{"id":13393502,"url":"https://github.com/nornagon/flatten-svg","last_synced_at":"2025-04-13T21:32:41.500Z","repository":{"id":34672680,"uuid":"175752239","full_name":"nornagon/flatten-svg","owner":"nornagon","description":"Flatten SVGs into points","archived":false,"fork":false,"pushed_at":"2023-03-04T03:21:07.000Z","size":1748,"stargazers_count":60,"open_issues_count":15,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-14T23:25:15.930Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nornagon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-03-15T05:09:33.000Z","updated_at":"2024-05-07T12:10:58.000Z","dependencies_parsed_at":"2024-01-13T17:11:05.445Z","dependency_job_id":"6de4cdd1-d429-4ad7-880f-26959320612f","html_url":"https://github.com/nornagon/flatten-svg","commit_stats":{"total_commits":25,"total_committers":4,"mean_commits":6.25,"dds":0.28,"last_synced_commit":"d399eec597d6cc6d0b72fe8faeb1cb48a217c108"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nornagon%2Fflatten-svg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nornagon%2Fflatten-svg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nornagon%2Fflatten-svg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nornagon%2Fflatten-svg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nornagon","download_url":"https://codeload.github.com/nornagon/flatten-svg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248786269,"owners_count":21161427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T17:00:54.463Z","updated_at":"2025-04-13T21:32:41.471Z","avatar_url":"https://github.com/nornagon.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# flatten-svg\n\n`flatten-svg` normalizes SVG shape data into a simplified line segment form\nsuitable for, say, a [plotter](https://axidraw.com/). All shapes are reduced to\nline segments, accurate to within a configurable error margin.\n\n## Example\n\nInput:\n\n```svg\n\u003csvg\u003e\n  \u003cg transform=\"translate(10 10)\"\u003e\n    \u003crect x=\"0\" y=\"0\" width=\"30\" height=\"10\" /\u003e\n    \u003cpath d=\"M0 0 l10 0 l0 10 l-10 0 Z\" /\u003e\n  \u003c/g\u003e\n\u003c/svg\u003e\n```\n\nUsage:\n\n```js\nimport {flattenSVG} from 'flatten-svg';\n\nconst paths = flattenSVG(svgElement);\n```\n\nOutput:\n\n```js\n[\n  { points: [[10, 10], [40, 10], [40, 20], [10, 20], [10, 10]] },\n  { points: [[10, 10], [20, 10], [20, 20], [10, 20], [10, 10]] }\n]\n```\n\n### Non-browser environments\n\n`flatten-svg` is compatible with [svgdom](https://github.com/svgjs/svgdom) for\nuse in non-browser environments such as node.js.\n\n```js\nimport {flattenSVG} from 'flatten-svg';\nimport {Window} from 'svgdom';\nimport {readFileSync} from 'fs';\n\nconst window = new Window\nwindow.document.documentElement.innerHTML = readFileSync('test.svg')\nconst paths = flattenSVG(window.document.documentElement)\n```\n\n## API\n\n### flattenSVG(svgElement[, options])\n\n* `svgElement` [SVGSVGElement](https://developer.mozilla.org/en-US/docs/Web/API/SVGSVGElement) - SVG to flatten.\n* `options` Object _(optional)_\n  * `maxError` number - maximum deviation from true shape. Defaults to 0.1.\n\nReturns `Line[]`\n\n### Line\n\nProperties:\n* `points` (\\[number, number] \u0026 {x: number, y: number})[] - list of points on the line\n* `stroke` ?string - if present, the `stroke` property of the line\n\nPoints on the line are two-element arrays ([x, y]), but also have .x and .y properties.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnornagon%2Fflatten-svg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnornagon%2Fflatten-svg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnornagon%2Fflatten-svg/lists"}