@seanyeh77/ui 0.41.0 → 0.42.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 (361) hide show
  1. package/README.md +32 -0
  2. package/dist/announce.d.ts +3 -0
  3. package/dist/announce.js +35 -0
  4. package/dist/announce.js.map +1 -0
  5. package/dist/bundle.js +1 -1
  6. package/dist/bundle.js.map +1 -1
  7. package/dist/components/AccentPicker/AccentPicker.d.ts +12 -0
  8. package/dist/components/AccentPicker/AccentPicker.js +96 -0
  9. package/dist/components/AccentPicker/AccentPicker.js.map +1 -0
  10. package/dist/components/ActionBar/ActionBar.d.ts +27 -0
  11. package/dist/components/ActionBar/ActionBar.js +62 -0
  12. package/dist/components/ActionBar/ActionBar.js.map +1 -0
  13. package/dist/components/AiMark/AiMark.d.ts +10 -0
  14. package/dist/components/AiMark/AiMark.js +21 -0
  15. package/dist/components/AiMark/AiMark.js.map +1 -0
  16. package/dist/components/Alert/Alert.d.ts +17 -0
  17. package/dist/components/Alert/Alert.js +56 -0
  18. package/dist/components/Alert/Alert.js.map +1 -0
  19. package/dist/components/AppShell/AppShell.d.ts +36 -0
  20. package/dist/components/AppShell/AppShell.js +195 -0
  21. package/dist/components/AppShell/AppShell.js.map +1 -0
  22. package/dist/components/Badge/Badge.d.ts +12 -0
  23. package/dist/components/Badge/Badge.js +58 -0
  24. package/dist/components/Badge/Badge.js.map +1 -0
  25. package/dist/components/BarChart/BarChart.d.ts +19 -0
  26. package/dist/components/BarChart/BarChart.js +78 -0
  27. package/dist/components/BarChart/BarChart.js.map +1 -0
  28. package/dist/components/Breadcrumb/Breadcrumb.d.ts +11 -0
  29. package/dist/components/Breadcrumb/Breadcrumb.js +29 -0
  30. package/dist/components/Breadcrumb/Breadcrumb.js.map +1 -0
  31. package/dist/components/Button/Button.d.ts +39 -0
  32. package/dist/components/Button/Button.js +54 -0
  33. package/dist/components/Button/Button.js.map +1 -0
  34. package/dist/components/Calendar/Calendar.d.ts +18 -0
  35. package/dist/components/Calendar/Calendar.js +125 -0
  36. package/dist/components/Calendar/Calendar.js.map +1 -0
  37. package/dist/components/Card/Card.d.ts +14 -0
  38. package/dist/components/Card/Card.js +33 -0
  39. package/dist/components/Card/Card.js.map +1 -0
  40. package/dist/components/Checkbox/Checkbox.d.ts +14 -0
  41. package/dist/components/Checkbox/Checkbox.js +27 -0
  42. package/dist/components/Checkbox/Checkbox.js.map +1 -0
  43. package/dist/components/CodeView/CodeView.d.ts +111 -0
  44. package/dist/components/CodeView/CodeView.js +790 -0
  45. package/dist/components/CodeView/CodeView.js.map +1 -0
  46. package/dist/components/CodeView/tokens.d.ts +5 -0
  47. package/dist/components/CodeView/tokens.js +70 -0
  48. package/dist/components/CodeView/tokens.js.map +1 -0
  49. package/dist/components/CommandPalette/CommandPalette.d.ts +52 -0
  50. package/dist/components/CommandPalette/CommandPalette.js +242 -0
  51. package/dist/components/CommandPalette/CommandPalette.js.map +1 -0
  52. package/dist/components/ConsoleLayout/ConsoleLayout.d.ts +44 -0
  53. package/dist/components/ConsoleLayout/ConsoleLayout.js +119 -0
  54. package/dist/components/ConsoleLayout/ConsoleLayout.js.map +1 -0
  55. package/dist/components/DangerZone/DangerZone.d.ts +16 -0
  56. package/dist/components/DangerZone/DangerZone.js +28 -0
  57. package/dist/components/DangerZone/DangerZone.js.map +1 -0
  58. package/dist/components/DataTable/DataTable.d.ts +99 -0
  59. package/dist/components/DataTable/DataTable.js +1267 -0
  60. package/dist/components/DataTable/DataTable.js.map +1 -0
  61. package/dist/components/DataTable/SortButton.js +222 -0
  62. package/dist/components/DataTable/SortButton.js.map +1 -0
  63. package/dist/components/DataTable/filters.js +147 -0
  64. package/dist/components/DataTable/filters.js.map +1 -0
  65. package/dist/components/DataTable/parts.js +373 -0
  66. package/dist/components/DataTable/parts.js.map +1 -0
  67. package/dist/components/DataTable/types.d.ts +85 -0
  68. package/dist/components/DatePicker/DatePicker.d.ts +15 -0
  69. package/dist/components/DatePicker/DatePicker.js +104 -0
  70. package/dist/components/DatePicker/DatePicker.js.map +1 -0
  71. package/dist/components/DateRangePicker/DateRangePicker.d.ts +11 -0
  72. package/dist/components/DateRangePicker/DateRangePicker.js +88 -0
  73. package/dist/components/DateRangePicker/DateRangePicker.js.map +1 -0
  74. package/dist/components/DetailList/DetailList.d.ts +17 -0
  75. package/dist/components/DetailList/DetailList.js +18 -0
  76. package/dist/components/DetailList/DetailList.js.map +1 -0
  77. package/dist/components/Dialog/Dialog.d.ts +30 -0
  78. package/dist/components/Dialog/Dialog.js +87 -0
  79. package/dist/components/Dialog/Dialog.js.map +1 -0
  80. package/dist/components/Drawer/Drawer.d.ts +20 -0
  81. package/dist/components/Drawer/Drawer.js +64 -0
  82. package/dist/components/Drawer/Drawer.js.map +1 -0
  83. package/dist/components/EmptyState/EmptyState.d.ts +15 -0
  84. package/dist/components/EmptyState/EmptyState.js +34 -0
  85. package/dist/components/EmptyState/EmptyState.js.map +1 -0
  86. package/dist/components/ErrorPage/ErrorPage.d.ts +14 -0
  87. package/dist/components/ErrorPage/ErrorPage.js +47 -0
  88. package/dist/components/ErrorPage/ErrorPage.js.map +1 -0
  89. package/dist/components/EventTimeline/EventTimeline.d.ts +19 -0
  90. package/dist/components/EventTimeline/EventTimeline.js +63 -0
  91. package/dist/components/EventTimeline/EventTimeline.js.map +1 -0
  92. package/dist/components/FileUpload/FileUpload.d.ts +27 -0
  93. package/dist/components/FileUpload/FileUpload.js +121 -0
  94. package/dist/components/FileUpload/FileUpload.js.map +1 -0
  95. package/dist/components/FormGrid/FormGrid.d.ts +7 -0
  96. package/dist/components/FormGrid/FormGrid.js +14 -0
  97. package/dist/components/FormGrid/FormGrid.js.map +1 -0
  98. package/dist/components/Graph/Graph.d.ts +18 -0
  99. package/dist/components/Graph/Graph.js +97 -0
  100. package/dist/components/Graph/Graph.js.map +1 -0
  101. package/dist/components/Grid/Grid.d.ts +16 -0
  102. package/dist/components/Grid/Grid.js +21 -0
  103. package/dist/components/Grid/Grid.js.map +1 -0
  104. package/dist/components/IconButton/IconButton.d.ts +32 -0
  105. package/dist/components/IconButton/IconButton.js +104 -0
  106. package/dist/components/IconButton/IconButton.js.map +1 -0
  107. package/dist/components/InlineCode/InlineCode.d.ts +46 -0
  108. package/dist/components/InlineCode/InlineCode.js +71 -0
  109. package/dist/components/InlineCode/InlineCode.js.map +1 -0
  110. package/dist/components/KpiCard/KpiCard.d.ts +38 -0
  111. package/dist/components/KpiCard/KpiCard.js +116 -0
  112. package/dist/components/KpiCard/KpiCard.js.map +1 -0
  113. package/dist/components/LayerGraph/LayerGraph.d.ts +117 -0
  114. package/dist/components/LayerGraph/LayerGraph.js +1644 -0
  115. package/dist/components/LayerGraph/LayerGraph.js.map +1 -0
  116. package/dist/components/LineChart/LineChart.d.ts +73 -0
  117. package/dist/components/LineChart/LineChart.js +337 -0
  118. package/dist/components/LineChart/LineChart.js.map +1 -0
  119. package/dist/components/LoadingBar/LoadingBar.d.ts +7 -0
  120. package/dist/components/LoadingBar/LoadingBar.js +18 -0
  121. package/dist/components/LoadingBar/LoadingBar.js.map +1 -0
  122. package/dist/components/LoginCard/LoginCard.d.ts +23 -0
  123. package/dist/components/LoginCard/LoginCard.js +113 -0
  124. package/dist/components/LoginCard/LoginCard.js.map +1 -0
  125. package/dist/components/Markdown/Markdown.d.ts +38 -0
  126. package/dist/components/Markdown/Markdown.js +716 -0
  127. package/dist/components/Markdown/Markdown.js.map +1 -0
  128. package/dist/components/Menu/Menu.d.ts +33 -0
  129. package/dist/components/Menu/Menu.js +75 -0
  130. package/dist/components/Menu/Menu.js.map +1 -0
  131. package/dist/components/Meter/Meter.d.ts +20 -0
  132. package/dist/components/Meter/Meter.js +120 -0
  133. package/dist/components/Meter/Meter.js.map +1 -0
  134. package/dist/components/MobileTabBar/MobileTabBar.d.ts +21 -0
  135. package/dist/components/MobileTabBar/MobileTabBar.js +47 -0
  136. package/dist/components/MobileTabBar/MobileTabBar.js.map +1 -0
  137. package/dist/components/MultiSelect/MultiSelect.d.ts +25 -0
  138. package/dist/components/MultiSelect/MultiSelect.js +116 -0
  139. package/dist/components/MultiSelect/MultiSelect.js.map +1 -0
  140. package/dist/components/NotificationBell/NotificationBell.d.ts +20 -0
  141. package/dist/components/NotificationBell/NotificationBell.js +92 -0
  142. package/dist/components/NotificationBell/NotificationBell.js.map +1 -0
  143. package/dist/components/Popover/Popover.d.ts +20 -0
  144. package/dist/components/Popover/Popover.js +48 -0
  145. package/dist/components/Popover/Popover.js.map +1 -0
  146. package/dist/components/ProgressBar/ProgressBar.d.ts +10 -0
  147. package/dist/components/ProgressBar/ProgressBar.js +38 -0
  148. package/dist/components/ProgressBar/ProgressBar.js.map +1 -0
  149. package/dist/components/ProgressRing/ProgressRing.d.ts +11 -0
  150. package/dist/components/ProgressRing/ProgressRing.js +53 -0
  151. package/dist/components/ProgressRing/ProgressRing.js.map +1 -0
  152. package/dist/components/ProjectSwitcher/ProjectSwitcher.d.ts +25 -0
  153. package/dist/components/ProjectSwitcher/ProjectSwitcher.js +97 -0
  154. package/dist/components/ProjectSwitcher/ProjectSwitcher.js.map +1 -0
  155. package/dist/components/RadioGroup/RadioGroup.d.ts +18 -0
  156. package/dist/components/RadioGroup/RadioGroup.js +63 -0
  157. package/dist/components/RadioGroup/RadioGroup.js.map +1 -0
  158. package/dist/components/SearchField/SearchField.d.ts +9 -0
  159. package/dist/components/SearchField/SearchField.js +46 -0
  160. package/dist/components/SearchField/SearchField.js.map +1 -0
  161. package/dist/components/Section/Section.d.ts +50 -0
  162. package/dist/components/Section/Section.js +220 -0
  163. package/dist/components/Section/Section.js.map +1 -0
  164. package/dist/components/SegmentedControl/SegmentedControl.d.ts +23 -0
  165. package/dist/components/SegmentedControl/SegmentedControl.js +86 -0
  166. package/dist/components/SegmentedControl/SegmentedControl.js.map +1 -0
  167. package/dist/components/Select/Select.d.ts +31 -0
  168. package/dist/components/Select/Select.js +138 -0
  169. package/dist/components/Select/Select.js.map +1 -0
  170. package/dist/components/SettingsLayout/SettingsLayout.d.ts +27 -0
  171. package/dist/components/SettingsLayout/SettingsLayout.js +69 -0
  172. package/dist/components/SettingsLayout/SettingsLayout.js.map +1 -0
  173. package/dist/components/SideNav/SideNav.d.ts +48 -0
  174. package/dist/components/SideNav/SideNav.js +220 -0
  175. package/dist/components/SideNav/SideNav.js.map +1 -0
  176. package/dist/components/Skeleton/Skeleton.d.ts +8 -0
  177. package/dist/components/Skeleton/Skeleton.js +17 -0
  178. package/dist/components/Skeleton/Skeleton.js.map +1 -0
  179. package/dist/components/SplitPane/SplitPane.d.ts +23 -0
  180. package/dist/components/SplitPane/SplitPane.js +140 -0
  181. package/dist/components/SplitPane/SplitPane.js.map +1 -0
  182. package/dist/components/StatusBand/StatusBand.d.ts +31 -0
  183. package/dist/components/StatusBand/StatusBand.js +43 -0
  184. package/dist/components/StatusBand/StatusBand.js.map +1 -0
  185. package/dist/components/Suggestion/Suggestion.d.ts +22 -0
  186. package/dist/components/Suggestion/Suggestion.js +72 -0
  187. package/dist/components/Suggestion/Suggestion.js.map +1 -0
  188. package/dist/components/Switch/Switch.d.ts +11 -0
  189. package/dist/components/Switch/Switch.js +56 -0
  190. package/dist/components/Switch/Switch.js.map +1 -0
  191. package/dist/components/Tabs/Tabs.d.ts +23 -0
  192. package/dist/components/Tabs/Tabs.js +117 -0
  193. package/dist/components/Tabs/Tabs.js.map +1 -0
  194. package/dist/components/Tag/Tag.d.ts +13 -0
  195. package/dist/components/Tag/Tag.js +22 -0
  196. package/dist/components/Tag/Tag.js.map +1 -0
  197. package/dist/components/Term/Term.d.ts +34 -0
  198. package/dist/components/Term/Term.js +138 -0
  199. package/dist/components/Term/Term.js.map +1 -0
  200. package/dist/components/TextArea/TextArea.d.ts +15 -0
  201. package/dist/components/TextArea/TextArea.js +75 -0
  202. package/dist/components/TextArea/TextArea.js.map +1 -0
  203. package/dist/components/TextField/TextField.d.ts +15 -0
  204. package/dist/components/TextField/TextField.js +43 -0
  205. package/dist/components/TextField/TextField.js.map +1 -0
  206. package/dist/components/ThemePicker/ThemePicker.d.ts +13 -0
  207. package/dist/components/ThemePicker/ThemePicker.js +66 -0
  208. package/dist/components/ThemePicker/ThemePicker.js.map +1 -0
  209. package/dist/components/TimeControl/TimeControl.d.ts +19 -0
  210. package/dist/components/TimeControl/TimeControl.js +47 -0
  211. package/dist/components/TimeControl/TimeControl.js.map +1 -0
  212. package/dist/components/Toast/Toast.d.ts +10 -0
  213. package/dist/components/Toast/Toast.js +27 -0
  214. package/dist/components/Toast/Toast.js.map +1 -0
  215. package/dist/components/Tooltip/Tooltip.d.ts +17 -0
  216. package/dist/components/Tooltip/Tooltip.js +69 -0
  217. package/dist/components/Tooltip/Tooltip.js.map +1 -0
  218. package/dist/components/TopBar/TopBar.d.ts +18 -0
  219. package/dist/components/TopBar/TopBar.js +55 -0
  220. package/dist/components/TopBar/TopBar.js.map +1 -0
  221. package/dist/components/Tour/Tour.d.ts +44 -0
  222. package/dist/components/Tour/Tour.js +440 -0
  223. package/dist/components/Tour/Tour.js.map +1 -0
  224. package/dist/components/TreeList/TreeList.d.ts +90 -0
  225. package/dist/components/TreeList/TreeList.js +588 -0
  226. package/dist/components/TreeList/TreeList.js.map +1 -0
  227. package/dist/components/TreeList/helpers.d.ts +2 -0
  228. package/dist/components/TreeList/helpers.js +104 -0
  229. package/dist/components/TreeList/helpers.js.map +1 -0
  230. package/dist/components/Workbench/Workbench.d.ts +100 -0
  231. package/dist/components/Workbench/Workbench.js +1137 -0
  232. package/dist/components/Workbench/Workbench.js.map +1 -0
  233. package/dist/components/ZoneMap/ZoneMap.d.ts +49 -0
  234. package/dist/components/ZoneMap/ZoneMap.js +89 -0
  235. package/dist/components/ZoneMap/ZoneMap.js.map +1 -0
  236. package/dist/css/AccentPicker.css +49 -0
  237. package/dist/css/ActionBar.css +36 -0
  238. package/dist/css/AiMark.css +14 -0
  239. package/dist/css/Alert.css +80 -0
  240. package/dist/css/AppShell.css +81 -0
  241. package/dist/css/Badge.css +68 -0
  242. package/dist/css/BarChart.css +66 -0
  243. package/dist/css/Breadcrumb.css +33 -0
  244. package/dist/css/Button.css +190 -0
  245. package/dist/css/Calendar.css +96 -0
  246. package/dist/css/Card.css +70 -0
  247. package/dist/css/Checkbox.css +38 -0
  248. package/dist/css/CodeView.css +302 -0
  249. package/dist/css/CommandPalette.css +232 -0
  250. package/dist/css/ConsoleLayout.css +131 -0
  251. package/dist/css/DangerZone.css +32 -0
  252. package/dist/css/DataTable.css +1195 -0
  253. package/dist/css/DatePicker.css +38 -0
  254. package/dist/css/DateRangePicker.css +70 -0
  255. package/dist/css/DetailList.css +69 -0
  256. package/dist/css/Dialog.css +3 -0
  257. package/dist/css/Drawer.css +90 -0
  258. package/dist/css/EmptyState.css +61 -0
  259. package/dist/css/ErrorPage.css +40 -0
  260. package/dist/css/EventTimeline.css +43 -0
  261. package/dist/css/FileUpload.css +92 -0
  262. package/dist/css/FormGrid.css +17 -0
  263. package/dist/css/Graph.css +99 -0
  264. package/dist/css/Grid.css +48 -0
  265. package/dist/css/IconButton.css +149 -0
  266. package/dist/css/InlineCode.css +92 -0
  267. package/dist/css/KpiCard.css +121 -0
  268. package/dist/css/LayerGraph.css +575 -0
  269. package/dist/css/LineChart.css +3 -0
  270. package/dist/css/LoadingBar.css +45 -0
  271. package/dist/css/LoginCard.css +65 -0
  272. package/dist/css/Markdown.css +266 -0
  273. package/dist/css/Menu.css +88 -0
  274. package/dist/css/Meter.css +110 -0
  275. package/dist/css/MobileTabBar.css +63 -0
  276. package/dist/css/MultiSelect.css +78 -0
  277. package/dist/css/NotificationBell.css +129 -0
  278. package/dist/css/Popover.css +57 -0
  279. package/dist/css/ProgressBar.css +42 -0
  280. package/dist/css/ProgressRing.css +19 -0
  281. package/dist/css/ProjectSwitcher.css +153 -0
  282. package/dist/css/RadioGroup.css +52 -0
  283. package/dist/css/SearchField.css +79 -0
  284. package/dist/css/Section.css +115 -0
  285. package/dist/css/SegmentedControl.css +67 -0
  286. package/dist/css/Select.css +136 -0
  287. package/dist/css/SettingsLayout.css +110 -0
  288. package/dist/css/SideNav.css +281 -0
  289. package/dist/css/Skeleton.css +19 -0
  290. package/dist/css/SplitPane.css +108 -0
  291. package/dist/css/StatusBand.css +23 -0
  292. package/dist/css/Suggestion.css +82 -0
  293. package/dist/css/Switch.css +46 -0
  294. package/dist/css/Tabs.css +91 -0
  295. package/dist/css/Tag.css +36 -0
  296. package/dist/css/Term.css +160 -0
  297. package/dist/css/TextArea.css +22 -0
  298. package/dist/css/TextField.css +2 -0
  299. package/dist/css/ThemePicker.css +70 -0
  300. package/dist/css/TimeControl.css +33 -0
  301. package/dist/css/Toast.css +47 -0
  302. package/dist/css/Tooltip.css +58 -0
  303. package/dist/css/TopBar.css +86 -0
  304. package/dist/css/Tour.css +90 -0
  305. package/dist/css/TreeList.css +532 -0
  306. package/dist/css/Workbench.css +652 -0
  307. package/dist/css/ZoneMap.css +203 -0
  308. package/dist/css/base.css +556 -0
  309. package/dist/css/end.css +273 -0
  310. package/dist/format-entry.d.ts +3 -0
  311. package/dist/format-entry.js +3 -0
  312. package/dist/format.d.ts +68 -2
  313. package/dist/format.js +237 -1
  314. package/dist/format.js.map +1 -0
  315. package/dist/i18n.d.ts +11 -0
  316. package/dist/{format-entry-CyChe8bk.js → i18n.js} +2 -235
  317. package/dist/i18n.js.map +1 -0
  318. package/dist/icons/Icon.d.ts +23 -0
  319. package/dist/icons/Icon.js +90 -0
  320. package/dist/icons/Icon.js.map +1 -0
  321. package/dist/icons/data.d.ts +150 -0
  322. package/dist/icons/data.js +256 -0
  323. package/dist/icons/data.js.map +1 -0
  324. package/dist/index.d.ts +84 -2293
  325. package/dist/index.js +79 -13348
  326. package/dist/internal/Field.js +71 -0
  327. package/dist/internal/Field.js.map +1 -0
  328. package/dist/internal/FloatingPanel.js +41 -0
  329. package/dist/internal/FloatingPanel.js.map +1 -0
  330. package/dist/internal/chart.js +131 -0
  331. package/dist/internal/chart.js.map +1 -0
  332. package/dist/internal/dev.js +21 -0
  333. package/dist/internal/dev.js.map +1 -0
  334. package/dist/internal/focus.js +94 -0
  335. package/dist/internal/focus.js.map +1 -0
  336. package/dist/internal/focusMain.d.ts +4 -0
  337. package/dist/internal/focusMain.js +22 -0
  338. package/dist/internal/focusMain.js.map +1 -0
  339. package/dist/internal/scrollHint.js +75 -0
  340. package/dist/internal/scrollHint.js.map +1 -0
  341. package/dist/internal/tableTools.js +109 -0
  342. package/dist/internal/tableTools.js.map +1 -0
  343. package/dist/internal/terms.d.ts +18 -0
  344. package/dist/internal/terms.js +64 -0
  345. package/dist/internal/terms.js.map +1 -0
  346. package/dist/internal/util.js +107 -0
  347. package/dist/internal/util.js.map +1 -0
  348. package/dist/motion.d.ts +5 -0
  349. package/dist/motion.js +29 -0
  350. package/dist/motion.js.map +1 -0
  351. package/dist/styles.css +4280 -4265
  352. package/dist/theme.d.ts +20 -0
  353. package/dist/theme.js +210 -0
  354. package/dist/theme.js.map +1 -0
  355. package/dist/tokens.css +4 -0
  356. package/docs/guidelines.md +1 -0
  357. package/docs/theme.md +49 -0
  358. package/package.json +5 -4
  359. package/dist/format-entry-CgMBtkni.d.ts +0 -79
  360. package/dist/format-entry-CyChe8bk.js.map +0 -1
  361. package/dist/index.js.map +0 -1
@@ -0,0 +1,1644 @@
1
+ "use client";
2
+ import { GraphLegend } from "../Graph/Graph.js";
3
+ import { Tabs } from "../Tabs/Tabs.js";
4
+ import { IconButton } from "../IconButton/IconButton.js";
5
+ import { Switch } from "../Switch/Switch.js";
6
+ import { tr } from "../../i18n.js";
7
+ import { format } from "../../format.js";
8
+ import { cx, monoNums } from "../../internal/util.js";
9
+ import { ScrollHint, useScrollHint } from "../../internal/scrollHint.js";
10
+ import { devWarn } from "../../internal/dev.js";
11
+ import { Icon } from "../../icons/Icon.js";
12
+ import * as React from "react";
13
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
14
+ // src/components/LayerGraph/LayerGraph.tsx
15
+ const scrollMemory = /* @__PURE__ */ new Map();
16
+ let measure;
17
+ const SPLIT = /(`[^`]+`|\d[\d,.]*)/;
18
+ /** A label with a number: {n} in a string, or a function of the number; the number comes back as \u0001 (monoNums). */
19
+ function withNum(label, n, fallback) {
20
+ if (typeof label === "function") {
21
+ const t = label(n);
22
+ for (const s of [format.number(n), String(n)]) if (t.includes(s)) return t.replace(s, "");
23
+ return t;
24
+ }
25
+ return (label ?? fallback(n)).replace("{n}", "");
26
+ }
27
+ /** The default for one (「1 call」) where the language has its own word for it, else the {n} form. */
28
+ function byCount(n, one, many) {
29
+ const t = n === 1 ? tr(one) : "";
30
+ return t && t !== one ? t : tr(many);
31
+ }
32
+ /** A box reached with the keyboard while partly scrolled out of the diagram's frame (phones): scroll it fully into view,
33
+ * with its focus outline (scroll-margin in styles.css). The browser scrolls only boxes that are wholly out of view. */
34
+ function showWhole(e) {
35
+ if (e.currentTarget.matches(":focus-visible")) e.currentTarget.scrollIntoView({
36
+ block: "nearest",
37
+ inline: "nearest"
38
+ });
39
+ }
40
+ /** The width of text in a font (`600 13px` and mono or sans), measured on a canvas. */
41
+ function textWidth(text, size, code) {
42
+ if (measure === void 0) measure = document.createElement("canvas").getContext("2d");
43
+ const c = measure;
44
+ if (!c) return text.length * size * .6;
45
+ const cs = getComputedStyle(document.documentElement);
46
+ c.font = `600 ${size}px ` + ((code ? cs.getPropertyValue("--font-mono") : cs.getPropertyValue("--font-sans")) || "sans-serif");
47
+ return c.measureText(text).width;
48
+ }
49
+ const TAG_KEEP = 8;
50
+ const MIN_FRAME = 160;
51
+ const MAX_EXTRA = 200;
52
+ /** HC: the bar under the diagram: drag it, ↑↓ 16 px, Enter or a double-click back to the drawn height. */
53
+ function HeightHandle(p) {
54
+ const [dragging, setDragging] = React.useState(false);
55
+ const from = React.useRef(null);
56
+ return /* @__PURE__ */ jsx("div", {
57
+ className: cx("ui-lg-resize", dragging && "is-dragging"),
58
+ role: "separator",
59
+ "aria-orientation": "horizontal",
60
+ "aria-label": tr("調整架構圖高度"),
61
+ "aria-valuenow": p.value,
62
+ "aria-valuemin": p.min,
63
+ "aria-valuemax": p.max,
64
+ "aria-valuetext": tr("{n} px", { n: p.value }),
65
+ tabIndex: 0,
66
+ onPointerDown: (e) => {
67
+ if (e.button !== 0) return;
68
+ e.preventDefault();
69
+ e.currentTarget.setPointerCapture(e.pointerId);
70
+ from.current = {
71
+ y: e.clientY,
72
+ d: p.start()
73
+ };
74
+ setDragging(true);
75
+ },
76
+ onPointerMove: (e) => {
77
+ if (!from.current) return;
78
+ p.onDrag(from.current.d + e.clientY - from.current.y);
79
+ },
80
+ onPointerUp: () => {
81
+ from.current = null;
82
+ setDragging(false);
83
+ },
84
+ onPointerCancel: () => {
85
+ from.current = null;
86
+ setDragging(false);
87
+ },
88
+ onDoubleClick: p.onReset,
89
+ onKeyDown: (e) => {
90
+ if (e.altKey || e.metaKey || e.ctrlKey) return;
91
+ if (e.key === "ArrowUp" || e.key === "ArrowDown") {
92
+ e.preventDefault();
93
+ p.onKey(e.key === "ArrowUp" ? -16 : 16);
94
+ } else if (e.key === "Enter") {
95
+ e.preventDefault();
96
+ p.onReset();
97
+ }
98
+ },
99
+ children: /* @__PURE__ */ jsxs("span", {
100
+ className: "ui-lg-resize-grip",
101
+ "aria-hidden": "true",
102
+ children: [
103
+ /* @__PURE__ */ jsx("i", {}),
104
+ /* @__PURE__ */ jsx("i", {}),
105
+ /* @__PURE__ */ jsx("i", {})
106
+ ]
107
+ })
108
+ });
109
+ }
110
+ function labelWidth(text) {
111
+ const parts = text.split(SPLIT).filter(Boolean);
112
+ if (measure === void 0) measure = document.createElement("canvas").getContext("2d");
113
+ const c = measure;
114
+ if (!c) return text.length * 9;
115
+ const cs = getComputedStyle(document.documentElement);
116
+ const sans = cs.getPropertyValue("--font-sans") || "sans-serif";
117
+ const mono = cs.getPropertyValue("--font-mono") || "monospace";
118
+ return parts.reduce((w, t) => {
119
+ const code = t[0] === "`" || /^\d/.test(t);
120
+ c.font = "600 12px " + (code ? mono : sans);
121
+ return w + c.measureText(t[0] === "`" ? t.slice(1, -1) : t).width;
122
+ }, 0);
123
+ }
124
+ const LABELS_KEY = "ui-lg-labels:";
125
+ const allIds = (nodes) => nodes.map((n) => n.id).join("|");
126
+ const GROW = 24;
127
+ const GROW_MAX = 144;
128
+ /** The label on 1 line, then wrapped onto 2, 3 and 4 lines as evenly as it goes. Breaks between Chinese characters
129
+ * and at spaces; never inside `code`, a word or a number, between a number and the word after it, before a closing
130
+ * mark or after an opening one. */
131
+ function wraps(text) {
132
+ const atoms = [];
133
+ for (const t of text.match(/`[^`]+`|[A-Za-z0-9_./:#@-]+|\s+|[\s\S]/gu) ?? []) {
134
+ const prev = atoms[atoms.length - 1];
135
+ const unit = /\d\s*$/.test(prev ?? "") && !/^[A-Za-z0-9_]/.test(t);
136
+ if (prev != null && (unit || /^[)」』、,。:;!?)\],;!?]/.test(t) || /[(「『([]$/.test(prev))) atoms[atoms.length - 1] = prev + t;
137
+ else atoms.push(t);
138
+ }
139
+ const fill = (max) => {
140
+ const lines = [];
141
+ let cur = "";
142
+ for (const a of atoms) {
143
+ if (/^\s+$/.test(a)) {
144
+ if (cur) cur += a;
145
+ continue;
146
+ }
147
+ if (cur && labelWidth(cur.trimEnd() + a) > max) {
148
+ lines.push(cur.trimEnd());
149
+ cur = a;
150
+ } else cur += a;
151
+ }
152
+ if (cur.trim()) lines.push(cur.trimEnd());
153
+ return lines;
154
+ };
155
+ const full = labelWidth(text);
156
+ const out = [[text]];
157
+ for (let n = 2; n <= 4; n++) {
158
+ let lo = Math.max(...atoms.filter((a) => a.trim()).map(labelWidth)) - 1;
159
+ let hi = full;
160
+ while (hi - lo > 1) {
161
+ const mid = (lo + hi) / 2;
162
+ if (fill(mid).length <= n) hi = mid;
163
+ else lo = mid;
164
+ }
165
+ const lines = fill(hi);
166
+ if (lines.length > out[out.length - 1].length) out.push(lines);
167
+ }
168
+ return out;
169
+ }
170
+ function labelParts(text) {
171
+ return text.split(SPLIT).filter(Boolean).map((t, i) => t[0] === "`" || /^\d/.test(t) ? /* @__PURE__ */ jsx("span", {
172
+ className: "ui-lg-code",
173
+ children: t[0] === "`" ? t.slice(1, -1) : t
174
+ }, i) : t);
175
+ }
176
+ /** Rounded orthogonal path through the points. */
177
+ function route(pts, R) {
178
+ let d = `M${pts[0][0]} ${pts[0][1]}`;
179
+ for (let i = 1; i < pts.length - 1; i++) {
180
+ const [a, b, c] = [
181
+ pts[i - 1],
182
+ pts[i],
183
+ pts[i + 1]
184
+ ];
185
+ const r = Math.min(R, Math.abs(b[0] - a[0] + b[1] - a[1]) / 2, Math.abs(c[0] - b[0] + c[1] - b[1]) / 2);
186
+ const ux = Math.sign(b[0] - a[0]);
187
+ const uy = Math.sign(b[1] - a[1]);
188
+ const vx = Math.sign(c[0] - b[0]);
189
+ const vy = Math.sign(c[1] - b[1]);
190
+ d += ` L${b[0] - ux * r} ${b[1] - uy * r} Q${b[0]} ${b[1]} ${b[0] + vx * r} ${b[1] + vy * r}`;
191
+ }
192
+ const z = pts[pts.length - 1];
193
+ return `${d} L${z[0]} ${z[1]}`;
194
+ }
195
+ /** Drops repeated points and points in the middle of a straight run. */
196
+ const clean = (pts) => pts.filter((q, i) => {
197
+ const o = pts[i - 1];
198
+ return !o || o[0] !== q[0] || o[1] !== q[1];
199
+ }).filter((q, i, arr) => {
200
+ const a = arr[i - 1];
201
+ const c = arr[i + 1];
202
+ return !a || !c || !(a[0] === q[0] && q[0] === c[0] || a[1] === q[1] && q[1] === c[1]);
203
+ });
204
+ /** Architecture as layers of boxes with arrows. Line width shows how often; inferred relations are dashed and labelled;
205
+ * shared items are listed under the diagram instead of drawn. Wider than its box: the boxes narrow (down to 120 px),
206
+ * then the whole diagram scales down (to 0.75 at least); past that it scrolls sideways at full width (PM, WA). */
207
+ function LayerGraph(p) {
208
+ const [avail, setAvail] = React.useState(0);
209
+ const [fit, setFit] = React.useState(null);
210
+ const fitted = fit && fit.at === avail ? fit : null;
211
+ const NW = fitted?.nw ?? (p.nodeWidth || 200);
212
+ const GAP = 56;
213
+ const [dh, setDhState] = React.useState(() => {
214
+ if (!p.resizable || !p.heightKey) return 0;
215
+ try {
216
+ const v = Number(localStorage.getItem("ui-lg-height:" + p.heightKey));
217
+ return Number.isFinite(v) ? v : 0;
218
+ } catch {
219
+ return 0;
220
+ }
221
+ });
222
+ const setDh = React.useCallback((v) => {
223
+ setDhState(v);
224
+ if (!p.heightKey) return;
225
+ try {
226
+ localStorage.setItem("ui-lg-height:" + p.heightKey, String(Math.round(v)));
227
+ } catch {}
228
+ }, [p.heightKey]);
229
+ const spreadKey = avail + "#" + p.nodes.map((n) => n.id).join("|") + "#" + p.edges.map((e) => e.from + ">" + e.to + ":" + (e.label ?? "")).join("|");
230
+ const [spreadAt, setSpread] = React.useState({
231
+ key: "",
232
+ n: 0
233
+ });
234
+ const spread = spreadAt.key === spreadKey ? spreadAt.n : 0;
235
+ const COL = (fitted?.col ?? 40) + spread * 24;
236
+ const scale = fitted?.scale ?? 1;
237
+ const PAD = 16;
238
+ const all = p.nodes;
239
+ const sel = p.selected ?? null;
240
+ devWarn(all.some((n) => n.fns != null), "LayerGraph", "fns is renamed size; pass size and, for the text under the bar, sizeLabel such as 「{n} 個函式」.");
241
+ devWarn(all.some((n) => n.external && n.shared), "LayerGraph", "a node is both external and shared; it is drawn as shared. Keep one of the two.");
242
+ const sizeOf = (n) => n.external && !n.shared ? void 0 : n.size ?? n.fns;
243
+ const sharedIds = new Set(all.filter((n) => n.shared).map((n) => n.id));
244
+ const main = all.filter((n) => !n.shared);
245
+ const tagLine = main.some((n) => {
246
+ if (!n.tag) return false;
247
+ const name = n.name || n.id;
248
+ const tagW = textWidth(n.tag, 12, false) + 12 + (n.tagTone === "warning" ? 15 : 0);
249
+ return NW - (n.external ? 24 : 28) - 6 - tagW < textWidth(name.slice(0, TAG_KEEP), 13, !!n.code) + (name.length > TAG_KEEP ? 1 : 0);
250
+ });
251
+ const NH = tagLine ? 76 : 60;
252
+ const shared = all.filter((n) => n.shared);
253
+ const edges = p.edges.filter((e) => !sharedIds.has(e.from) && !sharedIds.has(e.to));
254
+ const lab = (e) => !!(e.inferred || e.declared);
255
+ const byLayer = /* @__PURE__ */ new Map();
256
+ const EXTERNAL = Number.NEGATIVE_INFINITY;
257
+ for (const n of main) {
258
+ const l = n.external ? EXTERNAL : n.layer || 0;
259
+ byLayer.set(l, [...byLayer.get(l) ?? [], n]);
260
+ }
261
+ const layers = [...byLayer.keys()].sort((a, b) => a - b);
262
+ const cols = Math.max(1, ...layers.map((l) => byLayer.get(l)?.length ?? 0));
263
+ let W = 32 + cols * NW + (cols - 1) * COL;
264
+ const between = Math.max(0, layers.length - 1);
265
+ const extra = p.resizable && dh > 0 && between ? Math.min(MAX_EXTRA, dh / scale / between) : 0;
266
+ const gaps = layers.map((_, k) => GAP + (k < between ? extra : 0));
267
+ let H = 0;
268
+ const pos = {};
269
+ const layerIndex = {};
270
+ layers.forEach((l, k) => {
271
+ const row = byLayer.get(l) ?? [];
272
+ const off = (W - (row.length * NW + (row.length - 1) * COL)) / 2;
273
+ row.forEach((n, i) => {
274
+ pos[n.id] = {
275
+ x: off + i * (NW + COL),
276
+ y: 0
277
+ };
278
+ layerIndex[n.id] = k;
279
+ });
280
+ });
281
+ const rowTop = (k) => PAD + k * NH + gaps.slice(0, k).reduce((a, b) => a + b, 0);
282
+ const extRow = byLayer.get(EXTERNAL) ?? [];
283
+ const extW = Math.max(NW, Math.min(p.nodeWidth || 200, W - PAD));
284
+ const boxOf = (id) => {
285
+ const wide = extRow.length === 1 && extRow[0].id === id ? extW : NW;
286
+ return {
287
+ x: pos[id].x + (NW - wide) / 2,
288
+ w: wide
289
+ };
290
+ };
291
+ const placeRows = () => {
292
+ for (const id in pos) pos[id].y = rowTop(layerIndex[id]);
293
+ H = rowTop(layers.length - 1) + NH + PAD + (flatRow[layers.length - 1]?.length ? FLAT_ROOM : 0);
294
+ };
295
+ const maxSize = Math.max(1, ...main.map((n) => sizeOf(n) || 0));
296
+ const maxCount = Math.max(1, ...edges.map((e) => e.count || 0));
297
+ const isUp = (e) => !!pos[e.from] && !!pos[e.to] && layerIndex[e.to] < layerIndex[e.from];
298
+ const isFlat = (e) => !!pos[e.from] && !!pos[e.to] && e.from !== e.to && layerIndex[e.to] === layerIndex[e.from];
299
+ const flatIn = {};
300
+ const flatRow = {};
301
+ const outs = {};
302
+ const ins = {};
303
+ const upOut = {};
304
+ const upIn = {};
305
+ for (const e of edges) {
306
+ if (!pos[e.from] || !pos[e.to]) continue;
307
+ if (isUp(e)) {
308
+ (upOut[e.from] ??= []).push(e);
309
+ (upIn[e.to] ??= []).push(e);
310
+ continue;
311
+ }
312
+ (outs[e.from] ??= []).push(e);
313
+ if (isFlat(e)) {
314
+ (flatIn[e.to] ??= []).push(e);
315
+ (flatRow[layerIndex[e.from]] ??= []).push(e);
316
+ continue;
317
+ }
318
+ (ins[e.to] ??= []).push(e);
319
+ }
320
+ const FLAT_ROOM = 20 + 10 * Math.max(0, (flatRow[layers.length - 1]?.length ?? 0) - 1);
321
+ const ups = edges.filter(isUp);
322
+ const rowOf = (id) => byLayer.get(layers[layerIndex[id]]) ?? [];
323
+ const rightmost = (id) => rowOf(id)[rowOf(id).length - 1]?.id === id;
324
+ const leftmost = (id) => rowOf(id)[0]?.id === id;
325
+ const onLeft = (e) => !rightmost(e.to) && leftmost(e.to);
326
+ const upsL = ups.filter(onLeft);
327
+ const upsR = ups.filter((e) => !onLeft(e));
328
+ const LANE = 20;
329
+ const LANE_STEP = 12;
330
+ for (const k in outs) outs[k].sort((a, b) => pos[a.to].x - pos[b.to].x);
331
+ for (const k in ins) ins[k].sort((a, b) => pos[a.from].x - pos[b.from].x);
332
+ const edgeId = (e) => e.id ?? `${e.from}->${e.to}`;
333
+ const pickEdge = p.onSelectEdge;
334
+ const [labelsOn, setLabelsOn] = React.useState(() => {
335
+ try {
336
+ const v = window.localStorage.getItem(LABELS_KEY + (p.scrollKey ?? allIds(p.nodes)));
337
+ if (v === "1" || v === "0") return v === "1";
338
+ } catch {}
339
+ return p.edgeLabels !== "hover";
340
+ });
341
+ const peek = !labelsOn;
342
+ const switchLabels = () => {
343
+ const on = !labelsOn;
344
+ setLabelsOn(on);
345
+ try {
346
+ window.localStorage.setItem(LABELS_KEY + (p.scrollKey ?? allIds(p.nodes)), on ? "1" : "0");
347
+ } catch {}
348
+ };
349
+ const [hover, setHover] = React.useState(null);
350
+ const { ref: scrollRef, more: scrollMore, overflows, scrolled, onScroll } = useScrollHint();
351
+ const uid = React.useId().replace(/:/g, "");
352
+ const [view, setView] = React.useState("graph");
353
+ const memKey = p.scrollKey ?? all.map((n) => n.id).join("|");
354
+ React.useLayoutEffect(() => {
355
+ const el = scrollRef.current;
356
+ const x = scrollMemory.get(memKey);
357
+ if (el && x) el.scrollLeft = x;
358
+ }, [
359
+ memKey,
360
+ view,
361
+ scrollRef
362
+ ]);
363
+ const onScrollKeep = () => {
364
+ const el = scrollRef.current;
365
+ if (el) scrollMemory.set(memKey, el.scrollLeft);
366
+ onScroll();
367
+ };
368
+ const selEdge = pickEdge && edges.find((e) => edgeId(e) === p.selectedEdge) || null;
369
+ const selListEdge = pickEdge && p.edges.find((e) => edgeId(e) === p.selectedEdge) || null;
370
+ const nodeIdsAll = new Set(all.map((n) => n.id));
371
+ const uses = {};
372
+ for (const e of p.edges) if (sharedIds.has(e.to) && e.from !== e.to && nodeIdsAll.has(e.from)) (uses[e.to] ??= {})[e.from] = (uses[e.to]?.[e.from] ?? 0) + (e.count || 0);
373
+ const selShared = !selEdge && sel != null && sharedIds.has(sel) ? sel : null;
374
+ const related = (e) => selEdge ? e === selEdge : !!sel && !selShared && (e.from === sel || e.to === sel);
375
+ const focus = !!sel || !!selEdge;
376
+ const near = (id) => selEdge ? id === selEdge.from || id === selEdge.to : selShared ? id === selShared || id in (uses[selShared] ?? {}) : !sel || id === sel || edges.some((e) => related(e) && (e.from === id || e.to === id));
377
+ const pick = (id, on) => {
378
+ if (!on && p.selectedEdge != null) pickEdge?.(null);
379
+ p.onSelect?.(on ? null : id);
380
+ };
381
+ const nameOf = (id) => all.find((n) => n.id === id)?.name || id;
382
+ const countText = (e) => {
383
+ const n = e.count ?? 0;
384
+ return typeof p.countLabel === "function" ? p.countLabel(n) : (p.countLabel ?? byCount(n, "1 次", "{n} 次")).replace("{n}", format.number(n));
385
+ };
386
+ const midSentence = (t) => /^[A-Z][a-z]/.test(t) && !/^zh/i.test(format.locale()) ? t[0].toLowerCase() + t.slice(1) : t;
387
+ const sameLabel = /* @__PURE__ */ new Map();
388
+ for (const e of edges) if (lab(e) && e.label && pos[e.from] && pos[e.to]) sameLabel.set(e.label, (sameLabel.get(e.label) ?? 0) + 1);
389
+ const kindWord = (e) => e.declared ? p.declaredLabel || tr("宣告") : p.inferredLabel || tr("推測");
390
+ const inferredText = (e) => e.label && (sameLabel.get(e.label) ?? 0) > 1 ? tr("來自 {from},{label}", {
391
+ from: nameOf(e.from),
392
+ label: midSentence(e.label)
393
+ }) : e.label || kindWord(e);
394
+ const markText = (e) => lab(e) ? inferredText(e) : countText(e);
395
+ if (upsL.length) {
396
+ const left0 = Math.min(...main.map((n) => pos[n.id].x));
397
+ const shift = Math.max(0, PAD + (upsL.length - 1) * LANE_STEP + LANE - left0);
398
+ for (const id in pos) pos[id] = {
399
+ x: pos[id].x + shift,
400
+ y: pos[id].y
401
+ };
402
+ W += shift;
403
+ }
404
+ const boxesLeft = () => Math.min(...main.map((n) => pos[n.id].x));
405
+ const boxesRight = () => Math.max(0, ...main.map((n) => pos[n.id].x + NW));
406
+ const laneX = (e) => onLeft(e) ? boxesLeft() - LANE - upsL.indexOf(e) * LANE_STEP : boxesRight() + LANE + upsR.indexOf(e) * LANE_STEP;
407
+ const upLabelX = () => boxesLeft() - LANE + 8;
408
+ const upLabelEndL = () => boxesRight() + LANE - 8;
409
+ if (upsR.length) W = Math.max(W, boxesRight() + LANE + (upsR.length - 1) * LANE_STEP + PAD);
410
+ const choose = (e) => {
411
+ const id = edgeId(e);
412
+ const next = p.selectedEdge === id ? null : id;
413
+ if (next && sel != null) p.onSelect?.(null);
414
+ pickEdge?.(next);
415
+ };
416
+ const LANE_H = 28;
417
+ const txOf = (e) => Math.round(pos[e.to].x + NW * (ins[e.to].indexOf(e) + 1) / (ins[e.to].length + 1));
418
+ const laneGroups = {};
419
+ const laneCount = {};
420
+ {
421
+ const into = {};
422
+ for (const e of edges) if (ins[e.to]?.includes(e) && (lab(e) || related(e))) (into[e.to] ??= []).push(e);
423
+ for (const id in into) {
424
+ if (into[id].length < 2) continue;
425
+ laneGroups[id] = into[id].sort((a, b) => txOf(b) - txOf(a));
426
+ laneCount[id] = into[id].length;
427
+ }
428
+ }
429
+ const draw = () => {
430
+ const paths = [];
431
+ const labels = [];
432
+ const need = /* @__PURE__ */ new Set();
433
+ const crowd = /* @__PURE__ */ new Set();
434
+ let covered = 0;
435
+ const geomOf = (e) => {
436
+ const a = pos[e.from];
437
+ const b = pos[e.to];
438
+ const oi = outs[e.from].indexOf(e);
439
+ const on = outs[e.from].length;
440
+ const sx = outX(a.x, oi, on);
441
+ const sy = a.y + NH;
442
+ const tx = txOf(e);
443
+ const ty = b.y;
444
+ const off = (oi - (on - 1) / 2) * 6;
445
+ const skip = layerIndex[e.to] - layerIndex[e.from] > 1;
446
+ const y1 = sy + gaps[layerIndex[e.from]] / 2 + off;
447
+ let chx = sx;
448
+ if (skip) {
449
+ const next = (byLayer.get(layers[layerIndex[e.from] + 1]) ?? []).map((n) => pos[n.id]);
450
+ const mid = (sx + tx) / 2;
451
+ const chans = [next[0].x - COL / 2, ...next.map((q) => q.x + NW + COL / 2)].map((c) => Math.max(PAD / 2, Math.min(W - PAD / 2, c)));
452
+ chx = chans.reduce((best, c) => Math.abs(c - mid) < Math.abs(best - mid) ? c : best, chans[0]) + off;
453
+ }
454
+ return {
455
+ sx,
456
+ sy,
457
+ tx,
458
+ ty,
459
+ off,
460
+ skip,
461
+ y1,
462
+ chx,
463
+ from: skip ? chx : sx,
464
+ startY: skip ? y1 : sy
465
+ };
466
+ };
467
+ const lanes = /* @__PURE__ */ new Map();
468
+ const outX = (x, i, n) => Math.round(n < 2 ? x + NW / 2 : x + 16 + (NW - 32) * i / (n - 1));
469
+ const flatOf = (e) => {
470
+ const a = pos[e.from];
471
+ const b = pos[e.to];
472
+ const oi = outs[e.from].indexOf(e);
473
+ const on = outs[e.from].length;
474
+ const sx = outX(a.x, oi, on);
475
+ const j = flatRow[layerIndex[e.from]].indexOf(e);
476
+ const ti = flatIn[e.to].indexOf(e);
477
+ const tx = Math.round(b.x + NW - 24 - ti * 12);
478
+ return {
479
+ sx,
480
+ sy: a.y + NH,
481
+ y: a.y + NH + 14 + j * 10,
482
+ tx,
483
+ ty: b.y + NH
484
+ };
485
+ };
486
+ const vertsOf = (e) => {
487
+ if (isFlat(e)) {
488
+ const f = flatOf(e);
489
+ return [{
490
+ x: f.sx,
491
+ y0: f.sy,
492
+ y1: f.y
493
+ }, {
494
+ x: f.tx,
495
+ y0: f.ty,
496
+ y1: f.y
497
+ }];
498
+ }
499
+ if (isUp(e)) return [{
500
+ x: laneX(e),
501
+ y0: pos[e.to].y,
502
+ y1: pos[e.from].y + NH
503
+ }];
504
+ const g = geomOf(e);
505
+ if (!g.skip) return [{
506
+ x: g.sx,
507
+ y0: g.sy,
508
+ y1: g.y1
509
+ }, {
510
+ x: g.tx,
511
+ y0: g.y1,
512
+ y1: g.ty
513
+ }];
514
+ const y2 = g.ty - gaps[layerIndex[e.to] - 1] / 2 + g.off;
515
+ return [
516
+ {
517
+ x: g.sx,
518
+ y0: g.sy,
519
+ y1: g.y1
520
+ },
521
+ {
522
+ x: g.chx,
523
+ y0: g.y1,
524
+ y1: y2
525
+ },
526
+ {
527
+ x: g.tx,
528
+ y0: y2,
529
+ y1: g.ty
530
+ }
531
+ ];
532
+ };
533
+ for (const id in laneGroups) {
534
+ const group = laneGroups[id].map((e) => ({
535
+ e,
536
+ g: geomOf(e),
537
+ w: Math.ceil(labelWidth(markText(e)))
538
+ }));
539
+ const others = edges.filter((e) => !laneGroups[id].includes(e) && pos[e.from] && pos[e.to]).flatMap((e) => vertsOf(e).map((v) => ({
540
+ k: -1,
541
+ ...v
542
+ })));
543
+ const n = group.length;
544
+ const laneY = (j) => group[0].g.ty - 8 - 16 - j * LANE_H;
545
+ const perms = [];
546
+ const permute = (rest, acc) => {
547
+ if (!rest.length) perms.push(acc);
548
+ else rest.forEach((x, k) => permute([...rest.slice(0, k), ...rest.slice(k + 1)], [...acc, x]));
549
+ };
550
+ if (n <= 6) permute([...group.keys()], []);
551
+ else perms.push([...group.keys()]);
552
+ let best = null;
553
+ for (const perm of perms) {
554
+ const ys = [];
555
+ perm.forEach((k, j) => ys[k] = laneY(j));
556
+ const verts = [...group.flatMap((q, k) => [{
557
+ k,
558
+ x: q.g.from,
559
+ y0: q.g.startY,
560
+ y1: ys[k]
561
+ }, {
562
+ k,
563
+ x: q.g.tx,
564
+ y0: ys[k],
565
+ y1: q.g.ty - 8
566
+ }]), ...others];
567
+ const free = (k, x0, x1) => verts.every((v) => v.k === k ? !(v.x > x0 - 1 && v.x < x1 + 1 && v.y0 < ys[k] + 7 && v.y1 > ys[k] - 7) : !(v.x > x0 - 5 && v.x < x1 + 5 && v.y0 < ys[k] + 10 && v.y1 > ys[k] - 10));
568
+ let fails = 0;
569
+ const sides = [];
570
+ group.forEach((q, k) => {
571
+ const r0 = Math.max(q.g.from, q.g.tx) + 8;
572
+ const l1 = Math.min(q.g.from, q.g.tx) - 8;
573
+ if (free(k, r0, r0 + q.w)) sides[k] = "right";
574
+ else if (free(k, l1 - q.w, l1)) sides[k] = "left";
575
+ else {
576
+ sides[k] = "right";
577
+ fails++;
578
+ }
579
+ });
580
+ if (!best || fails < best.fails) best = {
581
+ fails,
582
+ ys,
583
+ sides
584
+ };
585
+ if (!fails) break;
586
+ }
587
+ if (best) group.forEach((q, k) => lanes.set(q.e, {
588
+ y: best.ys[k],
589
+ side: best.sides[k]
590
+ }));
591
+ }
592
+ const marks = [];
593
+ let wide = 0;
594
+ let least = 0;
595
+ const runs = [];
596
+ const segs = [];
597
+ const ptsOf = {};
598
+ const arrows = [];
599
+ const hitPaths = [];
600
+ edges.forEach((e, idx) => {
601
+ const a = pos[e.from];
602
+ const b = pos[e.to];
603
+ if (!a || !b) return;
604
+ const r = related(e);
605
+ const dim = focus && !r;
606
+ const picked = e === selEdge;
607
+ const hovered = !!pickEdge && hover === edgeId(e) && !r;
608
+ const up = isUp(e);
609
+ let pts;
610
+ let tx;
611
+ let ty;
612
+ let arrow;
613
+ let inn = 1;
614
+ let laneAt = null;
615
+ let turnFrom = 0;
616
+ let laneSide = "right";
617
+ if (up) {
618
+ const lx = laneX(e);
619
+ const L = onLeft(e);
620
+ const si = upOut[e.from].indexOf(e);
621
+ const sn = upOut[e.from].length;
622
+ const ti = upIn[e.to].indexOf(e);
623
+ const tn = upIn[e.to].length;
624
+ const start = [];
625
+ let y0;
626
+ if (L ? leftmost(e.from) : rightmost(e.from)) {
627
+ y0 = Math.round(a.y + NH / 2 + (si - (sn - 1) / 2) * 10);
628
+ start.push([L ? a.x : a.x + NW, y0], [lx, y0]);
629
+ } else {
630
+ const px = L ? a.x + 20 + si * 10 : a.x + NW - 20 - si * 10;
631
+ y0 = a.y - 12 - si * 6;
632
+ start.push([px, a.y], [px, y0], [lx, y0]);
633
+ }
634
+ let y1;
635
+ if (L || rightmost(e.to)) {
636
+ y1 = Math.round(b.y + NH / 2 + (ti - (tn - 1) / 2) * 10);
637
+ tx = L ? b.x : b.x + NW;
638
+ ty = y1;
639
+ const back = L ? tx - 9 : tx + 9;
640
+ pts = [
641
+ ...start,
642
+ [lx, y1],
643
+ [back, y1]
644
+ ];
645
+ arrow = `M${back} ${ty - 5} L${back} ${ty + 5} L${tx} ${ty} Z`;
646
+ arrows.push([
647
+ Math.min(tx, back),
648
+ Math.max(tx, back),
649
+ ty - 5,
650
+ ty + 5
651
+ ]);
652
+ runs.push([
653
+ Math.min(tx, lx),
654
+ Math.max(tx, lx),
655
+ y1 - 3,
656
+ y1 + 3
657
+ ]);
658
+ } else {
659
+ tx = b.x + NW - 20 - ti * 10;
660
+ y1 = b.y + NH + 12 + ti * 6;
661
+ ty = b.y + NH;
662
+ pts = [
663
+ ...start,
664
+ [lx, y1],
665
+ [tx, y1],
666
+ [tx, ty + 9]
667
+ ];
668
+ arrow = `M${tx - 5} ${ty + 9} L${tx + 5} ${ty + 9} L${tx} ${ty} Z`;
669
+ arrows.push([
670
+ tx - 5,
671
+ tx + 5,
672
+ ty,
673
+ ty + 9
674
+ ]);
675
+ runs.push([
676
+ tx,
677
+ lx,
678
+ y1 - 3,
679
+ y1 + 3
680
+ ]);
681
+ }
682
+ const sx0 = start[start.length - 2][0];
683
+ runs.push([
684
+ Math.min(sx0, lx),
685
+ Math.max(sx0, lx),
686
+ y0 - 3,
687
+ y0 + 3
688
+ ]);
689
+ if (lab(e) || r) {
690
+ const text = markText(e);
691
+ marks.push({
692
+ idx,
693
+ e,
694
+ text,
695
+ tx: L ? upLabelX() : upLabelEndL(),
696
+ ty: Math.round((y0 + y1) / 2),
697
+ left: !L,
698
+ r,
699
+ dim,
700
+ up: true
701
+ });
702
+ }
703
+ } else if (isFlat(e)) {
704
+ const f = flatOf(e);
705
+ tx = f.tx;
706
+ ty = f.ty;
707
+ pts = [
708
+ [f.sx, f.sy],
709
+ [f.sx, f.y],
710
+ [f.tx, f.y],
711
+ [f.tx, f.ty + 9]
712
+ ];
713
+ arrow = `M${tx - 5} ${ty + 9} L${tx + 5} ${ty + 9} L${tx} ${ty} Z`;
714
+ arrows.push([
715
+ tx - 5,
716
+ tx + 5,
717
+ ty,
718
+ ty + 9
719
+ ]);
720
+ runs.push([
721
+ Math.min(f.sx, f.tx),
722
+ Math.max(f.sx, f.tx),
723
+ f.y - 3,
724
+ f.y + 3
725
+ ]);
726
+ if (lab(e) || r) {
727
+ const text = markText(e);
728
+ marks.push({
729
+ idx,
730
+ e,
731
+ text,
732
+ tx: Math.round((f.sx + f.tx) / 2),
733
+ ty: f.y,
734
+ left: false,
735
+ r,
736
+ dim,
737
+ flat: true
738
+ });
739
+ }
740
+ } else {
741
+ inn = ins[e.to].length;
742
+ const g = geomOf(e);
743
+ const { sx, sy, skip } = g;
744
+ tx = g.tx;
745
+ ty = g.ty;
746
+ const lane = lanes.get(e);
747
+ const laneY = lane ? lane.y : null;
748
+ const y1 = !skip && laneY != null ? laneY : g.y1;
749
+ if (skip) {
750
+ const y2 = laneY ?? ty - gaps[layerIndex[e.to] - 1] / 2 + g.off;
751
+ pts = [
752
+ [sx, sy],
753
+ [sx, y1],
754
+ [g.chx, y1],
755
+ [g.chx, y2],
756
+ [tx, y2],
757
+ [tx, ty - 8]
758
+ ];
759
+ } else pts = [
760
+ [sx, sy],
761
+ [sx, y1],
762
+ [tx, y1],
763
+ [tx, ty - 8]
764
+ ];
765
+ turnFrom = g.from;
766
+ laneAt = laneY;
767
+ laneSide = lane?.side ?? "right";
768
+ arrow = `M${tx - 5} ${ty - 9} L${tx + 5} ${ty - 9} L${tx} ${ty} Z`;
769
+ arrows.push([
770
+ tx - 5,
771
+ tx + 5,
772
+ ty - 9,
773
+ ty
774
+ ]);
775
+ }
776
+ const w = (lab(e) ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount)) + (picked ? 1.5 : 0) + (hovered ? 2 : 0);
777
+ const cpts = clean(pts);
778
+ ptsOf[idx] = cpts;
779
+ for (let k = 1; k < cpts.length; k++) {
780
+ const [ax, ay] = cpts[k - 1];
781
+ const [bx, by] = cpts[k];
782
+ segs.push({
783
+ idx,
784
+ box: [
785
+ Math.min(ax, bx) - 3,
786
+ Math.max(ax, bx) + 3,
787
+ Math.min(ay, by) - 3,
788
+ Math.max(ay, by) + 3
789
+ ]
790
+ });
791
+ }
792
+ const d = route(cpts, 10);
793
+ paths.push(/* @__PURE__ */ jsx("path", {
794
+ className: cx("ui-lg-edge", e.declared ? "is-declared" : e.inferred && "is-inferred", r && "is-related", dim && "is-dim", hovered && "is-hover"),
795
+ d,
796
+ strokeWidth: w
797
+ }, "p" + idx));
798
+ if (!pickEdge && peek) hitPaths.push(/* @__PURE__ */ jsx("path", {
799
+ className: "ui-lg-hit is-peek",
800
+ d,
801
+ onPointerEnter: () => setHover(edgeId(e)),
802
+ onPointerLeave: () => setHover(null)
803
+ }, "h" + idx));
804
+ if (pickEdge) hitPaths.push(/* @__PURE__ */ jsx("path", {
805
+ className: "ui-lg-hit",
806
+ "data-edge": edgeId(e),
807
+ d,
808
+ role: "button",
809
+ tabIndex: 0,
810
+ "aria-label": tr("{from} 到 {to},{what}", {
811
+ from: nameOf(e.from),
812
+ to: nameOf(e.to),
813
+ what: markText(e).replace(/`/g, "")
814
+ }),
815
+ "aria-pressed": picked,
816
+ onClick: (ev) => {
817
+ ev.stopPropagation();
818
+ choose(e);
819
+ },
820
+ onPointerEnter: () => setHover(edgeId(e)),
821
+ onPointerLeave: () => setHover(null),
822
+ onFocus: peek ? () => setHover(edgeId(e)) : void 0,
823
+ onBlur: peek ? () => setHover(null) : void 0,
824
+ onKeyDown: (ev) => {
825
+ if (ev.key === "Enter" || ev.key === " ") {
826
+ ev.preventDefault();
827
+ choose(e);
828
+ } else if (ev.key === "Escape" && picked) pickEdge(null);
829
+ }
830
+ }, "h" + idx));
831
+ paths.push(/* @__PURE__ */ jsx("path", {
832
+ className: cx("ui-lg-arrow", r && "is-related", dim && "is-dim"),
833
+ d: arrow
834
+ }, "a" + idx));
835
+ if (!up && !isFlat(e) && (lab(e) || r)) {
836
+ const text = markText(e);
837
+ marks.push({
838
+ idx,
839
+ e,
840
+ text,
841
+ tx,
842
+ ty,
843
+ left: inn > 1 && tx < b.x + NW / 2,
844
+ r,
845
+ dim,
846
+ lane: laneAt,
847
+ from: turnFrom,
848
+ side: laneSide
849
+ });
850
+ }
851
+ });
852
+ const placed = [...arrows, ...runs];
853
+ const boxRects = main.map((n) => [
854
+ boxOf(n.id).x,
855
+ boxOf(n.id).x + boxOf(n.id).w,
856
+ pos[n.id].y,
857
+ pos[n.id].y + NH
858
+ ]);
859
+ const hits = (x0, x1, y0, y1) => placed.some((q) => x0 < q[1] + (q[4] || 0) && q[0] < x1 + (q[4] || 0) && y0 < q[3] && q[2] < y1);
860
+ const cross = (q, x0, lw, y0, y1) => x0 < q[1] - 1 && q[0] + 1 < x0 + lw && y0 < q[3] - 1 && q[2] + 1 < y1;
861
+ const gapTo = (b, x0, lw, y0, y1) => Math.hypot(Math.max(0, b[0] - (x0 + lw), x0 - b[1]), Math.max(0, b[2] - y1, y0 - b[3]));
862
+ const isMine = (idx, x0, lw, y0, y1) => {
863
+ let self = Infinity;
864
+ let other = Infinity;
865
+ for (const sg of segs) {
866
+ const d = gapTo(sg.box, x0, lw, y0, y1);
867
+ if (sg.idx === idx) self = Math.min(self, d);
868
+ else other = Math.min(other, d);
869
+ }
870
+ return self + 4 < other && other >= 8;
871
+ };
872
+ const alongLine = (m, own = true) => {
873
+ const pts = ptsOf[m.idx] ?? [];
874
+ const mine = (x0, lw, y0, y1) => isMine(m.idx, x0, lw, y0, y1);
875
+ const ok = (x0, lw, y0, y1) => (!own || mine(x0, lw, y0, y1)) && x0 >= PAD / 2 && x0 + lw <= W - PAD / 2 && y0 >= 2 && y1 <= H - 2 && !hits(x0 - 2, x0 + lw + 2, y0 - 2, y1 + 2) && !boxRects.some((q) => x0 < q[1] + 4 && q[0] < x0 + lw + 4 && y0 < q[3] + 4 && q[2] < y1 + 4) && !segs.some((sg) => sg.idx === m.idx ? cross(sg.box, x0, lw, y0, y1) : x0 < sg.box[1] + 2 && sg.box[0] < x0 + lw + 2 && y0 < sg.box[3] + 2 && sg.box[2] < y1 + 2);
876
+ for (const lines of wraps(m.text)) {
877
+ const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
878
+ const lh = lines.length * 16;
879
+ let best = null;
880
+ for (let k = 1; k < pts.length; k++) {
881
+ const [ax, ay] = pts[k - 1];
882
+ const [bx, by] = pts[k];
883
+ const len = Math.hypot(bx - ax, by - ay);
884
+ for (let t = 0; t <= len; t += 6) {
885
+ const x = ax + (bx - ax) * t / len;
886
+ const y = ay + (by - ay) * t / len;
887
+ const cands = ax === bx ? [[x + 8, y], [x - 8 - lw, y]] : [[x - lw / 2, y - 6 - lh / 2], [x - lw / 2, y + 6 + lh / 2]];
888
+ for (const [x0, top] of cands) {
889
+ const d = Math.hypot(x0 + lw / 2 - m.tx, top - m.ty);
890
+ if (best && d >= best.d) continue;
891
+ if (ok(x0, lw, top - lh / 2, top + lh / 2)) best = {
892
+ x0,
893
+ top,
894
+ d
895
+ };
896
+ }
897
+ }
898
+ }
899
+ if (best) return {
900
+ x0: Math.round(best.x0),
901
+ top: Math.round(best.top),
902
+ lw,
903
+ lh,
904
+ lines
905
+ };
906
+ }
907
+ return null;
908
+ };
909
+ const numbered = [];
910
+ const numberOn = (m, near) => {
911
+ const pts = ptsOf[m.idx] ?? [];
912
+ const cx = near.x0 + near.lw / 2;
913
+ const cy = near.top;
914
+ let best = null;
915
+ for (let k = 0; k + 1 < pts.length; k++) {
916
+ const [x1, y1] = pts[k];
917
+ const [x2, y2] = pts[k + 1];
918
+ const len = Math.hypot(x2 - x1, y2 - y1);
919
+ for (let t = 12; t <= len - 12; t += 4) {
920
+ const x = x1 + (x2 - x1) * t / len;
921
+ const y = y1 + (y2 - y1) * t / len;
922
+ const clear = !segs.some((sg) => sg.idx !== m.idx && gapTo(sg.box, x - 14, 28, y - 14, y + 14) === 0) && !boxRects.some((q) => x + 14 > q[0] && x - 14 < q[1] && y + 14 > q[2] && y - 14 < q[3]) && !hits(x - 14, x + 14, y - 14, y + 14) && !numbered.some((o) => Math.hypot(o.x - x, o.y - y) < 28);
923
+ const d = Math.hypot(x - cx, y - cy);
924
+ if (!best || clear && !best.clear || clear === best.clear && d < best.d) best = {
925
+ x,
926
+ y,
927
+ d,
928
+ clear
929
+ };
930
+ }
931
+ }
932
+ const at = best ?? {
933
+ x: m.tx,
934
+ y: m.ty - 20
935
+ };
936
+ numbered.push({
937
+ n: numbered.length + 1,
938
+ m,
939
+ x: Math.round(at.x),
940
+ y: Math.round(at.y)
941
+ });
942
+ return numbered.length;
943
+ };
944
+ const labelEl = (m, x0, top, lines = [m.text], over = false, num = 0) => /* @__PURE__ */ jsx("span", {
945
+ "aria-hidden": pickEdge ? true : void 0,
946
+ className: cx("ui-lg-label", over && "is-over", num > 0 && "is-numbered", num > 0 && (hover === edgeId(m.e) || m.e === selEdge) && "is-shown", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim", peek && !m.r && hover !== edgeId(m.e) && m.e !== selEdge && "is-quiet"),
947
+ style: {
948
+ left: x0,
949
+ top
950
+ },
951
+ onClick: pickEdge ? (ev) => {
952
+ ev.stopPropagation();
953
+ choose(m.e);
954
+ } : void 0,
955
+ onPointerEnter: pickEdge ? () => setHover(edgeId(m.e)) : void 0,
956
+ onPointerLeave: pickEdge ? () => setHover(null) : void 0,
957
+ children: lines.map((t, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [i ? /* @__PURE__ */ jsx("br", {}) : null, labelParts(t)] }, i))
958
+ }, "l" + m.idx);
959
+ const later = [];
960
+ const place = (m, last) => {
961
+ const w = Math.ceil(labelWidth(m.text));
962
+ if (m.flat) {
963
+ let spot = alongLine(m);
964
+ if (!spot) {
965
+ const g = layerIndex[m.e.from];
966
+ if (g < layers.length - 1) need.add(g);
967
+ covered++;
968
+ const x0 = Math.max(PAD / 2, Math.min(W - PAD / 2 - w, m.tx - w / 2));
969
+ const taken = (t) => hits(x0, x0 + w, t - 10, t + 10) || boxRects.some((q) => x0 < q[1] + 2 && q[0] < x0 + w + 2 && t - 10 < q[3] && q[2] < t + 10);
970
+ let top = m.ty + 14;
971
+ for (let k = 0; k < 8 && taken(top); k++) top += 18;
972
+ spot = {
973
+ x0,
974
+ top,
975
+ lw: w,
976
+ lh: 16,
977
+ lines: [m.text]
978
+ };
979
+ labels.push(labelEl(m, spot.x0, spot.top, spot.lines, true, numberOn(m, spot)));
980
+ return;
981
+ }
982
+ placed.push([
983
+ spot.x0,
984
+ spot.x0 + spot.lw,
985
+ spot.top - spot.lh / 2 - 4,
986
+ spot.top + spot.lh / 2 + 4,
987
+ 6
988
+ ]);
989
+ labels.push(labelEl(m, spot.x0, spot.top, spot.lines));
990
+ return;
991
+ }
992
+ if (m.up) {
993
+ const p0 = ptsOf[m.idx]?.[0];
994
+ const near = p0 ? alongLine({
995
+ ...m,
996
+ tx: p0[0],
997
+ ty: p0[1]
998
+ }, true) : null;
999
+ if (near) {
1000
+ placed.push([
1001
+ near.x0,
1002
+ near.x0 + near.lw,
1003
+ near.top - near.lh / 2 - 4,
1004
+ near.top + near.lh / 2 + 4,
1005
+ 6
1006
+ ]);
1007
+ labels.push(labelEl(m, near.x0, near.top, near.lines));
1008
+ return;
1009
+ }
1010
+ const x0Of = (lw) => Math.max(PAD / 2, Math.min(W - PAD / 2 - lw, m.left ? m.tx - lw : m.tx));
1011
+ const start0 = Math.max(10, Math.min(H - 10, m.ty));
1012
+ const find = (x0, lw, lh, withLines) => {
1013
+ const over = (q, y0, y1) => x0 < q[1] + 4 && q[0] < x0 + lw + 4 && y0 < q[3] + 4 && q[2] < y1 + 4;
1014
+ const bad = (y0, y1) => hits(x0, x0 + lw, y0 - 4, y1 + 4) || boxRects.some((q) => over(q, y0, y1)) || withLines && segs.some((g) => g.idx === m.idx ? cross(g.box, x0, lw, y0, y1) : over(g.box, y0, y1)) || withLines && !isMine(m.idx, x0, lw, y0, y1);
1015
+ for (let k = 0; k <= 16; k++) for (const dir of k ? [-1, 1] : [0]) {
1016
+ const t = start0 + dir * k * 18;
1017
+ if (t - lh / 2 >= 2 && t + lh / 2 <= H - 2 && !bad(t - lh / 2, t + lh / 2)) return t;
1018
+ }
1019
+ return null;
1020
+ };
1021
+ let spot = null;
1022
+ for (const lines of wraps(m.text)) {
1023
+ const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
1024
+ const lh = lines.length * 16;
1025
+ const x0 = x0Of(lw);
1026
+ const top = find(x0, lw, lh, true);
1027
+ if (top != null) {
1028
+ spot = {
1029
+ x0,
1030
+ top,
1031
+ lw,
1032
+ lh,
1033
+ lines
1034
+ };
1035
+ break;
1036
+ }
1037
+ }
1038
+ if (!spot) spot = alongLine(m);
1039
+ if (!spot) {
1040
+ const g = Math.max(0, Math.min(layers.length - 2, layers.findIndex((_, k) => k < layers.length - 1 && m.ty < rowTop(k + 1))));
1041
+ need.add(g);
1042
+ covered++;
1043
+ const x0 = x0Of(w);
1044
+ const top = find(x0, w, 16, false);
1045
+ if (top == null) crowd.add(g);
1046
+ const at = {
1047
+ x0,
1048
+ top: top ?? start0,
1049
+ lw: w,
1050
+ lh: 16,
1051
+ lines: [m.text]
1052
+ };
1053
+ labels.push(labelEl(m, at.x0, at.top, at.lines, true, numberOn(m, at)));
1054
+ return;
1055
+ }
1056
+ placed.push([
1057
+ spot.x0,
1058
+ spot.x0 + spot.lw,
1059
+ spot.top - spot.lh / 2 - 4,
1060
+ spot.top + spot.lh / 2 + 4,
1061
+ 6
1062
+ ]);
1063
+ labels.push(labelEl(m, spot.x0, spot.top, spot.lines));
1064
+ return;
1065
+ }
1066
+ const g = layerIndex[m.e.to] - 1;
1067
+ const gapTop = g >= 0 ? rowTop(g) + NH : 0;
1068
+ const sideOf = (lw) => {
1069
+ let left = m.left;
1070
+ if (left && m.tx - 8 - lw < 0) left = false;
1071
+ else if (!left && m.tx + 8 + lw > W) left = m.tx - 8 - lw >= 0;
1072
+ return left;
1073
+ };
1074
+ const at = (left, lw) => left ? m.tx - 8 - lw : Math.min(m.tx + 8, W - lw);
1075
+ const clear = (x0, lw, y0, y1) => {
1076
+ const over = (q) => x0 < q[1] + 2 && q[0] < x0 + lw + 2 && y0 < q[3] + 2 && q[2] < y1 + 2;
1077
+ return !hits(x0, x0 + lw, y0, y1) && !boxRects.some(over) && !segs.some((sg) => sg.idx === m.idx ? cross(sg.box, x0, lw, y0, y1) : over(sg.box));
1078
+ };
1079
+ let spot = null;
1080
+ if (m.lane != null) {
1081
+ const lane = m.lane;
1082
+ for (const lines of wraps(m.text)) {
1083
+ if (spot) break;
1084
+ const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
1085
+ const lh = lines.length * 16;
1086
+ const right = Math.max(m.tx, m.from ?? m.tx) + 8;
1087
+ const left = Math.min(m.tx, m.from ?? m.tx) - 8 - lw;
1088
+ for (const x0 of m.side === "left" ? [left, right] : [right, left]) if (!spot && clear(x0, lw, lane - lh / 2, lane + lh / 2)) spot = {
1089
+ x0,
1090
+ top: lane,
1091
+ lw,
1092
+ lh,
1093
+ lines
1094
+ };
1095
+ }
1096
+ }
1097
+ for (const lines of spot ? [] : wraps(m.text)) {
1098
+ const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
1099
+ const lh = lines.length * 16;
1100
+ const pref = sideOf(lw);
1101
+ for (const left of [pref, !pref]) {
1102
+ const x0 = at(left, lw);
1103
+ if (x0 < 0 || x0 + lw > W) continue;
1104
+ for (let k = 0; k < 8 && !spot; k++) {
1105
+ const top = m.ty - 8 - lh / 2 - k * 18;
1106
+ if (top - lh / 2 < Math.max(2, gapTop + 2)) break;
1107
+ if (clear(x0, lw, top - lh / 2, top + lh / 2)) spot = {
1108
+ x0,
1109
+ top,
1110
+ lw,
1111
+ lh,
1112
+ lines
1113
+ };
1114
+ }
1115
+ if (spot) break;
1116
+ }
1117
+ if (spot) break;
1118
+ }
1119
+ if (!spot) spot = alongLine(m);
1120
+ if (!spot && !last) {
1121
+ later.push(m);
1122
+ return;
1123
+ }
1124
+ const over = !spot;
1125
+ if (!spot) {
1126
+ if (g >= 0) need.add(g);
1127
+ covered++;
1128
+ const offBoxes = (x0, lw, y0, y1) => !hits(x0, x0 + lw, y0, y1) && !boxRects.some((q) => x0 < q[1] + 2 && q[0] < x0 + lw + 2 && y0 < q[3] + 2 && q[2] < y1 + 2);
1129
+ for (const lines of wraps(m.text)) {
1130
+ const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
1131
+ const lh = lines.length * 16;
1132
+ const pref = sideOf(lw);
1133
+ for (const left of [pref, !pref]) {
1134
+ const x0 = at(left, lw);
1135
+ if (x0 < 0 || x0 + lw > W) continue;
1136
+ for (let k = 0; k < 8 && !spot; k++) {
1137
+ const top = m.ty - 8 - lh / 2 - k * 18;
1138
+ if (top - lh / 2 < Math.max(2, gapTop + 2)) break;
1139
+ if (offBoxes(x0, lw, top - lh / 2, top + lh / 2)) spot = {
1140
+ x0,
1141
+ top,
1142
+ lw,
1143
+ lh,
1144
+ lines
1145
+ };
1146
+ }
1147
+ if (spot) break;
1148
+ }
1149
+ if (spot) break;
1150
+ }
1151
+ if (!spot) {
1152
+ if (g >= 0) crowd.add(g);
1153
+ const x0 = at(sideOf(w), w);
1154
+ let top = m.ty - 16;
1155
+ for (let k = 0; k < 8 && hits(x0, x0 + w, top - 8, top + 8); k++) top -= 18;
1156
+ spot = {
1157
+ x0,
1158
+ top,
1159
+ lw: w,
1160
+ lh: 16,
1161
+ lines: [m.text]
1162
+ };
1163
+ }
1164
+ }
1165
+ if (over) {
1166
+ labels.push(labelEl(m, spot.x0, spot.top, spot.lines, true, numberOn(m, spot)));
1167
+ return;
1168
+ }
1169
+ placed.push([
1170
+ spot.x0,
1171
+ spot.x0 + spot.lw,
1172
+ spot.top - spot.lh / 2 - 4,
1173
+ spot.top + spot.lh / 2 + 4,
1174
+ 6
1175
+ ]);
1176
+ wide = Math.max(wide, spot.x0 + spot.lw + PAD / 2 + 4);
1177
+ least = Math.min(least, spot.x0 - PAD / 2 - 4);
1178
+ labels.push(labelEl(m, spot.x0, spot.top, spot.lines, over));
1179
+ };
1180
+ marks.sort((m, n) => Number(!!m.up) - Number(!!n.up) || m.ty - n.ty || m.tx - n.tx).forEach((m) => place(m, false));
1181
+ later.forEach((m) => place(m, true));
1182
+ for (const o of numbered) labels.push(/* @__PURE__ */ jsx("span", {
1183
+ className: cx("ui-lg-num", o.m.dim && "is-dim", (hover === edgeId(o.m.e) || o.m.e === selEdge) && "is-on"),
1184
+ style: {
1185
+ left: o.x,
1186
+ top: o.y
1187
+ },
1188
+ "aria-hidden": "true",
1189
+ onPointerEnter: pickEdge ? () => setHover(edgeId(o.m.e)) : void 0,
1190
+ onPointerLeave: pickEdge ? () => setHover(null) : void 0,
1191
+ children: o.n
1192
+ }, "n" + o.m.idx));
1193
+ return {
1194
+ paths,
1195
+ labels,
1196
+ hitPaths,
1197
+ need,
1198
+ crowd,
1199
+ wide,
1200
+ least,
1201
+ covered,
1202
+ numbered
1203
+ };
1204
+ };
1205
+ for (const id in laneCount) {
1206
+ const g = layerIndex[id] - 1;
1207
+ if (g >= 0) gaps[g] = Math.max(gaps[g], laneCount[id] * LANE_H + 40);
1208
+ }
1209
+ const floor = gaps.slice();
1210
+ placeRows();
1211
+ let drawn = draw();
1212
+ const grows = () => [...drawn.need].filter((g) => gaps[g] < floor[g] + GROW_MAX);
1213
+ for (let k = 0; k < GROW_MAX / GROW && grows().length; k++) {
1214
+ for (const g of grows()) gaps[g] = Math.min(floor[g] + GROW_MAX, gaps[g] + GROW);
1215
+ placeRows();
1216
+ drawn = draw();
1217
+ }
1218
+ const stuck = [...drawn.need].filter((g) => gaps[g] >= floor[g] + GROW_MAX);
1219
+ if (stuck.length) {
1220
+ for (const g of stuck) gaps[g] = floor[g];
1221
+ placeRows();
1222
+ drawn = draw();
1223
+ const crowded = () => [...drawn.crowd].filter((g) => stuck.includes(g) && gaps[g] < floor[g] + GROW_MAX);
1224
+ for (let k = 0; k < GROW_MAX / GROW && crowded().length; k++) {
1225
+ for (const g of crowded()) gaps[g] = Math.min(floor[g] + GROW_MAX, gaps[g] + GROW);
1226
+ placeRows();
1227
+ drawn = draw();
1228
+ }
1229
+ }
1230
+ for (let k = 0; k < 3 && drawn.least < 0; k++) {
1231
+ const shift = Math.ceil(-drawn.least);
1232
+ for (const id in pos) pos[id].x += shift;
1233
+ W += shift;
1234
+ drawn = draw();
1235
+ }
1236
+ if (drawn.wide > W) {
1237
+ W = Math.ceil(drawn.wide);
1238
+ drawn = draw();
1239
+ }
1240
+ const { paths, labels, hitPaths, numbered } = drawn;
1241
+ const firstX = Math.min(...main.filter((n) => pos[n.id]).map((n) => boxOf(n.id).x), W);
1242
+ const selBox = sel != null && pos[sel] ? boxOf(sel) : null;
1243
+ const sizeText = (n) => withNum(p.sizeLabel, n, () => byCount(n, "1 個項目", "{n} 個項目"));
1244
+ const externalText = p.externalLabel ?? tr("repo 外");
1245
+ const useText = p.useLabel ?? tr("使用 {n} 次");
1246
+ const tagOf = (n) => n.tag ? /* @__PURE__ */ jsxs("span", {
1247
+ className: cx("ui-lg-tag", n.tagTone === "warning" && "is-warning"),
1248
+ children: [n.tagTone === "warning" ? /* @__PURE__ */ jsx(Icon, {
1249
+ name: "lock",
1250
+ size: 12
1251
+ }) : null, n.tag]
1252
+ }) : null;
1253
+ const nodes = main.map((n) => {
1254
+ const q = pos[n.id];
1255
+ const on = n.id === sel;
1256
+ const size = sizeOf(n);
1257
+ const used = selShared ? uses[selShared]?.[n.id] : void 0;
1258
+ return /* @__PURE__ */ jsxs("button", {
1259
+ type: "button",
1260
+ className: cx("ui-lg-node", n.external && "is-external", on && "is-selected", !near(n.id) && "is-dim"),
1261
+ onFocus: showWhole,
1262
+ style: {
1263
+ left: boxOf(n.id).x,
1264
+ top: q.y,
1265
+ width: boxOf(n.id).w,
1266
+ height: NH
1267
+ },
1268
+ "aria-pressed": p.onSelect ? on : void 0,
1269
+ onClick: p.onSelect ? () => pick(n.id, on) : void 0,
1270
+ children: [
1271
+ /* @__PURE__ */ jsxs("span", {
1272
+ className: "ui-lg-head",
1273
+ children: [
1274
+ /* @__PURE__ */ jsx("span", {
1275
+ className: cx("ui-lg-name", n.code && "is-code"),
1276
+ children: n.name || n.id
1277
+ }),
1278
+ tagLine ? null : tagOf(n),
1279
+ used ? /* @__PURE__ */ jsx("span", {
1280
+ className: "ui-lg-use",
1281
+ children: monoNums(useText.replace("{n}", ""), [used])
1282
+ }) : null
1283
+ ]
1284
+ }),
1285
+ tagLine ? tagOf(n) : null,
1286
+ n.external ? /* @__PURE__ */ jsx("span", {
1287
+ className: "ui-lg-ext",
1288
+ children: externalText
1289
+ }) : null,
1290
+ size != null ? /* @__PURE__ */ jsxs("span", {
1291
+ className: "ui-lg-size",
1292
+ children: [/* @__PURE__ */ jsx("span", {
1293
+ className: "ui-lg-track",
1294
+ "aria-hidden": "true",
1295
+ children: /* @__PURE__ */ jsx("span", { style: { width: Math.round(size / maxSize * 100) + "%" } })
1296
+ }), /* @__PURE__ */ jsx("span", {
1297
+ className: "ui-lg-count",
1298
+ children: monoNums(sizeText(size), [format.number(size)])
1299
+ })]
1300
+ }) : null
1301
+ ]
1302
+ }, n.id);
1303
+ });
1304
+ const sharedMeta = p.sharedMeta ?? tr("{a} 個項目使用,共 {b} 次");
1305
+ const sharedBoxes = shared.map((s) => {
1306
+ const by = uses[s.id] ?? {};
1307
+ const total = Object.values(by).reduce((a, b) => a + b, 0);
1308
+ const on = s.id === sel;
1309
+ const dim = !!selEdge || sel != null && !on && (selShared != null ? !(s.id in (uses[selShared] ?? {})) && !(selShared in by) : !(sel in by));
1310
+ return /* @__PURE__ */ jsxs("button", {
1311
+ type: "button",
1312
+ className: cx("ui-lg-node", "ui-lg-chip", on && "is-selected", dim && "is-dim"),
1313
+ onFocus: showWhole,
1314
+ "aria-pressed": p.onSelect ? on : void 0,
1315
+ onClick: p.onSelect ? () => pick(s.id, on) : void 0,
1316
+ children: [/* @__PURE__ */ jsxs("span", {
1317
+ className: "ui-lg-head",
1318
+ children: [/* @__PURE__ */ jsx("span", {
1319
+ className: cx("ui-lg-name", s.code && "is-code"),
1320
+ children: s.name || s.id
1321
+ }), tagOf(s)]
1322
+ }), /* @__PURE__ */ jsx("span", {
1323
+ className: "ui-lg-shared-meta",
1324
+ children: monoNums(sharedMeta.replace("{a}", "").replace("{b}", ""), [Object.keys(by).length, total])
1325
+ })]
1326
+ }, s.id);
1327
+ });
1328
+ const edgeText = (e) => lab(e) ? e.label ? tr("{label}({inferred})", {
1329
+ label: e.label,
1330
+ inferred: kindWord(e)
1331
+ }) : kindWord(e) : countText(e);
1332
+ const listItem = (key, on, dim, onClick, head, rest) => /* @__PURE__ */ jsxs("li", {
1333
+ className: cx("ui-lg-li", dim && "is-dim"),
1334
+ children: [onClick ? /* @__PURE__ */ jsx("button", {
1335
+ type: "button",
1336
+ className: cx("ui-lg-libtn", on && "is-selected"),
1337
+ "aria-pressed": on,
1338
+ onClick,
1339
+ children: head
1340
+ }) : /* @__PURE__ */ jsx("span", {
1341
+ className: "ui-lg-lihead",
1342
+ children: head
1343
+ }), rest]
1344
+ }, key);
1345
+ const nodeIds = new Set(all.map((n) => n.id));
1346
+ const list = /* @__PURE__ */ jsxs("div", {
1347
+ className: "ui-lg-list",
1348
+ children: [/* @__PURE__ */ jsxs("section", {
1349
+ "aria-labelledby": `${uid}-ln`,
1350
+ children: [/* @__PURE__ */ jsx("h3", {
1351
+ id: `${uid}-ln`,
1352
+ className: "ui-lg-listtitle",
1353
+ children: p.listLabels?.nodes ?? tr("項目")
1354
+ }), /* @__PURE__ */ jsx("ul", { children: all.map((n) => {
1355
+ const size = sizeOf(n);
1356
+ return listItem(n.id, n.id === sel, !near(n.id), p.onSelect ? () => pick(n.id, n.id === sel) : void 0, /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
1357
+ className: cx("ui-lg-liname", n.code && "ui-lg-code"),
1358
+ children: n.name || n.id
1359
+ }), tagOf(n)] }), n.external && !n.shared ? /* @__PURE__ */ jsxs("span", {
1360
+ className: "ui-lg-limeta",
1361
+ children: [tr(","), externalText]
1362
+ }) : size != null ? /* @__PURE__ */ jsxs("span", {
1363
+ className: "ui-lg-limeta",
1364
+ children: [tr(","), monoNums(sizeText(size), [format.number(size)])]
1365
+ }) : null);
1366
+ }) })]
1367
+ }), /* @__PURE__ */ jsxs("section", {
1368
+ "aria-labelledby": `${uid}-le`,
1369
+ children: [/* @__PURE__ */ jsx("h3", {
1370
+ id: `${uid}-le`,
1371
+ className: "ui-lg-listtitle",
1372
+ children: p.listLabels?.edges ?? tr("關係")
1373
+ }), /* @__PURE__ */ jsx("ul", { children: p.edges.filter((e) => nodeIds.has(e.from) && nodeIds.has(e.to)).map((e, i) => listItem(edgeId(e) + ":" + i, e === selListEdge, focus && !related(e) && !(selShared && e.to === selShared), pickEdge ? () => choose(e) : void 0, /* @__PURE__ */ jsxs(Fragment, { children: [
1374
+ /* @__PURE__ */ jsx("span", {
1375
+ className: "ui-lg-code",
1376
+ children: nameOf(e.from)
1377
+ }),
1378
+ " ",
1379
+ /* @__PURE__ */ jsx("span", {
1380
+ "aria-hidden": "true",
1381
+ children: "→"
1382
+ }),
1383
+ /* @__PURE__ */ jsx("span", {
1384
+ className: "ui-visually-hidden",
1385
+ children: tr("到")
1386
+ }),
1387
+ " ",
1388
+ /* @__PURE__ */ jsx("span", {
1389
+ className: "ui-lg-code",
1390
+ children: nameOf(e.to)
1391
+ }),
1392
+ /* @__PURE__ */ jsxs("span", {
1393
+ className: "ui-lg-limeta",
1394
+ children: [tr(":"), labelParts(edgeText(e))]
1395
+ })
1396
+ ] }), null)) })]
1397
+ })]
1398
+ });
1399
+ const showList = p.listView !== false && view === "list";
1400
+ const started = React.useRef("");
1401
+ React.useLayoutEffect(() => {
1402
+ const el = scrollRef.current;
1403
+ if (!el || showList || !fitted?.full || started.current === memKey) return;
1404
+ started.current = memKey;
1405
+ if (scrollMemory.get(memKey)) return;
1406
+ const x = selBox ? selBox.x + selBox.w / 2 - el.clientWidth / (2 * scale) : firstX - 16;
1407
+ el.scrollLeft = Math.max(0, x * scale);
1408
+ });
1409
+ const selX = selBox?.x;
1410
+ const selW = selBox?.w;
1411
+ React.useEffect(() => {
1412
+ const el = scrollRef.current;
1413
+ if (!el || showList || selX == null || selW == null) return;
1414
+ const l = selX * scale;
1415
+ const r = (selX + selW) * scale;
1416
+ if (l < el.scrollLeft) el.scrollLeft = Math.max(0, l - 16);
1417
+ else if (r > el.scrollLeft + el.clientWidth) el.scrollLeft = r - el.clientWidth + 16;
1418
+ }, [
1419
+ sel,
1420
+ selX,
1421
+ selW,
1422
+ scale,
1423
+ showList,
1424
+ scrollRef
1425
+ ]);
1426
+ const toggleShown = p.labelToggle !== false && !showList && p.edges.some((e) => lab(e));
1427
+ React.useLayoutEffect(() => {
1428
+ const el = scrollRef.current;
1429
+ if (!el) return;
1430
+ const measure = () => setAvail(el.clientWidth);
1431
+ measure();
1432
+ const ro = new ResizeObserver(measure);
1433
+ ro.observe(el);
1434
+ return () => ro.disconnect();
1435
+ }, [scrollRef, showList]);
1436
+ React.useLayoutEffect(() => {
1437
+ if (!avail || showList) return;
1438
+ if (!fitted) {
1439
+ if (W <= avail + .5) return;
1440
+ const base = p.nodeWidth || 200;
1441
+ const lose = W - avail - (cols - 1) * 16;
1442
+ const nw = Math.max(Math.min(base, 120), Math.floor(base - Math.max(0, lose) / cols));
1443
+ setFit({
1444
+ at: avail,
1445
+ nw,
1446
+ col: 24,
1447
+ scale: 1
1448
+ });
1449
+ return;
1450
+ }
1451
+ if (fitted.full) return;
1452
+ const s = Math.floor(avail / W * 1e3) / 1e3;
1453
+ if (W > avail + .5 && s < .75) {
1454
+ setFit({
1455
+ ...fitted,
1456
+ nw: p.nodeWidth || 200,
1457
+ col: 40,
1458
+ scale: 1,
1459
+ full: true
1460
+ });
1461
+ return;
1462
+ }
1463
+ const want = W <= avail + .5 ? 1 : s;
1464
+ if (want !== fitted.scale) setFit({
1465
+ ...fitted,
1466
+ scale: want
1467
+ });
1468
+ }, [
1469
+ avail,
1470
+ showList,
1471
+ fitted,
1472
+ W,
1473
+ p.nodeWidth,
1474
+ cols
1475
+ ]);
1476
+ const coveredNow = drawn.covered;
1477
+ React.useLayoutEffect(() => {
1478
+ if (coveredNow && spread < 5) setSpread({
1479
+ key: spreadKey,
1480
+ n: spread + 1
1481
+ });
1482
+ }, [
1483
+ coveredNow,
1484
+ spread,
1485
+ spreadKey
1486
+ ]);
1487
+ const drawnH = H * scale;
1488
+ const naturalH = drawnH - Math.max(0, dh);
1489
+ const frameH = p.resizable && dh < 0 ? Math.max(Math.min(MIN_FRAME, naturalH), naturalH + dh) : null;
1490
+ const dragTo = (v) => Math.max(Math.min(MIN_FRAME, naturalH) - naturalH, Math.min(v, between ? MAX_EXTRA * between * scale : 0));
1491
+ return /* @__PURE__ */ jsxs("div", {
1492
+ className: cx("ui-graph ui-lg", p.className),
1493
+ children: [
1494
+ p.listView === false && !toggleShown && !p.toolbar ? null : /* @__PURE__ */ jsxs("div", {
1495
+ className: "ui-lg-bar",
1496
+ children: [
1497
+ p.toolbar ? /* @__PURE__ */ jsx("div", {
1498
+ className: "ui-lg-toolbar",
1499
+ children: p.toolbar
1500
+ }) : null,
1501
+ toggleShown && p.labelToggle === "icon" ? /* @__PURE__ */ jsx(IconButton, {
1502
+ className: "ui-lg-labels-btn",
1503
+ icon: "tag",
1504
+ filled: labelsOn,
1505
+ label: tr("顯示線上文字"),
1506
+ "aria-pressed": labelsOn,
1507
+ onClick: switchLabels
1508
+ }) : toggleShown ? /* @__PURE__ */ jsxs("label", {
1509
+ className: "ui-lg-labels-switch",
1510
+ children: [/* @__PURE__ */ jsx(Switch, {
1511
+ checked: labelsOn,
1512
+ onChange: switchLabels,
1513
+ label: tr("線上文字")
1514
+ }), /* @__PURE__ */ jsx("span", {
1515
+ "aria-hidden": "true",
1516
+ children: tr("線上文字")
1517
+ })]
1518
+ }) : null,
1519
+ p.listView === false ? null : /* @__PURE__ */ jsx(Tabs, {
1520
+ label: tr("顯示方式"),
1521
+ value: view,
1522
+ onChange: setView,
1523
+ items: [{
1524
+ id: "graph",
1525
+ label: tr("圖")
1526
+ }, {
1527
+ id: "list",
1528
+ label: tr("清單")
1529
+ }]
1530
+ })
1531
+ ]
1532
+ }),
1533
+ showList ? list : null,
1534
+ /* @__PURE__ */ jsx("div", {
1535
+ className: cx("ui-lg-scroller", scrollMore && "has-more", showList && "is-hidden"),
1536
+ children: /* @__PURE__ */ jsx("div", {
1537
+ className: cx("ui-lg-scroll", frameH != null && "is-framed"),
1538
+ ref: scrollRef,
1539
+ onScroll: onScrollKeep,
1540
+ style: frameH != null ? { height: frameH } : void 0,
1541
+ children: /* @__PURE__ */ jsxs("div", {
1542
+ className: "ui-lg-canvas",
1543
+ style: scale === 1 ? {
1544
+ width: W,
1545
+ height: H
1546
+ } : {
1547
+ width: W,
1548
+ height: H,
1549
+ transform: `scale(${scale})`,
1550
+ transformOrigin: "0 0",
1551
+ marginRight: W * (scale - 1),
1552
+ marginBottom: H * (scale - 1),
1553
+ "--lg-scale": scale
1554
+ },
1555
+ role: "group",
1556
+ "aria-label": p.label || tr("架構圖"),
1557
+ onClick: pickEdge && p.selectedEdge != null ? () => pickEdge(null) : void 0,
1558
+ children: [
1559
+ /* @__PURE__ */ jsx("svg", {
1560
+ width: W,
1561
+ height: H,
1562
+ viewBox: `0 0 ${W} ${H}`,
1563
+ "aria-hidden": "true",
1564
+ children: paths
1565
+ }),
1566
+ nodes,
1567
+ labels,
1568
+ hitPaths.length && !pickEdge ? /* @__PURE__ */ jsx("svg", {
1569
+ className: "ui-lg-hits",
1570
+ width: W,
1571
+ height: H,
1572
+ viewBox: `0 0 ${W} ${H}`,
1573
+ "aria-hidden": "true",
1574
+ children: hitPaths
1575
+ }) : hitPaths.length ? /* @__PURE__ */ jsx("svg", {
1576
+ className: "ui-lg-hits",
1577
+ width: W,
1578
+ height: H,
1579
+ viewBox: `0 0 ${W} ${H}`,
1580
+ role: "group",
1581
+ "aria-label": tr("關係"),
1582
+ children: hitPaths
1583
+ }) : null
1584
+ ]
1585
+ })
1586
+ })
1587
+ }),
1588
+ p.resizable && !showList ? /* @__PURE__ */ jsx(HeightHandle, {
1589
+ value: Math.round(drawnH + Math.min(0, dh)),
1590
+ min: Math.round(Math.min(MIN_FRAME, drawnH)),
1591
+ max: Math.round(drawnH - Math.max(0, dh) + MAX_EXTRA * between * scale),
1592
+ onDrag: (d) => setDh(dragTo(d)),
1593
+ onKey: (step) => setDh(dragTo(dh + step)),
1594
+ onReset: () => setDh(0),
1595
+ start: () => dh
1596
+ }) : null,
1597
+ showList ? null : /* @__PURE__ */ jsx(ScrollHint, {
1598
+ show: overflows,
1599
+ done: scrolled
1600
+ }),
1601
+ showList || !numbered.length ? null : /* @__PURE__ */ jsx("ol", {
1602
+ className: "ui-lg-numlist",
1603
+ "aria-label": tr("編號的線"),
1604
+ children: numbered.map((o) => /* @__PURE__ */ jsxs("li", {
1605
+ className: cx(o.m.dim && "is-dim"),
1606
+ children: [/* @__PURE__ */ jsx("span", {
1607
+ className: "ui-lg-num is-static",
1608
+ "aria-hidden": "true",
1609
+ children: o.n
1610
+ }), /* @__PURE__ */ jsx("span", { children: labelParts(o.m.text) })]
1611
+ }, o.n))
1612
+ }),
1613
+ shared.length && !showList ? /* @__PURE__ */ jsxs("div", {
1614
+ className: "ui-lg-shared",
1615
+ children: [/* @__PURE__ */ jsx("div", {
1616
+ className: "ui-lg-shared-title",
1617
+ children: p.sharedLabel || tr("共用項目")
1618
+ }), /* @__PURE__ */ jsx("div", {
1619
+ className: "ui-lg-chips",
1620
+ children: sharedBoxes
1621
+ })]
1622
+ }) : null,
1623
+ showList || p.legend === false || !p.legendItems && !edges.some((e) => pos[e.from] && pos[e.to]) ? null : /* @__PURE__ */ jsx(GraphLegend, { items: p.legendItems || [
1624
+ ...edges.some((e) => !lab(e) && pos[e.from] && pos[e.to]) ? [{
1625
+ type: "weight",
1626
+ label: "次數越多線越粗"
1627
+ }] : [],
1628
+ ...edges.some((e) => e.inferred && !e.declared && pos[e.from] && pos[e.to]) ? [{
1629
+ type: "inferred",
1630
+ label: p.inferredLabel || "推測的關係",
1631
+ text: p.inferredText
1632
+ }] : [],
1633
+ ...edges.some((e) => e.declared && pos[e.from] && pos[e.to]) ? [{
1634
+ type: "declared",
1635
+ label: p.declaredLegend || "專案宣告的關係",
1636
+ text: p.declaredText
1637
+ }] : []
1638
+ ] })
1639
+ ]
1640
+ });
1641
+ }
1642
+ export { LayerGraph };
1643
+
1644
+ //# sourceMappingURL=LayerGraph.js.map