-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunocss-named-group-status.ts
62 lines (58 loc) · 1.81 KB
/
unocss-named-group-status.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { VariantObject } from 'unocss'
const parentModifiersMap: Record<string, string> = {
first: 'first-child',
last: 'last-child',
odd: 'odd',
even: 'even',
visited: 'visited',
checked: 'checked',
hover: 'hover',
'focus-within': 'focus-within',
'focus-visible': 'focus-visible',
focus: 'focus',
active: 'active',
link: 'link',
target: 'target',
'not-checked': 'not(:checked)',
default: 'default',
enabled: 'enabled',
indeterminate: 'indeterminate',
invalid: 'invalid',
valid: 'valid',
optional: 'optional',
required: 'required',
'placeholder-shown': 'placeholder-shown',
'read-only': 'read-only',
'read-write': 'read-write',
'not-disabled': 'not(:disabled)',
'first-of-type': 'first-of-type',
'not-first-of-type': 'not(:first-of-type)',
'last-of-type': 'last-of-type',
'not-last-of-type': 'not(:last-of-type)',
'not-first': 'not(:first-child)',
'not-last': 'not(:last-child)',
'only-child': 'only-child',
'not-only-child': 'not(:only-child)',
'only-of-type': 'only-of-type',
'not-only-of-type': 'not(:only-of-type)',
'even-of-type': 'nth-of-type(even)',
'odd-of-type': 'nth-of-type(odd)',
root: 'root',
empty: 'empty'
}
const parentModifiersMapStr = Object.keys(parentModifiersMap).join('|')
const parentModifierRegExp = new RegExp(`^group_(?<groupName>\\w+?)(?:-(?<groupModifier>${parentModifiersMapStr}))?:`)
export const parentNamedGroupStatusModifier: VariantObject = {
match: (matcher) => {
const m = matcher.match(parentModifierRegExp)
if (!m || !m.groups) return
const { groupName, groupModifier } = m.groups
return {
matcher: matcher.slice(m[0].length),
selector: (s) => groupModifier
? `.group_${groupName}:${parentModifiersMap[groupModifier]} ${s}`
: `.group_${groupName} ${s}`
}
},
multiPass: true
}