@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/dist/fonts.js CHANGED
@@ -1,200 +1,574 @@
1
- const x = {
2
- calibri: { family: "Carlito", metricCompatible: !0, cjk: !1 },
3
- "calibri light": { family: "Carlito", metricCompatible: !0, cjk: !1 },
4
- cambria: { family: "Caladea", metricCompatible: !0, cjk: !1 },
5
- "cambria math": { family: "Caladea", metricCompatible: !0, cjk: !1 },
6
- arial: { family: "Arimo", metricCompatible: !0, cjk: !1 },
7
- "arial narrow": { family: "Arimo", metricCompatible: !0, cjk: !1 },
8
- helvetica: { family: "Arimo", metricCompatible: !0, cjk: !1 },
9
- "helvetica neue": { family: "Arimo", metricCompatible: !0, cjk: !1 },
10
- "liberation sans": { family: "Arimo", metricCompatible: !0, cjk: !1 },
11
- "times new roman": { family: "Tinos", metricCompatible: !0, cjk: !1 },
12
- times: { family: "Tinos", metricCompatible: !0, cjk: !1 },
13
- "liberation serif": { family: "Tinos", metricCompatible: !0, cjk: !1 },
14
- "courier new": { family: "Cousine", metricCompatible: !0, cjk: !1 },
15
- courier: { family: "Cousine", metricCompatible: !0, cjk: !1 },
16
- consolas: { family: "Cousine", metricCompatible: !1, cjk: !1 },
17
- "liberation mono": { family: "Cousine", metricCompatible: !0, cjk: !1 },
18
- // 无度量兼容品,只能形近
19
- "segoe ui": { family: "Open Sans", metricCompatible: !1, cjk: !1 },
20
- tahoma: { family: "Open Sans", metricCompatible: !1, cjk: !1 },
21
- verdana: { family: "Open Sans", metricCompatible: !1, cjk: !1 },
22
- georgia: { family: "Tinos", metricCompatible: !1, cjk: !1 }
23
- }, $ = { latinFamily: "Arimo", latinSizeAdjust: { bold: 95.4, underscore: 74.6 } }, I = {
24
- // 黑体系
25
- 微软雅黑: { family: "Noto Sans SC", metricCompatible: !1, cjk: !0 },
26
- "microsoft yahei": { family: "Noto Sans SC", metricCompatible: !1, cjk: !0 },
27
- "microsoft yahei ui": { family: "Noto Sans SC", metricCompatible: !1, cjk: !0 },
28
- 苹方: { family: "Noto Sans SC", metricCompatible: !1, cjk: !0 },
29
- "pingfang sc": { family: "Noto Sans SC", metricCompatible: !1, cjk: !0 },
30
- 黑体: { family: "Noto Sans SC", metricCompatible: !1, cjk: !0 },
31
- simhei: { family: "Noto Sans SC", metricCompatible: !1, cjk: !0 },
32
- // 等线西文按 PowerPoint 导出实测:常规体与 Arial 等宽(0.996 倍),粗体 0.954 倍,下划线 0.415em。
33
- // Noto Sans SC 自带的西文宽出一截。参数与 core 的缺字合成字族一致,测试断言两边相同。
34
- 等线: { family: "Noto Sans SC", ...$, metricCompatible: !1, cjk: !0 },
35
- dengxian: { family: "Noto Sans SC", ...$, metricCompatible: !1, cjk: !0 },
36
- "source han sans sc": { family: "Noto Sans SC", metricCompatible: !1, cjk: !0 },
37
- 思源黑体: { family: "Noto Sans SC", metricCompatible: !1, cjk: !0 },
38
- "hiragino sans gb": { family: "Noto Sans SC", metricCompatible: !1, cjk: !0 },
39
- // 宋体系
40
- 宋体: { family: "Noto Serif SC", metricCompatible: !1, cjk: !0 },
41
- simsun: { family: "Noto Serif SC", metricCompatible: !1, cjk: !0 },
42
- 新宋体: { family: "Noto Serif SC", metricCompatible: !1, cjk: !0 },
43
- nsimsun: { family: "Noto Serif SC", metricCompatible: !1, cjk: !0 },
44
- 华文宋体: { family: "Noto Serif SC", metricCompatible: !1, cjk: !0 },
45
- stsong: { family: "Noto Serif SC", metricCompatible: !1, cjk: !0 },
46
- 思源宋体: { family: "Noto Serif SC", metricCompatible: !1, cjk: !0 },
47
- "source han serif sc": { family: "Noto Serif SC", metricCompatible: !1, cjk: !0 },
48
- // 楷体:霞鹜文楷的 OFL 头里有一条附加许可,明确允许「专用于 web font 分发」
49
- // 的子集 / WOFF2 转换保留原名,正好是这里的用法
50
- 楷体: { family: "LXGW WenKai", metricCompatible: !1, cjk: !0 },
51
- kaiti: { family: "LXGW WenKai", metricCompatible: !1, cjk: !0 },
52
- 华文楷体: { family: "LXGW WenKai", metricCompatible: !1, cjk: !0 },
53
- stkaiti: { family: "LXGW WenKai", metricCompatible: !1, cjk: !0 },
54
- // 仿宋没有对位的免费品,退到宋体系比退到黑体近
55
- 仿宋: { family: "Noto Serif SC", metricCompatible: !1, cjk: !0 },
56
- fangsong: { family: "Noto Serif SC", metricCompatible: !1, cjk: !0 }
57
- }, L = { ...x, ...I }, W = /^(wingdings|webdings|symbol|marlett)/i;
58
- function M(i, t) {
59
- const e = i.trim().toLowerCase();
60
- return !e || W.test(e) ? null : (t == null ? void 0 : t[e]) ?? L[e] ?? null;
61
- }
62
- const F = "https://cdn.jsdelivr.net/npm", O = {
63
- Carlito: { pkg: "@fontsource/carlito", version: "5.3.0", weights: [400, 700], italics: [400, 700] },
64
- Caladea: { pkg: "@fontsource/caladea", version: "5.3.0", weights: [400, 700], italics: [400, 700] },
65
- Arimo: { pkg: "@fontsource/arimo", version: "5.3.0", weights: [400, 500, 600, 700], italics: [400, 500, 600, 700] },
66
- Tinos: { pkg: "@fontsource/tinos", version: "5.3.0", weights: [400, 700], italics: [400, 700] },
67
- Cousine: { pkg: "@fontsource/cousine", version: "5.3.0", weights: [400, 700], italics: [400, 700] },
68
- "Open Sans": { pkg: "@fontsource/open-sans", version: "5.3.0", weights: [300, 400, 500, 600, 700, 800], italics: [300, 400, 500, 600, 700, 800] },
69
- "Noto Sans SC": { pkg: "@fontsource/noto-sans-sc", version: "5.3.0", weights: [100, 200, 300, 400, 500, 600, 700, 800, 900], italics: [] },
70
- "Noto Serif SC": { pkg: "@fontsource/noto-serif-sc", version: "5.3.0", weights: [200, 300, 400, 500, 600, 700, 800, 900], italics: [] },
71
- // 霞鹜文楷只出 Light / Regular / Bold 三档,没有 400
72
- "LXGW WenKai": { pkg: "@fontsource/lxgw-wenkai", version: "5.3.0", weights: [300, 500, 700], italics: [] }
73
- };
74
- function E(i, t) {
75
- let e = null;
76
- for (const s of i)
77
- (e === null || Math.abs(s - t) < Math.abs(e - t)) && (e = s);
78
- return e;
79
- }
80
- function G(i, t, e, s = F) {
81
- const o = O[i];
82
- if (!o) return null;
83
- const n = e ? o.italics : o.weights, l = E(n.length ? n : o.weights, t);
84
- if (l === null) return null;
85
- const a = e && o.italics.includes(l);
86
- return `${s}/${o.pkg}@${o.version}/${l}${a ? "-italic" : ""}.css`;
87
- }
88
- let C = null, T = !1;
89
- function K(i) {
90
- if (T) return C;
91
- T = !0;
92
- try {
93
- const t = i.createElement("canvas").getContext("2d");
94
- C = t && typeof t.measureText == "function" ? t : null;
95
- } catch {
96
- C = null;
97
- }
98
- return C;
99
- }
100
- const A = "MMMMHHHHiiiill漢字語";
101
- function U(i, t = globalThis.document) {
102
- const e = K(t);
103
- if (!e) return !1;
104
- for (const s of ["monospace", "serif"]) {
105
- e.font = `72px ${s}`;
106
- const o = e.measureText(A).width;
107
- if (e.font = `72px '${i.replace(/'/g, "")}', ${s}`, Math.abs(e.measureText(A).width - o) > 0.5) return !0;
108
- }
109
- return !1;
110
- }
111
- function X(i, t, e, s = {}) {
112
- const o = e.slice(0, e.lastIndexOf("/") + 1), n = t.replace(/['\\]/g, ""), l = i.replace(/font-family:\s*'[^']*'/g, `font-family: '${n}'`).replace(/url\(\.\/([^)]+)\)/g, (a, r) => `url(${o}${r})`);
113
- return s.preferLocal === !1 ? l : l.replace(/src:\s*url\(/g, `src: local('${n}'), url(`);
114
- }
115
- function P(i, t) {
116
- var s;
117
- const e = (s = i.match(/unicode-range:\s*([^;}]*)/)) == null ? void 0 : s[1];
118
- return e ? e.split(",").some((o) => {
119
- const [n, l = n] = o.trim().replace(/^U\+/i, "").split("-"), a = parseInt(n.replace(/\?/g, "0"), 16), r = parseInt(l.replace(/\?/g, "F"), 16);
120
- return t >= a && t <= r;
121
- }) : !0;
122
- }
123
- function _(i, t, e) {
124
- const s = i.match(/@font-face\s*\{[^}]*\}/g) ?? [], o = (a, r) => a.replace(/\s*\}$/, `
125
- size-adjust: ${r}%;
126
- }`), n = t >= 600 ? s.map((a) => o(a, e.bold)) : [...s], l = s.find((a) => P(a, 95));
127
- if (l) {
128
- const a = /unicode-range:/.test(l) ? l.replace(/unicode-range:\s*[^;}]*/, "unicode-range: U+5F") : l.replace(/\s*\}$/, `
129
- unicode-range: U+5F;
130
- }`);
131
- n.push(o(a, e.underscore));
132
- }
133
- return n.join(`
134
- `);
135
- }
136
- const u = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Map(), z = /[\u0000-\u024f\u1e00-\u1eff\u2000-\u206f]/;
137
- async function B(i) {
138
- let t = d.get(i);
139
- return t || (t = fetch(i).then((e) => e.ok ? e.text() : null).catch(() => null).then((e) => (e === null && d.delete(i), e)), d.set(i, t)), t;
140
- }
141
- async function H(i, t = {}) {
142
- const e = t.document ?? globalThis.document, s = t.base ?? F, o = t.skipInstalled !== !1;
143
- if (!e || typeof fetch != "function") return [];
144
- const n = i.map(async (l) => {
145
- const { family: a } = l, r = [...u].some((f) => f.startsWith(`${a}|`));
146
- if (o && !r && U(a, e)) return { family: a, status: "installed" };
147
- const c = M(a, t.overrides);
148
- if (!c) return { family: a, status: "unmapped" };
149
- if (c.cjk && t.cjk === !1) return { family: a, status: "skipped-cjk" };
150
- const j = /* @__PURE__ */ new Set();
151
- for (const f of l.styles) {
152
- const m = f.bold ? 700 : 400;
153
- j.add(`${m}|${c.cjk ? !1 : f.italic}`);
154
- }
155
- let S = !1;
156
- for (const f of j) {
157
- const [m, g] = f.split("|"), v = [c.family, ...c.latinFamily && z.test(l.chars) ? [c.latinFamily] : []];
158
- for (const b of v) {
159
- const y = G(b, Number(m), g === "true", s);
160
- if (!y) continue;
161
- const h = `${a}|${f}|${b}`;
162
- if (u.has(h)) continue;
163
- const w = await B(y);
164
- if (!w) continue;
165
- u.add(h);
166
- const p = e.createElement("style");
167
- p.dataset.webPptFont = a, c.cjk && (p.dataset.webPptCjk = "1");
168
- const k = b === c.latinFamily ? c.latinSizeAdjust : void 0, N = X(w, a, y, { preferLocal: !k });
169
- p.textContent = k ? _(N, Number(m), k) : N, e.head.appendChild(p);
170
- }
171
- try {
172
- await e.fonts.load(`${g === "true" ? "italic " : ""}${m} 16px '${a}'`, l.chars), S = !0;
173
- } catch {
174
- }
175
- }
176
- return S ? { family: a, status: "substituted", substitute: c.family } : { family: a, status: "failed" };
177
- });
178
- return Promise.all(n);
179
- }
180
- function D(i = {}) {
181
- const t = i.document ?? globalThis.document;
182
- if (!t) return;
183
- const e = i.cjkOnly ? "style[data-web-ppt-cjk]" : "style[data-web-ppt-font]";
184
- for (const s of t.querySelectorAll(e)) {
185
- for (const o of [...u])
186
- o.startsWith(`${s.dataset.webPptFont}|`) && u.delete(o);
187
- s.remove();
188
- }
189
- }
190
- export {
191
- F as DEFAULT_BASE,
192
- O as PACKAGES,
193
- L as SUBSTITUTIONS,
194
- G as cssUrl,
195
- U as isInstalled,
196
- H as loadFontsFor,
197
- X as rewriteFontFaceCss,
198
- M as substituteFor,
199
- D as unloadFonts
1
+ // src/substitute.ts
2
+ var e = {
3
+ calibri: {
4
+ family: "Carlito",
5
+ metricCompatible: !0,
6
+ cjk: !1
7
+ },
8
+ "calibri light": {
9
+ family: "Carlito",
10
+ metricCompatible: !0,
11
+ cjk: !1
12
+ },
13
+ cambria: {
14
+ family: "Caladea",
15
+ metricCompatible: !0,
16
+ cjk: !1
17
+ },
18
+ "cambria math": {
19
+ family: "Caladea",
20
+ metricCompatible: !0,
21
+ cjk: !1
22
+ },
23
+ arial: {
24
+ family: "Arimo",
25
+ metricCompatible: !0,
26
+ cjk: !1
27
+ },
28
+ "arial narrow": {
29
+ family: "Arimo",
30
+ metricCompatible: !0,
31
+ cjk: !1
32
+ },
33
+ helvetica: {
34
+ family: "Arimo",
35
+ metricCompatible: !0,
36
+ cjk: !1
37
+ },
38
+ "helvetica neue": {
39
+ family: "Arimo",
40
+ metricCompatible: !0,
41
+ cjk: !1
42
+ },
43
+ "liberation sans": {
44
+ family: "Arimo",
45
+ metricCompatible: !0,
46
+ cjk: !1
47
+ },
48
+ "times new roman": {
49
+ family: "Tinos",
50
+ metricCompatible: !0,
51
+ cjk: !1
52
+ },
53
+ times: {
54
+ family: "Tinos",
55
+ metricCompatible: !0,
56
+ cjk: !1
57
+ },
58
+ "liberation serif": {
59
+ family: "Tinos",
60
+ metricCompatible: !0,
61
+ cjk: !1
62
+ },
63
+ "courier new": {
64
+ family: "Cousine",
65
+ metricCompatible: !0,
66
+ cjk: !1
67
+ },
68
+ courier: {
69
+ family: "Cousine",
70
+ metricCompatible: !0,
71
+ cjk: !1
72
+ },
73
+ consolas: {
74
+ family: "Cousine",
75
+ metricCompatible: !1,
76
+ cjk: !1
77
+ },
78
+ "liberation mono": {
79
+ family: "Cousine",
80
+ metricCompatible: !0,
81
+ cjk: !1
82
+ },
83
+ "segoe ui": {
84
+ family: "Open Sans",
85
+ metricCompatible: !1,
86
+ cjk: !1
87
+ },
88
+ tahoma: {
89
+ family: "Open Sans",
90
+ metricCompatible: !1,
91
+ cjk: !1
92
+ },
93
+ verdana: {
94
+ family: "Open Sans",
95
+ metricCompatible: !1,
96
+ cjk: !1
97
+ },
98
+ georgia: {
99
+ family: "Tinos",
100
+ metricCompatible: !1,
101
+ cjk: !1
102
+ }
103
+ }, t = {
104
+ latinFamily: "Arimo",
105
+ latinSizeAdjust: {
106
+ bold: 95.4,
107
+ underscore: 74.6
108
+ }
109
+ }, n = {
110
+ 微软雅黑: {
111
+ family: "Noto Sans SC",
112
+ metricCompatible: !1,
113
+ cjk: !0
114
+ },
115
+ "microsoft yahei": {
116
+ family: "Noto Sans SC",
117
+ metricCompatible: !1,
118
+ cjk: !0
119
+ },
120
+ "microsoft yahei ui": {
121
+ family: "Noto Sans SC",
122
+ metricCompatible: !1,
123
+ cjk: !0
124
+ },
125
+ 苹方: {
126
+ family: "Noto Sans SC",
127
+ metricCompatible: !1,
128
+ cjk: !0
129
+ },
130
+ "pingfang sc": {
131
+ family: "Noto Sans SC",
132
+ metricCompatible: !1,
133
+ cjk: !0
134
+ },
135
+ 黑体: {
136
+ family: "Noto Sans SC",
137
+ metricCompatible: !1,
138
+ cjk: !0
139
+ },
140
+ simhei: {
141
+ family: "Noto Sans SC",
142
+ metricCompatible: !1,
143
+ cjk: !0
144
+ },
145
+ 等线: {
146
+ family: "Noto Sans SC",
147
+ ...t,
148
+ metricCompatible: !1,
149
+ cjk: !0
150
+ },
151
+ dengxian: {
152
+ family: "Noto Sans SC",
153
+ ...t,
154
+ metricCompatible: !1,
155
+ cjk: !0
156
+ },
157
+ "source han sans sc": {
158
+ family: "Noto Sans SC",
159
+ metricCompatible: !1,
160
+ cjk: !0
161
+ },
162
+ 思源黑体: {
163
+ family: "Noto Sans SC",
164
+ metricCompatible: !1,
165
+ cjk: !0
166
+ },
167
+ "hiragino sans gb": {
168
+ family: "Noto Sans SC",
169
+ metricCompatible: !1,
170
+ cjk: !0
171
+ },
172
+ 宋体: {
173
+ family: "Noto Serif SC",
174
+ metricCompatible: !1,
175
+ cjk: !0
176
+ },
177
+ simsun: {
178
+ family: "Noto Serif SC",
179
+ metricCompatible: !1,
180
+ cjk: !0
181
+ },
182
+ 新宋体: {
183
+ family: "Noto Serif SC",
184
+ metricCompatible: !1,
185
+ cjk: !0
186
+ },
187
+ nsimsun: {
188
+ family: "Noto Serif SC",
189
+ metricCompatible: !1,
190
+ cjk: !0
191
+ },
192
+ 华文宋体: {
193
+ family: "Noto Serif SC",
194
+ metricCompatible: !1,
195
+ cjk: !0
196
+ },
197
+ stsong: {
198
+ family: "Noto Serif SC",
199
+ metricCompatible: !1,
200
+ cjk: !0
201
+ },
202
+ 思源宋体: {
203
+ family: "Noto Serif SC",
204
+ metricCompatible: !1,
205
+ cjk: !0
206
+ },
207
+ "source han serif sc": {
208
+ family: "Noto Serif SC",
209
+ metricCompatible: !1,
210
+ cjk: !0
211
+ },
212
+ 楷体: {
213
+ family: "LXGW WenKai",
214
+ metricCompatible: !1,
215
+ cjk: !0
216
+ },
217
+ kaiti: {
218
+ family: "LXGW WenKai",
219
+ metricCompatible: !1,
220
+ cjk: !0
221
+ },
222
+ 华文楷体: {
223
+ family: "LXGW WenKai",
224
+ metricCompatible: !1,
225
+ cjk: !0
226
+ },
227
+ stkaiti: {
228
+ family: "LXGW WenKai",
229
+ metricCompatible: !1,
230
+ cjk: !0
231
+ },
232
+ 仿宋: {
233
+ family: "Noto Serif SC",
234
+ metricCompatible: !1,
235
+ cjk: !0
236
+ },
237
+ fangsong: {
238
+ family: "Noto Serif SC",
239
+ metricCompatible: !1,
240
+ cjk: !0
241
+ }
242
+ }, r = {
243
+ ...e,
244
+ ...n
245
+ }, i = /^(wingdings|webdings|symbol|marlett)/i;
246
+ function a(e, t) {
247
+ let n = e.trim().toLowerCase();
248
+ return !n || i.test(n) ? null : t?.[n] ?? r[n] ?? null;
249
+ }
250
+ // src/sources.ts
251
+ var o = "https://cdn.jsdelivr.net/npm", s = {
252
+ Carlito: {
253
+ pkg: "@fontsource/carlito",
254
+ version: "5.3.0",
255
+ weights: [400, 700],
256
+ italics: [400, 700]
257
+ },
258
+ Caladea: {
259
+ pkg: "@fontsource/caladea",
260
+ version: "5.3.0",
261
+ weights: [400, 700],
262
+ italics: [400, 700]
263
+ },
264
+ Arimo: {
265
+ pkg: "@fontsource/arimo",
266
+ version: "5.3.0",
267
+ weights: [
268
+ 400,
269
+ 500,
270
+ 600,
271
+ 700
272
+ ],
273
+ italics: [
274
+ 400,
275
+ 500,
276
+ 600,
277
+ 700
278
+ ]
279
+ },
280
+ Tinos: {
281
+ pkg: "@fontsource/tinos",
282
+ version: "5.3.0",
283
+ weights: [400, 700],
284
+ italics: [400, 700]
285
+ },
286
+ Cousine: {
287
+ pkg: "@fontsource/cousine",
288
+ version: "5.3.0",
289
+ weights: [400, 700],
290
+ italics: [400, 700]
291
+ },
292
+ "Open Sans": {
293
+ pkg: "@fontsource/open-sans",
294
+ version: "5.3.0",
295
+ weights: [
296
+ 300,
297
+ 400,
298
+ 500,
299
+ 600,
300
+ 700,
301
+ 800
302
+ ],
303
+ italics: [
304
+ 300,
305
+ 400,
306
+ 500,
307
+ 600,
308
+ 700,
309
+ 800
310
+ ]
311
+ },
312
+ "Noto Sans SC": {
313
+ pkg: "@fontsource/noto-sans-sc",
314
+ version: "5.3.0",
315
+ weights: [
316
+ 100,
317
+ 200,
318
+ 300,
319
+ 400,
320
+ 500,
321
+ 600,
322
+ 700,
323
+ 800,
324
+ 900
325
+ ],
326
+ italics: []
327
+ },
328
+ "Noto Serif SC": {
329
+ pkg: "@fontsource/noto-serif-sc",
330
+ version: "5.3.0",
331
+ weights: [
332
+ 200,
333
+ 300,
334
+ 400,
335
+ 500,
336
+ 600,
337
+ 700,
338
+ 800,
339
+ 900
340
+ ],
341
+ italics: []
342
+ },
343
+ "LXGW WenKai": {
344
+ pkg: "@fontsource/lxgw-wenkai",
345
+ version: "5.3.0",
346
+ weights: [
347
+ 300,
348
+ 500,
349
+ 700
350
+ ],
351
+ italics: []
352
+ }
200
353
  };
354
+ function c(e, t) {
355
+ let n = null;
356
+ for (let r of e) (n === null || Math.abs(r - t) < Math.abs(n - t)) && (n = r);
357
+ return n;
358
+ }
359
+ function l(e, t, n, r = o) {
360
+ let i = s[e];
361
+ if (!i) return null;
362
+ let a = n ? i.italics : i.weights, l = c(a.length ? a : i.weights, t);
363
+ if (l === null) return null;
364
+ let u = n && i.italics.includes(l);
365
+ return `${r}/${i.pkg}@${i.version}/${l}${u ? "-italic" : ""}.css`;
366
+ }
367
+ // src/load.ts
368
+ var u = null, d = !1;
369
+ function f(e) {
370
+ if (d) return u;
371
+ d = !0;
372
+ try {
373
+ let t = e.createElement("canvas").getContext("2d");
374
+ u = t && typeof t.measureText == "function" ? t : null;
375
+ } catch {
376
+ u = null;
377
+ }
378
+ return u;
379
+ }
380
+ var p = "MMMMHHHHiiiill漢字語";
381
+ function m(e, t = globalThis.document) {
382
+ let n = f(t);
383
+ if (!n) return !1;
384
+ for (let t of ["monospace", "serif"]) {
385
+ n.font = `72px ${t}`;
386
+ let r = n.measureText(p).width;
387
+ if (n.font = `72px '${e.replace(/'/g, "")}', ${t}`, Math.abs(n.measureText(p).width - r) > .5) return !0;
388
+ }
389
+ return !1;
390
+ }
391
+ function h(e, t, n, r = {}) {
392
+ let i = n.slice(0, n.lastIndexOf("/") + 1), a = t.replace(/['\\]/g, ""), o = e.replace(/font-family:\s*'[^']*'/g, `font-family: '${a}'`).replace(/url\(\.\/([^)]+)\)/g, (e, t) => `url(${i}${t})`);
393
+ return r.preferLocal === !1 ? o : o.replace(/src:\s*url\(/g, `src: local('${a}'), url(`);
394
+ }
395
+ function g(e, t) {
396
+ let n = e.match(/unicode-range:\s*([^;}]*)/)?.[1];
397
+ return !n || n.split(",").some((e) => {
398
+ let [n, r = n] = e.trim().replace(/^U\+/i, "").split("-"), i = parseInt(n.replace(/\?/g, "0"), 16), a = parseInt(r.replace(/\?/g, "F"), 16);
399
+ return t >= i && t <= a;
400
+ });
401
+ }
402
+ function _(e, t, n) {
403
+ let r = e.match(/@font-face\s*\{[^}]*\}/g) ?? [], i = (e, t) => e.replace(/\s*\}$/, `\n size-adjust: ${t}%;\n}`), a = t >= 600 ? r.map((e) => i(e, n.bold)) : [...r], o = r.find((e) => g(e, 95));
404
+ if (o) {
405
+ let e = /unicode-range:/.test(o) ? o.replace(/unicode-range:\s*[^;}]*/, "unicode-range: U+5F") : o.replace(/\s*\}$/, "\n unicode-range: U+5F;\n}");
406
+ a.push(i(e, n.underscore));
407
+ }
408
+ return a.join("\n");
409
+ }
410
+ var v = /* @__PURE__ */ new Set(), y = /* @__PURE__ */ new Map(), b = /[\u0000-\u024f\u1e00-\u1eff\u2000-\u206f]/;
411
+ async function x(e) {
412
+ let t = y.get(e);
413
+ return t || (t = fetch(e).then((e) => e.ok ? e.text() : null).catch(() => null).then((t) => (t === null && y.delete(e), t)), y.set(e, t)), t;
414
+ }
415
+ async function S(e, t = {}) {
416
+ let n = t.document ?? globalThis.document, r = t.base ?? "https://cdn.jsdelivr.net/npm", i = t.skipInstalled !== !1;
417
+ if (!n || typeof fetch != "function") return [];
418
+ let o = e.map(async (e) => {
419
+ let { family: o } = e, s = [...v].some((e) => e.startsWith(`${o}|`));
420
+ if (i && !s && m(o, n)) return {
421
+ family: o,
422
+ status: "installed"
423
+ };
424
+ let c = a(o, t.overrides);
425
+ if (!c) return {
426
+ family: o,
427
+ status: "unmapped"
428
+ };
429
+ if (c.cjk && t.cjk === !1) return {
430
+ family: o,
431
+ status: "skipped-cjk"
432
+ };
433
+ let u = /* @__PURE__ */ new Set();
434
+ for (let t of e.styles) {
435
+ let e = t.bold ? 700 : 400;
436
+ u.add(`${e}|${!c.cjk && t.italic}`);
437
+ }
438
+ let d = !1;
439
+ for (let t of u) {
440
+ let [i, a] = t.split("|"), s = [c.family, ...c.latinFamily && b.test(e.chars) ? [c.latinFamily] : []];
441
+ for (let e of s) {
442
+ let s = l(e, Number(i), a === "true", r);
443
+ if (!s) continue;
444
+ let u = `${o}|${t}|${e}`;
445
+ if (v.has(u)) continue;
446
+ let d = await x(s);
447
+ if (!d) continue;
448
+ v.add(u);
449
+ let f = n.createElement("style");
450
+ f.dataset.webPptFont = o, c.cjk && (f.dataset.webPptCjk = "1");
451
+ let p = e === c.latinFamily ? c.latinSizeAdjust : void 0, m = h(d, o, s, { preferLocal: !p });
452
+ f.textContent = p ? _(m, Number(i), p) : m, n.head.appendChild(f);
453
+ }
454
+ try {
455
+ await n.fonts.load(`${a === "true" ? "italic " : ""}${i} 16px '${o}'`, e.chars), d = !0;
456
+ } catch {}
457
+ }
458
+ return d ? {
459
+ family: o,
460
+ status: "substituted",
461
+ substitute: c.family
462
+ } : {
463
+ family: o,
464
+ status: "failed"
465
+ };
466
+ });
467
+ return Promise.all(o);
468
+ }
469
+ function C(e = {}) {
470
+ let t = e.document ?? globalThis.document;
471
+ if (!t) return;
472
+ let n = e.cjkOnly ? "style[data-web-ppt-cjk]" : "style[data-web-ppt-font]";
473
+ for (let e of t.querySelectorAll(n)) {
474
+ for (let t of [...v]) t.startsWith(`${e.dataset.webPptFont}|`) && v.delete(t);
475
+ e.remove();
476
+ }
477
+ }
478
+ // src/export-faces.ts
479
+ function w(e) {
480
+ let t = [];
481
+ for (let n of e.split(",")) {
482
+ let e = n.trim().match(/^U\+([0-9a-f?]{1,6})(?:-([0-9a-f]{1,6}))?$/i);
483
+ e && t.push([Number.parseInt(e[1].replace(/\?/g, "0"), 16), e[2] === void 0 ? Number.parseInt(e[1].replace(/\?/g, "F"), 16) : Number.parseInt(e[2], 16)]);
484
+ }
485
+ return t;
486
+ }
487
+ function T(e, t) {
488
+ for (let n of t) {
489
+ let t = n.codePointAt(0);
490
+ if (e.some(([e, n]) => t >= e && t <= n)) return !0;
491
+ }
492
+ return !1;
493
+ }
494
+ function E(e) {
495
+ let t = e.match(/unicode-range:\s*([^;}]*)/)?.[1];
496
+ if (!t) return null;
497
+ let n = w(t);
498
+ if (!n.length) return null;
499
+ let r = (e) => e.toString(16).toUpperCase().padStart(4, "0");
500
+ return n.map(([e, t]) => `U+${r(e)}-${r(t)}`).join(",");
501
+ }
502
+ var D = /* @__PURE__ */ new Map();
503
+ function O(e) {
504
+ let t = "";
505
+ for (let n = 0; n < e.length; n += 32768) t += String.fromCharCode(...e.subarray(n, n + 32768));
506
+ return btoa(t);
507
+ }
508
+ async function k(e) {
509
+ let t = D.get(e);
510
+ return t || (t = fetch(e).then(async (e) => {
511
+ if (!e.ok) throw Error(`HTTP ${e.status}`);
512
+ return `data:font/woff2;base64,${O(new Uint8Array(await e.arrayBuffer()))}`;
513
+ }).catch(() => null).then((t) => (t === null && D.delete(e), t)), D.set(e, t)), t;
514
+ }
515
+ async function A(e, t) {
516
+ let n = a(e.family, t.overrides);
517
+ if (!n || n.cjk && t.cjk === !1 || t.skipInstalled && t.document && m(e.family, t.document)) return [];
518
+ let r = /* @__PURE__ */ new Set();
519
+ for (let t of e.styles) r.add(`${t.bold ? 700 : 400}|${!n.cjk && t.italic}`);
520
+ let i = [];
521
+ for (let a of r) {
522
+ let [r, o] = a.split("|"), s = Number(r), c = s === 700, u = o === "true", d = [n.family, ...n.latinFamily && b.test(e.chars) ? [n.latinFamily] : []];
523
+ for (let r of d) {
524
+ let a = l(r, s, u, t.base ?? "https://cdn.jsdelivr.net/npm");
525
+ if (!a) continue;
526
+ let o = await x(a);
527
+ if (!o) {
528
+ t.onIssue?.({
529
+ family: e.family,
530
+ reason: "css-unavailable"
531
+ });
532
+ continue;
533
+ }
534
+ let d = n.latinSizeAdjust && r === n.latinFamily ? n.latinSizeAdjust : void 0, f = null;
535
+ for (let n of o.match(/@font-face\s*\{[^}]*\}/g) ?? []) {
536
+ let r = E(n);
537
+ if (r && !T(w(r), e.chars)) continue;
538
+ let o = n.match(/url\(([^)]+)\)/)?.[1]?.replace(/^['"]|['"]$/g, "");
539
+ if (!o) continue;
540
+ let s = await k(o.startsWith("./") ? `${a.slice(0, a.lastIndexOf("/") + 1)}${o.slice(2)}` : o);
541
+ s ? (d && c ? i.push({
542
+ family: e.family,
543
+ src: s,
544
+ bold: c,
545
+ italic: u,
546
+ unicodeRange: r ?? void 0,
547
+ sizeAdjust: d.bold
548
+ }) : i.push({
549
+ family: e.family,
550
+ src: s,
551
+ bold: c,
552
+ italic: u,
553
+ unicodeRange: r ?? void 0
554
+ }), d && r && T(w(r), "_") && (f = s)) : t.onIssue?.({
555
+ family: e.family,
556
+ reason: "slice-unavailable"
557
+ });
558
+ }
559
+ d && f && e.chars.includes("_") && i.push({
560
+ family: e.family,
561
+ src: f,
562
+ bold: c,
563
+ italic: u,
564
+ unicodeRange: "U+5F",
565
+ sizeAdjust: d.underscore
566
+ });
567
+ }
568
+ }
569
+ return i;
570
+ }
571
+ async function j(e, t = {}) {
572
+ return typeof fetch == "function" ? (await Promise.all(e.map((e) => A(e, t)))).flat() : [];
573
+ }
574
+ export { o as DEFAULT_BASE, s as PACKAGES, r as SUBSTITUTIONS, l as cssUrl, j as exportFontFaces, m as isInstalled, S as loadFontsFor, h as rewriteFontFaceCss, a as substituteFor, C as unloadFonts };