/
supports.ts
34 lines (30 loc) · 977 Bytes
/
supports.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
import type { VariantContext, VariantObject } from '@unocss/core'
import type { Theme } from '../theme'
import { getComponent, handler as h } from '../utils'
export const variantSupports: VariantObject = {
name: 'supports',
match(matcher, { theme }: VariantContext<Theme>) {
if (matcher.startsWith('supports-')) {
const matcherValue = matcher.substring(9)
const [match, rest] = getComponent(matcherValue, '[', ']', ':') ?? []
if (!(match && rest && rest !== ''))
return
let supports = h.bracket(match) ?? ''
if (supports === '') {
const themeValue = theme.supports?.[match]
if (themeValue)
supports = themeValue
}
if (supports) {
return {
matcher: rest,
handle: (input, next) => next({
...input,
parent: `${input.parent ? `${input.parent} $$ ` : ''}@supports ${supports}`,
}),
}
}
}
},
multiPass: true,
}