@zonsh/ui 0.0.0 → 0.2.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 (388) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -1
  3. package/assets/illustrations/drawing/bracket-construction-dark.svg +77 -0
  4. package/assets/illustrations/drawing/bracket-construction-filled-dark.svg +50 -0
  5. package/assets/illustrations/drawing/bracket-construction-filled.svg +50 -0
  6. package/assets/illustrations/drawing/bracket-construction.svg +77 -0
  7. package/assets/illustrations/drawing/crescent-dark.svg +28 -0
  8. package/assets/illustrations/drawing/crescent-guides-dark.svg +33 -0
  9. package/assets/illustrations/drawing/crescent-guides.svg +33 -0
  10. package/assets/illustrations/drawing/crescent.svg +28 -0
  11. package/assets/illustrations/drawing/eclipse-dark.svg +187 -0
  12. package/assets/illustrations/drawing/eclipse-guides-dark.svg +191 -0
  13. package/assets/illustrations/drawing/eclipse-guides.svg +191 -0
  14. package/assets/illustrations/drawing/eclipse.svg +187 -0
  15. package/assets/illustrations/drawing/elevation-guides-dark.svg +31 -0
  16. package/assets/illustrations/drawing/elevation-guides-plain-dark.svg +9 -0
  17. package/assets/illustrations/drawing/elevation-guides-plain.svg +9 -0
  18. package/assets/illustrations/drawing/elevation-guides.svg +31 -0
  19. package/assets/illustrations/drawing/horizon-dark.svg +30 -0
  20. package/assets/illustrations/drawing/horizon.svg +30 -0
  21. package/assets/illustrations/drawing/nib-study-dark.svg +107 -0
  22. package/assets/illustrations/drawing/nib-study-plain-dark.svg +93 -0
  23. package/assets/illustrations/drawing/nib-study-plain.svg +93 -0
  24. package/assets/illustrations/drawing/nib-study.svg +107 -0
  25. package/assets/illustrations/editorial/assistant-640.webp +0 -0
  26. package/assets/illustrations/editorial/assistant.webp +0 -0
  27. package/assets/illustrations/editorial/automation-640.webp +0 -0
  28. package/assets/illustrations/editorial/automation.webp +0 -0
  29. package/assets/illustrations/editorial/bracket-left-640.webp +0 -0
  30. package/assets/illustrations/editorial/bracket-left.webp +0 -0
  31. package/assets/illustrations/editorial/bracket-right-640.webp +0 -0
  32. package/assets/illustrations/editorial/bracket-right.webp +0 -0
  33. package/assets/illustrations/editorial/custom-software-640.webp +0 -0
  34. package/assets/illustrations/editorial/custom-software.webp +0 -0
  35. package/assets/illustrations/editorial/digitalization-640.webp +0 -0
  36. package/assets/illustrations/editorial/digitalization.webp +0 -0
  37. package/assets/illustrations/editorial/integration-640.webp +0 -0
  38. package/assets/illustrations/editorial/integration.webp +0 -0
  39. package/assets/illustrations/editorial/problem-640.webp +0 -0
  40. package/assets/illustrations/editorial/problem.webp +0 -0
  41. package/assets/illustrations/editorial/process-analysis-640.webp +0 -0
  42. package/assets/illustrations/editorial/process-analysis.webp +0 -0
  43. package/assets/illustrations/editorial/process-concept-640.webp +0 -0
  44. package/assets/illustrations/editorial/process-concept.webp +0 -0
  45. package/assets/illustrations/editorial/process-development-640.webp +0 -0
  46. package/assets/illustrations/editorial/process-development.webp +0 -0
  47. package/assets/illustrations/editorial/process-discovery-640.webp +0 -0
  48. package/assets/illustrations/editorial/process-discovery.webp +0 -0
  49. package/assets/illustrations/editorial/process-maintenance-640.webp +0 -0
  50. package/assets/illustrations/editorial/process-maintenance.webp +0 -0
  51. package/assets/illustrations/editorial/process-prototype-640.webp +0 -0
  52. package/assets/illustrations/editorial/process-prototype.webp +0 -0
  53. package/assets/illustrations/editorial/process-testing-640.webp +0 -0
  54. package/assets/illustrations/editorial/process-testing.webp +0 -0
  55. package/assets/illustrations/iso/automation-dark.svg +6 -0
  56. package/assets/illustrations/iso/automation.svg +6 -0
  57. package/assets/illustrations/iso/bar-chart-dark.svg +6 -0
  58. package/assets/illustrations/iso/bar-chart.svg +6 -0
  59. package/assets/illustrations/iso/brackets-classic-dark.svg +6 -0
  60. package/assets/illustrations/iso/brackets-classic.svg +6 -0
  61. package/assets/illustrations/iso/brackets-dark.svg +6 -0
  62. package/assets/illustrations/iso/brackets.svg +6 -0
  63. package/assets/illustrations/iso/city-dark.svg +6 -0
  64. package/assets/illustrations/iso/city.svg +6 -0
  65. package/assets/illustrations/iso/conveyor-dark.svg +6 -0
  66. package/assets/illustrations/iso/conveyor.svg +6 -0
  67. package/assets/illustrations/iso/database-dark.svg +6 -0
  68. package/assets/illustrations/iso/database.svg +6 -0
  69. package/assets/illustrations/iso/documents-dark.svg +6 -0
  70. package/assets/illustrations/iso/documents.svg +6 -0
  71. package/assets/illustrations/iso/inbox-dark.svg +6 -0
  72. package/assets/illustrations/iso/inbox.svg +6 -0
  73. package/assets/illustrations/iso/laptop-dark.svg +6 -0
  74. package/assets/illustrations/iso/laptop.svg +6 -0
  75. package/assets/illustrations/iso/monitor-dark.svg +6 -0
  76. package/assets/illustrations/iso/monitor.svg +6 -0
  77. package/assets/illustrations/iso/pipeline-dark.svg +6 -0
  78. package/assets/illustrations/iso/pipeline.svg +6 -0
  79. package/assets/illustrations/iso/platform-dark.svg +6 -0
  80. package/assets/illustrations/iso/platform.svg +6 -0
  81. package/assets/illustrations/iso/server-dark.svg +6 -0
  82. package/assets/illustrations/iso/server.svg +6 -0
  83. package/assets/illustrations/iso/spreadsheet-dark.svg +6 -0
  84. package/assets/illustrations/iso/spreadsheet.svg +6 -0
  85. package/assets/illustrations/iso/timeline-dark.svg +6 -0
  86. package/assets/illustrations/iso/timeline.svg +6 -0
  87. package/assets/illustrations/sheet/construction.svg +115 -0
  88. package/assets/illustrations/sheet/crescent.svg +40 -0
  89. package/assets/illustrations/sheet/limb.svg +42 -0
  90. package/assets/illustrations/sheet/stress-axis.svg +119 -0
  91. package/assets/illustrations/sheet/totality.svg +215 -0
  92. package/assets/illustrations/sheet/vertical-metrics.svg +43 -0
  93. package/assets/logo-left.svg +1 -0
  94. package/assets/logo-right.svg +1 -0
  95. package/assets/logo.svg +1 -0
  96. package/dist/components/_overlay.d.ts +47 -0
  97. package/dist/components/_overlay.js +59 -0
  98. package/dist/components/accordion.d.ts +32 -0
  99. package/dist/components/accordion.js +39 -0
  100. package/dist/components/alert-dialog.d.ts +45 -0
  101. package/dist/components/alert-dialog.js +56 -0
  102. package/dist/components/alert.d.ts +35 -0
  103. package/dist/components/alert.js +42 -0
  104. package/dist/components/ascii-field.d.ts +34 -0
  105. package/dist/components/ascii-field.js +410 -0
  106. package/dist/components/aspect-ratio.d.ts +14 -0
  107. package/dist/components/aspect-ratio.js +17 -0
  108. package/dist/components/avatar.d.ts +42 -0
  109. package/dist/components/avatar.js +55 -0
  110. package/dist/components/badge.d.ts +70 -0
  111. package/dist/components/badge.js +62 -0
  112. package/dist/components/breadcrumb.d.ts +22 -0
  113. package/dist/components/breadcrumb.js +32 -0
  114. package/dist/components/button-group.d.ts +30 -0
  115. package/dist/components/button-group.js +47 -0
  116. package/dist/components/button.d.ts +53 -0
  117. package/dist/components/button.js +130 -0
  118. package/dist/components/calendar.d.ts +26 -0
  119. package/dist/components/calendar.js +164 -0
  120. package/dist/components/card.d.ts +42 -0
  121. package/dist/components/card.js +76 -0
  122. package/dist/components/carousel.d.ts +90 -0
  123. package/dist/components/carousel.js +213 -0
  124. package/dist/components/chart.d.ts +180 -0
  125. package/dist/components/chart.js +286 -0
  126. package/dist/components/checkbox.d.ts +23 -0
  127. package/dist/components/checkbox.js +43 -0
  128. package/dist/components/code-block.d.ts +45 -0
  129. package/dist/components/code-block.js +58 -0
  130. package/dist/components/code-highlight.d.ts +13 -0
  131. package/dist/components/code-highlight.js +107 -0
  132. package/dist/components/collapsible.d.ts +20 -0
  133. package/dist/components/collapsible.js +32 -0
  134. package/dist/components/color-picker.d.ts +85 -0
  135. package/dist/components/color-picker.js +407 -0
  136. package/dist/components/combobox.d.ts +81 -0
  137. package/dist/components/combobox.js +100 -0
  138. package/dist/components/command.d.ts +112 -0
  139. package/dist/components/command.js +212 -0
  140. package/dist/components/context-menu.d.ts +29 -0
  141. package/dist/components/context-menu.js +35 -0
  142. package/dist/components/conversation.d.ts +27 -0
  143. package/dist/components/conversation.js +293 -0
  144. package/dist/components/copy-button.d.ts +46 -0
  145. package/dist/components/copy-button.js +118 -0
  146. package/dist/components/data-table.d.ts +175 -0
  147. package/dist/components/data-table.js +302 -0
  148. package/dist/components/date-picker.d.ts +91 -0
  149. package/dist/components/date-picker.js +207 -0
  150. package/dist/components/dialog.d.ts +48 -0
  151. package/dist/components/dialog.js +92 -0
  152. package/dist/components/direction.d.ts +16 -0
  153. package/dist/components/direction.js +18 -0
  154. package/dist/components/drawer.d.ts +60 -0
  155. package/dist/components/drawer.js +76 -0
  156. package/dist/components/empty.d.ts +31 -0
  157. package/dist/components/empty.js +50 -0
  158. package/dist/components/feature-list.d.ts +54 -0
  159. package/dist/components/feature-list.js +43 -0
  160. package/dist/components/field.d.ts +15 -0
  161. package/dist/components/field.js +36 -0
  162. package/dist/components/file-drop.d.ts +55 -0
  163. package/dist/components/file-drop.js +197 -0
  164. package/dist/components/filter-bar.d.ts +106 -0
  165. package/dist/components/filter-bar.js +296 -0
  166. package/dist/components/form.d.ts +33 -0
  167. package/dist/components/form.js +34 -0
  168. package/dist/components/graph.d.ts +105 -0
  169. package/dist/components/graph.js +786 -0
  170. package/dist/components/illustration.d.ts +85 -0
  171. package/dist/components/illustration.js +165 -0
  172. package/dist/components/input-group.d.ts +127 -0
  173. package/dist/components/input-group.js +292 -0
  174. package/dist/components/input.d.ts +16 -0
  175. package/dist/components/input.js +25 -0
  176. package/dist/components/item.d.ts +64 -0
  177. package/dist/components/item.js +116 -0
  178. package/dist/components/kbd.d.ts +33 -0
  179. package/dist/components/kbd.js +38 -0
  180. package/dist/components/label.d.ts +12 -0
  181. package/dist/components/label.js +24 -0
  182. package/dist/components/layout.d.ts +136 -0
  183. package/dist/components/layout.js +162 -0
  184. package/dist/components/logo.d.ts +54 -0
  185. package/dist/components/logo.js +96 -0
  186. package/dist/components/menu.d.ts +60 -0
  187. package/dist/components/menu.js +138 -0
  188. package/dist/components/menubar.d.ts +62 -0
  189. package/dist/components/menubar.js +223 -0
  190. package/dist/components/message.d.ts +42 -0
  191. package/dist/components/message.js +56 -0
  192. package/dist/components/meter.d.ts +31 -0
  193. package/dist/components/meter.js +25 -0
  194. package/dist/components/native-select.d.ts +26 -0
  195. package/dist/components/native-select.js +35 -0
  196. package/dist/components/navigation-menu.d.ts +42 -0
  197. package/dist/components/navigation-menu.js +97 -0
  198. package/dist/components/number-field.d.ts +36 -0
  199. package/dist/components/number-field.js +153 -0
  200. package/dist/components/otp-field.d.ts +35 -0
  201. package/dist/components/otp-field.js +94 -0
  202. package/dist/components/pagination.d.ts +31 -0
  203. package/dist/components/pagination.js +70 -0
  204. package/dist/components/pdf-viewer.d.ts +69 -0
  205. package/dist/components/pdf-viewer.js +929 -0
  206. package/dist/components/popover.d.ts +33 -0
  207. package/dist/components/popover.js +48 -0
  208. package/dist/components/preview-card.d.ts +25 -0
  209. package/dist/components/preview-card.js +22 -0
  210. package/dist/components/progress.d.ts +27 -0
  211. package/dist/components/progress.js +23 -0
  212. package/dist/components/prompt-input.d.ts +131 -0
  213. package/dist/components/prompt-input.js +403 -0
  214. package/dist/components/quote.d.ts +22 -0
  215. package/dist/components/quote.js +15 -0
  216. package/dist/components/radio-group.d.ts +18 -0
  217. package/dist/components/radio-group.js +34 -0
  218. package/dist/components/reasoning.d.ts +31 -0
  219. package/dist/components/reasoning.js +70 -0
  220. package/dist/components/resizable.d.ts +38 -0
  221. package/dist/components/resizable.js +41 -0
  222. package/dist/components/response.d.ts +30 -0
  223. package/dist/components/response.js +538 -0
  224. package/dist/components/scroll-area.d.ts +33 -0
  225. package/dist/components/scroll-area.js +31 -0
  226. package/dist/components/select.d.ts +35 -0
  227. package/dist/components/select.js +60 -0
  228. package/dist/components/separator.d.ts +14 -0
  229. package/dist/components/separator.js +17 -0
  230. package/dist/components/sidebar.d.ts +147 -0
  231. package/dist/components/sidebar.js +489 -0
  232. package/dist/components/site-header.d.ts +59 -0
  233. package/dist/components/site-header.js +67 -0
  234. package/dist/components/skeleton.d.ts +31 -0
  235. package/dist/components/skeleton.js +29 -0
  236. package/dist/components/slider.d.ts +24 -0
  237. package/dist/components/slider.js +129 -0
  238. package/dist/components/sources.d.ts +25 -0
  239. package/dist/components/sources.js +35 -0
  240. package/dist/components/spinner.d.ts +36 -0
  241. package/dist/components/spinner.js +72 -0
  242. package/dist/components/suggestions.d.ts +20 -0
  243. package/dist/components/suggestions.js +18 -0
  244. package/dist/components/switch.d.ts +14 -0
  245. package/dist/components/switch.js +26 -0
  246. package/dist/components/table.d.ts +162 -0
  247. package/dist/components/table.js +758 -0
  248. package/dist/components/tabs.d.ts +25 -0
  249. package/dist/components/tabs.js +162 -0
  250. package/dist/components/tag.d.ts +41 -0
  251. package/dist/components/tag.js +88 -0
  252. package/dist/components/tags-input.d.ts +40 -0
  253. package/dist/components/tags-input.js +239 -0
  254. package/dist/components/textarea.d.ts +13 -0
  255. package/dist/components/textarea.js +16 -0
  256. package/dist/components/theme.d.ts +41 -0
  257. package/dist/components/theme.js +112 -0
  258. package/dist/components/time-field.d.ts +51 -0
  259. package/dist/components/time-field.js +437 -0
  260. package/dist/components/timeline.d.ts +76 -0
  261. package/dist/components/timeline.js +99 -0
  262. package/dist/components/toast.d.ts +72 -0
  263. package/dist/components/toast.js +196 -0
  264. package/dist/components/toggle-group.d.ts +41 -0
  265. package/dist/components/toggle-group.js +140 -0
  266. package/dist/components/toggle.d.ts +23 -0
  267. package/dist/components/toggle.js +35 -0
  268. package/dist/components/tool-call.d.ts +52 -0
  269. package/dist/components/tool-call.js +57 -0
  270. package/dist/components/toolbar.d.ts +17 -0
  271. package/dist/components/toolbar.js +34 -0
  272. package/dist/components/tooltip.d.ts +42 -0
  273. package/dist/components/tooltip.js +47 -0
  274. package/dist/components/tree.d.ts +75 -0
  275. package/dist/components/tree.js +636 -0
  276. package/dist/components/typography.d.ts +134 -0
  277. package/dist/components/typography.js +176 -0
  278. package/dist/components/video-player.d.ts +276 -0
  279. package/dist/components/video-player.js +1352 -0
  280. package/dist/components/whiteboard.d.ts +80 -0
  281. package/dist/components/whiteboard.js +389 -0
  282. package/dist/index.d.ts +85 -0
  283. package/dist/index.js +86 -0
  284. package/dist/lib/cn.d.ts +20 -0
  285. package/dist/lib/cn.js +38 -0
  286. package/dist/lib/code-highlight.d.ts +31 -0
  287. package/dist/lib/code-highlight.js +24 -0
  288. package/dist/lib/code-theme.d.ts +19 -0
  289. package/dist/lib/code-theme.js +140 -0
  290. package/dist/lib/collapse-row.d.ts +9 -0
  291. package/dist/lib/collapse-row.js +129 -0
  292. package/dist/lib/digit-roll.d.ts +21 -0
  293. package/dist/lib/digit-roll.js +31 -0
  294. package/dist/lib/editorial-assets.d.ts +16 -0
  295. package/dist/lib/editorial-assets.js +56 -0
  296. package/dist/lib/figure/catalog.d.ts +127 -0
  297. package/dist/lib/figure/catalog.js +130 -0
  298. package/dist/lib/figure/figures/automation.d.ts +7 -0
  299. package/dist/lib/figure/figures/automation.js +143 -0
  300. package/dist/lib/figure/figures/bar-chart.d.ts +7 -0
  301. package/dist/lib/figure/figures/bar-chart.js +99 -0
  302. package/dist/lib/figure/figures/brackets-classic.d.ts +11 -0
  303. package/dist/lib/figure/figures/brackets-classic.js +170 -0
  304. package/dist/lib/figure/figures/brackets.d.ts +8 -0
  305. package/dist/lib/figure/figures/brackets.js +84 -0
  306. package/dist/lib/figure/figures/city.d.ts +7 -0
  307. package/dist/lib/figure/figures/city.js +93 -0
  308. package/dist/lib/figure/figures/conveyor.d.ts +7 -0
  309. package/dist/lib/figure/figures/conveyor.js +97 -0
  310. package/dist/lib/figure/figures/database.d.ts +7 -0
  311. package/dist/lib/figure/figures/database.js +65 -0
  312. package/dist/lib/figure/figures/documents.d.ts +7 -0
  313. package/dist/lib/figure/figures/documents.js +83 -0
  314. package/dist/lib/figure/figures/inbox.d.ts +7 -0
  315. package/dist/lib/figure/figures/inbox.js +92 -0
  316. package/dist/lib/figure/figures/laptop.d.ts +7 -0
  317. package/dist/lib/figure/figures/laptop.js +67 -0
  318. package/dist/lib/figure/figures/monitor.d.ts +7 -0
  319. package/dist/lib/figure/figures/monitor.js +59 -0
  320. package/dist/lib/figure/figures/pipeline.d.ts +8 -0
  321. package/dist/lib/figure/figures/pipeline.js +117 -0
  322. package/dist/lib/figure/figures/platform.d.ts +7 -0
  323. package/dist/lib/figure/figures/platform.js +117 -0
  324. package/dist/lib/figure/figures/server.d.ts +7 -0
  325. package/dist/lib/figure/figures/server.js +115 -0
  326. package/dist/lib/figure/figures/spreadsheet.d.ts +7 -0
  327. package/dist/lib/figure/figures/spreadsheet.js +87 -0
  328. package/dist/lib/figure/figures/timeline.d.ts +7 -0
  329. package/dist/lib/figure/figures/timeline.js +65 -0
  330. package/dist/lib/figure/kernel.d.ts +152 -0
  331. package/dist/lib/figure/kernel.js +576 -0
  332. package/dist/lib/figure/parts.d.ts +42 -0
  333. package/dist/lib/figure/parts.js +126 -0
  334. package/dist/lib/form-reset.d.ts +11 -0
  335. package/dist/lib/form-reset.js +22 -0
  336. package/dist/lib/glide.d.ts +53 -0
  337. package/dist/lib/glide.js +138 -0
  338. package/dist/lib/graph-layout.d.ts +58 -0
  339. package/dist/lib/graph-layout.js +200 -0
  340. package/dist/lib/illustration-drawings.d.ts +89 -0
  341. package/dist/lib/illustration-drawings.js +539 -0
  342. package/dist/lib/illustration-info.d.ts +37 -0
  343. package/dist/lib/illustration-info.js +22 -0
  344. package/dist/lib/illustration-library.d.ts +87 -0
  345. package/dist/lib/illustration-library.js +352 -0
  346. package/dist/lib/logo-geometry.d.ts +29 -0
  347. package/dist/lib/logo-geometry.js +67 -0
  348. package/dist/lib/markdown-guard.d.ts +16 -0
  349. package/dist/lib/markdown-guard.js +123 -0
  350. package/dist/lib/merge-refs.d.ts +10 -0
  351. package/dist/lib/merge-refs.js +26 -0
  352. package/dist/lib/motion.d.ts +6 -0
  353. package/dist/lib/motion.js +12 -0
  354. package/dist/lib/pdf-worker.d.ts +1 -0
  355. package/dist/lib/pdf-worker.js +6 -0
  356. package/dist/lib/pdf.d.ts +19 -0
  357. package/dist/lib/pdf.js +58 -0
  358. package/dist/lib/platform.d.ts +33 -0
  359. package/dist/lib/platform.js +68 -0
  360. package/dist/lib/room.d.ts +25 -0
  361. package/dist/lib/room.js +46 -0
  362. package/dist/lib/table-fit.d.ts +143 -0
  363. package/dist/lib/table-fit.js +577 -0
  364. package/dist/lib/theme-script.d.ts +18 -0
  365. package/dist/lib/theme-script.js +29 -0
  366. package/dist/styles/expressive.css +188 -0
  367. package/dist/styles/fonts.css +145 -0
  368. package/dist/styles/index.css +206 -0
  369. package/dist/styles/material.css +313 -0
  370. package/dist/styles/parts/ai.css +360 -0
  371. package/dist/styles/parts/brand.css +75 -0
  372. package/dist/styles/parts/controls.css +725 -0
  373. package/dist/styles/parts/data.css +222 -0
  374. package/dist/styles/parts/editorial.css +120 -0
  375. package/dist/styles/parts/feedback.css +273 -0
  376. package/dist/styles/parts/foundations.css +166 -0
  377. package/dist/styles/parts/graph.css +214 -0
  378. package/dist/styles/parts/inputs.css +261 -0
  379. package/dist/styles/parts/isometric.css +124 -0
  380. package/dist/styles/parts/navigation.css +232 -0
  381. package/dist/styles/parts/overlays.css +250 -0
  382. package/dist/styles/parts/pdf.css +154 -0
  383. package/dist/styles/parts/react-flow.css +519 -0
  384. package/dist/styles/parts/whiteboard.css +855 -0
  385. package/dist/styles/tokens.css +290 -0
  386. package/dist/vite.d.ts +116 -0
  387. package/dist/vite.js +129 -0
  388. package/package.json +188 -5
@@ -0,0 +1,126 @@
1
+ /*
2
+ * Shared parts for the figures: the zon mark, shapes drawn on a face, pulses along a line.
3
+ */
4
+ import { line, rrect } from "./kernel.js";
5
+ /* ── The mark (exact logo geometry, in stroke units: one unit = one bracket stroke) ── */
6
+ const STROKE = 36.773437;
7
+ const u = (n) => n / STROKE;
8
+ /** The mark's height and width. */
9
+ export const MARK_H = 264.53125 / STROKE;
10
+ export const MARK_W = u(262.46875);
11
+ /** The brackets as boxes in the x–z plane: [x0, x1, z0, z1] — a stem and an arm each. */
12
+ export const BRACKETS = (() => {
13
+ const lsx = u(56.4375);
14
+ const lArmTop = MARK_H - u(56.355469);
15
+ const rsx = u(169.339844);
16
+ const rArmX = u(169.257813 + 93.210937);
17
+ const rArmTop = MARK_H - u(112.808594);
18
+ const rBottom = MARK_H - u(262.378906);
19
+ return {
20
+ left: { stem: [lsx, lsx + 1, 0, MARK_H], arm: [0, lsx, lArmTop - 1, lArmTop] },
21
+ right: { stem: [rsx, rsx + 1, rBottom, MARK_H], arm: [rsx + 1, rArmX, rArmTop - 1, rArmTop] },
22
+ };
23
+ })();
24
+ /** The mark as a relief on a flat face: two bracket outlines, `size` tall, from (u0, v0) in face units. */
25
+ export function markOutline(size) {
26
+ const k = size / MARK_H;
27
+ const shapes = [];
28
+ for (const side of [BRACKETS.left, BRACKETS.right]) {
29
+ const [sx0, sx1, sz0, sz1] = side.stem;
30
+ const [ax0, ax1, az0, az1] = side.arm;
31
+ // An L as one outline: stem with the arm joined on, its own corners kept (rule 09, for a mark).
32
+ const pts = side === BRACKETS.left
33
+ ? [
34
+ [sx0, sz0],
35
+ [sx1, sz0],
36
+ [sx1, sz1],
37
+ [sx0, sz1],
38
+ [sx0, az1],
39
+ [ax0, az1],
40
+ [ax0, az0],
41
+ [sx0, az0],
42
+ ]
43
+ : [
44
+ [sx0, sz0],
45
+ [sx1, sz0],
46
+ [sx1, az0],
47
+ [ax1, az0],
48
+ [ax1, az1],
49
+ [sx1, az1],
50
+ [sx1, sz1],
51
+ [sx0, sz1],
52
+ ];
53
+ // Face coordinates: u across, v down the face (the mark's top towards v = 0).
54
+ shapes.push(pts.map(([x, z]) => [x * k, (MARK_H - z) * k]));
55
+ }
56
+ return shapes;
57
+ }
58
+ /** The +y face (the front, lower left) at y, from x0 and base z0: u along x, v up. */
59
+ export const frontFace = (cam, x0, y, z0) => (a, b) => cam.P(x0 + a, y, z0 + b);
60
+ /** The +x face (lower right) at x, from y0 and base z0: u along y, v up. */
61
+ export const sideFace = (cam, x, y0, z0) => (a, b) => cam.P(x, y0 + a, z0 + b);
62
+ /** A top face at height z, from (x0, y0): u along x, v along y. */
63
+ export const topFace = (cam, x0, y0, z) => (a, b) => cam.P(x0 + a, y0 + b, z);
64
+ /** A rounded rectangle on a face, as closed path data. */
65
+ export const faceRect = (face, u0, v0, w, h, r = 0.12) => line(rrect(u0, v0, u0 + w, v0 + h, r, 3).map(([a, b]) => face(a, b)), true);
66
+ /** A straight line on a face. */
67
+ export const faceLine = (face, a, b) => line([face(...a), face(...b)]);
68
+ /** A polyline through world points. */
69
+ export const poly = (cam, pts, closed = false) => line(pts.map(([x, y, z]) => cam.P(x, y, z)), closed);
70
+ /** A short dash centred at fraction t along a world segment: a pulse of light on a cable. */
71
+ export function dash(cam, a, b, t, len) {
72
+ const L = Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]) || 1;
73
+ const h = len / L / 2;
74
+ const p = (s) => {
75
+ const k = Math.min(1, Math.max(0, s));
76
+ return [a[0] + (b[0] - a[0]) * k, a[1] + (b[1] - a[1]) * k, a[2] + (b[2] - a[2]) * k];
77
+ };
78
+ if (t + h < 0 || t - h > 1)
79
+ return "";
80
+ return poly(cam, [p(t - h), p(t + h)]);
81
+ }
82
+ /** A point at fraction t along a polyline of world points (by length). */
83
+ export function along(pts, t) {
84
+ const lens = pts.slice(1).map((b, i) => Math.hypot(b[0] - pts[i][0], b[1] - pts[i][1], b[2] - pts[i][2]));
85
+ let left = Math.min(1, Math.max(0, t)) * lens.reduce((a, b) => a + b, 0);
86
+ for (let i = 0; i < lens.length; i++) {
87
+ if (left <= lens[i] || i === lens.length - 1) {
88
+ const k = lens[i] ? left / lens[i] : 0;
89
+ const a = pts[i];
90
+ const b = pts[i + 1];
91
+ return [a[0] + (b[0] - a[0]) * k, a[1] + (b[1] - a[1]) * k, a[2] + (b[2] - a[2]) * k];
92
+ }
93
+ left -= lens[i];
94
+ }
95
+ return pts[pts.length - 1];
96
+ }
97
+ /** A pulse along a polyline: the stretch [t − len, t] of its length, as path data. */
98
+ export function pulse(cam, pts, t, len) {
99
+ const total = pts.slice(1).reduce((s, b, i) => s + Math.hypot(b[0] - pts[i][0], b[1] - pts[i][1], b[2] - pts[i][2]), 0) || 1;
100
+ const k = len / total;
101
+ if (t - k > 1 || t < 0)
102
+ return "";
103
+ const out = [];
104
+ const n = 6;
105
+ for (let i = 0; i <= n; i++)
106
+ out.push(along(pts, t - k + (k * i) / n));
107
+ return poly(cam, out);
108
+ }
109
+ /**
110
+ * Where a value sits among band centres, as a fractional index (rule 01: the bands are rest
111
+ * positions and never move). Centres may run either way; the result is clamped half a band out.
112
+ */
113
+ export function bandIndex(v, centres) {
114
+ const n = centres.length;
115
+ if (n === 1)
116
+ return 0;
117
+ const dir = Math.sign(centres[n - 1] - centres[0]) || 1;
118
+ const at = (i) => centres[i] * dir;
119
+ const x = v * dir;
120
+ if (x <= at(0))
121
+ return Math.max(-0.5, (x - at(0)) / (at(1) - at(0)));
122
+ for (let i = 0; i < n - 1; i++)
123
+ if (x <= at(i + 1))
124
+ return i + (x - at(i)) / (at(i + 1) - at(i));
125
+ return Math.min(n - 0.5, n - 1 + (x - at(n - 1)) / (at(n - 1) - at(n - 2)));
126
+ }
@@ -0,0 +1,11 @@
1
+ import * as React from "react";
2
+ /**
3
+ * Base UI keeps a control's state inside the control and has no form reset of its own. After
4
+ * `form.reset()` (a reset button, or React clearing a form once its action has run) a checkbox,
5
+ * switch or radio would still show its old state while its hidden input went back to the default,
6
+ * so the next submit sends what nobody sees; a slider would keep its old value.
7
+ *
8
+ * The key returned here changes when the form around the element with `ref` resets: a part keyed
9
+ * with it remounts from its defaults, or from its value when controlled.
10
+ */
11
+ export declare function useFormReset<T extends Element>(): [key: number, ref: React.RefCallback<T>];
@@ -0,0 +1,22 @@
1
+ import * as React from "react";
2
+ /**
3
+ * Base UI keeps a control's state inside the control and has no form reset of its own. After
4
+ * `form.reset()` (a reset button, or React clearing a form once its action has run) a checkbox,
5
+ * switch or radio would still show its old state while its hidden input went back to the default,
6
+ * so the next submit sends what nobody sees; a slider would keep its old value.
7
+ *
8
+ * The key returned here changes when the form around the element with `ref` resets: a part keyed
9
+ * with it remounts from its defaults, or from its value when controlled.
10
+ */
11
+ export function useFormReset() {
12
+ const [key, setKey] = React.useState(0);
13
+ const ref = React.useCallback((node) => {
14
+ const form = node?.closest("form");
15
+ if (!form)
16
+ return;
17
+ const reset = () => setKey((k) => k + 1);
18
+ form.addEventListener("reset", reset);
19
+ return () => form.removeEventListener("reset", reset);
20
+ }, []);
21
+ return [key, ref];
22
+ }
@@ -0,0 +1,53 @@
1
+ import * as React from "react";
2
+ /** The box of a glide target, relative to its container's padding box. */
3
+ export interface GlideRect {
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ }
9
+ export interface GlideOptions {
10
+ /** Off: no target is tracked and `rect` stays null. */
11
+ enabled?: boolean;
12
+ /** Re-measure when these attributes change anywhere inside the container. */
13
+ attributes?: string[];
14
+ /** Re-measure on these events at the container (focusin, pointerover …). */
15
+ events?: string[];
16
+ /** Elements to watch for size changes besides the container itself. */
17
+ items?: string;
18
+ /**
19
+ * Keep the indicator in place this long (ms) after the target goes away. Moving between items
20
+ * (from one trigger to the next) can leave a moment with no target; within the linger the next
21
+ * one is reached by gliding instead of reappearing in place.
22
+ */
23
+ linger?: number;
24
+ }
25
+ export interface Glide {
26
+ /** The target's box, or the last one while `visible` is false (so a fade-out stays put). */
27
+ rect: GlideRect | null;
28
+ /** A target exists right now. */
29
+ visible: boolean;
30
+ /**
31
+ * Skip the transition this frame: true before the first placement and when the indicator
32
+ * reappears after having no target, so it never flies in from a stale position.
33
+ */
34
+ instant: boolean;
35
+ }
36
+ /**
37
+ * useGlide — one indicator that glides between the items of a container: the selected segment,
38
+ * the current page, the focused slot, the hovered trigger. `find` returns the item it should
39
+ * cover; the hook measures it and re-measures when attributes or events say the target moved,
40
+ * and when the container or an item resizes. Position the indicator absolutely inside the
41
+ * container with `glideStyle(glide)` and transition `translate`, `width` and `height`.
42
+ */
43
+ export declare function useGlide(container: React.RefObject<HTMLElement | null>, find: (container: HTMLElement) => Element | null, { enabled, attributes, events, items, linger }?: GlideOptions): Glide;
44
+ /** Inline style that places an absolutely positioned indicator over the glide target. */
45
+ export declare function glideStyle({ rect }: Glide): React.CSSProperties | undefined;
46
+ /**
47
+ * The indicator's motion: translate and size in 2 × --duration with the brand ease, opacity in
48
+ * --duration. Put `data-instant` on it while `glide.instant`, `data-visible` while visible.
49
+ * Reduced motion sets --duration to 0, so it moves instantly.
50
+ */
51
+ export declare const glideMotion = "pointer-events-none absolute top-0 left-0 opacity-0 data-visible:opacity-100 transition-[translate,width,height,opacity] duration-[calc(var(--duration)*2)] ease-brand data-instant:transition-none";
52
+ /** Merges a component's own ref with the one passed in by the caller. */
53
+ export declare function useMergedRef<T>(ref: React.Ref<T> | undefined): [React.RefObject<T | null>, (node: T | null) => void];
@@ -0,0 +1,138 @@
1
+ import * as React from "react";
2
+ /**
3
+ * The target's layout box relative to the container, from offset* — unaffected by transforms, so a
4
+ * button scaled mid-press measures at its resting size. Walks offsetParents up to the container.
5
+ */
6
+ function layoutBox(target, container) {
7
+ const node = target;
8
+ let x = 0;
9
+ let y = 0;
10
+ let current = node;
11
+ while (current && current !== container) {
12
+ x += current.offsetLeft;
13
+ y += current.offsetTop;
14
+ const parent = current.offsetParent;
15
+ if (parent && parent !== container) {
16
+ x += parent.clientLeft - parent.scrollLeft;
17
+ y += parent.clientTop - parent.scrollTop;
18
+ }
19
+ current = parent;
20
+ }
21
+ return { x, y, width: node.offsetWidth, height: node.offsetHeight };
22
+ }
23
+ const same = (a, b) => a === b || (!!a && !!b && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height);
24
+ /**
25
+ * useGlide — one indicator that glides between the items of a container: the selected segment,
26
+ * the current page, the focused slot, the hovered trigger. `find` returns the item it should
27
+ * cover; the hook measures it and re-measures when attributes or events say the target moved,
28
+ * and when the container or an item resizes. Position the indicator absolutely inside the
29
+ * container with `glideStyle(glide)` and transition `translate`, `width` and `height`.
30
+ */
31
+ export function useGlide(container, find, { enabled = true, attributes = [], events = [], items, linger = 0 } = {}) {
32
+ const [state, setState] = React.useState({ rect: null, visible: false, instant: true });
33
+ const findRef = React.useRef(find);
34
+ findRef.current = find;
35
+ const key = `${enabled}|${attributes.join()}|${events.join()}|${items ?? ""}|${linger}`;
36
+ React.useLayoutEffect(() => {
37
+ const el = container.current;
38
+ if (!enabled || !el) {
39
+ setState({ rect: null, visible: false, instant: true });
40
+ return;
41
+ }
42
+ let lingering = 0;
43
+ const hide = () => setState((prev) => (prev.visible ? { ...prev, visible: false } : prev));
44
+ const measure = () => {
45
+ const target = findRef.current(el);
46
+ if (!target && linger > 0) {
47
+ if (!lingering) {
48
+ lingering = window.setTimeout(() => {
49
+ lingering = 0;
50
+ if (findRef.current(el))
51
+ measure();
52
+ else
53
+ hide();
54
+ }, linger);
55
+ }
56
+ return;
57
+ }
58
+ clearTimeout(lingering);
59
+ lingering = 0;
60
+ setState((prev) => {
61
+ if (!target)
62
+ return prev.visible ? { ...prev, visible: false } : prev;
63
+ const rect = layoutBox(target, el);
64
+ // Appearing again (or for the first time): jump into place, then glide from there.
65
+ const instant = !prev.visible;
66
+ if (prev.visible && same(prev.rect, rect))
67
+ return prev;
68
+ return { rect, visible: true, instant };
69
+ });
70
+ };
71
+ let frame = 0;
72
+ const schedule = () => {
73
+ cancelAnimationFrame(frame);
74
+ frame = requestAnimationFrame(measure);
75
+ };
76
+ const resize = new ResizeObserver(measure);
77
+ const observe = () => {
78
+ resize.disconnect();
79
+ resize.observe(el);
80
+ if (items)
81
+ el.querySelectorAll(items).forEach((node) => resize.observe(node));
82
+ };
83
+ const mutations = new MutationObserver((records) => {
84
+ if (records.some((r) => r.type === "childList"))
85
+ observe();
86
+ measure();
87
+ });
88
+ mutations.observe(el, {
89
+ subtree: true,
90
+ childList: true,
91
+ attributes: attributes.length > 0,
92
+ ...(attributes.length > 0 ? { attributeFilter: attributes } : {}),
93
+ });
94
+ for (const type of events)
95
+ el.addEventListener(type, schedule);
96
+ observe();
97
+ measure();
98
+ return () => {
99
+ cancelAnimationFrame(frame);
100
+ clearTimeout(lingering);
101
+ mutations.disconnect();
102
+ resize.disconnect();
103
+ for (const type of events)
104
+ el.removeEventListener(type, schedule);
105
+ };
106
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- `key` captures the options.
107
+ }, [container, key]);
108
+ // After an instant placement, re-enable the transition on the next frame.
109
+ React.useEffect(() => {
110
+ if (!state.instant || !state.visible)
111
+ return;
112
+ const frame = requestAnimationFrame(() => setState((prev) => (prev.instant ? { ...prev, instant: false } : prev)));
113
+ return () => cancelAnimationFrame(frame);
114
+ }, [state.instant, state.visible]);
115
+ return state;
116
+ }
117
+ /** Inline style that places an absolutely positioned indicator over the glide target. */
118
+ export function glideStyle({ rect }) {
119
+ return rect ? { translate: `${rect.x}px ${rect.y}px`, width: rect.width, height: rect.height } : undefined;
120
+ }
121
+ /**
122
+ * The indicator's motion: translate and size in 2 × --duration with the brand ease, opacity in
123
+ * --duration. Put `data-instant` on it while `glide.instant`, `data-visible` while visible.
124
+ * Reduced motion sets --duration to 0, so it moves instantly.
125
+ */
126
+ export const glideMotion = "pointer-events-none absolute top-0 left-0 opacity-0 data-visible:opacity-100 transition-[translate,width,height,opacity] duration-[calc(var(--duration)*2)] ease-brand data-instant:transition-none";
127
+ /** Merges a component's own ref with the one passed in by the caller. */
128
+ export function useMergedRef(ref) {
129
+ const own = React.useRef(null);
130
+ const set = React.useCallback((node) => {
131
+ own.current = node;
132
+ if (typeof ref === "function")
133
+ ref(node);
134
+ else if (ref)
135
+ ref.current = node;
136
+ }, [ref]);
137
+ return [own, set];
138
+ }
@@ -0,0 +1,58 @@
1
+ import { type Simulation, type SimulationLinkDatum, type SimulationNodeDatum } from "d3-force";
2
+ export type LayoutKind = "flow" | "tree" | "network";
3
+ export type LayoutDirection = "right" | "down";
4
+ export interface LayoutNode {
5
+ id: string;
6
+ width: number;
7
+ height: number;
8
+ /** A group this node sits in (flows and trees). */
9
+ parent?: string;
10
+ /** Kept where it is (networks): a node the reader placed. */
11
+ fixed?: {
12
+ x: number;
13
+ y: number;
14
+ };
15
+ }
16
+ export interface LayoutEdge {
17
+ source: string;
18
+ target: string;
19
+ }
20
+ export interface Placed {
21
+ x: number;
22
+ y: number;
23
+ /** Groups only: the box that holds their children. */
24
+ width?: number;
25
+ height?: number;
26
+ }
27
+ /** Layered layout: ranks along `direction`, groups wrapped around their children. */
28
+ export declare function layered(nodes: LayoutNode[], edges: LayoutEdge[], kind: "flow" | "tree", direction: LayoutDirection): Map<string, Placed>;
29
+ interface ForceNode extends SimulationNodeDatum {
30
+ id: string;
31
+ r: number;
32
+ }
33
+ /** Builds the simulation a network settles under — reused live while a node is dragged. */
34
+ export declare function networkSimulation(nodes: LayoutNode[], edges: LayoutEdge[]): {
35
+ simulation: Simulation<ForceNode, SimulationLinkDatum<ForceNode>>;
36
+ sim: ForceNode[];
37
+ };
38
+ /**
39
+ * The simulation for dragging one node of a settled network. Every node is held near where it
40
+ * stands: its neighbours loosely, so they follow the link, the rest firmly, so the graph does not
41
+ * drift. Repulsion only reaches nearby nodes (the dragged one pushes what it passes), and it
42
+ * settles in about a second once let go.
43
+ */
44
+ export declare function dragSimulation(nodes: LayoutNode[], edges: LayoutEdge[], held: string): {
45
+ simulation: Simulation<ForceNode, SimulationLinkDatum<ForceNode>>;
46
+ sim: ForceNode[];
47
+ };
48
+ /** Force layout, run to rest before the first paint. */
49
+ export declare function network(nodes: LayoutNode[], edges: LayoutEdge[]): Map<string, Placed>;
50
+ /** The strip a lane's name sits in, and the room around its steps. */
51
+ export declare const LANE_HEADER = 36;
52
+ /**
53
+ * Swimlanes: the whole flow is laid out as one, so ranks line up across lanes; then each lane is
54
+ * a band across the full length of the flow, stacked one under the other (beside, flowing down),
55
+ * holding its steps — in rows, where two of them share a rank.
56
+ */
57
+ export declare function lanes(nodes: LayoutNode[], laneIds: string[], edges: LayoutEdge[], direction: LayoutDirection): Map<string, Placed>;
58
+ export {};
@@ -0,0 +1,200 @@
1
+ import { Graph as DagreGraph, layout as dagreLayout } from "@dagrejs/dagre";
2
+ import { forceCenter, forceCollide, forceLink, forceManyBody, forceSimulation, forceX, forceY, } from "d3-force";
3
+ /** Layered layout: ranks along `direction`, groups wrapped around their children. */
4
+ export function layered(nodes, edges, kind, direction) {
5
+ const groups = new Set(nodes.map((n) => n.parent).filter(Boolean));
6
+ const g = new DagreGraph({ compound: groups.size > 0, multigraph: true });
7
+ g.setGraph({
8
+ rankdir: direction === "down" ? "TB" : "LR",
9
+ // A tree reads as tiers: more room between them than between siblings.
10
+ nodesep: kind === "tree" ? 28 : 40,
11
+ ranksep: kind === "tree" ? 64 : 88,
12
+ edgesep: 16,
13
+ marginx: 24,
14
+ marginy: 24,
15
+ ranker: kind === "tree" ? "tight-tree" : "network-simplex",
16
+ });
17
+ g.setDefaultEdgeLabel(() => ({}));
18
+ for (const n of nodes) {
19
+ if (groups.has(n.id))
20
+ g.setNode(n.id, { paddingTop: 36, paddingBottom: 20, paddingLeft: 20, paddingRight: 20 });
21
+ else
22
+ g.setNode(n.id, { width: n.width, height: n.height });
23
+ }
24
+ for (const n of nodes)
25
+ if (n.parent && g.hasNode(n.parent))
26
+ g.setParent(n.id, n.parent);
27
+ edges.forEach((e, i) => {
28
+ // Edges to or from a group lay out against its contents: dagre cannot rank a compound node.
29
+ if (groups.has(e.source) || groups.has(e.target))
30
+ return;
31
+ if (g.hasNode(e.source) && g.hasNode(e.target))
32
+ g.setEdge(e.source, e.target, {}, `e${i}`);
33
+ });
34
+ dagreLayout(g);
35
+ const placed = new Map();
36
+ for (const n of nodes) {
37
+ const box = g.node(n.id);
38
+ if (!box)
39
+ continue;
40
+ const width = groups.has(n.id) ? box.width : n.width;
41
+ const height = groups.has(n.id) ? box.height : n.height;
42
+ placed.set(n.id, {
43
+ x: box.x - width / 2,
44
+ y: box.y - height / 2,
45
+ ...(groups.has(n.id) ? { width, height } : {}),
46
+ });
47
+ }
48
+ return placed;
49
+ }
50
+ /** The node radius a force layout keeps clear around a box. */
51
+ const radiusOf = (n) => Math.hypot(n.width, n.height) / 2 + 14;
52
+ /** Builds the simulation a network settles under — reused live while a node is dragged. */
53
+ export function networkSimulation(nodes, edges) {
54
+ const sim = nodes.map((n, i) => {
55
+ // Start on a phyllotaxis spiral, so the result is the same on every load.
56
+ const angle = i * 2.399963;
57
+ const radius = 18 * Math.sqrt(i + 0.5);
58
+ return {
59
+ id: n.id,
60
+ r: radiusOf(n),
61
+ x: n.fixed ? n.fixed.x + n.width / 2 : Math.cos(angle) * radius * 6,
62
+ y: n.fixed ? n.fixed.y + n.height / 2 : Math.sin(angle) * radius * 6,
63
+ ...(n.fixed ? { fx: n.fixed.x + n.width / 2, fy: n.fixed.y + n.height / 2 } : {}),
64
+ };
65
+ });
66
+ const ids = new Set(sim.map((n) => n.id));
67
+ const links = edges
68
+ .filter((e) => ids.has(e.source) && ids.has(e.target))
69
+ .map((e) => ({ source: e.source, target: e.target }));
70
+ const degree = new Map();
71
+ for (const e of edges) {
72
+ degree.set(e.source, (degree.get(e.source) ?? 0) + 1);
73
+ degree.set(e.target, (degree.get(e.target) ?? 0) + 1);
74
+ }
75
+ const simulation = forceSimulation(sim)
76
+ .force("link", forceLink(links)
77
+ .id((d) => d.id)
78
+ // Hubs keep their spokes a little further out, so the spokes do not crowd.
79
+ .distance((l) => {
80
+ const s = l.source;
81
+ const t = l.target;
82
+ return s.r + t.r + 56 + 8 * Math.min(6, Math.max(degree.get(s.id) ?? 0, degree.get(t.id) ?? 0));
83
+ })
84
+ .strength(0.45))
85
+ .force("charge", forceManyBody().strength(-1300).distanceMax(1400))
86
+ .force("collide", forceCollide((d) => d.r + 10).strength(0.95))
87
+ .force("x", forceX(0).strength(0.03))
88
+ .force("y", forceY(0).strength(0.05))
89
+ .force("center", forceCenter(0, 0))
90
+ // Settle slowly: a lower decay finds an arrangement with fewer crossings.
91
+ .alphaDecay(0.012)
92
+ .stop();
93
+ return { simulation, sim };
94
+ }
95
+ /**
96
+ * The simulation for dragging one node of a settled network. Every node is held near where it
97
+ * stands: its neighbours loosely, so they follow the link, the rest firmly, so the graph does not
98
+ * drift. Repulsion only reaches nearby nodes (the dragged one pushes what it passes), and it
99
+ * settles in about a second once let go.
100
+ */
101
+ export function dragSimulation(nodes, edges, held) {
102
+ const { simulation, sim } = networkSimulation(nodes, edges);
103
+ const near = new Set([held]);
104
+ for (const e of edges) {
105
+ if (e.source === held)
106
+ near.add(e.target);
107
+ if (e.target === held)
108
+ near.add(e.source);
109
+ }
110
+ for (const d of sim) {
111
+ if (d.id === held)
112
+ continue;
113
+ d.fx = null;
114
+ d.fy = null;
115
+ }
116
+ const home = new Map(sim.map((d) => [d.id, { x: d.x ?? 0, y: d.y ?? 0 }]));
117
+ const pull = (d) => (near.has(d.id) ? 0.02 : 0.14);
118
+ simulation
119
+ .force("center", null)
120
+ .force("charge", forceManyBody().strength(-520).distanceMax(320))
121
+ .force("x", forceX((d) => home.get(d.id).x).strength(pull))
122
+ .force("y", forceY((d) => home.get(d.id).y).strength(pull))
123
+ .alphaDecay(0.045)
124
+ .velocityDecay(0.5);
125
+ return { simulation, sim };
126
+ }
127
+ /** Force layout, run to rest before the first paint. */
128
+ export function network(nodes, edges) {
129
+ const { simulation, sim } = networkSimulation(nodes, edges);
130
+ const ticks = Math.ceil(Math.log(simulation.alphaMin()) / Math.log(1 - simulation.alphaDecay()));
131
+ simulation.tick(ticks);
132
+ const sizes = new Map(nodes.map((n) => [n.id, n]));
133
+ const placed = new Map();
134
+ for (const n of sim) {
135
+ const box = sizes.get(n.id);
136
+ placed.set(n.id, { x: (n.x ?? 0) - box.width / 2, y: (n.y ?? 0) - box.height / 2 });
137
+ }
138
+ return placed;
139
+ }
140
+ /** The strip a lane's name sits in, and the room around its steps. */
141
+ export const LANE_HEADER = 36;
142
+ const LANE_PAD = 22;
143
+ const LANE_ROW_GAP = 18;
144
+ /**
145
+ * Swimlanes: the whole flow is laid out as one, so ranks line up across lanes; then each lane is
146
+ * a band across the full length of the flow, stacked one under the other (beside, flowing down),
147
+ * holding its steps — in rows, where two of them share a rank.
148
+ */
149
+ export function lanes(nodes, laneIds, edges, direction) {
150
+ const lanesSet = new Set(laneIds);
151
+ const members = nodes.filter((n) => !lanesSet.has(n.id));
152
+ const flat = layered(members.map(({ parent: _parent, ...n }) => n), edges.filter((e) => !lanesSet.has(e.source) && !lanesSet.has(e.target)), "flow", direction);
153
+ const down = direction === "down";
154
+ const along = (id) => (down ? flat.get(id).y : flat.get(id).x);
155
+ const length = (n) => (down ? n.height : n.width);
156
+ const thickness = (n) => (down ? n.width : n.height);
157
+ let start = Infinity;
158
+ let end = -Infinity;
159
+ for (const n of members) {
160
+ start = Math.min(start, along(n.id));
161
+ end = Math.max(end, along(n.id) + length(n));
162
+ }
163
+ // Lanes with no steps in them yet (or all deleted) are only as long as their names.
164
+ if (!members.length)
165
+ start = end = 0;
166
+ const placed = new Map();
167
+ let offset = 0;
168
+ for (const lane of laneIds) {
169
+ const inLane = members.filter((n) => n.parent === lane).sort((a, b) => along(a.id) - along(b.id));
170
+ // Pack the lane's steps into rows: a step goes in the first row it does not overlap.
171
+ const rows = [];
172
+ for (const n of inLane) {
173
+ const from = along(n.id);
174
+ let row = rows.find((r) => from >= r.end + 24);
175
+ if (!row)
176
+ rows.push((row = { end: -Infinity, size: 0, nodes: [] }));
177
+ row.end = from + length(n);
178
+ row.size = Math.max(row.size, thickness(n));
179
+ row.nodes.push(n);
180
+ }
181
+ const inner = rows.reduce((sum, r) => sum + r.size, 0) + LANE_ROW_GAP * Math.max(0, rows.length - 1);
182
+ const size = Math.max(104, inner + LANE_PAD * 2);
183
+ let across = offset + (size - inner) / 2;
184
+ for (const row of rows) {
185
+ for (const n of row.nodes) {
186
+ const cross = across + (row.size - thickness(n)) / 2;
187
+ placed.set(n.id, down ? { x: cross, y: along(n.id) } : { x: along(n.id), y: cross });
188
+ }
189
+ across += row.size + LANE_ROW_GAP;
190
+ }
191
+ const span = end - start + LANE_PAD * 2 + LANE_HEADER;
192
+ const from = start - LANE_PAD - LANE_HEADER;
193
+ placed.set(lane, down
194
+ ? { x: offset, y: from, width: size, height: span }
195
+ : { x: from, y: offset, width: span, height: size });
196
+ // Neighbouring lanes share their border.
197
+ offset += size - 1;
198
+ }
199
+ return placed;
200
+ }