mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
Move plugin types into d.ts
This commit is contained in:
@ -47,10 +47,7 @@ plugins: [
|
|||||||
*
|
*
|
||||||
* @author April Arcus
|
* @author April Arcus
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'addAttributesToSVGElement'>}
|
||||||
* attribute?: string | Record<string, null | string>,
|
|
||||||
* attributes?: Array<string | Record<string, null | string>>
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
if (!Array.isArray(params.attributes) && !params.attribute) {
|
if (!Array.isArray(params.attributes) && !params.attribute) {
|
||||||
|
@ -49,10 +49,7 @@ plugins: [
|
|||||||
*
|
*
|
||||||
* @author April Arcus
|
* @author April Arcus
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'addClassesToSVGElement'>}
|
||||||
* className?: string,
|
|
||||||
* classNames?: Array<string>
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
if (
|
if (
|
||||||
|
@ -13,11 +13,7 @@ const regSpaces = /\s{2,}/g;
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'cleanupAttrs'>}
|
||||||
* newlines?: boolean,
|
|
||||||
* trim?: boolean,
|
|
||||||
* spaces?: boolean
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
const { newlines = true, trim = true, spaces = true } = params;
|
const { newlines = true, trim = true, spaces = true } = params;
|
||||||
|
@ -18,7 +18,7 @@ exports.description =
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'cleanupEnableBackground'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = (root) => {
|
exports.fn = (root) => {
|
||||||
const regEnableBackground =
|
const regEnableBackground =
|
||||||
|
@ -123,13 +123,7 @@ const getIdString = (arr) => {
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'cleanupIds'>}
|
||||||
* remove?: boolean,
|
|
||||||
* minify?: boolean,
|
|
||||||
* preserve?: Array<string>,
|
|
||||||
* preservePrefixes?: Array<string>,
|
|
||||||
* force?: boolean,
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (_root, params) => {
|
exports.fn = (_root, params) => {
|
||||||
const {
|
const {
|
||||||
|
@ -32,12 +32,7 @@ const absoluteLengths = {
|
|||||||
*
|
*
|
||||||
* @author kiyopikko
|
* @author kiyopikko
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'cleanupListOfValues'>}
|
||||||
* floatPrecision?: number,
|
|
||||||
* leadingZero?: boolean,
|
|
||||||
* defaultPx?: boolean,
|
|
||||||
* convertToPx?: boolean
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (_root, params) => {
|
exports.fn = (_root, params) => {
|
||||||
const {
|
const {
|
||||||
|
@ -25,12 +25,7 @@ const absoluteLengths = {
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'cleanupNumericValues'>}
|
||||||
* floatPrecision?: number,
|
|
||||||
* leadingZero?: boolean,
|
|
||||||
* defaultPx?: boolean,
|
|
||||||
* convertToPx?: boolean
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (_root, params) => {
|
exports.fn = (_root, params) => {
|
||||||
const {
|
const {
|
||||||
|
@ -49,7 +49,7 @@ const hasAnimatedAttr = (node, name) => {
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'collapseGroups'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -61,13 +61,7 @@ const convertRgbToHex = ([r, g, b]) => {
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'convertColors'>}
|
||||||
* currentColor?: boolean | string | RegExp,
|
|
||||||
* names2hex?: boolean,
|
|
||||||
* rgb2hex?: boolean,
|
|
||||||
* shorthex?: boolean,
|
|
||||||
* shortname?: boolean,
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (_root, params) => {
|
exports.fn = (_root, params) => {
|
||||||
const {
|
const {
|
||||||
|
@ -10,7 +10,7 @@ exports.description = 'converts non-eccentric <ellipse>s to <circle>s';
|
|||||||
*
|
*
|
||||||
* @author Taylor Hunt
|
* @author Taylor Hunt
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'convertEllipseToCircle'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -82,26 +82,7 @@ let arcTolerance;
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'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,
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
const {
|
const {
|
||||||
|
@ -21,10 +21,7 @@ const regNumber = /[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g;
|
|||||||
*
|
*
|
||||||
* @author Lev Solntsev
|
* @author Lev Solntsev
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'convertShapeToPath'>}
|
||||||
* convertArcs?: boolean,
|
|
||||||
* floatPrecision?: number
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
const { convertArcs = false, floatPrecision: precision } = params;
|
const { convertArcs = false, floatPrecision: precision } = params;
|
||||||
|
@ -65,9 +65,7 @@ const regStripComments = new RegExp(
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'convertStyleToAttrs'>}
|
||||||
* keepImportant?: boolean
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (_root, params) => {
|
exports.fn = (_root, params) => {
|
||||||
const { keepImportant = false } = params;
|
const { keepImportant = false } = params;
|
||||||
|
@ -24,20 +24,7 @@ exports.description = 'collapses multiple transformations and optimizes it';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'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,
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (_root, params) => {
|
exports.fn = (_root, params) => {
|
||||||
const {
|
const {
|
||||||
|
@ -63,12 +63,7 @@ const toAny = (value) => value;
|
|||||||
*
|
*
|
||||||
* @author strarsis <strarsis@gmail.com>
|
* @author strarsis <strarsis@gmail.com>
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'inlineStyles'>}
|
||||||
* onlyMatchedOnce?: boolean,
|
|
||||||
* removeMatchedSelectors?: boolean,
|
|
||||||
* useMqs?: Array<string>,
|
|
||||||
* usePseudos?: Array<string>
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
const {
|
const {
|
||||||
|
@ -12,11 +12,7 @@ exports.description = 'merges multiple paths in one if possible';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich, Lev Solntsev
|
* @author Kir Belevich, Lev Solntsev
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'mergePaths'>}
|
||||||
* force?: boolean,
|
|
||||||
* floatPrecision?: number,
|
|
||||||
* noSpaceAfterFlags?: boolean
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
const {
|
const {
|
||||||
|
@ -15,7 +15,7 @@ exports.description = 'merge multiple style elements into one';
|
|||||||
*
|
*
|
||||||
* @author strarsis <strarsis@gmail.com>
|
* @author strarsis <strarsis@gmail.com>
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'mergeStyles'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
/**
|
/**
|
||||||
|
@ -15,14 +15,7 @@ exports.description =
|
|||||||
*
|
*
|
||||||
* @author strarsis <strarsis@gmail.com>
|
* @author strarsis <strarsis@gmail.com>
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<csso.MinifyOptions & Omit<csso.CompressOptions, 'usage'> & {
|
* @type {import('./plugins-types').Plugin<'minifyStyles'>}
|
||||||
* usage?: boolean | {
|
|
||||||
* force?: boolean,
|
|
||||||
* ids?: boolean,
|
|
||||||
* classes?: boolean,
|
|
||||||
* tags?: boolean
|
|
||||||
* }
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (_root, { usage, ...params }) => {
|
exports.fn = (_root, { usage, ...params }) => {
|
||||||
let enableTagsUsage = true;
|
let enableTagsUsage = true;
|
||||||
|
@ -26,7 +26,7 @@ exports.description = 'Move common attributes of group children to the group';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'moveElemsAttrsToGroup'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = (root) => {
|
exports.fn = (root) => {
|
||||||
// find if any style element is present
|
// find if any style element is present
|
||||||
|
@ -23,7 +23,7 @@ const pathElemsWithGroupsAndText = [...pathElems, 'g', 'text'];
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'moveGroupAttrsToElems'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
213
plugins/plugins-types.ts
Normal file
213
plugins/plugins-types.ts
Normal file
@ -0,0 +1,213 @@
|
|||||||
|
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 BuiltinsWithOptionalParams = DefaultPlugins & {
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
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]
|
||||||
|
>;
|
@ -3,11 +3,6 @@
|
|||||||
const csstree = require('css-tree');
|
const csstree = require('css-tree');
|
||||||
const { referencesProps } = require('./_collections.js');
|
const { referencesProps } = require('./_collections.js');
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {import('../lib/types').XastElement} XastElement
|
|
||||||
* @typedef {import('../lib/types').PluginInfo} PluginInfo
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.name = 'prefixIds';
|
exports.name = 'prefixIds';
|
||||||
exports.description = 'prefix IDs';
|
exports.description = 'prefix IDs';
|
||||||
|
|
||||||
@ -75,12 +70,7 @@ const toAny = (value) => value;
|
|||||||
*
|
*
|
||||||
* @author strarsis <strarsis@gmail.com>
|
* @author strarsis <strarsis@gmail.com>
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'prefixIds'>}
|
||||||
* prefix?: boolean | string | ((node: XastElement, info: PluginInfo) => string),
|
|
||||||
* delim?: string,
|
|
||||||
* prefixIds?: boolean,
|
|
||||||
* prefixClassNames?: boolean,
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (_root, params, info) => {
|
exports.fn = (_root, params, info) => {
|
||||||
const { delim = '__', prefixIds = true, prefixClassNames = true } = params;
|
const { delim = '__', prefixIds = true, prefixClassNames = true } = params;
|
||||||
|
@ -73,7 +73,7 @@ exports.description =
|
|||||||
*
|
*
|
||||||
* @author Bradley Mease
|
* @author Bradley Mease
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<any>}
|
* @type {import('./plugins-types').Plugin<'removeAttributesBySelector'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
const selectors = Array.isArray(params.selectors)
|
const selectors = Array.isArray(params.selectors)
|
||||||
|
@ -81,11 +81,7 @@ plugins: [
|
|||||||
*
|
*
|
||||||
* @author Benny Schudel
|
* @author Benny Schudel
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'removeAttrs'>}
|
||||||
* elemSeparator?: string,
|
|
||||||
* preserveCurrentColor?: boolean,
|
|
||||||
* attrs: string | Array<string>
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
if (typeof params.attrs == 'undefined') {
|
if (typeof params.attrs == 'undefined') {
|
||||||
|
@ -14,7 +14,7 @@ exports.description = 'removes comments';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeComments'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -16,7 +16,7 @@ const standardDescs = /^(Created with|Created using)/;
|
|||||||
*
|
*
|
||||||
* @author Daniel Wabyick
|
* @author Daniel Wabyick
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{ removeAny?: boolean }>}
|
* @type {import('./plugins-types').Plugin<'removeDesc'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
const { removeAny = true } = params;
|
const { removeAny = true } = params;
|
||||||
|
@ -14,7 +14,7 @@ exports.description =
|
|||||||
*
|
*
|
||||||
* @author Benny Schudel
|
* @author Benny Schudel
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeDimensions'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -27,7 +27,7 @@ exports.description = 'removes doctype declaration';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeDoctype'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -16,9 +16,7 @@ exports.description = 'removes editors namespaces, elements and attributes';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'removeEditorsNSData'>}
|
||||||
* additionalNamespaces?: Array<string>
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (_root, params) => {
|
exports.fn = (_root, params) => {
|
||||||
let namespaces = editorNamespaces;
|
let namespaces = editorNamespaces;
|
||||||
|
@ -37,10 +37,7 @@ exports.description =
|
|||||||
*
|
*
|
||||||
* @author Eli Dupuis (@elidupuis)
|
* @author Eli Dupuis (@elidupuis)
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'removeElementsByAttr'>}
|
||||||
* id?: string | Array<string>,
|
|
||||||
* class?: string | Array<string>
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
const ids =
|
const ids =
|
||||||
|
@ -10,7 +10,7 @@ exports.description = 'removes empty attributes';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeEmptyAttrs'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -19,7 +19,7 @@ exports.description = 'removes empty container elements';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeEmptyContainers'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -22,11 +22,7 @@ exports.description = 'removes empty <text> elements';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'removeEmptyText'>}
|
||||||
* text?: boolean,
|
|
||||||
* tspan?: boolean,
|
|
||||||
* tref?: boolean
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
const { text = true, tspan = true, tref = true } = params;
|
const { text = true, tspan = true, tref = true } = params;
|
||||||
|
@ -28,23 +28,7 @@ exports.description =
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'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,
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
const {
|
const {
|
||||||
|
@ -12,7 +12,7 @@ exports.description = 'removes <metadata>';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeMetadata'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -15,7 +15,7 @@ exports.description =
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeNonInheritableGroupAttrs'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -17,7 +17,7 @@ exports.description =
|
|||||||
*
|
*
|
||||||
* @author JoshyPHP
|
* @author JoshyPHP
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeOffCanvasPaths'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
/**
|
/**
|
||||||
|
@ -12,7 +12,7 @@ exports.description = 'removes raster images (disabled by default)';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeRasterImages'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -12,7 +12,7 @@ exports.description = 'removes <script> elements (disabled by default)';
|
|||||||
*
|
*
|
||||||
* @author Patrick Klingemann
|
* @author Patrick Klingemann
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeScriptElement'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -12,7 +12,7 @@ exports.description = 'removes <style> element (disabled by default)';
|
|||||||
*
|
*
|
||||||
* @author Betsy Dupuis
|
* @author Betsy Dupuis
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeStyleElement'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -12,7 +12,7 @@ exports.description = 'removes <title>';
|
|||||||
*
|
*
|
||||||
* @author Igor Kalashnikov
|
* @author Igor Kalashnikov
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeTitle'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -92,15 +92,7 @@ for (const [name, config] of Object.entries(elems)) {
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'removeUnknownsAndDefaults'>}
|
||||||
* unknownContent?: boolean,
|
|
||||||
* unknownAttrs?: boolean,
|
|
||||||
* defaultAttrs?: boolean,
|
|
||||||
* uselessOverrides?: boolean,
|
|
||||||
* keepDataAttrs?: boolean,
|
|
||||||
* keepAriaAttrs?: boolean,
|
|
||||||
* keepRoleAttr?: boolean,
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
const {
|
const {
|
||||||
|
@ -9,7 +9,7 @@ exports.description = 'removes unused namespaces declaration';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeUnusedNS'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
/**
|
/**
|
||||||
|
@ -15,7 +15,7 @@ exports.description = 'removes elements in <defs> without id';
|
|||||||
*
|
*
|
||||||
* @author Lev Solntsev
|
* @author Lev Solntsev
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeUselessDefs'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -12,11 +12,7 @@ exports.description = 'removes useless stroke and fill attributes';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'removeUselessStrokeAndFill'>}
|
||||||
* stroke?: boolean,
|
|
||||||
* fill?: boolean,
|
|
||||||
* removeNone?: boolean
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (root, params) => {
|
exports.fn = (root, params) => {
|
||||||
const {
|
const {
|
||||||
|
@ -17,7 +17,7 @@ const viewBoxElems = ['svg', 'pattern', 'symbol'];
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeViewBox'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -14,7 +14,7 @@ exports.description =
|
|||||||
*
|
*
|
||||||
* @author Ricardo Tomasi
|
* @author Ricardo Tomasi
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeXMLNS'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -13,7 +13,7 @@ exports.description = 'removes XML processing instructions';
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'removeXMLProcInst'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -18,7 +18,7 @@ exports.description =
|
|||||||
*
|
*
|
||||||
* @author Jacob Howcroft
|
* @author Jacob Howcroft
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'reusePaths'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
/**
|
/**
|
||||||
|
@ -8,10 +8,7 @@ exports.description = 'Sort element attributes for better compression';
|
|||||||
*
|
*
|
||||||
* @author Nikolay Frantsev
|
* @author Nikolay Frantsev
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<{
|
* @type {import('./plugins-types').Plugin<'sortAttrs'>}
|
||||||
* order?: Array<string>
|
|
||||||
* xmlnsOrder?: 'front' | 'alphabetical'
|
|
||||||
* }>}
|
|
||||||
*/
|
*/
|
||||||
exports.fn = (_root, params) => {
|
exports.fn = (_root, params) => {
|
||||||
const {
|
const {
|
||||||
|
@ -9,7 +9,7 @@ exports.description = 'Sorts children of <defs> to improve compression';
|
|||||||
*
|
*
|
||||||
* @author David Leston
|
* @author David Leston
|
||||||
*
|
*
|
||||||
* @type {import('../lib/types').Plugin<void>}
|
* @type {import('./plugins-types').Plugin<'sortDefsChildren'>}
|
||||||
*/
|
*/
|
||||||
exports.fn = () => {
|
exports.fn = () => {
|
||||||
return {
|
return {
|
||||||
|
Reference in New Issue
Block a user