Skip to content

Add SVG Path Data API explainer#1290

Open
viralipurbey wants to merge 3 commits intoMicrosoftEdge:mainfrom
viralipurbey:viralipurbey/svg-path-data-api
Open

Add SVG Path Data API explainer#1290
viralipurbey wants to merge 3 commits intoMicrosoftEdge:mainfrom
viralipurbey:viralipurbey/svg-path-data-api

Conversation

@viralipurbey
Copy link
Copy Markdown

@viralipurbey viralipurbey commented Mar 30, 2026

Adds an explainer for implementing the SVG Path Data API (getPathData(), setPathData(), getPathSegmentAtLength()) on SVGPathElement.

Tracking issue: #1289

Background

Chrome removed the old SVGPathSegList API in Chrome 48 (2015). The SVG WG specified a cleaner replacement in the SVG Paths spec §7, which Firefox shipped in v137 (Jan 2025). Chrome has had no native segment-level path access for 10+ years (crbug.com/40441025, 45 upvotes).

Proposed API

Method Description
getPathData(settings) Read path segments as {type, values} plain objects
setPathData(pathData) Write segments from an array of {type, values} objects
getPathSegmentAtLength(distance) Get the segment at a given path length

Supports {normalize: true} to reduce all commands to absolute M, L, C, Z.

Key design decisions

  • WebIDL dictionary (not interface) - accepts plain {type, values} POJOs natively, avoiding the compatibility issue Firefox hit in v137
  • unrestricted float - NaN/Infinity accepted without throwing, matching SVG's error model
  • Invalid segments silently skipped, matching SVG's "render what you can" model and Firefox

Changes

  • SVG/SVGPathDataAPI/explainer.md - full explainer
  • README.md - added entry to Active Explainers table (SVG group)

Proposes adding getPathData(), setPathData(), and getPathSegmentAtLength()
to SVGPathElement, implementing the SVG Paths spec DOM interfaces.
Already shipped in Firefox 137+.
@viralipurbey
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Microsoft"

- Fix security claim: setPathData() operates on structured data, no string
  parsing needed (does not go through setAttribute)
- Add arc-to-cubic normalization precision note
- Document empty path behavior: getPathData() returns [], setPathData([])
  clears the path
- Document getPathSegmentAtLength edge cases: null for empty/NaN, clamp
  negative to 0
- Split before/after example into separate code blocks to avoid variable
  redeclaration
- Fix Chrome 48 date from 2015 to Jan 2016 (stable release date)
- Fix spec PR status wording: 'to be filed' instead of 'pending'
@viralipurbey viralipurbey force-pushed the viralipurbey/svg-path-data-api branch from 6af2a15 to 588800b Compare April 1, 2026 09:59
@goldenboy777
Copy link
Copy Markdown
Contributor

Looks good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants