eva-css-fluid 1.0.4 → 2.0.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.
package/README.md CHANGED
@@ -62,8 +62,64 @@ pnpm add eva-css-fluid
62
62
  yarn add eva-css-fluid
63
63
  ```
64
64
 
65
+ **Migrating from another framework?** See the [Migration Guide](./MIGRATION.md) for detailed instructions.
66
+
67
+ ## 🚦 Which Configuration Method Should I Use?
68
+
69
+ EVA CSS can be configured in two ways. **Choose based on your project needs:**
70
+
71
+ ### For Quick Start / Learning
72
+ 👉 **Use SCSS Variables** - Everything in one file, works immediately
73
+
74
+ ### For Production Projects
75
+ Choose based on your needs:
76
+
77
+ | You want... | Use... |
78
+ |-------------|--------|
79
+ | Simplicity, no build scripts | **SCSS Variables** (`@use ... with ()`) |
80
+ | Centralized config, multiple SCSS files | **JSON Config** (requires custom build script) |
81
+ | Watch mode without complexity | **SCSS Variables** |
82
+ | Config validation, better DX | **JSON Config** (requires custom build script) |
83
+
84
+ 💡 **You can start with SCSS variables and migrate to JSON later - the generated CSS is identical!**
85
+
86
+ ### Option Comparison
87
+
88
+ | Feature | SCSS Variables | JSON Config |
89
+ |---------|----------------|-------------|
90
+ | **Setup complexity** | ⭐ Simple | ⭐⭐⭐ Requires script |
91
+ | **Works with `npx sass`** | ✅ Yes, immediately | ⚠️ No, needs custom script |
92
+ | **Config location** | Inside SCSS file | Separate `eva.config.cjs` |
93
+ | **Multiple SCSS files** | ⚠️ Config duplicated | ✅ Shared config |
94
+ | **Validation** | ❌ No | ✅ `npx eva-css validate` |
95
+ | **Generated CSS** | ✅ Identical output | ✅ Identical output |
96
+
97
+ **See detailed workflows below** for implementation examples.
98
+
65
99
  ## 🚀 Quick Start
66
100
 
101
+ ### New Project (Recommended)
102
+
103
+ Get started instantly with a fully configured project:
104
+
105
+ ```bash
106
+ npm init eva-css my-project
107
+ cd my-project
108
+ npm install
109
+ npm run dev
110
+ ```
111
+
112
+ This scaffolds a complete EVA CSS project with:
113
+ - ✅ Pre-configured `eva.config.cjs`
114
+ - ✅ Example HTML and SCSS files
115
+ - ✅ Build scripts with purge support
116
+ - ✅ Ready to customize with your design sizes
117
+
118
+ **Choose from 3 templates:**
119
+ - **Minimal** - Variables only, no utilities
120
+ - **Utility** - Full utility classes (recommended)
121
+ - **Full** - Everything + examples + theme switching
122
+
67
123
  ### Using Pre-built CSS
68
124
 
69
125
  ```html
@@ -72,13 +128,35 @@ yarn add eva-css-fluid
72
128
 
73
129
  ### Using SCSS with Default Configuration
74
130
 
131
+ **Simple import** (Sass automatically finds the package in node_modules):
132
+
75
133
  ```scss
76
134
  @use 'eva-css-fluid';
77
135
  ```
78
136
 
137
+ **Or with explicit path** (if needed):
138
+
139
+ ```scss
140
+ @use 'eva-css-fluid/src' as *;
141
+ ```
142
+
143
+ **Compilation** (no --load-path needed!):
144
+
145
+ ```bash
146
+ # Simple - Sass finds the package automatically
147
+ npx sass styles/main.scss:styles/main.css
148
+
149
+ # Or with older Sass versions
150
+ npx sass --load-path=node_modules styles/main.scss:styles/main.css
151
+ ```
152
+
79
153
  ### Using SCSS with Custom Configuration
80
154
 
81
- **This is the main feature of EVA CSS!** Simply change the `$sizes` to match your Figma design:
155
+ **This is the main feature of EVA CSS!** Extract sizes from your design and configure EVA to generate only what you need.
156
+
157
+ #### Option 1: SCSS Variables (Recommended for Beginners)
158
+
159
+ **Direct configuration in your SCSS file** - Works immediately with `npx sass`:
82
160
 
83
161
  ```scss
84
162
  // Example: Sizes extracted from Figma design
@@ -90,6 +168,88 @@ yarn add eva-css-fluid
90
168
  );
91
169
  ```
92
170
 
171
+ **Compile immediately:**
172
+
173
+ ```bash
174
+ npx sass --load-path=node_modules styles/main.scss:styles/main.css
175
+ ```
176
+
177
+ ✅ **Advantages:**
178
+ - Works immediately with standard Sass compilation
179
+ - No additional build scripts needed
180
+ - Perfect for watch mode: `npx sass --watch ...`
181
+ - Great for learning and simple projects
182
+
183
+ ⚠️ **Note:** If you import EVA in multiple SCSS files, you'll need to duplicate the configuration.
184
+
185
+ #### Option 2: JSON Configuration (Advanced - Requires Build Script)
186
+
187
+ **Centralized configuration file** - Better for complex projects with multiple SCSS files:
188
+
189
+ Create `eva.config.cjs` in your project root:
190
+
191
+ ```javascript
192
+ // eva.config.cjs
193
+ module.exports = {
194
+ sizes: [4, 8, 16, 32, 64, 128], // 👈 Change these to YOUR design sizes!
195
+ fontSizes: [14, 16, 20, 24, 32], // 👈 Change these to YOUR font sizes!
196
+ buildClass: true,
197
+ pxRemSuffix: false
198
+ };
199
+ ```
200
+
201
+ Then in your SCSS:
202
+
203
+ ```scss
204
+ @use 'eva-css-fluid';
205
+ ```
206
+
207
+ ⚠️ **IMPORTANT:** JSON configuration requires a **custom build script** to work. SCSS cannot execute JavaScript directly.
208
+
209
+ **You have two choices:**
210
+
211
+ **A) Use the EVA package's build script** (for building EVA itself):
212
+ ```bash
213
+ # This is only for building the EVA CSS package itself, NOT for your project
214
+ cd node_modules/eva-css-fluid
215
+ npm run build
216
+ ```
217
+
218
+ **B) Create your own build script** (recommended for user projects):
219
+
220
+ 1. Copy the build script template:
221
+ ```bash
222
+ # Download the template (see examples/ folder for ready-to-use script)
223
+ curl -o scripts/build-eva.js https://raw.githubusercontent.com/nkdeus/eva/main/examples/user-scripts/build-with-config.js
224
+ ```
225
+
226
+ 2. Add npm script to your `package.json`:
227
+ ```json
228
+ {
229
+ "scripts": {
230
+ "build:css": "node scripts/build-eva.js styles/main.scss dist/main.css"
231
+ }
232
+ }
233
+ ```
234
+
235
+ 3. Build your CSS:
236
+ ```bash
237
+ npm run build:css
238
+ ```
239
+
240
+ ✅ **Advantages:**
241
+ - Single config file shared across multiple SCSS files
242
+ - Config validation with `npx eva-css validate`
243
+ - Cleaner SCSS files
244
+ - Better for large projects
245
+
246
+ ⚠️ **Disadvantages:**
247
+ - Requires custom build script setup
248
+ - More complex workflow
249
+ - Not compatible with standard `npx sass` command
250
+
251
+ 💡 **New to EVA CSS?** Start with **Option 1 (SCSS Variables)** and migrate to JSON config later if needed!
252
+
93
253
  **Real example from a Figma project:**
94
254
 
95
255
  ```scss
@@ -106,8 +266,142 @@ yarn add eva-css-fluid
106
266
  // var(--4), var(--8), var(--16), var(--32), var(--64), var(--120), var(--141)
107
267
  ```
108
268
 
269
+ ## ❓ FAQ - Configuration
270
+
271
+ ### Q: Why doesn't `@use 'eva-css-fluid'` automatically load `eva.config.cjs`?
272
+
273
+ **A:** SCSS cannot execute JavaScript during compilation. The `eva.config.cjs` file must be read **before** SCSS compilation and transformed into SCSS variables.
274
+
275
+ **Solutions:**
276
+ - **Simple:** Use `@use ... with ()` directly in your SCSS (no script needed)
277
+ - **Advanced:** Create a build script that reads the config and injects it into SCSS (see Option 2 above)
278
+
279
+ ### Q: What's the difference between "JSON config" and "SCSS variables"?
280
+
281
+ **A:** The generated CSS is **100% identical**. It's only a matter of workflow organization:
282
+
283
+ | Method | Configuration Location | Compilation Command |
284
+ |--------|----------------------|---------------------|
285
+ | SCSS Variables | Inside SCSS file with `@use ... with ()` | `npx sass styles.scss` |
286
+ | JSON Config | Separate `eva.config.cjs` file | Custom script required |
287
+
288
+ **Choose based on your workflow:**
289
+ - **Simple projects:** SCSS variables (quick and easy)
290
+ - **Complex projects with multiple SCSS files:** JSON config (shared configuration)
291
+
292
+ ### Q: Can I use the `scripts/build-with-config.cjs` from the eva-css package?
293
+
294
+ **A:** That script is designed to **build EVA CSS itself** (the framework), not your project.
295
+
296
+ For your project, you need to:
297
+ 1. Create your own build script (see template in `examples/user-scripts/`)
298
+ 2. Or use SCSS variables with `@use ... with ()` instead
299
+
300
+ ### Q: Which option should I use for my project?
301
+
302
+ **A:** Follow this decision tree:
303
+
304
+ ```
305
+ Do you have multiple SCSS files that need the same EVA config?
306
+ ├─ NO → Use SCSS Variables (simpler)
307
+ └─ YES → Do you want config validation and centralized settings?
308
+ ├─ YES → Use JSON Config (requires build script setup)
309
+ └─ NO → Use SCSS Variables (simpler, just duplicate config)
310
+ ```
311
+
312
+ ### Q: Can I migrate from SCSS variables to JSON config later?
313
+
314
+ **A:** Yes! Since both methods generate identical CSS, you can switch at any time:
315
+
316
+ 1. Create `eva.config.cjs` with your settings
317
+ 2. Set up a build script (see examples/)
318
+ 3. Update your SCSS from `@use ... with ()` to `@use 'eva-css-fluid'`
319
+ 4. Update your build command
320
+
321
+ No CSS changes needed!
322
+
109
323
  ## 🎨 Configuration Options
110
324
 
325
+ ### JSON Configuration (eva.config.cjs or package.json)
326
+
327
+ | Option | Type | Default | Description |
328
+ |--------|------|---------|-------------|
329
+ | `sizes` | `number[]` | `[4, 8, 12, 16, ...]` | Available fluid size values (must include 16) |
330
+ | `fontSizes` | `number[]` | `[12, 14, 16, ...]` | Available font sizes |
331
+ | `buildClass` | `boolean` | `true` | Generate utility classes or variables only |
332
+ | `pxRemSuffix` | `boolean` | `false` | Add px/rem static values for debugging |
333
+ | `nameBySize` | `boolean` | `true` | Use size values in variable names |
334
+ | `customClass` | `boolean` | `false` | Enable custom class filtering |
335
+ | `classConfig` | `object` | `{}` | Map of properties to sizes for custom classes |
336
+ | `debug` | `boolean` | `false` | Show configuration summary during compilation |
337
+ | **`theme.name`** | `string` | `'eva'` | Theme name (CSS class: `.theme-{name}`) |
338
+ | **`theme.colors`** | `object` | See below | Theme colors (HEX or OKLCH) |
339
+ | **`theme.lightMode`** | `object` | `{lightness:96.4, darkness:6.4}` | Light mode configuration |
340
+ | **`theme.darkMode`** | `object` | `{lightness:5, darkness:95}` | Dark mode configuration |
341
+ | **`theme.autoSwitch`** | `boolean` | `false` | Auto-switch based on prefers-color-scheme |
342
+ | `purge.enabled` | `boolean` | `false` | Enable CSS purging/tree-shaking |
343
+ | `purge.content` | `string[]` | `['**/*.{html,js,...}']` | Files to scan for used classes |
344
+ | `purge.css` | `string` | `'dist/eva.css'` | Input CSS file to purge |
345
+ | `purge.output` | `string` | `'dist/eva-purged.css'` | Output path for purged CSS |
346
+ | `purge.safelist` | `string[]` | `['theme-', ...]` | Classes/patterns to always keep |
347
+
348
+ #### Theme Colors Configuration
349
+
350
+ Define your theme colors in HEX (auto-converted to OKLCH) or OKLCH format:
351
+
352
+ ```javascript
353
+ // eva.config.cjs
354
+ module.exports = {
355
+ theme: {
356
+ name: 'myapp',
357
+ colors: {
358
+ // HEX format (from Figma, design tools, etc.)
359
+ brand: '#ff5733', // Automatically converted to OKLCH
360
+ accent: '#7300ff',
361
+ extra: '#ffe500',
362
+
363
+ // Or OKLCH format (for precise control)
364
+ dark: { lightness: 20, chroma: 0.05, hue: 200 },
365
+ light: { lightness: 95, chroma: 0.01, hue: 200 }
366
+ },
367
+ lightMode: {
368
+ lightness: 96.4, // Light background
369
+ darkness: 6.4 // Dark text
370
+ },
371
+ darkMode: {
372
+ lightness: 5, // Dark background
373
+ darkness: 95 // Light text
374
+ },
375
+ autoSwitch: false // Manual toggle with .toggle-theme class
376
+ }
377
+ };
378
+ ```
379
+
380
+ **Available colors:** `brand`, `accent`, `extra`, `dark`, `light`
381
+
382
+ **Color formats:**
383
+ - **HEX**: `"#ff5733"` - Automatically converted via eva-colors
384
+ - **OKLCH**: `{ lightness: 68, chroma: 0.21, hue: 33.69 }`
385
+
386
+ **Usage in HTML:**
387
+
388
+ ```html
389
+ <body class="current-theme theme-myapp">
390
+ <h1 class="_c-brand">Hello World</h1>
391
+
392
+ <button onclick="document.body.classList.toggle('toggle-theme')">
393
+ Toggle Dark Mode
394
+ </button>
395
+ </body>
396
+ ```
397
+
398
+ **Configuration Priority:**
399
+ 1. JSON config file (`eva.config.cjs` or `eva.config.js`)
400
+ 2. package.json `"eva"` key
401
+ 3. SCSS `@use ... with ()` variables
402
+
403
+ ### SCSS Variables (when using @use with)
404
+
111
405
  | Variable | Default | Description |
112
406
  |----------|---------|-------------|
113
407
  | `$sizes` | `4, 8, 12, 16, 24, 32, 48, 64, 96, 128` | Available fluid size values |
@@ -115,7 +409,22 @@ yarn add eva-css-fluid
115
409
  | `$build-class` | `true` | Generate utility classes (`true`) or variables only (`false`) |
116
410
  | `$px-rem-suffix` | `false` | Add px/rem static values for debugging |
117
411
  | `$name-by-size` | `true` | Use size values in variable names |
118
- | `$custom-class` | `false` | Enable custom class generation |
412
+ | `$custom-class` | `false` | Enable custom class filtering |
413
+ | `$class-config` | `()` | Map of properties to sizes when `$custom-class: true` |
414
+ | `$debug` | `false` | Show class generation summary during compilation |
415
+
416
+ ### CLI Commands
417
+
418
+ ```bash
419
+ # Validate your configuration
420
+ npx eva-css validate
421
+
422
+ # Generate SCSS variables from JSON config
423
+ npx eva-css generate
424
+
425
+ # Get help
426
+ npx eva-css help
427
+ ```
119
428
 
120
429
  ## 💡 Usage Examples
121
430
 
@@ -144,6 +453,83 @@ yarn add eva-css-fluid
144
453
  }
145
454
  ```
146
455
 
456
+ ### Custom Class Mode (`$custom-class: true`)
457
+
458
+ Generate only specific classes to reduce CSS output size:
459
+
460
+ ```scss
461
+ @use 'eva-css-fluid/src' as * with (
462
+ $sizes: (24, 50, 100),
463
+ $custom-class: true,
464
+ $class-config: (
465
+ w: (50, 100), // Only .w-50 and .w-100
466
+ px: (24,), // Only .px-24 (note trailing comma)
467
+ g: (24, 50) // Only .g-24 and .g-50
468
+ )
469
+ );
470
+ ```
471
+
472
+ This generates only the specified classes, perfect for production builds or when you need fine control over output size.
473
+
474
+ ### Pre-configured Entry Points
475
+
476
+ EVA CSS provides multiple entry points for different use cases:
477
+
478
+ ```scss
479
+ // Full framework (default) - Everything included
480
+ @use 'eva-css-fluid';
481
+
482
+ // Variables only - Just CSS variables, no utility classes
483
+ @use 'eva-css-fluid/variables';
484
+
485
+ // Core framework - Variables + reset + typography, no utilities
486
+ @use 'eva-css-fluid/core';
487
+
488
+ // Colors only - Just the OKLCH color system
489
+ @use 'eva-css-fluid/colors';
490
+ ```
491
+
492
+ **When to use each:**
493
+ - **Default** (`eva-css-fluid`): Full-featured projects with utility classes
494
+ - **Variables** (`eva-css-fluid/variables`): Building custom components
495
+ - **Core** (`eva-css-fluid/core`): Foundation + custom utilities
496
+ - **Colors** (`eva-css-fluid/colors`): Adding EVA colors to existing projects
497
+
498
+ ### Debug Mode
499
+
500
+ Enable debug mode to see a summary of your configuration during compilation:
501
+
502
+ ```scss
503
+ @use 'eva-css-fluid' with (
504
+ $sizes: (16, 24, 50, 100),
505
+ $debug: true // ← Shows configuration summary
506
+ );
507
+ ```
508
+
509
+ **Output example:**
510
+ ```
511
+ ╔══════════════════════════════════════════════════════════════
512
+ ║ EVA CSS - Configuration Summary
513
+ ╠══════════════════════════════════════════════════════════════
514
+ ║ Sizes: 16, 24, 50, 100
515
+ ║ Total sizes: 4
516
+ ║ Font sizes: 16, 24
517
+ ║ Total font sizes: 2
518
+ ╠══════════════════════════════════════════════════════════════
519
+ ║ Build Configuration:
520
+ ║ - Build classes: true
521
+ ║ - Custom class mode: false
522
+ ║ - Px/Rem suffix: false
523
+ ║ - Name by size: true
524
+ ╠══════════════════════════════════════════════════════════════
525
+ ║ Estimated Utility Classes:
526
+ ║ - Size properties: ~256 classes
527
+ ║ - Available properties: w, mw, h, p, px, pr, py, br, mb, mr, ml, mt, pt, pb, g, gap
528
+ ╚══════════════════════════════════════════════════════════════
529
+ ```
530
+
531
+ Perfect for understanding what's being generated and optimizing your configuration!
532
+
147
533
  ## 🎨 Fluid Scaling
148
534
 
149
535
  EVA CSS uses modern CSS `clamp()` for fluid scaling:
@@ -266,12 +652,64 @@ npx sass my-project.scss:my-project.css
266
652
 
267
653
  **The magic:** All sizes scale fluidly across viewport sizes using `clamp()` - no media queries needed!
268
654
 
655
+ ## 🗜️ Production Optimization (Tree-shaking)
656
+
657
+ EVA CSS includes automatic CSS purging to remove unused classes in production builds.
658
+
659
+ ### Enable in Configuration
660
+
661
+ ```javascript
662
+ // eva.config.cjs
663
+ module.exports = {
664
+ sizes: [16, 24, 32, 64],
665
+ fontSizes: [16, 24, 32],
666
+ purge: {
667
+ enabled: true, // Enable purging
668
+ content: ['src/**/*.{html,js,jsx,tsx}'], // Files to scan
669
+ css: 'dist/eva.css', // Input CSS
670
+ output: 'dist/eva-purged.css', // Output CSS
671
+ safelist: ['theme-', 'current-'] // Classes to keep
672
+ }
673
+ };
674
+ ```
675
+
676
+ ### Build with Purge
677
+
678
+ ```bash
679
+ # Build with purge (if enabled in config)
680
+ npm run build
681
+
682
+ # Or force purge via CLI flag
683
+ npm run build:purge
684
+ ```
685
+
686
+ **Results:** Typically reduces CSS file size by 60-90% depending on usage.
687
+
688
+ ### Manual Purge with eva-purge
689
+
690
+ For more control, use the standalone `eva-purge` package:
691
+
692
+ ```bash
693
+ # Install
694
+ npm install --save-dev eva-css-purge
695
+
696
+ # Run purge
697
+ npx eva-purge --css dist/eva.css --content "src/**/*.html"
698
+
699
+ # Or use eva.config.cjs
700
+ npx eva-purge --config eva.config.cjs
701
+ ```
702
+
703
+ See [eva-purge documentation](https://www.npmjs.com/package/eva-css-purge) for more options.
704
+
269
705
  ## 🛠️ Build from Source
270
706
 
271
707
  ```bash
272
708
  cd packages/eva-css
273
- npm run build # Build expanded CSS
709
+ npm run build # Build with config (includes purge if enabled)
274
710
  npm run build:min # Build minified CSS
711
+ npm run build:purge # Build with purge (force)
712
+ npm run build:sass # Build without config (pure SCSS)
275
713
  npm run watch # Watch mode for development
276
714
  ```
277
715
 
package/cli.cjs ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * EVA CSS CLI
5
+ * Commands for configuration validation and project setup
6
+ */
7
+
8
+ const { validateConfigCommand, generateScssCommand } = require('./src/config-loader.cjs');
9
+ const { initCommand, setupCommand } = require('./src/cli-commands.cjs');
10
+
11
+ const args = process.argv.slice(2);
12
+ const command = args[0];
13
+
14
+ function printHelp() {
15
+ console.log(`
16
+ EVA CSS - Fluid Design Framework
17
+
18
+ Usage:
19
+ eva-css <command> [options]
20
+
21
+ Commands:
22
+ init Initialize EVA CSS in existing project (creates eva.config.cjs)
23
+ setup Complete project setup with workflow choice (SCSS vs JSON)
24
+ validate Validate eva.config.js or package.json configuration
25
+ generate Generate SCSS variables from config file
26
+ help Show this help message
27
+
28
+ Examples:
29
+ eva-css init # Initialize eva.config.cjs interactively
30
+ eva-css setup # Complete setup with file generation
31
+ eva-css validate # Validate configuration
32
+ eva-css generate output.scss
33
+
34
+ Getting Started:
35
+ For new projects: eva-css setup
36
+ For existing projects: eva-css init
37
+
38
+ Documentation:
39
+ https://github.com/nkdeus/eva/blob/main/packages/eva-css/README.md
40
+ `);
41
+ }
42
+
43
+ switch (command) {
44
+ case 'init':
45
+ initCommand();
46
+ break;
47
+
48
+ case 'setup':
49
+ setupCommand();
50
+ break;
51
+
52
+ case 'validate':
53
+ validateConfigCommand();
54
+ break;
55
+
56
+ case 'generate':
57
+ const outputPath = args[1] || 'src/_config-generated.scss';
58
+ generateScssCommand(outputPath);
59
+ break;
60
+
61
+ case 'help':
62
+ case '--help':
63
+ case '-h':
64
+ case undefined:
65
+ printHelp();
66
+ process.exit(0);
67
+ break;
68
+
69
+ default:
70
+ console.error(`❌ Unknown command: ${command}\n`);
71
+ printHelp();
72
+ process.exit(1);
73
+ }