From 4573d0178e213d27a54490ea0f7a5076ec69e0ec Mon Sep 17 00:00:00 2001 From: Seth Falco Date: Wed, 30 Apr 2025 02:16:53 +0100 Subject: [PATCH] chore: migrate plugin types to plugin (#2111) --- CONTRIBUTING.md | 2 +- lib/parser.js | 2 +- lib/style.js | 2 +- lib/svgo.js | 2 +- lib/types.d.ts | 4 +- plugins/_transforms.js | 4 +- plugins/addAttributesToSVGElement.js | 8 +- plugins/addClassesToSVGElement.js | 11 +- plugins/cleanupAttrs.js | 9 +- plugins/cleanupEnableBackground.js | 2 +- plugins/cleanupIds.js | 9 +- plugins/cleanupListOfValues.js | 12 +- plugins/cleanupNumericValues.js | 10 +- plugins/collapseGroups.js | 2 +- plugins/convertColors.js | 12 +- plugins/convertEllipseToCircle.js | 2 +- plugins/convertOneStopGradients.js | 2 +- plugins/convertPathData.js | 71 ++--- plugins/convertShapeToPath.js | 6 +- plugins/convertStyleToAttrs.js | 7 +- plugins/convertTransform.js | 16 +- plugins/inlineStyles.js | 13 +- plugins/mergePaths.js | 15 +- plugins/mergeStyles.js | 2 +- plugins/minifyStyles.js | 31 +- plugins/moveElemsAttrsToGroup.js | 2 +- plugins/moveGroupAttrsToElems.js | 2 +- plugins/plugins-types.d.ts | 348 +++++----------------- plugins/prefixIds.js | 10 +- plugins/removeAttributesBySelector.js | 2 +- plugins/removeAttrs.js | 9 +- plugins/removeComments.js | 7 +- plugins/removeDeprecatedAttrs.js | 11 +- plugins/removeDesc.js | 7 +- plugins/removeDimensions.js | 2 +- plugins/removeDoctype.js | 2 +- plugins/removeEditorsNSData.js | 7 +- plugins/removeElementsByAttr.js | 8 +- plugins/removeEmptyAttrs.js | 2 +- plugins/removeEmptyContainers.js | 2 +- plugins/removeEmptyText.js | 9 +- plugins/removeHiddenElems.js | 31 +- plugins/removeMetadata.js | 2 +- plugins/removeNonInheritableGroupAttrs.js | 2 +- plugins/removeOffCanvasPaths.js | 2 +- plugins/removeRasterImages.js | 2 +- plugins/removeScripts.js | 2 +- plugins/removeStyleElement.js | 2 +- plugins/removeTitle.js | 2 +- plugins/removeUnknownsAndDefaults.js | 17 +- plugins/removeUnusedNS.js | 2 +- plugins/removeUselessDefs.js | 2 +- plugins/removeUselessStrokeAndFill.js | 9 +- plugins/removeViewBox.js | 2 +- plugins/removeXMLNS.js | 2 +- plugins/removeXMLProcInst.js | 2 +- plugins/removeXlink.js | 7 +- plugins/reusePaths.js | 2 +- plugins/sortAttrs.js | 8 +- plugins/sortDefsChildren.js | 2 +- 60 files changed, 399 insertions(+), 387 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b32f7360..baaf7560 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,7 +55,7 @@ You should read our [Plugin Architecture](https://svgo.dev/docs/plugins-api/) do SVGO plugins can optionally have parameters. These can be consumed by the plugin to tailor the behavior. -As types are managed through TypeScript definition files and JSDocs, you must define the parameter types in [`plugins/plugin-types.d.ts`](https://github.com/svg/svgo/blob/main/plugins/plugins-types.d.ts) for built-in plugins. Then you'll have code completion and type checking as you'd expect while editing the plugin if your code editor supports that. +Parameters must have types declared in a [`@typedef`](https://jsdoc.app/tags-typedef) at the top of the file. For new plugins, you must also append the appropriate type in [`plugins/plugin-types.d.ts`](https://github.com/svg/svgo/blob/main/plugins/plugins-types.d.ts). This way built-in plugins will have code completion and type checking as you'd expect while editing the plugin. ## Documentation diff --git a/lib/parser.js b/lib/parser.js index 96a37bdd..997f3d32 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -20,7 +20,7 @@ export class SvgoParserError extends Error { * @param {number} line * @param {number} column * @param {string} source - * @param {string|undefined} file + * @param {string | undefined} file */ constructor(message, line, column, source, file = undefined) { super(message); diff --git a/lib/style.js b/lib/style.js index 8f047cd2..4798449c 100644 --- a/lib/style.js +++ b/lib/style.js @@ -284,7 +284,7 @@ export const computeStyle = (stylesheet, node) => { * if a `.class` or `#id` is included by passing `name=class` or `name=id` * respectively. * - * @param {csstree.ListItem|string} selector + * @param {csstree.ListItem | string} selector * @param {string} name * @param {?string} value * @param {boolean} traversed diff --git a/lib/svgo.js b/lib/svgo.js index 3da6afed..529fe404 100644 --- a/lib/svgo.js +++ b/lib/svgo.js @@ -35,7 +35,7 @@ function getPlugin(name) { } /** - * @param {string|PluginConfig} plugin + * @param {string | PluginConfig} plugin * @returns {?PluginConfig} */ const resolvePluginConfig = (plugin) => { diff --git a/lib/types.d.ts b/lib/types.d.ts index 9c6a194e..d61acf31 100644 --- a/lib/types.d.ts +++ b/lib/types.d.ts @@ -105,9 +105,9 @@ export type PluginInfo = { multipassCount: number; }; -export type Plugin = ( +export type Plugin

= ( root: XastRoot, - params: Params, + params: P, info: PluginInfo, ) => Visitor | null | void; diff --git a/plugins/_transforms.js b/plugins/_transforms.js index 79028105..bfbe79eb 100644 --- a/plugins/_transforms.js +++ b/plugins/_transforms.js @@ -183,7 +183,7 @@ const getDecompositions = (matrix) => { /** * @param {TransformItem} matrix - * @returns {TransformItem[]|undefined} + * @returns {TransformItem[] | undefined} * @see {@link https://frederic-wang.fr/2013/12/01/decomposition-of-2d-transform-matrices/} Where applicable, variables are named in accordance with this document. */ const decomposeQRAB = (matrix) => { @@ -238,7 +238,7 @@ const decomposeQRAB = (matrix) => { /** * @param {TransformItem} matrix - * @returns {TransformItem[]|undefined} + * @returns {TransformItem[] | undefined} * @see {@link https://frederic-wang.fr/2013/12/01/decomposition-of-2d-transform-matrices/} Where applicable, variables are named in accordance with this document. */ const decomposeQRCD = (matrix) => { diff --git a/plugins/addAttributesToSVGElement.js b/plugins/addAttributesToSVGElement.js index ceee99f9..bec455a6 100644 --- a/plugins/addAttributesToSVGElement.js +++ b/plugins/addAttributesToSVGElement.js @@ -1,3 +1,9 @@ +/** + * @typedef AddAttributesToSVGElementParams + * @property {string | Record=} attribute + * @property {Array>=} attributes + */ + export const name = 'addAttributesToSVGElement'; export const description = 'adds attributes to an outer element'; @@ -45,7 +51,7 @@ plugins: [ * * @author April Arcus * - * @type {import('./plugins-types.js').Plugin<'addAttributesToSVGElement'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = (root, params) => { if (!Array.isArray(params.attributes) && !params.attribute) { diff --git a/plugins/addClassesToSVGElement.js b/plugins/addClassesToSVGElement.js index c32a0f25..55e960af 100644 --- a/plugins/addClassesToSVGElement.js +++ b/plugins/addClassesToSVGElement.js @@ -1,3 +1,12 @@ +/** + * @typedef {import('../lib/types.js').PluginInfo} PluginInfo + * @typedef {import('../lib/types.js').XastElement} XastElement + * + * @typedef AddClassesToSVGElementParams + * @property {string | ((node: XastElement, info: PluginInfo) => string)=} className + * @property {Array string)>=} classNames + */ + export const name = 'addClassesToSVGElement'; export const description = 'adds classnames to an outer element'; @@ -47,7 +56,7 @@ plugins: [ * * @author April Arcus * - * @type {import('./plugins-types.js').Plugin<'addClassesToSVGElement'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = (root, params, info) => { if ( diff --git a/plugins/cleanupAttrs.js b/plugins/cleanupAttrs.js index 6bbda85e..0268f155 100644 --- a/plugins/cleanupAttrs.js +++ b/plugins/cleanupAttrs.js @@ -1,3 +1,10 @@ +/** + * @typedef CleanupAttrsParams + * @property {boolean=} newlines + * @property {boolean=} trim + * @property {boolean=} spaces + */ + export const name = 'cleanupAttrs'; export const description = 'cleanups attributes from newlines, trailing and repeating spaces'; @@ -10,7 +17,7 @@ const regSpaces = /\s{2,}/g; * Cleanup attributes values from newlines, trailing and repeating spaces. * * @author Kir Belevich - * @type {import('./plugins-types.js').Plugin<'cleanupAttrs'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = (root, params) => { const { newlines = true, trim = true, spaces = true } = params; diff --git a/plugins/cleanupEnableBackground.js b/plugins/cleanupEnableBackground.js index 67dcaf79..8c6b4eb4 100644 --- a/plugins/cleanupEnableBackground.js +++ b/plugins/cleanupEnableBackground.js @@ -17,7 +17,7 @@ const regEnableBackground = * ⬇ * * @author Kir Belevich - * @type {import('./plugins-types.js').Plugin<'cleanupEnableBackground'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = (root) => { let hasFilter = false; diff --git a/plugins/cleanupIds.js b/plugins/cleanupIds.js index 7a30591c..b1fe5b5d 100644 --- a/plugins/cleanupIds.js +++ b/plugins/cleanupIds.js @@ -3,6 +3,13 @@ import { hasScripts, findReferences } from '../lib/svgo/tools.js'; /** * @typedef {import('../lib/types.js').XastElement} XastElement + * + * @typedef CleanupIdsParams + * @property {boolean=} remove + * @property {boolean=} minify + * @property {string[]=} preserve + * @property {string[]=} preservePrefixes + * @property {boolean=} force */ export const name = 'cleanupIds'; @@ -119,7 +126,7 @@ const getIdString = (arr) => { * * @author Kir Belevich * - * @type {import('./plugins-types.js').Plugin<'cleanupIds'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = (_root, params) => { const { diff --git a/plugins/cleanupListOfValues.js b/plugins/cleanupListOfValues.js index 5c2e6661..3c8fad6a 100644 --- a/plugins/cleanupListOfValues.js +++ b/plugins/cleanupListOfValues.js @@ -1,5 +1,13 @@ import { removeLeadingZero } from '../lib/svgo/tools.js'; +/** + * @typedef CleanupListOfValuesParams + * @property {number=} floatPrecision + * @property {boolean=} leadingZero + * @property {boolean=} defaultPx + * @property {boolean=} convertToPx + */ + export const name = 'cleanupListOfValues'; export const description = 'rounds list of values to the fixed precision'; @@ -30,7 +38,7 @@ const absoluteLengths = { * * @author kiyopikko * - * @type {import('./plugins-types.js').Plugin<'cleanupListOfValues'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = (_root, params) => { const { @@ -57,7 +65,7 @@ export const fn = (_root, params) => { /** @type {any} */ let matchedUnit = match[3] || ''; /** - * @type{'' | keyof typeof absoluteLengths} + * @type {'' | keyof typeof absoluteLengths} */ let units = matchedUnit; diff --git a/plugins/cleanupNumericValues.js b/plugins/cleanupNumericValues.js index 4c1d7e18..392c658c 100644 --- a/plugins/cleanupNumericValues.js +++ b/plugins/cleanupNumericValues.js @@ -1,5 +1,13 @@ import { removeLeadingZero } from '../lib/svgo/tools.js'; +/** + * @typedef CleanupNumericValuesParams + * @property {number=} floatPrecision + * @property {boolean=} leadingZero + * @property {boolean=} defaultPx + * @property {boolean=} convertToPx + */ + export const name = 'cleanupNumericValues'; export const description = 'rounds numeric values to the fixed precision, removes default ‘px’ units'; @@ -23,7 +31,7 @@ const absoluteLengths = { * * @author Kir Belevich * - * @type {import('./plugins-types.js').Plugin<'cleanupNumericValues'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = (_root, params) => { const { diff --git a/plugins/collapseGroups.js b/plugins/collapseGroups.js index 449059d2..fd3fc12d 100644 --- a/plugins/collapseGroups.js +++ b/plugins/collapseGroups.js @@ -49,7 +49,7 @@ const hasAnimatedAttr = (node, name) => { * * @author Kir Belevich * - * @type {import('./plugins-types.js').Plugin<'collapseGroups'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = (root) => { const stylesheet = collectStylesheet(root); diff --git a/plugins/convertColors.js b/plugins/convertColors.js index 6c7fdfd0..b267715d 100644 --- a/plugins/convertColors.js +++ b/plugins/convertColors.js @@ -1,6 +1,16 @@ import { colorsNames, colorsProps, colorsShortNames } from './_collections.js'; import { includesUrlReference } from '../lib/svgo/tools.js'; +/** + * @typedef ConvertColorsParams + * @property {boolean | string | RegExp=} currentColor + * @property {boolean=} names2hex + * @property {boolean=} rgb2hex + * @property {false | 'lower' | 'upper'=} convertCase + * @property {boolean=} shorthex + * @property {boolean=} shortname + */ + export const name = 'convertColors'; export const description = 'converts colors: rgb() to #rrggbb and #rrggbb to #rgb'; @@ -61,7 +71,7 @@ const convertRgbToHex = ([r, g, b]) => { * * @author Kir Belevich * - * @type {import('./plugins-types.js').Plugin<'convertColors'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = (_root, params) => { const { diff --git a/plugins/convertEllipseToCircle.js b/plugins/convertEllipseToCircle.js index 256eaaac..e8a9539b 100644 --- a/plugins/convertEllipseToCircle.js +++ b/plugins/convertEllipseToCircle.js @@ -8,7 +8,7 @@ export const description = 'converts non-eccentric s to s'; * * @author Taylor Hunt * - * @type {import('./plugins-types.js').Plugin<'convertEllipseToCircle'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = () => { return { diff --git a/plugins/convertOneStopGradients.js b/plugins/convertOneStopGradients.js index 076878ed..fa0c5701 100644 --- a/plugins/convertOneStopGradients.js +++ b/plugins/convertOneStopGradients.js @@ -19,7 +19,7 @@ export const description = * Converts one-stop (single color) gradients to a plain color. * * @author Seth Falco - * @type {import('./plugins-types.js').Plugin<'convertOneStopGradients'>} + * @type {import('../lib/types.js').Plugin} * @see https://developer.mozilla.org/docs/Web/SVG/Element/linearGradient * @see https://developer.mozilla.org/docs/Web/SVG/Element/radialGradient */ diff --git a/plugins/convertPathData.js b/plugins/convertPathData.js index 41fe5bb2..ce17d167 100644 --- a/plugins/convertPathData.js +++ b/plugins/convertPathData.js @@ -7,6 +7,38 @@ import { cleanupOutData, toFixed } from '../lib/svgo/tools.js'; /** * @typedef {import('../lib/types.js').PathDataItem} PathDataItem + * + * @typedef {[number, number]} Point + * + * @typedef Circle + * @property {Point} center + * @property {number} radius + * + * @typedef MakeArcs + * @property {number} threshold + * @property {number} tolerance + * + * @typedef ConvertPathDataParams + * @property {boolean=} applyTransforms + * @property {boolean=} applyTransformsStroked + * @property {MakeArcs=} makeArcs + * @property {boolean=} straightCurves + * @property {boolean=} convertToQ + * @property {boolean=} lineShorthands + * @property {boolean=} convertToZ + * @property {boolean=} curveSmoothShorthands + * @property {number | false=} floatPrecision + * @property {number=} transformPrecision + * @property {boolean=} smartArcRounding + * @property {boolean=} removeUseless + * @property {boolean=} collapseRepeated + * @property {boolean=} utilizeAbsolute + * @property {boolean=} leadingZero + * @property {boolean=} negativeExtraSpace + * @property {boolean=} noSpaceAfterFlags + * @property {boolean=} forceAbsolutePath + * + * @typedef {Required} InternalParams */ export const name = 'convertPathData'; @@ -24,43 +56,6 @@ let arcThreshold; /** @type {number} */ let arcTolerance; -/** - * @typedef {{ - * 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, - * }} InternalParams - */ - -/** - * @typedef {[number, number]} Point - */ - -/** - * @typedef {{ - * center: Point, - * radius: number - * }} Circle - */ - /** * Convert absolute Path to relative, * collapse repeated instructions, @@ -73,7 +68,7 @@ let arcTolerance; * * @author Kir Belevich * - * @type {import('./plugins-types.js').Plugin<'convertPathData'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = (root, params) => { const { diff --git a/plugins/convertShapeToPath.js b/plugins/convertShapeToPath.js index e91a0306..597e6967 100644 --- a/plugins/convertShapeToPath.js +++ b/plugins/convertShapeToPath.js @@ -3,6 +3,10 @@ import { detachNodeFromParent } from '../lib/xast.js'; /** * @typedef {import('../lib/types.js').PathDataItem} PathDataItem + * + * @typedef ConvertShapeToPathParams + * @property {boolean=} convertArcs + * @property {number=} floatPrecision */ export const name = 'convertShapeToPath'; @@ -19,7 +23,7 @@ const regNumber = /[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g; * * @author Lev Solntsev * - * @type {import('./plugins-types.js').Plugin<'convertShapeToPath'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = (root, params) => { const { convertArcs = false, floatPrecision: precision } = params; diff --git a/plugins/convertStyleToAttrs.js b/plugins/convertStyleToAttrs.js index 8c782b45..c8dd2295 100644 --- a/plugins/convertStyleToAttrs.js +++ b/plugins/convertStyleToAttrs.js @@ -1,5 +1,10 @@ import { attrsGroups } from './_collections.js'; +/** + * @typedef ConvertStyleToAttrsParams + * @property {boolean=} keepImportant + */ + export const name = 'convertStyleToAttrs'; export const description = 'converts style to attributes'; @@ -70,7 +75,7 @@ const regStripComments = new RegExp( * * @author Kir Belevich * - * @type {import('./plugins-types.js').Plugin<'convertStyleToAttrs'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = (_root, params) => { const { keepImportant = false } = params; diff --git a/plugins/convertTransform.js b/plugins/convertTransform.js index 5fcae7cf..46ae771d 100644 --- a/plugins/convertTransform.js +++ b/plugins/convertTransform.js @@ -10,6 +10,20 @@ import { * @typedef {import('../lib/types.js').XastChild} XastChild * @typedef {import('../lib/types.js').XastElement} XastElement * @typedef {import('../lib/types.js').XastParent} XastParent + * + * @typedef ConvertTransformParams + * @property {boolean=} convertToShorts + * @property {number=} degPrecision + * @property {number=} floatPrecision + * @property {number=} transformPrecision + * @property {boolean=} matrixToTransform + * @property {boolean=} shortTranslate + * @property {boolean=} shortScale + * @property {boolean=} shortRotate + * @property {boolean=} removeUseless + * @property {boolean=} collapseIntoOne + * @property {boolean=} leadingZero + * @property {boolean=} negativeExtraSpace */ export const name = 'convertTransform'; @@ -26,7 +40,7 @@ export const description = * * @author Kir Belevich * - * @type {import('./plugins-types.js').Plugin<'convertTransform'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = (_root, params) => { const { diff --git a/plugins/inlineStyles.js b/plugins/inlineStyles.js index 67841b7e..986b246c 100644 --- a/plugins/inlineStyles.js +++ b/plugins/inlineStyles.js @@ -11,6 +11,17 @@ import { compareSpecificity, includesAttrSelector } from '../lib/style.js'; /** * @typedef {import('../lib/types.js').XastElement} XastElement * @typedef {import('../lib/types.js').XastParent} XastParent + * + * @typedef InlineStylesParams + * @property {boolean=} onlyMatchedOnce Inlines selectors that match once only. + * @property {boolean=} removeMatchedSelectors + * Clean up matched selectors. Unused selects are left as-is. + * @property {string[]=} useMqs + * Media queries to use. An empty string indicates all selectors outside of + * media queries. + * @property {string[]=} usePseudos + * Pseudo-classes and elements to use. An empty string indicates all + * non-pseudo-classes and elements. */ export const name = 'inlineStyles'; @@ -34,7 +45,7 @@ const preservedPseudos = [ /** * Merges styles from style nodes into inline styles. * - * @type {import('./plugins-types.js').Plugin<'inlineStyles'>} + * @type {import('../lib/types.js').Plugin} * @author strarsis */ export const fn = (root, params) => { diff --git a/plugins/mergePaths.js b/plugins/mergePaths.js index bcfc294f..58cad7af 100644 --- a/plugins/mergePaths.js +++ b/plugins/mergePaths.js @@ -1,3 +1,7 @@ +import { collectStylesheet, computeStyle } from '../lib/style.js'; +import { path2js, js2path, intersects } from './_path.js'; +import { includesUrlReference } from '../lib/svgo/tools.js'; + /** * @typedef {import('../lib/types.js').ComputedStyles} ComputedStyles * @typedef {import('../lib/types.js').StaticStyle} StaticStyle @@ -5,12 +9,13 @@ * @typedef {import("../lib/types.js").PathDataItem} PathDataItem * @typedef {import('../lib/types.js').XastChild} XastChild * @typedef {import('../lib/types.js').XastElement} XastElement + * + * @typedef MergePathsParams + * @property {boolean=} force + * @property {number=} floatPrecision + * @property {boolean=} noSpaceAfterFlags */ -import { collectStylesheet, computeStyle } from '../lib/style.js'; -import { path2js, js2path, intersects } from './_path.js'; -import { includesUrlReference } from '../lib/svgo/tools.js'; - export const name = 'mergePaths'; export const description = 'merges multiple paths in one if possible'; @@ -34,7 +39,7 @@ function elementHasUrl(computedStyle, attName) { * * @author Kir Belevich, Lev Solntsev * - * @type {import('./plugins-types.js').Plugin<'mergePaths'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = (root, params) => { const { diff --git a/plugins/mergeStyles.js b/plugins/mergeStyles.js index ec094b12..2b59f3d2 100644 --- a/plugins/mergeStyles.js +++ b/plugins/mergeStyles.js @@ -13,7 +13,7 @@ export const description = 'merge multiple style elements into one'; * * @author strarsis * - * @type {import('./plugins-types.js').Plugin<'mergeStyles'>} + * @type {import('../lib/types.js').Plugin} */ export const fn = () => { /** diff --git a/plugins/minifyStyles.js b/plugins/minifyStyles.js index 869b9185..04b9d1ef 100644 --- a/plugins/minifyStyles.js +++ b/plugins/minifyStyles.js @@ -1,12 +1,31 @@ -/** - * @typedef {import('../lib/types.js').XastElement} XastElement - * @typedef {import('../lib/types.js').XastParent} XastParent - */ - import * as csso from 'csso'; import { detachNodeFromParent } from '../lib/xast.js'; import { hasScripts } from '../lib/svgo/tools.js'; +/** + * @typedef {import('../lib/types.js').XastElement} XastElement + * @typedef {import('../lib/types.js').XastParent} XastParent + * + * @typedef Usage + * @property {boolean=} force + * @property {boolean=} ids + * @property {boolean=} classes + * @property {boolean=} tags + * + * @typedef MinifyStylesParams + * @property {boolean=} restructure Disable or enable a structure optimizations. + * @property {boolean=} forceMediaMerge + * Enables merging of `@media` rules with the same media query split by other + * rules. Unsafe in general, but should work fine in most cases. Use it on + * your own risk. + * @property {'exclamation' | 'first-exclamation' | boolean=} comments + * Specify what comments to leave: + * - `'exclamation'` or `true` — leave all exclamation comments + * - `'first-exclamation'` — remove every comment except first one + * - `false` — remove all comments + * @property {boolean | Usage=} usage Advanced optimizations. + */ + export const name = 'minifyStyles'; export const description = 'minifies styles and removes unused styles'; @@ -14,7 +33,7 @@ export const description = 'minifies styles and removes unused styles'; * Minifies styles (