diff --git a/src/module/fonts.ts b/src/module/fonts.ts new file mode 100644 index 00000000..a4680802 --- /dev/null +++ b/src/module/fonts.ts @@ -0,0 +1,37 @@ +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; + load(): Promise; +} + +interface FontFaceSet { + readonly status: FontFaceSetStatus; + readonly ready: Promise; + check(font: string, text?: string): boolean; + load(font: string, text?: string): Promise; +} + +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}`))); +} diff --git a/src/module/hooks/init.ts b/src/module/hooks/init.ts index c7b1edcd..8db11fe2 100644 --- a/src/module/hooks/init.ts +++ b/src/module/hooks/init.ts @@ -8,6 +8,7 @@ import { DS4Actor } from "../actor/actor"; import { DS4CharacterActorSheet } from "../actor/sheets/character-sheet"; import { DS4CreatureActorSheet } from "../actor/sheets/creature-sheet"; import { DS4 } from "../config"; +import { preloadFonts as preloadFonts } from "../fonts"; import registerHandlebarsHelpers from "../handlebars/handlebars-helpers"; import registerHandlebarsPartials from "../handlebars/handlebars-partials"; import { getGame } from "../helpers"; @@ -61,6 +62,7 @@ async function init() { Items.unregisterSheet("core", ItemSheet); Items.registerSheet("ds4", DS4ItemSheet, { makeDefault: true }); + preloadFonts(); await registerHandlebarsPartials(); registerHandlebarsHelpers(); }