FontDefinition
A font family: its files, its CSS variable, and its fallback metrics.
A font family: its files, its CSS variable, and its fallback metrics.
Import#
ts
import type { FontDefinition } from "@shadow-js/dusk/vite";
Signature#
ts
interface FontDefinition {
/** The family name the CSS uses. */
readonly family: string;
/** CSS custom property that holds the font stack, for example `--font-sans`. */
readonly variable?: string;
readonly files: readonly FontFile[];
/** Generic and system families after the font. Default `["sans-serif"]`. */
readonly fallback?: readonly string[];
/** Default `swap`. */
readonly display?: FontDisplay;
/** Whether the family's files are preloaded unless a file says otherwise. Default true (see {@link FontFile.preload}). */
readonly preload?: boolean;
/**
* The size-adjusted fallback face (the `size-adjust` technique), so the text does not jump when the web font arrives.
*
* Absent: the face is built when the metrics of the family's files can be read (Arial, or Times New Roman when the
* `fallback` stack has `serif`), and left out, without an error, when they cannot. `false`: no fallback face.
* An object asks for the face and makes an unreadable file an error: `local` is the system font it is built from
* (`Arial`, `Times New Roman`); `font` defaults to the metrics the family's files declare (`readFontMetrics`, from the
* file nearest to weight 400 that has the Latin letters); `fallback` defaults to the system font's measured values in
* `SYSTEM_FALLBACKS`. Pass both to use other values (for example Next.js's capsize table).
*/
readonly metrics?:
| false
| {
readonly local: string;
readonly font?: FontMetrics;
readonly fallback?: { readonly unitsPerEm: number; readonly xWidthAvg: number };
};
}
Members#
| Name | Type | Description |
|---|---|---|
family |
readonly family: string |
The family name the CSS uses. |
variable? |
readonly variable?: string |
CSS custom property that holds the font stack, for example --font-sans. |
files |
readonly files: readonly FontFile[] |
|
fallback? |
readonly fallback?: readonly string[] |
Generic and system families after the font. Default ["sans-serif"]. |
display? |
readonly display?: FontDisplay |
Default swap. |
preload? |
readonly preload?: boolean |
Whether the family's files are preloaded unless a file says otherwise. Default true (see FontFile.preload). |
metrics? |
readonly metrics?: | false | { readonly local: string; readonly font?: FontMetrics; readonly fallback?: { readonly unitsPerEm: number; readonly xWidthAvg: number }; } |
The size-adjusted fallback face (the size-adjust technique), so the text does not jump when the web font arrives. Absent: the face is built when the metrics of the family's files can be read (Arial, or Times New Roman when the fallback stack has serif), and left out, without an error, when they cannot. false: no fallback face. An object asks for the face and makes an unreadable file an error: local is the system font it is built from (Arial, Times New Roman); font defaults to the metrics the family's files declare (readFontMetrics, from the file nearest to weight 400 that has the Latin letters); fallback defaults to the system font's measured values in SYSTEM_FALLBACKS. Pass both to use other values (for example Next.js's capsize table). |