@tenphi/tasty 0.0.0-snapshot.dffd134 → 0.0.0-snapshot.e01a0ee
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/README.md +436 -394
- package/dist/babel-types-BKDTT4--.d.ts +18 -0
- package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
- package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
- package/dist/chunks/build-config-DlxpZKk_.js +60 -0
- package/dist/chunks/build-config-DlxpZKk_.js.map +1 -0
- package/dist/{collector-UWhVKseF.js → chunks/collector-B4-yqFEs.js} +25 -119
- package/dist/chunks/collector-B4-yqFEs.js.map +1 -0
- package/dist/chunks/config-engine-DJsb5WYu.js +272 -0
- package/dist/chunks/config-engine-DJsb5WYu.js.map +1 -0
- package/dist/chunks/config-file-DlZXJMj8.js +25 -0
- package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
- package/dist/chunks/css-definitions-DW1TGGiy.js +910 -0
- package/dist/chunks/css-definitions-DW1TGGiy.js.map +1 -0
- package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
- package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
- package/dist/chunks/debug-DMMwe1rY.js +502 -0
- package/dist/chunks/debug-DMMwe1rY.js.map +1 -0
- package/dist/chunks/dsl-DYSJc1-T.js +1383 -0
- package/dist/chunks/dsl-DYSJc1-T.js.map +1 -0
- package/dist/chunks/hydration-TRcz5vnk.js +41 -0
- package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
- package/dist/chunks/react-runtime-DhPtFlZs.js +689 -0
- package/dist/chunks/react-runtime-DhPtFlZs.js.map +1 -0
- package/dist/chunks/runtime-engine-BlrVXv8l.js +2432 -0
- package/dist/chunks/runtime-engine-BlrVXv8l.js.map +1 -0
- package/dist/chunks/runtime-state-BLyMRYFF.js +152 -0
- package/dist/chunks/runtime-state-BLyMRYFF.js.map +1 -0
- package/dist/{merge-styles-CVCZ4hgD.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
- package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
- package/dist/chunks/style-engine-of5Xbc27.js +5571 -0
- package/dist/chunks/style-engine-of5Xbc27.js.map +1 -0
- package/dist/{css-writer-DEkJuPH6.js → chunks/zero-engine-D2jPSpWA.js} +65 -145
- package/dist/chunks/zero-engine-D2jPSpWA.js.map +1 -0
- package/dist/{collector-BPzZezAG.d.ts → collector-CTU-nl0g.d.ts} +23 -4
- package/dist/{config-D2INrjr_.d.ts → config-CcxqSZI2.d.ts} +274 -78
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/hydrate-CRyjjAyl.d.ts +22 -0
- package/dist/{index-BAAbdfRs.d.ts → index--GdqCPlp.d.ts} +366 -257
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -867
- package/dist/{merge-styles-NEvqayL_.d.ts → merge-styles-DSkVc6CD.d.ts} +2 -3
- package/dist/ssr/astro-client.d.ts +1 -1
- package/dist/ssr/astro-client.js +1 -14
- package/dist/ssr/astro-client.js.map +1 -1
- package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract-static.js +9 -0
- package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
- package/dist/ssr/astro-middleware-extract.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract.js +9 -0
- package/dist/ssr/astro-middleware-extract.js.map +1 -0
- package/dist/ssr/astro-middleware-static.d.ts +3 -2
- package/dist/ssr/astro-middleware-static.js +0 -11
- package/dist/ssr/astro-middleware-static.js.map +1 -1
- package/dist/ssr/astro-middleware.d.ts +3 -2
- package/dist/ssr/astro-middleware.js +0 -12
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +40 -6
- package/dist/ssr/astro.js +157 -93
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +2 -0
- package/dist/ssr/index.d.ts +5 -25
- package/dist/ssr/index.js +5 -5
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +64 -0
- package/dist/ssr/next-config.js +123 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -8
- package/dist/ssr/next.js +29 -43
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +8 -9
- package/dist/static/index.js +4 -22
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.d.ts +1 -2
- package/dist/{index-l_NdJSUS.d.ts → types-DJEM_BOJ.d.ts} +751 -590
- package/dist/zero/babel.d.ts +67 -2
- package/dist/zero/babel.js +77 -140
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +62 -8
- package/dist/zero/index.js +24 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +4 -5
- package/dist/zero/next.js +3 -38
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +16 -8
- package/docs/adoption.md +69 -36
- package/docs/ai-agents.md +122 -85
- package/docs/comparison.md +77 -47
- package/docs/configuration.md +435 -108
- package/docs/debug.md +21 -8
- package/docs/design-system.md +152 -31
- package/docs/dsl.md +497 -211
- package/docs/getting-started.md +130 -50
- package/docs/injector.md +117 -68
- package/docs/methodology.md +81 -50
- package/docs/migration-v3.md +52 -52
- package/docs/pipeline.md +55 -31
- package/docs/plugins.md +59 -75
- package/docs/react-api.md +139 -53
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +285 -101
- package/docs/styles.md +128 -33
- package/docs/tasty-static.md +272 -135
- package/package.json +119 -39
- package/dist/async-storage-DKK-wTD4.js +0 -44
- package/dist/async-storage-DKK-wTD4.js.map +0 -1
- package/dist/babel-HlEpSZrj.d.ts +0 -83
- package/dist/collector-UWhVKseF.js.map +0 -1
- package/dist/config-BCuFlC1I.js +0 -12180
- package/dist/config-BCuFlC1I.js.map +0 -1
- package/dist/context-CA8YKeMn.js +0 -24
- package/dist/context-CA8YKeMn.js.map +0 -1
- package/dist/core-CbMYIizf.js +0 -1550
- package/dist/core-CbMYIizf.js.map +0 -1
- package/dist/css-writer-DEkJuPH6.js.map +0 -1
- package/dist/format-global-rules-DklyaXv-.js +0 -22
- package/dist/format-global-rules-DklyaXv-.js.map +0 -1
- package/dist/format-rules-D2J4PbR5.js +0 -143
- package/dist/format-rules-D2J4PbR5.js.map +0 -1
- package/dist/hydrate-lZeNoz_w.js +0 -37
- package/dist/hydrate-lZeNoz_w.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-BUMyAa-Q.js +0 -424
- package/dist/keyframes-BUMyAa-Q.js.map +0 -1
- package/dist/merge-styles-CVCZ4hgD.js.map +0 -1
- package/dist/resolve-recipes-BnMC1WW1.js +0 -144
- package/dist/resolve-recipes-BnMC1WW1.js.map +0 -1
package/docs/pipeline.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
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
4
|
|
|
5
|
-
**Implementation:** [`src/pipeline/`](
|
|
5
|
+
**Implementation:** [`src/pipeline/`](https://github.com/tenphi/tasty/tree/main/src/pipeline) — TypeScript file names below are relative to that directory.
|
|
6
6
|
|
|
7
7
|
## Overview
|
|
8
8
|
|
|
@@ -76,7 +76,7 @@ Output: CSSRule[]
|
|
|
76
76
|
|
|
77
77
|
**Simplification** (`simplifyCondition` in `simplify.ts`) is not a separate numbered stage. It runs inside OR expansion, exclusive building, `expandExclusiveOrs` branch cleanup, combination ANDs, merge-by-value ORs, and materialization. Every call is cached by condition unique-id, so the repetition is cheap.
|
|
78
78
|
|
|
79
|
-
**Post-pass:** After `processStyles` collects rules from every handler, `runPipeline` (`index.ts`) filters duplicates using a key of `selector|declarations|atRules|rootPrefix|startingStyle`, then **stable-sorts rules by their cascade `order` hint (ascending source priority)** so lower-priority rules come first and higher-priority rules win, and finally emits every `@starting-style` rule **after** all normal rules.
|
|
79
|
+
**Post-pass:** After `processStyles` collects rules from every handler, `runPipeline` (`index.ts`) filters duplicates using a key of `selector|declarations|atRules|rootPrefix|startingStyle`, then **stable-sorts rules by their cascade `order` hint (ascending source priority)** so lower-priority rules come first and higher-priority rules win, and finally emits every `@starting-style` rule **after** all normal rules. Each Stage 4 snapshot takes the highest source priority among its entries as its `order` hint; when Stage 6 merges same-output rules, the merged rule keeps the lowest `order` of its group, so a rule carrying the `_` floor's value keeps the floor's early position (threaded `ComputedRule → CSSRule`). This ordering is cascade-critical because Stage 7 equalizes specificity with `:where()`: once every state selector carries zero specificity, source order alone decides which of two overlapping rules wins — most importantly the `_` fallback floor (low order, emitted first) versus the states layered over it, and `@starting-style` versus its normal counterpart. Mutually-exclusive rules are unaffected by ordering (they never both match), so reordering them is safe.
|
|
80
80
|
|
|
81
81
|
---
|
|
82
82
|
|
|
@@ -86,18 +86,22 @@ Output: CSSRule[]
|
|
|
86
86
|
|
|
87
87
|
### What It Does
|
|
88
88
|
|
|
89
|
-
Runs on each style's value map **before** any parsing
|
|
89
|
+
Runs on each style's value map **before** any parsing, when the map has at least three keys and one of them uses `&`. An atom is a **don't-care** when flipping it never changes which value the map resolves to; every key that mentions a don't-care atom is dropped.
|
|
90
90
|
|
|
91
91
|
### How It Works
|
|
92
92
|
|
|
93
|
-
1.
|
|
94
|
-
2.
|
|
95
|
-
3.
|
|
96
|
-
4. Drop
|
|
93
|
+
1. Split each key into its top-level `&` atoms. Keys containing `|`, `^`, or `,` at top level are a single opaque atom. The `_` floor (and a misused `_` key) is kept verbatim and left out of the analysis.
|
|
94
|
+
2. Treat the map as the cascade it is: the last authored key whose atoms all hold wins, and `''` is always the lowest priority.
|
|
95
|
+
3. An atom is a don't-care when, in every state, the cascade resolves to the same value with the atom present as with it absent. Only the states `(K₁ minus the atom) ∪ K₀`, for every key `K₁` that contains the atom and every key `K₀` that does not (or none), can tell the two apart, so the check is quadratic in the number of keys rather than exponential in atoms.
|
|
96
|
+
4. Drop every key that contains a don't-care atom. With the atom forced absent those keys never match, and by definition the result is unchanged.
|
|
97
|
+
|
|
98
|
+
The check is over the cascade, not over pairs of keys. In `{ '': A, checked: B, 'invalid & checked': C, disabled: A }`, `disabled` has the default's value, but it outranks `checked`: a checked, disabled element gets `A`, so `disabled` is not a don't-care. (An earlier pairwise rule — "every key with the atom has a same-value partner without it" — folded `disabled` into `''` here and lost that priority.)
|
|
99
|
+
|
|
100
|
+
Atoms are compared as strings and treated as independent. Real atoms can be related (`theme=dark` vs `theme=light`, nested media ranges); that only rules states out, so a don't-care over independent atoms is one for every real state too. Two guards keep the rewrite safe: a map with more than 32 distinct atoms is left unreduced, and a reduction that would leave the `_` floor alone with `''` (which means "use the floor", see Stage 1) is skipped.
|
|
97
101
|
|
|
98
102
|
### Why
|
|
99
103
|
|
|
100
|
-
Removing don't-care dimensions before parsing prevents combinatorial blowup in later stages. `mergeEntriesByValue`, `buildExclusiveConditions`, and materialization all see fewer entries and fewer spurious conditions.
|
|
104
|
+
Removing don't-care dimensions before parsing prevents combinatorial blowup in later stages. `mergeEntriesByValue`, `buildExclusiveConditions`, and materialization all see fewer entries and fewer spurious conditions.
|
|
101
105
|
|
|
102
106
|
### Example
|
|
103
107
|
|
|
@@ -193,10 +197,14 @@ Merging two same-value entries with conditions `C_h` (higher priority) and `C_l`
|
|
|
193
197
|
|
|
194
198
|
The merge is safe iff for every entry `e_m` strictly between them in priority with a different value,
|
|
195
199
|
|
|
196
|
-
|
|
200
|
+
```
|
|
201
|
+
simplify(C_m & C_l & !C_h) = FALSE
|
|
202
|
+
```
|
|
197
203
|
|
|
198
204
|
i.e. there is no scenario where the intermediate state could have matched, the lower same-value entry would also have matched, and the higher one would not. This is the only way the merge could leak through and shadow the intermediate state.
|
|
199
205
|
|
|
206
|
+
An intermediate whose condition always holds (a tautological key, or same-value keys that already merged into one, like `beta | !beta`) is checked like any other. Only the `''` default and the `_` floor are exempt from the check, and they are always the lowest priorities, so they are never intermediates.
|
|
207
|
+
|
|
200
208
|
### Why
|
|
201
209
|
|
|
202
210
|
Without this pass a value map like `{ '@dark': 'red', '@dark & @hc': 'red' }` would create two separate entries that later produce two CSS rules with identical output. Merging before exclusive building keeps the exclusive condition algebra small and avoids duplicate CSS. The safety check ensures we never break the cascade in service of this optimization.
|
|
@@ -293,7 +301,9 @@ B: B & !A (applies only when A doesn't)
|
|
|
293
301
|
C: C & !A & !B (applies only when neither A nor B)
|
|
294
302
|
```
|
|
295
303
|
|
|
296
|
-
Each exclusive condition is passed through `simplifyCondition`. Entries that simplify to `FALSE` (impossible) are filtered out.
|
|
304
|
+
Each exclusive condition is passed through `simplifyCondition`. Entries that simplify to `FALSE` (impossible) are filtered out.
|
|
305
|
+
|
|
306
|
+
Every entry is added to the "prior" list, including one whose condition is `TRUE`. That can be a tautological key, or same-value keys that merged into one in Stage 1b (`alpha: X, '!alpha': X` → `TRUE`). Such an entry always applies at its priority, so negating it correctly makes every lower entry `FALSE`. The bare `''` default is `TRUE` too, but it is always the lowest priority, so no entry comes after it.
|
|
297
307
|
|
|
298
308
|
### `_` fallback floor
|
|
299
309
|
|
|
@@ -354,7 +364,7 @@ This is the companion to **Stage 2a** (user-OR expansion). The split exists beca
|
|
|
354
364
|
|
|
355
365
|
| Stage | Runs on | Sees ORs from | Sorts branches? |
|
|
356
366
|
|---|---|---|---|
|
|
357
|
-
| 2a `expandOrConditions` | `ParsedStyleEntry.condition` | User-authored
|
|
367
|
+
| 2a `expandOrConditions` | `ParsedStyleEntry.condition` | User-authored `\|` in state keys | No — user order is stable |
|
|
358
368
|
| 3 `expandExclusiveOrs` | `ExclusiveStyleEntry.exclusiveCondition` | De Morgan negation inside `buildExclusiveConditions` | Yes — at-rule branches first |
|
|
359
369
|
|
|
360
370
|
### How It Works
|
|
@@ -383,7 +393,7 @@ The pre-build Stage 2a pass doesn't need this because user-authored ORs aren't p
|
|
|
383
393
|
|
|
384
394
|
### Example (conceptual)
|
|
385
395
|
|
|
386
|
-
See the comment block in `exclusive.ts
|
|
396
|
+
See the comment block on `expandExclusiveOrs` in `exclusive.ts`: a default value whose higher-priority sibling is `@supports(...) & :has(...)` gets an exclusive of `!@supports | !:has`. Expansion yields one branch under `@supports (not ...)` and another under `@supports (...) { :not(:has()) }` instead of a bare `:not(:has())` rule.
|
|
387
397
|
|
|
388
398
|
---
|
|
389
399
|
|
|
@@ -395,6 +405,8 @@ See the comment block in `exclusive.ts:500-523`: a default value whose higher-pr
|
|
|
395
405
|
|
|
396
406
|
Computes the Cartesian product of all style entries for a handler, creating snapshots of which value each style has for each possible state combination.
|
|
397
407
|
|
|
408
|
+
When every input is a direct value rather than a state map, the pipeline skips stages 0–4 and passes one unconditional snapshot directly to the handler. This avoids building exclusive entries and a Cartesian product for ordinary state-free styles.
|
|
409
|
+
|
|
398
410
|
### How It Works
|
|
399
411
|
|
|
400
412
|
1. Collect exclusive entries for each style the handler uses
|
|
@@ -454,6 +466,7 @@ Style handlers encapsulate the logic for translating design tokens (like `'2x'`)
|
|
|
454
466
|
### What It Does
|
|
455
467
|
|
|
456
468
|
Combines rules that have identical CSS output into a single rule with an OR condition.
|
|
469
|
+
Zero- and one-rule inputs return unchanged because no merge is possible.
|
|
457
470
|
|
|
458
471
|
### How It Works
|
|
459
472
|
|
|
@@ -509,9 +522,9 @@ Converts condition trees into actual CSS selectors and at-rules.
|
|
|
509
522
|
|
|
510
523
|
5. **`:where()` specificity equalization**: Every stateful part of the selector is wrapped in `:where(...)` so it contributes **zero specificity**:
|
|
511
524
|
- the flat root modifiers + pseudos and the root element's `:is()`/`:not()` groups are combined into one `:where(...)` (`buildSelectorFromVariant`);
|
|
512
|
-
- the sub-element (`@own`) groups are wrapped in a **separate** `:where(...)` so the sub-element's structural `[data-element="X"]` specificity is preserved while its states are zeroed;
|
|
525
|
+
- the sub-element (`@own`) groups are wrapped in a **separate** `:where(...)` so the sub-element's structural `[data-element="X"]` specificity is preserved while its states are zeroed. When the suffix ends in a pseudo-element, these are the pseudo-element's own states and stay after it (`a::before:where(:hover)`). States a pseudo-element can't have (attributes, modifiers, classes, tree-structural pseudo-classes) are dropped with a `PSEUDO_ELEMENT_STATE_IGNORED` warning before Stage 0, using the CSS language alone, never per-browser support (`pseudo-element-states.ts`). A direct selector that ends in a pseudo-element (`.card::before`) is rendered separately: its root states are checked the same way and go after the pseudo-element, its `@parent` segments before it, at the `pseudoElementAt` each `CSSRule` records;
|
|
513
526
|
- `@parent` ancestors (`parentGroupsToCSS`) become `:where(... *)` / `:where(:not(... *))`;
|
|
514
|
-
- the `@root` context prefix (`
|
|
527
|
+
- the `@root` context prefix (`rootStateToPrefix`) becomes `:where(:root...)` (zeroing the `:root` pseudo too). When a direct selector can only match the root itself (`:root`, `html`, `:where(:root)`), the state segment joins it instead — `:root:where([data-schema="dark"])` — since an ancestor prefix would ask for a `:root` inside the root.
|
|
515
528
|
|
|
516
529
|
The only specificity anchors that remain are the doubled component class (`.tXX.tXX`, added by the injector) and sub-element `[data-element]` attributes. Because Stage 2b already makes ordinary rules mutually exclusive, zeroing specificity never changes *which* rule matches — it only makes additive layering (`_` fallback floor, `@starting-style`) resolve deterministically by source order (see the post-pass). Canonical sorting/dedup/subsumption still run first; `:where()` is only the final wrapper, and both output paths (injector and direct-selector / SSR) consume the same wrapped fragments.
|
|
517
530
|
|
|
@@ -534,12 +547,13 @@ interface CSSRule {
|
|
|
534
547
|
declarations: string; // CSS declarations (e.g. 'color: red;')
|
|
535
548
|
atRules?: string[]; // Wrapping at-rules
|
|
536
549
|
rootPrefix?: string; // Root state prefix
|
|
550
|
+
rootState?: string; // Root-state segment without its :root anchor; lets a root selector take states directly
|
|
537
551
|
startingStyle?: boolean; // Wrap declarations in @starting-style
|
|
538
552
|
order?: number; // Internal cascade order hint (ascending source priority); stripped before injection
|
|
539
553
|
}
|
|
540
554
|
```
|
|
541
555
|
|
|
542
|
-
When `renderStyles` runs **without** a selector, returned rules include `needsClassName: true` (compatibility field for the injector); that flag is not part of `CSSRule`
|
|
556
|
+
When `renderStyles` runs **without** a selector, returned rules include `needsClassName: true` (compatibility field for the injector); that flag is not part of `CSSRule` (defined in `materialize-types.ts`).
|
|
543
557
|
|
|
544
558
|
---
|
|
545
559
|
|
|
@@ -607,7 +621,7 @@ Applies boolean algebra rules to reduce condition complexity and detect impossib
|
|
|
607
621
|
- `A & (A | B) = A`
|
|
608
622
|
- `A | (A & B) = A`
|
|
609
623
|
|
|
610
|
-
7. **Range intersection**: For **media and container** dimension queries, impossible ranges simplify to `FALSE` (e.g. `@media(w > 400px) & @media(w < 300px)`). Ranges with compatible bounds are also merged in place (`w >= 400 & w <= 800` → a single bounded range).
|
|
624
|
+
7. **Range intersection**: For **media and container** dimension queries, impossible ranges simplify to `FALSE` (e.g. `@media(w > 400px) & @media(w < 300px)`). Ranges with compatible bounds are also merged in place (`w >= 400 & w <= 800` → a single bounded range). Only bounds in the same unit are compared: `600px` and `40em` are never merged or found contradictory, because a query `em` follows the user's default font size. A bound with no numeric value (`calc(…)`) and a range whose two bounds use different units are left as they are.
|
|
611
625
|
|
|
612
626
|
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).
|
|
613
627
|
|
|
@@ -631,7 +645,7 @@ LRU and small auxiliary caches:
|
|
|
631
645
|
| Cache | Size | Key | Purpose |
|
|
632
646
|
|-------|------|-----|---------|
|
|
633
647
|
| `pipelineCache` | 5000 | `pipelineCacheKey \|\| stringifyStyles(styles)` | Skip full pipeline for identical styles |
|
|
634
|
-
| `parseCache` | 5000 | `trimmedStateKey + '
|
|
648
|
+
| `parseCache` | 5000 | `trimmedStateKey + '\0' + (isSubElement ? '1' : '0') + '\0' + (localPredefinedStates non-empty ? JSON.stringify(localPredefinedStates) : '')` | Skip re-parsing identical state keys in context |
|
|
635
649
|
| `simplifyCache` | 5000 | `getConditionUniqueId(node)` | Skip re-simplifying identical conditions |
|
|
636
650
|
| `conditionCache` | 3000 | `getConditionUniqueId(node)` in `conditionToCSS` | Skip re-materializing identical conditions |
|
|
637
651
|
| `variantKeyCache` | — | `WeakMap<SelectorVariant, string>` | Stable string keys for variants during materialization |
|
|
@@ -683,7 +697,7 @@ The default entry's exclusive is `!hovered & !@media(dark)` — no top-level OR,
|
|
|
683
697
|
|
|
684
698
|
### Stages 4–5: Compute combinations and call handler
|
|
685
699
|
|
|
686
|
-
Single style, three snapshots; the `color` handler emits `color` plus `--current-color
|
|
700
|
+
Single style, three snapshots; the `color` handler emits `color` plus a `--current-color` variable.
|
|
687
701
|
|
|
688
702
|
### Stage 6: Merge by value
|
|
689
703
|
|
|
@@ -691,27 +705,24 @@ Each snapshot yields distinct declarations; no merge.
|
|
|
691
705
|
|
|
692
706
|
### Stage 7: Materialize CSS
|
|
693
707
|
|
|
694
|
-
Using `renderStyles(styles, '.t1')
|
|
708
|
+
Using `renderStyles(styles, '.t1', { doubleSelector: true })`. The injector doubles the class the same way (`.t1.t1`) so Tasty owns specificity without `!important`, and every state is wrapped in `:where()` so it adds none. Rules come out in ascending priority:
|
|
695
709
|
|
|
696
710
|
```css
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
711
|
+
@media (not (prefers-color-scheme: dark)) {
|
|
712
|
+
.t1.t1:where(:not([data-hovered])) {
|
|
713
|
+
color: var(--white-color);
|
|
714
|
+
--current-color: var(--white-color);
|
|
715
|
+
}
|
|
701
716
|
}
|
|
702
717
|
@media (prefers-color-scheme: dark) {
|
|
703
|
-
.t1:not([data-hovered]) {
|
|
718
|
+
.t1.t1:where(:not([data-hovered])) {
|
|
704
719
|
color: var(--dark-color);
|
|
705
720
|
--current-color: var(--dark-color);
|
|
706
|
-
--current-color-oklch: var(--dark-color-oklch);
|
|
707
721
|
}
|
|
708
722
|
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
--current-color: var(--white-color);
|
|
713
|
-
--current-color-oklch: var(--white-color-oklch);
|
|
714
|
-
}
|
|
723
|
+
.t1.t1:where([data-hovered]) {
|
|
724
|
+
color: var(--highlight-color);
|
|
725
|
+
--current-color: var(--highlight-color);
|
|
715
726
|
}
|
|
716
727
|
```
|
|
717
728
|
|
|
@@ -742,3 +753,16 @@ Impossible combinations are detected at multiple levels (simplification, variant
|
|
|
742
753
|
### 4. Aggressive Caching
|
|
743
754
|
|
|
744
755
|
Parse, simplify, condition-to-CSS, and full-pipeline results are cached independently, enabling fast re-rendering when only parts of the style object change.
|
|
756
|
+
|
|
757
|
+
Cache keys must respect key order where it carries meaning. A state map resolves by key order, so `{ '': A, checked: B, disabled: C }` and `{ '': A, disabled: C, checked: B }` are different styles and must get different keys (and classes). Only the style keys of a styles object, including a sub-element's, are order-insensitive, so they may be sorted. `stringifyStyles` (pipeline cache) and `generateChunkCacheKey` (class allocation) both follow this rule.
|
|
758
|
+
|
|
759
|
+
---
|
|
760
|
+
|
|
761
|
+
## Testing Priority
|
|
762
|
+
|
|
763
|
+
Every stage above is an optimization that must leave one thing unchanged: in any state, the value that applies is the value of the last authored key whose condition holds. `src/test/state-oracle.ts` states that rule directly, with none of the pipeline's machinery, and two suites compare the pipeline against it:
|
|
764
|
+
|
|
765
|
+
- `src/pipeline/exclusive.test.ts` (Node) evaluates the conditions after each of Stages 0–3 on thousands of generated maps, and names the stage that disagrees.
|
|
766
|
+
- `src/pipeline/state-priority.test.ts` (browser) renders hand-written, permuted, and generated maps to CSS, applies every combination of states (modifiers, value modifiers, `:has()`, `@root`, `@parent`, `@own`, media, supports), and compares what the browser computes against the oracle. It also checks that rules stay mutually exclusive, which a correct computed value alone can hide. It runs through the pipeline, the runtime injector, and the SSR collector, with all maps mounted at once so a cache-key collision shows up.
|
|
767
|
+
|
|
768
|
+
A change to any stage should keep both green. When a generated map fails, the message includes the map, the failing states, and the CSS; the map is usually worth adding to the hand-written cases once it is reduced.
|
package/docs/plugins.md
CHANGED
|
@@ -37,29 +37,29 @@ configure({ plugins: [spacingPlugin()] });
|
|
|
37
37
|
|
|
38
38
|
**Configuration is locked after the first render.** `configure()` warns and does nothing once any style has been generated, so it must run before your first component renders — at module scope in your entry file, or in a design-system module every component imports. `resetConfig()` reopens it, but it exists for tests.
|
|
39
39
|
|
|
40
|
-
**Repeated `configure()` calls merge
|
|
40
|
+
**Repeated `configure()` calls merge.** Each call adds to what earlier calls registered, key by key, in every registry (`states`, `units`, `functions`, `handlers`, `propHandlers`, `baseStyleProps`, `tokens`, `replaceTokens`, `recipes`, `keyframes`, `properties`, `fontFaces`, `counterStyles`); `globalStyles` merges per selector. A later value for the same key wins.
|
|
41
41
|
|
|
42
42
|
---
|
|
43
43
|
|
|
44
44
|
## Choosing an extension point
|
|
45
45
|
|
|
46
|
-
| You want to add
|
|
47
|
-
|
|
48
|
-
| New value syntax — `okhsl(…)`, `double(2x)` | `functions` (bare key)
|
|
49
|
-
| A reusable CSS `@function`
|
|
50
|
-
| A new unit — `2gu`
|
|
51
|
-
| A new state alias — `@mobile`
|
|
52
|
-
| A style property → **CSS declarations**
|
|
53
|
-
| A style property on every component
|
|
54
|
-
| A **component prop** → anything
|
|
55
|
-
| A named bundle of styles
|
|
56
|
-
| Typography scale tokens
|
|
57
|
-
| `:root` variables
|
|
58
|
-
| Global selector styles
|
|
46
|
+
| You want to add | Use | Runs | Build-time extraction |
|
|
47
|
+
| ------------------------------------------- | -------------------------- | ---------------------------- | ----------------------- |
|
|
48
|
+
| New value syntax — `okhsl(…)`, `double(2x)` | `functions` (bare key) | parse time, per value | ✅ |
|
|
49
|
+
| A reusable CSS `@function` | `functions` (`$$name` key) | injected once, globally | ✅ |
|
|
50
|
+
| A new unit — `2gu` | `units` | parse time, per value | ✅ |
|
|
51
|
+
| A new state alias — `@mobile` | `states` | state-key parse | ✅ |
|
|
52
|
+
| A style property → **CSS declarations** | `handlers` | pipeline, per state snapshot | ✅ |
|
|
53
|
+
| A style property on every component | `baseStyleProps` | prop harvest | ✅ (styles only) |
|
|
54
|
+
| A **component prop** → anything | `propHandlers` | render, per component | ❌ (no props to run on) |
|
|
55
|
+
| A named bundle of styles | `recipes` | before chunking | ✅ |
|
|
56
|
+
| Typography scale tokens | `presets` | inject time | ✅ |
|
|
57
|
+
| `:root` variables | `tokens`, `replaceTokens` | inject time | ✅ |
|
|
58
|
+
| Global selector styles | `globalStyles` | inject time | ✅ |
|
|
59
59
|
|
|
60
60
|
Two distinctions do most of the work:
|
|
61
61
|
|
|
62
|
-
- **`handlers` vs `propHandlers`.** A handler turns a
|
|
62
|
+
- **`handlers` vs `propHandlers`.** A handler turns a _style property_ into CSS declarations and knows nothing about components. A prop handler turns a _component prop_ into other props — including `styles`, which then flow through the normal handlers. Reach for `propHandlers` when the input isn't a style value (an options object, a domain concept) or when it should affect more than styles.
|
|
63
63
|
- **`recipes` vs `propHandlers`.** A recipe is a static named bundle. A prop handler computes its styles from a value.
|
|
64
64
|
|
|
65
65
|
---
|
|
@@ -69,7 +69,7 @@ Two distinctions do most of the work:
|
|
|
69
69
|
A handler receives a map of the style properties it declared and returns CSS declarations. See [Configuration → Custom Style Handlers](configuration.md#custom-style-handlers) for the definition forms, return shape, the shared-handler groups you must be careful of, and chunk membership. The essentials:
|
|
70
70
|
|
|
71
71
|
- Values arrive **state-resolved but unparsed** — the raw authored DSL string (`'2x'`, `'#purple.5'`, `true`, `4`). Call the exported `parseStyle()` / `parseColor()` yourself.
|
|
72
|
-
- Return a `CSSMap` with **kebab-case** keys, an array of them, or nothing. `$` is a selector suffix, not a property.
|
|
72
|
+
- Return a `CSSMap` with **kebab-case** keys, an array of them, or nothing. `$` is a selector suffix, not a property. A property whose value is an array gets one declaration per entry, for fallback chains.
|
|
73
73
|
- Handlers must be pure and synchronous. They are called once per state combination and the results are cached.
|
|
74
74
|
- Use `defineHandler(deps, fn)` for multi-dependency handlers so the dependency types are inferred.
|
|
75
75
|
|
|
@@ -108,6 +108,7 @@ configure({
|
|
|
108
108
|
|
|
109
109
|
```ts
|
|
110
110
|
import { configure, mergeStyles } from '@tenphi/tasty';
|
|
111
|
+
import type { Styles } from '@tenphi/tasty';
|
|
111
112
|
|
|
112
113
|
configure({
|
|
113
114
|
propHandlers: {
|
|
@@ -115,7 +116,11 @@ configure({
|
|
|
115
116
|
const { glaze, ...rest } = props;
|
|
116
117
|
if (!glaze) return rest;
|
|
117
118
|
|
|
118
|
-
|
|
119
|
+
// glazeStyles: see the worked example below
|
|
120
|
+
return {
|
|
121
|
+
...rest,
|
|
122
|
+
styles: mergeStyles(glazeStyles(glaze), rest.styles as Styles),
|
|
123
|
+
};
|
|
119
124
|
},
|
|
120
125
|
},
|
|
121
126
|
});
|
|
@@ -123,12 +128,12 @@ configure({
|
|
|
123
128
|
|
|
124
129
|
**The key is the trigger.** By default a handler runs only when a prop matching its key is present, so an absent prop costs one property check rather than a call. Override that with a tuple:
|
|
125
130
|
|
|
126
|
-
| Definition
|
|
127
|
-
|
|
128
|
-
| `fn`
|
|
129
|
-
| `['glaze', fn]`
|
|
130
|
-
| `[['glaze', 'tint'], fn]` | either is present
|
|
131
|
-
| `['*', fn]`
|
|
131
|
+
| Definition | Runs when |
|
|
132
|
+
| ------------------------- | ------------------------------------- |
|
|
133
|
+
| `fn` | a prop named after the key is present |
|
|
134
|
+
| `['glaze', fn]` | `glaze` is present |
|
|
135
|
+
| `[['glaze', 'tint'], fn]` | either is present |
|
|
136
|
+
| `['*', fn]` | always |
|
|
132
137
|
|
|
133
138
|
**Chaining.** Handlers run in registration order — plugins first, then direct `configure()` — and each receives the previous one's output. Registering the same key twice replaces the handler in place, keeping its position.
|
|
134
139
|
|
|
@@ -136,16 +141,16 @@ configure({
|
|
|
136
141
|
|
|
137
142
|
### Rules
|
|
138
143
|
|
|
139
|
-
- **Be pure. Never mutate the input.** Style values are cached by object identity, so mutating a value object in place yields a stale class name
|
|
144
|
+
- **Be pure. Never mutate the input.** Style values are cached by object identity, so mutating a value object in place yields a stale class name _and_ stale CSS. Return fresh objects.
|
|
140
145
|
- **Memoize the styles you build, per input value.** A reference-stable (ideally frozen) styles object lets the cache key reuse its serialization instead of recomputing it on every render. This is the single highest-leverage thing you can do for performance.
|
|
141
146
|
- **Precedence is fixed** and not adjustable from a handler. Styles are merged as `factory defaults → styles → harvested style props`, and injected styles occupy the `styles` slot: they beat a component's own default styles and lose to a style prop passed at the call site. This matches how `recipe` already behaves.
|
|
142
|
-
- **Prefer returning `styles` over bare style props.** Returning `{ fill: '#red' }` only works if `fill` is harvestable on
|
|
147
|
+
- **Prefer returning `styles` over bare style props.** Returning `{ fill: '#red' }` only works if `fill` is harvestable on _that_ component (in its `styleProps`, or promoted via `baseStyleProps`); otherwise it leaks to the DOM.
|
|
143
148
|
|
|
144
149
|
### What it cannot do
|
|
145
150
|
|
|
146
151
|
- **`ref`** — `forwardRef` separates it from props, so it is out of reach.
|
|
147
152
|
- **Sub-elements** (`Card.Title`) — they have no `styles` prop and no style-prop harvest, so middleware does not run on them.
|
|
148
|
-
- **
|
|
153
|
+
- **Build-time extraction** — see [Rendering modes](#rendering-modes-and-caveats).
|
|
149
154
|
|
|
150
155
|
---
|
|
151
156
|
|
|
@@ -159,9 +164,9 @@ configure({ baseStyleProps: ['radius', 'shadow'] });
|
|
|
159
164
|
<Card radius="1r" shadow />
|
|
160
165
|
```
|
|
161
166
|
|
|
162
|
-
Names must
|
|
167
|
+
Names must start with a lowercase letter and contain only letters and digits, and must not collide with a prop `tasty()` consumes itself (`as`, `styles`, `variant`, `mods`, `tokens`, …); invalid entries are dropped with a development warning. Names are not checked against the style registry, so a misspelled name is still harvested as a style prop.
|
|
163
168
|
|
|
164
|
-
`configure()` may run
|
|
169
|
+
`configure()` may run _after_ your components are defined — each factory resolves its prop list lazily and refreshes when the registry changes.
|
|
165
170
|
|
|
166
171
|
**Costs and caveats.** Each name adds one property check per render of every component, forever, so keep the list short. The effect is app-global and cannot be scoped to a subtree — use a factory's own `styleProps` for that. Be wary of names that collide with real DOM or component props (`width`, `size`, `color`): promoting one means every component swallows it as a style, including when rendering `as={SomeThirdPartyComponent}`.
|
|
167
172
|
|
|
@@ -169,39 +174,9 @@ Names must be real style properties, must start with a lowercase letter, and mus
|
|
|
169
174
|
|
|
170
175
|
## Typing your extension
|
|
171
176
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
```ts
|
|
175
|
-
// tasty.d.ts
|
|
176
|
-
import type { StylePropValue } from '@tenphi/tasty';
|
|
177
|
+
Every extension point has a matching augmentation interface: `StylesInterface` for `handlers`, `TastyCustomProps` for `propHandlers`, `TastyBaseStylePropNames` for `baseStyleProps`, and `TastyNamedColors`, `TastyPresetNames`, and `TastyThemeNames` for the names your `tokens` and `presets` define. [Configuration → TypeScript](configuration.md#typescript) covers all six and the rules that go with them.
|
|
177
178
|
|
|
178
|
-
|
|
179
|
-
// configure({ handlers }) — a new style property
|
|
180
|
-
interface StylesInterface {
|
|
181
|
-
stripe?: StylePropValue<string>;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// configure({ propHandlers }) — a new component prop
|
|
185
|
-
interface TastyCustomProps {
|
|
186
|
-
glaze: 'soft' | 'strong' | { tone: string; intensity?: number };
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// configure({ baseStyleProps }) — promoted style names, typed like the style
|
|
190
|
-
interface TastyBaseStylePropNames {
|
|
191
|
-
radius: true;
|
|
192
|
-
shadow: true;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// configure({ tokens }) / recipes / presets — autocomplete for names
|
|
196
|
-
interface TastyNamedColors {
|
|
197
|
-
'glaze-bg': true;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
`TastyCustomProps` keys become optional props on every component. `TastyBaseStylePropNames` entries are typed exactly like the style they name, so `radius="1r"` accepts the same values as `styles={{ radius: '1r' }}`.
|
|
203
|
-
|
|
204
|
-
**Also update `tasty.config.ts`.** The ESLint plugin and VS Code extension validate style and token names against it, and neither is derived from the runtime registries:
|
|
179
|
+
**Also update `tasty.config.ts`.** The ESLint plugin and VS Code extension validate style and token names against it, and neither reads the runtime registries or your augmentations:
|
|
205
180
|
|
|
206
181
|
```ts
|
|
207
182
|
// tasty.config.ts
|
|
@@ -211,7 +186,7 @@ export default {
|
|
|
211
186
|
};
|
|
212
187
|
```
|
|
213
188
|
|
|
214
|
-
`propHandlers` keys are JSX props rather than style keys, so they need no entry — but any
|
|
189
|
+
`propHandlers` keys are JSX props rather than style keys, so they need no entry — but any _style_ name or token a handler expands into does.
|
|
215
190
|
|
|
216
191
|
---
|
|
217
192
|
|
|
@@ -246,7 +221,7 @@ function glazeStyles(value: GlazeValue): Styles {
|
|
|
246
221
|
styles = Object.freeze({
|
|
247
222
|
'#glaze-bg': `#${tone}.${intensity}`,
|
|
248
223
|
fill: '#glaze-bg',
|
|
249
|
-
transition: 'fill
|
|
224
|
+
transition: 'fill',
|
|
250
225
|
}) as Styles;
|
|
251
226
|
cache.set(key, styles);
|
|
252
227
|
}
|
|
@@ -274,7 +249,11 @@ export const glazePlugin: TastyPluginFactory = () => ({
|
|
|
274
249
|
|
|
275
250
|
// Typed so `#glaze-bg` animates smoothly instead of snapping.
|
|
276
251
|
properties: {
|
|
277
|
-
'#glaze-bg': {
|
|
252
|
+
'#glaze-bg': {
|
|
253
|
+
syntax: '<color>',
|
|
254
|
+
inherits: false,
|
|
255
|
+
initialValue: 'transparent',
|
|
256
|
+
},
|
|
278
257
|
},
|
|
279
258
|
});
|
|
280
259
|
```
|
|
@@ -295,6 +274,8 @@ configure({ plugins: [glazePlugin()] });
|
|
|
295
274
|
|
|
296
275
|
```ts
|
|
297
276
|
// tasty.d.ts
|
|
277
|
+
import '@tenphi/tasty';
|
|
278
|
+
|
|
298
279
|
declare module '@tenphi/tasty' {
|
|
299
280
|
interface TastyCustomProps {
|
|
300
281
|
glaze: import('./glaze-plugin').GlazeConfig | string;
|
|
@@ -302,19 +283,19 @@ declare module '@tenphi/tasty' {
|
|
|
302
283
|
}
|
|
303
284
|
```
|
|
304
285
|
|
|
305
|
-
The object value is unambiguous here precisely because `glaze` is a **prop**. A style
|
|
286
|
+
The object value is unambiguous here precisely because `glaze` is a **prop**. A style _value_ of the same shape would be indistinguishable from a state map (`{ tone: … }` looks exactly like `{ hovered: … }`), which is why this belongs in `propHandlers` rather than `handlers`.
|
|
306
287
|
|
|
307
288
|
---
|
|
308
289
|
|
|
309
290
|
## Rendering modes and caveats
|
|
310
291
|
|
|
311
|
-
| Mode
|
|
312
|
-
|
|
313
|
-
| Client
|
|
314
|
-
| SSR / RSC
|
|
315
|
-
|
|
|
292
|
+
| Mode | `functions` / `units` / `states` / `handlers` / `recipes` / `tokens` | `propHandlers` |
|
|
293
|
+
| -------------------------- | -------------------------------------------------------------------- | -------------- |
|
|
294
|
+
| Client | ✅ | ✅ |
|
|
295
|
+
| SSR / RSC | ✅ | ✅ |
|
|
296
|
+
| Build-time (`tastyStatic`) | ✅ at build time | not applicable |
|
|
316
297
|
|
|
317
|
-
**
|
|
298
|
+
**Build-time extraction.** The Babel plugin transforms `tastyStatic()` calls, which take styles objects — there are no props in that pipeline, so there is nothing for props middleware to run on. Components rendered through `tasty()` are untouched by the plugin; `propHandlers` work whether those components render on the server or in the browser. Everything in the `tastyStatic()` path runs at build time, which is why handlers, functions, and units must be pure functions of their input.
|
|
318
299
|
|
|
319
300
|
**Server and client must configure identically.** Class names are derived from resolved styles, so a handler or promoted prop registered on one side and not the other produces a hydration mismatch. This is the same requirement as `namePrefix` — see [SSR → Hydration mismatch warnings](ssr.md#hydration-mismatch-warnings).
|
|
320
301
|
|
|
@@ -323,17 +304,20 @@ The object value is unambiguous here precisely because `glaze` is a **prop**. A
|
|
|
323
304
|
## Testing a plugin
|
|
324
305
|
|
|
325
306
|
```ts
|
|
326
|
-
import {
|
|
307
|
+
import { resetConfig, renderStyles } from '@tenphi/tasty';
|
|
308
|
+
import type { PropHandler, Styles } from '@tenphi/tasty';
|
|
327
309
|
|
|
328
310
|
describe('glaze plugin', () => {
|
|
329
311
|
beforeEach(() => resetConfig());
|
|
330
312
|
afterEach(() => resetConfig());
|
|
331
313
|
|
|
332
|
-
it('
|
|
333
|
-
|
|
314
|
+
it('turns the glaze prop into styles', () => {
|
|
315
|
+
const glaze = glazePlugin().propHandlers!.glaze as PropHandler;
|
|
316
|
+
const out = glaze({ glaze: 'purple' })!;
|
|
334
317
|
|
|
335
|
-
|
|
318
|
+
expect(out).not.toHaveProperty('glaze');
|
|
336
319
|
|
|
320
|
+
const rules = renderStyles(out.styles as Styles, '.test');
|
|
337
321
|
expect(rules[0].declarations).toContain('--glaze-bg-color');
|
|
338
322
|
});
|
|
339
323
|
});
|
|
@@ -341,7 +325,7 @@ describe('glaze plugin', () => {
|
|
|
341
325
|
|
|
342
326
|
Two things to know:
|
|
343
327
|
|
|
344
|
-
- **Create components inside each test.** `resetConfig()` does not clear
|
|
328
|
+
- **Create components inside each test.** `resetConfig()` does not clear a component's own class-name cache, which `tasty()` keeps in DOM environments, so a module-scope component can keep returning a class whose CSS the reset removed.
|
|
345
329
|
- **Dev-mode warnings may not fire.** `isDevEnv()` reports `false` for `NODE_ENV=test`. Warnings that check it lazily can be enabled with `vi.stubEnv('NODE_ENV', 'development')`; some older ones capture it at module load and cannot be triggered from a test at all.
|
|
346
330
|
|
|
347
331
|
---
|