Files
react-native-devtools-frontend/node_modules/svgo/plugins/removeEmptyContainers.js
T
Tim van der Lippe 706ec965fb Add packages to optimize svgs dynamically
These packages will be used to dynamically optimize SVG images
during the build.

R=jacktfranklin@chromium.org

Bug: 1216402
Change-Id: I04e95aa7d79c9d67beaf8a7861182c52b16b7d0f
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2939992
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
2021-06-04 13:32:16 +00:00

44 lines
1.1 KiB
JavaScript

'use strict';
const { elemsGroups } = require('./_collections');
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;
};