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