@tenphi/tasty 0.0.0-snapshot.2f99c73 → 0.0.0-snapshot.31f6dd6

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.
Files changed (117) hide show
  1. package/README.md +411 -126
  2. package/dist/config.d.ts +10 -1
  3. package/dist/config.js +8 -5
  4. package/dist/config.js.map +1 -1
  5. package/dist/core/index.d.ts +33 -0
  6. package/dist/core/index.js +26 -0
  7. package/dist/debug.js +1 -1
  8. package/dist/debug.js.map +1 -1
  9. package/dist/hooks/useStyles.js +5 -5
  10. package/dist/hooks/useStyles.js.map +1 -1
  11. package/dist/index.d.ts +24 -14
  12. package/dist/index.js +14 -11
  13. package/dist/injector/injector.js +38 -16
  14. package/dist/injector/injector.js.map +1 -1
  15. package/dist/injector/sheet-manager.d.ts +12 -4
  16. package/dist/injector/sheet-manager.js +23 -9
  17. package/dist/injector/sheet-manager.js.map +1 -1
  18. package/dist/injector/types.d.ts +9 -0
  19. package/dist/parser/parser.js +1 -1
  20. package/dist/pipeline/conditions.d.ts +134 -0
  21. package/dist/pipeline/conditions.js +28 -20
  22. package/dist/pipeline/conditions.js.map +1 -1
  23. package/dist/pipeline/index.d.ts +2 -2
  24. package/dist/pipeline/index.js +64 -46
  25. package/dist/pipeline/index.js.map +1 -1
  26. package/dist/pipeline/materialize.js +250 -300
  27. package/dist/pipeline/materialize.js.map +1 -1
  28. package/dist/pipeline/parseStateKey.d.ts +15 -1
  29. package/dist/pipeline/parseStateKey.js +26 -27
  30. package/dist/pipeline/parseStateKey.js.map +1 -1
  31. package/dist/pipeline/simplify.js +111 -152
  32. package/dist/pipeline/simplify.js.map +1 -1
  33. package/dist/pipeline/warnings.js +18 -0
  34. package/dist/pipeline/warnings.js.map +1 -0
  35. package/dist/properties/index.js +82 -3
  36. package/dist/properties/index.js.map +1 -1
  37. package/dist/properties/property-type-resolver.d.ts +24 -0
  38. package/dist/properties/property-type-resolver.js +79 -0
  39. package/dist/properties/property-type-resolver.js.map +1 -0
  40. package/dist/states/index.d.ts +6 -2
  41. package/dist/styles/align.d.ts +1 -1
  42. package/dist/styles/align.js.map +1 -1
  43. package/dist/styles/border.d.ts +1 -1
  44. package/dist/styles/border.js.map +1 -1
  45. package/dist/styles/color.d.ts +2 -2
  46. package/dist/styles/color.js.map +1 -1
  47. package/dist/styles/createStyle.js +1 -1
  48. package/dist/styles/createStyle.js.map +1 -1
  49. package/dist/styles/fade.d.ts +1 -1
  50. package/dist/styles/fade.js.map +1 -1
  51. package/dist/styles/fill.d.ts +14 -16
  52. package/dist/styles/fill.js +6 -5
  53. package/dist/styles/fill.js.map +1 -1
  54. package/dist/styles/flow.d.ts +3 -3
  55. package/dist/styles/flow.js.map +1 -1
  56. package/dist/styles/index.d.ts +2 -2
  57. package/dist/styles/inset.d.ts +3 -1
  58. package/dist/styles/inset.js +48 -40
  59. package/dist/styles/inset.js.map +1 -1
  60. package/dist/styles/justify.d.ts +1 -1
  61. package/dist/styles/justify.js.map +1 -1
  62. package/dist/styles/margin.d.ts +1 -5
  63. package/dist/styles/margin.js +48 -40
  64. package/dist/styles/margin.js.map +1 -1
  65. package/dist/styles/padding.d.ts +1 -5
  66. package/dist/styles/padding.js +48 -40
  67. package/dist/styles/padding.js.map +1 -1
  68. package/dist/styles/predefined.d.ts +0 -1
  69. package/dist/styles/predefined.js.map +1 -1
  70. package/dist/styles/radius.d.ts +1 -1
  71. package/dist/styles/radius.js.map +1 -1
  72. package/dist/styles/scrollbar.d.ts +1 -1
  73. package/dist/styles/scrollbar.js +19 -12
  74. package/dist/styles/scrollbar.js.map +1 -1
  75. package/dist/styles/shadow.d.ts +2 -2
  76. package/dist/styles/shadow.js.map +1 -1
  77. package/dist/styles/styledScrollbar.d.ts +1 -1
  78. package/dist/styles/styledScrollbar.js.map +1 -1
  79. package/dist/styles/transition.d.ts +1 -1
  80. package/dist/styles/transition.js +26 -6
  81. package/dist/styles/transition.js.map +1 -1
  82. package/dist/styles/types.d.ts +5 -3
  83. package/dist/tasty.d.ts +1 -2
  84. package/dist/tasty.js +19 -4
  85. package/dist/tasty.js.map +1 -1
  86. package/dist/types.d.ts +6 -4
  87. package/dist/utils/colors.d.ts +1 -1
  88. package/dist/utils/colors.js.map +1 -1
  89. package/dist/utils/css-types.d.ts +7 -0
  90. package/dist/utils/dotize.d.ts +1 -1
  91. package/dist/utils/is-valid-element-type.js +15 -0
  92. package/dist/utils/is-valid-element-type.js.map +1 -0
  93. package/dist/utils/mod-attrs.js.map +1 -1
  94. package/dist/utils/process-tokens.d.ts +1 -1
  95. package/dist/utils/process-tokens.js.map +1 -1
  96. package/dist/utils/resolve-recipes.js +17 -13
  97. package/dist/utils/resolve-recipes.js.map +1 -1
  98. package/dist/utils/string.js.map +1 -1
  99. package/dist/utils/styles.d.ts +7 -12
  100. package/dist/utils/styles.js +175 -9
  101. package/dist/utils/styles.js.map +1 -1
  102. package/dist/zero/babel.d.ts +5 -0
  103. package/dist/zero/babel.js +13 -7
  104. package/dist/zero/babel.js.map +1 -1
  105. package/dist/zero/extractor.d.ts +0 -1
  106. package/dist/zero/extractor.js +66 -1
  107. package/dist/zero/extractor.js.map +1 -1
  108. package/package.json +69 -13
  109. package/tasty.config.ts +14 -0
  110. package/dist/chunks/cacheKey.d.ts +0 -1
  111. package/dist/chunks/index.d.ts +0 -3
  112. package/dist/chunks/renderChunk.d.ts +0 -2
  113. package/dist/hooks/index.d.ts +0 -5
  114. package/dist/parser/index.d.ts +0 -3
  115. package/dist/parser/index.js +0 -4
  116. package/dist/pipeline/exclusive.d.ts +0 -1
  117. 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
- A design-system-integrated styling system and DSL for concise, state-aware UI styling
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,23 @@
16
17
 
17
18
  ---
18
19
 
19
- Tasty is a powerful CSS-in-JS styling system for React that combines declarative state-aware styling with design system integration. It provides a concise DSL for creating maintainable, themeable components with built-in support for responsive design, dark mode, container queries, and more.
20
+ Most CSS-in-JS libraries emit rules that compete through cascade and specificity. Tasty emits **mutually exclusive CSS selectors** for any component state combination, exactly one selector matches each property at a time. No cascade conflicts, no specificity wars, no `!important` escapes. Components compose and extend without breaking each other.
20
21
 
21
- ## Features
22
+ That guarantee unlocks a concise, CSS-like DSL where design tokens, custom units, responsive states, container queries, sub-element styling, and theming all compose without surprises — one coherent system that scales from a single component to an enterprise design system.
22
23
 
23
- - **Declarative state-aware styling** — style objects with state keys (`hovered`, `disabled`, `@media`, `@root`, etc.)
24
- - **Design token integration** — color tokens (`#purple`), custom units (`2x`, `1r`), typography presets
25
- - **Sub-element styling** — style inner elements via capitalized keys with `data-element` attributes
26
- - **Advanced state mapping** — media queries, container queries, root states, supports queries with boolean logic
27
- - **Zero-runtime mode** — Babel plugin extracts CSS at build time for static sites
28
- - **Plugin system** — extensible with custom color functions (OKHSL, etc.)
29
- - **React hooks** — `useStyles`, `useGlobalStyles`, `useRawCSS` for programmatic style injection
30
- - **Style extension** — compose and extend styled components with proper merge semantics
31
- - **Recipes** — named style bundles for reusable patterns
32
- - **TypeScript-first** — full type definitions with module augmentation support
33
- - **Tree-shakeable ESM** — unbundled output with `sideEffects: false`
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. See [How It Actually Works](#how-it-actually-works).
27
+ - **AI-friendly by design** — Style definitions are declarative, self-contained, and structurally consistent. AI tools can read, understand, and refactor even advanced state bindings as confidently as a human — because there's no hidden cascade logic or implicit ordering to second-guess.
28
+ - **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. See [Style Properties](docs/styles.md).
29
+ - **CSS properties as normal component props** — `styleProps` lets you expose selected styles as typed React props. Use `<Button placeSelf="end">` or `<Space flow="row" gap="2x">` without extra wrappers, utility classes, or `styles` overrides. The same props also accept state maps, so responsive values work with the same API. See [CSS properties as props](#css-properties-as-props).
30
+ - **Design-system native** — Color tokens (`#primary`), spacing units (`2x`), typography presets (`h1`, `t2`), border radius (`1r`), and recipes are first-class primitives, not afterthoughts. See [Configuration](docs/configuration.md).
31
+ - **Near-complete modern CSS coverage** — Media queries, container queries, `@supports`, `:has()`, `@starting-style`, `@property`, `@keyframes`, etc. Some features that don't fit Tasty's component model (such as `@layer` and `!important`) are intentionally omitted, but real-world use cases are covered almost completely.
32
+ - **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. See [Zero Runtime](docs/tasty-static.md).
33
+ - **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.
34
+ - **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.
35
+ - **Composable and extensible by design** — Extend any component's styles with proper merge semantics, and evolve built-in behavior through configuration and plugins.
36
+ - **TypeScript-first** — Full type definitions, module augmentation for custom properties, and autocomplete for tokens, presets, and themes. See [Configuration](docs/configuration.md).
34
37
 
35
38
  ## Installation
36
39
 
@@ -38,17 +41,9 @@ Tasty is a powerful CSS-in-JS styling system for React that combines declarative
38
41
  pnpm add @tenphi/tasty
39
42
  ```
40
43
 
41
- ```bash
42
- npm install @tenphi/tasty
43
- ```
44
-
45
- ```bash
46
- yarn add @tenphi/tasty
47
- ```
48
-
49
44
  ## Quick Start
50
45
 
51
- ### Creating Styled Components
46
+ ### Create a styled component
52
47
 
53
48
  ```tsx
54
49
  import { tasty } from '@tenphi/tasty';
@@ -56,50 +51,68 @@ import { tasty } from '@tenphi/tasty';
56
51
  const Card = tasty({
57
52
  as: 'div',
58
53
  styles: {
54
+ display: 'flex',
55
+ flow: 'column',
59
56
  padding: '4x',
60
- fill: '#white',
61
- border: true,
62
- radius: true,
57
+ gap: '2x',
58
+ fill: '#surface',
59
+ border: '#border bottom',
60
+ radius: '1r',
63
61
  },
64
62
  });
65
63
 
64
+ // Just a React component
66
65
  <Card>Hello World</Card>
67
66
  ```
68
67
 
69
- ### State-Based Styling
68
+ Every value maps to CSS you'd recognize — but with tokens and units that keep your design system consistent by default.
69
+
70
+ ### Add state-driven styles
70
71
 
71
72
  ```tsx
72
- const InteractiveCard = tasty({
73
+ const Button = tasty({
74
+ as: 'button',
73
75
  styles: {
76
+ padding: '1.5x 3x',
74
77
  fill: {
75
- '': '#white',
76
- 'hovered': '#gray.05',
77
- 'pressed': '#gray.10',
78
- '@media(w < 768px)': '#surface',
78
+ '': '#primary',
79
+ ':hover': '#primary-hover',
80
+ ':active': '#primary-pressed',
81
+ '[disabled]': '#surface',
79
82
  },
80
- padding: {
81
- '': '4x',
82
- '@media(w < 768px)': '2x',
83
+ color: {
84
+ '': '#on-primary',
85
+ '[disabled]': '#text.40',
86
+ },
87
+ cursor: {
88
+ '': 'pointer',
89
+ '[disabled]': 'not-allowed',
83
90
  },
91
+ transition: 'theme',
84
92
  },
85
93
  });
86
94
  ```
87
95
 
88
- ### Extending Components
96
+ 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.
97
+
98
+ ### Extend any component
89
99
 
90
100
  ```tsx
91
101
  import { Button } from 'my-ui-lib';
92
102
 
93
- const PrimaryButton = tasty(Button, {
103
+ const DangerButton = tasty(Button, {
94
104
  styles: {
95
- fill: '#purple',
96
- color: '#white',
97
- padding: '2x 4x',
105
+ fill: {
106
+ '': '#danger',
107
+ ':hover': '#danger-hover',
108
+ },
98
109
  },
99
110
  });
100
111
  ```
101
112
 
102
- ### Configuration
113
+ Child styles merge with parent styles intelligently — state maps can extend or replace parent states per-property.
114
+
115
+ ### Configure once, use everywhere
103
116
 
104
117
  ```tsx
105
118
  import { configure } from '@tenphi/tasty';
@@ -107,154 +120,426 @@ import { configure } from '@tenphi/tasty';
107
120
  configure({
108
121
  states: {
109
122
  '@mobile': '@media(w < 768px)',
110
- '@dark': '@root(theme=dark)',
123
+ '@tablet': '@media(w < 1024px)',
124
+ '@dark': '@root(schema=dark) | (!@root(schema) & @media(prefers-color-scheme: dark))',
111
125
  },
112
126
  recipes: {
113
- card: {
114
- padding: '4x',
115
- fill: '#surface',
116
- radius: '1r',
117
- border: true,
118
- },
127
+ card: { padding: '4x', fill: '#surface', radius: '1r', border: true },
119
128
  },
120
129
  });
121
130
  ```
122
131
 
123
- ## Entry Points
132
+ Predefined states turn complex selector logic into single tokens. Use `@mobile` instead of writing media query expressions in every component.
124
133
 
125
- | Import | Description | Platform |
126
- |--------|-------------|----------|
127
- | `@tenphi/tasty` | Runtime style engine | Browser |
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 |
134
+ ### CSS properties as props
132
135
 
133
- ## Core Concepts
136
+ With `styleProps`, a component can expose the styles you choose as normal typed props. That means you can adjust layout, spacing, alignment, or positioning right where the component is used, instead of introducing wrapper elements or reaching for a separate styling API.
134
137
 
135
- ### Design Tokens
138
+ This is especially good for prototyping and fast UI iteration: you can shape interfaces quickly, while still staying inside a typed, design-system-aware component API that scales to production.
136
139
 
137
140
  ```tsx
138
- const TokenCard = tasty({
141
+ import { tasty, FLOW_STYLES, POSITION_STYLES } from '@tenphi/tasty';
142
+
143
+ const Space = tasty({
139
144
  styles: {
140
- fill: '#surface', // Color token → var(--surface-color)
141
- color: '#text', // Color token
142
- padding: '2x', // Gap multiplier → calc(var(--gap) * 2)
143
- radius: '1r', // Border radius → var(--radius)
144
- border: '1bw solid #border',
145
+ display: 'flex',
146
+ flow: 'column',
147
+ gap: '1x',
145
148
  },
149
+ styleProps: FLOW_STYLES,
146
150
  });
151
+
152
+ const Button = tasty({
153
+ as: 'button',
154
+ styles: {
155
+ padding: '1.5x 3x',
156
+ fill: '#primary',
157
+ color: '#primary-text',
158
+ radius: true,
159
+ },
160
+ styleProps: POSITION_STYLES,
161
+ });
162
+ ```
163
+
164
+ Now you can compose layout and tweak component positioning directly in JSX:
165
+
166
+ ```tsx
167
+ <Space flow="row" gap="2x" placeItems="center">
168
+ <Title>Dashboard</Title>
169
+ <Button placeSelf="end">Add Item</Button>
170
+ </Space>
171
+ ```
172
+
173
+ The same props also support state maps, so responsive values use the exact same API:
174
+
175
+ ```tsx
176
+ <Space
177
+ flow={{ '': 'column', '@tablet': 'row' }}
178
+ gap={{ '': '2x', '@tablet': '4x' }}
179
+ >
180
+ <Sidebar />
181
+ <Content />
182
+ </Space>
183
+ ```
184
+
185
+ Layout components can expose flow props. Buttons can expose positioning props. Each component can offer only the style props that make sense for its role, while still keeping tokens, custom units, and state maps fully typed. This works in runtime `tasty()` components, not in `tastyStatic()`.
186
+
187
+ ## How It Actually Works
188
+
189
+ This is the core idea that makes everything else possible.
190
+
191
+ Traditional CSS has two structural problems.
192
+
193
+ First, the **cascade** resolves conflicts by specificity and source order: when multiple selectors match, the one with the highest specificity wins, or — if specificity is equal — the last one in source order wins. That makes styles inherently fragile. Reordering imports, adding a media query, or composing components from different libraries can silently break styling.
194
+
195
+ Second, **authoring selectors that capture real-world state logic is fundamentally hard.** A single state like "dark mode" may depend on a root attribute, an OS preference, or both — each branch needing its own selector, proper negation of competing branches, and correct `@media` nesting. The example below shows the CSS you'd write by hand for just *one* property with *one* state. Scale that across dozens of properties, then add breakpoints and container queries, and the selector logic quickly becomes unmanageable.
196
+
197
+ Tasty solves both problems at once: **every state mapping compiles into mutually exclusive selectors.**
198
+
199
+ ```tsx
200
+ const Text = tasty({
201
+ styles: {
202
+ color: {
203
+ '': '#text',
204
+ '@dark': '#text-on-dark',
205
+ },
206
+ padding: {
207
+ '': '4x',
208
+ '@mobile': '2x',
209
+ },
210
+ },
211
+ });
212
+ ```
213
+
214
+ If `@dark` expands to `@root(schema=dark) | (!@root(schema) & @media(prefers-color-scheme: dark))`, Tasty generates:
215
+
216
+ ```css
217
+ /* Branch 1: Explicit dark schema */
218
+ :root[data-schema="dark"] .t0.t0 {
219
+ color: var(--text-on-dark-color);
220
+ }
221
+
222
+ /* Branch 2: No schema attribute + OS prefers dark */
223
+ @media (prefers-color-scheme: dark) {
224
+ :root:not([data-schema]) .t0.t0 {
225
+ color: var(--text-on-dark-color);
226
+ }
227
+ }
228
+
229
+ /* Default: no schema + OS does not prefer dark */
230
+ @media (not (prefers-color-scheme: dark)) {
231
+ :root:not([data-schema="dark"]) .t0.t0 {
232
+ color: var(--text-color);
233
+ }
234
+ }
235
+
236
+ /* Default: schema is set but not dark (any OS preference) */
237
+ :root:not([data-schema="dark"])[data-schema] .t0.t0 {
238
+ color: var(--text-color);
239
+ }
240
+ ```
241
+
242
+ Every rule is guarded by the negation of higher-priority rules. No two rules can match at the same time. No specificity arithmetic. No source-order dependence. Components compose and extend without collisions.
243
+
244
+ By absorbing selector complexity, Tasty makes advanced CSS patterns practical again — nested container queries, multi-condition `@supports` gates, and combined root-state/media branches. You stay in pure CSS instead of relying on JavaScript workarounds, so the browser can optimize layout, painting, and transitions natively. Tasty doesn't limit CSS; it unlocks its full potential by removing the complexity that held teams back.
245
+
246
+ ## Capabilities
247
+
248
+ ### Design Tokens and Custom Units
249
+
250
+ Tokens are first-class. Colors use `#name` syntax. Spacing, radius, and border width use multiplier units tied to CSS custom properties:
251
+
252
+ ```tsx
253
+ fill: '#surface', // → var(--surface-color)
254
+ color: '#text.80', // → 80% opacity text token
255
+ padding: '2x', // → calc(var(--gap) * 2)
256
+ radius: '1r', // → var(--radius)
257
+ border: '1bw solid #border',
258
+ ```
259
+
260
+ | Unit | Maps to | Example |
261
+ |------|---------|---------|
262
+ | `x` | `--gap` multiplier | `2x` → `calc(var(--gap) * 2)` |
263
+ | `r` | `--radius` multiplier | `1r` → `var(--radius)` |
264
+ | `bw` | `--border-width` multiplier | `1bw` → `var(--border-width)` |
265
+ | `ow` | `--outline-width` multiplier | `1ow` → `var(--outline-width)` |
266
+ | `cr` | `--card-radius` multiplier | `1cr` → `var(--card-radius)` |
267
+
268
+ Define your own units via `configure({ units: { ... } })`.
269
+
270
+ ### State System
271
+
272
+ Every style property accepts a state mapping object. Keys can be combined with boolean logic:
273
+
274
+ | State type | Syntax | CSS output |
275
+ |------------|--------|------------|
276
+ | Data attribute (boolean modifier) | `disabled` | `[data-disabled]` |
277
+ | Data attribute (value modifier) | `theme=danger` | `[data-theme="danger"]` |
278
+ | Pseudo-class | `:hover` | `:hover` |
279
+ | Attribute selector | `[role="tab"]` | `[role="tab"]` |
280
+ | Class selector (supported) | `.is-active` | `.is-active` |
281
+ | Media query | `@media(w < 768px)` | `@media (width < 768px)` |
282
+ | Container query | `@(panel, w >= 300px)` | `@container panel (width >= 300px)` |
283
+ | Root state | `@root(theme=dark)` | `:root[data-theme="dark"]` |
284
+ | Parent state | `@parent(theme=danger)` | `:is([data-theme="danger"] *)` |
285
+ | Feature query | `@supports(display: grid)` | `@supports (display: grid)` |
286
+ | Entry animation | `@starting` | `@starting-style` |
287
+
288
+ Combine with `&` (AND), `|` (OR), `!` (NOT):
289
+
290
+ ```tsx
291
+ fill: {
292
+ '': '#surface',
293
+ 'theme=danger & :hover': '#danger-hover',
294
+ '[aria-selected="true"]': '#accent-subtle',
295
+ }
147
296
  ```
148
297
 
149
298
  ### Sub-Element Styling
150
299
 
300
+ Style inner elements from the parent component definition. No extra components, no CSS leakage:
301
+
151
302
  ```tsx
152
303
  const Card = tasty({
153
304
  styles: {
154
305
  padding: '4x',
155
306
  Title: { preset: 'h3', color: '#primary' },
156
- Content: { color: '#text' },
157
- },
158
- elements: {
159
- Title: 'h2',
160
- Content: 'div',
307
+ Content: { color: '#text', preset: 't2' },
161
308
  },
309
+ elements: { Title: 'h2', Content: 'div' },
162
310
  });
163
311
 
164
312
  <Card>
165
- <Card.Title>Title</Card.Title>
166
- <Card.Content>Content</Card.Content>
313
+ <Card.Title>Heading</Card.Title>
314
+ <Card.Content>Body text</Card.Content>
167
315
  </Card>
168
316
  ```
169
317
 
170
- ### Hooks
318
+ Sub-elements use `data-element` attributes — no extra class names, no naming conventions.
319
+
320
+ 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.
321
+
322
+ Use `@own(...)` when a sub-element should react to its own state instead of the root state context.
323
+
324
+ Class selectors are also supported, but modifiers/pseudo-classes are usually the better default in design-system code.
325
+
326
+ Use the sub-element selector `$` when you need precise descendant targeting to avoid leakage in deeply nested component trees.
327
+
328
+ ### Variants
329
+
330
+ 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.
171
331
 
172
332
  ```tsx
173
- import { useStyles, useGlobalStyles } from '@tenphi/tasty';
333
+ const Button = tasty({
334
+ styles: { padding: '2x 4x', radius: '1r' },
335
+ variants: {
336
+ default: { fill: '#primary', color: '#on-primary' },
337
+ danger: { fill: '#danger', color: '#on-danger' },
338
+ outline: { fill: 'transparent', border: '1bw solid #primary' },
339
+ },
340
+ });
174
341
 
175
- function MyComponent() {
176
- const { className } = useStyles({
177
- padding: '2x',
178
- fill: '#surface',
179
- });
342
+ <Button variant="danger">Delete</Button>
343
+ ```
180
344
 
181
- useGlobalStyles('.card', {
182
- border: '1bw solid #border',
183
- radius: '1r',
184
- });
345
+ ### Recipes
346
+
347
+ 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.
348
+
349
+ ```tsx
350
+ configure({
351
+ recipes: {
352
+ card: { padding: '4x', fill: '#surface', radius: '1r', border: true },
353
+ elevated: { shadow: '0 2x 4x #shadow' },
354
+ },
355
+ });
356
+
357
+ const ProfileCard = tasty({
358
+ styles: {
359
+ recipe: 'card elevated',
360
+ color: '#text',
361
+ },
362
+ });
363
+ ```
364
+
365
+ 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'`.
366
+
367
+ ### Auto-Inferred `@property`
368
+
369
+ CSS custom properties do not animate smoothly by default because the browser does not know how to interpolate their values. The [`@property`](https://developer.mozilla.org/en-US/docs/Web/CSS/@property) at-rule fixes that by declaring a property's syntax, such as `<number>` or `<color>`.
370
+
371
+ In Tasty, you usually do not need to declare `@property` manually. When a custom property is assigned a concrete value, Tasty infers the syntax and registers the matching `@property` for you:
372
+
373
+ ```tsx
374
+ const Pulse = tasty({
375
+ styles: {
376
+ animation: 'pulse 2s infinite',
377
+ transform: 'scale($pulse-scale)',
378
+ '@keyframes': {
379
+ pulse: {
380
+ '0%, 100%': { '$pulse-scale': 1 },
381
+ '50%': { '$pulse-scale': 1.05 },
382
+ },
383
+ },
384
+ },
385
+ });
386
+ ```
387
+
388
+ Here, `$pulse-scale: 1` is inferred as `<number>`, so Tasty injects `@property --pulse-scale` automatically before using it in the animation. Supported inferred syntaxes: `<number>`, `<length>`, `<percentage>`, `<angle>`, `<time>`, and `<color>`.
389
+
390
+ If you prefer full manual control, disable auto-inference globally with `configure({ autoPropertyTypes: false })`.
391
+
392
+ ### Explicit `@properties`
393
+
394
+ Declare `@properties` yourself only when you need to override the defaults, for example to set `inherits: false` or provide a custom `initialValue`:
395
+
396
+ ```tsx
397
+ '@properties': {
398
+ '$pulse-scale': { syntax: '<number>', inherits: false, initialValue: 1 },
399
+ },
400
+ ```
401
+
402
+ ### React Hooks
403
+
404
+ For cases where you don't need a full component:
405
+
406
+ ```tsx
407
+ import { useStyles, useGlobalStyles, useRawCSS } from '@tenphi/tasty';
185
408
 
186
- return <div className={className}>Styled</div>;
409
+ function App() {
410
+ const { className } = useStyles({ padding: '2x', fill: '#surface' });
411
+ useGlobalStyles(':root', { '#primary': 'purple', '$gap': '8px' });
412
+ useRawCSS('body { margin: 0; }');
413
+
414
+ return <main className={className}>...</main>;
187
415
  }
188
416
  ```
189
417
 
190
418
  ### Zero-Runtime Mode
191
419
 
420
+ Extract all CSS at build time. Zero JavaScript overhead in production:
421
+
192
422
  ```tsx
193
423
  import { tastyStatic } from '@tenphi/tasty/static';
194
424
 
195
- const button = tastyStatic({
196
- display: 'inline-flex',
197
- padding: '2x 4x',
198
- fill: '#purple',
199
- color: '#white',
425
+ const card = tastyStatic({
426
+ padding: '4x',
427
+ fill: '#surface',
428
+ radius: '1r',
429
+ color: { '': '#text', '@dark': '#text-on-dark' },
200
430
  });
201
431
 
202
- <button className={button}>Click me</button>
432
+ // card is a CSS class name string
433
+ <div className={card}>Static styles, zero runtime</div>
203
434
  ```
204
435
 
205
436
  Configure the Babel plugin:
206
437
 
207
438
  ```js
208
- // babel.config.js
209
439
  module.exports = {
210
440
  plugins: [
211
- ['@tenphi/tasty/babel-plugin', { output: 'public/tasty.css' }],
441
+ ['@tenphi/tasty/babel-plugin', {
442
+ output: 'public/tasty.css',
443
+ config: {
444
+ states: { '@dark': '@root(theme=dark)' },
445
+ },
446
+ }],
212
447
  ],
213
448
  };
214
449
  ```
215
450
 
216
- ## Built-in Units
451
+ ### `tasty` vs `tastyStatic`
217
452
 
218
- | Unit | Description | Example | CSS Output |
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)` |
453
+ | | `tasty` (runtime) | `tastyStatic` (zero-runtime) |
454
+ |---|---|---|
455
+ | **Output** | React component | CSS class name |
456
+ | **CSS injection** | Runtime `<style>` tags | Build-time extraction |
457
+ | **Runtime cost** | Style generation on mount | None |
458
+ | **Generated CSS scope** | Only styles/variants used at runtime | All extracted static styles at build time |
459
+ | **Dynamic values** | Fully supported | Via CSS custom properties |
460
+ | **Sub-elements** | Built-in (`<C.Title>`) | Manual (`data-element`) |
461
+ | **Variants** | Built-in (`variants` option) | Separate static styles |
462
+ | **Framework** | React | Any (requires Babel) |
463
+ | **Best for** | Interactive apps, design systems | Static sites, SSG, landing pages |
464
+
465
+ Both share the same DSL, tokens, units, state mappings, and recipes.
466
+
467
+ ### Runtime Performance
468
+
469
+ If you choose the runtime approach, performance is usually a non-issue in practice:
470
+
471
+ - CSS is generated and injected only when styles are actually used.
472
+ - Multi-level caching avoids repeated parsing and style recomputation.
473
+ - Styles are split into reusable chunks and applied as multiple class names, so matching chunks can be reused across components instead of re-injected.
474
+ - Style normalization guarantees equivalent style input resolves to the same chunks, improving deduplication hit rates.
475
+ - A style garbage collector removes unused styles/chunks over time.
476
+ - A dedicated style injector minimizes DOM/style-tag overhead.
477
+ - This approach is validated in enterprise-scale apps where runtime styling overhead is not noticeable in normal UI flows.
228
478
 
229
- ## `tasty` vs `tastyStatic`
479
+ ## Entry Points
230
480
 
231
- Tasty ships two styling APIs with different trade-offs. Pick the one that fits your project:
481
+ | Import | Description | Platform |
482
+ |--------|-------------|----------|
483
+ | `@tenphi/tasty` | Runtime style engine (`tasty`, hooks, `configure`) | Browser |
484
+ | `@tenphi/tasty/static` | Zero-runtime static styles (`tastyStatic`) | Browser |
485
+ | `@tenphi/tasty/core` | Lower-level internals (config, parser, pipeline, injector, style handlers) for tooling and advanced use | Browser / Node |
486
+ | `@tenphi/tasty/babel-plugin` | Babel plugin for zero-runtime CSS extraction | Node |
487
+ | `@tenphi/tasty/zero` | Programmatic extraction API | Node |
488
+ | `@tenphi/tasty/next` | Next.js integration wrapper | Node |
232
489
 
233
- | | `tasty` (runtime) | `tastyStatic` (zero-runtime) |
234
- |---|---|---|
235
- | **Framework** | React only | Framework-agnostic (requires Babel) |
236
- | **Import** | `@tenphi/tasty` | `@tenphi/tasty/static` |
237
- | **Output** | React component | CSS class name (string) |
238
- | **CSS injection** | At runtime via `<style>` tags | At build time via Babel plugin |
239
- | **Runtime overhead** | Style generation + injection on mount | None CSS is pre-extracted |
240
- | **Requires Babel plugin** | No | Yes (`@tenphi/tasty/babel-plugin`) |
241
- | **Component creation** | `tasty({ as, styles, ... })` | `tastyStatic({ ... })` returns a class |
242
- | **Extending components** | `tasty(BaseComponent, { styles })` | `tastyStatic(baseStyle, { ... })` |
243
- | **Global / selector styles** | `useGlobalStyles(selector, styles)` | `tastyStatic(selector, styles)` |
244
- | **Style props at runtime** | Yes — `styleProps`, `styles`, `mods` | No — all values must be static |
245
- | **Dynamic values** | Fully supported | Only via CSS custom properties |
246
- | **Sub-elements** | Built-in (`elements` + `<C.Title>`) | Manual (use `data-element` + CSS) |
247
- | **Variants** | Built-in (`variants` option) | Manual (create separate static styles) |
248
- | **Tokens** | `tokens` prop → inline CSS vars | `processTokens()` helper |
249
- | **Design tokens & units** | Full support (`#color`, `2x`, `1r`) | Full support (`#color`, `2x`, `1r`) |
250
- | **State mappings** | Full support (modifiers, media, etc.) | Full support (modifiers, media, etc.) |
251
- | **Recipes** | Supported via `configure()` | Supported via Babel plugin config |
252
- | **Best for** | Interactive React apps, design systems | Static sites, landing pages, SSG |
490
+ ## Ecosystem
491
+
492
+ Tasty is the core of a production-ready styling platform. These companion tools complete the picture:
493
+
494
+ ### [ESLint Plugin](https://github.com/tenphi/eslint-plugin-tasty)
495
+
496
+ `@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.
497
+
498
+ ```bash
499
+ pnpm add -D @tenphi/eslint-plugin-tasty
500
+ ```
501
+
502
+ ```js
503
+ import tasty from '@tenphi/eslint-plugin-tasty';
504
+ export default [tasty.configs.recommended];
505
+ ```
506
+
507
+ ### [Glaze](https://github.com/tenphi/glaze)
508
+
509
+ `@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.
510
+
511
+ ```tsx
512
+ import { glaze } from '@tenphi/glaze';
513
+
514
+ const theme = glaze(280, 80);
515
+ theme.colors({
516
+ surface: { lightness: 97 },
517
+ text: { base: 'surface', lightness: '-52', contrast: 'AAA' },
518
+ });
519
+
520
+ const tokens = theme.tasty(); // Ready-to-use Tasty tokens
521
+ ```
522
+
523
+ ### [VS Code Extension](https://github.com/tenphi/tasty-vscode-extension)
524
+
525
+ 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.
526
+
527
+ <p align="center">
528
+ <img src="assets/tasty-vscode-highlight.png" width="512" alt="Tasty VS Code syntax highlighting example">
529
+ </p>
530
+
531
+ ### [Cube UI Kit](https://github.com/cube-js/cube-ui-kit)
532
+
533
+ 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
534
 
254
535
  ## Documentation
255
536
 
256
- - [Runtime API (tasty)](docs/tasty.md) — Full runtime styling documentation
257
- - [Zero Runtime (tastyStatic)](docs/tasty-static.md) — Build-time static styling documentation
537
+ - **[Usage Guide](docs/usage.md)**Runtime styling: component creation, state mappings, sub-elements, variants, and hooks
538
+ - **[Configuration](docs/configuration.md)**Global configuration: tokens, recipes, custom units, style handlers, and TypeScript extensions
539
+ - **[Style Properties](docs/styles.md)** — Complete reference for all enhanced style properties: syntax, values, modifiers, and recommendations
540
+ - **[Zero Runtime (tastyStatic)](docs/tasty-static.md)** — Build-time static styling: Babel plugin setup, Next.js integration, and static style patterns
541
+ - **[Style Injector](docs/injector.md)** — Internal CSS injection engine: `inject()`, `injectGlobal()`, `injectRawCSS()`, `keyframes()`, deduplication, reference counting, cleanup, SSR support, and Shadow DOM
542
+ - **[Debug Utilities](docs/debug.md)** — Runtime CSS inspection via `tastyDebug`: CSS extraction, element inspection, cache metrics, chunk breakdown, and performance monitoring
258
543
 
259
544
  ## License
260
545