rafaelcaricio / gradient-parser

Parse CSS3 gradient definitions and build an AST object.
MIT License
62 stars 10 forks source link

Can this parser run in the browser? #22

Open illtellyoulater opened 1 year ago

illtellyoulater commented 1 year ago

I saw the code for this parser posted on Stack Overflow (https://stackoverflow.com/a/58071223/988591) and I thought about just copying it in the console window... No errors were thrown and I went ahead and ran:

GradientParser.parse(some_elem.style);

but I am getting this...

Uncaught Error: [object CSSStyleDeclaration]: Invalid input not EOF
    at error (<anonymous>:34:15)
    at getAST (<anonymous>:43:7)
    at Object.parse (<anonymous>:344:12)
    at <anonymous>:1:16

does it mean it can't run client side in the browser or am I doing something wrong?

I'm looking for a way to parse a linear-gradient in JS, client side... can't believe it seems almost impossible...

rafaelcaricio commented 1 year ago

It has been a long time since I looked at the code in this library. I honestly don't know, sorry.

illtellyoulater commented 1 year ago

Ok no worries I found another solution, but perhaps if you leave this open maybe someone else will be able to answer to this one day :)

wallyfaye commented 1 year ago

something with a trailing semi colon like gradient.parse('linear-gradient(rgb(22, 234, 174) 0%, rgb(126, 32, 207) 100%);') will cause this error whereas gradient.parse('linear-gradient(rgb(22, 234, 174) 0%, rgb(126, 32, 207) 100%)') is fine

rafaelcaricio commented 1 year ago

That sounds like an easy fix then. I'm open to accept any PR you might want to send to fix this.