File tree Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -33,9 +33,18 @@ SVGO.prototype.optimize = function(svgstr, callback) {
33
33
return ;
34
34
}
35
35
36
- svgjs = PLUGINS ( svgjs , config . plugins ) ;
37
-
38
- callback ( JS2SVG ( svgjs , config . js2svg ) ) ;
36
+ var svg = { data : null } ,
37
+ maxIterationCount = config . multipass ? 10 : 1 ,
38
+ counter = 0 ,
39
+ prevResult ;
40
+
41
+ do {
42
+ prevResult = svg ;
43
+ svgjs = PLUGINS ( svgjs , config . plugins ) ;
44
+ svg = JS2SVG ( svgjs , config . js2svg ) ;
45
+ } while ( ++ counter < maxIterationCount && prevResult . data !== svg . data ) ;
46
+
47
+ callback ( svg ) ;
39
48
40
49
} ) ;
41
50
Original file line number Diff line number Diff line change @@ -85,6 +85,11 @@ module.exports = require('coa').Cmd()
85
85
return val || this . reject ( 'Option --datauri must have one of the following values: base64, enc or unenc' ) ;
86
86
} )
87
87
. end ( )
88
+ . opt ( )
89
+ . name ( 'multipass' ) . title ( 'Enable multipass' )
90
+ . long ( 'multipass' )
91
+ . flag ( )
92
+ . end ( )
88
93
. opt ( )
89
94
. name ( 'pretty' ) . title ( 'Make SVG pretty printed' )
90
95
. long ( 'pretty' )
@@ -136,6 +141,14 @@ module.exports = require('coa').Cmd()
136
141
config = changePluginsState ( opts . enable , true , config ) ;
137
142
}
138
143
144
+ // --multipass
145
+ if ( opts . multipass ) {
146
+
147
+ config = config || { } ;
148
+ config . multipass = true ;
149
+
150
+ }
151
+
139
152
// --pretty
140
153
if ( opts . pretty ) {
141
154
Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ module.exports = function(config) {
25
25
defaults . plugins = optimizePluginsArray ( defaults . plugins ) ;
26
26
}
27
27
28
+ defaults . multipass = config . multipass ;
29
+
28
30
} else {
29
31
30
32
defaults = EXTEND ( { } , yaml . safeLoad ( fs . readFileSync ( __dirname + '/../../.svgo.yml' , 'utf8' ) ) ) ;
@@ -33,6 +35,7 @@ module.exports = function(config) {
33
35
34
36
if ( config ) {
35
37
defaults = extendConfig ( defaults , config ) ;
38
+ defaults . multipass = config . multipass ;
36
39
}
37
40
38
41
defaults . plugins = optimizePluginsArray ( defaults . plugins ) ;
You can’t perform that action at this time.
0 commit comments