Skip to content

Commit

Permalink
fix(iu): add svgo config.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 17, 2023
1 parent 032a6b8 commit 4ae40b3
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions icons/iu/svgo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const REG = /(shape-padding:0;?|solid-opacity:1?|enable-background:accumulate;?|solid-color:#000;?|image-rendering:optimizeQuality;?|writing-mode:lr-tb;?|color-interpolation-filters:linearRGB;)/g;
const attrREG = /(vectornator:layerName)/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['vectornator:layerName'];
}
if (item.children) {
item.children = modify(item.children);
}
return item;
});
}

/** @type {import('svgo').Config} */
module.exports = {
multipass: true,
js2svg: {
indent: 2, // string with spaces or number of spaces. 4 by default
pretty: true, // boolean, false by default
},
plugins: [
'removeComments',
'removeDimensions',
'cleanupAttrs',
{
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)
},
}
]
}

0 comments on commit 4ae40b3

Please sign in to comment.