@tenphi/tasty 0.0.0-snapshot.2f41cf6 → 0.0.0-snapshot.2f4e31d
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 +440 -372
- package/dist/babel-types-Dc5zghyE.d.ts +18 -0
- package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
- package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
- package/dist/chunks/build-config-D9Iq8QQm.js +60 -0
- package/dist/chunks/build-config-D9Iq8QQm.js.map +1 -0
- package/dist/{collector-BMEQCkCn.js → chunks/collector-Cb8ah2JF.js} +68 -101
- package/dist/chunks/collector-Cb8ah2JF.js.map +1 -0
- package/dist/chunks/config-engine-CMYFZYQh.js +272 -0
- package/dist/chunks/config-engine-CMYFZYQh.js.map +1 -0
- package/dist/chunks/config-file-DlZXJMj8.js +25 -0
- package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
- package/dist/chunks/css-definitions-B4aWBkH3.js +910 -0
- package/dist/chunks/css-definitions-B4aWBkH3.js.map +1 -0
- package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
- package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
- package/dist/chunks/debug-D2Pu7Xhy.js +502 -0
- package/dist/chunks/debug-D2Pu7Xhy.js.map +1 -0
- package/dist/chunks/dsl-CsFl9LGn.js +1458 -0
- package/dist/chunks/dsl-CsFl9LGn.js.map +1 -0
- package/dist/chunks/hydration-TRcz5vnk.js +41 -0
- package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
- package/dist/chunks/react-runtime-DHiopXCu.js +691 -0
- package/dist/chunks/react-runtime-DHiopXCu.js.map +1 -0
- package/dist/chunks/runtime-engine-NGCofNXy.js +2435 -0
- package/dist/chunks/runtime-engine-NGCofNXy.js.map +1 -0
- package/dist/chunks/runtime-state-lZjMbvwV.js +152 -0
- package/dist/chunks/runtime-state-lZjMbvwV.js.map +1 -0
- package/dist/{merge-styles-3il_ClCF.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
- package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
- package/dist/chunks/style-engine-DnkV_4Jg.js +5602 -0
- package/dist/chunks/style-engine-DnkV_4Jg.js.map +1 -0
- package/dist/{css-writer-BSv8PrEX.js → chunks/zero-engine-DcwaCvFs.js} +95 -136
- package/dist/chunks/zero-engine-DcwaCvFs.js.map +1 -0
- package/dist/{collector-osfWTeRd.d.ts → collector-D2OT6I2G.d.ts} +64 -8
- package/dist/{config-BoZDUHW5.d.ts → config-C4ftFxgI.d.ts} +514 -92
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/hydrate-CRyjjAyl.d.ts +22 -0
- package/dist/{index-D-OA_O6i.d.ts → index-DxQNRj50.d.ts} +718 -502
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -732
- package/dist/{merge-styles-BMWcH6MF.d.ts → merge-styles-D39qBtox.d.ts} +2 -3
- package/dist/ssr/astro-client.d.ts +1 -1
- package/dist/ssr/astro-client.js +1 -14
- package/dist/ssr/astro-client.js.map +1 -1
- package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract-static.js +9 -0
- package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
- package/dist/ssr/astro-middleware-extract.d.ts +10 -0
- package/dist/ssr/astro-middleware-extract.js +9 -0
- package/dist/ssr/astro-middleware-extract.js.map +1 -0
- package/dist/ssr/astro-middleware-static.d.ts +17 -0
- package/dist/ssr/astro-middleware-static.js +7 -0
- package/dist/ssr/astro-middleware-static.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +11 -8
- package/dist/ssr/astro-middleware.js +2 -14
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +40 -10
- package/dist/ssr/astro.js +163 -91
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +2 -0
- package/dist/ssr/index.d.ts +5 -32
- package/dist/ssr/index.js +6 -6
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +64 -0
- package/dist/ssr/next-config.js +123 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -9
- package/dist/ssr/next.js +29 -44
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +8 -9
- package/dist/static/index.js +4 -22
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.d.ts +1 -2
- package/dist/static/inject.js.map +1 -1
- package/dist/{index-tcHuMPFt.d.ts → types-CYQIhUg1.d.ts} +883 -600
- package/dist/zero/babel.d.ts +12 -20
- package/dist/zero/babel.js +97 -156
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +76 -7
- package/dist/zero/index.js +25 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +4 -5
- package/dist/zero/next.js +3 -38
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +20 -9
- package/docs/adoption.md +69 -36
- package/docs/ai-agents.md +259 -0
- package/docs/comparison.md +77 -47
- package/docs/configuration.md +617 -98
- package/docs/debug.md +28 -15
- package/docs/design-system.md +154 -33
- package/docs/dsl.md +715 -194
- package/docs/getting-started.md +130 -50
- package/docs/injector.md +160 -69
- package/docs/methodology.md +82 -51
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +102 -33
- package/docs/plugins.md +333 -0
- package/docs/react-api.md +215 -50
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +310 -118
- package/docs/styles.md +225 -42
- package/docs/tasty-static.md +289 -136
- package/package.json +141 -45
- package/tasty.config.ts +6 -0
- package/dist/async-storage-B7_o6FKt.js +0 -44
- package/dist/async-storage-B7_o6FKt.js.map +0 -1
- package/dist/collector-BMEQCkCn.js.map +0 -1
- package/dist/config-eiremPHv.js +0 -10559
- package/dist/config-eiremPHv.js.map +0 -1
- package/dist/context-CkSg-kDT.js +0 -24
- package/dist/context-CkSg-kDT.js.map +0 -1
- package/dist/core-Dm9EkOA_.js +0 -1598
- package/dist/core-Dm9EkOA_.js.map +0 -1
- package/dist/css-writer-BSv8PrEX.js.map +0 -1
- package/dist/format-global-rules-Dbc_1tc3.js +0 -22
- package/dist/format-global-rules-Dbc_1tc3.js.map +0 -1
- package/dist/format-rules-DcFFQceU.js +0 -143
- package/dist/format-rules-DcFFQceU.js.map +0 -1
- package/dist/hydrate-B6SjFHhj.js +0 -45
- package/dist/hydrate-B6SjFHhj.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-DJ8Geo4L.js +0 -595
- package/dist/keyframes-DJ8Geo4L.js.map +0 -1
- package/dist/merge-styles-3il_ClCF.js.map +0 -1
- package/dist/resolve-recipes-B3MSkfFQ.js +0 -144
- package/dist/resolve-recipes-B3MSkfFQ.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
|
|
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).
|
|
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,45 @@ 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
|
+
|
|
19
32
|
#### State Key Types
|
|
20
33
|
|
|
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)
|
|
34
|
+
| Syntax | Example | Generated CSS |
|
|
35
|
+
| ------------------ | ------------------------ | ------------------------------------------------------------------------ |
|
|
36
|
+
| Boolean modifier | `hovered` | `[data-hovered]` |
|
|
37
|
+
| Value modifier | `theme=danger` | `[data-theme="danger"]` |
|
|
38
|
+
| Pseudo-class | `:hover` | `:hover` |
|
|
39
|
+
| Class selector | `.active` | `.active` |
|
|
40
|
+
| Attribute selector | `[aria-expanded="true"]` | `[aria-expanded="true"]` |
|
|
41
|
+
| Combined (AND) | `hovered & .active` | `[data-hovered].active` |
|
|
42
|
+
| Combined (OR) | `hovered \| focused` | `[data-hovered], [data-focused]` |
|
|
43
|
+
| Negated (NOT) | `!disabled` | `:not([data-disabled])` |
|
|
44
|
+
| Exclusive (XOR) | `hovered ^ focused` | `[data-hovered]:not([data-focused]), :not([data-hovered])[data-focused]` |
|
|
45
|
+
|
|
46
|
+
#### Automatic Native States
|
|
47
|
+
|
|
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:
|
|
49
|
+
|
|
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]` |
|
|
55
|
+
|
|
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.
|
|
32
57
|
|
|
33
58
|
Operator precedence (highest to lowest): `!` (NOT) > `^` (XOR) > `|` (OR) > `&` (AND). Use parentheses to override: `hovered & (pressed ^ focused)`.
|
|
34
59
|
|
|
60
|
+
A top-level comma is the same as `|`: `'hovered, focused'` is `'hovered | focused'`.
|
|
61
|
+
|
|
35
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:
|
|
36
63
|
|
|
37
64
|
```jsx
|
|
@@ -41,12 +68,30 @@ fill: {
|
|
|
41
68
|
}
|
|
42
69
|
```
|
|
43
70
|
|
|
71
|
+
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.
|
|
72
|
+
|
|
73
|
+
#### Default State Ordering
|
|
74
|
+
|
|
75
|
+
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.
|
|
76
|
+
|
|
77
|
+
```jsx
|
|
78
|
+
// Correct — default first
|
|
79
|
+
color: { '': '#text', hovered: '#accent' }
|
|
80
|
+
|
|
81
|
+
// Auto-corrected with a warning — '' moved to the front
|
|
82
|
+
color: { hovered: '#accent', '': '#text' }
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
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.
|
|
86
|
+
|
|
44
87
|
### Sub-element
|
|
45
88
|
|
|
46
89
|
Element styled using a capitalized key. Identified by `data-element` attribute:
|
|
47
90
|
|
|
48
91
|
```jsx
|
|
49
|
-
styles: {
|
|
92
|
+
styles: {
|
|
93
|
+
Title: { preset: 'h3' },
|
|
94
|
+
}
|
|
50
95
|
// Targets: <div data-element="Title">
|
|
51
96
|
```
|
|
52
97
|
|
|
@@ -56,19 +101,19 @@ Control how a sub-element selector attaches to the root selector using the `$` p
|
|
|
56
101
|
|
|
57
102
|
Examples below assume the sub-element key is **Cell** (i.e. `[data-element="Cell"]` in CSS):
|
|
58
103
|
|
|
59
|
-
| Pattern
|
|
60
|
-
|
|
61
|
-
|
|
|
62
|
-
| `>`
|
|
63
|
-
| `>Body>`
|
|
64
|
-
| `> Cell`
|
|
65
|
-
| `h1`
|
|
66
|
-
| `h1 >`
|
|
67
|
-
| `h1 *`
|
|
68
|
-
| `*`
|
|
69
|
-
| `&::before` | `::before`
|
|
70
|
-
| `@::before` | `[data-element="Cell"]::before`
|
|
71
|
-
| `>@.active` | `> [data-element="Cell"].active`
|
|
104
|
+
| Pattern | Result | Description |
|
|
105
|
+
| ----------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
106
|
+
| _(none)_ | `[data-element="Cell"]` | Descendant (default) |
|
|
107
|
+
| `>` | `> [data-element="Cell"]` | Direct child |
|
|
108
|
+
| `>Body>` | `> [data-element="Body"] > [data-element="Cell"]` | Chained elements |
|
|
109
|
+
| `> 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 |
|
|
110
|
+
| `h1` | `h1` | Tag selector (no key injection) |
|
|
111
|
+
| `h1 >` | `h1 > [data-element="Cell"]` | Key is direct child of tag |
|
|
112
|
+
| `h1 *` | `h1 *` | Any descendant of tag |
|
|
113
|
+
| `*` | `*` | All descendants |
|
|
114
|
+
| `&::before` | `::before` | Root pseudo (no key); `&` is required |
|
|
115
|
+
| `@::before` | `[data-element="Cell"]::before` | Pseudo on the sub-element |
|
|
116
|
+
| `>@.active` | `> [data-element="Cell"].active` | Class on the sub-element |
|
|
72
117
|
|
|
73
118
|
Rules for key injection (`[data-element="..."]`):
|
|
74
119
|
|
|
@@ -84,20 +129,22 @@ The `@` placeholder marks exactly where `[data-element="..."]` is injected, allo
|
|
|
84
129
|
const List = tasty({
|
|
85
130
|
styles: {
|
|
86
131
|
Item: {
|
|
87
|
-
$: '
|
|
88
|
-
|
|
132
|
+
$: '>@::after',
|
|
133
|
+
content: '""',
|
|
89
134
|
},
|
|
90
135
|
},
|
|
91
136
|
});
|
|
92
|
-
// → .
|
|
137
|
+
// → .t1x29r0l.t1x29r0l > [data-element="Item"]::after { content: ""; }
|
|
93
138
|
```
|
|
94
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
|
+
|
|
95
142
|
### Color Token
|
|
96
143
|
|
|
97
144
|
Named color prefixed with `#` that maps to CSS custom properties. Supports opacity with `.N` suffix:
|
|
98
145
|
|
|
99
146
|
```jsx
|
|
100
|
-
fill: '#purple.5'
|
|
147
|
+
fill: '#purple.5'; // → color-mix(in oklab, var(--purple-color) 50%, transparent)
|
|
101
148
|
```
|
|
102
149
|
|
|
103
150
|
### Modifier
|
|
@@ -109,7 +156,7 @@ mods={{ hovered: true, theme: 'danger' }}
|
|
|
109
156
|
// → data-hovered="" data-theme="danger"
|
|
110
157
|
```
|
|
111
158
|
|
|
112
|
-
Modifiers can also be exposed as top-level component props via `modProps` — see [
|
|
159
|
+
Modifiers can also be exposed as top-level component props via `modProps` — see [React API — Mod Props](react-api.md#mod-props).
|
|
113
160
|
|
|
114
161
|
---
|
|
115
162
|
|
|
@@ -119,25 +166,242 @@ Modifiers can also be exposed as top-level component props via `modProps` — se
|
|
|
119
166
|
color: '#purple', // Full opacity
|
|
120
167
|
color: '#purple.5', // 50% opacity
|
|
121
168
|
color: '#purple.05', // 5% opacity
|
|
169
|
+
color: '#purple.$fade', // Opacity from a custom property
|
|
122
170
|
fill: '#current', // → currentcolor
|
|
123
|
-
fill: '#
|
|
171
|
+
fill: '#surface+#dark.04', // #dark at 4% opacity over #surface, as one color
|
|
124
172
|
color: '(#primary, #secondary)', // Fallback syntax
|
|
125
173
|
```
|
|
126
174
|
|
|
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`:
|
|
180
|
+
|
|
181
|
+
```jsx
|
|
182
|
+
fill: '#purple.5';
|
|
183
|
+
// → color-mix(in oklab, var(--purple-color) 50%, transparent)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
The mix asks nothing of the color beyond _being_ a color. That means the suffix
|
|
187
|
+
works on every one of these:
|
|
188
|
+
|
|
189
|
+
- a token holding a `color-mix()`, a `light-dark()`, or a `color()` in a space
|
|
190
|
+
Tasty cannot convert — none of which have channels to decompose
|
|
191
|
+
- `#current`, which resolves to the color the element inherits
|
|
192
|
+
- a `--name-color` variable declared in your own CSS, with no Tasty token
|
|
193
|
+
definition behind it
|
|
194
|
+
|
|
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`.
|
|
214
|
+
|
|
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.
|
|
218
|
+
|
|
219
|
+
### `#current` is the keyword
|
|
220
|
+
|
|
221
|
+
`#current` emits the `currentcolor` keyword, so it resolves against the element
|
|
222
|
+
that reads it. That is what lets it follow a color an ancestor faded — a ramp
|
|
223
|
+
that expresses its disabled state once, in `color`, fades everything painted from
|
|
224
|
+
`#current` below it with no further declarations.
|
|
225
|
+
|
|
226
|
+
The `color` style also publishes `--current-color` beside every color it sets,
|
|
227
|
+
for anything that needs the inherited color _as a color_ rather than as the
|
|
228
|
+
keyword — hand-authored CSS, or a place the keyword will not do. Read it as
|
|
229
|
+
`$current-color`. It is registered with `initial-value: currentcolor`, so where
|
|
230
|
+
nothing published it, it still resolves against each element's own color:
|
|
231
|
+
|
|
232
|
+
```jsx
|
|
233
|
+
fill: '$current-color'; // → var(--current-color)
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
A color that already reads the color it inherits — `#current`, a `#current` fade
|
|
237
|
+
— is not published into it: resolving such a value a second time at a descendant
|
|
238
|
+
would fade it twice.
|
|
239
|
+
|
|
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":
|
|
244
|
+
|
|
245
|
+
```jsx
|
|
246
|
+
fill: '#current.4';
|
|
247
|
+
// → color-mix(in oklab, currentcolor 40%, transparent)
|
|
248
|
+
```
|
|
249
|
+
|
|
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).
|
|
258
|
+
|
|
259
|
+
### Compound colors
|
|
260
|
+
|
|
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:
|
|
263
|
+
|
|
264
|
+
```jsx
|
|
265
|
+
fill: '#surface+#dark.04',
|
|
266
|
+
// → color-mix(in srgb, var(--dark-color) 4%, var(--surface-color))
|
|
267
|
+
|
|
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
|
+
```
|
|
272
|
+
|
|
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.
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## CSS Color Functions
|
|
313
|
+
|
|
314
|
+
Every CSS color function is recognized as a color, so it lands in the color slot
|
|
315
|
+
of whichever style property you use it in — and tokens inside it are expanded:
|
|
316
|
+
|
|
317
|
+
```jsx
|
|
318
|
+
fill: 'color-mix(in oklab, #primary 50%, #surface)',
|
|
319
|
+
color: 'light-dark(#dark, #light)',
|
|
320
|
+
color: 'contrast-color(#primary)',
|
|
321
|
+
fill: 'color(display-p3 1 .5 0)',
|
|
322
|
+
border: '1bw solid oklch(from #primary l c h / 50%)', // relative color syntax
|
|
323
|
+
shadow: '0 0 1x color-mix(in oklab, #dark 20%, transparent)',
|
|
324
|
+
```
|
|
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
|
+
|
|
329
|
+
`light-dark()` is the one exception to "always a color": CSS lets it pick between
|
|
330
|
+
values of any type, so it is treated as a color only when its arguments are
|
|
331
|
+
colors. `padding: 'light-dark(1x, 2x)'` still reaches the padding slot.
|
|
332
|
+
|
|
333
|
+
A color token defined as one of these functions takes the
|
|
334
|
+
[opacity suffix](#color-tokens--opacity) like any other:
|
|
335
|
+
|
|
336
|
+
```jsx
|
|
337
|
+
const Card = tasty({
|
|
338
|
+
styles: {
|
|
339
|
+
'#brand': 'color-mix(in oklab, #primary 50%, #surface)',
|
|
340
|
+
fill: '#brand.5',
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
A [replace token](configuration.md#replace-tokens-parse-time-substitution) is
|
|
346
|
+
substituted while parsing, so its color is right there to fade in place. A
|
|
347
|
+
channel function takes the alpha after a slash; a derived function has no alpha
|
|
348
|
+
channel, so it gets wrapped:
|
|
349
|
+
|
|
350
|
+
```jsx
|
|
351
|
+
configure({
|
|
352
|
+
replaceTokens: {
|
|
353
|
+
'#solid': 'hsl(220 90% 50%)',
|
|
354
|
+
'#adaptive': 'light-dark(#dark, #light)',
|
|
355
|
+
},
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
fill: '#solid.5'; // → hsl(220 90% 50% / .5)
|
|
359
|
+
fill: '#adaptive.5'; // → color-mix(in oklab, light-dark(…) 50%, transparent)
|
|
360
|
+
```
|
|
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
|
+
|
|
127
391
|
---
|
|
128
392
|
|
|
129
393
|
## Built-in Units
|
|
130
394
|
|
|
131
|
-
| Unit | Description | Example | CSS
|
|
132
|
-
|
|
133
|
-
| `x`
|
|
134
|
-
| `r`
|
|
135
|
-
| `cr` | Card border radius | `1cr`
|
|
136
|
-
| `bw` | Border width | `2bw`
|
|
137
|
-
| `ow` | Outline width | `1ow`
|
|
138
|
-
| `sf` | Stable fraction | `1sf`
|
|
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)` |
|
|
139
403
|
|
|
140
|
-
|
|
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).
|
|
141
405
|
|
|
142
406
|
---
|
|
143
407
|
|
|
@@ -178,9 +442,29 @@ const ElevatedCard = tasty({
|
|
|
178
442
|
});
|
|
179
443
|
```
|
|
180
444
|
|
|
445
|
+
**Where recipes resolve:**
|
|
446
|
+
|
|
447
|
+
The `recipe` property is resolved on the component root and independently inside each sub-element's styles:
|
|
448
|
+
|
|
449
|
+
```jsx
|
|
450
|
+
const CardWithPanel = tasty({
|
|
451
|
+
styles: {
|
|
452
|
+
recipe: 'card',
|
|
453
|
+
Panel: {
|
|
454
|
+
recipe: 'card elevated',
|
|
455
|
+
padding: '2x', // Overrides the panel's base recipe padding
|
|
456
|
+
},
|
|
457
|
+
},
|
|
458
|
+
});
|
|
459
|
+
```
|
|
460
|
+
|
|
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).
|
|
462
|
+
|
|
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.
|
|
464
|
+
|
|
181
465
|
**Post-merge recipes (`/` separator):**
|
|
182
466
|
|
|
183
|
-
Recipes listed after `/` are applied
|
|
467
|
+
Recipes listed after `/` are applied _after_ component styles using `mergeStyles`:
|
|
184
468
|
|
|
185
469
|
```jsx
|
|
186
470
|
const Input = tasty({
|
|
@@ -218,8 +502,8 @@ When a style property uses a state map, the merge behavior depends on whether th
|
|
|
218
502
|
const MyButton = tasty(Button, {
|
|
219
503
|
styles: {
|
|
220
504
|
fill: {
|
|
221
|
-
|
|
222
|
-
|
|
505
|
+
loading: '#yellow', // append new state
|
|
506
|
+
disabled: '#gray.20', // override existing state in place
|
|
223
507
|
},
|
|
224
508
|
},
|
|
225
509
|
});
|
|
@@ -229,7 +513,7 @@ const MyButton = tasty(Button, {
|
|
|
229
513
|
styles: {
|
|
230
514
|
fill: {
|
|
231
515
|
'': '#red',
|
|
232
|
-
|
|
516
|
+
hovered: '#blue',
|
|
233
517
|
},
|
|
234
518
|
},
|
|
235
519
|
});
|
|
@@ -254,8 +538,14 @@ fill: {
|
|
|
254
538
|
Use `null` inside a state map to remove a state, or `false` to block it entirely (tombstone):
|
|
255
539
|
|
|
256
540
|
```jsx
|
|
257
|
-
|
|
258
|
-
|
|
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
|
+
});
|
|
259
549
|
```
|
|
260
550
|
|
|
261
551
|
### Resetting Properties with `null` and `false`
|
|
@@ -263,44 +553,54 @@ fill: { disabled: false } // tombstone — no CSS for disabled, blocks recipe to
|
|
|
263
553
|
```jsx
|
|
264
554
|
const SimpleButton = tasty(Button, {
|
|
265
555
|
styles: {
|
|
266
|
-
fill: null,
|
|
556
|
+
fill: null, // discard parent's fill, let recipe fill in
|
|
267
557
|
border: false, // no border at all (tombstone — blocks recipe too)
|
|
268
558
|
},
|
|
269
559
|
});
|
|
270
560
|
```
|
|
271
561
|
|
|
272
|
-
| Value
|
|
273
|
-
|
|
274
|
-
| `undefined` | Not provided — parent preserved
|
|
275
|
-
| `null`
|
|
276
|
-
| `false`
|
|
562
|
+
| Value | Meaning | Recipe fills in? |
|
|
563
|
+
| ----------- | ------------------------------------ | ---------------- |
|
|
564
|
+
| `undefined` | Not provided — parent preserved | N/A |
|
|
565
|
+
| `null` | Intentional unset — parent discarded | Yes |
|
|
566
|
+
| `false` | Tombstone — blocks everything | No |
|
|
277
567
|
|
|
278
568
|
---
|
|
279
569
|
|
|
280
570
|
## Advanced States (`@` prefix)
|
|
281
571
|
|
|
282
|
-
| Prefix
|
|
283
|
-
|
|
284
|
-
| `@media`
|
|
285
|
-
| `@(...)`
|
|
286
|
-
| `@supports` | Feature/selector support
|
|
287
|
-
| `@root`
|
|
288
|
-
| `@parent`
|
|
289
|
-
| `@own`
|
|
290
|
-
| `@starting` | Entry animation
|
|
291
|
-
|
|
|
292
|
-
| `:
|
|
293
|
-
| `:
|
|
294
|
-
| `:
|
|
572
|
+
| Prefix | Purpose | Example |
|
|
573
|
+
| ----------- | ----------------------------------------- | -------------------------- |
|
|
574
|
+
| `@media` | Media queries | `@media(w < 768px)` |
|
|
575
|
+
| `@(...)` | Container queries | `@(panel, w >= 300px)` |
|
|
576
|
+
| `@supports` | Feature/selector support | `@supports(display: grid)` |
|
|
577
|
+
| `@root` | Root element states | `@root(schema=dark)` |
|
|
578
|
+
| `@parent` | Parent/ancestor element states | `@parent(hovered)` |
|
|
579
|
+
| `@own` | Sub-element's own state | `@own(hovered)` |
|
|
580
|
+
| `@starting` | Entry animation | `@starting` |
|
|
581
|
+
| `_` | Fallback floor (always-on, never negated) | `_` |
|
|
582
|
+
| `:is()` | CSS `:is()` structural pseudo-class | `:is(fieldset > label)` |
|
|
583
|
+
| `:has()` | CSS `:has()` relational pseudo-class | `:has(> Icon)` |
|
|
584
|
+
| `:not()` | CSS `:not()` negation (prefer `!:is()`) | `:not(:first-child)` |
|
|
585
|
+
| `:where()` | CSS `:where()` (zero specificity) | `:where(Section)` |
|
|
586
|
+
|
|
587
|
+
> **Specificity.** All state selectors Tasty generates (modifiers, pseudo-classes,
|
|
588
|
+
> `:is()`/`:not()` groups, and `@root` / `@parent` context) are wrapped in
|
|
589
|
+
> `:where(...)` so they carry **zero specificity**. The only specificity anchors
|
|
590
|
+
> are the doubled component class (`.t0.t0`) and sub-element `[data-element]`
|
|
591
|
+
> attributes. This means overlapping rules (e.g. a `_` fallback floor and the
|
|
592
|
+
> states layered over it) resolve purely by **source order** — Tasty emits
|
|
593
|
+
> lower-priority states first and higher-priority states last so the cascade
|
|
594
|
+
> produces the intended winner.
|
|
295
595
|
|
|
296
596
|
### `@media(...)` — Media Queries
|
|
297
597
|
|
|
298
|
-
Media queries support dimension shorthands
|
|
598
|
+
Media queries support dimension shorthands:
|
|
299
599
|
|
|
300
600
|
| Shorthand | Expands to |
|
|
301
|
-
|
|
302
|
-
| `w`
|
|
303
|
-
| `h`
|
|
601
|
+
| --------- | ---------- |
|
|
602
|
+
| `w` | `width` |
|
|
603
|
+
| `h` | `height` |
|
|
304
604
|
|
|
305
605
|
```jsx
|
|
306
606
|
fill: {
|
|
@@ -311,16 +611,23 @@ fill: {
|
|
|
311
611
|
}
|
|
312
612
|
```
|
|
313
613
|
|
|
314
|
-
| Tasty syntax
|
|
315
|
-
|
|
316
|
-
| `@media(w < 768px)`
|
|
317
|
-
| `@media(600px <= w < 1200px)`
|
|
318
|
-
| `@media:print`
|
|
319
|
-
| `@media:screen`
|
|
614
|
+
| Tasty syntax | CSS output |
|
|
615
|
+
| ------------------------------------ | ------------------------------------- |
|
|
616
|
+
| `@media(w < 768px)` | `@media (width < 768px)` |
|
|
617
|
+
| `@media(600px <= w < 1200px)` | `@media (600px <= width < 1200px)` |
|
|
618
|
+
| `@media:print` | `@media print` |
|
|
619
|
+
| `@media:screen` | `@media screen` |
|
|
620
|
+
| `@media:all` | `@media all` |
|
|
621
|
+
| `@media:speech` | `@media speech` |
|
|
320
622
|
| `@media(prefers-color-scheme: dark)` | `@media (prefers-color-scheme: dark)` |
|
|
321
|
-
| `@media(prefers-reduced-motion)`
|
|
623
|
+
| `@media(prefers-reduced-motion)` | `@media (prefers-reduced-motion)` |
|
|
624
|
+
| `@media(aspect-ratio > 16/9)` | `@media (aspect-ratio > 16/9)` |
|
|
625
|
+
|
|
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`.
|
|
627
|
+
|
|
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`.
|
|
322
629
|
|
|
323
|
-
|
|
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.
|
|
324
631
|
|
|
325
632
|
In practice, define state aliases via `configure({ states })` and use `@mobile` instead of writing the full query in every component.
|
|
326
633
|
|
|
@@ -328,12 +635,12 @@ In practice, define state aliases via `configure({ states })` and use `@mobile`
|
|
|
328
635
|
|
|
329
636
|
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`.
|
|
330
637
|
|
|
331
|
-
| Shorthand | Expands to
|
|
332
|
-
|
|
333
|
-
| `w`
|
|
334
|
-
| `h`
|
|
335
|
-
| `is`
|
|
336
|
-
| `bs`
|
|
638
|
+
| Shorthand | Expands to |
|
|
639
|
+
| --------- | ------------- |
|
|
640
|
+
| `w` | `width` |
|
|
641
|
+
| `h` | `height` |
|
|
642
|
+
| `is` | `inline-size` |
|
|
643
|
+
| `bs` | `block-size` |
|
|
337
644
|
|
|
338
645
|
```jsx
|
|
339
646
|
const Panel = tasty({
|
|
@@ -346,26 +653,31 @@ const Panel = tasty({
|
|
|
346
653
|
});
|
|
347
654
|
```
|
|
348
655
|
|
|
349
|
-
| Tasty syntax
|
|
350
|
-
|
|
351
|
-
| `@(layout, w < 600px)`
|
|
352
|
-
| `@(w < 600px)`
|
|
353
|
-
| `@(layout, $variant=danger)`
|
|
354
|
-
| `@(layout, $compact)`
|
|
355
|
-
| `@(scroll-state(stuck: top))`
|
|
356
|
-
| `@(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"`.
|
|
357
666
|
|
|
358
|
-
|
|
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.
|
|
359
668
|
|
|
360
669
|
### `@supports(...)` — Feature Queries
|
|
361
670
|
|
|
362
|
-
Feature queries test CSS property support
|
|
671
|
+
Feature queries test CSS property support and accept CSS support functions such
|
|
672
|
+
as `at-rule()`. Use `$` as the first argument to test selector support:
|
|
363
673
|
|
|
364
|
-
| Tasty syntax
|
|
365
|
-
|
|
366
|
-
| `@supports(display: grid)`
|
|
367
|
-
| `@supports($, :has(*))`
|
|
368
|
-
|
|
|
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))` |
|
|
680
|
+
| `!@supports(at-rule(@scope))` | `@supports (not (at-rule(@scope)))` |
|
|
369
681
|
|
|
370
682
|
```jsx
|
|
371
683
|
display: {
|
|
@@ -374,6 +686,114 @@ display: {
|
|
|
374
686
|
}
|
|
375
687
|
```
|
|
376
688
|
|
|
689
|
+
`at-rule()` tests whether the browser supports the named at-rule. Its surrounding
|
|
690
|
+
parentheses in Tasty's CSS output are valid CSS. Negation and combinations with
|
|
691
|
+
other states use the same syntax as property queries:
|
|
692
|
+
|
|
693
|
+
```jsx
|
|
694
|
+
color: {
|
|
695
|
+
_: 'red',
|
|
696
|
+
'@supports(at-rule(@scope)) & @supports(display: grid)': 'blue',
|
|
697
|
+
}
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
Use `_` to keep a base value when a browser cannot evaluate a query. A support
|
|
701
|
+
query only detects a browser feature; it does not add an API for authoring the
|
|
702
|
+
queried at-rule in a Tasty style object. For conditional stylesheet imports such
|
|
703
|
+
as `@import url("scoped.css") supports(at-rule(@scope));`, use an ordinary CSS
|
|
704
|
+
stylesheet or document-level `useRawCSS()`. Put imports before other rules in
|
|
705
|
+
that stylesheet. Imports cannot be used in constructable stylesheets, including
|
|
706
|
+
Tasty's adopted-sheet mode for Shadow DOM.
|
|
707
|
+
|
|
708
|
+
### `_` — Fallback Floor
|
|
709
|
+
|
|
710
|
+
By default Tasty makes states **mutually exclusive**: a higher-priority state
|
|
711
|
+
turns the lower-priority ones off via negation, so exactly one branch applies.
|
|
712
|
+
This relies on `A | !A` always being true. CSS feature/container queries break
|
|
713
|
+
that assumption: `@supports(...)` and `@(...)` queries can be **unknown** (not
|
|
714
|
+
just true/false), and `not(unknown)` is also unknown — so a negated default
|
|
715
|
+
branch silently never applies. The classic case is `scroll-state`: a browser can
|
|
716
|
+
support `container-type: scroll-state` while a specific `scroll-state(...)` query
|
|
717
|
+
is unknown, leaving _no_ branch active.
|
|
718
|
+
|
|
719
|
+
The `_` fallback floor solves this. Use `_` as a **standalone key** and its value
|
|
720
|
+
**always applies** as a guaranteed floor: it never receives negation, and
|
|
721
|
+
higher-priority states simply layer over it via the cascade.
|
|
722
|
+
|
|
723
|
+
```jsx
|
|
724
|
+
inset: {
|
|
725
|
+
_: '0 top',
|
|
726
|
+
'@supports(container-type: scroll-state) & @(scroll-state(scrolled: block-end))':
|
|
727
|
+
'-80x top',
|
|
728
|
+
}
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
```css
|
|
732
|
+
.t0.t0 {
|
|
733
|
+
inset: 0 auto auto auto;
|
|
734
|
+
}
|
|
735
|
+
@supports (container-type: scroll-state) {
|
|
736
|
+
@container scroll-state(scrolled: block-end) {
|
|
737
|
+
.t0.t0 {
|
|
738
|
+
inset: -640px auto auto auto;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
The floor is emitted as a bare rule (no negated `@supports` / container branches),
|
|
745
|
+
so it always applies. When the override matches it wins because it is emitted
|
|
746
|
+
later and all state selectors share the same specificity (see the note on
|
|
747
|
+
`:where()` above).
|
|
748
|
+
|
|
749
|
+
Notes:
|
|
750
|
+
|
|
751
|
+
- `_` is a **standalone key only** — it defines a single map-wide floor and
|
|
752
|
+
cannot be combined with state logic. Keys like `_ & hovered` or `_ | focused`
|
|
753
|
+
are ignored with an `INVALID_FALLBACK_KEY` dev warning.
|
|
754
|
+
- `_` can coexist with the bare `''` default when other states exist: `''` is the
|
|
755
|
+
negated default, `_` is the always-on floor. With only `_` and `''` (no other
|
|
756
|
+
states) the `''` default is redundant — Tasty keeps the `_` value and drops
|
|
757
|
+
`''` with a `REDUNDANT_DEFAULT_STATE` warning.
|
|
758
|
+
- `_` is position-independent: it is always placed at the lowest priority
|
|
759
|
+
regardless of where it appears in the map.
|
|
760
|
+
|
|
761
|
+
#### `_` vs the `''` default
|
|
762
|
+
|
|
763
|
+
In simple maps where every other state is a plain modifier (always cleanly
|
|
764
|
+
on/off), `_` and `''` produce the **same visible result** — the base value shows
|
|
765
|
+
whenever no other state wins. They diverge in three situations, and the root
|
|
766
|
+
cause is always the same: **`''` is mutually exclusive (turned off by negation),
|
|
767
|
+
while `_` is always on (layered underneath).**
|
|
768
|
+
|
|
769
|
+
- **Unknown / invalid branches.** If a higher-priority branch sits behind a query
|
|
770
|
+
that can be _unknown_ (`@supports`, container, `scroll-state`) or uses a
|
|
771
|
+
selector the browser drops, the negated `''` default disappears along with it
|
|
772
|
+
(`not(unknown) = unknown`), leaving the property with no rule. The `_` floor
|
|
773
|
+
survives because it is an unconditional bare rule. This is the case `_` exists
|
|
774
|
+
for.
|
|
775
|
+
|
|
776
|
+
- **Empty / "unset" states.** A state can intentionally produce _no_ output (an
|
|
777
|
+
empty value) to leave a property unset while that state is active. With `''`
|
|
778
|
+
this works — the default is negated away and nothing replaces it, so the
|
|
779
|
+
property unsets. With `_` the floor can never be turned off, so its value keeps
|
|
780
|
+
applying and the "unset on this state" intent is lost.
|
|
781
|
+
|
|
782
|
+
```jsx
|
|
783
|
+
// '' : color unsets while loading. '_' : color stays #text while loading.
|
|
784
|
+
color: { '': '#text', loading: '' }
|
|
785
|
+
```
|
|
786
|
+
|
|
787
|
+
- **States with different output shapes.** Because `_` layers additively, when
|
|
788
|
+
different states emit _different sets_ of declarations, the floor's
|
|
789
|
+
declarations bleed through wherever the winning state does not override the
|
|
790
|
+
same property — which can produce inconsistent combinations. A `''` default is
|
|
791
|
+
swapped out cleanly by its mutually-exclusive condition.
|
|
792
|
+
|
|
793
|
+
Rule of thumb: **use `''` for the normal default** (clean mutual exclusivity,
|
|
794
|
+
supports unsetting), and reach for `_` only when a value must survive an
|
|
795
|
+
_unknown_ higher-priority branch.
|
|
796
|
+
|
|
377
797
|
### `@root(...)` — Root Element States
|
|
378
798
|
|
|
379
799
|
Root states generate selectors on the `:root` element. They are useful for theme modes, feature flags, and other page-level conditions:
|
|
@@ -388,15 +808,15 @@ color: {
|
|
|
388
808
|
}
|
|
389
809
|
```
|
|
390
810
|
|
|
391
|
-
| Tasty syntax
|
|
392
|
-
|
|
393
|
-
| `@root(schema=dark)`
|
|
394
|
-
| `@root(hovered)`
|
|
395
|
-
| `@root(.premium-user)` | `:root.premium-user`
|
|
396
|
-
| `@root([lang="en"])`
|
|
397
|
-
| `!@root(schema=dark)`
|
|
811
|
+
| Tasty syntax | CSS selector |
|
|
812
|
+
| ---------------------- | --------------------------------- |
|
|
813
|
+
| `@root(schema=dark)` | `:root[data-schema="dark"]` |
|
|
814
|
+
| `@root(hovered)` | `:root[data-hovered]` |
|
|
815
|
+
| `@root(.premium-user)` | `:root.premium-user` |
|
|
816
|
+
| `@root([lang="en"])` | `:root[lang="en"]` |
|
|
817
|
+
| `!@root(schema=dark)` | `:root:not([data-schema="dark"])` |
|
|
398
818
|
|
|
399
|
-
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 { ... }`.
|
|
400
820
|
|
|
401
821
|
### `@own(...)` — Sub-element's Own State
|
|
402
822
|
|
|
@@ -410,7 +830,7 @@ const Nav = tasty({
|
|
|
410
830
|
'': '#text',
|
|
411
831
|
'@own(:hover)': '#primary',
|
|
412
832
|
'@own(:focus-visible)': '#primary',
|
|
413
|
-
|
|
833
|
+
selected: '#primary', // root-level modifier
|
|
414
834
|
},
|
|
415
835
|
},
|
|
416
836
|
},
|
|
@@ -418,14 +838,28 @@ const Nav = tasty({
|
|
|
418
838
|
});
|
|
419
839
|
```
|
|
420
840
|
|
|
421
|
-
| Tasty syntax (inside sub-element) | CSS output
|
|
422
|
-
|
|
423
|
-
| `@own(:hover)`
|
|
424
|
-
| `@own(hovered)`
|
|
425
|
-
| `@own(theme=dark)`
|
|
841
|
+
| Tasty syntax (inside sub-element) | CSS output |
|
|
842
|
+
| --------------------------------- | ------------------------------------------------- |
|
|
843
|
+
| `@own(:hover)` | `:hover` on the sub-element selector |
|
|
844
|
+
| `@own(hovered)` | `[data-hovered]` on the sub-element selector |
|
|
845
|
+
| `@own(theme=dark)` | `[data-theme="dark"]` on the sub-element selector |
|
|
426
846
|
|
|
427
847
|
`@own()` is only valid inside sub-element styles. Using it on root styles emits a warning and is treated as a regular modifier.
|
|
428
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
|
+
|
|
429
863
|
### `@starting` — Entry Animation
|
|
430
864
|
|
|
431
865
|
Wraps the rule in `@starting-style`, enabling CSS entry animations for elements as they appear in the DOM:
|
|
@@ -435,40 +869,40 @@ const FadeIn = tasty({
|
|
|
435
869
|
styles: {
|
|
436
870
|
opacity: { '': '1', '@starting': '0' },
|
|
437
871
|
transform: { '': 'scale(1)', '@starting': 'scale(0.95)' },
|
|
438
|
-
transition: 'opacity
|
|
872
|
+
transition: 'opacity, translate',
|
|
439
873
|
},
|
|
440
874
|
});
|
|
441
875
|
```
|
|
442
876
|
|
|
443
|
-
| Tasty syntax | CSS output
|
|
444
|
-
|
|
445
|
-
| `@starting`
|
|
877
|
+
| Tasty syntax | CSS output |
|
|
878
|
+
| ------------ | ------------------------------------ |
|
|
879
|
+
| `@starting` | `.t0.t0 { @starting-style { ... } }` |
|
|
446
880
|
|
|
447
881
|
### `@parent(...)` — Parent Element States
|
|
448
882
|
|
|
449
|
-
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()`.
|
|
450
884
|
|
|
451
885
|
```jsx
|
|
452
886
|
const Highlight = tasty({
|
|
453
887
|
styles: {
|
|
454
888
|
fill: {
|
|
455
889
|
'': '#white',
|
|
456
|
-
'@parent(hovered)': '#gray.05',
|
|
457
|
-
'@parent(theme=dark, >)': '#dark-02',
|
|
890
|
+
'@parent(hovered)': '#gray.05', // Any ancestor has [data-hovered]
|
|
891
|
+
'@parent(theme=dark, >)': '#dark-02', // Direct parent has [data-theme="dark"]
|
|
458
892
|
},
|
|
459
893
|
},
|
|
460
894
|
});
|
|
461
895
|
```
|
|
462
896
|
|
|
463
|
-
| Syntax
|
|
464
|
-
|
|
465
|
-
| `@parent(hovered)`
|
|
466
|
-
| `!@parent(hovered)`
|
|
467
|
-
| `@parent(hovered, >)`
|
|
468
|
-
| `@parent(.active)`
|
|
469
|
-
| `@parent(hovered & focused)`
|
|
470
|
-
| `@parent(hovered) & @parent(focused)` | `:
|
|
471
|
-
| `@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) |
|
|
472
906
|
|
|
473
907
|
For sub-elements, the parent check applies to the root element's ancestors:
|
|
474
908
|
|
|
@@ -483,12 +917,12 @@ const Card = tasty({
|
|
|
483
917
|
},
|
|
484
918
|
},
|
|
485
919
|
});
|
|
486
|
-
// → .t0.t0:
|
|
920
|
+
// → .t0.t0:where([data-hovered] *) [data-element="Label"]
|
|
487
921
|
```
|
|
488
922
|
|
|
489
923
|
### `:is()`, `:has()` — CSS Structural Pseudo-classes
|
|
490
924
|
|
|
491
|
-
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()`.
|
|
492
926
|
|
|
493
927
|
`:where()` and `:not()` are also supported but rarely needed — use `:is()` and `!` negation instead.
|
|
494
928
|
|
|
@@ -499,38 +933,38 @@ const Card = tasty({
|
|
|
499
933
|
styles: {
|
|
500
934
|
display: {
|
|
501
935
|
'': 'block',
|
|
502
|
-
':has(> Icon)': 'grid',
|
|
503
|
-
':has(+ Icon)': 'grid',
|
|
504
|
-
':has(~ Icon)': 'grid',
|
|
505
|
-
':has(Icon +)': 'grid',
|
|
506
|
-
':has(Icon ~)': 'grid',
|
|
507
|
-
':is(fieldset > label)': 'inline',
|
|
508
|
-
'!:has(> Icon)': 'flex',
|
|
936
|
+
':has(> Icon)': 'grid', // has Icon as direct child
|
|
937
|
+
':has(+ Icon)': 'grid', // immediately followed by an Icon sibling
|
|
938
|
+
':has(~ Icon)': 'grid', // has an Icon sibling somewhere after
|
|
939
|
+
':has(Icon +)': 'grid', // immediately preceded by an Icon sibling (auto-completes to `Icon + *`)
|
|
940
|
+
':has(Icon ~)': 'grid', // has an Icon sibling somewhere before (auto-completes to `Icon ~ *`)
|
|
941
|
+
':is(fieldset > label)': 'inline', // is a label inside a fieldset (HTML tags)
|
|
942
|
+
'!:has(> Icon)': 'flex', // negation: no Icon child
|
|
509
943
|
},
|
|
510
944
|
},
|
|
511
945
|
});
|
|
512
946
|
```
|
|
513
947
|
|
|
514
|
-
| Syntax
|
|
515
|
-
|
|
516
|
-
| `:has(> Icon)`
|
|
517
|
-
| `:has(+ Icon)`
|
|
518
|
-
| `:has(~ Icon)`
|
|
519
|
-
| `:has(Icon +)`
|
|
520
|
-
| `:has(Icon ~)`
|
|
521
|
-
| `:has(>)`
|
|
522
|
-
| `:is(
|
|
523
|
-
| `:has(button)`
|
|
524
|
-
| `!:has(> Icon)`
|
|
525
|
-
| `!: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`) |
|
|
526
960
|
|
|
527
961
|
Combine with other states using boolean logic (`&`, `|`, `!`, `^`):
|
|
528
962
|
|
|
529
963
|
```jsx
|
|
530
|
-
':has(> Icon) & hovered'
|
|
531
|
-
'@parent(hovered) & :has(> Icon)'
|
|
532
|
-
':has(> Icon) | :has(> Button)'
|
|
533
|
-
':has(> Icon) ^ :has(> Button)'
|
|
964
|
+
':has(> Icon) & hovered'; // AND: structural + data attribute
|
|
965
|
+
'@parent(hovered) & :has(> Icon)'; // AND: parent check + structural
|
|
966
|
+
':has(> Icon) | :has(> Button)'; // OR: either sub-element present
|
|
967
|
+
':has(> Icon) ^ :has(> Button)'; // XOR: exactly one present
|
|
534
968
|
```
|
|
535
969
|
|
|
536
970
|
> **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.
|
|
@@ -555,6 +989,8 @@ const Pulse = tasty({
|
|
|
555
989
|
});
|
|
556
990
|
```
|
|
557
991
|
|
|
992
|
+
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.
|
|
993
|
+
|
|
558
994
|
---
|
|
559
995
|
|
|
560
996
|
## Properties (`@property`)
|
|
@@ -565,39 +1001,59 @@ CSS cannot transition or animate custom properties unless the browser knows thei
|
|
|
565
1001
|
const AnimatedGradient = tasty({
|
|
566
1002
|
styles: {
|
|
567
1003
|
'$gradient-angle': '0deg',
|
|
568
|
-
'#theme': '
|
|
569
|
-
|
|
570
|
-
transition: '$$gradient-angle
|
|
1004
|
+
'#theme': 'okhst(280 80% 50%)',
|
|
1005
|
+
image: 'linear-gradient($gradient-angle, #theme, #clear)',
|
|
1006
|
+
transition: '$$gradient-angle, ##theme',
|
|
571
1007
|
},
|
|
572
1008
|
});
|
|
573
1009
|
```
|
|
574
1010
|
|
|
575
1011
|
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.
|
|
576
1012
|
|
|
577
|
-
Use explicit `@
|
|
1013
|
+
Use explicit `@property` when you need non-default settings like `inherits: false`:
|
|
578
1014
|
|
|
579
1015
|
```jsx
|
|
580
|
-
'@
|
|
1016
|
+
'@property': {
|
|
581
1017
|
'$gradient-angle': { syntax: '<angle>', inherits: false, initialValue: '0deg' },
|
|
582
1018
|
},
|
|
583
1019
|
```
|
|
584
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
|
+
|
|
585
1041
|
---
|
|
586
1042
|
|
|
587
|
-
## Font Face (`@
|
|
1043
|
+
## Font Face (`@font-face`)
|
|
588
1044
|
|
|
589
1045
|
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).
|
|
590
1046
|
|
|
591
1047
|
```ts
|
|
592
1048
|
const Heading = tasty({
|
|
593
1049
|
styles: {
|
|
594
|
-
'@
|
|
1050
|
+
'@font-face': {
|
|
595
1051
|
'Brand Sans': {
|
|
596
1052
|
src: 'url("/fonts/brand-sans.woff2") format("woff2")',
|
|
597
1053
|
fontDisplay: 'swap',
|
|
598
1054
|
},
|
|
599
1055
|
},
|
|
600
|
-
|
|
1056
|
+
font: '"Brand Sans", sans-serif',
|
|
601
1057
|
},
|
|
602
1058
|
});
|
|
603
1059
|
```
|
|
@@ -607,7 +1063,7 @@ const Heading = tasty({
|
|
|
607
1063
|
Supply an array to register several variants of the same family:
|
|
608
1064
|
|
|
609
1065
|
```ts
|
|
610
|
-
'@
|
|
1066
|
+
'@font-face': {
|
|
611
1067
|
'Brand Sans': [
|
|
612
1068
|
{ src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
|
|
613
1069
|
{ src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
|
|
@@ -617,34 +1073,34 @@ Supply an array to register several variants of the same family:
|
|
|
617
1073
|
|
|
618
1074
|
### Supported descriptors
|
|
619
1075
|
|
|
620
|
-
| Descriptor
|
|
621
|
-
|
|
622
|
-
| `src` (required)
|
|
623
|
-
| `fontWeight`
|
|
624
|
-
| `fontStyle`
|
|
625
|
-
| `fontStretch`
|
|
626
|
-
| `fontDisplay`
|
|
627
|
-
| `unicodeRange`
|
|
628
|
-
| `ascentOverride`
|
|
629
|
-
| `descentOverride`
|
|
630
|
-
| `lineGapOverride`
|
|
631
|
-
| `sizeAdjust`
|
|
632
|
-
| `fontFeatureSettings`
|
|
633
|
-
| `fontVariationSettings` | `font-variation-settings` | `string`
|
|
1076
|
+
| Descriptor | CSS property | Type |
|
|
1077
|
+
| ----------------------- | ------------------------- | --------------------------------------------------------- |
|
|
1078
|
+
| `src` (required) | `src` | `string` |
|
|
1079
|
+
| `fontWeight` | `font-weight` | `string \| number` |
|
|
1080
|
+
| `fontStyle` | `font-style` | `string` |
|
|
1081
|
+
| `fontStretch` | `font-stretch` | `string` |
|
|
1082
|
+
| `fontDisplay` | `font-display` | `'auto' \| 'block' \| 'swap' \| 'fallback' \| 'optional'` |
|
|
1083
|
+
| `unicodeRange` | `unicode-range` | `string` |
|
|
1084
|
+
| `ascentOverride` | `ascent-override` | `string` |
|
|
1085
|
+
| `descentOverride` | `descent-override` | `string` |
|
|
1086
|
+
| `lineGapOverride` | `line-gap-override` | `string` |
|
|
1087
|
+
| `sizeAdjust` | `size-adjust` | `string` |
|
|
1088
|
+
| `fontFeatureSettings` | `font-feature-settings` | `string` |
|
|
1089
|
+
| `fontVariationSettings` | `font-variation-settings` | `string` |
|
|
634
1090
|
|
|
635
1091
|
> Font-face rules are permanent — they are injected once and never cleaned up, matching how browsers handle `@font-face`.
|
|
636
1092
|
|
|
637
1093
|
---
|
|
638
1094
|
|
|
639
|
-
## Counter Style (`@
|
|
1095
|
+
## Counter Style (`@counter-style`)
|
|
640
1096
|
|
|
641
1097
|
Define custom list markers via the CSS `@counter-style` at-rule. Keys are counter-style names, values are descriptor objects.
|
|
642
1098
|
|
|
643
1099
|
```ts
|
|
644
1100
|
const EmojiList = tasty({
|
|
645
|
-
|
|
1101
|
+
as: 'ol',
|
|
646
1102
|
styles: {
|
|
647
|
-
'@
|
|
1103
|
+
'@counter-style': {
|
|
648
1104
|
thumbs: {
|
|
649
1105
|
system: 'cyclic',
|
|
650
1106
|
symbols: '"👍"',
|
|
@@ -658,23 +1114,88 @@ const EmojiList = tasty({
|
|
|
658
1114
|
|
|
659
1115
|
### Supported descriptors
|
|
660
1116
|
|
|
661
|
-
| Descriptor
|
|
662
|
-
|
|
663
|
-
| `system` (required) | `system`
|
|
664
|
-
| `symbols`
|
|
665
|
-
| `additiveSymbols`
|
|
666
|
-
| `prefix`
|
|
667
|
-
| `suffix`
|
|
668
|
-
| `negative`
|
|
669
|
-
| `range`
|
|
670
|
-
| `pad`
|
|
671
|
-
| `fallback`
|
|
672
|
-
| `speakAs`
|
|
1117
|
+
| Descriptor | CSS property | Type |
|
|
1118
|
+
| ------------------- | ------------------ | ---------------------------------------------------------------------------------------- |
|
|
1119
|
+
| `system` (required) | `system` | `'cyclic' \| 'numeric' \| 'alphabetic' \| 'symbolic' \| 'additive' \| 'fixed' \| string` |
|
|
1120
|
+
| `symbols` | `symbols` | `string` |
|
|
1121
|
+
| `additiveSymbols` | `additive-symbols` | `string` |
|
|
1122
|
+
| `prefix` | `prefix` | `string` |
|
|
1123
|
+
| `suffix` | `suffix` | `string` |
|
|
1124
|
+
| `negative` | `negative` | `string` |
|
|
1125
|
+
| `range` | `range` | `string` |
|
|
1126
|
+
| `pad` | `pad` | `string` |
|
|
1127
|
+
| `fallback` | `fallback` | `string` |
|
|
1128
|
+
| `speakAs` | `speak-as` | `string` |
|
|
673
1129
|
|
|
674
1130
|
> Counter-style rules are permanent — they are injected once and never cleaned up, matching how browsers handle `@counter-style`.
|
|
675
1131
|
|
|
676
1132
|
---
|
|
677
1133
|
|
|
1134
|
+
## Functions (`@function`)
|
|
1135
|
+
|
|
1136
|
+
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.
|
|
1137
|
+
|
|
1138
|
+
The token convention follows Tasty's `$` vs `$$` distinction:
|
|
1139
|
+
|
|
1140
|
+
- **`$$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.
|
|
1141
|
+
- **`$name`** — a custom-property declaration/reference (`var(--name)`). Used for **parameters** and **local variables**, exactly like declaring custom props in a styles object.
|
|
1142
|
+
- **Local variables** are declared directly as `$name` keys on the descriptor — the body reads like a mini styles object.
|
|
1143
|
+
- `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.
|
|
1144
|
+
|
|
1145
|
+
```ts
|
|
1146
|
+
const Box = tasty({
|
|
1147
|
+
styles: {
|
|
1148
|
+
'@function': {
|
|
1149
|
+
// simplest: one bare param + result (auto-calc, no explicit calc())
|
|
1150
|
+
$$negative: { args: ['$value'], result: '(-1 * $value)' },
|
|
1151
|
+
|
|
1152
|
+
// typed param + default + return type + local variable
|
|
1153
|
+
$$shadow: {
|
|
1154
|
+
args: { '$shadow-color': { syntax: '<color>', default: 'inherit' } },
|
|
1155
|
+
returns: '<color>',
|
|
1156
|
+
$offset: '2px', // local variable
|
|
1157
|
+
result: '$offset $offset ($shadow-color, black)',
|
|
1158
|
+
},
|
|
1159
|
+
},
|
|
1160
|
+
margin: '$$negative(10px) top', // → margin: --negative(10px) 0 0 0
|
|
1161
|
+
shadow: '$$shadow(#accent)', // → box-shadow: --shadow(var(--accent-color))
|
|
1162
|
+
},
|
|
1163
|
+
});
|
|
1164
|
+
```
|
|
1165
|
+
|
|
1166
|
+
Generated CSS:
|
|
1167
|
+
|
|
1168
|
+
```css
|
|
1169
|
+
@function --negative(--value) {
|
|
1170
|
+
result: calc(-1 * var(--value));
|
|
1171
|
+
}
|
|
1172
|
+
@function --shadow(--shadow-color <color>: inherit) returns <color> {
|
|
1173
|
+
--offset: 2px;
|
|
1174
|
+
result: var(--offset) var(--offset) var(--shadow-color, black);
|
|
1175
|
+
}
|
|
1176
|
+
.t0 {
|
|
1177
|
+
margin: --negative(10px) 0 0 0;
|
|
1178
|
+
box-shadow: --shadow(var(--accent-color));
|
|
1179
|
+
}
|
|
1180
|
+
```
|
|
1181
|
+
|
|
1182
|
+
### Descriptor shape
|
|
1183
|
+
|
|
1184
|
+
| Field | Type | Notes |
|
|
1185
|
+
| ------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
1186
|
+
| `result` (required) | `string` | The `result:` value, parsed through the Tasty DSL. |
|
|
1187
|
+
| `args` | `string[]` \| `Record<string, FunctionParameter>` | Ordered parameters. Array form lists bare names; object form maps names to type/default. |
|
|
1188
|
+
| `returns` | `string` | Optional return type, e.g. `'<color>'`. |
|
|
1189
|
+
| `$name` keys | `string \| number` | Any `$name` key declares a local variable `--name` (value parsed). |
|
|
1190
|
+
|
|
1191
|
+
A `FunctionParameter` is one of: `true` (bare param), a string CSS type shorthand (`'<length>'`), or `{ syntax?: string; default?: string | number }`.
|
|
1192
|
+
|
|
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).
|
|
1194
|
+
|
|
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.
|
|
1196
|
+
|
|
1197
|
+
---
|
|
1198
|
+
|
|
678
1199
|
## Style Properties
|
|
679
1200
|
|
|
680
1201
|
For a complete reference of all enhanced style properties — syntax, values, modifiers, and recommendations — see **[Style Properties Reference](styles.md)**.
|
|
@@ -687,4 +1208,4 @@ For a complete reference of all enhanced style properties — syntax, values, mo
|
|
|
687
1208
|
- **[Methodology](methodology.md)** — Recommended patterns: root + sub-elements, styleProps, tokens, wrapping
|
|
688
1209
|
- **[Configuration](configuration.md)** — Tokens, recipes, custom units, style handlers, TypeScript extensions
|
|
689
1210
|
- **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
|
|
690
|
-
- **[
|
|
1211
|
+
- **[Build-Time Extraction (`tastyStatic`)](tasty-static.md)** — Static styling with the Babel plugin
|