@unocss/preset-mini 0.22.5 → 0.24.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/README.md +1 -1
- package/dist/chunks/default.cjs +10 -1
- package/dist/chunks/default.mjs +10 -2
- package/dist/chunks/default2.cjs +127 -152
- package/dist/chunks/default2.mjs +129 -153
- package/dist/chunks/default3.cjs +46 -9
- package/dist/chunks/default3.mjs +46 -10
- package/dist/chunks/utilities.cjs +248 -25
- package/dist/chunks/utilities.mjs +245 -27
- package/dist/{colors-338f482c.d.ts → colors-db01a23e.d.ts} +1 -1
- package/dist/colors.d.ts +2 -2
- package/dist/{default-17948303.d.ts → default-c46850c2.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/rules.cjs +0 -1
- package/dist/rules.d.ts +3 -4
- package/dist/rules.mjs +1 -1
- package/dist/theme.cjs +1 -0
- package/dist/theme.d.ts +12 -5
- package/dist/theme.mjs +1 -1
- package/dist/{types-c14b808b.d.ts → types-154878eb.d.ts} +1 -0
- package/dist/{utilities-29b01158.d.ts → utilities-0dc6e82e.d.ts} +6 -5
- package/dist/utils.cjs +5 -0
- package/dist/utils.d.ts +9 -4
- package/dist/utils.mjs +1 -1
- package/dist/variants.cjs +1 -0
- package/dist/variants.d.ts +6 -5
- package/dist/variants.mjs +1 -1
- package/package.json +5 -5
|
@@ -2,6 +2,221 @@
|
|
|
2
2
|
|
|
3
3
|
const core = require('@unocss/core');
|
|
4
4
|
|
|
5
|
+
const cssColorFunctions = ["hsl", "hsla", "hwb", "lab", "lch", "oklab", "oklch", "rgb", "rgba"];
|
|
6
|
+
function hex2rgba(hex = "") {
|
|
7
|
+
const color = parseHexColor(hex);
|
|
8
|
+
if (color != null) {
|
|
9
|
+
const { components, alpha } = color;
|
|
10
|
+
if (alpha === void 0)
|
|
11
|
+
return components;
|
|
12
|
+
return [...components, alpha];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function parseCssColor(str = "") {
|
|
16
|
+
const color = parseColor$1(str);
|
|
17
|
+
if (color == null)
|
|
18
|
+
return;
|
|
19
|
+
const { type: casedType, components, alpha } = color;
|
|
20
|
+
const type = casedType.toLowerCase();
|
|
21
|
+
if (components.length === 0)
|
|
22
|
+
return;
|
|
23
|
+
if (["rgba", "hsla"].includes(type) && alpha === void 0)
|
|
24
|
+
return;
|
|
25
|
+
if (cssColorFunctions.includes(type) && components.length !== 3)
|
|
26
|
+
return;
|
|
27
|
+
return { type, components, alpha };
|
|
28
|
+
}
|
|
29
|
+
function colorToString(color, alphaOverride) {
|
|
30
|
+
const { components } = color;
|
|
31
|
+
let { alpha, type } = color;
|
|
32
|
+
alpha = alphaOverride ?? alpha;
|
|
33
|
+
type = type.toLowerCase();
|
|
34
|
+
if (["hsla", "hsl", "rgba", "rgb"].includes(type))
|
|
35
|
+
return `${type.replace("a", "")}a(${components.join(",")}${alpha == null ? "" : `,${alpha}`})`;
|
|
36
|
+
alpha = alpha == null ? "" : ` / ${alpha}`;
|
|
37
|
+
if (cssColorFunctions.includes(type))
|
|
38
|
+
return `${type}(${components.join(" ")}${alpha})`;
|
|
39
|
+
return `color(${type} ${components.join(" ")}${alpha})`;
|
|
40
|
+
}
|
|
41
|
+
function parseColor$1(str) {
|
|
42
|
+
if (!str)
|
|
43
|
+
return;
|
|
44
|
+
let color = parseHexColor(str);
|
|
45
|
+
if (color != null)
|
|
46
|
+
return color;
|
|
47
|
+
color = cssColorKeyword(str);
|
|
48
|
+
if (color != null)
|
|
49
|
+
return color;
|
|
50
|
+
color = parseCssCommaColorFunction(str);
|
|
51
|
+
if (color != null)
|
|
52
|
+
return color;
|
|
53
|
+
color = parseCssSpaceColorFunction(str);
|
|
54
|
+
if (color != null)
|
|
55
|
+
return color;
|
|
56
|
+
color = parseCssColorFunction(str);
|
|
57
|
+
if (color != null)
|
|
58
|
+
return color;
|
|
59
|
+
}
|
|
60
|
+
function parseHexColor(str) {
|
|
61
|
+
const [, body] = str.match(/^#?([\da-f]+)$/i) || [];
|
|
62
|
+
if (!body)
|
|
63
|
+
return;
|
|
64
|
+
switch (body.length) {
|
|
65
|
+
case 3:
|
|
66
|
+
case 4:
|
|
67
|
+
const digits = Array.from(body, (s) => Number.parseInt(s, 16)).map((n) => n << 4 | n);
|
|
68
|
+
return {
|
|
69
|
+
type: "rgb",
|
|
70
|
+
components: digits.slice(0, 3),
|
|
71
|
+
alpha: body.length === 3 ? void 0 : Math.round(digits[3] / 255 * 100) / 100
|
|
72
|
+
};
|
|
73
|
+
case 6:
|
|
74
|
+
case 8:
|
|
75
|
+
const value = Number.parseInt(body, 16);
|
|
76
|
+
return {
|
|
77
|
+
type: "rgb",
|
|
78
|
+
components: body.length === 6 ? [value >> 16 & 255, value >> 8 & 255, value & 255] : [value >> 24 & 255, value >> 16 & 255, value >> 8 & 255],
|
|
79
|
+
alpha: body.length === 6 ? void 0 : Math.round((value & 255) / 255 * 100) / 100
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function cssColorKeyword(str) {
|
|
84
|
+
const color = {
|
|
85
|
+
rebeccapurple: [102, 51, 153, 1]
|
|
86
|
+
}[str];
|
|
87
|
+
if (color != null) {
|
|
88
|
+
return {
|
|
89
|
+
type: "rgb",
|
|
90
|
+
components: color.slice(0, 3),
|
|
91
|
+
alpha: color[3]
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function parseCssCommaColorFunction(color) {
|
|
96
|
+
const match = color.match(/^(rgb|rgba|hsl|hsla)\((.+)\)$/i);
|
|
97
|
+
if (!match)
|
|
98
|
+
return;
|
|
99
|
+
const [, type, componentString] = match;
|
|
100
|
+
const components = getComponents(componentString, ",", 5);
|
|
101
|
+
if (components && [3, 4].includes(components.length)) {
|
|
102
|
+
return {
|
|
103
|
+
type,
|
|
104
|
+
components: components.slice(0, 3),
|
|
105
|
+
alpha: components[3]
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const cssColorFunctionsRe = new RegExp(`^(${cssColorFunctions.join("|")})\\((.+)\\)$`, "i");
|
|
110
|
+
function parseCssSpaceColorFunction(color) {
|
|
111
|
+
const match = color.match(cssColorFunctionsRe);
|
|
112
|
+
if (!match)
|
|
113
|
+
return;
|
|
114
|
+
const [, fn, componentString] = match;
|
|
115
|
+
const parsed = parseCssSpaceColorValues(`${fn} ${componentString}`);
|
|
116
|
+
if (parsed) {
|
|
117
|
+
const { alpha, components: [type, ...components] } = parsed;
|
|
118
|
+
return {
|
|
119
|
+
type,
|
|
120
|
+
components,
|
|
121
|
+
alpha
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function parseCssColorFunction(color) {
|
|
126
|
+
const match = color.match(/^color\((.+)\)$/);
|
|
127
|
+
if (!match)
|
|
128
|
+
return;
|
|
129
|
+
const parsed = parseCssSpaceColorValues(match[1]);
|
|
130
|
+
if (parsed) {
|
|
131
|
+
const { alpha, components: [type, ...components] } = parsed;
|
|
132
|
+
return {
|
|
133
|
+
type,
|
|
134
|
+
components,
|
|
135
|
+
alpha
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function parseCssSpaceColorValues(componentString) {
|
|
140
|
+
const components = getComponents(componentString);
|
|
141
|
+
if (!components)
|
|
142
|
+
return;
|
|
143
|
+
let totalComponents = components.length;
|
|
144
|
+
if (components[totalComponents - 2] === "/") {
|
|
145
|
+
return {
|
|
146
|
+
components: components.slice(0, totalComponents - 2),
|
|
147
|
+
alpha: components[totalComponents - 1]
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (components[totalComponents - 2] != null && (components[totalComponents - 2].endsWith("/") || components[totalComponents - 1].startsWith("/"))) {
|
|
151
|
+
const removed = components.splice(totalComponents - 2);
|
|
152
|
+
components.push(removed.join(" "));
|
|
153
|
+
--totalComponents;
|
|
154
|
+
}
|
|
155
|
+
const withAlpha = getComponents(components[totalComponents - 1], "/", 3);
|
|
156
|
+
if (!withAlpha)
|
|
157
|
+
return;
|
|
158
|
+
if (withAlpha.length === 1 || withAlpha[withAlpha.length - 1] === "")
|
|
159
|
+
return { components };
|
|
160
|
+
const alpha = withAlpha.pop();
|
|
161
|
+
components[totalComponents - 1] = withAlpha.join("/");
|
|
162
|
+
return {
|
|
163
|
+
components,
|
|
164
|
+
alpha
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function getComponent(str, separator) {
|
|
168
|
+
str = str.trim();
|
|
169
|
+
if (str === "")
|
|
170
|
+
return;
|
|
171
|
+
const l = str.length;
|
|
172
|
+
let parenthesis = 0;
|
|
173
|
+
for (let i = 0; i < l; i++) {
|
|
174
|
+
switch (str[i]) {
|
|
175
|
+
case "(":
|
|
176
|
+
parenthesis++;
|
|
177
|
+
break;
|
|
178
|
+
case ")":
|
|
179
|
+
if (--parenthesis < 0)
|
|
180
|
+
return;
|
|
181
|
+
break;
|
|
182
|
+
case separator:
|
|
183
|
+
if (parenthesis === 0) {
|
|
184
|
+
const component = str.slice(0, i).trim();
|
|
185
|
+
if (component === "")
|
|
186
|
+
return;
|
|
187
|
+
return [
|
|
188
|
+
component,
|
|
189
|
+
str.slice(i + 1).trim()
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return [
|
|
195
|
+
str,
|
|
196
|
+
""
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
function getComponents(str, separator, limit) {
|
|
200
|
+
separator = separator ?? " ";
|
|
201
|
+
if (separator.length !== 1)
|
|
202
|
+
return;
|
|
203
|
+
limit = limit ?? 10;
|
|
204
|
+
const components = [];
|
|
205
|
+
let i = 0;
|
|
206
|
+
while (str !== "") {
|
|
207
|
+
if (++i > limit)
|
|
208
|
+
return;
|
|
209
|
+
const componentPair = getComponent(str, separator);
|
|
210
|
+
if (!componentPair)
|
|
211
|
+
return;
|
|
212
|
+
const [component, rest] = componentPair;
|
|
213
|
+
components.push(component);
|
|
214
|
+
str = rest;
|
|
215
|
+
}
|
|
216
|
+
if (components.length > 0)
|
|
217
|
+
return components;
|
|
218
|
+
}
|
|
219
|
+
|
|
5
220
|
const directionMap = {
|
|
6
221
|
"l": ["-left"],
|
|
7
222
|
"r": ["-right"],
|
|
@@ -141,7 +356,7 @@ const cssProps = [
|
|
|
141
356
|
"clip-path",
|
|
142
357
|
"clip"
|
|
143
358
|
];
|
|
144
|
-
const numberWithUnitRE = /^(-?[0-9.]+)(px|pt|pc|rem|em|%|vh|vw|in|cm|mm|ex|ch|vmin|vmax)?$/i;
|
|
359
|
+
const numberWithUnitRE = /^(-?[0-9.]+)(px|pt|pc|rem|em|%|vh|vw|in|cm|mm|ex|ch|vmin|vmax|rpx)?$/i;
|
|
145
360
|
const numberRE = /^(-?[0-9.]+)$/i;
|
|
146
361
|
const unitOnlyRE = /^(px)$/i;
|
|
147
362
|
function round(n) {
|
|
@@ -212,8 +427,8 @@ function bracket(str) {
|
|
|
212
427
|
}
|
|
213
428
|
}
|
|
214
429
|
function cssvar(str) {
|
|
215
|
-
if (str.
|
|
216
|
-
return `var(--${str.slice(1)})`;
|
|
430
|
+
if (str.match(/^\$\S/))
|
|
431
|
+
return `var(--${core.escapeSelector(str.slice(1))})`;
|
|
217
432
|
}
|
|
218
433
|
function time(str) {
|
|
219
434
|
const match = str.match(/^(-?[0-9.]+)(s|ms)?$/i);
|
|
@@ -296,7 +511,7 @@ const parseColor = (body, theme) => {
|
|
|
296
511
|
colorData = getThemeColor(theme, colors.slice(0, -1));
|
|
297
512
|
} else {
|
|
298
513
|
colorData = getThemeColor(theme, colors);
|
|
299
|
-
if (!colorData) {
|
|
514
|
+
if (!colorData && colors.length <= 2) {
|
|
300
515
|
[, no = no] = colors;
|
|
301
516
|
colorData = getThemeColor(theme, [name]);
|
|
302
517
|
}
|
|
@@ -306,58 +521,66 @@ const parseColor = (body, theme) => {
|
|
|
306
521
|
else if (no && colorData)
|
|
307
522
|
color = colorData[no];
|
|
308
523
|
}
|
|
309
|
-
const rgba = core.hex2rgba(color);
|
|
310
|
-
const alpha = opacity ? opacity[0] === "[" ? handler.bracket.percent(opacity) : parseFloat(opacity) / 100 : rgba?.[3];
|
|
311
|
-
const hasAlpha = alpha != null && !Number.isNaN(alpha);
|
|
312
|
-
if (rgba) {
|
|
313
|
-
if (hasAlpha) {
|
|
314
|
-
rgba[3] = typeof alpha === "string" && !alpha.includes("%") ? parseFloat(alpha) : alpha;
|
|
315
|
-
} else {
|
|
316
|
-
rgba.splice(3);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
524
|
return {
|
|
320
525
|
opacity,
|
|
321
526
|
name,
|
|
322
527
|
no,
|
|
323
528
|
color,
|
|
324
|
-
|
|
325
|
-
alpha:
|
|
529
|
+
cssColor: parseCssColor(color),
|
|
530
|
+
alpha: handler.bracket.cssvar.percent(opacity ?? "")
|
|
326
531
|
};
|
|
327
532
|
};
|
|
328
533
|
const colorResolver = (property, varName) => ([, body], { theme }) => {
|
|
329
534
|
const data = parseColor(body, theme);
|
|
330
535
|
if (!data)
|
|
331
536
|
return;
|
|
332
|
-
const { alpha,
|
|
333
|
-
if (
|
|
334
|
-
return;
|
|
335
|
-
if (rgba) {
|
|
537
|
+
const { alpha, color, cssColor } = data;
|
|
538
|
+
if (cssColor) {
|
|
336
539
|
if (alpha != null) {
|
|
337
540
|
return {
|
|
338
|
-
[property]:
|
|
541
|
+
[property]: colorToString(cssColor, alpha)
|
|
339
542
|
};
|
|
340
543
|
} else {
|
|
341
544
|
return {
|
|
342
|
-
[`--un-${varName}-opacity`]:
|
|
343
|
-
[property]:
|
|
545
|
+
[`--un-${varName}-opacity`]: cssColor.alpha ?? 1,
|
|
546
|
+
[property]: colorToString(cssColor, `var(--un-${varName}-opacity)`)
|
|
344
547
|
};
|
|
345
548
|
}
|
|
346
|
-
} else {
|
|
549
|
+
} else if (color) {
|
|
347
550
|
return {
|
|
348
|
-
[property]: color.replace("%alpha", `${alpha
|
|
551
|
+
[property]: color.replace("%alpha", `${alpha ?? 1}`)
|
|
349
552
|
};
|
|
350
553
|
}
|
|
351
554
|
};
|
|
555
|
+
const colorableShadows = (shadows, colorVar) => {
|
|
556
|
+
const colored = [];
|
|
557
|
+
shadows = core.toArray(shadows);
|
|
558
|
+
for (let i = 0; i < shadows.length; i++) {
|
|
559
|
+
const components = getComponents(shadows[i]);
|
|
560
|
+
if (!components)
|
|
561
|
+
return shadows;
|
|
562
|
+
const [maybeColor, ...size] = components.reverse();
|
|
563
|
+
const color = parseCssColor(maybeColor);
|
|
564
|
+
if (color == null)
|
|
565
|
+
return shadows;
|
|
566
|
+
colored.push(`${size.reverse().join(" ")} var(${colorVar}, ${colorToString(color)})`);
|
|
567
|
+
}
|
|
568
|
+
return colored;
|
|
569
|
+
};
|
|
352
570
|
|
|
353
571
|
exports.colorResolver = colorResolver;
|
|
572
|
+
exports.colorToString = colorToString;
|
|
573
|
+
exports.colorableShadows = colorableShadows;
|
|
354
574
|
exports.cornerMap = cornerMap;
|
|
355
575
|
exports.directionMap = directionMap;
|
|
356
576
|
exports.directionSize = directionSize;
|
|
577
|
+
exports.getComponents = getComponents;
|
|
357
578
|
exports.h = h;
|
|
358
579
|
exports.handler = handler;
|
|
580
|
+
exports.hex2rgba = hex2rgba;
|
|
359
581
|
exports.insetMap = insetMap;
|
|
360
582
|
exports.parseColor = parseColor;
|
|
583
|
+
exports.parseCssColor = parseCssColor;
|
|
361
584
|
exports.positionMap = positionMap;
|
|
362
585
|
exports.valueHandlers = valueHandlers;
|
|
363
586
|
exports.xyzMap = xyzMap;
|
|
@@ -1,4 +1,219 @@
|
|
|
1
|
-
import { createValueHandler,
|
|
1
|
+
import { escapeSelector, createValueHandler, toArray } from '@unocss/core';
|
|
2
|
+
|
|
3
|
+
const cssColorFunctions = ["hsl", "hsla", "hwb", "lab", "lch", "oklab", "oklch", "rgb", "rgba"];
|
|
4
|
+
function hex2rgba(hex = "") {
|
|
5
|
+
const color = parseHexColor(hex);
|
|
6
|
+
if (color != null) {
|
|
7
|
+
const { components, alpha } = color;
|
|
8
|
+
if (alpha === void 0)
|
|
9
|
+
return components;
|
|
10
|
+
return [...components, alpha];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function parseCssColor(str = "") {
|
|
14
|
+
const color = parseColor$1(str);
|
|
15
|
+
if (color == null)
|
|
16
|
+
return;
|
|
17
|
+
const { type: casedType, components, alpha } = color;
|
|
18
|
+
const type = casedType.toLowerCase();
|
|
19
|
+
if (components.length === 0)
|
|
20
|
+
return;
|
|
21
|
+
if (["rgba", "hsla"].includes(type) && alpha === void 0)
|
|
22
|
+
return;
|
|
23
|
+
if (cssColorFunctions.includes(type) && components.length !== 3)
|
|
24
|
+
return;
|
|
25
|
+
return { type, components, alpha };
|
|
26
|
+
}
|
|
27
|
+
function colorToString(color, alphaOverride) {
|
|
28
|
+
const { components } = color;
|
|
29
|
+
let { alpha, type } = color;
|
|
30
|
+
alpha = alphaOverride ?? alpha;
|
|
31
|
+
type = type.toLowerCase();
|
|
32
|
+
if (["hsla", "hsl", "rgba", "rgb"].includes(type))
|
|
33
|
+
return `${type.replace("a", "")}a(${components.join(",")}${alpha == null ? "" : `,${alpha}`})`;
|
|
34
|
+
alpha = alpha == null ? "" : ` / ${alpha}`;
|
|
35
|
+
if (cssColorFunctions.includes(type))
|
|
36
|
+
return `${type}(${components.join(" ")}${alpha})`;
|
|
37
|
+
return `color(${type} ${components.join(" ")}${alpha})`;
|
|
38
|
+
}
|
|
39
|
+
function parseColor$1(str) {
|
|
40
|
+
if (!str)
|
|
41
|
+
return;
|
|
42
|
+
let color = parseHexColor(str);
|
|
43
|
+
if (color != null)
|
|
44
|
+
return color;
|
|
45
|
+
color = cssColorKeyword(str);
|
|
46
|
+
if (color != null)
|
|
47
|
+
return color;
|
|
48
|
+
color = parseCssCommaColorFunction(str);
|
|
49
|
+
if (color != null)
|
|
50
|
+
return color;
|
|
51
|
+
color = parseCssSpaceColorFunction(str);
|
|
52
|
+
if (color != null)
|
|
53
|
+
return color;
|
|
54
|
+
color = parseCssColorFunction(str);
|
|
55
|
+
if (color != null)
|
|
56
|
+
return color;
|
|
57
|
+
}
|
|
58
|
+
function parseHexColor(str) {
|
|
59
|
+
const [, body] = str.match(/^#?([\da-f]+)$/i) || [];
|
|
60
|
+
if (!body)
|
|
61
|
+
return;
|
|
62
|
+
switch (body.length) {
|
|
63
|
+
case 3:
|
|
64
|
+
case 4:
|
|
65
|
+
const digits = Array.from(body, (s) => Number.parseInt(s, 16)).map((n) => n << 4 | n);
|
|
66
|
+
return {
|
|
67
|
+
type: "rgb",
|
|
68
|
+
components: digits.slice(0, 3),
|
|
69
|
+
alpha: body.length === 3 ? void 0 : Math.round(digits[3] / 255 * 100) / 100
|
|
70
|
+
};
|
|
71
|
+
case 6:
|
|
72
|
+
case 8:
|
|
73
|
+
const value = Number.parseInt(body, 16);
|
|
74
|
+
return {
|
|
75
|
+
type: "rgb",
|
|
76
|
+
components: body.length === 6 ? [value >> 16 & 255, value >> 8 & 255, value & 255] : [value >> 24 & 255, value >> 16 & 255, value >> 8 & 255],
|
|
77
|
+
alpha: body.length === 6 ? void 0 : Math.round((value & 255) / 255 * 100) / 100
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function cssColorKeyword(str) {
|
|
82
|
+
const color = {
|
|
83
|
+
rebeccapurple: [102, 51, 153, 1]
|
|
84
|
+
}[str];
|
|
85
|
+
if (color != null) {
|
|
86
|
+
return {
|
|
87
|
+
type: "rgb",
|
|
88
|
+
components: color.slice(0, 3),
|
|
89
|
+
alpha: color[3]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function parseCssCommaColorFunction(color) {
|
|
94
|
+
const match = color.match(/^(rgb|rgba|hsl|hsla)\((.+)\)$/i);
|
|
95
|
+
if (!match)
|
|
96
|
+
return;
|
|
97
|
+
const [, type, componentString] = match;
|
|
98
|
+
const components = getComponents(componentString, ",", 5);
|
|
99
|
+
if (components && [3, 4].includes(components.length)) {
|
|
100
|
+
return {
|
|
101
|
+
type,
|
|
102
|
+
components: components.slice(0, 3),
|
|
103
|
+
alpha: components[3]
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const cssColorFunctionsRe = new RegExp(`^(${cssColorFunctions.join("|")})\\((.+)\\)$`, "i");
|
|
108
|
+
function parseCssSpaceColorFunction(color) {
|
|
109
|
+
const match = color.match(cssColorFunctionsRe);
|
|
110
|
+
if (!match)
|
|
111
|
+
return;
|
|
112
|
+
const [, fn, componentString] = match;
|
|
113
|
+
const parsed = parseCssSpaceColorValues(`${fn} ${componentString}`);
|
|
114
|
+
if (parsed) {
|
|
115
|
+
const { alpha, components: [type, ...components] } = parsed;
|
|
116
|
+
return {
|
|
117
|
+
type,
|
|
118
|
+
components,
|
|
119
|
+
alpha
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function parseCssColorFunction(color) {
|
|
124
|
+
const match = color.match(/^color\((.+)\)$/);
|
|
125
|
+
if (!match)
|
|
126
|
+
return;
|
|
127
|
+
const parsed = parseCssSpaceColorValues(match[1]);
|
|
128
|
+
if (parsed) {
|
|
129
|
+
const { alpha, components: [type, ...components] } = parsed;
|
|
130
|
+
return {
|
|
131
|
+
type,
|
|
132
|
+
components,
|
|
133
|
+
alpha
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function parseCssSpaceColorValues(componentString) {
|
|
138
|
+
const components = getComponents(componentString);
|
|
139
|
+
if (!components)
|
|
140
|
+
return;
|
|
141
|
+
let totalComponents = components.length;
|
|
142
|
+
if (components[totalComponents - 2] === "/") {
|
|
143
|
+
return {
|
|
144
|
+
components: components.slice(0, totalComponents - 2),
|
|
145
|
+
alpha: components[totalComponents - 1]
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (components[totalComponents - 2] != null && (components[totalComponents - 2].endsWith("/") || components[totalComponents - 1].startsWith("/"))) {
|
|
149
|
+
const removed = components.splice(totalComponents - 2);
|
|
150
|
+
components.push(removed.join(" "));
|
|
151
|
+
--totalComponents;
|
|
152
|
+
}
|
|
153
|
+
const withAlpha = getComponents(components[totalComponents - 1], "/", 3);
|
|
154
|
+
if (!withAlpha)
|
|
155
|
+
return;
|
|
156
|
+
if (withAlpha.length === 1 || withAlpha[withAlpha.length - 1] === "")
|
|
157
|
+
return { components };
|
|
158
|
+
const alpha = withAlpha.pop();
|
|
159
|
+
components[totalComponents - 1] = withAlpha.join("/");
|
|
160
|
+
return {
|
|
161
|
+
components,
|
|
162
|
+
alpha
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function getComponent(str, separator) {
|
|
166
|
+
str = str.trim();
|
|
167
|
+
if (str === "")
|
|
168
|
+
return;
|
|
169
|
+
const l = str.length;
|
|
170
|
+
let parenthesis = 0;
|
|
171
|
+
for (let i = 0; i < l; i++) {
|
|
172
|
+
switch (str[i]) {
|
|
173
|
+
case "(":
|
|
174
|
+
parenthesis++;
|
|
175
|
+
break;
|
|
176
|
+
case ")":
|
|
177
|
+
if (--parenthesis < 0)
|
|
178
|
+
return;
|
|
179
|
+
break;
|
|
180
|
+
case separator:
|
|
181
|
+
if (parenthesis === 0) {
|
|
182
|
+
const component = str.slice(0, i).trim();
|
|
183
|
+
if (component === "")
|
|
184
|
+
return;
|
|
185
|
+
return [
|
|
186
|
+
component,
|
|
187
|
+
str.slice(i + 1).trim()
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return [
|
|
193
|
+
str,
|
|
194
|
+
""
|
|
195
|
+
];
|
|
196
|
+
}
|
|
197
|
+
function getComponents(str, separator, limit) {
|
|
198
|
+
separator = separator ?? " ";
|
|
199
|
+
if (separator.length !== 1)
|
|
200
|
+
return;
|
|
201
|
+
limit = limit ?? 10;
|
|
202
|
+
const components = [];
|
|
203
|
+
let i = 0;
|
|
204
|
+
while (str !== "") {
|
|
205
|
+
if (++i > limit)
|
|
206
|
+
return;
|
|
207
|
+
const componentPair = getComponent(str, separator);
|
|
208
|
+
if (!componentPair)
|
|
209
|
+
return;
|
|
210
|
+
const [component, rest] = componentPair;
|
|
211
|
+
components.push(component);
|
|
212
|
+
str = rest;
|
|
213
|
+
}
|
|
214
|
+
if (components.length > 0)
|
|
215
|
+
return components;
|
|
216
|
+
}
|
|
2
217
|
|
|
3
218
|
const directionMap = {
|
|
4
219
|
"l": ["-left"],
|
|
@@ -139,7 +354,7 @@ const cssProps = [
|
|
|
139
354
|
"clip-path",
|
|
140
355
|
"clip"
|
|
141
356
|
];
|
|
142
|
-
const numberWithUnitRE = /^(-?[0-9.]+)(px|pt|pc|rem|em|%|vh|vw|in|cm|mm|ex|ch|vmin|vmax)?$/i;
|
|
357
|
+
const numberWithUnitRE = /^(-?[0-9.]+)(px|pt|pc|rem|em|%|vh|vw|in|cm|mm|ex|ch|vmin|vmax|rpx)?$/i;
|
|
143
358
|
const numberRE = /^(-?[0-9.]+)$/i;
|
|
144
359
|
const unitOnlyRE = /^(px)$/i;
|
|
145
360
|
function round(n) {
|
|
@@ -210,8 +425,8 @@ function bracket(str) {
|
|
|
210
425
|
}
|
|
211
426
|
}
|
|
212
427
|
function cssvar(str) {
|
|
213
|
-
if (str.
|
|
214
|
-
return `var(--${str.slice(1)})`;
|
|
428
|
+
if (str.match(/^\$\S/))
|
|
429
|
+
return `var(--${escapeSelector(str.slice(1))})`;
|
|
215
430
|
}
|
|
216
431
|
function time(str) {
|
|
217
432
|
const match = str.match(/^(-?[0-9.]+)(s|ms)?$/i);
|
|
@@ -294,7 +509,7 @@ const parseColor = (body, theme) => {
|
|
|
294
509
|
colorData = getThemeColor(theme, colors.slice(0, -1));
|
|
295
510
|
} else {
|
|
296
511
|
colorData = getThemeColor(theme, colors);
|
|
297
|
-
if (!colorData) {
|
|
512
|
+
if (!colorData && colors.length <= 2) {
|
|
298
513
|
[, no = no] = colors;
|
|
299
514
|
colorData = getThemeColor(theme, [name]);
|
|
300
515
|
}
|
|
@@ -304,48 +519,51 @@ const parseColor = (body, theme) => {
|
|
|
304
519
|
else if (no && colorData)
|
|
305
520
|
color = colorData[no];
|
|
306
521
|
}
|
|
307
|
-
const rgba = hex2rgba(color);
|
|
308
|
-
const alpha = opacity ? opacity[0] === "[" ? handler.bracket.percent(opacity) : parseFloat(opacity) / 100 : rgba?.[3];
|
|
309
|
-
const hasAlpha = alpha != null && !Number.isNaN(alpha);
|
|
310
|
-
if (rgba) {
|
|
311
|
-
if (hasAlpha) {
|
|
312
|
-
rgba[3] = typeof alpha === "string" && !alpha.includes("%") ? parseFloat(alpha) : alpha;
|
|
313
|
-
} else {
|
|
314
|
-
rgba.splice(3);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
522
|
return {
|
|
318
523
|
opacity,
|
|
319
524
|
name,
|
|
320
525
|
no,
|
|
321
526
|
color,
|
|
322
|
-
|
|
323
|
-
alpha:
|
|
527
|
+
cssColor: parseCssColor(color),
|
|
528
|
+
alpha: handler.bracket.cssvar.percent(opacity ?? "")
|
|
324
529
|
};
|
|
325
530
|
};
|
|
326
531
|
const colorResolver = (property, varName) => ([, body], { theme }) => {
|
|
327
532
|
const data = parseColor(body, theme);
|
|
328
533
|
if (!data)
|
|
329
534
|
return;
|
|
330
|
-
const { alpha,
|
|
331
|
-
if (
|
|
332
|
-
return;
|
|
333
|
-
if (rgba) {
|
|
535
|
+
const { alpha, color, cssColor } = data;
|
|
536
|
+
if (cssColor) {
|
|
334
537
|
if (alpha != null) {
|
|
335
538
|
return {
|
|
336
|
-
[property]:
|
|
539
|
+
[property]: colorToString(cssColor, alpha)
|
|
337
540
|
};
|
|
338
541
|
} else {
|
|
339
542
|
return {
|
|
340
|
-
[`--un-${varName}-opacity`]:
|
|
341
|
-
[property]:
|
|
543
|
+
[`--un-${varName}-opacity`]: cssColor.alpha ?? 1,
|
|
544
|
+
[property]: colorToString(cssColor, `var(--un-${varName}-opacity)`)
|
|
342
545
|
};
|
|
343
546
|
}
|
|
344
|
-
} else {
|
|
547
|
+
} else if (color) {
|
|
345
548
|
return {
|
|
346
|
-
[property]: color.replace("%alpha", `${alpha
|
|
549
|
+
[property]: color.replace("%alpha", `${alpha ?? 1}`)
|
|
347
550
|
};
|
|
348
551
|
}
|
|
349
552
|
};
|
|
553
|
+
const colorableShadows = (shadows, colorVar) => {
|
|
554
|
+
const colored = [];
|
|
555
|
+
shadows = toArray(shadows);
|
|
556
|
+
for (let i = 0; i < shadows.length; i++) {
|
|
557
|
+
const components = getComponents(shadows[i]);
|
|
558
|
+
if (!components)
|
|
559
|
+
return shadows;
|
|
560
|
+
const [maybeColor, ...size] = components.reverse();
|
|
561
|
+
const color = parseCssColor(maybeColor);
|
|
562
|
+
if (color == null)
|
|
563
|
+
return shadows;
|
|
564
|
+
colored.push(`${size.reverse().join(" ")} var(${colorVar}, ${colorToString(color)})`);
|
|
565
|
+
}
|
|
566
|
+
return colored;
|
|
567
|
+
};
|
|
350
568
|
|
|
351
|
-
export {
|
|
569
|
+
export { colorToString as a, cornerMap as b, colorResolver as c, directionMap as d, colorableShadows as e, directionSize as f, positionMap as g, handler as h, insetMap as i, hex2rgba as j, parseCssColor as k, getComponents as l, h as m, parseColor as p, valueHandlers as v, xyzMap as x };
|
package/dist/colors.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { c as colors } from './colors-
|
|
2
|
-
import './types-
|
|
1
|
+
export { c as colors } from './colors-db01a23e';
|
|
2
|
+
import './types-154878eb';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PresetOptions, Preset } from '@unocss/core';
|
|
2
|
-
import { T as Theme } from './types-
|
|
3
|
-
export { T as Theme, a as ThemeAnimation } from './types-
|
|
4
|
-
export { t as theme } from './default-
|
|
5
|
-
export { c as colors } from './colors-
|
|
6
|
-
export { p as parseColor } from './utilities-
|
|
2
|
+
import { T as Theme } from './types-154878eb';
|
|
3
|
+
export { T as Theme, a as ThemeAnimation } from './types-154878eb';
|
|
4
|
+
export { t as theme } from './default-c46850c2';
|
|
5
|
+
export { c as colors } from './colors-db01a23e';
|
|
6
|
+
export { p as parseColor } from './utilities-0dc6e82e';
|
|
7
7
|
|
|
8
8
|
interface PresetMiniOptions extends PresetOptions {
|
|
9
9
|
/**
|
package/dist/rules.cjs
CHANGED
|
@@ -17,7 +17,6 @@ exports.borders = _default.borders;
|
|
|
17
17
|
exports.boxShadows = _default.boxShadows;
|
|
18
18
|
exports.boxSizing = _default.boxSizing;
|
|
19
19
|
exports.breaks = _default.breaks;
|
|
20
|
-
exports.colorableShadows = _default.colorableShadows;
|
|
21
20
|
exports.contents = _default.contents;
|
|
22
21
|
exports.cssProperty = _default.cssProperty;
|
|
23
22
|
exports.cssVariables = _default.cssVariables;
|