@shotstack/shotstack-canvas 1.8.4 → 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/README.md +13 -13
- package/dist/entry.node.cjs +2 -2
- package/dist/entry.node.js +2 -2
- package/dist/entry.web.d.ts +1 -1
- package/dist/entry.web.js +59 -17
- package/dist/{hb-ODWKSLMB.js → hb-KXF2MJ2J.js} +2 -2
- package/dist/{hbjs-HHU2TAW7.js → hbjs-ZTRARROF.js} +2 -2
- package/package.json +1 -1
- package/scripts/postinstall.js +58 -58
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# @shotstack/shotstack-canvas
|
|
2
|
-
|
|
3
|
-
One package → identical text shaping/wrapping/animation on Web & Node.
|
|
4
|
-
- HarfBuzz WASM for shaping and glyph outlines (via `harfbuzzjs`).
|
|
5
|
-
- Device-independent draw-ops.
|
|
6
|
-
- Painters: Canvas2D (web) and node-canvas (node).
|
|
7
|
-
- Deterministic time-driven animations.
|
|
8
|
-
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
pnpm add @shotstack/shotstack-canvas
|
|
13
|
-
# or npm i / yarn add
|
|
1
|
+
# @shotstack/shotstack-canvas
|
|
2
|
+
|
|
3
|
+
One package → identical text shaping/wrapping/animation on Web & Node.
|
|
4
|
+
- HarfBuzz WASM for shaping and glyph outlines (via `harfbuzzjs`).
|
|
5
|
+
- Device-independent draw-ops.
|
|
6
|
+
- Painters: Canvas2D (web) and node-canvas (node).
|
|
7
|
+
- Deterministic time-driven animations.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @shotstack/shotstack-canvas
|
|
13
|
+
# or npm i / yarn add
|
package/dist/entry.node.cjs
CHANGED
|
@@ -327,7 +327,7 @@ function setupWasmInterceptors(wasmBinary) {
|
|
|
327
327
|
const originalFetch = window.fetch;
|
|
328
328
|
window.fetch = function(input, init) {
|
|
329
329
|
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
330
|
-
if (url.includes("hb.wasm")
|
|
330
|
+
if (url.includes("hb.wasm")) {
|
|
331
331
|
return Promise.resolve(
|
|
332
332
|
new Response(wasmBinary.slice(0), {
|
|
333
333
|
status: 200,
|
|
@@ -360,7 +360,7 @@ function setupWasmInterceptors(wasmBinary) {
|
|
|
360
360
|
try {
|
|
361
361
|
const response = await source;
|
|
362
362
|
const url = response.url || "";
|
|
363
|
-
if (url.includes("hb.wasm")
|
|
363
|
+
if (url.includes("hb.wasm")) {
|
|
364
364
|
const module2 = await WebAssembly.compile(wasmBinary);
|
|
365
365
|
const instance = await WebAssembly.instantiate(module2, importObject);
|
|
366
366
|
return { module: module2, instance };
|
package/dist/entry.node.js
CHANGED
|
@@ -283,7 +283,7 @@ function setupWasmInterceptors(wasmBinary) {
|
|
|
283
283
|
const originalFetch = window.fetch;
|
|
284
284
|
window.fetch = function(input, init) {
|
|
285
285
|
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
286
|
-
if (url.includes("hb.wasm")
|
|
286
|
+
if (url.includes("hb.wasm")) {
|
|
287
287
|
return Promise.resolve(
|
|
288
288
|
new Response(wasmBinary.slice(0), {
|
|
289
289
|
status: 200,
|
|
@@ -316,7 +316,7 @@ function setupWasmInterceptors(wasmBinary) {
|
|
|
316
316
|
try {
|
|
317
317
|
const response = await source;
|
|
318
318
|
const url = response.url || "";
|
|
319
|
-
if (url.includes("hb.wasm")
|
|
319
|
+
if (url.includes("hb.wasm")) {
|
|
320
320
|
const module = await WebAssembly.compile(wasmBinary);
|
|
321
321
|
const instance = await WebAssembly.instantiate(module, importObject);
|
|
322
322
|
return { module, instance };
|
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
|
@@ -287,7 +287,7 @@ function setupWasmInterceptors(wasmBinary) {
|
|
|
287
287
|
const originalFetch = window.fetch;
|
|
288
288
|
window.fetch = function(input, init) {
|
|
289
289
|
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
290
|
-
if (url.includes("hb.wasm")
|
|
290
|
+
if (url.includes("hb.wasm")) {
|
|
291
291
|
return Promise.resolve(
|
|
292
292
|
new Response(wasmBinary.slice(0), {
|
|
293
293
|
status: 200,
|
|
@@ -320,7 +320,7 @@ function setupWasmInterceptors(wasmBinary) {
|
|
|
320
320
|
try {
|
|
321
321
|
const response = await source;
|
|
322
322
|
const url = response.url || "";
|
|
323
|
-
if (url.includes("hb.wasm")
|
|
323
|
+
if (url.includes("hb.wasm")) {
|
|
324
324
|
const module = await WebAssembly.compile(wasmBinary);
|
|
325
325
|
const instance = await WebAssembly.instantiate(module, importObject);
|
|
326
326
|
return { module, instance };
|
|
@@ -355,10 +355,10 @@ async function initHB(wasmBaseURL) {
|
|
|
355
355
|
}
|
|
356
356
|
};
|
|
357
357
|
}
|
|
358
|
-
const hbModule = await import("./hb-
|
|
358
|
+
const hbModule = await import("./hb-KXF2MJ2J.js");
|
|
359
359
|
const hbFactory = hbModule.default || hbModule;
|
|
360
360
|
const hbInstance = await hbFactory({ wasmBinary });
|
|
361
|
-
const hbjsModule = await import("./hbjs-
|
|
361
|
+
const hbjsModule = await import("./hbjs-ZTRARROF.js");
|
|
362
362
|
const hbjsWrapper = hbjsModule.default || hbjsModule;
|
|
363
363
|
const hb = hbjsWrapper(hbInstance);
|
|
364
364
|
if (!hb || typeof hb.createBuffer !== "function" || typeof hb.createFont !== "function") {
|
|
@@ -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 = {}) {
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
__require
|
|
5
5
|
} from "./chunk-HYGMWVDX.js";
|
|
6
6
|
|
|
7
|
-
// node_modules
|
|
7
|
+
// node_modules/harfbuzzjs/hb.js
|
|
8
8
|
var require_hb = __commonJS({
|
|
9
|
-
"node_modules
|
|
9
|
+
"node_modules/harfbuzzjs/hb.js"(exports, module) {
|
|
10
10
|
var createHarfBuzz = (() => {
|
|
11
11
|
var _scriptName = typeof document != "undefined" ? document.currentScript?.src : void 0;
|
|
12
12
|
return async function(moduleArg = {}) {
|
|
@@ -2,9 +2,9 @@ import {
|
|
|
2
2
|
__commonJS
|
|
3
3
|
} from "./chunk-HYGMWVDX.js";
|
|
4
4
|
|
|
5
|
-
// node_modules
|
|
5
|
+
// node_modules/harfbuzzjs/hbjs.js
|
|
6
6
|
var require_hbjs = __commonJS({
|
|
7
|
-
"node_modules
|
|
7
|
+
"node_modules/harfbuzzjs/hbjs.js"(exports, module) {
|
|
8
8
|
function hbjs(Module) {
|
|
9
9
|
"use strict";
|
|
10
10
|
var exports2 = Module.wasmExports;
|
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Postinstall script to verify native canvas bindings are available
|
|
5
|
-
* This helps catch issues early and provides helpful guidance
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { platform as _platform, arch as _arch } from 'os';
|
|
9
|
-
import { dirname } from 'path';
|
|
10
|
-
import { readdirSync } from 'fs';
|
|
11
|
-
import { createRequire } from 'module';
|
|
12
|
-
|
|
13
|
-
const require = createRequire(import.meta.url);
|
|
14
|
-
|
|
15
|
-
const platform = _platform();
|
|
16
|
-
const arch = _arch();
|
|
17
|
-
|
|
18
|
-
// Map platform/arch to package names
|
|
19
|
-
const platformMap = {
|
|
20
|
-
'darwin-arm64': '@napi-rs/canvas-darwin-arm64',
|
|
21
|
-
'darwin-x64': '@napi-rs/canvas-darwin-x64',
|
|
22
|
-
'linux-arm64': '@napi-rs/canvas-linux-arm64-gnu',
|
|
23
|
-
'linux-x64': '@napi-rs/canvas-linux-x64-gnu',
|
|
24
|
-
'win32-x64': '@napi-rs/canvas-win32-x64-msvc',
|
|
25
|
-
'linux-arm': '@napi-rs/canvas-linux-arm-gnueabihf',
|
|
26
|
-
'android-arm64': '@napi-rs/canvas-android-arm64',
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const platformKey = `${platform}-${arch}`;
|
|
30
|
-
const requiredPackage = platformMap[platformKey];
|
|
31
|
-
|
|
32
|
-
if (!requiredPackage) {
|
|
33
|
-
console.warn(`\n⚠️ Warning: Unsupported platform ${platformKey} for @napi-rs/canvas`);
|
|
34
|
-
console.warn(' Canvas rendering may not work on this platform.\n');
|
|
35
|
-
process.exit(0);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Check if the native binding package is installed
|
|
39
|
-
try {
|
|
40
|
-
const packagePath = require.resolve(`${requiredPackage}/package.json`);
|
|
41
|
-
const packageDir = dirname(packagePath);
|
|
42
|
-
|
|
43
|
-
// Verify the .node file exists
|
|
44
|
-
const nodeFiles = readdirSync(packageDir).filter(f => f.endsWith('.node'));
|
|
45
|
-
|
|
46
|
-
if (nodeFiles.length > 0) {
|
|
47
|
-
console.log(`✅ @shotstack/shotstack-canvas: Native canvas binding found for ${platformKey}`);
|
|
48
|
-
} else {
|
|
49
|
-
throw new Error('No .node file found');
|
|
50
|
-
}
|
|
51
|
-
} catch (error) {
|
|
52
|
-
console.warn(`\n⚠️ Warning: Native canvas binding not found for ${platformKey}`);
|
|
53
|
-
console.warn(` Expected package: ${requiredPackage}`);
|
|
54
|
-
console.warn('\n If you see "Cannot find native binding" errors, try:');
|
|
55
|
-
console.warn(' 1. Delete node_modules and package-lock.json');
|
|
56
|
-
console.warn(' 2. Run: npm install');
|
|
57
|
-
console.warn(` 3. Or manually install: npm install ${requiredPackage}\n`);
|
|
58
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Postinstall script to verify native canvas bindings are available
|
|
5
|
+
* This helps catch issues early and provides helpful guidance
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { platform as _platform, arch as _arch } from 'os';
|
|
9
|
+
import { dirname } from 'path';
|
|
10
|
+
import { readdirSync } from 'fs';
|
|
11
|
+
import { createRequire } from 'module';
|
|
12
|
+
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
|
|
15
|
+
const platform = _platform();
|
|
16
|
+
const arch = _arch();
|
|
17
|
+
|
|
18
|
+
// Map platform/arch to package names
|
|
19
|
+
const platformMap = {
|
|
20
|
+
'darwin-arm64': '@napi-rs/canvas-darwin-arm64',
|
|
21
|
+
'darwin-x64': '@napi-rs/canvas-darwin-x64',
|
|
22
|
+
'linux-arm64': '@napi-rs/canvas-linux-arm64-gnu',
|
|
23
|
+
'linux-x64': '@napi-rs/canvas-linux-x64-gnu',
|
|
24
|
+
'win32-x64': '@napi-rs/canvas-win32-x64-msvc',
|
|
25
|
+
'linux-arm': '@napi-rs/canvas-linux-arm-gnueabihf',
|
|
26
|
+
'android-arm64': '@napi-rs/canvas-android-arm64',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const platformKey = `${platform}-${arch}`;
|
|
30
|
+
const requiredPackage = platformMap[platformKey];
|
|
31
|
+
|
|
32
|
+
if (!requiredPackage) {
|
|
33
|
+
console.warn(`\n⚠️ Warning: Unsupported platform ${platformKey} for @napi-rs/canvas`);
|
|
34
|
+
console.warn(' Canvas rendering may not work on this platform.\n');
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Check if the native binding package is installed
|
|
39
|
+
try {
|
|
40
|
+
const packagePath = require.resolve(`${requiredPackage}/package.json`);
|
|
41
|
+
const packageDir = dirname(packagePath);
|
|
42
|
+
|
|
43
|
+
// Verify the .node file exists
|
|
44
|
+
const nodeFiles = readdirSync(packageDir).filter(f => f.endsWith('.node'));
|
|
45
|
+
|
|
46
|
+
if (nodeFiles.length > 0) {
|
|
47
|
+
console.log(`✅ @shotstack/shotstack-canvas: Native canvas binding found for ${platformKey}`);
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error('No .node file found');
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.warn(`\n⚠️ Warning: Native canvas binding not found for ${platformKey}`);
|
|
53
|
+
console.warn(` Expected package: ${requiredPackage}`);
|
|
54
|
+
console.warn('\n If you see "Cannot find native binding" errors, try:');
|
|
55
|
+
console.warn(' 1. Delete node_modules and package-lock.json');
|
|
56
|
+
console.warn(' 2. Run: npm install');
|
|
57
|
+
console.warn(` 3. Or manually install: npm install ${requiredPackage}\n`);
|
|
58
|
+
}
|