-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuno.config.ts
85 lines (83 loc) · 2.19 KB
/
uno.config.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import {
defineConfig,
presetIcons,
presetUno,
presetAttributify,
transformerDirectives,
presetMini,
} from "unocss";
import { compareColors, stringToColor } from "@iconify/utils/lib/colors";
import type { IconifyJSON } from "@iconify/types";
import {
SVG,
cleanupSVG,
parseColors,
isEmptyColor,
importDirectory,
runSVGO,
deOptimisePaths,
} from "@iconify/tools";
export default defineConfig({
presets: [
presetIcons({
autoInstall: false,
collections: {
"custom-svg": () => loadCustomIconSet(),
},
}),
presetUno(),
presetAttributify(),
// presetMini({
// dark: "class",
// }),
],
theme: {
colors: {
background_1: "#F1F2FD",
background_2: "#F7F8FE",
primary_2: "#70708C",
primary_1: "#FF8F6B",
},
},
//TransformerDirectives auto opened?
transformers: [transformerDirectives()],
});
async function loadCustomIconSet(): Promise<IconifyJSON> {
const iconSet = await importDirectory("assets/icons", {
prefix: "svg",
});
// console.log(iconSet.list().length);
await iconSet.forEach(async (name) => {
const svg = iconSet.toSVG(name)!;
// console.log('Source svg:', svg.toString());
cleanupSVG(svg);
const blackColor = stringToColor("black")!;
await parseColors(svg, {
defaultColor: "currentColor",
callback: (attr, colorStr, color) => {
if (color && compareColors(color, blackColor)) {
return "currentColor";
}
switch (color?.type) {
case "none":
case "current":
return color;
}
// throw new Error(`Unexpected color "${colorStr}" in attribute ${attr}`);
return "currentColor";
},
});
// console.log('After Cleanup and Before Optimise:', svg.toString());
// Optimise
runSVGO(svg);
// console.log('After Optimise and Before Update paths:', svg.toString());
// Update paths for compatibility with old software
await deOptimisePaths(svg);
// console.log('After Update paths:', svg.toString());
iconSet.fromSVG(name, svg);
// console.log(iconSet);
});
// console.log(iconSet.);
// Export as IconifyJSON
return iconSet.export();
}