@bendyline/squisq-editor-react 1.4.0 → 1.5.1

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 (446) hide show
  1. package/dist/DocumentSettingsDialog.d.ts +26 -0
  2. package/dist/DocumentSettingsDialog.d.ts.map +1 -0
  3. package/dist/DocumentSettingsDialog.js +115 -0
  4. package/dist/DocumentSettingsDialog.js.map +1 -0
  5. package/dist/EditorContext.d.ts +248 -4
  6. package/dist/EditorContext.d.ts.map +1 -1
  7. package/dist/EditorContext.js +248 -10
  8. package/dist/EditorContext.js.map +1 -1
  9. package/dist/EditorShell.d.ts +173 -4
  10. package/dist/EditorShell.d.ts.map +1 -1
  11. package/dist/EditorShell.js +110 -10
  12. package/dist/EditorShell.js.map +1 -1
  13. package/dist/EmojiPicker.d.ts +50 -0
  14. package/dist/EmojiPicker.d.ts.map +1 -0
  15. package/dist/EmojiPicker.js +182 -0
  16. package/dist/EmojiPicker.js.map +1 -0
  17. package/dist/ImageEditor.d.ts +68 -0
  18. package/dist/ImageEditor.d.ts.map +1 -0
  19. package/dist/ImageEditor.js +166 -0
  20. package/dist/ImageEditor.js.map +1 -0
  21. package/dist/ImageNodeView.d.ts +13 -1
  22. package/dist/ImageNodeView.d.ts.map +1 -1
  23. package/dist/ImageNodeView.js +172 -19
  24. package/dist/ImageNodeView.js.map +1 -1
  25. package/dist/ImageViewer.d.ts +26 -0
  26. package/dist/ImageViewer.d.ts.map +1 -0
  27. package/dist/ImageViewer.js +119 -0
  28. package/dist/ImageViewer.js.map +1 -0
  29. package/dist/InlineIcon.d.ts +17 -0
  30. package/dist/InlineIcon.d.ts.map +1 -0
  31. package/dist/InlineIcon.js +72 -0
  32. package/dist/InlineIcon.js.map +1 -0
  33. package/dist/InlinePreviewGutter.d.ts +52 -0
  34. package/dist/InlinePreviewGutter.d.ts.map +1 -0
  35. package/dist/InlinePreviewGutter.js +397 -0
  36. package/dist/InlinePreviewGutter.js.map +1 -0
  37. package/dist/LinkDialog.d.ts +43 -0
  38. package/dist/LinkDialog.d.ts.map +1 -0
  39. package/dist/LinkDialog.js +102 -0
  40. package/dist/LinkDialog.js.map +1 -0
  41. package/dist/MentionExtension.js +10 -7
  42. package/dist/MentionExtension.js.map +1 -1
  43. package/dist/OutlinePanel.d.ts +17 -0
  44. package/dist/OutlinePanel.d.ts.map +1 -0
  45. package/dist/OutlinePanel.js +167 -0
  46. package/dist/OutlinePanel.js.map +1 -0
  47. package/dist/PlainHtmlPreview.d.ts +50 -0
  48. package/dist/PlainHtmlPreview.d.ts.map +1 -0
  49. package/dist/PlainHtmlPreview.js +155 -0
  50. package/dist/PlainHtmlPreview.js.map +1 -0
  51. package/dist/PreviewControls.d.ts +15 -1
  52. package/dist/PreviewControls.d.ts.map +1 -1
  53. package/dist/PreviewControls.js +75 -18
  54. package/dist/PreviewControls.js.map +1 -1
  55. package/dist/PreviewPanel.d.ts +11 -10
  56. package/dist/PreviewPanel.d.ts.map +1 -1
  57. package/dist/PreviewPanel.js +20 -17
  58. package/dist/PreviewPanel.js.map +1 -1
  59. package/dist/RawEditor.d.ts.map +1 -1
  60. package/dist/RawEditor.js +198 -4
  61. package/dist/RawEditor.js.map +1 -1
  62. package/dist/RecorderEntry.d.ts +24 -0
  63. package/dist/RecorderEntry.d.ts.map +1 -0
  64. package/dist/RecorderEntry.js +139 -0
  65. package/dist/RecorderEntry.js.map +1 -0
  66. package/dist/TemplateAnnotation.d.ts.map +1 -1
  67. package/dist/TemplateAnnotation.js +32 -6
  68. package/dist/TemplateAnnotation.js.map +1 -1
  69. package/dist/TemplatePicker.d.ts +53 -0
  70. package/dist/TemplatePicker.d.ts.map +1 -0
  71. package/dist/TemplatePicker.js +388 -0
  72. package/dist/TemplatePicker.js.map +1 -0
  73. package/dist/ThemeCustomizerPanel.d.ts +32 -0
  74. package/dist/ThemeCustomizerPanel.d.ts.map +1 -0
  75. package/dist/ThemeCustomizerPanel.js +256 -0
  76. package/dist/ThemeCustomizerPanel.js.map +1 -0
  77. package/dist/ThemePicker.d.ts +33 -0
  78. package/dist/ThemePicker.d.ts.map +1 -0
  79. package/dist/ThemePicker.js +148 -0
  80. package/dist/ThemePicker.js.map +1 -0
  81. package/dist/Toolbar.d.ts.map +1 -1
  82. package/dist/Toolbar.js +508 -33
  83. package/dist/Toolbar.js.map +1 -1
  84. package/dist/VersionHistoryPanel.d.ts +14 -0
  85. package/dist/VersionHistoryPanel.d.ts.map +1 -0
  86. package/dist/VersionHistoryPanel.js +147 -0
  87. package/dist/VersionHistoryPanel.js.map +1 -0
  88. package/dist/ViewMenuPanel.d.ts +13 -0
  89. package/dist/ViewMenuPanel.d.ts.map +1 -0
  90. package/dist/ViewMenuPanel.js +58 -0
  91. package/dist/ViewMenuPanel.js.map +1 -0
  92. package/dist/WysiwygEditor.d.ts.map +1 -1
  93. package/dist/WysiwygEditor.js +198 -9
  94. package/dist/WysiwygEditor.js.map +1 -1
  95. package/dist/__tests__/detectMarkdown.test.js +0 -14
  96. package/dist/__tests__/detectMarkdown.test.js.map +1 -1
  97. package/dist/__tests__/documentSettingsDialog.test.d.ts +2 -0
  98. package/dist/__tests__/documentSettingsDialog.test.d.ts.map +1 -0
  99. package/dist/__tests__/documentSettingsDialog.test.js +132 -0
  100. package/dist/__tests__/documentSettingsDialog.test.js.map +1 -0
  101. package/dist/__tests__/emojiPicker.test.d.ts +2 -0
  102. package/dist/__tests__/emojiPicker.test.d.ts.map +1 -0
  103. package/dist/__tests__/emojiPicker.test.js +111 -0
  104. package/dist/__tests__/emojiPicker.test.js.map +1 -0
  105. package/dist/__tests__/fileKind.test.js +13 -0
  106. package/dist/__tests__/fileKind.test.js.map +1 -1
  107. package/dist/__tests__/imageEditAffordance.test.d.ts +2 -0
  108. package/dist/__tests__/imageEditAffordance.test.d.ts.map +1 -0
  109. package/dist/__tests__/imageEditAffordance.test.js +188 -0
  110. package/dist/__tests__/imageEditAffordance.test.js.map +1 -0
  111. package/dist/__tests__/imageEditorShell.test.d.ts +2 -0
  112. package/dist/__tests__/imageEditorShell.test.d.ts.map +1 -0
  113. package/dist/__tests__/imageEditorShell.test.js +52 -0
  114. package/dist/__tests__/imageEditorShell.test.js.map +1 -0
  115. package/dist/__tests__/imageEditorState.test.d.ts +3 -0
  116. package/dist/__tests__/imageEditorState.test.d.ts.map +1 -0
  117. package/dist/__tests__/imageEditorState.test.js +148 -0
  118. package/dist/__tests__/imageEditorState.test.js.map +1 -0
  119. package/dist/__tests__/inlinePreviewGutter.test.d.ts +2 -0
  120. package/dist/__tests__/inlinePreviewGutter.test.d.ts.map +1 -0
  121. package/dist/__tests__/inlinePreviewGutter.test.js +51 -0
  122. package/dist/__tests__/inlinePreviewGutter.test.js.map +1 -0
  123. package/dist/__tests__/inlinePreviewGutterAllBlocks.test.d.ts +2 -0
  124. package/dist/__tests__/inlinePreviewGutterAllBlocks.test.d.ts.map +1 -0
  125. package/dist/__tests__/inlinePreviewGutterAllBlocks.test.js +63 -0
  126. package/dist/__tests__/inlinePreviewGutterAllBlocks.test.js.map +1 -0
  127. package/dist/__tests__/jsonEditor.test.d.ts +2 -0
  128. package/dist/__tests__/jsonEditor.test.d.ts.map +1 -0
  129. package/dist/__tests__/jsonEditor.test.js +134 -0
  130. package/dist/__tests__/jsonEditor.test.js.map +1 -0
  131. package/dist/__tests__/layersPanel.test.d.ts +2 -0
  132. package/dist/__tests__/layersPanel.test.d.ts.map +1 -0
  133. package/dist/__tests__/layersPanel.test.js +84 -0
  134. package/dist/__tests__/layersPanel.test.js.map +1 -0
  135. package/dist/__tests__/linkDialogDocPicker.test.d.ts +7 -0
  136. package/dist/__tests__/linkDialogDocPicker.test.d.ts.map +1 -0
  137. package/dist/__tests__/linkDialogDocPicker.test.js +75 -0
  138. package/dist/__tests__/linkDialogDocPicker.test.js.map +1 -0
  139. package/dist/__tests__/outlinePanel.test.d.ts +2 -0
  140. package/dist/__tests__/outlinePanel.test.d.ts.map +1 -0
  141. package/dist/__tests__/outlinePanel.test.js +68 -0
  142. package/dist/__tests__/outlinePanel.test.js.map +1 -0
  143. package/dist/__tests__/plainHtmlPreview.test.d.ts +2 -0
  144. package/dist/__tests__/plainHtmlPreview.test.d.ts.map +1 -0
  145. package/dist/__tests__/plainHtmlPreview.test.js +87 -0
  146. package/dist/__tests__/plainHtmlPreview.test.js.map +1 -0
  147. package/dist/__tests__/propertiesPanel.test.d.ts +2 -0
  148. package/dist/__tests__/propertiesPanel.test.d.ts.map +1 -0
  149. package/dist/__tests__/propertiesPanel.test.js +64 -0
  150. package/dist/__tests__/propertiesPanel.test.js.map +1 -0
  151. package/dist/__tests__/recorderFormats.test.d.ts +2 -0
  152. package/dist/__tests__/recorderFormats.test.d.ts.map +1 -0
  153. package/dist/__tests__/recorderFormats.test.js +121 -0
  154. package/dist/__tests__/recorderFormats.test.js.map +1 -0
  155. package/dist/__tests__/recorderTimingJson.test.d.ts +2 -0
  156. package/dist/__tests__/recorderTimingJson.test.d.ts.map +1 -0
  157. package/dist/__tests__/recorderTimingJson.test.js +37 -0
  158. package/dist/__tests__/recorderTimingJson.test.js.map +1 -0
  159. package/dist/__tests__/templateAnnotationRoundTrip.test.d.ts +2 -0
  160. package/dist/__tests__/templateAnnotationRoundTrip.test.d.ts.map +1 -0
  161. package/dist/__tests__/templateAnnotationRoundTrip.test.js +31 -0
  162. package/dist/__tests__/templateAnnotationRoundTrip.test.js.map +1 -0
  163. package/dist/__tests__/tiptapBridge.test.js +13 -0
  164. package/dist/__tests__/tiptapBridge.test.js.map +1 -1
  165. package/dist/__tests__/useImageEditor.test.d.ts +2 -0
  166. package/dist/__tests__/useImageEditor.test.d.ts.map +1 -0
  167. package/dist/__tests__/useImageEditor.test.js +131 -0
  168. package/dist/__tests__/useImageEditor.test.js.map +1 -0
  169. package/dist/__tests__/useMediaRecorder.test.d.ts +2 -0
  170. package/dist/__tests__/useMediaRecorder.test.d.ts.map +1 -0
  171. package/dist/__tests__/useMediaRecorder.test.js +153 -0
  172. package/dist/__tests__/useMediaRecorder.test.js.map +1 -0
  173. package/dist/__tests__/versionHistory.test.d.ts +2 -0
  174. package/dist/__tests__/versionHistory.test.d.ts.map +1 -0
  175. package/dist/__tests__/versionHistory.test.js +124 -0
  176. package/dist/__tests__/versionHistory.test.js.map +1 -0
  177. package/dist/blockSlice.d.ts +24 -0
  178. package/dist/blockSlice.d.ts.map +1 -0
  179. package/dist/blockSlice.js +63 -0
  180. package/dist/blockSlice.js.map +1 -0
  181. package/dist/buildPreviewDoc.d.ts.map +1 -1
  182. package/dist/buildPreviewDoc.js +52 -2
  183. package/dist/buildPreviewDoc.js.map +1 -1
  184. package/dist/emojiData.d.ts +81 -0
  185. package/dist/emojiData.d.ts.map +1 -0
  186. package/dist/emojiData.js +1283 -0
  187. package/dist/emojiData.js.map +1 -0
  188. package/dist/fileKind.d.ts +6 -2
  189. package/dist/fileKind.d.ts.map +1 -1
  190. package/dist/fileKind.js +25 -4
  191. package/dist/fileKind.js.map +1 -1
  192. package/dist/hooks/useFileDrop.d.ts.map +1 -1
  193. package/dist/hooks/useFileDrop.js +40 -4
  194. package/dist/hooks/useFileDrop.js.map +1 -1
  195. package/dist/imageEditor/CanvasSurface.d.ts +31 -0
  196. package/dist/imageEditor/CanvasSurface.d.ts.map +1 -0
  197. package/dist/imageEditor/CanvasSurface.js +264 -0
  198. package/dist/imageEditor/CanvasSurface.js.map +1 -0
  199. package/dist/imageEditor/ImageVersionHistoryDropdown.d.ts +39 -0
  200. package/dist/imageEditor/ImageVersionHistoryDropdown.d.ts.map +1 -0
  201. package/dist/imageEditor/ImageVersionHistoryDropdown.js +283 -0
  202. package/dist/imageEditor/ImageVersionHistoryDropdown.js.map +1 -0
  203. package/dist/imageEditor/LayersPanel.d.ts +14 -0
  204. package/dist/imageEditor/LayersPanel.d.ts.map +1 -0
  205. package/dist/imageEditor/LayersPanel.js +43 -0
  206. package/dist/imageEditor/LayersPanel.js.map +1 -0
  207. package/dist/imageEditor/PropertiesPanel.d.ts +14 -0
  208. package/dist/imageEditor/PropertiesPanel.d.ts.map +1 -0
  209. package/dist/imageEditor/PropertiesPanel.js +97 -0
  210. package/dist/imageEditor/PropertiesPanel.js.map +1 -0
  211. package/dist/imageEditor/Toolbar.d.ts +30 -0
  212. package/dist/imageEditor/Toolbar.d.ts.map +1 -0
  213. package/dist/imageEditor/Toolbar.js +108 -0
  214. package/dist/imageEditor/Toolbar.js.map +1 -0
  215. package/dist/imageEditor/icons.d.ts +24 -0
  216. package/dist/imageEditor/icons.d.ts.map +1 -0
  217. package/dist/imageEditor/icons.js +45 -0
  218. package/dist/imageEditor/icons.js.map +1 -0
  219. package/dist/imageEditor/layers/EditorImageLayer.d.ts +16 -0
  220. package/dist/imageEditor/layers/EditorImageLayer.d.ts.map +1 -0
  221. package/dist/imageEditor/layers/EditorImageLayer.js +37 -0
  222. package/dist/imageEditor/layers/EditorImageLayer.js.map +1 -0
  223. package/dist/imageEditor/layers/EditorShapeLayer.d.ts +15 -0
  224. package/dist/imageEditor/layers/EditorShapeLayer.d.ts.map +1 -0
  225. package/dist/imageEditor/layers/EditorShapeLayer.js +20 -0
  226. package/dist/imageEditor/layers/EditorShapeLayer.js.map +1 -0
  227. package/dist/imageEditor/layers/EditorTextLayer.d.ts +18 -0
  228. package/dist/imageEditor/layers/EditorTextLayer.d.ts.map +1 -0
  229. package/dist/imageEditor/layers/EditorTextLayer.js +13 -0
  230. package/dist/imageEditor/layers/EditorTextLayer.js.map +1 -0
  231. package/dist/imageEditor/layers/SelectionHandles.d.ts +17 -0
  232. package/dist/imageEditor/layers/SelectionHandles.d.ts.map +1 -0
  233. package/dist/imageEditor/layers/SelectionHandles.js +19 -0
  234. package/dist/imageEditor/layers/SelectionHandles.js.map +1 -0
  235. package/dist/imageEditor/state.d.ts +76 -0
  236. package/dist/imageEditor/state.d.ts.map +1 -0
  237. package/dist/imageEditor/state.js +87 -0
  238. package/dist/imageEditor/state.js.map +1 -0
  239. package/dist/imageEditor/useImageEditor.d.ts +53 -0
  240. package/dist/imageEditor/useImageEditor.d.ts.map +1 -0
  241. package/dist/imageEditor/useImageEditor.js +244 -0
  242. package/dist/imageEditor/useImageEditor.js.map +1 -0
  243. package/dist/imageEditor/useImageEditorTokens.d.ts +16 -0
  244. package/dist/imageEditor/useImageEditorTokens.d.ts.map +1 -0
  245. package/dist/imageEditor/useImageEditorTokens.js +45 -0
  246. package/dist/imageEditor/useImageEditorTokens.js.map +1 -0
  247. package/dist/index.d.ts +48 -1
  248. package/dist/index.d.ts.map +1 -1
  249. package/dist/index.js +36 -0
  250. package/dist/index.js.map +1 -1
  251. package/dist/jsonEditor/EmbeddedRichTextField.d.ts +15 -0
  252. package/dist/jsonEditor/EmbeddedRichTextField.d.ts.map +1 -0
  253. package/dist/jsonEditor/EmbeddedRichTextField.js +74 -0
  254. package/dist/jsonEditor/EmbeddedRichTextField.js.map +1 -0
  255. package/dist/jsonEditor/JsonEditor.d.ts +36 -0
  256. package/dist/jsonEditor/JsonEditor.d.ts.map +1 -0
  257. package/dist/jsonEditor/JsonEditor.js +15 -0
  258. package/dist/jsonEditor/JsonEditor.js.map +1 -0
  259. package/dist/jsonEditor/JsonEditorContext.d.ts +28 -0
  260. package/dist/jsonEditor/JsonEditorContext.d.ts.map +1 -0
  261. package/dist/jsonEditor/JsonEditorContext.js +41 -0
  262. package/dist/jsonEditor/JsonEditorContext.js.map +1 -0
  263. package/dist/jsonEditor/RenderNode.d.ts +16 -0
  264. package/dist/jsonEditor/RenderNode.d.ts.map +1 -0
  265. package/dist/jsonEditor/RenderNode.js +32 -0
  266. package/dist/jsonEditor/RenderNode.js.map +1 -0
  267. package/dist/jsonEditor/editors.d.ts +36 -0
  268. package/dist/jsonEditor/editors.d.ts.map +1 -0
  269. package/dist/jsonEditor/editors.js +347 -0
  270. package/dist/jsonEditor/editors.js.map +1 -0
  271. package/dist/jsonEditor/index.d.ts +3 -0
  272. package/dist/jsonEditor/index.d.ts.map +1 -0
  273. package/dist/jsonEditor/index.js +2 -0
  274. package/dist/jsonEditor/index.js.map +1 -0
  275. package/dist/jsonEditor/useJsonEditorTokens.d.ts +13 -0
  276. package/dist/jsonEditor/useJsonEditorTokens.d.ts.map +1 -0
  277. package/dist/jsonEditor/useJsonEditorTokens.js +38 -0
  278. package/dist/jsonEditor/useJsonEditorTokens.js.map +1 -0
  279. package/dist/recorder/RecorderButton.d.ts +31 -0
  280. package/dist/recorder/RecorderButton.d.ts.map +1 -0
  281. package/dist/recorder/RecorderButton.js +24 -0
  282. package/dist/recorder/RecorderButton.js.map +1 -0
  283. package/dist/recorder/RecorderModal.d.ts +59 -0
  284. package/dist/recorder/RecorderModal.d.ts.map +1 -0
  285. package/dist/recorder/RecorderModal.js +333 -0
  286. package/dist/recorder/RecorderModal.js.map +1 -0
  287. package/dist/recorder/RecorderPanel.d.ts +25 -0
  288. package/dist/recorder/RecorderPanel.d.ts.map +1 -0
  289. package/dist/recorder/RecorderPanel.js +30 -0
  290. package/dist/recorder/RecorderPanel.js.map +1 -0
  291. package/dist/recorder/formats.d.ts +51 -0
  292. package/dist/recorder/formats.d.ts.map +1 -0
  293. package/dist/recorder/formats.js +144 -0
  294. package/dist/recorder/formats.js.map +1 -0
  295. package/dist/recorder/hooks/useMediaRecorder.d.ts +90 -0
  296. package/dist/recorder/hooks/useMediaRecorder.d.ts.map +1 -0
  297. package/dist/recorder/hooks/useMediaRecorder.js +277 -0
  298. package/dist/recorder/hooks/useMediaRecorder.js.map +1 -0
  299. package/dist/recorder/hooks/useStreamPreview.d.ts +22 -0
  300. package/dist/recorder/hooks/useStreamPreview.d.ts.map +1 -0
  301. package/dist/recorder/hooks/useStreamPreview.js +44 -0
  302. package/dist/recorder/hooks/useStreamPreview.js.map +1 -0
  303. package/dist/recorder/sources/cameraStream.d.ts +22 -0
  304. package/dist/recorder/sources/cameraStream.d.ts.map +1 -0
  305. package/dist/recorder/sources/cameraStream.js +24 -0
  306. package/dist/recorder/sources/cameraStream.js.map +1 -0
  307. package/dist/recorder/sources/micStream.d.ts +15 -0
  308. package/dist/recorder/sources/micStream.d.ts.map +1 -0
  309. package/dist/recorder/sources/micStream.js +24 -0
  310. package/dist/recorder/sources/micStream.js.map +1 -0
  311. package/dist/recorder/sources/screenStream.d.ts +53 -0
  312. package/dist/recorder/sources/screenStream.d.ts.map +1 -0
  313. package/dist/recorder/sources/screenStream.js +114 -0
  314. package/dist/recorder/sources/screenStream.js.map +1 -0
  315. package/dist/recorder/timingJson.d.ts +51 -0
  316. package/dist/recorder/timingJson.d.ts.map +1 -0
  317. package/dist/recorder/timingJson.js +42 -0
  318. package/dist/recorder/timingJson.js.map +1 -0
  319. package/dist/tiptap/TiptapAudio.d.ts +26 -0
  320. package/dist/tiptap/TiptapAudio.d.ts.map +1 -0
  321. package/dist/tiptap/TiptapAudio.js +58 -0
  322. package/dist/tiptap/TiptapAudio.js.map +1 -0
  323. package/dist/tiptap/TiptapVideo.d.ts +30 -0
  324. package/dist/tiptap/TiptapVideo.d.ts.map +1 -0
  325. package/dist/tiptap/TiptapVideo.js +66 -0
  326. package/dist/tiptap/TiptapVideo.js.map +1 -0
  327. package/dist/tiptap/useResolvedMediaSrc.d.ts +2 -0
  328. package/dist/tiptap/useResolvedMediaSrc.d.ts.map +1 -0
  329. package/dist/tiptap/useResolvedMediaSrc.js +42 -0
  330. package/dist/tiptap/useResolvedMediaSrc.js.map +1 -0
  331. package/dist/tiptapBridge.d.ts.map +1 -1
  332. package/dist/tiptapBridge.js +171 -14
  333. package/dist/tiptapBridge.js.map +1 -1
  334. package/dist/useHeadingLayout.d.ts +54 -0
  335. package/dist/useHeadingLayout.d.ts.map +1 -0
  336. package/dist/useHeadingLayout.js +260 -0
  337. package/dist/useHeadingLayout.js.map +1 -0
  338. package/dist/utils/collectInlineFontAwesomeCss.d.ts +21 -0
  339. package/dist/utils/collectInlineFontAwesomeCss.d.ts.map +1 -0
  340. package/dist/utils/collectInlineFontAwesomeCss.js +68 -0
  341. package/dist/utils/collectInlineFontAwesomeCss.js.map +1 -0
  342. package/dist/utils/dropUtils.d.ts +21 -2
  343. package/dist/utils/dropUtils.d.ts.map +1 -1
  344. package/dist/utils/dropUtils.js +43 -4
  345. package/dist/utils/dropUtils.js.map +1 -1
  346. package/dist/utils/normalizeMalformedAssetUrl.d.ts +15 -0
  347. package/dist/utils/normalizeMalformedAssetUrl.d.ts.map +1 -0
  348. package/dist/utils/normalizeMalformedAssetUrl.js +27 -0
  349. package/dist/utils/normalizeMalformedAssetUrl.js.map +1 -0
  350. package/package.json +8 -5
  351. package/src/DocumentSettingsDialog.tsx +266 -0
  352. package/src/EditorContext.tsx +534 -10
  353. package/src/EditorShell.tsx +571 -55
  354. package/src/EmojiPicker.tsx +332 -0
  355. package/src/ImageEditor.tsx +327 -0
  356. package/src/ImageNodeView.tsx +222 -21
  357. package/src/ImageViewer.tsx +221 -0
  358. package/src/InlineIcon.ts +84 -0
  359. package/src/InlinePreviewGutter.tsx +582 -0
  360. package/src/LinkDialog.tsx +276 -0
  361. package/src/MentionExtension.tsx +10 -7
  362. package/src/OutlinePanel.tsx +295 -0
  363. package/src/PlainHtmlPreview.tsx +211 -0
  364. package/src/PreviewControls.tsx +130 -24
  365. package/src/PreviewPanel.tsx +38 -21
  366. package/src/RawEditor.tsx +215 -4
  367. package/src/RecorderEntry.tsx +164 -0
  368. package/src/TemplateAnnotation.ts +32 -6
  369. package/src/TemplatePicker.tsx +818 -0
  370. package/src/ThemeCustomizerPanel.tsx +595 -0
  371. package/src/ThemePicker.tsx +319 -0
  372. package/src/Toolbar.tsx +708 -111
  373. package/src/VersionHistoryPanel.tsx +329 -0
  374. package/src/ViewMenuPanel.tsx +188 -0
  375. package/src/WysiwygEditor.tsx +229 -9
  376. package/src/__tests__/detectMarkdown.test.ts +0 -15
  377. package/src/__tests__/documentSettingsDialog.test.tsx +147 -0
  378. package/src/__tests__/emojiPicker.test.tsx +133 -0
  379. package/src/__tests__/fileKind.test.ts +16 -0
  380. package/src/__tests__/imageEditAffordance.test.tsx +268 -0
  381. package/src/__tests__/imageEditorShell.test.tsx +57 -0
  382. package/src/__tests__/imageEditorState.test.ts +171 -0
  383. package/src/__tests__/inlinePreviewGutter.test.tsx +62 -0
  384. package/src/__tests__/inlinePreviewGutterAllBlocks.test.tsx +103 -0
  385. package/src/__tests__/jsonEditor.test.tsx +168 -0
  386. package/src/__tests__/layersPanel.test.tsx +97 -0
  387. package/src/__tests__/linkDialogDocPicker.test.tsx +137 -0
  388. package/src/__tests__/outlinePanel.test.tsx +79 -0
  389. package/src/__tests__/plainHtmlPreview.test.tsx +107 -0
  390. package/src/__tests__/propertiesPanel.test.tsx +69 -0
  391. package/src/__tests__/recorderFormats.test.ts +146 -0
  392. package/src/__tests__/recorderTimingJson.test.ts +41 -0
  393. package/src/__tests__/templateAnnotationRoundTrip.test.ts +34 -0
  394. package/src/__tests__/tiptapBridge.test.ts +15 -0
  395. package/src/__tests__/useImageEditor.test.tsx +159 -0
  396. package/src/__tests__/useMediaRecorder.test.ts +186 -0
  397. package/src/__tests__/versionHistory.test.tsx +197 -0
  398. package/src/blockSlice.ts +75 -0
  399. package/src/buildPreviewDoc.ts +61 -6
  400. package/src/emojiData.ts +1337 -0
  401. package/src/fileKind.ts +30 -6
  402. package/src/hooks/useFileDrop.ts +40 -4
  403. package/src/imageEditor/CanvasSurface.tsx +402 -0
  404. package/src/imageEditor/ImageVersionHistoryDropdown.tsx +396 -0
  405. package/src/imageEditor/LayersPanel.tsx +143 -0
  406. package/src/imageEditor/PropertiesPanel.tsx +428 -0
  407. package/src/imageEditor/Toolbar.tsx +242 -0
  408. package/src/imageEditor/icons.tsx +144 -0
  409. package/src/imageEditor/image-editor.css +450 -0
  410. package/src/imageEditor/layers/EditorImageLayer.tsx +45 -0
  411. package/src/imageEditor/layers/EditorShapeLayer.tsx +62 -0
  412. package/src/imageEditor/layers/EditorTextLayer.tsx +45 -0
  413. package/src/imageEditor/layers/SelectionHandles.tsx +86 -0
  414. package/src/imageEditor/state.ts +153 -0
  415. package/src/imageEditor/useImageEditor.ts +328 -0
  416. package/src/imageEditor/useImageEditorTokens.ts +70 -0
  417. package/src/index.ts +82 -0
  418. package/src/jsonEditor/EmbeddedRichTextField.tsx +81 -0
  419. package/src/jsonEditor/JsonEditor.tsx +81 -0
  420. package/src/jsonEditor/JsonEditorContext.tsx +75 -0
  421. package/src/jsonEditor/RenderNode.tsx +66 -0
  422. package/src/jsonEditor/editors.tsx +678 -0
  423. package/src/jsonEditor/index.ts +2 -0
  424. package/src/jsonEditor/json-editor.css +463 -0
  425. package/src/jsonEditor/useJsonEditorTokens.ts +63 -0
  426. package/src/recorder/RecorderButton.tsx +72 -0
  427. package/src/recorder/RecorderModal.tsx +596 -0
  428. package/src/recorder/RecorderPanel.tsx +93 -0
  429. package/src/recorder/formats.ts +159 -0
  430. package/src/recorder/hooks/useMediaRecorder.ts +378 -0
  431. package/src/recorder/hooks/useStreamPreview.ts +47 -0
  432. package/src/recorder/sources/cameraStream.ts +32 -0
  433. package/src/recorder/sources/micStream.ts +25 -0
  434. package/src/recorder/sources/screenStream.ts +162 -0
  435. package/src/recorder/timingJson.ts +66 -0
  436. package/src/styles/editor.css +2490 -51
  437. package/src/styles/image-edit-affordance.css +201 -0
  438. package/src/styles/index.css +10 -0
  439. package/src/tiptap/TiptapAudio.tsx +86 -0
  440. package/src/tiptap/TiptapVideo.tsx +119 -0
  441. package/src/tiptap/useResolvedMediaSrc.ts +47 -0
  442. package/src/tiptapBridge.ts +188 -20
  443. package/src/useHeadingLayout.ts +294 -0
  444. package/src/utils/collectInlineFontAwesomeCss.ts +69 -0
  445. package/src/utils/dropUtils.ts +54 -6
  446. package/src/utils/normalizeMalformedAssetUrl.ts +22 -0
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Format probing for MediaRecorder.
3
+ *
4
+ * Different browsers expose different container/codec combinations. Chrome
5
+ * and Firefox produce WebM (VP8/VP9 + Opus); Safari produces MP4 (H.264 +
6
+ * AAC). We probe at runtime via `MediaRecorder.isTypeSupported()` and pick
7
+ * the best supported option, falling back to whatever the browser hands
8
+ * back when no probe succeeds.
9
+ */
10
+
11
+ /** What the recorded stream is intended to capture. */
12
+ export type CaptureKind = 'audio' | 'video';
13
+
14
+ /** A probed format choice — what to pass to `MediaRecorder` and where to write it. */
15
+ export interface ResolvedFormat {
16
+ /** MIME type to pass to `new MediaRecorder(stream, { mimeType })`. Empty string means "let the browser pick". */
17
+ mimeType: string;
18
+ /** File extension to use when writing to the container, including the leading dot. */
19
+ extension: string;
20
+ /** Container directory inside the `ContentContainer` (no trailing slash). */
21
+ directory: 'audio' | 'video';
22
+ }
23
+
24
+ /**
25
+ * Preferred MIME types for audio-only recording, in priority order. The
26
+ * first one `MediaRecorder.isTypeSupported()` accepts wins.
27
+ *
28
+ * Opus in a WebM container is the modern default (Chrome, Firefox, Edge).
29
+ * MP4/AAC covers Safari. Bare strings are kept as a final fallback for
30
+ * older browsers that don't accept codec hints.
31
+ */
32
+ const AUDIO_CANDIDATES = [
33
+ 'audio/webm;codecs=opus',
34
+ 'audio/webm',
35
+ 'audio/mp4;codecs=mp4a.40.2',
36
+ 'audio/mp4',
37
+ 'audio/ogg;codecs=opus',
38
+ ];
39
+
40
+ /**
41
+ * Preferred MIME types for video recording. VP9/Opus on top because it
42
+ * yields good quality at modest bitrate in Chrome/Firefox. VP8 follows for
43
+ * older Chromium. MP4/H.264 covers Safari.
44
+ */
45
+ const VIDEO_CANDIDATES = [
46
+ 'video/webm;codecs=vp9,opus',
47
+ 'video/webm;codecs=vp8,opus',
48
+ 'video/webm',
49
+ 'video/mp4;codecs=avc1.42E01E,mp4a.40.2',
50
+ 'video/mp4',
51
+ ];
52
+
53
+ /**
54
+ * Map a chosen MIME type to a file extension. Best-effort — if we can't
55
+ * tell, default to `.bin` so the file is at least retrievable.
56
+ */
57
+ function extensionForMime(mimeType: string): string {
58
+ const m = mimeType.toLowerCase();
59
+ if (m.startsWith('audio/webm')) return '.webm';
60
+ if (m.startsWith('audio/ogg')) return '.ogg';
61
+ if (m.startsWith('audio/mp4')) return '.m4a';
62
+ if (m.startsWith('audio/mpeg')) return '.mp3';
63
+ if (m.startsWith('audio/wav')) return '.wav';
64
+ if (m.startsWith('video/webm')) return '.webm';
65
+ if (m.startsWith('video/mp4')) return '.mp4';
66
+ return '.bin';
67
+ }
68
+
69
+ /**
70
+ * Probe `MediaRecorder.isTypeSupported()` and return the first supported
71
+ * MIME type from the candidate list. Returns `null` when the
72
+ * MediaRecorder API itself is unavailable or none of the candidates pass.
73
+ */
74
+ function probeMimeType(candidates: readonly string[]): string | null {
75
+ if (typeof MediaRecorder === 'undefined') return null;
76
+ for (const candidate of candidates) {
77
+ try {
78
+ if (MediaRecorder.isTypeSupported(candidate)) return candidate;
79
+ } catch {
80
+ // isTypeSupported isn't supposed to throw, but Safari has historically
81
+ // misbehaved on unknown codec strings. Keep probing.
82
+ }
83
+ }
84
+ return null;
85
+ }
86
+
87
+ /**
88
+ * Resolve the format the recorder will use for a given capture kind. If a
89
+ * `preferred` MIME type is supported, it wins; otherwise we fall through
90
+ * the priority list. When nothing matches (extremely old browser), we
91
+ * return an empty `mimeType` — `MediaRecorder` will pick a default and we
92
+ * tag the file with `.webm` as a best guess.
93
+ */
94
+ export function resolveFormat(kind: CaptureKind, preferred?: string): ResolvedFormat {
95
+ const candidates = kind === 'audio' ? AUDIO_CANDIDATES : VIDEO_CANDIDATES;
96
+ const probed = (preferred && probeMimeType([preferred])) ?? probeMimeType(candidates) ?? '';
97
+ const directory = kind === 'audio' ? 'audio' : 'video';
98
+ const extension = probed ? extensionForMime(probed) : '.webm';
99
+ return { mimeType: probed, extension, directory };
100
+ }
101
+
102
+ /**
103
+ * `MediaRecorder` support probe. Returns false when running in a
104
+ * non-browser environment (e.g. SSR) or on a browser that doesn't
105
+ * implement the API at all.
106
+ */
107
+ export function supportsMediaRecorder(): boolean {
108
+ return typeof MediaRecorder !== 'undefined';
109
+ }
110
+
111
+ /**
112
+ * `getUserMedia` support probe (for mic / camera capture).
113
+ */
114
+ export function supportsUserMedia(): boolean {
115
+ return (
116
+ typeof navigator !== 'undefined' &&
117
+ typeof navigator.mediaDevices !== 'undefined' &&
118
+ typeof navigator.mediaDevices.getUserMedia === 'function'
119
+ );
120
+ }
121
+
122
+ /**
123
+ * `getDisplayMedia` support probe (for screen capture). Browsers may
124
+ * implement `mediaDevices` without `getDisplayMedia` (Firefox on Android
125
+ * being the long-standing example), so this is its own probe.
126
+ */
127
+ export function supportsDisplayMedia(): boolean {
128
+ return (
129
+ typeof navigator !== 'undefined' &&
130
+ typeof navigator.mediaDevices !== 'undefined' &&
131
+ typeof navigator.mediaDevices.getDisplayMedia === 'function'
132
+ );
133
+ }
134
+
135
+ /**
136
+ * Build a default filename for a recording. `basename` is a hint
137
+ * (e.g. user-typed name); when omitted, a sortable timestamp is used so
138
+ * concurrent recordings don't collide.
139
+ */
140
+ export function buildFilename(kind: CaptureKind, extension: string, basename?: string): string {
141
+ const safe = basename
142
+ ? basename
143
+ .trim()
144
+ .replace(/[\\/:*?"<>|]+/g, '-')
145
+ .replace(/\s+/g, '-')
146
+ : '';
147
+ if (safe) return `${safe}${extension}`;
148
+ const now = new Date();
149
+ const stamp =
150
+ now.getFullYear().toString().padStart(4, '0') +
151
+ (now.getMonth() + 1).toString().padStart(2, '0') +
152
+ now.getDate().toString().padStart(2, '0') +
153
+ '-' +
154
+ now.getHours().toString().padStart(2, '0') +
155
+ now.getMinutes().toString().padStart(2, '0') +
156
+ now.getSeconds().toString().padStart(2, '0');
157
+ const prefix = kind === 'audio' ? 'narration' : 'recording';
158
+ return `${prefix}-${stamp}${extension}`;
159
+ }
@@ -0,0 +1,378 @@
1
+ /**
2
+ * useMediaRecorder
3
+ *
4
+ * React wrapper around `MediaRecorder` that handles stream acquisition,
5
+ * the recorder lifecycle, and produces a single `Blob` on stop. Selects
6
+ * a browser-supported MIME type via {@link resolveFormat}.
7
+ *
8
+ * Mirrors the shape of `useVideoExport` in `@bendyline/squisq-video-react`
9
+ * (request → start → stop → blob), inverted for capture rather than
10
+ * export.
11
+ */
12
+
13
+ import { useCallback, useEffect, useRef, useState } from 'react';
14
+ import {
15
+ resolveFormat,
16
+ supportsMediaRecorder,
17
+ type CaptureKind,
18
+ type ResolvedFormat,
19
+ } from '../formats.js';
20
+ import { requestMicStream } from '../sources/micStream.js';
21
+ import { requestCameraStream } from '../sources/cameraStream.js';
22
+ import { requestScreenStream, type ScreenStreamHandle } from '../sources/screenStream.js';
23
+
24
+ /** Which capture source to use. `screen+mic` mixes the microphone into the screen stream. */
25
+ export type RecorderSource = 'mic' | 'camera' | 'screen' | 'screen+mic';
26
+
27
+ /** Discriminated state describing what the recorder is currently doing. */
28
+ export type RecorderState =
29
+ | 'idle'
30
+ | 'requesting'
31
+ | 'ready'
32
+ | 'recording'
33
+ | 'stopping'
34
+ | 'stopped'
35
+ | 'error';
36
+
37
+ export interface UseMediaRecorderOptions {
38
+ /** Which capture pipeline to use. */
39
+ source: RecorderSource;
40
+ /**
41
+ * Preferred MIME type override. When the browser supports it, this
42
+ * wins over the default candidate list. When unset (or unsupported),
43
+ * the hook probes a built-in priority list.
44
+ */
45
+ mimeType?: string;
46
+ /** Video track constraints for camera / screen sources. */
47
+ videoConstraints?: MediaTrackConstraints | boolean;
48
+ /** Audio track constraints for mic / camera / screen+mic sources. */
49
+ audioConstraints?: MediaTrackConstraints | boolean;
50
+ /**
51
+ * Bits-per-second hint passed to `MediaRecorder`. Most browsers cap to
52
+ * reasonable defaults internally; leaving this undefined is usually
53
+ * fine.
54
+ */
55
+ bitsPerSecond?: number;
56
+ /**
57
+ * Whether to attempt to capture system audio when `source === 'screen'`
58
+ * or `'screen+mic'`. Browser support is limited (desktop Chromium
59
+ * only); when unsupported the resulting stream simply omits it.
60
+ */
61
+ systemAudio?: boolean;
62
+ }
63
+
64
+ export interface UseMediaRecorderResult {
65
+ /** Current recorder state. */
66
+ state: RecorderState;
67
+ /** Live `MediaStream` after `request()` succeeds; useful for preview. */
68
+ stream: MediaStream | null;
69
+ /** Final `Blob` after `stop()` resolves, or `null` while recording. */
70
+ blob: Blob | null;
71
+ /** MIME type the recorder actually used (after `request()`). */
72
+ mimeType: string | null;
73
+ /** File extension matching `mimeType` (e.g. `.webm`). */
74
+ extension: string | null;
75
+ /** Suggested container directory (`'audio'` for mic, `'video'` for camera/screen). */
76
+ directory: 'audio' | 'video' | null;
77
+ /** Milliseconds elapsed since `start()` was called. Updates ~10× per second while recording. */
78
+ durationMs: number;
79
+ /** Most recent error, if any. */
80
+ error: Error | null;
81
+ /**
82
+ * Acquire the stream and prepare a `MediaRecorder`. After this resolves
83
+ * the hook is in `'ready'` state and a `<video>`/`<audio>` element can
84
+ * preview `stream`. Call `start()` to begin recording.
85
+ */
86
+ request: () => Promise<void>;
87
+ /** Start recording. Must be called from `'ready'`. */
88
+ start: () => void;
89
+ /**
90
+ * Stop recording and resolve with the resulting `Blob`. Safe to call
91
+ * from `'recording'`; a no-op from any other state (resolves with the
92
+ * existing `blob`, or `null`).
93
+ */
94
+ stop: () => Promise<Blob | null>;
95
+ /**
96
+ * Tear everything down — stops the recorder if running, releases all
97
+ * tracks, disposes the AudioContext mixer (if any), and returns to
98
+ * `'idle'`. Always safe to call.
99
+ */
100
+ cancel: () => void;
101
+ /** Reset state without releasing the stream. Useful for re-recording. */
102
+ reset: () => void;
103
+ }
104
+
105
+ /**
106
+ * Acquire the right stream for the chosen source. Returns the stream
107
+ * plus an optional `dispose` callback for sources that own auxiliary
108
+ * resources (e.g. the screen+mic AudioContext mixer).
109
+ */
110
+ async function acquireStream(
111
+ opts: UseMediaRecorderOptions,
112
+ ): Promise<{ stream: MediaStream; dispose: () => void }> {
113
+ switch (opts.source) {
114
+ case 'mic': {
115
+ const audio = typeof opts.audioConstraints === 'object' ? opts.audioConstraints : undefined;
116
+ const stream = await requestMicStream(audio);
117
+ return { stream, dispose: () => {} };
118
+ }
119
+ case 'camera': {
120
+ const stream = await requestCameraStream({
121
+ video: opts.videoConstraints ?? true,
122
+ audio: opts.audioConstraints ?? true,
123
+ });
124
+ return { stream, dispose: () => {} };
125
+ }
126
+ case 'screen':
127
+ case 'screen+mic': {
128
+ const handle: ScreenStreamHandle = await requestScreenStream({
129
+ video: opts.videoConstraints ?? true,
130
+ systemAudio: opts.systemAudio ?? false,
131
+ includeMicrophone: opts.source === 'screen+mic',
132
+ microphoneConstraints:
133
+ typeof opts.audioConstraints === 'object' ? opts.audioConstraints : undefined,
134
+ });
135
+ return { stream: handle.stream, dispose: handle.dispose };
136
+ }
137
+ }
138
+ }
139
+
140
+ /** Whether the chosen source records video (vs. audio-only). */
141
+ function captureKindFor(source: RecorderSource): CaptureKind {
142
+ return source === 'mic' ? 'audio' : 'video';
143
+ }
144
+
145
+ /**
146
+ * Returns the kind of capture that the given source produces. Exposed
147
+ * separately from {@link useMediaRecorder} so non-React callers
148
+ * (e.g. headless tests) can resolve a format up front.
149
+ */
150
+ export function getCaptureKind(source: RecorderSource): CaptureKind {
151
+ return captureKindFor(source);
152
+ }
153
+
154
+ export function useMediaRecorder(options: UseMediaRecorderOptions): UseMediaRecorderResult {
155
+ const [state, setState] = useState<RecorderState>('idle');
156
+ const [stream, setStream] = useState<MediaStream | null>(null);
157
+ const [blob, setBlob] = useState<Blob | null>(null);
158
+ const [format, setFormat] = useState<ResolvedFormat | null>(null);
159
+ const [durationMs, setDurationMs] = useState(0);
160
+ const [error, setError] = useState<Error | null>(null);
161
+
162
+ const recorderRef = useRef<MediaRecorder | null>(null);
163
+ const chunksRef = useRef<Blob[]>([]);
164
+ const disposeStreamRef = useRef<(() => void) | null>(null);
165
+ const startTimestampRef = useRef<number | null>(null);
166
+ const tickerRef = useRef<ReturnType<typeof setInterval> | null>(null);
167
+ const stopResolversRef = useRef<Array<(blob: Blob | null) => void>>([]);
168
+
169
+ // Stable copy of options for callbacks that read them late. Re-evaluated
170
+ // each render, but each callback closes over the ref so we don't have
171
+ // to recreate them on every options change.
172
+ const optionsRef = useRef(options);
173
+ optionsRef.current = options;
174
+
175
+ const clearTicker = useCallback(() => {
176
+ if (tickerRef.current !== null) {
177
+ clearInterval(tickerRef.current);
178
+ tickerRef.current = null;
179
+ }
180
+ }, []);
181
+
182
+ const releaseStream = useCallback(() => {
183
+ const s = recorderRef.current?.stream;
184
+ if (s) {
185
+ s.getTracks().forEach((t) => t.stop());
186
+ }
187
+ // Also stop whatever we last handed to setStream — it may differ
188
+ // from recorderRef.current.stream when stream/recorder lifecycles
189
+ // diverged (e.g. cancel before start).
190
+ setStream((current) => {
191
+ current?.getTracks().forEach((t) => t.stop());
192
+ return null;
193
+ });
194
+ disposeStreamRef.current?.();
195
+ disposeStreamRef.current = null;
196
+ }, []);
197
+
198
+ const reset = useCallback(() => {
199
+ setBlob(null);
200
+ setDurationMs(0);
201
+ setError(null);
202
+ chunksRef.current = [];
203
+ startTimestampRef.current = null;
204
+ clearTicker();
205
+ // If a stream is still live from a prior `request()`, hop back to
206
+ // `'ready'` so the UI can offer "record again" without the caller
207
+ // having to re-acquire permissions. Otherwise drop to `'idle'`.
208
+ const rec = recorderRef.current;
209
+ if (rec && rec.state === 'inactive' && rec.stream.active) {
210
+ setState('ready');
211
+ } else {
212
+ setState('idle');
213
+ }
214
+ }, [clearTicker]);
215
+
216
+ const cancel = useCallback(() => {
217
+ const rec = recorderRef.current;
218
+ if (rec && rec.state !== 'inactive') {
219
+ try {
220
+ rec.stop();
221
+ } catch {
222
+ // Ignore — we're tearing down anyway.
223
+ }
224
+ }
225
+ recorderRef.current = null;
226
+ releaseStream();
227
+ clearTicker();
228
+ chunksRef.current = [];
229
+ startTimestampRef.current = null;
230
+ // Any in-flight stop() promises won't get a blob.
231
+ stopResolversRef.current.splice(0).forEach((resolve) => resolve(null));
232
+ setBlob(null);
233
+ setDurationMs(0);
234
+ setError(null);
235
+ setState('idle');
236
+ }, [clearTicker, releaseStream]);
237
+
238
+ const request = useCallback(async () => {
239
+ if (!supportsMediaRecorder()) {
240
+ const err = new Error('MediaRecorder is not supported in this environment.');
241
+ setError(err);
242
+ setState('error');
243
+ throw err;
244
+ }
245
+ if (state === 'recording' || state === 'stopping') {
246
+ // Don't start a parallel acquisition while one is in flight.
247
+ return;
248
+ }
249
+ setError(null);
250
+ setState('requesting');
251
+ try {
252
+ const { stream: nextStream, dispose } = await acquireStream(optionsRef.current);
253
+ const resolved = resolveFormat(
254
+ captureKindFor(optionsRef.current.source),
255
+ optionsRef.current.mimeType,
256
+ );
257
+ const recorderOptions: MediaRecorderOptions = {};
258
+ if (resolved.mimeType) recorderOptions.mimeType = resolved.mimeType;
259
+ if (optionsRef.current.bitsPerSecond) {
260
+ recorderOptions.bitsPerSecond = optionsRef.current.bitsPerSecond;
261
+ }
262
+ const recorder = new MediaRecorder(nextStream, recorderOptions);
263
+
264
+ recorder.ondataavailable = (e) => {
265
+ if (e.data && e.data.size > 0) chunksRef.current.push(e.data);
266
+ };
267
+ recorder.onstop = () => {
268
+ // The recorded MIME type is authoritative once data is in hand —
269
+ // some browsers down-negotiate the format (e.g. drop codec hint).
270
+ const recordedType = recorder.mimeType || resolved.mimeType || 'application/octet-stream';
271
+ const finalBlob = new Blob(chunksRef.current, { type: recordedType });
272
+ chunksRef.current = [];
273
+ setBlob(finalBlob);
274
+ setState('stopped');
275
+ clearTicker();
276
+ stopResolversRef.current.splice(0).forEach((resolve) => resolve(finalBlob));
277
+ };
278
+ recorder.onerror = (event) => {
279
+ const detail = (event as unknown as { error?: DOMException }).error;
280
+ const err = detail instanceof Error ? detail : new Error('Recorder error');
281
+ setError(err);
282
+ setState('error');
283
+ clearTicker();
284
+ stopResolversRef.current.splice(0).forEach((resolve) => resolve(null));
285
+ };
286
+
287
+ recorderRef.current = recorder;
288
+ disposeStreamRef.current = dispose;
289
+ setStream(nextStream);
290
+ setFormat(resolved);
291
+ setBlob(null);
292
+ setDurationMs(0);
293
+ setState('ready');
294
+ } catch (err: unknown) {
295
+ const normalized = err instanceof Error ? err : new Error('Stream acquisition failed');
296
+ setError(normalized);
297
+ setState('error');
298
+ throw normalized;
299
+ }
300
+ }, [state, clearTicker]);
301
+
302
+ const start = useCallback(() => {
303
+ const rec = recorderRef.current;
304
+ if (!rec) {
305
+ const err = new Error('Recorder is not ready. Call request() first.');
306
+ setError(err);
307
+ setState('error');
308
+ return;
309
+ }
310
+ if (rec.state === 'recording') return;
311
+ chunksRef.current = [];
312
+ setBlob(null);
313
+ setDurationMs(0);
314
+ startTimestampRef.current = Date.now();
315
+ rec.start(1000);
316
+ setState('recording');
317
+ clearTicker();
318
+ tickerRef.current = setInterval(() => {
319
+ if (startTimestampRef.current !== null) {
320
+ setDurationMs(Date.now() - startTimestampRef.current);
321
+ }
322
+ }, 100);
323
+ }, [clearTicker]);
324
+
325
+ const stop = useCallback((): Promise<Blob | null> => {
326
+ const rec = recorderRef.current;
327
+ if (!rec || rec.state === 'inactive') {
328
+ return Promise.resolve(blob);
329
+ }
330
+ setState('stopping');
331
+ return new Promise<Blob | null>((resolve) => {
332
+ stopResolversRef.current.push(resolve);
333
+ try {
334
+ rec.stop();
335
+ } catch (err: unknown) {
336
+ const normalized = err instanceof Error ? err : new Error('Failed to stop recorder');
337
+ setError(normalized);
338
+ setState('error');
339
+ clearTicker();
340
+ stopResolversRef.current.splice(0).forEach((r) => r(null));
341
+ }
342
+ });
343
+ }, [blob, clearTicker]);
344
+
345
+ // Final unmount cleanup — make sure we don't leak the camera light /
346
+ // screen-capture indicator if the component disappears mid-recording.
347
+ useEffect(() => {
348
+ return () => {
349
+ const rec = recorderRef.current;
350
+ if (rec && rec.state !== 'inactive') {
351
+ try {
352
+ rec.stop();
353
+ } catch {
354
+ // ignore
355
+ }
356
+ }
357
+ releaseStream();
358
+ clearTicker();
359
+ stopResolversRef.current.splice(0).forEach((resolve) => resolve(null));
360
+ };
361
+ }, [releaseStream, clearTicker]);
362
+
363
+ return {
364
+ state,
365
+ stream,
366
+ blob,
367
+ mimeType: format?.mimeType ?? null,
368
+ extension: format?.extension ?? null,
369
+ directory: format?.directory ?? null,
370
+ durationMs,
371
+ error,
372
+ request,
373
+ start,
374
+ stop,
375
+ cancel,
376
+ reset,
377
+ };
378
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * useStreamPreview — binds a `MediaStream` to a `<video>` element's
3
+ * `srcObject`. Decouples the preview surface from `useMediaRecorder`,
4
+ * letting hosts compose the preview element however they like.
5
+ */
6
+
7
+ import { useEffect, type RefObject } from 'react';
8
+
9
+ /**
10
+ * Assign `stream` to `<video>.srcObject` whenever either changes; clears
11
+ * it on unmount or when `stream` is `null`. The element is set to
12
+ * `playsInline` + `muted` automatically because previewing your own
13
+ * microphone with audio playthrough creates a feedback loop.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * const videoRef = useRef<HTMLVideoElement>(null);
18
+ * const { stream } = useMediaRecorder({ source: 'camera' });
19
+ * useStreamPreview(videoRef, stream);
20
+ * return <video ref={videoRef} autoPlay />;
21
+ * ```
22
+ */
23
+ export function useStreamPreview(
24
+ ref: RefObject<HTMLVideoElement | null>,
25
+ stream: MediaStream | null,
26
+ ): void {
27
+ useEffect(() => {
28
+ const el = ref.current;
29
+ if (!el) return;
30
+ el.muted = true;
31
+ el.playsInline = true;
32
+ el.srcObject = stream;
33
+ if (stream) {
34
+ // Some browsers don't auto-play on srcObject assignment; trigger
35
+ // it explicitly and ignore the inevitable "user gesture required"
36
+ // rejections — the preview will play on the next interaction.
37
+ void el.play().catch(() => {});
38
+ }
39
+ return () => {
40
+ // Only detach when this effect is tearing down. Don't stop tracks
41
+ // — that's the recorder's responsibility.
42
+ if (el.srcObject === stream) {
43
+ el.srcObject = null;
44
+ }
45
+ };
46
+ }, [ref, stream]);
47
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Camera + microphone capture via `getUserMedia({ video, audio })`.
3
+ */
4
+
5
+ import { supportsUserMedia } from '../formats.js';
6
+
7
+ export interface CameraStreamOptions {
8
+ /** Video track constraints (resolution, facing mode, frame rate). Pass `true` for browser default, or `false` to omit video. */
9
+ video?: boolean | MediaTrackConstraints;
10
+ /** Audio track constraints. Pass `true` for browser default, or `false` to omit audio. */
11
+ audio?: boolean | MediaTrackConstraints;
12
+ }
13
+
14
+ /**
15
+ * Request a camera + mic `MediaStream`. Caller owns the stream and must
16
+ * stop its tracks when done.
17
+ *
18
+ * Both tracks are requested by default. To capture video only, pass
19
+ * `audio: false`; to capture audio only use {@link requestMicStream}
20
+ * instead.
21
+ *
22
+ * @throws When `mediaDevices` is unavailable, or when the user denies
23
+ * permission.
24
+ */
25
+ export async function requestCameraStream(options?: CameraStreamOptions): Promise<MediaStream> {
26
+ if (!supportsUserMedia()) {
27
+ throw new Error('navigator.mediaDevices.getUserMedia is not available in this environment.');
28
+ }
29
+ const video = options?.video ?? true;
30
+ const audio = options?.audio ?? true;
31
+ return navigator.mediaDevices.getUserMedia({ video, audio });
32
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Microphone-only capture via `getUserMedia({ audio: true })`.
3
+ */
4
+
5
+ import { supportsUserMedia } from '../formats.js';
6
+
7
+ /**
8
+ * Request a microphone-only `MediaStream`. Caller owns the stream and
9
+ * must stop its tracks when done.
10
+ *
11
+ * @param constraints - Optional audio constraints (sample rate, device
12
+ * id, echo cancellation, etc.). Defaults to `true` — let the browser
13
+ * pick.
14
+ * @throws When `mediaDevices` is unavailable, or when the user denies
15
+ * permission (the underlying `getUserMedia` rejection propagates).
16
+ */
17
+ export async function requestMicStream(constraints?: MediaTrackConstraints): Promise<MediaStream> {
18
+ if (!supportsUserMedia()) {
19
+ throw new Error('navigator.mediaDevices.getUserMedia is not available in this environment.');
20
+ }
21
+ return navigator.mediaDevices.getUserMedia({
22
+ audio: constraints ?? true,
23
+ video: false,
24
+ });
25
+ }