@melcanz85/chaincss 1.11.3 → 1.11.5

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.
Files changed (2) hide show
  1. package/README.md +134 -131
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -4,25 +4,54 @@
4
4
  [![npm version](https://img.shields.io/npm/v/@melcanz85/chaincss.svg)](https://www.npmjs.com/package/@melcanz85/chaincss)
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
6
 
7
- [![Live Demo](https://img.shields.io/badge/demo-live-brightgreen)](https://melcanz08.github.io/chaincss_react_website/)
7
+ [![Live Demo](https://img.shields.io/badge/demo-live-brightgreen)](https://chaincss.dev)
8
8
 
9
9
  **Write CSS with JavaScript. Lets you CHOOSE your runtime cost. DUAL MODE**
10
10
 
11
- **Build-time compilation** → Pure CSS, zero JavaScript in browser
11
+ * **Build-time compilation** → Pure CSS, zero JavaScript in browser
12
12
 
13
- **Runtime hooks** → Dynamic, prop-based styles when you need them
13
+ * **Runtime hooks** → Dynamic, prop-based styles when you need them
14
14
 
15
- ## Installation
15
+ ### Requirements
16
16
 
17
- * Install [nodejs.](https://nodejs.org/en/download)
17
+ * Node.js 18.x or higher [download.](https://nodejs.org/en/download)
18
+
19
+ * For React: React 16.8+ (hooks support required)
20
+
21
+ ## Installation & Setup
22
+
23
+ ### For Static/Build-time Usage
18
24
 
19
25
  ```bash
20
26
 
21
27
  npm install @melcanz85/chaincss
22
28
  ```
23
29
 
24
- * In your html add a link tag with an href value of style/global.css this serves as the
25
- stylesheet for your entire webpage. You dont need to touch this css file.
30
+ ### For React with Runtime Hooks
31
+
32
+ ```bash
33
+ npm install @melcanz85/chaincss
34
+ # React hooks are included in the main package
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ **Syntax**
40
+
41
+ 1. Create your first .jcss file
42
+
43
+ ```javascript
44
+ // main.jcss
45
+ <@
46
+ const text = $().color('blue').textAlign('center').block('p');
47
+
48
+ //text.fontSize = '2rem';
49
+
50
+ run(text);
51
+ @>
52
+ ```
53
+
54
+ 2. Add the stylesheet link to your HTML
26
55
 
27
56
  ```html
28
57
  <!-- index.html -->
@@ -38,32 +67,54 @@ stylesheet for your entire webpage. You dont need to touch this css file.
38
67
  </html>
39
68
  ```
40
69
 
41
- ## Syntax
70
+ 3. Run the compiler
71
+
72
+ ```bash
73
+ npx chaincss ./src/main.jcss ./style --watch
74
+ ```
75
+
76
+ * *Note: The first run creates ./chaincss.config.js with default values. Edit this file to customize your build.*
77
+
78
+ ```javascript
79
+
80
+ module.exports = {
81
+ atomic: {
82
+ enabled: true,
83
+ enabled: true,
84
+ threshold: 3,
85
+ naming: 'hash',
86
+ cache: true,
87
+ cachePath: './.chaincss-cache',
88
+ minify: true
89
+ },
90
+ prefixer: {
91
+ mode: 'auto',
92
+ browsers: ['> 0.5%', 'last 2 versions', 'not dead'],
93
+ enabled: true,
94
+ sourceMap: true,
95
+ sourceMapInline: false
96
+ }
97
+ };
98
+
99
+ ````
100
+
101
+ 4. Open index.html in your browser — your styles should be applied!
102
+
103
+ * To modify or add styles just add a property to the newly created style object before the run() function. They become javascript regular objects.
42
104
 
43
105
  ```javascript
44
106
  // main.jcss
45
107
  <@
46
108
  const text = $().color('blue').textAlign('center').block('p');
47
109
 
48
- //text.fontSize = '2rem';
110
+ text.fontSize = '2rem';
111
+ text.padding = '10px';
112
+ text.backgroundColor = 'rgb(106, 90, 205)';
49
113
 
50
114
  run(text);
51
115
  @>
52
116
  ```
53
117
 
54
- * To apply this styles run this in your terminal / command prompt.
55
-
56
- ```bash
57
- npx chaincss ./src/main.jcss ./style --watch
58
- ````
59
-
60
- * Open your index.html in the browser.
61
-
62
- * To make changes uncomment styles between text variable declaration and run() method.
63
-
64
- * Thats how you add or modify the style block you treat them as a regular javascript object.
65
-
66
-
67
118
  ### File Structure
68
119
 
69
120
  ```text
@@ -104,15 +155,6 @@ stylesheet for your entire webpage. You dont need to touch this css file.
104
155
  compile(button);
105
156
  @>
106
157
  ```
107
- ..then run this in terminal/command prompt
108
-
109
- ```bash
110
- npx chaincss ./src/main.jcss ./style --watch
111
- # ./style/global.css generated!
112
- ````
113
- * Note: running `npx chaincss ./src/main.jcss ./style --watch ` for the first time will
114
- generate ./chaincss.config.js with default values. You can edit this to
115
- customize your build!.
116
158
 
117
159
  ### Mode 2: Runtime (React Hooks)
118
160
 
@@ -176,14 +218,16 @@ stylesheet for your entire webpage. You dont need to touch this css file.
176
218
 
177
219
  ## Use BOTH in the Same Project!
178
220
 
179
- ```jsx
221
+ ```javascript
180
222
  // Best of both worlds:
181
223
  // - Layout styles → Build-time (zero cost)
182
224
  // - Interactive styles → Runtime (dynamic)
183
225
 
184
226
  // chaincss/layout.jcss (build-time)
185
227
  const grid = $().display('grid').gap('1rem').block('.grid');
228
+ ```
186
229
 
230
+ ```jsx
187
231
  // components/Card.jsx (runtime)
188
232
  function Card({ isHighlighted }) {
189
233
  const styles = useChainStyles(() => {
@@ -239,30 +283,6 @@ stylesheet for your entire webpage. You dont need to touch this css file.
239
283
  .block('.btn');
240
284
  ````
241
285
 
242
- ### Basic Example
243
-
244
- **chaincss/button.jcss**
245
-
246
- ```javascript
247
- const button = $()
248
- .backgroundColor('#667eea')
249
- .color('white')
250
- .padding('0.75rem 1.5rem')
251
- .borderRadius('0.375rem')
252
- .fontWeight('600')
253
- .block('.btn');
254
-
255
- module.exports = button;
256
- ```
257
- **chaincss/main.jcss**
258
-
259
- ```javascript
260
- <@
261
- const button = get('./button.jcss');
262
- compile({ button });
263
- @>
264
- ````
265
-
266
286
  ## Advanced Features
267
287
 
268
288
  ### Design Tokens
@@ -283,8 +303,11 @@ stylesheet for your entire webpage. You dont need to touch this css file.
283
303
  lg: '1.5rem'
284
304
  }
285
305
  });
306
+ ```
286
307
 
287
- // In your styles
308
+ **In your styles**
309
+
310
+ ```javascript
288
311
  const button = $()
289
312
  .color('$colors.primary') // ← Token syntax!
290
313
  .padding('$spacing.md')
@@ -307,65 +330,6 @@ stylesheet for your entire webpage. You dont need to touch this css file.
307
330
  **After (atomic CSS):** 499 chars → **90% smaller!**
308
331
 
309
332
 
310
- ## Quick Start Guides
311
-
312
- ### With Node.js (Vanilla)
313
-
314
- ```bash
315
- # 1. Install
316
- npm install @melcanz85/chaincss
317
-
318
- # 2. Create your first .jcss file
319
- mkdir chaincss
320
- echo "const hello = $().color('red').block('.hello');
321
- compile({ hello });" > chaincss/main.jcss
322
-
323
- # 3. Build
324
- npx chaincss ./src/main.jcss ./style --watch & node server.js
325
- # ./style/global.css generated!
326
- ```
327
-
328
- ### With React + Vite
329
-
330
- ```bash
331
- # 1. Create React app
332
- npm create vite@latest my-app -- --template react
333
- cd my-app
334
-
335
- # 2. Install ChainCSS
336
- npm install @melcanz85/chaincss
337
-
338
- # 3. Create component with styles
339
- mkdir -p src/components/Button
340
- ```
341
-
342
- **src/components/Button/Button.jsx**
343
-
344
- ```jsx
345
-
346
- import { useChainStyles } from '@melcanz85/chaincss';
347
-
348
- export function Button({ variant = 'primary', children }) {
349
- const styles = useChainStyles(() => {
350
- const button = $()
351
- .backgroundColor(variant === 'primary' ? '#667eea' : '#48bb78')
352
- .color('white')
353
- .padding('0.5rem 1rem')
354
- .borderRadius('0.375rem')
355
- .hover()
356
- .transform('translateY(-2px)')
357
- .boxShadow('0 4px 6px rgba(0,0,0,0.1)')
358
- .block()
359
- return { button };
360
- });
361
- return <button className={styles.button}>{children}</button>;
362
- }
363
- ```
364
-
365
-
366
- See ChainCSS in action! Visit our interactive demo site - [https://melcanz08.github.io/chaincss_react_website/](https://melcanz08.github.io/chaincss_react_website/)
367
-
368
-
369
333
  ## Performance Comparison
370
334
 
371
335
  Approach Runtime Cost Bundle Size Dynamic Styles Learning Curve
@@ -382,40 +346,42 @@ See ChainCSS in action! Visit our interactive demo site - [https://melcanz08.git
382
346
 
383
347
  CSS Modules Zero Just CSS None Low
384
348
 
385
- **ChainCSS a "DUAL MODE optioned" css-in-js library**
349
+ **ChainCSS a "DUAL MODE" css-in-js library**
350
+
386
351
 
387
352
  ## API Reference
388
353
 
354
+
389
355
  ### Core Functions
390
356
 
391
- Function Description
357
+ Function Description
392
358
 
393
- $() Create a new chain builder
359
+ `$()` Create a new chain builder
394
360
 
395
- .block(selector) End chain and assign selector(s)
361
+ `.block(selector)` End chain and assign selector(s)
396
362
 
397
- compile(styles) Compile style objects to CSS
363
+ `compile(styles)` Compile style objects to CSS
398
364
 
399
- run(...styles) Process inline styles
365
+ `run(...styles)` Process inline styles
400
366
 
401
- get(filename) Import .jcss files
367
+ `get(filename)` Import `.jcss` files
402
368
 
403
- processor(input, output) Build-time processor
369
+ `processor(input, output)` Build-time processor
404
370
 
405
371
 
406
372
  ### React Hooks
407
373
 
408
- Hook Description
374
+ Hook Description
409
375
 
410
- useChainStyles(styles, options) Basic styles hook
376
+ `useChainStyles(styles, options)` Basic styles hook
411
377
 
412
- useDynamicChainStyles(factory, deps) Styles that depend on props/state
378
+ `useDynamicChainStyles(factory, deps)` Styles that depend on props/state
413
379
 
414
- useThemeChainStyles(styles, theme) Theme-aware styles
380
+ `useThemeChainStyles(styles, theme)` Theme-aware styles
415
381
 
416
- ChainCSSGlobal Global styles component
382
+ `ChainCSSGlobal` Global styles component
417
383
 
418
- cx(...classes) Conditional class merging
384
+ `cx(...classes)` Conditional class merging
419
385
 
420
386
 
421
387
  ## Editor Support
@@ -442,6 +408,43 @@ See ChainCSS in action! Visit our interactive demo site - [https://melcanz08.git
442
408
  au BufRead,BufNewFile `*.jcss` setfiletype javascript
443
409
  ```
444
410
 
411
+ ### Troubleshooting
412
+
413
+ **Q: My styles aren't appearing in the browser**
414
+
415
+ * Ensure your HTML includes `<link rel="stylesheet" href="style/global.css">`
416
+
417
+ * Run `npx chaincss` at least once to generate the initial CSS file
418
+
419
+ * Check that your `.jcss` files are in the correct directory
420
+
421
+ * Verify the path in your `npx chaincss` command matches your file structure
422
+
423
+ **Q: React hooks aren't working**
424
+
425
+ * Verify you're using React 16.8 or newer
426
+
427
+ * Import from `@melcanz85/chaincss` (not a subpath)
428
+
429
+ **Q: The `get()` function returns undefined**
430
+
431
+ * Ensure the imported file exports something (`use module.exports = ...`)
432
+
433
+ * Check that the file path is correct relative to your `main.jcss`
434
+
435
+ **Q: Changes aren't reflected after saving**
436
+
437
+ * Make sure the `--watch` flag is active
438
+
439
+ * If not using watch mode, re-run the build command
440
+
441
+ * Clear your browser cache or do a hard refresh
442
+
443
+
444
+ ## See ChainCSS in Action
445
+
446
+ Visit our interactive demo site: [https://www.chaincss.dev/](https://www.chaincss.dev)
447
+
445
448
  ## Contributing
446
449
 
447
450
  Contributions are welcome! Whether it's:
@@ -464,4 +467,4 @@ MIT © [Rommel Caneos](https://github.com/melcanz08)
464
467
 
465
468
  ## Star Us on GitHub!
466
469
 
467
- If ChainCSS helps you, please [give it a star!](https://github.com/melcanz08/chaincss) It helps others discover it.
470
+ If ChainCSS helps you, please [give it a star!](https://github.com/melcanz08/chaincss) It helps others discover it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melcanz85/chaincss",
3
- "version": "1.11.3",
3
+ "version": "1.11.5",
4
4
  "description": "A simple package transpiler for js to css",
5
5
  "exports": {
6
6
  ".": {