@tenphi/tasty 0.0.0-snapshot.fa23a44 → 0.0.0-snapshot.fa7ba65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +452 -365
  2. package/dist/babel-types-Dc5zghyE.d.ts +18 -0
  3. package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
  4. package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
  5. package/dist/chunks/build-config--0qoqt_P.js +60 -0
  6. package/dist/chunks/build-config--0qoqt_P.js.map +1 -0
  7. package/dist/{collector-DrgDE7QB.js → chunks/collector-zp5BrLF0.js} +79 -99
  8. package/dist/chunks/collector-zp5BrLF0.js.map +1 -0
  9. package/dist/chunks/config-engine-BaLq8HrX.js +272 -0
  10. package/dist/chunks/config-engine-BaLq8HrX.js.map +1 -0
  11. package/dist/chunks/config-file-DlZXJMj8.js +25 -0
  12. package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
  13. package/dist/chunks/css-definitions-CfXZ3tU9.js +910 -0
  14. package/dist/chunks/css-definitions-CfXZ3tU9.js.map +1 -0
  15. package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
  16. package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
  17. package/dist/chunks/debug--OC-WA-Q.js +502 -0
  18. package/dist/chunks/debug--OC-WA-Q.js.map +1 -0
  19. package/dist/chunks/dsl-CsFl9LGn.js +1458 -0
  20. package/dist/chunks/dsl-CsFl9LGn.js.map +1 -0
  21. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  22. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  23. package/dist/chunks/react-runtime-DnZ6M1Iv.js +691 -0
  24. package/dist/chunks/react-runtime-DnZ6M1Iv.js.map +1 -0
  25. package/dist/chunks/runtime-engine-J9X_h-Pw.js +2435 -0
  26. package/dist/chunks/runtime-engine-J9X_h-Pw.js.map +1 -0
  27. package/dist/chunks/runtime-state-o_v3Bj7b.js +152 -0
  28. package/dist/chunks/runtime-state-o_v3Bj7b.js.map +1 -0
  29. package/dist/{merge-styles-BUQsEpbv.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
  30. package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
  31. package/dist/chunks/style-engine-D6lC3O3G.js +5626 -0
  32. package/dist/chunks/style-engine-D6lC3O3G.js.map +1 -0
  33. package/dist/{css-writer-D--REwtp.js → chunks/zero-engine-BnjoV04F.js} +104 -123
  34. package/dist/chunks/zero-engine-BnjoV04F.js.map +1 -0
  35. package/dist/collector-D2OT6I2G.d.ts +164 -0
  36. package/dist/config-C4ftFxgI.d.ts +1367 -0
  37. package/dist/core/index.d.ts +5 -5
  38. package/dist/core/index.js +9 -6
  39. package/dist/hydrate-CRyjjAyl.d.ts +22 -0
  40. package/dist/index-DxQNRj50.d.ts +1964 -0
  41. package/dist/index.d.ts +5 -5
  42. package/dist/index.js +11 -732
  43. package/dist/{merge-styles-CtDJMhpJ.d.ts → merge-styles-D39qBtox.d.ts} +2 -3
  44. package/dist/ssr/astro-client.d.ts +1 -1
  45. package/dist/ssr/astro-client.js +1 -14
  46. package/dist/ssr/astro-client.js.map +1 -1
  47. package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
  48. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  49. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  50. package/dist/ssr/astro-middleware-extract.d.ts +10 -0
  51. package/dist/ssr/astro-middleware-extract.js +9 -0
  52. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  53. package/dist/ssr/astro-middleware-static.d.ts +17 -0
  54. package/dist/ssr/astro-middleware-static.js +7 -0
  55. package/dist/ssr/astro-middleware-static.js.map +1 -0
  56. package/dist/ssr/astro-middleware.d.ts +11 -8
  57. package/dist/ssr/astro-middleware.js +2 -14
  58. package/dist/ssr/astro-middleware.js.map +1 -1
  59. package/dist/ssr/astro.d.ts +33 -14
  60. package/dist/ssr/astro.js +163 -91
  61. package/dist/ssr/astro.js.map +1 -1
  62. package/dist/ssr/client.d.ts +2 -0
  63. package/dist/ssr/client.js +2 -0
  64. package/dist/ssr/index.d.ts +5 -32
  65. package/dist/ssr/index.js +6 -6
  66. package/dist/ssr/index.js.map +1 -1
  67. package/dist/ssr/next-config.d.ts +64 -0
  68. package/dist/ssr/next-config.js +123 -0
  69. package/dist/ssr/next-config.js.map +1 -0
  70. package/dist/ssr/next.d.ts +9 -9
  71. package/dist/ssr/next.js +29 -44
  72. package/dist/ssr/next.js.map +1 -1
  73. package/dist/static/index.d.ts +8 -9
  74. package/dist/static/index.js +4 -22
  75. package/dist/static/index.js.map +1 -1
  76. package/dist/static/inject.d.ts +1 -2
  77. package/dist/static/inject.js.map +1 -1
  78. package/dist/{index-dUtwpOux.d.ts → types-CYQIhUg1.d.ts} +691 -388
  79. package/dist/zero/babel.d.ts +12 -20
  80. package/dist/zero/babel.js +101 -152
  81. package/dist/zero/babel.js.map +1 -1
  82. package/dist/zero/index.d.ts +76 -7
  83. package/dist/zero/index.js +25 -2
  84. package/dist/zero/index.js.map +1 -0
  85. package/dist/zero/next.d.ts +4 -5
  86. package/dist/zero/next.js +3 -38
  87. package/dist/zero/next.js.map +1 -1
  88. package/docs/README.md +20 -9
  89. package/docs/adoption.md +69 -36
  90. package/docs/ai-agents.md +259 -0
  91. package/docs/comparison.md +77 -47
  92. package/docs/configuration.md +648 -85
  93. package/docs/debug.md +28 -15
  94. package/docs/design-system.md +166 -33
  95. package/docs/dsl.md +739 -196
  96. package/docs/getting-started.md +130 -50
  97. package/docs/injector.md +160 -69
  98. package/docs/llms.txt +31 -0
  99. package/docs/methodology.md +106 -49
  100. package/docs/migration-v3.md +285 -0
  101. package/docs/pipeline.md +142 -47
  102. package/docs/plugins.md +333 -0
  103. package/docs/react-api.md +236 -47
  104. package/docs/runtime-benchmarks.md +388 -0
  105. package/docs/ssr.md +310 -116
  106. package/docs/styles.md +234 -49
  107. package/docs/tasty-static.md +298 -130
  108. package/harness/dev.harnesspm/rules/usage.md +12 -0
  109. package/harness/dev.harnesspm/scripts/render.mjs +441 -0
  110. package/harness/dev.harnesspm/scripts/styles.mjs +412 -0
  111. package/harness/plugin.json +20 -0
  112. package/package.json +153 -45
  113. package/tasty.config.ts +7 -0
  114. package/dist/async-storage-B7_o6FKt.js +0 -44
  115. package/dist/async-storage-B7_o6FKt.js.map +0 -1
  116. package/dist/collector-DrgDE7QB.js.map +0 -1
  117. package/dist/collector-LuU1vZ68.d.ts +0 -98
  118. package/dist/config-_aQ_PZ-P.js +0 -10131
  119. package/dist/config-_aQ_PZ-P.js.map +0 -1
  120. package/dist/config-vuCRkBWX.d.ts +0 -884
  121. package/dist/context-CkSg-kDT.js +0 -24
  122. package/dist/context-CkSg-kDT.js.map +0 -1
  123. package/dist/core-BqO8pplb.js +0 -1592
  124. package/dist/core-BqO8pplb.js.map +0 -1
  125. package/dist/css-writer-D--REwtp.js.map +0 -1
  126. package/dist/format-global-rules-Dbc_1tc3.js +0 -22
  127. package/dist/format-global-rules-Dbc_1tc3.js.map +0 -1
  128. package/dist/format-rules-xwteB7a1.js +0 -143
  129. package/dist/format-rules-xwteB7a1.js.map +0 -1
  130. package/dist/hydrate-BvPT4ndL.js +0 -45
  131. package/dist/hydrate-BvPT4ndL.js.map +0 -1
  132. package/dist/index-ZRxZWzlj.d.ts +0 -1602
  133. package/dist/index.js.map +0 -1
  134. package/dist/keyframes-ClPFWy33.js +0 -587
  135. package/dist/keyframes-ClPFWy33.js.map +0 -1
  136. package/dist/merge-styles-BUQsEpbv.js.map +0 -1
  137. package/dist/resolve-recipes-C0-AMzCz.js +0 -144
  138. package/dist/resolve-recipes-C0-AMzCz.js.map +0 -1
package/docs/dsl.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # Style DSL Reference
2
2
 
3
- This is the Tasty style language reference — the value syntax, state mappings, tokens, units, extending semantics, and special declarations that apply to both runtime `tasty()` and build-time `tastyStatic()`.
3
+ This is the language behind Tasty’s predictable state resolution. Every property can use a state map; later branches declare higher priority, and Tasty compiles them so only one generated selector can match.
4
4
 
5
- For the runtime React API (`tasty()`, hooks, component props), see [React API](react-api.md). For all enhanced style properties, see [Style Properties](styles.md). For global configuration, see [Configuration](configuration.md).
5
+ The same value syntax, state maps, tokens, units, extension semantics, and special declarations apply to React `tasty()`—whether rendered on the client or server—and build-time `tastyStatic()`.
6
+
7
+ For the React API (`tasty()`, style functions, component props), see [React API](react-api.md). For all enhanced style properties, see [Style Properties](styles.md). For global configuration, see [Configuration](configuration.md).
8
+
9
+ To autocomplete your own token and preset names, see [TypeScript autocomplete](getting-started.md#typescript-autocomplete); to check state keys, tokens, units, and values at lint time, see [ESLint plugin](getting-started.md#eslint-plugin).
6
10
 
7
11
  ---
8
12
 
@@ -16,22 +20,65 @@ Object where keys represent states and values are the styles to apply:
16
20
  fill: { '': '#white', hovered: '#gray.05', 'theme=danger': '#red' }
17
21
  ```
18
22
 
23
+ Define an alias for one component by adding an `'@name': '<state expression>'` key to its styles. It works like a global alias from [`configure({ states })`](configuration.md#options), scoped to that component:
24
+
25
+ ```jsx
26
+ styles: {
27
+ '@narrow': '@media(w < 600px)',
28
+ fill: { '': '#surface', '@narrow': '#surface-mobile' },
29
+ }
30
+ ```
31
+
32
+ An alias can use other aliases, anywhere in its expression:
33
+
34
+ ```jsx
35
+ configure({
36
+ states: {
37
+ '@mobile': '@media(w < 768px)',
38
+ '@collapsed': '@mobile & !expanded',
39
+ },
40
+ });
41
+
42
+ styles: {
43
+ '@compact': '@collapsed | @media:print', // local, built on a global alias
44
+ padding: { '': '4x', '@compact': '2x' },
45
+ }
46
+ ```
47
+
48
+ - A local alias sees the component's aliases first, then the global ones. Aliases declared inside a sub-element also see the root-level ones.
49
+ - A global alias sees only global aliases. It means the same thing in every component: if a component redefines `@mobile` locally, the global `@collapsed` keeps using the global `@mobile`.
50
+ - A circular alias (`'@a': '@b'` with `'@b': '@a'`, or `'@a': '@a & hovered'`) never matches, and a `CIRCULAR_STATE_ALIAS` warning names the loop.
51
+
19
52
  #### State Key Types
20
53
 
21
- | Syntax | Example | Generated CSS |
22
- |--------|---------|---------------|
23
- | Boolean modifier | `hovered` | `[data-hovered]` |
24
- | Value modifier | `theme=danger` | `[data-theme="danger"]` |
25
- | Pseudo-class | `:hover` | `:hover` |
26
- | Class selector | `.active` | `.active` |
27
- | Attribute selector | `[aria-expanded="true"]` | `[aria-expanded="true"]` |
28
- | Combined (AND) | `hovered & .active` | `[data-hovered].active` |
29
- | Combined (OR) | `hovered \| focused` | `[data-hovered], [data-focused]` |
30
- | Negated (NOT) | `!disabled` | `:not([data-disabled])` |
31
- | Exclusive (XOR) | `hovered ^ focused` | `[data-hovered]:not([data-focused]), :not([data-hovered])[data-focused]` |
54
+ | Syntax | Example | Generated CSS |
55
+ | ------------------ | ------------------------ | ------------------------------------------------------------------------ |
56
+ | Boolean modifier | `hovered` | `[data-hovered]` |
57
+ | Value modifier | `theme=danger` | `[data-theme="danger"]` |
58
+ | Pseudo-class | `:hover` | `:hover` |
59
+ | Class selector | `.active` | `.active` |
60
+ | Attribute selector | `[aria-expanded="true"]` | `[aria-expanded="true"]` |
61
+ | Combined (AND) | `hovered & .active` | `[data-hovered].active` |
62
+ | Combined (OR) | `hovered \| focused` | `[data-hovered], [data-focused]` |
63
+ | Negated (NOT) | `!disabled` | `:not([data-disabled])` |
64
+ | Exclusive (XOR) | `hovered ^ focused` | `[data-hovered]:not([data-focused]), :not([data-hovered])[data-focused]` |
65
+
66
+ #### Automatic Native States
67
+
68
+ `disabled`, `checked`, and `hidden` are built-in automatic states. A Tasty component sets `data-disabled`, `data-checked`, and `data-hidden` from the native `disabled`, `checked`, and `hidden` props (or `isDisabled`, `isChecked`, `isHidden`), so each pair below expresses the same component state:
69
+
70
+ | Concise Tasty state | Compiles to | Explicit attribute selector |
71
+ | ------------------- | ----------------- | --------------------------- |
72
+ | `disabled` | `[data-disabled]` | `[disabled]` |
73
+ | `checked` | `[data-checked]` | `[checked]` |
74
+ | `hidden` | `[data-hidden]` | `[hidden]` |
75
+
76
+ Prefer the concise form when authoring Tasty component styles. Explicit attribute selectors remain valid and can be useful when targeting arbitrary attributes or when CSS-shaped syntax makes an introductory example easier to recognize.
32
77
 
33
78
  Operator precedence (highest to lowest): `!` (NOT) > `^` (XOR) > `|` (OR) > `&` (AND). Use parentheses to override: `hovered & (pressed ^ focused)`.
34
79
 
80
+ A top-level comma is the same as `|`: `'hovered, focused'` is `'hovered | focused'`.
81
+
35
82
  `^` (XOR) means "exactly one of" — `A ^ B` expands to `(A & !B) | (!A & B)`. This is useful for mutually exclusive states where exactly one should be active:
36
83
 
37
84
  ```jsx
@@ -41,32 +88,52 @@ fill: {
41
88
  }
42
89
  ```
43
90
 
91
+ Modifier and class names start with a letter and may be a single letter (`x` → `[data-x]`, `.x`). Tasty emits an `INVALID_STATE_KEY` warning for a key it cannot fully read and skips the unreadable parts. That covers characters outside the notation (`1st`, or `@media (w < 600px)` with a space before the parenthesis), an operator missing a state (`hovered &`), and two states with no operator between them (`hovered focused`). A partly read key can apply in states you did not mean, so fix the key rather than rely on what it produces.
92
+
93
+ #### Default State Ordering
94
+
95
+ Key order sets priority — later keys win and turn off earlier ones via negation. The bare default (`''`) is the lowest-priority state, so it **must be the first key**. If it appears after other states, Tasty moves it to the front and emits a dev warning (`MISPLACED_DEFAULT_STATE`); otherwise it would override every state above it.
96
+
97
+ ```jsx
98
+ // Correct — default first
99
+ color: { '': '#text', hovered: '#accent' }
100
+
101
+ // Auto-corrected with a warning — '' moved to the front
102
+ color: { hovered: '#accent', '': '#text' }
103
+ ```
104
+
105
+ The bare `''` default still **receives negation** (it is turned off when a higher-priority state matches). For a value that must always apply as a guaranteed floor — even where a query is _unknown_ — use the [`_` fallback floor](#_--fallback-floor) instead. The two can coexist: `''` is the negated default, `_` is the always-on floor. If a map contains only `_` and `''` (no other states), the `''` default is redundant — Tasty keeps the `_` value and drops `''` with a `REDUNDANT_DEFAULT_STATE` warning.
106
+
44
107
  ### Sub-element
45
108
 
46
109
  Element styled using a capitalized key. Identified by `data-element` attribute:
47
110
 
48
111
  ```jsx
49
- styles: { Title: { preset: 'h3' } }
112
+ styles: {
113
+ Title: { preset: 'h3' },
114
+ }
50
115
  // Targets: <div data-element="Title">
51
116
  ```
52
117
 
53
118
  #### Selector Affix (`$`)
54
119
 
55
- Control how a sub-element selector attaches to the root selector using the `$` property inside the sub-element's styles:
56
-
57
- | Pattern | Result | Description |
58
- |---------|--------|-------------|
59
- | *(none)* | ` [el]` | Descendant (default) |
60
- | `>` | `> [el]` | Direct child |
61
- | `>Body>Row>` | `> [Body] > [Row] > [el]` | Chained elements |
62
- | `h1` | ` h1` | Tag selector (no key injection) |
63
- | `h1 >` | ` h1 > [el]` | Key is direct child of tag |
64
- | `h1 *` | ` h1 *` | Any descendant of tag |
65
- | `*` | ` *` | All descendants |
66
- | `::before` | `::before` | Root pseudo (no key) |
67
- | `@::before` | `[el]::before` | Pseudo on the sub-element |
68
- | `>@:hover` | `> [el]:hover` | Pseudo-class on the sub-element |
69
- | `>@.active` | `> [el].active` | Class on the sub-element |
120
+ Control how a sub-element selector attaches to the root selector using the `$` property inside the sub-element's styles.
121
+
122
+ Examples below assume the sub-element key is **Cell** (i.e. `[data-element="Cell"]` in CSS):
123
+
124
+ | Pattern | Result | Description |
125
+ | ----------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
126
+ | _(none)_ | `[data-element="Cell"]` | Descendant (default) |
127
+ | `>` | `> [data-element="Cell"]` | Direct child |
128
+ | `>Body>` | `> [data-element="Body"] > [data-element="Cell"]` | Chained elements |
129
+ | `> Cell` | `> [data-element="Cell"]` | Self-name shorthand — when the trailing element name matches the sub-element's own key, it acts as the placeholder (same as `@`); no duplication |
130
+ | `h1` | `h1` | Tag selector (no key injection) |
131
+ | `h1 >` | `h1 > [data-element="Cell"]` | Key is direct child of tag |
132
+ | `h1 *` | `h1 *` | Any descendant of tag |
133
+ | `*` | `*` | All descendants |
134
+ | `&::before` | `::before` | Root pseudo (no key); `&` is required |
135
+ | `@::before` | `[data-element="Cell"]::before` | Pseudo on the sub-element |
136
+ | `>@.active` | `> [data-element="Cell"].active` | Class on the sub-element |
70
137
 
71
138
  Rules for key injection (`[data-element="..."]`):
72
139
 
@@ -82,20 +149,22 @@ The `@` placeholder marks exactly where `[data-element="..."]` is injected, allo
82
149
  const List = tasty({
83
150
  styles: {
84
151
  Item: {
85
- $: '>@:last-child',
86
- border: 'none',
152
+ $: '>@::after',
153
+ content: '""',
87
154
  },
88
155
  },
89
156
  });
90
- // → .t0 > [data-element="Item"]:last-child { border: none }
157
+ // → .t1x29r0l.t1x29r0l > [data-element="Item"]::after { content: ""; }
91
158
  ```
92
159
 
160
+ Keep conditions such as `:last-child` out of `$` and write them as `@own(:last-child)` in a state map; `tasty/no-state-in-selector` warns otherwise. When `$` ends in a pseudo-element, `@own()` describes the pseudo-element instead (see [`@own(...)`](#own--sub-elements-own-state)), so a condition on the element it belongs to stays in `$`, before the pseudo-element: `$: 'a[rel="next"]::before'`.
161
+
93
162
  ### Color Token
94
163
 
95
164
  Named color prefixed with `#` that maps to CSS custom properties. Supports opacity with `.N` suffix:
96
165
 
97
166
  ```jsx
98
- fill: '#purple.5' // → var(--purple-color) with 50% opacity
167
+ fill: '#purple.5'; // → color-mix(in oklab, var(--purple-color) 50%, transparent)
99
168
  ```
100
169
 
101
170
  ### Modifier
@@ -107,7 +176,7 @@ mods={{ hovered: true, theme: 'danger' }}
107
176
  // → data-hovered="" data-theme="danger"
108
177
  ```
109
178
 
110
- Modifiers can also be exposed as top-level component props via `modProps` — see [Runtime — Mod Props](react-api.md#mod-props).
179
+ Modifiers can also be exposed as top-level component props via `modProps` — see [React API — Mod Props](react-api.md#mod-props).
111
180
 
112
181
  ---
113
182
 
@@ -117,25 +186,242 @@ Modifiers can also be exposed as top-level component props via `modProps` — se
117
186
  color: '#purple', // Full opacity
118
187
  color: '#purple.5', // 50% opacity
119
188
  color: '#purple.05', // 5% opacity
189
+ color: '#purple.$fade', // Opacity from a custom property
120
190
  fill: '#current', // → currentcolor
121
- fill: '#current.5', // → color-mix(in oklab, currentcolor 50%, transparent)
191
+ fill: '#surface+#dark.04', // #dark at 4% opacity over #surface, as one color
122
192
  color: '(#primary, #secondary)', // Fallback syntax
123
193
  ```
124
194
 
195
+ `#white`, `#black`, `#border`, and `#outline` are registered by default (see [Default properties](#default-properties)), and `#clear` is a built-in alias for `transparent` (see [below](#clear-is-transparent)), so they work before you define any tokens.
196
+
197
+ A name that is also a hex color is read as a token with the literal as its fallback, in every color style: `color: '#ddd'` emits `var(--ddd-color, #ddd)`, and `#ddd.5` emits `color-mix(in oklab, var(--ddd-color, #ddd) 50%, transparent)`. A `#ddd` token, if you define one, wins over the literal.
198
+
199
+ The suffix fades the token's color by mixing it with `transparent`:
200
+
201
+ ```jsx
202
+ fill: '#purple.5';
203
+ // → color-mix(in oklab, var(--purple-color) 50%, transparent)
204
+ ```
205
+
206
+ The mix asks nothing of the color beyond _being_ a color. That means the suffix
207
+ works on every one of these:
208
+
209
+ - a token holding a `color-mix()`, a `light-dark()`, or a `color()` in a space
210
+ Tasty cannot convert — none of which have channels to decompose
211
+ - `#current`, which resolves to the color the element inherits
212
+ - a `--name-color` variable declared in your own CSS, with no Tasty token
213
+ definition behind it
214
+
215
+ `color-mix()` is Baseline widely available (Chrome 111, Firefox 113, Safari
216
+ 16.2). Two properties follow from mixing rather than writing an alpha channel:
217
+
218
+ - **Alpha composes.** The mix is premultiplied, so a color that is already
219
+ translucent is faded further: a token holding `rgb(255 0 0 / .8)` faded to
220
+ `.5` is alpha `.4`. An opaque token — the usual case — ends at exactly the
221
+ suffix. System colors are whatever the platform draws, and some are
222
+ translucent: Chrome and Safari on macOS give `Highlight` an alpha of `.6`, so
223
+ a token holding it faded to `.5` ends at `.3` there.
224
+ - **A `$prop` alpha must be a number.** `#purple.$fade` emits
225
+ `calc(var(--fade) * 100%)`, because a mix percentage cannot be a `<number>`,
226
+ so `$fade` has to hold `.5`, not `50%`.
227
+
228
+ ### `#clear` is transparent
229
+
230
+ `#clear` is a built-in [replace token](#replace-tokens) for `transparent`.
231
+ Opacity suffixes are ignored: `#clear.5` and `#clear.$fade` both emit
232
+ `transparent`. The same rule applies to user-defined replace tokens resolving
233
+ to `transparent`, including aliases of `#clear`.
234
+
235
+ It does not read `--clear-color` or require an `@property` registration.
236
+ An explicit `configure({ replaceTokens: { '#clear': ... } })` overrides the
237
+ default alias and uses the replacement's usual opacity behavior.
238
+
239
+ ### `#current` is the keyword
240
+
241
+ `#current` emits the `currentcolor` keyword, so it resolves against the element
242
+ that reads it. That is what lets it follow a color an ancestor faded — a ramp
243
+ that expresses its disabled state once, in `color`, fades everything painted from
244
+ `#current` below it with no further declarations.
245
+
246
+ The `color` style also publishes `--current-color` beside every color it sets,
247
+ for anything that needs the inherited color _as a color_ rather than as the
248
+ keyword — hand-authored CSS, or a place the keyword will not do. Read it as
249
+ `$current-color`. It is registered with `initial-value: currentcolor`, so where
250
+ nothing published it, it still resolves against each element's own color:
251
+
252
+ ```jsx
253
+ fill: '$current-color'; // → var(--current-color)
254
+ ```
255
+
256
+ A color that already reads the color it inherits — `#current`, a `#current` fade
257
+ — is not published into it: resolving such a value a second time at a descendant
258
+ would fade it twice.
259
+
260
+ ### `#current` fades compose
261
+
262
+ `currentcolor` is the color an element **inherits**, which an ancestor may
263
+ already have faded, so `#current.4` means "40% of what reaches me":
264
+
265
+ ```jsx
266
+ fill: '#current.4';
267
+ // → color-mix(in oklab, currentcolor 40%, transparent)
268
+ ```
269
+
270
+ A `#current` fade nested inside another one composes: a label at `#current.4`
271
+ with a fill of `#current.18` under it lands at `.072`. Color ramps built on
272
+ `#current` depend on that.
273
+
274
+ Fades always mix `in oklab`: it is unbounded, so a wide-gamut color is not
275
+ clamped, and rectangular, so there is no hue to interpolate against
276
+ `transparent`. Nothing configures it — see
277
+ [Color space](configuration.md#color-space).
278
+
279
+ ### Compound colors
280
+
281
+ Join color tokens with `+` to paint each one, at its own opacity, over the
282
+ colors before it. The result is one color, so it works anywhere a token does:
283
+
284
+ ```jsx
285
+ fill: '#surface+#dark.04',
286
+ // → color-mix(in srgb, var(--dark-color) 4%, var(--surface-color))
287
+
288
+ border: '1bw #border+#dark.1',
289
+ color: 'light-dark(#primary+#black.2, #primary+#white.2)',
290
+ '#hover-surface': '#surface-2+#surface-text.03',
291
+ ```
292
+
293
+ Read it left to right, bottom layer first: `#surface+#accent.1+#dark.04` paints
294
+ `#accent` at 10% over `#surface`, then `#dark` at 4% over that. Every operand is
295
+ an ordinary token — `#current`, `#clear`, a hex color, a replace token — and
296
+ takes its opacity suffix as it does anywhere: `#surface+#dark.$hover` reads the
297
+ opacity from `$hover`, and a faded base such as `#surface.5+#dark.04` is layered
298
+ as it is.
299
+
300
+ The layers mix in sRGB, the space browsers composite in, so the color is exactly
301
+ what stacking them as layers would show — but it is one color, which contrast
302
+ checkers can read and transitions interpolate. A faded base is exact too:
303
+ `#surface.5+#dark.04` is as translucent as the two layers would be.
304
+
305
+ Every layer's token has to be opaque. The mix counts a layer's own alpha as well
306
+ as its opacity suffix, and lowers the alpha of the whole color, so a layer token
307
+ that holds a translucent color, or turns transparent in some state, leaves the
308
+ result see-through: with `'#overlay': { '': '#clear', hovered: '#dark' }`,
309
+ `'#surface+#overlay.04'` is 96% opaque at rest. Vary the opacity instead
310
+ (`'#surface+#dark.$hover'`), or give each state its own color
311
+ (`fill: { '': '#surface', hovered: '#surface+#dark.04' }`).
312
+
313
+ - Write it as one word: `#surface + #dark.04` is three separate values, and
314
+ Tasty warns in development.
315
+ - A layer without an opacity covers everything before it: `#surface+#dark` is
316
+ `#dark`, with a development warning.
317
+ - A layer Tasty can see is transparent — `#clear`, a fade to `.0`, a color with
318
+ a zero alpha — is left out: `#surface+#clear` is `#surface`.
319
+ - Over a transparent base, a layer is just its fade: `#clear+#dark.04` compiles
320
+ to `#dark.04`.
321
+ - A `+` joining anything but color tokens (`#surface+1x`) is not a compound: the
322
+ token is dropped, with a development warning, and the style renders as if
323
+ that color were not there.
324
+
325
+ A `+` joins tokens only. To fade a whole compound, give it a token
326
+ (`'#hover-surface': '#surface+#dark.04'`) and fade that (`#hover-surface.5`). For
327
+ a mix that is not a layer over another color, such as an even blend in OKLCH,
328
+ write `color-mix()` itself.
329
+
330
+ ---
331
+
332
+ ## CSS Color Functions
333
+
334
+ Every CSS color function is recognized as a color, so it lands in the color slot
335
+ of whichever style property you use it in — and tokens inside it are expanded:
336
+
337
+ ```jsx
338
+ fill: 'color-mix(in oklab, #primary 50%, #surface)',
339
+ color: 'light-dark(#dark, #light)',
340
+ color: 'contrast-color(#primary)',
341
+ fill: 'color(display-p3 1 .5 0)',
342
+ border: '1bw solid oklch(from #primary l c h / 50%)', // relative color syntax
343
+ shadow: '0 0 1x color-mix(in oklab, #dark 20%, transparent)',
344
+ ```
345
+
346
+ Tasty also ships `okhsl()` and `okhst()`, which compile to `rgb()` at parse
347
+ time: `fill: 'okhsl(280 80% 50%)'` → `rgb(40% 38.5% 88.2%)`.
348
+
349
+ `light-dark()` is the one exception to "always a color": CSS lets it pick between
350
+ values of any type, so it is treated as a color only when its arguments are
351
+ colors. `padding: 'light-dark(1x, 2x)'` still reaches the padding slot.
352
+
353
+ A color token defined as one of these functions takes the
354
+ [opacity suffix](#color-tokens--opacity) like any other:
355
+
356
+ ```jsx
357
+ const Card = tasty({
358
+ styles: {
359
+ '#brand': 'color-mix(in oklab, #primary 50%, #surface)',
360
+ fill: '#brand.5',
361
+ },
362
+ });
363
+ ```
364
+
365
+ A [replace token](configuration.md#replace-tokens-parse-time-substitution) is
366
+ substituted while parsing, so its color is right there to fade in place. A
367
+ channel function takes the alpha after a slash; a derived function has no alpha
368
+ channel, so it gets wrapped:
369
+
370
+ ```jsx
371
+ configure({
372
+ replaceTokens: {
373
+ '#solid': 'hsl(220 90% 50%)',
374
+ '#adaptive': 'light-dark(#dark, #light)',
375
+ },
376
+ });
377
+
378
+ fill: '#solid.5'; // → hsl(220 90% 50% / .5)
379
+ fill: '#adaptive.5'; // → color-mix(in oklab, light-dark(…) 50%, transparent)
380
+ ```
381
+
382
+ ### Color keywords
383
+
384
+ CSS named colors (`rebeccapurple`) and system colors (`Canvas`, `CanvasText`,
385
+ `Highlight`, `ButtonText`, `GrayText`, `LinkText`, …) are colors too: they land
386
+ in the color slot of any style and can be a color token's value. System colors
387
+ are what `forced-colors` styles are written in:
388
+
389
+ ```jsx
390
+ const Checkbox = tasty({
391
+ styles: {
392
+ '#forced-border': 'CanvasText',
393
+ border: {
394
+ '': '1bw #border',
395
+ '@media(forced-colors: active)': '1bw #forced-border',
396
+ },
397
+ outline: { '': false, focused: '2px Highlight' },
398
+ },
399
+ });
400
+ ```
401
+
402
+ A custom property whose fallback is a single color is read as a color, so it
403
+ also fills the color slot: `border: '1bw var(--accent, Highlight)'`, as does
404
+ `($accent, Highlight)`. Keywords are case-insensitive: a color token keeps the
405
+ case it was written in, and a property value such as `border` or `fill` emits
406
+ them lowercase.
407
+
408
+ The deprecated system colors (`Menu`, `Window`, `ButtonHighlight`, …) are not
409
+ recognized.
410
+
125
411
  ---
126
412
 
127
413
  ## Built-in Units
128
414
 
129
- | Unit | Description | Example | CSS Output |
130
- |------|-------------|---------|------------|
131
- | `x` | Gap multiplier | `2x` | `calc(var(--gap) * 2)` |
132
- | `r` | Border radius | `1r` | `var(--radius)` |
133
- | `cr` | Card border radius | `1cr` | `var(--card-radius)` |
134
- | `bw` | Border width | `2bw` | `calc(var(--border-width) * 2)` |
135
- | `ow` | Outline width | `1ow` | `var(--outline-width)` |
136
- | `sf` | Stable fraction | `1sf` | `minmax(0, 1fr)` |
415
+ | Unit | Description | Default | Example | CSS output |
416
+ | ---- | ------------------ | ---------------- | ------- | ---------------- |
417
+ | `x` | Spacing step | `8px` | `2x` | `16px` |
418
+ | `r` | Border radius | `6px` | `1r` | `6px` |
419
+ | `cr` | Card border radius | `10px` | `1cr` | `10px` |
420
+ | `bw` | Border width | `1px` | `2bw` | `2px` |
421
+ | `ow` | Outline width | `3px` | `1ow` | `3px` |
422
+ | `sf` | Stable fraction | `minmax(0, Nfr)` | `1sf` | `minmax(0, 1fr)` |
137
423
 
138
- You can register additional custom units via [`configure()`](configuration.md#options).
424
+ Units compile to plain values. Change the scale with `configure({ units: { x: '4px' } })`, or point a unit at a custom property when it must change at runtime: with `units: { x: 'var(--gap)' }`, `2x` compiles to `calc(2 * var(--gap))`. Setting a `$gap` or `$radius` token does not change the units. Register additional units the same way via [`configure()`](configuration.md#options).
139
425
 
140
426
  ---
141
427
 
@@ -176,9 +462,29 @@ const ElevatedCard = tasty({
176
462
  });
177
463
  ```
178
464
 
465
+ **Where recipes resolve:**
466
+
467
+ The `recipe` property is resolved on the component root and independently inside each sub-element's styles:
468
+
469
+ ```jsx
470
+ const CardWithPanel = tasty({
471
+ styles: {
472
+ recipe: 'card',
473
+ Panel: {
474
+ recipe: 'card elevated',
475
+ padding: '2x', // Overrides the panel's base recipe padding
476
+ },
477
+ },
478
+ });
479
+ ```
480
+
481
+ At each level, base recipes are collected in the order listed (later recipes replace earlier values for the same property), then local styles are merged, then post recipes are merged. The merges with local styles and post recipes follow the [state-map extension and replacement rules](#extending-vs-replacing-state-maps).
482
+
483
+ Recipe definitions themselves cannot contain a `recipe` reference to another recipe: there is no recursive expansion or recipe inheritance. Compose names in the root or sub-element `recipe` property instead. See [Configuration — Recipes](configuration.md#recipes) for an unsupported nesting example.
484
+
179
485
  **Post-merge recipes (`/` separator):**
180
486
 
181
- Recipes listed after `/` are applied *after* component styles using `mergeStyles`:
487
+ Recipes listed after `/` are applied _after_ component styles using `mergeStyles`:
182
488
 
183
489
  ```jsx
184
490
  const Input = tasty({
@@ -216,8 +522,8 @@ When a style property uses a state map, the merge behavior depends on whether th
216
522
  const MyButton = tasty(Button, {
217
523
  styles: {
218
524
  fill: {
219
- 'loading': '#yellow', // append new state
220
- 'disabled': '#gray.20', // override existing state in place
525
+ loading: '#yellow', // append new state
526
+ disabled: '#gray.20', // override existing state in place
221
527
  },
222
528
  },
223
529
  });
@@ -227,7 +533,7 @@ const MyButton = tasty(Button, {
227
533
  styles: {
228
534
  fill: {
229
535
  '': '#red',
230
- 'hovered': '#blue',
536
+ hovered: '#blue',
231
537
  },
232
538
  },
233
539
  });
@@ -252,8 +558,14 @@ fill: {
252
558
  Use `null` inside a state map to remove a state, or `false` to block it entirely (tombstone):
253
559
 
254
560
  ```jsx
255
- fill: { pressed: null } // removes pressed from the result
256
- fill: { disabled: false } // tombstone — no CSS for disabled, blocks recipe too
561
+ const MyButton = tasty(Button, {
562
+ styles: {
563
+ fill: {
564
+ hovered: null, // removes the parent's hovered state
565
+ disabled: false, // tombstone — no CSS for disabled, blocks recipe too
566
+ },
567
+ },
568
+ });
257
569
  ```
258
570
 
259
571
  ### Resetting Properties with `null` and `false`
@@ -261,44 +573,54 @@ fill: { disabled: false } // tombstone — no CSS for disabled, blocks recipe to
261
573
  ```jsx
262
574
  const SimpleButton = tasty(Button, {
263
575
  styles: {
264
- fill: null, // discard parent's fill, let recipe fill in
576
+ fill: null, // discard parent's fill, let recipe fill in
265
577
  border: false, // no border at all (tombstone — blocks recipe too)
266
578
  },
267
579
  });
268
580
  ```
269
581
 
270
- | Value | Meaning | Recipe fills in? |
271
- |-------|---------|-----------------|
272
- | `undefined` | Not provided — parent preserved | N/A |
273
- | `null` | Intentional unset — parent discarded | Yes |
274
- | `false` | Tombstone — blocks everything | No |
582
+ | Value | Meaning | Recipe fills in? |
583
+ | ----------- | ------------------------------------ | ---------------- |
584
+ | `undefined` | Not provided — parent preserved | N/A |
585
+ | `null` | Intentional unset — parent discarded | Yes |
586
+ | `false` | Tombstone — blocks everything | No |
275
587
 
276
588
  ---
277
589
 
278
590
  ## Advanced States (`@` prefix)
279
591
 
280
- | Prefix | Purpose | Example |
281
- |--------|---------|---------|
282
- | `@media` | Media queries | `@media(w < 768px)` |
283
- | `@(...)` | Container queries | `@(panel, w >= 300px)` |
284
- | `@supports` | Feature/selector support | `@supports(display: grid)` |
285
- | `@root` | Root element states | `@root(schema=dark)` |
286
- | `@parent` | Parent/ancestor element states | `@parent(hovered)` |
287
- | `@own` | Sub-element's own state | `@own(hovered)` |
288
- | `@starting` | Entry animation | `@starting` |
289
- | `:is()` | CSS `:is()` structural pseudo-class | `:is(fieldset > label)` |
290
- | `:has()` | CSS `:has()` relational pseudo-class | `:has(> Icon)` |
291
- | `:not()` | CSS `:not()` negation (prefer `!:is()`) | `:not(:first-child)` |
292
- | `:where()` | CSS `:where()` (zero specificity) | `:where(Section)` |
592
+ | Prefix | Purpose | Example |
593
+ | ----------- | ----------------------------------------- | -------------------------- |
594
+ | `@media` | Media queries | `@media(w < 768px)` |
595
+ | `@(...)` | Container queries | `@(panel, w >= 300px)` |
596
+ | `@supports` | Feature/selector support | `@supports(display: grid)` |
597
+ | `@root` | Root element states | `@root(schema=dark)` |
598
+ | `@parent` | Parent/ancestor element states | `@parent(hovered)` |
599
+ | `@own` | Sub-element's own state | `@own(hovered)` |
600
+ | `@starting` | Entry animation | `@starting` |
601
+ | `_` | Fallback floor (always-on, never negated) | `_` |
602
+ | `:is()` | CSS `:is()` structural pseudo-class | `:is(fieldset > label)` |
603
+ | `:has()` | CSS `:has()` relational pseudo-class | `:has(> Icon)` |
604
+ | `:not()` | CSS `:not()` negation (prefer `!:is()`) | `:not(:first-child)` |
605
+ | `:where()` | CSS `:where()` (zero specificity) | `:where(Section)` |
606
+
607
+ > **Specificity.** All state selectors Tasty generates (modifiers, pseudo-classes,
608
+ > `:is()`/`:not()` groups, and `@root` / `@parent` context) are wrapped in
609
+ > `:where(...)` so they carry **zero specificity**. The only specificity anchors
610
+ > are the doubled component class (`.t0.t0`) and sub-element `[data-element]`
611
+ > attributes. This means overlapping rules (e.g. a `_` fallback floor and the
612
+ > states layered over it) resolve purely by **source order** — Tasty emits
613
+ > lower-priority states first and higher-priority states last so the cascade
614
+ > produces the intended winner.
293
615
 
294
616
  ### `@media(...)` — Media Queries
295
617
 
296
- Media queries support dimension shorthands and custom unit expansion:
618
+ Media queries support dimension shorthands:
297
619
 
298
620
  | Shorthand | Expands to |
299
- |-----------|------------|
300
- | `w` | `width` |
301
- | `h` | `height` |
621
+ | --------- | ---------- |
622
+ | `w` | `width` |
623
+ | `h` | `height` |
302
624
 
303
625
  ```jsx
304
626
  fill: {
@@ -309,16 +631,23 @@ fill: {
309
631
  }
310
632
  ```
311
633
 
312
- | Tasty syntax | CSS output |
313
- |--------------|------------|
314
- | `@media(w < 768px)` | `@media (width < 768px)` |
315
- | `@media(600px <= w < 1200px)` | `@media (600px <= width < 1200px)` |
316
- | `@media:print` | `@media print` |
317
- | `@media:screen` | `@media screen` |
634
+ | Tasty syntax | CSS output |
635
+ | ------------------------------------ | ------------------------------------- |
636
+ | `@media(w < 768px)` | `@media (width < 768px)` |
637
+ | `@media(600px <= w < 1200px)` | `@media (600px <= width < 1200px)` |
638
+ | `@media:print` | `@media print` |
639
+ | `@media:screen` | `@media screen` |
640
+ | `@media:all` | `@media all` |
641
+ | `@media:speech` | `@media speech` |
318
642
  | `@media(prefers-color-scheme: dark)` | `@media (prefers-color-scheme: dark)` |
319
- | `@media(prefers-reduced-motion)` | `@media (prefers-reduced-motion)` |
643
+ | `@media(prefers-reduced-motion)` | `@media (prefers-reduced-motion)` |
644
+ | `@media(aspect-ratio > 16/9)` | `@media (aspect-ratio > 16/9)` |
645
+
646
+ Tasty units resolve to their literal length inside query conditions, built-in and configured units alike: `@media(w < 40x)` emits `@media (width < 320px)`. A query condition cannot read a custom property, so a unit configured as one (`units: { x: 'var(--gap)' }`) cannot be used there; write that length in `px`, `em`, or `rem`.
320
647
 
321
- Custom units work inside media queries: `@media(w < 40x)` → `@media (width < calc(var(--gap) * 40))`.
648
+ Units are only converted in features that take a length: `width`, `height`, `inline-size`, and `block-size`, with or without `min-`/`max-` (`@media(min-width: 40x)` converts too). Every other feature keeps its value as written, so `@media(min-resolution: 2x)` and `@media(resolution >= 2x)` reach the browser unchanged: there `x` is CSS's own resolution unit, an alias of `dppx`.
649
+
650
+ When it combines or orders conditions, Tasty compares bounds only within one unit. `@media(w >= 600px) & @media(w < 40em)` keeps both bounds, because a query `em` follows the user's font size, so `600px` and `40em` cannot be ordered at build time.
322
651
 
323
652
  In practice, define state aliases via `configure({ states })` and use `@mobile` instead of writing the full query in every component.
324
653
 
@@ -326,12 +655,12 @@ In practice, define state aliases via `configure({ states })` and use `@mobile`
326
655
 
327
656
  Container queries use the syntax `@(name, condition)` for named containers or `@(condition)` for the nearest ancestor container. Dimension shorthands (`w`, `h`, `is`, `bs`) are expanded the same way as `@media`.
328
657
 
329
- | Shorthand | Expands to |
330
- |-----------|------------|
331
- | `w` | `width` |
332
- | `h` | `height` |
333
- | `is` | `inline-size` |
334
- | `bs` | `block-size` |
658
+ | Shorthand | Expands to |
659
+ | --------- | ------------- |
660
+ | `w` | `width` |
661
+ | `h` | `height` |
662
+ | `is` | `inline-size` |
663
+ | `bs` | `block-size` |
335
664
 
336
665
  ```jsx
337
666
  const Panel = tasty({
@@ -344,26 +673,31 @@ const Panel = tasty({
344
673
  });
345
674
  ```
346
675
 
347
- | Tasty syntax | CSS output |
348
- |--------------|------------|
349
- | `@(layout, w < 600px)` | `@container layout (width < 600px)` |
350
- | `@(w < 600px)` | `@container (width < 600px)` |
351
- | `@(layout, $variant=danger)` | `@container layout style(--variant: "danger")` |
352
- | `@(layout, $compact)` | `@container layout style(--compact)` |
353
- | `@(scroll-state(stuck: top))` | `@container scroll-state(stuck: top)` |
354
- | `@(nav, scroll-state(stuck: top))` | `@container nav scroll-state(stuck: top)` |
676
+ | Tasty syntax | CSS output |
677
+ | ---------------------------------- | -------------------------------------------- |
678
+ | `@(layout, w < 600px)` | `@container layout (width < 600px)` |
679
+ | `@(w < 600px)` | `@container (width < 600px)` |
680
+ | `@(layout, $variant=danger)` | `@container layout style(--variant: danger)` |
681
+ | `@(layout, $compact)` | `@container layout style(--compact)` |
682
+ | `@(scroll-state(stuck: top))` | `@container scroll-state(stuck: top)` |
683
+ | `@(nav, scroll-state(stuck: top))` | `@container nav scroll-state(stuck: top)` |
355
684
 
356
- Container style queries use `$prop` (boolean) or `$prop=value` syntax, which maps to CSS `style(--prop)` or `style(--prop: "value")`.
685
+ Container style queries use `$prop` (boolean) or `$prop=value` syntax, which maps to CSS `style(--prop)` or `style(--prop: value)`. The value is emitted unquoted, so it matches a custom property set to the identifier `danger`, not the string `"danger"`.
686
+
687
+ Other size features pass through as written: `@(aspect-ratio > 1)` → `@container (aspect-ratio > 1)`, `@(orientation: portrait)` → `@container (orientation: portrait)`. They need a container with `containerType: 'size'`, since an `inline-size` container has no block size to compare against.
357
688
 
358
689
  ### `@supports(...)` — Feature Queries
359
690
 
360
- Feature queries test CSS property support. Use `$` as the first argument to test selector support:
691
+ Feature queries test CSS property support and accept CSS support functions such
692
+ as `at-rule()`. Use `$` as the first argument to test selector support:
361
693
 
362
- | Tasty syntax | CSS output |
363
- |--------------|------------|
364
- | `@supports(display: grid)` | `@supports (display: grid)` |
365
- | `@supports($, :has(*))` | `@supports selector(:has(*))` |
366
- | `!@supports(display: grid)` | `@supports (not (display: grid))` |
694
+ | Tasty syntax | CSS output |
695
+ | ----------------------------- | ----------------------------------- |
696
+ | `@supports(display: grid)` | `@supports (display: grid)` |
697
+ | `@supports($, :has(*))` | `@supports selector(:has(*))` |
698
+ | `@supports(at-rule(@scope))` | `@supports (at-rule(@scope))` |
699
+ | `!@supports(display: grid)` | `@supports (not (display: grid))` |
700
+ | `!@supports(at-rule(@scope))` | `@supports (not (at-rule(@scope)))` |
367
701
 
368
702
  ```jsx
369
703
  display: {
@@ -372,6 +706,114 @@ display: {
372
706
  }
373
707
  ```
374
708
 
709
+ `at-rule()` tests whether the browser supports the named at-rule. Its surrounding
710
+ parentheses in Tasty's CSS output are valid CSS. Negation and combinations with
711
+ other states use the same syntax as property queries:
712
+
713
+ ```jsx
714
+ color: {
715
+ _: 'red',
716
+ '@supports(at-rule(@scope)) & @supports(display: grid)': 'blue',
717
+ }
718
+ ```
719
+
720
+ Use `_` to keep a base value when a browser cannot evaluate a query. A support
721
+ query only detects a browser feature; it does not add an API for authoring the
722
+ queried at-rule in a Tasty style object. For conditional stylesheet imports such
723
+ as `@import url("scoped.css") supports(at-rule(@scope));`, use an ordinary CSS
724
+ stylesheet or document-level `useRawCSS()`. Put imports before other rules in
725
+ that stylesheet. Imports cannot be used in constructable stylesheets, including
726
+ Tasty's adopted-sheet mode for Shadow DOM.
727
+
728
+ ### `_` — Fallback Floor
729
+
730
+ By default Tasty makes states **mutually exclusive**: a higher-priority state
731
+ turns the lower-priority ones off via negation, so exactly one branch applies.
732
+ This relies on `A | !A` always being true. CSS feature/container queries break
733
+ that assumption: `@supports(...)` and `@(...)` queries can be **unknown** (not
734
+ just true/false), and `not(unknown)` is also unknown — so a negated default
735
+ branch silently never applies. The classic case is `scroll-state`: a browser can
736
+ support `container-type: scroll-state` while a specific `scroll-state(...)` query
737
+ is unknown, leaving _no_ branch active.
738
+
739
+ The `_` fallback floor solves this. Use `_` as a **standalone key** and its value
740
+ **always applies** as a guaranteed floor: it never receives negation, and
741
+ higher-priority states simply layer over it via the cascade.
742
+
743
+ ```jsx
744
+ inset: {
745
+ _: '0 top',
746
+ '@supports(container-type: scroll-state) & @(scroll-state(scrolled: block-end))':
747
+ '-80x top',
748
+ }
749
+ ```
750
+
751
+ ```css
752
+ .t0.t0 {
753
+ inset: 0 auto auto auto;
754
+ }
755
+ @supports (container-type: scroll-state) {
756
+ @container scroll-state(scrolled: block-end) {
757
+ .t0.t0 {
758
+ inset: -640px auto auto auto;
759
+ }
760
+ }
761
+ }
762
+ ```
763
+
764
+ The floor is emitted as a bare rule (no negated `@supports` / container branches),
765
+ so it always applies. When the override matches it wins because it is emitted
766
+ later and all state selectors share the same specificity (see the note on
767
+ `:where()` above).
768
+
769
+ Notes:
770
+
771
+ - `_` is a **standalone key only** — it defines a single map-wide floor and
772
+ cannot be combined with state logic. Keys like `_ & hovered` or `_ | focused`
773
+ are ignored with an `INVALID_FALLBACK_KEY` dev warning.
774
+ - `_` can coexist with the bare `''` default when other states exist: `''` is the
775
+ negated default, `_` is the always-on floor. With only `_` and `''` (no other
776
+ states) the `''` default is redundant — Tasty keeps the `_` value and drops
777
+ `''` with a `REDUNDANT_DEFAULT_STATE` warning.
778
+ - `_` is position-independent: it is always placed at the lowest priority
779
+ regardless of where it appears in the map.
780
+
781
+ #### `_` vs the `''` default
782
+
783
+ In simple maps where every other state is a plain modifier (always cleanly
784
+ on/off), `_` and `''` produce the **same visible result** — the base value shows
785
+ whenever no other state wins. They diverge in three situations, and the root
786
+ cause is always the same: **`''` is mutually exclusive (turned off by negation),
787
+ while `_` is always on (layered underneath).**
788
+
789
+ - **Unknown / invalid branches.** If a higher-priority branch sits behind a query
790
+ that can be _unknown_ (`@supports`, container, `scroll-state`) or uses a
791
+ selector the browser drops, the negated `''` default disappears along with it
792
+ (`not(unknown) = unknown`), leaving the property with no rule. The `_` floor
793
+ survives because it is an unconditional bare rule. This is the case `_` exists
794
+ for.
795
+
796
+ - **Empty / "unset" states.** A state can intentionally produce _no_ output (an
797
+ empty value) to leave a property unset while that state is active. With `''`
798
+ this works — the default is negated away and nothing replaces it, so the
799
+ property unsets. With `_` the floor can never be turned off, so its value keeps
800
+ applying and the "unset on this state" intent is lost.
801
+
802
+ ```jsx
803
+ // '' : color unsets while loading. '_' : color stays #text while loading.
804
+ color: { '': '#text', loading: '' }
805
+ ```
806
+
807
+ - **States with different output shapes.** Because `_` layers additively, when
808
+ different states emit _different sets_ of declarations, the floor's
809
+ declarations bleed through wherever the winning state does not override the
810
+ same property — which can produce inconsistent combinations. A `''` default is
811
+ swapped out cleanly by its mutually-exclusive condition.
812
+
813
+ Rule of thumb: **use `''` for the normal default** (clean mutual exclusivity,
814
+ supports unsetting), and reach for `_` only when a value must survive an
815
+ _unknown_ higher-priority branch.
816
+
375
817
  ### `@root(...)` — Root Element States
376
818
 
377
819
  Root states generate selectors on the `:root` element. They are useful for theme modes, feature flags, and other page-level conditions:
@@ -386,15 +828,15 @@ color: {
386
828
  }
387
829
  ```
388
830
 
389
- | Tasty syntax | CSS selector |
390
- |--------------|-------------|
391
- | `@root(schema=dark)` | `:root[data-schema="dark"]` |
392
- | `@root(hovered)` | `:root[data-hovered]` |
393
- | `@root(.premium-user)` | `:root.premium-user` |
394
- | `@root([lang="en"])` | `:root[lang="en"]` |
395
- | `!@root(schema=dark)` | `:root:not([data-schema="dark"])` |
831
+ | Tasty syntax | CSS selector |
832
+ | ---------------------- | --------------------------------- |
833
+ | `@root(schema=dark)` | `:root[data-schema="dark"]` |
834
+ | `@root(hovered)` | `:root[data-hovered]` |
835
+ | `@root(.premium-user)` | `:root.premium-user` |
836
+ | `@root([lang="en"])` | `:root[lang="en"]` |
837
+ | `!@root(schema=dark)` | `:root:not([data-schema="dark"])` |
396
838
 
397
- Root conditions are prepended to the component selector: `:root[data-schema="dark"] .t0.t0 { ... }`.
839
+ Root conditions are prepended to the component selector inside `:where()`: `:where(:root[data-schema="dark"]) .t0.t0 { ... }`.
398
840
 
399
841
  ### `@own(...)` — Sub-element's Own State
400
842
 
@@ -408,7 +850,7 @@ const Nav = tasty({
408
850
  '': '#text',
409
851
  '@own(:hover)': '#primary',
410
852
  '@own(:focus-visible)': '#primary',
411
- 'selected': '#primary', // root-level modifier
853
+ selected: '#primary', // root-level modifier
412
854
  },
413
855
  },
414
856
  },
@@ -416,14 +858,28 @@ const Nav = tasty({
416
858
  });
417
859
  ```
418
860
 
419
- | Tasty syntax (inside sub-element) | CSS output |
420
- |-----------------------------------|------------|
421
- | `@own(:hover)` | `:hover` on the sub-element selector |
422
- | `@own(hovered)` | `[data-hovered]` on the sub-element selector |
423
- | `@own(theme=dark)` | `[data-theme="dark"]` on the sub-element selector |
861
+ | Tasty syntax (inside sub-element) | CSS output |
862
+ | --------------------------------- | ------------------------------------------------- |
863
+ | `@own(:hover)` | `:hover` on the sub-element selector |
864
+ | `@own(hovered)` | `[data-hovered]` on the sub-element selector |
865
+ | `@own(theme=dark)` | `[data-theme="dark"]` on the sub-element selector |
424
866
 
425
867
  `@own()` is only valid inside sub-element styles. Using it on root styles emits a warning and is treated as a regular modifier.
426
868
 
869
+ When `$` ends in a pseudo-element, `@own()` is the pseudo-element's own state and goes after it:
870
+
871
+ ```jsx
872
+ Label: {
873
+ $: '@::part(label)',
874
+ color: { '': '#text', '@own(:focus)': '#primary' },
875
+ },
876
+ // → .t0.t0 [data-element="Label"]::part(label):where(:focus) { … }
877
+ ```
878
+
879
+ A pseudo-element has no attributes, classes, or place in the DOM tree. So a state that tests a modifier (`@own(hovered)`), an attribute (`@own([open])`), a class, or a tree position (`@own(:first-child)`, `@own(:has(…))`) can never match it. Tasty ignores such a state and warns. To condition on the element the pseudo-element belongs to, write it in `$` before the pseudo-element (`$: 'a[rel="next"]::before'`), or use `@parent()` for its ancestors.
880
+
881
+ This covers every pseudo-element form: `::before`, `::marker`, `::backdrop`, vendor-prefixed ones such as `::-webkit-details-marker`, functional ones such as `::part(label)`, and the legacy `:before`, `:after`, `:first-line`, `:first-letter`. Each item of a `$` list is judged on its own. Tasty emits pseudo-class states regardless of browser support. Only some pseudo-elements, such as `::part()` and `::-webkit-scrollbar-thumb`, match states like `:hover` or `:focus` today.
882
+
427
883
  ### `@starting` — Entry Animation
428
884
 
429
885
  Wraps the rule in `@starting-style`, enabling CSS entry animations for elements as they appear in the DOM:
@@ -433,40 +889,40 @@ const FadeIn = tasty({
433
889
  styles: {
434
890
  opacity: { '': '1', '@starting': '0' },
435
891
  transform: { '': 'scale(1)', '@starting': 'scale(0.95)' },
436
- transition: 'opacity 0.3s, translate 0.3s',
892
+ transition: 'opacity, translate',
437
893
  },
438
894
  });
439
895
  ```
440
896
 
441
- | Tasty syntax | CSS output |
442
- |--------------|------------|
443
- | `@starting` | `@starting-style { .t0.t0 { ... } }` |
897
+ | Tasty syntax | CSS output |
898
+ | ------------ | ------------------------------------ |
899
+ | `@starting` | `.t0.t0 { @starting-style { ... } }` |
444
900
 
445
901
  ### `@parent(...)` — Parent Element States
446
902
 
447
- Style based on ancestor element attributes. Uses `:is([selector] *)` / `:not([selector] *)` for symmetric, composable parent checks. Boolean logic (`&`, `|`, `!`, `^`) is supported inside `@parent()`.
903
+ Style based on ancestor element attributes. Uses `:where([selector] *)` / `:where(:not([selector] *))` for symmetric, composable parent checks. Boolean logic (`&`, `|`, `!`, `^`) is supported inside `@parent()`.
448
904
 
449
905
  ```jsx
450
906
  const Highlight = tasty({
451
907
  styles: {
452
908
  fill: {
453
909
  '': '#white',
454
- '@parent(hovered)': '#gray.05', // Any ancestor has [data-hovered]
455
- '@parent(theme=dark, >)': '#dark-02', // Direct parent has [data-theme="dark"]
910
+ '@parent(hovered)': '#gray.05', // Any ancestor has [data-hovered]
911
+ '@parent(theme=dark, >)': '#dark-02', // Direct parent has [data-theme="dark"]
456
912
  },
457
913
  },
458
914
  });
459
915
  ```
460
916
 
461
- | Syntax | CSS Output |
462
- |--------|------------|
463
- | `@parent(hovered)` | `:is([data-hovered] *)` |
464
- | `!@parent(hovered)` | `:not([data-hovered] *)` |
465
- | `@parent(hovered, >)` | `:is([data-hovered] > *)` (direct parent) |
466
- | `@parent(.active)` | `:is(.active *)` |
467
- | `@parent(hovered & focused)` | `:is([data-hovered][data-focused] *)` (same ancestor) |
468
- | `@parent(hovered) & @parent(focused)` | `:is([data-hovered] *):is([data-focused] *)` (independent ancestors) |
469
- | `@parent(hovered \| focused)` | `:is([data-hovered] *, [data-focused] *)` (OR inside single wrapper) |
917
+ | Syntax | CSS Output |
918
+ | ------------------------------------- | -------------------------------------------------------------------------- |
919
+ | `@parent(hovered)` | `:where([data-hovered] *)` |
920
+ | `!@parent(hovered)` | `:where(:not([data-hovered] *))` |
921
+ | `@parent(hovered, >)` | `:where([data-hovered] > *)` (direct parent) |
922
+ | `@parent(.active)` | `:where(.active *)` |
923
+ | `@parent(hovered & focused)` | `:where([data-hovered][data-focused] *)` (same ancestor) |
924
+ | `@parent(hovered) & @parent(focused)` | `:where([data-hovered] *):where([data-focused] *)` (independent ancestors) |
925
+ | `@parent(hovered \| focused)` | `:where([data-hovered] *, [data-focused] *)` (OR inside single wrapper) |
470
926
 
471
927
  For sub-elements, the parent check applies to the root element's ancestors:
472
928
 
@@ -481,12 +937,12 @@ const Card = tasty({
481
937
  },
482
938
  },
483
939
  });
484
- // → .t0.t0:is([data-hovered] *) [data-element="Label"]
940
+ // → .t0.t0:where([data-hovered] *) [data-element="Label"]
485
941
  ```
486
942
 
487
943
  ### `:is()`, `:has()` — CSS Structural Pseudo-classes
488
944
 
489
- Use CSS structural pseudo-classes directly in state keys. Capitalized words become `[data-element="..."]` selectors; lowercase words are HTML tags. A trailing combinator (`>`, `+`, `~`) is auto-completed with `*`.
945
+ Use CSS structural pseudo-classes directly in state keys. Capitalized words become `[data-element="..."]` selectors; lowercase words are HTML tags. A trailing combinator (`>`, `+`, `~`) is auto-completed with `*`. Leading combinators (`> Icon`, `+ Icon`) are relative selectors and are valid only inside `:has()`.
490
946
 
491
947
  `:where()` and `:not()` are also supported but rarely needed — use `:is()` and `!` negation instead.
492
948
 
@@ -497,38 +953,38 @@ const Card = tasty({
497
953
  styles: {
498
954
  display: {
499
955
  '': 'block',
500
- ':has(> Icon)': 'grid', // has Icon as direct child
501
- ':has(+ Icon)': 'grid', // immediately followed by an Icon sibling
502
- ':has(~ Icon)': 'grid', // has an Icon sibling somewhere after
503
- ':has(Icon +)': 'grid', // immediately preceded by an Icon sibling (auto-completes to `Icon + *`)
504
- ':has(Icon ~)': 'grid', // has an Icon sibling somewhere before (auto-completes to `Icon ~ *`)
505
- ':is(fieldset > label)': 'inline', // is a label inside a fieldset (HTML tags)
506
- '!:has(> Icon)': 'flex', // negation: no Icon child
956
+ ':has(> Icon)': 'grid', // has Icon as direct child
957
+ ':has(+ Icon)': 'grid', // immediately followed by an Icon sibling
958
+ ':has(~ Icon)': 'grid', // has an Icon sibling somewhere after
959
+ ':has(Icon +)': 'grid', // immediately preceded by an Icon sibling (auto-completes to `Icon + *`)
960
+ ':has(Icon ~)': 'grid', // has an Icon sibling somewhere before (auto-completes to `Icon ~ *`)
961
+ ':is(fieldset > label)': 'inline', // is a label inside a fieldset (HTML tags)
962
+ '!:has(> Icon)': 'flex', // negation: no Icon child
507
963
  },
508
964
  },
509
965
  });
510
966
  ```
511
967
 
512
- | Syntax | CSS Output | Meaning |
513
- |--------|------------|---------|
514
- | `:has(> Icon)` | `:has(> [data-element="Icon"])` | Has Icon as direct child |
515
- | `:has(+ Icon)` | `:has(+ [data-element="Icon"])` | Immediately followed by an Icon sibling |
516
- | `:has(~ Icon)` | `:has(~ [data-element="Icon"])` | Has an Icon sibling somewhere after |
517
- | `:has(Icon +)` | `:has([data-element="Icon"] + *)` | Immediately preceded by an Icon sibling |
518
- | `:has(Icon ~)` | `:has([data-element="Icon"] ~ *)` | Has an Icon sibling somewhere before |
519
- | `:has(>)` | `:has(> *)` | Has any direct child |
520
- | `:is(> Field + input)` | `:is(> [data-element="Field"] + input)` | Structural match |
521
- | `:has(button)` | `:has(button)` | HTML tag (lowercase, unchanged) |
522
- | `!:has(> Icon)` | `:not(:has(> [data-element="Icon"]))` | Negation (use `!`) |
523
- | `!:is(Panel)` | `:not([data-element="Panel"])` | Negation (use `!:is`) |
968
+ | Syntax | CSS Output | Meaning |
969
+ | -------------------- | ------------------------------------- | --------------------------------------- |
970
+ | `:has(> Icon)` | `:has(> [data-element="Icon"])` | Has Icon as direct child |
971
+ | `:has(+ Icon)` | `:has(+ [data-element="Icon"])` | Immediately followed by an Icon sibling |
972
+ | `:has(~ Icon)` | `:has(~ [data-element="Icon"])` | Has an Icon sibling somewhere after |
973
+ | `:has(Icon +)` | `:has([data-element="Icon"] + *)` | Immediately preceded by an Icon sibling |
974
+ | `:has(Icon ~)` | `:has([data-element="Icon"] ~ *)` | Has an Icon sibling somewhere before |
975
+ | `:has(>)` | `:has(> *)` | Has any direct child |
976
+ | `:is(Field + input)` | `:is([data-element="Field"] + input)` | Is an input right after a Field sibling |
977
+ | `:has(button)` | `:has(button)` | HTML tag (lowercase, unchanged) |
978
+ | `!:has(> Icon)` | `:not(:has(> [data-element="Icon"]))` | Negation (use `!`) |
979
+ | `!:is(Panel)` | `:not([data-element="Panel"])` | Negation (use `!:is`) |
524
980
 
525
981
  Combine with other states using boolean logic (`&`, `|`, `!`, `^`):
526
982
 
527
983
  ```jsx
528
- ':has(> Icon) & hovered' // AND: structural + data attribute
529
- '@parent(hovered) & :has(> Icon)' // AND: parent check + structural
530
- ':has(> Icon) | :has(> Button)' // OR: either sub-element present
531
- ':has(> Icon) ^ :has(> Button)' // XOR: exactly one present
984
+ ':has(> Icon) & hovered'; // AND: structural + data attribute
985
+ '@parent(hovered) & :has(> Icon)'; // AND: parent check + structural
986
+ ':has(> Icon) | :has(> Button)'; // OR: either sub-element present
987
+ ':has(> Icon) ^ :has(> Button)'; // XOR: exactly one present
532
988
  ```
533
989
 
534
990
  > **Nesting limit:** The state key parser supports up to 2 levels of nested parentheses inside `:is()`, `:has()`, `:not()`, and `:where()` — e.g. `:has(Input:not(:disabled))` works, but 3+ levels like `:has(:is(:not(:hover)))` will not be tokenized correctly. This covers virtually all practical use cases.
@@ -553,6 +1009,8 @@ const Pulse = tasty({
553
1009
  });
554
1010
  ```
555
1011
 
1012
+ Keyframes names are case-sensitive and keep their authored case in `animation` and `animationName` (`fadeIn`, not `fadein`), so they match `@keyframes` defined here, in `configure({ keyframes })`, or in plain CSS. Everything else in the value — durations, timing functions, keywords — is parsed as usual.
1013
+
556
1014
  ---
557
1015
 
558
1016
  ## Properties (`@property`)
@@ -563,39 +1021,59 @@ CSS cannot transition or animate custom properties unless the browser knows thei
563
1021
  const AnimatedGradient = tasty({
564
1022
  styles: {
565
1023
  '$gradient-angle': '0deg',
566
- '#theme': 'okhsl(280 80% 50%)',
567
- background: 'linear-gradient($gradient-angle, #theme, transparent)',
568
- transition: '$$gradient-angle 0.3s, ##theme 0.3s',
1024
+ '#theme': 'okhst(280 80% 50%)',
1025
+ image: 'linear-gradient($gradient-angle, #theme, #clear)',
1026
+ transition: '$$gradient-angle, ##theme',
569
1027
  },
570
1028
  });
571
1029
  ```
572
1030
 
573
1031
  Here `$gradient-angle: '0deg'` is detected as `<angle>` and `#theme` as `<color>` (via the `#name` naming convention), so both transitions work without any manual `@property` declarations. Numeric types (`<number>`, `<length>`, `<percentage>`, `<angle>`, `<time>`) are inferred from values; `<color>` is inferred from `#name` tokens.
574
1032
 
575
- Use explicit `@properties` when you need non-default settings like `inherits: false`:
1033
+ Use explicit `@property` when you need non-default settings like `inherits: false`:
576
1034
 
577
1035
  ```jsx
578
- '@properties': {
1036
+ '@property': {
579
1037
  '$gradient-angle': { syntax: '<angle>', inherits: false, initialValue: '0deg' },
580
1038
  },
581
1039
  ```
582
1040
 
1041
+ ### Default properties
1042
+
1043
+ Tasty registers these properties itself. Style handlers read their defaults from them rather than repeating the values inline, so styles work before you define any tokens, and defining a token replaces the initial value.
1044
+
1045
+ | Token | Initial value | Read by |
1046
+ | ---------------------------------------------------- | ---------------------------------------- | -------------------------------------------------------------- |
1047
+ | `#current` | `currentcolor` | anything reading `$current-color`, which `color` sets |
1048
+ | `#white`, `#black` | `rgb(255 255 255)`, `rgb(0 0 0)` | your styles |
1049
+ | `#border` | `currentcolor` | `border` with no color |
1050
+ | `#outline` | `currentcolor` | `outline` with no color |
1051
+ | `$gap`, `$radius`, `$border-width`, `$outline-width` | `8px`, `6px`, `1px`, `3px` | units you point at them, as in `units: { x: 'var(--gap)' }` |
1052
+ | `$transition` | `80ms` | `transition` with no duration |
1053
+ | `$sharp-radius` | `0px` | the sharp corners of `radius: 'leaf'` and `radius: 'backleaf'` |
1054
+ | `$bold-font-weight` | `700` | `preset: 'name / strong'` |
1055
+ | `$font-sans-fallback`, `$font-mono-fallback` | a `system-ui` and a `ui-monospace` stack | `font` and presets, after `$font-sans` / `$font-mono` |
1056
+
1057
+ Every rendering path emits them: the client injector, the SSR collector (`TastyRegistry`, `tastyIntegration()`, `runWithCollector()`), the `withTastyNext()` shared stylesheet, and the Babel plugin. CSS written with the programmatic API needs [`extractConfigProperties()`](tasty-static.md#programmatic-api), once per stylesheet. Server rendering without a collector, such as Astro without `tastyIntegration()`, emits none of them.
1058
+
1059
+ The initial values need `@property` support: Chrome and Edge 85+, Firefox 128+, Safari 16.4+. In older engines a handler that reads one of these tokens resolves to nothing unless your tokens define it: a `border` with no color draws no border, and a `transition` with no duration does not animate. To support those engines, define the tokens your styles rely on in `configure({ tokens })`.
1060
+
583
1061
  ---
584
1062
 
585
- ## Font Face (`@fontFace`)
1063
+ ## Font Face (`@font-face`)
586
1064
 
587
1065
  Register custom fonts directly inside a `styles` object. Keys are font-family names, values are descriptor objects (or arrays of them for multiple weights/styles).
588
1066
 
589
1067
  ```ts
590
1068
  const Heading = tasty({
591
1069
  styles: {
592
- '@fontFace': {
1070
+ '@font-face': {
593
1071
  'Brand Sans': {
594
1072
  src: 'url("/fonts/brand-sans.woff2") format("woff2")',
595
1073
  fontDisplay: 'swap',
596
1074
  },
597
1075
  },
598
- fontFamily: '"Brand Sans", sans-serif',
1076
+ font: '"Brand Sans", sans-serif',
599
1077
  },
600
1078
  });
601
1079
  ```
@@ -605,7 +1083,7 @@ const Heading = tasty({
605
1083
  Supply an array to register several variants of the same family:
606
1084
 
607
1085
  ```ts
608
- '@fontFace': {
1086
+ '@font-face': {
609
1087
  'Brand Sans': [
610
1088
  { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
611
1089
  { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
@@ -615,34 +1093,34 @@ Supply an array to register several variants of the same family:
615
1093
 
616
1094
  ### Supported descriptors
617
1095
 
618
- | Descriptor | CSS property | Type |
619
- |---|---|---|
620
- | `src` (required) | `src` | `string` |
621
- | `fontWeight` | `font-weight` | `string \| number` |
622
- | `fontStyle` | `font-style` | `string` |
623
- | `fontStretch` | `font-stretch` | `string` |
624
- | `fontDisplay` | `font-display` | `'auto' \| 'block' \| 'swap' \| 'fallback' \| 'optional'` |
625
- | `unicodeRange` | `unicode-range` | `string` |
626
- | `ascentOverride` | `ascent-override` | `string` |
627
- | `descentOverride` | `descent-override` | `string` |
628
- | `lineGapOverride` | `line-gap-override` | `string` |
629
- | `sizeAdjust` | `size-adjust` | `string` |
630
- | `fontFeatureSettings` | `font-feature-settings` | `string` |
631
- | `fontVariationSettings` | `font-variation-settings` | `string` |
1096
+ | Descriptor | CSS property | Type |
1097
+ | ----------------------- | ------------------------- | --------------------------------------------------------- |
1098
+ | `src` (required) | `src` | `string` |
1099
+ | `fontWeight` | `font-weight` | `string \| number` |
1100
+ | `fontStyle` | `font-style` | `string` |
1101
+ | `fontStretch` | `font-stretch` | `string` |
1102
+ | `fontDisplay` | `font-display` | `'auto' \| 'block' \| 'swap' \| 'fallback' \| 'optional'` |
1103
+ | `unicodeRange` | `unicode-range` | `string` |
1104
+ | `ascentOverride` | `ascent-override` | `string` |
1105
+ | `descentOverride` | `descent-override` | `string` |
1106
+ | `lineGapOverride` | `line-gap-override` | `string` |
1107
+ | `sizeAdjust` | `size-adjust` | `string` |
1108
+ | `fontFeatureSettings` | `font-feature-settings` | `string` |
1109
+ | `fontVariationSettings` | `font-variation-settings` | `string` |
632
1110
 
633
1111
  > Font-face rules are permanent — they are injected once and never cleaned up, matching how browsers handle `@font-face`.
634
1112
 
635
1113
  ---
636
1114
 
637
- ## Counter Style (`@counterStyle`)
1115
+ ## Counter Style (`@counter-style`)
638
1116
 
639
1117
  Define custom list markers via the CSS `@counter-style` at-rule. Keys are counter-style names, values are descriptor objects.
640
1118
 
641
1119
  ```ts
642
1120
  const EmojiList = tasty({
643
- tag: 'ol',
1121
+ as: 'ol',
644
1122
  styles: {
645
- '@counterStyle': {
1123
+ '@counter-style': {
646
1124
  thumbs: {
647
1125
  system: 'cyclic',
648
1126
  symbols: '"👍"',
@@ -656,23 +1134,88 @@ const EmojiList = tasty({
656
1134
 
657
1135
  ### Supported descriptors
658
1136
 
659
- | Descriptor | CSS property | Type |
660
- |---|---|---|
661
- | `system` (required) | `system` | `'cyclic' \| 'numeric' \| 'alphabetic' \| 'symbolic' \| 'additive' \| 'fixed' \| string` |
662
- | `symbols` | `symbols` | `string` |
663
- | `additiveSymbols` | `additive-symbols` | `string` |
664
- | `prefix` | `prefix` | `string` |
665
- | `suffix` | `suffix` | `string` |
666
- | `negative` | `negative` | `string` |
667
- | `range` | `range` | `string` |
668
- | `pad` | `pad` | `string` |
669
- | `fallback` | `fallback` | `string` |
670
- | `speakAs` | `speak-as` | `string` |
1137
+ | Descriptor | CSS property | Type |
1138
+ | ------------------- | ------------------ | ---------------------------------------------------------------------------------------- |
1139
+ | `system` (required) | `system` | `'cyclic' \| 'numeric' \| 'alphabetic' \| 'symbolic' \| 'additive' \| 'fixed' \| string` |
1140
+ | `symbols` | `symbols` | `string` |
1141
+ | `additiveSymbols` | `additive-symbols` | `string` |
1142
+ | `prefix` | `prefix` | `string` |
1143
+ | `suffix` | `suffix` | `string` |
1144
+ | `negative` | `negative` | `string` |
1145
+ | `range` | `range` | `string` |
1146
+ | `pad` | `pad` | `string` |
1147
+ | `fallback` | `fallback` | `string` |
1148
+ | `speakAs` | `speak-as` | `string` |
671
1149
 
672
1150
  > Counter-style rules are permanent — they are injected once and never cleaned up, matching how browsers handle `@counter-style`.
673
1151
 
674
1152
  ---
675
1153
 
1154
+ ## Functions (`@function`)
1155
+
1156
+ Define reusable, parameterized CSS [custom functions](https://developer.mozilla.org/en-US/docs/Web/CSS/@function) via the CSS `@function` at-rule. A custom function takes parameters and returns a single value — like a dynamic custom property.
1157
+
1158
+ The token convention follows Tasty's `$` vs `$$` distinction:
1159
+
1160
+ - **`$$name`** — the literal callable name (`--name`). Used for the **definition key** and for **invocation** `$$name(...)`, mirroring the existing `$$gradient-angle` → `--gradient-angle` sugar. The definition key matches the call site.
1161
+ - **`$name`** — a custom-property declaration/reference (`var(--name)`). Used for **parameters** and **local variables**, exactly like declaring custom props in a styles object.
1162
+ - **Local variables** are declared directly as `$name` keys on the descriptor — the body reads like a mini styles object.
1163
+ - `result`, local-variable values, and parameter `default` values flow through the full Tasty DSL, so units (`2x`), color tokens (`#theme`), auto-calc (`(-1 * $value)` → `calc(-1 * var(--value))`), and fallbacks (`($shadow-color, black)` → `var(--shadow-color, black)`) all work.
1164
+
1165
+ ```ts
1166
+ const Box = tasty({
1167
+ styles: {
1168
+ '@function': {
1169
+ // simplest: one bare param + result (auto-calc, no explicit calc())
1170
+ $$negative: { args: ['$value'], result: '(-1 * $value)' },
1171
+
1172
+ // typed param + default + return type + local variable
1173
+ $$shadow: {
1174
+ args: { '$shadow-color': { syntax: '<color>', default: 'inherit' } },
1175
+ returns: '<color>',
1176
+ $offset: '2px', // local variable
1177
+ result: '$offset $offset ($shadow-color, black)',
1178
+ },
1179
+ },
1180
+ margin: '$$negative(10px) top', // → margin: --negative(10px) 0 0 0
1181
+ shadow: '$$shadow(#accent)', // → box-shadow: --shadow(var(--accent-color))
1182
+ },
1183
+ });
1184
+ ```
1185
+
1186
+ Generated CSS:
1187
+
1188
+ ```css
1189
+ @function --negative(--value) {
1190
+ result: calc(-1 * var(--value));
1191
+ }
1192
+ @function --shadow(--shadow-color <color>: inherit) returns <color> {
1193
+ --offset: 2px;
1194
+ result: var(--offset) var(--offset) var(--shadow-color, black);
1195
+ }
1196
+ .t0 {
1197
+ margin: --negative(10px) 0 0 0;
1198
+ box-shadow: --shadow(var(--accent-color));
1199
+ }
1200
+ ```
1201
+
1202
+ ### Descriptor shape
1203
+
1204
+ | Field | Type | Notes |
1205
+ | ------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------- |
1206
+ | `result` (required) | `string` | The `result:` value, parsed through the Tasty DSL. |
1207
+ | `args` | `string[]` \| `Record<string, FunctionParameter>` | Ordered parameters. Array form lists bare names; object form maps names to type/default. |
1208
+ | `returns` | `string` | Optional return type, e.g. `'<color>'`. |
1209
+ | `$name` keys | `string \| number` | Any `$name` key declares a local variable `--name` (value parsed). |
1210
+
1211
+ A `FunctionParameter` is one of: `true` (bare param), a string CSS type shorthand (`'<length>'`), or `{ syntax?: string; default?: string | number }`.
1212
+
1213
+ Functions can also be registered with the [`useFunction`](react-api.md#usefunction) style function or globally via [`configure({ functions })`](configuration.md#functions) (the same map also accepts bare-key parse functions).
1214
+
1215
+ > `@function` is permanent — injected once and never cleaned up, like `@counter-style`. It is an experimental CSS feature ([Chrome 139+](https://developer.mozilla.org/en-US/docs/Web/CSS/@function)); unsupported browsers safely ignore the native rule, so use it as progressive enhancement — or enable the [`configure({ polyfills: { functions: true } })`](configuration.md#polyfills) inline polyfill to expand `$$name(...)` calls into plain CSS for full cross-browser support.
1216
+
1217
+ ---
1218
+
676
1219
  ## Style Properties
677
1220
 
678
1221
  For a complete reference of all enhanced style properties — syntax, values, modifiers, and recommendations — see **[Style Properties Reference](styles.md)**.
@@ -685,4 +1228,4 @@ For a complete reference of all enhanced style properties — syntax, values, mo
685
1228
  - **[Methodology](methodology.md)** — Recommended patterns: root + sub-elements, styleProps, tokens, wrapping
686
1229
  - **[Configuration](configuration.md)** — Tokens, recipes, custom units, style handlers, TypeScript extensions
687
1230
  - **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
688
- - **[Zero Runtime (tastyStatic)](tasty-static.md)** — Build-time static styling with Babel plugin
1231
+ - **[Build-Time Extraction (`tastyStatic`)](tasty-static.md)** — Static styling with the Babel plugin