@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,146 @@
1
+ /**
2
+ * Plain value helpers shared by the chart model, the scales and the
3
+ * renderers: numbers, dates and their text. Pure and deterministic: dates
4
+ * are read and written in UTC, never in the local time zone.
5
+ */
6
+
7
+ /** Whether `text` is a number written the way `String(number)` writes it. */
8
+ export function isCanonicalNumber(text) {
9
+ if (typeof text !== 'string' || text.trim() !== text || text === '') {
10
+ return false;
11
+ }
12
+ const number = Number(text);
13
+ return Number.isFinite(number) && String(number) === text;
14
+ }
15
+
16
+ /** A finite number of a LiNo atom (`12`, `-3.5`, `1e3`), or `null`. */
17
+ export function toNumber(text) {
18
+ if (typeof text === 'number') {
19
+ return Number.isFinite(text) ? text : null;
20
+ }
21
+ if (typeof text !== 'string' || text.trim() === '') {
22
+ return null;
23
+ }
24
+ const number = Number(text);
25
+ return Number.isFinite(number) ? number : null;
26
+ }
27
+
28
+ const DIGITS = new Set('0123456789');
29
+ const isDigits = (text, length) =>
30
+ text.length === length && [...text].every((c) => DIGITS.has(c));
31
+
32
+ /**
33
+ * The UTC time of a plain date: a year (`YYYY`), a month (`YYYY-MM`) or a
34
+ * day (`YYYY-MM-DD`); `null` for anything else, an impossible day included.
35
+ */
36
+ function parseDate(value) {
37
+ const [year, month = '01', day = '01', ...extra] = value.split('-');
38
+ if (
39
+ extra.length > 0 ||
40
+ !isDigits(year, 4) ||
41
+ !isDigits(month, 2) ||
42
+ !isDigits(day, 2)
43
+ ) {
44
+ return null;
45
+ }
46
+ const time = Date.UTC(Number(year), Number(month) - 1, Number(day));
47
+ const date = new Date(time);
48
+ const exact =
49
+ date.getUTCMonth() === Number(month) - 1 &&
50
+ date.getUTCDate() === Number(day);
51
+ return exact ? time : null;
52
+ }
53
+
54
+ /**
55
+ * The UTC time of a temporal value: a plain date (`YYYY`, `YYYY-MM`,
56
+ * `YYYY-MM-DD`) or an ISO 8601 date-time with a zone (`...T12:00Z`). A
57
+ * number is a time in milliseconds. Returns `null` when it is not a date.
58
+ * @param {string|number} value
59
+ * @returns {number|null}
60
+ */
61
+ export function parseTemporal(value) {
62
+ if (typeof value === 'number') {
63
+ return Number.isFinite(value) ? value : null;
64
+ }
65
+ if (typeof value !== 'string') {
66
+ return null;
67
+ }
68
+ const date = parseDate(value);
69
+ if (date !== null) {
70
+ return date;
71
+ }
72
+ // A date-time needs an explicit zone, so the result never depends on the
73
+ // time zone of the machine.
74
+ const zoned =
75
+ value.includes('T') && (value.endsWith('Z') || hasOffset(value));
76
+ const time = zoned ? Date.parse(value) : Number.NaN;
77
+ return Number.isFinite(time) ? time : null;
78
+ }
79
+
80
+ /** Whether an ISO date-time ends with `+hh:mm` or `-hh:mm`. */
81
+ function hasOffset(value) {
82
+ const tail = value.slice(-6);
83
+ return (
84
+ (tail[0] === '+' || tail[0] === '-') &&
85
+ isDigits(tail.slice(1, 3), 2) &&
86
+ tail[3] === ':' &&
87
+ isDigits(tail.slice(4), 2)
88
+ );
89
+ }
90
+
91
+ const MONTHS = [
92
+ 'Jan',
93
+ 'Feb',
94
+ 'Mar',
95
+ 'Apr',
96
+ 'May',
97
+ 'Jun',
98
+ 'Jul',
99
+ 'Aug',
100
+ 'Sep',
101
+ 'Oct',
102
+ 'Nov',
103
+ 'Dec',
104
+ ];
105
+
106
+ /**
107
+ * A short English label of a UTC time, as precise as the value needs:
108
+ * `Jan 2026` (the first of a month), `Jan 31, 2026` or `Jan 31, 2026 12:30`.
109
+ * @param {number} time
110
+ */
111
+ export function formatTime(time) {
112
+ const date = new Date(time);
113
+ const year = date.getUTCFullYear();
114
+ const month = MONTHS[date.getUTCMonth()];
115
+ const day = date.getUTCDate();
116
+ const hours = date.getUTCHours();
117
+ const minutes = date.getUTCMinutes();
118
+ if (hours !== 0 || minutes !== 0) {
119
+ const hh = String(hours).padStart(2, '0');
120
+ const mm = String(minutes).padStart(2, '0');
121
+ return `${month} ${day}, ${year} ${hh}:${mm}`;
122
+ }
123
+ return day === 1 ? `${month} ${year}` : `${month} ${day}, ${year}`;
124
+ }
125
+
126
+ /**
127
+ * A number for people: at most `digits` fraction digits, no trailing
128
+ * zeros, a minus sign for negatives, a thin grouping of thousands.
129
+ * Deterministic (no `Intl`, whose output depends on the runtime's data).
130
+ * @param {number} value
131
+ * @param {number} [digits]
132
+ */
133
+ export function formatNumber(value, digits = 2) {
134
+ if (!Number.isFinite(value)) {
135
+ return String(value);
136
+ }
137
+ const fixed = Math.abs(value).toFixed(digits);
138
+ const [whole, fraction = ''] = fixed.split('.');
139
+ const trimmed = fraction.replace(/0+$/u, '');
140
+ const groups = [];
141
+ for (let end = whole.length; end > 0; end -= 3) {
142
+ groups.unshift(whole.slice(Math.max(0, end - 3), end));
143
+ }
144
+ const sign = value < 0 && Number(fixed) !== 0 ? '-' : '';
145
+ return `${sign}${groups.join(',')}${trimmed === '' ? '' : `.${trimmed}`}`;
146
+ }
@@ -0,0 +1,142 @@
1
+ # Chat kit
2
+
3
+ Import `@link-foundation/ui-components/chat` to register `chat-list`,
4
+ `message-stream`, `message-bubble`, `composer`, `day-separator` and
5
+ `reasoning-trace`. Load `@link-foundation/ui-components/chat.css` and the
6
+ existing `controls.css` and `data.css`. The complete runnable example is
7
+ [`chat.html`](../../examples/chat.html) (serve the repository with
8
+ `node scripts/serve-static.mjs --port 4173`).
9
+
10
+ ## One data contract
11
+
12
+ `parseChatData(textOrRawLinks)` reads the official Links Notation representation;
13
+ `chatDataToLino(records)` writes nested LiNo. Both validate unique IDs, scalar
14
+ fields, booleans and nonnegative integer counts. The result is an ordered array
15
+ of `{ id, kind, ...fields }`. Unknown scalar fields survive round trips so hosts
16
+ can carry metadata. References are record IDs, and optional fields stay absent.
17
+
18
+ ```lino
19
+ c1: chat
20
+ title 'Design review'
21
+ unread 2
22
+ can-edit false
23
+ can-react true
24
+ can-reply true
25
+ max-attachments 2
26
+ alice: participant
27
+ name Alice
28
+ m1: message
29
+ chat c1
30
+ sender alice
31
+ time '2026-10-30T10:00:00Z'
32
+ text Hello
33
+ m2: message
34
+ chat c1
35
+ sender me
36
+ outgoing true
37
+ reply-to m1
38
+ status pending
39
+ text 'Ready for review'
40
+ s1: step
41
+ message m2
42
+ parent none
43
+ title Review
44
+ state done
45
+ s2: step
46
+ message m2
47
+ parent s1
48
+ title Contrast
49
+ state done
50
+ ```
51
+
52
+ The six record kinds are `chat`, `message`, `participant`, `attachment`,
53
+ `reaction` and `step`. Attachments refer to `message` and contain `name`, `url`,
54
+ `mime`, `size`; reactions contain `message`, `emoji`, `count`, `selected`; steps
55
+ contain `message`, `parent`, `title`, `state`, optional `text`. Messages can carry
56
+ `service true`, `unread true` and explicit delivery `status` (`pending`,
57
+ `sending`, `sent`, `delivered`, `read`, `failed`). The adapter marks outgoing
58
+ messages and supplies receipt/unread snapshots; the kit never interprets IDs.
59
+ All displayed text uses text nodes. Unsafe attachment URLs are rendered as text.
60
+
61
+ ## Mount and actions
62
+
63
+ Use `mountDocument(container, lino, { parseOptions: { vocabulary:
64
+ chatVocabulary() }, chat: options })`. `options` contains:
65
+
66
+ - `data`: the record array or an observable `{ get(), subscribe(fn) }` snapshot.
67
+ - `windows`: named `createStreamWindow(source, limits)` instances.
68
+ - `clock: () => epochMilliseconds`, `locale`, `timeZone` and `labels` (translated
69
+ day groups, actions, delivery states, composer, paging and status strings).
70
+ - `slots.message(message, {document})`: optional trusted renderer returning a
71
+ Node or string (Markdown/diagrams belong to host renderers).
72
+ - `slots.before`, `slots.attachments`, `slots.after`: optional composer content,
73
+ returning Nodes. Hosts enforce attachment counts and send attachment data in
74
+ their adapter; `max-attachments` is published on the slot container and zero
75
+ hides attachment content.
76
+ - `spaceTarget`: optional shared ancestor for `--composer-space`; by default the
77
+ composer's parent. Put both stream and composer inside `.ui-chat-shell`.
78
+
79
+ ```lino
80
+ stream: message-stream
81
+ label Messages
82
+ chat c1
83
+ source history
84
+ compose: composer
85
+ chat c1
86
+ ```
87
+
88
+ A bubble and trace use `record <message-id>`; a day separator uses `time <ISO>`;
89
+ a chat list reads chat summaries from the snapshot. Without `source`, a stream
90
+ renders the snapshot's messages for its `chat`.
91
+
92
+ Bubbling events: `ui-chat-send` carries `{chat, text}`, `ui-chat-action` carries
93
+ `{action, message, selection}` (reaction buttons also carry `reaction`), and
94
+ `ui-chat-jump` carries `{id}`. The host performs network actions and updates the
95
+ snapshot. Capability flags default to unavailable; explicit message flags
96
+ can override chat flags. Context-menu target and multi-selection are independent.
97
+ Arrows move between messages, Space selects, Shift extends, Ctrl/Meta toggles,
98
+ Enter/ContextMenu/Shift+F10 opens the APG action menu, Escape clears selection.
99
+ Composer Enter sends; Shift+Enter inserts a newline; IME Enter is preserved.
100
+
101
+ ## Contiguous history and scroll ownership
102
+
103
+ A source implements `load({before?, after?, around?, limit, signal})`, returning
104
+ `Promise<{messages, hasOlder, hasNewer}>`. Pages are oldest first, IDs unique,
105
+ cursors exclusive; an omitted cursor requests the newest page. `around` returns
106
+ a contiguous page containing the target. The source must report gaps with
107
+ `hasNewer`/`hasOlder`, never join disjoint pages. No transport is built in.
108
+
109
+ `createStreamWindow` defaults to `pageSize: 50`, `prefetch: 30`, `ceiling: 500`.
110
+ The ceiling bounds retained messages: loading older drops the newest end and
111
+ marks `hasNewer`; loading newer drops the oldest end and marks `hasOlder`.
112
+ Jump replaces the window, preserves the gap boundary and publishes `highlighted`.
113
+ A missing target or failed load preserves existing history and exposes `error`;
114
+ retry clears the error. Concurrent page calls coalesce; jumps abort stale loads.
115
+ `state()` returns a snapshot; `subscribe(fn)` returns an unsubscribe function.
116
+ `loadNewer()` may poll at the live tail after a host receives new messages.
117
+
118
+ The stream renders a measured virtual range, prefetches near the edges and
119
+ anchors keyed rows on prepend. It follows the bottom until the user scrolls up.
120
+ “Follow latest” resumes following within the loaded window; hosts can jump to
121
+ their newest known ID to replace a historical window. The composer publishes
122
+ its measured height in an animation frame after ResizeObserver; the stream
123
+ reserves that exact height. The textarea can exceed half the viewport.
124
+
125
+ The host owns windows: destroy renderer handles and call `window.disconnect()`
126
+ on teardown. Observers, menus, listeners and queued frames are cleaned up by the
127
+ renderer; disconnecting a window aborts its outstanding source load.
128
+
129
+ ## Appearance
130
+
131
+ The four skin files in `skins/` are #19 token sets, with `dark` modes, adapted
132
+ from meta-sovereign's Unlicense `app.css`. Telegram, WhatsApp and Signal retain
133
+ 15px, 7.5px and 18px bubble radii. `cards`, `compact`, `bubbles` are independent
134
+ token sets; concatenate their generated CSS after the chosen skin. `readTokens`,
135
+ `resolveTokens` and `toCss` from ui-tokens generate scoped CSS; the example
136
+ handles system color-scheme changes and skin/style switches. Selection and
137
+ bubble contrast tests check WCAG AA in both modes. Motion honors the user's
138
+ reduced-motion setting. No GPL/AGPL client code is included.
139
+
140
+ Model inspiration: meta-sovereign `chat-model.js`, `chat-view.js` and composer
141
+ geometry; formal-ai research informed interaction requirements only. Provider
142
+ imports, entity formats and receipt counters deliberately stay in adapters.
@@ -0,0 +1,75 @@
1
+ import { createMenu } from '../overlays/menu.js';
2
+ import { virtualAnchor } from '../overlays/position.js';
3
+ import { chatOf, chatOptions, chatRecords, emit, make, uid } from './dom.js';
4
+ import { messageActions } from './message-bubble.js';
5
+
6
+ /** One APG menu per stream, with a target independent of selected messages. */
7
+ export function createChatActions(node, selection, ctx) {
8
+ let menu;
9
+ let surface;
10
+ const close = () => {
11
+ menu?.disconnect();
12
+ surface?.remove();
13
+ menu = null;
14
+ };
15
+ return {
16
+ open(message, anchor, point) {
17
+ close();
18
+ selection.target(message.id);
19
+ const actions = messageActions(chatOf(message, ctx), message);
20
+ if (!actions.length) {
21
+ return;
22
+ }
23
+ const labels = chatOptions(ctx).labels ?? {};
24
+ surface = make(ctx.document, 'div', {
25
+ class: 'ui-chat-menu',
26
+ hidden: true,
27
+ });
28
+ node.append(surface);
29
+ const el = {
30
+ id: uid('chat-actions'),
31
+ props: new Map([['label', [labels.actions ?? 'Message actions']]]),
32
+ properties: actions.map((action) => ({
33
+ name: 'item',
34
+ values: [
35
+ action,
36
+ ['label', labels[action] ?? action],
37
+ ['on', 'select', ['emit', action]],
38
+ ],
39
+ })),
40
+ };
41
+ menu = createMenu(
42
+ surface,
43
+ el,
44
+ {
45
+ ...ctx,
46
+ options: {
47
+ ...ctx.options,
48
+ onAction(detail) {
49
+ // Recheck current capabilities when the host updates data while open.
50
+ if (
51
+ messageActions(
52
+ chatOf(message, ctx),
53
+ chatRecords(ctx).find((r) => r.id === message.id) ?? message
54
+ ).includes(detail.action[1])
55
+ ) {
56
+ emit(node, 'ui-chat-action', {
57
+ action: detail.action[1],
58
+ message: message.id,
59
+ selection: [...selection.state().selected],
60
+ });
61
+ }
62
+ },
63
+ },
64
+ },
65
+ { manual: true, noTrigger: true }
66
+ );
67
+ menu.update(el, []);
68
+ menu.open(point ? virtualAnchor(point.x, point.y, anchor) : anchor, {
69
+ target: message.id,
70
+ selection: [...selection.state().selected],
71
+ });
72
+ },
73
+ disconnect: close,
74
+ };
75
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Provider-neutral, flat link records. References (chat, sender, message,
3
+ * reply-to and parent) are IDs, never provider identifiers to be interpreted.
4
+ * Applications adapt their transport records at this boundary.
5
+ * @typedef {'chat'|'message'|'participant'|'attachment'|'reaction'|'step'} ChatKind
6
+ * @typedef {{id: string, kind: ChatKind, [field: string]: string|number|boolean}} ChatRecord
7
+ * @typedef {ChatRecord & {chat?: string, sender?: string, time?: string, text?: string}} Message
8
+ * @typedef {ChatRecord & {'can-edit'?: boolean, 'can-react'?: boolean, 'can-reply'?: boolean, 'max-attachments'?: number}} Chat
9
+ */
10
+ import { parseLinks, formatLinks } from '@link-foundation/ui-core';
11
+
12
+ const KINDS = new Set([
13
+ 'chat',
14
+ 'message',
15
+ 'participant',
16
+ 'attachment',
17
+ 'reaction',
18
+ 'step',
19
+ ]);
20
+ const BOOLEAN = new Set([
21
+ 'can-edit',
22
+ 'can-react',
23
+ 'can-reply',
24
+ 'outgoing',
25
+ 'selected',
26
+ 'unread',
27
+ 'service',
28
+ ]);
29
+ const NUMBER = new Set(['count', 'size', 'max-attachments', 'pinned']);
30
+
31
+ function fieldValue(kind, name, value) {
32
+ if ((name === 'unread' && kind === 'chat') || NUMBER.has(name)) {
33
+ const number = Number(value);
34
+ if (value === '' || !Number.isSafeInteger(number) || number < 0) {
35
+ throw new TypeError(`Invalid ${name}`);
36
+ }
37
+ return number;
38
+ }
39
+ if (BOOLEAN.has(name)) {
40
+ if (value !== 'true' && value !== 'false') {
41
+ throw new TypeError(`Invalid ${name}`);
42
+ }
43
+ return value === 'true';
44
+ }
45
+ return value;
46
+ }
47
+
48
+ /** Read LiNo text or ui-core raw links (official links-notation parser). */
49
+ export function parseChatData(links) {
50
+ const roots = typeof links === 'string' ? parseLinks(links) : links;
51
+ const seen = new Set();
52
+ return roots.map((link) => {
53
+ if (!link.id || !KINDS.has(link.values?.[0]) || seen.has(link.id)) {
54
+ throw new TypeError('Chat records need unique IDs and a known kind');
55
+ }
56
+ seen.add(link.id);
57
+ const [kind, ...fields] = link.values;
58
+ const record = { id: link.id, kind };
59
+ for (const field of fields) {
60
+ if (
61
+ !Array.isArray(field) ||
62
+ field.length !== 2 ||
63
+ field.some((v) => typeof v !== 'string') ||
64
+ Object.hasOwn(record, field[0])
65
+ ) {
66
+ throw new TypeError('Chat fields must be unique scalar links');
67
+ }
68
+ Object.defineProperty(record, field[0], {
69
+ value: fieldValue(kind, ...field),
70
+ enumerable: true,
71
+ writable: true,
72
+ configurable: true,
73
+ });
74
+ }
75
+ return record;
76
+ });
77
+ }
78
+
79
+ /** Write nested LiNo; validate before returning text to keep the contract strict. */
80
+ export function chatDataToLino(data) {
81
+ const links = data.map(({ id, kind, ...fields }) => ({
82
+ id,
83
+ values: [
84
+ kind,
85
+ ...Object.entries(fields).map(([name, value]) => {
86
+ if (!['string', 'number', 'boolean'].includes(typeof value)) {
87
+ throw new TypeError('Chat fields must be scalar');
88
+ }
89
+ return [name, String(value)];
90
+ }),
91
+ ],
92
+ }));
93
+ parseChatData(links);
94
+ return formatLinks(links);
95
+ }
@@ -0,0 +1,42 @@
1
+ /** Chat list delegates measured virtualization and keyboard behavior to #37. */
2
+ import { mountDocument } from '@link-foundation/ui-dom';
3
+ import { formatLinks } from '@link-foundation/ui-core';
4
+ import { createDataSource, dataVocabulary } from '../data/index.js';
5
+ import { summarizeChats } from './chat-model.js';
6
+ import { atomOf, chatOptions, chatRecords, registerChatKind } from './dom.js';
7
+ registerChatKind('chat-list', (node, initial, ctx) => {
8
+ const options = chatOptions(ctx);
9
+ const source = createDataSource([]);
10
+ const mounted = mountDocument(
11
+ node,
12
+ formatLinks([
13
+ {
14
+ id: `${initial.id}-list`,
15
+ values: [
16
+ 'list',
17
+ ['label', atomOf(initial, 'label') ?? 'Chats'],
18
+ ['items', ['param', 'chats']],
19
+ ],
20
+ },
21
+ ]),
22
+ {
23
+ parseOptions: { vocabulary: dataVocabulary() },
24
+ data: { sources: { chats: source } },
25
+ }
26
+ );
27
+ const refresh = () =>
28
+ source.set(
29
+ summarizeChats(chatRecords(ctx)).map((c) => ({
30
+ ...c,
31
+ label: `${c.title ?? c.id}${c.unread ? ` · ${c.unread} ${options.labels?.unread ?? 'unread'}` : ''}${c.last ? ` — ${c.last.text ?? ''}` : ''}`,
32
+ }))
33
+ );
34
+ const unsubscribe = options.data?.subscribe?.(refresh);
35
+ return {
36
+ update: refresh,
37
+ disconnect() {
38
+ unsubscribe?.();
39
+ mounted.handle.destroy();
40
+ },
41
+ };
42
+ });
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Pure display shaping adapted from meta-sovereign's Unlicense chat-model.
3
+ * Provider receipt counters stay in host adapters; the contract has explicit
4
+ * unread and delivery values. Dates use an injected clock and time zone.
5
+ */
6
+ export const CHAT_FILTERS = Object.freeze(['all', 'unread']);
7
+ export const DAY_GROUPS = Object.freeze([
8
+ 'today',
9
+ 'yesterday',
10
+ 'week',
11
+ 'older',
12
+ ]);
13
+ const time = (m) => Date.parse(m?.time ?? '') || 0;
14
+
15
+ /** Stable chronological sort, pinned first for the latest order. */
16
+ export function sortChats(chats, order = 'latest') {
17
+ return [...chats].sort((a, b) => {
18
+ if (order === 'latest' && (a.pinned || b.pinned)) {
19
+ return (a.pinned || Infinity) - (b.pinned || Infinity);
20
+ }
21
+ return (order === 'oldest' ? 1 : -1) * (time(a.last) - time(b.last));
22
+ });
23
+ }
24
+
25
+ /** A supplied unread snapshot wins; otherwise count explicit incoming marks. */
26
+ export function unreadCount(messages, chat = {}) {
27
+ return chat.unread ?? messages.filter((m) => m.unread && !m.outgoing).length;
28
+ }
29
+
30
+ /** Explicit transport-independent delivery, including pending and failure. */
31
+ export function deliveryStatus(message) {
32
+ if (!message.outgoing) {
33
+ return null;
34
+ }
35
+ return message.status ?? 'pending';
36
+ }
37
+
38
+ /** A local calendar day as an ordinal; avoids 24-hour DST arithmetic. */
39
+ export function calendarDay(iso, timeZone = 'UTC') {
40
+ const date = new Date(iso);
41
+ if (!Number.isFinite(date.getTime())) {
42
+ return null;
43
+ }
44
+ const parts = Object.fromEntries(
45
+ new Intl.DateTimeFormat('en', {
46
+ timeZone,
47
+ year: 'numeric',
48
+ month: '2-digit',
49
+ day: '2-digit',
50
+ })
51
+ .formatToParts(date)
52
+ .map((p) => [p.type, p.value])
53
+ );
54
+ return (
55
+ Date.UTC(Number(parts.year), Number(parts.month) - 1, Number(parts.day)) /
56
+ 86400000
57
+ );
58
+ }
59
+
60
+ /** Calendar days with injected time, including DST transitions. */
61
+ export function dayGroup(iso, { clock, timeZone = 'UTC' }) {
62
+ const day = calendarDay(iso, timeZone);
63
+ if (day === null) {
64
+ return 'older';
65
+ }
66
+ const distance = calendarDay(clock(), timeZone) - day;
67
+ return distance === 0
68
+ ? 'today'
69
+ : distance === 1
70
+ ? 'yesterday'
71
+ : distance > 1 && distance <= 6
72
+ ? 'week'
73
+ : 'older';
74
+ }
75
+
76
+ export function dayLabel(
77
+ iso,
78
+ { clock, locale = 'en', timeZone = 'UTC', labels = {} }
79
+ ) {
80
+ const group = dayGroup(iso, { clock, timeZone });
81
+ return (
82
+ labels[group] ??
83
+ new Intl.DateTimeFormat(locale, { timeZone, dateStyle: 'medium' }).format(
84
+ new Date(iso)
85
+ )
86
+ );
87
+ }
88
+
89
+ export function summarizeChats(data, options = {}) {
90
+ const groups = new Map(
91
+ data
92
+ .filter((r) => r.kind === 'chat')
93
+ .map((r) => [r.id, { ...r, messages: [] }])
94
+ );
95
+ for (const message of data.filter((r) => r.kind === 'message')) {
96
+ groups.get(message.chat)?.messages.push(message);
97
+ }
98
+ return sortChats(
99
+ [...groups.values()].map(({ messages, ...chat }) => ({
100
+ ...chat,
101
+ last: [...messages].sort((a, b) => time(a) - time(b)).at(-1) ?? null,
102
+ unread: unreadCount(messages, chat),
103
+ }))
104
+ ).filter((chat) => options.filter !== 'unread' || chat.unread > 0);
105
+ }
106
+
107
+ /** Consecutive sender runs break on day, service line or a time gap. */
108
+ export function messageRuns(messages, { gap = 300000, timeZone = 'UTC' } = {}) {
109
+ const runs = [];
110
+ for (const message of messages) {
111
+ const last = runs.at(-1)?.messages.at(-1);
112
+ if (
113
+ !last ||
114
+ last.sender !== message.sender ||
115
+ last.service ||
116
+ message.service ||
117
+ time(message) - time(last) > gap ||
118
+ calendarDay(message.time, timeZone) !== calendarDay(last.time, timeZone)
119
+ ) {
120
+ runs.push({ sender: message.sender, messages: [] });
121
+ }
122
+ runs.at(-1).messages.push(message);
123
+ }
124
+ return runs;
125
+ }