source: trip-planner-front/node_modules/svgo/lib/svgo.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.4 KB
Line 
1'use strict';
2
3const {
4 defaultPlugins,
5 resolvePluginConfig,
6 extendDefaultPlugins,
7} = require('./svgo/config.js');
8const { parseSvg } = require('./parser.js');
9const js2svg = require('./svgo/js2svg.js');
10const { invokePlugins } = require('./svgo/plugins.js');
11const JSAPI = require('./svgo/jsAPI.js');
12const { encodeSVGDatauri } = require('./svgo/tools.js');
13
14exports.extendDefaultPlugins = extendDefaultPlugins;
15
16const optimize = (input, config) => {
17 if (config == null) {
18 config = {};
19 }
20 if (typeof config !== 'object') {
21 throw Error('Config should be an object');
22 }
23 const maxPassCount = config.multipass ? 10 : 1;
24 let prevResultSize = Number.POSITIVE_INFINITY;
25 let svgjs = null;
26 const info = {};
27 if (config.path != null) {
28 info.path = config.path;
29 }
30 for (let i = 0; i < maxPassCount; i += 1) {
31 info.multipassCount = i;
32 // TODO throw this error in v3
33 try {
34 svgjs = parseSvg(input, config.path);
35 } catch (error) {
36 return { error: error.toString(), modernError: error };
37 }
38 if (svgjs.error != null) {
39 if (config.path != null) {
40 svgjs.path = config.path;
41 }
42 return svgjs;
43 }
44 const plugins = config.plugins || defaultPlugins;
45 if (Array.isArray(plugins) === false) {
46 throw Error(
47 "Invalid plugins list. Provided 'plugins' in config should be an array."
48 );
49 }
50 const resolvedPlugins = plugins.map(resolvePluginConfig);
51 const globalOverrides = {};
52 if (config.floatPrecision != null) {
53 globalOverrides.floatPrecision = config.floatPrecision;
54 }
55 svgjs = invokePlugins(svgjs, info, resolvedPlugins, null, globalOverrides);
56 svgjs = js2svg(svgjs, config.js2svg);
57 if (svgjs.error) {
58 throw Error(svgjs.error);
59 }
60 if (svgjs.data.length < prevResultSize) {
61 input = svgjs.data;
62 prevResultSize = svgjs.data.length;
63 } else {
64 if (config.datauri) {
65 svgjs.data = encodeSVGDatauri(svgjs.data, config.datauri);
66 }
67 if (config.path != null) {
68 svgjs.path = config.path;
69 }
70 return svgjs;
71 }
72 }
73 return svgjs;
74};
75exports.optimize = optimize;
76
77/**
78 * The factory that creates a content item with the helper methods.
79 *
80 * @param {Object} data which is passed to jsAPI constructor
81 * @returns {JSAPI} content item
82 */
83const createContentItem = (data) => {
84 return new JSAPI(data);
85};
86exports.createContentItem = createContentItem;
Note: See TracBrowser for help on using the repository browser.