diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:05:55 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:05:55 +0800 |
| commit | c06f7ee0a40255214c477e13d9b956a7e07c2900 (patch) | |
| tree | f5982a568ef8fab865d0142e71c7494fea3e4c1b /node_modules/svgo/plugins/removeEditorsNSData.js | |
| parent | 3fd9400d4dccc25aa29b5702216732e0b7542073 (diff) | |
postcss,(plugins): nanocss, postcss-preset-env
Diffstat (limited to 'node_modules/svgo/plugins/removeEditorsNSData.js')
| -rw-r--r-- | node_modules/svgo/plugins/removeEditorsNSData.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/node_modules/svgo/plugins/removeEditorsNSData.js b/node_modules/svgo/plugins/removeEditorsNSData.js new file mode 100644 index 00000000..cf8016cd --- /dev/null +++ b/node_modules/svgo/plugins/removeEditorsNSData.js @@ -0,0 +1,64 @@ +'use strict'; + +const { detachNodeFromParent } = require('../lib/xast.js'); +const { editorNamespaces } = require('./_collections.js'); + +exports.name = 'removeEditorsNSData'; +exports.description = 'removes editors namespaces, elements and attributes'; + +/** + * Remove editors namespaces, elements and attributes. + * + * @example + * <svg xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"> + * <sodipodi:namedview/> + * <path sodipodi:nodetypes="cccc"/> + * + * @author Kir Belevich + * + * @type {import('./plugins-types').Plugin<'removeEditorsNSData'>} + */ +exports.fn = (_root, params) => { + let namespaces = editorNamespaces; + if (Array.isArray(params.additionalNamespaces)) { + namespaces = [...editorNamespaces, ...params.additionalNamespaces]; + } + /** + * @type {Array<string>} + */ + const prefixes = []; + return { + element: { + enter: (node, parentNode) => { + // collect namespace aliases from svg element + if (node.name === 'svg') { + for (const [name, value] of Object.entries(node.attributes)) { + if (name.startsWith('xmlns:') && namespaces.includes(value)) { + prefixes.push(name.slice('xmlns:'.length)); + // <svg xmlns:sodipodi=""> + delete node.attributes[name]; + } + } + } + // remove editor attributes, for example + // <* sodipodi:*=""> + for (const name of Object.keys(node.attributes)) { + if (name.includes(':')) { + const [prefix] = name.split(':'); + if (prefixes.includes(prefix)) { + delete node.attributes[name]; + } + } + } + // remove editor elements, for example + // <sodipodi:*> + if (node.name.includes(':')) { + const [prefix] = node.name.split(':'); + if (prefixes.includes(prefix)) { + detachNodeFromParent(node, parentNode); + } + } + }, + }, + }; +}; |
