@tldiagram/core-ui 1.87.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 (272) hide show
  1. package/dist/App.d.ts +1 -0
  2. package/dist/api/client.d.ts +143 -0
  3. package/dist/api/transport-vscode.d.ts +8 -0
  4. package/dist/api/transport.d.ts +1 -0
  5. package/dist/components/CodePreviewPanel-vscode.d.ts +7 -0
  6. package/dist/components/CodePreviewPanel.d.ts +9 -0
  7. package/dist/components/ConfirmDialog.d.ts +12 -0
  8. package/dist/components/ConnectorPanel.d.ts +21 -0
  9. package/dist/components/ContextBoundaryElement.d.ts +11 -0
  10. package/dist/components/ContextNeighborElement.d.ts +29 -0
  11. package/dist/components/ContextStraightConnector.d.ts +4 -0
  12. package/dist/components/CrossBranchControls.d.ts +9 -0
  13. package/dist/components/DependenciesOnboarding.d.ts +5 -0
  14. package/dist/components/DrawingCanvas.d.ts +39 -0
  15. package/dist/components/ElementLibrary-vscode.d.ts +7 -0
  16. package/dist/components/ElementLibrary.d.ts +22 -0
  17. package/dist/components/ElementNode.d.ts +36 -0
  18. package/dist/components/ElementPanel.d.ts +25 -0
  19. package/dist/components/ExploreOnboarding.d.ts +5 -0
  20. package/dist/components/ExplorePageOnboarding.d.ts +5 -0
  21. package/dist/components/ExportModal.d.ts +16 -0
  22. package/dist/components/FloatingEdge.d.ts +9 -0
  23. package/dist/components/GitSourceLinker.d.ts +8 -0
  24. package/dist/components/HeaderContext.d.ts +16 -0
  25. package/dist/components/Icons.d.ts +95 -0
  26. package/dist/components/ImportModal.d.ts +10 -0
  27. package/dist/components/InlineElementAdder.d.ts +17 -0
  28. package/dist/components/LayoutSection.d.ts +7 -0
  29. package/dist/components/LocalSourceLinker.d.ts +8 -0
  30. package/dist/components/MiniZoomOnboarding.d.ts +5 -0
  31. package/dist/components/NavBreadcrumb.d.ts +6 -0
  32. package/dist/components/NodeBody.d.ts +12 -0
  33. package/dist/components/NodeContainer.d.ts +8 -0
  34. package/dist/components/NodeHoverCard.d.ts +10 -0
  35. package/dist/components/PanelHeader.d.ts +8 -0
  36. package/dist/components/PanelUI.d.ts +3 -0
  37. package/dist/components/ProxyConnectorEdge.d.ts +4 -0
  38. package/dist/components/ProxyConnectorPanel.d.ts +9 -0
  39. package/dist/components/SafeBackground.d.ts +13 -0
  40. package/dist/components/ScrollIndicatorWrapper.d.ts +8 -0
  41. package/dist/components/SetChildModal.d.ts +10 -0
  42. package/dist/components/SetParentModal.d.ts +10 -0
  43. package/dist/components/SlidingPanel.d.ts +16 -0
  44. package/dist/components/TagUpsert.d.ts +8 -0
  45. package/dist/components/TopMenuBar.d.ts +8 -0
  46. package/dist/components/ViewBezierConnector.d.ts +4 -0
  47. package/dist/components/ViewDrawMenu.d.ts +22 -0
  48. package/dist/components/ViewEditorEdgeLabelLayout.d.ts +16 -0
  49. package/dist/components/ViewEditorOnboarding.d.ts +5 -0
  50. package/dist/components/ViewExplorer/TagManager/ColorPicker.d.ts +7 -0
  51. package/dist/components/ViewExplorer/TagManager/GroupNamingPopover.d.ts +10 -0
  52. package/dist/components/ViewExplorer/TagManager/LayerItem.d.ts +27 -0
  53. package/dist/components/ViewExplorer/TagManager/TagItem.d.ts +25 -0
  54. package/dist/components/ViewExplorer/TagManager/index.d.ts +21 -0
  55. package/dist/components/ViewExplorer/ViewNavigator.d.ts +11 -0
  56. package/dist/components/ViewExplorer/ViewSearch.d.ts +8 -0
  57. package/dist/components/ViewExplorer/ViewTree.d.ts +18 -0
  58. package/dist/components/ViewExplorer/index.d.ts +31 -0
  59. package/dist/components/ViewExplorer/types.d.ts +11 -0
  60. package/dist/components/ViewExplorer/utils.d.ts +6 -0
  61. package/dist/components/ViewExplorer-vscode.d.ts +6 -0
  62. package/dist/components/ViewFloatingMenu-vscode.d.ts +27 -0
  63. package/dist/components/ViewFloatingMenu.d.ts +39 -0
  64. package/dist/components/ViewGridNode.d.ts +29 -0
  65. package/dist/components/ViewHeaderButton.d.ts +11 -0
  66. package/dist/components/ViewPanel.d.ts +18 -0
  67. package/dist/components/ViewsGridOnboarding.d.ts +5 -0
  68. package/dist/components/ZUI/ZUICanvas.d.ts +18 -0
  69. package/dist/components/ZUI/index.d.ts +2 -0
  70. package/dist/components/ZUI/layout.d.ts +18 -0
  71. package/dist/components/ZUI/proxy.d.ts +25 -0
  72. package/dist/components/ZUI/renderer.d.ts +30 -0
  73. package/dist/components/ZUI/types.d.ts +140 -0
  74. package/dist/components/ZUI/useZUIInteraction.d.ts +21 -0
  75. package/dist/config/runtime-vscode.d.ts +22 -0
  76. package/dist/config/runtime.d.ts +5 -0
  77. package/dist/constants/colors.d.ts +27 -0
  78. package/dist/constants/diagramColors.d.ts +1 -0
  79. package/dist/context/ThemeContext.d.ts +27 -0
  80. package/dist/crossBranch/graph.d.ts +13 -0
  81. package/dist/crossBranch/resolve.d.ts +22 -0
  82. package/dist/crossBranch/settings.d.ts +6 -0
  83. package/dist/crossBranch/store.d.ts +11 -0
  84. package/dist/crossBranch/types.d.ts +96 -0
  85. package/dist/demo/DemoPage.d.ts +9 -0
  86. package/dist/demo/seed.d.ts +9 -0
  87. package/dist/demo/store.d.ts +137 -0
  88. package/dist/demo/viewEditor.d.ts +26 -0
  89. package/dist/favicon.svg +35 -0
  90. package/dist/hooks/useSafeFitView.d.ts +16 -0
  91. package/dist/index.css +1 -0
  92. package/dist/index.d.ts +115 -0
  93. package/dist/index.js +19966 -0
  94. package/dist/lib/vscodeBridge-vscode.d.ts +13 -0
  95. package/dist/lib/vscodeBridge.d.ts +5 -0
  96. package/dist/logo-120.png +0 -0
  97. package/dist/logo-bw.png +0 -0
  98. package/dist/logo-bw.svg +15 -0
  99. package/dist/logo-text.svg +51 -0
  100. package/dist/logo.svg +35 -0
  101. package/dist/pages/AppearanceSettings.d.ts +3 -0
  102. package/dist/pages/Dependencies.d.ts +1 -0
  103. package/dist/pages/InfiniteZoom.d.ts +7 -0
  104. package/dist/pages/Settings.d.ts +7 -0
  105. package/dist/pages/ViewEditor/components/EditorMenus.d.ts +24 -0
  106. package/dist/pages/ViewEditor/components/EditorOverlays.d.ts +30 -0
  107. package/dist/pages/ViewEditor/components/EmptyCanvasState.d.ts +7 -0
  108. package/dist/pages/ViewEditor/context.d.ts +13 -0
  109. package/dist/pages/ViewEditor/hooks/useCanvasInteractions.d.ts +201 -0
  110. package/dist/pages/ViewEditor/hooks/useDrawingEngine.d.ts +40 -0
  111. package/dist/pages/ViewEditor/hooks/useViewContextNeighbours.d.ts +20 -0
  112. package/dist/pages/ViewEditor/hooks/useViewData.d.ts +74 -0
  113. package/dist/pages/ViewEditor/index.d.ts +8 -0
  114. package/dist/pages/ViewEditor/utils.d.ts +14 -0
  115. package/dist/pages/Views.d.ts +6 -0
  116. package/dist/pages/ViewsGrid.d.ts +6 -0
  117. package/dist/pkg/importer/mermaid.d.ts +7 -0
  118. package/dist/pkg/importer/mermaid.test.d.ts +1 -0
  119. package/dist/platform/PlatformContext.d.ts +6 -0
  120. package/dist/platform/context.d.ts +3 -0
  121. package/dist/platform/local.d.ts +2 -0
  122. package/dist/platform/types.d.ts +17 -0
  123. package/dist/slots.d.ts +67 -0
  124. package/dist/theme.d.ts +2 -0
  125. package/dist/types/index.d.ts +193 -0
  126. package/dist/types/vscode-messages.d.ts +60 -0
  127. package/dist/utils/edgeDistribution.d.ts +34 -0
  128. package/dist/utils/githubApi.d.ts +4 -0
  129. package/dist/utils/githubCache.d.ts +17 -0
  130. package/dist/utils/ids.d.ts +2 -0
  131. package/dist/utils/technologyCatalog.d.ts +15 -0
  132. package/dist/utils/toast.d.ts +15 -0
  133. package/dist/utils/treesitter.d.ts +13 -0
  134. package/dist/utils/url.d.ts +12 -0
  135. package/package.json +159 -0
  136. package/src/App.tsx +141 -0
  137. package/src/api/client.ts +618 -0
  138. package/src/api/transport-vscode.ts +28 -0
  139. package/src/api/transport.ts +7 -0
  140. package/src/assets/logo-mark.svg +31 -0
  141. package/src/assets/logo-wordmark.svg +22 -0
  142. package/src/assets/logo.svg +35 -0
  143. package/src/components/CodePreviewPanel-vscode.tsx +85 -0
  144. package/src/components/CodePreviewPanel.tsx +384 -0
  145. package/src/components/ConfirmDialog.tsx +66 -0
  146. package/src/components/ConnectorPanel.tsx +403 -0
  147. package/src/components/ContextBoundaryElement.tsx +35 -0
  148. package/src/components/ContextNeighborElement.tsx +282 -0
  149. package/src/components/ContextStraightConnector.tsx +144 -0
  150. package/src/components/CrossBranchControls.tsx +105 -0
  151. package/src/components/DependenciesOnboarding.tsx +427 -0
  152. package/src/components/DrawingCanvas.tsx +391 -0
  153. package/src/components/ElementLibrary-vscode.tsx +9 -0
  154. package/src/components/ElementLibrary.tsx +512 -0
  155. package/src/components/ElementNode.tsx +1033 -0
  156. package/src/components/ElementPanel.tsx +928 -0
  157. package/src/components/ExploreOnboarding.tsx +347 -0
  158. package/src/components/ExplorePageOnboarding.tsx +383 -0
  159. package/src/components/ExportModal.tsx +132 -0
  160. package/src/components/FloatingEdge.tsx +115 -0
  161. package/src/components/GitSourceLinker.tsx +1053 -0
  162. package/src/components/HeaderContext.tsx +30 -0
  163. package/src/components/Icons.tsx +245 -0
  164. package/src/components/ImportModal.tsx +219 -0
  165. package/src/components/InlineElementAdder.tsx +216 -0
  166. package/src/components/LayoutSection.tsx +624 -0
  167. package/src/components/LocalSourceLinker.tsx +330 -0
  168. package/src/components/MiniZoomOnboarding.tsx +78 -0
  169. package/src/components/NavBreadcrumb.tsx +24 -0
  170. package/src/components/NodeBody.tsx +89 -0
  171. package/src/components/NodeContainer.tsx +58 -0
  172. package/src/components/NodeHoverCard.tsx +135 -0
  173. package/src/components/PanelHeader.tsx +36 -0
  174. package/src/components/PanelUI.tsx +24 -0
  175. package/src/components/ProxyConnectorEdge.tsx +169 -0
  176. package/src/components/ProxyConnectorPanel.tsx +130 -0
  177. package/src/components/SafeBackground.tsx +19 -0
  178. package/src/components/ScrollIndicatorWrapper.tsx +117 -0
  179. package/src/components/SetChildModal.tsx +191 -0
  180. package/src/components/SetParentModal.tsx +187 -0
  181. package/src/components/SlidingPanel.tsx +114 -0
  182. package/src/components/TagUpsert.tsx +142 -0
  183. package/src/components/TopMenuBar.tsx +380 -0
  184. package/src/components/ViewBezierConnector.tsx +143 -0
  185. package/src/components/ViewDrawMenu.tsx +270 -0
  186. package/src/components/ViewEditorEdgeLabelLayout.ts +189 -0
  187. package/src/components/ViewEditorOnboarding.tsx +445 -0
  188. package/src/components/ViewExplorer/TagManager/ColorPicker.tsx +49 -0
  189. package/src/components/ViewExplorer/TagManager/GroupNamingPopover.tsx +96 -0
  190. package/src/components/ViewExplorer/TagManager/LayerItem.tsx +228 -0
  191. package/src/components/ViewExplorer/TagManager/TagItem.tsx +242 -0
  192. package/src/components/ViewExplorer/TagManager/index.tsx +418 -0
  193. package/src/components/ViewExplorer/ViewNavigator.tsx +121 -0
  194. package/src/components/ViewExplorer/ViewSearch.tsx +33 -0
  195. package/src/components/ViewExplorer/ViewTree.tsx +98 -0
  196. package/src/components/ViewExplorer/index.tsx +384 -0
  197. package/src/components/ViewExplorer/types.ts +13 -0
  198. package/src/components/ViewExplorer/utils.ts +56 -0
  199. package/src/components/ViewExplorer-vscode.tsx +8 -0
  200. package/src/components/ViewFloatingMenu-vscode.tsx +248 -0
  201. package/src/components/ViewFloatingMenu.tsx +379 -0
  202. package/src/components/ViewGridNode.tsx +451 -0
  203. package/src/components/ViewHeaderButton.tsx +60 -0
  204. package/src/components/ViewPanel.tsx +162 -0
  205. package/src/components/ViewsGridOnboarding.tsx +400 -0
  206. package/src/components/ZUI/ZUICanvas.tsx +853 -0
  207. package/src/components/ZUI/index.ts +3 -0
  208. package/src/components/ZUI/layout.ts +323 -0
  209. package/src/components/ZUI/proxy.ts +278 -0
  210. package/src/components/ZUI/renderer.ts +1189 -0
  211. package/src/components/ZUI/types.ts +150 -0
  212. package/src/components/ZUI/useZUIInteraction.ts +720 -0
  213. package/src/config/runtime-vscode.ts +46 -0
  214. package/src/config/runtime.ts +30 -0
  215. package/src/constants/colors.ts +80 -0
  216. package/src/constants/diagramColors.ts +9 -0
  217. package/src/context/ThemeContext.tsx +158 -0
  218. package/src/crossBranch/graph.ts +207 -0
  219. package/src/crossBranch/resolve.ts +643 -0
  220. package/src/crossBranch/settings.ts +59 -0
  221. package/src/crossBranch/store.ts +71 -0
  222. package/src/crossBranch/types.ts +102 -0
  223. package/src/demo/DemoPage.tsx +184 -0
  224. package/src/demo/seed.ts +67 -0
  225. package/src/demo/store.ts +536 -0
  226. package/src/demo/viewEditor.ts +110 -0
  227. package/src/hooks/useSafeFitView.ts +60 -0
  228. package/src/index.css +309 -0
  229. package/src/index.ts +184 -0
  230. package/src/kafka-ss.png +0 -0
  231. package/src/lib/vscodeBridge-vscode.ts +27 -0
  232. package/src/lib/vscodeBridge.ts +7 -0
  233. package/src/main.tsx +46 -0
  234. package/src/pages/AppearanceSettings.tsx +135 -0
  235. package/src/pages/Dependencies.tsx +926 -0
  236. package/src/pages/InfiniteZoom.tsx +404 -0
  237. package/src/pages/Settings.tsx +91 -0
  238. package/src/pages/ViewEditor/EDGE_DISTRIBUTION.md +64 -0
  239. package/src/pages/ViewEditor/components/EditorMenus.tsx +112 -0
  240. package/src/pages/ViewEditor/components/EditorOverlays.tsx +172 -0
  241. package/src/pages/ViewEditor/components/EmptyCanvasState.tsx +42 -0
  242. package/src/pages/ViewEditor/context.tsx +21 -0
  243. package/src/pages/ViewEditor/hooks/useCanvasInteractions.ts +1349 -0
  244. package/src/pages/ViewEditor/hooks/useDrawingEngine.ts +127 -0
  245. package/src/pages/ViewEditor/hooks/useViewContextNeighbours.ts +501 -0
  246. package/src/pages/ViewEditor/hooks/useViewData.ts +491 -0
  247. package/src/pages/ViewEditor/index.tsx +1366 -0
  248. package/src/pages/ViewEditor/utils.ts +88 -0
  249. package/src/pages/Views.tsx +171 -0
  250. package/src/pages/ViewsGrid.tsx +1310 -0
  251. package/src/pkg/importer/mermaid.test.ts +141 -0
  252. package/src/pkg/importer/mermaid.ts +76 -0
  253. package/src/platform/PlatformContext.tsx +17 -0
  254. package/src/platform/context.ts +9 -0
  255. package/src/platform/local.tsx +15 -0
  256. package/src/platform/types.ts +19 -0
  257. package/src/slots.ts +92 -0
  258. package/src/styles/editor-panels.css +66 -0
  259. package/src/styles/theme.css +56 -0
  260. package/src/theme.ts +336 -0
  261. package/src/types/index.ts +234 -0
  262. package/src/types/offline-ambient.d.ts +14 -0
  263. package/src/types/vscode-messages.ts +32 -0
  264. package/src/utils/edgeDistribution.ts +103 -0
  265. package/src/utils/githubApi.ts +121 -0
  266. package/src/utils/githubCache.ts +108 -0
  267. package/src/utils/ids.ts +9 -0
  268. package/src/utils/technologyCatalog.ts +143 -0
  269. package/src/utils/toast.ts +100 -0
  270. package/src/utils/treesitter.ts +147 -0
  271. package/src/utils/url.ts +72 -0
  272. package/src/vite-env.d.ts +1 -0
@@ -0,0 +1,270 @@
1
+ import React from 'react'
2
+ import { Box } from '@chakra-ui/react'
3
+ import { DRAWING_COLORS } from '../constants/colors'
4
+
5
+ export function UndoSvg() {
6
+ return (
7
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
8
+ <polyline points="1 4 1 10 7 10" />
9
+ <path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10" />
10
+ </svg>
11
+ )
12
+ }
13
+ export function RedoSvg() {
14
+ return (
15
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
16
+ <polyline points="23 4 23 10 17 10" />
17
+ <path d="M20.49 15a9 9 0 1 1-2.13-9.36L23 10" />
18
+ </svg>
19
+ )
20
+ }
21
+ export function PencilSvg() {
22
+ return (
23
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
24
+ <path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z" />
25
+ </svg>
26
+ )
27
+ }
28
+ export function EraserSvg() {
29
+ return (
30
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
31
+ <path d="M20 20H7L3 16C2 15 2 13 3 12L13 2L22 11L20 13L17 10L10 17L13 20" />
32
+ </svg>
33
+ )
34
+ }
35
+ export function TextSvg() {
36
+ return (
37
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
38
+ <polyline points="4 7 4 4 20 4 20 7" />
39
+ <line x1="9" y1="20" x2="15" y2="20" />
40
+ <line x1="12" y1="4" x2="12" y2="20" />
41
+ </svg>
42
+ )
43
+ }
44
+ export function MoveSvg() {
45
+ return (
46
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
47
+ <polyline points="5 9 2 12 5 15" />
48
+ <polyline points="9 5 12 2 15 5" />
49
+ <polyline points="15 19 12 22 9 19" />
50
+ <polyline points="19 9 22 12 19 15" />
51
+ <line x1="2" y1="12" x2="22" y2="12" />
52
+ <line x1="12" y1="2" x2="12" y2="22" />
53
+ </svg>
54
+ )
55
+ }
56
+ export function CloseSvg() {
57
+ return (
58
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
59
+ <line x1="18" y1="6" x2="6" y2="18" />
60
+ <line x1="6" y1="6" x2="18" y2="18" />
61
+ </svg>
62
+ )
63
+ }
64
+
65
+ function DrawingBtn({ active, disabled, onClick, title, children }: {
66
+ active?: boolean
67
+ disabled?: boolean
68
+ onClick?: () => void
69
+ title?: string
70
+ children: React.ReactNode
71
+ }) {
72
+ return (
73
+ <Box
74
+ as="button"
75
+ title={title}
76
+ onClick={disabled ? undefined : onClick}
77
+ w="34px"
78
+ h="34px"
79
+ display="flex"
80
+ alignItems="center"
81
+ justifyContent="center"
82
+ rounded="8px"
83
+ position="relative"
84
+ cursor={disabled ? 'default' : 'pointer'}
85
+ opacity={disabled ? 0.3 : 1}
86
+ outline="none"
87
+ border="none"
88
+ bg={active ? 'rgba(var(--accent-rgb, 99,179,237), 0.15)' : 'transparent'}
89
+ color={active ? 'var(--accent)' : 'rgba(255,255,255,0.6)'}
90
+ transition="all 0.1s"
91
+ _hover={disabled ? {} : {
92
+ bg: active ? 'rgba(var(--accent-rgb, 99,179,237), 0.22)' : 'rgba(255,255,255,0.07)',
93
+ color: 'white',
94
+ }}
95
+ flexShrink={0}
96
+ >
97
+ {children}
98
+ {active && (
99
+ <Box
100
+ position="absolute"
101
+ bottom="4px"
102
+ left="50%"
103
+ transform="translateX(-50%)"
104
+ w="4px"
105
+ h="4px"
106
+ rounded="full"
107
+ bg="var(--accent)"
108
+ />
109
+ )}
110
+ </Box>
111
+ )
112
+ }
113
+
114
+ function DrawingDivider() {
115
+ return <Box w="1px" h="20px" bg="rgba(255,255,255,0.08)" mx="4px" flexShrink={0} />
116
+ }
117
+
118
+ const DRAWING_WIDTHS = [1, 3, 6, 12]
119
+
120
+ export interface ViewDrawMenuProps {
121
+ drawingMode: boolean
122
+ drawingTool: 'pencil' | 'eraser' | 'text' | 'select'
123
+ setDrawingTool: (tool: 'pencil' | 'eraser' | 'text' | 'select') => void
124
+ drawingColor: string
125
+ setDrawingColor: (color: string) => void
126
+ drawingWidth: number
127
+ setDrawingWidth: (width: number) => void
128
+ onUndo: () => void
129
+ onRedo: () => void
130
+ canUndo: boolean
131
+ canRedo: boolean
132
+ setDrawingMode: (mode: boolean) => void
133
+ }
134
+
135
+ export default function ViewDrawMenu({
136
+ drawingMode,
137
+ drawingTool,
138
+ setDrawingTool,
139
+ drawingColor,
140
+ setDrawingColor,
141
+ drawingWidth,
142
+ setDrawingWidth,
143
+ onUndo,
144
+ onRedo,
145
+ canUndo,
146
+ canRedo,
147
+ setDrawingMode,
148
+ }: ViewDrawMenuProps) {
149
+ if (!drawingMode) return null
150
+
151
+ return (
152
+ <Box
153
+ position="absolute"
154
+ top="12px"
155
+ left="50%"
156
+ transform="translateX(-50%)"
157
+ zIndex={100}
158
+ display="flex"
159
+ alignItems="center"
160
+ gap="2px"
161
+ bg="var(--bg-panel)"
162
+ backdropFilter="blur(20px)"
163
+ border="1px solid rgba(255,255,255,0.1)"
164
+ borderRadius="16px"
165
+ boxShadow="0 8px 32px rgba(0,0,0,0.5)"
166
+ px="6px"
167
+ py="6px"
168
+ userSelect="none"
169
+ >
170
+ {/* Selection / Move */}
171
+ <DrawingBtn title="Select & Move (V)" active={drawingTool === 'select'} onClick={() => setDrawingTool('select')}>
172
+ <MoveSvg />
173
+ </DrawingBtn>
174
+
175
+ <DrawingDivider />
176
+
177
+ {/* Tools */}
178
+ <DrawingBtn title="Pen (P)" active={drawingTool === 'pencil'} onClick={() => setDrawingTool('pencil')}>
179
+ <PencilSvg />
180
+ </DrawingBtn>
181
+ <DrawingBtn title="Eraser (E)" active={drawingTool === 'eraser'} onClick={() => setDrawingTool('eraser')}>
182
+ <EraserSvg />
183
+ </DrawingBtn>
184
+ <DrawingBtn title="Text (T)" active={drawingTool === 'text'} onClick={() => setDrawingTool('text')}>
185
+ <TextSvg />
186
+ </DrawingBtn>
187
+
188
+ <DrawingDivider />
189
+
190
+ {/* Color swatches */}
191
+ <Box display="flex" gap="4px" px="4px">
192
+ {DRAWING_COLORS.map(c => (
193
+ <Box
194
+ key={c}
195
+ as="button"
196
+ title={c}
197
+ onClick={() => setDrawingColor(c)}
198
+ w="18px"
199
+ h="18px"
200
+ rounded="full"
201
+ bg={c}
202
+ cursor="pointer"
203
+ flexShrink={0}
204
+ outline="none"
205
+ border="none"
206
+ boxShadow={
207
+ drawingColor === c
208
+ ? `0 0 0 2px var(--bg-panel), 0 0 0 4px ${c}`
209
+ : '0 0 0 1px rgba(255,255,255,0.1)'
210
+ }
211
+ transition="all 0.15s cubic-bezier(0.4, 0, 0.2, 1)"
212
+ _hover={{
213
+ transform: 'scale(1.2)',
214
+ boxShadow: drawingColor === c
215
+ ? `0 0 0 2px var(--bg-panel), 0 0 0 4px ${c}`
216
+ : `0 0 0 2px var(--bg-panel), 0 0 0 3px ${c}`
217
+ }}
218
+ />
219
+ ))}
220
+ </Box>
221
+
222
+ <DrawingDivider />
223
+
224
+ {/* Stroke width presets (horizontal lines) */}
225
+ <Box display="flex" gap="2px" px="4px">
226
+ {DRAWING_WIDTHS.map(size => (
227
+ <Box
228
+ key={size}
229
+ as="button"
230
+ title={drawingTool === 'text' ? `Font size ${size * 5}px` : `Width ${size}px`}
231
+ onClick={() => setDrawingWidth(size)}
232
+ w="30px"
233
+ h="30px"
234
+ display="flex"
235
+ alignItems="center"
236
+ justifyContent="center"
237
+ rounded="8px"
238
+ bg={drawingWidth === size ? 'rgba(255,255,255,0.1)' : 'transparent'}
239
+ transition="all 0.15s"
240
+ _hover={{ bg: 'rgba(255,255,255,0.05)' }}
241
+ >
242
+ <Box
243
+ w="16px"
244
+ h={`${Math.max(1, size / 1.5)}px`}
245
+ rounded="full"
246
+ bg={drawingWidth === size ? 'white' : 'whiteAlpha.400'}
247
+ />
248
+ </Box>
249
+ ))}
250
+ </Box>
251
+
252
+ <DrawingDivider />
253
+
254
+ {/* Undo / Redo */}
255
+ <DrawingBtn title="Undo (Cmd+Z)" disabled={!canUndo} onClick={onUndo}>
256
+ <UndoSvg />
257
+ </DrawingBtn>
258
+ <DrawingBtn title="Redo (Cmd+Shift+Z)" disabled={!canRedo} onClick={onRedo}>
259
+ <RedoSvg />
260
+ </DrawingBtn>
261
+
262
+ <DrawingDivider />
263
+
264
+ {/* Exit */}
265
+ <DrawingBtn title="Done" onClick={() => setDrawingMode(false)}>
266
+ <CloseSvg />
267
+ </DrawingBtn>
268
+ </Box>
269
+ )
270
+ }
@@ -0,0 +1,189 @@
1
+ import { useLayoutEffect, useSyncExternalStore } from 'react'
2
+
3
+ interface LabelRect {
4
+ left: number
5
+ top: number
6
+ right: number
7
+ bottom: number
8
+ }
9
+
10
+ interface LabelEntry {
11
+ id: string
12
+ preferredX: number
13
+ preferredY: number
14
+ width: number
15
+ height: number
16
+ dx: number
17
+ dy: number
18
+ alongLineOnly?: boolean
19
+ position: { x: number; y: number }
20
+ }
21
+
22
+ const entries = new Map<string, LabelEntry>()
23
+ const fallbackPositions = new Map<string, { x: number; y: number }>()
24
+ const listeners = new Set<() => void>()
25
+ let measureCtx: CanvasRenderingContext2D | null = null
26
+
27
+ function getMeasureContext() {
28
+ if (measureCtx) return measureCtx
29
+ if (typeof document === 'undefined') return null
30
+ measureCtx = document.createElement('canvas').getContext('2d')
31
+ return measureCtx
32
+ }
33
+
34
+ export function measureEdgeLabel(text: string, font: string) {
35
+ const ctx = getMeasureContext()
36
+ if (!ctx) return Math.max(8, text.length * 7)
37
+ ctx.font = font
38
+ return ctx.measureText(text).width
39
+ }
40
+
41
+ function emit() {
42
+ listeners.forEach((listener) => listener())
43
+ }
44
+
45
+ function rectsOverlap(a: LabelRect, b: LabelRect) {
46
+ return a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top
47
+ }
48
+
49
+ function buildRect(centerX: number, centerY: number, width: number, height: number, gap = 6): LabelRect {
50
+ return {
51
+ left: centerX - width / 2 - gap,
52
+ top: centerY - height / 2 - gap / 2,
53
+ right: centerX + width / 2 + gap,
54
+ bottom: centerY + height / 2 + gap / 2,
55
+ }
56
+ }
57
+
58
+ function pickPosition(entry: LabelEntry, occupiedRects: LabelRect[]) {
59
+ const step = entry.height + 8
60
+ const length = Math.hypot(entry.dx, entry.dy) || 1
61
+ const tangentX = entry.dx / length
62
+ const tangentY = entry.dy / length
63
+ const normalX = -entry.dy / length
64
+ const normalY = entry.dx / length
65
+
66
+ const candidateOffsets = entry.alongLineOnly
67
+ ? [
68
+ { x: 0, y: 0 },
69
+ { x: tangentX * step, y: tangentY * step },
70
+ { x: -tangentX * step, y: -tangentY * step },
71
+ { x: tangentX * step * 2, y: tangentY * step * 2 },
72
+ { x: -tangentX * step * 2, y: -tangentY * step * 2 },
73
+ { x: tangentX * step * 3, y: tangentY * step * 3 },
74
+ { x: -tangentX * step * 3, y: -tangentY * step * 3 },
75
+ ]
76
+ : [
77
+ { x: 0, y: 0 },
78
+ { x: normalX * step, y: normalY * step },
79
+ { x: -normalX * step, y: -normalY * step },
80
+ { x: normalX * step * 2, y: normalY * step * 2 },
81
+ { x: -normalX * step * 2, y: -normalY * step * 2 },
82
+ { x: tangentX * step, y: tangentY * step },
83
+ { x: -tangentX * step, y: -tangentY * step },
84
+ ]
85
+
86
+ for (const offset of candidateOffsets) {
87
+ const x = entry.preferredX + offset.x
88
+ const y = entry.preferredY + offset.y
89
+ const rect = buildRect(x, y, entry.width, entry.height)
90
+ if (occupiedRects.some((existing) => rectsOverlap(rect, existing))) continue
91
+ occupiedRects.push(rect)
92
+ return { x, y }
93
+ }
94
+
95
+ occupiedRects.push(buildRect(entry.preferredX, entry.preferredY, entry.width, entry.height))
96
+ return { x: entry.preferredX, y: entry.preferredY }
97
+ }
98
+
99
+ function recomputeLayout() {
100
+ const occupiedRects: LabelRect[] = []
101
+ let changed = false
102
+ const sortedEntries = Array.from(entries.values()).sort((left, right) => left.id.localeCompare(right.id))
103
+
104
+ for (const entry of sortedEntries) {
105
+ const nextPosition = pickPosition(entry, occupiedRects)
106
+ if (entry.position.x !== nextPosition.x || entry.position.y !== nextPosition.y) {
107
+ entry.position = nextPosition
108
+ changed = true
109
+ }
110
+ }
111
+
112
+ if (changed) emit()
113
+ }
114
+
115
+ function upsertEntry(entry: Omit<LabelEntry, 'position'>) {
116
+ const existing = entries.get(entry.id)
117
+ entries.set(entry.id, {
118
+ ...entry,
119
+ position: existing?.position ?? { x: entry.preferredX, y: entry.preferredY },
120
+ })
121
+ recomputeLayout()
122
+ }
123
+
124
+ function removeEntry(id: string) {
125
+ if (!entries.delete(id)) return
126
+ fallbackPositions.delete(id)
127
+ recomputeLayout()
128
+ }
129
+
130
+ function subscribe(listener: () => void) {
131
+ listeners.add(listener)
132
+ return () => listeners.delete(listener)
133
+ }
134
+
135
+ function getPosition(id: string, fallbackX: number, fallbackY: number) {
136
+ const entry = entries.get(id)
137
+ if (entry) return entry.position
138
+ // Cache the fallback so useSyncExternalStore gets a stable reference and
139
+ // doesn't detect a spurious change on every call before the entry is added.
140
+ let cached = fallbackPositions.get(id)
141
+ if (!cached || cached.x !== fallbackX || cached.y !== fallbackY) {
142
+ cached = { x: fallbackX, y: fallbackY }
143
+ fallbackPositions.set(id, cached)
144
+ }
145
+ return cached
146
+ }
147
+
148
+ interface UseEdgeLabelLayoutArgs {
149
+ id: string
150
+ preferredX: number
151
+ preferredY: number
152
+ width: number
153
+ height: number
154
+ dx: number
155
+ dy: number
156
+ alongLineOnly?: boolean
157
+ }
158
+
159
+ export function useEdgeLabelLayout({
160
+ id,
161
+ preferredX,
162
+ preferredY,
163
+ width,
164
+ height,
165
+ dx,
166
+ dy,
167
+ alongLineOnly,
168
+ }: UseEdgeLabelLayoutArgs) {
169
+ useLayoutEffect(() => {
170
+ upsertEntry({
171
+ id,
172
+ preferredX,
173
+ preferredY,
174
+ width,
175
+ height,
176
+ dx,
177
+ dy,
178
+ alongLineOnly,
179
+ })
180
+
181
+ return () => removeEntry(id)
182
+ }, [id, preferredX, preferredY, width, height, dx, dy, alongLineOnly])
183
+
184
+ return useSyncExternalStore(
185
+ subscribe,
186
+ () => getPosition(id, preferredX, preferredY),
187
+ () => ({ x: preferredX, y: preferredY }),
188
+ )
189
+ }