@bendyline/squisq-editor-react 2.1.0 → 2.3.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 (415) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +40 -0
  3. package/dist/chunk-54UGTQBO.js +862 -0
  4. package/dist/chunk-5JMHFAVW.js +2408 -0
  5. package/dist/chunk-5Q4JN4I5.js +132 -0
  6. package/dist/chunk-6VDYKI3L.js +49 -0
  7. package/dist/chunk-GS7QWYFT.js +9 -0
  8. package/dist/chunk-MJJK7YQB.js +949 -0
  9. package/dist/chunk-NITZVAXL.js +986 -0
  10. package/dist/chunk-TRCKHRBS.js +35234 -0
  11. package/dist/chunk-V44VP242.js +3256 -0
  12. package/dist/image-editor/index.d.ts +223 -0
  13. package/dist/image-editor/index.js +15 -0
  14. package/dist/index.d.ts +2060 -4040
  15. package/dist/index.js +496 -40014
  16. package/dist/json-editor/index.d.ts +27 -0
  17. package/dist/json-editor/index.js +7 -0
  18. package/dist/monaco.d.ts +1 -1
  19. package/dist/monaco.js +1 -2
  20. package/dist/recorder/index.d.ts +407 -0
  21. package/dist/recorder/index.js +43 -0
  22. package/dist/shell/index.d.ts +9 -0
  23. package/dist/shell/index.js +22 -0
  24. package/dist/shell-BxSCBm4H.d.ts +1064 -0
  25. package/dist/styles/index.css +598 -161
  26. package/dist/teleprompter/index.d.ts +497 -0
  27. package/dist/teleprompter/index.js +57 -0
  28. package/package.json +34 -8
  29. package/dist/index.js.map +0 -1
  30. package/dist/monaco.js.map +0 -1
  31. package/src/BlockCardView.tsx +0 -121
  32. package/src/BlockPreviewPanel.tsx +0 -69
  33. package/src/BlockPropertiesPopover.tsx +0 -222
  34. package/src/DocumentSettingsDialog.tsx +0 -272
  35. package/src/DropZoneOverlay.tsx +0 -137
  36. package/src/EditorContext.tsx +0 -1274
  37. package/src/EditorShell.tsx +0 -1358
  38. package/src/EmojiPicker.tsx +0 -332
  39. package/src/FolderView.tsx +0 -131
  40. package/src/Icon.tsx +0 -26
  41. package/src/ImageEditor.tsx +0 -395
  42. package/src/ImageNodeView.tsx +0 -284
  43. package/src/ImageViewer.tsx +0 -221
  44. package/src/InlineIcon.ts +0 -84
  45. package/src/InlinePreviewGutter.tsx +0 -590
  46. package/src/LinkDialog.tsx +0 -276
  47. package/src/MediaBin.tsx +0 -500
  48. package/src/MentionExtension.tsx +0 -261
  49. package/src/OutlinePanel.tsx +0 -547
  50. package/src/PlainHtmlPreview.tsx +0 -277
  51. package/src/PreviewControls.tsx +0 -1265
  52. package/src/PreviewPanel.tsx +0 -426
  53. package/src/RawEditor.tsx +0 -743
  54. package/src/RecorderEntry.tsx +0 -162
  55. package/src/StatusBar.tsx +0 -51
  56. package/src/TemplateAnnotation.ts +0 -167
  57. package/src/TemplateContentPreview.tsx +0 -56
  58. package/src/TemplatePicker.tsx +0 -1314
  59. package/src/ThemeCustomizerPanel.tsx +0 -304
  60. package/src/ThemePicker.tsx +0 -433
  61. package/src/TimelineBlockPreview.tsx +0 -37
  62. package/src/TimelineTrack.tsx +0 -671
  63. package/src/Toolbar.tsx +0 -2885
  64. package/src/Tooltip.tsx +0 -142
  65. package/src/TransitionPicker.tsx +0 -390
  66. package/src/VersionHistoryPanel.tsx +0 -359
  67. package/src/ViewMenuPanel.tsx +0 -189
  68. package/src/ViewSwitcher.tsx +0 -56
  69. package/src/WysiwygEditor.tsx +0 -806
  70. package/src/__tests__/blockProperties.test.ts +0 -92
  71. package/src/__tests__/blockPropertiesPopoverTheme.test.tsx +0 -33
  72. package/src/__tests__/blockRange.test.ts +0 -105
  73. package/src/__tests__/blockTagActivity.test.ts +0 -183
  74. package/src/__tests__/buildDocumentPreviewMarkdown.test.ts +0 -75
  75. package/src/__tests__/buildPreviewDocContent.test.ts +0 -65
  76. package/src/__tests__/buildPreviewDocTransition.test.ts +0 -92
  77. package/src/__tests__/canvasSurfaceTextEditing.test.tsx +0 -60
  78. package/src/__tests__/codeContextSectionView.test.tsx +0 -97
  79. package/src/__tests__/codeContextZoneManager.test.ts +0 -127
  80. package/src/__tests__/createShapeLayer.test.ts +0 -46
  81. package/src/__tests__/customLayoutManagerTheme.test.tsx +0 -34
  82. package/src/__tests__/detectMarkdown.test.ts +0 -73
  83. package/src/__tests__/diffContextSections.test.ts +0 -39
  84. package/src/__tests__/documentSettingsDialog.test.tsx +0 -197
  85. package/src/__tests__/drawingShapeRoundTrip.test.ts +0 -49
  86. package/src/__tests__/editorScrollHandoff.test.tsx +0 -102
  87. package/src/__tests__/editorScrollSync.test.ts +0 -65
  88. package/src/__tests__/editorShellCodeContext.test.tsx +0 -86
  89. package/src/__tests__/editorShellProps.test.tsx +0 -550
  90. package/src/__tests__/embeddedMedia.test.ts +0 -48
  91. package/src/__tests__/emojiPicker.test.tsx +0 -93
  92. package/src/__tests__/fileKind.test.ts +0 -112
  93. package/src/__tests__/findMode.test.tsx +0 -104
  94. package/src/__tests__/findModel.test.ts +0 -55
  95. package/src/__tests__/headingTransition.test.ts +0 -176
  96. package/src/__tests__/imageEditAffordance.test.tsx +0 -272
  97. package/src/__tests__/imageEditModalContract.test.tsx +0 -119
  98. package/src/__tests__/imageEditorShell.test.tsx +0 -94
  99. package/src/__tests__/imageEditorState.test.ts +0 -171
  100. package/src/__tests__/inlinePreviewGutter.test.tsx +0 -62
  101. package/src/__tests__/inlinePreviewGutterAllBlocks.test.tsx +0 -103
  102. package/src/__tests__/jsonEditor.test.tsx +0 -223
  103. package/src/__tests__/layersPanel.test.tsx +0 -167
  104. package/src/__tests__/layoutChildRoundTrip.test.ts +0 -71
  105. package/src/__tests__/linkDialogDocPicker.test.tsx +0 -137
  106. package/src/__tests__/majorApiTypes.test.ts +0 -26
  107. package/src/__tests__/markdownCodeFence.test.ts +0 -45
  108. package/src/__tests__/mediaAttachmentFlow.test.ts +0 -110
  109. package/src/__tests__/mediaBinDrop.test.tsx +0 -90
  110. package/src/__tests__/mediaReferences.test.ts +0 -97
  111. package/src/__tests__/narrationSave.test.ts +0 -148
  112. package/src/__tests__/outlinePanel.test.tsx +0 -169
  113. package/src/__tests__/outlineSource.test.ts +0 -217
  114. package/src/__tests__/plainHtmlPreview.test.tsx +0 -125
  115. package/src/__tests__/presentationMode.test.tsx +0 -290
  116. package/src/__tests__/previewControls.test.tsx +0 -571
  117. package/src/__tests__/previewPanelAudioFailure.test.tsx +0 -46
  118. package/src/__tests__/previewPanelPresentation.test.tsx +0 -126
  119. package/src/__tests__/previewPanelTransforms.test.tsx +0 -117
  120. package/src/__tests__/propertiesPanel.test.tsx +0 -69
  121. package/src/__tests__/rawEditorModelIsolation.test.ts +0 -19
  122. package/src/__tests__/recorderFormats.test.ts +0 -146
  123. package/src/__tests__/recorderMediaInsert.test.ts +0 -86
  124. package/src/__tests__/recorderTheme.test.tsx +0 -42
  125. package/src/__tests__/recorderTimingJson.test.ts +0 -41
  126. package/src/__tests__/resolveBlockVisual.test.ts +0 -43
  127. package/src/__tests__/selectionConversions.test.ts +0 -80
  128. package/src/__tests__/statusBar.test.tsx +0 -27
  129. package/src/__tests__/teleprompter.test.tsx +0 -190
  130. package/src/__tests__/templateAnnotationRoundTrip.test.ts +0 -99
  131. package/src/__tests__/templateContentPreview.test.ts +0 -101
  132. package/src/__tests__/templatePickerMetadata.test.ts +0 -32
  133. package/src/__tests__/templatePickerPortal.test.tsx +0 -62
  134. package/src/__tests__/timelineSource.test.ts +0 -134
  135. package/src/__tests__/tiptapBridge.test.ts +0 -575
  136. package/src/__tests__/tiptapBridgeConformance.test.ts +0 -47
  137. package/src/__tests__/tiptapCodeBlockRoundTrip.test.ts +0 -109
  138. package/src/__tests__/tiptapImageRoundTrip.test.ts +0 -73
  139. package/src/__tests__/toolbarSelectionConversion.test.tsx +0 -190
  140. package/src/__tests__/tooltip.test.tsx +0 -72
  141. package/src/__tests__/transformStyleId.test.ts +0 -13
  142. package/src/__tests__/transitionCatalog.test.ts +0 -64
  143. package/src/__tests__/useBlockNavigator.test.tsx +0 -67
  144. package/src/__tests__/useImageEditor.test.tsx +0 -226
  145. package/src/__tests__/useJsonEditorTokens.test.ts +0 -59
  146. package/src/__tests__/useMediaRecorder.test.ts +0 -302
  147. package/src/__tests__/useTimelineClock.test.ts +0 -21
  148. package/src/__tests__/versionHistory.test.tsx +0 -197
  149. package/src/__tests__/viewMenuPanel.test.tsx +0 -130
  150. package/src/__tests__/writeCanvasSettings.test.ts +0 -15
  151. package/src/__tests__/wysiwygImageUpload.test.ts +0 -69
  152. package/src/__tests__/wysiwygTemplateBadgeFocus.test.tsx +0 -56
  153. package/src/asciiDiagram/AsciiDiagramExtension.ts +0 -343
  154. package/src/asciiDiagram/AsciiDiagramWidget.tsx +0 -254
  155. package/src/asciiDiagram/RepairableDiagramExtension.ts +0 -200
  156. package/src/asciiDiagram/__tests__/AsciiDiagramExtension.test.ts +0 -164
  157. package/src/asciiDiagram/__tests__/RepairableDiagramExtension.test.ts +0 -159
  158. package/src/asciiDiagram/__tests__/asciiDiagramCommands.test.ts +0 -284
  159. package/src/asciiDiagram/__tests__/asciiDiagramOps.test.ts +0 -114
  160. package/src/asciiDiagram/__tests__/asciiPaste.test.ts +0 -43
  161. package/src/asciiDiagram/asciiDiagramCommands.ts +0 -174
  162. package/src/asciiDiagram/asciiDiagramData.ts +0 -149
  163. package/src/asciiDiagram/asciiDiagramOps.ts +0 -238
  164. package/src/asciiDiagram/asciiPaste.ts +0 -19
  165. package/src/blockProperties.ts +0 -88
  166. package/src/blockRange.ts +0 -132
  167. package/src/blockSlice.ts +0 -75
  168. package/src/blockTagActivity.ts +0 -233
  169. package/src/buildDocumentPreviewMarkdown.ts +0 -168
  170. package/src/buildPreviewDoc.ts +0 -407
  171. package/src/codeContext/CodeContextSectionView.tsx +0 -124
  172. package/src/codeContext/CodeContextZoneManager.ts +0 -149
  173. package/src/codeContext/CodeContextZones.tsx +0 -121
  174. package/src/codeContext/diffContextSections.ts +0 -38
  175. package/src/codeContext/types.ts +0 -75
  176. package/src/codeSnippet/CodeSnippetExtension.ts +0 -205
  177. package/src/codeSnippet/CodeSnippetWidget.tsx +0 -109
  178. package/src/codeSnippet/__tests__/CodeSnippetExtension.test.ts +0 -95
  179. package/src/codeSnippet/__tests__/codeSnippetLanguages.test.ts +0 -50
  180. package/src/codeSnippet/codeSnippetCommands.ts +0 -21
  181. package/src/codeSnippet/codeSnippetData.ts +0 -43
  182. package/src/codeSnippet/codeSnippetLanguages.ts +0 -216
  183. package/src/customTemplates/AddBin.tsx +0 -126
  184. package/src/customTemplates/CustomLayoutManager.tsx +0 -234
  185. package/src/customTemplates/CustomTemplateContext.tsx +0 -188
  186. package/src/customTemplates/LayerToolbar.tsx +0 -580
  187. package/src/customTemplates/ShapeGlyph.tsx +0 -47
  188. package/src/customTemplates/TemplateDesigner.tsx +0 -433
  189. package/src/customTemplates/__tests__/library.test.ts +0 -96
  190. package/src/customTemplates/__tests__/normalizePositions.test.ts +0 -109
  191. package/src/customTemplates/__tests__/shapeDefs.test.ts +0 -49
  192. package/src/customTemplates/__tests__/useMemoryLayerAdapter.test.ts +0 -108
  193. package/src/customTemplates/designer.css +0 -732
  194. package/src/customTemplates/index.ts +0 -31
  195. package/src/customTemplates/library.ts +0 -110
  196. package/src/customTemplates/normalizePositions.ts +0 -75
  197. package/src/customTemplates/shapeDefs.ts +0 -131
  198. package/src/customTemplates/thumbnail.tsx +0 -63
  199. package/src/customTemplates/tokenDefs.ts +0 -60
  200. package/src/customTemplates/useDocCustomTemplates.ts +0 -52
  201. package/src/customTemplates/useMemoryLayerAdapter.ts +0 -129
  202. package/src/customThemes/CustomThemeContext.tsx +0 -185
  203. package/src/customThemes/CustomThemeDialog.tsx +0 -316
  204. package/src/customThemes/ImportThemeSection.tsx +0 -178
  205. package/src/customThemes/__tests__/CustomThemeContext.test.tsx +0 -64
  206. package/src/customThemes/__tests__/CustomThemeDialog.test.tsx +0 -47
  207. package/src/customThemes/__tests__/customThemeLibrary.test.ts +0 -60
  208. package/src/customThemes/__tests__/importThemeSection.test.tsx +0 -192
  209. package/src/customThemes/customThemeLibrary.ts +0 -100
  210. package/src/customThemes/index.ts +0 -37
  211. package/src/customThemes/themeControls.tsx +0 -229
  212. package/src/customThemes/themeDraft.ts +0 -288
  213. package/src/customThemes/useDocCustomThemes.ts +0 -49
  214. package/src/detectMarkdown.ts +0 -62
  215. package/src/diagram/DiagramCanvas.tsx +0 -260
  216. package/src/diagram/DiagramMaximizedOverlay.tsx +0 -46
  217. package/src/diagram/diagramCommands.ts +0 -604
  218. package/src/diagram/diagramConstants.ts +0 -17
  219. package/src/diagram/types.ts +0 -35
  220. package/src/editorScrollSync.ts +0 -73
  221. package/src/embeddedMedia.ts +0 -78
  222. package/src/emojiData.ts +0 -1317
  223. package/src/fileKind.ts +0 -158
  224. package/src/find/FindHighlightExtension.ts +0 -81
  225. package/src/find/FindToolbar.tsx +0 -314
  226. package/src/find/findModel.ts +0 -77
  227. package/src/frontmatter.ts +0 -29
  228. package/src/frontmatterSettings.ts +0 -23
  229. package/src/headingTransition.ts +0 -291
  230. package/src/hooks/useFileDrop.ts +0 -266
  231. package/src/imageEditor/CanvasSurface.tsx +0 -703
  232. package/src/imageEditor/ImageVersionHistoryDropdown.tsx +0 -396
  233. package/src/imageEditor/LayersPanel.tsx +0 -218
  234. package/src/imageEditor/PropertiesPanel.tsx +0 -474
  235. package/src/imageEditor/Toolbar.tsx +0 -459
  236. package/src/imageEditor/createShapeLayer.ts +0 -280
  237. package/src/imageEditor/icons.tsx +0 -68
  238. package/src/imageEditor/image-editor.css +0 -574
  239. package/src/imageEditor/layers/EditorImageLayer.tsx +0 -45
  240. package/src/imageEditor/layers/EditorShapeLayer.tsx +0 -62
  241. package/src/imageEditor/layers/EditorTextLayer.tsx +0 -45
  242. package/src/imageEditor/layers/SelectionHandles.tsx +0 -86
  243. package/src/imageEditor/state.ts +0 -173
  244. package/src/imageEditor/useImageEditor.ts +0 -385
  245. package/src/imageEditor/useImageEditorTokens.ts +0 -70
  246. package/src/index.ts +0 -559
  247. package/src/jsonEditor/EmbeddedRichTextField.tsx +0 -81
  248. package/src/jsonEditor/JsonEditor.tsx +0 -81
  249. package/src/jsonEditor/JsonEditorContext.tsx +0 -81
  250. package/src/jsonEditor/RenderNode.tsx +0 -87
  251. package/src/jsonEditor/editors.tsx +0 -745
  252. package/src/jsonEditor/index.ts +0 -2
  253. package/src/jsonEditor/json-editor.css +0 -463
  254. package/src/jsonEditor/useJsonEditorTokens.ts +0 -33
  255. package/src/markdownCodeFence.ts +0 -72
  256. package/src/mediaDragMime.ts +0 -32
  257. package/src/mediaEntries.ts +0 -12
  258. package/src/mediaReferences.ts +0 -301
  259. package/src/mermaid/MermaidDiagramCanvas.tsx +0 -693
  260. package/src/mermaid/MermaidDiagramExtension.ts +0 -243
  261. package/src/mermaid/MermaidDiagramTypeThumbnail.tsx +0 -184
  262. package/src/mermaid/MermaidDiagramWidget.tsx +0 -653
  263. package/src/mermaid/MermaidShapePalette.tsx +0 -245
  264. package/src/mermaid/__tests__/MermaidDiagramExtension.test.ts +0 -361
  265. package/src/mermaid/__tests__/mermaidDiagramTypes.test.ts +0 -35
  266. package/src/mermaid/__tests__/mermaidRenderer.test.ts +0 -49
  267. package/src/mermaid/__tests__/mermaidSourceOps.test.ts +0 -213
  268. package/src/mermaid/__tests__/mermaidSyntax.test.ts +0 -71
  269. package/src/mermaid/mermaidCommands.ts +0 -34
  270. package/src/mermaid/mermaidData.ts +0 -31
  271. package/src/mermaid/mermaidDiagramTypes.ts +0 -325
  272. package/src/mermaid/mermaidModel.ts +0 -31
  273. package/src/mermaid/mermaidRenderer.ts +0 -181
  274. package/src/mermaid/mermaidShapes.ts +0 -113
  275. package/src/mermaid/mermaidSourceOps.ts +0 -454
  276. package/src/monaco.ts +0 -35
  277. package/src/monacoWorkers.ts +0 -89
  278. package/src/outlineSource.ts +0 -171
  279. package/src/presentation/PresentationMode.tsx +0 -596
  280. package/src/rawEditorIsolation.ts +0 -18
  281. package/src/recorder/RecorderButton.tsx +0 -80
  282. package/src/recorder/RecorderModal.tsx +0 -706
  283. package/src/recorder/RecorderPanel.tsx +0 -77
  284. package/src/recorder/formats.ts +0 -159
  285. package/src/recorder/hooks/useMediaRecorder.ts +0 -436
  286. package/src/recorder/hooks/useStreamPreview.ts +0 -47
  287. package/src/recorder/insertMediaBlock.ts +0 -30
  288. package/src/recorder/sources/cameraStream.ts +0 -32
  289. package/src/recorder/sources/micStream.ts +0 -25
  290. package/src/recorder/sources/screenStream.ts +0 -162
  291. package/src/recorder/timingJson.ts +0 -66
  292. package/src/resolveBlockVisual.ts +0 -39
  293. package/src/scene/Scene.tsx +0 -647
  294. package/src/scene/SceneBlockExtension.ts +0 -205
  295. package/src/scene/SceneBlockToolbar.tsx +0 -216
  296. package/src/scene/SceneBlockWidget.tsx +0 -441
  297. package/src/scene/ScenePropsBar.tsx +0 -85
  298. package/src/scene/SceneSelection.tsx +0 -111
  299. package/src/scene/SceneSideToolbar.tsx +0 -89
  300. package/src/scene/SceneViewControls.tsx +0 -43
  301. package/src/scene/SceneViewport.tsx +0 -106
  302. package/src/scene/ShapePalette.tsx +0 -196
  303. package/src/scene/__tests__/DiagramAdapter.test.ts +0 -142
  304. package/src/scene/__tests__/SceneBlockExtension.test.ts +0 -33
  305. package/src/scene/__tests__/bezierEdit.test.ts +0 -85
  306. package/src/scene/__tests__/blockLayers.test.ts +0 -57
  307. package/src/scene/__tests__/fitScale.test.ts +0 -19
  308. package/src/scene/__tests__/sceneIsolation.test.tsx +0 -119
  309. package/src/scene/__tests__/shapeLayers.test.ts +0 -106
  310. package/src/scene/__tests__/useSceneHitTest.test.ts +0 -90
  311. package/src/scene/__tests__/useScenePanZoom.test.ts +0 -130
  312. package/src/scene/adapters/DiagramAdapter.ts +0 -79
  313. package/src/scene/adapters/DrawingAdapter.ts +0 -420
  314. package/src/scene/adapters/LayoutAdapter.ts +0 -313
  315. package/src/scene/adapters/blockLayers.ts +0 -159
  316. package/src/scene/commands/SceneCommand.ts +0 -84
  317. package/src/scene/commands/drawingCommands.ts +0 -318
  318. package/src/scene/commands/layoutCommands.ts +0 -301
  319. package/src/scene/fitScale.ts +0 -17
  320. package/src/scene/hooks/useSceneHitTest.ts +0 -105
  321. package/src/scene/hooks/useScenePanZoom.ts +0 -154
  322. package/src/scene/hooks/useSceneSelection.ts +0 -62
  323. package/src/scene/index.ts +0 -90
  324. package/src/scene/layers/DiagramEdges.tsx +0 -142
  325. package/src/scene/layers/edgeGeometry.ts +0 -104
  326. package/src/scene/layers/nodeCard.tsx +0 -164
  327. package/src/scene/layers/renderLayer.tsx +0 -70
  328. package/src/scene/layers/shapeLayers.ts +0 -201
  329. package/src/scene/paths/bezierEdit.ts +0 -208
  330. package/src/scene/scene.css +0 -874
  331. package/src/scene/text/SceneTextOverlay.tsx +0 -161
  332. package/src/scene/text/sceneTextChannel.ts +0 -46
  333. package/src/scene/text/sceneTextConfig.ts +0 -31
  334. package/src/scene/text/sceneTiptap.ts +0 -36
  335. package/src/scene/text/useSceneTextEditing.ts +0 -39
  336. package/src/scene/tools/ConnectTool.ts +0 -209
  337. package/src/scene/tools/DrawingConnectTool.ts +0 -231
  338. package/src/scene/tools/PathTool.ts +0 -158
  339. package/src/scene/tools/PlaceTool.ts +0 -47
  340. package/src/scene/tools/SceneTool.ts +0 -85
  341. package/src/scene/tools/SelectTool.ts +0 -300
  342. package/src/scene/tools/ShapeTool.ts +0 -143
  343. package/src/scene/tools/TextTool.ts +0 -72
  344. package/src/scene/tools/TokenTool.ts +0 -95
  345. package/src/scene/tools/createDrawShapeTool.ts +0 -82
  346. package/src/selectionConversions.ts +0 -155
  347. package/src/styles/ascii-diagram.css +0 -79
  348. package/src/styles/ascii-timeline.css +0 -596
  349. package/src/styles/code-context.css +0 -155
  350. package/src/styles/code-snippet.css +0 -76
  351. package/src/styles/diagram.css +0 -183
  352. package/src/styles/editor.css +0 -7131
  353. package/src/styles/folder-view.css +0 -210
  354. package/src/styles/image-edit-affordance.css +0 -201
  355. package/src/styles/index.css +0 -20
  356. package/src/styles/mermaid-diagram.css +0 -487
  357. package/src/styles/tree-view.css +0 -189
  358. package/src/teleprompter/TeleprompterControls.tsx +0 -218
  359. package/src/teleprompter/TeleprompterSelfView.tsx +0 -22
  360. package/src/teleprompter/TeleprompterSurface.tsx +0 -267
  361. package/src/teleprompter/TeleprompterView.tsx +0 -338
  362. package/src/teleprompter/canvasRenderer.ts +0 -161
  363. package/src/teleprompter/floatingWindow.ts +0 -352
  364. package/src/teleprompter/index.ts +0 -61
  365. package/src/teleprompter/pcmWorklet.ts +0 -62
  366. package/src/teleprompter/recording/insertPreamble.ts +0 -80
  367. package/src/teleprompter/recording/narrationSave.ts +0 -134
  368. package/src/teleprompter/recording/useNarrationRecorder.ts +0 -367
  369. package/src/teleprompter/scrollModel.ts +0 -85
  370. package/src/teleprompter/teleprompterTheme.ts +0 -303
  371. package/src/teleprompter/types.ts +0 -38
  372. package/src/teleprompter/useFloatingWindow.ts +0 -74
  373. package/src/teleprompter/useMicAnalysis.ts +0 -211
  374. package/src/teleprompter/useTeleprompter.ts +0 -421
  375. package/src/templateContentPreviewResolver.ts +0 -360
  376. package/src/timeline/TimelineEditorWidget.tsx +0 -861
  377. package/src/timeline/TimelineViewExtension.ts +0 -252
  378. package/src/timeline/__tests__/TimelineEditorWidget.test.tsx +0 -414
  379. package/src/timeline/__tests__/TimelineViewExtension.test.ts +0 -163
  380. package/src/timeline/__tests__/timelineCommands.test.ts +0 -359
  381. package/src/timeline/__tests__/timelineOps.test.ts +0 -277
  382. package/src/timeline/__tests__/timelinePaste.test.ts +0 -34
  383. package/src/timeline/timelineCommands.ts +0 -421
  384. package/src/timeline/timelineData.ts +0 -54
  385. package/src/timeline/timelineOps.ts +0 -381
  386. package/src/timeline/timelinePaste.ts +0 -8
  387. package/src/timelineSource.ts +0 -244
  388. package/src/tiptap/TiptapAudio.tsx +0 -86
  389. package/src/tiptap/TiptapVideo.tsx +0 -119
  390. package/src/tiptap/useResolvedMediaSrc.ts +0 -47
  391. package/src/tiptapBridge.ts +0 -986
  392. package/src/tooltipPlacement.ts +0 -13
  393. package/src/transformStyleId.ts +0 -17
  394. package/src/transitionCatalog.ts +0 -159
  395. package/src/treeview/TreeOutlineWidget.tsx +0 -390
  396. package/src/treeview/TreeViewExtension.ts +0 -250
  397. package/src/treeview/__tests__/TreeOutlineWidget.test.tsx +0 -156
  398. package/src/treeview/__tests__/TreeViewExtension.test.ts +0 -122
  399. package/src/treeview/__tests__/treeOps.test.ts +0 -177
  400. package/src/treeview/__tests__/treePaste.test.ts +0 -40
  401. package/src/treeview/__tests__/treeViewCommands.test.ts +0 -179
  402. package/src/treeview/treeOps.ts +0 -231
  403. package/src/treeview/treePaste.ts +0 -13
  404. package/src/treeview/treeViewCommands.ts +0 -99
  405. package/src/treeview/treeViewData.ts +0 -41
  406. package/src/types/monaco-shims.d.ts +0 -10
  407. package/src/useBlockNavigator.ts +0 -153
  408. package/src/useHeadingLayout.ts +0 -294
  409. package/src/useMonacoLoader.ts +0 -82
  410. package/src/useTimelineClock.ts +0 -76
  411. package/src/utils/collectInlineFontAwesomeCss.ts +0 -69
  412. package/src/utils/dropUtils.ts +0 -136
  413. package/src/utils/normalizeMalformedAssetUrl.ts +0 -22
  414. package/src/writeCanvasSettings.ts +0 -30
  415. package/src/wysiwygImageUpload.ts +0 -113
@@ -1,986 +0,0 @@
1
- /**
2
- * Tiptap Bridge
3
- *
4
- * Conversion utilities between raw markdown source and Tiptap's JSON/HTML
5
- * content format. Uses a lightweight HTML-based approach: we convert markdown
6
- * to a simple HTML representation that Tiptap can consume, and parse
7
- * Tiptap's HTML output back to markdown.
8
- *
9
- * This bridge preserves markdown semantics much better than going through
10
- * Tiptap's native markdown extension, since we control the conversion
11
- * using squisq's own parser.
12
- */
13
-
14
- import { resolveIcon } from '@bendyline/squisq/icons';
15
- import {
16
- matchTrailingTemplateAnnotation,
17
- matchTrailingPandocAttr,
18
- tokenizeAttrTokens,
19
- } from '@bendyline/squisq/markdown';
20
-
21
- // Hoisted regex patterns for inline markdown ↔ HTML conversion
22
- const RE_BOLD_STAR = /\*\*(.+?)\*\*/g;
23
- const RE_BOLD_UNDER = /__(.+?)__/g;
24
- const RE_ITALIC_STAR = /\*(.+?)\*/g;
25
- const RE_ITALIC_UNDER = /_(.+?)_/g;
26
- const RE_STRIKETHROUGH = /~~(.+?)~~/g;
27
- const RE_INLINE_CODE = /`(.+?)`/g;
28
- const RE_LINK = /\[(.+?)\]\((.+?)\)/g;
29
- // `*?` on the alt — an empty alt (`![](foo.png)`) is valid markdown and
30
- // the most common shape for pasted/uploaded images that don't yet have
31
- // a human-picked caption. Previously required at least one alt char,
32
- // which dropped those images on the floor during markdown→HTML.
33
- const RE_IMAGE = /!\[(.*?)\]\((.+?)\)/g;
34
- // Mentions: `@[Display](scheme:id)` — scheme-part must start with a letter
35
- // so plain `$100` or price-style parentheticals don't accidentally match.
36
- // remark-stringify may round-trip the colon as `\:` — tolerate either.
37
- const RE_MENTION = /@\[([^\]]+?)\]\(([a-z][a-z0-9+.-]*)\\?:([^)\s]+)\)/gi;
38
- const RE_MENTION_TAG = /<span\b[^>]*?\bdata-mention\b[^>]*?>(?:<[^>]+>)*([^<]*)<\/span>/gi;
39
-
40
- // Inline FontAwesome icon. Markdown form: `{[github]}` (bare) or
41
- // `{[fa-solid:user]}` (qualified). HTML form (produced by the
42
- // `InlineIcon` Tiptap node and consumed back by `htmlToInline`):
43
- // `<i data-icon="github" data-family="brands" data-name="github"
44
- // class="fa-brands fa-github" contenteditable="false"></i>`.
45
- const RE_ICON_MD = /\{\[([a-zA-Z0-9_:-]+)\]\}/g;
46
- const RE_ICON_TAG = /<i\b[^>]*?\bdata-icon="([^"]*)"[^>]*?><\/i>/gi;
47
- const RE_STRONG_TAG = /<strong>(.*?)<\/strong>/g;
48
- const RE_B_TAG = /<b>(.*?)<\/b>/g;
49
- const RE_EM_TAG = /<em>(.*?)<\/em>/g;
50
- const RE_I_TAG = /<i>(.*?)<\/i>/g;
51
- const RE_S_TAG = /<s>(.*?)<\/s>/g;
52
- const RE_DEL_TAG = /<del>(.*?)<\/del>/g;
53
- const RE_CODE_TAG = /<code>(.*?)<\/code>/g;
54
- const RE_A_TAG = /<a[^>]+href="([^"]*)"[^>]*>(.*?)<\/a>/g;
55
- // Matches any `<img>` tag and captures its `src` + `alt` regardless of
56
- // attribute order. TipTap's Image extension renders `<img src="..."
57
- // alt="...">` (src first), while some other producers — including our
58
- // own `markdownToTiptap` conversion — emit alt-first. The previous
59
- // regex required alt-before-src and silently dropped every src-first
60
- // image; `RE_STRIP_TAGS` below would then delete the unmatched tag,
61
- // so the outgoing markdown had no image reference at all.
62
- const RE_IMG_TAG = /<img\b([^>]*)>/g;
63
- const RE_STRIP_TAGS = /<[^>]+>/g;
64
-
65
- /**
66
- * Convert raw markdown source to Tiptap-consumable HTML content.
67
- * Uses a simple markdown-to-HTML conversion that maps cleanly to
68
- * Tiptap's ProseMirror schema.
69
- */
70
- export function markdownToTiptap(markdown: string): string {
71
- if (!markdown.trim()) return '<p></p>';
72
-
73
- // Normalize line endings — content from zip archives may use \r\n
74
- const html = markdown.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
75
-
76
- // Process blocks line by line for accurate conversion
77
- const lines = html.split('\n');
78
- const outputBlocks: string[] = [];
79
- let inCodeBlock = false;
80
- let codeBlockLang = '';
81
- let codeBlockLines: string[] = [];
82
- let inList = false;
83
- let listItems: string[] = [];
84
- let listType: 'ul' | 'ol' | 'task' = 'ul';
85
- let inTable = false;
86
- let tableLines: string[] = [];
87
- let pendingBlankLines = 0;
88
-
89
- const flushPendingBlankParagraphs = () => {
90
- if (pendingBlankLines === 0) return;
91
- const emptyParagraphs =
92
- outputBlocks.length === 0 ? pendingBlankLines : Math.max(0, pendingBlankLines - 1);
93
- for (let i = 0; i < emptyParagraphs; i++) {
94
- outputBlocks.push('<p></p>');
95
- }
96
- pendingBlankLines = 0;
97
- };
98
-
99
- const pushBlock = (block: string) => {
100
- flushPendingBlankParagraphs();
101
- outputBlocks.push(block);
102
- };
103
-
104
- const flushList = () => {
105
- if (inList && listItems.length > 0) {
106
- const tag = listType === 'ol' ? 'ol' : 'ul';
107
- const attr = listType === 'task' ? ' data-type="taskList"' : '';
108
- pushBlock(`<${tag}${attr}>${listItems.join('')}</${tag}>`);
109
- listItems = [];
110
- inList = false;
111
- }
112
- };
113
-
114
- const flushTable = () => {
115
- if (!inTable || tableLines.length === 0) {
116
- inTable = false;
117
- tableLines = [];
118
- return;
119
- }
120
-
121
- // Validate: need at least 2 lines and second must be a separator
122
- const separatorCells = tableLines.length >= 2 ? parseTableCells(tableLines[1]) : [];
123
- const isSeparator =
124
- separatorCells.length > 0 && separatorCells.every((cell) => /^:?-+:?$/.test(cell.trim()));
125
-
126
- if (tableLines.length < 2 || !isSeparator) {
127
- // Not a valid table — render accumulated lines as paragraphs
128
- for (const tl of tableLines) {
129
- pushBlock(`<p>${inlineToHtml(tl)}</p>`);
130
- }
131
- inTable = false;
132
- tableLines = [];
133
- return;
134
- }
135
-
136
- const alignments = parseAlignments(tableLines[1]);
137
- const headerCells = parseTableCells(tableLines[0]);
138
-
139
- // Build header row
140
- const thHtml = headerCells
141
- .map((cell, i) => {
142
- const align = alignments[i];
143
- const style = align ? ` style="text-align: ${align}"` : '';
144
- return `<th${style}>${inlineToHtml(cell)}</th>`;
145
- })
146
- .join('');
147
-
148
- // Build body rows
149
- const bodyHtml = tableLines
150
- .slice(2)
151
- .map((rowLine) => {
152
- const cells = parseTableCells(rowLine);
153
- const tdHtml = cells
154
- .map((cell, i) => {
155
- const align = alignments[i];
156
- const style = align ? ` style="text-align: ${align}"` : '';
157
- return `<td${style}>${inlineToHtml(cell)}</td>`;
158
- })
159
- .join('');
160
- return `<tr>${tdHtml}</tr>`;
161
- })
162
- .join('');
163
-
164
- pushBlock(`<table><thead><tr>${thHtml}</tr></thead><tbody>${bodyHtml}</tbody></table>`);
165
-
166
- inTable = false;
167
- tableLines = [];
168
- };
169
-
170
- for (let i = 0; i < lines.length; i++) {
171
- const line = lines[i];
172
-
173
- // Code fence handling
174
- if (line.startsWith('```')) {
175
- if (!inCodeBlock) {
176
- flushList();
177
- flushPendingBlankParagraphs();
178
- inCodeBlock = true;
179
- codeBlockLang = line.slice(3).trim();
180
- codeBlockLines = [];
181
- continue;
182
- } else {
183
- const langAttr = codeBlockLang ? ` class="language-${escapeHtml(codeBlockLang)}"` : '';
184
- pushBlock(`<pre><code${langAttr}>${escapeHtml(codeBlockLines.join('\n'))}</code></pre>`);
185
- inCodeBlock = false;
186
- codeBlockLang = '';
187
- codeBlockLines = [];
188
- continue;
189
- }
190
- }
191
-
192
- if (inCodeBlock) {
193
- codeBlockLines.push(line);
194
- continue;
195
- }
196
-
197
- // If in table and current line is not a table row, flush
198
- if (inTable && !/^\|.*\|$/.test(line.trim())) {
199
- flushTable();
200
- }
201
-
202
- // Blank line flushes list
203
- if (line.trim() === '') {
204
- flushList();
205
- pendingBlankLines++;
206
- continue;
207
- }
208
-
209
- flushPendingBlankParagraphs();
210
-
211
- // Headings
212
- const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
213
- if (headingMatch) {
214
- flushList();
215
- const level = headingMatch[1].length;
216
- let text = headingMatch[2];
217
- let attrs = '';
218
-
219
- // Peel off trailing brace-blocks in any order: the squisq-native
220
- // `{[template …]}` annotation and the Pandoc `{#id .class key=value}`
221
- // attribute block may both appear at the end of the heading line.
222
- // Loop until neither matches. The matchers are imported from core so
223
- // this stays in sync with packages/core/src/markdown/convert.ts.
224
- let templateInner: string | null = null;
225
- let pandocInner: string | null = null;
226
- for (let pass = 0; pass < 4; pass++) {
227
- let matched = false;
228
- if (templateInner == null) {
229
- const m = matchTrailingTemplateAnnotation(text);
230
- if (m) {
231
- templateInner = m.inner.trim();
232
- text = text.slice(0, m.index).trimEnd();
233
- matched = true;
234
- }
235
- }
236
- if (pandocInner == null) {
237
- const m = matchTrailingPandocAttr(text);
238
- if (m) {
239
- pandocInner = m.inner.trim();
240
- text = text.slice(0, m.index).trimEnd();
241
- matched = true;
242
- }
243
- }
244
- if (!matched) break;
245
- }
246
-
247
- if (templateInner != null) {
248
- // Quote-aware tokenization (shared with the core parser) keeps a
249
- // quoted value like caption="Beach at sunset" as one token. The
250
- // tokens are stored raw — quotes included — so tiptapToMarkdown
251
- // can re-join them into the annotation verbatim.
252
- const tokens = tokenizeAttrTokens(templateInner);
253
- if (tokens.length === 0) {
254
- // Preserve an authored `{[]}` through the editable Tiptap document
255
- // while keeping the raw marker out of the visible heading text.
256
- attrs += ' data-template-empty="true"';
257
- }
258
- const firstIsParam = tokens.length > 0 && tokens[0].indexOf('=') > 0;
259
- if (!firstIsParam && tokens[0]) {
260
- attrs += ` data-template="${escapeHtml(tokens[0])}"`;
261
- }
262
- const params = tokens.slice(firstIsParam ? 0 : 1).filter((t) => t.includes('='));
263
- if (params.length > 0) {
264
- attrs += ` data-template-params="${escapeHtml(params.join(' '))}"`;
265
- }
266
- }
267
- if (pandocInner != null) {
268
- attrs += ` data-block-attrs="${escapeHtml(pandocInner)}"`;
269
- }
270
-
271
- pushBlock(`<h${level}${attrs}>${inlineToHtml(text)}</h${level}>`);
272
- continue;
273
- }
274
-
275
- // Thematic break
276
- if (/^(---|\*\*\*|___)(\s*)$/.test(line.trim())) {
277
- flushList();
278
- pushBlock('<hr>');
279
- continue;
280
- }
281
-
282
- // Blockquote
283
- if (line.startsWith('> ')) {
284
- flushList();
285
- const quoteLines = [line.slice(2)];
286
- while (i + 1 < lines.length && lines[i + 1].startsWith('> ')) {
287
- i++;
288
- quoteLines.push(lines[i].slice(2));
289
- }
290
- pushBlock(
291
- `<blockquote>${quoteLines.map((quoteLine) => `<p>${inlineToHtml(quoteLine)}</p>`).join('')}</blockquote>`,
292
- );
293
- continue;
294
- }
295
-
296
- // Task list item. Text is optional so freshly-typed, still-empty tasks
297
- // survive a round-trip. The checkbox itself is drawn by TaskItem's node
298
- // view from the data-checked attribute, so we only emit the text content
299
- // (in a paragraph, matching Tiptap's own node structure).
300
- const taskMatch = line.match(/^[-*+]\s+\[([xX ])\]\s*(.*)$/);
301
- if (taskMatch) {
302
- if (!inList || listType !== 'task') {
303
- flushList();
304
- inList = true;
305
- listType = 'task';
306
- }
307
- const checkedAttr = taskMatch[1].toLowerCase() === 'x' ? ' data-checked="true"' : '';
308
- listItems.push(
309
- `<li data-type="taskItem"${checkedAttr}><p>${inlineToHtml(taskMatch[2])}</p></li>`,
310
- );
311
- continue;
312
- }
313
-
314
- // Unordered list item
315
- const ulMatch = line.match(/^[-*+]\s+(.+)$/);
316
- if (ulMatch) {
317
- if (!inList || listType !== 'ul') {
318
- flushList();
319
- inList = true;
320
- listType = 'ul';
321
- }
322
- listItems.push(`<li><p>${inlineToHtml(ulMatch[1])}</p></li>`);
323
- continue;
324
- }
325
-
326
- // Ordered list item
327
- const olMatch = line.match(/^\d+\.\s+(.+)$/);
328
- if (olMatch) {
329
- if (!inList || listType !== 'ol') {
330
- flushList();
331
- inList = true;
332
- listType = 'ol';
333
- }
334
- listItems.push(`<li><p>${inlineToHtml(olMatch[1])}</p></li>`);
335
- continue;
336
- }
337
-
338
- // Table row
339
- if (/^\|.*\|$/.test(line.trim())) {
340
- if (!inTable) {
341
- flushList();
342
- inTable = true;
343
- tableLines = [];
344
- }
345
- tableLines.push(line);
346
- continue;
347
- }
348
-
349
- // Standalone image — emit as a top-level block `<img>` instead of
350
- // wrapping in `<p>`. The Tiptap Image extension is configured with
351
- // `inline: false`, so `<p><img></p>` parses to an empty paragraph
352
- // (the block image can't live inside the paragraph). That bug
353
- // manifested as a broken-image glyph after a markdown → WYSIWYG
354
- // round-trip for any dropped/pasted image.
355
- const standaloneImageMatch = line.trim().match(/^!\[(.*?)\]\((.+?)\)$/);
356
- if (standaloneImageMatch) {
357
- flushList();
358
- const alt = escapeHtml(standaloneImageMatch[1] ?? '');
359
- const src = escapeHtml(standaloneImageMatch[2] ?? '');
360
- pushBlock(`<img alt="${alt}" src="${src}">`);
361
- continue;
362
- }
363
-
364
- // Standalone raw HTML `<img>` line — emitted by `tiptapToMarkdown`
365
- // when the user has resized an image (width/height attrs are
366
- // serialized as HTML rather than markdown shorthand so the
367
- // dimensions survive round-trip). Pass the tag through unchanged
368
- // so Tiptap's Image extension parses width/height attributes.
369
- const trimmed = line.trim();
370
- if (/^<img\b[^>]*>$/i.test(trimmed)) {
371
- flushList();
372
- pushBlock(trimmed);
373
- continue;
374
- }
375
-
376
- // Standalone `<video>` / `<audio>` line — emitted by the recorder
377
- // (RecorderEntry) when it saves a clip, and by `tiptapToMarkdown`
378
- // when the WYSIWYG editor's TiptapVideo/TiptapAudio nodes serialize
379
- // back to markdown. Pass through unchanged so the editor's parseHTML
380
- // picks up the tag attributes (`src`, `controls`, …).
381
- if (/^<(?:video|audio)\b[^>]*>(?:[\s\S]*?<\/(?:video|audio)>)?$/i.test(trimmed)) {
382
- flushList();
383
- pushBlock(trimmed);
384
- continue;
385
- }
386
-
387
- // Regular paragraph
388
- flushList();
389
- pushBlock(`<p>${inlineToHtml(line)}</p>`);
390
- }
391
-
392
- // Close any remaining open blocks
393
- if (inCodeBlock) {
394
- const langAttr = codeBlockLang ? ` class="language-${escapeHtml(codeBlockLang)}"` : '';
395
- pushBlock(`<pre><code${langAttr}>${escapeHtml(codeBlockLines.join('\n'))}</code></pre>`);
396
- }
397
- flushList();
398
- flushTable();
399
- flushPendingBlankParagraphs();
400
-
401
- return outputBlocks.join('') || '<p></p>';
402
- }
403
-
404
- /**
405
- * Convert Tiptap HTML output back to markdown source.
406
- * Extracts semantic structure from HTML and produces clean markdown.
407
- */
408
- export function tiptapToMarkdown(html: string): string {
409
- if (!html || html === '<p></p>') return '';
410
-
411
- const lines: string[] = [];
412
-
413
- // Simple regex-based HTML to markdown conversion
414
- // This works because Tiptap produces clean, predictable HTML
415
- let remaining = html;
416
-
417
- while (remaining.length > 0) {
418
- // Headings
419
- const headingMatch = remaining.match(/^<h([1-6])([^>]*)>(.*?)<\/h\1>/s);
420
- if (headingMatch) {
421
- const level = parseInt(headingMatch[1], 10);
422
- const attrs = headingMatch[2];
423
- const headingHtml = headingMatch[3];
424
- // Template/property badges are editor chrome, not heading content. Strip
425
- // them structurally before converting the inline HTML. Older builds
426
- // briefly rendered the template label as real badge text; using the
427
- // markup boundary preserves that cleanup without mistaking a legitimate
428
- // heading suffix (for example "A Famous Quote") for the badge label.
429
- const chromeStart = headingHtml.search(
430
- /<span\b[^>]*\bclass="[^"]*\bsquisq-(?:template|props)-badge\b[^"]*"[^>]*>/i,
431
- );
432
- let text = htmlToInline(chromeStart >= 0 ? headingHtml.slice(0, chromeStart) : headingHtml);
433
-
434
- // Re-inject heading annotations from data attributes. Canonical
435
- // emit order: Pandoc `{#…}` first, then squisq `{[…]}` annotation
436
- // (matches blockToMdast in core/markdown/convert.ts).
437
- const blockAttrsMatch = attrs.match(/data-block-attrs="([^"]*)"/);
438
- const tmplMatch = attrs.match(/data-template="([^"]+)"/);
439
- const paramsMatch = attrs.match(/data-template-params="([^"]+)"/);
440
- const hasEmptyTemplateAnnotation = /\sdata-template-empty(?:="[^"]*")?/.test(attrs);
441
- if (blockAttrsMatch) {
442
- const inner = unescapeHtml(blockAttrsMatch[1]);
443
- text += ` {${inner}}`;
444
- }
445
- if (tmplMatch || paramsMatch) {
446
- let annotation = tmplMatch ? tmplMatch[1] : '';
447
- if (paramsMatch) {
448
- annotation += (annotation ? ' ' : '') + unescapeHtml(paramsMatch[1]);
449
- }
450
- text += ` {[${annotation}]}`;
451
- } else if (hasEmptyTemplateAnnotation) {
452
- text += ' {[]}';
453
- }
454
-
455
- lines.push('#'.repeat(level) + ' ' + text);
456
- lines.push('');
457
- remaining = remaining.slice(headingMatch[0].length);
458
- continue;
459
- }
460
-
461
- // Code blocks — tolerate attributes on <pre> and <code>: real
462
- // editor.getHTML() output carries class="squisq-code-block" on the
463
- // <pre> (StarterKit codeBlock HTMLAttributes), which a bare
464
- // `<pre><code` anchor never matches, silently dropping the fence.
465
- const codeMatch = remaining.match(/^<pre\b[^>]*><code\b([^>]*)>(.*?)<\/code><\/pre>/s);
466
- if (codeMatch) {
467
- const lang = /\bclass="language-([^"]*)"/.exec(codeMatch[1] ?? '')?.[1] ?? '';
468
- const code = unescapeHtml(codeMatch[2]);
469
- lines.push('```' + lang);
470
- lines.push(code);
471
- lines.push('```');
472
- lines.push('');
473
- remaining = remaining.slice(codeMatch[0].length);
474
- continue;
475
- }
476
-
477
- // Blockquote
478
- const bqMatch = remaining.match(/^<blockquote>(.*?)<\/blockquote>/s);
479
- if (bqMatch) {
480
- const paragraphs = bqMatch[1]
481
- .split(/<\/p>\s*<p[^>]*>/i)
482
- .map((paragraph) => paragraph.replace(/^<p[^>]*>/i, '').replace(/<\/p>\s*$/i, ''));
483
- for (const paragraph of paragraphs) {
484
- for (const quoteLine of htmlToInline(paragraph).split('\n')) {
485
- lines.push('> ' + quoteLine);
486
- }
487
- }
488
- const next = remaining.slice(bqMatch[0].length);
489
- // Older bridge output and direct Tiptap edits can still leave adjacent
490
- // blockquote nodes. Keep those nodes adjacent when serializing;
491
- // inserting the normal block separator here turns one quote into two
492
- // paragraphs every time the document passes through WYSIWYG mode.
493
- if (!/^\s*<blockquote>/.test(next)) lines.push('');
494
- remaining = next;
495
- continue;
496
- }
497
-
498
- // Horizontal rule
499
- if (
500
- remaining.startsWith('<hr>') ||
501
- remaining.startsWith('<hr/>') ||
502
- remaining.startsWith('<hr />')
503
- ) {
504
- const hrMatch = remaining.match(/^<hr\s*\/?>/);
505
- lines.push('---');
506
- lines.push('');
507
- remaining = remaining.slice(hrMatch![0].length);
508
- continue;
509
- }
510
-
511
- // Table (with optional Tiptap tableWrapper div; table tag may have style attrs)
512
- const tableMatch =
513
- remaining.match(
514
- /^<div[^>]*class="[^"]*tableWrapper[^"]*"[^>]*><table[^>]*>(.*?)<\/table>\s*<\/div>/s,
515
- ) || remaining.match(/^<table[^>]*>(.*?)<\/table>/s);
516
- if (tableMatch) {
517
- const tableContent = tableMatch[1];
518
-
519
- // Extract all rows with their cells
520
- const rows: { content: string; align: string | null; isHeader: boolean }[][] = [];
521
- const rowRegex = /<tr[^>]*>(.*?)<\/tr>/gs;
522
- let rowExec;
523
- while ((rowExec = rowRegex.exec(tableContent)) !== null) {
524
- const rowHtml = rowExec[1];
525
- const cells: { content: string; align: string | null; isHeader: boolean }[] = [];
526
- const cellRegex = /<(th|td)([^>]*)>(.*?)<\/\1>/gs;
527
- let cellExec;
528
- while ((cellExec = cellRegex.exec(rowHtml)) !== null) {
529
- const tag = cellExec[1];
530
- const attrs = cellExec[2];
531
- const content = htmlToInline(cellExec[3].replace(/<\/?p>/g, ''));
532
- const alignExec = attrs.match(/text-align:\s*(left|center|right)/);
533
- cells.push({
534
- content,
535
- align: alignExec ? alignExec[1] : null,
536
- isHeader: tag === 'th',
537
- });
538
- }
539
- if (cells.length > 0) {
540
- rows.push(cells);
541
- }
542
- }
543
-
544
- if (rows.length > 0) {
545
- // Header row = first row with th cells, or just the first row
546
- const headerIdx = rows.findIndex((r) => r.some((c) => c.isHeader));
547
- const hIdx = headerIdx >= 0 ? headerIdx : 0;
548
- const headerRow = rows[hIdx];
549
- const dataRows = rows.filter((_, i) => i !== hIdx);
550
-
551
- const aligns = headerRow.map((c) => c.align);
552
- lines.push('| ' + headerRow.map((c) => c.content || ' ').join(' | ') + ' |');
553
- lines.push(
554
- '| ' +
555
- aligns
556
- .map((a) => {
557
- if (a === 'center') return ':---:';
558
- if (a === 'right') return '---:';
559
- return '---';
560
- })
561
- .join(' | ') +
562
- ' |',
563
- );
564
- for (const row of dataRows) {
565
- lines.push('| ' + row.map((c) => c.content || ' ').join(' | ') + ' |');
566
- }
567
- lines.push('');
568
- }
569
-
570
- remaining = remaining.slice(tableMatch[0].length);
571
- continue;
572
- }
573
-
574
- // Task list
575
- const taskListMatch = remaining.match(/^<ul[^>]*data-type="taskList"[^>]*>(.*?)<\/ul>/s);
576
- if (taskListMatch) {
577
- const items = taskListMatch[1].matchAll(/<li[^>]*data-type="taskItem"[^>]*>.*?<\/li>/gs);
578
- for (const item of items) {
579
- // Read checked state from the attribute value only — a bare
580
- // includes('checked') matches the substring in data-checked="false".
581
- const checked = /data-checked="true"/.test(item[0]);
582
- // Drop the checkbox chrome (<label>…</label>) before reading text;
583
- // Tiptap puts the task text in the trailing content node, not the label.
584
- const body = item[0].replace(/<label\b[^>]*>.*?<\/label>/s, '');
585
- const text = htmlToInline(body.replace(/<[^>]+>/g, '').trim());
586
- lines.push(`- [${checked ? 'x' : ' '}] ${text}`.trimEnd());
587
- }
588
- lines.push('');
589
- remaining = remaining.slice(taskListMatch[0].length);
590
- continue;
591
- }
592
-
593
- // Unordered list
594
- const ulMatch = remaining.match(/^<ul>(.*?)<\/ul>/s);
595
- if (ulMatch) {
596
- const items = ulMatch[1].matchAll(/<li>(.*?)<\/li>/gs);
597
- for (const item of items) {
598
- lines.push(...renderListItem('- ', item[1]));
599
- }
600
- lines.push('');
601
- remaining = remaining.slice(ulMatch[0].length);
602
- continue;
603
- }
604
-
605
- // Ordered list
606
- const olMatch = remaining.match(/^<ol[^>]*>(.*?)<\/ol>/s);
607
- if (olMatch) {
608
- const items = [...olMatch[1].matchAll(/<li>(.*?)<\/li>/gs)];
609
- items.forEach((item, idx) => {
610
- lines.push(...renderListItem(`${idx + 1}. `, item[1]));
611
- });
612
- lines.push('');
613
- remaining = remaining.slice(olMatch[0].length);
614
- continue;
615
- }
616
-
617
- // Paragraph
618
- const pMatch = remaining.match(/^<p>(.*?)<\/p>/s);
619
- if (pMatch) {
620
- const text = htmlToInline(pMatch[1]);
621
- if (text.trim()) {
622
- lines.push(text);
623
- lines.push('');
624
- } else {
625
- lines.push('');
626
- }
627
- remaining = remaining.slice(pMatch[0].length);
628
- continue;
629
- }
630
-
631
- // Block-level image. TipTap's Image extension with `inline: false`
632
- // emits `<img src alt>` as a bare top-level element (no wrapping
633
- // `<p>`). Without this handler the skip-unknown-tags catch-all
634
- // below silently drops the image from the outgoing markdown —
635
- // the bug that made the chat composer ship image-less messages
636
- // even though the editor showed the picture. Handled here,
637
- // before the inline walker ever sees it.
638
- const imgMatch = remaining.match(/^<img\b([^>]*)>/);
639
- if (imgMatch) {
640
- const attrs = imgMatch[1] ?? '';
641
- const src = /\bsrc="([^"]*)"/i.exec(attrs)?.[1];
642
- if (src) {
643
- const alt = /\balt="([^"]*)"/i.exec(attrs)?.[1] ?? '';
644
- lines.push(serializeImage(src, alt, attrs));
645
- lines.push('');
646
- }
647
- remaining = remaining.slice(imgMatch[0].length);
648
- continue;
649
- }
650
-
651
- // Block-level `<video>` / `<audio>` — emitted by our TiptapVideo /
652
- // TiptapAudio atom nodes (block group). Serialize the whole tag
653
- // (opening + closing) back to markdown unchanged; CommonMark allows
654
- // inline HTML, and our renderer plus the InlinePreviewGutter both
655
- // know how to parse the htmlElement back out.
656
- const mediaMatch = remaining.match(/^<(video|audio)\b([^>]*)>(?:[\s\S]*?<\/\1>)?/);
657
- if (mediaMatch) {
658
- const tag = mediaMatch[1] === 'video' ? 'video' : 'audio';
659
- lines.push(serializeMediaTag(tag, mediaMatch[2] ?? ''));
660
- lines.push('');
661
- remaining = remaining.slice(mediaMatch[0].length);
662
- continue;
663
- }
664
-
665
- // Skip unknown tags or whitespace
666
- const skipMatch = remaining.match(/^(<[^>]+>|\s+)/);
667
- if (skipMatch) {
668
- remaining = remaining.slice(skipMatch[0].length);
669
- continue;
670
- }
671
-
672
- // Plain text (shouldn't happen in well-formed Tiptap output)
673
- const textMatch = remaining.match(/^([^<]+)/);
674
- if (textMatch) {
675
- lines.push(unescapeHtml(textMatch[1]));
676
- remaining = remaining.slice(textMatch[0].length);
677
- continue;
678
- }
679
-
680
- // Safety: skip one character to avoid infinite loop
681
- remaining = remaining.slice(1);
682
- }
683
-
684
- return lines.join('\n');
685
- }
686
-
687
- /**
688
- * Render a list item's HTML content as one or more markdown lines.
689
- * Handles `<p>` paragraph breaks (blank line) and `<br>` hard breaks
690
- * (two trailing spaces). Continuation lines are indented to keep them
691
- * inside the list item.
692
- */
693
- function renderListItem(prefix: string, html: string): string[] {
694
- const indent = ' '.repeat(prefix.length);
695
-
696
- // Pull out any block-level media nested in the item (e.g. a recording
697
- // dropped onto a list bullet, or a clip dragged into one). The inline
698
- // paragraph walk below ignores `<video>` / `<audio>` tags, so without
699
- // this they'd be silently dropped on serialize and lost from the
700
- // markdown source. We collect them and re-emit each as an indented
701
- // continuation line so they stay inside the list item and round-trip
702
- // through the markdown parser's block-media handler.
703
- const media: string[] = [];
704
- const htmlWithoutMedia = html.replace(
705
- /<(video|audio)\b([^>]*)>(?:[\s\S]*?<\/\1>)?/gi,
706
- (_full, tag: string, attrs: string) => {
707
- media.push(serializeMediaTag(tag.toLowerCase() === 'video' ? 'video' : 'audio', attrs ?? ''));
708
- return '';
709
- },
710
- );
711
-
712
- // Split on </p><p> to detect paragraph breaks within the item
713
- const paragraphs = htmlWithoutMedia
714
- .split(/<\/p>\s*<p[^>]*>/i)
715
- .map((p) => p.replace(/^<p[^>]*>/i, '').replace(/<\/p>\s*$/i, ''));
716
-
717
- const textLines: string[] = [];
718
- paragraphs.forEach((paragraph, pIdx) => {
719
- const inline = htmlToInline(paragraph).trim();
720
- if (!inline) return;
721
-
722
- // Each <br> already became " \n" in htmlToInline; split on it now.
723
- const subLines = inline.split('\n');
724
- subLines.forEach((sub, sIdx) => {
725
- if (pIdx === 0 && sIdx === 0) {
726
- textLines.push(prefix + sub);
727
- } else {
728
- // Blank line separator between paragraphs (sIdx === 0 means new paragraph)
729
- if (sIdx === 0) textLines.push('');
730
- textLines.push(indent + sub);
731
- }
732
- });
733
- });
734
-
735
- if (textLines.length === 0 && media.length === 0) return [prefix];
736
-
737
- // Text first (its first line carries the bullet marker), then each media
738
- // tag as its own indented continuation block. If the item is media-only,
739
- // the first tag takes the bullet so the item isn't emitted empty.
740
- const result: string[] = [];
741
- if (textLines.length > 0) {
742
- result.push(...textLines);
743
- for (const tag of media) {
744
- result.push('');
745
- result.push(indent + tag);
746
- }
747
- } else {
748
- result.push(prefix + media[0]);
749
- for (const tag of media.slice(1)) {
750
- result.push('');
751
- result.push(indent + tag);
752
- }
753
- }
754
- return result;
755
- }
756
-
757
- // ─── Table helpers ───────────────────────────────────────
758
-
759
- /** Split a GFM table row into trimmed cell strings (strips outer pipes). */
760
- function parseTableCells(line: string): string[] {
761
- let inner = line.trim();
762
- if (inner.startsWith('|')) inner = inner.slice(1);
763
- if (inner.endsWith('|')) inner = inner.slice(0, -1);
764
- return inner.split('|').map((cell) => cell.trim());
765
- }
766
-
767
- /** Parse a GFM separator line into column alignments. */
768
- function parseAlignments(separatorLine: string): (string | null)[] {
769
- return parseTableCells(separatorLine).map((cell) => {
770
- const s = cell.replace(/\s/g, '');
771
- if (s.startsWith(':') && s.endsWith(':')) return 'center';
772
- if (s.endsWith(':')) return 'right';
773
- if (s.startsWith(':')) return 'left';
774
- return null;
775
- });
776
- }
777
-
778
- // ─── Helpers ─────────────────────────────────────────────
779
-
780
- /**
781
- * Serialize a parsed `<img>` tag back to markdown. When the tag carries
782
- * an explicit `width` and/or `height` we emit a raw HTML `<img>` (the
783
- * markdown shorthand `![alt](src)` has no syntax for dimensions);
784
- * otherwise the friendlier shorthand is used. Markdown allows inline
785
- * HTML, so the HTML form parses and renders identically in any
786
- * CommonMark/GFM viewer.
787
- */
788
- /**
789
- * Serialize a `<video>` or `<audio>` tag (from the Tiptap atom node's
790
- * `renderHTML`) back to markdown. We re-emit only the attributes the
791
- * recorder + the renderer care about, in a stable order, so the
792
- * round-tripped markdown stays deterministic regardless of how Tiptap
793
- * decided to order them on its output.
794
- */
795
- function serializeMediaTag(tag: 'video' | 'audio', attrs: string): string {
796
- const src = /\bsrc="([^"]*)"/i.exec(attrs)?.[1] ?? '';
797
- const controls = /\bcontrols\b/i.test(attrs);
798
- const width = /\bwidth="([^"]*)"/i.exec(attrs)?.[1];
799
- const height = /\bheight="([^"]*)"/i.exec(attrs)?.[1];
800
- const poster = tag === 'video' ? /\bposter="([^"]*)"/i.exec(attrs)?.[1] : undefined;
801
- const parts = [`<${tag} src="${src}"`];
802
- if (controls) parts.push(' controls');
803
- if (width) parts.push(` width="${width}"`);
804
- if (height) parts.push(` height="${height}"`);
805
- if (poster) parts.push(` poster="${poster}"`);
806
- parts.push(`></${tag}>`);
807
- return parts.join('');
808
- }
809
-
810
- function serializeImage(src: string, alt: string, attrs: string): string {
811
- const width = /\bwidth="([^"]*)"/i.exec(attrs)?.[1];
812
- const height = /\bheight="([^"]*)"/i.exec(attrs)?.[1];
813
- const title = /\btitle="([^"]*)"/i.exec(attrs)?.[1];
814
- if (!width && !height) {
815
- return `![${alt}](${src})`;
816
- }
817
- const parts = [`<img alt="${alt}" src="${src}"`];
818
- if (width) parts.push(` width="${width}"`);
819
- if (height) parts.push(` height="${height}"`);
820
- if (title) parts.push(` title="${title}"`);
821
- parts.push('>');
822
- return parts.join('');
823
- }
824
-
825
- function escapeHtml(text: string): string {
826
- return text
827
- .replace(/&/g, '&amp;')
828
- .replace(/</g, '&lt;')
829
- .replace(/>/g, '&gt;')
830
- .replace(/"/g, '&quot;');
831
- }
832
-
833
- function unescapeHtml(text: string): string {
834
- return text
835
- .replace(/&lt;/g, '<')
836
- .replace(/&gt;/g, '>')
837
- .replace(/&quot;/g, '"')
838
- .replace(/&nbsp;|&#160;|&#xA0;/gi, '\u00a0')
839
- .replace(/&amp;/g, '&');
840
- }
841
-
842
- /** Convert inline markdown to HTML for Tiptap consumption */
843
- function inlineToHtml(text: string): string {
844
- // Extract images/mentions/links to opaque placeholders BEFORE running
845
- // any inline-formatting regexes. Otherwise `_` characters inside a URL
846
- // (e.g. `mikehome_files/IMG_6829.JPEG`) get turned into `<em>` tags by
847
- // the underscore-italic rule, mangling the src so the image renders
848
- // broken after a markdown ↔ WYSIWYG round-trip.
849
- const placeholders: string[] = [];
850
- const stash = (html: string): string => {
851
- const token = `\u0000PH${placeholders.length}\u0000`;
852
- placeholders.push(html);
853
- return token;
854
- };
855
-
856
- // We run extraction on the RAW text (before escapeHtml) so the
857
- // captured groups are the literal markdown contents; then we
858
- // selectively escape the parts of each placeholder that need it.
859
-
860
- // Images first: ![alt](src) — must be before links so the `!` prefix is consumed
861
- let staged = text.replace(RE_IMAGE, (_m, alt, src) =>
862
- stash(`<img alt="${escapeHtml(alt)}" src="${escapeHtml(src)}">`),
863
- );
864
-
865
- // Mentions: @[Display](scheme:id) — must run before links so the
866
- // bracket+paren isn't consumed as a regular link.
867
- staged = staged.replace(RE_MENTION, (_m, label, kind, id) =>
868
- stash(
869
- `<span data-mention="true" data-kind="${escapeHtml(kind)}" data-id="${escapeHtml(id)}" data-label="${escapeHtml(label)}" class="mention">@${escapeHtml(label)}</span>`,
870
- ),
871
- );
872
-
873
- // FontAwesome inline icons: {[github]} / {[fa-solid:user]} — resolve
874
- // against the FA catalog so unknown / ambiguous tokens stay as
875
- // literal text (preserved through escapeHtml later). Stashing here
876
- // alongside images/mentions keeps the `_` and other punctuation in
877
- // the class attribute from being mangled by the underscore-italic
878
- // regex below.
879
- staged = staged.replace(RE_ICON_MD, (full, token) => {
880
- const icon = resolveIcon(token);
881
- if (!icon) return full; // leave literal text — author may have meant it
882
- return stash(
883
- `<i class="fa-${icon.family} fa-${icon.name}" data-icon="${escapeHtml(token)}" data-family="${icon.family}" data-name="${icon.name}" contenteditable="false"></i>`,
884
- );
885
- });
886
-
887
- // Links: [text](url) — stash but keep the link text available to
888
- // inline formatting by recursing.
889
- staged = staged.replace(RE_LINK, (_m, linkText, href) =>
890
- stash(`<a href="${escapeHtml(href)}">${inlineToHtml(linkText)}</a>`),
891
- );
892
-
893
- let result = escapeHtml(staged);
894
-
895
- // Bold: **text** or __text__
896
- result = result.replace(RE_BOLD_STAR, '<strong>$1</strong>');
897
- result = result.replace(RE_BOLD_UNDER, '<strong>$1</strong>');
898
-
899
- // Italic: *text* or _text_
900
- result = result.replace(RE_ITALIC_STAR, '<em>$1</em>');
901
- result = result.replace(RE_ITALIC_UNDER, '<em>$1</em>');
902
-
903
- // Strikethrough: ~~text~~
904
- result = result.replace(RE_STRIKETHROUGH, '<s>$1</s>');
905
-
906
- // Inline code: `text`
907
- result = result.replace(RE_INLINE_CODE, '<code>$1</code>');
908
-
909
- // Restore placeholders. escapeHtml turned each `\u0000PHn\u0000` into
910
- // the same string (the NULs and digits are escape-safe), so the
911
- // restoration regex still matches.
912
- // eslint-disable-next-line no-control-regex
913
- result = result.replace(/\u0000PH(\d+)\u0000/g, (_m, idx) => placeholders[Number(idx)] ?? '');
914
-
915
- return preserveLeadingSpaces(result);
916
- }
917
-
918
- /** Convert inline HTML back to markdown */
919
- function htmlToInline(html: string): string {
920
- let result = html;
921
-
922
- // Soft line breaks — convert <br> to GFM hard-break syntax (two trailing
923
- // spaces + newline) before stripping tags so the newline survives.
924
- result = result.replace(/<br\s*\/?>/gi, ' \n');
925
-
926
- // FontAwesome inline icons — emit the original token. Must run before
927
- // RE_I_TAG (which matches a bare `<i>` and would otherwise eat icon
928
- // tags too). The token captured via data-icon already carries the
929
- // qualified form when needed, so source round-trips exactly.
930
- result = result.replace(RE_ICON_TAG, (_m, token) => `{[${token}]}`);
931
-
932
- // Strong
933
- result = result.replace(RE_STRONG_TAG, '**$1**');
934
- result = result.replace(RE_B_TAG, '**$1**');
935
-
936
- // Em
937
- result = result.replace(RE_EM_TAG, '*$1*');
938
- result = result.replace(RE_I_TAG, '*$1*');
939
-
940
- // Strikethrough
941
- result = result.replace(RE_S_TAG, '~~$1~~');
942
- result = result.replace(RE_DEL_TAG, '~~$1~~');
943
-
944
- // Code
945
- result = result.replace(RE_CODE_TAG, '`$1`');
946
-
947
- // Mentions — match before the link handler so the span isn't stripped
948
- // out as an unknown tag. Pull kind + id out of the data attributes.
949
- result = result.replace(RE_MENTION_TAG, (match, _inner) => {
950
- const kind = /data-kind="([^"]*)"/i.exec(match)?.[1] ?? '';
951
- const id = /data-id="([^"]*)"/i.exec(match)?.[1] ?? '';
952
- const label = /data-label="([^"]*)"/i.exec(match)?.[1] ?? '';
953
- if (!kind || !id || !label) return match;
954
- return `@[${label}](${kind}:${id})`;
955
- });
956
-
957
- // Links
958
- result = result.replace(RE_A_TAG, '[$2]($1)');
959
-
960
- // Images — order-agnostic attribute parsing (tiptap emits src-first,
961
- // our markdown-to-html emits alt-first; either must serialize back).
962
- // When a width/height is present we serialize as raw HTML `<img>` so
963
- // the dimensions survive the round-trip; otherwise the markdown
964
- // shorthand `![alt](src)` is used.
965
- result = result.replace(RE_IMG_TAG, (match, attrs: string) => {
966
- const src = /\bsrc="([^"]*)"/i.exec(attrs)?.[1];
967
- if (!src) return match;
968
- const alt = /\balt="([^"]*)"/i.exec(attrs)?.[1] ?? '';
969
- return serializeImage(src, alt, attrs);
970
- });
971
-
972
- // Strip remaining tags
973
- result = result.replace(RE_STRIP_TAGS, '');
974
-
975
- return restoreLeadingSpaces(unescapeHtml(result));
976
- }
977
-
978
- function preserveLeadingSpaces(html: string): string {
979
- return html.replace(/^ +/, (spaces) => '&nbsp;'.repeat(spaces.length));
980
- }
981
-
982
- function restoreLeadingSpaces(text: string): string {
983
- return text.replace(/(^|\n)(\u00a0+)/g, (_match, prefix: string, spaces: string) => {
984
- return prefix + ' '.repeat(spaces.length);
985
- });
986
- }