@link-foundation/ui-components 0.0.0-stage → 0.0.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 (402) hide show
  1. package/CONFIGURATIONS.md +74 -0
  2. package/ICONS.md +76 -0
  3. package/LICENSE +24 -0
  4. package/README.md +1499 -2
  5. package/bin/lino-network.mjs +71 -0
  6. package/dist/icons/ATTRIBUTION.md +602 -0
  7. package/dist/icons/NOTICE.lino +1261 -0
  8. package/dist/icons/brand.js +31 -0
  9. package/dist/icons/brand.svg +3 -0
  10. package/dist/icons/licenses/brand/DISCLAIMER.md +51 -0
  11. package/dist/icons/licenses/brand/LICENSE.md +30 -0
  12. package/dist/icons/licenses/lucide/LICENSE +43 -0
  13. package/dist/icons/licenses/material-symbols/LICENSE +202 -0
  14. package/dist/icons/licenses/material-symbols/NOTICE +12 -0
  15. package/dist/icons/licenses/tabler/LICENSE +21 -0
  16. package/dist/icons/lucide.js +681 -0
  17. package/dist/icons/lucide.svg +34 -0
  18. package/dist/icons/material-symbols.js +681 -0
  19. package/dist/icons/material-symbols.svg +34 -0
  20. package/dist/icons/own.js +521 -0
  21. package/dist/icons/own.svg +34 -0
  22. package/dist/icons/tabler.js +681 -0
  23. package/dist/icons/tabler.svg +34 -0
  24. package/dist/network-layout-NOTICE.md +6 -0
  25. package/dist/network-layout-d3-dispatch-LICENSE.txt +13 -0
  26. package/dist/network-layout-d3-force-LICENSE.txt +13 -0
  27. package/dist/network-layout-d3-quadtree-LICENSE.txt +13 -0
  28. package/dist/network-layout-d3-timer-LICENSE.txt +13 -0
  29. package/dist/network-layout-dagre-LICENSE.txt +19 -0
  30. package/dist/network-layout.worker.mjs +2 -0
  31. package/package.json +246 -4
  32. package/src/a11y/announce.js +88 -0
  33. package/src/a11y/bind-machine.js +181 -0
  34. package/src/a11y/focus.js +169 -0
  35. package/src/a11y/index.d.ts +89 -0
  36. package/src/a11y/index.js +19 -0
  37. package/src/a11y/keys.js +182 -0
  38. package/src/a11y/roving.js +167 -0
  39. package/src/a11y/typeahead.js +82 -0
  40. package/src/behavior/actions.js +235 -0
  41. package/src/behavior/diagnostics.js +73 -0
  42. package/src/behavior/dom.d.ts +38 -0
  43. package/src/behavior/dom.js +420 -0
  44. package/src/behavior/index.d.ts +211 -0
  45. package/src/behavior/index.js +29 -0
  46. package/src/behavior/interpret.js +454 -0
  47. package/src/behavior/machines/disclosure.lino +46 -0
  48. package/src/behavior/machines/index.js +91 -0
  49. package/src/behavior/machines/toggle.lino +25 -0
  50. package/src/behavior/parse-machine.js +367 -0
  51. package/src/charts/README.md +78 -0
  52. package/src/charts/activity-layout.js +350 -0
  53. package/src/charts/activity-model.js +130 -0
  54. package/src/charts/activity-validation.js +31 -0
  55. package/src/charts/chart-model.js +667 -0
  56. package/src/charts/chart.js +518 -0
  57. package/src/charts/echarts-adapter.d.ts +23 -0
  58. package/src/charts/echarts-adapter.js +240 -0
  59. package/src/charts/element.js +330 -0
  60. package/src/charts/errors.js +62 -0
  61. package/src/charts/gauge.js +27 -0
  62. package/src/charts/index.d.ts +344 -0
  63. package/src/charts/index.js +59 -0
  64. package/src/charts/layout.js +542 -0
  65. package/src/charts/lino.js +158 -0
  66. package/src/charts/mark-options.js +78 -0
  67. package/src/charts/read.js +101 -0
  68. package/src/charts/renderer-features.js +8 -0
  69. package/src/charts/scales.js +223 -0
  70. package/src/charts/small-model.js +223 -0
  71. package/src/charts/small-svg.js +269 -0
  72. package/src/charts/sparkline.js +27 -0
  73. package/src/charts/stat-tile.js +37 -0
  74. package/src/charts/summary.js +193 -0
  75. package/src/charts/svg-renderer.js +226 -0
  76. package/src/charts/svg.js +69 -0
  77. package/src/charts/tag-cloud.js +129 -0
  78. package/src/charts/tokens.js +171 -0
  79. package/src/charts/tooltip.js +47 -0
  80. package/src/charts/values.js +146 -0
  81. package/src/chat/README.md +142 -0
  82. package/src/chat/actions.js +75 -0
  83. package/src/chat/chat-contract.js +95 -0
  84. package/src/chat/chat-list.js +42 -0
  85. package/src/chat/chat-model.js +125 -0
  86. package/src/chat/chat.css +228 -0
  87. package/src/chat/composer.js +131 -0
  88. package/src/chat/day-separator.js +12 -0
  89. package/src/chat/dom.js +33 -0
  90. package/src/chat/follow.js +49 -0
  91. package/src/chat/index.d.ts +142 -0
  92. package/src/chat/index.js +13 -0
  93. package/src/chat/message-bubble.js +191 -0
  94. package/src/chat/message-stream.js +331 -0
  95. package/src/chat/reasoning-trace.js +70 -0
  96. package/src/chat/selection.js +39 -0
  97. package/src/chat/skins/bubbles.lino +2 -0
  98. package/src/chat/skins/cards.lino +4 -0
  99. package/src/chat/skins/compact.lino +4 -0
  100. package/src/chat/skins/signal.lino +25 -0
  101. package/src/chat/skins/t3.lino +25 -0
  102. package/src/chat/skins/telegram.lino +31 -0
  103. package/src/chat/skins/whatsapp.lino +25 -0
  104. package/src/chat/stream-keys.js +57 -0
  105. package/src/chat/stream-window.js +159 -0
  106. package/src/chat/vocabulary.js +19 -0
  107. package/src/controls/accordion.js +160 -0
  108. package/src/controls/avatar.js +80 -0
  109. package/src/controls/badge.js +48 -0
  110. package/src/controls/button-template.js +32 -0
  111. package/src/controls/button.js +97 -0
  112. package/src/controls/catalog.lino +84 -0
  113. package/src/controls/checkbox.js +112 -0
  114. package/src/controls/chip.js +140 -0
  115. package/src/controls/choices.js +45 -0
  116. package/src/controls/color-field.js +217 -0
  117. package/src/controls/color-popover.js +135 -0
  118. package/src/controls/color-rgb.js +80 -0
  119. package/src/controls/color.js +67 -0
  120. package/src/controls/combobox.js +192 -0
  121. package/src/controls/dom.js +261 -0
  122. package/src/controls/icon-button.js +33 -0
  123. package/src/controls/index.d.ts +163 -0
  124. package/src/controls/index.js +182 -0
  125. package/src/controls/kinds-text.js +358 -0
  126. package/src/controls/kinds.lino +350 -0
  127. package/src/controls/label.js +52 -0
  128. package/src/controls/link.js +101 -0
  129. package/src/controls/listbox.js +144 -0
  130. package/src/controls/machines/button.lino +20 -0
  131. package/src/controls/machines/checkbox.lino +17 -0
  132. package/src/controls/machines/chip.lino +20 -0
  133. package/src/controls/machines/color-field.lino +23 -0
  134. package/src/controls/machines/combobox.lino +82 -0
  135. package/src/controls/machines/icon-button.lino +20 -0
  136. package/src/controls/machines/index.js +586 -0
  137. package/src/controls/machines/number-field.lino +71 -0
  138. package/src/controls/machines/radio-group.lino +17 -0
  139. package/src/controls/machines/select.lino +122 -0
  140. package/src/controls/machines/slider.lino +99 -0
  141. package/src/controls/machines/switch.lino +19 -0
  142. package/src/controls/machines/text-area.lino +26 -0
  143. package/src/controls/machines/text-field.lino +26 -0
  144. package/src/controls/number-field.js +239 -0
  145. package/src/controls/numeric-keys.js +125 -0
  146. package/src/controls/option.js +54 -0
  147. package/src/controls/progress.js +76 -0
  148. package/src/controls/radio-group.js +234 -0
  149. package/src/controls/select.js +229 -0
  150. package/src/controls/slider.js +234 -0
  151. package/src/controls/stories.js +172 -0
  152. package/src/controls/styles.css +1060 -0
  153. package/src/controls/switch.js +95 -0
  154. package/src/controls/text-area.js +39 -0
  155. package/src/controls/text-field.js +131 -0
  156. package/src/controls/vocabulary.js +164 -0
  157. package/src/data/data.css +95 -0
  158. package/src/data/index.d.ts +83 -0
  159. package/src/data/index.js +10 -0
  160. package/src/data/keyboard.js +189 -0
  161. package/src/data/list.js +215 -0
  162. package/src/data/render-data.js +116 -0
  163. package/src/data/selection-dom.js +39 -0
  164. package/src/data/selection-model.js +43 -0
  165. package/src/data/sort-model.js +42 -0
  166. package/src/data/source.js +45 -0
  167. package/src/data/table.js +160 -0
  168. package/src/data/tree-model.js +41 -0
  169. package/src/data/tree.js +55 -0
  170. package/src/data/viewport.js +216 -0
  171. package/src/data/virtual-range.js +92 -0
  172. package/src/data/vocabulary.js +67 -0
  173. package/src/diagrams/diagram-model.js +511 -0
  174. package/src/diagrams/diagram.js +204 -0
  175. package/src/diagrams/index.d.ts +225 -0
  176. package/src/diagrams/index.js +48 -0
  177. package/src/diagrams/layout-dagre.js +164 -0
  178. package/src/diagrams/layout-plugins.js +131 -0
  179. package/src/diagrams/mermaid-export.js +232 -0
  180. package/src/diagrams/mermaid-view.js +229 -0
  181. package/src/diagrams/svg-diagram.js +215 -0
  182. package/src/editor/code-editor.js +206 -0
  183. package/src/editor/documents-model.js +170 -0
  184. package/src/editor/documents-persistence.js +85 -0
  185. package/src/editor/editor-engine.js +22 -0
  186. package/src/editor/editor-ui.js +203 -0
  187. package/src/editor/editor.css +106 -0
  188. package/src/editor/engines/codemirror.js +227 -0
  189. package/src/editor/engines/monaco.js +219 -0
  190. package/src/editor/index.d.ts +111 -0
  191. package/src/editor/index.js +14 -0
  192. package/src/editor/lino-highlight.js +106 -0
  193. package/src/editor/lino-structure.js +85 -0
  194. package/src/editor/validate-lino.js +43 -0
  195. package/src/embed/README.md +161 -0
  196. package/src/embed/controller.js +223 -0
  197. package/src/embed/element.js +141 -0
  198. package/src/embed/index.d.ts +75 -0
  199. package/src/embed/index.js +9 -0
  200. package/src/embed/providers/telegram.d.ts +3 -0
  201. package/src/embed/providers/telegram.js +38 -0
  202. package/src/embed/providers/vk.d.ts +3 -0
  203. package/src/embed/providers/vk.js +42 -0
  204. package/src/embed/providers/x.d.ts +3 -0
  205. package/src/embed/providers/x.js +31 -0
  206. package/src/embed/registry.js +35 -0
  207. package/src/embed/script.js +73 -0
  208. package/src/embed/view.js +122 -0
  209. package/src/icons/adapters/lucide.d.ts +15 -0
  210. package/src/icons/adapters/lucide.js +142 -0
  211. package/src/icons/adapters/material-symbols.d.ts +13 -0
  212. package/src/icons/adapters/material-symbols.js +113 -0
  213. package/src/icons/adapters/shared.d.ts +38 -0
  214. package/src/icons/adapters/shared.js +157 -0
  215. package/src/icons/adapters/simple-icons.d.ts +9 -0
  216. package/src/icons/adapters/simple-icons.js +38 -0
  217. package/src/icons/adapters/tabler.d.ts +9 -0
  218. package/src/icons/adapters/tabler.js +86 -0
  219. package/src/icons/icon-registry.js +215 -0
  220. package/src/icons/icon.js +356 -0
  221. package/src/icons/index.d.ts +123 -0
  222. package/src/icons/index.js +30 -0
  223. package/src/icons/names.js +51 -0
  224. package/src/icons/own-icons.js +521 -0
  225. package/src/icons/presentation.js +55 -0
  226. package/src/icons/svg.js +136 -0
  227. package/src/index.d.ts +14 -0
  228. package/src/index.js +40 -0
  229. package/src/layout/README.md +102 -0
  230. package/src/layout/app-shell.js +150 -0
  231. package/src/layout/catalog.lino +27 -0
  232. package/src/layout/dock-model.js +576 -0
  233. package/src/layout/dock-view.js +312 -0
  234. package/src/layout/dock.js +352 -0
  235. package/src/layout/dom.js +312 -0
  236. package/src/layout/grid.js +192 -0
  237. package/src/layout/index.d.ts +267 -0
  238. package/src/layout/index.js +60 -0
  239. package/src/layout/layer-manager.js +120 -0
  240. package/src/layout/layout.css +760 -0
  241. package/src/layout/menu.js +141 -0
  242. package/src/layout/nav-strip.js +174 -0
  243. package/src/layout/page-links.js +166 -0
  244. package/src/layout/panel.js +26 -0
  245. package/src/layout/pref-switches.js +209 -0
  246. package/src/layout/split-model.js +270 -0
  247. package/src/layout/split.js +430 -0
  248. package/src/layout/stack.js +86 -0
  249. package/src/layout/surfaces.js +119 -0
  250. package/src/layout/tab-group.js +151 -0
  251. package/src/layout/tab-strip.js +277 -0
  252. package/src/layout/vocabulary.js +229 -0
  253. package/src/layout/window-frame.js +222 -0
  254. package/src/layout/window.js +146 -0
  255. package/src/links-view/animator.js +144 -0
  256. package/src/links-view/configuration-classes.js +150 -0
  257. package/src/links-view/configuration-model.js +191 -0
  258. package/src/links-view/configuration-notations.js +230 -0
  259. package/src/links-view/configurations.d.ts +73 -0
  260. package/src/links-view/configurations.js +33 -0
  261. package/src/links-view/create-layout-runner.js +79 -0
  262. package/src/links-view/doublet-curves.js +239 -0
  263. package/src/links-view/doublet-layout.js +148 -0
  264. package/src/links-view/doublet-markers.js +109 -0
  265. package/src/links-view/doublet-options.js +369 -0
  266. package/src/links-view/doublet-svg.js +156 -0
  267. package/src/links-view/doublet.js +230 -0
  268. package/src/links-view/export.js +146 -0
  269. package/src/links-view/geometry.js +409 -0
  270. package/src/links-view/index.d.ts +1029 -0
  271. package/src/links-view/index.js +140 -0
  272. package/src/links-view/labels.js +28 -0
  273. package/src/links-view/layout-worker-entry.mjs +2 -0
  274. package/src/links-view/layout-worker.js +28 -0
  275. package/src/links-view/layouts/circle.js +7 -0
  276. package/src/links-view/layouts/force.js +76 -0
  277. package/src/links-view/layouts/grid.js +7 -0
  278. package/src/links-view/layouts/hex.js +8 -0
  279. package/src/links-view/layouts/index.js +15 -0
  280. package/src/links-view/layouts/layered.js +29 -0
  281. package/src/links-view/layouts/regular.js +27 -0
  282. package/src/links-view/layouts/spiral.js +10 -0
  283. package/src/links-view/link-view.js +494 -0
  284. package/src/links-view/links-gallery.js +306 -0
  285. package/src/links-view/links-network.js +496 -0
  286. package/src/links-view/lino-network-source.js +122 -0
  287. package/src/links-view/lino-network.js +233 -0
  288. package/src/links-view/lino-to-network.js +252 -0
  289. package/src/links-view/markers.js +192 -0
  290. package/src/links-view/model.js +233 -0
  291. package/src/links-view/network-editor/dom.js +36 -0
  292. package/src/links-view/network-editor/editor.js +202 -0
  293. package/src/links-view/network-editor/model.js +163 -0
  294. package/src/links-view/network-editor/options.js +265 -0
  295. package/src/links-view/network-editor/panels.js +423 -0
  296. package/src/links-view/network-editor/presets.js +76 -0
  297. package/src/links-view/network-editor/provider.js +93 -0
  298. package/src/links-view/network-editor/remap.js +45 -0
  299. package/src/links-view/network-editor/schema.js +224 -0
  300. package/src/links-view/network-editor/share.js +232 -0
  301. package/src/links-view/network-editor/styles.js +19 -0
  302. package/src/links-view/network-editor/url-sync.js +131 -0
  303. package/src/links-view/network-interaction.js +228 -0
  304. package/src/links-view/network-model.js +85 -0
  305. package/src/links-view/network-renderer.js +259 -0
  306. package/src/links-view/network-scene.js +245 -0
  307. package/src/links-view/network-source.js +82 -0
  308. package/src/links-view/network-vocabulary.js +18 -0
  309. package/src/links-view/presentation.js +199 -0
  310. package/src/links-view/render-canvas.js +102 -0
  311. package/src/links-view/render-svg.js +118 -0
  312. package/src/links-view/scene.js +233 -0
  313. package/src/links-view/solver-job.js +106 -0
  314. package/src/links-view/tokens.js +114 -0
  315. package/src/links-view/zoom-pan.js +203 -0
  316. package/src/overlays/catalog.lino +89 -0
  317. package/src/overlays/context-menu.js +110 -0
  318. package/src/overlays/dialog.js +117 -0
  319. package/src/overlays/dom.js +168 -0
  320. package/src/overlays/drawer.js +8 -0
  321. package/src/overlays/index.d.ts +80 -0
  322. package/src/overlays/index.js +25 -0
  323. package/src/overlays/kinds.lino +137 -0
  324. package/src/overlays/list-popover.js +129 -0
  325. package/src/overlays/machines/index.js +71 -0
  326. package/src/overlays/machines/surface.lino +11 -0
  327. package/src/overlays/machines/tabs.lino +7 -0
  328. package/src/overlays/machines/toast.lino +16 -0
  329. package/src/overlays/machines/tooltip.lino +29 -0
  330. package/src/overlays/menu.js +240 -0
  331. package/src/overlays/popover.js +194 -0
  332. package/src/overlays/position.js +84 -0
  333. package/src/overlays/radial-geometry.js +38 -0
  334. package/src/overlays/radial-menu.js +50 -0
  335. package/src/overlays/styles.css +155 -0
  336. package/src/overlays/tabs.js +125 -0
  337. package/src/overlays/toast-queue.js +105 -0
  338. package/src/overlays/toast.js +163 -0
  339. package/src/overlays/tooltip.js +110 -0
  340. package/src/overlays/vocabulary.js +3 -0
  341. package/src/settings/conditions.js +44 -0
  342. package/src/settings/control-for.js +62 -0
  343. package/src/settings/field-control.js +201 -0
  344. package/src/settings/index.d.ts +201 -0
  345. package/src/settings/index.js +3 -0
  346. package/src/settings/messages.js +112 -0
  347. package/src/settings/miniature.js +26 -0
  348. package/src/settings/panel-actions.js +234 -0
  349. package/src/settings/panel-model.js +49 -0
  350. package/src/settings/panel-refresh.js +56 -0
  351. package/src/settings/panel-rows.js +200 -0
  352. package/src/settings/preset-cards.js +43 -0
  353. package/src/settings/saved-looks.js +227 -0
  354. package/src/settings/section-layout.js +95 -0
  355. package/src/settings/section-tabs.js +175 -0
  356. package/src/settings/settings-panel.js +192 -0
  357. package/src/settings/settings.css +178 -0
  358. package/stories/accordion.lino +14 -0
  359. package/stories/alert-dialog.lino +4 -0
  360. package/stories/app-bar.lino +10 -0
  361. package/stories/avatar.lino +7 -0
  362. package/stories/badge.lino +12 -0
  363. package/stories/button.lino +17 -0
  364. package/stories/card.lino +10 -0
  365. package/stories/checkbox.lino +14 -0
  366. package/stories/chip.lino +19 -0
  367. package/stories/color-field.lino +9 -0
  368. package/stories/combobox.lino +10 -0
  369. package/stories/container.lino +11 -0
  370. package/stories/context-menu.lino +15 -0
  371. package/stories/dialog.lino +16 -0
  372. package/stories/drawer.lino +12 -0
  373. package/stories/icon-button.lino +13 -0
  374. package/stories/label.lino +7 -0
  375. package/stories/link-cards.lino +9 -0
  376. package/stories/link.lino +9 -0
  377. package/stories/menu-item.lino +6 -0
  378. package/stories/menu-separator.lino +7 -0
  379. package/stories/menu.lino +30 -0
  380. package/stories/nav-strip.lino +11 -0
  381. package/stories/number-field.lino +16 -0
  382. package/stories/option.lino +10 -0
  383. package/stories/paper.lino +11 -0
  384. package/stories/popover.lino +4 -0
  385. package/stories/pref-switches.lino +4 -0
  386. package/stories/progress.lino +14 -0
  387. package/stories/radial-menu.lino +19 -0
  388. package/stories/radio-group.lino +22 -0
  389. package/stories/radio.lino +10 -0
  390. package/stories/section-nav.lino +9 -0
  391. package/stories/select.lino +16 -0
  392. package/stories/slider.lino +14 -0
  393. package/stories/switch.lino +10 -0
  394. package/stories/tab-panel.lino +7 -0
  395. package/stories/tab.lino +7 -0
  396. package/stories/tabs.lino +25 -0
  397. package/stories/text-area.lino +12 -0
  398. package/stories/text-field.lino +23 -0
  399. package/stories/titled-section.lino +7 -0
  400. package/stories/toast.lino +3 -0
  401. package/stories/toaster.lino +2 -0
  402. package/stories/tooltip.lino +3 -0
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Diagram model → Mermaid text. Labels are always escaped (Mermaid entity
3
+ * codes), ids that Mermaid cannot read are replaced by safe ones, so the
4
+ * output never carries markup or Mermaid syntax taken from a label.
5
+ */
6
+
7
+ /** @typedef {import('./diagram-model.js').DiagramModel} DiagramModel */
8
+
9
+ const DIRECTIONS = Object.freeze({
10
+ down: 'TD',
11
+ up: 'BT',
12
+ right: 'LR',
13
+ left: 'RL',
14
+ });
15
+
16
+ /** Words Mermaid treats as keywords when used as an id. */
17
+ const RESERVED = new Set([
18
+ 'end',
19
+ 'graph',
20
+ 'subgraph',
21
+ 'flowchart',
22
+ 'state',
23
+ 'class',
24
+ 'direction',
25
+ 'style',
26
+ 'click',
27
+ 'default',
28
+ 'participant',
29
+ 'actor',
30
+ 'note',
31
+ 'loop',
32
+ 'alt',
33
+ 'opt',
34
+ 'par',
35
+ ]);
36
+
37
+ const SAFE_ID = /^[A-Za-z_][A-Za-z0-9_]*$/;
38
+
39
+ /**
40
+ * Escape a label for a quoted Mermaid string: `#`, `"`, `<`, `>`, `&` and
41
+ * `|` become entity codes and newlines spaces, so a label can never close the string.
42
+ * @param {string} text
43
+ * @returns {string}
44
+ */
45
+ export function escapeMermaidLabel(text) {
46
+ return String(text)
47
+ .replace(/#/g, '#35;')
48
+ .replace(/&/g, '#38;')
49
+ .replace(/"/g, '#quot;')
50
+ .replace(/</g, '#lt;')
51
+ .replace(/>/g, '#gt;')
52
+ .replace(/\|/g, '#124;')
53
+ .replace(/\r?\n/g, ' ');
54
+ }
55
+
56
+ /** An edge label that needs no quotes (`yes`, `Signed in?`). */
57
+ const PLAIN_EDGE_LABEL = /^[A-Za-z0-9 _.,?!'-]+$/;
58
+
59
+ const edgeLabel = (label) =>
60
+ PLAIN_EDGE_LABEL.test(label) ? label : `"${escapeMermaidLabel(label)}"`;
61
+
62
+ /**
63
+ * Map every node and group id to an id Mermaid can read; a safe id keeps
64
+ * its name, others become `n_<name>` with a counter on collisions.
65
+ * @param {DiagramModel} model
66
+ * @returns {Map<string, string>}
67
+ */
68
+ function mermaidIds(model) {
69
+ const ids = new Map();
70
+ const used = new Set();
71
+ const all = [...model.groups, ...model.nodes].map((item) => item.id);
72
+ for (const id of all) {
73
+ if (SAFE_ID.test(id) && !RESERVED.has(id.toLowerCase())) {
74
+ ids.set(id, id);
75
+ used.add(id);
76
+ }
77
+ }
78
+ for (const id of all) {
79
+ if (ids.has(id)) {
80
+ continue;
81
+ }
82
+ const base = `n_${id.replace(/[^A-Za-z0-9_]/g, '_')}`;
83
+ let candidate = base;
84
+ for (let i = 2; used.has(candidate); i += 1) {
85
+ candidate = `${base}_${i}`;
86
+ }
87
+ ids.set(id, candidate);
88
+ used.add(candidate);
89
+ }
90
+ return ids;
91
+ }
92
+
93
+ const FLOW_SHAPES = Object.freeze({
94
+ box: ['[', ']'],
95
+ round: ['(', ')'],
96
+ stadium: ['([', '])'],
97
+ circle: ['((', '))'],
98
+ diamond: ['{', '}'],
99
+ start: ['((', '))'],
100
+ end: ['(((', ')))'],
101
+ });
102
+
103
+ /**
104
+ * Lines of the items of each group, nested: `open(group)`, the children,
105
+ * `close`. Items outside every group come first.
106
+ */
107
+ function nested(model, lineOf, open, close) {
108
+ const lines = [];
109
+ const visit = (groupId, depth) => {
110
+ const pad = ' '.repeat(depth);
111
+ for (const group of model.groups.filter((g) => g.group === groupId)) {
112
+ lines.push(pad + open(group));
113
+ visit(group.id, depth + 1);
114
+ lines.push(pad + close);
115
+ }
116
+ for (const node of model.nodes.filter((n) => n.group === groupId)) {
117
+ const line = lineOf(node);
118
+ if (line !== null) {
119
+ lines.push(pad + line);
120
+ }
121
+ }
122
+ };
123
+ visit(null, 1);
124
+ return lines;
125
+ }
126
+
127
+ function flowchart(model) {
128
+ const ids = mermaidIds(model);
129
+ const lines = [`flowchart ${DIRECTIONS[model.direction]}`];
130
+ lines.push(
131
+ ...nested(
132
+ model,
133
+ (node) => {
134
+ const [open, close] = FLOW_SHAPES[node.shape];
135
+ return `${ids.get(node.id)}${open}"${escapeMermaidLabel(node.label)}"${close}`;
136
+ },
137
+ (group) =>
138
+ `subgraph ${ids.get(group.id)} ["${escapeMermaidLabel(group.label)}"]`,
139
+ 'end'
140
+ )
141
+ );
142
+ for (const edge of model.edges) {
143
+ const arrow = edge.label === null ? '-->' : `-->|${edgeLabel(edge.label)}|`;
144
+ lines.push(` ${ids.get(edge.from)} ${arrow} ${ids.get(edge.to)}`);
145
+ }
146
+ return lines;
147
+ }
148
+
149
+ const isPseudo = (node) => node.shape === 'start' || node.shape === 'end';
150
+
151
+ function state(model) {
152
+ const ids = mermaidIds(model);
153
+ const lines = [
154
+ 'stateDiagram-v2',
155
+ ` direction ${DIRECTIONS[model.direction].replace('TD', 'TB')}`,
156
+ ];
157
+ lines.push(
158
+ ...nested(
159
+ model,
160
+ (node) =>
161
+ isPseudo(node)
162
+ ? null
163
+ : `state "${escapeMermaidLabel(node.label)}" as ${ids.get(node.id)}`,
164
+ (group) =>
165
+ `state "${escapeMermaidLabel(group.label)}" as ${ids.get(group.id)} {`,
166
+ '}'
167
+ )
168
+ );
169
+ const nodes = new Map(model.nodes.map((node) => [node.id, node]));
170
+ const end = (id) => (isPseudo(nodes.get(id)) ? '[*]' : ids.get(id));
171
+ for (const edge of model.edges) {
172
+ const label =
173
+ edge.label === null ? '' : ` : ${escapeMermaidLabel(edge.label)}`;
174
+ lines.push(` ${end(edge.from)} --> ${end(edge.to)}${label}`);
175
+ }
176
+ return lines;
177
+ }
178
+
179
+ function sequence(model) {
180
+ const ids = mermaidIds(model);
181
+ const lines = ['sequenceDiagram'];
182
+ for (const node of model.nodes) {
183
+ lines.push(
184
+ ` participant ${ids.get(node.id)} as ${escapeMermaidLabel(node.label)}`
185
+ );
186
+ }
187
+ for (const edge of model.edges) {
188
+ const label = escapeMermaidLabel(edge.label ?? '');
189
+ lines.push(` ${ids.get(edge.from)}->>${ids.get(edge.to)}: ${label}`);
190
+ }
191
+ return lines;
192
+ }
193
+
194
+ function classDiagram(model) {
195
+ const ids = mermaidIds(model);
196
+ const lines = [
197
+ 'classDiagram',
198
+ ` direction ${DIRECTIONS[model.direction].replace('TD', 'TB')}`,
199
+ ];
200
+ for (const node of model.nodes) {
201
+ lines.push(
202
+ ` class ${ids.get(node.id)}["${escapeMermaidLabel(node.label)}"]`
203
+ );
204
+ }
205
+ for (const edge of model.edges) {
206
+ const label =
207
+ edge.label === null ? '' : ` : ${escapeMermaidLabel(edge.label)}`;
208
+ lines.push(` ${ids.get(edge.from)} --> ${ids.get(edge.to)}${label}`);
209
+ }
210
+ return lines;
211
+ }
212
+
213
+ const WRITERS = Object.freeze({
214
+ flowchart,
215
+ state,
216
+ sequence,
217
+ class: classDiagram,
218
+ });
219
+
220
+ /**
221
+ * Mermaid text of a diagram model (`flowchart`, `state`, `sequence` and
222
+ * `class` kinds), without a trailing newline.
223
+ * @param {DiagramModel} model
224
+ * @returns {string}
225
+ */
226
+ export function toMermaid(model) {
227
+ const write = WRITERS[model.kind];
228
+ if (!write) {
229
+ throw new TypeError(`toMermaid: unknown diagram kind "${model.kind}"`);
230
+ }
231
+ return write(model).join('\n');
232
+ }
@@ -0,0 +1,229 @@
1
+ /**
2
+ * The Mermaid adapter: `<ui-mermaid-view>` renders Mermaid text with Mermaid,
3
+ * imported on the first render only (`import('mermaid')`) and initialised
4
+ * with `securityLevel: 'strict'`. While Mermaid loads, and whenever the
5
+ * import or the render fails, the source text is shown in a `pre` with an
6
+ * error message, so a diagram never disappears (link-assistant/formal-ai
7
+ * issue 1190).
8
+ *
9
+ * Mermaid (MIT) is an optional peer dependency: an app that never shows a
10
+ * Mermaid diagram never downloads it.
11
+ */
12
+
13
+ /** @typedef {{initialize(config: object): void, render(id: string, text: string): Promise<{svg: string}>}} MermaidApi */
14
+ /** @typedef {() => Promise<any>} MermaidImporter resolves to the module */
15
+
16
+ export const MERMAID_CONFIG = Object.freeze({
17
+ startOnLoad: false,
18
+ securityLevel: 'strict',
19
+ });
20
+
21
+ /** @type {MermaidImporter} */
22
+ const importMermaid = () => import('mermaid');
23
+
24
+ let importer = importMermaid;
25
+ /** @type {Promise<MermaidApi>|null} */
26
+ let loading = null;
27
+ let renderCount = 0;
28
+
29
+ /**
30
+ * Replace how Mermaid is imported (a CDN URL, a bundled copy, a stub in
31
+ * tests). Resets the cached module.
32
+ * @param {MermaidImporter|null} next `null`: back to `import('mermaid')`
33
+ */
34
+ export function setMermaidImporter(next) {
35
+ if (next !== null && typeof next !== 'function') {
36
+ throw new TypeError('setMermaidImporter: expected a function or null');
37
+ }
38
+ importer = next ?? importMermaid;
39
+ loading = null;
40
+ }
41
+
42
+ /**
43
+ * Import and initialise Mermaid on the first call; a failed import is tried
44
+ * again by the next call.
45
+ * @returns {Promise<MermaidApi>}
46
+ */
47
+ export function loadMermaid() {
48
+ if (loading === null) {
49
+ loading = Promise.resolve()
50
+ .then(() => importer())
51
+ .then((module) => {
52
+ const mermaid = module?.default ?? module;
53
+ if (typeof mermaid?.render !== 'function') {
54
+ throw new TypeError('the mermaid module has no render function');
55
+ }
56
+ mermaid.initialize({ ...MERMAID_CONFIG });
57
+ return mermaid;
58
+ });
59
+ loading.catch(() => {
60
+ loading = null;
61
+ });
62
+ }
63
+ return loading;
64
+ }
65
+
66
+ /**
67
+ * Render Mermaid text to an SVG string with the lazily loaded Mermaid.
68
+ * @param {string} source
69
+ * @returns {Promise<string>}
70
+ */
71
+ export async function renderMermaid(source) {
72
+ const mermaid = await loadMermaid();
73
+ renderCount += 1;
74
+ const { svg } = await mermaid.render(`ui-mermaid-${renderCount}`, source);
75
+ return svg;
76
+ }
77
+
78
+ const VISUALLY_HIDDEN =
79
+ 'position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap;border:0';
80
+
81
+ /** Inline style of content kept for screen readers only. */
82
+ export const visuallyHiddenStyle = () => VISUALLY_HIDDEN;
83
+
84
+ /**
85
+ * Show the source text of a diagram in a `pre`, with an optional error
86
+ * message (`role="alert"`) before it. Text only, never markup.
87
+ * @param {HTMLElement} host
88
+ * @param {string} source
89
+ * @param {string|null} message
90
+ */
91
+ export function showSource(host, source, message) {
92
+ const doc = host.ownerDocument;
93
+ host.replaceChildren();
94
+ if (message !== null) {
95
+ const error = doc.createElement('p');
96
+ error.className = 'ui-diagram-error';
97
+ error.setAttribute('role', 'alert');
98
+ error.textContent = message;
99
+ host.appendChild(error);
100
+ }
101
+ const pre = doc.createElement('pre');
102
+ pre.className = 'ui-diagram-source';
103
+ pre.tabIndex = 0;
104
+ const code = doc.createElement('code');
105
+ code.textContent = source;
106
+ pre.appendChild(code);
107
+ host.appendChild(pre);
108
+ }
109
+
110
+ /**
111
+ * Set `data-state` and announce it with a `ui-diagram-state` event.
112
+ * @param {HTMLElement} host
113
+ * @param {'loading'|'ready'|'error'} state
114
+ * @param {object} [detail]
115
+ */
116
+ export function setState(host, state, detail = {}) {
117
+ host.dataset.state = state;
118
+ host.dispatchEvent(
119
+ new host.ownerDocument.defaultView.CustomEvent('ui-diagram-state', {
120
+ bubbles: true,
121
+ detail: { state, ...detail },
122
+ })
123
+ );
124
+ }
125
+
126
+ const errorText = (error) =>
127
+ error instanceof Error ? error.message : String(error);
128
+
129
+ /**
130
+ * The `<ui-mermaid-view>` class for a window.
131
+ * @param {typeof HTMLElement} Base
132
+ */
133
+ function mermaidViewClass(Base) {
134
+ return class MermaidView extends Base {
135
+ static get observedAttributes() {
136
+ return ['label'];
137
+ }
138
+
139
+ constructor() {
140
+ super();
141
+ /** @type {string|null} */
142
+ this._source = null;
143
+ this._run = 0;
144
+ }
145
+
146
+ /** The Mermaid text (defaults to the text content at first connect). */
147
+ get source() {
148
+ return this._source ?? '';
149
+ }
150
+
151
+ set source(value) {
152
+ this._source = String(value);
153
+ if (this.isConnected) {
154
+ this.refresh();
155
+ }
156
+ }
157
+
158
+ connectedCallback() {
159
+ if (this._source === null) {
160
+ this._source = (this.textContent ?? '').trim();
161
+ }
162
+ this.refresh();
163
+ }
164
+
165
+ attributeChangedCallback() {
166
+ const svg = this.querySelector('svg');
167
+ if (svg) {
168
+ svg.setAttribute('aria-label', this.label);
169
+ }
170
+ }
171
+
172
+ get label() {
173
+ return this.getAttribute('label') ?? 'Mermaid diagram';
174
+ }
175
+
176
+ /** Render again; resolves to the state reached. */
177
+ async refresh() {
178
+ const run = ++this._run;
179
+ const source = this.source;
180
+ showSource(this, source, null);
181
+ this.setAttribute('aria-busy', 'true');
182
+ setState(this, 'loading');
183
+ let svg;
184
+ let failure = null;
185
+ try {
186
+ svg = await renderMermaid(source);
187
+ } catch (error) {
188
+ failure = error;
189
+ }
190
+ if (run !== this._run) {
191
+ return this.dataset.state;
192
+ }
193
+ this.removeAttribute('aria-busy');
194
+ if (failure !== null) {
195
+ showSource(
196
+ this,
197
+ source,
198
+ `The diagram could not be drawn with Mermaid (${errorText(failure)}). Its source is shown instead.`
199
+ );
200
+ setState(this, 'error', { error: failure });
201
+ return 'error';
202
+ }
203
+ // Mermaid output, sanitised by Mermaid itself (securityLevel strict).
204
+ this.innerHTML = svg;
205
+ const drawn = this.querySelector('svg');
206
+ if (drawn) {
207
+ drawn.setAttribute('role', 'img');
208
+ drawn.setAttribute('aria-label', this.label);
209
+ }
210
+ setState(this, 'ready');
211
+ return 'ready';
212
+ }
213
+ };
214
+ }
215
+
216
+ /**
217
+ * Define `<ui-mermaid-view>` in a window (once).
218
+ * @param {Window & typeof globalThis} [win]
219
+ * @returns {CustomElementConstructor}
220
+ */
221
+ export function defineMermaidView(win = globalThis) {
222
+ const existing = win.customElements.get('ui-mermaid-view');
223
+ if (existing) {
224
+ return existing;
225
+ }
226
+ const MermaidView = mermaidViewClass(win.HTMLElement);
227
+ win.customElements.define('ui-mermaid-view', MermaidView);
228
+ return MermaidView;
229
+ }
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Our SVG renderer of `flowchart` and `state` diagrams: a model and its
3
+ * layout become one deterministic SVG string. Every label is escaped text;
4
+ * colours come from design tokens (CSS custom properties of
5
+ * `@link-foundation/ui-tokens`, with fallbacks), so the drawing follows the
6
+ * theme and `prefers-color-scheme` of the page.
7
+ */
8
+
9
+ import { describeDiagram } from './diagram-model.js';
10
+
11
+ /** @typedef {import('./diagram-model.js').DiagramModel} DiagramModel */
12
+ /** @typedef {import('./layout-dagre.js').Layout} Layout */
13
+
14
+ /**
15
+ * The colours and font of a drawing: any CSS value (`#1d1b20`,
16
+ * `var(--color-on-surface)`).
17
+ * @typedef {object} DiagramTokens
18
+ * @property {string} [surface] node fill
19
+ * @property {string} [onSurface] text and node outline
20
+ * @property {string} [edge] edge lines and arrowheads
21
+ * @property {string} [group] group fill
22
+ * @property {string} [groupOutline]
23
+ * @property {string} [accent] start and end states
24
+ * @property {string} [fontFamily]
25
+ * @property {number} [fontSize] in px
26
+ */
27
+
28
+ /** @type {Readonly<Required<DiagramTokens>>} */
29
+ export const DEFAULT_DIAGRAM_TOKENS = Object.freeze({
30
+ surface: 'var(--color-surface, #fffbfe)',
31
+ onSurface: 'var(--color-on-surface, #1d1b20)',
32
+ edge: 'var(--color-on-surface-variant, #49454f)',
33
+ group: 'var(--color-surface-container, #f3edf7)',
34
+ groupOutline: 'var(--color-outline, #79747e)',
35
+ accent: 'var(--color-primary, #6750a4)',
36
+ fontFamily: 'system-ui, sans-serif',
37
+ fontSize: 14,
38
+ });
39
+
40
+ export const SVG_KINDS = Object.freeze(['flowchart', 'state']);
41
+
42
+ const XML_ESCAPES = {
43
+ '&': '&amp;',
44
+ '<': '&lt;',
45
+ '>': '&gt;',
46
+ '"': '&quot;',
47
+ "'": '&#39;',
48
+ };
49
+
50
+ /**
51
+ * Escape text for XML text and attribute values.
52
+ * @param {string} text
53
+ * @returns {string}
54
+ */
55
+ export function escapeXml(text) {
56
+ return String(text).replace(/[&<>"']/g, (c) => XML_ESCAPES[c]);
57
+ }
58
+
59
+ /** A CSS value that is safe inside a `style` attribute. */
60
+ function cssValue(value) {
61
+ const text = String(value);
62
+ if (/[;{}<>"\\]/.test(text)) {
63
+ throw new TypeError(
64
+ `renderDiagramSvg: unsafe token value ${JSON.stringify(text)}`
65
+ );
66
+ }
67
+ return text;
68
+ }
69
+
70
+ /** A font size in px: a positive finite number. */
71
+ function fontSize(value) {
72
+ const size = Number(value);
73
+ if (!Number.isFinite(size) || size <= 0) {
74
+ throw new TypeError(
75
+ `renderDiagramSvg: fontSize must be a positive number, not ${JSON.stringify(value)}`
76
+ );
77
+ }
78
+ return size;
79
+ }
80
+
81
+ const num = (value) => String(Math.round(value * 100) / 100);
82
+
83
+ /** A safe id fragment for `id` attributes: letters, digits, `-` and `_`. */
84
+ const idPart = (text) => String(text).replace(/[^A-Za-z0-9_-]/g, '_');
85
+
86
+ function shapeSvg(node, b, t) {
87
+ const left = b.x - b.width / 2;
88
+ const top = b.y - b.height / 2;
89
+ const fill = `fill:${t.surface};stroke:${t.onSurface};stroke-width:1.5`;
90
+ switch (node.shape) {
91
+ case 'diamond':
92
+ return `<polygon points="${num(b.x)},${num(top)} ${num(left + b.width)},${num(b.y)} ${num(b.x)},${num(top + b.height)} ${num(left)},${num(b.y)}" style="${fill}"/>`;
93
+ case 'circle':
94
+ return `<ellipse cx="${num(b.x)}" cy="${num(b.y)}" rx="${num(b.width / 2)}" ry="${num(b.height / 2)}" style="${fill}"/>`;
95
+ case 'start':
96
+ return `<circle cx="${num(b.x)}" cy="${num(b.y)}" r="${num(Math.min(b.width, b.height) / 2)}" style="fill:${t.accent}"/>`;
97
+ case 'end': {
98
+ const r = Math.min(b.width, b.height) / 2;
99
+ return `<circle cx="${num(b.x)}" cy="${num(b.y)}" r="${num(r)}" style="fill:none;stroke:${t.accent};stroke-width:2"/><circle cx="${num(b.x)}" cy="${num(b.y)}" r="${num(r - 5)}" style="fill:${t.accent}"/>`;
100
+ }
101
+ default: {
102
+ const radius =
103
+ { box: 4, round: 12, stadium: b.height / 2 }[node.shape] ?? 4;
104
+ return `<rect x="${num(left)}" y="${num(top)}" width="${num(b.width)}" height="${num(b.height)}" rx="${num(radius)}" style="${fill}"/>`;
105
+ }
106
+ }
107
+ }
108
+
109
+ function textSvg(x, y, text, t, { size = t.fontSize, extra = '' } = {}) {
110
+ return `<text x="${num(x)}" y="${num(y)}" text-anchor="middle" dominant-baseline="central" style="fill:${t.onSurface};font-family:${t.fontFamily};font-size:${num(size)}px${extra}">${escapeXml(text)}</text>`;
111
+ }
112
+
113
+ function nodeSvg(node, b, t) {
114
+ const label =
115
+ node.shape === 'start' || node.shape === 'end'
116
+ ? ''
117
+ : textSvg(b.x, b.y, node.label, t);
118
+ return `<g class="ui-diagram-node" data-id="${escapeXml(node.id)}">${shapeSvg(node, b, t)}${label}</g>`;
119
+ }
120
+
121
+ function edgeSvg(edge, e, t, markerId) {
122
+ const d = e.points
123
+ .map((p, i) => `${i === 0 ? 'M' : 'L'}${num(p.x)} ${num(p.y)}`)
124
+ .join(' ');
125
+ let label = '';
126
+ if (edge.label !== null) {
127
+ const at = e.labelAt ?? e.points[Math.floor(e.points.length / 2)];
128
+ const width = edge.label.length * 7 + 8;
129
+ label = `<rect x="${num(at.x - width / 2)}" y="${num(at.y - 10)}" width="${num(width)}" height="20" rx="4" style="fill:${t.surface}"/>${textSvg(at.x, at.y, edge.label, t, { size: t.fontSize - 2 })}`;
130
+ }
131
+ return `<g class="ui-diagram-edge" data-id="${escapeXml(edge.id)}"><path d="${d}" marker-end="url(#${markerId})" style="fill:none;stroke:${t.edge};stroke-width:1.5"/>${label}</g>`;
132
+ }
133
+
134
+ function groupSvg(group, b, t) {
135
+ const left = b.x - b.width / 2;
136
+ const top = b.y - b.height / 2;
137
+ return `<g class="ui-diagram-group" data-id="${escapeXml(group.id)}"><rect x="${num(left)}" y="${num(top)}" width="${num(b.width)}" height="${num(b.height)}" rx="8" style="fill:${t.group};stroke:${t.groupOutline};stroke-dasharray:4 3"/>${textSvg(b.x, top + 14, group.label, t, { extra: ';font-weight:600' })}</g>`;
138
+ }
139
+
140
+ /**
141
+ * A one-sentence summary of a diagram, used as its accessible name.
142
+ * @param {DiagramModel} model
143
+ * @returns {string}
144
+ */
145
+ export function diagramSummary(model) {
146
+ const kind =
147
+ model.kind === 'flowchart'
148
+ ? 'Flowchart'
149
+ : `${model.kind[0].toUpperCase()}${model.kind.slice(1)} diagram`;
150
+ const title = model.label ?? model.id;
151
+ const { nodes, edges } = describeDiagram(model);
152
+ return `${kind} ${title}: ${nodes.length} ${nodes.length === 1 ? 'node' : 'nodes'}, ${edges.length} ${edges.length === 1 ? 'connection' : 'connections'}`;
153
+ }
154
+
155
+ /** Group depth, so outer groups are drawn under inner ones. */
156
+ function depthOf(model, group) {
157
+ const parents = new Map(model.groups.map((g) => [g.id, g.group]));
158
+ let depth = 0;
159
+ for (let at = group.group; at !== null; at = parents.get(at) ?? null) {
160
+ depth += 1;
161
+ }
162
+ return depth;
163
+ }
164
+
165
+ /**
166
+ * Render a laid-out diagram as an SVG string (`role="img"` with an
167
+ * `aria-label`, and the same summary as `<title>`). Deterministic: the same arguments give the
168
+ * same string.
169
+ * @param {DiagramModel} model
170
+ * @param {Layout} layout
171
+ * @param {DiagramTokens & {idPrefix?: string}} [tokens] `idPrefix` makes
172
+ * the marker id unique when one model is drawn twice on a page
173
+ * @returns {string}
174
+ */
175
+ export function renderDiagramSvg(model, layout, tokens = {}) {
176
+ if (!SVG_KINDS.includes(model.kind)) {
177
+ throw new TypeError(
178
+ `renderDiagramSvg: ${model.kind} diagrams are drawn by Mermaid (toMermaid)`
179
+ );
180
+ }
181
+ const { idPrefix, ...overrides } = tokens;
182
+ const t = Object.fromEntries(
183
+ Object.entries({ ...DEFAULT_DIAGRAM_TOKENS, ...overrides }).map(
184
+ ([k, v]) => [k, k === 'fontSize' ? fontSize(v) : cssValue(v)]
185
+ )
186
+ );
187
+ const prefix = idPart(idPrefix ?? `ui-diagram-${model.id}`);
188
+ const markerId = `${prefix}-arrow`;
189
+ const nodes = new Map(layout.nodes.map((b) => [b.id, b]));
190
+ const edges = new Map(layout.edges.map((e) => [e.id, e]));
191
+ const groups = new Map((layout.groups ?? []).map((b) => [b.id, b]));
192
+ const parts = [
193
+ `<svg xmlns="http://www.w3.org/2000/svg" class="ui-diagram-svg" viewBox="0 0 ${num(layout.width)} ${num(layout.height)}" width="${num(layout.width)}" height="${num(layout.height)}" role="img" aria-label="${escapeXml(diagramSummary(model))}">`,
194
+ `<title id="${prefix}-title">${escapeXml(diagramSummary(model))}</title>`,
195
+ `<defs><marker id="${markerId}" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse"><path d="M0 0 L10 5 L0 10 z" style="fill:${t.edge}"/></marker></defs>`,
196
+ ];
197
+ const sorted = [...model.groups].sort(
198
+ (a, b) => depthOf(model, a) - depthOf(model, b)
199
+ );
200
+ for (const group of sorted) {
201
+ if (groups.has(group.id)) {
202
+ parts.push(groupSvg(group, groups.get(group.id), t));
203
+ }
204
+ }
205
+ for (const edge of model.edges) {
206
+ if (edges.has(edge.id)) {
207
+ parts.push(edgeSvg(edge, edges.get(edge.id), t, markerId));
208
+ }
209
+ }
210
+ for (const node of model.nodes) {
211
+ parts.push(nodeSvg(node, nodes.get(node.id), t));
212
+ }
213
+ parts.push('</svg>');
214
+ return parts.join('');
215
+ }