Comparing version 2.0.2 to 2.0.3
@@ -42,2 +42,3 @@ 'use strict'; | ||
let dir = cwd; | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
@@ -44,0 +45,0 @@ const file = path.join(dir, "svgo.config.js"); |
@@ -43,10 +43,14 @@ 'use strict'; | ||
svgjs = svg2js(input); | ||
if (svgjs.error == null) { | ||
const plugins = config.plugins || defaultPlugins; | ||
if (Array.isArray(plugins) === false) { | ||
throw Error('Invalid plugins list. Provided \'plugins\' in config should be an array.'); | ||
if (svgjs.error != null) { | ||
if (config.path != null) { | ||
svgjs.path = config.path; | ||
} | ||
const resolvedPlugins = plugins.map(plugin => resolvePluginConfig(plugin, config)) | ||
svgjs = invokePlugins(svgjs, info, resolvedPlugins); | ||
return svgjs; | ||
} | ||
const plugins = config.plugins || defaultPlugins; | ||
if (Array.isArray(plugins) === false) { | ||
throw Error('Invalid plugins list. Provided \'plugins\' in config should be an array.'); | ||
} | ||
const resolvedPlugins = plugins.map(plugin => resolvePluginConfig(plugin, config)) | ||
svgjs = invokePlugins(svgjs, info, resolvedPlugins); | ||
svgjs = js2svg(svgjs, config.js2svg); | ||
@@ -53,0 +57,0 @@ if (svgjs.error) { |
@@ -1,2 +0,1 @@ | ||
/* jshint quotmark: false */ | ||
'use strict'; | ||
@@ -49,3 +48,3 @@ | ||
async function action(args, opts) { | ||
async function action(args, opts, command) { | ||
var input = opts.input || args; | ||
@@ -95,3 +94,5 @@ var output = opts.output; | ||
process.stdin.isTTY === true | ||
) return program.help(); | ||
) { | ||
return command.help(); | ||
} | ||
@@ -286,2 +287,9 @@ if (typeof process == 'object' && process.versions && process.versions.node && PKG && PKG.engines.node) { | ||
const result = optimize(data, { ...config, ...info }); | ||
if (result.error) { | ||
let message = result.error; | ||
if (result.path != null) { | ||
message += `\nFile: ${result.path}` | ||
} | ||
throw Error(message) | ||
} | ||
if (config.datauri) { | ||
@@ -288,0 +296,0 @@ result.data = encodeSVGDatauri(result.data, config.datauri); |
@@ -228,3 +228,2 @@ 'use strict'; | ||
JSAPI.prototype.computedAttr = function(name, val) { | ||
/* jshint eqnull: true */ | ||
if (!arguments.length) return; | ||
@@ -231,0 +230,0 @@ |
@@ -7,3 +7,3 @@ 'use strict'; | ||
CSSStyleDeclaration = require('./css-style-declaration'), | ||
entityDeclaration = /<!ENTITY\s+(\S+)\s+(?:'([^\']+)'|"([^\"]+)")\s*>/g; | ||
entityDeclaration = /<!ENTITY\s+(\S+)\s+(?:'([^']+)'|"([^"]+)")\s*>/g; | ||
@@ -10,0 +10,0 @@ var config = { |
@@ -83,3 +83,4 @@ 'use strict'; | ||
// no extra space after 'arcto' command flags | ||
// no extra space after 'arcto' command flags(large-arc and sweep flags) | ||
// a20 60 45 0 1 30 20 → a20 60 45 0130 20 | ||
if (params.noSpaceAfterFlags && (command == 'A' || command == 'a')) { | ||
@@ -86,0 +87,0 @@ var pos = i % 7; |
{ | ||
"name": "svgo", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Nodejs-based tool for optimizing SVG vector graphics files", | ||
@@ -52,6 +52,41 @@ "keywords": [ | ||
"scripts": { | ||
"test": "nyc --reporter=html --reporter=text mocha \"test/*/_index.js\"", | ||
"test": "c8 --reporter=html --reporter=text mocha \"test/*/_index.js\"", | ||
"lint": "eslint .", | ||
"test-browser": "rollup -c && node ./test/browser.js", | ||
"prepublishOnly": "rollup -c" | ||
"prepublishOnly": "rm -rf dist && rollup -c" | ||
}, | ||
"eslintConfig": { | ||
"ignorePatterns": [ | ||
"dist", | ||
"fixtures" | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": "2021" | ||
}, | ||
"env": { | ||
"node": true, | ||
"es2021": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended" | ||
], | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"rollup.config.js" | ||
], | ||
"parserOptions": { | ||
"sourceType": "module" | ||
} | ||
}, | ||
{ | ||
"files": [ | ||
"test/**/*.js" | ||
], | ||
"env": { | ||
"mocha": true | ||
} | ||
} | ||
] | ||
}, | ||
"dependencies": { | ||
@@ -71,7 +106,8 @@ "chalk": "^4.1.0", | ||
"@rollup/plugin-node-resolve": "^11.2.0", | ||
"c8": "^7.6.0", | ||
"chai": "^4.3.0", | ||
"del": "^6.0.0", | ||
"eslint": "^7.20.0", | ||
"mocha": "^8.3.0", | ||
"mock-stdin": "^1.0.0", | ||
"nyc": "^15.1.0", | ||
"playwright": "^1.8.1", | ||
@@ -78,0 +114,0 @@ "rollup": "^2.39.0" |
@@ -1523,2 +1523,3 @@ 'use strict'; | ||
'height', | ||
'mask-type', | ||
'maskUnits', | ||
@@ -1525,0 +1526,0 @@ 'maskContentUnits' |
@@ -1,2 +0,1 @@ | ||
/* global a2c */ | ||
'use strict'; | ||
@@ -64,3 +63,2 @@ | ||
} else { | ||
/* jshint boss: true */ | ||
if (instruction == 'A' || instruction == 'a') { | ||
@@ -656,3 +654,5 @@ var newData = []; | ||
var iterations = 1e4; // infinite loop protection, 10 000 iterations is more than enough | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
// eslint-disable-next-line no-constant-condition | ||
if (iterations-- == 0) { | ||
@@ -694,7 +694,6 @@ console.error('Error: infinite loop while processing mergePaths plugin.'); | ||
function processSimplex(simplex, direction) { | ||
/* jshint -W004 */ | ||
// we only need to handle to 1-simplex and 2-simplex | ||
if (simplex.length == 2) { // 1-simplex | ||
var a = simplex[1], | ||
let a = simplex[1], | ||
b = simplex[0], | ||
@@ -713,3 +712,3 @@ AO = minus(simplex[1]), | ||
} else { // 2-simplex | ||
var a = simplex[2], // [a, b, c] = simplex | ||
let a = simplex[2], // [a, b, c] = simplex | ||
b = simplex[1], | ||
@@ -853,3 +852,2 @@ c = simplex[0], | ||
function convexHull(points) { | ||
/* jshint -W004 */ | ||
@@ -863,3 +861,3 @@ points.sort(function(a, b) { | ||
bottom = 0; | ||
for (var i = 0; i < points.length; i++) { | ||
for (let i = 0; i < points.length; i++) { | ||
while (lower.length >= 2 && cross(lower[lower.length - 2], lower[lower.length - 1], points[i]) <= 0) { | ||
@@ -878,3 +876,3 @@ lower.pop(); | ||
top = 0; | ||
for (var i = points.length; i--;) { | ||
for (let i = points.length; i--;) { | ||
while (upper.length >= 2 && cross(upper[upper.length - 2], upper[upper.length - 1], points[i]) <= 0) { | ||
@@ -912,3 +910,2 @@ upper.pop(); | ||
// jshint ignore: start | ||
function a2c(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) { | ||
@@ -994,2 +991,1 @@ // for more information of where this Math came from visit: | ||
} | ||
// jshint ignore: end |
@@ -23,3 +23,2 @@ 'use strict'; | ||
transformString.split(regTransformSplit).forEach(function(item) { | ||
/*jshint -W084 */ | ||
var num; | ||
@@ -35,2 +34,3 @@ | ||
// then split it into [10, 50] and collect as context.data | ||
// eslint-disable-next-line no-cond-assign | ||
while (num = regNumericValues.exec(item)) { | ||
@@ -37,0 +37,0 @@ num = Number(num); |
@@ -13,15 +13,36 @@ 'use strict'; | ||
plugins: | ||
- addAttributesToSVGElement: | ||
attribute: "mySvg" | ||
plugins: [ | ||
{ | ||
name: 'addAttributesToSVGElement', | ||
params: { | ||
attribute: "mySvg" | ||
} | ||
} | ||
] | ||
plugins: | ||
- addAttributesToSVGElement: | ||
attributes: ["mySvg", "size-big"] | ||
plugins: [ | ||
{ | ||
name: 'addAttributesToSVGElement', | ||
params: { | ||
attributes: ["mySvg", "size-big"] | ||
} | ||
} | ||
] | ||
plugins: | ||
- addAttributesToSVGElement: | ||
attributes: | ||
- focusable: false | ||
- data-image: icon`; | ||
plugins: [ | ||
{ | ||
name: 'addAttributesToSVGElement', | ||
params: { | ||
attributes: [ | ||
{ | ||
focusable: false | ||
}, | ||
{ | ||
'data-image': icon | ||
} | ||
] | ||
} | ||
} | ||
] | ||
` | ||
@@ -31,16 +52,2 @@ /** | ||
* | ||
* plugins: | ||
* - addAttributesToSVGElement: | ||
* attribute: 'data-icon' | ||
* | ||
* plugins: | ||
* - addAttributesToSVGElement: | ||
* attributes: ['data-icon', 'data-disabled'] | ||
* | ||
* plugins: | ||
* - addAttributesToSVGElement: | ||
* attributes: | ||
* - focusable: false | ||
* - data-image: icon | ||
* | ||
* @author April Arcus | ||
@@ -47,0 +54,0 @@ */ |
@@ -26,3 +26,3 @@ 'use strict'; | ||
var regEnableBackground = /^new\s0\s0\s([\-+]?\d*\.?\d+([eE][\-+]?\d+)?)\s([\-+]?\d*\.?\d+([eE][\-+]?\d+)?)$/, | ||
var regEnableBackground = /^new\s0\s0\s([-+]?\d*\.?\d+([eE][-+]?\d+)?)\s([-+]?\d*\.?\d+([eE][-+]?\d+)?)$/, | ||
hasFilter = false, | ||
@@ -29,0 +29,0 @@ elems = ['svg', 'mask', 'pattern']; |
@@ -16,3 +16,3 @@ 'use strict'; | ||
var regNumericValues = /^([\-+]?\d*\.?\d+([eE][\-+]?\d+)?)(px|pt|pc|mm|cm|m|in|ft|em|ex|%)?$/, | ||
var regNumericValues = /^([-+]?\d*\.?\d+([eE][-+]?\d+)?)(px|pt|pc|mm|cm|m|in|ft|em|ex|%)?$/, | ||
regSeparator = /\s+,?\s*|,\s*/, | ||
@@ -19,0 +19,0 @@ removeLeadingZero = require('../lib/svgo/tools').removeLeadingZero, |
@@ -16,3 +16,3 @@ 'use strict'; | ||
var regNumericValues = /^([\-+]?\d*\.?\d+([eE][\-+]?\d+)?)(px|pt|pc|mm|cm|m|in|ft|em|ex|%)?$/, | ||
var regNumericValues = /^([-+]?\d*\.?\d+([eE][-+]?\d+)?)(px|pt|pc|mm|cm|m|in|ft|em|ex|%)?$/, | ||
removeLeadingZero = require('../lib/svgo/tools').removeLeadingZero, | ||
@@ -19,0 +19,0 @@ absoluteLengths = { // relative to px |
@@ -14,3 +14,2 @@ 'use strict'; | ||
function hasAnimatedAttr(item) { | ||
/* jshint validthis:true */ | ||
return item.isElem(animationElems) && item.hasAttr('attributeName', this) || | ||
@@ -17,0 +16,0 @@ !item.isEmpty() && item.content.some(hasAnimatedAttr, this); |
@@ -21,3 +21,3 @@ 'use strict'; | ||
regRGB = new RegExp('^rgb\\(\\s*' + rNumber + rComma + rNumber + rComma + rNumber + '\\s*\\)$'), | ||
regHEX = /^\#(([a-fA-F0-9])\2){3}$/, | ||
regHEX = /^#(([a-fA-F0-9])\2){3}$/, | ||
none = /\bnone\b/i; | ||
@@ -24,0 +24,0 @@ |
@@ -21,4 +21,4 @@ 'use strict'; | ||
if (item.isElem('ellipse')) { | ||
var rx = item.attr('rx').value || 0; | ||
var ry = item.attr('ry').value || 0; | ||
var rx = item.hasAttr('rx') && item.attr('rx').value || 0; | ||
var ry = item.hasAttr('ry') && item.attr('ry').value || 0; | ||
@@ -25,0 +25,0 @@ if (rx === ry || |
@@ -26,4 +26,4 @@ 'use strict'; | ||
negativeExtraSpace: true, | ||
noSpaceAfterFlags: true, | ||
forceAbsolutePath: false | ||
noSpaceAfterFlags: false, // a20 60 45 0 1 30 20 → a20 60 45 0130 20 | ||
forceAbsolutePath: false, | ||
}; | ||
@@ -30,0 +30,0 @@ |
@@ -1,2 +0,1 @@ | ||
/* jshint quotmark: false */ | ||
'use strict'; | ||
@@ -59,3 +58,2 @@ | ||
exports.fn = function(item, params) { | ||
/* jshint boss: true */ | ||
@@ -75,2 +73,3 @@ if (item.elem && item.hasAttr('style')) { | ||
regDeclarationBlock.lastIndex = 0; | ||
// eslint-disable-next-line no-cond-assign | ||
for (var rule; rule = regDeclarationBlock.exec(styleValue);) { | ||
@@ -77,0 +76,0 @@ if (!params.keepImportant || !rule[3]) { |
@@ -113,3 +113,2 @@ 'use strict'; | ||
function definePrecision(data, params) { | ||
/* jshint validthis: true */ | ||
var matrixData = data.reduce(getMatrixData, []), | ||
@@ -116,0 +115,0 @@ significantDigits = params.transformPrecision; |
@@ -14,3 +14,3 @@ 'use strict'; | ||
negativeExtraSpace: true, | ||
noSpaceAfterFlags: true | ||
noSpaceAfterFlags: false, // a20 60 45 0 1 30 20 → a20 60 45 0130 20 | ||
}; | ||
@@ -17,0 +17,0 @@ |
@@ -111,2 +111,3 @@ 'use strict'; | ||
if ( | ||
// eslint-disable-next-line no-prototype-builtins | ||
b.hasOwnProperty(n) && | ||
@@ -113,0 +114,0 @@ inheritableAttrs.indexOf(n) > -1 && |
@@ -33,3 +33,3 @@ 'use strict'; | ||
var escapeIdentifierName = function(str) { | ||
return str.replace(/[\. ]/g, '_'); | ||
return str.replace(/[. ]/g, '_'); | ||
}; | ||
@@ -155,3 +155,3 @@ | ||
// extract everything after latest slash or backslash | ||
const matched = path.match(/[\/\\]([^\/\\]+)$/); | ||
const matched = path.match(/[/\\]([^/\\]+)$/); | ||
if (matched) { | ||
@@ -158,0 +158,0 @@ return matched[1]; |
@@ -10,4 +10,4 @@ 'use strict'; | ||
exports.params = { | ||
id: [], | ||
class: [] | ||
id: [], | ||
class: [] | ||
}; | ||
@@ -55,28 +55,26 @@ | ||
exports.fn = function(item, params) { | ||
var elemId, elemClass; | ||
// wrap params in an array if not already | ||
['id', 'class'].forEach(function(key) { | ||
if (!Array.isArray(params[key])) { | ||
params[key] = [ params[key] ]; | ||
} | ||
}); | ||
// wrap params in an array if not already | ||
['id', 'class'].forEach(function(key) { | ||
if (!Array.isArray(params[key])) { | ||
params[key] = [ params[key] ]; | ||
} | ||
}); | ||
// abort if current item is no an element | ||
if (!item.isElem()) { | ||
return; | ||
} | ||
// abort if current item is no an element | ||
if (!item.isElem()) { | ||
return; | ||
} | ||
// remove element if it's `id` matches configured `id` params | ||
const elemId = item.attr('id'); | ||
if (elemId && params.id.length !== 0) { | ||
return params.id.includes(elemId.value) === false; | ||
} | ||
// remove element if it's `id` matches configured `id` params | ||
elemId = item.attr('id'); | ||
if (elemId) { | ||
return params.id.indexOf(elemId.value) === -1; | ||
} | ||
// remove element if it's `class` contains any of the configured `class` params | ||
elemClass = item.attr('class'); | ||
if (elemClass) { | ||
var hasClassRegex = new RegExp(params.class.join('|')); | ||
return !hasClassRegex.test(elemClass.value); | ||
} | ||
// remove element if it's `class` contains any of the configured `class` params | ||
const elemClass = item.attr('class'); | ||
if (elemClass && params.class.length !== 0) { | ||
const classList = elemClass.value.split(' '); | ||
return params.class.some(item => classList.includes(item)) === false; | ||
} | ||
}; |
@@ -122,23 +122,25 @@ /** | ||
} | ||
item = convertToUse(item, hasSeen.elem.attr('id').value); | ||
convertToUse(item, hasSeen.elem.attr('id').value); | ||
}); | ||
const defsTag = new JSAPI({ | ||
elem: 'defs', prefix: '', local: 'defs', content: [], attrs: []}, data); | ||
data.content[0].spliceContent(0, 0, defsTag); | ||
for (let def of defs) { | ||
// Remove class and style before copying to avoid circular refs in | ||
// JSON.stringify. This is fine because we don't actually want class or | ||
// style information to be copied. | ||
const style = def.style; | ||
const defClass = def.class; | ||
delete def.style; | ||
delete def.class; | ||
const defClone = def.clone(); | ||
def.style = style; | ||
def.class = defClass; | ||
defClone.removeAttr('transform'); | ||
defsTag.spliceContent(0, 0, defClone); | ||
// Convert the original def to a use so the first usage isn't duplicated. | ||
def = convertToUse(def, defClone.attr('id').value); | ||
def.removeAttr('id'); | ||
if (defs.length > 0) { | ||
const defsTag = new JSAPI({ | ||
elem: 'defs', prefix: '', local: 'defs', content: [], attrs: []}, data); | ||
data.content[0].spliceContent(0, 0, defsTag); | ||
for (let def of defs) { | ||
// Remove class and style before copying to avoid circular refs in | ||
// JSON.stringify. This is fine because we don't actually want class or | ||
// style information to be copied. | ||
const style = def.style; | ||
const defClass = def.class; | ||
delete def.style; | ||
delete def.class; | ||
const defClone = def.clone(); | ||
def.style = style; | ||
def.class = defClass; | ||
defClone.removeAttr('transform'); | ||
defsTag.spliceContent(0, 0, defClone); | ||
// Convert the original def to a use so the first usage isn't duplicated. | ||
def = convertToUse(def, defClone.attr('id').value); | ||
def.removeAttr('id'); | ||
} | ||
} | ||
@@ -145,0 +147,0 @@ return data; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1173505
11
33165