@melcanz85/chaincss 1.5.3 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +161 -191
- package/chaincss.js +5 -6
- package/package.json +1 -1
- package/transpiler.js +1 -1
package/README.md
CHANGED
|
@@ -1,193 +1,163 @@
|
|
|
1
1
|
# @melcanz85/chaincss
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
📦 Usage (Node.js)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
divSearchBar,
|
|
165
|
-
inputSearchBar
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
## In this example you can see the chaining pattern of code its like writing css code but in javascript fashion where you can manipulate its values through variables. In css you have to scroll down and find each block to change it. In this case you just find it through variables.
|
|
169
|
-
|
|
170
|
-
✨ Features
|
|
171
|
-
|
|
172
|
-
Status Feature Description
|
|
173
|
-
✅ Basic JS → CSS Convert plain JS objects to CSS
|
|
174
|
-
|
|
175
|
-
🚧 Nested selectors Support for parent { child {} } syntax
|
|
176
|
-
|
|
177
|
-
🚧 Media queries @media rule support
|
|
178
|
-
|
|
179
|
-
🚧 Keyframe animations @keyframes support
|
|
180
|
-
|
|
181
|
-
🚧 Vendor prefixing Auto-add -webkit-, -moz-, etc.
|
|
182
|
-
|
|
183
|
-
🚧 Source maps Debug generated CSS
|
|
184
|
-
|
|
185
|
-
🚧 Watch mode Auto-recompile on file changes
|
|
186
|
-
|
|
187
|
-
✅ = Working
|
|
188
|
-
🚧 = Coming soon
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
📄 License
|
|
192
|
-
|
|
193
|
-
MIT © Rommel Caneos
|
|
3
|
+
A simple JavaScript-to-CSS transpiler that converts JS objects into optimized CSS.
|
|
4
|
+
|
|
5
|
+
## 🚀 Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @melcanz85/chaincss
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 📦 Usage (Node.js)
|
|
12
|
+
|
|
13
|
+
### Quick Setup
|
|
14
|
+
|
|
15
|
+
1. **Install development dependencies:**
|
|
16
|
+
```bash
|
|
17
|
+
npm install --save-dev nodemon concurrently
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
2. **Update your `package.json` scripts:**
|
|
21
|
+
```json
|
|
22
|
+
"scripts": {
|
|
23
|
+
"start": "concurrently \"nodemon server.js\" \"nodemon --watch chaincss/*.jcss --watch processor.js --exec 'node processor.js'\""
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Project Structure
|
|
28
|
+
|
|
29
|
+
Create this folder structure in your project:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
your-project/
|
|
33
|
+
├── chaincss/ # ChainCSS source files
|
|
34
|
+
│ ├── chaincss.jcss # Main entry file
|
|
35
|
+
│ ├── chain.jcss # Chaining definitions
|
|
36
|
+
│ └── processor.js # Processing script
|
|
37
|
+
├── public/ # Output files
|
|
38
|
+
│ ├── index.html
|
|
39
|
+
│ └── chainstyle.css # Generated CSS
|
|
40
|
+
├── node_modules/
|
|
41
|
+
├── package.json
|
|
42
|
+
└── package-lock.json
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Processor Setup
|
|
46
|
+
|
|
47
|
+
In `chaincss/processor.js`:
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
const jss = require("@melcanz85/chaincss");
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
// Process main file and output CSS
|
|
54
|
+
jss.processJSS('./chaincss/chaincss.jcss', './public/chainstyle.css');
|
|
55
|
+
} catch (err) {
|
|
56
|
+
console.error('Error processing JSS file:', err.stack);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## 💻 Code Examples
|
|
62
|
+
|
|
63
|
+
### Main File (`chaincss/chaincss.jcss`)
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
<@
|
|
67
|
+
// Import chaining definitions
|
|
68
|
+
const style = get('./chain.jcss');
|
|
69
|
+
|
|
70
|
+
// Override specific styles
|
|
71
|
+
style.navA.color = 'red';
|
|
72
|
+
|
|
73
|
+
// Compile to CSS
|
|
74
|
+
compile(style);
|
|
75
|
+
@>
|
|
76
|
+
|
|
77
|
+
@media (max-width: 768px) {
|
|
78
|
+
<@
|
|
79
|
+
run(
|
|
80
|
+
chaincss.flexDirection('column').alignItems('flex-start').block('header'),
|
|
81
|
+
chaincss.order(1).block('.logo'),
|
|
82
|
+
chaincss.order(2).block('.search-bar'),
|
|
83
|
+
chaincss.order(3).block('h1'),
|
|
84
|
+
chaincss.order(5).block('nav'),
|
|
85
|
+
chaincss.order(4).display('flex').width('100%').justifyContent('flex-end').block('.burgerWrapper')
|
|
86
|
+
);
|
|
87
|
+
@>
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Chaining File (`chaincss/chain.jcss`)
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
// Variables for consistent styling
|
|
95
|
+
const bodyBgColor = '#f0f0f0';
|
|
96
|
+
const headerBgColor = '#333';
|
|
97
|
+
const bodyFontFamily = 'Arial, sans-serif';
|
|
98
|
+
const headerAlignItems = 'center';
|
|
99
|
+
const logoHeight = '50px';
|
|
100
|
+
|
|
101
|
+
// Reset browser defaults
|
|
102
|
+
const resetDefaultBrowStyle = chaincss
|
|
103
|
+
.margin('0')
|
|
104
|
+
.padding('0')
|
|
105
|
+
.block('body', 'h1', 'h2', 'h3', 'p', 'ul');
|
|
106
|
+
|
|
107
|
+
// Body styles
|
|
108
|
+
const bodyStyle = chaincss
|
|
109
|
+
.fontFamily(bodyFontFamily)
|
|
110
|
+
.lineHeight('1.6')
|
|
111
|
+
.bgColor(bodyBgColor)
|
|
112
|
+
.block('body');
|
|
113
|
+
|
|
114
|
+
// Header styles
|
|
115
|
+
const header = chaincss
|
|
116
|
+
.display('flex')
|
|
117
|
+
.alignItems(headerAlignItems)
|
|
118
|
+
.justifyContent('space-between')
|
|
119
|
+
.bgColor(headerBgColor)
|
|
120
|
+
.color('#fff')
|
|
121
|
+
.padding('10px 20px')
|
|
122
|
+
.block('header');
|
|
123
|
+
|
|
124
|
+
// Logo
|
|
125
|
+
const logoImgHeight = chaincss
|
|
126
|
+
.height(logoHeight)
|
|
127
|
+
.block('.logo img');
|
|
128
|
+
|
|
129
|
+
module.exports = {
|
|
130
|
+
resetDefaultBrowStyle,
|
|
131
|
+
bodyStyle,
|
|
132
|
+
header,
|
|
133
|
+
logoImgHeight
|
|
134
|
+
};
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## ✨ Features
|
|
138
|
+
|
|
139
|
+
| Status | Feature | Description |
|
|
140
|
+
|--------|---------|-------------|
|
|
141
|
+
| ✅ | Basic JS → CSS | Convert plain JS objects to CSS |
|
|
142
|
+
| 🚧 | Keyframe animations | @keyframes support |
|
|
143
|
+
| 🚧 | Vendor prefixing | Auto-add -webkit-, -moz-, etc. |
|
|
144
|
+
| 🚧 | Source maps | Debug generated CSS |
|
|
145
|
+
| 🚧 | Watch mode | Auto-recompile on file changes |
|
|
146
|
+
|
|
147
|
+
*✅ = Working, 🚧 = Coming soon*
|
|
148
|
+
|
|
149
|
+
## 📝 Notes
|
|
150
|
+
|
|
151
|
+
- CSS syntax can be written directly in `.jcss` files
|
|
152
|
+
- ChainCSS syntax must be wrapped in `<@ @>` delimiters
|
|
153
|
+
- The `get()` function imports chaining definitions from other files
|
|
154
|
+
- Style modifications between `get()` and `compile()` will override existing styles
|
|
155
|
+
|
|
156
|
+
## 👨💻 Contributing
|
|
157
|
+
|
|
158
|
+
Contributions are welcome! Feel free to open issues or submit pull requests.
|
|
159
|
+
|
|
160
|
+
## 📄 License
|
|
161
|
+
|
|
162
|
+
MIT © Rommel Caneos
|
|
163
|
+
|
package/chaincss.js
CHANGED
|
@@ -15,13 +15,12 @@ console.log(__dirname);
|
|
|
15
15
|
const processScript = (scriptBlock) => {
|
|
16
16
|
//const output = 'cssOutput = undefined;';
|
|
17
17
|
const context = vm.createContext({
|
|
18
|
-
...transpilerModule
|
|
18
|
+
...transpilerModule
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
const jsCode = scriptBlock.trim(); //`(function() { ${scriptBlock.trim()} })();`; Wrap script in IIFE
|
|
20
|
+
const jsCode = scriptBlock.trim();
|
|
22
21
|
const chainScript = new vm.Script(jsCode);
|
|
23
|
-
chainScript.runInContext(context);
|
|
24
|
-
return context.chain.cssOutput;
|
|
22
|
+
chainScript.runInContext(context);
|
|
23
|
+
return context.chain.cssOutput;
|
|
25
24
|
};
|
|
26
25
|
|
|
27
26
|
// CSS Minification Function
|
|
@@ -60,7 +59,7 @@ const processor = (inputFile, outputFile) => {
|
|
|
60
59
|
const outputDir = path.resolve(outputFile);
|
|
61
60
|
const trimmedCSS = outputCSS.trim();
|
|
62
61
|
const minCSS = minifyCss(trimmedCSS);
|
|
63
|
-
fs.writeFileSync(outputDir, minCSS, 'utf8');
|
|
62
|
+
fs.writeFileSync(outputDir, minCSS, 'utf8');
|
|
64
63
|
};
|
|
65
64
|
|
|
66
65
|
// Watch function
|
package/package.json
CHANGED
package/transpiler.js
CHANGED
|
@@ -193,7 +193,7 @@ const compile = (obj) => {
|
|
|
193
193
|
for (const key in obj) {
|
|
194
194
|
if (obj.hasOwnProperty(key)) {
|
|
195
195
|
const element = obj[key];
|
|
196
|
-
let selectors = element.selectors || [];
|
|
196
|
+
let selectors = element.selectors || [];
|
|
197
197
|
let elementCSS = '';
|
|
198
198
|
|
|
199
199
|
for (let prop in element) {
|