@shotstack/shotstack-canvas 1.4.5 → 1.4.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.
@@ -0,0 +1,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
+ }) : x)(function(x) {
7
+ if (typeof require !== "undefined") return require.apply(this, arguments);
8
+ throw Error('Dynamic require of "' + x + '" is not supported');
9
+ });
10
+ var __commonJS = (cb, mod) => function __require2() {
11
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
+ };
13
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
14
+
15
+ export {
16
+ __require,
17
+ __commonJS,
18
+ __publicField
19
+ };
@@ -178,10 +178,6 @@ function bufferToArrayBuffer(buffer) {
178
178
  }
179
179
  return arrayBuffer;
180
180
  }
181
- function getPkgName() {
182
- const codes = [104, 97, 114, 102, 98, 117, 122, 122, 106, 115];
183
- return codes.map((c) => String.fromCharCode(c)).join("");
184
- }
185
181
  var DEFAULT_WASM_URL = "https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm";
186
182
  async function fetchWasmFromUrl(url) {
187
183
  try {
@@ -210,11 +206,10 @@ async function loadWasmNode() {
210
206
  const { readFile: readFile2 } = await import("fs/promises");
211
207
  const path = await import("path");
212
208
  const candidates = [];
213
- const pkgName = getPkgName();
214
209
  try {
215
210
  const { createRequire } = await import("module");
216
211
  const requireFn = createRequire(import_meta.url || `file://${process.cwd()}/`);
217
- const harfbuzzPkgPath = requireFn.resolve(pkgName + "/package.json");
212
+ const harfbuzzPkgPath = requireFn.resolve("harfbuzzjs/package.json");
218
213
  const harfbuzzDir = path.dirname(harfbuzzPkgPath);
219
214
  candidates.push(path.join(harfbuzzDir, "hb.wasm"));
220
215
  } catch {
@@ -233,11 +228,11 @@ async function loadWasmNode() {
233
228
  candidates.push(
234
229
  path.join(currentDir, "dist/hb.wasm"),
235
230
  path.join(currentDir, "assets/wasm/hb.wasm"),
236
- path.join(currentDir, "node_modules", pkgName, "hb.wasm"),
231
+ path.join(currentDir, "node_modules/harfbuzzjs/hb.wasm"),
237
232
  path.join(currentDir, "node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm")
238
233
  );
239
234
  candidates.push(
240
- "/var/task/node_modules/" + pkgName + "/hb.wasm",
235
+ "/var/task/node_modules/harfbuzzjs/hb.wasm",
241
236
  "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm"
242
237
  );
243
238
  console.log(`\u{1F50D} Searching for WASM in ${candidates.length} local paths...`);
@@ -298,6 +293,23 @@ function setupWasmInterceptors(wasmBinary) {
298
293
  }
299
294
  return originalFetch.apply(this, [input, init]);
300
295
  };
296
+ const originalInstantiate = WebAssembly.instantiate;
297
+ WebAssembly.instantiate = async function(bufferSourceOrModule, importObject) {
298
+ console.log(
299
+ `\u{1F504} WebAssembly.instantiate called, type: ${bufferSourceOrModule instanceof WebAssembly.Module ? "Module" : "BufferSource"}`
300
+ );
301
+ if (bufferSourceOrModule instanceof WebAssembly.Module) {
302
+ return originalInstantiate.call(WebAssembly, bufferSourceOrModule, importObject);
303
+ }
304
+ console.log(`\u{1F504} Intercepted WebAssembly.instantiate, using pre-loaded WASM binary`);
305
+ const module2 = await WebAssembly.compile(wasmBinary);
306
+ const instance = await originalInstantiate.call(
307
+ WebAssembly,
308
+ module2,
309
+ importObject
310
+ );
311
+ return { module: module2, instance };
312
+ };
301
313
  const originalInstantiateStreaming = WebAssembly.instantiateStreaming;
302
314
  if (originalInstantiateStreaming) {
303
315
  WebAssembly.instantiateStreaming = async function(source, importObject) {
@@ -320,18 +332,6 @@ function setupWasmInterceptors(wasmBinary) {
320
332
  };
321
333
  }
322
334
  }
323
- async function importHarfBuzzJS() {
324
- try {
325
- const moduleName = getPkgName();
326
- const dynamicImport = new Function("specifier", "return import(specifier)");
327
- return await dynamicImport(moduleName);
328
- } catch (err) {
329
- console.error("Failed to import harfbuzzjs:", err);
330
- throw new Error(
331
- `Cannot import harfbuzzjs. This library requires harfbuzzjs to be installed. Error: ${err instanceof Error ? err.message : String(err)}`
332
- );
333
- }
334
- }
335
335
  async function initHB(wasmBaseURL) {
336
336
  if (hbSingleton) return hbSingleton;
337
337
  try {
@@ -347,21 +347,25 @@ async function initHB(wasmBaseURL) {
347
347
  console.log(`\u2705 WASM binary loaded successfully (${wasmBinary.byteLength} bytes)`);
348
348
  if (!isNode()) {
349
349
  setupWasmInterceptors(wasmBinary);
350
- }
351
- const mod = await importHarfBuzzJS();
352
- let hb;
353
- const candidate = mod.default || mod;
354
- if (typeof candidate === "function") {
355
- hb = await candidate({
356
- wasmBinary
357
- });
358
- } else if (candidate && typeof candidate.then === "function") {
359
- hb = await candidate;
360
- } else if (candidate && typeof candidate.createBuffer === "function") {
361
- hb = candidate;
362
- } else {
363
- throw new Error(`Unexpected harfbuzzjs export type: ${typeof candidate}`);
364
- }
350
+ window.Module = {
351
+ wasmBinary,
352
+ locateFile: (path) => {
353
+ console.log(`\u{1F50D} locateFile called for: ${path}`);
354
+ return path;
355
+ }
356
+ };
357
+ console.log(`\u{1F30D} Set global Module.wasmBinary (${wasmBinary.byteLength} bytes)`);
358
+ }
359
+ console.log("\u{1F504} Importing harfbuzzjs/hb.js (factory)");
360
+ const hbModule = await import("harfbuzzjs/hb.js");
361
+ const hbFactory = hbModule.default || hbModule;
362
+ console.log("\u{1F504} Calling hb factory with wasmBinary");
363
+ const hbInstance = await hbFactory({ wasmBinary });
364
+ console.log("\u{1F504} Importing harfbuzzjs/hbjs.js (wrapper)");
365
+ const hbjsModule = await import("harfbuzzjs/hbjs.js");
366
+ const hbjsWrapper = hbjsModule.default || hbjsModule;
367
+ console.log("\u{1F504} Wrapping hb instance");
368
+ const hb = hbjsWrapper(hbInstance);
365
369
  if (!hb || typeof hb.createBuffer !== "function" || typeof hb.createFont !== "function") {
366
370
  throw new Error("Failed to initialize HarfBuzz: unexpected export shape from 'harfbuzzjs'.");
367
371
  }
@@ -139,10 +139,6 @@ function bufferToArrayBuffer(buffer) {
139
139
  }
140
140
  return arrayBuffer;
141
141
  }
142
- function getPkgName() {
143
- const codes = [104, 97, 114, 102, 98, 117, 122, 122, 106, 115];
144
- return codes.map((c) => String.fromCharCode(c)).join("");
145
- }
146
142
  var DEFAULT_WASM_URL = "https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm";
147
143
  async function fetchWasmFromUrl(url) {
148
144
  try {
@@ -171,11 +167,10 @@ async function loadWasmNode() {
171
167
  const { readFile: readFile2 } = await import("fs/promises");
172
168
  const path = await import("path");
173
169
  const candidates = [];
174
- const pkgName = getPkgName();
175
170
  try {
176
171
  const { createRequire } = await import("module");
177
172
  const requireFn = createRequire(import.meta.url || `file://${process.cwd()}/`);
178
- const harfbuzzPkgPath = requireFn.resolve(pkgName + "/package.json");
173
+ const harfbuzzPkgPath = requireFn.resolve("harfbuzzjs/package.json");
179
174
  const harfbuzzDir = path.dirname(harfbuzzPkgPath);
180
175
  candidates.push(path.join(harfbuzzDir, "hb.wasm"));
181
176
  } catch {
@@ -194,11 +189,11 @@ async function loadWasmNode() {
194
189
  candidates.push(
195
190
  path.join(currentDir, "dist/hb.wasm"),
196
191
  path.join(currentDir, "assets/wasm/hb.wasm"),
197
- path.join(currentDir, "node_modules", pkgName, "hb.wasm"),
192
+ path.join(currentDir, "node_modules/harfbuzzjs/hb.wasm"),
198
193
  path.join(currentDir, "node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm")
199
194
  );
200
195
  candidates.push(
201
- "/var/task/node_modules/" + pkgName + "/hb.wasm",
196
+ "/var/task/node_modules/harfbuzzjs/hb.wasm",
202
197
  "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm"
203
198
  );
204
199
  console.log(`\u{1F50D} Searching for WASM in ${candidates.length} local paths...`);
@@ -259,6 +254,23 @@ function setupWasmInterceptors(wasmBinary) {
259
254
  }
260
255
  return originalFetch.apply(this, [input, init]);
261
256
  };
257
+ const originalInstantiate = WebAssembly.instantiate;
258
+ WebAssembly.instantiate = async function(bufferSourceOrModule, importObject) {
259
+ console.log(
260
+ `\u{1F504} WebAssembly.instantiate called, type: ${bufferSourceOrModule instanceof WebAssembly.Module ? "Module" : "BufferSource"}`
261
+ );
262
+ if (bufferSourceOrModule instanceof WebAssembly.Module) {
263
+ return originalInstantiate.call(WebAssembly, bufferSourceOrModule, importObject);
264
+ }
265
+ console.log(`\u{1F504} Intercepted WebAssembly.instantiate, using pre-loaded WASM binary`);
266
+ const module = await WebAssembly.compile(wasmBinary);
267
+ const instance = await originalInstantiate.call(
268
+ WebAssembly,
269
+ module,
270
+ importObject
271
+ );
272
+ return { module, instance };
273
+ };
262
274
  const originalInstantiateStreaming = WebAssembly.instantiateStreaming;
263
275
  if (originalInstantiateStreaming) {
264
276
  WebAssembly.instantiateStreaming = async function(source, importObject) {
@@ -281,18 +293,6 @@ function setupWasmInterceptors(wasmBinary) {
281
293
  };
282
294
  }
283
295
  }
284
- async function importHarfBuzzJS() {
285
- try {
286
- const moduleName = getPkgName();
287
- const dynamicImport = new Function("specifier", "return import(specifier)");
288
- return await dynamicImport(moduleName);
289
- } catch (err) {
290
- console.error("Failed to import harfbuzzjs:", err);
291
- throw new Error(
292
- `Cannot import harfbuzzjs. This library requires harfbuzzjs to be installed. Error: ${err instanceof Error ? err.message : String(err)}`
293
- );
294
- }
295
- }
296
296
  async function initHB(wasmBaseURL) {
297
297
  if (hbSingleton) return hbSingleton;
298
298
  try {
@@ -308,21 +308,25 @@ async function initHB(wasmBaseURL) {
308
308
  console.log(`\u2705 WASM binary loaded successfully (${wasmBinary.byteLength} bytes)`);
309
309
  if (!isNode()) {
310
310
  setupWasmInterceptors(wasmBinary);
311
- }
312
- const mod = await importHarfBuzzJS();
313
- let hb;
314
- const candidate = mod.default || mod;
315
- if (typeof candidate === "function") {
316
- hb = await candidate({
317
- wasmBinary
318
- });
319
- } else if (candidate && typeof candidate.then === "function") {
320
- hb = await candidate;
321
- } else if (candidate && typeof candidate.createBuffer === "function") {
322
- hb = candidate;
323
- } else {
324
- throw new Error(`Unexpected harfbuzzjs export type: ${typeof candidate}`);
325
- }
311
+ window.Module = {
312
+ wasmBinary,
313
+ locateFile: (path) => {
314
+ console.log(`\u{1F50D} locateFile called for: ${path}`);
315
+ return path;
316
+ }
317
+ };
318
+ console.log(`\u{1F30D} Set global Module.wasmBinary (${wasmBinary.byteLength} bytes)`);
319
+ }
320
+ console.log("\u{1F504} Importing harfbuzzjs/hb.js (factory)");
321
+ const hbModule = await import("harfbuzzjs/hb.js");
322
+ const hbFactory = hbModule.default || hbModule;
323
+ console.log("\u{1F504} Calling hb factory with wasmBinary");
324
+ const hbInstance = await hbFactory({ wasmBinary });
325
+ console.log("\u{1F504} Importing harfbuzzjs/hbjs.js (wrapper)");
326
+ const hbjsModule = await import("harfbuzzjs/hbjs.js");
327
+ const hbjsWrapper = hbjsModule.default || hbjsModule;
328
+ console.log("\u{1F504} Wrapping hb instance");
329
+ const hb = hbjsWrapper(hbInstance);
326
330
  if (!hb || typeof hb.createBuffer !== "function" || typeof hb.createFont !== "function") {
327
331
  throw new Error("Failed to initialize HarfBuzz: unexpected export shape from 'harfbuzzjs'.");
328
332
  }
package/dist/entry.web.js CHANGED
@@ -1,6 +1,6 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1
+ import {
2
+ __publicField
3
+ } from "./chunk-HYGMWVDX.js";
4
4
 
5
5
  // src/schema/asset-schema.ts
6
6
  import Joi from "joi";
@@ -143,10 +143,6 @@ function bufferToArrayBuffer(buffer) {
143
143
  }
144
144
  return arrayBuffer;
145
145
  }
146
- function getPkgName() {
147
- const codes = [104, 97, 114, 102, 98, 117, 122, 122, 106, 115];
148
- return codes.map((c) => String.fromCharCode(c)).join("");
149
- }
150
146
  var DEFAULT_WASM_URL = "https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm";
151
147
  async function fetchWasmFromUrl(url) {
152
148
  try {
@@ -175,11 +171,10 @@ async function loadWasmNode() {
175
171
  const { readFile } = await import("fs/promises");
176
172
  const path = await import("path");
177
173
  const candidates = [];
178
- const pkgName = getPkgName();
179
174
  try {
180
175
  const { createRequire } = await import("module");
181
176
  const requireFn = createRequire(import.meta.url || `file://${process.cwd()}/`);
182
- const harfbuzzPkgPath = requireFn.resolve(pkgName + "/package.json");
177
+ const harfbuzzPkgPath = requireFn.resolve("harfbuzzjs/package.json");
183
178
  const harfbuzzDir = path.dirname(harfbuzzPkgPath);
184
179
  candidates.push(path.join(harfbuzzDir, "hb.wasm"));
185
180
  } catch {
@@ -198,11 +193,11 @@ async function loadWasmNode() {
198
193
  candidates.push(
199
194
  path.join(currentDir, "dist/hb.wasm"),
200
195
  path.join(currentDir, "assets/wasm/hb.wasm"),
201
- path.join(currentDir, "node_modules", pkgName, "hb.wasm"),
196
+ path.join(currentDir, "node_modules/harfbuzzjs/hb.wasm"),
202
197
  path.join(currentDir, "node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm")
203
198
  );
204
199
  candidates.push(
205
- "/var/task/node_modules/" + pkgName + "/hb.wasm",
200
+ "/var/task/node_modules/harfbuzzjs/hb.wasm",
206
201
  "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm"
207
202
  );
208
203
  console.log(`\u{1F50D} Searching for WASM in ${candidates.length} local paths...`);
@@ -263,6 +258,23 @@ function setupWasmInterceptors(wasmBinary) {
263
258
  }
264
259
  return originalFetch.apply(this, [input, init]);
265
260
  };
261
+ const originalInstantiate = WebAssembly.instantiate;
262
+ WebAssembly.instantiate = async function(bufferSourceOrModule, importObject) {
263
+ console.log(
264
+ `\u{1F504} WebAssembly.instantiate called, type: ${bufferSourceOrModule instanceof WebAssembly.Module ? "Module" : "BufferSource"}`
265
+ );
266
+ if (bufferSourceOrModule instanceof WebAssembly.Module) {
267
+ return originalInstantiate.call(WebAssembly, bufferSourceOrModule, importObject);
268
+ }
269
+ console.log(`\u{1F504} Intercepted WebAssembly.instantiate, using pre-loaded WASM binary`);
270
+ const module = await WebAssembly.compile(wasmBinary);
271
+ const instance = await originalInstantiate.call(
272
+ WebAssembly,
273
+ module,
274
+ importObject
275
+ );
276
+ return { module, instance };
277
+ };
266
278
  const originalInstantiateStreaming = WebAssembly.instantiateStreaming;
267
279
  if (originalInstantiateStreaming) {
268
280
  WebAssembly.instantiateStreaming = async function(source, importObject) {
@@ -285,18 +297,6 @@ function setupWasmInterceptors(wasmBinary) {
285
297
  };
286
298
  }
287
299
  }
288
- async function importHarfBuzzJS() {
289
- try {
290
- const moduleName = getPkgName();
291
- const dynamicImport = new Function("specifier", "return import(specifier)");
292
- return await dynamicImport(moduleName);
293
- } catch (err) {
294
- console.error("Failed to import harfbuzzjs:", err);
295
- throw new Error(
296
- `Cannot import harfbuzzjs. This library requires harfbuzzjs to be installed. Error: ${err instanceof Error ? err.message : String(err)}`
297
- );
298
- }
299
- }
300
300
  async function initHB(wasmBaseURL) {
301
301
  if (hbSingleton) return hbSingleton;
302
302
  try {
@@ -312,21 +312,25 @@ async function initHB(wasmBaseURL) {
312
312
  console.log(`\u2705 WASM binary loaded successfully (${wasmBinary.byteLength} bytes)`);
313
313
  if (!isNode()) {
314
314
  setupWasmInterceptors(wasmBinary);
315
- }
316
- const mod = await importHarfBuzzJS();
317
- let hb;
318
- const candidate = mod.default || mod;
319
- if (typeof candidate === "function") {
320
- hb = await candidate({
321
- wasmBinary
322
- });
323
- } else if (candidate && typeof candidate.then === "function") {
324
- hb = await candidate;
325
- } else if (candidate && typeof candidate.createBuffer === "function") {
326
- hb = candidate;
327
- } else {
328
- throw new Error(`Unexpected harfbuzzjs export type: ${typeof candidate}`);
329
- }
315
+ window.Module = {
316
+ wasmBinary,
317
+ locateFile: (path) => {
318
+ console.log(`\u{1F50D} locateFile called for: ${path}`);
319
+ return path;
320
+ }
321
+ };
322
+ console.log(`\u{1F30D} Set global Module.wasmBinary (${wasmBinary.byteLength} bytes)`);
323
+ }
324
+ console.log("\u{1F504} Importing harfbuzzjs/hb.js (factory)");
325
+ const hbModule = await import("./hb-KXF2MJ2J.js");
326
+ const hbFactory = hbModule.default || hbModule;
327
+ console.log("\u{1F504} Calling hb factory with wasmBinary");
328
+ const hbInstance = await hbFactory({ wasmBinary });
329
+ console.log("\u{1F504} Importing harfbuzzjs/hbjs.js (wrapper)");
330
+ const hbjsModule = await import("./hbjs-ZTRARROF.js");
331
+ const hbjsWrapper = hbjsModule.default || hbjsModule;
332
+ console.log("\u{1F504} Wrapping hb instance");
333
+ const hb = hbjsWrapper(hbInstance);
330
334
  if (!hb || typeof hb.createBuffer !== "function" || typeof hb.createFont !== "function") {
331
335
  throw new Error("Failed to initialize HarfBuzz: unexpected export shape from 'harfbuzzjs'.");
332
336
  }