Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src/geometry/Svg.js, SVGPathSeg deprecated in Chrome, will be removed #196

Open
erzahurak opened this issue Jan 26, 2016 · 10 comments
Open
Labels

Comments

@erzahurak
Copy link

Chrome now reports:
SVGPathSeg is deprecated and will be removed in Chrome 48. See https://www.chromestatus.com/feature/5708851034718208.

will need replaced with:
https://svgwg.org/specs/paths/#InterfaceSVGPathData

there is a polyfill for this as well:
https://github.com/jarek-foksa/path-data-polyfill.js

@erzahurak erzahurak changed the title src/geometry/Svg.js, SVGPathSeg being deprecated src/geometry/Svg.js, SVGPathSeg deprecated in Chrome, will be removed Jan 26, 2016
@peterdemartini
Copy link

+1

@peterdemartini
Copy link

Google's recommended poly fill, https://github.com/progers/pathseg

@liabru liabru added the task label Feb 1, 2016
@dcrockwell
Copy link

+1

@liabru liabru closed this as completed in 8fcb893 Feb 7, 2016
@liabru
Copy link
Owner

liabru commented Feb 7, 2016

I've added the polyfill to the demo, anyone else wishing to use it will need to include the polyfill in their code too.

It looks like rewriting the module to use the new standard would take a fair bit of work. I'm looking at other options for replacing it. Thanks guys.

vassiliskrikonis added a commit to vassiliskrikonis/whether-the-weather that referenced this issue Jun 12, 2016
…les to look better.

There was this matter.js issue:
liabru/matter-js#196 that needed the polyfill
to work in Chrome
@lehni
Copy link

lehni commented Apr 23, 2017

I'ld like to make the suggestion to use your own SVG path data parser. We've done so in Paper.js, and the code is rather small, and has been heavily tested with all kinds of strange path data. I could split this into a separate module and add a more general purpose API to it, if this is of interest?

Here the code, it's about 120 LOC:

https://github.com/paperjs/paper.js/blob/develop/src/path/PathItem.js#L127

This would then also allow for the passing of an string containing SVG path-data to pathToVertices() instead of an SVG <path> element (both should work).

@liabru
Copy link
Owner

liabru commented Apr 25, 2017

@lehni neat, can it output an array of absolute points for any given path?

@lehni
Copy link

lehni commented Sep 17, 2017

@liabru yes that should be fairly easy to achieve. But converting the bezier curves to sequence of points is another challenge (that we have solved in in paper.js, but unfortunately the library is monolithic in nature)

@gizmooo
Copy link

gizmooo commented Apr 19, 2019

I'ld like to make the suggestion to use your own SVG path data parser. We've done so in Paper.js, and the code is rather small, and has been heavily tested with all kinds of strange path data. I could split this into a separate module and add a more general purpose API to it, if this is of interest?

Here the code, it's about 120 LOC:

https://github.com/paperjs/paper.js/blob/develop/src/path/PathItem.js#L127

This would then also allow for the passing of an string containing SVG path-data to pathToVertices() instead of an SVG <path> element (both should work).

Yeeah! I got a function from a code that advised @lehni and I managed to do without Matter.Svg.pathToVertices()

function setPathData(pathData) {
  let parts = pathData && pathData.match(/[mlhvcsqtaz][^mlhvcsqtaz]*/ig),
      coords;
  let array = [];

  for (let i = 0, l = parts && parts.length; i < l; i++) {
    coords = parts[i].match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g);

    for (let j = 0; j < coords.length; j+=2) {
      array.push({
        x: +coords[j],
        y: +coords[j + 1]
      })
    }
  }

  return array;
}

It works in chrome and ios safari
No polyfill needed

@Saathvik-s
Copy link

@gizmooo I got the error pathData.match is not a function

@el1s7
Copy link

el1s7 commented Sep 8, 2022

@liabru Any update on this? The polyfill causes performance issues and freezes the browser for a few seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants