@tenphi/tasty 0.0.0-snapshot.12940ba

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 (242) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +464 -0
  3. package/dist/_virtual/_rolldown/runtime.js +8 -0
  4. package/dist/chunks/cacheKey.d.ts +1 -0
  5. package/dist/chunks/cacheKey.js +70 -0
  6. package/dist/chunks/cacheKey.js.map +1 -0
  7. package/dist/chunks/definitions.d.ts +37 -0
  8. package/dist/chunks/definitions.js +260 -0
  9. package/dist/chunks/definitions.js.map +1 -0
  10. package/dist/chunks/index.d.ts +3 -0
  11. package/dist/chunks/renderChunk.d.ts +2 -0
  12. package/dist/chunks/renderChunk.js +61 -0
  13. package/dist/chunks/renderChunk.js.map +1 -0
  14. package/dist/config.d.ts +280 -0
  15. package/dist/config.js +403 -0
  16. package/dist/config.js.map +1 -0
  17. package/dist/debug.d.ts +204 -0
  18. package/dist/debug.js +733 -0
  19. package/dist/debug.js.map +1 -0
  20. package/dist/hooks/index.d.ts +5 -0
  21. package/dist/hooks/useGlobalStyles.d.ts +27 -0
  22. package/dist/hooks/useGlobalStyles.js +56 -0
  23. package/dist/hooks/useGlobalStyles.js.map +1 -0
  24. package/dist/hooks/useKeyframes.d.ts +56 -0
  25. package/dist/hooks/useKeyframes.js +54 -0
  26. package/dist/hooks/useKeyframes.js.map +1 -0
  27. package/dist/hooks/useProperty.d.ts +79 -0
  28. package/dist/hooks/useProperty.js +91 -0
  29. package/dist/hooks/useProperty.js.map +1 -0
  30. package/dist/hooks/useRawCSS.d.ts +53 -0
  31. package/dist/hooks/useRawCSS.js +28 -0
  32. package/dist/hooks/useRawCSS.js.map +1 -0
  33. package/dist/hooks/useStyles.d.ts +40 -0
  34. package/dist/hooks/useStyles.js +169 -0
  35. package/dist/hooks/useStyles.js.map +1 -0
  36. package/dist/index.d.ts +38 -0
  37. package/dist/index.js +30 -0
  38. package/dist/injector/index.d.ts +157 -0
  39. package/dist/injector/index.js +154 -0
  40. package/dist/injector/index.js.map +1 -0
  41. package/dist/injector/injector.d.ts +139 -0
  42. package/dist/injector/injector.js +404 -0
  43. package/dist/injector/injector.js.map +1 -0
  44. package/dist/injector/sheet-manager.d.ts +127 -0
  45. package/dist/injector/sheet-manager.js +714 -0
  46. package/dist/injector/sheet-manager.js.map +1 -0
  47. package/dist/injector/types.d.ts +135 -0
  48. package/dist/keyframes/index.js +206 -0
  49. package/dist/keyframes/index.js.map +1 -0
  50. package/dist/parser/classify.js +319 -0
  51. package/dist/parser/classify.js.map +1 -0
  52. package/dist/parser/const.js +33 -0
  53. package/dist/parser/const.js.map +1 -0
  54. package/dist/parser/index.d.ts +3 -0
  55. package/dist/parser/index.js +4 -0
  56. package/dist/parser/lru.js +109 -0
  57. package/dist/parser/lru.js.map +1 -0
  58. package/dist/parser/parser.d.ts +25 -0
  59. package/dist/parser/parser.js +116 -0
  60. package/dist/parser/parser.js.map +1 -0
  61. package/dist/parser/tokenizer.js +69 -0
  62. package/dist/parser/tokenizer.js.map +1 -0
  63. package/dist/parser/types.d.ts +51 -0
  64. package/dist/parser/types.js +46 -0
  65. package/dist/parser/types.js.map +1 -0
  66. package/dist/pipeline/conditions.js +398 -0
  67. package/dist/pipeline/conditions.js.map +1 -0
  68. package/dist/pipeline/exclusive.d.ts +1 -0
  69. package/dist/pipeline/exclusive.js +231 -0
  70. package/dist/pipeline/exclusive.js.map +1 -0
  71. package/dist/pipeline/index.d.ts +53 -0
  72. package/dist/pipeline/index.js +642 -0
  73. package/dist/pipeline/index.js.map +1 -0
  74. package/dist/pipeline/materialize.js +894 -0
  75. package/dist/pipeline/materialize.js.map +1 -0
  76. package/dist/pipeline/parseStateKey.d.ts +1 -0
  77. package/dist/pipeline/parseStateKey.js +439 -0
  78. package/dist/pipeline/parseStateKey.js.map +1 -0
  79. package/dist/pipeline/simplify.js +557 -0
  80. package/dist/pipeline/simplify.js.map +1 -0
  81. package/dist/plugins/index.d.ts +2 -0
  82. package/dist/plugins/okhsl-plugin.d.ts +35 -0
  83. package/dist/plugins/okhsl-plugin.js +371 -0
  84. package/dist/plugins/okhsl-plugin.js.map +1 -0
  85. package/dist/plugins/types.d.ts +69 -0
  86. package/dist/properties/index.js +158 -0
  87. package/dist/properties/index.js.map +1 -0
  88. package/dist/states/index.d.ts +45 -0
  89. package/dist/states/index.js +416 -0
  90. package/dist/states/index.js.map +1 -0
  91. package/dist/static/index.d.ts +5 -0
  92. package/dist/static/index.js +5 -0
  93. package/dist/static/tastyStatic.d.ts +46 -0
  94. package/dist/static/tastyStatic.js +31 -0
  95. package/dist/static/tastyStatic.js.map +1 -0
  96. package/dist/static/types.d.ts +49 -0
  97. package/dist/static/types.js +24 -0
  98. package/dist/static/types.js.map +1 -0
  99. package/dist/styles/align.d.ts +15 -0
  100. package/dist/styles/align.js +14 -0
  101. package/dist/styles/align.js.map +1 -0
  102. package/dist/styles/border.d.ts +25 -0
  103. package/dist/styles/border.js +114 -0
  104. package/dist/styles/border.js.map +1 -0
  105. package/dist/styles/color.d.ts +14 -0
  106. package/dist/styles/color.js +23 -0
  107. package/dist/styles/color.js.map +1 -0
  108. package/dist/styles/createStyle.js +77 -0
  109. package/dist/styles/createStyle.js.map +1 -0
  110. package/dist/styles/dimension.js +97 -0
  111. package/dist/styles/dimension.js.map +1 -0
  112. package/dist/styles/display.d.ts +37 -0
  113. package/dist/styles/display.js +67 -0
  114. package/dist/styles/display.js.map +1 -0
  115. package/dist/styles/fade.d.ts +15 -0
  116. package/dist/styles/fade.js +58 -0
  117. package/dist/styles/fade.js.map +1 -0
  118. package/dist/styles/fill.d.ts +44 -0
  119. package/dist/styles/fill.js +51 -0
  120. package/dist/styles/fill.js.map +1 -0
  121. package/dist/styles/flow.d.ts +16 -0
  122. package/dist/styles/flow.js +12 -0
  123. package/dist/styles/flow.js.map +1 -0
  124. package/dist/styles/gap.d.ts +31 -0
  125. package/dist/styles/gap.js +37 -0
  126. package/dist/styles/gap.js.map +1 -0
  127. package/dist/styles/height.d.ts +17 -0
  128. package/dist/styles/height.js +20 -0
  129. package/dist/styles/height.js.map +1 -0
  130. package/dist/styles/index.d.ts +2 -0
  131. package/dist/styles/index.js +9 -0
  132. package/dist/styles/index.js.map +1 -0
  133. package/dist/styles/inset.d.ts +50 -0
  134. package/dist/styles/inset.js +142 -0
  135. package/dist/styles/inset.js.map +1 -0
  136. package/dist/styles/justify.d.ts +15 -0
  137. package/dist/styles/justify.js +14 -0
  138. package/dist/styles/justify.js.map +1 -0
  139. package/dist/styles/list.d.ts +16 -0
  140. package/dist/styles/list.js +98 -0
  141. package/dist/styles/list.js.map +1 -0
  142. package/dist/styles/margin.d.ts +28 -0
  143. package/dist/styles/margin.js +96 -0
  144. package/dist/styles/margin.js.map +1 -0
  145. package/dist/styles/outline.d.ts +29 -0
  146. package/dist/styles/outline.js +65 -0
  147. package/dist/styles/outline.js.map +1 -0
  148. package/dist/styles/padding.d.ts +28 -0
  149. package/dist/styles/padding.js +96 -0
  150. package/dist/styles/padding.js.map +1 -0
  151. package/dist/styles/predefined.d.ts +74 -0
  152. package/dist/styles/predefined.js +241 -0
  153. package/dist/styles/predefined.js.map +1 -0
  154. package/dist/styles/preset.d.ts +47 -0
  155. package/dist/styles/preset.js +126 -0
  156. package/dist/styles/preset.js.map +1 -0
  157. package/dist/styles/radius.d.ts +14 -0
  158. package/dist/styles/radius.js +51 -0
  159. package/dist/styles/radius.js.map +1 -0
  160. package/dist/styles/scrollbar.d.ts +21 -0
  161. package/dist/styles/scrollbar.js +105 -0
  162. package/dist/styles/scrollbar.js.map +1 -0
  163. package/dist/styles/shadow.d.ts +14 -0
  164. package/dist/styles/shadow.js +24 -0
  165. package/dist/styles/shadow.js.map +1 -0
  166. package/dist/styles/styledScrollbar.d.ts +47 -0
  167. package/dist/styles/styledScrollbar.js +38 -0
  168. package/dist/styles/styledScrollbar.js.map +1 -0
  169. package/dist/styles/transition.d.ts +14 -0
  170. package/dist/styles/transition.js +138 -0
  171. package/dist/styles/transition.js.map +1 -0
  172. package/dist/styles/types.d.ts +498 -0
  173. package/dist/styles/width.d.ts +17 -0
  174. package/dist/styles/width.js +20 -0
  175. package/dist/styles/width.js.map +1 -0
  176. package/dist/tasty.d.ts +983 -0
  177. package/dist/tasty.js +191 -0
  178. package/dist/tasty.js.map +1 -0
  179. package/dist/tokens/typography.d.ts +19 -0
  180. package/dist/tokens/typography.js +237 -0
  181. package/dist/tokens/typography.js.map +1 -0
  182. package/dist/types.d.ts +182 -0
  183. package/dist/utils/cache-wrapper.js +26 -0
  184. package/dist/utils/cache-wrapper.js.map +1 -0
  185. package/dist/utils/case-converter.js +8 -0
  186. package/dist/utils/case-converter.js.map +1 -0
  187. package/dist/utils/colors.d.ts +5 -0
  188. package/dist/utils/colors.js +9 -0
  189. package/dist/utils/colors.js.map +1 -0
  190. package/dist/utils/dotize.d.ts +26 -0
  191. package/dist/utils/dotize.js +122 -0
  192. package/dist/utils/dotize.js.map +1 -0
  193. package/dist/utils/filter-base-props.d.ts +15 -0
  194. package/dist/utils/filter-base-props.js +45 -0
  195. package/dist/utils/filter-base-props.js.map +1 -0
  196. package/dist/utils/get-display-name.d.ts +7 -0
  197. package/dist/utils/get-display-name.js +10 -0
  198. package/dist/utils/get-display-name.js.map +1 -0
  199. package/dist/utils/hsl-to-rgb.js +38 -0
  200. package/dist/utils/hsl-to-rgb.js.map +1 -0
  201. package/dist/utils/is-dev-env.js +19 -0
  202. package/dist/utils/is-dev-env.js.map +1 -0
  203. package/dist/utils/merge-styles.d.ts +7 -0
  204. package/dist/utils/merge-styles.js +146 -0
  205. package/dist/utils/merge-styles.js.map +1 -0
  206. package/dist/utils/mod-attrs.d.ts +8 -0
  207. package/dist/utils/mod-attrs.js +21 -0
  208. package/dist/utils/mod-attrs.js.map +1 -0
  209. package/dist/utils/okhsl-to-rgb.js +296 -0
  210. package/dist/utils/okhsl-to-rgb.js.map +1 -0
  211. package/dist/utils/process-tokens.d.ts +31 -0
  212. package/dist/utils/process-tokens.js +171 -0
  213. package/dist/utils/process-tokens.js.map +1 -0
  214. package/dist/utils/resolve-recipes.d.ts +17 -0
  215. package/dist/utils/resolve-recipes.js +147 -0
  216. package/dist/utils/resolve-recipes.js.map +1 -0
  217. package/dist/utils/string.js +8 -0
  218. package/dist/utils/string.js.map +1 -0
  219. package/dist/utils/styles.d.ts +183 -0
  220. package/dist/utils/styles.js +585 -0
  221. package/dist/utils/styles.js.map +1 -0
  222. package/dist/utils/typography.d.ts +36 -0
  223. package/dist/utils/typography.js +53 -0
  224. package/dist/utils/typography.js.map +1 -0
  225. package/dist/utils/warnings.d.ts +16 -0
  226. package/dist/utils/warnings.js +16 -0
  227. package/dist/utils/warnings.js.map +1 -0
  228. package/dist/zero/babel.d.ts +108 -0
  229. package/dist/zero/babel.js +282 -0
  230. package/dist/zero/babel.js.map +1 -0
  231. package/dist/zero/css-writer.d.ts +45 -0
  232. package/dist/zero/css-writer.js +74 -0
  233. package/dist/zero/css-writer.js.map +1 -0
  234. package/dist/zero/extractor.d.ts +25 -0
  235. package/dist/zero/extractor.js +150 -0
  236. package/dist/zero/extractor.js.map +1 -0
  237. package/dist/zero/index.d.ts +3 -0
  238. package/dist/zero/index.js +4 -0
  239. package/dist/zero/next.d.ts +60 -0
  240. package/dist/zero/next.js +78 -0
  241. package/dist/zero/next.js.map +1 -0
  242. package/package.json +133 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Andrey Yamanov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,464 @@
1
+ <p align="center">
2
+ <img src="assets/tasty.svg" width="128" height="128" alt="Tasty logo">
3
+ </p>
4
+
5
+ <h1 align="center">Tasty</h1>
6
+
7
+ <p align="center">
8
+ <strong>The styling engine built for design systems.</strong><br>
9
+ Deterministic CSS generation. State-aware DSL. Zero specificity conflicts. Ever.
10
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="https://www.npmjs.com/package/@tenphi/tasty"><img src="https://img.shields.io/npm/v/@tenphi/tasty.svg" alt="npm version"></a>
14
+ <a href="https://github.com/tenphi/tasty/actions/workflows/ci.yml"><img src="https://github.com/tenphi/tasty/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI"></a>
15
+ <a href="https://github.com/tenphi/tasty/blob/main/LICENSE"><img src="https://img.shields.io/github/license/tenphi/tasty" alt="license"></a>
16
+ </p>
17
+
18
+ ---
19
+
20
+ Most CSS-in-JS libraries generate CSS. Tasty generates **mutually exclusive CSS** — for any combination of states, exactly one rule matches per property. No cascade conflicts, no specificity wars, no `!important` hacks. Components compose and extend without breaking each other. That's the foundation everything else is built on.
21
+
22
+ On top of that foundation, Tasty gives you a concise, CSS-like DSL with design tokens, custom units, responsive states, container queries, dark mode, sub-element styling, and zero-runtime extraction — all in one coherent system that scales from a single component to an enterprise design system.
23
+
24
+ ## Why Tasty
25
+
26
+ - **Deterministic at any scale** — Exclusive selector generation eliminates the entire class of cascade/specificity bugs. Every state combination resolves to exactly one CSS rule per property. Refactor freely.
27
+ - **DSL that feels like CSS** — Property names you already know (`padding`, `color`, `display`) with syntax sugar that removes boilerplate. Learn the DSL in minutes, not days.
28
+ - **Design-system native** — Color tokens (`#primary`), spacing units (`2x`), typography presets (`h1`, `t2`), border radius (`1r`), and recipes are first-class primitives, not afterthoughts.
29
+ - **Full modern CSS coverage** — Media queries, container queries, `@supports`, `:has()`, `@starting-style`, `@property`, keyframes, boolean state logic with `&`, `|`, `!` operators. If CSS can do it, Tasty can express it — concisely.
30
+ - **Runtime or zero-runtime — your call** — Use `tasty()` for dynamic React components with runtime injection, or `tastyStatic()` with the Babel plugin for zero-runtime CSS extraction. Same DSL, same tokens, same output.
31
+ - **Only generate what is used** — In runtime mode, Tasty injects CSS on demand for mounted components/variants, so your app avoids shipping style rules for UI states that are never rendered.
32
+ - **Runtime performance that holds at scale** — The runtime path is tested against enterprise-scale applications and tuned with multi-level caching, chunk-level style reuse, style garbage collection, and a dedicated injector.
33
+ - **Composable and extensible by design** — Extend any component's styles with proper merge semantics, and evolve built-in behavior through configuration and plugins.
34
+ - **TypeScript-first** — Full type definitions, module augmentation for custom properties, and autocomplete for tokens, presets, and themes.
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ pnpm add @tenphi/tasty
40
+ ```
41
+
42
+ ## Quick Start
43
+
44
+ ### Create a styled component
45
+
46
+ ```tsx
47
+ import { tasty } from '@tenphi/tasty';
48
+
49
+ const Card = tasty({
50
+ as: 'div',
51
+ styles: {
52
+ display: 'flex',
53
+ flow: 'column',
54
+ padding: '4x',
55
+ gap: '2x',
56
+ fill: '#surface',
57
+ border: '#border bottom',
58
+ radius: '1r',
59
+ },
60
+ });
61
+
62
+ // Just a React component
63
+ <Card>Hello World</Card>
64
+ ```
65
+
66
+ Every value maps to CSS you'd recognize — but with tokens and units that keep your design system consistent by default.
67
+
68
+ ### Add state-driven styles
69
+
70
+ ```tsx
71
+ const Button = tasty({
72
+ as: 'button',
73
+ styles: {
74
+ padding: '1.5x 3x',
75
+ fill: {
76
+ '': '#primary',
77
+ ':hover': '#primary-hover',
78
+ ':active': '#primary-pressed',
79
+ '[disabled]': '#surface',
80
+ },
81
+ color: {
82
+ '': '#on-primary',
83
+ '[disabled]': '#text.40',
84
+ },
85
+ cursor: {
86
+ '': 'pointer',
87
+ '[disabled]': 'not-allowed',
88
+ },
89
+ transition: 'theme',
90
+ },
91
+ });
92
+ ```
93
+
94
+ State keys support pseudo-classes first (`:hover`, `:active`), then modifiers (`theme=danger`), attributes (`[disabled]`), media/container queries, root states, and more. Tasty compiles them into exclusive selectors automatically.
95
+
96
+ ### Extend any component
97
+
98
+ ```tsx
99
+ import { Button } from 'my-ui-lib';
100
+
101
+ const DangerButton = tasty(Button, {
102
+ styles: {
103
+ fill: {
104
+ '': '#danger',
105
+ ':hover': '#danger-hover',
106
+ },
107
+ },
108
+ });
109
+ ```
110
+
111
+ Child styles merge with parent styles intelligently — state maps can extend or replace parent states per-property.
112
+
113
+ ### Configure once, use everywhere
114
+
115
+ ```tsx
116
+ import { configure } from '@tenphi/tasty';
117
+
118
+ configure({
119
+ states: {
120
+ '@mobile': '@media(w < 768px)',
121
+ '@tablet': '@media(w < 1024px)',
122
+ '@dark': '@root(schema=dark) | @media(prefers-color-scheme: dark)',
123
+ },
124
+ recipes: {
125
+ card: { padding: '4x', fill: '#surface', radius: '1r', border: true },
126
+ },
127
+ });
128
+ ```
129
+
130
+ Predefined states turn complex selector logic into single tokens. Use `@mobile` instead of writing media query expressions in every component.
131
+
132
+ ## How It Actually Works
133
+
134
+ This is the core idea that makes everything else possible.
135
+
136
+ Traditional CSS uses the cascade to resolve conflicts: when multiple selectors match, the one with the highest specificity wins, or — if specificity is equal — the last one in source order wins. This makes styles inherently fragile. Reordering imports, adding a new media query, or composing components from different libraries can silently break styling.
137
+
138
+ Tasty takes a fundamentally different approach: **every state mapping compiles into selectors that are guaranteed to never overlap.**
139
+
140
+ ```tsx
141
+ const Text = tasty({
142
+ styles: {
143
+ color: {
144
+ '': '#text',
145
+ '@dark': '#text-on-dark',
146
+ },
147
+ padding: {
148
+ '': '4x',
149
+ '@mobile': '2x',
150
+ },
151
+ },
152
+ });
153
+ ```
154
+
155
+ If `@dark` expands to `@root(schema=dark) | @media(prefers-color-scheme: dark)`, Tasty generates:
156
+
157
+ ```css
158
+ /* Explicit dark mode */
159
+ :root[data-schema="dark"] .t0.t0 {
160
+ color: var(--text-on-dark-color);
161
+ }
162
+
163
+ /* OS dark preference, no explicit override */
164
+ @media (prefers-color-scheme: dark) {
165
+ :root:not([data-schema="dark"]) .t0.t0 {
166
+ color: var(--text-on-dark-color);
167
+ }
168
+ }
169
+
170
+ /* Light mode — neither condition */
171
+ @media (not (prefers-color-scheme: dark)) {
172
+ :root:not([data-schema="dark"]) .t0.t0 {
173
+ color: var(--text-color);
174
+ }
175
+ }
176
+ ```
177
+
178
+ Every rule is guarded by the negation of all higher-priority rules. No two rules can ever match simultaneously. No specificity arithmetic. No source-order dependence. Components compose and extend without ever colliding.
179
+
180
+ ## Capabilities
181
+
182
+ ### Design Tokens and Custom Units
183
+
184
+ Tokens are first-class. Colors use `#name` syntax. Spacing, radius, and border width use multiplier units tied to CSS custom properties:
185
+
186
+ ```tsx
187
+ fill: '#surface', // → var(--surface-color)
188
+ color: '#text.80', // → 80% opacity text token
189
+ padding: '2x', // → calc(var(--gap) * 2)
190
+ radius: '1r', // → var(--radius)
191
+ border: '1bw solid #border',
192
+ ```
193
+
194
+ | Unit | Maps to | Example |
195
+ |------|---------|---------|
196
+ | `x` | `--gap` multiplier | `2x` → `calc(var(--gap) * 2)` |
197
+ | `r` | `--radius` multiplier | `1r` → `var(--radius)` |
198
+ | `bw` | `--border-width` multiplier | `1bw` → `var(--border-width)` |
199
+ | `ow` | `--outline-width` multiplier | `1ow` → `var(--outline-width)` |
200
+ | `cr` | `--card-radius` multiplier | `1cr` → `var(--card-radius)` |
201
+
202
+ Define your own units via `configure({ units: { ... } })`.
203
+
204
+ ### State System
205
+
206
+ Every style property accepts a state mapping object. Keys can be combined with boolean logic:
207
+
208
+ | State type | Syntax | CSS output |
209
+ |------------|--------|------------|
210
+ | Data attribute (boolean modifier) | `disabled` | `[data-disabled]` |
211
+ | Data attribute (value modifier) | `theme=danger` | `[data-theme="danger"]` |
212
+ | Pseudo-class | `:hover` | `:hover` |
213
+ | Attribute selector | `[role="tab"]` | `[role="tab"]` |
214
+ | Class selector (supported) | `.is-active` | `.is-active` |
215
+ | Media query | `@media(w < 768px)` | `@media (width < 768px)` |
216
+ | Container query | `@(panel, w >= 300px)` | `@container panel (width >= 300px)` |
217
+ | Root state | `@root(theme=dark)` | `:root[data-theme="dark"]` |
218
+ | Parent state | `@parent(theme=danger)` | `:is([data-theme="danger"] *)` |
219
+ | Feature query | `@supports(display: grid)` | `@supports (display: grid)` |
220
+ | Entry animation | `@starting` | `@starting-style` |
221
+
222
+ Combine with `&` (AND), `|` (OR), `!` (NOT):
223
+
224
+ ```tsx
225
+ fill: {
226
+ '': '#surface',
227
+ 'theme=danger & :hover': '#danger-hover',
228
+ '[aria-selected="true"]': '#accent-subtle',
229
+ }
230
+ ```
231
+
232
+ ### Sub-Element Styling
233
+
234
+ Style inner elements from the parent component definition. No extra components, no CSS leakage:
235
+
236
+ ```tsx
237
+ const Card = tasty({
238
+ styles: {
239
+ padding: '4x',
240
+ Title: { preset: 'h3', color: '#primary' },
241
+ Content: { color: '#text', preset: 't2' },
242
+ },
243
+ elements: { Title: 'h2', Content: 'div' },
244
+ });
245
+
246
+ <Card>
247
+ <Card.Title>Heading</Card.Title>
248
+ <Card.Content>Body text</Card.Content>
249
+ </Card>
250
+ ```
251
+
252
+ Sub-elements use `data-element` attributes — no extra class names, no naming conventions.
253
+
254
+ 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.
255
+
256
+ Use `@own(...)` when a sub-element should react to its own state instead of the root state context.
257
+
258
+ Class selectors are also supported, but modifiers/pseudo-classes are usually the better default in design-system code.
259
+
260
+ Use the sub-element selector `$` when you need precise descendant targeting to avoid leakage in deeply nested component trees.
261
+
262
+ ### Variants
263
+
264
+ 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.
265
+
266
+ ```tsx
267
+ const Button = tasty({
268
+ styles: { padding: '2x 4x', radius: '1r' },
269
+ variants: {
270
+ default: { fill: '#primary', color: '#on-primary' },
271
+ danger: { fill: '#danger', color: '#on-danger' },
272
+ outline: { fill: 'transparent', border: '1bw solid #primary' },
273
+ },
274
+ });
275
+
276
+ <Button variant="danger">Delete</Button>
277
+ ```
278
+
279
+ ### Recipes
280
+
281
+ 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.
282
+
283
+ ```tsx
284
+ configure({
285
+ recipes: {
286
+ card: { padding: '4x', fill: '#surface', radius: '1r', border: true },
287
+ elevated: { shadow: '0 2x 4x #shadow' },
288
+ },
289
+ });
290
+
291
+ const ProfileCard = tasty({
292
+ styles: {
293
+ recipe: 'card elevated',
294
+ color: '#text',
295
+ },
296
+ });
297
+ ```
298
+
299
+ 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'`.
300
+
301
+ ### Keyframes and `@property`
302
+
303
+ Modern CSS features are natively supported:
304
+
305
+ Color tokens are automatically registered as typed properties (`<color>`), so token-based transitions work without extra setup.
306
+
307
+ ```tsx
308
+ const Pulse = tasty({
309
+ styles: {
310
+ '@properties': {
311
+ '$pulse-scale': {
312
+ syntax: '<number>',
313
+ inherits: false,
314
+ initialValue: 1,
315
+ },
316
+ },
317
+ animation: 'pulse 2s infinite',
318
+ transform: 'scale($pulse-scale)',
319
+ '@keyframes': {
320
+ pulse: {
321
+ '0%, 100%': { '$pulse-scale': 1 },
322
+ '50%': { '$pulse-scale': 1.05 },
323
+ },
324
+ },
325
+ },
326
+ });
327
+ ```
328
+
329
+ ### React Hooks
330
+
331
+ For cases where you don't need a full component:
332
+
333
+ ```tsx
334
+ import { useStyles, useGlobalStyles, useRawCSS } from '@tenphi/tasty';
335
+
336
+ function App() {
337
+ const { className } = useStyles({ padding: '2x', fill: '#surface' });
338
+ useGlobalStyles(':root', { '#primary': 'purple', '$gap': '8px' });
339
+ useRawCSS('body { margin: 0; }');
340
+
341
+ return <main className={className}>...</main>;
342
+ }
343
+ ```
344
+
345
+ ### Zero-Runtime Mode
346
+
347
+ Extract all CSS at build time. Zero JavaScript overhead in production:
348
+
349
+ ```tsx
350
+ import { tastyStatic } from '@tenphi/tasty/static';
351
+
352
+ const card = tastyStatic({
353
+ padding: '4x',
354
+ fill: '#surface',
355
+ radius: '1r',
356
+ color: { '': '#text', '@dark': '#text-on-dark' },
357
+ });
358
+
359
+ // card is a CSS class name string
360
+ <div className={card}>Static styles, zero runtime</div>
361
+ ```
362
+
363
+ Configure the Babel plugin:
364
+
365
+ ```js
366
+ module.exports = {
367
+ plugins: [
368
+ ['@tenphi/tasty/babel-plugin', {
369
+ output: 'public/tasty.css',
370
+ config: {
371
+ states: { '@dark': '@root(theme=dark)' },
372
+ },
373
+ }],
374
+ ],
375
+ };
376
+ ```
377
+
378
+ ### `tasty` vs `tastyStatic`
379
+
380
+ | | `tasty` (runtime) | `tastyStatic` (zero-runtime) |
381
+ |---|---|---|
382
+ | **Output** | React component | CSS class name |
383
+ | **CSS injection** | Runtime `<style>` tags | Build-time extraction |
384
+ | **Runtime cost** | Style generation on mount | None |
385
+ | **Generated CSS scope** | Only styles/variants used at runtime | All extracted static styles at build time |
386
+ | **Dynamic values** | Fully supported | Via CSS custom properties |
387
+ | **Sub-elements** | Built-in (`<C.Title>`) | Manual (`data-element`) |
388
+ | **Variants** | Built-in (`variants` option) | Separate static styles |
389
+ | **Framework** | React | Any (requires Babel) |
390
+ | **Best for** | Interactive apps, design systems | Static sites, SSG, landing pages |
391
+
392
+ Both share the same DSL, tokens, units, state mappings, and recipes.
393
+
394
+ ### Runtime Performance
395
+
396
+ If you choose the runtime approach, performance is usually a non-issue in practice:
397
+
398
+ - CSS is generated and injected only when styles are actually used.
399
+ - Multi-level caching avoids repeated parsing and style recomputation.
400
+ - Styles are split into reusable chunks and applied as multiple class names, so matching chunks can be reused across components instead of re-injected.
401
+ - Style normalization guarantees equivalent style input resolves to the same chunks, improving deduplication hit rates.
402
+ - A style garbage collector removes unused styles/chunks over time.
403
+ - A dedicated style injector minimizes DOM/style-tag overhead.
404
+ - This approach is validated in enterprise-scale apps where runtime styling overhead is not noticeable in normal UI flows.
405
+
406
+ ## Entry Points
407
+
408
+ | Import | Description | Platform |
409
+ |--------|-------------|----------|
410
+ | `@tenphi/tasty` | Runtime style engine | Browser |
411
+ | `@tenphi/tasty/static` | Zero-runtime static styles | Browser |
412
+ | `@tenphi/tasty/babel-plugin` | Babel plugin for CSS extraction | Node |
413
+ | `@tenphi/tasty/zero` | Programmatic extraction API | Node |
414
+ | `@tenphi/tasty/next` | Next.js integration | Node |
415
+
416
+ ## Ecosystem
417
+
418
+ Tasty is the core of a production-ready styling platform. These companion tools complete the picture:
419
+
420
+ ### [ESLint Plugin](https://github.com/tenphi/eslint-plugin-tasty)
421
+
422
+ `@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.
423
+
424
+ ```bash
425
+ pnpm add -D @tenphi/eslint-plugin-tasty
426
+ ```
427
+
428
+ ```js
429
+ import tasty from '@tenphi/eslint-plugin-tasty';
430
+ export default [tasty.configs.recommended];
431
+ ```
432
+
433
+ ### [Glaze](https://github.com/tenphi/glaze)
434
+
435
+ `@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.
436
+
437
+ ```tsx
438
+ import { glaze } from '@tenphi/glaze';
439
+
440
+ const theme = glaze(280, 80);
441
+ theme.colors({
442
+ surface: { lightness: 97 },
443
+ text: { base: 'surface', lightness: '-52', contrast: 'AAA' },
444
+ });
445
+
446
+ const tokens = theme.tasty(); // Ready-to-use Tasty tokens
447
+ ```
448
+
449
+ ### [VS Code Extension](https://github.com/tenphi/tasty-vscode-extension)
450
+
451
+ 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.
452
+
453
+ ### [Cube UI Kit](https://github.com/cube-js/cube-ui-kit)
454
+
455
+ 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.
456
+
457
+ ## Documentation
458
+
459
+ - **[Runtime API (tasty)](docs/tasty.md)** — Full runtime styling documentation: component creation, state mappings, sub-elements, variants, hooks, configuration, and style property reference
460
+ - **[Zero Runtime (tastyStatic)](docs/tasty-static.md)** — Build-time static styling: Babel plugin setup, Next.js integration, and static style patterns
461
+
462
+ ## License
463
+
464
+ [MIT](LICENSE)
@@ -0,0 +1,8 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
3
+ if (typeof require !== "undefined") return require.apply(this, arguments);
4
+ throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
5
+ });
6
+
7
+ //#endregion
8
+ export { __require };
@@ -0,0 +1 @@
1
+ import "../styles/types.js";
@@ -0,0 +1,70 @@
1
+ import { extractLocalPredefinedStates, extractPredefinedStateRefs } from "../states/index.js";
2
+
3
+ //#region src/chunks/cacheKey.ts
4
+ /**
5
+ * Chunk-specific cache key generation.
6
+ *
7
+ * Generates cache keys that only include styles relevant to a specific chunk,
8
+ * enabling more granular caching and reuse.
9
+ *
10
+ * Enhanced to support predefined states:
11
+ * - Global predefined states don't affect cache keys (constant across app)
12
+ * - Local predefined states only affect cache keys if referenced in the chunk
13
+ */
14
+ /**
15
+ * Recursively serialize a value with sorted keys for stable output.
16
+ * This ensures that {a: 1, b: 2} and {b: 2, a: 1} produce the same string.
17
+ */
18
+ function stableStringify(value) {
19
+ if (value === null) return "null";
20
+ if (value === void 0) return "undefined";
21
+ if (typeof value !== "object") return JSON.stringify(value);
22
+ if (Array.isArray(value)) return "[" + value.map(stableStringify).join(",") + "]";
23
+ const obj = value;
24
+ const sortedKeys = Object.keys(obj).sort();
25
+ const parts = [];
26
+ for (const key of sortedKeys) if (obj[key] !== void 0) parts.push(`${JSON.stringify(key)}:${stableStringify(obj[key])}`);
27
+ return "{" + parts.join(",") + "}";
28
+ }
29
+ /**
30
+ * Generate a cache key for a specific chunk.
31
+ *
32
+ * Only includes the styles that belong to this chunk, allowing
33
+ * chunks to be cached independently.
34
+ *
35
+ * Also includes relevant local predefined states that are referenced
36
+ * by this chunk's styles.
37
+ *
38
+ * @param styles - The full styles object
39
+ * @param chunkName - Name of the chunk
40
+ * @param styleKeys - Keys of styles belonging to this chunk
41
+ * @returns A stable cache key string
42
+ */
43
+ function generateChunkCacheKey(styles, chunkName, styleKeys) {
44
+ const parts = [chunkName];
45
+ const sortedKeys = styleKeys.slice().sort();
46
+ let chunkStylesStr = "";
47
+ for (const key of sortedKeys) {
48
+ const value = styles[key];
49
+ if (value !== void 0) {
50
+ const serialized = stableStringify(value);
51
+ parts.push(`${key}:${serialized}`);
52
+ chunkStylesStr += serialized;
53
+ }
54
+ }
55
+ const localStates = extractLocalPredefinedStates(styles);
56
+ if (Object.keys(localStates).length > 0) {
57
+ const referencedStates = extractPredefinedStateRefs(chunkStylesStr);
58
+ const relevantLocalStates = [];
59
+ for (const stateName of referencedStates) if (localStates[stateName]) relevantLocalStates.push(`${stateName}=${localStates[stateName]}`);
60
+ if (relevantLocalStates.length > 0) {
61
+ relevantLocalStates.sort();
62
+ parts.unshift(`[states:${relevantLocalStates.join("|")}]`);
63
+ }
64
+ }
65
+ return parts.join("\0");
66
+ }
67
+
68
+ //#endregion
69
+ export { generateChunkCacheKey };
70
+ //# sourceMappingURL=cacheKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheKey.js","names":[],"sources":["../../src/chunks/cacheKey.ts"],"sourcesContent":["/**\n * Chunk-specific cache key generation.\n *\n * Generates cache keys that only include styles relevant to a specific chunk,\n * enabling more granular caching and reuse.\n *\n * Enhanced to support predefined states:\n * - Global predefined states don't affect cache keys (constant across app)\n * - Local predefined states only affect cache keys if referenced in the chunk\n */\n\nimport {\n extractLocalPredefinedStates,\n extractPredefinedStateRefs,\n} from '../states';\nimport type { Styles } from '../styles/types';\n\n/**\n * Recursively serialize a value with sorted keys for stable output.\n * This ensures that {a: 1, b: 2} and {b: 2, a: 1} produce the same string.\n */\nfunction stableStringify(value: unknown): string {\n if (value === null) {\n return 'null';\n }\n if (value === undefined) {\n return 'undefined';\n }\n if (typeof value !== 'object') {\n return JSON.stringify(value);\n }\n if (Array.isArray(value)) {\n return '[' + value.map(stableStringify).join(',') + ']';\n }\n // Object: sort keys for stable order\n const obj = value as Record<string, unknown>;\n const sortedKeys = Object.keys(obj).sort();\n const parts: string[] = [];\n for (const key of sortedKeys) {\n if (obj[key] !== undefined) {\n parts.push(`${JSON.stringify(key)}:${stableStringify(obj[key])}`);\n }\n }\n return '{' + parts.join(',') + '}';\n}\n\n/**\n * Generate a cache key for a specific chunk.\n *\n * Only includes the styles that belong to this chunk, allowing\n * chunks to be cached independently.\n *\n * Also includes relevant local predefined states that are referenced\n * by this chunk's styles.\n *\n * @param styles - The full styles object\n * @param chunkName - Name of the chunk\n * @param styleKeys - Keys of styles belonging to this chunk\n * @returns A stable cache key string\n */\nexport function generateChunkCacheKey(\n styles: Styles,\n chunkName: string,\n styleKeys: string[],\n): string {\n // Start with chunk name for namespace separation\n const parts: string[] = [chunkName];\n\n // Sort keys for stable ordering\n const sortedKeys = styleKeys.slice().sort();\n\n // Build the chunk-specific styles string for predefined state detection\n let chunkStylesStr = '';\n\n for (const key of sortedKeys) {\n const value = styles[key];\n if (value !== undefined) {\n // Use stable stringify for consistent serialization regardless of key order\n const serialized = stableStringify(value);\n parts.push(`${key}:${serialized}`);\n chunkStylesStr += serialized;\n }\n }\n\n // Extract local predefined states from the full styles object\n const localStates = extractLocalPredefinedStates(styles);\n\n // Only include local predefined states that are actually referenced in this chunk\n if (Object.keys(localStates).length > 0) {\n const referencedStates = extractPredefinedStateRefs(chunkStylesStr);\n const relevantLocalStates: string[] = [];\n\n for (const stateName of referencedStates) {\n if (localStates[stateName]) {\n relevantLocalStates.push(`${stateName}=${localStates[stateName]}`);\n }\n }\n\n // Add relevant local states to the cache key (sorted for stability)\n if (relevantLocalStates.length > 0) {\n relevantLocalStates.sort();\n parts.unshift(`[states:${relevantLocalStates.join('|')}]`);\n }\n }\n\n // Use null character as separator (safe, not in JSON output)\n return parts.join('\\0');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqBA,SAAS,gBAAgB,OAAwB;AAC/C,KAAI,UAAU,KACZ,QAAO;AAET,KAAI,UAAU,OACZ,QAAO;AAET,KAAI,OAAO,UAAU,SACnB,QAAO,KAAK,UAAU,MAAM;AAE9B,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MAAM,MAAM,IAAI,gBAAgB,CAAC,KAAK,IAAI,GAAG;CAGtD,MAAM,MAAM;CACZ,MAAM,aAAa,OAAO,KAAK,IAAI,CAAC,MAAM;CAC1C,MAAM,QAAkB,EAAE;AAC1B,MAAK,MAAM,OAAO,WAChB,KAAI,IAAI,SAAS,OACf,OAAM,KAAK,GAAG,KAAK,UAAU,IAAI,CAAC,GAAG,gBAAgB,IAAI,KAAK,GAAG;AAGrE,QAAO,MAAM,MAAM,KAAK,IAAI,GAAG;;;;;;;;;;;;;;;;AAiBjC,SAAgB,sBACd,QACA,WACA,WACQ;CAER,MAAM,QAAkB,CAAC,UAAU;CAGnC,MAAM,aAAa,UAAU,OAAO,CAAC,MAAM;CAG3C,IAAI,iBAAiB;AAErB,MAAK,MAAM,OAAO,YAAY;EAC5B,MAAM,QAAQ,OAAO;AACrB,MAAI,UAAU,QAAW;GAEvB,MAAM,aAAa,gBAAgB,MAAM;AACzC,SAAM,KAAK,GAAG,IAAI,GAAG,aAAa;AAClC,qBAAkB;;;CAKtB,MAAM,cAAc,6BAA6B,OAAO;AAGxD,KAAI,OAAO,KAAK,YAAY,CAAC,SAAS,GAAG;EACvC,MAAM,mBAAmB,2BAA2B,eAAe;EACnE,MAAM,sBAAgC,EAAE;AAExC,OAAK,MAAM,aAAa,iBACtB,KAAI,YAAY,WACd,qBAAoB,KAAK,GAAG,UAAU,GAAG,YAAY,aAAa;AAKtE,MAAI,oBAAoB,SAAS,GAAG;AAClC,uBAAoB,MAAM;AAC1B,SAAM,QAAQ,WAAW,oBAAoB,KAAK,IAAI,CAAC,GAAG;;;AAK9D,QAAO,MAAM,KAAK,KAAK"}
@@ -0,0 +1,37 @@
1
+ //#region src/chunks/definitions.d.ts
2
+ declare const CHUNK_NAMES: {
3
+ /** Special chunk for styles that cannot be split (e.g., @starting-style) */readonly COMBINED: "combined";
4
+ readonly SUBCOMPONENTS: "subcomponents";
5
+ readonly APPEARANCE: "appearance";
6
+ readonly FONT: "font";
7
+ readonly DIMENSION: "dimension";
8
+ readonly DISPLAY: "display";
9
+ readonly LAYOUT: "layout";
10
+ readonly POSITION: "position";
11
+ readonly MISC: "misc";
12
+ };
13
+ type ChunkName = (typeof CHUNK_NAMES)[keyof typeof CHUNK_NAMES];
14
+ /**
15
+ * Pre-computed map for O(1) style-to-chunk lookup.
16
+ * Built once at module load time.
17
+ */
18
+ declare const STYLE_TO_CHUNK: Map<string, ChunkName>;
19
+ interface ChunkInfo {
20
+ /** Name of the chunk */
21
+ name: ChunkName | string;
22
+ /** Style keys belonging to this chunk */
23
+ styleKeys: string[];
24
+ }
25
+ /**
26
+ * Categorize style keys into chunks.
27
+ *
28
+ * Returns chunks in a deterministic order (by CHUNK_ORDER) regardless
29
+ * of the order of keys in the input styles object.
30
+ *
31
+ * @param styles - The styles object to categorize
32
+ * @returns Map of chunk name to array of style keys in that chunk (in priority order)
33
+ */
34
+ declare function categorizeStyleKeys(styles: Record<string, unknown>): Map<string, string[]>;
35
+ //#endregion
36
+ export { CHUNK_NAMES, ChunkInfo, ChunkName, STYLE_TO_CHUNK, categorizeStyleKeys };
37
+ //# sourceMappingURL=definitions.d.ts.map