@tenphi/tasty 0.0.0-snapshot.047dfbb → 0.0.0-snapshot.04fb534
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 +452 -370
- package/dist/babel-types-Dc5zghyE.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--0qoqt_P.js +60 -0
- package/dist/chunks/build-config--0qoqt_P.js.map +1 -0
- package/dist/{collector-J6LwZR0N.js → chunks/collector-zp5BrLF0.js} +68 -101
- package/dist/chunks/collector-zp5BrLF0.js.map +1 -0
- package/dist/chunks/config-engine-BaLq8HrX.js +272 -0
- package/dist/chunks/config-engine-BaLq8HrX.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-CfXZ3tU9.js +910 -0
- package/dist/chunks/css-definitions-CfXZ3tU9.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--OC-WA-Q.js +502 -0
- package/dist/chunks/debug--OC-WA-Q.js.map +1 -0
- package/dist/chunks/dsl-CsFl9LGn.js +1458 -0
- package/dist/chunks/dsl-CsFl9LGn.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-DnZ6M1Iv.js +691 -0
- package/dist/chunks/react-runtime-DnZ6M1Iv.js.map +1 -0
- package/dist/chunks/runtime-engine-J9X_h-Pw.js +2435 -0
- package/dist/chunks/runtime-engine-J9X_h-Pw.js.map +1 -0
- package/dist/chunks/runtime-state-o_v3Bj7b.js +152 -0
- package/dist/chunks/runtime-state-o_v3Bj7b.js.map +1 -0
- package/dist/{merge-styles-CAdKaHxh.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-D6lC3O3G.js +5626 -0
- package/dist/chunks/style-engine-D6lC3O3G.js.map +1 -0
- package/dist/{css-writer-IC7tdnIf.js → chunks/zero-engine-BnjoV04F.js} +95 -136
- package/dist/chunks/zero-engine-BnjoV04F.js.map +1 -0
- package/dist/{collector-CddJZDOr.d.ts → collector-D2OT6I2G.d.ts} +64 -8
- package/dist/{config-C3SKYuxY.d.ts → config-C4ftFxgI.d.ts} +514 -92
- 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-ByBYTH9l.d.ts → index-DxQNRj50.d.ts} +586 -400
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -732
- package/dist/{merge-styles-CvUi7SOD.d.ts → merge-styles-D39qBtox.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 +17 -0
- package/dist/ssr/astro-middleware-static.js +7 -0
- package/dist/ssr/astro-middleware-static.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +11 -8
- package/dist/ssr/astro-middleware.js +2 -14
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +40 -10
- package/dist/ssr/astro.js +160 -86
- 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 -32
- package/dist/ssr/index.js +6 -6
- 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 -44
- 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-C5owZ15q.d.ts → types-CYQIhUg1.d.ts} +874 -598
- package/dist/zero/babel.d.ts +12 -19
- package/dist/zero/babel.js +97 -156
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +76 -7
- package/dist/zero/index.js +25 -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 +20 -9
- package/docs/adoption.md +69 -36
- package/docs/ai-agents.md +259 -0
- package/docs/comparison.md +77 -47
- package/docs/configuration.md +617 -98
- package/docs/debug.md +28 -15
- package/docs/design-system.md +166 -33
- package/docs/dsl.md +637 -205
- package/docs/getting-started.md +130 -50
- package/docs/injector.md +160 -69
- package/docs/llms.txt +31 -0
- package/docs/methodology.md +82 -51
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +57 -33
- package/docs/plugins.md +333 -0
- package/docs/react-api.md +215 -50
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +310 -118
- package/docs/styles.md +209 -41
- package/docs/tasty-static.md +289 -136
- package/harness/dev.harnesspm/rules/usage.md +12 -0
- package/harness/dev.harnesspm/scripts/render.mjs +441 -0
- package/harness/dev.harnesspm/scripts/styles.mjs +412 -0
- package/harness/plugin.json +20 -0
- package/package.json +148 -49
- package/tasty.config.ts +5 -0
- package/dist/async-storage-DKK-wTD4.js +0 -44
- package/dist/async-storage-DKK-wTD4.js.map +0 -1
- package/dist/collector-J6LwZR0N.js.map +0 -1
- package/dist/config-C3F4Ogo1.js +0 -10993
- package/dist/config-C3F4Ogo1.js.map +0 -1
- package/dist/context-CA8YKeMn.js +0 -24
- package/dist/context-CA8YKeMn.js.map +0 -1
- package/dist/core-DxHmF6S9.js +0 -1598
- package/dist/core-DxHmF6S9.js.map +0 -1
- package/dist/css-writer-IC7tdnIf.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-DTLY39Hm.js +0 -143
- package/dist/format-rules-DTLY39Hm.js.map +0 -1
- package/dist/hydrate-8Zglgy_C.js +0 -45
- package/dist/hydrate-8Zglgy_C.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-DgGkipNK.js +0 -595
- package/dist/keyframes-DgGkipNK.js.map +0 -1
- package/dist/merge-styles-CAdKaHxh.js.map +0 -1
- package/dist/resolve-recipes-BQNdunBd.js +0 -144
- package/dist/resolve-recipes-BQNdunBd.js.map +0 -1
package/docs/pipeline.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
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
|
|
|
9
|
-
The pipeline takes a `Styles` object and produces an array of `CSSRule` objects ready for injection into the DOM.
|
|
9
|
+
The pipeline takes a `Styles` object and produces an array of `CSSRule` objects ready for injection into the DOM. The entry point is `renderStyles`, which has two overloads: called with a selector or class (`renderStyles(styles, '.t1')`) it returns the rules directly; called without one (`renderStyles(styles)`) it returns `{ rules }` for a caller that will allocate the class name itself. The per-handler flow is:
|
|
10
10
|
|
|
11
11
|
```
|
|
12
12
|
Input: Styles Object
|
|
@@ -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
|
|
|
@@ -145,7 +149,7 @@ Converts each state key in a style value map (like `'hovered & !disabled'`, `'@m
|
|
|
145
149
|
- `@own(hovered)` → `OwnCondition` wrapping the parsed inner condition
|
|
146
150
|
- `@supports(display: grid)` → `SupportsCondition`
|
|
147
151
|
- `@(w < 600px)` → `ContainerCondition` (dimension, style, or raw subtypes)
|
|
148
|
-
- `@mobile` → Resolved via predefined states, then parsed recursively
|
|
152
|
+
- `@mobile` → Resolved via predefined states, then parsed recursively. A local alias resolves against local, then global aliases; a global alias resolves against global aliases only. A stack of the aliases being resolved stops a cycle: the repeated alias becomes `FALSE` and emits `CIRCULAR_STATE_ALIAS`
|
|
149
153
|
|
|
150
154
|
Pipeline warnings for invalid inputs (e.g. bad `$` selector affix) are emitted from `warnings.ts`.
|
|
151
155
|
|
|
@@ -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 `
|
|
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
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# Plugins & Extension Points
|
|
2
|
+
|
|
3
|
+
How to extend Tasty: new value syntax, new units, new states, new style properties, new component props, and how to package any of it as a plugin.
|
|
4
|
+
|
|
5
|
+
- [What a plugin is](#what-a-plugin-is)
|
|
6
|
+
- [Choosing an extension point](#choosing-an-extension-point)
|
|
7
|
+
- [Custom style handlers](#custom-style-handlers)
|
|
8
|
+
- [Props middleware](#props-middleware)
|
|
9
|
+
- [Base style props](#base-style-props)
|
|
10
|
+
- [Typing your extension](#typing-your-extension)
|
|
11
|
+
- [Worked example: a `glaze` plugin](#worked-example-a-glaze-plugin)
|
|
12
|
+
- [Rendering modes and caveats](#rendering-modes-and-caveats)
|
|
13
|
+
- [Testing a plugin](#testing-a-plugin)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## What a plugin is
|
|
18
|
+
|
|
19
|
+
A plugin is a plain object with a `name` and any subset of the `configure()` options it is allowed to supply. There is no lifecycle and no init hook — a plugin is just pre-packaged configuration.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { configure } from '@tenphi/tasty';
|
|
23
|
+
import type { TastyPluginFactory } from '@tenphi/tasty';
|
|
24
|
+
|
|
25
|
+
const spacingPlugin: TastyPluginFactory = () => ({
|
|
26
|
+
name: 'spacing',
|
|
27
|
+
units: { gu: (n) => `calc(${n} * var(--grid-unit))` },
|
|
28
|
+
tokens: { '$grid-unit': '4px' },
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
configure({ plugins: [spacingPlugin()] });
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`TastyPluginFactory<TOptions>` types a factory that takes options; with no type argument it types a zero-argument factory.
|
|
35
|
+
|
|
36
|
+
**Ordering.** Plugins are applied in array order and merged key by key, so a later plugin overrides an earlier one for the same key. Options passed directly to `configure()` are applied last and win over every plugin.
|
|
37
|
+
|
|
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
|
+
|
|
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
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Choosing an extension point
|
|
45
|
+
|
|
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
|
+
|
|
60
|
+
Two distinctions do most of the work:
|
|
61
|
+
|
|
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
|
+
- **`recipes` vs `propHandlers`.** A recipe is a static named bundle. A prop handler computes its styles from a value.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Custom style handlers
|
|
68
|
+
|
|
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
|
+
|
|
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. A property whose value is an array gets one declaration per entry, for fallback chains.
|
|
73
|
+
- Handlers must be pure and synchronous. They are called once per state combination and the results are cached.
|
|
74
|
+
- Use `defineHandler(deps, fn)` for multi-dependency handlers so the dependency types are inferred.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { configure, defineHandler, parseStyle } from '@tenphi/tasty';
|
|
78
|
+
|
|
79
|
+
configure({
|
|
80
|
+
handlers: {
|
|
81
|
+
// Every declaration set the handler returns can target its own selector.
|
|
82
|
+
stripe: defineHandler(['stripe'], ({ stripe }) => {
|
|
83
|
+
if (!stripe) return;
|
|
84
|
+
|
|
85
|
+
const { values } = parseStyle(String(stripe)).groups[0];
|
|
86
|
+
|
|
87
|
+
return [
|
|
88
|
+
{ position: 'relative' },
|
|
89
|
+
{
|
|
90
|
+
$: '&::before',
|
|
91
|
+
content: '""',
|
|
92
|
+
position: 'absolute',
|
|
93
|
+
inset: '0 auto 0 0',
|
|
94
|
+
width: values[0],
|
|
95
|
+
background: 'var(--purple-color)',
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
}),
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Props middleware
|
|
106
|
+
|
|
107
|
+
`propHandlers` are middleware over a component's props: props in, props out. They run at the very top of every tasty component's render, before any prop is destructured, so a handler can read and rewrite `styles`, `mods`, `tokens`, `variant`, `as`, `element`, and `qa`, and can strip its own props so they never reach the DOM.
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { configure, mergeStyles } from '@tenphi/tasty';
|
|
111
|
+
import type { Styles } from '@tenphi/tasty';
|
|
112
|
+
|
|
113
|
+
configure({
|
|
114
|
+
propHandlers: {
|
|
115
|
+
glaze: (props) => {
|
|
116
|
+
const { glaze, ...rest } = props;
|
|
117
|
+
if (!glaze) return rest;
|
|
118
|
+
|
|
119
|
+
// glazeStyles: see the worked example below
|
|
120
|
+
return {
|
|
121
|
+
...rest,
|
|
122
|
+
styles: mergeStyles(glazeStyles(glaze), rest.styles as Styles),
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
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:
|
|
130
|
+
|
|
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 |
|
|
137
|
+
|
|
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.
|
|
139
|
+
|
|
140
|
+
**Returning nothing means unchanged**, with a development-mode warning, because that is almost always a forgotten `return props`. A non-object return is ignored with a warning.
|
|
141
|
+
|
|
142
|
+
### Rules
|
|
143
|
+
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
148
|
+
|
|
149
|
+
### What it cannot do
|
|
150
|
+
|
|
151
|
+
- **`ref`** — `forwardRef` separates it from props, so it is out of reach.
|
|
152
|
+
- **Sub-elements** (`Card.Title`) — they have no `styles` prop and no style-prop harvest, so middleware does not run on them.
|
|
153
|
+
- **Build-time extraction** — see [Rendering modes](#rendering-modes-and-caveats).
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Base style props
|
|
158
|
+
|
|
159
|
+
A small set of style properties — `display`, `font`, `preset`, `hide`, `whiteSpace`, `opacity`, `transition` — are harvested as props on every `tasty()` component. `baseStyleProps` adds to that set globally:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
configure({ baseStyleProps: ['radius', 'shadow'] });
|
|
163
|
+
|
|
164
|
+
<Card radius="1r" shadow />
|
|
165
|
+
```
|
|
166
|
+
|
|
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.
|
|
168
|
+
|
|
169
|
+
`configure()` may run _after_ your components are defined — each factory resolves its prop list lazily and refreshes when the registry changes.
|
|
170
|
+
|
|
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}`.
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Typing your extension
|
|
176
|
+
|
|
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.
|
|
178
|
+
|
|
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:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
// tasty.config.ts
|
|
183
|
+
export default {
|
|
184
|
+
styles: ['stripe'],
|
|
185
|
+
tokens: ['#glaze-bg'],
|
|
186
|
+
};
|
|
187
|
+
```
|
|
188
|
+
|
|
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.
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Worked example: a `glaze` plugin
|
|
194
|
+
|
|
195
|
+
A `glaze` prop on every component that takes a configuration object and expands into color token declarations. This is the case `propHandlers` exists for: the value is an options object, not a style value, so it cannot be a style property.
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
// glaze-plugin.ts
|
|
199
|
+
import { mergeStyles } from '@tenphi/tasty';
|
|
200
|
+
import type { Styles, TastyPluginFactory } from '@tenphi/tasty';
|
|
201
|
+
|
|
202
|
+
export interface GlazeConfig {
|
|
203
|
+
tone: string;
|
|
204
|
+
/** 0–100. Default 10. */
|
|
205
|
+
intensity?: number;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
type GlazeValue = string | GlazeConfig;
|
|
209
|
+
|
|
210
|
+
// Memoized per value so the styles object is reference-stable across renders.
|
|
211
|
+
const cache = new Map<string, Styles>();
|
|
212
|
+
|
|
213
|
+
function glazeStyles(value: GlazeValue): Styles {
|
|
214
|
+
const { tone, intensity = 10 } =
|
|
215
|
+
typeof value === 'string' ? { tone: value } : value;
|
|
216
|
+
const key = `${tone}:${intensity}`;
|
|
217
|
+
|
|
218
|
+
let styles = cache.get(key);
|
|
219
|
+
|
|
220
|
+
if (!styles) {
|
|
221
|
+
styles = Object.freeze({
|
|
222
|
+
'#glaze-bg': `#${tone}.${intensity}`,
|
|
223
|
+
fill: '#glaze-bg',
|
|
224
|
+
transition: 'fill',
|
|
225
|
+
}) as Styles;
|
|
226
|
+
cache.set(key, styles);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return styles;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export const glazePlugin: TastyPluginFactory = () => ({
|
|
233
|
+
name: 'glaze',
|
|
234
|
+
|
|
235
|
+
propHandlers: {
|
|
236
|
+
glaze: (props) => {
|
|
237
|
+
const { glaze, ...rest } = props;
|
|
238
|
+
if (!glaze) return rest;
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
...rest,
|
|
242
|
+
styles: mergeStyles(
|
|
243
|
+
glazeStyles(glaze as GlazeValue),
|
|
244
|
+
rest.styles as Styles,
|
|
245
|
+
),
|
|
246
|
+
};
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
// Typed so `#glaze-bg` animates smoothly instead of snapping.
|
|
251
|
+
properties: {
|
|
252
|
+
'#glaze-bg': {
|
|
253
|
+
syntax: '<color>',
|
|
254
|
+
inherits: false,
|
|
255
|
+
initialValue: 'transparent',
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
// app entry, before the first render
|
|
263
|
+
import { configure } from '@tenphi/tasty';
|
|
264
|
+
|
|
265
|
+
import { glazePlugin } from './glaze-plugin';
|
|
266
|
+
|
|
267
|
+
configure({ plugins: [glazePlugin()] });
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
```tsx
|
|
271
|
+
<Element glaze="purple" />
|
|
272
|
+
<Element glaze={{ tone: 'success', intensity: 30 }} />
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
```ts
|
|
276
|
+
// tasty.d.ts
|
|
277
|
+
import '@tenphi/tasty';
|
|
278
|
+
|
|
279
|
+
declare module '@tenphi/tasty' {
|
|
280
|
+
interface TastyCustomProps {
|
|
281
|
+
glaze: import('./glaze-plugin').GlazeConfig | string;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
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`.
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Rendering modes and caveats
|
|
291
|
+
|
|
292
|
+
| Mode | `functions` / `units` / `states` / `handlers` / `recipes` / `tokens` | `propHandlers` |
|
|
293
|
+
| -------------------------- | -------------------------------------------------------------------- | -------------- |
|
|
294
|
+
| Client | ✅ | ✅ |
|
|
295
|
+
| SSR / RSC | ✅ | ✅ |
|
|
296
|
+
| Build-time (`tastyStatic`) | ✅ at build time | not applicable |
|
|
297
|
+
|
|
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.
|
|
299
|
+
|
|
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).
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## Testing a plugin
|
|
305
|
+
|
|
306
|
+
```ts
|
|
307
|
+
import { resetConfig, renderStyles } from '@tenphi/tasty';
|
|
308
|
+
import type { PropHandler, Styles } from '@tenphi/tasty';
|
|
309
|
+
|
|
310
|
+
describe('glaze plugin', () => {
|
|
311
|
+
beforeEach(() => resetConfig());
|
|
312
|
+
afterEach(() => resetConfig());
|
|
313
|
+
|
|
314
|
+
it('turns the glaze prop into styles', () => {
|
|
315
|
+
const glaze = glazePlugin().propHandlers!.glaze as PropHandler;
|
|
316
|
+
const out = glaze({ glaze: 'purple' })!;
|
|
317
|
+
|
|
318
|
+
expect(out).not.toHaveProperty('glaze');
|
|
319
|
+
|
|
320
|
+
const rules = renderStyles(out.styles as Styles, '.test');
|
|
321
|
+
expect(rules[0].declarations).toContain('--glaze-bg-color');
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Two things to know:
|
|
327
|
+
|
|
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.
|
|
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.
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
See [Configuration](configuration.md) for every option in detail, [Style DSL](dsl.md) for the value syntax your extensions produce, and [React API](react-api.md) for `tasty()`, `styleProps`, `modProps`, and `tokenProps`.
|