@zazz-ui/core 0.4.0 → 0.5.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 (331) hide show
  1. package/AUTHORING.md +158 -0
  2. package/CHANGELOG.md +341 -0
  3. package/README.md +55 -23
  4. package/dist/scroll-state-C8mA5gq6.js +1 -0
  5. package/dist/sri.json +124 -72
  6. package/dist/zazz.css +1 -1
  7. package/dist/zazz.js +1 -1
  8. package/editor/zazz.css-data.json +116794 -0
  9. package/editor/zazz.html-data.json +1683 -0
  10. package/editor/zazz.language-data.json +5001 -0
  11. package/editor/zazz.lint-data.json +152 -0
  12. package/package.json +12 -5
  13. package/src/base/_breakpoints.css +12 -0
  14. package/src/base/_layers.css +8 -9
  15. package/src/base/_properties-2xl.css +171 -0
  16. package/src/base/_properties-active.css +107 -0
  17. package/src/base/_properties-checked.css +107 -0
  18. package/src/base/_properties-current.css +107 -0
  19. package/src/base/_properties-disabled.css +107 -0
  20. package/src/base/_properties-focus-visible.css +107 -0
  21. package/src/base/_properties-focus-within.css +107 -0
  22. package/src/base/_properties-hover.css +107 -0
  23. package/src/base/_properties-lg.css +171 -0
  24. package/src/base/_properties-md.css +171 -0
  25. package/src/base/_properties-open.css +107 -0
  26. package/src/base/_properties-sm.css +171 -0
  27. package/src/base/_properties-starting.css +55 -0
  28. package/src/base/_properties-stuck.css +55 -0
  29. package/src/base/_properties-xl.css +171 -0
  30. package/src/base/_properties.css +555 -0
  31. package/src/base/_reset.css +67 -75
  32. package/src/base/_switches.css +145 -0
  33. package/src/base/_typography.css +437 -370
  34. package/src/base/_utilities-box.css +142 -0
  35. package/src/base/_utilities-color.css +290 -0
  36. package/src/base/_utilities-effects.css +235 -0
  37. package/src/base/_utilities-flow.css +312 -0
  38. package/src/base/_utilities-grid.css +143 -0
  39. package/src/base/_utilities-margin.css +376 -0
  40. package/src/base/_utilities-pseudo.css +426 -0
  41. package/src/base/_utilities-sizing.css +259 -0
  42. package/src/base/_utilities-spacing.css +190 -0
  43. package/src/base/_utilities-tier-2xl.css +93 -0
  44. package/src/base/_utilities-tier-active.css +61 -0
  45. package/src/base/_utilities-tier-checked.css +61 -0
  46. package/src/base/_utilities-tier-current.css +61 -0
  47. package/src/base/_utilities-tier-disabled.css +61 -0
  48. package/src/base/_utilities-tier-focus-visible.css +61 -0
  49. package/src/base/_utilities-tier-focus-within.css +61 -0
  50. package/src/base/_utilities-tier-hover.css +63 -0
  51. package/src/base/_utilities-tier-lg.css +93 -0
  52. package/src/base/_utilities-tier-md.css +93 -0
  53. package/src/base/_utilities-tier-open.css +61 -0
  54. package/src/base/_utilities-tier-sm.css +93 -0
  55. package/src/base/_utilities-tier-starting.css +35 -0
  56. package/src/base/_utilities-tier-stuck.css +114 -0
  57. package/src/base/_utilities-tier-xl.css +93 -0
  58. package/src/base/_utilities-typography.css +141 -0
  59. package/src/base/_variables.css +323 -372
  60. package/src/base/_view-transitions.css +10 -12
  61. package/src/base/command-score.d.ts.map +1 -1
  62. package/src/base/command-score.js +1 -2
  63. package/src/base/command-score.ts +1 -2
  64. package/src/base/dialog-lifecycle.js +1 -1
  65. package/src/base/dialog-lifecycle.ts +1 -1
  66. package/src/base/embla.d.ts +6 -7
  67. package/src/base/embla.d.ts.map +1 -1
  68. package/src/base/embla.js +89 -55
  69. package/src/base/embla.ts +89 -55
  70. package/src/base/hotkeys.d.ts +0 -5
  71. package/src/base/hotkeys.d.ts.map +1 -1
  72. package/src/base/hotkeys.ts +0 -5
  73. package/src/base/navigation.d.ts +12 -1
  74. package/src/base/navigation.d.ts.map +1 -1
  75. package/src/base/navigation.js +229 -86
  76. package/src/base/navigation.ts +224 -92
  77. package/src/base/reveal.js +14 -14
  78. package/src/base/reveal.ts +14 -14
  79. package/src/base/scroll-state.d.ts +21 -0
  80. package/src/base/scroll-state.d.ts.map +1 -0
  81. package/src/base/scroll-state.js +177 -0
  82. package/src/base/scroll-state.ts +188 -0
  83. package/src/base/signals.d.ts +1 -2
  84. package/src/base/signals.d.ts.map +1 -1
  85. package/src/base/signals.js +4 -6
  86. package/src/base/signals.ts +4 -6
  87. package/src/base/style-format.d.ts +33 -0
  88. package/src/base/style-format.d.ts.map +1 -0
  89. package/src/base/style-format.js +160 -0
  90. package/src/base/style-format.ts +180 -0
  91. package/src/base/typeahead.d.ts +19 -4
  92. package/src/base/typeahead.d.ts.map +1 -1
  93. package/src/base/typeahead.js +68 -21
  94. package/src/base/typeahead.ts +73 -23
  95. package/src/base/utilities.d.ts +188 -0
  96. package/src/base/utilities.d.ts.map +1 -0
  97. package/src/base/utilities.js +750 -0
  98. package/src/base/utilities.ts +865 -0
  99. package/src/base/utils.d.ts +3 -7
  100. package/src/base/utils.d.ts.map +1 -1
  101. package/src/base/utils.js +4 -8
  102. package/src/base/utils.ts +4 -8
  103. package/src/base/zazz-element.d.ts +14 -8
  104. package/src/base/zazz-element.d.ts.map +1 -1
  105. package/src/base/zazz-element.js +14 -8
  106. package/src/base/zazz-element.ts +15 -8
  107. package/src/globals.d.ts +1 -1
  108. package/src/head.d.ts +50 -4
  109. package/src/head.d.ts.map +1 -1
  110. package/src/head.js +119 -38
  111. package/src/head.ts +172 -41
  112. package/src/index.css +57 -14
  113. package/src/index.js +5 -0
  114. package/src/index.ts +6 -0
  115. package/src/manifest.d.ts +36 -5
  116. package/src/manifest.d.ts.map +1 -1
  117. package/src/manifest.js +150 -6
  118. package/src/manifest.ts +167 -9
  119. package/src/primitives/accordion/accordion.css +18 -17
  120. package/src/primitives/accordion/accordion.html +42 -9
  121. package/src/primitives/alert-dialog/alert-dialog.css +13 -13
  122. package/src/primitives/alert-dialog/alert-dialog.html +26 -12
  123. package/src/primitives/autocomplete/autocomplete-groups.html +64 -33
  124. package/src/primitives/autocomplete/autocomplete.css +45 -43
  125. package/src/primitives/autocomplete/autocomplete.d.ts +6 -5
  126. package/src/primitives/autocomplete/autocomplete.d.ts.map +1 -1
  127. package/src/primitives/autocomplete/autocomplete.html +38 -26
  128. package/src/primitives/autocomplete/autocomplete.js +6 -5
  129. package/src/primitives/autocomplete/autocomplete.ts +6 -5
  130. package/src/primitives/avatar/avatar.html +110 -15
  131. package/src/primitives/badge/badge-icon.html +22 -8
  132. package/src/primitives/badge/badge.css +401 -128
  133. package/src/primitives/badge/badge.html +12 -6
  134. package/src/primitives/breadcrumbs/breadcrumbs.html +25 -5
  135. package/src/primitives/button/button-icon-only.html +17 -11
  136. package/src/primitives/button/button-icon.html +9 -3
  137. package/src/primitives/button/button.css +408 -164
  138. package/src/primitives/button/button.html +14 -7
  139. package/src/primitives/button-group/button-group-vertical.html +5 -5
  140. package/src/primitives/button-group/button-group.css +53 -25
  141. package/src/primitives/button-group/button-group.html +18 -12
  142. package/src/primitives/callout/callout.css +114 -0
  143. package/src/primitives/callout/callout.html +188 -0
  144. package/src/primitives/card/card-subgrid.html +249 -34
  145. package/src/primitives/card/card.css +125 -0
  146. package/src/primitives/card/card.html +141 -20
  147. package/src/primitives/carousel/carousel.css +30 -20
  148. package/src/primitives/carousel/carousel.d.ts +7 -10
  149. package/src/primitives/carousel/carousel.d.ts.map +1 -1
  150. package/src/primitives/carousel/carousel.html +420 -84
  151. package/src/primitives/carousel/carousel.js +1 -1
  152. package/src/primitives/carousel/carousel.ts +8 -11
  153. package/src/primitives/checkbox/checkbox-tasklist.html +6 -6
  154. package/src/primitives/checkbox/checkbox.css +98 -40
  155. package/src/primitives/checkbox/checkbox.d.ts.map +1 -1
  156. package/src/primitives/checkbox/checkbox.html +13 -8
  157. package/src/primitives/checkbox/checkbox.js +7 -9
  158. package/src/primitives/checkbox/checkbox.ts +7 -15
  159. package/src/primitives/combobox/combobox-multiselect.html +53 -33
  160. package/src/primitives/combobox/combobox.css +147 -126
  161. package/src/primitives/combobox/combobox.d.ts +12 -11
  162. package/src/primitives/combobox/combobox.d.ts.map +1 -1
  163. package/src/primitives/combobox/combobox.html +48 -28
  164. package/src/primitives/combobox/combobox.js +46 -51
  165. package/src/primitives/combobox/combobox.ts +48 -55
  166. package/src/primitives/command/command-actions.d.ts +2 -3
  167. package/src/primitives/command/command-actions.d.ts.map +1 -1
  168. package/src/primitives/command/command-actions.html +48 -33
  169. package/src/primitives/command/command-actions.js +12 -10
  170. package/src/primitives/command/command-actions.ts +12 -13
  171. package/src/primitives/command/command-dialog.html +49 -25
  172. package/src/primitives/command/command.css +52 -42
  173. package/src/primitives/command/command.d.ts +10 -7
  174. package/src/primitives/command/command.d.ts.map +1 -1
  175. package/src/primitives/command/command.html +95 -46
  176. package/src/primitives/command/command.js +30 -13
  177. package/src/primitives/command/command.ts +30 -12
  178. package/src/primitives/debug/audit-core.d.ts +64 -0
  179. package/src/primitives/debug/audit-core.d.ts.map +1 -0
  180. package/src/primitives/debug/audit-core.js +356 -0
  181. package/src/primitives/debug/audit-core.ts +535 -0
  182. package/src/primitives/debug/debug.d.ts +50 -0
  183. package/src/primitives/debug/debug.d.ts.map +1 -0
  184. package/src/primitives/debug/debug.js +168 -0
  185. package/src/primitives/debug/debug.ts +211 -0
  186. package/src/primitives/dialog/dialog-with-form.html +67 -45
  187. package/src/primitives/dialog/dialog.css +87 -61
  188. package/src/primitives/dialog/dialog.html +25 -17
  189. package/src/primitives/fields/fields.css +108 -134
  190. package/src/primitives/fields/fields.html +39 -0
  191. package/src/primitives/input/input-icon-leading.html +3 -3
  192. package/src/primitives/input/input-icon-trailing.html +3 -3
  193. package/src/primitives/input/input.css +87 -49
  194. package/src/primitives/input/input.html +15 -15
  195. package/src/primitives/input-group/input-group-password-group.html +15 -15
  196. package/src/primitives/input-group/input-group.css +118 -75
  197. package/src/primitives/input-group/input-group.html +42 -30
  198. package/src/primitives/kbd/kbd-group.html +15 -2
  199. package/src/primitives/kbd/kbd.css +44 -31
  200. package/src/primitives/kbd/kbd.html +7 -1
  201. package/src/primitives/layout/layout.css +159 -0
  202. package/src/primitives/layout/layout.html +35 -0
  203. package/src/primitives/lightbox/lightbox.css +178 -105
  204. package/src/primitives/lightbox/lightbox.d.ts.map +1 -1
  205. package/src/primitives/lightbox/lightbox.html +138 -166
  206. package/src/primitives/lightbox/lightbox.js +10 -13
  207. package/src/primitives/lightbox/lightbox.ts +12 -13
  208. package/src/primitives/menu/menu-interest.html +60 -18
  209. package/src/primitives/menu/menu.css +22 -17
  210. package/src/primitives/menu/menu.d.ts +5 -5
  211. package/src/primitives/menu/menu.html +195 -40
  212. package/src/primitives/menu/menu.js +8 -8
  213. package/src/primitives/menu/menu.ts +8 -8
  214. package/src/primitives/menubar/menubar-help-search.html +78 -32
  215. package/src/primitives/menubar/menubar.html +166 -38
  216. package/src/primitives/meter/meter.css +41 -38
  217. package/src/primitives/meter/meter.html +44 -9
  218. package/src/primitives/mobile-menu/mobile-menu.css +47 -40
  219. package/src/primitives/mobile-menu/mobile-menu.html +1460 -179
  220. package/src/primitives/navigation-menu/navigation-menu-featured.html +155 -33
  221. package/src/primitives/navigation-menu/navigation-menu-icon-grid.html +222 -47
  222. package/src/primitives/navigation-menu/navigation-menu-interest.html +130 -38
  223. package/src/primitives/navigation-menu/navigation-menu-megamenu.html +402 -72
  224. package/src/primitives/navigation-menu/navigation-menu-simple.html +90 -40
  225. package/src/primitives/navigation-menu/navigation-menu.css +104 -106
  226. package/src/primitives/navigation-menu/navigation-menu.html +554 -158
  227. package/src/primitives/otp/otp.css +43 -44
  228. package/src/primitives/otp/otp.d.ts +4 -5
  229. package/src/primitives/otp/otp.d.ts.map +1 -1
  230. package/src/primitives/otp/otp.html +7 -6
  231. package/src/primitives/otp/otp.js +13 -18
  232. package/src/primitives/otp/otp.ts +12 -19
  233. package/src/primitives/password-group/password-group.css +132 -107
  234. package/src/primitives/password-group/password-group.d.ts.map +1 -1
  235. package/src/primitives/password-group/password-group.html +23 -16
  236. package/src/primitives/password-group/password-group.js +11 -12
  237. package/src/primitives/password-group/password-group.ts +11 -12
  238. package/src/primitives/popover/popover.css +89 -95
  239. package/src/primitives/popover/popover.html +18 -0
  240. package/src/primitives/progress/progress-indeterminate.html +1 -1
  241. package/src/primitives/progress/progress.css +34 -35
  242. package/src/primitives/progress/progress.html +18 -4
  243. package/src/primitives/prose/prose.html +19 -12
  244. package/src/primitives/radio/radio.css +83 -46
  245. package/src/primitives/radio/radio.html +16 -11
  246. package/src/primitives/reveal/reveal.css +37 -46
  247. package/src/primitives/reveal/reveal.html +15 -0
  248. package/src/primitives/scroll-fade/scroll-fade.css +115 -0
  249. package/src/primitives/scroll-fade/scroll-fade.html +69 -0
  250. package/src/primitives/select/multiselect.d.ts +8 -10
  251. package/src/primitives/select/multiselect.d.ts.map +1 -1
  252. package/src/primitives/select/multiselect.js +23 -27
  253. package/src/primitives/select/multiselect.ts +23 -29
  254. package/src/primitives/select/select-align.html +79 -16
  255. package/src/primitives/select/select-multiple.html +8 -4
  256. package/src/primitives/select/select-sides.html +104 -21
  257. package/src/primitives/select/select.css +299 -191
  258. package/src/primitives/select/select.html +24 -5
  259. package/src/primitives/separator/separator.css +15 -18
  260. package/src/primitives/separator/separator.html +37 -10
  261. package/src/primitives/slider/slider.css +48 -38
  262. package/src/primitives/slider/slider.html +9 -1
  263. package/src/primitives/style-guard/style-guard.d.ts +19 -0
  264. package/src/primitives/style-guard/style-guard.d.ts.map +1 -0
  265. package/src/primitives/style-guard/style-guard.js +125 -0
  266. package/src/primitives/style-guard/style-guard.ts +153 -0
  267. package/src/primitives/switch/switch.css +42 -33
  268. package/src/primitives/switch/switch.html +11 -6
  269. package/src/primitives/table/table-alternating.html +1 -1
  270. package/src/primitives/table/table-grid.html +5 -5
  271. package/src/primitives/table/table-size-sm.html +1 -1
  272. package/src/primitives/table/table.css +64 -61
  273. package/src/primitives/table/table.html +7 -7
  274. package/src/primitives/tabs/tabs.css +167 -166
  275. package/src/primitives/tabs/tabs.d.ts +10 -11
  276. package/src/primitives/tabs/tabs.d.ts.map +1 -1
  277. package/src/primitives/tabs/tabs.html +192 -36
  278. package/src/primitives/tabs/tabs.js +14 -15
  279. package/src/primitives/tabs/tabs.ts +14 -15
  280. package/src/primitives/textarea/textarea.css +69 -44
  281. package/src/primitives/textarea/textarea.html +3 -3
  282. package/src/primitives/toaster/toaster.css +90 -92
  283. package/src/primitives/toaster/toaster.d.ts +0 -6
  284. package/src/primitives/toaster/toaster.d.ts.map +1 -1
  285. package/src/primitives/toaster/toaster.html +22 -18
  286. package/src/primitives/toaster/toaster.js +64 -72
  287. package/src/primitives/toaster/toaster.ts +71 -87
  288. package/src/primitives/toggle/toggle.css +368 -153
  289. package/src/primitives/toggle/toggle.html +27 -9
  290. package/src/primitives/toggle-group/toggle-group-multiple.html +3 -3
  291. package/src/primitives/toggle-group/toggle-group-vertical.html +4 -4
  292. package/src/primitives/toggle-group/toggle-group.css +71 -23
  293. package/src/primitives/toggle-group/toggle-group.html +3 -3
  294. package/src/primitives/toolbar/toolbar.html +35 -13
  295. package/src/primitives/tooltip/tooltip-disabled.html +3 -3
  296. package/src/primitives/tooltip/tooltip-sides.html +36 -14
  297. package/src/primitives/tooltip/tooltip-with-kbd.html +5 -5
  298. package/src/primitives/tooltip/tooltip.css +111 -80
  299. package/src/primitives/tooltip/tooltip.html +3 -3
  300. package/src/primitives/utilities/aspect-ratio.html +51 -7
  301. package/src/primitives/utilities/basis.html +64 -11
  302. package/src/primitives/utilities/col-span.html +65 -9
  303. package/src/primitives/utilities/compose.html +48 -10
  304. package/src/primitives/utilities/flex-align.html +89 -19
  305. package/src/primitives/utilities/flex-direction.html +111 -13
  306. package/src/primitives/utilities/flex-grow.html +41 -7
  307. package/src/primitives/utilities/gap.html +158 -19
  308. package/src/primitives/utilities/grid-cols.html +75 -7
  309. package/src/primitives/utilities/grid-responsive.html +111 -12
  310. package/src/primitives/utilities/margin-auto.html +38 -7
  311. package/src/primitives/utilities/object-fit.html +75 -13
  312. package/src/primitives/utilities/order.html +40 -4
  313. package/src/primitives/utilities/overflow.html +74 -20
  314. package/src/primitives/utilities/padding-compose.html +67 -10
  315. package/src/primitives/utilities/padding.html +84 -13
  316. package/src/primitives/utilities/pile.html +29 -0
  317. package/src/primitives/utilities/position.html +65 -8
  318. package/src/primitives/utilities/responsive-flex.html +54 -7
  319. package/src/primitives/utilities/responsive-grid.html +115 -12
  320. package/src/primitives/utilities/size.html +120 -16
  321. package/src/primitives/utilities/width.html +123 -16
  322. package/examples/about.html +0 -583
  323. package/examples/components.html +0 -1028
  324. package/examples/forms.html +0 -504
  325. package/examples/index.html +0 -261
  326. package/examples/layout.html +0 -313
  327. package/examples/products.html +0 -839
  328. package/examples/responsive.html +0 -332
  329. package/src/base/_layout.css +0 -571
  330. package/src/base/_utilities.css +0 -6758
  331. package/src/primitives/utilities/grid-pile.html +0 -5
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview `<ui-debug>`: audits utilities in `style` attributes.
4
+ * @description Development only. On a listed domain the element walks every
5
+ * element once, and again on mutation, and warns about the mistakes the
6
+ * generated gates cannot report: an unknown utility, a wrong mode, a tier without
7
+ * a base, a modifier the family lacks, a base utility that flattens a state a
8
+ * primitive's hook covers, a raw property shadowing a utility, a
9
+ * whitespace form the gates cannot match, and a `data-<name>-*` attribute
10
+ * outside its identity. On an unlisted domain it removes itself and logs
11
+ * {@link DEBUG_WARNING} once. Identities and hooks are read from the page's
12
+ * stylesheets, so the audit needs no manifest. The checks live in
13
+ * `audit-core.ts`, which the html lint rules (`@zazz-ui/eslint-plugin`) share.
14
+ * @example
15
+ * <ui-debug data-debug-domains="localhost, staging.example.com"></ui-debug>
16
+ */
17
+ import { ZazzElement, defineZazzElement } from "../../base/zazz-element.js";
18
+ import { auditNode, auditPersistence, carriesIdentity, } from "./audit-core.js";
19
+ /** A live element as the audit core reads it. */
20
+ function auditNodeOf(el) {
21
+ return {
22
+ getAttribute: (name) => el.getAttribute(name),
23
+ getAttributeNames: () => el.getAttributeNames(),
24
+ withinIdentity: (name, identities) => {
25
+ for (let node = el; node; node = node.parentElement) {
26
+ if (carriesIdentity(node.tagName, node.getAttribute("data-ui"), name, identities))
27
+ return true;
28
+ }
29
+ return false;
30
+ },
31
+ };
32
+ }
33
+ /** Identity tokens and state-bearing hooks, read from the page's stylesheets. */
34
+ function fromStylesheets() {
35
+ const identities = new Set();
36
+ const hooks = {};
37
+ const hookPattern = /--ui-([a-z]+(?:-[a-z]+)*?)-([a-z-]+?)--(hover|active|focus-visible|focus-within|checked|open|disabled)\b/g;
38
+ for (const sheet of document.styleSheets) {
39
+ let rules;
40
+ try {
41
+ rules = sheet.cssRules;
42
+ }
43
+ catch {
44
+ continue;
45
+ }
46
+ for (const rule of rules) {
47
+ const text = rule.cssText;
48
+ for (const m of text.matchAll(/\[data-ui~="([^"]+)"\]/g))
49
+ identities.add(m[1]);
50
+ for (const m of text.matchAll(hookPattern)) {
51
+ const list = (hooks[m[1]] ??= []);
52
+ if (!list.includes(`${m[2]}--${m[3]}`))
53
+ list.push(`${m[2]}--${m[3]}`);
54
+ }
55
+ }
56
+ }
57
+ return { identities: [...identities], hooks };
58
+ }
59
+ /** Audits every element under `root` (inclusive) and returns the findings. */
60
+ export function audit(root, options = {}) {
61
+ const sheets = options.hooks && options.identities ? null : fromStylesheets();
62
+ const resolved = {
63
+ hooks: options.hooks ?? sheets.hooks,
64
+ identities: options.identities ?? sheets.identities,
65
+ };
66
+ const context = { ...resolved, isColor: (value) => CSS.supports("color", value) };
67
+ const found = [];
68
+ for (const el of [root, ...root.querySelectorAll("*")]) {
69
+ if (el.tagName === "UI-DEBUG")
70
+ continue;
71
+ for (const { message, rule } of auditNode(auditNodeOf(el), context))
72
+ found.push({ el, message, rule });
73
+ }
74
+ return found;
75
+ }
76
+ /**
77
+ * Calls out what survives an in-page navigation: on a `data-ui-navigation="swap"`
78
+ * page, which `data-ui-persist` elements are kept and which
79
+ * `data-ui-persist-scroll` elements carry their scroll offset; warnings for
80
+ * persistence that cannot work as written.
81
+ */
82
+ export function navigationReport(doc) {
83
+ const swap = doc.documentElement.getAttribute("data-ui-navigation") === "swap";
84
+ const idOf = (attribute) => (el) => el.getAttribute(attribute) ?? "";
85
+ const persists = idOf("data-ui-persist");
86
+ const owner = (el) => (el ? { id: persists(el), self: false } : null);
87
+ const persisted = auditPersistence(swap, [...doc.querySelectorAll("[data-ui-persist]")], persists, (el) => owner(el.parentElement?.closest("[data-ui-persist]")));
88
+ const scrolled = auditPersistence(swap, [...doc.querySelectorAll("[data-ui-persist-scroll]")], idOf("data-ui-persist-scroll"), (el) => el.hasAttribute("data-ui-persist")
89
+ ? { id: persists(el), self: true }
90
+ : owner(el.closest("[data-ui-persist]")), "data-ui-persist-scroll");
91
+ const warnings = [...persisted.warnings, ...scrolled.warnings];
92
+ if (!swap)
93
+ return { notes: [], warnings };
94
+ const kept = persisted.kept;
95
+ const ids = (els, attribute) => els.map((el) => `"${el.getAttribute(attribute)}"`).join(", ");
96
+ const one = scrolled.kept.length === 1;
97
+ const scroll = scrolled.kept.length
98
+ ? ` ${scrolled.kept.length} element${one ? " comes" : "s come"} from the next page but keep${one ? "s its" : " their"} scroll offset (${ids(scrolled.kept, "data-ui-persist-scroll")}).`
99
+ : "";
100
+ const notes = [
101
+ {
102
+ message: (kept.length
103
+ ? `In-page navigation is on. ${kept.length} element${kept.length === 1 ? " persists" : "s persist"} across navigations (${ids(kept, "data-ui-persist")}); everything else is replaced by the next page.`
104
+ : "In-page navigation is on, and nothing persists: every navigation replaces the whole body.") +
105
+ scroll,
106
+ elements: [...kept, ...scrolled.kept],
107
+ },
108
+ ];
109
+ return { notes, warnings };
110
+ }
111
+ export const DEBUG_WARNING = 'Style utility debug tools are still loaded in this domain, but not enabled. If this is intentional, you can ignore this warning by setting data-debug-warnings="false".';
112
+ let warnedOnce = false;
113
+ class UiDebug extends ZazzElement {
114
+ setup(signal) {
115
+ const domains = (this.getAttribute("data-debug-domains") ?? "")
116
+ .split(",")
117
+ .map((domain) => domain.trim())
118
+ .filter(Boolean);
119
+ if (!domains.includes(location.hostname)) {
120
+ if (this.getAttribute("data-debug-warnings") !== "false" && !warnedOnce) {
121
+ warnedOnce = true;
122
+ console.warn(DEBUG_WARNING);
123
+ }
124
+ this.remove();
125
+ return;
126
+ }
127
+ const reported = new WeakMap();
128
+ const navigation = navigationReport(document);
129
+ for (const { message, elements } of navigation.notes)
130
+ console.info(`[ui-debug] ${message}`, ...elements);
131
+ const report = () => {
132
+ for (const { el, message } of [
133
+ ...audit(document.body),
134
+ ...navigationReport(document).warnings,
135
+ ]) {
136
+ const seen = reported.get(el) ?? new Set();
137
+ if (seen.has(message))
138
+ continue;
139
+ seen.add(message);
140
+ reported.set(el, seen);
141
+ console.warn(`[ui-debug] ${message}`, el);
142
+ }
143
+ };
144
+ let frame = 0;
145
+ const observer = new MutationObserver(() => {
146
+ if (frame)
147
+ return;
148
+ frame = requestAnimationFrame(() => {
149
+ frame = 0;
150
+ report();
151
+ });
152
+ });
153
+ observer.observe(document.body, {
154
+ attributes: true,
155
+ attributeFilter: ["style", "data-ui"],
156
+ childList: true,
157
+ subtree: true,
158
+ });
159
+ signal.addEventListener("abort", () => {
160
+ observer.disconnect();
161
+ if (frame)
162
+ cancelAnimationFrame(frame);
163
+ });
164
+ report();
165
+ }
166
+ }
167
+ defineZazzElement("ui-debug", UiDebug);
168
+ export { UiDebug };
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @fileoverview `<ui-debug>`: audits utilities in `style` attributes.
5
+ * @description Development only. On a listed domain the element walks every
6
+ * element once, and again on mutation, and warns about the mistakes the
7
+ * generated gates cannot report: an unknown utility, a wrong mode, a tier without
8
+ * a base, a modifier the family lacks, a base utility that flattens a state a
9
+ * primitive's hook covers, a raw property shadowing a utility, a
10
+ * whitespace form the gates cannot match, and a `data-<name>-*` attribute
11
+ * outside its identity. On an unlisted domain it removes itself and logs
12
+ * {@link DEBUG_WARNING} once. Identities and hooks are read from the page's
13
+ * stylesheets, so the audit needs no manifest. The checks live in
14
+ * `audit-core.ts`, which the html lint rules (`@zazz-ui/eslint-plugin`) share.
15
+ * @example
16
+ * <ui-debug data-debug-domains="localhost, staging.example.com"></ui-debug>
17
+ */
18
+
19
+ import { ZazzElement, defineZazzElement } from "../../base/zazz-element.ts";
20
+ import {
21
+ auditNode,
22
+ auditPersistence,
23
+ carriesIdentity,
24
+ type AuditNode,
25
+ type RuleId,
26
+ } from "./audit-core.ts";
27
+
28
+ export interface Warning {
29
+ el: Element;
30
+ message: string;
31
+ rule: RuleId;
32
+ }
33
+
34
+ export interface AuditOptions {
35
+ /** State-bearing hooks per identity as `<utility>--<state>` (`bg--hover`); default: the page's stylesheets. */
36
+ hooks?: Record<string, string[]>;
37
+ /** Identity tokens the kit declares (`button`, `field-group`); default: the page's stylesheets. */
38
+ identities?: string[];
39
+ }
40
+
41
+ /** A live element as the audit core reads it. */
42
+ function auditNodeOf(el: Element): AuditNode {
43
+ return {
44
+ getAttribute: (name) => el.getAttribute(name),
45
+ getAttributeNames: () => el.getAttributeNames(),
46
+ withinIdentity: (name, identities) => {
47
+ for (let node: Element | null = el; node; node = node.parentElement) {
48
+ if (carriesIdentity(node.tagName, node.getAttribute("data-ui"), name, identities))
49
+ return true;
50
+ }
51
+ return false;
52
+ },
53
+ };
54
+ }
55
+
56
+ /** Identity tokens and state-bearing hooks, read from the page's stylesheets. */
57
+ function fromStylesheets(): { identities: string[]; hooks: Record<string, string[]> } {
58
+ const identities = new Set<string>();
59
+ const hooks: Record<string, string[]> = {};
60
+ const hookPattern =
61
+ /--ui-([a-z]+(?:-[a-z]+)*?)-([a-z-]+?)--(hover|active|focus-visible|focus-within|checked|open|disabled)\b/g;
62
+ for (const sheet of document.styleSheets) {
63
+ let rules: CSSRuleList;
64
+ try {
65
+ rules = sheet.cssRules;
66
+ } catch {
67
+ continue;
68
+ }
69
+ for (const rule of rules) {
70
+ const text = rule.cssText;
71
+ for (const m of text.matchAll(/\[data-ui~="([^"]+)"\]/g)) identities.add(m[1]!);
72
+ for (const m of text.matchAll(hookPattern)) {
73
+ const list = (hooks[m[1]!] ??= []);
74
+ if (!list.includes(`${m[2]}--${m[3]}`)) list.push(`${m[2]}--${m[3]}`);
75
+ }
76
+ }
77
+ }
78
+ return { identities: [...identities], hooks };
79
+ }
80
+
81
+ /** Audits every element under `root` (inclusive) and returns the findings. */
82
+ export function audit(root: Element, options: AuditOptions = {}): Warning[] {
83
+ const sheets = options.hooks && options.identities ? null : fromStylesheets();
84
+ const resolved: Required<AuditOptions> = {
85
+ hooks: options.hooks ?? sheets!.hooks,
86
+ identities: options.identities ?? sheets!.identities,
87
+ };
88
+ const context = { ...resolved, isColor: (value: string) => CSS.supports("color", value) };
89
+ const found: Warning[] = [];
90
+ for (const el of [root, ...root.querySelectorAll("*")]) {
91
+ if (el.tagName === "UI-DEBUG") continue;
92
+ for (const { message, rule } of auditNode(auditNodeOf(el), context))
93
+ found.push({ el, message, rule });
94
+ }
95
+ return found;
96
+ }
97
+
98
+ export interface Note {
99
+ message: string;
100
+ elements: Element[];
101
+ }
102
+
103
+ /**
104
+ * Calls out what survives an in-page navigation: on a `data-ui-navigation="swap"`
105
+ * page, which `data-ui-persist` elements are kept and which
106
+ * `data-ui-persist-scroll` elements carry their scroll offset; warnings for
107
+ * persistence that cannot work as written.
108
+ */
109
+ export function navigationReport(doc: Document): { notes: Note[]; warnings: Warning[] } {
110
+ const swap = doc.documentElement.getAttribute("data-ui-navigation") === "swap";
111
+ const idOf = (attribute: string) => (el: Element) => el.getAttribute(attribute) ?? "";
112
+ const persists = idOf("data-ui-persist");
113
+ const owner = (el: Element | null | undefined) => (el ? { id: persists(el), self: false } : null);
114
+ const persisted = auditPersistence(
115
+ swap,
116
+ [...doc.querySelectorAll("[data-ui-persist]")],
117
+ persists,
118
+ (el) => owner(el.parentElement?.closest("[data-ui-persist]")),
119
+ );
120
+ const scrolled = auditPersistence(
121
+ swap,
122
+ [...doc.querySelectorAll("[data-ui-persist-scroll]")],
123
+ idOf("data-ui-persist-scroll"),
124
+ (el) =>
125
+ el.hasAttribute("data-ui-persist")
126
+ ? { id: persists(el), self: true }
127
+ : owner(el.closest("[data-ui-persist]")),
128
+ "data-ui-persist-scroll",
129
+ );
130
+ const warnings = [...persisted.warnings, ...scrolled.warnings];
131
+ if (!swap) return { notes: [], warnings };
132
+ const kept = persisted.kept;
133
+ const ids = (els: Element[], attribute: string) =>
134
+ els.map((el) => `"${el.getAttribute(attribute)}"`).join(", ");
135
+ const one = scrolled.kept.length === 1;
136
+ const scroll = scrolled.kept.length
137
+ ? ` ${scrolled.kept.length} element${one ? " comes" : "s come"} from the next page but keep${one ? "s its" : " their"} scroll offset (${ids(scrolled.kept, "data-ui-persist-scroll")}).`
138
+ : "";
139
+ const notes: Note[] = [
140
+ {
141
+ message:
142
+ (kept.length
143
+ ? `In-page navigation is on. ${kept.length} element${kept.length === 1 ? " persists" : "s persist"} across navigations (${ids(kept, "data-ui-persist")}); everything else is replaced by the next page.`
144
+ : "In-page navigation is on, and nothing persists: every navigation replaces the whole body.") +
145
+ scroll,
146
+ elements: [...kept, ...scrolled.kept],
147
+ },
148
+ ];
149
+ return { notes, warnings };
150
+ }
151
+
152
+ export const DEBUG_WARNING =
153
+ 'Style utility debug tools are still loaded in this domain, but not enabled. If this is intentional, you can ignore this warning by setting data-debug-warnings="false".';
154
+
155
+ let warnedOnce = false;
156
+
157
+ class UiDebug extends ZazzElement {
158
+ protected setup(signal: AbortSignal): void {
159
+ const domains = (this.getAttribute("data-debug-domains") ?? "")
160
+ .split(",")
161
+ .map((domain) => domain.trim())
162
+ .filter(Boolean);
163
+ if (!domains.includes(location.hostname)) {
164
+ if (this.getAttribute("data-debug-warnings") !== "false" && !warnedOnce) {
165
+ warnedOnce = true;
166
+ console.warn(DEBUG_WARNING);
167
+ }
168
+ this.remove();
169
+ return;
170
+ }
171
+ const reported = new WeakMap<Element, Set<string>>();
172
+ const navigation = navigationReport(document);
173
+ for (const { message, elements } of navigation.notes)
174
+ console.info(`[ui-debug] ${message}`, ...elements);
175
+ const report = () => {
176
+ for (const { el, message } of [
177
+ ...audit(document.body),
178
+ ...navigationReport(document).warnings,
179
+ ]) {
180
+ const seen = reported.get(el) ?? new Set<string>();
181
+ if (seen.has(message)) continue;
182
+ seen.add(message);
183
+ reported.set(el, seen);
184
+ console.warn(`[ui-debug] ${message}`, el);
185
+ }
186
+ };
187
+ let frame = 0;
188
+ const observer = new MutationObserver(() => {
189
+ if (frame) return;
190
+ frame = requestAnimationFrame(() => {
191
+ frame = 0;
192
+ report();
193
+ });
194
+ });
195
+ observer.observe(document.body, {
196
+ attributes: true,
197
+ attributeFilter: ["style", "data-ui"],
198
+ childList: true,
199
+ subtree: true,
200
+ });
201
+ signal.addEventListener("abort", () => {
202
+ observer.disconnect();
203
+ if (frame) cancelAnimationFrame(frame);
204
+ });
205
+ report();
206
+ }
207
+ }
208
+
209
+ defineZazzElement("ui-debug", UiDebug);
210
+
211
+ export { UiDebug };
@@ -1,4 +1,4 @@
1
- <button class="ui-button" type="button" command="show-modal" commandfor="form-dialog-1">
1
+ <button data-ui="button" type="button" command="show-modal" commandfor="form-dialog-1">
2
2
  New project
3
3
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
4
4
  <rect width="256" height="256" fill="none" />
@@ -26,22 +26,44 @@
26
26
  />
27
27
  </svg>
28
28
  </button>
29
- <dialog id="form-dialog-1" class="ui-dialog" closedby="any" data-size="article">
30
- <div data-slot="dialog-content">
31
- <header data-slot="dialog-header">
32
- <h2 class="text-lg font-heading font-strong">New project</h2>
33
- <p class="text-muted-foreground">
29
+ <dialog id="form-dialog-1" data-ui="dialog" closedby="any" data-dialog-size="article">
30
+ <div data-dialog-slot="content">
31
+ <header data-dialog-slot="header">
32
+ <h2
33
+ style="
34
+ --font-size: var(--font-size-lg);
35
+ --font-weight: strong;
36
+ --font-family: var(--font-family-heading);
37
+ "
38
+ >
39
+ New project
40
+ </h2>
41
+ <p style="--text: var(--color-muted-foreground)">
34
42
  Add a project to your workspace. You can change these settings later.
35
43
  </p>
36
44
  </header>
37
- <form id="f-new-project-1" class="flex flex-col gap-md" data-slot="dialog-body" method="dialog">
38
- <fieldset class="ui-field-group">
39
- <legend class="sr-only">Contact</legend>
40
- <div class="grid grid-cols-2 gap-sm">
41
- <div class="ui-field">
42
- <label data-slot="field-label" for="fd-name">Name</label>
45
+ <form
46
+ id="f-new-project-1"
47
+ style="
48
+ --display: flex-col;
49
+ --gap: 6;
50
+ "
51
+ data-dialog-slot="body"
52
+ method="dialog"
53
+ >
54
+ <fieldset data-ui="field-group">
55
+ <legend data-ui="sr-only">Contact</legend>
56
+ <div
57
+ style="
58
+ --display: grid;
59
+ --grid-cols: 2;
60
+ --gap: 4;
61
+ "
62
+ >
63
+ <div data-ui="field">
64
+ <label data-field-slot="label" for="fd-name">Name</label>
43
65
  <input
44
- class="ui-input"
66
+ data-ui="input"
45
67
  id="fd-name"
46
68
  name="name"
47
69
  type="text"
@@ -50,10 +72,10 @@
50
72
  required
51
73
  />
52
74
  </div>
53
- <div class="ui-field">
54
- <label data-slot="field-label" for="fd-email">Email</label>
75
+ <div data-ui="field">
76
+ <label data-field-slot="label" for="fd-email">Email</label>
55
77
  <input
56
- class="ui-input"
78
+ data-ui="input"
57
79
  id="fd-email"
58
80
  name="email"
59
81
  type="email"
@@ -63,25 +85,25 @@
63
85
  autocomplete="email"
64
86
  aria-describedby="fd-email-hint"
65
87
  />
66
- <div data-slot="field-description">
67
- <span data-slot="field-hint" id="fd-email-hint"
88
+ <div data-field-slot="description">
89
+ <span data-field-slot="hint" id="fd-email-hint"
68
90
  >We'll only use this to send receipts.</span
69
91
  >
70
- <span data-slot="field-error" role="alert">Please enter a valid email address.</span>
92
+ <span data-field-slot="error" role="alert">Please enter a valid email address.</span>
71
93
  </div>
72
94
  </div>
73
- <label class="ui-field-group col-span-2">
74
- <span data-slot="field-label">Repository</span>
75
- <div class="ui-input-group">
95
+ <label data-ui="field" style="--col-span: 2">
96
+ <span data-field-slot="label">Repository</span>
97
+ <div data-ui="input-group">
76
98
  <input
77
- class="ui-input"
99
+ data-ui="input"
78
100
  type="search"
79
101
  name="repo"
80
102
  id="fd-repo"
81
103
  inputmode="search"
82
104
  placeholder="Search repositories…"
83
105
  />
84
- <span data-slot="input-group-addon">
106
+ <span data-input-group-slot="addon">
85
107
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
86
108
  <rect width="256" height="256" fill="none" />
87
109
  <circle
@@ -112,11 +134,11 @@
112
134
  </div>
113
135
  </fieldset>
114
136
 
115
- <fieldset class="ui-field-group">
116
- <div class="ui-field">
117
- <label data-slot="field-label" for="fd-message">Description</label>
137
+ <fieldset data-ui="field-group">
138
+ <div data-ui="field">
139
+ <label data-field-slot="label" for="fd-message">Description</label>
118
140
  <textarea
119
- class="ui-textarea"
141
+ data-ui="textarea"
120
142
  id="fd-message"
121
143
  name="description"
122
144
  inputmode="text"
@@ -125,26 +147,26 @@
125
147
  </div>
126
148
  </fieldset>
127
149
 
128
- <fieldset class="ui-radio-group">
150
+ <fieldset data-ui="radio-group">
129
151
  <legend>Billing</legend>
130
- <label class="ui-field" data-orientation="horizontal">
131
- <input class="ui-radio" type="radio" name="billing" value="monthly" />
132
- <span data-slot="field-label">Monthly billing</span>
152
+ <label data-ui="field" data-field-orientation="horizontal">
153
+ <input data-ui="radio" type="radio" name="billing" value="monthly" />
154
+ <span data-field-slot="label">Monthly billing</span>
133
155
  </label>
134
- <label class="ui-field" data-orientation="horizontal">
135
- <input class="ui-radio" type="radio" name="billing" value="annual" checked />
136
- <span data-slot="field-label">Annual billing</span>
156
+ <label data-ui="field" data-field-orientation="horizontal">
157
+ <input data-ui="radio" type="radio" name="billing" value="annual" checked />
158
+ <span data-field-slot="label">Annual billing</span>
137
159
  </label>
138
160
  </fieldset>
139
161
 
140
- <label class="ui-field" data-orientation="horizontal">
162
+ <label data-ui="field" data-field-orientation="horizontal">
141
163
  <input type="checkbox" name="terms" required />
142
- <span data-slot="field-label">Accept terms &amp; conditions</span>
164
+ <span data-field-slot="label">Accept terms &amp; conditions</span>
143
165
  </label>
144
166
  </form>
145
- <footer data-slot="dialog-footer">
167
+ <footer data-dialog-slot="footer">
146
168
  <button
147
- class="ui-button"
169
+ data-ui="button"
148
170
  type="button"
149
171
  value="cancel"
150
172
  commandfor="form-dialog-1"
@@ -153,8 +175,8 @@
153
175
  Cancel
154
176
  </button>
155
177
  <button
156
- class="ui-button"
157
- data-variant="primary"
178
+ data-ui="button"
179
+ data-button-variant="primary"
158
180
  type="submit"
159
181
  form="f-new-project-1"
160
182
  value="save"
@@ -163,10 +185,10 @@
163
185
  </button>
164
186
  </footer>
165
187
  <button
166
- class="ui-button"
167
- data-slot="dialog-close"
168
- data-size="icon"
169
- data-variant="ghost"
188
+ data-ui="button"
189
+ data-dialog-slot="close"
190
+ data-button-size="icon"
191
+ data-button-variant="ghost"
170
192
  type="button"
171
193
  commandfor="form-dialog-1"
172
194
  command="close"