@zazz-ui/core 0.15.1 → 0.16.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 (247) hide show
  1. package/AUTHORING.md +29 -14
  2. package/CHANGELOG.md +156 -0
  3. package/README.md +6 -5
  4. package/dist/{csp-LRx1fynI.js → csp-C1f62vyT.js} +1 -1
  5. package/dist/sri.json +70 -65
  6. package/dist/zazz.css +1 -1
  7. package/dist/zazz.js +1 -1
  8. package/editor/zazz.css-data.json +74 -2
  9. package/editor/zazz.html-data.json +119 -79
  10. package/editor/zazz.language-data.json +401 -313
  11. package/editor/zazz.lint-data.json +1752 -1731
  12. package/package.json +2 -1
  13. package/src/base/_defaults.css +11 -11
  14. package/src/base/_reset.css +2 -10
  15. package/src/base/_typography.css +17 -568
  16. package/src/base/_utilities-box.css +17 -17
  17. package/src/base/_utilities-pseudo.css +2 -2
  18. package/src/base/_variables.css +142 -97
  19. package/src/base/carousel-scroll.d.ts +1 -1
  20. package/src/base/carousel-scroll.js +6 -6
  21. package/src/base/carousel-scroll.ts +6 -6
  22. package/src/base/carousel.d.ts.map +1 -1
  23. package/src/base/carousel.js +6 -2
  24. package/src/base/carousel.ts +6 -2
  25. package/src/base/csp.js +2 -2
  26. package/src/base/csp.ts +2 -2
  27. package/src/base/kit-styling.d.ts.map +1 -1
  28. package/src/base/kit-styling.js +186 -183
  29. package/src/base/kit-styling.ts +186 -183
  30. package/src/base/navigation.d.ts +2 -2
  31. package/src/base/navigation.d.ts.map +1 -1
  32. package/src/base/navigation.js +25 -21
  33. package/src/base/navigation.ts +27 -21
  34. package/src/base/utilities.d.ts +1 -1
  35. package/src/base/utilities.d.ts.map +1 -1
  36. package/src/base/utilities.js +20 -4
  37. package/src/base/utilities.ts +21 -5
  38. package/src/base/zazz-element.d.ts +1 -1
  39. package/src/base/zazz-element.js +1 -1
  40. package/src/base/zazz-element.ts +1 -1
  41. package/src/{base → behaviors}/gesture.d.ts +4 -3
  42. package/src/behaviors/gesture.d.ts.map +1 -0
  43. package/src/{base → behaviors}/gesture.js +1 -1
  44. package/src/{base → behaviors}/gesture.ts +5 -4
  45. package/src/{base → behaviors}/hotkeys.d.ts +2 -1
  46. package/src/behaviors/hotkeys.d.ts.map +1 -0
  47. package/src/{base → behaviors}/hotkeys.ts +2 -1
  48. package/src/behaviors/list-navigation.d.ts +64 -0
  49. package/src/behaviors/list-navigation.d.ts.map +1 -0
  50. package/src/behaviors/list-navigation.js +66 -0
  51. package/src/behaviors/list-navigation.ts +107 -0
  52. package/src/{base → behaviors}/typeahead.d.ts +3 -1
  53. package/src/behaviors/typeahead.d.ts.map +1 -0
  54. package/src/{base → behaviors}/typeahead.js +12 -17
  55. package/src/{base → behaviors}/typeahead.ts +12 -17
  56. package/src/css-properties.json +704 -0
  57. package/src/index.css +7 -0
  58. package/src/manifest.d.ts +20 -9
  59. package/src/manifest.d.ts.map +1 -1
  60. package/src/manifest.js +125 -37
  61. package/src/manifest.ts +132 -38
  62. package/src/primitives/accordion/accordion.json +49 -0
  63. package/src/primitives/alert-dialog/alert-dialog.json +35 -0
  64. package/src/primitives/autocomplete/autocomplete.d.ts +2 -2
  65. package/src/primitives/autocomplete/autocomplete.d.ts.map +1 -1
  66. package/src/primitives/autocomplete/autocomplete.js +2 -2
  67. package/src/primitives/autocomplete/autocomplete.json +65 -0
  68. package/src/primitives/autocomplete/autocomplete.ts +2 -2
  69. package/src/primitives/avatar/avatar.css +108 -0
  70. package/src/primitives/avatar/avatar.html +20 -74
  71. package/src/primitives/avatar/avatar.json +48 -0
  72. package/src/primitives/badge/badge.css +45 -10
  73. package/src/primitives/badge/badge.html +4 -0
  74. package/src/primitives/badge/badge.json +83 -0
  75. package/src/primitives/breadcrumbs/breadcrumbs.json +20 -0
  76. package/src/primitives/button/button.css +50 -66
  77. package/src/primitives/button/button.html +4 -0
  78. package/src/primitives/button/button.json +85 -0
  79. package/src/primitives/button-group/button-group.css +4 -15
  80. package/src/primitives/button-group/button-group.json +40 -0
  81. package/src/primitives/callout/callout.css +1 -1
  82. package/src/primitives/callout/callout.html +12 -12
  83. package/src/primitives/callout/callout.json +54 -0
  84. package/src/primitives/card/card-article.html +13 -37
  85. package/src/primitives/card/card-horizontal.html +11 -14
  86. package/src/primitives/card/card-login.html +4 -4
  87. package/src/primitives/card/card-product.html +3 -3
  88. package/src/primitives/card/card-subgrid.html +4 -4
  89. package/src/primitives/card/card.css +1 -1
  90. package/src/primitives/card/card.html +8 -8
  91. package/src/primitives/card/card.json +73 -0
  92. package/src/primitives/carousel/carousel.css +1 -1
  93. package/src/primitives/carousel/carousel.json +89 -0
  94. package/src/primitives/checkbox/checkbox.css +1 -2
  95. package/src/primitives/checkbox/checkbox.json +51 -0
  96. package/src/primitives/combobox/combobox.css +3 -2
  97. package/src/primitives/combobox/combobox.d.ts +2 -2
  98. package/src/primitives/combobox/combobox.d.ts.map +1 -1
  99. package/src/primitives/combobox/combobox.js +2 -2
  100. package/src/primitives/combobox/combobox.json +113 -0
  101. package/src/primitives/combobox/combobox.ts +2 -2
  102. package/src/primitives/command/command-actions.html +1 -1
  103. package/src/primitives/command/command.d.ts +4 -3
  104. package/src/primitives/command/command.d.ts.map +1 -1
  105. package/src/primitives/command/command.js +7 -6
  106. package/src/primitives/command/command.json +86 -0
  107. package/src/primitives/command/command.ts +7 -6
  108. package/src/primitives/debug/audit-core.d.ts +19 -12
  109. package/src/primitives/debug/audit-core.d.ts.map +1 -1
  110. package/src/primitives/debug/audit-core.js +78 -16
  111. package/src/primitives/debug/audit-core.ts +94 -22
  112. package/src/primitives/debug/debug.d.ts +6 -4
  113. package/src/primitives/debug/debug.d.ts.map +1 -1
  114. package/src/primitives/debug/debug.js +50 -21
  115. package/src/primitives/debug/debug.json +29 -0
  116. package/src/primitives/debug/debug.ts +57 -35
  117. package/src/primitives/dialog/dialog.css +1 -4
  118. package/src/primitives/dialog/dialog.json +78 -0
  119. package/src/primitives/drawer/drawer.css +4 -2
  120. package/src/primitives/drawer/drawer.d.ts.map +1 -1
  121. package/src/primitives/drawer/drawer.js +76 -4
  122. package/src/primitives/drawer/drawer.json +98 -0
  123. package/src/primitives/drawer/drawer.ts +78 -5
  124. package/src/primitives/fields/fields.css +11 -4
  125. package/src/primitives/fields/fields.json +92 -0
  126. package/src/primitives/font/font.css +188 -0
  127. package/src/primitives/font/font.html +14 -0
  128. package/src/primitives/font/font.json +39 -0
  129. package/src/primitives/group/group.json +25 -0
  130. package/src/primitives/input/input.css +1 -2
  131. package/src/primitives/input/input.json +56 -0
  132. package/src/primitives/input-group/input-group-password-group.html +1 -1
  133. package/src/primitives/input-group/input-group.css +32 -3
  134. package/src/primitives/input-group/input-group.html +5 -8
  135. package/src/primitives/input-group/input-group.json +69 -0
  136. package/src/primitives/kbd/kbd.css +1 -1
  137. package/src/primitives/kbd/kbd.json +52 -0
  138. package/src/primitives/layout/layout.json +45 -0
  139. package/src/primitives/lightbox/lightbox.css +4 -3
  140. package/src/primitives/lightbox/lightbox.html +2 -2
  141. package/src/primitives/lightbox/lightbox.js +1 -1
  142. package/src/primitives/lightbox/lightbox.json +87 -0
  143. package/src/primitives/lightbox/lightbox.ts +1 -1
  144. package/src/primitives/link/link.css +28 -0
  145. package/src/primitives/link/link.html +5 -0
  146. package/src/primitives/link/link.json +23 -0
  147. package/src/primitives/menu/menu.d.ts +3 -0
  148. package/src/primitives/menu/menu.d.ts.map +1 -1
  149. package/src/primitives/menu/menu.js +10 -25
  150. package/src/primitives/menu/menu.json +51 -0
  151. package/src/primitives/menu/menu.ts +10 -27
  152. package/src/primitives/menubar/menubar.json +23 -0
  153. package/src/primitives/meter/meter.css +24 -3
  154. package/src/primitives/meter/meter.json +41 -0
  155. package/src/primitives/mobile-menu/mobile-menu.html +1 -1
  156. package/src/primitives/mobile-menu/mobile-menu.json +64 -0
  157. package/src/primitives/navigation-menu/navigation-menu-featured.html +58 -58
  158. package/src/primitives/navigation-menu/navigation-menu-megamenu.html +6 -113
  159. package/src/primitives/navigation-menu/navigation-menu.css +11 -5
  160. package/src/primitives/navigation-menu/navigation-menu.html +1 -1
  161. package/src/primitives/navigation-menu/navigation-menu.json +82 -0
  162. package/src/primitives/otp/otp.css +1 -1
  163. package/src/primitives/otp/otp.d.ts +3 -3
  164. package/src/primitives/otp/otp.js +5 -5
  165. package/src/primitives/otp/otp.json +75 -0
  166. package/src/primitives/otp/otp.ts +5 -5
  167. package/src/primitives/password-group/password-group.css +32 -2
  168. package/src/primitives/password-group/password-group.html +1 -1
  169. package/src/primitives/password-group/password-group.json +74 -0
  170. package/src/primitives/popover/popover.css +1 -1
  171. package/src/primitives/popover/popover.json +64 -0
  172. package/src/primitives/progress/progress.css +25 -3
  173. package/src/primitives/progress/progress.json +41 -0
  174. package/src/primitives/prose/prose.css +341 -0
  175. package/src/primitives/prose/prose.html +11 -11
  176. package/src/primitives/prose/prose.json +47 -0
  177. package/src/primitives/radio/radio.css +1 -1
  178. package/src/primitives/radio/radio.json +48 -0
  179. package/src/primitives/reveal/reveal.json +72 -0
  180. package/src/primitives/scroll-fade/scroll-fade.css +0 -3
  181. package/src/primitives/scroll-fade/scroll-fade.json +34 -0
  182. package/src/primitives/select/select.css +2 -2
  183. package/src/primitives/select/select.json +119 -0
  184. package/src/primitives/separator/separator.json +34 -0
  185. package/src/primitives/slider/slider.css +87 -13
  186. package/src/primitives/slider/slider.json +49 -0
  187. package/src/primitives/style-guard/style-guard.js +1 -1
  188. package/src/primitives/style-guard/style-guard.json +22 -0
  189. package/src/primitives/style-guard/style-guard.ts +2 -2
  190. package/src/primitives/switch/switch.css +107 -18
  191. package/src/primitives/switch/switch.json +71 -0
  192. package/src/primitives/table/table.json +74 -0
  193. package/src/primitives/tabs/tabs.css +24 -12
  194. package/src/primitives/tabs/tabs.d.ts +4 -2
  195. package/src/primitives/tabs/tabs.d.ts.map +1 -1
  196. package/src/primitives/tabs/tabs.js +14 -24
  197. package/src/primitives/tabs/tabs.json +94 -0
  198. package/src/primitives/tabs/tabs.ts +14 -26
  199. package/src/primitives/textarea/textarea.css +1 -1
  200. package/src/primitives/textarea/textarea.json +48 -0
  201. package/src/primitives/toaster/toaster.d.ts.map +1 -1
  202. package/src/primitives/toaster/toaster.js +4 -4
  203. package/src/primitives/toaster/toaster.json +101 -0
  204. package/src/primitives/toaster/toaster.ts +5 -5
  205. package/src/primitives/toggle/toggle.css +2 -52
  206. package/src/primitives/toggle/toggle.json +84 -0
  207. package/src/primitives/toggle-group/toggle-group.css +1 -1
  208. package/src/primitives/toggle-group/toggle-group.json +41 -0
  209. package/src/primitives/toolbar/toolbar.json +26 -0
  210. package/src/primitives/tooltip/tooltip.css +1 -1
  211. package/src/primitives/tooltip/tooltip.json +85 -0
  212. package/src/primitives/utilities/aspect-ratio.html +3 -3
  213. package/src/primitives/utilities/basis.html +5 -5
  214. package/src/primitives/utilities/col-span.html +5 -5
  215. package/src/primitives/utilities/compose.html +3 -3
  216. package/src/primitives/utilities/flex-align.html +3 -3
  217. package/src/primitives/utilities/flex-direction.html +8 -8
  218. package/src/primitives/utilities/flex-grow.html +3 -3
  219. package/src/primitives/utilities/flex-reverse.html +8 -8
  220. package/src/primitives/utilities/gallery.html +19 -19
  221. package/src/primitives/utilities/gap.html +12 -12
  222. package/src/primitives/utilities/grid-cols.html +6 -6
  223. package/src/primitives/utilities/grid-responsive.html +9 -9
  224. package/src/primitives/utilities/inline-flex.html +2 -2
  225. package/src/primitives/utilities/margin-auto.html +1 -1
  226. package/src/primitives/utilities/object-fit.html +3 -3
  227. package/src/primitives/utilities/order.html +3 -3
  228. package/src/primitives/utilities/overflow.html +14 -14
  229. package/src/primitives/utilities/padding-compose.html +3 -3
  230. package/src/primitives/utilities/padding.html +4 -4
  231. package/src/primitives/utilities/position.html +1 -1
  232. package/src/primitives/utilities/responsive-flex.html +4 -4
  233. package/src/primitives/utilities/responsive-grid.html +9 -9
  234. package/src/primitives/utilities/size.html +5 -5
  235. package/src/primitives/utilities/subgrid-col.html +7 -7
  236. package/src/primitives/utilities/subgrid-row.html +9 -9
  237. package/src/primitives/utilities/subgrid.html +9 -9
  238. package/src/primitives/utilities/utilities.json +48 -0
  239. package/src/primitives/utilities/width.html +5 -5
  240. package/src/base/gesture.d.ts.map +0 -1
  241. package/src/base/hotkeys.d.ts.map +0 -1
  242. package/src/base/typeahead.d.ts.map +0 -1
  243. /package/src/{base → behaviors}/command-score.d.ts +0 -0
  244. /package/src/{base → behaviors}/command-score.d.ts.map +0 -0
  245. /package/src/{base → behaviors}/command-score.js +0 -0
  246. /package/src/{base → behaviors}/command-score.ts +0 -0
  247. /package/src/{base → behaviors}/hotkeys.js +0 -0
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "command",
3
+ "summary": "command.css: Command (ui-command | [data-ui~=\"command\"], [data-command-slot~=\"panel\"])",
4
+ "identities": [
5
+ "command"
6
+ ],
7
+ "tags": [
8
+ "ui-command"
9
+ ],
10
+ "hooks": {
11
+ "Layout & Positioning": {
12
+ "--ui-command-option-gap": "var(--ui-field-option-gap)"
13
+ },
14
+ "Box Model & Sizing": {
15
+ "--ui-command-footer-p": "calc(var(--spacing) * 2)",
16
+ "--ui-command-group-label-p": "calc(var(--spacing) * 2) calc(var(--spacing) * 2) var(--spacing)",
17
+ "--ui-command-input-p": "calc(var(--spacing) * 3)",
18
+ "--ui-command-max-h": "calc(var(--spacing) * 96)",
19
+ "--ui-command-min-w": "calc(var(--spacing) * 96)"
20
+ },
21
+ "Borders & Outlines": {
22
+ "--ui-command-footer-border": "1px solid var(--color-border)",
23
+ "--ui-command-input-border": "1px solid var(--color-border)"
24
+ },
25
+ "Visual Effects": {
26
+ "--ui-command-shadow": "var(--ui-menu-shadow)"
27
+ }
28
+ },
29
+ "attributes": {
30
+ "data-command-filter": [],
31
+ "data-command-hotkey": [],
32
+ "data-command-keywords": [],
33
+ "data-command-min-length": [],
34
+ "data-command-select-behavior": [],
35
+ "data-command-sort": [],
36
+ "data-command-value": []
37
+ },
38
+ "slots": {
39
+ "data-command-slot": [
40
+ "empty",
41
+ "footer",
42
+ "group",
43
+ "group-label",
44
+ "header",
45
+ "input",
46
+ "item",
47
+ "list",
48
+ "open",
49
+ "panel"
50
+ ]
51
+ },
52
+ "states": {
53
+ "data-command-state": [
54
+ "highlighted"
55
+ ]
56
+ },
57
+ "requires": [
58
+ "popover",
59
+ "button",
60
+ "fields",
61
+ "dialog",
62
+ "menu",
63
+ "select",
64
+ "kbd"
65
+ ],
66
+ "files": {
67
+ "css": [
68
+ "primitives/command/command.css"
69
+ ],
70
+ "js": [
71
+ "primitives/command/command.js",
72
+ "primitives/command/command-actions.js"
73
+ ],
74
+ "base": [
75
+ "behaviors/list-navigation.js",
76
+ "behaviors/command-score.js",
77
+ "behaviors/hotkeys.js",
78
+ "behaviors/typeahead.js"
79
+ ],
80
+ "examples": [
81
+ "primitives/command/command.html",
82
+ "primitives/command/command-dialog.html",
83
+ "primitives/command/command-actions.html"
84
+ ]
85
+ }
86
+ }
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * @fileoverview `<ui-command>`: a command menu for search and quick actions.
5
5
  * @description Light-DOM custom element on the shared typeahead engine
6
- * (`base/typeahead.ts`). The panel (a `popover="auto"`
6
+ * (`behaviors/typeahead.ts`). The panel (a `popover="auto"`
7
7
  * dropdown or a `<dialog data-ui="dialog">`) contains the search input;
8
8
  * items rank by match score and the best match auto-highlights.
9
9
  *
@@ -19,7 +19,8 @@
19
19
  * - `data-command-hotkey` (root): global toggle shortcut, e.g. `"mod+k"`.
20
20
  * - `data-command-hotkey` (item): global accelerator that activates the item, active
21
21
  * while the element is connected (even with the panel closed).
22
- * - `data-command-stay-open` (item): keep the panel open after activation.
22
+ * - `data-command-select-behavior="persist"` (item): keep the panel open after
23
+ * activation (default: close it).
23
24
  * - `data-command-sort="document"` (root): opt out of score ranking (default: score).
24
25
  * - `data-command-filter="none"` (root): opt out of filtering for a list another
25
26
  * source already filtered (a search index); items added later are highlighted
@@ -34,8 +35,8 @@
34
35
  * for your `--command` on its target, or for `zazz:command-select` on the root.
35
36
  */
36
37
 
37
- import { TypeaheadElement } from "../../base/typeahead.ts";
38
- import { bindHotkey } from "../../base/hotkeys.ts";
38
+ import { TypeaheadElement } from "../../behaviors/typeahead.ts";
39
+ import { bindHotkey } from "../../behaviors/hotkeys.ts";
39
40
  import { defineZazzElement } from "../../base/zazz-element.ts";
40
41
 
41
42
  class UiCommand extends TypeaheadElement {
@@ -114,7 +115,7 @@ class UiCommand extends TypeaheadElement {
114
115
 
115
116
  /**
116
117
  * @description Runs one item's activation: optional synthetic click,
117
- * `zazz:command-select`, then close (unless `data-command-stay-open`).
118
+ * `zazz:command-select`, then close (unless `data-command-select-behavior="persist"`).
118
119
  *
119
120
  * @param item - The item to activate.
120
121
  * @param click - Whether to run the native activation via `click()`.
@@ -135,7 +136,7 @@ class UiCommand extends TypeaheadElement {
135
136
  this.#clicking = false;
136
137
  }
137
138
  }
138
- if (!item.hasAttribute("data-command-stay-open")) {
139
+ if (item.getAttribute("data-command-select-behavior") !== "persist") {
139
140
  this.#closePanel();
140
141
  }
141
142
  }
@@ -1,5 +1,5 @@
1
1
  /** A stable name per finding, so a linter can switch each one off. */
2
- export type RuleId = "unknown-utility" | "pseudo-form" | "group-needs-state" | "border-value" | "not-integer" | "tier-unsupported" | "tier-without-base" | "dual-value" | "keyword-number" | "raw-shadows-utility" | "flattens-state" | "gradient-incomplete" | "font-weight-name" | "scroll-state" | "whitespace-before-colon" | "whitespace-after-colon" | "attribute-outside-identity" | "retired-token" | "field-id-or-name" | "persist";
2
+ export type RuleId = "unknown-utility" | "pseudo-form" | "group-needs-state" | "border-value" | "not-integer" | "tier-unsupported" | "tier-without-base" | "dual-value" | "keyword-number" | "raw-shadows-utility" | "flattens-state" | "gradient-incomplete" | "font-weight-name" | "scroll-state" | "whitespace-before-colon" | "whitespace-after-colon" | "attribute-outside-identity" | "retired-token" | "font-role" | "field-id-or-name" | "persist";
3
3
  export declare const RULE_IDS: readonly RuleId[];
4
4
  /** `[start, end)` offsets into the `style` attribute's value. */
5
5
  export type Span = [number, number];
@@ -16,6 +16,11 @@ export interface Finding {
16
16
  /** The attribute the finding is about, when it is not `style`. */
17
17
  attribute?: string;
18
18
  suggestion?: Suggestion;
19
+ /**
20
+ * The attribute values that resolve the finding, when rewriting attributes
21
+ * does it: `null` removes one. `attribute` is among the keys.
22
+ */
23
+ attributes?: Record<string, string | null>;
19
24
  }
20
25
  /** The parts of an element the audit reads. */
21
26
  export interface AuditNode {
@@ -33,6 +38,12 @@ export interface AuditContext {
33
38
  hooks: Record<string, string[]>;
34
39
  /** Identity tokens the kit declares (`button`, `field-group`). */
35
40
  identities: readonly string[];
41
+ /**
42
+ * Typography roles the kit styles, the values of `data-font` (`h3`, `sm`):
43
+ * empty when `font.css` is not loaded, `null` when that cannot be known (a
44
+ * stylesheet the page may not read), which skips the `font-role` rule.
45
+ */
46
+ roles: readonly string[] | null;
36
47
  /** For each utility, the elements the kit reads it on through its own chain, as selectors. */
37
48
  reads: Readonly<Record<string, readonly string[]>>;
38
49
  /** For each tier-only utility, the elements a kit rule above `@layer defaults` sets its property on. */
@@ -55,19 +66,15 @@ export interface PersistFinding<T> {
55
66
  rule: "persist";
56
67
  message: string;
57
68
  }
58
- /** The persisted element that already carries another one (`self`: it is that element). */
59
- export interface PersistOwner {
60
- id: string;
61
- self: boolean;
62
- }
69
+ /** How a `data-navigation-persist` element crosses a swap: carried whole, or only its scroll offset. */
70
+ export type PersistMode = "element" | "scroll";
63
71
  /**
64
- * Checks `data-ui-persist` (or `data-ui-persist-scroll`) elements, in document
65
- * order: each needs the swap opt-in, an id, a unique id, and no `data-ui-persist`
66
- * element that already carries it (`ownerOf`: an ancestor, or for
67
- * `data-ui-persist-scroll` the element itself). Returns the elements that work
68
- * and the findings.
72
+ * Checks the `data-navigation-persist` elements of one mode, in document
73
+ * order: each needs the swap opt-in, an id, a unique id, and no carried
74
+ * element around it (`ownerOf` returns that element's id). Returns the elements
75
+ * that work and the findings.
69
76
  */
70
- export declare function auditPersistence<T>(swap: boolean, persisted: T[], idOf: (el: T) => string, ownerOf: (el: T) => PersistOwner | null, attribute?: "data-ui-persist" | "data-ui-persist-scroll"): {
77
+ export declare function auditPersistence<T>(swap: boolean, persisted: T[], idOf: (el: T) => string, ownerOf: (el: T) => string | null, mode?: PersistMode): {
71
78
  kept: T[];
72
79
  warnings: PersistFinding<T>[];
73
80
  };
@@ -1 +1 @@
1
- {"version":3,"file":"audit-core.d.ts","sourceRoot":"","sources":["audit-core.ts"],"names":[],"mappings":"AA6BA,sEAAsE;AACtE,MAAM,MAAM,MAAM,GACd,iBAAiB,GACjB,aAAa,GACb,mBAAmB,GACnB,cAAc,GACd,aAAa,GACb,kBAAkB,GAClB,mBAAmB,GACnB,YAAY,GACZ,gBAAgB,GAChB,qBAAqB,GACrB,gBAAgB,GAChB,qBAAqB,GACrB,kBAAkB,GAClB,cAAc,GACd,yBAAyB,GACzB,wBAAwB,GACxB,4BAA4B,GAC5B,eAAe,GACf,kBAAkB,GAClB,SAAS,CAAC;AAEd,eAAO,MAAM,QAAQ,EAAE,SAAS,MAAM,EAqBrC,CAAC;AAEF,iEAAiE;AACjE,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEpC,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,+CAA+C;AAC/C,MAAM,WAAW,SAAS;IACxB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG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;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,SAAS,MAAM,EAAE,GAC5B,OAAO,CAOT;AAED,mHAAmH;AACnH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,GAClD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAI1B;AAED,4DAA4D;AAC5D,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,EAAE,CAob3E;AAED,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,EAAE,EAAE,CAAC,CAAC;IACN,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wGAAwG;AACxG,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE/C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,IAAI,EAAE,OAAO,EACb,SAAS,EAAE,CAAC,EAAE,EACd,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,MAAM,EACvB,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,EACjC,IAAI,GAAE,WAAuB,GAC5B;IAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAA;CAAE,CA6C9C"}
@@ -27,6 +27,7 @@ export const RULE_IDS = [
27
27
  "whitespace-after-colon",
28
28
  "attribute-outside-identity",
29
29
  "retired-token",
30
+ "font-role",
30
31
  "field-id-or-name",
31
32
  "persist",
32
33
  ];
@@ -39,6 +40,59 @@ const BUTTON_TYPES = new Set(["button", "submit", "reset", "image"]);
39
40
  const NUMBER = /^-?(\d+\.?\d*|\.\d+)$/;
40
41
  const DIMENSION = /^-?(\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)$/;
41
42
  const FUNCTION = /^(calc|clamp|min|max|var|env|round|mod|rem|abs|sign)\(/;
43
+ /** A typography role from before `data-font`, as a `data-ui` token (`text-sm`, `text-link`). */
44
+ const RETIRED_ROLE = /^text-/;
45
+ /**
46
+ * The attributes that replace an element's retired `text-*` tokens: the role
47
+ * moves to `data-font`, `text-link` becomes the `link` identity, and `data-ui`
48
+ * goes when nothing is left in it. None when the element already has a
49
+ * `data-font`, carries two roles, or has template syntax among its tokens
50
+ * (`{{ size }}`): the author picks.
51
+ */
52
+ function retiredRoleRewrite(tokens, hasFont) {
53
+ const retired = tokens.filter((token) => RETIRED_ROLE.test(token) && RETIRED_TOKENS[token]);
54
+ const roles = retired.filter((token) => token !== "text-link").map((token) => token.slice(5));
55
+ if (!retired.length || roles.length > 1 || (roles.length && hasFont))
56
+ return undefined;
57
+ if (!tokens.every((token) => /^[\w-]+$/.test(token)))
58
+ return undefined;
59
+ const rest = tokens
60
+ .filter((token) => !retired.includes(token) || token === "text-link")
61
+ .map((token) => (token === "text-link" ? "link" : token));
62
+ return {
63
+ "data-ui": rest.length ? rest.join(" ") : null,
64
+ ...(roles.length ? { "data-font": roles[0] } : {}),
65
+ };
66
+ }
67
+ /** The order the roles are listed in: headings, then body sizes, large to small. */
68
+ const ROLE_ORDER = "display h1 h2 h3 h4 h5 h6 2xl xl lg md sm xs 2xs eyebrow".split(" ");
69
+ /** What is wrong with a `data-font` value, or nothing when it is one role the kit styles. */
70
+ function fontRoleMessage(value, known) {
71
+ const given = value.split(/\s+/).filter(Boolean);
72
+ if (!known.length) {
73
+ return "`data-font` does nothing here: the page has not loaded `primitives/font/font.css`.";
74
+ }
75
+ // largest first, as the scale runs; a role the order does not know goes last
76
+ const rank = (role) => ROLE_ORDER.indexOf(role) + 1 || ROLE_ORDER.length + 1;
77
+ const roles = [...known].sort((a, b) => rank(a) - rank(b));
78
+ const list = roles.map((role) => `\`${role}\``).join(", ");
79
+ if (!given.length)
80
+ return `\`data-font\` needs a role: ${list}.`;
81
+ if (given.length > 1) {
82
+ return `\`data-font\` takes one role, and \`${given.join(" ")}\` is ${given.length}; the attribute is matched whole, so none applies.`;
83
+ }
84
+ const [role] = given;
85
+ if (roles.includes(role))
86
+ return undefined;
87
+ if (role === "link" || role === "text-link") {
88
+ return `\`data-font="${role}"\` is not a typography role. A link is an identity: \`data-ui="link"\`.`;
89
+ }
90
+ const bare = role.replace(/^text-/, "");
91
+ if (bare !== role && roles.includes(bare)) {
92
+ return `\`data-font="${role}"\` is not a typography role. Write \`data-font="${bare}"\`.`;
93
+ }
94
+ return `\`data-font="${role}"\` is not a typography role. The roles are ${list}.`;
95
+ }
42
96
  /**
43
97
  * True when the kit matches `value` as text (`[style*="--w: auto"]`): a
44
98
  * keyword, a token by name, a `--display` shorthand, `none` on `--bg`, or
@@ -151,16 +205,28 @@ export function auditNode(node, context) {
151
205
  bases.add((parsed.side ? `${parsed.side}-` : "") + parsed.name);
152
206
  }
153
207
  const tokens = (node.getAttribute("data-ui") ?? "").split(/\s+/).filter(Boolean);
208
+ // one rewrite moves every retired text-* token on the element; the first finding carries it
209
+ let roleRewrite = retiredRoleRewrite(tokens, node.getAttribute("data-font") !== null);
154
210
  for (const token of tokens) {
155
211
  const replacement = RETIRED_TOKENS[token];
156
212
  if (replacement) {
213
+ const attributes = RETIRED_ROLE.test(token) ? roleRewrite : undefined;
214
+ if (attributes)
215
+ roleRewrite = undefined;
157
216
  found.push({
158
217
  rule: "retired-token",
159
218
  message: `\`data-ui="${token}"\` is gone: \`data-ui\` holds identities only. Use ${replacement}.`,
160
219
  attribute: "data-ui",
220
+ ...(attributes ? { attributes } : {}),
161
221
  });
162
222
  }
163
223
  }
224
+ const font = node.getAttribute("data-font");
225
+ if (font !== null && context.roles) {
226
+ const message = fontRoleMessage(font, context.roles);
227
+ if (message)
228
+ found.push({ rule: "font-role", message, attribute: "data-font" });
229
+ }
164
230
  const sticky = parsedPairs.some(([parsed, , declaration]) => parsed.name === STUCK_STATE.modifier ||
165
231
  (parsed.name === "position" && declaration.value === "sticky"));
166
232
  for (const [parsed, name, declaration] of parsedPairs) {
@@ -469,20 +535,19 @@ export function auditNode(node, context) {
469
535
  return found;
470
536
  }
471
537
  /**
472
- * Checks `data-ui-persist` (or `data-ui-persist-scroll`) elements, in document
473
- * order: each needs the swap opt-in, an id, a unique id, and no `data-ui-persist`
474
- * element that already carries it (`ownerOf`: an ancestor, or for
475
- * `data-ui-persist-scroll` the element itself). Returns the elements that work
476
- * and the findings.
538
+ * Checks the `data-navigation-persist` elements of one mode, in document
539
+ * order: each needs the swap opt-in, an id, a unique id, and no carried
540
+ * element around it (`ownerOf` returns that element's id). Returns the elements
541
+ * that work and the findings.
477
542
  */
478
- export function auditPersistence(swap, persisted, idOf, ownerOf, attribute = "data-ui-persist") {
543
+ export function auditPersistence(swap, persisted, idOf, ownerOf, mode = "element") {
479
544
  const warnings = [];
480
545
  const warn = (el, message) => warnings.push({ el, rule: "persist", message });
481
- const scroll = attribute === "data-ui-persist-scroll";
546
+ const scroll = mode === "scroll";
482
547
  const kept = [];
483
548
  if (!swap) {
484
549
  for (const el of persisted) {
485
- warn(el, `\`${attribute}\` has no effect: this page has no \`<html data-ui-navigation="swap">\`, so every navigation is a full load.`);
550
+ warn(el, `\`${scroll && !idOf(el) ? "data-navigation-persist-mode" : "data-navigation-persist"}\` has no effect: this page has no \`<html data-navigation="swap">\`, so every navigation is a full load.`);
486
551
  }
487
552
  return { kept, warnings };
488
553
  }
@@ -491,21 +556,18 @@ export function auditPersistence(swap, persisted, idOf, ownerOf, attribute = "da
491
556
  const id = idOf(el);
492
557
  if (!id) {
493
558
  warn(el, scroll
494
- ? "`data-ui-persist-scroll` has no id; its scroll offset is not carried across navigations."
495
- : "`data-ui-persist` has no id; it is not carried across navigations.");
559
+ ? '`data-navigation-persist-mode="scroll"` has no `data-navigation-persist` id; its scroll offset is not carried across navigations.'
560
+ : "`data-navigation-persist` has no id; it is not carried across navigations.");
496
561
  continue;
497
562
  }
498
563
  if (seen.has(id)) {
499
- warn(el, `\`${attribute}="${id}"\` is used twice; only the first ${scroll ? "keeps its scroll offset" : "is kept"}.`);
564
+ warn(el, `\`data-navigation-persist="${id}"\` is used twice; only the first ${scroll ? "keeps its scroll offset" : "is kept"}.`);
500
565
  continue;
501
566
  }
502
567
  seen.add(id);
503
568
  const owner = ownerOf(el);
504
- if (owner) {
505
- const where = owner.self ? "is on" : "sits inside";
506
- warn(el, scroll
507
- ? `\`data-ui-persist-scroll="${id}"\` ${where} \`data-ui-persist="${owner.id}"\`, which already keeps its scroll offset; drop \`data-ui-persist-scroll\`.`
508
- : `\`data-ui-persist="${id}"\` sits inside \`data-ui-persist="${owner.id}"\`, which already keeps it; drop the inner one.`);
569
+ if (owner !== null) {
570
+ warn(el, `\`data-navigation-persist="${id}"\` sits inside \`data-navigation-persist="${owner}"\`, which already keeps ${scroll ? "its scroll offset" : "it"}; drop the inner one.`);
509
571
  continue;
510
572
  }
511
573
  kept.push(el);
@@ -47,6 +47,7 @@ export type RuleId =
47
47
  | "whitespace-after-colon"
48
48
  | "attribute-outside-identity"
49
49
  | "retired-token"
50
+ | "font-role"
50
51
  | "field-id-or-name"
51
52
  | "persist";
52
53
 
@@ -69,6 +70,7 @@ export const RULE_IDS: readonly RuleId[] = [
69
70
  "whitespace-after-colon",
70
71
  "attribute-outside-identity",
71
72
  "retired-token",
73
+ "font-role",
72
74
  "field-id-or-name",
73
75
  "persist",
74
76
  ];
@@ -90,6 +92,11 @@ export interface Finding {
90
92
  /** The attribute the finding is about, when it is not `style`. */
91
93
  attribute?: string;
92
94
  suggestion?: Suggestion;
95
+ /**
96
+ * The attribute values that resolve the finding, when rewriting attributes
97
+ * does it: `null` removes one. `attribute` is among the keys.
98
+ */
99
+ attributes?: Record<string, string | null>;
93
100
  }
94
101
 
95
102
  /** The parts of an element the audit reads. */
@@ -109,6 +116,12 @@ export interface AuditContext {
109
116
  hooks: Record<string, string[]>;
110
117
  /** Identity tokens the kit declares (`button`, `field-group`). */
111
118
  identities: readonly string[];
119
+ /**
120
+ * Typography roles the kit styles, the values of `data-font` (`h3`, `sm`):
121
+ * empty when `font.css` is not loaded, `null` when that cannot be known (a
122
+ * stylesheet the page may not read), which skips the `font-role` rule.
123
+ */
124
+ roles: readonly string[] | null;
112
125
  /** For each utility, the elements the kit reads it on through its own chain, as selectors. */
113
126
  reads: Readonly<Record<string, readonly string[]>>;
114
127
  /** For each tier-only utility, the elements a kit rule above `@layer defaults` sets its property on. */
@@ -132,6 +145,62 @@ const DIMENSION =
132
145
  /^-?(\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)$/;
133
146
  const FUNCTION = /^(calc|clamp|min|max|var|env|round|mod|rem|abs|sign)\(/;
134
147
 
148
+ /** A typography role from before `data-font`, as a `data-ui` token (`text-sm`, `text-link`). */
149
+ const RETIRED_ROLE = /^text-/;
150
+
151
+ /**
152
+ * The attributes that replace an element's retired `text-*` tokens: the role
153
+ * moves to `data-font`, `text-link` becomes the `link` identity, and `data-ui`
154
+ * goes when nothing is left in it. None when the element already has a
155
+ * `data-font`, carries two roles, or has template syntax among its tokens
156
+ * (`{{ size }}`): the author picks.
157
+ */
158
+ function retiredRoleRewrite(
159
+ tokens: readonly string[],
160
+ hasFont: boolean,
161
+ ): Record<string, string | null> | undefined {
162
+ const retired = tokens.filter((token) => RETIRED_ROLE.test(token) && RETIRED_TOKENS[token]);
163
+ const roles = retired.filter((token) => token !== "text-link").map((token) => token.slice(5));
164
+ if (!retired.length || roles.length > 1 || (roles.length && hasFont)) return undefined;
165
+ if (!tokens.every((token) => /^[\w-]+$/.test(token))) return undefined;
166
+ const rest = tokens
167
+ .filter((token) => !retired.includes(token) || token === "text-link")
168
+ .map((token) => (token === "text-link" ? "link" : token));
169
+ return {
170
+ "data-ui": rest.length ? rest.join(" ") : null,
171
+ ...(roles.length ? { "data-font": roles[0]! } : {}),
172
+ };
173
+ }
174
+
175
+ /** The order the roles are listed in: headings, then body sizes, large to small. */
176
+ const ROLE_ORDER = "display h1 h2 h3 h4 h5 h6 2xl xl lg md sm xs 2xs eyebrow".split(" ");
177
+
178
+ /** What is wrong with a `data-font` value, or nothing when it is one role the kit styles. */
179
+ function fontRoleMessage(value: string, known: readonly string[]): string | undefined {
180
+ const given = value.split(/\s+/).filter(Boolean);
181
+ if (!known.length) {
182
+ return "`data-font` does nothing here: the page has not loaded `primitives/font/font.css`.";
183
+ }
184
+ // largest first, as the scale runs; a role the order does not know goes last
185
+ const rank = (role: string) => ROLE_ORDER.indexOf(role) + 1 || ROLE_ORDER.length + 1;
186
+ const roles = [...known].sort((a, b) => rank(a) - rank(b));
187
+ const list = roles.map((role) => `\`${role}\``).join(", ");
188
+ if (!given.length) return `\`data-font\` needs a role: ${list}.`;
189
+ if (given.length > 1) {
190
+ return `\`data-font\` takes one role, and \`${given.join(" ")}\` is ${given.length}; the attribute is matched whole, so none applies.`;
191
+ }
192
+ const [role] = given as [string];
193
+ if (roles.includes(role)) return undefined;
194
+ if (role === "link" || role === "text-link") {
195
+ return `\`data-font="${role}"\` is not a typography role. A link is an identity: \`data-ui="link"\`.`;
196
+ }
197
+ const bare = role.replace(/^text-/, "");
198
+ if (bare !== role && roles.includes(bare)) {
199
+ return `\`data-font="${role}"\` is not a typography role. Write \`data-font="${bare}"\`.`;
200
+ }
201
+ return `\`data-font="${role}"\` is not a typography role. The roles are ${list}.`;
202
+ }
203
+
135
204
  interface Declaration {
136
205
  /** The name as written; its whitespace is a finding. */
137
206
  name: string;
@@ -270,16 +339,26 @@ export function auditNode(node: AuditNode, context: AuditContext): Finding[] {
270
339
  if (!parsed.tier) bases.add((parsed.side ? `${parsed.side}-` : "") + parsed.name);
271
340
  }
272
341
  const tokens = (node.getAttribute("data-ui") ?? "").split(/\s+/).filter(Boolean);
342
+ // one rewrite moves every retired text-* token on the element; the first finding carries it
343
+ let roleRewrite = retiredRoleRewrite(tokens, node.getAttribute("data-font") !== null);
273
344
  for (const token of tokens) {
274
345
  const replacement = RETIRED_TOKENS[token];
275
346
  if (replacement) {
347
+ const attributes = RETIRED_ROLE.test(token) ? roleRewrite : undefined;
348
+ if (attributes) roleRewrite = undefined;
276
349
  found.push({
277
350
  rule: "retired-token",
278
351
  message: `\`data-ui="${token}"\` is gone: \`data-ui\` holds identities only. Use ${replacement}.`,
279
352
  attribute: "data-ui",
353
+ ...(attributes ? { attributes } : {}),
280
354
  });
281
355
  }
282
356
  }
357
+ const font = node.getAttribute("data-font");
358
+ if (font !== null && context.roles) {
359
+ const message = fontRoleMessage(font, context.roles);
360
+ if (message) found.push({ rule: "font-role", message, attribute: "data-font" });
361
+ }
283
362
  const sticky = parsedPairs.some(
284
363
  ([parsed, , declaration]) =>
285
364
  parsed.name === STUCK_STATE.modifier ||
@@ -674,35 +753,31 @@ export interface PersistFinding<T> {
674
753
  message: string;
675
754
  }
676
755
 
677
- /** The persisted element that already carries another one (`self`: it is that element). */
678
- export interface PersistOwner {
679
- id: string;
680
- self: boolean;
681
- }
756
+ /** How a `data-navigation-persist` element crosses a swap: carried whole, or only its scroll offset. */
757
+ export type PersistMode = "element" | "scroll";
682
758
 
683
759
  /**
684
- * Checks `data-ui-persist` (or `data-ui-persist-scroll`) elements, in document
685
- * order: each needs the swap opt-in, an id, a unique id, and no `data-ui-persist`
686
- * element that already carries it (`ownerOf`: an ancestor, or for
687
- * `data-ui-persist-scroll` the element itself). Returns the elements that work
688
- * and the findings.
760
+ * Checks the `data-navigation-persist` elements of one mode, in document
761
+ * order: each needs the swap opt-in, an id, a unique id, and no carried
762
+ * element around it (`ownerOf` returns that element's id). Returns the elements
763
+ * that work and the findings.
689
764
  */
690
765
  export function auditPersistence<T>(
691
766
  swap: boolean,
692
767
  persisted: T[],
693
768
  idOf: (el: T) => string,
694
- ownerOf: (el: T) => PersistOwner | null,
695
- attribute: "data-ui-persist" | "data-ui-persist-scroll" = "data-ui-persist",
769
+ ownerOf: (el: T) => string | null,
770
+ mode: PersistMode = "element",
696
771
  ): { kept: T[]; warnings: PersistFinding<T>[] } {
697
772
  const warnings: PersistFinding<T>[] = [];
698
773
  const warn = (el: T, message: string) => warnings.push({ el, rule: "persist", message });
699
- const scroll = attribute === "data-ui-persist-scroll";
774
+ const scroll = mode === "scroll";
700
775
  const kept: T[] = [];
701
776
  if (!swap) {
702
777
  for (const el of persisted) {
703
778
  warn(
704
779
  el,
705
- `\`${attribute}\` has no effect: this page has no \`<html data-ui-navigation="swap">\`, so every navigation is a full load.`,
780
+ `\`${scroll && !idOf(el) ? "data-navigation-persist-mode" : "data-navigation-persist"}\` has no effect: this page has no \`<html data-navigation="swap">\`, so every navigation is a full load.`,
706
781
  );
707
782
  }
708
783
  return { kept, warnings };
@@ -714,27 +789,24 @@ export function auditPersistence<T>(
714
789
  warn(
715
790
  el,
716
791
  scroll
717
- ? "`data-ui-persist-scroll` has no id; its scroll offset is not carried across navigations."
718
- : "`data-ui-persist` has no id; it is not carried across navigations.",
792
+ ? '`data-navigation-persist-mode="scroll"` has no `data-navigation-persist` id; its scroll offset is not carried across navigations.'
793
+ : "`data-navigation-persist` has no id; it is not carried across navigations.",
719
794
  );
720
795
  continue;
721
796
  }
722
797
  if (seen.has(id)) {
723
798
  warn(
724
799
  el,
725
- `\`${attribute}="${id}"\` is used twice; only the first ${scroll ? "keeps its scroll offset" : "is kept"}.`,
800
+ `\`data-navigation-persist="${id}"\` is used twice; only the first ${scroll ? "keeps its scroll offset" : "is kept"}.`,
726
801
  );
727
802
  continue;
728
803
  }
729
804
  seen.add(id);
730
805
  const owner = ownerOf(el);
731
- if (owner) {
732
- const where = owner.self ? "is on" : "sits inside";
806
+ if (owner !== null) {
733
807
  warn(
734
808
  el,
735
- scroll
736
- ? `\`data-ui-persist-scroll="${id}"\` ${where} \`data-ui-persist="${owner.id}"\`, which already keeps its scroll offset; drop \`data-ui-persist-scroll\`.`
737
- : `\`data-ui-persist="${id}"\` sits inside \`data-ui-persist="${owner.id}"\`, which already keeps it; drop the inner one.`,
809
+ `\`data-navigation-persist="${id}"\` sits inside \`data-navigation-persist="${owner}"\`, which already keeps ${scroll ? "its scroll offset" : "it"}; drop the inner one.`,
738
810
  );
739
811
  continue;
740
812
  }
@@ -10,6 +10,8 @@ export interface AuditOptions {
10
10
  hooks?: Record<string, string[]>;
11
11
  /** Identity tokens the kit declares (`button`, `field-group`); default: the page's stylesheets. */
12
12
  identities?: string[];
13
+ /** Typography roles the kit styles (the values of `data-font`), or `null` when unknown; default: the page's stylesheets. */
14
+ roles?: string[] | null;
13
15
  }
14
16
  /** Audits every element under `root` (inclusive) and returns the findings. */
15
17
  export declare function audit(root: Element, options?: AuditOptions): Warning[];
@@ -18,10 +20,10 @@ export interface Note {
18
20
  elements: Element[];
19
21
  }
20
22
  /**
21
- * Calls out what survives an in-page navigation: on a `data-ui-navigation="swap"`
22
- * page, which `data-ui-persist` elements are kept and which
23
- * `data-ui-persist-scroll` elements carry their scroll offset; warnings for
24
- * persistence that cannot work as written.
23
+ * Calls out what survives an in-page navigation: on a `data-navigation="swap"`
24
+ * page, which `data-navigation-persist` elements are kept and which
25
+ * (`data-navigation-persist-mode="scroll"`) carry only their scroll offset;
26
+ * warnings for persistence that cannot work as written.
25
27
  */
26
28
  export declare function navigationReport(doc: Document): {
27
29
  notes: Note[];
@@ -1 +1 @@
1
- {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["debug.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,WAAW,EAAqB,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAML,KAAK,MAAM,EACZ,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WA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