-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
032a6b8
commit 4ae40b3
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}, | ||
} | ||
] | ||
} |