@takumi-rs/wasm 2.0.0-beta.1 → 2.0.0-beta.11

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/bundlers/bun.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import * as wasm from "../dist/export";
1
+ import * as wasm from "../dist/export.mjs";
2
2
  import wasmPath from "../pkg/takumi_wasm_bg.wasm";
3
3
 
4
4
  const wasmBytes = await Bun.file(new URL(wasmPath, import.meta.url)).arrayBuffer();
5
5
 
6
6
  wasm.initSync({ module: wasmBytes });
7
7
 
8
- export * from "../dist/export";
8
+ export * from "../dist/export.mjs";
9
9
  export default wasm.default;
package/bundlers/node.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import { readFileSync } from "node:fs";
2
- import * as wasm from "../dist/export";
2
+ import * as wasm from "../dist/export.mjs";
3
3
 
4
4
  const wasmBytes = readFileSync(new URL("../pkg/takumi_wasm_bg.wasm", import.meta.url));
5
5
 
6
6
  wasm.initSync({ module: wasmBytes });
7
7
 
8
- export * from "../dist/export";
8
+ export * from "../dist/export.mjs";
9
9
  export default wasm.default;
package/bundlers/vite.mjs CHANGED
@@ -1,18 +1,31 @@
1
1
  import url from "../pkg/takumi_wasm_bg.wasm?url";
2
2
 
3
+ // `?url` is a browser path; map it to a file for server reads. Vite emits the asset next to the
4
+ // importing server chunk, so resolve relative to import.meta.url, not the framework output dir.
3
5
  async function processUrl() {
4
6
  if (typeof process !== "undefined" && process.versions?.node != null) {
5
7
  const { readFile } = await import("node:fs/promises");
8
+ const path = decodeURIComponent(url.replace(/[?#].*$/, ""));
6
9
 
7
- if (!url.startsWith("/")) {
8
- return readFile(new URL(url, import.meta.url));
10
+ // Dev SSR serves an `/@fs/<abs-path>` URL.
11
+ if (path.startsWith("/@fs/")) {
12
+ return readFile(path.slice("/@fs".length));
9
13
  }
10
14
 
11
- for (const candidate of [`../client${url}`, `../../client${url}`]) {
15
+ if (!path.startsWith("/")) {
16
+ return readFile(new URL(path, import.meta.url));
17
+ }
18
+
19
+ const basename = path.slice(path.lastIndexOf("/") + 1);
20
+ const candidates = [`./${basename}`, `../client${path}`, `../../client${path}`];
21
+
22
+ let lastError;
23
+ for (const candidate of candidates) {
12
24
  try {
13
25
  return await readFile(new URL(candidate, import.meta.url));
14
26
  } catch (error) {
15
27
  if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
28
+ lastError = error;
16
29
  continue;
17
30
  }
18
31
 
@@ -20,7 +33,7 @@ async function processUrl() {
20
33
  }
21
34
  }
22
35
 
23
- throw new Error(`Unable to locate Takumi WASM asset for SSR: ${url}`);
36
+ throw new Error(`Unable to locate Takumi WASM asset for SSR: ${url}`, { cause: lastError });
24
37
  }
25
38
 
26
39
  return fetch(new URL(url, import.meta.url)).then((response) => response.arrayBuffer());
package/dist/export.cjs CHANGED
@@ -152,10 +152,10 @@ function __wbg_get_imports() {
152
152
  __proto__: null,
153
153
  "./takumi_wasm_bg.js": {
154
154
  __proto__: null,
155
- __wbg_Error_fdd633d4bb5dd76a: function(arg0, arg1) {
155
+ __wbg_Error_92b29b0548f8b746: function(arg0, arg1) {
156
156
  return Error(getStringFromWasm0(arg0, arg1));
157
157
  },
158
- __wbg_Number_c4bdf66bb78f7977: function(arg0) {
158
+ __wbg_Number_9a4e0ecb0fa16705: function(arg0) {
159
159
  return Number(arg0);
160
160
  },
161
161
  __wbg_String_8564e559799eccda: function(arg0, arg1) {
@@ -164,55 +164,55 @@ function __wbg_get_imports() {
164
164
  getDataViewMemory0().setInt32(arg0 + 4, len1, true);
165
165
  getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
166
166
  },
167
- __wbg___wbindgen_bigint_get_as_i64_d9e915702856f831: function(arg0, arg1) {
167
+ __wbg___wbindgen_bigint_get_as_i64_d968e41184ae354f: function(arg0, arg1) {
168
168
  const v = arg1;
169
169
  const ret = typeof v === "bigint" ? v : void 0;
170
170
  getDataViewMemory0().setBigInt64(arg0 + 8, isLikeNone(ret) ? BigInt(0) : ret, true);
171
171
  getDataViewMemory0().setInt32(arg0 + 0, !isLikeNone(ret), true);
172
172
  },
173
- __wbg___wbindgen_boolean_get_edaed31a367ce1bd: function(arg0) {
173
+ __wbg___wbindgen_boolean_get_fa956cfa2d1bd751: function(arg0) {
174
174
  const v = arg0;
175
175
  const ret = typeof v === "boolean" ? v : void 0;
176
176
  return isLikeNone(ret) ? 16777215 : ret ? 1 : 0;
177
177
  },
178
- __wbg___wbindgen_debug_string_8a447059637473e2: function(arg0, arg1) {
178
+ __wbg___wbindgen_debug_string_c25d447a39f5578f: function(arg0, arg1) {
179
179
  const ptr1 = passStringToWasm0(debugString(arg1), wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
180
180
  const len1 = WASM_VECTOR_LEN;
181
181
  getDataViewMemory0().setInt32(arg0 + 4, len1, true);
182
182
  getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
183
183
  },
184
- __wbg___wbindgen_in_4990f46af709e33c: function(arg0, arg1) {
184
+ __wbg___wbindgen_in_aca499c5de7ff5e5: function(arg0, arg1) {
185
185
  return arg0 in arg1;
186
186
  },
187
- __wbg___wbindgen_is_bigint_90b5ccfe67c78460: function(arg0) {
187
+ __wbg___wbindgen_is_bigint_2f76dc55065b4273: function(arg0) {
188
188
  return typeof arg0 === "bigint";
189
189
  },
190
- __wbg___wbindgen_is_function_acc5528be2b923f2: function(arg0) {
190
+ __wbg___wbindgen_is_function_1ff95bcc5517c252: function(arg0) {
191
191
  return typeof arg0 === "function";
192
192
  },
193
- __wbg___wbindgen_is_object_0beba4a1980d3eea: function(arg0) {
193
+ __wbg___wbindgen_is_object_a27215656b807791: function(arg0) {
194
194
  const val = arg0;
195
195
  return typeof val === "object" && val !== null;
196
196
  },
197
- __wbg___wbindgen_is_string_1fca8072260dd261: function(arg0) {
197
+ __wbg___wbindgen_is_string_ea5e6cc2e4141dfe: function(arg0) {
198
198
  return typeof arg0 === "string";
199
199
  },
200
- __wbg___wbindgen_is_undefined_721f8decd50c87a3: function(arg0) {
200
+ __wbg___wbindgen_is_undefined_c05833b95a3cf397: function(arg0) {
201
201
  return arg0 === void 0;
202
202
  },
203
- __wbg___wbindgen_jsval_eq_4e8c38722cb8ff51: function(arg0, arg1) {
203
+ __wbg___wbindgen_jsval_eq_e659fcf7b0e32763: function(arg0, arg1) {
204
204
  return arg0 === arg1;
205
205
  },
206
- __wbg___wbindgen_jsval_loose_eq_4b9aba9e5b3c4582: function(arg0, arg1) {
206
+ __wbg___wbindgen_jsval_loose_eq_db4c3b15f63fc170: function(arg0, arg1) {
207
207
  return arg0 == arg1;
208
208
  },
209
- __wbg___wbindgen_number_get_1cc01dd708740256: function(arg0, arg1) {
209
+ __wbg___wbindgen_number_get_394265ed1e1b84ee: function(arg0, arg1) {
210
210
  const obj = arg1;
211
211
  const ret = typeof obj === "number" ? obj : void 0;
212
212
  getDataViewMemory0().setFloat64(arg0 + 8, isLikeNone(ret) ? 0 : ret, true);
213
213
  getDataViewMemory0().setInt32(arg0 + 0, !isLikeNone(ret), true);
214
214
  },
215
- __wbg___wbindgen_string_get_71bb4348194e31f0: function(arg0, arg1) {
215
+ __wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
216
216
  const obj = arg1;
217
217
  const ret = typeof obj === "string" ? obj : void 0;
218
218
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -220,35 +220,35 @@ function __wbg_get_imports() {
220
220
  getDataViewMemory0().setInt32(arg0 + 4, len1, true);
221
221
  getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
222
222
  },
223
- __wbg___wbindgen_throw_ea4887a5f8f9a9db: function(arg0, arg1) {
223
+ __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
224
224
  throw new Error(getStringFromWasm0(arg0, arg1));
225
225
  },
226
- __wbg_call_8e98ed2f3c86c4b5: function() {
226
+ __wbg_call_8a2dd23819f8a60a: function() {
227
227
  return handleError(function(arg0, arg1) {
228
228
  return arg0.call(arg1);
229
229
  }, arguments);
230
230
  },
231
- __wbg_done_b62d4a7d2286852a: function(arg0) {
231
+ __wbg_done_89b2b13e91a60321: function(arg0) {
232
232
  return arg0.done;
233
233
  },
234
- __wbg_entries_c261c3fa1f281256: function(arg0) {
234
+ __wbg_entries_015dc610cd81ede0: function(arg0) {
235
235
  return Object.entries(arg0);
236
236
  },
237
- __wbg_get_197a3fe98f169e38: function(arg0, arg1) {
237
+ __wbg_get_507a50627bffa49b: function(arg0, arg1) {
238
238
  return arg0[arg1 >>> 0];
239
239
  },
240
- __wbg_get_9a29be2cb383ed9a: function() {
240
+ __wbg_get_c7eb1f358a7654df: function() {
241
241
  return handleError(function(arg0, arg1) {
242
242
  return Reflect.get(arg0, arg1);
243
243
  }, arguments);
244
244
  },
245
- __wbg_get_unchecked_54a4374c38e08460: function(arg0, arg1) {
245
+ __wbg_get_unchecked_6e0ad6d2a41b06f6: function(arg0, arg1) {
246
246
  return arg0[arg1 >>> 0];
247
247
  },
248
248
  __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
249
249
  return arg0[arg1];
250
250
  },
251
- __wbg_instanceof_ArrayBuffer_2a7bb09fee70c2da: function(arg0) {
251
+ __wbg_instanceof_ArrayBuffer_4480b9e0068a8adb: function(arg0) {
252
252
  let result;
253
253
  try {
254
254
  result = arg0 instanceof ArrayBuffer;
@@ -257,7 +257,7 @@ function __wbg_get_imports() {
257
257
  }
258
258
  return result;
259
259
  },
260
- __wbg_instanceof_Map_afa18d5840c04c15: function(arg0) {
260
+ __wbg_instanceof_Map_e5b5e3db98422fcc: function(arg0) {
261
261
  let result;
262
262
  try {
263
263
  result = arg0 instanceof Map;
@@ -266,7 +266,7 @@ function __wbg_get_imports() {
266
266
  }
267
267
  return result;
268
268
  },
269
- __wbg_instanceof_Uint8Array_f080092dc70f5d58: function(arg0) {
269
+ __wbg_instanceof_Uint8Array_309b927aaf7a3fc7: function(arg0) {
270
270
  let result;
271
271
  try {
272
272
  result = arg0 instanceof Uint8Array;
@@ -275,51 +275,51 @@ function __wbg_get_imports() {
275
275
  }
276
276
  return result;
277
277
  },
278
- __wbg_isArray_145a34fd0a38d37b: function(arg0) {
278
+ __wbg_isArray_0677c962b281d01a: function(arg0) {
279
279
  return Array.isArray(arg0);
280
280
  },
281
- __wbg_isSafeInteger_a3389a198582f5f6: function(arg0) {
281
+ __wbg_isSafeInteger_04f36e4056f1b851: function(arg0) {
282
282
  return Number.isSafeInteger(arg0);
283
283
  },
284
- __wbg_iterator_cc47ba25a2be735a: function() {
284
+ __wbg_iterator_6f722e4a93058b71: function() {
285
285
  return Symbol.iterator;
286
286
  },
287
- __wbg_length_589238bdcf171f0e: function(arg0) {
287
+ __wbg_length_1f0964f4a5e2c6d8: function(arg0) {
288
288
  return arg0.length;
289
289
  },
290
- __wbg_length_c6054974c0a6cdb9: function(arg0) {
290
+ __wbg_length_370319915dc99107: function(arg0) {
291
291
  return arg0.length;
292
292
  },
293
- __wbg_new_2e117a478906f062: function() {
294
- return /* @__PURE__ */ new Object();
295
- },
296
- __wbg_new_36e147a8ced3c6e0: function() {
293
+ __wbg_new_32b398fb48b6d94a: function() {
297
294
  return new Array();
298
295
  },
299
- __wbg_new_81880fb5002cb255: function(arg0) {
296
+ __wbg_new_b667d279fd5aa943: function(arg0, arg1) {
297
+ return new Error(getStringFromWasm0(arg0, arg1));
298
+ },
299
+ __wbg_new_cd45aabdf6073e84: function(arg0) {
300
300
  return new Uint8Array(arg0);
301
301
  },
302
- __wbg_new_e66a4b7758dd2e5c: function(arg0, arg1) {
303
- return new Error(getStringFromWasm0(arg0, arg1));
302
+ __wbg_new_da52cf8fe3429cb2: function() {
303
+ return /* @__PURE__ */ new Object();
304
+ },
305
+ __wbg_next_6dbf2c0ac8cde20f: function(arg0) {
306
+ return arg0.next;
304
307
  },
305
- __wbg_next_0c4066e251d2eff9: function() {
308
+ __wbg_next_71f2aa1cb3d1e37e: function() {
306
309
  return handleError(function(arg0) {
307
310
  return arg0.next();
308
311
  }, arguments);
309
312
  },
310
- __wbg_next_402fa10b59ab20c3: function(arg0) {
311
- return arg0.next;
312
- },
313
- __wbg_prototypesetcall_d721637c7ca66eb8: function(arg0, arg1, arg2) {
313
+ __wbg_prototypesetcall_4770620bbe4688a0: function(arg0, arg1, arg2) {
314
314
  Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
315
315
  },
316
316
  __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
317
317
  arg0[arg1] = arg2;
318
318
  },
319
- __wbg_set_dc601f4a69da0bc2: function(arg0, arg1, arg2) {
319
+ __wbg_set_8a16b38e4805b298: function(arg0, arg1, arg2) {
320
320
  arg0[arg1 >>> 0] = arg2;
321
321
  },
322
- __wbg_value_49f783bb59765962: function(arg0) {
322
+ __wbg_value_a5d5488a9589444a: function(arg0) {
323
323
  return arg0.value;
324
324
  },
325
325
  __wbindgen_cast_0000000000000001: function(arg0) {
@@ -564,16 +564,32 @@ async function resolveImageLoaders(images) {
564
564
  })));
565
565
  }
566
566
  var Renderer = class {
567
- fontMapping = /* @__PURE__ */ new Map();
567
+ fontsByKey = /* @__PURE__ */ new Map();
568
+ fontsByData = /* @__PURE__ */ new WeakMap();
568
569
  inner = new Renderer$1();
570
+ getFont(key) {
571
+ return typeof key === "string" ? this.fontsByKey.get(key) : this.fontsByData.get(key);
572
+ }
573
+ setFont(key, family) {
574
+ if (typeof key === "string") this.fontsByKey.set(key, family);
575
+ else this.fontsByData.set(key, family);
576
+ }
577
+ deleteFont(key) {
578
+ if (typeof key === "string") this.fontsByKey.delete(key);
579
+ else this.fontsByData.delete(key);
580
+ }
569
581
  async prepareFonts(fonts) {
570
582
  if (!fonts) return;
571
583
  const families = await Promise.all(fonts.map(this.registerFont.bind(this)));
572
584
  return [...new Set(families.flat().map((f) => f.name))];
573
585
  }
574
586
  async render(node, options) {
575
- const { fonts, fontFamilies, images, ...rest } = options ?? {};
576
- const registeredFamilies = await this.prepareFonts(fonts);
587
+ const { fonts, fontFamilies, images, subset, ...rest } = options ?? {};
588
+ const registeredFamilies = await this.prepareFonts((0, _takumi_rs_helpers.pickFonts)({
589
+ fonts,
590
+ source: node,
591
+ subset
592
+ }));
577
593
  const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
578
594
  return this.inner.render(node, {
579
595
  ...rest,
@@ -582,8 +598,12 @@ var Renderer = class {
582
598
  });
583
599
  }
584
600
  async renderAsDataUrl(node, options) {
585
- const { fonts, fontFamilies, images, ...rest } = options ?? {};
586
- const registeredFamilies = await this.prepareFonts(fonts);
601
+ const { fonts, fontFamilies, images, subset, ...rest } = options ?? {};
602
+ const registeredFamilies = await this.prepareFonts((0, _takumi_rs_helpers.pickFonts)({
603
+ fonts,
604
+ source: node,
605
+ subset
606
+ }));
587
607
  const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
588
608
  return this.inner.renderAsDataUrl(node, {
589
609
  ...rest,
@@ -592,8 +612,12 @@ var Renderer = class {
592
612
  });
593
613
  }
594
614
  async renderSvg(node, options) {
595
- const { fonts, fontFamilies, images, ...rest } = options ?? {};
596
- const registeredFamilies = await this.prepareFonts(fonts);
615
+ const { fonts, fontFamilies, images, subset, ...rest } = options ?? {};
616
+ const registeredFamilies = await this.prepareFonts((0, _takumi_rs_helpers.pickFonts)({
617
+ fonts,
618
+ source: node,
619
+ subset
620
+ }));
597
621
  const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
598
622
  return this.inner.renderSvg(node, {
599
623
  ...rest,
@@ -602,8 +626,12 @@ var Renderer = class {
602
626
  });
603
627
  }
604
628
  async measure(node, options) {
605
- const { fonts, fontFamilies, images, ...rest } = options ?? {};
606
- const registeredFamilies = await this.prepareFonts(fonts);
629
+ const { fonts, fontFamilies, images, subset, ...rest } = options ?? {};
630
+ const registeredFamilies = await this.prepareFonts((0, _takumi_rs_helpers.pickFonts)({
631
+ fonts,
632
+ source: node,
633
+ subset
634
+ }));
607
635
  const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
608
636
  return this.inner.measure(node, {
609
637
  ...rest,
@@ -612,8 +640,13 @@ var Renderer = class {
612
640
  });
613
641
  }
614
642
  async renderAnimation(options) {
615
- const { fonts, fontFamilies, images, ...rest } = options;
616
- const registeredFamilies = await this.prepareFonts(fonts);
643
+ const { fonts, fontFamilies, images, subset, ...rest } = options;
644
+ const nodes = options.scenes.map((scene) => scene.node);
645
+ const registeredFamilies = await this.prepareFonts((0, _takumi_rs_helpers.pickFonts)({
646
+ fonts,
647
+ source: nodes,
648
+ subset
649
+ }));
617
650
  const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
618
651
  return this.inner.renderAnimation({
619
652
  ...rest,
@@ -622,8 +655,13 @@ var Renderer = class {
622
655
  });
623
656
  }
624
657
  async encodeFrames(frames, options) {
625
- const { fonts, fontFamilies, images, ...rest } = options;
626
- const registeredFamilies = await this.prepareFonts(fonts);
658
+ const { fonts, fontFamilies, images, subset, ...rest } = options;
659
+ const nodes = frames.map((frame) => frame.node);
660
+ const registeredFamilies = await this.prepareFonts((0, _takumi_rs_helpers.pickFonts)({
661
+ fonts,
662
+ source: nodes,
663
+ subset
664
+ }));
627
665
  const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
628
666
  return this.inner.encodeFrames(frames, {
629
667
  ...rest,
@@ -636,7 +674,7 @@ var Renderer = class {
636
674
  }
637
675
  async registerFont(font) {
638
676
  const key = createFontKey(font);
639
- const cached = this.fontMapping.get(key);
677
+ const cached = this.getFont(key);
640
678
  if (cached) return cached;
641
679
  const extracted = extractFontBuffer(font);
642
680
  const register = (data) => this.inner.registerFont(isBuffer(font) ? data : {
@@ -645,14 +683,14 @@ var Renderer = class {
645
683
  });
646
684
  if (isBuffer(extracted)) {
647
685
  const binded = register(extracted);
648
- this.fontMapping.set(key, Promise.resolve(binded));
686
+ this.setFont(key, Promise.resolve(binded));
649
687
  return binded;
650
688
  }
651
689
  const promise = extracted.then(register).catch((error) => {
652
- this.fontMapping.delete(key);
690
+ this.deleteFont(key);
653
691
  throw error;
654
692
  });
655
- this.fontMapping.set(key, promise);
693
+ this.setFont(key, promise);
656
694
  return promise;
657
695
  }
658
696
  };
@@ -673,10 +711,5 @@ function isBuffer(data) {
673
711
  //#endregion
674
712
  exports.Renderer = Renderer;
675
713
  exports.default = __wbg_init;
676
- Object.defineProperty(exports, "extractResourceUrls", {
677
- enumerable: true,
678
- get: function() {
679
- return _takumi_rs_helpers.extractResourceUrls;
680
- }
681
- });
714
+ exports.extractResourceUrls = _takumi_rs_helpers.extractResourceUrls;
682
715
  exports.initSync = initSync;
package/dist/export.d.cts CHANGED
@@ -240,7 +240,8 @@ declare function __wbg_init(module_or_path?: {
240
240
  //#endregion
241
241
  //#region src/export.d.ts
242
242
  type FontLoader = Font | (Omit<FontDetails, "data"> & {
243
- data: () => Promise<FontDetails["data"]> | FontDetails["data"];
243
+ data: () => Promise<FontDetails["data"]> | FontDetails["data"]; /** Inclusive codepoint ranges this face covers; lets `render` skip it when unused. */
244
+ ranges?: [number, number][];
244
245
  } & ({
245
246
  key: string;
246
247
  } | {
@@ -269,7 +270,8 @@ type OutputFormatOptions = {
269
270
  };
270
271
  type RenderOptions = Omit<RenderOptions$1, "images" | "format" | "quality"> & OutputFormatOptions & {
271
272
  fonts?: FontLoader[];
272
- images?: ImageLoader[];
273
+ images?: ImageLoader[]; /** Register only the `fonts` subsets the content renders. @default true */
274
+ subset?: boolean;
273
275
  };
274
276
  /**
275
277
  * Animation output format. On wasm, WebP animation is always lossless (lossy
@@ -284,19 +286,26 @@ type AnimationOutputFormatOptions = {
284
286
  };
285
287
  type RenderAnimationOptions = Omit<RenderAnimationOptions$1, "images" | "format"> & AnimationOutputFormatOptions & {
286
288
  fonts?: FontLoader[];
287
- images?: ImageLoader[];
289
+ images?: ImageLoader[]; /** Register only the `fonts` subsets the content renders. @default true */
290
+ subset?: boolean;
288
291
  };
289
292
  type EncodeFramesOptions = Omit<EncodeFramesOptions$1, "images" | "format"> & AnimationOutputFormatOptions & {
290
293
  fonts?: FontLoader[];
291
- images?: ImageLoader[];
294
+ images?: ImageLoader[]; /** Register only the `fonts` subsets the content renders. @default true */
295
+ subset?: boolean;
292
296
  };
293
297
  type SvgRenderOptions = Omit<SvgRenderOptions$1, "images"> & {
294
298
  fonts?: FontLoader[];
295
- images?: ImageLoader[];
299
+ images?: ImageLoader[]; /** Register only the `fonts` subsets the content renders. @default true */
300
+ subset?: boolean;
296
301
  };
297
302
  declare class Renderer {
298
- private fontMapping;
303
+ private fontsByKey;
304
+ private fontsByData;
299
305
  private inner;
306
+ private getFont;
307
+ private setFont;
308
+ private deleteFont;
300
309
  private prepareFonts;
301
310
  render(node: Node, options?: RenderOptions): Promise<Uint8Array<ArrayBufferLike>>;
302
311
  renderAsDataUrl(node: Node, options?: RenderOptions): Promise<string>;
@@ -305,7 +314,7 @@ declare class Renderer {
305
314
  renderAnimation(options: RenderAnimationOptions): Promise<Uint8Array<ArrayBufferLike>>;
306
315
  encodeFrames(frames: AnimationFrameSource[], options: EncodeFramesOptions): Promise<Uint8Array<ArrayBufferLike>>;
307
316
  free(): void;
308
- registerFont(font: FontLoader): Promise<any>;
317
+ registerFont(font: FontLoader): Promise<RegisteredFamily[]>;
309
318
  }
310
319
  //#endregion
311
320
  export { AnimationFrameSource, AnimationOutputFormatOptions, AnimationSceneSource, ByteBuf, ContainerNode, EncodeFramesOptions, Font, FontDetails, FontLoader, ImageLoader, ImageNode, ImageSource, InitInput, InitOutput, KeyframeRule, Keyframes, KeyframesMap, KeyframesRule, KeyframesRuleList, MeasuredNode, MeasuredTextRun, type Node, NodeMetadata, OutputFormatOptions, RegisteredFace, RegisteredFamily, RenderAnimationOptions, RenderOptions, Renderer, SvgRenderOptions, SyncInitInput, TextNode, __wbg_init as default, extractResourceUrls, initSync };
package/dist/export.d.mts CHANGED
@@ -240,7 +240,8 @@ declare function __wbg_init(module_or_path?: {
240
240
  //#endregion
241
241
  //#region src/export.d.ts
242
242
  type FontLoader = Font | (Omit<FontDetails, "data"> & {
243
- data: () => Promise<FontDetails["data"]> | FontDetails["data"];
243
+ data: () => Promise<FontDetails["data"]> | FontDetails["data"]; /** Inclusive codepoint ranges this face covers; lets `render` skip it when unused. */
244
+ ranges?: [number, number][];
244
245
  } & ({
245
246
  key: string;
246
247
  } | {
@@ -269,7 +270,8 @@ type OutputFormatOptions = {
269
270
  };
270
271
  type RenderOptions = Omit<RenderOptions$1, "images" | "format" | "quality"> & OutputFormatOptions & {
271
272
  fonts?: FontLoader[];
272
- images?: ImageLoader[];
273
+ images?: ImageLoader[]; /** Register only the `fonts` subsets the content renders. @default true */
274
+ subset?: boolean;
273
275
  };
274
276
  /**
275
277
  * Animation output format. On wasm, WebP animation is always lossless (lossy
@@ -284,19 +286,26 @@ type AnimationOutputFormatOptions = {
284
286
  };
285
287
  type RenderAnimationOptions = Omit<RenderAnimationOptions$1, "images" | "format"> & AnimationOutputFormatOptions & {
286
288
  fonts?: FontLoader[];
287
- images?: ImageLoader[];
289
+ images?: ImageLoader[]; /** Register only the `fonts` subsets the content renders. @default true */
290
+ subset?: boolean;
288
291
  };
289
292
  type EncodeFramesOptions = Omit<EncodeFramesOptions$1, "images" | "format"> & AnimationOutputFormatOptions & {
290
293
  fonts?: FontLoader[];
291
- images?: ImageLoader[];
294
+ images?: ImageLoader[]; /** Register only the `fonts` subsets the content renders. @default true */
295
+ subset?: boolean;
292
296
  };
293
297
  type SvgRenderOptions = Omit<SvgRenderOptions$1, "images"> & {
294
298
  fonts?: FontLoader[];
295
- images?: ImageLoader[];
299
+ images?: ImageLoader[]; /** Register only the `fonts` subsets the content renders. @default true */
300
+ subset?: boolean;
296
301
  };
297
302
  declare class Renderer {
298
- private fontMapping;
303
+ private fontsByKey;
304
+ private fontsByData;
299
305
  private inner;
306
+ private getFont;
307
+ private setFont;
308
+ private deleteFont;
300
309
  private prepareFonts;
301
310
  render(node: Node, options?: RenderOptions): Promise<Uint8Array<ArrayBufferLike>>;
302
311
  renderAsDataUrl(node: Node, options?: RenderOptions): Promise<string>;
@@ -305,7 +314,7 @@ declare class Renderer {
305
314
  renderAnimation(options: RenderAnimationOptions): Promise<Uint8Array<ArrayBufferLike>>;
306
315
  encodeFrames(frames: AnimationFrameSource[], options: EncodeFramesOptions): Promise<Uint8Array<ArrayBufferLike>>;
307
316
  free(): void;
308
- registerFont(font: FontLoader): Promise<any>;
317
+ registerFont(font: FontLoader): Promise<RegisteredFamily[]>;
309
318
  }
310
319
  //#endregion
311
320
  export { AnimationFrameSource, AnimationOutputFormatOptions, AnimationSceneSource, ByteBuf, ContainerNode, EncodeFramesOptions, Font, FontDetails, FontLoader, ImageLoader, ImageNode, ImageSource, InitInput, InitOutput, KeyframeRule, Keyframes, KeyframesMap, KeyframesRule, KeyframesRuleList, MeasuredNode, MeasuredTextRun, type Node, NodeMetadata, OutputFormatOptions, RegisteredFace, RegisteredFamily, RenderAnimationOptions, RenderOptions, Renderer, SvgRenderOptions, SyncInitInput, TextNode, __wbg_init as default, extractResourceUrls, initSync };
package/dist/export.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { extractResourceUrls } from "@takumi-rs/helpers";
1
+ import { extractResourceUrls, pickFonts } from "@takumi-rs/helpers";
2
2
  //#region pkg/takumi_wasm.js
3
3
  /**
4
4
  * The main renderer for Takumi image rendering engine.
@@ -148,10 +148,10 @@ function __wbg_get_imports() {
148
148
  __proto__: null,
149
149
  "./takumi_wasm_bg.js": {
150
150
  __proto__: null,
151
- __wbg_Error_fdd633d4bb5dd76a: function(arg0, arg1) {
151
+ __wbg_Error_92b29b0548f8b746: function(arg0, arg1) {
152
152
  return Error(getStringFromWasm0(arg0, arg1));
153
153
  },
154
- __wbg_Number_c4bdf66bb78f7977: function(arg0) {
154
+ __wbg_Number_9a4e0ecb0fa16705: function(arg0) {
155
155
  return Number(arg0);
156
156
  },
157
157
  __wbg_String_8564e559799eccda: function(arg0, arg1) {
@@ -160,55 +160,55 @@ function __wbg_get_imports() {
160
160
  getDataViewMemory0().setInt32(arg0 + 4, len1, true);
161
161
  getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
162
162
  },
163
- __wbg___wbindgen_bigint_get_as_i64_d9e915702856f831: function(arg0, arg1) {
163
+ __wbg___wbindgen_bigint_get_as_i64_d968e41184ae354f: function(arg0, arg1) {
164
164
  const v = arg1;
165
165
  const ret = typeof v === "bigint" ? v : void 0;
166
166
  getDataViewMemory0().setBigInt64(arg0 + 8, isLikeNone(ret) ? BigInt(0) : ret, true);
167
167
  getDataViewMemory0().setInt32(arg0 + 0, !isLikeNone(ret), true);
168
168
  },
169
- __wbg___wbindgen_boolean_get_edaed31a367ce1bd: function(arg0) {
169
+ __wbg___wbindgen_boolean_get_fa956cfa2d1bd751: function(arg0) {
170
170
  const v = arg0;
171
171
  const ret = typeof v === "boolean" ? v : void 0;
172
172
  return isLikeNone(ret) ? 16777215 : ret ? 1 : 0;
173
173
  },
174
- __wbg___wbindgen_debug_string_8a447059637473e2: function(arg0, arg1) {
174
+ __wbg___wbindgen_debug_string_c25d447a39f5578f: function(arg0, arg1) {
175
175
  const ptr1 = passStringToWasm0(debugString(arg1), wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
176
176
  const len1 = WASM_VECTOR_LEN;
177
177
  getDataViewMemory0().setInt32(arg0 + 4, len1, true);
178
178
  getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
179
179
  },
180
- __wbg___wbindgen_in_4990f46af709e33c: function(arg0, arg1) {
180
+ __wbg___wbindgen_in_aca499c5de7ff5e5: function(arg0, arg1) {
181
181
  return arg0 in arg1;
182
182
  },
183
- __wbg___wbindgen_is_bigint_90b5ccfe67c78460: function(arg0) {
183
+ __wbg___wbindgen_is_bigint_2f76dc55065b4273: function(arg0) {
184
184
  return typeof arg0 === "bigint";
185
185
  },
186
- __wbg___wbindgen_is_function_acc5528be2b923f2: function(arg0) {
186
+ __wbg___wbindgen_is_function_1ff95bcc5517c252: function(arg0) {
187
187
  return typeof arg0 === "function";
188
188
  },
189
- __wbg___wbindgen_is_object_0beba4a1980d3eea: function(arg0) {
189
+ __wbg___wbindgen_is_object_a27215656b807791: function(arg0) {
190
190
  const val = arg0;
191
191
  return typeof val === "object" && val !== null;
192
192
  },
193
- __wbg___wbindgen_is_string_1fca8072260dd261: function(arg0) {
193
+ __wbg___wbindgen_is_string_ea5e6cc2e4141dfe: function(arg0) {
194
194
  return typeof arg0 === "string";
195
195
  },
196
- __wbg___wbindgen_is_undefined_721f8decd50c87a3: function(arg0) {
196
+ __wbg___wbindgen_is_undefined_c05833b95a3cf397: function(arg0) {
197
197
  return arg0 === void 0;
198
198
  },
199
- __wbg___wbindgen_jsval_eq_4e8c38722cb8ff51: function(arg0, arg1) {
199
+ __wbg___wbindgen_jsval_eq_e659fcf7b0e32763: function(arg0, arg1) {
200
200
  return arg0 === arg1;
201
201
  },
202
- __wbg___wbindgen_jsval_loose_eq_4b9aba9e5b3c4582: function(arg0, arg1) {
202
+ __wbg___wbindgen_jsval_loose_eq_db4c3b15f63fc170: function(arg0, arg1) {
203
203
  return arg0 == arg1;
204
204
  },
205
- __wbg___wbindgen_number_get_1cc01dd708740256: function(arg0, arg1) {
205
+ __wbg___wbindgen_number_get_394265ed1e1b84ee: function(arg0, arg1) {
206
206
  const obj = arg1;
207
207
  const ret = typeof obj === "number" ? obj : void 0;
208
208
  getDataViewMemory0().setFloat64(arg0 + 8, isLikeNone(ret) ? 0 : ret, true);
209
209
  getDataViewMemory0().setInt32(arg0 + 0, !isLikeNone(ret), true);
210
210
  },
211
- __wbg___wbindgen_string_get_71bb4348194e31f0: function(arg0, arg1) {
211
+ __wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
212
212
  const obj = arg1;
213
213
  const ret = typeof obj === "string" ? obj : void 0;
214
214
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -216,35 +216,35 @@ function __wbg_get_imports() {
216
216
  getDataViewMemory0().setInt32(arg0 + 4, len1, true);
217
217
  getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
218
218
  },
219
- __wbg___wbindgen_throw_ea4887a5f8f9a9db: function(arg0, arg1) {
219
+ __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
220
220
  throw new Error(getStringFromWasm0(arg0, arg1));
221
221
  },
222
- __wbg_call_8e98ed2f3c86c4b5: function() {
222
+ __wbg_call_8a2dd23819f8a60a: function() {
223
223
  return handleError(function(arg0, arg1) {
224
224
  return arg0.call(arg1);
225
225
  }, arguments);
226
226
  },
227
- __wbg_done_b62d4a7d2286852a: function(arg0) {
227
+ __wbg_done_89b2b13e91a60321: function(arg0) {
228
228
  return arg0.done;
229
229
  },
230
- __wbg_entries_c261c3fa1f281256: function(arg0) {
230
+ __wbg_entries_015dc610cd81ede0: function(arg0) {
231
231
  return Object.entries(arg0);
232
232
  },
233
- __wbg_get_197a3fe98f169e38: function(arg0, arg1) {
233
+ __wbg_get_507a50627bffa49b: function(arg0, arg1) {
234
234
  return arg0[arg1 >>> 0];
235
235
  },
236
- __wbg_get_9a29be2cb383ed9a: function() {
236
+ __wbg_get_c7eb1f358a7654df: function() {
237
237
  return handleError(function(arg0, arg1) {
238
238
  return Reflect.get(arg0, arg1);
239
239
  }, arguments);
240
240
  },
241
- __wbg_get_unchecked_54a4374c38e08460: function(arg0, arg1) {
241
+ __wbg_get_unchecked_6e0ad6d2a41b06f6: function(arg0, arg1) {
242
242
  return arg0[arg1 >>> 0];
243
243
  },
244
244
  __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
245
245
  return arg0[arg1];
246
246
  },
247
- __wbg_instanceof_ArrayBuffer_2a7bb09fee70c2da: function(arg0) {
247
+ __wbg_instanceof_ArrayBuffer_4480b9e0068a8adb: function(arg0) {
248
248
  let result;
249
249
  try {
250
250
  result = arg0 instanceof ArrayBuffer;
@@ -253,7 +253,7 @@ function __wbg_get_imports() {
253
253
  }
254
254
  return result;
255
255
  },
256
- __wbg_instanceof_Map_afa18d5840c04c15: function(arg0) {
256
+ __wbg_instanceof_Map_e5b5e3db98422fcc: function(arg0) {
257
257
  let result;
258
258
  try {
259
259
  result = arg0 instanceof Map;
@@ -262,7 +262,7 @@ function __wbg_get_imports() {
262
262
  }
263
263
  return result;
264
264
  },
265
- __wbg_instanceof_Uint8Array_f080092dc70f5d58: function(arg0) {
265
+ __wbg_instanceof_Uint8Array_309b927aaf7a3fc7: function(arg0) {
266
266
  let result;
267
267
  try {
268
268
  result = arg0 instanceof Uint8Array;
@@ -271,51 +271,51 @@ function __wbg_get_imports() {
271
271
  }
272
272
  return result;
273
273
  },
274
- __wbg_isArray_145a34fd0a38d37b: function(arg0) {
274
+ __wbg_isArray_0677c962b281d01a: function(arg0) {
275
275
  return Array.isArray(arg0);
276
276
  },
277
- __wbg_isSafeInteger_a3389a198582f5f6: function(arg0) {
277
+ __wbg_isSafeInteger_04f36e4056f1b851: function(arg0) {
278
278
  return Number.isSafeInteger(arg0);
279
279
  },
280
- __wbg_iterator_cc47ba25a2be735a: function() {
280
+ __wbg_iterator_6f722e4a93058b71: function() {
281
281
  return Symbol.iterator;
282
282
  },
283
- __wbg_length_589238bdcf171f0e: function(arg0) {
283
+ __wbg_length_1f0964f4a5e2c6d8: function(arg0) {
284
284
  return arg0.length;
285
285
  },
286
- __wbg_length_c6054974c0a6cdb9: function(arg0) {
286
+ __wbg_length_370319915dc99107: function(arg0) {
287
287
  return arg0.length;
288
288
  },
289
- __wbg_new_2e117a478906f062: function() {
290
- return /* @__PURE__ */ new Object();
291
- },
292
- __wbg_new_36e147a8ced3c6e0: function() {
289
+ __wbg_new_32b398fb48b6d94a: function() {
293
290
  return new Array();
294
291
  },
295
- __wbg_new_81880fb5002cb255: function(arg0) {
292
+ __wbg_new_b667d279fd5aa943: function(arg0, arg1) {
293
+ return new Error(getStringFromWasm0(arg0, arg1));
294
+ },
295
+ __wbg_new_cd45aabdf6073e84: function(arg0) {
296
296
  return new Uint8Array(arg0);
297
297
  },
298
- __wbg_new_e66a4b7758dd2e5c: function(arg0, arg1) {
299
- return new Error(getStringFromWasm0(arg0, arg1));
298
+ __wbg_new_da52cf8fe3429cb2: function() {
299
+ return /* @__PURE__ */ new Object();
300
300
  },
301
- __wbg_next_0c4066e251d2eff9: function() {
301
+ __wbg_next_6dbf2c0ac8cde20f: function(arg0) {
302
+ return arg0.next;
303
+ },
304
+ __wbg_next_71f2aa1cb3d1e37e: function() {
302
305
  return handleError(function(arg0) {
303
306
  return arg0.next();
304
307
  }, arguments);
305
308
  },
306
- __wbg_next_402fa10b59ab20c3: function(arg0) {
307
- return arg0.next;
308
- },
309
- __wbg_prototypesetcall_d721637c7ca66eb8: function(arg0, arg1, arg2) {
309
+ __wbg_prototypesetcall_4770620bbe4688a0: function(arg0, arg1, arg2) {
310
310
  Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
311
311
  },
312
312
  __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
313
313
  arg0[arg1] = arg2;
314
314
  },
315
- __wbg_set_dc601f4a69da0bc2: function(arg0, arg1, arg2) {
315
+ __wbg_set_8a16b38e4805b298: function(arg0, arg1, arg2) {
316
316
  arg0[arg1 >>> 0] = arg2;
317
317
  },
318
- __wbg_value_49f783bb59765962: function(arg0) {
318
+ __wbg_value_a5d5488a9589444a: function(arg0) {
319
319
  return arg0.value;
320
320
  },
321
321
  __wbindgen_cast_0000000000000001: function(arg0) {
@@ -560,16 +560,32 @@ async function resolveImageLoaders(images) {
560
560
  })));
561
561
  }
562
562
  var Renderer = class {
563
- fontMapping = /* @__PURE__ */ new Map();
563
+ fontsByKey = /* @__PURE__ */ new Map();
564
+ fontsByData = /* @__PURE__ */ new WeakMap();
564
565
  inner = new Renderer$1();
566
+ getFont(key) {
567
+ return typeof key === "string" ? this.fontsByKey.get(key) : this.fontsByData.get(key);
568
+ }
569
+ setFont(key, family) {
570
+ if (typeof key === "string") this.fontsByKey.set(key, family);
571
+ else this.fontsByData.set(key, family);
572
+ }
573
+ deleteFont(key) {
574
+ if (typeof key === "string") this.fontsByKey.delete(key);
575
+ else this.fontsByData.delete(key);
576
+ }
565
577
  async prepareFonts(fonts) {
566
578
  if (!fonts) return;
567
579
  const families = await Promise.all(fonts.map(this.registerFont.bind(this)));
568
580
  return [...new Set(families.flat().map((f) => f.name))];
569
581
  }
570
582
  async render(node, options) {
571
- const { fonts, fontFamilies, images, ...rest } = options ?? {};
572
- const registeredFamilies = await this.prepareFonts(fonts);
583
+ const { fonts, fontFamilies, images, subset, ...rest } = options ?? {};
584
+ const registeredFamilies = await this.prepareFonts(pickFonts({
585
+ fonts,
586
+ source: node,
587
+ subset
588
+ }));
573
589
  const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
574
590
  return this.inner.render(node, {
575
591
  ...rest,
@@ -578,8 +594,12 @@ var Renderer = class {
578
594
  });
579
595
  }
580
596
  async renderAsDataUrl(node, options) {
581
- const { fonts, fontFamilies, images, ...rest } = options ?? {};
582
- const registeredFamilies = await this.prepareFonts(fonts);
597
+ const { fonts, fontFamilies, images, subset, ...rest } = options ?? {};
598
+ const registeredFamilies = await this.prepareFonts(pickFonts({
599
+ fonts,
600
+ source: node,
601
+ subset
602
+ }));
583
603
  const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
584
604
  return this.inner.renderAsDataUrl(node, {
585
605
  ...rest,
@@ -588,8 +608,12 @@ var Renderer = class {
588
608
  });
589
609
  }
590
610
  async renderSvg(node, options) {
591
- const { fonts, fontFamilies, images, ...rest } = options ?? {};
592
- const registeredFamilies = await this.prepareFonts(fonts);
611
+ const { fonts, fontFamilies, images, subset, ...rest } = options ?? {};
612
+ const registeredFamilies = await this.prepareFonts(pickFonts({
613
+ fonts,
614
+ source: node,
615
+ subset
616
+ }));
593
617
  const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
594
618
  return this.inner.renderSvg(node, {
595
619
  ...rest,
@@ -598,8 +622,12 @@ var Renderer = class {
598
622
  });
599
623
  }
600
624
  async measure(node, options) {
601
- const { fonts, fontFamilies, images, ...rest } = options ?? {};
602
- const registeredFamilies = await this.prepareFonts(fonts);
625
+ const { fonts, fontFamilies, images, subset, ...rest } = options ?? {};
626
+ const registeredFamilies = await this.prepareFonts(pickFonts({
627
+ fonts,
628
+ source: node,
629
+ subset
630
+ }));
603
631
  const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
604
632
  return this.inner.measure(node, {
605
633
  ...rest,
@@ -608,8 +636,13 @@ var Renderer = class {
608
636
  });
609
637
  }
610
638
  async renderAnimation(options) {
611
- const { fonts, fontFamilies, images, ...rest } = options;
612
- const registeredFamilies = await this.prepareFonts(fonts);
639
+ const { fonts, fontFamilies, images, subset, ...rest } = options;
640
+ const nodes = options.scenes.map((scene) => scene.node);
641
+ const registeredFamilies = await this.prepareFonts(pickFonts({
642
+ fonts,
643
+ source: nodes,
644
+ subset
645
+ }));
613
646
  const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
614
647
  return this.inner.renderAnimation({
615
648
  ...rest,
@@ -618,8 +651,13 @@ var Renderer = class {
618
651
  });
619
652
  }
620
653
  async encodeFrames(frames, options) {
621
- const { fonts, fontFamilies, images, ...rest } = options;
622
- const registeredFamilies = await this.prepareFonts(fonts);
654
+ const { fonts, fontFamilies, images, subset, ...rest } = options;
655
+ const nodes = frames.map((frame) => frame.node);
656
+ const registeredFamilies = await this.prepareFonts(pickFonts({
657
+ fonts,
658
+ source: nodes,
659
+ subset
660
+ }));
623
661
  const resolvedImages = images ? await resolveImageLoaders(images) : void 0;
624
662
  return this.inner.encodeFrames(frames, {
625
663
  ...rest,
@@ -632,7 +670,7 @@ var Renderer = class {
632
670
  }
633
671
  async registerFont(font) {
634
672
  const key = createFontKey(font);
635
- const cached = this.fontMapping.get(key);
673
+ const cached = this.getFont(key);
636
674
  if (cached) return cached;
637
675
  const extracted = extractFontBuffer(font);
638
676
  const register = (data) => this.inner.registerFont(isBuffer(font) ? data : {
@@ -641,14 +679,14 @@ var Renderer = class {
641
679
  });
642
680
  if (isBuffer(extracted)) {
643
681
  const binded = register(extracted);
644
- this.fontMapping.set(key, Promise.resolve(binded));
682
+ this.setFont(key, Promise.resolve(binded));
645
683
  return binded;
646
684
  }
647
685
  const promise = extracted.then(register).catch((error) => {
648
- this.fontMapping.delete(key);
686
+ this.deleteFont(key);
649
687
  throw error;
650
688
  });
651
- this.fontMapping.set(key, promise);
689
+ this.setFont(key, promise);
652
690
  return promise;
653
691
  }
654
692
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takumi-rs/wasm",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.11",
4
4
  "keywords": [
5
5
  "css",
6
6
  "image",
@@ -61,20 +61,47 @@
61
61
  }
62
62
  },
63
63
  "./auto": {
64
- "types": "./bundlers/type.d.ts",
65
- "bun": "./bundlers/bun.mjs",
66
- "workerd": "./bundlers/workerd.js",
67
- "unwasm": "./bundlers/next.mjs",
68
- "module": "./bundlers/vite.mjs",
69
- "node": "./bundlers/node.mjs",
70
- "default": "./bundlers/vite.mjs"
64
+ "bun": {
65
+ "types": "./bundlers/bun.d.ts",
66
+ "default": "./bundlers/bun.mjs"
67
+ },
68
+ "workerd": {
69
+ "types": "./bundlers/wasm-module.d.ts",
70
+ "default": "./bundlers/workerd.js"
71
+ },
72
+ "edge-light": {
73
+ "types": "./bundlers/wasm-module.d.ts",
74
+ "default": "./bundlers/next.mjs"
75
+ },
76
+ "unwasm": {
77
+ "types": "./bundlers/wasm-module.d.ts",
78
+ "default": "./bundlers/next.mjs"
79
+ },
80
+ "module": {
81
+ "types": "./bundlers/vite.d.ts",
82
+ "default": "./bundlers/vite.mjs"
83
+ },
84
+ "node": {
85
+ "require": {
86
+ "types": "./bundlers/node.d.cts",
87
+ "default": "./bundlers/node.cjs"
88
+ },
89
+ "default": {
90
+ "types": "./bundlers/node.d.ts",
91
+ "default": "./bundlers/node.mjs"
92
+ }
93
+ },
94
+ "default": {
95
+ "types": "./bundlers/wasm-module.d.ts",
96
+ "default": "./bundlers/vite.mjs"
97
+ }
71
98
  },
72
99
  "./takumi_wasm_bg.wasm": {
73
100
  "types": "./pkg/takumi_wasm_bg.wasm.d.ts",
74
101
  "default": "./pkg/takumi_wasm_bg.wasm"
75
102
  },
76
103
  "./next": {
77
- "types": "./bundlers/next.d.ts",
104
+ "types": "./bundlers/wasm-module.d.ts",
78
105
  "default": "./bundlers/next.mjs"
79
106
  },
80
107
  "./vite": {
@@ -83,21 +110,22 @@
83
110
  }
84
111
  },
85
112
  "scripts": {
86
- "build": "wasm-pack build --no-pack --release --out-dir pkg --target web && bun build:js && bun scripts/patch-generated-loader.ts",
113
+ "build": "wasm-pack build --no-pack --release --out-dir pkg --target web && bun build:js",
87
114
  "build:js": "tsdown",
88
- "build:debug": "wasm-pack build --no-pack --dev --out-dir pkg --target web && bun build:js && bun scripts/patch-generated-loader.ts",
89
- "prepublishOnly": "jq '.dependencies[\"@takumi-rs/helpers\"] = .version' package.json > tmp.json && mv tmp.json package.json",
115
+ "build:debug": "wasm-pack build --no-pack --dev --out-dir pkg --target web && bun build:js",
90
116
  "publish-lint": "attw --pack . && publint --strict ."
91
117
  },
92
118
  "dependencies": {
93
- "@takumi-rs/helpers": "2.0.0-beta.1"
119
+ "@takumi-rs/helpers": "2.0.0-beta.11"
94
120
  },
95
121
  "devDependencies": {
96
- "@types/bun": "catalog:",
122
+ "@types/bun": "^1.3.14",
97
123
  "csstype": "^3.2.3",
98
- "tsdown": "catalog:",
99
- "typescript": "catalog:",
100
- "unrun": "catalog:"
124
+ "tsdown": "^0.22.3",
125
+ "unrun": "^0.3.1"
126
+ },
127
+ "engines": {
128
+ "node": ">=18"
101
129
  },
102
130
  "readme": "README.md"
103
131
  }
Binary file
@@ -1,3 +0,0 @@
1
- declare const wasmModule: WebAssembly.Module;
2
-
3
- export default wasmModule;
File without changes