Skip to content

Commit 1e58337

Browse files
furicclaude
andcommitted
Refactor CSS into modular architecture with design system
Major architectural improvement reorganizing monolithic CSS into maintainable modular structure with comprehensive design tokens and build-time optimization. Key Changes: • Modular CSS Structure: Split into 9 organized files across base/, animations/, and components/ • CSS Design System: 120+ custom properties for consistent theming and spacing • Build Integration: PostCSS import resolution for seamless development workflow • Enhanced Documentation: Comprehensive README and architecture updates • Performance Optimization: Single optimized CSS output with GPU-accelerated animations • Accessibility: Reduced motion support and high DPI screen enhancements Technical Improvements: • Fixed demo runtime error by resolving CSS @import statements during build • Added postcss-import plugin for proper CSS module processing • Created comprehensive design token system with color, spacing, and animation variables • Implemented mobile-first responsive design with logical breakpoint organization • Enhanced build pipeline with CSS minification and source map generation Benefits: • Maintainability: Clear separation of concerns with logical file organization • Customization: CSS variables enable easy theming and component variants • Performance: Optimized animations and efficient selector specificity • Developer Experience: Well-documented modular structure improves development workflow • Backward Compatibility: No breaking changes to existing component APIs 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 996f3d3 commit 1e58337

16 files changed

Lines changed: 1455 additions & 654 deletions

docs/wiki/wiki-architecture-overview.md

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ Deep dive into Cosmic UI Lite's technical architecture, design decisions, and sy
5050
### Design Principles
5151

5252
1. **Zero Dependencies** - Pure vanilla JavaScript/TypeScript
53-
2. **Modular Design** - Each component is self-contained
53+
2. **Modular Design** - Both component and CSS architecture are modular
5454
3. **SVG-Based** - Vector graphics for scalability
5555
4. **Performance First** - Optimized for 60fps animations
5656
5. **Type Safety** - Complete TypeScript support
5757
6. **Framework Agnostic** - Works with any framework or vanilla JS
58+
7. **Design System Driven** - CSS custom properties enable consistent theming
5859

5960
---
6061

@@ -337,9 +338,84 @@ const observer = new IntersectionObserver((entries) => {
337338

338339
---
339340

341+
## CSS Architecture
342+
343+
### Modular CSS Structure
344+
345+
Cosmic UI Lite now uses a modular CSS architecture for better maintainability and organization:
346+
347+
```
348+
src/styles/
349+
├── cosmic-ui.css # Main entry point with imports
350+
├── README.md # CSS architecture documentation
351+
├── base/ # Foundation styles
352+
│ ├── _variables.css # CSS custom properties and design tokens
353+
│ ├── _shared.css # Shared component styles and utilities
354+
│ └── _responsive.css # Mobile-first responsive design
355+
├── animations/ # Animation and interaction effects
356+
│ ├── _keyframes.css # All animation definitions
357+
│ └── _hover-effects.css # Interactive hover states
358+
└── components/ # Individual component styles
359+
├── _button.css # Button component styles
360+
├── _modal.css # Modal component styles
361+
├── _card.css # Card component styles
362+
├── _info.css # Info popup component styles
363+
└── _tag.css # Tag component styles
364+
```
365+
366+
### CSS Custom Properties System
367+
368+
```css
369+
/* CSS Design Tokens (_variables.css) */
370+
:root {
371+
/* Color System */
372+
--cosmic-primary: #00d4ff;
373+
--cosmic-primary-glow: rgba(0, 212, 255, 0.3);
374+
--cosmic-button-primary: #4da6ff;
375+
--cosmic-button-secondary: #ff6b35;
376+
--cosmic-button-danger: #ff4444;
377+
378+
/* Spacing System */
379+
--cosmic-button-min-width: 120px;
380+
--cosmic-card-min-width: 300px;
381+
--cosmic-padding-small: 4px;
382+
--cosmic-padding-large: 20px;
383+
384+
/* Animation System */
385+
--cosmic-transition-fast: 0.3s;
386+
--cosmic-animation-pulse-medium: 3s;
387+
--cosmic-animation-particle-medium: 8s;
388+
}
389+
```
390+
391+
### Build-Time CSS Processing
392+
393+
The modular CSS is processed during build time using PostCSS:
394+
395+
```javascript
396+
// CSS processing in rollup.config.js
397+
postcss({
398+
extract: 'cosmic-ui.css',
399+
minimize: production,
400+
sourceMap: !production,
401+
plugins: [
402+
postcssImport({
403+
path: ['src/styles', 'src/styles/base', 'src/styles/components', 'src/styles/animations']
404+
})
405+
]
406+
})
407+
```
408+
409+
**Processing Pipeline:**
410+
1. **Import Resolution** - `@import` statements are resolved and inlined
411+
2. **CSS Variable Processing** - Custom properties are optimized
412+
3. **Vendor Prefixing** - Auto-prefixes for browser compatibility
413+
4. **Minification** - CSS is compressed for production
414+
5. **Source Maps** - Generated for development debugging
415+
340416
## Build Pipeline
341417

342-
### Rollup Configuration
418+
### Enhanced Rollup Configuration
343419

344420
```javascript
345421
// rollup.config.js
@@ -354,7 +430,11 @@ export default [
354430
},
355431
plugins: [
356432
typescript({ declaration: true, outDir: 'dist' }),
357-
postcss({ extract: 'cosmic-ui.css', minimize: true })
433+
postcss({
434+
extract: 'cosmic-ui.css',
435+
minimize: true,
436+
plugins: [postcssImport()] // NEW: Resolves CSS imports
437+
})
358438
]
359439
},
360440

@@ -375,7 +455,7 @@ export default [
375455
output: {
376456
file: 'dist/index.umd.js',
377457
format: 'umd',
378-
name: 'CosmicUILite',
458+
name: 'CosmicUI', // Updated name
379459
sourcemap: true
380460
},
381461
plugins: [typescript(), terser()]

package-lock.json

Lines changed: 41 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"@rollup/plugin-node-resolve": "^15.0.0",
5656
"@rollup/plugin-terser": "^0.4.0",
5757
"@rollup/plugin-typescript": "^11.0.0",
58+
"postcss-import": "^16.1.1",
5859
"rollup": "^3.0.0",
5960
"rollup-plugin-dts": "^6.0.0",
6061
"rollup-plugin-postcss": "^4.0.0",

rollup.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import commonjs from '@rollup/plugin-commonjs';
44
import terser from '@rollup/plugin-terser';
55
import postcss from 'rollup-plugin-postcss';
66
import { dts } from 'rollup-plugin-dts';
7+
import postcssImport from 'postcss-import';
78

89
const production = !process.env.ROLLUP_WATCH;
910

@@ -24,7 +25,12 @@ const baseConfig = {
2425
postcss({
2526
extract: 'cosmic-ui.css',
2627
minimize: production,
27-
sourceMap: !production
28+
sourceMap: !production,
29+
plugins: [
30+
postcssImport({
31+
path: ['src/styles', 'src/styles/base', 'src/styles/components', 'src/styles/animations']
32+
})
33+
]
2834
})
2935
]
3036
};

0 commit comments

Comments
 (0)