@unocss/preset-mini 0.58.0 → 0.58.2
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/colors.d.cts +1 -1
- package/dist/colors.d.mts +1 -1
- package/dist/colors.d.ts +1 -1
- package/dist/index.cjs +11 -11
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +6 -6
- package/dist/rules.cjs +50 -1008
- package/dist/rules.d.cts +1 -1
- package/dist/rules.d.mts +1 -1
- package/dist/rules.d.ts +1 -1
- package/dist/rules.mjs +5 -968
- package/dist/shared/{preset-mini.qLxuqSG-.cjs → preset-mini.-3Qybdh5.cjs} +38 -38
- package/dist/shared/preset-mini.0CcynBZx.mjs +537 -0
- package/dist/shared/{preset-mini.5jRPR_fm.mjs → preset-mini.0UJFjS_1.mjs} +2 -2
- package/dist/shared/{preset-mini.WoiFygE2.d.cts → preset-mini.20fUBpHS.d.cts} +1 -1
- package/dist/shared/{preset-mini.zVYE2D2j.d.ts → preset-mini.8w2rXvMk.d.ts} +1 -1
- package/dist/shared/preset-mini.AVP8I7_j.mjs +747 -0
- package/dist/shared/preset-mini.ORVb5Lu8.mjs +978 -0
- package/dist/shared/preset-mini.UhMMbd34.cjs +560 -0
- package/dist/shared/{preset-mini.4DxDu2I8.d.mts → preset-mini.YxT4AwuI.d.cts} +1 -1
- package/dist/shared/preset-mini.fgwIVvur.cjs +322 -0
- package/dist/shared/preset-mini.g6cWGZM2.cjs +1021 -0
- package/dist/shared/{preset-mini.5daNC9yh.d.ts → preset-mini.gVNz4b9u.d.ts} +1 -1
- package/dist/shared/{preset-mini.7XoWRZIl.d.cts → preset-mini.hpPpX7ws.d.cts} +1 -1
- package/dist/shared/{preset-mini.7XoWRZIl.d.mts → preset-mini.hpPpX7ws.d.mts} +1 -1
- package/dist/shared/{preset-mini.7XoWRZIl.d.ts → preset-mini.hpPpX7ws.d.ts} +1 -1
- package/dist/shared/preset-mini.jXC5Sr98.cjs +772 -0
- package/dist/shared/{preset-mini.WMGBnRDa.d.mts → preset-mini.nzD7Hw_0.d.mts} +1 -1
- package/dist/shared/{preset-mini.5-XKlNyK.d.cts → preset-mini.vMrmsD3H.d.mts} +1 -1
- package/dist/shared/preset-mini.zC_vZg74.mjs +291 -0
- package/dist/theme.cjs +34 -318
- package/dist/theme.d.cts +3 -3
- package/dist/theme.d.mts +3 -3
- package/dist/theme.d.ts +3 -3
- package/dist/theme.mjs +5 -293
- package/dist/utils.cjs +28 -545
- package/dist/utils.d.cts +4 -4
- package/dist/utils.d.mts +4 -4
- package/dist/utils.d.ts +4 -4
- package/dist/utils.mjs +2 -524
- package/dist/variants.cjs +31 -770
- package/dist/variants.d.cts +3 -3
- package/dist/variants.d.mts +3 -3
- package/dist/variants.d.ts +3 -3
- package/dist/variants.mjs +4 -747
- package/package.json +4 -4
|
@@ -0,0 +1,772 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const utilities = require('./preset-mini.UhMMbd34.cjs');
|
|
4
|
+
const ruleUtils = require('@unocss/rule-utils');
|
|
5
|
+
const core = require('@unocss/core');
|
|
6
|
+
|
|
7
|
+
const variantAria = {
|
|
8
|
+
name: "aria",
|
|
9
|
+
match(matcher, ctx) {
|
|
10
|
+
const variant = ruleUtils.variantGetParameter("aria-", matcher, ctx.generator.config.separators);
|
|
11
|
+
if (variant) {
|
|
12
|
+
const [match, rest] = variant;
|
|
13
|
+
const aria = utilities.h.bracket(match) ?? ctx.theme.aria?.[match] ?? "";
|
|
14
|
+
if (aria) {
|
|
15
|
+
return {
|
|
16
|
+
matcher: rest,
|
|
17
|
+
selector: (s) => `${s}[aria-${aria}]`
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function calcMaxWidthBySize(size) {
|
|
25
|
+
const value = size.match(/^-?[0-9]+\.?[0-9]*/)?.[0] || "";
|
|
26
|
+
const unit = size.slice(value.length);
|
|
27
|
+
if (unit === "px") {
|
|
28
|
+
const maxWidth = Number.parseFloat(value) - 0.1;
|
|
29
|
+
return Number.isNaN(maxWidth) ? size : `${maxWidth}${unit}`;
|
|
30
|
+
}
|
|
31
|
+
return `calc(${size} - 0.1px)`;
|
|
32
|
+
}
|
|
33
|
+
function variantBreakpoints() {
|
|
34
|
+
const regexCache = {};
|
|
35
|
+
return {
|
|
36
|
+
name: "breakpoints",
|
|
37
|
+
match(matcher, context) {
|
|
38
|
+
const variantEntries = (utilities.resolveBreakpoints(context) ?? []).map(({ point, size }, idx) => [point, size, idx]);
|
|
39
|
+
for (const [point, size, idx] of variantEntries) {
|
|
40
|
+
if (!regexCache[point])
|
|
41
|
+
regexCache[point] = new RegExp(`^((?:([al]t-|[<~]|max-))?${point}(?:${context.generator.config.separators.join("|")}))`);
|
|
42
|
+
const match = matcher.match(regexCache[point]);
|
|
43
|
+
if (!match)
|
|
44
|
+
continue;
|
|
45
|
+
const [, pre] = match;
|
|
46
|
+
const m = matcher.slice(pre.length);
|
|
47
|
+
if (m === "container")
|
|
48
|
+
continue;
|
|
49
|
+
const isLtPrefix = pre.startsWith("lt-") || pre.startsWith("<") || pre.startsWith("max-");
|
|
50
|
+
const isAtPrefix = pre.startsWith("at-") || pre.startsWith("~");
|
|
51
|
+
let order = 1e3;
|
|
52
|
+
if (isLtPrefix) {
|
|
53
|
+
order -= idx + 1;
|
|
54
|
+
return {
|
|
55
|
+
matcher: m,
|
|
56
|
+
handle: (input, next) => next({
|
|
57
|
+
...input,
|
|
58
|
+
parent: `${input.parent ? `${input.parent} $$ ` : ""}@media (max-width: ${calcMaxWidthBySize(size)})`,
|
|
59
|
+
parentOrder: order
|
|
60
|
+
})
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
order += idx + 1;
|
|
64
|
+
if (isAtPrefix && idx < variantEntries.length - 1) {
|
|
65
|
+
return {
|
|
66
|
+
matcher: m,
|
|
67
|
+
handle: (input, next) => next({
|
|
68
|
+
...input,
|
|
69
|
+
parent: `${input.parent ? `${input.parent} $$ ` : ""}@media (min-width: ${size}) and (max-width: ${calcMaxWidthBySize(variantEntries[idx + 1][1])})`,
|
|
70
|
+
parentOrder: order
|
|
71
|
+
})
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
matcher: m,
|
|
76
|
+
handle: (input, next) => next({
|
|
77
|
+
...input,
|
|
78
|
+
parent: `${input.parent ? `${input.parent} $$ ` : ""}@media (min-width: ${size})`,
|
|
79
|
+
parentOrder: order
|
|
80
|
+
})
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
multiPass: true,
|
|
85
|
+
autocomplete: "(at-|lt-|max-|)$breakpoints:"
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function scopeMatcher(name, combinator) {
|
|
90
|
+
return {
|
|
91
|
+
name: `combinator:${name}`,
|
|
92
|
+
match(matcher, ctx) {
|
|
93
|
+
if (!matcher.startsWith(name))
|
|
94
|
+
return;
|
|
95
|
+
const separators = ctx.generator.config.separators;
|
|
96
|
+
let body = ruleUtils.variantGetBracket(`${name}-`, matcher, separators);
|
|
97
|
+
if (!body) {
|
|
98
|
+
for (const separator of separators) {
|
|
99
|
+
if (matcher.startsWith(`${name}${separator}`)) {
|
|
100
|
+
body = ["", matcher.slice(name.length + separator.length)];
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (!body)
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
let bracketValue = utilities.h.bracket(body[0]) ?? "";
|
|
108
|
+
if (bracketValue === "")
|
|
109
|
+
bracketValue = "*";
|
|
110
|
+
return {
|
|
111
|
+
matcher: body[1],
|
|
112
|
+
selector: (s) => `${s}${combinator}${bracketValue}`
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
multiPass: true
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const variantCombinators = [
|
|
119
|
+
scopeMatcher("all", " "),
|
|
120
|
+
scopeMatcher("children", ">"),
|
|
121
|
+
scopeMatcher("next", "+"),
|
|
122
|
+
scopeMatcher("sibling", "+"),
|
|
123
|
+
scopeMatcher("siblings", "~")
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
const variantContainerQuery = {
|
|
127
|
+
name: "@",
|
|
128
|
+
match(matcher, ctx) {
|
|
129
|
+
if (matcher.startsWith("@container"))
|
|
130
|
+
return;
|
|
131
|
+
const variant = ruleUtils.variantGetParameter("@", matcher, ctx.generator.config.separators);
|
|
132
|
+
if (variant) {
|
|
133
|
+
const [match, rest, label] = variant;
|
|
134
|
+
const unbracket = utilities.h.bracket(match);
|
|
135
|
+
let container;
|
|
136
|
+
if (unbracket) {
|
|
137
|
+
const minWidth = utilities.h.numberWithUnit(unbracket);
|
|
138
|
+
if (minWidth)
|
|
139
|
+
container = `(min-width: ${minWidth})`;
|
|
140
|
+
} else {
|
|
141
|
+
container = ctx.theme.containers?.[match] ?? "";
|
|
142
|
+
}
|
|
143
|
+
if (container) {
|
|
144
|
+
core.warnOnce("The container query variant is experimental and may not follow semver.");
|
|
145
|
+
return {
|
|
146
|
+
matcher: rest,
|
|
147
|
+
handle: (input, next) => next({
|
|
148
|
+
...input,
|
|
149
|
+
parent: `${input.parent ? `${input.parent} $$ ` : ""}@container${label ? ` ${label} ` : " "}${container}`
|
|
150
|
+
})
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
multiPass: true
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
function variantColorsMediaOrClass(options = {}) {
|
|
159
|
+
if (options?.dark === "class" || typeof options.dark === "object") {
|
|
160
|
+
const { dark = ".dark", light = ".light" } = typeof options.dark === "string" ? {} : options.dark;
|
|
161
|
+
return [
|
|
162
|
+
ruleUtils.variantMatcher("dark", (input) => ({ prefix: `${dark} $$ ${input.prefix}` })),
|
|
163
|
+
ruleUtils.variantMatcher("light", (input) => ({ prefix: `${light} $$ ${input.prefix}` }))
|
|
164
|
+
];
|
|
165
|
+
}
|
|
166
|
+
return [
|
|
167
|
+
ruleUtils.variantParentMatcher("dark", "@media (prefers-color-scheme: dark)"),
|
|
168
|
+
ruleUtils.variantParentMatcher("light", "@media (prefers-color-scheme: light)")
|
|
169
|
+
];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const variantDataAttribute = {
|
|
173
|
+
name: "data",
|
|
174
|
+
match(matcher, ctx) {
|
|
175
|
+
const variant = ruleUtils.variantGetParameter("data-", matcher, ctx.generator.config.separators);
|
|
176
|
+
if (variant) {
|
|
177
|
+
const [match, rest] = variant;
|
|
178
|
+
const dataAttribute = utilities.h.bracket(match) ?? ctx.theme.data?.[match] ?? "";
|
|
179
|
+
if (dataAttribute) {
|
|
180
|
+
return {
|
|
181
|
+
matcher: rest,
|
|
182
|
+
selector: (s) => `${s}[data-${dataAttribute}]`
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
function taggedData(tagName) {
|
|
189
|
+
return {
|
|
190
|
+
name: `${tagName}-data`,
|
|
191
|
+
match(matcher, ctx) {
|
|
192
|
+
const variant = ruleUtils.variantGetParameter(`${tagName}-data-`, matcher, ctx.generator.config.separators);
|
|
193
|
+
if (variant) {
|
|
194
|
+
const [match, rest] = variant;
|
|
195
|
+
const dataAttribute = utilities.h.bracket(match) ?? ctx.theme.data?.[match] ?? "";
|
|
196
|
+
if (dataAttribute) {
|
|
197
|
+
return {
|
|
198
|
+
matcher: `${tagName}-[[data-${dataAttribute}]]:${rest}`
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
const variantTaggedDataAttributes = [
|
|
206
|
+
taggedData("group"),
|
|
207
|
+
taggedData("peer"),
|
|
208
|
+
taggedData("parent"),
|
|
209
|
+
taggedData("previous")
|
|
210
|
+
];
|
|
211
|
+
|
|
212
|
+
const variantLanguageDirections = [
|
|
213
|
+
ruleUtils.variantMatcher("rtl", (input) => ({ prefix: `[dir="rtl"] $$ ${input.prefix}` })),
|
|
214
|
+
ruleUtils.variantMatcher("ltr", (input) => ({ prefix: `[dir="ltr"] $$ ${input.prefix}` }))
|
|
215
|
+
];
|
|
216
|
+
|
|
217
|
+
const variantSelector = {
|
|
218
|
+
name: "selector",
|
|
219
|
+
match(matcher, ctx) {
|
|
220
|
+
const variant = ruleUtils.variantGetBracket("selector-", matcher, ctx.generator.config.separators);
|
|
221
|
+
if (variant) {
|
|
222
|
+
const [match, rest] = variant;
|
|
223
|
+
const selector = utilities.h.bracket(match);
|
|
224
|
+
if (selector) {
|
|
225
|
+
return {
|
|
226
|
+
matcher: rest,
|
|
227
|
+
selector: () => selector
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
const variantCssLayer = {
|
|
234
|
+
name: "layer",
|
|
235
|
+
match(matcher, ctx) {
|
|
236
|
+
const variant = ruleUtils.variantGetParameter("layer-", matcher, ctx.generator.config.separators);
|
|
237
|
+
if (variant) {
|
|
238
|
+
const [match, rest] = variant;
|
|
239
|
+
const layer = utilities.h.bracket(match) ?? match;
|
|
240
|
+
if (layer) {
|
|
241
|
+
return {
|
|
242
|
+
matcher: rest,
|
|
243
|
+
handle: (input, next) => next({
|
|
244
|
+
...input,
|
|
245
|
+
parent: `${input.parent ? `${input.parent} $$ ` : ""}@layer ${layer}`
|
|
246
|
+
})
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
const variantInternalLayer = {
|
|
253
|
+
name: "uno-layer",
|
|
254
|
+
match(matcher, ctx) {
|
|
255
|
+
const variant = ruleUtils.variantGetParameter("uno-layer-", matcher, ctx.generator.config.separators);
|
|
256
|
+
if (variant) {
|
|
257
|
+
const [match, rest] = variant;
|
|
258
|
+
const layer = utilities.h.bracket(match) ?? match;
|
|
259
|
+
if (layer) {
|
|
260
|
+
return {
|
|
261
|
+
matcher: rest,
|
|
262
|
+
layer
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
const variantScope = {
|
|
269
|
+
name: "scope",
|
|
270
|
+
match(matcher, ctx) {
|
|
271
|
+
const variant = ruleUtils.variantGetBracket("scope-", matcher, ctx.generator.config.separators);
|
|
272
|
+
if (variant) {
|
|
273
|
+
const [match, rest] = variant;
|
|
274
|
+
const scope = utilities.h.bracket(match);
|
|
275
|
+
if (scope) {
|
|
276
|
+
return {
|
|
277
|
+
matcher: rest,
|
|
278
|
+
selector: (s) => `${scope} $$ ${s}`
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
const variantVariables = {
|
|
285
|
+
name: "variables",
|
|
286
|
+
match(matcher, ctx) {
|
|
287
|
+
if (!matcher.startsWith("["))
|
|
288
|
+
return;
|
|
289
|
+
const [match, rest] = ruleUtils.getBracket(matcher, "[", "]") ?? [];
|
|
290
|
+
if (!(match && rest))
|
|
291
|
+
return;
|
|
292
|
+
let newMatcher;
|
|
293
|
+
for (const separator of ctx.generator.config.separators) {
|
|
294
|
+
if (rest.startsWith(separator)) {
|
|
295
|
+
newMatcher = rest.slice(separator.length);
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (newMatcher == null)
|
|
300
|
+
return;
|
|
301
|
+
const variant = utilities.h.bracket(match) ?? "";
|
|
302
|
+
const useParent = variant.startsWith("@");
|
|
303
|
+
if (!(useParent || variant.includes("&")))
|
|
304
|
+
return;
|
|
305
|
+
return {
|
|
306
|
+
matcher: newMatcher,
|
|
307
|
+
handle(input, next) {
|
|
308
|
+
const updates = useParent ? {
|
|
309
|
+
parent: `${input.parent ? `${input.parent} $$ ` : ""}${variant}`
|
|
310
|
+
} : {
|
|
311
|
+
selector: variant.replace(/&/g, input.selector)
|
|
312
|
+
};
|
|
313
|
+
return next({
|
|
314
|
+
...input,
|
|
315
|
+
...updates
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
},
|
|
320
|
+
multiPass: true
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const anchoredNumberRE = /^-?[0-9.]+(?:[a-z]+|%)?$/;
|
|
324
|
+
const numberRE = /-?[0-9.]+(?:[a-z]+|%)?/;
|
|
325
|
+
const ignoreProps = [
|
|
326
|
+
/\b(opacity|color|flex|backdrop-filter|^filter|transform)\b/
|
|
327
|
+
];
|
|
328
|
+
function negateMathFunction(value) {
|
|
329
|
+
const match = value.match(utilities.cssMathFnRE);
|
|
330
|
+
if (match) {
|
|
331
|
+
const [fnBody, rest] = ruleUtils.getStringComponent(`(${match[2]})${match[3]}`, "(", ")", " ") ?? [];
|
|
332
|
+
if (fnBody)
|
|
333
|
+
return `calc(${match[1]}${fnBody} * -1)${rest ? ` ${rest}` : ""}`;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const negateFunctionBodyRE = /\b(hue-rotate)\s*(\(.*)/;
|
|
337
|
+
function negateFunctionBody(value) {
|
|
338
|
+
const match = value.match(negateFunctionBodyRE);
|
|
339
|
+
if (match) {
|
|
340
|
+
const [fnBody, rest] = ruleUtils.getStringComponent(match[2], "(", ")", " ") ?? [];
|
|
341
|
+
if (fnBody) {
|
|
342
|
+
const body = anchoredNumberRE.test(fnBody.slice(1, -1)) ? fnBody.replace(numberRE, (i) => i.startsWith("-") ? i.slice(1) : `-${i}`) : `(calc(${fnBody} * -1))`;
|
|
343
|
+
return `${match[1]}${body}${rest ? ` ${rest}` : ""}`;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const variantNegative = {
|
|
348
|
+
name: "negative",
|
|
349
|
+
match(matcher) {
|
|
350
|
+
if (!matcher.startsWith("-"))
|
|
351
|
+
return;
|
|
352
|
+
return {
|
|
353
|
+
matcher: matcher.slice(1),
|
|
354
|
+
body: (body) => {
|
|
355
|
+
if (body.find((v) => v[0] === utilities.CONTROL_MINI_NO_NEGATIVE))
|
|
356
|
+
return;
|
|
357
|
+
let changed = false;
|
|
358
|
+
body.forEach((v) => {
|
|
359
|
+
const value = v[1]?.toString();
|
|
360
|
+
if (!value || value === "0")
|
|
361
|
+
return;
|
|
362
|
+
if (ignoreProps.some((i) => i.test(v[0])))
|
|
363
|
+
return;
|
|
364
|
+
const negatedFn = negateMathFunction(value);
|
|
365
|
+
if (negatedFn) {
|
|
366
|
+
v[1] = negatedFn;
|
|
367
|
+
changed = true;
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
const negatedBody = negateFunctionBody(value);
|
|
371
|
+
if (negatedBody) {
|
|
372
|
+
v[1] = negatedBody;
|
|
373
|
+
changed = true;
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (anchoredNumberRE.test(value)) {
|
|
377
|
+
v[1] = value.replace(numberRE, (i) => i.startsWith("-") ? i.slice(1) : `-${i}`);
|
|
378
|
+
changed = true;
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
if (changed)
|
|
382
|
+
return body;
|
|
383
|
+
return [];
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
function variantImportant() {
|
|
390
|
+
let re;
|
|
391
|
+
return {
|
|
392
|
+
name: "important",
|
|
393
|
+
match(matcher, ctx) {
|
|
394
|
+
if (!re)
|
|
395
|
+
re = new RegExp(`^(important(?:${ctx.generator.config.separators.join("|")})|!)`);
|
|
396
|
+
let base;
|
|
397
|
+
const match = matcher.match(re);
|
|
398
|
+
if (match)
|
|
399
|
+
base = matcher.slice(match[0].length);
|
|
400
|
+
else if (matcher.endsWith("!"))
|
|
401
|
+
base = matcher.slice(0, -1);
|
|
402
|
+
if (base) {
|
|
403
|
+
return {
|
|
404
|
+
matcher: base,
|
|
405
|
+
body: (body) => {
|
|
406
|
+
body.forEach((v) => {
|
|
407
|
+
if (v[1])
|
|
408
|
+
v[1] += " !important";
|
|
409
|
+
});
|
|
410
|
+
return body;
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const variantPrint = ruleUtils.variantParentMatcher("print", "@media print");
|
|
419
|
+
const variantCustomMedia = {
|
|
420
|
+
name: "media",
|
|
421
|
+
match(matcher, ctx) {
|
|
422
|
+
const variant = ruleUtils.variantGetParameter("media-", matcher, ctx.generator.config.separators);
|
|
423
|
+
if (variant) {
|
|
424
|
+
const [match, rest] = variant;
|
|
425
|
+
let media = utilities.h.bracket(match) ?? "";
|
|
426
|
+
if (media === "")
|
|
427
|
+
media = ctx.theme.media?.[match] ?? "";
|
|
428
|
+
if (media) {
|
|
429
|
+
return {
|
|
430
|
+
matcher: rest,
|
|
431
|
+
handle: (input, next) => next({
|
|
432
|
+
...input,
|
|
433
|
+
parent: `${input.parent ? `${input.parent} $$ ` : ""}@media ${media}`
|
|
434
|
+
})
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
multiPass: true
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
const variantSupports = {
|
|
443
|
+
name: "supports",
|
|
444
|
+
match(matcher, ctx) {
|
|
445
|
+
const variant = ruleUtils.variantGetParameter("supports-", matcher, ctx.generator.config.separators);
|
|
446
|
+
if (variant) {
|
|
447
|
+
const [match, rest] = variant;
|
|
448
|
+
let supports = utilities.h.bracket(match) ?? "";
|
|
449
|
+
if (supports === "")
|
|
450
|
+
supports = ctx.theme.supports?.[match] ?? "";
|
|
451
|
+
if (supports) {
|
|
452
|
+
return {
|
|
453
|
+
matcher: rest,
|
|
454
|
+
handle: (input, next) => next({
|
|
455
|
+
...input,
|
|
456
|
+
parent: `${input.parent ? `${input.parent} $$ ` : ""}@supports ${supports}`
|
|
457
|
+
})
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
multiPass: true
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
const PseudoClasses = Object.fromEntries([
|
|
466
|
+
// pseudo elements part 1
|
|
467
|
+
["first-letter", "::first-letter"],
|
|
468
|
+
["first-line", "::first-line"],
|
|
469
|
+
// location
|
|
470
|
+
"any-link",
|
|
471
|
+
"link",
|
|
472
|
+
"visited",
|
|
473
|
+
"target",
|
|
474
|
+
["open", "[open]"],
|
|
475
|
+
// forms
|
|
476
|
+
"default",
|
|
477
|
+
"checked",
|
|
478
|
+
"indeterminate",
|
|
479
|
+
"placeholder-shown",
|
|
480
|
+
"autofill",
|
|
481
|
+
"optional",
|
|
482
|
+
"required",
|
|
483
|
+
"valid",
|
|
484
|
+
"invalid",
|
|
485
|
+
"user-valid",
|
|
486
|
+
"user-invalid",
|
|
487
|
+
"in-range",
|
|
488
|
+
"out-of-range",
|
|
489
|
+
"read-only",
|
|
490
|
+
"read-write",
|
|
491
|
+
// content
|
|
492
|
+
"empty",
|
|
493
|
+
// interactions
|
|
494
|
+
"focus-within",
|
|
495
|
+
"hover",
|
|
496
|
+
"focus",
|
|
497
|
+
"focus-visible",
|
|
498
|
+
"active",
|
|
499
|
+
"enabled",
|
|
500
|
+
"disabled",
|
|
501
|
+
// tree-structural
|
|
502
|
+
"root",
|
|
503
|
+
"empty",
|
|
504
|
+
["even-of-type", ":nth-of-type(even)"],
|
|
505
|
+
["even", ":nth-child(even)"],
|
|
506
|
+
["odd-of-type", ":nth-of-type(odd)"],
|
|
507
|
+
["odd", ":nth-child(odd)"],
|
|
508
|
+
"first-of-type",
|
|
509
|
+
["first", ":first-child"],
|
|
510
|
+
"last-of-type",
|
|
511
|
+
["last", ":last-child"],
|
|
512
|
+
"only-child",
|
|
513
|
+
"only-of-type",
|
|
514
|
+
// pseudo elements part 2
|
|
515
|
+
["backdrop-element", "::backdrop"],
|
|
516
|
+
["placeholder", "::placeholder"],
|
|
517
|
+
["before", "::before"],
|
|
518
|
+
["after", "::after"],
|
|
519
|
+
["selection", "::selection"],
|
|
520
|
+
["marker", "::marker"],
|
|
521
|
+
["file", "::file-selector-button"]
|
|
522
|
+
].map((key) => Array.isArray(key) ? key : [key, `:${key}`]));
|
|
523
|
+
const PseudoClassesKeys = Object.keys(PseudoClasses);
|
|
524
|
+
const PseudoClassesColon = Object.fromEntries([
|
|
525
|
+
["backdrop", "::backdrop"]
|
|
526
|
+
].map((key) => Array.isArray(key) ? key : [key, `:${key}`]));
|
|
527
|
+
const PseudoClassesColonKeys = Object.keys(PseudoClassesColon);
|
|
528
|
+
const PseudoClassFunctions = [
|
|
529
|
+
"not",
|
|
530
|
+
"is",
|
|
531
|
+
"where",
|
|
532
|
+
"has"
|
|
533
|
+
];
|
|
534
|
+
const PseudoClassesStr = Object.entries(PseudoClasses).filter(([, pseudo]) => !pseudo.startsWith("::")).map(([key]) => key).sort((a, b) => b.length - a.length).join("|");
|
|
535
|
+
const PseudoClassesColonStr = Object.entries(PseudoClassesColon).filter(([, pseudo]) => !pseudo.startsWith("::")).map(([key]) => key).sort((a, b) => b.length - a.length).join("|");
|
|
536
|
+
const PseudoClassFunctionsStr = PseudoClassFunctions.join("|");
|
|
537
|
+
function taggedPseudoClassMatcher(tag, parent, combinator) {
|
|
538
|
+
const rawRE = new RegExp(`^(${core.escapeRegExp(parent)}:)(\\S+)${core.escapeRegExp(combinator)}\\1`);
|
|
539
|
+
let splitRE;
|
|
540
|
+
let pseudoRE;
|
|
541
|
+
let pseudoColonRE;
|
|
542
|
+
let pseudoVarRE;
|
|
543
|
+
const matchBracket = (input) => {
|
|
544
|
+
const body = ruleUtils.variantGetBracket(`${tag}-`, input, []);
|
|
545
|
+
if (!body)
|
|
546
|
+
return;
|
|
547
|
+
const [match, rest] = body;
|
|
548
|
+
const bracketValue = utilities.h.bracket(match);
|
|
549
|
+
if (bracketValue == null)
|
|
550
|
+
return;
|
|
551
|
+
const label = rest.split(splitRE, 1)?.[0] ?? "";
|
|
552
|
+
const prefix = `${parent}${core.escapeSelector(label)}`;
|
|
553
|
+
return [
|
|
554
|
+
label,
|
|
555
|
+
input.slice(input.length - (rest.length - label.length - 1)),
|
|
556
|
+
bracketValue.includes("&") ? bracketValue.replace(/&/g, prefix) : `${prefix}${bracketValue}`
|
|
557
|
+
];
|
|
558
|
+
};
|
|
559
|
+
const matchPseudo = (input) => {
|
|
560
|
+
const match = input.match(pseudoRE) || input.match(pseudoColonRE);
|
|
561
|
+
if (!match)
|
|
562
|
+
return;
|
|
563
|
+
const [original, fn, pseudoKey] = match;
|
|
564
|
+
const label = match[3] ?? "";
|
|
565
|
+
let pseudo = PseudoClasses[pseudoKey] || PseudoClassesColon[pseudoKey] || `:${pseudoKey}`;
|
|
566
|
+
if (fn)
|
|
567
|
+
pseudo = `:${fn}(${pseudo})`;
|
|
568
|
+
return [
|
|
569
|
+
label,
|
|
570
|
+
input.slice(original.length),
|
|
571
|
+
`${parent}${core.escapeSelector(label)}${pseudo}`,
|
|
572
|
+
pseudoKey
|
|
573
|
+
];
|
|
574
|
+
};
|
|
575
|
+
const matchPseudoVar = (input) => {
|
|
576
|
+
const match = input.match(pseudoVarRE);
|
|
577
|
+
if (!match)
|
|
578
|
+
return;
|
|
579
|
+
const [original, fn, pseudoValue] = match;
|
|
580
|
+
const label = match[3] ?? "";
|
|
581
|
+
const pseudo = `:${fn}(${pseudoValue})`;
|
|
582
|
+
return [
|
|
583
|
+
label,
|
|
584
|
+
input.slice(original.length),
|
|
585
|
+
`${parent}${core.escapeSelector(label)}${pseudo}`
|
|
586
|
+
];
|
|
587
|
+
};
|
|
588
|
+
return {
|
|
589
|
+
name: `pseudo:${tag}`,
|
|
590
|
+
match(input, ctx) {
|
|
591
|
+
if (!(splitRE && pseudoRE && pseudoColonRE)) {
|
|
592
|
+
splitRE = new RegExp(`(?:${ctx.generator.config.separators.join("|")})`);
|
|
593
|
+
pseudoRE = new RegExp(`^${tag}-(?:(?:(${PseudoClassFunctionsStr})-)?(${PseudoClassesStr}))(?:(/\\w+))?(?:${ctx.generator.config.separators.join("|")})`);
|
|
594
|
+
pseudoColonRE = new RegExp(`^${tag}-(?:(?:(${PseudoClassFunctionsStr})-)?(${PseudoClassesColonStr}))(?:(/\\w+))?(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
595
|
+
pseudoVarRE = new RegExp(`^${tag}-(?:(${PseudoClassFunctionsStr})-)?\\[(.+)\\](?:(/\\w+))?(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
596
|
+
}
|
|
597
|
+
if (!input.startsWith(tag))
|
|
598
|
+
return;
|
|
599
|
+
const result = matchBracket(input) || matchPseudo(input) || matchPseudoVar(input);
|
|
600
|
+
if (!result)
|
|
601
|
+
return;
|
|
602
|
+
const [label, matcher, prefix, pseudoName = ""] = result;
|
|
603
|
+
if (label !== "")
|
|
604
|
+
core.warnOnce("The labeled variant is experimental and may not follow semver.");
|
|
605
|
+
return {
|
|
606
|
+
matcher,
|
|
607
|
+
handle: (input2, next) => next({
|
|
608
|
+
...input2,
|
|
609
|
+
prefix: `${prefix}${combinator}${input2.prefix}`.replace(rawRE, "$1$2:"),
|
|
610
|
+
sort: PseudoClassesKeys.indexOf(pseudoName) ?? PseudoClassesColonKeys.indexOf(pseudoName)
|
|
611
|
+
})
|
|
612
|
+
};
|
|
613
|
+
},
|
|
614
|
+
multiPass: true
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
const excludedPseudo = [
|
|
618
|
+
"::-webkit-resizer",
|
|
619
|
+
"::-webkit-scrollbar",
|
|
620
|
+
"::-webkit-scrollbar-button",
|
|
621
|
+
"::-webkit-scrollbar-corner",
|
|
622
|
+
"::-webkit-scrollbar-thumb",
|
|
623
|
+
"::-webkit-scrollbar-track",
|
|
624
|
+
"::-webkit-scrollbar-track-piece",
|
|
625
|
+
"::file-selector-button"
|
|
626
|
+
];
|
|
627
|
+
const PseudoClassesAndElementsStr = Object.entries(PseudoClasses).map(([key]) => key).sort((a, b) => b.length - a.length).join("|");
|
|
628
|
+
const PseudoClassesAndElementsColonStr = Object.entries(PseudoClassesColon).map(([key]) => key).sort((a, b) => b.length - a.length).join("|");
|
|
629
|
+
function variantPseudoClassesAndElements() {
|
|
630
|
+
let PseudoClassesAndElementsRE;
|
|
631
|
+
let PseudoClassesAndElementsColonRE;
|
|
632
|
+
return {
|
|
633
|
+
name: "pseudo",
|
|
634
|
+
match(input, ctx) {
|
|
635
|
+
if (!(PseudoClassesAndElementsRE && PseudoClassesAndElementsRE)) {
|
|
636
|
+
PseudoClassesAndElementsRE = new RegExp(`^(${PseudoClassesAndElementsStr})(?:${ctx.generator.config.separators.join("|")})`);
|
|
637
|
+
PseudoClassesAndElementsColonRE = new RegExp(`^(${PseudoClassesAndElementsColonStr})(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
638
|
+
}
|
|
639
|
+
const match = input.match(PseudoClassesAndElementsRE) || input.match(PseudoClassesAndElementsColonRE);
|
|
640
|
+
if (match) {
|
|
641
|
+
const pseudo = PseudoClasses[match[1]] || PseudoClassesColon[match[1]] || `:${match[1]}`;
|
|
642
|
+
let index = PseudoClassesKeys.indexOf(match[1]);
|
|
643
|
+
if (index === -1)
|
|
644
|
+
index = PseudoClassesColonKeys.indexOf(match[1]);
|
|
645
|
+
if (index === -1)
|
|
646
|
+
index = void 0;
|
|
647
|
+
return {
|
|
648
|
+
matcher: input.slice(match[0].length),
|
|
649
|
+
handle: (input2, next) => {
|
|
650
|
+
const selectors = pseudo.startsWith("::") && !excludedPseudo.includes(pseudo) ? {
|
|
651
|
+
pseudo: `${input2.pseudo}${pseudo}`
|
|
652
|
+
} : {
|
|
653
|
+
selector: `${input2.selector}${pseudo}`
|
|
654
|
+
};
|
|
655
|
+
return next({
|
|
656
|
+
...input2,
|
|
657
|
+
...selectors,
|
|
658
|
+
sort: index,
|
|
659
|
+
noMerge: true
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
},
|
|
665
|
+
multiPass: true,
|
|
666
|
+
autocomplete: `(${PseudoClassesAndElementsStr}|${PseudoClassesAndElementsColonStr}):`
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
function variantPseudoClassFunctions() {
|
|
670
|
+
let PseudoClassFunctionsRE;
|
|
671
|
+
let PseudoClassColonFunctionsRE;
|
|
672
|
+
let PseudoClassVarFunctionRE;
|
|
673
|
+
return {
|
|
674
|
+
match(input, ctx) {
|
|
675
|
+
if (!(PseudoClassFunctionsRE && PseudoClassColonFunctionsRE)) {
|
|
676
|
+
PseudoClassFunctionsRE = new RegExp(`^(${PseudoClassFunctionsStr})-(${PseudoClassesStr})(?:${ctx.generator.config.separators.join("|")})`);
|
|
677
|
+
PseudoClassColonFunctionsRE = new RegExp(`^(${PseudoClassFunctionsStr})-(${PseudoClassesColonStr})(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
678
|
+
PseudoClassVarFunctionRE = new RegExp(`^(${PseudoClassFunctionsStr})-(\\[.+\\])(?:${ctx.generator.config.separators.filter((x) => x !== "-").join("|")})`);
|
|
679
|
+
}
|
|
680
|
+
const match = input.match(PseudoClassFunctionsRE) || input.match(PseudoClassColonFunctionsRE) || input.match(PseudoClassVarFunctionRE);
|
|
681
|
+
if (match) {
|
|
682
|
+
const fn = match[1];
|
|
683
|
+
const fnVal = ruleUtils.getBracket(match[2], "[", "]");
|
|
684
|
+
const pseudo = fnVal ? utilities.h.bracket(match[2]) : PseudoClasses[match[2]] || PseudoClassesColon[match[2]] || `:${match[2]}`;
|
|
685
|
+
return {
|
|
686
|
+
matcher: input.slice(match[0].length),
|
|
687
|
+
selector: (s) => `${s}:${fn}(${pseudo})`
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
},
|
|
691
|
+
multiPass: true,
|
|
692
|
+
autocomplete: `(${PseudoClassFunctionsStr})-(${PseudoClassesStr}|${PseudoClassesColonStr}):`
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
function variantTaggedPseudoClasses(options = {}) {
|
|
696
|
+
const attributify = !!options?.attributifyPseudo;
|
|
697
|
+
let firstPrefix = options?.prefix ?? "";
|
|
698
|
+
firstPrefix = (Array.isArray(firstPrefix) ? firstPrefix : [firstPrefix]).filter(Boolean)[0] ?? "";
|
|
699
|
+
const tagWithPrefix = (tag, combinator) => taggedPseudoClassMatcher(tag, attributify ? `[${firstPrefix}${tag}=""]` : `.${firstPrefix}${tag}`, combinator);
|
|
700
|
+
return [
|
|
701
|
+
tagWithPrefix("group", " "),
|
|
702
|
+
tagWithPrefix("peer", "~"),
|
|
703
|
+
tagWithPrefix("parent", ">"),
|
|
704
|
+
tagWithPrefix("previous", "+")
|
|
705
|
+
];
|
|
706
|
+
}
|
|
707
|
+
const PartClassesRE = /(part-\[(.+)]:)(.+)/;
|
|
708
|
+
const variantPartClasses = {
|
|
709
|
+
match(input) {
|
|
710
|
+
const match = input.match(PartClassesRE);
|
|
711
|
+
if (match) {
|
|
712
|
+
const part = `part(${match[2]})`;
|
|
713
|
+
return {
|
|
714
|
+
matcher: input.slice(match[1].length),
|
|
715
|
+
selector: (s) => `${s}::${part}`
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
},
|
|
719
|
+
multiPass: true
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
function variants(options) {
|
|
723
|
+
return [
|
|
724
|
+
variantAria,
|
|
725
|
+
variantDataAttribute,
|
|
726
|
+
variantCssLayer,
|
|
727
|
+
variantSelector,
|
|
728
|
+
variantInternalLayer,
|
|
729
|
+
variantNegative,
|
|
730
|
+
variantImportant(),
|
|
731
|
+
variantSupports,
|
|
732
|
+
variantPrint,
|
|
733
|
+
variantCustomMedia,
|
|
734
|
+
variantBreakpoints(),
|
|
735
|
+
...variantCombinators,
|
|
736
|
+
variantPseudoClassesAndElements(),
|
|
737
|
+
variantPseudoClassFunctions(),
|
|
738
|
+
...variantTaggedPseudoClasses(options),
|
|
739
|
+
variantPartClasses,
|
|
740
|
+
...variantColorsMediaOrClass(options),
|
|
741
|
+
...variantLanguageDirections,
|
|
742
|
+
variantScope,
|
|
743
|
+
variantContainerQuery,
|
|
744
|
+
variantVariables,
|
|
745
|
+
...variantTaggedDataAttributes
|
|
746
|
+
];
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
exports.calcMaxWidthBySize = calcMaxWidthBySize;
|
|
750
|
+
exports.variantAria = variantAria;
|
|
751
|
+
exports.variantBreakpoints = variantBreakpoints;
|
|
752
|
+
exports.variantColorsMediaOrClass = variantColorsMediaOrClass;
|
|
753
|
+
exports.variantCombinators = variantCombinators;
|
|
754
|
+
exports.variantContainerQuery = variantContainerQuery;
|
|
755
|
+
exports.variantCssLayer = variantCssLayer;
|
|
756
|
+
exports.variantCustomMedia = variantCustomMedia;
|
|
757
|
+
exports.variantDataAttribute = variantDataAttribute;
|
|
758
|
+
exports.variantImportant = variantImportant;
|
|
759
|
+
exports.variantInternalLayer = variantInternalLayer;
|
|
760
|
+
exports.variantLanguageDirections = variantLanguageDirections;
|
|
761
|
+
exports.variantNegative = variantNegative;
|
|
762
|
+
exports.variantPartClasses = variantPartClasses;
|
|
763
|
+
exports.variantPrint = variantPrint;
|
|
764
|
+
exports.variantPseudoClassFunctions = variantPseudoClassFunctions;
|
|
765
|
+
exports.variantPseudoClassesAndElements = variantPseudoClassesAndElements;
|
|
766
|
+
exports.variantScope = variantScope;
|
|
767
|
+
exports.variantSelector = variantSelector;
|
|
768
|
+
exports.variantSupports = variantSupports;
|
|
769
|
+
exports.variantTaggedDataAttributes = variantTaggedDataAttributes;
|
|
770
|
+
exports.variantTaggedPseudoClasses = variantTaggedPseudoClasses;
|
|
771
|
+
exports.variantVariables = variantVariables;
|
|
772
|
+
exports.variants = variants;
|