1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-31 07:44:22 +03:00

Code styling

This commit is contained in:
GreLI
2015-02-08 19:22:31 +03:00
parent 6fecd95f22
commit 5e7caa49dc
10 changed files with 24 additions and 46 deletions

View File

@ -10,7 +10,7 @@
"expr": true, "expr": true,
"curly": false, "curly": false,
"camelcase": true, "camelcase": true,
"eqeqeq": true, "eqeqeq": false,
"forin": false, "forin": false,
"immed": true, "immed": true,
"multistr": true, "multistr": true,

View File

@ -2,9 +2,10 @@
var EXTEND = require('whet.extend'); var EXTEND = require('whet.extend');
var JSAPI = module.exports = function(data) { var JSAPI = module.exports = function(data, parentNode) {
EXTEND(this, data); EXTEND(this, data);
if (parentNode) this.parentNode = parentNode;
}; };

View File

@ -21,14 +21,13 @@ var config = {
module.exports = function(data, callback) { module.exports = function(data, callback) {
var sax = SAX.parser(config.strict, config), var sax = SAX.parser(config.strict, config),
root = {}, root = new JSAPI({ elem: '#document' }),
current = root, current = root,
stack = [root]; stack = [root];
function pushToContent(content) { function pushToContent(content) {
content = new JSAPI(content); content = new JSAPI(content, current);
if (current != root) content.parentNode = current;
(current.content = current.content || []).push(content); (current.content = current.content || []).push(content);

View File

@ -201,7 +201,7 @@ exports.applyTransforms = function(elem, path, applyTransformsStroked, floatPrec
var matrix = transformsMultiply(transform2js(elem.attr('transform').value)), var matrix = transformsMultiply(transform2js(elem.attr('transform').value)),
splittedMatrix = matrix.splitted || splitMatrix(matrix.data), splittedMatrix = matrix.splitted || splitMatrix(matrix.data),
stroke = elem.computedAttr('stroke'), stroke = elem.computedAttr('stroke'),
newPoint, sx, sy, strokeWidth; newPoint, sx, sy;
if (stroke && stroke.value != 'none'){ if (stroke && stroke.value != 'none'){
if (!applyTransformsStroked){ 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[0] = pathItem.base[0] + pathItem.data[pathItem.data.length - 2];
pathItem.coords[1] = pathItem.base[1] + pathItem.data[pathItem.data.length - 1] 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; return rad * 180 / Math.PI % 360;
} }
function determinant(matrix) { function determinant(matrix) {
return matrix[0] * matrix[3] - matrix[1] * matrix[2]; return matrix[0] * matrix[3] - matrix[1] * matrix[2];
}; }
/* Splits matrix into primitive transformations /* Splits matrix into primitive transformations
= (object) in format: = (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); out.isSimple = !+out.shear.toFixed(9) && (out.scalex.toFixed(9) == out.scaley.toFixed(9) || !out.rotate);
return out; return out;
}; }
function a2c(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) { 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: // 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); y1 = rotateY(x1, y1, -rad);
x2 = rotateX(x2, y2, -rad); x2 = rotateX(x2, y2, -rad);
y2 = rotateY(x2, y2, -rad); y2 = rotateY(x2, y2, -rad);
var cos = Math.cos(Math.PI / 180 * angle), var x = (x1 - x2) / 2,
sin = Math.sin(Math.PI / 180 * angle),
x = (x1 - x2) / 2,
y = (y1 - y2) / 2; y = (y1 - y2) / 2;
var h = (x * x) / (rx * rx) + (y * y) / (ry * ry); var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
if (h > 1) { if (h > 1) {
@ -714,4 +712,4 @@ function a2c(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursiv
} }
return newres; return newres;
} }
}; }

View File

@ -42,7 +42,7 @@ exports.fn = function(item, params) {
} }
if ( item.hasAttr('enable-background') ) { if ( item.hasAttr('enable-background') ) {
roundValues(item.attrs["enable-background"]); roundValues(item.attrs['enable-background']);
} }
if ( item.hasAttr('viewBox') ) { if ( item.hasAttr('viewBox') ) {
@ -50,7 +50,7 @@ exports.fn = function(item, params) {
} }
if ( item.hasAttr('stroke-dasharray') ) { if ( item.hasAttr('stroke-dasharray') ) {
roundValues(item.attrs["stroke-dasharray"]); roundValues(item.attrs['stroke-dasharray']);
} }
if ( item.hasAttr('dx') ) { if ( item.hasAttr('dx') ) {
@ -77,7 +77,7 @@ exports.fn = function(item, params) {
matchNew, matchNew,
lists = $prop.value, lists = $prop.value,
listsArr = lists.split(regSeparator), listsArr = lists.split(regSeparator),
roundedListArr = new Array(), roundedListArr = [],
roundedList; roundedList;
listsArr.forEach(function(elem){ listsArr.forEach(function(elem){
@ -108,13 +108,13 @@ exports.fn = function(item, params) {
// if attribute value is "new"(only enable-background). // if attribute value is "new"(only enable-background).
else if(matchNew){ else if(matchNew){
roundedListArr.push("new"); roundedListArr.push('new');
} }
}); });
roundedList = roundedListArr.join(" "); roundedList = roundedListArr.join(' ');
$prop.value = roundedList; $prop.value = roundedList;
} }

View File

@ -542,8 +542,7 @@ function filters(path, params) {
*/ */
function convertToMixed(path, params) { function convertToMixed(path, params) {
var currentPoint = [0, 0], var prev = path[0];
prev = path[0];
path = path.filter(function(item, index) { path = path.filter(function(item, index) {
@ -675,7 +674,7 @@ function roundData(data) {
function round(data) { function round(data) {
for (var i = data.length; i--;) { for (var i = data.length; i--;) {
data[i] = +data[i].toFixed(precision) data[i] = +data[i].toFixed(precision);
} }
return data; return data;
} }

View File

@ -20,7 +20,7 @@ var empty = { value: 0 },
* *
* @author Lev Solntsev * @author Lev Solntsev
*/ */
exports.fn = function(item, params) { exports.fn = function(item) {
if ( if (
item.isElem('rect') && item.isElem('rect') &&

View File

@ -232,22 +232,3 @@ function js2transform(transformJS, params) {
return transformString; 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;
}

View File

@ -61,7 +61,7 @@ exports.fn = function(item) {
for(var i = 0, I = contentItemKeys.length; i < I; i++){ for(var i = 0, I = contentItemKeys.length; i < I; i++){
attrName = contentItemKeys[i]; attrName = contentItemKeys[i];
if (attrName != 'd'){ if (attrName != 'd'){
if(typeof prevContentItem.attrs[attrName] === "undefined"){ if(typeof prevContentItem.attrs[attrName] === 'undefined'){
equalData = false; equalData = false;
break; break;
} else if (prevContentItem.attrs[attrName].value !== contentItem.attrs[attrName].value){ } else if (prevContentItem.attrs[attrName].value !== contentItem.attrs[attrName].value){

View File

@ -64,7 +64,7 @@ for (var elem in elems) {
exports.fn = function(item, params) { exports.fn = function(item, params) {
var inheritable = { }, var inheritable = { },
key, attr; key;
// elems w/o namespace prefix // elems w/o namespace prefix
if (item.isElem() && !item.prefix) { if (item.isElem() && !item.prefix) {
@ -147,7 +147,7 @@ exports.fn = function(item, params) {
}); });
if (Object.keys(inheritable).length) { if (Object.keys(inheritable).length) {
item.content.forEach(function(content, i) { item.content.forEach(function(content) {
content.inheritedAttrs = inheritable; content.inheritedAttrs = inheritable;
} ); } );
} }