@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
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
:where([style*="--xl:"]) {
|
|
7
7
|
--_display-xl: var(--display--xl);
|
|
8
8
|
--_position-xl: var(--position--xl);
|
|
9
|
+
--_anchor-name-xl: var(--anchor-name--xl);
|
|
10
|
+
--_position-anchor-xl: var(--position-anchor--xl);
|
|
11
|
+
--_position-area-xl: var(--position-area--xl);
|
|
9
12
|
--_flex-wrap-xl: var(--flex-wrap--xl);
|
|
10
|
-
--_shrink-xl: var(--shrink--xl);
|
|
11
13
|
--_grid-flow-xl: var(--grid-flow--xl);
|
|
12
14
|
--_auto-cols-xl: var(--auto-cols--xl);
|
|
13
15
|
--_auto-rows-xl: var(--auto-rows--xl);
|
|
@@ -17,6 +19,7 @@
|
|
|
17
19
|
--_place-content-xl: var(--place-content--xl);
|
|
18
20
|
--_self-xl: var(--self--xl);
|
|
19
21
|
--_flex-xl: var(--flex--xl);
|
|
22
|
+
--_shrink-xl: var(--shrink--xl);
|
|
20
23
|
--_basis-xl: var(--basis--xl);
|
|
21
24
|
--_order-xl: var(--order--xl);
|
|
22
25
|
--_band-xl: var(--band--xl);
|
|
@@ -85,9 +85,6 @@
|
|
|
85
85
|
--_text-align: var(--text-align);
|
|
86
86
|
text-align: var(--_text-align-resolved);
|
|
87
87
|
}
|
|
88
|
-
:where(:is([style*="--text-align:"], [style*="--text-align--"], [style*="--group-text-align--"]):not(ui-accordion, ui-autocomplete, ui-button-group, ui-carousel, ui-combobox, ui-command, ui-kbd-group, ui-layout, ui-lightbox, ui-menu, ui-multiselect, ui-otp, ui-password, ui-tabs, ui-toaster, ui-toggle-group, ui-tooltip, [data-ui~="accordion"], [data-ui~="alert-dialog"], [data-ui~="autocomplete"], [data-ui~="badge"], [data-ui~="button"], [data-ui~="button-group"], [data-ui~="callout"], [data-ui~="card"], [data-ui~="carousel"], [data-ui~="combobox"], [data-ui~="command"], [data-ui~="dialog"], [data-ui~="field"], [data-ui~="field-group"], [data-ui~="input"], [data-ui~="input-group"], [data-ui~="kbd-group"], [data-ui~="layout"], [data-ui~="lightbox"], [data-ui~="menu"], [data-ui~="meter"], [data-ui~="mobile-menu"], [data-ui~="multiselect"], [data-ui~="navigation-menu"], [data-ui~="otp"], [data-ui~="password-group"], [data-ui~="progress"], [data-ui~="radio"], [data-ui~="radio-group"], [data-ui~="scroll-fade"], [data-ui~="select"], [data-ui~="separator"], [data-ui~="table"], [data-ui~="tabs"], [data-ui~="textarea"], [data-ui~="toaster"], [data-ui~="toggle"], [data-ui~="toggle-group"], [data-ui~="tooltip"])) {
|
|
89
|
-
text-align: var(--_text-align-resolved, start);
|
|
90
|
-
}
|
|
91
88
|
|
|
92
89
|
:where([style*="--text-transform:"], [style*="--text-transform--"]) {
|
|
93
90
|
--_text-transform-resolved: var(--_text-transform-2xl, var(--_text-transform-xl, var(--_text-transform-lg, var(--_text-transform-md, var(--_text-transform-sm, var(--_text-transform))))));
|
|
@@ -104,9 +101,6 @@
|
|
|
104
101
|
--_text-wrap: var(--text-wrap);
|
|
105
102
|
text-wrap: var(--_text-wrap-resolved);
|
|
106
103
|
}
|
|
107
|
-
:where(:is([style*="--text-wrap:"], [style*="--text-wrap--"], [style*="--group-text-wrap--"]):not(ui-accordion, ui-autocomplete, ui-button-group, ui-carousel, ui-combobox, ui-command, ui-kbd-group, ui-layout, ui-lightbox, ui-menu, ui-multiselect, ui-otp, ui-password, ui-tabs, ui-toaster, ui-toggle-group, ui-tooltip, [data-ui~="accordion"], [data-ui~="alert-dialog"], [data-ui~="autocomplete"], [data-ui~="badge"], [data-ui~="button"], [data-ui~="button-group"], [data-ui~="callout"], [data-ui~="card"], [data-ui~="carousel"], [data-ui~="combobox"], [data-ui~="command"], [data-ui~="dialog"], [data-ui~="field"], [data-ui~="field-group"], [data-ui~="input"], [data-ui~="input-group"], [data-ui~="kbd-group"], [data-ui~="layout"], [data-ui~="lightbox"], [data-ui~="menu"], [data-ui~="meter"], [data-ui~="mobile-menu"], [data-ui~="multiselect"], [data-ui~="navigation-menu"], [data-ui~="otp"], [data-ui~="password-group"], [data-ui~="progress"], [data-ui~="radio"], [data-ui~="radio-group"], [data-ui~="scroll-fade"], [data-ui~="select"], [data-ui~="separator"], [data-ui~="table"], [data-ui~="tabs"], [data-ui~="textarea"], [data-ui~="toaster"], [data-ui~="toggle"], [data-ui~="toggle-group"], [data-ui~="tooltip"])) {
|
|
108
|
-
text-wrap: var(--_text-wrap-resolved, wrap);
|
|
109
|
-
}
|
|
110
104
|
|
|
111
105
|
:where([style*="--line-clamp:"], [style*="--line-clamp--"]) {
|
|
112
106
|
--_line-clamp-resolved: var(--_line-clamp-2xl, var(--_line-clamp-xl, var(--_line-clamp-lg, var(--_line-clamp-md, var(--_line-clamp-sm, var(--_line-clamp))))));
|
|
@@ -126,9 +120,6 @@
|
|
|
126
120
|
--_text-decoration: var(--text-decoration);
|
|
127
121
|
text-decoration-line: var(--_text-decoration-resolved);
|
|
128
122
|
}
|
|
129
|
-
:where(:is([style*="--text-decoration:"], [style*="--text-decoration--"], [style*="--group-text-decoration--"]):not(ui-accordion, ui-autocomplete, ui-button-group, ui-carousel, ui-combobox, ui-command, ui-kbd-group, ui-layout, ui-lightbox, ui-menu, ui-multiselect, ui-otp, ui-password, ui-tabs, ui-toaster, ui-toggle-group, ui-tooltip, [data-ui~="accordion"], [data-ui~="alert-dialog"], [data-ui~="autocomplete"], [data-ui~="badge"], [data-ui~="button"], [data-ui~="button-group"], [data-ui~="callout"], [data-ui~="card"], [data-ui~="carousel"], [data-ui~="combobox"], [data-ui~="command"], [data-ui~="dialog"], [data-ui~="field"], [data-ui~="field-group"], [data-ui~="input"], [data-ui~="input-group"], [data-ui~="kbd-group"], [data-ui~="layout"], [data-ui~="lightbox"], [data-ui~="menu"], [data-ui~="meter"], [data-ui~="mobile-menu"], [data-ui~="multiselect"], [data-ui~="navigation-menu"], [data-ui~="otp"], [data-ui~="password-group"], [data-ui~="progress"], [data-ui~="radio"], [data-ui~="radio-group"], [data-ui~="scroll-fade"], [data-ui~="select"], [data-ui~="separator"], [data-ui~="table"], [data-ui~="tabs"], [data-ui~="textarea"], [data-ui~="toaster"], [data-ui~="toggle"], [data-ui~="toggle-group"], [data-ui~="tooltip"])) {
|
|
130
|
-
text-decoration-line: var(--_text-decoration-resolved, none);
|
|
131
|
-
}
|
|
132
123
|
|
|
133
124
|
:where([style*="--whitespace:"], [style*="--whitespace--"]) {
|
|
134
125
|
--_whitespace-resolved: var(--_whitespace-2xl, var(--_whitespace-xl, var(--_whitespace-lg, var(--_whitespace-md, var(--_whitespace-sm, var(--_whitespace))))));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** True when the document's policy blocks inline style attributes (some styled element has an empty declaration block). */
|
|
2
|
+
declare function blockedInlineStyles(root?: ParentNode): boolean;
|
|
3
|
+
/** Writes `el`'s `style` attribute into its declaration block through the CSSOM. No-op when the block already matches. */
|
|
4
|
+
declare function applyInlineStyles(el: Element): void;
|
|
5
|
+
/**
|
|
6
|
+
* @namespace Csp
|
|
7
|
+
* @property {Function} blockedInlineStyles - True when the policy blocks inline style attributes.
|
|
8
|
+
* @property {Function} applyInlineStyles - Applies one element's blocked attribute through the CSSOM.
|
|
9
|
+
* @property {Function} start - Applies every blocked attribute under `root` (default `document.body`) and watches for new ones.
|
|
10
|
+
* @property {Function} stop - Stops watching.
|
|
11
|
+
*/
|
|
12
|
+
declare const Csp: {
|
|
13
|
+
blockedInlineStyles: typeof blockedInlineStyles;
|
|
14
|
+
applyInlineStyles: typeof applyInlineStyles;
|
|
15
|
+
start(root?: Element): void;
|
|
16
|
+
stop(): void;
|
|
17
|
+
};
|
|
18
|
+
export { Csp };
|
|
19
|
+
//# sourceMappingURL=csp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csp.d.ts","sourceRoot":"","sources":["csp.ts"],"names":[],"mappings":"AAsCA,2HAA2H;AAC3H,iBAAS,mBAAmB,CAAC,IAAI,GAAE,UAAqB,GAAG,OAAO,CAGjE;AA8BD,0HAA0H;AAC1H,iBAAS,iBAAiB,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAQ5C;AAkBD;;;;;;GAMG;AACH,QAAA,MAAM,GAAG;;;iBAGK,OAAO,GAAmB,IAAI;YAWlC,IAAI;CAIb,CAAC;AAYF,OAAO,EAAE,GAAG,EAAE,CAAC"}
|
package/src/base/csp.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview CSP fallback: applies `style` attributes a Content Security Policy blocked.
|
|
4
|
+
* @description Loaded by `index.ts` only when the page's policy blocks inline
|
|
5
|
+
* style attributes (`style-src-attr` without `'unsafe-inline'`, or a
|
|
6
|
+
* `style-src` without it): the attribute text is still in the DOM, so the
|
|
7
|
+
* kit's `[style*="--p:"]` gates still match, but none of its values apply.
|
|
8
|
+
* CSP does not govern the CSSOM, so this module reads each attribute and
|
|
9
|
+
* writes its declarations with `style.setProperty`, one by one (never
|
|
10
|
+
* `cssText` or `setAttribute`, which the policy blocks), then watches for
|
|
11
|
+
* attributes written later. Utilities then need JavaScript and apply after the
|
|
12
|
+
* module runs; a policy that allows attributes (`style-src-attr
|
|
13
|
+
* 'unsafe-inline'`) needs none of this. `data-ui-guard="off"` opts an element
|
|
14
|
+
* out, as it does for the style guard.
|
|
15
|
+
*
|
|
16
|
+
* Detection never writes a probe: it looks for an element whose attribute
|
|
17
|
+
* holds a declaration while its declaration block is empty, which is what a
|
|
18
|
+
* blocked attribute looks like on load, so the kit never raises a violation
|
|
19
|
+
* report of its own. A blocked write to an element that already has a block
|
|
20
|
+
* (an app's `setAttribute("style", …)` after the fallback ran) leaves the old
|
|
21
|
+
* block in place, so each apply compares the attribute's declarations with
|
|
22
|
+
* the block and rewrites the block only when they differ.
|
|
23
|
+
*/
|
|
24
|
+
import { plainValue, scanDeclarations } from "./declarations.js";
|
|
25
|
+
// --- Detection ---
|
|
26
|
+
/** True when `el` carries a `style` attribute with a declaration that the policy did not apply. */
|
|
27
|
+
function blocked(el) {
|
|
28
|
+
if (!("style" in el))
|
|
29
|
+
return false;
|
|
30
|
+
const text = el.getAttribute("style");
|
|
31
|
+
return !!text && text.includes(":") && el.style.length === 0;
|
|
32
|
+
}
|
|
33
|
+
/** True when the document's policy blocks inline style attributes (some styled element has an empty declaration block). */
|
|
34
|
+
function blockedInlineStyles(root = document) {
|
|
35
|
+
for (const el of root.querySelectorAll("[style]"))
|
|
36
|
+
if (blocked(el))
|
|
37
|
+
return true;
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
// --- Apply ---
|
|
41
|
+
/** name → [value, priority] of the attribute's declarations, as `setProperty` takes them. */
|
|
42
|
+
function declared(text) {
|
|
43
|
+
const out = new Map();
|
|
44
|
+
for (const declaration of scanDeclarations(text)) {
|
|
45
|
+
if (declaration.colon !== -1) {
|
|
46
|
+
out.set(declaration.name, [plainValue(declaration), declaration.priority]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
/** True when the declaration block already holds exactly the attribute's declarations. */
|
|
52
|
+
function inSync(el, wanted) {
|
|
53
|
+
const { style } = el;
|
|
54
|
+
if (style.length !== wanted.size)
|
|
55
|
+
return false;
|
|
56
|
+
for (const [name, [value, priority]] of wanted) {
|
|
57
|
+
if (style.getPropertyValue(name).trim() !== value.trim() ||
|
|
58
|
+
style.getPropertyPriority(name) !== priority) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
/** Writes `el`'s `style` attribute into its declaration block through the CSSOM. No-op when the block already matches. */
|
|
65
|
+
function applyInlineStyles(el) {
|
|
66
|
+
if (!("style" in el) || el.getAttribute("data-ui-guard") === "off")
|
|
67
|
+
return;
|
|
68
|
+
const styled = el;
|
|
69
|
+
const wanted = declared(el.getAttribute("style") ?? "");
|
|
70
|
+
if (inSync(styled, wanted))
|
|
71
|
+
return;
|
|
72
|
+
// a blocked write leaves the previous block behind; the attribute is the truth
|
|
73
|
+
for (const name of [...styled.style].reverse())
|
|
74
|
+
styled.style.removeProperty(name);
|
|
75
|
+
for (const [name, [value, priority]] of wanted)
|
|
76
|
+
styled.style.setProperty(name, value, priority);
|
|
77
|
+
}
|
|
78
|
+
function applyAll(root) {
|
|
79
|
+
if (root instanceof Element)
|
|
80
|
+
applyInlineStyles(root);
|
|
81
|
+
for (const el of root.querySelectorAll("[style]"))
|
|
82
|
+
applyInlineStyles(el);
|
|
83
|
+
}
|
|
84
|
+
// --- Observe ---
|
|
85
|
+
let observer = null;
|
|
86
|
+
function onMutations(mutations) {
|
|
87
|
+
for (const mutation of mutations) {
|
|
88
|
+
if (mutation.type === "attributes")
|
|
89
|
+
applyInlineStyles(mutation.target);
|
|
90
|
+
for (const node of mutation.addedNodes)
|
|
91
|
+
if (node instanceof Element)
|
|
92
|
+
applyAll(node);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @namespace Csp
|
|
97
|
+
* @property {Function} blockedInlineStyles - True when the policy blocks inline style attributes.
|
|
98
|
+
* @property {Function} applyInlineStyles - Applies one element's blocked attribute through the CSSOM.
|
|
99
|
+
* @property {Function} start - Applies every blocked attribute under `root` (default `document.body`) and watches for new ones.
|
|
100
|
+
* @property {Function} stop - Stops watching.
|
|
101
|
+
*/
|
|
102
|
+
const Csp = {
|
|
103
|
+
blockedInlineStyles,
|
|
104
|
+
applyInlineStyles,
|
|
105
|
+
start(root = document.body) {
|
|
106
|
+
Csp.stop();
|
|
107
|
+
applyAll(root);
|
|
108
|
+
observer = new MutationObserver(onMutations);
|
|
109
|
+
observer.observe(root, {
|
|
110
|
+
attributes: true,
|
|
111
|
+
attributeFilter: ["style"],
|
|
112
|
+
childList: true,
|
|
113
|
+
subtree: true,
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
stop() {
|
|
117
|
+
observer?.disconnect();
|
|
118
|
+
observer = null;
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
// Auto-initialize in the browser once the DOM is ready (index.ts imports this
|
|
122
|
+
// module only when it has already seen a blocked attribute)
|
|
123
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
124
|
+
if (document.readyState === "loading") {
|
|
125
|
+
document.addEventListener("DOMContentLoaded", () => Csp.start());
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
Csp.start();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export { Csp };
|
package/src/base/csp.ts
ADDED
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Every selector below, once (rule selectors without state pseudo-classes); the records index it. */
|
|
2
|
+
export declare const KIT_SELECTORS: readonly string[];
|
|
3
|
+
/** For each utility, the elements the kit reads it on through its own chain: a tier alone works there. */
|
|
4
|
+
export declare const TIER_READS: Readonly<Record<string, readonly number[]>>;
|
|
5
|
+
/**
|
|
6
|
+
* For each tier-only utility (a no-base one, or the box-shadow composite's),
|
|
7
|
+
* the elements the kit sets its property on above `@layer defaults`: they keep
|
|
8
|
+
* their own value, and a tier alone applies there only through `TIER_READS`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const TIER_BLOCKS: Readonly<Record<string, readonly number[]>>;
|
|
11
|
+
//# sourceMappingURL=kit-styling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kit-styling.d.ts","sourceRoot":"","sources":["kit-styling.ts"],"names":[],"mappings":"AAEA,sGAAsG;AACtG,eAAO,MAAM,aAAa,EAAE,SAAS,MAAM,EAsQ1C,CAAC;AAEF,0GAA0G;AAC1G,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAoDlE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CA8InE,CAAC"}
|