svgo 0.1.4 → 1.0.1d
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.bundle/config +2 -0
- data/.eslintrc.yml +5 -104
- data/Gemfile.lock +5 -1
- data/README.MD +59 -33
- data/bin/svgo-ruby +5 -10
- data/lib/svgo.rb +18 -28
- data/lib/version.rb +1 -1
- data/svgo-js/svgo-built.js +340 -142
- data/svgo-js/svgo-wrapper.js +182 -110
- data/svgo.gemspec +15 -5
- data/yarn.lock +11 -1661
- metadata +21 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 014c1444c9a544946dc8d81359b240900f4b2ba49c92e853f9dce0ca001d9bb3
|
4
|
+
data.tar.gz: 9cf98a0336290ba94bbb827d9cb43a9772dffac1af93fcacb8f552af911325b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 044e6576e6c724c15794cd84a08b08804c0010d8a052b492f47f816a435de2ccf5de71c5cc10ece6b46fe035166eae57b5088adab04247b17d3b4d00c298f35f
|
7
|
+
data.tar.gz: 948e8fa98a3f5ce7ad85f9030a492ad6d3b340e44ea61df336f4d1aa5cedc1c76a5ff219823a832f75a5bb22d1a777e4028941adc14e1b7fbd18f78553ef9223
|
data/.bundle/config
ADDED
data/.eslintrc.yml
CHANGED
@@ -1,106 +1,7 @@
|
|
1
|
+
root: true
|
2
|
+
parserOptions:
|
3
|
+
ecmaVersion: 6
|
1
4
|
env:
|
2
5
|
node: true
|
3
|
-
extends:
|
4
|
-
|
5
|
-
ecmaVersion: 5
|
6
|
-
globals:
|
7
|
-
$: false
|
8
|
-
jQuery: false
|
9
|
-
I18n: false
|
10
|
-
locale: true
|
11
|
-
rules:
|
12
|
-
indent:
|
13
|
-
- warn
|
14
|
-
- 2
|
15
|
-
-
|
16
|
-
SwitchCase: 1
|
17
|
-
MemberExpression: 1
|
18
|
-
FunctionDeclaration:
|
19
|
-
body: 1
|
20
|
-
parameters: 2
|
21
|
-
CallExpression:
|
22
|
-
arguments: 1
|
23
|
-
ArrayExpression: 1
|
24
|
-
ObjectExpression: 1
|
25
|
-
|
26
|
-
linebreak-style:
|
27
|
-
- warn
|
28
|
-
- unix
|
29
|
-
quotes:
|
30
|
-
- warn
|
31
|
-
- double
|
32
|
-
-
|
33
|
-
avoidEscape: true
|
34
|
-
semi:
|
35
|
-
- error
|
36
|
-
- always
|
37
|
-
camelcase:
|
38
|
-
- warn
|
39
|
-
-
|
40
|
-
properties: never
|
41
|
-
ignoreDestructuring: false
|
42
|
-
brace-style:
|
43
|
-
- warn
|
44
|
-
- 1tbs
|
45
|
-
-
|
46
|
-
allowSingleLine: true
|
47
|
-
comma-spacing:
|
48
|
-
- warn
|
49
|
-
multiline-comment-style:
|
50
|
-
- warn
|
51
|
-
- separate-lines
|
52
|
-
spaced-comment:
|
53
|
-
- warn
|
54
|
-
- always
|
55
|
-
-
|
56
|
-
line:
|
57
|
-
markers:
|
58
|
-
- "="
|
59
|
-
block:
|
60
|
-
exceptions:
|
61
|
-
- "*"
|
62
|
-
balanced: true
|
63
|
-
no-multiple-empty-lines:
|
64
|
-
- error
|
65
|
-
-
|
66
|
-
max: 2
|
67
|
-
maxBOF: 0
|
68
|
-
maxEOF: 1
|
69
|
-
unicode-bom:
|
70
|
-
- error
|
71
|
-
- never
|
72
|
-
dot-location:
|
73
|
-
- error
|
74
|
-
- property
|
75
|
-
dot-notation:
|
76
|
-
- warn
|
77
|
-
no-alert:
|
78
|
-
warn
|
79
|
-
no-console:
|
80
|
-
warn
|
81
|
-
no-eval:
|
82
|
-
error
|
83
|
-
valid-jsdoc:
|
84
|
-
- error
|
85
|
-
-
|
86
|
-
prefer:
|
87
|
-
arg: param
|
88
|
-
argument: param
|
89
|
-
return: returns
|
90
|
-
preferType:
|
91
|
-
object: Object
|
92
|
-
array: Array
|
93
|
-
list: Array
|
94
|
-
hash: Object
|
95
|
-
dict: Object
|
96
|
-
requireReturn: false
|
97
|
-
requireReturnType: true
|
98
|
-
requireParamType: true
|
99
|
-
requireParamDescription: true
|
100
|
-
matchDescription: ".+"
|
101
|
-
requireReturnDescription: true
|
102
|
-
no-unused-vars:
|
103
|
-
- error
|
104
|
-
-
|
105
|
-
vars: all
|
106
|
-
argsIgnorePattern: "window|document|event|el|element|_"
|
6
|
+
extends:
|
7
|
+
- standard
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
svgo (0.1.
|
4
|
+
svgo (0.1.5)
|
5
5
|
execjs (>= 2.7.0)
|
6
|
+
mini_racer (= 0.2.4)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
11
|
coderay (1.1.2)
|
11
12
|
execjs (2.7.0)
|
13
|
+
libv8 (6.7.288.46.1-x86_64-linux)
|
12
14
|
method_source (0.9.0)
|
15
|
+
mini_racer (0.2.4)
|
16
|
+
libv8 (>= 6.3)
|
13
17
|
pry (0.11.3)
|
14
18
|
coderay (~> 1.1.0)
|
15
19
|
method_source (~> 0.9.0)
|
data/README.MD
CHANGED
@@ -1,31 +1,20 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/svgo.svg)](https://badge.fury.io/rb/svgo)
|
2
|
+
[![License](https://img.shields.io/github/license/greenhost/svgo-ruby.svg)](https://github.com/greenhost/svgo-ruby/blob/master/LICENSE.txt)
|
3
|
+
|
1
4
|
# A Ruby wrapper for Node SVGO
|
2
5
|
|
3
6
|
Removes metadata and editor data elements and attributes that are redundant
|
4
|
-
from SVG files. Can strip files so they are optimised for web use. Go to
|
7
|
+
from SVG files. Can strip files so they are optimised for web use. Go to
|
5
8
|
[SVGO](https://github.com/svg/svgo) for more documentation on features.
|
6
9
|
|
7
|
-
|
10
|
+
# Note to users of 1.x versions
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
fulfilled. Therefore there is a small wrapper JavaScript in this repository
|
14
|
-
that calls all the components that SVGO is made up of, but without the
|
15
|
-
`Promise`. It also wraps up the configuration of plugins the way it is expected
|
16
|
-
by SVGO's components. Lastly `require` is not supported by `execjs` so all of
|
17
|
-
this is transpiled to one monolithic JavaScript file - that is completely
|
18
|
-
self-contained, using [browserify](http://browserify.org/).
|
12
|
+
`execjs` is no longer used as a wrapper around JavaScript run times, instead
|
13
|
+
[`mini_racer`](https://github.com/discourse/mini_racer) is used directly. That
|
14
|
+
means one dependency is removed. `mini_racer` was already a dependency so it
|
15
|
+
should not make a difference during installation.
|
19
16
|
|
20
|
-
__NOTE:__ `execjs` supports a variety of JavaSript runtimes, notably
|
21
|
-
[`therubyracer`](https://github.com/cowboyd/therubyracer), but `therubyracer`
|
22
|
-
depends on an ancient [`libv8`](https://github.com/cowboyd/libv8), which
|
23
|
-
doesn't support some of the modern syntax used in SVGO. Therefore `mini_racer`
|
24
|
-
(a drop in replacement for `therubyracer`) is a dependency, which uses a much
|
25
|
-
more recent `libv8`.
|
26
17
|
|
27
|
-
If you have [Node](https://nodejs.org/) installed you could also use that as a
|
28
|
-
runtime.
|
29
18
|
|
30
19
|
## How to use?
|
31
20
|
|
@@ -52,7 +41,7 @@ svgo.optimize(File.read(svg_file))
|
|
52
41
|
|
53
42
|
#### Method 2
|
54
43
|
|
55
|
-
You can manually pass options to the class that correspond to
|
44
|
+
You can manually pass options to the class that correspond to
|
56
45
|
[SVGO](https://github.com/svg/svgo)'s documentation.
|
57
46
|
|
58
47
|
```ruby
|
@@ -75,21 +64,22 @@ svgo.optimize_file(svg_file)
|
|
75
64
|
# => <svg xmlns="http://www.w3.org/2000/svg" ...
|
76
65
|
```
|
77
66
|
|
78
|
-
You can also choose the plugins to use, you can either pass the exact plugins
|
67
|
+
You can also choose the plugins to use, you can either pass the exact plugins
|
68
|
+
you want with their configuration, or you can modify the default plugin list.
|
79
69
|
|
80
70
|
```ruby
|
81
71
|
require('svgo')
|
82
72
|
svg_file = "path/to/a.svg"
|
83
73
|
options = {
|
84
74
|
plugins: {
|
85
|
-
:
|
86
|
-
:
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
90
|
-
:
|
91
|
-
:
|
92
|
-
:
|
75
|
+
addAttributesToSVGElement: true,
|
76
|
+
addClassesToSVGElement: true,
|
77
|
+
cleanupAttrs: false,
|
78
|
+
cleanupEnableBackground: true,
|
79
|
+
cleanupIDs: false,
|
80
|
+
cleanupListOfValues: true,
|
81
|
+
collapseGroups: true,
|
82
|
+
cleanupNumericValues: true,
|
93
83
|
#etc..
|
94
84
|
}
|
95
85
|
}
|
@@ -98,7 +88,9 @@ svgo = SvgOptimizer.new(options)
|
|
98
88
|
|
99
89
|
### As a CLI tool
|
100
90
|
|
101
|
-
Strictly speaking this mode is for testing only. But if you can't install
|
91
|
+
Strictly speaking this mode is for testing only. But if you can't install
|
92
|
+
NodeJS, and you do have a Ruby environment and you really need a CLI tool, you
|
93
|
+
might be able to squeeze out some optimised files from this utility.
|
102
94
|
|
103
95
|
``` bash
|
104
96
|
gem install svgo-ruby
|
@@ -124,6 +116,40 @@ docker run -i svgo < test/fixtures/ruby.svg > test/fixtures/ruby.optim.svg
|
|
124
116
|
-rw-r--r-- 1 user staff 23K Nov 5 22:12 ruby.svg
|
125
117
|
```
|
126
118
|
|
127
|
-
##
|
119
|
+
## How this works
|
120
|
+
|
121
|
+
[`mini_racer`](https://github.com/discourse/mini_racer) is used to run the
|
122
|
+
Node SVGO as a library. The SVGO library returns a JavaScript Promise, which
|
123
|
+
is currently not supported by `mini_racer` and perhaps never will be.
|
124
|
+
`setTimeout` and sleep-like functions are also disabled in `mini_racer` so we
|
125
|
+
can't wait for the Promise to get fulfilled. Therefore there is a small
|
126
|
+
wrapper JavaScript in this repository
|
127
|
+
that calls all the components that SVGO is made up of, but without the
|
128
|
+
`Promise`. It also wraps up the configuration of plugins the way it is expected
|
129
|
+
by SVGO's components. Lastly `require` is not supported by `mini_racer` so all
|
130
|
+
of this is transpiled to one monolithic JavaScript file - that is completely
|
131
|
+
self-contained, using [browserify](http://browserify.org/).
|
132
|
+
|
133
|
+
### Transpiling Node SVGO
|
134
|
+
|
135
|
+
__TL;DR:__ A transpiled version of SVGO is included in the repository, so you
|
136
|
+
don't need to transpile anything.
|
137
|
+
|
138
|
+
Because `mini_racer` supports only self-contained modules, and does not allow
|
139
|
+
`require()`, `Promise` etc.. The SGVO library is wrapped in a JavaScript that
|
140
|
+
requires all the main parts of SVGO and makes an SVGO function without
|
141
|
+
JavaScript Promises. The wrapper is then transpiled to a self-contained module
|
142
|
+
using [browserify](http://browserify.org/).
|
143
|
+
|
144
|
+
The transpile command can be found in the `Rakefile`. Assuming you have
|
145
|
+
[Node](https://nodejs.org/) and [yarn](https://yarnpkg.com/en/) installed on
|
146
|
+
your system, you can then run:
|
147
|
+
|
148
|
+
``` bash
|
149
|
+
yarn install
|
150
|
+
rake
|
151
|
+
```
|
128
152
|
|
129
|
-
|
153
|
+
__Note__: if you do not have `yarn` you can run `npm install` instead, but if
|
154
|
+
you install Node modules often, you probably should do yourself a favour check
|
155
|
+
out [yarn](https://yarnpkg.com/en/).
|
data/bin/svgo-ruby
CHANGED
@@ -104,9 +104,6 @@ sortAttrs:
|
|
104
104
|
"sorts element attributes (disabled by default)"
|
105
105
|
}
|
106
106
|
|
107
|
-
options.plugins = Hash[
|
108
|
-
plugins.map { |k, str| [k, !str.include?("disabled by default")]}
|
109
|
-
]
|
110
107
|
parser = OptionParser.new do |opts|
|
111
108
|
opts.banner = "Usage: svgo-ruby [options] [input file]"
|
112
109
|
opts.separator ""
|
@@ -152,7 +149,7 @@ parser = OptionParser.new do |opts|
|
|
152
149
|
options.plugins[p.to_sym] = state
|
153
150
|
end
|
154
151
|
end
|
155
|
-
opts.on("--removeAttrs", String, %q(
|
152
|
+
opts.on("--removeAttrs [attrs]", String, %q(
|
156
153
|
A comma separated list of Javascript compatible regular expressions.
|
157
154
|
The format described in the plugin:
|
158
155
|
|
@@ -182,18 +179,16 @@ parser = OptionParser.new do |opts|
|
|
182
179
|
https://github.com/svg/svgo/blob/master/plugins/removeAttrs.js
|
183
180
|
).sub(/^\n\s+/,'').gsub(/ {4}/, " " * 12)) do |plugin_args|
|
184
181
|
patterns = plugin_args.sub(/\s*,\s*/, ",").split(",")
|
185
|
-
options.plugins
|
182
|
+
options.plugins[:removeAttrs] = {attrs: patterns}
|
186
183
|
end
|
187
184
|
end
|
188
185
|
|
189
186
|
parser.parse!
|
190
|
-
|
191
187
|
svgo = SvgOptimizer.new(options)
|
192
188
|
|
193
189
|
# Read from stdin..
|
194
190
|
unless STDIN.tty? and not STDIN.closed?
|
195
|
-
|
196
|
-
result = svgo.optimize(input_data)
|
191
|
+
result = svgo.optimize(ARGF.read)
|
197
192
|
else
|
198
193
|
# See if there is an input file name
|
199
194
|
input_file = ARGV.pop
|
@@ -203,7 +198,7 @@ else
|
|
203
198
|
exit 2
|
204
199
|
else
|
205
200
|
begin
|
206
|
-
|
201
|
+
result = svgo.optimize_file(input_file)
|
207
202
|
rescue => err
|
208
203
|
puts err.message
|
209
204
|
exit(1)
|
@@ -214,7 +209,7 @@ end
|
|
214
209
|
unless output_file
|
215
210
|
puts result['data']
|
216
211
|
else
|
217
|
-
File.new(output_file, 'w').write(
|
212
|
+
File.new(output_file, 'w').write(result['data'])
|
218
213
|
end
|
219
214
|
|
220
215
|
|
data/lib/svgo.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'mini_racer'
|
2
2
|
require 'json'
|
3
3
|
require 'pry'
|
4
4
|
require 'ostruct'
|
5
5
|
|
6
6
|
PLUGINS_DEFAULT = [
|
7
7
|
:addAttributesToSVGElement,
|
8
|
-
:addClassesToSVGElement,
|
9
8
|
:cleanupAttrs,
|
10
9
|
:cleanupEnableBackground,
|
11
10
|
:cleanupIDs,
|
@@ -47,8 +46,7 @@ class SvgoOptions
|
|
47
46
|
def initialize
|
48
47
|
@options = OpenStruct.new(
|
49
48
|
js2svg: OpenStruct.new(pretty: false),
|
50
|
-
plugins: PLUGINS_DEFAULT,
|
51
|
-
floatPrecision: 6,
|
49
|
+
plugins: PLUGINS_DEFAULT.map { | p | [ p, true ] }.to_h,
|
52
50
|
multipass: false
|
53
51
|
)
|
54
52
|
yield @options if block_given?
|
@@ -57,6 +55,9 @@ class SvgoOptions
|
|
57
55
|
def get_options(*args)
|
58
56
|
options = @options.to_h
|
59
57
|
options[:js2svg] = options[:js2svg].to_h
|
58
|
+
options[:plugins] = options[:plugins].map { | plugin, params |
|
59
|
+
{plugin => params}
|
60
|
+
}
|
60
61
|
options
|
61
62
|
end
|
62
63
|
|
@@ -110,6 +111,7 @@ class SvgoOptions
|
|
110
111
|
end
|
111
112
|
|
112
113
|
class SvgOptimizer
|
114
|
+
attr_accessor :options
|
113
115
|
def initialize(options=SvgoOptions.new)
|
114
116
|
yield options if block_given?
|
115
117
|
if options.is_a? SvgoOptions
|
@@ -117,39 +119,27 @@ class SvgOptimizer
|
|
117
119
|
else
|
118
120
|
@options = options
|
119
121
|
end
|
120
|
-
|
121
|
-
runtime = @options.delete "runtime"
|
122
|
-
unless runtime
|
123
|
-
# therubyracer is a first choice for execjs but its libv8 is too
|
124
|
-
# old for the svgo library and its dependencies.
|
125
|
-
runtimes = [
|
126
|
-
# MacOS only system component
|
127
|
-
ExecJS::Runtimes::JavaScriptCore,
|
128
|
-
ExecJS::Runtimes::MiniRacer,
|
129
|
-
ExecJS::Runtimes::Node
|
130
|
-
]
|
131
|
-
runtime = runtimes.select {|r| r.available?}.first
|
132
|
-
unless runtime
|
133
|
-
raise ExecJS::RuntimeUnavailable.new(
|
134
|
-
"No supported runtime available please install " \
|
135
|
-
"`mini_racer` or `NodeJS`."
|
136
|
-
)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
ExecJS.runtime = runtime
|
140
122
|
if not @options[:plugins]
|
141
123
|
@options[:plugins] = PLUGINS_DEFAULT
|
142
124
|
end
|
143
|
-
if @options[:plugins].is_a? Array
|
144
|
-
|
125
|
+
if not @options[:plugins].is_a? Array
|
126
|
+
raise StandardError.new("`options.plugins` should be an Array.")
|
145
127
|
end
|
128
|
+
@options[:plugins] = @options[:plugins].map { | p |
|
129
|
+
p.is_a?(Hash) ? p : {p => true}
|
130
|
+
}
|
146
131
|
svgo_js = File.expand_path("../../svgo-js/svgo-built.js", __FILE__)
|
147
132
|
svgo_module = File.open(svgo_js, "r:utf-8", &:read)
|
148
|
-
@context =
|
133
|
+
@context = MiniRacer::Context.new
|
134
|
+
@context.eval svgo_module
|
135
|
+
@context.call("svgo", {setup: @options})
|
149
136
|
end
|
150
137
|
|
151
138
|
def optimize(svg_data)
|
152
|
-
result = @context.call("svgo",
|
139
|
+
result = @context.call("svgo", {optimize: svg_data.to_s})
|
140
|
+
if not result
|
141
|
+
raise StandardError.new("Bad response from JavaScript runtime.")
|
142
|
+
end
|
153
143
|
if result['errors'].length > 0
|
154
144
|
if result['errors'].length > 1
|
155
145
|
err = %Q(Errors occurred: \n - #{result['errors'].join("\n - s")})
|
data/lib/version.rb
CHANGED
data/svgo-js/svgo-built.js
CHANGED
@@ -28934,7 +28934,7 @@ Writable.prototype._destroy = function (err, cb) {
|
|
28934
28934
|
cb(err);
|
28935
28935
|
};
|
28936
28936
|
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate)
|
28937
|
-
},{"./_stream_duplex":359,"./internal/streams/destroy":365,"./internal/streams/stream":366,"_process":357,"core-util-is":6,"inherits":309,"process-nextick-args":356,"safe-buffer":372,"timers":
|
28937
|
+
},{"./_stream_duplex":359,"./internal/streams/destroy":365,"./internal/streams/stream":366,"_process":357,"core-util-is":6,"inherits":309,"process-nextick-args":356,"safe-buffer":372,"timers":445,"util-deprecate":447}],364:[function(require,module,exports){
|
28938
28938
|
'use strict';
|
28939
28939
|
|
28940
28940
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
@@ -43669,7 +43669,133 @@ exports.fn = function(node, opts, extra) {
|
|
43669
43669
|
return node;
|
43670
43670
|
};
|
43671
43671
|
|
43672
|
-
},{"./_collections.js":398,"css-tree":19,"css-url-regex":119,"path":355,"unquote":
|
43672
|
+
},{"./_collections.js":398,"css-tree":19,"css-url-regex":119,"path":355,"unquote":446}],420:[function(require,module,exports){
|
43673
|
+
'use strict';
|
43674
|
+
|
43675
|
+
var DEFAULT_SEPARATOR = ':';
|
43676
|
+
|
43677
|
+
exports.type = 'perItem';
|
43678
|
+
|
43679
|
+
exports.active = false;
|
43680
|
+
|
43681
|
+
exports.description = 'removes specified attributes';
|
43682
|
+
|
43683
|
+
exports.params = {
|
43684
|
+
elemSeparator: DEFAULT_SEPARATOR,
|
43685
|
+
attrs: []
|
43686
|
+
};
|
43687
|
+
|
43688
|
+
/**
|
43689
|
+
* Remove attributes
|
43690
|
+
*
|
43691
|
+
* @param elemSeparator
|
43692
|
+
* format: string
|
43693
|
+
*
|
43694
|
+
* @param attrs:
|
43695
|
+
*
|
43696
|
+
* format: [ element* : attribute* ]
|
43697
|
+
*
|
43698
|
+
* element : regexp (wrapped into ^...$), single * or omitted > all elements
|
43699
|
+
* attribute : regexp (wrapped into ^...$)
|
43700
|
+
*
|
43701
|
+
* examples:
|
43702
|
+
*
|
43703
|
+
* > basic: remove fill attribute
|
43704
|
+
* ---
|
43705
|
+
* removeAttrs:
|
43706
|
+
* attrs: 'fill'
|
43707
|
+
*
|
43708
|
+
* > remove fill attribute on path element
|
43709
|
+
* ---
|
43710
|
+
* attrs: 'path:fill'
|
43711
|
+
*
|
43712
|
+
*
|
43713
|
+
* > remove all fill and stroke attribute
|
43714
|
+
* ---
|
43715
|
+
* attrs:
|
43716
|
+
* - 'fill'
|
43717
|
+
* - 'stroke'
|
43718
|
+
*
|
43719
|
+
* [is same as]
|
43720
|
+
*
|
43721
|
+
* attrs: '(fill|stroke)'
|
43722
|
+
*
|
43723
|
+
* [is same as]
|
43724
|
+
*
|
43725
|
+
* attrs: '*:(fill|stroke)'
|
43726
|
+
*
|
43727
|
+
* [is same as]
|
43728
|
+
*
|
43729
|
+
* attrs: '.*:(fill|stroke)'
|
43730
|
+
*
|
43731
|
+
*
|
43732
|
+
* > remove all stroke related attributes
|
43733
|
+
* ----
|
43734
|
+
* attrs: 'stroke.*'
|
43735
|
+
*
|
43736
|
+
*
|
43737
|
+
* @param {Object} item current iteration item
|
43738
|
+
* @param {Object} params plugin params
|
43739
|
+
* @return {Boolean} if false, item will be filtered out
|
43740
|
+
*
|
43741
|
+
* @author Benny Schudel
|
43742
|
+
*/
|
43743
|
+
exports.fn = function(item, params) {
|
43744
|
+
|
43745
|
+
// wrap into an array if params is not
|
43746
|
+
if (!Array.isArray(params.attrs)) {
|
43747
|
+
params.attrs = [params.attrs];
|
43748
|
+
}
|
43749
|
+
|
43750
|
+
if (item.isElem()) {
|
43751
|
+
var elemSeparator = typeof params.elemSeparator == 'string' ? params.elemSeparator : DEFAULT_SEPARATOR;
|
43752
|
+
|
43753
|
+
// prepare patterns
|
43754
|
+
var patterns = params.attrs.map(function(pattern) {
|
43755
|
+
|
43756
|
+
// apply to all elements if specifc element is omitted
|
43757
|
+
if (pattern.indexOf(elemSeparator) === -1) {
|
43758
|
+
pattern = ['.*', elemSeparator, pattern].join('');
|
43759
|
+
}
|
43760
|
+
|
43761
|
+
// create regexps for element and attribute name
|
43762
|
+
return pattern.split(elemSeparator)
|
43763
|
+
.map(function(value) {
|
43764
|
+
|
43765
|
+
// adjust single * to match anything
|
43766
|
+
if (value === '*') { value = '.*'; }
|
43767
|
+
|
43768
|
+
return new RegExp(['^', value, '$'].join(''), 'i');
|
43769
|
+
});
|
43770
|
+
|
43771
|
+
});
|
43772
|
+
|
43773
|
+
// loop patterns
|
43774
|
+
patterns.forEach(function(pattern) {
|
43775
|
+
|
43776
|
+
// matches element
|
43777
|
+
if (pattern[0].test(item.elem)) {
|
43778
|
+
|
43779
|
+
// loop attributes
|
43780
|
+
item.eachAttr(function(attr) {
|
43781
|
+
var name = attr.name;
|
43782
|
+
|
43783
|
+
// matches attribute name
|
43784
|
+
if (pattern[1].test(name)) {
|
43785
|
+
item.removeAttr(name);
|
43786
|
+
}
|
43787
|
+
|
43788
|
+
});
|
43789
|
+
|
43790
|
+
}
|
43791
|
+
|
43792
|
+
});
|
43793
|
+
|
43794
|
+
}
|
43795
|
+
|
43796
|
+
};
|
43797
|
+
|
43798
|
+
},{}],421:[function(require,module,exports){
|
43673
43799
|
'use strict';
|
43674
43800
|
|
43675
43801
|
exports.type = 'perItem';
|
@@ -43698,7 +43824,7 @@ exports.fn = function(item) {
|
|
43698
43824
|
|
43699
43825
|
};
|
43700
43826
|
|
43701
|
-
},{}],
|
43827
|
+
},{}],422:[function(require,module,exports){
|
43702
43828
|
'use strict';
|
43703
43829
|
|
43704
43830
|
exports.type = 'perItem';
|
@@ -43732,7 +43858,7 @@ exports.fn = function(item, params) {
|
|
43732
43858
|
|
43733
43859
|
};
|
43734
43860
|
|
43735
|
-
},{}],
|
43861
|
+
},{}],423:[function(require,module,exports){
|
43736
43862
|
'use strict';
|
43737
43863
|
|
43738
43864
|
exports.type = 'perItem';
|
@@ -43766,7 +43892,7 @@ exports.fn = function(item) {
|
|
43766
43892
|
|
43767
43893
|
};
|
43768
43894
|
|
43769
|
-
},{}],
|
43895
|
+
},{}],424:[function(require,module,exports){
|
43770
43896
|
'use strict';
|
43771
43897
|
|
43772
43898
|
exports.type = 'perItem';
|
@@ -43808,7 +43934,7 @@ exports.fn = function(item) {
|
|
43808
43934
|
|
43809
43935
|
};
|
43810
43936
|
|
43811
|
-
},{}],
|
43937
|
+
},{}],425:[function(require,module,exports){
|
43812
43938
|
'use strict';
|
43813
43939
|
|
43814
43940
|
exports.type = 'perItem';
|
@@ -43875,7 +44001,7 @@ exports.fn = function(item, params) {
|
|
43875
44001
|
|
43876
44002
|
};
|
43877
44003
|
|
43878
|
-
},{"./_collections":398}],
|
44004
|
+
},{"./_collections":398}],426:[function(require,module,exports){
|
43879
44005
|
'use strict';
|
43880
44006
|
|
43881
44007
|
exports.type = 'perItem';
|
@@ -43957,7 +44083,7 @@ exports.fn = function(item, params) {
|
|
43957
44083
|
}
|
43958
44084
|
};
|
43959
44085
|
|
43960
|
-
},{}],
|
44086
|
+
},{}],427:[function(require,module,exports){
|
43961
44087
|
'use strict';
|
43962
44088
|
|
43963
44089
|
exports.type = 'perItem';
|
@@ -43988,7 +44114,7 @@ exports.fn = function(item) {
|
|
43988
44114
|
|
43989
44115
|
};
|
43990
44116
|
|
43991
|
-
},{}],
|
44117
|
+
},{}],428:[function(require,module,exports){
|
43992
44118
|
'use strict';
|
43993
44119
|
|
43994
44120
|
exports.type = 'perItemReverse';
|
@@ -44022,7 +44148,7 @@ exports.fn = function(item) {
|
|
44022
44148
|
|
44023
44149
|
};
|
44024
44150
|
|
44025
|
-
},{"./_collections":398}],
|
44151
|
+
},{"./_collections":398}],429:[function(require,module,exports){
|
44026
44152
|
'use strict';
|
44027
44153
|
|
44028
44154
|
exports.type = 'perItem';
|
@@ -44083,7 +44209,7 @@ exports.fn = function(item, params) {
|
|
44083
44209
|
|
44084
44210
|
};
|
44085
44211
|
|
44086
|
-
},{}],
|
44212
|
+
},{}],430:[function(require,module,exports){
|
44087
44213
|
'use strict';
|
44088
44214
|
|
44089
44215
|
exports.type = 'perItem';
|
@@ -44310,7 +44436,7 @@ exports.fn = function (item, params) {
|
|
44310
44436
|
|
44311
44437
|
};
|
44312
44438
|
|
44313
|
-
},{}],
|
44439
|
+
},{}],431:[function(require,module,exports){
|
44314
44440
|
'use strict';
|
44315
44441
|
|
44316
44442
|
exports.type = 'perItem';
|
@@ -44335,7 +44461,7 @@ exports.fn = function(item) {
|
|
44335
44461
|
|
44336
44462
|
};
|
44337
44463
|
|
44338
|
-
},{}],
|
44464
|
+
},{}],432:[function(require,module,exports){
|
44339
44465
|
'use strict';
|
44340
44466
|
|
44341
44467
|
exports.type = 'perItem';
|
@@ -44374,7 +44500,7 @@ exports.fn = function(item) {
|
|
44374
44500
|
|
44375
44501
|
};
|
44376
44502
|
|
44377
|
-
},{"./_collections":398}],
|
44503
|
+
},{"./_collections":398}],433:[function(require,module,exports){
|
44378
44504
|
'use strict';
|
44379
44505
|
|
44380
44506
|
exports.type = 'perItem';
|
@@ -44404,7 +44530,7 @@ exports.fn = function(item) {
|
|
44404
44530
|
|
44405
44531
|
};
|
44406
44532
|
|
44407
|
-
},{}],
|
44533
|
+
},{}],434:[function(require,module,exports){
|
44408
44534
|
'use strict';
|
44409
44535
|
|
44410
44536
|
exports.type = 'perItem';
|
@@ -44429,7 +44555,7 @@ exports.fn = function(item) {
|
|
44429
44555
|
|
44430
44556
|
};
|
44431
44557
|
|
44432
|
-
},{}],
|
44558
|
+
},{}],435:[function(require,module,exports){
|
44433
44559
|
'use strict';
|
44434
44560
|
|
44435
44561
|
exports.type = 'perItem';
|
@@ -44454,7 +44580,7 @@ exports.fn = function(item) {
|
|
44454
44580
|
|
44455
44581
|
};
|
44456
44582
|
|
44457
|
-
},{}],
|
44583
|
+
},{}],436:[function(require,module,exports){
|
44458
44584
|
'use strict';
|
44459
44585
|
|
44460
44586
|
exports.type = 'perItem';
|
@@ -44479,7 +44605,7 @@ exports.fn = function(item) {
|
|
44479
44605
|
|
44480
44606
|
};
|
44481
44607
|
|
44482
|
-
},{}],
|
44608
|
+
},{}],437:[function(require,module,exports){
|
44483
44609
|
'use strict';
|
44484
44610
|
|
44485
44611
|
exports.type = 'perItem';
|
@@ -44631,7 +44757,7 @@ exports.fn = function(item, params) {
|
|
44631
44757
|
|
44632
44758
|
};
|
44633
44759
|
|
44634
|
-
},{"./_collections":398}],
|
44760
|
+
},{"./_collections":398}],438:[function(require,module,exports){
|
44635
44761
|
'use strict';
|
44636
44762
|
|
44637
44763
|
exports.type = 'full';
|
@@ -44740,7 +44866,7 @@ exports.fn = function(data) {
|
|
44740
44866
|
|
44741
44867
|
};
|
44742
44868
|
|
44743
|
-
},{}],
|
44869
|
+
},{}],439:[function(require,module,exports){
|
44744
44870
|
'use strict';
|
44745
44871
|
|
44746
44872
|
exports.type = 'perItem';
|
@@ -44795,7 +44921,7 @@ function getUsefulItems(item, usefulItems) {
|
|
44795
44921
|
return usefulItems;
|
44796
44922
|
}
|
44797
44923
|
|
44798
|
-
},{"./_collections":398}],
|
44924
|
+
},{"./_collections":398}],440:[function(require,module,exports){
|
44799
44925
|
'use strict';
|
44800
44926
|
|
44801
44927
|
exports.type = 'perItem';
|
@@ -44897,7 +45023,7 @@ exports.fn = function(item, params) {
|
|
44897
45023
|
|
44898
45024
|
};
|
44899
45025
|
|
44900
|
-
},{"./_collections":398}],
|
45026
|
+
},{"./_collections":398}],441:[function(require,module,exports){
|
44901
45027
|
'use strict';
|
44902
45028
|
|
44903
45029
|
exports.type = 'perItem';
|
@@ -44947,7 +45073,7 @@ exports.fn = function(item) {
|
|
44947
45073
|
|
44948
45074
|
};
|
44949
45075
|
|
44950
|
-
},{}],
|
45076
|
+
},{}],442:[function(require,module,exports){
|
44951
45077
|
'use strict';
|
44952
45078
|
|
44953
45079
|
exports.type = 'perItem';
|
@@ -44976,7 +45102,7 @@ exports.fn = function(item) {
|
|
44976
45102
|
}
|
44977
45103
|
|
44978
45104
|
};
|
44979
|
-
},{}],
|
45105
|
+
},{}],443:[function(require,module,exports){
|
44980
45106
|
'use strict';
|
44981
45107
|
|
44982
45108
|
exports.type = 'perItem';
|
@@ -45002,7 +45128,7 @@ exports.fn = function(item) {
|
|
45002
45128
|
|
45003
45129
|
};
|
45004
45130
|
|
45005
|
-
},{}],
|
45131
|
+
},{}],444:[function(require,module,exports){
|
45006
45132
|
'use strict';
|
45007
45133
|
|
45008
45134
|
exports.type = 'perItem';
|
@@ -45088,7 +45214,7 @@ exports.fn = function(item, params) {
|
|
45088
45214
|
|
45089
45215
|
};
|
45090
45216
|
|
45091
|
-
},{}],
|
45217
|
+
},{}],445:[function(require,module,exports){
|
45092
45218
|
(function (setImmediate,clearImmediate){
|
45093
45219
|
var nextTick = require('process/browser.js').nextTick;
|
45094
45220
|
var apply = Function.prototype.apply;
|
@@ -45167,7 +45293,7 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :
|
|
45167
45293
|
delete immediateIds[id];
|
45168
45294
|
};
|
45169
45295
|
}).call(this,require("timers").setImmediate,require("timers").clearImmediate)
|
45170
|
-
},{"process/browser.js":357,"timers":
|
45296
|
+
},{"process/browser.js":357,"timers":445}],446:[function(require,module,exports){
|
45171
45297
|
var reg = /[\'\"]/
|
45172
45298
|
|
45173
45299
|
module.exports = function unquote(str) {
|
@@ -45183,7 +45309,7 @@ module.exports = function unquote(str) {
|
|
45183
45309
|
return str
|
45184
45310
|
}
|
45185
45311
|
|
45186
|
-
},{}],
|
45312
|
+
},{}],447:[function(require,module,exports){
|
45187
45313
|
(function (global){
|
45188
45314
|
|
45189
45315
|
/**
|
@@ -45254,144 +45380,216 @@ function config (name) {
|
|
45254
45380
|
}
|
45255
45381
|
|
45256
45382
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
45257
|
-
},{}],
|
45258
|
-
|
45259
|
-
|
45260
|
-
|
45261
|
-
|
45262
|
-
|
45263
|
-
|
45264
|
-
addAttributesToSVGElement:
|
45265
|
-
|
45266
|
-
|
45267
|
-
|
45268
|
-
|
45269
|
-
|
45270
|
-
|
45271
|
-
|
45272
|
-
|
45273
|
-
|
45274
|
-
|
45275
|
-
|
45276
|
-
|
45277
|
-
|
45278
|
-
|
45279
|
-
|
45280
|
-
|
45281
|
-
|
45282
|
-
|
45283
|
-
|
45284
|
-
|
45285
|
-
|
45286
|
-
|
45287
|
-
|
45288
|
-
|
45289
|
-
|
45290
|
-
|
45291
|
-
|
45292
|
-
|
45293
|
-
|
45294
|
-
|
45295
|
-
|
45296
|
-
|
45297
|
-
|
45298
|
-
|
45299
|
-
|
45300
|
-
|
45301
|
-
|
45302
|
-
|
45303
|
-
|
45304
|
-
|
45305
|
-
|
45306
|
-
|
45307
|
-
|
45308
|
-
|
45309
|
-
|
45310
|
-
|
45311
|
-
|
45312
|
-
|
45313
|
-
|
45314
|
-
|
45315
|
-
|
45316
|
-
|
45317
|
-
|
45318
|
-
|
45319
|
-
|
45320
|
-
|
45321
|
-
|
45322
|
-
|
45323
|
-
|
45324
|
-
|
45325
|
-
|
45326
|
-
|
45383
|
+
},{}],448:[function(require,module,exports){
|
45384
|
+
'use strict'
|
45385
|
+
let CONFIG = require('../node_modules/svgo/lib/svgo/config.js')
|
45386
|
+
let SVG2JS = require('../node_modules/svgo/lib/svgo/svg2js.js')
|
45387
|
+
let PLUGINS = require('../node_modules/svgo/lib/svgo/plugins.js')
|
45388
|
+
let JS2SVG = require('../node_modules/svgo/lib/svgo/js2svg.js')
|
45389
|
+
let pluginModules = {
|
45390
|
+
addAttributesToSVGElement:
|
45391
|
+
require('../node_modules/svgo/plugins/addAttributesToSVGElement'),
|
45392
|
+
addClassesToSVGElement:
|
45393
|
+
require('../node_modules/svgo/plugins/addClassesToSVGElement'),
|
45394
|
+
cleanupAttrs:
|
45395
|
+
require('../node_modules/svgo/plugins/cleanupAttrs'),
|
45396
|
+
cleanupEnableBackground:
|
45397
|
+
require('../node_modules/svgo/plugins/cleanupEnableBackground'),
|
45398
|
+
cleanupIDs:
|
45399
|
+
require('../node_modules/svgo/plugins/cleanupIDs'),
|
45400
|
+
cleanupListOfValues:
|
45401
|
+
require('../node_modules/svgo/plugins/cleanupListOfValues'),
|
45402
|
+
cleanupNumericValues:
|
45403
|
+
require('../node_modules/svgo/plugins/cleanupNumericValues'),
|
45404
|
+
collapseGroups:
|
45405
|
+
require('../node_modules/svgo/plugins/collapseGroups'),
|
45406
|
+
convertColors:
|
45407
|
+
require('../node_modules/svgo/plugins/convertColors'),
|
45408
|
+
convertPathData:
|
45409
|
+
require('../node_modules/svgo/plugins/convertPathData'),
|
45410
|
+
convertShapeToPath:
|
45411
|
+
require('../node_modules/svgo/plugins/convertShapeToPath'),
|
45412
|
+
convertStyleToAttrs:
|
45413
|
+
require('../node_modules/svgo/plugins/convertStyleToAttrs'),
|
45414
|
+
convertTransform:
|
45415
|
+
require('../node_modules/svgo/plugins/convertTransform'),
|
45416
|
+
inlineStyles:
|
45417
|
+
require('../node_modules/svgo/plugins/inlineStyles'),
|
45418
|
+
mergePaths:
|
45419
|
+
require('../node_modules/svgo/plugins/mergePaths'),
|
45420
|
+
minifyStyles:
|
45421
|
+
require('../node_modules/svgo/plugins/minifyStyles'),
|
45422
|
+
moveElemsAttrsToGroup:
|
45423
|
+
require('../node_modules/svgo/plugins/moveElemsAttrsToGroup'),
|
45424
|
+
moveGroupAttrsToElems:
|
45425
|
+
require('../node_modules/svgo/plugins/moveGroupAttrsToElems'),
|
45426
|
+
prefixIds:
|
45427
|
+
require('../node_modules/svgo/plugins/prefixIds'),
|
45428
|
+
removeComments:
|
45429
|
+
require('../node_modules/svgo/plugins/removeComments'),
|
45430
|
+
removeDesc:
|
45431
|
+
require('../node_modules/svgo/plugins/removeDesc'),
|
45432
|
+
removeDimensions:
|
45433
|
+
require('../node_modules/svgo/plugins/removeDimensions'),
|
45434
|
+
removeDoctype:
|
45435
|
+
require('../node_modules/svgo/plugins/removeDoctype'),
|
45436
|
+
removeEditorsNSData:
|
45437
|
+
require('../node_modules/svgo/plugins/removeEditorsNSData'),
|
45438
|
+
removeElementsByAttr:
|
45439
|
+
require('../node_modules/svgo/plugins/removeElementsByAttr'),
|
45440
|
+
removeEmptyAttrs:
|
45441
|
+
require('../node_modules/svgo/plugins/removeEmptyAttrs'),
|
45442
|
+
removeEmptyContainers:
|
45443
|
+
require('../node_modules/svgo/plugins/removeEmptyContainers'),
|
45444
|
+
removeEmptyText:
|
45445
|
+
require('../node_modules/svgo/plugins/removeEmptyText'),
|
45446
|
+
removeHiddenElems:
|
45447
|
+
require('../node_modules/svgo/plugins/removeHiddenElems'),
|
45448
|
+
removeMetadata:
|
45449
|
+
require('../node_modules/svgo/plugins/removeMetadata'),
|
45450
|
+
removeNonInheritableGroupAttrs:
|
45451
|
+
require('../node_modules/svgo/plugins/removeNonInheritableGroupAttrs'),
|
45452
|
+
removeRasterImages:
|
45453
|
+
require('../node_modules/svgo/plugins/removeRasterImages'),
|
45454
|
+
removeScriptElement:
|
45455
|
+
require('../node_modules/svgo/plugins/removeScriptElement'),
|
45456
|
+
removeStyleElement:
|
45457
|
+
require('../node_modules/svgo/plugins/removeStyleElement'),
|
45458
|
+
removeTitle:
|
45459
|
+
require('../node_modules/svgo/plugins/removeTitle'),
|
45460
|
+
removeUnknownsAndDefaults:
|
45461
|
+
require('../node_modules/svgo/plugins/removeUnknownsAndDefaults'),
|
45462
|
+
removeUnusedNS:
|
45463
|
+
require('../node_modules/svgo/plugins/removeUnusedNS'),
|
45464
|
+
removeUselessDefs:
|
45465
|
+
require('../node_modules/svgo/plugins/removeUselessDefs'),
|
45466
|
+
removeUselessStrokeAndFill:
|
45467
|
+
require('../node_modules/svgo/plugins/removeUselessStrokeAndFill'),
|
45468
|
+
removeViewBox:
|
45469
|
+
require('../node_modules/svgo/plugins/removeViewBox'),
|
45470
|
+
removeXMLNS:
|
45471
|
+
require('../node_modules/svgo/plugins/removeXMLNS'),
|
45472
|
+
removeXMLProcInst:
|
45473
|
+
require('../node_modules/svgo/plugins/removeXMLProcInst'),
|
45474
|
+
sortAttrs:
|
45475
|
+
require('../node_modules/svgo/plugins/sortAttrs'),
|
45476
|
+
removeAttrs:
|
45477
|
+
require('../node_modules/svgo/plugins/removeAttrs')
|
45478
|
+
}
|
45479
|
+
|
45480
|
+
function isObject (item) {
|
45481
|
+
return (item && typeof item === 'object' && !Array.isArray(item))
|
45482
|
+
}
|
45483
|
+
|
45484
|
+
function mergeDeep (target, source) {
|
45485
|
+
let output = Object.assign({}, target)
|
45486
|
+
if (isObject(target) && isObject(source)) {
|
45487
|
+
Object.keys(source).forEach(key => {
|
45488
|
+
if (isObject(source[key])) {
|
45489
|
+
if (!(key in target)) {
|
45490
|
+
Object.assign(output, { [key]: source[key] })
|
45491
|
+
} else {
|
45492
|
+
output[key] = mergeDeep(target[key], source[key])
|
45493
|
+
}
|
45494
|
+
} else {
|
45495
|
+
Object.assign(output, { [key]: source[key] })
|
45496
|
+
}
|
45497
|
+
})
|
45498
|
+
}
|
45499
|
+
return output
|
45500
|
+
}
|
45501
|
+
|
45502
|
+
function SVGO (options) {
|
45503
|
+
let self = this
|
45504
|
+
let errors = []
|
45505
|
+
let log = []
|
45506
|
+
options.full = true
|
45507
|
+
options.plugins = options.plugins.map((plugin) => {
|
45508
|
+
let name = Object.keys(plugin)[0]
|
45509
|
+
let params = plugin[name]
|
45510
|
+
if (params) {
|
45511
|
+
params = typeof params === 'object' ? params : {}
|
45512
|
+
params = mergeDeep(pluginModules[name], params)
|
45513
|
+
params.active = true
|
45514
|
+
plugin[name] = params
|
45515
|
+
return plugin
|
45327
45516
|
}
|
45328
|
-
})
|
45329
|
-
|
45330
|
-
this.
|
45331
|
-
|
45332
|
-
|
45333
|
-
|
45334
|
-
|
45335
|
-
|
45336
|
-
|
45337
|
-
|
45338
|
-
self.svgjs = undefined
|
45339
|
-
SVG2JS(svgstr, function(svgjs) {
|
45517
|
+
})
|
45518
|
+
this.options = CONFIG(options)
|
45519
|
+
this.optimize = function (svgstr) {
|
45520
|
+
if (self.options.error) {
|
45521
|
+
errors.push('Configuration error: ' + self.options.error)
|
45522
|
+
}
|
45523
|
+
let passes = self.options.multipass ? 10 : 1
|
45524
|
+
let lastSize = Number.POSITIVE_INFINITY
|
45525
|
+
let newSize = 0
|
45526
|
+
let counter = 0
|
45527
|
+
self.svgjs = undefined
|
45528
|
+
SVG2JS(svgstr, function (svgjs) {
|
45340
45529
|
if (svgjs.error) {
|
45341
45530
|
// If we don't have anything yet, throw an exception.
|
45342
|
-
errors.push(
|
45531
|
+
errors.push('Error before optimization: ' + svgjs.error)
|
45343
45532
|
} else {
|
45344
45533
|
while (counter++ <= passes && newSize < lastSize) {
|
45345
|
-
lastSize = newSize
|
45534
|
+
lastSize = newSize
|
45346
45535
|
try {
|
45347
|
-
svgjs = self._optimize(svgjs, self.options.plugins)
|
45348
|
-
newSize = JS2SVG(svgjs, self.options.js2svg).data.length
|
45536
|
+
svgjs = self._optimize(svgjs, self.options.plugins)
|
45537
|
+
newSize = JS2SVG(svgjs, self.options.js2svg).data.length
|
45349
45538
|
} catch (exc) {
|
45350
45539
|
// Nothing to return yet..
|
45351
|
-
if (counter
|
45352
|
-
throw exc
|
45540
|
+
if (counter === 1) {
|
45541
|
+
throw exc
|
45542
|
+
}
|
45353
45543
|
// Get out of while loop, we have something to return
|
45354
45544
|
// that is somewhat optimized, only the last iteration
|
45355
45545
|
// failed.
|
45356
45546
|
errors.push(
|
45357
|
-
|
45358
|
-
|
45359
|
-
)
|
45360
|
-
break
|
45547
|
+
'Error occurred during optimization pass ' + counter +
|
45548
|
+
', returning data from pass ' + (counter - 1) + '.'
|
45549
|
+
)
|
45550
|
+
break
|
45361
45551
|
}
|
45362
45552
|
}
|
45363
|
-
self.svgjs = svgjs
|
45553
|
+
self.svgjs = svgjs
|
45364
45554
|
}
|
45365
|
-
})
|
45366
|
-
|
45367
|
-
if (self.svgjs !== undefined && typeof self.svgjs.content !==
|
45368
|
-
xml = JS2SVG(self.svgjs, self.options.js2svg).data
|
45555
|
+
})
|
45556
|
+
let xml
|
45557
|
+
if (self.svgjs !== undefined && typeof self.svgjs.content !== 'undefined') {
|
45558
|
+
xml = JS2SVG(self.svgjs, self.options.js2svg).data
|
45369
45559
|
}
|
45370
45560
|
return {
|
45371
45561
|
data: xml,
|
45372
|
-
errors
|
45562
|
+
errors,
|
45563
|
+
log,
|
45564
|
+
options,
|
45373
45565
|
passes: counter
|
45374
|
-
}
|
45375
|
-
}
|
45566
|
+
}
|
45567
|
+
}
|
45376
45568
|
}
|
45377
45569
|
|
45378
|
-
SVGO.prototype._optimize =
|
45570
|
+
SVGO.prototype._optimize = (svgjs, plugins) => {
|
45379
45571
|
// Optimization round..
|
45380
|
-
svgjs = PLUGINS(svgjs, {}, plugins)
|
45572
|
+
svgjs = PLUGINS(svgjs, {}, plugins)
|
45381
45573
|
if (svgjs.error) {
|
45382
|
-
// If we don
|
45383
|
-
throw
|
45574
|
+
// If we don't have anything yet, throw an exception.
|
45575
|
+
throw Error(
|
45576
|
+
`Error during optimization: ${svgjs.error} ${JSON.stringify(plugins)}`)
|
45384
45577
|
}
|
45385
45578
|
// If all went well keep the result.
|
45386
|
-
return svgjs
|
45387
|
-
}
|
45388
|
-
|
45389
|
-
module.exports =
|
45390
|
-
|
45391
|
-
|
45392
|
-
|
45393
|
-
|
45394
|
-
|
45579
|
+
return svgjs
|
45580
|
+
}
|
45581
|
+
let svgoContext
|
45582
|
+
module.exports = (obj) => {
|
45583
|
+
let command = Object.keys(obj)[0]
|
45584
|
+
let payload = obj[command]
|
45585
|
+
if (command === 'setup') {
|
45586
|
+
svgoContext = new SVGO(payload)
|
45587
|
+
return true
|
45588
|
+
} else if (command === 'optimize' && svgoContext) {
|
45589
|
+
return svgoContext.optimize(payload)
|
45590
|
+
}
|
45591
|
+
throw Error('You need to call `setup([options])` before calling optimize.')
|
45592
|
+
}
|
45395
45593
|
|
45396
|
-
},{"../node_modules/svgo/lib/svgo/config.js":389,"../node_modules/svgo/lib/svgo/js2svg.js":393,"../node_modules/svgo/lib/svgo/plugins.js":395,"../node_modules/svgo/lib/svgo/svg2js.js":396,"../node_modules/svgo/plugins/addAttributesToSVGElement":401,"../node_modules/svgo/plugins/addClassesToSVGElement":402,"../node_modules/svgo/plugins/cleanupAttrs":403,"../node_modules/svgo/plugins/cleanupEnableBackground":404,"../node_modules/svgo/plugins/cleanupIDs":405,"../node_modules/svgo/plugins/cleanupListOfValues":406,"../node_modules/svgo/plugins/cleanupNumericValues":407,"../node_modules/svgo/plugins/collapseGroups":408,"../node_modules/svgo/plugins/convertColors":409,"../node_modules/svgo/plugins/convertPathData":410,"../node_modules/svgo/plugins/convertShapeToPath":411,"../node_modules/svgo/plugins/convertStyleToAttrs":412,"../node_modules/svgo/plugins/convertTransform":413,"../node_modules/svgo/plugins/inlineStyles":414,"../node_modules/svgo/plugins/mergePaths":415,"../node_modules/svgo/plugins/minifyStyles":416,"../node_modules/svgo/plugins/moveElemsAttrsToGroup":417,"../node_modules/svgo/plugins/moveGroupAttrsToElems":418,"../node_modules/svgo/plugins/prefixIds":419,"../node_modules/svgo/plugins/
|
45594
|
+
},{"../node_modules/svgo/lib/svgo/config.js":389,"../node_modules/svgo/lib/svgo/js2svg.js":393,"../node_modules/svgo/lib/svgo/plugins.js":395,"../node_modules/svgo/lib/svgo/svg2js.js":396,"../node_modules/svgo/plugins/addAttributesToSVGElement":401,"../node_modules/svgo/plugins/addClassesToSVGElement":402,"../node_modules/svgo/plugins/cleanupAttrs":403,"../node_modules/svgo/plugins/cleanupEnableBackground":404,"../node_modules/svgo/plugins/cleanupIDs":405,"../node_modules/svgo/plugins/cleanupListOfValues":406,"../node_modules/svgo/plugins/cleanupNumericValues":407,"../node_modules/svgo/plugins/collapseGroups":408,"../node_modules/svgo/plugins/convertColors":409,"../node_modules/svgo/plugins/convertPathData":410,"../node_modules/svgo/plugins/convertShapeToPath":411,"../node_modules/svgo/plugins/convertStyleToAttrs":412,"../node_modules/svgo/plugins/convertTransform":413,"../node_modules/svgo/plugins/inlineStyles":414,"../node_modules/svgo/plugins/mergePaths":415,"../node_modules/svgo/plugins/minifyStyles":416,"../node_modules/svgo/plugins/moveElemsAttrsToGroup":417,"../node_modules/svgo/plugins/moveGroupAttrsToElems":418,"../node_modules/svgo/plugins/prefixIds":419,"../node_modules/svgo/plugins/removeAttrs":420,"../node_modules/svgo/plugins/removeComments":421,"../node_modules/svgo/plugins/removeDesc":422,"../node_modules/svgo/plugins/removeDimensions":423,"../node_modules/svgo/plugins/removeDoctype":424,"../node_modules/svgo/plugins/removeEditorsNSData":425,"../node_modules/svgo/plugins/removeElementsByAttr":426,"../node_modules/svgo/plugins/removeEmptyAttrs":427,"../node_modules/svgo/plugins/removeEmptyContainers":428,"../node_modules/svgo/plugins/removeEmptyText":429,"../node_modules/svgo/plugins/removeHiddenElems":430,"../node_modules/svgo/plugins/removeMetadata":431,"../node_modules/svgo/plugins/removeNonInheritableGroupAttrs":432,"../node_modules/svgo/plugins/removeRasterImages":433,"../node_modules/svgo/plugins/removeScriptElement":434,"../node_modules/svgo/plugins/removeStyleElement":435,"../node_modules/svgo/plugins/removeTitle":436,"../node_modules/svgo/plugins/removeUnknownsAndDefaults":437,"../node_modules/svgo/plugins/removeUnusedNS":438,"../node_modules/svgo/plugins/removeUselessDefs":439,"../node_modules/svgo/plugins/removeUselessStrokeAndFill":440,"../node_modules/svgo/plugins/removeViewBox":441,"../node_modules/svgo/plugins/removeXMLNS":442,"../node_modules/svgo/plugins/removeXMLProcInst":443,"../node_modules/svgo/plugins/sortAttrs":444}]},{},[448])(448)
|
45397
45595
|
});
|