@tenphi/tasty 0.0.0-snapshot.8a8eb7d → 0.0.0-snapshot.8be165d

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 (100) hide show
  1. package/README.md +176 -131
  2. package/dist/astro-C_by9qPq.js +307 -0
  3. package/dist/astro-C_by9qPq.js.map +1 -0
  4. package/dist/{async-storage-B7_o6FKt.js → async-storage-DKK-wTD4.js} +1 -1
  5. package/dist/{async-storage-B7_o6FKt.js.map → async-storage-DKK-wTD4.js.map} +1 -1
  6. package/dist/babel-BUQGeOXA.d.ts +83 -0
  7. package/dist/{collector-o-UYCV-b.js → collector-BevHh16N.js} +108 -24
  8. package/dist/collector-BevHh16N.js.map +1 -0
  9. package/dist/{collector-CpU85p2G.d.ts → collector-CLVr5_p3.d.ts} +62 -7
  10. package/dist/{config-DOvjo65E.js → config-NcdqU9PC.js} +2812 -1496
  11. package/dist/config-NcdqU9PC.js.map +1 -0
  12. package/dist/{config-3h7BtX4l.d.ts → config-YsxGv4tq.d.ts} +351 -33
  13. package/dist/{context-CkSg-kDT.js → context-CA8YKeMn.js} +1 -1
  14. package/dist/{context-CkSg-kDT.js.map → context-CA8YKeMn.js.map} +1 -1
  15. package/dist/core/index.d.ts +5 -5
  16. package/dist/core/index.js +6 -6
  17. package/dist/{core-CPx5Lqjr.js → core-D7s7u-k1.js} +150 -182
  18. package/dist/core-D7s7u-k1.js.map +1 -0
  19. package/dist/{css-writer-DJvsfR1w.js → css-writer-BDPmetHV.js} +54 -15
  20. package/dist/css-writer-BDPmetHV.js.map +1 -0
  21. package/dist/{format-global-rules-Dbc_1tc3.js → format-global-rules-DklyaXv-.js} +1 -1
  22. package/dist/{format-global-rules-Dbc_1tc3.js.map → format-global-rules-DklyaXv-.js.map} +1 -1
  23. package/dist/{format-rules-aRlqFAd1.js → format-rules-BQCn7JZH.js} +4 -17
  24. package/dist/format-rules-BQCn7JZH.js.map +1 -0
  25. package/dist/{hydrate-Ddw7yjyx.js → hydrate-C3cfqlaQ.js} +3 -11
  26. package/dist/{hydrate-Ddw7yjyx.js.map → hydrate-C3cfqlaQ.js.map} +1 -1
  27. package/dist/{index-C_SRmAWj.d.ts → index-CBK778ne.d.ts} +294 -161
  28. package/dist/{index-BsJz5xBF.d.ts → index-Cd45t5NM.d.ts} +297 -62
  29. package/dist/index.d.ts +5 -5
  30. package/dist/index.js +250 -60
  31. package/dist/index.js.map +1 -1
  32. package/dist/{keyframes-C4ObN2Vc.js → keyframes-ByhOtsXB.js} +97 -199
  33. package/dist/keyframes-ByhOtsXB.js.map +1 -0
  34. package/dist/{merge-styles-BbyWO2Gc.js → merge-styles-BKfagXfV.js} +2 -2
  35. package/dist/{merge-styles-BbyWO2Gc.js.map → merge-styles-BKfagXfV.js.map} +1 -1
  36. package/dist/{merge-styles-BzOwGOGC.d.ts → merge-styles-CU7JbEwg.d.ts} +2 -2
  37. package/dist/{resolve-recipes-CqTtBOKx.js → resolve-recipes-vvygrWLw.js} +3 -3
  38. package/dist/{resolve-recipes-CqTtBOKx.js.map → resolve-recipes-vvygrWLw.js.map} +1 -1
  39. package/dist/ssr/astro-client.js +1 -1
  40. package/dist/ssr/astro-client.js.map +1 -1
  41. package/dist/ssr/astro-middleware-extract-static.d.ts +11 -0
  42. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  43. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  44. package/dist/ssr/astro-middleware-extract.d.ts +11 -0
  45. package/dist/ssr/astro-middleware-extract.js +9 -0
  46. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  47. package/dist/ssr/astro-middleware-static.d.ts +18 -0
  48. package/dist/ssr/astro-middleware-static.js +18 -0
  49. package/dist/ssr/astro-middleware-static.js.map +1 -0
  50. package/dist/ssr/astro-middleware.d.ts +11 -7
  51. package/dist/ssr/astro-middleware.js +10 -10
  52. package/dist/ssr/astro-middleware.js.map +1 -1
  53. package/dist/ssr/astro.d.ts +37 -7
  54. package/dist/ssr/astro.js +2 -147
  55. package/dist/ssr/index.d.ts +2 -9
  56. package/dist/ssr/index.js +5 -5
  57. package/dist/ssr/index.js.map +1 -1
  58. package/dist/ssr/next.d.ts +2 -3
  59. package/dist/ssr/next.js +6 -7
  60. package/dist/ssr/next.js.map +1 -1
  61. package/dist/static/index.d.ts +2 -2
  62. package/dist/static/index.js +4 -4
  63. package/dist/static/index.js.map +1 -1
  64. package/dist/static/inject.js.map +1 -1
  65. package/dist/zero/babel.d.ts +2 -81
  66. package/dist/zero/babel.js +27 -23
  67. package/dist/zero/babel.js.map +1 -1
  68. package/dist/zero/index.d.ts +16 -2
  69. package/dist/zero/index.js +2 -2
  70. package/dist/zero/next.d.ts +1 -1
  71. package/dist/zero/next.js +1 -1
  72. package/dist/zero/next.js.map +1 -1
  73. package/docs/README.md +17 -9
  74. package/docs/adoption.md +56 -31
  75. package/docs/ai-agents.md +224 -0
  76. package/docs/comparison.md +69 -40
  77. package/docs/configuration.md +470 -85
  78. package/docs/debug.md +7 -7
  79. package/docs/design-system.md +43 -24
  80. package/docs/dsl.md +407 -185
  81. package/docs/getting-started.md +60 -39
  82. package/docs/injector.md +58 -5
  83. package/docs/methodology.md +44 -38
  84. package/docs/migration-v3.md +285 -0
  85. package/docs/pipeline.md +4 -7
  86. package/docs/plugins.md +353 -0
  87. package/docs/react-api.md +142 -42
  88. package/docs/runtime-benchmarks.md +216 -0
  89. package/docs/ssr.md +132 -86
  90. package/docs/styles.md +56 -9
  91. package/docs/tasty-static.md +140 -105
  92. package/package.json +50 -18
  93. package/tasty.config.ts +4 -0
  94. package/dist/collector-o-UYCV-b.js.map +0 -1
  95. package/dist/config-DOvjo65E.js.map +0 -1
  96. package/dist/core-CPx5Lqjr.js.map +0 -1
  97. package/dist/css-writer-DJvsfR1w.js.map +0 -1
  98. package/dist/format-rules-aRlqFAd1.js.map +0 -1
  99. package/dist/keyframes-C4ObN2Vc.js.map +0 -1
  100. package/dist/ssr/astro.js.map +0 -1
package/docs/react-api.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # React API
2
2
 
3
- The React-specific `tasty()` component factory, component props, and style functions. All Tasty style functions — `tasty()` components, `useStyles()`, `useGlobalStyles()`, `useRawCSS()`, `useKeyframes()`, `useProperty()`, `useFontFace()`, and `useCounterStyle()` — are hook-free and compatible with React Server Components. No `'use client'` directive needed. For the shared style language (state maps, tokens, units, extending semantics), see [Style DSL](dsl.md). For global configuration, see [Configuration](configuration.md). For the broader docs map, see the [Docs Hub](README.md).
3
+ Use `tasty()` to turn state-aware style definitions into normal React components, extend existing Tasty components, and expose typed styling APIs to consumers.
4
+
5
+ All Tasty style functions — `tasty()` components, `useStyles()`, `useGlobalStyles()`, `useRawCSS()`, `useKeyframes()`, `useProperty()`, `useFontFace()`, `useCounterStyle()`, and `useFunction()` — are hook-free and compatible with React Server Components. No `'use client'` directive is needed. For state maps, tokens, units, and extension semantics, see [Style DSL](dsl.md). For global configuration, see [Configuration](configuration.md). For the broader docs map, see the [Docs Hub](README.md).
4
6
 
5
7
  > **Note:** This file was previously named `runtime.md`. All functionality documented here works in both server and client contexts — "runtime" referred to style computation during React rendering, not to client-side JavaScript.
6
8
 
@@ -58,10 +60,12 @@ const Link = tasty({
58
60
 
59
61
  const Span = tasty({
60
62
  as: 'span',
61
- styles: { fontWeight: 'bold' },
63
+ styles: { preset: 'strong' },
62
64
  });
63
65
 
64
- <Link href="/blog" padding="1x">Blog</Link>;
66
+ <Link href="/blog" padding="1x">
67
+ Blog
68
+ </Link>;
65
69
  ```
66
70
 
67
71
  The wrapped component only needs to forward `className` (and ideally `style`/`ref`). Tasty-specific props (`qa`, `qaVal`, `mods`, `tokens`, `styleProps`, `modProps`, `tokenProps`) are consumed by Tasty and never leak to the DOM.
@@ -84,7 +88,7 @@ const FlexibleBox = tasty({
84
88
 
85
89
  <FlexibleBox gap="2x" align="center" fill="#surface">
86
90
  Content
87
- </FlexibleBox>
91
+ </FlexibleBox>;
88
92
  ```
89
93
 
90
94
  Style props accept state maps, so responsive values work through the same API:
@@ -98,6 +102,26 @@ Style props accept state maps, so responsive values work through the same API:
98
102
 
99
103
  For predefined style prop lists (`FLOW_STYLES`, `POSITION_STYLES`, `DIMENSION_STYLES`, etc.) and guidance on which props to expose per component category, see [Methodology — styleProps as the public API](methodology.md#styleprops-as-the-public-api).
100
104
 
105
+ ### Always-available style props
106
+
107
+ A small set of style properties — `display`, `font`, `preset`, `hide`, `whiteSpace`, `opacity`, and `transition` — are always harvested as style props on every `tasty()` component, even when `styleProps` is omitted. This means you can pass `<Card display="grid" />` or `<Text preset="h1" />` without declaring them. When you do declare `styleProps`, these base props are unioned with your list (not replaced).
108
+
109
+ ---
110
+
111
+ ## `Element`
112
+
113
+ `Element` is the unstyled base component exported from the main entry — equivalent to `tasty({})` (a `div` with no default styles). It accepts all Tasty props (`styles`, `styleProps`, `mods`, `tokens`, `as`, `qa`, `theme`, the `is*` props, etc.) and is useful as a generic styled box or as a building block for layout primitives.
114
+
115
+ ```jsx
116
+ import { Element } from '@tenphi/tasty';
117
+
118
+ <Element as="section" padding="4x" fill="#surface">
119
+ Content
120
+ </Element>;
121
+ ```
122
+
123
+ > Note: `Element` shadows the global DOM `Element` type when imported from `@tenphi/tasty`. In files that need the DOM type, alias the import: `import { Element as TastyElement } from '@tenphi/tasty'`.
124
+
101
125
  ---
102
126
 
103
127
  ## Mod Props
@@ -136,9 +160,9 @@ Map modifier names to type descriptors for precise TypeScript types:
136
160
  ```tsx
137
161
  const Button = tasty({
138
162
  modProps: {
139
- isLoading: Boolean, // isLoading?: boolean
140
- isSelected: Boolean, // isSelected?: boolean
141
- size: ['small', 'medium', 'large'] as const, // size?: 'small' | 'medium' | 'large'
163
+ isLoading: Boolean, // isLoading?: boolean
164
+ isSelected: Boolean, // isSelected?: boolean
165
+ size: ['small', 'medium', 'large'] as const, // size?: 'small' | 'medium' | 'large'
142
166
  },
143
167
  styles: {
144
168
  padding: { '': '2x 4x', 'size=small': '1x 2x', 'size=large': '3x 6x' },
@@ -146,18 +170,20 @@ const Button = tasty({
146
170
  },
147
171
  });
148
172
 
149
- <Button isLoading size="large">Submit</Button>
173
+ <Button isLoading size="large">
174
+ Submit
175
+ </Button>;
150
176
  // Renders: <button data-is-loading="" data-size="large">Submit</button>
151
177
  ```
152
178
 
153
179
  Available type descriptors:
154
180
 
155
- | Descriptor | TypeScript type | Example |
156
- |---|---|---|
157
- | `Boolean` | `boolean` | `isLoading: Boolean` |
158
- | `String` | `string` | `label: String` |
159
- | `Number` | `number` | `count: Number` |
160
- | `['a', 'b'] as const` | `'a' \| 'b'` | `size: ['sm', 'md', 'lg'] as const` |
181
+ | Descriptor | TypeScript type | Example |
182
+ | --------------------- | --------------- | ----------------------------------- |
183
+ | `Boolean` | `boolean` | `isLoading: Boolean` |
184
+ | `String` | `string` | `label: String` |
185
+ | `Number` | `number` | `count: Number` |
186
+ | `['a', 'b'] as const` | `'a' \| 'b'` | `size: ['sm', 'md', 'lg'] as const` |
161
187
 
162
188
  ### Merge with `mods`
163
189
 
@@ -170,11 +196,11 @@ Mod props and the `mods` object can be used together. Mod props take precedence:
170
196
 
171
197
  ### When to use `modProps` vs `mods`
172
198
 
173
- | Use case | Recommendation |
174
- |---|---|
199
+ | Use case | Recommendation |
200
+ | -------------------------------------------- | -------------------------------------------------------- |
175
201
  | Component has a fixed set of known modifiers | `modProps` — cleaner API, better TypeScript autocomplete |
176
- | Component needs arbitrary/dynamic modifiers | `mods` — open-ended `Record<string, ModValue>` |
177
- | Both fixed and dynamic | Combine: `modProps` for known keys, `mods` for ad-hoc |
202
+ | Component needs arbitrary/dynamic modifiers | `mods` — open-ended `Record<string, ModValue>` |
203
+ | Both fixed and dynamic | Combine: `modProps` for known keys, `mods` for ad-hoc |
178
204
 
179
205
  For architecture guidance on when to use modifiers vs `styleProps`, see [Methodology — modProps and mods](methodology.md#modprops-and-mods).
180
206
 
@@ -204,7 +230,7 @@ const ProgressBar = tasty({
204
230
 
205
231
  <ProgressBar progress="75%" accentColor="#purple" />
206
232
  // 'progress' → $progress → --progress
207
- // 'accentColor' → #accent → --accent-color + --accent-color-oklch
233
+ // 'accentColor' → #accent → --accent-color
208
234
  ```
209
235
 
210
236
  ### Object form
@@ -220,7 +246,7 @@ const Card = tasty({
220
246
  styles: { padding: '$card-size', fill: '#card-accent' },
221
247
  });
222
248
 
223
- <Card size="4x" color="#purple" />
249
+ <Card size="4x" color="#purple" />;
224
250
  ```
225
251
 
226
252
  ### Merge with `tokens`
@@ -239,11 +265,11 @@ const Bar = tasty({
239
265
 
240
266
  ### When to use `tokenProps` vs `tokens`
241
267
 
242
- | Use case | Recommendation |
243
- |---|---|
244
- | Component has a fixed set of known token keys | `tokenProps` — cleaner API, better TypeScript autocomplete |
245
- | Component needs arbitrary/dynamic token values | `tokens` — open-ended `Record<string, TokenValue>` |
246
- | Both fixed and dynamic | Combine: `tokenProps` for known keys, `tokens` for ad-hoc |
268
+ | Use case | Recommendation |
269
+ | ---------------------------------------------- | ---------------------------------------------------------- |
270
+ | Component has a fixed set of known token keys | `tokenProps` — cleaner API, better TypeScript autocomplete |
271
+ | Component needs arbitrary/dynamic token values | `tokens` — open-ended `Record<string, TokenValue>` |
272
+ | Both fixed and dynamic | Combine: `tokenProps` for known keys, `tokens` for ad-hoc |
247
273
 
248
274
  For architecture guidance, see [Methodology — tokenProps](methodology.md#tokenprops).
249
275
 
@@ -262,11 +288,11 @@ const Button = tasty({
262
288
  variants: {
263
289
  default: { fill: '#blue', color: '#white' },
264
290
  danger: { fill: '#red', color: '#white' },
265
- outline: { fill: 'transparent', color: '#blue', border: '1bw solid #blue' },
291
+ outline: { fill: '#clear', color: '#blue', border: '1bw solid #blue' },
266
292
  },
267
293
  });
268
294
 
269
- <Button variant="danger">Delete</Button>
295
+ <Button variant="danger">Delete</Button>;
270
296
  ```
271
297
 
272
298
  ### Extending Variants with Base State Maps
@@ -322,7 +348,7 @@ const Card = tasty({
322
348
  <Card>
323
349
  <Card.Title>Card Title</Card.Title>
324
350
  <Card.Content>Card content</Card.Content>
325
- </Card>
351
+ </Card>;
326
352
  ```
327
353
 
328
354
  Each entry in `elements` can be a tag name string or a config object:
@@ -348,7 +374,7 @@ const Card = tasty({
348
374
 
349
375
  <Card>
350
376
  <div data-element="Title">Card Title</div>
351
- </Card>
377
+ </Card>;
352
378
  ```
353
379
 
354
380
  ### Selector Affix (`$`)
@@ -381,7 +407,7 @@ On the client, CSS is injected synchronously into the DOM (idempotent via the in
381
407
 
382
408
  All style functions below are plain functions (not React hooks) and can be used in any environment: client components, SSR with a `ServerStyleCollector`, and React Server Components. They retain their `use` prefix for backward compatibility, but do not use any React hooks internally.
383
409
 
384
- In server-only contexts (Next.js RSC without `'use client'`, Astro without `client:*` directives, SSG), components that use only Tasty style functions produce zero client JavaScript. Tasty never forces the `'use client'` boundary — that decision belongs to your component when it needs React interactivity (state, effects, event handlers).
410
+ In server-only contexts, components that use only Tasty style functions ship no Tasty styling runtime. Astro without `client:*` directives produces no client JavaScript; server-only Next.js RSC follows the same Tasty architecture, while final output depends on the application deployment. Tasty never forces the `'use client'` boundary — that decision belongs to your component when it needs React interactivity (state, effects, event handlers).
385
411
 
386
412
  ### useStyles
387
413
 
@@ -419,6 +445,15 @@ function ThemeStyles() {
419
445
  }
420
446
  ```
421
447
 
448
+ A slot — the `id`, or the selector when no `id` is given — holds exactly one
449
+ injection **per `root`**. So:
450
+
451
+ - Changing the styles replaces the previous CSS rather than adding to it.
452
+ - Passing styles that produce no CSS (for example `{}`) clears the slot.
453
+ - The same selector used in two shadow roots keeps a separate injection in each.
454
+ - Two independent call sites that share a selector share a slot, and the last
455
+ render wins. Give them distinct `id`s if they should coexist.
456
+
422
457
  ### useRawCSS
423
458
 
424
459
  Inject raw CSS strings. Accepts an optional `id` in the options for update tracking — when the CSS changes for the same id, the previous injection is replaced:
@@ -435,6 +470,9 @@ function GlobalReset() {
435
470
  }
436
471
  ```
437
472
 
473
+ An `id` slot holds one injection per `root`. Without an `id` the CSS is deduped
474
+ by content and permanent — there is nothing to replace it with later.
475
+
438
476
  ### useKeyframes
439
477
 
440
478
  Inject `@keyframes` rules and return the generated animation name:
@@ -448,14 +486,14 @@ function Spinner() {
448
486
  from: { transform: 'rotate(0deg)' },
449
487
  to: { transform: 'rotate(360deg)' },
450
488
  },
451
- { name: 'spin' }
489
+ { name: 'spin' },
452
490
  );
453
491
 
454
492
  return <div style={{ animation: `${spin} 1s linear infinite` }} />;
455
493
  }
456
494
  ```
457
495
 
458
- `useKeyframes()` also supports a factory function. The deps array is accepted for backward compatibility but the factory is called on every invocation — deduplication is handled internally by content hash:
496
+ `useKeyframes()` also supports a factory function. Without a `name` the factory runs on every invocation and deduplication is handled internally by content hash; with a `name`, matching deps skip the factory entirely:
459
497
 
460
498
  ```tsx
461
499
  function Pulse({ scale }: { scale: number }) {
@@ -464,13 +502,24 @@ function Pulse({ scale }: { scale: number }) {
464
502
  '0%': { transform: 'scale(1)' },
465
503
  '100%': { transform: `scale(${scale})` },
466
504
  }),
467
- [scale]
505
+ [scale],
506
+ { name: 'pulse' },
468
507
  );
469
508
 
470
- return <div style={{ animation: `${pulse} 500ms ease-in-out alternate infinite` }} />;
509
+ return (
510
+ <div
511
+ style={{ animation: `${pulse} 500ms ease-in-out alternate infinite` }}
512
+ />
513
+ );
471
514
  }
472
515
  ```
473
516
 
517
+ Passing `name` claims a slot owned by that one call site, per `root` — much like
518
+ `id` in `useGlobalStyles()` and `useRawCSS()`. When the steps change the previous
519
+ `@keyframes` rule is disposed and the name is reused, so the rules don't
520
+ accumulate and the returned name stays stable. Anonymous keyframes are permanent
521
+ and shared by content.
522
+
474
523
  ### useProperty
475
524
 
476
525
  Register a CSS `@property` rule so a custom property can animate smoothly:
@@ -517,8 +566,16 @@ For multiple weights/styles, pass an array:
517
566
 
518
567
  ```tsx
519
568
  useFontFace('Brand Sans', [
520
- { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
521
- { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
569
+ {
570
+ src: 'url("/fonts/brand-regular.woff2") format("woff2")',
571
+ fontWeight: 400,
572
+ fontDisplay: 'swap',
573
+ },
574
+ {
575
+ src: 'url("/fonts/brand-bold.woff2") format("woff2")',
576
+ fontWeight: 700,
577
+ fontDisplay: 'swap',
578
+ },
522
579
  ]);
523
580
  ```
524
581
 
@@ -536,11 +593,14 @@ Inject a `@counter-style` rule and get back the counter style name. Permanent
536
593
  import { useCounterStyle } from '@tenphi/tasty';
537
594
 
538
595
  function EmojiList() {
539
- const styleName = useCounterStyle({
540
- system: 'cyclic',
541
- symbols: '"👍"',
542
- suffix: '" "',
543
- }, { name: 'thumbs' });
596
+ const styleName = useCounterStyle(
597
+ {
598
+ system: 'cyclic',
599
+ symbols: '"👍"',
600
+ suffix: '" "',
601
+ },
602
+ { name: 'thumbs' },
603
+ );
544
604
 
545
605
  return (
546
606
  <ol style={{ listStyleType: styleName }}>
@@ -560,6 +620,46 @@ function useCounterStyle(
560
620
  ): string;
561
621
  ```
562
622
 
623
+ ### useFunction
624
+
625
+ Register a CSS `@function` (custom function). Permanent — no cleanup on unmount. Deduplicates by function name. The function name accepts `$$name` (matching the call site `$$name(...)`), `$name`, or `--name`.
626
+
627
+ ```tsx
628
+ import { tasty, useFunction } from '@tenphi/tasty';
629
+
630
+ const Box = tasty({ styles: { margin: '$$negative(10px) top' } });
631
+
632
+ function Layout() {
633
+ useFunction('$$negative', { args: ['$value'], result: '(-1 * $value)' });
634
+ return <Box />;
635
+ }
636
+ ```
637
+
638
+ Call the function through the Tasty DSL rather than a raw `style` prop. An inline `style` value reaches the browser unparsed, so the `$$name(...)` sugar is never expanded — and under `configure({ polyfills: { functions: true } })` it silently does nothing, because the polyfill rewrites calls at parse time.
639
+
640
+ Inside a `tasty()` component you call functions with the same `$$name(...)` sugar:
641
+
642
+ ```tsx
643
+ const Box = tasty({
644
+ styles: {
645
+ '@function': { $$negative: { args: ['$value'], result: '(-1 * $value)' } },
646
+ margin: '$$negative(10px) top',
647
+ },
648
+ });
649
+ ```
650
+
651
+ Signature:
652
+
653
+ ```ts
654
+ function useFunction(
655
+ name: string,
656
+ definition: FunctionDefinition,
657
+ options?: { root?: Document | ShadowRoot },
658
+ ): void;
659
+ ```
660
+
661
+ See the [Functions section of the DSL reference](dsl.md#functions-function) for the full descriptor shape, token conventions, and value-sugar support. `@function` is an experimental CSS feature — unsupported browsers safely ignore the native rule, or enable the [`polyfills.functions`](configuration.md#polyfills) inline polyfill for full cross-browser support.
662
+
563
663
  ### Troubleshooting
564
664
 
565
665
  - Styles are not updating: make sure `configure()` runs before first render, and verify the generated class name or global rule with [Debug Utilities](debug.md).
@@ -576,6 +676,6 @@ function useCounterStyle(
576
676
  - **[Methodology](methodology.md)** — Recommended patterns: root + sub-elements, styleProps, tokens, wrapping
577
677
  - **[Configuration](configuration.md)** — Tokens, recipes, custom units, style handlers, TypeScript extensions
578
678
  - **[Style Properties](styles.md)** — Complete reference for all enhanced style properties
579
- - **[Zero Runtime (tastyStatic)](tasty-static.md)** — Build-time static styling with Babel plugin
679
+ - **[Build-Time Extraction (`tastyStatic`)](tasty-static.md)** — Static styling with the Babel plugin
580
680
  - **[Server-Side Rendering](ssr.md)** — SSR setup for Next.js, Astro, and generic frameworks
581
681
  - **[Debug Utilities](debug.md)** — Inspect injected CSS, cache state, and active styles at runtime
@@ -0,0 +1,216 @@
1
+ # Runtime Benchmarks
2
+
3
+ Tasty keeps its performance claims in reproducible benchmarks rather than
4
+ combining unlike measurements into one score. The repository measures four
5
+ different costs:
6
+
7
+ 1. Style parsing and generation in Node.
8
+ 2. The React overhead of an empty `tasty({})` wrapper.
9
+ 3. Cold browser generation and injection compared with equivalent CSS that is
10
+ already on the page.
11
+ 4. A representative React update that combines wrapper, cache, generation,
12
+ injection, and style-resolution work.
13
+
14
+ These are focused microbenchmarks, not page-load or interaction scores. Run
15
+ them several times on an otherwise idle machine and use a production profile
16
+ to decide whether any cost matters in an application.
17
+
18
+ ## Reproducing the Results
19
+
20
+ ```bash
21
+ pnpm bench
22
+ pnpm bench:overhead
23
+ pnpm bench:injection
24
+ pnpm bench:tree
25
+ ```
26
+
27
+ `pnpm bench` runs the core pipeline benchmarks in Node. The other three commands
28
+ use production code paths in headless Chromium. The first checkout may require
29
+ `pnpm test:setup` to download Chromium.
30
+
31
+ Run the Node and browser suites separately so they do not compete for CPU. The
32
+ browser timer has 0.1 ms resolution, so both browser benchmarks perform many
33
+ matched operations per sample and divide the absolute difference by the number
34
+ of elements or rules. Machine load, browser versions, and CPU power will move
35
+ the results.
36
+
37
+ ## Core Style Pipeline
38
+
39
+ The following numbers are single-call throughput measured on an Apple M1 Max
40
+ with Node 22:
41
+
42
+ | Operation | ops/sec | Latency (mean) |
43
+ | ----------------------------------------------------------- | -------------------: | -------------: |
44
+ | `renderStyles` — 5 flat properties (cold) | ~60,000 | ~17 us |
45
+ | `renderStyles` — state map with media/hover/modifier (cold) | ~18,500 | ~54 us |
46
+ | `renderStyles` — same styles (cached) | ~5,800,000 | ~0.17 us |
47
+ | `parseStateKey` — simple key like `:hover` (cold) | ~790,000 | ~1.3 us |
48
+ | `parseStateKey` — complex OR/AND/NOT key (cold) | ~140,000 | ~7 us |
49
+ | `parseStateKey` — any key (cached) | ~3,400,000–8,300,000 | ~0.1–0.3 us |
50
+ | `parseStyle` — value tokens like `2x 4x` (cold) | ~344,000 | ~2.9 us |
51
+ | `parseStyle` — color tokens (cold) | ~567,000 | ~1.8 us |
52
+ | `parseStyle` — any value (cached) | ~15,250,000 | ~0.07 us |
53
+
54
+ “Cold” cases use unique inputs to bypass the relevant caches. Cached cases
55
+ reuse one input and measure the LRU hot path. Expect roughly ±10% between runs.
56
+ These benchmarks do not include React, DOM work, stylesheet injection, style
57
+ resolution, layout, or paint.
58
+
59
+ The benchmark sources are colocated with the code they exercise:
60
+ [`pipeline.bench.ts`](../src/pipeline/pipeline.bench.ts),
61
+ [`parseStateKey.bench.ts`](../src/pipeline/parseStateKey.bench.ts), and the
62
+ parser benchmark files under [`src/parser`](../src/parser).
63
+
64
+ ## Empty Wrapper Overhead
65
+
66
+ Skipping the style pipeline does not make a `tasty()` component free. Even
67
+ `tasty({})` is a React component between its parent and the host element. React
68
+ tracks another fiber, and Tasty still processes and forwards the element's
69
+ props.
70
+
71
+ [`tasty-overhead.bench.tsx`](../src/tasty-overhead.bench.tsx) compares 10,000
72
+ raw `<div className>` siblings with 10,000 instances of one module-scoped
73
+ `tasty({})` component. Both receive the same props, and the benchmark fails if
74
+ they do not produce equivalent DOM.
75
+
76
+ The benchmark uses production React in headless Chromium. The factory is
77
+ created and its empty class-name cache is warmed before timing, so factory
78
+ creation, style generation, and injection are excluded. A detached container
79
+ excludes layout, paint, and stylesheet matching. Every commit is wrapped in
80
+ `flushSync`, keeping its synchronous reconciliation and commit inside the
81
+ sample. This does not estimate React's concurrent scheduling latency.
82
+
83
+ On an Apple M3 Pro with React 19.2.4 and Chromium 151, three consecutive runs
84
+ produced these ranges:
85
+
86
+ | Work on 10,000 siblings | Raw elements | `tasty({})` | Extra per wrapped element |
87
+ | ----------------------------------- | -----------: | -----------: | ------------------------: |
88
+ | Mount + remove | 4.5–4.9 ms | 14.0–14.9 ms | 0.95–1.00 us |
89
+ | Rerender, same host props | 1.3–1.4 ms | 10.9–11.4 ms | 0.96–1.00 us |
90
+ | Rerender, change one host attribute | 2.8–3.4 ms | 15.0–15.7 ms | 1.21–1.27 us |
91
+
92
+ The useful result is the raw/Tasty time difference divided by 10,000, not the
93
+ ratio between the two times. The ratio becomes large because the raw baseline
94
+ is tiny. In this synthetic workload, an empty wrapper adds roughly 1 us per
95
+ participating element, or 1.2–1.3 us when React also changes a DOM attribute.
96
+
97
+ This is the floor Tasty consumes when it has no styling job. It is not a
98
+ page-level score. Real trees include application components, effects, layout,
99
+ paint, and usually far fewer simultaneous styled-element updates. The benchmark
100
+ also does not measure retained memory; that requires a matched-tree heap
101
+ snapshot experiment with controlled garbage collection.
102
+
103
+ ## Cold Generation and Injection
104
+
105
+ [`tasty-injection.bench.ts`](../src/tasty-injection.bench.ts) measures the extra
106
+ work when Tasty must generate and inject CSS that an otherwise equivalent page
107
+ already has. It does not compare different stylesheet insertion techniques.
108
+
109
+ The benchmark covers four group sizes with one style-resolution boundary per
110
+ group:
111
+
112
+ - **One new rule:** add one rule, append its element, and immediately read its
113
+ computed style. Each sample performs 50 independent groups for timer
114
+ stability.
115
+ - **10 new rules together:** generate and insert 10 rules, append their 10
116
+ elements, then read every computed color without another write. Each sample
117
+ performs 10 independent groups.
118
+ - **100 or 1,000 new rules together:** perform the same sequence once per
119
+ sample with 100 or 1,000 rules before the resolution boundary.
120
+
121
+ Repeating the smaller groups inside one sample only raises the measurement
122
+ above Chromium's timer resolution. Results are divided by that repetition
123
+ count, so every row below describes one group with one resolution boundary.
124
+
125
+ For every transaction, the existing-CSS control has the equivalent stylesheet
126
+ parsed, adopted, and attached before timing. The runtime root has a Tasty
127
+ stylesheet pre-created with an unrelated sentinel rule, but not the measured
128
+ rules. Both paths perform the same class assignment, DOM commit, and
129
+ computed-style reads. Only the runtime path calls `computeStyles()` and inserts
130
+ the new rules.
131
+
132
+ Preparation and cleanup happen outside the sample timer. Every runtime style
133
+ value is unique within a cycle, the relevant caches are cleared between cycles,
134
+ and a guard verifies that both paths resolve to the same color. React and the
135
+ `tasty()` wrapper are absent so their independently measured costs do not enter
136
+ the result. Pre-creating both stylesheets also excludes one-time sheet creation
137
+ and adoption from the subtraction.
138
+
139
+ On an Apple M3 Pro with Chromium 151, three consecutive runs produced these
140
+ normalized ranges:
141
+
142
+ | New rules before one resolution | Groups per sample | Incremental cost per group | Incremental cost per rule |
143
+ | ------------------------------: | ----------------: | -------------------------: | ------------------------: |
144
+ | 1 | 50 | 0.111–0.114 ms | 111–114 us |
145
+ | 10 | 10 | 0.142–0.159 ms | 14.2–15.9 us |
146
+ | 100 | 1 | 0.90–0.94 ms | 9.0–9.4 us |
147
+ | 1,000 | 1 | 7.58–8.10 ms | 7.6–8.1 us |
148
+
149
+ The curve makes the fixed work visible. Delivering 1,000 rules before one
150
+ resolution boundary cost roughly 67–73 times as much in total as delivering
151
+ one rule and resolving it, not 1,000 times as much. The average incremental
152
+ cost per rule was roughly 14–15 times lower because the group amortized fixed
153
+ transaction work and let the browser resolve all stylesheet writes together.
154
+
155
+ The subtraction is the meaningful result. It includes Tasty's cold style
156
+ generation, cache and injector bookkeeping, rule insertion, and any additional
157
+ style invalidation exposed by that workload's resolution boundary. It does not
158
+ pretend to isolate `insertRule()` from the system that calls it.
159
+
160
+ This is a deliberately cold workload. Reused styles resolve from cache and do
161
+ not inject another rule. Different rule complexity, DOM shape, stylesheet size,
162
+ browser, and hardware will change the number. Because the same group and
163
+ resolution pattern is present in each workload's control, the difference
164
+ answers the narrower delivery question: how much extra work did Tasty perform
165
+ when the same CSS was not already there?
166
+
167
+ ## Representative React Tree
168
+
169
+ [`tasty-tree.bench.tsx`](../src/tasty-tree.bench.tsx) bridges the isolated
170
+ measurements with one production React update. Every path updates 1,000 host
171
+ elements sharing 20 combinations of `color` and `padding`, then reads computed
172
+ styles after the commit:
173
+
174
+ - **CSS already present:** raw elements switch between classes whose rules were
175
+ attached before timing.
176
+ - **Tasty, warm:** the elements switch between two sets of Tasty styles that
177
+ were generated before timing.
178
+ - **Tasty, cold:** every update introduces 20 new combinations shared across
179
+ the 1,000 elements.
180
+
181
+ The Tasty paths use the normal component API and `TastyBatchProvider`. On an
182
+ Apple M3 Pro with production React 19.2.4 and Chromium 151, three consecutive
183
+ runs produced these mean ranges:
184
+
185
+ | Update path | Total time for 1,000 elements |
186
+ | ----------------------------------- | ----------------------------: |
187
+ | CSS already present | 1.64–1.70 ms |
188
+ | Tasty, shared styles already cached | 4.17–4.43 ms |
189
+ | Tasty, 20 new shared styles | 4.62–4.80 ms |
190
+
191
+ In this workload, the warmed Tasty path added 2.52–2.73 ms over raw elements
192
+ with existing CSS. Introducing 20 new shared combinations added another
193
+ 0.38–0.55 ms over the warm Tasty update. This is a synthetic update, not an
194
+ application score: it excludes effects, layout reads, paint, and concurrent
195
+ scheduling, while deliberately making all 1,000 elements participate in every
196
+ commit.
197
+
198
+ ## Reading the Results Together
199
+
200
+ Do not add all three benchmark numbers to estimate an application blindly.
201
+ They describe different paths:
202
+
203
+ - A stable `tasty()` factory can skip the style pipeline on later renders, but
204
+ its React wrapper still participates in reconciliation.
205
+ - A cached style avoids cold parsing and generation and does not insert a new
206
+ rule.
207
+ - A genuinely new style pays generation and injection once, then becomes
208
+ reusable.
209
+ - A tree that shares a small style vocabulary pays the wrapper path per element
210
+ but cold generation only per new combination.
211
+ - Browser style resolution, layout, and paint depend on the actual document and
212
+ need application-level profiling.
213
+
214
+ The practical optimization target is therefore repeated work: keep style input
215
+ stable when possible, reuse generated chunks, and generate CSS at build or
216
+ server time when runtime flexibility is unnecessary.