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