@link-foundation/ui-components 0.0.0-stage → 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (402) hide show
  1. package/CONFIGURATIONS.md +74 -0
  2. package/ICONS.md +76 -0
  3. package/LICENSE +24 -0
  4. package/README.md +1499 -2
  5. package/bin/lino-network.mjs +71 -0
  6. package/dist/icons/ATTRIBUTION.md +602 -0
  7. package/dist/icons/NOTICE.lino +1261 -0
  8. package/dist/icons/brand.js +31 -0
  9. package/dist/icons/brand.svg +3 -0
  10. package/dist/icons/licenses/brand/DISCLAIMER.md +51 -0
  11. package/dist/icons/licenses/brand/LICENSE.md +30 -0
  12. package/dist/icons/licenses/lucide/LICENSE +43 -0
  13. package/dist/icons/licenses/material-symbols/LICENSE +202 -0
  14. package/dist/icons/licenses/material-symbols/NOTICE +12 -0
  15. package/dist/icons/licenses/tabler/LICENSE +21 -0
  16. package/dist/icons/lucide.js +681 -0
  17. package/dist/icons/lucide.svg +34 -0
  18. package/dist/icons/material-symbols.js +681 -0
  19. package/dist/icons/material-symbols.svg +34 -0
  20. package/dist/icons/own.js +521 -0
  21. package/dist/icons/own.svg +34 -0
  22. package/dist/icons/tabler.js +681 -0
  23. package/dist/icons/tabler.svg +34 -0
  24. package/dist/network-layout-NOTICE.md +6 -0
  25. package/dist/network-layout-d3-dispatch-LICENSE.txt +13 -0
  26. package/dist/network-layout-d3-force-LICENSE.txt +13 -0
  27. package/dist/network-layout-d3-quadtree-LICENSE.txt +13 -0
  28. package/dist/network-layout-d3-timer-LICENSE.txt +13 -0
  29. package/dist/network-layout-dagre-LICENSE.txt +19 -0
  30. package/dist/network-layout.worker.mjs +2 -0
  31. package/package.json +246 -4
  32. package/src/a11y/announce.js +88 -0
  33. package/src/a11y/bind-machine.js +181 -0
  34. package/src/a11y/focus.js +169 -0
  35. package/src/a11y/index.d.ts +89 -0
  36. package/src/a11y/index.js +19 -0
  37. package/src/a11y/keys.js +182 -0
  38. package/src/a11y/roving.js +167 -0
  39. package/src/a11y/typeahead.js +82 -0
  40. package/src/behavior/actions.js +235 -0
  41. package/src/behavior/diagnostics.js +73 -0
  42. package/src/behavior/dom.d.ts +38 -0
  43. package/src/behavior/dom.js +420 -0
  44. package/src/behavior/index.d.ts +211 -0
  45. package/src/behavior/index.js +29 -0
  46. package/src/behavior/interpret.js +454 -0
  47. package/src/behavior/machines/disclosure.lino +46 -0
  48. package/src/behavior/machines/index.js +91 -0
  49. package/src/behavior/machines/toggle.lino +25 -0
  50. package/src/behavior/parse-machine.js +367 -0
  51. package/src/charts/README.md +78 -0
  52. package/src/charts/activity-layout.js +350 -0
  53. package/src/charts/activity-model.js +130 -0
  54. package/src/charts/activity-validation.js +31 -0
  55. package/src/charts/chart-model.js +667 -0
  56. package/src/charts/chart.js +518 -0
  57. package/src/charts/echarts-adapter.d.ts +23 -0
  58. package/src/charts/echarts-adapter.js +240 -0
  59. package/src/charts/element.js +330 -0
  60. package/src/charts/errors.js +62 -0
  61. package/src/charts/gauge.js +27 -0
  62. package/src/charts/index.d.ts +344 -0
  63. package/src/charts/index.js +59 -0
  64. package/src/charts/layout.js +542 -0
  65. package/src/charts/lino.js +158 -0
  66. package/src/charts/mark-options.js +78 -0
  67. package/src/charts/read.js +101 -0
  68. package/src/charts/renderer-features.js +8 -0
  69. package/src/charts/scales.js +223 -0
  70. package/src/charts/small-model.js +223 -0
  71. package/src/charts/small-svg.js +269 -0
  72. package/src/charts/sparkline.js +27 -0
  73. package/src/charts/stat-tile.js +37 -0
  74. package/src/charts/summary.js +193 -0
  75. package/src/charts/svg-renderer.js +226 -0
  76. package/src/charts/svg.js +69 -0
  77. package/src/charts/tag-cloud.js +129 -0
  78. package/src/charts/tokens.js +171 -0
  79. package/src/charts/tooltip.js +47 -0
  80. package/src/charts/values.js +146 -0
  81. package/src/chat/README.md +142 -0
  82. package/src/chat/actions.js +75 -0
  83. package/src/chat/chat-contract.js +95 -0
  84. package/src/chat/chat-list.js +42 -0
  85. package/src/chat/chat-model.js +125 -0
  86. package/src/chat/chat.css +228 -0
  87. package/src/chat/composer.js +131 -0
  88. package/src/chat/day-separator.js +12 -0
  89. package/src/chat/dom.js +33 -0
  90. package/src/chat/follow.js +49 -0
  91. package/src/chat/index.d.ts +142 -0
  92. package/src/chat/index.js +13 -0
  93. package/src/chat/message-bubble.js +191 -0
  94. package/src/chat/message-stream.js +331 -0
  95. package/src/chat/reasoning-trace.js +70 -0
  96. package/src/chat/selection.js +39 -0
  97. package/src/chat/skins/bubbles.lino +2 -0
  98. package/src/chat/skins/cards.lino +4 -0
  99. package/src/chat/skins/compact.lino +4 -0
  100. package/src/chat/skins/signal.lino +25 -0
  101. package/src/chat/skins/t3.lino +25 -0
  102. package/src/chat/skins/telegram.lino +31 -0
  103. package/src/chat/skins/whatsapp.lino +25 -0
  104. package/src/chat/stream-keys.js +57 -0
  105. package/src/chat/stream-window.js +159 -0
  106. package/src/chat/vocabulary.js +19 -0
  107. package/src/controls/accordion.js +160 -0
  108. package/src/controls/avatar.js +80 -0
  109. package/src/controls/badge.js +48 -0
  110. package/src/controls/button-template.js +32 -0
  111. package/src/controls/button.js +97 -0
  112. package/src/controls/catalog.lino +84 -0
  113. package/src/controls/checkbox.js +112 -0
  114. package/src/controls/chip.js +140 -0
  115. package/src/controls/choices.js +45 -0
  116. package/src/controls/color-field.js +217 -0
  117. package/src/controls/color-popover.js +135 -0
  118. package/src/controls/color-rgb.js +80 -0
  119. package/src/controls/color.js +67 -0
  120. package/src/controls/combobox.js +192 -0
  121. package/src/controls/dom.js +261 -0
  122. package/src/controls/icon-button.js +33 -0
  123. package/src/controls/index.d.ts +163 -0
  124. package/src/controls/index.js +182 -0
  125. package/src/controls/kinds-text.js +358 -0
  126. package/src/controls/kinds.lino +350 -0
  127. package/src/controls/label.js +52 -0
  128. package/src/controls/link.js +101 -0
  129. package/src/controls/listbox.js +144 -0
  130. package/src/controls/machines/button.lino +20 -0
  131. package/src/controls/machines/checkbox.lino +17 -0
  132. package/src/controls/machines/chip.lino +20 -0
  133. package/src/controls/machines/color-field.lino +23 -0
  134. package/src/controls/machines/combobox.lino +82 -0
  135. package/src/controls/machines/icon-button.lino +20 -0
  136. package/src/controls/machines/index.js +586 -0
  137. package/src/controls/machines/number-field.lino +71 -0
  138. package/src/controls/machines/radio-group.lino +17 -0
  139. package/src/controls/machines/select.lino +122 -0
  140. package/src/controls/machines/slider.lino +99 -0
  141. package/src/controls/machines/switch.lino +19 -0
  142. package/src/controls/machines/text-area.lino +26 -0
  143. package/src/controls/machines/text-field.lino +26 -0
  144. package/src/controls/number-field.js +239 -0
  145. package/src/controls/numeric-keys.js +125 -0
  146. package/src/controls/option.js +54 -0
  147. package/src/controls/progress.js +76 -0
  148. package/src/controls/radio-group.js +234 -0
  149. package/src/controls/select.js +229 -0
  150. package/src/controls/slider.js +234 -0
  151. package/src/controls/stories.js +172 -0
  152. package/src/controls/styles.css +1060 -0
  153. package/src/controls/switch.js +95 -0
  154. package/src/controls/text-area.js +39 -0
  155. package/src/controls/text-field.js +131 -0
  156. package/src/controls/vocabulary.js +164 -0
  157. package/src/data/data.css +95 -0
  158. package/src/data/index.d.ts +83 -0
  159. package/src/data/index.js +10 -0
  160. package/src/data/keyboard.js +189 -0
  161. package/src/data/list.js +215 -0
  162. package/src/data/render-data.js +116 -0
  163. package/src/data/selection-dom.js +39 -0
  164. package/src/data/selection-model.js +43 -0
  165. package/src/data/sort-model.js +42 -0
  166. package/src/data/source.js +45 -0
  167. package/src/data/table.js +160 -0
  168. package/src/data/tree-model.js +41 -0
  169. package/src/data/tree.js +55 -0
  170. package/src/data/viewport.js +216 -0
  171. package/src/data/virtual-range.js +92 -0
  172. package/src/data/vocabulary.js +67 -0
  173. package/src/diagrams/diagram-model.js +511 -0
  174. package/src/diagrams/diagram.js +204 -0
  175. package/src/diagrams/index.d.ts +225 -0
  176. package/src/diagrams/index.js +48 -0
  177. package/src/diagrams/layout-dagre.js +164 -0
  178. package/src/diagrams/layout-plugins.js +131 -0
  179. package/src/diagrams/mermaid-export.js +232 -0
  180. package/src/diagrams/mermaid-view.js +229 -0
  181. package/src/diagrams/svg-diagram.js +215 -0
  182. package/src/editor/code-editor.js +206 -0
  183. package/src/editor/documents-model.js +170 -0
  184. package/src/editor/documents-persistence.js +85 -0
  185. package/src/editor/editor-engine.js +22 -0
  186. package/src/editor/editor-ui.js +203 -0
  187. package/src/editor/editor.css +106 -0
  188. package/src/editor/engines/codemirror.js +227 -0
  189. package/src/editor/engines/monaco.js +219 -0
  190. package/src/editor/index.d.ts +111 -0
  191. package/src/editor/index.js +14 -0
  192. package/src/editor/lino-highlight.js +106 -0
  193. package/src/editor/lino-structure.js +85 -0
  194. package/src/editor/validate-lino.js +43 -0
  195. package/src/embed/README.md +161 -0
  196. package/src/embed/controller.js +223 -0
  197. package/src/embed/element.js +141 -0
  198. package/src/embed/index.d.ts +75 -0
  199. package/src/embed/index.js +9 -0
  200. package/src/embed/providers/telegram.d.ts +3 -0
  201. package/src/embed/providers/telegram.js +38 -0
  202. package/src/embed/providers/vk.d.ts +3 -0
  203. package/src/embed/providers/vk.js +42 -0
  204. package/src/embed/providers/x.d.ts +3 -0
  205. package/src/embed/providers/x.js +31 -0
  206. package/src/embed/registry.js +35 -0
  207. package/src/embed/script.js +73 -0
  208. package/src/embed/view.js +122 -0
  209. package/src/icons/adapters/lucide.d.ts +15 -0
  210. package/src/icons/adapters/lucide.js +142 -0
  211. package/src/icons/adapters/material-symbols.d.ts +13 -0
  212. package/src/icons/adapters/material-symbols.js +113 -0
  213. package/src/icons/adapters/shared.d.ts +38 -0
  214. package/src/icons/adapters/shared.js +157 -0
  215. package/src/icons/adapters/simple-icons.d.ts +9 -0
  216. package/src/icons/adapters/simple-icons.js +38 -0
  217. package/src/icons/adapters/tabler.d.ts +9 -0
  218. package/src/icons/adapters/tabler.js +86 -0
  219. package/src/icons/icon-registry.js +215 -0
  220. package/src/icons/icon.js +356 -0
  221. package/src/icons/index.d.ts +123 -0
  222. package/src/icons/index.js +30 -0
  223. package/src/icons/names.js +51 -0
  224. package/src/icons/own-icons.js +521 -0
  225. package/src/icons/presentation.js +55 -0
  226. package/src/icons/svg.js +136 -0
  227. package/src/index.d.ts +14 -0
  228. package/src/index.js +40 -0
  229. package/src/layout/README.md +102 -0
  230. package/src/layout/app-shell.js +150 -0
  231. package/src/layout/catalog.lino +27 -0
  232. package/src/layout/dock-model.js +576 -0
  233. package/src/layout/dock-view.js +312 -0
  234. package/src/layout/dock.js +352 -0
  235. package/src/layout/dom.js +312 -0
  236. package/src/layout/grid.js +192 -0
  237. package/src/layout/index.d.ts +267 -0
  238. package/src/layout/index.js +60 -0
  239. package/src/layout/layer-manager.js +120 -0
  240. package/src/layout/layout.css +760 -0
  241. package/src/layout/menu.js +141 -0
  242. package/src/layout/nav-strip.js +174 -0
  243. package/src/layout/page-links.js +166 -0
  244. package/src/layout/panel.js +26 -0
  245. package/src/layout/pref-switches.js +209 -0
  246. package/src/layout/split-model.js +270 -0
  247. package/src/layout/split.js +430 -0
  248. package/src/layout/stack.js +86 -0
  249. package/src/layout/surfaces.js +119 -0
  250. package/src/layout/tab-group.js +151 -0
  251. package/src/layout/tab-strip.js +277 -0
  252. package/src/layout/vocabulary.js +229 -0
  253. package/src/layout/window-frame.js +222 -0
  254. package/src/layout/window.js +146 -0
  255. package/src/links-view/animator.js +144 -0
  256. package/src/links-view/configuration-classes.js +150 -0
  257. package/src/links-view/configuration-model.js +191 -0
  258. package/src/links-view/configuration-notations.js +230 -0
  259. package/src/links-view/configurations.d.ts +73 -0
  260. package/src/links-view/configurations.js +33 -0
  261. package/src/links-view/create-layout-runner.js +79 -0
  262. package/src/links-view/doublet-curves.js +239 -0
  263. package/src/links-view/doublet-layout.js +148 -0
  264. package/src/links-view/doublet-markers.js +109 -0
  265. package/src/links-view/doublet-options.js +369 -0
  266. package/src/links-view/doublet-svg.js +156 -0
  267. package/src/links-view/doublet.js +230 -0
  268. package/src/links-view/export.js +146 -0
  269. package/src/links-view/geometry.js +409 -0
  270. package/src/links-view/index.d.ts +1029 -0
  271. package/src/links-view/index.js +140 -0
  272. package/src/links-view/labels.js +28 -0
  273. package/src/links-view/layout-worker-entry.mjs +2 -0
  274. package/src/links-view/layout-worker.js +28 -0
  275. package/src/links-view/layouts/circle.js +7 -0
  276. package/src/links-view/layouts/force.js +76 -0
  277. package/src/links-view/layouts/grid.js +7 -0
  278. package/src/links-view/layouts/hex.js +8 -0
  279. package/src/links-view/layouts/index.js +15 -0
  280. package/src/links-view/layouts/layered.js +29 -0
  281. package/src/links-view/layouts/regular.js +27 -0
  282. package/src/links-view/layouts/spiral.js +10 -0
  283. package/src/links-view/link-view.js +494 -0
  284. package/src/links-view/links-gallery.js +306 -0
  285. package/src/links-view/links-network.js +496 -0
  286. package/src/links-view/lino-network-source.js +122 -0
  287. package/src/links-view/lino-network.js +233 -0
  288. package/src/links-view/lino-to-network.js +252 -0
  289. package/src/links-view/markers.js +192 -0
  290. package/src/links-view/model.js +233 -0
  291. package/src/links-view/network-editor/dom.js +36 -0
  292. package/src/links-view/network-editor/editor.js +202 -0
  293. package/src/links-view/network-editor/model.js +163 -0
  294. package/src/links-view/network-editor/options.js +265 -0
  295. package/src/links-view/network-editor/panels.js +423 -0
  296. package/src/links-view/network-editor/presets.js +76 -0
  297. package/src/links-view/network-editor/provider.js +93 -0
  298. package/src/links-view/network-editor/remap.js +45 -0
  299. package/src/links-view/network-editor/schema.js +224 -0
  300. package/src/links-view/network-editor/share.js +232 -0
  301. package/src/links-view/network-editor/styles.js +19 -0
  302. package/src/links-view/network-editor/url-sync.js +131 -0
  303. package/src/links-view/network-interaction.js +228 -0
  304. package/src/links-view/network-model.js +85 -0
  305. package/src/links-view/network-renderer.js +259 -0
  306. package/src/links-view/network-scene.js +245 -0
  307. package/src/links-view/network-source.js +82 -0
  308. package/src/links-view/network-vocabulary.js +18 -0
  309. package/src/links-view/presentation.js +199 -0
  310. package/src/links-view/render-canvas.js +102 -0
  311. package/src/links-view/render-svg.js +118 -0
  312. package/src/links-view/scene.js +233 -0
  313. package/src/links-view/solver-job.js +106 -0
  314. package/src/links-view/tokens.js +114 -0
  315. package/src/links-view/zoom-pan.js +203 -0
  316. package/src/overlays/catalog.lino +89 -0
  317. package/src/overlays/context-menu.js +110 -0
  318. package/src/overlays/dialog.js +117 -0
  319. package/src/overlays/dom.js +168 -0
  320. package/src/overlays/drawer.js +8 -0
  321. package/src/overlays/index.d.ts +80 -0
  322. package/src/overlays/index.js +25 -0
  323. package/src/overlays/kinds.lino +137 -0
  324. package/src/overlays/list-popover.js +129 -0
  325. package/src/overlays/machines/index.js +71 -0
  326. package/src/overlays/machines/surface.lino +11 -0
  327. package/src/overlays/machines/tabs.lino +7 -0
  328. package/src/overlays/machines/toast.lino +16 -0
  329. package/src/overlays/machines/tooltip.lino +29 -0
  330. package/src/overlays/menu.js +240 -0
  331. package/src/overlays/popover.js +194 -0
  332. package/src/overlays/position.js +84 -0
  333. package/src/overlays/radial-geometry.js +38 -0
  334. package/src/overlays/radial-menu.js +50 -0
  335. package/src/overlays/styles.css +155 -0
  336. package/src/overlays/tabs.js +125 -0
  337. package/src/overlays/toast-queue.js +105 -0
  338. package/src/overlays/toast.js +163 -0
  339. package/src/overlays/tooltip.js +110 -0
  340. package/src/overlays/vocabulary.js +3 -0
  341. package/src/settings/conditions.js +44 -0
  342. package/src/settings/control-for.js +62 -0
  343. package/src/settings/field-control.js +201 -0
  344. package/src/settings/index.d.ts +201 -0
  345. package/src/settings/index.js +3 -0
  346. package/src/settings/messages.js +112 -0
  347. package/src/settings/miniature.js +26 -0
  348. package/src/settings/panel-actions.js +234 -0
  349. package/src/settings/panel-model.js +49 -0
  350. package/src/settings/panel-refresh.js +56 -0
  351. package/src/settings/panel-rows.js +200 -0
  352. package/src/settings/preset-cards.js +43 -0
  353. package/src/settings/saved-looks.js +227 -0
  354. package/src/settings/section-layout.js +95 -0
  355. package/src/settings/section-tabs.js +175 -0
  356. package/src/settings/settings-panel.js +192 -0
  357. package/src/settings/settings.css +178 -0
  358. package/stories/accordion.lino +14 -0
  359. package/stories/alert-dialog.lino +4 -0
  360. package/stories/app-bar.lino +10 -0
  361. package/stories/avatar.lino +7 -0
  362. package/stories/badge.lino +12 -0
  363. package/stories/button.lino +17 -0
  364. package/stories/card.lino +10 -0
  365. package/stories/checkbox.lino +14 -0
  366. package/stories/chip.lino +19 -0
  367. package/stories/color-field.lino +9 -0
  368. package/stories/combobox.lino +10 -0
  369. package/stories/container.lino +11 -0
  370. package/stories/context-menu.lino +15 -0
  371. package/stories/dialog.lino +16 -0
  372. package/stories/drawer.lino +12 -0
  373. package/stories/icon-button.lino +13 -0
  374. package/stories/label.lino +7 -0
  375. package/stories/link-cards.lino +9 -0
  376. package/stories/link.lino +9 -0
  377. package/stories/menu-item.lino +6 -0
  378. package/stories/menu-separator.lino +7 -0
  379. package/stories/menu.lino +30 -0
  380. package/stories/nav-strip.lino +11 -0
  381. package/stories/number-field.lino +16 -0
  382. package/stories/option.lino +10 -0
  383. package/stories/paper.lino +11 -0
  384. package/stories/popover.lino +4 -0
  385. package/stories/pref-switches.lino +4 -0
  386. package/stories/progress.lino +14 -0
  387. package/stories/radial-menu.lino +19 -0
  388. package/stories/radio-group.lino +22 -0
  389. package/stories/radio.lino +10 -0
  390. package/stories/section-nav.lino +9 -0
  391. package/stories/select.lino +16 -0
  392. package/stories/slider.lino +14 -0
  393. package/stories/switch.lino +10 -0
  394. package/stories/tab-panel.lino +7 -0
  395. package/stories/tab.lino +7 -0
  396. package/stories/tabs.lino +25 -0
  397. package/stories/text-area.lino +12 -0
  398. package/stories/text-field.lino +23 -0
  399. package/stories/titled-section.lino +7 -0
  400. package/stories/toast.lino +3 -0
  401. package/stories/toaster.lino +2 -0
  402. package/stories/tooltip.lino +3 -0
@@ -0,0 +1,203 @@
1
+ /**
2
+ * `createZoomPan(element, options)`: wheel zoom, drag pan and two-finger
3
+ * pinch for one element. Every listener is added to the element itself (a
4
+ * drag keeps receiving moves through pointer capture), never to `document`
5
+ * or `window`, so two views on a page zoom independently, and `destroy()`
6
+ * removes all of them.
7
+ *
8
+ * The view maps a point `p` of the content to `p · k + (x, y)` on the
9
+ * element. A wheel step of `delta` pixels zooms by `0.999 ** delta` around
10
+ * the pointer (links-visuals); a line step counts as 24 pixels.
11
+ */
12
+
13
+ /**
14
+ * @typedef {{x: number, y: number, k: number}} View
15
+ * @typedef {object} ZoomPanOptions
16
+ * @property {number} [min] the smallest zoom (default 0.1)
17
+ * @property {number} [max] the largest zoom (default 20)
18
+ * @property {View} [initial] default `{x: 0, y: 0, k: 1}`
19
+ * @property {(view: View, cause: string) => void} [onChange]
20
+ * @property {boolean} [wheel] zoom with the wheel (default true)
21
+ * @property {(message: string, data?: object) => void} [debug] traces
22
+ * every event (off by default)
23
+ * @typedef {object} ZoomPan
24
+ * @property {() => View} get
25
+ * @property {(view: Partial<View>) => View} set the zoom is clamped
26
+ * @property {() => View} reset back to the initial view
27
+ * @property {(factor: number, pivot?: {x: number, y: number}) => View} zoomBy
28
+ * the pivot stays in place (default: the middle of the element)
29
+ * @property {(dx: number, dy: number) => View} panBy
30
+ * @property {() => void} destroy
31
+ */
32
+
33
+ /** Pixels per wheel step for `deltaMode` 0 (pixels), 1 (lines), 2 (pages). */
34
+ const DELTA_SCALE = Object.freeze([1, 24, 800]);
35
+
36
+ /** The zoom factor of a wheel delta in pixels. */
37
+ export const wheelFactor = (delta) => 0.999 ** delta;
38
+
39
+ /** The wheel delta of an event in pixels. */
40
+ export const wheelDelta = (event) =>
41
+ event.deltaY * (DELTA_SCALE[event.deltaMode ?? 0] ?? 1);
42
+
43
+ const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
44
+
45
+ /** The position of an event relative to the element's top-left corner. */
46
+ function localPoint(element, event) {
47
+ const rect = element.getBoundingClientRect?.() ?? { left: 0, top: 0 };
48
+ return { x: event.clientX - rect.left, y: event.clientY - rect.top };
49
+ }
50
+
51
+ /** The middle of the element (the keyboard zoom pivot). */
52
+ function middle(element) {
53
+ const rect = element.getBoundingClientRect?.() ?? { width: 0, height: 0 };
54
+ return { x: rect.width / 2, y: rect.height / 2 };
55
+ }
56
+
57
+ /**
58
+ * Make an element zoomable and pannable.
59
+ * @param {HTMLElement} element
60
+ * @param {ZoomPanOptions} [options]
61
+ * @returns {ZoomPan}
62
+ */
63
+ export function createZoomPan(element, options = {}) {
64
+ const { min = 0.1, max = 20, onChange, debug } = options;
65
+ if (!(min > 0 && max >= min)) {
66
+ throw new RangeError('createZoomPan: needs 0 < min <= max');
67
+ }
68
+ const initial = { x: 0, y: 0, k: 1, ...options.initial };
69
+ initial.k = clamp(initial.k, min, max);
70
+ let view = { ...initial };
71
+ /** @type {Map<number, {x: number, y: number}>} */
72
+ const pointers = new Map();
73
+ let destroyed = false;
74
+
75
+ const emit = (next, cause) => {
76
+ const changed = next.x !== view.x || next.y !== view.y || next.k !== view.k;
77
+ view = next;
78
+ if (changed) {
79
+ debug?.('change', { view: { ...view }, cause });
80
+ onChange?.({ ...view }, cause);
81
+ }
82
+ return { ...view };
83
+ };
84
+
85
+ const zoomBy = (factor, pivot = middle(element), cause = 'zoom') => {
86
+ const k = clamp(view.k * factor, min, max);
87
+ const ratio = k / view.k;
88
+ return emit(
89
+ {
90
+ x: pivot.x - (pivot.x - view.x) * ratio,
91
+ y: pivot.y - (pivot.y - view.y) * ratio,
92
+ k,
93
+ },
94
+ cause
95
+ );
96
+ };
97
+
98
+ const panBy = (dx, dy, cause = 'pan') =>
99
+ emit({ x: view.x + dx, y: view.y + dy, k: view.k }, cause);
100
+
101
+ const onWheel = (event) => {
102
+ const delta = wheelDelta(event);
103
+ debug?.('wheel', { delta });
104
+ if (delta === 0) {
105
+ return;
106
+ }
107
+ event.preventDefault();
108
+ zoomBy(wheelFactor(delta), localPoint(element, event), 'wheel');
109
+ };
110
+
111
+ /** The middle and spread of the two first pointers (a pinch). */
112
+ const pinch = () => {
113
+ const [a, b] = [...pointers.values()];
114
+ return {
115
+ center: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 },
116
+ spread: Math.hypot(b.x - a.x, b.y - a.y),
117
+ };
118
+ };
119
+
120
+ const onPointerDown = (event) => {
121
+ if (event.pointerType === 'mouse' && event.button !== 0) {
122
+ return;
123
+ }
124
+ pointers.set(event.pointerId, localPoint(element, event));
125
+ element.setPointerCapture?.(event.pointerId);
126
+ debug?.('pointerdown', { id: event.pointerId, count: pointers.size });
127
+ };
128
+
129
+ const onPointerMove = (event) => {
130
+ const last = pointers.get(event.pointerId);
131
+ if (last === undefined) {
132
+ return;
133
+ }
134
+ const now = localPoint(element, event);
135
+ if (pointers.size >= 2) {
136
+ const before = pinch();
137
+ pointers.set(event.pointerId, now);
138
+ const after = pinch();
139
+ if (before.spread > 0) {
140
+ zoomBy(after.spread / before.spread, after.center, 'pinch');
141
+ }
142
+ panBy(
143
+ (after.center.x - before.center.x) / 2,
144
+ (after.center.y - before.center.y) / 2,
145
+ 'pinch'
146
+ );
147
+ return;
148
+ }
149
+ pointers.set(event.pointerId, now);
150
+ panBy(now.x - last.x, now.y - last.y, 'drag');
151
+ };
152
+
153
+ const onPointerEnd = (event) => {
154
+ if (!pointers.delete(event.pointerId)) {
155
+ return;
156
+ }
157
+ if (element.hasPointerCapture?.(event.pointerId)) {
158
+ element.releasePointerCapture?.(event.pointerId);
159
+ }
160
+ debug?.('pointerup', { id: event.pointerId, count: pointers.size });
161
+ };
162
+
163
+ const listeners = [
164
+ ['pointerdown', onPointerDown],
165
+ ['pointermove', onPointerMove],
166
+ ['pointerup', onPointerEnd],
167
+ ['pointercancel', onPointerEnd],
168
+ ['lostpointercapture', onPointerEnd],
169
+ ];
170
+ if (options.wheel !== false) {
171
+ listeners.push(['wheel', onWheel, { passive: false }]);
172
+ }
173
+ for (const [type, fn, opts] of listeners) {
174
+ element.addEventListener(type, fn, opts);
175
+ }
176
+
177
+ return {
178
+ get: () => ({ ...view }),
179
+ set(next) {
180
+ return emit(
181
+ {
182
+ x: next.x ?? view.x,
183
+ y: next.y ?? view.y,
184
+ k: clamp(next.k ?? view.k, min, max),
185
+ },
186
+ 'set'
187
+ );
188
+ },
189
+ reset: () => emit({ ...initial }, 'reset'),
190
+ zoomBy: (factor, pivot) => zoomBy(factor, pivot),
191
+ panBy: (dx, dy) => panBy(dx, dy),
192
+ destroy() {
193
+ if (destroyed) {
194
+ return;
195
+ }
196
+ destroyed = true;
197
+ for (const [type, fn, opts] of listeners) {
198
+ element.removeEventListener(type, fn, opts);
199
+ }
200
+ pointers.clear();
201
+ },
202
+ };
203
+ }
@@ -0,0 +1,89 @@
1
+ dialog-catalog: component-entry
2
+ kind dialog
3
+ story 'packages/ui-components/stories/dialog.lino'
4
+ keyboard 'Tab Shift+Tab Escape'
5
+ machine surface
6
+
7
+ alert-dialog-catalog: component-entry
8
+ kind alert-dialog
9
+ story 'packages/ui-components/stories/alert-dialog.lino'
10
+ keyboard 'Tab Shift+Tab Escape'
11
+ machine surface
12
+
13
+ popover-catalog: component-entry
14
+ kind popover
15
+ story 'packages/ui-components/stories/popover.lino'
16
+ keyboard 'Escape'
17
+ machine surface
18
+
19
+ tooltip-catalog: component-entry
20
+ kind tooltip
21
+ story 'packages/ui-components/stories/tooltip.lino'
22
+ keyboard 'Tab Escape'
23
+ machine tooltip
24
+
25
+ menu-catalog: component-entry
26
+ kind menu
27
+ story 'packages/ui-components/stories/menu.lino'
28
+ keyboard 'ArrowDown ArrowUp Home End Enter Space Escape ArrowRight ArrowLeft typeahead'
29
+ machine surface
30
+
31
+ menu-item-catalog: component-entry
32
+ kind menu-item
33
+ story 'packages/ui-components/stories/menu-item.lino'
34
+ keyboard 'Enter Space'
35
+ machine surface
36
+
37
+ menu-separator-catalog: component-entry
38
+ kind menu-separator
39
+ story 'packages/ui-components/stories/menu-separator.lino'
40
+ keyboard 'none'
41
+ machine surface
42
+
43
+ context-menu-catalog: component-entry
44
+ kind context-menu
45
+ story 'packages/ui-components/stories/context-menu.lino'
46
+ keyboard 'ContextMenu Shift+F10 ArrowDown ArrowUp Home End Enter Space Escape typeahead'
47
+ machine surface
48
+
49
+ radial-menu-catalog: component-entry
50
+ kind radial-menu
51
+ story 'packages/ui-components/stories/radial-menu.lino'
52
+ keyboard 'ArrowRight ArrowLeft ArrowDown ArrowUp Home End Enter Space Escape'
53
+ machine surface
54
+
55
+ tabs-catalog: component-entry
56
+ kind tabs
57
+ story 'packages/ui-components/stories/tabs.lino'
58
+ keyboard 'ArrowRight ArrowLeft Home End Enter Space'
59
+ machine tabs
60
+
61
+ tab-catalog: component-entry
62
+ kind tab
63
+ story 'packages/ui-components/stories/tab.lino'
64
+ keyboard 'ArrowRight ArrowLeft Enter Space'
65
+ machine tabs
66
+
67
+ tab-panel-catalog: component-entry
68
+ kind tab-panel
69
+ story 'packages/ui-components/stories/tab-panel.lino'
70
+ keyboard 'Tab'
71
+ machine tabs
72
+
73
+ toast-catalog: component-entry
74
+ kind toast
75
+ story 'packages/ui-components/stories/toast.lino'
76
+ keyboard 'Tab Enter Space'
77
+ machine toast
78
+
79
+ toaster-catalog: component-entry
80
+ kind toaster
81
+ story 'packages/ui-components/stories/toaster.lino'
82
+ keyboard 'Tab'
83
+ machine toast
84
+
85
+ drawer-catalog: component-entry
86
+ kind drawer
87
+ story 'packages/ui-components/stories/drawer.lino'
88
+ keyboard 'Tab Shift+Tab Escape'
89
+ machine surface
@@ -0,0 +1,110 @@
1
+ /** Context menus intercept only their declared target. Selection is separate. */
2
+ import {
3
+ anchorOf,
4
+ atomOf,
5
+ clockOf,
6
+ listen,
7
+ make,
8
+ registerOverlay,
9
+ } from './dom.js';
10
+ import { createMenu } from './menu.js';
11
+ import { virtualAnchor } from './position.js';
12
+
13
+ export function createContextMenu(node, initial, ctx) {
14
+ let el = initial;
15
+ let destroyed = false;
16
+ let timer;
17
+ let origin;
18
+ const clock = clockOf(ctx);
19
+ const detach = [];
20
+ const menu = createMenu(node, el, ctx, { noTrigger: true, manual: true });
21
+ const cancel = () => {
22
+ clock.clearTimeout(timer);
23
+ timer = undefined;
24
+ };
25
+ globalThis.queueMicrotask(() => {
26
+ if (destroyed) {
27
+ return;
28
+ }
29
+ const target = anchorOf(node, el);
30
+ if (!target) {
31
+ return;
32
+ }
33
+ const show = (x, y) => {
34
+ const selection = ctx.options.overlays?.selection?.() ?? [];
35
+ menu.open(virtualAnchor(x, y, target), {
36
+ target: target.closest('[data-link-id]')?.dataset.linkId ?? target.id,
37
+ selection: [...selection],
38
+ });
39
+ };
40
+ const atTarget = () => {
41
+ const rect = target.getBoundingClientRect();
42
+ show(rect.left, rect.bottom);
43
+ };
44
+ detach.push(
45
+ listen(target, 'contextmenu', (event) => {
46
+ event.preventDefault();
47
+ cancel();
48
+ show(event.clientX, event.clientY);
49
+ })
50
+ );
51
+ detach.push(
52
+ listen(target, 'keydown', (event) => {
53
+ if (
54
+ event.key === 'ContextMenu' ||
55
+ (event.key === 'F10' && event.shiftKey)
56
+ ) {
57
+ event.preventDefault();
58
+ atTarget();
59
+ }
60
+ })
61
+ );
62
+ detach.push(
63
+ listen(target, 'pointerdown', (event) => {
64
+ if (event.pointerType !== 'touch') {
65
+ return;
66
+ }
67
+ cancel();
68
+ origin = { x: event.clientX, y: event.clientY };
69
+ timer = clock.setTimeout(
70
+ () => {
71
+ timer = undefined;
72
+ show(origin.x, origin.y);
73
+ },
74
+ Number(atomOf(el, 'long-press') ?? 600)
75
+ );
76
+ })
77
+ );
78
+ detach.push(
79
+ listen(target, 'pointermove', (event) => {
80
+ if (
81
+ origin &&
82
+ Math.hypot(event.clientX - origin.x, event.clientY - origin.y) > 10
83
+ ) {
84
+ cancel();
85
+ }
86
+ })
87
+ );
88
+ for (const type of ['pointerup', 'pointercancel', 'lostpointercapture']) {
89
+ detach.push(listen(target, type, cancel));
90
+ }
91
+ });
92
+ return {
93
+ ...menu,
94
+ update(next, changed) {
95
+ el = next;
96
+ menu.update(el, changed);
97
+ },
98
+ disconnect() {
99
+ destroyed = true;
100
+ cancel();
101
+ detach.forEach((fn) => fn());
102
+ menu.disconnect();
103
+ },
104
+ };
105
+ }
106
+ registerOverlay(
107
+ 'context-menu',
108
+ (el, ctx) => make(ctx.document, 'div', { hidden: true }),
109
+ createContextMenu
110
+ );
@@ -0,0 +1,117 @@
1
+ /** Modal dialog and alert dialog, backed by the browser's top layer. */
2
+ import { restoreFocus, trapFocus } from '../a11y/index.js';
3
+ import {
4
+ atomOf,
5
+ contentParts,
6
+ destroyParts,
7
+ emit,
8
+ layerSurface,
9
+ listen,
10
+ make,
11
+ registerOverlay,
12
+ surfaceState,
13
+ } from './dom.js';
14
+
15
+ export function createDialog(node, initial, ctx) {
16
+ let el = initial;
17
+ let previous;
18
+ let release;
19
+ let unlayer;
20
+ let destroyed = false;
21
+ const state = surfaceState(node, ctx);
22
+ const modal = () => el.kind !== 'drawer' || atomOf(el, 'modal') !== 'false';
23
+ const close = () => {
24
+ if (state.service.state !== 'open') {
25
+ return;
26
+ }
27
+ release?.();
28
+ release = undefined;
29
+ if (node.open) {
30
+ if (typeof node.close === 'function') {
31
+ node.close();
32
+ } else {
33
+ node.removeAttribute('open');
34
+ }
35
+ }
36
+ node.hidden = true;
37
+ unlayer?.();
38
+ unlayer = undefined;
39
+ state.service.send('close');
40
+ restoreFocus(previous);
41
+ emit(node, 'ui-close', { source: el.id });
42
+ };
43
+ const open = () => {
44
+ if (destroyed || state.service.state === 'open') {
45
+ return;
46
+ }
47
+ previous = ctx.document.activeElement;
48
+ node.hidden = false;
49
+ node.setAttribute('aria-modal', String(modal()));
50
+ if (modal() && typeof node.showModal === 'function') {
51
+ node.showModal();
52
+ release = trapFocus(node, { restore: false });
53
+ } else {
54
+ node.setAttribute('open', '');
55
+ unlayer = layerSurface(node, ctx, modal() ? 'modal' : 'dock');
56
+ if (modal()) {
57
+ release = trapFocus(node, { restore: false });
58
+ } else {
59
+ node.querySelector('button')?.focus();
60
+ }
61
+ }
62
+ state.service.send('open');
63
+ };
64
+ const detach = [
65
+ listen(node, 'cancel', (event) => {
66
+ event.preventDefault();
67
+ close();
68
+ }),
69
+ listen(node, 'close', () => {
70
+ if (!node.open) {
71
+ close();
72
+ }
73
+ }),
74
+ listen(node, 'keydown', (event) => {
75
+ if (event.key === 'Escape') {
76
+ event.preventDefault();
77
+ event.stopPropagation();
78
+ close();
79
+ }
80
+ }),
81
+ ];
82
+ return {
83
+ open,
84
+ close,
85
+ service: state.service,
86
+ update(next) {
87
+ el = next;
88
+ node.setAttribute(
89
+ 'role',
90
+ el.kind === 'alert-dialog' ? 'alertdialog' : 'dialog'
91
+ );
92
+ node.dataset.side = atomOf(el, 'side') ?? 'right';
93
+ contentParts(node, el, close, ctx);
94
+ if (atomOf(el, 'open') === 'true') {
95
+ globalThis.queueMicrotask(open);
96
+ } else if (atomOf(el, 'open') === 'false') {
97
+ close();
98
+ } else if (state.service.state === 'closed') {
99
+ node.hidden = true;
100
+ }
101
+ },
102
+ disconnect() {
103
+ destroyed = true;
104
+ close();
105
+ destroyParts(node);
106
+ state.stop();
107
+ detach.forEach((fn) => fn());
108
+ },
109
+ };
110
+ }
111
+ for (const kind of ['dialog', 'alert-dialog']) {
112
+ registerOverlay(
113
+ kind,
114
+ (el, ctx) => make(ctx.document, 'dialog', { hidden: true }),
115
+ createDialog
116
+ );
117
+ }
@@ -0,0 +1,168 @@
1
+ /** Shared kind lifecycle, native parts, actions and layer registration. */
2
+ import { defineKind, mountDocument } from '@link-foundation/ui-dom';
3
+ import { formatLinks } from '@link-foundation/ui-core';
4
+ import { createActionRegistry, interpret } from '../behavior/index.js';
5
+ import {
6
+ atomOf,
7
+ controllerOf,
8
+ dropController,
9
+ emit,
10
+ idOf,
11
+ isLive,
12
+ layersOf,
13
+ make,
14
+ watchChildren,
15
+ } from '../layout/dom.js';
16
+ import { SURFACE_MACHINE } from './machines/index.js';
17
+ export { atomOf, emit, idOf, make, watchChildren };
18
+
19
+ export const overlayController = (node) => controllers.get(node);
20
+ const controllers = new WeakMap();
21
+ const partHandles = new WeakMap();
22
+ export function destroyParts(node) {
23
+ (partHandles.get(node) ?? []).forEach(({ handle }) => handle.destroy());
24
+ partHandles.delete(node);
25
+ }
26
+ const defaultClock = {
27
+ setTimeout: (fn, ms) => globalThis.setTimeout(fn, ms),
28
+ clearTimeout: (id) => globalThis.clearTimeout(id),
29
+ };
30
+ export const clockOf = (ctx) => ctx.options.overlays?.clock ?? defaultClock;
31
+
32
+ export function registerOverlay(kind, create, setup, update = () => {}) {
33
+ defineKind(kind, {
34
+ tag: `ui-${kind}`,
35
+ create: (el, ctx) => create(el, ctx),
36
+ update(node, el, changed, ctx) {
37
+ if (!node.id) {
38
+ node.id = `ui-${kind}-${encodeURIComponent(el.id)}`;
39
+ }
40
+ node.classList.add('ui-overlay');
41
+ node.dataset.kind = kind;
42
+ if (isLive(ctx)) {
43
+ const controller = controllerOf(node, () => setup(node, el, ctx));
44
+ controllers.set(node, controller);
45
+ controller.update?.(el, changed);
46
+ } else {
47
+ update(node, el, ctx);
48
+ }
49
+ },
50
+ destroy(node) {
51
+ dropController(node);
52
+ controllers.delete(node);
53
+ },
54
+ });
55
+ }
56
+
57
+ export function surfaceState(node, ctx, machine = SURFACE_MACHINE) {
58
+ const service = interpret(machine, {
59
+ clock: clockOf(ctx),
60
+ actions: createActionRegistry(),
61
+ });
62
+ node.dataset.state = service.state;
63
+ const unsubscribe = service.subscribe(({ state }) => {
64
+ node.dataset.state = state;
65
+ });
66
+ return {
67
+ service,
68
+ stop() {
69
+ unsubscribe();
70
+ service.stop();
71
+ },
72
+ };
73
+ }
74
+
75
+ export function layerSurface(node, ctx, layer) {
76
+ const manager = layersOf(ctx);
77
+ const id = idOf(node);
78
+ manager.register(id, layer);
79
+ const update = () => {
80
+ node.style.zIndex = String(manager.zIndexOf(id));
81
+ };
82
+ const unsubscribe = manager.subscribe(update);
83
+ update();
84
+ return () => {
85
+ unsubscribe();
86
+ manager.unregister(id);
87
+ };
88
+ }
89
+
90
+ export function listen(target, type, listener, options) {
91
+ target.addEventListener(type, listener, options);
92
+ return () => target.removeEventListener(type, listener, options);
93
+ }
94
+
95
+ /** Find a declared anchor by DOM id or stable link id without selector injection. */
96
+ export function anchorOf(node, el) {
97
+ const id = atomOf(el, 'anchor');
98
+ const doc = node.ownerDocument;
99
+ const anchor =
100
+ doc.getElementById(id) ??
101
+ [...doc.querySelectorAll('[data-link-id]')].find(
102
+ (item) => item.dataset.linkId === id
103
+ ) ??
104
+ null;
105
+ return anchor?.localName === 'ui-button'
106
+ ? (anchor.querySelector('button') ?? anchor)
107
+ : anchor;
108
+ }
109
+
110
+ /** Render the simple title/body/actions parts used in the dialect example.
111
+ * Rich content can also be supplied as regular rendered children. */
112
+ export function contentParts(node, el, onClose, ctx) {
113
+ let title = node.querySelector(':scope > [data-part="title"]');
114
+ if (!title) {
115
+ title = make(ctx.document, 'h2', {
116
+ 'data-part': 'title',
117
+ id: `${idOf(node)}-title`,
118
+ });
119
+ node.prepend(title);
120
+ }
121
+ title.textContent = atomOf(el, 'title') ?? atomOf(el, 'label') ?? el.kind;
122
+ node.setAttribute('aria-labelledby', title.id);
123
+ let body = node.querySelector(':scope > [data-part="body"]');
124
+ if (!body) {
125
+ body = make(ctx.document, 'div', { 'data-part': 'body' });
126
+ node.append(body);
127
+ }
128
+ const old = partHandles.get(node) ?? [];
129
+ old.forEach(({ handle }) => handle.destroy());
130
+ body.replaceChildren();
131
+ let actions = node.querySelector(':scope > [data-part="actions"]');
132
+ if (!actions) {
133
+ actions = make(ctx.document, 'div', { 'data-part': 'actions' });
134
+ node.append(actions);
135
+ }
136
+ actions.replaceChildren();
137
+ const handles = [];
138
+ for (const [part, container] of [
139
+ ['body', body],
140
+ ['actions', actions],
141
+ ]) {
142
+ const raw = el.props.get(part) ?? [];
143
+ if (raw.length === 1 && typeof raw[0] === 'string') {
144
+ container.textContent = raw[0];
145
+ } else if (raw.length) {
146
+ handles.push(
147
+ mountDocument(container, formatLinks(raw), {
148
+ ...ctx.options,
149
+ onAction(detail, event) {
150
+ ctx.options.onAction?.(detail, event);
151
+ if (detail.action[0] === 'emit' && detail.action[1] === 'close') {
152
+ onClose();
153
+ }
154
+ },
155
+ })
156
+ );
157
+ }
158
+ }
159
+ partHandles.set(node, handles);
160
+ const close = make(
161
+ ctx.document,
162
+ 'button',
163
+ { type: 'button', 'aria-label': 'Close', 'data-part': 'close' },
164
+ 'Close'
165
+ );
166
+ close.addEventListener('click', onClose);
167
+ actions.append(close);
168
+ }
@@ -0,0 +1,8 @@
1
+ /** Modal drawers use <dialog>; docked drawers share the dialog controller. */
2
+ import { createDialog } from './dialog.js';
3
+ import { make, registerOverlay } from './dom.js';
4
+ registerOverlay(
5
+ 'drawer',
6
+ (el, ctx) => make(ctx.document, 'dialog', { hidden: true }),
7
+ createDialog
8
+ );