diff --git a/.jshintrc b/.jshintrc index f5a4ba94..2720c412 100644 --- a/.jshintrc +++ b/.jshintrc @@ -10,7 +10,7 @@ "expr": true, "curly": false, "camelcase": true, - "eqeqeq": true, + "eqeqeq": false, "forin": false, "immed": true, "multistr": true, diff --git a/lib/svgo/jsAPI.js b/lib/svgo/jsAPI.js index 4b4c86fa..edc779ee 100644 --- a/lib/svgo/jsAPI.js +++ b/lib/svgo/jsAPI.js @@ -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; }; diff --git a/lib/svgo/svg2js.js b/lib/svgo/svg2js.js index a4c5408f..c6b1d7fc 100644 --- a/lib/svgo/svg2js.js +++ b/lib/svgo/svg2js.js @@ -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); diff --git a/plugins/_path.js b/plugins/_path.js index 7f4a00be..b1aa4f84 100644 --- a/plugins/_path.js +++ b/plugins/_path.js @@ -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; } -}; +} diff --git a/plugins/cleanupListOfValues.js b/plugins/cleanupListOfValues.js index 80866e14..2bd92cb1 100644 --- a/plugins/cleanupListOfValues.js +++ b/plugins/cleanupListOfValues.js @@ -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; } diff --git a/plugins/convertPathData.js b/plugins/convertPathData.js index 3b389760..81d5e5df 100644 --- a/plugins/convertPathData.js +++ b/plugins/convertPathData.js @@ -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; } diff --git a/plugins/convertShapeToPath.js b/plugins/convertShapeToPath.js index 869ad287..e2fbb4f6 100644 --- a/plugins/convertShapeToPath.js +++ b/plugins/convertShapeToPath.js @@ -20,7 +20,7 @@ var empty = { value: 0 }, * * @author Lev Solntsev */ -exports.fn = function(item, params) { +exports.fn = function(item) { if ( item.isElem('rect') && diff --git a/plugins/convertTransform.js b/plugins/convertTransform.js index d070bebe..af84b5cd 100644 --- a/plugins/convertTransform.js +++ b/plugins/convertTransform.js @@ -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; - -} diff --git a/plugins/mergePaths.js b/plugins/mergePaths.js index dd45ee01..154ff72a 100644 --- a/plugins/mergePaths.js +++ b/plugins/mergePaths.js @@ -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){ diff --git a/plugins/removeUnknownsAndDefaults.js b/plugins/removeUnknownsAndDefaults.js index ab389e08..6f4d48d2 100644 --- a/plugins/removeUnknownsAndDefaults.js +++ b/plugins/removeUnknownsAndDefaults.js @@ -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; } ); }