@threadlabs/looma 0.42.0 → 0.43.1

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 (272) hide show
  1. package/components/ui-action-bar/ui-action-bar.html +1 -7
  2. package/components/ui-affordance-scope/ui-affordance-scope.html +4 -4
  3. package/components/ui-avatar/ui-avatar.html +0 -22
  4. package/components/ui-avatar-group/ui-avatar-group.html +1 -11
  5. package/components/ui-badge/ui-badge.html +57 -78
  6. package/components/ui-button/ui-button.html +36 -81
  7. package/components/ui-callout/ui-callout.html +30 -68
  8. package/components/ui-card/ui-card.html +47 -21
  9. package/components/ui-checkbox/ui-checkbox.html +1 -15
  10. package/components/ui-cluster/ui-cluster.html +1 -7
  11. package/components/ui-combobox/ui-combobox.html +7 -70
  12. package/components/ui-container/ui-container.html +2 -12
  13. package/components/ui-context-menu/ui-context-menu.html +1 -23
  14. package/components/ui-dialog/ui-dialog.html +1 -31
  15. package/components/ui-disclosure/ui-disclosure.html +1 -15
  16. package/components/ui-editor-mention-menu/ui-editor-mention-menu.js +3 -0
  17. package/components/ui-editor-slash-menu/ui-editor-slash-menu.js +4 -0
  18. package/components/ui-editor-table-overlay/ui-editor-table-overlay.html +3 -2
  19. package/components/ui-floating-action-button/ui-floating-action-button.html +0 -14
  20. package/components/ui-form-field/ui-form-field.html +2 -32
  21. package/components/ui-grid/ui-grid.html +1 -11
  22. package/components/ui-icon/ui-icon.html +1 -12
  23. package/components/ui-icon-button/ui-icon-button.html +52 -87
  24. package/components/ui-input/ui-input.html +5 -55
  25. package/components/ui-input-group/ui-input-group.html +1 -13
  26. package/components/ui-list/ui-list.html +0 -10
  27. package/components/ui-list-item/ui-list-item.html +1 -19
  28. package/components/ui-listbox/ui-listbox.html +0 -21
  29. package/components/ui-menu/ui-menu.html +0 -22
  30. package/components/ui-menu-item/ui-menu-item.html +0 -26
  31. package/components/ui-meter/ui-meter.html +11 -6
  32. package/components/ui-nav-item/ui-nav-item.html +0 -18
  33. package/components/ui-popover/ui-popover.html +0 -30
  34. package/components/ui-radio/ui-radio.html +7 -13
  35. package/components/ui-radio-group/ui-radio-group.html +0 -5
  36. package/components/ui-reel/ui-reel.html +1 -11
  37. package/components/ui-search-result-row/ui-search-result-row.html +0 -34
  38. package/components/ui-search-shell/ui-search-shell.html +1 -43
  39. package/components/ui-select/ui-select.html +0 -42
  40. package/components/ui-separator/ui-separator.html +0 -6
  41. package/components/ui-sidebar/ui-sidebar.html +2 -24
  42. package/components/ui-site-header/ui-site-header.html +0 -25
  43. package/components/ui-skeleton/ui-skeleton.html +0 -9
  44. package/components/ui-stack/ui-stack.html +6 -11
  45. package/components/ui-swatch/ui-swatch.html +0 -5
  46. package/components/ui-switch/ui-switch.html +1 -15
  47. package/components/ui-switcher/ui-switcher.html +1 -11
  48. package/components/ui-tabs/ui-tabs.html +1 -19
  49. package/components/ui-text/ui-text.html +19 -6
  50. package/components/ui-textarea/ui-textarea.html +0 -50
  51. package/components/ui-toast/ui-toast.html +12 -27
  52. package/components/ui-toast-region/ui-toast-region.html +13 -34
  53. package/components/ui-tooltip/ui-tooltip.html +1 -43
  54. package/components/ui-top-bar/ui-top-bar.html +1 -31
  55. package/components/ui-tree/ui-tree.html +1 -16
  56. package/components/ui-tree-item/ui-tree-item.html +1 -23
  57. package/components/ui-tree-item/ui-tree-item.js +0 -1
  58. package/dist/index.js +1 -1
  59. package/docs/README.md +13 -11
  60. package/docs/card.html +2 -6
  61. package/docs/card.js +7 -37
  62. package/docs/catalog.json +821 -202
  63. package/docs/catalog.mjs +1 -1
  64. package/docs/customizer-render.mjs +27 -14
  65. package/docs/customizer.js +42 -9
  66. package/docs/documentation.css +3 -7
  67. package/docs/examples/ui-button/examples/08-loading.behavior.js +1 -1
  68. package/docs/examples/ui-checkbox/examples/02-checked-indeterminate-and-disabled.behavior.js +1 -1
  69. package/docs/examples/ui-editor-mention-menu/examples/00-preview.behavior.js +1 -0
  70. package/docs/examples/ui-editor-slash-menu/examples/00-preview.behavior.js +81 -0
  71. package/docs/examples/ui-editor-table-overlay/examples/00-preview.behavior.js +24 -0
  72. package/docs/examples/ui-search-shell/examples/00-preview.behavior.js +14 -0
  73. package/docs/examples/ui-search-shell/examples/02-label-dismissible-status-and-footer.behavior.js +7 -7
  74. package/docs/examples/ui-toast/examples/01-authored.behavior.js +2 -2
  75. package/docs/index.d.ts +1 -1
  76. package/docs/local-server.mjs +2 -5
  77. package/docs/palette.mjs +5 -4
  78. package/docs/pastoral.svg +54 -0
  79. package/docs/portrait.svg +15 -0
  80. package/docs/render.mjs +33 -3
  81. package/docs/site.mjs +22 -54
  82. package/docs/theme.mjs +97 -35
  83. package/docs/value-editors.mjs +2 -1
  84. package/package.json +2 -2
  85. package/styles/ui-action-bar.css +3 -11
  86. package/styles/ui-affordance-scope.css +4 -4
  87. package/styles/ui-avatar-group.css +3 -15
  88. package/styles/ui-avatar.css +2 -26
  89. package/styles/ui-badge.css +56 -80
  90. package/styles/ui-button.css +35 -83
  91. package/styles/ui-callout.css +32 -72
  92. package/styles/ui-card.css +42 -18
  93. package/styles/ui-checkbox.css +3 -19
  94. package/styles/ui-cluster.css +2 -10
  95. package/styles/ui-combobox.css +7 -140
  96. package/styles/ui-container.css +2 -14
  97. package/styles/ui-context-menu.css +3 -27
  98. package/styles/ui-dialog.css +5 -67
  99. package/styles/ui-disclosure.css +3 -19
  100. package/styles/ui-editor-table-overlay.css +2 -2
  101. package/styles/ui-floating-action-button.css +2 -18
  102. package/styles/ui-form-field.css +4 -36
  103. package/styles/ui-grid.css +2 -14
  104. package/styles/ui-icon-button.css +51 -89
  105. package/styles/ui-icon.css +3 -16
  106. package/styles/ui-input-group.css +2 -14
  107. package/styles/ui-input.css +6 -57
  108. package/styles/ui-list-item.css +3 -23
  109. package/styles/ui-list.css +2 -14
  110. package/styles/ui-listbox.css +2 -44
  111. package/styles/ui-menu-item.css +2 -30
  112. package/styles/ui-menu.css +2 -26
  113. package/styles/ui-meter.css +8 -4
  114. package/styles/ui-nav-item.css +2 -22
  115. package/styles/ui-popover.css +2 -34
  116. package/styles/ui-radio-group.css +1 -6
  117. package/styles/ui-radio.css +9 -17
  118. package/styles/ui-reel.css +2 -14
  119. package/styles/ui-search-result-row.css +2 -38
  120. package/styles/ui-search-shell.css +3 -47
  121. package/styles/ui-select.css +2 -46
  122. package/styles/ui-separator.css +2 -10
  123. package/styles/ui-sidebar.css +4 -28
  124. package/styles/ui-site-header.css +1 -26
  125. package/styles/ui-skeleton.css +2 -12
  126. package/styles/ui-stack.css +4 -12
  127. package/styles/ui-swatch.css +1 -6
  128. package/styles/ui-switch.css +3 -19
  129. package/styles/ui-switcher.css +2 -14
  130. package/styles/ui-tabs.css +3 -23
  131. package/styles/ui-text.css +10 -2
  132. package/styles/ui-textarea.css +2 -54
  133. package/styles/ui-toast-region.css +29 -73
  134. package/styles/ui-toast.css +24 -54
  135. package/styles/ui-tooltip.css +3 -47
  136. package/styles/ui-top-bar.css +3 -35
  137. package/styles/ui-tree-item.css +5 -51
  138. package/styles/ui-tree.css +3 -20
  139. package/theme-system.css +6 -2
  140. package/tokens.css +55 -21
  141. package/vanilla/UiBadge.d.ts +1 -1
  142. package/vanilla/UiBadge.js +1 -1
  143. package/vanilla/UiButton.d.ts +1 -1
  144. package/vanilla/UiButton.js +1 -1
  145. package/vanilla/UiCard.d.ts +1 -1
  146. package/vanilla/UiCard.js +1 -1
  147. package/vanilla/UiEditorTableOverlay.js +50 -36
  148. package/vanilla/UiIconButton.d.ts +1 -1
  149. package/vanilla/UiIconButton.js +1 -1
  150. package/vanilla/UiMeter.d.ts +1 -1
  151. package/vanilla/UiMeter.js +1 -1
  152. package/vanilla/UiStack.js +1 -1
  153. package/vanilla/UiText.d.ts +1 -1
  154. package/vanilla/UiText.js +1 -1
  155. package/vue/UiActionBar.vue +3 -9
  156. package/vue/UiAffordanceScope.vue +4 -4
  157. package/vue/UiAvatar.vue +1 -28
  158. package/vue/UiAvatarGroup.vue +1 -11
  159. package/vue/UiBadge.d.ts +2 -2
  160. package/vue/UiBadge.vue +84 -81
  161. package/vue/UiButton.d.ts +2 -2
  162. package/vue/UiButton.vue +78 -97
  163. package/vue/UiCallout.vue +30 -71
  164. package/vue/UiCard.d.ts +2 -2
  165. package/vue/UiCard.vue +77 -26
  166. package/vue/UiCheckbox.vue +1 -15
  167. package/vue/UiCluster.vue +1 -10
  168. package/vue/UiCombobox.vue +13 -72
  169. package/vue/UiContainer.vue +1 -13
  170. package/vue/UiContextMenu.vue +1 -30
  171. package/vue/UiDialog.vue +3 -33
  172. package/vue/UiDisclosure.vue +1 -15
  173. package/vue/UiEditorTableOverlay.d.ts +11 -1
  174. package/vue/UiEditorTableOverlay.vue +100 -65
  175. package/vue/UiFloatingActionButton.vue +0 -22
  176. package/vue/UiFormField.vue +6 -33
  177. package/vue/UiGrid.vue +1 -13
  178. package/vue/UiIcon.vue +1 -16
  179. package/vue/UiIconButton.d.ts +2 -2
  180. package/vue/UiIconButton.vue +103 -99
  181. package/vue/UiInput.vue +1 -54
  182. package/vue/UiInputGroup.vue +8 -20
  183. package/vue/UiList.vue +2 -12
  184. package/vue/UiListItem.vue +8 -26
  185. package/vue/UiListbox.vue +0 -23
  186. package/vue/UiMenu.vue +1 -23
  187. package/vue/UiMenuItem.vue +0 -26
  188. package/vue/UiMeter.d.ts +2 -2
  189. package/vue/UiMeter.vue +47 -12
  190. package/vue/UiNavItem.vue +3 -21
  191. package/vue/UiPopover.vue +1 -32
  192. package/vue/UiRadio.vue +1 -11
  193. package/vue/UiRadioGroup.vue +0 -11
  194. package/vue/UiReel.vue +1 -11
  195. package/vue/UiSearchResultRow.vue +0 -35
  196. package/vue/UiSearchShell.vue +1 -53
  197. package/vue/UiSelect.vue +0 -42
  198. package/vue/UiSeparator.vue +0 -7
  199. package/vue/UiSidebar.vue +3 -26
  200. package/vue/UiSiteHeader.vue +0 -24
  201. package/vue/UiSkeleton.vue +0 -9
  202. package/vue/UiStack.vue +6 -11
  203. package/vue/UiSwatch.vue +1 -6
  204. package/vue/UiSwitch.vue +1 -15
  205. package/vue/UiSwitcher.vue +1 -14
  206. package/vue/UiTabs.vue +1 -19
  207. package/vue/UiText.d.ts +2 -2
  208. package/vue/UiText.vue +29 -4
  209. package/vue/UiTextarea.vue +0 -50
  210. package/vue/UiToast.vue +26 -34
  211. package/vue/UiToastRegion.vue +26 -55
  212. package/vue/UiTooltip.vue +1 -43
  213. package/vue/UiTopBar.vue +1 -34
  214. package/vue/UiTree.vue +2 -17
  215. package/vue/UiTreeItem.vue +2 -28
  216. package/vue/chunks/UiActionBar.js +1 -1
  217. package/vue/chunks/UiAffordanceScope.js +1 -1
  218. package/vue/chunks/UiAvatar.js +1 -1
  219. package/vue/chunks/UiAvatarGroup.js +1 -1
  220. package/vue/chunks/UiBadge.js +4 -2
  221. package/vue/chunks/UiButton.js +4 -2
  222. package/vue/chunks/UiCallout.js +1 -1
  223. package/vue/chunks/UiCard.js +5 -3
  224. package/vue/chunks/UiCheckbox.js +1 -1
  225. package/vue/chunks/UiCluster.js +2 -2
  226. package/vue/chunks/UiCombobox.js +3 -3
  227. package/vue/chunks/UiContainer.js +2 -2
  228. package/vue/chunks/UiContextMenu.js +1 -1
  229. package/vue/chunks/UiDialog.js +1 -1
  230. package/vue/chunks/UiDisclosure.js +1 -1
  231. package/vue/chunks/UiEditorTableOverlay.js +41 -13
  232. package/vue/chunks/UiFloatingActionButton.js +1 -1
  233. package/vue/chunks/UiFormField.js +1 -1
  234. package/vue/chunks/UiGrid.js +2 -2
  235. package/vue/chunks/UiIcon.js +1 -1
  236. package/vue/chunks/UiIconButton.js +4 -2
  237. package/vue/chunks/UiInput.js +1 -1
  238. package/vue/chunks/UiInputGroup.js +1 -1
  239. package/vue/chunks/UiList.js +1 -1
  240. package/vue/chunks/UiListItem.js +1 -1
  241. package/vue/chunks/UiListbox.js +1 -1
  242. package/vue/chunks/UiMenu.js +1 -1
  243. package/vue/chunks/UiMenuItem.js +1 -1
  244. package/vue/chunks/UiMeter.js +4 -2
  245. package/vue/chunks/UiNavItem.js +1 -1
  246. package/vue/chunks/UiPopover.js +1 -1
  247. package/vue/chunks/UiRadio.js +1 -1
  248. package/vue/chunks/UiRadioGroup.js +1 -1
  249. package/vue/chunks/UiReel.js +2 -2
  250. package/vue/chunks/UiSearchResultRow.js +1 -1
  251. package/vue/chunks/UiSearchShell.js +1 -1
  252. package/vue/chunks/UiSelect.js +1 -1
  253. package/vue/chunks/UiSeparator.js +1 -1
  254. package/vue/chunks/UiSidebar.js +1 -1
  255. package/vue/chunks/UiSiteHeader.js +1 -1
  256. package/vue/chunks/UiSkeleton.js +1 -1
  257. package/vue/chunks/UiStack.js +3 -3
  258. package/vue/chunks/UiSwatch.js +1 -1
  259. package/vue/chunks/UiSwitch.js +1 -1
  260. package/vue/chunks/UiSwitcher.js +2 -2
  261. package/vue/chunks/UiTabs.js +1 -1
  262. package/vue/chunks/UiText.js +4 -2
  263. package/vue/chunks/UiTextarea.js +1 -1
  264. package/vue/chunks/UiToast.js +1 -1
  265. package/vue/chunks/UiToastRegion.js +1 -1
  266. package/vue/chunks/UiTooltip.js +1 -1
  267. package/vue/chunks/UiTopBar.js +1 -1
  268. package/vue/chunks/UiTree.js +1 -1
  269. package/vue/chunks/UiTreeItem.js +1 -1
  270. package/vue/components.css +633 -2068
  271. package/vue/editor/index.js +7 -1
  272. package/docs/preview.js +0 -22
@@ -0,0 +1,54 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 400" role="img" aria-labelledby="title description">
2
+ <title id="title">A quiet afternoon in the countryside</title>
3
+ <desc id="description">Soft green hills surround a red-roofed farmhouse, a winding stream, and sheep grazing beneath a broad oak tree.</desc>
4
+ <rect width="640" height="400" fill="#e9efdf"/>
5
+ <circle cx="486" cy="85" r="36" fill="#edcd79"/>
6
+ <g fill="#faf8ed">
7
+ <path d="M65 89c0-12 10-21 22-20 4-20 35-24 46-6 16-4 30 8 29 23 14-2 25 7 25 18H65Z"/>
8
+ <path d="M300 58c2-11 17-16 26-9 10-15 33-10 36 7 13-3 25 6 25 17h-87Z"/>
9
+ </g>
10
+ <path d="M0 183c76-55 128-46 196-8 67 37 112-68 199-45 85 22 134 67 245 22v248H0Z" fill="#a9c2ad"/>
11
+ <path d="M0 227c108-62 189-36 285-8 111 33 182-60 355-18v199H0Z" fill="#89aa79"/>
12
+ <path d="M0 287c89-20 165-64 267-45 110 21 219 79 373 18v140H0Z" fill="#6b925e"/>
13
+ <path d="M0 349c128-72 240-22 363-4 116 17 190-36 277-31v86H0Z" fill="#52784f"/>
14
+ <path d="M362 211c-43 31 63 45 28 72-35 26-113 35-99 64 9 20 54 32 84 53h92c-40-44-127-52-124-72 3-19 79-31 84-57 6-30-94-38-55-60Z" fill="#c7deda"/>
15
+ <path d="M368 213c-28 26 57 44 31 65" fill="none" stroke="#e5eee0" stroke-width="4" stroke-linecap="round"/>
16
+ <path d="M168 214c-21 37-74 45-90 75-17 33 26 56 21 111h40c-1-57-48-77-38-105 10-27 72-45 80-81Z" fill="#d9c38b"/>
17
+ <g>
18
+ <rect x="121" y="173" width="88" height="53" fill="#f6ead0"/>
19
+ <path d="m109 177 56-39 56 39Z" fill="#a55d48"/>
20
+ <path d="m118 177 47-32 47 32Z" fill="#bd7458"/>
21
+ <rect x="181" y="191" width="15" height="35" rx="1" fill="#637961"/>
22
+ <rect x="135" y="189" width="20" height="19" rx="1" fill="#75999a"/>
23
+ <path d="M145 189v19m-10-9h20" stroke="#f6ead0" stroke-width="3"/>
24
+ <path d="M194 155v-17h9v23" fill="#a55d48"/>
25
+ <rect x="238" y="192" width="47" height="35" fill="#b67456"/>
26
+ <path d="m231 194 30-26 31 26Z" fill="#805947"/>
27
+ <rect x="253" y="207" width="16" height="20" fill="#765940"/>
28
+ </g>
29
+ <g fill="none" stroke="#f0dfb7" stroke-width="4" stroke-linecap="round">
30
+ <path d="m27 253 76-18m-65 3v27m25-34v27m25-34v27"/>
31
+ <path d="m222 248 74 11m-63-24v27m26-22v27m26-23v27"/>
32
+ </g>
33
+ <g>
34
+ <path d="m535 220-8 112h24l-6-112Z" fill="#6d6246"/>
35
+ <path d="m539 263-23-28m24 14 23-24" fill="none" stroke="#6d6246" stroke-width="8" stroke-linecap="round"/>
36
+ <path d="M482 232c-26-5-33-36-14-54-10-23 9-45 33-42 9-28 48-31 64-8 26-13 55 6 52 32 28 10 29 45 6 59 0 23-35 34-51 19-24 21-63 16-67-5Z" fill="#3c684d"/>
37
+ <path d="M484 174c4-21 29-30 44-18 9-24 45-22 53 3 22-5 38 13 34 31-43-17-86 6-131-16Z" fill="#527d55"/>
38
+ </g>
39
+ <g stroke="#465b48" stroke-width="3" stroke-linecap="round">
40
+ <path d="M385 323v9m17-10v9m47 13v8m16-10v9"/>
41
+ </g>
42
+ <g fill="#f4edda">
43
+ <ellipse cx="392" cy="317" rx="16" ry="10"/>
44
+ <ellipse cx="455" cy="338" rx="14" ry="9"/>
45
+ </g>
46
+ <g fill="#465b48">
47
+ <ellipse cx="406" cy="318" rx="5" ry="7"/>
48
+ <ellipse cx="468" cy="338" rx="4" ry="6"/>
49
+ </g>
50
+ <g fill="#e4ca80">
51
+ <circle cx="41" cy="370" r="3"/><circle cx="56" cy="351" r="3"/><circle cx="186" cy="346" r="3"/>
52
+ <circle cx="202" cy="364" r="3"/><circle cx="569" cy="363" r="3"/><circle cx="590" cy="346" r="3"/>
53
+ </g>
54
+ </svg>
@@ -0,0 +1,15 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96" role="img" aria-labelledby="title description">
2
+ <title id="title">Illustrated portrait of Maya Chen</title>
3
+ <desc id="description">A warm, abstract profile portrait on a violet background.</desc>
4
+ <defs>
5
+ <linearGradient id="background" x1="0" y1="0" x2="1" y2="1">
6
+ <stop offset="0" stop-color="#8078ed"/>
7
+ <stop offset="1" stop-color="#40389e"/>
8
+ </linearGradient>
9
+ </defs>
10
+ <rect width="96" height="96" rx="24" fill="url(#background)"/>
11
+ <circle cx="48" cy="38" r="18" fill="#f5c9a7"/>
12
+ <path d="M29 38c0-17 10-25 21-25 13 0 22 10 21 26-5-8-13-13-24-13-7 0-13 4-18 12Z" fill="#292238"/>
13
+ <path d="M18 96c2-23 13-35 30-35s28 12 30 35H18Z" fill="#f6f3ff"/>
14
+ <path d="M39 43c3 3 15 3 18 0" fill="none" stroke="#a45b50" stroke-width="2" stroke-linecap="round"/>
15
+ </svg>
package/docs/render.mjs CHANGED
@@ -3,13 +3,43 @@ import { escapeHtml as escape } from './catalog.mjs';
3
3
  import { createLoomaMarkdownIt } from '@threadlabs/looma/markdown/markdown-it';
4
4
 
5
5
  const descriptions = createLoomaMarkdownIt().set({ html: false });
6
+ export const cardDescription = description => (descriptions.parseInline(description ?? '', {})[0]?.children ?? []).map(token => token.content).join('').split(/(?<=[.!?])\s/)[0];
6
7
 
7
8
  const literal = value => escape(value).replaceAll('{', '\\{');
8
9
  const code = value => `<code>${literal(value ?? '—')}</code>`;
9
10
  const table = (head, rows) => `<table><thead><tr>${head.map(h => `<th>${literal(h)}</th>`).join('')}</tr></thead><tbody>${rows.map(row => `<tr>${row.map(value => `<td>${value}</td>`).join('')}</tr>`).join('')}</tbody></table>`;
10
11
  export const exampleKey = id => createHash('sha256').update(id).digest('hex').slice(0, 20);
11
12
  export const componentPath = component => `/${component.group === 'editor' ? 'editor' : 'components'}/${component.navigationParent ?? component.tag}/` + (component.navigationParent ? `#${component.tag}-api` : '');
12
- export const previewPath = example => `/_looma/preview/${exampleKey(example.id)}/`;
13
+ export const previewTag = example => `looma-preview-${exampleKey(example.id)}`;
14
+ export const previewMarkup = (example, namespace, base = '/', layout = false) => `<div slot="preview"><div data-preview="${escape(example.id)}"${layout || example.stretch ? ' data-preview-layout' : ''}>${scopedExampleMarkup(example, base, namespace)}</div></div>`;
15
+ export function exampleResources(examples, catalog) {
16
+ const resources = new Map([...catalog.resources ?? [], ...catalog.components].map(resource => [resource.tag, resource.resource]));
17
+ const tags = [...new Set(examples.flatMap(example => [...example.markup.matchAll(/<([a-z][\w]*-[\w-]+)\b/g)].map(match => match[1])))];
18
+ return tags.filter(tag => resources.has(tag)).map(tag => `<link rel="component" href="${escape(resources.get(tag))}">`).join('\n');
19
+ }
20
+
21
+ /** Keep authored ID relationships local when several examples share one document. */
22
+ export function scopedExampleMarkup(example, base = '/', namespace) {
23
+ const ids = new Set([...example.markup.matchAll(/\sid=["']([^"']+)["']/g)].map(match => match[1]));
24
+ const destinations = [...new Set([...example.markup.matchAll(/\bhref=["']#([^"']+)["']/g)].map(match => match[1]))].filter(id => !ids.has(id));
25
+ const markup = example.markup.replaceAll('src="/_looma/', `src="${base}_looma/`) + destinations.map(id => `<span id="${escape(id)}" hidden></span>`).join('');
26
+ return markup.replace(/<([a-z][\w:-]*)\b((?:[^>"']|"[^"]*"|'[^']*')*)>/gi, (tag, name, attributes) => {
27
+ if (name === 'img') attributes = attributes.replace(/\ssrc="([^"]*\/_looma\/[^"]*)"/, (_, url) => ` from:src="${escape(JSON.stringify(url))}"`);
28
+ const scoped = attributes.replace(/\s(id|for|commandfor|popovertarget|aria-labelledby|aria-describedby|aria-controls|aria-owns|aria-activedescendant|list|form|headers|href|name)\s*=\s*(["'])(.*?)\2/gi, (attribute, key, quote, value) => {
29
+ if (key === 'name' && !['ui-radio', 'ui-radio-group'].includes(name) && !(name === 'input' && /\btype=["']radio["']/.test(attributes))) return attribute;
30
+ if (!value || key === 'href' && !value.startsWith('#')) return attribute;
31
+ if (namespace) {
32
+ const scopedValue = (key === 'href' ? '#' : '') + value.replace(/^#/, '').split(/\s+/).map(id => `${namespace}-${id}`).join(' ');
33
+ return `${key === 'id' && !/\bdata-example-id=/.test(attributes) ? ` data-example-id="${escape(value)}"` : ''} ${key}="${escape(scopedValue)}"`;
34
+ }
35
+ const values = value.replace(/^#/, '').split(/\s+/);
36
+ const binding = values.map(id => `concat($namespace, '-', ${JSON.stringify(id)})`).join(', " ", ');
37
+ const source = key === 'href' ? `concat('#', ${binding})` : values.length > 1 ? `concat(${binding})` : `concat($namespace, '-', ${JSON.stringify(value)})`;
38
+ return `${key === 'id' && !/\bdata-example-id=/.test(attributes) ? ` data-example-id="${escape(value)}"` : ''} from:${key}="${escape(source)}"`;
39
+ });
40
+ return `<${name}${scoped}>`;
41
+ });
42
+ }
13
43
 
14
44
  export function apiBody(api, prefix = '') {
15
45
  const attributes = api.attributes ?? [];
@@ -71,7 +101,7 @@ export function exampleCodes(example, component, components) {
71
101
 
72
102
  /** The same card invocation is embedded in reference pages and rendered by the customizer. */
73
103
  export function cardMarkup(example, base = '/', component = {}, { reference = false, code: exampleCode = '' } = {}) {
74
- return `<looma-example-card identity="${escape(example.id)}"${reference ? ' reference' : ''} title="${escape(component.title ?? example.title)}" description="${escape(reference ? example.description : component.description ?? example.description)}" example-title="${escape(example.title)}" category="${escape(component.group ?? 'forms')}" tag="${escape(component.tag ?? '')}" package-name="${escape(component.package ?? '')}" native-root="${escape(component.root ? `<${component.root}>` : '')}" href="${component.tag ? base + componentPath(component).slice(1) : ''}" src="${base}${previewPath(example).slice(1)}"${example.resizable ? ' resizable' : ''}>${reference ? `<div slot="heading" class="looma-example-heading"><h3 id="example-${exampleKey(example.id)}">${escape(example.title)}</h3><p>${escape(example.description)}</p></div>` : ''}${exampleCode}</looma-example-card>`;
104
+ return `<looma-example-card identity="${escape(example.id)}"${reference ? ' reference' : ''} title="${escape(component.title ?? example.title)}" description="${escape(reference ? example.description : cardDescription(component.description ?? example.description))}" example-title="${escape(example.title)}" category="${escape(component.group ?? 'forms')}" tag="${escape(component.tag ?? '')}" package-name="${escape(component.package ?? '')}" native-root="${escape(component.root ? `<${component.root}>` : '')}" href="${component.tag ? base + componentPath(component).slice(1) : ''}"${example.resizable ? ' resizable' : ''}>${previewMarkup(example, `${reference ? 'reference' : 'catalog'}-${exampleKey(example.id)}`, base, component.group === 'layout')}${reference ? `<div slot="heading" class="looma-example-heading"><h3 id="example-${exampleKey(example.id)}">${escape(example.title)}</h3><p>${escape(example.description)}</p></div>` : ''}${exampleCode}</looma-example-card>`;
75
105
  }
76
106
 
77
107
  export function referencePage(component, catalog, cardResource, base) {
@@ -89,5 +119,5 @@ export function referencePage(component, catalog, cardResource, base) {
89
119
  return `<ui-tabs slot="code" label="Example syntax" group="syntax" style="--ui-tabs-panel-padding: 0px">${tabs}</ui-tabs>`;
90
120
  };
91
121
  const body = `<div class="looma-reference-examples"><ui-stack gap="xl">${examples.map(example => `<ui-card as="section" variant="subtle" padding="lg">${cardMarkup(example, base, catalog.components.find(c => c.examples.some(e => e.id === example.id)) ?? component, { reference: true, code: codes(example) })}</ui-card>`).join('')}</ui-stack></div>`;
92
- return `---\ntitle: ${JSON.stringify(component.title)}\ndescription: ${JSON.stringify(component.description || `${component.title} component reference.`)}\nid: ${JSON.stringify(component.id)}\n---\n\n# ${escape(component.title)}\n\n<div class="component-description"><p>${descriptions.renderInline(component.description).replaceAll('{', '\\{').replaceAll('\n', '&#10;')}</p></div>\n\n<link rel="component" href="${cardResource}">\n<link rel="component" href="${cardResource.replace(/card\.html$/, 'reference.html')}">\n<link rel="component" href="@threadlabs/looma/components/ui-card/ui-card.html">\n<link rel="component" href="@threadlabs/looma/components/ui-tabs/ui-tabs.html">\n<link rel="component" href="@threadlabs/looma/components/ui-disclosure/ui-disclosure.html">\n<link rel="component" href="@threadlabs/looma/components/ui-stack/ui-stack.html">\n\n<looma-reference>\n\n<div class="looma-reference-tabs"><ui-tabs label="Component reference" style="--ui-tabs-panel-padding: 0px; --ui-tabs-tab-min-block-size: var(--ui-control-size-lg)"><section aria-label="Examples">${body}</section><section aria-label="API"><h2 id="api">API</h2>\n${apiBody(component)}\n${parts.map(part => `<h2 id="${part.tag}-api">${literal(part.title)} API</h2><p>${literal(part.description)}</p>${apiBody(part, part.tag + '-')}`).join('\n')}</section></ui-tabs></div>\n\n</looma-reference>\n`;
122
+ return `---\ntitle: ${JSON.stringify(component.title)}\ndescription: ${JSON.stringify(component.description || `${component.title} component reference.`)}\nid: ${JSON.stringify(component.id)}\n---\n\n# ${escape(component.title)}\n\n<div class="component-description"><p>${descriptions.renderInline(component.description).replaceAll('{', '\\{').replaceAll('\n', '&#10;')}</p></div>\n\n<link rel="component" href="${cardResource}">\n${exampleResources(examples, catalog)}\n<link rel="component" href="${cardResource.replace(/card\.html$/, 'reference.html')}">\n<link rel="component" href="@threadlabs/looma/components/ui-card/ui-card.html">\n<link rel="component" href="@threadlabs/looma/components/ui-tabs/ui-tabs.html">\n<link rel="component" href="@threadlabs/looma/components/ui-disclosure/ui-disclosure.html">\n<link rel="component" href="@threadlabs/looma/components/ui-stack/ui-stack.html">\n\n<looma-reference>\n\n<div class="looma-reference-tabs"><ui-tabs label="Component reference" style="--ui-tabs-panel-padding: 0px; --ui-tabs-tab-min-block-size: var(--ui-control-size-lg)"><section aria-label="Examples">${body}</section><section aria-label="API"><h2 id="api">API</h2>\n${apiBody(component)}\n${parts.map(part => `<h2 id="${part.tag}-api">${literal(part.title)} API</h2><p>${literal(part.description)}</p>${apiBody(part, part.tag + '-')}`).join('\n')}</section></ui-tabs></div>\n\n</looma-reference>\n`;
93
123
  }
package/docs/site.mjs CHANGED
@@ -1,14 +1,15 @@
1
1
  import { cp, mkdir, readFile, readdir, realpath, rename, rm, symlink, unlink, writeFile } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
- import { createHash, randomUUID } from 'node:crypto';
3
+ import { randomUUID } from 'node:crypto';
4
4
  import { createRequire } from 'node:module';
5
5
  import { fileURLToPath, pathToFileURL } from 'node:url';
6
6
  import { discoverComponents, escapeHtml, mergeCatalogs, readCatalog, readJson } from './catalog.mjs';
7
- import { cardMarkup, componentPath, exampleKey, previewPath, referencePage } from './render.mjs';
7
+ import { cardMarkup, componentPath, exampleKey, previewTag, scopedExampleMarkup, exampleResources, referencePage } from './render.mjs';
8
8
  import { defaultRecipe, themeCSS } from './theme.mjs';
9
9
  import { customizerResource } from './customizer-render.mjs';
10
10
  import { catalogResource } from './catalog-view.mjs';
11
11
  import { cacheDirectory, rejectSymlink, withBuildLock } from './workspace.mjs';
12
+ import { googleFontURL } from './fonts.mjs';
12
13
 
13
14
  const own = name => fileURLToPath(new URL(name, import.meta.url));
14
15
  /** Resolve import-only optional tooling peers in the consumer's ESM package scope. */
@@ -84,7 +85,6 @@ export async function prepareDocumentation({ root, config = {}, catalog }) {
84
85
  await cp(own('card.js'), path.join(generated, 'card.js'));
85
86
  await writeFile(path.join(generated, 'catalog-view.html'), catalogResource(combined.groups));
86
87
  await cp(own('catalog-view.js'), path.join(generated, 'catalog-view.js'));
87
- await cp(own('preview.js'), path.join(generated, 'preview.js'));
88
88
  for (const file of ['reference.html', 'reference.js']) await cp(own(file), path.join(generated, file));
89
89
  for (const file of ['customizer.js', 'theme.mjs', 'theme-session.mjs', 'value-editors.mjs', 'palette.mjs', 'fonts.mjs']) await cp(own(file), path.join(generated, file));
90
90
  const write = async (file, source) => { await mkdir(path.dirname(file), { recursive: true }); await writeFile(file, source); };
@@ -106,16 +106,10 @@ export async function prepareDocumentation({ root, config = {}, catalog }) {
106
106
  const file = path.join(previews, key + '.html');
107
107
  const tags = [...new Set([...example.markup.matchAll(/<([a-z][\w]*-[\w-]+)\b/g)].map(match => match[1]))];
108
108
  const links = tags.filter(tag => resourceByTag.has(tag)).map(tag => `<link rel="component" href="${escapeHtml(resourceByTag.get(tag).resource)}">`).join('\n');
109
- // Navigation specimens name destinations supplied by their host application. Give those
110
- // fragments local stand-ins inside the isolated stage; keep real documentation links checked.
111
- const declaredIds = new Set([...example.markup.matchAll(/\sid=["']([^"']+)["']/g)].map(match => match[1]));
112
- const destinations = [...new Set([...example.markup.matchAll(/\bhref=["']#([^"']+)["']/g)].map(match => match[1]))].filter(id => !declaredIds.has(id));
113
- const anchors = destinations.map(id => `<span id="${escapeHtml(id)}" hidden></span>`).join('');
114
109
  const setup = path.join(previews, key + '.js');
115
- const behavior = example.behavior;
116
- await write(setup, `import { connect as connectPreview } from '../preview.js';\n${behavior ? `import setupExample from ${JSON.stringify(behavior)};\n` : ''}export function connect(host) { const stopPreview = connectPreview(host); ${behavior ? 'const stopExample = setupExample(host.element);' : ''} return () => { ${behavior ? 'stopExample?.();' : ''} stopPreview(); }; }\n`);
117
- await write(file, ` ${links}\n<template component="looma-preview-${key}" module="./${key}.js"><defs><meta name="mk:navigation" content="hidden"><title>${escapeHtml(example.title)}</title></defs><div data-preview="${escapeHtml(example.id)}"${component.group === 'layout' ? ' data-preview-layout' : ''}>${example.markup}${anchors}</div></template>\n`);
118
- examples.push({ ...example, file, component: component.id, path: base + previewPath(example).slice(1) });
110
+ if (example.behavior) await write(setup, `import setupExample from ${JSON.stringify(example.behavior)};\nexport function connect(host) { return setupExample(host.element); }\n`);
111
+ await write(file, `${links}\n<template component="${previewTag(example)}"${example.behavior ? ` module="./${key}.js"` : ''}><defs><prop name="namespace" type="string" default="${key}">A unique namespace for this example's IDs and control relationships.</prop></defs><div><div data-preview="${escapeHtml(example.id)}"${component.group === 'layout' ? ' data-preview-layout' : ''}>${scopedExampleMarkup(example, base)}</div></div></template>\n`);
112
+ examples.push({ ...example, file, component: component.id, path: base + componentPath(component).slice(1) });
119
113
  }
120
114
  }
121
115
  const gallery = combined.groups.map(group => {
@@ -123,7 +117,7 @@ export async function prepareDocumentation({ root, config = {}, catalog }) {
123
117
  // A standalone opening tag makes this a Markdown HTML block, keeping native card wrappers inside Grid.
124
118
  return components.length ? `<section data-catalog-group="${escapeHtml(group.id)}">\n\n## ${escapeHtml(group.label)}\n\n<ui-grid columns="3" min="sm">\n${components.map(component => `<div data-category="${escapeHtml(component.group)}" data-catalog-search="${escapeHtml(`${component.tag} ${component.title} ${component.description}`)}">${cardMarkup(component.examples[0], base, component)}</div>`).join('\n')}\n</ui-grid>\n\n</section>` : '';
125
119
  }).join('\n\n');
126
- await write(path.join(content, 'components/index.md'), `---\ntitle: Components\n---\n\n# Components\n\nExplore the live examples that also power your theme customizer.\n\n<link rel="component" href="${relativeHref(path.join(content, 'components/index.md'), card)}">\n<link rel="component" href="@threadlabs/looma/components/ui-grid/ui-grid.html">\n<link rel="component" href="${relativeHref(path.join(content, 'components/index.md'), path.join(generated, 'catalog-view.html'))}">\n\n<looma-catalog>\n\n${gallery}\n\n</looma-catalog>\n`);
120
+ await write(path.join(content, 'components/index.md'), `---\ntitle: Components\n---\n\n# Components\n\nExplore the live examples that also power your theme customizer.\n\n<link rel="component" href="${relativeHref(path.join(content, 'components/index.md'), card)}">\n${exampleResources(combined.components.filter(component => !component.navigationParent).map(component => component.examples[0]), combined)}\n<link rel="component" href="@threadlabs/looma/components/ui-grid/ui-grid.html">\n<link rel="component" href="${relativeHref(path.join(content, 'components/index.md'), path.join(generated, 'catalog-view.html'))}">\n\n<looma-catalog>\n\n${gallery}\n\n</looma-catalog>\n`);
127
121
  await write(path.join(content, 'index.md'), `---\ntitle: ${JSON.stringify(config.title ?? 'Your design system')}\n---\n\n# ${config.title ?? 'Your design system'}\n\nWeave your design system from Looma and your own HTML Next components.\n\n[Explore components](/components/) · [Customize your theme](/customize/)\n`);
128
122
  if (combined.components.some(component => component.group === 'editor')) await write(path.join(content, 'editor.md'), `---\ntitle: Editor\nsidebar: false\n---\n\n# Editor\n\nWriting tools and editor components, separate from the general component reference.\n\n${combined.components.filter(component => component.group === 'editor' && !component.navigationParent).map(component => `- [${component.title}](${componentPath(component)})`).join('\n')}\n`);
129
123
  await write(path.join(content, 'design-system.md'), await readFile(own('README.md'), 'utf8'));
@@ -141,6 +135,9 @@ export async function prepareDocumentation({ root, config = {}, catalog }) {
141
135
  await mkdir(path.dirname(target), { recursive: true }); await cp(source, target);
142
136
  }
143
137
  }
138
+ await write(path.join(generated, 'example-behaviors.js'), examples.filter(example => example.behavior).map((example, index) => `import setup${index} from ${JSON.stringify(example.behavior)};`).join('\n') + `\nexport const exampleBehaviors = {${examples.filter(example => example.behavior).map((example, index) => `${JSON.stringify(example.id)}: setup${index}`).join(',')}};\n`);
139
+ const choice = exampleResources(examples, combined) + `\n<template component="looma-preview-choice"><defs><prop name="identity" type="string" default="">The authored example to render.</prop><prop name="namespace" type="string" default="selected">Unique ID namespace within this page.</prop></defs><div>${examples.map(example => `<div $if="${escapeHtml(`$identity = ${JSON.stringify(example.id)}`)}" data-preview="${escapeHtml(example.id)}"${example.stretch || combined.components.find(component => component.id === example.component)?.group === 'layout' ? ' data-preview-layout' : ''}>${scopedExampleMarkup(example, base)}</div>`).join('')}</div></template>`;
140
+ await write(path.join(generated, 'preview-choice.html'), choice);
144
141
  const customizer = path.join(generated, 'customizer.html');
145
142
  await write(customizer, customizerResource({ catalog: combined, config, base }, config.recipe));
146
143
  const customizerPage = path.join(content, 'customize.md');
@@ -169,9 +166,8 @@ async function themeBootstrap(site) {
169
166
  export function documentationPlugin(site) {
170
167
  return {
171
168
  name: 'looma-design-system',
172
- buildEnd: context => isolatePreviewScripts(site, context),
173
- generate: async () => ({ '/_looma/theme-system.css': await readFile(fileURLToPath(import.meta.resolve('@threadlabs/looma/theme-system.css')), 'utf8') }),
174
- config: () => ({ pages: [{ dir: path.relative(site.root, site.previews), prefix: '/_looma/preview/', layout: false }], css: [own('documentation.css')] }),
169
+ generate: async () => ({ '/_looma/pastoral.svg': await readFile(own('pastoral.svg'), 'utf8'), '/_looma/portrait.svg': await readFile(own('portrait.svg'), 'utf8'), '/_looma/theme-system.css': await readFile(fileURLToPath(import.meta.resolve('@threadlabs/looma/theme-system.css')), 'utf8') }),
170
+ config: () => ({ css: [own('documentation.css')] }),
175
171
  };
176
172
  }
177
173
 
@@ -180,15 +176,21 @@ export async function documentationOptions(site) {
180
176
  const styles = ['tokens.css', 'theme-light.css', 'theme-dark.css', 'theme-system.css'].map(file => fileURLToPath(import.meta.resolve(`@threadlabs/looma/${file}`)));
181
177
  const options = siteOptions({ root: site.root, contentDir: path.relative(site.root, site.content), title: site.config.title ?? 'Your design system', headerNotice: 'Custom theme', base: site.base, outDir: site.config.outDir ?? 'site', ...(site.config.origin ? { origin: site.config.origin } : {}), ...(site.config.logo ? { logo: site.config.logo } : {}), ...(site.config.nav ? { nav: site.config.nav } : {}) }, { plugins: [documentationPlugin(site)], css: styles, redirects: site.redirects });
182
178
  const savedTheme = path.join(site.generated, 'saved-theme.css');
183
- await writeFile(savedTheme, site.config.themeCSSContents ?? themeCSS(site.config.recipe ?? defaultRecipe()));
179
+ const recipe = site.config.recipe ?? defaultRecipe();
180
+ const overrides = await Promise.all((site.config.overrides ?? []).map(file => readFile(path.resolve(site.root, file), 'utf8')));
181
+ const localFonts = new Set(overrides.flatMap(css => [...css.matchAll(/@font-face\s*\{[^}]*font-family:\s*['"]([^'"]+)['"]/g)].map(match => match[1])));
182
+ const remoteFonts = Object.fromEntries(Object.entries(recipe.fonts ?? {}).filter(([, family]) => !localFonts.has(family)));
183
+ const imported = googleFontURL(recipe.fonts), remaining = googleFontURL(remoteFonts);
184
+ // A supplied face already serves the same family; avoid another render-blocking stylesheet.
185
+ const savedCSS = (site.config.themeCSSContents ?? themeCSS(recipe)).replace(`@import url("${imported}");`, remaining ? `@import url("${remaining}");` : '');
186
+ await writeFile(savedTheme, savedCSS);
184
187
  const themeStyles = [savedTheme, ...await portableThemeStyles(site)];
185
188
  return { ...options, plugins: [...options.plugins, { name: 'looma-saved-theme', config: () => ({ css: themeStyles }) },
186
189
  // Markupress supplies its head script in its own config hook; compose after it.
187
190
  { name: 'looma-browser-theme', config: async current => ({ headScript: [current.headScript, await themeBootstrap(site)].filter(Boolean).join('\n;\n') }) }] };
188
191
  }
189
192
 
190
- /** Opaque example frames cannot fetch local fonts without host-specific CORS headers.
191
- * Bundle those font files into theme CSS for both the local server and static output. */
193
+ /** Bundle project theme styles once, shared by the page and every inline example. */
192
194
  async function portableThemeStyles(site) {
193
195
  const overrides = site.config.overrides ?? [];
194
196
  if (!overrides.length) return [];
@@ -197,7 +199,6 @@ async function portableThemeStyles(site) {
197
199
  await writeFile(entry, overrides.map(file => `@import ${JSON.stringify(path.resolve(site.root, file))};`).join('\n'));
198
200
  const bundled = await build({ root: site.root, base: './', configFile: false, logLevel: 'silent',
199
201
  build: { write: false, minify: false, cssMinify: false,
200
- assetsInlineLimit: file => /\.(woff2?|ttf|otf)$/i.test(file),
201
202
  rollupOptions: { input: entry, output: { assetFileNames: 'theme-assets/[name]-[hash][extname]' } } } });
202
203
  const styles = [];
203
204
  for (const output of (Array.isArray(bundled) ? bundled[0] : bundled).output) {
@@ -210,7 +211,7 @@ async function portableThemeStyles(site) {
210
211
  return styles;
211
212
  }
212
213
 
213
- /** Build through MarkupKit, then make opaque preview scripts portable to static hosts without CORS. */
214
+ /** Build references and examples together through MarkupKit. */
214
215
  export async function buildDocumentation({ root = process.cwd(), config = {}, catalog } = {}) {
215
216
  return withBuildLock(root, async () => {
216
217
  const site = await prepareDocumentation({ root, config, catalog });
@@ -219,36 +220,3 @@ export async function buildDocumentation({ root = process.cwd(), config = {}, ca
219
220
  return { ...built, site };
220
221
  });
221
222
  }
222
-
223
- async function isolatePreviewScripts(site, { outDir }) {
224
- const { build } = await tool('vite', site.root);
225
- // Preview entries and outputs are independent. Keep compiler memory bounded
226
- // and retain the build lock until every in-flight bundle has settled.
227
- const remaining = [...site.examples];
228
- const results = await Promise.allSettled(Array.from({ length: Math.min(2, remaining.length) }, async () => {
229
- try {
230
- for (let example; (example = remaining.pop());) {
231
- const htmlFile = path.join(outDir, '_looma/preview', exampleKey(example.id), 'index.html');
232
- let html = await readFile(htmlFile, 'utf8');
233
- const scripts = [...html.matchAll(/<script\b[^>]*type="module"[^>]*src="([^"]+)"[^>]*><\/script>/g)];
234
- if (!scripts.length) throw new Error(`No browser module found for isolated preview ${example.id}.`);
235
- for (const [tag, url] of scripts) {
236
- const input = path.join(outDir, url.slice(site.base.length));
237
- const bundle = await build({ configFile: false, logLevel: 'silent', build: { write: false, minify: true, lib: { entry: input, name: 'LoomaPreview', formats: ['iife'] }, rollupOptions: { output: { codeSplitting: false } } } });
238
- const code = (Array.isArray(bundle) ? bundle[0] : bundle).output.find(output => output.type === 'chunk').code;
239
- // A sandbox has an opaque origin: Safari cannot authorize this runtime via 'self'.
240
- // Hash the exact inline bytes and run after the preview DOM, preserving isolation.
241
- const script = code.replace(/<\/script/gi, '<\\/script');
242
- const hash = createHash('sha256').update(script).digest('base64');
243
- if (!/<meta\b[^>]*http-equiv="Content-Security-Policy"[^>]*content="[^"]*\bscript-src\b/.test(html)) throw new Error(`Missing script policy for isolated preview ${example.id}.`);
244
- html = html.replace(/(<meta\b[^>]*http-equiv="Content-Security-Policy"[^>]*content="[^"]*\bscript-src)\b/, `$1 'sha256-${hash}'`);
245
- html = html.replace(tag, '').replace('</body>', () => `<script>${script}</script></body>`);
246
- }
247
- html = html.replace(/<link\b[^>]*rel="modulepreload"[^>]*>/g, '');
248
- await writeFile(htmlFile, html);
249
- }
250
- } catch (error) { remaining.length = 0; throw error; }
251
- }));
252
- const failed = results.find(result => result.status === 'rejected');
253
- if (failed) throw failed.reason;
254
- }
package/docs/theme.mjs CHANGED
@@ -5,12 +5,32 @@ const bounds = {
5
5
  'text-size': [14, 24], 'control-roominess': [2, 4], 'corner-roundness': [0, 32],
6
6
  'line-weight': [.5, 3], rhythm: [.75, 1.5], spacing: [.75, 1.5], 'scale-contrast': [1, 1.5],
7
7
  'space-curve': [.5, 2], 'text-weight': [400, 700], 'outer-depth': [0, 2], 'inner-depth': [0, 2],
8
- 'response-time': [0, 600],
8
+ 'response-time': [0, 600], 'neutral-border-contrast': [1, 4.5],
9
9
  };
10
10
 
11
+ const brandChoices = { primary: 'Primary accent', secondary: 'Secondary accent', tertiary: 'Tertiary accent' };
12
+ const statusChoices = { derived: 'Semantic hue', related: 'Harmonize with primary', ...brandChoices };
13
+ const neutralChoices = { text: 'Derive from text', ...brandChoices, gray: 'Untinted gray' };
14
+ const relationshipChoices = { preserve: 'Preserve seed hues', neighboring: 'Neighboring hues', complementary: 'Complementary hues' };
15
+ const choicesFor = id => id === 'neutral-source' ? neutralChoices : id.endsWith('-source') ? statusChoices : id.endsWith('-accent') ? brandChoices : relationshipChoices;
16
+ const statusSeeds = { danger: '#c92d1e', success: '#007a33', warning: '#ba5b0b', info: '#0066cc' };
17
+
11
18
  /** The shared authoring schema; ids remain stable in saved recipes. */
12
19
  export const themeFields = [
13
20
  ['Colour', 'action', 'Action', '--ui-accent', 'colour', '#5b55d6', 'Primary fill; readable labels and contextual action text are derived separately.'],
21
+ ['Colour', 'secondary-action', 'Secondary accent', null, 'optional-colour', 'none', 'An optional supporting brand color for selected components. Primary actions keep the primary accent.'],
22
+ ['Colour', 'tertiary-action', 'Tertiary accent', null, 'optional-colour', 'none', 'An optional third accent for categories, highlights and supporting content.'],
23
+ ['Colour', 'neutral-source', 'Neutral relationship', null, 'choice', 'text', 'Derive restrained neutrals from text, an accent family or an untinted gray. Shared border contrast and readable labels stay governed.'],
24
+ ['Colour', 'neutral-strength', 'Neutral fill strength', null, 'fraction', '0.25', 'How much neutral pigment appears in quiet filled controls. Borders remain shared with fields.'],
25
+ ['Colour', 'neutral-border-contrast', 'Neutral border contrast', null, 'ratio', '2', 'Minimum border-to-surface contrast for neutral buttons and form fields. 2:1 is the balanced default; raise it for stronger boundaries.'],
26
+ ['Colour', 'status-chroma', 'Derived status saturation', null, 'fraction', '0.5', 'Perceptual saturation of derived status colors, coordinated with the primary accent. Brand mappings keep the chosen family intact.'],
27
+ ['Colour', 'success-source', 'Success relationship', null, 'choice', 'derived', 'Choose a semantic hue, harmonize it with primary, or use a governed brand-accent family.'],
28
+ ['Colour', 'danger-source', 'Error relationship', null, 'choice', 'derived', 'Choose a semantic hue, harmonize it with primary, or use a governed brand-accent family.'],
29
+ ['Colour', 'warning-source', 'Warning relationship', null, 'choice', 'derived', 'Choose a semantic hue, harmonize it with primary, or use a governed brand-accent family.'],
30
+ ['Colour', 'info-source', 'Info relationship', null, 'choice', 'derived', 'Choose a semantic hue, harmonize it with primary, or use a governed brand-accent family.'],
31
+ ['Colour', 'selection-accent', 'Selection accent', null, 'choice', 'primary', 'Choose the accent for selected rows and choices.'],
32
+ ['Colour', 'focus-accent', 'Focus accent', null, 'choice', 'primary', 'Choose the accent for keyboard focus rings.'],
33
+ ['Colour', 'link-accent', 'Link accent', null, 'choice', 'primary', 'Choose the accent for inline Text links and editor links.'],
14
34
  ['Colour', 'canvas', 'Canvas', '--ui-surface', 'colour', '#f6f6f8', 'The ground behind surfaces.'],
15
35
  ['Colour', 'surface', 'Surface', '--ui-surface-raised', 'colour', '#ffffff', 'Fields, cards and floating surfaces.'],
16
36
  ['Colour', 'text', 'Text', '--ui-text', 'colour', '#1a1a1a', 'Readable content; supporting text follows this and Surface.'],
@@ -20,10 +40,11 @@ export const themeFields = [
20
40
  ['Type', 'body-font', 'Font', '--ui-font-sans', 'font', 'system-ui, sans-serif', 'The shared interface typeface.'],
21
41
  ['Type', 'display-font', 'Heading font', '--ui-font-display', 'font', 'system-ui, sans-serif', 'The heading typeface.'],
22
42
  ['Type', 'text-size', 'Base text size', '--ui-font-size', 'positive-length', '16px', 'Sets the document root in px. Type, spacing and layout use rem relationships and scale from this base once.'],
43
+ ['Type', 'label-size', 'Field label size', '--ui-field-label-font-size', 'inherited-length', 'inherit', 'Follows body text unless you choose a separate size for field labels. Help text keeps its supporting size.'],
23
44
  ['Type', 'text-weight', 'Emphasis weight', '--ui-font-medium', 'weight', '500', 'Control-label emphasis; body and headings keep their roles.'],
24
45
  ['Size & spacing', 'control-roominess', 'Control roominess', '--ui-control-roominess', 'positive', '2.5', 'Shared control height as a multiple of base text size; buttons, fields and swatches stay aligned.'],
25
- ['Size & spacing', 'rhythm', 'Rhythm', '--ui-rhythm', 'positive', '1', 'More or less breathing room between lines and groups. Spacing fine-tunes gaps independently.'],
26
- ['Size & spacing', 'spacing', 'Spacing', '--ui-spacing', 'positive', '1', 'More or less breathing room throughout the interface.'],
46
+ ['Size & spacing', 'rhythm', 'Rhythm', '--ui-rhythm', 'positive', '1', 'Vertical breathing room: opens text lines and the gaps between stacked groups without spreading navigation or button rows.'],
47
+ ['Size & spacing', 'spacing', 'Spacing', '--ui-spacing', 'positive', '1', 'Space between controls and around content. Changes gaps and padding independently of vertical rhythm.'],
27
48
  ['Size & spacing', 'scale-contrast', 'Size ratio', '--ui-scale-ratio', 'ratio', '1.2', 'The multiplier between small, medium and large controls. At 1 the sizes are equal; higher values separate them.'],
28
49
  ['Size & spacing', 'space-curve', 'Spacing curve', '--ui-space-curve', 'nonnegative', '1', 'Spacing growth: 1 is linear, 2 is quadratic. Independent of control sizes.'],
29
50
  ['Size & spacing', 'corner-roundness', 'Corner roundness', '--ui-radius-md', 'length', '8px', 'One corner family across controls and surfaces.'],
@@ -43,12 +64,12 @@ export const themeFields = [
43
64
  ['Material', 'light-strength', 'Light strength', '--ui-light-strength', 'fraction', '0.65', 'Shared illumination; each material and component role determines its response.'],
44
65
  ['Motion', 'response-time', 'Response time', '--ui-motion-fast', 'time', '120ms', 'Shared feedback pace; floating transitions take proportionally longer.'],
45
66
  ['Motion', 'response-curve', 'Response curve', '--ui-motion-ease', 'easing', 'cubic-bezier(0.2,0,0.2,1)', 'How movement accelerates and settles.'],
46
- ].map(([family, id, label, property, type, defaultValue, description]) => Object.freeze({ family, id, label, property, type, defaultValue, description, ...(type === 'choice' ? { choices: { preserve: 'Preserve seed hues', neighboring: 'Neighboring hues', complementary: 'Complementary hues' } } : {}), ...(bounds[id] ? { min: bounds[id][0], max: bounds[id][1] } : type === 'fraction' ? { min: 0, max: 1 } : {}) }));
67
+ ].map(([family, id, label, property, type, defaultValue, description]) => Object.freeze({ family, id, label, property, type, defaultValue, description, ...(type === 'choice' ? { choices: choicesFor(id) } : {}), ...(bounds[id] ? { min: bounds[id][0], max: bounds[id][1] } : type === 'fraction' ? { min: 0, max: 1 } : {}) }));
47
68
 
48
69
  const baseRecipe = () => ({ schemaVersion: 1, values: Object.fromEntries(themeFields.map(field => [field.id, field.defaultValue])) });
49
70
  const starting = values => ({ schemaVersion: 1, values: { ...baseRecipe().values, ...values } });
50
71
  /** The documentation starts with Looma's coordinated identity; Clear keeps the neutral baseline. */
51
- export const defaultRecipe = () => ({ ...starting({ action: '#7658d6', canvas: '#fbf9f4', surface: '#fffdf8', text: '#2b2538', 'body-font': googleFontStack('Manrope'), 'display-font': googleFontStack('Manrope'), 'text-size': '17px' }), fonts: { 'body-font': 'Manrope', 'display-font': 'Manrope' } });
72
+ export const defaultRecipe = () => ({ ...starting({ action: '#7658d6', canvas: '#fbf9f4', surface: '#ffffff', text: '#2b2538', 'body-font': googleFontStack('Manrope'), 'display-font': googleFontStack('Manrope'), 'text-size': '17px' }), fonts: { 'body-font': 'Manrope', 'display-font': 'Manrope' } });
52
73
  export const startingPoints = {
53
74
  looma: defaultRecipe(),
54
75
  clear: baseRecipe(),
@@ -136,9 +157,11 @@ export function validateRecipe(input) {
136
157
  let valid = typeof value === 'string' && value.length > 0;
137
158
  if (valid) switch (field.type) {
138
159
  case 'choice': valid = Object.hasOwn(field.choices, value); break;
160
+ case 'optional-colour': valid = value === field.defaultValue || /^#[\da-f]{6}$/i.test(value); break;
139
161
  case 'colour': valid = /^#[\da-f]{6}$/i.test(value); break;
140
162
  case 'font': valid = font.test(value); break;
141
163
  case 'length': valid = length.test(value) && Number.isFinite(parseFloat(value)); break;
164
+ case 'inherited-length': valid = value === 'inherit' || (length.test(value) && Number.isFinite(parseFloat(value)) && parseFloat(value) > 0); break;
142
165
  case 'positive-length': valid = length.test(value) && Number.isFinite(parseFloat(value)) && parseFloat(value) > 0; break;
143
166
  case 'time': valid = time.test(value) && Number.isFinite(parseFloat(value)); break;
144
167
  case 'easing': valid = easing(value); break;
@@ -271,13 +294,34 @@ export function deriveTheme(input, { mode } = {}) {
271
294
  const surface = seed => readableColour(nativeInk === ink ? seed : companionSurface(seed, mode ?? (ink === '#000000' ? 'light' : 'dark')), [ink], 7, paper);
272
295
  tokens['--ui-surface'] = surface(seeds.canvas);
273
296
  tokens['--ui-surface-raised'] = surface(seeds.surface);
274
- tokens['--ui-surface-sunken'] = surface(mix(tokens['--ui-surface-raised'], tokens['--ui-surface'], .92));
297
+ const dark = ink === '#ffffff';
298
+ if (dark) {
299
+ // Dark plates need a positive elevation step; independently flipping near-white
300
+ // seeds otherwise collapses both canvas and content to almost the same black.
301
+ const [canvasL, canvasC, canvasH] = toLch(tokens['--ui-surface']);
302
+ tokens['--ui-surface'] = fromLch([Math.min(canvasL, .38), canvasC, canvasH]);
303
+ const [raisedL, raisedC, raisedH] = toLch(tokens['--ui-surface-raised']);
304
+ tokens['--ui-surface-raised'] = readableColour(fromLch([Math.max(raisedL, Math.min(canvasL, .38) + .08), raisedC, raisedH]), [ink], 7, paper);
305
+ tokens['--ui-surface-sunken'] = fromLch([Math.max(0, Math.min(canvasL, .38) - .035), canvasC, canvasH]);
306
+ } else tokens['--ui-surface-sunken'] = surface(mix(tokens['--ui-surface-raised'], tokens['--ui-surface'], .92));
275
307
  const surfaces = ['--ui-surface', '--ui-surface-raised', '--ui-surface-sunken'].map(name => tokens[name]);
276
- const tones = { accent: seeds.action, danger: '#c92d1e', success: '#007a33', warning: '#ba5b0b', info: '#0066cc' };
308
+ const accents = { primary: seeds.action, secondary: seeds['secondary-action'], tertiary: seeds['tertiary-action'] };
309
+ const tones = { accent: accents.primary, 'accent-secondary': accents.secondary, 'accent-tertiary': accents.tertiary };
310
+ const brandChroma = Math.min(.20, Math.max(.08, toLch(accents.primary)[1]));
311
+ for (const role of ['danger','success','warning','info']) {
312
+ const source = values[role + '-source'];
313
+ if (source === 'derived' || source === 'related') {
314
+ let [l, , h] = toLch(statusSeeds[role]);
315
+ if (source === 'related') {
316
+ const brandHue = toLch(accents.primary)[2];
317
+ const delta = ((brandHue - h + 540) % 360) - 180;
318
+ h += Math.max(-15, Math.min(15, delta));
319
+ }
320
+ tones[role] = fromLch([l, brandChroma * (.5 + Number(values['status-chroma'])) * (.6 + Number(values['color-intensity']) * .8), h]);
321
+ } else tones[role] = accents[source];
322
+ }
277
323
  for (const [tone, original] of Object.entries(tones)) {
278
- const [l, c, h] = toLch(original);
279
- const seed = tone === 'accent' ? original : fromLch([l, c * (.6 + Number(values['color-intensity']) * .8), h]);
280
- const fill = seed;
324
+ const fill = original;
281
325
  const onFill = foreground(fill, '#ffffff', '#000000');
282
326
  tokens[`--ui-${tone}`] = fill;
283
327
  tokens[`--ui-on-${tone}`] = onFill;
@@ -286,20 +330,29 @@ export function deriveTheme(input, { mode } = {}) {
286
330
  const stateTarget = onFill === '#000000' ? '#ffffff' : '#000000';
287
331
  tokens[`--ui-${tone}-hover`] = mix(fill, stateTarget, .86);
288
332
  tokens[`--ui-${tone}-active`] = mix(fill, stateTarget, .74);
289
- tokens[`--ui-${tone}-soft`] = mix(fill, tokens['--ui-surface-raised'], .08);
333
+ const contextual = readableColour(fill, surfaces, 4.5, ink);
334
+ const quiet = mix(contextual, tokens['--ui-surface-raised'], .20);
335
+ const [quietL] = toLch(quiet);
336
+ const [, pigmentC, pigmentH] = toLch(fill);
337
+ const plateL = toLch(tokens['--ui-surface-raised'])[0];
338
+ const quietC = dark ? Math.min(pigmentC, .035) : Math.min(pigmentC, .02 + .03 * Math.max(0, Math.cos((pigmentH - 140) * Math.PI / 180)));
339
+ tokens[`--ui-${tone}-soft`] = readableColour(fromLch([dark ? Math.max(quietL, plateL + .07) : Math.max(.92, plateL - .04), quietC, pigmentH]), [ink], 4.5, paper);
290
340
  }
291
341
  // Quiet fills are actual alpha composites. At an extreme light/dark flip,
292
342
  // reduce their shared tint before it would leave no readable contextual ink.
293
- const quietSurfaces = strength => [...surfaces, ...Object.keys(tones).flatMap(tone => surfaces.flatMap(background => [
343
+ const quietSurfaces = strength => [...surfaces, ...(dark ? [readableColour(mix(ink, tokens['--ui-surface-raised'], .22), [ink], 4.5, paper)] : []), ...Object.keys(tones).map(tone => tokens[`--ui-${tone}-soft`]), ...Object.keys(tones).flatMap(tone => surfaces.flatMap(background => [
294
344
  mix(tokens[`--ui-${tone}`], background, .12 * strength),
295
- ...[.05, .12, .18].map(alpha => alphaSurface(tokens[`--ui-${tone}`], background, alpha * strength)),
345
+ ...[.05, .12, .18, .19].map(alpha => alphaSurface(tokens[`--ui-${tone}`], background, alpha * strength)),
296
346
  ]))];
297
347
  let tonalOpacity = 1;
298
348
  while (tonalOpacity > 0 && quietSurfaces(tonalOpacity).some(background => contrast(ink, background) < 4.5)) tonalOpacity = Math.max(0, tonalOpacity - .01);
299
349
  tokens['--ui-tonal-opacity'] = String(Number(tonalOpacity.toFixed(2)));
300
350
  const readingSurfaces = quietSurfaces(tonalOpacity);
301
351
  for (const tone of Object.keys(tones)) {
302
- tokens[`--ui-${tone}-subtle-text`] = readableColour(tokens[`--ui-${tone}`], readingSurfaces, 4.5, ink);
352
+ const [l, c, h] = toLch(tokens[`--ui-${tone}`]);
353
+ const foregroundSeed = fromLch([dark ? Math.max(l, .80) : Math.min(l, .50), Math.min(c, dark ? .16 : .18), h]);
354
+ tokens[`--ui-${tone}-subtle-text`] = readableColour(foregroundSeed, readingSurfaces, 4.5, ink);
355
+ tokens[`--ui-${tone}-soft-border`] = alphaSurface(tokens[`--ui-${tone}-subtle-text`], tokens[`--ui-${tone}-soft`], .25);
303
356
  }
304
357
  // Existing validation/editor hooks must receive a contextual text role, never
305
358
  // a pressed fill. Preserve consumer overrides at their established boundaries.
@@ -309,27 +362,32 @@ export function deriveTheme(input, { mode } = {}) {
309
362
  tokens['--ui-text'] = readableColour(textSeed, readingSurfaces, 4.5, ink);
310
363
  tokens['--ui-text-secondary'] = readableColour(mix(tokens['--ui-text'], tokens['--ui-surface-raised'], .72), readingSurfaces, 4.5, ink);
311
364
  tokens['--ui-text-muted'] = tokens['--ui-text-secondary'];
312
- // One continuous action-family range: primary pigment determines the neutral
313
- // companion and their boundaries. These are design calibration values, not an
314
- // empirical attention score. A floor preserves near-surface action boundaries.
365
+ // Colored action edges keep a boundary when their pigment approaches a surface.
366
+ // Neutral controls use their own shared contrast decision below.
315
367
  const separation = Math.min(...surfaces.map(surface => colourDistance(tokens['--ui-accent'], surface)));
316
368
  const amplitude = .10 + .16 * separation / (separation + .20);
317
369
  for (const tone of Object.keys(tones)) for (const state of ['', '-hover', '-active']) {
318
370
  tokens[`--ui-${tone}${state}-border`] = actionBoundary(tokens[`--ui-${tone}${state}`], surfaces, ink, amplitude);
319
371
  }
320
- // Keep secondary contours quieter than the weakest resolved primary edge,
321
- // including warm surfaces where an assisted edge can approach its backdrop.
322
- const familyRange = Math.min(amplitude, ...['', '-hover', '-active'].flatMap(state => surfaces.map(surface =>
323
- colourDistance(tokens[`--ui-accent${state}-border`], surface),
324
- )));
325
- for (const [state, fillScale, edgeScale] of [['surface', .25, .45], ['hover', .35, .55], ['active', .45, .65]]) {
326
- tokens[`--ui-neutral-${state}`] = readableColour(surfaceOffset(tokens['--ui-surface-raised'], tokens['--ui-text'], familyRange * fillScale), [tokens['--ui-text']], 4.5, paper);
327
- tokens[`--ui-neutral-${state === 'surface' ? '' : state + '-'}border`] = surfaceOffset(tokens['--ui-surface-raised'], tokens['--ui-text'], familyRange * edgeScale);
372
+ // Neutral pigment governs fills; a shared contrast floor governs every neutral
373
+ // control boundary independently of how close the brand pigment is to its canvas.
374
+ const neutralSource = values['neutral-source'];
375
+ const [, neutralC, neutralH] = toLch(neutralSource === 'text' || neutralSource === 'gray' ? tokens['--ui-text'] : accents[neutralSource]);
376
+ const neutral = fromLch([toLch(tokens['--ui-text'])[0], neutralSource === 'gray' ? 0 : Math.min(.04, neutralC), neutralH]);
377
+ const fillAmount = .02 + Number(values['neutral-strength']) * .16;
378
+ for (const [state, amount] of [['surface', fillAmount], ['hover', fillAmount + .04], ['active', fillAmount + .08]]) {
379
+ const tinted = mix(neutral, tokens['--ui-surface-raised'], amount * (dark ? 2.25 : 1));
380
+ const [l, c, h] = toLch(tinted);
381
+ const fill = dark ? fromLch([Math.max(l, toLch(tokens['--ui-surface-raised'])[0] + amount * 1.5), c, h]) : tinted;
382
+ tokens[`--ui-neutral-${state}`] = readableColour(fill, [tokens['--ui-text']], 4.5, paper);
328
383
  }
329
- // Enclosure lines describe regions; native field affordances retain their
330
- // independently resolved control border below.
331
- tokens['--ui-border'] = surfaceOffset(tokens['--ui-surface-raised'], tokens['--ui-text'], familyRange * .20);
332
- tokens['--ui-border-strong'] = surfaceOffset(tokens['--ui-surface-raised'], tokens['--ui-text'], familyRange * .35);
384
+ const borderSurfaces = [...surfaces, tokens['--ui-neutral-surface']];
385
+ const engagedSurfaces = [...surfaces, tokens['--ui-neutral-hover'], tokens['--ui-neutral-active']];
386
+ const borderMinimum = Math.min(4.5, Number(values['neutral-border-contrast']) * (dark ? 1.15 : 1));
387
+ tokens['--ui-control-border'] = readableColour(mix(neutral, tokens['--ui-surface-raised'], .14), borderSurfaces, borderMinimum, ink);
388
+ tokens['--ui-control-border-hover'] = readableColour(tokens['--ui-control-border'], engagedSurfaces, Math.min(4.5, borderMinimum + .3), ink);
389
+ tokens['--ui-border'] = mix(neutral, tokens['--ui-surface-raised'], .10);
390
+ tokens['--ui-border-strong'] = mix(neutral, tokens['--ui-surface-raised'], .18);
333
391
  for (const [role, fill, labels] of [
334
392
  ['surface', tokens['--ui-surface-raised'], [tokens['--ui-text'], tokens['--ui-text-secondary'], ...Object.keys(tones).map(tone => tokens[`--ui-${tone}-subtle-text`])]],
335
393
  ['neutral', tokens['--ui-neutral-surface'], tokens['--ui-text']],
@@ -344,18 +402,22 @@ export function deriveTheme(input, { mode } = {}) {
344
402
  const range = [Math.min(low, luminance(trackFill)), Math.max(high, luminance(trackFill), luminance(tokens[`--ui-${track}-specular`]))];
345
403
  for (const [part, colour] of Object.entries(materialColours(fill, range, values['light-color'], 3.05))) tokens[`--ui-${role}-${part}`] = colour;
346
404
  }
347
- tokens['--ui-selection-surface'] = mix(tokens['--ui-accent'], tokens['--ui-surface-raised'], .1);
348
- tokens['--ui-selection-text'] = tokens['--ui-accent-subtle-text'];
349
- tokens['--ui-selection-border'] = mix(tokens['--ui-accent'], tokens['--ui-surface-raised'], .2);
405
+ const selection = values['selection-accent'] === 'primary' ? 'accent' : 'accent-' + values['selection-accent'];
406
+ const link = values['link-accent'] === 'primary' ? 'accent' : 'accent-' + values['link-accent'];
407
+ tokens['--ui-link-color'] = tokens[`--ui-${link}-subtle-text`];
408
+ tokens['--ui-editor-link-color'] = tokens['--ui-link-color'];
409
+ // Contextual pigment keeps even deep brand colors visible over a dark plate.
410
+ const selectionPigment = tokens[`--ui-${selection}${dark ? '-subtle-text' : ''}`];
411
+ tokens['--ui-selection-surface'] = readableColour(mix(selectionPigment, tokens['--ui-surface-raised'], dark ? .22 : .1), [ink], dark ? 7 : 4.5, paper);
412
+ tokens['--ui-selection-text'] = readableColour(tokens[`--ui-${selection}-subtle-text`], [...surfaces, tokens['--ui-selection-surface']], dark ? 7 : 4.5, ink);
413
+ tokens['--ui-selection-border'] = mix(selectionPigment, tokens['--ui-surface-raised'], dark ? .44 : .2);
350
414
  tokens['--ui-control-surface'] = tokens['--ui-surface-raised'];
351
415
  // A hint is quieter than body copy; resolve it against its field, not every tinted content surface.
352
416
  tokens['--ui-control-placeholder'] = readableColour(mix(tokens['--ui-text'], tokens['--ui-control-surface'], .5), [tokens['--ui-control-surface']], 4.5, ink);
353
- tokens['--ui-control-border'] = readableColour(mix(tokens['--ui-text'], tokens['--ui-surface-raised'], .43), readingSurfaces, 3, ink);
354
- tokens['--ui-control-border-hover'] = tokens['--ui-control-border'];
355
417
  tokens['--ui-disabled-text'] = mix(tokens['--ui-text'], tokens['--ui-surface-raised'], .45);
356
418
  tokens['--ui-disabled-surface'] = tokens['--ui-surface-sunken'];
357
419
  tokens['--ui-disabled-border'] = mix(tokens['--ui-text'], tokens['--ui-surface-raised'], .2);
358
- tokens['--ui-focus-ring'] = readableColour(tokens['--ui-accent'], readingSurfaces, 3, ink);
420
+ tokens['--ui-focus-ring'] = readableColour(accents[values['focus-accent']], readingSurfaces, 3, ink);
359
421
  tokens['--ui-focus-width'] = 'max(2px, calc(var(--ui-border-width) * 2))';
360
422
  tokens['color-scheme'] = ink === '#000000' ? 'light' : 'dark';
361
423
  for (const [id, property] of [['canvas', '--ui-surface'], ['surface', '--ui-surface-raised'], ['text', '--ui-text']]) {
@@ -4,10 +4,11 @@ const timeUnits = { ms: 1, s: 1000 };
4
4
  const rounded = value => String(Number(Number(value).toFixed(6)));
5
5
 
6
6
  export function valueEditor(field, value, { remPixels = 16 } = {}) {
7
+ if (field.type === 'inherited-length') return { kind: 'inherited-size', value };
7
8
  if (field.id === 'text-size') return { kind: 'number', value, unit: 'px', min: field.min, max: field.max, step: 1 };
8
9
  if (field.type === 'choice') return { kind: 'choice', value };
9
10
  if (field.type === 'easing') return { kind: /^step-/.test(value) ? 'text' : 'curve', value };
10
- if (['colour', 'font'].includes(field.type)) return { kind: 'text', value };
11
+ if (['colour', 'optional-colour', 'font'].includes(field.type)) return { kind: 'text', value };
11
12
  if (field.type.includes('length') || field.type === 'time') {
12
13
  const unit = value.match(/[a-z]+$/i)?.[0] ?? 'px';
13
14
  // Convert authoring limits against the same root as the displayed quantity.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threadlabs/looma",
3
- "version": "0.42.0",
3
+ "version": "0.43.1",
4
4
  "type": "module",
5
5
  "description": "Looma components as HTML, Vue, and plain DOM, with design tokens.",
6
6
  "license": "MIT",
@@ -127,7 +127,7 @@
127
127
  "@tiptap/pm": ">=2 <3",
128
128
  "@tiptap/vue-3": ">=2 <3",
129
129
  "vue": "^3.5.43",
130
- "markupress": ">=0.10.0 <1",
130
+ "markupress": ">=0.10.2 <1",
131
131
  "@threadlabs/markupkit": ">=0.2.0 <1",
132
132
  "vite": ">=7.2.7 <9"
133
133
  },