@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.mjs CHANGED
@@ -1,752 +1,709 @@
1
- import { isString, escapeRegExp, escapeSelector, toArray } from '@unocss/core';
2
- import MagicString from 'magic-string';
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
- if (str === "")
6
- 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++) {
12
- switch (str[i]) {
13
- case open:
14
- if (!opened) {
15
- opened = true;
16
- openAt = i;
17
- }
18
- parenthesis++;
19
- break;
20
- case close:
21
- --parenthesis;
22
- if (parenthesis < 0)
23
- return;
24
- if (parenthesis === 0) {
25
- return [
26
- str.slice(openAt, i + 1),
27
- str.slice(i + 1),
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
- if (str === "")
37
- return;
38
- if (isString(separators))
39
- separators = [separators];
40
- if (separators.length === 0)
41
- return;
42
- const l = str.length;
43
- let parenthesis = 0;
44
- for (let i = 0; i < l; i++) {
45
- switch (str[i]) {
46
- case open:
47
- parenthesis++;
48
- break;
49
- case close:
50
- if (--parenthesis < 0)
51
- return;
52
- break;
53
- default:
54
- for (const separator of separators) {
55
- const separatorLength = separator.length;
56
- if (separatorLength && separator === str.slice(i, i + separatorLength) && parenthesis === 0) {
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
- limit = limit ?? 10;
74
- const components = [];
75
- let i = 0;
76
- while (str !== "") {
77
- if (++i > limit)
78
- return;
79
- const componentPair = getStringComponent(str, open, close, separators);
80
- if (!componentPair)
81
- return;
82
- const [component, rest] = componentPair;
83
- components.push(component);
84
- str = rest;
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
- const cssColorFunctions = ["hsl", "hsla", "hwb", "lab", "lch", "oklab", "oklch", "rgb", "rgba"];
91
- const rectangularColorSpace = ["srgb", "srgb-linear", "display-p3", "a98-rgb", "prophoto-rgb", "rec2020", "lab", "oklab", "xyz", "xyz-d50", "xyz-d65"];
92
- const polarColorSpace = ["hsl", "hwb", "lch", "oklch"];
93
- const hueInterpolationMethods = ["shorter", "longer", "increasing", "decreasing"];
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
- if (!type)
98
- return false;
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
- const color = parseHexColor(hex);
103
- if (color != null) {
104
- const { components, alpha } = color;
105
- if (alpha == null)
106
- return components;
107
- return [...components, alpha];
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
- const color = parseColor(str);
112
- if (color == null || color === false)
113
- return;
114
- const { type: casedType, components, alpha } = color;
115
- const type = casedType.toLowerCase();
116
- if (components.length === 0)
117
- return;
118
- if (cssColorFunctions.includes(type) && ![1, 3].includes(components.length))
119
- return;
120
- return {
121
- type,
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
- const alpha = color.alpha ?? 1;
128
- return typeof alpha === "string" && alphaPlaceholders.includes(alpha) ? 1 : alpha;
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
- if (typeof color === "string")
132
- return color.replace(alphaPlaceholdersRE, `${alphaOverride ?? 1}`);
133
- const { components } = color;
134
- let { alpha, type } = color;
135
- alpha = alphaOverride ?? alpha;
136
- type = type.toLowerCase();
137
- if (["hsla", "rgba"].includes(type))
138
- return `${type}(${components.join(", ")}${alpha == null ? "" : `, ${alpha}`})`;
139
- alpha = alpha == null ? "" : ` / ${alpha}`;
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
- if (!str)
146
- return;
147
- let color = parseHexColor(str);
148
- if (color != null)
149
- return color;
150
- color = cssColorKeyword(str);
151
- if (color != null)
152
- return color;
153
- color = parseCssCommaColorFunction(str);
154
- if (color != null)
155
- return color;
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
- const [, body] = str.match(/^#([\da-f]+)$/i) || [];
165
- if (!body)
166
- return;
167
- switch (body.length) {
168
- case 3:
169
- case 4: {
170
- const digits = Array.from(body, (s) => Number.parseInt(s, 16)).map((n) => n << 4 | n);
171
- return {
172
- type: "rgb",
173
- components: digits.slice(0, 3),
174
- alpha: body.length === 3 ? void 0 : Math.round(digits[3] / 255 * 100) / 100
175
- };
176
- }
177
- case 6:
178
- case 8: {
179
- const value = Number.parseInt(body, 16);
180
- return {
181
- type: "rgb",
182
- components: body.length === 6 ? [value >> 16 & 255, value >> 8 & 255, value & 255] : [value >> 24 & 255, value >> 16 & 255, value >> 8 & 255],
183
- alpha: body.length === 6 ? void 0 : Math.round((value & 255) / 255 * 100) / 100
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
- const color = {
190
- rebeccapurple: [102, 51, 153, 1]
191
- }[str];
192
- if (color != null) {
193
- return {
194
- type: "rgb",
195
- components: color.slice(0, 3),
196
- alpha: color[3]
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
- const match = color.match(/^(rgb|rgba|hsl|hsla)\((.+)\)$/i);
202
- if (!match)
203
- return;
204
- const [, type, componentString] = match;
205
- const components = getStringComponents(componentString, ",", 5);
206
- if (components) {
207
- if ([3, 4].includes(components.length)) {
208
- return {
209
- type,
210
- components: components.slice(0, 3),
211
- alpha: components[3]
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
- const match = color.match(cssColorFunctionsRe);
221
- if (!match)
222
- return;
223
- const [, fn, componentString] = match;
224
- const parsed = parseCssSpaceColorValues(`${fn} ${componentString}`);
225
- if (parsed) {
226
- const { alpha, components: [type, ...components] } = parsed;
227
- return {
228
- type,
229
- components,
230
- alpha
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
- const match = color.match(/^color\((.+)\)$/);
236
- if (!match)
237
- 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
- }
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
- const components = getStringComponents(componentString, " ");
250
- if (!components)
251
- return;
252
- let totalComponents = components.length;
253
- if (components[totalComponents - 2] === "/") {
254
- return {
255
- components: components.slice(0, totalComponents - 2),
256
- alpha: components[totalComponents - 1]
257
- };
258
- }
259
- if (components[totalComponents - 2] != null && (components[totalComponents - 2].endsWith("/") || components[totalComponents - 1].startsWith("/"))) {
260
- const removed = components.splice(totalComponents - 2);
261
- components.push(removed.join(" "));
262
- --totalComponents;
263
- }
264
- const withAlpha = getStringComponents(components[totalComponents - 1], "/", 2);
265
- if (!withAlpha)
266
- return;
267
- if (withAlpha.length === 1 || withAlpha[withAlpha.length - 1] === "")
268
- return { components };
269
- const alpha = withAlpha.pop();
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
- return str.includes("theme(") && str.includes(")");
276
+ return str.includes("theme(") && str.includes(")");
280
277
  }
281
278
  function transformThemeFn(code, theme, throwOnMissing = true) {
282
- const matches = Array.from(code.toString().matchAll(themeFnRE));
283
- if (!matches.length)
284
- return code;
285
- const s = new MagicString(code);
286
- for (const match of matches) {
287
- const rawArg = match[2];
288
- if (!rawArg)
289
- throw new Error("theme() expect exact one argument, but got 0");
290
- const value = transformThemeString(rawArg, theme, throwOnMissing);
291
- if (value) {
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
- const [rawKey, alpha] = code.split("/");
303
- const keys = rawKey.trim().split(".");
304
- let value = keys.reduce((t, k) => t?.[k], theme);
305
- if (typeof value === "object") {
306
- value = value.DEFAULT;
307
- }
308
- if (typeof value === "string") {
309
- if (alpha) {
310
- const color = parseCssColor(value);
311
- if (color)
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
- const value = size.match(/^-?\d+\.?\d*/)?.[0] || "";
321
- const unit = size.slice(value.length);
322
- if (unit === "px") {
323
- const maxWidth = Number.parseFloat(value) - 0.1;
324
- return Number.isNaN(maxWidth) ? size : `${maxWidth}${unit}`;
325
- }
326
- return `calc(${size} - 0.1px)`;
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
- const handler = function(str, theme) {
331
- const s = this.__options?.sequence || [];
332
- this.__options.sequence = [];
333
- for (const n of s) {
334
- const res = handlers[n](str, theme);
335
- if (res != null)
336
- return res;
337
- }
338
- };
339
- function addProcessor(that, name) {
340
- if (!that.__options) {
341
- that.__options = {
342
- sequence: []
343
- };
344
- }
345
- that.__options.sequence.push(name);
346
- return that;
347
- }
348
- for (const name of Object.keys(handlers)) {
349
- Object.defineProperty(handler, name, {
350
- enumerable: true,
351
- configurable: true,
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
- return str.includes("icon(") && str.includes(")");
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
- // pseudo elements part 1
368
- ["first-letter", "::first-letter"],
369
- ["first-line", "::first-line"],
370
- // location
371
- "any-link",
372
- "link",
373
- "visited",
374
- "target",
375
- ["open", "[open]"],
376
- // forms
377
- "default",
378
- "checked",
379
- "indeterminate",
380
- "placeholder-shown",
381
- "autofill",
382
- "optional",
383
- "required",
384
- "valid",
385
- "invalid",
386
- "user-valid",
387
- "user-invalid",
388
- "in-range",
389
- "out-of-range",
390
- "read-only",
391
- "read-write",
392
- // content
393
- "empty",
394
- // interactions
395
- "focus-within",
396
- "hover",
397
- "focus",
398
- "focus-visible",
399
- "active",
400
- "enabled",
401
- "disabled",
402
- "popover-open",
403
- // tree-structural
404
- "root",
405
- "empty",
406
- ["even-of-type", ":nth-of-type(even)"],
407
- ["even", ":nth-child(even)"],
408
- ["odd-of-type", ":nth-of-type(odd)"],
409
- ["odd", ":nth-child(odd)"],
410
- ["nth", `:nth-child(${PseudoPlaceholder})`],
411
- ["nth-last", `:nth-last-child(${PseudoPlaceholder})`],
412
- ["nth-last-of-type", `:nth-last-of-type(${PseudoPlaceholder})`],
413
- ["nth-of-type", `:nth-of-type(${PseudoPlaceholder})`],
414
- "first-of-type",
415
- ["first", ":first-child"],
416
- "last-of-type",
417
- ["last", ":last-child"],
418
- "only-child",
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
- "not",
434
- "is",
435
- "where",
436
- "has"
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
- "::-webkit-resizer",
448
- "::-webkit-scrollbar",
449
- "::-webkit-scrollbar-button",
450
- "::-webkit-scrollbar-corner",
451
- "::-webkit-scrollbar-thumb",
452
- "::-webkit-scrollbar-track",
453
- "::-webkit-scrollbar-track-piece",
454
- "::file-selector-button"
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
- const { h, variantGetBracket } = utils;
460
- const rawRE = new RegExp(`^(${escapeRegExp(parent)}:)(\\S+)${escapeRegExp(combinator)}\\1`);
461
- let splitRE;
462
- let pseudoRE;
463
- let pseudoColonRE;
464
- let pseudoVarRE;
465
- const matchBracket = (input) => {
466
- const body = variantGetBracket(`${tag}-`, input, []);
467
- if (!body)
468
- return;
469
- const [match, rest] = body;
470
- const bracketValue = h.bracket(match);
471
- if (bracketValue == null)
472
- return;
473
- const label = rest.split(splitRE, 1)?.[0] ?? "";
474
- const prefix = `${parent}${escapeSelector(label)}`;
475
- return [
476
- label,
477
- input.slice(input.length - (rest.length - label.length - 1)),
478
- bracketValue.includes("&") ? bracketValue.replace(/&/g, prefix) : `${prefix}${bracketValue}`
479
- ];
480
- };
481
- const matchPseudo = (input) => {
482
- const match = input.match(pseudoRE) || input.match(pseudoColonRE);
483
- if (!match)
484
- return;
485
- const [original, fn, pseudoKey] = match;
486
- const label = match[3] ?? "";
487
- let pseudo = PseudoClasses[pseudoKey] || PseudoClassesColon[pseudoKey] || `:${pseudoKey}`;
488
- if (fn)
489
- pseudo = `:${fn}(${pseudo})`;
490
- return [
491
- label,
492
- input.slice(original.length),
493
- `${parent}${escapeSelector(label)}${pseudo}`,
494
- pseudoKey
495
- ];
496
- };
497
- const matchPseudoVar = (input) => {
498
- const match = input.match(pseudoVarRE);
499
- if (!match)
500
- return;
501
- const [original, fn, pseudoValue] = match;
502
- const label = match[3] ?? "";
503
- const pseudo = `:${fn}(${pseudoValue})`;
504
- return [
505
- label,
506
- input.slice(original.length),
507
- `${parent}${escapeSelector(label)}${pseudo}`
508
- ];
509
- };
510
- return {
511
- name: `pseudo:${tag}`,
512
- match(input, ctx) {
513
- if (!(splitRE && pseudoRE && pseudoColonRE)) {
514
- splitRE = new RegExp(`(?:${ctx.generator.config.separators.join("|")})`);
515
- pseudoRE = new RegExp(`^${tag}-(?:(?:(${PseudoClassFunctionsStr})-)?(${PseudoClassesStr}))(?:(/[\\w-]+))?(?:${ctx.generator.config.separators.join("|")})`);
516
- pseudoColonRE = new RegExp(`^${tag}-(?:(?:(${PseudoClassFunctionsStr})-)?(${PseudoClassesColonStr}))(?:(/[\\w-]+))?(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
517
- pseudoVarRE = new RegExp(`^${tag}-(?:(${PseudoClassFunctionsStr})-)?\\[(.+)\\](?:(/[\\w-]+))?(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
518
- }
519
- if (!input.startsWith(tag))
520
- return;
521
- const result = matchBracket(input) || matchPseudo(input) || matchPseudoVar(input);
522
- if (!result)
523
- return;
524
- const [_label, matcher, prefix, pseudoName = ""] = result;
525
- return {
526
- matcher,
527
- handle: (input2, next) => next({
528
- ...input2,
529
- prefix: `${prefix}${combinator}${input2.prefix}`.replace(rawRE, "$1$2:"),
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
- const { h } = utils;
539
- let PseudoClassesAndElementsRE;
540
- let PseudoClassesAndElementsColonRE;
541
- let PseudoClassesMultiRE;
542
- return [
543
- {
544
- name: "pseudo",
545
- match(input, ctx) {
546
- if (!(PseudoClassesAndElementsRE && PseudoClassesAndElementsColonRE)) {
547
- PseudoClassesAndElementsRE = new RegExp(`^(${PseudoClassesAndElementsStr})(?:-(\\d+|\\[(\\w|[+-.])+\\]))?(?:${ctx.generator.config.separators.join("|")})`);
548
- PseudoClassesAndElementsColonRE = new RegExp(`^(${PseudoClassesAndElementsColonStr})(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
549
- }
550
- const match = input.match(PseudoClassesAndElementsRE) || input.match(PseudoClassesAndElementsColonRE);
551
- if (match) {
552
- let pseudo = PseudoClasses[match[1]] || PseudoClassesColon[match[1]] || `:${match[1]}`;
553
- if (match[2]) {
554
- let anPlusB;
555
- if (match[2].startsWith("[") && match[2].endsWith("]")) {
556
- anPlusB = h.bracket(match[2]);
557
- } else {
558
- anPlusB = match[2];
559
- }
560
- if (anPlusB) {
561
- pseudo = pseudo.replace(PseudoPlaceholder, anPlusB);
562
- }
563
- }
564
- let index = PseudoClassesKeys.indexOf(match[1]);
565
- if (index === -1)
566
- index = PseudoClassesColonKeys.indexOf(match[1]);
567
- if (index === -1)
568
- index = void 0;
569
- return {
570
- matcher: input.slice(match[0].length),
571
- handle: (input2, next) => {
572
- const selectors = pseudo.includes("::") && !excludedPseudo.includes(pseudo) ? {
573
- pseudo: `${input2.pseudo}${pseudo}`
574
- } : {
575
- selector: `${input2.selector}${pseudo}`
576
- };
577
- return next({
578
- ...input2,
579
- ...selectors,
580
- sort: index,
581
- noMerge: true
582
- });
583
- }
584
- };
585
- }
586
- },
587
- multiPass: true,
588
- autocomplete: `(${PseudoClassesAndElementsStr}|${PseudoClassesAndElementsColonStr}):`
589
- },
590
- {
591
- name: "pseudo:multi",
592
- match(input, ctx) {
593
- if (!PseudoClassesMultiRE) {
594
- PseudoClassesMultiRE = new RegExp(`^(${PseudoClassesMultiStr})(?:${ctx.generator.config.separators.join("|")})`);
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
- const { getBracket, h } = utils;
617
- let PseudoClassFunctionsRE;
618
- let PseudoClassColonFunctionsRE;
619
- let PseudoClassVarFunctionRE;
620
- return {
621
- match(input, ctx) {
622
- if (!(PseudoClassFunctionsRE && PseudoClassColonFunctionsRE)) {
623
- PseudoClassFunctionsRE = new RegExp(`^(${PseudoClassFunctionsStr})-(${PseudoClassesStr})(?:${ctx.generator.config.separators.join("|")})`);
624
- PseudoClassColonFunctionsRE = new RegExp(`^(${PseudoClassFunctionsStr})-(${PseudoClassesColonStr})(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
625
- PseudoClassVarFunctionRE = new RegExp(`^(${PseudoClassFunctionsStr})-(\\[.+\\])(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
626
- }
627
- const match = input.match(PseudoClassFunctionsRE) || input.match(PseudoClassColonFunctionsRE) || input.match(PseudoClassVarFunctionRE);
628
- if (match) {
629
- const fn = match[1];
630
- const fnVal = getBracket(match[2], "[", "]");
631
- const pseudo = fnVal ? h.bracket(match[2]) : PseudoClasses[match[2]] || PseudoClassesColon[match[2]] || `:${match[2]}`;
632
- return {
633
- matcher: input.slice(match[0].length),
634
- selector: (s) => `${s}:${fn}(${pseudo})`
635
- };
636
- }
637
- },
638
- multiPass: true,
639
- autocomplete: `(${PseudoClassFunctionsStr})-(${PseudoClassesStr}|${PseudoClassesColonStr}):`
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
- const attributify = !!options?.attributifyPseudo;
644
- let firstPrefix = options?.prefix ?? "";
645
- firstPrefix = escapeSelector((Array.isArray(firstPrefix) ? firstPrefix : [firstPrefix]).filter(Boolean)[0] ?? "");
646
- const tagWithPrefix = (tag, combinator) => createTaggedPseudoClassMatcher(tag, attributify ? `[${firstPrefix}${tag}=""]` : `.${firstPrefix}${tag}`, combinator, utils);
647
- return [
648
- tagWithPrefix("group", " "),
649
- tagWithPrefix("peer", "~"),
650
- tagWithPrefix("parent", ">"),
651
- tagWithPrefix("previous", "+")
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
- return {
657
- match(input) {
658
- const match = input.match(PartClassesRE);
659
- if (match) {
660
- const part = `part(${match[2]})`;
661
- return {
662
- matcher: input.slice(match[1].length),
663
- selector: (s) => `${s}::${part}`
664
- };
665
- }
666
- },
667
- multiPass: true
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
- let re;
673
- return {
674
- name,
675
- match(input, ctx) {
676
- if (!re)
677
- re = new RegExp(`^${escapeRegExp(name)}(?:${ctx.generator.config.separators.join("|")})`);
678
- const match = input.match(re);
679
- if (match) {
680
- const matcher = input.slice(match[0].length);
681
- const handlers = toArray(handler).map((handler2) => ({
682
- matcher,
683
- handle: (input2, next) => next({
684
- ...input2,
685
- ...handler2(input2)
686
- }),
687
- ...options
688
- }));
689
- return handlers.length === 1 ? handlers[0] : handlers;
690
- }
691
- },
692
- autocomplete: `${name}:`
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
- let re;
697
- return {
698
- name,
699
- match(input, ctx) {
700
- if (!re)
701
- re = new RegExp(`^${escapeRegExp(name)}(?:${ctx.generator.config.separators.join("|")})`);
702
- const match = input.match(re);
703
- if (match) {
704
- return {
705
- matcher: input.slice(match[0].length),
706
- handle: (input2, next) => next({
707
- ...input2,
708
- parent: `${input2.parent ? `${input2.parent} $$ ` : ""}${parent}`
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
- if (matcher.startsWith(`${prefix}[`)) {
718
- const [match, rest] = getBracket(matcher.slice(prefix.length), "[", "]") ?? [];
719
- if (match && rest) {
720
- for (const separator of separators) {
721
- if (rest.startsWith(separator))
722
- return [match, rest.slice(separator.length), separator];
723
- }
724
- return [match, rest, ""];
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
- for (const p of toArray(prefix)) {
730
- if (matcher.startsWith(p)) {
731
- const body = variantGetBracket(p, matcher, separators);
732
- if (body) {
733
- const [label = "", rest = body[1]] = variantGetParameter("/", body[1], separators) ?? [];
734
- return [body[0], rest, label];
735
- }
736
- for (const separator of separators.filter((x) => x !== "/")) {
737
- const pos = matcher.indexOf(separator, p.length);
738
- if (pos !== -1) {
739
- const labelPos = matcher.indexOf("/", p.length);
740
- const unlabelled = labelPos === -1 || pos <= labelPos;
741
- return [
742
- matcher.slice(p.length, unlabelled ? pos : labelPos),
743
- matcher.slice(pos + separator.length),
744
- unlabelled ? "" : matcher.slice(labelPos + 1, pos)
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
- 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 };
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 };