@bendyline/squisq-video-react 1.0.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.
@@ -0,0 +1,263 @@
1
+ /**
2
+ * useFrameCapture — Hidden div + html2canvas frame capture.
3
+ *
4
+ * Mounts a DocPlayer in renderMode inside a hidden div (same document),
5
+ * then captures individual frames by seeking the player and rendering
6
+ * the DOM to a canvas via html2canvas.
7
+ *
8
+ * Uses React directly — no script injection, no iframes, no eval.
9
+ *
10
+ * Returns an ImageBitmap for each frame (transferable to a Worker).
11
+ */
12
+
13
+ import { createElement } from 'react';
14
+ import { createRoot, type Root } from 'react-dom/client';
15
+ import { useRef, useCallback, useMemo } from 'react';
16
+ import type { Doc, MediaProvider } from '@bendyline/squisq/schemas';
17
+ import type { RenderHtmlOptions } from '@bendyline/squisq-video';
18
+ import { DocPlayer, MediaContext } from '@bendyline/squisq-react';
19
+ import type { SquisqWindow, CaptionMode, CaptionStyle } from '@bendyline/squisq-react';
20
+ import html2canvas from 'html2canvas';
21
+
22
+ export interface FrameCaptureHandle {
23
+ /** Initialize the hidden player. Returns the video duration in seconds. */
24
+ init: (
25
+ doc: Doc,
26
+ renderOptions: Omit<RenderHtmlOptions, 'playerScript'>,
27
+ captionMode?: CaptionMode,
28
+ ) => Promise<number>;
29
+ /** Capture a single frame at the given time (seconds). Returns an ImageBitmap. */
30
+ captureFrame: (time: number) => Promise<ImageBitmap>;
31
+ /** Clean up resources. */
32
+ destroy: () => void;
33
+ }
34
+
35
+ /** Extension → MIME type map (hoisted to avoid per-image allocation). */
36
+ const MIME_MAP: Record<string, string> = {
37
+ jpg: 'image/jpeg',
38
+ jpeg: 'image/jpeg',
39
+ png: 'image/png',
40
+ gif: 'image/gif',
41
+ webp: 'image/webp',
42
+ svg: 'image/svg+xml',
43
+ bmp: 'image/bmp',
44
+ avif: 'image/avif',
45
+ };
46
+
47
+ /** Convert an ArrayBuffer to a base64 data URI using chunked encoding (O(n)). */
48
+ function arrayBufferToDataUrl(buffer: ArrayBuffer, mime: string): string {
49
+ const bytes = new Uint8Array(buffer);
50
+ const chunks: string[] = [];
51
+ const CHUNK = 8192;
52
+ for (let i = 0; i < bytes.length; i += CHUNK) {
53
+ chunks.push(String.fromCharCode(...bytes.subarray(i, i + CHUNK)));
54
+ }
55
+ return `data:${mime};base64,${btoa(chunks.join(''))}`;
56
+ }
57
+
58
+ /**
59
+ * Create an inline MediaProvider from a map of paths to ArrayBuffers.
60
+ */
61
+ function createInlineProvider(images: Map<string, ArrayBuffer>): MediaProvider {
62
+ const dataUrls = new Map<string, string>();
63
+ const mimeTypes = new Map<string, string>();
64
+ for (const [path, buffer] of images) {
65
+ const ext = path.split('.').pop()?.toLowerCase() ?? '';
66
+ const mime = MIME_MAP[ext] ?? 'application/octet-stream';
67
+ dataUrls.set(path, arrayBufferToDataUrl(buffer, mime));
68
+ mimeTypes.set(path, mime);
69
+ }
70
+
71
+ return {
72
+ async resolveUrl(relativePath: string): Promise<string> {
73
+ return dataUrls.get(relativePath) ?? relativePath;
74
+ },
75
+ async listMedia() {
76
+ return [...dataUrls.keys()].map((name) => ({
77
+ name,
78
+ mimeType: mimeTypes.get(name) ?? 'application/octet-stream',
79
+ size: 0,
80
+ }));
81
+ },
82
+ async addMedia() {
83
+ throw new Error('Read-only');
84
+ },
85
+ async removeMedia() {
86
+ throw new Error('Read-only');
87
+ },
88
+ dispose() {},
89
+ };
90
+ }
91
+
92
+ /**
93
+ * Hook that manages a hidden div for frame capture.
94
+ */
95
+ export function useFrameCapture(): FrameCaptureHandle {
96
+ const containerRef = useRef<HTMLDivElement | null>(null);
97
+ const rootRef = useRef<Root | null>(null);
98
+ const dimensionsRef = useRef<{ width: number; height: number }>({ width: 1920, height: 1080 });
99
+
100
+ const init = useCallback(
101
+ async (
102
+ doc: Doc,
103
+ renderOptions: Omit<RenderHtmlOptions, 'playerScript'>,
104
+ captionMode?: CaptionMode,
105
+ ): Promise<number> => {
106
+ // Clean up any existing container.
107
+ // Defer unmount to avoid "synchronously unmount a root while React
108
+ // was already rendering" when init() is called from a React handler.
109
+ if (rootRef.current || containerRef.current) {
110
+ const oldRoot = rootRef.current;
111
+ const oldContainer = containerRef.current;
112
+ rootRef.current = null;
113
+ containerRef.current = null;
114
+ await new Promise<void>((resolve) => {
115
+ setTimeout(() => {
116
+ if (oldRoot) oldRoot.unmount();
117
+ if (oldContainer) oldContainer.remove();
118
+ resolve();
119
+ }, 0);
120
+ });
121
+ }
122
+
123
+ const width = renderOptions.width ?? 1920;
124
+ const height = renderOptions.height ?? 1080;
125
+ dimensionsRef.current = { width, height };
126
+
127
+ // Create a hidden container
128
+ const container = document.createElement('div');
129
+ container.style.cssText =
130
+ `position:fixed;left:0;top:0;width:${width}px;height:${height}px;` +
131
+ 'opacity:0;pointer-events:none;z-index:-1;overflow:hidden;';
132
+ document.body.appendChild(container);
133
+ containerRef.current = container;
134
+
135
+ // Create render root
136
+ const renderRoot = document.createElement('div');
137
+ renderRoot.id = 'squisq-capture-root';
138
+ renderRoot.style.cssText = `width:${width}px;height:${height}px;`;
139
+ container.appendChild(renderRoot);
140
+
141
+ // Build media provider from images
142
+ const mediaProvider = renderOptions.images
143
+ ? createInlineProvider(renderOptions.images)
144
+ : null;
145
+
146
+ // Mount DocPlayer in renderMode via React
147
+ const root = createRoot(renderRoot);
148
+ rootRef.current = root;
149
+
150
+ // Derive caption props from captionMode
151
+ const captionsEnabled = captionMode !== undefined && captionMode !== 'off';
152
+ const captionStyle: CaptionStyle = captionMode === 'social' ? 'social' : 'standard';
153
+
154
+ const playerElement = createElement(DocPlayer, {
155
+ script: doc,
156
+ basePath: '.',
157
+ renderMode: true,
158
+ showControls: false,
159
+ autoPlay: false,
160
+ forceViewport: { width, height, name: 'export' },
161
+ captionsEnabled,
162
+ captionStyle,
163
+ });
164
+
165
+ // Defer rendering to the next microtask to avoid "synchronously unmount
166
+ // a root while React was already rendering" when init() is called during
167
+ // a React render cycle (e.g., from startExport in VideoExportModal).
168
+ await new Promise<void>((resolve) => setTimeout(resolve, 0));
169
+
170
+ if (mediaProvider) {
171
+ root.render(createElement(MediaContext.Provider, { value: mediaProvider }, playerElement));
172
+ } else {
173
+ root.render(playerElement);
174
+ }
175
+
176
+ // Wait for the render API to appear on window
177
+ return new Promise<number>((resolve, reject) => {
178
+ const timeout = setTimeout(() => {
179
+ const w = window as SquisqWindow;
180
+ const hasSeek = typeof w.seekTo === 'function';
181
+ const hasDur = typeof w.getDuration === 'function';
182
+ const rootEl = containerRef.current?.querySelector('#squisq-capture-root');
183
+ const hasPlayer = rootEl ? rootEl.querySelector('.doc-player') !== null : false;
184
+ reject(
185
+ new Error(
186
+ `Render API did not initialize within 15s. ` +
187
+ `seekTo=${hasSeek}, getDuration=${hasDur}, player=${hasPlayer}, root=${!!rootEl}`,
188
+ ),
189
+ );
190
+ }, 15000);
191
+
192
+ const checkApi = () => {
193
+ const w = window as SquisqWindow;
194
+ if (typeof w.getDuration === 'function' && typeof w.seekTo === 'function') {
195
+ clearTimeout(timeout);
196
+ const duration = w.getDuration();
197
+ resolve(duration);
198
+ } else {
199
+ requestAnimationFrame(checkApi);
200
+ }
201
+ };
202
+
203
+ // Give React time to mount and run useEffects
204
+ setTimeout(checkApi, 500);
205
+ });
206
+ },
207
+ [],
208
+ );
209
+
210
+ const captureFrame = useCallback(async (time: number): Promise<ImageBitmap> => {
211
+ const container = containerRef.current;
212
+ const w = window as SquisqWindow;
213
+ if (!container || typeof w.seekTo !== 'function') {
214
+ throw new Error('Frame capture not initialized — call init() first');
215
+ }
216
+
217
+ const { width, height } = dimensionsRef.current;
218
+
219
+ // Seek the player to the target time
220
+ await w.seekTo(time);
221
+
222
+ // Wait for the DOM to update after seek
223
+ await new Promise<void>((resolve) =>
224
+ requestAnimationFrame(() => requestAnimationFrame(() => resolve())),
225
+ );
226
+
227
+ const root = container.querySelector('#squisq-capture-root') as HTMLElement;
228
+ if (!root) {
229
+ throw new Error('Capture root element not found');
230
+ }
231
+
232
+ // Render the DOM to a canvas via html2canvas.
233
+ // We're in the same document (no iframe), so COEP doesn't block cloning.
234
+ const canvas = await html2canvas(root, {
235
+ width,
236
+ height,
237
+ scale: 1,
238
+ useCORS: true,
239
+ allowTaint: true,
240
+ backgroundColor: '#000000',
241
+ logging: false,
242
+ });
243
+
244
+ // Convert to ImageBitmap (transferable to worker — zero-copy)
245
+ const bitmap = await createImageBitmap(canvas);
246
+ return bitmap;
247
+ }, []);
248
+
249
+ const destroy = useCallback(() => {
250
+ if (rootRef.current) {
251
+ rootRef.current.unmount();
252
+ rootRef.current = null;
253
+ }
254
+ if (containerRef.current) {
255
+ containerRef.current.remove();
256
+ containerRef.current = null;
257
+ }
258
+ }, []);
259
+
260
+ // Return a stable object to prevent useEffect cleanup loops
261
+ // in consumers that depend on the handle reference.
262
+ return useMemo(() => ({ init, captureFrame, destroy }), [init, captureFrame, destroy]);
263
+ }
@@ -0,0 +1,343 @@
1
+ /**
2
+ * useVideoExport — Main orchestration hook for browser video export.
3
+ *
4
+ * Coordinates frame capture (hidden iframe + html2canvas) with
5
+ * main-thread WebCodecs encoding via mp4-muxer. Manages the full
6
+ * lifecycle: prepare → capture + encode → download.
7
+ *
8
+ * Encoding runs on the main thread because frame capture via html2canvas
9
+ * (~100-200ms per frame) is the bottleneck, not encoding (~1ms per frame
10
+ * with hardware-accelerated WebCodecs). Worker offloading would add
11
+ * complexity with minimal benefit.
12
+ *
13
+ * Usage:
14
+ * const { state, progress, phase, startExport, cancel, downloadUrl } = useVideoExport();
15
+ * <button onClick={() => startExport(doc, options)}>Export</button>
16
+ */
17
+
18
+ import { useState, useRef, useCallback, useEffect } from 'react';
19
+ import type { Doc } from '@bendyline/squisq/schemas';
20
+ import type { MediaProvider } from '@bendyline/squisq/schemas';
21
+ import type { VideoQuality, VideoOrientation } from '@bendyline/squisq-video';
22
+ import { resolveDimensions } from '@bendyline/squisq-video';
23
+ import type { CaptionMode } from '@bendyline/squisq-react';
24
+ import { createEncoder, supportsWebCodecs, type MainThreadEncoder } from '../mainThreadEncoder.js';
25
+ import { useFrameCapture } from './useFrameCapture.js';
26
+
27
+ // ── Types ──────────────────────────────────────────────────────────
28
+
29
+ export type VideoExportState =
30
+ | 'idle'
31
+ | 'preparing'
32
+ | 'capturing'
33
+ | 'encoding'
34
+ | 'complete'
35
+ | 'error';
36
+
37
+ export interface VideoExportConfig {
38
+ /** Encoding quality preset (default: 'normal') */
39
+ quality?: VideoQuality;
40
+ /** Frames per second (default: 30) */
41
+ fps?: number;
42
+ /** Viewport orientation (default: 'landscape') */
43
+ orientation?: VideoOrientation;
44
+ /**
45
+ * Map of relative image paths to binary data.
46
+ * Used to embed images into the render HTML.
47
+ */
48
+ images?: Map<string, ArrayBuffer>;
49
+ /**
50
+ * Map of audio segment names to binary data.
51
+ * Used to embed audio into the render HTML.
52
+ */
53
+ audio?: Map<string, ArrayBuffer>;
54
+ /** MediaProvider to resolve media URLs (alternative to passing images directly) */
55
+ mediaProvider?: MediaProvider;
56
+ /** Caption mode for the exported video (default: 'off') */
57
+ captionMode?: CaptionMode;
58
+ /** Player IIFE bundle (unused in browser export, kept for CLI/Playwright path) */
59
+ playerScript?: string;
60
+ }
61
+
62
+ export interface VideoExportResult {
63
+ /** Current export state */
64
+ state: VideoExportState;
65
+ /** 0–100 progress percentage */
66
+ progress: number;
67
+ /** Human-readable description of the current phase */
68
+ phase: string;
69
+ /** Video duration detected from the doc (seconds) */
70
+ duration: number;
71
+ /** Encoder backend ('webcodecs' when active, null when idle) */
72
+ backend: 'webcodecs' | null;
73
+ /** Blob download URL (populated when state === 'complete') */
74
+ downloadUrl: string | null;
75
+ /** File size in bytes (populated when state === 'complete') */
76
+ fileSize: number;
77
+ /** Error message (populated when state === 'error') */
78
+ error: string | null;
79
+ /** Seconds elapsed since export started */
80
+ elapsed: number;
81
+ /** Estimated seconds remaining (0 when idle or complete) */
82
+ estimatedRemaining: number;
83
+ /** Start a new export */
84
+ startExport: (doc: Doc, config: VideoExportConfig) => Promise<void>;
85
+ /** Cancel an in-progress export */
86
+ cancel: () => void;
87
+ /** Reset state back to idle (e.g., after complete or error) */
88
+ reset: () => void;
89
+ }
90
+
91
+ // ── Hook ───────────────────────────────────────────────────────────
92
+
93
+ export function useVideoExport(): VideoExportResult {
94
+ const [state, setState] = useState<VideoExportState>('idle');
95
+ const [progress, setProgress] = useState(0);
96
+ const [phase, setPhase] = useState('');
97
+ const [duration, setDuration] = useState(0);
98
+ const [backend, setBackend] = useState<'webcodecs' | null>(null);
99
+ const [downloadUrl, setDownloadUrl] = useState<string | null>(null);
100
+ const [fileSize, setFileSize] = useState(0);
101
+ const [error, setError] = useState<string | null>(null);
102
+
103
+ const [elapsed, setElapsed] = useState(0);
104
+ const [estimatedRemaining, setEstimatedRemaining] = useState(0);
105
+
106
+ const encoderRef = useRef<MainThreadEncoder | null>(null);
107
+ const cancelledRef = useRef(false);
108
+ const downloadUrlRef = useRef<string | null>(null);
109
+ const startTimeRef = useRef<number>(0);
110
+ const elapsedTimerRef = useRef<ReturnType<typeof setInterval> | null>(null);
111
+
112
+ const frameCapture = useFrameCapture();
113
+
114
+ // Clean up on unmount
115
+ useEffect(() => {
116
+ return () => {
117
+ if (elapsedTimerRef.current) clearInterval(elapsedTimerRef.current);
118
+ if (downloadUrlRef.current) {
119
+ URL.revokeObjectURL(downloadUrlRef.current);
120
+ }
121
+ if (encoderRef.current) {
122
+ encoderRef.current.close();
123
+ }
124
+ frameCapture.destroy();
125
+ };
126
+ }, [frameCapture]);
127
+
128
+ const reset = useCallback(() => {
129
+ if (downloadUrlRef.current) {
130
+ URL.revokeObjectURL(downloadUrlRef.current);
131
+ downloadUrlRef.current = null;
132
+ }
133
+ if (encoderRef.current) {
134
+ encoderRef.current.close();
135
+ encoderRef.current = null;
136
+ }
137
+ frameCapture.destroy();
138
+ setState('idle');
139
+ setProgress(0);
140
+ setPhase('');
141
+ setDuration(0);
142
+ setBackend(null);
143
+ setDownloadUrl(null);
144
+ setFileSize(0);
145
+ setError(null);
146
+ setElapsed(0);
147
+ setEstimatedRemaining(0);
148
+ if (elapsedTimerRef.current) clearInterval(elapsedTimerRef.current);
149
+ cancelledRef.current = false;
150
+ }, [frameCapture]);
151
+
152
+ const cancel = useCallback(() => {
153
+ cancelledRef.current = true;
154
+ if (elapsedTimerRef.current) clearInterval(elapsedTimerRef.current);
155
+ if (encoderRef.current) {
156
+ encoderRef.current.close();
157
+ encoderRef.current = null;
158
+ }
159
+ frameCapture.destroy();
160
+ setState('idle');
161
+ setProgress(0);
162
+ setPhase('Cancelled');
163
+ }, [frameCapture]);
164
+
165
+ const startExport = useCallback(
166
+ async (doc: Doc, config: VideoExportConfig) => {
167
+ // Clear previous state
168
+ cancelledRef.current = false;
169
+ if (downloadUrlRef.current) {
170
+ URL.revokeObjectURL(downloadUrlRef.current);
171
+ downloadUrlRef.current = null;
172
+ }
173
+ setDownloadUrl(null);
174
+ setFileSize(0);
175
+ setError(null);
176
+
177
+ const quality = config.quality ?? 'normal';
178
+ const fps = config.fps ?? 30;
179
+ const orientation = config.orientation ?? 'landscape';
180
+ const { width, height } = resolveDimensions({ orientation });
181
+
182
+ try {
183
+ // ── Check browser support ─────────────────────────────────
184
+ if (!supportsWebCodecs()) {
185
+ throw new Error(
186
+ 'WebCodecs is not available in this browser. ' +
187
+ 'Video export requires Chrome 94+, Edge 94+, or another Chromium-based browser.',
188
+ );
189
+ }
190
+
191
+ // ── Step 1: Prepare ───────────────────────────────────────
192
+ setState('preparing');
193
+ setPhase('Loading document…');
194
+ setProgress(0);
195
+ setElapsed(0);
196
+ setEstimatedRemaining(0);
197
+
198
+ // Start elapsed timer
199
+ startTimeRef.current = performance.now();
200
+ if (elapsedTimerRef.current) clearInterval(elapsedTimerRef.current);
201
+ elapsedTimerRef.current = setInterval(() => {
202
+ setElapsed(Math.floor((performance.now() - startTimeRef.current) / 1000));
203
+ }, 1000);
204
+
205
+ // Collect images from MediaProvider if provided and images not passed directly
206
+ let images = config.images;
207
+ if (!images && config.mediaProvider) {
208
+ images = new Map<string, ArrayBuffer>();
209
+ const entries = await config.mediaProvider.listMedia();
210
+ for (const entry of entries) {
211
+ const url = await config.mediaProvider.resolveUrl(entry.name);
212
+ const res = await fetch(url);
213
+ if (res.ok) {
214
+ const data = await res.arrayBuffer();
215
+ images.set(entry.name, data);
216
+ }
217
+ }
218
+ }
219
+
220
+ const docDuration = await frameCapture.init(
221
+ doc,
222
+ { images, audio: config.audio, width, height },
223
+ config.captionMode,
224
+ );
225
+
226
+ if (cancelledRef.current) return;
227
+
228
+ setDuration(docDuration);
229
+ if (docDuration <= 0) {
230
+ throw new Error('Document has zero duration — nothing to export');
231
+ }
232
+
233
+ // ── Step 2: Create encoder ────────────────────────────────
234
+ setPhase('Starting encoder…');
235
+ setProgress(5);
236
+
237
+ const encoder = createEncoder({ width, height, fps, quality });
238
+ encoderRef.current = encoder;
239
+ setBackend('webcodecs');
240
+
241
+ if (cancelledRef.current) return;
242
+
243
+ // ── Step 3: Capture frames and encode ─────────────────────
244
+ setState('capturing');
245
+ const totalFrames = Math.ceil(docDuration * fps);
246
+
247
+ const captureStartTime = performance.now();
248
+ // Throttle UI updates to every ~10 frames to avoid excessive re-renders.
249
+ // Each setState between awaits triggers a separate render cycle.
250
+ const UI_UPDATE_INTERVAL = 10;
251
+
252
+ for (let i = 0; i < totalFrames; i++) {
253
+ if (cancelledRef.current) return;
254
+
255
+ const time = i / fps;
256
+
257
+ // Update UI periodically (not every frame)
258
+ if (i % UI_UPDATE_INTERVAL === 0 || i === totalFrames - 1) {
259
+ const captureProgress = Math.round((i / totalFrames) * 90);
260
+ setProgress(5 + captureProgress);
261
+ setPhase(`Capturing frame ${i + 1}/${totalFrames} (${time.toFixed(1)}s)`);
262
+
263
+ if (i > 0) {
264
+ const elapsedCapture = (performance.now() - captureStartTime) / 1000;
265
+ const avgPerFrame = elapsedCapture / i;
266
+ const remaining = Math.round(avgPerFrame * (totalFrames - i));
267
+ setEstimatedRemaining(remaining);
268
+ }
269
+ }
270
+
271
+ const bitmap = await frameCapture.captureFrame(time);
272
+
273
+ if (cancelledRef.current) {
274
+ bitmap.close();
275
+ return;
276
+ }
277
+
278
+ // Encode immediately — WebCodecs is fast and async internally
279
+ encoder.encodeFrame(bitmap, i);
280
+ }
281
+
282
+ if (cancelledRef.current) return;
283
+
284
+ // ── Step 4: Finalize MP4 ──────────────────────────────────
285
+ setState('encoding');
286
+ setPhase('Finalizing video…');
287
+ setProgress(95);
288
+
289
+ const mp4Buffer = await encoder.finalize();
290
+ encoderRef.current = null;
291
+
292
+ if (cancelledRef.current) return;
293
+
294
+ // ── Step 5: Create download URL ───────────────────────────
295
+ const blob = new Blob([mp4Buffer], { type: 'video/mp4' });
296
+ const url = URL.createObjectURL(blob);
297
+ downloadUrlRef.current = url;
298
+
299
+ setDownloadUrl(url);
300
+ setFileSize(mp4Buffer.byteLength);
301
+ setState('complete');
302
+ setProgress(100);
303
+ setPhase('Export complete');
304
+ setEstimatedRemaining(0);
305
+ if (elapsedTimerRef.current) clearInterval(elapsedTimerRef.current);
306
+
307
+ // Clean up
308
+ frameCapture.destroy();
309
+ } catch (err: unknown) {
310
+ if (elapsedTimerRef.current) clearInterval(elapsedTimerRef.current);
311
+ if (cancelledRef.current) return;
312
+ const message = err instanceof Error ? err.message : String(err);
313
+ setState('error');
314
+ setError(message);
315
+ setPhase('Export failed');
316
+
317
+ // Clean up on error
318
+ if (encoderRef.current) {
319
+ encoderRef.current.close();
320
+ encoderRef.current = null;
321
+ }
322
+ frameCapture.destroy();
323
+ }
324
+ },
325
+ [frameCapture],
326
+ );
327
+
328
+ return {
329
+ state,
330
+ progress,
331
+ phase,
332
+ duration,
333
+ backend,
334
+ downloadUrl,
335
+ fileSize,
336
+ error,
337
+ elapsed,
338
+ estimatedRemaining,
339
+ startExport,
340
+ cancel,
341
+ reset,
342
+ };
343
+ }
package/src/index.ts ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @bendyline/squisq-video-react — Browser Video Export for Squisq Documents
3
+ *
4
+ * Provides React components and hooks for exporting Squisq documents
5
+ * to MP4 video directly in the browser.
6
+ *
7
+ * - VideoExportModal: Full modal UI for configure → export → download
8
+ * - VideoExportButton: Drop-in button that opens the modal
9
+ * - useVideoExport: Low-level hook for custom UIs
10
+ * - useFrameCapture: Frame capture via hidden iframe + html2canvas
11
+ *
12
+ * Encoding: WebCodecs (H.264 via hardware-accelerated VideoEncoder, Chrome 94+)
13
+ */
14
+
15
+ // ── Components ─────────────────────────────────────────────────────
16
+ export { VideoExportModal } from './VideoExportModal.js';
17
+ export type { VideoExportModalProps } from './VideoExportModal.js';
18
+
19
+ export { VideoExportButton } from './VideoExportButton.js';
20
+ export type { VideoExportButtonProps } from './VideoExportButton.js';
21
+
22
+ // ── Hooks ──────────────────────────────────────────────────────────
23
+ export { useVideoExport } from './hooks/useVideoExport.js';
24
+ export type {
25
+ VideoExportState,
26
+ VideoExportConfig,
27
+ VideoExportResult,
28
+ } from './hooks/useVideoExport.js';
29
+
30
+ export { useFrameCapture } from './hooks/useFrameCapture.js';
31
+ export type { FrameCaptureHandle } from './hooks/useFrameCapture.js';
32
+
33
+ // ── Encoder Utilities (for advanced usage) ─────────────────────────
34
+ export { supportsWebCodecs, createEncoder } from './mainThreadEncoder.js';
35
+ export type { MainThreadEncoder } from './mainThreadEncoder.js';