@tenphi/tasty 0.0.0-snapshot.b49ed29 → 0.0.0-snapshot.b4e384c
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 +403 -380
- package/dist/{babel-types-DpUCD2L_.d.ts → babel-types-Dc5zghyE.d.ts} +2 -2
- package/dist/chunks/{build-config-DQHNt7oV.js → build-config-D9Iq8QQm.js} +5 -5
- package/dist/chunks/{build-config-DQHNt7oV.js.map → build-config-D9Iq8QQm.js.map} +1 -1
- package/dist/chunks/{collector-CLJMa9_d.js → collector-Cb8ah2JF.js} +4 -4
- package/dist/chunks/{collector-CLJMa9_d.js.map → collector-Cb8ah2JF.js.map} +1 -1
- package/dist/chunks/{config-engine-DQTnjS4S.js → config-engine-CMYFZYQh.js} +5 -5
- package/dist/chunks/config-engine-CMYFZYQh.js.map +1 -0
- package/dist/chunks/{css-definitions-gzJPklRN.js → css-definitions-B4aWBkH3.js} +88 -78
- package/dist/chunks/css-definitions-B4aWBkH3.js.map +1 -0
- package/dist/chunks/{debug-XlLKYbjU.js → debug-D2Pu7Xhy.js} +4 -4
- package/dist/chunks/{debug-XlLKYbjU.js.map → debug-D2Pu7Xhy.js.map} +1 -1
- package/dist/chunks/{dsl-DRhFWQzo.js → dsl-CsFl9LGn.js} +132 -52
- package/dist/chunks/dsl-CsFl9LGn.js.map +1 -0
- package/dist/chunks/{react-runtime-CxMPs43X.js → react-runtime-DHiopXCu.js} +8 -6
- package/dist/chunks/react-runtime-DHiopXCu.js.map +1 -0
- package/dist/chunks/{runtime-engine-8qIHnb-B.js → runtime-engine-NGCofNXy.js} +11 -7
- package/dist/chunks/runtime-engine-NGCofNXy.js.map +1 -0
- package/dist/chunks/{runtime-state-BaSL1KZU.js → runtime-state-lZjMbvwV.js} +14 -3
- package/dist/chunks/runtime-state-lZjMbvwV.js.map +1 -0
- package/dist/chunks/{style-engine-DgP6pNeS.js → style-engine-DnkV_4Jg.js} +256 -95
- package/dist/chunks/style-engine-DnkV_4Jg.js.map +1 -0
- package/dist/chunks/{zero-engine-DvCd7ZUf.js → zero-engine-DcwaCvFs.js} +6 -6
- package/dist/chunks/zero-engine-DcwaCvFs.js.map +1 -0
- package/dist/{collector-D4POJ53X.d.ts → collector-D2OT6I2G.d.ts} +2 -2
- package/dist/{config-DvPUj4cw.d.ts → config-C4ftFxgI.d.ts} +13 -10
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +7 -7
- package/dist/{index-DC4q-xDq.d.ts → index-DxQNRj50.d.ts} +34 -16
- package/dist/index.d.ts +5 -5
- package/dist/index.js +8 -8
- package/dist/{merge-styles-Jb5iZ-Jf.d.ts → merge-styles-D39qBtox.d.ts} +2 -2
- package/dist/ssr/astro.js +2 -2
- package/dist/ssr/index.d.ts +1 -1
- package/dist/ssr/index.js +2 -2
- package/dist/ssr/next-config.d.ts +1 -1
- package/dist/ssr/next-config.js +3 -3
- package/dist/ssr/next.d.ts +1 -1
- package/dist/ssr/next.js +3 -3
- package/dist/static/index.d.ts +2 -2
- package/dist/{types-ZbF2_6LV.d.ts → types-CYQIhUg1.d.ts} +9 -7
- package/dist/zero/babel.d.ts +9 -3
- package/dist/zero/babel.js +8 -8
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +25 -6
- package/dist/zero/index.js +5 -4
- package/dist/zero/index.js.map +1 -1
- package/dist/zero/next.d.ts +1 -1
- package/docs/README.md +4 -1
- package/docs/adoption.md +25 -17
- package/docs/ai-agents.md +43 -34
- package/docs/comparison.md +9 -8
- package/docs/configuration.md +186 -68
- package/docs/debug.md +3 -2
- package/docs/design-system.md +117 -15
- package/docs/dsl.md +258 -116
- package/docs/getting-started.md +81 -24
- package/docs/injector.md +41 -40
- package/docs/methodology.md +46 -21
- package/docs/migration-v3.md +3 -3
- package/docs/pipeline.md +19 -16
- package/docs/plugins.md +21 -41
- package/docs/react-api.md +70 -14
- package/docs/runtime-benchmarks.md +4 -4
- package/docs/ssr.md +92 -66
- package/docs/styles.md +82 -16
- package/docs/tasty-static.md +143 -58
- package/package.json +32 -33
- package/dist/chunks/config-engine-DQTnjS4S.js.map +0 -1
- package/dist/chunks/css-definitions-gzJPklRN.js.map +0 -1
- package/dist/chunks/dsl-DRhFWQzo.js.map +0 -1
- package/dist/chunks/react-runtime-CxMPs43X.js.map +0 -1
- package/dist/chunks/runtime-engine-8qIHnb-B.js.map +0 -1
- package/dist/chunks/runtime-state-BaSL1KZU.js.map +0 -1
- package/dist/chunks/style-engine-DgP6pNeS.js.map +0 -1
- package/dist/chunks/zero-engine-DvCd7ZUf.js.map +0 -1
package/docs/dsl.md
CHANGED
|
@@ -6,6 +6,8 @@ The same value syntax, state maps, tokens, units, extension semantics, and speci
|
|
|
6
6
|
|
|
7
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
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).
|
|
10
|
+
|
|
9
11
|
---
|
|
10
12
|
|
|
11
13
|
## Dictionary
|
|
@@ -18,6 +20,15 @@ Object where keys represent states and values are the styles to apply:
|
|
|
18
20
|
fill: { '': '#white', hovered: '#gray.05', 'theme=danger': '#red' }
|
|
19
21
|
```
|
|
20
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
|
+
|
|
21
32
|
#### State Key Types
|
|
22
33
|
|
|
23
34
|
| Syntax | Example | Generated CSS |
|
|
@@ -34,17 +45,20 @@ fill: { '': '#white', hovered: '#gray.05', 'theme=danger': '#red' }
|
|
|
34
45
|
|
|
35
46
|
#### Automatic Native States
|
|
36
47
|
|
|
37
|
-
`disabled` and `
|
|
48
|
+
`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:
|
|
38
49
|
|
|
39
|
-
| Concise Tasty state | Explicit attribute selector |
|
|
40
|
-
| ------------------- | --------------------------- |
|
|
41
|
-
| `disabled` | `[disabled]` |
|
|
42
|
-
| `checked` | `[checked]` |
|
|
50
|
+
| Concise Tasty state | Compiles to | Explicit attribute selector |
|
|
51
|
+
| ------------------- | ----------------- | --------------------------- |
|
|
52
|
+
| `disabled` | `[data-disabled]` | `[disabled]` |
|
|
53
|
+
| `checked` | `[data-checked]` | `[checked]` |
|
|
54
|
+
| `hidden` | `[data-hidden]` | `[hidden]` |
|
|
43
55
|
|
|
44
56
|
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.
|
|
45
57
|
|
|
46
58
|
Operator precedence (highest to lowest): `!` (NOT) > `^` (XOR) > `|` (OR) > `&` (AND). Use parentheses to override: `hovered & (pressed ^ focused)`.
|
|
47
59
|
|
|
60
|
+
A top-level comma is the same as `|`: `'hovered, focused'` is `'hovered | focused'`.
|
|
61
|
+
|
|
48
62
|
`^` (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:
|
|
49
63
|
|
|
50
64
|
```jsx
|
|
@@ -76,9 +90,7 @@ Element styled using a capitalized key. Identified by `data-element` attribute:
|
|
|
76
90
|
|
|
77
91
|
```jsx
|
|
78
92
|
styles: {
|
|
79
|
-
Title: {
|
|
80
|
-
preset: 'h3';
|
|
81
|
-
}
|
|
93
|
+
Title: { preset: 'h3' },
|
|
82
94
|
}
|
|
83
95
|
// Targets: <div data-element="Title">
|
|
84
96
|
```
|
|
@@ -117,20 +129,22 @@ The `@` placeholder marks exactly where `[data-element="..."]` is injected, allo
|
|
|
117
129
|
const List = tasty({
|
|
118
130
|
styles: {
|
|
119
131
|
Item: {
|
|
120
|
-
$: '
|
|
121
|
-
|
|
132
|
+
$: '>@::after',
|
|
133
|
+
content: '""',
|
|
122
134
|
},
|
|
123
135
|
},
|
|
124
136
|
});
|
|
125
|
-
// → .
|
|
137
|
+
// → .t1x29r0l.t1x29r0l > [data-element="Item"]::after { content: ""; }
|
|
126
138
|
```
|
|
127
139
|
|
|
140
|
+
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'`.
|
|
141
|
+
|
|
128
142
|
### Color Token
|
|
129
143
|
|
|
130
144
|
Named color prefixed with `#` that maps to CSS custom properties. Supports opacity with `.N` suffix:
|
|
131
145
|
|
|
132
146
|
```jsx
|
|
133
|
-
fill: '#purple.5'; // →
|
|
147
|
+
fill: '#purple.5'; // → color-mix(in oklab, var(--purple-color) 50%, transparent)
|
|
134
148
|
```
|
|
135
149
|
|
|
136
150
|
### Modifier
|
|
@@ -154,19 +168,23 @@ color: '#purple.5', // 50% opacity
|
|
|
154
168
|
color: '#purple.05', // 5% opacity
|
|
155
169
|
color: '#purple.$fade', // Opacity from a custom property
|
|
156
170
|
fill: '#current', // → currentcolor
|
|
171
|
+
fill: '#surface+#dark.04', // #dark at 4% opacity over #surface, as one color
|
|
157
172
|
color: '(#primary, #secondary)', // Fallback syntax
|
|
158
173
|
```
|
|
159
174
|
|
|
160
|
-
|
|
175
|
+
`#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.
|
|
176
|
+
|
|
177
|
+
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.
|
|
178
|
+
|
|
179
|
+
The suffix fades the token's color by mixing it with `transparent`:
|
|
161
180
|
|
|
162
181
|
```jsx
|
|
163
182
|
fill: '#purple.5';
|
|
164
|
-
// →
|
|
183
|
+
// → color-mix(in oklab, var(--purple-color) 50%, transparent)
|
|
165
184
|
```
|
|
166
185
|
|
|
167
|
-
The
|
|
168
|
-
|
|
169
|
-
these:
|
|
186
|
+
The mix asks nothing of the color beyond _being_ a color. That means the suffix
|
|
187
|
+
works on every one of these:
|
|
170
188
|
|
|
171
189
|
- a token holding a `color-mix()`, a `light-dark()`, or a `color()` in a space
|
|
172
190
|
Tasty cannot convert — none of which have channels to decompose
|
|
@@ -174,13 +192,29 @@ these:
|
|
|
174
192
|
- a `--name-color` variable declared in your own CSS, with no Tasty token
|
|
175
193
|
definition behind it
|
|
176
194
|
|
|
177
|
-
|
|
195
|
+
`color-mix()` is Baseline widely available (Chrome 111, Firefox 113, Safari
|
|
196
|
+
16.2). Two properties follow from mixing rather than writing an alpha channel:
|
|
197
|
+
|
|
198
|
+
- **Alpha composes.** The mix is premultiplied, so a color that is already
|
|
199
|
+
translucent is faded further: a token holding `rgb(255 0 0 / .8)` faded to
|
|
200
|
+
`.5` is alpha `.4`. An opaque token — the usual case — ends at exactly the
|
|
201
|
+
suffix. System colors are whatever the platform draws, and some are
|
|
202
|
+
translucent: Chrome and Safari on macOS give `Highlight` an alpha of `.6`, so
|
|
203
|
+
a token holding it faded to `.5` ends at `.3` there.
|
|
204
|
+
- **A `$prop` alpha must be a number.** `#purple.$fade` emits
|
|
205
|
+
`calc(var(--fade) * 100%)`, because a mix percentage cannot be a `<number>`,
|
|
206
|
+
so `$fade` has to hold `.5`, not `50%`.
|
|
207
|
+
|
|
208
|
+
### `#clear` is transparent
|
|
209
|
+
|
|
210
|
+
`#clear` is a built-in [replace token](#replace-tokens) for `transparent`.
|
|
211
|
+
Opacity suffixes are ignored: `#clear.5` and `#clear.$fade` both emit
|
|
212
|
+
`transparent`. The same rule applies to user-defined replace tokens resolving
|
|
213
|
+
to `transparent`, including aliases of `#clear`.
|
|
178
214
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
`/ var(--fade)` unchanged, so it works whether `$fade` holds `.5` or `50%` —
|
|
183
|
-
which is what `--*-opacity` properties are registered to accept.
|
|
215
|
+
It does not read `--clear-color` or require an `@property` registration.
|
|
216
|
+
An explicit `configure({ replaceTokens: { '#clear': ... } })` overrides the
|
|
217
|
+
default alias and uses the replacement's usual opacity behavior.
|
|
184
218
|
|
|
185
219
|
### `#current` is the keyword
|
|
186
220
|
|
|
@@ -203,42 +237,75 @@ A color that already reads the color it inherits — `#current`, a `#current` fa
|
|
|
203
237
|
— is not published into it: resolving such a value a second time at a descendant
|
|
204
238
|
would fade it twice.
|
|
205
239
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
240
|
+
### `#current` fades compose
|
|
241
|
+
|
|
242
|
+
`currentcolor` is the color an element **inherits**, which an ancestor may
|
|
243
|
+
already have faded, so `#current.4` means "40% of what reaches me":
|
|
209
244
|
|
|
210
245
|
```jsx
|
|
211
|
-
|
|
212
|
-
//
|
|
213
|
-
// fill: oklch(from currentcolor l c h / .5) → Chrome, Firefox, Safari 18+
|
|
246
|
+
fill: '#current.4';
|
|
247
|
+
// → color-mix(in oklab, currentcolor 40%, transparent)
|
|
214
248
|
```
|
|
215
249
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
`#current`
|
|
250
|
+
A `#current` fade nested inside another one composes: a label at `#current.4`
|
|
251
|
+
with a fill of `#current.18` under it lands at `.072`. Color ramps built on
|
|
252
|
+
`#current` depend on that.
|
|
253
|
+
|
|
254
|
+
Fades always mix `in oklab`: it is unbounded, so a wide-gamut color is not
|
|
255
|
+
clamped, and rectangular, so there is no hue to interpolate against
|
|
256
|
+
`transparent`. Nothing configures it — see
|
|
257
|
+
[Color space](configuration.md#color-space).
|
|
219
258
|
|
|
220
|
-
###
|
|
259
|
+
### Compound colors
|
|
221
260
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
**inherits**, which an ancestor may already have faded — `#current.4` means "40%
|
|
225
|
-
of what reaches me":
|
|
261
|
+
Join color tokens with `+` to paint each one, at its own opacity, over the
|
|
262
|
+
colors before it. The result is one color, so it works anywhere a token does:
|
|
226
263
|
|
|
227
264
|
```jsx
|
|
228
|
-
fill: '#
|
|
229
|
-
// → color-mix(in
|
|
230
|
-
```
|
|
265
|
+
fill: '#surface+#dark.04',
|
|
266
|
+
// → color-mix(in srgb, var(--dark-color) 4%, var(--surface-color))
|
|
231
267
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
custom property used as `#current.$fade` must hold a unitless number; a token
|
|
237
|
-
accepts either form.
|
|
268
|
+
border: '1bw #border+#dark.1',
|
|
269
|
+
color: 'light-dark(#primary+#black.2, #primary+#white.2)',
|
|
270
|
+
'#hover-surface': '#surface-2+#surface-text.03',
|
|
271
|
+
```
|
|
238
272
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
273
|
+
Read it left to right, bottom layer first: `#surface+#accent.1+#dark.04` paints
|
|
274
|
+
`#accent` at 10% over `#surface`, then `#dark` at 4% over that. Every operand is
|
|
275
|
+
an ordinary token — `#current`, `#clear`, a hex color, a replace token — and
|
|
276
|
+
takes its opacity suffix as it does anywhere: `#surface+#dark.$hover` reads the
|
|
277
|
+
opacity from `$hover`, and a faded base such as `#surface.5+#dark.04` is layered
|
|
278
|
+
as it is.
|
|
279
|
+
|
|
280
|
+
The layers mix in sRGB, the space browsers composite in, so the color is exactly
|
|
281
|
+
what stacking them as layers would show — but it is one color, which contrast
|
|
282
|
+
checkers can read and transitions interpolate. A faded base is exact too:
|
|
283
|
+
`#surface.5+#dark.04` is as translucent as the two layers would be.
|
|
284
|
+
|
|
285
|
+
Every layer's token has to be opaque. The mix counts a layer's own alpha as well
|
|
286
|
+
as its opacity suffix, and lowers the alpha of the whole color, so a layer token
|
|
287
|
+
that holds a translucent color, or turns transparent in some state, leaves the
|
|
288
|
+
result see-through: with `'#overlay': { '': '#clear', hovered: '#dark' }`,
|
|
289
|
+
`'#surface+#overlay.04'` is 96% opaque at rest. Vary the opacity instead
|
|
290
|
+
(`'#surface+#dark.$hover'`), or give each state its own color
|
|
291
|
+
(`fill: { '': '#surface', hovered: '#surface+#dark.04' }`).
|
|
292
|
+
|
|
293
|
+
- Write it as one word: `#surface + #dark.04` is three separate values, and
|
|
294
|
+
Tasty warns in development.
|
|
295
|
+
- A layer without an opacity covers everything before it: `#surface+#dark` is
|
|
296
|
+
`#dark`, with a development warning.
|
|
297
|
+
- A layer Tasty can see is transparent — `#clear`, a fade to `.0`, a color with
|
|
298
|
+
a zero alpha — is left out: `#surface+#clear` is `#surface`.
|
|
299
|
+
- Over a transparent base, a layer is just its fade: `#clear+#dark.04` compiles
|
|
300
|
+
to `#dark.04`.
|
|
301
|
+
- A `+` joining anything but color tokens (`#surface+1x`) is not a compound: the
|
|
302
|
+
token is dropped, with a development warning, and the style renders as if
|
|
303
|
+
that color were not there.
|
|
304
|
+
|
|
305
|
+
A `+` joins tokens only. To fade a whole compound, give it a token
|
|
306
|
+
(`'#hover-surface': '#surface+#dark.04'`) and fade that (`#hover-surface.5`). For
|
|
307
|
+
a mix that is not a layer over another color, such as an even blend in OKLCH,
|
|
308
|
+
write `color-mix()` itself.
|
|
242
309
|
|
|
243
310
|
---
|
|
244
311
|
|
|
@@ -256,6 +323,9 @@ border: '1bw solid oklch(from #primary l c h / 50%)', // relative color syntax
|
|
|
256
323
|
shadow: '0 0 1x color-mix(in oklab, #dark 20%, transparent)',
|
|
257
324
|
```
|
|
258
325
|
|
|
326
|
+
Tasty also ships `okhsl()` and `okhst()`, which compile to `rgb()` at parse
|
|
327
|
+
time: `fill: 'okhsl(280 80% 50%)'` → `rgb(40% 38.5% 88.2%)`.
|
|
328
|
+
|
|
259
329
|
`light-dark()` is the one exception to "always a color": CSS lets it pick between
|
|
260
330
|
values of any type, so it is treated as a color only when its arguments are
|
|
261
331
|
colors. `padding: 'light-dark(1x, 2x)'` still reaches the padding slot.
|
|
@@ -286,23 +356,52 @@ configure({
|
|
|
286
356
|
});
|
|
287
357
|
|
|
288
358
|
fill: '#solid.5'; // → hsl(220 90% 50% / .5)
|
|
289
|
-
fill: '#adaptive.5'; // →
|
|
359
|
+
fill: '#adaptive.5'; // → color-mix(in oklab, light-dark(…) 50%, transparent)
|
|
290
360
|
```
|
|
291
361
|
|
|
362
|
+
### Color keywords
|
|
363
|
+
|
|
364
|
+
CSS named colors (`rebeccapurple`) and system colors (`Canvas`, `CanvasText`,
|
|
365
|
+
`Highlight`, `ButtonText`, `GrayText`, `LinkText`, …) are colors too: they land
|
|
366
|
+
in the color slot of any style and can be a color token's value. System colors
|
|
367
|
+
are what `forced-colors` styles are written in:
|
|
368
|
+
|
|
369
|
+
```jsx
|
|
370
|
+
const Checkbox = tasty({
|
|
371
|
+
styles: {
|
|
372
|
+
'#forced-border': 'CanvasText',
|
|
373
|
+
border: {
|
|
374
|
+
'': '1bw #border',
|
|
375
|
+
'@media(forced-colors: active)': '1bw #forced-border',
|
|
376
|
+
},
|
|
377
|
+
outline: { '': false, focused: '2px Highlight' },
|
|
378
|
+
},
|
|
379
|
+
});
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
A custom property whose fallback is a single color is read as a color, so it
|
|
383
|
+
also fills the color slot: `border: '1bw var(--accent, Highlight)'`, as does
|
|
384
|
+
`($accent, Highlight)`. Keywords are case-insensitive: a color token keeps the
|
|
385
|
+
case it was written in, and a property value such as `border` or `fill` emits
|
|
386
|
+
them lowercase.
|
|
387
|
+
|
|
388
|
+
The deprecated system colors (`Menu`, `Window`, `ButtonHighlight`, …) are not
|
|
389
|
+
recognized.
|
|
390
|
+
|
|
292
391
|
---
|
|
293
392
|
|
|
294
393
|
## Built-in Units
|
|
295
394
|
|
|
296
|
-
| Unit | Description | Example | CSS
|
|
297
|
-
| ---- | ------------------ | ------- |
|
|
298
|
-
| `x` |
|
|
299
|
-
| `r` | Border radius | `1r` | `
|
|
300
|
-
| `cr` | Card border radius | `1cr` | `
|
|
301
|
-
| `bw` | Border width | `2bw` | `
|
|
302
|
-
| `ow` | Outline width | `1ow` | `
|
|
303
|
-
| `sf` | Stable fraction | `1sf` | `minmax(0, 1fr)`
|
|
395
|
+
| Unit | Description | Default | Example | CSS output |
|
|
396
|
+
| ---- | ------------------ | ---------------- | ------- | ---------------- |
|
|
397
|
+
| `x` | Spacing step | `8px` | `2x` | `16px` |
|
|
398
|
+
| `r` | Border radius | `6px` | `1r` | `6px` |
|
|
399
|
+
| `cr` | Card border radius | `10px` | `1cr` | `10px` |
|
|
400
|
+
| `bw` | Border width | `1px` | `2bw` | `2px` |
|
|
401
|
+
| `ow` | Outline width | `3px` | `1ow` | `3px` |
|
|
402
|
+
| `sf` | Stable fraction | `minmax(0, Nfr)` | `1sf` | `minmax(0, 1fr)` |
|
|
304
403
|
|
|
305
|
-
|
|
404
|
+
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).
|
|
306
405
|
|
|
307
406
|
---
|
|
308
407
|
|
|
@@ -359,7 +458,7 @@ const CardWithPanel = tasty({
|
|
|
359
458
|
});
|
|
360
459
|
```
|
|
361
460
|
|
|
362
|
-
At each level, base recipes are collected in
|
|
461
|
+
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).
|
|
363
462
|
|
|
364
463
|
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.
|
|
365
464
|
|
|
@@ -439,12 +538,14 @@ fill: {
|
|
|
439
538
|
Use `null` inside a state map to remove a state, or `false` to block it entirely (tombstone):
|
|
440
539
|
|
|
441
540
|
```jsx
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
}
|
|
541
|
+
const MyButton = tasty(Button, {
|
|
542
|
+
styles: {
|
|
543
|
+
fill: {
|
|
544
|
+
hovered: null, // removes the parent's hovered state
|
|
545
|
+
disabled: false, // tombstone — no CSS for disabled, blocks recipe too
|
|
546
|
+
},
|
|
547
|
+
},
|
|
548
|
+
});
|
|
448
549
|
```
|
|
449
550
|
|
|
450
551
|
### Resetting Properties with `null` and `false`
|
|
@@ -494,7 +595,7 @@ const SimpleButton = tasty(Button, {
|
|
|
494
595
|
|
|
495
596
|
### `@media(...)` — Media Queries
|
|
496
597
|
|
|
497
|
-
Media queries support dimension shorthands
|
|
598
|
+
Media queries support dimension shorthands:
|
|
498
599
|
|
|
499
600
|
| Shorthand | Expands to |
|
|
500
601
|
| --------- | ---------- |
|
|
@@ -516,13 +617,18 @@ fill: {
|
|
|
516
617
|
| `@media(600px <= w < 1200px)` | `@media (600px <= width < 1200px)` |
|
|
517
618
|
| `@media:print` | `@media print` |
|
|
518
619
|
| `@media:screen` | `@media screen` |
|
|
620
|
+
| `@media:all` | `@media all` |
|
|
621
|
+
| `@media:speech` | `@media speech` |
|
|
519
622
|
| `@media(prefers-color-scheme: dark)` | `@media (prefers-color-scheme: dark)` |
|
|
520
623
|
| `@media(prefers-reduced-motion)` | `@media (prefers-reduced-motion)` |
|
|
624
|
+
| `@media(aspect-ratio > 16/9)` | `@media (aspect-ratio > 16/9)` |
|
|
521
625
|
|
|
522
|
-
|
|
626
|
+
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`.
|
|
523
627
|
|
|
524
628
|
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`.
|
|
525
629
|
|
|
630
|
+
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.
|
|
631
|
+
|
|
526
632
|
In practice, define state aliases via `configure({ states })` and use `@mobile` instead of writing the full query in every component.
|
|
527
633
|
|
|
528
634
|
### `@(...)` — Container Queries
|
|
@@ -547,28 +653,30 @@ const Panel = tasty({
|
|
|
547
653
|
});
|
|
548
654
|
```
|
|
549
655
|
|
|
550
|
-
| Tasty syntax | CSS output
|
|
551
|
-
| ---------------------------------- |
|
|
552
|
-
| `@(layout, w < 600px)` | `@container layout (width < 600px)`
|
|
553
|
-
| `@(w < 600px)` | `@container (width < 600px)`
|
|
554
|
-
| `@(layout, $variant=danger)` | `@container layout style(--variant:
|
|
555
|
-
| `@(layout, $compact)` | `@container layout style(--compact)`
|
|
556
|
-
| `@(scroll-state(stuck: top))` | `@container scroll-state(stuck: top)`
|
|
557
|
-
| `@(nav, scroll-state(stuck: top))` | `@container nav scroll-state(stuck: top)`
|
|
656
|
+
| Tasty syntax | CSS output |
|
|
657
|
+
| ---------------------------------- | -------------------------------------------- |
|
|
658
|
+
| `@(layout, w < 600px)` | `@container layout (width < 600px)` |
|
|
659
|
+
| `@(w < 600px)` | `@container (width < 600px)` |
|
|
660
|
+
| `@(layout, $variant=danger)` | `@container layout style(--variant: danger)` |
|
|
661
|
+
| `@(layout, $compact)` | `@container layout style(--compact)` |
|
|
662
|
+
| `@(scroll-state(stuck: top))` | `@container scroll-state(stuck: top)` |
|
|
663
|
+
| `@(nav, scroll-state(stuck: top))` | `@container nav scroll-state(stuck: top)` |
|
|
664
|
+
|
|
665
|
+
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"`.
|
|
558
666
|
|
|
559
|
-
|
|
667
|
+
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.
|
|
560
668
|
|
|
561
669
|
### `@supports(...)` — Feature Queries
|
|
562
670
|
|
|
563
671
|
Feature queries test CSS property support and accept CSS support functions such
|
|
564
672
|
as `at-rule()`. Use `$` as the first argument to test selector support:
|
|
565
673
|
|
|
566
|
-
| Tasty syntax
|
|
567
|
-
|
|
|
568
|
-
| `@supports(display: grid)`
|
|
569
|
-
| `@supports($, :has(*))` | `@supports selector(:has(*))`
|
|
570
|
-
| `@supports(at-rule(@scope))` | `@supports (at-rule(@scope))`
|
|
571
|
-
| `!@supports(display: grid)`
|
|
674
|
+
| Tasty syntax | CSS output |
|
|
675
|
+
| ----------------------------- | ----------------------------------- |
|
|
676
|
+
| `@supports(display: grid)` | `@supports (display: grid)` |
|
|
677
|
+
| `@supports($, :has(*))` | `@supports selector(:has(*))` |
|
|
678
|
+
| `@supports(at-rule(@scope))` | `@supports (at-rule(@scope))` |
|
|
679
|
+
| `!@supports(display: grid)` | `@supports (not (display: grid))` |
|
|
572
680
|
| `!@supports(at-rule(@scope))` | `@supports (not (at-rule(@scope)))` |
|
|
573
681
|
|
|
574
682
|
```jsx
|
|
@@ -622,12 +730,12 @@ inset: {
|
|
|
622
730
|
|
|
623
731
|
```css
|
|
624
732
|
.t0.t0 {
|
|
625
|
-
inset: 0
|
|
733
|
+
inset: 0 auto auto auto;
|
|
626
734
|
}
|
|
627
|
-
@container scroll-state
|
|
628
|
-
@
|
|
735
|
+
@supports (container-type: scroll-state) {
|
|
736
|
+
@container scroll-state(scrolled: block-end) {
|
|
629
737
|
.t0.t0 {
|
|
630
|
-
inset: -
|
|
738
|
+
inset: -640px auto auto auto;
|
|
631
739
|
}
|
|
632
740
|
}
|
|
633
741
|
}
|
|
@@ -636,7 +744,7 @@ inset: {
|
|
|
636
744
|
The floor is emitted as a bare rule (no negated `@supports` / container branches),
|
|
637
745
|
so it always applies. When the override matches it wins because it is emitted
|
|
638
746
|
later and all state selectors share the same specificity (see the note on
|
|
639
|
-
`:where()`
|
|
747
|
+
`:where()` above).
|
|
640
748
|
|
|
641
749
|
Notes:
|
|
642
750
|
|
|
@@ -708,7 +816,7 @@ color: {
|
|
|
708
816
|
| `@root([lang="en"])` | `:root[lang="en"]` |
|
|
709
817
|
| `!@root(schema=dark)` | `:root:not([data-schema="dark"])` |
|
|
710
818
|
|
|
711
|
-
Root conditions are prepended to the component selector
|
|
819
|
+
Root conditions are prepended to the component selector inside `:where()`: `:where(:root[data-schema="dark"]) .t0.t0 { ... }`.
|
|
712
820
|
|
|
713
821
|
### `@own(...)` — Sub-element's Own State
|
|
714
822
|
|
|
@@ -738,6 +846,20 @@ const Nav = tasty({
|
|
|
738
846
|
|
|
739
847
|
`@own()` is only valid inside sub-element styles. Using it on root styles emits a warning and is treated as a regular modifier.
|
|
740
848
|
|
|
849
|
+
When `$` ends in a pseudo-element, `@own()` is the pseudo-element's own state and goes after it:
|
|
850
|
+
|
|
851
|
+
```jsx
|
|
852
|
+
Label: {
|
|
853
|
+
$: '@::part(label)',
|
|
854
|
+
color: { '': '#text', '@own(:focus)': '#primary' },
|
|
855
|
+
},
|
|
856
|
+
// → .t0.t0 [data-element="Label"]::part(label):where(:focus) { … }
|
|
857
|
+
```
|
|
858
|
+
|
|
859
|
+
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.
|
|
860
|
+
|
|
861
|
+
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.
|
|
862
|
+
|
|
741
863
|
### `@starting` — Entry Animation
|
|
742
864
|
|
|
743
865
|
Wraps the rule in `@starting-style`, enabling CSS entry animations for elements as they appear in the DOM:
|
|
@@ -754,11 +876,11 @@ const FadeIn = tasty({
|
|
|
754
876
|
|
|
755
877
|
| Tasty syntax | CSS output |
|
|
756
878
|
| ------------ | ------------------------------------ |
|
|
757
|
-
| `@starting` |
|
|
879
|
+
| `@starting` | `.t0.t0 { @starting-style { ... } }` |
|
|
758
880
|
|
|
759
881
|
### `@parent(...)` — Parent Element States
|
|
760
882
|
|
|
761
|
-
Style based on ancestor element attributes. Uses `:
|
|
883
|
+
Style based on ancestor element attributes. Uses `:where([selector] *)` / `:where(:not([selector] *))` for symmetric, composable parent checks. Boolean logic (`&`, `|`, `!`, `^`) is supported inside `@parent()`.
|
|
762
884
|
|
|
763
885
|
```jsx
|
|
764
886
|
const Highlight = tasty({
|
|
@@ -772,15 +894,15 @@ const Highlight = tasty({
|
|
|
772
894
|
});
|
|
773
895
|
```
|
|
774
896
|
|
|
775
|
-
| Syntax | CSS Output
|
|
776
|
-
| ------------------------------------- |
|
|
777
|
-
| `@parent(hovered)` | `:
|
|
778
|
-
| `!@parent(hovered)` | `:not([data-hovered] *)`
|
|
779
|
-
| `@parent(hovered, >)` | `:
|
|
780
|
-
| `@parent(.active)` | `:
|
|
781
|
-
| `@parent(hovered & focused)` | `:
|
|
782
|
-
| `@parent(hovered) & @parent(focused)` | `:
|
|
783
|
-
| `@parent(hovered \| focused)` | `:
|
|
897
|
+
| Syntax | CSS Output |
|
|
898
|
+
| ------------------------------------- | -------------------------------------------------------------------------- |
|
|
899
|
+
| `@parent(hovered)` | `:where([data-hovered] *)` |
|
|
900
|
+
| `!@parent(hovered)` | `:where(:not([data-hovered] *))` |
|
|
901
|
+
| `@parent(hovered, >)` | `:where([data-hovered] > *)` (direct parent) |
|
|
902
|
+
| `@parent(.active)` | `:where(.active *)` |
|
|
903
|
+
| `@parent(hovered & focused)` | `:where([data-hovered][data-focused] *)` (same ancestor) |
|
|
904
|
+
| `@parent(hovered) & @parent(focused)` | `:where([data-hovered] *):where([data-focused] *)` (independent ancestors) |
|
|
905
|
+
| `@parent(hovered \| focused)` | `:where([data-hovered] *, [data-focused] *)` (OR inside single wrapper) |
|
|
784
906
|
|
|
785
907
|
For sub-elements, the parent check applies to the root element's ancestors:
|
|
786
908
|
|
|
@@ -795,12 +917,12 @@ const Card = tasty({
|
|
|
795
917
|
},
|
|
796
918
|
},
|
|
797
919
|
});
|
|
798
|
-
// → .t0.t0:
|
|
920
|
+
// → .t0.t0:where([data-hovered] *) [data-element="Label"]
|
|
799
921
|
```
|
|
800
922
|
|
|
801
923
|
### `:is()`, `:has()` — CSS Structural Pseudo-classes
|
|
802
924
|
|
|
803
|
-
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 `*`.
|
|
925
|
+
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()`.
|
|
804
926
|
|
|
805
927
|
`:where()` and `:not()` are also supported but rarely needed — use `:is()` and `!` negation instead.
|
|
806
928
|
|
|
@@ -823,18 +945,18 @@ const Card = tasty({
|
|
|
823
945
|
});
|
|
824
946
|
```
|
|
825
947
|
|
|
826
|
-
| Syntax
|
|
827
|
-
|
|
|
828
|
-
| `:has(> Icon)`
|
|
829
|
-
| `:has(+ Icon)`
|
|
830
|
-
| `:has(~ Icon)`
|
|
831
|
-
| `:has(Icon +)`
|
|
832
|
-
| `:has(Icon ~)`
|
|
833
|
-
| `:has(>)`
|
|
834
|
-
| `:is(
|
|
835
|
-
| `:has(button)`
|
|
836
|
-
| `!:has(> Icon)`
|
|
837
|
-
| `!:is(Panel)`
|
|
948
|
+
| Syntax | CSS Output | Meaning |
|
|
949
|
+
| -------------------- | ------------------------------------- | --------------------------------------- |
|
|
950
|
+
| `:has(> Icon)` | `:has(> [data-element="Icon"])` | Has Icon as direct child |
|
|
951
|
+
| `:has(+ Icon)` | `:has(+ [data-element="Icon"])` | Immediately followed by an Icon sibling |
|
|
952
|
+
| `:has(~ Icon)` | `:has(~ [data-element="Icon"])` | Has an Icon sibling somewhere after |
|
|
953
|
+
| `:has(Icon +)` | `:has([data-element="Icon"] + *)` | Immediately preceded by an Icon sibling |
|
|
954
|
+
| `:has(Icon ~)` | `:has([data-element="Icon"] ~ *)` | Has an Icon sibling somewhere before |
|
|
955
|
+
| `:has(>)` | `:has(> *)` | Has any direct child |
|
|
956
|
+
| `:is(Field + input)` | `:is([data-element="Field"] + input)` | Is an input right after a Field sibling |
|
|
957
|
+
| `:has(button)` | `:has(button)` | HTML tag (lowercase, unchanged) |
|
|
958
|
+
| `!:has(> Icon)` | `:not(:has(> [data-element="Icon"]))` | Negation (use `!`) |
|
|
959
|
+
| `!:is(Panel)` | `:not([data-element="Panel"])` | Negation (use `!:is`) |
|
|
838
960
|
|
|
839
961
|
Combine with other states using boolean logic (`&`, `|`, `!`, `^`):
|
|
840
962
|
|
|
@@ -896,6 +1018,26 @@ Use explicit `@property` when you need non-default settings like `inherits: fals
|
|
|
896
1018
|
},
|
|
897
1019
|
```
|
|
898
1020
|
|
|
1021
|
+
### Default properties
|
|
1022
|
+
|
|
1023
|
+
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.
|
|
1024
|
+
|
|
1025
|
+
| Token | Initial value | Read by |
|
|
1026
|
+
| ---------------------------------------------------- | ---------------------------------------- | -------------------------------------------------------------- |
|
|
1027
|
+
| `#current` | `currentcolor` | anything reading `$current-color`, which `color` sets |
|
|
1028
|
+
| `#white`, `#black` | `rgb(255 255 255)`, `rgb(0 0 0)` | your styles |
|
|
1029
|
+
| `#border` | `currentcolor` | `border` with no color |
|
|
1030
|
+
| `#outline` | `currentcolor` | `outline` with no color |
|
|
1031
|
+
| `$gap`, `$radius`, `$border-width`, `$outline-width` | `8px`, `6px`, `1px`, `3px` | units you point at them, as in `units: { x: 'var(--gap)' }` |
|
|
1032
|
+
| `$transition` | `80ms` | `transition` with no duration |
|
|
1033
|
+
| `$sharp-radius` | `0px` | the sharp corners of `radius: 'leaf'` and `radius: 'backleaf'` |
|
|
1034
|
+
| `$bold-font-weight` | `700` | `preset: 'name / strong'` |
|
|
1035
|
+
| `$font-sans-fallback`, `$font-mono-fallback` | a `system-ui` and a `ui-monospace` stack | `font` and presets, after `$font-sans` / `$font-mono` |
|
|
1036
|
+
|
|
1037
|
+
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.
|
|
1038
|
+
|
|
1039
|
+
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 })`.
|
|
1040
|
+
|
|
899
1041
|
---
|
|
900
1042
|
|
|
901
1043
|
## Font Face (`@font-face`)
|
|
@@ -956,7 +1098,7 @@ Define custom list markers via the CSS `@counter-style` at-rule. Keys are counte
|
|
|
956
1098
|
|
|
957
1099
|
```ts
|
|
958
1100
|
const EmojiList = tasty({
|
|
959
|
-
|
|
1101
|
+
as: 'ol',
|
|
960
1102
|
styles: {
|
|
961
1103
|
'@counter-style': {
|
|
962
1104
|
thumbs: {
|
|
@@ -1048,7 +1190,7 @@ Generated CSS:
|
|
|
1048
1190
|
|
|
1049
1191
|
A `FunctionParameter` is one of: `true` (bare param), a string CSS type shorthand (`'<length>'`), or `{ syntax?: string; default?: string | number }`.
|
|
1050
1192
|
|
|
1051
|
-
Functions can also be registered with the [`useFunction`](react-api.md#usefunction)
|
|
1193
|
+
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).
|
|
1052
1194
|
|
|
1053
1195
|
> `@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.
|
|
1054
1196
|
|