{"name":"svg-path-properties","version":"2.0.0","keywords":["path","getPointAtLength","length","canvas","svg"],"author":{"url":"https://geoexamples.com","name":"Roger Veciana i Rovira"},"license":"ISC","_id":"svg-path-properties@2.0.0","maintainers":[{"name":"rveciana","email":"rveciana@gmail.com"}],"homepage":"http://geoexamples.com/path-properties/","bugs":{"url":"https://github.com/rveciana/svg-path-properties/issues"},"dist":{"shasum":"7ce880bf6aa725d8c9613d5d3ec7ed292bc53f06","tarball":"http://registry-npm.ywwl.com/svg-path-properties/download/svg-path-properties-2.0.0.tgz","fileCount":16,"integrity":"sha512-7+zZ4gQB8/aOnNOMy+tqCO1b1oju5umaiiNX2KuXihUX9IwFctOiCXAetpyk2if/q+YZB9qiKbo2Q/klgpfuSQ==","signatures":[{"sig":"MEQCIBcRozyQjM0OXl4lZ32+hKqhn/tsvPMdw1vrunAUFGjRAiA4AowFx2gLfpH5/YXsyB+y0Bd8SrNUkIlxc2j7VgpXrg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/svg-path-properties@2.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":109382,"size":31574,"noattachment":false,"key":"/svg-path-properties/-/svg-path-properties-2.0.0.tgz"},"type":"module","types":"dist/main.d.ts","engines":{"node":">=22.0.0"},"exports":{".":{"import":{"types":"./dist/main.d.ts","default":"./dist/main.mjs"},"default":"./dist/main.mjs","require":{"types":"./dist/main.d.cts","default":"./dist/main.cjs"}},"./dist/*":{"types":"./dist/*.d.ts","import":"./dist/*.mjs","require":"./dist/*.cjs"}},"gitHead":"1f9fbb0c1d1743f5b096bb1ec3adb672b2d205ee","scripts":{"lint":"eslint . && npm run lint:lockfile","test":"c8 node --import tsx --test test/*.test.ts","build":"tsc && tsup --minify terser","release":"changeset publish","version":"changeset version","lint:fix":"eslint . --fix","test:watch":"c8 node --import tsx --test --watch test/**/*.test.ts","coverage:view":"open coverage/lcov-report/index.html","lint:lockfile":"lockfile-lint --path package-lock.json --validate-https --allowed-hosts npm yarn"},"_npmUser":{"name":"rveciana","email":"rveciana@gmail.com"},"repository":{"url":"git+https://github.com/rveciana/svg-path-properties.git","type":"git"},"_npmVersion":"10.8.2","description":"Calculate the length for an SVG path, to use it with node or a Canvas element","directories":{},"lint-staged":{"**/*.{js,json}":["npm run lint:fix"]},"_nodeVersion":"20.19.4","publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"packageManager":"npm@8.4.0","devDependencies":{"c8":"^10.1.2","tsx":"^4.19.4","tsup":"^8.1.0","husky":"^9.0.11","eslint":"^9.6.0","terser":"^5.43.1","typescript":"^5.5.3","@types/node":"24.0.15","lint-staged":"16.1.2","neostandard":"0.12.2","lockfile-lint":"^4.14.0","@changesets/cli":"^2.27.7","eslint-plugin-security":"^3.0.1","@changesets/changelog-github":"^0.5.0","validate-conventional-commit":"^1.0.4"},"_npmOperationalInternal":{"tmp":"tmp/svg-path-properties_2.0.0_1753219439340_0.40022842171807116","host":"s3://npm-registry-packages-npm-production"},"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":1753219439523,"_cnpm_publish_time":1753219439523,"dist-tags":{"latest":"2.2.0"}}