mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 01:38:07 +08:00
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>
58 lines
1.1 KiB
JavaScript
58 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
exports.type = 'perItem';
|
|
|
|
exports.active = true;
|
|
|
|
exports.description = 'removes empty <text> elements';
|
|
|
|
exports.params = {
|
|
text: true,
|
|
tspan: true,
|
|
tref: true,
|
|
};
|
|
|
|
/**
|
|
* Remove empty Text elements.
|
|
*
|
|
* @see https://www.w3.org/TR/SVG11/text.html
|
|
*
|
|
* @example
|
|
* Remove empty text element:
|
|
* <text/>
|
|
*
|
|
* Remove empty tspan element:
|
|
* <tspan/>
|
|
*
|
|
* Remove tref with empty xlink:href attribute:
|
|
* <tref xlink:href=""/>
|
|
*
|
|
* @param {Object} item current iteration item
|
|
* @param {Object} params plugin params
|
|
* @return {Boolean} if false, item will be filtered out
|
|
*
|
|
* @author Kir Belevich
|
|
*/
|
|
exports.fn = function (item, params) {
|
|
if (item.type === 'element') {
|
|
// Remove empty text element
|
|
if (params.text && item.name === 'text' && item.children.length === 0) {
|
|
return false;
|
|
}
|
|
|
|
// Remove empty tspan element
|
|
if (params.tspan && item.name === 'tspan' && item.children.length === 0) {
|
|
return false;
|
|
}
|
|
|
|
// Remove tref with empty xlink:href attribute
|
|
if (
|
|
params.tref &&
|
|
item.name === 'tref' &&
|
|
item.attributes['xlink:href'] == null
|
|
) {
|
|
return false;
|
|
}
|
|
}
|
|
};
|