@tenphi/tasty 0.0.0-snapshot.8dc3efa → 0.0.0-snapshot.8efdc31
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-docs8f4c.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-DmSCYjYl.js +60 -0
- package/dist/chunks/build-config-DmSCYjYl.js.map +1 -0
- package/dist/{collector-CBddDz-s.js → chunks/collector-8w5r-xFl.js} +68 -101
- package/dist/chunks/collector-8w5r-xFl.js.map +1 -0
- package/dist/chunks/config-engine-DjRv6Axa.js +272 -0
- package/dist/chunks/config-engine-DjRv6Axa.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-_UidGa56.js +910 -0
- package/dist/chunks/css-definitions-_UidGa56.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-B6dZq3uH.js +502 -0
- package/dist/chunks/debug-B6dZq3uH.js.map +1 -0
- package/dist/chunks/dsl-rgu6XQcD.js +1386 -0
- package/dist/chunks/dsl-rgu6XQcD.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-DS1cEAMK.js +689 -0
- package/dist/chunks/react-runtime-DS1cEAMK.js.map +1 -0
- package/dist/chunks/runtime-engine-DFCZN1nF.js +2432 -0
- package/dist/chunks/runtime-engine-DFCZN1nF.js.map +1 -0
- package/dist/chunks/runtime-state-C8MzPjBR.js +152 -0
- package/dist/chunks/runtime-state-C8MzPjBR.js.map +1 -0
- package/dist/{merge-styles-CWRl0mKF.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-DoGrZPBB.js +5576 -0
- package/dist/chunks/style-engine-DoGrZPBB.js.map +1 -0
- package/dist/{css-writer-DPR4cAyK.js → chunks/zero-engine-CiVidroC.js} +95 -136
- package/dist/chunks/zero-engine-CiVidroC.js.map +1 -0
- package/dist/{collector-osfWTeRd.d.ts → collector-CTU-nl0g.d.ts} +64 -8
- package/dist/{config-BoZDUHW5.d.ts → config-DDY7NlZ1.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-B_k47mc_.d.ts → index-DOxyS72p.d.ts} +714 -407
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -732
- package/dist/{merge-styles-BMWcH6MF.d.ts → merge-styles-DSkVc6CD.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-DJEM_BOJ.d.ts} +879 -598
- 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 +258 -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 +663 -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 +213 -48
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +310 -118
- package/docs/styles.md +177 -40
- package/docs/tasty-static.md +289 -136
- package/package.json +146 -41
- package/tasty.config.ts +5 -0
- package/dist/async-storage-B7_o6FKt.js +0 -44
- package/dist/async-storage-B7_o6FKt.js.map +0 -1
- package/dist/collector-CBddDz-s.js.map +0 -1
- package/dist/config-dkNtxY1j.js +0 -10462
- package/dist/config-dkNtxY1j.js.map +0 -1
- package/dist/context-CkSg-kDT.js +0 -24
- package/dist/context-CkSg-kDT.js.map +0 -1
- package/dist/core-CWJ4JX5P.js +0 -1598
- package/dist/core-CWJ4JX5P.js.map +0 -1
- package/dist/css-writer-DPR4cAyK.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-BnfFVBQE.js +0 -143
- package/dist/format-rules-BnfFVBQE.js.map +0 -1
- package/dist/hydrate-Chagc_CN.js +0 -45
- package/dist/hydrate-Chagc_CN.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-Dbe0HQAg.js +0 -588
- package/dist/keyframes-Dbe0HQAg.js.map +0 -1
- package/dist/merge-styles-CWRl0mKF.js.map +0 -1
- package/dist/resolve-recipes-DZBMeDib.js +0 -144
- package/dist/resolve-recipes-DZBMeDib.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,190 @@ 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: '#current.5', // → color-mix(in oklab, currentcolor 50%, transparent)
|
|
124
171
|
color: '(#primary, #secondary)', // Fallback syntax
|
|
125
172
|
```
|
|
126
173
|
|
|
174
|
+
`#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.
|
|
175
|
+
|
|
176
|
+
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.
|
|
177
|
+
|
|
178
|
+
The suffix fades the token's color by mixing it with `transparent`:
|
|
179
|
+
|
|
180
|
+
```jsx
|
|
181
|
+
fill: '#purple.5';
|
|
182
|
+
// → color-mix(in oklab, var(--purple-color) 50%, transparent)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
The mix asks nothing of the color beyond _being_ a color. That means the suffix
|
|
186
|
+
works on every one of these:
|
|
187
|
+
|
|
188
|
+
- a token holding a `color-mix()`, a `light-dark()`, or a `color()` in a space
|
|
189
|
+
Tasty cannot convert — none of which have channels to decompose
|
|
190
|
+
- `#current`, which resolves to the color the element inherits
|
|
191
|
+
- a `--name-color` variable declared in your own CSS, with no Tasty token
|
|
192
|
+
definition behind it
|
|
193
|
+
|
|
194
|
+
`color-mix()` is Baseline widely available (Chrome 111, Firefox 113, Safari
|
|
195
|
+
16.2). Two properties follow from mixing rather than writing an alpha channel:
|
|
196
|
+
|
|
197
|
+
- **Alpha composes.** The mix is premultiplied, so a color that is already
|
|
198
|
+
translucent is faded further: a token holding `rgb(255 0 0 / .8)` faded to
|
|
199
|
+
`.5` is alpha `.4`. An opaque token — the usual case — ends at exactly the
|
|
200
|
+
suffix. System colors are whatever the platform draws, and some are
|
|
201
|
+
translucent: Chrome and Safari on macOS give `Highlight` an alpha of `.6`, so
|
|
202
|
+
a token holding it faded to `.5` ends at `.3` there.
|
|
203
|
+
- **A `$prop` alpha must be a number.** `#purple.$fade` emits
|
|
204
|
+
`calc(var(--fade) * 100%)`, because a mix percentage cannot be a `<number>`,
|
|
205
|
+
so `$fade` has to hold `.5`, not `50%`.
|
|
206
|
+
|
|
207
|
+
### `#clear` is transparent
|
|
208
|
+
|
|
209
|
+
`#clear` is a built-in [replace token](#replace-tokens) for `transparent`.
|
|
210
|
+
Opacity suffixes are ignored: `#clear.5` and `#clear.$fade` both emit
|
|
211
|
+
`transparent`. The same rule applies to user-defined replace tokens resolving
|
|
212
|
+
to `transparent`, including aliases of `#clear`.
|
|
213
|
+
|
|
214
|
+
It does not read `--clear-color` or require an `@property` registration.
|
|
215
|
+
An explicit `configure({ replaceTokens: { '#clear': ... } })` overrides the
|
|
216
|
+
default alias and uses the replacement's usual opacity behavior.
|
|
217
|
+
|
|
218
|
+
### `#current` is the keyword
|
|
219
|
+
|
|
220
|
+
`#current` emits the `currentcolor` keyword, so it resolves against the element
|
|
221
|
+
that reads it. That is what lets it follow a color an ancestor faded — a ramp
|
|
222
|
+
that expresses its disabled state once, in `color`, fades everything painted from
|
|
223
|
+
`#current` below it with no further declarations.
|
|
224
|
+
|
|
225
|
+
The `color` style also publishes `--current-color` beside every color it sets,
|
|
226
|
+
for anything that needs the inherited color _as a color_ rather than as the
|
|
227
|
+
keyword — hand-authored CSS, or a place the keyword will not do. Read it as
|
|
228
|
+
`$current-color`. It is registered with `initial-value: currentcolor`, so where
|
|
229
|
+
nothing published it, it still resolves against each element's own color:
|
|
230
|
+
|
|
231
|
+
```jsx
|
|
232
|
+
fill: '$current-color'; // → var(--current-color)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
A color that already reads the color it inherits — `#current`, a `#current` fade
|
|
236
|
+
— is not published into it: resolving such a value a second time at a descendant
|
|
237
|
+
would fade it twice.
|
|
238
|
+
|
|
239
|
+
### `#current` fades compose
|
|
240
|
+
|
|
241
|
+
`currentcolor` is the color an element **inherits**, which an ancestor may
|
|
242
|
+
already have faded, so `#current.4` means "40% of what reaches me":
|
|
243
|
+
|
|
244
|
+
```jsx
|
|
245
|
+
fill: '#current.4';
|
|
246
|
+
// → color-mix(in oklab, currentcolor 40%, transparent)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
A `#current` fade nested inside another one composes: a label at `#current.4`
|
|
250
|
+
with a fill of `#current.18` under it lands at `.072`. Color ramps built on
|
|
251
|
+
`#current` depend on that.
|
|
252
|
+
|
|
253
|
+
Fades always mix `in oklab`: it is unbounded, so a wide-gamut color is not
|
|
254
|
+
clamped, and rectangular, so there is no hue to interpolate against
|
|
255
|
+
`transparent`. Nothing configures it — see
|
|
256
|
+
[Color space](configuration.md#color-space).
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## CSS Color Functions
|
|
261
|
+
|
|
262
|
+
Every CSS color function is recognized as a color, so it lands in the color slot
|
|
263
|
+
of whichever style property you use it in — and tokens inside it are expanded:
|
|
264
|
+
|
|
265
|
+
```jsx
|
|
266
|
+
fill: 'color-mix(in oklab, #primary 50%, #surface)',
|
|
267
|
+
color: 'light-dark(#dark, #light)',
|
|
268
|
+
color: 'contrast-color(#primary)',
|
|
269
|
+
fill: 'color(display-p3 1 .5 0)',
|
|
270
|
+
border: '1bw solid oklch(from #primary l c h / 50%)', // relative color syntax
|
|
271
|
+
shadow: '0 0 1x color-mix(in oklab, #dark 20%, transparent)',
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Tasty also ships `okhsl()` and `okhst()`, which compile to `rgb()` at parse
|
|
275
|
+
time: `fill: 'okhsl(280 80% 50%)'` → `rgb(40% 38.5% 88.2%)`.
|
|
276
|
+
|
|
277
|
+
`light-dark()` is the one exception to "always a color": CSS lets it pick between
|
|
278
|
+
values of any type, so it is treated as a color only when its arguments are
|
|
279
|
+
colors. `padding: 'light-dark(1x, 2x)'` still reaches the padding slot.
|
|
280
|
+
|
|
281
|
+
A color token defined as one of these functions takes the
|
|
282
|
+
[opacity suffix](#color-tokens--opacity) like any other:
|
|
283
|
+
|
|
284
|
+
```jsx
|
|
285
|
+
const Card = tasty({
|
|
286
|
+
styles: {
|
|
287
|
+
'#brand': 'color-mix(in oklab, #primary 50%, #surface)',
|
|
288
|
+
fill: '#brand.5',
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
A [replace token](configuration.md#replace-tokens-parse-time-substitution) is
|
|
294
|
+
substituted while parsing, so its color is right there to fade in place. A
|
|
295
|
+
channel function takes the alpha after a slash; a derived function has no alpha
|
|
296
|
+
channel, so it gets wrapped:
|
|
297
|
+
|
|
298
|
+
```jsx
|
|
299
|
+
configure({
|
|
300
|
+
replaceTokens: {
|
|
301
|
+
'#solid': 'hsl(220 90% 50%)',
|
|
302
|
+
'#adaptive': 'light-dark(#dark, #light)',
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
fill: '#solid.5'; // → hsl(220 90% 50% / .5)
|
|
307
|
+
fill: '#adaptive.5'; // → color-mix(in oklab, light-dark(…) 50%, transparent)
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Color keywords
|
|
311
|
+
|
|
312
|
+
CSS named colors (`rebeccapurple`) and system colors (`Canvas`, `CanvasText`,
|
|
313
|
+
`Highlight`, `ButtonText`, `GrayText`, `LinkText`, …) are colors too: they land
|
|
314
|
+
in the color slot of any style and can be a color token's value. System colors
|
|
315
|
+
are what `forced-colors` styles are written in:
|
|
316
|
+
|
|
317
|
+
```jsx
|
|
318
|
+
const Checkbox = tasty({
|
|
319
|
+
styles: {
|
|
320
|
+
'#forced-border': 'CanvasText',
|
|
321
|
+
border: {
|
|
322
|
+
'': '1bw #border',
|
|
323
|
+
'@media(forced-colors: active)': '1bw #forced-border',
|
|
324
|
+
},
|
|
325
|
+
outline: { '': false, focused: '2px Highlight' },
|
|
326
|
+
},
|
|
327
|
+
});
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
A custom property whose fallback is a single color is read as a color, so it
|
|
331
|
+
also fills the color slot: `border: '1bw var(--accent, Highlight)'`, as does
|
|
332
|
+
`($accent, Highlight)`. Keywords are case-insensitive: a color token keeps the
|
|
333
|
+
case it was written in, and a property value such as `border` or `fill` emits
|
|
334
|
+
them lowercase.
|
|
335
|
+
|
|
336
|
+
The deprecated system colors (`Menu`, `Window`, `ButtonHighlight`, …) are not
|
|
337
|
+
recognized.
|
|
338
|
+
|
|
127
339
|
---
|
|
128
340
|
|
|
129
341
|
## Built-in Units
|
|
130
342
|
|
|
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`
|
|
343
|
+
| Unit | Description | Default | Example | CSS output |
|
|
344
|
+
| ---- | ------------------ | ---------------- | ------- | ---------------- |
|
|
345
|
+
| `x` | Spacing step | `8px` | `2x` | `16px` |
|
|
346
|
+
| `r` | Border radius | `6px` | `1r` | `6px` |
|
|
347
|
+
| `cr` | Card border radius | `10px` | `1cr` | `10px` |
|
|
348
|
+
| `bw` | Border width | `1px` | `2bw` | `2px` |
|
|
349
|
+
| `ow` | Outline width | `3px` | `1ow` | `3px` |
|
|
350
|
+
| `sf` | Stable fraction | `minmax(0, Nfr)` | `1sf` | `minmax(0, 1fr)` |
|
|
139
351
|
|
|
140
|
-
|
|
352
|
+
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
353
|
|
|
142
354
|
---
|
|
143
355
|
|
|
@@ -178,9 +390,29 @@ const ElevatedCard = tasty({
|
|
|
178
390
|
});
|
|
179
391
|
```
|
|
180
392
|
|
|
393
|
+
**Where recipes resolve:**
|
|
394
|
+
|
|
395
|
+
The `recipe` property is resolved on the component root and independently inside each sub-element's styles:
|
|
396
|
+
|
|
397
|
+
```jsx
|
|
398
|
+
const CardWithPanel = tasty({
|
|
399
|
+
styles: {
|
|
400
|
+
recipe: 'card',
|
|
401
|
+
Panel: {
|
|
402
|
+
recipe: 'card elevated',
|
|
403
|
+
padding: '2x', // Overrides the panel's base recipe padding
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
});
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
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).
|
|
410
|
+
|
|
411
|
+
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.
|
|
412
|
+
|
|
181
413
|
**Post-merge recipes (`/` separator):**
|
|
182
414
|
|
|
183
|
-
Recipes listed after `/` are applied
|
|
415
|
+
Recipes listed after `/` are applied _after_ component styles using `mergeStyles`:
|
|
184
416
|
|
|
185
417
|
```jsx
|
|
186
418
|
const Input = tasty({
|
|
@@ -218,8 +450,8 @@ When a style property uses a state map, the merge behavior depends on whether th
|
|
|
218
450
|
const MyButton = tasty(Button, {
|
|
219
451
|
styles: {
|
|
220
452
|
fill: {
|
|
221
|
-
|
|
222
|
-
|
|
453
|
+
loading: '#yellow', // append new state
|
|
454
|
+
disabled: '#gray.20', // override existing state in place
|
|
223
455
|
},
|
|
224
456
|
},
|
|
225
457
|
});
|
|
@@ -229,7 +461,7 @@ const MyButton = tasty(Button, {
|
|
|
229
461
|
styles: {
|
|
230
462
|
fill: {
|
|
231
463
|
'': '#red',
|
|
232
|
-
|
|
464
|
+
hovered: '#blue',
|
|
233
465
|
},
|
|
234
466
|
},
|
|
235
467
|
});
|
|
@@ -254,8 +486,14 @@ fill: {
|
|
|
254
486
|
Use `null` inside a state map to remove a state, or `false` to block it entirely (tombstone):
|
|
255
487
|
|
|
256
488
|
```jsx
|
|
257
|
-
|
|
258
|
-
|
|
489
|
+
const MyButton = tasty(Button, {
|
|
490
|
+
styles: {
|
|
491
|
+
fill: {
|
|
492
|
+
hovered: null, // removes the parent's hovered state
|
|
493
|
+
disabled: false, // tombstone — no CSS for disabled, blocks recipe too
|
|
494
|
+
},
|
|
495
|
+
},
|
|
496
|
+
});
|
|
259
497
|
```
|
|
260
498
|
|
|
261
499
|
### Resetting Properties with `null` and `false`
|
|
@@ -263,44 +501,54 @@ fill: { disabled: false } // tombstone — no CSS for disabled, blocks recipe to
|
|
|
263
501
|
```jsx
|
|
264
502
|
const SimpleButton = tasty(Button, {
|
|
265
503
|
styles: {
|
|
266
|
-
fill: null,
|
|
504
|
+
fill: null, // discard parent's fill, let recipe fill in
|
|
267
505
|
border: false, // no border at all (tombstone — blocks recipe too)
|
|
268
506
|
},
|
|
269
507
|
});
|
|
270
508
|
```
|
|
271
509
|
|
|
272
|
-
| Value
|
|
273
|
-
|
|
274
|
-
| `undefined` | Not provided — parent preserved
|
|
275
|
-
| `null`
|
|
276
|
-
| `false`
|
|
510
|
+
| Value | Meaning | Recipe fills in? |
|
|
511
|
+
| ----------- | ------------------------------------ | ---------------- |
|
|
512
|
+
| `undefined` | Not provided — parent preserved | N/A |
|
|
513
|
+
| `null` | Intentional unset — parent discarded | Yes |
|
|
514
|
+
| `false` | Tombstone — blocks everything | No |
|
|
277
515
|
|
|
278
516
|
---
|
|
279
517
|
|
|
280
518
|
## Advanced States (`@` prefix)
|
|
281
519
|
|
|
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
|
-
| `:
|
|
520
|
+
| Prefix | Purpose | Example |
|
|
521
|
+
| ----------- | ----------------------------------------- | -------------------------- |
|
|
522
|
+
| `@media` | Media queries | `@media(w < 768px)` |
|
|
523
|
+
| `@(...)` | Container queries | `@(panel, w >= 300px)` |
|
|
524
|
+
| `@supports` | Feature/selector support | `@supports(display: grid)` |
|
|
525
|
+
| `@root` | Root element states | `@root(schema=dark)` |
|
|
526
|
+
| `@parent` | Parent/ancestor element states | `@parent(hovered)` |
|
|
527
|
+
| `@own` | Sub-element's own state | `@own(hovered)` |
|
|
528
|
+
| `@starting` | Entry animation | `@starting` |
|
|
529
|
+
| `_` | Fallback floor (always-on, never negated) | `_` |
|
|
530
|
+
| `:is()` | CSS `:is()` structural pseudo-class | `:is(fieldset > label)` |
|
|
531
|
+
| `:has()` | CSS `:has()` relational pseudo-class | `:has(> Icon)` |
|
|
532
|
+
| `:not()` | CSS `:not()` negation (prefer `!:is()`) | `:not(:first-child)` |
|
|
533
|
+
| `:where()` | CSS `:where()` (zero specificity) | `:where(Section)` |
|
|
534
|
+
|
|
535
|
+
> **Specificity.** All state selectors Tasty generates (modifiers, pseudo-classes,
|
|
536
|
+
> `:is()`/`:not()` groups, and `@root` / `@parent` context) are wrapped in
|
|
537
|
+
> `:where(...)` so they carry **zero specificity**. The only specificity anchors
|
|
538
|
+
> are the doubled component class (`.t0.t0`) and sub-element `[data-element]`
|
|
539
|
+
> attributes. This means overlapping rules (e.g. a `_` fallback floor and the
|
|
540
|
+
> states layered over it) resolve purely by **source order** — Tasty emits
|
|
541
|
+
> lower-priority states first and higher-priority states last so the cascade
|
|
542
|
+
> produces the intended winner.
|
|
295
543
|
|
|
296
544
|
### `@media(...)` — Media Queries
|
|
297
545
|
|
|
298
|
-
Media queries support dimension shorthands
|
|
546
|
+
Media queries support dimension shorthands:
|
|
299
547
|
|
|
300
548
|
| Shorthand | Expands to |
|
|
301
|
-
|
|
302
|
-
| `w`
|
|
303
|
-
| `h`
|
|
549
|
+
| --------- | ---------- |
|
|
550
|
+
| `w` | `width` |
|
|
551
|
+
| `h` | `height` |
|
|
304
552
|
|
|
305
553
|
```jsx
|
|
306
554
|
fill: {
|
|
@@ -311,16 +559,23 @@ fill: {
|
|
|
311
559
|
}
|
|
312
560
|
```
|
|
313
561
|
|
|
314
|
-
| Tasty syntax
|
|
315
|
-
|
|
316
|
-
| `@media(w < 768px)`
|
|
317
|
-
| `@media(600px <= w < 1200px)`
|
|
318
|
-
| `@media:print`
|
|
319
|
-
| `@media:screen`
|
|
562
|
+
| Tasty syntax | CSS output |
|
|
563
|
+
| ------------------------------------ | ------------------------------------- |
|
|
564
|
+
| `@media(w < 768px)` | `@media (width < 768px)` |
|
|
565
|
+
| `@media(600px <= w < 1200px)` | `@media (600px <= width < 1200px)` |
|
|
566
|
+
| `@media:print` | `@media print` |
|
|
567
|
+
| `@media:screen` | `@media screen` |
|
|
568
|
+
| `@media:all` | `@media all` |
|
|
569
|
+
| `@media:speech` | `@media speech` |
|
|
320
570
|
| `@media(prefers-color-scheme: dark)` | `@media (prefers-color-scheme: dark)` |
|
|
321
|
-
| `@media(prefers-reduced-motion)`
|
|
571
|
+
| `@media(prefers-reduced-motion)` | `@media (prefers-reduced-motion)` |
|
|
572
|
+
| `@media(aspect-ratio > 16/9)` | `@media (aspect-ratio > 16/9)` |
|
|
573
|
+
|
|
574
|
+
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`.
|
|
322
575
|
|
|
323
|
-
|
|
576
|
+
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`.
|
|
577
|
+
|
|
578
|
+
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
579
|
|
|
325
580
|
In practice, define state aliases via `configure({ states })` and use `@mobile` instead of writing the full query in every component.
|
|
326
581
|
|
|
@@ -328,12 +583,12 @@ In practice, define state aliases via `configure({ states })` and use `@mobile`
|
|
|
328
583
|
|
|
329
584
|
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
585
|
|
|
331
|
-
| Shorthand | Expands to
|
|
332
|
-
|
|
333
|
-
| `w`
|
|
334
|
-
| `h`
|
|
335
|
-
| `is`
|
|
336
|
-
| `bs`
|
|
586
|
+
| Shorthand | Expands to |
|
|
587
|
+
| --------- | ------------- |
|
|
588
|
+
| `w` | `width` |
|
|
589
|
+
| `h` | `height` |
|
|
590
|
+
| `is` | `inline-size` |
|
|
591
|
+
| `bs` | `block-size` |
|
|
337
592
|
|
|
338
593
|
```jsx
|
|
339
594
|
const Panel = tasty({
|
|
@@ -346,26 +601,31 @@ const Panel = tasty({
|
|
|
346
601
|
});
|
|
347
602
|
```
|
|
348
603
|
|
|
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)`
|
|
604
|
+
| Tasty syntax | CSS output |
|
|
605
|
+
| ---------------------------------- | -------------------------------------------- |
|
|
606
|
+
| `@(layout, w < 600px)` | `@container layout (width < 600px)` |
|
|
607
|
+
| `@(w < 600px)` | `@container (width < 600px)` |
|
|
608
|
+
| `@(layout, $variant=danger)` | `@container layout style(--variant: danger)` |
|
|
609
|
+
| `@(layout, $compact)` | `@container layout style(--compact)` |
|
|
610
|
+
| `@(scroll-state(stuck: top))` | `@container scroll-state(stuck: top)` |
|
|
611
|
+
| `@(nav, scroll-state(stuck: top))` | `@container nav scroll-state(stuck: top)` |
|
|
357
612
|
|
|
358
|
-
Container style queries use `$prop` (boolean) or `$prop=value` syntax, which maps to CSS `style(--prop)` or `style(--prop:
|
|
613
|
+
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"`.
|
|
614
|
+
|
|
615
|
+
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
616
|
|
|
360
617
|
### `@supports(...)` — Feature Queries
|
|
361
618
|
|
|
362
|
-
Feature queries test CSS property support
|
|
619
|
+
Feature queries test CSS property support and accept CSS support functions such
|
|
620
|
+
as `at-rule()`. Use `$` as the first argument to test selector support:
|
|
363
621
|
|
|
364
|
-
| Tasty syntax
|
|
365
|
-
|
|
366
|
-
| `@supports(display: grid)`
|
|
367
|
-
| `@supports($, :has(*))`
|
|
368
|
-
|
|
|
622
|
+
| Tasty syntax | CSS output |
|
|
623
|
+
| ----------------------------- | ----------------------------------- |
|
|
624
|
+
| `@supports(display: grid)` | `@supports (display: grid)` |
|
|
625
|
+
| `@supports($, :has(*))` | `@supports selector(:has(*))` |
|
|
626
|
+
| `@supports(at-rule(@scope))` | `@supports (at-rule(@scope))` |
|
|
627
|
+
| `!@supports(display: grid)` | `@supports (not (display: grid))` |
|
|
628
|
+
| `!@supports(at-rule(@scope))` | `@supports (not (at-rule(@scope)))` |
|
|
369
629
|
|
|
370
630
|
```jsx
|
|
371
631
|
display: {
|
|
@@ -374,6 +634,114 @@ display: {
|
|
|
374
634
|
}
|
|
375
635
|
```
|
|
376
636
|
|
|
637
|
+
`at-rule()` tests whether the browser supports the named at-rule. Its surrounding
|
|
638
|
+
parentheses in Tasty's CSS output are valid CSS. Negation and combinations with
|
|
639
|
+
other states use the same syntax as property queries:
|
|
640
|
+
|
|
641
|
+
```jsx
|
|
642
|
+
color: {
|
|
643
|
+
_: 'red',
|
|
644
|
+
'@supports(at-rule(@scope)) & @supports(display: grid)': 'blue',
|
|
645
|
+
}
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
Use `_` to keep a base value when a browser cannot evaluate a query. A support
|
|
649
|
+
query only detects a browser feature; it does not add an API for authoring the
|
|
650
|
+
queried at-rule in a Tasty style object. For conditional stylesheet imports such
|
|
651
|
+
as `@import url("scoped.css") supports(at-rule(@scope));`, use an ordinary CSS
|
|
652
|
+
stylesheet or document-level `useRawCSS()`. Put imports before other rules in
|
|
653
|
+
that stylesheet. Imports cannot be used in constructable stylesheets, including
|
|
654
|
+
Tasty's adopted-sheet mode for Shadow DOM.
|
|
655
|
+
|
|
656
|
+
### `_` — Fallback Floor
|
|
657
|
+
|
|
658
|
+
By default Tasty makes states **mutually exclusive**: a higher-priority state
|
|
659
|
+
turns the lower-priority ones off via negation, so exactly one branch applies.
|
|
660
|
+
This relies on `A | !A` always being true. CSS feature/container queries break
|
|
661
|
+
that assumption: `@supports(...)` and `@(...)` queries can be **unknown** (not
|
|
662
|
+
just true/false), and `not(unknown)` is also unknown — so a negated default
|
|
663
|
+
branch silently never applies. The classic case is `scroll-state`: a browser can
|
|
664
|
+
support `container-type: scroll-state` while a specific `scroll-state(...)` query
|
|
665
|
+
is unknown, leaving _no_ branch active.
|
|
666
|
+
|
|
667
|
+
The `_` fallback floor solves this. Use `_` as a **standalone key** and its value
|
|
668
|
+
**always applies** as a guaranteed floor: it never receives negation, and
|
|
669
|
+
higher-priority states simply layer over it via the cascade.
|
|
670
|
+
|
|
671
|
+
```jsx
|
|
672
|
+
inset: {
|
|
673
|
+
_: '0 top',
|
|
674
|
+
'@supports(container-type: scroll-state) & @(scroll-state(scrolled: block-end))':
|
|
675
|
+
'-80x top',
|
|
676
|
+
}
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
```css
|
|
680
|
+
.t0.t0 {
|
|
681
|
+
inset: 0 auto auto auto;
|
|
682
|
+
}
|
|
683
|
+
@supports (container-type: scroll-state) {
|
|
684
|
+
@container scroll-state(scrolled: block-end) {
|
|
685
|
+
.t0.t0 {
|
|
686
|
+
inset: -640px auto auto auto;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
The floor is emitted as a bare rule (no negated `@supports` / container branches),
|
|
693
|
+
so it always applies. When the override matches it wins because it is emitted
|
|
694
|
+
later and all state selectors share the same specificity (see the note on
|
|
695
|
+
`:where()` above).
|
|
696
|
+
|
|
697
|
+
Notes:
|
|
698
|
+
|
|
699
|
+
- `_` is a **standalone key only** — it defines a single map-wide floor and
|
|
700
|
+
cannot be combined with state logic. Keys like `_ & hovered` or `_ | focused`
|
|
701
|
+
are ignored with an `INVALID_FALLBACK_KEY` dev warning.
|
|
702
|
+
- `_` can coexist with the bare `''` default when other states exist: `''` is the
|
|
703
|
+
negated default, `_` is the always-on floor. With only `_` and `''` (no other
|
|
704
|
+
states) the `''` default is redundant — Tasty keeps the `_` value and drops
|
|
705
|
+
`''` with a `REDUNDANT_DEFAULT_STATE` warning.
|
|
706
|
+
- `_` is position-independent: it is always placed at the lowest priority
|
|
707
|
+
regardless of where it appears in the map.
|
|
708
|
+
|
|
709
|
+
#### `_` vs the `''` default
|
|
710
|
+
|
|
711
|
+
In simple maps where every other state is a plain modifier (always cleanly
|
|
712
|
+
on/off), `_` and `''` produce the **same visible result** — the base value shows
|
|
713
|
+
whenever no other state wins. They diverge in three situations, and the root
|
|
714
|
+
cause is always the same: **`''` is mutually exclusive (turned off by negation),
|
|
715
|
+
while `_` is always on (layered underneath).**
|
|
716
|
+
|
|
717
|
+
- **Unknown / invalid branches.** If a higher-priority branch sits behind a query
|
|
718
|
+
that can be _unknown_ (`@supports`, container, `scroll-state`) or uses a
|
|
719
|
+
selector the browser drops, the negated `''` default disappears along with it
|
|
720
|
+
(`not(unknown) = unknown`), leaving the property with no rule. The `_` floor
|
|
721
|
+
survives because it is an unconditional bare rule. This is the case `_` exists
|
|
722
|
+
for.
|
|
723
|
+
|
|
724
|
+
- **Empty / "unset" states.** A state can intentionally produce _no_ output (an
|
|
725
|
+
empty value) to leave a property unset while that state is active. With `''`
|
|
726
|
+
this works — the default is negated away and nothing replaces it, so the
|
|
727
|
+
property unsets. With `_` the floor can never be turned off, so its value keeps
|
|
728
|
+
applying and the "unset on this state" intent is lost.
|
|
729
|
+
|
|
730
|
+
```jsx
|
|
731
|
+
// '' : color unsets while loading. '_' : color stays #text while loading.
|
|
732
|
+
color: { '': '#text', loading: '' }
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
- **States with different output shapes.** Because `_` layers additively, when
|
|
736
|
+
different states emit _different sets_ of declarations, the floor's
|
|
737
|
+
declarations bleed through wherever the winning state does not override the
|
|
738
|
+
same property — which can produce inconsistent combinations. A `''` default is
|
|
739
|
+
swapped out cleanly by its mutually-exclusive condition.
|
|
740
|
+
|
|
741
|
+
Rule of thumb: **use `''` for the normal default** (clean mutual exclusivity,
|
|
742
|
+
supports unsetting), and reach for `_` only when a value must survive an
|
|
743
|
+
_unknown_ higher-priority branch.
|
|
744
|
+
|
|
377
745
|
### `@root(...)` — Root Element States
|
|
378
746
|
|
|
379
747
|
Root states generate selectors on the `:root` element. They are useful for theme modes, feature flags, and other page-level conditions:
|
|
@@ -388,15 +756,15 @@ color: {
|
|
|
388
756
|
}
|
|
389
757
|
```
|
|
390
758
|
|
|
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)`
|
|
759
|
+
| Tasty syntax | CSS selector |
|
|
760
|
+
| ---------------------- | --------------------------------- |
|
|
761
|
+
| `@root(schema=dark)` | `:root[data-schema="dark"]` |
|
|
762
|
+
| `@root(hovered)` | `:root[data-hovered]` |
|
|
763
|
+
| `@root(.premium-user)` | `:root.premium-user` |
|
|
764
|
+
| `@root([lang="en"])` | `:root[lang="en"]` |
|
|
765
|
+
| `!@root(schema=dark)` | `:root:not([data-schema="dark"])` |
|
|
398
766
|
|
|
399
|
-
Root conditions are prepended to the component selector
|
|
767
|
+
Root conditions are prepended to the component selector inside `:where()`: `:where(:root[data-schema="dark"]) .t0.t0 { ... }`.
|
|
400
768
|
|
|
401
769
|
### `@own(...)` — Sub-element's Own State
|
|
402
770
|
|
|
@@ -410,7 +778,7 @@ const Nav = tasty({
|
|
|
410
778
|
'': '#text',
|
|
411
779
|
'@own(:hover)': '#primary',
|
|
412
780
|
'@own(:focus-visible)': '#primary',
|
|
413
|
-
|
|
781
|
+
selected: '#primary', // root-level modifier
|
|
414
782
|
},
|
|
415
783
|
},
|
|
416
784
|
},
|
|
@@ -418,14 +786,28 @@ const Nav = tasty({
|
|
|
418
786
|
});
|
|
419
787
|
```
|
|
420
788
|
|
|
421
|
-
| Tasty syntax (inside sub-element) | CSS output
|
|
422
|
-
|
|
423
|
-
| `@own(:hover)`
|
|
424
|
-
| `@own(hovered)`
|
|
425
|
-
| `@own(theme=dark)`
|
|
789
|
+
| Tasty syntax (inside sub-element) | CSS output |
|
|
790
|
+
| --------------------------------- | ------------------------------------------------- |
|
|
791
|
+
| `@own(:hover)` | `:hover` on the sub-element selector |
|
|
792
|
+
| `@own(hovered)` | `[data-hovered]` on the sub-element selector |
|
|
793
|
+
| `@own(theme=dark)` | `[data-theme="dark"]` on the sub-element selector |
|
|
426
794
|
|
|
427
795
|
`@own()` is only valid inside sub-element styles. Using it on root styles emits a warning and is treated as a regular modifier.
|
|
428
796
|
|
|
797
|
+
When `$` ends in a pseudo-element, `@own()` is the pseudo-element's own state and goes after it:
|
|
798
|
+
|
|
799
|
+
```jsx
|
|
800
|
+
Label: {
|
|
801
|
+
$: '@::part(label)',
|
|
802
|
+
color: { '': '#text', '@own(:focus)': '#primary' },
|
|
803
|
+
},
|
|
804
|
+
// → .t0.t0 [data-element="Label"]::part(label):where(:focus) { … }
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
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.
|
|
808
|
+
|
|
809
|
+
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.
|
|
810
|
+
|
|
429
811
|
### `@starting` — Entry Animation
|
|
430
812
|
|
|
431
813
|
Wraps the rule in `@starting-style`, enabling CSS entry animations for elements as they appear in the DOM:
|
|
@@ -435,40 +817,40 @@ const FadeIn = tasty({
|
|
|
435
817
|
styles: {
|
|
436
818
|
opacity: { '': '1', '@starting': '0' },
|
|
437
819
|
transform: { '': 'scale(1)', '@starting': 'scale(0.95)' },
|
|
438
|
-
transition: 'opacity
|
|
820
|
+
transition: 'opacity, translate',
|
|
439
821
|
},
|
|
440
822
|
});
|
|
441
823
|
```
|
|
442
824
|
|
|
443
|
-
| Tasty syntax | CSS output
|
|
444
|
-
|
|
445
|
-
| `@starting`
|
|
825
|
+
| Tasty syntax | CSS output |
|
|
826
|
+
| ------------ | ------------------------------------ |
|
|
827
|
+
| `@starting` | `.t0.t0 { @starting-style { ... } }` |
|
|
446
828
|
|
|
447
829
|
### `@parent(...)` — Parent Element States
|
|
448
830
|
|
|
449
|
-
Style based on ancestor element attributes. Uses `:
|
|
831
|
+
Style based on ancestor element attributes. Uses `:where([selector] *)` / `:where(:not([selector] *))` for symmetric, composable parent checks. Boolean logic (`&`, `|`, `!`, `^`) is supported inside `@parent()`.
|
|
450
832
|
|
|
451
833
|
```jsx
|
|
452
834
|
const Highlight = tasty({
|
|
453
835
|
styles: {
|
|
454
836
|
fill: {
|
|
455
837
|
'': '#white',
|
|
456
|
-
'@parent(hovered)': '#gray.05',
|
|
457
|
-
'@parent(theme=dark, >)': '#dark-02',
|
|
838
|
+
'@parent(hovered)': '#gray.05', // Any ancestor has [data-hovered]
|
|
839
|
+
'@parent(theme=dark, >)': '#dark-02', // Direct parent has [data-theme="dark"]
|
|
458
840
|
},
|
|
459
841
|
},
|
|
460
842
|
});
|
|
461
843
|
```
|
|
462
844
|
|
|
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)`
|
|
845
|
+
| Syntax | CSS Output |
|
|
846
|
+
| ------------------------------------- | -------------------------------------------------------------------------- |
|
|
847
|
+
| `@parent(hovered)` | `:where([data-hovered] *)` |
|
|
848
|
+
| `!@parent(hovered)` | `:where(:not([data-hovered] *))` |
|
|
849
|
+
| `@parent(hovered, >)` | `:where([data-hovered] > *)` (direct parent) |
|
|
850
|
+
| `@parent(.active)` | `:where(.active *)` |
|
|
851
|
+
| `@parent(hovered & focused)` | `:where([data-hovered][data-focused] *)` (same ancestor) |
|
|
852
|
+
| `@parent(hovered) & @parent(focused)` | `:where([data-hovered] *):where([data-focused] *)` (independent ancestors) |
|
|
853
|
+
| `@parent(hovered \| focused)` | `:where([data-hovered] *, [data-focused] *)` (OR inside single wrapper) |
|
|
472
854
|
|
|
473
855
|
For sub-elements, the parent check applies to the root element's ancestors:
|
|
474
856
|
|
|
@@ -483,12 +865,12 @@ const Card = tasty({
|
|
|
483
865
|
},
|
|
484
866
|
},
|
|
485
867
|
});
|
|
486
|
-
// → .t0.t0:
|
|
868
|
+
// → .t0.t0:where([data-hovered] *) [data-element="Label"]
|
|
487
869
|
```
|
|
488
870
|
|
|
489
871
|
### `:is()`, `:has()` — CSS Structural Pseudo-classes
|
|
490
872
|
|
|
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 `*`.
|
|
873
|
+
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
874
|
|
|
493
875
|
`:where()` and `:not()` are also supported but rarely needed — use `:is()` and `!` negation instead.
|
|
494
876
|
|
|
@@ -499,38 +881,38 @@ const Card = tasty({
|
|
|
499
881
|
styles: {
|
|
500
882
|
display: {
|
|
501
883
|
'': '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',
|
|
884
|
+
':has(> Icon)': 'grid', // has Icon as direct child
|
|
885
|
+
':has(+ Icon)': 'grid', // immediately followed by an Icon sibling
|
|
886
|
+
':has(~ Icon)': 'grid', // has an Icon sibling somewhere after
|
|
887
|
+
':has(Icon +)': 'grid', // immediately preceded by an Icon sibling (auto-completes to `Icon + *`)
|
|
888
|
+
':has(Icon ~)': 'grid', // has an Icon sibling somewhere before (auto-completes to `Icon ~ *`)
|
|
889
|
+
':is(fieldset > label)': 'inline', // is a label inside a fieldset (HTML tags)
|
|
890
|
+
'!:has(> Icon)': 'flex', // negation: no Icon child
|
|
509
891
|
},
|
|
510
892
|
},
|
|
511
893
|
});
|
|
512
894
|
```
|
|
513
895
|
|
|
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)`
|
|
896
|
+
| Syntax | CSS Output | Meaning |
|
|
897
|
+
| -------------------- | ------------------------------------- | --------------------------------------- |
|
|
898
|
+
| `:has(> Icon)` | `:has(> [data-element="Icon"])` | Has Icon as direct child |
|
|
899
|
+
| `:has(+ Icon)` | `:has(+ [data-element="Icon"])` | Immediately followed by an Icon sibling |
|
|
900
|
+
| `:has(~ Icon)` | `:has(~ [data-element="Icon"])` | Has an Icon sibling somewhere after |
|
|
901
|
+
| `:has(Icon +)` | `:has([data-element="Icon"] + *)` | Immediately preceded by an Icon sibling |
|
|
902
|
+
| `:has(Icon ~)` | `:has([data-element="Icon"] ~ *)` | Has an Icon sibling somewhere before |
|
|
903
|
+
| `:has(>)` | `:has(> *)` | Has any direct child |
|
|
904
|
+
| `:is(Field + input)` | `:is([data-element="Field"] + input)` | Is an input right after a Field sibling |
|
|
905
|
+
| `:has(button)` | `:has(button)` | HTML tag (lowercase, unchanged) |
|
|
906
|
+
| `!:has(> Icon)` | `:not(:has(> [data-element="Icon"]))` | Negation (use `!`) |
|
|
907
|
+
| `!:is(Panel)` | `:not([data-element="Panel"])` | Negation (use `!:is`) |
|
|
526
908
|
|
|
527
909
|
Combine with other states using boolean logic (`&`, `|`, `!`, `^`):
|
|
528
910
|
|
|
529
911
|
```jsx
|
|
530
|
-
':has(> Icon) & hovered'
|
|
531
|
-
'@parent(hovered) & :has(> Icon)'
|
|
532
|
-
':has(> Icon) | :has(> Button)'
|
|
533
|
-
':has(> Icon) ^ :has(> Button)'
|
|
912
|
+
':has(> Icon) & hovered'; // AND: structural + data attribute
|
|
913
|
+
'@parent(hovered) & :has(> Icon)'; // AND: parent check + structural
|
|
914
|
+
':has(> Icon) | :has(> Button)'; // OR: either sub-element present
|
|
915
|
+
':has(> Icon) ^ :has(> Button)'; // XOR: exactly one present
|
|
534
916
|
```
|
|
535
917
|
|
|
536
918
|
> **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 +937,8 @@ const Pulse = tasty({
|
|
|
555
937
|
});
|
|
556
938
|
```
|
|
557
939
|
|
|
940
|
+
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.
|
|
941
|
+
|
|
558
942
|
---
|
|
559
943
|
|
|
560
944
|
## Properties (`@property`)
|
|
@@ -565,39 +949,59 @@ CSS cannot transition or animate custom properties unless the browser knows thei
|
|
|
565
949
|
const AnimatedGradient = tasty({
|
|
566
950
|
styles: {
|
|
567
951
|
'$gradient-angle': '0deg',
|
|
568
|
-
'#theme': '
|
|
569
|
-
|
|
570
|
-
transition: '$$gradient-angle
|
|
952
|
+
'#theme': 'okhst(280 80% 50%)',
|
|
953
|
+
image: 'linear-gradient($gradient-angle, #theme, #clear)',
|
|
954
|
+
transition: '$$gradient-angle, ##theme',
|
|
571
955
|
},
|
|
572
956
|
});
|
|
573
957
|
```
|
|
574
958
|
|
|
575
959
|
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
960
|
|
|
577
|
-
Use explicit `@
|
|
961
|
+
Use explicit `@property` when you need non-default settings like `inherits: false`:
|
|
578
962
|
|
|
579
963
|
```jsx
|
|
580
|
-
'@
|
|
964
|
+
'@property': {
|
|
581
965
|
'$gradient-angle': { syntax: '<angle>', inherits: false, initialValue: '0deg' },
|
|
582
966
|
},
|
|
583
967
|
```
|
|
584
968
|
|
|
969
|
+
### Default properties
|
|
970
|
+
|
|
971
|
+
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.
|
|
972
|
+
|
|
973
|
+
| Token | Initial value | Read by |
|
|
974
|
+
| ---------------------------------------------------- | ---------------------------------------- | -------------------------------------------------------------- |
|
|
975
|
+
| `#current` | `currentcolor` | anything reading `$current-color`, which `color` sets |
|
|
976
|
+
| `#white`, `#black` | `rgb(255 255 255)`, `rgb(0 0 0)` | your styles |
|
|
977
|
+
| `#border` | `currentcolor` | `border` with no color |
|
|
978
|
+
| `#outline` | `currentcolor` | `outline` with no color |
|
|
979
|
+
| `$gap`, `$radius`, `$border-width`, `$outline-width` | `8px`, `6px`, `1px`, `3px` | units you point at them, as in `units: { x: 'var(--gap)' }` |
|
|
980
|
+
| `$transition` | `80ms` | `transition` with no duration |
|
|
981
|
+
| `$sharp-radius` | `0px` | the sharp corners of `radius: 'leaf'` and `radius: 'backleaf'` |
|
|
982
|
+
| `$bold-font-weight` | `700` | `preset: 'name / strong'` |
|
|
983
|
+
| `$font-sans-fallback`, `$font-mono-fallback` | a `system-ui` and a `ui-monospace` stack | `font` and presets, after `$font-sans` / `$font-mono` |
|
|
984
|
+
|
|
985
|
+
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.
|
|
986
|
+
|
|
987
|
+
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 })`.
|
|
988
|
+
|
|
585
989
|
---
|
|
586
990
|
|
|
587
|
-
## Font Face (`@
|
|
991
|
+
## Font Face (`@font-face`)
|
|
588
992
|
|
|
589
993
|
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
994
|
|
|
591
995
|
```ts
|
|
592
996
|
const Heading = tasty({
|
|
593
997
|
styles: {
|
|
594
|
-
'@
|
|
998
|
+
'@font-face': {
|
|
595
999
|
'Brand Sans': {
|
|
596
1000
|
src: 'url("/fonts/brand-sans.woff2") format("woff2")',
|
|
597
1001
|
fontDisplay: 'swap',
|
|
598
1002
|
},
|
|
599
1003
|
},
|
|
600
|
-
|
|
1004
|
+
font: '"Brand Sans", sans-serif',
|
|
601
1005
|
},
|
|
602
1006
|
});
|
|
603
1007
|
```
|
|
@@ -607,7 +1011,7 @@ const Heading = tasty({
|
|
|
607
1011
|
Supply an array to register several variants of the same family:
|
|
608
1012
|
|
|
609
1013
|
```ts
|
|
610
|
-
'@
|
|
1014
|
+
'@font-face': {
|
|
611
1015
|
'Brand Sans': [
|
|
612
1016
|
{ src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
|
|
613
1017
|
{ src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
|
|
@@ -617,34 +1021,34 @@ Supply an array to register several variants of the same family:
|
|
|
617
1021
|
|
|
618
1022
|
### Supported descriptors
|
|
619
1023
|
|
|
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`
|
|
1024
|
+
| Descriptor | CSS property | Type |
|
|
1025
|
+
| ----------------------- | ------------------------- | --------------------------------------------------------- |
|
|
1026
|
+
| `src` (required) | `src` | `string` |
|
|
1027
|
+
| `fontWeight` | `font-weight` | `string \| number` |
|
|
1028
|
+
| `fontStyle` | `font-style` | `string` |
|
|
1029
|
+
| `fontStretch` | `font-stretch` | `string` |
|
|
1030
|
+
| `fontDisplay` | `font-display` | `'auto' \| 'block' \| 'swap' \| 'fallback' \| 'optional'` |
|
|
1031
|
+
| `unicodeRange` | `unicode-range` | `string` |
|
|
1032
|
+
| `ascentOverride` | `ascent-override` | `string` |
|
|
1033
|
+
| `descentOverride` | `descent-override` | `string` |
|
|
1034
|
+
| `lineGapOverride` | `line-gap-override` | `string` |
|
|
1035
|
+
| `sizeAdjust` | `size-adjust` | `string` |
|
|
1036
|
+
| `fontFeatureSettings` | `font-feature-settings` | `string` |
|
|
1037
|
+
| `fontVariationSettings` | `font-variation-settings` | `string` |
|
|
634
1038
|
|
|
635
1039
|
> Font-face rules are permanent — they are injected once and never cleaned up, matching how browsers handle `@font-face`.
|
|
636
1040
|
|
|
637
1041
|
---
|
|
638
1042
|
|
|
639
|
-
## Counter Style (`@
|
|
1043
|
+
## Counter Style (`@counter-style`)
|
|
640
1044
|
|
|
641
1045
|
Define custom list markers via the CSS `@counter-style` at-rule. Keys are counter-style names, values are descriptor objects.
|
|
642
1046
|
|
|
643
1047
|
```ts
|
|
644
1048
|
const EmojiList = tasty({
|
|
645
|
-
|
|
1049
|
+
as: 'ol',
|
|
646
1050
|
styles: {
|
|
647
|
-
'@
|
|
1051
|
+
'@counter-style': {
|
|
648
1052
|
thumbs: {
|
|
649
1053
|
system: 'cyclic',
|
|
650
1054
|
symbols: '"👍"',
|
|
@@ -658,23 +1062,88 @@ const EmojiList = tasty({
|
|
|
658
1062
|
|
|
659
1063
|
### Supported descriptors
|
|
660
1064
|
|
|
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`
|
|
1065
|
+
| Descriptor | CSS property | Type |
|
|
1066
|
+
| ------------------- | ------------------ | ---------------------------------------------------------------------------------------- |
|
|
1067
|
+
| `system` (required) | `system` | `'cyclic' \| 'numeric' \| 'alphabetic' \| 'symbolic' \| 'additive' \| 'fixed' \| string` |
|
|
1068
|
+
| `symbols` | `symbols` | `string` |
|
|
1069
|
+
| `additiveSymbols` | `additive-symbols` | `string` |
|
|
1070
|
+
| `prefix` | `prefix` | `string` |
|
|
1071
|
+
| `suffix` | `suffix` | `string` |
|
|
1072
|
+
| `negative` | `negative` | `string` |
|
|
1073
|
+
| `range` | `range` | `string` |
|
|
1074
|
+
| `pad` | `pad` | `string` |
|
|
1075
|
+
| `fallback` | `fallback` | `string` |
|
|
1076
|
+
| `speakAs` | `speak-as` | `string` |
|
|
673
1077
|
|
|
674
1078
|
> Counter-style rules are permanent — they are injected once and never cleaned up, matching how browsers handle `@counter-style`.
|
|
675
1079
|
|
|
676
1080
|
---
|
|
677
1081
|
|
|
1082
|
+
## Functions (`@function`)
|
|
1083
|
+
|
|
1084
|
+
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.
|
|
1085
|
+
|
|
1086
|
+
The token convention follows Tasty's `$` vs `$$` distinction:
|
|
1087
|
+
|
|
1088
|
+
- **`$$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.
|
|
1089
|
+
- **`$name`** — a custom-property declaration/reference (`var(--name)`). Used for **parameters** and **local variables**, exactly like declaring custom props in a styles object.
|
|
1090
|
+
- **Local variables** are declared directly as `$name` keys on the descriptor — the body reads like a mini styles object.
|
|
1091
|
+
- `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.
|
|
1092
|
+
|
|
1093
|
+
```ts
|
|
1094
|
+
const Box = tasty({
|
|
1095
|
+
styles: {
|
|
1096
|
+
'@function': {
|
|
1097
|
+
// simplest: one bare param + result (auto-calc, no explicit calc())
|
|
1098
|
+
$$negative: { args: ['$value'], result: '(-1 * $value)' },
|
|
1099
|
+
|
|
1100
|
+
// typed param + default + return type + local variable
|
|
1101
|
+
$$shadow: {
|
|
1102
|
+
args: { '$shadow-color': { syntax: '<color>', default: 'inherit' } },
|
|
1103
|
+
returns: '<color>',
|
|
1104
|
+
$offset: '2px', // local variable
|
|
1105
|
+
result: '$offset $offset ($shadow-color, black)',
|
|
1106
|
+
},
|
|
1107
|
+
},
|
|
1108
|
+
margin: '$$negative(10px) top', // → margin: --negative(10px) 0 0 0
|
|
1109
|
+
shadow: '$$shadow(#accent)', // → box-shadow: --shadow(var(--accent-color))
|
|
1110
|
+
},
|
|
1111
|
+
});
|
|
1112
|
+
```
|
|
1113
|
+
|
|
1114
|
+
Generated CSS:
|
|
1115
|
+
|
|
1116
|
+
```css
|
|
1117
|
+
@function --negative(--value) {
|
|
1118
|
+
result: calc(-1 * var(--value));
|
|
1119
|
+
}
|
|
1120
|
+
@function --shadow(--shadow-color <color>: inherit) returns <color> {
|
|
1121
|
+
--offset: 2px;
|
|
1122
|
+
result: var(--offset) var(--offset) var(--shadow-color, black);
|
|
1123
|
+
}
|
|
1124
|
+
.t0 {
|
|
1125
|
+
margin: --negative(10px) 0 0 0;
|
|
1126
|
+
box-shadow: --shadow(var(--accent-color));
|
|
1127
|
+
}
|
|
1128
|
+
```
|
|
1129
|
+
|
|
1130
|
+
### Descriptor shape
|
|
1131
|
+
|
|
1132
|
+
| Field | Type | Notes |
|
|
1133
|
+
| ------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
1134
|
+
| `result` (required) | `string` | The `result:` value, parsed through the Tasty DSL. |
|
|
1135
|
+
| `args` | `string[]` \| `Record<string, FunctionParameter>` | Ordered parameters. Array form lists bare names; object form maps names to type/default. |
|
|
1136
|
+
| `returns` | `string` | Optional return type, e.g. `'<color>'`. |
|
|
1137
|
+
| `$name` keys | `string \| number` | Any `$name` key declares a local variable `--name` (value parsed). |
|
|
1138
|
+
|
|
1139
|
+
A `FunctionParameter` is one of: `true` (bare param), a string CSS type shorthand (`'<length>'`), or `{ syntax?: string; default?: string | number }`.
|
|
1140
|
+
|
|
1141
|
+
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).
|
|
1142
|
+
|
|
1143
|
+
> `@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.
|
|
1144
|
+
|
|
1145
|
+
---
|
|
1146
|
+
|
|
678
1147
|
## Style Properties
|
|
679
1148
|
|
|
680
1149
|
For a complete reference of all enhanced style properties — syntax, values, modifiers, and recommendations — see **[Style Properties Reference](styles.md)**.
|
|
@@ -687,4 +1156,4 @@ For a complete reference of all enhanced style properties — syntax, values, mo
|
|
|
687
1156
|
- **[Methodology](methodology.md)** — Recommended patterns: root + sub-elements, styleProps, tokens, wrapping
|
|
688
1157
|
- **[Configuration](configuration.md)** — Tokens, recipes, custom units, style handlers, TypeScript extensions
|
|
689
1158
|
- **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
|
|
690
|
-
- **[
|
|
1159
|
+
- **[Build-Time Extraction (`tastyStatic`)](tasty-static.md)** — Static styling with the Babel plugin
|