/
shadow.ts
30 lines (26 loc) · 1.1 KB
/
shadow.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
import type { Rule } from '@unocss/core'
import type { Theme } from '../theme'
import { colorResolver, colorableShadows, handler as h } from '../utils'
import { varEmpty } from './static'
export const boxShadowsBase = {
'--un-ring-offset-shadow': '0 0 #0000',
'--un-ring-shadow': '0 0 #0000',
'--un-shadow-inset': varEmpty,
'--un-shadow': '0 0 #0000',
}
export const boxShadows: Rule<Theme>[] = [
[/^shadow(?:-(.+))?$/, ([, d], { theme }) => {
const v = theme.boxShadow?.[d || 'DEFAULT']
if (v) {
return {
'--un-shadow': colorableShadows(v, '--un-shadow-color').join(','),
'box-shadow': 'var(--un-ring-offset-shadow, 0 0 #0000), var(--un-ring-shadow, 0 0 #0000), var(--un-shadow)',
}
}
}, { autocomplete: 'shadow-$boxShadow' }],
// color
[/^shadow-(.+)$/, colorResolver('--un-shadow-color', 'shadow'), { autocomplete: 'shadow-$colors' }],
[/^shadow-op(?:acity)?-?(.+)$/, ([, opacity]) => ({ '--un-shadow-opacity': h.bracket.percent(opacity) }), { autocomplete: 'shadow-(op|opacity)-<percent>' }],
// inset
['shadow-inset', { '--un-shadow-inset': 'inset' }],
]