@haklex/rich-ext-whiteboard 0.0.0-stage → 0.65.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 (316) hide show
  1. package/README.md +147 -2
  2. package/dist/WhiteboardConfigContext.d.ts +14 -0
  3. package/dist/WhiteboardConfigContext.d.ts.map +1 -0
  4. package/dist/WhiteboardDisplayRenderer.d.ts +14 -0
  5. package/dist/WhiteboardDisplayRenderer.d.ts.map +1 -0
  6. package/dist/WhiteboardEditNode.d.ts +14 -0
  7. package/dist/WhiteboardEditNode.d.ts.map +1 -0
  8. package/dist/WhiteboardEditRenderer.d.ts +8 -0
  9. package/dist/WhiteboardEditRenderer.d.ts.map +1 -0
  10. package/dist/WhiteboardEditorDialog.d.ts +23 -0
  11. package/dist/WhiteboardEditorDialog.d.ts.map +1 -0
  12. package/dist/WhiteboardExpandShell-D1s7iDKh.js +2550 -0
  13. package/dist/WhiteboardExpandShell.d.ts +9 -0
  14. package/dist/WhiteboardExpandShell.d.ts.map +1 -0
  15. package/dist/WhiteboardFrameStates.d.ts +11 -0
  16. package/dist/WhiteboardFrameStates.d.ts.map +1 -0
  17. package/dist/WhiteboardNode.d.ts +22 -0
  18. package/dist/WhiteboardNode.d.ts.map +1 -0
  19. package/dist/WhiteboardOptionsMenu.d.ts +16 -0
  20. package/dist/WhiteboardOptionsMenu.d.ts.map +1 -0
  21. package/dist/WhiteboardPlugin.d.ts +3 -0
  22. package/dist/WhiteboardPlugin.d.ts.map +1 -0
  23. package/dist/WhiteboardSSRRenderer.d.ts +8 -0
  24. package/dist/WhiteboardSSRRenderer.d.ts.map +1 -0
  25. package/dist/acceptance/brainstorm-board.d.ts +3 -0
  26. package/dist/acceptance/brainstorm-board.d.ts.map +1 -0
  27. package/dist/acceptance/brainstorm.test.d.ts +2 -0
  28. package/dist/acceptance/brainstorm.test.d.ts.map +1 -0
  29. package/dist/acceptance/fixtures.d.ts +5 -0
  30. package/dist/acceptance/fixtures.d.ts.map +1 -0
  31. package/dist/acceptance/review-fixes.test.d.ts +2 -0
  32. package/dist/acceptance/review-fixes.test.d.ts.map +1 -0
  33. package/dist/acceptance/roundtrip.test.d.ts +2 -0
  34. package/dist/acceptance/roundtrip.test.d.ts.map +1 -0
  35. package/dist/canvas-state.d.ts +5 -0
  36. package/dist/canvas-state.d.ts.map +1 -0
  37. package/dist/display.test.d.ts +2 -0
  38. package/dist/display.test.d.ts.map +1 -0
  39. package/dist/editor/FrameNameEditor.d.ts +6 -0
  40. package/dist/editor/FrameNameEditor.d.ts.map +1 -0
  41. package/dist/editor/MobileDock.d.ts +6 -0
  42. package/dist/editor/MobileDock.d.ts.map +1 -0
  43. package/dist/editor/RichTextEditor.d.ts +7 -0
  44. package/dist/editor/RichTextEditor.d.ts.map +1 -0
  45. package/dist/editor/RichTextFormatBar.d.ts +8 -0
  46. package/dist/editor/RichTextFormatBar.d.ts.map +1 -0
  47. package/dist/editor/StylePanel.d.ts +6 -0
  48. package/dist/editor/StylePanel.d.ts.map +1 -0
  49. package/dist/editor/StyleSheet.d.ts +7 -0
  50. package/dist/editor/StyleSheet.d.ts.map +1 -0
  51. package/dist/editor/TextEditor.d.ts +7 -0
  52. package/dist/editor/TextEditor.d.ts.map +1 -0
  53. package/dist/editor/Toolbar.d.ts +20 -0
  54. package/dist/editor/Toolbar.d.ts.map +1 -0
  55. package/dist/editor/WhiteboardCanvas.d.ts +14 -0
  56. package/dist/editor/WhiteboardCanvas.d.ts.map +1 -0
  57. package/dist/editor/WhiteboardEditor.d.ts +10 -0
  58. package/dist/editor/WhiteboardEditor.d.ts.map +1 -0
  59. package/dist/editor/ZoomControls.d.ts +7 -0
  60. package/dist/editor/ZoomControls.d.ts.map +1 -0
  61. package/dist/editor/actions.d.ts +13 -0
  62. package/dist/editor/actions.d.ts.map +1 -0
  63. package/dist/editor/actions.test.d.ts +2 -0
  64. package/dist/editor/actions.test.d.ts.map +1 -0
  65. package/dist/editor/binding-actions.d.ts +8 -0
  66. package/dist/editor/binding-actions.d.ts.map +1 -0
  67. package/dist/editor/binding.test.d.ts +2 -0
  68. package/dist/editor/binding.test.d.ts.map +1 -0
  69. package/dist/editor/card-tool.test.d.ts +2 -0
  70. package/dist/editor/card-tool.test.d.ts.map +1 -0
  71. package/dist/editor/chrome.css.d.ts +24 -0
  72. package/dist/editor/chrome.css.d.ts.map +1 -0
  73. package/dist/editor/clipboard-actions.d.ts +6 -0
  74. package/dist/editor/clipboard-actions.d.ts.map +1 -0
  75. package/dist/editor/clipboard-events.test.d.ts +2 -0
  76. package/dist/editor/clipboard-events.test.d.ts.map +1 -0
  77. package/dist/editor/clipboard.test.d.ts +2 -0
  78. package/dist/editor/clipboard.test.d.ts.map +1 -0
  79. package/dist/editor/editor.css.d.ts +5 -0
  80. package/dist/editor/editor.css.d.ts.map +1 -0
  81. package/dist/editor/elbow.test.d.ts +2 -0
  82. package/dist/editor/elbow.test.d.ts.map +1 -0
  83. package/dist/editor/focus.test.d.ts +2 -0
  84. package/dist/editor/focus.test.d.ts.map +1 -0
  85. package/dist/editor/frames.test.d.ts +2 -0
  86. package/dist/editor/frames.test.d.ts.map +1 -0
  87. package/dist/editor/gestures.d.ts +11 -0
  88. package/dist/editor/gestures.d.ts.map +1 -0
  89. package/dist/editor/grid.d.ts +9 -0
  90. package/dist/editor/grid.d.ts.map +1 -0
  91. package/dist/editor/grid.test.d.ts +2 -0
  92. package/dist/editor/grid.test.d.ts.map +1 -0
  93. package/dist/editor/history.d.ts +13 -0
  94. package/dist/editor/history.d.ts.map +1 -0
  95. package/dist/editor/image-actions.d.ts +17 -0
  96. package/dist/editor/image-actions.d.ts.map +1 -0
  97. package/dist/editor/image.test.d.ts +2 -0
  98. package/dist/editor/image.test.d.ts.map +1 -0
  99. package/dist/editor/layout.d.ts +4 -0
  100. package/dist/editor/layout.d.ts.map +1 -0
  101. package/dist/editor/linear-editor.d.ts +28 -0
  102. package/dist/editor/linear-editor.d.ts.map +1 -0
  103. package/dist/editor/linear-editor.test.d.ts +2 -0
  104. package/dist/editor/linear-editor.test.d.ts.map +1 -0
  105. package/dist/editor/overlay/LinearHandles.d.ts +6 -0
  106. package/dist/editor/overlay/LinearHandles.d.ts.map +1 -0
  107. package/dist/editor/overlay/SelectionOverlay.d.ts +7 -0
  108. package/dist/editor/overlay/SelectionOverlay.d.ts.map +1 -0
  109. package/dist/editor/overlay/TransformHandles.d.ts +6 -0
  110. package/dist/editor/overlay/TransformHandles.d.ts.map +1 -0
  111. package/dist/editor/render-fidelity.test.d.ts +2 -0
  112. package/dist/editor/render-fidelity.test.d.ts.map +1 -0
  113. package/dist/editor/richtext-actions.d.ts +6 -0
  114. package/dist/editor/richtext-actions.d.ts.map +1 -0
  115. package/dist/editor/richtext-edit.test.d.ts +2 -0
  116. package/dist/editor/richtext-edit.test.d.ts.map +1 -0
  117. package/dist/editor/richtext-editor.css.d.ts +17 -0
  118. package/dist/editor/richtext-editor.css.d.ts.map +1 -0
  119. package/dist/editor/richtext-format.test.d.ts +2 -0
  120. package/dist/editor/richtext-format.test.d.ts.map +1 -0
  121. package/dist/editor/richtext-load.test.d.ts +2 -0
  122. package/dist/editor/richtext-load.test.d.ts.map +1 -0
  123. package/dist/editor/selection-utils.d.ts +17 -0
  124. package/dist/editor/selection-utils.d.ts.map +1 -0
  125. package/dist/editor/selection.test.d.ts +2 -0
  126. package/dist/editor/selection.test.d.ts.map +1 -0
  127. package/dist/editor/shadow.test.d.ts +2 -0
  128. package/dist/editor/shadow.test.d.ts.map +1 -0
  129. package/dist/editor/shortcuts.d.ts +16 -0
  130. package/dist/editor/shortcuts.d.ts.map +1 -0
  131. package/dist/editor/store.d.ts +21 -0
  132. package/dist/editor/store.d.ts.map +1 -0
  133. package/dist/editor/store.test.d.ts +2 -0
  134. package/dist/editor/store.test.d.ts.map +1 -0
  135. package/dist/editor/style-options.d.ts +21 -0
  136. package/dist/editor/style-options.d.ts.map +1 -0
  137. package/dist/editor/style-props.d.ts +10 -0
  138. package/dist/editor/style-props.d.ts.map +1 -0
  139. package/dist/editor/style-rows.d.ts +4 -0
  140. package/dist/editor/style-rows.d.ts.map +1 -0
  141. package/dist/editor/svg-paste.test.d.ts +2 -0
  142. package/dist/editor/svg-paste.test.d.ts.map +1 -0
  143. package/dist/editor/svg.test.d.ts +2 -0
  144. package/dist/editor/svg.test.d.ts.map +1 -0
  145. package/dist/editor/text-actions.d.ts +15 -0
  146. package/dist/editor/text-actions.d.ts.map +1 -0
  147. package/dist/editor/text-editor.css.d.ts +3 -0
  148. package/dist/editor/text-editor.css.d.ts.map +1 -0
  149. package/dist/editor/text.test.d.ts +2 -0
  150. package/dist/editor/text.test.d.ts.map +1 -0
  151. package/dist/editor/tools/card.d.ts +5 -0
  152. package/dist/editor/tools/card.d.ts.map +1 -0
  153. package/dist/editor/tools/creation.d.ts +8 -0
  154. package/dist/editor/tools/creation.d.ts.map +1 -0
  155. package/dist/editor/tools/eraser.d.ts +3 -0
  156. package/dist/editor/tools/eraser.d.ts.map +1 -0
  157. package/dist/editor/tools/freedraw.d.ts +3 -0
  158. package/dist/editor/tools/freedraw.d.ts.map +1 -0
  159. package/dist/editor/tools/hand.d.ts +3 -0
  160. package/dist/editor/tools/hand.d.ts.map +1 -0
  161. package/dist/editor/tools/image.d.ts +3 -0
  162. package/dist/editor/tools/image.d.ts.map +1 -0
  163. package/dist/editor/tools/index.d.ts +9 -0
  164. package/dist/editor/tools/index.d.ts.map +1 -0
  165. package/dist/editor/tools/linear.d.ts +10 -0
  166. package/dist/editor/tools/linear.d.ts.map +1 -0
  167. package/dist/editor/tools/point-gesture.d.ts +10 -0
  168. package/dist/editor/tools/point-gesture.d.ts.map +1 -0
  169. package/dist/editor/tools/selection.d.ts +9 -0
  170. package/dist/editor/tools/selection.d.ts.map +1 -0
  171. package/dist/editor/tools/shape.d.ts +15 -0
  172. package/dist/editor/tools/shape.d.ts.map +1 -0
  173. package/dist/editor/tools/text.d.ts +3 -0
  174. package/dist/editor/tools/text.d.ts.map +1 -0
  175. package/dist/editor/tools/transform-gesture.d.ts +13 -0
  176. package/dist/editor/tools/transform-gesture.d.ts.map +1 -0
  177. package/dist/editor/tools/types.d.ts +28 -0
  178. package/dist/editor/tools/types.d.ts.map +1 -0
  179. package/dist/editor/tools.test.d.ts +2 -0
  180. package/dist/editor/tools.test.d.ts.map +1 -0
  181. package/dist/editor/touch.test.d.ts +2 -0
  182. package/dist/editor/touch.test.d.ts.map +1 -0
  183. package/dist/editor/transform.d.ts +25 -0
  184. package/dist/editor/transform.d.ts.map +1 -0
  185. package/dist/editor/transform.test.d.ts +2 -0
  186. package/dist/editor/transform.test.d.ts.map +1 -0
  187. package/dist/editor/types.d.ts +41 -0
  188. package/dist/editor/types.d.ts.map +1 -0
  189. package/dist/editor/viewport.d.ts +14 -0
  190. package/dist/editor/viewport.d.ts.map +1 -0
  191. package/dist/index.d.ts +27 -0
  192. package/dist/index.d.ts.map +1 -0
  193. package/dist/index.mjs +4941 -0
  194. package/dist/model/bindable.d.ts +3 -0
  195. package/dist/model/bindable.d.ts.map +1 -0
  196. package/dist/model/binding.d.ts +15 -0
  197. package/dist/model/binding.d.ts.map +1 -0
  198. package/dist/model/bounds.d.ts +17 -0
  199. package/dist/model/bounds.d.ts.map +1 -0
  200. package/dist/model/bounds.test.d.ts +2 -0
  201. package/dist/model/bounds.test.d.ts.map +1 -0
  202. package/dist/model/clipboard.d.ts +11 -0
  203. package/dist/model/clipboard.d.ts.map +1 -0
  204. package/dist/model/clone.d.ts +6 -0
  205. package/dist/model/clone.d.ts.map +1 -0
  206. package/dist/model/create.d.ts +17 -0
  207. package/dist/model/create.d.ts.map +1 -0
  208. package/dist/model/create.test.d.ts +2 -0
  209. package/dist/model/create.test.d.ts.map +1 -0
  210. package/dist/model/defaults.d.ts +22 -0
  211. package/dist/model/defaults.d.ts.map +1 -0
  212. package/dist/model/elbow.d.ts +16 -0
  213. package/dist/model/elbow.d.ts.map +1 -0
  214. package/dist/model/elbow.test.d.ts +2 -0
  215. package/dist/model/elbow.test.d.ts.map +1 -0
  216. package/dist/model/fractional-index.d.ts +9 -0
  217. package/dist/model/fractional-index.d.ts.map +1 -0
  218. package/dist/model/fractional-index.test.d.ts +2 -0
  219. package/dist/model/fractional-index.test.d.ts.map +1 -0
  220. package/dist/model/frames.d.ts +8 -0
  221. package/dist/model/frames.d.ts.map +1 -0
  222. package/dist/model/frames.test.d.ts +2 -0
  223. package/dist/model/frames.test.d.ts.map +1 -0
  224. package/dist/model/geometry.d.ts +13 -0
  225. package/dist/model/geometry.d.ts.map +1 -0
  226. package/dist/model/linear-points.d.ts +5 -0
  227. package/dist/model/linear-points.d.ts.map +1 -0
  228. package/dist/model/measure.d.ts +16 -0
  229. package/dist/model/measure.d.ts.map +1 -0
  230. package/dist/model/mutate.d.ts +8 -0
  231. package/dist/model/mutate.d.ts.map +1 -0
  232. package/dist/model/random.d.ts +3 -0
  233. package/dist/model/random.d.ts.map +1 -0
  234. package/dist/model/restore.d.ts +6 -0
  235. package/dist/model/restore.d.ts.map +1 -0
  236. package/dist/model/restore.test.d.ts +2 -0
  237. package/dist/model/restore.test.d.ts.map +1 -0
  238. package/dist/model/richtext-editable.d.ts +3 -0
  239. package/dist/model/richtext-editable.d.ts.map +1 -0
  240. package/dist/model/richtext-layout.d.ts +6 -0
  241. package/dist/model/richtext-layout.d.ts.map +1 -0
  242. package/dist/model/richtext-layout.test.d.ts +2 -0
  243. package/dist/model/richtext-layout.test.d.ts.map +1 -0
  244. package/dist/model/richtext.d.ts +42 -0
  245. package/dist/model/richtext.d.ts.map +1 -0
  246. package/dist/model/shadow.d.ts +5 -0
  247. package/dist/model/shadow.d.ts.map +1 -0
  248. package/dist/model/svg.d.ts +8 -0
  249. package/dist/model/svg.d.ts.map +1 -0
  250. package/dist/model/svg.test.d.ts +2 -0
  251. package/dist/model/svg.test.d.ts.map +1 -0
  252. package/dist/model/text-layout.d.ts +13 -0
  253. package/dist/model/text-layout.d.ts.map +1 -0
  254. package/dist/model/text.test.d.ts +2 -0
  255. package/dist/model/text.test.d.ts.map +1 -0
  256. package/dist/rename.test.d.ts +2 -0
  257. package/dist/rename.test.d.ts.map +1 -0
  258. package/dist/rich-ext-whiteboard.css +2 -0
  259. package/dist/scene/InteractiveScene.d.ts +11 -0
  260. package/dist/scene/InteractiveScene.d.ts.map +1 -0
  261. package/dist/scene/Scene.d.ts +27 -0
  262. package/dist/scene/Scene.d.ts.map +1 -0
  263. package/dist/scene/context.d.ts +4 -0
  264. package/dist/scene/context.d.ts.map +1 -0
  265. package/dist/scene/elements.d.ts +7 -0
  266. package/dist/scene/elements.d.ts.map +1 -0
  267. package/dist/scene/fidelity.test.d.ts +2 -0
  268. package/dist/scene/fidelity.test.d.ts.map +1 -0
  269. package/dist/scene/fill.test.d.ts +2 -0
  270. package/dist/scene/fill.test.d.ts.map +1 -0
  271. package/dist/scene/fonts.d.ts +11 -0
  272. package/dist/scene/fonts.d.ts.map +1 -0
  273. package/dist/scene/freedraw.d.ts +3 -0
  274. package/dist/scene/freedraw.d.ts.map +1 -0
  275. package/dist/scene/normalize.d.ts +4 -0
  276. package/dist/scene/normalize.d.ts.map +1 -0
  277. package/dist/scene/richtext/RichTextBody.d.ts +6 -0
  278. package/dist/scene/richtext/RichTextBody.d.ts.map +1 -0
  279. package/dist/scene/richtext/RichTextContent.d.ts +6 -0
  280. package/dist/scene/richtext/RichTextContent.d.ts.map +1 -0
  281. package/dist/scene/richtext.test.d.ts +2 -0
  282. package/dist/scene/richtext.test.d.ts.map +1 -0
  283. package/dist/scene/rough.d.ts +19 -0
  284. package/dist/scene/rough.d.ts.map +1 -0
  285. package/dist/scene/scene.test.d.ts +2 -0
  286. package/dist/scene/scene.test.d.ts.map +1 -0
  287. package/dist/scene/shadow.d.ts +6 -0
  288. package/dist/scene/shadow.d.ts.map +1 -0
  289. package/dist/scene/shadow.test.d.ts +2 -0
  290. package/dist/scene/shadow.test.d.ts.map +1 -0
  291. package/dist/scene/styles.css.d.ts +7 -0
  292. package/dist/scene/styles.css.d.ts.map +1 -0
  293. package/dist/scene/svg-element.d.ts +6 -0
  294. package/dist/scene/svg-element.d.ts.map +1 -0
  295. package/dist/scene/svg.test.d.ts +2 -0
  296. package/dist/scene/svg.test.d.ts.map +1 -0
  297. package/dist/scene/types.d.ts +149 -0
  298. package/dist/scene/types.d.ts.map +1 -0
  299. package/dist/slot.d.ts +11 -0
  300. package/dist/slot.d.ts.map +1 -0
  301. package/dist/static.d.ts +18 -0
  302. package/dist/static.d.ts.map +1 -0
  303. package/dist/static.mjs +1 -0
  304. package/dist/styles.css.d.ts +29 -0
  305. package/dist/styles.css.d.ts.map +1 -0
  306. package/dist/transformer.d.ts +2 -0
  307. package/dist/transformer.d.ts.map +1 -0
  308. package/dist/types.d.ts +15 -0
  309. package/dist/types.d.ts.map +1 -0
  310. package/dist/types.test.d.ts +2 -0
  311. package/dist/types.test.d.ts.map +1 -0
  312. package/dist/useWhiteboardData.d.ts +16 -0
  313. package/dist/useWhiteboardData.d.ts.map +1 -0
  314. package/dist/useWhiteboardFont.d.ts +3 -0
  315. package/dist/useWhiteboardFont.d.ts.map +1 -0
  316. package/package.json +70 -3
@@ -0,0 +1,2550 @@
1
+ import { EXCALIDRAW_BLOCK_TRANSFORMER } from "@haklex/rich-headless/transformers";
2
+ import { Component, Suspense, createContext, lazy, memo, use, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ import { createRendererDecoration, useColorScheme } from "@haklex/rich-editor/static";
5
+ import { Maximize2, PenLine, ScanSearch, TriangleAlert, X, ZoomIn, ZoomOut } from "lucide-react";
6
+ import { getStroke } from "perfect-freehand";
7
+ import { RoughGenerator } from "roughjs/bin/generator";
8
+ import { ViewportGate } from "@haklex/rich-editor-ui";
9
+ import { DecoratorNode } from "lexical";
10
+ //#region \0rolldown/runtime.js
11
+ var __defProp = Object.defineProperty;
12
+ var __exportAll = (all, no_symbols) => {
13
+ let target = {};
14
+ for (var name in all) __defProp(target, name, {
15
+ get: all[name],
16
+ enumerable: true
17
+ });
18
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
19
+ return target;
20
+ };
21
+ //#endregion
22
+ //#region src/slot.ts
23
+ var WHITEBOARD_NODE_KEY = "Whiteboard";
24
+ //#endregion
25
+ //#region src/styles.css.ts
26
+ var whiteboardStaticContainer = "_1xd3mo40";
27
+ var whiteboardEditorContainer = "_1xd3mo41";
28
+ var whiteboardPlaceholder = "_1xd3mo42";
29
+ var whiteboardStateLayer = "_1xd3mo43";
30
+ var whiteboardStateIcon = "_1xd3mo44";
31
+ var whiteboardLoading = "_1xd3mo46";
32
+ var whiteboardEmpty = "_1xd3mo47";
33
+ var whiteboardError = "_1xd3mo48";
34
+ var whiteboardErrorIcon = "_1xd3mo49";
35
+ var whiteboardFullscreenPopup = "_1xd3mo4b";
36
+ var whiteboardDialogHeader = "_1xd3mo4c";
37
+ var whiteboardDialogHeaderTitle = "_1xd3mo4d";
38
+ var whiteboardDialogTitle = "_1xd3mo4e";
39
+ var whiteboardHeaderClose = "_1xd3mo4g";
40
+ var whiteboardDialogCanvas = "_1xd3mo4h";
41
+ var whiteboardDialogBody = "_1xd3mo4i";
42
+ var whiteboardShell = "_1xd3mo4j";
43
+ var whiteboardSavedDot = "_1xd3mo4k";
44
+ var whiteboardOptionsActions = "_1xd3mo4l";
45
+ var whiteboardOptionsAdvanced = "_1xd3mo4m";
46
+ var whiteboardOptionsHeading = "_1xd3mo4n";
47
+ var whiteboardOptionsGroup = "_1xd3mo4o";
48
+ var whiteboardOptionsLabel = "_1xd3mo4p";
49
+ var whiteboardEditOverlay = "_1xd3mo4q";
50
+ var whiteboardEditLabel = "_1xd3mo4r";
51
+ //#endregion
52
+ //#region src/types.ts
53
+ var LOCAL_SCENE_PATH = /^(?:\.{1,2}\/)?[\w-][\w./-]*\.excalidraw$/;
54
+ function isLocalScenePath(ref) {
55
+ return LOCAL_SCENE_PATH.test(ref);
56
+ }
57
+ function parseSnapshot(raw) {
58
+ if (!raw || !raw.trim()) return null;
59
+ try {
60
+ const json = JSON.parse(raw);
61
+ if (json && typeof json === "object") return {
62
+ type: "inline",
63
+ data: json
64
+ };
65
+ } catch {}
66
+ const lines = raw.split("\n");
67
+ const firstLine = lines[0].trim();
68
+ if (!firstLine.startsWith("http") && !firstLine.startsWith("blob:") && !firstLine.startsWith("ref:") && !isLocalScenePath(firstLine)) return null;
69
+ const remaining = lines.slice(1).join("\n").trim();
70
+ if (remaining) try {
71
+ const delta = JSON.parse(remaining);
72
+ if (delta && typeof delta === "object") return {
73
+ type: "delta",
74
+ baseUrl: firstLine,
75
+ delta
76
+ };
77
+ } catch {}
78
+ return {
79
+ type: "remote",
80
+ url: firstLine
81
+ };
82
+ }
83
+ function serializeSnapshot(snapshot) {
84
+ switch (snapshot.type) {
85
+ case "inline": return JSON.stringify(snapshot.data);
86
+ case "remote": return snapshot.url;
87
+ case "delta": return [snapshot.baseUrl, JSON.stringify(snapshot.delta)].join("\n");
88
+ }
89
+ }
90
+ //#endregion
91
+ //#region src/WhiteboardConfigContext.tsx
92
+ var WhiteboardConfigContext = createContext({});
93
+ function WhiteboardConfigProvider({ apiUrl, fontCssHref, saveSnapshot, uploadFile, children }) {
94
+ const value = useMemo(() => ({
95
+ apiUrl,
96
+ fontCssHref,
97
+ saveSnapshot,
98
+ uploadFile
99
+ }), [
100
+ apiUrl,
101
+ fontCssHref,
102
+ saveSnapshot,
103
+ uploadFile
104
+ ]);
105
+ return /* @__PURE__ */ jsx(WhiteboardConfigContext.Provider, {
106
+ value,
107
+ children
108
+ });
109
+ }
110
+ function useWhiteboardConfig() {
111
+ return use(WhiteboardConfigContext);
112
+ }
113
+ //#endregion
114
+ //#region src/model/geometry.ts
115
+ function rotatePoint([x, y], [cx, cy], angle) {
116
+ if (!angle) return [x, y];
117
+ const cos = Math.cos(angle);
118
+ const sin = Math.sin(angle);
119
+ const dx = x - cx;
120
+ const dy = y - cy;
121
+ return [cx + dx * cos - dy * sin, cy + dx * sin + dy * cos];
122
+ }
123
+ function distance([ax, ay], [bx, by]) {
124
+ return Math.hypot(bx - ax, by - ay);
125
+ }
126
+ function distanceToSegment(p, a, b) {
127
+ const [px, py] = p;
128
+ const [ax, ay] = a;
129
+ const [bx, by] = b;
130
+ const dx = bx - ax;
131
+ const dy = by - ay;
132
+ const lengthSq = dx * dx + dy * dy;
133
+ if (lengthSq === 0) return distance(p, a);
134
+ const t = Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / lengthSq));
135
+ return distance(p, [ax + t * dx, ay + t * dy]);
136
+ }
137
+ function boundsOfPoints(points) {
138
+ let minX = Infinity;
139
+ let minY = Infinity;
140
+ let maxX = -Infinity;
141
+ let maxY = -Infinity;
142
+ for (const [x, y] of points) {
143
+ minX = Math.min(minX, x);
144
+ minY = Math.min(minY, y);
145
+ maxX = Math.max(maxX, x);
146
+ maxY = Math.max(maxY, y);
147
+ }
148
+ return [
149
+ minX,
150
+ minY,
151
+ maxX,
152
+ maxY
153
+ ];
154
+ }
155
+ function boundsContain(outer, inner) {
156
+ return inner[0] >= outer[0] && inner[1] >= outer[1] && inner[2] <= outer[2] && inner[3] <= outer[3];
157
+ }
158
+ function boundsIntersect(a, b) {
159
+ return a[0] <= b[2] && a[2] >= b[0] && a[1] <= b[3] && a[3] >= b[1];
160
+ }
161
+ function normalizeBox(a, b) {
162
+ return [
163
+ Math.min(a[0], b[0]),
164
+ Math.min(a[1], b[1]),
165
+ Math.max(a[0], b[0]),
166
+ Math.max(a[1], b[1])
167
+ ];
168
+ }
169
+ function angleOf(el) {
170
+ return typeof el.angle === "number" && Number.isFinite(el.angle) ? el.angle : 0;
171
+ }
172
+ //#endregion
173
+ //#region src/model/bounds.ts
174
+ function isLinear(el) {
175
+ return el.type === "line" || el.type === "arrow" || el.type === "freedraw";
176
+ }
177
+ function pointsOf(el) {
178
+ return el.points && el.points.length > 0 ? el.points : [[0, 0]];
179
+ }
180
+ function getElementCenter(el) {
181
+ if (isLinear(el)) {
182
+ const [minX, minY, maxX, maxY] = boundsOfPoints(pointsOf(el));
183
+ return [el.x + (minX + maxX) / 2, el.y + (minY + maxY) / 2];
184
+ }
185
+ return [el.x + el.width / 2, el.y + el.height / 2];
186
+ }
187
+ function getLinearAbsolutePoints(el) {
188
+ const center = getElementCenter(el);
189
+ return pointsOf(el).map(([px, py]) => rotatePoint([el.x + px, el.y + py], center, angleOf(el)));
190
+ }
191
+ function getElementAbsoluteCorners(el) {
192
+ if (isLinear(el)) return getLinearAbsolutePoints(el);
193
+ const center = getElementCenter(el);
194
+ const { x, y, width: w, height: h } = el;
195
+ return [
196
+ [x, y],
197
+ [x + w, y],
198
+ [x + w, y + h],
199
+ [x, y + h]
200
+ ].map((p) => rotatePoint(p, center, angleOf(el)));
201
+ }
202
+ function getElementBounds(el) {
203
+ return boundsOfPoints(getElementAbsoluteCorners(el));
204
+ }
205
+ function getCommonBounds(elements) {
206
+ if (elements.length === 0) return [
207
+ 0,
208
+ 0,
209
+ 0,
210
+ 0
211
+ ];
212
+ return boundsOfPoints(elements.flatMap((el) => getElementAbsoluteCorners(el)));
213
+ }
214
+ function toLocalPoint(el, p) {
215
+ const [x, y] = rotatePoint(p, getElementCenter(el), -angleOf(el));
216
+ return [x - el.x, y - el.y];
217
+ }
218
+ var isFilled = (el) => !!el.backgroundColor && el.backgroundColor !== "transparent";
219
+ function hitRectangle(w, h, [lx, ly], tol, filled) {
220
+ if (!(lx >= -tol && lx <= w + tol && ly >= -tol && ly <= h + tol)) return false;
221
+ if (filled) return true;
222
+ return lx <= tol || lx >= w - tol || ly <= tol || ly >= h - tol;
223
+ }
224
+ function hitEllipse(w, h, [lx, ly], tol, filled) {
225
+ const rx = w / 2;
226
+ const ry = h / 2;
227
+ if (rx <= 0 || ry <= 0) return false;
228
+ const dx = lx - rx;
229
+ const dy = ly - ry;
230
+ const norm = Math.sqrt(dx * dx / (rx * rx) + dy * dy / (ry * ry));
231
+ const edgeDistance = Math.abs(norm - 1) * Math.min(rx, ry);
232
+ if (filled && norm <= 1) return true;
233
+ return edgeDistance <= tol;
234
+ }
235
+ function hitDiamond(w, h, p, tol, filled) {
236
+ const top = [w / 2, 0];
237
+ const right = [w, h / 2];
238
+ const bottom = [w / 2, h];
239
+ const left = [0, h / 2];
240
+ if (filled && w > 0 && h > 0) {
241
+ if (Math.abs(p[0] - w / 2) / (w / 2) + Math.abs(p[1] - h / 2) / (h / 2) <= 1) return true;
242
+ }
243
+ return [
244
+ [top, right],
245
+ [right, bottom],
246
+ [bottom, left],
247
+ [left, top]
248
+ ].some(([a, b]) => distanceToSegment(p, a, b) <= tol);
249
+ }
250
+ function hitPolyline(points, p, tol) {
251
+ if (points.length === 1) return distanceToSegment(p, points[0], points[0]) <= tol;
252
+ for (let i = 0; i < points.length - 1; i++) if (distanceToSegment(p, points[i], points[i + 1]) <= tol) return true;
253
+ return false;
254
+ }
255
+ function hitTestElement(el, p, tolerance) {
256
+ if (el.isDeleted) return false;
257
+ const tol = tolerance + (Number.isFinite(el.strokeWidth) ? el.strokeWidth : 0) / 2;
258
+ if (isLinear(el)) return hitPolyline(getLinearAbsolutePoints(el), p, tol);
259
+ const local = toLocalPoint(el, p);
260
+ const { width: w, height: h } = el;
261
+ switch (el.type) {
262
+ case "rectangle":
263
+ case "embeddable":
264
+ case "iframe": return hitRectangle(w, h, local, tol, isFilled(el));
265
+ case "ellipse": return hitEllipse(w, h, local, tol, isFilled(el));
266
+ case "diamond": return hitDiamond(w, h, local, tol, isFilled(el));
267
+ case "frame":
268
+ case "magicframe": {
269
+ const [lx, ly] = local;
270
+ return lx >= 0 && lx <= w && ly >= -20 && ly < 0 || hitRectangle(w, h, local, tol, false);
271
+ }
272
+ default: return hitRectangle(w, h, local, tol, true);
273
+ }
274
+ }
275
+ function elementsInBox(elements, box) {
276
+ return elements.filter((el) => !el.isDeleted && boundsContain(box, getElementBounds(el)));
277
+ }
278
+ //#endregion
279
+ //#region src/scene/fonts.ts
280
+ var HAND_FONT_STACK = "\"LXGW WenKai Screen\", \"LXGW WenKai\", \"Excalifont\", \"Virgil\", \"Comic Sans MS\", \"Segoe Print\", \"Bradley Hand\", cursive";
281
+ var SANS_FONT_STACK = "Helvetica, \"PingFang SC\", \"Microsoft YaHei\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", system-ui, sans-serif";
282
+ var MONO_FONT_STACK = "\"Cascadia Code\", \"Cascadia\", ui-monospace, SFMono-Regular, \"SF Mono\", Menlo, Consolas, monospace";
283
+ function fontFamilyToCss(id) {
284
+ switch (id) {
285
+ case 2:
286
+ case 6:
287
+ case 9: return SANS_FONT_STACK;
288
+ case 3:
289
+ case 8: return MONO_FONT_STACK;
290
+ default: return HAND_FONT_STACK;
291
+ }
292
+ }
293
+ //#endregion
294
+ //#region src/model/defaults.ts
295
+ var DEFAULT_STYLE = {
296
+ strokeColor: "#1e1e1e",
297
+ backgroundColor: "transparent",
298
+ fillStyle: "hachure",
299
+ strokeWidth: 2,
300
+ strokeStyle: "solid",
301
+ roughness: 1,
302
+ opacity: 100,
303
+ roundness: "round",
304
+ shadow: false,
305
+ fontFamily: 5,
306
+ fontSize: 20,
307
+ textAlign: "left",
308
+ startArrowhead: null,
309
+ endArrowhead: "arrow",
310
+ arrowType: "round"
311
+ };
312
+ var DEFAULT_LINE_HEIGHT$1 = 1.25;
313
+ //#endregion
314
+ //#region src/model/random.ts
315
+ var ALPHABET = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
316
+ function randomId(size = 21) {
317
+ const bytes = crypto.getRandomValues(new Uint8Array(size));
318
+ let id = "";
319
+ for (const byte of bytes) id += ALPHABET[byte & 63];
320
+ return id;
321
+ }
322
+ function randomInteger() {
323
+ return Math.floor(Math.random() * 2 ** 31);
324
+ }
325
+ //#endregion
326
+ //#region src/model/richtext.ts
327
+ var RICHTEXT_TEXT_COLOR = "#1e1e1e";
328
+ var RICHTEXT_LINK_COLOR = "#1971c2";
329
+ var RICHTEXT_QUOTE_BORDER = "3px solid #c4c4c4";
330
+ var BODY = {
331
+ fontSize: 16,
332
+ fontWeight: 400,
333
+ lineHeight: 1.5
334
+ };
335
+ var HEADINGS = {
336
+ h1: {
337
+ fontSize: 26,
338
+ fontWeight: 600,
339
+ lineHeight: 1.3
340
+ },
341
+ h2: {
342
+ fontSize: 22,
343
+ fontWeight: 600,
344
+ lineHeight: 1.35
345
+ },
346
+ h3: {
347
+ fontSize: 18,
348
+ fontWeight: 600,
349
+ lineHeight: 1.4
350
+ }
351
+ };
352
+ function blockTypography(node) {
353
+ if (node.type !== "heading") return BODY;
354
+ return HEADINGS[node.tag ?? ""] ?? {
355
+ ...BODY,
356
+ fontWeight: 600
357
+ };
358
+ }
359
+ var TEXT_FORMAT = {
360
+ bold: 1,
361
+ italic: 2,
362
+ strikethrough: 4,
363
+ underline: 8,
364
+ code: 16,
365
+ highlight: 128
366
+ };
367
+ function hasFormat(node, flag) {
368
+ return typeof node.format === "number" && (node.format & flag) !== 0;
369
+ }
370
+ var BLOCK_CONTAINERS = /* @__PURE__ */ new Set([
371
+ "root",
372
+ "list",
373
+ "listitem",
374
+ "quote"
375
+ ]);
376
+ function isBlockContainer(node) {
377
+ return BLOCK_CONTAINERS.has(node.type);
378
+ }
379
+ function richTextPlainText(node) {
380
+ if (!node) return "";
381
+ if (node.type === "text") return node.text ?? "";
382
+ if (typeof node.text === "string" && !node.children?.length) return node.text;
383
+ if (node.type === "linebreak") return "\n";
384
+ if (node.type === "tab") return " ";
385
+ return (node.children ?? []).map(richTextPlainText).join("");
386
+ }
387
+ function contentRoot(content) {
388
+ const root = content?.root;
389
+ return root && Array.isArray(root.children) ? root : {
390
+ type: "root",
391
+ children: []
392
+ };
393
+ }
394
+ function paragraphs(lines) {
395
+ return { root: {
396
+ type: "root",
397
+ children: lines.map((text) => ({
398
+ type: "paragraph",
399
+ children: text ? [{
400
+ type: "text",
401
+ text
402
+ }] : []
403
+ }))
404
+ } };
405
+ }
406
+ //#endregion
407
+ //#region src/model/shadow.ts
408
+ var SHADOW_TYPES = /* @__PURE__ */ new Set([
409
+ "rectangle",
410
+ "diamond",
411
+ "ellipse",
412
+ "image",
413
+ "svg",
414
+ "richtext"
415
+ ]);
416
+ var supportsShadow = (type) => SHADOW_TYPES.has(type);
417
+ var hasShadow = (el) => el.shadow === true && supportsShadow(el.type);
418
+ //#endregion
419
+ //#region src/model/create.ts
420
+ function roundnessFor(type, style) {
421
+ if (style.roundness === "sharp") return null;
422
+ if (type === "line" || type === "arrow") return { type: 2 };
423
+ if ([
424
+ "rectangle",
425
+ "diamond",
426
+ "embeddable",
427
+ "iframe",
428
+ "richtext"
429
+ ].includes(type)) return { type: 3 };
430
+ return null;
431
+ }
432
+ function base(type, partial, style) {
433
+ return {
434
+ id: randomId(),
435
+ type,
436
+ x: 0,
437
+ y: 0,
438
+ width: 0,
439
+ height: 0,
440
+ angle: 0,
441
+ strokeColor: style.strokeColor,
442
+ backgroundColor: style.backgroundColor,
443
+ fillStyle: style.fillStyle,
444
+ ...style.shadow && supportsShadow(type) ? { shadow: true } : null,
445
+ strokeWidth: style.strokeWidth,
446
+ strokeStyle: style.strokeStyle,
447
+ roughness: style.roughness,
448
+ opacity: style.opacity,
449
+ groupIds: [],
450
+ frameId: null,
451
+ index: null,
452
+ roundness: roundnessFor(type, style),
453
+ seed: randomInteger(),
454
+ version: 1,
455
+ versionNonce: randomInteger(),
456
+ isDeleted: false,
457
+ boundElements: null,
458
+ updated: Date.now(),
459
+ link: null,
460
+ locked: false,
461
+ ...partial
462
+ };
463
+ }
464
+ function newElement(type, partial, style = DEFAULT_STYLE) {
465
+ return base(type, partial, style);
466
+ }
467
+ function newLinearElement(type, partial, style = DEFAULT_STYLE) {
468
+ const isArrow = type === "arrow";
469
+ const elbowed = isArrow && style.arrowType === "elbow";
470
+ return {
471
+ ...base(type, {}, isArrow && style.arrowType !== "round" ? {
472
+ ...style,
473
+ roundness: "sharp"
474
+ } : style),
475
+ points: [[0, 0]],
476
+ lastCommittedPoint: null,
477
+ startBinding: null,
478
+ endBinding: null,
479
+ startArrowhead: isArrow ? style.startArrowhead : null,
480
+ endArrowhead: isArrow ? style.endArrowhead : null,
481
+ ...isArrow ? { elbowed } : null,
482
+ ...partial
483
+ };
484
+ }
485
+ function newFreedrawElement(partial, style = DEFAULT_STYLE) {
486
+ return {
487
+ ...base("freedraw", {}, style),
488
+ points: [],
489
+ pressures: [],
490
+ simulatePressure: true,
491
+ lastCommittedPoint: null,
492
+ ...partial
493
+ };
494
+ }
495
+ function newTextElement(partial, style = DEFAULT_STYLE) {
496
+ return {
497
+ ...base("text", {}, {
498
+ ...style,
499
+ roundness: "sharp"
500
+ }),
501
+ fontSize: style.fontSize,
502
+ fontFamily: style.fontFamily,
503
+ textAlign: style.textAlign,
504
+ verticalAlign: "top",
505
+ containerId: null,
506
+ originalText: partial.text,
507
+ autoResize: true,
508
+ lineHeight: DEFAULT_LINE_HEIGHT$1,
509
+ ...partial
510
+ };
511
+ }
512
+ function newImageElement(partial, style = DEFAULT_STYLE) {
513
+ return {
514
+ ...base("image", {}, {
515
+ ...style,
516
+ roundness: "sharp"
517
+ }),
518
+ fileId: void 0,
519
+ status: "pending",
520
+ scale: [1, 1],
521
+ crop: null,
522
+ ...partial
523
+ };
524
+ }
525
+ function newRichTextElement(partial, style = DEFAULT_STYLE) {
526
+ return {
527
+ ...base("richtext", {}, {
528
+ ...style,
529
+ roundness: "round",
530
+ shadow: false
531
+ }),
532
+ strokeColor: "transparent",
533
+ backgroundColor: "#ffec99",
534
+ fillStyle: "solid",
535
+ roughness: 0,
536
+ strokeWidth: 1,
537
+ content: paragraphs([""]),
538
+ ...partial
539
+ };
540
+ }
541
+ function newSvgElement(partial, style = DEFAULT_STYLE) {
542
+ return {
543
+ ...base("svg", {}, {
544
+ ...style,
545
+ roundness: "sharp",
546
+ shadow: false
547
+ }),
548
+ svg: "",
549
+ ...partial
550
+ };
551
+ }
552
+ function newFrameElement(partial, style = DEFAULT_STYLE) {
553
+ return {
554
+ ...base("frame", {}, {
555
+ ...style,
556
+ roundness: "sharp",
557
+ backgroundColor: "transparent"
558
+ }),
559
+ name: null,
560
+ ...partial
561
+ };
562
+ }
563
+ //#endregion
564
+ //#region src/model/measure.ts
565
+ var CJK = /[\p{Script=Han}\p{Script=Hangul}\p{Script=Hiragana}\p{Script=Katakana}\u3000-\u303F\uFF01-\uFF60]/u;
566
+ function estimate(text, font) {
567
+ const size = fontSizeOf(font);
568
+ let width = 0;
569
+ for (const ch of text) width += CJK.test(ch) ? size : size * .6;
570
+ return width;
571
+ }
572
+ var context;
573
+ function getContext() {
574
+ if (context !== void 0) return context;
575
+ context = null;
576
+ if (typeof OffscreenCanvas !== "undefined") context = new OffscreenCanvas(1, 1).getContext("2d");
577
+ if (!context && typeof document !== "undefined" && !/jsdom/i.test(navigator.userAgent)) context = document.createElement("canvas").getContext("2d");
578
+ return context;
579
+ }
580
+ var canvasMeasurer = (text, font) => {
581
+ const ctx = getContext();
582
+ if (!ctx) return estimate(text, font);
583
+ ctx.font = font;
584
+ return ctx.measureText(text).width;
585
+ };
586
+ var measurer = canvasMeasurer;
587
+ function measureLine(text, font) {
588
+ return measurer(text, font);
589
+ }
590
+ function fontSizeOf(font) {
591
+ const match = /(\d+(?:\.\d+)?)px/.exec(font);
592
+ return match ? Number(match[1]) : 20;
593
+ }
594
+ function getFontString({ fontSize, fontFamily }) {
595
+ return `${fontSize}px ${fontFamilyToCss(fontFamily)}`;
596
+ }
597
+ var LINE_HEIGHTS = {
598
+ 1: 1.25,
599
+ 2: 1.15,
600
+ 3: 1.2,
601
+ 5: 1.25,
602
+ 6: 1.35,
603
+ 8: 1.15,
604
+ 9: 1.15
605
+ };
606
+ function getLineHeight(fontFamily) {
607
+ return LINE_HEIGHTS[fontFamily] ?? 1.25;
608
+ }
609
+ function measureText(text, font, lineHeight) {
610
+ const lines = text.split("\n");
611
+ return {
612
+ width: Math.max(0, ...lines.map((line) => measureLine(line, font))),
613
+ height: lines.length * fontSizeOf(font) * lineHeight
614
+ };
615
+ }
616
+ function isCJK(ch) {
617
+ return CJK.test(ch);
618
+ }
619
+ //#endregion
620
+ //#region src/model/fractional-index.ts
621
+ var DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
622
+ var ZERO = DIGITS[0];
623
+ var SMALLEST_INTEGER = `A${ZERO.repeat(26)}`;
624
+ function midpoint(a, b) {
625
+ if (b !== null && a >= b) throw new Error(`${a} >= ${b}`);
626
+ if (a.slice(-1) === ZERO || b && b.slice(-1) === ZERO) throw new Error("trailing zero");
627
+ if (b) {
628
+ let n = 0;
629
+ while ((a[n] || ZERO) === b[n]) n++;
630
+ if (n > 0) return b.slice(0, n) + midpoint(a.slice(n), b.slice(n));
631
+ }
632
+ const digitA = a ? DIGITS.indexOf(a[0]) : 0;
633
+ const digitB = b !== null ? DIGITS.indexOf(b[0]) : 62;
634
+ if (digitB - digitA > 1) return DIGITS[Math.round(.5 * (digitA + digitB))];
635
+ if (b && b.length > 1) return b.slice(0, 1);
636
+ return DIGITS[digitA] + midpoint(a.slice(1), null);
637
+ }
638
+ function integerLength(head) {
639
+ if (head >= "a" && head <= "z") return head.charCodeAt(0) - 97 + 2;
640
+ if (head >= "A" && head <= "Z") return 90 - head.charCodeAt(0) + 2;
641
+ throw new Error(`invalid order key head: ${head}`);
642
+ }
643
+ function integerPart(key) {
644
+ const length = integerLength(key[0]);
645
+ if (length > key.length) throw new Error(`invalid order key: ${key}`);
646
+ return key.slice(0, length);
647
+ }
648
+ function isValidIndex(key) {
649
+ if (typeof key !== "string" || key.length === 0) return false;
650
+ try {
651
+ if (key === SMALLEST_INTEGER) return false;
652
+ const int = integerPart(key);
653
+ if (![...key].every((c) => DIGITS.includes(c))) return false;
654
+ return key.slice(int.length).slice(-1) !== ZERO;
655
+ } catch {
656
+ return false;
657
+ }
658
+ }
659
+ function assertValid(key) {
660
+ if (!isValidIndex(key)) throw new Error(`invalid order key: ${key}`);
661
+ }
662
+ function incrementInteger(x) {
663
+ const [head, ...digits] = x.split("");
664
+ let carry = true;
665
+ for (let i = digits.length - 1; carry && i >= 0; i--) {
666
+ const d = DIGITS.indexOf(digits[i]) + 1;
667
+ if (d === 62) digits[i] = ZERO;
668
+ else {
669
+ digits[i] = DIGITS[d];
670
+ carry = false;
671
+ }
672
+ }
673
+ if (!carry) return head + digits.join("");
674
+ if (head === "Z") return `a${ZERO}`;
675
+ if (head === "z") return null;
676
+ const next = String.fromCharCode(head.charCodeAt(0) + 1);
677
+ if (next > "a") digits.push(ZERO);
678
+ else digits.pop();
679
+ return next + digits.join("");
680
+ }
681
+ function decrementInteger(x) {
682
+ const [head, ...digits] = x.split("");
683
+ let borrow = true;
684
+ for (let i = digits.length - 1; borrow && i >= 0; i--) {
685
+ const d = DIGITS.indexOf(digits[i]) - 1;
686
+ if (d === -1) digits[i] = DIGITS.slice(-1);
687
+ else {
688
+ digits[i] = DIGITS[d];
689
+ borrow = false;
690
+ }
691
+ }
692
+ if (!borrow) return head + digits.join("");
693
+ if (head === "a") return `Z${DIGITS.slice(-1)}`;
694
+ if (head === "A") return null;
695
+ const next = String.fromCharCode(head.charCodeAt(0) - 1);
696
+ if (next < "Z") digits.push(DIGITS.slice(-1));
697
+ else digits.pop();
698
+ return next + digits.join("");
699
+ }
700
+ function generateKeyBetween(a, b) {
701
+ if (a !== null) assertValid(a);
702
+ if (b !== null) assertValid(b);
703
+ if (a !== null && b !== null && a >= b) throw new Error(`${a} >= ${b}`);
704
+ if (a === null) {
705
+ if (b === null) return `a${ZERO}`;
706
+ const ib = integerPart(b);
707
+ const fb = b.slice(ib.length);
708
+ if (ib === SMALLEST_INTEGER) return ib + midpoint("", fb);
709
+ if (ib < b) return ib;
710
+ const res = decrementInteger(ib);
711
+ if (res === null) throw new Error("cannot decrement any more");
712
+ return res;
713
+ }
714
+ if (b === null) {
715
+ const ia = integerPart(a);
716
+ const fa = a.slice(ia.length);
717
+ const i = incrementInteger(ia);
718
+ return i === null ? ia + midpoint(fa, null) : i;
719
+ }
720
+ const ia = integerPart(a);
721
+ const fa = a.slice(ia.length);
722
+ const ib = integerPart(b);
723
+ const fb = b.slice(ib.length);
724
+ if (ia === ib) return ia + midpoint(fa, fb);
725
+ const i = incrementInteger(ia);
726
+ if (i === null) throw new Error("cannot increment any more");
727
+ if (i < b) return i;
728
+ return ia + midpoint(fa, null);
729
+ }
730
+ function generateNKeysBetween(a, b, n) {
731
+ if (n <= 0) return [];
732
+ if (n === 1) return [generateKeyBetween(a, b)];
733
+ if (b === null) {
734
+ let c = generateKeyBetween(a, b);
735
+ const result = [c];
736
+ for (let i = 0; i < n - 1; i++) {
737
+ c = generateKeyBetween(c, b);
738
+ result.push(c);
739
+ }
740
+ return result;
741
+ }
742
+ if (a === null) {
743
+ let c = generateKeyBetween(a, b);
744
+ const result = [c];
745
+ for (let i = 0; i < n - 1; i++) {
746
+ c = generateKeyBetween(a, c);
747
+ result.push(c);
748
+ }
749
+ return result.reverse();
750
+ }
751
+ const mid = Math.floor(n / 2);
752
+ const c = generateKeyBetween(a, b);
753
+ return [
754
+ ...generateNKeysBetween(a, c, mid),
755
+ c,
756
+ ...generateNKeysBetween(c, b, n - mid - 1)
757
+ ];
758
+ }
759
+ function syncIndices(elements) {
760
+ const valid = [];
761
+ let last = null;
762
+ for (const el of elements) {
763
+ const ok = isValidIndex(el.index) && (last === null || el.index > last);
764
+ valid.push(ok);
765
+ if (ok) last = el.index;
766
+ }
767
+ if (valid.every(Boolean)) return [...elements];
768
+ const out = [...elements];
769
+ let i = 0;
770
+ while (i < out.length) {
771
+ if (valid[i]) {
772
+ i++;
773
+ continue;
774
+ }
775
+ const start = i;
776
+ while (i < out.length && !valid[i]) i++;
777
+ const keys = generateNKeysBetween(start > 0 ? out[start - 1].index : null, i < out.length ? out[i].index : null, i - start);
778
+ for (let k = start; k < i; k++) out[k] = {
779
+ ...out[k],
780
+ index: keys[k - start]
781
+ };
782
+ }
783
+ return out;
784
+ }
785
+ //#endregion
786
+ //#region src/model/mutate.ts
787
+ function bumpVersion(el, patch = {}) {
788
+ return {
789
+ ...el,
790
+ ...patch,
791
+ version: (el.version ?? 0) + 1,
792
+ versionNonce: randomInteger(),
793
+ updated: Date.now()
794
+ };
795
+ }
796
+ //#endregion
797
+ //#region src/model/svg.ts
798
+ var SVG_NS = "http://www.w3.org/2000/svg";
799
+ var ROOT = /<svg\b[^>]*>/i;
800
+ function isSvgSource(src) {
801
+ return typeof src === "string" && /^\s*(?:<\?xml[^>]*>\s*)?(?:<!--[\s\S]*?-->\s*)*<svg[\s/>]/i.test(src);
802
+ }
803
+ function normalizeSvgSource(src) {
804
+ const root = ROOT.exec(src);
805
+ if (!root || /\sxmlns\s*=/.test(root[0])) return src;
806
+ const at = root.index + 4;
807
+ return `${src.slice(0, at)} xmlns="${SVG_NS}"${src.slice(at)}`;
808
+ }
809
+ function svgDataUrl(src) {
810
+ return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(normalizeSvgSource(src))}`;
811
+ }
812
+ function attr(tag, name) {
813
+ const match = new RegExp(`\\s${name}\\s*=\\s*["']([^"']*)["']`, "i").exec(tag);
814
+ return match ? match[1] : null;
815
+ }
816
+ function length(value) {
817
+ if (!value) return null;
818
+ const match = /^\s*(\d+(?:\.\d+)?)\s*(?:px\s*)?$/i.exec(value);
819
+ return match ? Number(match[1]) : null;
820
+ }
821
+ function parseSvgSize(src) {
822
+ const root = ROOT.exec(src)?.[0];
823
+ if (!root) return null;
824
+ const width = length(attr(root, "width"));
825
+ const height = length(attr(root, "height"));
826
+ if (width && height) return {
827
+ width,
828
+ height
829
+ };
830
+ const box = attr(root, "viewBox")?.trim().split(/[\s,]+/).map(Number);
831
+ if (box && box.length === 4 && box[2] > 0 && box[3] > 0) return {
832
+ width: box[2],
833
+ height: box[3]
834
+ };
835
+ return null;
836
+ }
837
+ //#endregion
838
+ //#region src/model/text-layout.ts
839
+ var ARROW_LABEL_MIN_WIDTH = 120;
840
+ var ARROW_LABEL_WIDTH_RATIO = .7;
841
+ function tokenize(paragraph) {
842
+ const tokens = [];
843
+ let word = "";
844
+ for (const ch of paragraph) if (ch === " " || isCJK(ch)) {
845
+ if (word) tokens.push(word);
846
+ word = "";
847
+ tokens.push(ch);
848
+ } else word += ch;
849
+ if (word) tokens.push(word);
850
+ return tokens;
851
+ }
852
+ function breakLongToken(token, font, maxWidth) {
853
+ const parts = [];
854
+ let current = "";
855
+ for (const ch of token) if (current && measureLine(current + ch, font) > maxWidth) {
856
+ parts.push(current);
857
+ current = ch;
858
+ } else current += ch;
859
+ if (current) parts.push(current);
860
+ return parts;
861
+ }
862
+ function wrapParagraph(paragraph, font, maxWidth) {
863
+ const lines = [];
864
+ let line = "";
865
+ const push = () => {
866
+ lines.push(line.trimEnd());
867
+ line = "";
868
+ };
869
+ for (const token of tokenize(paragraph)) {
870
+ if (measureLine(line + token, font) <= maxWidth) {
871
+ line += token;
872
+ continue;
873
+ }
874
+ if (token === " ") {
875
+ push();
876
+ continue;
877
+ }
878
+ if (line) push();
879
+ if (measureLine(token, font) <= maxWidth) {
880
+ line = token;
881
+ continue;
882
+ }
883
+ const parts = breakLongToken(token, font, maxWidth);
884
+ for (const part of parts.slice(0, -1)) lines.push(part);
885
+ line = parts.at(-1) ?? "";
886
+ }
887
+ if (line || lines.length === 0) push();
888
+ return lines;
889
+ }
890
+ function wrapText(text, font, maxWidth) {
891
+ if (!Number.isFinite(maxWidth) || maxWidth <= 0) return text;
892
+ return text.split("\n").flatMap((paragraph) => wrapParagraph(paragraph, font, maxWidth)).join("\n");
893
+ }
894
+ function polylineLength(points) {
895
+ let total = 0;
896
+ for (let i = 0; i < points.length - 1; i++) total += distance(points[i], points[i + 1]);
897
+ return total;
898
+ }
899
+ function getLinearMidpoint(el) {
900
+ if (!isLinear(el)) return [el.x + el.width / 2, el.y + el.height / 2];
901
+ const points = getLinearAbsolutePoints(el);
902
+ if (points.length === 1) return points[0];
903
+ let remaining = polylineLength(points) / 2;
904
+ for (let i = 0; i < points.length - 1; i++) {
905
+ const segment = distance(points[i], points[i + 1]);
906
+ if (remaining <= segment) {
907
+ const t = segment === 0 ? 0 : remaining / segment;
908
+ return [points[i][0] + (points[i + 1][0] - points[i][0]) * t, points[i][1] + (points[i + 1][1] - points[i][1]) * t];
909
+ }
910
+ remaining -= segment;
911
+ }
912
+ return points.at(-1);
913
+ }
914
+ function getContainerTextMaxWidth(container) {
915
+ const pad = 10;
916
+ if (isLinear(container)) {
917
+ const length = polylineLength(getLinearAbsolutePoints(container));
918
+ return Math.max(ARROW_LABEL_MIN_WIDTH, length * ARROW_LABEL_WIDTH_RATIO);
919
+ }
920
+ if (container.type === "ellipse") return Math.round(container.width / 2 * Math.SQRT2) - pad;
921
+ if (container.type === "diamond") return Math.round(container.width / 2) - pad;
922
+ return container.width - pad;
923
+ }
924
+ function getContainerTextMaxHeight(container) {
925
+ const pad = 10;
926
+ if (container.type === "ellipse") return Math.round(container.height / 2 * Math.SQRT2) - pad;
927
+ if (container.type === "diamond") return Math.round(container.height / 2) - pad;
928
+ return container.height - pad;
929
+ }
930
+ function containerHeightFor(container, textHeight) {
931
+ const pad = 10;
932
+ if (container.type === "ellipse") return Math.ceil((textHeight + pad) * 2 / Math.SQRT2);
933
+ if (container.type === "diamond") return Math.ceil((textHeight + pad) * 2);
934
+ return textHeight + pad;
935
+ }
936
+ function layoutBoundText(container, textEl) {
937
+ const font = getFontString(textEl);
938
+ const lineHeight = textEl.lineHeight ?? getLineHeight(textEl.fontFamily);
939
+ const source = textEl.originalText ?? textEl.text;
940
+ const wrapped = wrapText(source, font, getContainerTextMaxWidth(container));
941
+ const size = measureText(wrapped, font, lineHeight);
942
+ let nextContainer = container;
943
+ if (!isLinear(container) && size.height > getContainerTextMaxHeight(container)) nextContainer = bumpVersion(container, { height: containerHeightFor(container, size.height) });
944
+ const linear = isLinear(nextContainer);
945
+ const [cx, cy] = linear ? getLinearMidpoint(nextContainer) : [nextContainer.x + nextContainer.width / 2, nextContainer.y + nextContainer.height / 2];
946
+ const textAlign = linear ? "center" : textEl.textAlign ?? "center";
947
+ const verticalAlign = linear ? "middle" : textEl.verticalAlign ?? "middle";
948
+ const halfW = linear ? size.width / 2 : getContainerTextMaxWidth(nextContainer) / 2;
949
+ const halfH = linear ? size.height / 2 : getContainerTextMaxHeight(nextContainer) / 2;
950
+ const x = textAlign === "left" ? cx - halfW : textAlign === "right" ? cx + halfW - size.width : cx - size.width / 2;
951
+ const y = verticalAlign === "top" ? cy - halfH : verticalAlign === "bottom" ? cy + halfH - size.height : cy - size.height / 2;
952
+ const angle = linear ? 0 : angleOf(nextContainer);
953
+ const [tx, ty] = angle ? rotatePoint([x + size.width / 2, y + size.height / 2], [cx, cy], angle) : [x + size.width / 2, y + size.height / 2];
954
+ const text = {
955
+ ...textEl,
956
+ text: wrapped,
957
+ originalText: source,
958
+ width: size.width,
959
+ height: size.height,
960
+ x: tx - size.width / 2,
961
+ y: ty - size.height / 2,
962
+ angle,
963
+ textAlign,
964
+ verticalAlign,
965
+ containerId: nextContainer.id
966
+ };
967
+ return {
968
+ container: nextContainer,
969
+ text
970
+ };
971
+ }
972
+ function refreshTextDimensions(textEl, container) {
973
+ if (container) return layoutBoundText(container, textEl).text;
974
+ const font = getFontString(textEl);
975
+ const lineHeight = textEl.lineHeight ?? getLineHeight(textEl.fontFamily);
976
+ const source = textEl.originalText ?? textEl.text;
977
+ const text = textEl.autoResize === false ? wrapText(source, font, textEl.width) : source;
978
+ const size = measureText(text, font, lineHeight);
979
+ return {
980
+ ...textEl,
981
+ text,
982
+ width: textEl.autoResize === false ? textEl.width : size.width,
983
+ height: size.height
984
+ };
985
+ }
986
+ //#endregion
987
+ //#region src/model/restore.ts
988
+ function defaultsFor(raw) {
989
+ switch (raw.type) {
990
+ case "line":
991
+ case "arrow": return newLinearElement(raw.type, {});
992
+ case "freedraw": return newFreedrawElement({});
993
+ case "text": return newTextElement({ text: raw.text ?? "" });
994
+ case "image": return newImageElement({});
995
+ case "svg": return newSvgElement({});
996
+ case "richtext": return newRichTextElement({});
997
+ case "frame":
998
+ case "magicframe": return {
999
+ ...newFrameElement({}),
1000
+ type: raw.type
1001
+ };
1002
+ default: return newElement(raw.type ?? "rectangle", {});
1003
+ }
1004
+ }
1005
+ var ADAPTIVE_RADIUS_TYPES = /* @__PURE__ */ new Set([
1006
+ "rectangle",
1007
+ "image",
1008
+ "embeddable",
1009
+ "iframe"
1010
+ ]);
1011
+ function legacyRoundness(raw) {
1012
+ if (raw.strokeSharpness !== "round") return null;
1013
+ return { type: ADAPTIVE_RADIUS_TYPES.has(raw.type ?? "") ? 3 : 2 };
1014
+ }
1015
+ function normalizeElement(raw) {
1016
+ const merged = { ...defaultsFor(raw) };
1017
+ for (const [key, value] of Object.entries(raw)) if (value !== void 0) merged[key] = value;
1018
+ if (!("roundness" in raw) || raw.roundness === void 0) merged.roundness = legacyRoundness(raw);
1019
+ if (raw.type === "text" && merged.originalText === void 0) merged.originalText = raw.text;
1020
+ if (raw.type === "svg" && typeof merged.svg === "string") merged.svg = normalizeSvgSource(merged.svg);
1021
+ if ((raw.type === "line" || raw.type === "arrow") && !raw.points) merged.points = [[0, 0], [raw.width ?? 0, raw.height ?? 0]];
1022
+ return merged;
1023
+ }
1024
+ async function loadFonts(elements) {
1025
+ if (typeof document === "undefined" || !document.fonts?.load) return;
1026
+ const fonts = new Set(elements.filter((el) => el.type === "text").map((el) => `${el.fontSize}px ${fontFamilyToCss(el.fontFamily)}`));
1027
+ await Promise.all([...fonts].map((font) => document.fonts.load(font).catch(() => [])));
1028
+ }
1029
+ function textChanged(a, b) {
1030
+ return a.text !== b.text || a.width !== b.width || a.height !== b.height || a.x !== b.x || a.y !== b.y;
1031
+ }
1032
+ async function restoreElements(elements, _localElements, opts = {}) {
1033
+ const normalized = syncIndices(elements.map((el) => normalizeElement(el)));
1034
+ if (!opts.refreshDimensions) return normalized;
1035
+ await loadFonts(normalized);
1036
+ const byId = new Map(normalized.map((el) => [el.id, el]));
1037
+ return normalized.map((el) => {
1038
+ if (el.type !== "text") return el;
1039
+ const next = refreshTextDimensions(el, el.containerId ? byId.get(el.containerId) : void 0);
1040
+ return textChanged(el, next) ? bumpVersion(el, next) : el;
1041
+ });
1042
+ }
1043
+ //#endregion
1044
+ //#region src/model/richtext-layout.ts
1045
+ var richTextFont = (node) => {
1046
+ const { fontSize, fontWeight } = blockTypography(node);
1047
+ return `${fontWeight === 600 ? "bold " : ""}${fontSize}px ${SANS_FONT_STACK}`;
1048
+ };
1049
+ function blockHeight(node, width) {
1050
+ const { lineHeight } = blockTypography(node);
1051
+ const font = richTextFont(node);
1052
+ return wrapText(richTextPlainText(node), font, Math.max(1, width)).split("\n").length * fontSizeOf(font) * lineHeight;
1053
+ }
1054
+ function childIndent(node) {
1055
+ if (node.type === "list") return 20;
1056
+ if (node.type === "quote") return 12;
1057
+ return 0;
1058
+ }
1059
+ function hasBlockChildren(node) {
1060
+ return (node.children ?? []).some((child) => isBlockContainer(child) || child.type === "paragraph" || child.type === "heading");
1061
+ }
1062
+ function stackHeight(nodes, width) {
1063
+ let total = 0;
1064
+ for (const node of nodes) if (isBlockContainer(node) && hasBlockChildren(node)) total += stackHeight(node.children ?? [], width - childIndent(node));
1065
+ else total += blockHeight(node, width - childIndent(node));
1066
+ return total;
1067
+ }
1068
+ var cache = /* @__PURE__ */ new WeakMap();
1069
+ function measureRichTextHeight(content, width) {
1070
+ const root = contentRoot(content);
1071
+ const byWidth = cache.get(root);
1072
+ const cached = byWidth?.get(width);
1073
+ if (cached !== void 0) return cached;
1074
+ const inner = width - 24;
1075
+ const blocks = root.children ?? [];
1076
+ const height = (blocks.length === 0 ? blockHeight({ type: "paragraph" }, inner) : stackHeight(blocks, inner)) + 24;
1077
+ if (byWidth) byWidth.set(width, height);
1078
+ else cache.set(root, /* @__PURE__ */ new Map([[width, height]]));
1079
+ return height;
1080
+ }
1081
+ var DEFAULT_KEYS = {
1082
+ richtext: Object.keys(newRichTextElement({})),
1083
+ svg: Object.keys(newSvgElement({}))
1084
+ };
1085
+ function withDefaults(el) {
1086
+ const keys = DEFAULT_KEYS[el.type];
1087
+ if (!(!!keys && (keys.some((key) => !(key in el) || el[key] === void 0) || !Number.isFinite(el.width) || !Number.isFinite(el.height)))) return el;
1088
+ const next = normalizeElement(el);
1089
+ return {
1090
+ ...next,
1091
+ width: Number.isFinite(next.width) ? next.width : 0,
1092
+ height: Number.isFinite(next.height) ? next.height : 0
1093
+ };
1094
+ }
1095
+ function resolveRichTextHeights(elements) {
1096
+ let changed = false;
1097
+ const next = elements.map((input) => {
1098
+ const el = withDefaults(input);
1099
+ if (el !== input) changed = true;
1100
+ if (el.type !== "richtext" || el.isDeleted) return el;
1101
+ const needed = measureRichTextHeight(el.content, el.width);
1102
+ if (!(needed > el.height)) return el;
1103
+ changed = true;
1104
+ return {
1105
+ ...el,
1106
+ height: needed
1107
+ };
1108
+ });
1109
+ return changed ? next : elements;
1110
+ }
1111
+ //#endregion
1112
+ //#region src/scene/context.ts
1113
+ var SceneDarkContext = createContext(null);
1114
+ //#endregion
1115
+ //#region src/scene/freedraw.ts
1116
+ var average = (a, b) => (a + b) / 2;
1117
+ function outlineToPath(points) {
1118
+ const len = points.length;
1119
+ if (len < 4) return "";
1120
+ let a = points[0];
1121
+ let b = points[1];
1122
+ const c = points[2];
1123
+ let d = `M${a[0].toFixed(2)},${a[1].toFixed(2)} Q${b[0].toFixed(2)},${b[1].toFixed(2)} ${average(b[0], c[0]).toFixed(2)},${average(b[1], c[1]).toFixed(2)} T`;
1124
+ for (let i = 2, max = len - 1; i < max; i++) {
1125
+ a = points[i];
1126
+ b = points[i + 1];
1127
+ d += `${average(a[0], b[0]).toFixed(2)},${average(a[1], b[1]).toFixed(2)} `;
1128
+ }
1129
+ return `${d}Z`;
1130
+ }
1131
+ function freedrawOutline(el) {
1132
+ const pressures = el.pressures ?? [];
1133
+ const simulate = el.simulatePressure ?? pressures.length === 0;
1134
+ const input = el.points.map(([x, y], i) => [
1135
+ x,
1136
+ y,
1137
+ simulate ? .5 : pressures[i] ?? .5
1138
+ ]);
1139
+ return outlineToPath(getStroke(input, {
1140
+ simulatePressure: simulate,
1141
+ size: el.strokeWidth * 4.25,
1142
+ thinning: .6,
1143
+ smoothing: .5,
1144
+ streamline: .5,
1145
+ easing: (t) => Math.sin(t * Math.PI / 2),
1146
+ last: true
1147
+ }));
1148
+ }
1149
+ //#endregion
1150
+ //#region src/scene/richtext/RichTextContent.tsx
1151
+ var SAFE_URL = /^(?:https?:|mailto:|#|\/)/i;
1152
+ function parseStyle(style) {
1153
+ const out = {};
1154
+ for (const part of (style ?? "").split(";")) {
1155
+ const [rawKey, ...rest] = part.split(":");
1156
+ const key = rawKey?.trim().toLowerCase();
1157
+ const value = rest.join(":").trim();
1158
+ if (!value || /url\(|expression/i.test(value)) continue;
1159
+ if (key === "color") out.color = value;
1160
+ if (key === "background-color") out.backgroundColor = value;
1161
+ }
1162
+ return out;
1163
+ }
1164
+ function renderText(node, key) {
1165
+ let out = node.text ?? "";
1166
+ const style = parseStyle(node.style);
1167
+ if (Object.keys(style).length > 0) out = /* @__PURE__ */ jsx("span", {
1168
+ style,
1169
+ children: out
1170
+ });
1171
+ if (hasFormat(node, TEXT_FORMAT.code)) out = /* @__PURE__ */ jsx("code", { children: out });
1172
+ if (hasFormat(node, TEXT_FORMAT.highlight)) out = /* @__PURE__ */ jsx("mark", { children: out });
1173
+ if (hasFormat(node, TEXT_FORMAT.underline)) out = /* @__PURE__ */ jsx("u", { children: out });
1174
+ if (hasFormat(node, TEXT_FORMAT.strikethrough)) out = /* @__PURE__ */ jsx("s", { children: out });
1175
+ if (hasFormat(node, TEXT_FORMAT.italic)) out = /* @__PURE__ */ jsx("em", { children: out });
1176
+ if (hasFormat(node, TEXT_FORMAT.bold)) out = /* @__PURE__ */ jsx("strong", { children: out });
1177
+ return /* @__PURE__ */ jsx("span", { children: out }, key);
1178
+ }
1179
+ function renderInline(nodes = []) {
1180
+ return nodes.map((node, i) => {
1181
+ switch (node.type) {
1182
+ case "text": return renderText(node, i);
1183
+ case "linebreak": return /* @__PURE__ */ jsx("br", {}, i);
1184
+ case "tab": return /* @__PURE__ */ jsx("span", { children: " " }, i);
1185
+ case "link":
1186
+ case "autolink": {
1187
+ const href = typeof node.url === "string" && SAFE_URL.test(node.url) ? node.url : void 0;
1188
+ return /* @__PURE__ */ jsx("a", {
1189
+ href,
1190
+ rel: "noopener noreferrer",
1191
+ style: { color: RICHTEXT_LINK_COLOR },
1192
+ target: "_blank",
1193
+ children: renderInline(node.children)
1194
+ }, i);
1195
+ }
1196
+ default: return /* @__PURE__ */ jsx("span", { children: richTextPlainText(node) }, i);
1197
+ }
1198
+ });
1199
+ }
1200
+ function blockStyle(node) {
1201
+ const { fontSize, fontWeight, lineHeight } = blockTypography(node);
1202
+ return {
1203
+ fontSize,
1204
+ fontWeight,
1205
+ lineHeight,
1206
+ margin: 0,
1207
+ minHeight: fontSize * lineHeight
1208
+ };
1209
+ }
1210
+ var HEADING_TAGS = /* @__PURE__ */ new Set([
1211
+ "h1",
1212
+ "h2",
1213
+ "h3",
1214
+ "h4",
1215
+ "h5",
1216
+ "h6"
1217
+ ]);
1218
+ function renderBlock(node, key) {
1219
+ switch (node.type) {
1220
+ case "paragraph": return /* @__PURE__ */ jsx("p", {
1221
+ style: blockStyle(node),
1222
+ children: renderInline(node.children)
1223
+ }, key);
1224
+ case "heading": {
1225
+ const Tag = HEADING_TAGS.has(node.tag ?? "") ? node.tag : "h4";
1226
+ return /* @__PURE__ */ jsx(Tag, {
1227
+ style: blockStyle(node),
1228
+ children: renderInline(node.children)
1229
+ }, key);
1230
+ }
1231
+ case "quote": return /* @__PURE__ */ jsx("blockquote", {
1232
+ style: {
1233
+ ...blockStyle(node),
1234
+ paddingLeft: 9,
1235
+ borderLeft: RICHTEXT_QUOTE_BORDER
1236
+ },
1237
+ children: renderInline(node.children)
1238
+ }, key);
1239
+ case "list": {
1240
+ const List = node.listType === "number" ? "ol" : "ul";
1241
+ return /* @__PURE__ */ jsx(List, {
1242
+ style: {
1243
+ margin: 0,
1244
+ paddingLeft: 20
1245
+ },
1246
+ children: (node.children ?? []).map((item, i) => renderListItem(item.type === "listitem" ? item : {
1247
+ type: "listitem",
1248
+ children: [item]
1249
+ }, i))
1250
+ }, key);
1251
+ }
1252
+ default: return /* @__PURE__ */ jsx("p", {
1253
+ style: blockStyle({ type: "paragraph" }),
1254
+ children: richTextPlainText(node)
1255
+ }, key);
1256
+ }
1257
+ }
1258
+ function renderListItem(node, key) {
1259
+ const children = node.children ?? [];
1260
+ const nested = children.filter((child) => child.type === "list");
1261
+ const inline = children.filter((child) => child.type !== "list");
1262
+ return /* @__PURE__ */ jsxs("li", {
1263
+ style: blockStyle({ type: "paragraph" }),
1264
+ children: [renderInline(inline), nested.map((list, i) => renderBlock(list, i))]
1265
+ }, key);
1266
+ }
1267
+ var RICHTEXT_BASE_STYLE = {
1268
+ color: RICHTEXT_TEXT_COLOR,
1269
+ fontFamily: SANS_FONT_STACK,
1270
+ overflowWrap: "break-word",
1271
+ whiteSpace: "pre-wrap"
1272
+ };
1273
+ var RichTextContent = ({ content }) => /* @__PURE__ */ jsx(Fragment, { children: (contentRoot(content).children ?? []).map((node, i) => renderBlock(node, i)) });
1274
+ //#endregion
1275
+ //#region src/scene/richtext/RichTextBody.tsx
1276
+ var XHTML_NS = { xmlns: "http://www.w3.org/1999/xhtml" };
1277
+ var RichTextBody = ({ el }) => /* @__PURE__ */ jsx("foreignObject", {
1278
+ height: el.height,
1279
+ style: { overflow: "visible" },
1280
+ width: el.width,
1281
+ children: /* @__PURE__ */ jsx("div", {
1282
+ "data-richtext-body": el.id,
1283
+ ...XHTML_NS,
1284
+ style: {
1285
+ ...RICHTEXT_BASE_STYLE,
1286
+ boxSizing: "border-box",
1287
+ width: el.width,
1288
+ minHeight: el.height,
1289
+ padding: 12
1290
+ },
1291
+ children: /* @__PURE__ */ jsx(RichTextContent, { content: el.content })
1292
+ })
1293
+ });
1294
+ //#endregion
1295
+ //#region src/scene/rough.ts
1296
+ var _gen = null;
1297
+ function gen() {
1298
+ if (!_gen) _gen = new RoughGenerator();
1299
+ return _gen;
1300
+ }
1301
+ function roughOptionsForElement(el, override) {
1302
+ const dashes = strokeDash(el.strokeStyle, el.strokeWidth);
1303
+ const opts = {
1304
+ seed: el.seed || 1,
1305
+ stroke: el.strokeColor,
1306
+ strokeWidth: el.strokeWidth,
1307
+ roughness: el.roughness,
1308
+ disableMultiStroke: el.strokeWidth < 2,
1309
+ fill: el.backgroundColor === "transparent" ? void 0 : el.backgroundColor,
1310
+ fillStyle: el.fillStyle,
1311
+ fillWeight: el.strokeWidth / 2,
1312
+ hachureGap: el.strokeWidth * 4,
1313
+ preserveVertices: false
1314
+ };
1315
+ if (dashes) opts.strokeLineDash = dashes;
1316
+ return {
1317
+ ...opts,
1318
+ ...override
1319
+ };
1320
+ }
1321
+ function strokeDash(style, w) {
1322
+ if (style === "solid") return void 0;
1323
+ if (style === "dashed") return [8, 8 + w];
1324
+ if (style === "dotted") return [1.5, 6 + w];
1325
+ }
1326
+ function rectangle(el, override) {
1327
+ return gen().rectangle(0, 0, el.width, el.height, roughOptionsForElement(el, override));
1328
+ }
1329
+ function ellipse(el, override) {
1330
+ return gen().ellipse(el.width / 2, el.height / 2, el.width, el.height, roughOptionsForElement(el, override));
1331
+ }
1332
+ function diamond(el, override) {
1333
+ const hw = el.width / 2;
1334
+ const hh = el.height / 2;
1335
+ return gen().polygon([
1336
+ [hw, 0],
1337
+ [el.width, hh],
1338
+ [hw, el.height],
1339
+ [0, hh]
1340
+ ], roughOptionsForElement(el, override));
1341
+ }
1342
+ function path(d, options) {
1343
+ return gen().path(d, options);
1344
+ }
1345
+ function linearPath(points, options) {
1346
+ return gen().linearPath(points, options);
1347
+ }
1348
+ function curve(points, options) {
1349
+ return gen().curve(points, options);
1350
+ }
1351
+ function opsToPath(ops) {
1352
+ let d = "";
1353
+ for (const { op, data } of ops) switch (op) {
1354
+ case "move":
1355
+ d += `M${data[0]} ${data[1]} `;
1356
+ break;
1357
+ case "lineTo":
1358
+ d += `L${data[0]} ${data[1]} `;
1359
+ break;
1360
+ case "bcurveTo": d += `C${data[0]} ${data[1]}, ${data[2]} ${data[3]}, ${data[4]} ${data[5]} `;
1361
+ }
1362
+ return d.trim();
1363
+ }
1364
+ function drawableToOpSets(drawable) {
1365
+ return drawable.sets.map((set) => ({
1366
+ type: set.type,
1367
+ d: opsToPath(set.ops)
1368
+ }));
1369
+ }
1370
+ function roundedRectPath(width, height, radius) {
1371
+ const r = Math.max(0, Math.min(radius, width / 2, height / 2));
1372
+ return [
1373
+ `M ${r} 0`,
1374
+ `L ${width - r} 0`,
1375
+ `Q ${width} 0 ${width} ${r}`,
1376
+ `L ${width} ${height - r}`,
1377
+ `Q ${width} ${height} ${width - r} ${height}`,
1378
+ `L ${r} ${height}`,
1379
+ `Q 0 ${height} 0 ${height - r}`,
1380
+ `L 0 ${r}`,
1381
+ `Q 0 0 ${r} 0`,
1382
+ "Z"
1383
+ ].join(" ");
1384
+ }
1385
+ var PROPORTIONAL_RADIUS = .25;
1386
+ var FIXED_RADIUS = 32;
1387
+ function getCornerRadius(el) {
1388
+ if (!el.roundness) return 0;
1389
+ if (el.roundness.type === 3) {
1390
+ const min = Math.min(el.width, el.height);
1391
+ return Math.min(min * PROPORTIONAL_RADIUS, FIXED_RADIUS);
1392
+ }
1393
+ return el.roundness.value ?? 0;
1394
+ }
1395
+ //#endregion
1396
+ //#region src/scene/svg-element.tsx
1397
+ var SvgRender = ({ el }) => {
1398
+ const darkFilter = use(SceneDarkContext);
1399
+ if (!isSvgSource(el.svg)) return /* @__PURE__ */ jsx("rect", {
1400
+ fill: "none",
1401
+ height: el.height,
1402
+ stroke: "#888",
1403
+ strokeDasharray: "4 4",
1404
+ strokeWidth: 1,
1405
+ width: el.width
1406
+ });
1407
+ return /* @__PURE__ */ jsx("image", {
1408
+ filter: darkFilter ? `url(#${darkFilter.filterId})` : void 0,
1409
+ height: el.height,
1410
+ href: svgDataUrl(el.svg),
1411
+ preserveAspectRatio: "xMidYMid meet",
1412
+ width: el.width
1413
+ });
1414
+ };
1415
+ //#endregion
1416
+ //#region src/scene/elements.tsx
1417
+ var ElementContent = ({ el, files }) => {
1418
+ switch (el.type) {
1419
+ case "rectangle": return /* @__PURE__ */ jsx(RectangleRender, { el });
1420
+ case "ellipse": return /* @__PURE__ */ jsx(EllipseRender, { el });
1421
+ case "diamond": return /* @__PURE__ */ jsx(DiamondRender, { el });
1422
+ case "line":
1423
+ case "arrow": return /* @__PURE__ */ jsx(LinearRender, { el });
1424
+ case "freedraw": return /* @__PURE__ */ jsx(FreedrawRender, { el });
1425
+ case "text": return /* @__PURE__ */ jsx(TextRender, { el });
1426
+ case "image": return /* @__PURE__ */ jsx(ImageRender, {
1427
+ el,
1428
+ files
1429
+ });
1430
+ case "svg": return /* @__PURE__ */ jsx(SvgRender, { el });
1431
+ case "richtext": return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(RectangleRender, { el }), /* @__PURE__ */ jsx(RichTextBody, { el })] });
1432
+ case "frame":
1433
+ case "magicframe": return /* @__PURE__ */ jsx(FrameRender, { el });
1434
+ case "embeddable":
1435
+ case "iframe": return /* @__PURE__ */ jsx(EmbedPlaceholder, { el });
1436
+ default: return null;
1437
+ }
1438
+ };
1439
+ var EVENODD_SHAPES = /* @__PURE__ */ new Set(["curve", "polygon"]);
1440
+ var PathSet = ({ drawable, fillColor, strokeColor, strokeWidth }) => {
1441
+ const opSets = drawableToOpSets(drawable);
1442
+ return /* @__PURE__ */ jsx(Fragment, { children: opSets.map((set, i) => {
1443
+ if (set.type === "path") return /* @__PURE__ */ jsx("path", {
1444
+ d: set.d,
1445
+ fill: "none",
1446
+ stroke: strokeColor,
1447
+ strokeLinecap: "round",
1448
+ strokeLinejoin: "round",
1449
+ strokeWidth
1450
+ }, i);
1451
+ if (set.type === "fillPath") return /* @__PURE__ */ jsx("path", {
1452
+ d: set.d,
1453
+ fill: fillColor || "none",
1454
+ fillRule: EVENODD_SHAPES.has(drawable.shape) ? "evenodd" : void 0,
1455
+ stroke: "none"
1456
+ }, i);
1457
+ return /* @__PURE__ */ jsx("path", {
1458
+ d: set.d,
1459
+ fill: "none",
1460
+ stroke: fillColor || strokeColor,
1461
+ strokeLinecap: "round",
1462
+ strokeLinejoin: "round",
1463
+ strokeWidth: drawable.options.fillWeight ?? strokeWidth / 2
1464
+ }, i);
1465
+ }) });
1466
+ };
1467
+ var RectangleRender = ({ el }) => {
1468
+ const radius = getCornerRadius(el);
1469
+ const opts = roughOptionsForElement(el);
1470
+ const drawable = radius > 0 ? path(roundedRectPath(el.width, el.height, radius), opts) : rectangle(el);
1471
+ return /* @__PURE__ */ jsx(PathSet, {
1472
+ drawable,
1473
+ fillColor: el.backgroundColor !== "transparent" ? el.backgroundColor : void 0,
1474
+ strokeColor: el.strokeColor,
1475
+ strokeWidth: el.strokeWidth
1476
+ });
1477
+ };
1478
+ var EllipseRender = ({ el }) => {
1479
+ const drawable = ellipse(el);
1480
+ return /* @__PURE__ */ jsx(PathSet, {
1481
+ drawable,
1482
+ fillColor: el.backgroundColor !== "transparent" ? el.backgroundColor : void 0,
1483
+ strokeColor: el.strokeColor,
1484
+ strokeWidth: el.strokeWidth
1485
+ });
1486
+ };
1487
+ var DiamondRender = ({ el }) => {
1488
+ const drawable = diamond(el);
1489
+ return /* @__PURE__ */ jsx(PathSet, {
1490
+ drawable,
1491
+ fillColor: el.backgroundColor !== "transparent" ? el.backgroundColor : void 0,
1492
+ strokeColor: el.strokeColor,
1493
+ strokeWidth: el.strokeWidth
1494
+ });
1495
+ };
1496
+ var ARROWHEAD_LENGTH = 18;
1497
+ function arrowheadAngle(points, end) {
1498
+ if (points.length < 2) return {
1499
+ x: 0,
1500
+ y: 0,
1501
+ angle: 0
1502
+ };
1503
+ const idx = end === "end" ? points.length - 1 : 0;
1504
+ const next = end === "end" ? points.length - 2 : 1;
1505
+ const [x, y] = points[idx];
1506
+ const [px, py] = points[next];
1507
+ return {
1508
+ x,
1509
+ y,
1510
+ angle: Math.atan2(y - py, x - px)
1511
+ };
1512
+ }
1513
+ var Arrowhead = ({ angle, color, shape, strokeWidth, x, y }) => {
1514
+ if (!shape) return null;
1515
+ if (shape === "arrow" || shape === "triangle" || shape === "triangle_outline") {
1516
+ const len = ARROWHEAD_LENGTH;
1517
+ const a1 = angle + Math.PI - Math.PI / 7;
1518
+ const a2 = angle + Math.PI + Math.PI / 7;
1519
+ const x1 = x + Math.cos(a1) * len;
1520
+ const y1 = y + Math.sin(a1) * len;
1521
+ const x2 = x + Math.cos(a2) * len;
1522
+ const y2 = y + Math.sin(a2) * len;
1523
+ if (shape === "arrow") return /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
1524
+ stroke: color,
1525
+ strokeLinecap: "round",
1526
+ strokeWidth,
1527
+ x1: x,
1528
+ x2: x1,
1529
+ y1: y,
1530
+ y2: y1
1531
+ }), /* @__PURE__ */ jsx("line", {
1532
+ stroke: color,
1533
+ strokeLinecap: "round",
1534
+ strokeWidth,
1535
+ x1: x,
1536
+ x2,
1537
+ y1: y,
1538
+ y2
1539
+ })] });
1540
+ return /* @__PURE__ */ jsx("polygon", {
1541
+ fill: shape === "triangle" ? color : "none",
1542
+ points: `${x},${y} ${x1},${y1} ${x2},${y2}`,
1543
+ stroke: color,
1544
+ strokeLinejoin: "round",
1545
+ strokeWidth
1546
+ });
1547
+ }
1548
+ if (shape === "dot" || shape === "circle" || shape === "circle_outline") return /* @__PURE__ */ jsx("circle", {
1549
+ cx: x,
1550
+ cy: y,
1551
+ fill: shape === "circle_outline" ? "none" : color,
1552
+ r: ARROWHEAD_LENGTH / 3,
1553
+ stroke: color,
1554
+ strokeWidth
1555
+ });
1556
+ if (shape === "bar") {
1557
+ const len = ARROWHEAD_LENGTH / 1.5;
1558
+ const perp = angle + Math.PI / 2;
1559
+ return /* @__PURE__ */ jsx("line", {
1560
+ stroke: color,
1561
+ strokeLinecap: "round",
1562
+ strokeWidth,
1563
+ x1: x + Math.cos(perp) * len,
1564
+ x2: x - Math.cos(perp) * len,
1565
+ y1: y + Math.sin(perp) * len,
1566
+ y2: y - Math.sin(perp) * len
1567
+ });
1568
+ }
1569
+ return null;
1570
+ };
1571
+ var LinearRender = ({ el }) => {
1572
+ const points = el.points && el.points.length > 0 ? el.points : [[0, 0], [el.width, el.height]];
1573
+ const isCurved = el.roundness?.type === 2;
1574
+ const opts = roughOptionsForElement(el, {
1575
+ fill: void 0,
1576
+ fillStyle: void 0
1577
+ });
1578
+ const drawable = isCurved && points.length > 2 ? curve(points, opts) : linearPath(points, opts);
1579
+ const startHead = el.startArrowhead;
1580
+ const endHead = el.type === "arrow" ? el.endArrowhead ?? "arrow" : el.endArrowhead;
1581
+ const startInfo = startHead ? arrowheadAngle(points, "start") : null;
1582
+ const endInfo = endHead ? arrowheadAngle(points, "end") : null;
1583
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1584
+ /* @__PURE__ */ jsx(PathSet, {
1585
+ drawable,
1586
+ strokeColor: el.strokeColor,
1587
+ strokeWidth: el.strokeWidth
1588
+ }),
1589
+ startHead && startInfo && /* @__PURE__ */ jsx(Arrowhead, {
1590
+ angle: startInfo.angle + Math.PI,
1591
+ color: el.strokeColor,
1592
+ shape: startHead,
1593
+ strokeWidth: el.strokeWidth,
1594
+ x: startInfo.x,
1595
+ y: startInfo.y
1596
+ }),
1597
+ endHead && endInfo && /* @__PURE__ */ jsx(Arrowhead, {
1598
+ angle: endInfo.angle,
1599
+ color: el.strokeColor,
1600
+ shape: endHead,
1601
+ strokeWidth: el.strokeWidth,
1602
+ x: endInfo.x,
1603
+ y: endInfo.y
1604
+ })
1605
+ ] });
1606
+ };
1607
+ var FreedrawRender = ({ el }) => {
1608
+ if (!el.points || el.points.length === 0) return null;
1609
+ if (el.points.length === 1) {
1610
+ const [x, y] = el.points[0];
1611
+ return /* @__PURE__ */ jsx("circle", {
1612
+ cx: x,
1613
+ cy: y,
1614
+ fill: el.strokeColor,
1615
+ r: el.strokeWidth
1616
+ });
1617
+ }
1618
+ return /* @__PURE__ */ jsx("path", {
1619
+ d: freedrawOutline(el),
1620
+ fill: el.strokeColor,
1621
+ stroke: "none"
1622
+ });
1623
+ };
1624
+ var DEFAULT_LINE_HEIGHT = 1.25;
1625
+ var TextRender = ({ el }) => {
1626
+ const lineHeight = el.lineHeight ?? DEFAULT_LINE_HEIGHT;
1627
+ const lines = el.text.split("\n");
1628
+ const fontSize = el.fontSize;
1629
+ const family = fontFamilyToCss(el.fontFamily);
1630
+ const anchor = el.textAlign === "center" ? "middle" : el.textAlign === "right" ? "end" : "start";
1631
+ const ax = el.textAlign === "center" ? el.width / 2 : el.textAlign === "right" ? el.width : 0;
1632
+ const dy = fontSize * lineHeight;
1633
+ const baseline = fontSize * .82;
1634
+ return /* @__PURE__ */ jsx("text", {
1635
+ dominantBaseline: "alphabetic",
1636
+ fill: el.strokeColor,
1637
+ fontFamily: family,
1638
+ fontSize,
1639
+ style: { whiteSpace: "pre" },
1640
+ textAnchor: anchor,
1641
+ x: ax,
1642
+ y: baseline,
1643
+ children: lines.map((line, i) => /* @__PURE__ */ jsx("tspan", {
1644
+ dy: i === 0 ? 0 : dy,
1645
+ x: ax,
1646
+ children: line || " "
1647
+ }, i))
1648
+ });
1649
+ };
1650
+ var ImageRender = ({ el, files }) => {
1651
+ const darkFilter = use(SceneDarkContext);
1652
+ const clipId = `rich-excalidraw-crop-${useId().replaceAll(/[^\w-]/g, "")}`;
1653
+ const file = el.fileId && files ? files[el.fileId] : void 0;
1654
+ if (!file?.dataURL) return /* @__PURE__ */ jsx(ImagePlaceholder, {
1655
+ el,
1656
+ label: "Image"
1657
+ });
1658
+ const scaleX = el.scale?.[0] ?? 1;
1659
+ const scaleY = el.scale?.[1] ?? 1;
1660
+ const flip = scaleX !== 1 || scaleY !== 1 ? `translate(${scaleX < 0 ? el.width : 0} ${scaleY < 0 ? el.height : 0}) scale(${scaleX} ${scaleY})` : void 0;
1661
+ const filter = darkFilter ? `url(#${darkFilter.filterId})` : void 0;
1662
+ const crop = el.crop;
1663
+ if (crop && crop.width > 0 && crop.height > 0) {
1664
+ const sx = el.width / crop.width;
1665
+ const sy = el.height / crop.height;
1666
+ const naturalWidth = crop.naturalWidth ?? crop.x + crop.width;
1667
+ const naturalHeight = crop.naturalHeight ?? crop.y + crop.height;
1668
+ return /* @__PURE__ */ jsxs("g", {
1669
+ transform: flip,
1670
+ children: [/* @__PURE__ */ jsx("clipPath", {
1671
+ id: clipId,
1672
+ children: /* @__PURE__ */ jsx("rect", {
1673
+ height: el.height,
1674
+ width: el.width
1675
+ })
1676
+ }), /* @__PURE__ */ jsx("image", {
1677
+ clipPath: `url(#${clipId})`,
1678
+ filter,
1679
+ height: naturalHeight * sy,
1680
+ href: file.dataURL,
1681
+ preserveAspectRatio: "none",
1682
+ width: naturalWidth * sx,
1683
+ x: -crop.x * sx,
1684
+ y: -crop.y * sy
1685
+ })]
1686
+ });
1687
+ }
1688
+ return /* @__PURE__ */ jsx("image", {
1689
+ filter,
1690
+ height: el.height,
1691
+ href: file.dataURL,
1692
+ preserveAspectRatio: "none",
1693
+ transform: flip,
1694
+ width: el.width
1695
+ });
1696
+ };
1697
+ var ImagePlaceholder = ({ el, label }) => {
1698
+ return /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("rect", {
1699
+ fill: "none",
1700
+ height: el.height,
1701
+ stroke: el.strokeColor || "#888",
1702
+ strokeDasharray: "4 4",
1703
+ strokeWidth: 1,
1704
+ width: el.width
1705
+ }), /* @__PURE__ */ jsx("text", {
1706
+ dominantBaseline: "middle",
1707
+ fill: el.strokeColor || "#888",
1708
+ fontFamily: fontFamilyToCss(1),
1709
+ fontSize: Math.min(16, el.height / 4),
1710
+ textAnchor: "middle",
1711
+ x: el.width / 2,
1712
+ y: el.height / 2,
1713
+ children: label
1714
+ })] });
1715
+ };
1716
+ var FrameRender = ({ el }) => {
1717
+ const name = el.name || (el.type === "magicframe" ? "Magic frame" : "Frame");
1718
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("rect", {
1719
+ fill: "none",
1720
+ height: el.height,
1721
+ rx: 4,
1722
+ stroke: "#bbb",
1723
+ strokeWidth: 1.5,
1724
+ width: el.width
1725
+ }), /* @__PURE__ */ jsx("text", {
1726
+ fill: "#999",
1727
+ fontFamily: fontFamilyToCss(2),
1728
+ fontSize: 12,
1729
+ x: 4,
1730
+ y: -4,
1731
+ children: name
1732
+ })] });
1733
+ };
1734
+ var EmbedPlaceholder = ({ el }) => /* @__PURE__ */ jsx(ImagePlaceholder, {
1735
+ el,
1736
+ label: "Embed"
1737
+ });
1738
+ //#endregion
1739
+ //#region src/scene/shadow.tsx
1740
+ var ShadowFilter = ({ dark, id }) => /* @__PURE__ */ jsx("filter", {
1741
+ height: "160%",
1742
+ id,
1743
+ width: "140%",
1744
+ x: "-20%",
1745
+ y: "-20%",
1746
+ children: /* @__PURE__ */ jsx("feDropShadow", {
1747
+ dx: "0",
1748
+ dy: "3",
1749
+ floodColor: dark ? "#fff" : "#000",
1750
+ floodOpacity: "0.14",
1751
+ stdDeviation: "4"
1752
+ })
1753
+ });
1754
+ //#endregion
1755
+ //#region src/scene/Scene.tsx
1756
+ var SVG_PADDING = 32;
1757
+ function computeSceneBounds(input) {
1758
+ const elements = resolveRichTextHeights(input);
1759
+ let minX = Infinity;
1760
+ let minY = Infinity;
1761
+ let maxX = -Infinity;
1762
+ let maxY = -Infinity;
1763
+ for (const el of elements) {
1764
+ if (el.isDeleted) continue;
1765
+ minX = Math.min(minX, el.x);
1766
+ minY = Math.min(minY, el.y);
1767
+ maxX = Math.max(maxX, el.x + el.width);
1768
+ maxY = Math.max(maxY, el.y + el.height);
1769
+ }
1770
+ if (!Number.isFinite(minX)) return {
1771
+ minX: 0,
1772
+ minY: 0,
1773
+ width: 100,
1774
+ height: 100
1775
+ };
1776
+ return {
1777
+ minX: minX - SVG_PADDING,
1778
+ minY: minY - SVG_PADDING,
1779
+ width: maxX - minX + 64,
1780
+ height: maxY - minY + 64
1781
+ };
1782
+ }
1783
+ var DARK_SCENE_FILTER = "invert(93%) hue-rotate(180deg)";
1784
+ var CounterInvertFilter = ({ id }) => /* @__PURE__ */ jsxs("filter", {
1785
+ colorInterpolationFilters: "sRGB",
1786
+ id,
1787
+ children: [/* @__PURE__ */ jsx("feColorMatrix", {
1788
+ type: "hueRotate",
1789
+ values: "180"
1790
+ }), /* @__PURE__ */ jsx("feColorMatrix", {
1791
+ type: "matrix",
1792
+ values: "-1.16279 0 0 0 1.081395 0 -1.16279 0 0 1.081395 0 0 -1.16279 0 1.081395 0 0 0 1 0"
1793
+ })]
1794
+ });
1795
+ var isFrame = (el) => el.type === "frame" || el.type === "magicframe";
1796
+ var SceneContent = memo(({ dark = false, elementProps, files, hiddenIds, scene }) => {
1797
+ const elements = resolveRichTextHeights(scene.elements.filter((el) => !el.isDeleted));
1798
+ const uid = useId().replaceAll(/[^\w-]/g, "");
1799
+ const filterId = `rich-excalidraw-counter-invert-${uid}`;
1800
+ const frames = new Map(elements.filter(isFrame).map((f) => [f.id, f]));
1801
+ const usedFrames = new Set(elements.map((el) => el.frameId).filter((id) => !!id && frames.has(id)));
1802
+ const clipId = (frameId) => `rich-excalidraw-frame-${uid}-${frameId.replaceAll(/[^\w-]/g, "")}`;
1803
+ const shadowId = `rich-excalidraw-shadow-${uid}`;
1804
+ const anyShadow = elements.some(hasShadow);
1805
+ const hasDefs = dark || usedFrames.size > 0 || anyShadow;
1806
+ return /* @__PURE__ */ jsxs(SceneDarkContext, {
1807
+ value: dark ? { filterId } : null,
1808
+ children: [hasDefs && /* @__PURE__ */ jsxs("defs", { children: [
1809
+ dark && /* @__PURE__ */ jsx(CounterInvertFilter, { id: filterId }),
1810
+ anyShadow && /* @__PURE__ */ jsx(ShadowFilter, {
1811
+ dark,
1812
+ id: shadowId
1813
+ }),
1814
+ [...usedFrames].map((id) => {
1815
+ const f = frames.get(id);
1816
+ return /* @__PURE__ */ jsx("clipPath", {
1817
+ id: clipId(id),
1818
+ children: /* @__PURE__ */ jsx("rect", {
1819
+ height: f.height,
1820
+ width: f.width,
1821
+ x: f.x,
1822
+ y: f.y
1823
+ })
1824
+ }, id);
1825
+ })
1826
+ ] }), elements.map((el) => {
1827
+ if (hiddenIds?.has(el.id)) return null;
1828
+ const element = /* @__PURE__ */ jsx(ElementGroup, {
1829
+ el,
1830
+ extra: elementProps?.(el),
1831
+ files
1832
+ }, el.id);
1833
+ const group = hasShadow(el) ? /* @__PURE__ */ jsx("g", {
1834
+ filter: `url(#${shadowId})`,
1835
+ children: element
1836
+ }, el.id) : element;
1837
+ if (el.frameId && usedFrames.has(el.frameId)) return /* @__PURE__ */ jsx("g", {
1838
+ clipPath: `url(#${clipId(el.frameId)})`,
1839
+ children: group
1840
+ }, el.id);
1841
+ return group;
1842
+ })]
1843
+ });
1844
+ });
1845
+ SceneContent.displayName = "SceneContent";
1846
+ var Scene = ({ className, files, scene, style, theme = "light" }) => {
1847
+ const bounds = computeSceneBounds(scene.elements.filter((el) => !el.isDeleted));
1848
+ const isDark = theme === "dark";
1849
+ return /* @__PURE__ */ jsx("svg", {
1850
+ className,
1851
+ preserveAspectRatio: "xMidYMid meet",
1852
+ role: "img",
1853
+ viewBox: `${bounds.minX} ${bounds.minY} ${bounds.width} ${bounds.height}`,
1854
+ xmlns: "http://www.w3.org/2000/svg",
1855
+ style: {
1856
+ width: "100%",
1857
+ height: "100%",
1858
+ display: "block",
1859
+ ...isDark ? { filter: DARK_SCENE_FILTER } : null,
1860
+ ...style
1861
+ },
1862
+ children: /* @__PURE__ */ jsx(SceneContent, {
1863
+ dark: isDark,
1864
+ files: files ?? scene.files,
1865
+ scene
1866
+ })
1867
+ });
1868
+ };
1869
+ var ElementGroup = ({ el, extra, files }) => {
1870
+ const angleDeg = angleOf(el) * 180 / Math.PI;
1871
+ const [cx, cy] = getElementCenter(el);
1872
+ const transform = `translate(${el.x} ${el.y}) rotate(${angleDeg} ${cx - el.x} ${cy - el.y})`;
1873
+ return /* @__PURE__ */ jsx("g", {
1874
+ "data-cx": cx,
1875
+ "data-cy": cy,
1876
+ "data-id": el.id,
1877
+ "data-type": el.type,
1878
+ opacity: el.opacity != null ? el.opacity / 100 : 1,
1879
+ transform,
1880
+ ...extra,
1881
+ children: /* @__PURE__ */ jsx(ElementContent, {
1882
+ el,
1883
+ files
1884
+ })
1885
+ });
1886
+ };
1887
+ //#endregion
1888
+ //#region src/scene/styles.css.ts
1889
+ var sceneRoot = "hfbknr0";
1890
+ var sceneSvg = "hfbknr1";
1891
+ var toolbar = "hfbknr2";
1892
+ var toolButton = "hfbknr3";
1893
+ var zoomLabel = "hfbknr4";
1894
+ var toolSeparator = "hfbknr5";
1895
+ //#endregion
1896
+ //#region src/scene/InteractiveScene.tsx
1897
+ var MIN_SCALE = .05;
1898
+ var MAX_SCALE = 16;
1899
+ var ZOOM_STEP = 1.2;
1900
+ var InteractiveScene = ({ mode = "inline", onExpand, scene, theme = "light" }) => {
1901
+ const containerRef = useRef(null);
1902
+ const [size, setSize] = useState({
1903
+ w: 0,
1904
+ h: 0
1905
+ });
1906
+ const [transform, setTransform] = useState({
1907
+ s: 1,
1908
+ tx: 0,
1909
+ ty: 0
1910
+ });
1911
+ const [panning, setPanning] = useState(false);
1912
+ const transformRef = useRef(transform);
1913
+ const userInteractedRef = useRef(false);
1914
+ const elements = useMemo(() => scene.elements.filter((el) => !el.isDeleted), [scene]);
1915
+ const bounds = useMemo(() => computeSceneBounds(elements), [elements]);
1916
+ useEffect(() => {
1917
+ transformRef.current = transform;
1918
+ }, [transform]);
1919
+ useLayoutEffect(() => {
1920
+ const node = containerRef.current;
1921
+ if (!node) return;
1922
+ const rect = node.getBoundingClientRect();
1923
+ setSize({
1924
+ w: rect.width,
1925
+ h: rect.height
1926
+ });
1927
+ const ro = new ResizeObserver((entries) => {
1928
+ const r = entries[0].contentRect;
1929
+ setSize({
1930
+ w: r.width,
1931
+ h: r.height
1932
+ });
1933
+ });
1934
+ ro.observe(node);
1935
+ return () => ro.disconnect();
1936
+ }, []);
1937
+ const computeFit = useCallback(() => {
1938
+ if (!size.w || !size.h) return {
1939
+ s: 1,
1940
+ tx: 0,
1941
+ ty: 0
1942
+ };
1943
+ const sceneW = bounds.width || 1;
1944
+ const sceneH = bounds.height || 1;
1945
+ const s = Math.max(MIN_SCALE, Math.min(MAX_SCALE, Math.min((size.w - 64) / sceneW, (size.h - 64) / sceneH)));
1946
+ return {
1947
+ s,
1948
+ tx: size.w / 2 - (bounds.minX + sceneW / 2) * s,
1949
+ ty: size.h / 2 - (bounds.minY + sceneH / 2) * s
1950
+ };
1951
+ }, [size, bounds]);
1952
+ const fitToContent = useCallback(() => {
1953
+ setTransform(computeFit());
1954
+ userInteractedRef.current = false;
1955
+ }, [computeFit]);
1956
+ useLayoutEffect(() => {
1957
+ if (userInteractedRef.current) return;
1958
+ if (!size.w || !size.h) return;
1959
+ setTransform(computeFit());
1960
+ }, [size, computeFit]);
1961
+ useEffect(() => {
1962
+ userInteractedRef.current = false;
1963
+ }, [scene]);
1964
+ const zoomAt = useCallback((factor, anchorX, anchorY) => {
1965
+ const t = transformRef.current;
1966
+ const newS = Math.max(MIN_SCALE, Math.min(MAX_SCALE, t.s * factor));
1967
+ const k = newS / t.s;
1968
+ if (k === 1) return;
1969
+ userInteractedRef.current = true;
1970
+ setTransform({
1971
+ s: newS,
1972
+ tx: anchorX - (anchorX - t.tx) * k,
1973
+ ty: anchorY - (anchorY - t.ty) * k
1974
+ });
1975
+ }, []);
1976
+ useEffect(() => {
1977
+ const node = containerRef.current;
1978
+ if (!node) return;
1979
+ const onWheel = (e) => {
1980
+ if (!e.ctrlKey && !e.metaKey) return;
1981
+ e.preventDefault();
1982
+ const rect = node.getBoundingClientRect();
1983
+ zoomAt(e.deltaY > 0 ? .9 : 1.1, e.clientX - rect.left, e.clientY - rect.top);
1984
+ };
1985
+ node.addEventListener("wheel", onWheel, { passive: false });
1986
+ return () => node.removeEventListener("wheel", onWheel);
1987
+ }, [zoomAt]);
1988
+ const pointersRef = useRef(/* @__PURE__ */ new Map());
1989
+ const panRef = useRef(null);
1990
+ const pinchRef = useRef(null);
1991
+ const ownsPointer = (e) => !(mode === "inline" && e.pointerType === "touch");
1992
+ const startPinch = () => {
1993
+ const pts = [...pointersRef.current.values()];
1994
+ const node = containerRef.current;
1995
+ if (pts.length < 2 || !node) return;
1996
+ const rect = node.getBoundingClientRect();
1997
+ pinchRef.current = {
1998
+ distance: Math.hypot(pts[0].x - pts[1].x, pts[0].y - pts[1].y) || 1,
1999
+ origScale: transformRef.current.s,
2000
+ origTx: transformRef.current.tx,
2001
+ origTy: transformRef.current.ty,
2002
+ midX: (pts[0].x + pts[1].x) / 2 - rect.left,
2003
+ midY: (pts[0].y + pts[1].y) / 2 - rect.top
2004
+ };
2005
+ };
2006
+ const handlePointerDown = (e) => {
2007
+ if (!ownsPointer(e)) return;
2008
+ if (e.pointerType === "mouse" && e.button !== 0) return;
2009
+ if (e.target.closest("button")) return;
2010
+ e.currentTarget.setPointerCapture(e.pointerId);
2011
+ pointersRef.current.set(e.pointerId, {
2012
+ x: e.clientX,
2013
+ y: e.clientY
2014
+ });
2015
+ if (pointersRef.current.size === 1) {
2016
+ panRef.current = {
2017
+ startX: e.clientX,
2018
+ startY: e.clientY,
2019
+ origTx: transformRef.current.tx,
2020
+ origTy: transformRef.current.ty
2021
+ };
2022
+ setPanning(true);
2023
+ } else if (pointersRef.current.size === 2) {
2024
+ panRef.current = null;
2025
+ startPinch();
2026
+ }
2027
+ };
2028
+ const handlePointerMove = (e) => {
2029
+ if (!pointersRef.current.has(e.pointerId)) return;
2030
+ pointersRef.current.set(e.pointerId, {
2031
+ x: e.clientX,
2032
+ y: e.clientY
2033
+ });
2034
+ const pinch = pinchRef.current;
2035
+ if (pinch && pointersRef.current.size === 2) {
2036
+ userInteractedRef.current = true;
2037
+ const pts = [...pointersRef.current.values()];
2038
+ const ratio = (Math.hypot(pts[0].x - pts[1].x, pts[0].y - pts[1].y) || 1) / pinch.distance;
2039
+ const newS = Math.max(MIN_SCALE, Math.min(MAX_SCALE, pinch.origScale * ratio));
2040
+ const k = newS / pinch.origScale;
2041
+ setTransform({
2042
+ s: newS,
2043
+ tx: pinch.midX - (pinch.midX - pinch.origTx) * k,
2044
+ ty: pinch.midY - (pinch.midY - pinch.origTy) * k
2045
+ });
2046
+ return;
2047
+ }
2048
+ const pan = panRef.current;
2049
+ if (pan && pointersRef.current.size === 1) {
2050
+ userInteractedRef.current = true;
2051
+ setTransform((t) => ({
2052
+ s: t.s,
2053
+ tx: pan.origTx + e.clientX - pan.startX,
2054
+ ty: pan.origTy + e.clientY - pan.startY
2055
+ }));
2056
+ }
2057
+ };
2058
+ const releasePointer = (e) => {
2059
+ if (!pointersRef.current.delete(e.pointerId)) return;
2060
+ if (pointersRef.current.size < 2) pinchRef.current = null;
2061
+ if (pointersRef.current.size === 0) {
2062
+ panRef.current = null;
2063
+ setPanning(false);
2064
+ }
2065
+ if (e.currentTarget.hasPointerCapture(e.pointerId)) e.currentTarget.releasePointerCapture(e.pointerId);
2066
+ };
2067
+ const handleDoubleClick = (e) => {
2068
+ if (e.target.closest("button")) return;
2069
+ fitToContent();
2070
+ };
2071
+ const centerZoom = (factor) => zoomAt(factor, size.w / 2, size.h / 2);
2072
+ const isDark = theme === "dark";
2073
+ const label = `Whiteboard, ${elements.length} elements`;
2074
+ return /* @__PURE__ */ jsxs("div", {
2075
+ className: sceneRoot,
2076
+ "data-color-scheme": theme,
2077
+ "data-mode": mode,
2078
+ "data-panning": panning,
2079
+ ref: containerRef,
2080
+ onDoubleClick: handleDoubleClick,
2081
+ onPointerCancel: releasePointer,
2082
+ onPointerDown: handlePointerDown,
2083
+ onPointerMove: handlePointerMove,
2084
+ onPointerUp: releasePointer,
2085
+ children: [/* @__PURE__ */ jsx("svg", {
2086
+ "aria-label": label,
2087
+ className: sceneSvg,
2088
+ preserveAspectRatio: "xMinYMin meet",
2089
+ role: "img",
2090
+ style: isDark ? { filter: DARK_SCENE_FILTER } : void 0,
2091
+ viewBox: `0 0 ${size.w || 1} ${size.h || 1}`,
2092
+ xmlns: "http://www.w3.org/2000/svg",
2093
+ children: /* @__PURE__ */ jsx("g", {
2094
+ transform: `translate(${transform.tx} ${transform.ty}) scale(${transform.s})`,
2095
+ children: /* @__PURE__ */ jsx(SceneContent, {
2096
+ dark: isDark,
2097
+ files: scene.files,
2098
+ scene
2099
+ })
2100
+ })
2101
+ }), /* @__PURE__ */ jsxs("div", {
2102
+ className: toolbar,
2103
+ children: [
2104
+ /* @__PURE__ */ jsx("button", {
2105
+ "aria-label": "Zoom out",
2106
+ className: toolButton,
2107
+ title: "Zoom out (⌘/Ctrl + scroll)",
2108
+ type: "button",
2109
+ onClick: () => centerZoom(1 / ZOOM_STEP),
2110
+ children: /* @__PURE__ */ jsx(ZoomOut, {})
2111
+ }),
2112
+ /* @__PURE__ */ jsxs("span", {
2113
+ className: zoomLabel,
2114
+ children: [Math.round(transform.s * 100), "%"]
2115
+ }),
2116
+ /* @__PURE__ */ jsx("button", {
2117
+ "aria-label": "Zoom in",
2118
+ className: toolButton,
2119
+ title: "Zoom in (⌘/Ctrl + scroll)",
2120
+ type: "button",
2121
+ onClick: () => centerZoom(ZOOM_STEP),
2122
+ children: /* @__PURE__ */ jsx(ZoomIn, {})
2123
+ }),
2124
+ /* @__PURE__ */ jsx("span", {
2125
+ "aria-hidden": true,
2126
+ className: toolSeparator
2127
+ }),
2128
+ /* @__PURE__ */ jsx("button", {
2129
+ "aria-label": "Fit to content",
2130
+ className: toolButton,
2131
+ title: "Fit to content (double-click)",
2132
+ type: "button",
2133
+ onClick: fitToContent,
2134
+ children: /* @__PURE__ */ jsx(ScanSearch, {})
2135
+ }),
2136
+ onExpand && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
2137
+ "aria-hidden": true,
2138
+ className: "hfbknr5"
2139
+ }), /* @__PURE__ */ jsx("button", {
2140
+ "aria-label": "Fullscreen",
2141
+ className: "hfbknr3",
2142
+ title: "Fullscreen",
2143
+ type: "button",
2144
+ onClick: (e) => onExpand(e.currentTarget),
2145
+ children: /* @__PURE__ */ jsx(Maximize2, {})
2146
+ })] })
2147
+ ]
2148
+ })]
2149
+ });
2150
+ };
2151
+ //#endregion
2152
+ //#region src/scene/normalize.ts
2153
+ function toScene(data) {
2154
+ if (!data) return null;
2155
+ if (typeof data !== "object") return null;
2156
+ if (!Array.isArray(data.elements) && data.data !== void 0) return toScene(data.data);
2157
+ return {
2158
+ type: "excalidraw",
2159
+ elements: Array.isArray(data.elements) ? data.elements : [],
2160
+ appState: data.appState ?? {},
2161
+ files: data.files ?? {}
2162
+ };
2163
+ }
2164
+ function countElements(scene) {
2165
+ return scene.elements.filter((el) => !el.isDeleted).length;
2166
+ }
2167
+ //#endregion
2168
+ //#region src/useWhiteboardData.ts
2169
+ function resolveUrl(url, apiUrl) {
2170
+ const refLine = url;
2171
+ if (url.startsWith("http") || url.startsWith("blob:") || isLocalScenePath(url)) return {
2172
+ fetchUrl: url,
2173
+ refLine
2174
+ };
2175
+ if (url.startsWith("ref:") && apiUrl) return {
2176
+ fetchUrl: `${apiUrl}/objects/${url.slice(4)}`,
2177
+ refLine
2178
+ };
2179
+ return { error: url.startsWith("ref:") ? "Missing apiUrl for ref resolution" : "Unrecognized snapshot format" };
2180
+ }
2181
+ function typedToParsed(typed, apiUrl) {
2182
+ switch (typed.type) {
2183
+ case "inline": return {
2184
+ type: "inline",
2185
+ snapshot: typed.data
2186
+ };
2187
+ case "remote": {
2188
+ const result = resolveUrl(typed.url, apiUrl);
2189
+ if ("error" in result) return {
2190
+ type: "error",
2191
+ error: result.error
2192
+ };
2193
+ return {
2194
+ type: "remote",
2195
+ fetchUrl: result.fetchUrl,
2196
+ refLine: result.refLine
2197
+ };
2198
+ }
2199
+ case "delta": {
2200
+ const result = resolveUrl(typed.baseUrl, apiUrl);
2201
+ if ("error" in result) return {
2202
+ type: "error",
2203
+ error: result.error
2204
+ };
2205
+ return {
2206
+ type: "incremental",
2207
+ fetchUrl: result.fetchUrl,
2208
+ refLine: result.refLine,
2209
+ delta: typed.delta
2210
+ };
2211
+ }
2212
+ }
2213
+ }
2214
+ function stringToParsed(data, apiUrl) {
2215
+ if (!data.trim()) return { type: "empty" };
2216
+ const typed = parseSnapshot(data);
2217
+ if (!typed) return {
2218
+ type: "error",
2219
+ error: "Unrecognized snapshot format"
2220
+ };
2221
+ return typedToParsed(typed, apiUrl);
2222
+ }
2223
+ function useWhiteboardData(data) {
2224
+ const { apiUrl } = useWhiteboardConfig();
2225
+ const parsed = useMemo(() => {
2226
+ if (data === null || data === void 0) return { type: "empty" };
2227
+ if (typeof data === "string") return stringToParsed(data, apiUrl);
2228
+ return typedToParsed(data, apiUrl);
2229
+ }, [data, apiUrl]);
2230
+ const [remoteSnapshot, setRemoteSnapshot] = useState();
2231
+ const [baseData, setBaseData] = useState();
2232
+ const [loading, setLoading] = useState(parsed.type === "remote" || parsed.type === "incremental");
2233
+ const [error, setError] = useState("");
2234
+ const [attempt, setAttempt] = useState(0);
2235
+ const retry = useCallback(() => setAttempt((n) => n + 1), []);
2236
+ useEffect(() => {
2237
+ if (parsed.type !== "remote" && parsed.type !== "incremental") return;
2238
+ const { fetchUrl } = parsed;
2239
+ const delta = parsed.type === "incremental" ? parsed.delta : void 0;
2240
+ let cancelled = false;
2241
+ setLoading(true);
2242
+ setError("");
2243
+ fetch(fetchUrl).then((res) => {
2244
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
2245
+ return res.json();
2246
+ }).then(async (json) => {
2247
+ if (cancelled) return;
2248
+ setBaseData(json);
2249
+ if ((delta ? Object.keys(delta) : []).length > 0) {
2250
+ const { patch } = await import("jsondiffpatch");
2251
+ if (cancelled) return;
2252
+ const patched = patch(structuredClone(json), delta);
2253
+ setRemoteSnapshot(patched);
2254
+ } else setRemoteSnapshot(json);
2255
+ setLoading(false);
2256
+ }).catch((err) => {
2257
+ if (!cancelled) {
2258
+ setError(err instanceof Error ? err.message : "Failed to load");
2259
+ setLoading(false);
2260
+ }
2261
+ });
2262
+ return () => {
2263
+ cancelled = true;
2264
+ };
2265
+ }, [parsed, attempt]);
2266
+ if (parsed.type === "inline") return {
2267
+ snapshot: parsed.snapshot,
2268
+ loading: false,
2269
+ error: "",
2270
+ retry,
2271
+ retryable: false
2272
+ };
2273
+ if (parsed.type === "remote" || parsed.type === "incremental") return {
2274
+ snapshot: remoteSnapshot,
2275
+ loading,
2276
+ error,
2277
+ retry,
2278
+ retryable: Boolean(error),
2279
+ baseRef: parsed.refLine,
2280
+ baseData
2281
+ };
2282
+ if (parsed.type === "error") return {
2283
+ snapshot: void 0,
2284
+ loading: false,
2285
+ error: parsed.error,
2286
+ retry,
2287
+ retryable: false
2288
+ };
2289
+ return {
2290
+ snapshot: void 0,
2291
+ loading: false,
2292
+ error: "",
2293
+ retry,
2294
+ retryable: false
2295
+ };
2296
+ }
2297
+ //#endregion
2298
+ //#region src/useWhiteboardFont.ts
2299
+ var DEFAULT_FONT_CSS_HREF = "https://cdn.jsdelivr.net/npm/lxgw-wenkai-screen-webfont/style.css";
2300
+ function useWhiteboardFont() {
2301
+ const { fontCssHref = DEFAULT_FONT_CSS_HREF } = useWhiteboardConfig();
2302
+ useEffect(() => {
2303
+ if (!fontCssHref || typeof document === "undefined") return;
2304
+ if (document.head.querySelector(`link[href="${CSS.escape(fontCssHref)}"]`)) return;
2305
+ const link = document.createElement("link");
2306
+ link.rel = "stylesheet";
2307
+ link.href = fontCssHref;
2308
+ document.head.append(link);
2309
+ }, [fontCssHref]);
2310
+ }
2311
+ //#endregion
2312
+ //#region src/WhiteboardFrameStates.tsx
2313
+ var WhiteboardPlaceholderState = ({ elementCount }) => {
2314
+ const label = elementCount ? `Whiteboard · ${elementCount} elements` : "Whiteboard";
2315
+ return /* @__PURE__ */ jsxs("div", {
2316
+ "aria-label": label,
2317
+ className: whiteboardStateLayer,
2318
+ children: [/* @__PURE__ */ jsx(PenLine, {
2319
+ "aria-hidden": true,
2320
+ className: whiteboardStateIcon
2321
+ }), /* @__PURE__ */ jsx("span", { children: label })]
2322
+ });
2323
+ };
2324
+ var WhiteboardLoadingState = () => /* @__PURE__ */ jsx("div", {
2325
+ "aria-busy": true,
2326
+ className: whiteboardLoading,
2327
+ children: /* @__PURE__ */ jsx("span", { children: "Loading whiteboard…" })
2328
+ });
2329
+ var WhiteboardEmptyState = () => /* @__PURE__ */ jsx("div", {
2330
+ className: whiteboardEmpty,
2331
+ children: /* @__PURE__ */ jsx("span", { children: "Empty whiteboard" })
2332
+ });
2333
+ var WhiteboardErrorState = ({ message, onRetry }) => /* @__PURE__ */ jsxs("div", {
2334
+ className: whiteboardError,
2335
+ role: "alert",
2336
+ children: [
2337
+ /* @__PURE__ */ jsx(TriangleAlert, {
2338
+ "aria-hidden": true,
2339
+ className: whiteboardErrorIcon
2340
+ }),
2341
+ /* @__PURE__ */ jsx("span", { children: message }),
2342
+ onRetry && /* @__PURE__ */ jsx("button", {
2343
+ className: "_1xd3mo4a",
2344
+ type: "button",
2345
+ onClick: onRetry,
2346
+ children: "Retry"
2347
+ })
2348
+ ]
2349
+ });
2350
+ //#endregion
2351
+ //#region \0@oxc-project+runtime@0.154.0/helpers/esm/typeof.js
2352
+ function _typeof(o) {
2353
+ "@babel/helpers - typeof";
2354
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
2355
+ return typeof o;
2356
+ } : function(o) {
2357
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
2358
+ }, _typeof(o);
2359
+ }
2360
+ //#endregion
2361
+ //#region \0@oxc-project+runtime@0.154.0/helpers/esm/toPrimitive.js
2362
+ function toPrimitive(t, r) {
2363
+ if ("object" != _typeof(t) || !t) return t;
2364
+ var e = t[Symbol.toPrimitive];
2365
+ if (void 0 !== e) {
2366
+ var i = e.call(t, r || "default");
2367
+ if ("object" != _typeof(i)) return i;
2368
+ throw new TypeError("@@toPrimitive must return a primitive value.");
2369
+ }
2370
+ return ("string" === r ? String : Number)(t);
2371
+ }
2372
+ //#endregion
2373
+ //#region \0@oxc-project+runtime@0.154.0/helpers/esm/toPropertyKey.js
2374
+ function toPropertyKey(t) {
2375
+ var i = toPrimitive(t, "string");
2376
+ return "symbol" == _typeof(i) ? i : i + "";
2377
+ }
2378
+ //#endregion
2379
+ //#region \0@oxc-project+runtime@0.154.0/helpers/esm/defineProperty.js
2380
+ function _defineProperty(e, r, t) {
2381
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
2382
+ value: t,
2383
+ enumerable: !0,
2384
+ configurable: !0,
2385
+ writable: !0
2386
+ }) : e[r] = t, e;
2387
+ }
2388
+ //#endregion
2389
+ //#region src/WhiteboardDisplayRenderer.tsx
2390
+ var WhiteboardDisplayRenderer_exports = /* @__PURE__ */ __exportAll({ WhiteboardDisplayRenderer: () => WhiteboardDisplayRenderer });
2391
+ var WhiteboardDisplayRenderer = ({ onExpand, snapshot }) => {
2392
+ const theme = useColorScheme();
2393
+ const { snapshot: data, loading, error, retry, retryable } = useWhiteboardData(snapshot);
2394
+ const scene = useMemo(() => toScene(data), [data]);
2395
+ useWhiteboardFont();
2396
+ const handleExpand = useCallback((target) => {
2397
+ if (!onExpand || !scene) return;
2398
+ onExpand({
2399
+ content: /* @__PURE__ */ jsx(InteractiveScene, {
2400
+ mode: "fullscreen",
2401
+ scene,
2402
+ theme
2403
+ }),
2404
+ elementCount: countElements(scene),
2405
+ target,
2406
+ theme
2407
+ });
2408
+ }, [
2409
+ onExpand,
2410
+ scene,
2411
+ theme
2412
+ ]);
2413
+ let body;
2414
+ if (loading) body = /* @__PURE__ */ jsx(WhiteboardLoadingState, {});
2415
+ else if (error) body = /* @__PURE__ */ jsx(WhiteboardErrorState, {
2416
+ message: error,
2417
+ onRetry: retryable ? retry : void 0
2418
+ });
2419
+ else if (!data) body = /* @__PURE__ */ jsx(WhiteboardEmptyState, {});
2420
+ else if (!scene) body = /* @__PURE__ */ jsx(WhiteboardErrorState, { message: "Invalid whiteboard data" });
2421
+ else if (countElements(scene) === 0) body = /* @__PURE__ */ jsx(WhiteboardEmptyState, {});
2422
+ else body = /* @__PURE__ */ jsx(WhiteboardErrorBoundary, {
2423
+ fallback: /* @__PURE__ */ jsx(WhiteboardErrorState, { message: "Failed to render whiteboard" }),
2424
+ children: /* @__PURE__ */ jsx(InteractiveScene, {
2425
+ scene,
2426
+ theme,
2427
+ onExpand: onExpand ? handleExpand : void 0
2428
+ })
2429
+ });
2430
+ return /* @__PURE__ */ jsx("div", {
2431
+ className: whiteboardStaticContainer,
2432
+ "data-theme": theme,
2433
+ children: body
2434
+ });
2435
+ };
2436
+ var WhiteboardErrorBoundary = class extends Component {
2437
+ constructor(..._args) {
2438
+ super(..._args);
2439
+ _defineProperty(this, "state", { hasError: false });
2440
+ }
2441
+ static getDerivedStateFromError() {
2442
+ return { hasError: true };
2443
+ }
2444
+ render() {
2445
+ return this.state.hasError ? this.props.fallback : this.props.children;
2446
+ }
2447
+ };
2448
+ //#endregion
2449
+ //#region src/WhiteboardSSRRenderer.tsx
2450
+ var LazyDisplayRenderer = lazy(() => Promise.resolve().then(() => WhiteboardDisplayRenderer_exports).then((m) => ({ default: m.WhiteboardDisplayRenderer })));
2451
+ function countInlineElements(snapshot) {
2452
+ try {
2453
+ const data = JSON.parse(snapshot);
2454
+ if (data && typeof data === "object" && Array.isArray(data.elements)) return data.elements.filter((el) => !el?.isDeleted).length;
2455
+ } catch {}
2456
+ }
2457
+ var WhiteboardPlaceholder = ({ snapshot }) => /* @__PURE__ */ jsx("div", {
2458
+ className: whiteboardPlaceholder,
2459
+ children: /* @__PURE__ */ jsx(WhiteboardPlaceholderState, { elementCount: countInlineElements(snapshot) })
2460
+ });
2461
+ var WhiteboardSSRRenderer = ({ onExpand, snapshot }) => {
2462
+ return /* @__PURE__ */ jsx(ViewportGate, {
2463
+ fallback: /* @__PURE__ */ jsx(WhiteboardPlaceholder, { snapshot }),
2464
+ children: /* @__PURE__ */ jsx(Suspense, {
2465
+ fallback: /* @__PURE__ */ jsx(WhiteboardPlaceholder, { snapshot }),
2466
+ children: /* @__PURE__ */ jsx(LazyDisplayRenderer, {
2467
+ snapshot,
2468
+ onExpand
2469
+ })
2470
+ })
2471
+ });
2472
+ };
2473
+ //#endregion
2474
+ //#region src/WhiteboardNode.ts
2475
+ var WhiteboardNode = class WhiteboardNode extends DecoratorNode {
2476
+ static getType() {
2477
+ return "excalidraw";
2478
+ }
2479
+ static clone(node) {
2480
+ return new WhiteboardNode(node.__snapshot, node.__key);
2481
+ }
2482
+ constructor(snapshot, key) {
2483
+ super(key);
2484
+ _defineProperty(this, "__snapshot", void 0);
2485
+ this.__snapshot = snapshot;
2486
+ }
2487
+ createDOM(_config) {
2488
+ const div = document.createElement("div");
2489
+ div.className = "rich-excalidraw-wrapper";
2490
+ return div;
2491
+ }
2492
+ updateDOM() {
2493
+ return false;
2494
+ }
2495
+ isInline() {
2496
+ return false;
2497
+ }
2498
+ static importJSON(_serializedNode) {
2499
+ return $createWhiteboardNode(_serializedNode.snapshot).updateFromJSON(_serializedNode);
2500
+ }
2501
+ exportJSON() {
2502
+ return {
2503
+ ...super.exportJSON(),
2504
+ type: "excalidraw",
2505
+ snapshot: this.__snapshot,
2506
+ version: 1
2507
+ };
2508
+ }
2509
+ getSnapshot() {
2510
+ return this.__snapshot;
2511
+ }
2512
+ setSnapshot(snapshot) {
2513
+ const writable = this.getWritable();
2514
+ writable.__snapshot = snapshot;
2515
+ }
2516
+ decorate(_editor, _config) {
2517
+ return createRendererDecoration(WHITEBOARD_NODE_KEY, WhiteboardSSRRenderer, { snapshot: this.__snapshot });
2518
+ }
2519
+ };
2520
+ function $createWhiteboardNode(snapshot) {
2521
+ return new WhiteboardNode(snapshot);
2522
+ }
2523
+ function $isWhiteboardNode(node) {
2524
+ return node instanceof WhiteboardNode;
2525
+ }
2526
+ //#endregion
2527
+ //#region src/WhiteboardExpandShell.tsx
2528
+ var WhiteboardExpandShell = ({ children, dismiss, meta = "excalidraw", title = "Whiteboard" }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
2529
+ className: whiteboardDialogHeader,
2530
+ children: [/* @__PURE__ */ jsxs("div", {
2531
+ className: whiteboardDialogHeaderTitle,
2532
+ children: [/* @__PURE__ */ jsx("span", {
2533
+ className: whiteboardDialogTitle,
2534
+ children: title
2535
+ }), meta != null && /* @__PURE__ */ jsx("span", {
2536
+ className: "_1xd3mo4f",
2537
+ children: meta
2538
+ })]
2539
+ }), /* @__PURE__ */ jsx("button", {
2540
+ className: whiteboardHeaderClose,
2541
+ type: "button",
2542
+ onClick: dismiss,
2543
+ children: /* @__PURE__ */ jsx(X, { size: 18 })
2544
+ })]
2545
+ }), /* @__PURE__ */ jsx("div", {
2546
+ className: whiteboardDialogCanvas,
2547
+ children
2548
+ })] });
2549
+ //#endregion
2550
+ export { angleOf as $, newElement as A, randomId as B, layoutBoundText as C, whiteboardSavedDot as Ct, bumpVersion as D, parseSvgSize as E, __exportAll as Et, newRichTextElement as F, getCommonBounds as G, DEFAULT_STYLE as H, newSvgElement as I, getElementCenter as J, getElementAbsoluteCorners as K, newTextElement as L, newFreedrawElement as M, newImageElement as N, syncIndices as O, newLinearElement as P, toLocalPoint as Q, contentRoot as R, restoreElements as S, whiteboardOptionsLabel as St, isSvgSource as T, WHITEBOARD_NODE_KEY as Tt, fontFamilyToCss as U, randomInteger as V, elementsInBox as W, hitTestElement as X, getLinearAbsolutePoints as Y, isLinear as Z, Scene as _, whiteboardFullscreenPopup as _t, WhiteboardSSRRenderer as a, rotatePoint as at, resolveRichTextHeights as b, whiteboardOptionsGroup as bt, WhiteboardEmptyState as c, isLocalScenePath as ct, DEFAULT_FONT_CSS_HREF as d, EXCALIDRAW_BLOCK_TRANSFORMER as dt, boundsContain as et, useWhiteboardFont as f, whiteboardDialogBody as ft, DARK_SCENE_FILTER as g, whiteboardEditorContainer as gt, toScene as h, whiteboardEditOverlay as ht, WhiteboardNode as i, normalizeBox as it, newFrameElement as j, getLineHeight as k, WhiteboardErrorState as l, parseSnapshot as lt, countElements as m, whiteboardEditLabel as mt, $createWhiteboardNode as n, boundsOfPoints as nt, WhiteboardDisplayRenderer as o, WhiteboardConfigProvider as ot, useWhiteboardData as p, whiteboardDialogCanvas as pt, getElementBounds as q, $isWhiteboardNode as r, distanceToSegment as rt, _defineProperty as s, useWhiteboardConfig as st, WhiteboardExpandShell as t, boundsIntersect as tt, WhiteboardLoadingState as u, serializeSnapshot as ut, SceneContent as v, whiteboardOptionsActions as vt, refreshTextDimensions as w, whiteboardShell as wt, normalizeElement as x, whiteboardOptionsHeading as xt, RICHTEXT_BASE_STYLE as y, whiteboardOptionsAdvanced as yt, richTextPlainText as z };