Home / File/ system-fallbacks-provider.ts — astro Source File

system-fallbacks-provider.ts — astro Source File

Architecture documentation for system-fallbacks-provider.ts, a typescript file in the astro codebase. 2 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  6d0f31e9_9428_514e_4c85_fa96f3a99c1e["system-fallbacks-provider.ts"]
  e92fda44_4a5d_b83b_1a45_958cdae6c91b["./definitions.js"]
  6d0f31e9_9428_514e_4c85_fa96f3a99c1e --> e92fda44_4a5d_b83b_1a45_958cdae6c91b
  ea387312_d0a2_bb52_dafc_3872f7307f95["../../src/assets/fonts/types.js"]
  6d0f31e9_9428_514e_4c85_fa96f3a99c1e --> ea387312_d0a2_bb52_dafc_3872f7307f95
  style 6d0f31e9_9428_514e_4c85_fa96f3a99c1e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { SystemFallbacksProvider } from '../definitions.js';
import type { FontFaceMetrics, GenericFallbackName } from '../types.js';

// Extracted from https://raw.githubusercontent.com/seek-oss/capsize/refs/heads/master/packages/metrics/src/entireMetricsCollection.json
const SYSTEM_METRICS = {
	'Times New Roman': {
		ascent: 1825,
		descent: -443,
		lineGap: 87,
		unitsPerEm: 2048,
		xWidthAvg: 832,
	},
	Arial: {
		ascent: 1854,
		descent: -434,
		lineGap: 67,
		unitsPerEm: 2048,
		xWidthAvg: 913,
	},
	'Courier New': {
		ascent: 1705,
		descent: -615,
		lineGap: 0,
		unitsPerEm: 2048,
		xWidthAvg: 1229,
	},
	BlinkMacSystemFont: {
		ascent: 1980,
		descent: -432,
		lineGap: 0,
		unitsPerEm: 2048,
		xWidthAvg: 853,
	},
	'Segoe UI': {
		ascent: 2210,
		descent: -514,
		lineGap: 0,
		unitsPerEm: 2048,
		xWidthAvg: 908,
	},
	Roboto: {
		ascent: 1900,
		descent: -500,
		lineGap: 0,
		unitsPerEm: 2048,
		xWidthAvg: 911,
	},
	'Helvetica Neue': {
		ascent: 952,
		descent: -213,
		lineGap: 28,
		unitsPerEm: 1000,
		xWidthAvg: 450,
	},
} satisfies Record<string, FontFaceMetrics>;

type FallbackName = keyof typeof SYSTEM_METRICS;

// Source: https://github.com/nuxt/fonts/blob/3a3eb6dfecc472242b3011b25f3fcbae237d0acc/src/module.ts#L55-L75
const DEFAULT_FALLBACKS = {
	serif: ['Times New Roman'],
	'sans-serif': ['Arial'],
	monospace: ['Courier New'],
	'system-ui': ['BlinkMacSystemFont', 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Arial'],
	'ui-serif': ['Times New Roman'],
	'ui-sans-serif': ['Arial'],
	'ui-monospace': ['Courier New'],
} satisfies Partial<Record<GenericFallbackName, Array<FallbackName>>>;

// TODO: find a better name
export class RealSystemFallbacksProvider implements SystemFallbacksProvider {
	getLocalFonts(fallback: GenericFallbackName): Array<string> | null {
		return DEFAULT_FALLBACKS[fallback as keyof typeof DEFAULT_FALLBACKS] ?? null;
	}

	getMetricsForLocalFont(family: string): FontFaceMetrics {
		return SYSTEM_METRICS[family as FallbackName];
	}
}

Domain

Subdomains

Types

Dependencies

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

Frequently Asked Questions

What does system-fallbacks-provider.ts do?
system-fallbacks-provider.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What does system-fallbacks-provider.ts depend on?
system-fallbacks-provider.ts imports 2 module(s): ../../src/assets/fonts/types.js, ./definitions.js.
Where is system-fallbacks-provider.ts in the architecture?
system-fallbacks-provider.ts is located at packages/astro/src/assets/fonts/infra/system-fallbacks-provider.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