@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.
@@ -37,10 +37,13 @@ const variantBreakpoints = (matcher, _, theme) => {
37
37
  }
38
38
  };
39
39
 
40
- const variantChildren = [
41
- variants$1.variantMatcher("children", (input) => `${input} > *`),
40
+ const variantCombinators = [
42
41
  variants$1.variantMatcher("all", (input) => `${input} *`),
43
- variants$1.variantMatcher("next", (input) => `${input}+*`)
42
+ variants$1.variantMatcher("children", (input) => `${input}>*`),
43
+ variants$1.variantMatcher("next", (input) => `${input}+*`),
44
+ variants$1.variantMatcher("sibling", (input) => `${input}+*`),
45
+ variants$1.variantMatcher("siblings", (input) => `${input}~*`),
46
+ variants$1.variantMatcher("svg", (input) => `${input} svg *`)
44
47
  ];
45
48
 
46
49
  const variantColorsClass = [
@@ -110,20 +113,23 @@ const variantSpace = (matcher) => {
110
113
  }
111
114
  };
112
115
 
113
- const variants = [
116
+ const variants = (options) => [
114
117
  variantSpace,
115
118
  variantNegative,
116
119
  variantImportant,
117
120
  variantBreakpoints,
118
- ...variantChildren,
121
+ ...variantCombinators,
119
122
  pseudo.variantPseudoClasses,
120
- pseudo.variantPseudoElements
123
+ pseudo.variantTaggedPseudoClasses(options),
124
+ pseudo.variantPseudoElements,
125
+ pseudo.partClasses,
126
+ ...options.dark === "media" ? variantColorsMedia : variantColorsClass
121
127
  ];
122
128
 
123
129
  exports.variantBreakpoints = variantBreakpoints;
124
- exports.variantChildren = variantChildren;
125
130
  exports.variantColorsClass = variantColorsClass;
126
131
  exports.variantColorsMedia = variantColorsMedia;
132
+ exports.variantCombinators = variantCombinators;
127
133
  exports.variantImportant = variantImportant;
128
134
  exports.variantNegative = variantNegative;
129
135
  exports.variantSpace = variantSpace;
@@ -1,5 +1,5 @@
1
1
  import { v as variantMatcher } from './variants.mjs';
2
- import { v as variantPseudoClasses, a as variantPseudoElements } from './pseudo.mjs';
2
+ import { v as variantPseudoClasses, a as variantTaggedPseudoClasses, b as variantPseudoElements, p as partClasses } from './pseudo.mjs';
3
3
 
4
4
  const regexCache = {};
5
5
  const variantBreakpoints = (matcher, _, theme) => {
@@ -35,10 +35,13 @@ const variantBreakpoints = (matcher, _, theme) => {
35
35
  }
36
36
  };
37
37
 
38
- const variantChildren = [
39
- variantMatcher("children", (input) => `${input} > *`),
38
+ const variantCombinators = [
40
39
  variantMatcher("all", (input) => `${input} *`),
41
- variantMatcher("next", (input) => `${input}+*`)
40
+ variantMatcher("children", (input) => `${input}>*`),
41
+ variantMatcher("next", (input) => `${input}+*`),
42
+ variantMatcher("sibling", (input) => `${input}+*`),
43
+ variantMatcher("siblings", (input) => `${input}~*`),
44
+ variantMatcher("svg", (input) => `${input} svg *`)
42
45
  ];
43
46
 
44
47
  const variantColorsClass = [
@@ -108,14 +111,17 @@ const variantSpace = (matcher) => {
108
111
  }
109
112
  };
110
113
 
111
- const variants = [
114
+ const variants = (options) => [
112
115
  variantSpace,
113
116
  variantNegative,
114
117
  variantImportant,
115
118
  variantBreakpoints,
116
- ...variantChildren,
119
+ ...variantCombinators,
117
120
  variantPseudoClasses,
118
- variantPseudoElements
121
+ variantTaggedPseudoClasses(options),
122
+ variantPseudoElements,
123
+ partClasses,
124
+ ...options.dark === "media" ? variantColorsMedia : variantColorsClass
119
125
  ];
120
126
 
121
- 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 };
127
+ export { variantBreakpoints as a, variantCombinators as b, variantColorsClass as c, variantColorsMedia as d, variantImportant as e, variantNegative as f, variantSpace as g, variants as v };
@@ -2,66 +2,86 @@
2
2
 
3
3
  const core = require('@unocss/core');
4
4
 
5
- const CONTROL_BYPASS_PSEUDO = "$$no-pseudo";
5
+ const CONTROL_BYPASS_PSEUDO_CLASS = "$$no-pseudo";
6
6
  const PseudoClasses = Object.fromEntries([
7
+ "any-link",
8
+ "link",
9
+ "visited",
10
+ "target",
11
+ "hover",
7
12
  "active",
8
- "checked",
9
- "default",
10
- "empty",
11
- "enabled",
12
- "disabled",
13
- "first-of-type",
14
- ["first", "first-child"],
15
13
  "focus-visible",
16
14
  "focus-within",
17
15
  "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",
16
+ "autofill",
17
+ "enabled",
18
+ "disabled",
28
19
  "read-only",
29
20
  "read-write",
21
+ "placeholder-shown",
22
+ "default",
23
+ "checked",
24
+ "indeterminate",
25
+ "valid",
26
+ "invalid",
30
27
  "required",
28
+ "optional",
31
29
  "root",
32
- "target",
33
- "valid",
34
- "visited",
30
+ "empty",
35
31
  ["even-of-type", "nth-of-type(even)"],
36
32
  ["even", "nth-child(even)"],
37
33
  ["odd-of-type", "nth-of-type(odd)"],
38
- ["odd", "nth-child(odd)"]
34
+ ["odd", "nth-child(odd)"],
35
+ "first-of-type",
36
+ ["first", "first-child"],
37
+ "last-of-type",
38
+ ["last", "last-child"],
39
+ "only-child",
40
+ "only-of-type"
39
41
  ].map(core.toArray));
40
42
  const PseudoElements = [
43
+ "placeholder",
41
44
  "before",
42
45
  "after",
43
46
  "first-letter",
44
47
  "first-line",
45
48
  "selection"
46
49
  ];
50
+ const PartClassesRE = /(part-\[(.+)]:)(.+)/;
47
51
  const PseudoElementsRE = new RegExp(`^(${PseudoElements.join("|")})[:-]`);
48
52
  const PseudoClassesStr = Object.keys(PseudoClasses).join("|");
49
53
  const PseudoClassesRE = new RegExp(`^(${PseudoClassesStr})[:-]`);
50
54
  const PseudoClassesNotRE = new RegExp(`^not-(${PseudoClassesStr})[:-]`);
51
- const PseudoClassesGroupRE = new RegExp(`^group-(${PseudoClassesStr})[:-]`);
52
- const PseudoClassesPeerRE = new RegExp(`^peer-(${PseudoClassesStr})[:-]`);
55
+ function shouldAdd(entires) {
56
+ return !entires.find((i) => i[0] === CONTROL_BYPASS_PSEUDO_CLASS) || void 0;
57
+ }
58
+ function taggedPseudoClassMatcher(tag, parent, combinator) {
59
+ const re = new RegExp(`^${tag}-((not-)?(${PseudoClassesStr}))[:-]`);
60
+ const rawRe = new RegExp(`^${core.escapeRegExp(parent)}:`);
61
+ return (input) => {
62
+ const match = input.match(re);
63
+ if (match) {
64
+ let pseudo = PseudoClasses[match[3]] || match[3];
65
+ if (match[2])
66
+ pseudo = `not(:${pseudo})`;
67
+ return {
68
+ matcher: input.slice(match[1].length + tag.length + 2),
69
+ selector: (s, body) => {
70
+ return shouldAdd(body) && rawRe.test(s) ? s.replace(rawRe, `${parent}:${pseudo}:`) : `${parent}:${pseudo}${combinator}${s}`;
71
+ }
72
+ };
73
+ }
74
+ };
75
+ }
53
76
  const variantPseudoElements = (input) => {
54
77
  const match = input.match(PseudoElementsRE);
55
78
  if (match) {
56
79
  return {
57
80
  matcher: input.slice(match[1].length + 1),
58
- selector: (s, body) => shouldAdd(body) && `${s}::${match[1]}`
81
+ selector: (s) => `${s}::${match[1]}`
59
82
  };
60
83
  }
61
84
  };
62
- function shouldAdd(entires) {
63
- return !entires.find((i) => i[0] === CONTROL_BYPASS_PSEUDO) || void 0;
64
- }
65
85
  const variantPseudoClasses = {
66
86
  match: (input) => {
67
87
  let match = input.match(PseudoClassesRE);
@@ -80,27 +100,40 @@ const variantPseudoClasses = {
80
100
  selector: (s, body) => shouldAdd(body) && `${s}:not(:${pseudo})`
81
101
  };
82
102
  }
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);
103
+ },
104
+ multiPass: true
105
+ };
106
+ const variantTaggedPseudoClasses = (options = {}) => ({
107
+ match: (input) => {
108
+ const attributify = !!options?.attributifyPseudo;
109
+ const g = taggedPseudoClassMatcher("group", attributify ? '[group=""]' : ".group", " ")(input);
110
+ if (g)
111
+ return g;
112
+ const p = taggedPseudoClassMatcher("peer", attributify ? '[peer=""]' : ".peer", "~")(input);
113
+ if (p)
114
+ return p;
115
+ },
116
+ multiPass: true
117
+ });
118
+ const partClasses = {
119
+ match: (input) => {
120
+ const match = input.match(PartClassesRE);
92
121
  if (match) {
93
- const pseudo = PseudoClasses[match[1]] || match[1];
122
+ const part = `part(${match[2]})`;
94
123
  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}`
124
+ matcher: input.slice(match[1].length),
125
+ selector: (s, body) => {
126
+ return shouldAdd(body) && `${s}::${part}`;
127
+ }
97
128
  };
98
129
  }
99
130
  },
100
131
  multiPass: true
101
132
  };
102
133
 
103
- exports.CONTROL_BYPASS_PSEUDO = CONTROL_BYPASS_PSEUDO;
134
+ exports.CONTROL_BYPASS_PSEUDO_CLASS = CONTROL_BYPASS_PSEUDO_CLASS;
104
135
  exports.PseudoClasses = PseudoClasses;
136
+ exports.partClasses = partClasses;
105
137
  exports.variantPseudoClasses = variantPseudoClasses;
106
138
  exports.variantPseudoElements = variantPseudoElements;
139
+ exports.variantTaggedPseudoClasses = variantTaggedPseudoClasses;
@@ -1,65 +1,85 @@
1
- import { toArray } from '@unocss/core';
1
+ import { toArray, escapeRegExp } from '@unocss/core';
2
2
 
3
- const CONTROL_BYPASS_PSEUDO = "$$no-pseudo";
3
+ const CONTROL_BYPASS_PSEUDO_CLASS = "$$no-pseudo";
4
4
  const PseudoClasses = Object.fromEntries([
5
+ "any-link",
6
+ "link",
7
+ "visited",
8
+ "target",
9
+ "hover",
5
10
  "active",
6
- "checked",
7
- "default",
8
- "empty",
9
- "enabled",
10
- "disabled",
11
- "first-of-type",
12
- ["first", "first-child"],
13
11
  "focus-visible",
14
12
  "focus-within",
15
13
  "focus",
16
- "hover",
17
- "indeterminate",
18
- "invalid",
19
- "last-of-type",
20
- ["last", "last-child"],
21
- "link",
22
- "only-child",
23
- "only-of-type",
24
- "optional",
25
- "placeholder-shown",
14
+ "autofill",
15
+ "enabled",
16
+ "disabled",
26
17
  "read-only",
27
18
  "read-write",
19
+ "placeholder-shown",
20
+ "default",
21
+ "checked",
22
+ "indeterminate",
23
+ "valid",
24
+ "invalid",
28
25
  "required",
26
+ "optional",
29
27
  "root",
30
- "target",
31
- "valid",
32
- "visited",
28
+ "empty",
33
29
  ["even-of-type", "nth-of-type(even)"],
34
30
  ["even", "nth-child(even)"],
35
31
  ["odd-of-type", "nth-of-type(odd)"],
36
- ["odd", "nth-child(odd)"]
32
+ ["odd", "nth-child(odd)"],
33
+ "first-of-type",
34
+ ["first", "first-child"],
35
+ "last-of-type",
36
+ ["last", "last-child"],
37
+ "only-child",
38
+ "only-of-type"
37
39
  ].map(toArray));
38
40
  const PseudoElements = [
41
+ "placeholder",
39
42
  "before",
40
43
  "after",
41
44
  "first-letter",
42
45
  "first-line",
43
46
  "selection"
44
47
  ];
48
+ const PartClassesRE = /(part-\[(.+)]:)(.+)/;
45
49
  const PseudoElementsRE = new RegExp(`^(${PseudoElements.join("|")})[:-]`);
46
50
  const PseudoClassesStr = Object.keys(PseudoClasses).join("|");
47
51
  const PseudoClassesRE = new RegExp(`^(${PseudoClassesStr})[:-]`);
48
52
  const PseudoClassesNotRE = new RegExp(`^not-(${PseudoClassesStr})[:-]`);
49
- const PseudoClassesGroupRE = new RegExp(`^group-(${PseudoClassesStr})[:-]`);
50
- const PseudoClassesPeerRE = new RegExp(`^peer-(${PseudoClassesStr})[:-]`);
53
+ function shouldAdd(entires) {
54
+ return !entires.find((i) => i[0] === CONTROL_BYPASS_PSEUDO_CLASS) || void 0;
55
+ }
56
+ function taggedPseudoClassMatcher(tag, parent, combinator) {
57
+ const re = new RegExp(`^${tag}-((not-)?(${PseudoClassesStr}))[:-]`);
58
+ const rawRe = new RegExp(`^${escapeRegExp(parent)}:`);
59
+ return (input) => {
60
+ const match = input.match(re);
61
+ if (match) {
62
+ let pseudo = PseudoClasses[match[3]] || match[3];
63
+ if (match[2])
64
+ pseudo = `not(:${pseudo})`;
65
+ return {
66
+ matcher: input.slice(match[1].length + tag.length + 2),
67
+ selector: (s, body) => {
68
+ return shouldAdd(body) && rawRe.test(s) ? s.replace(rawRe, `${parent}:${pseudo}:`) : `${parent}:${pseudo}${combinator}${s}`;
69
+ }
70
+ };
71
+ }
72
+ };
73
+ }
51
74
  const variantPseudoElements = (input) => {
52
75
  const match = input.match(PseudoElementsRE);
53
76
  if (match) {
54
77
  return {
55
78
  matcher: input.slice(match[1].length + 1),
56
- selector: (s, body) => shouldAdd(body) && `${s}::${match[1]}`
79
+ selector: (s) => `${s}::${match[1]}`
57
80
  };
58
81
  }
59
82
  };
60
- function shouldAdd(entires) {
61
- return !entires.find((i) => i[0] === CONTROL_BYPASS_PSEUDO) || void 0;
62
- }
63
83
  const variantPseudoClasses = {
64
84
  match: (input) => {
65
85
  let match = input.match(PseudoClassesRE);
@@ -78,24 +98,35 @@ const variantPseudoClasses = {
78
98
  selector: (s, body) => shouldAdd(body) && `${s}:not(:${pseudo})`
79
99
  };
80
100
  }
81
- match = input.match(PseudoClassesGroupRE);
82
- if (match) {
83
- const pseudo = PseudoClasses[match[1]] || match[1];
84
- return {
85
- matcher: input.slice(match[1].length + 7),
86
- selector: (s, body) => shouldAdd(body) && s.includes(".group:") ? s.replace(/\.group:/, `.group:${pseudo}:`) : `.group:${pseudo} ${s}`
87
- };
88
- }
89
- match = input.match(PseudoClassesPeerRE);
101
+ },
102
+ multiPass: true
103
+ };
104
+ const variantTaggedPseudoClasses = (options = {}) => ({
105
+ match: (input) => {
106
+ const attributify = !!options?.attributifyPseudo;
107
+ const g = taggedPseudoClassMatcher("group", attributify ? '[group=""]' : ".group", " ")(input);
108
+ if (g)
109
+ return g;
110
+ const p = taggedPseudoClassMatcher("peer", attributify ? '[peer=""]' : ".peer", "~")(input);
111
+ if (p)
112
+ return p;
113
+ },
114
+ multiPass: true
115
+ });
116
+ const partClasses = {
117
+ match: (input) => {
118
+ const match = input.match(PartClassesRE);
90
119
  if (match) {
91
- const pseudo = PseudoClasses[match[1]] || match[1];
120
+ const part = `part(${match[2]})`;
92
121
  return {
93
- matcher: input.slice(match[1].length + 6),
94
- selector: (s, body) => shouldAdd(body) && s.includes(".peer:") ? s.replace(/\.peer:/, `.peer:${pseudo}:`) : `.peer:${pseudo} ~ ${s}`
122
+ matcher: input.slice(match[1].length),
123
+ selector: (s, body) => {
124
+ return shouldAdd(body) && `${s}::${part}`;
125
+ }
95
126
  };
96
127
  }
97
128
  },
98
129
  multiPass: true
99
130
  };
100
131
 
101
- export { CONTROL_BYPASS_PSEUDO as C, PseudoClasses as P, variantPseudoElements as a, variantPseudoClasses as v };
132
+ export { CONTROL_BYPASS_PSEUDO_CLASS as C, PseudoClasses as P, variantTaggedPseudoClasses as a, variantPseudoElements as b, partClasses as p, variantPseudoClasses as v };