@melcanz85/chaincss 1.5.5 → 1.5.7

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 CHANGED
@@ -30,16 +30,15 @@ json
30
30
  Project Structure
31
31
 
32
32
  Create this folder structure in your project:
33
- text
34
33
 
35
34
  your-project/
36
35
  ├── chaincss/ # ChainCSS source files
37
- │ ├── chaincss.jcss # Main entry file
36
+ │ ├── main.jcss # Main entry file
38
37
  │ ├── chain.jcss # Chaining definitions
39
38
  │ └── processor.js # Processing script
40
39
  ├── public/ # Output files
41
40
  │ ├── index.html
42
- │ └── chainstyle.css # Generated CSS
41
+ │ └── style.css # Generated CSS
43
42
  ├── node_modules/
44
43
  ├── package.json
45
44
  └── package-lock.json
@@ -47,48 +46,22 @@ your-project/
47
46
  Processor Setup
48
47
 
49
48
  In chaincss/processor.js:
50
- javascript
51
49
 
52
- const jss = require("@melcanz85/chaincss");
50
+ const chain = require("@melcanz85/chaincss");
53
51
 
54
52
  try {
55
53
  // Process main file and output CSS
56
- jss.processJSS('./chaincss/chaincss.jcss', './public/chainstyle.css');
54
+ chain.processor('./chaincss/main.jcss', './public/style.css');
57
55
  } catch (err) {
58
- console.error('Error processing JSS file:', err.stack);
56
+ console.error('Error processing chainCSS file:', err.stack);
59
57
  process.exit(1);
60
58
  }
61
59
 
62
60
  💻 Code Examples
63
- Main File (chaincss/chaincss.jcss)
64
- javascript
65
61
 
66
- <@
67
- // Import chaining definitions
68
- const style = get('./chain.jcss');
62
+ --Chaining File (chaincss/chain.jcss):
69
63
 
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
- Chaining File (chaincss/chain.jcss)
91
- javascript
64
+ *** This is where the chaining happens all codes here are javascript codes the methods are the css properties but since its a js code its a camelCase syntax example the property font-family its fontFamily in chaincss syntax.
92
65
 
93
66
  // Variables for consistent styling
94
67
  const bodyBgColor = '#f0f0f0';
@@ -132,15 +105,43 @@ module.exports = {
132
105
  logoImgHeight
133
106
  };
134
107
 
135
- 📝 Notes
136
108
 
137
- CSS syntax can be written directly in .jcss files
109
+ --Main File (chaincss/main.jcss):
110
+
111
+ <@
112
+ // Import chaining definitions
113
+ const style = get('./chain.jcss');
114
+
115
+ // Override specific styles
116
+ style.header.bgColor = 'red';
117
+
118
+ // Compile to CSS
119
+ compile(style);
120
+ @>
138
121
 
139
- ChainCSS syntax must be wrapped in <@ @> delimiters
122
+ @media (max-width: 768px) {
123
+ <@
124
+ run(
125
+ chaincss.flexDirection('column').alignItems('flex-start').block('header'),
126
+ chaincss.order(1).block('.logo'),
127
+ chaincss.order(2).block('.search-bar'),
128
+ chaincss.order(3).block('h1'),
129
+ chaincss.order(5).block('nav'),
130
+ chaincss.order(4).display('flex').width('100%').justifyContent('flex-end').block('.burgerWrapper')
131
+ );
132
+ @>
133
+ }
134
+
135
+
136
+ 📝 Notes
137
+
138
+ You can directly put css syntax on your main file.
139
+
140
+ But chainCSS syntax must be wrapped in <@ @> delimiters.
140
141
 
141
142
  The get() function imports chaining definitions from other files
142
143
 
143
- Style modifications between get() and compile() will override existing styles
144
+ YOU can modify your style in between get() and compile() in the main file it will override the styles in the chainn file.
144
145
 
145
146
  🎨 Editor Support
146
147
 
@@ -148,7 +149,6 @@ Since .jcss files are just JavaScript files with ChainCSS syntax, you can easily
148
149
  VS Code
149
150
 
150
151
  Add this to your project's .vscode/settings.json:
151
- json
152
152
 
153
153
  {
154
154
  "files.associations": {
@@ -196,6 +196,8 @@ coffeescript
196
196
  Other Editors
197
197
 
198
198
  Most modern editors allow you to associate file extensions with language modes. Simply configure your editor to treat .jcss files as JavaScript.
199
+
200
+
199
201
  ✨ Features
200
202
  Status Feature Description
201
203
  ✅ Basic JS → CSS Convert plain JS objects to CSS
@@ -208,6 +210,8 @@ Status Feature Description
208
210
  👨‍💻 Contributing
209
211
 
210
212
  Contributions are welcome! Feel free to open issues or submit pull requests.
213
+
214
+
211
215
  📄 License
212
216
 
213
217
  MIT © Rommel Caneos
package/chaincss.js CHANGED
@@ -6,14 +6,10 @@ const path = require('path');
6
6
  const fs = require('fs');
7
7
  const chokidar = require('chokidar');
8
8
  const CleanCSS = require('clean-css');
9
-
10
- // CUSTOM MADE MODULE INSIDE JSS FOLDER
11
9
  const transpilerModule = require('./transpiler.js');
12
10
 
13
- console.log(__dirname);
14
11
  // FUNCTION TO PROCESS CHUNKS OF SCRIPTS FROM THE INPUT FILE USING THE VM MODULE
15
12
  const processScript = (scriptBlock) => {
16
- //const output = 'cssOutput = undefined;';
17
13
  const context = vm.createContext({
18
14
  ...transpilerModule
19
15
  });
@@ -35,6 +31,12 @@ const minifyCss = (css) => {
35
31
 
36
32
  // FUNCTION TO CONVERT JS CODES TO CSS CODE
37
33
  const processor = (inputFile, outputFile) => {
34
+ const allowedExtensions = ['.jcss'];
35
+ const fileExt = path.extname(inputFile).toLowerCase();
36
+
37
+ if (!allowedExtensions.includes(fileExt)) {
38
+ throw new Error(`Invalid file extension: ${fileExt}. Only .jcss files are allowed.`);
39
+ }
38
40
  const input = path.resolve(inputFile);
39
41
  const content = fs.readFileSync(input, 'utf8');
40
42
  const blocks = content.split(/<@([\s\S]*?)@>/gm);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melcanz85/chaincss",
3
- "version": "1.5.5",
3
+ "version": "1.5.7",
4
4
  "description": "A simple package transpiler for js to css",
5
5
  "main": "chaincss.js",
6
6
  "bin": {
package/transpiler.js CHANGED
@@ -1,3 +1,5 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
1
3
  const chain = {
2
4
  cssOutput : undefined,
3
5
  catcher: {},
@@ -193,10 +195,13 @@ const compile = (obj) => {
193
195
  for (const key in obj) {
194
196
  if (obj.hasOwnProperty(key)) {
195
197
  const element = obj[key];
196
- let selectors = element.selectors || [];
198
+ let selectors = element.selectors || []; // Provide default empty array if selectors is undefined
197
199
  let elementCSS = '';
198
-
200
+ console.log('Problematic element:', element);
201
+ console.log('Type of element:', typeof element);
202
+ console.log('Is element null?', element === null);
199
203
  for (let prop in element) {
204
+
200
205
  if (element.hasOwnProperty(prop) && prop !== 'selectors') {
201
206
  // Convert camelCase to kebab-case
202
207
  const kebabKey = prop.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
@@ -212,12 +217,35 @@ const compile = (obj) => {
212
217
  chain.cssOutput = cssString;
213
218
  };
214
219
 
215
- const get = require;
220
+ const get = (filename) => {
221
+ console.log('get() called with:', filename);
222
+ console.log('Current working directory:', process.cwd());
223
+
224
+ const fileExt = path.extname(filename).toLowerCase();
225
+ if (fileExt !== '.jcss') {
226
+ throw new Error(`Import error: ${filename} must have .jcss extension`);
227
+ }
228
+
229
+ // Try to resolve the path
230
+ const resolvedPath = path.resolve(process.cwd(), filename);
231
+ console.log('Resolved path:', resolvedPath);
232
+
233
+ // Check if file exists
234
+ const exists = fs.existsSync(resolvedPath);
235
+ console.log('File exists?', exists);
236
+
237
+ if (!exists) {
238
+ throw new Error(`File not found: ${filename} (resolved to: ${resolvedPath})`);
239
+ }
240
+
241
+ return require(resolvedPath);
242
+ };
216
243
 
217
244
  if (typeof global !== 'undefined') {
218
245
  global.chain = chain;
219
246
  }
220
247
 
248
+
221
249
  module.exports = {
222
250
  chain,
223
251
  run,