@gjsify/dom-elements 0.64.57 → 0.64.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/font-face.js +1 -1
- package/lib/types/font-face.d.ts +18 -6
- package/package.json +10 -10
package/lib/esm/font-face.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{fontMapHasFamily as
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"gi://GLib?version=2.0";import{fontMapHasFamily as t,registerFontFaces as n}from"@gjsify/utils/font-map";function stageFontBytes(t){let n=e.build_filenamev([e.get_user_cache_dir(),`gjsify`,`fonts`]);e.mkdir_with_parents(n,493);let r=t.length>4&&String.fromCharCode(t[0],t[1],t[2],t[3])===`OTTO`,i=`${e.compute_checksum_for_bytes(e.ChecksumType.SHA256,new e.Bytes(t))}${r?`.otf`:`.ttf`}`,a=e.build_filenamev([n,i]);if(!e.file_test(a,e.FileTest.EXISTS)){let n=`${a}.${e.get_monotonic_time()}.part`;e.file_set_contents(n,t),e.rename(n,a)}return a}var FontFace=class{constructor(e,t,n){this.status=`unloaded`,this.display=`auto`,this.style=`normal`,this.weight=`normal`,this.stretch=`normal`,this.unicodeRange=`U+0-10FFFF`,this.variant=`normal`,this.featureSettings=`normal`,this._started=null,this.family=e,this.source=typeof t==`string`?t:`[binary]`,this.loaded=new Promise((e,t)=>{this._settle={resolve:e,reject:t}}),this.loaded.catch(()=>{}),typeof t==`string`?this._bytes=null:(this._bytes=ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),this.load())}_extractFilePath(){let e=this.source.match(/url\s*\(\s*["']?(file:\/\/\/[^"')]+)["']?\s*\)/i);return e?decodeURIComponent(e[1].replace(/^file:\/\//,``)):null}load(){return this._started??=this._load(),this._started}async _load(){this.status=`loading`,await Promise.resolve();try{let e=this._bytes?stageFontBytes(this._bytes):this._extractFilePath();if(e){let t=n([e]);t.available&&reportRegistration(this.family,t)}}catch(e){throw this.status=`error`,this._settle.reject(e),e}return this.status=`loaded`,this._settle.resolve(this),this}};function reportRegistration(e,n){for(let t of n.failed)console.warn(`FontFace.load: ${t.path} could not be read as a font (${t.message}), so text asking for "${e}" will render in a substituted one.`);for(let e of n.declined)console.warn(`FontFace.load: no font map in this process would take ${e} — Pango answers a family it does not hold with the default sans, and nothing else says so. A shipped .app reaches its faces through ATSApplicationFontsPath; a bare \`gjsify run\` needs initFonts() first.`);for(let t of n.unreachable)console.warn(`FontFace.load: ${t} is registered and "${e}" is a family this font map holds, but text asking for it will still render in a substituted one: the map had already resolved that family to the fallback, and that cached answer cannot be asked again. Register the face before anything lays text out.`);n.registered.length!==0&&n.map!==void 0&&(t(n.map,e)||console.warn(`FontFace.load: ${n.registered[0]} is registered, but "${e}" is not a family on the font map — it may be registered under a different name, and text asking for it will render in a substituted one.`))}function requestedFamilies(e){let t=e.match(/\d(?:\.\d+)?(?:px|pt|em|rem|%)(?:\/\S+)?\s+(.+)$/i);return(t?t[1]:e).split(`,`).map(e=>e.trim().replace(/^["']|["']$/g,``).toLowerCase()).filter(e=>e.length>0)}var FontFaceSet=class{constructor(){this._faces=new Set}get status(){for(let e of this._faces)if(e.status===`loading`)return`loading`;return`loaded`}get ready(){let e=Array.from(this._faces).filter(e=>e.status===`loading`).map(e=>e.loaded.catch(()=>e));return Promise.all(e).then(()=>this)}addEventListener(e,t){}removeEventListener(e,t){}dispatchEvent(e){return!0}add(e){return this._faces.add(e),this}delete(e){return this._faces.delete(e)}clear(){this._faces.clear()}has(e){return this._faces.has(e)}_matching(e){let t=requestedFamilies(e);return Array.from(this._faces).filter(e=>t.includes(e.family.toLowerCase()))}check(e,t){return this._matching(e).every(e=>e.status===`loaded`)}load(e,t){let n=this._matching(e);return Promise.all(n.map(e=>e.load())).then(()=>n)}forEach(e){this._faces.forEach(t=>e(t,t,this))}values(){return this._faces.values()}keys(){return this._faces.values()}entries(){return Array.from(this._faces).map(e=>[e,e])[Symbol.iterator]()}[Symbol.iterator](){return this._faces[Symbol.iterator]()}get size(){return this._faces.size}};export{FontFace,FontFaceSet};
|
package/lib/types/font-face.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
type FontFaceStatus = 'unloaded' | 'loading' | 'loaded' | 'error';
|
|
1
2
|
export declare class FontFace {
|
|
2
3
|
readonly family: string;
|
|
3
4
|
readonly source: string;
|
|
4
|
-
status:
|
|
5
|
+
status: FontFaceStatus;
|
|
5
6
|
loaded: Promise<FontFace>;
|
|
6
7
|
display: string;
|
|
7
8
|
style: string;
|
|
@@ -10,20 +11,27 @@ export declare class FontFace {
|
|
|
10
11
|
unicodeRange: string;
|
|
11
12
|
variant: string;
|
|
12
13
|
featureSettings: string;
|
|
14
|
+
private readonly _bytes;
|
|
15
|
+
private _started;
|
|
16
|
+
private _settle;
|
|
13
17
|
constructor(family: string, source: string | ArrayBuffer | ArrayBufferView, _descriptors?: Record<string, string>);
|
|
14
18
|
private _extractFilePath;
|
|
15
19
|
load(): Promise<FontFace>;
|
|
20
|
+
private _load;
|
|
16
21
|
}
|
|
17
22
|
/**
|
|
18
|
-
*
|
|
23
|
+
* The faces a page registered, and what `ctx.font` can therefore draw. `add()` does not load a face
|
|
24
|
+
* built from a URL (the Web contract: `load()` or the first use does); a face built from bytes is
|
|
25
|
+
* already loading, and `ready` waits for it.
|
|
19
26
|
*
|
|
20
27
|
* Does not extend EventTarget: the event methods are no-ops, so a consumer listening for
|
|
21
28
|
* 'loadingdone' silently receives nothing.
|
|
22
29
|
*/
|
|
23
30
|
export declare class FontFaceSet {
|
|
24
|
-
status: 'loading' | 'loaded';
|
|
25
|
-
ready: Promise<FontFaceSet>;
|
|
26
31
|
private _faces;
|
|
32
|
+
get status(): 'loading' | 'loaded';
|
|
33
|
+
/** Resolves once every face that is loading NOW has settled; a failed face does not reject it. */
|
|
34
|
+
get ready(): Promise<FontFaceSet>;
|
|
27
35
|
addEventListener(_type: string, _listener: unknown): void;
|
|
28
36
|
removeEventListener(_type: string, _listener: unknown): void;
|
|
29
37
|
dispatchEvent(_event: unknown): boolean;
|
|
@@ -31,8 +39,11 @@ export declare class FontFaceSet {
|
|
|
31
39
|
delete(face: FontFace): boolean;
|
|
32
40
|
clear(): void;
|
|
33
41
|
has(face: FontFace): boolean;
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
private _matching;
|
|
43
|
+
/** True when every face of this set that `font` names is loaded (a name not in the set is a system font). */
|
|
44
|
+
check(font: string, _text?: string): boolean;
|
|
45
|
+
/** Loads the faces of this set that `font` names and resolves with them. */
|
|
46
|
+
load(font: string, _text?: string): Promise<FontFace[]>;
|
|
36
47
|
forEach(callback: (value: FontFace, key: FontFace, parent: FontFaceSet) => void): void;
|
|
37
48
|
values(): IterableIterator<FontFace>;
|
|
38
49
|
keys(): IterableIterator<FontFace>;
|
|
@@ -40,3 +51,4 @@ export declare class FontFaceSet {
|
|
|
40
51
|
[Symbol.iterator](): Iterator<FontFace>;
|
|
41
52
|
get size(): number;
|
|
42
53
|
}
|
|
54
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/dom-elements",
|
|
3
|
-
"version": "0.64.
|
|
3
|
+
"version": "0.64.58",
|
|
4
4
|
"description": "DOM element hierarchy (Node, Element, HTMLElement, HTMLImageElement) for GJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -72,19 +72,19 @@
|
|
|
72
72
|
"@girs/gjs": "5.4.0",
|
|
73
73
|
"@girs/glib-2.0": "5.4.0",
|
|
74
74
|
"@girs/gst-1.0": "5.4.0",
|
|
75
|
-
"@gjsify/abort-controller": "0.64.
|
|
76
|
-
"@gjsify/canvas2d-core": "0.64.
|
|
77
|
-
"@gjsify/dom-events": "0.64.
|
|
78
|
-
"@gjsify/domparser": "0.64.
|
|
79
|
-
"@gjsify/fetch": "0.64.
|
|
80
|
-
"@gjsify/node-globals": "0.64.
|
|
81
|
-
"@gjsify/utils": "0.64.
|
|
75
|
+
"@gjsify/abort-controller": "0.64.58",
|
|
76
|
+
"@gjsify/canvas2d-core": "0.64.58",
|
|
77
|
+
"@gjsify/dom-events": "0.64.58",
|
|
78
|
+
"@gjsify/domparser": "0.64.58",
|
|
79
|
+
"@gjsify/fetch": "0.64.58",
|
|
80
|
+
"@gjsify/node-globals": "0.64.58",
|
|
81
|
+
"@gjsify/utils": "0.64.58"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@girs/pango-1.0": "5.4.0",
|
|
85
85
|
"@girs/pangocairo-1.0": "5.4.0",
|
|
86
|
-
"@gjsify/cli": "0.64.
|
|
87
|
-
"@gjsify/unit": "0.64.
|
|
86
|
+
"@gjsify/cli": "0.64.58",
|
|
87
|
+
"@gjsify/unit": "0.64.58",
|
|
88
88
|
"@types/node": "^25.9.2",
|
|
89
89
|
"typescript": "^6.0.3"
|
|
90
90
|
},
|