@shotstack/shotstack-canvas 1.3.4 → 1.3.6

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.
@@ -205,32 +205,37 @@ async function fetchWasmFromUrl(url) {
205
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
222
- ...harfbuzzWasmPath ? [harfbuzzWasmPath] : [],
223
- // Then try relative paths from current directory
224
- path.join(currentDir, "../../dist/hb.wasm"),
225
- path.join(currentDir, "../dist/hb.wasm"),
226
- path.join(currentDir, "../../assets/wasm/hb.wasm"),
227
- path.join(currentDir, "../assets/wasm/hb.wasm"),
228
- path.join(currentDir, "./hb.wasm"),
229
- path.join(currentDir, "../hb.wasm"),
230
- // Also try node_modules paths relative to current dir
231
- path.join(currentDir, "../../node_modules/harfbuzzjs/hb.wasm"),
232
- path.join(currentDir, "../../../node_modules/harfbuzzjs/hb.wasm")
233
- ];
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(
236
+ "/var/task/node_modules/harfbuzzjs/hb.wasm",
237
+ "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm"
238
+ );
234
239
  console.log(`\u{1F50D} Searching for WASM in ${candidates.length} local paths...`);
235
240
  for (const candidate of candidates) {
236
241
  try {
@@ -245,7 +250,8 @@ async function loadWasmNode() {
245
250
  return await fetchWasmFromUrl(DEFAULT_WASM_URL);
246
251
  } catch (err) {
247
252
  console.error("Error in loadWasmNode:", err);
248
- return void 0;
253
+ console.log("\u26A0\uFE0F Error during local search, falling back to URL...");
254
+ return await fetchWasmFromUrl(DEFAULT_WASM_URL);
249
255
  }
250
256
  }
251
257
  async function loadWasmWeb(wasmBaseURL) {
@@ -1934,7 +1940,7 @@ var VideoGenerator = class {
1934
1940
  ffmpeg.on("close", (code) => {
1935
1941
  if (code === 0) {
1936
1942
  console.log("\u2705 Video generation complete!");
1937
- resolve();
1943
+ resolve(finalOutputPath);
1938
1944
  } else {
1939
1945
  console.error("FFmpeg stderr:", ffmpegError);
1940
1946
  reject(new Error(`FFmpeg exited with code ${code}`));
@@ -2183,7 +2189,8 @@ async function createTextEngine(opts = {}) {
2183
2189
  const frameGenerator = async (time) => {
2184
2190
  return this.renderFrame(asset, time);
2185
2191
  };
2186
- await videoGenerator.generateVideo(frameGenerator, finalOptions);
2192
+ const actualOutputPath = await videoGenerator.generateVideo(frameGenerator, finalOptions);
2193
+ return actualOutputPath;
2187
2194
  } catch (err) {
2188
2195
  throw new Error(
2189
2196
  `Failed to generate video: ${err instanceof Error ? err.message : String(err)}`
@@ -243,7 +243,7 @@ declare function createTextEngine(opts?: {
243
243
  render(ops: DrawOp[]): Promise<void>;
244
244
  toPNG(): Promise<Buffer>;
245
245
  }>;
246
- generateVideo(asset: RichTextValidated, options: Partial<VideoGenerationOptions>): Promise<void>;
246
+ generateVideo(asset: RichTextValidated, options: Partial<VideoGenerationOptions>): Promise<string>;
247
247
  destroy(): void;
248
248
  }>;
249
249
 
@@ -243,7 +243,7 @@ declare function createTextEngine(opts?: {
243
243
  render(ops: DrawOp[]): Promise<void>;
244
244
  toPNG(): Promise<Buffer>;
245
245
  }>;
246
- generateVideo(asset: RichTextValidated, options: Partial<VideoGenerationOptions>): Promise<void>;
246
+ generateVideo(asset: RichTextValidated, options: Partial<VideoGenerationOptions>): Promise<string>;
247
247
  destroy(): void;
248
248
  }>;
249
249
 
@@ -166,32 +166,37 @@ async function fetchWasmFromUrl(url) {
166
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
183
- ...harfbuzzWasmPath ? [harfbuzzWasmPath] : [],
184
- // Then try relative paths from current directory
185
- path.join(currentDir, "../../dist/hb.wasm"),
186
- path.join(currentDir, "../dist/hb.wasm"),
187
- path.join(currentDir, "../../assets/wasm/hb.wasm"),
188
- path.join(currentDir, "../assets/wasm/hb.wasm"),
189
- path.join(currentDir, "./hb.wasm"),
190
- path.join(currentDir, "../hb.wasm"),
191
- // Also try node_modules paths relative to current dir
192
- path.join(currentDir, "../../node_modules/harfbuzzjs/hb.wasm"),
193
- path.join(currentDir, "../../../node_modules/harfbuzzjs/hb.wasm")
194
- ];
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(
197
+ "/var/task/node_modules/harfbuzzjs/hb.wasm",
198
+ "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm"
199
+ );
195
200
  console.log(`\u{1F50D} Searching for WASM in ${candidates.length} local paths...`);
196
201
  for (const candidate of candidates) {
197
202
  try {
@@ -206,7 +211,8 @@ async function loadWasmNode() {
206
211
  return await fetchWasmFromUrl(DEFAULT_WASM_URL);
207
212
  } catch (err) {
208
213
  console.error("Error in loadWasmNode:", err);
209
- return void 0;
214
+ console.log("\u26A0\uFE0F Error during local search, falling back to URL...");
215
+ return await fetchWasmFromUrl(DEFAULT_WASM_URL);
210
216
  }
211
217
  }
212
218
  async function loadWasmWeb(wasmBaseURL) {
@@ -1895,7 +1901,7 @@ var VideoGenerator = class {
1895
1901
  ffmpeg.on("close", (code) => {
1896
1902
  if (code === 0) {
1897
1903
  console.log("\u2705 Video generation complete!");
1898
- resolve();
1904
+ resolve(finalOutputPath);
1899
1905
  } else {
1900
1906
  console.error("FFmpeg stderr:", ffmpegError);
1901
1907
  reject(new Error(`FFmpeg exited with code ${code}`));
@@ -2144,7 +2150,8 @@ async function createTextEngine(opts = {}) {
2144
2150
  const frameGenerator = async (time) => {
2145
2151
  return this.renderFrame(asset, time);
2146
2152
  };
2147
- await videoGenerator.generateVideo(frameGenerator, finalOptions);
2153
+ const actualOutputPath = await videoGenerator.generateVideo(frameGenerator, finalOptions);
2154
+ return actualOutputPath;
2148
2155
  } catch (err) {
2149
2156
  throw new Error(
2150
2157
  `Failed to generate video: ${err instanceof Error ? err.message : String(err)}`
package/dist/entry.web.js CHANGED
@@ -170,32 +170,37 @@ async function fetchWasmFromUrl(url) {
170
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
187
- ...harfbuzzWasmPath ? [harfbuzzWasmPath] : [],
188
- // Then try relative paths from current directory
189
- path.join(currentDir, "../../dist/hb.wasm"),
190
- path.join(currentDir, "../dist/hb.wasm"),
191
- path.join(currentDir, "../../assets/wasm/hb.wasm"),
192
- path.join(currentDir, "../assets/wasm/hb.wasm"),
193
- path.join(currentDir, "./hb.wasm"),
194
- path.join(currentDir, "../hb.wasm"),
195
- // Also try node_modules paths relative to current dir
196
- path.join(currentDir, "../../node_modules/harfbuzzjs/hb.wasm"),
197
- path.join(currentDir, "../../../node_modules/harfbuzzjs/hb.wasm")
198
- ];
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(
201
+ "/var/task/node_modules/harfbuzzjs/hb.wasm",
202
+ "/var/task/node_modules/@shotstack/shotstack-canvas/assets/wasm/hb.wasm"
203
+ );
199
204
  console.log(`\u{1F50D} Searching for WASM in ${candidates.length} local paths...`);
200
205
  for (const candidate of candidates) {
201
206
  try {
@@ -210,7 +215,8 @@ async function loadWasmNode() {
210
215
  return await fetchWasmFromUrl(DEFAULT_WASM_URL);
211
216
  } catch (err) {
212
217
  console.error("Error in loadWasmNode:", err);
213
- return void 0;
218
+ console.log("\u26A0\uFE0F Error during local search, falling back to URL...");
219
+ return await fetchWasmFromUrl(DEFAULT_WASM_URL);
214
220
  }
215
221
  }
216
222
  async function loadWasmWeb(wasmBaseURL) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shotstack/shotstack-canvas",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
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",