-
Notifications
You must be signed in to change notification settings - Fork 167
/
unocss.ts
30 lines (28 loc) · 1.07 KB
/
unocss.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 { createGenerator, type UnoGenerator, type UserConfig } from "@unocss/core";
import type { AtomicCSSConfig } from "./types.ts";
type UnoConfig = UserConfig & AtomicCSSConfig;
export default function unocss(config: UnoConfig): UnoGenerator & AtomicCSSConfig;
export default function unocss(test: RegExp, config: UnoConfig): UnoGenerator & AtomicCSSConfig;
export default function unocss(
testOrConfig: RegExp | UnoConfig,
config?: UnoConfig,
): UnoGenerator & AtomicCSSConfig {
const test = testOrConfig instanceof RegExp ? testOrConfig : undefined;
config = testOrConfig instanceof RegExp ? config ?? {} : testOrConfig;
if (!Array.isArray(config.presets)) {
throw new Error("UnoCSS: `presets` must be an array.");
}
const generator = createGenerator(config);
if (test) {
Reflect.set(generator, "test", test);
}
if (config.test) {
Reflect.set(generator, "test", config.test);
}
Reflect.set(
generator,
"resetCSS",
`https://esm.sh/v108/@unocss/reset@${generator.version}/${config.resetCSS ?? "tailwind"}.css`,
);
return generator;
}