@zazz-ui/core 0.4.1 → 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 +331 -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 +43 -39
  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 +145 -122
  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 +88 -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 +297 -186
  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,535 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @fileoverview The DOM-free audit behind `<ui-debug>` and the html lint rules.
5
+ * @description Works on {@link AuditNode}, a five-method view of an element, so
6
+ * the browser (a live `Element`) and the linter (an html-eslint `Tag`) run the
7
+ * same checks and raise the same messages. Each finding names its rule and,
8
+ * where it can, the span of the declaration it is about (offsets into the
9
+ * `style` attribute) and a suggested rewrite.
10
+ */
11
+
12
+ import {
13
+ BORDER_SHORTHANDS,
14
+ GRADIENT_TYPES,
15
+ UTILITIES,
16
+ PSEUDO_ONLY,
17
+ FONT_WEIGHT_NAMES,
18
+ STUCK_STATE,
19
+ STATES,
20
+ parseUtilityName,
21
+ tiersOf,
22
+ type Utility,
23
+ type UtilityName,
24
+ } from "../../base/utilities.ts";
25
+
26
+ /** A stable name per finding, so a linter can switch each one off. */
27
+ export type RuleId =
28
+ | "unknown-utility"
29
+ | "pseudo-form"
30
+ | "group-needs-state"
31
+ | "border-value"
32
+ | "not-integer"
33
+ | "tier-unsupported"
34
+ | "tier-without-base"
35
+ | "dual-value"
36
+ | "keyword-number"
37
+ | "raw-shadows-utility"
38
+ | "flattens-state"
39
+ | "gradient-incomplete"
40
+ | "font-weight-name"
41
+ | "scroll-state"
42
+ | "whitespace-before-colon"
43
+ | "attribute-outside-identity"
44
+ | "persist";
45
+
46
+ export const RULE_IDS: readonly RuleId[] = [
47
+ "unknown-utility",
48
+ "pseudo-form",
49
+ "group-needs-state",
50
+ "border-value",
51
+ "not-integer",
52
+ "tier-unsupported",
53
+ "tier-without-base",
54
+ "dual-value",
55
+ "keyword-number",
56
+ "raw-shadows-utility",
57
+ "flattens-state",
58
+ "gradient-incomplete",
59
+ "font-weight-name",
60
+ "scroll-state",
61
+ "whitespace-before-colon",
62
+ "attribute-outside-identity",
63
+ "persist",
64
+ ];
65
+
66
+ /** `[start, end)` offsets into the `style` attribute's value. */
67
+ export type Span = [number, number];
68
+
69
+ export interface Suggestion {
70
+ description: string;
71
+ span: Span;
72
+ text: string;
73
+ }
74
+
75
+ export interface Finding {
76
+ rule: RuleId;
77
+ message: string;
78
+ /** The declaration the finding is about, inside `style`. */
79
+ span?: Span;
80
+ /** The attribute the finding is about, when it is not `style`. */
81
+ attribute?: string;
82
+ suggestion?: Suggestion;
83
+ }
84
+
85
+ /** The parts of an element the audit reads. */
86
+ export interface AuditNode {
87
+ getAttribute(name: string): string | null;
88
+ getAttributeNames(): string[];
89
+ /** True when this node or an ancestor carries the identity `name` (see {@link carriesIdentity}). */
90
+ withinIdentity(name: string, identities: readonly string[]): boolean;
91
+ }
92
+
93
+ export interface AuditContext {
94
+ /** State-bearing hooks per identity as `<utility>--<state>` (`bg--hover`). */
95
+ hooks: Record<string, string[]>;
96
+ /** Identity tokens the kit declares (`button`, `field-group`). */
97
+ identities: readonly string[];
98
+ /** True when `value` is a color identifier (`red`, `currentcolor`); the browser asks `CSS.supports`. */
99
+ isColor: (value: string) => boolean;
100
+ }
101
+
102
+ const UTILITY_BY_NAME = new Map<string, Utility>(
103
+ [...UTILITIES, ...PSEUDO_ONLY].map((utility) => [utility.name, utility]),
104
+ );
105
+ const PSEUDO_ONLY_NAMES = new Set(PSEUDO_ONLY.map((utility) => utility.name));
106
+
107
+ const NUMBER = /^-?(\d+\.?\d*|\.\d+)$/;
108
+ const DIMENSION =
109
+ /^-?(\d+\.?\d*|\.\d+)(px|r?em|%|v[wh]|v[ib]|[sld]v[wh]|ch|ex|cap|ic|lh|rlh|cq[iwhb]|cqmin|cqmax|pt|cm|mm|in)$/;
110
+ const FUNCTION = /^(calc|clamp|min|max|var|env|round|mod|rem|abs|sign)\(/;
111
+
112
+ interface Declaration {
113
+ /** The name as written; its whitespace is a finding. */
114
+ name: string;
115
+ value: string;
116
+ span: Span;
117
+ }
118
+
119
+ /** Splits a `style` attribute into declarations with their spans. */
120
+ function declarations(text: string): Declaration[] {
121
+ const found: Declaration[] = [];
122
+ let offset = 0;
123
+ for (const part of text.split(";")) {
124
+ const start = offset;
125
+ offset += part.length + 1;
126
+ const colon = part.indexOf(":");
127
+ if (colon === -1) continue;
128
+ const lead = part.length - part.trimStart().length;
129
+ const trail = part.length - part.trimEnd().length;
130
+ found.push({
131
+ name: part.slice(0, colon),
132
+ value: part
133
+ .slice(colon + 1)
134
+ .replace(/!\s*important\s*$/i, "")
135
+ .trim(),
136
+ span: [start + lead, start + part.length - trail],
137
+ });
138
+ }
139
+ return found;
140
+ }
141
+
142
+ /**
143
+ * True when `value` can be a border shorthand value: one number, one
144
+ * length, one function (`var()`, `calc()`, a color function), or an identifier
145
+ * the browser accepts as a color. Several space-separated values (CSS's
146
+ * `1px solid red`), a percentage, or an unknown word all draw a 1px
147
+ * transparent border instead.
148
+ */
149
+ function isBorderValue(value: string, isColor: (value: string) => boolean): boolean {
150
+ if (NUMBER.test(value) || FUNCTION.test(value) || /^#[\da-f]{3,8}$/i.test(value)) return true;
151
+ if (/^(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color|color-mix|light-dark)\(/i.test(value))
152
+ return true;
153
+ if (DIMENSION.test(value)) return !value.endsWith("%");
154
+ if (/^-?[a-z][\w-]*$/i.test(value)) return isColor(value);
155
+ return false;
156
+ }
157
+
158
+ function isDualValue(value: string, utility: Utility): boolean {
159
+ return (
160
+ NUMBER.test(value) ||
161
+ DIMENSION.test(value) ||
162
+ FUNCTION.test(value) ||
163
+ (utility.keywords ?? []).includes(value)
164
+ );
165
+ }
166
+
167
+ /**
168
+ * True when an element with this tag and `data-ui` carries the identity `name`:
169
+ * a tag form or a declared token that is `name` or sits under its prefix
170
+ * (`field-group` and `<ui-toggle-group>` carry `field` and `toggle`).
171
+ */
172
+ export function carriesIdentity(
173
+ tagName: string,
174
+ dataUi: string | null,
175
+ name: string,
176
+ identities: readonly string[],
177
+ ): boolean {
178
+ const tag = tagName.toLowerCase();
179
+ if (tag === `ui-${name}` || tag.startsWith(`ui-${name}-`)) return true;
180
+ const tokens = (dataUi ?? "").split(/\s+/).filter(Boolean);
181
+ return tokens.some(
182
+ (token) => identities.includes(token) && (token === name || token.startsWith(`${name}-`)),
183
+ );
184
+ }
185
+
186
+ /** Audits one element's `style` and `data-*` attributes. */
187
+ export function auditNode(node: AuditNode, context: AuditContext): Finding[] {
188
+ const found: Finding[] = [];
189
+ const style = declarations(node.getAttribute("style") ?? "");
190
+ const bases = new Set<string>();
191
+ const raw = new Map<string, Declaration>();
192
+ const parsedPairs: [UtilityName, string, Declaration][] = [];
193
+ for (const declaration of style) {
194
+ const name = declaration.name.trim();
195
+ if (!name.startsWith("--")) {
196
+ raw.set(name, declaration);
197
+ continue;
198
+ }
199
+ if (declaration.name.trimStart() !== name) {
200
+ const [start] = declaration.span;
201
+ found.push({
202
+ rule: "whitespace-before-colon",
203
+ message: `\`${name} : ${declaration.value}\` has whitespace before the colon; the gates match \`${name}: …\` only.`,
204
+ span: declaration.span,
205
+ suggestion: {
206
+ description: `Write \`${name}:\`.`,
207
+ span: [start, start + declaration.name.trimStart().length],
208
+ text: name,
209
+ },
210
+ });
211
+ }
212
+ const parsed = parseUtilityName(name);
213
+ parsedPairs.push([parsed, name, declaration]);
214
+ if (!parsed.tier) bases.add((parsed.side ? `${parsed.side}-` : "") + parsed.name);
215
+ }
216
+ const tokens = (node.getAttribute("data-ui") ?? "").split(/\s+/).filter(Boolean);
217
+ for (const [parsed, name, declaration] of parsedPairs) {
218
+ const { value, span } = declaration;
219
+ const warn = (rule: RuleId, message: string, suggestion?: Suggestion) =>
220
+ found.push({ rule, message, span, ...(suggestion ? { suggestion } : {}) });
221
+ // --stuck-state names the side a sticky container reports as stuck
222
+ if (parsed.name === STUCK_STATE.modifier && !parsed.group && !parsed.side) {
223
+ if (parsed.tier) {
224
+ warn(
225
+ "scroll-state",
226
+ `\`${name}\` has no tiers: the stuck state needs sticky positioning, so switch \`--position\` at that breakpoint instead.`,
227
+ );
228
+ } else if (!(STUCK_STATE.sides as readonly string[]).includes(value)) {
229
+ warn(
230
+ "scroll-state",
231
+ `\`${name}: ${value}\` is not a side the stuck state matches: ${STUCK_STATE.sides.join(", ")}.`,
232
+ );
233
+ }
234
+ continue;
235
+ }
236
+ const utility = UTILITY_BY_NAME.get(parsed.name);
237
+ if (!utility) {
238
+ if (parsed.name === "flex-direction") {
239
+ warn(
240
+ "unknown-utility",
241
+ `\`${name}\` is gone: the direction rides on --display. Write \`--display${parsed.tier ? `--${parsed.tier}` : ""}: flex-col\` (or flex-row, …-reverse, inline-flex-…).`,
242
+ );
243
+ } else if (!name.startsWith("--ui-")) {
244
+ warn("unknown-utility", `\`${name}\` is an unknown utility.`);
245
+ }
246
+ continue;
247
+ }
248
+ if (parsed.side && !utility.pseudo) {
249
+ warn("pseudo-form", `\`${name}\`: --${utility.name} has no ::${parsed.side} form.`);
250
+ continue;
251
+ }
252
+ if (!parsed.side && PSEUDO_ONLY_NAMES.has(utility.name)) {
253
+ warn(
254
+ "pseudo-form",
255
+ `\`${name}\` exists only as \`--before-${utility.name}\` / \`--after-${utility.name}\`.`,
256
+ );
257
+ continue;
258
+ }
259
+ const baseName = (parsed.side ? `${parsed.side}-` : "") + utility.name;
260
+ if (parsed.group && parsed.tier === "stuck") {
261
+ warn(
262
+ "scroll-state",
263
+ `\`${name}\` has no group form: the sticky container is the trigger, so write \`--${utility.name}--stuck\` inside it.`,
264
+ );
265
+ continue;
266
+ }
267
+ // a container query never matches the container: on the sticky element itself it never applies
268
+ if (parsed.tier === "stuck" && !parsed.side) {
269
+ const style = node.getAttribute("style") ?? "";
270
+ if (style.includes(": sticky") || style.includes(`--${STUCK_STATE.modifier}:`)) {
271
+ warn(
272
+ "scroll-state",
273
+ `\`${name}\` is on the sticky container itself; the stuck state reaches only its descendants, so move it to a child.`,
274
+ );
275
+ }
276
+ }
277
+ if (parsed.group && parsed.tier === "starting") {
278
+ warn(
279
+ "group-needs-state",
280
+ `\`${name}\` has no group form: a starting style belongs to the element itself, so write \`--${utility.name}--starting\`.`,
281
+ );
282
+ continue;
283
+ }
284
+ if (parsed.group && !(parsed.tier && (STATES as readonly string[]).includes(parsed.tier))) {
285
+ warn(
286
+ "group-needs-state",
287
+ `\`${name}\` needs a state tier: group utilities take \`--group-${utility.name}--<state>\`.`,
288
+ );
289
+ continue;
290
+ }
291
+ if (utility.emit === "border" && !isBorderValue(value, context.isColor)) {
292
+ warn(
293
+ "border-value",
294
+ `\`${name}: ${value}\` is not one color, number, or length; it draws a 1px transparent border. Use \`--border: 2\`, \`--border: var(--color-primary)\`, or set \`--border-style\` separately.`,
295
+ );
296
+ }
297
+ // an integer utility emits `repeat(n, …)`, `span n`, or a count, so anything else silently does nothing
298
+ if (
299
+ utility.mode === "integer" &&
300
+ !/^\d+$/.test(value) &&
301
+ !FUNCTION.test(value) &&
302
+ !(utility.keywords ?? []).includes(value) &&
303
+ !(utility.emit === "line-clamp" && value === "none")
304
+ ) {
305
+ const template = utility.name.replace(/^grid-/, "template-");
306
+ const tier = parsed.tier ? `--${parsed.tier}` : "";
307
+ // Tailwind's col-span-full is the line range 1 / -1, which splits into
308
+ // the start and end utilities (there is no raw grid-column / grid-row one)
309
+ const line = utility.name.replace(/-span$/, "");
310
+ const fullSpan = `--${line}-start${tier}: 1; --${line}-end${tier}: -1`;
311
+ const [hint, rewrite] =
312
+ template !== utility.name && UTILITY_BY_NAME.has(template)
313
+ ? ["For a track list write", `--${template}${tier}: ${value}`]
314
+ : utility.emit === "span" && value === "full"
315
+ ? ["To span every track write", fullSpan]
316
+ : [];
317
+ warn(
318
+ "not-integer",
319
+ `\`${name}: ${value}\` is not an integer.${rewrite ? ` ${hint} \`${rewrite}\`.` : ""}`,
320
+ rewrite ? { description: `Write \`${rewrite}\`.`, span, text: rewrite } : undefined,
321
+ );
322
+ }
323
+ if (parsed.tier) {
324
+ const tiers = tiersOf(utility);
325
+ if (!tiers.includes(parsed.tier)) {
326
+ warn(
327
+ "tier-unsupported",
328
+ `\`${name}\` uses a tier the ${utility.family} family has no setter for; \`--${utility.name}\` takes ${tiers.length ? tiers.join(", ") : "no tiers"}.`,
329
+ );
330
+ continue;
331
+ }
332
+ // a border shorthand is the base a border longhand's tier overrides
333
+ const borderBase =
334
+ /^border-(?:width|color|style)$/.test(baseName) &&
335
+ BORDER_SHORTHANDS.some((name) => bases.has(name));
336
+ if (utility.noBase === undefined && !bases.has(baseName) && !borderBase) {
337
+ warn(
338
+ "tier-without-base",
339
+ `\`${name}\` has no base \`--${baseName}\`; the tier only overrides a base.`,
340
+ );
341
+ }
342
+ continue;
343
+ }
344
+ if (utility.mode === "dual" && !isDualValue(value, utility)) {
345
+ warn(
346
+ "dual-value",
347
+ `\`${name}: ${value}\` is neither a scale number, a length, nor a keyword (${(utility.keywords ?? []).join(", ") || "none"}).`,
348
+ );
349
+ }
350
+ if (utility.mode === "keyword" && NUMBER.test(value)) {
351
+ warn("keyword-number", `\`${name}: ${value}\` is a number on a keyword utility.`);
352
+ }
353
+ // standard weight names are not CSS (only normal and bold are): write the number
354
+ const weight = utility.name === "font-weight" ? FONT_WEIGHT_NAMES[value] : undefined;
355
+ if (weight !== undefined) {
356
+ const valueEnd = span[1];
357
+ const valueStart = valueEnd - value.length;
358
+ warn(
359
+ "font-weight-name",
360
+ `\`${name}: ${value}\` is not a CSS weight: write \`${weight}\` (the keywords are heading, body, and strong).`,
361
+ { description: `Write \`${weight}\`.`, span: [valueStart, valueEnd], text: String(weight) },
362
+ );
363
+ }
364
+ for (const property of utility.properties) {
365
+ const shadow = raw.get(property);
366
+ if (shadow) {
367
+ found.push({
368
+ rule: "raw-shadows-utility",
369
+ message: `\`${property}: ${shadow.value}\` shadows the utility \`${name}\`; the raw declaration wins.`,
370
+ span: shadow.span,
371
+ });
372
+ }
373
+ }
374
+ // A base utility flattens the state a primitive hook covers unless the tier is set too.
375
+ // With a variant preset the override is deliberate (variant + utility, as in Tailwind).
376
+ if (!parsed.side) {
377
+ for (const token of tokens) {
378
+ if (node.getAttribute(`data-${token}-variant`) !== null) continue;
379
+ for (const hook of context.hooks[token] ?? []) {
380
+ const [hookUtility, state] = hook.split("--");
381
+ // a border shorthand writes the border-color and border-width the hooks back
382
+ const covers =
383
+ hookUtility === utility.name ||
384
+ (utility.emit === "border" &&
385
+ (hookUtility === "border-color" || hookUtility === "border-width"));
386
+ if (
387
+ covers &&
388
+ state &&
389
+ !parsedPairs.some(
390
+ ([p]) => (p.name === utility.name || p.name === hookUtility) && p.tier === state,
391
+ )
392
+ ) {
393
+ warn(
394
+ "flattens-state",
395
+ `\`${name}\` on a ${token} flattens its ${state} state; add \`--${utility.name}--${state}\` or set the hook \`--ui-${token}-${hookUtility}--${state}\`.`,
396
+ );
397
+ }
398
+ }
399
+ }
400
+ }
401
+ }
402
+ // a gradient needs a type (--bg-linear | -radial | -conic) and --bg-stops, both at the base
403
+ const declared = (base: string) =>
404
+ parsedPairs.find(([p]) => !p.tier && !p.side && p.name === base);
405
+ const types = GRADIENT_TYPES.map((type) => declared(`bg-${type}`)).filter((pair) => !!pair);
406
+ const stops = declared("bg-stops");
407
+ if (!stops) {
408
+ for (const [, name, { span }] of types) {
409
+ found.push({
410
+ rule: "gradient-incomplete",
411
+ message: `\`${name}\` draws nothing without \`--bg-stops\` (the gradient's color stops).`,
412
+ span,
413
+ });
414
+ }
415
+ } else if (!types.length) {
416
+ found.push({
417
+ rule: "gradient-incomplete",
418
+ message:
419
+ "`--bg-stops` draws nothing without a gradient type: `--bg-linear`, `--bg-radial`, or `--bg-conic`.",
420
+ span: stops[2].span,
421
+ });
422
+ }
423
+ if (types.length > 1) {
424
+ found.push({
425
+ rule: "gradient-incomplete",
426
+ message: `One gradient per element: ${types.map(([, name]) => `\`${name}\``).join(", ")} are set and only the last in source (linear, radial, conic) draws.`,
427
+ span: types[0]![2].span,
428
+ });
429
+ }
430
+ // data-<name>-<key> outside the identity (slots and states sit on children by design).
431
+ // A custom-command invoker carries the attributes of the identity its command
432
+ // names (`commandfor` + `command="--toast-success"` → toaster): that script
433
+ // reads them off the invoker.
434
+ const command = node.getAttribute("commandfor") === null ? "" : node.getAttribute("command");
435
+ const commandRoot = command?.startsWith("--") ? command.slice(2).split("-")[0] : "";
436
+ const byLength = [...context.identities].sort((a, b) => b.length - a.length);
437
+ for (const attribute of node.getAttributeNames()) {
438
+ if (
439
+ !attribute.startsWith("data-") ||
440
+ attribute.startsWith("data-ui") ||
441
+ attribute.startsWith("data-debug")
442
+ )
443
+ continue;
444
+ if (attribute.endsWith("-slot") || attribute.endsWith("-state")) continue;
445
+ const owner = byLength.find((name) => attribute.startsWith(`data-${name}-`));
446
+ if (!owner || (commandRoot && owner.startsWith(commandRoot))) continue;
447
+ const root = owner.split("-")[0]!;
448
+ if (
449
+ !node.withinIdentity(root, context.identities) &&
450
+ node.getAttribute(`data-${root}`) === null
451
+ ) {
452
+ found.push({
453
+ rule: "attribute-outside-identity",
454
+ message: `\`${attribute}\` belongs to ${owner}, but neither this element nor an ancestor carries it in \`data-ui\`.`,
455
+ attribute,
456
+ });
457
+ }
458
+ }
459
+ return found;
460
+ }
461
+
462
+ export interface PersistFinding<T> {
463
+ el: T;
464
+ rule: "persist";
465
+ message: string;
466
+ }
467
+
468
+ /** The persisted element that already carries another one (`self`: it is that element). */
469
+ export interface PersistOwner {
470
+ id: string;
471
+ self: boolean;
472
+ }
473
+
474
+ /**
475
+ * Checks `data-ui-persist` (or `data-ui-persist-scroll`) elements, in document
476
+ * order: each needs the swap opt-in, an id, a unique id, and no `data-ui-persist`
477
+ * element that already carries it (`ownerOf`: an ancestor, or for
478
+ * `data-ui-persist-scroll` the element itself). Returns the elements that work
479
+ * and the findings.
480
+ */
481
+ export function auditPersistence<T>(
482
+ swap: boolean,
483
+ persisted: T[],
484
+ idOf: (el: T) => string,
485
+ ownerOf: (el: T) => PersistOwner | null,
486
+ attribute: "data-ui-persist" | "data-ui-persist-scroll" = "data-ui-persist",
487
+ ): { kept: T[]; warnings: PersistFinding<T>[] } {
488
+ const warnings: PersistFinding<T>[] = [];
489
+ const warn = (el: T, message: string) => warnings.push({ el, rule: "persist", message });
490
+ const scroll = attribute === "data-ui-persist-scroll";
491
+ const kept: T[] = [];
492
+ if (!swap) {
493
+ for (const el of persisted) {
494
+ warn(
495
+ el,
496
+ `\`${attribute}\` has no effect: this page has no \`<html data-ui-navigation="swap">\`, so every navigation is a full load.`,
497
+ );
498
+ }
499
+ return { kept, warnings };
500
+ }
501
+ const seen = new Set<string>();
502
+ for (const el of persisted) {
503
+ const id = idOf(el);
504
+ if (!id) {
505
+ warn(
506
+ el,
507
+ scroll
508
+ ? "`data-ui-persist-scroll` has no id; its scroll offset is not carried across navigations."
509
+ : "`data-ui-persist` has no id; it is not carried across navigations.",
510
+ );
511
+ continue;
512
+ }
513
+ if (seen.has(id)) {
514
+ warn(
515
+ el,
516
+ `\`${attribute}="${id}"\` is used twice; only the first ${scroll ? "keeps its scroll offset" : "is kept"}.`,
517
+ );
518
+ continue;
519
+ }
520
+ seen.add(id);
521
+ const owner = ownerOf(el);
522
+ if (owner) {
523
+ const where = owner.self ? "is on" : "sits inside";
524
+ warn(
525
+ el,
526
+ scroll
527
+ ? `\`data-ui-persist-scroll="${id}"\` ${where} \`data-ui-persist="${owner.id}"\`, which already keeps its scroll offset; drop \`data-ui-persist-scroll\`.`
528
+ : `\`data-ui-persist="${id}"\` sits inside \`data-ui-persist="${owner.id}"\`, which already keeps it; drop the inner one.`,
529
+ );
530
+ continue;
531
+ }
532
+ kept.push(el);
533
+ }
534
+ return { kept, warnings };
535
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @fileoverview `<ui-debug>`: audits utilities in `style` attributes.
3
+ * @description Development only. On a listed domain the element walks every
4
+ * element once, and again on mutation, and warns about the mistakes the
5
+ * generated gates cannot report: an unknown utility, a wrong mode, a tier without
6
+ * a base, a modifier the family lacks, a base utility that flattens a state a
7
+ * primitive's hook covers, a raw property shadowing a utility, a
8
+ * whitespace form the gates cannot match, and a `data-<name>-*` attribute
9
+ * outside its identity. On an unlisted domain it removes itself and logs
10
+ * {@link DEBUG_WARNING} once. Identities and hooks are read from the page's
11
+ * stylesheets, so the audit needs no manifest. The checks live in
12
+ * `audit-core.ts`, which the html lint rules (`@zazz-ui/eslint-plugin`) share.
13
+ * @example
14
+ * <ui-debug data-debug-domains="localhost, staging.example.com"></ui-debug>
15
+ */
16
+ import { ZazzElement } from "../../base/zazz-element.ts";
17
+ import { type RuleId } from "./audit-core.ts";
18
+ export interface Warning {
19
+ el: Element;
20
+ message: string;
21
+ rule: RuleId;
22
+ }
23
+ export interface AuditOptions {
24
+ /** State-bearing hooks per identity as `<utility>--<state>` (`bg--hover`); default: the page's stylesheets. */
25
+ hooks?: Record<string, string[]>;
26
+ /** Identity tokens the kit declares (`button`, `field-group`); default: the page's stylesheets. */
27
+ identities?: string[];
28
+ }
29
+ /** Audits every element under `root` (inclusive) and returns the findings. */
30
+ export declare function audit(root: Element, options?: AuditOptions): Warning[];
31
+ export interface Note {
32
+ message: string;
33
+ elements: Element[];
34
+ }
35
+ /**
36
+ * Calls out what survives an in-page navigation: on a `data-ui-navigation="swap"`
37
+ * page, which `data-ui-persist` elements are kept and which
38
+ * `data-ui-persist-scroll` elements carry their scroll offset; warnings for
39
+ * persistence that cannot work as written.
40
+ */
41
+ export declare function navigationReport(doc: Document): {
42
+ notes: Note[];
43
+ warnings: Warning[];
44
+ };
45
+ export declare 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\".";
46
+ declare class UiDebug extends ZazzElement {
47
+ protected setup(signal: AbortSignal): void;
48
+ }
49
+ export { UiDebug };
50
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["debug.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAAW,EAAqB,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAKL,KAAK,MAAM,EACZ,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,+GAA+G;IAC/G,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACjC,mGAAmG;IACnG,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AA0CD,8EAA8E;AAC9E,wBAAgB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,EAAE,CAc1E;AAED,MAAM,WAAW,IAAI;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,QAAQ,GAAG;IAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAAC,QAAQ,EAAE,OAAO,EAAE,CAAA;CAAE,CAyCtF;AAED,eAAO,MAAM,aAAa,8KACiJ,CAAC;AAI5K,cAAM,OAAQ,SAAQ,WAAW;IAC/B,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAgDzC;CACF;AAID,OAAO,EAAE,OAAO,EAAE,CAAC"}