{"name":"svg-pathdata","version":"7.0.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.0.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":"a64dc510e7bd5a6a9450063083f11e7308d2a3bc","tarball":"http://registry-npm.ywwl.com/svg-pathdata/download/svg-pathdata-7.0.0.tgz","fileCount":156,"integrity":"sha512-R0T/Xij8AvDHy//mLlXyv1phLoFurCHWjHXikkzhXMz6kN3hup78tAFpFDCr0Zr+uIs7vmKQN+SvRjM03mMoHg==","signatures":[{"sig":"MEUCIGK8zdou3Eq+ypN5Ox2b7vfwS/1FMIQV2dWFR5610lerAiEA/k8Zot9S0pYVdGviXvdHHSXlOifQbq5DWHtur75wL08=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":565736,"size":94264,"noattachment":false,"key":"/svg-pathdata/-/svg-pathdata-7.0.0.tgz"},"jest":{"roots":["<rootDir>/src"],"transform":{"^.+\\.tsx?$":["@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","config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"engines":{"node":">=20.11.1"},"gitHead":"73bedd6cf8300619cbee97d4ffa522c7e605ca4d","metapak":{"data":{"files":"'src/**/*.ts'","ignore":["dist"],"distFiles":"'dist/**/*.js'","testsFiles":"'src/**/*.test.ts'","bundleFiles":["dist","src"]},"configs":["main","readme","tsesm","jest","eslint","codeclimate","ghactions"]},"scripts":{"cz":"env NODE_ENV=${NODE_ENV:-cli} git cz","cli":"env NODE_ENV=${NODE_ENV:-cli}","jest":"NODE_OPTIONS=--experimental-vm-modules NODE_ENV=test jest","lint":"eslint 'src/**/*.ts'","test":"npm run jest","build":"rimraf 'dist' && tsc --outDir dist","cover":"npm run jest -- --coverage","precz":"npm t && npm run lint && npm run metapak -- -s && npm run build","format":"npm run prettier","metapak":"metapak","rebuild":"swc ./src -s -d dist -C jsc.target=es2022","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 metapak -- -s && npm run build","type-check":"tsc --pretty --noEmit"},"_npmUser":{"name":"nfroidure","email":"nicolas.froidure@insertafter.com"},"prettier":{"semi":true,"proseWrap":"always","printWidth":80,"singleQuote":true,"trailingComma":"all"},"overrides":{"eslint":"^9.7.0"},"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":{},"greenkeeper":{"ignore":["commitizen","cz-conventional-changelog","conventional-changelog-cli","typescript","rimraf","@swc/cli","@swc/core","@swc/helpers","jest","@swc/jest","eslint","prettier","eslint-config-prettier","eslint-plugin-prettier","typescript-eslint"]},"_nodeVersion":"20.14.0","dependencies":{"yerror":"^8.0.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","eslint":"^9.7.0","rimraf":"^6.0.1","metapak":"^6.0.1","@swc/cli":"^0.4.0","prettier":"^3.3.3","@swc/core":"^1.6.13","@swc/jest":"^0.2.36","@eslint/js":"^9.7.0","commitizen":"^4.3.0","typescript":"^5.5.3","@swc/helpers":"^0.5.12","metapak-nfroidure":"18.2.0","typescript-eslint":"^7.16.0","eslint-plugin-jest":"^28.6.0","eslint-config-prettier":"^9.1.0","eslint-plugin-prettier":"^5.1.3","cz-conventional-changelog":"^3.3.0","conventional-changelog-cli":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/svg-pathdata_7.0.0_1722282107871_0.7392580549918892","host":"s3://npm-registry-packages"},"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":1722282108048,"_cnpm_publish_time":1722282108048,"dist-tags":{"latest":"9.0.0"}}