@@ -16,7 +16,7 @@ The Style Injector provides:
1616## Quick Start
1717
1818``` typescript
19- import { inject , injectGlobal , configure } from ' ./tasty/injector' ;
19+ import { inject , configure } from ' ./tasty/injector' ;
2020
2121// Configure once (optional)
2222configure ({
@@ -25,32 +25,48 @@ configure({
2525});
2626
2727// Inject component styles
28- const { className, dispose } = inject (' &{ color: red; padding: 10px; }' );
28+ const { className, dispose } = inject ([{
29+ selector: ' .t-123' ,
30+ declarations: ' color: red; padding: 10px;'
31+ }]);
2932
3033// Inject global styles
31- const globalDispose = injectGlobal (' body' , ' margin: 0; font-family: Arial;' );
34+ const globalDispose = inject ([
35+ { selector: ' body' , declarations: ' margin: 0; font-family: Arial;' },
36+ { selector: ' .header' , declarations: ' background: blue; height: 60px;' }
37+ ]);
3238
3339// Cleanup when component unmounts
3440useEffect (() => dispose , [dispose ]);
3541```
3642
3743## API Reference
3844
39- ### ` inject(cssText: string , options?): InjectResult `
45+ ### ` inject(rules: StyleResult[] , options?): InjectResult `
4046
41- Injects CSS and returns a className with dispose function.
47+ Injects CSS rules and returns a className with dispose function. Supports both component injection (with generated class names) and global injection (with custom selectors) .
4248
4349``` typescript
44- const result = inject (' &{ color: red; &:hover{ color: blue; } }' );
50+ // Component injection - for tasty components
51+ const componentResult = inject ([{
52+ selector: ' .t-abc123' ,
53+ declarations: ' color: red; padding: 10px;' ,
54+ }]);
4555// Returns: { className: 't-abc123', dispose: () => void }
46- ```
47-
48- ### ` injectGlobal(selector: string, cssText: string, options?): DisposeFunction `
4956
50- Injects global CSS rules.
51-
52- ``` typescript
53- const dispose = injectGlobal (' body' , ' margin: 0; background: white;' );
57+ // Global injection - for global styles
58+ const globalResult = inject ([
59+ {
60+ selector: ' body' ,
61+ declarations: ' margin: 0; font-family: Arial;' ,
62+ },
63+ {
64+ selector: ' .header' ,
65+ declarations: ' background: blue; color: white;' ,
66+ atRules: [' @media (min-width: 768px)' ],
67+ }
68+ ]);
69+ // Returns: { className: 't-def456', dispose: () => void }
5470```
5571
5672### ` configure(config: Partial<StyleInjectorConfig>): void `
@@ -95,8 +111,8 @@ const cssForSSR = getCssText();
95111 │ │
96112 ▼ ▼
97113┌─────────────────┐ ┌─────────────────┐
98- │ flattenNestedCss │ │ CSSStyleSheet │
99- │ │ │ <style> element │
114+ │ StyleResult │ │ CSSStyleSheet │
115+ │ Array │ │ <style> element │
100116└─────────────────┘ └─────────────────┘
101117```
102118
@@ -105,11 +121,11 @@ const cssForSSR = getCssText();
105121### ✅ Complete
106122- Core types and interfaces
107123- Hash utility (collision-resistant, base52 encoding)
108- - CSS nesting flattener (handles all selector patterns )
124+ - Direct StyleResult injection (bypasses CSS parsing )
109125- SheetManager (DOM manipulation, cleanup)
110126- StyleInjector core (injection, deduplication, GC)
111127- Global configuration API
112- - Comprehensive test suite (89 passing tests)
128+ - Comprehensive test suite
113129
114130### 🔧 In Progress
115131- Integration with tasty components
@@ -122,13 +138,12 @@ const cssForSSR = getCssText();
122138## Test Coverage
123139
124140- ** Comprehensive test coverage** covering all critical functionality
125- - All major code paths tested: hashing, flattening , sheet management, reference counting, bulk cleanup
141+ - All major code paths tested: hashing, direct injection , sheet management, reference counting, bulk cleanup
126142
127143## Files
128144
129145- ` types.ts ` - TypeScript interfaces and types
130146- ` hash.ts ` - Hash utility for class name generation
131- - ` flatten.ts ` - CSS nesting flattener
132147- ` sheet-manager.ts ` - DOM stylesheet management
133148- ` injector.ts ` - Core StyleInjector class
134149- ` index.ts ` - Global API and configuration
0 commit comments