@fontmin-rs/wasm 1.1.0 → 1.2.0-rc.2

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.
@@ -101,10 +101,10 @@ function __wbg_get_imports() {
101
101
  __proto__: null,
102
102
  "./fontmin_wasm_core_bg.js": {
103
103
  __proto__: null,
104
- __wbg_Error_92b29b0548f8b746: function(arg0, arg1) {
104
+ __wbg_Error_408e67f47ca7b58b: function(arg0, arg1) {
105
105
  return addHeapObject(Error(getStringFromWasm0(arg0, arg1)));
106
106
  },
107
- __wbg_Number_9a4e0ecb0fa16705: function(arg0) {
107
+ __wbg_Number_3890faa6d3ff057d: function(arg0) {
108
108
  return Number(getObject(arg0));
109
109
  },
110
110
  __wbg_String_8564e559799eccda: function(arg0, arg1) {
@@ -113,55 +113,55 @@ function __wbg_get_imports() {
113
113
  getDataViewMemory0().setInt32(arg0 + 4, len1, true);
114
114
  getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
115
115
  },
116
- __wbg___wbindgen_bigint_get_as_i64_d968e41184ae354f: function(arg0, arg1) {
116
+ __wbg___wbindgen_bigint_get_as_i64_c4ecf48528083721: function(arg0, arg1) {
117
117
  const v = getObject(arg1);
118
118
  const ret = typeof v === "bigint" ? v : void 0;
119
119
  getDataViewMemory0().setBigInt64(arg0 + 8, isLikeNone(ret) ? BigInt(0) : ret, true);
120
120
  getDataViewMemory0().setInt32(arg0 + 0, !isLikeNone(ret), true);
121
121
  },
122
- __wbg___wbindgen_boolean_get_fa956cfa2d1bd751: function(arg0) {
122
+ __wbg___wbindgen_boolean_get_c9c83ebd41b34df3: function(arg0) {
123
123
  const v = getObject(arg0);
124
124
  const ret = typeof v === "boolean" ? v : void 0;
125
125
  return isLikeNone(ret) ? 16777215 : ret ? 1 : 0;
126
126
  },
127
- __wbg___wbindgen_debug_string_c25d447a39f5578f: function(arg0, arg1) {
127
+ __wbg___wbindgen_debug_string_a57024b9c6e4a48b: function(arg0, arg1) {
128
128
  const ptr1 = passStringToWasm0(debugString(getObject(arg1)), wasm.__wbindgen_export, wasm.__wbindgen_export2);
129
129
  const len1 = WASM_VECTOR_LEN;
130
130
  getDataViewMemory0().setInt32(arg0 + 4, len1, true);
131
131
  getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
132
132
  },
133
- __wbg___wbindgen_in_aca499c5de7ff5e5: function(arg0, arg1) {
133
+ __wbg___wbindgen_in_ac983077f137f2e6: function(arg0, arg1) {
134
134
  return getObject(arg0) in getObject(arg1);
135
135
  },
136
- __wbg___wbindgen_is_bigint_2f76dc55065b4273: function(arg0) {
136
+ __wbg___wbindgen_is_bigint_8ffbbef442139384: function(arg0) {
137
137
  return typeof getObject(arg0) === "bigint";
138
138
  },
139
- __wbg___wbindgen_is_function_1ff95bcc5517c252: function(arg0) {
139
+ __wbg___wbindgen_is_function_5e4570eb24ffa122: function(arg0) {
140
140
  return typeof getObject(arg0) === "function";
141
141
  },
142
- __wbg___wbindgen_is_object_a27215656b807791: function(arg0) {
142
+ __wbg___wbindgen_is_object_a2790eb24c211ea0: function(arg0) {
143
143
  const val = getObject(arg0);
144
144
  return typeof val === "object" && val !== null;
145
145
  },
146
- __wbg___wbindgen_is_string_ea5e6cc2e4141dfe: function(arg0) {
146
+ __wbg___wbindgen_is_string_e6f02f0ea5f20a32: function(arg0) {
147
147
  return typeof getObject(arg0) === "string";
148
148
  },
149
- __wbg___wbindgen_is_undefined_c05833b95a3cf397: function(arg0) {
149
+ __wbg___wbindgen_is_undefined_6cff064c44e0d823: function(arg0) {
150
150
  return getObject(arg0) === void 0;
151
151
  },
152
- __wbg___wbindgen_jsval_eq_e659fcf7b0e32763: function(arg0, arg1) {
152
+ __wbg___wbindgen_jsval_eq_0a18949a61670320: function(arg0, arg1) {
153
153
  return getObject(arg0) === getObject(arg1);
154
154
  },
155
- __wbg___wbindgen_jsval_loose_eq_db4c3b15f63fc170: function(arg0, arg1) {
155
+ __wbg___wbindgen_jsval_loose_eq_acf2776254a8d832: function(arg0, arg1) {
156
156
  return getObject(arg0) == getObject(arg1);
157
157
  },
158
- __wbg___wbindgen_number_get_394265ed1e1b84ee: function(arg0, arg1) {
158
+ __wbg___wbindgen_number_get_136b9679cab35cfb: function(arg0, arg1) {
159
159
  const obj = getObject(arg1);
160
160
  const ret = typeof obj === "number" ? obj : void 0;
161
161
  getDataViewMemory0().setFloat64(arg0 + 8, isLikeNone(ret) ? 0 : ret, true);
162
162
  getDataViewMemory0().setInt32(arg0 + 0, !isLikeNone(ret), true);
163
163
  },
164
- __wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
164
+ __wbg___wbindgen_string_get_d154f1e671052120: function(arg0, arg1) {
165
165
  const obj = getObject(arg1);
166
166
  const ret = typeof obj === "string" ? obj : void 0;
167
167
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
@@ -169,30 +169,30 @@ function __wbg_get_imports() {
169
169
  getDataViewMemory0().setInt32(arg0 + 4, len1, true);
170
170
  getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
171
171
  },
172
- __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
172
+ __wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
173
173
  throw new Error(getStringFromWasm0(arg0, arg1));
174
174
  },
175
- __wbg_call_8a2dd23819f8a60a: function() {
175
+ __wbg_call_1c5886ab9c57d1c7: function() {
176
176
  return handleError(function(arg0, arg1) {
177
177
  return addHeapObject(getObject(arg0).call(getObject(arg1)));
178
178
  }, arguments);
179
179
  },
180
- __wbg_done_89b2b13e91a60321: function(arg0) {
180
+ __wbg_done_669171204c3dcae2: function(arg0) {
181
181
  return getObject(arg0).done;
182
182
  },
183
- __wbg_entries_015dc610cd81ede0: function(arg0) {
183
+ __wbg_entries_7774d489e1da5f4f: function(arg0) {
184
184
  return addHeapObject(Object.entries(getObject(arg0)));
185
185
  },
186
- __wbg_get_507a50627bffa49b: function(arg0, arg1) {
186
+ __wbg_get_c0c8f8d7da0c03dd: function(arg0, arg1) {
187
187
  const ret = getObject(arg0)[arg1 >>> 0];
188
188
  return addHeapObject(ret);
189
189
  },
190
- __wbg_get_c7eb1f358a7654df: function() {
190
+ __wbg_get_d173c0308df22d37: function() {
191
191
  return handleError(function(arg0, arg1) {
192
192
  return addHeapObject(Reflect.get(getObject(arg0), getObject(arg1)));
193
193
  }, arguments);
194
194
  },
195
- __wbg_get_unchecked_6e0ad6d2a41b06f6: function(arg0, arg1) {
195
+ __wbg_get_unchecked_e20b893aeafc3fca: function(arg0, arg1) {
196
196
  const ret = getObject(arg0)[arg1 >>> 0];
197
197
  return addHeapObject(ret);
198
198
  },
@@ -200,7 +200,7 @@ function __wbg_get_imports() {
200
200
  const ret = getObject(arg0)[getObject(arg1)];
201
201
  return addHeapObject(ret);
202
202
  },
203
- __wbg_instanceof_ArrayBuffer_4480b9e0068a8adb: function(arg0) {
203
+ __wbg_instanceof_ArrayBuffer_993d02d2d254cad1: function(arg0) {
204
204
  let result;
205
205
  try {
206
206
  result = getObject(arg0) instanceof ArrayBuffer;
@@ -209,7 +209,7 @@ function __wbg_get_imports() {
209
209
  }
210
210
  return result;
211
211
  },
212
- __wbg_instanceof_Map_e5b5e3db98422fcc: function(arg0) {
212
+ __wbg_instanceof_Map_9a4d6ead180ae3a9: function(arg0) {
213
213
  let result;
214
214
  try {
215
215
  result = getObject(arg0) instanceof Map;
@@ -218,7 +218,7 @@ function __wbg_get_imports() {
218
218
  }
219
219
  return result;
220
220
  },
221
- __wbg_instanceof_Uint8Array_309b927aaf7a3fc7: function(arg0) {
221
+ __wbg_instanceof_Uint8Array_f935dbb0aa7cdeed: function(arg0) {
222
222
  let result;
223
223
  try {
224
224
  result = getObject(arg0) instanceof Uint8Array;
@@ -227,56 +227,56 @@ function __wbg_get_imports() {
227
227
  }
228
228
  return result;
229
229
  },
230
- __wbg_isArray_0677c962b281d01a: function(arg0) {
230
+ __wbg_isArray_6339f732981044bf: function(arg0) {
231
231
  return Array.isArray(getObject(arg0));
232
232
  },
233
- __wbg_isSafeInteger_04f36e4056f1b851: function(arg0) {
233
+ __wbg_isSafeInteger_f3d6cd19ccfe4512: function(arg0) {
234
234
  return Number.isSafeInteger(getObject(arg0));
235
235
  },
236
- __wbg_iterator_6f722e4a93058b71: function() {
236
+ __wbg_iterator_5cebbb86e33c6dd6: function() {
237
237
  const ret = Symbol.iterator;
238
238
  return addHeapObject(ret);
239
239
  },
240
- __wbg_length_1f0964f4a5e2c6d8: function(arg0) {
240
+ __wbg_length_36bd29c6848c2144: function(arg0) {
241
241
  return getObject(arg0).length;
242
242
  },
243
- __wbg_length_370319915dc99107: function(arg0) {
243
+ __wbg_length_ecfa2c63d3d0d82c: function(arg0) {
244
244
  return getObject(arg0).length;
245
245
  },
246
- __wbg_new_32b398fb48b6d94a: function() {
246
+ __wbg_new_116be93542d39019: function() {
247
247
  return addHeapObject(new Array());
248
248
  },
249
- __wbg_new_7796ffc7ed656783: function() {
250
- return addHeapObject(/* @__PURE__ */ new Map());
251
- },
252
- __wbg_new_cd45aabdf6073e84: function(arg0) {
249
+ __wbg_new_77cc4f4f472aeb81: function(arg0) {
253
250
  return addHeapObject(new Uint8Array(getObject(arg0)));
254
251
  },
255
- __wbg_new_da52cf8fe3429cb2: function() {
256
- return addHeapObject(/* @__PURE__ */ new Object());
252
+ __wbg_new_cdf041679ded4c5f: function() {
253
+ return addHeapObject(/* @__PURE__ */ new Map());
257
254
  },
258
- __wbg_next_6dbf2c0ac8cde20f: function(arg0) {
259
- const ret = getObject(arg0).next;
260
- return addHeapObject(ret);
255
+ __wbg_new_ebe3e0f6837f0879: function() {
256
+ return addHeapObject(/* @__PURE__ */ new Object());
261
257
  },
262
- __wbg_next_71f2aa1cb3d1e37e: function() {
258
+ __wbg_next_42cf16ee0dafc9e2: function() {
263
259
  return handleError(function(arg0) {
264
260
  return addHeapObject(getObject(arg0).next());
265
261
  }, arguments);
266
262
  },
267
- __wbg_prototypesetcall_4770620bbe4688a0: function(arg0, arg1, arg2) {
263
+ __wbg_next_8f26b64fa5e9f64b: function(arg0) {
264
+ const ret = getObject(arg0).next;
265
+ return addHeapObject(ret);
266
+ },
267
+ __wbg_prototypesetcall_de8e0d9553586985: function(arg0, arg1, arg2) {
268
268
  Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
269
269
  },
270
- __wbg_set_575dd786d51585f8: function(arg0, arg1, arg2) {
270
+ __wbg_set_014226dfeca53178: function(arg0, arg1, arg2) {
271
271
  return addHeapObject(getObject(arg0).set(getObject(arg1), getObject(arg2)));
272
272
  },
273
273
  __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
274
274
  getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
275
275
  },
276
- __wbg_set_8a16b38e4805b298: function(arg0, arg1, arg2) {
276
+ __wbg_set_a80955eb93b145c6: function(arg0, arg1, arg2) {
277
277
  getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
278
278
  },
279
- __wbg_value_a5d5488a9589444a: function(arg0) {
279
+ __wbg_value_1e2369fab29b420e: function(arg0) {
280
280
  const ret = getObject(arg0).value;
281
281
  return addHeapObject(ret);
282
282
  },
@@ -457,10 +457,11 @@ function __wbg_finalize_init(instance, module) {
457
457
  }
458
458
  async function __wbg_load(module, imports) {
459
459
  if (typeof Response === "function" && module instanceof Response) {
460
+ if (!module.ok) throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
460
461
  if (typeof WebAssembly.instantiateStreaming === "function") try {
461
462
  return await WebAssembly.instantiateStreaming(module, imports);
462
463
  } catch (e) {
463
- if (module.ok && expectedResponseType(module.type) && module.headers.get("Content-Type") !== "application/wasm") console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
464
+ if (expectedResponseType(module.type) && module.headers.get("Content-Type") !== "application/wasm") console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
464
465
  else throw e;
465
466
  }
466
467
  const bytes = await module.arrayBuffer();
@@ -484,16 +485,20 @@ async function __wbg_load(module, imports) {
484
485
  }
485
486
  function initSync(module) {
486
487
  if (wasm !== void 0) return wasm;
487
- if (module !== void 0) if (Object.getPrototypeOf(module) === Object.prototype) ({module} = module);
488
- else console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
488
+ if (module !== void 0) {
489
+ if (Object.getPrototypeOf(module) === Object.prototype) ({module} = module);
490
+ else console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
491
+ }
489
492
  const imports = __wbg_get_imports();
490
493
  if (!(module instanceof WebAssembly.Module)) module = new WebAssembly.Module(module);
491
494
  return __wbg_finalize_init(new WebAssembly.Instance(module, imports), module);
492
495
  }
493
496
  async function __wbg_init(module_or_path) {
494
497
  if (wasm !== void 0) return wasm;
495
- if (module_or_path !== void 0) if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path);
496
- else console.warn("using deprecated parameters for the initialization function; pass a single object instead");
498
+ if (module_or_path !== void 0) {
499
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path);
500
+ else console.warn("using deprecated parameters for the initialization function; pass a single object instead");
501
+ }
497
502
  if (module_or_path === void 0) module_or_path = new URL("fontmin_wasm_core_bg.wasm", import.meta.url);
498
503
  const imports = __wbg_get_imports();
499
504
  if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) module_or_path = fetch(module_or_path);
Binary file
package/dist/index.mjs CHANGED
@@ -23,7 +23,7 @@ async function initWasm(input) {
23
23
  }
24
24
  }
25
25
  async function initializeWasm(input) {
26
- const module = await import("./fontmin_wasm_core-C2e3XISU.mjs");
26
+ const module = await import("./fontmin_wasm_core-B5DVVyeB.mjs");
27
27
  await module.default(input === void 0 ? void 0 : { module_or_path: input });
28
28
  if (module.runtime_name() !== "fontmin-rs") throw new Error("fontmin-rs WASM runtime did not initialize correctly");
29
29
  initialized = true;
@@ -63,9 +63,17 @@ function createFontminDiagnostics(operationName) {
63
63
  throw normalizeFontminDiagnostic(error);
64
64
  }
65
65
  }
66
+ async function withFontminDiagnosticsAsync(operation) {
67
+ try {
68
+ return await operation();
69
+ } catch (error) {
70
+ throw normalizeFontminDiagnostic(error);
71
+ }
72
+ }
66
73
  return {
67
74
  normalizeFontminDiagnostic,
68
- withFontminDiagnostics
75
+ withFontminDiagnostics,
76
+ withFontminDiagnosticsAsync
69
77
  };
70
78
  }
71
79
  //#endregion
@@ -73,6 +81,30 @@ function createFontminDiagnostics(operationName) {
73
81
  const { normalizeFontminDiagnostic, withFontminDiagnostics } = createFontminDiagnostics("fontmin-rs WASM operation");
74
82
  //#endregion
75
83
  //#region ../../packages/fontmin/src/runtime-neutral/optimize-policy.ts
84
+ async function mapWithConcurrency(inputs, concurrency, transform) {
85
+ if (!Number.isInteger(concurrency) || concurrency < 1) throw new TypeError("parallel thread count must be a positive integer");
86
+ if (inputs.length === 0) return [];
87
+ const outputs = [];
88
+ const failures = [];
89
+ let nextIndex = 0;
90
+ const worker = async () => {
91
+ while (failures.length === 0) {
92
+ const index = nextIndex;
93
+ nextIndex += 1;
94
+ if (index >= inputs.length) return;
95
+ const input = inputs[index];
96
+ try {
97
+ outputs[index] = await transform(input, index);
98
+ } catch (error) {
99
+ failures.push(error);
100
+ }
101
+ }
102
+ };
103
+ const workerCount = Math.min(concurrency, inputs.length);
104
+ await Promise.all(Array.from({ length: workerCount }, () => worker()));
105
+ if (failures.length > 0) throw failures[0];
106
+ return outputs;
107
+ }
76
108
  const FONT_CONVERSIONS = [
77
109
  {
78
110
  inputFormat: "otf",
@@ -105,38 +137,36 @@ const FONT_CONVERSIONS = [
105
137
  outputFormat: "woff2"
106
138
  }
107
139
  ];
108
- async function applyAssetTransform(assets, transform, context, normalize) {
109
- const transformedAssets = [];
110
- for (const asset of assets) {
140
+ async function applyAssetTransform(assets, transform, context, normalize, concurrency = 1) {
141
+ return (await mapWithConcurrency(assets, concurrency, async (asset) => {
111
142
  const result = await transform(asset, context);
112
- if (result === void 0) transformedAssets.push(asset);
113
- else if (Array.isArray(result)) transformedAssets.push(...result.map((asset) => normalize(asset)));
114
- else if (result !== null) transformedAssets.push(normalize(result));
115
- }
116
- return transformedAssets;
117
- }
118
- async function applyAssetConversion(assets, clone, convert) {
143
+ if (result === void 0) return [asset];
144
+ if (Array.isArray(result)) return result.map((asset) => normalize(asset));
145
+ if (result === null) return [];
146
+ return [normalize(result)];
147
+ })).flat();
148
+ }
149
+ async function applyAssetConversion(assets, clone, convert, concurrency = 1) {
150
+ const converted = await mapWithConcurrency(assets, concurrency, async (asset) => ({
151
+ asset,
152
+ convertedAsset: await convert(asset)
153
+ }));
119
154
  const primaryAssets = [];
120
155
  const clonedAssets = [];
121
- for (const asset of assets) {
122
- const convertedAsset = await convert(asset);
123
- if (convertedAsset === void 0) primaryAssets.push(asset);
124
- else if (clone) {
125
- primaryAssets.push(asset);
126
- clonedAssets.push(convertedAsset);
127
- } else primaryAssets.push(convertedAsset);
128
- }
156
+ for (const { asset, convertedAsset } of converted) if (convertedAsset === void 0) primaryAssets.push(asset);
157
+ else if (clone) {
158
+ primaryAssets.push(asset);
159
+ clonedAssets.push(convertedAsset);
160
+ } else primaryAssets.push(convertedAsset);
129
161
  return clone ? [...primaryAssets, ...clonedAssets] : primaryAssets;
130
162
  }
131
- async function applyFontConversion(assets, pluginName, clone, formatOf, convert) {
163
+ async function applyFontConversion(assets, pluginName, clone, formatOf, convert, concurrency = 1) {
132
164
  const conversion = FONT_CONVERSIONS.find((candidate) => candidate.name === pluginName);
133
165
  if (conversion === void 0) return;
134
- return applyAssetConversion(assets, clone, (asset) => formatOf(asset) === conversion.inputFormat ? convert(asset, conversion) : void 0);
166
+ return applyAssetConversion(assets, clone, (asset) => formatOf(asset) === conversion.inputFormat ? convert(asset, conversion) : void 0, concurrency);
135
167
  }
136
- async function flatMapAssets(assets, transform) {
137
- const transformedAssets = [];
138
- for (const asset of assets) transformedAssets.push(...await transform(asset));
139
- return transformedAssets;
168
+ async function flatMapAssets(assets, transform, concurrency = 1) {
169
+ return (await mapWithConcurrency(assets, concurrency, transform)).flat();
140
170
  }
141
171
  function missingGlyphWarning(report) {
142
172
  if (report.missing.length === 0) return;
@@ -293,7 +323,7 @@ function coverageOptions(options) {
293
323
  }
294
324
  //#endregion
295
325
  //#region ../../packages/fontmin/src/runtime-neutral/auto-delivery.ts
296
- const DEFAULT_TARGET_BYTES = 100 * 1024;
326
+ const DEFAULT_TARGET_BYTES = 102400;
297
327
  const DEFAULT_TOLERANCE = .15;
298
328
  const DEFAULT_MAX_SLICES = 32;
299
329
  const GROUPS = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fontmin-rs/wasm",
3
- "version": "1.1.0",
3
+ "version": "1.2.0-rc.2",
4
4
  "description": "Browser WASM runtime for fontmin-rs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -25,10 +25,10 @@
25
25
  },
26
26
  "devDependencies": {
27
27
  "@ntnyq/tsconfig": "^3.1.0",
28
- "playwright": "^1.61.1",
29
- "tsdown": "^0.22.12",
28
+ "playwright": "^1.62.1",
29
+ "tsdown": "^0.22.14",
30
30
  "typescript": "^7.0.2",
31
- "vitest": "^4.1.10"
31
+ "vitest": "^4.1.11"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "pnpm run build:wasm && pnpm run build:js",