Scorpio
CSS as JavaScript
npm install --save-dev scorpio
;
Why?
- Simpler builds
- CSS and JS can share data
- Import into selector scopes (like above)
- Generate styles programmatically
Scorpio is written in plain old JavaScript, so that it works anywhere. It can be imported into a bundle using something like webpack, or included directly, like plain javascript. It will export its API functions as a node module, and/or on window.scorpio
.
API
$(selector, rulesAndChildren...)
Returns a selector with the given rules and child selectors. Child selectors will be scoped under the parent selector. See above example.
CSS(selectors...)
Returns a CSS string representation of the given selectors.
applyCSS(selectors...)
Same as CSS, except that it applies the styles instead of returning them. This is achieved by appending a <style>
tag to document.head
.