@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.
@@ -164,9 +164,62 @@ var RichTextAssetSchema = import_joi.default.object({
164
164
 
165
165
  // src/wasm/hb-loader.ts
166
166
  var hbSingleton = null;
167
+ function isNode() {
168
+ return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
169
+ }
170
+ async function loadWasmWeb(wasmBaseURL) {
171
+ try {
172
+ if (wasmBaseURL) {
173
+ const url = wasmBaseURL.endsWith(".wasm") ? wasmBaseURL : wasmBaseURL.endsWith("/") ? `${wasmBaseURL}hb.wasm` : `${wasmBaseURL}/hb.wasm`;
174
+ console.log(`Fetching WASM from: ${url}`);
175
+ const response = await fetch(url);
176
+ if (response.ok) {
177
+ const arrayBuffer = await response.arrayBuffer();
178
+ const bytes = new Uint8Array(arrayBuffer);
179
+ if (bytes.length >= 4 && bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115 && bytes[3] === 109) {
180
+ console.log(`\u2705 Valid WASM binary loaded (${bytes.length} bytes)`);
181
+ return arrayBuffer;
182
+ }
183
+ }
184
+ }
185
+ return void 0;
186
+ } catch (err) {
187
+ console.error("Error in loadWasmWeb:", err);
188
+ return void 0;
189
+ }
190
+ }
191
+ function setupWasmFetchInterceptor(wasmBinary) {
192
+ const originalFetch = window.fetch;
193
+ window.fetch = function(input, init) {
194
+ const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
195
+ if (url.includes("hb.wasm") || url.endsWith(".wasm")) {
196
+ console.log(`\u{1F504} Intercepted fetch for: ${url}`);
197
+ return Promise.resolve(
198
+ new Response(wasmBinary, {
199
+ status: 200,
200
+ statusText: "OK",
201
+ headers: {
202
+ "Content-Type": "application/wasm",
203
+ "Content-Length": wasmBinary.byteLength.toString()
204
+ }
205
+ })
206
+ );
207
+ }
208
+ return originalFetch.apply(this, [input, init]);
209
+ };
210
+ }
167
211
  async function initHB(wasmBaseURL) {
168
212
  if (hbSingleton) return hbSingleton;
169
213
  try {
214
+ let wasmBinary;
215
+ wasmBinary = await loadWasmWeb(wasmBaseURL);
216
+ if (!wasmBinary) {
217
+ throw new Error("Failed to load WASM binary from any source");
218
+ }
219
+ console.log(`\u2705 WASM binary loaded successfully (${wasmBinary.byteLength} bytes)`);
220
+ if (!isNode()) {
221
+ setupWasmFetchInterceptor(wasmBinary);
222
+ }
170
223
  const mod = await import("harfbuzzjs");
171
224
  const candidate = mod.default;
172
225
  let hb;
@@ -180,10 +233,11 @@ async function initHB(wasmBaseURL) {
180
233
  if (!hb || typeof hb.createBuffer !== "function" || typeof hb.createFont !== "function") {
181
234
  throw new Error("Failed to initialize HarfBuzz: unexpected export shape from 'harfbuzzjs'.");
182
235
  }
183
- void wasmBaseURL;
184
236
  hbSingleton = hb;
237
+ console.log("\u2705 HarfBuzz initialized successfully");
185
238
  return hbSingleton;
186
239
  } catch (err) {
240
+ console.error("Failed to initialize HarfBuzz:", err);
187
241
  throw new Error(
188
242
  `Failed to initialize HarfBuzz: ${err instanceof Error ? err.message : String(err)}`
189
243
  );
@@ -222,7 +276,7 @@ var FontRegistry = class _FontRegistry {
222
276
  }
223
277
  async _doInit() {
224
278
  try {
225
- this.hb = await initHB(this.wasmBaseURL);
279
+ this.hb = await initHB("https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm");
226
280
  } catch (error) {
227
281
  this.initPromise = void 0;
228
282
  throw error;