{"name":"svg-path-properties","version":"2.1.0","description":"Calculate the length for an SVG path, to use it with node or a Canvas element","types":"dist/main.d.ts","type":"module","exports":{".":{"import":{"types":"./dist/main.d.ts","default":"./dist/main.mjs"},"require":{"types":"./dist/main.d.cts","default":"./dist/main.cjs"},"default":"./dist/main.mjs"},"./dist/*":{"types":"./dist/*.d.ts","import":"./dist/*.mjs","require":"./dist/*.cjs"}},"engines":{"node":">=22.0.0"},"packageManager":"npm@8.4.0","scripts":{"build":"tsc && tsup --minify terser","lint":"eslint . && npm run lint:lockfile","lint:fix":"eslint . --fix","lint:lockfile":"lockfile-lint --path package-lock.json --validate-https --allowed-hosts npm yarn","test":"c8 node --import tsx --test test/*.test.ts","test:watch":"c8 node --import tsx --test --watch test/**/*.test.ts","coverage:view":"open coverage/lcov-report/index.html","version":"changeset version","release":"changeset publish"},"author":{"name":"Roger Veciana i Rovira","url":"https://geoexamples.com"},"publishConfig":{"provenance":true,"access":"public"},"license":"ISC","keywords":["path","getPointAtLength","length","canvas","svg"],"homepage":"http://geoexamples.com/path-properties/","repository":{"type":"git","url":"git+https://github.com/rveciana/svg-path-properties.git"},"devDependencies":{"@changesets/changelog-github":"^0.5.0","@changesets/cli":"^2.27.7","@types/node":"^25.2.3","c8":"^10.1.2","eslint":"^9.39.2","eslint-plugin-security":"^3.0.1","husky":"^9.0.11","lint-staged":"^16.2.7","lockfile-lint":"^5.0.0","neostandard":"0.12.2","terser":"^5.43.1","tsup":"^8.1.0","tsx":"^4.19.4","typescript":"^5.5.3","validate-conventional-commit":"^1.0.4"},"lint-staged":{"**/*.{js,json}":["npm run lint:fix"]},"gitHead":"63466ab6225369f1534241e1a2794be5098c9696","_id":"svg-path-properties@2.1.0","bugs":{"url":"https://github.com/rveciana/svg-path-properties/issues"},"_nodeVersion":"22.23.2","_npmVersion":"12.0.2","dist":{"integrity":"sha512-Zp8IvhMTfQDeVqC8wczQQXJiF7HrafV/SFkRzjYcagchNh/FL+o/Ljbe++6vOfimkZp/bVHFJXb/V2dk51YgwA==","shasum":"4468b10d428b3b9c4195a3eb0d3b98ce659aab2c","tarball":"http://registry-npm.ywwl.com/svg-path-properties/download/svg-path-properties-2.1.0.tgz","fileCount":7,"unpackedSize":64733,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/svg-path-properties@2.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIA5YbtPe1L6rOXwgx6gPM5GW0S7Vcl3e8aNvYnBwfVBJAiEAuL4I7RFsQ0LeFsj1F4+EkXw7ygCNtpkW6tgUy9SOEk0="}],"size":21192,"noattachment":false,"key":"/svg-path-properties/-/svg-path-properties-2.1.0.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:41506038-2439-4296-8a76-1aa5838a8e40"}},"directories":{},"maintainers":[{"name":"rveciana","email":"rveciana@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/svg-path-properties_2.1.0_1787479163848_0.7620859474884767"},"_hasShrinkwrap":false,"readme":"# svg-path-properties\n\nPure Javascript alternative to getPointAtLength(t) and getTotalLength() functions. Works with Canvas objects and when Node\n\nJavaScript can access to path elements properties in a browser, such as its length and the point at a given length. Unfortunately, this can't be achieved using a Canvas element or when working with node. This library can be used to replace this need. It has no dependencies on other JavaScript libraries.\n\n## INSTALL\n\nTo use with npm, just type\n\n    npm install svg-path-properties\n\nThe package is lightweight with no dependencies (~20KB gzipped).\n\nYou can use it in the browser directly by including _svg-path-properties.min.js_ from the dist directory\n\n    <script src=\"svg-path-properties.min.js\"></script>\n\n## USAGE\n\nThe available methods are:\n\n    const path = require(\"svg-path-properties\");\n    const properties = new path.svgPathProperties(\"M0,100 Q50,-50 100,100 T200,100\");\n    const length = properties.getTotalLength();\n    const point = properties.getPointAtLength(200);\n    const tangent = properties.getTangentAtLength(200);\n    const allProperties = properties.getPropertiesAtLength(200);\n    const parts = properties.getParts();\n\n### `getTotalLength()`\n\nReturns the total length of the path.\n\n### `getPointAtLength(pos)`\n\nReturns `{ x, y }` — the coordinates at the given distance along the path.\n\n### `getTangentAtLength(pos)`\n\nReturns `{ x, y }` — the normalized tangent vector at the given distance.\n\n### `getPropertiesAtLength(pos)`\n\nReturns `{ x, y, tangentX, tangentY }` — point and tangent combined.\n\n### `getParts()`\n\nReturns an array of segment objects, one per path command (move commands are skipped). Each object has:\n\n| Property | Description |\n|---|---|\n| `start` | `{ x, y }` — start point of the segment |\n| `end` | `{ x, y }` — end point of the segment |\n| `length` | Arc length of the segment |\n| `getPointAtLength(pos)` | Point at local distance within the segment |\n| `getTangentAtLength(pos)` | Tangent at local distance within the segment |\n| `getPropertiesAtLength(pos)` | Point and tangent combined |\n| `details` | Raw segment parameters (see below) |\n\n#### `details` — segment parameters\n\nEach segment's `details` is a tuple in SVG notation with the **uppercase command letter** and all coordinates in **absolute form**:\n\n| Tuple | Segment type |\n|---|---|\n| `['L', x, y]` | Line to |\n| `['H', x]` | Horizontal line to |\n| `['V', y]` | Vertical line to |\n| `['Z']` | Close path |\n| `['C', cp1x, cp1y, cp2x, cp2y, x, y]` | Cubic Bézier |\n| `['Q', cpx, cpy, x, y]` | Quadratic Bézier |\n| `['A', rx, ry, xRotation, largeArcFlag, sweepFlag, x, y]` | Elliptical arc (`largeArcFlag` and `sweepFlag` are `0` or `1`) |\n\nExample — parametric interpolation along a cubic Bézier at evenly-spaced `t` values instead of arc-length:\n\n    import { svgPathProperties } from \"svg-path-properties\";\n\n    const parts = new svgPathProperties(\"M0,0 C10,20 30,40 50,0\").getParts();\n    for (const part of parts) {\n      if (part.details[0] === 'C') {\n        const [, cp1x, cp1y, cp2x, cp2y, x, y] = part.details;\n        // evaluate cubic Bézier at t=0.5\n        const t = 0.5;\n        const px = Math.pow(1-t,3)*part.start.x + 3*Math.pow(1-t,2)*t*cp1x + 3*(1-t)*t*t*cp2x + t*t*t*x;\n        const py = Math.pow(1-t,3)*part.start.y + 3*Math.pow(1-t,2)*t*cp1y + 3*(1-t)*t*t*cp2y + t*t*t*y;\n      }\n    }\n\n### Node\n\n    const path = require(\"svg-path-properties\");\n    const properties = new path.svgPathProperties(\"M0,100 Q50,-50 100,100 T200,100\");\n\n### Including it from an import\n\n    import { svgPathProperties } from \"svg-path-properties\";\n    const properties = new svgPathProperties(\"M0,100 Q50,-50 100,100 T200,100\");\n\n### Including the script in the browser\n\nOnce the _script_ tag has been included,\n\n    const properties = new svgPathProperties.svgPathProperties(\"M0,100 Q50,-50 100,100 T200,100\");\n\n### Using _new_\n\nSince _svgPathProperties_ is a class, using _new_ is the correct way to initilize it. For backwards compatibility reasons, the object can be get without it:\n\n    const properties = svgPathProperties(\"M0,100 Q50,-50 100,100 T200,100\");\n\n## Some usage examples\n\n- [Drawing an animated path](http://bl.ocks.org/rveciana/209fa7efeb01f05fa4a544a76ac8ed91)\n- [Label positioning](http://bl.ocks.org/rveciana/bef48021e38a77a520109d2088bff9eb)\n- [Drawing stramlines arrows](http://bl.ocks.org/rveciana/edb1dd43f3edc5d16ecaf4839c032dec)\n- [Using it to get a length when in node instead of the browser](https://github.com/veltman/flubber/blob/master/src/svg.js), as in the [Flubber library](https://github.com/veltman/flubber)\n- [SVG animations in React Native](https://bitbucket.org/ingenuityph/react-native-svg-animations/src/master/)\n\n## Typescript\n\nThe TypeScript declaration file is available too, since version 0.5.0. From version 1.0.0, the whole library has been rewritten using TypeScript, and the types are auto-generated.\n\nAll public APIs are fully documented with JSDoc comments for better IDE support.\n\n## CREDITS\n\nSome parts of the code are taken from other libraries or questions at StackOverflow:\n\nFor Bézier curves:\n\n- [example in bl.ocks.org](http://bl.ocks.org/hnakamur/e7efd0602bfc15f66fc5), [gist code](https://gist.github.com/tunght13488/6744e77c242cc7a94859)\n- [Stack overflow question](http://stackoverflow.com/questions/11854907/calculate-the-length-of-a-segment-of-a-quadratic-bezier)\n- [A Primer on Bézier Curves](http://pomax.github.io/bezierinfo)\n- [Arc elements calculation](https://github.com/MadLittleMods/svg-curve-lib/tree/f07d6008a673816f4cb74a3269164b430c3a95cb)\n\n- [path parsing](https://github.com/jkroso/parse-svg-path)\n","publish_time":1787479163989,"_cnpm_publish_time":1787479163989,"dist-tags":{"latest":"2.2.0"}}