asciify-engine 1.0.43 → 1.0.44

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.
package/dist/index.d.cts CHANGED
@@ -233,10 +233,17 @@ interface AsciifySimpleOptions {
233
233
  options?: Partial<AsciiOptions>;
234
234
  }
235
235
  interface AsciifyLiveVideoOptions extends AsciifySimpleOptions {
236
+ /**
237
+ * When `true`, automatically sizes the canvas to the video's native pixel
238
+ * dimensions after metadata loads, before `onReady` fires.
239
+ * Eliminates manual canvas-sizing boilerplate for the common case.
240
+ * Default: `false`
241
+ */
242
+ autoSize?: boolean;
236
243
  /**
237
244
  * Called once when the video metadata is ready and playback has started.
238
- * Receive the backing video element — useful for sizing the canvas or
239
- * triggering a ready state in your UI.
245
+ * Receives the backing video element — use this to size the canvas, trigger
246
+ * a loading state change, start a timer, etc.
240
247
  */
241
248
  onReady?: (video: HTMLVideoElement) => void;
242
249
  /** Called after every rendered frame. Useful for frame counters or timers. */
@@ -288,7 +295,7 @@ declare function asciifyVideo(source: HTMLVideoElement | string, canvas: HTMLCan
288
295
  * const stop = await asciifyLiveVideo('/clip.mp4', canvas);
289
296
  * // later: stop();
290
297
  */
291
- declare function asciifyLiveVideo(source: HTMLVideoElement | string, canvas: HTMLCanvasElement, { fontSize, artStyle, options, onReady, onFrame }?: AsciifyLiveVideoOptions): Promise<() => void>;
298
+ declare function asciifyLiveVideo(source: HTMLVideoElement | string, canvas: HTMLCanvasElement, { fontSize, artStyle, options, autoSize, onReady, onFrame }?: AsciifyLiveVideoOptions): Promise<() => void>;
292
299
 
293
300
  interface WaveBackgroundOptions {
294
301
  /** Font size in CSS pixels (default: 13) */
package/dist/index.d.ts CHANGED
@@ -233,10 +233,17 @@ interface AsciifySimpleOptions {
233
233
  options?: Partial<AsciiOptions>;
234
234
  }
235
235
  interface AsciifyLiveVideoOptions extends AsciifySimpleOptions {
236
+ /**
237
+ * When `true`, automatically sizes the canvas to the video's native pixel
238
+ * dimensions after metadata loads, before `onReady` fires.
239
+ * Eliminates manual canvas-sizing boilerplate for the common case.
240
+ * Default: `false`
241
+ */
242
+ autoSize?: boolean;
236
243
  /**
237
244
  * Called once when the video metadata is ready and playback has started.
238
- * Receive the backing video element — useful for sizing the canvas or
239
- * triggering a ready state in your UI.
245
+ * Receives the backing video element — use this to size the canvas, trigger
246
+ * a loading state change, start a timer, etc.
240
247
  */
241
248
  onReady?: (video: HTMLVideoElement) => void;
242
249
  /** Called after every rendered frame. Useful for frame counters or timers. */
@@ -288,7 +295,7 @@ declare function asciifyVideo(source: HTMLVideoElement | string, canvas: HTMLCan
288
295
  * const stop = await asciifyLiveVideo('/clip.mp4', canvas);
289
296
  * // later: stop();
290
297
  */
291
- declare function asciifyLiveVideo(source: HTMLVideoElement | string, canvas: HTMLCanvasElement, { fontSize, artStyle, options, onReady, onFrame }?: AsciifyLiveVideoOptions): Promise<() => void>;
298
+ declare function asciifyLiveVideo(source: HTMLVideoElement | string, canvas: HTMLCanvasElement, { fontSize, artStyle, options, autoSize, onReady, onFrame }?: AsciifyLiveVideoOptions): Promise<() => void>;
292
299
 
293
300
  interface WaveBackgroundOptions {
294
301
  /** Font size in CSS pixels (default: 13) */
package/dist/index.js CHANGED
@@ -1075,7 +1075,7 @@ async function asciifyVideo(source, canvas, { fontSize = 10, artStyle = "classic
1075
1075
  cancelAnimationFrame(animId);
1076
1076
  };
1077
1077
  }
1078
- async function asciifyLiveVideo(source, canvas, { fontSize = 10, artStyle = "classic", options = {}, onReady, onFrame } = {}) {
1078
+ async function asciifyLiveVideo(source, canvas, { fontSize = 10, artStyle = "classic", options = {}, autoSize = false, onReady, onFrame } = {}) {
1079
1079
  let video;
1080
1080
  let ownedVideo = false;
1081
1081
  if (typeof source === "string") {
@@ -1103,13 +1103,16 @@ async function asciifyLiveVideo(source, canvas, { fontSize = 10, artStyle = "cla
1103
1103
  });
1104
1104
  await video.play().catch(() => {
1105
1105
  });
1106
- onReady?.(video);
1107
1106
  } else {
1108
1107
  video = source;
1109
1108
  if (video.paused) await video.play().catch(() => {
1110
1109
  });
1111
- onReady?.(video);
1112
1110
  }
1111
+ if (autoSize) {
1112
+ canvas.width = video.videoWidth;
1113
+ canvas.height = video.videoHeight;
1114
+ }
1115
+ onReady?.(video);
1113
1116
  const merged = { ...DEFAULT_OPTIONS, ...ART_STYLE_PRESETS[artStyle], ...options, fontSize };
1114
1117
  const ctx = canvas.getContext("2d");
1115
1118
  if (!ctx) throw new Error("asciifyLiveVideo: could not get 2d context from canvas.");