@web-ppt/fonts 0.8.0-beta.3 → 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 +40 -31
- 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-worker.js
CHANGED
|
@@ -1,215 +1,279 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
1
|
+
import { n as e, r as t, t as n } from "./provider-B6_T5p3K.js";
|
|
2
|
+
import { t as r } from "./fault-Wg7mCzGf.js";
|
|
3
|
+
// src/glyphs/worker-protocol.ts
|
|
4
|
+
var i = "web-ppt-fonts/1";
|
|
5
|
+
// src/glyphs/worker-server.ts
|
|
6
|
+
function a(t, a) {
|
|
7
|
+
let o = n(a), s = new AbortController(), c = e(a.limits), l = !1, u = Promise.resolve(), d = (e) => {
|
|
8
|
+
let n = e.data;
|
|
9
|
+
!l && n && n.protocol === "web-ppt-fonts/1" && Number.isSafeInteger(n.id) && (u = u.then(async () => {
|
|
10
|
+
if (l) return;
|
|
11
|
+
let e;
|
|
12
|
+
try {
|
|
13
|
+
if (n.operation === "register") e = await o.register({
|
|
14
|
+
id: n.face.id,
|
|
15
|
+
family: n.face.family,
|
|
16
|
+
origin: n.face.origin,
|
|
17
|
+
bytes: n.bytes,
|
|
18
|
+
restrictions: n.face.embedding
|
|
19
|
+
}, { purpose: "view-print" });
|
|
20
|
+
else if (n.operation === "shape") e = await o.shape(n.faceId, n.text, n.options);
|
|
21
|
+
else if (n.operation === "outline") e = await o.outline(n.faceId, n.glyphId, { purpose: n.purpose });
|
|
22
|
+
else if (n.operation === "decode") {
|
|
23
|
+
if (!a.decodeEot) e = {
|
|
24
|
+
ok: !1,
|
|
25
|
+
reason: "decoder-unavailable"
|
|
26
|
+
};
|
|
27
|
+
else if (!(n.bytes instanceof Uint8Array) || n.bytes.length > c.maxFontBytes || !Number.isSafeInteger(n.maxOutputBytes) || n.maxOutputBytes < 1) e = {
|
|
28
|
+
ok: !1,
|
|
29
|
+
reason: "resource-limit"
|
|
30
|
+
};
|
|
31
|
+
else {
|
|
32
|
+
let t = Math.min(n.maxOutputBytes, c.maxFontBytes), r = await a.decodeEot(n.bytes, {
|
|
33
|
+
signal: s.signal,
|
|
34
|
+
maxOutputBytes: t
|
|
35
|
+
});
|
|
36
|
+
e = r?.length ? r.length > t ? {
|
|
37
|
+
ok: !1,
|
|
38
|
+
reason: "resource-limit"
|
|
39
|
+
} : {
|
|
40
|
+
ok: !0,
|
|
41
|
+
value: new Uint8Array(r)
|
|
42
|
+
} : {
|
|
43
|
+
ok: !1,
|
|
44
|
+
reason: "decode-failed"
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
} else e = {
|
|
48
|
+
ok: !1,
|
|
49
|
+
reason: "shaper-failed"
|
|
50
|
+
};
|
|
51
|
+
} catch (t) {
|
|
52
|
+
e = {
|
|
53
|
+
ok: !1,
|
|
54
|
+
reason: t instanceof r ? t.reason : n.operation === "decode" ? "decode-failed" : "shaper-failed"
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
l || t.postMessage({
|
|
58
|
+
protocol: i,
|
|
59
|
+
id: n.id,
|
|
60
|
+
result: e
|
|
61
|
+
}, e.ok && e.value instanceof Uint8Array ? [e.value.buffer] : []);
|
|
62
|
+
}).catch(() => {}));
|
|
63
|
+
};
|
|
64
|
+
return t.addEventListener("message", d), () => {
|
|
65
|
+
l || (l = !0, s.abort(), t.removeEventListener("message", d), o.dispose());
|
|
66
|
+
};
|
|
43
67
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
// src/glyphs/worker-result.ts
|
|
69
|
+
function o(e, n, i, a) {
|
|
70
|
+
let o = () => {
|
|
71
|
+
throw new r("shaper-failed");
|
|
72
|
+
};
|
|
73
|
+
e && typeof e == "object" || o();
|
|
74
|
+
let s = e;
|
|
75
|
+
if (Array.isArray(s.glyphs) && Array.isArray(s.clusters) && s.faceId === n.id && s.text === i && s.unitsPerEm === n.unitsPerEm && s.script === a.script && s.direction === a.direction && s.language === a.language || o(), s.glyphs.length > Math.max(256, i.length * 32) || s.clusters.length > s.glyphs.length) throw new r("resource-limit");
|
|
76
|
+
let c = [], l = 0, u = 0;
|
|
77
|
+
for (let e of s.clusters) {
|
|
78
|
+
(!e || !Number.isInteger(e.glyphEnd) || !Number.isInteger(e.end) || e.glyphStart !== l || e.glyphEnd <= l || e.glyphEnd > s.glyphs.length || e.start !== u || e.end <= u || e.end > i.length || e.text !== i.slice(e.start, e.end)) && o();
|
|
79
|
+
for (let t = e.glyphStart; t < e.glyphEnd; t++) {
|
|
80
|
+
let n = s.glyphs[t];
|
|
81
|
+
n && typeof n == "object" || o(), c.push({
|
|
82
|
+
...n,
|
|
83
|
+
cluster: e.start
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
l = e.glyphEnd, u = e.end;
|
|
87
|
+
}
|
|
88
|
+
(l !== s.glyphs.length || u !== i.length) && o();
|
|
89
|
+
let d = t(n, i, a, c);
|
|
90
|
+
return d.ok && d.value.xAdvance === s.xAdvance && d.value.yAdvance === s.yAdvance || o(), c;
|
|
65
91
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
92
|
+
// src/glyphs/worker-client.ts
|
|
93
|
+
function s(e, t = {}) {
|
|
94
|
+
let n = t.maxQueuedRequests ?? 64, a = t.requestTimeoutMs ?? 3e4, s = t.maxPendingBytes ?? 67108864;
|
|
95
|
+
if (!Number.isInteger(n) || n < 1 || !Number.isSafeInteger(s) || s < 1 || !Number.isFinite(a) || a < 1) throw RangeError("Invalid font worker budget");
|
|
96
|
+
let c = /* @__PURE__ */ new Map(), l = [], u = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set(), p = !1, m, h, g = 0, _ = 0, v = 0, y = "action", b, x, S = () => {
|
|
97
|
+
b !== void 0 && clearTimeout(b), b = void 0, x?.(), x = void 0, m?.terminate(), m = void 0, u.clear();
|
|
98
|
+
}, C = (e, t, n) => {
|
|
99
|
+
v -= e.cost, e.signal?.removeEventListener("abort", e.cancel), e === h && (b !== void 0 && clearTimeout(b), b = void 0, h = void 0), n ? e.reject(n) : e.resolve(t);
|
|
100
|
+
}, w = () => {
|
|
101
|
+
S(), h && C(h, void 0, new r("shaper-failed"));
|
|
102
|
+
for (let e of l.splice(0)) C(e, void 0, new r("shaper-failed"));
|
|
103
|
+
}, T = () => {
|
|
104
|
+
if (!h || !m) return;
|
|
105
|
+
let e = h.font;
|
|
106
|
+
y = !e || u.has(e.info.id) ? "action" : "register", _ = ++g;
|
|
107
|
+
let t = {
|
|
108
|
+
protocol: i,
|
|
109
|
+
id: _
|
|
110
|
+
};
|
|
111
|
+
if (y === "register" && e) {
|
|
112
|
+
let n = e.bytes.slice();
|
|
113
|
+
m.postMessage({
|
|
114
|
+
...t,
|
|
115
|
+
operation: "register",
|
|
116
|
+
face: e.info,
|
|
117
|
+
bytes: n
|
|
118
|
+
}, [n.buffer]);
|
|
119
|
+
} else if (h.action.operation === "decode") {
|
|
120
|
+
let e = h.action.bytes.slice();
|
|
121
|
+
m.postMessage({
|
|
122
|
+
...t,
|
|
123
|
+
...h.action,
|
|
124
|
+
bytes: e
|
|
125
|
+
}, [e.buffer]);
|
|
126
|
+
} else e && m.postMessage({
|
|
127
|
+
...t,
|
|
128
|
+
...h.action,
|
|
129
|
+
faceId: e.info.id
|
|
130
|
+
});
|
|
131
|
+
}, E = () => {
|
|
132
|
+
if (!(h || p || !l.length)) {
|
|
133
|
+
h = l.shift();
|
|
134
|
+
try {
|
|
135
|
+
if (!m) {
|
|
136
|
+
let t = e();
|
|
137
|
+
m = t;
|
|
138
|
+
let n = (e) => {
|
|
139
|
+
if (m !== t || !h) return;
|
|
140
|
+
let n = e.data;
|
|
141
|
+
if (n && n.protocol === "web-ppt-fonts/1" && n.id === _) {
|
|
142
|
+
if (!n.result || typeof n.result.ok != "boolean") w();
|
|
143
|
+
else if (!n.result.ok) C(h, void 0, new r(n.result.reason, n.result.missing, n.result.range)), E();
|
|
144
|
+
else if (y === "register") {
|
|
145
|
+
u.add(h.font.info.id);
|
|
146
|
+
try {
|
|
147
|
+
T();
|
|
148
|
+
} catch {
|
|
149
|
+
w();
|
|
150
|
+
}
|
|
151
|
+
} else C(h, n.result.value), E();
|
|
152
|
+
}
|
|
153
|
+
}, i = () => {
|
|
154
|
+
m === t && w();
|
|
155
|
+
};
|
|
156
|
+
t.addEventListener("message", n), t.addEventListener("error", i), t.addEventListener("messageerror", i), x = () => {
|
|
157
|
+
t.removeEventListener("message", n), t.removeEventListener("error", i), t.removeEventListener("messageerror", i);
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
b = setTimeout(w, a), T();
|
|
161
|
+
} catch {
|
|
162
|
+
w();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}, D = (e, t, i) => new Promise((a, o) => {
|
|
166
|
+
if (p) {
|
|
167
|
+
o(new r("provider-disposed"));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (i?.aborted) {
|
|
171
|
+
o(new r("aborted"));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
let c = t.operation === "decode" ? t.bytes.length : t.operation === "shape" ? t.text.length * 2 : 0;
|
|
175
|
+
if (l.length + +!!h >= n || v + c > s) {
|
|
176
|
+
o(new r("resource-limit"));
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
t.operation === "decode" && (t = {
|
|
180
|
+
...t,
|
|
181
|
+
bytes: new Uint8Array(t.bytes)
|
|
182
|
+
}), v += c;
|
|
183
|
+
let u = {
|
|
184
|
+
font: e,
|
|
185
|
+
action: t,
|
|
186
|
+
cost: c,
|
|
187
|
+
signal: i,
|
|
188
|
+
resolve: a,
|
|
189
|
+
reject: o,
|
|
190
|
+
cancel: () => {
|
|
191
|
+
if (h === u) S(), C(u, void 0, new r("aborted"));
|
|
192
|
+
else {
|
|
193
|
+
let e = l.indexOf(u);
|
|
194
|
+
if (e < 0) return;
|
|
195
|
+
l.splice(e, 1), C(u, void 0, new r("aborted"));
|
|
196
|
+
}
|
|
197
|
+
E();
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
i?.addEventListener("abort", u.cancel, { once: !0 }), l.push(u), E();
|
|
201
|
+
});
|
|
202
|
+
return {
|
|
203
|
+
async decodeEot(e, t) {
|
|
204
|
+
return await D(void 0, {
|
|
205
|
+
operation: "decode",
|
|
206
|
+
bytes: e,
|
|
207
|
+
maxOutputBytes: t.maxOutputBytes
|
|
208
|
+
}, t.signal);
|
|
209
|
+
},
|
|
210
|
+
async open(e, t) {
|
|
211
|
+
if (p || t.aborted) throw new r(p ? "provider-disposed" : "aborted");
|
|
212
|
+
if (d.has(e.info.id)) throw new r("duplicate-face-id");
|
|
213
|
+
d.add(e.info.id);
|
|
214
|
+
let n = {
|
|
215
|
+
info: {
|
|
216
|
+
...e.info,
|
|
217
|
+
bbox: [...e.info.bbox],
|
|
218
|
+
embedding: { ...e.info.embedding }
|
|
219
|
+
},
|
|
220
|
+
bytes: new Uint8Array(e.bytes)
|
|
221
|
+
};
|
|
222
|
+
c.set(n.info.id, n);
|
|
223
|
+
let i = n.info.id, a = () => {
|
|
224
|
+
if (!n) return;
|
|
225
|
+
let e = n;
|
|
226
|
+
if (n = void 0, c.delete(i), f.delete(a), !p) {
|
|
227
|
+
for (let t = l.length - 1; t >= 0; t--) l[t].font === e && C(l.splice(t, 1)[0], void 0, new r("face-unavailable"));
|
|
228
|
+
h?.font === e ? C(h, void 0, new r("face-unavailable")) : h &&= (l.unshift(h), void 0), S(), E();
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
f.add(a);
|
|
232
|
+
let s = () => {
|
|
233
|
+
if (!n || p) throw new r("provider-disposed");
|
|
234
|
+
return n;
|
|
235
|
+
};
|
|
236
|
+
return {
|
|
237
|
+
async shape(e, t) {
|
|
238
|
+
let n = s(), r = {
|
|
239
|
+
purpose: t.purpose,
|
|
240
|
+
script: t.script,
|
|
241
|
+
direction: t.direction,
|
|
242
|
+
language: t.language
|
|
243
|
+
};
|
|
244
|
+
return o(await D(n, {
|
|
245
|
+
operation: "shape",
|
|
246
|
+
text: e,
|
|
247
|
+
options: r
|
|
248
|
+
}, t.signal), n.info, e, t);
|
|
249
|
+
},
|
|
250
|
+
async outline(e, t) {
|
|
251
|
+
return await D(s(), {
|
|
252
|
+
operation: "outline",
|
|
253
|
+
glyphId: e,
|
|
254
|
+
purpose: t.purpose
|
|
255
|
+
}, t.signal);
|
|
256
|
+
},
|
|
257
|
+
dispose: a
|
|
258
|
+
};
|
|
259
|
+
},
|
|
260
|
+
state() {
|
|
261
|
+
return {
|
|
262
|
+
disposed: p,
|
|
263
|
+
retainedFontBytes: [...c.values()].reduce((e, t) => e + t.bytes.length, 0),
|
|
264
|
+
pendingRequests: l.length + +!!h,
|
|
265
|
+
pendingBytes: v,
|
|
266
|
+
workerActive: !!m
|
|
267
|
+
};
|
|
268
|
+
},
|
|
269
|
+
dispose() {
|
|
270
|
+
if (!p) {
|
|
271
|
+
p = !0, S(), h && C(h, void 0, new r("provider-disposed"));
|
|
272
|
+
for (let e of l.splice(0)) C(e, void 0, new r("provider-disposed"));
|
|
273
|
+
for (let e of [...f]) e();
|
|
274
|
+
c.clear(), d.clear();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
};
|
|
211
278
|
}
|
|
212
|
-
export {
|
|
213
|
-
D as createWorkerFontShaper,
|
|
214
|
-
z as serveFontWorker
|
|
215
|
-
};
|
|
279
|
+
export { s as createWorkerFontShaper, a as serveFontWorker };
|