@shotstack/shotstack-canvas 1.1.5 → 1.1.7
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 +160 -52
- package/dist/entry.node.cjs.map +1 -1
- package/dist/entry.node.js +160 -52
- package/dist/entry.node.js.map +1 -1
- package/dist/entry.web.js +57 -3
- package/dist/entry.web.js.map +1 -1
- package/package.json +2 -3
- package/public/hb.wasm +0 -0
package/dist/entry.web.js
CHANGED
|
@@ -130,9 +130,62 @@ var RichTextAssetSchema = Joi.object({
|
|
|
130
130
|
|
|
131
131
|
// src/wasm/hb-loader.ts
|
|
132
132
|
var hbSingleton = null;
|
|
133
|
+
function isNode() {
|
|
134
|
+
return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
135
|
+
}
|
|
136
|
+
async function loadWasmWeb(wasmBaseURL) {
|
|
137
|
+
try {
|
|
138
|
+
if (wasmBaseURL) {
|
|
139
|
+
const url = wasmBaseURL.endsWith(".wasm") ? wasmBaseURL : wasmBaseURL.endsWith("/") ? `${wasmBaseURL}hb.wasm` : `${wasmBaseURL}/hb.wasm`;
|
|
140
|
+
console.log(`Fetching WASM from: ${url}`);
|
|
141
|
+
const response = await fetch(url);
|
|
142
|
+
if (response.ok) {
|
|
143
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
144
|
+
const bytes = new Uint8Array(arrayBuffer);
|
|
145
|
+
if (bytes.length >= 4 && bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115 && bytes[3] === 109) {
|
|
146
|
+
console.log(`\u2705 Valid WASM binary loaded (${bytes.length} bytes)`);
|
|
147
|
+
return arrayBuffer;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return void 0;
|
|
152
|
+
} catch (err) {
|
|
153
|
+
console.error("Error in loadWasmWeb:", err);
|
|
154
|
+
return void 0;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function setupWasmFetchInterceptor(wasmBinary) {
|
|
158
|
+
const originalFetch = window.fetch;
|
|
159
|
+
window.fetch = function(input, init) {
|
|
160
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
161
|
+
if (url.includes("hb.wasm") || url.endsWith(".wasm")) {
|
|
162
|
+
console.log(`\u{1F504} Intercepted fetch for: ${url}`);
|
|
163
|
+
return Promise.resolve(
|
|
164
|
+
new Response(wasmBinary, {
|
|
165
|
+
status: 200,
|
|
166
|
+
statusText: "OK",
|
|
167
|
+
headers: {
|
|
168
|
+
"Content-Type": "application/wasm",
|
|
169
|
+
"Content-Length": wasmBinary.byteLength.toString()
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
return originalFetch.apply(this, [input, init]);
|
|
175
|
+
};
|
|
176
|
+
}
|
|
133
177
|
async function initHB(wasmBaseURL) {
|
|
134
178
|
if (hbSingleton) return hbSingleton;
|
|
135
179
|
try {
|
|
180
|
+
let wasmBinary;
|
|
181
|
+
wasmBinary = await loadWasmWeb(wasmBaseURL);
|
|
182
|
+
if (!wasmBinary) {
|
|
183
|
+
throw new Error("Failed to load WASM binary from any source");
|
|
184
|
+
}
|
|
185
|
+
console.log(`\u2705 WASM binary loaded successfully (${wasmBinary.byteLength} bytes)`);
|
|
186
|
+
if (!isNode()) {
|
|
187
|
+
setupWasmFetchInterceptor(wasmBinary);
|
|
188
|
+
}
|
|
136
189
|
const mod = await import("harfbuzzjs");
|
|
137
190
|
const candidate = mod.default;
|
|
138
191
|
let hb;
|
|
@@ -146,10 +199,11 @@ async function initHB(wasmBaseURL) {
|
|
|
146
199
|
if (!hb || typeof hb.createBuffer !== "function" || typeof hb.createFont !== "function") {
|
|
147
200
|
throw new Error("Failed to initialize HarfBuzz: unexpected export shape from 'harfbuzzjs'.");
|
|
148
201
|
}
|
|
149
|
-
void wasmBaseURL;
|
|
150
202
|
hbSingleton = hb;
|
|
203
|
+
console.log("\u2705 HarfBuzz initialized successfully");
|
|
151
204
|
return hbSingleton;
|
|
152
205
|
} catch (err) {
|
|
206
|
+
console.error("Failed to initialize HarfBuzz:", err);
|
|
153
207
|
throw new Error(
|
|
154
208
|
`Failed to initialize HarfBuzz: ${err instanceof Error ? err.message : String(err)}`
|
|
155
209
|
);
|
|
@@ -187,7 +241,7 @@ var _FontRegistry = class _FontRegistry {
|
|
|
187
241
|
}
|
|
188
242
|
async _doInit() {
|
|
189
243
|
try {
|
|
190
|
-
this.hb = await initHB(
|
|
244
|
+
this.hb = await initHB("https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm");
|
|
191
245
|
} catch (error) {
|
|
192
246
|
this.initPromise = void 0;
|
|
193
247
|
throw error;
|
|
@@ -1406,7 +1460,7 @@ async function createTextEngine(opts = {}) {
|
|
|
1406
1460
|
const width = opts.width ?? CANVAS_CONFIG.DEFAULTS.width;
|
|
1407
1461
|
const height = opts.height ?? CANVAS_CONFIG.DEFAULTS.height;
|
|
1408
1462
|
const pixelRatio = opts.pixelRatio ?? CANVAS_CONFIG.DEFAULTS.pixelRatio;
|
|
1409
|
-
const wasmBaseURL =
|
|
1463
|
+
const wasmBaseURL = "https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm";
|
|
1410
1464
|
const fonts = new FontRegistry(wasmBaseURL);
|
|
1411
1465
|
const layout = new LayoutEngine(fonts);
|
|
1412
1466
|
try {
|