@unocss/rule-utils 66.5.10 → 66.5.12
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/dist/index.d.mts +1010 -60
- package/dist/index.mjs +620 -663
- package/package.json +5 -6
- package/dist/index.d.ts +0 -120
package/dist/index.mjs
CHANGED
|
@@ -1,752 +1,709 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import MagicString from
|
|
1
|
+
import { escapeRegExp, escapeSelector, isString, toArray } from "@unocss/core";
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
3
|
|
|
4
|
+
//#region src/utilities.ts
|
|
4
5
|
function getBracket(str, open, close) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
str.slice(0, openAt)
|
|
29
|
-
];
|
|
30
|
-
}
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
6
|
+
if (str === "") return;
|
|
7
|
+
const l = str.length;
|
|
8
|
+
let parenthesis = 0;
|
|
9
|
+
let opened = false;
|
|
10
|
+
let openAt = 0;
|
|
11
|
+
for (let i = 0; i < l; i++) switch (str[i]) {
|
|
12
|
+
case open:
|
|
13
|
+
if (!opened) {
|
|
14
|
+
opened = true;
|
|
15
|
+
openAt = i;
|
|
16
|
+
}
|
|
17
|
+
parenthesis++;
|
|
18
|
+
break;
|
|
19
|
+
case close:
|
|
20
|
+
--parenthesis;
|
|
21
|
+
if (parenthesis < 0) return;
|
|
22
|
+
if (parenthesis === 0) return [
|
|
23
|
+
str.slice(openAt, i + 1),
|
|
24
|
+
str.slice(i + 1),
|
|
25
|
+
str.slice(0, openAt)
|
|
26
|
+
];
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
34
29
|
}
|
|
35
30
|
function getStringComponent(str, open, close, separators) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (i === 0 || i === l - separatorLength)
|
|
58
|
-
return;
|
|
59
|
-
return [
|
|
60
|
-
str.slice(0, i),
|
|
61
|
-
str.slice(i + separatorLength)
|
|
62
|
-
];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return [
|
|
68
|
-
str,
|
|
69
|
-
""
|
|
70
|
-
];
|
|
31
|
+
if (str === "") return;
|
|
32
|
+
if (isString(separators)) separators = [separators];
|
|
33
|
+
if (separators.length === 0) return;
|
|
34
|
+
const l = str.length;
|
|
35
|
+
let parenthesis = 0;
|
|
36
|
+
for (let i = 0; i < l; i++) switch (str[i]) {
|
|
37
|
+
case open:
|
|
38
|
+
parenthesis++;
|
|
39
|
+
break;
|
|
40
|
+
case close:
|
|
41
|
+
if (--parenthesis < 0) return;
|
|
42
|
+
break;
|
|
43
|
+
default: for (const separator of separators) {
|
|
44
|
+
const separatorLength = separator.length;
|
|
45
|
+
if (separatorLength && separator === str.slice(i, i + separatorLength) && parenthesis === 0) {
|
|
46
|
+
if (i === 0 || i === l - separatorLength) return;
|
|
47
|
+
return [str.slice(0, i), str.slice(i + separatorLength)];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return [str, ""];
|
|
71
52
|
}
|
|
72
53
|
function getStringComponents(str, separators, limit, open = "(", close = ")") {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
if (components.length > 0)
|
|
87
|
-
return components;
|
|
54
|
+
limit = limit ?? 10;
|
|
55
|
+
const components = [];
|
|
56
|
+
let i = 0;
|
|
57
|
+
while (str !== "") {
|
|
58
|
+
if (++i > limit) return;
|
|
59
|
+
const componentPair = getStringComponent(str, open, close, separators);
|
|
60
|
+
if (!componentPair) return;
|
|
61
|
+
const [component, rest] = componentPair;
|
|
62
|
+
components.push(component);
|
|
63
|
+
str = rest;
|
|
64
|
+
}
|
|
65
|
+
if (components.length > 0) return components;
|
|
88
66
|
}
|
|
89
67
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/colors.ts
|
|
70
|
+
const cssColorFunctions = [
|
|
71
|
+
"hsl",
|
|
72
|
+
"hsla",
|
|
73
|
+
"hwb",
|
|
74
|
+
"lab",
|
|
75
|
+
"lch",
|
|
76
|
+
"oklab",
|
|
77
|
+
"oklch",
|
|
78
|
+
"rgb",
|
|
79
|
+
"rgba"
|
|
80
|
+
];
|
|
81
|
+
const rectangularColorSpace = [
|
|
82
|
+
"srgb",
|
|
83
|
+
"srgb-linear",
|
|
84
|
+
"display-p3",
|
|
85
|
+
"a98-rgb",
|
|
86
|
+
"prophoto-rgb",
|
|
87
|
+
"rec2020",
|
|
88
|
+
"lab",
|
|
89
|
+
"oklab",
|
|
90
|
+
"xyz",
|
|
91
|
+
"xyz-d50",
|
|
92
|
+
"xyz-d65"
|
|
93
|
+
];
|
|
94
|
+
const polarColorSpace = [
|
|
95
|
+
"hsl",
|
|
96
|
+
"hwb",
|
|
97
|
+
"lch",
|
|
98
|
+
"oklch"
|
|
99
|
+
];
|
|
100
|
+
const hueInterpolationMethods = [
|
|
101
|
+
"shorter",
|
|
102
|
+
"longer",
|
|
103
|
+
"increasing",
|
|
104
|
+
"decreasing"
|
|
105
|
+
];
|
|
94
106
|
const alphaPlaceholders = ["%alpha", "<alpha-value>"];
|
|
95
107
|
const alphaPlaceholdersRE = new RegExp(alphaPlaceholders.map((v) => escapeRegExp(v)).join("|"), "g");
|
|
96
108
|
function isInterpolatedMethod(type) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return rectangularColorSpace.some((space) => type.includes(space)) || polarColorSpace.some((space) => type.includes(space)) || hueInterpolationMethods.some((method) => type.includes(method));
|
|
109
|
+
if (!type) return false;
|
|
110
|
+
return rectangularColorSpace.some((space) => type.includes(space)) || polarColorSpace.some((space) => type.includes(space)) || hueInterpolationMethods.some((method) => type.includes(method));
|
|
100
111
|
}
|
|
101
112
|
function hex2rgba(hex = "") {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
113
|
+
const color = parseHexColor(hex);
|
|
114
|
+
if (color != null) {
|
|
115
|
+
const { components, alpha } = color;
|
|
116
|
+
if (alpha == null) return components;
|
|
117
|
+
return [...components, alpha];
|
|
118
|
+
}
|
|
109
119
|
}
|
|
110
120
|
function parseCssColor(str = "") {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
components: components.map((c) => typeof c === "string" ? c.trim() : c),
|
|
123
|
-
alpha: typeof alpha === "string" ? alpha.trim() : alpha
|
|
124
|
-
};
|
|
121
|
+
const color = parseColor(str);
|
|
122
|
+
if (color == null || color === false) return;
|
|
123
|
+
const { type: casedType, components, alpha } = color;
|
|
124
|
+
const type = casedType.toLowerCase();
|
|
125
|
+
if (components.length === 0) return;
|
|
126
|
+
if (cssColorFunctions.includes(type) && ![1, 3].includes(components.length)) return;
|
|
127
|
+
return {
|
|
128
|
+
type,
|
|
129
|
+
components: components.map((c) => typeof c === "string" ? c.trim() : c),
|
|
130
|
+
alpha: typeof alpha === "string" ? alpha.trim() : alpha
|
|
131
|
+
};
|
|
125
132
|
}
|
|
126
133
|
function colorOpacityToString(color) {
|
|
127
|
-
|
|
128
|
-
|
|
134
|
+
const alpha = color.alpha ?? 1;
|
|
135
|
+
return typeof alpha === "string" && alphaPlaceholders.includes(alpha) ? 1 : alpha;
|
|
129
136
|
}
|
|
130
137
|
function colorToString(color, alphaOverride) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (cssColorFunctions.includes(type))
|
|
141
|
-
return `${type}(${components.join(" ")}${alpha})`;
|
|
142
|
-
return `color(${type} ${components.join(" ")}${alpha})`;
|
|
138
|
+
if (typeof color === "string") return color.replace(alphaPlaceholdersRE, `${alphaOverride ?? 1}`);
|
|
139
|
+
const { components } = color;
|
|
140
|
+
let { alpha, type } = color;
|
|
141
|
+
alpha = alphaOverride ?? alpha;
|
|
142
|
+
type = type.toLowerCase();
|
|
143
|
+
if (["hsla", "rgba"].includes(type)) return `${type}(${components.join(", ")}${alpha == null ? "" : `, ${alpha}`})`;
|
|
144
|
+
alpha = alpha == null ? "" : ` / ${alpha}`;
|
|
145
|
+
if (cssColorFunctions.includes(type)) return `${type}(${components.join(" ")}${alpha})`;
|
|
146
|
+
return `color(${type} ${components.join(" ")}${alpha})`;
|
|
143
147
|
}
|
|
144
148
|
function parseColor(str) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
color = parseCssSpaceColorFunction(str);
|
|
157
|
-
if (color != null)
|
|
158
|
-
return color;
|
|
159
|
-
color = parseCssColorFunction(str);
|
|
160
|
-
if (color != null)
|
|
161
|
-
return color;
|
|
149
|
+
if (!str) return;
|
|
150
|
+
let color = parseHexColor(str);
|
|
151
|
+
if (color != null) return color;
|
|
152
|
+
color = cssColorKeyword(str);
|
|
153
|
+
if (color != null) return color;
|
|
154
|
+
color = parseCssCommaColorFunction(str);
|
|
155
|
+
if (color != null) return color;
|
|
156
|
+
color = parseCssSpaceColorFunction(str);
|
|
157
|
+
if (color != null) return color;
|
|
158
|
+
color = parseCssColorFunction(str);
|
|
159
|
+
if (color != null) return color;
|
|
162
160
|
}
|
|
163
161
|
function parseHexColor(str) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
162
|
+
const [, body] = str.match(/^#([\da-f]+)$/i) || [];
|
|
163
|
+
if (!body) return;
|
|
164
|
+
switch (body.length) {
|
|
165
|
+
case 3:
|
|
166
|
+
case 4: {
|
|
167
|
+
const digits = Array.from(body, (s) => Number.parseInt(s, 16)).map((n) => n << 4 | n);
|
|
168
|
+
return {
|
|
169
|
+
type: "rgb",
|
|
170
|
+
components: digits.slice(0, 3),
|
|
171
|
+
alpha: body.length === 3 ? void 0 : Math.round(digits[3] / 255 * 100) / 100
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
case 6:
|
|
175
|
+
case 8: {
|
|
176
|
+
const value = Number.parseInt(body, 16);
|
|
177
|
+
return {
|
|
178
|
+
type: "rgb",
|
|
179
|
+
components: body.length === 6 ? [
|
|
180
|
+
value >> 16 & 255,
|
|
181
|
+
value >> 8 & 255,
|
|
182
|
+
value & 255
|
|
183
|
+
] : [
|
|
184
|
+
value >> 24 & 255,
|
|
185
|
+
value >> 16 & 255,
|
|
186
|
+
value >> 8 & 255
|
|
187
|
+
],
|
|
188
|
+
alpha: body.length === 6 ? void 0 : Math.round((value & 255) / 255 * 100) / 100
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
187
192
|
}
|
|
188
193
|
function cssColorKeyword(str) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
194
|
+
const color = { rebeccapurple: [
|
|
195
|
+
102,
|
|
196
|
+
51,
|
|
197
|
+
153,
|
|
198
|
+
1
|
|
199
|
+
] }[str];
|
|
200
|
+
if (color != null) return {
|
|
201
|
+
type: "rgb",
|
|
202
|
+
components: color.slice(0, 3),
|
|
203
|
+
alpha: color[3]
|
|
204
|
+
};
|
|
199
205
|
}
|
|
200
206
|
function parseCssCommaColorFunction(color) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
} else if (components.length !== 1) {
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
207
|
+
const match = color.match(/^(rgb|rgba|hsl|hsla)\((.+)\)$/i);
|
|
208
|
+
if (!match) return;
|
|
209
|
+
const [, type, componentString] = match;
|
|
210
|
+
const components = getStringComponents(componentString, ",", 5);
|
|
211
|
+
if (components) {
|
|
212
|
+
if ([3, 4].includes(components.length)) return {
|
|
213
|
+
type,
|
|
214
|
+
components: components.slice(0, 3),
|
|
215
|
+
alpha: components[3]
|
|
216
|
+
};
|
|
217
|
+
else if (components.length !== 1) return false;
|
|
218
|
+
}
|
|
217
219
|
}
|
|
218
220
|
const cssColorFunctionsRe = new RegExp(`^(${cssColorFunctions.join("|")})\\((.+)\\)$`, "i");
|
|
219
221
|
function parseCssSpaceColorFunction(color) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
222
|
+
const match = color.match(cssColorFunctionsRe);
|
|
223
|
+
if (!match) return;
|
|
224
|
+
const [, fn, componentString] = match;
|
|
225
|
+
const parsed = parseCssSpaceColorValues(`${fn} ${componentString}`);
|
|
226
|
+
if (parsed) {
|
|
227
|
+
const { alpha, components: [type, ...components] } = parsed;
|
|
228
|
+
return {
|
|
229
|
+
type,
|
|
230
|
+
components,
|
|
231
|
+
alpha
|
|
232
|
+
};
|
|
233
|
+
}
|
|
233
234
|
}
|
|
234
235
|
function parseCssColorFunction(color) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
236
|
+
const match = color.match(/^color\((.+)\)$/);
|
|
237
|
+
if (!match) return;
|
|
238
|
+
const parsed = parseCssSpaceColorValues(match[1]);
|
|
239
|
+
if (parsed) {
|
|
240
|
+
const { alpha, components: [type, ...components] } = parsed;
|
|
241
|
+
return {
|
|
242
|
+
type,
|
|
243
|
+
components,
|
|
244
|
+
alpha
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
247
|
}
|
|
248
248
|
function parseCssSpaceColorValues(componentString) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
components[totalComponents - 1] = withAlpha.join("/");
|
|
271
|
-
return {
|
|
272
|
-
components,
|
|
273
|
-
alpha
|
|
274
|
-
};
|
|
249
|
+
const components = getStringComponents(componentString, " ");
|
|
250
|
+
if (!components) return;
|
|
251
|
+
let totalComponents = components.length;
|
|
252
|
+
if (components[totalComponents - 2] === "/") return {
|
|
253
|
+
components: components.slice(0, totalComponents - 2),
|
|
254
|
+
alpha: components[totalComponents - 1]
|
|
255
|
+
};
|
|
256
|
+
if (components[totalComponents - 2] != null && (components[totalComponents - 2].endsWith("/") || components[totalComponents - 1].startsWith("/"))) {
|
|
257
|
+
const removed = components.splice(totalComponents - 2);
|
|
258
|
+
components.push(removed.join(" "));
|
|
259
|
+
--totalComponents;
|
|
260
|
+
}
|
|
261
|
+
const withAlpha = getStringComponents(components[totalComponents - 1], "/", 2);
|
|
262
|
+
if (!withAlpha) return;
|
|
263
|
+
if (withAlpha.length === 1 || withAlpha[withAlpha.length - 1] === "") return { components };
|
|
264
|
+
const alpha = withAlpha.pop();
|
|
265
|
+
components[totalComponents - 1] = withAlpha.join("/");
|
|
266
|
+
return {
|
|
267
|
+
components,
|
|
268
|
+
alpha
|
|
269
|
+
};
|
|
275
270
|
}
|
|
276
271
|
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/directive.ts
|
|
277
274
|
const themeFnRE = /theme\(\s*(['"])?(.*?)\1?\s*\)/g;
|
|
278
275
|
function hasThemeFn(str) {
|
|
279
|
-
|
|
276
|
+
return str.includes("theme(") && str.includes(")");
|
|
280
277
|
}
|
|
281
278
|
function transformThemeFn(code, theme, throwOnMissing = true) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
s.overwrite(
|
|
293
|
-
match.index,
|
|
294
|
-
match.index + match[0].length,
|
|
295
|
-
value
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return s.toString();
|
|
279
|
+
const matches = Array.from(code.toString().matchAll(themeFnRE));
|
|
280
|
+
if (!matches.length) return code;
|
|
281
|
+
const s = new MagicString(code);
|
|
282
|
+
for (const match of matches) {
|
|
283
|
+
const rawArg = match[2];
|
|
284
|
+
if (!rawArg) throw new Error("theme() expect exact one argument, but got 0");
|
|
285
|
+
const value = transformThemeString(rawArg, theme, throwOnMissing);
|
|
286
|
+
if (value) s.overwrite(match.index, match.index + match[0].length, value);
|
|
287
|
+
}
|
|
288
|
+
return s.toString();
|
|
300
289
|
}
|
|
301
290
|
function transformThemeString(code, theme, throwOnMissing = true) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
value = colorToString(color, alpha);
|
|
313
|
-
}
|
|
314
|
-
return value;
|
|
315
|
-
} else if (throwOnMissing) {
|
|
316
|
-
throw new Error(`theme of "${code}" did not found`);
|
|
317
|
-
}
|
|
291
|
+
const [rawKey, alpha] = code.split("/");
|
|
292
|
+
let value = rawKey.trim().split(".").reduce((t, k) => t === null || t === void 0 ? void 0 : t[k], theme);
|
|
293
|
+
if (typeof value === "object") value = value.DEFAULT;
|
|
294
|
+
if (typeof value === "string") {
|
|
295
|
+
if (alpha) {
|
|
296
|
+
const color = parseCssColor(value);
|
|
297
|
+
if (color) value = colorToString(color, alpha);
|
|
298
|
+
}
|
|
299
|
+
return value;
|
|
300
|
+
} else if (throwOnMissing) throw new Error(`theme of "${code}" did not found`);
|
|
318
301
|
}
|
|
319
302
|
function calcMaxWidthBySize(size) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
303
|
+
var _size$match;
|
|
304
|
+
const value = ((_size$match = size.match(/^-?\d+\.?\d*/)) === null || _size$match === void 0 ? void 0 : _size$match[0]) || "";
|
|
305
|
+
const unit = size.slice(value.length);
|
|
306
|
+
if (unit === "px") {
|
|
307
|
+
const maxWidth = Number.parseFloat(value) - .1;
|
|
308
|
+
return Number.isNaN(maxWidth) ? size : `${maxWidth}${unit}`;
|
|
309
|
+
}
|
|
310
|
+
return `calc(${size} - 0.1px)`;
|
|
327
311
|
}
|
|
328
312
|
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/handlers.ts
|
|
329
315
|
function createValueHandler(handlers) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
get() {
|
|
353
|
-
return addProcessor(this, name);
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
return handler;
|
|
316
|
+
const handler = function(str, theme) {
|
|
317
|
+
var _this$__options;
|
|
318
|
+
const s = ((_this$__options = this.__options) === null || _this$__options === void 0 ? void 0 : _this$__options.sequence) || [];
|
|
319
|
+
this.__options.sequence = [];
|
|
320
|
+
for (const n of s) {
|
|
321
|
+
const res = handlers[n](str, theme);
|
|
322
|
+
if (res != null) return res;
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
function addProcessor(that, name) {
|
|
326
|
+
if (!that.__options) that.__options = { sequence: [] };
|
|
327
|
+
that.__options.sequence.push(name);
|
|
328
|
+
return that;
|
|
329
|
+
}
|
|
330
|
+
for (const name of Object.keys(handlers)) Object.defineProperty(handler, name, {
|
|
331
|
+
enumerable: true,
|
|
332
|
+
configurable: true,
|
|
333
|
+
get() {
|
|
334
|
+
return addProcessor(this, name);
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
return handler;
|
|
358
338
|
}
|
|
359
339
|
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region src/icon.ts
|
|
360
342
|
const iconFnRE = /icon\(\s*(['"])?(.*?)\1?\s*\)/g;
|
|
361
343
|
function hasIconFn(str) {
|
|
362
|
-
|
|
344
|
+
return str.includes("icon(") && str.includes(")");
|
|
363
345
|
}
|
|
364
346
|
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region src/pseudo.ts
|
|
365
349
|
const PseudoPlaceholder = "__pseudo_placeholder__";
|
|
350
|
+
/**
|
|
351
|
+
* Note: the order of following pseudo classes will affect the order of generated css.
|
|
352
|
+
*
|
|
353
|
+
* Reference: https://github.com/tailwindlabs/tailwindcss/blob/main/src/corePlugins.js#L83
|
|
354
|
+
*/
|
|
366
355
|
const PseudoClasses = Object.fromEntries([
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
"only-of-type",
|
|
420
|
-
// pseudo elements part 2
|
|
421
|
-
["backdrop-element", "::backdrop"],
|
|
422
|
-
["placeholder", "::placeholder"],
|
|
423
|
-
["before", "::before"],
|
|
424
|
-
["after", "::after"],
|
|
425
|
-
["file", "::file-selector-button"]
|
|
356
|
+
["first-letter", "::first-letter"],
|
|
357
|
+
["first-line", "::first-line"],
|
|
358
|
+
"any-link",
|
|
359
|
+
"link",
|
|
360
|
+
"visited",
|
|
361
|
+
"target",
|
|
362
|
+
["open", "[open]"],
|
|
363
|
+
"default",
|
|
364
|
+
"checked",
|
|
365
|
+
"indeterminate",
|
|
366
|
+
"placeholder-shown",
|
|
367
|
+
"autofill",
|
|
368
|
+
"optional",
|
|
369
|
+
"required",
|
|
370
|
+
"valid",
|
|
371
|
+
"invalid",
|
|
372
|
+
"user-valid",
|
|
373
|
+
"user-invalid",
|
|
374
|
+
"in-range",
|
|
375
|
+
"out-of-range",
|
|
376
|
+
"read-only",
|
|
377
|
+
"read-write",
|
|
378
|
+
"empty",
|
|
379
|
+
"focus-within",
|
|
380
|
+
"hover",
|
|
381
|
+
"focus",
|
|
382
|
+
"focus-visible",
|
|
383
|
+
"active",
|
|
384
|
+
"enabled",
|
|
385
|
+
"disabled",
|
|
386
|
+
"popover-open",
|
|
387
|
+
"root",
|
|
388
|
+
"empty",
|
|
389
|
+
["even-of-type", ":nth-of-type(even)"],
|
|
390
|
+
["even", ":nth-child(even)"],
|
|
391
|
+
["odd-of-type", ":nth-of-type(odd)"],
|
|
392
|
+
["odd", ":nth-child(odd)"],
|
|
393
|
+
["nth", `:nth-child(${PseudoPlaceholder})`],
|
|
394
|
+
["nth-last", `:nth-last-child(${PseudoPlaceholder})`],
|
|
395
|
+
["nth-last-of-type", `:nth-last-of-type(${PseudoPlaceholder})`],
|
|
396
|
+
["nth-of-type", `:nth-of-type(${PseudoPlaceholder})`],
|
|
397
|
+
"first-of-type",
|
|
398
|
+
["first", ":first-child"],
|
|
399
|
+
"last-of-type",
|
|
400
|
+
["last", ":last-child"],
|
|
401
|
+
"only-child",
|
|
402
|
+
"only-of-type",
|
|
403
|
+
["backdrop-element", "::backdrop"],
|
|
404
|
+
["placeholder", "::placeholder"],
|
|
405
|
+
["before", "::before"],
|
|
406
|
+
["after", "::after"],
|
|
407
|
+
["file", "::file-selector-button"]
|
|
426
408
|
].map((key) => Array.isArray(key) ? key : [key, `:${key}`]));
|
|
427
409
|
const PseudoClassesKeys = Object.keys(PseudoClasses);
|
|
428
|
-
const PseudoClassesColon = Object.fromEntries([
|
|
429
|
-
["backdrop", "::backdrop"]
|
|
430
|
-
].map((key) => Array.isArray(key) ? key : [key, `:${key}`]));
|
|
410
|
+
const PseudoClassesColon = Object.fromEntries([["backdrop", "::backdrop"]].map((key) => Array.isArray(key) ? key : [key, `:${key}`]));
|
|
431
411
|
const PseudoClassesColonKeys = Object.keys(PseudoClassesColon);
|
|
432
412
|
const PseudoClassFunctions = [
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
413
|
+
"not",
|
|
414
|
+
"is",
|
|
415
|
+
"where",
|
|
416
|
+
"has"
|
|
437
417
|
];
|
|
438
|
-
const PseudoClassesMulti = Object.fromEntries([
|
|
439
|
-
["selection", ["::selection", " *::selection"]],
|
|
440
|
-
["marker", ["::marker", " *::marker"]]
|
|
441
|
-
]);
|
|
418
|
+
const PseudoClassesMulti = Object.fromEntries([["selection", ["::selection", " *::selection"]], ["marker", ["::marker", " *::marker"]]]);
|
|
442
419
|
const PseudoClassesStr = Object.entries(PseudoClasses).filter(([, pseudo]) => !pseudo.startsWith("::")).map(([key]) => key).sort((a, b) => b.length - a.length).join("|");
|
|
443
420
|
const PseudoClassesColonStr = Object.entries(PseudoClassesColon).filter(([, pseudo]) => !pseudo.startsWith("::")).map(([key]) => key).sort((a, b) => b.length - a.length).join("|");
|
|
444
421
|
const PseudoClassFunctionsStr = PseudoClassFunctions.join("|");
|
|
445
422
|
const PseudoClassesMultiStr = Object.keys(PseudoClassesMulti).sort((a, b) => b.length - a.length).join("|");
|
|
446
423
|
const excludedPseudo = [
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
424
|
+
"::-webkit-resizer",
|
|
425
|
+
"::-webkit-scrollbar",
|
|
426
|
+
"::-webkit-scrollbar-button",
|
|
427
|
+
"::-webkit-scrollbar-corner",
|
|
428
|
+
"::-webkit-scrollbar-thumb",
|
|
429
|
+
"::-webkit-scrollbar-track",
|
|
430
|
+
"::-webkit-scrollbar-track-piece",
|
|
431
|
+
"::file-selector-button"
|
|
455
432
|
];
|
|
456
433
|
const PseudoClassesAndElementsStr = Object.entries(PseudoClasses).map(([key]) => key).sort((a, b) => b.length - a.length).join("|");
|
|
457
434
|
const PseudoClassesAndElementsColonStr = Object.entries(PseudoClassesColon).map(([key]) => key).sort((a, b) => b.length - a.length).join("|");
|
|
458
435
|
function createTaggedPseudoClassMatcher(tag, parent, combinator, utils) {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
sort: PseudoClassesKeys.indexOf(pseudoName) ?? PseudoClassesColonKeys.indexOf(pseudoName)
|
|
531
|
-
})
|
|
532
|
-
};
|
|
533
|
-
},
|
|
534
|
-
multiPass: true
|
|
535
|
-
};
|
|
436
|
+
const { h, variantGetBracket: variantGetBracket$1 } = utils;
|
|
437
|
+
const rawRE = /* @__PURE__ */ new RegExp(`^(${escapeRegExp(parent)}:)(\\S+)${escapeRegExp(combinator)}\\1`);
|
|
438
|
+
let splitRE;
|
|
439
|
+
let pseudoRE;
|
|
440
|
+
let pseudoColonRE;
|
|
441
|
+
let pseudoVarRE;
|
|
442
|
+
const matchBracket = (input) => {
|
|
443
|
+
var _rest$split;
|
|
444
|
+
const body = variantGetBracket$1(`${tag}-`, input, []);
|
|
445
|
+
if (!body) return;
|
|
446
|
+
const [match, rest] = body;
|
|
447
|
+
const bracketValue = h.bracket(match);
|
|
448
|
+
if (bracketValue == null) return;
|
|
449
|
+
const label = ((_rest$split = rest.split(splitRE, 1)) === null || _rest$split === void 0 ? void 0 : _rest$split[0]) ?? "";
|
|
450
|
+
const prefix = `${parent}${escapeSelector(label)}`;
|
|
451
|
+
return [
|
|
452
|
+
label,
|
|
453
|
+
input.slice(input.length - (rest.length - label.length - 1)),
|
|
454
|
+
bracketValue.includes("&") ? bracketValue.replace(/&/g, prefix) : `${prefix}${bracketValue}`
|
|
455
|
+
];
|
|
456
|
+
};
|
|
457
|
+
const matchPseudo = (input) => {
|
|
458
|
+
const match = input.match(pseudoRE) || input.match(pseudoColonRE);
|
|
459
|
+
if (!match) return;
|
|
460
|
+
const [original, fn, pseudoKey] = match;
|
|
461
|
+
const label = match[3] ?? "";
|
|
462
|
+
let pseudo = PseudoClasses[pseudoKey] || PseudoClassesColon[pseudoKey] || `:${pseudoKey}`;
|
|
463
|
+
if (fn) pseudo = `:${fn}(${pseudo})`;
|
|
464
|
+
return [
|
|
465
|
+
label,
|
|
466
|
+
input.slice(original.length),
|
|
467
|
+
`${parent}${escapeSelector(label)}${pseudo}`,
|
|
468
|
+
pseudoKey
|
|
469
|
+
];
|
|
470
|
+
};
|
|
471
|
+
const matchPseudoVar = (input) => {
|
|
472
|
+
const match = input.match(pseudoVarRE);
|
|
473
|
+
if (!match) return;
|
|
474
|
+
const [original, fn, pseudoValue] = match;
|
|
475
|
+
const label = match[3] ?? "";
|
|
476
|
+
const pseudo = `:${fn}(${pseudoValue})`;
|
|
477
|
+
return [
|
|
478
|
+
label,
|
|
479
|
+
input.slice(original.length),
|
|
480
|
+
`${parent}${escapeSelector(label)}${pseudo}`
|
|
481
|
+
];
|
|
482
|
+
};
|
|
483
|
+
return {
|
|
484
|
+
name: `pseudo:${tag}`,
|
|
485
|
+
match(input, ctx) {
|
|
486
|
+
if (!(splitRE && pseudoRE && pseudoColonRE)) {
|
|
487
|
+
splitRE = /* @__PURE__ */ new RegExp(`(?:${ctx.generator.config.separators.join("|")})`);
|
|
488
|
+
pseudoRE = /* @__PURE__ */ new RegExp(`^${tag}-(?:(?:(${PseudoClassFunctionsStr})-)?(${PseudoClassesStr}))(?:(/[\\w-]+))?(?:${ctx.generator.config.separators.join("|")})`);
|
|
489
|
+
pseudoColonRE = /* @__PURE__ */ new RegExp(`^${tag}-(?:(?:(${PseudoClassFunctionsStr})-)?(${PseudoClassesColonStr}))(?:(/[\\w-]+))?(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
490
|
+
pseudoVarRE = /* @__PURE__ */ new RegExp(`^${tag}-(?:(${PseudoClassFunctionsStr})-)?\\[(.+)\\](?:(/[\\w-]+))?(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
491
|
+
}
|
|
492
|
+
if (!input.startsWith(tag)) return;
|
|
493
|
+
const result = matchBracket(input) || matchPseudo(input) || matchPseudoVar(input);
|
|
494
|
+
if (!result) return;
|
|
495
|
+
const [_label, matcher, prefix, pseudoName = ""] = result;
|
|
496
|
+
return {
|
|
497
|
+
matcher,
|
|
498
|
+
handle: (input$1, next) => next({
|
|
499
|
+
...input$1,
|
|
500
|
+
prefix: `${prefix}${combinator}${input$1.prefix}`.replace(rawRE, "$1$2:"),
|
|
501
|
+
sort: PseudoClassesKeys.indexOf(pseudoName) ?? PseudoClassesColonKeys.indexOf(pseudoName)
|
|
502
|
+
})
|
|
503
|
+
};
|
|
504
|
+
},
|
|
505
|
+
multiPass: true
|
|
506
|
+
};
|
|
536
507
|
}
|
|
537
508
|
function createPseudoClassesAndElements(utils) {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
}
|
|
596
|
-
const match = input.match(PseudoClassesMultiRE);
|
|
597
|
-
if (match) {
|
|
598
|
-
const pseudos = PseudoClassesMulti[match[1]];
|
|
599
|
-
return pseudos.map((pseudo) => {
|
|
600
|
-
return {
|
|
601
|
-
matcher: input.slice(match[0].length),
|
|
602
|
-
handle: (input2, next) => next({
|
|
603
|
-
...input2,
|
|
604
|
-
pseudo: `${input2.pseudo}${pseudo}`
|
|
605
|
-
})
|
|
606
|
-
};
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
},
|
|
610
|
-
multiPass: false,
|
|
611
|
-
autocomplete: `(${PseudoClassesMultiStr}):`
|
|
612
|
-
}
|
|
613
|
-
];
|
|
509
|
+
const { h } = utils;
|
|
510
|
+
let PseudoClassesAndElementsRE;
|
|
511
|
+
let PseudoClassesAndElementsColonRE;
|
|
512
|
+
let PseudoClassesMultiRE;
|
|
513
|
+
return [{
|
|
514
|
+
name: "pseudo",
|
|
515
|
+
match(input, ctx) {
|
|
516
|
+
if (!(PseudoClassesAndElementsRE && PseudoClassesAndElementsColonRE)) {
|
|
517
|
+
PseudoClassesAndElementsRE = /* @__PURE__ */ new RegExp(`^(${PseudoClassesAndElementsStr})(?:-(\\d+|\\[(\\w|[+-.])+\\]))?(?:${ctx.generator.config.separators.join("|")})`);
|
|
518
|
+
PseudoClassesAndElementsColonRE = /* @__PURE__ */ new RegExp(`^(${PseudoClassesAndElementsColonStr})(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
519
|
+
}
|
|
520
|
+
const match = input.match(PseudoClassesAndElementsRE) || input.match(PseudoClassesAndElementsColonRE);
|
|
521
|
+
if (match) {
|
|
522
|
+
let pseudo = PseudoClasses[match[1]] || PseudoClassesColon[match[1]] || `:${match[1]}`;
|
|
523
|
+
if (match[2]) {
|
|
524
|
+
let anPlusB;
|
|
525
|
+
if (match[2].startsWith("[") && match[2].endsWith("]")) anPlusB = h.bracket(match[2]);
|
|
526
|
+
else anPlusB = match[2];
|
|
527
|
+
if (anPlusB) pseudo = pseudo.replace(PseudoPlaceholder, anPlusB);
|
|
528
|
+
}
|
|
529
|
+
let index = PseudoClassesKeys.indexOf(match[1]);
|
|
530
|
+
if (index === -1) index = PseudoClassesColonKeys.indexOf(match[1]);
|
|
531
|
+
if (index === -1) index = void 0;
|
|
532
|
+
return {
|
|
533
|
+
matcher: input.slice(match[0].length),
|
|
534
|
+
handle: (input$1, next) => {
|
|
535
|
+
const selectors = pseudo.includes("::") && !excludedPseudo.includes(pseudo) ? { pseudo: `${input$1.pseudo}${pseudo}` } : { selector: `${input$1.selector}${pseudo}` };
|
|
536
|
+
return next({
|
|
537
|
+
...input$1,
|
|
538
|
+
...selectors,
|
|
539
|
+
sort: index,
|
|
540
|
+
noMerge: true
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
multiPass: true,
|
|
547
|
+
autocomplete: `(${PseudoClassesAndElementsStr}|${PseudoClassesAndElementsColonStr}):`
|
|
548
|
+
}, {
|
|
549
|
+
name: "pseudo:multi",
|
|
550
|
+
match(input, ctx) {
|
|
551
|
+
if (!PseudoClassesMultiRE) PseudoClassesMultiRE = /* @__PURE__ */ new RegExp(`^(${PseudoClassesMultiStr})(?:${ctx.generator.config.separators.join("|")})`);
|
|
552
|
+
const match = input.match(PseudoClassesMultiRE);
|
|
553
|
+
if (match) return PseudoClassesMulti[match[1]].map((pseudo) => {
|
|
554
|
+
return {
|
|
555
|
+
matcher: input.slice(match[0].length),
|
|
556
|
+
handle: (input$1, next) => next({
|
|
557
|
+
...input$1,
|
|
558
|
+
pseudo: `${input$1.pseudo}${pseudo}`
|
|
559
|
+
})
|
|
560
|
+
};
|
|
561
|
+
});
|
|
562
|
+
},
|
|
563
|
+
multiPass: false,
|
|
564
|
+
autocomplete: `(${PseudoClassesMultiStr}):`
|
|
565
|
+
}];
|
|
614
566
|
}
|
|
615
567
|
function createPseudoClassFunctions(utils) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
};
|
|
568
|
+
const { getBracket: getBracket$1, h } = utils;
|
|
569
|
+
let PseudoClassFunctionsRE;
|
|
570
|
+
let PseudoClassColonFunctionsRE;
|
|
571
|
+
let PseudoClassVarFunctionRE;
|
|
572
|
+
return {
|
|
573
|
+
match(input, ctx) {
|
|
574
|
+
if (!(PseudoClassFunctionsRE && PseudoClassColonFunctionsRE)) {
|
|
575
|
+
PseudoClassFunctionsRE = /* @__PURE__ */ new RegExp(`^(${PseudoClassFunctionsStr})-(${PseudoClassesStr})(?:${ctx.generator.config.separators.join("|")})`);
|
|
576
|
+
PseudoClassColonFunctionsRE = /* @__PURE__ */ new RegExp(`^(${PseudoClassFunctionsStr})-(${PseudoClassesColonStr})(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
577
|
+
PseudoClassVarFunctionRE = /* @__PURE__ */ new RegExp(`^(${PseudoClassFunctionsStr})-(\\[.+\\])(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
578
|
+
}
|
|
579
|
+
const match = input.match(PseudoClassFunctionsRE) || input.match(PseudoClassColonFunctionsRE) || input.match(PseudoClassVarFunctionRE);
|
|
580
|
+
if (match) {
|
|
581
|
+
const fn = match[1];
|
|
582
|
+
const pseudo = getBracket$1(match[2], "[", "]") ? h.bracket(match[2]) : PseudoClasses[match[2]] || PseudoClassesColon[match[2]] || `:${match[2]}`;
|
|
583
|
+
return {
|
|
584
|
+
matcher: input.slice(match[0].length),
|
|
585
|
+
selector: (s) => `${s}:${fn}(${pseudo})`
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
multiPass: true,
|
|
590
|
+
autocomplete: `(${PseudoClassFunctionsStr})-(${PseudoClassesStr}|${PseudoClassesColonStr}):`
|
|
591
|
+
};
|
|
641
592
|
}
|
|
642
593
|
function createTaggedPseudoClasses(options, utils) {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
594
|
+
const attributify = !!(options === null || options === void 0 ? void 0 : options.attributifyPseudo);
|
|
595
|
+
let firstPrefix = (options === null || options === void 0 ? void 0 : options.prefix) ?? "";
|
|
596
|
+
firstPrefix = escapeSelector((Array.isArray(firstPrefix) ? firstPrefix : [firstPrefix]).filter(Boolean)[0] ?? "");
|
|
597
|
+
const tagWithPrefix = (tag, combinator) => createTaggedPseudoClassMatcher(tag, attributify ? `[${firstPrefix}${tag}=""]` : `.${firstPrefix}${tag}`, combinator, utils);
|
|
598
|
+
return [
|
|
599
|
+
tagWithPrefix("group", " "),
|
|
600
|
+
tagWithPrefix("peer", "~"),
|
|
601
|
+
tagWithPrefix("parent", ">"),
|
|
602
|
+
tagWithPrefix("previous", "+")
|
|
603
|
+
];
|
|
653
604
|
}
|
|
654
605
|
const PartClassesRE = /(part-\[(.+)\]:)(.+)/;
|
|
655
606
|
function createPartClasses() {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
607
|
+
return {
|
|
608
|
+
match(input) {
|
|
609
|
+
const match = input.match(PartClassesRE);
|
|
610
|
+
if (match) {
|
|
611
|
+
const part = `part(${match[2]})`;
|
|
612
|
+
return {
|
|
613
|
+
matcher: input.slice(match[1].length),
|
|
614
|
+
selector: (s) => `${s}::${part}`
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
},
|
|
618
|
+
multiPass: true
|
|
619
|
+
};
|
|
669
620
|
}
|
|
670
621
|
|
|
622
|
+
//#endregion
|
|
623
|
+
//#region src/variants.ts
|
|
671
624
|
function variantMatcher(name, handler, options = {}) {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
};
|
|
625
|
+
let re;
|
|
626
|
+
return {
|
|
627
|
+
name,
|
|
628
|
+
match(input, ctx) {
|
|
629
|
+
if (!re) re = /* @__PURE__ */ new RegExp(`^${escapeRegExp(name)}(?:${ctx.generator.config.separators.join("|")})`);
|
|
630
|
+
const match = input.match(re);
|
|
631
|
+
if (match) {
|
|
632
|
+
const matcher = input.slice(match[0].length);
|
|
633
|
+
const handlers = toArray(handler).map((handler$1) => ({
|
|
634
|
+
matcher,
|
|
635
|
+
handle: (input$1, next) => next({
|
|
636
|
+
...input$1,
|
|
637
|
+
...handler$1(input$1)
|
|
638
|
+
}),
|
|
639
|
+
...options
|
|
640
|
+
}));
|
|
641
|
+
return handlers.length === 1 ? handlers[0] : handlers;
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
autocomplete: `${name}:`
|
|
645
|
+
};
|
|
694
646
|
}
|
|
695
647
|
function variantParentMatcher(name, parent) {
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
},
|
|
713
|
-
autocomplete: `${name}:`
|
|
714
|
-
};
|
|
648
|
+
let re;
|
|
649
|
+
return {
|
|
650
|
+
name,
|
|
651
|
+
match(input, ctx) {
|
|
652
|
+
if (!re) re = /* @__PURE__ */ new RegExp(`^${escapeRegExp(name)}(?:${ctx.generator.config.separators.join("|")})`);
|
|
653
|
+
const match = input.match(re);
|
|
654
|
+
if (match) return {
|
|
655
|
+
matcher: input.slice(match[0].length),
|
|
656
|
+
handle: (input$1, next) => next({
|
|
657
|
+
...input$1,
|
|
658
|
+
parent: `${input$1.parent ? `${input$1.parent} $$ ` : ""}${parent}`
|
|
659
|
+
})
|
|
660
|
+
};
|
|
661
|
+
},
|
|
662
|
+
autocomplete: `${name}:`
|
|
663
|
+
};
|
|
715
664
|
}
|
|
716
665
|
function variantGetBracket(prefix, matcher, separators) {
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
666
|
+
if (matcher.startsWith(`${prefix}[`)) {
|
|
667
|
+
const [match, rest] = getBracket(matcher.slice(prefix.length), "[", "]") ?? [];
|
|
668
|
+
if (match && rest) {
|
|
669
|
+
for (const separator of separators) if (rest.startsWith(separator)) return [
|
|
670
|
+
match,
|
|
671
|
+
rest.slice(separator.length),
|
|
672
|
+
separator
|
|
673
|
+
];
|
|
674
|
+
return [
|
|
675
|
+
match,
|
|
676
|
+
rest,
|
|
677
|
+
""
|
|
678
|
+
];
|
|
679
|
+
}
|
|
680
|
+
}
|
|
727
681
|
}
|
|
728
682
|
function variantGetParameter(prefix, matcher, separators) {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
683
|
+
for (const p of toArray(prefix)) if (matcher.startsWith(p)) {
|
|
684
|
+
const body = variantGetBracket(p, matcher, separators);
|
|
685
|
+
if (body) {
|
|
686
|
+
const [label = "", rest = body[1]] = variantGetParameter("/", body[1], separators) ?? [];
|
|
687
|
+
return [
|
|
688
|
+
body[0],
|
|
689
|
+
rest,
|
|
690
|
+
label
|
|
691
|
+
];
|
|
692
|
+
}
|
|
693
|
+
for (const separator of separators.filter((x) => x !== "/")) {
|
|
694
|
+
const pos = matcher.indexOf(separator, p.length);
|
|
695
|
+
if (pos !== -1) {
|
|
696
|
+
const labelPos = matcher.indexOf("/", p.length);
|
|
697
|
+
const unlabelled = labelPos === -1 || pos <= labelPos;
|
|
698
|
+
return [
|
|
699
|
+
matcher.slice(p.length, unlabelled ? pos : labelPos),
|
|
700
|
+
matcher.slice(pos + separator.length),
|
|
701
|
+
unlabelled ? "" : matcher.slice(labelPos + 1, pos)
|
|
702
|
+
];
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
750
706
|
}
|
|
751
707
|
|
|
752
|
-
|
|
708
|
+
//#endregion
|
|
709
|
+
export { PseudoClassFunctions, PseudoClassFunctionsStr, PseudoClasses, PseudoClassesAndElementsColonStr, PseudoClassesAndElementsStr, PseudoClassesColon, PseudoClassesColonKeys, PseudoClassesColonStr, PseudoClassesKeys, PseudoClassesMulti, PseudoClassesMultiStr, PseudoClassesStr, alphaPlaceholders, alphaPlaceholdersRE, calcMaxWidthBySize, colorOpacityToString, colorToString, createPartClasses, createPseudoClassFunctions, createPseudoClassesAndElements, createTaggedPseudoClassMatcher, createTaggedPseudoClasses, createValueHandler, cssColorFunctions, excludedPseudo, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, hueInterpolationMethods, iconFnRE, isInterpolatedMethod, parseCssColor, polarColorSpace, rectangularColorSpace, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
|