Home / Function/ resolveFont() — astro Function Reference

resolveFont() — astro Function Reference

Architecture documentation for the resolveFont() function in local.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  679bd80d_33eb_0431_d016_0b3f5601ceb1["resolveFont()"]
  214874ef_a162_c192_431e_95979e65861c["LocalFontProvider"]
  679bd80d_33eb_0431_d016_0b3f5601ceb1 -->|defined in| 214874ef_a162_c192_431e_95979e65861c
  style 679bd80d_33eb_0431_d016_0b3f5601ceb1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/assets/fonts/providers/local.ts lines 107–146

	resolveFont(options: ResolveFontOptions<LocalFamilyOptions>): {
		fonts: Array<unifont.FontFaceData>;
	} {
		return {
			fonts:
				options.options?.variants.map((variant) => {
					const shouldInfer = variant.weight === undefined || variant.style === undefined;

					// We prepare the data
					const data: unifont.FontFaceData = {
						// If it should be inferred, we don't want to set the value
						weight: variant.weight,
						style: variant.style,
						src: [],
						unicodeRange: variant.unicodeRange,
						display: variant.display,
						stretch: variant.stretch,
						featureSettings: variant.featureSettings,
						variationSettings: variant.variationSettings,
					};
					// We proxy each source
					data.src = variant.src.map((rawSource, index) => {
						const source = this.#normalizeSource(rawSource);
						// We only try to infer for the first source. Indeed if it doesn't work, the function
						// call will throw an error so that will be interrupted anyways
						if (shouldInfer && index === 0) {
							const result = this.#fontFileReader.extract({
								family: options.familyName,
								url: source.url,
							});
							if (variant.weight === undefined) data.weight = result.weight;
							if (variant.style === undefined) data.style = result.style;
						}

						return source;
					});
					return data;
				}) ?? [],
		};
	}

Domain

Subdomains

Frequently Asked Questions

What does resolveFont() do?
resolveFont() is a function in the astro codebase, defined in packages/astro/src/assets/fonts/providers/local.ts.
Where is resolveFont() defined?
resolveFont() is defined in packages/astro/src/assets/fonts/providers/local.ts at line 107.

Analyze Your Own Codebase

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

Try Supermodel Free