elit 3.6.5 → 3.6.7
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/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +6 -0
- package/dist/build.cjs +421 -331
- package/dist/build.d.ts +1 -16
- package/dist/build.js +420 -330
- package/dist/build.mjs +420 -330
- package/dist/chokidar.cjs +219 -182
- package/dist/chokidar.d.ts +25 -10
- package/dist/chokidar.js +217 -182
- package/dist/chokidar.mjs +218 -183
- package/dist/cli.cjs +21608 -20241
- package/dist/cli.d.ts +19 -37
- package/dist/cli.mjs +21262 -19910
- package/dist/config.cjs +357 -350
- package/dist/config.d.ts +19 -240
- package/dist/config.js +520 -515
- package/dist/config.mjs +346 -341
- package/dist/contracts-BeW9k0yZ.d.ts +54 -0
- package/dist/contracts-D7KIS-TK.d.ts +36 -0
- package/dist/coverage.cjs +448 -485
- package/dist/coverage.d.ts +13 -59
- package/dist/coverage.js +447 -484
- package/dist/coverage.mjs +447 -484
- package/dist/database.cjs +819 -828
- package/dist/database.d.ts +8 -24
- package/dist/database.js +818 -829
- package/dist/database.mjs +818 -829
- package/dist/desktop-auto-render.cjs +1700 -1522
- package/dist/desktop-auto-render.d.ts +4 -9
- package/dist/desktop-auto-render.js +1695 -1517
- package/dist/desktop-auto-render.mjs +1696 -1518
- package/dist/desktop.cjs +3 -1
- package/dist/desktop.d.ts +4 -1
- package/dist/desktop.js +1 -1
- package/dist/desktop.mjs +1 -1
- package/dist/dev-build.cjs +830 -0
- package/dist/dev-build.d.ts +53 -0
- package/dist/dev-build.js +3318 -0
- package/dist/dev-build.mjs +797 -0
- package/dist/dom.cjs +717 -590
- package/dist/dom.d.ts +2 -15
- package/dist/dom.js +714 -587
- package/dist/dom.mjs +716 -589
- package/dist/el.cjs +62 -52
- package/dist/el.d.ts +5 -10
- package/dist/el.js +60 -52
- package/dist/el.mjs +60 -52
- package/dist/fs.cjs +72 -63
- package/dist/fs.d.ts +22 -19
- package/dist/fs.js +71 -62
- package/dist/fs.mjs +71 -62
- package/dist/hmr.cjs +40 -14
- package/dist/hmr.d.ts +11 -23
- package/dist/hmr.js +38 -14
- package/dist/hmr.mjs +38 -14
- package/dist/http.cjs +251 -99
- package/dist/http.d.ts +38 -104
- package/dist/http.js +249 -99
- package/dist/http.mjs +249 -99
- package/dist/https.cjs +524 -228
- package/dist/https.d.ts +44 -36
- package/dist/https.js +520 -226
- package/dist/https.mjs +522 -228
- package/dist/index.cjs +7502 -7690
- package/dist/index.d.ts +8 -3
- package/dist/index.js +7486 -7676
- package/dist/index.mjs +7497 -7686
- package/dist/mime-types.cjs +10 -4
- package/dist/mime-types.d.ts +8 -11
- package/dist/mime-types.js +9 -3
- package/dist/mime-types.mjs +9 -3
- package/dist/native.cjs +8616 -8869
- package/dist/native.d.ts +7 -8
- package/dist/native.js +8682 -8935
- package/dist/native.mjs +8615 -8868
- package/dist/path.cjs +83 -77
- package/dist/path.d.ts +29 -29
- package/dist/path.js +82 -76
- package/dist/path.mjs +82 -76
- package/dist/pm.cjs +3300 -0
- package/dist/pm.d.ts +256 -0
- package/dist/pm.js +5638 -0
- package/dist/pm.mjs +3196 -0
- package/dist/preview-build.cjs +712 -0
- package/dist/preview-build.d.ts +59 -0
- package/dist/preview-build.js +3194 -0
- package/dist/preview-build.mjs +676 -0
- package/dist/render-context.cjs +13 -2
- package/dist/render-context.d.ts +9 -31
- package/dist/render-context.js +11 -2
- package/dist/render-context.mjs +11 -2
- package/dist/router.cjs +787 -645
- package/dist/router.d.ts +8 -12
- package/dist/router.js +786 -644
- package/dist/router.mjs +786 -644
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/server.cjs +3315 -2603
- package/dist/server.d.ts +49 -4
- package/dist/server.js +7611 -2834
- package/dist/server.mjs +3317 -2607
- package/dist/smtp-server.cjs +128 -0
- package/dist/smtp-server.d.ts +27 -0
- package/dist/smtp-server.js +4199 -0
- package/dist/smtp-server.mjs +100 -0
- package/dist/state-DvEkDehk.d.ts +195 -0
- package/dist/state.cjs +768 -658
- package/dist/state.d.ts +11 -69
- package/dist/state.js +760 -650
- package/dist/state.mjs +767 -657
- package/dist/style.cjs +1011 -968
- package/dist/style.d.ts +13 -127
- package/dist/style.js +1009 -970
- package/dist/style.mjs +1011 -971
- package/dist/test-reporter.cjs +332 -316
- package/dist/test-reporter.d.ts +28 -33
- package/dist/test-reporter.js +328 -312
- package/dist/test-reporter.mjs +328 -312
- package/dist/test-runtime.cjs +927 -968
- package/dist/test-runtime.d.ts +24 -99
- package/dist/test-runtime.js +922 -965
- package/dist/test-runtime.mjs +922 -965
- package/dist/test.cjs +4428 -4273
- package/dist/test.d.ts +2 -8
- package/dist/test.js +4307 -4154
- package/dist/test.mjs +4419 -4267
- package/dist/types-BONVzPtp.d.ts +59 -0
- package/dist/types-BR4wMiVx.d.ts +32 -0
- package/dist/types-C4gKykuG.d.ts +23 -0
- package/dist/types-CIhpN1-K.d.ts +64 -0
- package/dist/types-Ckj8md_j.d.ts +84 -0
- package/dist/types-CpjQTAkX.d.ts +24 -0
- package/dist/types-D0LjrYjS.d.ts +14 -0
- package/dist/types-DAisuVr5.d.ts +75 -0
- package/dist/types-tJn88E1N.d.ts +242 -0
- package/dist/types.d.ts +71 -226
- package/dist/universal.cjs +1 -1
- package/dist/universal.d.ts +1 -5
- package/dist/universal.js +1 -1
- package/dist/universal.mjs +1 -1
- package/dist/websocket-XfyK23zD.d.ts +119 -0
- package/dist/ws.cjs +129 -108
- package/dist/ws.d.ts +21 -131
- package/dist/ws.js +128 -109
- package/dist/ws.mjs +128 -109
- package/dist/wss.cjs +757 -479
- package/dist/wss.d.ts +31 -28
- package/dist/wss.js +755 -479
- package/dist/wss.mjs +758 -482
- package/package.json +16 -1
- package/vendor/epaint-0.31.1/src/image.rs +418 -0
- package/dist/server-CcBFc2F5.d.ts +0 -449
package/dist/style.mjs
CHANGED
|
@@ -1,247 +1,571 @@
|
|
|
1
|
-
// src/style.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
// src/client/style/condition-utils.ts
|
|
2
|
+
function splitConditionalClauses(value, operator) {
|
|
3
|
+
const clauses = [];
|
|
4
|
+
let token = "";
|
|
5
|
+
let depth = 0;
|
|
6
|
+
for (let index = 0; index < value.length; index++) {
|
|
7
|
+
const char = value[index];
|
|
8
|
+
if (char === "(") {
|
|
9
|
+
depth += 1;
|
|
10
|
+
} else if (char === ")" && depth > 0) {
|
|
11
|
+
depth -= 1;
|
|
12
|
+
}
|
|
13
|
+
const operatorToken = ` ${operator} `;
|
|
14
|
+
if (depth === 0 && value.slice(index, index + operatorToken.length).toLowerCase() === operatorToken) {
|
|
15
|
+
const trimmed = token.trim();
|
|
16
|
+
if (trimmed) {
|
|
17
|
+
clauses.push(trimmed);
|
|
18
|
+
}
|
|
19
|
+
token = "";
|
|
20
|
+
index += operatorToken.length - 1;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
token += char;
|
|
21
24
|
}
|
|
22
|
-
|
|
25
|
+
const trailing = token.trim();
|
|
26
|
+
if (trailing) {
|
|
27
|
+
clauses.push(trailing);
|
|
28
|
+
}
|
|
29
|
+
return clauses;
|
|
23
30
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
31
|
+
function matchesSupportsDeclaration(property, value) {
|
|
32
|
+
const normalizedProperty = property.trim().toLowerCase();
|
|
33
|
+
const normalizedValue = value.trim().toLowerCase();
|
|
34
|
+
const supportedProperties = /* @__PURE__ */ new Set([
|
|
35
|
+
"align-items",
|
|
36
|
+
"background",
|
|
37
|
+
"background-color",
|
|
38
|
+
"backdrop-filter",
|
|
39
|
+
"border",
|
|
40
|
+
"border-radius",
|
|
41
|
+
"box-shadow",
|
|
42
|
+
"color",
|
|
43
|
+
"column-gap",
|
|
44
|
+
"container-name",
|
|
45
|
+
"container-type",
|
|
46
|
+
"display",
|
|
47
|
+
"flex",
|
|
48
|
+
"flex-direction",
|
|
49
|
+
"flex-grow",
|
|
50
|
+
"flex-wrap",
|
|
51
|
+
"font-family",
|
|
52
|
+
"font-size",
|
|
53
|
+
"font-weight",
|
|
54
|
+
"gap",
|
|
55
|
+
"grid-template-columns",
|
|
56
|
+
"height",
|
|
57
|
+
"justify-content",
|
|
58
|
+
"letter-spacing",
|
|
59
|
+
"line-height",
|
|
60
|
+
"margin",
|
|
61
|
+
"margin-bottom",
|
|
62
|
+
"margin-left",
|
|
63
|
+
"margin-right",
|
|
64
|
+
"margin-top",
|
|
65
|
+
"max-height",
|
|
66
|
+
"max-width",
|
|
67
|
+
"min-height",
|
|
68
|
+
"min-width",
|
|
69
|
+
"padding",
|
|
70
|
+
"padding-bottom",
|
|
71
|
+
"padding-end",
|
|
72
|
+
"padding-horizontal",
|
|
73
|
+
"padding-left",
|
|
74
|
+
"padding-right",
|
|
75
|
+
"padding-start",
|
|
76
|
+
"padding-top",
|
|
77
|
+
"padding-vertical",
|
|
78
|
+
"row-gap",
|
|
79
|
+
"text-align",
|
|
80
|
+
"text-decoration",
|
|
81
|
+
"text-transform",
|
|
82
|
+
"width"
|
|
83
|
+
]);
|
|
84
|
+
if (!supportedProperties.has(normalizedProperty)) {
|
|
85
|
+
return false;
|
|
50
86
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const cssVar = {
|
|
54
|
-
name: name.startsWith("--") ? name : `--${name}`,
|
|
55
|
-
value,
|
|
56
|
-
toString() {
|
|
57
|
-
return `var(${this.name})`;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
this.variables.push(cssVar);
|
|
61
|
-
return cssVar;
|
|
87
|
+
if (normalizedProperty === "display") {
|
|
88
|
+
return (/* @__PURE__ */ new Set(["block", "flex", "grid", "inline", "inline-block", "inline-flex", "inline-grid"])).has(normalizedValue);
|
|
62
89
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return fallback ? `var(${varName}, ${fallback})` : `var(${varName})`;
|
|
90
|
+
if (normalizedProperty === "backdrop-filter") {
|
|
91
|
+
return /blur\(/.test(normalizedValue);
|
|
66
92
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const rule = { selector: tag, styles: styles2, type: "tag" };
|
|
70
|
-
this.rules.push(rule);
|
|
71
|
-
return rule;
|
|
93
|
+
if (normalizedProperty === "container-type") {
|
|
94
|
+
return (/* @__PURE__ */ new Set(["inline-size", "size"])).has(normalizedValue);
|
|
72
95
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
function matchesSupportsCondition(condition) {
|
|
99
|
+
const normalized = condition.trim().replace(/^\(+|\)+$/g, "").trim();
|
|
100
|
+
if (!normalized) {
|
|
101
|
+
return true;
|
|
78
102
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const rule = { selector, styles: styles2, type: "id" };
|
|
82
|
-
this.rules.push(rule);
|
|
83
|
-
return rule;
|
|
103
|
+
if (normalized.toLowerCase().startsWith("not ")) {
|
|
104
|
+
return !matchesSupportsCondition(normalized.slice(4));
|
|
84
105
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const selector = baseSelector ? `${baseSelector}${pseudoClass}` : pseudoClass;
|
|
89
|
-
const rule = { selector, styles: styles2, type: "pseudo-class" };
|
|
90
|
-
this.rules.push(rule);
|
|
91
|
-
return rule;
|
|
106
|
+
const orClauses = splitConditionalClauses(normalized, "or");
|
|
107
|
+
if (orClauses.length > 1) {
|
|
108
|
+
return orClauses.some((clause) => matchesSupportsCondition(clause));
|
|
92
109
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const rule = { selector, styles: styles2, type: "pseudo-element" };
|
|
97
|
-
this.rules.push(rule);
|
|
98
|
-
return rule;
|
|
110
|
+
const andClauses = splitConditionalClauses(normalized, "and");
|
|
111
|
+
if (andClauses.length > 1) {
|
|
112
|
+
return andClauses.every((clause) => matchesSupportsCondition(clause));
|
|
99
113
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const selector = baseSelector ? `${baseSelector}${attrSelector}` : attrSelector;
|
|
104
|
-
const rule = { selector, styles: styles2, type: "attribute" };
|
|
105
|
-
this.rules.push(rule);
|
|
106
|
-
return rule;
|
|
114
|
+
const declarationMatch = normalized.match(/^([a-z-]+)\s*:\s*(.+)$/i);
|
|
115
|
+
if (!declarationMatch) {
|
|
116
|
+
return false;
|
|
107
117
|
}
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
return matchesSupportsDeclaration(declarationMatch[1], declarationMatch[2]);
|
|
119
|
+
}
|
|
120
|
+
function findMatchingContainerTarget(ancestors, name) {
|
|
121
|
+
const normalizedName = typeof name === "string" && name.trim() ? name.trim().toLowerCase() : void 0;
|
|
122
|
+
for (let index = ancestors.length - 1; index >= 0; index--) {
|
|
123
|
+
const ancestor = ancestors[index];
|
|
124
|
+
if (!ancestor?.isContainer || ancestor.containerWidth === void 0) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (!normalizedName) {
|
|
128
|
+
return ancestor;
|
|
129
|
+
}
|
|
130
|
+
if ((ancestor.containerNames ?? []).includes(normalizedName)) {
|
|
131
|
+
return ancestor;
|
|
132
|
+
}
|
|
110
133
|
}
|
|
111
|
-
|
|
112
|
-
|
|
134
|
+
return void 0;
|
|
135
|
+
}
|
|
136
|
+
function matchesContainerCondition(condition, containerWidth) {
|
|
137
|
+
const normalized = condition.trim().replace(/^\(+|\)+$/g, "").trim().toLowerCase();
|
|
138
|
+
if (!normalized) {
|
|
139
|
+
return true;
|
|
113
140
|
}
|
|
114
|
-
|
|
115
|
-
return
|
|
141
|
+
if (normalized.startsWith("not ")) {
|
|
142
|
+
return !matchesContainerCondition(normalized.slice(4), containerWidth);
|
|
116
143
|
}
|
|
117
|
-
|
|
118
|
-
|
|
144
|
+
const orClauses = splitConditionalClauses(normalized, "or");
|
|
145
|
+
if (orClauses.length > 1) {
|
|
146
|
+
return orClauses.some((clause) => matchesContainerCondition(clause, containerWidth));
|
|
119
147
|
}
|
|
120
|
-
|
|
121
|
-
|
|
148
|
+
const andClauses = splitConditionalClauses(normalized, "and");
|
|
149
|
+
if (andClauses.length > 1) {
|
|
150
|
+
return andClauses.every((clause) => matchesContainerCondition(clause, containerWidth));
|
|
122
151
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return
|
|
152
|
+
if (normalized.startsWith("min-width:")) {
|
|
153
|
+
const minWidth = parseMediaLength(normalized.slice("min-width:".length));
|
|
154
|
+
return minWidth !== void 0 && containerWidth >= minWidth;
|
|
126
155
|
}
|
|
127
|
-
|
|
128
|
-
|
|
156
|
+
if (normalized.startsWith("max-width:")) {
|
|
157
|
+
const maxWidth = parseMediaLength(normalized.slice("max-width:".length));
|
|
158
|
+
return maxWidth !== void 0 && containerWidth <= maxWidth;
|
|
129
159
|
}
|
|
130
|
-
|
|
131
|
-
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
function parseMediaLength(value) {
|
|
163
|
+
const match = value.trim().match(/^(-?\d+(?:\.\d+)?)(px|rem|em)?$/i);
|
|
164
|
+
if (!match) {
|
|
165
|
+
return void 0;
|
|
132
166
|
}
|
|
133
|
-
|
|
134
|
-
|
|
167
|
+
const numericValue = Number(match[1]);
|
|
168
|
+
const unit = (match[2] ?? "px").toLowerCase();
|
|
169
|
+
if (unit === "rem" || unit === "em") {
|
|
170
|
+
return numericValue * 16;
|
|
135
171
|
}
|
|
136
|
-
|
|
137
|
-
|
|
172
|
+
return numericValue;
|
|
173
|
+
}
|
|
174
|
+
function matchesMediaCondition(condition, options) {
|
|
175
|
+
const normalized = condition.trim().replace(/^\(+|\)+$/g, "").trim().toLowerCase();
|
|
176
|
+
if (!normalized) {
|
|
177
|
+
return true;
|
|
138
178
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const rule = { selector, styles: styles2, type: "name" };
|
|
143
|
-
return rule;
|
|
179
|
+
if (normalized.startsWith("min-width:")) {
|
|
180
|
+
const minWidth = parseMediaLength(normalized.slice("min-width:".length));
|
|
181
|
+
return minWidth !== void 0 && options.viewportWidth !== void 0 && options.viewportWidth >= minWidth;
|
|
144
182
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return
|
|
183
|
+
if (normalized.startsWith("max-width:")) {
|
|
184
|
+
const maxWidth = parseMediaLength(normalized.slice("max-width:".length));
|
|
185
|
+
return maxWidth !== void 0 && options.viewportWidth !== void 0 && options.viewportWidth <= maxWidth;
|
|
148
186
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const keyframeSteps = Object.entries(steps).map(([step, styles2]) => ({
|
|
152
|
-
step: step === "from" ? "from" : step === "to" ? "to" : `${step}%`,
|
|
153
|
-
styles: styles2
|
|
154
|
-
}));
|
|
155
|
-
const kf = { name, steps: keyframeSteps };
|
|
156
|
-
this.keyframes.push(kf);
|
|
157
|
-
return kf;
|
|
187
|
+
if (normalized === "prefers-color-scheme: dark") {
|
|
188
|
+
return options.colorScheme === "dark";
|
|
158
189
|
}
|
|
159
|
-
|
|
160
|
-
return
|
|
190
|
+
if (normalized === "prefers-color-scheme: light") {
|
|
191
|
+
return (options.colorScheme ?? "light") === "light";
|
|
161
192
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
this.fontFaces.push(options);
|
|
165
|
-
return options;
|
|
193
|
+
if (normalized === "prefers-reduced-motion: reduce") {
|
|
194
|
+
return options.reducedMotion === true;
|
|
166
195
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
function matchesMediaRule(rule, options) {
|
|
199
|
+
const mediaType = options.mediaType ?? "screen";
|
|
200
|
+
if (rule.type && rule.type !== mediaType && rule.type !== "all") {
|
|
201
|
+
return false;
|
|
172
202
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const mediaRule = { type, condition, rules: this.rulesToCSSRules(rules) };
|
|
176
|
-
this.mediaRules.push(mediaRule);
|
|
177
|
-
return mediaRule;
|
|
203
|
+
if (!rule.condition.trim()) {
|
|
204
|
+
return true;
|
|
178
205
|
}
|
|
179
|
-
|
|
180
|
-
|
|
206
|
+
return rule.condition.split(/\band\b/i).map((part) => part.trim()).filter(Boolean).every((part) => matchesMediaCondition(part, options));
|
|
207
|
+
}
|
|
208
|
+
function getOrderedLayerNames(layerOrder2, layerRules) {
|
|
209
|
+
const orderedLayerNames = [];
|
|
210
|
+
for (const layerName of layerOrder2) {
|
|
211
|
+
const normalizedName = layerName.trim();
|
|
212
|
+
if (normalizedName && !orderedLayerNames.includes(normalizedName)) {
|
|
213
|
+
orderedLayerNames.push(normalizedName);
|
|
214
|
+
}
|
|
181
215
|
}
|
|
182
|
-
|
|
183
|
-
|
|
216
|
+
for (const layerRule of layerRules) {
|
|
217
|
+
const normalizedName = layerRule.name.trim();
|
|
218
|
+
if (normalizedName && !orderedLayerNames.includes(normalizedName)) {
|
|
219
|
+
orderedLayerNames.push(normalizedName);
|
|
220
|
+
}
|
|
184
221
|
}
|
|
185
|
-
|
|
186
|
-
|
|
222
|
+
return orderedLayerNames;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/client/style/selector-parser.ts
|
|
226
|
+
function splitSelectorList(value) {
|
|
227
|
+
const selectors = [];
|
|
228
|
+
let token = "";
|
|
229
|
+
let attributeDepth = 0;
|
|
230
|
+
let parenthesisDepth = 0;
|
|
231
|
+
let quoted;
|
|
232
|
+
for (let index = 0; index < value.length; index++) {
|
|
233
|
+
const char = value[index];
|
|
234
|
+
if (quoted) {
|
|
235
|
+
token += char;
|
|
236
|
+
if (char === quoted && value[index - 1] !== "\\") {
|
|
237
|
+
quoted = void 0;
|
|
238
|
+
}
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (char === '"' || char === "'") {
|
|
242
|
+
quoted = char;
|
|
243
|
+
token += char;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (char === "[") {
|
|
247
|
+
attributeDepth += 1;
|
|
248
|
+
token += char;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (char === "]" && attributeDepth > 0) {
|
|
252
|
+
attributeDepth -= 1;
|
|
253
|
+
token += char;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (attributeDepth === 0 && char === "(") {
|
|
257
|
+
parenthesisDepth += 1;
|
|
258
|
+
token += char;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
if (attributeDepth === 0 && char === ")" && parenthesisDepth > 0) {
|
|
262
|
+
parenthesisDepth -= 1;
|
|
263
|
+
token += char;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (attributeDepth === 0 && parenthesisDepth === 0 && char === ",") {
|
|
267
|
+
const trimmed = token.trim();
|
|
268
|
+
if (trimmed) {
|
|
269
|
+
selectors.push(trimmed);
|
|
270
|
+
}
|
|
271
|
+
token = "";
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
token += char;
|
|
187
275
|
}
|
|
188
|
-
|
|
189
|
-
|
|
276
|
+
const trailing = token.trim();
|
|
277
|
+
if (trailing) {
|
|
278
|
+
selectors.push(trailing);
|
|
190
279
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
280
|
+
return selectors;
|
|
281
|
+
}
|
|
282
|
+
function parsePseudoSelectorToken(token, startIndex) {
|
|
283
|
+
if (token[startIndex] !== ":" || token[startIndex + 1] === ":") {
|
|
284
|
+
return void 0;
|
|
195
285
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return
|
|
286
|
+
let cursor = startIndex + 1;
|
|
287
|
+
const nameMatch = token.slice(cursor).match(/^([_a-zA-Z][-_a-zA-Z0-9]*)/);
|
|
288
|
+
if (!nameMatch) {
|
|
289
|
+
return void 0;
|
|
200
290
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return
|
|
291
|
+
const pseudoName = nameMatch[1].toLowerCase();
|
|
292
|
+
cursor += nameMatch[0].length;
|
|
293
|
+
if (token[cursor] !== "(") {
|
|
294
|
+
return { value: pseudoName, nextIndex: cursor };
|
|
295
|
+
}
|
|
296
|
+
const argumentStart = cursor + 1;
|
|
297
|
+
let attributeDepth = 0;
|
|
298
|
+
let parenthesisDepth = 1;
|
|
299
|
+
let quoted;
|
|
300
|
+
cursor += 1;
|
|
301
|
+
while (cursor < token.length) {
|
|
302
|
+
const char = token[cursor];
|
|
303
|
+
if (quoted) {
|
|
304
|
+
if (char === quoted && token[cursor - 1] !== "\\") {
|
|
305
|
+
quoted = void 0;
|
|
306
|
+
}
|
|
307
|
+
cursor += 1;
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if (char === '"' || char === "'") {
|
|
311
|
+
quoted = char;
|
|
312
|
+
cursor += 1;
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (char === "[") {
|
|
316
|
+
attributeDepth += 1;
|
|
317
|
+
cursor += 1;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if (char === "]" && attributeDepth > 0) {
|
|
321
|
+
attributeDepth -= 1;
|
|
322
|
+
cursor += 1;
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if (attributeDepth === 0 && char === "(") {
|
|
326
|
+
parenthesisDepth += 1;
|
|
327
|
+
cursor += 1;
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
if (attributeDepth === 0 && char === ")") {
|
|
331
|
+
parenthesisDepth -= 1;
|
|
332
|
+
if (parenthesisDepth === 0) {
|
|
333
|
+
const pseudoArgument = token.slice(argumentStart, cursor).trim();
|
|
334
|
+
return {
|
|
335
|
+
value: pseudoArgument.length > 0 ? `${pseudoName}(${pseudoArgument})` : `${pseudoName}()`,
|
|
336
|
+
nextIndex: cursor + 1
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
cursor += 1;
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
cursor += 1;
|
|
205
343
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
344
|
+
return void 0;
|
|
345
|
+
}
|
|
346
|
+
function parseSimpleSelectorToken(token) {
|
|
347
|
+
const trimmed = token.trim();
|
|
348
|
+
if (!trimmed || /[*&]/.test(trimmed)) {
|
|
349
|
+
return void 0;
|
|
211
350
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
351
|
+
let cursor = 0;
|
|
352
|
+
let tagName;
|
|
353
|
+
let idName;
|
|
354
|
+
const classNames = [];
|
|
355
|
+
const attributes = [];
|
|
356
|
+
const pseudoClasses = [];
|
|
357
|
+
const tagMatch = trimmed.slice(cursor).match(/^([_a-zA-Z][-_a-zA-Z0-9]*)/);
|
|
358
|
+
if (tagMatch) {
|
|
359
|
+
tagName = tagMatch[1].toLowerCase();
|
|
360
|
+
cursor += tagMatch[0].length;
|
|
361
|
+
}
|
|
362
|
+
while (cursor < trimmed.length) {
|
|
363
|
+
const char = trimmed[cursor];
|
|
364
|
+
if (char === ".") {
|
|
365
|
+
const classMatch = trimmed.slice(cursor).match(/^\.([_a-zA-Z][-_a-zA-Z0-9]*)/);
|
|
366
|
+
if (!classMatch) {
|
|
367
|
+
return void 0;
|
|
368
|
+
}
|
|
369
|
+
classNames.push(classMatch[1]);
|
|
370
|
+
cursor += classMatch[0].length;
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (char === "#") {
|
|
374
|
+
const idMatch = trimmed.slice(cursor).match(/^#([_a-zA-Z][-_a-zA-Z0-9]*)/);
|
|
375
|
+
if (!idMatch || idName) {
|
|
376
|
+
return void 0;
|
|
377
|
+
}
|
|
378
|
+
idName = idMatch[1];
|
|
379
|
+
cursor += idMatch[0].length;
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
if (char === "[") {
|
|
383
|
+
const endIndex = trimmed.indexOf("]", cursor + 1);
|
|
384
|
+
if (endIndex === -1) {
|
|
385
|
+
return void 0;
|
|
386
|
+
}
|
|
387
|
+
const rawAttribute = trimmed.slice(cursor + 1, endIndex).trim();
|
|
388
|
+
const attrMatch = rawAttribute.match(/^([_a-zA-Z][-_a-zA-Z0-9]*)(?:\s*(=|~=|\^=|\$=|\*=)\s*(?:"([^"]*)"|'([^']*)'|([^\s"']+)))?$/);
|
|
389
|
+
if (!attrMatch) {
|
|
390
|
+
return void 0;
|
|
391
|
+
}
|
|
392
|
+
attributes.push({
|
|
393
|
+
name: attrMatch[1].toLowerCase(),
|
|
394
|
+
operator: attrMatch[2],
|
|
395
|
+
value: attrMatch[3] ?? attrMatch[4] ?? attrMatch[5]
|
|
396
|
+
});
|
|
397
|
+
cursor = endIndex + 1;
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (char === ":") {
|
|
401
|
+
const pseudoToken = parsePseudoSelectorToken(trimmed, cursor);
|
|
402
|
+
if (!pseudoToken) {
|
|
403
|
+
return void 0;
|
|
404
|
+
}
|
|
405
|
+
pseudoClasses.push(pseudoToken.value);
|
|
406
|
+
cursor = pseudoToken.nextIndex;
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
return void 0;
|
|
215
410
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const supportsRule = { condition, rules: this.rulesToCSSRules(rules) };
|
|
219
|
-
this.supportsRules.push(supportsRule);
|
|
220
|
-
return supportsRule;
|
|
411
|
+
if (!tagName && !idName && classNames.length === 0 && attributes.length === 0 && pseudoClasses.length === 0) {
|
|
412
|
+
return void 0;
|
|
221
413
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
414
|
+
return { tagName, idName, classNames, attributes, pseudoClasses };
|
|
415
|
+
}
|
|
416
|
+
function extractSupportedSelectorChains(selector, parsedSelectorChainCache) {
|
|
417
|
+
const cached = parsedSelectorChainCache.get(selector);
|
|
418
|
+
if (cached) {
|
|
419
|
+
return cached;
|
|
225
420
|
}
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
421
|
+
const parsedChains = splitSelectorList(selector).map((segment) => segment.trim()).map((segment) => {
|
|
422
|
+
const chain = [];
|
|
423
|
+
let token = "";
|
|
424
|
+
let combinator = "descendant";
|
|
425
|
+
let invalid = false;
|
|
426
|
+
let attributeDepth = 0;
|
|
427
|
+
let parenthesisDepth = 0;
|
|
428
|
+
let quoted;
|
|
429
|
+
const flushToken = () => {
|
|
430
|
+
const trimmedToken = token.trim();
|
|
431
|
+
token = "";
|
|
432
|
+
if (!trimmedToken || invalid) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
const parsed = parseSimpleSelectorToken(trimmedToken);
|
|
436
|
+
if (!parsed) {
|
|
437
|
+
invalid = true;
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (chain.length > 0) {
|
|
441
|
+
parsed.combinator = combinator;
|
|
442
|
+
}
|
|
443
|
+
chain.push(parsed);
|
|
444
|
+
combinator = "descendant";
|
|
445
|
+
};
|
|
446
|
+
for (let index = 0; index < segment.length; index++) {
|
|
447
|
+
const char = segment[index];
|
|
448
|
+
if (quoted) {
|
|
449
|
+
token += char;
|
|
450
|
+
if (char === quoted && segment[index - 1] !== "\\") {
|
|
451
|
+
quoted = void 0;
|
|
452
|
+
}
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
if (char === '"' || char === "'") {
|
|
456
|
+
quoted = char;
|
|
457
|
+
token += char;
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
if (char === "[") {
|
|
461
|
+
attributeDepth += 1;
|
|
462
|
+
token += char;
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
if (char === "]") {
|
|
466
|
+
if (attributeDepth > 0) {
|
|
467
|
+
attributeDepth -= 1;
|
|
468
|
+
}
|
|
469
|
+
token += char;
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
if (attributeDepth === 0 && char === "(") {
|
|
473
|
+
parenthesisDepth += 1;
|
|
474
|
+
token += char;
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
if (attributeDepth === 0 && char === ")" && parenthesisDepth > 0) {
|
|
478
|
+
parenthesisDepth -= 1;
|
|
479
|
+
token += char;
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
if (attributeDepth === 0 && parenthesisDepth === 0 && (char === ">" || char === "+" || char === "~")) {
|
|
483
|
+
flushToken();
|
|
484
|
+
if (invalid) {
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
combinator = char === ">" ? "child" : char === "+" ? "adjacent-sibling" : "general-sibling";
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
if (attributeDepth === 0 && parenthesisDepth === 0 && /\s/.test(char)) {
|
|
491
|
+
flushToken();
|
|
492
|
+
if (invalid) {
|
|
493
|
+
break;
|
|
494
|
+
}
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
token += char;
|
|
498
|
+
}
|
|
499
|
+
flushToken();
|
|
500
|
+
if (invalid || chain.length === 0) {
|
|
501
|
+
return void 0;
|
|
502
|
+
}
|
|
503
|
+
return chain.some((part) => Boolean(part.tagName) || Boolean(part.idName) || part.classNames.length > 0 || part.attributes.length > 0 || part.pseudoClasses.length > 0) ? chain : void 0;
|
|
504
|
+
}).filter((segment) => Array.isArray(segment) && segment.length > 0);
|
|
505
|
+
parsedSelectorChainCache.set(selector, parsedChains);
|
|
506
|
+
return parsedChains;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// src/client/style/native-resolver.ts
|
|
510
|
+
var NativeStyleResolver = class {
|
|
511
|
+
constructor() {
|
|
512
|
+
this.parsedSelectorChainCache = /* @__PURE__ */ new Map();
|
|
230
513
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
514
|
+
resolveNativeStyles(target, ancestors = [], options = {}, context) {
|
|
515
|
+
return this.withNativeTargetNormalizationCache(() => {
|
|
516
|
+
const normalizedTarget = this.normalizeTarget(target);
|
|
517
|
+
if (!normalizedTarget.tagName && (!normalizedTarget.classNames || normalizedTarget.classNames.length === 0)) {
|
|
518
|
+
return {};
|
|
519
|
+
}
|
|
520
|
+
const normalizedAncestors = ancestors.map((ancestor) => this.normalizeTarget(ancestor));
|
|
521
|
+
const resolved = {};
|
|
522
|
+
const applyRules = (rules) => {
|
|
523
|
+
for (const rule of rules) {
|
|
524
|
+
const selectorChains = extractSupportedSelectorChains(rule.selector, this.parsedSelectorChainCache);
|
|
525
|
+
if (selectorChains.length === 0) {
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
const matches = selectorChains.some((selectorChain) => this.matchesSelectorChain(normalizedTarget, normalizedAncestors, selectorChain));
|
|
529
|
+
if (!matches) {
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
for (const [property, value] of Object.entries(rule.styles)) {
|
|
533
|
+
resolved[property] = typeof value === "string" ? this.resolveVariableReferences(value, context.variables) : value;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
for (const layerName of getOrderedLayerNames(context.layerOrder, context.layerRules)) {
|
|
538
|
+
for (const layerRule of context.layerRules) {
|
|
539
|
+
if (layerRule.name.trim() === layerName) {
|
|
540
|
+
applyRules(layerRule.rules);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
applyRules(context.rules);
|
|
545
|
+
for (const supportsRule of context.supportsRules) {
|
|
546
|
+
if (matchesSupportsCondition(supportsRule.condition)) {
|
|
547
|
+
applyRules(supportsRule.rules);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
for (const containerRule of context.containerRules) {
|
|
551
|
+
const matchingContainer = findMatchingContainerTarget(normalizedAncestors, containerRule.name);
|
|
552
|
+
if (matchingContainer && this.hasContainerWidth(matchingContainer) && matchesContainerCondition(containerRule.condition, matchingContainer.containerWidth)) {
|
|
553
|
+
applyRules(containerRule.rules);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
for (const mediaRule of context.mediaRules) {
|
|
557
|
+
if (matchesMediaRule(mediaRule, options)) {
|
|
558
|
+
applyRules(mediaRule.rules);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return resolved;
|
|
237
562
|
});
|
|
238
|
-
return cssRules;
|
|
239
563
|
}
|
|
240
|
-
|
|
241
|
-
return
|
|
564
|
+
resolveClassStyles(classNames, context) {
|
|
565
|
+
return this.resolveNativeStyles({ classNames }, [], {}, context);
|
|
242
566
|
}
|
|
243
|
-
|
|
244
|
-
return
|
|
567
|
+
hasContainerWidth(target) {
|
|
568
|
+
return typeof target.containerWidth === "number" && Number.isFinite(target.containerWidth);
|
|
245
569
|
}
|
|
246
570
|
resolveVariableReferences(value, variables) {
|
|
247
571
|
let resolved = value;
|
|
@@ -304,448 +628,10 @@ var CreateStyle = class {
|
|
|
304
628
|
const previousCache = this.nativeTargetNormalizationCache;
|
|
305
629
|
this.nativeTargetNormalizationCache = /* @__PURE__ */ new WeakMap();
|
|
306
630
|
try {
|
|
307
|
-
return callback();
|
|
308
|
-
} finally {
|
|
309
|
-
this.nativeTargetNormalizationCache = previousCache;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
splitConditionalClauses(value, operator) {
|
|
313
|
-
const clauses = [];
|
|
314
|
-
let token = "";
|
|
315
|
-
let depth = 0;
|
|
316
|
-
for (let index = 0; index < value.length; index++) {
|
|
317
|
-
const char = value[index];
|
|
318
|
-
if (char === "(") {
|
|
319
|
-
depth += 1;
|
|
320
|
-
} else if (char === ")" && depth > 0) {
|
|
321
|
-
depth -= 1;
|
|
322
|
-
}
|
|
323
|
-
const operatorToken = ` ${operator} `;
|
|
324
|
-
if (depth === 0 && value.slice(index, index + operatorToken.length).toLowerCase() === operatorToken) {
|
|
325
|
-
const trimmed = token.trim();
|
|
326
|
-
if (trimmed) {
|
|
327
|
-
clauses.push(trimmed);
|
|
328
|
-
}
|
|
329
|
-
token = "";
|
|
330
|
-
index += operatorToken.length - 1;
|
|
331
|
-
continue;
|
|
332
|
-
}
|
|
333
|
-
token += char;
|
|
334
|
-
}
|
|
335
|
-
const trailing = token.trim();
|
|
336
|
-
if (trailing) {
|
|
337
|
-
clauses.push(trailing);
|
|
338
|
-
}
|
|
339
|
-
return clauses;
|
|
340
|
-
}
|
|
341
|
-
splitSelectorList(value) {
|
|
342
|
-
const selectors = [];
|
|
343
|
-
let token = "";
|
|
344
|
-
let attributeDepth = 0;
|
|
345
|
-
let parenthesisDepth = 0;
|
|
346
|
-
let quoted;
|
|
347
|
-
for (let index = 0; index < value.length; index++) {
|
|
348
|
-
const char = value[index];
|
|
349
|
-
if (quoted) {
|
|
350
|
-
token += char;
|
|
351
|
-
if (char === quoted && value[index - 1] !== "\\") {
|
|
352
|
-
quoted = void 0;
|
|
353
|
-
}
|
|
354
|
-
continue;
|
|
355
|
-
}
|
|
356
|
-
if (char === '"' || char === "'") {
|
|
357
|
-
quoted = char;
|
|
358
|
-
token += char;
|
|
359
|
-
continue;
|
|
360
|
-
}
|
|
361
|
-
if (char === "[") {
|
|
362
|
-
attributeDepth += 1;
|
|
363
|
-
token += char;
|
|
364
|
-
continue;
|
|
365
|
-
}
|
|
366
|
-
if (char === "]" && attributeDepth > 0) {
|
|
367
|
-
attributeDepth -= 1;
|
|
368
|
-
token += char;
|
|
369
|
-
continue;
|
|
370
|
-
}
|
|
371
|
-
if (attributeDepth === 0 && char === "(") {
|
|
372
|
-
parenthesisDepth += 1;
|
|
373
|
-
token += char;
|
|
374
|
-
continue;
|
|
375
|
-
}
|
|
376
|
-
if (attributeDepth === 0 && char === ")" && parenthesisDepth > 0) {
|
|
377
|
-
parenthesisDepth -= 1;
|
|
378
|
-
token += char;
|
|
379
|
-
continue;
|
|
380
|
-
}
|
|
381
|
-
if (attributeDepth === 0 && parenthesisDepth === 0 && char === ",") {
|
|
382
|
-
const trimmed = token.trim();
|
|
383
|
-
if (trimmed) {
|
|
384
|
-
selectors.push(trimmed);
|
|
385
|
-
}
|
|
386
|
-
token = "";
|
|
387
|
-
continue;
|
|
388
|
-
}
|
|
389
|
-
token += char;
|
|
390
|
-
}
|
|
391
|
-
const trailing = token.trim();
|
|
392
|
-
if (trailing) {
|
|
393
|
-
selectors.push(trailing);
|
|
394
|
-
}
|
|
395
|
-
return selectors;
|
|
396
|
-
}
|
|
397
|
-
parsePseudoSelectorToken(token, startIndex) {
|
|
398
|
-
if (token[startIndex] !== ":" || token[startIndex + 1] === ":") {
|
|
399
|
-
return void 0;
|
|
400
|
-
}
|
|
401
|
-
let cursor = startIndex + 1;
|
|
402
|
-
const nameMatch = token.slice(cursor).match(/^([_a-zA-Z][-_a-zA-Z0-9]*)/);
|
|
403
|
-
if (!nameMatch) {
|
|
404
|
-
return void 0;
|
|
405
|
-
}
|
|
406
|
-
const pseudoName = nameMatch[1].toLowerCase();
|
|
407
|
-
cursor += nameMatch[0].length;
|
|
408
|
-
if (token[cursor] !== "(") {
|
|
409
|
-
return { value: pseudoName, nextIndex: cursor };
|
|
410
|
-
}
|
|
411
|
-
const argumentStart = cursor + 1;
|
|
412
|
-
let attributeDepth = 0;
|
|
413
|
-
let parenthesisDepth = 1;
|
|
414
|
-
let quoted;
|
|
415
|
-
cursor += 1;
|
|
416
|
-
while (cursor < token.length) {
|
|
417
|
-
const char = token[cursor];
|
|
418
|
-
if (quoted) {
|
|
419
|
-
if (char === quoted && token[cursor - 1] !== "\\") {
|
|
420
|
-
quoted = void 0;
|
|
421
|
-
}
|
|
422
|
-
cursor += 1;
|
|
423
|
-
continue;
|
|
424
|
-
}
|
|
425
|
-
if (char === '"' || char === "'") {
|
|
426
|
-
quoted = char;
|
|
427
|
-
cursor += 1;
|
|
428
|
-
continue;
|
|
429
|
-
}
|
|
430
|
-
if (char === "[") {
|
|
431
|
-
attributeDepth += 1;
|
|
432
|
-
cursor += 1;
|
|
433
|
-
continue;
|
|
434
|
-
}
|
|
435
|
-
if (char === "]" && attributeDepth > 0) {
|
|
436
|
-
attributeDepth -= 1;
|
|
437
|
-
cursor += 1;
|
|
438
|
-
continue;
|
|
439
|
-
}
|
|
440
|
-
if (attributeDepth === 0 && char === "(") {
|
|
441
|
-
parenthesisDepth += 1;
|
|
442
|
-
cursor += 1;
|
|
443
|
-
continue;
|
|
444
|
-
}
|
|
445
|
-
if (attributeDepth === 0 && char === ")") {
|
|
446
|
-
parenthesisDepth -= 1;
|
|
447
|
-
if (parenthesisDepth === 0) {
|
|
448
|
-
const pseudoArgument = token.slice(argumentStart, cursor).trim();
|
|
449
|
-
return {
|
|
450
|
-
value: pseudoArgument.length > 0 ? `${pseudoName}(${pseudoArgument})` : `${pseudoName}()`,
|
|
451
|
-
nextIndex: cursor + 1
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
cursor += 1;
|
|
455
|
-
continue;
|
|
456
|
-
}
|
|
457
|
-
cursor += 1;
|
|
458
|
-
}
|
|
459
|
-
return void 0;
|
|
460
|
-
}
|
|
461
|
-
matchesSupportsDeclaration(property, value) {
|
|
462
|
-
const normalizedProperty = property.trim().toLowerCase();
|
|
463
|
-
const normalizedValue = value.trim().toLowerCase();
|
|
464
|
-
const supportedProperties = /* @__PURE__ */ new Set([
|
|
465
|
-
"align-items",
|
|
466
|
-
"background",
|
|
467
|
-
"background-color",
|
|
468
|
-
"backdrop-filter",
|
|
469
|
-
"border",
|
|
470
|
-
"border-radius",
|
|
471
|
-
"box-shadow",
|
|
472
|
-
"color",
|
|
473
|
-
"column-gap",
|
|
474
|
-
"container-name",
|
|
475
|
-
"container-type",
|
|
476
|
-
"display",
|
|
477
|
-
"flex",
|
|
478
|
-
"flex-direction",
|
|
479
|
-
"flex-grow",
|
|
480
|
-
"flex-wrap",
|
|
481
|
-
"font-family",
|
|
482
|
-
"font-size",
|
|
483
|
-
"font-weight",
|
|
484
|
-
"gap",
|
|
485
|
-
"grid-template-columns",
|
|
486
|
-
"height",
|
|
487
|
-
"justify-content",
|
|
488
|
-
"letter-spacing",
|
|
489
|
-
"line-height",
|
|
490
|
-
"margin",
|
|
491
|
-
"margin-bottom",
|
|
492
|
-
"margin-left",
|
|
493
|
-
"margin-right",
|
|
494
|
-
"margin-top",
|
|
495
|
-
"max-height",
|
|
496
|
-
"max-width",
|
|
497
|
-
"min-height",
|
|
498
|
-
"min-width",
|
|
499
|
-
"padding",
|
|
500
|
-
"padding-bottom",
|
|
501
|
-
"padding-end",
|
|
502
|
-
"padding-horizontal",
|
|
503
|
-
"padding-left",
|
|
504
|
-
"padding-right",
|
|
505
|
-
"padding-start",
|
|
506
|
-
"padding-top",
|
|
507
|
-
"padding-vertical",
|
|
508
|
-
"row-gap",
|
|
509
|
-
"text-align",
|
|
510
|
-
"text-decoration",
|
|
511
|
-
"text-transform",
|
|
512
|
-
"width"
|
|
513
|
-
]);
|
|
514
|
-
if (!supportedProperties.has(normalizedProperty)) {
|
|
515
|
-
return false;
|
|
516
|
-
}
|
|
517
|
-
if (normalizedProperty === "display") {
|
|
518
|
-
return (/* @__PURE__ */ new Set(["block", "flex", "grid", "inline", "inline-block", "inline-flex", "inline-grid"])).has(normalizedValue);
|
|
519
|
-
}
|
|
520
|
-
if (normalizedProperty === "backdrop-filter") {
|
|
521
|
-
return /blur\(/.test(normalizedValue);
|
|
522
|
-
}
|
|
523
|
-
if (normalizedProperty === "container-type") {
|
|
524
|
-
return (/* @__PURE__ */ new Set(["inline-size", "size"])).has(normalizedValue);
|
|
525
|
-
}
|
|
526
|
-
return true;
|
|
527
|
-
}
|
|
528
|
-
matchesSupportsCondition(condition) {
|
|
529
|
-
const normalized = condition.trim().replace(/^\(+|\)+$/g, "").trim();
|
|
530
|
-
if (!normalized) {
|
|
531
|
-
return true;
|
|
532
|
-
}
|
|
533
|
-
if (normalized.toLowerCase().startsWith("not ")) {
|
|
534
|
-
return !this.matchesSupportsCondition(normalized.slice(4));
|
|
535
|
-
}
|
|
536
|
-
const orClauses = this.splitConditionalClauses(normalized, "or");
|
|
537
|
-
if (orClauses.length > 1) {
|
|
538
|
-
return orClauses.some((clause) => this.matchesSupportsCondition(clause));
|
|
539
|
-
}
|
|
540
|
-
const andClauses = this.splitConditionalClauses(normalized, "and");
|
|
541
|
-
if (andClauses.length > 1) {
|
|
542
|
-
return andClauses.every((clause) => this.matchesSupportsCondition(clause));
|
|
543
|
-
}
|
|
544
|
-
const declarationMatch = normalized.match(/^([a-z-]+)\s*:\s*(.+)$/i);
|
|
545
|
-
if (!declarationMatch) {
|
|
546
|
-
return false;
|
|
547
|
-
}
|
|
548
|
-
return this.matchesSupportsDeclaration(declarationMatch[1], declarationMatch[2]);
|
|
549
|
-
}
|
|
550
|
-
findMatchingContainerTarget(ancestors, name) {
|
|
551
|
-
const normalizedName = typeof name === "string" && name.trim() ? name.trim().toLowerCase() : void 0;
|
|
552
|
-
for (let index = ancestors.length - 1; index >= 0; index--) {
|
|
553
|
-
const ancestor = ancestors[index];
|
|
554
|
-
if (!ancestor?.isContainer || ancestor.containerWidth === void 0) {
|
|
555
|
-
continue;
|
|
556
|
-
}
|
|
557
|
-
if (!normalizedName) {
|
|
558
|
-
return ancestor;
|
|
559
|
-
}
|
|
560
|
-
if ((ancestor.containerNames ?? []).includes(normalizedName)) {
|
|
561
|
-
return ancestor;
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
return void 0;
|
|
565
|
-
}
|
|
566
|
-
matchesContainerCondition(condition, containerWidth) {
|
|
567
|
-
const normalized = condition.trim().replace(/^\(+|\)+$/g, "").trim().toLowerCase();
|
|
568
|
-
if (!normalized) {
|
|
569
|
-
return true;
|
|
570
|
-
}
|
|
571
|
-
if (normalized.startsWith("not ")) {
|
|
572
|
-
return !this.matchesContainerCondition(normalized.slice(4), containerWidth);
|
|
573
|
-
}
|
|
574
|
-
const orClauses = this.splitConditionalClauses(normalized, "or");
|
|
575
|
-
if (orClauses.length > 1) {
|
|
576
|
-
return orClauses.some((clause) => this.matchesContainerCondition(clause, containerWidth));
|
|
577
|
-
}
|
|
578
|
-
const andClauses = this.splitConditionalClauses(normalized, "and");
|
|
579
|
-
if (andClauses.length > 1) {
|
|
580
|
-
return andClauses.every((clause) => this.matchesContainerCondition(clause, containerWidth));
|
|
581
|
-
}
|
|
582
|
-
if (normalized.startsWith("min-width:")) {
|
|
583
|
-
const minWidth = this.parseMediaLength(normalized.slice("min-width:".length));
|
|
584
|
-
return minWidth !== void 0 && containerWidth >= minWidth;
|
|
585
|
-
}
|
|
586
|
-
if (normalized.startsWith("max-width:")) {
|
|
587
|
-
const maxWidth = this.parseMediaLength(normalized.slice("max-width:".length));
|
|
588
|
-
return maxWidth !== void 0 && containerWidth <= maxWidth;
|
|
589
|
-
}
|
|
590
|
-
return false;
|
|
591
|
-
}
|
|
592
|
-
parseSimpleSelectorToken(token) {
|
|
593
|
-
const trimmed = token.trim();
|
|
594
|
-
if (!trimmed || /[*&]/.test(trimmed)) {
|
|
595
|
-
return void 0;
|
|
596
|
-
}
|
|
597
|
-
let cursor = 0;
|
|
598
|
-
let tagName;
|
|
599
|
-
let idName;
|
|
600
|
-
const classNames = [];
|
|
601
|
-
const attributes = [];
|
|
602
|
-
const pseudoClasses = [];
|
|
603
|
-
const tagMatch = trimmed.slice(cursor).match(/^([_a-zA-Z][-_a-zA-Z0-9]*)/);
|
|
604
|
-
if (tagMatch) {
|
|
605
|
-
tagName = tagMatch[1].toLowerCase();
|
|
606
|
-
cursor += tagMatch[0].length;
|
|
607
|
-
}
|
|
608
|
-
while (cursor < trimmed.length) {
|
|
609
|
-
const char = trimmed[cursor];
|
|
610
|
-
if (char === ".") {
|
|
611
|
-
const classMatch = trimmed.slice(cursor).match(/^\.([_a-zA-Z][-_a-zA-Z0-9]*)/);
|
|
612
|
-
if (!classMatch) {
|
|
613
|
-
return void 0;
|
|
614
|
-
}
|
|
615
|
-
classNames.push(classMatch[1]);
|
|
616
|
-
cursor += classMatch[0].length;
|
|
617
|
-
continue;
|
|
618
|
-
}
|
|
619
|
-
if (char === "#") {
|
|
620
|
-
const idMatch = trimmed.slice(cursor).match(/^#([_a-zA-Z][-_a-zA-Z0-9]*)/);
|
|
621
|
-
if (!idMatch || idName) {
|
|
622
|
-
return void 0;
|
|
623
|
-
}
|
|
624
|
-
idName = idMatch[1];
|
|
625
|
-
cursor += idMatch[0].length;
|
|
626
|
-
continue;
|
|
627
|
-
}
|
|
628
|
-
if (char === "[") {
|
|
629
|
-
const endIndex = trimmed.indexOf("]", cursor + 1);
|
|
630
|
-
if (endIndex === -1) {
|
|
631
|
-
return void 0;
|
|
632
|
-
}
|
|
633
|
-
const rawAttribute = trimmed.slice(cursor + 1, endIndex).trim();
|
|
634
|
-
const attrMatch = rawAttribute.match(/^([_a-zA-Z][-_a-zA-Z0-9]*)(?:\s*(=|~=|\^=|\$=|\*=)\s*(?:"([^"]*)"|'([^']*)'|([^\s"']+)))?$/);
|
|
635
|
-
if (!attrMatch) {
|
|
636
|
-
return void 0;
|
|
637
|
-
}
|
|
638
|
-
attributes.push({
|
|
639
|
-
name: attrMatch[1].toLowerCase(),
|
|
640
|
-
operator: attrMatch[2],
|
|
641
|
-
value: attrMatch[3] ?? attrMatch[4] ?? attrMatch[5]
|
|
642
|
-
});
|
|
643
|
-
cursor = endIndex + 1;
|
|
644
|
-
continue;
|
|
645
|
-
}
|
|
646
|
-
if (char === ":") {
|
|
647
|
-
const pseudoToken = this.parsePseudoSelectorToken(trimmed, cursor);
|
|
648
|
-
if (!pseudoToken) {
|
|
649
|
-
return void 0;
|
|
650
|
-
}
|
|
651
|
-
pseudoClasses.push(pseudoToken.value);
|
|
652
|
-
cursor = pseudoToken.nextIndex;
|
|
653
|
-
continue;
|
|
654
|
-
}
|
|
655
|
-
return void 0;
|
|
656
|
-
}
|
|
657
|
-
if (!tagName && !idName && classNames.length === 0 && attributes.length === 0 && pseudoClasses.length === 0) {
|
|
658
|
-
return void 0;
|
|
659
|
-
}
|
|
660
|
-
return { tagName, idName, classNames, attributes, pseudoClasses };
|
|
661
|
-
}
|
|
662
|
-
extractSupportedSelectorChains(selector) {
|
|
663
|
-
const cached = this.parsedSelectorChainCache.get(selector);
|
|
664
|
-
if (cached) {
|
|
665
|
-
return cached;
|
|
666
|
-
}
|
|
667
|
-
const parsedChains = this.splitSelectorList(selector).map((segment) => segment.trim()).map((segment) => {
|
|
668
|
-
const chain = [];
|
|
669
|
-
let token = "";
|
|
670
|
-
let combinator = "descendant";
|
|
671
|
-
let invalid = false;
|
|
672
|
-
let attributeDepth = 0;
|
|
673
|
-
let parenthesisDepth = 0;
|
|
674
|
-
let quoted;
|
|
675
|
-
const flushToken = () => {
|
|
676
|
-
const trimmedToken = token.trim();
|
|
677
|
-
token = "";
|
|
678
|
-
if (!trimmedToken || invalid) {
|
|
679
|
-
return;
|
|
680
|
-
}
|
|
681
|
-
const parsed = this.parseSimpleSelectorToken(trimmedToken);
|
|
682
|
-
if (!parsed) {
|
|
683
|
-
invalid = true;
|
|
684
|
-
return;
|
|
685
|
-
}
|
|
686
|
-
if (chain.length > 0) {
|
|
687
|
-
parsed.combinator = combinator;
|
|
688
|
-
}
|
|
689
|
-
chain.push(parsed);
|
|
690
|
-
combinator = "descendant";
|
|
691
|
-
};
|
|
692
|
-
for (let index = 0; index < segment.length; index++) {
|
|
693
|
-
const char = segment[index];
|
|
694
|
-
if (quoted) {
|
|
695
|
-
token += char;
|
|
696
|
-
if (char === quoted && segment[index - 1] !== "\\") {
|
|
697
|
-
quoted = void 0;
|
|
698
|
-
}
|
|
699
|
-
continue;
|
|
700
|
-
}
|
|
701
|
-
if (char === '"' || char === "'") {
|
|
702
|
-
quoted = char;
|
|
703
|
-
token += char;
|
|
704
|
-
continue;
|
|
705
|
-
}
|
|
706
|
-
if (char === "[") {
|
|
707
|
-
attributeDepth += 1;
|
|
708
|
-
token += char;
|
|
709
|
-
continue;
|
|
710
|
-
}
|
|
711
|
-
if (char === "]") {
|
|
712
|
-
if (attributeDepth > 0) {
|
|
713
|
-
attributeDepth -= 1;
|
|
714
|
-
}
|
|
715
|
-
token += char;
|
|
716
|
-
continue;
|
|
717
|
-
}
|
|
718
|
-
if (attributeDepth === 0 && char === "(") {
|
|
719
|
-
parenthesisDepth += 1;
|
|
720
|
-
token += char;
|
|
721
|
-
continue;
|
|
722
|
-
}
|
|
723
|
-
if (attributeDepth === 0 && char === ")" && parenthesisDepth > 0) {
|
|
724
|
-
parenthesisDepth -= 1;
|
|
725
|
-
token += char;
|
|
726
|
-
continue;
|
|
727
|
-
}
|
|
728
|
-
if (attributeDepth === 0 && parenthesisDepth === 0 && (char === ">" || char === "+" || char === "~")) {
|
|
729
|
-
flushToken();
|
|
730
|
-
if (invalid) break;
|
|
731
|
-
combinator = char === ">" ? "child" : char === "+" ? "adjacent-sibling" : "general-sibling";
|
|
732
|
-
continue;
|
|
733
|
-
}
|
|
734
|
-
if (attributeDepth === 0 && parenthesisDepth === 0 && /\s/.test(char)) {
|
|
735
|
-
flushToken();
|
|
736
|
-
if (invalid) break;
|
|
737
|
-
continue;
|
|
738
|
-
}
|
|
739
|
-
token += char;
|
|
740
|
-
}
|
|
741
|
-
flushToken();
|
|
742
|
-
if (invalid || chain.length === 0) {
|
|
743
|
-
return void 0;
|
|
744
|
-
}
|
|
745
|
-
return chain.some((part) => Boolean(part.tagName) || Boolean(part.idName) || part.classNames.length > 0 || part.attributes.length > 0 || part.pseudoClasses.length > 0) ? chain : void 0;
|
|
746
|
-
}).filter((segment) => Array.isArray(segment) && segment.length > 0);
|
|
747
|
-
this.parsedSelectorChainCache.set(selector, parsedChains);
|
|
748
|
-
return parsedChains;
|
|
631
|
+
return callback();
|
|
632
|
+
} finally {
|
|
633
|
+
this.nativeTargetNormalizationCache = previousCache;
|
|
634
|
+
}
|
|
749
635
|
}
|
|
750
636
|
matchesAttributeSelector(targetValue, selector) {
|
|
751
637
|
if (selector.operator === void 0) {
|
|
@@ -832,13 +718,13 @@ var CreateStyle = class {
|
|
|
832
718
|
if (!pseudoArgument) {
|
|
833
719
|
return false;
|
|
834
720
|
}
|
|
835
|
-
const selectorArguments =
|
|
721
|
+
const selectorArguments = splitSelectorList(pseudoArgument);
|
|
836
722
|
if (selectorArguments.length === 0) {
|
|
837
723
|
return false;
|
|
838
724
|
}
|
|
839
725
|
const parsedSelectors = [];
|
|
840
726
|
for (const selectorArgument of selectorArguments) {
|
|
841
|
-
const parsedSelector =
|
|
727
|
+
const parsedSelector = parseSimpleSelectorToken(selectorArgument);
|
|
842
728
|
if (!parsedSelector) {
|
|
843
729
|
return false;
|
|
844
730
|
}
|
|
@@ -887,7 +773,7 @@ var CreateStyle = class {
|
|
|
887
773
|
return Number.isInteger(n) && n >= 0;
|
|
888
774
|
}
|
|
889
775
|
matchesHasPseudoClass(target, pseudoArgument) {
|
|
890
|
-
const selectorArguments =
|
|
776
|
+
const selectorArguments = splitSelectorList(pseudoArgument);
|
|
891
777
|
if (selectorArguments.length === 0) {
|
|
892
778
|
return false;
|
|
893
779
|
}
|
|
@@ -902,7 +788,7 @@ var CreateStyle = class {
|
|
|
902
788
|
if (!scopeRelativeSelector) {
|
|
903
789
|
return false;
|
|
904
790
|
}
|
|
905
|
-
const selectorChains =
|
|
791
|
+
const selectorChains = extractSupportedSelectorChains(scopeRelativeSelector, this.parsedSelectorChainCache);
|
|
906
792
|
if (selectorChains.length === 0) {
|
|
907
793
|
return false;
|
|
908
794
|
}
|
|
@@ -942,356 +828,471 @@ var CreateStyle = class {
|
|
|
942
828
|
const nextAncestors = [...ancestors, target];
|
|
943
829
|
return (target.children ?? []).some((child) => this.matchesSelectorChainInSubtree(child, nextAncestors, chain));
|
|
944
830
|
}
|
|
945
|
-
matchesSelectorChain(target, ancestors, chain) {
|
|
946
|
-
const initialCursor = {
|
|
947
|
-
target,
|
|
948
|
-
ancestorIndex: ancestors.length - 1,
|
|
949
|
-
previousSiblings: Array.isArray(target.previousSiblings) ? target.previousSiblings : []
|
|
950
|
-
};
|
|
951
|
-
return this.matchesSelectorChainFromCursor(chain, chain.length - 1, ancestors, initialCursor);
|
|
831
|
+
matchesSelectorChain(target, ancestors, chain) {
|
|
832
|
+
const initialCursor = {
|
|
833
|
+
target,
|
|
834
|
+
ancestorIndex: ancestors.length - 1,
|
|
835
|
+
previousSiblings: Array.isArray(target.previousSiblings) ? target.previousSiblings : []
|
|
836
|
+
};
|
|
837
|
+
return this.matchesSelectorChainFromCursor(chain, chain.length - 1, ancestors, initialCursor);
|
|
838
|
+
}
|
|
839
|
+
getAncestorCursor(ancestors, ancestorIndex) {
|
|
840
|
+
if (ancestorIndex < 0 || ancestorIndex >= ancestors.length) {
|
|
841
|
+
return void 0;
|
|
842
|
+
}
|
|
843
|
+
const ancestor = ancestors[ancestorIndex];
|
|
844
|
+
return {
|
|
845
|
+
target: ancestor,
|
|
846
|
+
ancestorIndex: ancestorIndex - 1,
|
|
847
|
+
previousSiblings: Array.isArray(ancestor.previousSiblings) ? ancestor.previousSiblings : []
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
matchesSelectorChainFromCursor(chain, chainIndex, ancestors, cursor) {
|
|
851
|
+
if (!this.matchesSelectorPart(cursor.target, chain[chainIndex])) {
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
if (chainIndex === 0) {
|
|
855
|
+
return true;
|
|
856
|
+
}
|
|
857
|
+
const combinator = chain[chainIndex].combinator ?? "descendant";
|
|
858
|
+
switch (combinator) {
|
|
859
|
+
case "child": {
|
|
860
|
+
const parentCursor = this.getAncestorCursor(ancestors, cursor.ancestorIndex);
|
|
861
|
+
return parentCursor ? this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, parentCursor) : false;
|
|
862
|
+
}
|
|
863
|
+
case "adjacent-sibling": {
|
|
864
|
+
const siblingIndex = cursor.previousSiblings.length - 1;
|
|
865
|
+
if (siblingIndex < 0) {
|
|
866
|
+
return false;
|
|
867
|
+
}
|
|
868
|
+
return this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, {
|
|
869
|
+
target: cursor.previousSiblings[siblingIndex],
|
|
870
|
+
ancestorIndex: cursor.ancestorIndex,
|
|
871
|
+
previousSiblings: cursor.previousSiblings.slice(0, siblingIndex)
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
case "general-sibling": {
|
|
875
|
+
for (let siblingIndex = cursor.previousSiblings.length - 1; siblingIndex >= 0; siblingIndex--) {
|
|
876
|
+
if (this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, {
|
|
877
|
+
target: cursor.previousSiblings[siblingIndex],
|
|
878
|
+
ancestorIndex: cursor.ancestorIndex,
|
|
879
|
+
previousSiblings: cursor.previousSiblings.slice(0, siblingIndex)
|
|
880
|
+
})) {
|
|
881
|
+
return true;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
return false;
|
|
885
|
+
}
|
|
886
|
+
case "descendant":
|
|
887
|
+
default: {
|
|
888
|
+
for (let ancestorIndex = cursor.ancestorIndex; ancestorIndex >= 0; ancestorIndex--) {
|
|
889
|
+
const ancestorCursor = this.getAncestorCursor(ancestors, ancestorIndex);
|
|
890
|
+
if (ancestorCursor && this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, ancestorCursor)) {
|
|
891
|
+
return true;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
return false;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
|
|
900
|
+
// src/client/style/renderer.ts
|
|
901
|
+
function toKebabCase(str) {
|
|
902
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
903
|
+
}
|
|
904
|
+
function stylesToString(styles2, indent = " ") {
|
|
905
|
+
return Object.entries(styles2).map(([prop, value]) => {
|
|
906
|
+
const cssValue = typeof value === "object" && value !== null && "name" in value ? `var(${value.name})` : value;
|
|
907
|
+
return `${indent}${toKebabCase(prop)}: ${cssValue};`;
|
|
908
|
+
}).join("\n");
|
|
909
|
+
}
|
|
910
|
+
function renderRule(rule, indent = "") {
|
|
911
|
+
let css = `${indent}${rule.selector} {
|
|
912
|
+
${stylesToString(rule.styles, indent + " ")}
|
|
913
|
+
`;
|
|
914
|
+
if (rule.nested && rule.nested.length > 0) {
|
|
915
|
+
for (const nestedRule of rule.nested) {
|
|
916
|
+
const nestedSelector = nestedRule.selector.startsWith("&") ? nestedRule.selector.replace(/&/g, rule.selector) : `${rule.selector} ${nestedRule.selector}`;
|
|
917
|
+
css += `
|
|
918
|
+
${indent}${nestedSelector} {
|
|
919
|
+
${stylesToString(nestedRule.styles, indent + " ")}
|
|
920
|
+
${indent}}
|
|
921
|
+
`;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
css += `${indent}}`;
|
|
925
|
+
return css;
|
|
926
|
+
}
|
|
927
|
+
function renderRulesWithIndent(rules, indent = " ") {
|
|
928
|
+
return rules.map((rule) => renderRule(rule, indent)).join("\n");
|
|
929
|
+
}
|
|
930
|
+
function renderMediaRule(media) {
|
|
931
|
+
const condition = media.type && media.condition ? `${media.type} and (${media.condition})` : media.type ? media.type : `(${media.condition})`;
|
|
932
|
+
return `@media ${condition} {
|
|
933
|
+
${renderRulesWithIndent(media.rules)}
|
|
934
|
+
}`;
|
|
935
|
+
}
|
|
936
|
+
function renderKeyframes(kf) {
|
|
937
|
+
let css = `@keyframes ${kf.name} {
|
|
938
|
+
`;
|
|
939
|
+
for (const step of kf.steps) {
|
|
940
|
+
css += ` ${step.step} {
|
|
941
|
+
${stylesToString(step.styles, " ")}
|
|
942
|
+
}
|
|
943
|
+
`;
|
|
944
|
+
}
|
|
945
|
+
css += "}";
|
|
946
|
+
return css;
|
|
947
|
+
}
|
|
948
|
+
function renderFontFace(ff) {
|
|
949
|
+
let css = "@font-face {\n";
|
|
950
|
+
css += ` font-family: "${ff.fontFamily}";
|
|
951
|
+
`;
|
|
952
|
+
css += ` src: ${ff.src};
|
|
953
|
+
`;
|
|
954
|
+
if (ff.fontWeight) css += ` font-weight: ${ff.fontWeight};
|
|
955
|
+
`;
|
|
956
|
+
if (ff.fontStyle) css += ` font-style: ${ff.fontStyle};
|
|
957
|
+
`;
|
|
958
|
+
if (ff.fontDisplay) css += ` font-display: ${ff.fontDisplay};
|
|
959
|
+
`;
|
|
960
|
+
if (ff.unicodeRange) css += ` unicode-range: ${ff.unicodeRange};
|
|
961
|
+
`;
|
|
962
|
+
css += "}";
|
|
963
|
+
return css;
|
|
964
|
+
}
|
|
965
|
+
function renderContainerRule(container2) {
|
|
966
|
+
const nameStr = container2.name ? `${container2.name} ` : "";
|
|
967
|
+
return `@container ${nameStr}(${container2.condition}) {
|
|
968
|
+
${renderRulesWithIndent(container2.rules)}
|
|
969
|
+
}`;
|
|
970
|
+
}
|
|
971
|
+
function renderSupportsRule(supports) {
|
|
972
|
+
return `@supports (${supports.condition}) {
|
|
973
|
+
${renderRulesWithIndent(supports.rules)}
|
|
974
|
+
}`;
|
|
975
|
+
}
|
|
976
|
+
function renderLayerRule(layer2) {
|
|
977
|
+
return `@layer ${layer2.name} {
|
|
978
|
+
${renderRulesWithIndent(layer2.rules)}
|
|
979
|
+
}`;
|
|
980
|
+
}
|
|
981
|
+
function renderStyleSheet(context, ...additionalRules) {
|
|
982
|
+
const parts = [];
|
|
983
|
+
if (context.imports.length > 0) {
|
|
984
|
+
parts.push(context.imports.join("\n"));
|
|
985
|
+
}
|
|
986
|
+
if (context.layerOrder.length > 0) {
|
|
987
|
+
parts.push(`@layer ${context.layerOrder.join(", ")};`);
|
|
988
|
+
}
|
|
989
|
+
if (context.variables.length > 0) {
|
|
990
|
+
const varDeclarations = context.variables.map((variable) => ` ${variable.name}: ${variable.value};`).join("\n");
|
|
991
|
+
parts.push(`:root {
|
|
992
|
+
${varDeclarations}
|
|
993
|
+
}`);
|
|
994
|
+
}
|
|
995
|
+
for (const ff of context.fontFaces) {
|
|
996
|
+
parts.push(renderFontFace(ff));
|
|
997
|
+
}
|
|
998
|
+
for (const kf of context.keyframes) {
|
|
999
|
+
parts.push(renderKeyframes(kf));
|
|
1000
|
+
}
|
|
1001
|
+
const allRules = [...context.rules];
|
|
1002
|
+
const allMediaRules = [...context.mediaRules];
|
|
1003
|
+
const allKeyframes = [];
|
|
1004
|
+
const allContainerRules = [...context.containerRules];
|
|
1005
|
+
const allSupportsRules = [...context.supportsRules];
|
|
1006
|
+
const allLayerRules = [...context.layerRules];
|
|
1007
|
+
for (const item of additionalRules) {
|
|
1008
|
+
if (!item) {
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
if (Array.isArray(item)) {
|
|
1012
|
+
allRules.push(...item);
|
|
1013
|
+
} else if ("condition" in item && "rules" in item && !("name" in item && "steps" in item)) {
|
|
1014
|
+
if ("type" in item) {
|
|
1015
|
+
allMediaRules.push(item);
|
|
1016
|
+
} else if ("name" in item && typeof item.name === "string") {
|
|
1017
|
+
allContainerRules.push(item);
|
|
1018
|
+
} else {
|
|
1019
|
+
allSupportsRules.push(item);
|
|
1020
|
+
}
|
|
1021
|
+
} else if ("name" in item && "steps" in item) {
|
|
1022
|
+
allKeyframes.push(item);
|
|
1023
|
+
} else if ("name" in item && "rules" in item) {
|
|
1024
|
+
allLayerRules.push(item);
|
|
1025
|
+
} else {
|
|
1026
|
+
allRules.push(item);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
for (const kf of allKeyframes) {
|
|
1030
|
+
parts.push(renderKeyframes(kf));
|
|
1031
|
+
}
|
|
1032
|
+
for (const layer2 of allLayerRules) {
|
|
1033
|
+
parts.push(renderLayerRule(layer2));
|
|
1034
|
+
}
|
|
1035
|
+
for (const rule of allRules) {
|
|
1036
|
+
parts.push(renderRule(rule));
|
|
1037
|
+
}
|
|
1038
|
+
for (const supports of allSupportsRules) {
|
|
1039
|
+
parts.push(renderSupportsRule(supports));
|
|
1040
|
+
}
|
|
1041
|
+
for (const container2 of allContainerRules) {
|
|
1042
|
+
parts.push(renderContainerRule(container2));
|
|
1043
|
+
}
|
|
1044
|
+
for (const media of allMediaRules) {
|
|
1045
|
+
parts.push(renderMediaRule(media));
|
|
1046
|
+
}
|
|
1047
|
+
return parts.join("\n\n");
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
// src/client/style/store.ts
|
|
1051
|
+
var ELIT_SHARED_STYLE_STORE_KEY = "__elitSharedStyleStore__";
|
|
1052
|
+
function createStyleStore() {
|
|
1053
|
+
return {
|
|
1054
|
+
variables: [],
|
|
1055
|
+
rules: [],
|
|
1056
|
+
mediaRules: [],
|
|
1057
|
+
keyframes: [],
|
|
1058
|
+
fontFaces: [],
|
|
1059
|
+
imports: [],
|
|
1060
|
+
containerRules: [],
|
|
1061
|
+
supportsRules: [],
|
|
1062
|
+
layerRules: [],
|
|
1063
|
+
layerOrder: []
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
function getSharedStyleStore() {
|
|
1067
|
+
const globalScope = globalThis;
|
|
1068
|
+
if (!globalScope[ELIT_SHARED_STYLE_STORE_KEY]) {
|
|
1069
|
+
globalScope[ELIT_SHARED_STYLE_STORE_KEY] = createStyleStore();
|
|
1070
|
+
}
|
|
1071
|
+
return globalScope[ELIT_SHARED_STYLE_STORE_KEY];
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
// src/client/style/index.ts
|
|
1075
|
+
var CreateStyle = class {
|
|
1076
|
+
constructor(store) {
|
|
1077
|
+
this.variables = [];
|
|
1078
|
+
this.rules = [];
|
|
1079
|
+
this.mediaRules = [];
|
|
1080
|
+
this.keyframes = [];
|
|
1081
|
+
this.fontFaces = [];
|
|
1082
|
+
this.imports = [];
|
|
1083
|
+
this.containerRules = [];
|
|
1084
|
+
this.supportsRules = [];
|
|
1085
|
+
this.layerRules = [];
|
|
1086
|
+
this._layerOrder = [];
|
|
1087
|
+
this.nativeStyleResolver = new NativeStyleResolver();
|
|
1088
|
+
if (!store) {
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
this.variables = store.variables;
|
|
1092
|
+
this.rules = store.rules;
|
|
1093
|
+
this.mediaRules = store.mediaRules;
|
|
1094
|
+
this.keyframes = store.keyframes;
|
|
1095
|
+
this.fontFaces = store.fontFaces;
|
|
1096
|
+
this.imports = store.imports;
|
|
1097
|
+
this.containerRules = store.containerRules;
|
|
1098
|
+
this.supportsRules = store.supportsRules;
|
|
1099
|
+
this.layerRules = store.layerRules;
|
|
1100
|
+
this._layerOrder = store.layerOrder;
|
|
1101
|
+
}
|
|
1102
|
+
addVar(name, value) {
|
|
1103
|
+
const cssVar = {
|
|
1104
|
+
name: name.startsWith("--") ? name : `--${name}`,
|
|
1105
|
+
value,
|
|
1106
|
+
toString() {
|
|
1107
|
+
return `var(${this.name})`;
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
this.variables.push(cssVar);
|
|
1111
|
+
return cssVar;
|
|
1112
|
+
}
|
|
1113
|
+
var(variable, fallback) {
|
|
1114
|
+
const varName = typeof variable === "string" ? variable.startsWith("--") ? variable : `--${variable}` : variable.name;
|
|
1115
|
+
return fallback ? `var(${varName}, ${fallback})` : `var(${varName})`;
|
|
1116
|
+
}
|
|
1117
|
+
addTag(tag, styles2) {
|
|
1118
|
+
const rule = { selector: tag, styles: styles2, type: "tag" };
|
|
1119
|
+
this.rules.push(rule);
|
|
1120
|
+
return rule;
|
|
1121
|
+
}
|
|
1122
|
+
addClass(name, styles2) {
|
|
1123
|
+
const selector = name.startsWith(".") ? name : `.${name}`;
|
|
1124
|
+
const rule = { selector, styles: styles2, type: "class" };
|
|
1125
|
+
this.rules.push(rule);
|
|
1126
|
+
return rule;
|
|
1127
|
+
}
|
|
1128
|
+
addId(name, styles2) {
|
|
1129
|
+
const selector = name.startsWith("#") ? name : `#${name}`;
|
|
1130
|
+
const rule = { selector, styles: styles2, type: "id" };
|
|
1131
|
+
this.rules.push(rule);
|
|
1132
|
+
return rule;
|
|
1133
|
+
}
|
|
1134
|
+
addPseudoClass(pseudo, styles2, baseSelector) {
|
|
1135
|
+
const pseudoClass = pseudo.startsWith(":") ? pseudo : `:${pseudo}`;
|
|
1136
|
+
const selector = baseSelector ? `${baseSelector}${pseudoClass}` : pseudoClass;
|
|
1137
|
+
const rule = { selector, styles: styles2, type: "pseudo-class" };
|
|
1138
|
+
this.rules.push(rule);
|
|
1139
|
+
return rule;
|
|
1140
|
+
}
|
|
1141
|
+
addPseudoElement(pseudo, styles2, baseSelector) {
|
|
1142
|
+
const pseudoElement = pseudo.startsWith("::") ? pseudo : `::${pseudo}`;
|
|
1143
|
+
const selector = baseSelector ? `${baseSelector}${pseudoElement}` : pseudoElement;
|
|
1144
|
+
const rule = { selector, styles: styles2, type: "pseudo-element" };
|
|
1145
|
+
this.rules.push(rule);
|
|
1146
|
+
return rule;
|
|
1147
|
+
}
|
|
1148
|
+
addAttribute(attr, styles2, baseSelector) {
|
|
1149
|
+
const attrSelector = attr.startsWith("[") ? attr : `[${attr}]`;
|
|
1150
|
+
const selector = baseSelector ? `${baseSelector}${attrSelector}` : attrSelector;
|
|
1151
|
+
const rule = { selector, styles: styles2, type: "attribute" };
|
|
1152
|
+
this.rules.push(rule);
|
|
1153
|
+
return rule;
|
|
1154
|
+
}
|
|
1155
|
+
attrEquals(attr, value, styles2, baseSelector) {
|
|
1156
|
+
return this.addAttribute(`${attr}="${value}"`, styles2, baseSelector);
|
|
1157
|
+
}
|
|
1158
|
+
attrContainsWord(attr, value, styles2, baseSelector) {
|
|
1159
|
+
return this.addAttribute(`${attr}~="${value}"`, styles2, baseSelector);
|
|
1160
|
+
}
|
|
1161
|
+
attrStartsWith(attr, value, styles2, baseSelector) {
|
|
1162
|
+
return this.addAttribute(`${attr}^="${value}"`, styles2, baseSelector);
|
|
1163
|
+
}
|
|
1164
|
+
attrEndsWith(attr, value, styles2, baseSelector) {
|
|
1165
|
+
return this.addAttribute(`${attr}$="${value}"`, styles2, baseSelector);
|
|
1166
|
+
}
|
|
1167
|
+
attrContains(attr, value, styles2, baseSelector) {
|
|
1168
|
+
return this.addAttribute(`${attr}*="${value}"`, styles2, baseSelector);
|
|
1169
|
+
}
|
|
1170
|
+
descendant(ancestor, descendant2, styles2) {
|
|
1171
|
+
return this.createAndAddRule(`${ancestor} ${descendant2}`, styles2);
|
|
1172
|
+
}
|
|
1173
|
+
child(parent, childSel, styles2) {
|
|
1174
|
+
return this.createAndAddRule(`${parent} > ${childSel}`, styles2);
|
|
1175
|
+
}
|
|
1176
|
+
adjacentSibling(element, sibling, styles2) {
|
|
1177
|
+
return this.createAndAddRule(`${element} + ${sibling}`, styles2);
|
|
1178
|
+
}
|
|
1179
|
+
generalSibling(element, sibling, styles2) {
|
|
1180
|
+
return this.createAndAddRule(`${element} ~ ${sibling}`, styles2);
|
|
1181
|
+
}
|
|
1182
|
+
multiple(selectors, styles2) {
|
|
1183
|
+
return this.createAndAddRule(selectors.join(", "), styles2);
|
|
1184
|
+
}
|
|
1185
|
+
addName(name, styles2) {
|
|
1186
|
+
const selector = name.startsWith("--") ? `&${name}` : `&--${name}`;
|
|
1187
|
+
return { selector, styles: styles2, type: "name" };
|
|
1188
|
+
}
|
|
1189
|
+
nesting(parentRule, ...childRules) {
|
|
1190
|
+
parentRule.nested = childRules;
|
|
1191
|
+
return parentRule;
|
|
1192
|
+
}
|
|
1193
|
+
keyframe(name, steps) {
|
|
1194
|
+
const keyframeSteps = Object.entries(steps).map(([step, styles2]) => ({
|
|
1195
|
+
step: step === "from" ? "from" : step === "to" ? "to" : `${step}%`,
|
|
1196
|
+
styles: styles2
|
|
1197
|
+
}));
|
|
1198
|
+
const kf = { name, steps: keyframeSteps };
|
|
1199
|
+
this.keyframes.push(kf);
|
|
1200
|
+
return kf;
|
|
952
1201
|
}
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
return void 0;
|
|
956
|
-
}
|
|
957
|
-
const ancestor = ancestors[ancestorIndex];
|
|
958
|
-
return {
|
|
959
|
-
target: ancestor,
|
|
960
|
-
ancestorIndex: ancestorIndex - 1,
|
|
961
|
-
previousSiblings: Array.isArray(ancestor.previousSiblings) ? ancestor.previousSiblings : []
|
|
962
|
-
};
|
|
1202
|
+
keyframeFromTo(name, from, to) {
|
|
1203
|
+
return this.keyframe(name, { from, to });
|
|
963
1204
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
}
|
|
968
|
-
if (chainIndex === 0) {
|
|
969
|
-
return true;
|
|
970
|
-
}
|
|
971
|
-
const combinator = chain[chainIndex].combinator ?? "descendant";
|
|
972
|
-
switch (combinator) {
|
|
973
|
-
case "child": {
|
|
974
|
-
const parentCursor = this.getAncestorCursor(ancestors, cursor.ancestorIndex);
|
|
975
|
-
return parentCursor ? this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, parentCursor) : false;
|
|
976
|
-
}
|
|
977
|
-
case "adjacent-sibling": {
|
|
978
|
-
const siblingIndex = cursor.previousSiblings.length - 1;
|
|
979
|
-
if (siblingIndex < 0) {
|
|
980
|
-
return false;
|
|
981
|
-
}
|
|
982
|
-
return this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, {
|
|
983
|
-
target: cursor.previousSiblings[siblingIndex],
|
|
984
|
-
ancestorIndex: cursor.ancestorIndex,
|
|
985
|
-
previousSiblings: cursor.previousSiblings.slice(0, siblingIndex)
|
|
986
|
-
});
|
|
987
|
-
}
|
|
988
|
-
case "general-sibling": {
|
|
989
|
-
for (let siblingIndex = cursor.previousSiblings.length - 1; siblingIndex >= 0; siblingIndex--) {
|
|
990
|
-
if (this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, {
|
|
991
|
-
target: cursor.previousSiblings[siblingIndex],
|
|
992
|
-
ancestorIndex: cursor.ancestorIndex,
|
|
993
|
-
previousSiblings: cursor.previousSiblings.slice(0, siblingIndex)
|
|
994
|
-
})) {
|
|
995
|
-
return true;
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
return false;
|
|
999
|
-
}
|
|
1000
|
-
case "descendant":
|
|
1001
|
-
default: {
|
|
1002
|
-
for (let ancestorIndex = cursor.ancestorIndex; ancestorIndex >= 0; ancestorIndex--) {
|
|
1003
|
-
const ancestorCursor = this.getAncestorCursor(ancestors, ancestorIndex);
|
|
1004
|
-
if (ancestorCursor && this.matchesSelectorChainFromCursor(chain, chainIndex - 1, ancestors, ancestorCursor)) {
|
|
1005
|
-
return true;
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
return false;
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1205
|
+
fontFace(options) {
|
|
1206
|
+
this.fontFaces.push(options);
|
|
1207
|
+
return options;
|
|
1011
1208
|
}
|
|
1012
|
-
|
|
1013
|
-
const
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
}
|
|
1017
|
-
const numericValue = Number(match[1]);
|
|
1018
|
-
const unit = (match[2] ?? "px").toLowerCase();
|
|
1019
|
-
if (unit === "rem" || unit === "em") {
|
|
1020
|
-
return numericValue * 16;
|
|
1021
|
-
}
|
|
1022
|
-
return numericValue;
|
|
1209
|
+
import(url, mediaQuery) {
|
|
1210
|
+
const importRule = mediaQuery ? `@import url("${url}") ${mediaQuery};` : `@import url("${url}");`;
|
|
1211
|
+
this.imports.push(importRule);
|
|
1212
|
+
return importRule;
|
|
1023
1213
|
}
|
|
1024
|
-
|
|
1025
|
-
const
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
}
|
|
1029
|
-
if (normalized.startsWith("min-width:")) {
|
|
1030
|
-
const minWidth = this.parseMediaLength(normalized.slice("min-width:".length));
|
|
1031
|
-
return minWidth !== void 0 && options.viewportWidth !== void 0 && options.viewportWidth >= minWidth;
|
|
1032
|
-
}
|
|
1033
|
-
if (normalized.startsWith("max-width:")) {
|
|
1034
|
-
const maxWidth = this.parseMediaLength(normalized.slice("max-width:".length));
|
|
1035
|
-
return maxWidth !== void 0 && options.viewportWidth !== void 0 && options.viewportWidth <= maxWidth;
|
|
1036
|
-
}
|
|
1037
|
-
if (normalized === "prefers-color-scheme: dark") {
|
|
1038
|
-
return options.colorScheme === "dark";
|
|
1039
|
-
}
|
|
1040
|
-
if (normalized === "prefers-color-scheme: light") {
|
|
1041
|
-
return (options.colorScheme ?? "light") === "light";
|
|
1042
|
-
}
|
|
1043
|
-
if (normalized === "prefers-reduced-motion: reduce") {
|
|
1044
|
-
return options.reducedMotion === true;
|
|
1045
|
-
}
|
|
1046
|
-
return false;
|
|
1214
|
+
media(type, condition, rules) {
|
|
1215
|
+
const mediaRule = { type, condition, rules: this.rulesToCSSRules(rules) };
|
|
1216
|
+
this.mediaRules.push(mediaRule);
|
|
1217
|
+
return mediaRule;
|
|
1047
1218
|
}
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
if (rule.type && rule.type !== mediaType && rule.type !== "all") {
|
|
1051
|
-
return false;
|
|
1052
|
-
}
|
|
1053
|
-
if (!rule.condition.trim()) {
|
|
1054
|
-
return true;
|
|
1055
|
-
}
|
|
1056
|
-
return rule.condition.split(/\band\b/i).map((part) => part.trim()).filter(Boolean).every((part) => this.matchesMediaCondition(part, options));
|
|
1219
|
+
mediaScreen(condition, rules) {
|
|
1220
|
+
return this.media("screen", condition, rules);
|
|
1057
1221
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
for (const layerName of this._layerOrder) {
|
|
1061
|
-
const normalizedName = layerName.trim();
|
|
1062
|
-
if (normalizedName && !orderedLayerNames.includes(normalizedName)) {
|
|
1063
|
-
orderedLayerNames.push(normalizedName);
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
for (const layerRule of this.layerRules) {
|
|
1067
|
-
const normalizedName = layerRule.name.trim();
|
|
1068
|
-
if (normalizedName && !orderedLayerNames.includes(normalizedName)) {
|
|
1069
|
-
orderedLayerNames.push(normalizedName);
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
return orderedLayerNames;
|
|
1222
|
+
mediaPrint(rules) {
|
|
1223
|
+
return this.media("print", "", rules);
|
|
1073
1224
|
}
|
|
1074
|
-
|
|
1075
|
-
return this.
|
|
1076
|
-
const normalizedTarget = this.normalizeTarget(target);
|
|
1077
|
-
if (!normalizedTarget.tagName && (!normalizedTarget.classNames || normalizedTarget.classNames.length === 0)) {
|
|
1078
|
-
return {};
|
|
1079
|
-
}
|
|
1080
|
-
const normalizedAncestors = ancestors.map((ancestor) => this.normalizeTarget(ancestor));
|
|
1081
|
-
const variables = this.getVariables();
|
|
1082
|
-
const resolved = {};
|
|
1083
|
-
const applyRules = (rules) => {
|
|
1084
|
-
for (const rule of rules) {
|
|
1085
|
-
const selectorChains = this.extractSupportedSelectorChains(rule.selector);
|
|
1086
|
-
if (selectorChains.length === 0) {
|
|
1087
|
-
continue;
|
|
1088
|
-
}
|
|
1089
|
-
const matches = selectorChains.some((selectorChain) => this.matchesSelectorChain(normalizedTarget, normalizedAncestors, selectorChain));
|
|
1090
|
-
if (!matches) {
|
|
1091
|
-
continue;
|
|
1092
|
-
}
|
|
1093
|
-
for (const [property, value] of Object.entries(rule.styles)) {
|
|
1094
|
-
resolved[property] = typeof value === "string" ? this.resolveVariableReferences(value, variables) : value;
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
};
|
|
1098
|
-
for (const layerName of this.getOrderedLayerNames()) {
|
|
1099
|
-
for (const layerRule of this.layerRules) {
|
|
1100
|
-
if (layerRule.name.trim() === layerName) {
|
|
1101
|
-
applyRules(layerRule.rules);
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
applyRules(this.rules);
|
|
1106
|
-
for (const supportsRule of this.supportsRules) {
|
|
1107
|
-
if (this.matchesSupportsCondition(supportsRule.condition)) {
|
|
1108
|
-
applyRules(supportsRule.rules);
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
for (const containerRule of this.containerRules) {
|
|
1112
|
-
const matchingContainer = this.findMatchingContainerTarget(normalizedAncestors, containerRule.name);
|
|
1113
|
-
if (matchingContainer && this.matchesContainerCondition(containerRule.condition, matchingContainer.containerWidth)) {
|
|
1114
|
-
applyRules(containerRule.rules);
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
for (const mediaRule of this.mediaRules) {
|
|
1118
|
-
if (this.matchesMediaRule(mediaRule, options)) {
|
|
1119
|
-
applyRules(mediaRule.rules);
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
return resolved;
|
|
1123
|
-
});
|
|
1225
|
+
mediaMinWidth(minWidth, rules) {
|
|
1226
|
+
return this.media("screen", `min-width: ${minWidth}`, rules);
|
|
1124
1227
|
}
|
|
1125
|
-
|
|
1126
|
-
return this.
|
|
1228
|
+
mediaMaxWidth(maxWidth, rules) {
|
|
1229
|
+
return this.media("screen", `max-width: ${maxWidth}`, rules);
|
|
1127
1230
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1231
|
+
mediaDark(rules) {
|
|
1232
|
+
const mediaRule = { type: "", condition: "prefers-color-scheme: dark", rules: this.rulesToCSSRules(rules) };
|
|
1233
|
+
this.mediaRules.push(mediaRule);
|
|
1234
|
+
return mediaRule;
|
|
1131
1235
|
}
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
return rule;
|
|
1236
|
+
mediaLight(rules) {
|
|
1237
|
+
const mediaRule = { type: "", condition: "prefers-color-scheme: light", rules: this.rulesToCSSRules(rules) };
|
|
1238
|
+
this.mediaRules.push(mediaRule);
|
|
1239
|
+
return mediaRule;
|
|
1137
1240
|
}
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
styles: styles2,
|
|
1143
|
-
type: "custom"
|
|
1144
|
-
}));
|
|
1241
|
+
mediaReducedMotion(rules) {
|
|
1242
|
+
const mediaRule = { type: "", condition: "prefers-reduced-motion: reduce", rules: this.rulesToCSSRules(rules) };
|
|
1243
|
+
this.mediaRules.push(mediaRule);
|
|
1244
|
+
return mediaRule;
|
|
1145
1245
|
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1246
|
+
container(condition, rules, name) {
|
|
1247
|
+
const containerRule = { name, condition, rules: this.rulesToCSSRules(rules) };
|
|
1248
|
+
this.containerRules.push(containerRule);
|
|
1249
|
+
return containerRule;
|
|
1149
1250
|
}
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
return `${indent}${this.toKebabCase(prop)}: ${cssValue};`;
|
|
1154
|
-
}).join("\n");
|
|
1251
|
+
addContainer(name, styles2) {
|
|
1252
|
+
const containerStyles = { ...styles2, containerName: name };
|
|
1253
|
+
return this.addClass(name, containerStyles);
|
|
1155
1254
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
if (rule.nested && rule.nested.length > 0) {
|
|
1161
|
-
for (const nestedRule of rule.nested) {
|
|
1162
|
-
const nestedSelector = nestedRule.selector.startsWith("&") ? nestedRule.selector.replace(/&/g, rule.selector) : `${rule.selector} ${nestedRule.selector}`;
|
|
1163
|
-
css += `
|
|
1164
|
-
${indent}${nestedSelector} {
|
|
1165
|
-
${this.stylesToString(nestedRule.styles, indent + " ")}
|
|
1166
|
-
${indent}}
|
|
1167
|
-
`;
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
css += `${indent}}`;
|
|
1171
|
-
return css;
|
|
1255
|
+
supports(condition, rules) {
|
|
1256
|
+
const supportsRule = { condition, rules: this.rulesToCSSRules(rules) };
|
|
1257
|
+
this.supportsRules.push(supportsRule);
|
|
1258
|
+
return supportsRule;
|
|
1172
1259
|
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
return `@media ${condition} {
|
|
1176
|
-
${this.renderRulesWithIndent(media.rules)}
|
|
1177
|
-
}`;
|
|
1260
|
+
layerOrder(...layers) {
|
|
1261
|
+
this._layerOrder = layers;
|
|
1178
1262
|
}
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
css += ` ${step.step} {
|
|
1184
|
-
${this.stylesToString(step.styles, " ")}
|
|
1185
|
-
}
|
|
1186
|
-
`;
|
|
1187
|
-
}
|
|
1188
|
-
css += "}";
|
|
1189
|
-
return css;
|
|
1263
|
+
layer(name, rules) {
|
|
1264
|
+
const layerRule = { name, rules: this.rulesToCSSRules(rules) };
|
|
1265
|
+
this.layerRules.push(layerRule);
|
|
1266
|
+
return layerRule;
|
|
1190
1267
|
}
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
if (ff.fontWeight) css += ` font-weight: ${ff.fontWeight};
|
|
1198
|
-
`;
|
|
1199
|
-
if (ff.fontStyle) css += ` font-style: ${ff.fontStyle};
|
|
1200
|
-
`;
|
|
1201
|
-
if (ff.fontDisplay) css += ` font-display: ${ff.fontDisplay};
|
|
1202
|
-
`;
|
|
1203
|
-
if (ff.unicodeRange) css += ` unicode-range: ${ff.unicodeRange};
|
|
1204
|
-
`;
|
|
1205
|
-
css += "}";
|
|
1206
|
-
return css;
|
|
1268
|
+
add(rules) {
|
|
1269
|
+
return Object.entries(rules).map(([selector, styles2]) => {
|
|
1270
|
+
const rule = { selector, styles: styles2, type: "custom" };
|
|
1271
|
+
this.rules.push(rule);
|
|
1272
|
+
return rule;
|
|
1273
|
+
});
|
|
1207
1274
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
return `@container ${nameStr}(${container2.condition}) {
|
|
1211
|
-
${this.renderRulesWithIndent(container2.rules)}
|
|
1212
|
-
}`;
|
|
1275
|
+
important(value) {
|
|
1276
|
+
return `${value} !important`;
|
|
1213
1277
|
}
|
|
1214
|
-
|
|
1215
|
-
return
|
|
1216
|
-
${this.renderRulesWithIndent(supports.rules)}
|
|
1217
|
-
}`;
|
|
1278
|
+
getVariables() {
|
|
1279
|
+
return Object.fromEntries(this.variables.map((variable) => [variable.name, variable.value]));
|
|
1218
1280
|
}
|
|
1219
|
-
|
|
1220
|
-
return
|
|
1221
|
-
|
|
1222
|
-
|
|
1281
|
+
resolveNativeStyles(target, ancestors = [], options = {}) {
|
|
1282
|
+
return this.nativeStyleResolver.resolveNativeStyles(target, ancestors, options, this.getResolverContext());
|
|
1283
|
+
}
|
|
1284
|
+
resolveClassStyles(classNames) {
|
|
1285
|
+
return this.nativeStyleResolver.resolveClassStyles(classNames, this.getResolverContext());
|
|
1223
1286
|
}
|
|
1224
|
-
// Render Output
|
|
1225
1287
|
render(...additionalRules) {
|
|
1226
|
-
|
|
1227
|
-
if (this.imports.length > 0) {
|
|
1228
|
-
parts.push(this.imports.join("\n"));
|
|
1229
|
-
}
|
|
1230
|
-
if (this._layerOrder.length > 0) {
|
|
1231
|
-
parts.push(`@layer ${this._layerOrder.join(", ")};`);
|
|
1232
|
-
}
|
|
1233
|
-
if (this.variables.length > 0) {
|
|
1234
|
-
const varDeclarations = this.variables.map((v) => ` ${v.name}: ${v.value};`).join("\n");
|
|
1235
|
-
parts.push(`:root {
|
|
1236
|
-
${varDeclarations}
|
|
1237
|
-
}`);
|
|
1238
|
-
}
|
|
1239
|
-
for (const ff of this.fontFaces) {
|
|
1240
|
-
parts.push(this.renderFontFace(ff));
|
|
1241
|
-
}
|
|
1242
|
-
for (const kf of this.keyframes) {
|
|
1243
|
-
parts.push(this.renderKeyframes(kf));
|
|
1244
|
-
}
|
|
1245
|
-
const allRules = [...this.rules];
|
|
1246
|
-
const allMediaRules = [...this.mediaRules];
|
|
1247
|
-
const allKeyframes = [];
|
|
1248
|
-
const allContainerRules = [...this.containerRules];
|
|
1249
|
-
const allSupportsRules = [...this.supportsRules];
|
|
1250
|
-
const allLayerRules = [...this.layerRules];
|
|
1251
|
-
for (const item of additionalRules) {
|
|
1252
|
-
if (!item) continue;
|
|
1253
|
-
if (Array.isArray(item)) {
|
|
1254
|
-
allRules.push(...item);
|
|
1255
|
-
} else if ("condition" in item && "rules" in item && !("name" in item && "steps" in item)) {
|
|
1256
|
-
if ("type" in item) {
|
|
1257
|
-
allMediaRules.push(item);
|
|
1258
|
-
} else if ("name" in item && typeof item.name === "string") {
|
|
1259
|
-
allContainerRules.push(item);
|
|
1260
|
-
} else {
|
|
1261
|
-
allSupportsRules.push(item);
|
|
1262
|
-
}
|
|
1263
|
-
} else if ("name" in item && "steps" in item) {
|
|
1264
|
-
allKeyframes.push(item);
|
|
1265
|
-
} else if ("name" in item && "rules" in item) {
|
|
1266
|
-
allLayerRules.push(item);
|
|
1267
|
-
} else {
|
|
1268
|
-
allRules.push(item);
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
for (const kf of allKeyframes) {
|
|
1272
|
-
parts.push(this.renderKeyframes(kf));
|
|
1273
|
-
}
|
|
1274
|
-
for (const layer2 of allLayerRules) {
|
|
1275
|
-
parts.push(this.renderLayerRule(layer2));
|
|
1276
|
-
}
|
|
1277
|
-
for (const rule of allRules) {
|
|
1278
|
-
parts.push(this.renderRule(rule));
|
|
1279
|
-
}
|
|
1280
|
-
for (const supports of allSupportsRules) {
|
|
1281
|
-
parts.push(this.renderSupportsRule(supports));
|
|
1282
|
-
}
|
|
1283
|
-
for (const container2 of allContainerRules) {
|
|
1284
|
-
parts.push(this.renderContainerRule(container2));
|
|
1285
|
-
}
|
|
1286
|
-
for (const media of allMediaRules) {
|
|
1287
|
-
parts.push(this.renderMediaRule(media));
|
|
1288
|
-
}
|
|
1289
|
-
return parts.join("\n\n");
|
|
1288
|
+
return renderStyleSheet(this.getRenderContext(), ...additionalRules);
|
|
1290
1289
|
}
|
|
1291
1290
|
inject(styleId) {
|
|
1292
1291
|
const css = this.render();
|
|
1293
1292
|
const style = document.createElement("style");
|
|
1294
|
-
if (styleId)
|
|
1293
|
+
if (styleId) {
|
|
1294
|
+
style.id = styleId;
|
|
1295
|
+
}
|
|
1295
1296
|
style.textContent = css;
|
|
1296
1297
|
document.head.appendChild(style);
|
|
1297
1298
|
return style;
|
|
@@ -1308,6 +1309,43 @@ ${varDeclarations}
|
|
|
1308
1309
|
this.layerRules.length = 0;
|
|
1309
1310
|
this._layerOrder.length = 0;
|
|
1310
1311
|
}
|
|
1312
|
+
getResolverContext() {
|
|
1313
|
+
return {
|
|
1314
|
+
variables: this.getVariables(),
|
|
1315
|
+
rules: this.rules,
|
|
1316
|
+
mediaRules: this.mediaRules,
|
|
1317
|
+
containerRules: this.containerRules,
|
|
1318
|
+
supportsRules: this.supportsRules,
|
|
1319
|
+
layerRules: this.layerRules,
|
|
1320
|
+
layerOrder: this._layerOrder
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
getRenderContext() {
|
|
1324
|
+
return {
|
|
1325
|
+
imports: this.imports,
|
|
1326
|
+
layerOrder: this._layerOrder,
|
|
1327
|
+
variables: this.variables,
|
|
1328
|
+
fontFaces: this.fontFaces,
|
|
1329
|
+
keyframes: this.keyframes,
|
|
1330
|
+
rules: this.rules,
|
|
1331
|
+
mediaRules: this.mediaRules,
|
|
1332
|
+
containerRules: this.containerRules,
|
|
1333
|
+
supportsRules: this.supportsRules,
|
|
1334
|
+
layerRules: this.layerRules
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
createAndAddRule(selector, styles2, type = "custom") {
|
|
1338
|
+
const rule = { selector, styles: styles2, type };
|
|
1339
|
+
this.rules.push(rule);
|
|
1340
|
+
return rule;
|
|
1341
|
+
}
|
|
1342
|
+
rulesToCSSRules(rules) {
|
|
1343
|
+
return Object.entries(rules).map(([selector, styles2]) => ({
|
|
1344
|
+
selector,
|
|
1345
|
+
styles: styles2,
|
|
1346
|
+
type: "custom"
|
|
1347
|
+
}));
|
|
1348
|
+
}
|
|
1311
1349
|
};
|
|
1312
1350
|
var styles = new CreateStyle(getSharedStyleStore());
|
|
1313
1351
|
var {
|
|
@@ -1351,6 +1389,7 @@ var {
|
|
|
1351
1389
|
add: addStyle,
|
|
1352
1390
|
important,
|
|
1353
1391
|
getVariables: getStyleVariables,
|
|
1392
|
+
resolveNativeStyles,
|
|
1354
1393
|
resolveClassStyles,
|
|
1355
1394
|
render: renderStyle,
|
|
1356
1395
|
inject: injectStyle,
|
|
@@ -1403,6 +1442,7 @@ export {
|
|
|
1403
1442
|
nesting,
|
|
1404
1443
|
renderStyle,
|
|
1405
1444
|
resolveClassStyles,
|
|
1445
|
+
resolveNativeStyles,
|
|
1406
1446
|
styles,
|
|
1407
1447
|
supportsStyle
|
|
1408
1448
|
};
|