@unocss/preset-mini 0.57.6 → 0.58.0
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.cjs +3 -3
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +4 -4
- package/dist/rules.cjs +128 -92
- package/dist/rules.d.cts +1 -5
- package/dist/rules.d.mts +1 -5
- package/dist/rules.d.ts +1 -5
- package/dist/rules.mjs +130 -93
- package/dist/shared/{preset-mini.dPVVIvNm.mjs → preset-mini.5jRPR_fm.mjs} +15 -5
- package/dist/shared/{preset-mini.XmVozI6N.d.mts → preset-mini.WMGBnRDa.d.mts} +3 -2
- package/dist/shared/{preset-mini.Jpc0QYPj.d.cts → preset-mini.WoiFygE2.d.cts} +3 -2
- package/dist/shared/{preset-mini.MACvs-wn.cjs → preset-mini.qLxuqSG-.cjs} +15 -5
- package/dist/shared/{preset-mini.QW22c5Df.d.ts → preset-mini.zVYE2D2j.d.ts} +3 -2
- package/dist/theme.cjs +2 -2
- package/dist/theme.mjs +2 -2
- package/dist/utils.cjs +545 -28
- package/dist/utils.d.cts +3 -3
- package/dist/utils.d.mts +3 -3
- package/dist/utils.d.ts +3 -3
- package/dist/utils.mjs +524 -2
- package/dist/variants.cjs +62 -31
- 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 +62 -31
- package/package.json +4 -4
- package/dist/shared/preset-mini.ImRm63ih.cjs +0 -542
- package/dist/shared/preset-mini.Stl9mkMB.mjs +0 -518
package/dist/utils.mjs
CHANGED
|
@@ -1,3 +1,525 @@
|
|
|
1
|
-
|
|
1
|
+
import { createValueHandler, getStringComponent, parseCssColor, colorToString, colorOpacityToString, getStringComponents } from '@unocss/rule-utils';
|
|
2
2
|
export * from '@unocss/rule-utils';
|
|
3
|
-
import '@unocss/core';
|
|
3
|
+
import { escapeSelector, toArray } from '@unocss/core';
|
|
4
|
+
|
|
5
|
+
const directionMap = {
|
|
6
|
+
"l": ["-left"],
|
|
7
|
+
"r": ["-right"],
|
|
8
|
+
"t": ["-top"],
|
|
9
|
+
"b": ["-bottom"],
|
|
10
|
+
"s": ["-inline-start"],
|
|
11
|
+
"e": ["-inline-end"],
|
|
12
|
+
"x": ["-left", "-right"],
|
|
13
|
+
"y": ["-top", "-bottom"],
|
|
14
|
+
"": [""],
|
|
15
|
+
"bs": ["-block-start"],
|
|
16
|
+
"be": ["-block-end"],
|
|
17
|
+
"is": ["-inline-start"],
|
|
18
|
+
"ie": ["-inline-end"],
|
|
19
|
+
"block": ["-block-start", "-block-end"],
|
|
20
|
+
"inline": ["-inline-start", "-inline-end"]
|
|
21
|
+
};
|
|
22
|
+
const insetMap = {
|
|
23
|
+
...directionMap,
|
|
24
|
+
s: ["-inset-inline-start"],
|
|
25
|
+
start: ["-inset-inline-start"],
|
|
26
|
+
e: ["-inset-inline-end"],
|
|
27
|
+
end: ["-inset-inline-end"],
|
|
28
|
+
bs: ["-inset-block-start"],
|
|
29
|
+
be: ["-inset-block-end"],
|
|
30
|
+
is: ["-inset-inline-start"],
|
|
31
|
+
ie: ["-inset-inline-end"],
|
|
32
|
+
block: ["-inset-block-start", "-inset-block-end"],
|
|
33
|
+
inline: ["-inset-inline-start", "-inset-inline-end"]
|
|
34
|
+
};
|
|
35
|
+
const cornerMap = {
|
|
36
|
+
"l": ["-top-left", "-bottom-left"],
|
|
37
|
+
"r": ["-top-right", "-bottom-right"],
|
|
38
|
+
"t": ["-top-left", "-top-right"],
|
|
39
|
+
"b": ["-bottom-left", "-bottom-right"],
|
|
40
|
+
"tl": ["-top-left"],
|
|
41
|
+
"lt": ["-top-left"],
|
|
42
|
+
"tr": ["-top-right"],
|
|
43
|
+
"rt": ["-top-right"],
|
|
44
|
+
"bl": ["-bottom-left"],
|
|
45
|
+
"lb": ["-bottom-left"],
|
|
46
|
+
"br": ["-bottom-right"],
|
|
47
|
+
"rb": ["-bottom-right"],
|
|
48
|
+
"": [""],
|
|
49
|
+
"bs": ["-start-start", "-start-end"],
|
|
50
|
+
"be": ["-end-start", "-end-end"],
|
|
51
|
+
"s": ["-end-start", "-start-start"],
|
|
52
|
+
"is": ["-end-start", "-start-start"],
|
|
53
|
+
"e": ["-start-end", "-end-end"],
|
|
54
|
+
"ie": ["-start-end", "-end-end"],
|
|
55
|
+
"ss": ["-start-start"],
|
|
56
|
+
"bs-is": ["-start-start"],
|
|
57
|
+
"is-bs": ["-start-start"],
|
|
58
|
+
"se": ["-start-end"],
|
|
59
|
+
"bs-ie": ["-start-end"],
|
|
60
|
+
"ie-bs": ["-start-end"],
|
|
61
|
+
"es": ["-end-start"],
|
|
62
|
+
"be-is": ["-end-start"],
|
|
63
|
+
"is-be": ["-end-start"],
|
|
64
|
+
"ee": ["-end-end"],
|
|
65
|
+
"be-ie": ["-end-end"],
|
|
66
|
+
"ie-be": ["-end-end"]
|
|
67
|
+
};
|
|
68
|
+
const xyzMap = {
|
|
69
|
+
"x": ["-x"],
|
|
70
|
+
"y": ["-y"],
|
|
71
|
+
"z": ["-z"],
|
|
72
|
+
"": ["-x", "-y"]
|
|
73
|
+
};
|
|
74
|
+
const basePositionMap = [
|
|
75
|
+
"top",
|
|
76
|
+
"top center",
|
|
77
|
+
"top left",
|
|
78
|
+
"top right",
|
|
79
|
+
"bottom",
|
|
80
|
+
"bottom center",
|
|
81
|
+
"bottom left",
|
|
82
|
+
"bottom right",
|
|
83
|
+
"left",
|
|
84
|
+
"left center",
|
|
85
|
+
"left top",
|
|
86
|
+
"left bottom",
|
|
87
|
+
"right",
|
|
88
|
+
"right center",
|
|
89
|
+
"right top",
|
|
90
|
+
"right bottom",
|
|
91
|
+
"center",
|
|
92
|
+
"center top",
|
|
93
|
+
"center bottom",
|
|
94
|
+
"center left",
|
|
95
|
+
"center right",
|
|
96
|
+
"center center"
|
|
97
|
+
];
|
|
98
|
+
const positionMap = Object.assign(
|
|
99
|
+
{},
|
|
100
|
+
...basePositionMap.map((p) => ({ [p.replace(/ /, "-")]: p })),
|
|
101
|
+
...basePositionMap.map((p) => ({ [p.replace(/\b(\w)\w+/g, "$1").replace(/ /, "")]: p }))
|
|
102
|
+
);
|
|
103
|
+
const globalKeywords = [
|
|
104
|
+
"inherit",
|
|
105
|
+
"initial",
|
|
106
|
+
"revert",
|
|
107
|
+
"revert-layer",
|
|
108
|
+
"unset"
|
|
109
|
+
];
|
|
110
|
+
const cssMathFnRE = /^(calc|clamp|min|max)\s*\((.+)\)(.*)/;
|
|
111
|
+
|
|
112
|
+
const numberWithUnitRE = /^(-?\d*(?:\.\d+)?)(px|pt|pc|%|r?(?:em|ex|lh|cap|ch|ic)|(?:[sld]?v|cq)(?:[whib]|min|max)|in|cm|mm|rpx)?$/i;
|
|
113
|
+
const numberRE = /^(-?\d*(?:\.\d+)?)$/i;
|
|
114
|
+
const unitOnlyRE = /^(px)$/i;
|
|
115
|
+
const bracketTypeRe = /^\[(color|length|position|quoted|string):/i;
|
|
116
|
+
|
|
117
|
+
const cssProps = [
|
|
118
|
+
// basic props
|
|
119
|
+
"color",
|
|
120
|
+
"border-color",
|
|
121
|
+
"background-color",
|
|
122
|
+
"flex-grow",
|
|
123
|
+
"flex",
|
|
124
|
+
"flex-shrink",
|
|
125
|
+
"caret-color",
|
|
126
|
+
"font",
|
|
127
|
+
"gap",
|
|
128
|
+
"opacity",
|
|
129
|
+
"visibility",
|
|
130
|
+
"z-index",
|
|
131
|
+
"font-weight",
|
|
132
|
+
"zoom",
|
|
133
|
+
"text-shadow",
|
|
134
|
+
"transform",
|
|
135
|
+
"box-shadow",
|
|
136
|
+
// positions
|
|
137
|
+
"background-position",
|
|
138
|
+
"left",
|
|
139
|
+
"right",
|
|
140
|
+
"top",
|
|
141
|
+
"bottom",
|
|
142
|
+
"object-position",
|
|
143
|
+
// sizes
|
|
144
|
+
"max-height",
|
|
145
|
+
"min-height",
|
|
146
|
+
"max-width",
|
|
147
|
+
"min-width",
|
|
148
|
+
"height",
|
|
149
|
+
"width",
|
|
150
|
+
"border-width",
|
|
151
|
+
"margin",
|
|
152
|
+
"padding",
|
|
153
|
+
"outline-width",
|
|
154
|
+
"outline-offset",
|
|
155
|
+
"font-size",
|
|
156
|
+
"line-height",
|
|
157
|
+
"text-indent",
|
|
158
|
+
"vertical-align",
|
|
159
|
+
"border-spacing",
|
|
160
|
+
"letter-spacing",
|
|
161
|
+
"word-spacing",
|
|
162
|
+
// enhances
|
|
163
|
+
"stroke",
|
|
164
|
+
"filter",
|
|
165
|
+
"backdrop-filter",
|
|
166
|
+
"fill",
|
|
167
|
+
"mask",
|
|
168
|
+
"mask-size",
|
|
169
|
+
"mask-border",
|
|
170
|
+
"clip-path",
|
|
171
|
+
"clip",
|
|
172
|
+
"border-radius"
|
|
173
|
+
];
|
|
174
|
+
function round(n) {
|
|
175
|
+
return n.toFixed(10).replace(/\.0+$/, "").replace(/(\.\d+?)0+$/, "$1");
|
|
176
|
+
}
|
|
177
|
+
function numberWithUnit(str) {
|
|
178
|
+
const match = str.match(numberWithUnitRE);
|
|
179
|
+
if (!match)
|
|
180
|
+
return;
|
|
181
|
+
const [, n, unit] = match;
|
|
182
|
+
const num = Number.parseFloat(n);
|
|
183
|
+
if (unit && !Number.isNaN(num))
|
|
184
|
+
return `${round(num)}${unit}`;
|
|
185
|
+
}
|
|
186
|
+
function auto(str) {
|
|
187
|
+
if (str === "auto" || str === "a")
|
|
188
|
+
return "auto";
|
|
189
|
+
}
|
|
190
|
+
function rem(str) {
|
|
191
|
+
if (unitOnlyRE.test(str))
|
|
192
|
+
return `1${str}`;
|
|
193
|
+
const match = str.match(numberWithUnitRE);
|
|
194
|
+
if (!match)
|
|
195
|
+
return;
|
|
196
|
+
const [, n, unit] = match;
|
|
197
|
+
const num = Number.parseFloat(n);
|
|
198
|
+
if (!Number.isNaN(num)) {
|
|
199
|
+
if (num === 0)
|
|
200
|
+
return "0";
|
|
201
|
+
return unit ? `${round(num)}${unit}` : `${round(num / 4)}rem`;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function px(str) {
|
|
205
|
+
if (unitOnlyRE.test(str))
|
|
206
|
+
return `1${str}`;
|
|
207
|
+
const match = str.match(numberWithUnitRE);
|
|
208
|
+
if (!match)
|
|
209
|
+
return;
|
|
210
|
+
const [, n, unit] = match;
|
|
211
|
+
const num = Number.parseFloat(n);
|
|
212
|
+
if (!Number.isNaN(num))
|
|
213
|
+
return unit ? `${round(num)}${unit}` : `${round(num)}px`;
|
|
214
|
+
}
|
|
215
|
+
function number(str) {
|
|
216
|
+
if (!numberRE.test(str))
|
|
217
|
+
return;
|
|
218
|
+
const num = Number.parseFloat(str);
|
|
219
|
+
if (!Number.isNaN(num))
|
|
220
|
+
return round(num);
|
|
221
|
+
}
|
|
222
|
+
function percent(str) {
|
|
223
|
+
if (str.endsWith("%"))
|
|
224
|
+
str = str.slice(0, -1);
|
|
225
|
+
if (!numberRE.test(str))
|
|
226
|
+
return;
|
|
227
|
+
const num = Number.parseFloat(str);
|
|
228
|
+
if (!Number.isNaN(num))
|
|
229
|
+
return `${round(num / 100)}`;
|
|
230
|
+
}
|
|
231
|
+
function fraction(str) {
|
|
232
|
+
if (str === "full")
|
|
233
|
+
return "100%";
|
|
234
|
+
const [left, right] = str.split("/");
|
|
235
|
+
const num = Number.parseFloat(left) / Number.parseFloat(right);
|
|
236
|
+
if (!Number.isNaN(num)) {
|
|
237
|
+
if (num === 0)
|
|
238
|
+
return "0";
|
|
239
|
+
return `${round(num * 100)}%`;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function bracketWithType(str, requiredType) {
|
|
243
|
+
if (str && str.startsWith("[") && str.endsWith("]")) {
|
|
244
|
+
let base;
|
|
245
|
+
let hintedType;
|
|
246
|
+
const match = str.match(bracketTypeRe);
|
|
247
|
+
if (!match) {
|
|
248
|
+
base = str.slice(1, -1);
|
|
249
|
+
} else {
|
|
250
|
+
if (!requiredType)
|
|
251
|
+
hintedType = match[1];
|
|
252
|
+
base = str.slice(match[0].length, -1);
|
|
253
|
+
}
|
|
254
|
+
if (!base)
|
|
255
|
+
return;
|
|
256
|
+
if (base === '=""')
|
|
257
|
+
return;
|
|
258
|
+
if (base.startsWith("--"))
|
|
259
|
+
base = `var(${base})`;
|
|
260
|
+
let curly = 0;
|
|
261
|
+
for (const i of base) {
|
|
262
|
+
if (i === "[") {
|
|
263
|
+
curly += 1;
|
|
264
|
+
} else if (i === "]") {
|
|
265
|
+
curly -= 1;
|
|
266
|
+
if (curly < 0)
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (curly)
|
|
271
|
+
return;
|
|
272
|
+
switch (hintedType) {
|
|
273
|
+
case "string":
|
|
274
|
+
return base.replace(/(^|[^\\])_/g, "$1 ").replace(/\\_/g, "_");
|
|
275
|
+
case "quoted":
|
|
276
|
+
return base.replace(/(^|[^\\])_/g, "$1 ").replace(/\\_/g, "_").replace(/(["\\])/g, "\\$1").replace(/^(.+)$/, '"$1"');
|
|
277
|
+
}
|
|
278
|
+
return base.replace(/(url\(.*?\))/g, (v) => v.replace(/_/g, "\\_")).replace(/(^|[^\\])_/g, "$1 ").replace(/\\_/g, "_").replace(/(?:calc|clamp|max|min)\((.*)/g, (match2) => {
|
|
279
|
+
const vars = [];
|
|
280
|
+
return match2.replace(/var\((--.+?)[,)]/g, (match3, g1) => {
|
|
281
|
+
vars.push(g1);
|
|
282
|
+
return match3.replace(g1, "--un-calc");
|
|
283
|
+
}).replace(/(-?\d*\.?\d(?!\b-\d.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, "$1 $2 ").replace(/--un-calc/g, () => vars.shift());
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function bracket(str) {
|
|
288
|
+
return bracketWithType(str);
|
|
289
|
+
}
|
|
290
|
+
function bracketOfColor(str) {
|
|
291
|
+
return bracketWithType(str, "color");
|
|
292
|
+
}
|
|
293
|
+
function bracketOfLength(str) {
|
|
294
|
+
return bracketWithType(str, "length");
|
|
295
|
+
}
|
|
296
|
+
function bracketOfPosition(str) {
|
|
297
|
+
return bracketWithType(str, "position");
|
|
298
|
+
}
|
|
299
|
+
function cssvar(str) {
|
|
300
|
+
if (/^\$[^\s'"`;{}]/.test(str))
|
|
301
|
+
return `var(--${escapeSelector(str.slice(1))})`;
|
|
302
|
+
}
|
|
303
|
+
function time(str) {
|
|
304
|
+
const match = str.match(/^(-?[0-9.]+)(s|ms)?$/i);
|
|
305
|
+
if (!match)
|
|
306
|
+
return;
|
|
307
|
+
const [, n, unit] = match;
|
|
308
|
+
const num = Number.parseFloat(n);
|
|
309
|
+
if (!Number.isNaN(num)) {
|
|
310
|
+
if (num === 0 && !unit)
|
|
311
|
+
return "0s";
|
|
312
|
+
return unit ? `${round(num)}${unit}` : `${round(num)}ms`;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function degree(str) {
|
|
316
|
+
const match = str.match(/^(-?[0-9.]+)(deg|rad|grad|turn)?$/i);
|
|
317
|
+
if (!match)
|
|
318
|
+
return;
|
|
319
|
+
const [, n, unit] = match;
|
|
320
|
+
const num = Number.parseFloat(n);
|
|
321
|
+
if (!Number.isNaN(num)) {
|
|
322
|
+
if (num === 0)
|
|
323
|
+
return "0";
|
|
324
|
+
return unit ? `${round(num)}${unit}` : `${round(num)}deg`;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function global(str) {
|
|
328
|
+
if (globalKeywords.includes(str))
|
|
329
|
+
return str;
|
|
330
|
+
}
|
|
331
|
+
function properties(str) {
|
|
332
|
+
if (str.split(",").every((prop) => cssProps.includes(prop)))
|
|
333
|
+
return str;
|
|
334
|
+
}
|
|
335
|
+
function position(str) {
|
|
336
|
+
if (["top", "left", "right", "bottom", "center"].includes(str))
|
|
337
|
+
return str;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const valueHandlers = {
|
|
341
|
+
__proto__: null,
|
|
342
|
+
auto: auto,
|
|
343
|
+
bracket: bracket,
|
|
344
|
+
bracketOfColor: bracketOfColor,
|
|
345
|
+
bracketOfLength: bracketOfLength,
|
|
346
|
+
bracketOfPosition: bracketOfPosition,
|
|
347
|
+
cssvar: cssvar,
|
|
348
|
+
degree: degree,
|
|
349
|
+
fraction: fraction,
|
|
350
|
+
global: global,
|
|
351
|
+
number: number,
|
|
352
|
+
numberWithUnit: numberWithUnit,
|
|
353
|
+
percent: percent,
|
|
354
|
+
position: position,
|
|
355
|
+
properties: properties,
|
|
356
|
+
px: px,
|
|
357
|
+
rem: rem,
|
|
358
|
+
time: time
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const handler = createValueHandler(valueHandlers);
|
|
362
|
+
const h = handler;
|
|
363
|
+
|
|
364
|
+
const CONTROL_MINI_NO_NEGATIVE = "$$mini-no-negative";
|
|
365
|
+
function directionSize(propertyPrefix) {
|
|
366
|
+
return ([_, direction, size], { theme }) => {
|
|
367
|
+
const v = theme.spacing?.[size || "DEFAULT"] ?? h.bracket.cssvar.global.auto.fraction.rem(size);
|
|
368
|
+
if (v != null)
|
|
369
|
+
return directionMap[direction].map((i) => [`${propertyPrefix}${i}`, v]);
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
function getThemeColorForKey(theme, colors, key = "colors") {
|
|
373
|
+
let obj = theme[key];
|
|
374
|
+
let index = -1;
|
|
375
|
+
for (const c of colors) {
|
|
376
|
+
index += 1;
|
|
377
|
+
if (obj && typeof obj !== "string") {
|
|
378
|
+
const camel = colors.slice(index).join("-").replace(/(-[a-z])/g, (n) => n.slice(1).toUpperCase());
|
|
379
|
+
if (obj[camel])
|
|
380
|
+
return obj[camel];
|
|
381
|
+
if (obj[c]) {
|
|
382
|
+
obj = obj[c];
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return void 0;
|
|
387
|
+
}
|
|
388
|
+
return obj;
|
|
389
|
+
}
|
|
390
|
+
function getThemeColor(theme, colors, key) {
|
|
391
|
+
return getThemeColorForKey(theme, colors, key) || getThemeColorForKey(theme, colors, "colors");
|
|
392
|
+
}
|
|
393
|
+
function splitShorthand(body, type) {
|
|
394
|
+
const [front, rest] = getStringComponent(body, "[", "]", ["/", ":"]) ?? [];
|
|
395
|
+
if (front != null) {
|
|
396
|
+
const match = (front.match(bracketTypeRe) ?? [])[1];
|
|
397
|
+
if (match == null || match === type)
|
|
398
|
+
return [front, rest];
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
function parseColor(body, theme, key) {
|
|
402
|
+
const split = splitShorthand(body, "color");
|
|
403
|
+
if (!split)
|
|
404
|
+
return;
|
|
405
|
+
const [main, opacity] = split;
|
|
406
|
+
const colors = main.replace(/([a-z])([0-9])/g, "$1-$2").split(/-/g);
|
|
407
|
+
const [name] = colors;
|
|
408
|
+
if (!name)
|
|
409
|
+
return;
|
|
410
|
+
let color;
|
|
411
|
+
const bracket = h.bracketOfColor(main);
|
|
412
|
+
const bracketOrMain = bracket || main;
|
|
413
|
+
if (h.numberWithUnit(bracketOrMain))
|
|
414
|
+
return;
|
|
415
|
+
if (/^#[\da-fA-F]+/.test(bracketOrMain))
|
|
416
|
+
color = bracketOrMain;
|
|
417
|
+
else if (/^hex-[\da-fA-F]+/.test(bracketOrMain))
|
|
418
|
+
color = `#${bracketOrMain.slice(4)}`;
|
|
419
|
+
else if (main.startsWith("$"))
|
|
420
|
+
color = h.cssvar(main);
|
|
421
|
+
color = color || bracket;
|
|
422
|
+
if (!color) {
|
|
423
|
+
const colorData = getThemeColor(theme, [main], key);
|
|
424
|
+
if (typeof colorData === "string")
|
|
425
|
+
color = colorData;
|
|
426
|
+
}
|
|
427
|
+
let no = "DEFAULT";
|
|
428
|
+
if (!color) {
|
|
429
|
+
let colorData;
|
|
430
|
+
const [scale] = colors.slice(-1);
|
|
431
|
+
if (/^\d+$/.test(scale)) {
|
|
432
|
+
no = scale;
|
|
433
|
+
colorData = getThemeColor(theme, colors.slice(0, -1), key);
|
|
434
|
+
if (!colorData || typeof colorData === "string")
|
|
435
|
+
color = void 0;
|
|
436
|
+
else
|
|
437
|
+
color = colorData[no];
|
|
438
|
+
} else {
|
|
439
|
+
colorData = getThemeColor(theme, colors, key);
|
|
440
|
+
if (!colorData && colors.length <= 2) {
|
|
441
|
+
[, no = no] = colors;
|
|
442
|
+
colorData = getThemeColor(theme, [name], key);
|
|
443
|
+
}
|
|
444
|
+
if (typeof colorData === "string")
|
|
445
|
+
color = colorData;
|
|
446
|
+
else if (no && colorData)
|
|
447
|
+
color = colorData[no];
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return {
|
|
451
|
+
opacity,
|
|
452
|
+
name,
|
|
453
|
+
no,
|
|
454
|
+
color,
|
|
455
|
+
cssColor: parseCssColor(color),
|
|
456
|
+
alpha: h.bracket.cssvar.percent(opacity ?? "")
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
function colorResolver(property, varName, key, shouldPass) {
|
|
460
|
+
return ([, body], { theme }) => {
|
|
461
|
+
const data = parseColor(body, theme, key);
|
|
462
|
+
if (!data)
|
|
463
|
+
return;
|
|
464
|
+
const { alpha, color, cssColor } = data;
|
|
465
|
+
const css = {};
|
|
466
|
+
if (cssColor) {
|
|
467
|
+
if (alpha != null) {
|
|
468
|
+
css[property] = colorToString(cssColor, alpha);
|
|
469
|
+
} else {
|
|
470
|
+
css[`--un-${varName}-opacity`] = colorOpacityToString(cssColor);
|
|
471
|
+
css[property] = colorToString(cssColor, `var(--un-${varName}-opacity)`);
|
|
472
|
+
}
|
|
473
|
+
} else if (color) {
|
|
474
|
+
css[property] = colorToString(color, alpha);
|
|
475
|
+
}
|
|
476
|
+
if (shouldPass?.(css) !== false)
|
|
477
|
+
return css;
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
function colorableShadows(shadows, colorVar) {
|
|
481
|
+
const colored = [];
|
|
482
|
+
shadows = toArray(shadows);
|
|
483
|
+
for (let i = 0; i < shadows.length; i++) {
|
|
484
|
+
const components = getStringComponents(shadows[i], " ", 6);
|
|
485
|
+
if (!components || components.length < 3)
|
|
486
|
+
return shadows;
|
|
487
|
+
if (parseCssColor(components.at(0)))
|
|
488
|
+
return shadows;
|
|
489
|
+
let colorVarValue = "";
|
|
490
|
+
if (parseCssColor(components.at(-1))) {
|
|
491
|
+
const color = parseCssColor(components.pop());
|
|
492
|
+
if (color)
|
|
493
|
+
colorVarValue = `, ${colorToString(color)}`;
|
|
494
|
+
}
|
|
495
|
+
colored.push(`${components.join(" ")} var(${colorVar}${colorVarValue})`);
|
|
496
|
+
}
|
|
497
|
+
return colored;
|
|
498
|
+
}
|
|
499
|
+
function hasParseableColor(color, theme, key) {
|
|
500
|
+
return color != null && !!parseColor(color, theme, key)?.color;
|
|
501
|
+
}
|
|
502
|
+
function resolveBreakpoints({ theme, generator }, key = "breakpoints") {
|
|
503
|
+
let breakpoints;
|
|
504
|
+
if (generator.userConfig && generator.userConfig.theme)
|
|
505
|
+
breakpoints = generator.userConfig.theme[key];
|
|
506
|
+
if (!breakpoints)
|
|
507
|
+
breakpoints = theme[key];
|
|
508
|
+
return breakpoints ? Object.entries(breakpoints).sort((a, b) => Number.parseInt(a[1].replace(/[a-z]+/gi, "")) - Number.parseInt(b[1].replace(/[a-z]+/gi, ""))).map(([point, size]) => ({ point, size })) : void 0;
|
|
509
|
+
}
|
|
510
|
+
function resolveVerticalBreakpoints(context) {
|
|
511
|
+
return resolveBreakpoints(context, "verticalBreakpoints");
|
|
512
|
+
}
|
|
513
|
+
function makeGlobalStaticRules(prefix, property) {
|
|
514
|
+
return globalKeywords.map((keyword) => [`${prefix}-${keyword}`, { [property ?? prefix]: keyword }]);
|
|
515
|
+
}
|
|
516
|
+
function isCSSMathFn(value) {
|
|
517
|
+
return value != null && cssMathFnRE.test(value);
|
|
518
|
+
}
|
|
519
|
+
function isSize(str) {
|
|
520
|
+
if (str[0] === "[" && str.slice(-1) === "]")
|
|
521
|
+
str = str.slice(1, -1);
|
|
522
|
+
return cssMathFnRE.test(str) || numberWithUnitRE.test(str);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
export { CONTROL_MINI_NO_NEGATIVE, colorResolver, colorableShadows, cornerMap, cssMathFnRE, directionMap, directionSize, globalKeywords, h, handler, hasParseableColor, insetMap, isCSSMathFn, isSize, makeGlobalStaticRules, parseColor, positionMap, resolveBreakpoints, resolveVerticalBreakpoints, splitShorthand, valueHandlers, xyzMap };
|
package/dist/variants.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const ruleUtils = require('@unocss/rule-utils');
|
|
4
|
-
const utils = require('./
|
|
4
|
+
const utils = require('./utils.cjs');
|
|
5
5
|
const core = require('@unocss/core');
|
|
6
6
|
|
|
7
7
|
const variantAria = {
|
|
@@ -185,21 +185,29 @@ const variantDataAttribute = {
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
};
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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 = utils.h.bracket(match) ?? ctx.theme.data?.[match] ?? "";
|
|
196
|
+
if (dataAttribute) {
|
|
197
|
+
return {
|
|
198
|
+
matcher: `${tagName}-[[data-${dataAttribute}]]:${rest}`
|
|
199
|
+
};
|
|
200
|
+
}
|
|
199
201
|
}
|
|
200
202
|
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
const variantTaggedDataAttributes = [
|
|
206
|
+
taggedData("group"),
|
|
207
|
+
taggedData("peer"),
|
|
208
|
+
taggedData("parent"),
|
|
209
|
+
taggedData("previous")
|
|
210
|
+
];
|
|
203
211
|
|
|
204
212
|
const variantLanguageDirections = [
|
|
205
213
|
ruleUtils.variantMatcher("rtl", (input) => ({ prefix: `[dir="rtl"] $$ ${input.prefix}` })),
|
|
@@ -312,18 +320,30 @@ const variantVariables = {
|
|
|
312
320
|
multiPass: true
|
|
313
321
|
};
|
|
314
322
|
|
|
315
|
-
const
|
|
323
|
+
const anchoredNumberRE = /^-?[0-9.]+(?:[a-z]+|%)?$/;
|
|
324
|
+
const numberRE = /-?[0-9.]+(?:[a-z]+|%)?/;
|
|
316
325
|
const ignoreProps = [
|
|
317
|
-
|
|
326
|
+
/\b(opacity|color|flex|backdrop-filter|^filter|transform)\b/
|
|
318
327
|
];
|
|
319
|
-
function
|
|
320
|
-
const match = value.match(
|
|
328
|
+
function negateMathFunction(value) {
|
|
329
|
+
const match = value.match(utils.cssMathFnRE);
|
|
321
330
|
if (match) {
|
|
322
|
-
const [fnBody, rest] = ruleUtils.getStringComponent(match[2]
|
|
331
|
+
const [fnBody, rest] = ruleUtils.getStringComponent(`(${match[2]})${match[3]}`, "(", ")", " ") ?? [];
|
|
323
332
|
if (fnBody)
|
|
324
333
|
return `calc(${match[1]}${fnBody} * -1)${rest ? ` ${rest}` : ""}`;
|
|
325
334
|
}
|
|
326
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
|
+
}
|
|
327
347
|
const variantNegative = {
|
|
328
348
|
name: "negative",
|
|
329
349
|
match(matcher) {
|
|
@@ -339,14 +359,22 @@ const variantNegative = {
|
|
|
339
359
|
const value = v[1]?.toString();
|
|
340
360
|
if (!value || value === "0")
|
|
341
361
|
return;
|
|
342
|
-
if (ignoreProps.some((i) => v[0]
|
|
362
|
+
if (ignoreProps.some((i) => i.test(v[0])))
|
|
343
363
|
return;
|
|
344
|
-
const
|
|
345
|
-
if (
|
|
346
|
-
v[1] =
|
|
364
|
+
const negatedFn = negateMathFunction(value);
|
|
365
|
+
if (negatedFn) {
|
|
366
|
+
v[1] = negatedFn;
|
|
347
367
|
changed = true;
|
|
348
|
-
|
|
349
|
-
|
|
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}`);
|
|
350
378
|
changed = true;
|
|
351
379
|
}
|
|
352
380
|
});
|
|
@@ -666,11 +694,14 @@ function variantPseudoClassFunctions() {
|
|
|
666
694
|
}
|
|
667
695
|
function variantTaggedPseudoClasses(options = {}) {
|
|
668
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);
|
|
669
700
|
return [
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
701
|
+
tagWithPrefix("group", " "),
|
|
702
|
+
tagWithPrefix("peer", "~"),
|
|
703
|
+
tagWithPrefix("parent", ">"),
|
|
704
|
+
tagWithPrefix("previous", "+")
|
|
674
705
|
];
|
|
675
706
|
}
|
|
676
707
|
const PartClassesRE = /(part-\[(.+)]:)(.+)/;
|
|
@@ -711,7 +742,7 @@ function variants(options) {
|
|
|
711
742
|
variantScope,
|
|
712
743
|
variantContainerQuery,
|
|
713
744
|
variantVariables,
|
|
714
|
-
|
|
745
|
+
...variantTaggedDataAttributes
|
|
715
746
|
];
|
|
716
747
|
}
|
|
717
748
|
|
|
@@ -724,7 +755,6 @@ exports.variantContainerQuery = variantContainerQuery;
|
|
|
724
755
|
exports.variantCssLayer = variantCssLayer;
|
|
725
756
|
exports.variantCustomMedia = variantCustomMedia;
|
|
726
757
|
exports.variantDataAttribute = variantDataAttribute;
|
|
727
|
-
exports.variantGroupDataAttribute = variantGroupDataAttribute;
|
|
728
758
|
exports.variantImportant = variantImportant;
|
|
729
759
|
exports.variantInternalLayer = variantInternalLayer;
|
|
730
760
|
exports.variantLanguageDirections = variantLanguageDirections;
|
|
@@ -736,6 +766,7 @@ exports.variantPseudoClassesAndElements = variantPseudoClassesAndElements;
|
|
|
736
766
|
exports.variantScope = variantScope;
|
|
737
767
|
exports.variantSelector = variantSelector;
|
|
738
768
|
exports.variantSupports = variantSupports;
|
|
769
|
+
exports.variantTaggedDataAttributes = variantTaggedDataAttributes;
|
|
739
770
|
exports.variantTaggedPseudoClasses = variantTaggedPseudoClasses;
|
|
740
771
|
exports.variantVariables = variantVariables;
|
|
741
772
|
exports.variants = variants;
|