@unocss/preset-mini 0.16.3 → 0.18.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.
@@ -0,0 +1,294 @@
1
+ 'use strict';
2
+
3
+ const core = require('@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
+ "a": [""]
16
+ };
17
+ const cornerMap = {
18
+ "t": ["-top-left", "-top-right"],
19
+ "r": ["-top-right", "-bottom-right"],
20
+ "b": ["-bottom-left", "-bottom-right"],
21
+ "l": ["-bottom-left", "-top-left"],
22
+ "tl": ["-top-left"],
23
+ "lt": ["-top-left"],
24
+ "tr": ["-top-right"],
25
+ "rt": ["-top-right"],
26
+ "bl": ["-bottom-left"],
27
+ "lb": ["-bottom-left"],
28
+ "br": ["-bottom-right"],
29
+ "rb": ["-bottom-right"],
30
+ "": [""]
31
+ };
32
+ const xyzMap = {
33
+ "x": ["-x"],
34
+ "y": ["-y"],
35
+ "z": ["-z"],
36
+ "": ["-x", "-y"]
37
+ };
38
+
39
+ const cssBasicProps = [
40
+ "color",
41
+ "border-color",
42
+ "background-color",
43
+ "flex-grow",
44
+ "flex",
45
+ "flex-shrink",
46
+ "caret-color",
47
+ "font",
48
+ "gap",
49
+ "opacity",
50
+ "visibility",
51
+ "z-index",
52
+ "font-weight",
53
+ "zoom",
54
+ "text-shadow",
55
+ "transform",
56
+ "box-shadow"
57
+ ];
58
+ const cssPositionProps = [
59
+ "backround-position",
60
+ "left",
61
+ "right",
62
+ "top",
63
+ "bottom",
64
+ "object-position"
65
+ ];
66
+ const cssSizeProps = [
67
+ "max-height",
68
+ "min-height",
69
+ "max-width",
70
+ "min-width",
71
+ "height",
72
+ "width",
73
+ "border-width",
74
+ "margin",
75
+ "padding",
76
+ "outline-width",
77
+ "outline-offset",
78
+ "font-size",
79
+ "line-height",
80
+ "text-indent",
81
+ "vertical-align",
82
+ "border-spacing",
83
+ "letter-spacing",
84
+ "word-spacing"
85
+ ];
86
+ const cssEnhanceProps = ["stroke", "filter", "backdrop-filter", "fill", "mask", "mask-size", "mask-border", "clip-path", "clip"];
87
+ const cssProps = [
88
+ ...cssBasicProps,
89
+ ...cssPositionProps,
90
+ ...cssSizeProps,
91
+ ...cssEnhanceProps
92
+ ];
93
+ const numberWithUnitRE = /^(-?[0-9.]+)(px|pt|pc|rem|em|%|vh|vw|in|cm|mm|ex|ch|vmin|vmax)?$/i;
94
+ const numberRE = /^(-?[0-9.]+)$/i;
95
+ const unitOnlyRE = /^(px)$/i;
96
+ function numberWithUnit(str) {
97
+ const match = str.match(numberWithUnitRE);
98
+ if (!match)
99
+ return;
100
+ const [, , unit] = match;
101
+ if (unit)
102
+ return str;
103
+ }
104
+ function auto(str) {
105
+ if (str === "auto" || str === "a")
106
+ return "auto";
107
+ }
108
+ function rem(str) {
109
+ if (str.match(unitOnlyRE))
110
+ return `1${str}`;
111
+ const match = str.match(numberWithUnitRE);
112
+ if (!match)
113
+ return;
114
+ const [, n, unit] = match;
115
+ if (unit)
116
+ return str;
117
+ const num = parseFloat(n);
118
+ if (!Number.isNaN(num))
119
+ return `${num / 4}rem`;
120
+ }
121
+ function px(str) {
122
+ if (str.match(unitOnlyRE))
123
+ return `1${str}`;
124
+ const match = str.match(numberWithUnitRE);
125
+ if (!match)
126
+ return;
127
+ const [, n, unit] = match;
128
+ if (unit)
129
+ return str;
130
+ const num = parseFloat(n);
131
+ if (!Number.isNaN(num))
132
+ return `${num}px`;
133
+ }
134
+ function number(str) {
135
+ if (!numberRE.test(str))
136
+ return;
137
+ const num = parseFloat(str);
138
+ if (!Number.isNaN(num))
139
+ return num;
140
+ }
141
+ function percent(str) {
142
+ if (str.endsWith("%"))
143
+ str = str.slice(0, -1);
144
+ const num = parseFloat(str);
145
+ if (!Number.isNaN(num))
146
+ return `${num / 100}`;
147
+ }
148
+ function fraction(str) {
149
+ if (str === "full")
150
+ return "100%";
151
+ const [left, right] = str.split("/");
152
+ const num = parseFloat(left) / parseFloat(right);
153
+ if (!Number.isNaN(num))
154
+ return `${num * 100}%`;
155
+ }
156
+ function bracket(str) {
157
+ if (str && str[0] === "[" && str[str.length - 1] === "]") {
158
+ return str.slice(1, -1).replace(/_/g, " ").replace(/calc\((.*)/g, (v) => {
159
+ return v.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, "$1 $2 ");
160
+ });
161
+ }
162
+ }
163
+ function cssvar(str) {
164
+ if (str.startsWith("$"))
165
+ return `var(--${str.slice(1)})`;
166
+ }
167
+ function time(str) {
168
+ const duration = Number(str.replace(/(s|ms)$/, ""));
169
+ if (isNaN(duration))
170
+ return;
171
+ if (/(s|ms)$/.test(str))
172
+ return str;
173
+ return `${str}ms`;
174
+ }
175
+ function global(str) {
176
+ if (["inherit", "initial", "revert", "unset"].includes(str))
177
+ return str;
178
+ }
179
+ function properties(str) {
180
+ if (str === void 0)
181
+ return;
182
+ for (const prop of str.split(",")) {
183
+ if (!cssProps.includes(prop))
184
+ return;
185
+ }
186
+ return str;
187
+ }
188
+
189
+ const valueHandlers = {
190
+ __proto__: null,
191
+ numberWithUnit: numberWithUnit,
192
+ auto: auto,
193
+ rem: rem,
194
+ px: px,
195
+ number: number,
196
+ percent: percent,
197
+ fraction: fraction,
198
+ bracket: bracket,
199
+ cssvar: cssvar,
200
+ time: time,
201
+ global: global,
202
+ properties: properties
203
+ };
204
+
205
+ const handler = core.createValueHandler(valueHandlers);
206
+ const h = handler;
207
+
208
+ function capitalize(str) {
209
+ return str.charAt(0).toUpperCase() + str.slice(1);
210
+ }
211
+ const directionSize = (propertyPrefix) => ([_, direction, size]) => {
212
+ const v = handler.bracket.auto.rem.fraction.cssvar(size);
213
+ if (v !== void 0)
214
+ return directionMap[direction].map((i) => [`${propertyPrefix}${i}`, v]);
215
+ };
216
+ const getThemeColor = (theme, colors) => theme.colors?.[colors.join("-").replace(/(-[a-z])/g, (n) => n.slice(1).toUpperCase())];
217
+ const parseColor = (body, theme) => {
218
+ const [main, opacity] = body.split(/(?:\/|:)/);
219
+ const colors = main.replace(/([a-z])([0-9])/g, "$1-$2").split(/-/g);
220
+ const [name] = colors;
221
+ if (!name)
222
+ return;
223
+ let color;
224
+ const bracket = handler.bracket(main);
225
+ const bracketOrMain = bracket || main;
226
+ if (bracketOrMain.startsWith("#"))
227
+ color = bracketOrMain.slice(1);
228
+ if (bracketOrMain.startsWith("hex-"))
229
+ color = bracketOrMain.slice(4);
230
+ color = color || bracket;
231
+ let no = "DEFAULT";
232
+ if (!color) {
233
+ let colorData;
234
+ const [scale] = colors.slice(-1);
235
+ if (scale.match(/^\d+$/)) {
236
+ no = scale;
237
+ colorData = getThemeColor(theme, colors.slice(0, -1));
238
+ } else {
239
+ colorData = getThemeColor(theme, colors);
240
+ if (!colorData) {
241
+ [, no = no] = colors;
242
+ colorData = getThemeColor(theme, [name]);
243
+ }
244
+ }
245
+ if (typeof colorData === "string")
246
+ color = colorData;
247
+ else if (no && colorData)
248
+ color = colorData[no];
249
+ }
250
+ return {
251
+ opacity,
252
+ name,
253
+ no,
254
+ color,
255
+ rgba: core.hex2rgba(color)
256
+ };
257
+ };
258
+ const colorResolver = (property, varName) => ([, body], { theme }) => {
259
+ const data = parseColor(body, theme);
260
+ if (!data)
261
+ return;
262
+ const { opacity, color, rgba } = data;
263
+ if (!color)
264
+ return;
265
+ const a = opacity ? opacity[0] === "[" ? handler.bracket.percent(opacity) : parseFloat(opacity) / 100 : rgba?.[3];
266
+ if (rgba) {
267
+ if (a != null && !Number.isNaN(a)) {
268
+ rgba[3] = typeof a === "string" && !a.includes("%") ? parseFloat(a) : a;
269
+ return {
270
+ [property]: `rgba(${rgba.join(",")})`
271
+ };
272
+ } else {
273
+ return {
274
+ [`--un-${varName}-opacity`]: 1,
275
+ [property]: `rgba(${rgba.slice(0, 3).join(",")},var(--un-${varName}-opacity))`
276
+ };
277
+ }
278
+ } else {
279
+ return {
280
+ [property]: color.replace("%alpha", `${a || 1}`)
281
+ };
282
+ }
283
+ };
284
+
285
+ exports.capitalize = capitalize;
286
+ exports.colorResolver = colorResolver;
287
+ exports.cornerMap = cornerMap;
288
+ exports.directionMap = directionMap;
289
+ exports.directionSize = directionSize;
290
+ exports.h = h;
291
+ exports.handler = handler;
292
+ exports.parseColor = parseColor;
293
+ exports.valueHandlers = valueHandlers;
294
+ exports.xyzMap = xyzMap;
@@ -0,0 +1,283 @@
1
+ import { createValueHandler, hex2rgba } from '@unocss/core';
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 cssBasicProps = [
38
+ "color",
39
+ "border-color",
40
+ "background-color",
41
+ "flex-grow",
42
+ "flex",
43
+ "flex-shrink",
44
+ "caret-color",
45
+ "font",
46
+ "gap",
47
+ "opacity",
48
+ "visibility",
49
+ "z-index",
50
+ "font-weight",
51
+ "zoom",
52
+ "text-shadow",
53
+ "transform",
54
+ "box-shadow"
55
+ ];
56
+ const cssPositionProps = [
57
+ "backround-position",
58
+ "left",
59
+ "right",
60
+ "top",
61
+ "bottom",
62
+ "object-position"
63
+ ];
64
+ const cssSizeProps = [
65
+ "max-height",
66
+ "min-height",
67
+ "max-width",
68
+ "min-width",
69
+ "height",
70
+ "width",
71
+ "border-width",
72
+ "margin",
73
+ "padding",
74
+ "outline-width",
75
+ "outline-offset",
76
+ "font-size",
77
+ "line-height",
78
+ "text-indent",
79
+ "vertical-align",
80
+ "border-spacing",
81
+ "letter-spacing",
82
+ "word-spacing"
83
+ ];
84
+ const cssEnhanceProps = ["stroke", "filter", "backdrop-filter", "fill", "mask", "mask-size", "mask-border", "clip-path", "clip"];
85
+ const cssProps = [
86
+ ...cssBasicProps,
87
+ ...cssPositionProps,
88
+ ...cssSizeProps,
89
+ ...cssEnhanceProps
90
+ ];
91
+ const numberWithUnitRE = /^(-?[0-9.]+)(px|pt|pc|rem|em|%|vh|vw|in|cm|mm|ex|ch|vmin|vmax)?$/i;
92
+ const numberRE = /^(-?[0-9.]+)$/i;
93
+ const unitOnlyRE = /^(px)$/i;
94
+ function numberWithUnit(str) {
95
+ const match = str.match(numberWithUnitRE);
96
+ if (!match)
97
+ return;
98
+ const [, , unit] = match;
99
+ if (unit)
100
+ return str;
101
+ }
102
+ function auto(str) {
103
+ if (str === "auto" || str === "a")
104
+ return "auto";
105
+ }
106
+ function rem(str) {
107
+ if (str.match(unitOnlyRE))
108
+ return `1${str}`;
109
+ const match = str.match(numberWithUnitRE);
110
+ if (!match)
111
+ return;
112
+ const [, n, unit] = match;
113
+ if (unit)
114
+ return str;
115
+ const num = parseFloat(n);
116
+ if (!Number.isNaN(num))
117
+ return `${num / 4}rem`;
118
+ }
119
+ function px(str) {
120
+ if (str.match(unitOnlyRE))
121
+ return `1${str}`;
122
+ const match = str.match(numberWithUnitRE);
123
+ if (!match)
124
+ return;
125
+ const [, n, unit] = match;
126
+ if (unit)
127
+ return str;
128
+ const num = parseFloat(n);
129
+ if (!Number.isNaN(num))
130
+ return `${num}px`;
131
+ }
132
+ function number(str) {
133
+ if (!numberRE.test(str))
134
+ return;
135
+ const num = parseFloat(str);
136
+ if (!Number.isNaN(num))
137
+ return num;
138
+ }
139
+ function percent(str) {
140
+ if (str.endsWith("%"))
141
+ str = str.slice(0, -1);
142
+ const num = parseFloat(str);
143
+ if (!Number.isNaN(num))
144
+ return `${num / 100}`;
145
+ }
146
+ function fraction(str) {
147
+ if (str === "full")
148
+ return "100%";
149
+ const [left, right] = str.split("/");
150
+ const num = parseFloat(left) / parseFloat(right);
151
+ if (!Number.isNaN(num))
152
+ return `${num * 100}%`;
153
+ }
154
+ function bracket(str) {
155
+ if (str && str[0] === "[" && str[str.length - 1] === "]") {
156
+ return str.slice(1, -1).replace(/_/g, " ").replace(/calc\((.*)/g, (v) => {
157
+ return v.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, "$1 $2 ");
158
+ });
159
+ }
160
+ }
161
+ function cssvar(str) {
162
+ if (str.startsWith("$"))
163
+ return `var(--${str.slice(1)})`;
164
+ }
165
+ function time(str) {
166
+ const duration = Number(str.replace(/(s|ms)$/, ""));
167
+ if (isNaN(duration))
168
+ return;
169
+ if (/(s|ms)$/.test(str))
170
+ return str;
171
+ return `${str}ms`;
172
+ }
173
+ function global(str) {
174
+ if (["inherit", "initial", "revert", "unset"].includes(str))
175
+ return str;
176
+ }
177
+ function properties(str) {
178
+ if (str === void 0)
179
+ return;
180
+ for (const prop of str.split(",")) {
181
+ if (!cssProps.includes(prop))
182
+ return;
183
+ }
184
+ return str;
185
+ }
186
+
187
+ const valueHandlers = {
188
+ __proto__: null,
189
+ numberWithUnit: numberWithUnit,
190
+ auto: auto,
191
+ rem: rem,
192
+ px: px,
193
+ number: number,
194
+ percent: percent,
195
+ fraction: fraction,
196
+ bracket: bracket,
197
+ cssvar: cssvar,
198
+ time: time,
199
+ global: global,
200
+ properties: properties
201
+ };
202
+
203
+ const handler = createValueHandler(valueHandlers);
204
+ const h = handler;
205
+
206
+ function capitalize(str) {
207
+ return str.charAt(0).toUpperCase() + str.slice(1);
208
+ }
209
+ const directionSize = (propertyPrefix) => ([_, direction, size]) => {
210
+ const v = handler.bracket.auto.rem.fraction.cssvar(size);
211
+ if (v !== void 0)
212
+ return directionMap[direction].map((i) => [`${propertyPrefix}${i}`, v]);
213
+ };
214
+ const getThemeColor = (theme, colors) => theme.colors?.[colors.join("-").replace(/(-[a-z])/g, (n) => n.slice(1).toUpperCase())];
215
+ const parseColor = (body, theme) => {
216
+ const [main, opacity] = body.split(/(?:\/|:)/);
217
+ const colors = main.replace(/([a-z])([0-9])/g, "$1-$2").split(/-/g);
218
+ const [name] = colors;
219
+ if (!name)
220
+ return;
221
+ let color;
222
+ const bracket = handler.bracket(main);
223
+ const bracketOrMain = bracket || main;
224
+ if (bracketOrMain.startsWith("#"))
225
+ color = bracketOrMain.slice(1);
226
+ if (bracketOrMain.startsWith("hex-"))
227
+ color = bracketOrMain.slice(4);
228
+ color = color || bracket;
229
+ let no = "DEFAULT";
230
+ if (!color) {
231
+ let colorData;
232
+ const [scale] = colors.slice(-1);
233
+ if (scale.match(/^\d+$/)) {
234
+ no = scale;
235
+ colorData = getThemeColor(theme, colors.slice(0, -1));
236
+ } else {
237
+ colorData = getThemeColor(theme, colors);
238
+ if (!colorData) {
239
+ [, no = no] = colors;
240
+ colorData = getThemeColor(theme, [name]);
241
+ }
242
+ }
243
+ if (typeof colorData === "string")
244
+ color = colorData;
245
+ else if (no && colorData)
246
+ color = colorData[no];
247
+ }
248
+ return {
249
+ opacity,
250
+ name,
251
+ no,
252
+ color,
253
+ rgba: hex2rgba(color)
254
+ };
255
+ };
256
+ const colorResolver = (property, varName) => ([, body], { theme }) => {
257
+ const data = parseColor(body, theme);
258
+ if (!data)
259
+ return;
260
+ const { opacity, color, rgba } = data;
261
+ if (!color)
262
+ return;
263
+ const a = opacity ? opacity[0] === "[" ? handler.bracket.percent(opacity) : parseFloat(opacity) / 100 : rgba?.[3];
264
+ if (rgba) {
265
+ if (a != null && !Number.isNaN(a)) {
266
+ rgba[3] = typeof a === "string" && !a.includes("%") ? parseFloat(a) : a;
267
+ return {
268
+ [property]: `rgba(${rgba.join(",")})`
269
+ };
270
+ } else {
271
+ return {
272
+ [`--un-${varName}-opacity`]: 1,
273
+ [property]: `rgba(${rgba.slice(0, 3).join(",")},var(--un-${varName}-opacity))`
274
+ };
275
+ }
276
+ } else {
277
+ return {
278
+ [property]: color.replace("%alpha", `${a || 1}`)
279
+ };
280
+ }
281
+ };
282
+
283
+ export { cornerMap as a, capitalize as b, colorResolver as c, directionMap as d, directionSize as e, h as f, handler as h, parseColor as p, valueHandlers as v, xyzMap as x };
@@ -1,13 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  const variantMatcher = (name, selector) => {
4
- const length = name.length + 1;
5
- const re = new RegExp(`^${name}[:-]`);
4
+ const re = new RegExp(`^(${name})[:-]`);
6
5
  return (input) => {
7
- return input.match(re) ? {
8
- matcher: input.slice(length),
9
- selector
10
- } : void 0;
6
+ const match = input.match(re);
7
+ if (match) {
8
+ return {
9
+ matcher: input.slice(match[1].length + 1),
10
+ selector
11
+ };
12
+ }
11
13
  };
12
14
  };
13
15
 
@@ -1,11 +1,13 @@
1
1
  const variantMatcher = (name, selector) => {
2
- const length = name.length + 1;
3
- const re = new RegExp(`^${name}[:-]`);
2
+ const re = new RegExp(`^(${name})[:-]`);
4
3
  return (input) => {
5
- return input.match(re) ? {
6
- matcher: input.slice(length),
7
- selector
8
- } : void 0;
4
+ const match = input.match(re);
5
+ if (match) {
6
+ return {
7
+ matcher: input.slice(match[1].length + 1),
8
+ selector
9
+ };
10
+ }
9
11
  };
10
12
  };
11
13
 
package/dist/index.cjs CHANGED
@@ -6,8 +6,8 @@ const _default = require('./chunks/default.cjs');
6
6
  const _default$1 = require('./chunks/default2.cjs');
7
7
  const _default$2 = require('./chunks/default3.cjs');
8
8
  const colors = require('./chunks/colors.cjs');
9
+ require('./chunks/utilities.cjs');
9
10
  require('@unocss/core');
10
- require('./chunks/index.cjs');
11
11
  require('./chunks/pseudo.cjs');
12
12
  require('./chunks/variants.cjs');
13
13
 
@@ -15,10 +15,7 @@ const presetMini = (options = {}) => ({
15
15
  name: "@unocss/preset-mini",
16
16
  theme: _default.theme,
17
17
  rules: _default$1.rules,
18
- variants: [
19
- ..._default$2.variants,
20
- ...options.dark === "media" ? _default$2.variantColorsMedia : _default$2.variantColorsClass
21
- ],
18
+ variants: _default$2.variants(options),
22
19
  options
23
20
  });
24
21
 
package/dist/index.d.ts CHANGED
@@ -9,6 +9,10 @@ interface PresetMiniOptions {
9
9
  * @default 'class'
10
10
  */
11
11
  dark?: 'class' | 'media';
12
+ /**
13
+ * @default false
14
+ */
15
+ attributifyPseudo?: Boolean;
12
16
  }
13
17
  declare const presetMini: (options?: PresetMiniOptions) => Preset<Theme>;
14
18
 
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import { t as theme } from './chunks/default.mjs';
2
2
  export { t as theme } from './chunks/default.mjs';
3
3
  import { r as rules } from './chunks/default2.mjs';
4
- import { v as variants, a as variantColorsMedia, b as variantColorsClass } from './chunks/default3.mjs';
4
+ import { v as variants } from './chunks/default3.mjs';
5
5
  export { c as colors } from './chunks/colors.mjs';
6
+ import './chunks/utilities.mjs';
6
7
  import '@unocss/core';
7
- import './chunks/index.mjs';
8
8
  import './chunks/pseudo.mjs';
9
9
  import './chunks/variants.mjs';
10
10
 
@@ -12,10 +12,7 @@ const presetMini = (options = {}) => ({
12
12
  name: "@unocss/preset-mini",
13
13
  theme,
14
14
  rules,
15
- variants: [
16
- ...variants,
17
- ...options.dark === "media" ? variantColorsMedia : variantColorsClass
18
- ],
15
+ variants: variants(options),
19
16
  options
20
17
  });
21
18