@shotstack/shotstack-canvas 1.3.3 → 1.3.5

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.
@@ -202,40 +202,41 @@ async function fetchWasmFromUrl(url) {
202
202
  return void 0;
203
203
  }
204
204
  }
205
- async function loadWasmNode(wasmBaseURL) {
205
+ async function loadWasmNode() {
206
206
  try {
207
207
  const { readFile: readFile2 } = await import("fs/promises");
208
- const { fileURLToPath } = await import("url");
209
208
  const path = await import("path");
210
- const { createRequire } = await import("module");
211
- const currentDir = path.dirname(fileURLToPath(import_meta.url));
212
- let harfbuzzWasmPath;
209
+ const candidates = [];
213
210
  try {
214
- const require2 = createRequire(import_meta.url);
215
- const harfbuzzPkgPath = require2.resolve("harfbuzzjs/package.json");
211
+ const { createRequire } = await import("module");
212
+ const requireFn = createRequire(import_meta.url || `file://${process.cwd()}/`);
213
+ const harfbuzzPkgPath = requireFn.resolve("harfbuzzjs/package.json");
216
214
  const harfbuzzDir = path.dirname(harfbuzzPkgPath);
217
- harfbuzzWasmPath = path.join(harfbuzzDir, "hb.wasm");
215
+ candidates.push(path.join(harfbuzzDir, "hb.wasm"));
218
216
  } catch {
219
217
  }
220
- const candidates = [
221
- // First try the harfbuzzjs package location (resolved via require)
222
- ...harfbuzzWasmPath ? [harfbuzzWasmPath] : [],
223
- // Lambda environment paths
218
+ let currentDir;
219
+ try {
220
+ if (typeof import_meta.url === "string") {
221
+ const { fileURLToPath } = await import("url");
222
+ currentDir = path.dirname(fileURLToPath(import_meta.url));
223
+ }
224
+ } catch {
225
+ }
226
+ if (!currentDir) {
227
+ currentDir = process.cwd();
228
+ }
229
+ candidates.push(
230
+ path.join(currentDir, "dist/hb.wasm"),
231
+ path.join(currentDir, "assets/wasm/hb.wasm"),
232
+ path.join(currentDir, "node_modules/harfbuzzjs/hb.wasm"),
233
+ path.join(currentDir, "node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm")
234
+ );
235
+ candidates.push(
224
236
  "/var/task/node_modules/harfbuzzjs/hb.wasm",
225
- "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm",
226
- // Relative paths from current directory
227
- path.join(currentDir, "../../dist/hb.wasm"),
228
- path.join(currentDir, "../dist/hb.wasm"),
229
- path.join(currentDir, "../../assets/wasm/hb.wasm"),
230
- path.join(currentDir, "../assets/wasm/hb.wasm"),
231
- path.join(currentDir, "./hb.wasm"),
232
- path.join(currentDir, "../hb.wasm"),
233
- // node_modules relative paths
234
- path.join(currentDir, "../../node_modules/harfbuzzjs/hb.wasm"),
235
- path.join(currentDir, "../../../node_modules/harfbuzzjs/hb.wasm"),
236
- path.join(currentDir, "../../../../node_modules/harfbuzzjs/hb.wasm")
237
- ];
238
- console.log(`\u{1F50D} Searching for WASM in ${candidates.length} locations...`);
237
+ "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm"
238
+ );
239
+ console.log(`\u{1F50D} Searching for WASM in ${candidates.length} local paths...`);
239
240
  for (const candidate of candidates) {
240
241
  try {
241
242
  const buffer = await readFile2(candidate);
@@ -245,11 +246,12 @@ async function loadWasmNode(wasmBaseURL) {
245
246
  continue;
246
247
  }
247
248
  }
248
- console.log("\u{1F4C2} Local WASM not found in any location, fetching from URL...");
249
- const urlToFetch = wasmBaseURL || DEFAULT_WASM_URL;
250
- return await fetchWasmFromUrl(urlToFetch);
251
- } catch {
252
- return void 0;
249
+ console.log("\u{1F4C2} Local WASM not found, fetching from URL...");
250
+ return await fetchWasmFromUrl(DEFAULT_WASM_URL);
251
+ } catch (err) {
252
+ console.error("Error in loadWasmNode:", err);
253
+ console.log("\u26A0\uFE0F Error during local search, falling back to URL...");
254
+ return await fetchWasmFromUrl(DEFAULT_WASM_URL);
253
255
  }
254
256
  }
255
257
  async function loadWasmWeb(wasmBaseURL) {
@@ -319,7 +321,7 @@ async function initHB(wasmBaseURL) {
319
321
  try {
320
322
  let wasmBinary;
321
323
  if (isNode()) {
322
- wasmBinary = await loadWasmNode(wasmBaseURL);
324
+ wasmBinary = await loadWasmNode();
323
325
  } else {
324
326
  wasmBinary = await loadWasmWeb(wasmBaseURL);
325
327
  }
@@ -163,40 +163,41 @@ async function fetchWasmFromUrl(url) {
163
163
  return void 0;
164
164
  }
165
165
  }
166
- async function loadWasmNode(wasmBaseURL) {
166
+ async function loadWasmNode() {
167
167
  try {
168
168
  const { readFile: readFile2 } = await import("fs/promises");
169
- const { fileURLToPath } = await import("url");
170
169
  const path = await import("path");
171
- const { createRequire } = await import("module");
172
- const currentDir = path.dirname(fileURLToPath(import.meta.url));
173
- let harfbuzzWasmPath;
170
+ const candidates = [];
174
171
  try {
175
- const require2 = createRequire(import.meta.url);
176
- const harfbuzzPkgPath = require2.resolve("harfbuzzjs/package.json");
172
+ const { createRequire } = await import("module");
173
+ const requireFn = createRequire(import.meta.url || `file://${process.cwd()}/`);
174
+ const harfbuzzPkgPath = requireFn.resolve("harfbuzzjs/package.json");
177
175
  const harfbuzzDir = path.dirname(harfbuzzPkgPath);
178
- harfbuzzWasmPath = path.join(harfbuzzDir, "hb.wasm");
176
+ candidates.push(path.join(harfbuzzDir, "hb.wasm"));
179
177
  } catch {
180
178
  }
181
- const candidates = [
182
- // First try the harfbuzzjs package location (resolved via require)
183
- ...harfbuzzWasmPath ? [harfbuzzWasmPath] : [],
184
- // Lambda environment paths
179
+ let currentDir;
180
+ try {
181
+ if (typeof import.meta.url === "string") {
182
+ const { fileURLToPath } = await import("url");
183
+ currentDir = path.dirname(fileURLToPath(import.meta.url));
184
+ }
185
+ } catch {
186
+ }
187
+ if (!currentDir) {
188
+ currentDir = process.cwd();
189
+ }
190
+ candidates.push(
191
+ path.join(currentDir, "dist/hb.wasm"),
192
+ path.join(currentDir, "assets/wasm/hb.wasm"),
193
+ path.join(currentDir, "node_modules/harfbuzzjs/hb.wasm"),
194
+ path.join(currentDir, "node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm")
195
+ );
196
+ candidates.push(
185
197
  "/var/task/node_modules/harfbuzzjs/hb.wasm",
186
- "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm",
187
- // Relative paths from current directory
188
- path.join(currentDir, "../../dist/hb.wasm"),
189
- path.join(currentDir, "../dist/hb.wasm"),
190
- path.join(currentDir, "../../assets/wasm/hb.wasm"),
191
- path.join(currentDir, "../assets/wasm/hb.wasm"),
192
- path.join(currentDir, "./hb.wasm"),
193
- path.join(currentDir, "../hb.wasm"),
194
- // node_modules relative paths
195
- path.join(currentDir, "../../node_modules/harfbuzzjs/hb.wasm"),
196
- path.join(currentDir, "../../../node_modules/harfbuzzjs/hb.wasm"),
197
- path.join(currentDir, "../../../../node_modules/harfbuzzjs/hb.wasm")
198
- ];
199
- console.log(`\u{1F50D} Searching for WASM in ${candidates.length} locations...`);
198
+ "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm"
199
+ );
200
+ console.log(`\u{1F50D} Searching for WASM in ${candidates.length} local paths...`);
200
201
  for (const candidate of candidates) {
201
202
  try {
202
203
  const buffer = await readFile2(candidate);
@@ -206,11 +207,12 @@ async function loadWasmNode(wasmBaseURL) {
206
207
  continue;
207
208
  }
208
209
  }
209
- console.log("\u{1F4C2} Local WASM not found in any location, fetching from URL...");
210
- const urlToFetch = wasmBaseURL || DEFAULT_WASM_URL;
211
- return await fetchWasmFromUrl(urlToFetch);
212
- } catch {
213
- return void 0;
210
+ console.log("\u{1F4C2} Local WASM not found, fetching from URL...");
211
+ return await fetchWasmFromUrl(DEFAULT_WASM_URL);
212
+ } catch (err) {
213
+ console.error("Error in loadWasmNode:", err);
214
+ console.log("\u26A0\uFE0F Error during local search, falling back to URL...");
215
+ return await fetchWasmFromUrl(DEFAULT_WASM_URL);
214
216
  }
215
217
  }
216
218
  async function loadWasmWeb(wasmBaseURL) {
@@ -280,7 +282,7 @@ async function initHB(wasmBaseURL) {
280
282
  try {
281
283
  let wasmBinary;
282
284
  if (isNode()) {
283
- wasmBinary = await loadWasmNode(wasmBaseURL);
285
+ wasmBinary = await loadWasmNode();
284
286
  } else {
285
287
  wasmBinary = await loadWasmWeb(wasmBaseURL);
286
288
  }
package/dist/entry.web.js CHANGED
@@ -167,40 +167,41 @@ async function fetchWasmFromUrl(url) {
167
167
  return void 0;
168
168
  }
169
169
  }
170
- async function loadWasmNode(wasmBaseURL) {
170
+ async function loadWasmNode() {
171
171
  try {
172
172
  const { readFile } = await import("fs/promises");
173
- const { fileURLToPath } = await import("url");
174
173
  const path = await import("path");
175
- const { createRequire } = await import("module");
176
- const currentDir = path.dirname(fileURLToPath(import.meta.url));
177
- let harfbuzzWasmPath;
174
+ const candidates = [];
178
175
  try {
179
- const require2 = createRequire(import.meta.url);
180
- const harfbuzzPkgPath = require2.resolve("harfbuzzjs/package.json");
176
+ const { createRequire } = await import("module");
177
+ const requireFn = createRequire(import.meta.url || `file://${process.cwd()}/`);
178
+ const harfbuzzPkgPath = requireFn.resolve("harfbuzzjs/package.json");
181
179
  const harfbuzzDir = path.dirname(harfbuzzPkgPath);
182
- harfbuzzWasmPath = path.join(harfbuzzDir, "hb.wasm");
180
+ candidates.push(path.join(harfbuzzDir, "hb.wasm"));
183
181
  } catch {
184
182
  }
185
- const candidates = [
186
- // First try the harfbuzzjs package location (resolved via require)
187
- ...harfbuzzWasmPath ? [harfbuzzWasmPath] : [],
188
- // Lambda environment paths
183
+ let currentDir;
184
+ try {
185
+ if (typeof import.meta.url === "string") {
186
+ const { fileURLToPath } = await import("url");
187
+ currentDir = path.dirname(fileURLToPath(import.meta.url));
188
+ }
189
+ } catch {
190
+ }
191
+ if (!currentDir) {
192
+ currentDir = process.cwd();
193
+ }
194
+ candidates.push(
195
+ path.join(currentDir, "dist/hb.wasm"),
196
+ path.join(currentDir, "assets/wasm/hb.wasm"),
197
+ path.join(currentDir, "node_modules/harfbuzzjs/hb.wasm"),
198
+ path.join(currentDir, "node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm")
199
+ );
200
+ candidates.push(
189
201
  "/var/task/node_modules/harfbuzzjs/hb.wasm",
190
- "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm",
191
- // Relative paths from current directory
192
- path.join(currentDir, "../../dist/hb.wasm"),
193
- path.join(currentDir, "../dist/hb.wasm"),
194
- path.join(currentDir, "../../assets/wasm/hb.wasm"),
195
- path.join(currentDir, "../assets/wasm/hb.wasm"),
196
- path.join(currentDir, "./hb.wasm"),
197
- path.join(currentDir, "../hb.wasm"),
198
- // node_modules relative paths
199
- path.join(currentDir, "../../node_modules/harfbuzzjs/hb.wasm"),
200
- path.join(currentDir, "../../../node_modules/harfbuzzjs/hb.wasm"),
201
- path.join(currentDir, "../../../../node_modules/harfbuzzjs/hb.wasm")
202
- ];
203
- console.log(`\u{1F50D} Searching for WASM in ${candidates.length} locations...`);
202
+ "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm"
203
+ );
204
+ console.log(`\u{1F50D} Searching for WASM in ${candidates.length} local paths...`);
204
205
  for (const candidate of candidates) {
205
206
  try {
206
207
  const buffer = await readFile(candidate);
@@ -210,11 +211,12 @@ async function loadWasmNode(wasmBaseURL) {
210
211
  continue;
211
212
  }
212
213
  }
213
- console.log("\u{1F4C2} Local WASM not found in any location, fetching from URL...");
214
- const urlToFetch = wasmBaseURL || DEFAULT_WASM_URL;
215
- return await fetchWasmFromUrl(urlToFetch);
216
- } catch {
217
- return void 0;
214
+ console.log("\u{1F4C2} Local WASM not found, fetching from URL...");
215
+ return await fetchWasmFromUrl(DEFAULT_WASM_URL);
216
+ } catch (err) {
217
+ console.error("Error in loadWasmNode:", err);
218
+ console.log("\u26A0\uFE0F Error during local search, falling back to URL...");
219
+ return await fetchWasmFromUrl(DEFAULT_WASM_URL);
218
220
  }
219
221
  }
220
222
  async function loadWasmWeb(wasmBaseURL) {
@@ -284,7 +286,7 @@ async function initHB(wasmBaseURL) {
284
286
  try {
285
287
  let wasmBinary;
286
288
  if (isNode()) {
287
- wasmBinary = await loadWasmNode(wasmBaseURL);
289
+ wasmBinary = await loadWasmNode();
288
290
  } else {
289
291
  wasmBinary = await loadWasmWeb(wasmBaseURL);
290
292
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shotstack/shotstack-canvas",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "Text layout & animation engine (HarfBuzz) for Node & Web - fully self-contained.",
5
5
  "type": "module",
6
6
  "main": "./dist/entry.node.cjs",