jarek-foksa/path-data-polyfill

How to use this library?

Exr0n opened this issue · 2 comments

Exr0n commented

I think I might be going crazy, but I can't figure out how to use this package. #4 loads it from a link that appears to be dead, and I still can't seem to access the polyfill when it's loaded from a script. Should it be imported from a js module?

<!doctype html>
<html>
  <head>
    <script src="https://raw.githubusercontent.com/jarek-foksa/path-data-polyfill/master/path-data-polyfill.js"></script>
    <script>
     window.addEventListener("load", (event) => {
       console.log("pathData", document.querySelector("path").getPathData());
     });
    </script>
  </head>
  <body>
    <svg viewBox="0 0 500 500">
      <path d="M 0 0 L 100 100 L 200 200"></path>
    </svg>
  </body>
</html>

(copied from #4 but using Github raw as a CDN (the horror) fails on my machine)
image

Any tips would be greatly appreciated!

Afaik raw.github URLs will be send as plain text (mime type) – so you can't use them directly as a js script source.

Use this instead –
<script src="https://cdn.jsdelivr.net/npm/path-data-polyfill@1.0.3/path-data-polyfill.min.js"></script>
Fetch it for instance from jsdelivr.com

Admittedly, finding the right CDN URL apparently has become trickier, just because similar named libraries show up first in search results.

Working examples
codepen: Helpers: svg convert primitives to path polygon, circle, rect etc)
stackoverflow: SVG - Convert all shapes/primitives to

... and pretty much every second svg SO answer related to advanced calculating tasks without using bloated libraries.
Jarek Foksa: thank you so much for this incredibly reliable "futurefill"!

Exr0n commented

Cool, thanks for the CDN link. That worked!