├── test ├── coa │ └── testFolderWithNoSvg │ │ └── test ├── mocha.opts ├── plugins │ ├── removeEmptyAttrs.01.svg │ ├── removeUnknownsAndDefaults.13.svg │ ├── convertColors.02.svg │ ├── removeTitle.01.svg │ ├── removeMetadata.01.svg │ ├── removeDesc.01.svg │ ├── removeEmptyText.01.svg │ ├── removeEmptyText.02.svg │ ├── removeHiddenElems.09.svg │ ├── removeHiddenElems.10.svg │ ├── removeDimensions.04.svg │ ├── removeEmptyText.03.svg │ ├── removeXMLProcInst.01.svg │ ├── removeDimensions.05.svg │ ├── removeComments.02.svg │ ├── removeDimensions.03.svg │ ├── removeHiddenElems.02.svg │ ├── removeHiddenElems.01.svg │ ├── cleanupAttrs.01.svg │ ├── removeComments.01.svg │ ├── removeDimensions.02.svg │ ├── addAttributesToSVGElement.02.svg │ ├── removeViewBox.03.svg │ ├── removeDimensions.01.svg │ ├── removeHiddenElems.04.svg │ ├── removeViewBox.01.svg │ ├── convertPathData.10.svg │ ├── removeHiddenElems.05.svg │ ├── removeHiddenElems.07.svg │ ├── removeHiddenElems.06.svg │ ├── removeUnknownsAndDefaults.14.svg │ ├── removeViewBox.02.svg │ ├── addClassesToSVGElement.01.svg │ ├── collapseGroups.01.svg │ ├── removeViewBox.04.svg │ ├── removeDoctype.01.svg │ ├── removeUnusedNS.01.svg │ ├── removeUselessDefs.01.svg │ ├── addAttributesToSVGElement.01.svg │ ├── cleanupAttrs.02.svg │ ├── collapseGroups.02.svg │ ├── removeXMLProcInst.02.svg │ ├── convertColors.03.svg │ ├── addAttributesToSVGElement.03.svg │ ├── inlineStyles.01.svg │ ├── prefixIds.03.svg │ ├── removeEmptyContainers.01.svg │ ├── collapseGroups.03.svg │ ├── collapseGroups.16.svg │ ├── convertEllipseToCircle.01.svg │ ├── cleanupEnableBackground.04.svg │ ├── cleanupListOfValues.01.svg │ ├── removeUnknownsAndDefaults.03.svg │ ├── removeNonInheritableGroupAttrs.02.svg │ ├── convertPathData.13.svg │ ├── convertPathData.20.svg │ ├── removeUnusedNS.02.svg │ ├── convertStyleToAttrs.04.svg │ ├── collapseGroups.04.svg │ ├── removeEditorsNSData.01.svg │ ├── removeEditorsNSData.02.svg │ ├── inlineStyles.02.svg │ ├── cleanupNumericValues.02.svg │ ├── convertStyleToAttrs.01.svg │ ├── collapseGroups.05.svg │ ├── removeUnknownsAndDefaults.06.svg │ ├── convertShapeToPath.04.svg │ ├── cleanupNumericValues.01.svg │ ├── collapseGroups.06.svg │ ├── inlineStyles.04.svg │ ├── moveGroupAttrsToElems.02.svg │ ├── convertStyleToAttrs.03.svg │ ├── convertPathData.18.svg │ ├── inlineStyles.10.svg │ ├── removeUnknownsAndDefaults.01.svg │ ├── removeUnknownsAndDefaults.04.svg │ ├── convertStyleToAttrs.05.svg │ ├── moveElemsAttrsToGroup.06.svg │ ├── moveGroupAttrsToElems.05.svg │ ├── convertStyleToAttrs.02.svg │ ├── inlineStyles.12.svg │ ├── moveElemsAttrsToGroup.01.svg │ ├── collapseGroups.08.svg │ ├── removeAttributesBySelector.02.svg │ ├── removeAttributesBySelector.01.svg │ ├── removeUnknownsAndDefaults.02.svg │ ├── moveElemsAttrsToGroup.02.svg │ ├── cleanupIDs.03.svg │ ├── removeUnknownsAndDefaults.12.svg │ ├── removeOffCanvasPaths.01.svg │ ├── convertShapeToPath.02.svg │ ├── removeUnknownsAndDefaults.10.svg │ ├── cleanupIDs.06.svg │ ├── convertPathData.16.svg │ ├── cleanupIDs.07.svg │ ├── convertColors.01.svg │ ├── inlineStyles.11.svg │ ├── removeUnusedNS.03.svg │ ├── removeUnusedNS.05.svg │ ├── moveGroupAttrsToElems.01.svg │ ├── cleanupIDs.02.svg │ ├── inlineStyles.07.svg │ ├── removeNonInheritableGroupAttrs.01.svg │ ├── moveElemsAttrsToGroup.05.svg │ ├── inlineStyles.05.svg │ ├── convertPathData.19.svg │ ├── inlineStyles.08.svg │ ├── moveElemsAttrsToGroup.03.svg │ ├── removeAttributesBySelector.03.svg │ ├── convertPathData.05.svg │ ├── removeElementsByAttr.03.svg │ ├── inlineStyles.09.svg │ ├── removeOffCanvasPaths.04.svg │ ├── collapseGroups.07.svg │ ├── minifyStyles.08.svg │ ├── moveGroupAttrsToElems.03.svg │ ├── cleanupEnableBackground.01.svg │ ├── cleanupListOfValues.03.svg │ ├── convertPathData.15.svg │ ├── minifyStyles.04.svg │ ├── collapseGroups.13.svg │ ├── removeUnknownsAndDefaults.09.svg │ ├── removeOffCanvasPaths.02.svg │ ├── removeUnusedNS.04.svg │ ├── removeUnusedNS.06.svg │ ├── cleanupEnableBackground.02.svg │ ├── convertPathData.07.svg │ ├── mergePaths.01.svg │ ├── removeOffCanvasPaths.03.svg │ ├── removeUnusedNS.07.svg │ ├── removeOffCanvasPaths.05.svg │ ├── collapseGroups.15.svg │ ├── removeUnknownsAndDefaults.11.svg │ ├── sortAttrs.01.svg │ ├── cleanupIDs.11.svg │ ├── moveGroupAttrsToElems.06.svg │ ├── removeElementsByAttr.05.svg │ ├── removeUselessDefs.03.svg │ ├── minifyStyles.07.svg │ ├── minifyStyles.06.svg │ ├── minifyStyles.05.svg │ ├── removeRasterImages.01.svg │ ├── cleanupEnableBackground.03.svg │ ├── collapseGroups.14.svg │ ├── inlineStyles.06.svg │ ├── sortAttrs.02.svg │ ├── convertColors.04.svg │ ├── removeHiddenElems.03.svg │ ├── convertPathData.02.svg │ ├── removeElementsByAttr.06.svg │ ├── inlineStyles.17.svg │ ├── collapseGroups.09.svg │ ├── collapseGroups.11.svg │ ├── inlineStyles.03.svg │ ├── removeEmptyContainers.03.svg │ ├── removeRasterImages.02.svg │ ├── removeElementsByAttr.02.svg │ ├── removeScriptElement.01.svg │ ├── removeUnknownsAndDefaults.07.svg │ ├── removeElementsByAttr.01.svg │ ├── removeEmptyContainers.02.svg │ ├── convertPathData.17.svg │ ├── moveGroupAttrsToElems.04.svg │ ├── prefixIds.04.svg │ ├── convertPathData.09.svg │ ├── minifyStyles.10.svg │ ├── minifyStyles.01.svg │ ├── cleanupIDs.16.svg │ ├── cleanupIDs.18.svg │ ├── cleanupIDs.08.svg │ ├── prefixIds.01.svg │ ├── prefixIds.09.svg │ ├── cleanupIDs.17.svg │ ├── prefixIds.07.svg │ ├── removeUselessStrokeAndFill.02_.svg │ ├── prefixIds.08.svg │ ├── removeStyleElement.01.svg │ ├── cleanupIDs.12.svg │ ├── prefixIds.02.svg │ ├── removeUnknownsAndDefaults.08.svg │ ├── convertTransform.04.svg │ ├── cleanupIDs.15.svg │ ├── minifyStyles.02.svg │ ├── convertTransform.03.svg │ ├── removeElementsByAttr.04.svg │ ├── minifyStyles.09.svg │ ├── removeUnknownsAndDefaults.05.svg │ ├── convertPathData.04.svg │ ├── moveElemsAttrsToGroup.07.svg │ ├── removeHiddenElems.08.svg │ ├── cleanupIDs.09.svg │ ├── removeAttrs.01.svg │ ├── cleanupIDs.13.svg │ ├── convertShapeToPath.03.svg │ ├── minifyStyles.03.svg │ ├── removeUselessStrokeAndFill.03.svg │ ├── collapseGroups.10.svg │ ├── reusePaths.02.svg │ ├── convertPathData.01.svg │ ├── convertTransform.02.svg │ ├── inlineStyles.14.svg │ ├── convertShapeToPath.01.svg │ ├── removeAttrs.02.svg │ ├── cleanupIDs.05.svg │ ├── cleanupIDs.19.svg │ ├── prefixIds.10.svg │ ├── cleanupListOfValues.02.svg │ ├── sortDefsChildren.01.svg │ ├── convertPathData.06.svg │ ├── removeAttrs.03.svg │ ├── convertPathData.12.svg │ ├── removeUselessStrokeAndFill.02.svg │ ├── cleanupIDs.10.svg │ ├── cleanupIDs.14.svg │ ├── moveElemsAttrsToGroup.04.svg │ ├── removeUselessDefs.02.svg │ ├── removeAttrs.05.svg │ ├── removeAttrs.04.svg │ ├── mergePaths.03.svg │ ├── mergePaths.02.svg │ ├── convertPathData.14.svg │ ├── reusePaths.01.svg │ ├── convertPathData.08.svg │ ├── prefixIds.06.svg │ ├── _index.js │ ├── convertPathData.03.svg │ ├── inlineStyles.16.svg │ ├── prefixIds.05.svg │ ├── cleanupIDs.01.svg │ ├── removeUselessStrokeAndFill.01.svg │ ├── collapseGroups.12.svg │ └── cleanupIDs.20.svg ├── svgo │ ├── test.svg │ └── _index.js ├── svg2js │ ├── test.entities.svg │ ├── test.bad.svg │ └── test.svg └── jsapi │ └── _index.js ├── .eslintrc.js ├── bin └── svgo ├── examples └── test.svg ├── .prettierrc.js ├── .gitignore ├── .npmignore ├── .travis.yml ├── lib ├── optimize.js ├── get-svgo-instance.js └── svgo │ └── css-select-adapter.js ├── plugins ├── removeMetadata.js ├── removeTitle.js ├── removeScriptElement.js ├── removeStyleElement.js ├── removeEmptyAttrs.js ├── removeXMLProcInst.js ├── removeComments.js ├── removeRasterImages.js ├── removeXMLNS.js ├── removeEmptyContainers.js ├── removeDesc.js ├── removeNonInheritableGroupAttrs.js ├── convertEllipseToCircle.js ├── removeDoctype.js ├── removeUselessDefs.js ├── removeEmptyText.js ├── removeViewBox.js ├── removeDimensions.js ├── addClassesToSVGElement.js ├── cleanupAttrs.js ├── sortDefsChildren.js ├── removeEditorsNSData.js ├── moveGroupAttrsToElems.js ├── removeAttributesBySelector.js └── sortAttrs.js ├── Makefile ├── defaults.js └── package.json /test/coa/testFolderWithNoSvg/test: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['airbnb-base'], 3 | }; 4 | -------------------------------------------------------------------------------- /bin/svgo: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('../lib/svgo/coa').run(); 4 | -------------------------------------------------------------------------------- /examples/test.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | printWidth: 100, 3 | singleQuote: true, 4 | trailingComma: 'es5', 5 | }; 6 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --reporter spec 2 | --require should 3 | test/config 4 | test/svg2js 5 | test/plugins 6 | test/jsapi 7 | test/svgo 8 | test/coa 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | lib-cov/ 3 | html-report/ 4 | lcov.info 5 | bin/svgo-profiling 6 | *.sublime-* 7 | *.log 8 | .DS_Store 9 | .idea 10 | .vscode 11 | .npmrc 12 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | docs 2 | examples 3 | test 4 | lib-cov 5 | .editorconfig 6 | .gitignore 7 | .jshintignore 8 | .jshintrc 9 | .travis.yml 10 | lcov.info 11 | logo.svg 12 | CHANGELOG.MD 13 | -------------------------------------------------------------------------------- /test/plugins/removeEmptyAttrs.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/removeUnknownsAndDefaults.13.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/convertColors.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/removeTitle.01.svg: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | 5 | 6 | @@@ 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/plugins/removeMetadata.01.svg: -------------------------------------------------------------------------------- 1 | 2 | ... 3 | 4 | 5 | 6 | @@@ 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - 6 5 | - 8 6 | - 10 7 | - 12 8 | 9 | branches: 10 | only: 11 | - master 12 | 13 | before_install: 14 | - npm install -g jshint 15 | 16 | script: make travis 17 | -------------------------------------------------------------------------------- /lib/optimize.js: -------------------------------------------------------------------------------- 1 | const getSvgoInstance = require('./get-svgo-instance'); 2 | 3 | const svgo = getSvgoInstance(); 4 | 5 | module.exports = function optimize(svgString) { 6 | return svgo.optimize(svgString).then((r) => r.data); 7 | }; 8 | -------------------------------------------------------------------------------- /test/plugins/removeDesc.01.svg: -------------------------------------------------------------------------------- 1 | 2 | Created with Sketch. 3 | 4 | 5 | 6 | @@@ 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/plugins/removeEmptyText.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/removeEmptyText.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/removeHiddenElems.09.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/removeHiddenElems.10.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/removeDimensions.04.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | 5 | @@@ 6 | 7 | 8 | test 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/removeEmptyText.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | ... 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/removeXMLProcInst.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | test 4 | 5 | 6 | @@@ 7 | 8 | 9 | test 10 | 11 | -------------------------------------------------------------------------------- /test/plugins/removeDimensions.05.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | 5 | @@@ 6 | 7 | 8 | test 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/removeComments.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | test 4 | 5 | 6 | @@@ 7 | 8 | 9 | 10 | test 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/removeDimensions.03.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | 5 | @@@ 6 | 7 | 8 | test 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/removeHiddenElems.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/removeHiddenElems.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/cleanupAttrs.01.svg: -------------------------------------------------------------------------------- 1 | 4 | test 5 | 6 | 7 | @@@ 8 | 9 | 10 | test 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/removeComments.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /test/plugins/removeDimensions.02.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | 5 | @@@ 6 | 7 | 8 | test 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/addAttributesToSVGElement.02.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | 5 | @@@ 6 | 7 | 8 | test 9 | 10 | 11 | @@@ 12 | 13 | {"attribute":"data-icon"} 14 | -------------------------------------------------------------------------------- /test/plugins/removeViewBox.03.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | 5 | @@@ 6 | 7 | 8 | test 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/removeDimensions.01.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | 5 | @@@ 6 | 7 | 8 | test 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/removeHiddenElems.04.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /test/plugins/removeViewBox.01.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | 5 | @@@ 6 | 7 | 8 | test 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.10.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/removeHiddenElems.05.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /test/plugins/removeHiddenElems.07.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /test/plugins/removeHiddenElems.06.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /test/plugins/removeUnknownsAndDefaults.14.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | 11 | @@@ 12 | 13 | { "keepRoleAttr": true } 14 | -------------------------------------------------------------------------------- /test/plugins/removeViewBox.02.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | 5 | @@@ 6 | 7 | 8 | test 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/addClassesToSVGElement.01.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | 5 | @@@ 6 | 7 | 8 | test 9 | 10 | 11 | @@@ 12 | 13 | {"classNames":["mySvg","size-big"]} 14 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | @@@ 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/plugins/removeViewBox.04.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | 5 | @@@ 6 | 7 | 8 | test 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/removeDoctype.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | test 4 | 5 | 6 | @@@ 7 | 8 | 9 | test 10 | 11 | -------------------------------------------------------------------------------- /test/plugins/removeUnusedNS.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | test 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | test 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/plugins/removeUselessDefs.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/plugins/addAttributesToSVGElement.01.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | 5 | @@@ 6 | 7 | 8 | test 9 | 10 | 11 | @@@ 12 | 13 | {"attributes":["data-icon","className={classes}"]} 14 | -------------------------------------------------------------------------------- /test/plugins/cleanupAttrs.02.svg: -------------------------------------------------------------------------------- 1 | 3 | test & <& > ' " & 4 | 5 | 6 | @@@ 7 | 8 | 9 | test & <& > ' " & 10 | 11 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | @@@ 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/plugins/removeXMLProcInst.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | test 4 | 5 | 6 | @@@ 7 | 8 | 9 | 10 | test 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/convertColors.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @@@ 7 | 8 | 9 | 10 | 11 | 12 | 13 | @@@ 14 | 15 | { "shorthex": false } 16 | -------------------------------------------------------------------------------- /test/plugins/addAttributesToSVGElement.03.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | 5 | @@@ 6 | 7 | 8 | test 9 | 10 | 11 | @@@ 12 | 13 | {"attributes":[{"focusable":"false"},{"data-image":"icon"}]} 14 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/prefixIds.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/removeEmptyContainers.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | @@@ 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | @@@ 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.16.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | @@@ 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/plugins/convertEllipseToCircle.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/plugins/cleanupEnableBackground.04.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | test 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | test 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/plugins/cleanupListOfValues.01.svg: -------------------------------------------------------------------------------- 1 | 2 | test 3 | 4 | 5 | @@@ 6 | 7 | 8 | test 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/removeUnknownsAndDefaults.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/plugins/removeNonInheritableGroupAttrs.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.13.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.20.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/removeUnusedNS.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | test 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | test 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/plugins/convertStyleToAttrs.04.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.04.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/plugins/removeEditorsNSData.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | ... 4 | 5 | 6 | 7 | 8 | 9 | @@@ 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/plugins/removeEditorsNSData.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | ... 4 | 5 | 6 | 7 | 8 | 9 | @@@ 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /test/plugins/cleanupNumericValues.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/convertStyleToAttrs.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.05.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/plugins/removeUnknownsAndDefaults.06.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/plugins/convertShapeToPath.04.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @@@ 7 | 8 | 9 | 10 | 11 | 12 | 13 | @@@ 14 | 15 | { "convertArcs": true } 16 | -------------------------------------------------------------------------------- /test/plugins/cleanupNumericValues.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.06.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.04.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | @@@ 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/plugins/moveGroupAttrsToElems.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/plugins/convertStyleToAttrs.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @@@ 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.18.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.10.svg: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/plugins/removeUnknownsAndDefaults.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @@@ 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/removeUnknownsAndDefaults.04.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | @@@ 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/svgo/test.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/plugins/convertStyleToAttrs.05.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | 11 | @@@ 12 | 13 | { "keepImportant": true } 14 | -------------------------------------------------------------------------------- /test/plugins/moveElemsAttrsToGroup.06.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/plugins/moveGroupAttrsToElems.05.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/plugins/convertStyleToAttrs.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @@@ 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.12.svg: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | 14 | @@@ 15 | 16 | {"usePseudos":[":hover"]} 17 | -------------------------------------------------------------------------------- /test/plugins/moveElemsAttrsToGroup.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | text 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | text 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.08.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/plugins/removeAttributesBySelector.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | 11 | @@@ 12 | 13 | { "selector": "[fill='#00ff00']", "attributes": ["fill", "stroke"] } 14 | -------------------------------------------------------------------------------- /test/plugins/removeAttributesBySelector.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | 11 | @@@ 12 | 13 | { "selector": "[fill='#00ff00']", "attributes": "fill" } 14 | -------------------------------------------------------------------------------- /test/plugins/removeUnknownsAndDefaults.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | test 4 | 5 | 6 | test 7 | 8 | 9 | test 10 | 11 | 12 | 13 | @@@ 14 | 15 | 16 | 17 | test 18 | 19 | 20 | test 21 | 22 | 23 | -------------------------------------------------------------------------------- /test/plugins/moveElemsAttrsToGroup.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | text 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | text 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /plugins/removeMetadata.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'removes '; 6 | 7 | /** 8 | * Remove . 9 | * 10 | * http://www.w3.org/TR/SVG/metadata.html 11 | * 12 | * @param {Object} item current iteration item 13 | * @return {Boolean} if false, item will be filtered out 14 | * 15 | * @author Kir Belevich 16 | */ 17 | exports.fn = function (item) { 18 | return !item.isElem('metadata'); 19 | }; 20 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/plugins/removeUnknownsAndDefaults.12.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | Title 4 | 5 | 6 | test 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | Title 15 | 16 | 17 | test 18 | 19 | 20 | 21 | @@@ 22 | 23 | { "keepAriaAttrs": false } 24 | -------------------------------------------------------------------------------- /test/plugins/removeOffCanvasPaths.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | @@@ 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /plugins/removeTitle.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'removes '; 6 | 7 | /** 8 | * Remove <title>. 9 | * 10 | * https://developer.mozilla.org/en-US/docs/Web/SVG/Element/title 11 | * 12 | * @param {Object} item current iteration item 13 | * @return {Boolean} if false, item will be filtered out 14 | * 15 | * @author Igor Kalashnikov 16 | */ 17 | exports.fn = function (item) { 18 | return !item.isElem('title'); 19 | }; 20 | -------------------------------------------------------------------------------- /test/plugins/convertShapeToPath.02.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <line x2="100%" y2="100%"/> 3 | <line x1="24" y2="24"/> 4 | <line x1="10" y1="10" x2="50" y2="20"/> 5 | <line stroke="#000" x1="10" y1="10" x2="50" y2="20"/> 6 | </svg> 7 | 8 | @@@ 9 | 10 | <svg xmlns="http://www.w3.org/2000/svg"> 11 | <line x2="100%" y2="100%"/> 12 | <path d="M24 0L0 24"/> 13 | <path d="M10 10L50 20"/> 14 | <path stroke="#000" d="M10 10L50 20"/> 15 | </svg> 16 | -------------------------------------------------------------------------------- /test/plugins/removeUnknownsAndDefaults.10.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <g transform="translate(792)"> 3 | <g transform="translate(792)"> 4 | <path d="M118.8 186.9l79.2"/> 5 | </g> 6 | </g> 7 | </svg> 8 | 9 | @@@ 10 | 11 | <svg xmlns="http://www.w3.org/2000/svg"> 12 | <g transform="translate(792)"> 13 | <g transform="translate(792)"> 14 | <path d="M118.8 186.9l79.2"/> 15 | </g> 16 | </g> 17 | </svg> 18 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.06.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> 2 | <style> 3 | … 4 | </style> 5 | <circle id="circle001" fill="red" cx="60" cy="60" r="50"/> 6 | </svg> 7 | 8 | @@@ 9 | 10 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> 11 | <style> 12 | … 13 | </style> 14 | <circle fill="red" cx="60" cy="60" r="50"/> 15 | </svg> 16 | 17 | @@@ 18 | 19 | {"force": true} 20 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.16.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <path d="M.49 8.8c-.3-.75-.44-1.55-.44-2.35 0-3.54 2.88-6.43 6.43-6.43 3.53 0 6.42 2.88 6.42 6.43 0 .8-.15 1.6-.43 2.35"/> 3 | <path d="M13.4 6.62c0-2.5-1.98-4.57-4.4-4.57S4.6 4.1 4.6 6.62"/> 4 | </svg> 5 | 6 | @@@ 7 | 8 | <svg xmlns="http://www.w3.org/2000/svg"> 9 | <path d="M0 9V6a6 6 0 1112 3"/> 10 | <path d="M13 7c0-3-2-5-4-5S5 4 5 7"/> 11 | </svg> 12 | 13 | @@@ 14 | 15 | { "floatPrecision": 0 } 16 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.07.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> 2 | <script> 3 | … 4 | </script> 5 | <circle id="circle001" fill="red" cx="60" cy="60" r="50"/> 6 | </svg> 7 | 8 | @@@ 9 | 10 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> 11 | <script> 12 | … 13 | </script> 14 | <circle fill="red" cx="60" cy="60" r="50"/> 15 | </svg> 16 | 17 | @@@ 18 | 19 | {"force": true} 20 | -------------------------------------------------------------------------------- /test/plugins/convertColors.01.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <g color="black"/> 3 | <g color="BLACK"/> 4 | <path fill="rgb(64, 64, 64)"/> 5 | <path fill="rgb(86.27451%,86.666667%,87.058824%)"/> 6 | <path fill="rgb(-255,100,500)"/> 7 | </svg> 8 | 9 | @@@ 10 | 11 | <svg xmlns="http://www.w3.org/2000/svg"> 12 | <g color="#000"/> 13 | <g color="#000"/> 14 | <path fill="#404040"/> 15 | <path fill="#DCDDDE"/> 16 | <path fill="#0064FF"/> 17 | </svg> 18 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.11.svg: -------------------------------------------------------------------------------- 1 | <svg id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> 2 | <style> 3 | .st0{fill:blue;} 4 | .st0:hover{stroke:red;} 5 | </style> 6 | <rect width="100" height="100" class="st0"/> 7 | </svg> 8 | 9 | @@@ 10 | 11 | <svg id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> 12 | <style> 13 | .st0:hover{stroke:red} 14 | </style> 15 | <rect width="100" height="100" style="fill:blue"/> 16 | </svg> 17 | -------------------------------------------------------------------------------- /test/plugins/removeUnusedNS.03.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:test="http://trololololololololololo.com/" xmlns:test2="http://trololololololololololo.com/"> 2 | <g test:attr="val"> 3 | <g> 4 | test 5 | </g> 6 | </g> 7 | </svg> 8 | 9 | @@@ 10 | 11 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:test="http://trololololololololololo.com/"> 12 | <g test:attr="val"> 13 | <g> 14 | test 15 | </g> 16 | </g> 17 | </svg> 18 | -------------------------------------------------------------------------------- /test/plugins/removeUnusedNS.05.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:test="http://trololololololololololo.com/" xmlns:test2="http://trololololololololololo.com/"> 2 | <g> 3 | <test:elem> 4 | test 5 | </test:elem> 6 | </g> 7 | </svg> 8 | 9 | @@@ 10 | 11 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:test="http://trololololololololololo.com/"> 12 | <g> 13 | <test:elem> 14 | test 15 | </test:elem> 16 | </g> 17 | </svg> 18 | -------------------------------------------------------------------------------- /test/plugins/moveGroupAttrsToElems.01.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <g transform="scale(2)"> 3 | <path transform="rotate(45)" d="M0,0 L10,20"/> 4 | <path transform="translate(10, 20)" d="M0,10 L20,30"/> 5 | </g> 6 | </svg> 7 | 8 | @@@ 9 | 10 | <svg xmlns="http://www.w3.org/2000/svg"> 11 | <g> 12 | <path transform="scale(2) rotate(45)" d="M0,0 L10,20"/> 13 | <path transform="scale(2) translate(10, 20)" d="M0,10 L20,30"/> 14 | </g> 15 | </svg> 16 | -------------------------------------------------------------------------------- /plugins/removeScriptElement.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = false; 4 | 5 | exports.description = 'removes <script> elements (disabled by default)'; 6 | 7 | /** 8 | * Remove <script>. 9 | * 10 | * https://www.w3.org/TR/SVG/script.html 11 | * 12 | * @param {Object} item current iteration item 13 | * @return {Boolean} if false, item will be filtered out 14 | * 15 | * @author Patrick Klingemann 16 | */ 17 | exports.fn = function (item) { 18 | return !item.isElem('script'); 19 | }; 20 | -------------------------------------------------------------------------------- /plugins/removeStyleElement.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = false; 4 | 5 | exports.description = 'removes <style> element (disabled by default)'; 6 | 7 | /** 8 | * Remove <style>. 9 | * 10 | * http://www.w3.org/TR/SVG/styling.html#StyleElement 11 | * 12 | * @param {Object} item current iteration item 13 | * @return {Boolean} if false, item will be filtered out 14 | * 15 | * @author Betsy Dupuis 16 | */ 17 | exports.fn = function (item) { 18 | return !item.isElem('style'); 19 | }; 20 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.02.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> 2 | <style> 3 | .cls-1 { fill: #fff; } 4 | </style> 5 | <circle id="circle001" fill="red" cx="60" cy="60" r="50"/> 6 | </svg> 7 | 8 | @@@ 9 | 10 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> 11 | <style> 12 | .cls-1 { fill: #fff; } 13 | </style> 14 | <circle id="circle001" fill="red" cx="60" cy="60" r="50"/> 15 | </svg> 16 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.07.svg: -------------------------------------------------------------------------------- 1 | <svg id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> 2 | <style> 3 | .red { 4 | fill: red !important; 5 | } 6 | .blue { 7 | fill: blue; 8 | } 9 | </style> 10 | <rect width="100" height="100" class="blue red"/> 11 | </svg> 12 | 13 | @@@ 14 | 15 | <svg id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> 16 | <rect width="100" height="100" style="fill:red!important"/> 17 | </svg> 18 | -------------------------------------------------------------------------------- /test/plugins/removeNonInheritableGroupAttrs.01.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <g class="test" clip-path="url(#clip1)" transform="rotate(45)" display="none" opacity="0.5" visibility="visible"> 3 | <path d="M0 0 L 10 20"/> 4 | </g> 5 | </svg> 6 | 7 | @@@ 8 | 9 | <svg xmlns="http://www.w3.org/2000/svg"> 10 | <g class="test" clip-path="url(#clip1)" transform="rotate(45)" display="none" opacity="0.5" visibility="visible"> 11 | <path d="M0 0 L 10 20"/> 12 | </g> 13 | </svg> 14 | -------------------------------------------------------------------------------- /test/plugins/moveElemsAttrsToGroup.05.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <g attr1="val1"> 3 | <g fill="red" color="#000" opacity="1"> 4 | text 5 | </g> 6 | <circle fill="red" color="#000" opacity="1"/> 7 | </g> 8 | </svg> 9 | 10 | @@@ 11 | 12 | <svg xmlns="http://www.w3.org/2000/svg"> 13 | <g attr1="val1" fill="red" color="#000"> 14 | <g opacity="1"> 15 | text 16 | </g> 17 | <circle opacity="1"/> 18 | </g> 19 | </svg> 20 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.05.svg: -------------------------------------------------------------------------------- 1 | <svg id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> 2 | <style> 3 | .st1 { 4 | fill: red; 5 | } 6 | .st0 { 7 | color: blue; 8 | } 9 | </style> 10 | <rect width="100" height="100" class="st0 st1" style="color:yellow"/> 11 | </svg> 12 | 13 | @@@ 14 | 15 | <svg id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> 16 | <rect width="100" height="100" style="color:yellow;fill:red"/> 17 | </svg> 18 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.19.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 500"> 2 | <path transform="translate(250, 250) scale(1.5, 1.5) translate(-250, -250)" fill="#7ED321" stroke="#000" stroke-width="15" vector-effect="non-scaling-stroke" d="M125 125h250v250h-250v-250z"/> 3 | </svg> 4 | 5 | @@@ 6 | 7 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 500"> 8 | <path fill="#7ED321" stroke="#000" stroke-width="15" vector-effect="non-scaling-stroke" d="M62.5 62.5h375v375h-375v-375z"/> 9 | </svg> 10 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.08.svg: -------------------------------------------------------------------------------- 1 | <svg id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> 2 | <style> 3 | .red { 4 | fill: red !important; 5 | } 6 | .blue { 7 | fill: blue; 8 | } 9 | </style> 10 | <rect width="100" height="100" class="blue red" style="fill:yellow"/> 11 | </svg> 12 | 13 | @@@ 14 | 15 | <svg id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> 16 | <rect width="100" height="100" style="fill:red!important"/> 17 | </svg> 18 | -------------------------------------------------------------------------------- /test/plugins/moveElemsAttrsToGroup.03.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <g attr1="val1"> 3 | <g attr2="val2"> 4 | text 5 | </g> 6 | <circle attr2="val2" attr3="val3"/> 7 | <path d="..."/> 8 | </g> 9 | </svg> 10 | 11 | @@@ 12 | 13 | <svg xmlns="http://www.w3.org/2000/svg"> 14 | <g attr1="val1"> 15 | <g attr2="val2"> 16 | text 17 | </g> 18 | <circle attr2="val2" attr3="val3"/> 19 | <path d="..."/> 20 | </g> 21 | </svg> 22 | -------------------------------------------------------------------------------- /test/plugins/removeAttributesBySelector.03.svg: -------------------------------------------------------------------------------- 1 | <svg id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> 2 | <rect id="remove" x="0" y="0" width="100" height="100" fill="#00ff00" stroke="#00ff00"/> 3 | </svg> 4 | 5 | @@@ 6 | 7 | <svg id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> 8 | <rect x="0" y="0" width="100" height="100"/> 9 | </svg> 10 | 11 | @@@ 12 | 13 | { "selectors": [{ "selector": "[fill='#00ff00']", "attributes": "fill" }, { "selector": "#remove", "attributes": ["stroke", "id"] }] } 14 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.05.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <path d="M 10.3467,50.09 L 10.0000,50.20"/> 3 | <path d="m 10 10 l 1 1 M 20 20"/> 4 | <path d="m 0 0 l .1133 1 l .1133 2 l .1133 3"/> 5 | <path d="m 0 0 l .0025 3 .0025 2 .0025 3 .0025 2"/> 6 | </svg> 7 | 8 | @@@ 9 | 10 | <svg xmlns="http://www.w3.org/2000/svg"> 11 | <path d="M10.347 50.09L10 50.2"/> 12 | <path d="M10 10l1 1m9 9"/> 13 | <path d="M0 0l.113 1 .114 2L.34 6"/> 14 | <path d="M0 0l.003 3 .002 2 .003 3 .002 2"/> 15 | </svg> 16 | -------------------------------------------------------------------------------- /test/plugins/removeElementsByAttr.03.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" width="19" height="19" viewBox="0 0 19 19"> 2 | <rect id="someID" width="19" height="19"/> 3 | <path id="anotherID" d="M1093.5,31.792l-0.72.721-8.27-8.286-8.28,8.286-0.72-.721,8.28-8.286-8.28-8.286,0.72-.721,8.28,8.286,8.27-8.286,0.72,0.721-8.27,8.286Z" transform="translate(-1075 -14)"/> 4 | </svg> 5 | 6 | @@@ 7 | 8 | <svg xmlns="http://www.w3.org/2000/svg" width="19" height="19" viewBox="0 0 19 19"/> 9 | 10 | @@@ 11 | 12 | { "id": ["someID", "anotherID"] } 13 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.09.svg: -------------------------------------------------------------------------------- 1 | <svg id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> 2 | <style> 3 | .red { 4 | fill: red !important; 5 | } 6 | .blue { 7 | fill: blue; 8 | } 9 | </style> 10 | <rect width="100" height="100" class="blue red" style="fill:yellow !important"/> 11 | </svg> 12 | 13 | @@@ 14 | 15 | <svg id="test" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> 16 | <rect width="100" height="100" style="fill:yellow!important"/> 17 | </svg> 18 | -------------------------------------------------------------------------------- /test/plugins/removeOffCanvasPaths.04.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"> 2 | <path d="M20.16 107.3l13.18-12.18m-1.6-5.41l-16.32 6.51M13 84.5h18m77 22.8L94.83 95.12m1.6-5.41l16.32 6.51M115 84.5H98" fill="none" stroke="#444" stroke-width="3"/> 3 | </svg> 4 | 5 | @@@ 6 | 7 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"> 8 | <path d="M20.16 107.3l13.18-12.18m-1.6-5.41l-16.32 6.51M13 84.5h18m77 22.8L94.83 95.12m1.6-5.41l16.32 6.51M115 84.5H98" fill="none" stroke="#444" stroke-width="3"/> 9 | </svg> 10 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.07.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <g attr1="val1"> 3 | <g attr2="val2"> 4 | <path attr2="val2" d="..."/> 5 | </g> 6 | <g attr2="val2"> 7 | <path attr2="val3" d="..."/> 8 | </g> 9 | </g> 10 | </svg> 11 | 12 | @@@ 13 | 14 | <svg xmlns="http://www.w3.org/2000/svg"> 15 | <g attr1="val1"> 16 | <path attr2="val2" d="..."/> 17 | <g attr2="val2"> 18 | <path attr2="val3" d="..."/> 19 | </g> 20 | </g> 21 | </svg> 22 | -------------------------------------------------------------------------------- /test/plugins/minifyStyles.08.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <style> 3 | .used { p: 1 } 4 | .unused { p: 2 } 5 | </style> 6 | <g class="used" onclick="/* on* attributes prevents removing unused styles */"> 7 | test 8 | </g> 9 | </svg> 10 | 11 | @@@ 12 | 13 | <svg xmlns="http://www.w3.org/2000/svg"> 14 | <style> 15 | .used{p:1}.unused{p:2} 16 | </style> 17 | <g class="used" onclick="/* on* attributes prevents removing unused styles */"> 18 | test 19 | </g> 20 | </svg> 21 | -------------------------------------------------------------------------------- /test/plugins/moveGroupAttrsToElems.03.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <g transform="rotate(30)"> 3 | <g transform="scale(2)"> 4 | <path d="M0,0 L10,20"/> 5 | <path d="M0,10 L20,30"/> 6 | </g> 7 | </g> 8 | </svg> 9 | 10 | @@@ 11 | 12 | <svg xmlns="http://www.w3.org/2000/svg"> 13 | <g> 14 | <g> 15 | <path d="M0,0 L10,20" transform="rotate(30) scale(2)"/> 16 | <path d="M0,10 L20,30" transform="rotate(30) scale(2)"/> 17 | </g> 18 | </g> 19 | </svg> 20 | -------------------------------------------------------------------------------- /test/plugins/cleanupEnableBackground.01.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" width="100.5" height=".5" enable-background="new 0 0 100.5 .5"> 2 | <defs> 3 | <filter id="ShiftBGAndBlur"> 4 | <feOffset dx="0" dy="75"/> 5 | </filter> 6 | </defs> 7 | test 8 | </svg> 9 | 10 | @@@ 11 | 12 | <svg xmlns="http://www.w3.org/2000/svg" width="100.5" height=".5"> 13 | <defs> 14 | <filter id="ShiftBGAndBlur"> 15 | <feOffset dx="0" dy="75"/> 16 | </filter> 17 | </defs> 18 | test 19 | </svg> 20 | -------------------------------------------------------------------------------- /test/plugins/cleanupListOfValues.03.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <text x="23.2350 20.2268px 0.22356em 80.0005%" y="23.2350 20.2268px 0.22356em 80.0005%" dx="23.2350 20.2268px 0.22356em 80.0005%" dy="23.2350 20.2268px 0.22356em 80.0005%"> 3 | test 4 | </text> 5 | </svg> 6 | 7 | @@@ 8 | 9 | <svg xmlns="http://www.w3.org/2000/svg"> 10 | <text x="23.235 20.227 .224em 80.001%" y="23.235 20.227 .224em 80.001%" dx="23.235 20.227 .224em 80.001%" dy="23.235 20.227 .224em 80.001%"> 11 | test 12 | </text> 13 | </svg> 14 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.15.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <path d="M.49 8.8c-.3-.75-.44-1.55-.44-2.35 0-3.54 2.88-6.43 6.43-6.43 3.53 0 6.42 2.88 6.42 6.43 0 .8-.15 1.6-.43 2.35"/> 3 | <path d="M13.4 6.62c0-2.5-1.98-4.57-4.4-4.57S4.6 4.1 4.6 6.62"/> 4 | </svg> 5 | 6 | @@@ 7 | 8 | <svg xmlns="http://www.w3.org/2000/svg"> 9 | <path d="M.49 8.8A6.44 6.44 0 016.48.02a6.44 6.44 0 015.99 8.78"/> 10 | <path d="M13.4 6.62c0-2.5-1.98-4.57-4.4-4.57S4.6 4.1 4.6 6.62"/> 11 | </svg> 12 | 13 | @@@ 14 | 15 | { "floatPrecision": 2 } 16 | -------------------------------------------------------------------------------- /test/plugins/minifyStyles.04.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <style> 3 | .used { p: 1 } 4 | .unused { p: 2 } 5 | #used { p: 3 } 6 | #unused { p: 4 } 7 | g { p: 5 } 8 | unused { p: 6 } 9 | </style> 10 | <g id="used" class="used"> 11 | test 12 | </g> 13 | </svg> 14 | 15 | @@@ 16 | 17 | <svg xmlns="http://www.w3.org/2000/svg"> 18 | <style> 19 | .used{p:1}#used{p:3}g{p:5} 20 | </style> 21 | <g id="used" class="used"> 22 | test 23 | </g> 24 | </svg> 25 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.13.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <style> 3 | .n{display:none} 4 | .i{display:inline} 5 | </style> 6 | <g id="a"> 7 | <g class="i"/> 8 | </g> 9 | <g id="b" class="n"> 10 | <g class="i"/> 11 | </g> 12 | </svg> 13 | 14 | @@@ 15 | 16 | <svg xmlns="http://www.w3.org/2000/svg"> 17 | <style> 18 | .n{display:none} .i{display:inline} 19 | </style> 20 | <g class="i" id="a"/> 21 | <g id="b" class="n"> 22 | <g class="i"/> 23 | </g> 24 | </svg> 25 | -------------------------------------------------------------------------------- /plugins/removeEmptyAttrs.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'removes empty attributes'; 6 | 7 | /** 8 | * Remove attributes with empty values. 9 | * 10 | * @param {Object} item current iteration item 11 | * @return {Boolean} if false, item will be filtered out 12 | * 13 | * @author Kir Belevich 14 | */ 15 | exports.fn = function (item) { 16 | if (item.elem) { 17 | item.eachAttr((attr) => { 18 | if (attr.value === '') { 19 | item.removeAttr(attr.name); 20 | } 21 | }); 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /plugins/removeXMLProcInst.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'removes XML processing instructions'; 6 | 7 | /** 8 | * Remove XML Processing Instruction. 9 | * 10 | * @example 11 | * <?xml version="1.0" encoding="utf-8"?> 12 | * 13 | * @param {Object} item current iteration item 14 | * @return {Boolean} if false, item will be filtered out 15 | * 16 | * @author Kir Belevich 17 | */ 18 | exports.fn = function (item) { 19 | return !(item.processinginstruction && item.processinginstruction.name === 'xml'); 20 | }; 21 | -------------------------------------------------------------------------------- /test/plugins/removeUnknownsAndDefaults.09.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <metadata> 3 | <sfw> 4 | <slices></slices> 5 | <sliceSourceBounds height="67.3" width="85.9" y="-40.8" x="-42.5" bottomLeftOrigin="true"></sliceSourceBounds> 6 | </sfw> 7 | <ellipse/> 8 | </metadata> 9 | <ellipse> 10 | <font-face/> 11 | </ellipse> 12 | </svg> 13 | 14 | @@@ 15 | 16 | <svg xmlns="http://www.w3.org/2000/svg"> 17 | <metadata> 18 | <ellipse/> 19 | </metadata> 20 | <ellipse/> 21 | </svg> 22 | -------------------------------------------------------------------------------- /test/plugins/removeOffCanvasPaths.02.svg: -------------------------------------------------------------------------------- 1 | <svg height="1000" width="1000" xmlns="http://www.w3.org/2000/svg"> 2 | <path d="M10 10 h 80 v 80 h -80 z"/> 3 | <path d="M10 -90 h 80 v 80 h -80 z"/> 4 | <path d="M110 10 h 80 v 80 h -80 z"/> 5 | <path d="M10 110 h 80 v 80 h -80 z"/> 6 | <path d="M-90 10 h 80 v 80 h -80 z"/> 7 | </svg> 8 | 9 | @@@ 10 | 11 | <svg height="1000" width="1000" xmlns="http://www.w3.org/2000/svg"> 12 | <path d="M10 10 h 80 v 80 h -80 z"/> 13 | <path d="M110 10 h 80 v 80 h -80 z"/> 14 | <path d="M10 110 h 80 v 80 h -80 z"/> 15 | </svg> 16 | -------------------------------------------------------------------------------- /test/plugins/removeUnusedNS.04.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:test="http://trololololololololololo.com/" xmlns:test2="http://trololololololololololo.com/"> 2 | <g test:attr="val"> 3 | <g test2:attr="val"> 4 | test 5 | </g> 6 | </g> 7 | </svg> 8 | 9 | @@@ 10 | 11 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:test="http://trololololololololololo.com/" xmlns:test2="http://trololololololololololo.com/"> 12 | <g test:attr="val"> 13 | <g test2:attr="val"> 14 | test 15 | </g> 16 | </g> 17 | </svg> 18 | -------------------------------------------------------------------------------- /test/plugins/removeUnusedNS.06.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:test="http://trololololololololololo.com/" xmlns:test2="http://trololololololololololo.com/"> 2 | <test:elem> 3 | <test2:elem> 4 | test 5 | </test2:elem> 6 | </test:elem> 7 | </svg> 8 | 9 | @@@ 10 | 11 | <svg xmlns="http://www.w3.org/2000/svg" xmlns:test="http://trololololololololololo.com/" xmlns:test2="http://trololololololololololo.com/"> 12 | <test:elem> 13 | <test2:elem> 14 | test 15 | </test2:elem> 16 | </test:elem> 17 | </svg> 18 | -------------------------------------------------------------------------------- /test/plugins/cleanupEnableBackground.02.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" enable-background="new 0 0 100 50"> 2 | <defs> 3 | <filter id="ShiftBGAndBlur"> 4 | <feOffset dx="0" dy="75"/> 5 | </filter> 6 | </defs> 7 | test 8 | </svg> 9 | 10 | @@@ 11 | 12 | <svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" enable-background="new 0 0 100 50"> 13 | <defs> 14 | <filter id="ShiftBGAndBlur"> 15 | <feOffset dx="0" dy="75"/> 16 | </filter> 17 | </defs> 18 | test 19 | </svg> 20 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.07.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <path d="m 0,0"/> 3 | <path d="m 0,0l 0,0"/> 4 | <path d="m 0,0h 0"/> 5 | <path d="m 0,0v 0"/> 6 | <path d="m 0,0c 0,0 0,0 0,0 s 0,0 0,0"/> 7 | <path d="m 0,0q 0,0 0,0 t 0,0"/> 8 | <path d="m 0,0a 25,25 -30 0,1 0,0"/> 9 | </svg> 10 | 11 | @@@ 12 | 13 | <svg xmlns="http://www.w3.org/2000/svg"> 14 | <path d="M0 0"/> 15 | <path d="M0 0"/> 16 | <path d="M0 0"/> 17 | <path d="M0 0"/> 18 | <path d="M0 0"/> 19 | <path d="M0 0"/> 20 | <path d="M0 0"/> 21 | </svg> 22 | -------------------------------------------------------------------------------- /test/plugins/mergePaths.01.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <path d="M 0,0 z"/> 3 | <path d="M 10,10 z"/> 4 | <path d="M 20,20 l 10,10 M 30,0 c 10,0 20,10 20,20"/> 5 | <path d="M 30,30 z"/> 6 | <path d="M 30,30 z" fill="#f00"/> 7 | <path d="M 40,40 z"/> 8 | <path d="m 50,50 0,10 20,30 40,0"/> 9 | </svg> 10 | 11 | @@@ 12 | 13 | <svg xmlns="http://www.w3.org/2000/svg"> 14 | <path d="M0 0zM10 10zM20 20l10 10M30 0c10 0 20 10 20 20M30 30z"/> 15 | <path d="M 30,30 z" fill="#f00"/> 16 | <path d="M40 40zM50 50l0 10 20 30 40 0"/> 17 | </svg> 18 | -------------------------------------------------------------------------------- /test/plugins/removeOffCanvasPaths.03.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"> 2 | <path d="M0 0h128v128H0z" fill="none" stroke="red"/> 3 | <path d="M10.14 51.5c4.07 1.56 7.52 4.47 7.37 11.16" fill="none" stroke="#00f"/> 4 | <path d="M100 200c4.07 1.56 7.52 4.47 7.37 11.16" fill="none" stroke="#00f"/> 5 | </svg> 6 | 7 | @@@ 8 | 9 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"> 10 | <path d="M0 0h128v128H0z" fill="none" stroke="red"/> 11 | <path d="M10.14 51.5c4.07 1.56 7.52 4.47 7.37 11.16" fill="none" stroke="#00f"/> 12 | </svg> 13 | -------------------------------------------------------------------------------- /test/plugins/removeUnusedNS.07.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" inkscape:version="0.92.2 (5c3e80d, 2017-08-06)" sodipodi:docname="test.svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"> 2 | test 3 | </svg> 4 | 5 | @@@ 6 | 7 | <svg xmlns="http://www.w3.org/2000/svg" inkscape:version="0.92.2 (5c3e80d, 2017-08-06)" sodipodi:docname="test.svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"> 8 | test 9 | </svg> 10 | -------------------------------------------------------------------------------- /test/plugins/removeOffCanvasPaths.05.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> 2 | <path d="M-100-100h50v50h-50z" fill="red" transform="translate(100 100)"/> 3 | <g transform="translate(150 150)"> 4 | <path d="M-100-100h50v50h-50z" fill="blue"/> 5 | </g> 6 | </svg> 7 | 8 | @@@ 9 | 10 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> 11 | <path d="M-100-100h50v50h-50z" fill="red" transform="translate(100 100)"/> 12 | <g transform="translate(150 150)"> 13 | <path d="M-100-100h50v50h-50z" fill="blue"/> 14 | </g> 15 | </svg> 16 | -------------------------------------------------------------------------------- /plugins/removeComments.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'removes comments'; 6 | 7 | /** 8 | * Remove comments. 9 | * 10 | * @example 11 | * <!-- Generator: Adobe Illustrator 15.0.0, SVG Export 12 | * Plug-In . SVG Version: 6.00 Build 0) --> 13 | * 14 | * @param {Object} item current iteration item 15 | * @return {Boolean} if false, item will be filtered out 16 | * 17 | * @author Kir Belevich 18 | */ 19 | exports.fn = function (item) { 20 | if (item.comment && item.comment.charAt(0) !== '!') { 21 | return false; 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.15.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg"> 2 | <g color="red"> 3 | <g color="inherit" fill="none" stroke="none"> 4 | <circle cx="130" cy="80" r="60" fill="currentColor"/> 5 | <circle cx="350" cy="80" r="60" stroke="currentColor" stroke-width="4"/> 6 | </g> 7 | </g> 8 | </svg> 9 | 10 | @@@ 11 | 12 | <svg xmlns="http://www.w3.org/2000/svg"> 13 | <g color="red" fill="none" stroke="none"> 14 | <circle cx="130" cy="80" r="60" fill="currentColor"/> 15 | <circle cx="350" cy="80" r="60" stroke="currentColor" stroke-width="4"/> 16 | </g> 17 | </svg> -------------------------------------------------------------------------------- /test/plugins/removeUnknownsAndDefaults.11.svg: -------------------------------------------------------------------------------- 1 | <svg xmlns="http://www.w3.org/2000/svg" aria-labelledby="title"> 2 | <title id="title"> 3 | Title 4 | 5 | 6 | test 7 | 8 | 9 | 10 | 11 | 12 | @@@ 13 | 14 | 15 | 16 | Title 17 | 18 | 19 | test 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/plugins/sortAttrs.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | test 4 | 5 | 6 | @@@ 7 | 8 | 9 | 10 | test 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.11.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | @@@ 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/plugins/moveGroupAttrsToElems.06.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | test: 2 | @npm run test 3 | 4 | lib-cov: 5 | @./node_modules/.bin/istanbul instrument --output lib-cov --no-compact --variable global.__coverage__ lib 6 | 7 | coverage: lib-cov 8 | @COVERAGE=1 ISTANBUL_REPORTERS=text-summary ./node_modules/.bin/mocha --reporter mocha-istanbul 9 | @rm -rf lib-cov 10 | 11 | coveralls: lib-cov 12 | @COVERAGE=1 ISTANBUL_REPORTERS=lcovonly ./node_modules/.bin/mocha --reporter mocha-istanbul 13 | @cat lcov.info | ./node_modules/.bin/coveralls 14 | @rm -rf lib-cov lcov.info 15 | 16 | travis: lint test coveralls 17 | 18 | lint: 19 | @npm run lint 20 | 21 | .PHONY: test 22 | -------------------------------------------------------------------------------- /test/plugins/removeElementsByAttr.05.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | @@@ 12 | 13 | { "class": ["someClass", "anotherClass"] } 14 | -------------------------------------------------------------------------------- /plugins/removeRasterImages.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = false; 4 | 5 | exports.description = 'removes raster images (disabled by default)'; 6 | 7 | /** 8 | * Remove raster images references in . 9 | * 10 | * @see https://bugs.webkit.org/show_bug.cgi?id=63548 11 | * 12 | * @param {Object} item current iteration item 13 | * @return {Boolean} if false, item will be filtered out 14 | * 15 | * @author Kir Belevich 16 | */ 17 | exports.fn = function (item) { 18 | if (item.isElem('image') && item.hasAttrLocal('href', /(\.|image\/)(jpg|png|gif)/)) { 19 | return false; 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /test/plugins/removeUselessDefs.03.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/minifyStyles.07.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 9 | 10 | test 11 | 12 | 13 | 14 | @@@ 15 | 16 | 17 | 20 | 23 | 24 | test 25 | 26 | 27 | -------------------------------------------------------------------------------- /test/plugins/minifyStyles.06.svg: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | test 12 | 13 | 14 | 15 | @@@ 16 | 17 | 18 | 21 | 22 | test 23 | 24 | 25 | 26 | @@@ 27 | 28 | {"usage":false} 29 | -------------------------------------------------------------------------------- /test/plugins/minifyStyles.05.svg: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | test 12 | 13 | 14 | 15 | @@@ 16 | 17 | 18 | 21 | 22 | test 23 | 24 | 25 | 26 | @@@ 27 | 28 | {"usage":{"ids":false,"tags":false}} 29 | -------------------------------------------------------------------------------- /test/plugins/removeRasterImages.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/plugins/cleanupEnableBackground.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | test 9 | 10 | 11 | 12 | @@@ 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | test 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.14.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.06.svg: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | @@@ 15 | 16 | 17 | 18 | 19 | 20 | 21 | @@@ 22 | 23 | {"onlyMatchedOnce":false} 24 | -------------------------------------------------------------------------------- /test/plugins/sortAttrs.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | test 4 | 5 | 6 | @@@ 7 | 8 | 9 | 10 | test 11 | 12 | 13 | @@@ 14 | 15 | { "xmlnsOrder": "alphabetical" } 16 | -------------------------------------------------------------------------------- /test/plugins/convertColors.04.svg: -------------------------------------------------------------------------------- 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 | { "currentColor": true } -------------------------------------------------------------------------------- /plugins/removeXMLNS.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = false; 4 | 5 | exports.description = 'removes xmlns attribute (for inline svg, disabled by default)'; 6 | 7 | /** 8 | * Remove the xmlns attribute when present. 9 | * 10 | * @example 11 | * 12 | * ↓ 13 | * 14 | * 15 | * @param {Object} item current iteration item 16 | * @return {Boolean} if true, xmlns will be filtered out 17 | * 18 | * @author Ricardo Tomasi 19 | */ 20 | exports.fn = function (item) { 21 | if (item.isElem('svg') && item.hasAttr('xmlns')) { 22 | item.removeAttr('xmlns'); 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /test/plugins/removeHiddenElems.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/plugins/removeElementsByAttr.06.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | 14 | @@@ 15 | 16 | { "id": "someID", "class": "someClass" } 17 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.17.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
hello, world
5 |
6 |
7 | 8 | @@@ 9 | 10 | 11 | 12 | 15 | 16 |
17 | hello, world 18 |
19 | 20 |
21 |
22 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.09.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.11.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | @@@ 17 | 18 | 19 | 20 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /test/plugins/removeEmptyContainers.03.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/removeRasterImages.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/plugins/removeElementsByAttr.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @@@ 7 | 8 | 9 | 10 | 11 | 12 | @@@ 13 | 14 | { "id": "someID" } 15 | -------------------------------------------------------------------------------- /test/plugins/removeScriptElement.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @@@ 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /test/plugins/removeUnknownsAndDefaults.07.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | fallback test 5 |
6 |
7 | 8 | 9 | test 10 | 11 | 12 | test 13 | 14 | 15 | test 16 | 17 |
18 | 19 | @@@ 20 | 21 | 22 | 23 |
24 | fallback test 25 |
26 |
27 | 28 | test 29 | 30 | 31 | test 32 | 33 |
34 | -------------------------------------------------------------------------------- /test/plugins/removeElementsByAttr.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @@@ 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/plugins/removeEmptyContainers.02.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/svg2js/test.entities.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | ]> 8 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.17.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @@@ 6 | 7 | 8 | 9 | 10 | 11 | @@@ 12 | 13 | { "floatPrecision": 8 } 14 | -------------------------------------------------------------------------------- /test/plugins/moveGroupAttrsToElems.04.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/prefixIds.04.svg: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | @@@ 15 | 16 | 17 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.09.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | @@@ 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/plugins/minifyStyles.10.svg: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | tell stories in 250 characters 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 16 | 17 | tell stories in 250 characters 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/svg2js/test.bad.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | style type="text/css"> 10 | svg { fill: red; } 11 | 12 | 13 | 14 | 15 | test 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /test/plugins/minifyStyles.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.16.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | @@@ 22 | 23 | {"preserve": "a"} 24 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.18.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | @@@ 22 | 23 | {"preservePrefixes": "a"} 24 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.08.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | @@@ 18 | 19 | {"preserve": ["circle", "rect"]} 20 | -------------------------------------------------------------------------------- /test/plugins/prefixIds.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | @@@ 16 | 17 | 18 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/plugins/prefixIds.09.svg: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | @@@ 16 | 17 | 18 | 21 | 22 | 23 | 24 | 25 | @@@ 26 | 27 | {"prefixIds":false,"prefixClassNames":false} 28 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.17.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | @@@ 22 | 23 | {"preservePrefixes": "a"} 24 | -------------------------------------------------------------------------------- /test/plugins/prefixIds.07.svg: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | @@@ 16 | 17 | 18 | 21 | 22 | 23 | 24 | 25 | @@@ 26 | 27 | {"prefixIds":false} 28 | -------------------------------------------------------------------------------- /test/plugins/removeUselessStrokeAndFill.02_.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | @@@ 17 | 18 | 19 | 20 | 21 | 22 | @@@ 23 | 24 | { "removeNone": true } -------------------------------------------------------------------------------- /test/plugins/prefixIds.08.svg: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | @@@ 16 | 17 | 18 | 21 | 22 | 23 | 24 | 25 | @@@ 26 | 27 | {"prefixClassNames":false} 28 | -------------------------------------------------------------------------------- /test/plugins/removeStyleElement.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | @@@ 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.12.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | @@@ 18 | 19 | {"preservePrefixes": ["xyz"]} 20 | -------------------------------------------------------------------------------- /test/plugins/prefixIds.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | @@@ 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/plugins/removeUnknownsAndDefaults.08.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/svg2js/test.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 12 | 13 | 14 | 15 | test 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /plugins/removeEmptyContainers.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItemReverse'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'removes empty container elements'; 6 | 7 | const { container } = require('./_collections').elemsGroups; 8 | 9 | /** 10 | * Remove empty containers. 11 | * 12 | * @see http://www.w3.org/TR/SVG/intro.html#TermContainerElement 13 | * 14 | * @example 15 | * 16 | * 17 | * @example 18 | * 19 | * 20 | * @param {Object} item current iteration item 21 | * @return {Boolean} if false, item will be filtered out 22 | * 23 | * @author Kir Belevich 24 | */ 25 | exports.fn = function (item) { 26 | return !( 27 | item.isElem(container) 28 | && !item.isElem('svg') 29 | && item.isEmpty() 30 | && (!item.isElem('pattern') || !item.hasAttrLocal('href')) 31 | ); 32 | }; 33 | -------------------------------------------------------------------------------- /test/plugins/convertTransform.04.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.15.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | @@@ 18 | 19 | {"preserve": ["circle"], "preservePrefixes": ["suffix", "rect"]} 20 | -------------------------------------------------------------------------------- /test/plugins/minifyStyles.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | @@@ 12 | 13 | 14 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/plugins/convertTransform.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | @@@ 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/plugins/removeElementsByAttr.04.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | 14 | 15 | @@@ 16 | 17 | { "class": "someClass" } 18 | -------------------------------------------------------------------------------- /plugins/removeDesc.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.params = { 6 | removeAny: true, 7 | }; 8 | 9 | exports.description = 'removes '; 10 | 11 | const standardDescs = /^(Created with|Created using)/; 12 | 13 | /** 14 | * Removes . 15 | * Removes only standard editors content or empty elements 'cause it can be used for accessibility. 16 | * Enable parameter 'removeAny' to remove any description. 17 | * 18 | * https://developer.mozilla.org/en-US/docs/Web/SVG/Element/desc 19 | * 20 | * @param {Object} item current iteration item 21 | * @return {Boolean} if false, item will be filtered out 22 | * 23 | * @author Daniel Wabyick 24 | */ 25 | exports.fn = function (item, params) { 26 | return ( 27 | !item.isElem('desc') 28 | || !(params.removeAny || item.isEmpty() || standardDescs.test(item.content[0].text)) 29 | ); 30 | }; 31 | -------------------------------------------------------------------------------- /test/plugins/minifyStyles.09.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 9 | 10 | test 11 | 12 | 13 | 14 | @@@ 15 | 16 | 17 | 20 | 23 | 24 | test 25 | 26 | 27 | 28 | @@@ 29 | { "usage": { "force": true } } -------------------------------------------------------------------------------- /test/plugins/removeUnknownsAndDefaults.05.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.04.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | @@@ 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/plugins/moveElemsAttrsToGroup.07.svg: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | @@@ 12 | 13 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/plugins/removeHiddenElems.08.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.09.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | @@@ 21 | 22 | {"force": true, "preserve": ["circle", "rect"]} 23 | -------------------------------------------------------------------------------- /test/plugins/removeAttrs.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | @@@ 18 | 19 | {"attrs":["circle:stroke.*","path:fill"]} 20 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.13.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | @@@ 21 | 22 | {"force": true, "preservePrefixes": ["pre1_", "pre2_"]} 23 | -------------------------------------------------------------------------------- /test/plugins/convertShapeToPath.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | @@@ 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/plugins/minifyStyles.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/plugins/removeUselessStrokeAndFill.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | @@@ 12 | 13 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /plugins/removeNonInheritableGroupAttrs.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'removes non-inheritable group’s presentational attributes'; 6 | 7 | const { inheritableAttrs } = require('./_collections'); 8 | const { attrsGroups } = require('./_collections'); 9 | const applyGroups = require('./_collections').presentationNonInheritableGroupAttrs; 10 | 11 | /** 12 | * Remove non-inheritable group's "presentation" attributes. 13 | * 14 | * @param {Object} item current iteration item 15 | * @return {Boolean} if false, item will be filtered out 16 | * 17 | * @author Kir Belevich 18 | */ 19 | exports.fn = function (item) { 20 | if (item.isElem('g')) { 21 | item.eachAttr((attr) => { 22 | if ( 23 | ~attrsGroups.presentation.indexOf(attr.name) 24 | && !~inheritableAttrs.indexOf(attr.name) 25 | && !~applyGroups.indexOf(attr.name) 26 | ) { 27 | item.removeAttr(attr.name); 28 | } 29 | }); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.10.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/reusePaths.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /plugins/convertEllipseToCircle.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'converts non-eccentric s to s'; 6 | 7 | /** 8 | * Converts non-eccentric s to s. 9 | * 10 | * @see http://www.w3.org/TR/SVG/shapes.html 11 | * 12 | * @param {Object} item current iteration item 13 | * @return {Boolean} if false, item will be filtered out 14 | * 15 | * @author Taylor Hunt 16 | */ 17 | exports.fn = function (item) { 18 | if (item.isElem('ellipse')) { 19 | const rx = item.attr('rx').value || 0; 20 | const ry = item.attr('ry').value || 0; 21 | 22 | if ( 23 | rx === ry 24 | || rx === 'auto' 25 | || ry === 'auto' // SVG2 26 | ) { 27 | const radius = rx !== 'auto' ? rx : ry; 28 | item.renameElem('circle'); 29 | item.removeAttr(['rx', 'ry']); 30 | item.addAttr({ 31 | name: 'r', 32 | value: radius, 33 | prefix: '', 34 | local: 'r', 35 | }); 36 | } 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.01.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/convertTransform.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | @@@ 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.14.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 14 | 15 | 16 | 17 | @@@ 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | @@@ 29 | 30 | {"useMqs": ["media only screen and (min-device-width:320px) and (max-device-width:480px) and (-webkit-min-device-pixel-ratio:2)"]} 31 | -------------------------------------------------------------------------------- /test/plugins/convertShapeToPath.01.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/removeAttrs.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | @@@ 18 | 19 | {"attrs":"(fill|stroke)"} 20 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.05.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.19.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | @@@ 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/plugins/prefixIds.10.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/plugins/cleanupListOfValues.02.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | test 4 | 5 | 6 | 7 | 8 | 9 | 10 | @@@ 11 | 12 | 13 | 14 | test 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/plugins/sortDefsChildren.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | referenced text 5 | 6 | 7 | 8 | referenced text 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | @@@ 17 | 18 | 19 | 20 | 21 | 22 | 23 | referenced text 24 | 25 | 26 | referenced text 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.06.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/removeAttrs.03.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @@@ 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | @@@ 18 | 19 | {"attrs":"(fill|stroke)", "preserveCurrentColor": true} 20 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.12.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/removeUselessStrokeAndFill.02.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /plugins/removeDoctype.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'removes doctype declaration'; 6 | 7 | /** 8 | * Remove DOCTYPE declaration. 9 | * 10 | * "Unfortunately the SVG DTDs are a source of so many 11 | * issues that the SVG WG has decided not to write one 12 | * for the upcoming SVG 1.2 standard. In fact SVG WG 13 | * members are even telling people not to use a DOCTYPE 14 | * declaration in SVG 1.0 and 1.1 documents" 15 | * https://jwatt.org/svg/authoring/#doctype-declaration 16 | * 17 | * @example 18 | * 20 | * 21 | * @example 22 | * 25 | * ]> 26 | * 27 | * @param {Object} item current iteration item 28 | * @return {Boolean} if false, item will be filtered out 29 | * 30 | * @author Kir Belevich 31 | */ 32 | exports.fn = function (item) { 33 | if (item.doctype) { 34 | return false; 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.10.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 14 | 15 | 16 | @@@ 17 | 18 | 19 | 22 | 23 | 24 | 25 | 26 | 30 | 31 | 32 | @@@ 33 | 34 | {"force": true, "preserve": "figure"} 35 | -------------------------------------------------------------------------------- /plugins/removeUselessDefs.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'removes elements in without id'; 6 | 7 | const { nonRendering } = require('./_collections').elemsGroups; 8 | 9 | /** 10 | * Removes content of defs and properties that aren't rendered directly without ids. 11 | * 12 | * @param {Object} item current iteration item 13 | * @return {Boolean} if false, item will be filtered out 14 | * 15 | * @author Lev Solntsev 16 | */ 17 | exports.fn = function (item) { 18 | if (item.isElem('defs')) { 19 | if (item.content) { 20 | item.content = getUsefulItems(item, []); 21 | } 22 | 23 | if (item.isEmpty()) return false; 24 | } else if (item.isElem(nonRendering) && !item.hasAttr('id')) { 25 | return false; 26 | } 27 | }; 28 | 29 | function getUsefulItems(item, usefulItems) { 30 | item.content.forEach((child) => { 31 | if (child.hasAttr('id') || child.isElem('style')) { 32 | usefulItems.push(child); 33 | child.parentNode = item; 34 | } else if (!child.isEmpty()) { 35 | child.content = getUsefulItems(child, usefulItems); 36 | } 37 | }); 38 | 39 | return usefulItems; 40 | } 41 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.14.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 14 | 15 | 16 | @@@ 17 | 18 | 19 | 22 | 23 | 24 | 25 | 26 | 30 | 31 | 32 | @@@ 33 | 34 | {"force": true, "preservePrefixes": "pre1_"} 35 | -------------------------------------------------------------------------------- /plugins/removeEmptyText.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'removes empty elements'; 6 | 7 | exports.params = { 8 | text: true, 9 | tspan: true, 10 | tref: true, 11 | }; 12 | 13 | /** 14 | * Remove empty Text elements. 15 | * 16 | * @see http://www.w3.org/TR/SVG/text.html 17 | * 18 | * @example 19 | * Remove empty text element: 20 | * 21 | * 22 | * Remove empty tspan element: 23 | * 24 | * 25 | * Remove tref with empty xlink:href attribute: 26 | * 27 | * 28 | * @param {Object} item current iteration item 29 | * @param {Object} params plugin params 30 | * @return {Boolean} if false, item will be filtered out 31 | * 32 | * @author Kir Belevich 33 | */ 34 | exports.fn = function (item, params) { 35 | // Remove empty text element 36 | if (params.text && item.isElem('text') && item.isEmpty()) return false; 37 | 38 | // Remove empty tspan element 39 | if (params.tspan && item.isElem('tspan') && item.isEmpty()) return false; 40 | 41 | // Remove tref with empty xlink:href attribute 42 | if (params.tref && item.isElem('tref') && !item.hasAttrLocal('href')) return false; 43 | }; 44 | -------------------------------------------------------------------------------- /test/plugins/moveElemsAttrsToGroup.04.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /plugins/removeViewBox.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'removes viewBox attribute when possible'; 6 | 7 | const viewBoxElems = ['svg', 'pattern', 'symbol']; 8 | 9 | /** 10 | * Remove viewBox attr which coincides with a width/height box. 11 | * 12 | * @see http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute 13 | * 14 | * @example 15 | * 16 | * ⬇ 17 | * 18 | * 19 | * @param {Object} item current iteration item 20 | * @return {Boolean} if false, item will be filtered out 21 | * 22 | * @author Kir Belevich 23 | */ 24 | exports.fn = function (item) { 25 | if ( 26 | item.isElem(viewBoxElems) 27 | && item.hasAttr('viewBox') 28 | && item.hasAttr('width') 29 | && item.hasAttr('height') 30 | ) { 31 | const nums = item.attr('viewBox').value.split(/[ ,]+/g); 32 | 33 | if ( 34 | nums[0] === '0' 35 | && nums[1] === '0' 36 | && item.attr('width').value.replace(/px$/, '') === nums[2] // could use parseFloat too 37 | && item.attr('height').value.replace(/px$/, '') === nums[3] 38 | ) { 39 | item.removeAttr('viewBox'); 40 | } 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /test/plugins/removeUselessDefs.02.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/removeAttrs.05.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | @@@ 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | @@@ 20 | 21 | {"attrs":"*:(stroke|fill):((?!^#FFF$).)*"} 22 | -------------------------------------------------------------------------------- /plugins/removeDimensions.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = false; 4 | 5 | exports.description = 'removes width and height in presence of viewBox (opposite to removeViewBox, disable it first)'; 6 | 7 | /** 8 | * Remove width/height attributes and add the viewBox attribute if it's missing 9 | * 10 | * @example 11 | * 12 | * ↓ 13 | * 14 | * 15 | * @param {Object} item current iteration item 16 | * @return {Boolean} if true, with and height will be filtered out 17 | * 18 | * @author Benny Schudel 19 | */ 20 | exports.fn = function (item) { 21 | if (item.isElem('svg')) { 22 | if (item.hasAttr('viewBox')) { 23 | item.removeAttr('width'); 24 | item.removeAttr('height'); 25 | } else if ( 26 | item.hasAttr('width') 27 | && item.hasAttr('height') 28 | && !isNaN(Number(item.attr('width').value)) 29 | && !isNaN(Number(item.attr('height').value)) 30 | ) { 31 | item.addAttr({ 32 | name: 'viewBox', 33 | value: `0 0 ${Number(item.attr('width').value)} ${Number(item.attr('height').value)}`, 34 | prefix: '', 35 | local: 'viewBox', 36 | }); 37 | item.removeAttr('width'); 38 | item.removeAttr('height'); 39 | } 40 | } 41 | }; 42 | -------------------------------------------------------------------------------- /plugins/addClassesToSVGElement.js: -------------------------------------------------------------------------------- 1 | exports.type = 'full'; 2 | 3 | exports.active = false; 4 | 5 | exports.description = 'adds classnames to an outer element'; 6 | 7 | const ENOCLS = `Error in plugin "addClassesToSVGElement": absent parameters. 8 | It should have a list of classes in "classNames" or one "className". 9 | Config example: 10 | 11 | plugins: 12 | - addClassesToSVGElement: 13 | className: "mySvg" 14 | 15 | plugins: 16 | - addClassesToSVGElement: 17 | classNames: ["mySvg", "size-big"] 18 | `; 19 | 20 | /** 21 | * Add classnames to an outer element. Example config: 22 | * 23 | * plugins: 24 | * - addClassesToSVGElement: 25 | * className: 'mySvg' 26 | * 27 | * plugins: 28 | * - addClassesToSVGElement: 29 | * classNames: ['mySvg', 'size-big'] 30 | * 31 | * @author April Arcus 32 | */ 33 | exports.fn = function (data, params) { 34 | if ( 35 | !params 36 | || !((Array.isArray(params.classNames) && params.classNames.some(String)) || params.className) 37 | ) { 38 | console.error(ENOCLS); 39 | return data; 40 | } 41 | 42 | const classNames = params.classNames || [params.className]; 43 | const svg = data.content[0]; 44 | 45 | if (svg.isElem('svg')) { 46 | svg.class.add.apply(svg.class, classNames); 47 | } 48 | 49 | return data; 50 | }; 51 | -------------------------------------------------------------------------------- /test/plugins/removeAttrs.04.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | @@@ 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | @@@ 20 | 21 | {"attrs":"*:(stroke|fill):red"} 22 | -------------------------------------------------------------------------------- /lib/get-svgo-instance.js: -------------------------------------------------------------------------------- 1 | const SVGO = require('./svgo'); 2 | 3 | const defaultPlugins = { 4 | cleanupAttrs: true, 5 | removeDoctype: true, 6 | removeXMLProcInst: true, 7 | removeComments: true, 8 | removeMetadata: true, 9 | removeTitle: true, 10 | removeDesc: true, 11 | removeUselessDefs: true, 12 | removeEditorsNSData: true, 13 | removeEmptyAttrs: true, 14 | removeHiddenElems: true, 15 | removeEmptyText: true, 16 | removeEmptyContainers: true, 17 | removeViewBox: false, 18 | cleanupEnableBackground: true, 19 | convertStyleToAttrs: true, 20 | convertColors: true, 21 | convertPathData: true, 22 | convertTransform: true, 23 | removeUnknownsAndDefaults: true, 24 | removeNonInheritableGroupAttrs: true, 25 | removeUselessStrokeAndFill: false, 26 | removeUnusedNS: true, 27 | cleanupIDs: true, 28 | cleanupNumericValues: true, 29 | moveElemsAttrsToGroup: true, 30 | moveGroupAttrsToElems: true, 31 | collapseGroups: true, 32 | removeRasterImages: false, 33 | mergePaths: true, 34 | convertShapeToPath: true, 35 | sortAttrs: true, 36 | removeDimensions: true, 37 | }; 38 | 39 | module.exports = function getSvgoInstance(plugins = defaultPlugins) { 40 | const pasrsedPlugins = Object.keys(plugins).map((key) => ({ [key]: plugins[key] })); 41 | return new SVGO({ plugins: pasrsedPlugins }); 42 | }; 43 | -------------------------------------------------------------------------------- /test/plugins/mergePaths.03.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /plugins/cleanupAttrs.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'cleanups attributes from newlines, trailing and repeating spaces'; 6 | 7 | exports.params = { 8 | newlines: true, 9 | trim: true, 10 | spaces: true, 11 | }; 12 | 13 | const regNewlinesNeedSpace = /(\S)\r?\n(\S)/g; 14 | const regNewlines = /\r?\n/g; 15 | const regSpaces = /\s{2,}/g; 16 | 17 | /** 18 | * Cleanup attributes values from newlines, trailing and repeating spaces. 19 | * 20 | * @param {Object} item current iteration item 21 | * @param {Object} params plugin params 22 | * @return {Boolean} if false, item will be filtered out 23 | * 24 | * @author Kir Belevich 25 | */ 26 | exports.fn = function (item, params) { 27 | if (item.isElem()) { 28 | item.eachAttr((attr) => { 29 | if (params.newlines) { 30 | // new line which requires a space instead of themselve 31 | attr.value = attr.value.replace(regNewlinesNeedSpace, (match, p1, p2) => `${p1} ${p2}`); 32 | 33 | // simple new line 34 | attr.value = attr.value.replace(regNewlines, ''); 35 | } 36 | 37 | if (params.trim) { 38 | attr.value = attr.value.trim(); 39 | } 40 | 41 | if (params.spaces) { 42 | attr.value = attr.value.replace(regSpaces, ' '); 43 | } 44 | }); 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /test/svgo/_index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var FS = require('fs'), 4 | PATH = require('path'), 5 | EOL = require('os').EOL, 6 | regEOL = new RegExp(EOL, 'g'), 7 | SVGO = require(process.env.COVERAGE ? 8 | '../../lib-cov/svgo': 9 | '../../lib/svgo'); 10 | 11 | describe('indentation', function() { 12 | 13 | it('should create indent with 2 spaces', function(done) { 14 | 15 | var filepath = PATH.resolve(__dirname, './test.svg'), 16 | svgo; 17 | 18 | FS.readFile(filepath, 'utf8', function(err, data) { 19 | if (err) { 20 | throw err; 21 | } 22 | 23 | var splitted = normalize(data).split(/\s*@@@\s*/), 24 | orig = splitted[0], 25 | should = splitted[1]; 26 | 27 | svgo = new SVGO({ 28 | full : true, 29 | plugins : [], 30 | js2svg : { pretty: true, indent: 2 } 31 | }); 32 | 33 | svgo.optimize(orig, {path: filepath}).then(function(result) { 34 | normalize(result.data).should.be.equal(should); 35 | done(); 36 | }); 37 | 38 | }); 39 | 40 | }); 41 | 42 | }); 43 | 44 | function normalize(file) { 45 | return file.trim().replace(regEOL, '\n'); 46 | } 47 | -------------------------------------------------------------------------------- /test/plugins/mergePaths.02.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /plugins/sortDefsChildren.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'Sorts children of to improve compression'; 6 | 7 | /** 8 | * Sorts children of defs in order to improve compression. 9 | * Sorted first by frequency then by element name length then by element name (to ensure grouping). 10 | * 11 | * @param {Object} item current iteration item 12 | * @return {Boolean} if false, item will be filtered out 13 | * 14 | * @author David Leston 15 | */ 16 | exports.fn = function (item) { 17 | if (item.isElem('defs')) { 18 | if (item.content) { 19 | const frequency = item.content.reduce((frequency, child) => { 20 | if (child.elem in frequency) { 21 | frequency[child.elem]++; 22 | } else { 23 | frequency[child.elem] = 1; 24 | } 25 | return frequency; 26 | }, {}); 27 | item.content.sort((a, b) => { 28 | const frequencyComparison = frequency[b.elem] - frequency[a.elem]; 29 | if (frequencyComparison !== 0) { 30 | return frequencyComparison; 31 | } 32 | const lengthComparison = b.elem.length - a.elem.length; 33 | if (lengthComparison !== 0) { 34 | return lengthComparison; 35 | } 36 | return a.elem != b.elem ? (a.elem > b.elem ? -1 : 1) : 0; 37 | }); 38 | } 39 | 40 | return true; 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /test/jsapi/_index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var SVGO = require(process.env.COVERAGE ? 4 | '../../lib-cov/svgo.js' : 5 | '../../lib/svgo.js'); 6 | 7 | var JSAPI = require(process.env.COVERAGE ? 8 | '../../lib-cov/svgo/jsAPI.js' : 9 | '../../lib/svgo/jsAPI.js'); 10 | 11 | describe('svgo object', function() { 12 | 13 | it('should has createContentItem method', function() { 14 | var svgo = new SVGO(); 15 | svgo.createContentItem.should.be.a.Function; 16 | }); 17 | 18 | it('should be able to create content item', function() { 19 | var svgo = new SVGO(); 20 | var item = svgo.createContentItem({ 21 | elem: 'elementName', 22 | prefix: 'prefixName', 23 | local: 'localName' 24 | }); 25 | 26 | item.should.be.instanceof(JSAPI); 27 | item.should.have.ownProperty('elem').equal('elementName'); 28 | item.should.have.ownProperty('prefix').equal('prefixName'); 29 | item.should.have.ownProperty('local').equal('localName'); 30 | }); 31 | 32 | it('should be able create content item without argument', function() { 33 | var svgo = new SVGO(); 34 | var item = svgo.createContentItem(); 35 | 36 | item.should.be.instanceof(JSAPI); 37 | item.should.be.empty; 38 | }); 39 | 40 | it('should have ES module interop default property', function() { 41 | SVGO.should.equal(SVGO.default); 42 | }); 43 | 44 | }); 45 | -------------------------------------------------------------------------------- /defaults.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | 'removeDoctype', 4 | 'removeXMLProcInst', 5 | 'removeComments', 6 | 'removeMetadata', 7 | 'removeXMLNS', 8 | 'removeEditorsNSData', 9 | 'cleanupAttrs', 10 | 'inlineStyles', 11 | 'minifyStyles', 12 | 'convertStyleToAttrs', 13 | 'cleanupIDs', 14 | 'prefixIds', 15 | 'removeRasterImages', 16 | 'removeUselessDefs', 17 | 'cleanupNumericValues', 18 | 'cleanupListOfValues', 19 | 'convertColors', 20 | 'removeUnknownsAndDefaults', 21 | 'removeNonInheritableGroupAttrs', 22 | 'removeUselessStrokeAndFill', 23 | 'removeViewBox', 24 | 'cleanupEnableBackground', 25 | 'removeHiddenElems', 26 | 'removeEmptyText', 27 | 'convertShapeToPath', 28 | 'convertEllipseToCircle', 29 | 'moveElemsAttrsToGroup', 30 | 'moveGroupAttrsToElems', 31 | 'collapseGroups', 32 | 'convertPathData', 33 | 'convertTransform', 34 | 'removeEmptyAttrs', 35 | 'removeEmptyContainers', 36 | 'mergePaths', 37 | 'removeUnusedNS', 38 | 'sortAttrs', 39 | 'sortDefsChildren', 40 | 'removeTitle', 41 | 'removeDesc', 42 | 'removeDimensions', 43 | 'removeAttrs', 44 | 'removeAttributesBySelector', 45 | 'removeElementsByAttr', 46 | 'addClassesToSVGElement', 47 | 'removeStyleElement', 48 | 'removeScriptElement', 49 | 'addAttributesToSVGElement', 50 | 'removeOffCanvasPaths', 51 | 'reusePaths', 52 | ], 53 | }; 54 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.14.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/reusePaths.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 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 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.08.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /lib/svgo/css-select-adapter.js: -------------------------------------------------------------------------------- 1 | const baseCssAdapter = require('css-select-base-adapter'); 2 | 3 | /** 4 | * DOMUtils API for SVGO AST (used by css-select) 5 | */ 6 | const svgoCssSelectAdapterMin = { 7 | // is the node a tag? 8 | // isTag: ( node:Node ) => isTag:Boolean 9 | isTag(node) { 10 | return node.isElem(); 11 | }, 12 | 13 | // get the parent of the node 14 | // getParent: ( node:Node ) => parentNode:Node 15 | // returns null when no parent exists 16 | getParent(node) { 17 | return node.parentNode || null; 18 | }, 19 | 20 | // get the node's children 21 | // getChildren: ( node:Node ) => children:[Node] 22 | getChildren(node) { 23 | return node.content || []; 24 | }, 25 | 26 | // get the name of the tag 27 | // getName: ( elem:ElementNode ) => tagName:String 28 | getName(elemAst) { 29 | return elemAst.elem; 30 | }, 31 | 32 | // get the text content of the node, and its children if it has any 33 | // getText: ( node:Node ) => text:String 34 | // returns empty string when there is no text 35 | getText(node) { 36 | return node.content[0].text || node.content[0].cdata || ''; 37 | }, 38 | 39 | // get the attribute value 40 | // getAttributeValue: ( elem:ElementNode, name:String ) => value:String 41 | // returns null when attribute doesn't exist 42 | getAttributeValue(elem, name) { 43 | return elem.hasAttr(name) ? elem.attr(name).value : null; 44 | }, 45 | }; 46 | 47 | // use base adapter for default implementation 48 | const svgoCssSelectAdapter = baseCssAdapter(svgoCssSelectAdapterMin); 49 | 50 | module.exports = svgoCssSelectAdapter; 51 | -------------------------------------------------------------------------------- /plugins/removeEditorsNSData.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'removes editors namespaces, elements and attributes'; 6 | 7 | let { editorNamespaces } = require('./_collections'); 8 | 9 | const prefixes = []; 10 | 11 | exports.params = { 12 | additionalNamespaces: [], 13 | }; 14 | 15 | /** 16 | * Remove editors namespaces, elements and attributes. 17 | * 18 | * @example 19 | * 20 | * 21 | * 22 | * 23 | * @param {Object} item current iteration item 24 | * @param {Object} params plugin params 25 | * @return {Boolean} if false, item will be filtered out 26 | * 27 | * @author Kir Belevich 28 | */ 29 | exports.fn = function (item, params) { 30 | if (Array.isArray(params.additionalNamespaces)) { 31 | editorNamespaces = editorNamespaces.concat(params.additionalNamespaces); 32 | } 33 | 34 | if (item.elem) { 35 | if (item.isElem('svg')) { 36 | item.eachAttr((attr) => { 37 | if (attr.prefix === 'xmlns' && editorNamespaces.indexOf(attr.value) > -1) { 38 | prefixes.push(attr.local); 39 | 40 | // 41 | item.removeAttr(attr.name); 42 | } 43 | }); 44 | } 45 | 46 | // <* sodipodi:*=""> 47 | item.eachAttr((attr) => { 48 | if (prefixes.indexOf(attr.prefix) > -1) { 49 | item.removeAttr(attr.name); 50 | } 51 | }); 52 | 53 | // 54 | if (prefixes.indexOf(item.prefix) > -1) { 55 | return false; 56 | } 57 | } 58 | }; 59 | -------------------------------------------------------------------------------- /test/plugins/prefixIds.06.svg: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | @@@ 29 | 30 | 31 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /test/plugins/_index.js: -------------------------------------------------------------------------------- 1 | const FS = require('fs'); 2 | const PATH = require('path'); 3 | const { EOL } = require('os'); 4 | 5 | const regEOL = new RegExp(EOL, 'g'); 6 | const regFilename = /^(.*)\.(\d+)\.svg$/; 7 | const SVGO = require(process.env.COVERAGE ? '../../lib-cov/svgo' : '../../lib/svgo'); 8 | 9 | describe('plugins tests', () => { 10 | FS.readdirSync(__dirname).forEach((file) => { 11 | const match = file.match(regFilename); 12 | let index; 13 | let name; 14 | 15 | if (match) { 16 | name = match[1]; 17 | index = match[2]; 18 | 19 | file = PATH.resolve(__dirname, file); 20 | 21 | it(`${name}.${index}`, () => readFile(file).then((data) => { 22 | const splitted = normalize(data).split(/\s*@@@\s*/); 23 | const orig = splitted[0]; 24 | const should = splitted[1]; 25 | const params = splitted[2]; 26 | const plugins = {}; 27 | let svgo; 28 | 29 | plugins[name] = params ? JSON.parse(params) : true; 30 | 31 | svgo = new SVGO({ 32 | full: true, 33 | plugins: [plugins], 34 | js2svg: { pretty: true }, 35 | }); 36 | 37 | return svgo.optimize(orig, { path: file }).then((result) => { 38 | // FIXME: results.data has a '\n' at the end while it should not 39 | normalize(result.data).should.be.equal(should); 40 | }); 41 | })); 42 | } 43 | }); 44 | }); 45 | 46 | function normalize(file) { 47 | return file.trim().replace(regEOL, '\n'); 48 | } 49 | 50 | function readFile(file) { 51 | return new Promise((resolve, reject) => { 52 | FS.readFile(file, 'utf8', (err, data) => { 53 | if (err) return reject(err); 54 | resolve(data); 55 | }); 56 | }); 57 | } 58 | -------------------------------------------------------------------------------- /plugins/moveGroupAttrsToElems.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = true; 4 | 5 | exports.description = 'moves some group attributes to the content elements'; 6 | 7 | const collections = require('./_collections.js'); 8 | 9 | const pathElems = collections.pathElems.concat(['g', 'text']); 10 | const { referencesProps } = collections; 11 | 12 | /** 13 | * Move group attrs to the content elements. 14 | * 15 | * @example 16 | * 17 | * 18 | * 19 | * 20 | * ⬇ 21 | * 22 | * 23 | * 24 | * 25 | * 26 | * @param {Object} item current iteration item 27 | * @return {Boolean} if false, item will be filtered out 28 | * 29 | * @author Kir Belevich 30 | */ 31 | exports.fn = function (item) { 32 | // move group transform attr to content's pathElems 33 | if ( 34 | item.isElem('g') 35 | && item.hasAttr('transform') 36 | && !item.isEmpty() 37 | && !item.someAttr((attr) => ~referencesProps.indexOf(attr.name) && ~attr.value.indexOf('url(')) 38 | && item.content.every((inner) => inner.isElem(pathElems) && !inner.hasAttr('id')) 39 | ) { 40 | item.content.forEach((inner) => { 41 | const attr = item.attr('transform'); 42 | if (inner.hasAttr('transform')) { 43 | inner.attr('transform').value = `${attr.value} ${inner.attr('transform').value}`; 44 | } else { 45 | inner.addAttr({ 46 | name: attr.name, 47 | local: attr.local, 48 | prefix: attr.prefix, 49 | value: attr.value, 50 | }); 51 | } 52 | }); 53 | 54 | item.removeAttr('transform'); 55 | } 56 | }; 57 | -------------------------------------------------------------------------------- /test/plugins/convertPathData.03.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/inlineStyles.16.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | button 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | @@@ 26 | 27 | 28 | 29 | button 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | @@@ 39 | 40 | {"onlyMatchedOnce":false} 41 | -------------------------------------------------------------------------------- /test/plugins/prefixIds.05.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.01.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | referenced text 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 | referenced text 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /test/plugins/removeUselessStrokeAndFill.01.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/plugins/collapseGroups.12.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "svgo-browser", 3 | "version": "1.3.8", 4 | "description": "svgo tool for browser and node usage", 5 | "keywords": [ 6 | "svgo", 7 | "svg", 8 | "optimize", 9 | "minify" 10 | ], 11 | "homepage": "https://github.com/rtivital/svgo-browser", 12 | "bugs": { 13 | "url": "https://github.com/rtivital/svgo-browser/issues" 14 | }, 15 | "author": { 16 | "name": "Kir Belevich", 17 | "email": "kir@belevi.ch", 18 | "url": "https://github.com/deepsweet" 19 | }, 20 | "contributors": [ 21 | { 22 | "name": "Sergey Belov", 23 | "email": "peimei@ya.ru", 24 | "url": "http://github.com/arikon" 25 | }, 26 | { 27 | "name": "Lev Solntsev", 28 | "email": "lev.sun@ya.ru", 29 | "url": "http://github.com/GreLI" 30 | } 31 | ], 32 | "repository": { 33 | "type": "git", 34 | "url": "https://github.com/rtivital/svgo-browser" 35 | }, 36 | "main": "./lib/svgo.js", 37 | "bin": { 38 | "svgo": "./bin/svgo" 39 | }, 40 | "directories": { 41 | "bin": "./bin", 42 | "lib": "./lib", 43 | "example": "./examples" 44 | }, 45 | "scripts": { 46 | "test": "set NODE_ENV=test && mocha", 47 | "lint": "eslint ." 48 | }, 49 | "dependencies": { 50 | "chalk": "^2.4.1", 51 | "coa": "^2.0.2", 52 | "css-select": "^2.0.0", 53 | "css-select-base-adapter": "^0.1.1", 54 | "css-tree": "1.0.0-alpha.37", 55 | "csso": "^4.0.2", 56 | "js-yaml": "^3.13.1", 57 | "mkdirp": "~0.5.1", 58 | "sax": "~1.2.4", 59 | "stable": "^0.1.8", 60 | "unquote": "~1.1.1", 61 | "util.promisify": "~1.0.0" 62 | }, 63 | "devDependencies": { 64 | "coveralls": "^3.0.7", 65 | "eslint": "^7.6.0", 66 | "eslint-config-airbnb-base": "^14.2.0", 67 | "eslint-plugin-import": "^2.22.0", 68 | "fs-extra": "~8.1.0", 69 | "istanbul": "~0.4.5", 70 | "mocha": "~6.2.2", 71 | "mocha-istanbul": "~0.3.0", 72 | "mock-stdin": "~0.3.1", 73 | "should": "~13.2.3" 74 | }, 75 | "engines": { 76 | "node": ">=4.0.0" 77 | }, 78 | "license": "MIT" 79 | } 80 | -------------------------------------------------------------------------------- /test/plugins/cleanupIDs.20.svg: -------------------------------------------------------------------------------- 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 | {"prefix": "test__", "remove": "false"} 42 | -------------------------------------------------------------------------------- /plugins/removeAttributesBySelector.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = false; 4 | 5 | exports.description = 'removes attributes of elements that match a css selector'; 6 | 7 | /** 8 | * Removes attributes of elements that match a css selector. 9 | * 10 | * @param {Object} item current iteration item 11 | * @param {Object} params plugin params 12 | * @return {Boolean} if false, item will be filtered out 13 | * 14 | * @example 15 | * A selector removing a single attribute 16 | * plugins: 17 | * - removeAttributesBySelector: 18 | * selector: "[fill='#00ff00']" 19 | * attributes: "fill" 20 | * 21 | * 22 | * ↓ 23 | * 24 | * 25 | * A selector removing multiple attributes 26 | * plugins: 27 | * - removeAttributesBySelector: 28 | * selector: "[fill='#00ff00']" 29 | * attributes: 30 | * - fill 31 | * - stroke 32 | * 33 | * 34 | * ↓ 35 | * 36 | * 37 | * Multiple selectors removing attributes 38 | * plugins: 39 | * - removeAttributesBySelector: 40 | * selectors: 41 | * - selector: "[fill='#00ff00']" 42 | * attributes: "fill" 43 | * 44 | * - selector: "#remove" 45 | * attributes: 46 | * - stroke 47 | * - id 48 | * 49 | * 50 | * ↓ 51 | * 52 | * 53 | * @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors|MDN CSS Selectors} 54 | * 55 | * @author Bradley Mease 56 | */ 57 | exports.fn = function (item, params) { 58 | const selectors = Array.isArray(params.selectors) ? params.selectors : [params]; 59 | 60 | selectors.map((i) => { 61 | if (item.matches(i.selector)) { 62 | item.removeAttr(i.attributes); 63 | } 64 | }); 65 | }; 66 | -------------------------------------------------------------------------------- /plugins/sortAttrs.js: -------------------------------------------------------------------------------- 1 | exports.type = 'perItem'; 2 | 3 | exports.active = false; 4 | 5 | exports.description = 'sorts element attributes (disabled by default)'; 6 | 7 | exports.params = { 8 | order: [ 9 | 'id', 10 | 'width', 11 | 'height', 12 | 'x', 13 | 'x1', 14 | 'x2', 15 | 'y', 16 | 'y1', 17 | 'y2', 18 | 'cx', 19 | 'cy', 20 | 'r', 21 | 'fill', 22 | 'stroke', 23 | 'marker', 24 | 'd', 25 | 'points', 26 | ], 27 | }; 28 | 29 | /** 30 | * Sort element attributes for epic readability. 31 | * 32 | * @param {Object} item current iteration item 33 | * @param {Object} params plugin params 34 | * 35 | * @author Nikolay Frantsev 36 | */ 37 | exports.fn = function (item, params) { 38 | const attrs = []; 39 | const sorted = {}; 40 | const orderlen = params.order.length + 1; 41 | const xmlnsOrder = params.xmlnsOrder || 'front'; 42 | 43 | if (item.elem) { 44 | item.eachAttr((attr) => { 45 | attrs.push(attr); 46 | }); 47 | 48 | attrs.sort((a, b) => { 49 | if (a.prefix != b.prefix) { 50 | // xmlns attributes implicitly have the prefix xmlns 51 | if (xmlnsOrder == 'front') { 52 | if (a.prefix == 'xmlns') return -1; 53 | if (b.prefix == 'xmlns') return 1; 54 | } 55 | return a.prefix < b.prefix ? -1 : 1; 56 | } 57 | 58 | let aindex = orderlen; 59 | let bindex = orderlen; 60 | 61 | for (let i = 0; i < params.order.length; i++) { 62 | if (a.name == params.order[i]) { 63 | aindex = i; 64 | } else if (a.name.indexOf(`${params.order[i]}-`) === 0) { 65 | aindex = i + 0.5; 66 | } 67 | if (b.name == params.order[i]) { 68 | bindex = i; 69 | } else if (b.name.indexOf(`${params.order[i]}-`) === 0) { 70 | bindex = i + 0.5; 71 | } 72 | } 73 | 74 | if (aindex != bindex) { 75 | return aindex - bindex; 76 | } 77 | return a.name < b.name ? -1 : 1; 78 | }); 79 | 80 | attrs.forEach((attr) => { 81 | sorted[attr.name] = attr; 82 | }); 83 | 84 | item.attrs = sorted; 85 | } 86 | }; 87 | --------------------------------------------------------------------------------