NV / CSSOM

Unmaintained! ⚠️ CSS Object Model implemented in pure JavaScript. Also, a CSS parser.
https://nv.github.io/CSSOM/docs/parse.html
MIT License
751 stars 99 forks source link

serialize/deserialize CSSOM.StyleSheet <> JSON #85

Closed pyramation closed 5 years ago

pyramation commented 7 years ago

I have a use case to serialize the "state" of the CSSOM.Stylesheet, not sure if this would be something useful, but I have working a gist here that exports CSSOM2JSON and JSON2CSSOM:

https://gist.github.com/pyramation/3bafcff80a4fc41b04af8834a2a0d794

Is this something that I am unaware of that already exists? I wanted to be able to write out to a JSON, and then read it back in and have a legitimate CSSOM object to work with

NV commented 5 years ago

No, I'm unaware of anything like this.

If you're willing to implement [toJSON method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()_behavior), I'm willing to take pull requests. I think it would make sense to add toJSON to StyleSheet and perhaps CSSRule.