diff --git a/icons/wl/svgo.config.js b/icons/wl/svgo.config.js index 5f88b7181..29d0c8e95 100644 --- a/icons/wl/svgo.config.js +++ b/icons/wl/svgo.config.js @@ -1,3 +1,23 @@ +const REG = /(block-progression:tb;?|-inkscape-font-specification:(Sans|Helvetica Neue Bold|Bitstream Vera Sans|Open Sans Bold);?)/g; +const attrREG = /(onclick)/g; + +function modify(children = []) { + return children.map((item) => { + const str = item.attributes?.['style']; + if (str && REG.test(str)) { + item.attributes['style'] = str.replace(REG, ''); + } + if (attrREG.test(Object.keys(item.attributes || {}).join(','))) { + delete item.attributes['onclick']; + } + if (item.children) { + item.children = modify(item.children); + } + return item; + }); +} + +/** @type {import('svgo').Config} */ module.exports = { multipass: true, js2svg: { @@ -13,5 +33,19 @@ module.exports = { attributes: ['height="1em"', 'width="1em"'] } }, + { + name: 'removeAttrs', + fn: (ast, params, info) => { + delete ast.children[0]?.attributes['style']; + delete ast.children[0]?.attributes['xml:space']; + delete ast.children[0]?.attributes['xmlns:vectornator']; + ast.children[0]?.children.forEach((item) => { + if (item.name === 'a') { + ast.children[0].children = [...item.children]; + } + }); + ast.children = modify(ast.children) + }, + } ] }