@yassine-bouassida/scenecap 1.0.1 → 1.1.0

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.mts CHANGED
@@ -54,6 +54,13 @@ interface RecordingOptions {
54
54
  backgroundColor: string;
55
55
  /** Device pixel ratio (for retina) */
56
56
  devicePixelRatio: number;
57
+ /**
58
+ * How to capture the DOM:
59
+ * - 'auto' Try display capture first, fall back to canvas (default)
60
+ * - 'display' getDisplayMedia — captures iframes, handles tab switching, best fidelity
61
+ * - 'canvas' Canvas + SVG foreignObject — no permissions needed, limited fidelity
62
+ */
63
+ captureMethod?: 'auto' | 'display' | 'canvas';
57
64
  }
58
65
  interface RecordingSession {
59
66
  /** Unique session ID */
@@ -165,32 +172,61 @@ declare class ScenarioRunner {
165
172
  private cleanup;
166
173
  }
167
174
 
168
- /**
169
- * Records a DOM element to a video file using the Canvas capture API.
170
- * This captures the visual output of a container element frame-by-frame.
171
- */
172
175
  declare class VideoRecorder {
173
176
  private options;
174
177
  private mediaRecorder;
175
178
  private chunks;
176
- private canvas;
177
179
  private stream;
178
180
  private captureInterval;
181
+ private displayStream;
182
+ private displayVideo;
183
+ private videoEncoder;
184
+ private mp4Output;
185
+ private mp4Target;
186
+ private pendingEncodes;
187
+ private frameCount;
188
+ private frameIntervalUs;
189
+ private usingVideoEncoder;
179
190
  constructor(options?: Partial<RecordingOptions>);
180
191
  /**
181
- * Start recording from a canvas element.
192
+ * Start recording a DOM element.
193
+ *
194
+ * Strategy selection (captureMethod):
195
+ * 'auto' → try display capture, fall back to canvas
196
+ * 'display' → getDisplayMedia (best fidelity, iframes, tab-switch-safe)
197
+ * 'canvas' → SVG foreignObject canvas rendering (no permissions)
182
198
  */
183
- startFromCanvas(canvas: HTMLCanvasElement): Promise<void>;
199
+ startFromElement(element: HTMLElement): Promise<void>;
184
200
  /**
185
- * Start recording a DOM element by continuously painting it to a canvas.
201
+ * Start recording directly from an existing canvas element.
186
202
  */
187
- startFromElement(element: HTMLElement): Promise<void>;
203
+ startFromCanvas(canvas: HTMLCanvasElement): Promise<void>;
188
204
  /**
189
205
  * Stop recording and return the video blob.
190
206
  */
191
207
  stop(): Promise<Blob>;
192
- private cleanup;
193
208
  get isRecording(): boolean;
209
+ /**
210
+ * Capture via getDisplayMedia — crops the live tab stream to the element.
211
+ * Works across iframe boundaries and survives tab switches.
212
+ */
213
+ private startWithDisplayCapture;
214
+ /**
215
+ * Capture via SVG foreignObject → canvas — no permissions needed.
216
+ * Limited: cross-origin resources, iframes, and some CSS effects won't render.
217
+ */
218
+ private startWithCanvasCapture;
219
+ /**
220
+ * Wire up either VideoEncoder + Mediabunny (Chrome MP4)
221
+ * or MediaRecorder (WebM / native Safari MP4).
222
+ */
223
+ private initRecorder;
224
+ /**
225
+ * Encode the current canvas frame into VideoEncoder (MP4 path only).
226
+ * No-op when using MediaRecorder.
227
+ */
228
+ private encodeFrameIfNeeded;
229
+ private cleanup;
194
230
  }
195
231
 
196
232
  /**
package/dist/index.d.ts CHANGED
@@ -54,6 +54,13 @@ interface RecordingOptions {
54
54
  backgroundColor: string;
55
55
  /** Device pixel ratio (for retina) */
56
56
  devicePixelRatio: number;
57
+ /**
58
+ * How to capture the DOM:
59
+ * - 'auto' Try display capture first, fall back to canvas (default)
60
+ * - 'display' getDisplayMedia — captures iframes, handles tab switching, best fidelity
61
+ * - 'canvas' Canvas + SVG foreignObject — no permissions needed, limited fidelity
62
+ */
63
+ captureMethod?: 'auto' | 'display' | 'canvas';
57
64
  }
58
65
  interface RecordingSession {
59
66
  /** Unique session ID */
@@ -165,32 +172,61 @@ declare class ScenarioRunner {
165
172
  private cleanup;
166
173
  }
167
174
 
168
- /**
169
- * Records a DOM element to a video file using the Canvas capture API.
170
- * This captures the visual output of a container element frame-by-frame.
171
- */
172
175
  declare class VideoRecorder {
173
176
  private options;
174
177
  private mediaRecorder;
175
178
  private chunks;
176
- private canvas;
177
179
  private stream;
178
180
  private captureInterval;
181
+ private displayStream;
182
+ private displayVideo;
183
+ private videoEncoder;
184
+ private mp4Output;
185
+ private mp4Target;
186
+ private pendingEncodes;
187
+ private frameCount;
188
+ private frameIntervalUs;
189
+ private usingVideoEncoder;
179
190
  constructor(options?: Partial<RecordingOptions>);
180
191
  /**
181
- * Start recording from a canvas element.
192
+ * Start recording a DOM element.
193
+ *
194
+ * Strategy selection (captureMethod):
195
+ * 'auto' → try display capture, fall back to canvas
196
+ * 'display' → getDisplayMedia (best fidelity, iframes, tab-switch-safe)
197
+ * 'canvas' → SVG foreignObject canvas rendering (no permissions)
182
198
  */
183
- startFromCanvas(canvas: HTMLCanvasElement): Promise<void>;
199
+ startFromElement(element: HTMLElement): Promise<void>;
184
200
  /**
185
- * Start recording a DOM element by continuously painting it to a canvas.
201
+ * Start recording directly from an existing canvas element.
186
202
  */
187
- startFromElement(element: HTMLElement): Promise<void>;
203
+ startFromCanvas(canvas: HTMLCanvasElement): Promise<void>;
188
204
  /**
189
205
  * Stop recording and return the video blob.
190
206
  */
191
207
  stop(): Promise<Blob>;
192
- private cleanup;
193
208
  get isRecording(): boolean;
209
+ /**
210
+ * Capture via getDisplayMedia — crops the live tab stream to the element.
211
+ * Works across iframe boundaries and survives tab switches.
212
+ */
213
+ private startWithDisplayCapture;
214
+ /**
215
+ * Capture via SVG foreignObject → canvas — no permissions needed.
216
+ * Limited: cross-origin resources, iframes, and some CSS effects won't render.
217
+ */
218
+ private startWithCanvasCapture;
219
+ /**
220
+ * Wire up either VideoEncoder + Mediabunny (Chrome MP4)
221
+ * or MediaRecorder (WebM / native Safari MP4).
222
+ */
223
+ private initRecorder;
224
+ /**
225
+ * Encode the current canvas frame into VideoEncoder (MP4 path only).
226
+ * No-op when using MediaRecorder.
227
+ */
228
+ private encodeFrameIfNeeded;
229
+ private cleanup;
194
230
  }
195
231
 
196
232
  /**