@bendyline/squisq-editor-react 2.0.1 → 2.2.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.
Files changed (357) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +40 -0
  3. package/README.md +10 -2
  4. package/dist/index.d.ts +683 -60
  5. package/dist/index.js +9648 -3750
  6. package/dist/monaco.js +0 -1
  7. package/dist/styles/index.css +1160 -241
  8. package/package.json +10 -6
  9. package/dist/index.js.map +0 -1
  10. package/dist/monaco.js.map +0 -1
  11. package/src/BlockCardView.tsx +0 -121
  12. package/src/BlockPreviewPanel.tsx +0 -69
  13. package/src/BlockPropertiesPopover.tsx +0 -222
  14. package/src/DocumentSettingsDialog.tsx +0 -272
  15. package/src/DropZoneOverlay.tsx +0 -137
  16. package/src/EditorContext.tsx +0 -1247
  17. package/src/EditorShell.tsx +0 -1334
  18. package/src/EmojiPicker.tsx +0 -332
  19. package/src/FolderView.tsx +0 -131
  20. package/src/Icon.tsx +0 -26
  21. package/src/ImageEditor.tsx +0 -395
  22. package/src/ImageNodeView.tsx +0 -284
  23. package/src/ImageViewer.tsx +0 -221
  24. package/src/InlineIcon.ts +0 -84
  25. package/src/InlinePreviewGutter.tsx +0 -590
  26. package/src/LinkDialog.tsx +0 -276
  27. package/src/MediaBin.tsx +0 -500
  28. package/src/MentionExtension.tsx +0 -261
  29. package/src/OutlinePanel.tsx +0 -547
  30. package/src/PlainHtmlPreview.tsx +0 -277
  31. package/src/PreviewControls.tsx +0 -1250
  32. package/src/PreviewPanel.tsx +0 -422
  33. package/src/RawEditor.tsx +0 -731
  34. package/src/RecorderEntry.tsx +0 -159
  35. package/src/StatusBar.tsx +0 -51
  36. package/src/TemplateAnnotation.ts +0 -167
  37. package/src/TemplateContentPreview.tsx +0 -56
  38. package/src/TemplatePicker.tsx +0 -1314
  39. package/src/ThemeCustomizerPanel.tsx +0 -304
  40. package/src/ThemePicker.tsx +0 -433
  41. package/src/TimelineBlockPreview.tsx +0 -37
  42. package/src/TimelineTrack.tsx +0 -671
  43. package/src/Toolbar.tsx +0 -2587
  44. package/src/Tooltip.tsx +0 -142
  45. package/src/TransitionPicker.tsx +0 -390
  46. package/src/VersionHistoryPanel.tsx +0 -359
  47. package/src/ViewMenuPanel.tsx +0 -189
  48. package/src/ViewSwitcher.tsx +0 -56
  49. package/src/WysiwygEditor.tsx +0 -792
  50. package/src/__tests__/blockProperties.test.ts +0 -92
  51. package/src/__tests__/blockPropertiesPopoverTheme.test.tsx +0 -33
  52. package/src/__tests__/blockRange.test.ts +0 -105
  53. package/src/__tests__/blockTagActivity.test.ts +0 -183
  54. package/src/__tests__/buildDocumentPreviewMarkdown.test.ts +0 -75
  55. package/src/__tests__/buildPreviewDocContent.test.ts +0 -48
  56. package/src/__tests__/buildPreviewDocTransition.test.ts +0 -92
  57. package/src/__tests__/canvasSurfaceTextEditing.test.tsx +0 -60
  58. package/src/__tests__/codeContextSectionView.test.tsx +0 -97
  59. package/src/__tests__/codeContextZoneManager.test.ts +0 -127
  60. package/src/__tests__/createShapeLayer.test.ts +0 -46
  61. package/src/__tests__/customLayoutManagerTheme.test.tsx +0 -34
  62. package/src/__tests__/detectMarkdown.test.ts +0 -73
  63. package/src/__tests__/diffContextSections.test.ts +0 -39
  64. package/src/__tests__/documentSettingsDialog.test.tsx +0 -197
  65. package/src/__tests__/drawingShapeRoundTrip.test.ts +0 -49
  66. package/src/__tests__/editorScrollHandoff.test.tsx +0 -102
  67. package/src/__tests__/editorScrollSync.test.ts +0 -65
  68. package/src/__tests__/editorShellCodeContext.test.tsx +0 -86
  69. package/src/__tests__/editorShellProps.test.tsx +0 -485
  70. package/src/__tests__/embeddedMedia.test.ts +0 -48
  71. package/src/__tests__/emojiPicker.test.tsx +0 -93
  72. package/src/__tests__/fileKind.test.ts +0 -112
  73. package/src/__tests__/headingTransition.test.ts +0 -176
  74. package/src/__tests__/imageEditAffordance.test.tsx +0 -272
  75. package/src/__tests__/imageEditModalContract.test.tsx +0 -119
  76. package/src/__tests__/imageEditorShell.test.tsx +0 -94
  77. package/src/__tests__/imageEditorState.test.ts +0 -171
  78. package/src/__tests__/inlinePreviewGutter.test.tsx +0 -62
  79. package/src/__tests__/inlinePreviewGutterAllBlocks.test.tsx +0 -103
  80. package/src/__tests__/jsonEditor.test.tsx +0 -223
  81. package/src/__tests__/layersPanel.test.tsx +0 -167
  82. package/src/__tests__/layoutChildRoundTrip.test.ts +0 -71
  83. package/src/__tests__/linkDialogDocPicker.test.tsx +0 -137
  84. package/src/__tests__/majorApiTypes.test.ts +0 -26
  85. package/src/__tests__/mediaAttachmentFlow.test.ts +0 -110
  86. package/src/__tests__/mediaBinDrop.test.tsx +0 -90
  87. package/src/__tests__/mediaReferences.test.ts +0 -82
  88. package/src/__tests__/narrationSave.test.ts +0 -148
  89. package/src/__tests__/outlinePanel.test.tsx +0 -169
  90. package/src/__tests__/outlineSource.test.ts +0 -217
  91. package/src/__tests__/plainHtmlPreview.test.tsx +0 -125
  92. package/src/__tests__/presentationMode.test.tsx +0 -290
  93. package/src/__tests__/previewControls.test.tsx +0 -540
  94. package/src/__tests__/previewPanelAudioFailure.test.tsx +0 -46
  95. package/src/__tests__/previewPanelPresentation.test.tsx +0 -126
  96. package/src/__tests__/previewPanelTransforms.test.tsx +0 -117
  97. package/src/__tests__/propertiesPanel.test.tsx +0 -69
  98. package/src/__tests__/rawEditorModelIsolation.test.ts +0 -19
  99. package/src/__tests__/recorderFormats.test.ts +0 -146
  100. package/src/__tests__/recorderMediaInsert.test.ts +0 -86
  101. package/src/__tests__/recorderTheme.test.tsx +0 -42
  102. package/src/__tests__/recorderTimingJson.test.ts +0 -41
  103. package/src/__tests__/resolveBlockVisual.test.ts +0 -43
  104. package/src/__tests__/selectionConversions.test.ts +0 -80
  105. package/src/__tests__/statusBar.test.tsx +0 -27
  106. package/src/__tests__/teleprompter.test.tsx +0 -190
  107. package/src/__tests__/templateAnnotationRoundTrip.test.ts +0 -99
  108. package/src/__tests__/templateContentPreview.test.ts +0 -101
  109. package/src/__tests__/templatePickerMetadata.test.ts +0 -32
  110. package/src/__tests__/templatePickerPortal.test.tsx +0 -62
  111. package/src/__tests__/timelineSource.test.ts +0 -134
  112. package/src/__tests__/tiptapBridge.test.ts +0 -566
  113. package/src/__tests__/tiptapBridgeConformance.test.ts +0 -47
  114. package/src/__tests__/tiptapCodeBlockRoundTrip.test.ts +0 -109
  115. package/src/__tests__/tiptapImageRoundTrip.test.ts +0 -73
  116. package/src/__tests__/toolbarSelectionConversion.test.tsx +0 -164
  117. package/src/__tests__/tooltip.test.tsx +0 -72
  118. package/src/__tests__/transformStyleId.test.ts +0 -13
  119. package/src/__tests__/transitionCatalog.test.ts +0 -64
  120. package/src/__tests__/useBlockNavigator.test.tsx +0 -67
  121. package/src/__tests__/useImageEditor.test.tsx +0 -226
  122. package/src/__tests__/useJsonEditorTokens.test.ts +0 -59
  123. package/src/__tests__/useMediaRecorder.test.ts +0 -302
  124. package/src/__tests__/useTimelineClock.test.ts +0 -21
  125. package/src/__tests__/versionHistory.test.tsx +0 -197
  126. package/src/__tests__/viewMenuPanel.test.tsx +0 -130
  127. package/src/__tests__/wysiwygImageUpload.test.ts +0 -69
  128. package/src/__tests__/wysiwygTemplateBadgeFocus.test.tsx +0 -56
  129. package/src/asciiDiagram/AsciiDiagramExtension.ts +0 -343
  130. package/src/asciiDiagram/AsciiDiagramWidget.tsx +0 -254
  131. package/src/asciiDiagram/RepairableDiagramExtension.ts +0 -200
  132. package/src/asciiDiagram/__tests__/AsciiDiagramExtension.test.ts +0 -145
  133. package/src/asciiDiagram/__tests__/RepairableDiagramExtension.test.ts +0 -159
  134. package/src/asciiDiagram/__tests__/asciiDiagramCommands.test.ts +0 -284
  135. package/src/asciiDiagram/__tests__/asciiDiagramOps.test.ts +0 -114
  136. package/src/asciiDiagram/__tests__/asciiPaste.test.ts +0 -43
  137. package/src/asciiDiagram/asciiDiagramCommands.ts +0 -174
  138. package/src/asciiDiagram/asciiDiagramData.ts +0 -149
  139. package/src/asciiDiagram/asciiDiagramOps.ts +0 -238
  140. package/src/asciiDiagram/asciiPaste.ts +0 -19
  141. package/src/blockProperties.ts +0 -88
  142. package/src/blockRange.ts +0 -132
  143. package/src/blockSlice.ts +0 -75
  144. package/src/blockTagActivity.ts +0 -233
  145. package/src/buildDocumentPreviewMarkdown.ts +0 -168
  146. package/src/buildPreviewDoc.ts +0 -405
  147. package/src/codeContext/CodeContextSectionView.tsx +0 -124
  148. package/src/codeContext/CodeContextZoneManager.ts +0 -149
  149. package/src/codeContext/CodeContextZones.tsx +0 -121
  150. package/src/codeContext/diffContextSections.ts +0 -38
  151. package/src/codeContext/types.ts +0 -75
  152. package/src/customTemplates/AddBin.tsx +0 -126
  153. package/src/customTemplates/CustomLayoutManager.tsx +0 -234
  154. package/src/customTemplates/CustomTemplateContext.tsx +0 -188
  155. package/src/customTemplates/LayerToolbar.tsx +0 -580
  156. package/src/customTemplates/ShapeGlyph.tsx +0 -47
  157. package/src/customTemplates/TemplateDesigner.tsx +0 -433
  158. package/src/customTemplates/__tests__/library.test.ts +0 -96
  159. package/src/customTemplates/__tests__/normalizePositions.test.ts +0 -109
  160. package/src/customTemplates/__tests__/shapeDefs.test.ts +0 -49
  161. package/src/customTemplates/__tests__/useMemoryLayerAdapter.test.ts +0 -108
  162. package/src/customTemplates/designer.css +0 -732
  163. package/src/customTemplates/index.ts +0 -31
  164. package/src/customTemplates/library.ts +0 -110
  165. package/src/customTemplates/normalizePositions.ts +0 -75
  166. package/src/customTemplates/shapeDefs.ts +0 -131
  167. package/src/customTemplates/thumbnail.tsx +0 -63
  168. package/src/customTemplates/tokenDefs.ts +0 -60
  169. package/src/customTemplates/useDocCustomTemplates.ts +0 -52
  170. package/src/customTemplates/useMemoryLayerAdapter.ts +0 -129
  171. package/src/customThemes/CustomThemeContext.tsx +0 -185
  172. package/src/customThemes/CustomThemeDialog.tsx +0 -316
  173. package/src/customThemes/ImportThemeSection.tsx +0 -178
  174. package/src/customThemes/__tests__/CustomThemeContext.test.tsx +0 -64
  175. package/src/customThemes/__tests__/CustomThemeDialog.test.tsx +0 -47
  176. package/src/customThemes/__tests__/customThemeLibrary.test.ts +0 -60
  177. package/src/customThemes/__tests__/importThemeSection.test.tsx +0 -192
  178. package/src/customThemes/customThemeLibrary.ts +0 -100
  179. package/src/customThemes/index.ts +0 -37
  180. package/src/customThemes/themeControls.tsx +0 -229
  181. package/src/customThemes/themeDraft.ts +0 -288
  182. package/src/customThemes/useDocCustomThemes.ts +0 -49
  183. package/src/detectMarkdown.ts +0 -62
  184. package/src/diagram/DiagramCanvas.tsx +0 -259
  185. package/src/diagram/DiagramMaximizedOverlay.tsx +0 -46
  186. package/src/diagram/diagramCommands.ts +0 -604
  187. package/src/diagram/diagramConstants.ts +0 -17
  188. package/src/diagram/types.ts +0 -35
  189. package/src/editorScrollSync.ts +0 -73
  190. package/src/embeddedMedia.ts +0 -78
  191. package/src/emojiData.ts +0 -1317
  192. package/src/fileKind.ts +0 -158
  193. package/src/frontmatter.ts +0 -29
  194. package/src/frontmatterSettings.ts +0 -23
  195. package/src/headingTransition.ts +0 -291
  196. package/src/hooks/useFileDrop.ts +0 -266
  197. package/src/imageEditor/CanvasSurface.tsx +0 -703
  198. package/src/imageEditor/ImageVersionHistoryDropdown.tsx +0 -396
  199. package/src/imageEditor/LayersPanel.tsx +0 -218
  200. package/src/imageEditor/PropertiesPanel.tsx +0 -474
  201. package/src/imageEditor/Toolbar.tsx +0 -459
  202. package/src/imageEditor/createShapeLayer.ts +0 -280
  203. package/src/imageEditor/icons.tsx +0 -68
  204. package/src/imageEditor/image-editor.css +0 -574
  205. package/src/imageEditor/layers/EditorImageLayer.tsx +0 -45
  206. package/src/imageEditor/layers/EditorShapeLayer.tsx +0 -62
  207. package/src/imageEditor/layers/EditorTextLayer.tsx +0 -45
  208. package/src/imageEditor/layers/SelectionHandles.tsx +0 -86
  209. package/src/imageEditor/state.ts +0 -173
  210. package/src/imageEditor/useImageEditor.ts +0 -385
  211. package/src/imageEditor/useImageEditorTokens.ts +0 -70
  212. package/src/index.ts +0 -470
  213. package/src/jsonEditor/EmbeddedRichTextField.tsx +0 -81
  214. package/src/jsonEditor/JsonEditor.tsx +0 -81
  215. package/src/jsonEditor/JsonEditorContext.tsx +0 -81
  216. package/src/jsonEditor/RenderNode.tsx +0 -87
  217. package/src/jsonEditor/editors.tsx +0 -745
  218. package/src/jsonEditor/index.ts +0 -2
  219. package/src/jsonEditor/json-editor.css +0 -463
  220. package/src/jsonEditor/useJsonEditorTokens.ts +0 -33
  221. package/src/mediaDragMime.ts +0 -32
  222. package/src/mediaEntries.ts +0 -12
  223. package/src/mediaReferences.ts +0 -299
  224. package/src/monaco.ts +0 -35
  225. package/src/monacoWorkers.ts +0 -89
  226. package/src/outlineSource.ts +0 -171
  227. package/src/presentation/PresentationMode.tsx +0 -596
  228. package/src/rawEditorIsolation.ts +0 -18
  229. package/src/recorder/RecorderButton.tsx +0 -80
  230. package/src/recorder/RecorderModal.tsx +0 -706
  231. package/src/recorder/RecorderPanel.tsx +0 -77
  232. package/src/recorder/formats.ts +0 -159
  233. package/src/recorder/hooks/useMediaRecorder.ts +0 -436
  234. package/src/recorder/hooks/useStreamPreview.ts +0 -47
  235. package/src/recorder/insertMediaBlock.ts +0 -30
  236. package/src/recorder/sources/cameraStream.ts +0 -32
  237. package/src/recorder/sources/micStream.ts +0 -25
  238. package/src/recorder/sources/screenStream.ts +0 -162
  239. package/src/recorder/timingJson.ts +0 -66
  240. package/src/resolveBlockVisual.ts +0 -39
  241. package/src/scene/Scene.tsx +0 -616
  242. package/src/scene/SceneBlockExtension.ts +0 -205
  243. package/src/scene/SceneBlockToolbar.tsx +0 -201
  244. package/src/scene/SceneBlockWidget.tsx +0 -441
  245. package/src/scene/ScenePropsBar.tsx +0 -85
  246. package/src/scene/SceneSelection.tsx +0 -111
  247. package/src/scene/SceneSideToolbar.tsx +0 -89
  248. package/src/scene/SceneViewport.tsx +0 -106
  249. package/src/scene/ShapePalette.tsx +0 -196
  250. package/src/scene/__tests__/DiagramAdapter.test.ts +0 -142
  251. package/src/scene/__tests__/SceneBlockExtension.test.ts +0 -33
  252. package/src/scene/__tests__/bezierEdit.test.ts +0 -85
  253. package/src/scene/__tests__/blockLayers.test.ts +0 -57
  254. package/src/scene/__tests__/sceneIsolation.test.tsx +0 -119
  255. package/src/scene/__tests__/shapeLayers.test.ts +0 -106
  256. package/src/scene/__tests__/useSceneHitTest.test.ts +0 -90
  257. package/src/scene/__tests__/useScenePanZoom.test.ts +0 -103
  258. package/src/scene/adapters/DiagramAdapter.ts +0 -79
  259. package/src/scene/adapters/DrawingAdapter.ts +0 -420
  260. package/src/scene/adapters/LayoutAdapter.ts +0 -313
  261. package/src/scene/adapters/blockLayers.ts +0 -159
  262. package/src/scene/commands/SceneCommand.ts +0 -84
  263. package/src/scene/commands/drawingCommands.ts +0 -318
  264. package/src/scene/commands/layoutCommands.ts +0 -301
  265. package/src/scene/hooks/useSceneHitTest.ts +0 -105
  266. package/src/scene/hooks/useScenePanZoom.ts +0 -147
  267. package/src/scene/hooks/useSceneSelection.ts +0 -62
  268. package/src/scene/index.ts +0 -90
  269. package/src/scene/layers/DiagramEdges.tsx +0 -142
  270. package/src/scene/layers/edgeGeometry.ts +0 -104
  271. package/src/scene/layers/nodeCard.tsx +0 -164
  272. package/src/scene/layers/renderLayer.tsx +0 -70
  273. package/src/scene/layers/shapeLayers.ts +0 -201
  274. package/src/scene/paths/bezierEdit.ts +0 -208
  275. package/src/scene/scene.css +0 -792
  276. package/src/scene/text/SceneTextOverlay.tsx +0 -161
  277. package/src/scene/text/sceneTextChannel.ts +0 -46
  278. package/src/scene/text/sceneTextConfig.ts +0 -31
  279. package/src/scene/text/sceneTiptap.ts +0 -36
  280. package/src/scene/text/useSceneTextEditing.ts +0 -39
  281. package/src/scene/tools/ConnectTool.ts +0 -209
  282. package/src/scene/tools/DrawingConnectTool.ts +0 -231
  283. package/src/scene/tools/PathTool.ts +0 -158
  284. package/src/scene/tools/PlaceTool.ts +0 -47
  285. package/src/scene/tools/SceneTool.ts +0 -85
  286. package/src/scene/tools/SelectTool.ts +0 -300
  287. package/src/scene/tools/ShapeTool.ts +0 -143
  288. package/src/scene/tools/TextTool.ts +0 -72
  289. package/src/scene/tools/TokenTool.ts +0 -95
  290. package/src/scene/tools/createDrawShapeTool.ts +0 -82
  291. package/src/selectionConversions.ts +0 -155
  292. package/src/styles/ascii-diagram.css +0 -79
  293. package/src/styles/ascii-timeline.css +0 -596
  294. package/src/styles/code-context.css +0 -155
  295. package/src/styles/diagram.css +0 -183
  296. package/src/styles/editor.css +0 -6811
  297. package/src/styles/folder-view.css +0 -210
  298. package/src/styles/image-edit-affordance.css +0 -201
  299. package/src/styles/index.css +0 -18
  300. package/src/styles/tree-view.css +0 -189
  301. package/src/teleprompter/TeleprompterControls.tsx +0 -218
  302. package/src/teleprompter/TeleprompterSelfView.tsx +0 -22
  303. package/src/teleprompter/TeleprompterSurface.tsx +0 -267
  304. package/src/teleprompter/TeleprompterView.tsx +0 -338
  305. package/src/teleprompter/canvasRenderer.ts +0 -161
  306. package/src/teleprompter/floatingWindow.ts +0 -352
  307. package/src/teleprompter/index.ts +0 -61
  308. package/src/teleprompter/pcmWorklet.ts +0 -62
  309. package/src/teleprompter/recording/insertPreamble.ts +0 -80
  310. package/src/teleprompter/recording/narrationSave.ts +0 -134
  311. package/src/teleprompter/recording/useNarrationRecorder.ts +0 -367
  312. package/src/teleprompter/scrollModel.ts +0 -85
  313. package/src/teleprompter/teleprompterTheme.ts +0 -303
  314. package/src/teleprompter/types.ts +0 -38
  315. package/src/teleprompter/useFloatingWindow.ts +0 -74
  316. package/src/teleprompter/useMicAnalysis.ts +0 -211
  317. package/src/teleprompter/useTeleprompter.ts +0 -421
  318. package/src/templateContentPreviewResolver.ts +0 -360
  319. package/src/timeline/TimelineEditorWidget.tsx +0 -861
  320. package/src/timeline/TimelineViewExtension.ts +0 -252
  321. package/src/timeline/__tests__/TimelineEditorWidget.test.tsx +0 -414
  322. package/src/timeline/__tests__/TimelineViewExtension.test.ts +0 -163
  323. package/src/timeline/__tests__/timelineCommands.test.ts +0 -359
  324. package/src/timeline/__tests__/timelineOps.test.ts +0 -277
  325. package/src/timeline/__tests__/timelinePaste.test.ts +0 -34
  326. package/src/timeline/timelineCommands.ts +0 -421
  327. package/src/timeline/timelineData.ts +0 -54
  328. package/src/timeline/timelineOps.ts +0 -381
  329. package/src/timeline/timelinePaste.ts +0 -8
  330. package/src/timelineSource.ts +0 -244
  331. package/src/tiptap/TiptapAudio.tsx +0 -86
  332. package/src/tiptap/TiptapVideo.tsx +0 -119
  333. package/src/tiptap/useResolvedMediaSrc.ts +0 -47
  334. package/src/tiptapBridge.ts +0 -986
  335. package/src/tooltipPlacement.ts +0 -13
  336. package/src/transformStyleId.ts +0 -17
  337. package/src/transitionCatalog.ts +0 -159
  338. package/src/treeview/TreeOutlineWidget.tsx +0 -390
  339. package/src/treeview/TreeViewExtension.ts +0 -250
  340. package/src/treeview/__tests__/TreeOutlineWidget.test.tsx +0 -156
  341. package/src/treeview/__tests__/TreeViewExtension.test.ts +0 -122
  342. package/src/treeview/__tests__/treeOps.test.ts +0 -177
  343. package/src/treeview/__tests__/treePaste.test.ts +0 -40
  344. package/src/treeview/__tests__/treeViewCommands.test.ts +0 -179
  345. package/src/treeview/treeOps.ts +0 -231
  346. package/src/treeview/treePaste.ts +0 -13
  347. package/src/treeview/treeViewCommands.ts +0 -99
  348. package/src/treeview/treeViewData.ts +0 -41
  349. package/src/types/monaco-shims.d.ts +0 -10
  350. package/src/useBlockNavigator.ts +0 -153
  351. package/src/useHeadingLayout.ts +0 -294
  352. package/src/useMonacoLoader.ts +0 -82
  353. package/src/useTimelineClock.ts +0 -76
  354. package/src/utils/collectInlineFontAwesomeCss.ts +0 -69
  355. package/src/utils/dropUtils.ts +0 -136
  356. package/src/utils/normalizeMalformedAssetUrl.ts +0 -22
  357. package/src/wysiwygImageUpload.ts +0 -113
@@ -1,352 +0,0 @@
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
- }
@@ -1,61 +0,0 @@
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';
@@ -1,62 +0,0 @@
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
- }
@@ -1,80 +0,0 @@
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
- }
@@ -1,134 +0,0 @@
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
- }