import type { Font } from '@capsizecss/unpack'; import type * as unifont from 'unifont'; import type * as z from 'zod/v4'; import type { DisplaySchema, StyleSchema, WeightSchema } from './config.js'; import type { FONT_TYPES, GENERIC_FALLBACK_NAMES } from './constants.js'; import type { CollectedFontForMetrics } from './core/optimize-fallbacks.js'; export type Weight = z.infer; type Display = z.infer; export interface FontProviderInitContext { /** * Useful for caching. */ storage: { getItem: { (key: string): Promise; (key: string, init: () => Awaitable): Promise; }; setItem: (key: string, value: unknown) => Awaitable; }; /** * The project root, useful for resolving local files paths. */ root: URL; /** * Requests a provider API, retrying transient failures. Requests are routed through a * proxy if one is configured, so providers should always request the upstream URL. */ fetch: (url: string, init?: RequestInit) => Promise; } type Awaitable = T | Promise; export interface FontProvider | undefined | never = never> { /** * A unique name for the provider, used in logs and for identification. */ name: string; /** * A serializable object, used for identification. */ config?: Record | undefined; /** * Optional callback, used to perform any initialization logic. */ init?: ((context: FontProviderInitContext) => Awaitable) | undefined; /** * Used to retrieve and return font face data based on the given options. */ resolveFont: (options: ResolveFontOptions) => Awaitable<{ fonts: Array; } | undefined>; /** * Optional callback, used to return the list of available font names. */ listFonts?: (() => Awaitable | undefined>) | undefined; /** * Optional callback, used to return the properties available for a given font family. * It allows Astro to warn about configured values a provider cannot serve. Return * `undefined` when the family is unknown to the provider. */ getFontProperties?: ((options: GetFontPropertiesOptions) => Awaitable) | undefined; } export interface GetFontPropertiesOptions { /** * The font family name, as identified by the font provider. */ familyName: string; } /** * Describes what a provider can actually serve for a given font family. Any * `undefined` property means the provider does not expose that information, * not that nothing is available. */ export interface FontProperties { /** * Weights available for the font family. Values are either discrete weights (`"400"`) * or variable ranges expressed as `" "` (`"100 900"`). */ weights?: Array | undefined; /** * Styles available for the font family. */ styles?: Array