@shotstack/shotstack-canvas 1.3.1 → 1.3.2

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.
@@ -179,7 +179,25 @@ function bufferToArrayBuffer(buffer) {
179
179
  }
180
180
  return arrayBuffer;
181
181
  }
182
- async function loadWasmNode() {
182
+ var DEFAULT_WASM_URL = "https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm";
183
+ async function fetchWasmFromUrl(url) {
184
+ try {
185
+ const response = await fetch(url);
186
+ if (response.ok) {
187
+ const arrayBuffer = await response.arrayBuffer();
188
+ const bytes = new Uint8Array(arrayBuffer);
189
+ if (bytes.length >= 4 && bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115 && bytes[3] === 109) {
190
+ console.log(`\u2705 Fetched WASM from URL (${bytes.length} bytes)`);
191
+ return arrayBuffer;
192
+ }
193
+ }
194
+ return void 0;
195
+ } catch (err) {
196
+ console.warn(`Failed to fetch WASM from ${url}:`, err);
197
+ return void 0;
198
+ }
199
+ }
200
+ async function loadWasmNode(wasmBaseURL) {
183
201
  try {
184
202
  const { readFile: readFile2 } = await import("fs/promises");
185
203
  const { fileURLToPath } = await import("url");
@@ -195,15 +213,22 @@ async function loadWasmNode() {
195
213
  } catch {
196
214
  }
197
215
  const candidates = [
216
+ // First try the harfbuzzjs package location (resolved via require)
198
217
  ...harfbuzzWasmPath ? [harfbuzzWasmPath] : [],
218
+ // Lambda environment paths
219
+ "/var/task/node_modules/harfbuzzjs/hb.wasm",
220
+ "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm",
221
+ // Relative paths from current directory
199
222
  path.join(currentDir, "../../dist/hb.wasm"),
200
223
  path.join(currentDir, "../dist/hb.wasm"),
201
224
  path.join(currentDir, "../../assets/wasm/hb.wasm"),
202
225
  path.join(currentDir, "../assets/wasm/hb.wasm"),
203
226
  path.join(currentDir, "./hb.wasm"),
204
227
  path.join(currentDir, "../hb.wasm"),
228
+ // node_modules relative paths
205
229
  path.join(currentDir, "../../node_modules/harfbuzzjs/hb.wasm"),
206
- path.join(currentDir, "../../../node_modules/harfbuzzjs/hb.wasm")
230
+ path.join(currentDir, "../../../node_modules/harfbuzzjs/hb.wasm"),
231
+ path.join(currentDir, "../../../../node_modules/harfbuzzjs/hb.wasm")
207
232
  ];
208
233
  for (const candidate of candidates) {
209
234
  try {
@@ -214,7 +239,9 @@ async function loadWasmNode() {
214
239
  continue;
215
240
  }
216
241
  }
217
- return void 0;
242
+ console.log("Local WASM not found, fetching from URL...");
243
+ const urlToFetch = wasmBaseURL || DEFAULT_WASM_URL;
244
+ return await fetchWasmFromUrl(urlToFetch);
218
245
  } catch {
219
246
  return void 0;
220
247
  }
@@ -286,7 +313,7 @@ async function initHB(wasmBaseURL) {
286
313
  try {
287
314
  let wasmBinary;
288
315
  if (isNode()) {
289
- wasmBinary = await loadWasmNode();
316
+ wasmBinary = await loadWasmNode(wasmBaseURL);
290
317
  } else {
291
318
  wasmBinary = await loadWasmWeb(wasmBaseURL);
292
319
  }
@@ -140,7 +140,25 @@ function bufferToArrayBuffer(buffer) {
140
140
  }
141
141
  return arrayBuffer;
142
142
  }
143
- async function loadWasmNode() {
143
+ var DEFAULT_WASM_URL = "https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm";
144
+ async function fetchWasmFromUrl(url) {
145
+ try {
146
+ const response = await fetch(url);
147
+ if (response.ok) {
148
+ const arrayBuffer = await response.arrayBuffer();
149
+ const bytes = new Uint8Array(arrayBuffer);
150
+ if (bytes.length >= 4 && bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115 && bytes[3] === 109) {
151
+ console.log(`\u2705 Fetched WASM from URL (${bytes.length} bytes)`);
152
+ return arrayBuffer;
153
+ }
154
+ }
155
+ return void 0;
156
+ } catch (err) {
157
+ console.warn(`Failed to fetch WASM from ${url}:`, err);
158
+ return void 0;
159
+ }
160
+ }
161
+ async function loadWasmNode(wasmBaseURL) {
144
162
  try {
145
163
  const { readFile: readFile2 } = await import("fs/promises");
146
164
  const { fileURLToPath } = await import("url");
@@ -156,15 +174,22 @@ async function loadWasmNode() {
156
174
  } catch {
157
175
  }
158
176
  const candidates = [
177
+ // First try the harfbuzzjs package location (resolved via require)
159
178
  ...harfbuzzWasmPath ? [harfbuzzWasmPath] : [],
179
+ // Lambda environment paths
180
+ "/var/task/node_modules/harfbuzzjs/hb.wasm",
181
+ "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm",
182
+ // Relative paths from current directory
160
183
  path.join(currentDir, "../../dist/hb.wasm"),
161
184
  path.join(currentDir, "../dist/hb.wasm"),
162
185
  path.join(currentDir, "../../assets/wasm/hb.wasm"),
163
186
  path.join(currentDir, "../assets/wasm/hb.wasm"),
164
187
  path.join(currentDir, "./hb.wasm"),
165
188
  path.join(currentDir, "../hb.wasm"),
189
+ // node_modules relative paths
166
190
  path.join(currentDir, "../../node_modules/harfbuzzjs/hb.wasm"),
167
- path.join(currentDir, "../../../node_modules/harfbuzzjs/hb.wasm")
191
+ path.join(currentDir, "../../../node_modules/harfbuzzjs/hb.wasm"),
192
+ path.join(currentDir, "../../../../node_modules/harfbuzzjs/hb.wasm")
168
193
  ];
169
194
  for (const candidate of candidates) {
170
195
  try {
@@ -175,7 +200,9 @@ async function loadWasmNode() {
175
200
  continue;
176
201
  }
177
202
  }
178
- return void 0;
203
+ console.log("Local WASM not found, fetching from URL...");
204
+ const urlToFetch = wasmBaseURL || DEFAULT_WASM_URL;
205
+ return await fetchWasmFromUrl(urlToFetch);
179
206
  } catch {
180
207
  return void 0;
181
208
  }
@@ -247,7 +274,7 @@ async function initHB(wasmBaseURL) {
247
274
  try {
248
275
  let wasmBinary;
249
276
  if (isNode()) {
250
- wasmBinary = await loadWasmNode();
277
+ wasmBinary = await loadWasmNode(wasmBaseURL);
251
278
  } else {
252
279
  wasmBinary = await loadWasmWeb(wasmBaseURL);
253
280
  }
package/dist/entry.web.js CHANGED
@@ -144,7 +144,25 @@ function bufferToArrayBuffer(buffer) {
144
144
  }
145
145
  return arrayBuffer;
146
146
  }
147
- async function loadWasmNode() {
147
+ var DEFAULT_WASM_URL = "https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/euo5r93oyr/zzz01k9h-yycyx-2x2y6-qx9bj-7n567b/source.wasm";
148
+ async function fetchWasmFromUrl(url) {
149
+ try {
150
+ const response = await fetch(url);
151
+ if (response.ok) {
152
+ const arrayBuffer = await response.arrayBuffer();
153
+ const bytes = new Uint8Array(arrayBuffer);
154
+ if (bytes.length >= 4 && bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115 && bytes[3] === 109) {
155
+ console.log(`\u2705 Fetched WASM from URL (${bytes.length} bytes)`);
156
+ return arrayBuffer;
157
+ }
158
+ }
159
+ return void 0;
160
+ } catch (err) {
161
+ console.warn(`Failed to fetch WASM from ${url}:`, err);
162
+ return void 0;
163
+ }
164
+ }
165
+ async function loadWasmNode(wasmBaseURL) {
148
166
  try {
149
167
  const { readFile } = await import("fs/promises");
150
168
  const { fileURLToPath } = await import("url");
@@ -160,15 +178,22 @@ async function loadWasmNode() {
160
178
  } catch {
161
179
  }
162
180
  const candidates = [
181
+ // First try the harfbuzzjs package location (resolved via require)
163
182
  ...harfbuzzWasmPath ? [harfbuzzWasmPath] : [],
183
+ // Lambda environment paths
184
+ "/var/task/node_modules/harfbuzzjs/hb.wasm",
185
+ "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm",
186
+ // Relative paths from current directory
164
187
  path.join(currentDir, "../../dist/hb.wasm"),
165
188
  path.join(currentDir, "../dist/hb.wasm"),
166
189
  path.join(currentDir, "../../assets/wasm/hb.wasm"),
167
190
  path.join(currentDir, "../assets/wasm/hb.wasm"),
168
191
  path.join(currentDir, "./hb.wasm"),
169
192
  path.join(currentDir, "../hb.wasm"),
193
+ // node_modules relative paths
170
194
  path.join(currentDir, "../../node_modules/harfbuzzjs/hb.wasm"),
171
- path.join(currentDir, "../../../node_modules/harfbuzzjs/hb.wasm")
195
+ path.join(currentDir, "../../../node_modules/harfbuzzjs/hb.wasm"),
196
+ path.join(currentDir, "../../../../node_modules/harfbuzzjs/hb.wasm")
172
197
  ];
173
198
  for (const candidate of candidates) {
174
199
  try {
@@ -179,7 +204,9 @@ async function loadWasmNode() {
179
204
  continue;
180
205
  }
181
206
  }
182
- return void 0;
207
+ console.log("Local WASM not found, fetching from URL...");
208
+ const urlToFetch = wasmBaseURL || DEFAULT_WASM_URL;
209
+ return await fetchWasmFromUrl(urlToFetch);
183
210
  } catch {
184
211
  return void 0;
185
212
  }
@@ -251,7 +278,7 @@ async function initHB(wasmBaseURL) {
251
278
  try {
252
279
  let wasmBinary;
253
280
  if (isNode()) {
254
- wasmBinary = await loadWasmNode();
281
+ wasmBinary = await loadWasmNode(wasmBaseURL);
255
282
  } else {
256
283
  wasmBinary = await loadWasmWeb(wasmBaseURL);
257
284
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shotstack/shotstack-canvas",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
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",