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

@import support #3

Closed NV closed 12 years ago

NV commented 13 years ago
@import url("partial.css");
@import url("http://usercss.ru/styles/night/night.css");

Spec. WebKit implementation: CSSImportRule.cpp.

NV commented 13 years ago

Since I have to read a file (e.g. partial.css or http://usercss.ru/styles/night/night.css) it will be a platform-dependent. I need API to define how to do that. It might use XHR for browser environment. Don't know a good way to do it for Node.js yet.

papandreou commented 13 years ago

I have a use case where it would be nice if the import wasn't actually performed per default, but added to the data structure alongside cssRules.

stef commented 13 years ago

ditto, i need to handle the downloading my self. why not provide a callback that handles the downloading of imported sheets?

NV commented 13 years ago

stef, yes, it will be a callback.

NV commented 13 years ago

d7ac379d7f2ae3cbf727fda3a42e1569dc4c1807 Basic support of @import rules.

@import url(partial.css);

cssRules of imported stylesheet is always an empty array. Browsers behaves the same way when imported CSS is not found. If you need to parse imported stylesheet you can do it yourself by traversing a stylesheet, fetching CSSImportRule#href, parsing it and setting it back to CSSImportRule#styleSheet.

papandreou commented 13 years ago

it works beautifully. Used it to add support for CSSImport relations in AssetGraph 665b6f3.

Thanks! Papandreou

stef commented 13 years ago

thanks a lot! works here as well.

stef commented 13 years ago

i find a lot of css on the web, where the import rule is without the 'url()' enclosure, like this: @import "/wp-content/themes/arclite/style.css";

stef commented 13 years ago

there was a bug in the parser which prevented '"' enclosed urls to work, see stef/CSSOM@350c2a281aba8b471032