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

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

primeNG components

  • Property mode set to 100644
File size: 2.3 KB
Line 
1'use strict';
2
3const {
4 defaultPlugins,
5 resolvePluginConfig,
6 extendDefaultPlugins,
7} = require('./svgo/config.js');
8const { parseSvg } = require('./parser.js');
9const { stringifySvg } = require('./stringifier.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 = stringifySvg(svgjs, config.js2svg);
57 if (svgjs.data.length < prevResultSize) {
58 input = svgjs.data;
59 prevResultSize = svgjs.data.length;
60 } else {
61 if (config.datauri) {
62 svgjs.data = encodeSVGDatauri(svgjs.data, config.datauri);
63 }
64 if (config.path != null) {
65 svgjs.path = config.path;
66 }
67 return svgjs;
68 }
69 }
70 return svgjs;
71};
72exports.optimize = optimize;
73
74/**
75 * The factory that creates a content item with the helper methods.
76 *
77 * @param {Object} data which is passed to jsAPI constructor
78 * @returns {JSAPI} content item
79 */
80const createContentItem = (data) => {
81 return new JSAPI(data);
82};
83exports.createContentItem = createContentItem;
Note: See TracBrowser for help on using the repository browser.