๐จ๐ CSSProxyBuilder (CSS-in-JS)
CSS.Builder provides a declarative, chainable API for building CSS with:
- ๐งฑ Nested selectors
- ๐ฑ Media queries
- ๐ Keyframes
- ๐งฌ Vendor prefixing
- ๐งน Optional minification
โจ๐ฏ Basic Example
1import { CSS } from "hbh-proxies";3const css = new CSS.Builder()4 .button({5 padding: "10px",6 background: "blue",7 color: "white"8 })9 .button.hover({10 background: "darkblue"11 })12 .all;14console.log(css);
๐จ Output
1button { padding: 10px; background: blue; color: white; }2button:hover { background: darkblue; }
๐๐ Selector Chaining
| Chain | Result |
|---|---|
.div.span |
div span |
.button.hover |
button:hover |
.ul.li.a |
ul li a |
Pseudo-selectors (
:hover,:active, etc.) automatically attach without spaces.
๐ฏ๐งฉ Applying Styles
You apply styles by calling the proxy:
1.div({2 margin: "0",3 padding: "0"4})
๐ฑ๐ Media Queries
Media queries are declared using keys starting with @media.
1.container({2 width: "100%",3 "@media (max-width: 600px)": {4 width: "90%"5 }6})
๐จ Output
1container { width: 100%; }2@media (max-width: 600px) {3 container { width: 90%; }4}
๐โจ Keyframes
1const css = new CSS.Builder()2 .keyframes("fadeIn", {3 from: { opacity: 0 },4 to: { opacity: 1 }5 })6 .box({7 animation: "fadeIn 1s ease-in"8 })9 .all;
๐จ Output
1box { animation: fadeIn 1s ease-in; }3@keyframes fadeIn {4 from { opacity: 0; }5 to { opacity: 1; }6}
๐งฌ๐ง Vendor Prefixing
Vendor prefixes are automatically applied to known properties:
1.box({2 transform: "scale(1.2)"3})
๐จ Output
1box {2 -webkit-transform: scale(1.2);3 -moz-transform: scale(1.2);4 -ms-transform: scale(1.2);5 -o-transform: scale(1.2);6 transform: scale(1.2);7}
๐ฆ Prefix Data
1CSS.Prefixers.Props // Set of prefixed properties2CSS.Prefixers.Prefixes // ['-webkit-', '-moz-', '-ms-', '-o-']
๐งนโก Minification
โถ๏ธ Enable Minification
1const css = new CSS.Builder()2 .minify()3 .card({4 padding: "10px",5 border: "1px solid #000"6 })7 .all;
๐จ Output
1card{padding:10px;border:1px solid #000}
๐ ๐งช Standalone Minifier
1import { CSS } from "hbh-proxies";3CSS.Minify(`4 /* comment */5 .box {6 padding: 10px;7 margin: 0;8 }9`);
๐ค๐ Retrieving CSS
| Property | Description |
|---|---|
.css |
Last generated CSS block |
.all |
Full accumulated CSS |
String(proxy) |
Same as .all |