-
Notifications
You must be signed in to change notification settings - Fork 311
/
svgo.config.js
59 lines (59 loc) · 2.12 KB
/
svgo.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
export default {
multipass: true,
js2svg: {
indent: 4,
pretty: true,
},
plugins: [
{
name: 'preset-default',
params: {
overrides: {
// cleanupIds plugin can not recognize quoted url,
// we disable it for `pnpm svgo`.
cleanupIds: false,
},
},
},
'prefixIds',
// Easy to preview with Finder
'removeDimensions',
{
// Raycast can not resolve reference elements without quote,
// with this plugin, we add quote for reference urls.
name: 'quoteUrl',
fn: () => {
const nodes = []
const unquotedUrlRe = /^url\([^'"].*?\)/
const ignoreAttributes = ['fill']
return {
element: {
enter: (node) => {
for (const key of Object.keys(node.attributes)) {
const value = node.attributes[key]
if (value?.match(unquotedUrlRe)) {
nodes.push(node)
}
}
},
},
root: {
exit() {
nodes.forEach((node) => {
for (const key of Object.keys(node.attributes)) {
if (ignoreAttributes.includes(key)) continue
const value = node.attributes[key]
if (value?.match(unquotedUrlRe)) {
node.attributes[key] = value.replace(/^url\((.*?)\)/, (_, url) => {
return `url('${url}')`
})
}
}
})
},
},
}
},
},
],
}