@animus-ui/core 0.2.0-beta.0 → 0.2.0-beta.2

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.
@@ -1,87 +0,0 @@
1
- # Critical Findings: Animus Framework Analysis
2
-
3
- Based on comprehensive analysis across competitive positioning, agent compatibility, and philosophical foundations, these are the critical findings about Animus:
4
-
5
- ## 1. The Core Innovation: Progressive Type Narrowing
6
-
7
- **Finding**: Animus is the only CSS framework that uses class inheritance to enforce method calling order, creating a unique "progressive type narrowing" pattern.
8
-
9
- **Significance**: This transforms the infinite CSS possibility space into a finite state machine with clear transitions, making it uniquely suited for AI agent code generation.
10
-
11
- ## 2. Constraints Are Actually Advantages
12
-
13
- **Finding**: What initially appeared as rigid constraints (enforced method ordering) are actually significant advantages for both static analysis and AI agent predictability.
14
-
15
- **Evidence**:
16
- - Deterministic AST generation enables superior compile-time optimization
17
- - More amenable to static extraction than Panda CSS's flexible object API
18
- - Could potentially match or exceed Vanilla Extract's zero-runtime performance
19
-
20
- ## 3. The `extend()` Escape Hatch Changes Everything
21
-
22
- **Finding**: The `extend()` method completely eliminates the perceived inflexibility by allowing all methods to be called in any order when needed.
23
-
24
- **Impact**: This provides "guided flexibility" - structure for 95% of cases, complete freedom for 5% edge cases.
25
-
26
- ## 4. Perfect Human-AI Alignment
27
-
28
- **Finding**: Animus creates unprecedented alignment between human developer needs and AI agent capabilities.
29
-
30
- **How**:
31
- - Humans benefit from reduced cognitive load and self-documenting patterns
32
- - AI agents benefit from unambiguous intent expression and predictable patterns
33
- - Both benefit from having one canonical way to express styling intent
34
-
35
- ## 5. Intent-Driven API Design
36
-
37
- **Finding**: Each Animus method isn't just "adding styles" - it's declaring semantic intent:
38
- - `.styles()` = "This is what it always looks like"
39
- - `.variant()` = "This is how it varies by design choice"
40
- - `.states()` = "This is how it responds to interaction"
41
- - `.props()` = "This is what can be dynamically controlled"
42
-
43
- **Significance**: This creates a shared language for intent between humans and machines.
44
-
45
- ## 6. No Capability Sacrifice
46
-
47
- **Finding**: Despite the constraints, Animus retains full CSS capability:
48
- - Any valid CSS can be written in `.styles()`
49
- - All Emotion features (css prop, className, runtime styles) remain available
50
- - The constraints exist only at the API design level, not the capability level
51
-
52
- ## 7. Superior Agent Compatibility Potential
53
-
54
- **Finding**: With proper investment, Animus could become the #2 framework for AI agents (score: 8.84/10), surpassed only by Vanilla Extract.
55
-
56
- **Key Advantages**:
57
- - Type Safety: 10/10 potential
58
- - API Predictability: 10/10 potential
59
- - Code Generation: 10/10 potential
60
-
61
- ## 8. The Philosophy Is the Product
62
-
63
- **Finding**: Animus represents a new paradigm - "Constrain expression to enable communication, not capability to limit possibility."
64
-
65
- **Implication**: This philosophy could guide future API design in the AI age, where tools need to create structured languages for intent that both humans and machines can speak fluently.
66
-
67
- ## 9. Current Limitations Are Solvable
68
-
69
- **Finding**: The main current limitations are:
70
- - Documentation (4/10) - Easily improved with investment
71
- - Community (1/10) - Natural growth over time
72
- - Runtime overhead - Solvable with static extraction
73
-
74
- **Note**: The core architecture has no fundamental limitations.
75
-
76
- ## 10. This Is Actually Revolutionary (For AI Agents)
77
-
78
- **Personal Assessment**: After deep analysis and self-reflection, Animus IS revolutionary for AI agents because:
79
- - It's the only framework where the API itself enforces best practices
80
- - Invalid patterns are structurally impossible, not just discouraged
81
- - It transforms styling from an open-ended problem to a constraint satisfaction problem
82
-
83
- **The Ultimate Realization**: I would genuinely prefer working with Animus over more "flexible" alternatives. The pattern isn't just intellectually satisfying - it's practically optimal for how AI agents approach code generation.
84
-
85
- ## Conclusion
86
-
87
- Animus demonstrates that the future of human-AI collaboration isn't about dumbing down APIs or limiting capabilities. It's about creating structured ways to express intent that make the right thing the obvious thing, while keeping everything else possible. This is a genuinely new approach that could reshape how we think about API design in the age of AI.
@@ -1,393 +0,0 @@
1
- # A Proposal for a Build-Time CSS-in-JS Compiler for the Animus Component Builder API
2
-
3
- ## I. Introduction
4
-
5
- ### The Evolution of CSS-in-JS
6
-
7
- The evolution of styling in modern web development has seen a significant shift towards CSS-in-JS solutions, driven by:
8
- - Better developer experience
9
- - Component-level encapsulation
10
- - Ability to leverage JavaScript's dynamism
11
-
12
- However, traditional runtime CSS-in-JS libraries introduce performance overhead due to style parsing and injection during component rendering. This has spurred the development of build-time, or "zero-runtime," CSS-in-JS compilers that extract styles into static CSS files during the build process.
13
-
14
- ### Animus and Build-Time Compilation
15
-
16
- Animus, a library for "creating scalable and expressive component languages with CSS-in-JS", stands to gain substantially from a build-time compiler. This would:
17
- - Align with Animus's goal of expressiveness (JavaScript-based style definitions)
18
- - Ensure scalability and performance (optimized, static CSS output)
19
- - Draw inspiration from established solutions:
20
- - [Tamagui](https://tamagui.dev)
21
- - [Linaria](https://github.com/callstack/linaria)
22
- - [Vanilla Extract](https://vanilla-extract.style)
23
- - [Style9](https://github.com/johanholmerin/style9)
24
-
25
- ### Core Objectives
26
-
27
- The proposed Animus compiler aims to:
28
- 1. Parse styles defined via the Animus component builder API at build time
29
- 2. Generate atomic CSS for optimal bundle size and reusability
30
- 3. Handle dynamic styling and theming through CSS custom properties
31
- 4. Deliver high-performance styling with superior developer experience
32
- 5. Provide robust integration with modern build tools
33
-
34
- ## II. Core Architectural Principles
35
-
36
- ### A. Static Extraction of Styles
37
-
38
- #### The Foundation
39
- Build-time CSS-in-JS compilers shift style processing from the browser (runtime) to the developer's machine (build time).
40
-
41
- **Key Benefits:**
42
- - Browser downloads and parses CSS in parallel with JavaScript
43
- - Eliminates JavaScript execution cost for style computation
44
- - Enables advanced optimizations not possible at runtime
45
-
46
- **Implementation Examples:**
47
- - **Tamagui**: Pre-processes styles at build time, transforming verbose UI code into optimized atomic CSS
48
- - **Linaria**: Extracts CSS at build time, leaving no runtime component for style processing
49
-
50
- **Animus Requirements:**
51
- - Parse output of the component builder API (e.g., `.styles()`, `.variant()`, `.states()`)
52
- - Evaluate JavaScript expressions at build time (constants, theme variables)
53
- - Balance between expressive power and static analyzability
54
-
55
- ### B. Abstract Syntax Tree (AST) Manipulation
56
-
57
- #### Core Technology
58
- AST manipulation is central to static extraction and code transformation.
59
-
60
- **Primary Tools:**
61
- 1. **Babel**
62
- - Comprehensive transformation API
63
- - Visitor pattern for AST traversal
64
- - Used by Linaria for transformations
65
-
66
- 2. **esbuild**
67
- - Exceptional speed
68
- - Used by Tamagui for bundling and evaluation
69
- - Good for auxiliary tasks
70
-
71
- **Animus Implementation Strategy:**
72
-
73
- A custom Babel plugin would:
74
- 1. Identify Animus component builder API calls
75
- 2. Extract style objects or template literals
76
- 3. Evaluate embedded JavaScript expressions
77
- 4. Generate unique class names
78
- 5. Replace original definitions with class references
79
- 6. Collect extracted styles for CSS generation
80
-
81
- ### C. Generation of Atomic CSS
82
-
83
- #### The Atomic CSS Methodology
84
- Each CSS class performs a single, immutable styling task:
85
- ```css
86
- .color-blue { color: blue; }
87
- .padding-10 { padding: 10px; }
88
- ```
89
-
90
- **Benefits for Animus:**
91
- - **Reduced Bundle Size**: CSS size plateaus as components reuse atomic classes
92
- - **Improved Cacheability**: Highly reusable classes
93
- - **Predictable Styling**: Single-purpose classes reduce style conflicts
94
-
95
- **Real-World Results:**
96
- - Facebook's redesign: 413 KB → 74 KB gzipped CSS
97
- - Style9 and Tamagui both use atomic CSS generation
98
-
99
- **Implementation Process:**
100
- 1. Break down style rules into property-value pairs
101
- 2. Create deterministic class names for each pair
102
- 3. Assign multiple atomic classes to components
103
-
104
- ### D. Handling Dynamic Styles and Theming
105
-
106
- #### CSS Custom Properties Solution
107
- The most effective approach for zero-runtime dynamic styling uses CSS Variables.
108
-
109
- **Example Transformation:**
110
- ```javascript
111
- // Input (Linaria-style)
112
- const Title = styled.h1`
113
- color: ${props => (props.primary ? 'tomato' : 'black')};
114
- `;
115
-
116
- // Output CSS
117
- .title_xyz {
118
- color: var(--title-color-xyz);
119
- }
120
-
121
- // Runtime: style="--title-color-xyz: tomato;"
122
- ```
123
-
124
- #### Techniques for Dynamic Styling
125
-
126
- | Technique | Description | Example Libraries | Animus Implementation | Pros | Cons |
127
- |-----------|-------------|-------------------|----------------------|------|------|
128
- | **CSS Custom Properties via Props** | Styles use CSS variables; props update variables via inline styles | Linaria, Vanilla Extract, Style9 | Generate CSS with `var()`, set values inline | Highly flexible, minimal runtime | Requires CSS variable support |
129
- | **Pre-defined Variants** | Finite style variations; compiler generates CSS for each | Panda CSS, Vanilla Extract, Tamagui | `.variant()` generates classes like `.Button--size-small` | Zero runtime for definitions, type-safe | Less flexible for continuous values |
130
- | **Build-Time Theme Resolution** | Theme tokens resolved to values at compile time | Tamagui, Style9 | Replace `theme.colors.primary` with `#FF0000` | No runtime cost | Fixed at build time |
131
- | **Runtime Theme via CSS Variables** | Themes as CSS variable sets; switch by updating root variables | Vanilla Extract | Use `var(--animus-primary-color)` everywhere | Dynamic theme switching | More setup required |
132
-
133
- ## III. Compiler Toolchain and Implementation
134
-
135
- ### A. Leveraging Babel or esbuild
136
-
137
- #### Tool Selection
138
-
139
- **Babel**
140
- - Rich plugin ecosystem
141
- - Visitor pattern ideal for AST manipulation
142
- - Best for primary transformation phase
143
-
144
- **esbuild**
145
- - Exceptional speed
146
- - Good for bundling and evaluation tasks
147
- - Used by Tamagui for certain operations
148
-
149
- **Hybrid Approach for Animus:**
150
- - Babel for main AST traversal and style extraction
151
- - esbuild for evaluating theme files and utilities
152
-
153
- ### B. The Evaluator Component
154
-
155
- #### Purpose
156
- Evaluate JavaScript expressions within styles at compile time.
157
-
158
- #### Capabilities
159
-
160
- 1. **Constant Folding**
161
- - `2 * 8` → `16`
162
- - Simple arithmetic evaluation
163
-
164
- 2. **Variable Resolution**
165
- - Look up imported constants
166
- - Access theme values from whitelisted modules
167
-
168
- 3. **Function Calls**
169
- - Pure utility functions only
170
- - e.g., `darken(colors.primary, 0.1)`
171
-
172
- 4. **Sandboxing**
173
- - Isolated evaluation environment
174
- - Prevent arbitrary code execution
175
-
176
- #### Limitations
177
- - Cannot handle runtime state (props, browser APIs)
178
- - Dynamic aspects must use CSS variables
179
-
180
- ### C. Configuration and Integration
181
-
182
- #### Key Configuration Options
183
-
184
- ```javascript
185
- // animus.config.js
186
- {
187
- components: ['src/components/**/*'], // Where to find components
188
- themePath: './src/theme.ts', // Theme configuration
189
- importsWhitelist: ['constants.js'], // Safe to evaluate
190
- outputDir: '.animus', // Build artifacts
191
- atomicCss: true, // Enable atomic CSS
192
- disableExtraction: false // Dev mode flag
193
- }
194
- ```
195
-
196
- #### Bundler Integration
197
- - Webpack: Custom loader
198
- - Vite: Transform plugin
199
- - Rspack: Compatible with webpack loaders
200
-
201
- ## IV. Advanced Optimizations
202
-
203
- ### A. Tree Shaking and Dead Code Elimination
204
-
205
- #### Style-Level Tree Shaking
206
- - Analyze component usage across application
207
- - Remove unused variants and states
208
- - Track style dependency graphs
209
-
210
- **Implementation Complexity:**
211
- - Requires whole-application analysis
212
- - Must track dynamic prop usage
213
- - Start with simpler token-level DCE
214
-
215
- #### JavaScript Integration
216
- - Generate tree-shakeable JavaScript
217
- - Mark CSS imports with proper `sideEffects`
218
- - Use ES module syntax throughout
219
-
220
- ### B. Minimizing Runtime Overhead
221
-
222
- #### CSS Variables Approach
223
- ```javascript
224
- // Minimal runtime for dynamic styles
225
- element.style.setProperty('--my-color', newColor);
226
- ```
227
-
228
- #### Conditional Classes
229
- - Compile-time string concatenation
230
- - No runtime style object creation
231
- - Simple className application logic
232
-
233
- ### C. Cross-Platform Optimization (Tamagui-Inspired)
234
-
235
- #### Platform-Specific Output
236
- - **Web**: Generate CSS files
237
- - **React Native**: JavaScript style objects
238
-
239
- #### Compiler Requirements
240
- - Understand platform differences
241
- - Transform property names and values
242
- - Handle layout system variations
243
-
244
- ### D. Additional Optimizations
245
-
246
- 1. **CSS Property Sorting**: Improve compression
247
- 2. **Shorthand Handling**: Expand for atomicity
248
- 3. **Media Query Optimization**: Collapse and reorder
249
-
250
- ## V. Developer Experience Considerations
251
-
252
- ### A. API Design
253
-
254
- #### Animus Builder Pattern Advantages
255
- ```javascript
256
- // Structured, analyzable API
257
- const Button = animus
258
- .styles({ padding: '10px' })
259
- .variant({
260
- prop: 'size',
261
- variants: { small: {}, large: {} }
262
- })
263
- .states({ hover: {} })
264
- .asElement('button');
265
- ```
266
-
267
- **Benefits:**
268
- - Clear method semantics
269
- - Easier static analysis
270
- - Structured input for compiler
271
-
272
- ### B. Debugging Support
273
-
274
- #### Essential Features
275
- 1. **High-Quality Source Maps**
276
- - Link atomic classes to source
277
- - Enable browser DevTools inspection
278
-
279
- 2. **Clear Error Messages**
280
- - Pinpoint exact source location
281
- - Actionable error descriptions
282
-
283
- ### C. Build Tool Integration
284
-
285
- #### Requirements
286
- - Fast recompilation
287
- - Reliable HMR support
288
- - TypeScript integration
289
- - Editor autocompletion
290
-
291
- ## VI. Animus API Integration
292
-
293
- ### A. Compiler as API Backend
294
-
295
- The compiler processes structured builder definitions:
296
-
297
- ```javascript
298
- // Example Animus API usage
299
- Animus.defineComponent('MyStyledButton')
300
- .baseStyles({
301
- padding: '10px 15px',
302
- borderRadius: '4px',
303
- })
304
- .variants({
305
- intent: {
306
- primary: { backgroundColor: theme.colors.primary },
307
- secondary: { backgroundColor: theme.colors.secondary },
308
- },
309
- size: {
310
- small: { fontSize: '12px' },
311
- large: { fontSize: '16px' },
312
- }
313
- })
314
- .dynamicStyles(props => ({
315
- opacity: props.disabled ? 0.5 : 1,
316
- }))
317
- .build();
318
- ```
319
-
320
- **Compiler Processing:**
321
- - `.baseStyles()` and `.variants()` → Static extraction
322
- - `.dynamicStyles()` → CSS variable generation
323
-
324
- ### B. Preserving Expressiveness
325
-
326
- The compiler must:
327
- - Correctly interpret all API semantics
328
- - Handle complex variant definitions
329
- - Support responsive styles
330
- - Resolve theme tokens appropriately
331
-
332
- ### C. Developer Workflow
333
-
334
- 1. Define components using Animus API
335
- 2. Build process invokes compiler automatically
336
- 3. Compiler extracts and optimizes styles
337
- 4. Bundler processes results
338
- 5. No manual intervention required
339
-
340
- ## VII. Implementation Roadmap
341
-
342
- ### Phase 1: Core Functionality
343
- - Parse basic Animus API calls
344
- - Implement atomic CSS generation
345
- - Basic theme token resolution
346
- - Simple Babel plugin
347
-
348
- ### Phase 2: Dynamic Styling
349
- - CSS Custom Properties support
350
- - Runtime theme switching
351
- - Expression evaluation
352
- - Enhanced source maps
353
-
354
- ### Phase 3: Advanced Features
355
- - Dead code elimination
356
- - Media query optimization
357
- - TypeScript enhancements
358
- - HMR improvements
359
-
360
- ### Phase 4: Extended Capabilities (Optional)
361
- - Cross-platform support
362
- - Plugin architecture
363
- - Community extensions
364
-
365
- ## VIII. Key Challenges and Considerations
366
-
367
- ### Technical Challenges
368
- 1. **Static Analysis Complexity**: Reliable JavaScript evaluation
369
- 2. **Compiler Performance**: Fast build times for large projects
370
- 3. **Edge Case Handling**: Comprehensive CSS/JS coverage
371
- 4. **Ecosystem Evolution**: Keeping pace with frontend changes
372
-
373
- ### Long-Term Considerations
374
- - Ongoing maintenance requirements
375
- - Community building and documentation
376
- - Integration with design tools
377
- - Visual regression testing support
378
-
379
- ## IX. Conclusion
380
-
381
- A dedicated build-time CSS-in-JS compiler represents a strategic imperative for Animus. By combining:
382
- - Static extraction and AST manipulation
383
- - Atomic CSS generation
384
- - Intelligent dynamic styling via CSS Variables
385
- - Deep integration with the builder API
386
-
387
- The Animus compiler can deliver on the promise of "scalable and expressive component languages" without runtime performance penalties. A phased implementation approach, strong focus on developer experience, and commitment to ongoing maintenance will position Animus as a leading solution for next-generation component development.
388
-
389
- ---
390
-
391
- ## References
392
-
393
- [1-29] *[References omitted for brevity but preserved in structure]*