mirror of
https://github.com/svg/svgo.git
synced 2025-07-31 07:44:22 +03:00
Code styling
This commit is contained in:
@ -10,7 +10,7 @@
|
||||
"expr": true,
|
||||
"curly": false,
|
||||
"camelcase": true,
|
||||
"eqeqeq": true,
|
||||
"eqeqeq": false,
|
||||
"forin": false,
|
||||
"immed": true,
|
||||
"multistr": true,
|
||||
|
@ -2,9 +2,10 @@
|
||||
|
||||
var EXTEND = require('whet.extend');
|
||||
|
||||
var JSAPI = module.exports = function(data) {
|
||||
var JSAPI = module.exports = function(data, parentNode) {
|
||||
|
||||
EXTEND(this, data);
|
||||
if (parentNode) this.parentNode = parentNode;
|
||||
|
||||
};
|
||||
|
||||
|
@ -21,14 +21,13 @@ var config = {
|
||||
module.exports = function(data, callback) {
|
||||
|
||||
var sax = SAX.parser(config.strict, config),
|
||||
root = {},
|
||||
root = new JSAPI({ elem: '#document' }),
|
||||
current = root,
|
||||
stack = [root];
|
||||
|
||||
function pushToContent(content) {
|
||||
|
||||
content = new JSAPI(content);
|
||||
if (current != root) content.parentNode = current;
|
||||
content = new JSAPI(content, current);
|
||||
|
||||
(current.content = current.content || []).push(content);
|
||||
|
||||
|
@ -201,7 +201,7 @@ exports.applyTransforms = function(elem, path, applyTransformsStroked, floatPrec
|
||||
var matrix = transformsMultiply(transform2js(elem.attr('transform').value)),
|
||||
splittedMatrix = matrix.splitted || splitMatrix(matrix.data),
|
||||
stroke = elem.computedAttr('stroke'),
|
||||
newPoint, sx, sy, strokeWidth;
|
||||
newPoint, sx, sy;
|
||||
|
||||
if (stroke && stroke.value != 'none'){
|
||||
if (!applyTransformsStroked){
|
||||
@ -318,8 +318,8 @@ exports.applyTransforms = function(elem, path, applyTransformsStroked, floatPrec
|
||||
}
|
||||
}
|
||||
|
||||
pathItem.coords[0] = pathItem.base[0] + pathItem.data[pathItem.data.length - 2]
|
||||
pathItem.coords[1] = pathItem.base[1] + pathItem.data[pathItem.data.length - 1]
|
||||
pathItem.coords[0] = pathItem.base[0] + pathItem.data[pathItem.data.length - 2];
|
||||
pathItem.coords[1] = pathItem.base[1] + pathItem.data[pathItem.data.length - 1];
|
||||
|
||||
}
|
||||
|
||||
@ -586,9 +586,9 @@ function deg(rad) {
|
||||
return rad * 180 / Math.PI % 360;
|
||||
}
|
||||
|
||||
function determinant(matrix) {
|
||||
function determinant(matrix) {
|
||||
return matrix[0] * matrix[3] - matrix[1] * matrix[2];
|
||||
};
|
||||
}
|
||||
|
||||
/* Splits matrix into primitive transformations
|
||||
= (object) in format:
|
||||
@ -631,7 +631,7 @@ function splitMatrix(matrix) {
|
||||
}
|
||||
out.isSimple = !+out.shear.toFixed(9) && (out.scalex.toFixed(9) == out.scaley.toFixed(9) || !out.rotate);
|
||||
return out;
|
||||
};
|
||||
}
|
||||
|
||||
function a2c(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
|
||||
// for more information of where this Math came from visit:
|
||||
@ -646,9 +646,7 @@ function a2c(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursiv
|
||||
y1 = rotateY(x1, y1, -rad);
|
||||
x2 = rotateX(x2, y2, -rad);
|
||||
y2 = rotateY(x2, y2, -rad);
|
||||
var cos = Math.cos(Math.PI / 180 * angle),
|
||||
sin = Math.sin(Math.PI / 180 * angle),
|
||||
x = (x1 - x2) / 2,
|
||||
var x = (x1 - x2) / 2,
|
||||
y = (y1 - y2) / 2;
|
||||
var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
|
||||
if (h > 1) {
|
||||
@ -714,4 +712,4 @@ function a2c(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursiv
|
||||
}
|
||||
return newres;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ exports.fn = function(item, params) {
|
||||
}
|
||||
|
||||
if ( item.hasAttr('enable-background') ) {
|
||||
roundValues(item.attrs["enable-background"]);
|
||||
roundValues(item.attrs['enable-background']);
|
||||
}
|
||||
|
||||
if ( item.hasAttr('viewBox') ) {
|
||||
@ -50,7 +50,7 @@ exports.fn = function(item, params) {
|
||||
}
|
||||
|
||||
if ( item.hasAttr('stroke-dasharray') ) {
|
||||
roundValues(item.attrs["stroke-dasharray"]);
|
||||
roundValues(item.attrs['stroke-dasharray']);
|
||||
}
|
||||
|
||||
if ( item.hasAttr('dx') ) {
|
||||
@ -77,7 +77,7 @@ exports.fn = function(item, params) {
|
||||
matchNew,
|
||||
lists = $prop.value,
|
||||
listsArr = lists.split(regSeparator),
|
||||
roundedListArr = new Array(),
|
||||
roundedListArr = [],
|
||||
roundedList;
|
||||
|
||||
listsArr.forEach(function(elem){
|
||||
@ -108,13 +108,13 @@ exports.fn = function(item, params) {
|
||||
// if attribute value is "new"(only enable-background).
|
||||
else if(matchNew){
|
||||
|
||||
roundedListArr.push("new");
|
||||
roundedListArr.push('new');
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
roundedList = roundedListArr.join(" ");
|
||||
roundedList = roundedListArr.join(' ');
|
||||
$prop.value = roundedList;
|
||||
|
||||
}
|
||||
|
@ -542,8 +542,7 @@ function filters(path, params) {
|
||||
*/
|
||||
function convertToMixed(path, params) {
|
||||
|
||||
var currentPoint = [0, 0],
|
||||
prev = path[0];
|
||||
var prev = path[0];
|
||||
|
||||
path = path.filter(function(item, index) {
|
||||
|
||||
@ -675,7 +674,7 @@ function roundData(data) {
|
||||
|
||||
function round(data) {
|
||||
for (var i = data.length; i--;) {
|
||||
data[i] = +data[i].toFixed(precision)
|
||||
data[i] = +data[i].toFixed(precision);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ var empty = { value: 0 },
|
||||
*
|
||||
* @author Lev Solntsev
|
||||
*/
|
||||
exports.fn = function(item, params) {
|
||||
exports.fn = function(item) {
|
||||
|
||||
if (
|
||||
item.isElem('rect') &&
|
||||
|
@ -232,22 +232,3 @@ function js2transform(transformJS, params) {
|
||||
return transformString;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert long translate or scale transforms to the shorts ones.
|
||||
*
|
||||
* @param {Array} data transform data
|
||||
*
|
||||
* @return {Array} output data
|
||||
*/
|
||||
function longTranslateScaleToShort(data) {
|
||||
|
||||
// translate(50 50) → translate(50)
|
||||
// scale(2 2) → scale(2)
|
||||
if (data[1] !== undefined && data[1] === data[0]) {
|
||||
data = [data[0]];
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ exports.fn = function(item) {
|
||||
for(var i = 0, I = contentItemKeys.length; i < I; i++){
|
||||
attrName = contentItemKeys[i];
|
||||
if (attrName != 'd'){
|
||||
if(typeof prevContentItem.attrs[attrName] === "undefined"){
|
||||
if(typeof prevContentItem.attrs[attrName] === 'undefined'){
|
||||
equalData = false;
|
||||
break;
|
||||
} else if (prevContentItem.attrs[attrName].value !== contentItem.attrs[attrName].value){
|
||||
|
@ -64,7 +64,7 @@ for (var elem in elems) {
|
||||
exports.fn = function(item, params) {
|
||||
|
||||
var inheritable = { },
|
||||
key, attr;
|
||||
key;
|
||||
|
||||
// elems w/o namespace prefix
|
||||
if (item.isElem() && !item.prefix) {
|
||||
@ -147,7 +147,7 @@ exports.fn = function(item, params) {
|
||||
});
|
||||
|
||||
if (Object.keys(inheritable).length) {
|
||||
item.content.forEach(function(content, i) {
|
||||
item.content.forEach(function(content) {
|
||||
content.inheritedAttrs = inheritable;
|
||||
} );
|
||||
}
|
||||
|
Reference in New Issue
Block a user