mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
Drop plugin by path support and load builtins statically
This commit is contained in:
@ -1,8 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var FS = require('fs');
|
const FS = require('fs');
|
||||||
var PATH = require('path');
|
const PATH = require('path');
|
||||||
var yaml = require('js-yaml');
|
const yaml = require('js-yaml');
|
||||||
|
const pluginsMap = require('../../plugins/plugins.js');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read and/or extend/replace default config file,
|
* Read and/or extend/replace default config file,
|
||||||
@ -79,7 +80,7 @@ function preparePluginsArray(config, plugins) {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
plugin = setPluginActiveState(
|
plugin = setPluginActiveState(
|
||||||
loadPlugin(config, key, item[key].path),
|
{ ...pluginsMap[key] },
|
||||||
item,
|
item,
|
||||||
key
|
key
|
||||||
);
|
);
|
||||||
@ -89,7 +90,7 @@ function preparePluginsArray(config, plugins) {
|
|||||||
// name
|
// name
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
plugin = loadPlugin(config, item);
|
plugin = { ...pluginsMap[item] };
|
||||||
plugin.name = item;
|
plugin.name = item;
|
||||||
if (typeof plugin.params === 'object') {
|
if (typeof plugin.params === 'object') {
|
||||||
plugin.params = Object.assign({}, plugin.params);
|
plugin.params = Object.assign({}, plugin.params);
|
||||||
@ -132,10 +133,6 @@ function extendConfig(defaults, config) {
|
|||||||
if (typeof item[key] === 'object' && item[key].fn && typeof item[key].fn === 'function') {
|
if (typeof item[key] === 'object' && item[key].fn && typeof item[key].fn === 'function') {
|
||||||
defaults.plugins.push(setupCustomPlugin(key, item[key]));
|
defaults.plugins.push(setupCustomPlugin(key, item[key]));
|
||||||
|
|
||||||
// plugin defined via path
|
|
||||||
} else if (typeof item[key] === 'object' && item[key].path) {
|
|
||||||
defaults.plugins.push(setPluginActiveState(loadPlugin(config, undefined, item[key].path), item, key));
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
defaults.plugins.forEach(function(plugin) {
|
defaults.plugins.forEach(function(plugin) {
|
||||||
|
|
||||||
@ -228,23 +225,3 @@ function setPluginActiveState(plugin, item, key) {
|
|||||||
|
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads default plugin using name or custom plugin defined via path in config.
|
|
||||||
*
|
|
||||||
* @param {Object} config
|
|
||||||
* @param {Object} name
|
|
||||||
* @param {Object} path
|
|
||||||
* @return {Object} plugin
|
|
||||||
*/
|
|
||||||
function loadPlugin(config, name, path) {
|
|
||||||
var plugin;
|
|
||||||
|
|
||||||
if (!path) {
|
|
||||||
plugin = require('../../plugins/' + name);
|
|
||||||
} else {
|
|
||||||
plugin = require(PATH.resolve(config.__DIR, path));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Object.assign({}, plugin);
|
|
||||||
}
|
|
||||||
|
49
plugins/plugins.js
Normal file
49
plugins/plugins.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
exports.addAttributesToSVGElement = require('./addAttributesToSVGElement.js');
|
||||||
|
exports.addClassesToSVGElement = require('./addClassesToSVGElement.js');
|
||||||
|
exports.cleanupAttrs = require('./cleanupAttrs.js');
|
||||||
|
exports.cleanupEnableBackground = require('./cleanupEnableBackground.js');
|
||||||
|
exports.cleanupIDs = require('./cleanupIDs.js');
|
||||||
|
exports.cleanupListOfValues = require('./cleanupListOfValues.js');
|
||||||
|
exports.cleanupNumericValues = require('./cleanupNumericValues.js');
|
||||||
|
exports.collapseGroups = require('./collapseGroups.js');
|
||||||
|
exports.convertColors = require('./convertColors.js');
|
||||||
|
exports.convertEllipseToCircle = require('./convertEllipseToCircle.js');
|
||||||
|
exports.convertPathData = require('./convertPathData.js');
|
||||||
|
exports.convertShapeToPath = require('./convertShapeToPath.js');
|
||||||
|
exports.convertStyleToAttrs = require('./convertStyleToAttrs.js');
|
||||||
|
exports.convertTransform = require('./convertTransform.js');
|
||||||
|
exports.inlineStyles = require('./inlineStyles.js');
|
||||||
|
exports.mergePaths = require('./mergePaths.js');
|
||||||
|
exports.minifyStyles = require('./minifyStyles.js');
|
||||||
|
exports.moveElemsAttrsToGroup = require('./moveElemsAttrsToGroup.js');
|
||||||
|
exports.moveGroupAttrsToElems = require('./moveGroupAttrsToElems.js');
|
||||||
|
exports.prefixIds = require('./prefixIds.js');
|
||||||
|
exports.removeAttributesBySelector = require('./removeAttributesBySelector.js');
|
||||||
|
exports.removeAttrs = require('./removeAttrs.js');
|
||||||
|
exports.removeComments = require('./removeComments.js');
|
||||||
|
exports.removeDesc = require('./removeDesc.js');
|
||||||
|
exports.removeDimensions = require('./removeDimensions.js');
|
||||||
|
exports.removeDoctype = require('./removeDoctype.js');
|
||||||
|
exports.removeEditorsNSData = require('./removeEditorsNSData.js');
|
||||||
|
exports.removeElementsByAttr = require('./removeElementsByAttr.js');
|
||||||
|
exports.removeEmptyAttrs = require('./removeEmptyAttrs.js');
|
||||||
|
exports.removeEmptyContainers = require('./removeEmptyContainers.js');
|
||||||
|
exports.removeEmptyText = require('./removeEmptyText.js');
|
||||||
|
exports.removeHiddenElems = require('./removeHiddenElems.js');
|
||||||
|
exports.removeMetadata = require('./removeMetadata.js');
|
||||||
|
exports.removeNonInheritableGroupAttrs = require('./removeNonInheritableGroupAttrs.js');
|
||||||
|
exports.removeOffCanvasPaths = require('./removeOffCanvasPaths.js');
|
||||||
|
exports.removeRasterImages = require('./removeRasterImages.js');
|
||||||
|
exports.removeScriptElement = require('./removeScriptElement.js');
|
||||||
|
exports.removeStyleElement = require('./removeStyleElement.js');
|
||||||
|
exports.removeTitle = require('./removeTitle.js');
|
||||||
|
exports.removeUnknownsAndDefaults = require('./removeUnknownsAndDefaults.js');
|
||||||
|
exports.removeUnusedNS = require('./removeUnusedNS.js');
|
||||||
|
exports.removeUselessDefs = require('./removeUselessDefs.js');
|
||||||
|
exports.removeUselessStrokeAndFill = require('./removeUselessStrokeAndFill.js');
|
||||||
|
exports.removeViewBox = require('./removeViewBox.js');
|
||||||
|
exports.removeXMLNS = require('./removeXMLNS.js');
|
||||||
|
exports.removeXMLProcInst = require('./removeXMLProcInst.js');
|
||||||
|
exports.reusePaths = require('./reusePaths.js');
|
||||||
|
exports.sortAttrs = require('./sortAttrs.js');
|
||||||
|
exports.sortDefsChildren = require('./sortDefsChildren.js');
|
@ -6,8 +6,9 @@ exports.active = false;
|
|||||||
|
|
||||||
exports.description = 'removes elements that are drawn outside of the viewbox (disabled by default)';
|
exports.description = 'removes elements that are drawn outside of the viewbox (disabled by default)';
|
||||||
|
|
||||||
var SVGO = require('../lib/svgo.js'),
|
const JSAPI = require('../lib/svgo/jsAPI.js');
|
||||||
_path = require('./_path.js'),
|
|
||||||
|
var _path = require('./_path.js'),
|
||||||
intersects = _path.intersects,
|
intersects = _path.intersects,
|
||||||
path2js = _path.path2js,
|
path2js = _path.path2js,
|
||||||
viewBox,
|
viewBox,
|
||||||
@ -97,7 +98,7 @@ function parseViewBox(svg)
|
|||||||
bottom: parseFloat(m[2]) + parseFloat(m[4])
|
bottom: parseFloat(m[2]) + parseFloat(m[4])
|
||||||
};
|
};
|
||||||
|
|
||||||
var path = new SVGO().createContentItem({
|
var path = new JSAPI({
|
||||||
elem: 'path',
|
elem: 'path',
|
||||||
prefix: '',
|
prefix: '',
|
||||||
local: 'path'
|
local: 'path'
|
||||||
|
@ -24,7 +24,7 @@ describe('plugins tests', function() {
|
|||||||
|
|
||||||
file = PATH.resolve(__dirname, file);
|
file = PATH.resolve(__dirname, file);
|
||||||
|
|
||||||
it(name + '.' + index, function() {
|
it.only(name + '.' + index, function() {
|
||||||
|
|
||||||
return readFile(file)
|
return readFile(file)
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
|
Reference in New Issue
Block a user