Skip to content

Commit f7bd632

Browse files
committed
Let's just get it out there.
0 parents  commit f7bd632

File tree

13 files changed

+1582
-0
lines changed

13 files changed

+1582
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
output

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Alex MacArthur
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# CSS by JS
2+
3+
The next iteration of CSS-in-JS. Turn your CSS into JS that turns it into CSS.
4+
5+
## Description
6+
7+
This a CLI tool that will turn a CSS file into JS, which will then apply the styles to the DOM when loaded in the browser. So, you write CSS, but you never load a single `*.css` file onto your page. It's left to JS, which is doing eveything else these days anyway.
8+
9+
For example, this CSS:
10+
11+
```css
12+
:root {
13+
--my-color: #1a1a1a;
14+
}
15+
16+
body,
17+
html {
18+
font-family: "Source Sans Pro", sans-serif;
19+
background: linear-gradient(45deg, #f5d9ff, #fefdff);
20+
color: var(--my-color);
21+
}
22+
23+
main {
24+
text-align: center;
25+
max-width: 700px;
26+
margin: 0 auto;
27+
}
28+
29+
h1,
30+
h3 {
31+
margin: 0;
32+
}
33+
```
34+
35+
Turns into this, which is then passed to a `applyCSS` function:
36+
37+
```javascript
38+
[
39+
{ name: ":root", properties: [{ name: "--my-color", value: "#1a1a1a" }] },
40+
{
41+
name: "body, html",
42+
properties: [
43+
{ name: "font-family", value: "'Source Sans Pro', sans-serif" },
44+
{ name: "background", value: "linear-gradient(45deg, #f5d9ff, #fefdff)" },
45+
{ name: "color", value: "var(--my-color)" }
46+
]
47+
},
48+
{
49+
name: "main",
50+
properties: [
51+
{ name: "text-align", value: "center" },
52+
{ name: "max-width", value: "700px" },
53+
{ name: "margin", value: "0 auto" }
54+
]
55+
},
56+
{ name: "h1, h3", properties: [{ name: "margin", value: "0" }] }
57+
];
58+
```
59+
60+
And when the output is loaded on your page, you get styles:
61+
62+
```html
63+
<script src=".output/css-by-js.js"></script>
64+
```
65+
66+
![alt text](./assets/markup.jpg "styles applied to DOM")
67+
68+
## Installation
69+
70+
`npm install css-by-js`
71+
72+
## Usage
73+
74+
You just need to pass in a reference to a CSS file, as well as location where the file will be outputted.
75+
76+
`css-by-js --file=./assets/sample.css --output=./assets/output.js`
77+
78+
A `--file` is required. If no `--output` is specified, a `css-by-js.js` file will be created in the current directory.
79+
80+
## Support
81+
82+
I can't imagine it works perfectly in every scenario, but I've designed the tool to handle simple element CSS rules (`div{}`), pseudo-elements, and even CSS custom properties. If you find an oddball out there, make file an issue or make a contribution.
83+
84+
## Why would I use this?
85+
86+
I'll leave that up to you.
87+
88+
## License
89+
90+
MIT © [Alex MacArthur](https://macarthur.me)

assets/markup.jpg

357 KB
Loading

assets/sample.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
:root {
2+
--my-color: #1a1a1a;
3+
}
4+
5+
body,
6+
html {
7+
font-family: "Source Sans Pro", sans-serif;
8+
background: linear-gradient(45deg, #f5d9ff, #fefdff);
9+
color: var(--my-color);
10+
}
11+
12+
main {
13+
text-align: center;
14+
max-width: 700px;
15+
margin: 0 auto;
16+
}
17+
18+
h1,
19+
h3 {
20+
margin: 0;
21+
}
22+
23+
h1 {
24+
font-size: 100px;
25+
}
26+
27+
h3 {
28+
font-size: 75px;
29+
}
30+
31+
h3:after {
32+
content: "";
33+
display: block;
34+
background: var(--my-color);
35+
height: 5px;
36+
width: 100%;
37+
}

output/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)