@tenphi/tasty 0.0.0-snapshot.b2ad8a7 → 0.0.0-snapshot.b317d64

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 (119) hide show
  1. package/README.md +6 -6
  2. package/dist/babel-types-C_7kRP38.d.ts +18 -0
  3. package/dist/chunks/async-storage-CG5HnUT5.js +20 -0
  4. package/dist/chunks/async-storage-CG5HnUT5.js.map +1 -0
  5. package/dist/chunks/build-config-BDLYGmKn.js +60 -0
  6. package/dist/chunks/build-config-BDLYGmKn.js.map +1 -0
  7. package/dist/{collector-DCI2yzwx.js → chunks/collector-DqcB0UUT.js} +25 -119
  8. package/dist/chunks/collector-DqcB0UUT.js.map +1 -0
  9. package/dist/chunks/config-engine-CGIMO2PV.js +272 -0
  10. package/dist/chunks/config-engine-CGIMO2PV.js.map +1 -0
  11. package/dist/chunks/css-definitions-BibU6ZnP.js +904 -0
  12. package/dist/chunks/css-definitions-BibU6ZnP.js.map +1 -0
  13. package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
  14. package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
  15. package/dist/chunks/debug-Dy36S1sU.js +502 -0
  16. package/dist/chunks/debug-Dy36S1sU.js.map +1 -0
  17. package/dist/chunks/dsl-DRhFWQzo.js +1378 -0
  18. package/dist/chunks/dsl-DRhFWQzo.js.map +1 -0
  19. package/dist/chunks/hydration-TRcz5vnk.js +41 -0
  20. package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
  21. package/dist/chunks/react-runtime-BljxMd6C.js +582 -0
  22. package/dist/chunks/react-runtime-BljxMd6C.js.map +1 -0
  23. package/dist/chunks/runtime-engine-CPYI2bA8.js +2415 -0
  24. package/dist/chunks/runtime-engine-CPYI2bA8.js.map +1 -0
  25. package/dist/chunks/runtime-state-C0u1jp-Q.js +141 -0
  26. package/dist/chunks/runtime-state-C0u1jp-Q.js.map +1 -0
  27. package/dist/{merge-styles-CzVxdtav.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
  28. package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
  29. package/dist/chunks/style-engine-D35rvcdB.js +5420 -0
  30. package/dist/chunks/style-engine-D35rvcdB.js.map +1 -0
  31. package/dist/{css-writer-Cq0fg5v8.js → chunks/zero-engine-b--JCZad.js} +51 -146
  32. package/dist/chunks/zero-engine-b--JCZad.js.map +1 -0
  33. package/dist/{collector-CQDeU7WS.d.ts → collector-w4mBj5gd.d.ts} +23 -4
  34. package/dist/{config-CwRr6-fG.d.ts → config-CrZOfNJ5.d.ts} +110 -96
  35. package/dist/core/index.d.ts +5 -5
  36. package/dist/core/index.js +9 -6
  37. package/dist/{index-C0W21Qcb.d.ts → index-CYJtAI9a.d.ts} +243 -281
  38. package/dist/index.d.ts +5 -5
  39. package/dist/index.js +11 -998
  40. package/dist/{merge-styles-Bpwfy1CS.d.ts → merge-styles-VXwJ0Frr.d.ts} +2 -3
  41. package/dist/ssr/astro-client.d.ts +1 -1
  42. package/dist/ssr/astro-client.js +1 -14
  43. package/dist/ssr/astro-client.js.map +1 -1
  44. package/dist/ssr/astro-middleware-extract-static.d.ts +10 -0
  45. package/dist/ssr/astro-middleware-extract-static.js +9 -0
  46. package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
  47. package/dist/ssr/astro-middleware-extract.d.ts +10 -0
  48. package/dist/ssr/astro-middleware-extract.js +9 -0
  49. package/dist/ssr/astro-middleware-extract.js.map +1 -0
  50. package/dist/ssr/astro-middleware-static.d.ts +3 -2
  51. package/dist/ssr/astro-middleware-static.js +0 -11
  52. package/dist/ssr/astro-middleware-static.js.map +1 -1
  53. package/dist/ssr/astro-middleware.d.ts +3 -2
  54. package/dist/ssr/astro-middleware.js +0 -12
  55. package/dist/ssr/astro-middleware.js.map +1 -1
  56. package/dist/ssr/astro.d.ts +40 -6
  57. package/dist/ssr/astro.js +157 -93
  58. package/dist/ssr/astro.js.map +1 -1
  59. package/dist/ssr/index.d.ts +10 -11
  60. package/dist/ssr/index.js +4 -4
  61. package/dist/ssr/index.js.map +1 -1
  62. package/dist/ssr/next-config.d.ts +64 -0
  63. package/dist/ssr/next-config.js +134 -0
  64. package/dist/ssr/next-config.js.map +1 -0
  65. package/dist/ssr/next.d.ts +9 -8
  66. package/dist/ssr/next.js +29 -43
  67. package/dist/ssr/next.js.map +1 -1
  68. package/dist/static/index.d.ts +8 -9
  69. package/dist/static/index.js +4 -22
  70. package/dist/static/index.js.map +1 -1
  71. package/dist/static/inject.d.ts +1 -2
  72. package/dist/{index-DpykQKO8.d.ts → types-JEY8PVYP.d.ts} +986 -972
  73. package/dist/zero/babel.d.ts +67 -2
  74. package/dist/zero/babel.js +57 -131
  75. package/dist/zero/babel.js.map +1 -1
  76. package/dist/zero/index.d.ts +44 -8
  77. package/dist/zero/index.js +24 -2
  78. package/dist/zero/index.js.map +1 -0
  79. package/dist/zero/next.d.ts +4 -5
  80. package/dist/zero/next.js +0 -31
  81. package/dist/zero/next.js.map +1 -1
  82. package/docs/ai-agents.md +31 -5
  83. package/docs/configuration.md +18 -2
  84. package/docs/debug.md +15 -5
  85. package/docs/dsl.md +56 -8
  86. package/docs/getting-started.md +13 -11
  87. package/docs/injector.md +21 -7
  88. package/docs/methodology.md +5 -5
  89. package/docs/pipeline.md +34 -10
  90. package/docs/plugins.md +1 -1
  91. package/docs/react-api.md +9 -0
  92. package/docs/runtime-benchmarks.md +282 -110
  93. package/docs/ssr.md +179 -20
  94. package/docs/styles.md +89 -19
  95. package/docs/tasty-static.md +34 -1
  96. package/package.json +101 -36
  97. package/dist/async-storage-DKK-wTD4.js +0 -44
  98. package/dist/async-storage-DKK-wTD4.js.map +0 -1
  99. package/dist/babel-B_P8t-f0.d.ts +0 -83
  100. package/dist/collector-DCI2yzwx.js.map +0 -1
  101. package/dist/config-B97n_EIv.js +0 -12612
  102. package/dist/config-B97n_EIv.js.map +0 -1
  103. package/dist/context-CA8YKeMn.js +0 -24
  104. package/dist/context-CA8YKeMn.js.map +0 -1
  105. package/dist/core-DWrUWxog.js +0 -1645
  106. package/dist/core-DWrUWxog.js.map +0 -1
  107. package/dist/css-writer-Cq0fg5v8.js.map +0 -1
  108. package/dist/format-global-rules-DklyaXv-.js +0 -22
  109. package/dist/format-global-rules-DklyaXv-.js.map +0 -1
  110. package/dist/format-rules-Wb7dJOoL.js +0 -130
  111. package/dist/format-rules-Wb7dJOoL.js.map +0 -1
  112. package/dist/hydrate-gFTLBDK9.js +0 -37
  113. package/dist/hydrate-gFTLBDK9.js.map +0 -1
  114. package/dist/index.js.map +0 -1
  115. package/dist/merge-styles-CzVxdtav.js.map +0 -1
  116. package/dist/renderChunk-COXABoQz.js +0 -290
  117. package/dist/renderChunk-COXABoQz.js.map +0 -1
  118. package/dist/resolve-recipes-BnrUEjWV.js +0 -144
  119. package/dist/resolve-recipes-BnrUEjWV.js.map +0 -1
@@ -1,745 +1,228 @@
1
1
  import { Properties } from "csstype";
2
-
3
- //#region src/properties/property-type-resolver.d.ts
4
- /**
5
- * PropertyTypeResolver
6
- *
7
- * Automatically infers CSS @property types from custom property values.
8
- * Supports deferred resolution for var() reference chains of arbitrary depth.
9
- */
10
- declare class PropertyTypeResolver {
11
- /** propName → the prop it depends on */
12
- private pendingDeps;
13
- /** propName → list of props waiting on it */
14
- private reverseDeps;
15
- /**
16
- * Scan CSS declarations and auto-register @property for custom properties
17
- * whose types can be inferred from their values.
18
- */
19
- scanDeclarations(declarations: string, isPropertyDefined: (name: string) => boolean, registerProperty: (name: string, syntax: string, initialValue: string) => void): void;
20
- private addDependency;
21
- private resolve;
22
- private isComplexValue;
23
- }
2
+ //#region src/utils/css-types.d.ts
3
+ interface CSSProperties extends Properties<string | number> {}
24
4
  //#endregion
25
- //#region src/injector/batch.d.ts
5
+ //#region src/parser/types.d.ts
26
6
  /**
27
- * Deferred CSSOM writes ("batched injection").
28
- *
29
- * Every `insertRule()` on a live stylesheet invalidates style for the sheet's
30
- * scope, so Blink recalculates style the next time anything reads layout or
31
- * computed style. When components inject during React's render phase and other
32
- * components read layout in the same pass, the two interleave:
33
- *
34
- * inject -> read (forced recalc) -> inject -> read (forced recalc) -> ...
35
- *
36
- * Batching moves every sheet write out from between those reads. Writes are
37
- * queued in FIFO order and drained in one go, so the tree is invalidated once
38
- * per flush instead of once per component.
39
- *
40
- * ## Ordering
41
- *
42
- * A single queue holds *all* writes — component rules, global rules, keyframes,
43
- * `@property`, `@font-face`, `@counter-style`, `@function` and raw CSS. Draining
44
- * it in insertion order keeps the sheet byte-identical to unbatched output,
45
- * which matters because equal-specificity rules resolve by document order.
46
- *
47
- * ## Batch windows — why queuing is safe
48
- *
49
- * Deferring a write past React's layout phase would let a `useLayoutEffect`
50
- * measure an element whose rules are not in the sheet yet, reading the unstyled
51
- * box. `<TastyBatchProvider>` closes that hole by opening a *window* during its
52
- * render and closing it — flushing — in its `useInsertionEffect`, which React
53
- * runs in the mutation phase, before any layout effect:
54
- *
55
- * provider renders -> window OPEN
56
- * children render -> injections queued
57
- * provider insertionEffect -> FLUSH, window CLOSED
58
- * layout effects run -> rules are in the sheet
59
- *
60
- * So in the default (`batchInjection: true`) mode a write is only ever queued
61
- * inside a commit whose flush is already guaranteed by that same commit. Every
62
- * injection outside a window — a deep update the provider did not re-render
63
- * for, a `useLayoutEffect` that injects, an event handler, an async callback —
64
- * is written straight through, exactly as with batching off.
65
- *
66
- * `batchInjection: 'always'` opts out of the gate and queues unconditionally.
67
- * That wins on more commits, at the cost of the measurement hazard above.
68
- *
69
- * ## Flush points (earliest wins)
70
- *
71
- * 1. `<TastyBatchProvider>`'s `useInsertionEffect` — closes the window.
72
- * 2. A microtask — a backstop for a render that was aborted or suspended and
73
- * therefore never reached its insertion effect. An aborted render mounts
74
- * nothing, so nothing can measure what it queued. Microtasks also always
75
- * drain before paint, so styles are never visually missing.
76
- * 3. `flushStyles()` — explicit, and called internally by every injector read
77
- * API (`getCSSText`, `cleanup`, `gc`, `destroy`, ...).
7
+ * A part within a group, representing a slash-separated segment.
8
+ * For example, in `'2px solid #red / 4px'`, there are two parts:
9
+ * - Part 0: `2px solid #red`
10
+ * - Part 1: `4px`
78
11
  */
79
- interface QueuedWrite {
80
- /** Perform the deferred sheet write. */
81
- run: () => void;
82
- /** Set when the owner disposed before the write happened. */
83
- cancelled: boolean;
84
- /** Set once the write has been applied (or skipped as cancelled). */
85
- done: boolean;
12
+ interface StyleDetailsPart {
13
+ mods: string[];
14
+ values: string[];
15
+ colors: string[];
16
+ all: string[];
17
+ output: string;
86
18
  }
87
- /** Whether any write is still waiting to hit a stylesheet. */
88
- declare function hasPendingStyleWrites(): boolean;
89
- /**
90
- * Drain every pending sheet write, in insertion order.
91
- *
92
- * Safe to call when the queue is empty (the common case, so the guard comes
93
- * first) and safe to call re-entrantly: a nested `flushStyles()` is a no-op,
94
- * and work a draining write triggers is written in place by
95
- * `enqueueStyleWrite` rather than queued behind the rest of the batch.
96
- */
97
- declare function flushStyles(): void;
98
19
  /**
99
- * Drop every pending write without applying it. Test helper — production code
100
- * should call `flushStyles()` instead.
20
+ * A group of style details, representing a comma-separated segment.
21
+ * Contains aggregated values from all parts for backward compatibility,
22
+ * plus the structured `parts` array for handlers that need slash separation.
101
23
  */
102
- declare function resetStyleBatch(): void;
103
- //#endregion
104
- //#region src/injector/types.d.ts
105
- declare global {
106
- interface Window {
107
- __TASTY__?: string[];
108
- }
24
+ interface StyleDetails {
25
+ input: string;
26
+ output: string;
27
+ /** Aggregated mods from all parts (backward compatible) */
28
+ mods: string[];
29
+ /** Aggregated values from all parts (backward compatible) */
30
+ values: string[];
31
+ /** Aggregated colors from all parts (backward compatible) */
32
+ colors: string[];
33
+ /** Aggregated all tokens from all parts (backward compatible) */
34
+ all: string[];
35
+ /** Slash-separated parts within this group */
36
+ parts: StyleDetailsPart[];
109
37
  }
110
- interface InjectResult {
111
- className: string;
112
- dispose: () => void;
38
+ interface ProcessedStyle {
39
+ output: string;
40
+ groups: StyleDetails[];
113
41
  }
114
- interface GlobalInjectResult {
115
- dispose: () => void;
42
+ type UnitHandler = (scalar: number) => string;
43
+ interface ParserOptions {
44
+ functions?: Record<string, (parsed: StyleDetails[]) => string>;
45
+ units?: Record<string, string | UnitHandler>;
46
+ cacheSize?: number;
116
47
  }
117
- type DisposeFunction = () => void;
118
- interface StyleInjectorConfig {
119
- nonce?: string;
120
- maxRulesPerSheet?: number;
121
- forceTextInjection?: boolean;
122
- /** Enable development mode features: performance metrics and debug information storage */
123
- devMode?: boolean;
124
- /**
125
- * Global predefined states for advanced state mapping.
126
- * These are state aliases that can be used in any component.
127
- * Example: { '@mobile': '@media(w < 920px)', '@dark': '@root(theme=dark)' }
128
- */
129
- states?: Record<string, string>;
130
- /**
131
- * Automatically infer and register CSS @property declarations
132
- * from custom property values. When false, only explicit @property are used.
133
- * @default true
134
- */
135
- autoPropertyTypes?: boolean;
136
- /** Garbage collection configuration for unused styles */
137
- gc?: GCConfig;
48
+ //#endregion
49
+ //#region src/parser/parser.d.ts
50
+ declare class StyleParser {
51
+ private opts;
52
+ private cache;
53
+ constructor(opts?: ParserOptions);
54
+ process(src: string): ProcessedStyle;
55
+ setFunctions(functions: Required<ParserOptions>['functions']): void;
56
+ setUnits(units: Required<ParserOptions>['units']): void;
57
+ updateOptions(patch: Partial<ParserOptions>): void;
138
58
  /**
139
- * Prefix prepended to every generated identifier.
140
- * Mirrors the `namePrefix` field on the public `TastyConfig` so that
141
- * standalone injector consumers can configure it directly.
142
- * @default 't'
59
+ * Clear the parser cache.
60
+ * Call this when external state that affects parsing results has changed
61
+ * (e.g., predefined tokens).
143
62
  */
144
- namePrefix?: string;
63
+ clearCache(): void;
145
64
  /**
146
- * Defer stylesheet writes and apply them in one batch instead of one
147
- * `insertRule()` per component. Mirrors `batchInjection` on the public
148
- * `TastyConfig`.
149
- * @default false
65
+ * Get the current units configuration.
150
66
  */
151
- batchInjection?: boolean | 'always';
67
+ getUnits(): ParserOptions['units'];
152
68
  }
69
+ //#endregion
70
+ //#region src/utils/styles.d.ts
71
+ type StyleValue<T = string> = T | boolean | number | null | undefined;
153
72
  /**
154
- * Per-className usage tracking for GC.
73
+ * Normalize a color token value.
74
+ * - Boolean `true` is converted to `'transparent'`
75
+ * - Boolean `false` returns `null` (signals the token should be skipped)
76
+ * - Other values are returned as-is
77
+ *
78
+ * @param value - The raw token value
79
+ * @returns Normalized value or null if the token should be skipped
155
80
  */
81
+ declare function normalizeColorTokenValue<T>(value: T | boolean): T | 'transparent' | null;
82
+ type StyleValueStateMap<T = string> = Record<string, StyleValue<T> | '@inherit'>;
156
83
  /**
157
- * The CSS a class name stands for, kept so the class can be re-created.
158
- *
159
- * This is what makes collection safe: a render hands a class name to a
160
- * component before the commit that mounts it, and collection can run in
161
- * between. The component's insertion effect re-inserts from the recipe when it
162
- * finally commits, so deleting a rule early costs a re-insert, never a
163
- * missing style.
84
+ * Combined type for style values that can be either a direct value or a state map.
85
+ * Use this for component props that accept style values.
164
86
  */
165
- interface StyleRecipe {
166
- rules: StyleResult[];
167
- cacheKey?: string;
168
- /**
169
- * `@keyframes` these rules animate, by the name they were authored under.
170
- *
171
- * Kept here rather than injected during render for the same reason as the
172
- * rules themselves: a render that is discarded must leave nothing behind.
173
- * They are injected when the class is, and disposed when it is deleted —
174
- * the injected name can differ from the authored one, so the animation
175
- * declarations are rewritten at that point.
176
- */
177
- keyframes?: Record<string, KeyframesSteps>;
178
- }
87
+ type StylePropValue<T = string> = StyleValue<T> | StyleValueStateMap<T>;
179
88
  /**
180
- * Configuration for the style garbage collector.
181
- *
182
- * Collection is driven by React commits, not by timers or DOM scans: a styled
183
- * component acquires its classes in `useInsertionEffect` and releases them when
184
- * it unmounts. Every `releaseInterval` releases, a pass is scheduled to delete
185
- * whatever is still at zero, keeping the `capacity` most recently released.
89
+ * One dependency value as a style handler receives it: already resolved for a
90
+ * single state, but still the **raw authored DSL string** (`'2x'`, `'#purple.5'`).
91
+ * Handlers parse it themselves via {@link parseStyle} / {@link parseColor}.
186
92
  */
187
- interface GCConfig {
188
- /**
189
- * Number of releases between automatic collection passes. A component
190
- * unmounting releases one entry per chunk it carried.
191
- * @default 1000
192
- */
193
- releaseInterval?: number;
194
- /**
195
- * Maximum number of collectible styles to retain. Collection evicts the
196
- * least recently released first once this is exceeded. Mounted styles and
197
- * pinned styles do not count against it.
198
- * @default 1000
199
- */
200
- capacity?: number;
201
- }
93
+ type ResolvedStyleValue = StyleValue<string>;
202
94
  /**
203
- * Per-call options for inject().
95
+ * The dependency map a handler receives — one resolved value per style name in
96
+ * its `__lookupStyles`.
204
97
  */
205
- interface InjectOptions {
206
- root?: Document | ShadowRoot;
207
- /** Reuse the class already injected for this key instead of writing again. */
208
- cacheKey?: string;
209
- /**
210
- * Pin the injected class (default `true`). A pinned class is never evicted by
211
- * `gc()`, and the returned `dispose()` releases the pin. Pass `false` when the
212
- * caller keeps no handle and the DOM is the only record that the class is in
213
- * use — the render path does this, because a hook-free render has no unmount
214
- * signal to dispose on.
215
- */
216
- pin?: boolean;
217
- }
98
+ type StyleHandlerProps<TDeps extends string = string> = Partial<Record<TDeps, ResolvedStyleValue>>;
218
99
  /**
219
- * Per-call options for gc().
100
+ * One set of CSS declarations returned by a style handler.
101
+ *
102
+ * Keys are **kebab-case** CSS property names (`'background-color'`, not
103
+ * `backgroundColor`) or `--custom-property` names. Values are stringified, so
104
+ * numbers are accepted. `$` is reserved as a selector suffix.
220
105
  */
221
- interface GCOptions {
222
- root?: Document | ShadowRoot;
223
- /** Bypass capacity threshold and remove ALL unused styles. */
224
- force?: boolean;
225
- }
226
- interface RuleInfo {
227
- className: string;
228
- ruleIndex: number;
229
- sheetIndex: number;
230
- /** Dev-only: full CSS texts inserted for this class; omitted in production */
231
- cssText?: string[];
232
- /** Inclusive end index of the contiguous block of inserted rules for this className */
233
- endRuleIndex?: number;
234
- /** NEW: exact indices of all inserted rules for this className */
235
- indices?: number[];
236
- }
237
- type InjectionMode = 'style-element' | 'adopted';
238
- interface SheetInfo {
239
- /** HTMLStyleElement used in style-element mode; null in adopted mode. */
240
- sheet: HTMLStyleElement | null;
241
- /** Constructable CSSStyleSheet used in adopted mode (ShadowRoot targets) */
242
- constructableSheet?: CSSStyleSheet;
243
- ruleCount: number;
244
- holes: number[];
245
- /**
246
- * True when this sheet is written through `textContent` instead of CSSOM.
247
- * Decided once at sheet creation so a sheet is never half CSSOM / half text.
248
- */
249
- textMode?: boolean;
250
- /**
251
- * Inserted rule texts in rule-index order. Maintained only in text mode —
252
- * it is what makes deletion possible there, since `textContent` cannot be
253
- * edited rule-by-rule and has to be rebuilt.
254
- */
255
- textRules?: string[];
256
- }
257
- interface CleanupStats {
258
- timestamp: number;
259
- classesDeleted: number;
260
- cssSize: number;
261
- rulesDeleted: number;
262
- }
263
- interface CacheMetrics {
264
- hits: number;
265
- misses: number;
266
- bulkCleanups: number;
267
- totalInsertions: number;
268
- totalUnused: number;
269
- stylesCleanedUp: number;
270
- cleanupHistory: CleanupStats[];
271
- startTime: number;
272
- unusedHits?: number;
273
- }
274
- interface RootRegistry {
275
- sheets: SheetInfo[];
276
- /** className -> outstanding `inject()` references; 0 means nobody holds a handle */
277
- pinCounts: Map<string, number>;
278
- rules: Map<string, RuleInfo>;
279
- /** Cache key to className mapping to avoid dual storage of RuleInfo objects */
280
- cacheKeyToClassName: Map<string, string>;
281
- /** Deduplication set of fully materialized CSS rules inserted into sheets */
282
- ruleTextSet: Set<string>;
283
- /** Performance metrics (optional) */
284
- metrics?: CacheMetrics;
285
- /** Keyframes cache by content hash -> entry */
286
- keyframesCache: Map<string, KeyframesCacheEntry>;
287
- /** Keyframes name to content hash mapping for collision detection */
288
- keyframesNameToContent: Map<string, string>;
289
- /** Counter for generating keyframes names like k0, k1, k2... */
290
- keyframesCounter: number;
291
- /** Map of injected @property names to their normalized declarations for tracking */
292
- injectedProperties: Map<string, string>;
293
- /** Content hashes of injected @font-face rules for deduplication */
294
- injectedFontFaces: Set<string>;
295
- /**
296
- * Injected @counter-style rules. Maps the name to whether it was injected
297
- * "strong" (`true`, the default — overrides) or "weak" (`false`, global
298
- * `configure()` definitions that never clobber an existing rule).
299
- */
300
- injectedCounterStyles: Map<string, boolean>;
301
- /**
302
- * Injected @function rules. Maps the CSS function name to whether it was
303
- * injected "strong" (`true`, the default — overrides) or "weak" (`false`,
304
- * global `configure()` definitions that never clobber an existing rule).
305
- */
306
- injectedFunctions: Map<string, boolean>;
307
- /** Global rules tracking for index adjustment */
308
- globalRules: Map<string, RuleInfo>;
309
- /** Resolver for auto-inferring @property types from declaration values */
310
- propertyTypeResolver: PropertyTypeResolver;
311
- /** className -> how many mounted components hold it (0 means collectible) */
312
- committed: Map<string, number>;
313
- /** className -> disposers for the @keyframes its rules animate */
314
- keyframeHandles: Map<string, (() => void)[]>;
315
- /** className -> when it last dropped to zero, for least-recently-released order */
316
- candidates: Map<string, number>;
317
- /** How many entries from `window.__TASTY__` have been synced into this registry */
318
- serverClassSyncIndex: number;
319
- /** Whether `<style data-tasty-rsc>` tags have been scanned for class names */
320
- rscStylesScanned: boolean;
321
- /** Whether this root uses adoptedStyleSheets or <style> elements */
322
- injectionMode: InjectionMode;
323
- /**
324
- * Lazy feature-test for `@property` support, cached per registry.
325
- * - `undefined`: not yet probed.
326
- * - `true`: engine supports `@property`; rejections indicate user-authored
327
- * invalid rules and should warn.
328
- * - `false`: engine doesn't support `@property` (e.g., jsdom); rejections
329
- * are expected and warnings are suppressed.
330
- */
331
- atPropertySupported?: boolean;
332
- }
333
- type StyleRule = StyleResult;
334
- interface KeyframesInfo {
335
- name: string;
336
- sheetIndex: number;
337
- ruleIndex: number;
338
- /** Dev-only: full CSS text of the @keyframes rule; omitted in production */
339
- cssText?: string;
340
- }
341
- type KeyframeStep = string | Record<string, string | number>;
342
- type KeyframesSteps = Record<string, KeyframeStep>;
343
- interface KeyframesResult {
344
- toString(): string;
345
- dispose: () => void;
346
- }
347
- interface KeyframesCacheEntry {
348
- name: string;
349
- refCount: number;
350
- info: KeyframesInfo;
351
- /**
352
- * Queued sheet write, when `batchInjection` deferred the insertion. Present
353
- * only between `keyframes()` and the flush; disposing in that window cancels
354
- * the write instead of deleting a rule that was never inserted.
355
- */
356
- pending?: QueuedWrite;
357
- }
106
+ type CSSMap = {
107
+ /** Selector suffix (or suffixes) these declarations apply to, e.g. `'& > *'`. */
108
+ $?: string | string[];
109
+ } & Record<string, string | number | (string | number)[] | undefined>;
110
+ type StyleHandlerResult = CSSMap | CSSMap[] | null | void;
111
+ type RawStyleHandler<TProps extends object = StyleHandlerProps> = (props: TProps) => StyleHandlerResult;
112
+ type StyleHandler<TProps extends object = StyleHandlerProps> = RawStyleHandler<TProps> & {
113
+ __lookupStyles: string[];
114
+ };
358
115
  /**
359
- * Definition for a CSS @property at-rule.
360
- * Used to define custom property syntax, inheritance, and initial value.
116
+ * The handler type used by the registry (`STYLE_HANDLER_MAP`), with parameter
117
+ * variance erased.
118
+ *
119
+ * Handlers declare narrow, hand-written dependency types — `({ fill }: { fill?:
120
+ * string }) => …` — which under `strictFunctionTypes` are not assignable to a
121
+ * wider parameter type. The registry stores handlers of many different dependency
122
+ * shapes together, so it needs the erased form. Prefer {@link StyleHandler} (or
123
+ * {@link defineHandler}) when writing a handler; this type is for code that
124
+ * inspects the registry.
361
125
  */
362
- interface PropertyDefinition {
363
- /** CSS syntax string (e.g., '<color>', '<angle>', '<number>') */
364
- syntax?: string;
365
- /** Whether the property inherits (default: true) */
366
- inherits?: boolean;
367
- /** Initial value for the property */
368
- initialValue?: string | number;
369
- }
126
+ type AnyStyleHandler = ((props: any) => StyleHandlerResult) & {
127
+ __lookupStyles: string[];
128
+ };
370
129
  /**
371
- * Options for registering a CSS `@property`.
372
- * Extends {@link PropertyDefinition} with an optional injection root.
130
+ * Handler definition forms for configure() and plugins.
131
+ * - Function only: lookup styles inferred from key name
132
+ * - Single property tuple: ['styleName', handler]
133
+ * - Multi-property tuple: [['style1', 'style2'], handler]
134
+ *
135
+ * Use {@link defineHandler} to have the dependency names inferred into the
136
+ * handler's parameter type instead of annotating it by hand.
373
137
  */
374
- interface PropertyOptions extends PropertyDefinition {
375
- /** Shadow root or document to inject into */
376
- root?: Document | ShadowRoot;
138
+ type StyleHandlerDefinition<TDeps extends string = string> = RawStyleHandler<StyleHandlerProps<TDeps>> | [TDeps, RawStyleHandler<StyleHandlerProps<TDeps>>] | [readonly TDeps[], RawStyleHandler<StyleHandlerProps<TDeps>>];
139
+ interface ParsedColor {
140
+ color?: string;
141
+ name?: string;
142
+ opacity?: number;
377
143
  }
144
+ type StyleMap = Record<string, StyleValue | StyleValueStateMap>;
145
+ declare const CUSTOM_UNITS: {
146
+ r: string;
147
+ cr: string;
148
+ bw: string;
149
+ ow: string;
150
+ x: string;
151
+ sf: (num: number) => string;
152
+ };
153
+ declare const DIRECTIONS: string[];
154
+ /**
155
+ * Get the global StyleParser instance.
156
+ * Used by configure() to apply parser configuration.
157
+ */
158
+ declare function getGlobalParser(): StyleParser;
159
+ /**
160
+ * Get the current global predefined tokens.
161
+ * Returns null if no tokens are configured.
162
+ */
163
+ declare function getGlobalPredefinedTokens(): Record<string, string> | null;
378
164
  /**
379
- * A single parameter for a CSS @function at-rule.
380
165
  *
381
- * - `true` — a bare parameter with no type or default.
382
- * - `string` — a CSS type shorthand (e.g. `'<length>'`, `'<color>'`).
383
- * - object — full form with optional `syntax` (type) and `default` value.
166
+ * @param {String} value
167
+ * @param {Number} mode
168
+ * @returns {Object<String,String|Array>}
384
169
  */
385
- type FunctionParameter = true | string | {
386
- syntax?: string;
387
- default?: string | number;
388
- };
170
+ declare function parseStyle(value: StyleValue): ProcessedStyle;
389
171
  /**
390
- * Definition for a CSS @function at-rule (custom function).
172
+ * Parse color. Find it value, name and opacity.
173
+ * Optimized to avoid heavy parseStyle calls for simple color patterns.
174
+ */
175
+ declare function parseColor(val: string, ignoreError?: boolean): ParsedColor;
176
+ declare function filterMods(mods: string[], allowedMods: readonly string[]): string[];
177
+ declare function stringifyStyles(styles: unknown): string;
178
+ //#endregion
179
+ //#region src/styles/types.d.ts
180
+ /**
181
+ * Extensible interface for named color tokens.
182
+ * Augment this interface to register project-specific color names
183
+ * for autocomplete in `fill`, `color`, `svgFill`, and other color style props.
391
184
  *
392
- * The descriptor body reads like a mini styles object: any `$name` key declares
393
- * a local variable (`--name`) whose value is parsed through the Tasty DSL.
394
- * `result` is the only required field.
185
+ * @example
186
+ * ```typescript
187
+ * declare module '@tenphi/tasty' {
188
+ * interface TastyNamedColors {
189
+ * primary: true;
190
+ * danger: true;
191
+ * }
192
+ * }
193
+ * ```
194
+ */
195
+ interface TastyNamedColors {}
196
+ type NamedColorKey = Extract<keyof TastyNamedColors, string>;
197
+ type NamedColor = [NamedColorKey] extends [never] ? string : NamedColorKey;
198
+ /**
199
+ * Extensible interface for typography preset names.
200
+ * Augment this interface to register project-specific preset names for autocomplete.
395
201
  *
396
202
  * @example
397
- * ```ts
398
- * // @function --negative(--value) { result: calc(-1 * var(--value)); }
399
- * { args: ['$value'], result: '(-1 * $value)' }
203
+ * ```typescript
204
+ * declare module '@tenphi/tasty' {
205
+ * interface TastyPresetNames {
206
+ * h1: true;
207
+ * t3: true;
208
+ * }
209
+ * }
400
210
  * ```
401
211
  */
402
- interface FunctionDefinition {
212
+ interface TastyPresetNames {}
213
+ type PresetNameKey = Extract<keyof TastyPresetNames, string>;
214
+ type PresetName = [PresetNameKey] extends [never] ? string : PresetNameKey;
215
+ type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
216
+ type OpaquePercentage = '' | `.${Digit}` | `.${Digit}${Digit}` | '.100';
217
+ type ColorValue = `#${NamedColor}${OpaquePercentage}` | `rgb(${string})` | `hsl(${string})` | `okhsl(${string})` | `oklch(${string})` | (string & {});
218
+ type NoType = false | null | undefined;
219
+ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font' | 'outline' | 'type' | 'gap' | 'padding' | 'margin' | 'width' | 'height' | 'blockSize' | 'inlineSize' | 'border' | 'transition' | 'placeContent' | 'placeItems' | 'scrollMargin' | 'scrollMarginTop' | 'scrollMarginRight' | 'scrollMarginBottom' | 'scrollMarginLeft' | 'scrollPadding' | 'scrollPaddingTop' | 'scrollPaddingRight' | 'scrollPaddingBottom' | 'scrollPaddingLeft' | 'overscrollBehaviorBlock' | 'overscrollBehaviorInline' | 'overscrollBehaviorX' | 'overscrollBehaviorY'> {
220
+ overscrollBehaviorBlock?: CSSProperties['overscrollBehaviorBlock'] | 'chain';
221
+ overscrollBehaviorInline?: CSSProperties['overscrollBehaviorInline'] | 'chain';
222
+ overscrollBehaviorX?: CSSProperties['overscrollBehaviorX'] | 'chain';
223
+ overscrollBehaviorY?: CSSProperties['overscrollBehaviorY'] | 'chain';
403
224
  /**
404
- * Ordered parameters. Array form lists bare parameter names (`['$value']`);
405
- * object form maps each parameter name to its type/default.
406
- */
407
- args?: string[] | Record<string, FunctionParameter>;
408
- /** Optional return type, e.g. `'<color>'`. */
409
- returns?: string;
410
- /** The `result:` descriptor value (parsed through the Tasty DSL). Required. */
411
- result: string;
412
- /** Local variables: any `$name` key declares `--name` in the body. */
413
- [localVar: `$${string}`]: string | number | undefined;
414
- }
415
- /**
416
- * Descriptors for a CSS @font-face at-rule.
417
- */
418
- interface FontFaceDescriptors {
419
- /** Required. URL(s) to the font file(s). */
420
- src: string;
421
- /** Font weight or range. Default: 'normal'. */
422
- fontWeight?: string | number;
423
- /** Font style. Default: 'normal'. */
424
- fontStyle?: 'normal' | 'italic' | 'oblique' | (string & {});
425
- /** Font stretch. Default: 'normal'. */
426
- fontStretch?: string;
427
- /** Loading behavior. Default: 'auto'. */
428
- fontDisplay?: 'auto' | 'block' | 'swap' | 'fallback' | 'optional';
429
- /** Unicode range to cover. */
430
- unicodeRange?: string;
431
- /** Ascent metric override. */
432
- ascentOverride?: string;
433
- /** Descent metric override. */
434
- descentOverride?: string;
435
- /** Line gap metric override. */
436
- lineGapOverride?: string;
437
- /** Size adjustment factor. */
438
- sizeAdjust?: string;
439
- /** OpenType feature settings. */
440
- fontFeatureSettings?: string;
441
- /** Font variation axis settings. */
442
- fontVariationSettings?: string;
443
- }
444
- /** Single descriptor or array of descriptors for multiple weights/styles. */
445
- type FontFaceInput = FontFaceDescriptors | FontFaceDescriptors[];
446
- /**
447
- * Descriptors for a CSS @counter-style at-rule.
448
- */
449
- interface CounterStyleDescriptors {
450
- /** Required. Numbering algorithm. */
451
- system: 'cyclic' | 'numeric' | 'alphabetic' | 'symbolic' | 'additive' | 'fixed' | (string & {});
452
- /** Symbols for non-additive systems. */
453
- symbols?: string;
454
- /** Symbol-value pairs for additive system. */
455
- additiveSymbols?: string;
456
- /** String prepended to the marker. Default: "". */
457
- prefix?: string;
458
- /** String appended to the marker. Default: ". ". */
459
- suffix?: string;
460
- /** Negative-value wrapping (e.g., '"(" ")"'). */
461
- negative?: string;
462
- /** Counter range (e.g., 'infinite infinite'). */
463
- range?: string;
464
- /** Minimum marker width and pad symbol (e.g., '3 "0"'). */
465
- pad?: string;
466
- /** Fallback counter style name. */
467
- fallback?: string;
468
- /** Speech synthesis hint. */
469
- speakAs?: string;
470
- }
471
- interface RawCSSResult {
472
- dispose: () => void;
473
- }
474
- //#endregion
475
- //#region src/utils/css-types.d.ts
476
- interface CSSProperties extends Properties<string | number> {}
477
- //#endregion
478
- //#region src/parser/types.d.ts
479
- /**
480
- * A part within a group, representing a slash-separated segment.
481
- * For example, in `'2px solid #red / 4px'`, there are two parts:
482
- * - Part 0: `2px solid #red`
483
- * - Part 1: `4px`
484
- */
485
- interface StyleDetailsPart {
486
- mods: string[];
487
- values: string[];
488
- colors: string[];
489
- all: string[];
490
- output: string;
491
- }
492
- /**
493
- * A group of style details, representing a comma-separated segment.
494
- * Contains aggregated values from all parts for backward compatibility,
495
- * plus the structured `parts` array for handlers that need slash separation.
496
- */
497
- interface StyleDetails {
498
- input: string;
499
- output: string;
500
- /** Aggregated mods from all parts (backward compatible) */
501
- mods: string[];
502
- /** Aggregated values from all parts (backward compatible) */
503
- values: string[];
504
- /** Aggregated colors from all parts (backward compatible) */
505
- colors: string[];
506
- /** Aggregated all tokens from all parts (backward compatible) */
507
- all: string[];
508
- /** Slash-separated parts within this group */
509
- parts: StyleDetailsPart[];
510
- }
511
- interface ProcessedStyle {
512
- output: string;
513
- groups: StyleDetails[];
514
- }
515
- type UnitHandler = (scalar: number) => string;
516
- interface ParserOptions {
517
- functions?: Record<string, (parsed: StyleDetails[]) => string>;
518
- units?: Record<string, string | UnitHandler>;
519
- cacheSize?: number;
520
- }
521
- //#endregion
522
- //#region src/parser/parser.d.ts
523
- declare class StyleParser {
524
- private opts;
525
- private cache;
526
- constructor(opts?: ParserOptions);
527
- process(src: string): ProcessedStyle;
528
- setFunctions(functions: Required<ParserOptions>['functions']): void;
529
- setUnits(units: Required<ParserOptions>['units']): void;
530
- updateOptions(patch: Partial<ParserOptions>): void;
531
- /**
532
- * Clear the parser cache.
533
- * Call this when external state that affects parsing results has changed
534
- * (e.g., predefined tokens).
535
- */
536
- clearCache(): void;
537
- /**
538
- * Get the current units configuration.
539
- */
540
- getUnits(): ParserOptions['units'];
541
- }
542
- //#endregion
543
- //#region src/utils/color-math.d.ts
544
- /**
545
- * Consolidated color conversion math.
546
- *
547
- * Single source of truth for all color space conversions used across the
548
- * library: sRGB gamma, HSL, OKLab, OKLCH, OKHSL, hex parsing, named
549
- * colors, and CSS string converters.
550
- *
551
- * This module has zero internal imports — it is a leaf dependency.
552
- *
553
- * Reference: https://bottosson.github.io/posts/oklab/
554
- */
555
- type Vec3 = [number, number, number];
556
- /**
557
- * sRGB gamma to linear. Only the sRGB-to-OKLab direction needs it, so this is
558
- * test-only for the same reason as {@link srgbToOkhsl} — the forward path goes
559
- * through {@link srgbLinearToGamma} instead.
560
- */
561
- /**
562
- * HSL to RGB.
563
- * Algorithm from CSS Color 4 spec.
564
- *
565
- * @param h - Hue in degrees (0-360)
566
- * @param s - Saturation (0-1)
567
- * @param l - Lightness (0-1)
568
- * @returns RGB values in 0-255 range (may have fractional values)
569
- */
570
- declare function hslToRgbValues(h: number, s: number, l: number): Vec3;
571
- declare function getNamedColorHex(): Map<string, string>;
572
- /**
573
- * Convert hex color string to `rgb()` CSS string.
574
- * Supports 3, 4, 6, and 8 character hex values (with or without `#`).
575
- */
576
- declare function hexToRgb(hex: string): string | null;
577
- /**
578
- * Extract RGB values from an `rgb()`/`rgba()` string.
579
- * Supports comma-separated, space-separated, fractional, percentage,
580
- * and slash alpha notation.
581
- *
582
- * @returns Array of RGB values (0-255 range), converting percentages as needed.
583
- */
584
- declare function getRgbValuesFromRgbaString(str: string): number[];
585
- /**
586
- * Convert any recognized color string to an `rgb()` CSS string.
587
- * Handles hex, `okhsl()`, `okhst()`, `hsl()`/`hsla()`, named CSS colors,
588
- * and `rgb()`/`rgba()` pass-through.
589
- */
590
- declare function strToRgb(color: string, _ignoreAlpha?: boolean): string | null | undefined;
591
- //#endregion
592
- //#region src/utils/styles.d.ts
593
- type StyleValue<T = string> = T | boolean | number | null | undefined;
594
- /**
595
- * Normalize a color token value.
596
- * - Boolean `true` is converted to `'transparent'`
597
- * - Boolean `false` returns `null` (signals the token should be skipped)
598
- * - Other values are returned as-is
599
- *
600
- * @param value - The raw token value
601
- * @returns Normalized value or null if the token should be skipped
602
- */
603
- declare function normalizeColorTokenValue<T>(value: T | boolean): T | 'transparent' | null;
604
- type StyleValueStateMap<T = string> = Record<string, StyleValue<T> | '@inherit'>;
605
- /**
606
- * Combined type for style values that can be either a direct value or a state map.
607
- * Use this for component props that accept style values.
608
- */
609
- type StylePropValue<T = string> = StyleValue<T> | StyleValueStateMap<T>;
610
- /**
611
- * One dependency value as a style handler receives it: already resolved for a
612
- * single state, but still the **raw authored DSL string** (`'2x'`, `'#purple.5'`).
613
- * Handlers parse it themselves via {@link parseStyle} / {@link parseColor}.
614
- */
615
- type ResolvedStyleValue = StyleValue<string>;
616
- /**
617
- * The dependency map a handler receives — one resolved value per style name in
618
- * its `__lookupStyles`.
619
- */
620
- type StyleHandlerProps<TDeps extends string = string> = Partial<Record<TDeps, ResolvedStyleValue>>;
621
- /**
622
- * One set of CSS declarations returned by a style handler.
623
- *
624
- * Keys are **kebab-case** CSS property names (`'background-color'`, not
625
- * `backgroundColor`) or `--custom-property` names. Values are stringified, so
626
- * numbers are accepted. `$` is reserved as a selector suffix.
627
- */
628
- type CSSMap = {
629
- /** Selector suffix (or suffixes) these declarations apply to, e.g. `'& > *'`. */$?: string | string[];
630
- } & Record<string, string | number | (string | number)[] | undefined>;
631
- type StyleHandlerResult = CSSMap | CSSMap[] | null | void;
632
- type RawStyleHandler<TProps extends object = StyleHandlerProps> = (props: TProps) => StyleHandlerResult;
633
- type StyleHandler<TProps extends object = StyleHandlerProps> = RawStyleHandler<TProps> & {
634
- __lookupStyles: string[];
635
- };
636
- /**
637
- * The handler type used by the registry (`STYLE_HANDLER_MAP`), with parameter
638
- * variance erased.
639
- *
640
- * Handlers declare narrow, hand-written dependency types — `({ fill }: { fill?:
641
- * string }) => …` — which under `strictFunctionTypes` are not assignable to a
642
- * wider parameter type. The registry stores handlers of many different dependency
643
- * shapes together, so it needs the erased form. Prefer {@link StyleHandler} (or
644
- * {@link defineHandler}) when writing a handler; this type is for code that
645
- * inspects the registry.
646
- */
647
- type AnyStyleHandler = ((props: any) => StyleHandlerResult) & {
648
- __lookupStyles: string[];
649
- };
650
- /**
651
- * Handler definition forms for configure() and plugins.
652
- * - Function only: lookup styles inferred from key name
653
- * - Single property tuple: ['styleName', handler]
654
- * - Multi-property tuple: [['style1', 'style2'], handler]
655
- *
656
- * Use {@link defineHandler} to have the dependency names inferred into the
657
- * handler's parameter type instead of annotating it by hand.
658
- */
659
- type StyleHandlerDefinition<TDeps extends string = string> = RawStyleHandler<StyleHandlerProps<TDeps>> | [TDeps, RawStyleHandler<StyleHandlerProps<TDeps>>] | [readonly TDeps[], RawStyleHandler<StyleHandlerProps<TDeps>>];
660
- interface ParsedColor {
661
- color?: string;
662
- name?: string;
663
- opacity?: number;
664
- }
665
- type StyleMap = Record<string, StyleValue | StyleValueStateMap>;
666
- declare const CUSTOM_UNITS: {
667
- r: string;
668
- cr: string;
669
- bw: string;
670
- ow: string;
671
- x: string;
672
- sf: (num: number) => string;
673
- };
674
- declare const DIRECTIONS: string[];
675
- /**
676
- * Get the global StyleParser instance.
677
- * Used by configure() to apply parser configuration.
678
- */
679
- declare function getGlobalParser(): StyleParser;
680
- /**
681
- * Get the current global predefined tokens.
682
- * Returns null if no tokens are configured.
683
- */
684
- declare function getGlobalPredefinedTokens(): Record<string, string> | null;
685
- /**
686
- *
687
- * @param {String} value
688
- * @param {Number} mode
689
- * @returns {Object<String,String|Array>}
690
- */
691
- declare function parseStyle(value: StyleValue): ProcessedStyle;
692
- /**
693
- * Parse color. Find it value, name and opacity.
694
- * Optimized to avoid heavy parseStyle calls for simple color patterns.
695
- */
696
- declare function parseColor(val: string, ignoreError?: boolean): ParsedColor;
697
- declare function filterMods(mods: string[], allowedMods: string[]): string[];
698
- declare function stringifyStyles(styles: unknown): string;
699
- //#endregion
700
- //#region src/styles/types.d.ts
701
- /**
702
- * Extensible interface for named color tokens.
703
- * Augment this interface to register project-specific color names
704
- * for autocomplete in `fill`, `color`, `svgFill`, and other color style props.
705
- *
706
- * @example
707
- * ```typescript
708
- * declare module '@tenphi/tasty' {
709
- * interface TastyNamedColors {
710
- * primary: true;
711
- * danger: true;
712
- * }
713
- * }
714
- * ```
715
- */
716
- interface TastyNamedColors {}
717
- type NamedColorKey = Extract<keyof TastyNamedColors, string>;
718
- type NamedColor = [NamedColorKey] extends [never] ? string : NamedColorKey;
719
- /**
720
- * Extensible interface for typography preset names.
721
- * Augment this interface to register project-specific preset names for autocomplete.
722
- *
723
- * @example
724
- * ```typescript
725
- * declare module '@tenphi/tasty' {
726
- * interface TastyPresetNames {
727
- * h1: true;
728
- * t3: true;
729
- * }
730
- * }
731
- * ```
732
- */
733
- interface TastyPresetNames {}
734
- type PresetNameKey = Extract<keyof TastyPresetNames, string>;
735
- type PresetName = [PresetNameKey] extends [never] ? string : PresetNameKey;
736
- type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
737
- type OpaquePercentage = '' | `.${Digit}` | `.${Digit}${Digit}` | '.100';
738
- type ColorValue = `#${NamedColor}${OpaquePercentage}` | `rgb(${string})` | `hsl(${string})` | `okhsl(${string})` | `oklch(${string})` | (string & {});
739
- type NoType = false | null | undefined;
740
- interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font' | 'outline' | 'type' | 'gap' | 'padding' | 'margin' | 'width' | 'height' | 'border' | 'transition' | 'placeContent' | 'placeItems' | 'scrollMargin' | 'scrollMarginTop' | 'scrollMarginRight' | 'scrollMarginBottom' | 'scrollMarginLeft' | 'scrollMarginBlock' | 'scrollMarginInline'> {
741
- /**
742
- * @deprecated Use `flow` style instead.
225
+ * @deprecated Use `flow` style instead.
743
226
  */
744
227
  flexDirection: CSSProperties['flexDirection'];
745
228
  /**
@@ -889,6 +372,10 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
889
372
  * - `padding={true}` // default padding on all sides
890
373
  */
891
374
  padding?: CSSProperties['padding'] | string | boolean;
375
+ /** Logical block-axis padding with `start`/`end` modifiers. */
376
+ blockPadding?: CSSProperties['paddingBlock'] | string | boolean;
377
+ /** Logical inline-axis padding with `start`/`end` modifiers. */
378
+ inlinePadding?: CSSProperties['paddingInline'] | string | boolean;
892
379
  /**
893
380
  * Shorthand for element margin. Supports custom units, directional modifiers, and design-system-driven defaults.
894
381
  *
@@ -903,6 +390,10 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
903
390
  * - `margin={true}` // default margin on all sides
904
391
  */
905
392
  margin?: CSSProperties['margin'] | string | boolean;
393
+ /** Logical block-axis margin with `start`/`end` modifiers. */
394
+ blockMargin?: CSSProperties['marginBlock'] | string | boolean;
395
+ /** Logical inline-axis margin with `start`/`end` modifiers. */
396
+ inlineMargin?: CSSProperties['marginInline'] | string | boolean;
906
397
  /**
907
398
  * Concise shorthand for setting element width, including min-width and max-width. Supports custom units and advanced sizing keywords.
908
399
  *
@@ -934,6 +425,16 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
934
425
  * - `height={true}` // height: auto
935
426
  */
936
427
  height?: CSSProperties['height'] | string | boolean;
428
+ /**
429
+ * Logical block size with the same enhanced min/max/fixed syntax as `width`.
430
+ * Emits native `block-size`, `min-block-size`, and `max-block-size` declarations.
431
+ */
432
+ blockSize?: CSSProperties['blockSize'] | string | boolean;
433
+ /**
434
+ * Logical inline size with the same enhanced min/max/fixed syntax as `width`.
435
+ * Emits native `inline-size`, `min-inline-size`, and `max-inline-size` declarations.
436
+ */
437
+ inlineSize?: CSSProperties['inlineSize'] | string | boolean;
937
438
  /**
938
439
  * Shorthand for border width, style, and color. Supports directional modifiers and design-system defaults.
939
440
  *
@@ -955,6 +456,10 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
955
456
  * custom property directly, name it `$name-color`.
956
457
  */
957
458
  border?: CSSProperties['border'] | string | boolean;
459
+ /** Logical block-axis border with `start`/`end` modifiers. */
460
+ blockBorder?: CSSProperties['borderBlock'] | string | boolean;
461
+ /** Logical inline-axis border with `start`/`end` modifiers. */
462
+ inlineBorder?: CSSProperties['borderInline'] | string | boolean;
958
463
  /**
959
464
  * Powerful shorthand for CSS transitions using semantic names and design tokens. Supports grouped transitions for common UI effects.
960
465
  *
@@ -962,10 +467,10 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
962
467
  * Multiple transitions: separated by commas
963
468
  *
964
469
  * Examples:
965
- * - `transition="fill 0.2s, radius 0.3s"` // transitions background-color and border-radius
966
- * - `transition="fade 0.15s ease-in"` // transitions mask with easing
967
- * - `transition="theme 0.3s"` // transitions all theme-related properties
968
- * - `transition="preset 0.2s"` // transitions typography properties
470
+ * - `transition="fill, radius"` // transitions background-color and border-radius
471
+ * - `transition="fade $transition ease-in"` // transitions mask with explicit timing token
472
+ * - `transition="theme"` // transitions all theme-related properties
473
+ * - `transition="preset"` // transitions typography properties
969
474
  */
970
475
  transition?: CSSProperties['transition'] | string;
971
476
  /**
@@ -1160,8 +665,23 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
1160
665
  scrollMarginRight?: string | number | boolean;
1161
666
  scrollMarginBottom?: string | number | boolean;
1162
667
  scrollMarginLeft?: string | number | boolean;
1163
- scrollMarginBlock?: string | number | boolean;
1164
- scrollMarginInline?: string | number | boolean;
668
+ /** Logical block-axis scroll margin with `start`/`end` modifiers. */
669
+ blockScrollMargin?: CSSProperties['scrollMarginBlock'] | string | boolean;
670
+ /** Logical inline-axis scroll margin with `start`/`end` modifiers. */
671
+ inlineScrollMargin?: CSSProperties['scrollMarginInline'] | string | boolean;
672
+ /**
673
+ * Shorthand for physical scroll padding. Supports custom units and the same
674
+ * physical direction modifiers as `padding`.
675
+ */
676
+ scrollPadding?: CSSProperties['scrollPadding'] | string | boolean;
677
+ scrollPaddingTop?: string | number | boolean;
678
+ scrollPaddingRight?: string | number | boolean;
679
+ scrollPaddingBottom?: string | number | boolean;
680
+ scrollPaddingLeft?: string | number | boolean;
681
+ /** Logical block-axis scroll padding with `start`/`end` modifiers. */
682
+ blockScrollPadding?: CSSProperties['scrollPaddingBlock'] | string | boolean;
683
+ /** Logical inline-axis scroll padding with `start`/`end` modifiers. */
684
+ inlineScrollPadding?: CSSProperties['scrollPaddingInline'] | string | boolean;
1165
685
  /**
1166
686
  * Shorthand for `top`, `right`, `bottom`, and `left` offsets. Supports custom units, directional modifiers, and positioning.
1167
687
  *
@@ -1183,6 +703,10 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
1183
703
  * insets the sides by `4x`. Without `dock` a second value is ignored.
1184
704
  */
1185
705
  inset?: 'top' | 'right' | 'bottom' | 'left' | 'dock' | string | CSSProperties['inset'];
706
+ /** Logical block-axis inset with `start`/`end` modifiers. */
707
+ blockInset?: CSSProperties['insetBlock'] | string | boolean;
708
+ /** Logical inline-axis inset with `start`/`end` modifiers. */
709
+ inlineInset?: CSSProperties['insetInline'] | string | boolean;
1186
710
  /**
1187
711
  * Local keyframes definitions for this component.
1188
712
  * Keys are animation names, values are keyframes step definitions.
@@ -1225,329 +749,819 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
1225
749
  */
1226
750
  '@counter-style'?: Record<string, CounterStyleDescriptors>;
1227
751
  /**
1228
- * Local @function definitions (CSS custom functions) for this component.
1229
- * Keys are function names using `$$name` (the literal callable `--name`),
1230
- * matching the call site `$$name(...)`. Values are function definitions.
1231
- *
1232
- * Local variables are declared directly as `$name` keys on the descriptor;
1233
- * `result`, local-var values, and parameter defaults are parsed through the
1234
- * Tasty DSL (units, color tokens, auto-calc, fallbacks).
752
+ * Local @function definitions (CSS custom functions) for this component.
753
+ * Keys are function names using `$$name` (the literal callable `--name`),
754
+ * matching the call site `$$name(...)`. Values are function definitions.
755
+ *
756
+ * Local variables are declared directly as `$name` keys on the descriptor;
757
+ * `result`, local-var values, and parameter defaults are parsed through the
758
+ * Tasty DSL (units, color tokens, auto-calc, fallbacks).
759
+ *
760
+ * Examples:
761
+ * - `'@function': { '$$negative': { args: ['$value'], result: '(-1 * $value)' } }`
762
+ * - `'@function': { '$$shadow': { args: { '$color': { syntax: '<color>', default: 'inherit' } }, returns: '<color>', '$offset': '2px', result: '$offset $offset ($color, black)' } }`
763
+ */
764
+ '@function'?: Record<string, FunctionDefinition>;
765
+ /**
766
+ * Apply one or more predefined style recipes by name.
767
+ * Recipes are defined globally via `configure({ recipes: { ... } })`.
768
+ * Multiple recipes are space-separated. Use `/` to separate base recipes
769
+ * (applied before component styles) from post recipes (applied after, via mergeStyles).
770
+ * Use `none` to explicitly skip base recipes.
771
+ *
772
+ * Examples:
773
+ * - `recipe: 'card'` // Apply the 'card' recipe
774
+ * - `recipe: 'card elevated'` // Apply 'card' then 'elevated', then component styles
775
+ * - `recipe: 'reset input / input-autofill'` // Base recipes, then post recipe
776
+ * - `recipe: 'none / disabled'` // No base recipes, only post recipe
777
+ * - `recipe: ''` // Clear recipes from base styles when extending
778
+ */
779
+ recipe?: string;
780
+ }
781
+ type SuffixForSelector = '&' | '.' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
782
+ type Selector = `${SuffixForSelector}${string}`;
783
+ type NotSelector = Exclude<string, Selector | keyof StylesInterface>;
784
+ /** Special style keys that should not be wrapped in StyleValue/StyleValueStateMap */
785
+ type SpecialStyleKeys = '@keyframes' | '@property' | '@font-face' | '@counter-style' | '@function' | 'recipe';
786
+ type StylesWithoutSelectors = { [key in keyof StylesInterface as key extends SpecialStyleKeys ? never : key]?: StyleValue<StylesInterface[key]> | StyleValueStateMap<StylesInterface[key]>; };
787
+ /**
788
+ * Index signature for recipe-specific arbitrary keys.
789
+ * Supports local predefined states (`@name`), vendor-prefixed CSS properties (`-webkit-*`),
790
+ * CSS custom properties (`$name`), and color tokens (`#name`).
791
+ * Unlike StylesIndexSignature, does NOT allow sub-element selectors (recipes are flat).
792
+ */
793
+ type RecipeIndexSignature = Record<string, StyleValue<string | number | boolean | undefined> | StyleValueStateMap<string | number | boolean | undefined>>;
794
+ /**
795
+ * Style type for recipe definitions.
796
+ * Like StylesWithoutSelectors but also allows `@keyframes`, `@property`,
797
+ * local predefined states, and vendor-prefixed CSS properties.
798
+ * Excludes `recipe` to prevent recursive references.
799
+ */
800
+ type RecipeStyles = StylesWithoutSelectors & RecipeIndexSignature & {
801
+ '@keyframes'?: StylesInterface['@keyframes'];
802
+ '@property'?: StylesInterface['@property'];
803
+ '@font-face'?: StylesInterface['@font-face'];
804
+ '@counter-style'?: StylesInterface['@counter-style'];
805
+ '@function'?: StylesInterface['@function'];
806
+ };
807
+ /** Special properties that are not regular style values */
808
+ interface SpecialStyleProperties {
809
+ '@keyframes'?: StylesInterface['@keyframes'];
810
+ '@property'?: StylesInterface['@property'];
811
+ '@font-face'?: StylesInterface['@font-face'];
812
+ '@counter-style'?: StylesInterface['@counter-style'];
813
+ '@function'?: StylesInterface['@function'];
814
+ recipe?: StylesInterface['recipe'];
815
+ }
816
+ /** Index signature for arbitrary style keys (sub-elements, CSS variables, etc.) */
817
+ interface StylesIndexSignature {
818
+ [key: string]: StyleValue<string | number | boolean | undefined> | StyleValueStateMap<string | number | boolean | undefined> | Styles | false | StylesInterface['@keyframes'] | StylesInterface['@property'] | StylesInterface['@font-face'] | StylesInterface['@counter-style'] | StylesInterface['@function'];
819
+ /**
820
+ * Selector combinator: `undefined` (descendant, default), `'>'` (child), `'+'` (adjacent), `'~'` (sibling).
821
+ * Can chain with capitalized names: `'> Body > Row >'`. Spaces required around combinators.
822
+ */
823
+ $?: string;
824
+ }
825
+ type Styles = StylesWithoutSelectors & SpecialStyleProperties & StylesIndexSignature;
826
+ /**
827
+ * Value type for design tokens passed to `configure({ tokens })`.
828
+ * Can be a direct value or a state map for responsive/theme-aware tokens.
829
+ */
830
+ type ConfigTokenValue = string | number | boolean | Record<string, string | number | boolean | undefined | null | '@inherit'>;
831
+ /**
832
+ * Design tokens injected as CSS custom properties on `:root`.
833
+ * Keys must start with `$` (value tokens) or `#` (color tokens).
834
+ *
835
+ * - `$name` keys become `--name` CSS custom properties
836
+ * - `#name` keys become `--name-color` properties
837
+ */
838
+ type ConfigTokens = Record<`$${string}` | `#${string}`, ConfigTokenValue>;
839
+ //#endregion
840
+ //#region src/pipeline/conditions.d.ts
841
+ /**
842
+ * ConditionNode Types and Helpers
843
+ *
844
+ * Core data structures for representing style conditions as an abstract syntax tree.
845
+ * Used throughout the pipeline for parsing, simplification, and CSS generation.
846
+ */
847
+ /**
848
+ * Base interface for all state conditions (leaf nodes)
849
+ */
850
+ interface BaseStateCondition {
851
+ kind: 'state';
852
+ negated: boolean;
853
+ raw: string;
854
+ uniqueId: string;
855
+ }
856
+ /**
857
+ * Modifier condition: [data-attr] or [data-attr="value"]
858
+ */
859
+ interface ModifierCondition extends BaseStateCondition {
860
+ type: 'modifier';
861
+ attribute: string;
862
+ value?: string;
863
+ operator?: '=' | '^=' | '$=' | '*=';
864
+ }
865
+ /**
866
+ * Pseudo-class condition: :hover, :focus-visible
867
+ */
868
+ interface PseudoCondition extends BaseStateCondition {
869
+ type: 'pseudo';
870
+ pseudo: string;
871
+ }
872
+ /**
873
+ * Numeric bound for dimension queries
874
+ */
875
+ interface NumericBound {
876
+ value: string;
877
+ valueNumeric: number | null;
878
+ inclusive: boolean;
879
+ }
880
+ /**
881
+ * Media query condition
882
+ */
883
+ interface MediaCondition extends BaseStateCondition {
884
+ type: 'media';
885
+ subtype: 'dimension' | 'feature' | 'type';
886
+ dimension?: 'width' | 'height' | 'inline-size' | 'block-size';
887
+ lowerBound?: NumericBound;
888
+ upperBound?: NumericBound;
889
+ feature?: string;
890
+ featureValue?: string;
891
+ mediaType?: 'print' | 'screen' | 'all' | 'speech';
892
+ }
893
+ /**
894
+ * Container query condition
895
+ */
896
+ interface ContainerCondition extends BaseStateCondition {
897
+ type: 'container';
898
+ subtype: 'dimension' | 'style' | 'raw';
899
+ containerName?: string;
900
+ dimension?: 'width' | 'height' | 'inline-size' | 'block-size';
901
+ lowerBound?: NumericBound;
902
+ upperBound?: NumericBound;
903
+ property?: string;
904
+ propertyValue?: string;
905
+ rawCondition?: string;
906
+ }
907
+ /**
908
+ * Root state condition: @root(theme=dark)
909
+ */
910
+ interface RootCondition extends BaseStateCondition {
911
+ type: 'root';
912
+ innerCondition: ConditionNode;
913
+ }
914
+ /**
915
+ * Parent state condition: @parent(hovered), @parent(theme=dark, >)
916
+ */
917
+ interface ParentCondition extends BaseStateCondition {
918
+ type: 'parent';
919
+ innerCondition: ConditionNode;
920
+ direct: boolean;
921
+ }
922
+ /**
923
+ * Own state condition: @own(hovered)
924
+ */
925
+ interface OwnCondition extends BaseStateCondition {
926
+ type: 'own';
927
+ innerCondition: ConditionNode;
928
+ }
929
+ /**
930
+ * Starting style condition: @starting
931
+ */
932
+ interface StartingCondition extends BaseStateCondition {
933
+ type: 'starting';
934
+ }
935
+ /**
936
+ * Supports query condition: @supports(display: grid), @supports($, :has(*))
937
+ */
938
+ interface SupportsCondition extends BaseStateCondition {
939
+ type: 'supports';
940
+ subtype: 'feature' | 'selector';
941
+ condition: string;
942
+ }
943
+ /**
944
+ * Union of all state condition types
945
+ */
946
+ type StateCondition = ModifierCondition | PseudoCondition | MediaCondition | ContainerCondition | RootCondition | ParentCondition | OwnCondition | StartingCondition | SupportsCondition;
947
+ /**
948
+ * Compound node: combines conditions with AND/OR
949
+ */
950
+ interface CompoundCondition {
951
+ kind: 'compound';
952
+ operator: 'AND' | 'OR';
953
+ children: ConditionNode[];
954
+ }
955
+ /**
956
+ * True condition (matches everything)
957
+ */
958
+ interface TrueCondition {
959
+ kind: 'true';
960
+ }
961
+ /**
962
+ * False condition (matches nothing - skip this rule)
963
+ */
964
+ interface FalseCondition {
965
+ kind: 'false';
966
+ }
967
+ /**
968
+ * Union of all condition node types
969
+ */
970
+ type ConditionNode = StateCondition | CompoundCondition | TrueCondition | FalseCondition;
971
+ //#endregion
972
+ //#region src/states/index.d.ts
973
+ /**
974
+ * Parsed advanced state information
975
+ */
976
+ interface ParsedAdvancedState {
977
+ type: 'media' | 'container' | 'root' | 'parent' | 'own' | 'starting' | 'predefined' | 'modifier';
978
+ condition: string;
979
+ containerName?: string;
980
+ raw: string;
981
+ mediaType?: string;
982
+ }
983
+ /**
984
+ * Context for state parsing operations
985
+ */
986
+ interface StateParserContext {
987
+ localPredefinedStates: Record<string, string>;
988
+ globalPredefinedStates: Record<string, string>;
989
+ isSubElement?: boolean;
990
+ }
991
+ /**
992
+ * At-rule context for CSS generation
993
+ */
994
+ interface AtRuleContext {
995
+ media?: string[];
996
+ container?: {
997
+ name?: string;
998
+ condition: string;
999
+ }[];
1000
+ startingStyle?: boolean;
1001
+ rootStates?: string[];
1002
+ negatedRootStates?: string[];
1003
+ }
1004
+ /**
1005
+ * Configure global predefined states
1006
+ */
1007
+ declare function setGlobalPredefinedStates(states: Record<string, string>): void;
1008
+ /**
1009
+ * Get global predefined states
1010
+ */
1011
+ declare function getGlobalPredefinedStates(): Record<string, string>;
1012
+ /**
1013
+ * Create a state parser context from styles
1014
+ */
1015
+ declare function createStateParserContext(styles?: Styles, isSubElement?: boolean): StateParserContext;
1016
+ //#endregion
1017
+ //#region src/pipeline/parseStateKey.d.ts
1018
+ interface ParseStateKeyOptions {
1019
+ context?: StateParserContext;
1020
+ isSubElement?: boolean;
1021
+ }
1022
+ /**
1023
+ * Parse a state key string into a ConditionNode
1024
+ */
1025
+ declare function parseStateKey(stateKey: string, options?: ParseStateKeyOptions): ConditionNode;
1026
+ //#endregion
1027
+ //#region src/pipeline/index.d.ts
1028
+ /**
1029
+ * Matches the old StyleResult interface for backward compatibility
1030
+ */
1031
+ interface StyleResult {
1032
+ selector: string;
1033
+ declarations: string;
1034
+ atRules?: string[];
1035
+ needsClassName?: boolean;
1036
+ rootPrefix?: string;
1037
+ /** When true, declarations are wrapped in @starting-style { ... } inside the selector rule */
1038
+ startingStyle?: boolean;
1039
+ }
1040
+ /**
1041
+ * Matches the old RenderResult interface for backward compatibility
1042
+ */
1043
+ interface RenderResult {
1044
+ rules: StyleResult[];
1045
+ className?: string;
1046
+ }
1047
+ /**
1048
+ * Options for renderStyles when using direct selector mode.
1049
+ */
1050
+ interface RenderStylesOptions {
1051
+ /**
1052
+ * Whether to double the class selector for increased specificity.
1053
+ * When true, `.myClass` becomes `.myClass.myClass` for higher specificity.
1235
1054
  *
1236
- * Examples:
1237
- * - `'@function': { '$$negative': { args: ['$value'], result: '(-1 * $value)' } }`
1238
- * - `'@function': { '$$shadow': { args: { '$color': { syntax: '<color>', default: 'inherit' } }, returns: '<color>', '$offset': '2px', result: '$offset $offset ($color, black)' } }`
1239
- */
1240
- '@function'?: Record<string, FunctionDefinition>;
1241
- /**
1242
- * Apply one or more predefined style recipes by name.
1243
- * Recipes are defined globally via `configure({ recipes: { ... } })`.
1244
- * Multiple recipes are space-separated. Use `/` to separate base recipes
1245
- * (applied before component styles) from post recipes (applied after, via mergeStyles).
1246
- * Use `none` to explicitly skip base recipes.
1055
+ * @default false - User-provided selectors are not doubled.
1247
1056
  *
1248
- * Examples:
1249
- * - `recipe: 'card'` // Apply the 'card' recipe
1250
- * - `recipe: 'card elevated'` // Apply 'card' then 'elevated', then component styles
1251
- * - `recipe: 'reset input / input-autofill'` // Base recipes, then post recipe
1252
- * - `recipe: 'none / disabled'` // No base recipes, only post recipe
1253
- * - `recipe: ''` // Clear recipes from base styles when extending
1057
+ * Note: This only applies when a classNameOrSelector is provided.
1058
+ * When renderStyles returns RenderResult with needsClassName=true,
1059
+ * the injector handles doubling automatically.
1254
1060
  */
1255
- recipe?: string;
1061
+ doubleSelector?: boolean;
1256
1062
  }
1257
- type SuffixForSelector = '&' | '.' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
1258
- type Selector = `${SuffixForSelector}${string}`;
1259
- type NotSelector = Exclude<string, Selector | keyof StylesInterface>;
1260
- /** Special style keys that should not be wrapped in StyleValue/StyleValueStateMap */
1261
- type SpecialStyleKeys = '@keyframes' | '@property' | '@font-face' | '@counter-style' | '@function' | 'recipe';
1262
- type StylesWithoutSelectors = { [key in keyof StylesInterface as key extends SpecialStyleKeys ? never : key]?: StyleValue<StylesInterface[key]> | StyleValueStateMap<StylesInterface[key]> };
1263
1063
  /**
1264
- * Index signature for recipe-specific arbitrary keys.
1265
- * Supports local predefined states (`@name`), vendor-prefixed CSS properties (`-webkit-*`),
1266
- * CSS custom properties (`$name`), and color tokens (`#name`).
1267
- * Unlike StylesIndexSignature, does NOT allow sub-element selectors (recipes are flat).
1064
+ * Render styles to CSS rules.
1065
+ *
1066
+ * When called without classNameOrSelector, returns RenderResult with needsClassName=true.
1067
+ * When called with a selector/className string, returns StyleResult[] for direct injection.
1268
1068
  */
1269
- type RecipeIndexSignature = Record<string, StyleValue<string | number | boolean | undefined> | StyleValueStateMap<string | number | boolean | undefined>>;
1069
+ declare function renderStyles(styles?: Styles, classNameOrSelector?: undefined, options?: undefined, pipelineCacheKey?: string): RenderResult;
1070
+ declare function renderStyles(styles: Styles | undefined, classNameOrSelector: string, options?: RenderStylesOptions): StyleResult[];
1071
+ //#endregion
1072
+ //#region src/properties/property-type-resolver.d.ts
1270
1073
  /**
1271
- * Style type for recipe definitions.
1272
- * Like StylesWithoutSelectors but also allows `@keyframes`, `@property`,
1273
- * local predefined states, and vendor-prefixed CSS properties.
1274
- * Excludes `recipe` to prevent recursive references.
1074
+ * PropertyTypeResolver
1075
+ *
1076
+ * Automatically infers CSS @property types from custom property values.
1077
+ * Supports deferred resolution for var() reference chains of arbitrary depth.
1275
1078
  */
1276
- type RecipeStyles = StylesWithoutSelectors & RecipeIndexSignature & {
1277
- '@keyframes'?: StylesInterface['@keyframes'];
1278
- '@property'?: StylesInterface['@property'];
1279
- '@font-face'?: StylesInterface['@font-face'];
1280
- '@counter-style'?: StylesInterface['@counter-style'];
1281
- '@function'?: StylesInterface['@function'];
1282
- };
1283
- /** Special properties that are not regular style values */
1284
- interface SpecialStyleProperties {
1285
- '@keyframes'?: StylesInterface['@keyframes'];
1286
- '@property'?: StylesInterface['@property'];
1287
- '@font-face'?: StylesInterface['@font-face'];
1288
- '@counter-style'?: StylesInterface['@counter-style'];
1289
- '@function'?: StylesInterface['@function'];
1290
- recipe?: StylesInterface['recipe'];
1291
- }
1292
- /** Index signature for arbitrary style keys (sub-elements, CSS variables, etc.) */
1293
- interface StylesIndexSignature {
1294
- [key: string]: StyleValue<string | number | boolean | undefined> | StyleValueStateMap<string | number | boolean | undefined> | Styles | false | StylesInterface['@keyframes'] | StylesInterface['@property'] | StylesInterface['@font-face'] | StylesInterface['@counter-style'] | StylesInterface['@function'];
1079
+ declare class PropertyTypeResolver {
1080
+ /** propName → the prop it depends on */
1081
+ private pendingDeps;
1082
+ /** propName → list of props waiting on it */
1083
+ private reverseDeps;
1295
1084
  /**
1296
- * Selector combinator: `undefined` (descendant, default), `'>'` (child), `'+'` (adjacent), `'~'` (sibling).
1297
- * Can chain with capitalized names: `'> Body > Row >'`. Spaces required around combinators.
1085
+ * Scan CSS declarations and auto-register @property for custom properties
1086
+ * whose types can be inferred from their values.
1298
1087
  */
1299
- $?: string;
1088
+ scanDeclarations(declarations: string, isPropertyDefined: (name: string) => boolean, registerProperty: (name: string, syntax: string, initialValue: string) => void): void;
1089
+ private addDependency;
1090
+ private resolve;
1091
+ private isComplexValue;
1300
1092
  }
1301
- type Styles = StylesWithoutSelectors & SpecialStyleProperties & StylesIndexSignature;
1302
- /**
1303
- * Value type for design tokens passed to `configure({ tokens })`.
1304
- * Can be a direct value or a state map for responsive/theme-aware tokens.
1305
- */
1306
- type ConfigTokenValue = string | number | boolean | Record<string, string | number | boolean | undefined | null | '@inherit'>;
1093
+ //#endregion
1094
+ //#region src/injector/batch.d.ts
1307
1095
  /**
1308
- * Design tokens injected as CSS custom properties on `:root`.
1309
- * Keys must start with `$` (value tokens) or `#` (color tokens).
1096
+ * Deferred CSSOM writes ("batched injection").
1310
1097
  *
1311
- * - `$name` keys become `--name` CSS custom properties
1312
- * - `#name` keys become `--name-color` properties
1098
+ * Every `insertRule()` on a live stylesheet invalidates style for the sheet's
1099
+ * scope, so Blink recalculates style the next time anything reads layout or
1100
+ * computed style. When components inject during React's render phase and other
1101
+ * components read layout in the same pass, the two interleave:
1102
+ *
1103
+ * inject -> read (forced recalc) -> inject -> read (forced recalc) -> ...
1104
+ *
1105
+ * Batching moves every sheet write out from between those reads. Writes are
1106
+ * queued in FIFO order and drained in one go, so the tree is invalidated once
1107
+ * per flush instead of once per component.
1108
+ *
1109
+ * ## Ordering
1110
+ *
1111
+ * A single queue holds *all* writes — component rules, global rules, keyframes,
1112
+ * `@property`, `@font-face`, `@counter-style`, `@function` and raw CSS. Draining
1113
+ * it in insertion order keeps the sheet byte-identical to unbatched output,
1114
+ * which matters because equal-specificity rules resolve by document order.
1115
+ *
1116
+ * ## Batch windows — why queuing is safe
1117
+ *
1118
+ * Deferring a write past React's layout phase would let a `useLayoutEffect`
1119
+ * measure an element whose rules are not in the sheet yet, reading the unstyled
1120
+ * box. `<TastyBatchProvider>` closes that hole by opening a *window* during its
1121
+ * render and closing it — flushing — in its `useInsertionEffect`, which React
1122
+ * runs in the mutation phase, before any layout effect:
1123
+ *
1124
+ * provider renders -> window OPEN
1125
+ * children render -> injections queued
1126
+ * provider insertionEffect -> FLUSH, window CLOSED
1127
+ * layout effects run -> rules are in the sheet
1128
+ *
1129
+ * So in the default (`batchInjection: true`) mode a write is only ever queued
1130
+ * inside a commit whose flush is already guaranteed by that same commit. Every
1131
+ * injection outside a window — a deep update the provider did not re-render
1132
+ * for, a `useLayoutEffect` that injects, an event handler, an async callback —
1133
+ * is written straight through, exactly as with batching off.
1134
+ *
1135
+ * `batchInjection: 'always'` opts out of the gate and queues unconditionally.
1136
+ * That wins on more commits, at the cost of the measurement hazard above.
1137
+ *
1138
+ * ## Flush points (earliest wins)
1139
+ *
1140
+ * 1. `<TastyBatchProvider>`'s `useInsertionEffect` — closes the window.
1141
+ * 2. A microtask — a backstop for a render that was aborted or suspended and
1142
+ * therefore never reached its insertion effect. An aborted render mounts
1143
+ * nothing, so nothing can measure what it queued. Microtasks also always
1144
+ * drain before paint, so styles are never visually missing.
1145
+ * 3. `flushStyles()` — explicit, and called internally by every injector read
1146
+ * API (`getCSSText`, `cleanup`, `gc`, `destroy`, ...).
1313
1147
  */
1314
- type ConfigTokens = Record<`$${string}` | `#${string}`, ConfigTokenValue>;
1315
- //#endregion
1316
- //#region src/pipeline/conditions.d.ts
1148
+ interface QueuedWrite {
1149
+ /** Perform the deferred sheet write. */
1150
+ run: () => void;
1151
+ /** Set when the owner disposed before the write happened. */
1152
+ cancelled: boolean;
1153
+ /** Set once the write has been applied (or skipped as cancelled). */
1154
+ done: boolean;
1155
+ }
1156
+ /** Whether any write is still waiting to hit a stylesheet. */
1157
+ declare function hasPendingStyleWrites(): boolean;
1317
1158
  /**
1318
- * ConditionNode Types and Helpers
1159
+ * Drain every pending sheet write, in insertion order.
1319
1160
  *
1320
- * Core data structures for representing style conditions as an abstract syntax tree.
1321
- * Used throughout the pipeline for parsing, simplification, and CSS generation.
1161
+ * Safe to call when the queue is empty (the common case, so the guard comes
1162
+ * first) and safe to call re-entrantly: a nested `flushStyles()` is a no-op,
1163
+ * and work a draining write triggers is written in place by
1164
+ * `enqueueStyleWrite` rather than queued behind the rest of the batch.
1322
1165
  */
1166
+ declare function flushStyles(): void;
1323
1167
  /**
1324
- * Base interface for all state conditions (leaf nodes)
1168
+ * Drop every pending write without applying it. Test helper — production code
1169
+ * should call `flushStyles()` instead.
1325
1170
  */
1326
- interface BaseStateCondition {
1327
- kind: 'state';
1328
- negated: boolean;
1329
- raw: string;
1330
- uniqueId: string;
1171
+ declare function resetStyleBatch(): void;
1172
+ //#endregion
1173
+ //#region src/injector/types.d.ts
1174
+ declare global {
1175
+ interface Window {
1176
+ __TASTY__?: string[];
1177
+ }
1331
1178
  }
1332
- /**
1333
- * Modifier condition: [data-attr] or [data-attr="value"]
1334
- */
1335
- interface ModifierCondition extends BaseStateCondition {
1336
- type: 'modifier';
1337
- attribute: string;
1338
- value?: string;
1339
- operator?: '=' | '^=' | '$=' | '*=';
1179
+ interface InjectResult {
1180
+ className: string;
1181
+ dispose: () => void;
1340
1182
  }
1341
- /**
1342
- * Pseudo-class condition: :hover, :focus-visible
1343
- */
1344
- interface PseudoCondition extends BaseStateCondition {
1345
- type: 'pseudo';
1346
- pseudo: string;
1183
+ interface GlobalInjectResult {
1184
+ dispose: () => void;
1347
1185
  }
1348
- /**
1349
- * Numeric bound for dimension queries
1350
- */
1351
- interface NumericBound {
1352
- value: string;
1353
- valueNumeric: number | null;
1354
- inclusive: boolean;
1186
+ type DisposeFunction = () => void;
1187
+ interface StyleInjectorConfig {
1188
+ nonce?: string;
1189
+ maxRulesPerSheet?: number;
1190
+ forceTextInjection?: boolean;
1191
+ /** Enable development mode features: performance metrics and debug information storage */
1192
+ devMode?: boolean;
1193
+ /**
1194
+ * Global predefined states for advanced state mapping.
1195
+ * These are state aliases that can be used in any component.
1196
+ * Example: { '@mobile': '@media(w < 920px)', '@dark': '@root(theme=dark)' }
1197
+ */
1198
+ states?: Record<string, string>;
1199
+ /**
1200
+ * Automatically infer and register CSS @property declarations
1201
+ * from custom property values. When false, only explicit @property are used.
1202
+ * @default true
1203
+ */
1204
+ autoPropertyTypes?: boolean;
1205
+ /** Garbage collection configuration for unused styles */
1206
+ gc?: GCConfig;
1207
+ /**
1208
+ * Prefix prepended to every generated identifier.
1209
+ * Mirrors the `namePrefix` field on the public `TastyConfig` so that
1210
+ * standalone injector consumers can configure it directly.
1211
+ * @default 't'
1212
+ */
1213
+ namePrefix?: string;
1214
+ /**
1215
+ * Defer stylesheet writes and apply them in one batch instead of one
1216
+ * `insertRule()` per component. Mirrors `batchInjection` on the public
1217
+ * `TastyConfig`.
1218
+ * @default false
1219
+ */
1220
+ batchInjection?: boolean | 'always';
1355
1221
  }
1356
1222
  /**
1357
- * Media query condition
1223
+ * Per-className usage tracking for GC.
1358
1224
  */
1359
- interface MediaCondition extends BaseStateCondition {
1360
- type: 'media';
1361
- subtype: 'dimension' | 'feature' | 'type';
1362
- dimension?: 'width' | 'height' | 'inline-size' | 'block-size';
1363
- lowerBound?: NumericBound;
1364
- upperBound?: NumericBound;
1365
- feature?: string;
1366
- featureValue?: string;
1367
- mediaType?: 'print' | 'screen' | 'all' | 'speech';
1368
- }
1369
1225
  /**
1370
- * Container query condition
1226
+ * @deprecated Nothing reads this any more. Collection asks the DOM what is
1227
+ * rendered rather than tracking usage per class, so there is no usage record
1228
+ * to describe. Kept so existing imports keep type-checking.
1371
1229
  */
1372
- interface ContainerCondition extends BaseStateCondition {
1373
- type: 'container';
1374
- subtype: 'dimension' | 'style' | 'raw';
1375
- containerName?: string;
1376
- dimension?: 'width' | 'height' | 'inline-size' | 'block-size';
1377
- lowerBound?: NumericBound;
1378
- upperBound?: NumericBound;
1379
- property?: string;
1380
- propertyValue?: string;
1381
- rawCondition?: string;
1230
+ interface StyleUsage {
1231
+ lastTouchedAt: number;
1382
1232
  }
1383
1233
  /**
1384
- * Root state condition: @root(theme=dark)
1234
+ * Configuration for the style garbage collector.
1235
+ *
1236
+ * GC is triggered by touch count rather than timers: every `touchInterval`
1237
+ * touches, an idle callback is scheduled to evict unused styles above
1238
+ * `capacity`, oldest first.
1385
1239
  */
1386
- interface RootCondition extends BaseStateCondition {
1387
- type: 'root';
1388
- innerCondition: ConditionNode;
1240
+ interface GCConfig {
1241
+ /**
1242
+ * How long a class is left alone after collection first notices nothing is
1243
+ * carrying it, in milliseconds (default 10,000).
1244
+ *
1245
+ * Rendering is not commit-aware: a render can resolve a class and commit it a
1246
+ * little later, and in between nothing on the page carries it. Rather than
1247
+ * try to tell that apart from a class that is finished — which cannot be done
1248
+ * from outside React — collection simply does not touch anything that was in
1249
+ * use recently. A render would have to stay pending for the whole window to
1250
+ * lose its rules, and it gets them back on its next render.
1251
+ */
1252
+ grace?: number;
1253
+ /**
1254
+ * Number of touch events between automatic GC cycles.
1255
+ * @default 1000
1256
+ */
1257
+ touchInterval?: number;
1258
+ /**
1259
+ * Maximum number of unused styles to retain.
1260
+ * GC evicts the oldest unused styles when this limit is exceeded.
1261
+ * Pinned styles and DOM-live styles
1262
+ * do not count against this limit.
1263
+ * @default 1000
1264
+ */
1265
+ capacity?: number;
1389
1266
  }
1390
1267
  /**
1391
- * Parent state condition: @parent(hovered), @parent(theme=dark, >)
1268
+ * Per-call options for inject().
1392
1269
  */
1393
- interface ParentCondition extends BaseStateCondition {
1394
- type: 'parent';
1395
- innerCondition: ConditionNode;
1396
- direct: boolean;
1270
+ interface InjectOptions {
1271
+ root?: Document | ShadowRoot;
1272
+ /** Reuse the class already injected for this key instead of writing again. */
1273
+ cacheKey?: string;
1274
+ /**
1275
+ * Pin the injected class (default `true`). A pinned class is never evicted by
1276
+ * `gc()`, and the returned `dispose()` releases the pin. Pass `false` when the
1277
+ * caller keeps no handle and the DOM is the only record that the class is in
1278
+ * use — the render path does this, because a hook-free render has no unmount
1279
+ * signal to dispose on.
1280
+ */
1281
+ pin?: boolean;
1397
1282
  }
1398
1283
  /**
1399
- * Own state condition: @own(hovered)
1284
+ * Per-call options for gc().
1400
1285
  */
1401
- interface OwnCondition extends BaseStateCondition {
1402
- type: 'own';
1403
- innerCondition: ConditionNode;
1286
+ interface GCOptions {
1287
+ root?: Document | ShadowRoot;
1288
+ /** Bypass capacity threshold and remove ALL unused styles. */
1289
+ force?: boolean;
1404
1290
  }
1405
- /**
1406
- * Starting style condition: @starting
1407
- */
1408
- interface StartingCondition extends BaseStateCondition {
1409
- type: 'starting';
1291
+ interface RuleInfo {
1292
+ className: string;
1293
+ ruleIndex: number;
1294
+ sheetIndex: number;
1295
+ /** Dev-only: full CSS texts inserted for this class; omitted in production */
1296
+ cssText?: string[];
1297
+ /** Inclusive end index of the contiguous block of inserted rules for this className */
1298
+ endRuleIndex?: number;
1299
+ /** NEW: exact indices of all inserted rules for this className */
1300
+ indices?: number[];
1410
1301
  }
1411
- /**
1412
- * Supports query condition: @supports(display: grid), @supports($, :has(*))
1413
- */
1414
- interface SupportsCondition extends BaseStateCondition {
1415
- type: 'supports';
1416
- subtype: 'feature' | 'selector';
1417
- condition: string;
1302
+ type InjectionMode = 'style-element' | 'adopted';
1303
+ interface SheetInfo {
1304
+ /** HTMLStyleElement used in style-element mode; null in adopted mode. */
1305
+ sheet: HTMLStyleElement | null;
1306
+ /** Constructable CSSStyleSheet used in adopted mode (ShadowRoot targets) */
1307
+ constructableSheet?: CSSStyleSheet;
1308
+ ruleCount: number;
1309
+ holes: number[];
1310
+ /**
1311
+ * True when this sheet is written through `textContent` instead of CSSOM.
1312
+ * Decided once at sheet creation so a sheet is never half CSSOM / half text.
1313
+ */
1314
+ textMode?: boolean;
1315
+ /**
1316
+ * Inserted rule texts in rule-index order. Maintained only in text mode —
1317
+ * it is what makes deletion possible there, since `textContent` cannot be
1318
+ * edited rule-by-rule and has to be rebuilt.
1319
+ */
1320
+ textRules?: string[];
1418
1321
  }
1419
- /**
1420
- * Union of all state condition types
1421
- */
1422
- type StateCondition = ModifierCondition | PseudoCondition | MediaCondition | ContainerCondition | RootCondition | ParentCondition | OwnCondition | StartingCondition | SupportsCondition;
1423
- /**
1424
- * Compound node: combines conditions with AND/OR
1425
- */
1426
- interface CompoundCondition {
1427
- kind: 'compound';
1428
- operator: 'AND' | 'OR';
1429
- children: ConditionNode[];
1322
+ interface CleanupStats {
1323
+ timestamp: number;
1324
+ classesDeleted: number;
1325
+ cssSize: number;
1326
+ rulesDeleted: number;
1327
+ }
1328
+ interface CacheMetrics {
1329
+ hits: number;
1330
+ misses: number;
1331
+ bulkCleanups: number;
1332
+ totalInsertions: number;
1333
+ totalUnused: number;
1334
+ stylesCleanedUp: number;
1335
+ cleanupHistory: CleanupStats[];
1336
+ startTime: number;
1337
+ unusedHits?: number;
1338
+ }
1339
+ interface RootRegistry {
1340
+ sheets: SheetInfo[];
1341
+ /** className -> outstanding `inject()` references; 0 means nobody holds a handle */
1342
+ pinCounts: Map<string, number>;
1343
+ rules: Map<string, RuleInfo>;
1344
+ /** Cache key to className mapping to avoid dual storage of RuleInfo objects */
1345
+ cacheKeyToClassName: Map<string, string>;
1346
+ /** Deduplication set of fully materialized CSS rules inserted into sheets */
1347
+ ruleTextSet: Set<string>;
1348
+ /** Performance metrics (optional) */
1349
+ metrics?: CacheMetrics;
1350
+ /** Keyframes cache by content hash -> entry */
1351
+ keyframesCache: Map<string, KeyframesCacheEntry>;
1352
+ /** Keyframes name to content hash mapping for collision detection */
1353
+ keyframesNameToContent: Map<string, string>;
1354
+ /** Counter for generating keyframes names like k0, k1, k2... */
1355
+ keyframesCounter: number;
1356
+ /** Map of injected @property names to their normalized declarations for tracking */
1357
+ injectedProperties: Map<string, string>;
1358
+ /** Content hashes of injected @font-face rules for deduplication */
1359
+ injectedFontFaces: Set<string>;
1360
+ /**
1361
+ * Injected @counter-style rules. Maps the name to whether it was injected
1362
+ * "strong" (`true`, the default — overrides) or "weak" (`false`, global
1363
+ * `configure()` definitions that never clobber an existing rule).
1364
+ */
1365
+ injectedCounterStyles: Map<string, boolean>;
1366
+ /**
1367
+ * Injected @function rules. Maps the CSS function name to whether it was
1368
+ * injected "strong" (`true`, the default — overrides) or "weak" (`false`,
1369
+ * global `configure()` definitions that never clobber an existing rule).
1370
+ */
1371
+ injectedFunctions: Map<string, boolean>;
1372
+ /** Global rules tracking for index adjustment */
1373
+ globalRules: Map<string, RuleInfo>;
1374
+ /** Resolver for auto-inferring @property types from declaration values */
1375
+ propertyTypeResolver: PropertyTypeResolver;
1376
+ /**
1377
+ * className -> when the class was first noticed to be carrying nothing:
1378
+ * injection, or the first sweep that looked and did not find it on an
1379
+ * element. Cleared the moment a sweep finds it rendered again.
1380
+ *
1381
+ * Deliberately "when it was noticed", not "when it stopped being rendered".
1382
+ * Nothing observes the moment an element leaves, so a class that unmounted
1383
+ * just before a sweep and one that unmounted just after the previous sweep
1384
+ * would otherwise be treated differently — and the first would lose its
1385
+ * grace window entirely. Starting the clock at the sighting gives every
1386
+ * class the same full window, whenever it actually went.
1387
+ *
1388
+ * Written only by the sweep's own DOM scan and at injection, so rendering
1389
+ * never pays for it.
1390
+ */
1391
+ unusedSince: Map<string, number>;
1392
+ /**
1393
+ * Local `@keyframes` a class animates, by the name they were authored under.
1394
+ *
1395
+ * One reference is held per distinct set of steps, however many renders ask
1396
+ * for it, and the classes that animate it own that reference between them.
1397
+ * The last of them to be deleted releases it, so keyframes cannot outlive
1398
+ * every rule that referred to them, and repeat renders cannot pile up
1399
+ * references nobody gives back.
1400
+ */
1401
+ localKeyframes: Map<string, {
1402
+ name: string;
1403
+ dispose: () => void;
1404
+ owners: Set<string>;
1405
+ }>;
1406
+ /** Renders since the last scheduled sweep (per-root) */
1407
+ touchCount: number;
1408
+ /** How many entries from `window.__TASTY__` have been synced into this registry */
1409
+ serverClassSyncIndex: number;
1410
+ /** Whether `<style data-tasty-rsc>` tags have been scanned for class names */
1411
+ rscStylesScanned: boolean;
1412
+ /** Whether this root uses adoptedStyleSheets or <style> elements */
1413
+ injectionMode: InjectionMode;
1414
+ /**
1415
+ * Lazy feature-test for `@property` support, cached per registry.
1416
+ * - `undefined`: not yet probed.
1417
+ * - `true`: engine supports `@property`; rejections indicate user-authored
1418
+ * invalid rules and should warn.
1419
+ * - `false`: engine doesn't support `@property` (e.g., jsdom); rejections
1420
+ * are expected and warnings are suppressed.
1421
+ */
1422
+ atPropertySupported?: boolean;
1430
1423
  }
1431
- /**
1432
- * True condition (matches everything)
1433
- */
1434
- interface TrueCondition {
1435
- kind: 'true';
1424
+ type StyleRule = StyleResult;
1425
+ interface KeyframesInfo {
1426
+ name: string;
1427
+ sheetIndex: number;
1428
+ ruleIndex: number;
1429
+ /** Dev-only: full CSS text of the @keyframes rule; omitted in production */
1430
+ cssText?: string;
1436
1431
  }
1437
- /**
1438
- * False condition (matches nothing - skip this rule)
1439
- */
1440
- interface FalseCondition {
1441
- kind: 'false';
1432
+ type KeyframeStep = string | Record<string, string | number>;
1433
+ type KeyframesSteps = Record<string, KeyframeStep>;
1434
+ interface KeyframesResult {
1435
+ toString(): string;
1436
+ dispose: () => void;
1442
1437
  }
1443
- /**
1444
- * Union of all condition node types
1445
- */
1446
- type ConditionNode = StateCondition | CompoundCondition | TrueCondition | FalseCondition;
1447
- //#endregion
1448
- //#region src/states/index.d.ts
1449
- /**
1450
- * Parsed advanced state information
1451
- */
1452
- interface ParsedAdvancedState {
1453
- type: 'media' | 'container' | 'root' | 'parent' | 'own' | 'starting' | 'predefined' | 'modifier';
1454
- condition: string;
1455
- containerName?: string;
1456
- raw: string;
1457
- mediaType?: string;
1438
+ interface KeyframesCacheEntry {
1439
+ name: string;
1440
+ refCount: number;
1441
+ info: KeyframesInfo;
1442
+ /**
1443
+ * Queued sheet write, when `batchInjection` deferred the insertion. Present
1444
+ * only between `keyframes()` and the flush; disposing in that window cancels
1445
+ * the write instead of deleting a rule that was never inserted.
1446
+ */
1447
+ pending?: QueuedWrite;
1458
1448
  }
1459
1449
  /**
1460
- * Context for state parsing operations
1450
+ * Definition for a CSS @property at-rule.
1451
+ * Used to define custom property syntax, inheritance, and initial value.
1461
1452
  */
1462
- interface StateParserContext {
1463
- localPredefinedStates: Record<string, string>;
1464
- globalPredefinedStates: Record<string, string>;
1465
- isSubElement?: boolean;
1453
+ interface PropertyDefinition {
1454
+ /** CSS syntax string (e.g., '<color>', '<angle>', '<number>') */
1455
+ syntax?: string;
1456
+ /** Whether the property inherits (default: true) */
1457
+ inherits?: boolean;
1458
+ /** Initial value for the property */
1459
+ initialValue?: string | number;
1466
1460
  }
1467
1461
  /**
1468
- * At-rule context for CSS generation
1462
+ * Options for registering a CSS `@property`.
1463
+ * Extends {@link PropertyDefinition} with an optional injection root.
1469
1464
  */
1470
- interface AtRuleContext {
1471
- media?: string[];
1472
- container?: {
1473
- name?: string;
1474
- condition: string;
1475
- }[];
1476
- startingStyle?: boolean;
1477
- rootStates?: string[];
1478
- negatedRootStates?: string[];
1465
+ interface PropertyOptions extends PropertyDefinition {
1466
+ /** Shadow root or document to inject into */
1467
+ root?: Document | ShadowRoot;
1479
1468
  }
1480
1469
  /**
1481
- * Configure global predefined states
1482
- */
1483
- declare function setGlobalPredefinedStates(states: Record<string, string>): void;
1484
- /**
1485
- * Get global predefined states
1470
+ * A single parameter for a CSS @function at-rule.
1471
+ *
1472
+ * - `true` — a bare parameter with no type or default.
1473
+ * - `string` — a CSS type shorthand (e.g. `'<length>'`, `'<color>'`).
1474
+ * - object — full form with optional `syntax` (type) and `default` value.
1486
1475
  */
1487
- declare function getGlobalPredefinedStates(): Record<string, string>;
1476
+ type FunctionParameter = true | string | {
1477
+ syntax?: string;
1478
+ default?: string | number;
1479
+ };
1488
1480
  /**
1489
- * Create a state parser context from styles
1481
+ * Definition for a CSS @function at-rule (custom function).
1482
+ *
1483
+ * The descriptor body reads like a mini styles object: any `$name` key declares
1484
+ * a local variable (`--name`) whose value is parsed through the Tasty DSL.
1485
+ * `result` is the only required field.
1486
+ *
1487
+ * @example
1488
+ * ```ts
1489
+ * // @function --negative(--value) { result: calc(-1 * var(--value)); }
1490
+ * { args: ['$value'], result: '(-1 * $value)' }
1491
+ * ```
1490
1492
  */
1491
- declare function createStateParserContext(styles?: Styles, isSubElement?: boolean): StateParserContext;
1492
- //#endregion
1493
- //#region src/pipeline/parseStateKey.d.ts
1494
- interface ParseStateKeyOptions {
1495
- context?: StateParserContext;
1496
- isSubElement?: boolean;
1493
+ interface FunctionDefinition {
1494
+ /**
1495
+ * Ordered parameters. Array form lists bare parameter names (`['$value']`);
1496
+ * object form maps each parameter name to its type/default.
1497
+ */
1498
+ args?: string[] | Record<string, FunctionParameter>;
1499
+ /** Optional return type, e.g. `'<color>'`. */
1500
+ returns?: string;
1501
+ /** The `result:` descriptor value (parsed through the Tasty DSL). Required. */
1502
+ result: string;
1503
+ /** Local variables: any `$name` key declares `--name` in the body. */
1504
+ [localVar: `$${string}`]: string | number | undefined;
1497
1505
  }
1498
1506
  /**
1499
- * Parse a state key string into a ConditionNode
1500
- */
1501
- declare function parseStateKey(stateKey: string, options?: ParseStateKeyOptions): ConditionNode;
1502
- //#endregion
1503
- //#region src/pipeline/index.d.ts
1504
- /**
1505
- * Matches the old StyleResult interface for backward compatibility
1507
+ * Descriptors for a CSS @font-face at-rule.
1506
1508
  */
1507
- interface StyleResult {
1508
- selector: string;
1509
- declarations: string;
1510
- atRules?: string[];
1511
- needsClassName?: boolean;
1512
- rootPrefix?: string;
1513
- /** When true, declarations are wrapped in @starting-style { ... } inside the selector rule */
1514
- startingStyle?: boolean;
1509
+ interface FontFaceDescriptors {
1510
+ /** Required. URL(s) to the font file(s). */
1511
+ src: string;
1512
+ /** Font weight or range. Default: 'normal'. */
1513
+ fontWeight?: string | number;
1514
+ /** Font style. Default: 'normal'. */
1515
+ fontStyle?: 'normal' | 'italic' | 'oblique' | (string & {});
1516
+ /** Font stretch. Default: 'normal'. */
1517
+ fontStretch?: string;
1518
+ /** Loading behavior. Default: 'auto'. */
1519
+ fontDisplay?: 'auto' | 'block' | 'swap' | 'fallback' | 'optional';
1520
+ /** Unicode range to cover. */
1521
+ unicodeRange?: string;
1522
+ /** Ascent metric override. */
1523
+ ascentOverride?: string;
1524
+ /** Descent metric override. */
1525
+ descentOverride?: string;
1526
+ /** Line gap metric override. */
1527
+ lineGapOverride?: string;
1528
+ /** Size adjustment factor. */
1529
+ sizeAdjust?: string;
1530
+ /** OpenType feature settings. */
1531
+ fontFeatureSettings?: string;
1532
+ /** Font variation axis settings. */
1533
+ fontVariationSettings?: string;
1515
1534
  }
1535
+ /** Single descriptor or array of descriptors for multiple weights/styles. */
1536
+ type FontFaceInput = FontFaceDescriptors | FontFaceDescriptors[];
1516
1537
  /**
1517
- * Matches the old RenderResult interface for backward compatibility
1538
+ * Descriptors for a CSS @counter-style at-rule.
1518
1539
  */
1519
- interface RenderResult {
1520
- rules: StyleResult[];
1521
- className?: string;
1540
+ interface CounterStyleDescriptors {
1541
+ /** Required. Numbering algorithm. */
1542
+ system: 'cyclic' | 'numeric' | 'alphabetic' | 'symbolic' | 'additive' | 'fixed' | (string & {});
1543
+ /** Symbols for non-additive systems. */
1544
+ symbols?: string;
1545
+ /** Symbol-value pairs for additive system. */
1546
+ additiveSymbols?: string;
1547
+ /** String prepended to the marker. Default: "". */
1548
+ prefix?: string;
1549
+ /** String appended to the marker. Default: ". ". */
1550
+ suffix?: string;
1551
+ /** Negative-value wrapping (e.g., '"(" ")"'). */
1552
+ negative?: string;
1553
+ /** Counter range (e.g., 'infinite infinite'). */
1554
+ range?: string;
1555
+ /** Minimum marker width and pad symbol (e.g., '3 "0"'). */
1556
+ pad?: string;
1557
+ /** Fallback counter style name. */
1558
+ fallback?: string;
1559
+ /** Speech synthesis hint. */
1560
+ speakAs?: string;
1522
1561
  }
1523
- /**
1524
- * Check if a key is a CSS selector
1525
- */
1526
- declare function isSelector(key: string): boolean;
1527
- /**
1528
- * Options for renderStyles when using direct selector mode.
1529
- */
1530
- interface RenderStylesOptions {
1531
- /**
1532
- * Whether to double the class selector for increased specificity.
1533
- * When true, `.myClass` becomes `.myClass.myClass` for higher specificity.
1534
- *
1535
- * @default false - User-provided selectors are not doubled.
1536
- *
1537
- * Note: This only applies when a classNameOrSelector is provided.
1538
- * When renderStyles returns RenderResult with needsClassName=true,
1539
- * the injector handles doubling automatically.
1540
- */
1541
- doubleSelector?: boolean;
1562
+ interface RawCSSResult {
1563
+ dispose: () => void;
1542
1564
  }
1543
- /**
1544
- * Render styles to CSS rules.
1545
- *
1546
- * When called without classNameOrSelector, returns RenderResult with needsClassName=true.
1547
- * When called with a selector/className string, returns StyleResult[] for direct injection.
1548
- */
1549
- declare function renderStyles(styles?: Styles, classNameOrSelector?: undefined, options?: undefined, pipelineCacheKey?: string): RenderResult;
1550
- declare function renderStyles(styles: Styles | undefined, classNameOrSelector: string, options?: RenderStylesOptions): StyleResult[];
1551
1565
  //#endregion
1552
- export { StyleParser as $, ParsedColor as A, StyleRecipe as At, StyleValueStateMap as B, SuffixForSelector as C, PropertyDefinition as Ct, CSSMap as D, RuleInfo as Dt, AnyStyleHandler as E, RootRegistry as Et, StyleHandlerProps as F, resetStyleBatch as Ft, parseColor as G, getGlobalParser as H, StyleHandlerResult as I, getNamedColorHex as J, parseStyle as K, StyleMap as L, ResolvedStyleValue as M, QueuedWrite as Mt, StyleHandler as N, flushStyles as Nt, CUSTOM_UNITS as O, SheetInfo as Ot, StyleHandlerDefinition as P, hasPendingStyleWrites as Pt, strToRgb as Q, StylePropValue as R, StylesWithoutSelectors as S, KeyframesSteps as St, TastyPresetNames as T, RawCSSResult as Tt, getGlobalPredefinedTokens as U, filterMods as V, normalizeColorTokenValue as W, hexToRgb as X, getRgbValuesFromRgbaString as Y, hslToRgbValues as Z, NotSelector as _, InjectResult as _t, ParseStateKeyOptions as a, CSSProperties as at, Styles as b, KeyframesInfo as bt, ParsedAdvancedState as c, DisposeFunction as ct, getGlobalPredefinedStates as d, FunctionDefinition as dt, ParserOptions as et, setGlobalPredefinedStates as f, FunctionParameter as ft, NoType as g, InjectOptions as gt, ConfigTokens as h, GlobalInjectResult as ht, renderStyles as i, UnitHandler as it, RawStyleHandler as j, StyleRule as jt, DIRECTIONS as k, StyleInjectorConfig as kt, StateParserContext as l, FontFaceDescriptors as lt, ConfigTokenValue as m, GCOptions as mt, StyleResult as n, StyleDetails as nt, parseStateKey as o, CacheMetrics as ot, ConditionNode as p, GCConfig as pt, stringifyStyles as q, isSelector as r, StyleDetailsPart as rt, AtRuleContext as s, CounterStyleDescriptors as st, RenderResult as t, ProcessedStyle as tt, createStateParserContext as u, FontFaceInput as ut, RecipeStyles as v, InjectionMode as vt, TastyNamedColors as w, PropertyOptions as wt, StylesInterface as x, KeyframesResult as xt, Selector as y, KeyframesCacheEntry as yt, StyleValue as z };
1553
- //# sourceMappingURL=index-DpykQKO8.d.ts.map
1566
+ export { TastyNamedColors as $, resetStyleBatch as A, getGlobalPredefinedStates as B, SheetInfo as C, StyleParser as Ct, QueuedWrite as D, StyleDetailsPart as Dt, StyleUsage as E, StyleDetails as Et, parseStateKey as F, NoType as G, ConditionNode as H, AtRuleContext as I, Selector as J, NotSelector as K, ParsedAdvancedState as L, StyleResult as M, renderStyles as N, flushStyles as O, UnitHandler as Ot, ParseStateKeyOptions as P, SuffixForSelector as Q, StateParserContext as R, RuleInfo as S, stringifyStyles as St, StyleRule as T, ProcessedStyle as Tt, ConfigTokenValue as U, setGlobalPredefinedStates as V, ConfigTokens as W, StylesInterface as X, Styles as Y, StylesWithoutSelectors as Z, KeyframesSteps as _, getGlobalParser as _t, FontFaceInput as a, ParsedColor as at, RawCSSResult as b, parseColor as bt, GCConfig as c, StyleHandler as ct, InjectOptions as d, StyleHandlerResult as dt, TastyPresetNames as et, InjectResult as f, StyleMap as ft, KeyframesResult as g, filterMods as gt, KeyframesInfo as h, StyleValueStateMap as ht, FontFaceDescriptors as i, DIRECTIONS as it, RenderResult as j, hasPendingStyleWrites as k, CSSProperties as kt, GCOptions as l, StyleHandlerDefinition as lt, KeyframesCacheEntry as m, StyleValue as mt, CounterStyleDescriptors as n, CSSMap as nt, FunctionDefinition as o, RawStyleHandler as ot, InjectionMode as p, StylePropValue as pt, RecipeStyles as q, DisposeFunction as r, CUSTOM_UNITS as rt, FunctionParameter as s, ResolvedStyleValue as st, CacheMetrics as t, AnyStyleHandler as tt, GlobalInjectResult as u, StyleHandlerProps as ut, PropertyDefinition as v, getGlobalPredefinedTokens as vt, StyleInjectorConfig as w, ParserOptions as wt, RootRegistry as x, parseStyle as xt, PropertyOptions as y, normalizeColorTokenValue as yt, createStateParserContext as z };
1567
+ //# sourceMappingURL=types-JEY8PVYP.d.ts.map