@link-foundation/ui-components 0.0.0-stage → 0.1.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,245 @@
1
+ import { linkGeometry, pathToSvgD, endAngles } from './geometry.js';
2
+ import {
3
+ escapeAttribute,
4
+ svgMarkerDefs,
5
+ markerElementId,
6
+ drawMarker,
7
+ getMarker,
8
+ } from './markers.js';
9
+ import { visibleLabels } from './labels.js';
10
+ import { networkNeighbours } from './network-model.js';
11
+
12
+ /**
13
+ * Two shared geometry curves meet at the allocated centre anchor. This works
14
+ * for references to links even in cyclic networks: no recursive resolution.
15
+ */
16
+ export function networkGeometry(link, positions) {
17
+ const center = positions.get(link.id) ?? { x: 0, y: 0 };
18
+ const source = positions.get(link.source) ?? {
19
+ x: center.x - 24,
20
+ y: center.y - 12,
21
+ };
22
+ const target = positions.get(link.target) ?? {
23
+ x: center.x + 24,
24
+ y: center.y + 12,
25
+ };
26
+ const loop = (a, b) => a.x === b.x && a.y === b.y;
27
+ const first = linkGeometry({
28
+ source,
29
+ target: center,
30
+ selfLoop: loop(source, center),
31
+ loopRadius: 16,
32
+ });
33
+ const last = linkGeometry({
34
+ source: center,
35
+ target,
36
+ selfLoop: loop(center, target),
37
+ loopRadius: 16,
38
+ });
39
+ // A self-reference loop from #41 starts and finishes at its source anchor.
40
+ return {
41
+ source,
42
+ target,
43
+ center,
44
+ path: [...first.path, ...last.path],
45
+ points: [...first.points, ...last.points],
46
+ };
47
+ }
48
+
49
+ /** Static geometry is cached by the element; pan/zoom reuses the same paths. */
50
+ export function networkShapes(
51
+ network,
52
+ positions,
53
+ style = 'glyph',
54
+ previous = new Map()
55
+ ) {
56
+ const shapes = new Map();
57
+ for (const link of network.links.values()) {
58
+ const old = previous.get(link.id);
59
+ if (
60
+ old &&
61
+ old.style === style &&
62
+ old.sourceId === link.source &&
63
+ old.targetId === link.target &&
64
+ old.geometry.center === positions.get(link.id) &&
65
+ (link.source === 0 ||
66
+ old.geometry.source === positions.get(link.source)) &&
67
+ (link.target === 0 || old.geometry.target === positions.get(link.target))
68
+ ) {
69
+ shapes.set(link.id, old);
70
+ continue;
71
+ }
72
+ const geometry = networkGeometry(link, positions);
73
+ shapes.set(link.id, {
74
+ id: link.id,
75
+ sourceId: link.source,
76
+ targetId: link.target,
77
+ geometry,
78
+ d: pathToSvgD(geometry.path),
79
+ ends: {
80
+ source: link.source === 0 ? 'cross' : 'bar',
81
+ target: link.target === 0 ? 'cross' : 'arrow',
82
+ },
83
+ style,
84
+ });
85
+ }
86
+ return shapes;
87
+ }
88
+
89
+ export function networkLabels(
90
+ network,
91
+ positions,
92
+ zoom,
93
+ options,
94
+ selected = []
95
+ ) {
96
+ const labels = [...network.points.values(), ...network.links.values()].map(
97
+ (item) => {
98
+ const at = positions.get(item.id) ?? { x: 0, y: 0 };
99
+ const text = String(item.label ?? item.id);
100
+ return {
101
+ id: item.id,
102
+ text,
103
+ x: at.x + 8,
104
+ y: at.y - 18,
105
+ width: [...text].reduce(
106
+ (width, char) => width + (char.codePointAt(0) > 255 ? 16 : 8),
107
+ 0
108
+ ),
109
+ height: 16,
110
+ priority: selected.includes(item.id) ? 1 : 0,
111
+ };
112
+ }
113
+ );
114
+ const visible = new Set(visibleLabels(labels, zoom, options));
115
+ return labels.filter((label) => visible.has(label.id));
116
+ }
117
+
118
+ export function highlightIds(network, hovered) {
119
+ return hovered === null
120
+ ? new Set()
121
+ : new Set([hovered, ...networkNeighbours(network, hovered)]);
122
+ }
123
+
124
+ const attr = (value) => escapeAttribute(String(value));
125
+
126
+ export function networkItemSvg(
127
+ shape,
128
+ positions,
129
+ colors,
130
+ selected,
131
+ highlighted
132
+ ) {
133
+ const { id, geometry, ends, style } = shape;
134
+ const color = selected
135
+ ? colors.focus
136
+ : highlighted
137
+ ? colors.blueprintStart
138
+ : colors.line;
139
+ const c = geometry.center;
140
+ const line = (d, start, end) =>
141
+ `<path d="${d}" fill="none" stroke="${attr(color)}" stroke-width="${selected || highlighted ? 2 : 1}" marker-start="url(#${markerElementId('network', 'source', start)})" marker-end="url(#${markerElementId('network', 'target', end)})"></path>`;
142
+ const paths =
143
+ style === 'node-edge'
144
+ ? `${line(shape.d, ends.source, ends.target)}<circle cx="${c.x}" cy="${c.y}" r="5" fill="${attr(color)}"></circle>`
145
+ : line(shape.d, ends.source, ends.target);
146
+ return `<g data-id="${attr(id)}" data-selected="${selected}" data-highlighted="${highlighted}">${paths}</g>`;
147
+ }
148
+
149
+ /** Marker definitions come exclusively from #41, shared with Canvas. */
150
+ export function networkDefs(colors) {
151
+ return ['bar', 'arrow', 'cross']
152
+ .map((shape) =>
153
+ svgMarkerDefs({ source: shape, target: shape }, colors, {
154
+ idPrefix: 'network',
155
+ })
156
+ )
157
+ .join('')
158
+ .replaceAll('/>', '></path>');
159
+ }
160
+
161
+ export function networkPointSvg(
162
+ id,
163
+ point,
164
+ colors,
165
+ selected = false,
166
+ highlighted = false
167
+ ) {
168
+ return `<circle data-point="${attr(id)}" cx="${point.x}" cy="${point.y}" r="4" fill="${attr(selected ? colors.focus : highlighted ? colors.blueprintStart : colors.line)}"></circle>`;
169
+ }
170
+
171
+ export function networkLabelSvg(label, colors) {
172
+ return `<text x="${label.x}" y="${label.y + 13}" font-family="monospace" font-size="13" fill="${attr(colors.line)}">${attr(label.text)}</text>`;
173
+ }
174
+
175
+ /** Paint a cached scene without allocating geometry or starting a frame loop. */
176
+ export function drawNetworkCanvas(ctx, shapes, network, positions, options) {
177
+ const {
178
+ colors,
179
+ view,
180
+ width,
181
+ height,
182
+ selected = [],
183
+ hovered,
184
+ pixelRatio = 1,
185
+ } = options;
186
+ const highlighted = highlightIds(network, hovered);
187
+ ctx.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
188
+ ctx.fillStyle = colors.background;
189
+ ctx.fillRect(0, 0, width, height);
190
+ ctx.transform(view.k, 0, 0, view.k, view.x, view.y);
191
+ for (const shape of shapes.values()) {
192
+ const { id, geometry, ends } = shape;
193
+ const color = selected.includes(id)
194
+ ? colors.focus
195
+ : highlighted.has(id)
196
+ ? colors.blueprintStart
197
+ : colors.line;
198
+ ctx.lineWidth = selected.includes(id) || highlighted.has(id) ? 2 : 1;
199
+ ctx.strokeStyle = color;
200
+ ctx.beginPath();
201
+ ctx.moveTo(geometry.path[0].p0.x, geometry.path[0].p0.y);
202
+ for (const s of geometry.path) {
203
+ ctx.bezierCurveTo(s.c1.x, s.c1.y, s.c2.x, s.c2.y, s.p3.x, s.p3.y);
204
+ }
205
+ ctx.stroke();
206
+ const angles = endAngles(geometry.path);
207
+ for (const [end, at, angle] of [
208
+ ['source', geometry.path[0].p0, angles.start],
209
+ ['target', geometry.path.at(-1).p3, angles.end],
210
+ ]) {
211
+ drawMarker(ctx, getMarker(ends[end]), at, angle, ctx.lineWidth, {
212
+ color: colors[end],
213
+ Path2D: options.Path2D,
214
+ });
215
+ }
216
+ if (shape.style === 'node-edge') {
217
+ ctx.beginPath();
218
+ ctx.arc(geometry.center.x, geometry.center.y, 5, 0, Math.PI * 2);
219
+ ctx.fillStyle = color;
220
+ ctx.fill();
221
+ }
222
+ }
223
+ for (const id of network.points.keys()) {
224
+ const point = positions.get(id);
225
+ ctx.beginPath();
226
+ ctx.arc(point.x, point.y, 4, 0, Math.PI * 2);
227
+ ctx.fillStyle = selected.includes(id)
228
+ ? colors.focus
229
+ : highlighted.has(id)
230
+ ? colors.blueprintStart
231
+ : colors.line;
232
+ ctx.fill();
233
+ }
234
+ for (const label of networkLabels(
235
+ network,
236
+ positions,
237
+ view.k,
238
+ options.labels,
239
+ selected
240
+ )) {
241
+ ctx.fillStyle = colors.line;
242
+ ctx.font = '13px monospace';
243
+ ctx.fillText(label.text, label.x, label.y + 13);
244
+ }
245
+ }
@@ -0,0 +1,82 @@
1
+ import { parse } from '@link-foundation/ui-core';
2
+ import { networkVocabulary } from './network-vocabulary.js';
3
+ import { rawSublinks } from './model.js';
4
+
5
+ const property = (node, name) =>
6
+ node.properties?.filter((p) => p.name === name).at(-1)?.values?.[0];
7
+
8
+ /** ui-store keeps link endpoints as properties or the first two positional atoms. */
9
+ export function storeNetworkLink(store, id) {
10
+ const node = store.get(id);
11
+ if (!node || node.kind !== 'link') {
12
+ return null;
13
+ }
14
+ return {
15
+ id,
16
+ source: property(node, 'source') ?? node.positional[0] ?? 0,
17
+ target: property(node, 'target') ?? node.positional[1] ?? 0,
18
+ label: property(node, 'label') ?? id,
19
+ };
20
+ }
21
+
22
+ export function storeNetworkLinks(store) {
23
+ const result = [];
24
+ const pending = [...store.roots()];
25
+ while (pending.length) {
26
+ const id = pending.pop();
27
+ const link = storeNetworkLink(store, id);
28
+ if (link) {
29
+ result.push(link);
30
+ }
31
+ pending.push(...store.children(id));
32
+ }
33
+ return result.reverse();
34
+ }
35
+
36
+ /** Read component configuration using the official ui-core/LiNo projection. */
37
+ export function readNetworkSource(text) {
38
+ const parsed = parse(text, {
39
+ checks: false,
40
+ vocabulary: networkVocabulary(),
41
+ });
42
+ const root = parsed.roots.find((node) => node.kind === 'links-network');
43
+ return {
44
+ ...readNetworkRaw(root ? networkRaw(root, root.children) : []),
45
+ diagnostics: parsed.diagnostics,
46
+ };
47
+ }
48
+
49
+ export function networkRaw(element, children = []) {
50
+ return [
51
+ ...(element.properties ?? []).map((p) => [p.name, ...p.values]),
52
+ ...rawSublinks(element, children),
53
+ ];
54
+ }
55
+
56
+ export function readNetworkRaw(raw) {
57
+ const fields = new Map(
58
+ raw.filter(Array.isArray).map((value) => [value[0], value.slice(1)])
59
+ );
60
+ const links = (fields.get('items') ?? [])
61
+ .filter(Array.isArray)
62
+ .map((value) => {
63
+ const props = new Map(
64
+ value.filter(Array.isArray).map((p) => [p[0], p[1]])
65
+ );
66
+ return {
67
+ id: props.get('id') ?? value[0],
68
+ source: props.get('source') ?? value[1] ?? 0,
69
+ target: props.get('target') ?? value[2] ?? 0,
70
+ label: props.get('label') ?? props.get('id') ?? value[0],
71
+ };
72
+ });
73
+ const labels = new Map(
74
+ (fields.get('labels') ?? []).filter(Array.isArray).map((p) => [p[0], p[1]])
75
+ );
76
+ return {
77
+ links,
78
+ layout: fields.get('layout')?.[0] ?? 'circle',
79
+ style: fields.get('style')?.[0] ?? 'glyph',
80
+ minZoom: Number(labels.get('min-zoom') ?? 0.6),
81
+ };
82
+ }
@@ -0,0 +1,18 @@
1
+ import { defaultVocabulary, loadVocabulary } from '@link-foundation/ui-core';
2
+
3
+ /** Extend the UI dialect explicitly, without mutating the shared vocabulary. */
4
+ export function networkVocabulary() {
5
+ const base = defaultVocabulary();
6
+ const extension = loadVocabulary(`links-network: kind
7
+ property on action multi
8
+ property label string
9
+ property layout
10
+ enum circle grid hex spiral force layered
11
+ property style
12
+ enum glyph node-edge
13
+ property labels any
14
+ property items any
15
+ children none
16
+ `);
17
+ return { ...base, kinds: new Map([...base.kinds, ...extension.kinds]) };
18
+ }
@@ -0,0 +1,199 @@
1
+ import { parseNested, formatLinks } from '@link-foundation/ui-core';
2
+ import { networkToRaster } from './export.js';
3
+
4
+ const clone = (value) => globalThis.structuredClone(value);
5
+
6
+ function checkedInput(previous, patch) {
7
+ const input = clone({ ...previous, ...patch });
8
+ if (
9
+ typeof input.index !== 'string' ||
10
+ !/^(0|[1-9][0-9]*)$/u.test(input.index)
11
+ ) {
12
+ throw new TypeError('Network index must be a nonnegative decimal string');
13
+ }
14
+ if (typeof input.options !== 'string') {
15
+ throw new TypeError('Network options must be Links Notation text');
16
+ }
17
+ parseNested(input.options);
18
+ if (!Array.isArray(input.items)) {
19
+ throw new TypeError('Network items must be an array');
20
+ }
21
+ return input;
22
+ }
23
+
24
+ function checkedFrame(frame) {
25
+ if (!(frame?.positions instanceof Map) || !(frame.pins instanceof Map)) {
26
+ throw new TypeError('Provider frame requires positions and pins maps');
27
+ }
28
+ for (const points of [frame.positions, frame.pins]) {
29
+ for (const point of points.values()) {
30
+ if (!Number.isFinite(point.x) || !Number.isFinite(point.y)) {
31
+ throw new RangeError('Provider coordinates must be finite');
32
+ }
33
+ }
34
+ }
35
+ const b = frame.bounds;
36
+ if (
37
+ !b ||
38
+ ![b.x, b.y, b.width, b.height].every(Number.isFinite) ||
39
+ b.width <= 0 ||
40
+ b.height <= 0
41
+ ) {
42
+ throw new RangeError('Provider frame requires finite, positive bounds');
43
+ }
44
+ return clone(frame);
45
+ }
46
+
47
+ /**
48
+ * Transactional bridge for host geometry, collision solver and export backends.
49
+ * Providers receive detached snapshots. Only the most recent completed job may
50
+ * commit. No geometry/style settings are inferred, rounded or discarded.
51
+ */
52
+ export function createNetworkPresentation(provider, { debug } = {}) {
53
+ if (
54
+ typeof provider.geometry !== 'function' ||
55
+ typeof provider.svg !== 'function'
56
+ ) {
57
+ throw new TypeError(
58
+ 'A network provider requires geometry and svg functions'
59
+ );
60
+ }
61
+ let input = { items: [], index: '0', options: '' };
62
+ let requestedInput = input;
63
+ let frame;
64
+ let controller;
65
+ let revision = 0;
66
+ let committedRevision = 0;
67
+ let disposed = false;
68
+ const listeners = new Set();
69
+ const snapshot = () => clone({ input, frame, revision: committedRevision });
70
+ const assertReady = () => {
71
+ if (disposed) {
72
+ throw new Error('Network presentation is disposed');
73
+ }
74
+ if (!frame) {
75
+ throw new Error('Network presentation has no prepared frame');
76
+ }
77
+ };
78
+ const notify = () => {
79
+ for (const listener of listeners) {
80
+ listener(snapshot());
81
+ }
82
+ };
83
+ async function run(kind, patch) {
84
+ if (disposed) {
85
+ throw new Error('Network presentation is disposed');
86
+ }
87
+ if (typeof provider[kind] !== 'function') {
88
+ throw new TypeError(`Provider does not support ${kind}`);
89
+ }
90
+ const candidate = checkedInput(
91
+ kind === 'geometry' ? requestedInput : input,
92
+ patch
93
+ );
94
+ requestedInput = candidate;
95
+ controller?.abort();
96
+ const active = new globalThis.AbortController();
97
+ controller = active;
98
+ const job = ++revision;
99
+ const request = {
100
+ revision: job,
101
+ input: clone(candidate),
102
+ frame: clone(frame),
103
+ signal: active.signal,
104
+ };
105
+ debug?.('network-provider:start', { kind, revision: job });
106
+ try {
107
+ const result = await provider[kind](request);
108
+ if (disposed || job !== revision) {
109
+ return false;
110
+ }
111
+ const next = checkedFrame(result);
112
+ input = candidate;
113
+ frame = next;
114
+ committedRevision = job;
115
+ debug?.('network-provider:commit', { kind, revision: job });
116
+ notify();
117
+ return true;
118
+ } catch (error) {
119
+ if (disposed || job !== revision) {
120
+ return false;
121
+ }
122
+ requestedInput = input;
123
+ debug?.('network-provider:error', {
124
+ kind,
125
+ revision: job,
126
+ message: error.message,
127
+ });
128
+ throw error;
129
+ }
130
+ }
131
+ function toSvg() {
132
+ assertReady();
133
+ const svg = provider.svg(snapshot());
134
+ if (typeof svg !== 'string') {
135
+ throw new TypeError('Provider svg must return a string');
136
+ }
137
+ return svg;
138
+ }
139
+ return {
140
+ update: (patch) => run('geometry', patch),
141
+ solve: () => {
142
+ assertReady();
143
+ return run('solve', {});
144
+ },
145
+ snapshot,
146
+ toSvg,
147
+ toRaster(type = 'image/png', options = {}) {
148
+ // Capture both at the same revision before any asynchronous encoding.
149
+ if (!['image/png', 'image/jpeg', 'image/webp'].includes(type)) {
150
+ throw new RangeError('Unsupported network raster format');
151
+ }
152
+ const svg = toSvg();
153
+ const state = snapshot();
154
+ return provider.raster
155
+ ? provider.raster({ ...state, svg, type, options })
156
+ : networkToRaster(svg, { ...options, type });
157
+ },
158
+ toLino() {
159
+ assertReady();
160
+ const positionLinks = (points) =>
161
+ [...points].map(([id, point]) => [
162
+ String(id),
163
+ String(point.x),
164
+ String(point.y),
165
+ ]);
166
+ return formatLinks([
167
+ {
168
+ id: 'presentation',
169
+ values: [
170
+ 'network-presentation',
171
+ ['index', input.index],
172
+ ['options', ...parseNested(input.options)],
173
+ ['positions', ...positionLinks(frame.positions)],
174
+ ['pins', ...positionLinks(frame.pins)],
175
+ [
176
+ 'bounds',
177
+ ...['x', 'y', 'width', 'height'].map((key) =>
178
+ String(frame.bounds[key])
179
+ ),
180
+ ],
181
+ ],
182
+ },
183
+ ]);
184
+ },
185
+ subscribe(listener) {
186
+ if (disposed) {
187
+ throw new Error('Network presentation is disposed');
188
+ }
189
+ listeners.add(listener);
190
+ return () => listeners.delete(listener);
191
+ },
192
+ dispose() {
193
+ disposed = true;
194
+ ++revision;
195
+ controller?.abort();
196
+ listeners.clear();
197
+ },
198
+ };
199
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * `drawLinkCanvas(ctx, geometry, style)`: one link on a 2D canvas, the same
3
+ * scene as `renderLinkSvg` draws. The marker shapes come from `markers.js`
4
+ * (`drawMarker` turns the same path data into a `Path2D`).
5
+ */
6
+
7
+ import { drawMarker, getMarker } from './markers.js';
8
+ import { buildScene } from './scene.js';
9
+
10
+ function strokeSegments(ctx, segments, color, width) {
11
+ if (segments.length === 0) {
12
+ return;
13
+ }
14
+ ctx.beginPath();
15
+ for (const s of segments) {
16
+ ctx.moveTo(s.x1, s.y1);
17
+ ctx.lineTo(s.x2, s.y2);
18
+ }
19
+ ctx.strokeStyle = color;
20
+ ctx.lineWidth = width;
21
+ ctx.stroke();
22
+ }
23
+
24
+ function drawPath(ctx, path) {
25
+ ctx.beginPath();
26
+ if (path.length === 0) {
27
+ return;
28
+ }
29
+ ctx.moveTo(path[0].p0.x, path[0].p0.y);
30
+ for (const s of path) {
31
+ ctx.bezierCurveTo(s.c1.x, s.c1.y, s.c2.x, s.c2.y, s.p3.x, s.p3.y);
32
+ }
33
+ }
34
+
35
+ function drawBlueprint(ctx, blueprint) {
36
+ ctx.setLineDash([...blueprint.dash]);
37
+ const { points, color, width } = blueprint.guide;
38
+ ctx.beginPath();
39
+ points.forEach((p, i) =>
40
+ i === 0 ? ctx.moveTo(p.x, p.y) : ctx.lineTo(p.x, p.y)
41
+ );
42
+ ctx.strokeStyle = color;
43
+ ctx.lineWidth = width;
44
+ ctx.stroke();
45
+ for (const p of blueprint.points) {
46
+ ctx.beginPath();
47
+ // SVG starts a circle's dashes at its rightmost point, going clockwise
48
+ // (y down); so does a canvas arc from angle 0.
49
+ ctx.arc(p.at.x, p.at.y, blueprint.radius, 0, Math.PI * 2);
50
+ ctx.strokeStyle = p.color;
51
+ ctx.lineWidth = blueprint.strokeWidth;
52
+ ctx.stroke();
53
+ }
54
+ ctx.setLineDash([]);
55
+ }
56
+
57
+ /**
58
+ * Draw one link. The canvas is cleared to the background first.
59
+ * @param {CanvasRenderingContext2D} ctx
60
+ * @param {import('./geometry.js').LinkGeometry} geometry
61
+ * @param {import('./scene.js').LinkStyle & {Path2D?: typeof Path2D}} style
62
+ * @returns {{markers: string[]}} the marker shape ids drawn (source,
63
+ * target), as `drawnMarkers` lists them for SVG
64
+ */
65
+ export function drawLinkCanvas(ctx, geometry, style) {
66
+ const scene = buildScene(geometry, style);
67
+ const ratio = style.pixelRatio ?? 1;
68
+ const { view } = scene;
69
+ ctx.save();
70
+ ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
71
+ ctx.fillStyle = scene.background;
72
+ ctx.fillRect(0, 0, scene.width, scene.height);
73
+ ctx.transform(view.k, 0, 0, view.k, view.x, view.y);
74
+ ctx.setLineDash([]);
75
+ if (scene.grid !== null) {
76
+ const g = scene.grid;
77
+ strokeSegments(ctx, g.minor, g.minorColor, g.minorWidth);
78
+ strokeSegments(ctx, g.major, g.majorColor, g.majorWidth);
79
+ }
80
+ drawPath(ctx, scene.line.path);
81
+ ctx.strokeStyle = scene.line.color;
82
+ ctx.lineWidth = scene.line.width;
83
+ ctx.lineCap = 'butt';
84
+ ctx.lineJoin = 'round';
85
+ ctx.stroke();
86
+ const markers = [];
87
+ for (const end of scene.ends) {
88
+ const marker = getMarker(end.shape);
89
+ const drawn = drawMarker(ctx, marker, end.at, end.angle, scene.line.width, {
90
+ color: end.color,
91
+ Path2D: style.Path2D,
92
+ });
93
+ if (drawn) {
94
+ markers.push(marker.id);
95
+ }
96
+ }
97
+ if (scene.blueprint !== null) {
98
+ drawBlueprint(ctx, scene.blueprint);
99
+ }
100
+ ctx.restore();
101
+ return { markers };
102
+ }