@zazz-ui/core 0.6.2 → 0.6.3

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 (46) hide show
  1. package/AUTHORING.md +4 -2
  2. package/CHANGELOG.md +25 -0
  3. package/README.md +3 -3
  4. package/dist/csp-D72qtdXZ.js +1 -0
  5. package/dist/sri.json +13 -10
  6. package/dist/zazz.css +1 -1
  7. package/dist/zazz.js +1 -1
  8. package/package.json +1 -1
  9. package/src/base/_utilities-color.css +3 -0
  10. package/src/base/_utilities-spacing.css +35 -0
  11. package/src/base/csp.d.ts +19 -0
  12. package/src/base/csp.d.ts.map +1 -0
  13. package/src/base/csp.js +131 -0
  14. package/src/base/csp.ts +137 -0
  15. package/src/base/declarations.d.ts +36 -0
  16. package/src/base/declarations.d.ts.map +1 -0
  17. package/src/base/declarations.js +70 -0
  18. package/src/base/declarations.ts +97 -0
  19. package/src/base/style-format.d.ts +3 -22
  20. package/src/base/style-format.d.ts.map +1 -1
  21. package/src/base/style-format.js +4 -62
  22. package/src/base/style-format.ts +4 -71
  23. package/src/base/utilities.d.ts.map +1 -1
  24. package/src/base/utilities.js +35 -17
  25. package/src/base/utilities.ts +42 -20
  26. package/src/head.d.ts +6 -0
  27. package/src/head.d.ts.map +1 -1
  28. package/src/head.js +21 -14
  29. package/src/head.ts +38 -11
  30. package/src/index.js +22 -0
  31. package/src/index.ts +19 -0
  32. package/src/manifest.d.ts +21 -1
  33. package/src/manifest.d.ts.map +1 -1
  34. package/src/manifest.js +10 -1
  35. package/src/manifest.ts +25 -1
  36. package/src/primitives/debug/audit-core.d.ts +1 -1
  37. package/src/primitives/debug/audit-core.d.ts.map +1 -1
  38. package/src/primitives/debug/audit-core.js +35 -5
  39. package/src/primitives/debug/audit-core.ts +42 -4
  40. package/src/primitives/prose/prose.html +3 -3
  41. package/src/primitives/table/table-size-sm.html +12 -12
  42. package/src/primitives/utilities/aspect-ratio.html +1 -0
  43. package/src/primitives/utilities/margin-auto.html +1 -1
  44. package/src/primitives/utilities/overflow.html +5 -6
  45. package/src/primitives/utilities/position.html +1 -1
  46. package/src/primitives/utilities/width.html +2 -1
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @fileoverview CSP fallback: applies `style` attributes a Content Security Policy blocked.
5
+ * @description Loaded by `index.ts` only when the page's policy blocks inline
6
+ * style attributes (`style-src-attr` without `'unsafe-inline'`, or a
7
+ * `style-src` without it): the attribute text is still in the DOM, so the
8
+ * kit's `[style*="--p:"]` gates still match, but none of its values apply.
9
+ * CSP does not govern the CSSOM, so this module reads each attribute and
10
+ * writes its declarations with `style.setProperty`, one by one (never
11
+ * `cssText` or `setAttribute`, which the policy blocks), then watches for
12
+ * attributes written later. Utilities then need JavaScript and apply after the
13
+ * module runs; a policy that allows attributes (`style-src-attr
14
+ * 'unsafe-inline'`) needs none of this. `data-ui-guard="off"` opts an element
15
+ * out, as it does for the style guard.
16
+ *
17
+ * Detection never writes a probe: it looks for an element whose attribute
18
+ * holds a declaration while its declaration block is empty, which is what a
19
+ * blocked attribute looks like on load, so the kit never raises a violation
20
+ * report of its own. A blocked write to an element that already has a block
21
+ * (an app's `setAttribute("style", …)` after the fallback ran) leaves the old
22
+ * block in place, so each apply compares the attribute's declarations with
23
+ * the block and rewrites the block only when they differ.
24
+ */
25
+
26
+ import { plainValue, scanDeclarations } from "./declarations.ts";
27
+
28
+ type Styled = Element & ElementCSSInlineStyle;
29
+
30
+ // --- Detection ---
31
+
32
+ /** True when `el` carries a `style` attribute with a declaration that the policy did not apply. */
33
+ function blocked(el: Element): el is Styled {
34
+ if (!("style" in el)) return false;
35
+ const text = el.getAttribute("style");
36
+ return !!text && text.includes(":") && (el as Styled).style.length === 0;
37
+ }
38
+
39
+ /** True when the document's policy blocks inline style attributes (some styled element has an empty declaration block). */
40
+ function blockedInlineStyles(root: ParentNode = document): boolean {
41
+ for (const el of root.querySelectorAll("[style]")) if (blocked(el)) return true;
42
+ return false;
43
+ }
44
+
45
+ // --- Apply ---
46
+
47
+ /** name → [value, priority] of the attribute's declarations, as `setProperty` takes them. */
48
+ function declared(text: string): Map<string, [string, string]> {
49
+ const out = new Map<string, [string, string]>();
50
+ for (const declaration of scanDeclarations(text)) {
51
+ if (declaration.colon !== -1) {
52
+ out.set(declaration.name, [plainValue(declaration), declaration.priority]);
53
+ }
54
+ }
55
+ return out;
56
+ }
57
+
58
+ /** True when the declaration block already holds exactly the attribute's declarations. */
59
+ function inSync(el: Styled, wanted: Map<string, [string, string]>): boolean {
60
+ const { style } = el;
61
+ if (style.length !== wanted.size) return false;
62
+ for (const [name, [value, priority]] of wanted) {
63
+ if (
64
+ style.getPropertyValue(name).trim() !== value.trim() ||
65
+ style.getPropertyPriority(name) !== priority
66
+ ) {
67
+ return false;
68
+ }
69
+ }
70
+ return true;
71
+ }
72
+
73
+ /** Writes `el`'s `style` attribute into its declaration block through the CSSOM. No-op when the block already matches. */
74
+ function applyInlineStyles(el: Element): void {
75
+ if (!("style" in el) || el.getAttribute("data-ui-guard") === "off") return;
76
+ const styled = el as Styled;
77
+ const wanted = declared(el.getAttribute("style") ?? "");
78
+ if (inSync(styled, wanted)) return;
79
+ // a blocked write leaves the previous block behind; the attribute is the truth
80
+ for (const name of [...styled.style].reverse()) styled.style.removeProperty(name);
81
+ for (const [name, [value, priority]] of wanted) styled.style.setProperty(name, value, priority);
82
+ }
83
+
84
+ function applyAll(root: ParentNode): void {
85
+ if (root instanceof Element) applyInlineStyles(root);
86
+ for (const el of root.querySelectorAll("[style]")) applyInlineStyles(el);
87
+ }
88
+
89
+ // --- Observe ---
90
+
91
+ let observer: MutationObserver | null = null;
92
+
93
+ function onMutations(mutations: MutationRecord[]): void {
94
+ for (const mutation of mutations) {
95
+ if (mutation.type === "attributes") applyInlineStyles(mutation.target as Element);
96
+ for (const node of mutation.addedNodes) if (node instanceof Element) applyAll(node);
97
+ }
98
+ }
99
+
100
+ /**
101
+ * @namespace Csp
102
+ * @property {Function} blockedInlineStyles - True when the policy blocks inline style attributes.
103
+ * @property {Function} applyInlineStyles - Applies one element's blocked attribute through the CSSOM.
104
+ * @property {Function} start - Applies every blocked attribute under `root` (default `document.body`) and watches for new ones.
105
+ * @property {Function} stop - Stops watching.
106
+ */
107
+ const Csp = {
108
+ blockedInlineStyles,
109
+ applyInlineStyles,
110
+ start(root: Element = document.body): void {
111
+ Csp.stop();
112
+ applyAll(root);
113
+ observer = new MutationObserver(onMutations);
114
+ observer.observe(root, {
115
+ attributes: true,
116
+ attributeFilter: ["style"],
117
+ childList: true,
118
+ subtree: true,
119
+ });
120
+ },
121
+ stop(): void {
122
+ observer?.disconnect();
123
+ observer = null;
124
+ },
125
+ };
126
+
127
+ // Auto-initialize in the browser once the DOM is ready (index.ts imports this
128
+ // module only when it has already seen a blocked attribute)
129
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
130
+ if (document.readyState === "loading") {
131
+ document.addEventListener("DOMContentLoaded", () => Csp.start());
132
+ } else {
133
+ Csp.start();
134
+ }
135
+ }
136
+
137
+ export { Csp };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @fileoverview Splits a `style` attribute value into declarations.
3
+ * @description One parser for every reader of the attribute text: the
4
+ * formatter (`style-format.ts`), the language server, and the CSP fallback
5
+ * (`csp.ts`). Splits on top-level `;` only, so a `;` inside `url("…")`,
6
+ * `var(--x, …)`, or a quoted string stays in its value. No imports, so a
7
+ * runtime module can use it without pulling in the utility tables.
8
+ */
9
+ /** `[start, end)` offsets into a style value. */
10
+ export type Range = [number, number];
11
+ /** One declaration of a style value, with its parts' offsets (all trimmed). */
12
+ export interface ScannedDeclaration {
13
+ /** The whole declaration. */
14
+ span: Range;
15
+ /** The name; a declaration still being typed (`--p`) is all name. */
16
+ name: string;
17
+ nameSpan: Range;
18
+ /** Offset of the colon, or -1 when there is none yet. */
19
+ colon: number;
20
+ /** The value as written, `!important` included. */
21
+ value: string;
22
+ /** Empty (`[colon + 1, colon + 1]`) when nothing follows the colon. */
23
+ valueSpan: Range;
24
+ /** `"important"` when the value ends in `!important`, else `""` (what `setProperty` takes). */
25
+ priority: "" | "important";
26
+ }
27
+ /**
28
+ * Scans a style value into declarations, splitting on top-level `;` (not inside
29
+ * parentheses or quotes). Empty segments are skipped.
30
+ */
31
+ export declare function scanDeclarations(value: string): ScannedDeclaration[];
32
+ /** Splits a style value on top-level `;`, ignoring ones inside parentheses or quotes. */
33
+ export declare function splitDeclarations(value: string): string[];
34
+ /** A declaration's value without its `!important`, for `setProperty(name, value, priority)`. */
35
+ export declare function plainValue({ value }: ScannedDeclaration): string;
36
+ //# sourceMappingURL=declarations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declarations.d.ts","sourceRoot":"","sources":["declarations.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAIH,iDAAiD;AACjD,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAErC,+EAA+E;AAC/E,MAAM,WAAW,kBAAkB;IACjC,6BAA6B;IAC7B,IAAI,EAAE,KAAK,CAAC;IACZ,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,KAAK,CAAC;IAChB,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,SAAS,EAAE,KAAK,CAAC;IACjB,+FAA+F;IAC/F,QAAQ,EAAE,EAAE,GAAG,WAAW,CAAC;CAC5B;AAWD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAwCpE;AAED,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAEzD;AAED,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,kBAAkB,GAAG,MAAM,CAEhE"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /** Trims `[start, end)` of `text` to its non-whitespace extent. */
3
+ function trimRange(text, start, end) {
4
+ while (start < end && /\s/.test(text[start]))
5
+ start++;
6
+ while (end > start && /\s/.test(text[end - 1]))
7
+ end--;
8
+ return [start, end];
9
+ }
10
+ const IMPORTANT = /!\s*important$/i;
11
+ /**
12
+ * Scans a style value into declarations, splitting on top-level `;` (not inside
13
+ * parentheses or quotes). Empty segments are skipped.
14
+ */
15
+ export function scanDeclarations(value) {
16
+ const found = [];
17
+ const push = (from, to) => {
18
+ const span = trimRange(value, from, to);
19
+ if (span[0] === span[1])
20
+ return;
21
+ const colon = value.indexOf(":", span[0]);
22
+ const hasColon = colon !== -1 && colon < span[1];
23
+ const nameSpan = hasColon ? trimRange(value, span[0], colon) : span;
24
+ const valueSpan = hasColon
25
+ ? trimRange(value, colon + 1, span[1])
26
+ : [span[1], span[1]];
27
+ const text = value.slice(...valueSpan);
28
+ found.push({
29
+ span,
30
+ name: value.slice(...nameSpan),
31
+ nameSpan,
32
+ colon: hasColon ? colon : -1,
33
+ value: text,
34
+ valueSpan,
35
+ priority: IMPORTANT.test(text) ? "important" : "",
36
+ });
37
+ };
38
+ let depth = 0;
39
+ let quote = null;
40
+ let start = 0;
41
+ for (let i = 0; i < value.length; i++) {
42
+ const ch = value[i];
43
+ if (quote) {
44
+ if (ch === "\\")
45
+ i++;
46
+ else if (ch === quote)
47
+ quote = null;
48
+ }
49
+ else if (ch === '"' || ch === "'")
50
+ quote = ch;
51
+ else if (ch === "(")
52
+ depth++;
53
+ else if (ch === ")")
54
+ depth = Math.max(0, depth - 1);
55
+ else if (ch === ";" && depth === 0) {
56
+ push(start, i);
57
+ start = i + 1;
58
+ }
59
+ }
60
+ push(start, value.length);
61
+ return found;
62
+ }
63
+ /** Splits a style value on top-level `;`, ignoring ones inside parentheses or quotes. */
64
+ export function splitDeclarations(value) {
65
+ return scanDeclarations(value).map(({ span }) => value.slice(...span));
66
+ }
67
+ /** A declaration's value without its `!important`, for `setProperty(name, value, priority)`. */
68
+ export function plainValue({ value }) {
69
+ return value.replace(IMPORTANT, "").trimEnd();
70
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @fileoverview Splits a `style` attribute value into declarations.
5
+ * @description One parser for every reader of the attribute text: the
6
+ * formatter (`style-format.ts`), the language server, and the CSP fallback
7
+ * (`csp.ts`). Splits on top-level `;` only, so a `;` inside `url("…")`,
8
+ * `var(--x, …)`, or a quoted string stays in its value. No imports, so a
9
+ * runtime module can use it without pulling in the utility tables.
10
+ */
11
+
12
+ // --- Declarations ---
13
+
14
+ /** `[start, end)` offsets into a style value. */
15
+ export type Range = [number, number];
16
+
17
+ /** One declaration of a style value, with its parts' offsets (all trimmed). */
18
+ export interface ScannedDeclaration {
19
+ /** The whole declaration. */
20
+ span: Range;
21
+ /** The name; a declaration still being typed (`--p`) is all name. */
22
+ name: string;
23
+ nameSpan: Range;
24
+ /** Offset of the colon, or -1 when there is none yet. */
25
+ colon: number;
26
+ /** The value as written, `!important` included. */
27
+ value: string;
28
+ /** Empty (`[colon + 1, colon + 1]`) when nothing follows the colon. */
29
+ valueSpan: Range;
30
+ /** `"important"` when the value ends in `!important`, else `""` (what `setProperty` takes). */
31
+ priority: "" | "important";
32
+ }
33
+
34
+ /** Trims `[start, end)` of `text` to its non-whitespace extent. */
35
+ function trimRange(text: string, start: number, end: number): Range {
36
+ while (start < end && /\s/.test(text[start]!)) start++;
37
+ while (end > start && /\s/.test(text[end - 1]!)) end--;
38
+ return [start, end];
39
+ }
40
+
41
+ const IMPORTANT = /!\s*important$/i;
42
+
43
+ /**
44
+ * Scans a style value into declarations, splitting on top-level `;` (not inside
45
+ * parentheses or quotes). Empty segments are skipped.
46
+ */
47
+ export function scanDeclarations(value: string): ScannedDeclaration[] {
48
+ const found: ScannedDeclaration[] = [];
49
+ const push = (from: number, to: number) => {
50
+ const span = trimRange(value, from, to);
51
+ if (span[0] === span[1]) return;
52
+ const colon = value.indexOf(":", span[0]);
53
+ const hasColon = colon !== -1 && colon < span[1];
54
+ const nameSpan = hasColon ? trimRange(value, span[0], colon) : span;
55
+ const valueSpan = hasColon
56
+ ? trimRange(value, colon + 1, span[1])
57
+ : ([span[1], span[1]] as Range);
58
+ const text = value.slice(...valueSpan);
59
+ found.push({
60
+ span,
61
+ name: value.slice(...nameSpan),
62
+ nameSpan,
63
+ colon: hasColon ? colon : -1,
64
+ value: text,
65
+ valueSpan,
66
+ priority: IMPORTANT.test(text) ? "important" : "",
67
+ });
68
+ };
69
+ let depth = 0;
70
+ let quote: string | null = null;
71
+ let start = 0;
72
+ for (let i = 0; i < value.length; i++) {
73
+ const ch = value[i]!;
74
+ if (quote) {
75
+ if (ch === "\\") i++;
76
+ else if (ch === quote) quote = null;
77
+ } else if (ch === '"' || ch === "'") quote = ch;
78
+ else if (ch === "(") depth++;
79
+ else if (ch === ")") depth = Math.max(0, depth - 1);
80
+ else if (ch === ";" && depth === 0) {
81
+ push(start, i);
82
+ start = i + 1;
83
+ }
84
+ }
85
+ push(start, value.length);
86
+ return found;
87
+ }
88
+
89
+ /** Splits a style value on top-level `;`, ignoring ones inside parentheses or quotes. */
90
+ export function splitDeclarations(value: string): string[] {
91
+ return scanDeclarations(value).map(({ span }) => value.slice(...span));
92
+ }
93
+
94
+ /** A declaration's value without its `!important`, for `setProperty(name, value, priority)`. */
95
+ export function plainValue({ value }: ScannedDeclaration): string {
96
+ return value.replace(IMPORTANT, "").trimEnd();
97
+ }
@@ -1,25 +1,6 @@
1
- /** `[start, end)` offsets into a style value. */
2
- export type Range = [number, number];
3
- /** One declaration of a style value, with its parts' offsets (all trimmed). */
4
- export interface ScannedDeclaration {
5
- /** The whole declaration. */
6
- span: Range;
7
- /** The name; a declaration still being typed (`--p`) is all name. */
8
- name: string;
9
- nameSpan: Range;
10
- /** Offset of the colon, or -1 when there is none yet. */
11
- colon: number;
12
- value: string;
13
- /** Empty (`[colon + 1, colon + 1]`) when nothing follows the colon. */
14
- valueSpan: Range;
15
- }
16
- /**
17
- * Scans a style value into declarations, splitting on top-level `;` (not inside
18
- * parentheses or quotes). Empty segments are skipped.
19
- */
20
- export declare function scanDeclarations(value: string): ScannedDeclaration[];
21
- /** Splits a style value on top-level `;`, ignoring ones inside parentheses or quotes. */
22
- export declare function splitDeclarations(value: string): string[];
1
+ import { scanDeclarations, splitDeclarations } from "./declarations.ts";
2
+ export { scanDeclarations, splitDeclarations };
3
+ export type { Range, ScannedDeclaration } from "./declarations.ts";
23
4
  /** `--px :6` → `--px: 6`. A declaration without a colon is kept as written. */
24
5
  export declare function normalize(declaration: string): string;
25
6
  /** Declarations in cascade order (a stable sort). */
@@ -1 +1 @@
1
- {"version":3,"file":"style-format.d.ts","sourceRoot":"","sources":["style-format.ts"],"names":[],"mappings":"AAgCA,iDAAiD;AACjD,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAErC,+EAA+E;AAC/E,MAAM,WAAW,kBAAkB;IACjC,6BAA6B;IAC7B,IAAI,EAAE,KAAK,CAAC;IACZ,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,KAAK,CAAC;IAChB,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,SAAS,EAAE,KAAK,CAAC;CAClB;AASD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAsCpE;AAED,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAEzD;AAsBD,+EAA+E;AAC/E,wBAAgB,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAIrD;AA8BD,qDAAqD;AACrD,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAGlE;AAID;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAM1E"}
1
+ {"version":3,"file":"style-format.d.ts","sourceRoot":"","sources":["style-format.ts"],"names":[],"mappings":"AAiCA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,CAAC;AAC/C,YAAY,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAsBnE,+EAA+E;AAC/E,wBAAgB,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAIrD;AA8BD,qDAAqD;AACrD,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAGlE;AAID;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAM1E"}
@@ -18,68 +18,10 @@
18
18
  * keeps its winner and raw shorthands keep their place before longhands.
19
19
  */
20
20
  import { BREAKPOINTS, PSEUDO_ONLY, PSEUDO_SIDES, STATES, UTILITIES, parseUtilityName, } from "./utilities.js";
21
- /** Trims `[start, end)` of `text` to its non-whitespace extent. */
22
- function trimRange(text, start, end) {
23
- while (start < end && /\s/.test(text[start]))
24
- start++;
25
- while (end > start && /\s/.test(text[end - 1]))
26
- end--;
27
- return [start, end];
28
- }
29
- /**
30
- * Scans a style value into declarations, splitting on top-level `;` (not inside
31
- * parentheses or quotes). Empty segments are skipped.
32
- */
33
- export function scanDeclarations(value) {
34
- const found = [];
35
- const push = (from, to) => {
36
- const span = trimRange(value, from, to);
37
- if (span[0] === span[1])
38
- return;
39
- const colon = value.indexOf(":", span[0]);
40
- const hasColon = colon !== -1 && colon < span[1];
41
- const nameSpan = hasColon ? trimRange(value, span[0], colon) : span;
42
- const valueSpan = hasColon
43
- ? trimRange(value, colon + 1, span[1])
44
- : [span[1], span[1]];
45
- found.push({
46
- span,
47
- name: value.slice(...nameSpan),
48
- nameSpan,
49
- colon: hasColon ? colon : -1,
50
- value: value.slice(...valueSpan),
51
- valueSpan,
52
- });
53
- };
54
- let depth = 0;
55
- let quote = null;
56
- let start = 0;
57
- for (let i = 0; i < value.length; i++) {
58
- const ch = value[i];
59
- if (quote) {
60
- if (ch === "\\")
61
- i++;
62
- else if (ch === quote)
63
- quote = null;
64
- }
65
- else if (ch === '"' || ch === "'")
66
- quote = ch;
67
- else if (ch === "(")
68
- depth++;
69
- else if (ch === ")")
70
- depth = Math.max(0, depth - 1);
71
- else if (ch === ";" && depth === 0) {
72
- push(start, i);
73
- start = i + 1;
74
- }
75
- }
76
- push(start, value.length);
77
- return found;
78
- }
79
- /** Splits a style value on top-level `;`, ignoring ones inside parentheses or quotes. */
80
- export function splitDeclarations(value) {
81
- return scanDeclarations(value).map(({ span }) => value.slice(...span));
82
- }
21
+ // --- Declarations ---
22
+ // the parser lives in declarations.ts (no imports) so the CSP fallback can share it
23
+ import { scanDeclarations, splitDeclarations } from "./declarations.js";
24
+ export { scanDeclarations, splitDeclarations };
83
25
  /** Collapses whitespace runs to one space, outside quotes. */
84
26
  function collapse(text) {
85
27
  let out = "";
@@ -30,78 +30,11 @@ import {
30
30
 
31
31
  // --- Declarations ---
32
32
 
33
- /** `[start, end)` offsets into a style value. */
34
- export type Range = [number, number];
33
+ // the parser lives in declarations.ts (no imports) so the CSP fallback can share it
34
+ import { scanDeclarations, splitDeclarations } from "./declarations.ts";
35
35
 
36
- /** One declaration of a style value, with its parts' offsets (all trimmed). */
37
- export interface ScannedDeclaration {
38
- /** The whole declaration. */
39
- span: Range;
40
- /** The name; a declaration still being typed (`--p`) is all name. */
41
- name: string;
42
- nameSpan: Range;
43
- /** Offset of the colon, or -1 when there is none yet. */
44
- colon: number;
45
- value: string;
46
- /** Empty (`[colon + 1, colon + 1]`) when nothing follows the colon. */
47
- valueSpan: Range;
48
- }
49
-
50
- /** Trims `[start, end)` of `text` to its non-whitespace extent. */
51
- function trimRange(text: string, start: number, end: number): Range {
52
- while (start < end && /\s/.test(text[start]!)) start++;
53
- while (end > start && /\s/.test(text[end - 1]!)) end--;
54
- return [start, end];
55
- }
56
-
57
- /**
58
- * Scans a style value into declarations, splitting on top-level `;` (not inside
59
- * parentheses or quotes). Empty segments are skipped.
60
- */
61
- export function scanDeclarations(value: string): ScannedDeclaration[] {
62
- const found: ScannedDeclaration[] = [];
63
- const push = (from: number, to: number) => {
64
- const span = trimRange(value, from, to);
65
- if (span[0] === span[1]) return;
66
- const colon = value.indexOf(":", span[0]);
67
- const hasColon = colon !== -1 && colon < span[1];
68
- const nameSpan = hasColon ? trimRange(value, span[0], colon) : span;
69
- const valueSpan = hasColon
70
- ? trimRange(value, colon + 1, span[1])
71
- : ([span[1], span[1]] as Range);
72
- found.push({
73
- span,
74
- name: value.slice(...nameSpan),
75
- nameSpan,
76
- colon: hasColon ? colon : -1,
77
- value: value.slice(...valueSpan),
78
- valueSpan,
79
- });
80
- };
81
- let depth = 0;
82
- let quote: string | null = null;
83
- let start = 0;
84
- for (let i = 0; i < value.length; i++) {
85
- const ch = value[i]!;
86
- if (quote) {
87
- if (ch === "\\") i++;
88
- else if (ch === quote) quote = null;
89
- } else if (ch === '"' || ch === "'") quote = ch;
90
- else if (ch === "(") depth++;
91
- else if (ch === ")") depth = Math.max(0, depth - 1);
92
- else if (ch === ";" && depth === 0) {
93
- push(start, i);
94
- start = i + 1;
95
- }
96
- }
97
- push(start, value.length);
98
- return found;
99
- }
100
-
101
- /** Splits a style value on top-level `;`, ignoring ones inside parentheses or quotes. */
102
- export function splitDeclarations(value: string): string[] {
103
- return scanDeclarations(value).map(({ span }) => value.slice(...span));
104
- }
36
+ export { scanDeclarations, splitDeclarations };
37
+ export type { Range, ScannedDeclaration } from "./declarations.ts";
105
38
 
106
39
  /** Collapses whitespace runs to one space, outside quotes. */
107
40
  function collapse(text: string): string {
@@ -1 +1 @@
1
- {"version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G,SAAS,MAAM,EAAE,CAM3D;AAED,qDAAqD;AACrD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,IAAI,CAAC;CACd;AAID,sGAAsG;AACtG,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAyBzD"}
@@ -179,6 +179,22 @@ export const SIZING_KEYWORDS = ["auto", "fit-content", "min-content", "max-conte
179
179
  export const MARGIN_KEYWORDS = ["auto"];
180
180
  /** A layout places its children; a tier-only column utility there keeps the band below the tier. */
181
181
  const LAYOUT_CHILDREN = ["ui-layout > *", '[data-ui~="layout"] > *'];
182
+ /**
183
+ * Elements the reset or the prose scope pads (a prose list's indent, a quote's
184
+ * inset, inline code, form controls): a tier-only padding utility there would
185
+ * zero that padding below the tier, so they keep the base requirement.
186
+ */
187
+ const BASE_PADDED = [
188
+ '[data-ui~="prose"] :is(ul, ol, dd, blockquote, cite)',
189
+ "code",
190
+ "button",
191
+ "input",
192
+ "select",
193
+ "textarea",
194
+ "optgroup",
195
+ ];
196
+ /** Elements the reset paints: a tier-only `--bg` there would clear the paint below the tier. */
197
+ const BASE_PAINTED = ["code", "hr"];
182
198
  /**
183
199
  * Track-list keywords `--grid-cols` / `--grid-rows` take besides a count. `none`
184
200
  * is not one: `--template-cols: none` says the same, and every keyword
@@ -350,26 +366,25 @@ export const UTILITIES = [
350
366
  family: "grid",
351
367
  emit: "grid-fit",
352
368
  },
353
- // spacing: dual mode; gap is on the no-base allowlist
354
- { name: "p", pseudo: true, properties: ["padding"], mode: "dual", family: "spacing" },
355
- { name: "px", pseudo: true, properties: ["padding-inline"], mode: "dual", family: "spacing" },
356
- { name: "py", pseudo: true, properties: ["padding-block"], mode: "dual", family: "spacing" },
357
- {
358
- name: "pt",
359
- pseudo: true,
360
- properties: ["padding-block-start"],
361
- mode: "dual",
362
- family: "spacing",
363
- },
364
- { name: "pb", pseudo: true, properties: ["padding-block-end"], mode: "dual", family: "spacing" },
365
- {
366
- name: "pl",
369
+ // spacing: dual mode; padding and gap are on the no-base allowlist (the reset
370
+ // zeroes padding, so `--px--md: 8` alone pads from md), except where the base pads
371
+ ...[
372
+ ["p", "padding"],
373
+ ["px", "padding-inline"],
374
+ ["py", "padding-block"],
375
+ ["pt", "padding-block-start"],
376
+ ["pb", "padding-block-end"],
377
+ ["pl", "padding-inline-start"],
378
+ ["pr", "padding-inline-end"],
379
+ ].map(([name, property]) => ({
380
+ name,
367
381
  pseudo: true,
368
- properties: ["padding-inline-start"],
382
+ properties: [property],
369
383
  mode: "dual",
370
384
  family: "spacing",
371
- },
372
- { name: "pr", pseudo: true, properties: ["padding-inline-end"], mode: "dual", family: "spacing" },
385
+ noBase: "0",
386
+ noBaseExclude: BASE_PADDED,
387
+ })),
373
388
  { name: "gap", properties: ["gap"], mode: "dual", family: "spacing", noBase: "0" },
374
389
  { name: "gap-x", properties: ["column-gap"], mode: "dual", family: "spacing", noBase: "0" },
375
390
  { name: "gap-y", properties: ["row-gap"], mode: "dual", family: "spacing", noBase: "0" },
@@ -556,6 +571,7 @@ export const UTILITIES = [
556
571
  { name: "whitespace", properties: ["white-space"], mode: "keyword", family: "typography" },
557
572
  // color: states; bg-alpha feeds the bg emission
558
573
  { name: "text", properties: ["color"], mode: "raw", family: "color", pseudo: true },
574
+ // on the no-base allowlist: a plain element is transparent, so `--bg--hover` alone paints on hover
559
575
  {
560
576
  name: "bg",
561
577
  properties: ["background-color"],
@@ -563,6 +579,8 @@ export const UTILITIES = [
563
579
  family: "color",
564
580
  emit: "bg",
565
581
  pseudo: true,
582
+ noBase: "transparent",
583
+ noBaseExclude: BASE_PAINTED,
566
584
  },
567
585
  { name: "bg-alpha", properties: [], mode: "raw", family: "color", emit: "none" },
568
586
  // gradients: the type utility carries the prelude (direction, shape, position,