@tenphi/tasty 0.0.0-snapshot.a85ade8 → 0.0.0-snapshot.a8a2a5d
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 +418 -381
- package/dist/babel-types-BOABQvEI.d.ts +16 -0
- package/dist/chunks/async-storage-CzSKAyrI.js +36 -0
- package/dist/chunks/async-storage-CzSKAyrI.js.map +1 -0
- package/dist/chunks/build-config-DQkT3Wru.js +59 -0
- package/dist/chunks/build-config-DQkT3Wru.js.map +1 -0
- package/dist/{collector-C6TtL8HJ.js → chunks/collector-Df9zcabl.js} +11 -129
- package/dist/chunks/collector-Df9zcabl.js.map +1 -0
- package/dist/chunks/config-engine-C7OUmM1J.js +269 -0
- package/dist/chunks/config-engine-C7OUmM1J.js.map +1 -0
- package/dist/chunks/config-file-BX3F_61U.js +24 -0
- package/dist/chunks/config-file-BX3F_61U.js.map +1 -0
- package/dist/chunks/css-definitions-BkdTqT7G.js +896 -0
- package/dist/chunks/css-definitions-BkdTqT7G.js.map +1 -0
- package/dist/chunks/css-resources-C0zT36nQ.js +141 -0
- package/dist/chunks/css-resources-C0zT36nQ.js.map +1 -0
- package/dist/chunks/debug-CwGMB2RI.js +501 -0
- package/dist/chunks/debug-CwGMB2RI.js.map +1 -0
- package/dist/chunks/dsl-BAwiOznp.js +1442 -0
- package/dist/chunks/dsl-BAwiOznp.js.map +1 -0
- package/dist/chunks/hydration-DEmoq1sQ.js +39 -0
- package/dist/chunks/hydration-DEmoq1sQ.js.map +1 -0
- package/dist/chunks/react-runtime-B8YqpFx7.js +678 -0
- package/dist/chunks/react-runtime-B8YqpFx7.js.map +1 -0
- package/dist/chunks/runtime-engine-CHNH2nGy.js +2418 -0
- package/dist/chunks/runtime-engine-CHNH2nGy.js.map +1 -0
- package/dist/chunks/runtime-state-BxLKsQzs.js +150 -0
- package/dist/chunks/runtime-state-BxLKsQzs.js.map +1 -0
- package/dist/{merge-styles-DuoZEsm9.js → chunks/shared-utils-CYgOs2mp.js} +58 -57
- package/dist/chunks/shared-utils-CYgOs2mp.js.map +1 -0
- package/dist/chunks/style-engine-DkKH-TqL.js +5573 -0
- package/dist/chunks/style-engine-DkKH-TqL.js.map +1 -0
- package/dist/{css-writer-Bgowobbx.js → chunks/zero-engine-C-0ar_PT.js} +67 -149
- package/dist/chunks/zero-engine-C-0ar_PT.js.map +1 -0
- package/dist/{collector-BTVXj2hS.d.ts → collector-BN6hCWIx.d.ts} +3 -6
- package/dist/{config-LfIDmVHx.d.ts → config-Chmu-PnP.d.ts} +49 -63
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/hydrate-CTh8SGd9.d.ts +20 -0
- package/dist/{index-Bm9ltvdH.d.ts → index-szujmf6W.d.ts} +263 -348
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -922
- package/dist/merge-styles-Cx25bpax.d.ts +4 -0
- package/dist/ssr/astro-client.d.ts +1 -1
- package/dist/ssr/astro-client.js +2 -16
- package/dist/ssr/astro-client.js.map +1 -1
- package/dist/ssr/astro-middleware-extract-static.d.ts +1 -4
- package/dist/ssr/astro-middleware-extract-static.js +1 -2
- package/dist/ssr/astro-middleware-extract.d.ts +1 -4
- package/dist/ssr/astro-middleware-extract.js +1 -2
- package/dist/ssr/astro-middleware-static.d.ts +1 -4
- package/dist/ssr/astro-middleware-static.js +2 -14
- package/dist/ssr/astro-middleware-static.js.map +1 -1
- package/dist/ssr/astro-middleware.d.ts +1 -4
- package/dist/ssr/astro-middleware.js +2 -15
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +17 -19
- package/dist/ssr/astro.js +218 -1
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +1 -0
- package/dist/ssr/index.d.ts +5 -27
- package/dist/ssr/index.js +6 -7
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +63 -0
- package/dist/ssr/next-config.js +122 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -10
- package/dist/ssr/next.js +30 -45
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +8 -13
- package/dist/static/index.js +6 -26
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.d.ts +1 -4
- package/dist/static/inject.js +1 -2
- package/dist/{index-BmogEzTo.d.ts → types-DbMN-Yyn.d.ts} +1013 -1043
- package/dist/zero/babel.d.ts +71 -2
- package/dist/zero/babel.js +84 -150
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +61 -12
- package/dist/zero/index.js +24 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +5 -7
- package/dist/zero/next.js +4 -40
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +4 -1
- package/docs/adoption.md +25 -17
- package/docs/ai-agents.md +69 -34
- package/docs/comparison.md +9 -8
- package/docs/configuration.md +204 -70
- package/docs/debug.md +18 -7
- package/docs/design-system.md +129 -15
- package/docs/dsl.md +327 -117
- package/docs/getting-started.md +81 -22
- package/docs/injector.md +41 -40
- package/docs/llms.txt +31 -0
- package/docs/methodology.md +48 -23
- package/docs/migration-v3.md +3 -3
- package/docs/pipeline.md +55 -28
- package/docs/plugins.md +22 -42
- package/docs/react-api.md +76 -11
- package/docs/runtime-benchmarks.md +257 -47
- package/docs/ssr.md +226 -80
- package/docs/styles.md +169 -33
- package/docs/tasty-static.md +176 -58
- package/harness/dev.harnesspm/rules/usage.md +12 -0
- package/harness/dev.harnesspm/scripts/render.mjs +320 -0
- package/harness/dev.harnesspm/scripts/styles.mjs +299 -0
- package/harness/plugin.json +20 -0
- package/package.json +116 -48
- package/tasty.config.ts +1 -0
- package/dist/astro-ib7E7V4Y.js +0 -307
- package/dist/astro-ib7E7V4Y.js.map +0 -1
- package/dist/async-storage-DKK-wTD4.js +0 -44
- package/dist/async-storage-DKK-wTD4.js.map +0 -1
- package/dist/babel-DWCsafYw.d.ts +0 -83
- package/dist/collector-C6TtL8HJ.js.map +0 -1
- package/dist/config-B3gPdCqd.js +0 -12421
- package/dist/config-B3gPdCqd.js.map +0 -1
- package/dist/context-CA8YKeMn.js +0 -24
- package/dist/context-CA8YKeMn.js.map +0 -1
- package/dist/core-Bq7w2kti.js +0 -1686
- package/dist/core-Bq7w2kti.js.map +0 -1
- package/dist/css-writer-Bgowobbx.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-rCZ37rqY.js +0 -130
- package/dist/format-rules-rCZ37rqY.js.map +0 -1
- package/dist/hydrate-CNOmZprz.js +0 -37
- package/dist/hydrate-CNOmZprz.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-DE-OE76F.js +0 -535
- package/dist/keyframes-DE-OE76F.js.map +0 -1
- package/dist/merge-styles-BcLl1u_d.d.ts +0 -7
- package/dist/merge-styles-DuoZEsm9.js.map +0 -1
- package/dist/resolve-recipes-H9NqOQuP.js +0 -144
- package/dist/resolve-recipes-H9NqOQuP.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
|
|
|
@@ -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 `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 |
|
|
@@ -691,24 +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
|
-
|
|
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
|
+
}
|
|
700
716
|
}
|
|
701
717
|
@media (prefers-color-scheme: dark) {
|
|
702
|
-
.t1:not([data-hovered]) {
|
|
718
|
+
.t1.t1:where(:not([data-hovered])) {
|
|
703
719
|
color: var(--dark-color);
|
|
704
720
|
--current-color: var(--dark-color);
|
|
705
721
|
}
|
|
706
722
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
--current-color: var(--white-color);
|
|
711
|
-
}
|
|
723
|
+
.t1.t1:where([data-hovered]) {
|
|
724
|
+
color: var(--highlight-color);
|
|
725
|
+
--current-color: var(--highlight-color);
|
|
712
726
|
}
|
|
713
727
|
```
|
|
714
728
|
|
|
@@ -739,3 +753,16 @@ Impossible combinations are detected at multiple levels (simplification, variant
|
|
|
739
753
|
### 4. Aggressive Caching
|
|
740
754
|
|
|
741
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,7 +37,7 @@ 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
|
|
|
@@ -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
|
});
|
|
@@ -159,7 +164,7 @@ 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
169
|
`configure()` may run _after_ your components are defined — each factory resolves its prop list lazily and refreshes when the registry changes.
|
|
165
170
|
|
|
@@ -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
|
-
|
|
178
|
-
declare module '@tenphi/tasty' {
|
|
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
|
-
```
|
|
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.
|
|
201
178
|
|
|
202
|
-
|
|
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
|
|
@@ -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
|
}
|
|
@@ -299,6 +274,8 @@ configure({ plugins: [glazePlugin()] });
|
|
|
299
274
|
|
|
300
275
|
```ts
|
|
301
276
|
// tasty.d.ts
|
|
277
|
+
import '@tenphi/tasty';
|
|
278
|
+
|
|
302
279
|
declare module '@tenphi/tasty' {
|
|
303
280
|
interface TastyCustomProps {
|
|
304
281
|
glaze: import('./glaze-plugin').GlazeConfig | string;
|
|
@@ -327,17 +304,20 @@ The object value is unambiguous here precisely because `glaze` is a **prop**. A
|
|
|
327
304
|
## Testing a plugin
|
|
328
305
|
|
|
329
306
|
```ts
|
|
330
|
-
import {
|
|
307
|
+
import { resetConfig, renderStyles } from '@tenphi/tasty';
|
|
308
|
+
import type { PropHandler, Styles } from '@tenphi/tasty';
|
|
331
309
|
|
|
332
310
|
describe('glaze plugin', () => {
|
|
333
311
|
beforeEach(() => resetConfig());
|
|
334
312
|
afterEach(() => resetConfig());
|
|
335
313
|
|
|
336
|
-
it('
|
|
337
|
-
|
|
314
|
+
it('turns the glaze prop into styles', () => {
|
|
315
|
+
const glaze = glazePlugin().propHandlers!.glaze as PropHandler;
|
|
316
|
+
const out = glaze({ glaze: 'purple' })!;
|
|
338
317
|
|
|
339
|
-
|
|
318
|
+
expect(out).not.toHaveProperty('glaze');
|
|
340
319
|
|
|
320
|
+
const rules = renderStyles(out.styles as Styles, '.test');
|
|
341
321
|
expect(rules[0].declarations).toContain('--glaze-bg-color');
|
|
342
322
|
});
|
|
343
323
|
});
|
|
@@ -345,7 +325,7 @@ describe('glaze plugin', () => {
|
|
|
345
325
|
|
|
346
326
|
Two things to know:
|
|
347
327
|
|
|
348
|
-
- **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.
|
|
349
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.
|
|
350
330
|
|
|
351
331
|
---
|
package/docs/react-api.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Use `tasty()` to turn state-aware style definitions into normal React components, extend existing Tasty components, and expose typed styling APIs to consumers.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Every Tasty style function — `tasty()` components, `computeStyles()`, `useStyles()`, `useGlobalStyles()`, `useRawCSS()`, `useKeyframes()`, `useProperty()`, `useFontFace()`, `useCounterStyle()`, and `useFunction()` — works in React Server Components with no `'use client'` directive. All of them except `useStyles()` are hook-free. `useStyles()` reads the `TastyRegistry` collector from React context on the client, so it is a real hook there; outside React, call `computeStyles()` instead. For state maps, tokens, units, and extension semantics, see [Style DSL](dsl.md). For global configuration, see [Configuration](configuration.md). For the broader docs map, see the [Docs Hub](README.md).
|
|
6
6
|
|
|
7
7
|
> **Note:** This file was previously named `runtime.md`. All functionality documented here works in both server and client contexts — "runtime" referred to style computation during React rendering, not to client-side JavaScript.
|
|
8
8
|
|
|
@@ -44,6 +44,30 @@ const PrimaryButton = tasty(Button, {
|
|
|
44
44
|
|
|
45
45
|
Style maps merge intelligently — see [Style DSL — Extending vs. Replacing State Maps](dsl.md#extending-vs-replacing-state-maps) for extend mode, replace mode, `@inherit`, `null`, and `false` tombstones.
|
|
46
46
|
|
|
47
|
+
The extension form takes the same component options as `tasty({ … })`:
|
|
48
|
+
|
|
49
|
+
```jsx
|
|
50
|
+
const ActionCard = tasty(Card, {
|
|
51
|
+
styles: { fill: { '': '#surface', isRaised: '#surface-raised' } },
|
|
52
|
+
styleProps: ['gap'] as const, // gap="2x" becomes a style
|
|
53
|
+
modProps: ['isRaised'] as const, // isRaised becomes a mod (data-is-raised)
|
|
54
|
+
tokenProps: ['accentColor'] as const, // accentColor sets the #accent token
|
|
55
|
+
variants: {
|
|
56
|
+
plain: { border: 0 },
|
|
57
|
+
framed: { border: '2bw #accent' },
|
|
58
|
+
},
|
|
59
|
+
variant: 'framed', // applied when no variant prop is passed
|
|
60
|
+
elements: { Footer: 'footer' },
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
<ActionCard gap="2x" isRaised accentColor="#purple">
|
|
64
|
+
<ActionCard.Title>Kept from Card</ActionCard.Title>
|
|
65
|
+
<ActionCard.Footer>Added here</ActionCard.Footer>
|
|
66
|
+
</ActionCard>;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The extension turns its own `styleProps`, `modProps`, and `tokenProps` into the `styles`, `mods`, and `tokens` it passes to the base, which renders them as usual: mods as `data-*` attributes, tokens as inline custom properties. Its `variants` merge over its `styles`, and the `variant` prop is still forwarded, so it selects the base's own variants too and accepts either set's names. Both sets share that one prop, so a name only one of them defines leaves the other at its fallback: if `Card` had an `accent` variant, `variant="accent"` would apply it together with `framed`, and `variant="plain"` would leave `Card` on its default. For two independent choices, give one of them its own prop, such as a `modProps` value list. `elements` adds sub-components, and the base's are kept: `ActionCard.Title` is `Card.Title`. The returned component is typed with all of these props and sub-components.
|
|
70
|
+
|
|
47
71
|
`tasty(Component, ...)` always wraps `Component` and forwards every prop to it, so `Component` must be Tasty-aware (i.e. it accepts `styles`, `mods`, `qa`, etc. and renders them through its own Tasty pipeline). To apply styles to a third-party component or a string DOM tag via `className`, use the options-only form with `as`:
|
|
48
72
|
|
|
49
73
|
```jsx
|
|
@@ -68,7 +92,9 @@ const Span = tasty({
|
|
|
68
92
|
</Link>;
|
|
69
93
|
```
|
|
70
94
|
|
|
71
|
-
The wrapped component only needs to forward `className` (and ideally `style`/`ref`). Tasty
|
|
95
|
+
The wrapped component only needs to forward `className` (and ideally `style`/`ref`). Tasty's own props (`styles`, `mods`, `tokens`, `qa`, `qaVal`, `theme`, `element`, the `is*` props) and the props you declared with `styleProps`, `modProps`, or `tokenProps` are consumed by Tasty; mods, `qa`, `qaVal`, `theme`, and `element` reach the DOM only as `data-*` attributes.
|
|
96
|
+
|
|
97
|
+
Props forwarded to the `as` component keep their declared types and requiredness. For example, a component with `position: 'top-right' | 'bottom-left'` accepts those values through `tasty({ as: Component })`; CSS positioning can still be set through `styles.position`. A prop explicitly listed in `styleProps` is consumed as a style value instead. The always-available base style props below are also consumed by Tasty, so keep component-specific prop names separate from those reserved names.
|
|
72
98
|
|
|
73
99
|
---
|
|
74
100
|
|
|
@@ -110,12 +136,12 @@ A small set of style properties — `display`, `font`, `preset`, `hide`, `whiteS
|
|
|
110
136
|
|
|
111
137
|
## `Element`
|
|
112
138
|
|
|
113
|
-
`Element` is the unstyled base component exported from the main entry — equivalent to `tasty({})` (a `div` with no default styles). It accepts
|
|
139
|
+
`Element` is the unstyled base component exported from the main entry — equivalent to `tasty({})` (a `div` with no default styles). It accepts the props every Tasty component has (`as`, `styles`, `mods`, `tokens`, `qa`, `theme`, the `is*` props) plus the [always-available style props](#always-available-style-props), and is useful as a generic box or as a building block for layout primitives. Other style names, such as `padding`, are not props on it: create a component with `styleProps` for those, or pass them through `styles`.
|
|
114
140
|
|
|
115
141
|
```jsx
|
|
116
142
|
import { Element } from '@tenphi/tasty';
|
|
117
143
|
|
|
118
|
-
<Element as="section"
|
|
144
|
+
<Element as="section" display="grid" preset="t2" styles={{ padding: '4x' }}>
|
|
119
145
|
Content
|
|
120
146
|
</Element>;
|
|
121
147
|
```
|
|
@@ -142,6 +168,7 @@ List modifier key names. Types default to `ModValue` (`boolean | string | number
|
|
|
142
168
|
|
|
143
169
|
```jsx
|
|
144
170
|
const Button = tasty({
|
|
171
|
+
as: 'button',
|
|
145
172
|
modProps: ['isLoading', 'isSelected'] as const,
|
|
146
173
|
styles: {
|
|
147
174
|
fill: { '': '#surface', isLoading: '#surface.5' },
|
|
@@ -159,6 +186,7 @@ Map modifier names to type descriptors for precise TypeScript types:
|
|
|
159
186
|
|
|
160
187
|
```tsx
|
|
161
188
|
const Button = tasty({
|
|
189
|
+
as: 'button',
|
|
162
190
|
modProps: {
|
|
163
191
|
isLoading: Boolean, // isLoading?: boolean
|
|
164
192
|
isSelected: Boolean, // isSelected?: boolean
|
|
@@ -295,6 +323,24 @@ const Button = tasty({
|
|
|
295
323
|
<Button variant="danger">Delete</Button>;
|
|
296
324
|
```
|
|
297
325
|
|
|
326
|
+
With `variant` omitted, or set to a key `variants` does not define, the `default` variant applies; without a `default` key only the base `styles` apply. `variant` is typed from the variant keys.
|
|
327
|
+
|
|
328
|
+
To fall back to another variant instead, name it in the `variant` option:
|
|
329
|
+
|
|
330
|
+
```jsx
|
|
331
|
+
const Button = tasty({
|
|
332
|
+
styles: { padding: '2x 4x' },
|
|
333
|
+
variants: {
|
|
334
|
+
primary: { fill: '#blue', color: '#white' },
|
|
335
|
+
danger: { fill: '#red', color: '#white' },
|
|
336
|
+
},
|
|
337
|
+
variant: 'primary',
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
<Button>Save</Button>; // primary
|
|
341
|
+
<Button variant="danger">Delete</Button>;
|
|
342
|
+
```
|
|
343
|
+
|
|
298
344
|
### Extending Variants with Base State Maps
|
|
299
345
|
|
|
300
346
|
When base `styles` contain an extend-mode state map (an object **without** a `''` key), it is applied **after** the variant merge. This lets you add or override states across all variants without repeating yourself:
|
|
@@ -310,7 +356,7 @@ const Badge = tasty({
|
|
|
310
356
|
variants: {
|
|
311
357
|
primary: {
|
|
312
358
|
border: { '': '#white.2', pressed: '#primary-text', disabled: '#clear' },
|
|
313
|
-
fill: { '': '#
|
|
359
|
+
fill: { '': '#primary', hovered: '#primary-text' },
|
|
314
360
|
},
|
|
315
361
|
secondary: {
|
|
316
362
|
border: { '': '#primary.15', pressed: '#primary.3' },
|
|
@@ -360,7 +406,7 @@ elements: {
|
|
|
360
406
|
}
|
|
361
407
|
```
|
|
362
408
|
|
|
363
|
-
The sub-components produced by `elements` support `mods`, `tokens`, `isDisabled`, `isHidden`, and `isChecked` props — the same modifier interface as the root component.
|
|
409
|
+
The sub-components produced by `elements` support `mods`, `tokens`, `theme`, `isDisabled`, `isHidden`, and `isChecked` props — the same modifier interface as the root component. As on the root, `theme` renders as `data-theme`, and an explicit `data-theme` wins over it.
|
|
364
410
|
|
|
365
411
|
If you don't need sub-components (e.g., the inner elements are already rendered by a third-party library), you can still style them by key alone — just omit `elements` and apply `data-element` manually:
|
|
366
412
|
|
|
@@ -399,19 +445,19 @@ const { className } = computeStyles({
|
|
|
399
445
|
});
|
|
400
446
|
```
|
|
401
447
|
|
|
402
|
-
On the client, CSS is injected synchronously into the DOM (idempotent via the injector cache). On the server, CSS
|
|
448
|
+
On the client, CSS is injected synchronously into the DOM (idempotent via the injector cache). On the server with an SSR collector (from `runWithCollector()` or `TastyRegistry`), the CSS goes to the collector. With neither a collector nor a `document` — a React Server Component — nothing is injected: the CSS comes back as `css`, and you render it in a `style` tag yourself, as `tasty()` components do. This is the same function that `tasty()` components use internally.
|
|
403
449
|
|
|
404
450
|
---
|
|
405
451
|
|
|
406
452
|
## Style Functions
|
|
407
453
|
|
|
408
|
-
All style functions below
|
|
454
|
+
All style functions below work in client components, SSR with a `ServerStyleCollector`, and React Server Components. All except `useStyles()` are plain functions, not React hooks; they keep the `use` prefix for backward compatibility.
|
|
409
455
|
|
|
410
456
|
In server-only contexts, components that use only Tasty style functions ship no Tasty styling runtime. Astro without `client:*` directives produces no client JavaScript; server-only Next.js RSC follows the same Tasty architecture, while final output depends on the application deployment. Tasty never forces the `'use client'` boundary — that decision belongs to your component when it needs React interactivity (state, effects, event handlers).
|
|
411
457
|
|
|
412
458
|
### useStyles
|
|
413
459
|
|
|
414
|
-
Generate a className from a style object.
|
|
460
|
+
Generate a className from a style object. A thin wrapper around `computeStyles()` that also picks up the `TastyRegistry` collector through React context. That makes it a hook on the client: call it inside a component, and use `computeStyles()` outside React. It also works in a Server Component, where it skips the context lookup; like the other style functions there, it cannot emit CSS itself, so the next `tasty()` element in the tree emits it.
|
|
415
461
|
|
|
416
462
|
```tsx
|
|
417
463
|
import { useStyles } from '@tenphi/tasty';
|
|
@@ -445,6 +491,17 @@ function ThemeStyles() {
|
|
|
445
491
|
}
|
|
446
492
|
```
|
|
447
493
|
|
|
494
|
+
The selector can be a list (`'.uni-checkbox, uni-checkbox'`) — every item gets
|
|
495
|
+
the states and sub-elements, with no `:is()` wrapping needed. Root states
|
|
496
|
+
(`@root(...)`) on a selector that is the root itself (`:root`, `html`) apply to
|
|
497
|
+
that element. A selector that ends in a pseudo-element takes its states on the
|
|
498
|
+
pseudo-element (`'.card::before'` with `:hover` gives
|
|
499
|
+
`.card::before:where(:hover)`) and `@parent()` on the element before it.
|
|
500
|
+
Attribute and modifier states, which a pseudo-element can't have, are ignored
|
|
501
|
+
with a warning. Local `@keyframes` are injected with the rules,
|
|
502
|
+
under the same resolved names `tasty()` components use, and `@starting` states
|
|
503
|
+
emit `@starting-style`.
|
|
504
|
+
|
|
448
505
|
A slot — the `id`, or the selector when no `id` is given — holds exactly one
|
|
449
506
|
injection **per `root`**. So:
|
|
450
507
|
|
|
@@ -473,6 +530,8 @@ function GlobalReset() {
|
|
|
473
530
|
An `id` slot holds one injection per `root`. Without an `id` the CSS is deduped
|
|
474
531
|
by content and permanent — there is nothing to replace it with later.
|
|
475
532
|
|
|
533
|
+
It also accepts a factory and deps — `useRawCSS(() => css, [deps], { id })` — and skips the factory while the deps for that `id` are unchanged.
|
|
534
|
+
|
|
476
535
|
### useKeyframes
|
|
477
536
|
|
|
478
537
|
Inject `@keyframes` rules and return the generated animation name:
|
|
@@ -582,7 +641,11 @@ useFontFace('Brand Sans', [
|
|
|
582
641
|
Signature:
|
|
583
642
|
|
|
584
643
|
```ts
|
|
585
|
-
function useFontFace(
|
|
644
|
+
function useFontFace(
|
|
645
|
+
family: string,
|
|
646
|
+
input: FontFaceInput,
|
|
647
|
+
options?: { root?: Document | ShadowRoot },
|
|
648
|
+
): void;
|
|
586
649
|
```
|
|
587
650
|
|
|
588
651
|
### useCounterStyle
|
|
@@ -664,9 +727,10 @@ See the [Functions section of the DSL reference](dsl.md#functions-function) for
|
|
|
664
727
|
|
|
665
728
|
- Styles are not updating: make sure `configure()` runs before first render, and verify the generated class name or global rule with [Debug Utilities](debug.md).
|
|
666
729
|
- SSR output looks wrong: check the [SSR guide](ssr.md) for collector setup. All style functions discover the SSR collector via `AsyncLocalStorage` or the global getter registered by `TastyRegistry`.
|
|
730
|
+
- "Server rendering without a style collector" in development: the server render has no request scope, so each `tasty()` element inlines its own CSS and configured globals are not emitted. Add `tastyIntegration()` (Astro), `TastyRegistry` (Next.js), or `runWithCollector()` — see the [SSR guide](ssr.md).
|
|
667
731
|
- Animation/custom property issues: prefer `useKeyframes()` and `useProperty()` over raw CSS when you want Tasty to manage injection and SSR collection for you.
|
|
668
732
|
- For dynamic styles that change over the component lifecycle, use the `id` option in `useGlobalStyles()` and `useRawCSS()` to enable update tracking.
|
|
669
|
-
- RSC inline mode: CSS accumulated by standalone style functions (`useGlobalStyles`, `useRawCSS`, etc.) is flushed into inline `<style>` tags by the next `tasty()` component in the render tree. If your page uses only standalone style functions without any `tasty()` component, the CSS will not be emitted. Ensure at least one `tasty()` component is present in each RSC render tree.
|
|
733
|
+
- RSC inline mode: CSS accumulated by standalone style functions (`useStyles`, `useGlobalStyles`, `useRawCSS`, etc.) is flushed into inline `<style>` tags by the next `tasty()` component in the render tree. If your page uses only standalone style functions without any `tasty()` component, the CSS will not be emitted. Ensure at least one `tasty()` component is present in each RSC render tree.
|
|
670
734
|
|
|
671
735
|
---
|
|
672
736
|
|
|
@@ -675,6 +739,7 @@ See the [Functions section of the DSL reference](dsl.md#functions-function) for
|
|
|
675
739
|
- **[Style DSL](dsl.md)** — State maps, tokens, units, extending semantics, keyframes, @property
|
|
676
740
|
- **[Methodology](methodology.md)** — Recommended patterns: root + sub-elements, styleProps, tokens, wrapping
|
|
677
741
|
- **[Configuration](configuration.md)** — Tokens, recipes, custom units, style handlers, TypeScript extensions
|
|
742
|
+
- **[Configuration → TypeScript](configuration.md#typescript)** — How props are typed and how to register your names
|
|
678
743
|
- **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
|
|
679
744
|
- **[Build-Time Extraction (`tastyStatic`)](tasty-static.md)** — Static styling with the Babel plugin
|
|
680
745
|
- **[Server-Side Rendering](ssr.md)** — SSR setup for Next.js, Astro, and generic frameworks
|