2021-07-08 23:32:22 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Johannes Loher
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2021-07-08 23:25:00 +02:00
|
|
|
type CSSOMString = string;
|
|
|
|
type FontFaceLoadStatus = "unloaded" | "loading" | "loaded" | "error";
|
|
|
|
type FontFaceSetStatus = "loading" | "loaded";
|
|
|
|
|
|
|
|
interface FontFace {
|
|
|
|
family: CSSOMString;
|
|
|
|
style: CSSOMString;
|
|
|
|
weight: CSSOMString;
|
|
|
|
stretch: CSSOMString;
|
|
|
|
unicodeRange: CSSOMString;
|
|
|
|
variant: CSSOMString;
|
|
|
|
featureSettings: CSSOMString;
|
|
|
|
variationSettings: CSSOMString;
|
|
|
|
display: CSSOMString;
|
|
|
|
readonly status: FontFaceLoadStatus;
|
|
|
|
readonly loaded: Promise<FontFace>;
|
|
|
|
load(): Promise<FontFace>;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface FontFaceSet {
|
|
|
|
readonly status: FontFaceSetStatus;
|
|
|
|
readonly ready: Promise<FontFaceSet>;
|
|
|
|
check(font: string, text?: string): boolean;
|
|
|
|
load(font: string, text?: string): Promise<FontFace[]>;
|
|
|
|
}
|
|
|
|
|
|
|
|
declare global {
|
|
|
|
interface Document {
|
|
|
|
fonts: FontFaceSet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const fonts = ["Lora", "Wood Stamp"];
|
|
|
|
|
|
|
|
export async function preloadFonts() {
|
|
|
|
return Promise.all(fonts.map((font) => document.fonts.load(`1rem ${font}`)));
|
|
|
|
}
|