-
Notifications
You must be signed in to change notification settings - Fork 5
/
svgo.config-component.js
68 lines (66 loc) · 1.71 KB
/
svgo.config-component.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
60
61
62
63
64
65
66
67
68
const addClassNamesPlugin = require('./add_classnames.svgo-plugin');
module.exports = {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false
}
}
},
{
name: 'addClassNamesPlugin',
type: 'perItem',
params: {
rules: [
{
attribute: 'fill',
value: '#A5ADB1',
className: 'fi-icon-component-base-fill'
},
{
attribute: 'stroke',
value: '#A5ADB1',
className: 'fi-icon-component-base-stroke'
},
{
attribute: 'fill',
value: '#E97025',
className: 'fi-icon-component-highlight-fill'
},
{
attribute: 'stroke',
value: '#E97025',
className: 'fi-icon-component-highlight-stroke'
},
{
attribute: 'fill',
value: '#00347A',
className: 'fi-icon-component-brand-fill'
}
]
},
fn: function (item, params) {
var patternMap = params.rules.map(function (rule) {
return {
pattern: [
new RegExp(['^', rule.attribute, '$'].join(''), 'i'),
new RegExp(['^', rule.value, '$'].join(''), 'i')
],
className: rule.className
};
});
patternMap.forEach(function (pm) {
if (item.attrs) {
for (const [name, value] of Object.entries(item.attrs)) {
if (pm.pattern[0].test(name) && pm.pattern[1].test(value.value)) {
item.class.add(pm.className);
}
}
}
});
}
}
]
};