mirror of
https://github.com/svg/svgo.git
synced 2025-04-19 10:22:15 +03:00
I saw complaints about `extendDefaultPlugins` api - it cannot be used when svgo is installed globally - it requires svgo to be installed when using svgo-loader or svgo-jsx - it prevents using serializable config formats like json In this diff I introduced the new plugin which is a bundle of all default plugins. ```js module.exports = { plugins: [ 'preset_default', // or { name: 'preset_default', floatPrecision: 4, overrides: { convertPathData: { applyTransforms: false } } } ] } ```
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const { elemsGroups } = require('./_collections');
|
|
|
|
exports.name = 'removeEmptyContainers';
|
|
|
|
exports.type = 'perItemReverse';
|
|
|
|
exports.active = true;
|
|
|
|
exports.description = 'removes empty container elements';
|
|
|
|
/**
|
|
* Remove empty containers.
|
|
*
|
|
* @see https://www.w3.org/TR/SVG11/intro.html#TermContainerElement
|
|
*
|
|
* @example
|
|
* <defs/>
|
|
*
|
|
* @example
|
|
* <g><marker><a/></marker></g>
|
|
*
|
|
* @param {Object} item current iteration item
|
|
* @return {Boolean} if false, item will be filtered out
|
|
*
|
|
* @author Kir Belevich
|
|
*/
|
|
exports.fn = function (item) {
|
|
if (item.type === 'element') {
|
|
return (
|
|
item.children.length !== 0 ||
|
|
elemsGroups.container.includes(item.name) === false ||
|
|
item.name === 'svg' ||
|
|
// empty patterns may contain reusable configuration
|
|
(item.name === 'pattern' && Object.keys(item.attributes).length !== 0) ||
|
|
// The 'g' may not have content, but the filter may cause a rectangle
|
|
// to be created and filled with pattern.
|
|
(item.name === 'g' && item.attributes.filter != null) ||
|
|
// empty <mask> hides masked element
|
|
(item.name === 'mask' && item.attributes.id != null)
|
|
);
|
|
}
|
|
return true;
|
|
};
|