@iconify/tools 1.3.17 → 2.0.0-dev.2

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.
Files changed (147) hide show
  1. package/.editorconfig +13 -0
  2. package/.eslintignore +2 -0
  3. package/lib/colors/attribs.d.ts +16 -0
  4. package/lib/colors/attribs.js +26 -0
  5. package/lib/colors/attribs.mjs +28 -0
  6. package/lib/colors/parse.d.ts +37 -0
  7. package/lib/colors/parse.js +261 -0
  8. package/lib/colors/parse.mjs +212 -0
  9. package/lib/css/parse.d.ts +4 -0
  10. package/lib/css/parse.js +23 -0
  11. package/lib/css/parse.mjs +20 -0
  12. package/lib/css/parser/error.d.ts +11 -0
  13. package/lib/css/parser/error.js +27 -0
  14. package/lib/css/parser/error.mjs +23 -0
  15. package/lib/css/parser/export.d.ts +5 -0
  16. package/lib/css/parser/export.js +69 -0
  17. package/lib/css/parser/export.mjs +46 -0
  18. package/lib/css/parser/strings.d.ts +13 -0
  19. package/lib/css/parser/strings.js +93 -0
  20. package/lib/css/parser/strings.mjs +74 -0
  21. package/lib/css/parser/text.d.ts +17 -0
  22. package/lib/css/parser/text.js +174 -0
  23. package/lib/css/parser/text.mjs +133 -0
  24. package/lib/css/parser/tokens.d.ts +6 -0
  25. package/lib/css/parser/tokens.js +200 -0
  26. package/lib/css/parser/tokens.mjs +186 -0
  27. package/lib/css/parser/tree.d.ts +5 -0
  28. package/lib/css/parser/tree.js +44 -0
  29. package/lib/css/parser/tree.mjs +40 -0
  30. package/lib/css/parser/types.d.ts +51 -0
  31. package/lib/css/parser/types.js +2 -0
  32. package/lib/css/parser/types.mjs +0 -0
  33. package/lib/icon-set/index.d.ts +134 -0
  34. package/lib/icon-set/index.js +776 -0
  35. package/lib/icon-set/index.mjs +617 -0
  36. package/lib/icon-set/match.d.ts +6 -0
  37. package/lib/icon-set/match.js +66 -0
  38. package/lib/icon-set/match.mjs +55 -0
  39. package/lib/icon-set/merge.d.ts +5 -0
  40. package/lib/icon-set/merge.js +91 -0
  41. package/lib/icon-set/merge.mjs +75 -0
  42. package/lib/icon-set/props.d.ts +10 -0
  43. package/lib/icon-set/props.js +33 -0
  44. package/lib/icon-set/props.mjs +25 -0
  45. package/lib/icon-set/types.d.ts +68 -0
  46. package/lib/icon-set/types.js +2 -0
  47. package/lib/icon-set/types.mjs +0 -0
  48. package/lib/import/directory.d.ts +35 -0
  49. package/lib/import/directory.js +59 -0
  50. package/lib/import/directory.mjs +47 -0
  51. package/lib/misc/keyword.d.ts +4 -0
  52. package/lib/misc/keyword.js +31 -0
  53. package/lib/misc/keyword.mjs +17 -0
  54. package/lib/misc/scan.d.ts +24 -0
  55. package/lib/misc/scan.js +48 -0
  56. package/lib/misc/scan.mjs +43 -0
  57. package/lib/optimise/flags.d.ts +5 -0
  58. package/lib/optimise/flags.js +303 -0
  59. package/lib/optimise/flags.mjs +241 -0
  60. package/lib/optimise/scale.d.ts +5 -0
  61. package/lib/optimise/scale.js +42 -0
  62. package/lib/optimise/scale.mjs +22 -0
  63. package/lib/optimise/svgo.d.ts +27 -0
  64. package/lib/optimise/svgo.js +88 -0
  65. package/lib/optimise/svgo.mjs +75 -0
  66. package/lib/svg/cleanup/attribs.d.ts +5 -0
  67. package/lib/svg/cleanup/attribs.js +43 -0
  68. package/lib/svg/cleanup/attribs.mjs +36 -0
  69. package/lib/svg/cleanup/bad-tags.d.ts +5 -0
  70. package/lib/svg/cleanup/bad-tags.js +69 -0
  71. package/lib/svg/cleanup/bad-tags.mjs +68 -0
  72. package/lib/svg/cleanup/inline-style.d.ts +5 -0
  73. package/lib/svg/cleanup/inline-style.js +77 -0
  74. package/lib/svg/cleanup/inline-style.mjs +65 -0
  75. package/lib/svg/cleanup/root-svg.d.ts +5 -0
  76. package/lib/svg/cleanup/root-svg.js +106 -0
  77. package/lib/svg/cleanup/root-svg.mjs +88 -0
  78. package/lib/svg/cleanup/svgo-style.d.ts +5 -0
  79. package/lib/svg/cleanup/svgo-style.js +35 -0
  80. package/lib/svg/cleanup/svgo-style.mjs +29 -0
  81. package/lib/svg/cleanup.d.ts +5 -0
  82. package/lib/svg/cleanup.js +24 -0
  83. package/lib/svg/cleanup.mjs +16 -0
  84. package/lib/svg/data/attributes.d.ts +71 -0
  85. package/lib/svg/data/attributes.js +403 -0
  86. package/lib/svg/data/attributes.mjs +352 -0
  87. package/lib/svg/data/tags.d.ts +89 -0
  88. package/lib/svg/data/tags.js +185 -0
  89. package/lib/svg/data/tags.mjs +136 -0
  90. package/lib/svg/index.d.ts +33 -0
  91. package/lib/svg/index.js +122 -0
  92. package/lib/svg/index.mjs +85 -0
  93. package/lib/svg/parse-style.d.ts +40 -0
  94. package/lib/svg/parse-style.js +131 -0
  95. package/lib/svg/parse-style.mjs +109 -0
  96. package/lib/svg/parse.d.ts +30 -0
  97. package/lib/svg/parse.js +49 -0
  98. package/lib/svg/parse.mjs +40 -0
  99. package/package.json +167 -13
  100. package/README.md +0 -576
  101. package/license.txt +0 -21
  102. package/sample/parse.js +0 -74
  103. package/sample/source/icon-close.svg +0 -15
  104. package/sample/source/icon-confirm.svg +0 -14
  105. package/sample/source/icon-search.svg +0 -16
  106. package/src/collection.js +0 -641
  107. package/src/colors/change_palette.js +0 -227
  108. package/src/colors/get_palette.js +0 -143
  109. package/src/colors/opacify.js +0 -195
  110. package/src/export/component.js +0 -482
  111. package/src/export/dir.js +0 -109
  112. package/src/export/json.js +0 -329
  113. package/src/export/phantomjs.js +0 -76
  114. package/src/export/phantomjs_script.js +0 -125
  115. package/src/export/png.js +0 -193
  116. package/src/export/svg.js +0 -55
  117. package/src/export/templates/component.md +0 -79
  118. package/src/export/templates/info.md +0 -3
  119. package/src/export/templates/sample-react-1.md +0 -21
  120. package/src/export/templates/sample-react-2.md +0 -15
  121. package/src/export/templates/sample-react.md +0 -11
  122. package/src/export/templates/sample-svelte.md +0 -11
  123. package/src/export/templates/sample-svelte1.md +0 -22
  124. package/src/export/templates/sample-svelte2.md +0 -13
  125. package/src/export/templates/sample-vue-0.md +0 -30
  126. package/src/export/templates/sample-vue-1.md +0 -25
  127. package/src/export/templates/sample-vue-2.md +0 -27
  128. package/src/export/templates/sample-vue.md +0 -28
  129. package/src/helpers.js +0 -43
  130. package/src/import/dir.js +0 -234
  131. package/src/import/font.js +0 -402
  132. package/src/import/json.js +0 -200
  133. package/src/import/svg.js +0 -60
  134. package/src/import/web_icons.js +0 -248
  135. package/src/modules.js +0 -50
  136. package/src/optimize/crop.js +0 -554
  137. package/src/optimize/crop_script.js +0 -525
  138. package/src/optimize/flags.js +0 -430
  139. package/src/optimize/scale.js +0 -72
  140. package/src/optimize/svgo.js +0 -161
  141. package/src/optimize/tags.js +0 -522
  142. package/src/shapes/convert.js +0 -264
  143. package/src/shapes/index.js +0 -135
  144. package/src/shapes/length.js +0 -707
  145. package/src/shapes/length_script.js +0 -105
  146. package/src/shapes/options.js +0 -60
  147. package/src/svg.js +0 -162
@@ -1,430 +0,0 @@
1
- /**
2
- * This file is part of the @iconify/tools package.
3
- *
4
- * (c) Vjacheslav Trushkin <cyberalien@gmail.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- 'use strict';
11
-
12
- const cheerio = require('cheerio');
13
- const SVG = require('../svg');
14
-
15
- const debug = false;
16
-
17
- /*
18
- Parts of code are based on svg-pathdata code (license: MIT)
19
- */
20
-
21
- /**
22
- * Command constants
23
- *
24
- * @type {number}
25
- */
26
- const CLOSE_PATH = 1;
27
- const MOVE_TO = 2;
28
- const HORIZ_LINE_TO = 4;
29
- const VERT_LINE_TO = 8;
30
- const LINE_TO = 16;
31
- const CURVE_TO = 32;
32
- const SMOOTH_CURVE_TO = 64;
33
- const QUAD_TO = 128;
34
- const SMOOTH_QUAD_TO = 256;
35
- const ARC = 512;
36
- const LINE_COMMANDS = LINE_TO | HORIZ_LINE_TO | VERT_LINE_TO;
37
- const DRAWING_COMMANDS =
38
- HORIZ_LINE_TO |
39
- VERT_LINE_TO |
40
- LINE_TO |
41
- CURVE_TO |
42
- SMOOTH_CURVE_TO |
43
- QUAD_TO |
44
- SMOOTH_QUAD_TO |
45
- ARC;
46
-
47
- /**
48
- * Number of arguments for each command
49
- *
50
- * @type {object}
51
- */
52
- const argCount = {
53
- [MOVE_TO]: 2,
54
- [LINE_TO]: 2,
55
- [HORIZ_LINE_TO]: 1,
56
- [VERT_LINE_TO]: 1,
57
- [CLOSE_PATH]: 0,
58
- [QUAD_TO]: 4,
59
- [SMOOTH_QUAD_TO]: 2,
60
- [CURVE_TO]: 6,
61
- [SMOOTH_CURVE_TO]: 4,
62
- [ARC]: 7,
63
- };
64
-
65
- /**
66
- * Check if character is a digit
67
- *
68
- * @param {number} num
69
- * @return {boolean}
70
- */
71
- const isDigit = num => num >= 48 && num <= 57;
72
-
73
- /**
74
- * Check if character is white space
75
- *
76
- * @param {number} num
77
- * @return {boolean}
78
- */
79
- const isWhiteSpace = num => num === 32 || num === 9 || num === 13 || num === 10;
80
-
81
- /**
82
- * Clean up path
83
- *
84
- * @param {string} path
85
- * @return {string}
86
- */
87
- function cleanPath(path) {
88
- let commands = [],
89
- length = path.length,
90
- currentNumber = '',
91
- currentNumberHasExp = false,
92
- currentNumberHasExpDigits = false,
93
- currentNumberHasDecimal = false,
94
- canParseCommandOrComma = true,
95
- currentCommand = null,
96
- currentCommandType = null,
97
- currentArgs = [],
98
- i,
99
- char,
100
- num;
101
-
102
- const finishCommand = () => {
103
- if (debug) {
104
- console.log('Finishing command "' + currentCommand + '"', currentArgs);
105
- }
106
- commands.push({
107
- command: currentCommand,
108
- params: currentArgs.slice(0),
109
- });
110
- currentArgs = [];
111
- canParseCommandOrComma = true;
112
- };
113
-
114
- const parseNumber = () => {
115
- // Number ended - validate it
116
- if (currentNumber !== '' && currentCommandType) {
117
- let value = Number(currentNumber);
118
- if (isNaN(value)) {
119
- throw new Error('Invalid number "' + currentNumber + '" at ' + i);
120
- }
121
-
122
- // Validate arc arguments
123
- if (currentCommandType === ARC) {
124
- if (currentArgs.length < 2 && value <= 0) {
125
- if (debug) {
126
- console.log(
127
- 'Command: "' + currentCommand + '", args: ',
128
- currentArgs
129
- );
130
- }
131
- throw new Error(
132
- 'Expected positive number, got "' + value + '" at ' + i
133
- );
134
- }
135
-
136
- while (true) {
137
- // Not flag
138
- if (currentArgs.length < 3 || currentArgs.length > 4) {
139
- break;
140
- }
141
- // Valid flag
142
- if (currentNumber === '0' || currentNumber === '1') {
143
- break;
144
- }
145
- // Unpack flag
146
- let slice = currentNumber.slice(0, 1),
147
- newNumber = currentNumber.slice(1),
148
- newValue = Number(newNumber);
149
-
150
- if (slice === '0' || slice === '1') {
151
- // Valid flag
152
- if (isNaN(newValue)) {
153
- throw new Error('Invalid number "' + currentNumber + '" at ' + i);
154
- }
155
- if (debug) {
156
- console.log('Compressed flag "' + slice + '" at ' + i);
157
- }
158
- currentArgs.push(slice);
159
- currentNumber = newNumber;
160
- value = newValue;
161
- continue;
162
- }
163
-
164
- if (debug) {
165
- console.log(
166
- 'Command: "' + currentCommand + '", args: ',
167
- currentArgs
168
- );
169
- }
170
- throw new Error(
171
- 'Expected a flag, got "' + currentNumber + '" at ' + i
172
- );
173
- }
174
- }
175
-
176
- // Add current number to arguments list
177
- if (debug) {
178
- console.log('End of number "' + currentNumber + '" at ' + i);
179
- }
180
- currentArgs.push(currentNumber);
181
-
182
- if (currentArgs.length === argCount[currentCommandType]) {
183
- finishCommand();
184
- }
185
-
186
- currentNumber = '';
187
- currentNumberHasExpDigits = false;
188
- currentNumberHasExp = false;
189
- currentNumberHasDecimal = false;
190
- canParseCommandOrComma = true;
191
- }
192
- };
193
-
194
- if (debug) {
195
- console.log('Parsing "' + path + '"');
196
- }
197
-
198
- for (i = 0; i < length; i++) {
199
- char = path[i];
200
- num = char.charCodeAt(0);
201
-
202
- // Test for number
203
- if (isDigit(num)) {
204
- // console.log('Digit "' + char + '" at ' + i);
205
- currentNumber += char;
206
- currentNumberHasExpDigits = currentNumberHasExp;
207
- continue;
208
- }
209
-
210
- // Test for exponential number
211
- if (char === 'e' || char === 'E') {
212
- // console.log('Digit "' + char + '" at ' + i);
213
- currentNumber += char;
214
- currentNumberHasExp = true;
215
- continue;
216
- }
217
-
218
- // Test for number signs
219
- if (
220
- (char === '-' || char === '+') &&
221
- currentNumberHasExp &&
222
- !currentNumberHasExpDigits
223
- ) {
224
- // console.log('Digit "' + char + '" at ' + i);
225
- currentNumber += char;
226
- continue;
227
- }
228
-
229
- // Decimal point
230
- if (char === '.' && !currentNumberHasExp && !currentNumberHasDecimal) {
231
- // console.log('Digit "' + char + '" at ' + i);
232
- currentNumber += char;
233
- currentNumberHasDecimal = true;
234
- continue;
235
- }
236
-
237
- // Number ended - validate it
238
- parseNumber();
239
-
240
- // White space
241
- if (isWhiteSpace(num)) {
242
- // console.log('Whitespace "' + char + '" at ' + i);
243
- continue;
244
- }
245
-
246
- // Only one comma per command
247
- if (canParseCommandOrComma && char === ',') {
248
- // console.log('Comma at ' + i);
249
- canParseCommandOrComma = false;
250
- continue;
251
- }
252
-
253
- // New number
254
- if (char === '+' || char === '-' || char === '.') {
255
- // console.log('Digit "' + char + '" at ' + i);
256
- currentNumber = char;
257
- currentNumberHasDecimal = char === '.';
258
- continue;
259
- }
260
-
261
- // Expecting new command, so argument should be empty
262
- if (currentArgs.length > 0) {
263
- throw new Error('Unexpected command at ' + i);
264
- }
265
-
266
- // Test comma, reset value
267
- if (!canParseCommandOrComma) {
268
- throw new Error('Command cannot follow comma at ' + i + '');
269
- }
270
- canParseCommandOrComma = false;
271
-
272
- // Detect next command
273
- // console.log('New command "' + char + '" at ' + i);
274
- currentCommand = char;
275
- switch (char) {
276
- case 'z':
277
- case 'Z':
278
- // Close path
279
- commands.push({
280
- command: char,
281
- params: [],
282
- });
283
- canParseCommandOrComma = true;
284
- currentCommandType = null;
285
- currentCommand = null;
286
- break;
287
-
288
- case 'h':
289
- case 'H':
290
- // Horizontal move
291
- currentCommandType = HORIZ_LINE_TO;
292
- break;
293
-
294
- case 'v':
295
- case 'V':
296
- // Vertical move
297
- currentCommandType = VERT_LINE_TO;
298
- break;
299
-
300
- case 'm':
301
- case 'M':
302
- // Move to
303
- currentCommandType = MOVE_TO;
304
- break;
305
-
306
- case 'l':
307
- case 'L':
308
- // Line to
309
- currentCommandType = LINE_TO;
310
- break;
311
-
312
- case 'c':
313
- case 'C':
314
- // Curve
315
- currentCommandType = CURVE_TO;
316
- break;
317
-
318
- case 's':
319
- case 'S':
320
- // Smooth curve
321
- currentCommandType = SMOOTH_CURVE_TO;
322
- break;
323
-
324
- case 'q':
325
- case 'Q':
326
- // Quadratic bezier curve
327
- currentCommandType = QUAD_TO;
328
- break;
329
-
330
- case 't':
331
- case 'T':
332
- // Smooth quadratic bezier curve
333
- currentCommandType = SMOOTH_QUAD_TO;
334
- break;
335
-
336
- case 'a':
337
- case 'A':
338
- // Elliptic arc
339
- currentCommandType = ARC;
340
- break;
341
-
342
- default:
343
- throw new Error('Unexpected character "' + char + '" at ' + i);
344
- }
345
- }
346
-
347
- // Parse last number
348
- parseNumber();
349
-
350
- // Add last command
351
- if (currentArgs.length) {
352
- if (!currentCommandType) {
353
- throw new Error('Empty path');
354
- }
355
- if (currentArgs.length !== argCount[currentCommandType]) {
356
- throw new Error('Unexpected end of path at ' + i);
357
- }
358
- finishCommand();
359
- }
360
-
361
- // Build path
362
- let output = '';
363
-
364
- commands.forEach(item => {
365
- output += item.command;
366
-
367
- item.params.forEach((value, index) => {
368
- if (index > 0) {
369
- let char = value[0];
370
- // noinspection FallThroughInSwitchStatementJS
371
- switch (char) {
372
- case '-':
373
- case '+':
374
- // Number - no space
375
- break;
376
-
377
- case '.':
378
- // Dot - no space if previous entry was command
379
- if (index < 1) {
380
- break;
381
- }
382
-
383
- // No space if previous entry had dot
384
- if (item.params[index - 1].indexOf('.') !== -1) {
385
- break;
386
- }
387
-
388
- default:
389
- output += ' ';
390
- }
391
- }
392
- output += value;
393
- });
394
- });
395
-
396
- return output;
397
- }
398
-
399
- /**
400
- * Undo compressed flags
401
- *
402
- * @param {string|SVG} code
403
- * @return {string|SVG}
404
- */
405
- const cleanUpFlags = code => {
406
- let svg = typeof code === 'object' ? code : new SVG(code),
407
- $root = svg.$svg(':root');
408
-
409
- function checkNodes($parent) {
410
- $parent.children().each((index, child) => {
411
- let $child = cheerio(child);
412
-
413
- switch (child.tagName) {
414
- case 'path':
415
- if (child.attribs && child.attribs.d) {
416
- child.attribs.d = cleanPath(child.attribs.d);
417
- }
418
- break;
419
- }
420
-
421
- checkNodes($child);
422
- });
423
- }
424
-
425
- checkNodes($root);
426
-
427
- return typeof code === 'object' ? svg : svg.toString();
428
- };
429
-
430
- module.exports = cleanUpFlags;
@@ -1,72 +0,0 @@
1
- /**
2
- * This file is part of the @iconify/tools package.
3
- *
4
- * (c) Vjacheslav Trushkin <cyberalien@gmail.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- 'use strict';
11
-
12
- const svgo = require('svgo');
13
-
14
- /**
15
- * Scale SVG
16
- *
17
- * @param {SVG} svg SVG object
18
- * @param {number} scale
19
- * @return {Promise}
20
- */
21
- module.exports = (svg, scale) => {
22
- return new Promise((fulfill, reject) => {
23
- try {
24
- let width = svg.width * scale,
25
- height = svg.height * scale,
26
- left = svg.left * scale,
27
- top = svg.top * scale,
28
- content =
29
- '<svg width="' +
30
- width +
31
- '" height="' +
32
- height +
33
- '" viewBox="' +
34
- left +
35
- ' ' +
36
- top +
37
- ' ' +
38
- width +
39
- ' ' +
40
- height +
41
- '" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
42
- '<g transform="scale(' +
43
- scale +
44
- ')">' +
45
- svg.getBody() +
46
- '</g></svg>';
47
-
48
- new svgo({
49
- plugins: [
50
- {
51
- mergePaths: false,
52
- },
53
- ],
54
- })
55
- .optimize(content)
56
- .then(result => {
57
- if (!result || !result.info || !result.data) {
58
- return reject(result.error ? result.error : 'Invalid SVG file');
59
- }
60
-
61
- // Update SVG object
62
- svg.load(result.data);
63
- fulfill(svg);
64
- })
65
- .catch(err => {
66
- return reject(err);
67
- });
68
- } catch (err) {
69
- reject(err);
70
- }
71
- });
72
- };
@@ -1,161 +0,0 @@
1
- /**
2
- * This file is part of the @iconify/tools package.
3
- *
4
- * (c) Vjacheslav Trushkin <cyberalien@gmail.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- 'use strict';
11
-
12
- const cheerio = require('cheerio');
13
- const svgo = require('svgo');
14
- const SVG = require('../svg');
15
- const cleanUpFlags = require('./flags');
16
-
17
- /**
18
- * Default options
19
- *
20
- * @type {object}
21
- */
22
- const defaults = {
23
- // Run SVGO twice
24
- 'doublePass': false,
25
-
26
- // Custom array of SVGO plugins
27
- 'plugins': null,
28
-
29
- // Options below are ignored if "plugins" is set
30
- 'id-prefix': 'svg-', // Replace id prefix. Set to null to disable
31
- 'mergePaths': false, // Merge paths
32
- 'convertShapeToPath': true, // Converts shapes to paths
33
- 'noSpaceAfterFlags': false, // Removes space after flags in paths
34
- };
35
-
36
- /**
37
- * SVGO optimization
38
- *
39
- * @param {SVG|string} svg SVG object
40
- * @param {object} [options] Options
41
- * @return {Promise}
42
- */
43
- const optimize = (svg, options) => {
44
- return new Promise((fulfill, reject) => {
45
- try {
46
- let content = typeof svg === 'string' ? svg : svg.toString();
47
-
48
- let plugins;
49
- if (options.plugins instanceof Array) {
50
- plugins = options.plugins;
51
- } else {
52
- plugins = [
53
- {
54
- removeTitle: true,
55
- },
56
- {
57
- removeDesc: true,
58
- },
59
- {
60
- removeRasterImages: true,
61
- },
62
- {
63
- convertShapeToPath: options.convertShapeToPath,
64
- },
65
- ];
66
-
67
- if (!options.noSpaceAfterFlags) {
68
- plugins.push({
69
- mergePaths:
70
- options.mergePaths === false
71
- ? false
72
- : {
73
- noSpaceAfterFlags: false,
74
- },
75
- });
76
- plugins.push({
77
- convertPathData: {
78
- noSpaceAfterFlags: false,
79
- },
80
- });
81
- } else {
82
- plugins.push({
83
- mergePaths: options.mergePaths,
84
- });
85
- }
86
-
87
- if (options['id-prefix'] !== null) {
88
- plugins.push({
89
- cleanupIDs: {
90
- remove: true,
91
- prefix: options['id-prefix'],
92
- },
93
- });
94
- }
95
- }
96
-
97
- new svgo({
98
- plugins: plugins,
99
- })
100
- .optimize(content)
101
- .then((result) => {
102
- if (!result || !result.info || !result.data) {
103
- return reject(result.error ? result.error : 'Invalid SVG file');
104
- }
105
-
106
- let code;
107
- try {
108
- code = options.noSpaceAfterFlags
109
- ? result.data
110
- : cleanUpFlags(result.data);
111
- } catch (err) {
112
- return reject(err);
113
- }
114
-
115
- // Update SVG object or return string
116
- if (typeof svg === 'string') {
117
- fulfill(code);
118
- } else {
119
- svg.load(code);
120
- fulfill(svg);
121
- }
122
- })
123
- .catch((err) => {
124
- return reject(err);
125
- });
126
- } catch (err) {
127
- reject(err);
128
- }
129
- });
130
- };
131
-
132
- module.exports = (svg, options) => {
133
- // Set options
134
- options = options === void 0 ? Object.create(null) : options;
135
- Object.keys(defaults).forEach((key) => {
136
- if (options[key] === void 0) {
137
- options[key] = defaults[key];
138
- }
139
- });
140
-
141
- return new Promise((fulfill, reject) => {
142
- // Check for doublePass
143
- const doublePass = options.doublePass;
144
- optimize(svg, options)
145
- .then((result) => {
146
- if (doublePass) {
147
- return optimize(result, options);
148
- } else {
149
- fulfill(result);
150
- }
151
- })
152
- .then((result) => {
153
- if (doublePass) {
154
- fulfill(result);
155
- }
156
- })
157
- .catch((err) => {
158
- reject(err);
159
- });
160
- });
161
- };