@tenphi/tasty 0.0.0-snapshot.2f99c73 → 0.0.0-snapshot.36e329c

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 (116) hide show
  1. package/README.md +404 -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 +36 -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 +101 -1
  36. package/dist/properties/index.js.map +1 -1
  37. package/dist/properties/property-type-resolver.d.ts +29 -0
  38. package/dist/properties/property-type-resolver.js +103 -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.map +1 -1
  53. package/dist/styles/flow.d.ts +3 -3
  54. package/dist/styles/flow.js.map +1 -1
  55. package/dist/styles/index.d.ts +2 -2
  56. package/dist/styles/inset.d.ts +3 -1
  57. package/dist/styles/inset.js +48 -40
  58. package/dist/styles/inset.js.map +1 -1
  59. package/dist/styles/justify.d.ts +1 -1
  60. package/dist/styles/justify.js.map +1 -1
  61. package/dist/styles/margin.d.ts +1 -5
  62. package/dist/styles/margin.js +48 -40
  63. package/dist/styles/margin.js.map +1 -1
  64. package/dist/styles/padding.d.ts +1 -5
  65. package/dist/styles/padding.js +48 -40
  66. package/dist/styles/padding.js.map +1 -1
  67. package/dist/styles/predefined.d.ts +0 -1
  68. package/dist/styles/predefined.js.map +1 -1
  69. package/dist/styles/radius.d.ts +1 -1
  70. package/dist/styles/radius.js.map +1 -1
  71. package/dist/styles/scrollbar.d.ts +1 -1
  72. package/dist/styles/scrollbar.js +19 -12
  73. package/dist/styles/scrollbar.js.map +1 -1
  74. package/dist/styles/shadow.d.ts +2 -2
  75. package/dist/styles/shadow.js.map +1 -1
  76. package/dist/styles/styledScrollbar.d.ts +1 -1
  77. package/dist/styles/styledScrollbar.js.map +1 -1
  78. package/dist/styles/transition.d.ts +1 -1
  79. package/dist/styles/transition.js +26 -6
  80. package/dist/styles/transition.js.map +1 -1
  81. package/dist/styles/types.d.ts +5 -3
  82. package/dist/tasty.d.ts +1 -2
  83. package/dist/tasty.js +19 -4
  84. package/dist/tasty.js.map +1 -1
  85. package/dist/types.d.ts +6 -4
  86. package/dist/utils/colors.d.ts +1 -1
  87. package/dist/utils/colors.js.map +1 -1
  88. package/dist/utils/css-types.d.ts +7 -0
  89. package/dist/utils/dotize.d.ts +1 -1
  90. package/dist/utils/is-valid-element-type.js +15 -0
  91. package/dist/utils/is-valid-element-type.js.map +1 -0
  92. package/dist/utils/mod-attrs.js.map +1 -1
  93. package/dist/utils/process-tokens.d.ts +1 -1
  94. package/dist/utils/process-tokens.js.map +1 -1
  95. package/dist/utils/resolve-recipes.js +17 -13
  96. package/dist/utils/resolve-recipes.js.map +1 -1
  97. package/dist/utils/string.js.map +1 -1
  98. package/dist/utils/styles.d.ts +7 -12
  99. package/dist/utils/styles.js +175 -9
  100. package/dist/utils/styles.js.map +1 -1
  101. package/dist/zero/babel.d.ts +5 -0
  102. package/dist/zero/babel.js +13 -7
  103. package/dist/zero/babel.js.map +1 -1
  104. package/dist/zero/extractor.d.ts +0 -1
  105. package/dist/zero/extractor.js +66 -1
  106. package/dist/zero/extractor.js.map +1 -1
  107. package/package.json +69 -13
  108. package/tasty.config.ts +14 -0
  109. package/dist/chunks/cacheKey.d.ts +0 -1
  110. package/dist/chunks/index.d.ts +0 -3
  111. package/dist/chunks/renderChunk.d.ts +0 -2
  112. package/dist/hooks/index.d.ts +0 -5
  113. package/dist/parser/index.d.ts +0 -3
  114. package/dist/parser/index.js +0 -4
  115. package/dist/pipeline/exclusive.d.ts +0 -1
  116. 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',
83
86
  },
87
+ cursor: {
88
+ '': 'pointer',
89
+ '[disabled]': 'not-allowed',
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,419 @@ 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
135
+
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.
137
+
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.
139
+
140
+ ```tsx
141
+ import { tasty, FLOW_STYLES, POSITION_STYLES } from '@tenphi/tasty';
142
+
143
+ const Space = tasty({
144
+ styles: {
145
+ display: 'flex',
146
+ flow: 'column',
147
+ gap: '1x',
148
+ },
149
+ styleProps: FLOW_STYLES,
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.
132
192
 
133
- ## Core Concepts
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.
134
194
 
135
- ### Design Tokens
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.**
136
198
 
137
199
  ```tsx
138
- const TokenCard = tasty({
200
+ const Text = tasty({
139
201
  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',
202
+ color: {
203
+ '': '#text',
204
+ '@dark': '#text-on-dark',
205
+ },
206
+ padding: {
207
+ '': '4x',
208
+ '@mobile': '2x',
209
+ },
145
210
  },
146
211
  });
147
212
  ```
148
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
+ }
296
+ ```
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
+ ### Keyframes and `@property`
368
+
369
+ Modern CSS features are natively supported:
370
+
371
+ Color tokens are automatically registered as typed properties (`<color>`), so token-based transitions work without extra setup.
372
+
373
+ ```tsx
374
+ const Pulse = tasty({
375
+ styles: {
376
+ '@properties': {
377
+ '$pulse-scale': {
378
+ syntax: '<number>',
379
+ inherits: false,
380
+ initialValue: 1,
381
+ },
382
+ },
383
+ animation: 'pulse 2s infinite',
384
+ transform: 'scale($pulse-scale)',
385
+ '@keyframes': {
386
+ pulse: {
387
+ '0%, 100%': { '$pulse-scale': 1 },
388
+ '50%': { '$pulse-scale': 1.05 },
389
+ },
390
+ },
391
+ },
392
+ });
393
+ ```
185
394
 
186
- return <div className={className}>Styled</div>;
395
+ ### React Hooks
396
+
397
+ For cases where you don't need a full component:
398
+
399
+ ```tsx
400
+ import { useStyles, useGlobalStyles, useRawCSS } from '@tenphi/tasty';
401
+
402
+ function App() {
403
+ const { className } = useStyles({ padding: '2x', fill: '#surface' });
404
+ useGlobalStyles(':root', { '#primary': 'purple', '$gap': '8px' });
405
+ useRawCSS('body { margin: 0; }');
406
+
407
+ return <main className={className}>...</main>;
187
408
  }
188
409
  ```
189
410
 
190
411
  ### Zero-Runtime Mode
191
412
 
413
+ Extract all CSS at build time. Zero JavaScript overhead in production:
414
+
192
415
  ```tsx
193
416
  import { tastyStatic } from '@tenphi/tasty/static';
194
417
 
195
- const button = tastyStatic({
196
- display: 'inline-flex',
197
- padding: '2x 4x',
198
- fill: '#purple',
199
- color: '#white',
418
+ const card = tastyStatic({
419
+ padding: '4x',
420
+ fill: '#surface',
421
+ radius: '1r',
422
+ color: { '': '#text', '@dark': '#text-on-dark' },
200
423
  });
201
424
 
202
- <button className={button}>Click me</button>
425
+ // card is a CSS class name string
426
+ <div className={card}>Static styles, zero runtime</div>
203
427
  ```
204
428
 
205
429
  Configure the Babel plugin:
206
430
 
207
431
  ```js
208
- // babel.config.js
209
432
  module.exports = {
210
433
  plugins: [
211
- ['@tenphi/tasty/babel-plugin', { output: 'public/tasty.css' }],
434
+ ['@tenphi/tasty/babel-plugin', {
435
+ output: 'public/tasty.css',
436
+ config: {
437
+ states: { '@dark': '@root(theme=dark)' },
438
+ },
439
+ }],
212
440
  ],
213
441
  };
214
442
  ```
215
443
 
216
- ## Built-in Units
444
+ ### `tasty` vs `tastyStatic`
445
+
446
+ | | `tasty` (runtime) | `tastyStatic` (zero-runtime) |
447
+ |---|---|---|
448
+ | **Output** | React component | CSS class name |
449
+ | **CSS injection** | Runtime `<style>` tags | Build-time extraction |
450
+ | **Runtime cost** | Style generation on mount | None |
451
+ | **Generated CSS scope** | Only styles/variants used at runtime | All extracted static styles at build time |
452
+ | **Dynamic values** | Fully supported | Via CSS custom properties |
453
+ | **Sub-elements** | Built-in (`<C.Title>`) | Manual (`data-element`) |
454
+ | **Variants** | Built-in (`variants` option) | Separate static styles |
455
+ | **Framework** | React | Any (requires Babel) |
456
+ | **Best for** | Interactive apps, design systems | Static sites, SSG, landing pages |
457
+
458
+ Both share the same DSL, tokens, units, state mappings, and recipes.
459
+
460
+ ### Runtime Performance
461
+
462
+ If you choose the runtime approach, performance is usually a non-issue in practice:
463
+
464
+ - CSS is generated and injected only when styles are actually used.
465
+ - Multi-level caching avoids repeated parsing and style recomputation.
466
+ - Styles are split into reusable chunks and applied as multiple class names, so matching chunks can be reused across components instead of re-injected.
467
+ - Style normalization guarantees equivalent style input resolves to the same chunks, improving deduplication hit rates.
468
+ - A style garbage collector removes unused styles/chunks over time.
469
+ - A dedicated style injector minimizes DOM/style-tag overhead.
470
+ - This approach is validated in enterprise-scale apps where runtime styling overhead is not noticeable in normal UI flows.
471
+
472
+ ## Entry Points
473
+
474
+ | Import | Description | Platform |
475
+ |--------|-------------|----------|
476
+ | `@tenphi/tasty` | Runtime style engine (`tasty`, hooks, `configure`) | Browser |
477
+ | `@tenphi/tasty/static` | Zero-runtime static styles (`tastyStatic`) | Browser |
478
+ | `@tenphi/tasty/core` | Lower-level internals (config, parser, pipeline, injector, style handlers) for tooling and advanced use | Browser / Node |
479
+ | `@tenphi/tasty/babel-plugin` | Babel plugin for zero-runtime CSS extraction | Node |
480
+ | `@tenphi/tasty/zero` | Programmatic extraction API | Node |
481
+ | `@tenphi/tasty/next` | Next.js integration wrapper | Node |
217
482
 
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)` |
483
+ ## Ecosystem
228
484
 
229
- ## `tasty` vs `tastyStatic`
485
+ Tasty is the core of a production-ready styling platform. These companion tools complete the picture:
230
486
 
231
- Tasty ships two styling APIs with different trade-offs. Pick the one that fits your project:
487
+ ### [ESLint Plugin](https://github.com/tenphi/eslint-plugin-tasty)
232
488
 
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 |
489
+ `@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.
490
+
491
+ ```bash
492
+ pnpm add -D @tenphi/eslint-plugin-tasty
493
+ ```
494
+
495
+ ```js
496
+ import tasty from '@tenphi/eslint-plugin-tasty';
497
+ export default [tasty.configs.recommended];
498
+ ```
499
+
500
+ ### [Glaze](https://github.com/tenphi/glaze)
501
+
502
+ `@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.
503
+
504
+ ```tsx
505
+ import { glaze } from '@tenphi/glaze';
506
+
507
+ const theme = glaze(280, 80);
508
+ theme.colors({
509
+ surface: { lightness: 97 },
510
+ text: { base: 'surface', lightness: '-52', contrast: 'AAA' },
511
+ });
512
+
513
+ const tokens = theme.tasty(); // Ready-to-use Tasty tokens
514
+ ```
515
+
516
+ ### [VS Code Extension](https://github.com/tenphi/tasty-vscode-extension)
517
+
518
+ 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.
519
+
520
+ <p align="center">
521
+ <img src="assets/tasty-vscode-highlight.png" width="512" alt="Tasty VS Code syntax highlighting example">
522
+ </p>
523
+
524
+ ### [Cube UI Kit](https://github.com/cube-js/cube-ui-kit)
525
+
526
+ 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
527
 
254
528
  ## Documentation
255
529
 
256
- - [Runtime API (tasty)](docs/tasty.md) — Full runtime styling documentation
257
- - [Zero Runtime (tastyStatic)](docs/tasty-static.md) — Build-time static styling documentation
530
+ - **[Usage Guide](docs/usage.md)**Runtime styling: component creation, state mappings, sub-elements, variants, and hooks
531
+ - **[Configuration](docs/configuration.md)**Global configuration: tokens, recipes, custom units, style handlers, and TypeScript extensions
532
+ - **[Style Properties](docs/styles.md)** — Complete reference for all enhanced style properties: syntax, values, modifiers, and recommendations
533
+ - **[Zero Runtime (tastyStatic)](docs/tasty-static.md)** — Build-time static styling: Babel plugin setup, Next.js integration, and static style patterns
534
+ - **[Style Injector](docs/injector.md)** — Internal CSS injection engine: `inject()`, `injectGlobal()`, `injectRawCSS()`, `keyframes()`, deduplication, reference counting, cleanup, SSR support, and Shadow DOM
535
+ - **[Debug Utilities](docs/debug.md)** — Runtime CSS inspection via `tastyDebug`: CSS extraction, element inspection, cache metrics, chunk breakdown, and performance monitoring
258
536
 
259
537
  ## License
260
538