@unocss/preset-mini 0.15.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/LICENSE +21 -0
- package/README.md +23 -0
- package/colors.d.ts +1 -0
- package/dist/chunks/colors.cjs +339 -0
- package/dist/chunks/colors.mjs +337 -0
- package/dist/chunks/default.cjs +226 -0
- package/dist/chunks/default.mjs +206 -0
- package/dist/chunks/default2.cjs +1077 -0
- package/dist/chunks/default2.mjs +997 -0
- package/dist/chunks/default3.cjs +128 -0
- package/dist/chunks/default3.mjs +119 -0
- package/dist/chunks/index.cjs +169 -0
- package/dist/chunks/index.mjs +153 -0
- package/dist/chunks/pseudo.cjs +106 -0
- package/dist/chunks/pseudo.mjs +101 -0
- package/dist/chunks/variants.cjs +14 -0
- package/dist/chunks/variants.mjs +12 -0
- package/dist/colors-d6b5a5b4.d.ts +5 -0
- package/dist/colors.cjs +9 -0
- package/dist/colors.d.ts +2 -0
- package/dist/colors.mjs +1 -0
- package/dist/default-c7c67d23.d.ts +5 -0
- package/dist/index.cjs +28 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.mjs +22 -0
- package/dist/rules.cjs +90 -0
- package/dist/rules.d.ts +122 -0
- package/dist/rules.mjs +4 -0
- package/dist/theme.cjs +29 -0
- package/dist/theme.d.ts +157 -0
- package/dist/theme.mjs +2 -0
- package/dist/types-7963d0b3.d.ts +24 -0
- package/dist/utils.cjs +25 -0
- package/dist/utils.d.ts +56 -0
- package/dist/utils.mjs +2 -0
- package/dist/variants.cjs +23 -0
- package/dist/variants.d.ts +22 -0
- package/dist/variants.mjs +4 -0
- package/package.json +70 -0
- package/rules.d.ts +1 -0
- package/theme.d.ts +1 -0
- package/utils.d.ts +1 -0
- package/variants.d.ts +1 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const variants$1 = require('./variants.cjs');
|
|
4
|
+
const pseudo = require('./pseudo.cjs');
|
|
5
|
+
|
|
6
|
+
const regexCache = {};
|
|
7
|
+
const variantBreakpoints = (matcher, _, theme) => {
|
|
8
|
+
const variantEntries = Object.entries(theme.breakpoints || {}).map(([point, size], idx) => [point, size, idx]);
|
|
9
|
+
for (const [point, size, idx] of variantEntries) {
|
|
10
|
+
if (!regexCache[point])
|
|
11
|
+
regexCache[point] = new RegExp(`^((?:[a|l]t-)?${point}[:-])`);
|
|
12
|
+
const match = matcher.match(regexCache[point]);
|
|
13
|
+
if (!match)
|
|
14
|
+
continue;
|
|
15
|
+
const [, pre] = match;
|
|
16
|
+
let direction = "min";
|
|
17
|
+
let order = parseInt(size);
|
|
18
|
+
if (pre.startsWith("lt-")) {
|
|
19
|
+
direction = "max";
|
|
20
|
+
order = -order;
|
|
21
|
+
}
|
|
22
|
+
const m = matcher.slice(pre.length);
|
|
23
|
+
if (m === "container")
|
|
24
|
+
continue;
|
|
25
|
+
if (pre.startsWith("at-") && idx < variantEntries.length - 1) {
|
|
26
|
+
return {
|
|
27
|
+
matcher: m,
|
|
28
|
+
parent: [`@media (min-width: ${size}) and (max-width: ${variantEntries[idx + 1][1]})`, order]
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
matcher: m,
|
|
33
|
+
parent: [`@media (${direction}-width: ${size})`, order]
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const variantChildren = [
|
|
39
|
+
variants$1.variantMatcher("children", (input) => `${input} > *`),
|
|
40
|
+
variants$1.variantMatcher("all", (input) => `${input} *`),
|
|
41
|
+
variants$1.variantMatcher("next", (input) => `${input}+*`)
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const variantColorsClass = [
|
|
45
|
+
variants$1.variantMatcher("dark", (input) => `.dark $$ ${input}`),
|
|
46
|
+
variants$1.variantMatcher("light", (input) => `.light $$ ${input}`)
|
|
47
|
+
];
|
|
48
|
+
const variantColorsMedia = [
|
|
49
|
+
(v) => {
|
|
50
|
+
const dark = variants$1.variantMatcher("dark")(v);
|
|
51
|
+
if (dark) {
|
|
52
|
+
return {
|
|
53
|
+
...dark,
|
|
54
|
+
parent: "@media (prefers-color-scheme: dark)"
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const light = variants$1.variantMatcher("light")(v);
|
|
58
|
+
if (light) {
|
|
59
|
+
return {
|
|
60
|
+
...light,
|
|
61
|
+
parent: "@media (prefers-color-scheme: light)"
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
const variantImportant = {
|
|
68
|
+
match(matcher) {
|
|
69
|
+
if (matcher.startsWith("!")) {
|
|
70
|
+
return {
|
|
71
|
+
matcher: matcher.slice(1),
|
|
72
|
+
body: (body) => {
|
|
73
|
+
body.forEach((v) => {
|
|
74
|
+
if (v[1])
|
|
75
|
+
v[1] += " !important";
|
|
76
|
+
});
|
|
77
|
+
return body;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const variantNegative = {
|
|
84
|
+
match(matcher) {
|
|
85
|
+
if (matcher.startsWith("-")) {
|
|
86
|
+
return {
|
|
87
|
+
matcher: matcher.slice(1),
|
|
88
|
+
body: (body) => {
|
|
89
|
+
body.forEach((v) => {
|
|
90
|
+
if (v[0].startsWith("--un-scale") || v[1]?.toString() === "0")
|
|
91
|
+
return;
|
|
92
|
+
v[1] = v[1]?.toString().replace(/[0-9.]+(?:[a-z]+|%)?/, (i) => `-${i}`);
|
|
93
|
+
});
|
|
94
|
+
return body;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const variantSpace = (matcher) => {
|
|
101
|
+
if (/^space-?([xy])-?(-?.+)$/.test(matcher) || /^divide-/.test(matcher)) {
|
|
102
|
+
return {
|
|
103
|
+
matcher,
|
|
104
|
+
selector: (input) => {
|
|
105
|
+
return `${input}>:not([hidden])~:not([hidden])`;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const variants = [
|
|
112
|
+
variantSpace,
|
|
113
|
+
variantNegative,
|
|
114
|
+
variantImportant,
|
|
115
|
+
variantBreakpoints,
|
|
116
|
+
...variantChildren,
|
|
117
|
+
pseudo.variantPseudoClasses,
|
|
118
|
+
pseudo.variantPseudoElements
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
exports.variantBreakpoints = variantBreakpoints;
|
|
122
|
+
exports.variantChildren = variantChildren;
|
|
123
|
+
exports.variantColorsClass = variantColorsClass;
|
|
124
|
+
exports.variantColorsMedia = variantColorsMedia;
|
|
125
|
+
exports.variantImportant = variantImportant;
|
|
126
|
+
exports.variantNegative = variantNegative;
|
|
127
|
+
exports.variantSpace = variantSpace;
|
|
128
|
+
exports.variants = variants;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { v as variantMatcher } from './variants.mjs';
|
|
2
|
+
import { v as variantPseudoClasses, a as variantPseudoElements } from './pseudo.mjs';
|
|
3
|
+
|
|
4
|
+
const regexCache = {};
|
|
5
|
+
const variantBreakpoints = (matcher, _, theme) => {
|
|
6
|
+
const variantEntries = Object.entries(theme.breakpoints || {}).map(([point, size], idx) => [point, size, idx]);
|
|
7
|
+
for (const [point, size, idx] of variantEntries) {
|
|
8
|
+
if (!regexCache[point])
|
|
9
|
+
regexCache[point] = new RegExp(`^((?:[a|l]t-)?${point}[:-])`);
|
|
10
|
+
const match = matcher.match(regexCache[point]);
|
|
11
|
+
if (!match)
|
|
12
|
+
continue;
|
|
13
|
+
const [, pre] = match;
|
|
14
|
+
let direction = "min";
|
|
15
|
+
let order = parseInt(size);
|
|
16
|
+
if (pre.startsWith("lt-")) {
|
|
17
|
+
direction = "max";
|
|
18
|
+
order = -order;
|
|
19
|
+
}
|
|
20
|
+
const m = matcher.slice(pre.length);
|
|
21
|
+
if (m === "container")
|
|
22
|
+
continue;
|
|
23
|
+
if (pre.startsWith("at-") && idx < variantEntries.length - 1) {
|
|
24
|
+
return {
|
|
25
|
+
matcher: m,
|
|
26
|
+
parent: [`@media (min-width: ${size}) and (max-width: ${variantEntries[idx + 1][1]})`, order]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
matcher: m,
|
|
31
|
+
parent: [`@media (${direction}-width: ${size})`, order]
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const variantChildren = [
|
|
37
|
+
variantMatcher("children", (input) => `${input} > *`),
|
|
38
|
+
variantMatcher("all", (input) => `${input} *`),
|
|
39
|
+
variantMatcher("next", (input) => `${input}+*`)
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
const variantColorsClass = [
|
|
43
|
+
variantMatcher("dark", (input) => `.dark $$ ${input}`),
|
|
44
|
+
variantMatcher("light", (input) => `.light $$ ${input}`)
|
|
45
|
+
];
|
|
46
|
+
const variantColorsMedia = [
|
|
47
|
+
(v) => {
|
|
48
|
+
const dark = variantMatcher("dark")(v);
|
|
49
|
+
if (dark) {
|
|
50
|
+
return {
|
|
51
|
+
...dark,
|
|
52
|
+
parent: "@media (prefers-color-scheme: dark)"
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const light = variantMatcher("light")(v);
|
|
56
|
+
if (light) {
|
|
57
|
+
return {
|
|
58
|
+
...light,
|
|
59
|
+
parent: "@media (prefers-color-scheme: light)"
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
const variantImportant = {
|
|
66
|
+
match(matcher) {
|
|
67
|
+
if (matcher.startsWith("!")) {
|
|
68
|
+
return {
|
|
69
|
+
matcher: matcher.slice(1),
|
|
70
|
+
body: (body) => {
|
|
71
|
+
body.forEach((v) => {
|
|
72
|
+
if (v[1])
|
|
73
|
+
v[1] += " !important";
|
|
74
|
+
});
|
|
75
|
+
return body;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const variantNegative = {
|
|
82
|
+
match(matcher) {
|
|
83
|
+
if (matcher.startsWith("-")) {
|
|
84
|
+
return {
|
|
85
|
+
matcher: matcher.slice(1),
|
|
86
|
+
body: (body) => {
|
|
87
|
+
body.forEach((v) => {
|
|
88
|
+
if (v[0].startsWith("--un-scale") || v[1]?.toString() === "0")
|
|
89
|
+
return;
|
|
90
|
+
v[1] = v[1]?.toString().replace(/[0-9.]+(?:[a-z]+|%)?/, (i) => `-${i}`);
|
|
91
|
+
});
|
|
92
|
+
return body;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const variantSpace = (matcher) => {
|
|
99
|
+
if (/^space-?([xy])-?(-?.+)$/.test(matcher) || /^divide-/.test(matcher)) {
|
|
100
|
+
return {
|
|
101
|
+
matcher,
|
|
102
|
+
selector: (input) => {
|
|
103
|
+
return `${input}>:not([hidden])~:not([hidden])`;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const variants = [
|
|
110
|
+
variantSpace,
|
|
111
|
+
variantNegative,
|
|
112
|
+
variantImportant,
|
|
113
|
+
variantBreakpoints,
|
|
114
|
+
...variantChildren,
|
|
115
|
+
variantPseudoClasses,
|
|
116
|
+
variantPseudoElements
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
export { variantColorsMedia as a, variantColorsClass as b, variantBreakpoints as c, variantChildren as d, variantImportant as e, variantNegative as f, variantSpace as g, variants as v };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const directionMap = {
|
|
4
|
+
"l": ["-left"],
|
|
5
|
+
"r": ["-right"],
|
|
6
|
+
"t": ["-top"],
|
|
7
|
+
"b": ["-bottom"],
|
|
8
|
+
"s": ["-inline-start"],
|
|
9
|
+
"e": ["-inline-end"],
|
|
10
|
+
"x": ["-left", "-right"],
|
|
11
|
+
"y": ["-top", "-bottom"],
|
|
12
|
+
"": [""],
|
|
13
|
+
"a": [""]
|
|
14
|
+
};
|
|
15
|
+
const cornerMap = {
|
|
16
|
+
"t": ["-top-left", "-top-right"],
|
|
17
|
+
"r": ["-top-right", "-bottom-right"],
|
|
18
|
+
"b": ["-bottom-left", "-bottom-right"],
|
|
19
|
+
"l": ["-bottom-left", "-top-left"],
|
|
20
|
+
"tl": ["-top-left"],
|
|
21
|
+
"lt": ["-top-left"],
|
|
22
|
+
"tr": ["-top-right"],
|
|
23
|
+
"rt": ["-top-right"],
|
|
24
|
+
"bl": ["-bottom-left"],
|
|
25
|
+
"lb": ["-bottom-left"],
|
|
26
|
+
"br": ["-bottom-right"],
|
|
27
|
+
"rb": ["-bottom-right"],
|
|
28
|
+
"": [""]
|
|
29
|
+
};
|
|
30
|
+
const xyzMap = {
|
|
31
|
+
"x": ["-x"],
|
|
32
|
+
"y": ["-y"],
|
|
33
|
+
"z": ["-z"],
|
|
34
|
+
"": ["-x", "-y"]
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const numberWithUnitRE = /^(-?[0-9.]+)(px|pt|pc|rem|em|%|vh|vw|in|cm|mm|ex|ch|vmin|vmax)?$/i;
|
|
38
|
+
const numberRE = /^(-?[0-9.]+)$/i;
|
|
39
|
+
function rem(str) {
|
|
40
|
+
if (str === "auto" || str === "a")
|
|
41
|
+
return "auto";
|
|
42
|
+
const match = str.match(numberWithUnitRE);
|
|
43
|
+
if (!match)
|
|
44
|
+
return;
|
|
45
|
+
const [, n, unit] = match;
|
|
46
|
+
if (unit)
|
|
47
|
+
return str;
|
|
48
|
+
const num = parseFloat(n);
|
|
49
|
+
if (!Number.isNaN(num))
|
|
50
|
+
return `${num / 4}rem`;
|
|
51
|
+
}
|
|
52
|
+
function px(str) {
|
|
53
|
+
const match = str.match(numberWithUnitRE);
|
|
54
|
+
if (!match)
|
|
55
|
+
return;
|
|
56
|
+
const [, n, unit] = match;
|
|
57
|
+
if (unit)
|
|
58
|
+
return str;
|
|
59
|
+
const num = parseFloat(n);
|
|
60
|
+
if (!Number.isNaN(num))
|
|
61
|
+
return `${num}px`;
|
|
62
|
+
}
|
|
63
|
+
function number(str) {
|
|
64
|
+
if (!numberRE.test(str))
|
|
65
|
+
return;
|
|
66
|
+
const num = parseFloat(str);
|
|
67
|
+
if (!Number.isNaN(num))
|
|
68
|
+
return num;
|
|
69
|
+
}
|
|
70
|
+
function percent(str) {
|
|
71
|
+
if (str.endsWith("%"))
|
|
72
|
+
str = str.slice(0, -1);
|
|
73
|
+
const num = parseFloat(str);
|
|
74
|
+
if (!Number.isNaN(num))
|
|
75
|
+
return `${num / 100}`;
|
|
76
|
+
}
|
|
77
|
+
function fraction(str) {
|
|
78
|
+
if (str === "full")
|
|
79
|
+
return "100%";
|
|
80
|
+
const [left, right] = str.split("/");
|
|
81
|
+
const num = parseFloat(left) / parseFloat(right);
|
|
82
|
+
if (!Number.isNaN(num))
|
|
83
|
+
return `${num * 100}%`;
|
|
84
|
+
}
|
|
85
|
+
function bracket(str) {
|
|
86
|
+
if (str && str[0] === "[" && str[str.length - 1] === "]") {
|
|
87
|
+
return str.slice(1, -1).replace(/_/g, " ").replace(/calc\((.*)/g, (v) => {
|
|
88
|
+
return v.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, "$1 $2 ");
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function cssvar(str) {
|
|
93
|
+
if (str.startsWith("$"))
|
|
94
|
+
return `var(--${str.slice(1)})`;
|
|
95
|
+
}
|
|
96
|
+
function time(str) {
|
|
97
|
+
const duration = Number(str.replace(/(s|ms)$/, ""));
|
|
98
|
+
if (isNaN(duration))
|
|
99
|
+
return;
|
|
100
|
+
if (/ms|s$/.test(str))
|
|
101
|
+
return str;
|
|
102
|
+
return `${str}ms`;
|
|
103
|
+
}
|
|
104
|
+
function global(str) {
|
|
105
|
+
if (["inherit", "initial", "unset"].includes(str))
|
|
106
|
+
return str;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const handlers = {
|
|
110
|
+
__proto__: null,
|
|
111
|
+
rem: rem,
|
|
112
|
+
px: px,
|
|
113
|
+
number: number,
|
|
114
|
+
percent: percent,
|
|
115
|
+
fraction: fraction,
|
|
116
|
+
bracket: bracket,
|
|
117
|
+
cssvar: cssvar,
|
|
118
|
+
time: time,
|
|
119
|
+
global: global
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const handlersNames = Object.keys(handlers);
|
|
123
|
+
const handler = function(str) {
|
|
124
|
+
const s = this.__options?.sequence || [];
|
|
125
|
+
this.__options.sequence = [];
|
|
126
|
+
for (const n of s) {
|
|
127
|
+
const res = handlers[n](str);
|
|
128
|
+
if (res != null)
|
|
129
|
+
return res;
|
|
130
|
+
}
|
|
131
|
+
return void 0;
|
|
132
|
+
};
|
|
133
|
+
function addProcessor(that, name) {
|
|
134
|
+
if (!that.__options) {
|
|
135
|
+
that.__options = {
|
|
136
|
+
sequence: []
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
that.__options.sequence.push(name);
|
|
140
|
+
return that;
|
|
141
|
+
}
|
|
142
|
+
handlersNames.forEach((i) => {
|
|
143
|
+
Object.defineProperty(handler, i, {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
get() {
|
|
146
|
+
return addProcessor(this, i);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
function capitalize(str) {
|
|
152
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
exports.bracket = bracket;
|
|
156
|
+
exports.capitalize = capitalize;
|
|
157
|
+
exports.cornerMap = cornerMap;
|
|
158
|
+
exports.cssvar = cssvar;
|
|
159
|
+
exports.directionMap = directionMap;
|
|
160
|
+
exports.fraction = fraction;
|
|
161
|
+
exports.global = global;
|
|
162
|
+
exports.handler = handler;
|
|
163
|
+
exports.handlersNames = handlersNames;
|
|
164
|
+
exports.number = number;
|
|
165
|
+
exports.percent = percent;
|
|
166
|
+
exports.px = px;
|
|
167
|
+
exports.rem = rem;
|
|
168
|
+
exports.time = time;
|
|
169
|
+
exports.xyzMap = xyzMap;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
const directionMap = {
|
|
2
|
+
"l": ["-left"],
|
|
3
|
+
"r": ["-right"],
|
|
4
|
+
"t": ["-top"],
|
|
5
|
+
"b": ["-bottom"],
|
|
6
|
+
"s": ["-inline-start"],
|
|
7
|
+
"e": ["-inline-end"],
|
|
8
|
+
"x": ["-left", "-right"],
|
|
9
|
+
"y": ["-top", "-bottom"],
|
|
10
|
+
"": [""],
|
|
11
|
+
"a": [""]
|
|
12
|
+
};
|
|
13
|
+
const cornerMap = {
|
|
14
|
+
"t": ["-top-left", "-top-right"],
|
|
15
|
+
"r": ["-top-right", "-bottom-right"],
|
|
16
|
+
"b": ["-bottom-left", "-bottom-right"],
|
|
17
|
+
"l": ["-bottom-left", "-top-left"],
|
|
18
|
+
"tl": ["-top-left"],
|
|
19
|
+
"lt": ["-top-left"],
|
|
20
|
+
"tr": ["-top-right"],
|
|
21
|
+
"rt": ["-top-right"],
|
|
22
|
+
"bl": ["-bottom-left"],
|
|
23
|
+
"lb": ["-bottom-left"],
|
|
24
|
+
"br": ["-bottom-right"],
|
|
25
|
+
"rb": ["-bottom-right"],
|
|
26
|
+
"": [""]
|
|
27
|
+
};
|
|
28
|
+
const xyzMap = {
|
|
29
|
+
"x": ["-x"],
|
|
30
|
+
"y": ["-y"],
|
|
31
|
+
"z": ["-z"],
|
|
32
|
+
"": ["-x", "-y"]
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const numberWithUnitRE = /^(-?[0-9.]+)(px|pt|pc|rem|em|%|vh|vw|in|cm|mm|ex|ch|vmin|vmax)?$/i;
|
|
36
|
+
const numberRE = /^(-?[0-9.]+)$/i;
|
|
37
|
+
function rem(str) {
|
|
38
|
+
if (str === "auto" || str === "a")
|
|
39
|
+
return "auto";
|
|
40
|
+
const match = str.match(numberWithUnitRE);
|
|
41
|
+
if (!match)
|
|
42
|
+
return;
|
|
43
|
+
const [, n, unit] = match;
|
|
44
|
+
if (unit)
|
|
45
|
+
return str;
|
|
46
|
+
const num = parseFloat(n);
|
|
47
|
+
if (!Number.isNaN(num))
|
|
48
|
+
return `${num / 4}rem`;
|
|
49
|
+
}
|
|
50
|
+
function px(str) {
|
|
51
|
+
const match = str.match(numberWithUnitRE);
|
|
52
|
+
if (!match)
|
|
53
|
+
return;
|
|
54
|
+
const [, n, unit] = match;
|
|
55
|
+
if (unit)
|
|
56
|
+
return str;
|
|
57
|
+
const num = parseFloat(n);
|
|
58
|
+
if (!Number.isNaN(num))
|
|
59
|
+
return `${num}px`;
|
|
60
|
+
}
|
|
61
|
+
function number(str) {
|
|
62
|
+
if (!numberRE.test(str))
|
|
63
|
+
return;
|
|
64
|
+
const num = parseFloat(str);
|
|
65
|
+
if (!Number.isNaN(num))
|
|
66
|
+
return num;
|
|
67
|
+
}
|
|
68
|
+
function percent(str) {
|
|
69
|
+
if (str.endsWith("%"))
|
|
70
|
+
str = str.slice(0, -1);
|
|
71
|
+
const num = parseFloat(str);
|
|
72
|
+
if (!Number.isNaN(num))
|
|
73
|
+
return `${num / 100}`;
|
|
74
|
+
}
|
|
75
|
+
function fraction(str) {
|
|
76
|
+
if (str === "full")
|
|
77
|
+
return "100%";
|
|
78
|
+
const [left, right] = str.split("/");
|
|
79
|
+
const num = parseFloat(left) / parseFloat(right);
|
|
80
|
+
if (!Number.isNaN(num))
|
|
81
|
+
return `${num * 100}%`;
|
|
82
|
+
}
|
|
83
|
+
function bracket(str) {
|
|
84
|
+
if (str && str[0] === "[" && str[str.length - 1] === "]") {
|
|
85
|
+
return str.slice(1, -1).replace(/_/g, " ").replace(/calc\((.*)/g, (v) => {
|
|
86
|
+
return v.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, "$1 $2 ");
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function cssvar(str) {
|
|
91
|
+
if (str.startsWith("$"))
|
|
92
|
+
return `var(--${str.slice(1)})`;
|
|
93
|
+
}
|
|
94
|
+
function time(str) {
|
|
95
|
+
const duration = Number(str.replace(/(s|ms)$/, ""));
|
|
96
|
+
if (isNaN(duration))
|
|
97
|
+
return;
|
|
98
|
+
if (/ms|s$/.test(str))
|
|
99
|
+
return str;
|
|
100
|
+
return `${str}ms`;
|
|
101
|
+
}
|
|
102
|
+
function global(str) {
|
|
103
|
+
if (["inherit", "initial", "unset"].includes(str))
|
|
104
|
+
return str;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const handlers = {
|
|
108
|
+
__proto__: null,
|
|
109
|
+
rem: rem,
|
|
110
|
+
px: px,
|
|
111
|
+
number: number,
|
|
112
|
+
percent: percent,
|
|
113
|
+
fraction: fraction,
|
|
114
|
+
bracket: bracket,
|
|
115
|
+
cssvar: cssvar,
|
|
116
|
+
time: time,
|
|
117
|
+
global: global
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const handlersNames = Object.keys(handlers);
|
|
121
|
+
const handler = function(str) {
|
|
122
|
+
const s = this.__options?.sequence || [];
|
|
123
|
+
this.__options.sequence = [];
|
|
124
|
+
for (const n of s) {
|
|
125
|
+
const res = handlers[n](str);
|
|
126
|
+
if (res != null)
|
|
127
|
+
return res;
|
|
128
|
+
}
|
|
129
|
+
return void 0;
|
|
130
|
+
};
|
|
131
|
+
function addProcessor(that, name) {
|
|
132
|
+
if (!that.__options) {
|
|
133
|
+
that.__options = {
|
|
134
|
+
sequence: []
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
that.__options.sequence.push(name);
|
|
138
|
+
return that;
|
|
139
|
+
}
|
|
140
|
+
handlersNames.forEach((i) => {
|
|
141
|
+
Object.defineProperty(handler, i, {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get() {
|
|
144
|
+
return addProcessor(this, i);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
function capitalize(str) {
|
|
150
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { capitalize as a, percent as b, cornerMap as c, directionMap as d, bracket as e, fraction as f, cssvar as g, handler as h, global as i, handlersNames as j, number as n, px as p, rem as r, time as t, xyzMap as x };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const core = require('@unocss/core');
|
|
4
|
+
|
|
5
|
+
const CONTROL_BYPASS_PSEUDO = "$$no-pseudo";
|
|
6
|
+
const PseudoClasses = Object.fromEntries([
|
|
7
|
+
"active",
|
|
8
|
+
"checked",
|
|
9
|
+
"default",
|
|
10
|
+
"empty",
|
|
11
|
+
"enabled",
|
|
12
|
+
"disabled",
|
|
13
|
+
"first-of-type",
|
|
14
|
+
["first", "first-child"],
|
|
15
|
+
"focus-visible",
|
|
16
|
+
"focus-within",
|
|
17
|
+
"focus",
|
|
18
|
+
"hover",
|
|
19
|
+
"indeterminate",
|
|
20
|
+
"invalid",
|
|
21
|
+
"last-of-type",
|
|
22
|
+
["last", "last-child"],
|
|
23
|
+
"link",
|
|
24
|
+
"only-child",
|
|
25
|
+
"only-of-type",
|
|
26
|
+
"optional",
|
|
27
|
+
"placeholder-shown",
|
|
28
|
+
"read-only",
|
|
29
|
+
"read-write",
|
|
30
|
+
"required",
|
|
31
|
+
"root",
|
|
32
|
+
"target",
|
|
33
|
+
"valid",
|
|
34
|
+
"visited",
|
|
35
|
+
["even-of-type", "nth-of-type(even)"],
|
|
36
|
+
["even", "nth-child(even)"],
|
|
37
|
+
["odd-of-type", "nth-of-type(odd)"],
|
|
38
|
+
["odd", "nth-child(odd)"]
|
|
39
|
+
].map(core.toArray));
|
|
40
|
+
const PseudoElements = [
|
|
41
|
+
"before",
|
|
42
|
+
"after",
|
|
43
|
+
"first-letter",
|
|
44
|
+
"first-line",
|
|
45
|
+
"selection"
|
|
46
|
+
];
|
|
47
|
+
const PseudoElementsRE = new RegExp(`^(${PseudoElements.join("|")})[:-]`);
|
|
48
|
+
const PseudoClassesStr = Object.keys(PseudoClasses).join("|");
|
|
49
|
+
const PseudoClassesRE = new RegExp(`^(${PseudoClassesStr})[:-]`);
|
|
50
|
+
const PseudoClassesNotRE = new RegExp(`^not-(${PseudoClassesStr})[:-]`);
|
|
51
|
+
const PseudoClassesGroupRE = new RegExp(`^group-(${PseudoClassesStr})[:-]`);
|
|
52
|
+
const PseudoClassesPeerRE = new RegExp(`^peer-(${PseudoClassesStr})[:-]`);
|
|
53
|
+
const variantPseudoElements = (input) => {
|
|
54
|
+
const match = input.match(PseudoElementsRE);
|
|
55
|
+
if (match) {
|
|
56
|
+
return {
|
|
57
|
+
matcher: input.slice(match[1].length + 1),
|
|
58
|
+
selector: (s, body) => shouldAdd(body) && `${s}::${match[1]}`
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
function shouldAdd(entires) {
|
|
63
|
+
return !entires.find((i) => i[0] === CONTROL_BYPASS_PSEUDO) || void 0;
|
|
64
|
+
}
|
|
65
|
+
const variantPseudoClasses = {
|
|
66
|
+
match: (input) => {
|
|
67
|
+
let match = input.match(PseudoClassesRE);
|
|
68
|
+
if (match) {
|
|
69
|
+
const pseudo = PseudoClasses[match[1]] || match[1];
|
|
70
|
+
return {
|
|
71
|
+
matcher: input.slice(match[1].length + 1),
|
|
72
|
+
selector: (s, body) => shouldAdd(body) && `${s}:${pseudo}`
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
match = input.match(PseudoClassesNotRE);
|
|
76
|
+
if (match) {
|
|
77
|
+
const pseudo = PseudoClasses[match[1]] || match[1];
|
|
78
|
+
return {
|
|
79
|
+
matcher: input.slice(match[1].length + 5),
|
|
80
|
+
selector: (s, body) => shouldAdd(body) && `${s}:not(:${pseudo})`
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
match = input.match(PseudoClassesGroupRE);
|
|
84
|
+
if (match) {
|
|
85
|
+
const pseudo = PseudoClasses[match[1]] || match[1];
|
|
86
|
+
return {
|
|
87
|
+
matcher: input.slice(match[1].length + 7),
|
|
88
|
+
selector: (s, body) => shouldAdd(body) && s.includes(".group:") ? s.replace(/\.group:/, `.group:${pseudo}:`) : `.group:${pseudo} ${s}`
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
match = input.match(PseudoClassesPeerRE);
|
|
92
|
+
if (match) {
|
|
93
|
+
const pseudo = PseudoClasses[match[1]] || match[1];
|
|
94
|
+
return {
|
|
95
|
+
matcher: input.slice(match[1].length + 6),
|
|
96
|
+
selector: (s, body) => shouldAdd(body) && s.includes(".peer:") ? s.replace(/\.peer:/, `.peer:${pseudo}:`) : `.peer:${pseudo} ~ ${s}`
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
multiPass: true
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
exports.CONTROL_BYPASS_PSEUDO = CONTROL_BYPASS_PSEUDO;
|
|
104
|
+
exports.PseudoClasses = PseudoClasses;
|
|
105
|
+
exports.variantPseudoClasses = variantPseudoClasses;
|
|
106
|
+
exports.variantPseudoElements = variantPseudoElements;
|