@tenphi/tasty 0.0.0-snapshot.cb3b623 → 0.0.0-snapshot.cca2ea6

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 (92) hide show
  1. package/README.md +176 -131
  2. package/dist/{async-storage-B7_o6FKt.js → async-storage-DKK-wTD4.js} +1 -1
  3. package/dist/{async-storage-B7_o6FKt.js.map → async-storage-DKK-wTD4.js.map} +1 -1
  4. package/dist/babel-CHy3n_M7.d.ts +83 -0
  5. package/dist/{collector-osfWTeRd.d.ts → collector-0YO-P1vW.d.ts} +44 -7
  6. package/dist/{collector-BZe0AMUR.js → collector-Eve9-4dP.js} +76 -15
  7. package/dist/collector-Eve9-4dP.js.map +1 -0
  8. package/dist/{config-LDodmgVz.js → config-Bwerr9rW.js} +3914 -2020
  9. package/dist/config-Bwerr9rW.js.map +1 -0
  10. package/dist/{config-BoZDUHW5.d.ts → config-DRp9aYRG.d.ts} +436 -63
  11. package/dist/{context-CkSg-kDT.js → context-CA8YKeMn.js} +1 -1
  12. package/dist/{context-CkSg-kDT.js.map → context-CA8YKeMn.js.map} +1 -1
  13. package/dist/core/index.d.ts +5 -5
  14. package/dist/core/index.js +6 -6
  15. package/dist/{core-CQfmSOQW.js → core-C9nPCkW6.js} +202 -219
  16. package/dist/core-C9nPCkW6.js.map +1 -0
  17. package/dist/{css-writer-BjqQ_6-j.js → css-writer-7SOcy4BM.js} +54 -15
  18. package/dist/css-writer-7SOcy4BM.js.map +1 -0
  19. package/dist/{format-global-rules-Dbc_1tc3.js → format-global-rules-DklyaXv-.js} +1 -1
  20. package/dist/{format-global-rules-Dbc_1tc3.js.map → format-global-rules-DklyaXv-.js.map} +1 -1
  21. package/dist/{format-rules-CkZinBt0.js → format-rules-Cb8LAho6.js} +4 -17
  22. package/dist/format-rules-Cb8LAho6.js.map +1 -0
  23. package/dist/{hydrate-M5WHyrmy.js → hydrate-DfL38fk5.js} +4 -12
  24. package/dist/{hydrate-M5WHyrmy.js.map → hydrate-DfL38fk5.js.map} +1 -1
  25. package/dist/{index-J7y6BV89.d.ts → index-B1A0pcCf.d.ts} +496 -201
  26. package/dist/{index-tcHuMPFt.d.ts → index-BmogEzTo.d.ts} +358 -69
  27. package/dist/index.d.ts +5 -5
  28. package/dist/index.js +250 -60
  29. package/dist/index.js.map +1 -1
  30. package/dist/{keyframes-Bp3MU20J.js → keyframes-CygCEfJG.js} +97 -192
  31. package/dist/keyframes-CygCEfJG.js.map +1 -0
  32. package/dist/{merge-styles-BMWcH6MF.d.ts → merge-styles-BcLl1u_d.d.ts} +2 -2
  33. package/dist/{merge-styles-DQW8Anlk.js → merge-styles-Bh_wsNk_.js} +2 -2
  34. package/dist/{merge-styles-DQW8Anlk.js.map → merge-styles-Bh_wsNk_.js.map} +1 -1
  35. package/dist/{resolve-recipes-BIxxAwSm.js → resolve-recipes-Da6piP7f.js} +3 -3
  36. package/dist/{resolve-recipes-BIxxAwSm.js.map → resolve-recipes-Da6piP7f.js.map} +1 -1
  37. package/dist/ssr/astro-client.js +1 -1
  38. package/dist/ssr/astro-client.js.map +1 -1
  39. package/dist/ssr/astro-middleware-static.d.ts +16 -0
  40. package/dist/ssr/astro-middleware-static.js +18 -0
  41. package/dist/ssr/astro-middleware-static.js.map +1 -0
  42. package/dist/ssr/astro-middleware.d.ts +8 -6
  43. package/dist/ssr/astro-middleware.js +10 -10
  44. package/dist/ssr/astro-middleware.js.map +1 -1
  45. package/dist/ssr/astro.d.ts +1 -5
  46. package/dist/ssr/astro.js +29 -21
  47. package/dist/ssr/astro.js.map +1 -1
  48. package/dist/ssr/index.d.ts +2 -9
  49. package/dist/ssr/index.js +5 -5
  50. package/dist/ssr/index.js.map +1 -1
  51. package/dist/ssr/next.d.ts +2 -3
  52. package/dist/ssr/next.js +6 -7
  53. package/dist/ssr/next.js.map +1 -1
  54. package/dist/static/index.d.ts +2 -2
  55. package/dist/static/index.js +4 -4
  56. package/dist/static/index.js.map +1 -1
  57. package/dist/static/inject.js.map +1 -1
  58. package/dist/zero/babel.d.ts +2 -81
  59. package/dist/zero/babel.js +27 -23
  60. package/dist/zero/babel.js.map +1 -1
  61. package/dist/zero/index.d.ts +16 -2
  62. package/dist/zero/index.js +2 -2
  63. package/dist/zero/next.d.ts +1 -1
  64. package/dist/zero/next.js +1 -1
  65. package/dist/zero/next.js.map +1 -1
  66. package/docs/README.md +17 -9
  67. package/docs/adoption.md +56 -31
  68. package/docs/ai-agents.md +224 -0
  69. package/docs/comparison.md +69 -40
  70. package/docs/configuration.md +470 -85
  71. package/docs/debug.md +11 -9
  72. package/docs/design-system.md +43 -24
  73. package/docs/dsl.md +508 -177
  74. package/docs/getting-started.md +60 -39
  75. package/docs/injector.md +120 -30
  76. package/docs/methodology.md +44 -38
  77. package/docs/migration-v3.md +285 -0
  78. package/docs/pipeline.md +53 -11
  79. package/docs/plugins.md +353 -0
  80. package/docs/react-api.md +142 -42
  81. package/docs/runtime-benchmarks.md +178 -0
  82. package/docs/ssr.md +90 -83
  83. package/docs/styles.md +56 -9
  84. package/docs/tasty-static.md +140 -105
  85. package/package.json +46 -20
  86. package/tasty.config.ts +5 -0
  87. package/dist/collector-BZe0AMUR.js.map +0 -1
  88. package/dist/config-LDodmgVz.js.map +0 -1
  89. package/dist/core-CQfmSOQW.js.map +0 -1
  90. package/dist/css-writer-BjqQ_6-j.js.map +0 -1
  91. package/dist/format-rules-CkZinBt0.js.map +0 -1
  92. package/dist/keyframes-Bp3MU20J.js.map +0 -1
@@ -1,5 +1,52 @@
1
- import { Ct as RawCSSResult, Dt as StyleInjectorConfig, Et as SheetInfo, M as StyleHandlerDefinition, Ot as StyleRule, St as PropertyDefinition, Tt as RuleInfo, b as Styles, bt as KeyframesResult, ct as CacheMetrics, dt as FontFaceDescriptors, ft as FontFaceInput, gt as InjectResult, h as ConfigTokens, ht as GlobalInjectResult, it as StyleDetails, lt as CounterStyleDescriptors, mt as GCOptions, n as StyleResult, ot as UnitHandler, pt as GCConfig, v as RecipeStyles, wt as RootRegistry, xt as KeyframesSteps, yt as KeyframesInfo } from "./index-tcHuMPFt.js";
1
+ import { At as StyleRule, Ct as PropertyDefinition, Dt as RuleInfo, Et as RootRegistry, Ot as SheetInfo, P as StyleHandlerDefinition, St as KeyframesSteps, Tt as RawCSSResult, _t as InjectResult, b as Styles, bt as KeyframesInfo, dt as FunctionDefinition, gt as InjectOptions, h as ConfigTokens, ht as GlobalInjectResult, it as UnitHandler, kt as StyleInjectorConfig, lt as FontFaceDescriptors, mt as GCOptions, n as StyleResult, nt as StyleDetails, ot as CacheMetrics, pt as GCConfig, st as CounterStyleDescriptors, ut as FontFaceInput, v as RecipeStyles, xt as KeyframesResult } from "./index-BmogEzTo.js";
2
2
 
3
+ //#region src/prop-handlers.d.ts
4
+ /**
5
+ * Props middleware for tasty components.
6
+ *
7
+ * A prop handler receives a component's props and returns them, changed or not.
8
+ * That makes it the extension point for props that are *not* style properties:
9
+ * it can read a custom prop, strip it so it never reaches the DOM, and fold its
10
+ * meaning into `styles`, `mods`, `tokens`, `variant`, or `as`.
11
+ *
12
+ * ```ts
13
+ * configure({
14
+ * propHandlers: {
15
+ * glaze: (props) => {
16
+ * const { glaze, ...rest } = props;
17
+ * if (!glaze) return rest;
18
+ * return { ...rest, styles: mergeStyles(glazeStyles(glaze), rest.styles) };
19
+ * },
20
+ * },
21
+ * });
22
+ * ```
23
+ *
24
+ * Handlers run on every render of every tasty component, so the registry is a
25
+ * pre-composed chain that is `null` while nothing is registered — the cost when
26
+ * unused is one property load and one branch.
27
+ */
28
+ /** Props object handed to a prop handler. Deliberately untyped: handlers see everything. */
29
+ type PropHandlerProps = Record<string, unknown>;
30
+ /**
31
+ * Props middleware: props in, props out. Returning nothing means "unchanged".
32
+ *
33
+ * Must be a **pure function** and must not mutate its input. Style values are
34
+ * cached by object identity, so mutating a value object in place produces a stale
35
+ * class name and stale CSS. Return fresh (ideally frozen, ideally memoized)
36
+ * objects instead.
37
+ */
38
+ type PropHandler = (props: PropHandlerProps) => PropHandlerProps | void | null;
39
+ /**
40
+ * How a prop handler is declared. The map key is both its name and, by default,
41
+ * the prop that triggers it.
42
+ *
43
+ * - `fn` — triggered when a prop matching the key is present
44
+ * - `['glaze', fn]` — triggered by the named prop
45
+ * - `[['glaze', 'tone'], fn]` — triggered by any of them
46
+ * - `['*', fn]` — unconditional; runs on every render of every component
47
+ */
48
+ type PropHandlerDefinition = PropHandler | [string, PropHandler] | [string[], PropHandler];
49
+ //#endregion
3
50
  //#region src/injector/sheet-manager.d.ts
4
51
  declare class SheetManager {
5
52
  private rootRegistries;
@@ -20,6 +67,19 @@ declare class SheetManager {
20
67
  * abstracting away adopted vs style-element modes.
21
68
  */
22
69
  getCSSSheet(sheetInfo: SheetInfo): CSSStyleSheet | null;
70
+ /**
71
+ * Record an inserted rule text at its rule index (text mode only).
72
+ *
73
+ * `textRules` mirrors the sheet's rule order. `textContent` cannot be edited
74
+ * rule-by-rule the way CSSOM can, so keeping the texts is what makes
75
+ * deletion possible at all in this mode.
76
+ */
77
+ private trackTextRule;
78
+ /**
79
+ * Remove rule indices from a text-mode sheet and rewrite the element's text.
80
+ * Returns the indices that were actually removed.
81
+ */
82
+ private deleteTextRules;
23
83
  /**
24
84
  * Determine the injection mode for a root.
25
85
  * ShadowRoot uses adopted stylesheets when supported; Document uses <style> elements.
@@ -91,13 +151,16 @@ declare class SheetManager {
91
151
  */
92
152
  private engineSupportsAtProperty;
93
153
  /**
94
- * Force cleanup of unused styles
95
- */
96
- forceCleanup(registry: RootRegistry): void;
97
- /**
98
- * Perform bulk cleanup of all unused styles (refCount = 0).
154
+ * Delete the given classes: their rules leave the sheets and every registry
155
+ * entry pointing at them is dropped.
156
+ *
157
+ * Deciding *what* is unused belongs to `StyleInjector.gc()`, which owns the
158
+ * DOM scan and the capacity policy. This only re-checks that each class is
159
+ * still safe to delete, and reports how many were.
160
+ *
161
+ * @returns Number of classes actually deleted.
99
162
  */
100
- private performBulkCleanup;
163
+ deleteClasses(registry: RootRegistry, classNames: Iterable<string>): number;
101
164
  /**
102
165
  * Get total number of rules across all sheets
103
166
  */
@@ -105,7 +168,7 @@ declare class SheetManager {
105
168
  /**
106
169
  * Get CSS text from all sheets (for SSR)
107
170
  */
108
- getCssText(registry: RootRegistry): string;
171
+ getCSSText(registry: RootRegistry): string;
109
172
  /**
110
173
  * Get cache performance metrics
111
174
  */
@@ -177,12 +240,43 @@ declare class StyleInjector {
177
240
  private sheetManager;
178
241
  private config;
179
242
  private globalRuleCounter;
180
- private pendingGCHandle;
243
+ /** Cancels the scheduled sweep, whichever timer scheduled it. */
244
+ private cancelPendingGC;
181
245
  private namePrefix;
182
246
  private classRegex;
183
247
  private rscClassRegex;
184
248
  /** @internal — exposed for debug utilities only */
185
249
  get _sheetManager(): SheetManager;
250
+ /**
251
+ * Whether sheet writes should be queued instead of applied immediately.
252
+ *
253
+ * Only ever true on the client: SSR collects CSS as text and the RSC path
254
+ * returns it as strings, so neither has a live sheet to batch writes against.
255
+ *
256
+ * In the default `true` mode a write is only queued inside an open batch
257
+ * window — a commit in which `<TastyBatchProvider>` rendered and will
258
+ * therefore flush in its insertion effect, before any layout effect can
259
+ * measure. Everything else falls through to a synchronous write, so enabling
260
+ * the flag cannot make a `useLayoutEffect` read an unstyled element.
261
+ * `'always'` drops the gate and accepts that trade for wider coverage.
262
+ */
263
+ private get batching();
264
+ /**
265
+ * Apply a sheet write now, or queue it when batching is on.
266
+ * Returns the queue handle when deferred, so the caller can cancel it if it
267
+ * disposes before the flush.
268
+ */
269
+ private writeSheet;
270
+ /**
271
+ * Insert a global (non-class) rule, honouring batching.
272
+ *
273
+ * `onApplied` records the caller's dedupe bookkeeping. When the write is
274
+ * queued it runs eagerly, so a repeat call before the flush bails out instead
275
+ * of queueing the same rule twice — the same reasoning as
276
+ * `insertPropertyRule`'s eager marking. When written synchronously it runs
277
+ * only on success, preserving the existing retry-on-failure behaviour.
278
+ */
279
+ private writeGlobalRule;
186
280
  constructor(config?: StyleInjectorConfig);
187
281
  /**
188
282
  * Generate a deterministic class name from a cache key using content hash.
@@ -208,10 +302,7 @@ declare class StyleInjector {
208
302
  /**
209
303
  * Inject styles from StyleResult objects
210
304
  */
211
- inject(rules: StyleResult[], options?: {
212
- root?: Document | ShadowRoot;
213
- cacheKey?: string;
214
- }): InjectResult;
305
+ inject(rules: StyleResult[], options?: InjectOptions): InjectResult;
215
306
  /**
216
307
  * Inject global styles (rules without a generated tasty class selector)
217
308
  * This ensures we don't reserve a tasty class name (t{number}) for global rules,
@@ -235,32 +326,46 @@ declare class StyleInjector {
235
326
  root?: Document | ShadowRoot;
236
327
  }): string;
237
328
  /**
238
- * Increment refCount for an already-injected cacheKey and return a dispose.
239
- * Used by useStyles on cache hits (hydration or runtime reuse) where
240
- * the pipeline was skipped but refCount tracking is still needed.
241
- * Returns null if the cacheKey is not found.
329
+ * Hold the local `@keyframes` a set of classes animates, and tell the caller
330
+ * what they ended up being called.
331
+ *
332
+ * One reference per distinct set of steps, taken the first time it is asked
333
+ * for and shared by every class that animates it — a repeat render finds it
334
+ * already held and takes nothing further, which is what stops the reference
335
+ * count climbing for the life of the page. The reference goes when the last
336
+ * of those classes is deleted.
337
+ */
338
+ holdKeyframes(classNames: string[], steps: Record<string, KeyframesSteps>, options?: {
339
+ root?: Document | ShadowRoot;
340
+ }): Map<string, string> | null;
341
+ /**
342
+ * Pin an already-injected cacheKey and return the handle that releases it.
343
+ * For callers that skipped the pipeline on a cache hit but still need the
344
+ * class held. Returns null if the cacheKey is not found.
242
345
  */
243
346
  trackRef(cacheKey: string, options?: {
244
347
  root?: Document | ShadowRoot;
245
348
  }): InjectResult | null;
246
349
  /**
247
- * Dispose of a className (decrements refCount only).
350
+ * Release one pin on a className. At zero pins the class is not deleted — it
351
+ * stays cached and collectible, and `gc()` decides when it actually goes.
248
352
  */
249
- private dispose;
353
+ private unpin;
250
354
  /**
251
- * Force bulk cleanup of unused styles
355
+ * Remove every style that is neither in the DOM nor referenced by an
356
+ * outstanding `inject()` handle, ignoring the GC capacity threshold.
252
357
  */
253
358
  cleanup(root?: Document | ShadowRoot): void;
254
359
  /**
255
360
  * Get CSS text from all sheets (for SSR)
256
361
  */
257
- getCssText(options?: {
362
+ getCSSText(options?: {
258
363
  root?: Document | ShadowRoot;
259
364
  }): string;
260
365
  /**
261
366
  * Get CSS only for the provided tasty classNames (e.g., ["t0","t3"])
262
367
  */
263
- getCssTextForClasses(classNames: Iterable<string>, options?: {
368
+ getCSSTextForClasses(classNames: Iterable<string>, options?: {
264
369
  root?: Document | ShadowRoot;
265
370
  }): string;
266
371
  /**
@@ -322,11 +427,28 @@ declare class StyleInjector {
322
427
  /**
323
428
  * Inject a CSS @counter-style rule.
324
429
  *
325
- * Permanent and global — no dispose or ref-counting.
326
- * Deduplicates by name (first definition wins).
430
+ * Permanent and global — no dispose or ref-counting. Deduplicates by name.
431
+ * By default a definition overrides a previously injected one of the same
432
+ * name. Pass `weak: true` for global `configure()` definitions, which must
433
+ * never clobber an existing rule (so component-local definitions win
434
+ * regardless of injection order).
327
435
  */
328
436
  counterStyle(name: string, descriptors: CounterStyleDescriptors, options?: {
329
437
  root?: Document | ShadowRoot;
438
+ weak?: boolean;
439
+ }): void;
440
+ /**
441
+ * Inject a CSS @function rule (custom function).
442
+ *
443
+ * Permanent and global — no dispose or ref-counting. Deduplicates by function
444
+ * name. By default a definition overrides a previously injected one of the
445
+ * same name. Pass `weak: true` for global `configure()` definitions, which
446
+ * must never clobber an existing rule (so component-local definitions win
447
+ * regardless of injection order).
448
+ */
449
+ func(name: string, definition: FunctionDefinition, options?: {
450
+ root?: Document | ShadowRoot;
451
+ weak?: boolean;
330
452
  }): void;
331
453
  /**
332
454
  * Inject keyframes and return object with toString() and dispose()
@@ -346,27 +468,67 @@ declare class StyleInjector {
346
468
  */
347
469
  private disposeKeyframes;
348
470
  /**
349
- * Record a render-time usage hit for one or more classNames.
350
- * Handles space-separated multi-chunk classNames.
351
- * When the global touch counter reaches `touchInterval`, schedules a GC
352
- * via `requestIdleCallback`.
353
- * No-op on the server.
471
+ * Count a render, and schedule a collection pass every `touchInterval` of
472
+ * them. Nothing else: what a class is worth keeping is decided by the sweep's
473
+ * own DOM scan, so rendering does not track usage at all.
474
+ *
475
+ * @deprecated The class name is ignored — pass anything, or stop calling it.
476
+ * Collection no longer records per-class usage, and scheduling does not need
477
+ * to know which class was rendered.
354
478
  */
355
- touch(className: string, options?: {
479
+ touch(_className: string, options?: {
356
480
  root?: Document | ShadowRoot;
357
481
  }): void;
358
482
  /**
359
- * Schedule a GC via `requestIdleCallback` (or synchronously as fallback).
360
- * Runs GC on all active roots. Avoids double-scheduling via `pendingGCHandle`.
483
+ * Schedule a GC in idle time. Runs GC on all active roots, and avoids
484
+ * double-scheduling.
485
+ *
486
+ * Idle only. Without `requestIdleCallback` nothing is collected
487
+ * automatically: running the sweep inline here would put it inside the render
488
+ * that touched the class, and collection is never urgent enough for that.
361
489
  */
362
490
  private scheduleGC;
491
+ /**
492
+ * The one definition of "unused": this injector owns the class's rules, no
493
+ * element in `root` carries it, and nobody pinned it.
494
+ *
495
+ * `gc()` evicts from this set, `getMetrics()` counts it, and `tastyDebug`
496
+ * reports it — all through here, so the three can never disagree about what
497
+ * "unused" means. Entries carry their last `touch()` so callers can drop the
498
+ * oldest first; a class that was never touched sorts as oldest.
499
+ */
500
+ /**
501
+ * Everything the injector holds falls into one of five bands, and only the
502
+ * last of them is ever deleted:
503
+ *
504
+ * 1. rendered — some element carries the class right now
505
+ * 2. not ours — queued for a batched write, pre-allocated, or server-rendered
506
+ * 3. hot — nothing carries it, but that was noticed less than `grace` ago
507
+ * 4. cached — cold, but within `capacity` when ordered by when it went cold
508
+ * 5. the rest
509
+ *
510
+ * This returns bands 4 and 5 together, most recently cold first; `gc()` draws
511
+ * the capacity line through them. Band 3 is what makes collection safe
512
+ * without a commit signal: a render can resolve a class and commit it a
513
+ * little later, and during that gap nothing on the page carries it.
514
+ */
515
+ private collectUnused;
516
+ /**
517
+ * Class names this injector holds CSS for that nothing renders and nobody
518
+ * pinned — exactly what `gc({ force: true })` would delete. Unordered.
519
+ */
520
+ getUnusedClasses(options?: {
521
+ root?: Document | ShadowRoot;
522
+ }): string[];
363
523
  /**
364
524
  * Synchronous garbage collection.
365
525
  *
366
- * 1. Quick upper-bound check: skip if unused count can't exceed capacity.
367
- * 2. Scans the DOM for live tasty classNames (safety guard).
368
- * 3. With `force: true`: deletes all unused entries inline.
369
- * Without `force`: collects unused, sorts oldest-first, evicts over capacity.
526
+ * 1. Quick upper-bound check: skip if the registry is smaller than capacity.
527
+ * 2. Scans the DOM for live tasty classNames — the DOM, not a ref count, is
528
+ * what says a class rendered by a component is still in use.
529
+ * 3. With `force: true`: deletes every unused class.
530
+ * Without `force`: keeps the `capacity` most recently touched and deletes
531
+ * the rest, oldest first.
370
532
  *
371
533
  * @returns Number of styles evicted.
372
534
  */
@@ -377,7 +539,38 @@ declare class StyleInjector {
377
539
  destroy(root?: Document | ShadowRoot): void;
378
540
  }
379
541
  //#endregion
542
+ //#region src/functions/index.d.ts
543
+ /**
544
+ * A parse-time function: receives the parsed (comma-separated) argument groups
545
+ * and returns a CSS value string. This is the JS flavor of the unified
546
+ * `functions` config (bare-name keys), distinct from declarative `@function`
547
+ * definitions (`$$`-prefixed keys).
548
+ */
549
+ type ParseFunction = (groups: StyleDetails[]) => string;
550
+ /**
551
+ * The unified `functions` map: keys are either bare names (parse functions,
552
+ * value is a function) or `$$name`/`$name`/`--name` (declarative CSS functions,
553
+ * value is a {@link FunctionDefinition} object).
554
+ */
555
+ type FunctionsConfig = Record<string, FunctionDefinition | ParseFunction>;
556
+ //#endregion
380
557
  //#region src/utils/color-space.d.ts
558
+ /**
559
+ * Color handling that survives into the emitted CSS.
560
+ *
561
+ * Tasty does not rewrite a color into a particular color space: opacity is
562
+ * applied with CSS relative color syntax, which reads the channels off whatever
563
+ * the browser resolves a value to, so a color is emitted exactly as authored.
564
+ * What is left here is how an alpha gets applied, and the one distinction that
565
+ * matters — replacing a token's alpha versus composing onto an inherited one.
566
+ */
567
+ /**
568
+ * The color space a `#name` token's value used to be rewritten into.
569
+ *
570
+ * @deprecated Kept for the `colorSpace` config option, which no longer has any
571
+ * effect. Colors are emitted as authored and opacity is always applied in
572
+ * `oklch` through relative color syntax.
573
+ */
381
574
  type ColorSpace = 'rgb' | 'hsl' | 'oklch';
382
575
  //#endregion
383
576
  //#region src/utils/typography.d.ts
@@ -441,8 +634,12 @@ declare function generateTypographyTokens(presets: Record<string, TypographyPres
441
634
  interface TastyPlugin {
442
635
  /** Unique name for the plugin (used for debugging and conflict detection) */
443
636
  name: string;
444
- /** Custom functions that transform parsed style groups into CSS values */
445
- funcs?: Record<string, (groups: StyleDetails[]) => string>;
637
+ /**
638
+ * Custom functions (unified map). Bare keys map to parse functions
639
+ * `(groups) => string`; `$$name` keys map to declarative CSS `@function`
640
+ * definitions. See {@link FunctionsConfig}.
641
+ */
642
+ functions?: FunctionsConfig;
446
643
  /** Custom units that transform numeric values (e.g., `2x` → `calc(2 * var(--gap))`) */
447
644
  units?: Record<string, string | UnitHandler>;
448
645
  /** Custom state aliases (e.g., `'@mobile': '@media(w < 768px)'`) */
@@ -461,11 +658,37 @@ interface TastyPlugin {
461
658
  * ```
462
659
  */
463
660
  handlers?: Record<string, StyleHandlerDefinition>;
661
+ /**
662
+ * Props middleware for every tasty component — props in, props out. The
663
+ * extension point for props that are not style properties: read a custom prop,
664
+ * strip it so it never reaches the DOM, and fold its meaning into `styles`,
665
+ * `mods`, `tokens`, `variant`, or `as`.
666
+ *
667
+ * Must be pure and must not mutate its input.
668
+ * See {@link TastyConfig.propHandlers}.
669
+ * @example
670
+ * ```ts
671
+ * propHandlers: {
672
+ * glaze: (props) => {
673
+ * const { glaze, ...rest } = props;
674
+ * if (!glaze) return rest;
675
+ * return { ...rest, styles: mergeStyles(glazeStyles(glaze), rest.styles) };
676
+ * },
677
+ * }
678
+ * ```
679
+ */
680
+ propHandlers?: Record<string, PropHandlerDefinition>;
681
+ /**
682
+ * Style properties exposed as top-level props on every tasty component, in
683
+ * addition to the built-in base styles.
684
+ * See {@link TastyConfig.baseStyleProps}.
685
+ */
686
+ baseStyleProps?: readonly string[];
464
687
  /**
465
688
  * Design tokens injected as CSS custom properties on `:root`.
466
689
  * Values are parsed through the Tasty DSL. Supports state maps.
467
690
  * - `$name` → `--name` CSS custom property
468
- * - `#name` → `--name-color` and `--name-color-{colorSpace}`
691
+ * - `#name` → `--name-color`
469
692
  */
470
693
  tokens?: ConfigTokens;
471
694
  /** Predefined tokens replaced during style parsing (`$name` or `#name`) */
@@ -492,6 +715,19 @@ interface TastyPlugin {
492
715
  * Supports the full Tasty style syntax.
493
716
  */
494
717
  globalStyles?: Record<string, Styles>;
718
+ /**
719
+ * Global CSS `@property` definitions. A plugin whose handler or prop handler
720
+ * emits a custom property usually wants one, so the property animates and
721
+ * inherits correctly instead of being treated as an untyped string.
722
+ * See {@link TastyConfig.properties}.
723
+ */
724
+ properties?: Record<string, PropertyDefinition>;
725
+ /** Global keyframes, injected only when referenced. See {@link TastyConfig.keyframes}. */
726
+ keyframes?: Record<string, KeyframesSteps>;
727
+ /** Global `@font-face` definitions. See {@link TastyConfig.fontFaces}. */
728
+ fontFaces?: Record<string, FontFaceInput>;
729
+ /** Global `@counter-style` definitions. See {@link TastyConfig.counterStyles}. */
730
+ counterStyles?: Record<string, CounterStyleDescriptors>;
495
731
  }
496
732
  /**
497
733
  * A factory function that creates a TastyPlugin.
@@ -502,13 +738,13 @@ interface TastyPlugin {
502
738
  * // Plugin without options
503
739
  * const okhslPlugin: TastyPluginFactory = () => ({
504
740
  * name: 'okhsl',
505
- * funcs: { okhsl: okhslFunc },
741
+ * functions: { okhsl: okhslFunction },
506
742
  * });
507
743
  *
508
744
  * // Plugin with options
509
745
  * const debugPlugin: TastyPluginFactory<{ verbose: boolean }> = (options) => ({
510
746
  * name: 'debug',
511
- * funcs: { debug: createDebugFunc(options.verbose) },
747
+ * functions: { debug: createDebugFunc(options.verbose) },
512
748
  * });
513
749
  * ```
514
750
  */
@@ -545,30 +781,92 @@ interface TastyConfig {
545
781
  */
546
782
  units?: Record<string, string | UnitHandler>;
547
783
  /**
548
- * Custom functions for the style parser (merged with existing).
549
- * Functions process parsed style groups and return CSS values.
550
- * @example { myFunc: (groups) => groups.map(g => g.output).join(' ') }
784
+ * Custom functions (merged with existing). A single map holds both flavors,
785
+ * discriminated by value type:
786
+ *
787
+ * - **Bare key + function value** — a parse-time function that processes the
788
+ * parsed argument groups and returns a CSS value. Called as `name(...)`.
789
+ * - **`$$name` key + object value** — a declarative CSS `@function`
790
+ * definition. Called as `$$name(...)` (→ native `--name(...)`).
791
+ *
792
+ * A key whose prefix does not match its value type (object under a bare key,
793
+ * or function under a `$$` key) is ignored with a dev warning.
794
+ *
795
+ * @example
796
+ * ```ts
797
+ * configure({
798
+ * functions: {
799
+ * double: (groups) => `calc(2 * ${groups[0].output})`, // parse function
800
+ * $$negative: { args: ['$value'], result: '(-1 * $value)' }, // CSS function
801
+ * },
802
+ * });
803
+ * ```
551
804
  */
552
- funcs?: Record<string, (groups: StyleDetails[]) => string>;
805
+ functions?: FunctionsConfig;
553
806
  /**
554
- * Color space used for decomposed color token companion variables.
555
- * Controls the CSS function and suffix for alpha composition.
807
+ * @deprecated No longer has any effect; will be removed in the next major.
808
+ * Setting it warns in development.
556
809
  *
557
- * - `'rgb'` — suffix `-rgb`, e.g. `rgb(var(--name-color-rgb) / .5)`
558
- * - `'hsl'` — suffix `-hsl`, e.g. `hsl(var(--name-color-hsl) / .5)`
559
- * - `'oklch'` — suffix `-oklch`, e.g. `oklch(var(--name-color-oklch) / .5)`
810
+ * A `#name` token's value used to be rewritten into this color space so an
811
+ * opacity suffix had numeric channels to write an alpha into. Opacity now uses
812
+ * relative color syntax — `oklch(from var(--name-color) l c h / .5)` — which
813
+ * has the browser read the channels, so a color is emitted exactly as
814
+ * authored and there is nothing left for the setting to decide.
560
815
  *
561
- * @default 'oklch'
816
+ * To address a token's channels yourself, write relative color syntax against
817
+ * the token: `oklch(from var(--brand-color) calc(l * 1.2) c h)`. It works on
818
+ * every `<color>`, including the ones no conversion could evaluate.
562
819
  */
563
820
  colorSpace?: ColorSpace;
564
821
  /**
565
822
  * Automatically infer and register CSS @property declarations
566
823
  * from custom property values found in styles, keyframes, and global config.
567
824
  * Covers all types: \<color\>, \<number\>, \<length\>, \<angle\>, \<percentage\>, \<time\>.
568
- * When false, only explicitly declared @properties are registered.
825
+ * When false, only explicitly declared @property are registered.
569
826
  * @default true
570
827
  */
571
828
  autoPropertyTypes?: boolean;
829
+ /**
830
+ * Defer stylesheet writes and apply them in one batch instead of performing
831
+ * one `insertRule()` per component during render.
832
+ *
833
+ * Each `insertRule()` on a live sheet invalidates style for that sheet's
834
+ * scope. When components inject during React's render phase while other
835
+ * components read layout in the same pass, the two interleave and the browser
836
+ * is forced to recalculate style between every injection. Batching collapses
837
+ * that into one invalidation per flush.
838
+ *
839
+ * - `false` (default) — inject synchronously, one write per component.
840
+ * - `true` — batch, but only inside a *batch window*: a commit in which
841
+ * `<TastyBatchProvider>` rendered and will therefore flush in its
842
+ * `useInsertionEffect`, before any `useLayoutEffect` runs. Any injection
843
+ * outside a window — a deep update the provider did not re-render for, an
844
+ * injection from a layout effect, an event handler, an async callback — is
845
+ * written straight through. Enabling this can never make a layout effect
846
+ * measure an unstyled element. Requires `<TastyBatchProvider>`; without it
847
+ * nothing is batched (and dev mode says so once).
848
+ * - `'always'` — batch every injection, flushing on a microtask when no
849
+ * window is open. Wins on more commits, but a `useLayoutEffect` that
850
+ * measures a freshly mounted element can read its unstyled box, because
851
+ * microtasks run after the layout phase. Paint is unaffected: microtasks
852
+ * always drain before the browser paints.
853
+ *
854
+ * No effect during SSR or RSC: styles are collected as text there, the
855
+ * runtime injector never runs, and the provider is inert without a
856
+ * `document`. No effect on zero-runtime `tastyStatic` styles either — those
857
+ * are extracted at build time and never reach the injector.
858
+ *
859
+ * @default false
860
+ * @example
861
+ * ```tsx
862
+ * configure({ batchInjection: true });
863
+ *
864
+ * <TastyBatchProvider>
865
+ * <App />
866
+ * </TastyBatchProvider>
867
+ * ```
868
+ */
869
+ batchInjection?: boolean | 'always';
572
870
  /**
573
871
  * Garbage collection configuration for unused styles.
574
872
  * GC is triggered by touch count: every `touchInterval` touches, the
@@ -597,7 +895,7 @@ interface TastyConfig {
597
895
  * `'ts'` (overridable via the same option) so its classes can't
598
896
  * collide with runtime classes when both are loaded on the same page.
599
897
  *
600
- * Must match `^[a-zA-Z][a-zA-Z0-9_-]{0,31}$`. Locked once styles
898
+ * Must match `^[a-zA-Z_][a-zA-Z0-9_-]{0,31}$`. Locked once styles
601
899
  * have been generated.
602
900
  *
603
901
  * @default 't'
@@ -673,7 +971,7 @@ interface TastyConfig {
673
971
  * @example
674
972
  * ```ts
675
973
  * configure({
676
- * fontFace: {
974
+ * fontFaces: {
677
975
  * 'Brand Sans': [
678
976
  * { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
679
977
  * { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
@@ -683,7 +981,7 @@ interface TastyConfig {
683
981
  * });
684
982
  * ```
685
983
  */
686
- fontFace?: Record<string, FontFaceInput>;
984
+ fontFaces?: Record<string, FontFaceInput>;
687
985
  /**
688
986
  * Global @counter-style definitions.
689
987
  * Keys are counter-style names, values are descriptor objects.
@@ -691,13 +989,32 @@ interface TastyConfig {
691
989
  * @example
692
990
  * ```ts
693
991
  * configure({
694
- * counterStyle: {
992
+ * counterStyles: {
695
993
  * thumbs: { system: 'cyclic', symbols: '"👍"', suffix: '" "' },
696
994
  * },
697
995
  * });
698
996
  * ```
699
997
  */
700
- counterStyle?: Record<string, CounterStyleDescriptors>;
998
+ counterStyles?: Record<string, CounterStyleDescriptors>;
999
+ /**
1000
+ * Opt-in polyfills for not-yet-baseline CSS features. Each key toggles a
1001
+ * feature polyfill; all default to `false`.
1002
+ *
1003
+ * - `functions` — polyfill CSS `@function` by inlining every `$$name(...)`
1004
+ * call into plain CSS (calc/var/color-mix) at parse time instead of
1005
+ * emitting the native `@function` at-rule. Enables `@function` usage in
1006
+ * browsers that don't support it yet (Firefox/Safari). Note this is the
1007
+ * `functions` *feature toggle*, distinct from the top-level `functions`
1008
+ * definitions map.
1009
+ *
1010
+ * @example
1011
+ * ```ts
1012
+ * configure({ polyfills: { functions: true } });
1013
+ * ```
1014
+ */
1015
+ polyfills?: {
1016
+ functions?: boolean;
1017
+ };
701
1018
  /**
702
1019
  * Custom style handlers that transform style properties into CSS declarations.
703
1020
  * Handlers replace built-in handlers for the same style name.
@@ -727,13 +1044,63 @@ interface TastyConfig {
727
1044
  * ```
728
1045
  */
729
1046
  handlers?: Record<string, StyleHandlerDefinition>;
1047
+ /**
1048
+ * Props middleware for every tasty component. A prop handler receives the
1049
+ * component's props and returns them, changed or not — the extension point for
1050
+ * props that are not style properties.
1051
+ *
1052
+ * The map key is the handler's name and, by default, the prop that triggers it.
1053
+ * Use `['*', fn]` for an unconditional handler, or `[['a', 'b'], fn]` to trigger
1054
+ * on any of several props.
1055
+ *
1056
+ * Handlers must be pure and must not mutate their input: style values are cached
1057
+ * by object identity, so mutating one in place yields stale CSS. Memoize the
1058
+ * styles you build per input value.
1059
+ *
1060
+ * Not applicable to zero-runtime mode — `tastyStatic()` takes styles objects, not
1061
+ * props, so there is nothing for middleware to run on. Components rendered
1062
+ * through `tasty()` are unaffected and keep the runtime injector.
1063
+ *
1064
+ * @example
1065
+ * ```ts
1066
+ * configure({
1067
+ * propHandlers: {
1068
+ * glaze: (props) => {
1069
+ * const { glaze, ...rest } = props;
1070
+ * if (!glaze) return rest;
1071
+ * return { ...rest, styles: mergeStyles(glazeStyles(glaze), rest.styles) };
1072
+ * },
1073
+ * },
1074
+ * });
1075
+ *
1076
+ * <Element glaze="purple" />
1077
+ * ```
1078
+ */
1079
+ propHandlers?: Record<string, PropHandlerDefinition>;
1080
+ /**
1081
+ * Style properties exposed as top-level props on **every** tasty component, in
1082
+ * addition to the built-in base styles, without each component listing them in
1083
+ * `styleProps`.
1084
+ *
1085
+ * Augment `TastyBaseStylePropNames` to type them. Each name costs one property
1086
+ * check per render of every component, so keep the list short; the effect is
1087
+ * app-global and cannot be scoped to a subtree.
1088
+ *
1089
+ * @example
1090
+ * ```ts
1091
+ * configure({ baseStyleProps: ['radius', 'shadow'] });
1092
+ *
1093
+ * <Card radius="1r" shadow />
1094
+ * ```
1095
+ */
1096
+ baseStyleProps?: readonly string[];
730
1097
  /**
731
1098
  * Design tokens injected as CSS custom properties on `:root`.
732
1099
  * Values are parsed through the Tasty DSL. Supports state maps
733
1100
  * for responsive/theme-aware tokens.
734
1101
  *
735
1102
  * - `$name` keys become `--name` CSS custom properties
736
- * - `#name` keys become `--name-color` and `--name-color-{colorSpace}` properties
1103
+ * - `#name` keys become `--name-color` properties
737
1104
  *
738
1105
  * Tokens are injected once when the first style is rendered.
739
1106
  *
@@ -782,7 +1149,7 @@ interface TastyConfig {
782
1149
  /**
783
1150
  * Predefined style recipes -- named style bundles that can be applied via `recipe` style property.
784
1151
  * Recipe values are flat tasty styles (no sub-element keys). They may contain base styles,
785
- * tokens (`$name`/`#name` definitions), local states, `@keyframes`, and `@properties`.
1152
+ * tokens (`$name`/`#name` definitions), local states, `@keyframes`, and `@property`.
786
1153
  *
787
1154
  * Components reference recipes via: `recipe: 'name1 name2'` in their styles.
788
1155
  * Use `/` to separate base recipes from post recipes: `recipe: 'base1 base2 / post1'`.
@@ -878,13 +1245,19 @@ declare function getGlobalKeyframes(): Record<string, KeyframesSteps> | null;
878
1245
  * Returns null if no font faces configured.
879
1246
  * Reads from globalThis first for cross-module SSR support.
880
1247
  */
881
- declare function getGlobalFontFace(): Record<string, FontFaceInput> | null;
1248
+ declare function getGlobalFontFaces(): Record<string, FontFaceInput> | null;
882
1249
  /**
883
1250
  * Get global counter-style configuration.
884
1251
  * Returns null if no counter styles configured.
885
1252
  * Reads from globalThis first for cross-module SSR support.
886
1253
  */
887
- declare function getGlobalCounterStyle(): Record<string, CounterStyleDescriptors> | null;
1254
+ declare function getGlobalCounterStyles(): Record<string, CounterStyleDescriptors> | null;
1255
+ /**
1256
+ * Get global @function configuration.
1257
+ * Returns null if no functions configured.
1258
+ * Reads from globalThis first for cross-module SSR support.
1259
+ */
1260
+ declare function getGlobalFunctions(): Record<string, FunctionDefinition> | null;
888
1261
  /**
889
1262
  * Check if any global recipes are configured.
890
1263
  * Fast path: returns false if no recipes were ever set.
@@ -941,5 +1314,5 @@ declare function getNamePrefix(): string;
941
1314
  */
942
1315
  declare function resetConfig(): void;
943
1316
  //#endregion
944
- export { SheetManager as S, TypographyPreset as _, getGlobalFontFace as a, ColorSpace as b, getNamePrefix as c, hasStylesGenerated as d, isConfigLocked as f, TastyPluginFactory as g, TastyPlugin as h, getGlobalCounterStyle as i, hasGlobalKeyframes as l, resetConfig as m, configure as n, getGlobalKeyframes as o, isTestEnvironment as p, getConfig as r, getGlobalRecipes as s, TastyConfig as t, hasGlobalRecipes as u, TypographyTokenValue as v, StyleInjector as x, generateTypographyTokens as y };
945
- //# sourceMappingURL=config-BoZDUHW5.d.ts.map
1317
+ export { ParseFunction as C, PropHandlerDefinition as D, PropHandler as E, PropHandlerProps as O, FunctionsConfig as S, SheetManager as T, TastyPluginFactory as _, getGlobalFontFaces as a, generateTypographyTokens as b, getGlobalRecipes as c, hasGlobalRecipes as d, hasStylesGenerated as f, TastyPlugin as g, resetConfig as h, getGlobalCounterStyles as i, getNamePrefix as l, isTestEnvironment as m, configure as n, getGlobalFunctions as o, isConfigLocked as p, getConfig as r, getGlobalKeyframes as s, TastyConfig as t, hasGlobalKeyframes as u, TypographyPreset as v, StyleInjector as w, ColorSpace as x, TypographyTokenValue as y };
1318
+ //# sourceMappingURL=config-DRp9aYRG.d.ts.map