@unocss/preset-mini 0.23.0 → 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/default2.cjs +118 -133
- package/dist/chunks/default2.mjs +120 -134
- package/dist/chunks/utilities.cjs +130 -112
- package/dist/chunks/utilities.mjs +129 -114
- package/dist/index.d.ts +1 -1
- package/dist/rules.cjs +0 -1
- package/dist/rules.d.ts +1 -2
- package/dist/rules.mjs +1 -1
- package/dist/{utilities-8c324eff.d.ts → utilities-0dc6e82e.d.ts} +5 -4
- package/dist/utils.cjs +3 -0
- package/dist/utils.d.ts +4 -2
- package/dist/utils.mjs +1 -1
- package/dist/variants.d.ts +1 -1
- package/package.json +5 -5
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const core = require('@unocss/core');
|
|
4
4
|
|
|
5
|
+
const cssColorFunctions = ["hsl", "hsla", "hwb", "lab", "lch", "oklab", "oklch", "rgb", "rgba"];
|
|
5
6
|
function hex2rgba(hex = "") {
|
|
6
7
|
const color = parseHexColor(hex);
|
|
7
8
|
if (color != null) {
|
|
@@ -11,41 +12,32 @@ function hex2rgba(hex = "") {
|
|
|
11
12
|
return [...components, alpha];
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
|
-
function parseHexColor(str) {
|
|
15
|
-
const [, body] = str.match(/^#?([\da-f]+)$/i) || [];
|
|
16
|
-
if (!body)
|
|
17
|
-
return;
|
|
18
|
-
switch (body.length) {
|
|
19
|
-
case 3:
|
|
20
|
-
case 4:
|
|
21
|
-
const digits = Array.from(body, (s) => Number.parseInt(s, 16)).map((n) => n << 4 | n);
|
|
22
|
-
return {
|
|
23
|
-
type: "rgb",
|
|
24
|
-
components: digits.slice(0, 3),
|
|
25
|
-
alpha: body.length === 3 ? void 0 : Math.round(digits[3] / 255 * 100) / 100
|
|
26
|
-
};
|
|
27
|
-
case 6:
|
|
28
|
-
case 8:
|
|
29
|
-
const value = Number.parseInt(body, 16);
|
|
30
|
-
return {
|
|
31
|
-
type: "rgb",
|
|
32
|
-
components: body.length === 6 ? [value >> 16 & 255, value >> 8 & 255, value & 255] : [value >> 24 & 255, value >> 16 & 255, value >> 8 & 255],
|
|
33
|
-
alpha: body.length === 6 ? void 0 : Math.round((value & 255) / 255 * 100) / 100
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
15
|
function parseCssColor(str = "") {
|
|
38
16
|
const color = parseColor$1(str);
|
|
39
17
|
if (color == null)
|
|
40
18
|
return;
|
|
41
19
|
const { type: casedType, components, alpha } = color;
|
|
42
20
|
const type = casedType.toLowerCase();
|
|
21
|
+
if (components.length === 0)
|
|
22
|
+
return;
|
|
43
23
|
if (["rgba", "hsla"].includes(type) && alpha === void 0)
|
|
44
24
|
return;
|
|
45
|
-
if (
|
|
25
|
+
if (cssColorFunctions.includes(type) && components.length !== 3)
|
|
46
26
|
return;
|
|
47
27
|
return { type, components, alpha };
|
|
48
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
|
+
}
|
|
49
41
|
function parseColor$1(str) {
|
|
50
42
|
if (!str)
|
|
51
43
|
return;
|
|
@@ -65,10 +57,32 @@ function parseColor$1(str) {
|
|
|
65
57
|
if (color != null)
|
|
66
58
|
return color;
|
|
67
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
|
+
}
|
|
68
83
|
function cssColorKeyword(str) {
|
|
69
84
|
const color = {
|
|
70
|
-
rebeccapurple: [102, 51, 153, 1]
|
|
71
|
-
transparent: [0, 0, 0, 0]
|
|
85
|
+
rebeccapurple: [102, 51, 153, 1]
|
|
72
86
|
}[str];
|
|
73
87
|
if (color != null) {
|
|
74
88
|
return {
|
|
@@ -78,54 +92,13 @@ function cssColorKeyword(str) {
|
|
|
78
92
|
};
|
|
79
93
|
}
|
|
80
94
|
}
|
|
81
|
-
function getComponent(separator, str) {
|
|
82
|
-
const component = str.trim();
|
|
83
|
-
if (component === "")
|
|
84
|
-
return;
|
|
85
|
-
const l = str.length;
|
|
86
|
-
let parenthesis = 0;
|
|
87
|
-
for (let i = 0; i < l; i++) {
|
|
88
|
-
switch (str[i]) {
|
|
89
|
-
case "(":
|
|
90
|
-
parenthesis++;
|
|
91
|
-
break;
|
|
92
|
-
case ")":
|
|
93
|
-
if (--parenthesis < 0)
|
|
94
|
-
return;
|
|
95
|
-
break;
|
|
96
|
-
case separator:
|
|
97
|
-
if (parenthesis === 0) {
|
|
98
|
-
const component2 = str.slice(0, i).trim();
|
|
99
|
-
if (component2 === "")
|
|
100
|
-
return;
|
|
101
|
-
return [
|
|
102
|
-
str.slice(0, i).trim(),
|
|
103
|
-
str.slice(i + 1).trim()
|
|
104
|
-
];
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return [
|
|
109
|
-
str.trim(),
|
|
110
|
-
""
|
|
111
|
-
];
|
|
112
|
-
}
|
|
113
95
|
function parseCssCommaColorFunction(color) {
|
|
114
96
|
const match = color.match(/^(rgb|rgba|hsl|hsla)\((.+)\)$/i);
|
|
115
97
|
if (!match)
|
|
116
98
|
return;
|
|
117
99
|
const [, type, componentString] = match;
|
|
118
|
-
const components =
|
|
119
|
-
|
|
120
|
-
for (let c = 5; c > 0 && cs !== ""; --c) {
|
|
121
|
-
const componentValue = getComponent(",", cs);
|
|
122
|
-
if (!componentValue)
|
|
123
|
-
return;
|
|
124
|
-
const [component, rest] = componentValue;
|
|
125
|
-
components.push(component);
|
|
126
|
-
cs = rest;
|
|
127
|
-
}
|
|
128
|
-
if ([3, 4].includes(components.length)) {
|
|
100
|
+
const components = getComponents(componentString, ",", 5);
|
|
101
|
+
if (components && [3, 4].includes(components.length)) {
|
|
129
102
|
return {
|
|
130
103
|
type,
|
|
131
104
|
components: components.slice(0, 3),
|
|
@@ -133,8 +106,9 @@ function parseCssCommaColorFunction(color) {
|
|
|
133
106
|
};
|
|
134
107
|
}
|
|
135
108
|
}
|
|
109
|
+
const cssColorFunctionsRe = new RegExp(`^(${cssColorFunctions.join("|")})\\((.+)\\)$`, "i");
|
|
136
110
|
function parseCssSpaceColorFunction(color) {
|
|
137
|
-
const match = color.match(
|
|
111
|
+
const match = color.match(cssColorFunctionsRe);
|
|
138
112
|
if (!match)
|
|
139
113
|
return;
|
|
140
114
|
const [, fn, componentString] = match;
|
|
@@ -163,16 +137,9 @@ function parseCssColorFunction(color) {
|
|
|
163
137
|
}
|
|
164
138
|
}
|
|
165
139
|
function parseCssSpaceColorValues(componentString) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const cc = getComponent(" ", cs);
|
|
170
|
-
if (!cc)
|
|
171
|
-
return;
|
|
172
|
-
const [component, rest] = cc;
|
|
173
|
-
components.push(component);
|
|
174
|
-
cs = rest;
|
|
175
|
-
}
|
|
140
|
+
const components = getComponents(componentString);
|
|
141
|
+
if (!components)
|
|
142
|
+
return;
|
|
176
143
|
let totalComponents = components.length;
|
|
177
144
|
if (components[totalComponents - 2] === "/") {
|
|
178
145
|
return {
|
|
@@ -180,21 +147,14 @@ function parseCssSpaceColorValues(componentString) {
|
|
|
180
147
|
alpha: components[totalComponents - 1]
|
|
181
148
|
};
|
|
182
149
|
}
|
|
183
|
-
if (components[totalComponents - 2].endsWith("/") || components[totalComponents - 1].startsWith("/")) {
|
|
150
|
+
if (components[totalComponents - 2] != null && (components[totalComponents - 2].endsWith("/") || components[totalComponents - 1].startsWith("/"))) {
|
|
184
151
|
const removed = components.splice(totalComponents - 2);
|
|
185
152
|
components.push(removed.join(" "));
|
|
186
153
|
--totalComponents;
|
|
187
154
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const cc = getComponent("/", cs);
|
|
192
|
-
if (!cc)
|
|
193
|
-
return;
|
|
194
|
-
const [component, rest] = cc;
|
|
195
|
-
withAlpha.push(component);
|
|
196
|
-
cs = rest;
|
|
197
|
-
}
|
|
155
|
+
const withAlpha = getComponents(components[totalComponents - 1], "/", 3);
|
|
156
|
+
if (!withAlpha)
|
|
157
|
+
return;
|
|
198
158
|
if (withAlpha.length === 1 || withAlpha[withAlpha.length - 1] === "")
|
|
199
159
|
return { components };
|
|
200
160
|
const alpha = withAlpha.pop();
|
|
@@ -204,6 +164,58 @@ function parseCssSpaceColorValues(componentString) {
|
|
|
204
164
|
alpha
|
|
205
165
|
};
|
|
206
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
|
+
}
|
|
207
219
|
|
|
208
220
|
const directionMap = {
|
|
209
221
|
"l": ["-left"],
|
|
@@ -509,54 +521,60 @@ const parseColor = (body, theme) => {
|
|
|
509
521
|
else if (no && colorData)
|
|
510
522
|
color = colorData[no];
|
|
511
523
|
}
|
|
512
|
-
const rgba = hex2rgba(color);
|
|
513
|
-
const alpha = opacity ? opacity[0] === "[" ? handler.bracket.percent(opacity) : parseFloat(opacity) / 100 : rgba?.[3];
|
|
514
|
-
const hasAlpha = alpha != null && !Number.isNaN(alpha);
|
|
515
|
-
if (rgba) {
|
|
516
|
-
if (hasAlpha) {
|
|
517
|
-
rgba[3] = typeof alpha === "string" && !alpha.includes("%") ? parseFloat(alpha) : alpha;
|
|
518
|
-
} else {
|
|
519
|
-
rgba.splice(3);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
524
|
return {
|
|
523
525
|
opacity,
|
|
524
526
|
name,
|
|
525
527
|
no,
|
|
526
528
|
color,
|
|
527
|
-
|
|
528
|
-
alpha:
|
|
529
|
+
cssColor: parseCssColor(color),
|
|
530
|
+
alpha: handler.bracket.cssvar.percent(opacity ?? "")
|
|
529
531
|
};
|
|
530
532
|
};
|
|
531
533
|
const colorResolver = (property, varName) => ([, body], { theme }) => {
|
|
532
534
|
const data = parseColor(body, theme);
|
|
533
535
|
if (!data)
|
|
534
536
|
return;
|
|
535
|
-
const { alpha,
|
|
536
|
-
if (
|
|
537
|
-
return;
|
|
538
|
-
if (rgba) {
|
|
537
|
+
const { alpha, color, cssColor } = data;
|
|
538
|
+
if (cssColor) {
|
|
539
539
|
if (alpha != null) {
|
|
540
540
|
return {
|
|
541
|
-
[property]:
|
|
541
|
+
[property]: colorToString(cssColor, alpha)
|
|
542
542
|
};
|
|
543
543
|
} else {
|
|
544
544
|
return {
|
|
545
|
-
[`--un-${varName}-opacity`]:
|
|
546
|
-
[property]:
|
|
545
|
+
[`--un-${varName}-opacity`]: cssColor.alpha ?? 1,
|
|
546
|
+
[property]: colorToString(cssColor, `var(--un-${varName}-opacity)`)
|
|
547
547
|
};
|
|
548
548
|
}
|
|
549
|
-
} else {
|
|
549
|
+
} else if (color) {
|
|
550
550
|
return {
|
|
551
|
-
[property]: color.replace("%alpha", `${alpha
|
|
551
|
+
[property]: color.replace("%alpha", `${alpha ?? 1}`)
|
|
552
552
|
};
|
|
553
553
|
}
|
|
554
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
|
+
};
|
|
555
570
|
|
|
556
571
|
exports.colorResolver = colorResolver;
|
|
572
|
+
exports.colorToString = colorToString;
|
|
573
|
+
exports.colorableShadows = colorableShadows;
|
|
557
574
|
exports.cornerMap = cornerMap;
|
|
558
575
|
exports.directionMap = directionMap;
|
|
559
576
|
exports.directionSize = directionSize;
|
|
577
|
+
exports.getComponents = getComponents;
|
|
560
578
|
exports.h = h;
|
|
561
579
|
exports.handler = handler;
|
|
562
580
|
exports.hex2rgba = hex2rgba;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { escapeSelector, createValueHandler } from '@unocss/core';
|
|
1
|
+
import { escapeSelector, createValueHandler, toArray } from '@unocss/core';
|
|
2
2
|
|
|
3
|
+
const cssColorFunctions = ["hsl", "hsla", "hwb", "lab", "lch", "oklab", "oklch", "rgb", "rgba"];
|
|
3
4
|
function hex2rgba(hex = "") {
|
|
4
5
|
const color = parseHexColor(hex);
|
|
5
6
|
if (color != null) {
|
|
@@ -9,41 +10,32 @@ function hex2rgba(hex = "") {
|
|
|
9
10
|
return [...components, alpha];
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
|
-
function parseHexColor(str) {
|
|
13
|
-
const [, body] = str.match(/^#?([\da-f]+)$/i) || [];
|
|
14
|
-
if (!body)
|
|
15
|
-
return;
|
|
16
|
-
switch (body.length) {
|
|
17
|
-
case 3:
|
|
18
|
-
case 4:
|
|
19
|
-
const digits = Array.from(body, (s) => Number.parseInt(s, 16)).map((n) => n << 4 | n);
|
|
20
|
-
return {
|
|
21
|
-
type: "rgb",
|
|
22
|
-
components: digits.slice(0, 3),
|
|
23
|
-
alpha: body.length === 3 ? void 0 : Math.round(digits[3] / 255 * 100) / 100
|
|
24
|
-
};
|
|
25
|
-
case 6:
|
|
26
|
-
case 8:
|
|
27
|
-
const value = Number.parseInt(body, 16);
|
|
28
|
-
return {
|
|
29
|
-
type: "rgb",
|
|
30
|
-
components: body.length === 6 ? [value >> 16 & 255, value >> 8 & 255, value & 255] : [value >> 24 & 255, value >> 16 & 255, value >> 8 & 255],
|
|
31
|
-
alpha: body.length === 6 ? void 0 : Math.round((value & 255) / 255 * 100) / 100
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
13
|
function parseCssColor(str = "") {
|
|
36
14
|
const color = parseColor$1(str);
|
|
37
15
|
if (color == null)
|
|
38
16
|
return;
|
|
39
17
|
const { type: casedType, components, alpha } = color;
|
|
40
18
|
const type = casedType.toLowerCase();
|
|
19
|
+
if (components.length === 0)
|
|
20
|
+
return;
|
|
41
21
|
if (["rgba", "hsla"].includes(type) && alpha === void 0)
|
|
42
22
|
return;
|
|
43
|
-
if (
|
|
23
|
+
if (cssColorFunctions.includes(type) && components.length !== 3)
|
|
44
24
|
return;
|
|
45
25
|
return { type, components, alpha };
|
|
46
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
|
+
}
|
|
47
39
|
function parseColor$1(str) {
|
|
48
40
|
if (!str)
|
|
49
41
|
return;
|
|
@@ -63,10 +55,32 @@ function parseColor$1(str) {
|
|
|
63
55
|
if (color != null)
|
|
64
56
|
return color;
|
|
65
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
|
+
}
|
|
66
81
|
function cssColorKeyword(str) {
|
|
67
82
|
const color = {
|
|
68
|
-
rebeccapurple: [102, 51, 153, 1]
|
|
69
|
-
transparent: [0, 0, 0, 0]
|
|
83
|
+
rebeccapurple: [102, 51, 153, 1]
|
|
70
84
|
}[str];
|
|
71
85
|
if (color != null) {
|
|
72
86
|
return {
|
|
@@ -76,54 +90,13 @@ function cssColorKeyword(str) {
|
|
|
76
90
|
};
|
|
77
91
|
}
|
|
78
92
|
}
|
|
79
|
-
function getComponent(separator, str) {
|
|
80
|
-
const component = str.trim();
|
|
81
|
-
if (component === "")
|
|
82
|
-
return;
|
|
83
|
-
const l = str.length;
|
|
84
|
-
let parenthesis = 0;
|
|
85
|
-
for (let i = 0; i < l; i++) {
|
|
86
|
-
switch (str[i]) {
|
|
87
|
-
case "(":
|
|
88
|
-
parenthesis++;
|
|
89
|
-
break;
|
|
90
|
-
case ")":
|
|
91
|
-
if (--parenthesis < 0)
|
|
92
|
-
return;
|
|
93
|
-
break;
|
|
94
|
-
case separator:
|
|
95
|
-
if (parenthesis === 0) {
|
|
96
|
-
const component2 = str.slice(0, i).trim();
|
|
97
|
-
if (component2 === "")
|
|
98
|
-
return;
|
|
99
|
-
return [
|
|
100
|
-
str.slice(0, i).trim(),
|
|
101
|
-
str.slice(i + 1).trim()
|
|
102
|
-
];
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return [
|
|
107
|
-
str.trim(),
|
|
108
|
-
""
|
|
109
|
-
];
|
|
110
|
-
}
|
|
111
93
|
function parseCssCommaColorFunction(color) {
|
|
112
94
|
const match = color.match(/^(rgb|rgba|hsl|hsla)\((.+)\)$/i);
|
|
113
95
|
if (!match)
|
|
114
96
|
return;
|
|
115
97
|
const [, type, componentString] = match;
|
|
116
|
-
const components =
|
|
117
|
-
|
|
118
|
-
for (let c = 5; c > 0 && cs !== ""; --c) {
|
|
119
|
-
const componentValue = getComponent(",", cs);
|
|
120
|
-
if (!componentValue)
|
|
121
|
-
return;
|
|
122
|
-
const [component, rest] = componentValue;
|
|
123
|
-
components.push(component);
|
|
124
|
-
cs = rest;
|
|
125
|
-
}
|
|
126
|
-
if ([3, 4].includes(components.length)) {
|
|
98
|
+
const components = getComponents(componentString, ",", 5);
|
|
99
|
+
if (components && [3, 4].includes(components.length)) {
|
|
127
100
|
return {
|
|
128
101
|
type,
|
|
129
102
|
components: components.slice(0, 3),
|
|
@@ -131,8 +104,9 @@ function parseCssCommaColorFunction(color) {
|
|
|
131
104
|
};
|
|
132
105
|
}
|
|
133
106
|
}
|
|
107
|
+
const cssColorFunctionsRe = new RegExp(`^(${cssColorFunctions.join("|")})\\((.+)\\)$`, "i");
|
|
134
108
|
function parseCssSpaceColorFunction(color) {
|
|
135
|
-
const match = color.match(
|
|
109
|
+
const match = color.match(cssColorFunctionsRe);
|
|
136
110
|
if (!match)
|
|
137
111
|
return;
|
|
138
112
|
const [, fn, componentString] = match;
|
|
@@ -161,16 +135,9 @@ function parseCssColorFunction(color) {
|
|
|
161
135
|
}
|
|
162
136
|
}
|
|
163
137
|
function parseCssSpaceColorValues(componentString) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const cc = getComponent(" ", cs);
|
|
168
|
-
if (!cc)
|
|
169
|
-
return;
|
|
170
|
-
const [component, rest] = cc;
|
|
171
|
-
components.push(component);
|
|
172
|
-
cs = rest;
|
|
173
|
-
}
|
|
138
|
+
const components = getComponents(componentString);
|
|
139
|
+
if (!components)
|
|
140
|
+
return;
|
|
174
141
|
let totalComponents = components.length;
|
|
175
142
|
if (components[totalComponents - 2] === "/") {
|
|
176
143
|
return {
|
|
@@ -178,21 +145,14 @@ function parseCssSpaceColorValues(componentString) {
|
|
|
178
145
|
alpha: components[totalComponents - 1]
|
|
179
146
|
};
|
|
180
147
|
}
|
|
181
|
-
if (components[totalComponents - 2].endsWith("/") || components[totalComponents - 1].startsWith("/")) {
|
|
148
|
+
if (components[totalComponents - 2] != null && (components[totalComponents - 2].endsWith("/") || components[totalComponents - 1].startsWith("/"))) {
|
|
182
149
|
const removed = components.splice(totalComponents - 2);
|
|
183
150
|
components.push(removed.join(" "));
|
|
184
151
|
--totalComponents;
|
|
185
152
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const cc = getComponent("/", cs);
|
|
190
|
-
if (!cc)
|
|
191
|
-
return;
|
|
192
|
-
const [component, rest] = cc;
|
|
193
|
-
withAlpha.push(component);
|
|
194
|
-
cs = rest;
|
|
195
|
-
}
|
|
153
|
+
const withAlpha = getComponents(components[totalComponents - 1], "/", 3);
|
|
154
|
+
if (!withAlpha)
|
|
155
|
+
return;
|
|
196
156
|
if (withAlpha.length === 1 || withAlpha[withAlpha.length - 1] === "")
|
|
197
157
|
return { components };
|
|
198
158
|
const alpha = withAlpha.pop();
|
|
@@ -202,6 +162,58 @@ function parseCssSpaceColorValues(componentString) {
|
|
|
202
162
|
alpha
|
|
203
163
|
};
|
|
204
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
|
+
}
|
|
205
217
|
|
|
206
218
|
const directionMap = {
|
|
207
219
|
"l": ["-left"],
|
|
@@ -507,48 +519,51 @@ const parseColor = (body, theme) => {
|
|
|
507
519
|
else if (no && colorData)
|
|
508
520
|
color = colorData[no];
|
|
509
521
|
}
|
|
510
|
-
const rgba = hex2rgba(color);
|
|
511
|
-
const alpha = opacity ? opacity[0] === "[" ? handler.bracket.percent(opacity) : parseFloat(opacity) / 100 : rgba?.[3];
|
|
512
|
-
const hasAlpha = alpha != null && !Number.isNaN(alpha);
|
|
513
|
-
if (rgba) {
|
|
514
|
-
if (hasAlpha) {
|
|
515
|
-
rgba[3] = typeof alpha === "string" && !alpha.includes("%") ? parseFloat(alpha) : alpha;
|
|
516
|
-
} else {
|
|
517
|
-
rgba.splice(3);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
522
|
return {
|
|
521
523
|
opacity,
|
|
522
524
|
name,
|
|
523
525
|
no,
|
|
524
526
|
color,
|
|
525
|
-
|
|
526
|
-
alpha:
|
|
527
|
+
cssColor: parseCssColor(color),
|
|
528
|
+
alpha: handler.bracket.cssvar.percent(opacity ?? "")
|
|
527
529
|
};
|
|
528
530
|
};
|
|
529
531
|
const colorResolver = (property, varName) => ([, body], { theme }) => {
|
|
530
532
|
const data = parseColor(body, theme);
|
|
531
533
|
if (!data)
|
|
532
534
|
return;
|
|
533
|
-
const { alpha,
|
|
534
|
-
if (
|
|
535
|
-
return;
|
|
536
|
-
if (rgba) {
|
|
535
|
+
const { alpha, color, cssColor } = data;
|
|
536
|
+
if (cssColor) {
|
|
537
537
|
if (alpha != null) {
|
|
538
538
|
return {
|
|
539
|
-
[property]:
|
|
539
|
+
[property]: colorToString(cssColor, alpha)
|
|
540
540
|
};
|
|
541
541
|
} else {
|
|
542
542
|
return {
|
|
543
|
-
[`--un-${varName}-opacity`]:
|
|
544
|
-
[property]:
|
|
543
|
+
[`--un-${varName}-opacity`]: cssColor.alpha ?? 1,
|
|
544
|
+
[property]: colorToString(cssColor, `var(--un-${varName}-opacity)`)
|
|
545
545
|
};
|
|
546
546
|
}
|
|
547
|
-
} else {
|
|
547
|
+
} else if (color) {
|
|
548
548
|
return {
|
|
549
|
-
[property]: color.replace("%alpha", `${alpha
|
|
549
|
+
[property]: color.replace("%alpha", `${alpha ?? 1}`)
|
|
550
550
|
};
|
|
551
551
|
}
|
|
552
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
|
+
};
|
|
553
568
|
|
|
554
|
-
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/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { T as Theme } from './types-154878eb';
|
|
|
3
3
|
export { T as Theme, a as ThemeAnimation } from './types-154878eb';
|
|
4
4
|
export { t as theme } from './default-c46850c2';
|
|
5
5
|
export { c as colors } from './colors-db01a23e';
|
|
6
|
-
export { p as parseColor } from './utilities-
|
|
6
|
+
export { p as parseColor } from './utilities-0dc6e82e';
|
|
7
7
|
|
|
8
8
|
interface PresetMiniOptions extends PresetOptions {
|
|
9
9
|
/**
|