@shotstack/shotstack-canvas 1.8.5 → 1.9.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.
@@ -346,6 +346,10 @@ function setupWasmInterceptors(wasmBinary) {
346
346
  if (bufferSourceOrModule instanceof WebAssembly.Module) {
347
347
  return originalInstantiate.call(WebAssembly, bufferSourceOrModule, importObject);
348
348
  }
349
+ const inputSize = bufferSourceOrModule instanceof ArrayBuffer ? bufferSourceOrModule.byteLength : bufferSourceOrModule.byteLength;
350
+ if (inputSize !== wasmBinary.byteLength) {
351
+ return originalInstantiate.call(WebAssembly, bufferSourceOrModule, importObject);
352
+ }
349
353
  const module2 = await WebAssembly.compile(wasmBinary);
350
354
  const instance = await originalInstantiate.call(
351
355
  WebAssembly,
@@ -367,9 +371,7 @@ function setupWasmInterceptors(wasmBinary) {
367
371
  }
368
372
  return originalInstantiateStreaming.call(WebAssembly, response, importObject);
369
373
  } catch (err) {
370
- const module2 = await WebAssembly.compile(wasmBinary);
371
- const instance = await WebAssembly.instantiate(module2, importObject);
372
- return { module: module2, instance };
374
+ throw err;
373
375
  }
374
376
  };
375
377
  }
@@ -302,6 +302,10 @@ function setupWasmInterceptors(wasmBinary) {
302
302
  if (bufferSourceOrModule instanceof WebAssembly.Module) {
303
303
  return originalInstantiate.call(WebAssembly, bufferSourceOrModule, importObject);
304
304
  }
305
+ const inputSize = bufferSourceOrModule instanceof ArrayBuffer ? bufferSourceOrModule.byteLength : bufferSourceOrModule.byteLength;
306
+ if (inputSize !== wasmBinary.byteLength) {
307
+ return originalInstantiate.call(WebAssembly, bufferSourceOrModule, importObject);
308
+ }
305
309
  const module = await WebAssembly.compile(wasmBinary);
306
310
  const instance = await originalInstantiate.call(
307
311
  WebAssembly,
@@ -323,9 +327,7 @@ function setupWasmInterceptors(wasmBinary) {
323
327
  }
324
328
  return originalInstantiateStreaming.call(WebAssembly, response, importObject);
325
329
  } catch (err) {
326
- const module = await WebAssembly.compile(wasmBinary);
327
- const instance = await WebAssembly.instantiate(module, importObject);
328
- return { module, instance };
330
+ throw err;
329
331
  }
330
332
  };
331
333
  }
@@ -528,7 +528,7 @@ interface ResvgRenderResult {
528
528
  width: number;
529
529
  height: number;
530
530
  }
531
- declare function initResvg(wasmBinary?: ArrayBuffer): Promise<void>;
531
+ declare function initResvg(wasmBinary?: ArrayBuffer | string): Promise<void>;
532
532
  declare function renderSvgToPng(svgString: string, options?: ResvgRenderOptions): Promise<ResvgRenderResult>;
533
533
  declare function shapeToSvgString(asset: CanvasSvgAsset, defaultWidth: number, defaultHeight: number): string;
534
534
  declare function generateShapePathData(shape: NonNullable<CanvasSvgAsset["shape"]>): string;
package/dist/entry.web.js CHANGED
@@ -306,6 +306,10 @@ function setupWasmInterceptors(wasmBinary) {
306
306
  if (bufferSourceOrModule instanceof WebAssembly.Module) {
307
307
  return originalInstantiate.call(WebAssembly, bufferSourceOrModule, importObject);
308
308
  }
309
+ const inputSize = bufferSourceOrModule instanceof ArrayBuffer ? bufferSourceOrModule.byteLength : bufferSourceOrModule.byteLength;
310
+ if (inputSize !== wasmBinary.byteLength) {
311
+ return originalInstantiate.call(WebAssembly, bufferSourceOrModule, importObject);
312
+ }
309
313
  const module = await WebAssembly.compile(wasmBinary);
310
314
  const instance = await originalInstantiate.call(
311
315
  WebAssembly,
@@ -327,9 +331,7 @@ function setupWasmInterceptors(wasmBinary) {
327
331
  }
328
332
  return originalInstantiateStreaming.call(WebAssembly, response, importObject);
329
333
  } catch (err) {
330
- const module = await WebAssembly.compile(wasmBinary);
331
- const instance = await WebAssembly.instantiate(module, importObject);
332
- return { module, instance };
334
+ throw err;
333
335
  }
334
336
  };
335
337
  }
@@ -2748,17 +2750,55 @@ function quadraticToCubic(x0, y0, qx, qy, x, y) {
2748
2750
  // src/core/resvg-renderer-web.ts
2749
2751
  var resvgWasmModule = null;
2750
2752
  var wasmInitialized = false;
2751
- async function initResvgWasm() {
2753
+ var DEFAULT_RESVG_WASM_URL = "https://unpkg.com/@resvg/resvg-wasm@2.6.2/index_bg.wasm";
2754
+ async function fetchResvgWasmFromUrl(url) {
2755
+ try {
2756
+ const response = await fetch(url);
2757
+ if (response.ok) {
2758
+ const arrayBuffer = await response.arrayBuffer();
2759
+ const bytes = new Uint8Array(arrayBuffer);
2760
+ if (bytes.length >= 4 && bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115 && bytes[3] === 109) {
2761
+ return arrayBuffer;
2762
+ } else {
2763
+ console.error(`Invalid WASM magic number from URL: ${url}`);
2764
+ }
2765
+ } else {
2766
+ console.error(`Failed to fetch resvg WASM from URL: ${url}, status: ${response.status}`);
2767
+ }
2768
+ return void 0;
2769
+ } catch (err) {
2770
+ console.error(`Error fetching resvg WASM from ${url}:`, err);
2771
+ return void 0;
2772
+ }
2773
+ }
2774
+ async function loadResvgWasmWeb(wasmBaseURL) {
2775
+ try {
2776
+ if (wasmBaseURL) {
2777
+ const url = wasmBaseURL.endsWith(".wasm") ? wasmBaseURL : wasmBaseURL.endsWith("/") ? `${wasmBaseURL}resvg.wasm` : `${wasmBaseURL}/resvg.wasm`;
2778
+ const result = await fetchResvgWasmFromUrl(url);
2779
+ if (result) return result;
2780
+ }
2781
+ return void 0;
2782
+ } catch (err) {
2783
+ console.error("Error in loadResvgWasmWeb:", err);
2784
+ return void 0;
2785
+ }
2786
+ }
2787
+ async function initResvgWasm(wasmBaseURL) {
2752
2788
  if (resvgWasmModule && wasmInitialized) {
2753
2789
  return resvgWasmModule;
2754
2790
  }
2755
2791
  const wasmModule = await import("@resvg/resvg-wasm");
2756
2792
  resvgWasmModule = wasmModule;
2757
2793
  if (!wasmInitialized) {
2758
- const wasmUrl = new URL("@resvg/resvg-wasm/index_bg.wasm", import.meta.url);
2759
- const wasmResponse = await fetch(wasmUrl);
2760
- const wasmBytes = await wasmResponse.arrayBuffer();
2761
- const compiled = await WebAssembly.compile(wasmBytes);
2794
+ let wasmBinary = await loadResvgWasmWeb(wasmBaseURL);
2795
+ if (!wasmBinary) {
2796
+ wasmBinary = await fetchResvgWasmFromUrl(DEFAULT_RESVG_WASM_URL);
2797
+ }
2798
+ if (!wasmBinary) {
2799
+ throw new Error("Failed to load resvg WASM from any source");
2800
+ }
2801
+ const compiled = await WebAssembly.compile(wasmBinary);
2762
2802
  await resvgWasmModule.initWasm(compiled);
2763
2803
  wasmInitialized = true;
2764
2804
  }
@@ -2770,16 +2810,20 @@ async function initResvg(wasmBinary) {
2770
2810
  }
2771
2811
  const wasmModule = await import("@resvg/resvg-wasm");
2772
2812
  resvgWasmModule = wasmModule;
2773
- if (wasmBinary) {
2774
- const compiled = await WebAssembly.compile(wasmBinary);
2775
- await resvgWasmModule.initWasm(compiled);
2813
+ let binary;
2814
+ if (wasmBinary instanceof ArrayBuffer) {
2815
+ binary = wasmBinary;
2776
2816
  } else {
2777
- const wasmUrl = new URL("@resvg/resvg-wasm/index_bg.wasm", import.meta.url);
2778
- const wasmResponse = await fetch(wasmUrl);
2779
- const wasmBytes = await wasmResponse.arrayBuffer();
2780
- const compiled = await WebAssembly.compile(wasmBytes);
2781
- await resvgWasmModule.initWasm(compiled);
2817
+ binary = await loadResvgWasmWeb(wasmBinary);
2818
+ if (!binary) {
2819
+ binary = await fetchResvgWasmFromUrl(DEFAULT_RESVG_WASM_URL);
2820
+ }
2821
+ }
2822
+ if (!binary) {
2823
+ throw new Error("Failed to load resvg WASM from any source");
2782
2824
  }
2825
+ const compiled = await WebAssembly.compile(binary);
2826
+ await resvgWasmModule.initWasm(compiled);
2783
2827
  wasmInitialized = true;
2784
2828
  }
2785
2829
  async function renderSvgToPng(svgString, options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shotstack/shotstack-canvas",
3
- "version": "1.8.5",
3
+ "version": "1.9.1",
4
4
  "description": "Text layout & animation engine (HarfBuzz) for Node & Web - fully self-contained.",
5
5
  "type": "module",
6
6
  "main": "./dist/entry.node.cjs",