@tenphi/tasty 0.0.0-snapshot.8a8eb7d → 0.0.0-snapshot.8be165d
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 +176 -131
- package/dist/astro-C_by9qPq.js +307 -0
- package/dist/astro-C_by9qPq.js.map +1 -0
- package/dist/{async-storage-B7_o6FKt.js → async-storage-DKK-wTD4.js} +1 -1
- package/dist/{async-storage-B7_o6FKt.js.map → async-storage-DKK-wTD4.js.map} +1 -1
- package/dist/babel-BUQGeOXA.d.ts +83 -0
- package/dist/{collector-o-UYCV-b.js → collector-BevHh16N.js} +108 -24
- package/dist/collector-BevHh16N.js.map +1 -0
- package/dist/{collector-CpU85p2G.d.ts → collector-CLVr5_p3.d.ts} +62 -7
- package/dist/{config-DOvjo65E.js → config-NcdqU9PC.js} +2812 -1496
- package/dist/config-NcdqU9PC.js.map +1 -0
- package/dist/{config-3h7BtX4l.d.ts → config-YsxGv4tq.d.ts} +351 -33
- package/dist/{context-CkSg-kDT.js → context-CA8YKeMn.js} +1 -1
- package/dist/{context-CkSg-kDT.js.map → context-CA8YKeMn.js.map} +1 -1
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +6 -6
- package/dist/{core-CPx5Lqjr.js → core-D7s7u-k1.js} +150 -182
- package/dist/core-D7s7u-k1.js.map +1 -0
- package/dist/{css-writer-DJvsfR1w.js → css-writer-BDPmetHV.js} +54 -15
- package/dist/css-writer-BDPmetHV.js.map +1 -0
- package/dist/{format-global-rules-Dbc_1tc3.js → format-global-rules-DklyaXv-.js} +1 -1
- package/dist/{format-global-rules-Dbc_1tc3.js.map → format-global-rules-DklyaXv-.js.map} +1 -1
- package/dist/{format-rules-aRlqFAd1.js → format-rules-BQCn7JZH.js} +4 -17
- package/dist/format-rules-BQCn7JZH.js.map +1 -0
- package/dist/{hydrate-Ddw7yjyx.js → hydrate-C3cfqlaQ.js} +3 -11
- package/dist/{hydrate-Ddw7yjyx.js.map → hydrate-C3cfqlaQ.js.map} +1 -1
- package/dist/{index-C_SRmAWj.d.ts → index-CBK778ne.d.ts} +294 -161
- package/dist/{index-BsJz5xBF.d.ts → index-Cd45t5NM.d.ts} +297 -62
- package/dist/index.d.ts +5 -5
- package/dist/index.js +250 -60
- package/dist/index.js.map +1 -1
- package/dist/{keyframes-C4ObN2Vc.js → keyframes-ByhOtsXB.js} +97 -199
- package/dist/keyframes-ByhOtsXB.js.map +1 -0
- package/dist/{merge-styles-BbyWO2Gc.js → merge-styles-BKfagXfV.js} +2 -2
- package/dist/{merge-styles-BbyWO2Gc.js.map → merge-styles-BKfagXfV.js.map} +1 -1
- package/dist/{merge-styles-BzOwGOGC.d.ts → merge-styles-CU7JbEwg.d.ts} +2 -2
- package/dist/{resolve-recipes-CqTtBOKx.js → resolve-recipes-vvygrWLw.js} +3 -3
- package/dist/{resolve-recipes-CqTtBOKx.js.map → resolve-recipes-vvygrWLw.js.map} +1 -1
- package/dist/ssr/astro-client.js +1 -1
- package/dist/ssr/astro-client.js.map +1 -1
- package/dist/ssr/astro-middleware-extract-static.d.ts +11 -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 +11 -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 +18 -0
- package/dist/ssr/astro-middleware-static.js +18 -0
- package/dist/ssr/astro-middleware-static.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +11 -7
- package/dist/ssr/astro-middleware.js +10 -10
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +37 -7
- package/dist/ssr/astro.js +2 -147
- package/dist/ssr/index.d.ts +2 -9
- package/dist/ssr/index.js +5 -5
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next.d.ts +2 -3
- package/dist/ssr/next.js +6 -7
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +2 -2
- package/dist/static/index.js +4 -4
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.js.map +1 -1
- package/dist/zero/babel.d.ts +2 -81
- package/dist/zero/babel.js +27 -23
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +16 -2
- package/dist/zero/index.js +2 -2
- package/dist/zero/next.d.ts +1 -1
- package/dist/zero/next.js +1 -1
- 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 +224 -0
- package/docs/comparison.md +69 -40
- package/docs/configuration.md +470 -85
- package/docs/debug.md +7 -7
- package/docs/design-system.md +43 -24
- package/docs/dsl.md +407 -185
- package/docs/getting-started.md +60 -39
- package/docs/injector.md +58 -5
- package/docs/methodology.md +44 -38
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +4 -7
- package/docs/plugins.md +353 -0
- package/docs/react-api.md +142 -42
- package/docs/runtime-benchmarks.md +216 -0
- package/docs/ssr.md +132 -86
- package/docs/styles.md +56 -9
- package/docs/tasty-static.md +140 -105
- package/package.json +50 -18
- package/tasty.config.ts +4 -0
- package/dist/collector-o-UYCV-b.js.map +0 -1
- package/dist/config-DOvjo65E.js.map +0 -1
- package/dist/core-CPx5Lqjr.js.map +0 -1
- package/dist/css-writer-DJvsfR1w.js.map +0 -1
- package/dist/format-rules-aRlqFAd1.js.map +0 -1
- package/dist/keyframes-C4ObN2Vc.js.map +0 -1
- package/dist/ssr/astro.js.map +0 -1
package/docs/dsl.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# Style DSL Reference
|
|
2
2
|
|
|
3
|
-
This is the Tasty
|
|
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
|
-
|
|
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).
|
|
6
8
|
|
|
7
9
|
---
|
|
8
10
|
|
|
@@ -18,17 +20,28 @@ fill: { '': '#white', hovered: '#gray.05', 'theme=danger': '#red' }
|
|
|
18
20
|
|
|
19
21
|
#### State Key Types
|
|
20
22
|
|
|
21
|
-
| Syntax
|
|
22
|
-
|
|
23
|
-
| Boolean modifier
|
|
24
|
-
| Value modifier
|
|
25
|
-
| Pseudo-class
|
|
26
|
-
| Class selector
|
|
27
|
-
| Attribute selector | `[aria-expanded="true"]` | `[aria-expanded="true"]`
|
|
28
|
-
| Combined (AND)
|
|
29
|
-
| Combined (OR)
|
|
30
|
-
| Negated (NOT)
|
|
31
|
-
| Exclusive (XOR)
|
|
23
|
+
| Syntax | Example | Generated CSS |
|
|
24
|
+
| ------------------ | ------------------------ | ------------------------------------------------------------------------ |
|
|
25
|
+
| Boolean modifier | `hovered` | `[data-hovered]` |
|
|
26
|
+
| Value modifier | `theme=danger` | `[data-theme="danger"]` |
|
|
27
|
+
| Pseudo-class | `:hover` | `:hover` |
|
|
28
|
+
| Class selector | `.active` | `.active` |
|
|
29
|
+
| Attribute selector | `[aria-expanded="true"]` | `[aria-expanded="true"]` |
|
|
30
|
+
| Combined (AND) | `hovered & .active` | `[data-hovered].active` |
|
|
31
|
+
| Combined (OR) | `hovered \| focused` | `[data-hovered], [data-focused]` |
|
|
32
|
+
| Negated (NOT) | `!disabled` | `:not([data-disabled])` |
|
|
33
|
+
| Exclusive (XOR) | `hovered ^ focused` | `[data-hovered]:not([data-focused]), :not([data-hovered])[data-focused]` |
|
|
34
|
+
|
|
35
|
+
#### Automatic Native States
|
|
36
|
+
|
|
37
|
+
`disabled` and `checked` are built-in automatic states. On a Tasty component, they track the corresponding native prop or attribute, so these pairs express the same component state:
|
|
38
|
+
|
|
39
|
+
| Concise Tasty state | Explicit attribute selector |
|
|
40
|
+
| ------------------- | --------------------------- |
|
|
41
|
+
| `disabled` | `[disabled]` |
|
|
42
|
+
| `checked` | `[checked]` |
|
|
43
|
+
|
|
44
|
+
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
45
|
|
|
33
46
|
Operator precedence (highest to lowest): `!` (NOT) > `^` (XOR) > `|` (OR) > `&` (AND). Use parentheses to override: `hovered & (pressed ^ focused)`.
|
|
34
47
|
|
|
@@ -53,14 +66,18 @@ color: { '': '#text', hovered: '#accent' }
|
|
|
53
66
|
color: { hovered: '#accent', '': '#text' }
|
|
54
67
|
```
|
|
55
68
|
|
|
56
|
-
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
|
|
69
|
+
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.
|
|
57
70
|
|
|
58
71
|
### Sub-element
|
|
59
72
|
|
|
60
73
|
Element styled using a capitalized key. Identified by `data-element` attribute:
|
|
61
74
|
|
|
62
75
|
```jsx
|
|
63
|
-
styles: {
|
|
76
|
+
styles: {
|
|
77
|
+
Title: {
|
|
78
|
+
preset: 'h3';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
64
81
|
// Targets: <div data-element="Title">
|
|
65
82
|
```
|
|
66
83
|
|
|
@@ -70,19 +87,19 @@ Control how a sub-element selector attaches to the root selector using the `$` p
|
|
|
70
87
|
|
|
71
88
|
Examples below assume the sub-element key is **Cell** (i.e. `[data-element="Cell"]` in CSS):
|
|
72
89
|
|
|
73
|
-
| Pattern
|
|
74
|
-
|
|
75
|
-
|
|
|
76
|
-
| `>`
|
|
77
|
-
| `>Body>`
|
|
78
|
-
| `> Cell`
|
|
79
|
-
| `h1`
|
|
80
|
-
| `h1 >`
|
|
81
|
-
| `h1 *`
|
|
82
|
-
| `*`
|
|
83
|
-
| `&::before` | `::before`
|
|
84
|
-
| `@::before` | `[data-element="Cell"]::before`
|
|
85
|
-
| `>@.active` | `> [data-element="Cell"].active`
|
|
90
|
+
| Pattern | Result | Description |
|
|
91
|
+
| ----------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
92
|
+
| _(none)_ | `[data-element="Cell"]` | Descendant (default) |
|
|
93
|
+
| `>` | `> [data-element="Cell"]` | Direct child |
|
|
94
|
+
| `>Body>` | `> [data-element="Body"] > [data-element="Cell"]` | Chained elements |
|
|
95
|
+
| `> 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 |
|
|
96
|
+
| `h1` | `h1` | Tag selector (no key injection) |
|
|
97
|
+
| `h1 >` | `h1 > [data-element="Cell"]` | Key is direct child of tag |
|
|
98
|
+
| `h1 *` | `h1 *` | Any descendant of tag |
|
|
99
|
+
| `*` | `*` | All descendants |
|
|
100
|
+
| `&::before` | `::before` | Root pseudo (no key); `&` is required |
|
|
101
|
+
| `@::before` | `[data-element="Cell"]::before` | Pseudo on the sub-element |
|
|
102
|
+
| `>@.active` | `> [data-element="Cell"].active` | Class on the sub-element |
|
|
86
103
|
|
|
87
104
|
Rules for key injection (`[data-element="..."]`):
|
|
88
105
|
|
|
@@ -111,7 +128,7 @@ const List = tasty({
|
|
|
111
128
|
Named color prefixed with `#` that maps to CSS custom properties. Supports opacity with `.N` suffix:
|
|
112
129
|
|
|
113
130
|
```jsx
|
|
114
|
-
fill: '#purple.5'
|
|
131
|
+
fill: '#purple.5'; // → oklch(from var(--purple-color) l c h / .5)
|
|
115
132
|
```
|
|
116
133
|
|
|
117
134
|
### Modifier
|
|
@@ -123,7 +140,7 @@ mods={{ hovered: true, theme: 'danger' }}
|
|
|
123
140
|
// → data-hovered="" data-theme="danger"
|
|
124
141
|
```
|
|
125
142
|
|
|
126
|
-
Modifiers can also be exposed as top-level component props via `modProps` — see [
|
|
143
|
+
Modifiers can also be exposed as top-level component props via `modProps` — see [React API — Mod Props](react-api.md#mod-props).
|
|
127
144
|
|
|
128
145
|
---
|
|
129
146
|
|
|
@@ -133,23 +150,155 @@ Modifiers can also be exposed as top-level component props via `modProps` — se
|
|
|
133
150
|
color: '#purple', // Full opacity
|
|
134
151
|
color: '#purple.5', // 50% opacity
|
|
135
152
|
color: '#purple.05', // 5% opacity
|
|
153
|
+
color: '#purple.$fade', // Opacity from a custom property
|
|
136
154
|
fill: '#current', // → currentcolor
|
|
137
|
-
fill: '#current.5', // → color-mix(in oklab, currentcolor 50%, transparent)
|
|
138
155
|
color: '(#primary, #secondary)', // Fallback syntax
|
|
139
156
|
```
|
|
140
157
|
|
|
158
|
+
The suffix sets the alpha on the token's color with CSS relative color syntax:
|
|
159
|
+
|
|
160
|
+
```jsx
|
|
161
|
+
fill: '#purple.5';
|
|
162
|
+
// → oklch(from var(--purple-color) l c h / .5)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The channels are copied over and the alpha slot is written, which asks nothing of
|
|
166
|
+
the color beyond _being_ a color. That means the suffix works on every one of
|
|
167
|
+
these:
|
|
168
|
+
|
|
169
|
+
- a token holding a `color-mix()`, a `light-dark()`, or a `color()` in a space
|
|
170
|
+
Tasty cannot convert — none of which have channels to decompose
|
|
171
|
+
- `#current`, which resolves to the color the element inherits
|
|
172
|
+
- a `--name-color` variable declared in your own CSS, with no Tasty token
|
|
173
|
+
definition behind it
|
|
174
|
+
|
|
175
|
+
Two properties follow from writing the alpha slot rather than compositing:
|
|
176
|
+
|
|
177
|
+
- **Alpha is replaced, not multiplied.** A token holding `rgb(255 0 0 / .8)`
|
|
178
|
+
faded to `.5` is alpha `.5`, not `.4`.
|
|
179
|
+
- **The alpha may be a number or a percentage.** `#purple.$fade` emits
|
|
180
|
+
`/ var(--fade)` unchanged, so it works whether `$fade` holds `.5` or `50%` —
|
|
181
|
+
which is what `--*-opacity` properties are registered to accept.
|
|
182
|
+
|
|
183
|
+
### `#current` is the keyword
|
|
184
|
+
|
|
185
|
+
`#current` emits the `currentcolor` keyword, so it resolves against the element
|
|
186
|
+
that reads it. That is what lets it follow a color an ancestor faded — a ramp
|
|
187
|
+
that expresses its disabled state once, in `color`, fades everything painted from
|
|
188
|
+
`#current` below it with no further declarations.
|
|
189
|
+
|
|
190
|
+
The `color` style also publishes `--current-color` beside every color it sets,
|
|
191
|
+
for anything that needs the inherited color _as a color_ rather than as the
|
|
192
|
+
keyword — hand-authored CSS, or a place the keyword will not do. Read it as
|
|
193
|
+
`$current-color`. It is registered with `initial-value: currentcolor`, so where
|
|
194
|
+
nothing published it, it still resolves against each element's own color:
|
|
195
|
+
|
|
196
|
+
```jsx
|
|
197
|
+
fill: '$current-color'; // → var(--current-color)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
A color that already reads the color it inherits — `#current`, a `#current` fade
|
|
201
|
+
— is not published into it: resolving such a value a second time at a descendant
|
|
202
|
+
would fade it twice.
|
|
203
|
+
|
|
204
|
+
One case needs the wider floor to be considered. A token _defined_ as `#current`
|
|
205
|
+
and then faded gives relative color syntax a `currentcolor` origin, which Safari
|
|
206
|
+
supports only from 18:
|
|
207
|
+
|
|
208
|
+
```jsx
|
|
209
|
+
{ '#ink': '#current', fill: '#ink.5' }
|
|
210
|
+
// --ink-color: currentcolor
|
|
211
|
+
// fill: oklch(from currentcolor l c h / .5) → Chrome, Firefox, Safari 18+
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Put the fade in the token instead — `{ '#ink': '#current.5' }` — and it goes
|
|
215
|
+
through `color-mix()`, which works from Safari 16.2 and composes like every other
|
|
216
|
+
`#current` fade.
|
|
217
|
+
|
|
218
|
+
### `#current` composes instead
|
|
219
|
+
|
|
220
|
+
`#current` is the one exception, and the difference is deliberate. A token _names_
|
|
221
|
+
a color, so fading it sets its alpha. `currentcolor` is the color an element
|
|
222
|
+
**inherits**, which an ancestor may already have faded — `#current.4` means "40%
|
|
223
|
+
of what reaches me":
|
|
224
|
+
|
|
225
|
+
```jsx
|
|
226
|
+
fill: '#current.4';
|
|
227
|
+
// → color-mix(in oklab, currentcolor 40%, transparent)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
So a `#current` fade nested inside another one composes: a label at `#current.4`
|
|
231
|
+
with a fill of `#current.18` under it lands at `.072`. Color ramps built on
|
|
232
|
+
`#current` depend on that — replacing would double the opacity of every nested
|
|
233
|
+
step. Because a `color-mix()` percentage cannot be a `<number>`, an opacity
|
|
234
|
+
custom property used as `#current.$fade` must hold a unitless number; a token
|
|
235
|
+
accepts either form.
|
|
236
|
+
|
|
237
|
+
The space is always `oklch`: it is unbounded, so a wide-gamut color survives a
|
|
238
|
+
round trip that a gamut-limited space would clamp. Nothing configures this —
|
|
239
|
+
see [Color space](configuration.md#color-space).
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## CSS Color Functions
|
|
244
|
+
|
|
245
|
+
Every CSS color function is recognized as a color, so it lands in the color slot
|
|
246
|
+
of whichever style property you use it in — and tokens inside it are expanded:
|
|
247
|
+
|
|
248
|
+
```jsx
|
|
249
|
+
fill: 'color-mix(in oklab, #primary 50%, #surface)',
|
|
250
|
+
color: 'light-dark(#dark, #light)',
|
|
251
|
+
color: 'contrast-color(#primary)',
|
|
252
|
+
fill: 'color(display-p3 1 .5 0)',
|
|
253
|
+
border: '1bw solid oklch(from #primary l c h / 50%)', // relative color syntax
|
|
254
|
+
shadow: '0 0 1x color-mix(in oklab, #dark 20%, transparent)',
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
`light-dark()` is the one exception to "always a color": CSS lets it pick between
|
|
258
|
+
values of any type, so it is treated as a color only when its arguments are
|
|
259
|
+
colors. `padding: 'light-dark(1x, 2x)'` still reaches the padding slot.
|
|
260
|
+
|
|
261
|
+
A color token defined as one of these functions takes the
|
|
262
|
+
[opacity suffix](#color-tokens--opacity) like any other:
|
|
263
|
+
|
|
264
|
+
```jsx
|
|
265
|
+
const Card = tasty({
|
|
266
|
+
styles: {
|
|
267
|
+
'#brand': 'color-mix(in oklab, #primary 50%, #surface)',
|
|
268
|
+
fill: '#brand.5',
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
A [replace token](configuration.md#replace-tokens-parse-time-substitution) is
|
|
274
|
+
substituted while parsing, so its color is right there to fade in place. A
|
|
275
|
+
channel function takes the alpha after a slash; a derived function has no alpha
|
|
276
|
+
channel, so it gets wrapped:
|
|
277
|
+
|
|
278
|
+
```jsx
|
|
279
|
+
configure({
|
|
280
|
+
replaceTokens: {
|
|
281
|
+
'#solid': 'hsl(220 90% 50%)',
|
|
282
|
+
'#adaptive': 'light-dark(#dark, #light)',
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
fill: '#solid.5'; // → hsl(220 90% 50% / .5)
|
|
287
|
+
fill: '#adaptive.5'; // → oklch(from light-dark(…) l c h / .5)
|
|
288
|
+
```
|
|
289
|
+
|
|
141
290
|
---
|
|
142
291
|
|
|
143
292
|
## Built-in Units
|
|
144
293
|
|
|
145
|
-
| Unit | Description
|
|
146
|
-
|
|
147
|
-
| `x`
|
|
148
|
-
| `r`
|
|
149
|
-
| `cr` | Card border radius | `1cr`
|
|
150
|
-
| `bw` | Border width
|
|
151
|
-
| `ow` | Outline width
|
|
152
|
-
| `sf` | Stable fraction
|
|
294
|
+
| Unit | Description | Example | CSS Output |
|
|
295
|
+
| ---- | ------------------ | ------- | ------------------------------- |
|
|
296
|
+
| `x` | Gap multiplier | `2x` | `calc(var(--gap) * 2)` |
|
|
297
|
+
| `r` | Border radius | `1r` | `var(--radius)` |
|
|
298
|
+
| `cr` | Card border radius | `1cr` | `var(--card-radius)` |
|
|
299
|
+
| `bw` | Border width | `2bw` | `calc(var(--border-width) * 2)` |
|
|
300
|
+
| `ow` | Outline width | `1ow` | `var(--outline-width)` |
|
|
301
|
+
| `sf` | Stable fraction | `1sf` | `minmax(0, 1fr)` |
|
|
153
302
|
|
|
154
303
|
You can register additional custom units via [`configure()`](configuration.md#options).
|
|
155
304
|
|
|
@@ -194,7 +343,7 @@ const ElevatedCard = tasty({
|
|
|
194
343
|
|
|
195
344
|
**Post-merge recipes (`/` separator):**
|
|
196
345
|
|
|
197
|
-
Recipes listed after `/` are applied
|
|
346
|
+
Recipes listed after `/` are applied _after_ component styles using `mergeStyles`:
|
|
198
347
|
|
|
199
348
|
```jsx
|
|
200
349
|
const Input = tasty({
|
|
@@ -232,8 +381,8 @@ When a style property uses a state map, the merge behavior depends on whether th
|
|
|
232
381
|
const MyButton = tasty(Button, {
|
|
233
382
|
styles: {
|
|
234
383
|
fill: {
|
|
235
|
-
|
|
236
|
-
|
|
384
|
+
loading: '#yellow', // append new state
|
|
385
|
+
disabled: '#gray.20', // override existing state in place
|
|
237
386
|
},
|
|
238
387
|
},
|
|
239
388
|
});
|
|
@@ -243,7 +392,7 @@ const MyButton = tasty(Button, {
|
|
|
243
392
|
styles: {
|
|
244
393
|
fill: {
|
|
245
394
|
'': '#red',
|
|
246
|
-
|
|
395
|
+
hovered: '#blue',
|
|
247
396
|
},
|
|
248
397
|
},
|
|
249
398
|
});
|
|
@@ -268,8 +417,12 @@ fill: {
|
|
|
268
417
|
Use `null` inside a state map to remove a state, or `false` to block it entirely (tombstone):
|
|
269
418
|
|
|
270
419
|
```jsx
|
|
271
|
-
fill: {
|
|
272
|
-
|
|
420
|
+
fill: {
|
|
421
|
+
pressed: null;
|
|
422
|
+
} // removes pressed from the result
|
|
423
|
+
fill: {
|
|
424
|
+
disabled: false;
|
|
425
|
+
} // tombstone — no CSS for disabled, blocks recipe too
|
|
273
426
|
```
|
|
274
427
|
|
|
275
428
|
### Resetting Properties with `null` and `false`
|
|
@@ -277,36 +430,36 @@ fill: { disabled: false } // tombstone — no CSS for disabled, blocks recipe to
|
|
|
277
430
|
```jsx
|
|
278
431
|
const SimpleButton = tasty(Button, {
|
|
279
432
|
styles: {
|
|
280
|
-
fill: null,
|
|
433
|
+
fill: null, // discard parent's fill, let recipe fill in
|
|
281
434
|
border: false, // no border at all (tombstone — blocks recipe too)
|
|
282
435
|
},
|
|
283
436
|
});
|
|
284
437
|
```
|
|
285
438
|
|
|
286
|
-
| Value
|
|
287
|
-
|
|
288
|
-
| `undefined` | Not provided — parent preserved
|
|
289
|
-
| `null`
|
|
290
|
-
| `false`
|
|
439
|
+
| Value | Meaning | Recipe fills in? |
|
|
440
|
+
| ----------- | ------------------------------------ | ---------------- |
|
|
441
|
+
| `undefined` | Not provided — parent preserved | N/A |
|
|
442
|
+
| `null` | Intentional unset — parent discarded | Yes |
|
|
443
|
+
| `false` | Tombstone — blocks everything | No |
|
|
291
444
|
|
|
292
445
|
---
|
|
293
446
|
|
|
294
447
|
## Advanced States (`@` prefix)
|
|
295
448
|
|
|
296
|
-
| Prefix
|
|
297
|
-
|
|
298
|
-
| `@media`
|
|
299
|
-
| `@(...)`
|
|
300
|
-
| `@supports` | Feature/selector support
|
|
301
|
-
| `@root`
|
|
302
|
-
| `@parent`
|
|
303
|
-
| `@own`
|
|
304
|
-
| `@starting` | Entry animation
|
|
305
|
-
| `_`
|
|
306
|
-
| `:is()`
|
|
307
|
-
| `:has()`
|
|
308
|
-
| `:not()`
|
|
309
|
-
| `:where()`
|
|
449
|
+
| Prefix | Purpose | Example |
|
|
450
|
+
| ----------- | ----------------------------------------- | -------------------------- |
|
|
451
|
+
| `@media` | Media queries | `@media(w < 768px)` |
|
|
452
|
+
| `@(...)` | Container queries | `@(panel, w >= 300px)` |
|
|
453
|
+
| `@supports` | Feature/selector support | `@supports(display: grid)` |
|
|
454
|
+
| `@root` | Root element states | `@root(schema=dark)` |
|
|
455
|
+
| `@parent` | Parent/ancestor element states | `@parent(hovered)` |
|
|
456
|
+
| `@own` | Sub-element's own state | `@own(hovered)` |
|
|
457
|
+
| `@starting` | Entry animation | `@starting` |
|
|
458
|
+
| `_` | Fallback floor (always-on, never negated) | `_` |
|
|
459
|
+
| `:is()` | CSS `:is()` structural pseudo-class | `:is(fieldset > label)` |
|
|
460
|
+
| `:has()` | CSS `:has()` relational pseudo-class | `:has(> Icon)` |
|
|
461
|
+
| `:not()` | CSS `:not()` negation (prefer `!:is()`) | `:not(:first-child)` |
|
|
462
|
+
| `:where()` | CSS `:where()` (zero specificity) | `:where(Section)` |
|
|
310
463
|
|
|
311
464
|
> **Specificity.** All state selectors Tasty generates (modifiers, pseudo-classes,
|
|
312
465
|
> `:is()`/`:not()` groups, and `@root` / `@parent` context) are wrapped in
|
|
@@ -322,9 +475,9 @@ const SimpleButton = tasty(Button, {
|
|
|
322
475
|
Media queries support dimension shorthands and custom unit expansion:
|
|
323
476
|
|
|
324
477
|
| Shorthand | Expands to |
|
|
325
|
-
|
|
326
|
-
| `w`
|
|
327
|
-
| `h`
|
|
478
|
+
| --------- | ---------- |
|
|
479
|
+
| `w` | `width` |
|
|
480
|
+
| `h` | `height` |
|
|
328
481
|
|
|
329
482
|
```jsx
|
|
330
483
|
fill: {
|
|
@@ -335,14 +488,14 @@ fill: {
|
|
|
335
488
|
}
|
|
336
489
|
```
|
|
337
490
|
|
|
338
|
-
| Tasty syntax
|
|
339
|
-
|
|
340
|
-
| `@media(w < 768px)`
|
|
341
|
-
| `@media(600px <= w < 1200px)`
|
|
342
|
-
| `@media:print`
|
|
343
|
-
| `@media:screen`
|
|
491
|
+
| Tasty syntax | CSS output |
|
|
492
|
+
| ------------------------------------ | ------------------------------------- |
|
|
493
|
+
| `@media(w < 768px)` | `@media (width < 768px)` |
|
|
494
|
+
| `@media(600px <= w < 1200px)` | `@media (600px <= width < 1200px)` |
|
|
495
|
+
| `@media:print` | `@media print` |
|
|
496
|
+
| `@media:screen` | `@media screen` |
|
|
344
497
|
| `@media(prefers-color-scheme: dark)` | `@media (prefers-color-scheme: dark)` |
|
|
345
|
-
| `@media(prefers-reduced-motion)`
|
|
498
|
+
| `@media(prefers-reduced-motion)` | `@media (prefers-reduced-motion)` |
|
|
346
499
|
|
|
347
500
|
Custom units work inside media queries: `@media(w < 40x)` → `@media (width < calc(var(--gap) * 40))`.
|
|
348
501
|
|
|
@@ -352,12 +505,12 @@ In practice, define state aliases via `configure({ states })` and use `@mobile`
|
|
|
352
505
|
|
|
353
506
|
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`.
|
|
354
507
|
|
|
355
|
-
| Shorthand | Expands to
|
|
356
|
-
|
|
357
|
-
| `w`
|
|
358
|
-
| `h`
|
|
359
|
-
| `is`
|
|
360
|
-
| `bs`
|
|
508
|
+
| Shorthand | Expands to |
|
|
509
|
+
| --------- | ------------- |
|
|
510
|
+
| `w` | `width` |
|
|
511
|
+
| `h` | `height` |
|
|
512
|
+
| `is` | `inline-size` |
|
|
513
|
+
| `bs` | `block-size` |
|
|
361
514
|
|
|
362
515
|
```jsx
|
|
363
516
|
const Panel = tasty({
|
|
@@ -370,14 +523,14 @@ const Panel = tasty({
|
|
|
370
523
|
});
|
|
371
524
|
```
|
|
372
525
|
|
|
373
|
-
| Tasty syntax
|
|
374
|
-
|
|
375
|
-
| `@(layout, w < 600px)`
|
|
376
|
-
| `@(w < 600px)`
|
|
377
|
-
| `@(layout, $variant=danger)`
|
|
378
|
-
| `@(layout, $compact)`
|
|
379
|
-
| `@(scroll-state(stuck: top))`
|
|
380
|
-
| `@(nav, scroll-state(stuck: top))` | `@container nav scroll-state(stuck: top)`
|
|
526
|
+
| Tasty syntax | CSS output |
|
|
527
|
+
| ---------------------------------- | ---------------------------------------------- |
|
|
528
|
+
| `@(layout, w < 600px)` | `@container layout (width < 600px)` |
|
|
529
|
+
| `@(w < 600px)` | `@container (width < 600px)` |
|
|
530
|
+
| `@(layout, $variant=danger)` | `@container layout style(--variant: "danger")` |
|
|
531
|
+
| `@(layout, $compact)` | `@container layout style(--compact)` |
|
|
532
|
+
| `@(scroll-state(stuck: top))` | `@container scroll-state(stuck: top)` |
|
|
533
|
+
| `@(nav, scroll-state(stuck: top))` | `@container nav scroll-state(stuck: top)` |
|
|
381
534
|
|
|
382
535
|
Container style queries use `$prop` (boolean) or `$prop=value` syntax, which maps to CSS `style(--prop)` or `style(--prop: "value")`.
|
|
383
536
|
|
|
@@ -385,10 +538,10 @@ Container style queries use `$prop` (boolean) or `$prop=value` syntax, which map
|
|
|
385
538
|
|
|
386
539
|
Feature queries test CSS property support. Use `$` as the first argument to test selector support:
|
|
387
540
|
|
|
388
|
-
| Tasty syntax
|
|
389
|
-
|
|
390
|
-
| `@supports(display: grid)`
|
|
391
|
-
| `@supports($, :has(*))`
|
|
541
|
+
| Tasty syntax | CSS output |
|
|
542
|
+
| --------------------------- | --------------------------------- |
|
|
543
|
+
| `@supports(display: grid)` | `@supports (display: grid)` |
|
|
544
|
+
| `@supports($, :has(*))` | `@supports selector(:has(*))` |
|
|
392
545
|
| `!@supports(display: grid)` | `@supports (not (display: grid))` |
|
|
393
546
|
|
|
394
547
|
```jsx
|
|
@@ -407,7 +560,7 @@ that assumption: `@supports(...)` and `@(...)` queries can be **unknown** (not
|
|
|
407
560
|
just true/false), and `not(unknown)` is also unknown — so a negated default
|
|
408
561
|
branch silently never applies. The classic case is `scroll-state`: a browser can
|
|
409
562
|
support `container-type: scroll-state` while a specific `scroll-state(...)` query
|
|
410
|
-
is unknown, leaving
|
|
563
|
+
is unknown, leaving _no_ branch active.
|
|
411
564
|
|
|
412
565
|
The `_` fallback floor solves this. Use `_` as a **standalone key** and its value
|
|
413
566
|
**always applies** as a guaranteed floor: it never receives negation, and
|
|
@@ -422,10 +575,14 @@ inset: {
|
|
|
422
575
|
```
|
|
423
576
|
|
|
424
577
|
```css
|
|
425
|
-
.t0.t0 {
|
|
578
|
+
.t0.t0 {
|
|
579
|
+
inset: 0...;
|
|
580
|
+
}
|
|
426
581
|
@container scroll-state(scrolled: block-end) {
|
|
427
582
|
@supports (container-type: scroll-state) {
|
|
428
|
-
.t0.t0 {
|
|
583
|
+
.t0.t0 {
|
|
584
|
+
inset: -80px...;
|
|
585
|
+
}
|
|
429
586
|
}
|
|
430
587
|
}
|
|
431
588
|
```
|
|
@@ -456,13 +613,13 @@ cause is always the same: **`''` is mutually exclusive (turned off by negation),
|
|
|
456
613
|
while `_` is always on (layered underneath).**
|
|
457
614
|
|
|
458
615
|
- **Unknown / invalid branches.** If a higher-priority branch sits behind a query
|
|
459
|
-
that can be
|
|
616
|
+
that can be _unknown_ (`@supports`, container, `scroll-state`) or uses a
|
|
460
617
|
selector the browser drops, the negated `''` default disappears along with it
|
|
461
618
|
(`not(unknown) = unknown`), leaving the property with no rule. The `_` floor
|
|
462
619
|
survives because it is an unconditional bare rule. This is the case `_` exists
|
|
463
620
|
for.
|
|
464
621
|
|
|
465
|
-
- **Empty / "unset" states.** A state can intentionally produce
|
|
622
|
+
- **Empty / "unset" states.** A state can intentionally produce _no_ output (an
|
|
466
623
|
empty value) to leave a property unset while that state is active. With `''`
|
|
467
624
|
this works — the default is negated away and nothing replaces it, so the
|
|
468
625
|
property unsets. With `_` the floor can never be turned off, so its value keeps
|
|
@@ -474,14 +631,14 @@ while `_` is always on (layered underneath).**
|
|
|
474
631
|
```
|
|
475
632
|
|
|
476
633
|
- **States with different output shapes.** Because `_` layers additively, when
|
|
477
|
-
different states emit
|
|
634
|
+
different states emit _different sets_ of declarations, the floor's
|
|
478
635
|
declarations bleed through wherever the winning state does not override the
|
|
479
636
|
same property — which can produce inconsistent combinations. A `''` default is
|
|
480
637
|
swapped out cleanly by its mutually-exclusive condition.
|
|
481
638
|
|
|
482
639
|
Rule of thumb: **use `''` for the normal default** (clean mutual exclusivity,
|
|
483
640
|
supports unsetting), and reach for `_` only when a value must survive an
|
|
484
|
-
|
|
641
|
+
_unknown_ higher-priority branch.
|
|
485
642
|
|
|
486
643
|
### `@root(...)` — Root Element States
|
|
487
644
|
|
|
@@ -497,13 +654,13 @@ color: {
|
|
|
497
654
|
}
|
|
498
655
|
```
|
|
499
656
|
|
|
500
|
-
| Tasty syntax
|
|
501
|
-
|
|
502
|
-
| `@root(schema=dark)`
|
|
503
|
-
| `@root(hovered)`
|
|
504
|
-
| `@root(.premium-user)` | `:root.premium-user`
|
|
505
|
-
| `@root([lang="en"])`
|
|
506
|
-
| `!@root(schema=dark)`
|
|
657
|
+
| Tasty syntax | CSS selector |
|
|
658
|
+
| ---------------------- | --------------------------------- |
|
|
659
|
+
| `@root(schema=dark)` | `:root[data-schema="dark"]` |
|
|
660
|
+
| `@root(hovered)` | `:root[data-hovered]` |
|
|
661
|
+
| `@root(.premium-user)` | `:root.premium-user` |
|
|
662
|
+
| `@root([lang="en"])` | `:root[lang="en"]` |
|
|
663
|
+
| `!@root(schema=dark)` | `:root:not([data-schema="dark"])` |
|
|
507
664
|
|
|
508
665
|
Root conditions are prepended to the component selector: `:root[data-schema="dark"] .t0.t0 { ... }`.
|
|
509
666
|
|
|
@@ -519,7 +676,7 @@ const Nav = tasty({
|
|
|
519
676
|
'': '#text',
|
|
520
677
|
'@own(:hover)': '#primary',
|
|
521
678
|
'@own(:focus-visible)': '#primary',
|
|
522
|
-
|
|
679
|
+
selected: '#primary', // root-level modifier
|
|
523
680
|
},
|
|
524
681
|
},
|
|
525
682
|
},
|
|
@@ -527,11 +684,11 @@ const Nav = tasty({
|
|
|
527
684
|
});
|
|
528
685
|
```
|
|
529
686
|
|
|
530
|
-
| Tasty syntax (inside sub-element) | CSS output
|
|
531
|
-
|
|
532
|
-
| `@own(:hover)`
|
|
533
|
-
| `@own(hovered)`
|
|
534
|
-
| `@own(theme=dark)`
|
|
687
|
+
| Tasty syntax (inside sub-element) | CSS output |
|
|
688
|
+
| --------------------------------- | ------------------------------------------------- |
|
|
689
|
+
| `@own(:hover)` | `:hover` on the sub-element selector |
|
|
690
|
+
| `@own(hovered)` | `[data-hovered]` on the sub-element selector |
|
|
691
|
+
| `@own(theme=dark)` | `[data-theme="dark"]` on the sub-element selector |
|
|
535
692
|
|
|
536
693
|
`@own()` is only valid inside sub-element styles. Using it on root styles emits a warning and is treated as a regular modifier.
|
|
537
694
|
|
|
@@ -549,9 +706,9 @@ const FadeIn = tasty({
|
|
|
549
706
|
});
|
|
550
707
|
```
|
|
551
708
|
|
|
552
|
-
| Tasty syntax | CSS output
|
|
553
|
-
|
|
554
|
-
| `@starting`
|
|
709
|
+
| Tasty syntax | CSS output |
|
|
710
|
+
| ------------ | ------------------------------------ |
|
|
711
|
+
| `@starting` | `@starting-style { .t0.t0 { ... } }` |
|
|
555
712
|
|
|
556
713
|
### `@parent(...)` — Parent Element States
|
|
557
714
|
|
|
@@ -562,22 +719,22 @@ const Highlight = tasty({
|
|
|
562
719
|
styles: {
|
|
563
720
|
fill: {
|
|
564
721
|
'': '#white',
|
|
565
|
-
'@parent(hovered)': '#gray.05',
|
|
566
|
-
'@parent(theme=dark, >)': '#dark-02',
|
|
722
|
+
'@parent(hovered)': '#gray.05', // Any ancestor has [data-hovered]
|
|
723
|
+
'@parent(theme=dark, >)': '#dark-02', // Direct parent has [data-theme="dark"]
|
|
567
724
|
},
|
|
568
725
|
},
|
|
569
726
|
});
|
|
570
727
|
```
|
|
571
728
|
|
|
572
|
-
| Syntax
|
|
573
|
-
|
|
574
|
-
| `@parent(hovered)`
|
|
575
|
-
| `!@parent(hovered)`
|
|
576
|
-
| `@parent(hovered, >)`
|
|
577
|
-
| `@parent(.active)`
|
|
578
|
-
| `@parent(hovered & focused)`
|
|
729
|
+
| Syntax | CSS Output |
|
|
730
|
+
| ------------------------------------- | -------------------------------------------------------------------- |
|
|
731
|
+
| `@parent(hovered)` | `:is([data-hovered] *)` |
|
|
732
|
+
| `!@parent(hovered)` | `:not([data-hovered] *)` |
|
|
733
|
+
| `@parent(hovered, >)` | `:is([data-hovered] > *)` (direct parent) |
|
|
734
|
+
| `@parent(.active)` | `:is(.active *)` |
|
|
735
|
+
| `@parent(hovered & focused)` | `:is([data-hovered][data-focused] *)` (same ancestor) |
|
|
579
736
|
| `@parent(hovered) & @parent(focused)` | `:is([data-hovered] *):is([data-focused] *)` (independent ancestors) |
|
|
580
|
-
| `@parent(hovered \| focused)`
|
|
737
|
+
| `@parent(hovered \| focused)` | `:is([data-hovered] *, [data-focused] *)` (OR inside single wrapper) |
|
|
581
738
|
|
|
582
739
|
For sub-elements, the parent check applies to the root element's ancestors:
|
|
583
740
|
|
|
@@ -608,38 +765,38 @@ const Card = tasty({
|
|
|
608
765
|
styles: {
|
|
609
766
|
display: {
|
|
610
767
|
'': 'block',
|
|
611
|
-
':has(> Icon)': 'grid',
|
|
612
|
-
':has(+ Icon)': 'grid',
|
|
613
|
-
':has(~ Icon)': 'grid',
|
|
614
|
-
':has(Icon +)': 'grid',
|
|
615
|
-
':has(Icon ~)': 'grid',
|
|
616
|
-
':is(fieldset > label)': 'inline',
|
|
617
|
-
'!:has(> Icon)': 'flex',
|
|
768
|
+
':has(> Icon)': 'grid', // has Icon as direct child
|
|
769
|
+
':has(+ Icon)': 'grid', // immediately followed by an Icon sibling
|
|
770
|
+
':has(~ Icon)': 'grid', // has an Icon sibling somewhere after
|
|
771
|
+
':has(Icon +)': 'grid', // immediately preceded by an Icon sibling (auto-completes to `Icon + *`)
|
|
772
|
+
':has(Icon ~)': 'grid', // has an Icon sibling somewhere before (auto-completes to `Icon ~ *`)
|
|
773
|
+
':is(fieldset > label)': 'inline', // is a label inside a fieldset (HTML tags)
|
|
774
|
+
'!:has(> Icon)': 'flex', // negation: no Icon child
|
|
618
775
|
},
|
|
619
776
|
},
|
|
620
777
|
});
|
|
621
778
|
```
|
|
622
779
|
|
|
623
|
-
| Syntax
|
|
624
|
-
|
|
625
|
-
| `:has(> Icon)`
|
|
626
|
-
| `:has(+ Icon)`
|
|
627
|
-
| `:has(~ Icon)`
|
|
628
|
-
| `:has(Icon +)`
|
|
629
|
-
| `:has(Icon ~)`
|
|
630
|
-
| `:has(>)`
|
|
631
|
-
| `:is(> Field + input)` | `:is(> [data-element="Field"] + input)` | Structural match
|
|
632
|
-
| `:has(button)`
|
|
633
|
-
| `!:has(> Icon)`
|
|
634
|
-
| `!:is(Panel)`
|
|
780
|
+
| Syntax | CSS Output | Meaning |
|
|
781
|
+
| ---------------------- | --------------------------------------- | --------------------------------------- |
|
|
782
|
+
| `:has(> Icon)` | `:has(> [data-element="Icon"])` | Has Icon as direct child |
|
|
783
|
+
| `:has(+ Icon)` | `:has(+ [data-element="Icon"])` | Immediately followed by an Icon sibling |
|
|
784
|
+
| `:has(~ Icon)` | `:has(~ [data-element="Icon"])` | Has an Icon sibling somewhere after |
|
|
785
|
+
| `:has(Icon +)` | `:has([data-element="Icon"] + *)` | Immediately preceded by an Icon sibling |
|
|
786
|
+
| `:has(Icon ~)` | `:has([data-element="Icon"] ~ *)` | Has an Icon sibling somewhere before |
|
|
787
|
+
| `:has(>)` | `:has(> *)` | Has any direct child |
|
|
788
|
+
| `:is(> Field + input)` | `:is(> [data-element="Field"] + input)` | Structural match |
|
|
789
|
+
| `:has(button)` | `:has(button)` | HTML tag (lowercase, unchanged) |
|
|
790
|
+
| `!:has(> Icon)` | `:not(:has(> [data-element="Icon"]))` | Negation (use `!`) |
|
|
791
|
+
| `!:is(Panel)` | `:not([data-element="Panel"])` | Negation (use `!:is`) |
|
|
635
792
|
|
|
636
793
|
Combine with other states using boolean logic (`&`, `|`, `!`, `^`):
|
|
637
794
|
|
|
638
795
|
```jsx
|
|
639
|
-
':has(> Icon) & hovered'
|
|
640
|
-
'@parent(hovered) & :has(> Icon)'
|
|
641
|
-
':has(> Icon) | :has(> Button)'
|
|
642
|
-
':has(> Icon) ^ :has(> Button)'
|
|
796
|
+
':has(> Icon) & hovered'; // AND: structural + data attribute
|
|
797
|
+
'@parent(hovered) & :has(> Icon)'; // AND: parent check + structural
|
|
798
|
+
':has(> Icon) | :has(> Button)'; // OR: either sub-element present
|
|
799
|
+
':has(> Icon) ^ :has(> Button)'; // XOR: exactly one present
|
|
643
800
|
```
|
|
644
801
|
|
|
645
802
|
> **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.
|
|
@@ -675,7 +832,7 @@ const AnimatedGradient = tasty({
|
|
|
675
832
|
styles: {
|
|
676
833
|
'$gradient-angle': '0deg',
|
|
677
834
|
'#theme': 'okhst(280 80% 50%)',
|
|
678
|
-
|
|
835
|
+
image: 'linear-gradient($gradient-angle, #theme, #clear)',
|
|
679
836
|
transition: '$$gradient-angle 0.3s, ##theme 0.3s',
|
|
680
837
|
},
|
|
681
838
|
});
|
|
@@ -683,30 +840,30 @@ const AnimatedGradient = tasty({
|
|
|
683
840
|
|
|
684
841
|
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.
|
|
685
842
|
|
|
686
|
-
Use explicit `@
|
|
843
|
+
Use explicit `@property` when you need non-default settings like `inherits: false`:
|
|
687
844
|
|
|
688
845
|
```jsx
|
|
689
|
-
'@
|
|
846
|
+
'@property': {
|
|
690
847
|
'$gradient-angle': { syntax: '<angle>', inherits: false, initialValue: '0deg' },
|
|
691
848
|
},
|
|
692
849
|
```
|
|
693
850
|
|
|
694
851
|
---
|
|
695
852
|
|
|
696
|
-
## Font Face (`@
|
|
853
|
+
## Font Face (`@font-face`)
|
|
697
854
|
|
|
698
855
|
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).
|
|
699
856
|
|
|
700
857
|
```ts
|
|
701
858
|
const Heading = tasty({
|
|
702
859
|
styles: {
|
|
703
|
-
'@
|
|
860
|
+
'@font-face': {
|
|
704
861
|
'Brand Sans': {
|
|
705
862
|
src: 'url("/fonts/brand-sans.woff2") format("woff2")',
|
|
706
863
|
fontDisplay: 'swap',
|
|
707
864
|
},
|
|
708
865
|
},
|
|
709
|
-
|
|
866
|
+
font: '"Brand Sans", sans-serif',
|
|
710
867
|
},
|
|
711
868
|
});
|
|
712
869
|
```
|
|
@@ -716,7 +873,7 @@ const Heading = tasty({
|
|
|
716
873
|
Supply an array to register several variants of the same family:
|
|
717
874
|
|
|
718
875
|
```ts
|
|
719
|
-
'@
|
|
876
|
+
'@font-face': {
|
|
720
877
|
'Brand Sans': [
|
|
721
878
|
{ src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
|
|
722
879
|
{ src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
|
|
@@ -726,26 +883,26 @@ Supply an array to register several variants of the same family:
|
|
|
726
883
|
|
|
727
884
|
### Supported descriptors
|
|
728
885
|
|
|
729
|
-
| Descriptor
|
|
730
|
-
|
|
731
|
-
| `src` (required)
|
|
732
|
-
| `fontWeight`
|
|
733
|
-
| `fontStyle`
|
|
734
|
-
| `fontStretch`
|
|
735
|
-
| `fontDisplay`
|
|
736
|
-
| `unicodeRange`
|
|
737
|
-
| `ascentOverride`
|
|
738
|
-
| `descentOverride`
|
|
739
|
-
| `lineGapOverride`
|
|
740
|
-
| `sizeAdjust`
|
|
741
|
-
| `fontFeatureSettings`
|
|
742
|
-
| `fontVariationSettings` | `font-variation-settings` | `string`
|
|
886
|
+
| Descriptor | CSS property | Type |
|
|
887
|
+
| ----------------------- | ------------------------- | --------------------------------------------------------- |
|
|
888
|
+
| `src` (required) | `src` | `string` |
|
|
889
|
+
| `fontWeight` | `font-weight` | `string \| number` |
|
|
890
|
+
| `fontStyle` | `font-style` | `string` |
|
|
891
|
+
| `fontStretch` | `font-stretch` | `string` |
|
|
892
|
+
| `fontDisplay` | `font-display` | `'auto' \| 'block' \| 'swap' \| 'fallback' \| 'optional'` |
|
|
893
|
+
| `unicodeRange` | `unicode-range` | `string` |
|
|
894
|
+
| `ascentOverride` | `ascent-override` | `string` |
|
|
895
|
+
| `descentOverride` | `descent-override` | `string` |
|
|
896
|
+
| `lineGapOverride` | `line-gap-override` | `string` |
|
|
897
|
+
| `sizeAdjust` | `size-adjust` | `string` |
|
|
898
|
+
| `fontFeatureSettings` | `font-feature-settings` | `string` |
|
|
899
|
+
| `fontVariationSettings` | `font-variation-settings` | `string` |
|
|
743
900
|
|
|
744
901
|
> Font-face rules are permanent — they are injected once and never cleaned up, matching how browsers handle `@font-face`.
|
|
745
902
|
|
|
746
903
|
---
|
|
747
904
|
|
|
748
|
-
## Counter Style (`@
|
|
905
|
+
## Counter Style (`@counter-style`)
|
|
749
906
|
|
|
750
907
|
Define custom list markers via the CSS `@counter-style` at-rule. Keys are counter-style names, values are descriptor objects.
|
|
751
908
|
|
|
@@ -753,7 +910,7 @@ Define custom list markers via the CSS `@counter-style` at-rule. Keys are counte
|
|
|
753
910
|
const EmojiList = tasty({
|
|
754
911
|
tag: 'ol',
|
|
755
912
|
styles: {
|
|
756
|
-
'@
|
|
913
|
+
'@counter-style': {
|
|
757
914
|
thumbs: {
|
|
758
915
|
system: 'cyclic',
|
|
759
916
|
symbols: '"👍"',
|
|
@@ -767,23 +924,88 @@ const EmojiList = tasty({
|
|
|
767
924
|
|
|
768
925
|
### Supported descriptors
|
|
769
926
|
|
|
770
|
-
| Descriptor
|
|
771
|
-
|
|
772
|
-
| `system` (required) | `system`
|
|
773
|
-
| `symbols`
|
|
774
|
-
| `additiveSymbols`
|
|
775
|
-
| `prefix`
|
|
776
|
-
| `suffix`
|
|
777
|
-
| `negative`
|
|
778
|
-
| `range`
|
|
779
|
-
| `pad`
|
|
780
|
-
| `fallback`
|
|
781
|
-
| `speakAs`
|
|
927
|
+
| Descriptor | CSS property | Type |
|
|
928
|
+
| ------------------- | ------------------ | ---------------------------------------------------------------------------------------- |
|
|
929
|
+
| `system` (required) | `system` | `'cyclic' \| 'numeric' \| 'alphabetic' \| 'symbolic' \| 'additive' \| 'fixed' \| string` |
|
|
930
|
+
| `symbols` | `symbols` | `string` |
|
|
931
|
+
| `additiveSymbols` | `additive-symbols` | `string` |
|
|
932
|
+
| `prefix` | `prefix` | `string` |
|
|
933
|
+
| `suffix` | `suffix` | `string` |
|
|
934
|
+
| `negative` | `negative` | `string` |
|
|
935
|
+
| `range` | `range` | `string` |
|
|
936
|
+
| `pad` | `pad` | `string` |
|
|
937
|
+
| `fallback` | `fallback` | `string` |
|
|
938
|
+
| `speakAs` | `speak-as` | `string` |
|
|
782
939
|
|
|
783
940
|
> Counter-style rules are permanent — they are injected once and never cleaned up, matching how browsers handle `@counter-style`.
|
|
784
941
|
|
|
785
942
|
---
|
|
786
943
|
|
|
944
|
+
## Functions (`@function`)
|
|
945
|
+
|
|
946
|
+
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.
|
|
947
|
+
|
|
948
|
+
The token convention follows Tasty's `$` vs `$$` distinction:
|
|
949
|
+
|
|
950
|
+
- **`$$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.
|
|
951
|
+
- **`$name`** — a custom-property declaration/reference (`var(--name)`). Used for **parameters** and **local variables**, exactly like declaring custom props in a styles object.
|
|
952
|
+
- **Local variables** are declared directly as `$name` keys on the descriptor — the body reads like a mini styles object.
|
|
953
|
+
- `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.
|
|
954
|
+
|
|
955
|
+
```ts
|
|
956
|
+
const Box = tasty({
|
|
957
|
+
styles: {
|
|
958
|
+
'@function': {
|
|
959
|
+
// simplest: one bare param + result (auto-calc, no explicit calc())
|
|
960
|
+
$$negative: { args: ['$value'], result: '(-1 * $value)' },
|
|
961
|
+
|
|
962
|
+
// typed param + default + return type + local variable
|
|
963
|
+
$$shadow: {
|
|
964
|
+
args: { '$shadow-color': { syntax: '<color>', default: 'inherit' } },
|
|
965
|
+
returns: '<color>',
|
|
966
|
+
$offset: '2px', // local variable
|
|
967
|
+
result: '$offset $offset ($shadow-color, black)',
|
|
968
|
+
},
|
|
969
|
+
},
|
|
970
|
+
margin: '$$negative(10px) top', // → margin: --negative(10px) 0 0 0
|
|
971
|
+
shadow: '$$shadow(#accent)', // → box-shadow: --shadow(var(--accent-color))
|
|
972
|
+
},
|
|
973
|
+
});
|
|
974
|
+
```
|
|
975
|
+
|
|
976
|
+
Generated CSS:
|
|
977
|
+
|
|
978
|
+
```css
|
|
979
|
+
@function --negative(--value) {
|
|
980
|
+
result: calc(-1 * var(--value));
|
|
981
|
+
}
|
|
982
|
+
@function --shadow(--shadow-color <color>: inherit) returns <color> {
|
|
983
|
+
--offset: 2px;
|
|
984
|
+
result: var(--offset) var(--offset) var(--shadow-color, black);
|
|
985
|
+
}
|
|
986
|
+
.t0 {
|
|
987
|
+
margin: --negative(10px) 0 0 0;
|
|
988
|
+
box-shadow: --shadow(var(--accent-color));
|
|
989
|
+
}
|
|
990
|
+
```
|
|
991
|
+
|
|
992
|
+
### Descriptor shape
|
|
993
|
+
|
|
994
|
+
| Field | Type | Notes |
|
|
995
|
+
| ------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
996
|
+
| `result` (required) | `string` | The `result:` value, parsed through the Tasty DSL. |
|
|
997
|
+
| `args` | `string[]` \| `Record<string, FunctionParameter>` | Ordered parameters. Array form lists bare names; object form maps names to type/default. |
|
|
998
|
+
| `returns` | `string` | Optional return type, e.g. `'<color>'`. |
|
|
999
|
+
| `$name` keys | `string \| number` | Any `$name` key declares a local variable `--name` (value parsed). |
|
|
1000
|
+
|
|
1001
|
+
A `FunctionParameter` is one of: `true` (bare param), a string CSS type shorthand (`'<length>'`), or `{ syntax?: string; default?: string | number }`.
|
|
1002
|
+
|
|
1003
|
+
Functions can also be registered with the [`useFunction`](react-api.md#usefunction) hook or globally via [`configure({ functions })`](configuration.md#functions) (the same map also accepts bare-key parse functions).
|
|
1004
|
+
|
|
1005
|
+
> `@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.
|
|
1006
|
+
|
|
1007
|
+
---
|
|
1008
|
+
|
|
787
1009
|
## Style Properties
|
|
788
1010
|
|
|
789
1011
|
For a complete reference of all enhanced style properties — syntax, values, modifiers, and recommendations — see **[Style Properties Reference](styles.md)**.
|
|
@@ -796,4 +1018,4 @@ For a complete reference of all enhanced style properties — syntax, values, mo
|
|
|
796
1018
|
- **[Methodology](methodology.md)** — Recommended patterns: root + sub-elements, styleProps, tokens, wrapping
|
|
797
1019
|
- **[Configuration](configuration.md)** — Tokens, recipes, custom units, style handlers, TypeScript extensions
|
|
798
1020
|
- **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
|
|
799
|
-
- **[
|
|
1021
|
+
- **[Build-Time Extraction (`tastyStatic`)](tasty-static.md)** — Static styling with the Babel plugin
|