| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- 'use strict';
- const pluginsMap = require('../../plugins/plugins.js');
- const pluginsOrder = [
- 'removeDoctype',
- 'removeXMLProcInst',
- 'removeComments',
- 'removeMetadata',
- 'removeXMLNS',
- 'removeEditorsNSData',
- 'cleanupAttrs',
- 'mergeStyles',
- 'inlineStyles',
- 'minifyStyles',
- 'convertStyleToAttrs',
- 'cleanupIDs',
- 'prefixIds',
- 'removeRasterImages',
- 'removeUselessDefs',
- 'cleanupNumericValues',
- 'cleanupListOfValues',
- 'convertColors',
- 'removeUnknownsAndDefaults',
- 'removeNonInheritableGroupAttrs',
- 'removeUselessStrokeAndFill',
- 'removeViewBox',
- 'cleanupEnableBackground',
- 'removeHiddenElems',
- 'removeEmptyText',
- 'convertShapeToPath',
- 'convertEllipseToCircle',
- 'moveElemsAttrsToGroup',
- 'moveGroupAttrsToElems',
- 'collapseGroups',
- 'convertPathData',
- 'convertTransform',
- 'removeEmptyAttrs',
- 'removeEmptyContainers',
- 'mergePaths',
- 'removeUnusedNS',
- 'sortAttrs',
- 'sortDefsChildren',
- 'removeTitle',
- 'removeDesc',
- 'removeDimensions',
- 'removeAttrs',
- 'removeAttributesBySelector',
- 'removeElementsByAttr',
- 'addClassesToSVGElement',
- 'removeStyleElement',
- 'removeScriptElement',
- 'addAttributesToSVGElement',
- 'removeOffCanvasPaths',
- 'reusePaths',
- ];
- const defaultPlugins = pluginsOrder.filter((name) => pluginsMap[name].active);
- exports.defaultPlugins = defaultPlugins;
- const extendDefaultPlugins = (plugins) => {
- console.warn(
- '\n"extendDefaultPlugins" utility is deprecated.\n' +
- 'Use "preset-default" plugin with overrides instead.\n' +
- 'For example:\n' +
- `{\n` +
- ` name: 'preset-default',\n` +
- ` params: {\n` +
- ` overrides: {\n` +
- ` // customize plugin options\n` +
- ` convertShapeToPath: {\n` +
- ` convertArcs: true\n` +
- ` },\n` +
- ` // disable plugins\n` +
- ` convertPathData: false\n` +
- ` }\n` +
- ` }\n` +
- `}\n`
- );
- const extendedPlugins = pluginsOrder.map((name) => ({
- name,
- active: pluginsMap[name].active,
- }));
- for (const plugin of plugins) {
- const resolvedPlugin = resolvePluginConfig(plugin);
- const index = pluginsOrder.indexOf(resolvedPlugin.name);
- if (index === -1) {
- extendedPlugins.push(plugin);
- } else {
- extendedPlugins[index] = plugin;
- }
- }
- return extendedPlugins;
- };
- exports.extendDefaultPlugins = extendDefaultPlugins;
- const resolvePluginConfig = (plugin) => {
- let configParams = {};
- if (typeof plugin === 'string') {
- // resolve builtin plugin specified as string
- const pluginConfig = pluginsMap[plugin];
- if (pluginConfig == null) {
- throw Error(`Unknown builtin plugin "${plugin}" specified.`);
- }
- return {
- ...pluginConfig,
- name: plugin,
- active: true,
- params: { ...pluginConfig.params, ...configParams },
- };
- }
- if (typeof plugin === 'object' && plugin != null) {
- if (plugin.name == null) {
- throw Error(`Plugin name should be specified`);
- }
- if (plugin.fn) {
- // resolve custom plugin with implementation
- return {
- active: true,
- ...plugin,
- params: { ...configParams, ...plugin.params },
- };
- } else {
- // resolve builtin plugin specified as object without implementation
- const pluginConfig = pluginsMap[plugin.name];
- if (pluginConfig == null) {
- throw Error(`Unknown builtin plugin "${plugin.name}" specified.`);
- }
- return {
- ...pluginConfig,
- active: true,
- ...plugin,
- params: { ...pluginConfig.params, ...configParams, ...plugin.params },
- };
- }
- }
- return null;
- };
- exports.resolvePluginConfig = resolvePluginConfig;
|