@bendyline/squisq-editor-react 1.6.1 → 2.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.
- package/README.md +12 -3
- package/dist/index.d.ts +1304 -208
- package/dist/index.js +22838 -14494
- package/dist/index.js.map +1 -1
- package/dist/monaco.d.ts +1 -0
- package/dist/monaco.js +4 -0
- package/dist/monaco.js.map +1 -0
- package/dist/styles/index.css +2384 -408
- package/package.json +9 -5
- package/src/BlockPropertiesPopover.tsx +48 -17
- package/src/DocumentSettingsDialog.tsx +13 -21
- package/src/EditorContext.tsx +199 -42
- package/src/EditorShell.tsx +403 -270
- package/src/ImageEditor.tsx +22 -1
- package/src/InlinePreviewGutter.tsx +16 -8
- package/src/MediaBin.tsx +276 -40
- package/src/OutlinePanel.tsx +202 -7
- package/src/PlainHtmlPreview.tsx +40 -1
- package/src/PreviewControls.tsx +466 -93
- package/src/PreviewPanel.tsx +313 -77
- package/src/RawEditor.tsx +13 -2
- package/src/StatusBar.tsx +5 -2
- package/src/TemplateAnnotation.ts +34 -10
- package/src/TemplateContentPreview.tsx +56 -0
- package/src/TemplatePicker.tsx +355 -134
- package/src/ThemeCustomizerPanel.tsx +30 -15
- package/src/ThemePicker.tsx +10 -5
- package/src/TimelineBlockPreview.tsx +1 -1
- package/src/Toolbar.tsx +719 -238
- package/src/TransitionPicker.tsx +44 -5
- package/src/ViewMenuPanel.tsx +12 -14
- package/src/ViewSwitcher.tsx +4 -4
- package/src/WysiwygEditor.tsx +167 -92
- package/src/__tests__/blockPropertiesPopoverTheme.test.tsx +33 -0
- package/src/__tests__/blockTagActivity.test.ts +183 -0
- package/src/__tests__/buildDocumentPreviewMarkdown.test.ts +75 -0
- package/src/__tests__/buildPreviewDocContent.test.ts +48 -0
- package/src/__tests__/buildPreviewDocTransition.test.ts +22 -3
- package/src/__tests__/canvasSurfaceTextEditing.test.tsx +60 -0
- package/src/__tests__/customLayoutManagerTheme.test.tsx +34 -0
- package/src/__tests__/documentSettingsDialog.test.tsx +29 -1
- package/src/__tests__/editorScrollHandoff.test.tsx +102 -0
- package/src/__tests__/editorScrollSync.test.ts +65 -0
- package/src/__tests__/editorShellProps.test.tsx +390 -1
- package/src/__tests__/emojiPicker.test.tsx +2 -42
- package/src/__tests__/headingTransition.test.ts +53 -15
- package/src/__tests__/imageEditAffordance.test.tsx +5 -1
- package/src/__tests__/imageEditModalContract.test.tsx +119 -0
- package/src/__tests__/imageEditorShell.test.tsx +38 -1
- package/src/__tests__/jsonEditor.test.tsx +56 -1
- package/src/__tests__/layersPanel.test.tsx +75 -5
- package/src/__tests__/majorApiTypes.test.ts +26 -0
- package/src/__tests__/mediaBinDrop.test.tsx +90 -0
- package/src/__tests__/mediaReferences.test.ts +82 -0
- package/src/__tests__/narrationSave.test.ts +148 -0
- package/src/__tests__/outlinePanel.test.tsx +93 -3
- package/src/__tests__/outlineSource.test.ts +217 -0
- package/src/__tests__/plainHtmlPreview.test.tsx +17 -1
- package/src/__tests__/presentationMode.test.tsx +290 -0
- package/src/__tests__/previewControls.test.tsx +312 -6
- package/src/__tests__/previewPanelAudioFailure.test.tsx +46 -0
- package/src/__tests__/previewPanelPresentation.test.tsx +126 -0
- package/src/__tests__/previewPanelTransforms.test.tsx +117 -0
- package/src/__tests__/rawEditorModelIsolation.test.ts +19 -0
- package/src/__tests__/resolveBlockVisual.test.ts +43 -0
- package/src/__tests__/statusBar.test.tsx +27 -0
- package/src/__tests__/teleprompter.test.tsx +190 -0
- package/src/__tests__/templateAnnotationRoundTrip.test.ts +49 -2
- package/src/__tests__/templateContentPreview.test.ts +101 -0
- package/src/__tests__/templatePickerPortal.test.tsx +62 -0
- package/src/__tests__/tiptapBridge.test.ts +70 -0
- package/src/__tests__/tiptapCodeBlockRoundTrip.test.ts +109 -0
- package/src/__tests__/transformStyleId.test.ts +13 -0
- package/src/__tests__/useImageEditor.test.tsx +67 -0
- package/src/__tests__/useMediaRecorder.test.ts +75 -0
- package/src/__tests__/viewMenuPanel.test.tsx +130 -0
- package/src/__tests__/wysiwygImageUpload.test.ts +69 -0
- package/src/__tests__/wysiwygTemplateBadgeFocus.test.tsx +56 -0
- package/src/asciiDiagram/AsciiDiagramExtension.ts +343 -0
- package/src/asciiDiagram/AsciiDiagramWidget.tsx +224 -0
- package/src/asciiDiagram/RepairableDiagramExtension.ts +200 -0
- package/src/asciiDiagram/__tests__/AsciiDiagramExtension.test.ts +145 -0
- package/src/asciiDiagram/__tests__/RepairableDiagramExtension.test.ts +159 -0
- package/src/asciiDiagram/__tests__/asciiDiagramCommands.test.ts +227 -0
- package/src/asciiDiagram/__tests__/asciiDiagramOps.test.ts +114 -0
- package/src/asciiDiagram/__tests__/asciiPaste.test.ts +43 -0
- package/src/asciiDiagram/asciiDiagramCommands.ts +148 -0
- package/src/asciiDiagram/asciiDiagramData.ts +116 -0
- package/src/asciiDiagram/asciiDiagramOps.ts +219 -0
- package/src/asciiDiagram/asciiPaste.ts +19 -0
- package/src/blockTagActivity.ts +233 -0
- package/src/buildDocumentPreviewMarkdown.ts +168 -0
- package/src/buildPreviewDoc.ts +19 -12
- package/src/customTemplates/CustomLayoutManager.tsx +3 -2
- package/src/customTemplates/CustomTemplateContext.tsx +6 -0
- package/src/customTemplates/TemplateDesigner.tsx +7 -4
- package/src/customTemplates/__tests__/library.test.ts +8 -0
- package/src/customTemplates/designer.css +158 -99
- package/src/customTemplates/library.ts +16 -3
- package/src/customThemes/CustomThemeContext.tsx +6 -0
- package/src/customThemes/CustomThemeDialog.tsx +35 -5
- package/src/customThemes/ImportThemeSection.tsx +178 -0
- package/src/customThemes/__tests__/customThemeLibrary.test.ts +9 -0
- package/src/customThemes/__tests__/importThemeSection.test.tsx +192 -0
- package/src/customThemes/customThemeLibrary.ts +7 -4
- package/src/customThemes/index.ts +7 -1
- package/src/customThemes/themeDraft.ts +23 -7
- package/src/diagram/DiagramCanvas.tsx +9 -4
- package/src/diagram/types.ts +35 -0
- package/src/editorScrollSync.ts +73 -0
- package/src/emojiData.ts +3 -23
- package/src/headingTransition.ts +85 -25
- package/src/imageEditor/CanvasSurface.tsx +29 -23
- package/src/imageEditor/LayersPanel.tsx +78 -3
- package/src/imageEditor/Toolbar.tsx +5 -1
- package/src/imageEditor/icons.tsx +4 -0
- package/src/imageEditor/image-editor.css +75 -0
- package/src/imageEditor/layers/SelectionHandles.tsx +1 -1
- package/src/imageEditor/useImageEditor.ts +71 -14
- package/src/index.ts +193 -20
- package/src/jsonEditor/JsonEditorContext.tsx +12 -6
- package/src/jsonEditor/RenderNode.tsx +24 -3
- package/src/jsonEditor/editors.tsx +86 -19
- package/src/mediaEntries.ts +12 -0
- package/src/mediaReferences.ts +299 -0
- package/src/monaco.ts +35 -0
- package/src/monacoWorkers.ts +89 -0
- package/src/outlineSource.ts +171 -0
- package/src/presentation/PresentationMode.tsx +596 -0
- package/src/rawEditorIsolation.ts +18 -0
- package/src/recorder/hooks/useMediaRecorder.ts +97 -53
- package/src/resolveBlockVisual.ts +10 -4
- package/src/scene/Scene.tsx +101 -25
- package/src/scene/SceneBlockExtension.ts +17 -10
- package/src/scene/SceneBlockWidget.tsx +11 -4
- package/src/scene/SceneSelection.tsx +19 -15
- package/src/scene/SceneSideToolbar.tsx +89 -0
- package/src/scene/SceneViewport.tsx +7 -3
- package/src/scene/ShapePalette.tsx +17 -2
- package/src/scene/__tests__/DiagramAdapter.test.ts +86 -0
- package/src/scene/__tests__/SceneBlockExtension.test.ts +33 -0
- package/src/scene/__tests__/sceneIsolation.test.tsx +93 -0
- package/src/scene/adapters/DiagramAdapter.ts +12 -101
- package/src/scene/commands/SceneCommand.ts +4 -1
- package/src/scene/index.ts +1 -6
- package/src/scene/layers/DiagramEdges.tsx +24 -9
- package/src/scene/layers/edgeGeometry.ts +31 -4
- package/src/scene/layers/nodeCard.tsx +27 -8
- package/src/scene/scene.css +145 -2
- package/src/scene/text/SceneTextOverlay.tsx +5 -5
- package/src/scene/text/sceneTextChannel.ts +26 -20
- package/src/scene/text/sceneTextConfig.ts +4 -0
- package/src/scene/tools/ConnectTool.ts +126 -28
- package/src/scene/tools/DrawingConnectTool.ts +86 -16
- package/src/scene/tools/SceneTool.ts +10 -0
- package/src/scene/tools/SelectTool.ts +34 -18
- package/src/scene/tools/ShapeTool.ts +2 -3
- package/src/styles/ascii-diagram.css +79 -0
- package/src/styles/ascii-timeline.css +499 -0
- package/src/styles/editor.css +1566 -219
- package/src/styles/index.css +3 -0
- package/src/styles/tree-view.css +139 -0
- package/src/teleprompter/TeleprompterControls.tsx +218 -0
- package/src/teleprompter/TeleprompterSelfView.tsx +22 -0
- package/src/teleprompter/TeleprompterSurface.tsx +267 -0
- package/src/teleprompter/TeleprompterView.tsx +338 -0
- package/src/teleprompter/canvasRenderer.ts +161 -0
- package/src/teleprompter/floatingWindow.ts +352 -0
- package/src/teleprompter/index.ts +61 -0
- package/src/teleprompter/pcmWorklet.ts +62 -0
- package/src/teleprompter/recording/insertPreamble.ts +80 -0
- package/src/teleprompter/recording/narrationSave.ts +134 -0
- package/src/teleprompter/recording/useNarrationRecorder.ts +367 -0
- package/src/teleprompter/scrollModel.ts +85 -0
- package/src/teleprompter/teleprompterTheme.ts +303 -0
- package/src/teleprompter/types.ts +38 -0
- package/src/teleprompter/useFloatingWindow.ts +74 -0
- package/src/teleprompter/useMicAnalysis.ts +211 -0
- package/src/teleprompter/useTeleprompter.ts +421 -0
- package/src/templateContentPreviewResolver.ts +360 -0
- package/src/timeline/TimelineEditorWidget.tsx +702 -0
- package/src/timeline/TimelineViewExtension.ts +252 -0
- package/src/timeline/__tests__/TimelineEditorWidget.test.tsx +355 -0
- package/src/timeline/__tests__/TimelineViewExtension.test.ts +163 -0
- package/src/timeline/__tests__/timelineCommands.test.ts +327 -0
- package/src/timeline/__tests__/timelineOps.test.ts +222 -0
- package/src/timeline/__tests__/timelinePaste.test.ts +34 -0
- package/src/timeline/timelineCommands.ts +367 -0
- package/src/timeline/timelineData.ts +54 -0
- package/src/timeline/timelineOps.ts +277 -0
- package/src/timeline/timelinePaste.ts +8 -0
- package/src/tiptapBridge.ts +84 -49
- package/src/transformStyleId.ts +17 -0
- package/src/treeview/TreeOutlineWidget.tsx +240 -0
- package/src/treeview/TreeViewExtension.ts +250 -0
- package/src/treeview/__tests__/TreeViewExtension.test.ts +122 -0
- package/src/treeview/__tests__/treeOps.test.ts +125 -0
- package/src/treeview/__tests__/treePaste.test.ts +40 -0
- package/src/treeview/__tests__/treeViewCommands.test.ts +163 -0
- package/src/treeview/treeOps.ts +172 -0
- package/src/treeview/treePaste.ts +13 -0
- package/src/treeview/treeViewCommands.ts +94 -0
- package/src/treeview/treeViewData.ts +41 -0
- package/src/useMonacoLoader.ts +11 -34
- package/src/wysiwygImageUpload.ts +113 -0
- package/src/diagram/DiagramExtension.ts +0 -209
- package/src/diagram/DiagramWidget.tsx +0 -270
- package/src/diagram/useDiagramData.ts +0 -126
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Floating-teleprompter window manager — framework-free.
|
|
3
|
+
*
|
|
4
|
+
* Capability ladder, best first:
|
|
5
|
+
* 1. `document-pip` — Document Picture-in-Picture (Chromium 116+,
|
|
6
|
+
* Firefox 151+): a true always-on-top window hosting live DOM; the
|
|
7
|
+
* React surface portals into it.
|
|
8
|
+
* 2. `video-pip` — canvas → `captureStream(0)` → `<video>` →
|
|
9
|
+
* `requestPictureInPicture()` (Safari's only always-on-top path;
|
|
10
|
+
* `webkitSetPresentationMode` fallback). Read-only: the main
|
|
11
|
+
* window draws frames and calls `requestFrame()` on analysis
|
|
12
|
+
* ticks — never rAF, which throttles under occlusion.
|
|
13
|
+
* 3. `popup` — `window.open` (positionable, not always-on-top).
|
|
14
|
+
* 4. `docked` — no float.
|
|
15
|
+
*
|
|
16
|
+
* Every tier is feature-detected at open time and falls through to the
|
|
17
|
+
* next on ANY failure. All interactive state stays in the main window;
|
|
18
|
+
* floats are render targets only.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type { FloatTier } from './types';
|
|
22
|
+
|
|
23
|
+
interface DocumentPictureInPictureApi {
|
|
24
|
+
requestWindow(options?: { width?: number; height?: number }): Promise<Window>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface WindowWithDocPip extends Window {
|
|
28
|
+
documentPictureInPicture?: DocumentPictureInPictureApi;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface WebKitVideoElement extends HTMLVideoElement {
|
|
32
|
+
webkitSetPresentationMode?: (mode: 'picture-in-picture' | 'inline') => void;
|
|
33
|
+
webkitSupportsPresentationMode?: (mode: string) => boolean;
|
|
34
|
+
webkitPresentationMode?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface CaptureTrackWithRequestFrame extends MediaStreamTrack {
|
|
38
|
+
requestFrame?: () => void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface FloatOpenOptions {
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
/** Try this tier first; the ladder continues below it on failure. */
|
|
45
|
+
preferredTier?: FloatTier;
|
|
46
|
+
title: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface CanvasSink {
|
|
50
|
+
canvas: HTMLCanvasElement;
|
|
51
|
+
width: number;
|
|
52
|
+
height: number;
|
|
53
|
+
/** Push the freshly drawn canvas frame into the PiP video. */
|
|
54
|
+
requestFrame: () => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type FloatEvent = 'closed' | 'tierchange';
|
|
58
|
+
|
|
59
|
+
export interface FloatingWindowManager {
|
|
60
|
+
readonly tier: FloatTier;
|
|
61
|
+
readonly isOpen: boolean;
|
|
62
|
+
/** Resolves with the tier that actually opened ('docked' if none could). */
|
|
63
|
+
open(opts: FloatOpenOptions): Promise<FloatTier>;
|
|
64
|
+
/** Idempotent; restores docked and emits 'closed'. */
|
|
65
|
+
close(): void;
|
|
66
|
+
/** Portal container for 'document-pip' | 'popup'; null otherwise. */
|
|
67
|
+
getPortalTarget(): HTMLElement | null;
|
|
68
|
+
/** Canvas sink for 'video-pip'; null otherwise. */
|
|
69
|
+
getCanvasSink(): CanvasSink | null;
|
|
70
|
+
on(event: FloatEvent, cb: (tier: FloatTier) => void): () => void;
|
|
71
|
+
/** Tear everything down (unmount); like close() but silent-safe. */
|
|
72
|
+
dispose(): void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Feature-detect the available float tiers, best first. */
|
|
76
|
+
export function detectFloatTiers(): FloatTier[] {
|
|
77
|
+
const tiers: FloatTier[] = [];
|
|
78
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
79
|
+
if ((window as WindowWithDocPip).documentPictureInPicture) tiers.push('document-pip');
|
|
80
|
+
const video = document.createElement('video') as WebKitVideoElement;
|
|
81
|
+
const stdPip =
|
|
82
|
+
document.pictureInPictureEnabled === true &&
|
|
83
|
+
typeof video.requestPictureInPicture === 'function';
|
|
84
|
+
const webkitPip =
|
|
85
|
+
typeof video.webkitSetPresentationMode === 'function' &&
|
|
86
|
+
(video.webkitSupportsPresentationMode?.('picture-in-picture') ?? true);
|
|
87
|
+
const canCapture =
|
|
88
|
+
typeof HTMLCanvasElement !== 'undefined' &&
|
|
89
|
+
typeof HTMLCanvasElement.prototype.captureStream === 'function';
|
|
90
|
+
if ((stdPip || webkitPip) && canCapture) tiers.push('video-pip');
|
|
91
|
+
if (typeof window.open === 'function') tiers.push('popup');
|
|
92
|
+
}
|
|
93
|
+
tiers.push('docked');
|
|
94
|
+
return tiers;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface ActiveFloat {
|
|
98
|
+
tier: FloatTier;
|
|
99
|
+
portalTarget: HTMLElement | null;
|
|
100
|
+
canvasSink: CanvasSink | null;
|
|
101
|
+
dispose: () => void;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function createFloatingWindowManager(deps: { styleCss: string }): FloatingWindowManager {
|
|
105
|
+
let active: ActiveFloat | null = null;
|
|
106
|
+
const listeners: Record<FloatEvent, Set<(tier: FloatTier) => void>> = {
|
|
107
|
+
closed: new Set(),
|
|
108
|
+
tierchange: new Set(),
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const emit = (event: FloatEvent, tier: FloatTier) => {
|
|
112
|
+
for (const cb of listeners[event]) cb(tier);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/** Handles user-initiated closes (PiP ✕, popup close, navigation). */
|
|
116
|
+
const handleExternalClose = () => {
|
|
117
|
+
if (!active) return;
|
|
118
|
+
const closing = active;
|
|
119
|
+
active = null;
|
|
120
|
+
closing.dispose();
|
|
121
|
+
emit('tierchange', 'docked');
|
|
122
|
+
emit('closed', 'docked');
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const openerPageHide = () => manager.close();
|
|
126
|
+
if (typeof window !== 'undefined') {
|
|
127
|
+
window.addEventListener('pagehide', openerPageHide);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const writeFloatDocument = (doc: Document, title: string): HTMLElement => {
|
|
131
|
+
doc.title = title;
|
|
132
|
+
const style = doc.createElement('style');
|
|
133
|
+
style.textContent = `${deps.styleCss}\nhtml,body{margin:0;height:100%;}#squisq-float-root{height:100%;display:flex;}`;
|
|
134
|
+
doc.head.appendChild(style);
|
|
135
|
+
const root = doc.createElement('div');
|
|
136
|
+
root.id = 'squisq-float-root';
|
|
137
|
+
doc.body.appendChild(root);
|
|
138
|
+
return root;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const openDocumentPip = async (opts: FloatOpenOptions): Promise<ActiveFloat> => {
|
|
142
|
+
const api = (window as WindowWithDocPip).documentPictureInPicture;
|
|
143
|
+
if (!api) throw new Error('Document PiP unavailable');
|
|
144
|
+
const pip = await api.requestWindow({ width: opts.width, height: opts.height });
|
|
145
|
+
// Copy same-origin stylesheets so editor chrome vars resolve; the
|
|
146
|
+
// injected styleCss below is what the surface actually depends on.
|
|
147
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
148
|
+
try {
|
|
149
|
+
const rules = Array.from(sheet.cssRules)
|
|
150
|
+
.map((rule) => rule.cssText)
|
|
151
|
+
.join('\n');
|
|
152
|
+
const style = pip.document.createElement('style');
|
|
153
|
+
style.textContent = rules;
|
|
154
|
+
pip.document.head.appendChild(style);
|
|
155
|
+
} catch {
|
|
156
|
+
if (sheet.href) {
|
|
157
|
+
const link = pip.document.createElement('link');
|
|
158
|
+
link.rel = 'stylesheet';
|
|
159
|
+
link.href = sheet.href;
|
|
160
|
+
pip.document.head.appendChild(link);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const root = writeFloatDocument(pip.document, opts.title);
|
|
165
|
+
pip.addEventListener('pagehide', handleExternalClose);
|
|
166
|
+
return {
|
|
167
|
+
tier: 'document-pip',
|
|
168
|
+
portalTarget: root,
|
|
169
|
+
canvasSink: null,
|
|
170
|
+
dispose: () => {
|
|
171
|
+
pip.removeEventListener('pagehide', handleExternalClose);
|
|
172
|
+
try {
|
|
173
|
+
pip.close();
|
|
174
|
+
} catch {
|
|
175
|
+
// Already closed by the user.
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const openVideoPip = async (opts: FloatOpenOptions): Promise<ActiveFloat> => {
|
|
182
|
+
const canvas = document.createElement('canvas');
|
|
183
|
+
canvas.width = Math.round(opts.width * (window.devicePixelRatio || 1));
|
|
184
|
+
canvas.height = Math.round(opts.height * (window.devicePixelRatio || 1));
|
|
185
|
+
const ctx = canvas.getContext('2d');
|
|
186
|
+
if (!ctx || typeof canvas.captureStream !== 'function') {
|
|
187
|
+
throw new Error('canvas.captureStream unavailable');
|
|
188
|
+
}
|
|
189
|
+
ctx.fillStyle = '#101014';
|
|
190
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
191
|
+
|
|
192
|
+
let stream: MediaStream;
|
|
193
|
+
let requestFrame: () => void;
|
|
194
|
+
try {
|
|
195
|
+
stream = canvas.captureStream(0);
|
|
196
|
+
const track = stream.getVideoTracks()[0] as CaptureTrackWithRequestFrame;
|
|
197
|
+
if (typeof track.requestFrame === 'function') {
|
|
198
|
+
const pushFrame = track.requestFrame.bind(track);
|
|
199
|
+
requestFrame = () => pushFrame();
|
|
200
|
+
} else {
|
|
201
|
+
// No manual-frame API: fall back to a 30 fps capture; draws still
|
|
202
|
+
// happen on analysis ticks so content stays audio-clock driven.
|
|
203
|
+
stream = canvas.captureStream(30);
|
|
204
|
+
requestFrame = () => undefined;
|
|
205
|
+
}
|
|
206
|
+
} catch {
|
|
207
|
+
stream = canvas.captureStream(30);
|
|
208
|
+
requestFrame = () => undefined;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const video = document.createElement('video') as WebKitVideoElement;
|
|
212
|
+
video.muted = true;
|
|
213
|
+
video.playsInline = true;
|
|
214
|
+
video.style.position = 'fixed';
|
|
215
|
+
video.style.left = '-10000px';
|
|
216
|
+
video.style.width = `${opts.width}px`;
|
|
217
|
+
video.srcObject = stream;
|
|
218
|
+
document.body.appendChild(video);
|
|
219
|
+
|
|
220
|
+
const cleanupDom = () => {
|
|
221
|
+
video.pause();
|
|
222
|
+
video.srcObject = null;
|
|
223
|
+
video.remove();
|
|
224
|
+
for (const track of stream.getTracks()) track.stop();
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
await video.play();
|
|
229
|
+
requestFrame();
|
|
230
|
+
if (typeof video.requestPictureInPicture === 'function' && document.pictureInPictureEnabled) {
|
|
231
|
+
await video.requestPictureInPicture();
|
|
232
|
+
video.addEventListener('leavepictureinpicture', handleExternalClose);
|
|
233
|
+
} else if (typeof video.webkitSetPresentationMode === 'function') {
|
|
234
|
+
video.webkitSetPresentationMode('picture-in-picture');
|
|
235
|
+
video.addEventListener('webkitpresentationmodechanged', () => {
|
|
236
|
+
if (video.webkitPresentationMode === 'inline') handleExternalClose();
|
|
237
|
+
});
|
|
238
|
+
} else {
|
|
239
|
+
throw new Error('No video PiP API');
|
|
240
|
+
}
|
|
241
|
+
} catch (err: unknown) {
|
|
242
|
+
cleanupDom();
|
|
243
|
+
throw err instanceof Error ? err : new Error(String(err));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
tier: 'video-pip',
|
|
248
|
+
portalTarget: null,
|
|
249
|
+
canvasSink: { canvas, width: canvas.width, height: canvas.height, requestFrame },
|
|
250
|
+
dispose: () => {
|
|
251
|
+
video.removeEventListener('leavepictureinpicture', handleExternalClose);
|
|
252
|
+
if (document.pictureInPictureElement === video) {
|
|
253
|
+
void document.exitPictureInPicture().catch(() => undefined);
|
|
254
|
+
} else if (
|
|
255
|
+
typeof video.webkitSetPresentationMode === 'function' &&
|
|
256
|
+
video.webkitPresentationMode === 'picture-in-picture'
|
|
257
|
+
) {
|
|
258
|
+
video.webkitSetPresentationMode('inline');
|
|
259
|
+
}
|
|
260
|
+
cleanupDom();
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const openPopup = (opts: FloatOpenOptions): ActiveFloat => {
|
|
266
|
+
const popup = window.open(
|
|
267
|
+
'',
|
|
268
|
+
'squisq-teleprompter',
|
|
269
|
+
`popup=yes,width=${opts.width},height=${opts.height}`,
|
|
270
|
+
);
|
|
271
|
+
if (!popup) throw new Error('Popup blocked');
|
|
272
|
+
const root = writeFloatDocument(popup.document, opts.title);
|
|
273
|
+
popup.addEventListener('pagehide', handleExternalClose);
|
|
274
|
+
popup.focus();
|
|
275
|
+
return {
|
|
276
|
+
tier: 'popup',
|
|
277
|
+
portalTarget: root,
|
|
278
|
+
canvasSink: null,
|
|
279
|
+
dispose: () => {
|
|
280
|
+
popup.removeEventListener('pagehide', handleExternalClose);
|
|
281
|
+
try {
|
|
282
|
+
popup.close();
|
|
283
|
+
} catch {
|
|
284
|
+
// Already closed.
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const manager: FloatingWindowManager = {
|
|
291
|
+
get tier() {
|
|
292
|
+
return active?.tier ?? 'docked';
|
|
293
|
+
},
|
|
294
|
+
get isOpen() {
|
|
295
|
+
return active !== null;
|
|
296
|
+
},
|
|
297
|
+
async open(opts: FloatOpenOptions): Promise<FloatTier> {
|
|
298
|
+
manager.close();
|
|
299
|
+
const supported = detectFloatTiers();
|
|
300
|
+
const ladder =
|
|
301
|
+
opts.preferredTier && supported.includes(opts.preferredTier)
|
|
302
|
+
? [opts.preferredTier, ...supported.filter((t) => t !== opts.preferredTier)]
|
|
303
|
+
: supported;
|
|
304
|
+
for (const tier of ladder) {
|
|
305
|
+
if (tier === 'docked') break;
|
|
306
|
+
try {
|
|
307
|
+
if (tier === 'document-pip') active = await openDocumentPip(opts);
|
|
308
|
+
else if (tier === 'video-pip') active = await openVideoPip(opts);
|
|
309
|
+
else if (tier === 'popup') active = openPopup(opts);
|
|
310
|
+
if (active) {
|
|
311
|
+
emit('tierchange', active.tier);
|
|
312
|
+
return active.tier;
|
|
313
|
+
}
|
|
314
|
+
} catch {
|
|
315
|
+
active = null; // fall through to the next tier
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
emit('tierchange', 'docked');
|
|
319
|
+
return 'docked';
|
|
320
|
+
},
|
|
321
|
+
close() {
|
|
322
|
+
if (!active) return;
|
|
323
|
+
const closing = active;
|
|
324
|
+
active = null;
|
|
325
|
+
closing.dispose();
|
|
326
|
+
emit('tierchange', 'docked');
|
|
327
|
+
emit('closed', 'docked');
|
|
328
|
+
},
|
|
329
|
+
getPortalTarget() {
|
|
330
|
+
return active?.portalTarget ?? null;
|
|
331
|
+
},
|
|
332
|
+
getCanvasSink() {
|
|
333
|
+
return active?.canvasSink ?? null;
|
|
334
|
+
},
|
|
335
|
+
on(event: FloatEvent, cb: (tier: FloatTier) => void) {
|
|
336
|
+
listeners[event].add(cb);
|
|
337
|
+
return () => {
|
|
338
|
+
listeners[event].delete(cb);
|
|
339
|
+
};
|
|
340
|
+
},
|
|
341
|
+
dispose() {
|
|
342
|
+
manager.close();
|
|
343
|
+
if (typeof window !== 'undefined') {
|
|
344
|
+
window.removeEventListener('pagehide', openerPageHide);
|
|
345
|
+
}
|
|
346
|
+
listeners.closed.clear();
|
|
347
|
+
listeners.tierchange.clear();
|
|
348
|
+
},
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
return manager;
|
|
352
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrate (teleprompter) display mode — public surface.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
TeleprompterView,
|
|
7
|
+
type TeleprompterViewProps,
|
|
8
|
+
type TeleprompterRecordingDeps,
|
|
9
|
+
} from './TeleprompterView';
|
|
10
|
+
export {
|
|
11
|
+
useNarrationRecorder,
|
|
12
|
+
type NarrationRecorderController,
|
|
13
|
+
type NarrationRecorderState,
|
|
14
|
+
type NarrationTake,
|
|
15
|
+
} from './recording/useNarrationRecorder';
|
|
16
|
+
export {
|
|
17
|
+
buildNarrationSavePlan,
|
|
18
|
+
executeNarrationSave,
|
|
19
|
+
type NarrationSavePlan,
|
|
20
|
+
type NarrationSaveResult,
|
|
21
|
+
} from './recording/narrationSave';
|
|
22
|
+
export {
|
|
23
|
+
insertNarrationPreamble,
|
|
24
|
+
narrationAnnotationLine,
|
|
25
|
+
cameraVideoLine,
|
|
26
|
+
} from './recording/insertPreamble';
|
|
27
|
+
export { TeleprompterSurface, type TeleprompterSurfaceProps } from './TeleprompterSurface';
|
|
28
|
+
export { TeleprompterControls, type TeleprompterControlsProps } from './TeleprompterControls';
|
|
29
|
+
export {
|
|
30
|
+
useTeleprompter,
|
|
31
|
+
vadConfigForSensitivity,
|
|
32
|
+
type TeleprompterController,
|
|
33
|
+
} from './useTeleprompter';
|
|
34
|
+
export { useMicAnalysis, type MicAnalysisHandle, type MicAnalysisStatus } from './useMicAnalysis';
|
|
35
|
+
export { PCM_WORKLET_SOURCE, PCM_WORKLET_NAME, registerPcmWorklet } from './pcmWorklet';
|
|
36
|
+
export {
|
|
37
|
+
createFloatingWindowManager,
|
|
38
|
+
detectFloatTiers,
|
|
39
|
+
type FloatingWindowManager,
|
|
40
|
+
type FloatOpenOptions,
|
|
41
|
+
type CanvasSink,
|
|
42
|
+
} from './floatingWindow';
|
|
43
|
+
export { useFloatingWindow, type FloatingWindowHandle } from './useFloatingWindow';
|
|
44
|
+
export {
|
|
45
|
+
measureTokenLines,
|
|
46
|
+
targetOffsetFor,
|
|
47
|
+
stepScroll,
|
|
48
|
+
EYE_LINE_FRACTION,
|
|
49
|
+
type TokenLineMap,
|
|
50
|
+
} from './scrollModel';
|
|
51
|
+
export {
|
|
52
|
+
TELEPROMPTER_CSS,
|
|
53
|
+
ensureTeleprompterStyles,
|
|
54
|
+
prompterVarsFromTheme,
|
|
55
|
+
} from './teleprompterTheme';
|
|
56
|
+
export {
|
|
57
|
+
DEFAULT_TELEPROMPTER_PREFS,
|
|
58
|
+
type TeleprompterPrefs,
|
|
59
|
+
type PrompterTransport,
|
|
60
|
+
type FloatTier,
|
|
61
|
+
} from './types';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The PCM tap AudioWorklet, shipped as an inline source string.
|
|
3
|
+
*
|
|
4
|
+
* Why inline → Blob URL instead of a bundled asset: `audioWorklet
|
|
5
|
+
* .addModule(url)` resolves relative to the host DOCUMENT, so a
|
|
6
|
+
* dist-relative asset would need every consumer's bundler to rewrite
|
|
7
|
+
* and serve it (editor-react ships zero runtime assets today). The
|
|
8
|
+
* worklet is ~30 lines with no imports; inlining follows the
|
|
9
|
+
* `PLAYER_BUNDLE` source-string precedent and needs zero bundler
|
|
10
|
+
* config. The worklet does NO DSP — it batches 128-sample render
|
|
11
|
+
* quanta into 1024-sample frames and posts them (transferably) to the
|
|
12
|
+
* main thread, where the pure engine in `@bendyline/squisq/narration`
|
|
13
|
+
* runs. The audio render thread never throttles, so pacing keeps
|
|
14
|
+
* working while the browser window is fully occluded by recording
|
|
15
|
+
* software — the whole point of the teleprompter's scenario 2.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export const PCM_WORKLET_NAME = 'squisq-pcm-tap';
|
|
19
|
+
|
|
20
|
+
export const PCM_WORKLET_SOURCE = `
|
|
21
|
+
class SquisqPcmTap extends AudioWorkletProcessor {
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this._buf = new Float32Array(1024);
|
|
25
|
+
this._len = 0;
|
|
26
|
+
}
|
|
27
|
+
process(inputs) {
|
|
28
|
+
const channel = inputs[0] && inputs[0][0];
|
|
29
|
+
if (channel && channel.length > 0) {
|
|
30
|
+
let i = 0;
|
|
31
|
+
while (i < channel.length) {
|
|
32
|
+
const n = Math.min(channel.length - i, this._buf.length - this._len);
|
|
33
|
+
this._buf.set(channel.subarray(i, i + n), this._len);
|
|
34
|
+
this._len += n;
|
|
35
|
+
i += n;
|
|
36
|
+
if (this._len === this._buf.length) {
|
|
37
|
+
const out = this._buf;
|
|
38
|
+
this._buf = new Float32Array(1024);
|
|
39
|
+
this._len = 0;
|
|
40
|
+
// Clone, don't transfer: Chrome recycles buffers transferred out
|
|
41
|
+
// of the worklet scope once the receiving handler returns, so a
|
|
42
|
+
// transferred hop reads as zeros if anything retains it. A 4 KB
|
|
43
|
+
// structured clone at ~47 Hz is negligible.
|
|
44
|
+
this.port.postMessage({ pcm: out, audioTime: currentTime });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
registerProcessor('${PCM_WORKLET_NAME}', SquisqPcmTap);
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
/** Register the tap on an AudioContext via a same-origin Blob URL. */
|
|
55
|
+
export async function registerPcmWorklet(ctx: AudioContext): Promise<void> {
|
|
56
|
+
const url = URL.createObjectURL(new Blob([PCM_WORKLET_SOURCE], { type: 'text/javascript' }));
|
|
57
|
+
try {
|
|
58
|
+
await ctx.audioWorklet.addModule(url);
|
|
59
|
+
} finally {
|
|
60
|
+
URL.revokeObjectURL(url);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure markdown edit: insert (or replace) the narration reference at the
|
|
3
|
+
* start of the document.
|
|
4
|
+
*
|
|
5
|
+
* The narration take is referenced by a preamble media annotation —
|
|
6
|
+
* `{[audio src=audio/narration-….webm anchor=document]}` — the canonical
|
|
7
|
+
* authored form `markdownToDoc` lifts into `doc.documentMedia`. A prior
|
|
8
|
+
* teleprompter take's line (matched by the `audio/narration-` prefix +
|
|
9
|
+
* `anchor=document`) is replaced, so retakes swap the reference instead
|
|
10
|
+
* of stacking narrations. The optional camera companion rides on the
|
|
11
|
+
* next line as an inline `<video>` (deliberately NOT doc-anchored:
|
|
12
|
+
* document-anchored video renders full-bleed behind every block and is
|
|
13
|
+
* excluded from export audio — not a talking head).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const NARRATION_LINE =
|
|
17
|
+
/^\{\[audio\s[^\]]*src="?audio\/narration-[^\]]*anchor=document[^\]]*\]\}\s*$/;
|
|
18
|
+
const CAMERA_LINE = /^<video\s[^>]*src="video\/narration-cam-[^"]*"[^>]*><\/video>\s*$/;
|
|
19
|
+
|
|
20
|
+
function quoteSrc(path: string): string {
|
|
21
|
+
return /[\s"']/.test(path) ? `"${path.replace(/"/g, '\\"')}"` : path;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function narrationAnnotationLine(audioPath: string): string {
|
|
25
|
+
return `{[audio src=${quoteSrc(audioPath)} anchor=document]}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function cameraVideoLine(cameraPath: string): string {
|
|
29
|
+
return `<video src="${cameraPath}" controls width="240"></video>`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Insert the narration preamble after the frontmatter (or at the top),
|
|
34
|
+
* replacing any previous teleprompter take's lines.
|
|
35
|
+
*/
|
|
36
|
+
export function insertNarrationPreamble(
|
|
37
|
+
source: string,
|
|
38
|
+
audioPath: string,
|
|
39
|
+
cameraPath: string | null,
|
|
40
|
+
): string {
|
|
41
|
+
const lines = source.split('\n');
|
|
42
|
+
|
|
43
|
+
// Locate the insertion point: after a closing frontmatter fence.
|
|
44
|
+
let insertAt = 0;
|
|
45
|
+
if (lines[0]?.trim() === '---') {
|
|
46
|
+
for (let i = 1; i < lines.length; i++) {
|
|
47
|
+
if (lines[i].trim() === '---') {
|
|
48
|
+
insertAt = i + 1;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Remove a previous take's annotation (+ adjacent camera line).
|
|
55
|
+
for (let i = 0; i < lines.length; i++) {
|
|
56
|
+
if (!NARRATION_LINE.test(lines[i])) continue;
|
|
57
|
+
let removeEnd = i + 1;
|
|
58
|
+
while (removeEnd < lines.length && lines[removeEnd].trim() === '') removeEnd++;
|
|
59
|
+
if (removeEnd < lines.length && CAMERA_LINE.test(lines[removeEnd])) removeEnd++;
|
|
60
|
+
// Also consume one trailing blank so we don't accumulate gaps.
|
|
61
|
+
if (removeEnd < lines.length && lines[removeEnd].trim() === '') removeEnd++;
|
|
62
|
+
lines.splice(i, removeEnd - i);
|
|
63
|
+
if (insertAt > i) insertAt = Math.max(0, insertAt - (removeEnd - i));
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const inserted: string[] = [narrationAnnotationLine(audioPath)];
|
|
68
|
+
if (cameraPath) {
|
|
69
|
+
inserted.push('', cameraVideoLine(cameraPath));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Blank-line separation on both sides (unless at the very top with
|
|
73
|
+
// content immediately following, where only the trailing blank matters).
|
|
74
|
+
const before = lines.slice(0, insertAt);
|
|
75
|
+
const after = lines.slice(insertAt);
|
|
76
|
+
if (before.length > 0 && before[before.length - 1].trim() !== '') before.push('');
|
|
77
|
+
if (after.length > 0 && after[0].trim() !== '') inserted.push('');
|
|
78
|
+
|
|
79
|
+
return [...before, ...inserted, ...after].join('\n');
|
|
80
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure save-plan builder for a narration take, plus its executor.
|
|
3
|
+
*
|
|
4
|
+
* Follows the recorder's conventions (`RecorderModal.handleSave`):
|
|
5
|
+
* audio at `audio/<narration-…>` via `MediaProvider.addMedia` (the
|
|
6
|
+
* RETURNED path is authoritative — providers may rename), the timing
|
|
7
|
+
* sidecar at `<audio>.timing.json` via `container.writeFile` (falling
|
|
8
|
+
* back to `addMedia` with a warning), and ONE `setMarkdownSource` write
|
|
9
|
+
* composing every markdown edit from a single snapshot (the single-write
|
|
10
|
+
* rule — successive writes each derive from stale source and clobber
|
|
11
|
+
* each other).
|
|
12
|
+
*
|
|
13
|
+
* Block timings deliberately do NOT get baked into heading `duration=`
|
|
14
|
+
* pins: pins outrank narration in `applyNarrationTiming`, so baking
|
|
15
|
+
* them would shadow every retake. The sidecar owns the timing.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
buildNarrationTimingJson,
|
|
20
|
+
type NarrationAlignment,
|
|
21
|
+
type NarrationScript,
|
|
22
|
+
type NarrationTimingJsonV3,
|
|
23
|
+
} from '@bendyline/squisq/narration';
|
|
24
|
+
import type { MediaProvider } from '@bendyline/squisq/schemas';
|
|
25
|
+
import type { ContentContainer } from '@bendyline/squisq/storage';
|
|
26
|
+
import { buildFilename } from '../../recorder/formats';
|
|
27
|
+
import { encodeTimingJson, timingPathFor } from '../../recorder/timingJson';
|
|
28
|
+
import { insertNarrationPreamble } from './insertPreamble';
|
|
29
|
+
|
|
30
|
+
export interface NarrationSavePlanArgs {
|
|
31
|
+
script: NarrationScript;
|
|
32
|
+
/** Null when decode/alignment failed — the sidecar still saves (empty timing). */
|
|
33
|
+
alignment: NarrationAlignment | null;
|
|
34
|
+
durationSec: number;
|
|
35
|
+
audioExt: string;
|
|
36
|
+
cameraExt: string | null;
|
|
37
|
+
baseWpm: number;
|
|
38
|
+
cameraOffsetSec?: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface NarrationSavePlan {
|
|
42
|
+
audioRelativeName: string;
|
|
43
|
+
cameraRelativeName: string | null;
|
|
44
|
+
sidecarPayload: NarrationTimingJsonV3;
|
|
45
|
+
/** Sidecar path for a given (possibly renamed) saved audio path. */
|
|
46
|
+
sidecarPathFor: (savedAudioPath: string) => string;
|
|
47
|
+
/** Compose ALL markdown edits from one source snapshot. */
|
|
48
|
+
nextMarkdown: (
|
|
49
|
+
currentSource: string,
|
|
50
|
+
savedAudioPath: string,
|
|
51
|
+
savedCameraPath: string | null,
|
|
52
|
+
) => string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function buildNarrationSavePlan(args: NarrationSavePlanArgs): NarrationSavePlan {
|
|
56
|
+
const sidecarPayload: NarrationTimingJsonV3 = args.alignment
|
|
57
|
+
? buildNarrationTimingJson(args.script, args.alignment, args.durationSec, {
|
|
58
|
+
baseWpm: args.baseWpm,
|
|
59
|
+
...(args.cameraOffsetSec !== undefined ? { cameraOffsetSec: args.cameraOffsetSec } : {}),
|
|
60
|
+
})
|
|
61
|
+
: {
|
|
62
|
+
version: 3,
|
|
63
|
+
sourceText: args.script.sourceText,
|
|
64
|
+
duration: args.durationSec,
|
|
65
|
+
bookmarks: [],
|
|
66
|
+
blocks: [],
|
|
67
|
+
generator: { name: 'squisq-teleprompter', method: 'dsp-align', baseWpm: args.baseWpm },
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
audioRelativeName: `audio/${buildFilename('audio', args.audioExt)}`,
|
|
72
|
+
cameraRelativeName: args.cameraExt
|
|
73
|
+
? `video/${buildFilename('video', args.cameraExt, 'narration-cam')}`
|
|
74
|
+
: null,
|
|
75
|
+
sidecarPayload,
|
|
76
|
+
sidecarPathFor: (savedAudioPath) => timingPathFor(savedAudioPath),
|
|
77
|
+
nextMarkdown: (currentSource, savedAudioPath, savedCameraPath) =>
|
|
78
|
+
insertNarrationPreamble(currentSource, savedAudioPath, savedCameraPath),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface ExecuteNarrationSaveDeps {
|
|
83
|
+
mediaProvider: MediaProvider;
|
|
84
|
+
container: ContentContainer | null;
|
|
85
|
+
markdownSource: string;
|
|
86
|
+
setMarkdownSource: (next: string) => void;
|
|
87
|
+
bumpMediaRevision: () => void;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface NarrationSaveResult {
|
|
91
|
+
audioPath: string;
|
|
92
|
+
cameraPath: string | null;
|
|
93
|
+
sidecarPath: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Execute a save plan: media writes, sidecar, then the single markdown write. */
|
|
97
|
+
export async function executeNarrationSave(
|
|
98
|
+
plan: NarrationSavePlan,
|
|
99
|
+
take: { audioBlob: Blob; audioMime: string; cameraBlob: Blob | null; cameraMime: string | null },
|
|
100
|
+
deps: ExecuteNarrationSaveDeps,
|
|
101
|
+
): Promise<NarrationSaveResult> {
|
|
102
|
+
const audioPath = await deps.mediaProvider.addMedia(
|
|
103
|
+
plan.audioRelativeName,
|
|
104
|
+
take.audioBlob,
|
|
105
|
+
take.audioMime,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const sidecarPath = plan.sidecarPathFor(audioPath);
|
|
109
|
+
const encoded = encodeTimingJson(plan.sidecarPayload);
|
|
110
|
+
if (deps.container) {
|
|
111
|
+
await deps.container.writeFile(sidecarPath, encoded, 'application/json');
|
|
112
|
+
} else {
|
|
113
|
+
const storedAt = await deps.mediaProvider.addMedia(sidecarPath, encoded, 'application/json');
|
|
114
|
+
if (storedAt !== sidecarPath) {
|
|
115
|
+
console.warn(
|
|
116
|
+
`Narration timing sidecar stored at "${storedAt}" instead of "${sidecarPath}"; ` +
|
|
117
|
+
'narration timing will not be discovered until it sits next to the audio file.',
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let cameraPath: string | null = null;
|
|
123
|
+
if (plan.cameraRelativeName && take.cameraBlob && take.cameraMime) {
|
|
124
|
+
cameraPath = await deps.mediaProvider.addMedia(
|
|
125
|
+
plan.cameraRelativeName,
|
|
126
|
+
take.cameraBlob,
|
|
127
|
+
take.cameraMime,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
deps.setMarkdownSource(plan.nextMarkdown(deps.markdownSource, audioPath, cameraPath));
|
|
132
|
+
deps.bumpMediaRevision();
|
|
133
|
+
return { audioPath, cameraPath, sidecarPath };
|
|
134
|
+
}
|