mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 09:47:56 +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>
75 lines
2.0 KiB
JavaScript
75 lines
2.0 KiB
JavaScript
'use strict';
|
|
|
|
exports.type = 'perItem';
|
|
|
|
exports.active = false;
|
|
|
|
exports.description =
|
|
'removes attributes of elements that match a css selector';
|
|
|
|
/**
|
|
* Removes attributes of elements that match a css selector.
|
|
*
|
|
* @param {Object} item current iteration item
|
|
* @param {Object} params plugin params
|
|
* @return {Boolean} if false, item will be filtered out
|
|
*
|
|
* @example
|
|
* <caption>A selector removing a single attribute</caption>
|
|
* plugins:
|
|
* - removeAttributesBySelector:
|
|
* selector: "[fill='#00ff00']"
|
|
* attributes: "fill"
|
|
*
|
|
* <rect x="0" y="0" width="100" height="100" fill="#00ff00" stroke="#00ff00"/>
|
|
* ↓
|
|
* <rect x="0" y="0" width="100" height="100" stroke="#00ff00"/>
|
|
*
|
|
* <caption>A selector removing multiple attributes</caption>
|
|
* plugins:
|
|
* - removeAttributesBySelector:
|
|
* selector: "[fill='#00ff00']"
|
|
* attributes:
|
|
* - fill
|
|
* - stroke
|
|
*
|
|
* <rect x="0" y="0" width="100" height="100" fill="#00ff00" stroke="#00ff00"/>
|
|
* ↓
|
|
* <rect x="0" y="0" width="100" height="100"/>
|
|
*
|
|
* <caption>Multiple selectors removing attributes</caption>
|
|
* plugins:
|
|
* - removeAttributesBySelector:
|
|
* selectors:
|
|
* - selector: "[fill='#00ff00']"
|
|
* attributes: "fill"
|
|
*
|
|
* - selector: "#remove"
|
|
* attributes:
|
|
* - stroke
|
|
* - id
|
|
*
|
|
* <rect x="0" y="0" width="100" height="100" fill="#00ff00" stroke="#00ff00"/>
|
|
* ↓
|
|
* <rect x="0" y="0" width="100" height="100"/>
|
|
*
|
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors|MDN CSS Selectors}
|
|
*
|
|
* @author Bradley Mease
|
|
*/
|
|
exports.fn = function (item, params) {
|
|
var selectors = Array.isArray(params.selectors) ? params.selectors : [params];
|
|
|
|
selectors.map(({ selector, attributes }) => {
|
|
if (item.matches(selector)) {
|
|
if (Array.isArray(attributes)) {
|
|
for (const name of attributes) {
|
|
delete item.attributes[name];
|
|
}
|
|
} else {
|
|
delete item.attributes[attributes];
|
|
}
|
|
}
|
|
});
|
|
};
|