@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.
- package/dist/entry.node.cjs +5 -3
- package/dist/entry.node.js +5 -3
- package/dist/entry.web.d.ts +1 -1
- package/dist/entry.web.js +60 -16
- package/package.json +1 -1
package/dist/entry.node.cjs
CHANGED
|
@@ -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
|
-
|
|
371
|
-
const instance = await WebAssembly.instantiate(module2, importObject);
|
|
372
|
-
return { module: module2, instance };
|
|
374
|
+
throw err;
|
|
373
375
|
}
|
|
374
376
|
};
|
|
375
377
|
}
|
package/dist/entry.node.js
CHANGED
|
@@ -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
|
-
|
|
327
|
-
const instance = await WebAssembly.instantiate(module, importObject);
|
|
328
|
-
return { module, instance };
|
|
330
|
+
throw err;
|
|
329
331
|
}
|
|
330
332
|
};
|
|
331
333
|
}
|
package/dist/entry.web.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
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
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2813
|
+
let binary;
|
|
2814
|
+
if (wasmBinary instanceof ArrayBuffer) {
|
|
2815
|
+
binary = wasmBinary;
|
|
2776
2816
|
} else {
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
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