@shotstack/shotstack-canvas 1.3.1 → 1.3.3

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,30 @@ 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
+ console.log(`\u{1F310} Fetching WASM from URL: ${url}`);
186
+ const response = await fetch(url);
187
+ if (response.ok) {
188
+ const arrayBuffer = await response.arrayBuffer();
189
+ const bytes = new Uint8Array(arrayBuffer);
190
+ if (bytes.length >= 4 && bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115 && bytes[3] === 109) {
191
+ console.log(`\u2705 Fetched WASM from URL (${bytes.length} bytes)`);
192
+ return arrayBuffer;
193
+ } else {
194
+ console.error(`\u274C Invalid WASM magic number from URL: ${url}`);
195
+ }
196
+ } else {
197
+ console.error(`\u274C Failed to fetch WASM from URL: ${url}, status: ${response.status}`);
198
+ }
199
+ return void 0;
200
+ } catch (err) {
201
+ console.error(`\u274C Error fetching WASM from ${url}:`, err);
202
+ return void 0;
203
+ }
204
+ }
205
+ async function loadWasmNode(wasmBaseURL) {
183
206
  try {
184
207
  const { readFile: readFile2 } = await import("fs/promises");
185
208
  const { fileURLToPath } = await import("url");
@@ -195,16 +218,24 @@ async function loadWasmNode() {
195
218
  } catch {
196
219
  }
197
220
  const candidates = [
221
+ // First try the harfbuzzjs package location (resolved via require)
198
222
  ...harfbuzzWasmPath ? [harfbuzzWasmPath] : [],
223
+ // Lambda environment paths
224
+ "/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
199
227
  path.join(currentDir, "../../dist/hb.wasm"),
200
228
  path.join(currentDir, "../dist/hb.wasm"),
201
229
  path.join(currentDir, "../../assets/wasm/hb.wasm"),
202
230
  path.join(currentDir, "../assets/wasm/hb.wasm"),
203
231
  path.join(currentDir, "./hb.wasm"),
204
232
  path.join(currentDir, "../hb.wasm"),
233
+ // node_modules relative paths
205
234
  path.join(currentDir, "../../node_modules/harfbuzzjs/hb.wasm"),
206
- 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")
207
237
  ];
238
+ console.log(`\u{1F50D} Searching for WASM in ${candidates.length} locations...`);
208
239
  for (const candidate of candidates) {
209
240
  try {
210
241
  const buffer = await readFile2(candidate);
@@ -214,7 +245,9 @@ async function loadWasmNode() {
214
245
  continue;
215
246
  }
216
247
  }
217
- return void 0;
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);
218
251
  } catch {
219
252
  return void 0;
220
253
  }
@@ -286,7 +319,7 @@ async function initHB(wasmBaseURL) {
286
319
  try {
287
320
  let wasmBinary;
288
321
  if (isNode()) {
289
- wasmBinary = await loadWasmNode();
322
+ wasmBinary = await loadWasmNode(wasmBaseURL);
290
323
  } else {
291
324
  wasmBinary = await loadWasmWeb(wasmBaseURL);
292
325
  }
@@ -140,7 +140,30 @@ 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
+ console.log(`\u{1F310} Fetching WASM from URL: ${url}`);
147
+ const response = await fetch(url);
148
+ if (response.ok) {
149
+ const arrayBuffer = await response.arrayBuffer();
150
+ const bytes = new Uint8Array(arrayBuffer);
151
+ if (bytes.length >= 4 && bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115 && bytes[3] === 109) {
152
+ console.log(`\u2705 Fetched WASM from URL (${bytes.length} bytes)`);
153
+ return arrayBuffer;
154
+ } else {
155
+ console.error(`\u274C Invalid WASM magic number from URL: ${url}`);
156
+ }
157
+ } else {
158
+ console.error(`\u274C Failed to fetch WASM from URL: ${url}, status: ${response.status}`);
159
+ }
160
+ return void 0;
161
+ } catch (err) {
162
+ console.error(`\u274C Error fetching WASM from ${url}:`, err);
163
+ return void 0;
164
+ }
165
+ }
166
+ async function loadWasmNode(wasmBaseURL) {
144
167
  try {
145
168
  const { readFile: readFile2 } = await import("fs/promises");
146
169
  const { fileURLToPath } = await import("url");
@@ -156,16 +179,24 @@ async function loadWasmNode() {
156
179
  } catch {
157
180
  }
158
181
  const candidates = [
182
+ // First try the harfbuzzjs package location (resolved via require)
159
183
  ...harfbuzzWasmPath ? [harfbuzzWasmPath] : [],
184
+ // Lambda environment paths
185
+ "/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
160
188
  path.join(currentDir, "../../dist/hb.wasm"),
161
189
  path.join(currentDir, "../dist/hb.wasm"),
162
190
  path.join(currentDir, "../../assets/wasm/hb.wasm"),
163
191
  path.join(currentDir, "../assets/wasm/hb.wasm"),
164
192
  path.join(currentDir, "./hb.wasm"),
165
193
  path.join(currentDir, "../hb.wasm"),
194
+ // node_modules relative paths
166
195
  path.join(currentDir, "../../node_modules/harfbuzzjs/hb.wasm"),
167
- 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")
168
198
  ];
199
+ console.log(`\u{1F50D} Searching for WASM in ${candidates.length} locations...`);
169
200
  for (const candidate of candidates) {
170
201
  try {
171
202
  const buffer = await readFile2(candidate);
@@ -175,7 +206,9 @@ async function loadWasmNode() {
175
206
  continue;
176
207
  }
177
208
  }
178
- return void 0;
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);
179
212
  } catch {
180
213
  return void 0;
181
214
  }
@@ -247,7 +280,7 @@ async function initHB(wasmBaseURL) {
247
280
  try {
248
281
  let wasmBinary;
249
282
  if (isNode()) {
250
- wasmBinary = await loadWasmNode();
283
+ wasmBinary = await loadWasmNode(wasmBaseURL);
251
284
  } else {
252
285
  wasmBinary = await loadWasmWeb(wasmBaseURL);
253
286
  }
package/dist/entry.web.js CHANGED
@@ -144,7 +144,30 @@ 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
+ console.log(`\u{1F310} Fetching WASM from URL: ${url}`);
151
+ const response = await fetch(url);
152
+ if (response.ok) {
153
+ const arrayBuffer = await response.arrayBuffer();
154
+ const bytes = new Uint8Array(arrayBuffer);
155
+ if (bytes.length >= 4 && bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115 && bytes[3] === 109) {
156
+ console.log(`\u2705 Fetched WASM from URL (${bytes.length} bytes)`);
157
+ return arrayBuffer;
158
+ } else {
159
+ console.error(`\u274C Invalid WASM magic number from URL: ${url}`);
160
+ }
161
+ } else {
162
+ console.error(`\u274C Failed to fetch WASM from URL: ${url}, status: ${response.status}`);
163
+ }
164
+ return void 0;
165
+ } catch (err) {
166
+ console.error(`\u274C Error fetching WASM from ${url}:`, err);
167
+ return void 0;
168
+ }
169
+ }
170
+ async function loadWasmNode(wasmBaseURL) {
148
171
  try {
149
172
  const { readFile } = await import("fs/promises");
150
173
  const { fileURLToPath } = await import("url");
@@ -160,16 +183,24 @@ async function loadWasmNode() {
160
183
  } catch {
161
184
  }
162
185
  const candidates = [
186
+ // First try the harfbuzzjs package location (resolved via require)
163
187
  ...harfbuzzWasmPath ? [harfbuzzWasmPath] : [],
188
+ // Lambda environment paths
189
+ "/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
164
192
  path.join(currentDir, "../../dist/hb.wasm"),
165
193
  path.join(currentDir, "../dist/hb.wasm"),
166
194
  path.join(currentDir, "../../assets/wasm/hb.wasm"),
167
195
  path.join(currentDir, "../assets/wasm/hb.wasm"),
168
196
  path.join(currentDir, "./hb.wasm"),
169
197
  path.join(currentDir, "../hb.wasm"),
198
+ // node_modules relative paths
170
199
  path.join(currentDir, "../../node_modules/harfbuzzjs/hb.wasm"),
171
- 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")
172
202
  ];
203
+ console.log(`\u{1F50D} Searching for WASM in ${candidates.length} locations...`);
173
204
  for (const candidate of candidates) {
174
205
  try {
175
206
  const buffer = await readFile(candidate);
@@ -179,7 +210,9 @@ async function loadWasmNode() {
179
210
  continue;
180
211
  }
181
212
  }
182
- return void 0;
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);
183
216
  } catch {
184
217
  return void 0;
185
218
  }
@@ -251,7 +284,7 @@ async function initHB(wasmBaseURL) {
251
284
  try {
252
285
  let wasmBinary;
253
286
  if (isNode()) {
254
- wasmBinary = await loadWasmNode();
287
+ wasmBinary = await loadWasmNode(wasmBaseURL);
255
288
  } else {
256
289
  wasmBinary = await loadWasmWeb(wasmBaseURL);
257
290
  }
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.3",
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",