-
-
Notifications
You must be signed in to change notification settings - Fork 778
/
container.ts
39 lines (36 loc) · 1.21 KB
/
container.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
import type { VariantContext, VariantObject } from '@unocss/core'
import { warnOnce } from '@unocss/core'
import type { Theme } from '../theme'
import { handler as h, variantGetParameter } from '../utils'
export const variantContainerQuery: VariantObject = {
name: '@',
match(matcher, ctx: VariantContext<Theme>) {
if (matcher.startsWith('@container'))
return
const variant = variantGetParameter('@', matcher, ctx.generator.config.separators)
if (variant) {
const [match, rest, label] = variant
const unbracket = h.bracket(match)
let container: string | undefined
if (unbracket) {
const minWidth = h.numberWithUnit(unbracket)
if (minWidth)
container = `(min-width: ${minWidth})`
}
else {
container = ctx.theme.containers?.[match] ?? ''
}
if (container) {
warnOnce('The container query variant is experimental and may not follow semver.')
return {
matcher: rest,
handle: (input, next) => next({
...input,
parent: `${input.parent ? `${input.parent} $$ ` : ''}@container${label ? ` ${label} ` : ' '}${container}`,
}),
}
}
}
},
multiPass: true,
}