@shotstack/shotstack-canvas 1.8.5 → 1.9.0
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.web.d.ts +1 -1
- package/dist/entry.web.js +55 -13
- package/package.json +1 -1
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
|
@@ -2748,17 +2748,55 @@ function quadraticToCubic(x0, y0, qx, qy, x, y) {
|
|
|
2748
2748
|
// src/core/resvg-renderer-web.ts
|
|
2749
2749
|
var resvgWasmModule = null;
|
|
2750
2750
|
var wasmInitialized = false;
|
|
2751
|
-
|
|
2751
|
+
var DEFAULT_RESVG_WASM_URL = "https://unpkg.com/@resvg/resvg-wasm@2.6.2/index_bg.wasm";
|
|
2752
|
+
async function fetchResvgWasmFromUrl(url) {
|
|
2753
|
+
try {
|
|
2754
|
+
const response = await fetch(url);
|
|
2755
|
+
if (response.ok) {
|
|
2756
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
2757
|
+
const bytes = new Uint8Array(arrayBuffer);
|
|
2758
|
+
if (bytes.length >= 4 && bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115 && bytes[3] === 109) {
|
|
2759
|
+
return arrayBuffer;
|
|
2760
|
+
} else {
|
|
2761
|
+
console.error(`Invalid WASM magic number from URL: ${url}`);
|
|
2762
|
+
}
|
|
2763
|
+
} else {
|
|
2764
|
+
console.error(`Failed to fetch resvg WASM from URL: ${url}, status: ${response.status}`);
|
|
2765
|
+
}
|
|
2766
|
+
return void 0;
|
|
2767
|
+
} catch (err) {
|
|
2768
|
+
console.error(`Error fetching resvg WASM from ${url}:`, err);
|
|
2769
|
+
return void 0;
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
async function loadResvgWasmWeb(wasmBaseURL) {
|
|
2773
|
+
try {
|
|
2774
|
+
if (wasmBaseURL) {
|
|
2775
|
+
const url = wasmBaseURL.endsWith(".wasm") ? wasmBaseURL : wasmBaseURL.endsWith("/") ? `${wasmBaseURL}resvg.wasm` : `${wasmBaseURL}/resvg.wasm`;
|
|
2776
|
+
const result = await fetchResvgWasmFromUrl(url);
|
|
2777
|
+
if (result) return result;
|
|
2778
|
+
}
|
|
2779
|
+
return void 0;
|
|
2780
|
+
} catch (err) {
|
|
2781
|
+
console.error("Error in loadResvgWasmWeb:", err);
|
|
2782
|
+
return void 0;
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
async function initResvgWasm(wasmBaseURL) {
|
|
2752
2786
|
if (resvgWasmModule && wasmInitialized) {
|
|
2753
2787
|
return resvgWasmModule;
|
|
2754
2788
|
}
|
|
2755
2789
|
const wasmModule = await import("@resvg/resvg-wasm");
|
|
2756
2790
|
resvgWasmModule = wasmModule;
|
|
2757
2791
|
if (!wasmInitialized) {
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2792
|
+
let wasmBinary = await loadResvgWasmWeb(wasmBaseURL);
|
|
2793
|
+
if (!wasmBinary) {
|
|
2794
|
+
wasmBinary = await fetchResvgWasmFromUrl(DEFAULT_RESVG_WASM_URL);
|
|
2795
|
+
}
|
|
2796
|
+
if (!wasmBinary) {
|
|
2797
|
+
throw new Error("Failed to load resvg WASM from any source");
|
|
2798
|
+
}
|
|
2799
|
+
const compiled = await WebAssembly.compile(wasmBinary);
|
|
2762
2800
|
await resvgWasmModule.initWasm(compiled);
|
|
2763
2801
|
wasmInitialized = true;
|
|
2764
2802
|
}
|
|
@@ -2770,16 +2808,20 @@ async function initResvg(wasmBinary) {
|
|
|
2770
2808
|
}
|
|
2771
2809
|
const wasmModule = await import("@resvg/resvg-wasm");
|
|
2772
2810
|
resvgWasmModule = wasmModule;
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2811
|
+
let binary;
|
|
2812
|
+
if (wasmBinary instanceof ArrayBuffer) {
|
|
2813
|
+
binary = wasmBinary;
|
|
2776
2814
|
} else {
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2815
|
+
binary = await loadResvgWasmWeb(wasmBinary);
|
|
2816
|
+
if (!binary) {
|
|
2817
|
+
binary = await fetchResvgWasmFromUrl(DEFAULT_RESVG_WASM_URL);
|
|
2818
|
+
}
|
|
2819
|
+
}
|
|
2820
|
+
if (!binary) {
|
|
2821
|
+
throw new Error("Failed to load resvg WASM from any source");
|
|
2782
2822
|
}
|
|
2823
|
+
const compiled = await WebAssembly.compile(binary);
|
|
2824
|
+
await resvgWasmModule.initWasm(compiled);
|
|
2783
2825
|
wasmInitialized = true;
|
|
2784
2826
|
}
|
|
2785
2827
|
async function renderSvgToPng(svgString, options = {}) {
|
package/package.json
CHANGED