-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathunocss.ts
42 lines (39 loc) · 1.32 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
31
32
33
34
35
36
37
38
39
40
41
42
import { createGenerator, type UserConfig } from "@unocss/core";
import type { AtomicCSSEngine, Plugin } from "../server/types.ts";
export type UnoConfig = UserConfig & { test?: RegExp; resetCSS?: boolean };
export function UnoCSS(config?: UnoConfig): AtomicCSSEngine {
if (!Array.isArray(config?.presets)) {
throw new Error("UnoCSS: `presets` must be an array.");
}
const generator = createGenerator(config);
if (config?.test) {
Reflect.set(generator, "test", config?.test);
}
if (config?.test instanceof RegExp) {
Reflect.set(generator, "test", config.test);
}
if (config?.resetCSS !== false) {
Reflect.set(
generator,
"resetCSS",
`https://esm.sh/@unocss/reset@${generator.version}/tailwind.css`,
);
}
Reflect.set(generator, "name", "UnoCSS");
return generator;
}
export default function UnoCSSPlugin(config: UnoConfig): Plugin;
export default function UnoCSSPlugin(test: RegExp, config: UnoConfig): Plugin;
export default function UnoCSSPlugin(testOrConfig: RegExp | UnoConfig, config?: UnoConfig): Plugin {
return {
name: "unocss",
setup(aleph) {
const isRegexp = testOrConfig instanceof RegExp;
config = isRegexp ? config ?? {} : testOrConfig;
if (isRegexp) {
config.test = testOrConfig;
}
aleph.atomicCSS = UnoCSS(config);
},
};
}