@zazz-ui/core 0.15.0 → 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.
- package/AUTHORING.md +29 -14
- package/CHANGELOG.md +162 -0
- package/README.md +6 -5
- package/dist/{csp-LRx1fynI.js → csp-C1f62vyT.js} +1 -1
- package/dist/sri.json +70 -65
- package/dist/zazz.css +1 -1
- package/dist/zazz.js +1 -1
- package/editor/zazz.css-data.json +74 -2
- package/editor/zazz.html-data.json +119 -79
- package/editor/zazz.language-data.json +402 -314
- package/editor/zazz.lint-data.json +1752 -1731
- package/package.json +2 -1
- package/src/base/_defaults.css +11 -11
- package/src/base/_reset.css +2 -10
- package/src/base/_typography.css +17 -568
- package/src/base/_utilities-box.css +17 -17
- package/src/base/_utilities-pseudo.css +2 -2
- package/src/base/_variables.css +142 -97
- package/src/base/carousel-scroll.d.ts +1 -1
- package/src/base/carousel-scroll.js +6 -6
- package/src/base/carousel-scroll.ts +6 -6
- package/src/base/carousel.d.ts.map +1 -1
- package/src/base/carousel.js +6 -2
- package/src/base/carousel.ts +6 -2
- package/src/base/csp.js +2 -2
- package/src/base/csp.ts +2 -2
- package/src/base/kit-styling.d.ts.map +1 -1
- package/src/base/kit-styling.js +186 -183
- package/src/base/kit-styling.ts +186 -183
- package/src/base/navigation.d.ts +2 -2
- package/src/base/navigation.d.ts.map +1 -1
- package/src/base/navigation.js +25 -21
- package/src/base/navigation.ts +27 -21
- package/src/base/utilities.d.ts +1 -1
- package/src/base/utilities.d.ts.map +1 -1
- package/src/base/utilities.js +20 -4
- package/src/base/utilities.ts +21 -5
- package/src/base/zazz-element.d.ts +1 -1
- package/src/base/zazz-element.js +1 -1
- package/src/base/zazz-element.ts +1 -1
- package/src/{base → behaviors}/gesture.d.ts +4 -3
- package/src/behaviors/gesture.d.ts.map +1 -0
- package/src/{base → behaviors}/gesture.js +1 -1
- package/src/{base → behaviors}/gesture.ts +5 -4
- package/src/{base → behaviors}/hotkeys.d.ts +2 -1
- package/src/behaviors/hotkeys.d.ts.map +1 -0
- package/src/{base → behaviors}/hotkeys.ts +2 -1
- package/src/behaviors/list-navigation.d.ts +64 -0
- package/src/behaviors/list-navigation.d.ts.map +1 -0
- package/src/behaviors/list-navigation.js +66 -0
- package/src/behaviors/list-navigation.ts +107 -0
- package/src/{base → behaviors}/typeahead.d.ts +3 -1
- package/src/behaviors/typeahead.d.ts.map +1 -0
- package/src/{base → behaviors}/typeahead.js +12 -17
- package/src/{base → behaviors}/typeahead.ts +12 -17
- package/src/css-properties.json +704 -0
- package/src/index.css +7 -0
- package/src/manifest.d.ts +20 -9
- package/src/manifest.d.ts.map +1 -1
- package/src/manifest.js +125 -37
- package/src/manifest.ts +132 -38
- package/src/primitives/accordion/accordion.json +49 -0
- package/src/primitives/alert-dialog/alert-dialog.json +35 -0
- package/src/primitives/autocomplete/autocomplete.d.ts +2 -2
- package/src/primitives/autocomplete/autocomplete.d.ts.map +1 -1
- package/src/primitives/autocomplete/autocomplete.js +2 -2
- package/src/primitives/autocomplete/autocomplete.json +65 -0
- package/src/primitives/autocomplete/autocomplete.ts +2 -2
- package/src/primitives/avatar/avatar.css +108 -0
- package/src/primitives/avatar/avatar.html +20 -74
- package/src/primitives/avatar/avatar.json +48 -0
- package/src/primitives/badge/badge.css +45 -10
- package/src/primitives/badge/badge.html +4 -0
- package/src/primitives/badge/badge.json +83 -0
- package/src/primitives/breadcrumbs/breadcrumbs.json +20 -0
- package/src/primitives/button/button.css +50 -66
- package/src/primitives/button/button.html +4 -0
- package/src/primitives/button/button.json +85 -0
- package/src/primitives/button-group/button-group.css +4 -15
- package/src/primitives/button-group/button-group.json +40 -0
- package/src/primitives/callout/callout.css +1 -1
- package/src/primitives/callout/callout.html +12 -12
- package/src/primitives/callout/callout.json +54 -0
- package/src/primitives/card/card-article.html +13 -37
- package/src/primitives/card/card-horizontal.html +11 -14
- package/src/primitives/card/card-login.html +4 -4
- package/src/primitives/card/card-product.html +3 -3
- package/src/primitives/card/card-subgrid.html +4 -4
- package/src/primitives/card/card.css +1 -1
- package/src/primitives/card/card.html +8 -8
- package/src/primitives/card/card.json +73 -0
- package/src/primitives/carousel/carousel.css +1 -1
- package/src/primitives/carousel/carousel.json +89 -0
- package/src/primitives/checkbox/checkbox.css +1 -2
- package/src/primitives/checkbox/checkbox.json +51 -0
- package/src/primitives/combobox/combobox.css +3 -2
- package/src/primitives/combobox/combobox.d.ts +2 -2
- package/src/primitives/combobox/combobox.d.ts.map +1 -1
- package/src/primitives/combobox/combobox.js +2 -2
- package/src/primitives/combobox/combobox.json +113 -0
- package/src/primitives/combobox/combobox.ts +2 -2
- package/src/primitives/command/command-actions.html +1 -1
- package/src/primitives/command/command.d.ts +4 -3
- package/src/primitives/command/command.d.ts.map +1 -1
- package/src/primitives/command/command.js +7 -6
- package/src/primitives/command/command.json +86 -0
- package/src/primitives/command/command.ts +7 -6
- package/src/primitives/debug/audit-core.d.ts +19 -12
- package/src/primitives/debug/audit-core.d.ts.map +1 -1
- package/src/primitives/debug/audit-core.js +78 -16
- package/src/primitives/debug/audit-core.ts +94 -22
- package/src/primitives/debug/debug.d.ts +6 -4
- package/src/primitives/debug/debug.d.ts.map +1 -1
- package/src/primitives/debug/debug.js +50 -21
- package/src/primitives/debug/debug.json +29 -0
- package/src/primitives/debug/debug.ts +57 -35
- package/src/primitives/dialog/dialog.css +1 -4
- package/src/primitives/dialog/dialog.json +78 -0
- package/src/primitives/drawer/drawer.css +4 -2
- package/src/primitives/drawer/drawer.d.ts.map +1 -1
- package/src/primitives/drawer/drawer.js +76 -4
- package/src/primitives/drawer/drawer.json +98 -0
- package/src/primitives/drawer/drawer.ts +78 -5
- package/src/primitives/fields/fields.css +11 -4
- package/src/primitives/fields/fields.json +92 -0
- package/src/primitives/font/font.css +188 -0
- package/src/primitives/font/font.html +14 -0
- package/src/primitives/font/font.json +39 -0
- package/src/primitives/group/group.json +25 -0
- package/src/primitives/input/input.css +1 -2
- package/src/primitives/input/input.json +56 -0
- package/src/primitives/input-group/input-group-password-group.html +1 -1
- package/src/primitives/input-group/input-group.css +32 -3
- package/src/primitives/input-group/input-group.html +5 -8
- package/src/primitives/input-group/input-group.json +69 -0
- package/src/primitives/kbd/kbd.css +1 -1
- package/src/primitives/kbd/kbd.json +52 -0
- package/src/primitives/layout/layout.json +45 -0
- package/src/primitives/lightbox/lightbox.css +4 -3
- package/src/primitives/lightbox/lightbox.html +2 -2
- package/src/primitives/lightbox/lightbox.js +1 -1
- package/src/primitives/lightbox/lightbox.json +87 -0
- package/src/primitives/lightbox/lightbox.ts +1 -1
- package/src/primitives/link/link.css +28 -0
- package/src/primitives/link/link.html +5 -0
- package/src/primitives/link/link.json +23 -0
- package/src/primitives/menu/menu.d.ts +3 -0
- package/src/primitives/menu/menu.d.ts.map +1 -1
- package/src/primitives/menu/menu.js +10 -25
- package/src/primitives/menu/menu.json +51 -0
- package/src/primitives/menu/menu.ts +10 -27
- package/src/primitives/menubar/menubar.json +23 -0
- package/src/primitives/meter/meter.css +24 -3
- package/src/primitives/meter/meter.json +41 -0
- package/src/primitives/mobile-menu/mobile-menu.html +1 -1
- package/src/primitives/mobile-menu/mobile-menu.json +64 -0
- package/src/primitives/navigation-menu/navigation-menu-featured.html +58 -58
- package/src/primitives/navigation-menu/navigation-menu-megamenu.html +6 -113
- package/src/primitives/navigation-menu/navigation-menu.css +11 -5
- package/src/primitives/navigation-menu/navigation-menu.html +1 -1
- package/src/primitives/navigation-menu/navigation-menu.json +82 -0
- package/src/primitives/otp/otp.css +1 -1
- package/src/primitives/otp/otp.d.ts +3 -3
- package/src/primitives/otp/otp.js +5 -5
- package/src/primitives/otp/otp.json +75 -0
- package/src/primitives/otp/otp.ts +5 -5
- package/src/primitives/password-group/password-group.css +32 -2
- package/src/primitives/password-group/password-group.html +1 -1
- package/src/primitives/password-group/password-group.json +74 -0
- package/src/primitives/popover/popover.css +1 -1
- package/src/primitives/popover/popover.json +64 -0
- package/src/primitives/progress/progress.css +25 -3
- package/src/primitives/progress/progress.json +41 -0
- package/src/primitives/prose/prose.css +341 -0
- package/src/primitives/prose/prose.html +11 -11
- package/src/primitives/prose/prose.json +47 -0
- package/src/primitives/radio/radio.css +1 -1
- package/src/primitives/radio/radio.json +48 -0
- package/src/primitives/reveal/reveal.json +72 -0
- package/src/primitives/scroll-fade/scroll-fade.css +0 -3
- package/src/primitives/scroll-fade/scroll-fade.json +34 -0
- package/src/primitives/select/select.css +2 -2
- package/src/primitives/select/select.json +119 -0
- package/src/primitives/separator/separator.json +34 -0
- package/src/primitives/slider/slider.css +87 -13
- package/src/primitives/slider/slider.json +49 -0
- package/src/primitives/style-guard/style-guard.js +1 -1
- package/src/primitives/style-guard/style-guard.json +22 -0
- package/src/primitives/style-guard/style-guard.ts +2 -2
- package/src/primitives/switch/switch.css +107 -18
- package/src/primitives/switch/switch.json +71 -0
- package/src/primitives/table/table.json +74 -0
- package/src/primitives/tabs/tabs.css +24 -12
- package/src/primitives/tabs/tabs.d.ts +4 -2
- package/src/primitives/tabs/tabs.d.ts.map +1 -1
- package/src/primitives/tabs/tabs.js +14 -24
- package/src/primitives/tabs/tabs.json +94 -0
- package/src/primitives/tabs/tabs.ts +14 -26
- package/src/primitives/textarea/textarea.css +1 -1
- package/src/primitives/textarea/textarea.json +48 -0
- package/src/primitives/toaster/toaster.d.ts.map +1 -1
- package/src/primitives/toaster/toaster.js +4 -4
- package/src/primitives/toaster/toaster.json +101 -0
- package/src/primitives/toaster/toaster.ts +5 -5
- package/src/primitives/toggle/toggle.css +2 -52
- package/src/primitives/toggle/toggle.json +84 -0
- package/src/primitives/toggle-group/toggle-group.css +1 -1
- package/src/primitives/toggle-group/toggle-group.json +41 -0
- package/src/primitives/toolbar/toolbar.json +26 -0
- package/src/primitives/tooltip/tooltip.css +6 -4
- package/src/primitives/tooltip/tooltip.json +85 -0
- package/src/primitives/utilities/aspect-ratio.html +3 -3
- package/src/primitives/utilities/basis.html +5 -5
- package/src/primitives/utilities/col-span.html +5 -5
- package/src/primitives/utilities/compose.html +3 -3
- package/src/primitives/utilities/flex-align.html +3 -3
- package/src/primitives/utilities/flex-direction.html +8 -8
- package/src/primitives/utilities/flex-grow.html +3 -3
- package/src/primitives/utilities/flex-reverse.html +8 -8
- package/src/primitives/utilities/gallery.html +19 -19
- package/src/primitives/utilities/gap.html +12 -12
- package/src/primitives/utilities/grid-cols.html +6 -6
- package/src/primitives/utilities/grid-responsive.html +9 -9
- package/src/primitives/utilities/inline-flex.html +2 -2
- package/src/primitives/utilities/margin-auto.html +1 -1
- package/src/primitives/utilities/object-fit.html +3 -3
- package/src/primitives/utilities/order.html +3 -3
- package/src/primitives/utilities/overflow.html +14 -14
- package/src/primitives/utilities/padding-compose.html +3 -3
- package/src/primitives/utilities/padding.html +4 -4
- package/src/primitives/utilities/position.html +1 -1
- package/src/primitives/utilities/responsive-flex.html +4 -4
- package/src/primitives/utilities/responsive-grid.html +9 -9
- package/src/primitives/utilities/size.html +5 -5
- package/src/primitives/utilities/subgrid-col.html +7 -7
- package/src/primitives/utilities/subgrid-row.html +9 -9
- package/src/primitives/utilities/subgrid.html +9 -9
- package/src/primitives/utilities/utilities.json +48 -0
- package/src/primitives/utilities/width.html +5 -5
- package/src/base/gesture.d.ts.map +0 -1
- package/src/base/hotkeys.d.ts.map +0 -1
- package/src/base/typeahead.d.ts.map +0 -1
- /package/src/{base → behaviors}/command-score.d.ts +0 -0
- /package/src/{base → behaviors}/command-score.d.ts.map +0 -0
- /package/src/{base → behaviors}/command-score.js +0 -0
- /package/src/{base → behaviors}/command-score.ts +0 -0
- /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
|
-
* (`
|
|
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-
|
|
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 "../../
|
|
38
|
-
import { bindHotkey } from "../../
|
|
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-
|
|
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 (
|
|
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
|
-
/**
|
|
59
|
-
export
|
|
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-
|
|
65
|
-
* order: each needs the swap opt-in, an id, a unique id, and no
|
|
66
|
-
* element
|
|
67
|
-
*
|
|
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) =>
|
|
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,
|
|
1
|
+
{"version":3,"file":"audit-core.d.ts","sourceRoot":"","sources":["audit-core.ts"],"names":[],"mappings":"AA6BA,sEAAsE;AACtE,MAAM,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;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-
|
|
473
|
-
* order: each needs the swap opt-in, an id, a unique id, and no
|
|
474
|
-
* element
|
|
475
|
-
*
|
|
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,
|
|
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 =
|
|
546
|
+
const scroll = mode === "scroll";
|
|
482
547
|
const kept = [];
|
|
483
548
|
if (!swap) {
|
|
484
549
|
for (const el of persisted) {
|
|
485
|
-
warn(el, `\`${
|
|
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
|
-
?
|
|
495
|
-
: "`data-
|
|
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,
|
|
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
|
-
|
|
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
|
-
/**
|
|
678
|
-
export
|
|
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-
|
|
685
|
-
* order: each needs the swap opt-in, an id, a unique id, and no
|
|
686
|
-
* element
|
|
687
|
-
*
|
|
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) =>
|
|
695
|
-
|
|
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 =
|
|
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
|
-
`\`${
|
|
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
|
-
?
|
|
718
|
-
: "`data-
|
|
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
|
-
|
|
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-
|
|
22
|
-
* page, which `data-
|
|
23
|
-
* `data-
|
|
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,WAAW,OAAO;IACtB,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE,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