@animus-ui/theming 0.1.1-beta.28 → 0.1.1-beta.30
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/CHANGELOG.md +12 -0
- package/CLAUDE.md +334 -0
- package/dist/utils/index.d.ts +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.1.1-beta.30](https://github.com/codecaaron/animus/compare/@animus-ui/theming@0.1.1-beta.28...@animus-ui/theming@0.1.1-beta.30) (2025-07-01)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @animus-ui/theming
|
|
9
|
+
|
|
10
|
+
## 0.1.1-beta.29 (2025-06-15)
|
|
11
|
+
|
|
12
|
+
## 0.1.1-beta.1 (2022-01-09)
|
|
13
|
+
|
|
14
|
+
## 0.1.1-beta.0 (2022-01-09)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @animus-ui/theming
|
|
17
|
+
|
|
6
18
|
## [0.1.1-beta.28](https://github.com/codecaaron/animus/compare/@animus-ui/theming@0.1.1-beta.27...@animus-ui/theming@0.1.1-beta.28) (2025-06-13)
|
|
7
19
|
|
|
8
20
|
**Note:** Version bump only for package @animus-ui/theming
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
# ThemeBuilder Architecture & Animus Integration
|
|
2
|
+
|
|
3
|
+
This document captures deep architectural insights about the ThemeBuilder system and its integration with the Animus builder from the core package.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
1. [ThemeBuilder Architecture](#themebuilder-architecture)
|
|
8
|
+
2. [Design Token Resolution Process](#design-token-resolution-process)
|
|
9
|
+
3. [Animus Builder Integration](#animus-builder-integration)
|
|
10
|
+
4. [Critical Integration Points](#critical-integration-points)
|
|
11
|
+
5. [Recommendations & Improvements](#recommendations--improvements)
|
|
12
|
+
6. [Open Questions](#open-questions)
|
|
13
|
+
|
|
14
|
+
## ThemeBuilder Architecture
|
|
15
|
+
|
|
16
|
+
### Overview
|
|
17
|
+
|
|
18
|
+
The ThemeBuilder provides a fluent, type-safe API for building themes with design tokens, CSS variables, and color modes. It follows a Producer-Consumer pattern where ThemeBuilder produces theme configuration and Animus consumes it via Emotion's ThemeProvider.
|
|
19
|
+
|
|
20
|
+
### Core Components
|
|
21
|
+
|
|
22
|
+
#### 1. Current ThemeBuilder Implementation (`createTheme.ts`)
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
export class ThemeBuilder<T extends AbstractTheme> {
|
|
26
|
+
#theme = {} as T;
|
|
27
|
+
|
|
28
|
+
constructor(baseTheme: T) { /* ... */ }
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Key Methods:**
|
|
33
|
+
- `createScaleVariables(key)` - Transforms theme scales into CSS variables
|
|
34
|
+
- `addColors(colors)` - Adds color tokens to the theme
|
|
35
|
+
- `addColorModes(initialMode, modeConfig)` - Implements color mode switching
|
|
36
|
+
- `addScale(key, createScale)` - Adds new scale to the theme
|
|
37
|
+
- `updateScale(key, updateFn)` - Updates existing scale values
|
|
38
|
+
- `build()` - Finalizes the theme
|
|
39
|
+
|
|
40
|
+
#### 2. Legacy ThemeBuilder (`ThemeBuilder.ts`)
|
|
41
|
+
|
|
42
|
+
Uses class inheritance hierarchy:
|
|
43
|
+
```
|
|
44
|
+
ThemeUnitialized → ThemeWithBreakpoints → ThemeWithRawColors → ThemeWithAll
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Theme Object Structure
|
|
48
|
+
|
|
49
|
+
The built theme contains three critical structures:
|
|
50
|
+
|
|
51
|
+
1. **Public Scales** (e.g., `theme.colors`): CSS variable references (`'var(--colors-primary)'`)
|
|
52
|
+
2. **Private Variables** (`theme._variables`): CSS variable definitions
|
|
53
|
+
3. **Private Tokens** (`theme._tokens`): Original values (currently redundant)
|
|
54
|
+
|
|
55
|
+
## Design Token Resolution Process
|
|
56
|
+
|
|
57
|
+
### 1. Token Definition Phase
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
createTheme(baseTheme)
|
|
61
|
+
.addColors({ primary: '#007bff' })
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 2. Serialization Phase
|
|
65
|
+
|
|
66
|
+
The `serializeTokens` function creates:
|
|
67
|
+
- **Token References**: `{ primary: 'var(--colors-primary)' }`
|
|
68
|
+
- **Token Variables**: `{ '--colors-primary': '#007bff' }`
|
|
69
|
+
|
|
70
|
+
### 3. Storage Phase
|
|
71
|
+
|
|
72
|
+
- `theme.colors.primary` = `'var(--colors-primary)'`
|
|
73
|
+
- `theme._variables.root['--colors-primary']` = `'#007bff'`
|
|
74
|
+
- `theme._tokens.colors.primary` = `'#007bff'`
|
|
75
|
+
|
|
76
|
+
### 4. Injection Phase (Critical Gap)
|
|
77
|
+
|
|
78
|
+
**Currently missing**: A mechanism to inject CSS variables into the DOM. Applications must implement:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const MyGlobalStyles = () => {
|
|
82
|
+
const theme = useTheme();
|
|
83
|
+
return (
|
|
84
|
+
<Global
|
|
85
|
+
styles={css`
|
|
86
|
+
:root {
|
|
87
|
+
/* Inject theme._variables.root here */
|
|
88
|
+
}
|
|
89
|
+
`}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 5. Component Usage Phase
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
<MyComponent color="primary" />
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 6. Style Resolution Phase
|
|
102
|
+
|
|
103
|
+
1. `createPropertyStyle` invoked for `color` prop
|
|
104
|
+
2. Calls `lookupScaleValue('primary', 'colors', theme)`
|
|
105
|
+
3. Returns `'var(--colors-primary)'`
|
|
106
|
+
4. Emotion generates CSS: `color: var(--colors-primary);`
|
|
107
|
+
|
|
108
|
+
### 7. Browser Resolution Phase
|
|
109
|
+
|
|
110
|
+
Browser applies styles using CSS Custom Properties from injected variables.
|
|
111
|
+
|
|
112
|
+
## Animus Builder Integration
|
|
113
|
+
|
|
114
|
+
### Architecture Overview
|
|
115
|
+
|
|
116
|
+
Animus uses a class hierarchy with fluent API:
|
|
117
|
+
```
|
|
118
|
+
Animus → AnimusWithBase → AnimusWithVariants → AnimusWithStates → AnimusWithSystem → AnimusWithAll
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Integration Points
|
|
122
|
+
|
|
123
|
+
1. **Theme Access**: Animus components receive theme via Emotion's ThemeProvider
|
|
124
|
+
2. **Scale Lookup**: `lookupScaleValue` resolves theme values from scales
|
|
125
|
+
3. **CSS Variable Support**: Animus treats CSS variable strings as opaque values
|
|
126
|
+
4. **Responsive Breakpoints**: Both systems use `theme.breakpoints` for media queries
|
|
127
|
+
|
|
128
|
+
### Value Resolution Flow
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
Component Prop → createPropertyStyle → lookupScaleValue → Theme Scale → CSS Variable → Browser
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Critical Integration Points
|
|
135
|
+
|
|
136
|
+
### 1. Scale Value Resolution
|
|
137
|
+
|
|
138
|
+
The `lookupScaleValue` function in core/src/scales/lookupScaleValue.ts:
|
|
139
|
+
- Resolves values from theme scales
|
|
140
|
+
- Falls back to compatTheme
|
|
141
|
+
- **Limitation**: Doesn't support negative values (e.g., `m="-4"`)
|
|
142
|
+
|
|
143
|
+
### 2. Responsive Values
|
|
144
|
+
|
|
145
|
+
- **ThemeBuilder**: Creates breakpoint CSS variables
|
|
146
|
+
- **Animus**: Uses breakpoints for media query generation
|
|
147
|
+
- Both systems must coordinate on breakpoint definitions
|
|
148
|
+
|
|
149
|
+
### 3. Color Modes
|
|
150
|
+
|
|
151
|
+
Current implementation has complexity:
|
|
152
|
+
- `_variables.mode` contains initial mode values
|
|
153
|
+
- `_tokens.modes` structure unclear
|
|
154
|
+
- Application responsible for mode switching logic
|
|
155
|
+
|
|
156
|
+
## Recommendations & Improvements
|
|
157
|
+
|
|
158
|
+
### 1. Simplify Theme Contract
|
|
159
|
+
|
|
160
|
+
Remove `_tokens` from final output, keeping only:
|
|
161
|
+
- **Public Scales**: CSS variable references
|
|
162
|
+
- **Private Variables**: CSS variable definitions
|
|
163
|
+
|
|
164
|
+
### 2. Provide Global Styles Utility
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
export const createGlobalStyles = (theme) => {
|
|
168
|
+
const { root, modes } = theme._variables;
|
|
169
|
+
|
|
170
|
+
return css`
|
|
171
|
+
:root {
|
|
172
|
+
${varsToCss(root)}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
${Object.entries(modes).map(([mode, vars]) => `
|
|
176
|
+
[data-theme='${mode}'] {
|
|
177
|
+
${varsToCss(vars)}
|
|
178
|
+
}
|
|
179
|
+
`).join('')}
|
|
180
|
+
`;
|
|
181
|
+
};
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 3. Support Negative Values
|
|
185
|
+
|
|
186
|
+
Update `lookupScaleValue` to handle string-prefixed negatives:
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
if (isString(val) && val.startsWith('-')) {
|
|
190
|
+
const positiveKey = val.substring(1);
|
|
191
|
+
const scaleValue = get(usedScale, positiveKey);
|
|
192
|
+
|
|
193
|
+
if (isString(scaleValue) || isNumber(scaleValue)) {
|
|
194
|
+
return `-${scaleValue}`;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 4. Improve Color Mode Architecture
|
|
200
|
+
|
|
201
|
+
Restructure `_variables` for clarity:
|
|
202
|
+
```typescript
|
|
203
|
+
{
|
|
204
|
+
_variables: {
|
|
205
|
+
root: { /* base tokens */ },
|
|
206
|
+
modes: {
|
|
207
|
+
light: { /* semantic aliases */ },
|
|
208
|
+
dark: { /* semantic aliases */ }
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### 5. Type Safety Enhancements
|
|
215
|
+
|
|
216
|
+
- Create comprehensive type tests for chained builder calls
|
|
217
|
+
- Provide `GetAnimusProps<T>` utility type
|
|
218
|
+
- Make `build()` method generic for better inference
|
|
219
|
+
|
|
220
|
+
## Open Questions
|
|
221
|
+
|
|
222
|
+
### Critical Architecture Questions
|
|
223
|
+
|
|
224
|
+
1. **Variable Injection Strategy**: Should we provide an official `ThemeProvider` wrapper that handles CSS variable injection automatically?
|
|
225
|
+
- Current gap: Apps must manually inject `theme._variables` into DOM
|
|
226
|
+
- Consideration: Auto-injection could simplify setup but reduce flexibility
|
|
227
|
+
|
|
228
|
+
2. **Migration Path**: How do we support gradual migration from literal-value themes to CSS-variable-based themes?
|
|
229
|
+
- Challenge: Mixed themes with both literal values and CSS variables
|
|
230
|
+
- Need: Clear documentation and tooling for incremental adoption
|
|
231
|
+
|
|
232
|
+
3. **Performance Optimization**: Is the extensive use of `lodash.merge` in builder chains a performance concern?
|
|
233
|
+
- Impact: Each builder method creates new merged objects
|
|
234
|
+
- Alternative: Investigate more performant merge strategies or lazy evaluation
|
|
235
|
+
|
|
236
|
+
4. **Type Complexity**: How can we simplify the generic type chains while maintaining type safety?
|
|
237
|
+
- Current: Heavy generic usage can create complex error messages
|
|
238
|
+
- Goal: Better developer experience with clearer type errors
|
|
239
|
+
|
|
240
|
+
### Integration Improvements
|
|
241
|
+
|
|
242
|
+
5. **Negative Value Support**: Should negative values use string prefix pattern (like Chakra UI)?
|
|
243
|
+
- Current: `lookupScaleValue` doesn't support negative theme values
|
|
244
|
+
- Proposed: Support `m="-4"` syntax for negative margins
|
|
245
|
+
|
|
246
|
+
6. **Color Mode Architecture**: Should we simplify the current three-source-of-truth pattern?
|
|
247
|
+
- Current: `_variables`, `_tokens`, and public scales create confusion
|
|
248
|
+
- Proposed: Eliminate `_tokens` from final build output
|
|
249
|
+
|
|
250
|
+
7. **Responsive Value Coordination**: How to ensure array/object responsive syntax works consistently?
|
|
251
|
+
- Need: Integration tests between ThemeBuilder breakpoints and Animus responsive arrays
|
|
252
|
+
- Challenge: Both systems must coordinate on breakpoint definitions
|
|
253
|
+
|
|
254
|
+
### Developer Experience
|
|
255
|
+
|
|
256
|
+
8. **Official Global Styles Utility**: Should we provide `createGlobalStyles` helper?
|
|
257
|
+
- Benefit: Standardized way to inject CSS variables
|
|
258
|
+
- Implementation: Could be part of @animus-ui/theming package
|
|
259
|
+
|
|
260
|
+
9. **Theme Structure Validation**: Should we validate theme structure at runtime?
|
|
261
|
+
- Use case: Catch missing CSS variable injections early
|
|
262
|
+
- Trade-off: Runtime validation vs. bundle size
|
|
263
|
+
|
|
264
|
+
10. **Documentation Gaps**: Which patterns need more comprehensive examples?
|
|
265
|
+
- Compound components with theming
|
|
266
|
+
- Global styles and CSS resets
|
|
267
|
+
- Performance optimization patterns
|
|
268
|
+
- Common UI patterns (modals, dropdowns, forms)
|
|
269
|
+
|
|
270
|
+
### Technical Debt
|
|
271
|
+
|
|
272
|
+
11. **Legacy ThemeBuilder**: Should we deprecate the class inheritance version?
|
|
273
|
+
- Current: Two implementations create confusion
|
|
274
|
+
- Migration: Need clear upgrade path for existing users
|
|
275
|
+
|
|
276
|
+
12. **Theme Contract Clarity**: How to better document the theme object contract?
|
|
277
|
+
- Issue: Unclear when to use `_variables` vs `_tokens` vs public scales
|
|
278
|
+
- Solution: Clearer separation of concerns in documentation
|
|
279
|
+
|
|
280
|
+
### New Questions from Real-World Usage Analysis
|
|
281
|
+
|
|
282
|
+
13. **Gradient Token System**: How should gradient tokens be defined in ThemeBuilder?
|
|
283
|
+
- Observed: Components use `gradient: 'flowX'` tokens
|
|
284
|
+
- Need: Clear pattern for defining complex gradient tokens as CSS variables
|
|
285
|
+
|
|
286
|
+
14. **Numeric Value Normalization**: How do numeric theme values (0, 1, 0.5) map to CSS?
|
|
287
|
+
- Observed: `width: 1`, `size: 1`, `left: 0.5` in components
|
|
288
|
+
- Question: Is this a percentage system or theme scale reference?
|
|
289
|
+
|
|
290
|
+
15. **Semantic Token Categories**: What token categories should ThemeBuilder support?
|
|
291
|
+
- Observed: text-shadow tokens ('flush', 'link-raised')
|
|
292
|
+
- Observed: gradient tokens ('flowX')
|
|
293
|
+
- Question: How to organize non-standard CSS tokens?
|
|
294
|
+
|
|
295
|
+
16. **WebKit-Specific Properties**: Should ThemeBuilder handle vendor prefixes?
|
|
296
|
+
- Observed: `WebkitTextFillColor`, `WebkitBackgroundClip` usage
|
|
297
|
+
- Challenge: CSS variables with vendor prefixes
|
|
298
|
+
|
|
299
|
+
17. **Grid Template Token Support**: Should grid templates be tokenized?
|
|
300
|
+
- Observed: Complex responsive grid templates in Layout
|
|
301
|
+
- Consideration: Token vs. inline definition trade-offs
|
|
302
|
+
|
|
303
|
+
18. **Animation Token Integration**: How should keyframe animations work with tokens?
|
|
304
|
+
- Observed: Imported keyframes used with Animus styles
|
|
305
|
+
- Question: Can animations reference theme tokens?
|
|
306
|
+
|
|
307
|
+
19. **Performance Benchmarks**: What's the performance impact of CSS variables?
|
|
308
|
+
- Heavy use of pseudo-elements with gradient variables
|
|
309
|
+
- Need: Benchmarks comparing literal values vs. CSS variables
|
|
310
|
+
|
|
311
|
+
20. **Custom Property Mappings**: Should ThemeBuilder know about Animus prop shorthands?
|
|
312
|
+
- Observed: `area` → `gridArea`, `gradient` → complex gradient
|
|
313
|
+
- Question: Where should this mapping knowledge live?
|
|
314
|
+
|
|
315
|
+
## Technical Notes
|
|
316
|
+
|
|
317
|
+
### Key Files
|
|
318
|
+
|
|
319
|
+
- `/packages/theming/src/utils/createTheme.ts` - Main builder implementation
|
|
320
|
+
- `/packages/theming/src/utils/serializeTokens.ts` - CSS variable generation
|
|
321
|
+
- `/packages/theming/src/utils/flattenScale.ts` - Object flattening utilities
|
|
322
|
+
- `/packages/core/src/scales/lookupScaleValue.ts` - Theme value resolution
|
|
323
|
+
- `/packages/core/src/Animus.ts` - Style builder integration
|
|
324
|
+
|
|
325
|
+
### Dependencies
|
|
326
|
+
|
|
327
|
+
- Emotion for CSS-in-JS and theming
|
|
328
|
+
- Lodash for object manipulation
|
|
329
|
+
- TypeScript for type safety
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
*Last Updated: January 2025*
|
|
334
|
+
*Analysis based on deep architectural review and integration testing*
|
package/dist/utils/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@animus-ui/theming",
|
|
3
|
-
"version": "0.1.1-beta.
|
|
3
|
+
"version": "0.1.1-beta.30",
|
|
4
4
|
"description": "Theming Utilities",
|
|
5
5
|
"author": "Aaron Robb <airrobb@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/codecaaron/animus#readme",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"url": "https://github.com/codecaaron/animus/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@animus-ui/core": "^0.2.0-beta.
|
|
28
|
+
"@animus-ui/core": "^0.2.0-beta.2",
|
|
29
29
|
"@emotion/react": "^11.14.0",
|
|
30
30
|
"@emotion/styled": "^11.14.0"
|
|
31
31
|
},
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"lodash": "*",
|
|
34
34
|
"typescript": ">=4.3.5"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "fbc53708e472bbc9b68a06d81a97614c504c8025"
|
|
37
37
|
}
|