source: trip-planner-front/node_modules/svgo/lib/svgo/config.js@ 6a3a178

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

initial commit

  • Property mode set to 100644
File size: 3.6 KB
Line 
1'use strict';
2
3const pluginsMap = require('../../plugins/plugins.js');
4
5const pluginsOrder = [
6 'removeDoctype',
7 'removeXMLProcInst',
8 'removeComments',
9 'removeMetadata',
10 'removeXMLNS',
11 'removeEditorsNSData',
12 'cleanupAttrs',
13 'mergeStyles',
14 'inlineStyles',
15 'minifyStyles',
16 'convertStyleToAttrs',
17 'cleanupIDs',
18 'prefixIds',
19 'removeRasterImages',
20 'removeUselessDefs',
21 'cleanupNumericValues',
22 'cleanupListOfValues',
23 'convertColors',
24 'removeUnknownsAndDefaults',
25 'removeNonInheritableGroupAttrs',
26 'removeUselessStrokeAndFill',
27 'removeViewBox',
28 'cleanupEnableBackground',
29 'removeHiddenElems',
30 'removeEmptyText',
31 'convertShapeToPath',
32 'convertEllipseToCircle',
33 'moveElemsAttrsToGroup',
34 'moveGroupAttrsToElems',
35 'collapseGroups',
36 'convertPathData',
37 'convertTransform',
38 'removeEmptyAttrs',
39 'removeEmptyContainers',
40 'mergePaths',
41 'removeUnusedNS',
42 'sortAttrs',
43 'sortDefsChildren',
44 'removeTitle',
45 'removeDesc',
46 'removeDimensions',
47 'removeAttrs',
48 'removeAttributesBySelector',
49 'removeElementsByAttr',
50 'addClassesToSVGElement',
51 'removeStyleElement',
52 'removeScriptElement',
53 'addAttributesToSVGElement',
54 'removeOffCanvasPaths',
55 'reusePaths',
56];
57const defaultPlugins = pluginsOrder.filter((name) => pluginsMap[name].active);
58exports.defaultPlugins = defaultPlugins;
59
60const extendDefaultPlugins = (plugins) => {
61 console.warn(
62 '\n"extendDefaultPlugins" utility is deprecated.\n' +
63 'Use "preset-default" plugin with overrides instead.\n' +
64 'For example:\n' +
65 `{\n` +
66 ` name: 'preset-default',\n` +
67 ` params: {\n` +
68 ` overrides: {\n` +
69 ` // customize plugin options\n` +
70 ` convertShapeToPath: {\n` +
71 ` convertArcs: true\n` +
72 ` },\n` +
73 ` // disable plugins\n` +
74 ` convertPathData: false\n` +
75 ` }\n` +
76 ` }\n` +
77 `}\n`
78 );
79 const extendedPlugins = pluginsOrder.map((name) => ({
80 name,
81 active: pluginsMap[name].active,
82 }));
83 for (const plugin of plugins) {
84 const resolvedPlugin = resolvePluginConfig(plugin);
85 const index = pluginsOrder.indexOf(resolvedPlugin.name);
86 if (index === -1) {
87 extendedPlugins.push(plugin);
88 } else {
89 extendedPlugins[index] = plugin;
90 }
91 }
92 return extendedPlugins;
93};
94exports.extendDefaultPlugins = extendDefaultPlugins;
95
96const resolvePluginConfig = (plugin) => {
97 let configParams = {};
98 if (typeof plugin === 'string') {
99 // resolve builtin plugin specified as string
100 const pluginConfig = pluginsMap[plugin];
101 if (pluginConfig == null) {
102 throw Error(`Unknown builtin plugin "${plugin}" specified.`);
103 }
104 return {
105 ...pluginConfig,
106 name: plugin,
107 active: true,
108 params: { ...pluginConfig.params, ...configParams },
109 };
110 }
111 if (typeof plugin === 'object' && plugin != null) {
112 if (plugin.name == null) {
113 throw Error(`Plugin name should be specified`);
114 }
115 if (plugin.fn) {
116 // resolve custom plugin with implementation
117 return {
118 active: true,
119 ...plugin,
120 params: { ...configParams, ...plugin.params },
121 };
122 } else {
123 // resolve builtin plugin specified as object without implementation
124 const pluginConfig = pluginsMap[plugin.name];
125 if (pluginConfig == null) {
126 throw Error(`Unknown builtin plugin "${plugin.name}" specified.`);
127 }
128 return {
129 ...pluginConfig,
130 active: true,
131 ...plugin,
132 params: { ...pluginConfig.params, ...configParams, ...plugin.params },
133 };
134 }
135 }
136 return null;
137};
138exports.resolvePluginConfig = resolvePluginConfig;
Note: See TracBrowser for help on using the repository browser.