Home / File/ unifont-font-resolver.ts — astro Source File

unifont-font-resolver.ts — astro Source File

Architecture documentation for unifont-font-resolver.ts, a typescript file in the astro codebase. 3 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  ca507970_e93d_33e9_8890_c7346bc9af2b["unifont-font-resolver.ts"]
  e92fda44_4a5d_b83b_1a45_958cdae6c91b["./definitions.js"]
  ca507970_e93d_33e9_8890_c7346bc9af2b --> e92fda44_4a5d_b83b_1a45_958cdae6c91b
  ea387312_d0a2_bb52_dafc_3872f7307f95["../../src/assets/fonts/types.js"]
  ca507970_e93d_33e9_8890_c7346bc9af2b --> ea387312_d0a2_bb52_dafc_3872f7307f95
  07866fa4_1b50_10c2_1b6b_5b1f385406b5["unifont"]
  ca507970_e93d_33e9_8890_c7346bc9af2b --> 07866fa4_1b50_10c2_1b6b_5b1f385406b5
  style ca507970_e93d_33e9_8890_c7346bc9af2b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { FontFaceData, Provider } from 'unifont';
import { createUnifont, defineFontProvider, type Unifont } from 'unifont';
import type { FontResolver, Hasher, Storage } from '../definitions.js';
import type { FontProvider, ResolvedFontFamily, ResolveFontOptions } from '../types.js';

type NonEmptyProviders = [
	Provider<string, Record<string, any>>,
	...Array<Provider<string, Record<string, any>>>,
];

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);
// ... (70 more lines)

Domain

Subdomains

Dependencies

  • ../../src/assets/fonts/types.js
  • ./definitions.js
  • unifont

Frequently Asked Questions

What does unifont-font-resolver.ts do?
unifont-font-resolver.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What does unifont-font-resolver.ts depend on?
unifont-font-resolver.ts imports 3 module(s): ../../src/assets/fonts/types.js, ./definitions.js, unifont.
Where is unifont-font-resolver.ts in the architecture?
unifont-font-resolver.ts is located at packages/astro/src/assets/fonts/infra/unifont-font-resolver.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/assets/fonts/infra).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free