-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
plugins-types.d.ts
298 lines (290 loc) · 7.29 KB
/
plugins-types.d.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import type {
Plugin as PluginDef,
PluginInfo,
XastElement,
} from '../lib/types.js';
type DefaultPlugins = {
cleanupAttrs: {
newlines?: boolean;
trim?: boolean;
spaces?: boolean;
};
cleanupEnableBackground: void;
cleanupIds: {
remove?: boolean;
minify?: boolean;
preserve?: string[];
preservePrefixes?: string[];
force?: boolean;
};
cleanupNumericValues: {
floatPrecision?: number;
leadingZero?: boolean;
defaultPx?: boolean;
convertToPx?: boolean;
};
collapseGroups: void;
convertColors: {
currentColor?: boolean | string | RegExp;
names2hex?: boolean;
rgb2hex?: boolean;
convertCase?: false | 'lower' | 'upper';
shorthex?: boolean;
shortname?: boolean;
};
convertEllipseToCircle: void;
convertPathData: {
applyTransforms?: boolean;
applyTransformsStroked?: boolean;
makeArcs?: {
threshold: number;
tolerance: number;
};
straightCurves?: boolean;
convertToQ?: boolean;
lineShorthands?: boolean;
convertToZ?: boolean;
curveSmoothShorthands?: boolean;
floatPrecision?: number | false;
transformPrecision?: number;
smartArcRounding?: boolean;
removeUseless?: boolean;
collapseRepeated?: boolean;
utilizeAbsolute?: boolean;
leadingZero?: boolean;
negativeExtraSpace?: boolean;
noSpaceAfterFlags?: boolean;
forceAbsolutePath?: boolean;
};
convertShapeToPath: {
convertArcs?: boolean;
floatPrecision?: number;
};
convertTransform: {
convertToShorts?: boolean;
degPrecision?: number;
floatPrecision?: number;
transformPrecision?: number;
matrixToTransform?: boolean;
shortTranslate?: boolean;
shortScale?: boolean;
shortRotate?: boolean;
removeUseless?: boolean;
collapseIntoOne?: boolean;
leadingZero?: boolean;
negativeExtraSpace?: boolean;
};
mergeStyles: void;
inlineStyles: {
/**
* Inlines selectors that match once only.
*
* @default true
*/
onlyMatchedOnce?: boolean;
/**
* Clean up matched selectors. Unused selects are left as-is.
*
* @default true
*/
removeMatchedSelectors?: boolean;
/**
* Media queries to use. An empty string indicates all selectors outside of
* media queries.
*/
useMqs?: string[];
/**
* Pseudo-classes and elements to use. An empty string indicates all
* all non-pseudo-classes and elements.
*/
usePseudos?: string[];
};
mergePaths: {
force?: boolean;
floatPrecision?: number;
noSpaceAfterFlags?: boolean;
};
minifyStyles: {
/**
* Disable or enable a structure optimisations.
* @default true
*/
restructure?: boolean;
/**
* Enables merging of @media rules with the same media query split by other rules.
* The optimisation is unsafe in general, but should work fine in most cases. Use it on your own risk.
* @default false
*/
forceMediaMerge?: boolean;
/**
* Specify what comments to leave:
* - 'exclamation' or true – leave all exclamation comments
* - 'first-exclamation' – remove every comment except first one
* - false – remove all comments
* @default true
*/
comments?: string | boolean;
/**
* Advanced optimizations
*/
usage?:
| boolean
| {
force?: boolean;
ids?: boolean;
classes?: boolean;
tags?: boolean;
};
};
moveElemsAttrsToGroup: void;
moveGroupAttrsToElems: void;
removeComments: {
preservePatterns: Array<RegExp | string> | false;
};
removeDeprecatedAttrs: {
removeUnsafe?: boolean;
};
removeDesc: {
removeAny?: boolean;
};
removeDoctype: void;
removeEditorsNSData: {
additionalNamespaces?: string[];
};
removeEmptyAttrs: void;
removeEmptyContainers: void;
removeEmptyText: {
text?: boolean;
tspan?: boolean;
tref?: boolean;
};
removeHiddenElems: {
isHidden?: boolean;
displayNone?: boolean;
opacity0?: boolean;
circleR0?: boolean;
ellipseRX0?: boolean;
ellipseRY0?: boolean;
rectWidth0?: boolean;
rectHeight0?: boolean;
patternWidth0?: boolean;
patternHeight0?: boolean;
imageWidth0?: boolean;
imageHeight0?: boolean;
pathEmptyD?: boolean;
polylineEmptyPoints?: boolean;
polygonEmptyPoints?: boolean;
};
removeMetadata: void;
removeNonInheritableGroupAttrs: void;
removeUnknownsAndDefaults: {
unknownContent?: boolean;
unknownAttrs?: boolean;
defaultAttrs?: boolean;
/**
* If to remove XML declarations that are assigned their default value. XML
* declarations are the properties in the `<?xml … ?>` block at the top of
* the document.
*/
defaultMarkupDeclarations?: boolean;
uselessOverrides?: boolean;
keepDataAttrs?: boolean;
keepAriaAttrs?: boolean;
keepRoleAttr?: boolean;
};
removeUnusedNS: void;
removeUselessDefs: void;
removeUselessStrokeAndFill: {
stroke?: boolean;
fill?: boolean;
removeNone?: boolean;
};
removeXMLProcInst: void;
sortAttrs: {
order?: string[];
xmlnsOrder?: 'front' | 'alphabetical';
};
sortDefsChildren: void;
};
type PresetDefaultOverrides = {
[Name in keyof DefaultPlugins]?: DefaultPlugins[Name] | false;
};
export type BuiltinsWithOptionalParams = DefaultPlugins & {
'preset-default': {
floatPrecision?: number;
/**
* All default plugins can be customized or disabled here
* for example
* {
* sortAttrs: { xmlnsOrder: "alphabetical" },
* cleanupAttrs: false,
* }
*/
overrides?: PresetDefaultOverrides;
};
cleanupListOfValues: {
floatPrecision?: number;
leadingZero?: boolean;
defaultPx?: boolean;
convertToPx?: boolean;
};
convertOneStopGradients: void;
convertStyleToAttrs: {
keepImportant?: boolean;
};
prefixIds: {
prefix?:
| boolean
| string
| ((node: XastElement, info: PluginInfo) => string);
delim?: string;
prefixIds?: boolean;
prefixClassNames?: boolean;
};
removeDimensions: void;
removeOffCanvasPaths: void;
removeRasterImages: void;
removeScripts: void;
removeStyleElement: void;
removeTitle: void;
removeViewBox: void;
removeXlink: {
/**
* By default this plugin ignores legacy elements that were deprecated or
* removed in SVG 2. Set to true to force performing operations on those
* too.
*
* @default false
*/
includeLegacy: boolean;
};
removeXMLNS: void;
reusePaths: void;
};
export type BuiltinsWithRequiredParams = {
addAttributesToSVGElement: {
attribute?: string | Record<string, null | string>;
attributes?: Array<string | Record<string, null | string>>;
};
addClassesToSVGElement: {
className?: string | ((node: XastElement, info: PluginInfo) => string);
classNames?: Array<
string | ((node: XastElement, info: PluginInfo) => string)
>;
};
removeAttributesBySelector: any;
removeAttrs: {
elemSeparator?: string;
preserveCurrentColor?: boolean;
attrs: string | string[];
};
removeElementsByAttr: {
id?: string | string[];
class?: string | string[];
};
};
export type PluginsParams = BuiltinsWithOptionalParams &
BuiltinsWithRequiredParams;
export type Plugin<Name extends keyof PluginsParams> = PluginDef<
PluginsParams[Name]
>;