@unocss/preset-mini 0.20.1 → 0.21.1

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.
@@ -46,23 +46,22 @@ const variantCombinators = [
46
46
  variants$1.variantMatcher("svg", (input) => `${input} svg *`)
47
47
  ];
48
48
 
49
- const variantColorsMediaOrClass = [
50
- (v, { options: { dark } }) => {
51
- if (dark === "class")
52
- return variants$1.variantMatcher("dark", (input) => `.dark $$ ${input}`)(v);
53
- },
54
- (v, { options: { dark } }) => {
55
- if (dark === "class")
56
- return variants$1.variantMatcher("light", (input) => `.light $$ ${input}`)(v);
57
- },
58
- (v, { options: { dark } }) => {
59
- if (dark === "media")
60
- return variants$1.variantParentMatcher("dark", "@media (prefers-color-scheme: dark)")(v);
61
- },
62
- (v, { options: { dark } }) => {
63
- if (dark === "media")
64
- return variants$1.variantParentMatcher("light", "@media (prefers-color-scheme: light)")(v);
49
+ const variantColorsMediaOrClass = (options = {}) => {
50
+ if (options?.dark === "class") {
51
+ return [
52
+ variants$1.variantMatcher("dark", (input) => `.dark $$ ${input}`),
53
+ variants$1.variantMatcher("light", (input) => `.light $$ ${input}`)
54
+ ];
65
55
  }
56
+ return [
57
+ variants$1.variantParentMatcher("dark", "@media (prefers-color-scheme: dark)"),
58
+ variants$1.variantParentMatcher("light", "@media (prefers-color-scheme: light)")
59
+ ];
60
+ };
61
+
62
+ const variantLanguageDirections = [
63
+ variants$1.variantMatcher("rtl", (input) => `[dir="rtl"] $$ ${input}`),
64
+ variants$1.variantMatcher("ltr", (input) => `[dir="ltr"] $$ ${input}`)
66
65
  ];
67
66
 
68
67
  const variantImportant = {
@@ -98,39 +97,43 @@ const variantNegative = {
98
97
  }
99
98
  }
100
99
  };
101
- const variantSpace = (matcher) => {
102
- if (/^space-?([xy])-?(-?.+)$/.test(matcher) || /^divide-/.test(matcher)) {
103
- return {
104
- matcher,
105
- selector: (input) => {
106
- return `${input}>:not([hidden])~:not([hidden])`;
107
- }
108
- };
109
- }
110
- };
100
+
101
+ const variantMotions = [
102
+ variants$1.variantParentMatcher("motion-reduce", "@media (prefers-reduced-motion: reduce)"),
103
+ variants$1.variantParentMatcher("motion-safe", "@media (prefers-reduced-motion: no-preference)")
104
+ ];
105
+
106
+ const variantOrientations = [
107
+ variants$1.variantParentMatcher("landscape", "@media (orientation: landscape)"),
108
+ variants$1.variantParentMatcher("portrait", "@media (orientation: portrait)")
109
+ ];
111
110
 
112
111
  const variantPrint = variants$1.variantParentMatcher("print", "@media print");
113
112
 
114
- const variants = [
115
- variantSpace,
113
+ const variants = (options) => [
116
114
  variantNegative,
117
115
  variantImportant,
118
116
  variantPrint,
117
+ ...variantOrientations,
118
+ ...variantMotions,
119
119
  variantBreakpoints,
120
120
  ...variantCombinators,
121
121
  pseudo.variantPseudoClasses,
122
122
  pseudo.variantPseudoClassFunctions,
123
- pseudo.variantTaggedPseudoClasses,
123
+ ...pseudo.variantTaggedPseudoClasses(options),
124
124
  pseudo.variantPseudoElements,
125
125
  pseudo.partClasses,
126
- ...variantColorsMediaOrClass
126
+ ...variantColorsMediaOrClass(options),
127
+ ...variantLanguageDirections
127
128
  ];
128
129
 
129
130
  exports.variantBreakpoints = variantBreakpoints;
130
131
  exports.variantColorsMediaOrClass = variantColorsMediaOrClass;
131
132
  exports.variantCombinators = variantCombinators;
132
133
  exports.variantImportant = variantImportant;
134
+ exports.variantLanguageDirections = variantLanguageDirections;
135
+ exports.variantMotions = variantMotions;
133
136
  exports.variantNegative = variantNegative;
137
+ exports.variantOrientations = variantOrientations;
134
138
  exports.variantPrint = variantPrint;
135
- exports.variantSpace = variantSpace;
136
139
  exports.variants = variants;
@@ -44,23 +44,22 @@ const variantCombinators = [
44
44
  variantMatcher("svg", (input) => `${input} svg *`)
45
45
  ];
46
46
 
47
- const variantColorsMediaOrClass = [
48
- (v, { options: { dark } }) => {
49
- if (dark === "class")
50
- return variantMatcher("dark", (input) => `.dark $$ ${input}`)(v);
51
- },
52
- (v, { options: { dark } }) => {
53
- if (dark === "class")
54
- return variantMatcher("light", (input) => `.light $$ ${input}`)(v);
55
- },
56
- (v, { options: { dark } }) => {
57
- if (dark === "media")
58
- return variantParentMatcher("dark", "@media (prefers-color-scheme: dark)")(v);
59
- },
60
- (v, { options: { dark } }) => {
61
- if (dark === "media")
62
- return variantParentMatcher("light", "@media (prefers-color-scheme: light)")(v);
47
+ const variantColorsMediaOrClass = (options = {}) => {
48
+ if (options?.dark === "class") {
49
+ return [
50
+ variantMatcher("dark", (input) => `.dark $$ ${input}`),
51
+ variantMatcher("light", (input) => `.light $$ ${input}`)
52
+ ];
63
53
  }
54
+ return [
55
+ variantParentMatcher("dark", "@media (prefers-color-scheme: dark)"),
56
+ variantParentMatcher("light", "@media (prefers-color-scheme: light)")
57
+ ];
58
+ };
59
+
60
+ const variantLanguageDirections = [
61
+ variantMatcher("rtl", (input) => `[dir="rtl"] $$ ${input}`),
62
+ variantMatcher("ltr", (input) => `[dir="ltr"] $$ ${input}`)
64
63
  ];
65
64
 
66
65
  const variantImportant = {
@@ -96,32 +95,34 @@ const variantNegative = {
96
95
  }
97
96
  }
98
97
  };
99
- const variantSpace = (matcher) => {
100
- if (/^space-?([xy])-?(-?.+)$/.test(matcher) || /^divide-/.test(matcher)) {
101
- return {
102
- matcher,
103
- selector: (input) => {
104
- return `${input}>:not([hidden])~:not([hidden])`;
105
- }
106
- };
107
- }
108
- };
98
+
99
+ const variantMotions = [
100
+ variantParentMatcher("motion-reduce", "@media (prefers-reduced-motion: reduce)"),
101
+ variantParentMatcher("motion-safe", "@media (prefers-reduced-motion: no-preference)")
102
+ ];
103
+
104
+ const variantOrientations = [
105
+ variantParentMatcher("landscape", "@media (orientation: landscape)"),
106
+ variantParentMatcher("portrait", "@media (orientation: portrait)")
107
+ ];
109
108
 
110
109
  const variantPrint = variantParentMatcher("print", "@media print");
111
110
 
112
- const variants = [
113
- variantSpace,
111
+ const variants = (options) => [
114
112
  variantNegative,
115
113
  variantImportant,
116
114
  variantPrint,
115
+ ...variantOrientations,
116
+ ...variantMotions,
117
117
  variantBreakpoints,
118
118
  ...variantCombinators,
119
119
  variantPseudoClasses,
120
120
  variantPseudoClassFunctions,
121
- variantTaggedPseudoClasses,
121
+ ...variantTaggedPseudoClasses(options),
122
122
  variantPseudoElements,
123
123
  partClasses,
124
- ...variantColorsMediaOrClass
124
+ ...variantColorsMediaOrClass(options),
125
+ ...variantLanguageDirections
125
126
  ];
126
127
 
127
- export { variantBreakpoints as a, variantCombinators as b, variantColorsMediaOrClass as c, variantImportant as d, variantNegative as e, variantSpace as f, variantPrint as g, variants as v };
128
+ export { variantBreakpoints as a, variantCombinators as b, variantColorsMediaOrClass as c, variantLanguageDirections as d, variantImportant as e, variantNegative as f, variantMotions as g, variantOrientations as h, variantPrint as i, variants as v };
@@ -8,6 +8,7 @@ const PseudoClasses = Object.fromEntries([
8
8
  "link",
9
9
  "visited",
10
10
  "target",
11
+ ["open", "[open]"],
11
12
  "hover",
12
13
  "active",
13
14
  "focus-visible",
@@ -24,39 +25,44 @@ const PseudoClasses = Object.fromEntries([
24
25
  "indeterminate",
25
26
  "valid",
26
27
  "invalid",
28
+ "in-range",
29
+ "out-of-range",
27
30
  "required",
28
31
  "optional",
29
32
  "root",
30
33
  "empty",
31
- ["even-of-type", "nth-of-type(even)"],
32
- ["even", "nth-child(even)"],
33
- ["odd-of-type", "nth-of-type(odd)"],
34
- ["odd", "nth-child(odd)"],
34
+ ["even-of-type", ":nth-of-type(even)"],
35
+ ["even", ":nth-child(even)"],
36
+ ["odd-of-type", ":nth-of-type(odd)"],
37
+ ["odd", ":nth-child(odd)"],
35
38
  "first-of-type",
36
- ["first", "first-child"],
39
+ ["first", ":first-child"],
37
40
  "last-of-type",
38
- ["last", "last-child"],
41
+ ["last", ":last-child"],
39
42
  "only-child",
40
43
  "only-of-type"
41
44
  ].map(core.toArray));
42
- const PseudoElements = [
45
+ const PseudoElements = Object.fromEntries([
43
46
  "placeholder",
44
47
  "before",
45
48
  "after",
46
49
  "first-letter",
47
50
  "first-line",
48
- "selection"
49
- ];
51
+ "selection",
52
+ "marker",
53
+ ["file", "::file-selector-button"]
54
+ ].map(core.toArray));
50
55
  const PseudoClassFunctions = [
51
56
  "not",
52
57
  "is",
53
58
  "where",
54
59
  "has"
55
60
  ];
56
- const PartClassesRE = /(part-\[(.+)]:)(.+)/;
57
- const PseudoElementsRE = new RegExp(`^(${PseudoElements.join("|")})[:-]`);
61
+ const PseudoElementsStr = Object.keys(PseudoElements).join("|");
58
62
  const PseudoClassesStr = Object.keys(PseudoClasses).join("|");
59
63
  const PseudoClassFunctionsStr = PseudoClassFunctions.join("|");
64
+ const PartClassesRE = /(part-\[(.+)]:)(.+)/;
65
+ const PseudoElementsRE = new RegExp(`^(${PseudoElementsStr})[:-]`);
60
66
  const PseudoClassesRE = new RegExp(`^(${PseudoClassesStr})[:-]`);
61
67
  const PseudoClassFunctionsRE = new RegExp(`^(${PseudoClassFunctionsStr})-(${PseudoClassesStr})[:-]`);
62
68
  function shouldAdd(entires) {
@@ -68,13 +74,13 @@ const taggedPseudoClassMatcher = (tag, parent, combinator) => {
68
74
  return (input) => {
69
75
  const match = input.match(re);
70
76
  if (match) {
71
- let pseudo = PseudoClasses[match[3]] || match[3];
77
+ let pseudo = PseudoClasses[match[3]] || `:${match[3]}`;
72
78
  if (match[2])
73
- pseudo = `${match[2]}(:${pseudo})`;
79
+ pseudo = `:${match[2]}(${pseudo})`;
74
80
  return {
75
81
  matcher: input.slice(match[1].length + tag.length + 2),
76
82
  selector: (s, body) => {
77
- return shouldAdd(body) && rawRe.test(s) ? s.replace(rawRe, `${parent}:${pseudo}:`) : `${parent}:${pseudo}${combinator}${s}`;
83
+ return shouldAdd(body) && rawRe.test(s) ? s.replace(rawRe, `${parent}${pseudo}:`) : `${parent}${pseudo}${combinator}${s}`;
78
84
  }
79
85
  };
80
86
  }
@@ -83,9 +89,10 @@ const taggedPseudoClassMatcher = (tag, parent, combinator) => {
83
89
  const variantPseudoElements = (input) => {
84
90
  const match = input.match(PseudoElementsRE);
85
91
  if (match) {
92
+ const pseudo = PseudoElements[match[1]] || `::${match[1]}`;
86
93
  return {
87
94
  matcher: input.slice(match[1].length + 1),
88
- selector: (s) => `${s}::${match[1]}`
95
+ selector: (s) => `${s}${pseudo}`
89
96
  };
90
97
  }
91
98
  };
@@ -93,10 +100,10 @@ const variantPseudoClasses = {
93
100
  match: (input) => {
94
101
  const match = input.match(PseudoClassesRE);
95
102
  if (match) {
96
- const pseudo = PseudoClasses[match[1]] || match[1];
103
+ const pseudo = PseudoClasses[match[1]] || `:${match[1]}`;
97
104
  return {
98
105
  matcher: input.slice(match[1].length + 1),
99
- selector: (s, body) => shouldAdd(body) && `${s}:${pseudo}`
106
+ selector: (s, body) => shouldAdd(body) && `${s}${pseudo}`
100
107
  };
101
108
  }
102
109
  },
@@ -107,25 +114,27 @@ const variantPseudoClassFunctions = {
107
114
  const match = input.match(PseudoClassFunctionsRE);
108
115
  if (match) {
109
116
  const fn = match[1];
110
- const pseudo = PseudoClasses[match[2]] || match[2];
117
+ const pseudo = PseudoClasses[match[2]] || `:${match[2]}`;
111
118
  return {
112
119
  matcher: input.slice(match[1].length + match[2].length + 2),
113
- selector: (s, body) => shouldAdd(body) && `${s}:${fn}(:${pseudo})`
120
+ selector: (s, body) => shouldAdd(body) && `${s}:${fn}(${pseudo})`
114
121
  };
115
122
  }
116
123
  },
117
124
  multiPass: true
118
125
  };
119
- const variantTaggedPseudoClasses = {
120
- match: (input, { options: { attributifyPseudo } }) => {
121
- const g = taggedPseudoClassMatcher("group", attributifyPseudo ? '[group=""]' : ".group", " ")(input);
122
- if (g)
123
- return g;
124
- const p = taggedPseudoClassMatcher("peer", attributifyPseudo ? '[peer=""]' : ".peer", "~")(input);
125
- if (p)
126
- return p;
127
- },
128
- multiPass: true
126
+ const variantTaggedPseudoClasses = (options = {}) => {
127
+ const attributify = !!options?.attributifyPseudo;
128
+ return [
129
+ {
130
+ match: taggedPseudoClassMatcher("group", attributify ? '[group=""]' : ".group", " "),
131
+ multiPass: true
132
+ },
133
+ {
134
+ match: taggedPseudoClassMatcher("peer", attributify ? '[peer=""]' : ".peer", "~"),
135
+ multiPass: true
136
+ }
137
+ ];
129
138
  };
130
139
  const partClasses = {
131
140
  match: (input) => {
@@ -6,6 +6,7 @@ const PseudoClasses = Object.fromEntries([
6
6
  "link",
7
7
  "visited",
8
8
  "target",
9
+ ["open", "[open]"],
9
10
  "hover",
10
11
  "active",
11
12
  "focus-visible",
@@ -22,39 +23,44 @@ const PseudoClasses = Object.fromEntries([
22
23
  "indeterminate",
23
24
  "valid",
24
25
  "invalid",
26
+ "in-range",
27
+ "out-of-range",
25
28
  "required",
26
29
  "optional",
27
30
  "root",
28
31
  "empty",
29
- ["even-of-type", "nth-of-type(even)"],
30
- ["even", "nth-child(even)"],
31
- ["odd-of-type", "nth-of-type(odd)"],
32
- ["odd", "nth-child(odd)"],
32
+ ["even-of-type", ":nth-of-type(even)"],
33
+ ["even", ":nth-child(even)"],
34
+ ["odd-of-type", ":nth-of-type(odd)"],
35
+ ["odd", ":nth-child(odd)"],
33
36
  "first-of-type",
34
- ["first", "first-child"],
37
+ ["first", ":first-child"],
35
38
  "last-of-type",
36
- ["last", "last-child"],
39
+ ["last", ":last-child"],
37
40
  "only-child",
38
41
  "only-of-type"
39
42
  ].map(toArray));
40
- const PseudoElements = [
43
+ const PseudoElements = Object.fromEntries([
41
44
  "placeholder",
42
45
  "before",
43
46
  "after",
44
47
  "first-letter",
45
48
  "first-line",
46
- "selection"
47
- ];
49
+ "selection",
50
+ "marker",
51
+ ["file", "::file-selector-button"]
52
+ ].map(toArray));
48
53
  const PseudoClassFunctions = [
49
54
  "not",
50
55
  "is",
51
56
  "where",
52
57
  "has"
53
58
  ];
54
- const PartClassesRE = /(part-\[(.+)]:)(.+)/;
55
- const PseudoElementsRE = new RegExp(`^(${PseudoElements.join("|")})[:-]`);
59
+ const PseudoElementsStr = Object.keys(PseudoElements).join("|");
56
60
  const PseudoClassesStr = Object.keys(PseudoClasses).join("|");
57
61
  const PseudoClassFunctionsStr = PseudoClassFunctions.join("|");
62
+ const PartClassesRE = /(part-\[(.+)]:)(.+)/;
63
+ const PseudoElementsRE = new RegExp(`^(${PseudoElementsStr})[:-]`);
58
64
  const PseudoClassesRE = new RegExp(`^(${PseudoClassesStr})[:-]`);
59
65
  const PseudoClassFunctionsRE = new RegExp(`^(${PseudoClassFunctionsStr})-(${PseudoClassesStr})[:-]`);
60
66
  function shouldAdd(entires) {
@@ -66,13 +72,13 @@ const taggedPseudoClassMatcher = (tag, parent, combinator) => {
66
72
  return (input) => {
67
73
  const match = input.match(re);
68
74
  if (match) {
69
- let pseudo = PseudoClasses[match[3]] || match[3];
75
+ let pseudo = PseudoClasses[match[3]] || `:${match[3]}`;
70
76
  if (match[2])
71
- pseudo = `${match[2]}(:${pseudo})`;
77
+ pseudo = `:${match[2]}(${pseudo})`;
72
78
  return {
73
79
  matcher: input.slice(match[1].length + tag.length + 2),
74
80
  selector: (s, body) => {
75
- return shouldAdd(body) && rawRe.test(s) ? s.replace(rawRe, `${parent}:${pseudo}:`) : `${parent}:${pseudo}${combinator}${s}`;
81
+ return shouldAdd(body) && rawRe.test(s) ? s.replace(rawRe, `${parent}${pseudo}:`) : `${parent}${pseudo}${combinator}${s}`;
76
82
  }
77
83
  };
78
84
  }
@@ -81,9 +87,10 @@ const taggedPseudoClassMatcher = (tag, parent, combinator) => {
81
87
  const variantPseudoElements = (input) => {
82
88
  const match = input.match(PseudoElementsRE);
83
89
  if (match) {
90
+ const pseudo = PseudoElements[match[1]] || `::${match[1]}`;
84
91
  return {
85
92
  matcher: input.slice(match[1].length + 1),
86
- selector: (s) => `${s}::${match[1]}`
93
+ selector: (s) => `${s}${pseudo}`
87
94
  };
88
95
  }
89
96
  };
@@ -91,10 +98,10 @@ const variantPseudoClasses = {
91
98
  match: (input) => {
92
99
  const match = input.match(PseudoClassesRE);
93
100
  if (match) {
94
- const pseudo = PseudoClasses[match[1]] || match[1];
101
+ const pseudo = PseudoClasses[match[1]] || `:${match[1]}`;
95
102
  return {
96
103
  matcher: input.slice(match[1].length + 1),
97
- selector: (s, body) => shouldAdd(body) && `${s}:${pseudo}`
104
+ selector: (s, body) => shouldAdd(body) && `${s}${pseudo}`
98
105
  };
99
106
  }
100
107
  },
@@ -105,25 +112,27 @@ const variantPseudoClassFunctions = {
105
112
  const match = input.match(PseudoClassFunctionsRE);
106
113
  if (match) {
107
114
  const fn = match[1];
108
- const pseudo = PseudoClasses[match[2]] || match[2];
115
+ const pseudo = PseudoClasses[match[2]] || `:${match[2]}`;
109
116
  return {
110
117
  matcher: input.slice(match[1].length + match[2].length + 2),
111
- selector: (s, body) => shouldAdd(body) && `${s}:${fn}(:${pseudo})`
118
+ selector: (s, body) => shouldAdd(body) && `${s}:${fn}(${pseudo})`
112
119
  };
113
120
  }
114
121
  },
115
122
  multiPass: true
116
123
  };
117
- const variantTaggedPseudoClasses = {
118
- match: (input, { options: { attributifyPseudo } }) => {
119
- const g = taggedPseudoClassMatcher("group", attributifyPseudo ? '[group=""]' : ".group", " ")(input);
120
- if (g)
121
- return g;
122
- const p = taggedPseudoClassMatcher("peer", attributifyPseudo ? '[peer=""]' : ".peer", "~")(input);
123
- if (p)
124
- return p;
125
- },
126
- multiPass: true
124
+ const variantTaggedPseudoClasses = (options = {}) => {
125
+ const attributify = !!options?.attributifyPseudo;
126
+ return [
127
+ {
128
+ match: taggedPseudoClassMatcher("group", attributify ? '[group=""]' : ".group", " "),
129
+ multiPass: true
130
+ },
131
+ {
132
+ match: taggedPseudoClassMatcher("peer", attributify ? '[peer=""]' : ".peer", "~"),
133
+ multiPass: true
134
+ }
135
+ ];
127
136
  };
128
137
  const partClasses = {
129
138
  match: (input) => {