{"name":"svg-pathdata","version":"7.2.0","keywords":["svg","path","data","parser","encoder","transformer","reader","writer","stream","typescript"],"author":{"url":"https://insertafter.com/en/index.html","name":"Nicolas Froidure","email":"nicolas.froidure@insertafter.com"},"license":"MIT","_id":"svg-pathdata@7.2.0","maintainers":[{"name":"nfroidure","email":"nicolas.froidure@insertafter.com"},{"name":"pioug","email":"gilles.piou@gmail.com"},{"name":"huerlisi","email":"simon.huerlimann@cyt.ch"},{"name":"narida","email":"adrianleonhard@gmail.com"}],"contributors":[{"name":"Anders Kaseorg","email":"andersk@mit.edu"}],"homepage":"https://github.com/nfroidure/svg-pathdata#readme","bugs":{"url":"https://github.com/nfroidure/SVGPathData/issues"},"dist":{"shasum":"a786973f2cea2580981c56c77a00742b677222f2","tarball":"http://registry-npm.ywwl.com/svg-pathdata/download/svg-pathdata-7.2.0.tgz","fileCount":160,"integrity":"sha512-qd+AxqMpfRrRQaWb2SrNFvn69cvl6piqY8TxhYl2Li1g4/LO5F9NJb5wI4vNwRryqgSgD43gYKLm/w3ag1bKvQ==","signatures":[{"sig":"MEYCIQDlu1PoOeMAyl0QmzN6+FE2EQ87S9ppC796pUEZFtTgSgIhAJAARwhQU+1yKSK3JQHt40ab5++gx62x8quTUt0fvdOl","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":636472,"size":110284,"noattachment":false,"key":"/svg-pathdata/-/svg-pathdata-7.2.0.tgz"},"jest":{"roots":["<rootDir>/src"],"transform":{"^.+\\.(t|j)sx?$":"@swc/jest"},"prettierPath":null,"testEnvironment":"node","moduleNameMapper":{"(.+)\\.js":"$1"},"coverageReporters":["lcov"],"extensionsToTreatAsEsm":[".ts"],"testPathIgnorePatterns":["/node_modules/"]},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","engines":{"node":">=20.11.1"},"gitHead":"4e886f1f8a6db670e95d7eeac8ba23afee7f989b","scripts":{"jest":"jest","lint":"eslint \"src/**/*.ts\"","test":"jest","build":"tsc -p tsconfig.json","cover":"jest --coverage","precz":"npm t && npm run lint && npm run build","format":"npm run prettier","version":"npm run changelog","prettier":"prettier --write \"src/**/*.ts\"","changelog":"conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md","preversion":"npm t && npm run lint && npm run build","type-check":"tsc --pretty --noEmit"},"_npmUser":{"name":"narida","email":"adrianleonhard@gmail.com"},"repository":{"url":"git+https://github.com/nfroidure/svg-pathdata.git","type":"git"},"_npmVersion":"10.7.0","description":"Manipulate SVG path data (path[d] attribute content) simply and efficiently.","directories":{},"_nodeVersion":"22.2.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","eslint":"^9.21.0","prettier":"^3.3.3","@swc/core":"^1.11.9","@swc/jest":"^0.2.37","@eslint/js":"^9.21.0","typescript":"^5.7.0","typescript-eslint":"^8.25.0","eslint-plugin-jest":"^28.11.0","eslint-config-prettier":"^10.0.2","conventional-changelog-cli":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/svg-pathdata_7.2.0_1742063930008_0.9831717205145121","host":"s3://npm-registry-packages-npm-production"},"readme":"[//]: # ( )\n[//]: # (This file is automatically generated by a `metapak`)\n[//]: # (module. Do not change it  except between the)\n[//]: # (`content:start/end` flags, your changes would)\n[//]: # (be overridden.)\n[//]: # ( )\n# svg-pathdata\n> Manipulate SVG path data (path[d] attribute content) simply and efficiently.\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/svg-pathdata/blob/main/LICENSE)\n[![Coverage Status](https://coveralls.io/repos/github/nfroidure/svg-pathdata/badge.svg?branch=main)](https://coveralls.io/github/nfroidure/svg-pathdata?branch=main)\n\n\n[//]: # (::contents:start)\n\n## Usage\n\nInstall the module:\n\n```sh\nnpm install --save svg-pathdata\n```\n\nThen in your JavaScript files:\n\n```js\nimport {\n  SVGPathData,\n  SVGPathDataTransformer,\n  SVGPathDataEncoder,\n  SVGPathDataParser,\n} from 'svg-pathdata';\n```\n\n## Reading PathData\n\n```js\nconst pathData = new SVGPathData(`\n  M 10 10\n  H 60\n  V 60\n  L 10 60\n  Z`);\n\nconsole.log(pathData.commands);\n\n// [  {type: SVGPathData.MOVE_TO,       relative: false,  x: 10,  y: 10},\n//    {type: SVGPathData.HORIZ_LINE_TO, relative: false,  x: 60},\n//    {type: SVGPathData.VERT_LINE_TO,  relative: false,          y: 60},\n//    {type: SVGPathData.LINE_TO,       relative: false,  x: 10,  y: 60},\n//    {type: SVGPathData.CLOSE_PATH}]\n```\n\n## Reading PathData in chunks\n\n```js\nconst parser = new SVGPathDataParser();\n\nparser.parse('   '); // returns []\nparser.parse('M 10'); // returns []\nparser.parse(' 10'); // returns [{type: SVGPathData.MOVE_TO, relative: false, x: 10, y: 10 }]\n\nparser.write('H 60'); // returns [{type: SVGPathData.HORIZ_LINE_TO, relative: false, x: 60 }]\n\nparser.write('V'); // returns []\nparser.write('60'); // returns [{type: SVGPathData.VERT_LINE_TO, relative: false, y: 60 }]\n\nparser.write('L 10 60 \\n  Z');\n// returns [\n//   {type: SVGPathData.LINE_TO, relative: false, x: 10, y: 60 },\n//   {type: SVGPathData.CLOSE_PATH }]\n\nparser.finish(); // tell parser there is no more data: will throw if there are unfinished commands.\n```\n\n## Outputting PathData\n\n```js\nconst pathData = new SVGPathData(`\n  M 10 10\n  H 60\n  V 60\n  L 10 60\n  Z`);\n// returns \"M10 10H60V60L10 60Z\"\n\nencodeSVGPath({ type: SVGPathData.MOVE_TO, relative: false, x: 10, y: 10 });\n// returns \"M10 10\"\n\nencodeSVGPath({ type: SVGPathData.HORIZ_LINE_TO, relative: false, x: 60 });\n// returns \"H60\"\n\nencodeSVGPath([\n  { type: SVGPathData.VERT_LINE_TO, relative: false, y: 60 },\n  { type: SVGPathData.LINE_TO, relative: false, x: 10, y: 60 },\n  { type: SVGPathData.CLOSE_PATH },\n]);\n// returns \"V60L10 60Z\"\n```\n\n## Transforming PathData\n\nThis library can perform transformations on SVG paths. Here is\n[an example of that kind of use](https://github.com/nfroidure/svgicons2svgfont/blob/aa6df0211419e9d61c417c63bcc353f0cb2ea0c8/src/index.js#L192).\n\n### Transforming entire paths\n\n```js\nnew SVGPathData(`\n   m 10,10\n   h 60\n   v 60\n   l 10,60\n   z`)\n  .toAbs()\n  .encode();\n// return s\"M10,10 H70 V70 L80,130 Z\"\n```\n\n### Transforming partial data\n\nHere, we take SVGPathData from stdin and output it transformed to stdout.\n\n```js\nconst transformingParser = new SVGPathDataParser().toAbs().scale(2, 2);\ntransformingParser.parse('m 0 0'); // returns [{ type: SVGPathData.MOVE_TO,       relative: false, x: 0, y: 0 }]\ntransformingParser.parse('l 2 3'); // returns [{ type: SVGPathData.LINE_TO,       relative: false, x: 4, y: 6 }]\n```\n\n## Supported transformations\n\nYou can find all supported transformations in\n[src/SVGPathDataTransformer.ts](https://github.com/nfroidure/SVGPathData/blob/master/src/SVGPathDataTransformer.ts#L47).\nAdditionally, you can create your own by writing a function with the following\nsignature:\n\n```js\ntype TransformFunction = (command: SVGCommand) => SVGCommand | SVGCommand[];\n\nfunction SET_X_TO(xValue = 10) {\n  return function(command) {\n    command.x = xValue; // transform command objects and return them\n    return command;\n  };\n};\n\n// Synchronous usage\nnew SVGPathData('...')\n  .transform(SET_X_TO(25))\n  .encode();\n\n// Chunk usage\nnew SVGPathDataParser().transform(SET_X_TO(25));\n```\n\n## Contributing\n\nClone this project, run:\n\n```sh\nnpm install; npm test\n```\n\n[//]: # (::contents:end)\n\n# API\n## Functions\n\n<dl>\n<dt><a href=\"#annotateArcCommand\">annotateArcCommand()</a></dt>\n<dd><p><a href=\"https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes\">https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes</a>\nFixes rX and rY.\nEnsures lArcFlag and sweepFlag are 0 or 1\nAdds center coordinates: command.cX, command.cY (relative or absolute, depending on command.relative)\nAdds start and end arc parameters (in degrees): command.phi1, command.phi2; phi1 &lt; phi2 iff. c.sweepFlag == true</p>\n</dd>\n<dt><a href=\"#intersectionUnitCircleLine\">intersectionUnitCircleLine()</a></dt>\n<dd><p>Solves a quadratic system of equations of the form\n     a * x + b * y = c\n     x² + y² = 1\nThis can be understood as the intersection of the unit circle with a line.\n     =&gt; y = (c - a x) / b\n     =&gt; x² + (c - a x)² / b² = 1\n     =&gt; x² b² + c² - 2 c a x + a² x² = b²\n     =&gt; (a² + b²) x² - 2 a c x + (c² - b²) = 0</p>\n</dd>\n<dt><a href=\"#arePointsCollinear\">arePointsCollinear(p1, p2, p3)</a> ⇒</dt>\n<dd><p>Determines if three points are collinear (lie on the same straight line)\nand the middle point is on the line segment between the first and third points</p>\n</dd>\n<dt><a href=\"#createEllipse\">createEllipse()</a></dt>\n<dd><p>Creates an ellipse path centered at (cx,cy) with radii rx and ry</p>\n</dd>\n<dt><a href=\"#createRect\">createRect()</a></dt>\n<dd><p>Creates a rectangle path with optional rounded corners</p>\n</dd>\n<dt><a href=\"#createPolyline\">createPolyline()</a></dt>\n<dd><p>Creates a polyline from an array of coordinates [x1,y1,x2,y2,...]</p>\n</dd>\n<dt><a href=\"#createPolygon\">createPolygon()</a></dt>\n<dd><p>Creates a closed polygon from an array of coordinates</p>\n</dd>\n<dt><a href=\"#REMOVE_COLLINEAR\">REMOVE_COLLINEAR(commands)</a> ⇒</dt>\n<dd><p>Process a path and remove collinear points</p>\n</dd>\n<dt><a href=\"#REVERSE_PATH\">REVERSE_PATH(commands, preserveSubpathOrder)</a> ⇒</dt>\n<dd><p>Reverses the order of path commands to go from end to start\nIMPORTANT: This function expects absolute commands as input.\nIt doesn&#39;t convert relative to absolute - use SVGPathDataTransformer.TO_ABS() first if needed.</p>\n</dd>\n</dl>\n\n<a name=\"annotateArcCommand\"></a>\n\n## annotateArcCommand()\nhttps://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes\nFixes rX and rY.\nEnsures lArcFlag and sweepFlag are 0 or 1\nAdds center coordinates: command.cX, command.cY (relative or absolute, depending on command.relative)\nAdds start and end arc parameters (in degrees): command.phi1, command.phi2; phi1 < phi2 iff. c.sweepFlag == true\n\n**Kind**: global function  \n<a name=\"intersectionUnitCircleLine\"></a>\n\n## intersectionUnitCircleLine()\nSolves a quadratic system of equations of the form\n     a * x + b * y = c\n     x² + y² = 1\nThis can be understood as the intersection of the unit circle with a line.\n     => y = (c - a x) / b\n     => x² + (c - a x)² / b² = 1\n     => x² b² + c² - 2 c a x + a² x² = b²\n     => (a² + b²) x² - 2 a c x + (c² - b²) = 0\n\n**Kind**: global function  \n<a name=\"arePointsCollinear\"></a>\n\n## arePointsCollinear(p1, p2, p3) ⇒\nDetermines if three points are collinear (lie on the same straight line)\nand the middle point is on the line segment between the first and third points\n\n**Kind**: global function  \n**Returns**: true if the points are collinear and p2 is on the segment p1-p3  \n\n| Param | Description |\n| --- | --- |\n| p1 | First point [x, y] |\n| p2 | Middle point that might be removed |\n| p3 | Last point [x, y] |\n\n<a name=\"createEllipse\"></a>\n\n## createEllipse()\nCreates an ellipse path centered at (cx,cy) with radii rx and ry\n\n**Kind**: global function  \n<a name=\"createRect\"></a>\n\n## createRect()\nCreates a rectangle path with optional rounded corners\n\n**Kind**: global function  \n<a name=\"createPolyline\"></a>\n\n## createPolyline()\nCreates a polyline from an array of coordinates [x1,y1,x2,y2,...]\n\n**Kind**: global function  \n<a name=\"createPolygon\"></a>\n\n## createPolygon()\nCreates a closed polygon from an array of coordinates\n\n**Kind**: global function  \n<a name=\"REMOVE_COLLINEAR\"></a>\n\n## REMOVE\\_COLLINEAR(commands) ⇒\nProcess a path and remove collinear points\n\n**Kind**: global function  \n**Returns**: New array with collinear points removed  \n\n| Param | Description |\n| --- | --- |\n| commands | Array of SVG path commands to process (must be absolute) |\n\n<a name=\"REVERSE_PATH\"></a>\n\n## REVERSE\\_PATH(commands, preserveSubpathOrder) ⇒\nReverses the order of path commands to go from end to start\nIMPORTANT: This function expects absolute commands as input.\nIt doesn't convert relative to absolute - use SVGPathDataTransformer.TO_ABS() first if needed.\n\n**Kind**: global function  \n**Returns**: New SVG commands in reverse order with absolute coordinates  \n\n| Param | Description |\n| --- | --- |\n| commands | SVG path commands in absolute form to reverse |\n| preserveSubpathOrder | If true, keeps subpaths in their original order |\n\n\n# Authors\n- [Nicolas Froidure](https://insertafter.com/en/index.html)\n- [Anders Kaseorg](mailto:andersk@mit.edu)\n\n# License\n[MIT](https://github.com/nfroidure/svg-pathdata/blob/main/LICENSE)\n","publish_time":1742063930258,"_cnpm_publish_time":1742063930258,"dist-tags":{"latest":"9.0.0"}}