UnifontFontResolver Class — astro Architecture
Architecture documentation for the UnifontFontResolver class in unifont-font-resolver.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD e75025f8_1303_03ea_42ce_653194e50374["UnifontFontResolver"] ca507970_e93d_33e9_8890_c7346bc9af2b["unifont-font-resolver.ts"] e75025f8_1303_03ea_42ce_653194e50374 -->|defined in| ca507970_e93d_33e9_8890_c7346bc9af2b 1609ec04_7f38_14b9_f3ab_431aa6530554["constructor()"] e75025f8_1303_03ea_42ce_653194e50374 -->|method| 1609ec04_7f38_14b9_f3ab_431aa6530554 86803e41_45ca_a354_b3e0_fd9a88d03563["idFromProvider()"] e75025f8_1303_03ea_42ce_653194e50374 -->|method| 86803e41_45ca_a354_b3e0_fd9a88d03563 585ad958_97bd_0d25_1b2b_d396c4fe2747["astroToUnifontProvider()"] e75025f8_1303_03ea_42ce_653194e50374 -->|method| 585ad958_97bd_0d25_1b2b_d396c4fe2747 9f4d1ee9_7723_97a0_a304_0a2525104e5b["extractUnifontProviders()"] e75025f8_1303_03ea_42ce_653194e50374 -->|method| 9f4d1ee9_7723_97a0_a304_0a2525104e5b 67ba1af0_9e8b_299f_9d2e_835350aaa28f["create()"] e75025f8_1303_03ea_42ce_653194e50374 -->|method| 67ba1af0_9e8b_299f_9d2e_835350aaa28f 40582598_ddaf_bc56_1d35_6346d14bd03c["resolveFont()"] e75025f8_1303_03ea_42ce_653194e50374 -->|method| 40582598_ddaf_bc56_1d35_6346d14bd03c 45f5b03a_8e0e_9fc6_197c_a482452c81b0["listFonts()"] e75025f8_1303_03ea_42ce_653194e50374 -->|method| 45f5b03a_8e0e_9fc6_197c_a482452c81b0
Relationship Graph
Source Code
packages/astro/src/assets/fonts/infra/unifont-font-resolver.ts lines 11–129
export class UnifontFontResolver implements FontResolver {
readonly #unifont: Unifont<NonEmptyProviders>;
readonly #hasher: Hasher;
private constructor({
unifont,
hasher,
}: { unifont: Unifont<NonEmptyProviders>; hasher: Hasher }) {
this.#unifont = unifont;
this.#hasher = hasher;
}
static idFromProvider({ hasher, provider }: { hasher: Hasher; provider: FontProvider }): string {
const hash = hasher.hashObject({
name: provider.name,
...provider.config,
});
return `${provider.name}-${hash}`;
}
static astroToUnifontProvider(astroProvider: FontProvider, root: URL): Provider {
return defineFontProvider(astroProvider.name, async (_options: any, ctx) => {
await astroProvider?.init?.({ ...ctx, root });
return {
async resolveFont(familyName, { options, ...rest }) {
return await astroProvider.resolveFont({ familyName, options, ...rest });
},
async listFonts() {
return astroProvider.listFonts?.();
},
};
})(astroProvider.config);
}
static extractUnifontProviders({
families,
hasher,
root,
}: {
families: Array<ResolvedFontFamily>;
hasher: Hasher;
root: URL;
}) {
const providers = new Map<string, Provider>();
for (const { provider } of families) {
const id = this.idFromProvider({ hasher, provider });
if (!providers.has(id)) {
const unifontProvider = this.astroToUnifontProvider(provider, root);
// Makes sure every font uses the right instance of a given provider
// if this provider is provided several times with different options
// We have to mutate the unifont provider name because unifont deduplicates
// based on the name.
unifontProvider._name = this.idFromProvider({ hasher, provider });
providers.set(id, unifontProvider);
}
}
return Array.from(providers.values()) as NonEmptyProviders;
}
static async create({
families,
hasher,
storage,
root,
}: {
families: Array<ResolvedFontFamily>;
hasher: Hasher;
storage: Storage;
root: URL;
}) {
return new UnifontFontResolver({
unifont: await createUnifont(this.extractUnifontProviders({ families, hasher, root }), {
storage,
// TODO: consider enabling, would require new astro errors
throwOnError: false,
}),
hasher,
});
Domain
Source
Frequently Asked Questions
What is the UnifontFontResolver class?
UnifontFontResolver is a class in the astro codebase, defined in packages/astro/src/assets/fonts/infra/unifont-font-resolver.ts.
Where is UnifontFontResolver defined?
UnifontFontResolver is defined in packages/astro/src/assets/fonts/infra/unifont-font-resolver.ts at line 11.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free