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

Provide a way to get only the svg data #114

Open
vigreco opened this issue Jan 9, 2018 · 2 comments
Open

Provide a way to get only the svg data #114

vigreco opened this issue Jan 9, 2018 · 2 comments

Comments

@vigreco
Copy link
Collaborator

vigreco commented Jan 9, 2018

Currently the only way to generate an svg output in browser is using the method toString() which returns an svg tag as string:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 37 37">
  <path stroke="#000000" d="M4 4.5h7m1 0h2m1 0h2m1 ..."/>
</svg>

This is ok, but it could be a bit inconvenient for who want to handle the markup in a different way (for example in a React app) or who want to use the qrcode as a part of another image.

We should provide a way to return only the data and let the users do whatever they want with it.

// example output
{
  size: 37
  paths: [
    {
      d:"M0 0h37v37H0z",
      fill:"#ffffff"
    },
    {
      d: "M4 4.5h7m1 0h2m1 0h2m1 ...",
      stroke: "#000000"
    }
  ]
}

I'm not sure yet how/where to provide this output.
Should we add a dedicated method? or integrate it in the one already available and enable it through an option?

Any suggestions would be very appreciated 😄
Thanks!

cc @soldair

@soldair
Copy link
Owner

soldair commented Jan 10, 2018

this is interesting. thinking about it. =)

i worry that if you expose this object format we'll be kinda stuck with it even if you find a better way to do it in the future. I like dedicated methods that do the things they say they do. this is more what folks expect. like toSvg({data: true/false})

whatever you think =)

@TriMoon
Copy link

TriMoon commented Jul 15, 2019

It would be much better if there was a method to return a SVGElement, then the toString() could be rewritten to return the outerHTML...

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

No branches or pull requests

3 participants