'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
*
A selector removing a single attribute
* plugins:
* - removeAttributesBySelector:
* selector: "[fill='#00ff00']"
* attributes: "fill"
*
*
* ↓
*
*
* A selector removing multiple attributes
* plugins:
* - removeAttributesBySelector:
* selector: "[fill='#00ff00']"
* attributes:
* - fill
* - stroke
*
*
* ↓
*
*
* Multiple selectors removing attributes
* plugins:
* - removeAttributesBySelector:
* selectors:
* - selector: "[fill='#00ff00']"
* attributes: "fill"
*
* - selector: "#remove"
* attributes:
* - stroke
* - id
*
*
* ↓
*
*
* @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];
}
}
});
};