@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,233 @@
1
+ import { defineLinksNetwork } from './links-network.js';
2
+ import { linoToNetwork } from './lino-to-network.js';
3
+ import { sourceReferences } from './lino-network-source.js';
4
+
5
+ export const LINO_NETWORK_TAG = 'lino-network';
6
+ const CSS = `:host { display:block; color-scheme:light dark; }
7
+ links-network { width:100%; height:400px; }
8
+ pre { white-space:pre-wrap; overflow-wrap:anywhere; padding:12px; border:1px solid currentColor; }
9
+ mark { background:#ffe066; color:#171717; }
10
+ ul { padding-inline-start:24px; }
11
+ [hidden] { display:none; }`;
12
+
13
+ function showDiagnostics(state, diagnostics) {
14
+ state.diagnostics = diagnostics;
15
+ state.list.replaceChildren();
16
+ state.list.hidden = diagnostics.length === 0;
17
+ for (const diagnostic of diagnostics) {
18
+ const item = state.win.document.createElement('li');
19
+ item.textContent = `${diagnostic.severity}: ${diagnostic.line}:${diagnostic.column} ${diagnostic.message}`;
20
+ state.list.append(item);
21
+ }
22
+ }
23
+
24
+ function highlightSource(state, position) {
25
+ const text = state.text;
26
+ let start = 0;
27
+ let line = 1;
28
+ while (line < position.line && start < text.length) {
29
+ if (text[start] === '\r') {
30
+ line++;
31
+ if (text[start + 1] === '\n') {
32
+ start++;
33
+ }
34
+ } else if (text[start] === '\n') {
35
+ line++;
36
+ }
37
+ start++;
38
+ }
39
+ start += position.column - 1;
40
+ const token = sourceReferences(text).find((token) => token.start === start);
41
+ const end = token?.end ?? start + 1;
42
+ const mark = state.win.document.createElement('mark');
43
+ mark.textContent = text.slice(start, end);
44
+ state.source.replaceChildren(text.slice(0, start), mark, text.slice(end));
45
+ }
46
+
47
+ function selectSource(node, state, event) {
48
+ const id = event.detail.ids.at(-1);
49
+ const position = state.sourceMap.get(id);
50
+ if (!position) {
51
+ state.source.textContent = state.text;
52
+ return;
53
+ }
54
+ highlightSource(state, position);
55
+ node.dispatchEvent(
56
+ new state.win.CustomEvent('select', {
57
+ detail: { id, ...position },
58
+ bubbles: true,
59
+ composed: true,
60
+ })
61
+ );
62
+ }
63
+
64
+ async function loadSource(node, state) {
65
+ state.controller?.abort();
66
+ const controller = new state.win.AbortController();
67
+ state.controller = controller;
68
+ state.options.debug?.('Loading LiNo source', {
69
+ src: node.getAttribute('src'),
70
+ });
71
+ try {
72
+ let text = node.getAttribute('lino') ?? node.textContent;
73
+ if (node.hasAttribute('src')) {
74
+ const response = await (
75
+ state.options.fetch ?? state.win.fetch.bind(state.win)
76
+ )(node.getAttribute('src'), { signal: controller.signal });
77
+ if (!response.ok) {
78
+ throw new Error(`Unable to load LiNo (${response.status})`);
79
+ }
80
+ text = await response.text();
81
+ }
82
+ if (controller.signal.aborted) {
83
+ return;
84
+ }
85
+ state.text = text;
86
+ state.source.textContent = text;
87
+ const converted = linoToNetwork(text, state.options);
88
+ state.sourceMap = converted.sourceMap;
89
+ showDiagnostics(state, converted.diagnostics);
90
+ state.view.items = converted.links;
91
+ await state.view.ready;
92
+ } catch (error) {
93
+ state.options.debug?.('LiNo source load failed', {
94
+ src: node.getAttribute('src'),
95
+ aborted: controller.signal.aborted,
96
+ error,
97
+ });
98
+ if (controller.signal.aborted) {
99
+ return;
100
+ }
101
+ state.text = '';
102
+ state.source.textContent = '';
103
+ state.sourceMap = new Map();
104
+ state.view.items = [];
105
+ showDiagnostics(state, [
106
+ {
107
+ code: 'load-error',
108
+ severity: 'error',
109
+ line: 1,
110
+ column: 1,
111
+ message: error.message,
112
+ },
113
+ ]);
114
+ }
115
+ }
116
+
117
+ /** Explicit registration; safe to import in Node without a DOM. */
118
+ export function defineLinoNetwork(win = globalThis.window, options = {}) {
119
+ const tag = options.tag ?? LINO_NETWORK_TAG;
120
+ if (win.customElements.get(tag)) {
121
+ return win.customElements.get(tag);
122
+ }
123
+ defineLinksNetwork(win, { createWorker: options.createWorker });
124
+ class LinoNetwork extends win.HTMLElement {
125
+ #state;
126
+ static get observedAttributes() {
127
+ return ['src', 'lino', 'layout', 'style-mode', 'theme', 'label'];
128
+ }
129
+ constructor() {
130
+ super();
131
+ const root = this.attachShadow({ mode: 'open' });
132
+ const style = win.document.createElement('style');
133
+ style.textContent = CSS;
134
+ const view = win.document.createElement('links-network');
135
+ const list = win.document.createElement('ul');
136
+ list.setAttribute('aria-label', 'Diagnostics');
137
+ list.setAttribute('aria-live', 'polite');
138
+ list.hidden = true;
139
+ const source = win.document.createElement('pre');
140
+ source.setAttribute('aria-label', 'Links Notation source');
141
+ root.append(style, view, list, source);
142
+ this.#state = {
143
+ win,
144
+ options,
145
+ view,
146
+ list,
147
+ source,
148
+ text: '',
149
+ sourceMap: new Map(),
150
+ diagnostics: [],
151
+ connected: false,
152
+ ready: Promise.resolve(),
153
+ };
154
+ view.addEventListener('selectionchange', (event) =>
155
+ selectSource(this, this.#state, event)
156
+ );
157
+ }
158
+ connectedCallback() {
159
+ this.#state.connected = true;
160
+ for (const name of ['layout', 'style-mode', 'theme', 'label']) {
161
+ this.#forward(name);
162
+ }
163
+ this.#state.observer = new win.MutationObserver(() => this.#load());
164
+ this.#state.observer.observe(this, {
165
+ childList: true,
166
+ characterData: true,
167
+ subtree: true,
168
+ });
169
+ this.#load();
170
+ }
171
+ disconnectedCallback() {
172
+ this.#state.connected = false;
173
+ this.#state.controller?.abort();
174
+ this.#state.observer?.disconnect();
175
+ }
176
+ attributeChangedCallback(name) {
177
+ // Upgrade reactions run while markup is already in the document, before
178
+ // connectedCallback. Let that callback forward attributes and load once;
179
+ // otherwise it immediately aborts and replaces the upgrade's first fetch.
180
+ if (!this.#state.connected) {
181
+ return;
182
+ }
183
+ if (name === 'src' || name === 'lino') {
184
+ this.#load();
185
+ } else {
186
+ this.#forward(name);
187
+ }
188
+ }
189
+ #forward(name) {
190
+ const value = this.getAttribute(name);
191
+ if (value === null) {
192
+ this.#state.view.removeAttribute(name);
193
+ } else {
194
+ this.#state.view.setAttribute(name, value);
195
+ }
196
+ }
197
+ #load() {
198
+ this.#state.ready = loadSource(this, this.#state);
199
+ }
200
+ get ready() {
201
+ return this.#state.ready;
202
+ }
203
+ get diagnostics() {
204
+ return [...this.#state.diagnostics];
205
+ }
206
+ get sourceMap() {
207
+ return new Map(this.#state.sourceMap);
208
+ }
209
+ get network() {
210
+ return this.#state.view.network;
211
+ }
212
+ get networkView() {
213
+ return this.#state.view;
214
+ }
215
+ get lino() {
216
+ return this.#state.text;
217
+ }
218
+ set lino(text) {
219
+ this.setAttribute('lino', text);
220
+ }
221
+ select(id) {
222
+ this.#state.view.select(id);
223
+ }
224
+ toSvg() {
225
+ return this.#state.view.toSvg();
226
+ }
227
+ toPng(scale = 1) {
228
+ return this.#state.view.toPng(scale);
229
+ }
230
+ }
231
+ win.customElements.define(tag, LinoNetwork);
232
+ return LinoNetwork;
233
+ }
@@ -0,0 +1,252 @@
1
+ import { Link, Parser } from 'links-notation';
2
+ import { normalizeLink } from '@link-foundation/ui-core/source';
3
+ import { annotateLinks, formatNetworkRoots } from './lino-network-source.js';
4
+
5
+ // Indented groups hold values of their parent, before path normalisation.
6
+ const unindent = ({ element, children }) =>
7
+ new Link(element.id, [...element.values, ...children.map(unindent)]);
8
+
9
+ const numeric = (text) =>
10
+ text.length > 0 && [...text].every((c) => c >= '0' && c <= '9');
11
+ const isDefinition = (node) =>
12
+ node.id !== null && (node.values.length > 0 || node.definition);
13
+ const isReference = (node) => node.id !== null && !isDefinition(node);
14
+ const loneWord = (node) =>
15
+ node.id === null && node.values.length === 1 && isReference(node.values[0]);
16
+
17
+ function freshId(used, preferred) {
18
+ let id = preferred;
19
+ let suffix = 0;
20
+ while (used.has(id) || id === '0') {
21
+ id = `${preferred}~${++suffix}`;
22
+ }
23
+ used.add(id);
24
+ return id;
25
+ }
26
+
27
+ function mapper(roots, positions) {
28
+ const rootSet = new WeakSet(roots);
29
+ const rootWord = (node) => rootSet.has(node) && loneWord(node);
30
+ const used = new Set(['0']);
31
+ const definitions = new Map();
32
+ const ids = new WeakMap();
33
+ const ignored = new WeakSet();
34
+ const diagnostics = [];
35
+ const sourceMap = new Map();
36
+ const links = [];
37
+ const points = new Map();
38
+ const warn = (code, node, message) =>
39
+ diagnostics.push({
40
+ code,
41
+ severity: 'warning',
42
+ ...positions.get(node),
43
+ message,
44
+ });
45
+ const collect = (node) => {
46
+ if (isDefinition(node)) {
47
+ if (definitions.has(node.id)) {
48
+ ignored.add(node);
49
+ warn(
50
+ 'duplicate-id',
51
+ node,
52
+ `Duplicate ID ${node.id}; the first definition wins`
53
+ );
54
+ return;
55
+ }
56
+ definitions.set(node.id, node);
57
+ }
58
+ if (node.id !== null && !node.quote) {
59
+ used.add(node.id);
60
+ }
61
+ node.values.forEach(collect);
62
+ };
63
+ roots.forEach(collect);
64
+ for (const [id, node] of definitions) {
65
+ ids.set(node, id === '0' ? freshId(used, '@id:0') : id);
66
+ }
67
+ const allocate = (node, path) => {
68
+ if (ignored.has(node) || isReference(node)) {
69
+ return;
70
+ }
71
+ if (rootWord(node)) {
72
+ return;
73
+ }
74
+ if (!ids.has(node)) {
75
+ ids.set(node, freshId(used, path));
76
+ }
77
+ node.values.forEach((value, index) =>
78
+ allocate(value, `${ids.get(node)}/${index}`)
79
+ );
80
+ };
81
+ roots.forEach((node, index) => allocate(node, `@${index}`));
82
+ const locate = (id, node) => {
83
+ if (!sourceMap.has(id)) {
84
+ sourceMap.set(id, positions.get(node));
85
+ }
86
+ return id;
87
+ };
88
+ const point = (node) => {
89
+ const key = node.quote ? `value:${node.id}` : `point:${node.id}`;
90
+ if (!points.has(key)) {
91
+ const id = node.quote
92
+ ? freshId(used, `@value:${node.id}`)
93
+ : node.id === '0'
94
+ ? freshId(used, '@point:0')
95
+ : node.id;
96
+ points.set(key, {
97
+ id,
98
+ kind: node.quote ? 'value' : 'point',
99
+ label: node.id,
100
+ });
101
+ }
102
+ return locate(points.get(key).id, node);
103
+ };
104
+ const reference = (node) => {
105
+ if (node.quote) {
106
+ return point(node);
107
+ }
108
+ const definition = definitions.get(node.id);
109
+ if (definition) {
110
+ return ids.get(definition);
111
+ }
112
+ if (numeric(node.id)) {
113
+ warn(
114
+ 'unknown-reference',
115
+ node,
116
+ `Unknown reference ${node.id}; shown as a point`
117
+ );
118
+ }
119
+ return point(node);
120
+ };
121
+ const visit = (node) => {
122
+ if (ignored.has(node)) {
123
+ return ids.get(definitions.get(node.id));
124
+ }
125
+ if (isReference(node)) {
126
+ return reference(node);
127
+ }
128
+ if (rootWord(node)) {
129
+ return reference(node.values[0]);
130
+ }
131
+ const id = locate(ids.get(node), node);
132
+ // Reserve the parent's place before traversing nested values.
133
+ const link = { id, source: 0, target: 0, label: node.id ?? id };
134
+ links.push(link);
135
+ const values = node.values.map(visit);
136
+ if (values.length === 2) {
137
+ [link.source, link.target] = values;
138
+ } else if (values.length > 0) {
139
+ link.source = id;
140
+ link.target = values[0];
141
+ for (let i = 1; i < values.length; i++) {
142
+ const chainId = locate(freshId(used, `${id}/${i}`), node.values[i]);
143
+ links.push({
144
+ id: chainId,
145
+ source: values[i - 1],
146
+ target: values[i],
147
+ label: chainId,
148
+ });
149
+ }
150
+ }
151
+ return id;
152
+ };
153
+ roots.forEach(visit);
154
+ const input = [...links, ...points.values()];
155
+ if (input.length > 0) {
156
+ // Enumerable metadata survives buildNetwork's record copies and structured clone.
157
+ // Positions stay separate so equivalent parse shapes yield equal networks.
158
+ input[0].lino = { roots };
159
+ }
160
+ return { links: input, diagnostics, sourceMap };
161
+ }
162
+
163
+ /**
164
+ * Convert arbitrary LiNo using only the official parser, with bounded input/depth.
165
+ *
166
+ * | LiNo | Network |
167
+ * | --- | --- |
168
+ * | `(a: b c)` | Link a, source b, target c (forward references allowed). |
169
+ * | `(a: b c d)` | a: a→b, a/1: b→c, a/2: c→d. |
170
+ * | `(a: (b c) d)` | Anonymous link a/0 referenced by a. |
171
+ * | Bare word | Labelled point unless it names a definition. |
172
+ * | Quoted value | Separate point with kind value and decoded label. |
173
+ * | `(a: a a)` / cycles | References retained without recursive expansion. |
174
+ * | Duplicate id | Warning; first definition and its subtree win. |
175
+ *
176
+ * One value uses the sequence's first edge; zero values make a free-ended link.
177
+ * Root single words are points. Root anonymous links use @0, @1, etc.
178
+ * Generated IDs get ~1, ~2, etc. on collision; explicit ID 0 is remapped because
179
+ * the network model reserves 0 for free ends. Numeric atoms without definitions
180
+ * warn; ordinary words are valid labels (LiNo has no distinct reference syntax).
181
+ *
182
+ * @param {string} text
183
+ * @param {{ maxInputSize?: number, maxDepth?: number }} [options]
184
+ * @returns {{ links: import('./index.js').LinoNetworkInput[], diagnostics: object[], sourceMap: Map<string, {line:number,column:number}> }}
185
+ */
186
+ export function linoToNetwork(text, options = {}) {
187
+ const { maxInputSize = 1024 * 1024, maxDepth = 64 } = options;
188
+ try {
189
+ if (typeof text !== 'string') {
190
+ throw new TypeError('Links Notation input must be a string');
191
+ }
192
+ if (text.length > maxInputSize) {
193
+ return {
194
+ links: [],
195
+ sourceMap: new Map(),
196
+ diagnostics: [
197
+ {
198
+ code: 'input-too-large',
199
+ severity: 'error',
200
+ line: 1,
201
+ column: 1,
202
+ message: `Input exceeds ${maxInputSize} characters`,
203
+ },
204
+ ],
205
+ };
206
+ }
207
+ const parser = new Parser({ maxInputSize, maxDepth });
208
+ const links = parser.parseGroups(text).map(unindent).map(normalizeLink);
209
+ const { roots, positions } = annotateLinks(links, text);
210
+ return mapper(roots, positions);
211
+ } catch (error) {
212
+ return {
213
+ links: [],
214
+ sourceMap: new Map(),
215
+ diagnostics: [
216
+ {
217
+ code:
218
+ error.maxDepth || error.cause instanceof RangeError
219
+ ? 'depth-exceeded'
220
+ : 'syntax-error',
221
+ severity: 'error',
222
+ line: error.line ?? 1,
223
+ column: error.column ?? 1,
224
+ message: error.message,
225
+ },
226
+ ],
227
+ };
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Reconstruct LiNo-origin networks (a conversion, its links, or buildNetwork).
233
+ * Preserves IDs, references and quoted value kinds; formatting is nested LiNo.
234
+ * View edits are intentionally outside this read-only converter's contract.
235
+ * @returns {string}
236
+ */
237
+ export function networkToLino(network) {
238
+ const input =
239
+ network.links instanceof Map
240
+ ? [...network.links.values(), ...network.points.values()]
241
+ : Array.isArray(network)
242
+ ? network
243
+ : network.links;
244
+ if (input.length === 0) {
245
+ return '';
246
+ }
247
+ const metadata = input.find((link) => link.lino)?.lino;
248
+ if (!metadata) {
249
+ throw new TypeError('networkToLino requires a network that came from LiNo');
250
+ }
251
+ return formatNetworkRoots(metadata.roots);
252
+ }
@@ -0,0 +1,192 @@
1
+ /**
2
+ * The marker shapes of a link end, described once as data and drawn by both
3
+ * renderers: as SVG `<marker>` elements (`svgMarkerDefs`) and on a canvas
4
+ * with `Path2D` (`drawMarker`). Each shape is SVG path data in a 100 × 100
5
+ * box; `refX`/`refY` is the point that sits on the end of the line, and the
6
+ * box is drawn with `+x` along the line (SVG `orient="auto"`).
7
+ *
8
+ * One box unit is one stroke width of the line (SVG
9
+ * `markerUnits="strokeWidth"`), so markers grow with the line. The `arrow`
10
+ * and the tick of `bar` are the links-visuals markers (Unlicense).
11
+ *
12
+ * No colour is written here: the colour of an end comes from the tokens.
13
+ */
14
+
15
+ import { fmt } from './geometry.js';
16
+
17
+ /**
18
+ * @typedef {object} Marker
19
+ * @property {string} id the shape name (`arrow`)
20
+ * @property {string} viewBox always `0 0 100 100`
21
+ * @property {string} path SVG path data in the box (empty for `none`)
22
+ * @property {number} refX
23
+ * @property {number} refY
24
+ * @property {'stroke'|'fill'} paint whether the path is stroked or filled
25
+ * @property {number} strokeWidth in box units (one line width)
26
+ * @property {string} label how the end is announced
27
+ */
28
+
29
+ const VIEW_BOX = '0 0 100 100';
30
+
31
+ /** @type {Readonly<Record<string, Readonly<Marker>>>} */
32
+ export const MARKERS = Object.freeze({
33
+ bar: Object.freeze({
34
+ id: 'bar',
35
+ viewBox: VIEW_BOX,
36
+ path: 'M 50 39.27 L 50 60.73',
37
+ refX: 50,
38
+ refY: 50,
39
+ paint: 'stroke',
40
+ strokeWidth: 1,
41
+ label: 'bar',
42
+ }),
43
+ arrow: Object.freeze({
44
+ id: 'arrow',
45
+ viewBox: VIEW_BOX,
46
+ path: 'M 10.35 50.35 L -0.35 39.65 M 10.35 49.65 L -0.35 60.35',
47
+ refX: 10,
48
+ refY: 50,
49
+ paint: 'stroke',
50
+ strokeWidth: 1,
51
+ label: 'arrow',
52
+ }),
53
+ cross: Object.freeze({
54
+ id: 'cross',
55
+ viewBox: VIEW_BOX,
56
+ path: 'M 43 43 L 57 57 M 43 57 L 57 43',
57
+ refX: 50,
58
+ refY: 50,
59
+ paint: 'stroke',
60
+ strokeWidth: 1,
61
+ label: 'cross',
62
+ }),
63
+ dot: Object.freeze({
64
+ id: 'dot',
65
+ viewBox: VIEW_BOX,
66
+ path: 'M 54 50 A 4 4 0 1 1 46 50 A 4 4 0 1 1 54 50 Z',
67
+ refX: 50,
68
+ refY: 50,
69
+ paint: 'fill',
70
+ strokeWidth: 0,
71
+ label: 'dot',
72
+ }),
73
+ none: Object.freeze({
74
+ id: 'none',
75
+ viewBox: VIEW_BOX,
76
+ path: '',
77
+ refX: 50,
78
+ refY: 50,
79
+ paint: 'stroke',
80
+ strokeWidth: 0,
81
+ label: 'no marker',
82
+ }),
83
+ });
84
+
85
+ /** The marker shape names, in a fixed order. */
86
+ export const MARKER_IDS = Object.freeze(Object.keys(MARKERS));
87
+
88
+ /** The markers of a link when none are given. */
89
+ export const DEFAULT_ENDS = Object.freeze({ source: 'bar', target: 'arrow' });
90
+
91
+ /** The box size of every marker (the viewBox is `0 0 100 100`). */
92
+ export const MARKER_BOX = 100;
93
+
94
+ /**
95
+ * The marker of a shape name; an unknown name is `undefined`.
96
+ * @param {string} id
97
+ * @returns {Readonly<Marker>|undefined}
98
+ */
99
+ export const getMarker = (id) =>
100
+ Object.hasOwn(MARKERS, id) ? MARKERS[id] : undefined;
101
+
102
+ /** Text for an XML attribute value. */
103
+ export const escapeAttribute = (text) =>
104
+ String(text)
105
+ .replace(/&/gu, '&amp;')
106
+ .replace(/"/gu, '&quot;')
107
+ .replace(/</gu, '&lt;')
108
+ .replace(/>/gu, '&gt;');
109
+
110
+ /**
111
+ * The id of the SVG marker of one end of a link.
112
+ * @param {string} prefix unique per drawing
113
+ * @param {'source'|'target'} end
114
+ * @param {string} shape
115
+ */
116
+ export const markerElementId = (prefix, end, shape) =>
117
+ `${prefix}-${end}-${shape}`;
118
+
119
+ /**
120
+ * SVG `<marker>` elements for the ends of a link. Each end gets its own
121
+ * element, because the two ends can have different colours.
122
+ * @param {Partial<Record<'source'|'target', string>>} ends shape per end
123
+ * @param {Record<string, string>} colors `source` and `target` colours
124
+ * (from `linkColors`)
125
+ * @param {{idPrefix?: string}} [options]
126
+ * @returns {string} `<marker>` elements (no `<defs>` around them); `none`
127
+ * and unknown shapes give nothing
128
+ */
129
+ export function svgMarkerDefs(ends, colors, { idPrefix = 'link' } = {}) {
130
+ return ['source', 'target']
131
+ .map((end) => {
132
+ const marker = getMarker(ends[end]);
133
+ if (marker === undefined || marker.path === '') {
134
+ return '';
135
+ }
136
+ const color = escapeAttribute(colors[end]);
137
+ const paint =
138
+ marker.paint === 'fill'
139
+ ? `fill="${color}" stroke="none"`
140
+ : `fill="none" stroke="${color}" stroke-width="${fmt(marker.strokeWidth)}" stroke-linecap="butt"`;
141
+ return (
142
+ `<marker id="${escapeAttribute(markerElementId(idPrefix, end, marker.id))}" data-marker="${marker.id}" ` +
143
+ `viewBox="${marker.viewBox}" refX="${fmt(marker.refX)}" refY="${fmt(marker.refY)}" ` +
144
+ `markerWidth="${MARKER_BOX}" markerHeight="${MARKER_BOX}" markerUnits="strokeWidth" ` +
145
+ `orient="auto" overflow="visible"><path d="${marker.path}" ${paint}/></marker>`
146
+ );
147
+ })
148
+ .join('');
149
+ }
150
+
151
+ /**
152
+ * Draw a marker on a canvas: the same path data as the SVG marker, through
153
+ * `Path2D`, placed at `at`, turned by `angle` and scaled by `scale` (canvas
154
+ * units per box unit: the line width, as with `markerUnits="strokeWidth"`).
155
+ * @param {CanvasRenderingContext2D} ctx
156
+ * @param {Readonly<Marker>} marker
157
+ * @param {{x: number, y: number}} at
158
+ * @param {number} angle radians
159
+ * @param {number} scale
160
+ * @param {{color?: string, Path2D?: typeof Path2D}} [options] without
161
+ * `color` the current fill or stroke style is kept; `Path2D` defaults to
162
+ * the global one
163
+ * @returns {boolean} whether anything was drawn
164
+ */
165
+ export function drawMarker(ctx, marker, at, angle, scale, options = {}) {
166
+ if (marker === undefined || marker.path === '') {
167
+ return false;
168
+ }
169
+ const Path = options.Path2D ?? globalThis.Path2D;
170
+ const shape = new Path(marker.path);
171
+ ctx.save();
172
+ ctx.translate(at.x, at.y);
173
+ ctx.rotate(angle);
174
+ ctx.scale(scale, scale);
175
+ ctx.translate(-marker.refX, -marker.refY);
176
+ if (marker.paint === 'fill') {
177
+ if (options.color !== undefined) {
178
+ ctx.fillStyle = options.color;
179
+ }
180
+ ctx.fill(shape);
181
+ } else {
182
+ if (options.color !== undefined) {
183
+ ctx.strokeStyle = options.color;
184
+ }
185
+ ctx.lineWidth = marker.strokeWidth;
186
+ ctx.lineCap = 'butt';
187
+ ctx.setLineDash([]);
188
+ ctx.stroke(shape);
189
+ }
190
+ ctx.restore();
191
+ return true;
192
+ }