From dff760a7f11afdfec374951c3a0c1b5ce420b5ed Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Thu, 8 Jul 2021 23:25:00 +0200 Subject: [PATCH 1/3] preload fonts so that when first opening an actor / item sheet, they are already available and the sheet is rendered faster --- src/module/fonts.ts | 37 +++++++++++++++++++++++++++++++++++++ src/module/hooks/init.ts | 2 ++ 2 files changed, 39 insertions(+) create mode 100644 src/module/fonts.ts 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(); } From aad9d30a7b16c2204c61e4a342cc4b3880cf34ad Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Thu, 8 Jul 2021 23:31:17 +0200 Subject: [PATCH 2/3] Update to newest types and remove now obsolete object spreading --- package.json | 2 +- src/module/actor/sheets/actor-sheet.ts | 2 +- src/module/item/item-sheet.ts | 2 +- yarn.lock | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index bd320f8b..e5ab5a24 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "postinstall": "husky install" }, "devDependencies": { - "@league-of-foundry-developers/foundry-vtt-types": "^0.8.8-0", + "@league-of-foundry-developers/foundry-vtt-types": "^0.8.8-1", "@rollup/plugin-node-resolve": "^13.0.0", "@types/fs-extra": "^9.0.12", "@types/jest": "^26.0.24", diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts index 8f4a5f0e..012d621d 100644 --- a/src/module/actor/sheets/actor-sheet.ts +++ b/src/module/actor/sheets/actor-sheet.ts @@ -175,7 +175,7 @@ export class DS4ActorSheet extends ActorSheet icon: "icons/svg/aura.svg", }; - return ActiveEffect.create({ ...createData }, { parent: this.item }); + return ActiveEffect.create(createData, { parent: this.item }); } } diff --git a/yarn.lock b/yarn.lock index fc3277da..c371ecb2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -689,9 +689,9 @@ __metadata: languageName: node linkType: hard -"@league-of-foundry-developers/foundry-vtt-types@npm:^0.8.8-0": - version: 0.8.8-0 - resolution: "@league-of-foundry-developers/foundry-vtt-types@npm:0.8.8-0" +"@league-of-foundry-developers/foundry-vtt-types@npm:^0.8.8-1": + version: 0.8.8-1 + resolution: "@league-of-foundry-developers/foundry-vtt-types@npm:0.8.8-1" dependencies: "@types/jquery": ~3.5.5 "@types/simple-peer": ~9.11.0 @@ -701,7 +701,7 @@ __metadata: socket.io-client: 4.1.2 tinymce: 5.8.1 typescript: ^4.1.6 - checksum: cec288979cf341a28e8335fe5c538190df94925dad1a552a755d18cf2d5b557453a73dd1c17882c8576dd5226c86b89fe7ace1b51d1c5c3266613108e704a1bc + checksum: 40721e3f50f99606ab33b9db46c58eb2fdeb259c3e0c5fb5b856086bd11151406ffb8356bad51a516e2253dde507b7fc98c62ecd6002864c75a3f49e2baf2c83 languageName: node linkType: hard @@ -2949,7 +2949,7 @@ __metadata: version: 0.0.0-use.local resolution: "dungeonslayers4@workspace:." dependencies: - "@league-of-foundry-developers/foundry-vtt-types": ^0.8.8-0 + "@league-of-foundry-developers/foundry-vtt-types": ^0.8.8-1 "@rollup/plugin-node-resolve": ^13.0.0 "@types/fs-extra": ^9.0.12 "@types/jest": ^26.0.24 From a10c98c3ce5d6836a34dacdfdaac219864beef3b Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Thu, 8 Jul 2021 23:32:22 +0200 Subject: [PATCH 3/3] Add missing licensing info --- src/module/fonts.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/module/fonts.ts b/src/module/fonts.ts index a4680802..25fd62bc 100644 --- a/src/module/fonts.ts +++ b/src/module/fonts.ts @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2021 Johannes Loher +// +// SPDX-License-Identifier: MIT + type CSSOMString = string; type FontFaceLoadStatus = "unloaded" | "loading" | "loaded" | "error"; type FontFaceSetStatus = "loading" | "loaded";