@unocss/preset-mini 0.39.1 → 0.40.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.
@@ -96,8 +96,8 @@ const variantCustomMedia = {
96
96
  const variantColorsMediaOrClass = (options = {}) => {
97
97
  if (options?.dark === "class") {
98
98
  return [
99
- variants$1.variantMatcher("dark", (input) => `.dark $$ ${input}`),
100
- variants$1.variantMatcher("light", (input) => `.light $$ ${input}`)
99
+ variants$1.variantMatcher("dark", (input) => ({ prefix: `${input.prefix}.dark $$ ` })),
100
+ variants$1.variantMatcher("light", (input) => ({ prefix: `${input.prefix}.light $$ ` }))
101
101
  ];
102
102
  }
103
103
  return [
@@ -107,8 +107,8 @@ const variantColorsMediaOrClass = (options = {}) => {
107
107
  };
108
108
 
109
109
  const variantLanguageDirections = [
110
- variants$1.variantMatcher("rtl", (input) => `[dir="rtl"] $$ ${input}`),
111
- variants$1.variantMatcher("ltr", (input) => `[dir="ltr"] $$ ${input}`)
110
+ variants$1.variantMatcher("rtl", (input) => ({ prefix: `${input.prefix}[dir="rtl"] $$ ` })),
111
+ variants$1.variantMatcher("ltr", (input) => ({ prefix: `${input.prefix}[dir="ltr"] $$ ` }))
112
112
  ];
113
113
 
114
114
  const variantSelector = {
@@ -159,6 +159,25 @@ const variantScope = {
159
159
  }
160
160
  }
161
161
  };
162
+ const variantVariables = {
163
+ name: "variables",
164
+ match(matcher) {
165
+ const match = matcher.match(/^(\[[^\]]+\]):/);
166
+ if (match) {
167
+ const variant = utilities.handler.bracket(match[1]) ?? "";
168
+ const updates = variant.startsWith("@") ? {
169
+ parent: variant
170
+ } : {
171
+ selector: (s) => variant.replace(/&/g, s)
172
+ };
173
+ return {
174
+ matcher: matcher.slice(match[0].length),
175
+ ...updates
176
+ };
177
+ }
178
+ },
179
+ multiPass: true
180
+ };
162
181
 
163
182
  const numberRE = /[0-9.]+(?:[a-z]+|%)?/;
164
183
  const ignoreProps = [
@@ -282,7 +301,7 @@ const sortValue = (pseudo) => {
282
301
  return 1;
283
302
  };
284
303
  const taggedPseudoClassMatcher = (tag, parent, combinator) => {
285
- const rawRe = new RegExp(`^${core.escapeRegExp(parent)}:`);
304
+ const rawRe = new RegExp(`${core.escapeRegExp(parent)}:`);
286
305
  const pseudoRE = new RegExp(`^${tag}-((?:(${PseudoClassFunctionsStr})-)?(${PseudoClassesStr}))[:-]`);
287
306
  const pseudoColonRE = new RegExp(`^${tag}-((?:(${PseudoClassFunctionsStr})-)?(${PseudoClassesColonStr}))[:]`);
288
307
  return {
@@ -295,8 +314,11 @@ const taggedPseudoClassMatcher = (tag, parent, combinator) => {
295
314
  pseudo = `:${match[2]}(${pseudo})`;
296
315
  return {
297
316
  matcher: input.slice(match[0].length),
298
- selector: (s) => rawRe.test(s) ? s.replace(rawRe, `${parent}${pseudo}:`) : `${parent}${pseudo}${combinator}${s}`,
299
- sort: sortValue(match[3])
317
+ handle: (input2, next) => next({
318
+ ...input2,
319
+ prefix: rawRe.test(input2.prefix) ? input2.prefix.replace(rawRe, `${parent}${pseudo}:`) : `${input2.prefix}${parent}${pseudo}${combinator}`,
320
+ sort: sortValue(match[3])
321
+ })
300
322
  };
301
323
  }
302
324
  }
@@ -314,8 +336,18 @@ const variantPseudoClassesAndElements = {
314
336
  const pseudo = PseudoClasses[match[1]] || PseudoClassesColon[match[1]] || `:${match[1]}`;
315
337
  return {
316
338
  matcher: input.slice(match[0].length),
317
- selector: (s) => `${s}${pseudo}`,
318
- sort: sortValue(match[1])
339
+ handle: (input2, next) => {
340
+ const selectors = pseudo.startsWith("::") ? {
341
+ pseudo: `${input2.pseudo}${pseudo}`
342
+ } : {
343
+ selector: `${input2.selector}${pseudo}`
344
+ };
345
+ return next({
346
+ ...input2,
347
+ ...selectors,
348
+ sort: sortValue(match[1])
349
+ });
350
+ }
319
351
  };
320
352
  }
321
353
  },
@@ -376,6 +408,7 @@ const partClasses = {
376
408
  };
377
409
 
378
410
  const variants = (options) => [
411
+ variantVariables,
379
412
  variantCssLayer,
380
413
  variantSelector,
381
414
  variantInternalLayer,
@@ -410,4 +443,5 @@ exports.variantPseudoClassesAndElements = variantPseudoClassesAndElements;
410
443
  exports.variantScope = variantScope;
411
444
  exports.variantSelector = variantSelector;
412
445
  exports.variantTaggedPseudoClasses = variantTaggedPseudoClasses;
446
+ exports.variantVariables = variantVariables;
413
447
  exports.variants = variants;
@@ -1,4 +1,4 @@
1
- import { k as resolveBreakpoints, C as CONTROL_MINI_NO_NEGATIVE } from './utilities.mjs';
1
+ import { k as resolveBreakpoints, h as handler, C as CONTROL_MINI_NO_NEGATIVE } from './utilities.mjs';
2
2
  import { v as variantParentMatcher, a as variantMatcher } from './variants.mjs';
3
3
  import { escapeRegExp } from '@unocss/core';
4
4
 
@@ -94,8 +94,8 @@ const variantCustomMedia = {
94
94
  const variantColorsMediaOrClass = (options = {}) => {
95
95
  if (options?.dark === "class") {
96
96
  return [
97
- variantMatcher("dark", (input) => `.dark $$ ${input}`),
98
- variantMatcher("light", (input) => `.light $$ ${input}`)
97
+ variantMatcher("dark", (input) => ({ prefix: `${input.prefix}.dark $$ ` })),
98
+ variantMatcher("light", (input) => ({ prefix: `${input.prefix}.light $$ ` }))
99
99
  ];
100
100
  }
101
101
  return [
@@ -105,8 +105,8 @@ const variantColorsMediaOrClass = (options = {}) => {
105
105
  };
106
106
 
107
107
  const variantLanguageDirections = [
108
- variantMatcher("rtl", (input) => `[dir="rtl"] $$ ${input}`),
109
- variantMatcher("ltr", (input) => `[dir="ltr"] $$ ${input}`)
108
+ variantMatcher("rtl", (input) => ({ prefix: `${input.prefix}[dir="rtl"] $$ ` })),
109
+ variantMatcher("ltr", (input) => ({ prefix: `${input.prefix}[dir="ltr"] $$ ` }))
110
110
  ];
111
111
 
112
112
  const variantSelector = {
@@ -157,6 +157,25 @@ const variantScope = {
157
157
  }
158
158
  }
159
159
  };
160
+ const variantVariables = {
161
+ name: "variables",
162
+ match(matcher) {
163
+ const match = matcher.match(/^(\[[^\]]+\]):/);
164
+ if (match) {
165
+ const variant = handler.bracket(match[1]) ?? "";
166
+ const updates = variant.startsWith("@") ? {
167
+ parent: variant
168
+ } : {
169
+ selector: (s) => variant.replace(/&/g, s)
170
+ };
171
+ return {
172
+ matcher: matcher.slice(match[0].length),
173
+ ...updates
174
+ };
175
+ }
176
+ },
177
+ multiPass: true
178
+ };
160
179
 
161
180
  const numberRE = /[0-9.]+(?:[a-z]+|%)?/;
162
181
  const ignoreProps = [
@@ -280,7 +299,7 @@ const sortValue = (pseudo) => {
280
299
  return 1;
281
300
  };
282
301
  const taggedPseudoClassMatcher = (tag, parent, combinator) => {
283
- const rawRe = new RegExp(`^${escapeRegExp(parent)}:`);
302
+ const rawRe = new RegExp(`${escapeRegExp(parent)}:`);
284
303
  const pseudoRE = new RegExp(`^${tag}-((?:(${PseudoClassFunctionsStr})-)?(${PseudoClassesStr}))[:-]`);
285
304
  const pseudoColonRE = new RegExp(`^${tag}-((?:(${PseudoClassFunctionsStr})-)?(${PseudoClassesColonStr}))[:]`);
286
305
  return {
@@ -293,8 +312,11 @@ const taggedPseudoClassMatcher = (tag, parent, combinator) => {
293
312
  pseudo = `:${match[2]}(${pseudo})`;
294
313
  return {
295
314
  matcher: input.slice(match[0].length),
296
- selector: (s) => rawRe.test(s) ? s.replace(rawRe, `${parent}${pseudo}:`) : `${parent}${pseudo}${combinator}${s}`,
297
- sort: sortValue(match[3])
315
+ handle: (input2, next) => next({
316
+ ...input2,
317
+ prefix: rawRe.test(input2.prefix) ? input2.prefix.replace(rawRe, `${parent}${pseudo}:`) : `${input2.prefix}${parent}${pseudo}${combinator}`,
318
+ sort: sortValue(match[3])
319
+ })
298
320
  };
299
321
  }
300
322
  }
@@ -312,8 +334,18 @@ const variantPseudoClassesAndElements = {
312
334
  const pseudo = PseudoClasses[match[1]] || PseudoClassesColon[match[1]] || `:${match[1]}`;
313
335
  return {
314
336
  matcher: input.slice(match[0].length),
315
- selector: (s) => `${s}${pseudo}`,
316
- sort: sortValue(match[1])
337
+ handle: (input2, next) => {
338
+ const selectors = pseudo.startsWith("::") ? {
339
+ pseudo: `${input2.pseudo}${pseudo}`
340
+ } : {
341
+ selector: `${input2.selector}${pseudo}`
342
+ };
343
+ return next({
344
+ ...input2,
345
+ ...selectors,
346
+ sort: sortValue(match[1])
347
+ });
348
+ }
317
349
  };
318
350
  }
319
351
  },
@@ -374,6 +406,7 @@ const partClasses = {
374
406
  };
375
407
 
376
408
  const variants = (options) => [
409
+ variantVariables,
377
410
  variantCssLayer,
378
411
  variantSelector,
379
412
  variantInternalLayer,
@@ -392,4 +425,4 @@ const variants = (options) => [
392
425
  variantScope
393
426
  ];
394
427
 
395
- export { variantBreakpoints as a, variantCombinators as b, variantPrint as c, variantCustomMedia as d, variantColorsMediaOrClass as e, variantLanguageDirections as f, variantSelector as g, variantCssLayer as h, variantInternalLayer as i, variantScope as j, variantPseudoClassesAndElements as k, variantPseudoClassFunctions as l, variantTaggedPseudoClasses as m, variantImportant as n, variantNegative as o, partClasses as p, variants as v };
428
+ export { variantBreakpoints as a, variantCombinators as b, variantPrint as c, variantCustomMedia as d, variantColorsMediaOrClass as e, variantLanguageDirections as f, variantSelector as g, variantCssLayer as h, variantInternalLayer as i, variantScope as j, variantVariables as k, variantPseudoClassesAndElements as l, variantPseudoClassFunctions as m, variantTaggedPseudoClasses as n, variantImportant as o, partClasses as p, variantNegative as q, variants as v };
@@ -2,7 +2,7 @@
2
2
 
3
3
  const core = require('@unocss/core');
4
4
 
5
- const variantMatcher = (name, selector) => {
5
+ const variantMatcher = (name, handler) => {
6
6
  const re = new RegExp(`^${core.escapeRegExp(name)}[:-]`);
7
7
  return {
8
8
  name,
@@ -11,7 +11,10 @@ const variantMatcher = (name, selector) => {
11
11
  if (match) {
12
12
  return {
13
13
  matcher: input.slice(match[0].length),
14
- selector
14
+ handle: (input2, next) => next({
15
+ ...input2,
16
+ ...handler(input2)
17
+ })
15
18
  };
16
19
  }
17
20
  },
@@ -1,6 +1,6 @@
1
1
  import { escapeRegExp } from '@unocss/core';
2
2
 
3
- const variantMatcher = (name, selector) => {
3
+ const variantMatcher = (name, handler) => {
4
4
  const re = new RegExp(`^${escapeRegExp(name)}[:-]`);
5
5
  return {
6
6
  name,
@@ -9,7 +9,10 @@ const variantMatcher = (name, selector) => {
9
9
  if (match) {
10
10
  return {
11
11
  matcher: input.slice(match[0].length),
12
- selector
12
+ handle: (input2, next) => next({
13
+ ...input2,
14
+ ...handler(input2)
15
+ })
13
16
  };
14
17
  }
15
18
  },
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _unocss_core from '@unocss/core';
2
- import { RGBAColorValue, CSSColorValue, VariantObject } from '@unocss/core';
2
+ import { RGBAColorValue, CSSColorValue, VariantHandlerContext, VariantObject } from '@unocss/core';
3
3
  export { C as CONTROL_MINI_NO_NEGATIVE, c as colorResolver, a as colorableShadows, d as directionSize, h as hasParseableColor, p as parseColor, r as resolveBreakpoints, b as resolveVerticalBreakpoints } from './utilities-c3da10e0.js';
4
4
  import './types-2a2972f5.js';
5
5
 
@@ -76,7 +76,7 @@ declare namespace handlers {
76
76
  declare const handler: _unocss_core.ValueHandler<"number" | "auto" | "global" | "position" | "numberWithUnit" | "rem" | "px" | "percent" | "fraction" | "bracket" | "bracketOfColor" | "bracketOfLength" | "bracketOfPosition" | "cssvar" | "time" | "degree" | "properties">;
77
77
  declare const h: _unocss_core.ValueHandler<"number" | "auto" | "global" | "position" | "numberWithUnit" | "rem" | "px" | "percent" | "fraction" | "bracket" | "bracketOfColor" | "bracketOfLength" | "bracketOfPosition" | "cssvar" | "time" | "degree" | "properties">;
78
78
 
79
- declare const variantMatcher: (name: string, selector?: ((input: string) => string | undefined) | undefined) => VariantObject;
79
+ declare const variantMatcher: (name: string, handler: (input: VariantHandlerContext) => Record<string, any>) => VariantObject;
80
80
  declare const variantParentMatcher: (name: string, parent: string) => VariantObject;
81
81
 
82
82
  export { colorOpacityToString, colorToString, cornerMap, directionMap, getComponents, globalKeywords, h, handler, hex2rgba, insetMap, parseCssColor, positionMap, handlers as valueHandlers, variantMatcher, variantParentMatcher, xyzMap };
package/dist/variants.cjs CHANGED
@@ -25,4 +25,5 @@ exports.variantPseudoClassesAndElements = _default.variantPseudoClassesAndElemen
25
25
  exports.variantScope = _default.variantScope;
26
26
  exports.variantSelector = _default.variantSelector;
27
27
  exports.variantTaggedPseudoClasses = _default.variantTaggedPseudoClasses;
28
+ exports.variantVariables = _default.variantVariables;
28
29
  exports.variants = _default.variants;
@@ -22,6 +22,7 @@ declare const variantSelector: Variant;
22
22
  declare const variantCssLayer: Variant;
23
23
  declare const variantInternalLayer: Variant;
24
24
  declare const variantScope: Variant;
25
+ declare const variantVariables: Variant;
25
26
 
26
27
  declare const variantPseudoClassesAndElements: VariantObject;
27
28
  declare const variantPseudoClassFunctions: VariantObject;
@@ -32,4 +33,4 @@ declare const variantImportant: Variant;
32
33
 
33
34
  declare const variantNegative: Variant;
34
35
 
35
- export { partClasses, variantBreakpoints, variantColorsMediaOrClass, variantCombinators, variantCssLayer, variantCustomMedia, variantImportant, variantInternalLayer, variantLanguageDirections, variantNegative, variantPrint, variantPseudoClassFunctions, variantPseudoClassesAndElements, variantScope, variantSelector, variantTaggedPseudoClasses, variants };
36
+ export { partClasses, variantBreakpoints, variantColorsMediaOrClass, variantCombinators, variantCssLayer, variantCustomMedia, variantImportant, variantInternalLayer, variantLanguageDirections, variantNegative, variantPrint, variantPseudoClassFunctions, variantPseudoClassesAndElements, variantScope, variantSelector, variantTaggedPseudoClasses, variantVariables, variants };
package/dist/variants.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { p as partClasses, a as variantBreakpoints, e as variantColorsMediaOrClass, b as variantCombinators, h as variantCssLayer, d as variantCustomMedia, n as variantImportant, i as variantInternalLayer, f as variantLanguageDirections, o as variantNegative, c as variantPrint, l as variantPseudoClassFunctions, k as variantPseudoClassesAndElements, j as variantScope, g as variantSelector, m as variantTaggedPseudoClasses, v as variants } from './chunks/default3.mjs';
1
+ export { p as partClasses, a as variantBreakpoints, e as variantColorsMediaOrClass, b as variantCombinators, h as variantCssLayer, d as variantCustomMedia, o as variantImportant, i as variantInternalLayer, f as variantLanguageDirections, q as variantNegative, c as variantPrint, m as variantPseudoClassFunctions, l as variantPseudoClassesAndElements, j as variantScope, g as variantSelector, n as variantTaggedPseudoClasses, k as variantVariables, v as variants } from './chunks/default3.mjs';
2
2
  import './chunks/utilities.mjs';
3
3
  import '@unocss/core';
4
4
  import './chunks/variants.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/preset-mini",
3
- "version": "0.39.1",
3
+ "version": "0.40.0",
4
4
  "description": "The minimal preset for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -61,7 +61,7 @@
61
61
  "*.css"
62
62
  ],
63
63
  "dependencies": {
64
- "@unocss/core": "0.39.1"
64
+ "@unocss/core": "0.40.0"
65
65
  },
66
66
  "scripts": {
67
67
  "build": "unbuild",