@tenphi/tasty 0.0.0-snapshot.dfef2a5 → 0.0.0-snapshot.e01a0ee

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 (129) hide show
  1. package/README.md +436 -395
  2. package/dist/babel-types-BKDTT4--.d.ts +18 -0
  3. package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
  4. package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
  5. package/dist/chunks/build-config-DlxpZKk_.js +60 -0
  6. package/dist/chunks/build-config-DlxpZKk_.js.map +1 -0
  7. package/dist/{collector-DTahQUiV.js → chunks/collector-B4-yqFEs.js} +25 -119
  8. package/dist/chunks/collector-B4-yqFEs.js.map +1 -0
  9. package/dist/chunks/config-engine-DJsb5WYu.js +272 -0
  10. package/dist/chunks/config-engine-DJsb5WYu.js.map +1 -0
  11. package/dist/chunks/config-file-DlZXJMj8.js +25 -0
  12. package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
  13. package/dist/chunks/css-definitions-DW1TGGiy.js +910 -0
  14. package/dist/chunks/css-definitions-DW1TGGiy.js.map +1 -0
  15. package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
  16. package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
  17. package/dist/chunks/debug-DMMwe1rY.js +502 -0
  18. package/dist/chunks/debug-DMMwe1rY.js.map +1 -0
  19. package/dist/chunks/dsl-DYSJc1-T.js +1383 -0
  20. package/dist/chunks/dsl-DYSJc1-T.js.map +1 -0
  21. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  22. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  23. package/dist/chunks/react-runtime-DhPtFlZs.js +689 -0
  24. package/dist/chunks/react-runtime-DhPtFlZs.js.map +1 -0
  25. package/dist/chunks/runtime-engine-BlrVXv8l.js +2432 -0
  26. package/dist/chunks/runtime-engine-BlrVXv8l.js.map +1 -0
  27. package/dist/chunks/runtime-state-BLyMRYFF.js +152 -0
  28. package/dist/chunks/runtime-state-BLyMRYFF.js.map +1 -0
  29. package/dist/{merge-styles-oklji0KB.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
  30. package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
  31. package/dist/chunks/style-engine-of5Xbc27.js +5571 -0
  32. package/dist/chunks/style-engine-of5Xbc27.js.map +1 -0
  33. package/dist/{css-writer-BrQjOLNY.js → chunks/zero-engine-D2jPSpWA.js} +65 -145
  34. package/dist/chunks/zero-engine-D2jPSpWA.js.map +1 -0
  35. package/dist/{collector-DUaHCcTS.d.ts → collector-CTU-nl0g.d.ts} +23 -4
  36. package/dist/{config-YsxGv4tq.d.ts → config-CcxqSZI2.d.ts} +175 -70
  37. package/dist/core/index.d.ts +5 -5
  38. package/dist/core/index.js +9 -6
  39. package/dist/hydrate-CRyjjAyl.d.ts +22 -0
  40. package/dist/{index-DhhUI0yi.d.ts → index--GdqCPlp.d.ts} +311 -253
  41. package/dist/index.d.ts +5 -5
  42. package/dist/index.js +11 -921
  43. package/dist/{merge-styles-CU7JbEwg.d.ts → merge-styles-DSkVc6CD.d.ts} +2 -3
  44. package/dist/ssr/astro-client.d.ts +1 -1
  45. package/dist/ssr/astro-client.js +1 -14
  46. package/dist/ssr/astro-client.js.map +1 -1
  47. package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
  48. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  49. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  50. package/dist/ssr/astro-middleware-extract.d.ts +10 -0
  51. package/dist/ssr/astro-middleware-extract.js +9 -0
  52. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  53. package/dist/ssr/astro-middleware-static.d.ts +3 -2
  54. package/dist/ssr/astro-middleware-static.js +0 -11
  55. package/dist/ssr/astro-middleware-static.js.map +1 -1
  56. package/dist/ssr/astro-middleware.d.ts +3 -2
  57. package/dist/ssr/astro-middleware.js +0 -12
  58. package/dist/ssr/astro-middleware.js.map +1 -1
  59. package/dist/ssr/astro.d.ts +40 -6
  60. package/dist/ssr/astro.js +157 -93
  61. package/dist/ssr/astro.js.map +1 -1
  62. package/dist/ssr/client.d.ts +2 -0
  63. package/dist/ssr/client.js +2 -0
  64. package/dist/ssr/index.d.ts +5 -25
  65. package/dist/ssr/index.js +5 -5
  66. package/dist/ssr/index.js.map +1 -1
  67. package/dist/ssr/next-config.d.ts +64 -0
  68. package/dist/ssr/next-config.js +123 -0
  69. package/dist/ssr/next-config.js.map +1 -0
  70. package/dist/ssr/next.d.ts +9 -8
  71. package/dist/ssr/next.js +29 -43
  72. package/dist/ssr/next.js.map +1 -1
  73. package/dist/static/index.d.ts +8 -9
  74. package/dist/static/index.js +4 -22
  75. package/dist/static/index.js.map +1 -1
  76. package/dist/static/inject.d.ts +1 -2
  77. package/dist/{index-Cd45t5NM.d.ts → types-DJEM_BOJ.d.ts} +864 -818
  78. package/dist/zero/babel.d.ts +67 -2
  79. package/dist/zero/babel.js +77 -140
  80. package/dist/zero/babel.js.map +1 -1
  81. package/dist/zero/index.d.ts +62 -8
  82. package/dist/zero/index.js +24 -2
  83. package/dist/zero/index.js.map +1 -0
  84. package/dist/zero/next.d.ts +4 -5
  85. package/dist/zero/next.js +3 -38
  86. package/dist/zero/next.js.map +1 -1
  87. package/docs/README.md +16 -8
  88. package/docs/adoption.md +69 -36
  89. package/docs/ai-agents.md +120 -86
  90. package/docs/comparison.md +77 -47
  91. package/docs/configuration.md +251 -109
  92. package/docs/debug.md +21 -8
  93. package/docs/design-system.md +152 -31
  94. package/docs/dsl.md +373 -219
  95. package/docs/getting-started.md +130 -50
  96. package/docs/injector.md +106 -68
  97. package/docs/methodology.md +80 -49
  98. package/docs/migration-v3.md +52 -52
  99. package/docs/pipeline.md +54 -27
  100. package/docs/plugins.md +59 -75
  101. package/docs/react-api.md +138 -52
  102. package/docs/runtime-benchmarks.md +388 -0
  103. package/docs/ssr.md +285 -101
  104. package/docs/styles.md +118 -32
  105. package/docs/tasty-static.md +272 -135
  106. package/package.json +118 -34
  107. package/dist/async-storage-DKK-wTD4.js +0 -44
  108. package/dist/async-storage-DKK-wTD4.js.map +0 -1
  109. package/dist/babel-BUQGeOXA.d.ts +0 -83
  110. package/dist/collector-DTahQUiV.js.map +0 -1
  111. package/dist/config-B5kHzuNz.js +0 -12269
  112. package/dist/config-B5kHzuNz.js.map +0 -1
  113. package/dist/context-CA8YKeMn.js +0 -24
  114. package/dist/context-CA8YKeMn.js.map +0 -1
  115. package/dist/core-CTP5hhqP.js +0 -1565
  116. package/dist/core-CTP5hhqP.js.map +0 -1
  117. package/dist/css-writer-BrQjOLNY.js.map +0 -1
  118. package/dist/format-global-rules-DklyaXv-.js +0 -22
  119. package/dist/format-global-rules-DklyaXv-.js.map +0 -1
  120. package/dist/format-rules-DKOA-6qu.js +0 -130
  121. package/dist/format-rules-DKOA-6qu.js.map +0 -1
  122. package/dist/hydrate-OeMX99We.js +0 -37
  123. package/dist/hydrate-OeMX99We.js.map +0 -1
  124. package/dist/index.js.map +0 -1
  125. package/dist/keyframes-CoBy6OgI.js +0 -424
  126. package/dist/keyframes-CoBy6OgI.js.map +0 -1
  127. package/dist/merge-styles-oklji0KB.js.map +0 -1
  128. package/dist/resolve-recipes-DTG81rzl.js +0 -144
  129. package/dist/resolve-recipes-DTG81rzl.js.map +0 -1
@@ -1,6 +1,8 @@
1
1
  # Getting Started
2
2
 
3
- This guide walks you from zero to a working Tasty component, then through the optional shared configuration and tooling layers. It is the right starting point when you already want to try Tasty in code. If you are still deciding whether Tasty fits your team, start with [Comparison](comparison.md) and [Adoption Guide](adoption.md) first. For a feature overview, see the [README](../README.md). For the full style language reference, see the [Style DSL](dsl.md). For the React API, see the [React API](react-api.md). For the rest of the docs by role or task, see the [Docs Hub](README.md).
3
+ Build one stateful component first. You will see how Tasty expresses priority as a state map, why overlapping states do not compete, and where shared design-system configuration fits afterward.
4
+
5
+ This is the right starting point when you are ready to try Tasty in code. If you are still evaluating it, read the [Introduction](../README.md), [Comparison](comparison.md), and [Adoption Guide](adoption.md).
4
6
 
5
7
  ---
6
8
 
@@ -10,7 +12,7 @@ This guide walks you from zero to a working Tasty component, then through the op
10
12
  - **React** >= 18 (peer dependency)
11
13
  - **Package manager**: pnpm, npm, or yarn
12
14
 
13
- Tasty can be used immediately in a React app, but it is most compelling for teams building reusable components with intersecting states, variants, tokens, and design-system conventions.
15
+ No Tasty configuration is required for the first component.
14
16
 
15
17
  ---
16
18
 
@@ -22,36 +24,57 @@ pnpm add @tenphi/tasty
22
24
 
23
25
  ---
24
26
 
25
- ## Your first component
27
+ ## Build a button whose states don’t fight
26
28
 
27
29
  ```tsx
28
30
  import { tasty } from '@tenphi/tasty';
29
31
 
30
- const Card = tasty({
31
- as: 'div',
32
+ const Button = tasty({
33
+ as: 'button',
32
34
  styles: {
33
- display: 'flex',
34
- flow: 'column',
35
- padding: '4x',
36
- gap: '2x',
37
- fill: '#white',
38
- border: true,
39
- radius: true,
35
+ padding: '12px 20px',
36
+ radius: '8px',
37
+ border: '0',
38
+ fill: {
39
+ '': 'royalblue',
40
+ ':hover': 'blue',
41
+ ':active': 'navy',
42
+ disabled: 'lightgray',
43
+ },
44
+ color: {
45
+ '': 'white',
46
+ disabled: 'dimgray',
47
+ },
48
+ cursor: {
49
+ '': 'pointer',
50
+ disabled: 'not-allowed',
51
+ },
40
52
  },
41
53
  });
42
54
 
43
55
  export default function App() {
44
- return <Card>Hello, Tasty!</Card>;
56
+ return (
57
+ <>
58
+ <Button>Save changes</Button>
59
+ <Button disabled>Disabled</Button>
60
+ </>
61
+ );
45
62
  }
46
63
  ```
47
64
 
48
- `tasty()` returns a normal React component. Values like `4x`, `#white`, `true`, and `1r` are Tasty DSL — they map to CSS custom properties, shorthand expansions, and design tokens. See [Style Properties](styles.md) for the full reference.
65
+ `tasty()` returns a normal React component. The keys in each state map define priority: later branches win over earlier ones. Because `disabled` is last, a disabled button keeps its disabled styles even while the pointer is over it.
66
+
67
+ `disabled`, `checked`, and `hidden` are built-in automatic states. Tasty sets `data-disabled`, `data-checked`, and `data-hidden` from the matching native prop, so `disabled` in a state map is the concise form of `[disabled]` (it compiles to `[data-disabled]`).
68
+
69
+ Tasty compiles that priority into selectors that exclude one another. The hover, active, and disabled background rules cannot all match and ask the CSS cascade to decide the winner.
70
+
71
+ The example uses ordinary CSS values so it works without setup. A design system will usually replace them with shared tokens, units, and state aliases in the next step. See the [Style DSL](dsl.md) for the complete state-map syntax and [Style Properties](styles.md) for Tasty’s enhanced CSS properties.
49
72
 
50
73
  ---
51
74
 
52
- ## Optional: add shared configuration
75
+ ## Add your design system’s language
53
76
 
54
- Use `configure()` once, before your app renders, when your app or design system needs shared state aliases, tokens, recipes, or parser extensions:
77
+ The first component needs no configuration. Use `configure()` once, before your app renders, when your app or design system is ready to share tokens, state aliases, recipes, units, or parser extensions:
55
78
 
56
79
  ```tsx
57
80
  // src/tasty-config.ts
@@ -78,9 +101,9 @@ import App from './App';
78
101
  createRoot(document.getElementById('root')!).render(<App />);
79
102
  ```
80
103
 
81
- ### Define shared tokens and override default unit values
104
+ ### Define shared tokens and units
82
105
 
83
- Color tokens like `#primary` resolve to CSS custom properties at runtime (e.g. `var(--primary-color)`). Built-in units like `x`, `r`, and `bw` already work without setup and multiply CSS custom properties by default. Use `configure({ tokens })` when you want to define shared token values or override the defaults your app uses:
106
+ Color tokens like `#primary` and value tokens like `$sidebar-width` resolve to CSS custom properties (`var(--primary-color)`, `var(--sidebar-width)`). Define their values with `configure({ tokens })`:
84
107
 
85
108
  ```tsx
86
109
  // src/tasty-config.ts
@@ -91,10 +114,7 @@ configure({
91
114
  '#primary': 'oklch(55% 0.25 265)',
92
115
  '#surface': '#fff',
93
116
  '#text': '#111',
94
- '$gap': '8px',
95
- '$radius': '4px',
96
- '$border-width': '1px',
97
- '$outline-width': '2px',
117
+ '$sidebar-width': '280px',
98
118
  },
99
119
  });
100
120
  ```
@@ -112,7 +132,20 @@ configure({
112
132
  });
113
133
  ```
114
134
 
115
- Every component using `#primary`, `2x`, or `1r` adjusts automatically. Tokens are injected as `:root` CSS custom properties when the first style is rendered. You can also use standard CSS color values such as `rgb(...)`, `hsl(...)`, and named colors directly; `okhsl(...)` is the recommended choice when you want authored colors that stay aligned with Tasty's design-system-oriented workflow.
135
+ Tokens are injected as `:root` CSS custom properties when the first style is rendered, and every component using `#primary` follows them. You can also use standard CSS color values such as `rgb(...)`, `hsl(...)`, and named colors directly; the built-in `okhsl(...)` and `okhst(...)` functions are the recommended choice when you want authored colors that stay aligned with Tasty's design-system-oriented workflow.
136
+
137
+ Units work differently: `x`, `r`, `cr`, `bw`, and `ow` compile to plain values when styles are generated (`2x` → `16px` with the default `8px` step), so setting a `$gap` token does not change them. Change the scale with `configure({ units })`:
138
+
139
+ ```tsx
140
+ configure({
141
+ units: {
142
+ x: '4px', // spacing step: 2x → 8px
143
+ r: '8px', // radius: 1r → 8px
144
+ },
145
+ });
146
+ ```
147
+
148
+ When the scale has to change at runtime, for example per theme or density, point the unit at a custom property and define that property as a token. With `units: { x: 'var(--gap)' }` and `tokens: { $gap: '8px' }`, `2x` compiles to `calc(2 * var(--gap))`. See [Built-in Units](dsl.md#built-in-units) for the defaults.
116
149
 
117
150
  > **Note:** `configure({ replaceTokens })` is a separate mechanism — it replaces tokens with literal values at parse time (baked into CSS). Use it for value aliases like `$card-padding: '4x'` that should be resolved during style generation, not for defining color or unit values. See [Configuration — Replace Tokens](configuration.md#replace-tokens-parse-time-substitution) for details.
118
151
 
@@ -122,7 +155,7 @@ See [Configuration](configuration.md) for the full `configure()` API — tokens,
122
155
 
123
156
  ## ESLint plugin
124
157
 
125
- The ESLint plugin catches invalid style properties, bad token references, malformed state keys, and other mistakes at lint time — before they reach the browser.
158
+ The ESLint plugin catches invalid style properties, bad token references, malformed state keys, and other mistakes at lint time — before they reach the browser. It checks style objects and JSX style props alike, and runs under both ESLint 9+ and oxlint.
126
159
 
127
160
  ### Install
128
161
 
@@ -144,54 +177,98 @@ export default [
144
177
  ];
145
178
  ```
146
179
 
147
- ### What `recommended` catches
180
+ ### Tell it about your design system
148
181
 
149
- The `recommended` config enables 18 of the plugin's 27 total rules. It covers the most common issues without turning on the stricter governance rules:
182
+ Without project configuration the plugin checks syntax and property names, but it cannot know which tokens, presets, or recipes exist. Add a `tasty.config.ts` at the project root to enable those checks for the names your `configure()` call defines:
150
183
 
151
- | Category | Rules | Examples |
152
- |----------|-------|---------|
153
- | Property validation | `known-property`, `valid-boolean-property`, `valid-sub-element` | Flags typos like `pading` or invalid boolean usage |
154
- | Value validation | `valid-value`, `valid-color-token`, `valid-custom-unit` | Catches `#nonexistent` tokens, bad unit syntax |
155
- | State validation | `valid-state-key`, `no-nested-state-map`, `require-default-state` | Validates state key syntax, ensures `''` default exists |
156
- | Structure | `valid-styles-structure`, `no-important`, `no-nested-selector` | Prevents `!important`, invalid nesting |
157
- | Static mode | `static-no-dynamic-values`, `static-valid-selector` | Enforces build-time constraints in `tastyStatic()` |
158
- | Style properties | `valid-preset`, `valid-recipe`, `valid-transition`, `valid-directional-modifier`, `valid-radius-shape` | Validates preset names, recipe references, transition syntax |
184
+ ```ts
185
+ // tasty.config.ts
186
+ export default {
187
+ tokens: ['#primary', '#surface', '#text', '$sidebar-width'],
188
+ states: ['@mobile', '@dark'],
189
+ presets: ['h1', 'h2', 't1', 't2'],
190
+ recipes: ['card'],
191
+ importSources: ['@my-org/ui'], // modules that re-export tasty()
192
+ };
193
+ ```
194
+
195
+ Every list is optional; leaving one out skips that check. `importSources` matters when your design system re-exports `tasty()` from its own module: the plugin only lints calls whose import it can trace.
196
+
197
+ ### What `recommended` catches
198
+
199
+ | Category | Rules | Examples |
200
+ | ------------------- | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------ |
201
+ | Property validation | `known-property`, `valid-boolean-property`, `valid-sub-element` | Flags typos like `pading` or invalid boolean usage |
202
+ | Value validation | `valid-value`, `valid-color-token`, `valid-custom-unit` | Catches `#nonexistent` tokens, bad unit syntax |
203
+ | State validation | `valid-state-key`, `no-nested-state-map`, `require-default-state` | Validates state key syntax, ensures `''` default exists |
204
+ | Structure | `valid-styles-structure`, `no-important`, `no-nested-selector` | Prevents `!important`, invalid nesting |
205
+ | Static mode | `static-no-dynamic-values`, `static-valid-selector` | Enforces build-time constraints in `tastyStatic()` |
206
+ | Style properties | `valid-preset`, `valid-recipe`, `valid-transition`, `valid-directional-modifier`, `valid-radius-shape` | Validates preset names, recipe references, transition syntax |
207
+ | Token usage | `no-raw-color-values`, `consistent-token-usage`, `no-raw-transition-duration` | Suggests `#color` tokens over raw colors, units over raw pixel lengths |
208
+ | Preferred syntax | `prefer-shorthand-property`, `prefer-auto-calc`, `prefer-hide`, `prefer-state-negation`, and others | Suggests `fill` over `backgroundColor`, `(...)` over `calc(...)` |
209
+ | Component props | `no-style-prop`, `no-classname-prop`, `no-styles-prop` | Points escape hatches toward `tokens`, `mods`, and the component's props |
210
+ | Dynamic styles | `no-runtime-styles-mutation`, `no-style-spread` | Warns on JavaScript values and spreads inside runtime style objects |
159
211
 
160
212
  ### Strict config
161
213
 
162
- For stricter governance, use `tasty.configs.strict`. It adds rules that enforce best practices like preferring shorthand properties, consistent token usage, and flagging direct `styles` prop usage:
214
+ For stricter governance, use `tasty.configs.strict`. It adds existence checks for `$` custom properties and `@` state aliases, and validates state definitions in `configure()` and `tasty.config.ts`:
163
215
 
164
216
  ```js
165
- export default [
166
- tasty.configs.strict,
167
- ];
217
+ export default [tasty.configs.strict];
218
+ ```
219
+
220
+ See the [plugin README](https://github.com/tenphi/eslint-plugin-tasty) for every rule, the oxlint setup, and the experimental type-aware mode for JSX props.
221
+
222
+ ---
223
+
224
+ ## TypeScript autocomplete
225
+
226
+ Component props are typed from their definitions without extra setup: `modProps` value lists become unions, `variant` is typed from the variant keys, and sub-elements are typed components. To get autocomplete for your own token, preset, and theme names inside style values, register them with module augmentation:
227
+
228
+ ```ts
229
+ // tasty.d.ts
230
+ import '@tenphi/tasty';
231
+
232
+ declare module '@tenphi/tasty' {
233
+ interface TastyNamedColors {
234
+ primary: true;
235
+ surface: true;
236
+ text: true;
237
+ }
238
+ interface TastyPresetNames {
239
+ h1: true;
240
+ t2: true;
241
+ }
242
+ }
168
243
  ```
169
244
 
245
+ See [Configuration → TypeScript](configuration.md#typescript) for every augmentation interface and how component props are typed.
246
+
170
247
  ---
171
248
 
172
249
  ## Editor support
173
250
 
174
- **[VS Code Extension](https://github.com/tenphi/tasty-vscode-extension)** — Syntax highlighting for Tasty styles in TypeScript/TSX/JavaScript/JSX. Highlights color tokens, custom units, state keys, presets, and style properties inside `tasty()` and `tastyStatic()` calls. Install from the VS Code marketplace or from a `.vsix` file.
251
+ **[VS Code Extension](https://github.com/tenphi/tasty-vscode-extension)** — Syntax highlighting for Tasty styles in TypeScript/TSX/JavaScript/JSX: color tokens, custom units, state keys, presets, and style properties inside `tasty()`, `tastyStatic()`, `styles` objects, and style functions. It also adds snippets for components, state maps, and `configure()`. Install the `.vsix` from the [latest GitHub release](https://github.com/tenphi/tasty-vscode-extension/releases/latest); the extension is not published to the marketplace.
175
252
 
176
- **[Glaze](https://github.com/tenphi/glaze)** — OKHSL-based color theme generator with automatic WCAG contrast solving. Generate light, dark, and high-contrast color palettes from a single hue and export them directly as Tasty color tokens. See the [Ecosystem section](../README.md#ecosystem) in the README.
253
+ **[Glaze](https://github.com/tenphi/glaze)** — Not an editor tool, but the fastest way to fill `configure({ tokens })`: it generates light, dark, and high-contrast palettes from one hue in the OKHST color space, solves WCAG and APCA contrast, and exports them as Tasty tokens with `configure({ tokens: theme.tasty() })`. See [Glaze in the README](../README.md#glaze).
177
254
 
178
255
  ---
179
256
 
180
257
  ## Choosing a rendering mode
181
258
 
182
- `tasty()` is the default for all React apps. All `tasty()` components and style functions are hook-free and work as React Server Components without `'use client'`. In server-only contexts, they produce zero client JavaScript with the full feature set.
259
+ `tasty()` is the default for all React apps. All `tasty()` components and style functions are hook-free and work as React Server Components without `'use client'`. Zero-runtime delivery is not tied to one API: both server-only `tasty()` and build-time `tastyStatic()` can ship no Tasty styling runtime to the browser.
183
260
 
184
- | Approach | Entry point | Best for | Trade-off |
185
- |------|-------------|----------|-----------|
186
- | **Runtime (default)** | `tasty()` from `@tenphi/tasty` | All React apps — server-rendered by default, zero client JS until you need interactivity | Full feature set (styleProps, sub-elements, variants); CSS computed during rendering |
187
- | **Runtime + SSR integration** | Add `@tenphi/tasty/ssr/*` | Apps with client-side hydration (Next.js client components, Astro islands) | Adds CSS batching, deduplication, FOUC prevention, and client cache hydration |
188
- | **Zero-runtime** | `tastyStatic()` from `@tenphi/tasty/static` | Non-React frameworks or build-time extraction without React | Requires Babel plugin; no `styleProps` or runtime-only APIs |
261
+ | Approach | Authoring API | CSS is generated | Tasty runtime in the browser | Best for |
262
+ | ------------------------- | ------------------------------------------- | ----------------------------------- | ---------------------------- | ---------------------------------------------------------------- |
263
+ | **Server-only React** | `tasty()`; optional `@tenphi/tasty/ssr/*` | During server or static rendering | None | Astro without islands, server-only RSC, SSG |
264
+ | **Hydrated React** | `tasty()` plus `@tenphi/tasty/ssr/*` | During SSR, then on demand in React | Only in hydrated components | Interactive React apps, Next.js client components, Astro islands |
265
+ | **Build-time extraction** | `tastyStatic()` from `@tenphi/tasty/static` | During the build | None in file mode | Non-React frameworks or extraction before rendering |
189
266
 
190
267
  Both `tasty()` and `tastyStatic()` share the same DSL, tokens, units, and state mappings.
191
268
 
192
- - **Runtime** is the default and requires no extra setup beyond `@tenphi/tasty`. In server-only contexts (Next.js RSC, Astro without `client:*` directives, SSG), `tasty()` produces static HTML + CSS with zero client JavaScript — the same end result as `tastyStatic()` but with the full feature set. For example, `tasty()` + `tastyIntegration()` in Astro without islands gives you the complete API with zero JS shipped.
193
- - **SSR integration** is only needed when your app also has client-side rendering. Add `@tenphi/tasty/ssr/next`, `@tenphi/tasty/ssr/astro`, or the core SSR API to get CSS deduplication and cache hydration. See [Server-Side Rendering](ssr.md).
194
- - **Zero-runtime** requires the Babel plugin and additional peer dependencies. Use it when you need build-time extraction without a React runtime. See [Zero Runtime (tastyStatic)](tasty-static.md).
269
+ - **Server-only `tasty()`** keeps the full feature set (`styleProps`, sub-elements, variants) while generating CSS during server rendering. `tasty()` plus `tastyIntegration({ islands: false })` in Astro is the verified concrete setup and ships no client JavaScript. The same server-only architecture applies to Next.js RSC; verify the generated output for your deployment.
270
+ - **Hydrated `tasty()`** uses the SSR integrations to batch and deduplicate server CSS, prevent FOUC, and hydrate the client cache. The browser styling pipeline is available only where React components hydrate. See [Server-Side Rendering](ssr.md).
271
+ - **Build-time extraction** uses the Babel plugin and additional peer dependencies. Choose `tastyStatic()` when CSS must be generated before rendering or when the consumer is not React. File mode ships no styling runtime; inject mode intentionally includes a tiny CSS injector. See [Build-Time Extraction (`tastyStatic`)](tasty-static.md).
195
272
 
196
273
  ---
197
274
 
@@ -205,6 +282,7 @@ Both `tasty()` and `tastyStatic()` share the same DSL, tokens, units, and state
205
282
  - **[Adoption Guide](adoption.md)** — Roll out Tasty inside an existing design system or platform team
206
283
  - **[Comparison](comparison.md)** — Evaluate Tasty against other styling systems
207
284
  - **[Configuration](configuration.md)** — Full `configure()` API: tokens, recipes, custom units, style handlers, TypeScript extensions
285
+ - **[Plugins & Extension Points](plugins.md)** — Add your own style properties, units, functions, and component props
208
286
  - **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
209
287
  - **[Debug Utilities](debug.md)** — Inspect generated CSS and debug runtime behavior when styles do not look right
210
288
 
@@ -214,4 +292,6 @@ Both `tasty()` and `tastyStatic()` share the same DSL, tokens, units, and state
214
292
 
215
293
  - Styles are missing on first render: make sure the file that calls `configure()` is imported before any `tasty()` component renders.
216
294
  - Token or unit values are not what you expect: check your `configure({ tokens, units })` setup, then inspect the generated CSS variables with [Debug Utilities](debug.md).
217
- - You need build-time extraction or server-rendered CSS delivery: use [Zero Runtime (tastyStatic)](tasty-static.md) for extraction, or add [Server-Side Rendering](ssr.md) on top of runtime `tasty()` when your framework renders on the server.
295
+ - Changing a `$gap` or `$radius` token does not change `2x` or `1r`: units compile to plain values from `configure({ units })`. Point a unit at the custom property (`units: { x: 'var(--gap)' }`) if it should follow the token.
296
+ - The linter accepts unknown tokens or presets: list them in `tasty.config.ts` so the plugin knows what your design system defines.
297
+ - You need zero-runtime delivery: use server-only [`tasty()` with server rendering](ssr.md) to keep the full React API, or use [`tastyStatic()` build-time extraction](tasty-static.md) when styles must be compiled before rendering.
package/docs/injector.md CHANGED
@@ -9,11 +9,11 @@ A high-performance CSS-in-JS solution that powers the Tasty design system with e
9
9
  The Style Injector is the core engine behind Tasty's styling system, providing:
10
10
 
11
11
  - **Hash-based deduplication** - Identical CSS gets the same className
12
- - **Reference counting** - Automatic cleanup when components unmount (refCount = 0)
13
- - **CSS nesting flattening** - Handles `&`, `.Class`, `SubElement` patterns
12
+ - **DOM-driven lifetime** - Styles are collected once nothing renders them
13
+ - **Selector assembly** - Prepends the doubled `.tX.tX` class and root prefix to the pipeline's selector fragments (sub-element and `&` nesting is flattened earlier, by the pipeline)
14
14
  - **At-rule injection** - First-class `@keyframes`, `@property`, `@font-face`, `@counter-style`, and `@function` support
15
15
  - **Smart cleanup** - CSS rules batched cleanup, keyframes disposed immediately
16
- - **SSR support** - Deterministic class names and CSS extraction
16
+ - **SSR support** - Deterministic class names shared with `ServerStyleCollector`, and hydration of server-rendered classes
17
17
  - **Multiple roots** - Works with Document and ShadowRoot
18
18
  - **Non-stacking cleanups** - Prevents timeout accumulation for better performance
19
19
 
@@ -55,18 +55,26 @@ Injects CSS rules and returns a className with dispose function.
55
55
  ```typescript
56
56
  import { inject } from '@tenphi/tasty';
57
57
 
58
- // Component styling - generates tasty class names
58
+ // Rules flagged needsClassName get the generated class prepended (doubled)
59
59
  const result = inject([{
60
- selector: '.t-abc123',
60
+ selector: '',
61
61
  declarations: 'color: red; padding: 10px;',
62
+ needsClassName: true,
62
63
  }]);
63
64
 
64
- console.log(result.className); // 't-abc123'
65
+ console.log(result.className); // 'th8n0uh' — `t` + base36 hash of the rules
66
+ // Injected: .th8n0uh.th8n0uh { color: red; padding: 10px; }
65
67
 
66
- // Cleanup when component unmounts (refCount decremented)
68
+ // Release the pin; the class becomes collectible once nothing renders it
67
69
  result.dispose();
68
70
  ```
69
71
 
72
+ `inject()` **pins** the class it returns, and `gc()` never evicts a pinned class
73
+ — that is what `dispose()` releases. Pass `{ pin: false }` when the caller keeps
74
+ no handle and the DOM is the only record that the class is in use; `dispose()`
75
+ is then a no-op. The render path (`tasty()` / `computeStyles()`) injects this
76
+ way, because a hook-free render has no unmount signal to dispose on.
77
+
70
78
  ### `injectGlobal(rules, options?): { dispose: () => void }`
71
79
 
72
80
  Injects global styles that don't reserve tasty class names.
@@ -169,7 +177,7 @@ const result = testInjector.inject(rules);
169
177
  Injects CSS keyframes with automatic deduplication.
170
178
 
171
179
  ```typescript
172
- // Generated name (k0, k1, k2...)
180
+ // Generated name (tk0, tk1, … — namePrefix + 'k' + counter)
173
181
  const fadeIn = keyframes({
174
182
  from: { opacity: 0 },
175
183
  to: { opacity: 1 },
@@ -245,8 +253,30 @@ Dispose, ref-counted cleanup and GC therefore behave identically in every mode.
245
253
  - Most options have sensible defaults and auto-detection
246
254
  - `configure()` is optional - the injector works with defaults
247
255
  - **Configuration is locked after styles are generated** - calling `configure()` after first render will emit a warning and be ignored
248
- - `gc.touchInterval`: Number of touch events between GC cycles. Each style render counts as a touch. When the counter reaches this value, GC is scheduled via `requestIdleCallback`.
249
- - `gc.capacity`: Maximum number of unused styles (refCount = 0, not in DOM) to retain. When exceeded, the oldest are evicted first. Actively referenced styles don't count against this limit.
256
+ - `gc.touchInterval`: Number of renders between sweeps. When the counter reaches this value, a sweep is scheduled via `requestIdleCallback`; without idle callbacks nothing is collected automatically.
257
+ - `gc.grace`: How long a class is left alone after collection first notices nothing is carrying it, in milliseconds (default `10000`).
258
+ - Automatic sweeps are opt-in: they run only when `configure({ gc })` is set (`gc: {}` enables them with these defaults). Without it nothing is collected until you call `gc()` or `cleanup()`.
259
+
260
+ **What a sweep does.** Everything the injector holds falls into one of five bands, and only the last is ever deleted:
261
+
262
+ | Band | | Deleted |
263
+ |---|---|---|
264
+ | 1 | **Rendered** — some element carries the class right now | never |
265
+ | 2 | **Not ours** — queued for a batched write, pre-allocated, or server-rendered | never |
266
+ | 3 | **Hot** — nothing carries it, but that was noticed less than `grace` ago | never |
267
+ | 4 | **Cached** — cold, but within `capacity` when ordered by when it went cold | never |
268
+ | 5 | Everything else | on every sweep |
269
+
270
+ `gc({ force: true })` and `cleanup()` take bands 4 and 5 together, ignoring capacity. Band 3 is spared even then: an explicit cleanup is still no reason to take rules from a render that has not committed yet.
271
+
272
+ `tasty()` components cache the class names they computed, so a re-render with the same styles skips the pipeline. Whenever `gc()`, `cleanup()` or `destroy()` deletes rules, those caches are dropped too, so a component whose CSS was collected injects it again on its next render.
273
+
274
+ > **Why band 3 exists.** Rendering is not commit-aware: a render can resolve a class and commit it a little later, and in between nothing on the page carries it. From outside React that is indistinguishable from a class that is finished, so collection does not try to tell them apart — it leaves alone anything only just noticed to be cold. A render would have to stay pending for the whole window to lose its rules, and it gets them back on its next render.
275
+ >
276
+ > The clock starts when a sweep *notices*, not when the element actually left — nothing observes that moment, so starting it at the sighting is what gives every class the same full window however long ago it went.
277
+ >
278
+ > This is also why collection costs nothing to run: the timestamps are written by the sweep's own DOM scan, so rendering tracks nothing per class.
279
+ - `gc.capacity`: Maximum number of unused styles (not in the DOM, not pinned) to retain. When exceeded, the least recently used are evicted first. Rendered and pinned styles don't count against this limit.
250
280
 
251
281
  ---
252
282
 
@@ -264,7 +294,7 @@ Beyond ordinary rules, the injector has a dedicated entry point per at-rule. All
264
294
 
265
295
  Every one of these takes an optional `root` (a `Document` or `ShadowRoot`).
266
296
 
267
- `func()` also accepts `weak: true`, which registers the rule **without** overriding an existing one of the same name. `configure()` uses it for global `@function` definitions so a component-local definition always wins over the global default, regardless of which is injected first.
297
+ `counterStyle()` and `func()` also accept `weak: true`, which registers the rule **without** overriding an existing one of the same name. `configure()` uses it for global `@counter-style` and `@function` definitions so a component-local definition always wins over the global default, regardless of which is injected first.
268
298
 
269
299
  ```ts
270
300
  import { counterStyle, fontFace, func, property } from '@tenphi/tasty';
@@ -281,22 +311,24 @@ func('$$negative', { args: ['$value'], result: '(-1 * $value)' });
281
311
 
282
312
  ### Style Result Format
283
313
 
284
- The injector works with `StyleResult` objects from the tasty parser:
314
+ The injector works with `StyleResult` objects from the pipeline (`renderStyles`):
285
315
 
286
316
  ```typescript
287
317
  interface StyleResult {
288
- selector: string; // CSS selector
289
- declarations: string; // CSS declarations
290
- atRules?: string[]; // @media, @supports, etc.
291
- nestingLevel?: number; // Nesting depth for specificity
318
+ selector: string; // full selector, or a fragment when needsClassName
319
+ declarations: string; // CSS declarations
320
+ atRules?: string[]; // @media, @container, @supports, …
321
+ needsClassName?: boolean; // prepend the generated `.tX.tX` (OR'd fragments joined with '|||')
322
+ rootPrefix?: string; // root-state prefix placed before the class
323
+ startingStyle?: boolean; // wrap declarations in @starting-style
292
324
  }
293
325
 
294
326
  // Example StyleResult
295
327
  const styleRule: StyleResult = {
296
- selector: '.t-button',
328
+ selector: ':where([data-hovered])',
297
329
  declarations: 'padding: 8px 16px; background: blue; color: white;',
298
330
  atRules: ['@media (min-width: 768px)'],
299
- nestingLevel: 0,
331
+ needsClassName: true,
300
332
  };
301
333
  ```
302
334
 
@@ -314,38 +346,39 @@ API here calls it for you.
314
346
  ### Deduplication & Performance
315
347
 
316
348
  ```typescript
317
- // Identical CSS rules get the same className
318
- const button1 = inject([{
319
- selector: '.t-btn1',
320
- declarations: 'padding: 8px; color: red;'
321
- }]);
349
+ const rule = { selector: '', declarations: 'padding: 8px; color: red;', needsClassName: true };
322
350
 
323
- const button2 = inject([{
324
- selector: '.t-btn2',
325
- declarations: 'padding: 8px; color: red;' // Same declarations
326
- }]);
351
+ const button1 = inject([rule], { cacheKey: 'button' });
352
+ const button2 = inject([rule], { cacheKey: 'button' });
327
353
 
328
- // Both get the same className due to deduplication
354
+ // One class, one copy of the CSS
329
355
  console.log(button1.className === button2.className); // true
330
356
  ```
331
357
 
332
- ### Reference Counting
358
+ Without `cacheKey` the class name is a hash of the rules, so injecting the same rules again reuses the class the same way: the rules are written once, and each call adds a pin that its own `dispose()` releases.
359
+
360
+ ### Pinning
333
361
 
334
362
  ```typescript
335
- // Multiple components using the same styles
336
- const comp1 = inject([commonStyle]);
337
- const comp2 = inject([commonStyle]);
338
- const comp3 = inject([commonStyle]);
339
-
340
- // Style is kept alive while any component uses it
341
- comp1.dispose(); // refCount: 3 → 2
342
- comp2.dispose(); // refCount: 2 → 1
343
- comp3.dispose(); // refCount: 1 → 0, eligible for bulk cleanup
344
-
345
- // Rule exists but refCount = 0 means unused
346
- // Next inject() with same styles will increment refCount and reuse immediately
363
+ // Multiple callers using the same styles
364
+ const comp1 = inject([commonStyle], { cacheKey: 'common' });
365
+ const comp2 = inject([commonStyle], { cacheKey: 'common' });
366
+ const comp3 = inject([commonStyle], { cacheKey: 'common' });
367
+
368
+ // Style is pinned while any caller holds a handle
369
+ comp1.dispose(); // pins: 3 → 2
370
+ comp2.dispose(); // pins: 2 → 1
371
+ comp3.dispose(); // pins: 1 → 0, now up to the DOM and gc()
372
+
373
+ // Unpinned does not mean deleted: the rule stays cached and is reused instantly
374
+ // by the next inject(). gc() decides when it actually goes.
347
375
  ```
348
376
 
377
+ Pinning covers callers that hold a handle. Styles that come from rendering are
378
+ never pinned — see `{ pin: false }` under
379
+ [`inject()`](#injectrules-options-injectresult) — so what keeps them alive is
380
+ being in the DOM, and nothing else.
381
+
349
382
  ### Garbage Collection
350
383
 
351
384
  ```typescript
@@ -353,6 +386,9 @@ import { configure, gc } from '@tenphi/tasty';
353
386
 
354
387
  // Keyframes: Disposed immediately when refCount = 0 (safer for global scope)
355
388
  // CSS rules: Tracked by touch count and cleaned up via gc()
389
+ //
390
+ // A CSS rule is collectible when no element carries its class AND nobody
391
+ // pinned it with inject().
356
392
 
357
393
  configure({
358
394
  gc: {
@@ -367,15 +403,19 @@ gc();
367
403
  // Force-remove ALL unused styles (e.g. on route change or test teardown):
368
404
  gc({ force: true });
369
405
 
370
- // GC is also triggered automatically by touch count during rendering.
371
- // Every `touchInterval` touches, GC is scheduled via requestIdleCallback.
406
+ // cleanup() is the same thing:
407
+ cleanup();
408
+
409
+ // Every `touchInterval` renders, a sweep is scheduled in idle time. It scans
410
+ // the DOM for the classes actually on the page and sorts everything the
411
+ // injector holds into five bands — only the last one is deleted. See below.
372
412
 
373
413
  // Benefits:
374
414
  // - Activity-proportional: busy apps trigger GC more often
375
415
  // - DOM-safe: styles currently in the DOM are never evicted
376
416
  // - Oldest-first: least recently used styles are evicted first
377
417
  // - Keyframes: Immediate cleanup prevents global namespace pollution
378
- // - Unused styles can be instantly reactivated (just increment refCount)
418
+ // - Unused styles stay cached until evicted, so re-rendering them is a cache hit
379
419
  ```
380
420
 
381
421
  ### Shadow DOM Support
@@ -402,15 +442,16 @@ const shadowAnimation = keyframes({
402
442
 
403
443
  ### Server-Side Rendering
404
444
 
445
+ `getCSSText()` reads the injector's stylesheets, so it needs a DOM; on a server it throws. Collect server CSS with `ServerStyleCollector` from `@tenphi/tasty/ssr` (`collector.getCSS()`) — see [SSR](./ssr.md).
446
+
405
447
  ```typescript
406
448
  import { getCSSText, getCSSTextForNode } from '@tenphi/tasty';
449
+ import { render } from '@testing-library/react';
407
450
 
408
- // Extract all CSS for SSR
409
- const cssText = getCSSText();
451
+ const cssText = getCSSText(); // everything the injector holds (browser / test DOM)
410
452
 
411
- // Extract CSS for specific DOM subtree (like jest-styled-components)
412
- const container = render(<MyComponent />);
413
- const componentCSS = getCSSTextForNode(container);
453
+ const { container } = render(<MyComponent />);
454
+ const componentCSS = getCSSTextForNode(container); // only the CSS this subtree uses
414
455
  ```
415
456
 
416
457
  ### Test Environment Detection
@@ -470,11 +511,11 @@ const metrics = injector.instance.getMetrics();
470
511
  console.log({
471
512
  cacheHits: metrics.hits, // Successful cache hits
472
513
  cacheMisses: metrics.misses, // New styles injected
473
- unusedHits: metrics.unusedHits, // Current unused styles (calculated on demand)
514
+ unusedHits: metrics.unusedHits, // Styles currently eligible for eviction (scans the DOM)
474
515
  bulkCleanups: metrics.bulkCleanups, // Number of bulk cleanup operations
475
516
  stylesCleanedUp: metrics.stylesCleanedUp, // Total styles removed in bulk cleanups
476
517
  totalInsertions: metrics.totalInsertions, // Lifetime insertions
477
- totalUnused: metrics.totalUnused, // Total styles marked as unused (refCount = 0)
518
+ totalUnused: metrics.totalUnused, // Times a pinned style lost its last pin
478
519
  startTime: metrics.startTime, // Metrics collection start timestamp
479
520
  cleanupHistory: metrics.cleanupHistory, // Detailed cleanup operation history
480
521
  });
@@ -483,17 +524,14 @@ console.log({
483
524
  ### Debug Information
484
525
 
485
526
  ```typescript
486
- // Get detailed information about injected styles
487
- const debugInfo = injector.instance.getDebugInfo();
527
+ import { tastyDebug } from '@tenphi/tasty';
488
528
 
489
- console.log({
490
- activeStyles: debugInfo.activeStyles, // Currently active styles
491
- unusedStyles: debugInfo.unusedStyles, // Styles marked for cleanup
492
- totalSheets: debugInfo.totalSheets, // Number of stylesheets
493
- totalRules: debugInfo.totalRules, // Total CSS rules
494
- });
529
+ const { activeClasses, unusedClasses, hotClasses, totalRuleCount } =
530
+ tastyDebug.summary({ raw: true });
495
531
  ```
496
532
 
533
+ See [Debug Utilities](./debug.md).
534
+
497
535
  ### Cleanup History
498
536
 
499
537
  ```typescript
@@ -518,10 +556,10 @@ metrics.cleanupHistory.forEach(cleanup => {
518
556
 
519
557
  ```typescript
520
558
  // ✅ Reuse styles - identical CSS gets deduplicated
521
- const buttonBase = { padding: '8px 16px', borderRadius: '4px' };
559
+ const buttonBase = 'padding: 8px 16px; border-radius: 4px;';
522
560
 
523
561
  // ✅ Avoid frequent disposal and re-injection
524
- // Let the reference counting system handle cleanup
562
+ // Let the injector handle cleanup
525
563
 
526
564
  // ✅ Use bulk operations for global styles
527
565
  injectGlobal([
@@ -547,13 +585,13 @@ configure({
547
585
  // The injector automatically manages memory through:
548
586
 
549
587
  // 1. Hash-based deduplication - same CSS = same className
550
- // 2. Reference counting - styles stay alive while in use (refCount > 0)
551
- // 3. Immediate keyframes cleanup - disposed instantly when refCount = 0
552
- // 4. Touch-count GC - unused CSS rules are evicted oldest-first when over capacity
553
- // 5. DOM safety guard - styles visible in the DOM are never evicted
588
+ // 2. DOM-driven lifetime - a rendered class is never evicted
589
+ // 3. Pinning - inject() callers hold their classes until they dispose
590
+ // 4. Immediate keyframes cleanup - disposed instantly when refCount = 0
591
+ // 5. Touch-count GC - unused CSS rules are evicted oldest-first when over capacity
554
592
 
555
593
  // Manual cleanup is rarely needed but available:
556
- cleanup(); // Force immediate cleanup of all unused CSS rules (refCount = 0)
594
+ cleanup(); // Remove every rule that is neither rendered nor pinned
557
595
  destroy(); // Nuclear option: remove all stylesheets and reset
558
596
  ```
559
597
 
@@ -575,9 +613,9 @@ const StyledButton = tasty({
575
613
 
576
614
  // Internally uses the injector:
577
615
  // 1. Styles are parsed into StyleResult objects
578
- // 2. inject() is called with the parsed results
616
+ // 2. inject() is called with the parsed results, unpinned
579
617
  // 3. Component gets the returned className
580
- // 4. dispose() is called when component unmounts
618
+ // 4. gc() reclaims the class once no element carries it
581
619
  ```
582
620
 
583
621
  For most development, you'll use the [React API](./react-api.md) rather than the injector directly. The injector provides the high-performance foundation that makes Tasty's declarative styling possible.