@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,62 @@
1
+ /** The basic control used by each schema kind. Custom vector/list types are
2
+ * registered with ui-settings by the application, using defineFieldType. */
3
+ const CONTROLS = Object.freeze({
4
+ toggle: 'switch',
5
+ choice: 'select',
6
+ range: 'slider',
7
+ number: 'number-field',
8
+ color: 'color-field',
9
+ text: 'text-field',
10
+ vector: 'vector',
11
+ vector3: 'vector',
12
+ list: 'chips',
13
+ });
14
+
15
+ /** @param {import('@link-foundation/ui-settings').SettingField} field */
16
+ export function controlFor(field) {
17
+ const element = CONTROLS[field.type];
18
+ if (!element) {
19
+ throw new TypeError(`Unsupported settings control: ${field.type}`);
20
+ }
21
+ const props = { label: field.label ?? field.key };
22
+ if (element === 'number-field' && field.normalization?.numbers) {
23
+ props.normalization = field.normalization.numbers;
24
+ }
25
+ for (const key of ['min', 'max', 'step', 'unit', 'options']) {
26
+ if (field[key] !== undefined) {
27
+ props[key] = field[key];
28
+ }
29
+ }
30
+ for (const key of [
31
+ 'fallback',
32
+ 'inherit',
33
+ 'mode',
34
+ 'palettes',
35
+ 'snapping',
36
+ 'rgb',
37
+ 'palette',
38
+ 'menu-min-width',
39
+ 'menu-max-height',
40
+ ]) {
41
+ if (field.props?.[key] !== undefined) {
42
+ props[key] = field.props?.[key];
43
+ }
44
+ }
45
+ if (Array.isArray(props.palettes)) {
46
+ props.palettes = props.palettes.map((group) =>
47
+ group?.name
48
+ ? [
49
+ ['name', group.name],
50
+ [
51
+ 'colors',
52
+ ...group.colors.map((color) => [
53
+ ['name', color.name],
54
+ ['hex', color.hex],
55
+ ]),
56
+ ],
57
+ ]
58
+ : group
59
+ );
60
+ }
61
+ return { element, props };
62
+ }
@@ -0,0 +1,201 @@
1
+ import { formatLinks } from '@link-foundation/ui-core';
2
+ import { formatValue, equalValue } from '@link-foundation/ui-settings';
3
+ import { mountControls } from '../controls/index.js';
4
+ import { controlFor } from './control-for.js';
5
+
6
+ /** Mount the existing basic controls; vectors and chips compose native inputs. */
7
+ export function mountField(
8
+ container,
9
+ field,
10
+ value,
11
+ onChange,
12
+ id,
13
+ { messages } = {}
14
+ ) {
15
+ const doc = container.ownerDocument;
16
+ const { element, props } = controlFor(field);
17
+ const numberLabel = () =>
18
+ messages?.text('number', { label: props.label }) ?? `${props.label} number`;
19
+ if (element === 'vector' || element === 'chips') {
20
+ return mountCollection(
21
+ container,
22
+ field,
23
+ value,
24
+ onChange,
25
+ element,
26
+ messages
27
+ );
28
+ }
29
+ if (element === 'color-field') {
30
+ props.rgb ??= true;
31
+ }
32
+ const editorLabels = () => {
33
+ const names =
34
+ element === 'number-field'
35
+ ? ['increment', 'decrement', 'inherit', 'inherited']
36
+ : element === 'color-field'
37
+ ? ['palette', 'rgb', 'red', 'green', 'blue']
38
+ : [];
39
+ return Object.fromEntries(
40
+ names
41
+ .map((key) => [
42
+ `${key}-label`,
43
+ messages?.text(key, { label: props.label }),
44
+ ])
45
+ .filter(([, value]) => value !== undefined)
46
+ );
47
+ };
48
+ Object.assign(props, editorLabels());
49
+ const property = element === 'switch' ? 'checked' : 'value';
50
+ const clauses = Object.entries(props)
51
+ .filter(([key]) => !['options', 'unit'].includes(key))
52
+ .map(([key, v]) => [key, ...(Array.isArray(v) ? v : [String(v)])]);
53
+ const optionLabels = choiceLabels(field);
54
+ const children =
55
+ element === 'select'
56
+ ? (field.options ?? []).map((v, i) => ({
57
+ id: `${id}-option-${i}`,
58
+ values: ['option', optionLabels.get(v) ?? v, ['value', v]],
59
+ }))
60
+ : [];
61
+ const source = formatLinks([
62
+ {
63
+ id,
64
+ values: [
65
+ element,
66
+ ...clauses,
67
+ ...(value === null ? [] : [[property, ...formatValue(field, value)]]),
68
+ ...children,
69
+ ],
70
+ },
71
+ ]);
72
+ const mounted = mountControls(container, source);
73
+ let labelsRevision = messages?.revision;
74
+ const change = (event) => onChange(event.detail.value);
75
+ container.addEventListener('ui-change', change);
76
+ let number;
77
+ if (element === 'slider') {
78
+ number = doc.createElement('input');
79
+ number.type = 'number';
80
+ number.setAttribute('aria-label', numberLabel());
81
+ for (const key of ['min', 'max', 'step']) {
82
+ if (field[key] !== undefined) {
83
+ number[key] = field[key];
84
+ }
85
+ }
86
+ number.value = String(value);
87
+ number.addEventListener('input', () =>
88
+ onChange(number.value === '' ? null : Number(number.value))
89
+ );
90
+ container.append(number);
91
+ }
92
+ return {
93
+ update(next) {
94
+ if (labelsRevision !== messages?.revision) {
95
+ labelsRevision = messages?.revision;
96
+ for (const [key, label] of Object.entries(editorLabels())) {
97
+ mounted.store.setProp(id, key, [label]);
98
+ }
99
+ }
100
+ if (number) {
101
+ number.setAttribute('aria-label', numberLabel());
102
+ }
103
+ if (next === null) {
104
+ if (mounted.store.get(id).properties.some((p) => p.name === property)) {
105
+ mounted.store.removeProp(id, property);
106
+ }
107
+ } else {
108
+ mounted.store.setProp(id, property, formatValue(field, next));
109
+ }
110
+ if (number) {
111
+ number.value = String(next);
112
+ }
113
+ },
114
+ destroy() {
115
+ container.removeEventListener('ui-change', change);
116
+ mounted.destroy();
117
+ },
118
+ };
119
+ }
120
+
121
+ function mountCollection(container, field, value, onChange, element, messages) {
122
+ const doc = container.ownerDocument;
123
+ let current = value;
124
+ let lastMessages = messages?.revision;
125
+ const render = () => {
126
+ container.replaceChildren();
127
+ const group = doc.createElement('fieldset');
128
+ const legend = doc.createElement('legend');
129
+ legend.textContent = field.label ?? field.key;
130
+ group.append(legend);
131
+ for (const [index, item] of current.entries()) {
132
+ if (element === 'vector') {
133
+ const input = doc.createElement('input');
134
+ input.type = 'number';
135
+ input.value = String(item);
136
+ input.setAttribute('aria-label', `${legend.textContent} ${index + 1}`);
137
+ input.addEventListener('change', () =>
138
+ onChange(
139
+ current.map((v, i) => (i === index ? Number(input.value) : v))
140
+ )
141
+ );
142
+ group.append(input);
143
+ } else {
144
+ const chip = doc.createElement('button');
145
+ chip.type = 'button';
146
+ chip.textContent = `${item} ×`;
147
+ chip.setAttribute(
148
+ 'aria-label',
149
+ messages?.text('remove', { label: item }) ?? `Remove ${item}`
150
+ );
151
+ chip.addEventListener('click', () =>
152
+ onChange(current.filter((_, i) => i !== index))
153
+ );
154
+ group.append(chip);
155
+ }
156
+ }
157
+ if (element === 'chips') {
158
+ const input = doc.createElement('input');
159
+ input.setAttribute(
160
+ 'aria-label',
161
+ messages?.text('add', { label: legend.textContent }) ??
162
+ `Add ${legend.textContent}`
163
+ );
164
+ const add = doc.createElement('button');
165
+ add.type = 'button';
166
+ add.textContent =
167
+ messages?.text('add', { label: legend.textContent }) ??
168
+ `Add ${legend.textContent}`;
169
+ add.addEventListener('click', () => {
170
+ if (input.value.trim()) {
171
+ onChange([...current, input.value.trim()]);
172
+ }
173
+ });
174
+ group.append(input, add);
175
+ }
176
+ container.append(group);
177
+ };
178
+ render();
179
+ return {
180
+ update(next) {
181
+ const nextMessages = messages?.revision;
182
+ if (equalValue(field, current, next) && lastMessages === nextMessages) {
183
+ return;
184
+ }
185
+ lastMessages = nextMessages;
186
+ current = next;
187
+ render();
188
+ },
189
+ destroy() {
190
+ container.replaceChildren();
191
+ },
192
+ };
193
+ }
194
+
195
+ function choiceLabels(field) {
196
+ const labels = field.props['option-labels'];
197
+ const pairs = Array.isArray(labels?.[0]) ? labels : [labels];
198
+ return new Map(
199
+ pairs.filter((pair) => Array.isArray(pair) && pair.length === 2)
200
+ );
201
+ }
@@ -0,0 +1,201 @@
1
+ import type {
2
+ SettingField,
3
+ SettingsSchema,
4
+ SettingsValues,
5
+ SettingsProjection,
6
+ SettingsSection,
7
+ } from '@link-foundation/ui-settings';
8
+ export interface SettingsTarget {
9
+ values(): SettingsValues;
10
+ update(values: SettingsValues): unknown;
11
+ subscribe?(listener: (values: SettingsValues) => void): () => void;
12
+ }
13
+ export interface PanelModelOptions {
14
+ query?: string;
15
+ tabs?: Record<string, string>;
16
+ level?: string;
17
+ sectionLevels?: Record<string, string>;
18
+ includeAll?: boolean;
19
+ }
20
+ export interface PanelModel {
21
+ sections: (SettingsSection & { fields: SettingField[] })[];
22
+ visibleCount: number;
23
+ changedCount: number;
24
+ activePreset?: string;
25
+ }
26
+ export interface FieldControl {
27
+ update(value: unknown): void;
28
+ destroy(): void;
29
+ }
30
+ export type SettingsMessageKey =
31
+ | 'back'
32
+ | 'inherit'
33
+ | 'inherited'
34
+ | 'levels'
35
+ | 'levelOwned'
36
+ | 'copyLooks'
37
+ | 'emptyLooks'
38
+ | 'defaultLook'
39
+ | 'updateLook'
40
+ | 'renameLook'
41
+ | 'looksError'
42
+ | 'settings'
43
+ | 'close'
44
+ | 'search'
45
+ | 'preset'
46
+ | 'custom'
47
+ | 'randomize'
48
+ | 'resetAll'
49
+ | 'confirmReset'
50
+ | 'peek'
51
+ | 'changes'
52
+ | 'copyText'
53
+ | 'copied'
54
+ | 'copyFallback'
55
+ | 'copyChanges'
56
+ | 'pasteChanges'
57
+ | 'invalid'
58
+ | 'applied'
59
+ | 'import'
60
+ | 'readError'
61
+ | 'export'
62
+ | 'share'
63
+ | 'shareError'
64
+ | 'lookName'
65
+ | 'looks'
66
+ | 'saveLook'
67
+ | 'applyLook'
68
+ | 'deleteLook'
69
+ | 'beforeLink'
70
+ | 'reset'
71
+ | 'tabs'
72
+ | 'value'
73
+ | 'changed'
74
+ | 'count'
75
+ | 'rejected'
76
+ | 'increment'
77
+ | 'decrement'
78
+ | 'palette'
79
+ | 'rgb'
80
+ | 'red'
81
+ | 'green'
82
+ | 'blue'
83
+ | 'number'
84
+ | 'remove'
85
+ | 'add';
86
+ export interface SettingsMessageParams {
87
+ label?: string;
88
+ count?: number;
89
+ keys?: string[];
90
+ }
91
+ export type SettingsMessages = Partial<
92
+ Record<
93
+ SettingsMessageKey,
94
+ string | ((params: SettingsMessageParams) => string)
95
+ >
96
+ >;
97
+ export interface SettingsPanelOptions extends PanelModelOptions {
98
+ document?: Document;
99
+ values?: SettingsValues;
100
+ target?: SettingsTarget;
101
+ mode?: 'page' | 'drawer';
102
+ label?: string;
103
+ messages?: SettingsMessages;
104
+ previewRoot?: HTMLElement;
105
+ project?: SettingsProjection;
106
+ onPreview?: (values: SettingsValues, root: HTMLElement) => void;
107
+ columns?: number | { count: number; balance: 'estimate' };
108
+ presets?: { display: 'cards' };
109
+ peek?: 'hold' | 'toggle';
110
+ looksStorage?: Pick<Storage, 'getItem' | 'setItem'> | null;
111
+ looksStorageKey?: string;
112
+ onChangedCount?: (count: number) => void;
113
+ mountMiniature?: (context: {
114
+ container: HTMLElement;
115
+ values: SettingsValues;
116
+ preset?: import('@link-foundation/ui-settings').SettingsPreset;
117
+ look?: string;
118
+ }) => { update?(values: SettingsValues): void; destroy?(): void };
119
+ random?: () => number;
120
+ randomLocked?: Iterable<string>;
121
+ confirmReset?: () => boolean;
122
+ shareUrl?: string;
123
+ sharedHash?: string;
124
+ savedLooks?: Record<string, SettingsValues>;
125
+ onLooksChange?: (looks: Record<string, SettingsValues>) => void;
126
+ formatCount?: (model: PanelModel) => string;
127
+ normalizeChanges?: (
128
+ values: SettingsValues,
129
+ changes: SettingsValues
130
+ ) => SettingsValues;
131
+ mountControl?: (
132
+ container: HTMLElement,
133
+ field: SettingField,
134
+ value: unknown,
135
+ onChange: (value: unknown) => void,
136
+ id: string
137
+ ) => FieldControl;
138
+ mountPreview?: (context: {
139
+ container: HTMLElement;
140
+ field?: SettingField;
141
+ section?: SettingsSection;
142
+ level?: string;
143
+ values: SettingsValues;
144
+ }) => {
145
+ update(
146
+ values: SettingsValues,
147
+ definition: SettingField | SettingsSection,
148
+ level?: string
149
+ ): void;
150
+ destroy?(): void;
151
+ };
152
+ codec?: {
153
+ read(
154
+ text: string,
155
+ options?: { base?: SettingsValues }
156
+ ): {
157
+ ok: boolean;
158
+ values: SettingsValues;
159
+ rejected: string[];
160
+ diagnostics?: { severity: string }[];
161
+ };
162
+ write(values: SettingsValues): string;
163
+ };
164
+ onChange?: (values: SettingsValues, changed: SettingsValues) => void;
165
+ }
166
+ export function controlFor(field: SettingField): {
167
+ element: string;
168
+ props: Record<string, unknown>;
169
+ };
170
+ export function buildPanelModel(
171
+ schema: SettingsSchema,
172
+ values: SettingsValues,
173
+ options?: PanelModelOptions
174
+ ): PanelModel;
175
+ export function createSettingsPanel(
176
+ schema: SettingsSchema,
177
+ options?: SettingsPanelOptions
178
+ ): {
179
+ element: HTMLElement;
180
+ values(): SettingsValues;
181
+ update(changes: SettingsValues): void;
182
+ setTab(section: string, tab: string): void;
183
+ setSectionLevel(section: string, level: string): void;
184
+ changedCount(): number;
185
+ setLevel(level?: string): void;
186
+ setMessages(messages: SettingsMessages): void;
187
+ saveLook(name?: string): boolean;
188
+ renameLook(name: string, nextName: string): boolean;
189
+ deleteLook(name: string): boolean;
190
+ exportLooks(): string;
191
+ applyLook(name: string): void;
192
+ applyShared(
193
+ hash: string
194
+ ): ReturnType<typeof import('@link-foundation/ui-settings').fromShareHash>;
195
+ restoreBeforeLink(): void;
196
+ importText(text: string): boolean;
197
+ exportText(): string;
198
+ open(trigger?: Element): void;
199
+ close(): void;
200
+ destroy(): void;
201
+ };
@@ -0,0 +1,3 @@
1
+ export { controlFor } from './control-for.js';
2
+ export { buildPanelModel } from './panel-model.js';
3
+ export { createSettingsPanel } from './settings-panel.js';
@@ -0,0 +1,112 @@
1
+ /** Host catalogs may use ui-i18n or any formatter; parameters stay structured. */
2
+ export const PANEL_MESSAGES = Object.freeze({
3
+ settings: 'Settings',
4
+ back: 'Back to my look',
5
+ inherit: ({ label }) => `Inherit ${label}`,
6
+ inherited: 'inherited',
7
+ levels: ({ label }) => `${label} levels`,
8
+ levelOwned: 'Own values',
9
+ copyLooks: 'Copy all looks',
10
+ emptyLooks: 'No saved looks yet',
11
+ defaultLook: ({ count }) => `Look ${count}`,
12
+ updateLook: 'Update to current',
13
+ renameLook: 'Rename look',
14
+ looksError:
15
+ 'Could not save or read looks. Check storage permissions or available space.',
16
+ close: 'Close settings',
17
+ search: 'Search settings',
18
+ preset: 'Preset',
19
+ custom: 'Custom',
20
+ randomize: 'Randomize',
21
+ resetAll: 'Reset everything',
22
+ confirmReset: 'Reset every setting to its default?',
23
+ peek: 'Peek defaults',
24
+ changes: 'Your changes',
25
+ copyText: 'Copy text',
26
+ copied: 'Copied',
27
+ copyFallback: 'Select and copy this text',
28
+ copyChanges: 'Copy changes',
29
+ pasteChanges: 'Paste changes',
30
+ invalid: 'Invalid settings. No changes applied.',
31
+ applied: 'Changes applied',
32
+ import: 'Import settings',
33
+ readError: 'Could not read settings',
34
+ export: 'Export settings',
35
+ share: 'Copy share link',
36
+ shareError: 'Could not create share link',
37
+ lookName: 'Look name',
38
+ looks: 'Saved looks',
39
+ saveLook: 'Save look',
40
+ applyLook: 'Apply saved look',
41
+ deleteLook: 'Delete saved look',
42
+ beforeLink: 'Before the link',
43
+ reset: ({ label }) => `Reset ${label}`,
44
+ tabs: ({ label }) => `${label} tabs`,
45
+ value: ({ label }) => `${label} value`,
46
+ changed: 'Changed',
47
+ count: ({ count }) => `${count} changed settings`,
48
+ rejected: ({ keys }) => `Invalid settings: ${keys.join(', ')}`,
49
+ increment: ({ label }) => `Increase ${label}`,
50
+ decrement: ({ label }) => `Decrease ${label}`,
51
+ palette: ({ label }) => `${label} palette`,
52
+ rgb: ({ label }) => `${label} RGB`,
53
+ red: ({ label }) => `${label} red`,
54
+ green: ({ label }) => `${label} green`,
55
+ blue: ({ label }) => `${label} blue`,
56
+ number: ({ label }) => `${label} number`,
57
+ remove: ({ label }) => `Remove ${label}`,
58
+ add: ({ label }) => `Add ${label}`,
59
+ });
60
+
61
+ export function createMessages(catalog = {}) {
62
+ let current = catalog;
63
+ let revision = 0;
64
+ const contents = new Map();
65
+ const bindings = new Map();
66
+ const text = (key, params = {}) => {
67
+ const value = current[key] ?? PANEL_MESSAGES[key];
68
+ return typeof value === 'function' ? value(params) : value;
69
+ };
70
+ const bind = (update, owner) => {
71
+ bindings.set(update, owner);
72
+ update();
73
+ };
74
+ return {
75
+ text,
76
+ get revision() {
77
+ return revision;
78
+ },
79
+ content(element, key, params) {
80
+ if (!contents.has(element)) {
81
+ bind(() => {
82
+ const item = contents.get(element);
83
+ if (item) {
84
+ element.textContent = text(...item);
85
+ }
86
+ }, element);
87
+ }
88
+ contents.set(element, [key, params]);
89
+ element.textContent = text(key, params);
90
+ },
91
+ message: (key, params) => () => text(key, params),
92
+ bind,
93
+ attr(element, name, key, params) {
94
+ bind(() => element.setAttribute(name, text(key, params)), element);
95
+ },
96
+ release(root) {
97
+ for (const [update, owner] of bindings) {
98
+ if (owner && root.contains(owner)) {
99
+ bindings.delete(update);
100
+ contents.delete(owner);
101
+ }
102
+ }
103
+ },
104
+ update(next) {
105
+ current = next;
106
+ revision++;
107
+ for (const update of bindings.keys()) {
108
+ update();
109
+ }
110
+ },
111
+ };
112
+ }
@@ -0,0 +1,26 @@
1
+ import { applyToRoot } from '@link-foundation/ui-settings';
2
+
3
+ /** Hosts may render site-specific content; the default uses the same projection as the live preview. */
4
+ export function miniature(context, parent, values, detail = {}) {
5
+ const container = context.node('div', undefined, parent);
6
+ container.className = 'settings-miniature';
7
+ container.setAttribute('aria-hidden', 'true');
8
+ container.inert = true;
9
+ const custom = context.options.mountMiniature?.({
10
+ container,
11
+ values,
12
+ ...detail,
13
+ });
14
+ if (!custom) {
15
+ context.node('span', 'Aa', container);
16
+ }
17
+ return {
18
+ update(next) {
19
+ applyToRoot(context.schema, next, container, {
20
+ project: context.options.project,
21
+ });
22
+ custom?.update?.(next);
23
+ },
24
+ destroy: () => custom?.destroy?.(),
25
+ };
26
+ }