-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
types.ts
190 lines (172 loc) · 4.82 KB
/
types.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import type { Awaitable } from '@antfu/utils';
import type { FullIconCustomisations } from '../customisations/defaults';
import type { IconifyJSON } from '@iconify/types';
/**
* External package name.
*
* You can use scoped packages, for example, `@my-collections/collection-a` or normal packages `my-awaesome-collection`.
*/
export type ExternalPkgName = string | [scope: string, collection: string];
/**
* Type for universal icon loader.
*/
export type UniversalIconLoader = (
collection: string,
icon: string,
options?: IconifyLoaderOptions
) => Promise<string | undefined>;
/**
* Custom icon loader, used by `getCustomIcon`.
*/
export type CustomIconLoader = (name: string) => Awaitable<string | undefined>;
/**
* Auto-install options
*/
export type AutoInstall =
| boolean
| ((name: string) => Promise<void | undefined>);
/**
* Custom icon customizer, it will allow to customize all icons on a collection or individual icons.
*/
export type IconCustomizer = (
collection: string,
icon: string,
props: Record<string, string>
) => Awaitable<void>;
/**
* Icon customizations: will be applied to all resolved icons.
*
* For each loaded icon, the customizations will be applied in this order:
* - apply `transform` to raw `svg`, if provided and using custom icon collection
* - apply `customize` with default customizations, if provided
* - apply `iconCustomizer` with `customize` customizations, if provided
* - apply `additionalProps` with `iconCustomizer` customizations, if provided
* - apply `trimSVG` to the final `SVG` only when using custom icon collection and `trimCustomSvg` enabled
*/
export type IconCustomizations = {
/**
* Transform raw `svg`.
*
* **WARNING**: `transform` will be only applied when using `custom` icon collection: it will be applied only when using `getCustomIcon` and excluded when using `searchForIcon`.
*
* @param svg The loaded `svg`
* @param collection The name of the collection
* @param icon The name of the icon
* @return The transformed `svg`.
*/
transform?: (
svg: string,
collection: string,
icon: string
) => Awaitable<string>;
/**
* Change default icon customizations values.
*
* @param defaultCustomizations Default icon's customizations values.
* @return The modified icon's customizations values.
*/
customize?: (
defaultCustomizations: FullIconCustomisations
) => FullIconCustomisations;
/**
* Custom icon customizer.
*/
iconCustomizer?: IconCustomizer;
/**
* Additional icon properties.
*
* All properties without value will not be applied.
*/
additionalProps?: Record<string, string | undefined>;
/**
* Should optimize the custom `svg` icon?.
*
* Enable this flag when using custom `SVG` on `CSS`.
*
* @default `false`.
*/
trimCustomSvg?: boolean;
};
/**
* List of icons as object. Key is the icon name, the value is the icon data or callback (can be async) to get icon data
*/
export type InlineCollection = Record<
string,
string | (() => Awaitable<string | undefined>)
>;
/**
* Collection of custom icons. Key is the collection name, the value is the loader or InlineCollection object
*/
export type CustomCollections = Record<
string,
CustomIconLoader | InlineCollection
>;
/**
* Options to use with the modern loader.
*/
export type IconifyLoaderOptions = {
/**
* Emit warning when missing icons are matched
*/
warn?: string;
/**
* Add svg and xlink xml namespace when necessary.
*
* @default false
*/
addXmlNs?: boolean;
/**
* Scale of icons against 1em
*/
scale?: number;
/**
* Style to apply to icons by default
*
* @default ''
*/
defaultStyle?: string;
/**
* Class names to apply to icons by default
*
* @default ''
*/
defaultClass?: string;
/**
* Loader for custom loaders
*/
customCollections?: Record<
string,
| (() => Awaitable<IconifyJSON>)
| undefined
| CustomIconLoader
| InlineCollection
>;
/**
* Icon customizer
*/
customizations?: IconCustomizations;
/**
* Auto install icon sources package when the usages is detected
*
* **WARNING**: only on `node` environment, on `browser` this option will be ignored
*
* @default false
*/
autoInstall?: AutoInstall;
/**
* The additional icon properties applied to the svg.
*
* The `width` and `height` will not be set to the `svg` if already present on it, and so, the `width` and `height` will be those you configure on the customizations.
* If you omit the `width/height/scale` options and the `svg` contains the `width` and/or `height`, then, both will be extracted from the `svg`.
*
* If you need that properties just add an empty object here, useful for example when using the `svg` on `CSS`.
*/
usedProps?: Record<string, string>;
/**
* Current working directory, used to resolve the @iconify-json package.
*
* Only used on `node` environment.
* @default process.cwd()
*/
cwd?: string;
};