@haklex/rich-ext-whiteboard 0.0.0-stage → 0.65.0

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