schnee effeckt und fehler Korektur
This commit is contained in:
95
node_modules/svgo/plugins/removeEditorsNSData.js
generated
vendored
95
node_modules/svgo/plugins/removeEditorsNSData.js
generated
vendored
@@ -1,18 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
exports.type = 'perItem';
|
||||
const { detachNodeFromParent } = require('../lib/xast.js');
|
||||
const { editorNamespaces } = require('./_collections.js');
|
||||
|
||||
exports.type = 'visitor';
|
||||
exports.name = 'removeEditorsNSData';
|
||||
exports.active = true;
|
||||
|
||||
exports.description = 'removes editors namespaces, elements and attributes';
|
||||
|
||||
var editorNamespaces = require('./_collections').editorNamespaces,
|
||||
prefixes = [];
|
||||
|
||||
exports.params = {
|
||||
additionalNamespaces: []
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove editors namespaces, elements and attributes.
|
||||
*
|
||||
@@ -21,45 +16,53 @@ exports.params = {
|
||||
* <sodipodi:namedview/>
|
||||
* <path sodipodi:nodetypes="cccc"/>
|
||||
*
|
||||
* @param {Object} item current iteration item
|
||||
* @param {Object} params plugin params
|
||||
* @return {Boolean} if false, item will be filtered out
|
||||
*
|
||||
* @author Kir Belevich
|
||||
*
|
||||
* @type {import('../lib/types').Plugin<{
|
||||
* additionalNamespaces?: Array<string>
|
||||
* }>}
|
||||
*/
|
||||
exports.fn = function(item, params) {
|
||||
|
||||
if (Array.isArray(params.additionalNamespaces)) {
|
||||
editorNamespaces = editorNamespaces.concat(params.additionalNamespaces);
|
||||
}
|
||||
|
||||
if (item.elem) {
|
||||
|
||||
if (item.isElem('svg')) {
|
||||
|
||||
item.eachAttr(function(attr) {
|
||||
if (attr.prefix === 'xmlns' && editorNamespaces.indexOf(attr.value) > -1) {
|
||||
prefixes.push(attr.local);
|
||||
|
||||
// <svg xmlns:sodipodi="">
|
||||
item.removeAttr(attr.name);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// <* sodipodi:*="">
|
||||
item.eachAttr(function(attr) {
|
||||
if (prefixes.indexOf(attr.prefix) > -1) {
|
||||
item.removeAttr(attr.name);
|
||||
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];
|
||||
}
|
||||
});
|
||||
|
||||
// <sodipodi:*>
|
||||
if (prefixes.indexOf(item.prefix) > -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user