@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.
@@ -0,0 +1,12 @@
1
+ import type { FontSubsetter } from '@web-ppt/core';
2
+ /**
3
+ * 用 harfbuzzjs 的 `harfbuzz-subset.wasm` 构造导出子集化引擎。
4
+ *
5
+ * 与 `glyphs/harfbuzz` 的整形适配器同一形态:wasm 字节由宿主提供(vite 里
6
+ * `import wasmUrl from 'harfbuzzjs/dist/harfbuzz-subset.wasm?url'` 后 fetch),
7
+ * 本包不携带、不下载任何字体字节或 WASM。
8
+ *
9
+ * 确定性:hb-subset 对同输入同参数输出相同字节;本函数不引入时间戳与随机数,
10
+ * 满足 `FontSubsetter` 的快照要求。
11
+ */
12
+ export declare function createHarfBuzzSubsetter(wasm: BufferSource): Promise<FontSubsetter>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 导出子集化引擎入口。
3
+ *
4
+ * `createHarfBuzzSubsetter` 是 HarfBuzz 适配器;wasm 与字体字节都由宿主提供。
5
+ * 产出的 `FontSubsetter` 直接作为 core 导出选项 `fonts.subsetter` 传入。
6
+ */
7
+ export { createHarfBuzzSubsetter } from './harfbuzz';
package/dist/subset.js ADDED
@@ -0,0 +1,64 @@
1
+ // src/subset/harfbuzz.ts
2
+ var e = {
3
+ ok: !1,
4
+ reason: "subset-failed"
5
+ };
6
+ function t(t) {
7
+ return WebAssembly.instantiate(t, {}).then(({ instance: t }) => {
8
+ let n = t.exports;
9
+ if (typeof n.hb_subset_or_fail != "function" || !n.memory || typeof n.malloc != "function") throw Error("传入的 wasm 不是 harfbuzz-subset 构建:缺少 hb_subset_or_fail / memory / malloc 导出");
10
+ n._initialize?.();
11
+ let r = !1;
12
+ return {
13
+ subset: async (t) => {
14
+ if (r) throw Error("subsetter 已释放,不能继续子集化");
15
+ if (t.mime !== "font/ttf" && t.mime !== "font/otf") return e;
16
+ let { bytes: i } = t, a = n.malloc(i.length);
17
+ if (!a) return e;
18
+ let o = 0;
19
+ try {
20
+ if (new Uint8Array(n.memory.buffer).set(i, a), o = n.hb_blob_create(a, i.length, 1, 0, 0), !o) return e;
21
+ let r = n.hb_face_create(o, 0);
22
+ if (!r) return e;
23
+ try {
24
+ let i = n.hb_subset_input_create_or_fail();
25
+ if (!i) return e;
26
+ try {
27
+ let a = n.hb_subset_input_unicode_set(i);
28
+ for (let e of t.chars) n.hb_set_add(a, e.codePointAt(0) ?? 0);
29
+ n.hb_subset_input_pin_all_axes_to_default(i, r);
30
+ let o = n.hb_subset_or_fail(r, i);
31
+ if (!o) return e;
32
+ try {
33
+ let r = n.hb_face_reference_blob(o);
34
+ if (!r) return e;
35
+ try {
36
+ let i = n.hb_blob_get_length(r), a = n.hb_blob_get_data(r, 0);
37
+ return !i || !a ? e : {
38
+ ok: !0,
39
+ bytes: new Uint8Array(n.memory.buffer).slice(a, a + i),
40
+ mime: t.mime
41
+ };
42
+ } finally {
43
+ n.hb_blob_destroy(r);
44
+ }
45
+ } finally {
46
+ n.hb_face_destroy(o);
47
+ }
48
+ } finally {
49
+ n.hb_subset_input_destroy(i);
50
+ }
51
+ } finally {
52
+ n.hb_face_destroy(r);
53
+ }
54
+ } finally {
55
+ o && n.hb_blob_destroy(o), n.free(a);
56
+ }
57
+ },
58
+ dispose() {
59
+ r = !0;
60
+ }
61
+ };
62
+ });
63
+ }
64
+ export { t as createHarfBuzzSubsetter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@web-ppt/fonts",
3
- "version": "0.8.0",
3
+ "version": "0.9.0-beta.1",
4
4
  "description": "Font substitution and on-demand web-font loading for PowerPoint decks: metric-compatible free substitutes plus a unicode-range slice loader. Zero font bytes in the package.",
5
5
  "keywords": [
6
6
  "pptx",
@@ -25,6 +25,9 @@
25
25
  "directory": "packages/fonts"
26
26
  },
27
27
  "type": "module",
28
+ "engines": {
29
+ "node": ">=22"
30
+ },
28
31
  "sideEffects": false,
29
32
  "main": "./dist/fonts.js",
30
33
  "module": "./dist/fonts.js",
@@ -50,6 +53,10 @@
50
53
  "types": "./dist/glyphs/browser.d.ts",
51
54
  "import": "./dist/glyphs-browser.js"
52
55
  },
56
+ "./subset": {
57
+ "types": "./dist/subset/index.d.ts",
58
+ "import": "./dist/subset.js"
59
+ },
53
60
  "./package.json": "./package.json"
54
61
  },
55
62
  "files": [
@@ -64,7 +71,7 @@
64
71
  "prepack": "node ../../tooling/sync-package-docs.mjs"
65
72
  },
66
73
  "peerDependencies": {
67
- "@web-ppt/core": "^0.8.0"
74
+ "@web-ppt/core": "0.9.0-beta.1"
68
75
  },
69
76
  "publishConfig": {
70
77
  "access": "public"
@@ -1,16 +0,0 @@
1
- class i extends Error {
2
- constructor(t, n, r) {
3
- super(t), this.reason = t, this.missing = n, this.range = r;
4
- }
5
- }
6
- function o() {
7
- throw new i("invalid-font");
8
- }
9
- function e() {
10
- throw new i("resource-limit");
11
- }
12
- export {
13
- i as F,
14
- o as i,
15
- e as r
16
- };