/
preflights.ts
32 lines (28 loc) · 1.01 KB
/
preflights.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
import type { Preflight, PreflightContext } from '@unocss/core'
import { entriesToCss, toArray } from '@unocss/core'
import type { Theme } from './theme'
const wxPrefix = ['page,::before,::after']
const taroPrefix = ['*,::before,::after']
const uniappPrefix = ['uni-page-body,::before,::after']
// const defaultPrefix = ['*,::before,::after', '::backdrop']
export default function (isH5: boolean, platform: string): Preflight[] {
return [
{
layer: 'preflights',
getCSS(ctx: PreflightContext<Theme>) {
if (ctx.theme.preflightBase) {
const css = entriesToCss(Object.entries(ctx.theme.preflightBase))
let preflightRoot = ctx.theme.preflightRoot
if (!preflightRoot) {
if (isH5)
preflightRoot = platform === 'uniapp' ? uniappPrefix : taroPrefix
else
preflightRoot = wxPrefix
}
const roots = toArray(preflightRoot)
return roots.map(root => `${root}{${css}}`).join('')
}
},
},
]
}