mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
Add plugin types (#1527)
Covered following plugins - addAttributesToSVGElement.js - addClassesToSVGElement.js - cleanupAttrs.js - convertEllipseToCircle.js - removeAttributesBySelector.js - removeAttrs.js - removeComments.js - removeDesc.js - removeDoctype.js - removeElementsByAttr.js - removeEmptyText.js - removeMetadata.js - removeRasterImages.js - removeScriptElement.js - removeStyleElement.js - removeTitle.js - removeXMLProcInst.js
This commit is contained in:
@ -50,6 +50,11 @@ plugins: [
|
||||
* ]
|
||||
*
|
||||
* @author April Arcus
|
||||
*
|
||||
* @type {import('../lib/types').Plugin<{
|
||||
* className?: string,
|
||||
* classNames?: Array<string>
|
||||
* }>}
|
||||
*/
|
||||
exports.fn = (root, params) => {
|
||||
if (
|
||||
@ -57,13 +62,14 @@ exports.fn = (root, params) => {
|
||||
!params.className
|
||||
) {
|
||||
console.error(ENOCLS);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
const classNames = params.classNames || [params.className];
|
||||
return {
|
||||
element: {
|
||||
enter: (node, parentNode) => {
|
||||
if (node.name === 'svg' && parentNode.type === 'root') {
|
||||
// @ts-ignore class attribute will be just a string eventually
|
||||
node.class.add(...classNames);
|
||||
}
|
||||
},
|
||||
|
Reference in New Issue
Block a user