1
0
mirror of https://github.com/svg/svgo.git synced 2026-01-27 07:02:06 +03:00
Files
svgo/plugins/plugins-types.ts
2022-11-11 12:50:33 +03:00

230 lines
5.4 KiB
TypeScript

import type * as csso from 'csso';
import type {
Plugin as PluginDef,
PluginInfo,
XastElement,
} from '../lib/types';
type DefaultPlugins = {
cleanupAttrs: {
newlines?: boolean;
trim?: boolean;
spaces?: boolean;
};
cleanupEnableBackground: void;
cleanupIds: {
remove?: boolean;
minify?: boolean;
preserve?: Array<string>;
preservePrefixes?: Array<string>;
force?: boolean;
};
cleanupNumericValues: {
floatPrecision?: number;
leadingZero?: boolean;
defaultPx?: boolean;
convertToPx?: boolean;
};
collapseGroups: void;
convertColors: {
currentColor?: boolean | string | RegExp;
names2hex?: boolean;
rgb2hex?: boolean;
shorthex?: boolean;
shortname?: boolean;
};
convertEllipseToCircle: void;
convertPathData: {
applyTransforms?: boolean;
applyTransformsStroked?: boolean;
makeArcs?: {
threshold: number;
tolerance: number;
};
straightCurves?: boolean;
lineShorthands?: boolean;
curveSmoothShorthands?: boolean;
floatPrecision?: number | false;
transformPrecision?: number;
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: {
onlyMatchedOnce?: boolean;
removeMatchedSelectors?: boolean;
useMqs?: Array<string>;
usePseudos?: Array<string>;
};
mergePaths: {
force?: boolean;
floatPrecision?: number;
noSpaceAfterFlags?: boolean;
};
minifyStyles: csso.MinifyOptions &
Omit<csso.CompressOptions, 'usage'> & {
usage?:
| boolean
| {
force?: boolean;
ids?: boolean;
classes?: boolean;
tags?: boolean;
};
};
moveElemsAttrsToGroup: void;
moveGroupAttrsToElems: void;
removeComments: void;
removeDesc: {
removeAny?: boolean;
};
removeDoctype: void;
removeEditorsNSData: {
additionalNamespaces?: Array<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;
removeTitle: void;
removeUnknownsAndDefaults: {
unknownContent?: boolean;
unknownAttrs?: boolean;
defaultAttrs?: boolean;
uselessOverrides?: boolean;
keepDataAttrs?: boolean;
keepAriaAttrs?: boolean;
keepRoleAttr?: boolean;
};
removeUnusedNS: void;
removeUselessDefs: void;
removeUselessStrokeAndFill: {
stroke?: boolean;
fill?: boolean;
removeNone?: boolean;
};
removeViewBox: void;
removeXMLProcInst: void;
sortAttrs: {
order?: Array<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;
};
convertStyleToAttrs: {
keepImportant?: boolean;
};
prefixIds: {
prefix?:
| boolean
| string
| ((node: XastElement, info: PluginInfo) => string);
delim?: string;
prefixIds?: boolean;
prefixClassNames?: boolean;
};
removeDimensions: void;
removeOffCanvasPaths: void;
removeRasterImages: void;
removeScriptElement: void;
removeStyleElement: void;
removeXMLNS: void;
reusePaths: void;
};
export type BuiltinsWithRequiredParams = {
addAttributesToSVGElement: {
attribute?: string | Record<string, null | string>;
attributes?: Array<string | Record<string, null | string>>;
};
addClassesToSVGElement: {
className?: string;
classNames?: Array<string>;
};
removeAttributesBySelector: any;
removeAttrs: {
elemSeparator?: string;
preserveCurrentColor?: boolean;
attrs: string | Array<string>;
};
removeElementsByAttr: {
id?: string | Array<string>;
class?: string | Array<string>;
};
};
type PluginsParams = BuiltinsWithOptionalParams & BuiltinsWithRequiredParams;
export type Plugin<Name extends keyof PluginsParams> = PluginDef<
PluginsParams[Name]
>;