From c06f7ee0a40255214c477e13d9b956a7e07c2900 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sat, 14 Oct 2023 15:05:55 +0800 Subject: postcss,(plugins): nanocss, postcss-preset-env --- .../svgo/plugins/removeAttributesBySelector.js | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 node_modules/svgo/plugins/removeAttributesBySelector.js (limited to 'node_modules/svgo/plugins/removeAttributesBySelector.js') diff --git a/node_modules/svgo/plugins/removeAttributesBySelector.js b/node_modules/svgo/plugins/removeAttributesBySelector.js new file mode 100644 index 00000000..09db8a8d --- /dev/null +++ b/node_modules/svgo/plugins/removeAttributesBySelector.js @@ -0,0 +1,97 @@ +'use strict'; + +const { querySelectorAll } = require('../lib/xast.js'); + +exports.name = 'removeAttributesBySelector'; +exports.description = + 'removes attributes of elements that match a css selector'; + +/** + * Removes attributes of elements that match a css selector. + * + * @example + * A selector removing a single attribute + * plugins: [ + * { + * name: "removeAttributesBySelector", + * params: { + * selector: "[fill='#00ff00']" + * attributes: "fill" + * } + * } + * ] + * + * + * ↓ + * + * + * A selector removing multiple attributes + * plugins: [ + * { + * name: "removeAttributesBySelector", + * params: { + * selector: "[fill='#00ff00']", + * attributes: [ + * "fill", + * "stroke" + * ] + * } + * } + * ] + * + * + * ↓ + * + * + * Multiple selectors removing attributes + * plugins: [ + * { + * name: "removeAttributesBySelector", + * params: { + * selectors: [ + * { + * selector: "[fill='#00ff00']", + * attributes: "fill" + * }, + * { + * selector: "#remove", + * attributes: [ + * "stroke", + * "id" + * ] + * } + * ] + * } + * } + * ] + * + * + * ↓ + * + * + * @link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors|MDN CSS Selectors + * + * @author Bradley Mease + * + * @type {import('./plugins-types').Plugin<'removeAttributesBySelector'>} + */ +exports.fn = (root, params) => { + const selectors = Array.isArray(params.selectors) + ? params.selectors + : [params]; + for (const { selector, attributes } of selectors) { + const nodes = querySelectorAll(root, selector); + for (const node of nodes) { + if (node.type === 'element') { + if (Array.isArray(attributes)) { + for (const name of attributes) { + delete node.attributes[name]; + } + } else { + delete node.attributes[attributes]; + } + } + } + } + return {}; +}; -- cgit v1.2.3