@tenphi/tasty 0.0.0-snapshot.a8b4749 → 0.0.0-snapshot.a8da86e
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 +181 -136
- package/dist/babel-types-C_7kRP38.d.ts +18 -0
- package/dist/chunks/async-storage-CG5HnUT5.js +20 -0
- package/dist/chunks/async-storage-CG5HnUT5.js.map +1 -0
- package/dist/chunks/build-config-Betc6IB6.js +60 -0
- package/dist/chunks/build-config-Betc6IB6.js.map +1 -0
- package/dist/{collector-C-keQH9m.js → chunks/collector-DqqisglQ.js} +68 -101
- package/dist/chunks/collector-DqqisglQ.js.map +1 -0
- package/dist/chunks/config-engine-BPeROwq2.js +272 -0
- package/dist/chunks/config-engine-BPeROwq2.js.map +1 -0
- package/dist/chunks/css-definitions-IeuyJTGk.js +899 -0
- package/dist/chunks/css-definitions-IeuyJTGk.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-P1E2jkj7.js +502 -0
- package/dist/chunks/debug-P1E2jkj7.js.map +1 -0
- package/dist/chunks/dsl-DRhFWQzo.js +1378 -0
- package/dist/chunks/dsl-DRhFWQzo.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-XMBbGRes.js +582 -0
- package/dist/chunks/react-runtime-XMBbGRes.js.map +1 -0
- package/dist/chunks/runtime-engine-CsIMtulO.js +2415 -0
- package/dist/chunks/runtime-engine-CsIMtulO.js.map +1 -0
- package/dist/chunks/runtime-state-CyKzDioI.js +141 -0
- package/dist/chunks/runtime-state-CyKzDioI.js.map +1 -0
- package/dist/{merge-styles-Cd2vBl9b.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-RbokDN6A.js +5427 -0
- package/dist/chunks/style-engine-RbokDN6A.js.map +1 -0
- package/dist/{css-writer-BWvwQzz0.js → chunks/zero-engine-DbtjMsfo.js} +81 -137
- package/dist/chunks/zero-engine-DbtjMsfo.js.map +1 -0
- package/dist/{collector-osfWTeRd.d.ts → collector-w4mBj5gd.d.ts} +64 -8
- package/dist/{config-BoZDUHW5.d.ts → config-CrZOfNJ5.d.ts} +489 -85
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/{index-B_k47mc_.d.ts → index-CYJtAI9a.d.ts} +664 -399
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -732
- package/dist/{merge-styles-BMWcH6MF.d.ts → merge-styles-VXwJ0Frr.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 +163 -91
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/index.d.ts +10 -18
- package/dist/ssr/index.js +5 -5
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +64 -0
- package/dist/ssr/next-config.js +134 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -9
- 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/static/inject.js.map +1 -1
- package/dist/{index-tcHuMPFt.d.ts → types-JEY8PVYP.d.ts} +874 -593
- package/dist/zero/babel.d.ts +5 -19
- package/dist/zero/babel.js +74 -144
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +57 -7
- package/dist/zero/index.js +24 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +4 -5
- package/dist/zero/next.js +0 -31
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +17 -9
- package/docs/adoption.md +56 -31
- package/docs/ai-agents.md +250 -0
- package/docs/comparison.md +69 -40
- package/docs/configuration.md +487 -86
- package/docs/debug.md +26 -14
- package/docs/design-system.md +43 -24
- package/docs/dsl.md +558 -181
- package/docs/getting-started.md +64 -41
- package/docs/injector.md +120 -30
- package/docs/methodology.md +46 -40
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +87 -21
- package/docs/plugins.md +353 -0
- package/docs/react-api.md +151 -42
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +252 -86
- package/docs/styles.md +142 -25
- package/docs/tasty-static.md +174 -106
- package/package.json +127 -35
- package/tasty.config.ts +5 -0
- package/dist/async-storage-B7_o6FKt.js +0 -44
- package/dist/async-storage-B7_o6FKt.js.map +0 -1
- package/dist/collector-C-keQH9m.js.map +0 -1
- package/dist/config-BBiyxMCe.js +0 -10559
- package/dist/config-BBiyxMCe.js.map +0 -1
- package/dist/context-CkSg-kDT.js +0 -24
- package/dist/context-CkSg-kDT.js.map +0 -1
- package/dist/core-BO4319td.js +0 -1598
- package/dist/core-BO4319td.js.map +0 -1
- package/dist/css-writer-BWvwQzz0.js.map +0 -1
- package/dist/format-global-rules-Dbc_1tc3.js +0 -22
- package/dist/format-global-rules-Dbc_1tc3.js.map +0 -1
- package/dist/format-rules-BSjeH4Z7.js +0 -143
- package/dist/format-rules-BSjeH4Z7.js.map +0 -1
- package/dist/hydrate-CcvrP4qJ.js +0 -45
- package/dist/hydrate-CcvrP4qJ.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-BUQhdOSJ.js +0 -588
- package/dist/keyframes-BUQhdOSJ.js.map +0 -1
- package/dist/merge-styles-Cd2vBl9b.js.map +0 -1
- package/dist/resolve-recipes-C1nrvnYh.js +0 -144
- package/dist/resolve-recipes-C1nrvnYh.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
|
|
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. The `order` hint is the highest source priority among the entries that produced each rule (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
|
|
|
@@ -120,6 +124,8 @@ Removing don't-care dimensions before parsing prevents combinatorial blowup in l
|
|
|
120
124
|
|
|
121
125
|
Converts each state key in a style value map (like `'hovered & !disabled'`, `'@media(w < 768px)'`) into `ConditionNode` trees. `parseStyleEntries` walks the object keys in source order and assigns priorities; `parseStateKey` parses a single key string.
|
|
122
126
|
|
|
127
|
+
`parseStyleEntries` also handles the bare `''` default and the standalone `_` fallback floor before the priority order is finalized. The bare `''` default only behaves correctly as the lowest-priority state, so a misplaced one is moved to the front (`MISPLACED_DEFAULT_STATE` warning). The `_` key is pulled out as a separate floor entry (`floor: true`, `TrueCondition`) and always assigned the lowest priority. If a map defines only `_` and a bare `''` (no other states), the `''` default is redundant — it is dropped in favor of the `_` value (`REDUNDANT_DEFAULT_STATE` warning). A `_` combined with state logic (`_ & hovered`, `_ | x`) is ignored (`INVALID_FALLBACK_KEY` warning).
|
|
128
|
+
|
|
123
129
|
### How It Works
|
|
124
130
|
|
|
125
131
|
1. **Tokenization**: The state key is split into tokens using a regex pattern that recognizes:
|
|
@@ -195,6 +201,8 @@ The merge is safe iff for every entry `e_m` strictly between them in priority wi
|
|
|
195
201
|
|
|
196
202
|
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.
|
|
197
203
|
|
|
204
|
+
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.
|
|
205
|
+
|
|
198
206
|
### Why
|
|
199
207
|
|
|
200
208
|
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.
|
|
@@ -291,7 +299,35 @@ B: B & !A (applies only when A doesn't)
|
|
|
291
299
|
C: C & !A & !B (applies only when neither A nor B)
|
|
292
300
|
```
|
|
293
301
|
|
|
294
|
-
Each exclusive condition is passed through `simplifyCondition`. Entries that simplify to `FALSE` (impossible) are filtered out.
|
|
302
|
+
Each exclusive condition is passed through `simplifyCondition`. Entries that simplify to `FALSE` (impossible) are filtered out.
|
|
303
|
+
|
|
304
|
+
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.
|
|
305
|
+
|
|
306
|
+
### `_` fallback floor
|
|
307
|
+
|
|
308
|
+
An entry flagged `floor: true` (from the standalone `_` key) is the one
|
|
309
|
+
exception to the negation cascade above. `buildExclusiveConditions` **pulls the
|
|
310
|
+
floor entries out** before the negation pass, builds the remaining entries with a
|
|
311
|
+
plain unconditional negation loop, then re-appends each floor with its own
|
|
312
|
+
(`TRUE`) condition as the exclusive condition. So the floor **always applies**,
|
|
313
|
+
never receives `!prior`, and never negates lower-priority entries. Because its
|
|
314
|
+
condition is `TRUE`, Stage 1 `mergeEntriesByValue` already leaves it untouched
|
|
315
|
+
(same guard as the bare `''` default), so no floor-specific merge handling is
|
|
316
|
+
needed.
|
|
317
|
+
|
|
318
|
+
This exists to fix the *unknown-query hole*: CSS three-valued logic makes
|
|
319
|
+
`not(unknown) = unknown`, so a negated `@supports(...)` / container-query default
|
|
320
|
+
branch silently never applies. A `_` floor sidesteps negation entirely and lets
|
|
321
|
+
the positive override layer on top via the cascade (see Stage 7's `:where()`
|
|
322
|
+
equalization and the ascending-priority post-pass).
|
|
323
|
+
|
|
324
|
+
Because the floor is **additive** (always emitted, never negated) rather than
|
|
325
|
+
mutually exclusive, it differs observably from the `''` default in two ways
|
|
326
|
+
beyond the unknown-query fix: an "empty" higher-priority state (one that emits no
|
|
327
|
+
declarations) cannot unset the property — the floor still applies — and when
|
|
328
|
+
states emit different declaration sets, the floor's declarations bleed through
|
|
329
|
+
wherever a winning state does not override the same property. The `''` default,
|
|
330
|
+
being negated, swaps out cleanly. See the DSL guide's "`_` vs the `''` default".
|
|
295
331
|
|
|
296
332
|
### Why
|
|
297
333
|
|
|
@@ -333,22 +369,29 @@ This is the companion to **Stage 2a** (user-OR expansion). The split exists beca
|
|
|
333
369
|
|
|
334
370
|
1. Collect top-level OR branches of `exclusiveCondition`.
|
|
335
371
|
2. If there is no OR (single branch), the entry is unchanged. Pure selector ORs with no at-rule context are also left alone (materialization handles them via `:is()` / variant merging).
|
|
336
|
-
3. Otherwise `sortOrBranchesForExpansion` reorders branches
|
|
372
|
+
3. Otherwise `sortOrBranchesForExpansion` reorders branches by a three-tier rank — `@supports` branches first, then other at-rule branches (media / container / starting), then pure-selector branches. This is load-bearing for correctness (see below).
|
|
337
373
|
4. Each branch is made exclusive against prior branches: `branch & !prior[0] & !prior[1] & ...`, then simplified.
|
|
338
374
|
5. Impossible branches are dropped; expanded entries get a synthetic `stateKey` suffix like `[or:0]`.
|
|
339
375
|
|
|
340
376
|
### Why the sort matters
|
|
341
377
|
|
|
342
|
-
Consider `!A | !B` where A is an at-rule (e.g. `@supports(grid)`) and B is a modifier (e.g. `:has(foo)`):
|
|
378
|
+
**At-rules before selectors.** Consider `!A | !B` where A is an at-rule (e.g. `@supports(grid)`) and B is a modifier (e.g. `:has(foo)`):
|
|
343
379
|
|
|
344
380
|
- **With at-rule-first sort** (`!A`, then `!B & A`): the first branch emits "outside `@supports`", the second emits "inside `@supports` with `:not(:has(foo))`". Full coverage.
|
|
345
381
|
- **Without the sort** (`!B`, then `!A & B`): the first branch emits `:not(:has(foo))` as a bare selector with no at-rule context — leaking the rule outside `@supports`. The second is incomplete.
|
|
346
382
|
|
|
383
|
+
**`@supports` before other at-rules (Kleene logic).** A `@supports` feature query is special: anything ANDed with it can become *unknown* — not simply false — when the feature is unsupported. The canonical case is a feature guard over a dependent query, e.g. `@supports(container-type: scroll-state) & @(scroll-state(scrolled: block-end))` (`S & C`). The default's exclusive is `!(S & C) = !S | !C`, which `simplify` sorts alphabetically into `[!C, !S]`.
|
|
384
|
+
|
|
385
|
+
- **Expanding `!C` first** emits a bare `@container (not scroll-state(...))` rule. In a browser without `scroll-state` support that query is unknown (not false), so it matches nothing and the default `inset` is never applied — a coverage hole.
|
|
386
|
+
- **Expanding `!S` first** yields `!S | (S & !C)`: a bare `@supports (not (container-type: scroll-state))` fallback carrying the default, plus the dependent negation nested inside the supported scope. Full coverage, and the unsupported path never references the guarded query.
|
|
387
|
+
|
|
388
|
+
Because `!S | (S & !R) ≡ !S | !R` in two-valued logic, this reordering is a no-op for cases without an `@supports` guard. The same supports-first ordering is also applied in `makeOrBranchesExclusive` (`materialize.ts`) for ORs that survive nested inside an AND (e.g. `compact & (!S | !C)`).
|
|
389
|
+
|
|
347
390
|
The pre-build Stage 2a pass doesn't need this because user-authored ORs aren't produced by negation and their branches are expected to apply in each branch's own scope.
|
|
348
391
|
|
|
349
392
|
### Example (conceptual)
|
|
350
393
|
|
|
351
|
-
See the comment block in `exclusive.ts
|
|
394
|
+
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.
|
|
352
395
|
|
|
353
396
|
---
|
|
354
397
|
|
|
@@ -360,6 +403,8 @@ See the comment block in `exclusive.ts:500-523`: a default value whose higher-pr
|
|
|
360
403
|
|
|
361
404
|
Computes the Cartesian product of all style entries for a handler, creating snapshots of which value each style has for each possible state combination.
|
|
362
405
|
|
|
406
|
+
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.
|
|
407
|
+
|
|
363
408
|
### How It Works
|
|
364
409
|
|
|
365
410
|
1. Collect exclusive entries for each style the handler uses
|
|
@@ -419,6 +464,7 @@ Style handlers encapsulate the logic for translating design tokens (like `'2x'`)
|
|
|
419
464
|
### What It Does
|
|
420
465
|
|
|
421
466
|
Combines rules that have identical CSS output into a single rule with an OR condition.
|
|
467
|
+
Zero- and one-rule inputs return unchanged because no merge is possible.
|
|
422
468
|
|
|
423
469
|
### How It Works
|
|
424
470
|
|
|
@@ -470,7 +516,15 @@ Converts condition trees into actual CSS selectors and at-rules.
|
|
|
470
516
|
|
|
471
517
|
3. **Contradiction detection**: During variant merging, impossible combinations are dropped (e.g. conflicting media, root, or modifier negations).
|
|
472
518
|
|
|
473
|
-
4. **`materializeComputedRule`**: Groups variants by sorted at-rules plus root-prefix key; within each group, `mergeVariantsIntoSelectorGroups` merges variants that differ only in flat modifier/pseudo parts; builds selector strings and emits one or more `CSSRule` objects.
|
|
519
|
+
4. **`materializeComputedRule`**: Groups variants by sorted at-rules plus root-prefix key; within each group, `mergeVariantsIntoSelectorGroups` merges variants that differ only in flat modifier/pseudo parts; builds selector strings and emits one or more `CSSRule` objects. The rule's `order` hint (cascade priority) is propagated here for the post-pass sort.
|
|
520
|
+
|
|
521
|
+
5. **`:where()` specificity equalization**: Every stateful part of the selector is wrapped in `:where(...)` so it contributes **zero specificity**:
|
|
522
|
+
- the flat root modifiers + pseudos and the root element's `:is()`/`:not()` groups are combined into one `:where(...)` (`buildSelectorFromVariant`);
|
|
523
|
+
- 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;
|
|
524
|
+
- `@parent` ancestors (`parentGroupsToCSS`) become `:where(... *)` / `:where(:not(... *))`;
|
|
525
|
+
- 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.
|
|
526
|
+
|
|
527
|
+
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.
|
|
474
528
|
|
|
475
529
|
### Why
|
|
476
530
|
|
|
@@ -491,10 +545,12 @@ interface CSSRule {
|
|
|
491
545
|
declarations: string; // CSS declarations (e.g. 'color: red;')
|
|
492
546
|
atRules?: string[]; // Wrapping at-rules
|
|
493
547
|
rootPrefix?: string; // Root state prefix
|
|
548
|
+
startingStyle?: boolean; // Wrap declarations in @starting-style
|
|
549
|
+
order?: number; // Internal cascade order hint (ascending source priority); stripped before injection
|
|
494
550
|
}
|
|
495
551
|
```
|
|
496
552
|
|
|
497
|
-
When `
|
|
553
|
+
When `renderStyles` runs **without** a selector, returned rules include `needsClassName: true` (compatibility field for the injector); that flag is not part of `CSSRule` inside `materialize.ts`.
|
|
498
554
|
|
|
499
555
|
---
|
|
500
556
|
|
|
@@ -562,7 +618,7 @@ Applies boolean algebra rules to reduce condition complexity and detect impossib
|
|
|
562
618
|
- `A & (A | B) = A`
|
|
563
619
|
- `A | (A & B) = A`
|
|
564
620
|
|
|
565
|
-
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).
|
|
621
|
+
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.
|
|
566
622
|
|
|
567
623
|
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).
|
|
568
624
|
|
|
@@ -638,7 +694,7 @@ The default entry's exclusive is `!hovered & !@media(dark)` — no top-level OR,
|
|
|
638
694
|
|
|
639
695
|
### Stages 4–5: Compute combinations and call handler
|
|
640
696
|
|
|
641
|
-
Single style, three snapshots; the `color` handler emits `color` plus `--current-color
|
|
697
|
+
Single style, three snapshots; the `color` handler emits `color` plus a `--current-color` variable.
|
|
642
698
|
|
|
643
699
|
### Stage 6: Merge by value
|
|
644
700
|
|
|
@@ -646,26 +702,23 @@ Each snapshot yields distinct declarations; no merge.
|
|
|
646
702
|
|
|
647
703
|
### Stage 7: Materialize CSS
|
|
648
704
|
|
|
649
|
-
Using `renderStyles(styles, '.t1')` (
|
|
705
|
+
Using `renderStyles(styles, '.t1')` (the class is doubled — `.t1.t1` — so Tasty owns specificity without `!important`):
|
|
650
706
|
|
|
651
707
|
```css
|
|
652
708
|
.t1[data-hovered] {
|
|
653
709
|
color: var(--highlight-color);
|
|
654
710
|
--current-color: var(--highlight-color);
|
|
655
|
-
--current-color-oklch: var(--highlight-color-oklch);
|
|
656
711
|
}
|
|
657
712
|
@media (prefers-color-scheme: dark) {
|
|
658
713
|
.t1:not([data-hovered]) {
|
|
659
714
|
color: var(--dark-color);
|
|
660
715
|
--current-color: var(--dark-color);
|
|
661
|
-
--current-color-oklch: var(--dark-color-oklch);
|
|
662
716
|
}
|
|
663
717
|
}
|
|
664
718
|
@media (not (prefers-color-scheme: dark)) {
|
|
665
719
|
.t1:not([data-hovered]) {
|
|
666
720
|
color: var(--white-color);
|
|
667
721
|
--current-color: var(--white-color);
|
|
668
|
-
--current-color-oklch: var(--white-color-oklch);
|
|
669
722
|
}
|
|
670
723
|
}
|
|
671
724
|
```
|
|
@@ -697,3 +750,16 @@ Impossible combinations are detected at multiple levels (simplification, variant
|
|
|
697
750
|
### 4. Aggressive Caching
|
|
698
751
|
|
|
699
752
|
Parse, simplify, condition-to-CSS, and full-pipeline results are cached independently, enabling fast re-rendering when only parts of the style object change.
|
|
753
|
+
|
|
754
|
+
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.
|
|
755
|
+
|
|
756
|
+
---
|
|
757
|
+
|
|
758
|
+
## Testing Priority
|
|
759
|
+
|
|
760
|
+
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:
|
|
761
|
+
|
|
762
|
+
- `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.
|
|
763
|
+
- `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.
|
|
764
|
+
|
|
765
|
+
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,353 @@
|
|
|
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** for `tokens` and `globalStyles` (per selector). See [Configuration](configuration.md) for the current per-key semantics.
|
|
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.
|
|
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
|
+
|
|
112
|
+
configure({
|
|
113
|
+
propHandlers: {
|
|
114
|
+
glaze: (props) => {
|
|
115
|
+
const { glaze, ...rest } = props;
|
|
116
|
+
if (!glaze) return rest;
|
|
117
|
+
|
|
118
|
+
return { ...rest, styles: mergeStyles(glazeStyles(glaze), rest.styles) };
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**The key is the trigger.** By default a handler runs only when a prop matching its key is present, so an absent prop costs one property check rather than a call. Override that with a tuple:
|
|
125
|
+
|
|
126
|
+
| Definition | Runs when |
|
|
127
|
+
| ------------------------- | ------------------------------------- |
|
|
128
|
+
| `fn` | a prop named after the key is present |
|
|
129
|
+
| `['glaze', fn]` | `glaze` is present |
|
|
130
|
+
| `[['glaze', 'tint'], fn]` | either is present |
|
|
131
|
+
| `['*', fn]` | always |
|
|
132
|
+
|
|
133
|
+
**Chaining.** Handlers run in registration order — plugins first, then direct `configure()` — and each receives the previous one's output. Registering the same key twice replaces the handler in place, keeping its position.
|
|
134
|
+
|
|
135
|
+
**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.
|
|
136
|
+
|
|
137
|
+
### Rules
|
|
138
|
+
|
|
139
|
+
- **Be pure. Never mutate the input.** Style values are cached by object identity, so mutating a value object in place yields a stale class name _and_ stale CSS. Return fresh objects.
|
|
140
|
+
- **Memoize the styles you build, per input value.** A reference-stable (ideally frozen) styles object lets the cache key reuse its serialization instead of recomputing it on every render. This is the single highest-leverage thing you can do for performance.
|
|
141
|
+
- **Precedence is fixed** and not adjustable from a handler. Styles are merged as `factory defaults → styles → harvested style props`, and injected styles occupy the `styles` slot: they beat a component's own default styles and lose to a style prop passed at the call site. This matches how `recipe` already behaves.
|
|
142
|
+
- **Prefer returning `styles` over bare style props.** Returning `{ fill: '#red' }` only works if `fill` is harvestable on _that_ component (in its `styleProps`, or promoted via `baseStyleProps`); otherwise it leaks to the DOM.
|
|
143
|
+
|
|
144
|
+
### What it cannot do
|
|
145
|
+
|
|
146
|
+
- **`ref`** — `forwardRef` separates it from props, so it is out of reach.
|
|
147
|
+
- **Sub-elements** (`Card.Title`) — they have no `styles` prop and no style-prop harvest, so middleware does not run on them.
|
|
148
|
+
- **Build-time extraction** — see [Rendering modes](#rendering-modes-and-caveats).
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Base style props
|
|
153
|
+
|
|
154
|
+
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:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
configure({ baseStyleProps: ['radius', 'shadow'] });
|
|
158
|
+
|
|
159
|
+
<Card radius="1r" shadow />
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Names must be real style properties, must start with a lowercase letter, and must not collide with a prop `tasty()` consumes itself (`as`, `styles`, `variant`, `mods`, `tokens`, …); invalid entries are dropped with a development warning.
|
|
163
|
+
|
|
164
|
+
`configure()` may run _after_ your components are defined — each factory resolves its prop list lazily and refreshes when the registry changes.
|
|
165
|
+
|
|
166
|
+
**Costs and caveats.** Each name adds one property check per render of every component, forever, so keep the list short. The effect is app-global and cannot be scoped to a subtree — use a factory's own `styleProps` for that. Be wary of names that collide with real DOM or component props (`width`, `size`, `color`): promoting one means every component swallows it as a style, including when rendering `as={SomeThirdPartyComponent}`.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Typing your extension
|
|
171
|
+
|
|
172
|
+
Four augmentation points, each matching a runtime registry:
|
|
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
|
+
```
|
|
201
|
+
|
|
202
|
+
`TastyCustomProps` keys become optional props on every component. `TastyBaseStylePropNames` entries are typed exactly like the style they name, so `radius="1r"` accepts the same values as `styles={{ radius: '1r' }}`.
|
|
203
|
+
|
|
204
|
+
**Also update `tasty.config.ts`.** The ESLint plugin and VS Code extension validate style and token names against it, and neither is derived from the runtime registries:
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
// tasty.config.ts
|
|
208
|
+
export default {
|
|
209
|
+
styles: ['stripe'],
|
|
210
|
+
tokens: ['#glaze-bg'],
|
|
211
|
+
};
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
`propHandlers` keys are JSX props rather than style keys, so they need no entry — but any _style_ name or token a handler expands into does.
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Worked example: a `glaze` plugin
|
|
219
|
+
|
|
220
|
+
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.
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
// glaze-plugin.ts
|
|
224
|
+
import { mergeStyles } from '@tenphi/tasty';
|
|
225
|
+
import type { Styles, TastyPluginFactory } from '@tenphi/tasty';
|
|
226
|
+
|
|
227
|
+
export interface GlazeConfig {
|
|
228
|
+
tone: string;
|
|
229
|
+
/** 0–100. Default 10. */
|
|
230
|
+
intensity?: number;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
type GlazeValue = string | GlazeConfig;
|
|
234
|
+
|
|
235
|
+
// Memoized per value so the styles object is reference-stable across renders.
|
|
236
|
+
const cache = new Map<string, Styles>();
|
|
237
|
+
|
|
238
|
+
function glazeStyles(value: GlazeValue): Styles {
|
|
239
|
+
const { tone, intensity = 10 } =
|
|
240
|
+
typeof value === 'string' ? { tone: value } : value;
|
|
241
|
+
const key = `${tone}:${intensity}`;
|
|
242
|
+
|
|
243
|
+
let styles = cache.get(key);
|
|
244
|
+
|
|
245
|
+
if (!styles) {
|
|
246
|
+
styles = Object.freeze({
|
|
247
|
+
'#glaze-bg': `#${tone}.${intensity}`,
|
|
248
|
+
fill: '#glaze-bg',
|
|
249
|
+
transition: 'fill',
|
|
250
|
+
}) as Styles;
|
|
251
|
+
cache.set(key, styles);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return styles;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export const glazePlugin: TastyPluginFactory = () => ({
|
|
258
|
+
name: 'glaze',
|
|
259
|
+
|
|
260
|
+
propHandlers: {
|
|
261
|
+
glaze: (props) => {
|
|
262
|
+
const { glaze, ...rest } = props;
|
|
263
|
+
if (!glaze) return rest;
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
...rest,
|
|
267
|
+
styles: mergeStyles(
|
|
268
|
+
glazeStyles(glaze as GlazeValue),
|
|
269
|
+
rest.styles as Styles,
|
|
270
|
+
),
|
|
271
|
+
};
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
|
|
275
|
+
// Typed so `#glaze-bg` animates smoothly instead of snapping.
|
|
276
|
+
properties: {
|
|
277
|
+
'#glaze-bg': {
|
|
278
|
+
syntax: '<color>',
|
|
279
|
+
inherits: false,
|
|
280
|
+
initialValue: 'transparent',
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
```ts
|
|
287
|
+
// app entry, before the first render
|
|
288
|
+
import { configure } from '@tenphi/tasty';
|
|
289
|
+
|
|
290
|
+
import { glazePlugin } from './glaze-plugin';
|
|
291
|
+
|
|
292
|
+
configure({ plugins: [glazePlugin()] });
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
```tsx
|
|
296
|
+
<Element glaze="purple" />
|
|
297
|
+
<Element glaze={{ tone: 'success', intensity: 30 }} />
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
```ts
|
|
301
|
+
// tasty.d.ts
|
|
302
|
+
declare module '@tenphi/tasty' {
|
|
303
|
+
interface TastyCustomProps {
|
|
304
|
+
glaze: import('./glaze-plugin').GlazeConfig | string;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
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`.
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## Rendering modes and caveats
|
|
314
|
+
|
|
315
|
+
| Mode | `functions` / `units` / `states` / `handlers` / `recipes` / `tokens` | `propHandlers` |
|
|
316
|
+
| -------------------------- | -------------------------------------------------------------------- | -------------- |
|
|
317
|
+
| Client | ✅ | ✅ |
|
|
318
|
+
| SSR / RSC | ✅ | ✅ |
|
|
319
|
+
| Build-time (`tastyStatic`) | ✅ at build time | not applicable |
|
|
320
|
+
|
|
321
|
+
**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.
|
|
322
|
+
|
|
323
|
+
**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).
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## Testing a plugin
|
|
328
|
+
|
|
329
|
+
```ts
|
|
330
|
+
import { configure, resetConfig, renderStyles } from '@tenphi/tasty';
|
|
331
|
+
|
|
332
|
+
describe('glaze plugin', () => {
|
|
333
|
+
beforeEach(() => resetConfig());
|
|
334
|
+
afterEach(() => resetConfig());
|
|
335
|
+
|
|
336
|
+
it('expands into a color token declaration', () => {
|
|
337
|
+
configure({ plugins: [glazePlugin()] });
|
|
338
|
+
|
|
339
|
+
const rules = renderStyles({ '#glaze-bg': '#purple.10' }, '.test');
|
|
340
|
+
|
|
341
|
+
expect(rules[0].declarations).toContain('--glaze-bg-color');
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
Two things to know:
|
|
347
|
+
|
|
348
|
+
- **Create components inside each test.** `resetConfig()` does not clear the per-factory class-name cache or prop-list memo, so a module-scope component created in one test carries state into the next.
|
|
349
|
+
- **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
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
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`.
|