preload fonts so that when first opening an actor / item sheet, they are already available and the sheet is rendered faster
This commit is contained in:
parent
e7f6477127
commit
dff760a7f1
2 changed files with 39 additions and 0 deletions
37
src/module/fonts.ts
Normal file
37
src/module/fonts.ts
Normal file
|
@ -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<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}`)));
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue