@zazz-ui/core 0.6.2 → 0.7.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 +5 -3
- package/CHANGELOG.md +38 -0
- package/README.md +3 -3
- package/dist/csp-D72qtdXZ.js +1 -0
- package/dist/sri.json +54 -49
- package/dist/zazz.css +1 -1
- package/dist/zazz.js +1 -1
- package/editor/zazz.css-data.json +312 -24
- package/editor/zazz.language-data.json +9 -9
- package/editor/zazz.lint-data.json +2028 -0
- package/package.json +1 -1
- package/src/base/_defaults.css +367 -0
- package/src/base/_layers.css +6 -2
- package/src/base/_properties-2xl.css +8 -2
- package/src/base/_properties-active.css +12 -0
- package/src/base/_properties-checked.css +12 -0
- package/src/base/_properties-current.css +12 -0
- package/src/base/_properties-disabled.css +12 -0
- package/src/base/_properties-focus-visible.css +12 -0
- package/src/base/_properties-focus-within.css +12 -0
- package/src/base/_properties-hover.css +12 -0
- package/src/base/_properties-lg.css +8 -2
- package/src/base/_properties-md.css +8 -2
- package/src/base/_properties-open.css +12 -0
- package/src/base/_properties-sm.css +8 -2
- package/src/base/_properties-starting.css +6 -0
- package/src/base/_properties-stuck.css +6 -0
- package/src/base/_properties-xl.css +8 -2
- package/src/base/_properties.css +12 -3
- package/src/base/_utilities-box.css +0 -15
- package/src/base/_utilities-effects.css +0 -15
- package/src/base/_utilities-flow.css +79 -68
- package/src/base/_utilities-grid.css +20 -32
- package/src/base/_utilities-sizing.css +0 -3
- package/src/base/_utilities-spacing.css +36 -11
- package/src/base/_utilities-tier-2xl.css +4 -1
- package/src/base/_utilities-tier-active.css +6 -0
- package/src/base/_utilities-tier-checked.css +6 -0
- package/src/base/_utilities-tier-current.css +6 -0
- package/src/base/_utilities-tier-disabled.css +6 -0
- package/src/base/_utilities-tier-focus-visible.css +6 -0
- package/src/base/_utilities-tier-focus-within.css +6 -0
- package/src/base/_utilities-tier-hover.css +6 -0
- package/src/base/_utilities-tier-lg.css +4 -1
- package/src/base/_utilities-tier-md.css +4 -1
- package/src/base/_utilities-tier-open.css +6 -0
- package/src/base/_utilities-tier-sm.css +4 -1
- package/src/base/_utilities-tier-starting.css +3 -0
- package/src/base/_utilities-tier-stuck.css +3 -0
- package/src/base/_utilities-tier-xl.css +4 -1
- package/src/base/_utilities-typography.css +0 -9
- package/src/base/csp.d.ts +19 -0
- package/src/base/csp.d.ts.map +1 -0
- package/src/base/csp.js +131 -0
- package/src/base/csp.ts +137 -0
- package/src/base/declarations.d.ts +36 -0
- package/src/base/declarations.d.ts.map +1 -0
- package/src/base/declarations.js +70 -0
- package/src/base/declarations.ts +97 -0
- package/src/base/kit-styling.d.ts +11 -0
- package/src/base/kit-styling.d.ts.map +1 -0
- package/src/base/kit-styling.js +467 -0
- package/src/base/kit-styling.ts +470 -0
- package/src/base/style-format.d.ts +3 -22
- package/src/base/style-format.d.ts.map +1 -1
- package/src/base/style-format.js +4 -62
- package/src/base/style-format.ts +4 -71
- package/src/base/utilities.d.ts +14 -6
- package/src/base/utilities.d.ts.map +1 -1
- package/src/base/utilities.js +81 -29
- package/src/base/utilities.ts +92 -38
- package/src/head.d.ts +6 -0
- package/src/head.d.ts.map +1 -1
- package/src/head.js +21 -14
- package/src/head.ts +38 -11
- package/src/index.css +1 -0
- package/src/index.js +22 -0
- package/src/index.ts +19 -0
- package/src/manifest.d.ts +21 -1
- package/src/manifest.d.ts.map +1 -1
- package/src/manifest.js +12 -2
- package/src/manifest.ts +27 -2
- package/src/primitives/debug/audit-core.d.ts +9 -1
- package/src/primitives/debug/audit-core.d.ts.map +1 -1
- package/src/primitives/debug/audit-core.js +58 -8
- package/src/primitives/debug/audit-core.ts +84 -7
- package/src/primitives/debug/debug.d.ts +0 -15
- package/src/primitives/debug/debug.d.ts.map +1 -1
- package/src/primitives/debug/debug.js +11 -2
- package/src/primitives/debug/debug.ts +12 -1
- package/src/primitives/prose/prose.html +3 -3
- package/src/primitives/table/table-size-sm.html +12 -12
- package/src/primitives/utilities/aspect-ratio.html +1 -0
- package/src/primitives/utilities/margin-auto.html +1 -1
- package/src/primitives/utilities/overflow.html +5 -6
- package/src/primitives/utilities/position.html +1 -1
- package/src/primitives/utilities/width.html +2 -1
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* where it can, the span of the declaration it is about (offsets into the
|
|
8
8
|
* `style` attribute) and a suggested rewrite.
|
|
9
9
|
*/
|
|
10
|
-
import { BORDER_SHORTHANDS, GRADIENT_TYPES, UTILITIES, PSEUDO_ONLY, FONT_WEIGHT_NAMES, STUCK_STATE, STATES, parseUtilityName, tiersOf, } from "../../base/utilities.js";
|
|
10
|
+
import { BORDER_SHORTHANDS, BOX_SHADOW_COMPOSITE, SHORTHAND_OF, DISPLAY_SHORTHANDS, GRADIENT_TYPES, UTILITIES, PSEUDO_ONLY, FONT_WEIGHT_NAMES, STUCK_STATE, STATES, parseUtilityName, tiersOf, } from "../../base/utilities.js";
|
|
11
11
|
export const RULE_IDS = [
|
|
12
12
|
"unknown-utility",
|
|
13
13
|
"pseudo-form",
|
|
@@ -24,6 +24,7 @@ export const RULE_IDS = [
|
|
|
24
24
|
"font-weight-name",
|
|
25
25
|
"scroll-state",
|
|
26
26
|
"whitespace-before-colon",
|
|
27
|
+
"whitespace-after-colon",
|
|
27
28
|
"attribute-outside-identity",
|
|
28
29
|
"field-id-or-name",
|
|
29
30
|
"persist",
|
|
@@ -37,6 +38,19 @@ const BUTTON_TYPES = new Set(["button", "submit", "reset", "image"]);
|
|
|
37
38
|
const NUMBER = /^-?(\d+\.?\d*|\.\d+)$/;
|
|
38
39
|
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)$/;
|
|
39
40
|
const FUNCTION = /^(calc|clamp|min|max|var|env|round|mod|rem|abs|sign)\(/;
|
|
41
|
+
/**
|
|
42
|
+
* True when the kit matches `value` as text (`[style*="--w: auto"]`): a
|
|
43
|
+
* keyword, a token by name, a `--display` shorthand, `none` on `--bg`, or
|
|
44
|
+
* `sticky` on `--position`. Those forms need exactly one space after the colon;
|
|
45
|
+
* a tier gate (`--p:`) reads the property itself and takes any spacing.
|
|
46
|
+
*/
|
|
47
|
+
function gatedValue(utility, value) {
|
|
48
|
+
return ((utility.keywords ?? []).includes(value) ||
|
|
49
|
+
value in (utility.aliases ?? {}) ||
|
|
50
|
+
(utility.name === "display" && value in DISPLAY_SHORTHANDS) ||
|
|
51
|
+
(utility.name === "bg" && value === "none") ||
|
|
52
|
+
(utility.name === "position" && value === "sticky"));
|
|
53
|
+
}
|
|
40
54
|
/** Splits a `style` attribute into declarations with their spans. */
|
|
41
55
|
function declarations(text) {
|
|
42
56
|
const found = [];
|
|
@@ -49,12 +63,11 @@ function declarations(text) {
|
|
|
49
63
|
continue;
|
|
50
64
|
const lead = part.length - part.trimStart().length;
|
|
51
65
|
const trail = part.length - part.trimEnd().length;
|
|
66
|
+
const raw = part.slice(colon + 1);
|
|
52
67
|
found.push({
|
|
53
68
|
name: part.slice(0, colon),
|
|
54
|
-
value:
|
|
55
|
-
|
|
56
|
-
.replace(/!\s*important\s*$/i, "")
|
|
57
|
-
.trim(),
|
|
69
|
+
value: raw.replace(/!\s*important\s*$/i, "").trim(),
|
|
70
|
+
raw,
|
|
58
71
|
span: [start + lead, start + part.length - trail],
|
|
59
72
|
});
|
|
60
73
|
}
|
|
@@ -96,6 +109,10 @@ export function carriesIdentity(tagName, dataUi, name, identities) {
|
|
|
96
109
|
const tokens = (dataUi ?? "").split(/\s+/).filter(Boolean);
|
|
97
110
|
return tokens.some((token) => identities.includes(token) && (token === name || token.startsWith(`${name}-`)));
|
|
98
111
|
}
|
|
112
|
+
/** `reads` / `blocks` as generated (indices into `selectors`), back as selector lists for {@link AuditContext}. */
|
|
113
|
+
export function expandStyling(selectors, record) {
|
|
114
|
+
return Object.fromEntries(Object.entries(record).map(([name, indices]) => [name, indices.map((i) => selectors[i])]));
|
|
115
|
+
}
|
|
99
116
|
/** Audits one element's `style` and `data-*` attributes. */
|
|
100
117
|
export function auditNode(node, context) {
|
|
101
118
|
const found = [];
|
|
@@ -131,6 +148,18 @@ export function auditNode(node, context) {
|
|
|
131
148
|
for (const [parsed, name, declaration] of parsedPairs) {
|
|
132
149
|
const { value, span } = declaration;
|
|
133
150
|
const warn = (rule, message, suggestion) => found.push({ rule, message, span, ...(suggestion ? { suggestion } : {}) });
|
|
151
|
+
// the gated forms match the attribute text, so `--w:auto` and `--w: auto` miss
|
|
152
|
+
const spacing = () => {
|
|
153
|
+
const { raw } = declaration;
|
|
154
|
+
if (raw === ` ${value}` || /!\s*important/i.test(raw))
|
|
155
|
+
return;
|
|
156
|
+
const colon = span[0] + declaration.name.trimStart().length;
|
|
157
|
+
warn("whitespace-after-colon", `\`${name}:${raw}\` is matched as text, so it needs exactly one space after the colon: \`${name}: ${value}\`.`, {
|
|
158
|
+
description: `Write \`${name}: ${value}\`.`,
|
|
159
|
+
span: [colon + 1, span[1]],
|
|
160
|
+
text: ` ${value}`,
|
|
161
|
+
});
|
|
162
|
+
};
|
|
134
163
|
// --stuck-state names the side a sticky container reports as stuck
|
|
135
164
|
if (parsed.name === STUCK_STATE.modifier && !parsed.group && !parsed.side) {
|
|
136
165
|
if (parsed.tier) {
|
|
@@ -139,6 +168,9 @@ export function auditNode(node, context) {
|
|
|
139
168
|
else if (!STUCK_STATE.sides.includes(value)) {
|
|
140
169
|
warn("scroll-state", `\`${name}: ${value}\` is not a side the stuck state matches: ${STUCK_STATE.sides.join(", ")}.`);
|
|
141
170
|
}
|
|
171
|
+
else {
|
|
172
|
+
spacing();
|
|
173
|
+
}
|
|
142
174
|
continue;
|
|
143
175
|
}
|
|
144
176
|
const utility = UTILITY_BY_NAME.get(parsed.name);
|
|
@@ -159,6 +191,8 @@ export function auditNode(node, context) {
|
|
|
159
191
|
warn("pseudo-form", `\`${name}\` exists only as \`--before-${utility.name}\` / \`--after-${utility.name}\`.`);
|
|
160
192
|
continue;
|
|
161
193
|
}
|
|
194
|
+
if (!parsed.side && gatedValue(utility, value))
|
|
195
|
+
spacing();
|
|
162
196
|
const baseName = (parsed.side ? `${parsed.side}-` : "") + utility.name;
|
|
163
197
|
if (parsed.group && parsed.tier === "stuck") {
|
|
164
198
|
warn("scroll-state", `\`${name}\` has no group form: the sticky container is the trigger, so write \`--${utility.name}--stuck\` inside it.`);
|
|
@@ -210,9 +244,25 @@ export function auditNode(node, context) {
|
|
|
210
244
|
// a border shorthand is the base a border longhand's tier overrides
|
|
211
245
|
const borderBase = /^border-(?:width|color|style)$/.test(baseName) &&
|
|
212
246
|
BORDER_SHORTHANDS.some((name) => bases.has(name));
|
|
213
|
-
// a
|
|
214
|
-
const
|
|
215
|
-
|
|
247
|
+
// a shorthand's base is the base its longhand's tier overrides (`--p: 4; --px--md: 1`)
|
|
248
|
+
const shorthandBase = (SHORTHAND_OF[baseName] ?? []).some((name) => bases.has(name));
|
|
249
|
+
// the box-shadow composite (ring, shadow) works tier-only like a no-base utility;
|
|
250
|
+
// the other feeds (`--bg-alpha`, `--focus-ring`, `--shadow-angle`) reach the
|
|
251
|
+
// element through another utility or a token, and are not checked here
|
|
252
|
+
const composite = BOX_SHADOW_COMPOSITE.includes(utility.name);
|
|
253
|
+
const feedsComposite = !composite && (utility.emit === "none" || utility.emit === "px");
|
|
254
|
+
// a tier alone works where the kit reads the utility through its own chain,
|
|
255
|
+
// or where the tier-only rule (`@layer defaults`) applies: a no-base utility
|
|
256
|
+
// whose property no kit rule above that layer sets on this element
|
|
257
|
+
const readByKit = (context.reads[utility.name] ?? []).some((selector) => node.matches(selector));
|
|
258
|
+
const noBase = (utility.noBase !== undefined || composite) &&
|
|
259
|
+
!(context.blocks[utility.name] ?? []).some((selector) => node.matches(selector));
|
|
260
|
+
if (!readByKit &&
|
|
261
|
+
!noBase &&
|
|
262
|
+
!bases.has(baseName) &&
|
|
263
|
+
!borderBase &&
|
|
264
|
+
!shorthandBase &&
|
|
265
|
+
!feedsComposite) {
|
|
216
266
|
warn("tier-without-base", `\`${name}\` has no base \`--${baseName}\`; the tier only overrides a base.`);
|
|
217
267
|
}
|
|
218
268
|
continue;
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
13
|
BORDER_SHORTHANDS,
|
|
14
|
+
BOX_SHADOW_COMPOSITE,
|
|
15
|
+
SHORTHAND_OF,
|
|
16
|
+
DISPLAY_SHORTHANDS,
|
|
14
17
|
GRADIENT_TYPES,
|
|
15
18
|
UTILITIES,
|
|
16
19
|
PSEUDO_ONLY,
|
|
@@ -40,6 +43,7 @@ export type RuleId =
|
|
|
40
43
|
| "font-weight-name"
|
|
41
44
|
| "scroll-state"
|
|
42
45
|
| "whitespace-before-colon"
|
|
46
|
+
| "whitespace-after-colon"
|
|
43
47
|
| "attribute-outside-identity"
|
|
44
48
|
| "field-id-or-name"
|
|
45
49
|
| "persist";
|
|
@@ -60,6 +64,7 @@ export const RULE_IDS: readonly RuleId[] = [
|
|
|
60
64
|
"font-weight-name",
|
|
61
65
|
"scroll-state",
|
|
62
66
|
"whitespace-before-colon",
|
|
67
|
+
"whitespace-after-colon",
|
|
63
68
|
"attribute-outside-identity",
|
|
64
69
|
"field-id-or-name",
|
|
65
70
|
"persist",
|
|
@@ -92,6 +97,8 @@ export interface AuditNode {
|
|
|
92
97
|
getAttributeNames(): string[];
|
|
93
98
|
/** True when this node or an ancestor carries the identity `name` (see {@link carriesIdentity}). */
|
|
94
99
|
withinIdentity(name: string, identities: readonly string[]): boolean;
|
|
100
|
+
/** `Element.matches`, for the selectors in `reads` and `blocks`. */
|
|
101
|
+
matches(selector: string): boolean;
|
|
95
102
|
}
|
|
96
103
|
|
|
97
104
|
export interface AuditContext {
|
|
@@ -99,6 +106,10 @@ export interface AuditContext {
|
|
|
99
106
|
hooks: Record<string, string[]>;
|
|
100
107
|
/** Identity tokens the kit declares (`button`, `field-group`). */
|
|
101
108
|
identities: readonly string[];
|
|
109
|
+
/** For each utility, the elements the kit reads it on through its own chain, as selectors. */
|
|
110
|
+
reads: Readonly<Record<string, readonly string[]>>;
|
|
111
|
+
/** For each tier-only utility, the elements a kit rule above `@layer defaults` sets its property on. */
|
|
112
|
+
blocks: Readonly<Record<string, readonly string[]>>;
|
|
102
113
|
/** True when `value` is a color identifier (`red`, `currentcolor`); the browser asks `CSS.supports`. */
|
|
103
114
|
isColor: (value: string) => boolean;
|
|
104
115
|
}
|
|
@@ -122,9 +133,27 @@ interface Declaration {
|
|
|
122
133
|
/** The name as written; its whitespace is a finding. */
|
|
123
134
|
name: string;
|
|
124
135
|
value: string;
|
|
136
|
+
/** The text after the colon as written (`!important` included), for the whitespace check. */
|
|
137
|
+
raw: string;
|
|
125
138
|
span: Span;
|
|
126
139
|
}
|
|
127
140
|
|
|
141
|
+
/**
|
|
142
|
+
* True when the kit matches `value` as text (`[style*="--w: auto"]`): a
|
|
143
|
+
* keyword, a token by name, a `--display` shorthand, `none` on `--bg`, or
|
|
144
|
+
* `sticky` on `--position`. Those forms need exactly one space after the colon;
|
|
145
|
+
* a tier gate (`--p:`) reads the property itself and takes any spacing.
|
|
146
|
+
*/
|
|
147
|
+
function gatedValue(utility: Utility, value: string): boolean {
|
|
148
|
+
return (
|
|
149
|
+
(utility.keywords ?? []).includes(value) ||
|
|
150
|
+
value in (utility.aliases ?? {}) ||
|
|
151
|
+
(utility.name === "display" && value in DISPLAY_SHORTHANDS) ||
|
|
152
|
+
(utility.name === "bg" && value === "none") ||
|
|
153
|
+
(utility.name === "position" && value === "sticky")
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
128
157
|
/** Splits a `style` attribute into declarations with their spans. */
|
|
129
158
|
function declarations(text: string): Declaration[] {
|
|
130
159
|
const found: Declaration[] = [];
|
|
@@ -136,12 +165,11 @@ function declarations(text: string): Declaration[] {
|
|
|
136
165
|
if (colon === -1) continue;
|
|
137
166
|
const lead = part.length - part.trimStart().length;
|
|
138
167
|
const trail = part.length - part.trimEnd().length;
|
|
168
|
+
const raw = part.slice(colon + 1);
|
|
139
169
|
found.push({
|
|
140
170
|
name: part.slice(0, colon),
|
|
141
|
-
value:
|
|
142
|
-
|
|
143
|
-
.replace(/!\s*important\s*$/i, "")
|
|
144
|
-
.trim(),
|
|
171
|
+
value: raw.replace(/!\s*important\s*$/i, "").trim(),
|
|
172
|
+
raw,
|
|
145
173
|
span: [start + lead, start + part.length - trail],
|
|
146
174
|
});
|
|
147
175
|
}
|
|
@@ -192,6 +220,16 @@ export function carriesIdentity(
|
|
|
192
220
|
);
|
|
193
221
|
}
|
|
194
222
|
|
|
223
|
+
/** `reads` / `blocks` as generated (indices into `selectors`), back as selector lists for {@link AuditContext}. */
|
|
224
|
+
export function expandStyling(
|
|
225
|
+
selectors: readonly string[],
|
|
226
|
+
record: Readonly<Record<string, readonly number[]>>,
|
|
227
|
+
): Record<string, string[]> {
|
|
228
|
+
return Object.fromEntries(
|
|
229
|
+
Object.entries(record).map(([name, indices]) => [name, indices.map((i) => selectors[i]!)]),
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
195
233
|
/** Audits one element's `style` and `data-*` attributes. */
|
|
196
234
|
export function auditNode(node: AuditNode, context: AuditContext): Finding[] {
|
|
197
235
|
const found: Finding[] = [];
|
|
@@ -227,6 +265,21 @@ export function auditNode(node: AuditNode, context: AuditContext): Finding[] {
|
|
|
227
265
|
const { value, span } = declaration;
|
|
228
266
|
const warn = (rule: RuleId, message: string, suggestion?: Suggestion) =>
|
|
229
267
|
found.push({ rule, message, span, ...(suggestion ? { suggestion } : {}) });
|
|
268
|
+
// the gated forms match the attribute text, so `--w:auto` and `--w: auto` miss
|
|
269
|
+
const spacing = () => {
|
|
270
|
+
const { raw } = declaration;
|
|
271
|
+
if (raw === ` ${value}` || /!\s*important/i.test(raw)) return;
|
|
272
|
+
const colon = span[0] + declaration.name.trimStart().length;
|
|
273
|
+
warn(
|
|
274
|
+
"whitespace-after-colon",
|
|
275
|
+
`\`${name}:${raw}\` is matched as text, so it needs exactly one space after the colon: \`${name}: ${value}\`.`,
|
|
276
|
+
{
|
|
277
|
+
description: `Write \`${name}: ${value}\`.`,
|
|
278
|
+
span: [colon + 1, span[1]],
|
|
279
|
+
text: ` ${value}`,
|
|
280
|
+
},
|
|
281
|
+
);
|
|
282
|
+
};
|
|
230
283
|
// --stuck-state names the side a sticky container reports as stuck
|
|
231
284
|
if (parsed.name === STUCK_STATE.modifier && !parsed.group && !parsed.side) {
|
|
232
285
|
if (parsed.tier) {
|
|
@@ -239,6 +292,8 @@ export function auditNode(node: AuditNode, context: AuditContext): Finding[] {
|
|
|
239
292
|
"scroll-state",
|
|
240
293
|
`\`${name}: ${value}\` is not a side the stuck state matches: ${STUCK_STATE.sides.join(", ")}.`,
|
|
241
294
|
);
|
|
295
|
+
} else {
|
|
296
|
+
spacing();
|
|
242
297
|
}
|
|
243
298
|
continue;
|
|
244
299
|
}
|
|
@@ -265,6 +320,7 @@ export function auditNode(node: AuditNode, context: AuditContext): Finding[] {
|
|
|
265
320
|
);
|
|
266
321
|
continue;
|
|
267
322
|
}
|
|
323
|
+
if (!parsed.side && gatedValue(utility, value)) spacing();
|
|
268
324
|
const baseName = (parsed.side ? `${parsed.side}-` : "") + utility.name;
|
|
269
325
|
if (parsed.group && parsed.tier === "stuck") {
|
|
270
326
|
warn(
|
|
@@ -342,9 +398,30 @@ export function auditNode(node: AuditNode, context: AuditContext): Finding[] {
|
|
|
342
398
|
const borderBase =
|
|
343
399
|
/^border-(?:width|color|style)$/.test(baseName) &&
|
|
344
400
|
BORDER_SHORTHANDS.some((name) => bases.has(name));
|
|
345
|
-
// a
|
|
346
|
-
const
|
|
347
|
-
|
|
401
|
+
// a shorthand's base is the base its longhand's tier overrides (`--p: 4; --px--md: 1`)
|
|
402
|
+
const shorthandBase = (SHORTHAND_OF[baseName] ?? []).some((name) => bases.has(name));
|
|
403
|
+
// the box-shadow composite (ring, shadow) works tier-only like a no-base utility;
|
|
404
|
+
// the other feeds (`--bg-alpha`, `--focus-ring`, `--shadow-angle`) reach the
|
|
405
|
+
// element through another utility or a token, and are not checked here
|
|
406
|
+
const composite = (BOX_SHADOW_COMPOSITE as readonly string[]).includes(utility.name);
|
|
407
|
+
const feedsComposite = !composite && (utility.emit === "none" || utility.emit === "px");
|
|
408
|
+
// a tier alone works where the kit reads the utility through its own chain,
|
|
409
|
+
// or where the tier-only rule (`@layer defaults`) applies: a no-base utility
|
|
410
|
+
// whose property no kit rule above that layer sets on this element
|
|
411
|
+
const readByKit = (context.reads[utility.name] ?? []).some((selector) =>
|
|
412
|
+
node.matches(selector),
|
|
413
|
+
);
|
|
414
|
+
const noBase =
|
|
415
|
+
(utility.noBase !== undefined || composite) &&
|
|
416
|
+
!(context.blocks[utility.name] ?? []).some((selector) => node.matches(selector));
|
|
417
|
+
if (
|
|
418
|
+
!readByKit &&
|
|
419
|
+
!noBase &&
|
|
420
|
+
!bases.has(baseName) &&
|
|
421
|
+
!borderBase &&
|
|
422
|
+
!shorthandBase &&
|
|
423
|
+
!feedsComposite
|
|
424
|
+
) {
|
|
348
425
|
warn(
|
|
349
426
|
"tier-without-base",
|
|
350
427
|
`\`${name}\` has no base \`--${baseName}\`; the tier only overrides a base.`,
|
|
@@ -1,18 +1,3 @@
|
|
|
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
1
|
import { ZazzElement } from "../../base/zazz-element.ts";
|
|
17
2
|
import { type RuleId } from "./audit-core.ts";
|
|
18
3
|
export interface Warning {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["debug.ts"],"names":[],"mappings":"
|
|
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,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;AA+CD,8EAA8E;AAC9E,wBAAgB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,EAAE,CAmB1E;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"}
|
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
* @example
|
|
15
15
|
* <ui-debug data-debug-domains="localhost, staging.example.com"></ui-debug>
|
|
16
16
|
*/
|
|
17
|
+
import { KIT_SELECTORS, TIER_BLOCKS, TIER_READS } from "../../base/kit-styling.js";
|
|
17
18
|
import { ZazzElement, defineZazzElement } from "../../base/zazz-element.js";
|
|
18
|
-
import { auditNode, auditPersistence, carriesIdentity, } from "./audit-core.js";
|
|
19
|
+
import { auditNode, auditPersistence, carriesIdentity, expandStyling, } from "./audit-core.js";
|
|
19
20
|
/** A live element as the audit core reads it. */
|
|
20
21
|
function auditNodeOf(el) {
|
|
21
22
|
return {
|
|
@@ -29,8 +30,11 @@ function auditNodeOf(el) {
|
|
|
29
30
|
}
|
|
30
31
|
return false;
|
|
31
32
|
},
|
|
33
|
+
matches: (selector) => el.matches(selector),
|
|
32
34
|
};
|
|
33
35
|
}
|
|
36
|
+
const READS = expandStyling(KIT_SELECTORS, TIER_READS);
|
|
37
|
+
const BLOCKS = expandStyling(KIT_SELECTORS, TIER_BLOCKS);
|
|
34
38
|
/** Identity tokens and state-bearing hooks, read from the page's stylesheets. */
|
|
35
39
|
function fromStylesheets() {
|
|
36
40
|
const identities = new Set();
|
|
@@ -64,7 +68,12 @@ export function audit(root, options = {}) {
|
|
|
64
68
|
hooks: options.hooks ?? sheets.hooks,
|
|
65
69
|
identities: options.identities ?? sheets.identities,
|
|
66
70
|
};
|
|
67
|
-
const context = {
|
|
71
|
+
const context = {
|
|
72
|
+
...resolved,
|
|
73
|
+
reads: READS,
|
|
74
|
+
blocks: BLOCKS,
|
|
75
|
+
isColor: (value) => CSS.supports("color", value),
|
|
76
|
+
};
|
|
68
77
|
const found = [];
|
|
69
78
|
for (const el of [root, ...root.querySelectorAll("*")]) {
|
|
70
79
|
if (el.tagName === "UI-DEBUG")
|
|
@@ -16,11 +16,13 @@
|
|
|
16
16
|
* <ui-debug data-debug-domains="localhost, staging.example.com"></ui-debug>
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
import { KIT_SELECTORS, TIER_BLOCKS, TIER_READS } from "../../base/kit-styling.ts";
|
|
19
20
|
import { ZazzElement, defineZazzElement } from "../../base/zazz-element.ts";
|
|
20
21
|
import {
|
|
21
22
|
auditNode,
|
|
22
23
|
auditPersistence,
|
|
23
24
|
carriesIdentity,
|
|
25
|
+
expandStyling,
|
|
24
26
|
type AuditNode,
|
|
25
27
|
type RuleId,
|
|
26
28
|
} from "./audit-core.ts";
|
|
@@ -51,9 +53,13 @@ function auditNodeOf(el: Element): AuditNode {
|
|
|
51
53
|
}
|
|
52
54
|
return false;
|
|
53
55
|
},
|
|
56
|
+
matches: (selector) => el.matches(selector),
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
59
|
|
|
60
|
+
const READS = expandStyling(KIT_SELECTORS, TIER_READS);
|
|
61
|
+
const BLOCKS = expandStyling(KIT_SELECTORS, TIER_BLOCKS);
|
|
62
|
+
|
|
57
63
|
/** Identity tokens and state-bearing hooks, read from the page's stylesheets. */
|
|
58
64
|
function fromStylesheets(): { identities: string[]; hooks: Record<string, string[]> } {
|
|
59
65
|
const identities = new Set<string>();
|
|
@@ -86,7 +92,12 @@ export function audit(root: Element, options: AuditOptions = {}): Warning[] {
|
|
|
86
92
|
hooks: options.hooks ?? sheets!.hooks,
|
|
87
93
|
identities: options.identities ?? sheets!.identities,
|
|
88
94
|
};
|
|
89
|
-
const context = {
|
|
95
|
+
const context = {
|
|
96
|
+
...resolved,
|
|
97
|
+
reads: READS,
|
|
98
|
+
blocks: BLOCKS,
|
|
99
|
+
isColor: (value: string) => CSS.supports("color", value),
|
|
100
|
+
};
|
|
90
101
|
const found: Warning[] = [];
|
|
91
102
|
for (const el of [root, ...root.querySelectorAll("*")]) {
|
|
92
103
|
if (el.tagName === "UI-DEBUG") continue;
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
loading="lazy"
|
|
66
66
|
width="800"
|
|
67
67
|
height="400"
|
|
68
|
-
src="https://
|
|
69
|
-
alt="
|
|
68
|
+
src="https://images.unsplash.com/photo-1564760055775-d63b17a55c44?auto=format&fit=crop&w=800&h=400&q=60"
|
|
69
|
+
alt="Elephants crossing a floodplain at dusk"
|
|
70
70
|
/>
|
|
71
|
-
<figcaption>Figure 1:
|
|
71
|
+
<figcaption>Figure 1: An image and its caption, styled by data-ui="prose"</figcaption>
|
|
72
72
|
</figure>
|
|
73
73
|
</article>
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
<table data-ui="table" data-table-size="sm">
|
|
2
2
|
<thead>
|
|
3
3
|
<tr>
|
|
4
|
-
<th>
|
|
5
|
-
<th>
|
|
6
|
-
<th>
|
|
4
|
+
<th>Attribute</th>
|
|
5
|
+
<th>Kind</th>
|
|
6
|
+
<th>Values</th>
|
|
7
7
|
</tr>
|
|
8
8
|
</thead>
|
|
9
9
|
<tbody>
|
|
10
10
|
<tr>
|
|
11
|
-
<td>data-variant</td>
|
|
12
|
-
<td>
|
|
13
|
-
<td
|
|
11
|
+
<td>data-table-variant</td>
|
|
12
|
+
<td>preset</td>
|
|
13
|
+
<td>alternating, grid</td>
|
|
14
14
|
</tr>
|
|
15
15
|
<tr>
|
|
16
|
-
<td>data-size</td>
|
|
17
|
-
<td>
|
|
18
|
-
<td
|
|
16
|
+
<td>data-table-size</td>
|
|
17
|
+
<td>preset</td>
|
|
18
|
+
<td>sm</td>
|
|
19
19
|
</tr>
|
|
20
20
|
<tr>
|
|
21
|
-
<td>data-state</td>
|
|
22
|
-
<td>
|
|
23
|
-
<td
|
|
21
|
+
<td>data-table-state</td>
|
|
22
|
+
<td>state</td>
|
|
23
|
+
<td>selected</td>
|
|
24
24
|
</tr>
|
|
25
25
|
</tbody>
|
|
26
26
|
</table>
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
--display: flex-col;
|
|
19
19
|
--p: 4;
|
|
20
20
|
--gap: 2;
|
|
21
|
-
--h:
|
|
21
|
+
--h: 24;
|
|
22
22
|
--bg: var(--color-muted);
|
|
23
23
|
--rounded: var(--radius-md);
|
|
24
24
|
--overflow-x: clip;
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
--text-align: center;
|
|
40
40
|
--text: var(--color-muted-foreground);
|
|
41
41
|
"
|
|
42
|
-
|
|
42
|
+
>--overflow-y: auto</span
|
|
43
43
|
>
|
|
44
44
|
</div>
|
|
45
45
|
<div
|
|
@@ -53,11 +53,10 @@
|
|
|
53
53
|
--display: flex-col;
|
|
54
54
|
--p: 4;
|
|
55
55
|
--gap: 2;
|
|
56
|
-
--h:
|
|
56
|
+
--h: 24;
|
|
57
57
|
--bg: var(--color-muted);
|
|
58
58
|
--rounded: var(--radius-md);
|
|
59
|
-
--overflow
|
|
60
|
-
--overflow-y: auto;
|
|
59
|
+
--overflow: hidden;
|
|
61
60
|
"
|
|
62
61
|
>
|
|
63
62
|
<p data-ui="text-sm">Scrollable region one</p>
|
|
@@ -74,7 +73,7 @@
|
|
|
74
73
|
--text-align: center;
|
|
75
74
|
--text: var(--color-muted-foreground);
|
|
76
75
|
"
|
|
77
|
-
|
|
76
|
+
>--overflow: hidden</span
|
|
78
77
|
>
|
|
79
78
|
</div>
|
|
80
79
|
</div>
|