@tenphi/tasty 0.0.0-snapshot.2f99c73 → 0.0.0-snapshot.c11c8b8
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 +334 -126
- package/dist/config.d.ts +2 -1
- package/dist/config.js +8 -5
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +33 -0
- package/dist/core/index.js +26 -0
- package/dist/hooks/useStyles.js +1 -1
- package/dist/index.d.ts +16 -14
- package/dist/index.js +14 -11
- package/dist/injector/injector.js +1 -1
- package/dist/parser/parser.js +1 -1
- package/dist/pipeline/conditions.d.ts +134 -0
- package/dist/pipeline/conditions.js +14 -12
- package/dist/pipeline/conditions.js.map +1 -1
- package/dist/pipeline/index.d.ts +2 -2
- package/dist/pipeline/index.js +5 -6
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js +77 -151
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.d.ts +18 -1
- package/dist/pipeline/parseStateKey.js +3 -12
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js.map +1 -1
- package/dist/states/index.d.ts +6 -2
- package/dist/styles/index.d.ts +2 -2
- package/dist/styles/predefined.d.ts +0 -1
- package/dist/styles/types.d.ts +5 -3
- package/dist/tasty.d.ts +1 -2
- package/dist/tasty.js +3 -3
- package/dist/tasty.js.map +1 -1
- package/dist/types.d.ts +5 -3
- package/dist/utils/css-types.d.ts +7 -0
- package/dist/utils/is-valid-element-type.js +15 -0
- package/dist/utils/is-valid-element-type.js.map +1 -0
- package/dist/utils/process-tokens.d.ts +1 -1
- package/dist/utils/process-tokens.js.map +1 -1
- package/dist/utils/resolve-recipes.js +17 -13
- package/dist/utils/resolve-recipes.js.map +1 -1
- package/dist/utils/styles.js +1 -1
- package/dist/zero/extractor.d.ts +0 -1
- package/package.json +15 -10
- package/dist/chunks/cacheKey.d.ts +0 -1
- package/dist/chunks/index.d.ts +0 -3
- package/dist/chunks/renderChunk.d.ts +0 -2
- package/dist/hooks/index.d.ts +0 -5
- package/dist/parser/index.d.ts +0 -3
- package/dist/parser/index.js +0 -4
- package/dist/pipeline/exclusive.d.ts +0 -1
- package/dist/plugins/index.d.ts +0 -2
package/README.md
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
<h1 align="center">Tasty</h1>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
|
|
8
|
+
<strong>The styling engine built for design systems.</strong><br>
|
|
9
|
+
Deterministic CSS generation. State-aware DSL. Zero specificity conflicts. Ever.
|
|
9
10
|
</p>
|
|
10
11
|
|
|
11
12
|
<p align="center">
|
|
@@ -16,21 +17,21 @@
|
|
|
16
17
|
|
|
17
18
|
---
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
Most CSS-in-JS libraries generate CSS. Tasty generates **mutually exclusive CSS** — for any combination of states, exactly one rule matches per property. No cascade conflicts, no specificity wars, no `!important` hacks. Components compose and extend without breaking each other. That's the foundation everything else is built on.
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
On top of that foundation, Tasty gives you a concise, CSS-like DSL with design tokens, custom units, responsive states, container queries, dark mode, sub-element styling, and zero-runtime extraction — all in one coherent system that scales from a single component to an enterprise design system.
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- **
|
|
26
|
-
- **
|
|
27
|
-
- **
|
|
28
|
-
- **
|
|
29
|
-
- **
|
|
30
|
-
- **
|
|
31
|
-
- **
|
|
32
|
-
- **
|
|
33
|
-
- **
|
|
24
|
+
## Why Tasty
|
|
25
|
+
|
|
26
|
+
- **Deterministic at any scale** — Exclusive selector generation eliminates the entire class of cascade/specificity bugs. Every state combination resolves to exactly one CSS rule per property. Refactor freely.
|
|
27
|
+
- **DSL that feels like CSS** — Property names you already know (`padding`, `color`, `display`) with syntax sugar that removes boilerplate. Learn the DSL in minutes, not days.
|
|
28
|
+
- **Design-system native** — Color tokens (`#primary`), spacing units (`2x`), typography presets (`h1`, `t2`), border radius (`1r`), and recipes are first-class primitives, not afterthoughts.
|
|
29
|
+
- **Full modern CSS coverage** — Media queries, container queries, `@supports`, `:has()`, `@starting-style`, `@property`, keyframes, boolean state logic with `&`, `|`, `!` operators. If CSS can do it, Tasty can express it — concisely.
|
|
30
|
+
- **Runtime or zero-runtime — your call** — Use `tasty()` for dynamic React components with runtime injection, or `tastyStatic()` with the Babel plugin for zero-runtime CSS extraction. Same DSL, same tokens, same output.
|
|
31
|
+
- **Only generate what is used** — In runtime mode, Tasty injects CSS on demand for mounted components/variants, so your app avoids shipping style rules for UI states that are never rendered.
|
|
32
|
+
- **Runtime performance that holds at scale** — The runtime path is tested against enterprise-scale applications and tuned with multi-level caching, chunk-level style reuse, style garbage collection, and a dedicated injector.
|
|
33
|
+
- **Composable and extensible by design** — Extend any component's styles with proper merge semantics, and evolve built-in behavior through configuration and plugins.
|
|
34
|
+
- **TypeScript-first** — Full type definitions, module augmentation for custom properties, and autocomplete for tokens, presets, and themes.
|
|
34
35
|
|
|
35
36
|
## Installation
|
|
36
37
|
|
|
@@ -38,17 +39,9 @@ Tasty is a powerful CSS-in-JS styling system for React that combines declarative
|
|
|
38
39
|
pnpm add @tenphi/tasty
|
|
39
40
|
```
|
|
40
41
|
|
|
41
|
-
```bash
|
|
42
|
-
npm install @tenphi/tasty
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
yarn add @tenphi/tasty
|
|
47
|
-
```
|
|
48
|
-
|
|
49
42
|
## Quick Start
|
|
50
43
|
|
|
51
|
-
###
|
|
44
|
+
### Create a styled component
|
|
52
45
|
|
|
53
46
|
```tsx
|
|
54
47
|
import { tasty } from '@tenphi/tasty';
|
|
@@ -56,50 +49,68 @@ import { tasty } from '@tenphi/tasty';
|
|
|
56
49
|
const Card = tasty({
|
|
57
50
|
as: 'div',
|
|
58
51
|
styles: {
|
|
52
|
+
display: 'flex',
|
|
53
|
+
flow: 'column',
|
|
59
54
|
padding: '4x',
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
gap: '2x',
|
|
56
|
+
fill: '#surface',
|
|
57
|
+
border: '#border bottom',
|
|
58
|
+
radius: '1r',
|
|
63
59
|
},
|
|
64
60
|
});
|
|
65
61
|
|
|
62
|
+
// Just a React component
|
|
66
63
|
<Card>Hello World</Card>
|
|
67
64
|
```
|
|
68
65
|
|
|
69
|
-
|
|
66
|
+
Every value maps to CSS you'd recognize — but with tokens and units that keep your design system consistent by default.
|
|
67
|
+
|
|
68
|
+
### Add state-driven styles
|
|
70
69
|
|
|
71
70
|
```tsx
|
|
72
|
-
const
|
|
71
|
+
const Button = tasty({
|
|
72
|
+
as: 'button',
|
|
73
73
|
styles: {
|
|
74
|
+
padding: '1.5x 3x',
|
|
74
75
|
fill: {
|
|
75
|
-
'': '#
|
|
76
|
-
'
|
|
77
|
-
'
|
|
78
|
-
'
|
|
76
|
+
'': '#primary',
|
|
77
|
+
':hover': '#primary-hover',
|
|
78
|
+
':active': '#primary-pressed',
|
|
79
|
+
'[disabled]': '#surface',
|
|
79
80
|
},
|
|
80
|
-
|
|
81
|
-
'': '
|
|
82
|
-
'
|
|
81
|
+
color: {
|
|
82
|
+
'': '#on-primary',
|
|
83
|
+
'[disabled]': '#text.40',
|
|
83
84
|
},
|
|
85
|
+
cursor: {
|
|
86
|
+
'': 'pointer',
|
|
87
|
+
'[disabled]': 'not-allowed',
|
|
88
|
+
},
|
|
89
|
+
transition: 'theme',
|
|
84
90
|
},
|
|
85
91
|
});
|
|
86
92
|
```
|
|
87
93
|
|
|
88
|
-
|
|
94
|
+
State keys support pseudo-classes first (`:hover`, `:active`), then modifiers (`theme=danger`), attributes (`[disabled]`), media/container queries, root states, and more. Tasty compiles them into exclusive selectors automatically.
|
|
95
|
+
|
|
96
|
+
### Extend any component
|
|
89
97
|
|
|
90
98
|
```tsx
|
|
91
99
|
import { Button } from 'my-ui-lib';
|
|
92
100
|
|
|
93
|
-
const
|
|
101
|
+
const DangerButton = tasty(Button, {
|
|
94
102
|
styles: {
|
|
95
|
-
fill:
|
|
96
|
-
|
|
97
|
-
|
|
103
|
+
fill: {
|
|
104
|
+
'': '#danger',
|
|
105
|
+
':hover': '#danger-hover',
|
|
106
|
+
},
|
|
98
107
|
},
|
|
99
108
|
});
|
|
100
109
|
```
|
|
101
110
|
|
|
102
|
-
|
|
111
|
+
Child styles merge with parent styles intelligently — state maps can extend or replace parent states per-property.
|
|
112
|
+
|
|
113
|
+
### Configure once, use everywhere
|
|
103
114
|
|
|
104
115
|
```tsx
|
|
105
116
|
import { configure } from '@tenphi/tasty';
|
|
@@ -107,154 +118,351 @@ import { configure } from '@tenphi/tasty';
|
|
|
107
118
|
configure({
|
|
108
119
|
states: {
|
|
109
120
|
'@mobile': '@media(w < 768px)',
|
|
110
|
-
'@
|
|
121
|
+
'@tablet': '@media(w < 1024px)',
|
|
122
|
+
'@dark': '@root(schema=dark) | (!@root(schema) & @media(prefers-color-scheme: dark))',
|
|
111
123
|
},
|
|
112
124
|
recipes: {
|
|
113
|
-
card: {
|
|
114
|
-
padding: '4x',
|
|
115
|
-
fill: '#surface',
|
|
116
|
-
radius: '1r',
|
|
117
|
-
border: true,
|
|
118
|
-
},
|
|
125
|
+
card: { padding: '4x', fill: '#surface', radius: '1r', border: true },
|
|
119
126
|
},
|
|
120
127
|
});
|
|
121
128
|
```
|
|
122
129
|
|
|
123
|
-
|
|
130
|
+
Predefined states turn complex selector logic into single tokens. Use `@mobile` instead of writing media query expressions in every component.
|
|
124
131
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
| `@tenphi/tasty/static` | Build-time static style generation | Browser |
|
|
129
|
-
| `@tenphi/tasty/babel-plugin` | Babel plugin for zero-runtime | Node |
|
|
130
|
-
| `@tenphi/tasty/zero` | Programmatic extraction API | Node |
|
|
131
|
-
| `@tenphi/tasty/next` | Next.js integration wrapper | Node |
|
|
132
|
+
## How It Actually Works
|
|
133
|
+
|
|
134
|
+
This is the core idea that makes everything else possible.
|
|
132
135
|
|
|
133
|
-
|
|
136
|
+
Traditional CSS uses the cascade to resolve conflicts: when multiple selectors match, the one with the highest specificity wins, or — if specificity is equal — the last one in source order wins. This makes styles inherently fragile. Reordering imports, adding a new media query, or composing components from different libraries can silently break styling.
|
|
134
137
|
|
|
135
|
-
|
|
138
|
+
Tasty takes a fundamentally different approach: **every state mapping compiles into selectors that are guaranteed to never overlap.**
|
|
136
139
|
|
|
137
140
|
```tsx
|
|
138
|
-
const
|
|
141
|
+
const Text = tasty({
|
|
139
142
|
styles: {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
color: {
|
|
144
|
+
'': '#text',
|
|
145
|
+
'@dark': '#text-on-dark',
|
|
146
|
+
},
|
|
147
|
+
padding: {
|
|
148
|
+
'': '4x',
|
|
149
|
+
'@mobile': '2x',
|
|
150
|
+
},
|
|
145
151
|
},
|
|
146
152
|
});
|
|
147
153
|
```
|
|
148
154
|
|
|
155
|
+
If `@dark` expands to `@root(schema=dark) | (!@root(schema) & @media(prefers-color-scheme: dark))`, Tasty generates:
|
|
156
|
+
|
|
157
|
+
```css
|
|
158
|
+
/* Branch 1: Explicit dark schema */
|
|
159
|
+
:root[data-schema="dark"] .t0.t0 {
|
|
160
|
+
color: var(--text-on-dark-color);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/* Branch 2: No schema attribute + OS prefers dark */
|
|
164
|
+
@media (prefers-color-scheme: dark) {
|
|
165
|
+
:root:not([data-schema]) .t0.t0 {
|
|
166
|
+
color: var(--text-on-dark-color);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/* Default: no schema + OS does not prefer dark */
|
|
171
|
+
@media (not (prefers-color-scheme: dark)) {
|
|
172
|
+
:root:not([data-schema="dark"]) .t0.t0 {
|
|
173
|
+
color: var(--text-color);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* Default: schema is set but not dark (any OS preference) */
|
|
178
|
+
:root:not([data-schema="dark"])[data-schema] .t0.t0 {
|
|
179
|
+
color: var(--text-color);
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Every rule is guarded by the negation of all higher-priority rules. No two rules can ever match simultaneously. No specificity arithmetic. No source-order dependence. Components compose and extend without ever colliding.
|
|
184
|
+
|
|
185
|
+
## Capabilities
|
|
186
|
+
|
|
187
|
+
### Design Tokens and Custom Units
|
|
188
|
+
|
|
189
|
+
Tokens are first-class. Colors use `#name` syntax. Spacing, radius, and border width use multiplier units tied to CSS custom properties:
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
fill: '#surface', // → var(--surface-color)
|
|
193
|
+
color: '#text.80', // → 80% opacity text token
|
|
194
|
+
padding: '2x', // → calc(var(--gap) * 2)
|
|
195
|
+
radius: '1r', // → var(--radius)
|
|
196
|
+
border: '1bw solid #border',
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
| Unit | Maps to | Example |
|
|
200
|
+
|------|---------|---------|
|
|
201
|
+
| `x` | `--gap` multiplier | `2x` → `calc(var(--gap) * 2)` |
|
|
202
|
+
| `r` | `--radius` multiplier | `1r` → `var(--radius)` |
|
|
203
|
+
| `bw` | `--border-width` multiplier | `1bw` → `var(--border-width)` |
|
|
204
|
+
| `ow` | `--outline-width` multiplier | `1ow` → `var(--outline-width)` |
|
|
205
|
+
| `cr` | `--card-radius` multiplier | `1cr` → `var(--card-radius)` |
|
|
206
|
+
|
|
207
|
+
Define your own units via `configure({ units: { ... } })`.
|
|
208
|
+
|
|
209
|
+
### State System
|
|
210
|
+
|
|
211
|
+
Every style property accepts a state mapping object. Keys can be combined with boolean logic:
|
|
212
|
+
|
|
213
|
+
| State type | Syntax | CSS output |
|
|
214
|
+
|------------|--------|------------|
|
|
215
|
+
| Data attribute (boolean modifier) | `disabled` | `[data-disabled]` |
|
|
216
|
+
| Data attribute (value modifier) | `theme=danger` | `[data-theme="danger"]` |
|
|
217
|
+
| Pseudo-class | `:hover` | `:hover` |
|
|
218
|
+
| Attribute selector | `[role="tab"]` | `[role="tab"]` |
|
|
219
|
+
| Class selector (supported) | `.is-active` | `.is-active` |
|
|
220
|
+
| Media query | `@media(w < 768px)` | `@media (width < 768px)` |
|
|
221
|
+
| Container query | `@(panel, w >= 300px)` | `@container panel (width >= 300px)` |
|
|
222
|
+
| Root state | `@root(theme=dark)` | `:root[data-theme="dark"]` |
|
|
223
|
+
| Parent state | `@parent(theme=danger)` | `:is([data-theme="danger"] *)` |
|
|
224
|
+
| Feature query | `@supports(display: grid)` | `@supports (display: grid)` |
|
|
225
|
+
| Entry animation | `@starting` | `@starting-style` |
|
|
226
|
+
|
|
227
|
+
Combine with `&` (AND), `|` (OR), `!` (NOT):
|
|
228
|
+
|
|
229
|
+
```tsx
|
|
230
|
+
fill: {
|
|
231
|
+
'': '#surface',
|
|
232
|
+
'theme=danger & :hover': '#danger-hover',
|
|
233
|
+
'[aria-selected="true"]': '#accent-subtle',
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
149
237
|
### Sub-Element Styling
|
|
150
238
|
|
|
239
|
+
Style inner elements from the parent component definition. No extra components, no CSS leakage:
|
|
240
|
+
|
|
151
241
|
```tsx
|
|
152
242
|
const Card = tasty({
|
|
153
243
|
styles: {
|
|
154
244
|
padding: '4x',
|
|
155
245
|
Title: { preset: 'h3', color: '#primary' },
|
|
156
|
-
Content: { color: '#text' },
|
|
157
|
-
},
|
|
158
|
-
elements: {
|
|
159
|
-
Title: 'h2',
|
|
160
|
-
Content: 'div',
|
|
246
|
+
Content: { color: '#text', preset: 't2' },
|
|
161
247
|
},
|
|
248
|
+
elements: { Title: 'h2', Content: 'div' },
|
|
162
249
|
});
|
|
163
250
|
|
|
164
251
|
<Card>
|
|
165
|
-
<Card.Title>
|
|
166
|
-
<Card.Content>
|
|
252
|
+
<Card.Title>Heading</Card.Title>
|
|
253
|
+
<Card.Content>Body text</Card.Content>
|
|
167
254
|
</Card>
|
|
168
255
|
```
|
|
169
256
|
|
|
170
|
-
|
|
257
|
+
Sub-elements use `data-element` attributes — no extra class names, no naming conventions.
|
|
258
|
+
|
|
259
|
+
By default, sub-elements participate in the same state context as the root component. That means mappings like `:hover`, `theme=danger`, `[role="button"]`, and other keys are evaluated as one unified block, which keeps styling logic predictable across the whole markup tree.
|
|
260
|
+
|
|
261
|
+
Use `@own(...)` when a sub-element should react to its own state instead of the root state context.
|
|
262
|
+
|
|
263
|
+
Class selectors are also supported, but modifiers/pseudo-classes are usually the better default in design-system code.
|
|
264
|
+
|
|
265
|
+
Use the sub-element selector `$` when you need precise descendant targeting to avoid leakage in deeply nested component trees.
|
|
266
|
+
|
|
267
|
+
### Variants
|
|
268
|
+
|
|
269
|
+
Variants are designed to keep single-component CSS lean. Instead of generating dozens of static button classes up front, define all versions once and let runtime usage decide what CSS is actually emitted.
|
|
270
|
+
|
|
271
|
+
```tsx
|
|
272
|
+
const Button = tasty({
|
|
273
|
+
styles: { padding: '2x 4x', radius: '1r' },
|
|
274
|
+
variants: {
|
|
275
|
+
default: { fill: '#primary', color: '#on-primary' },
|
|
276
|
+
danger: { fill: '#danger', color: '#on-danger' },
|
|
277
|
+
outline: { fill: 'transparent', border: '1bw solid #primary' },
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
<Button variant="danger">Delete</Button>
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Recipes
|
|
285
|
+
|
|
286
|
+
Recipes are predefined style sets that work like composable styling classes for Tasty. They can be pre-applied or post-applied to current styles, which lets you add reusable state logic while still allowing local style overrides.
|
|
171
287
|
|
|
172
288
|
```tsx
|
|
173
|
-
|
|
289
|
+
configure({
|
|
290
|
+
recipes: {
|
|
291
|
+
card: { padding: '4x', fill: '#surface', radius: '1r', border: true },
|
|
292
|
+
elevated: { shadow: '0 2x 4x #shadow' },
|
|
293
|
+
},
|
|
294
|
+
});
|
|
174
295
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
296
|
+
const ProfileCard = tasty({
|
|
297
|
+
styles: {
|
|
298
|
+
recipe: 'card elevated',
|
|
299
|
+
color: '#text',
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
```
|
|
180
303
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
304
|
+
Use `/` to post-apply recipes after local styles when you need recipe states/styles to win the final merge order. Use `none` to skip base recipes: `recipe: 'none / disabled'`.
|
|
305
|
+
|
|
306
|
+
### Keyframes and `@property`
|
|
307
|
+
|
|
308
|
+
Modern CSS features are natively supported:
|
|
309
|
+
|
|
310
|
+
Color tokens are automatically registered as typed properties (`<color>`), so token-based transitions work without extra setup.
|
|
311
|
+
|
|
312
|
+
```tsx
|
|
313
|
+
const Pulse = tasty({
|
|
314
|
+
styles: {
|
|
315
|
+
'@properties': {
|
|
316
|
+
'$pulse-scale': {
|
|
317
|
+
syntax: '<number>',
|
|
318
|
+
inherits: false,
|
|
319
|
+
initialValue: 1,
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
animation: 'pulse 2s infinite',
|
|
323
|
+
transform: 'scale($pulse-scale)',
|
|
324
|
+
'@keyframes': {
|
|
325
|
+
pulse: {
|
|
326
|
+
'0%, 100%': { '$pulse-scale': 1 },
|
|
327
|
+
'50%': { '$pulse-scale': 1.05 },
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### React Hooks
|
|
335
|
+
|
|
336
|
+
For cases where you don't need a full component:
|
|
337
|
+
|
|
338
|
+
```tsx
|
|
339
|
+
import { useStyles, useGlobalStyles, useRawCSS } from '@tenphi/tasty';
|
|
185
340
|
|
|
186
|
-
|
|
341
|
+
function App() {
|
|
342
|
+
const { className } = useStyles({ padding: '2x', fill: '#surface' });
|
|
343
|
+
useGlobalStyles(':root', { '#primary': 'purple', '$gap': '8px' });
|
|
344
|
+
useRawCSS('body { margin: 0; }');
|
|
345
|
+
|
|
346
|
+
return <main className={className}>...</main>;
|
|
187
347
|
}
|
|
188
348
|
```
|
|
189
349
|
|
|
190
350
|
### Zero-Runtime Mode
|
|
191
351
|
|
|
352
|
+
Extract all CSS at build time. Zero JavaScript overhead in production:
|
|
353
|
+
|
|
192
354
|
```tsx
|
|
193
355
|
import { tastyStatic } from '@tenphi/tasty/static';
|
|
194
356
|
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
color: '#
|
|
357
|
+
const card = tastyStatic({
|
|
358
|
+
padding: '4x',
|
|
359
|
+
fill: '#surface',
|
|
360
|
+
radius: '1r',
|
|
361
|
+
color: { '': '#text', '@dark': '#text-on-dark' },
|
|
200
362
|
});
|
|
201
363
|
|
|
202
|
-
|
|
364
|
+
// card is a CSS class name string
|
|
365
|
+
<div className={card}>Static styles, zero runtime</div>
|
|
203
366
|
```
|
|
204
367
|
|
|
205
368
|
Configure the Babel plugin:
|
|
206
369
|
|
|
207
370
|
```js
|
|
208
|
-
// babel.config.js
|
|
209
371
|
module.exports = {
|
|
210
372
|
plugins: [
|
|
211
|
-
['@tenphi/tasty/babel-plugin', {
|
|
373
|
+
['@tenphi/tasty/babel-plugin', {
|
|
374
|
+
output: 'public/tasty.css',
|
|
375
|
+
config: {
|
|
376
|
+
states: { '@dark': '@root(theme=dark)' },
|
|
377
|
+
},
|
|
378
|
+
}],
|
|
212
379
|
],
|
|
213
380
|
};
|
|
214
381
|
```
|
|
215
382
|
|
|
216
|
-
|
|
383
|
+
### `tasty` vs `tastyStatic`
|
|
384
|
+
|
|
385
|
+
| | `tasty` (runtime) | `tastyStatic` (zero-runtime) |
|
|
386
|
+
|---|---|---|
|
|
387
|
+
| **Output** | React component | CSS class name |
|
|
388
|
+
| **CSS injection** | Runtime `<style>` tags | Build-time extraction |
|
|
389
|
+
| **Runtime cost** | Style generation on mount | None |
|
|
390
|
+
| **Generated CSS scope** | Only styles/variants used at runtime | All extracted static styles at build time |
|
|
391
|
+
| **Dynamic values** | Fully supported | Via CSS custom properties |
|
|
392
|
+
| **Sub-elements** | Built-in (`<C.Title>`) | Manual (`data-element`) |
|
|
393
|
+
| **Variants** | Built-in (`variants` option) | Separate static styles |
|
|
394
|
+
| **Framework** | React | Any (requires Babel) |
|
|
395
|
+
| **Best for** | Interactive apps, design systems | Static sites, SSG, landing pages |
|
|
396
|
+
|
|
397
|
+
Both share the same DSL, tokens, units, state mappings, and recipes.
|
|
398
|
+
|
|
399
|
+
### Runtime Performance
|
|
400
|
+
|
|
401
|
+
If you choose the runtime approach, performance is usually a non-issue in practice:
|
|
402
|
+
|
|
403
|
+
- CSS is generated and injected only when styles are actually used.
|
|
404
|
+
- Multi-level caching avoids repeated parsing and style recomputation.
|
|
405
|
+
- Styles are split into reusable chunks and applied as multiple class names, so matching chunks can be reused across components instead of re-injected.
|
|
406
|
+
- Style normalization guarantees equivalent style input resolves to the same chunks, improving deduplication hit rates.
|
|
407
|
+
- A style garbage collector removes unused styles/chunks over time.
|
|
408
|
+
- A dedicated style injector minimizes DOM/style-tag overhead.
|
|
409
|
+
- This approach is validated in enterprise-scale apps where runtime styling overhead is not noticeable in normal UI flows.
|
|
410
|
+
|
|
411
|
+
## Entry Points
|
|
412
|
+
|
|
413
|
+
| Import | Description | Platform |
|
|
414
|
+
|--------|-------------|----------|
|
|
415
|
+
| `@tenphi/tasty` | Runtime style engine | Browser |
|
|
416
|
+
| `@tenphi/tasty/static` | Zero-runtime static styles | Browser |
|
|
417
|
+
| `@tenphi/tasty/babel-plugin` | Babel plugin for CSS extraction | Node |
|
|
418
|
+
| `@tenphi/tasty/zero` | Programmatic extraction API | Node |
|
|
419
|
+
| `@tenphi/tasty/next` | Next.js integration | Node |
|
|
217
420
|
|
|
218
|
-
|
|
219
|
-
|------|-------------|---------|------------|
|
|
220
|
-
| `x` | Gap multiplier | `2x` | `calc(var(--gap) * 2)` |
|
|
221
|
-
| `r` | Border radius | `1r` | `var(--radius)` |
|
|
222
|
-
| `cr` | Card border radius | `1cr` | `var(--card-radius)` |
|
|
223
|
-
| `bw` | Border width | `2bw` | `calc(var(--border-width) * 2)` |
|
|
224
|
-
| `ow` | Outline width | `1ow` | `var(--outline-width)` |
|
|
225
|
-
| `fs` | Font size | `1fs` | `var(--font-size)` |
|
|
226
|
-
| `lh` | Line height | `1lh` | `var(--line-height)` |
|
|
227
|
-
| `sf` | Stable fraction | `1sf` | `minmax(0, 1fr)` |
|
|
421
|
+
## Ecosystem
|
|
228
422
|
|
|
229
|
-
|
|
423
|
+
Tasty is the core of a production-ready styling platform. These companion tools complete the picture:
|
|
230
424
|
|
|
231
|
-
|
|
425
|
+
### [ESLint Plugin](https://github.com/tenphi/eslint-plugin-tasty)
|
|
232
426
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
427
|
+
`@tenphi/eslint-plugin-tasty` — 27 lint rules that validate style property names, value syntax, token existence, state keys, and enforce best practices. Catch typos and invalid styles at lint time, not at runtime.
|
|
428
|
+
|
|
429
|
+
```bash
|
|
430
|
+
pnpm add -D @tenphi/eslint-plugin-tasty
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
```js
|
|
434
|
+
import tasty from '@tenphi/eslint-plugin-tasty';
|
|
435
|
+
export default [tasty.configs.recommended];
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
### [Glaze](https://github.com/tenphi/glaze)
|
|
439
|
+
|
|
440
|
+
`@tenphi/glaze` — OKHSL-based color theme generator with automatic WCAG contrast solving. Generate light, dark, and high-contrast palettes from a single hue, and export them directly as Tasty color tokens.
|
|
441
|
+
|
|
442
|
+
```tsx
|
|
443
|
+
import { glaze } from '@tenphi/glaze';
|
|
444
|
+
|
|
445
|
+
const theme = glaze(280, 80);
|
|
446
|
+
theme.colors({
|
|
447
|
+
surface: { lightness: 97 },
|
|
448
|
+
text: { base: 'surface', lightness: '-52', contrast: 'AAA' },
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
const tokens = theme.tasty(); // Ready-to-use Tasty tokens
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### [VS Code Extension](https://github.com/tenphi/tasty-vscode-extension)
|
|
455
|
+
|
|
456
|
+
Syntax highlighting for Tasty styles in TypeScript, TSX, JavaScript, and JSX. Highlights color tokens, custom units, state keys, presets, and style properties inside `tasty()`, `tastyStatic()`, and related APIs.
|
|
457
|
+
|
|
458
|
+
### [Cube UI Kit](https://github.com/cube-js/cube-ui-kit)
|
|
459
|
+
|
|
460
|
+
Open-source React UI kit built on Tasty + React Aria. 100+ production components proving Tasty works at design-system scale. A reference implementation and a ready-to-use component library.
|
|
253
461
|
|
|
254
462
|
## Documentation
|
|
255
463
|
|
|
256
|
-
- [Runtime API (tasty)](docs/tasty.md) — Full runtime styling documentation
|
|
257
|
-
- [Zero Runtime (tastyStatic)](docs/tasty-static.md) — Build-time static styling
|
|
464
|
+
- **[Runtime API (tasty)](docs/tasty.md)** — Full runtime styling documentation: component creation, state mappings, sub-elements, variants, hooks, configuration, and style property reference
|
|
465
|
+
- **[Zero Runtime (tastyStatic)](docs/tasty-static.md)** — Build-time static styling: Babel plugin setup, Next.js integration, and static style patterns
|
|
258
466
|
|
|
259
467
|
## License
|
|
260
468
|
|
package/dist/config.d.ts
CHANGED
|
@@ -178,7 +178,8 @@ interface TastyConfig {
|
|
|
178
178
|
* tokens (`$name`/`#name` definitions), local states, `@keyframes`, and `@properties`.
|
|
179
179
|
*
|
|
180
180
|
* Components reference recipes via: `recipe: 'name1 name2'` in their styles.
|
|
181
|
-
* Use
|
|
181
|
+
* Use `/` to separate base recipes from post recipes: `recipe: 'base1 base2 / post1'`.
|
|
182
|
+
* Use `none` to skip base recipes: `recipe: 'none / post1'`.
|
|
182
183
|
* Resolution order: `base_recipes → component styles → post_recipes`.
|
|
183
184
|
*
|
|
184
185
|
* Recipes cannot reference other recipes.
|
package/dist/config.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CUSTOM_UNITS, getGlobalFuncs, getGlobalParser, normalizeColorTokenValue, resetGlobalPredefinedTokens, setGlobalPredefinedTokens } from "./utils/styles.js";
|
|
2
1
|
import { isDevEnv } from "./utils/is-dev-env.js";
|
|
2
|
+
import { setGlobalPredefinedStates } from "./states/index.js";
|
|
3
|
+
import { CUSTOM_UNITS, getGlobalFuncs, getGlobalParser, normalizeColorTokenValue, resetGlobalPredefinedTokens, setGlobalPredefinedTokens } from "./utils/styles.js";
|
|
3
4
|
import { normalizeHandlerDefinition, registerHandler, resetHandlers } from "./styles/predefined.js";
|
|
4
5
|
import { StyleInjector } from "./injector/injector.js";
|
|
5
|
-
import { setGlobalPredefinedStates } from "./states/index.js";
|
|
6
6
|
import { clearPipelineCache, isSelector } from "./pipeline/index.js";
|
|
7
7
|
|
|
8
8
|
//#region src/config.ts
|
|
@@ -223,9 +223,12 @@ function setGlobalRecipes(recipes) {
|
|
|
223
223
|
warnOnce("recipes-after-styles", "[Tasty] Cannot update recipes after styles have been generated.\nThe new recipes will be ignored.");
|
|
224
224
|
return;
|
|
225
225
|
}
|
|
226
|
-
if (devMode) for (const [name, recipeStyles] of Object.entries(recipes))
|
|
227
|
-
if (
|
|
228
|
-
|
|
226
|
+
if (devMode) for (const [name, recipeStyles] of Object.entries(recipes)) {
|
|
227
|
+
if (name === "none") warnOnce("recipe-reserved-none", "[Tasty] Recipe name \"none\" is reserved. It is used as a keyword meaning \"no base recipes\" (e.g. recipe: 'none / post-recipe'). Choose a different name for your recipe.");
|
|
228
|
+
for (const key of Object.keys(recipeStyles)) {
|
|
229
|
+
if (isSelector(key)) warnOnce(`recipe-selector-${name}-${key}`, `[Tasty] Recipe "${name}" contains sub-element key "${key}". Recipes must be flat styles without sub-element keys. Remove the sub-element key from the recipe definition.`);
|
|
230
|
+
if (key === "recipe") warnOnce(`recipe-recursive-${name}`, `[Tasty] Recipe "${name}" contains a "recipe" key. Recipes cannot reference other recipes. Use space-separated names for composition: recipe: 'base elevated'.`);
|
|
231
|
+
}
|
|
229
232
|
}
|
|
230
233
|
globalRecipes = recipes;
|
|
231
234
|
}
|