Socket
Socket
Sign inDemoInstall

svg-pathdata

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-pathdata - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

test/rotate.js

8

Gruntfile.js
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-parallel');
require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks);

@@ -63,2 +59,4 @@ grunt.initConfig({

'dist',
'karma:local',
'watch',
'parallel:testing'

@@ -65,0 +63,0 @@ ]);

{
"name": "svg-pathdata",
"version": "0.0.1",
"version": "0.0.2",
"description": "SVG Path Datas parsing",
"main": "dist/SVGPathData.js",
"main": "src/SVGPathData.js",
"scripts": {

@@ -14,5 +14,11 @@ "test": "grunt test"

"keywords": [
"SVG",
"PathData",
"parser"
"svg",
"path",
"data",
"parser",
"encoder",
"transformer",
"reader",
"writer",
"stream"
],

@@ -24,5 +30,5 @@ "author": "Nicolas Froidure",

},
"engines": {
"node": "0.10.*"
},
"engines": {
"node": "0.10.*"
},
"devDependencies": {

@@ -38,3 +44,2 @@ "grunt": "0.4.x",

"sinon": "1.7.x",
"karma-script-launcher": "0.1.x",
"karma-chrome-launcher": "0.1.x",

@@ -45,4 +50,5 @@ "karma-firefox-launcher": "0.1.x",

"karma": "0.10.x",
"grunt-karma": "0.6.x"
"grunt-karma": "0.6.x",
"matchdep": "~0.3.0"
}
}
# SVGPathData [![Build Status](https://travis-ci.org/nfroidure/SVGPathData.png?branch=master)](https://travis-ci.org/nfroidure/SVGPathData)
Manipulating SVG PathDatas (path[d] attribute content) simply and efficiently.
Manipulating SVG path datas (path[d] attribute content) simply and efficiently.
## Including the library
This library is fully node based (based on current stream implementation) but
you can also use it in modern browser with the browserified build or in your
own build using Browserify.
you can also use it in modern browser with the
[browserified build](https://github.com/nfroidure/SVGPathData/blob/master/dist/SVGPathData.js)
or in your own build using Browserify.

@@ -10,0 +11,0 @@ ## Reading PathDatas

@@ -21,2 +21,44 @@ function SVGPathData(content) {

SVGPathData.prototype.translate = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.TRANSLATE, arguments);
return this;
};
SVGPathData.prototype.scale = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.SCALE, arguments);
return this;
};
SVGPathData.prototype.rotate = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.ROTATE, arguments);
return this;
};
SVGPathData.prototype.matrix = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.MATRIX, arguments);
return this;
};
SVGPathData.prototype.skewX = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.SKEW_X, arguments);
return this;
};
SVGPathData.prototype.skewY = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.SKEW_Y, arguments);
return this;
};
SVGPathData.prototype.xSymetry = function() {
this.commands = SVGPathData.transform(this.commands,
SVGPathData.Transformer.X_AXIS_SIMETRY, arguments);
return this;
};
SVGPathData.prototype.ySymetry = function() {

@@ -23,0 +65,0 @@ this.commands = SVGPathData.transform(this.commands,

@@ -111,28 +111,45 @@ // Transform SVG PathData

// Symetry througth the Y axis
SVGPathDataTransformer.Y_AXIS_SIMETRY = function(yDecal) {
var notFirst = false;
// SVG Transforms : http://www.w3.org/TR/SVGTiny12/coords.html#TransformList
// Matrix : http://apike.ca/prog_svg_transform.html
SVGPathDataTransformer.MATRIX = function(a, b, c, d, e, f) {
var prevX = 0, prevY = 0;
if('number' !== typeof a, 'number' !== typeof b,
'number' !== typeof c, 'number' !== typeof d,
'number' !== typeof e, 'number' !== typeof f) {
throw Error('A matrix transformation requires parameters [a,b,c,d,e,f]'
+' to be set and to be numbers.');
}
return function(command) {
if('undefined' !== command.y) {
if(notFirst && command.relative) {
command.y = -command.y;
} else {
command.y = yDecal - command.y;
}
if('undefined' !== typeof command.x) {
command.x = command.x * a +
('undefined' !== typeof command.y ?
command.y : (command.relative ? 0 : prevY)
) * c
+ e;
}
if('undefined' !== command.y1) {
if(notFirst && command.relative) {
command.y1 = -command.y1;
} else {
command.y1 = yDecal - command.y1;
}
if('undefined' !== typeof command.y) {
command.y = ('undefined' !== typeof command.x ?
command.x : (command.relative ? 0 : prevX)
) * b
+ command.y * d
+ f;
}
if('undefined' !== command.y2) {
if(notFirst && command.relative) {
command.y2 = -command.y2;
} else {
command.y2 = yDecal - command.y2;
}
if('undefined' !== typeof command.x1) {
command.x1 = command.x1 * a + command.y1 * c + e;
}
notFirst = true;
if('undefined' !== typeof command.y1) {
command.y1 = command.x1 * b + command.y1 * d + f;
}
if('undefined' !== typeof command.x2) {
command.x2 = command.x2 * a + command.y2 * c + e;
}
if('undefined' !== typeof command.y2) {
command.y2 = command.x2 * b + command.y2 * d + f;
}
prevX = ('undefined' !== typeof command.x ?
(command.relative ? prevX + command.x : command.x) :
prevX);
prevY = ('undefined' !== typeof command.y ?
(command.relative ? prevY + command.y : command.y) :
prevY);
return command;

@@ -142,3 +159,74 @@ };

// Rotation
SVGPathDataTransformer.ROTATE = function(a, x, y) {
return (function(toOrigin, fromOrigin, rotate) {
return function(command) {
return fromOrigin(rotate(toOrigin(command)));
};
})(SVGPathDataTransformer.TRANSLATE(x || 0, y || 0)
, SVGPathDataTransformer.TRANSLATE(-(x || 0), -(y || 0))
, SVGPathDataTransformer.MATRIX(Math.cos(a), Math.sin(a),
-Math.sin(a), Math.cos(a), 0, 0)
);
};
// Translation
SVGPathDataTransformer.TRANSLATE = function(dX, dY) {
if('number' !== typeof dX) {
throw Error('A translate transformation requires the parameter dX'
+' to be set and to be a number.');
}
return SVGPathDataTransformer.MATRIX(1, 0, 0, 1, dX, dY || 0);
};
// Scaling
SVGPathDataTransformer.SCALE = function(dX, dY) {
if('number' !== typeof dX) {
throw Error('A scale transformation requires the parameter dX'
+' to be set and to be a number.');
}
return SVGPathDataTransformer.MATRIX(dX, 0, 0, dY || dX, 0, 0);
};
// Skew
SVGPathDataTransformer.SKEW_X = function(a) {
if('number' !== typeof a) {
throw Error('A skewX transformation requires the parameter a'
+' to be set and to be a number.');
}
return SVGPathDataTransformer.MATRIX(1, 0, Math.atan(a), 1, 0, 0);
}
SVGPathDataTransformer.SKEW_Y = function(a) {
if('number' !== typeof a) {
throw Error('A skewY transformation requires the parameter a'
+' to be set and to be a number.');
}
return SVGPathDataTransformer.MATRIX(1, Math.atan(a), 0, 1, 0, 0);
}
// Symetry througth the X axis
SVGPathDataTransformer.X_AXIS_SIMETRY = function(xDecal) {
return (function(toAbs, scale, translate) {
return function(command) {
return translate(scale(toAbs(command)));
};
})(SVGPathDataTransformer.TO_ABS(),
SVGPathDataTransformer.SCALE(-1, 1),
SVGPathDataTransformer.TRANSLATE(xDecal || 0, 0)
);
};
// Symetry througth the Y axis
SVGPathDataTransformer.Y_AXIS_SIMETRY = function(yDecal) {
return (function(toAbs, scale, translate) {
return function(command) {
return translate(scale(toAbs(command)));
};
})(SVGPathDataTransformer.TO_ABS(),
SVGPathDataTransformer.SCALE(1, -1),
SVGPathDataTransformer.TRANSLATE(0, yDecal || 0)
);
};
module.exports = SVGPathDataTransformer;

@@ -8,5 +8,4 @@ var assert = chai.assert;

, 'M250 381C199.119048 381 151.285714 361.164188 115.333333 325.159688L165.857143 274.653375C188.333333 297.156188 218.238095 309.5625 250 309.5625C298.214286 309.5625 341.333333 280.797 359.904762 236.291438L369.071429 214.3125L500 214.3125L500 285.75L415 285.75C381.285714 344.304937 318.880952 381 250 381L250 381L250 381L250 381zM130.952381 166.6875L0 166.6875L0 95.25L85.047619 95.25C118.738095 36.695062500000006 181.142857 0 250 0C300.880952 0 348.714286 19.835812499999975 384.690476 55.84031249999998L334.166667 106.34662500000002C311.690476 83.84381250000001 281.809524 71.4375 250 71.4375C201.833333 71.4375 158.666667 100.20299999999997 140.119048 144.708563L130.952381 166.6875L130.952381 166.6875L130.952381 166.6875L130.952381 166.6875zM130.952381 166.6875');
console.log(new SVGPathData('M250,381 C199.119048,381 151.285714,361.164188 115.333333,325.159688 L165.857143,274.653375 C188.333333,297.156188 218.238095,309.5625 250,309.5625 C298.214286,309.5625 341.333333,280.797 359.904762,236.291438 L369.071429,214.3125 L500,214.3125 L500,285.75 L415,285.75 C381.285714,344.304937 318.880952,381 250,381 L250,381 L250,381 L250,381 Z M130.952381,166.6875 L0,166.6875 L0,95.25 L85.047619,95.25 C118.738095,36.6950625 181.142857,0 250,0 C300.880952,0 348.714286,19.8358125 384.690476,55.8403125 L334.166667,106.346625 C311.690476,83.8438125 281.809524,71.4375 250,71.4375 C201.833333,71.4375 158.666667,100.203 140.119048,144.708563 L130.952381,166.6875 L130.952381,166.6875 L130.952381,166.6875 L130.952381,166.6875 Z M130.952381,166.6875').ySymetry(381).encode());
});
});

@@ -8,4 +8,22 @@ var assert = chai.assert;

'm12.5 140c0 0 7.63017 -32.95472 17.21798 -45.085701c0 0 8.60793 -7.043235 12.91188 -7.630171c4.30396 -0.586937 31.109058 -1.173872 31.109058 -1.173872l8.021699 -9.821022h3.717026l1.173872 -15.810194l-3.521618 -3.717024l-1.564688 -9.782503l0.586937 -4.50008h1.760808c0 0 1.138927 -12.71791 0.977752 -14.0879c-0.160463 -1.36928 4.911579 -16.18532 17.628774 -18.17648c12.71719 -1.99188 35.0336 10.50851 35.0336 10.50851l-1.20525 21.55903l-2.34775 6.65242l1.36928 0.39153c0 0 -0.1954 3.71702 -1.76081 6.260173c0 0 -2.15233 10.760974 -7.63017 10.956382l-4.30467 12.521783l-3.71703 4.109267l-2.93468 8.607922l14.67341 17.80493l1.17387 10.36944c0 0 8.52734 7.60521 6.31794 20.04214h-124.68722z'
).xSymetry(150).encode(),
'M137.5 140C137.5 140 129.86983 107.04527999999999 120.28202 94.914299C120.28202 94.914299 111.67409 87.871064 107.37013999999999 87.284128C103.06618 86.69719099999999 76.261082 86.11025599999999 76.261082 86.11025599999999L68.239383 76.289234H64.522357L63.348485 60.47904L66.870103 56.762015999999996L68.434791 46.979513L67.847854 42.479433H66.087046C66.087046 42.479433 64.948119 29.761523 65.109294 28.391533000000003C65.269757 27.022253000000003 60.197715 12.206213000000002 47.48052000000001 10.215053000000001C34.76333000000001 8.223173000000001 12.446920000000006 20.723563 12.446920000000006 20.723563L13.652170000000012 42.282593L15.999920000000003 48.935013L14.63064 49.326543C14.63064 49.326543 14.826040000000006 53.043563 16.391449999999992 55.586716C16.391449999999992 55.586716 18.543779999999998 66.34769 24.021619999999984 66.543098L28.326289999999986 79.064881L32.04331999999998 83.174148L34.97799999999998 91.78207L20.30458999999999 109.587L19.130719999999997 119.95644C19.130719999999997 119.95644 10.603379999999987 127.56165 12.812780000000004 139.99858H137.5z');
});
it("should work when reversed", function() {
assert.equal(new SVGPathData(
'm12.5 140c0 0 7.63017 -32.95472 17.21798 -45.085701c0 0 8.60793 -7.043235 12.91188 -7.630171c4.30396 -0.586937 31.109058 -1.173872 31.109058 -1.173872l8.021699 -9.821022h3.717026l1.173872 -15.810194l-3.521618 -3.717024l-1.564688 -9.782503l0.586937 -4.50008h1.760808c0 0 1.138927 -12.71791 0.977752 -14.0879c-0.160463 -1.36928 4.911579 -16.18532 17.628774 -18.17648c12.71719 -1.99188 35.0336 10.50851 35.0336 10.50851l-1.20525 21.55903l-2.34775 6.65242l1.36928 0.39153c0 0 -0.1954 3.71702 -1.76081 6.260173c0 0 -2.15233 10.760974 -7.63017 10.956382l-4.30467 12.521783l-3.71703 4.109267l-2.93468 8.607922l14.67341 17.80493l1.17387 10.36944c0 0 8.52734 7.60521 6.31794 20.04214h-124.68722z'
).xSymetry(150).xSymetry(150).encode(),
'M12.5 140C12.5 140 20.130169999999993 107.04527999999999 29.717979999999997 94.914299C29.717979999999997 94.914299 38.32590999999999 87.871064 42.62986000000001 87.284128C46.93382 86.69719099999999 73.738918 86.11025599999999 73.738918 86.11025599999999L81.760617 76.289234H85.477643L86.651515 60.47904L83.129897 56.762015999999996L81.565209 46.979513L82.152146 42.479433H83.912954C83.912954 42.479433 85.051881 29.761523 84.890706 28.391533000000003C84.730243 27.022253000000003 89.802285 12.206213000000002 102.51947999999999 10.215053000000001C115.23666999999999 8.223173000000001 137.55308 20.723563 137.55308 20.723563L136.34783 42.282593L134.00008 48.935013L135.36936 49.326543C135.36936 49.326543 135.17396 53.043563 133.60855 55.586716C133.60855 55.586716 131.45622 66.34769 125.97838000000002 66.543098L121.67371000000001 79.064881L117.95668000000002 83.174148L115.02200000000002 91.78207L129.69541 109.587L130.86928 119.95644C130.86928 119.95644 139.39662 127.56165 137.18722 139.99858H12.5z');
});
});
describe("Y axis symetry", function() {
it("should work with an arbitrary path", function() {
assert.equal(new SVGPathData(
'm12.5 140c0 0 7.63017 -32.95472 17.21798 -45.085701c0 0 8.60793 -7.043235 12.91188 -7.630171c4.30396 -0.586937 31.109058 -1.173872 31.109058 -1.173872l8.021699 -9.821022h3.717026l1.173872 -15.810194l-3.521618 -3.717024l-1.564688 -9.782503l0.586937 -4.50008h1.760808c0 0 1.138927 -12.71791 0.977752 -14.0879c-0.160463 -1.36928 4.911579 -16.18532 17.628774 -18.17648c12.71719 -1.99188 35.0336 10.50851 35.0336 10.50851l-1.20525 21.55903l-2.34775 6.65242l1.36928 0.39153c0 0 -0.1954 3.71702 -1.76081 6.260173c0 0 -2.15233 10.760974 -7.63017 10.956382l-4.30467 12.521783l-3.71703 4.109267l-2.93468 8.607922l14.67341 17.80493l1.17387 10.36944c0 0 8.52734 7.60521 6.31794 20.04214h-124.68722z'
).ySymetry(150).encode(),
'm12.5 10c0 0 7.63017 32.95472 17.21798 45.085701c0 0 8.60793 7.043235 12.91188 7.630171c4.30396 0.586937 31.109058 1.173872 31.109058 1.173872l8.021699 9.821022h3.717026l1.173872 15.810194l-3.521618 3.717024l-1.564688 9.782503l0.586937 4.50008h1.760808c0 0 1.138927 12.71791 0.977752 14.0879c-0.160463 1.36928 4.911579 16.18532 17.628774 18.17648c12.71719 1.99188 35.0336 -10.50851 35.0336 -10.50851l-1.20525 -21.55903l-2.34775 -6.65242l1.36928 -0.39153c0 0 -0.1954 -3.71702 -1.76081 -6.260173c0 0 -2.15233 -10.760974 -7.63017 -10.956382l-4.30467 -12.521783l-3.71703 -4.109267l-2.93468 -8.607922l14.67341 -17.80493l1.17387 -10.36944c0 0 8.52734 -7.60521 6.31794 -20.04214h-124.68722z');
'M12.5 10C12.5 10 20.13017 42.95472000000001 29.71798 55.085701C29.71798 55.085701 38.32591 62.128935999999996 42.62986 62.715872000000005C46.93382 63.30280900000001 73.738918 63.88974400000001 73.738918 63.88974400000001L81.760617 73.710766H85.477643L86.651515 89.52096L83.129897 93.23798400000001L81.565209 103.020487L82.152146 107.520567H83.912954C83.912954 107.520567 85.051881 120.238477 84.890706 121.60846699999999C84.730243 122.977747 89.802285 137.793787 102.51947999999999 139.784947C115.23666999999999 141.776827 137.55308 129.276437 137.55308 129.276437L136.34783 107.71740700000001L134.00008 101.064987L135.36936 100.673457C135.36936 100.673457 135.17396 96.956437 133.60855 94.413284C133.60855 94.413284 131.45622 83.65231 125.97838000000002 83.456902L121.67371000000001 70.935119L117.95668000000002 66.825852L115.02200000000002 58.217929999999996L129.69541 40.413L130.86928 30.04356C130.86928 30.04356 139.39662 22.43835 137.18722 10.001419999999996H12.5z');
});

@@ -17,5 +35,6 @@

).ySymetry(150).ySymetry(150).encode(),
'm12.5 140c0 0 7.63017 -32.95472 17.21798 -45.085701c0 0 8.60793 -7.043235 12.91188 -7.630171c4.30396 -0.586937 31.109058 -1.173872 31.109058 -1.173872l8.021699 -9.821022h3.717026l1.173872 -15.810194l-3.521618 -3.717024l-1.564688 -9.782503l0.586937 -4.50008h1.760808c0 0 1.138927 -12.71791 0.977752 -14.0879c-0.160463 -1.36928 4.911579 -16.18532 17.628774 -18.17648c12.71719 -1.99188 35.0336 10.50851 35.0336 10.50851l-1.20525 21.55903l-2.34775 6.65242l1.36928 0.39153c0 0 -0.1954 3.71702 -1.76081 6.260173c0 0 -2.15233 10.760974 -7.63017 10.956382l-4.30467 12.521783l-3.71703 4.109267l-2.93468 8.607922l14.67341 17.80493l1.17387 10.36944c0 0 8.52734 7.60521 6.31794 20.04214h-124.68722z');
'M12.5 140C12.5 140 20.13017 107.04527999999999 29.71798 94.914299C29.71798 94.914299 38.32591 87.871064 42.62986 87.284128C46.93382 86.69719099999999 73.738918 86.11025599999999 73.738918 86.11025599999999L81.760617 76.289234H85.477643L86.651515 60.47904L83.129897 56.76201599999999L81.565209 46.979513L82.152146 42.479433H83.912954C83.912954 42.479433 85.051881 29.761522999999997 84.890706 28.39153300000001C84.730243 27.022253000000006 89.802285 12.206212999999991 102.51947999999999 10.215053000000012C115.23666999999999 8.223173000000003 137.55308 20.723563000000013 137.55308 20.723563000000013L136.34783 42.28259299999999L134.00008 48.935013L135.36936 49.326543C135.36936 49.326543 135.17396 53.043563000000006 133.60855 55.586715999999996C133.60855 55.586715999999996 131.45622 66.34769 125.97838000000002 66.543098L121.67371000000001 79.064881L117.95668000000002 83.174148L115.02200000000002 91.78207L129.69541 109.587L130.86928 119.95644C130.86928 119.95644 139.39662 127.56165 137.18722 139.99858H12.5z');
});
});

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc