It exports two functions:
renderToString(styles)
- Render the CSS to a string. (This has no DOM dependency, and it omits the@charset
- that's for you to set.)renderToDOM(styles)
- Render the CSS to the DOM.
Note that renderToString
omits any charset - the user should specify that before emitting.
Styles are specified as follows:
const styles = {
// Optional: provide parent styles
"@extend": [...parents],
// Optional: provide imports with conditions
"@import": [
"url",
["url", "screen"],
["url", "supports(display: flex)"],
],
// Optional: provide namespaces (usually useless)
"@namespace": {
// Specify root namespace
"": "http://www.w3.org/1999/xhtml",
// Specify namespace for a particular prefix
"svg": "http://www.w3.org/2000/svg",
},
// Define selectors with properties
".foo": {
display: "flex",
// Define nested selectors
"> .bar": {
"margin": "0 auto",
}
},
// Define at-rules
"@page": {
color: "red",
"@first": {color: "green"},
},
}
Note that this doesn't support nested at-rules like ".foo": {"@media screen": ...}
.