@web-ppt/fonts 0.8.0 → 0.9.0-beta.1
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/CHANGELOG.md +33 -42
- package/README.md +25 -2
- package/dist/export-faces.d.ts +40 -0
- package/dist/fault-Wg7mCzGf.js +13 -0
- package/dist/fonts.js +573 -199
- package/dist/glyphs/index.d.ts +1 -1
- package/dist/glyphs-browser.js +112 -76
- package/dist/glyphs-harfbuzz.js +36 -37
- package/dist/glyphs-worker.js +276 -212
- package/dist/glyphs.js +108 -68
- package/dist/index.d.ts +2 -0
- package/dist/load.d.ts +4 -0
- package/dist/provider-B6_T5p3K.js +796 -0
- package/dist/subset/harfbuzz.d.ts +12 -0
- package/dist/subset/index.d.ts +7 -0
- package/dist/subset.js +64 -0
- package/package.json +9 -2
- package/dist/fault-HMYM9DhC.js +0 -16
- package/dist/provider-9-K8y5p4.js +0 -617
package/dist/glyphs/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export { withFontMeasurement } from './measurement';
|
|
|
4
4
|
export type { FontMeasurementOptions, PreparedFontMeasurement } from './measurement';
|
|
5
5
|
export type { FontTextSegment } from './text-scripts';
|
|
6
6
|
export type FontGlyphProvider = ReturnType<typeof import('./provider').createFontProvider>;
|
|
7
|
-
export type { FontSource, FontRequestOptions, FontRequest, FontFaceInfo, FontEmbedding, FontEmbeddingRights, FontProblem, FontFailure, FontResult, FontProviderOptions, FontScript, FontShapeOptions, PositionedGlyph, GlyphCluster, GlyphRun, ShaperGlyph, FontShaperFace, FontShaper, FontProviderLimits } from './types';
|
|
7
|
+
export type { FontSource, FontRequestOptions, FontRequest, FontFaceInfo, FontEmbedding, FontEmbeddingRights, FontProblem, FontFailure, FontResult, FontProviderOptions, FontScript, FontShapeOptions, PositionedGlyph, GlyphCluster, GlyphRun, ShaperGlyph, FontShaperFace, FontShaper, FontProviderLimits, } from './types';
|
package/dist/glyphs-browser.js
CHANGED
|
@@ -1,78 +1,114 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
o(), u(e);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
1
|
+
// src/glyphs/browser.ts
|
|
2
|
+
function e(e, t, n) {
|
|
3
|
+
return new Promise((r, i) => {
|
|
4
|
+
let a = () => {
|
|
5
|
+
o(), i(new DOMException("字体加载已取消", "AbortError"));
|
|
6
|
+
}, o = () => {
|
|
7
|
+
t.removeEventListener("abort", a), n?.removeEventListener("abort", a);
|
|
8
|
+
};
|
|
9
|
+
t.addEventListener("abort", a, { once: !0 }), n?.addEventListener("abort", a, { once: !0 }), t.aborted || n?.aborted ? (o(), a()) : Promise.resolve().then(() => e.load()).then(() => {
|
|
10
|
+
o(), r();
|
|
11
|
+
}, (e) => {
|
|
12
|
+
o(), i(e);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
18
15
|
}
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
16
|
+
function t(t, n = document) {
|
|
17
|
+
let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), a = new AbortController(), o = !1, s = (e, n) => o || t.state().disposed ? {
|
|
18
|
+
ok: !1,
|
|
19
|
+
reason: "provider-disposed",
|
|
20
|
+
faceId: e
|
|
21
|
+
} : n.signal?.aborted ? {
|
|
22
|
+
ok: !1,
|
|
23
|
+
reason: "aborted",
|
|
24
|
+
faceId: e
|
|
25
|
+
} : void 0;
|
|
26
|
+
return {
|
|
27
|
+
async install(o, c) {
|
|
28
|
+
let l = s(o, c);
|
|
29
|
+
if (l) return l;
|
|
30
|
+
let u = await t.embedding(o, c);
|
|
31
|
+
if (!u.ok) return u;
|
|
32
|
+
let d = s(o, c);
|
|
33
|
+
if (d) return d;
|
|
34
|
+
let { info: f, bytes: p } = u.value, m = c.family ?? f.family;
|
|
35
|
+
if (![400, 700].includes(f.weight)) return {
|
|
36
|
+
ok: !1,
|
|
37
|
+
reason: "face-style-mismatch",
|
|
38
|
+
faceId: o
|
|
39
|
+
};
|
|
40
|
+
if (!m.trim() || m.length > 256 || /[\u0000-\u001f\u007f]/.test(m)) return {
|
|
41
|
+
ok: !1,
|
|
42
|
+
reason: "invalid-request",
|
|
43
|
+
faceId: o
|
|
44
|
+
};
|
|
45
|
+
let h = JSON.stringify([o, m]), g = r.get(h);
|
|
46
|
+
if (g) return {
|
|
47
|
+
ok: !0,
|
|
48
|
+
value: { ...g.resource }
|
|
49
|
+
};
|
|
50
|
+
if (i.has(h)) return {
|
|
51
|
+
ok: !1,
|
|
52
|
+
reason: "duplicate-face-id",
|
|
53
|
+
faceId: o
|
|
54
|
+
};
|
|
55
|
+
i.add(h);
|
|
56
|
+
let _, v;
|
|
57
|
+
try {
|
|
58
|
+
let t = s(o, c);
|
|
59
|
+
if (t) return t;
|
|
60
|
+
_ = new FontFace(m, new Uint8Array(p).buffer, {
|
|
61
|
+
weight: String(f.weight),
|
|
62
|
+
style: f.italic ? "italic" : "normal"
|
|
63
|
+
}), await e(_, a.signal, c.signal);
|
|
64
|
+
let i = s(o, c);
|
|
65
|
+
if (i) return i;
|
|
66
|
+
n.fonts.add(_), v = URL.createObjectURL(new Blob([new Uint8Array(p).buffer], { type: "font/ttf" }));
|
|
67
|
+
let l = {
|
|
68
|
+
family: m,
|
|
69
|
+
src: v,
|
|
70
|
+
bold: f.weight === 700,
|
|
71
|
+
italic: f.italic
|
|
72
|
+
};
|
|
73
|
+
return r.set(h, {
|
|
74
|
+
id: o,
|
|
75
|
+
font: _,
|
|
76
|
+
resource: l,
|
|
77
|
+
bytes: p.length
|
|
78
|
+
}), {
|
|
79
|
+
ok: !0,
|
|
80
|
+
value: { ...l }
|
|
81
|
+
};
|
|
82
|
+
} catch {
|
|
83
|
+
return _ && n.fonts.delete(_), v && URL.revokeObjectURL(v), s(o, c) ?? {
|
|
84
|
+
ok: !1,
|
|
85
|
+
reason: "font-install-failed",
|
|
86
|
+
faceId: o
|
|
87
|
+
};
|
|
88
|
+
} finally {
|
|
89
|
+
i.delete(h);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
resources() {
|
|
93
|
+
return [...r.values()].map((e) => ({ ...e.resource }));
|
|
94
|
+
},
|
|
95
|
+
remove(e) {
|
|
96
|
+
for (let [t, i] of r) i.id === e && (n.fonts.delete(i.font), URL.revokeObjectURL(i.resource.src), r.delete(t));
|
|
97
|
+
},
|
|
98
|
+
state() {
|
|
99
|
+
return {
|
|
100
|
+
disposed: o,
|
|
101
|
+
faces: r.size,
|
|
102
|
+
sourceBytes: [...r.values()].reduce((e, t) => e + t.bytes, 0)
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
dispose() {
|
|
106
|
+
if (!o) {
|
|
107
|
+
o = !0, a.abort();
|
|
108
|
+
for (let e of r.values()) n.fonts.delete(e.font), URL.revokeObjectURL(e.resource.src);
|
|
109
|
+
r.clear();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
75
113
|
}
|
|
76
|
-
export {
|
|
77
|
-
p as createFontFaceScope
|
|
78
|
-
};
|
|
114
|
+
export { t as createFontFaceScope };
|
package/dist/glyphs-harfbuzz.js
CHANGED
|
@@ -1,38 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
import { t as e } from "./fault-Wg7mCzGf.js";
|
|
2
|
+
// src/glyphs/harfbuzz.ts
|
|
3
|
+
function t(t) {
|
|
4
|
+
let n = !1, r = /* @__PURE__ */ new Set();
|
|
5
|
+
return {
|
|
6
|
+
async open(i, a) {
|
|
7
|
+
if (n || a.aborted) throw new e("aborted");
|
|
8
|
+
let o = new t.Font(new t.Face(new t.Blob(i.bytes))), s = () => {
|
|
9
|
+
o = void 0, r.delete(s);
|
|
10
|
+
};
|
|
11
|
+
return r.add(s), {
|
|
12
|
+
async shape(r, i) {
|
|
13
|
+
if (!o || n || i.signal?.aborted) throw new e("aborted");
|
|
14
|
+
let a = new t.Buffer();
|
|
15
|
+
a.addText(r), a.guessSegmentProperties(), a.setDirection(t.Direction.LTR), a.setScript(i.script), a.setLanguage(i.language), t.shape(o, a);
|
|
16
|
+
let s = a.getGlyphInfos(), c = a.getGlyphPositions();
|
|
17
|
+
if (s.length !== c.length) throw new e("shaper-failed");
|
|
18
|
+
return s.map((e, t) => ({
|
|
19
|
+
id: e.codepoint,
|
|
20
|
+
cluster: e.cluster,
|
|
21
|
+
...c[t]
|
|
22
|
+
}));
|
|
23
|
+
},
|
|
24
|
+
async outline(t, r) {
|
|
25
|
+
if (!o || n || r.signal?.aborted) throw new e("aborted");
|
|
26
|
+
return o.glyphToPath(t);
|
|
27
|
+
},
|
|
28
|
+
dispose: s
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
dispose() {
|
|
32
|
+
n = !0;
|
|
33
|
+
for (let e of [...r]) e();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
35
36
|
}
|
|
36
|
-
export {
|
|
37
|
-
y as createHarfBuzzShaper
|
|
38
|
-
};
|
|
37
|
+
export { t as createHarfBuzzShaper };
|