@tenphi/tasty 0.13.0 → 0.14.0

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.
Files changed (92) hide show
  1. package/README.md +117 -28
  2. package/dist/chunks/cacheKey.js +16 -8
  3. package/dist/chunks/cacheKey.js.map +1 -1
  4. package/dist/chunks/renderChunk.js +31 -32
  5. package/dist/chunks/renderChunk.js.map +1 -1
  6. package/dist/config.d.ts +14 -2
  7. package/dist/config.js +11 -4
  8. package/dist/config.js.map +1 -1
  9. package/dist/core/index.d.ts +6 -4
  10. package/dist/core/index.js +5 -4
  11. package/dist/debug.d.ts +26 -141
  12. package/dist/debug.js +356 -635
  13. package/dist/debug.js.map +1 -1
  14. package/dist/hooks/useStyles.js +4 -3
  15. package/dist/hooks/useStyles.js.map +1 -1
  16. package/dist/index.d.ts +6 -4
  17. package/dist/index.js +5 -4
  18. package/dist/parser/classify.js +2 -1
  19. package/dist/parser/classify.js.map +1 -1
  20. package/dist/parser/parser.js +1 -1
  21. package/dist/pipeline/index.d.ts +1 -1
  22. package/dist/pipeline/index.js +24 -14
  23. package/dist/pipeline/index.js.map +1 -1
  24. package/dist/pipeline/materialize.js +328 -79
  25. package/dist/pipeline/materialize.js.map +1 -1
  26. package/dist/pipeline/parseStateKey.d.ts +1 -1
  27. package/dist/pipeline/parseStateKey.js +2 -6
  28. package/dist/pipeline/parseStateKey.js.map +1 -1
  29. package/dist/plugins/okhsl-plugin.js +2 -275
  30. package/dist/plugins/okhsl-plugin.js.map +1 -1
  31. package/dist/plugins/types.d.ts +1 -1
  32. package/dist/properties/index.js +2 -15
  33. package/dist/properties/index.js.map +1 -1
  34. package/dist/ssr/format-property.js +9 -7
  35. package/dist/ssr/format-property.js.map +1 -1
  36. package/dist/states/index.js +10 -257
  37. package/dist/states/index.js.map +1 -1
  38. package/dist/styles/color.js +9 -5
  39. package/dist/styles/color.js.map +1 -1
  40. package/dist/styles/createStyle.js +24 -21
  41. package/dist/styles/createStyle.js.map +1 -1
  42. package/dist/styles/index.js +1 -1
  43. package/dist/styles/predefined.js +1 -1
  44. package/dist/styles/predefined.js.map +1 -1
  45. package/dist/styles/types.d.ts +1 -1
  46. package/dist/tasty.d.ts +6 -6
  47. package/dist/tasty.js +24 -11
  48. package/dist/tasty.js.map +1 -1
  49. package/dist/types.d.ts +1 -1
  50. package/dist/utils/cache-wrapper.js +4 -8
  51. package/dist/utils/cache-wrapper.js.map +1 -1
  52. package/dist/utils/color-math.d.ts +46 -0
  53. package/dist/utils/color-math.js +749 -0
  54. package/dist/utils/color-math.js.map +1 -0
  55. package/dist/utils/color-space.d.ts +5 -0
  56. package/dist/utils/color-space.js +229 -0
  57. package/dist/utils/color-space.js.map +1 -0
  58. package/dist/utils/colors.js +3 -1
  59. package/dist/utils/colors.js.map +1 -1
  60. package/dist/utils/has-keys.js +13 -0
  61. package/dist/utils/has-keys.js.map +1 -0
  62. package/dist/utils/mod-attrs.js +2 -2
  63. package/dist/utils/mod-attrs.js.map +1 -1
  64. package/dist/utils/process-tokens.d.ts +3 -13
  65. package/dist/utils/process-tokens.js +18 -98
  66. package/dist/utils/process-tokens.js.map +1 -1
  67. package/dist/utils/styles.d.ts +2 -78
  68. package/dist/utils/styles.js +28 -535
  69. package/dist/utils/styles.js.map +1 -1
  70. package/dist/zero/babel.d.ts +8 -0
  71. package/dist/zero/babel.js +18 -3
  72. package/dist/zero/babel.js.map +1 -1
  73. package/dist/zero/next.js +9 -1
  74. package/dist/zero/next.js.map +1 -1
  75. package/docs/PIPELINE.md +519 -0
  76. package/docs/README.md +30 -0
  77. package/docs/adoption.md +10 -2
  78. package/docs/comparison.md +11 -6
  79. package/docs/configuration.md +26 -3
  80. package/docs/debug.md +152 -339
  81. package/docs/dsl.md +3 -1
  82. package/docs/getting-started.md +21 -7
  83. package/docs/injector.md +2 -2
  84. package/docs/runtime.md +59 -9
  85. package/docs/ssr.md +2 -2
  86. package/docs/styles.md +1 -1
  87. package/docs/tasty-static.md +19 -9
  88. package/package.json +4 -3
  89. package/dist/utils/hsl-to-rgb.js +0 -38
  90. package/dist/utils/hsl-to-rgb.js.map +0 -1
  91. package/dist/utils/okhsl-to-rgb.js +0 -296
  92. package/dist/utils/okhsl-to-rgb.js.map +0 -1
@@ -0,0 +1,519 @@
1
+ # Tasty Style Rendering Pipeline
2
+
3
+ This document describes the style rendering pipeline that transforms style objects into CSS rules. The pipeline ensures that each style value is applied to exactly one condition through exclusive condition building, boolean simplification, and intelligent CSS generation.
4
+
5
+ **Implementation:** [`src/pipeline/`](../src/pipeline/) — TypeScript file names below are relative to that directory.
6
+
7
+ ## Overview
8
+
9
+ The pipeline takes a `Styles` object and produces an array of `CSSRule` objects ready for injection into the DOM. Entry points include `renderStylesPipeline` (full pipeline + optional class-name prefixing) and `renderStyles` (direct selector/class mode). The per-handler flow has seven main stages:
10
+
11
+ ```
12
+ Input: Styles Object
13
+
14
+ ┌─────────────────────────────────────┐
15
+ │ 1. PARSE CONDITIONS │
16
+ │ parseStyleEntries + parseStateKey│
17
+ └─────────────────────────────────────┘
18
+
19
+ ┌─────────────────────────────────────┐
20
+ │ 2. BUILD EXCLUSIVE CONDITIONS │
21
+ │ Negate higher-priority entries │
22
+ └─────────────────────────────────────┘
23
+
24
+ ┌─────────────────────────────────────┐
25
+ │ 3. EXPAND AT-RULE OR BRANCHES │
26
+ │ expandExclusiveOrs (when needed)│
27
+ └─────────────────────────────────────┘
28
+
29
+ ┌─────────────────────────────────────┐
30
+ │ 4. COMPUTE STATE COMBINATIONS │
31
+ │ Cartesian product across styles │
32
+ └─────────────────────────────────────┘
33
+
34
+ ┌─────────────────────────────────────┐
35
+ │ 5. CALL HANDLERS │
36
+ │ Compute CSS declarations │
37
+ └─────────────────────────────────────┘
38
+
39
+ ┌─────────────────────────────────────┐
40
+ │ 6. MERGE BY VALUE │
41
+ │ Combine rules with same output │
42
+ └─────────────────────────────────────┘
43
+
44
+ ┌─────────────────────────────────────┐
45
+ │ 7. MATERIALIZE CSS │
46
+ │ Condition → selectors + at-rules│
47
+ └─────────────────────────────────────┘
48
+
49
+ ┌─────────────────────────────────────┐
50
+ │ runPipeline: dedupe identical rules │
51
+ └─────────────────────────────────────┘
52
+
53
+ Output: CSSRule[]
54
+ ```
55
+
56
+ **Simplification** (`simplifyCondition` in `simplify.ts`) is not a separate numbered stage. It runs inside exclusive building, `expandExclusiveOrs` branch cleanup, combination ANDs, merge-by-value ORs, and materialization as needed.
57
+
58
+ **Post-pass:** After `processStyles` collects rules from every handler, `runPipeline` filters duplicates using a key of `selector|declarations|atRules|rootPrefix` so identical emitted rules appear once.
59
+
60
+ ---
61
+
62
+ ## Stage 1: Parse Conditions
63
+
64
+ **Files:** `exclusive.ts` (`parseStyleEntries`), `parseStateKey.ts` (`parseStateKey`)
65
+
66
+ ### What It Does
67
+
68
+ Converts each state key in a style value map (like `'hovered & !disabled'`, `'@media(w < 768px)'`) into `ConditionNode` trees. `parseStyleEntries` walks the object keys in source order and assigns priorities; `parseStateKey` parses a single key string.
69
+
70
+ ### How It Works
71
+
72
+ 1. **Tokenization**: The state key is split into tokens using a regex pattern that recognizes:
73
+ - Operators: `&` (AND), `|` (OR), `!` (NOT), `^` (XOR)
74
+ - Parentheses for grouping
75
+ - State tokens: `@media(...)`, `@root(...)`, `@parent(...)`, `@own(...)`, `@supports(...)`, `@(...)`, `@starting`, predefined states, modifiers, pseudo-classes
76
+
77
+ 2. **Recursive Descent Parsing**: Tokens are parsed with operator precedence:
78
+ ```
79
+ ! (NOT) > ^ (XOR) > | (OR) > & (AND)
80
+ ```
81
+
82
+ 3. **State Token Interpretation**: Each state token is converted to a specific condition type:
83
+ - `hovered` → `ModifierCondition` with `attribute: 'data-hovered'`
84
+ - `theme=dark` → `ModifierCondition` with `attribute: 'data-theme', value: 'dark'`
85
+ - `:hover` → `PseudoCondition`
86
+ - `@media(w < 768px)` → `MediaCondition` (`subtype: 'dimension'`) with bounds
87
+ - `@media(prefers-color-scheme: dark)` → `MediaCondition` (`subtype: 'feature'`, `feature` + `featureValue`)
88
+ - `@root(schema=dark)` → `RootCondition` wrapping the inner condition
89
+ - `@parent(hovered)` → `ParentCondition` (optional `direct` for immediate parent)
90
+ - `@own(hovered)` → `OwnCondition` wrapping the parsed inner condition
91
+ - `@supports(display: grid)` → `SupportsCondition`
92
+ - `@(w < 600px)` → `ContainerCondition` (dimension, style, or raw subtypes)
93
+ - `@mobile` → Resolved via predefined states, then parsed recursively
94
+
95
+ Pipeline warnings for invalid inputs (e.g. bad `$` selector affix) are emitted from `warnings.ts`.
96
+
97
+ ### Why
98
+
99
+ The condition tree representation enables:
100
+ - Boolean algebra operations (simplification, negation)
101
+ - Semantic analysis (detect contradictions)
102
+ - Flexible CSS generation (different output for media vs. selectors)
103
+
104
+ ### Example
105
+
106
+ ```typescript
107
+ // Input
108
+ 'hovered & @media(w < 768px)'
109
+
110
+ // Output ConditionNode
111
+ {
112
+ kind: 'compound',
113
+ operator: 'AND',
114
+ children: [
115
+ { kind: 'state', type: 'modifier', attribute: 'data-hovered', ... },
116
+ { kind: 'state', type: 'media', subtype: 'dimension', upperBound: { value: '768px', ... }, ... }
117
+ ]
118
+ }
119
+ ```
120
+
121
+ ---
122
+
123
+ ## Stage 2: Build Exclusive Conditions
124
+
125
+ **File:** `exclusive.ts` (`buildExclusiveConditions`)
126
+
127
+ ### What It Does
128
+
129
+ Ensures each style entry applies in exactly one scenario by ANDing each condition with the negation of all higher-priority conditions.
130
+
131
+ ### How It Works
132
+
133
+ Given entries ordered by priority (highest first):
134
+ ```
135
+ A: value1 (priority 2)
136
+ B: value2 (priority 1)
137
+ C: value3 (priority 0)
138
+ ```
139
+
140
+ Produces:
141
+ ```
142
+ A: A (highest priority, no negation needed)
143
+ B: B & !A (applies only when A doesn't)
144
+ C: C & !A & !B (applies only when neither A nor B)
145
+ ```
146
+
147
+ Each exclusive condition is passed through `simplifyCondition`. Entries that simplify to `FALSE` (impossible) are filtered out. The default state (`''` → `TrueCondition`) is not added to the “prior” list for negation (see `buildExclusiveConditions`).
148
+
149
+ ### Why
150
+
151
+ This eliminates CSS specificity wars. Instead of relying on cascade order, each CSS rule matches in exactly one scenario. Benefits:
152
+ - Predictable styling regardless of rule order
153
+ - No conflicts from overlapping conditions
154
+ - Easier debugging (each rule is mutually exclusive)
155
+
156
+ ### Example
157
+
158
+ ```typescript
159
+ // Style value mapping
160
+ { padding: { '': '2x', 'compact': '1x', '@media(w < 768px)': '0.5x' } }
161
+
162
+ // After exclusive building (highest priority first):
163
+ // @media(w < 768px): applies when media matches
164
+ // compact & !@media(w < 768px): applies when compact but NOT media
165
+ // !compact & !@media(w < 768px): default, applies when neither
166
+ ```
167
+
168
+ ---
169
+
170
+ ## Stage 3: Expand At-Rule OR Branches
171
+
172
+ **File:** `exclusive.ts` (`expandExclusiveOrs`)
173
+
174
+ ### What It Does
175
+
176
+ Runs **after** `buildExclusiveConditions`. When an entry’s **exclusive** condition contains a top-level OR that mixes **at-rule** context (`media`, `container`, `supports`, `starting`) with other branches, those ORs are split into mutually exclusive branches so each branch keeps the correct at-rule wrapping (e.g. after De Morgan: `!(A & B)` → `!A | !B`).
177
+
178
+ ### How It Works
179
+
180
+ 1. Collect top-level OR branches of `exclusiveCondition`.
181
+ 2. If there is no OR, or **no** branch involves at-rule context, the entry is unchanged (pure selector ORs are handled later via `:is()` / variant merging in materialization).
182
+ 3. Otherwise, branches are sorted with `sortOrBranchesForExpansion` so at-rule-heavy branches come first, then each branch is made exclusive against prior branches: `branch & !prior[0] & !prior[1] & ...`, then simplified.
183
+ 4. Impossible branches are dropped; expanded entries get a synthetic `stateKey` suffix like `[or:0]`.
184
+
185
+ ### Why
186
+
187
+ Without this pass, a condition like `!(@supports & :has)` could produce one rule missing the `@supports` wrapper. Exclusive OR expansion ensures negated at-rule groups still nest modifiers correctly.
188
+
189
+ ### Example (conceptual)
190
+
191
+ See the comment block in `exclusive.ts` (~195–206): a default value’s exclusive condition can become `!@supports | !:has`; expansion yields one branch under `@supports (not …)` and another under `@supports (…) { :not(:has()) }` instead of a bare `:not(:has())` rule.
192
+
193
+ ---
194
+
195
+ ## Stage 4: Compute State Combinations
196
+
197
+ **File:** `index.ts` (`computeStateCombinations`)
198
+
199
+ ### What It Does
200
+
201
+ Computes the Cartesian product of all style entries for a handler, creating snapshots of which value each style has for each possible state combination.
202
+
203
+ ### How It Works
204
+
205
+ 1. Collect exclusive entries for each style the handler uses
206
+ 2. Compute Cartesian product: every combination of entries
207
+ 3. For each combination:
208
+ - AND all `exclusiveCondition` values together
209
+ - `simplifyCondition` the result
210
+ - Skip if simplified to `FALSE`
211
+ - Record the values for each style
212
+
213
+ ### Why
214
+
215
+ Style handlers often depend on multiple style properties (e.g., `padding` might look at both `padding` and `gap`). By computing all valid combinations, we can call the handler once per unique state and get the correct CSS output.
216
+
217
+ ### Example
218
+
219
+ ```typescript
220
+ // Handler looks up: ['padding', 'size']
221
+ // padding has entries: [{ value: '2x', condition: A }, { value: '1x', condition: B }]
222
+ // size has entries: [{ value: 'large', condition: C }, { value: 'small', condition: D }]
223
+
224
+ // Combinations:
225
+ // { padding: '2x', size: 'large', condition: A & C }
226
+ // { padding: '2x', size: 'small', condition: A & D }
227
+ // { padding: '1x', size: 'large', condition: B & C }
228
+ // { padding: '1x', size: 'small', condition: B & D }
229
+ ```
230
+
231
+ ---
232
+
233
+ ## Stage 5: Call Handlers
234
+
235
+ **File:** `index.ts` (within `processStyles`)
236
+
237
+ ### What It Does
238
+
239
+ Invokes style handlers with computed value snapshots to produce CSS declarations.
240
+
241
+ ### How It Works
242
+
243
+ 1. For each state snapshot (condition + values):
244
+ - Call the handler with the values
245
+ - Handler returns CSS properties (e.g., `{ 'padding-top': '16px', 'padding-bottom': '16px' }`)
246
+ - Handler may also return `$` (selector suffix) for pseudo-elements
247
+ 2. Create computed rules with the condition, declarations, and selector suffix
248
+
249
+ ### Why
250
+
251
+ Style handlers encapsulate the logic for translating design tokens (like `'2x'`) to actual CSS values (like `'16px'`). They can also handle complex multi-property styles (e.g., `padding` → `padding-top`, `padding-right`, etc.).
252
+
253
+ ---
254
+
255
+ ## Stage 6: Merge By Value
256
+
257
+ **File:** `index.ts` (`mergeByValue`)
258
+
259
+ ### What It Does
260
+
261
+ Combines rules that have identical CSS output into a single rule with an OR condition.
262
+
263
+ ### How It Works
264
+
265
+ 1. Group rules by `selectorSuffix` plus a stable string for declarations (JSON via an internal `declStringCache` `WeakMap` on declaration objects)
266
+ 2. For rules in the same group:
267
+ - Merge their conditions with OR
268
+ - `simplifyCondition` the resulting condition
269
+ 3. Output one rule per group
270
+
271
+ ### Why
272
+
273
+ Different state combinations might produce the same CSS output. Rather than emitting duplicate CSS, we combine them into a single rule. This reduces CSS size and improves performance.
274
+
275
+ ### Example
276
+
277
+ ```typescript
278
+ // Before merging:
279
+ // condition: A → { color: 'red' }
280
+ // condition: B → { color: 'red' }
281
+
282
+ // After merging:
283
+ // condition: A | B → { color: 'red' }
284
+ ```
285
+
286
+ ---
287
+
288
+ ## Stage 7: Materialize CSS
289
+
290
+ **File:** `materialize.ts` (`conditionToCSS`, `materializeComputedRule` in `index.ts`)
291
+
292
+ ### What It Does
293
+
294
+ Converts condition trees into actual CSS selectors and at-rules.
295
+
296
+ ### How It Works
297
+
298
+ 1. **Condition to CSS components** (`conditionToCSS`): Walk the condition tree and build `SelectorVariant` data:
299
+ - `ModifierCondition` → attribute selectors (e.g. `[data-hovered]`); optional `operator` (`=`, `^=`, `$=`, `*=`)
300
+ - `PseudoCondition` → pseudo-class (e.g. `:hover`)
301
+ - `MediaCondition` → `@media` (dimension, feature, or type)
302
+ - `ContainerCondition` → `@container` (dimension, style query, or raw)
303
+ - `RootCondition` → `rootGroups` / root prefix fragments
304
+ - `ParentCondition` → `parentGroups` / ancestor selectors (`direct` → child combinator path)
305
+ - `OwnCondition` → `ownGroups` on the **styled** element (sub-element / `&` scope), optimized with `optimizeGroups`
306
+ - `SupportsCondition` → `@supports` at-rules
307
+ - `StartingCondition` → `@starting-style` wrapper
308
+
309
+ 2. **AND / OR on variants**: AND merges variant dimensions; OR yields multiple variants (later merged into `:is()` / `:not()` groups where appropriate).
310
+
311
+ 3. **Contradiction detection**: During variant merging, impossible combinations are dropped (e.g. conflicting media, root, or modifier negations).
312
+
313
+ 4. **`materializeComputedRule`**: Groups variants by sorted at-rules plus root-prefix key; within each group, `mergeVariantsIntoSelectorGroups` merges variants that differ only in flat modifier/pseudo parts; builds selector strings and emits one or more `CSSRule` objects.
314
+
315
+ ### Why
316
+
317
+ CSS has different mechanisms for different condition types:
318
+ - Modifiers → attribute selectors
319
+ - Media queries → `@media` blocks
320
+ - Container queries → `@container` blocks
321
+ - Root state → `:root` / root groups
322
+ - Supports → `@supports` blocks
323
+
324
+ The materialization layer handles these differences while maintaining the logical semantics of the condition tree.
325
+
326
+ ### Output Structure
327
+
328
+ ```typescript
329
+ interface CSSRule {
330
+ selector: string | string[]; // Selector fragment(s); array when OR’d selector branches
331
+ declarations: string; // CSS declarations (e.g. 'color: red;')
332
+ atRules?: string[]; // Wrapping at-rules
333
+ rootPrefix?: string; // Root state prefix
334
+ }
335
+ ```
336
+
337
+ When `renderStylesPipeline` runs **without** a class name, returned rules include `needsClassName: true` (compatibility field for the injector); that flag is not part of `CSSRule` inside `materialize.ts`.
338
+
339
+ ---
340
+
341
+ ## Condition Types
342
+
343
+ **File:** `conditions.ts`
344
+
345
+ ### ConditionNode Hierarchy
346
+
347
+ ```
348
+ ConditionNode
349
+ ├── TrueCondition (matches everything)
350
+ ├── FalseCondition (matches nothing)
351
+ ├── CompoundCondition (AND/OR of children)
352
+ └── StateCondition
353
+ ├── ModifierCondition (data attributes; optional value + match operator)
354
+ ├── PseudoCondition (CSS pseudo-classes: :hover)
355
+ ├── MediaCondition (subtype: dimension | feature | type)
356
+ ├── ContainerCondition (subtype: dimension | style | raw)
357
+ ├── RootCondition (inner condition under :root)
358
+ ├── ParentCondition (@parent(...); optional direct parent)
359
+ ├── OwnCondition (@own(...); scoped to styled / sub-element)
360
+ ├── SupportsCondition (@supports(...))
361
+ └── StartingCondition (@starting-style wrapper)
362
+ ```
363
+
364
+ ### Key Operations
365
+
366
+ - `and(...conditions)`: Create AND with short-circuit and flattening
367
+ - `or(...conditions)`: Create OR with short-circuit and flattening
368
+ - `not(condition)`: Negate with De Morgan's law support
369
+ - `getConditionUniqueId(condition)`: Get canonical ID for comparison
370
+
371
+ ---
372
+
373
+ ## Simplification
374
+
375
+ **File:** `simplify.ts`
376
+
377
+ ### What It Does
378
+
379
+ Applies boolean algebra rules to reduce condition complexity and detect impossible combinations.
380
+
381
+ ### Rules Applied
382
+
383
+ 1. **Identity Laws**:
384
+ - `A & TRUE = A`
385
+ - `A | FALSE = A`
386
+
387
+ 2. **Annihilator Laws**:
388
+ - `A & FALSE = FALSE`
389
+ - `A | TRUE = TRUE`
390
+
391
+ 3. **Contradiction Detection**:
392
+ - `A & !A = FALSE`
393
+
394
+ 4. **Tautology Detection**:
395
+ - `A | !A = TRUE`
396
+
397
+ 5. **Idempotent Laws** (via deduplication):
398
+ - `A & A = A`
399
+ - `A | A = A`
400
+
401
+ 6. **Absorption Laws**:
402
+ - `A & (A | B) = A`
403
+ - `A | (A & B) = A`
404
+
405
+ 7. **Range intersection**: For **media and container** dimension queries, impossible ranges simplify to `FALSE` (e.g. `@media(w > 400px) & @media(w < 300px)`).
406
+
407
+ 8. **Container style queries**: Conflicting or redundant `@container` style conditions on the same property can be reduced (see `simplify.ts` around the container-style conflict pass).
408
+
409
+ 9. **Attribute conflict detection**:
410
+ - `[data-theme="dark"] & [data-theme="light"] = FALSE`
411
+
412
+ ### Why
413
+
414
+ Simplification reduces CSS output size and catches impossible combinations early, preventing invalid CSS rules from being generated.
415
+
416
+ ---
417
+
418
+ ## Caching Strategy
419
+
420
+ LRU and small auxiliary caches:
421
+
422
+ | Cache | Size | Key | Purpose |
423
+ |-------|------|-----|---------|
424
+ | `pipelineCache` | 5000 | `pipelineCacheKey \|\| stringifyStyles(styles)` | Skip full pipeline for identical styles |
425
+ | `parseCache` | 5000 | `trimmedStateKey + '\\0' + isSubElement + '\\0' + JSON.stringify(localPredefinedStates)` | Skip re-parsing identical state keys in context |
426
+ | `simplifyCache` | 5000 | `getConditionUniqueId(node)` | Skip re-simplifying identical conditions |
427
+ | `conditionCache` | 3000 | `getConditionUniqueId(node)` in `conditionToCSS` | Skip re-materializing identical conditions |
428
+ | `variantKeyCache` | — | `WeakMap<SelectorVariant, string>` | Stable string keys for variants during materialization |
429
+ | `declStringCache` | — | `WeakMap<Record<string,string>, string>` | Stable JSON keys for declaration objects in `mergeByValue` |
430
+
431
+ ---
432
+
433
+ ## Example Walkthrough
434
+
435
+ ### Input
436
+
437
+ ```typescript
438
+ const styles = {
439
+ color: {
440
+ '': '#white',
441
+ '@media(prefers-color-scheme: dark)': '#dark',
442
+ hovered: '#highlight',
443
+ },
444
+ };
445
+ ```
446
+
447
+ ### Stage 1: Parse Conditions
448
+
449
+ ```
450
+ '' → TrueCondition
451
+ '@media(prefers-color-scheme: dark)' → MediaCondition(subtype: 'feature', feature: 'prefers-color-scheme', featureValue: 'dark')
452
+ 'hovered' → ModifierCondition(attribute: 'data-hovered')
453
+ ```
454
+
455
+ ### Stages 2–3: Exclusive conditions + expand OR
456
+
457
+ Processing order (highest priority first): `hovered`, `@media(dark)`, default.
458
+
459
+ ```
460
+ hovered: [data-hovered]
461
+ @media(dark) & !hovered: @media(dark) & :not([data-hovered])
462
+ !hovered & !@media(dark): :not([data-hovered]) & not @media(dark)
463
+ ```
464
+
465
+ No at-rule OR expansion needed on these exclusives.
466
+
467
+ ### Stages 4–5: Compute combinations and call handler
468
+
469
+ Single style, three snapshots; the `color` handler emits `color` plus `--current-color*` variables.
470
+
471
+ ### Stage 6: Merge by value
472
+
473
+ Each snapshot yields distinct declarations; no merge.
474
+
475
+ ### Stage 7: Materialize CSS
476
+
477
+ Using `renderStyles(styles, '.t1')` (single class prefix; `renderStylesPipeline` doubles the class for specificity when a class name is supplied):
478
+
479
+ ```css
480
+ .t1[data-hovered] {
481
+ color: var(--highlight-color);
482
+ --current-color: var(--highlight-color);
483
+ --current-color-oklch: var(--highlight-color-oklch);
484
+ }
485
+ @media (prefers-color-scheme: dark) {
486
+ .t1:not([data-hovered]) {
487
+ color: var(--dark-color);
488
+ --current-color: var(--dark-color);
489
+ --current-color-oklch: var(--dark-color-oklch);
490
+ }
491
+ }
492
+ @media (not (prefers-color-scheme: dark)) {
493
+ .t1:not([data-hovered]) {
494
+ color: var(--white-color);
495
+ --current-color: var(--white-color);
496
+ --current-color-oklch: var(--white-color-oklch);
497
+ }
498
+ }
499
+ ```
500
+
501
+ ---
502
+
503
+ ## Key Design Decisions
504
+
505
+ ### 1. Exclusive Conditions Over CSS Specificity
506
+
507
+ Rather than relying on CSS cascade rules, we generate mutually exclusive selectors. This makes styling predictable and debuggable.
508
+
509
+ ### 2. OR Handling: DNF, `:is()`, and `expandExclusiveOrs`
510
+
511
+ OR of conditions is ultimately expressed as DNF (OR of ANDs) for CSS—comma-separated selectors, multiple rules, or `:is()` / `:not()` groups. **User-authored** ORs on pure selector conditions are handled in materialization. **`expandExclusiveOrs`** is an additional, **post-exclusive** pass for ORs that appear on **exclusive** conditions and involve **at-rule** branches (often from De Morgan on `@supports` / `@media` / `@container` / `@starting`), so each branch keeps correct at-rule nesting.
512
+
513
+ ### 3. Early Contradiction Detection
514
+
515
+ Impossible combinations are detected at multiple levels (simplification, variant merging) to avoid generating invalid CSS.
516
+
517
+ ### 4. Aggressive Caching
518
+
519
+ Parse, simplify, condition-to-CSS, and full-pipeline results are cached independently, enabling fast re-rendering when only parts of the style object change.
package/docs/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Tasty Docs
2
+
3
+ Use this page when you know what you want to do, but not which document to open next.
4
+
5
+ ## Start Here
6
+
7
+ - **New to Tasty**: [Getting Started](getting-started.md) for installation, the first component, optional shared `configure()`, ESLint, editor tooling, and rendering mode selection.
8
+ - **Learning the component model**: [Methodology](methodology.md) for root + sub-elements, `styleProps`, tokens, extension, and recommended boundaries between `styles`, `style`, and wrappers.
9
+ - **Evaluating fit**: [Comparison](comparison.md) for tool-selection context, then [Adoption Guide](adoption.md) for rollout strategy inside a design system.
10
+
11
+ ## By Role
12
+
13
+ - **Application developer using an existing design system**: [Getting Started](getting-started.md), then [Runtime API](runtime.md).
14
+ - **Design-system author**: [Methodology](methodology.md), [Building a Design System](design-system.md), [Configuration](configuration.md), and [Adoption Guide](adoption.md).
15
+ - **Platform or tooling engineer**: [Configuration](configuration.md), [Zero Runtime (tastyStatic)](tasty-static.md), [Server-Side Rendering](ssr.md), and [Debug Utilities](debug.md).
16
+
17
+ ## By Rendering Mode
18
+
19
+ - **Runtime React components**: [Runtime API](runtime.md)
20
+ - **Zero-runtime / build-time extraction**: [Zero Runtime (tastyStatic)](tasty-static.md)
21
+ - **SSR with runtime `tasty()`**: [Server-Side Rendering](ssr.md)
22
+
23
+ ## By Task
24
+
25
+ - **Learn the style language**: [Style DSL](dsl.md)
26
+ - **Look up a property handler**: [Style Properties](styles.md)
27
+ - **Define tokens, units, recipes, keyframes, or properties globally**: [Configuration](configuration.md)
28
+ - **Debug generated CSS or cache behavior**: [Debug Utilities](debug.md)
29
+ - **Understand how selector generation works internally**: [Style rendering pipeline](PIPELINE.md)
30
+ - **Understand runtime injection internals**: [Style Injector](injector.md)
package/docs/adoption.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Tasty is not a drop-in replacement for another styling library. It is a **substrate for building a design-system-defined styling language**. That means the adoption path is not "rewrite your classes" but "reshape your styling architecture."
4
4
 
5
- This guide is for design-system maintainers and platform engineers evaluating Tasty or introducing it into an existing codebase.
5
+ This guide is for design-system maintainers and platform engineers evaluating Tasty or introducing it into an existing codebase. Use this document for rollout strategy and adoption sequencing; use the [Comparison guide](comparison.md) when the open question is whether Tasty is the right tool in the first place.
6
6
 
7
7
  ---
8
8
 
@@ -74,7 +74,7 @@ The same engine can power a minimal design system with a handful of tokens:
74
74
  ```tsx
75
75
  configure({
76
76
  tokens: { '#bg': '#white', '#text': '#111' },
77
- states: { '@dark': '@root(theme=dark)' },
77
+ states: { '@dark': '@root(schema=dark)' },
78
78
  });
79
79
  ```
80
80
 
@@ -272,6 +272,14 @@ const LoadingButton = tasty(Button, {
272
272
 
273
273
  ---
274
274
 
275
+ ## Migration and Interop Notes
276
+
277
+ - **From Tailwind**: keep utility-authored product surfaces as-is at first, and use Tasty to build or replace the design-system primitives underneath them instead of forcing an all-at-once markup rewrite.
278
+ - **From CSS-in-JS libraries**: start with shared primitives such as `Box`, `Text`, and `Button`, preserve the external component API, and move state logic into Tasty state maps so behavior changes without product-code churn.
279
+ - **From CSS Modules or plain CSS**: migrate token definitions and repeated patterns first, then wrap existing DOM structure with `tasty()` components gradually rather than converting every stylesheet at once.
280
+
281
+ ---
282
+
275
283
  ## Learn more
276
284
 
277
285
  - [README](../README.md) -- overview, quick start, and feature highlights
@@ -1,6 +1,8 @@
1
1
  # Comparison
2
2
 
3
- Tasty is best understood not as a general-purpose CSS framework, but as a **styling engine for design systems**.
3
+ Use this guide when you are deciding whether Tasty is the right tool. If you have already decided to adopt it and need rollout guidance, use the [Adoption Guide](adoption.md) instead.
4
+
5
+ Tasty is best understood not as a general-purpose CSS framework, but as a **styling engine for design systems and shared component APIs**.
4
6
 
5
7
  Most styling tools focus on one of these layers:
6
8
 
@@ -10,7 +12,9 @@ Most styling tools focus on one of these layers:
10
12
  - utility composition
11
13
  - atomic CSS generation
12
14
 
13
- Tasty targets a different layer: it helps design-system authors define a **house styling language** on top of CSS, including tokens, state semantics, style props, recipes, custom units, and sub-element rules.
15
+ Tasty targets a different layer: it helps teams define a **house styling language** on top of CSS, including tokens, state semantics, style props, recipes, custom units, and sub-element rules.
16
+
17
+ That does not mean a big upfront configuration step is required. Tasty's built-in units and normal CSS color values work out of the box, and `okhsl(...)` is available immediately as the recommended path for color authoring. The extra setup comes later if a team wants shared tokens, aliases, recipes, or stricter conventions.
14
18
 
15
19
  That is why syntax-level comparisons are often shallow. The more meaningful comparison is about:
16
20
 
@@ -25,7 +29,7 @@ That is why syntax-level comparisons are often shallow. The more meaningful comp
25
29
 
26
30
  | System | Best described as | Main authoring model | Conflict model | Best fit |
27
31
  |---|---|---|---|---|
28
- | **Tasty** | Design-system styling engine | Custom DSL with tokens, state maps, recipes, style props, sub-elements, custom units | **Mutually exclusive selector resolution** for stateful styles | DS/platform teams defining a house styling language |
32
+ | **Tasty** | Design-system styling engine | Custom DSL with tokens, state maps, recipes, style props, sub-elements, custom units | **Mutually exclusive selector resolution** for stateful styles | Teams building shared component APIs or a house styling language |
29
33
  | **Tailwind CSS** | Utility-first styling framework | Utility classes in markup | Utility composition, variants, and framework-controlled ordering | Product teams optimizing for speed and direct authoring |
30
34
  | **Panda CSS** | Typed styling engine with atomic output | Typed style objects, recipes, generated primitives, style props | Atomic CSS with static analysis | Teams wanting a DS-friendly engine with typed primitives |
31
35
  | **vanilla-extract** | Zero-runtime TS-native stylesheet system | `.css.ts` files, theme contracts, style composition | Standard CSS semantics | Teams wanting static CSS and low-level control |
@@ -103,7 +107,7 @@ Its strength is speed: developers compose utilities directly where they use them
103
107
 
104
108
  Tasty solves a different problem.
105
109
 
106
- Tasty is more appropriate when styling should be exposed through a **design-system-owned API** rather than through raw utility composition. Instead of asking every product engineer to compose the styling vocabulary directly, Tasty makes more sense when a design-system team wants to define:
110
+ Tasty is more appropriate when styling should be exposed through a **design-system-owned API** rather than through raw utility composition. You can start using Tasty immediately with its built-in DSL, but it becomes especially compelling when a team wants to define:
107
111
 
108
112
  - approved style props
109
113
  - semantic tokens
@@ -118,7 +122,7 @@ So this is not mainly a comparison of syntax. It is a comparison of **governance
118
122
  - Tailwind: developers author directly with framework vocabulary
119
123
  - Tasty: design-system authors define the vocabulary product teams consume
120
124
 
121
- Tailwind is usually a stronger fit for fast product styling. Tasty is usually a stronger fit for governed design-system architecture.
125
+ Tailwind is usually a stronger fit for fast product styling with framework-owned vocabulary. Tasty is usually a stronger fit when teams want direct usability now, but also a path toward governed design-system architecture.
122
126
 
123
127
  To make this concrete, consider a button with `hover`, `disabled`, and `theme=danger` states.
124
128
 
@@ -356,6 +360,7 @@ That is why generic "feature matrix" comparisons often miss the point. Tasty is
356
360
  Tasty makes the most sense when:
357
361
 
358
362
  - a real design system exists or is being built
363
+ - a shared component API is emerging even if the design system is still lightweight
359
364
  - styling should be governed through a central platform team
360
365
  - component state logic is complex
361
366
  - the team wants a house styling language instead of raw CSS-shaped authoring
@@ -369,7 +374,7 @@ Tasty makes the most sense when:
369
374
 
370
375
  A different tool may be more appropriate when:
371
376
 
372
- - the main goal is styling app code directly with minimal setup
377
+ - the main goal is styling app code directly with minimal setup and without defining shared styling conventions
373
378
  - the team prefers a shared framework vocabulary over a custom design-system language
374
379
  - the complexity of intersecting states is low
375
380
  - low ceremony matters more than central governance