svgo 0.1.7 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4b4f58ca387e882c969739c3a7eb34033e3a437
4
- data.tar.gz: 845dc991d02d9c670d0cf1e193553d85e87d2e9d
3
+ metadata.gz: 9736533516c323e32c469677ffe1077df1aa9643
4
+ data.tar.gz: 9979d1903f52702ab52c6a556156cc8ee5ab57b2
5
5
  SHA512:
6
- metadata.gz: a9e701c7e89508e1a111785bbccadb62c2580955aeef958154dffed7a19c5ccd4a77b93fe9aed3afe472d18284b42af87d5cbbaa254efacc031882cc8fdb8825
7
- data.tar.gz: 1d5ba9c255b78e6eceed95281b95dd2f6bb7c08df9301ce3301e8dba5febb268a1439e6d631898b4b087bccffb81831780117e43aa9f858e38298985c0129a23
6
+ metadata.gz: 5c6e546856027895bbc54696ce96c53c2c190e4482c80896ba21bf87470b79d04639774599488a5c6696338e07e4d96fe1773777345cc5ed00b58b47a93d075a
7
+ data.tar.gz: 5dea61b7b5e8f201c81ffa257d91c72d7ba026fbd18aa685d648c80537df272e16d87e8a968ed940087ad275e7de5249e23048bfdd9d08f6a5d074a711b4d900
@@ -1,106 +1,7 @@
1
+ root: true
2
+ parserOptions:
3
+ ecmaVersion: 6
1
4
  env:
2
5
  node: true
3
- extends: 'eslint:recommended'
4
- parserOptions:
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/README.MD CHANGED
@@ -7,6 +7,15 @@ Removes metadata and editor data elements and attributes that are redundant
7
7
  from SVG files. Can strip files so they are optimised for web use. Go to
8
8
  [SVGO](https://github.com/svg/svgo) for more documentation on features.
9
9
 
10
+ # Note to users of 1.x versions
11
+
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.
16
+
17
+
18
+
10
19
  ## How to use?
11
20
 
12
21
  ### As a library
@@ -63,14 +72,14 @@ require('svgo')
63
72
  svg_file = "path/to/a.svg"
64
73
  options = {
65
74
  plugins: {
66
- :addAttributesToSVGElement=>true,
67
- :addClassesToSVGElement=>true,
68
- :cleanupAttrs=>false,
69
- :cleanupEnableBackground=>true,
70
- :cleanupIDs=>false,
71
- :cleanupListOfValues=>true,
72
- :cleanupNumericValues=>true,
73
- :collapseGroups=>true,
75
+ addAttributesToSVGElement: true,
76
+ addClassesToSVGElement: true,
77
+ cleanupAttrs: false,
78
+ cleanupEnableBackground: true,
79
+ cleanupIDs: false,
80
+ cleanupListOfValues: true,
81
+ collapseGroups: true,
82
+ cleanupNumericValues: true,
74
83
  #etc..
75
84
  }
76
85
  }
@@ -109,33 +118,24 @@ docker run -i svgo < test/fixtures/ruby.svg > test/fixtures/ruby.optim.svg
109
118
 
110
119
  ## How this works
111
120
 
112
- [`execjs`](https://github.com/rails/execjs) is used to run the Node SVGO as a
113
- library. The SVGO library returns a JavaScript Promise, which is currently not
114
- supported by `execjs` and probably never will be. `setTimeout` and sleep-like
115
- functions are also disabled in `execjs` so we can't wait for the Promise to get
116
- fulfilled. Therefore there is a small wrapper JavaScript in this repository
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
117
127
  that calls all the components that SVGO is made up of, but without the
118
128
  `Promise`. It also wraps up the configuration of plugins the way it is expected
119
- by SVGO's components. Lastly `require` is not supported by `execjs` so all of
120
- this is transpiled to one monolithic JavaScript file - that is completely
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
121
131
  self-contained, using [browserify](http://browserify.org/).
122
132
 
123
- __NOTE:__ `execjs` supports a variety of JavaSript runtimes, notably
124
- [`therubyracer`](https://github.com/cowboyd/therubyracer), but `therubyracer`
125
- depends on an ancient [`libv8`](https://github.com/cowboyd/libv8), which
126
- doesn't support some of the modern syntax used in SVGO. Therefore `mini_racer`
127
- (a drop in replacement for `therubyracer`) is a dependency, which uses a much
128
- more recent `libv8`.
129
-
130
- If you have [Node](https://nodejs.org/) installed you could also use that as a
131
- runtime.
132
-
133
133
  ### Transpiling Node SVGO
134
134
 
135
135
  __TL;DR:__ A transpiled version of SVGO is included in the repository, so you
136
136
  don't need to transpile anything.
137
137
 
138
- Because `execjs` supports only self-contained modules, and does not allow
138
+ Because `mini_racer` supports only self-contained modules, and does not allow
139
139
  `require()`, `Promise` etc.. The SGVO library is wrapped in a JavaScript that
140
140
  requires all the main parts of SVGO and makes an SVGO function without
141
141
  JavaScript Promises. The wrapper is then transpiled to a self-contained module
@@ -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 ""
@@ -1,11 +1,10 @@
1
- require 'execjs'
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,37 +119,24 @@ 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
- ExecJS::Runtimes::MiniRacer,
127
- ExecJS::Runtimes::Node
128
- ]
129
- runtime = runtimes.select {|r| r.available?}.first
130
- unless runtime
131
- raise ExecJS::RuntimeUnavailable.new(
132
- "No supported runtime available please install " \
133
- "`mini_racer` or `NodeJS`."
134
- )
135
- end
136
- end
137
- ExecJS.runtime = runtime
138
122
  if not @options[:plugins]
139
123
  @options[:plugins] = PLUGINS_DEFAULT
140
124
  end
141
- if @options[:plugins].is_a? Array
142
- @options[:plugins] = @options[:plugins].map {|p| [p, true]}.to_h
125
+ if not @options[:plugins].is_a? Array
126
+ raise StandardError.new("`options.plugins` should be an Array.")
143
127
  end
128
+ @options[:plugins] = @options[:plugins].map { | p |
129
+ p.is_a?(Hash) ? p : {p => true}
130
+ }
144
131
  svgo_js = File.expand_path("../../svgo-js/svgo-built.js", __FILE__)
145
132
  svgo_module = File.open(svgo_js, "r:utf-8", &:read)
146
- @context = ExecJS.compile(svgo_module)
133
+ @context = MiniRacer::Context.new
134
+ @context.eval svgo_module
135
+ @context.call("svgo", {setup: @options})
147
136
  end
148
137
 
149
138
  def optimize(svg_data)
150
- result = @context.call("svgo", @options.to_json, svg_data.to_s)
139
+ result = @context.call("svgo", {optimize: svg_data.to_s})
151
140
  if not result
152
141
  raise StandardError.new("Bad response from JavaScript runtime.")
153
142
  end
@@ -1,3 +1,3 @@
1
1
  module SvgoVersion
2
- VERSION = '0.1.7'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -45381,144 +45381,215 @@ function config (name) {
45381
45381
 
45382
45382
  }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
45383
45383
  },{}],448:[function(require,module,exports){
45384
- "use strict";
45385
- var CONFIG = require("../node_modules/svgo/lib/svgo/config.js");
45386
- var SVG2JS = require("../node_modules/svgo/lib/svgo/svg2js.js");
45387
- var PLUGINS = require("../node_modules/svgo/lib/svgo/plugins.js");
45388
- var JS2SVG = require("../node_modules/svgo/lib/svgo/js2svg.js");
45389
- var pluginModules = {
45390
- addAttributesToSVGElement: require("../node_modules/svgo/plugins/addAttributesToSVGElement"),
45391
- addClassesToSVGElement: require("../node_modules/svgo/plugins/addClassesToSVGElement"),
45392
- cleanupAttrs: require("../node_modules/svgo/plugins/cleanupAttrs"),
45393
- cleanupEnableBackground: require("../node_modules/svgo/plugins/cleanupEnableBackground"),
45394
- cleanupIDs: require("../node_modules/svgo/plugins/cleanupIDs"),
45395
- cleanupListOfValues: require("../node_modules/svgo/plugins/cleanupListOfValues"),
45396
- cleanupNumericValues: require("../node_modules/svgo/plugins/cleanupNumericValues"),
45397
- collapseGroups: require("../node_modules/svgo/plugins/collapseGroups"),
45398
- convertColors: require("../node_modules/svgo/plugins/convertColors"),
45399
- convertPathData: require("../node_modules/svgo/plugins/convertPathData"),
45400
- convertShapeToPath: require("../node_modules/svgo/plugins/convertShapeToPath"),
45401
- convertStyleToAttrs: require("../node_modules/svgo/plugins/convertStyleToAttrs"),
45402
- convertTransform: require("../node_modules/svgo/plugins/convertTransform"),
45403
- inlineStyles: require("../node_modules/svgo/plugins/inlineStyles"),
45404
- mergePaths: require("../node_modules/svgo/plugins/mergePaths"),
45405
- minifyStyles: require("../node_modules/svgo/plugins/minifyStyles"),
45406
- moveElemsAttrsToGroup: require("../node_modules/svgo/plugins/moveElemsAttrsToGroup"),
45407
- moveGroupAttrsToElems: require("../node_modules/svgo/plugins/moveGroupAttrsToElems"),
45408
- prefixIds: require("../node_modules/svgo/plugins/prefixIds"),
45409
- removeComments: require("../node_modules/svgo/plugins/removeComments"),
45410
- removeDesc: require("../node_modules/svgo/plugins/removeDesc"),
45411
- removeDimensions: require("../node_modules/svgo/plugins/removeDimensions"),
45412
- removeDoctype: require("../node_modules/svgo/plugins/removeDoctype"),
45413
- removeEditorsNSData: require("../node_modules/svgo/plugins/removeEditorsNSData"),
45414
- removeElementsByAttr: require("../node_modules/svgo/plugins/removeElementsByAttr"),
45415
- removeEmptyAttrs: require("../node_modules/svgo/plugins/removeEmptyAttrs"),
45416
- removeEmptyContainers: require("../node_modules/svgo/plugins/removeEmptyContainers"),
45417
- removeEmptyText: require("../node_modules/svgo/plugins/removeEmptyText"),
45418
- removeHiddenElems: require("../node_modules/svgo/plugins/removeHiddenElems"),
45419
- removeMetadata: require("../node_modules/svgo/plugins/removeMetadata"),
45420
- removeNonInheritableGroupAttrs: require("../node_modules/svgo/plugins/removeNonInheritableGroupAttrs"),
45421
- removeRasterImages: require("../node_modules/svgo/plugins/removeRasterImages"),
45422
- removeScriptElement: require("../node_modules/svgo/plugins/removeScriptElement"),
45423
- removeStyleElement: require("../node_modules/svgo/plugins/removeStyleElement"),
45424
- removeTitle: require("../node_modules/svgo/plugins/removeTitle"),
45425
- removeUnknownsAndDefaults: require("../node_modules/svgo/plugins/removeUnknownsAndDefaults"),
45426
- removeUnusedNS: require("../node_modules/svgo/plugins/removeUnusedNS"),
45427
- removeUselessDefs: require("../node_modules/svgo/plugins/removeUselessDefs"),
45428
- removeUselessStrokeAndFill: require("../node_modules/svgo/plugins/removeUselessStrokeAndFill"),
45429
- removeViewBox: require("../node_modules/svgo/plugins/removeViewBox"),
45430
- removeXMLNS: require("../node_modules/svgo/plugins/removeXMLNS"),
45431
- removeXMLProcInst: require("../node_modules/svgo/plugins/removeXMLProcInst"),
45432
- sortAttrs: require("../node_modules/svgo/plugins/sortAttrs"),
45433
- removeAttrs: require("../node_modules/svgo/plugins/removeAttrs")
45434
- };
45435
-
45436
- function SVGO(options) {
45437
- var self = this;
45438
- var plugins = options.plugins;
45439
- options.plugins = [];
45440
-
45441
- Object.keys(plugins).forEach(function(key){
45442
- var value = plugins[key];
45443
- var plugin = {};
45444
- plugin[key] = pluginModules[key];
45445
- switch(typeof value) {
45446
- case "boolean":
45447
- if (value)
45448
- options.plugins.push(plugin);
45449
- break;
45450
- default:
45451
- plugin.params = value;
45452
- options.plugins.push(plugin);
45453
- break;
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
45454
45516
  }
45455
- });
45456
- var errors = [];
45457
- this.options = CONFIG(options);
45458
- this.optimize = function(svgstr) {
45459
- if (self.options.error)
45460
- errors.push("Configuration error: " + self.options.error);
45461
- var passes = self.options.multipass ? 10 : 1;
45462
- var lastSize = Number.POSITIVE_INFINITY;
45463
- var newSize = 0;
45464
- var counter = 0;
45465
- self.svgjs = undefined;
45466
- 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) {
45467
45529
  if (svgjs.error) {
45468
45530
  // If we don't have anything yet, throw an exception.
45469
- errors.push("Error before optimization: " + svgjs.error);
45531
+ errors.push('Error before optimization: ' + svgjs.error)
45470
45532
  } else {
45471
45533
  while (counter++ <= passes && newSize < lastSize) {
45472
- lastSize = newSize;
45534
+ lastSize = newSize
45473
45535
  try {
45474
- svgjs = self._optimize(svgjs, self.options.plugins);
45475
- 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
45476
45538
  } catch (exc) {
45477
45539
  // Nothing to return yet..
45478
- if (counter == 1)
45479
- throw exc;
45540
+ if (counter === 1) {
45541
+ throw exc
45542
+ }
45480
45543
  // Get out of while loop, we have something to return
45481
45544
  // that is somewhat optimized, only the last iteration
45482
45545
  // failed.
45483
45546
  errors.push(
45484
- "Error occurred during optimization pass " + counter +
45485
- ", returning data from pass " + (counter - 1) +"."
45486
- );
45487
- break;
45547
+ 'Error occurred during optimization pass ' + counter +
45548
+ ', returning data from pass ' + (counter - 1) + '.'
45549
+ )
45550
+ break
45488
45551
  }
45489
45552
  }
45490
- self.svgjs = svgjs;
45553
+ self.svgjs = svgjs
45491
45554
  }
45492
- });
45493
- var xml;
45494
- if (self.svgjs !== undefined && typeof self.svgjs.content !== "undefined") {
45495
- 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
45496
45559
  }
45497
45560
  return {
45498
45561
  data: xml,
45499
- errors: errors,
45562
+ errors,
45563
+ log,
45564
+ options,
45500
45565
  passes: counter
45501
- };
45502
- };
45566
+ }
45567
+ }
45503
45568
  }
45504
45569
 
45505
- SVGO.prototype._optimize = function(svgjs, plugins) {
45570
+ SVGO.prototype._optimize = (svgjs, plugins) => {
45506
45571
  // Optimization round..
45507
- svgjs = PLUGINS(svgjs, {}, plugins);
45572
+ svgjs = PLUGINS(svgjs, {}, plugins)
45508
45573
  if (svgjs.error) {
45509
- // If we don"t have anything yet, throw an exception.
45510
- throw "Error during optimization: " + svgjs.error;
45574
+ // If we don't have anything yet, throw an exception.
45575
+ throw Error(
45576
+ `Error during optimization: ${svgjs.error} ${JSON.stringify(plugins)}`)
45511
45577
  }
45512
45578
  // If all went well keep the result.
45513
- return svgjs;
45514
- };
45515
-
45516
- module.exports = function(options, data) {
45517
- options = JSON.parse(options);
45518
- options.full = true;
45519
- var svgoContext = new SVGO(options);
45520
- return svgoContext.optimize(data);
45521
- };
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
+ }
45522
45593
 
45523
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)
45524
45595
  });