@tenphi/tasty 0.0.0-snapshot.06c8a41 → 0.0.0-snapshot.07ea4a0
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.
- package/README.md +408 -385
- package/dist/babel-types-BKDTT4--.d.ts +18 -0
- package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
- package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
- package/dist/chunks/build-config-CW4k04_V.js +60 -0
- package/dist/chunks/build-config-CW4k04_V.js.map +1 -0
- package/dist/{collector-B3OsM252.js → chunks/collector-DKWQXEwN.js} +10 -127
- package/dist/chunks/collector-DKWQXEwN.js.map +1 -0
- package/dist/chunks/config-engine-DTglOA78.js +272 -0
- package/dist/chunks/config-engine-DTglOA78.js.map +1 -0
- package/dist/chunks/config-file-DlZXJMj8.js +25 -0
- package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
- package/dist/chunks/css-definitions-_C7C-daI.js +910 -0
- package/dist/chunks/css-definitions-_C7C-daI.js.map +1 -0
- package/dist/{css-resources-Cyl_axbI.js → chunks/css-resources-P7IBUUZs.js} +2 -9
- package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
- package/dist/chunks/debug-BapJwy9w.js +502 -0
- package/dist/chunks/debug-BapJwy9w.js.map +1 -0
- package/dist/chunks/dsl-DYSJc1-T.js +1383 -0
- package/dist/chunks/dsl-DYSJc1-T.js.map +1 -0
- package/dist/chunks/hydration-TRcz5vnk.js +41 -0
- package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
- package/dist/chunks/react-runtime-DayjnPuC.js +689 -0
- package/dist/chunks/react-runtime-DayjnPuC.js.map +1 -0
- package/dist/chunks/runtime-engine-IwGbSMb4.js +2432 -0
- package/dist/chunks/runtime-engine-IwGbSMb4.js.map +1 -0
- package/dist/chunks/runtime-state-CVrL92zX.js +152 -0
- package/dist/chunks/runtime-state-CVrL92zX.js.map +1 -0
- package/dist/{merge-styles-DuoZEsm9.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
- package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
- package/dist/chunks/style-engine-CVmNIjow.js +5521 -0
- package/dist/chunks/style-engine-CVmNIjow.js.map +1 -0
- package/dist/{css-writer-Bgowobbx.js → chunks/zero-engine-igHhzYM6.js} +65 -145
- package/dist/chunks/zero-engine-igHhzYM6.js.map +1 -0
- package/dist/{collector-BTVXj2hS.d.ts → collector-CTU-nl0g.d.ts} +6 -5
- package/dist/{config-LfIDmVHx.d.ts → config-CcxqSZI2.d.ts} +45 -40
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/hydrate-CRyjjAyl.d.ts +22 -0
- package/dist/{index-Bm9ltvdH.d.ts → index--GdqCPlp.d.ts} +271 -242
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -922
- package/dist/{merge-styles-BcLl1u_d.d.ts → merge-styles-DSkVc6CD.d.ts} +2 -3
- package/dist/ssr/astro-client.d.ts +1 -1
- package/dist/ssr/astro-client.js +1 -14
- package/dist/ssr/astro-client.js.map +1 -1
- package/dist/ssr/astro-middleware-extract-static.d.ts +1 -2
- package/dist/ssr/astro-middleware-extract-static.js +1 -1
- package/dist/ssr/astro-middleware-extract.d.ts +1 -2
- package/dist/ssr/astro-middleware-extract.js +1 -1
- package/dist/ssr/astro-middleware-static.d.ts +1 -2
- package/dist/ssr/astro-middleware-static.js +1 -12
- package/dist/ssr/astro-middleware-static.js.map +1 -1
- package/dist/ssr/astro-middleware.d.ts +1 -2
- package/dist/ssr/astro-middleware.js +1 -13
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +8 -16
- package/dist/ssr/astro.js +220 -1
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +2 -0
- package/dist/ssr/index.d.ts +5 -25
- package/dist/ssr/index.js +5 -5
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +3 -5
- package/dist/ssr/next-config.js +43 -35
- package/dist/ssr/next-config.js.map +1 -1
- package/dist/ssr/next.d.ts +3 -9
- package/dist/ssr/next.js +7 -38
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +8 -9
- package/dist/static/index.js +4 -22
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.d.ts +1 -2
- package/dist/{index-BmogEzTo.d.ts → types-DJEM_BOJ.d.ts} +852 -860
- package/dist/zero/babel.d.ts +67 -2
- package/dist/zero/babel.js +77 -140
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +62 -8
- package/dist/zero/index.js +24 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +4 -5
- package/dist/zero/next.js +3 -38
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +4 -1
- package/docs/adoption.md +25 -17
- package/docs/ai-agents.md +66 -33
- package/docs/comparison.md +9 -8
- package/docs/configuration.md +192 -60
- package/docs/debug.md +5 -7
- package/docs/design-system.md +117 -15
- package/docs/dsl.md +204 -82
- package/docs/getting-started.md +81 -22
- package/docs/injector.md +41 -40
- package/docs/methodology.md +48 -23
- package/docs/migration-v3.md +3 -3
- package/docs/pipeline.md +54 -27
- package/docs/plugins.md +22 -42
- package/docs/react-api.md +72 -9
- package/docs/runtime-benchmarks.md +146 -91
- package/docs/ssr.md +92 -66
- package/docs/styles.md +117 -31
- package/docs/tasty-static.md +162 -58
- package/package.json +96 -38
- package/dist/astro-CeYENy2x.js +0 -301
- package/dist/astro-CeYENy2x.js.map +0 -1
- package/dist/async-storage-DKK-wTD4.js +0 -44
- package/dist/async-storage-DKK-wTD4.js.map +0 -1
- package/dist/babel-DWCsafYw.d.ts +0 -83
- package/dist/collector-B3OsM252.js.map +0 -1
- package/dist/config-B3gPdCqd.js +0 -12421
- package/dist/config-B3gPdCqd.js.map +0 -1
- package/dist/context-CA8YKeMn.js +0 -24
- package/dist/context-CA8YKeMn.js.map +0 -1
- package/dist/core-DGm0CFHP.js +0 -1732
- package/dist/core-DGm0CFHP.js.map +0 -1
- package/dist/css-resources-Cyl_axbI.js.map +0 -1
- package/dist/css-writer-Bgowobbx.js.map +0 -1
- package/dist/format-global-rules-DklyaXv-.js +0 -22
- package/dist/format-global-rules-DklyaXv-.js.map +0 -1
- package/dist/format-rules-XRw9u7d4.js +0 -104
- package/dist/format-rules-XRw9u7d4.js.map +0 -1
- package/dist/hydrate-CNOmZprz.js +0 -37
- package/dist/hydrate-CNOmZprz.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-DE-OE76F.js +0 -535
- package/dist/keyframes-DE-OE76F.js.map +0 -1
- package/dist/merge-styles-DuoZEsm9.js.map +0 -1
- package/dist/resolve-recipes-H9NqOQuP.js +0 -144
- package/dist/resolve-recipes-H9NqOQuP.js.map +0 -1
- package/dist/ssr-collector-ref-COs_ioWl.js +0 -29
- package/dist/ssr-collector-ref-COs_ioWl.js.map +0 -1
|
@@ -1,643 +1,99 @@
|
|
|
1
1
|
import { Properties } from "csstype";
|
|
2
|
-
|
|
3
|
-
|
|
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/
|
|
5
|
+
//#region src/parser/types.d.ts
|
|
26
6
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
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
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
*
|
|
100
|
-
*
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
|
111
|
-
|
|
112
|
-
|
|
38
|
+
interface ProcessedStyle {
|
|
39
|
+
output: string;
|
|
40
|
+
groups: StyleDetails[];
|
|
113
41
|
}
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
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
|
-
|
|
63
|
+
clearCache(): void;
|
|
145
64
|
/**
|
|
146
|
-
*
|
|
147
|
-
* `insertRule()` per component. Mirrors `batchInjection` on the public
|
|
148
|
-
* `TastyConfig`.
|
|
149
|
-
* @default false
|
|
65
|
+
* Get the current units configuration.
|
|
150
66
|
*/
|
|
151
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* to describe. Kept so existing imports keep type-checking.
|
|
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.
|
|
160
86
|
*/
|
|
161
|
-
|
|
162
|
-
lastTouchedAt: number;
|
|
163
|
-
}
|
|
87
|
+
type StylePropValue<T = string> = StyleValue<T> | StyleValueStateMap<T>;
|
|
164
88
|
/**
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* touches, an idle callback is scheduled to evict unused styles above
|
|
169
|
-
* `capacity`, oldest first.
|
|
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}.
|
|
170
92
|
*/
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* How long a class is left alone after collection first notices nothing is
|
|
174
|
-
* carrying it, in milliseconds (default 10,000).
|
|
175
|
-
*
|
|
176
|
-
* Rendering is not commit-aware: a render can resolve a class and commit it a
|
|
177
|
-
* little later, and in between nothing on the page carries it. Rather than
|
|
178
|
-
* try to tell that apart from a class that is finished — which cannot be done
|
|
179
|
-
* from outside React — collection simply does not touch anything that was in
|
|
180
|
-
* use recently. A render would have to stay pending for the whole window to
|
|
181
|
-
* lose its rules, and it gets them back on its next render.
|
|
182
|
-
*/
|
|
183
|
-
grace?: number;
|
|
184
|
-
/**
|
|
185
|
-
* Number of touch events between automatic GC cycles.
|
|
186
|
-
* @default 1000
|
|
187
|
-
*/
|
|
188
|
-
touchInterval?: number;
|
|
189
|
-
/**
|
|
190
|
-
* Maximum number of unused styles to retain.
|
|
191
|
-
* GC evicts the oldest unused styles when this limit is exceeded.
|
|
192
|
-
* Pinned styles and DOM-live styles
|
|
193
|
-
* do not count against this limit.
|
|
194
|
-
* @default 1000
|
|
195
|
-
*/
|
|
196
|
-
capacity?: number;
|
|
197
|
-
}
|
|
93
|
+
type ResolvedStyleValue = StyleValue<string>;
|
|
198
94
|
/**
|
|
199
|
-
*
|
|
200
|
-
|
|
201
|
-
interface InjectOptions {
|
|
202
|
-
root?: Document | ShadowRoot;
|
|
203
|
-
/** Reuse the class already injected for this key instead of writing again. */
|
|
204
|
-
cacheKey?: string;
|
|
205
|
-
/**
|
|
206
|
-
* Pin the injected class (default `true`). A pinned class is never evicted by
|
|
207
|
-
* `gc()`, and the returned `dispose()` releases the pin. Pass `false` when the
|
|
208
|
-
* caller keeps no handle and the DOM is the only record that the class is in
|
|
209
|
-
* use — the render path does this, because a hook-free render has no unmount
|
|
210
|
-
* signal to dispose on.
|
|
211
|
-
*/
|
|
212
|
-
pin?: boolean;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Per-call options for gc().
|
|
216
|
-
*/
|
|
217
|
-
interface GCOptions {
|
|
218
|
-
root?: Document | ShadowRoot;
|
|
219
|
-
/** Bypass capacity threshold and remove ALL unused styles. */
|
|
220
|
-
force?: boolean;
|
|
221
|
-
}
|
|
222
|
-
interface RuleInfo {
|
|
223
|
-
className: string;
|
|
224
|
-
ruleIndex: number;
|
|
225
|
-
sheetIndex: number;
|
|
226
|
-
/** Dev-only: full CSS texts inserted for this class; omitted in production */
|
|
227
|
-
cssText?: string[];
|
|
228
|
-
/** Inclusive end index of the contiguous block of inserted rules for this className */
|
|
229
|
-
endRuleIndex?: number;
|
|
230
|
-
/** NEW: exact indices of all inserted rules for this className */
|
|
231
|
-
indices?: number[];
|
|
232
|
-
}
|
|
233
|
-
type InjectionMode = 'style-element' | 'adopted';
|
|
234
|
-
interface SheetInfo {
|
|
235
|
-
/** HTMLStyleElement used in style-element mode; null in adopted mode. */
|
|
236
|
-
sheet: HTMLStyleElement | null;
|
|
237
|
-
/** Constructable CSSStyleSheet used in adopted mode (ShadowRoot targets) */
|
|
238
|
-
constructableSheet?: CSSStyleSheet;
|
|
239
|
-
ruleCount: number;
|
|
240
|
-
holes: number[];
|
|
241
|
-
/**
|
|
242
|
-
* True when this sheet is written through `textContent` instead of CSSOM.
|
|
243
|
-
* Decided once at sheet creation so a sheet is never half CSSOM / half text.
|
|
244
|
-
*/
|
|
245
|
-
textMode?: boolean;
|
|
246
|
-
/**
|
|
247
|
-
* Inserted rule texts in rule-index order. Maintained only in text mode —
|
|
248
|
-
* it is what makes deletion possible there, since `textContent` cannot be
|
|
249
|
-
* edited rule-by-rule and has to be rebuilt.
|
|
250
|
-
*/
|
|
251
|
-
textRules?: string[];
|
|
252
|
-
}
|
|
253
|
-
interface CleanupStats {
|
|
254
|
-
timestamp: number;
|
|
255
|
-
classesDeleted: number;
|
|
256
|
-
cssSize: number;
|
|
257
|
-
rulesDeleted: number;
|
|
258
|
-
}
|
|
259
|
-
interface CacheMetrics {
|
|
260
|
-
hits: number;
|
|
261
|
-
misses: number;
|
|
262
|
-
bulkCleanups: number;
|
|
263
|
-
totalInsertions: number;
|
|
264
|
-
totalUnused: number;
|
|
265
|
-
stylesCleanedUp: number;
|
|
266
|
-
cleanupHistory: CleanupStats[];
|
|
267
|
-
startTime: number;
|
|
268
|
-
unusedHits?: number;
|
|
269
|
-
}
|
|
270
|
-
interface RootRegistry {
|
|
271
|
-
sheets: SheetInfo[];
|
|
272
|
-
/** className -> outstanding `inject()` references; 0 means nobody holds a handle */
|
|
273
|
-
pinCounts: Map<string, number>;
|
|
274
|
-
rules: Map<string, RuleInfo>;
|
|
275
|
-
/** Cache key to className mapping to avoid dual storage of RuleInfo objects */
|
|
276
|
-
cacheKeyToClassName: Map<string, string>;
|
|
277
|
-
/** Deduplication set of fully materialized CSS rules inserted into sheets */
|
|
278
|
-
ruleTextSet: Set<string>;
|
|
279
|
-
/** Performance metrics (optional) */
|
|
280
|
-
metrics?: CacheMetrics;
|
|
281
|
-
/** Keyframes cache by content hash -> entry */
|
|
282
|
-
keyframesCache: Map<string, KeyframesCacheEntry>;
|
|
283
|
-
/** Keyframes name to content hash mapping for collision detection */
|
|
284
|
-
keyframesNameToContent: Map<string, string>;
|
|
285
|
-
/** Counter for generating keyframes names like k0, k1, k2... */
|
|
286
|
-
keyframesCounter: number;
|
|
287
|
-
/** Map of injected @property names to their normalized declarations for tracking */
|
|
288
|
-
injectedProperties: Map<string, string>;
|
|
289
|
-
/** Content hashes of injected @font-face rules for deduplication */
|
|
290
|
-
injectedFontFaces: Set<string>;
|
|
291
|
-
/**
|
|
292
|
-
* Injected @counter-style rules. Maps the name to whether it was injected
|
|
293
|
-
* "strong" (`true`, the default — overrides) or "weak" (`false`, global
|
|
294
|
-
* `configure()` definitions that never clobber an existing rule).
|
|
295
|
-
*/
|
|
296
|
-
injectedCounterStyles: Map<string, boolean>;
|
|
297
|
-
/**
|
|
298
|
-
* Injected @function rules. Maps the CSS function name to whether it was
|
|
299
|
-
* injected "strong" (`true`, the default — overrides) or "weak" (`false`,
|
|
300
|
-
* global `configure()` definitions that never clobber an existing rule).
|
|
301
|
-
*/
|
|
302
|
-
injectedFunctions: Map<string, boolean>;
|
|
303
|
-
/** Global rules tracking for index adjustment */
|
|
304
|
-
globalRules: Map<string, RuleInfo>;
|
|
305
|
-
/** Resolver for auto-inferring @property types from declaration values */
|
|
306
|
-
propertyTypeResolver: PropertyTypeResolver;
|
|
307
|
-
/**
|
|
308
|
-
* className -> when the class was first noticed to be carrying nothing:
|
|
309
|
-
* injection, or the first sweep that looked and did not find it on an
|
|
310
|
-
* element. Cleared the moment a sweep finds it rendered again.
|
|
311
|
-
*
|
|
312
|
-
* Deliberately "when it was noticed", not "when it stopped being rendered".
|
|
313
|
-
* Nothing observes the moment an element leaves, so a class that unmounted
|
|
314
|
-
* just before a sweep and one that unmounted just after the previous sweep
|
|
315
|
-
* would otherwise be treated differently — and the first would lose its
|
|
316
|
-
* grace window entirely. Starting the clock at the sighting gives every
|
|
317
|
-
* class the same full window, whenever it actually went.
|
|
318
|
-
*
|
|
319
|
-
* Written only by the sweep's own DOM scan and at injection, so rendering
|
|
320
|
-
* never pays for it.
|
|
321
|
-
*/
|
|
322
|
-
unusedSince: Map<string, number>;
|
|
323
|
-
/**
|
|
324
|
-
* Local `@keyframes` a class animates, by the name they were authored under.
|
|
325
|
-
*
|
|
326
|
-
* One reference is held per distinct set of steps, however many renders ask
|
|
327
|
-
* for it, and the classes that animate it own that reference between them.
|
|
328
|
-
* The last of them to be deleted releases it, so keyframes cannot outlive
|
|
329
|
-
* every rule that referred to them, and repeat renders cannot pile up
|
|
330
|
-
* references nobody gives back.
|
|
331
|
-
*/
|
|
332
|
-
localKeyframes: Map<string, {
|
|
333
|
-
name: string;
|
|
334
|
-
dispose: () => void;
|
|
335
|
-
owners: Set<string>;
|
|
336
|
-
}>;
|
|
337
|
-
/** Renders since the last scheduled sweep (per-root) */
|
|
338
|
-
touchCount: number;
|
|
339
|
-
/** How many entries from `window.__TASTY__` have been synced into this registry */
|
|
340
|
-
serverClassSyncIndex: number;
|
|
341
|
-
/** Whether `<style data-tasty-rsc>` tags have been scanned for class names */
|
|
342
|
-
rscStylesScanned: boolean;
|
|
343
|
-
/** Whether this root uses adoptedStyleSheets or <style> elements */
|
|
344
|
-
injectionMode: InjectionMode;
|
|
345
|
-
/**
|
|
346
|
-
* Lazy feature-test for `@property` support, cached per registry.
|
|
347
|
-
* - `undefined`: not yet probed.
|
|
348
|
-
* - `true`: engine supports `@property`; rejections indicate user-authored
|
|
349
|
-
* invalid rules and should warn.
|
|
350
|
-
* - `false`: engine doesn't support `@property` (e.g., jsdom); rejections
|
|
351
|
-
* are expected and warnings are suppressed.
|
|
352
|
-
*/
|
|
353
|
-
atPropertySupported?: boolean;
|
|
354
|
-
}
|
|
355
|
-
type StyleRule = StyleResult;
|
|
356
|
-
interface KeyframesInfo {
|
|
357
|
-
name: string;
|
|
358
|
-
sheetIndex: number;
|
|
359
|
-
ruleIndex: number;
|
|
360
|
-
/** Dev-only: full CSS text of the @keyframes rule; omitted in production */
|
|
361
|
-
cssText?: string;
|
|
362
|
-
}
|
|
363
|
-
type KeyframeStep = string | Record<string, string | number>;
|
|
364
|
-
type KeyframesSteps = Record<string, KeyframeStep>;
|
|
365
|
-
interface KeyframesResult {
|
|
366
|
-
toString(): string;
|
|
367
|
-
dispose: () => void;
|
|
368
|
-
}
|
|
369
|
-
interface KeyframesCacheEntry {
|
|
370
|
-
name: string;
|
|
371
|
-
refCount: number;
|
|
372
|
-
info: KeyframesInfo;
|
|
373
|
-
/**
|
|
374
|
-
* Queued sheet write, when `batchInjection` deferred the insertion. Present
|
|
375
|
-
* only between `keyframes()` and the flush; disposing in that window cancels
|
|
376
|
-
* the write instead of deleting a rule that was never inserted.
|
|
377
|
-
*/
|
|
378
|
-
pending?: QueuedWrite;
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* Definition for a CSS @property at-rule.
|
|
382
|
-
* Used to define custom property syntax, inheritance, and initial value.
|
|
383
|
-
*/
|
|
384
|
-
interface PropertyDefinition {
|
|
385
|
-
/** CSS syntax string (e.g., '<color>', '<angle>', '<number>') */
|
|
386
|
-
syntax?: string;
|
|
387
|
-
/** Whether the property inherits (default: true) */
|
|
388
|
-
inherits?: boolean;
|
|
389
|
-
/** Initial value for the property */
|
|
390
|
-
initialValue?: string | number;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Options for registering a CSS `@property`.
|
|
394
|
-
* Extends {@link PropertyDefinition} with an optional injection root.
|
|
395
|
-
*/
|
|
396
|
-
interface PropertyOptions extends PropertyDefinition {
|
|
397
|
-
/** Shadow root or document to inject into */
|
|
398
|
-
root?: Document | ShadowRoot;
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* A single parameter for a CSS @function at-rule.
|
|
402
|
-
*
|
|
403
|
-
* - `true` — a bare parameter with no type or default.
|
|
404
|
-
* - `string` — a CSS type shorthand (e.g. `'<length>'`, `'<color>'`).
|
|
405
|
-
* - object — full form with optional `syntax` (type) and `default` value.
|
|
406
|
-
*/
|
|
407
|
-
type FunctionParameter = true | string | {
|
|
408
|
-
syntax?: string;
|
|
409
|
-
default?: string | number;
|
|
410
|
-
};
|
|
411
|
-
/**
|
|
412
|
-
* Definition for a CSS @function at-rule (custom function).
|
|
413
|
-
*
|
|
414
|
-
* The descriptor body reads like a mini styles object: any `$name` key declares
|
|
415
|
-
* a local variable (`--name`) whose value is parsed through the Tasty DSL.
|
|
416
|
-
* `result` is the only required field.
|
|
417
|
-
*
|
|
418
|
-
* @example
|
|
419
|
-
* ```ts
|
|
420
|
-
* // @function --negative(--value) { result: calc(-1 * var(--value)); }
|
|
421
|
-
* { args: ['$value'], result: '(-1 * $value)' }
|
|
422
|
-
* ```
|
|
423
|
-
*/
|
|
424
|
-
interface FunctionDefinition {
|
|
425
|
-
/**
|
|
426
|
-
* Ordered parameters. Array form lists bare parameter names (`['$value']`);
|
|
427
|
-
* object form maps each parameter name to its type/default.
|
|
428
|
-
*/
|
|
429
|
-
args?: string[] | Record<string, FunctionParameter>;
|
|
430
|
-
/** Optional return type, e.g. `'<color>'`. */
|
|
431
|
-
returns?: string;
|
|
432
|
-
/** The `result:` descriptor value (parsed through the Tasty DSL). Required. */
|
|
433
|
-
result: string;
|
|
434
|
-
/** Local variables: any `$name` key declares `--name` in the body. */
|
|
435
|
-
[localVar: `$${string}`]: string | number | undefined;
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Descriptors for a CSS @font-face at-rule.
|
|
439
|
-
*/
|
|
440
|
-
interface FontFaceDescriptors {
|
|
441
|
-
/** Required. URL(s) to the font file(s). */
|
|
442
|
-
src: string;
|
|
443
|
-
/** Font weight or range. Default: 'normal'. */
|
|
444
|
-
fontWeight?: string | number;
|
|
445
|
-
/** Font style. Default: 'normal'. */
|
|
446
|
-
fontStyle?: 'normal' | 'italic' | 'oblique' | (string & {});
|
|
447
|
-
/** Font stretch. Default: 'normal'. */
|
|
448
|
-
fontStretch?: string;
|
|
449
|
-
/** Loading behavior. Default: 'auto'. */
|
|
450
|
-
fontDisplay?: 'auto' | 'block' | 'swap' | 'fallback' | 'optional';
|
|
451
|
-
/** Unicode range to cover. */
|
|
452
|
-
unicodeRange?: string;
|
|
453
|
-
/** Ascent metric override. */
|
|
454
|
-
ascentOverride?: string;
|
|
455
|
-
/** Descent metric override. */
|
|
456
|
-
descentOverride?: string;
|
|
457
|
-
/** Line gap metric override. */
|
|
458
|
-
lineGapOverride?: string;
|
|
459
|
-
/** Size adjustment factor. */
|
|
460
|
-
sizeAdjust?: string;
|
|
461
|
-
/** OpenType feature settings. */
|
|
462
|
-
fontFeatureSettings?: string;
|
|
463
|
-
/** Font variation axis settings. */
|
|
464
|
-
fontVariationSettings?: string;
|
|
465
|
-
}
|
|
466
|
-
/** Single descriptor or array of descriptors for multiple weights/styles. */
|
|
467
|
-
type FontFaceInput = FontFaceDescriptors | FontFaceDescriptors[];
|
|
468
|
-
/**
|
|
469
|
-
* Descriptors for a CSS @counter-style at-rule.
|
|
470
|
-
*/
|
|
471
|
-
interface CounterStyleDescriptors {
|
|
472
|
-
/** Required. Numbering algorithm. */
|
|
473
|
-
system: 'cyclic' | 'numeric' | 'alphabetic' | 'symbolic' | 'additive' | 'fixed' | (string & {});
|
|
474
|
-
/** Symbols for non-additive systems. */
|
|
475
|
-
symbols?: string;
|
|
476
|
-
/** Symbol-value pairs for additive system. */
|
|
477
|
-
additiveSymbols?: string;
|
|
478
|
-
/** String prepended to the marker. Default: "". */
|
|
479
|
-
prefix?: string;
|
|
480
|
-
/** String appended to the marker. Default: ". ". */
|
|
481
|
-
suffix?: string;
|
|
482
|
-
/** Negative-value wrapping (e.g., '"(" ")"'). */
|
|
483
|
-
negative?: string;
|
|
484
|
-
/** Counter range (e.g., 'infinite infinite'). */
|
|
485
|
-
range?: string;
|
|
486
|
-
/** Minimum marker width and pad symbol (e.g., '3 "0"'). */
|
|
487
|
-
pad?: string;
|
|
488
|
-
/** Fallback counter style name. */
|
|
489
|
-
fallback?: string;
|
|
490
|
-
/** Speech synthesis hint. */
|
|
491
|
-
speakAs?: string;
|
|
492
|
-
}
|
|
493
|
-
interface RawCSSResult {
|
|
494
|
-
dispose: () => void;
|
|
495
|
-
}
|
|
496
|
-
//#endregion
|
|
497
|
-
//#region src/utils/css-types.d.ts
|
|
498
|
-
interface CSSProperties extends Properties<string | number> {}
|
|
499
|
-
//#endregion
|
|
500
|
-
//#region src/parser/types.d.ts
|
|
501
|
-
/**
|
|
502
|
-
* A part within a group, representing a slash-separated segment.
|
|
503
|
-
* For example, in `'2px solid #red / 4px'`, there are two parts:
|
|
504
|
-
* - Part 0: `2px solid #red`
|
|
505
|
-
* - Part 1: `4px`
|
|
506
|
-
*/
|
|
507
|
-
interface StyleDetailsPart {
|
|
508
|
-
mods: string[];
|
|
509
|
-
values: string[];
|
|
510
|
-
colors: string[];
|
|
511
|
-
all: string[];
|
|
512
|
-
output: string;
|
|
513
|
-
}
|
|
514
|
-
/**
|
|
515
|
-
* A group of style details, representing a comma-separated segment.
|
|
516
|
-
* Contains aggregated values from all parts for backward compatibility,
|
|
517
|
-
* plus the structured `parts` array for handlers that need slash separation.
|
|
518
|
-
*/
|
|
519
|
-
interface StyleDetails {
|
|
520
|
-
input: string;
|
|
521
|
-
output: string;
|
|
522
|
-
/** Aggregated mods from all parts (backward compatible) */
|
|
523
|
-
mods: string[];
|
|
524
|
-
/** Aggregated values from all parts (backward compatible) */
|
|
525
|
-
values: string[];
|
|
526
|
-
/** Aggregated colors from all parts (backward compatible) */
|
|
527
|
-
colors: string[];
|
|
528
|
-
/** Aggregated all tokens from all parts (backward compatible) */
|
|
529
|
-
all: string[];
|
|
530
|
-
/** Slash-separated parts within this group */
|
|
531
|
-
parts: StyleDetailsPart[];
|
|
532
|
-
}
|
|
533
|
-
interface ProcessedStyle {
|
|
534
|
-
output: string;
|
|
535
|
-
groups: StyleDetails[];
|
|
536
|
-
}
|
|
537
|
-
type UnitHandler = (scalar: number) => string;
|
|
538
|
-
interface ParserOptions {
|
|
539
|
-
functions?: Record<string, (parsed: StyleDetails[]) => string>;
|
|
540
|
-
units?: Record<string, string | UnitHandler>;
|
|
541
|
-
cacheSize?: number;
|
|
542
|
-
}
|
|
543
|
-
//#endregion
|
|
544
|
-
//#region src/parser/parser.d.ts
|
|
545
|
-
declare class StyleParser {
|
|
546
|
-
private opts;
|
|
547
|
-
private cache;
|
|
548
|
-
constructor(opts?: ParserOptions);
|
|
549
|
-
process(src: string): ProcessedStyle;
|
|
550
|
-
setFunctions(functions: Required<ParserOptions>['functions']): void;
|
|
551
|
-
setUnits(units: Required<ParserOptions>['units']): void;
|
|
552
|
-
updateOptions(patch: Partial<ParserOptions>): void;
|
|
553
|
-
/**
|
|
554
|
-
* Clear the parser cache.
|
|
555
|
-
* Call this when external state that affects parsing results has changed
|
|
556
|
-
* (e.g., predefined tokens).
|
|
557
|
-
*/
|
|
558
|
-
clearCache(): void;
|
|
559
|
-
/**
|
|
560
|
-
* Get the current units configuration.
|
|
561
|
-
*/
|
|
562
|
-
getUnits(): ParserOptions['units'];
|
|
563
|
-
}
|
|
564
|
-
//#endregion
|
|
565
|
-
//#region src/utils/color-math.d.ts
|
|
566
|
-
/**
|
|
567
|
-
* Consolidated color conversion math.
|
|
568
|
-
*
|
|
569
|
-
* Single source of truth for all color space conversions used across the
|
|
570
|
-
* library: sRGB gamma, HSL, OKLab, OKLCH, OKHSL, hex parsing, named
|
|
571
|
-
* colors, and CSS string converters.
|
|
572
|
-
*
|
|
573
|
-
* This module has zero internal imports — it is a leaf dependency.
|
|
574
|
-
*
|
|
575
|
-
* Reference: https://bottosson.github.io/posts/oklab/
|
|
576
|
-
*/
|
|
577
|
-
type Vec3 = [number, number, number];
|
|
578
|
-
/**
|
|
579
|
-
* sRGB gamma to linear. Only the sRGB-to-OKLab direction needs it, so this is
|
|
580
|
-
* test-only for the same reason as {@link srgbToOkhsl} — the forward path goes
|
|
581
|
-
* through {@link srgbLinearToGamma} instead.
|
|
582
|
-
*/
|
|
583
|
-
/**
|
|
584
|
-
* HSL to RGB.
|
|
585
|
-
* Algorithm from CSS Color 4 spec.
|
|
586
|
-
*
|
|
587
|
-
* @param h - Hue in degrees (0-360)
|
|
588
|
-
* @param s - Saturation (0-1)
|
|
589
|
-
* @param l - Lightness (0-1)
|
|
590
|
-
* @returns RGB values in 0-255 range (may have fractional values)
|
|
591
|
-
*/
|
|
592
|
-
declare function hslToRgbValues(h: number, s: number, l: number): Vec3;
|
|
593
|
-
declare function getNamedColorHex(): Map<string, string>;
|
|
594
|
-
/**
|
|
595
|
-
* Convert hex color string to `rgb()` CSS string.
|
|
596
|
-
* Supports 3, 4, 6, and 8 character hex values (with or without `#`).
|
|
597
|
-
*/
|
|
598
|
-
declare function hexToRgb(hex: string): string | null;
|
|
599
|
-
/**
|
|
600
|
-
* Extract RGB values from an `rgb()`/`rgba()` string.
|
|
601
|
-
* Supports comma-separated, space-separated, fractional, percentage,
|
|
602
|
-
* and slash alpha notation.
|
|
603
|
-
*
|
|
604
|
-
* @returns Array of RGB values (0-255 range), converting percentages as needed.
|
|
605
|
-
*/
|
|
606
|
-
declare function getRgbValuesFromRgbaString(str: string): number[];
|
|
607
|
-
/**
|
|
608
|
-
* Convert any recognized color string to an `rgb()` CSS string.
|
|
609
|
-
* Handles hex, `okhsl()`, `okhst()`, `hsl()`/`hsla()`, named CSS colors,
|
|
610
|
-
* and `rgb()`/`rgba()` pass-through.
|
|
611
|
-
*/
|
|
612
|
-
declare function strToRgb(color: string, _ignoreAlpha?: boolean): string | null | undefined;
|
|
613
|
-
//#endregion
|
|
614
|
-
//#region src/utils/styles.d.ts
|
|
615
|
-
type StyleValue<T = string> = T | boolean | number | null | undefined;
|
|
616
|
-
/**
|
|
617
|
-
* Normalize a color token value.
|
|
618
|
-
* - Boolean `true` is converted to `'transparent'`
|
|
619
|
-
* - Boolean `false` returns `null` (signals the token should be skipped)
|
|
620
|
-
* - Other values are returned as-is
|
|
621
|
-
*
|
|
622
|
-
* @param value - The raw token value
|
|
623
|
-
* @returns Normalized value or null if the token should be skipped
|
|
624
|
-
*/
|
|
625
|
-
declare function normalizeColorTokenValue<T>(value: T | boolean): T | 'transparent' | null;
|
|
626
|
-
type StyleValueStateMap<T = string> = Record<string, StyleValue<T> | '@inherit'>;
|
|
627
|
-
/**
|
|
628
|
-
* Combined type for style values that can be either a direct value or a state map.
|
|
629
|
-
* Use this for component props that accept style values.
|
|
630
|
-
*/
|
|
631
|
-
type StylePropValue<T = string> = StyleValue<T> | StyleValueStateMap<T>;
|
|
632
|
-
/**
|
|
633
|
-
* One dependency value as a style handler receives it: already resolved for a
|
|
634
|
-
* single state, but still the **raw authored DSL string** (`'2x'`, `'#purple.5'`).
|
|
635
|
-
* Handlers parse it themselves via {@link parseStyle} / {@link parseColor}.
|
|
636
|
-
*/
|
|
637
|
-
type ResolvedStyleValue = StyleValue<string>;
|
|
638
|
-
/**
|
|
639
|
-
* The dependency map a handler receives — one resolved value per style name in
|
|
640
|
-
* its `__lookupStyles`.
|
|
95
|
+
* The dependency map a handler receives — one resolved value per style name in
|
|
96
|
+
* its `__lookupStyles`.
|
|
641
97
|
*/
|
|
642
98
|
type StyleHandlerProps<TDeps extends string = string> = Partial<Record<TDeps, ResolvedStyleValue>>;
|
|
643
99
|
/**
|
|
@@ -648,7 +104,8 @@ type StyleHandlerProps<TDeps extends string = string> = Partial<Record<TDeps, Re
|
|
|
648
104
|
* numbers are accepted. `$` is reserved as a selector suffix.
|
|
649
105
|
*/
|
|
650
106
|
type CSSMap = {
|
|
651
|
-
/** Selector suffix (or suffixes) these declarations apply to, e.g. `'& > *'`.
|
|
107
|
+
/** Selector suffix (or suffixes) these declarations apply to, e.g. `'& > *'`. */
|
|
108
|
+
$?: string | string[];
|
|
652
109
|
} & Record<string, string | number | (string | number)[] | undefined>;
|
|
653
110
|
type StyleHandlerResult = CSSMap | CSSMap[] | null | void;
|
|
654
111
|
type RawStyleHandler<TProps extends object = StyleHandlerProps> = (props: TProps) => StyleHandlerResult;
|
|
@@ -700,10 +157,9 @@ declare const DIRECTIONS: string[];
|
|
|
700
157
|
*/
|
|
701
158
|
declare function getGlobalParser(): StyleParser;
|
|
702
159
|
/**
|
|
703
|
-
* Get the current global predefined tokens.
|
|
704
|
-
* Returns null if no tokens are configured.
|
|
160
|
+
* Get the current global predefined tokens, including built-in defaults.
|
|
705
161
|
*/
|
|
706
|
-
declare function getGlobalPredefinedTokens(): Record<string, string
|
|
162
|
+
declare function getGlobalPredefinedTokens(): Record<string, string>;
|
|
707
163
|
/**
|
|
708
164
|
*
|
|
709
165
|
* @param {String} value
|
|
@@ -716,7 +172,7 @@ declare function parseStyle(value: StyleValue): ProcessedStyle;
|
|
|
716
172
|
* Optimized to avoid heavy parseStyle calls for simple color patterns.
|
|
717
173
|
*/
|
|
718
174
|
declare function parseColor(val: string, ignoreError?: boolean): ParsedColor;
|
|
719
|
-
declare function filterMods(mods: string[], allowedMods: string[]): string[];
|
|
175
|
+
declare function filterMods(mods: string[], allowedMods: readonly string[]): string[];
|
|
720
176
|
declare function stringifyStyles(styles: unknown): string;
|
|
721
177
|
//#endregion
|
|
722
178
|
//#region src/styles/types.d.ts
|
|
@@ -759,7 +215,11 @@ type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
|
759
215
|
type OpaquePercentage = '' | `.${Digit}` | `.${Digit}${Digit}` | '.100';
|
|
760
216
|
type ColorValue = `#${NamedColor}${OpaquePercentage}` | `rgb(${string})` | `hsl(${string})` | `okhsl(${string})` | `oklch(${string})` | (string & {});
|
|
761
217
|
type NoType = false | null | undefined;
|
|
762
|
-
interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font' | 'outline' | 'type' | 'gap' | 'padding' | 'margin' | 'width' | 'height' | 'border' | 'transition' | 'placeContent' | 'placeItems' | 'scrollMargin' | 'scrollMarginTop' | 'scrollMarginRight' | 'scrollMarginBottom' | 'scrollMarginLeft' | '
|
|
218
|
+
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'> {
|
|
219
|
+
overscrollBehaviorBlock?: CSSProperties['overscrollBehaviorBlock'] | 'chain';
|
|
220
|
+
overscrollBehaviorInline?: CSSProperties['overscrollBehaviorInline'] | 'chain';
|
|
221
|
+
overscrollBehaviorX?: CSSProperties['overscrollBehaviorX'] | 'chain';
|
|
222
|
+
overscrollBehaviorY?: CSSProperties['overscrollBehaviorY'] | 'chain';
|
|
763
223
|
/**
|
|
764
224
|
* @deprecated Use `flow` style instead.
|
|
765
225
|
*/
|
|
@@ -786,7 +246,8 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
|
|
|
786
246
|
* - `fill="okhsl(200 100% 50%)"` // perceptually uniform OKHSL color
|
|
787
247
|
* - `fill="oklch(0.7 0.15 200)"` // OKLCH color
|
|
788
248
|
* - `fill="#primary #secondary"` // double color (second as foreground overlay)
|
|
789
|
-
*
|
|
249
|
+
*
|
|
250
|
+
* `fill={false}` sets no fill. `fill={true}` names no color and is ignored.
|
|
790
251
|
*/
|
|
791
252
|
fill?: ColorValue | boolean;
|
|
792
253
|
/**
|
|
@@ -911,6 +372,10 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
|
|
|
911
372
|
* - `padding={true}` // default padding on all sides
|
|
912
373
|
*/
|
|
913
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;
|
|
914
379
|
/**
|
|
915
380
|
* Shorthand for element margin. Supports custom units, directional modifiers, and design-system-driven defaults.
|
|
916
381
|
*
|
|
@@ -925,6 +390,10 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
|
|
|
925
390
|
* - `margin={true}` // default margin on all sides
|
|
926
391
|
*/
|
|
927
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;
|
|
928
397
|
/**
|
|
929
398
|
* Concise shorthand for setting element width, including min-width and max-width. Supports custom units and advanced sizing keywords.
|
|
930
399
|
*
|
|
@@ -956,6 +425,16 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
|
|
|
956
425
|
* - `height={true}` // height: auto
|
|
957
426
|
*/
|
|
958
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;
|
|
959
438
|
/**
|
|
960
439
|
* Shorthand for border width, style, and color. Supports directional modifiers and design-system defaults.
|
|
961
440
|
*
|
|
@@ -977,6 +456,10 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
|
|
|
977
456
|
* custom property directly, name it `$name-color`.
|
|
978
457
|
*/
|
|
979
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;
|
|
980
463
|
/**
|
|
981
464
|
* Powerful shorthand for CSS transitions using semantic names and design tokens. Supports grouped transitions for common UI effects.
|
|
982
465
|
*
|
|
@@ -984,10 +467,10 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
|
|
|
984
467
|
* Multiple transitions: separated by commas
|
|
985
468
|
*
|
|
986
469
|
* Examples:
|
|
987
|
-
* - `transition="fill
|
|
988
|
-
* - `transition="fade
|
|
989
|
-
* - `transition="theme
|
|
990
|
-
* - `transition="preset
|
|
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
|
|
991
474
|
*/
|
|
992
475
|
transition?: CSSProperties['transition'] | string;
|
|
993
476
|
/**
|
|
@@ -1017,7 +500,7 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
|
|
|
1017
500
|
* Corner modifiers: `top-left`, `top-right`, `bottom-right`, `bottom-left` — a single corner
|
|
1018
501
|
*
|
|
1019
502
|
* Examples:
|
|
1020
|
-
* - `radius="2r"` // border-radius:
|
|
503
|
+
* - `radius="2r"` // border-radius: 12px
|
|
1021
504
|
* - `radius={true}` // default radius (1r)
|
|
1022
505
|
* - `radius="round"` // fully rounded (9999rem)
|
|
1023
506
|
* - `radius="leaf"` // asymmetric leaf shape
|
|
@@ -1182,8 +665,23 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
|
|
|
1182
665
|
scrollMarginRight?: string | number | boolean;
|
|
1183
666
|
scrollMarginBottom?: string | number | boolean;
|
|
1184
667
|
scrollMarginLeft?: string | number | boolean;
|
|
1185
|
-
|
|
1186
|
-
|
|
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;
|
|
1187
685
|
/**
|
|
1188
686
|
* Shorthand for `top`, `right`, `bottom`, and `left` offsets. Supports custom units, directional modifiers, and positioning.
|
|
1189
687
|
*
|
|
@@ -1205,6 +703,10 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
|
|
|
1205
703
|
* insets the sides by `4x`. Without `dock` a second value is ignored.
|
|
1206
704
|
*/
|
|
1207
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;
|
|
1208
710
|
/**
|
|
1209
711
|
* Local keyframes definitions for this component.
|
|
1210
712
|
* Keys are animation names, values are keyframes step definitions.
|
|
@@ -1276,300 +778,790 @@ interface StylesInterface extends Omit<CSSProperties, 'color' | 'fill' | 'font'
|
|
|
1276
778
|
*/
|
|
1277
779
|
recipe?: string;
|
|
1278
780
|
}
|
|
1279
|
-
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';
|
|
1280
|
-
type Selector = `${SuffixForSelector}${string}`;
|
|
1281
|
-
type NotSelector = Exclude<string, Selector | keyof StylesInterface>;
|
|
1282
|
-
/** Special style keys that should not be wrapped in StyleValue/StyleValueStateMap */
|
|
1283
|
-
type SpecialStyleKeys = '@keyframes' | '@property' | '@font-face' | '@counter-style' | '@function' | 'recipe';
|
|
1284
|
-
type StylesWithoutSelectors = { [key in keyof StylesInterface as key extends SpecialStyleKeys ? never : key]?: StyleValue<StylesInterface[key]> | StyleValueStateMap<StylesInterface[key]
|
|
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
|
+
}
|
|
1285
955
|
/**
|
|
1286
|
-
*
|
|
1287
|
-
* Supports local predefined states (`@name`), vendor-prefixed CSS properties (`-webkit-*`),
|
|
1288
|
-
* CSS custom properties (`$name`), and color tokens (`#name`).
|
|
1289
|
-
* Unlike StylesIndexSignature, does NOT allow sub-element selectors (recipes are flat).
|
|
956
|
+
* True condition (matches everything)
|
|
1290
957
|
*/
|
|
1291
|
-
|
|
958
|
+
interface TrueCondition {
|
|
959
|
+
kind: 'true';
|
|
960
|
+
}
|
|
1292
961
|
/**
|
|
1293
|
-
*
|
|
1294
|
-
* Like StylesWithoutSelectors but also allows `@keyframes`, `@property`,
|
|
1295
|
-
* local predefined states, and vendor-prefixed CSS properties.
|
|
1296
|
-
* Excludes `recipe` to prevent recursive references.
|
|
962
|
+
* False condition (matches nothing - skip this rule)
|
|
1297
963
|
*/
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
'@property'?: StylesInterface['@property'];
|
|
1301
|
-
'@font-face'?: StylesInterface['@font-face'];
|
|
1302
|
-
'@counter-style'?: StylesInterface['@counter-style'];
|
|
1303
|
-
'@function'?: StylesInterface['@function'];
|
|
1304
|
-
};
|
|
1305
|
-
/** Special properties that are not regular style values */
|
|
1306
|
-
interface SpecialStyleProperties {
|
|
1307
|
-
'@keyframes'?: StylesInterface['@keyframes'];
|
|
1308
|
-
'@property'?: StylesInterface['@property'];
|
|
1309
|
-
'@font-face'?: StylesInterface['@font-face'];
|
|
1310
|
-
'@counter-style'?: StylesInterface['@counter-style'];
|
|
1311
|
-
'@function'?: StylesInterface['@function'];
|
|
1312
|
-
recipe?: StylesInterface['recipe'];
|
|
964
|
+
interface FalseCondition {
|
|
965
|
+
kind: 'false';
|
|
1313
966
|
}
|
|
1314
|
-
/**
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
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;
|
|
1322
982
|
}
|
|
1323
|
-
type Styles = StylesWithoutSelectors & SpecialStyleProperties & StylesIndexSignature;
|
|
1324
983
|
/**
|
|
1325
|
-
*
|
|
1326
|
-
* Can be a direct value or a state map for responsive/theme-aware tokens.
|
|
984
|
+
* Context for state parsing operations
|
|
1327
985
|
*/
|
|
1328
|
-
|
|
986
|
+
interface StateParserContext {
|
|
987
|
+
localPredefinedStates: Record<string, string>;
|
|
988
|
+
globalPredefinedStates: Record<string, string>;
|
|
989
|
+
isSubElement?: boolean;
|
|
990
|
+
}
|
|
1329
991
|
/**
|
|
1330
|
-
*
|
|
1331
|
-
* Keys must start with `$` (value tokens) or `#` (color tokens).
|
|
1332
|
-
*
|
|
1333
|
-
* - `$name` keys become `--name` CSS custom properties
|
|
1334
|
-
* - `#name` keys become `--name-color` properties
|
|
992
|
+
* At-rule context for CSS generation
|
|
1335
993
|
*/
|
|
1336
|
-
|
|
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;
|
|
1337
1016
|
//#endregion
|
|
1338
|
-
//#region src/pipeline/
|
|
1017
|
+
//#region src/pipeline/parseStateKey.d.ts
|
|
1018
|
+
interface ParseStateKeyOptions {
|
|
1019
|
+
context?: StateParserContext;
|
|
1020
|
+
isSubElement?: boolean;
|
|
1021
|
+
}
|
|
1339
1022
|
/**
|
|
1340
|
-
*
|
|
1341
|
-
*
|
|
1342
|
-
* Core data structures for representing style conditions as an abstract syntax tree.
|
|
1343
|
-
* Used throughout the pipeline for parsing, simplification, and CSS generation.
|
|
1023
|
+
* Parse a state key string into a ConditionNode
|
|
1344
1024
|
*/
|
|
1025
|
+
declare function parseStateKey(stateKey: string, options?: ParseStateKeyOptions): ConditionNode;
|
|
1026
|
+
//#endregion
|
|
1027
|
+
//#region src/pipeline/index.d.ts
|
|
1345
1028
|
/**
|
|
1346
|
-
*
|
|
1029
|
+
* Matches the old StyleResult interface for backward compatibility
|
|
1347
1030
|
*/
|
|
1348
|
-
interface
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
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;
|
|
1353
1039
|
}
|
|
1354
1040
|
/**
|
|
1355
|
-
*
|
|
1041
|
+
* Matches the old RenderResult interface for backward compatibility
|
|
1356
1042
|
*/
|
|
1357
|
-
interface
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
value?: string;
|
|
1361
|
-
operator?: '=' | '^=' | '$=' | '*=';
|
|
1043
|
+
interface RenderResult {
|
|
1044
|
+
rules: StyleResult[];
|
|
1045
|
+
className?: string;
|
|
1362
1046
|
}
|
|
1363
1047
|
/**
|
|
1364
|
-
*
|
|
1048
|
+
* Options for renderStyles when using direct selector mode.
|
|
1365
1049
|
*/
|
|
1366
|
-
interface
|
|
1367
|
-
|
|
1368
|
-
|
|
1050
|
+
interface RenderStylesOptions {
|
|
1051
|
+
/**
|
|
1052
|
+
* Whether to double the class selector for increased specificity.
|
|
1053
|
+
* When true, `.myClass` becomes `.myClass.myClass` for higher specificity.
|
|
1054
|
+
*
|
|
1055
|
+
* @default false - User-provided selectors are not doubled.
|
|
1056
|
+
*
|
|
1057
|
+
* Note: This only applies when a classNameOrSelector is provided.
|
|
1058
|
+
* When renderStyles returns RenderResult with needsClassName=true,
|
|
1059
|
+
* the injector handles doubling automatically.
|
|
1060
|
+
*/
|
|
1061
|
+
doubleSelector?: boolean;
|
|
1369
1062
|
}
|
|
1370
1063
|
/**
|
|
1371
|
-
*
|
|
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.
|
|
1372
1068
|
*/
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
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
|
|
1073
|
+
/**
|
|
1074
|
+
* PropertyTypeResolver
|
|
1075
|
+
*
|
|
1076
|
+
* Automatically infers CSS @property types from custom property values.
|
|
1077
|
+
* Supports deferred resolution for var() reference chains of arbitrary depth.
|
|
1078
|
+
*/
|
|
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;
|
|
1084
|
+
/**
|
|
1085
|
+
* Scan CSS declarations and auto-register @property for custom properties
|
|
1086
|
+
* whose types can be inferred from their values.
|
|
1087
|
+
*/
|
|
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;
|
|
1377
1092
|
}
|
|
1093
|
+
//#endregion
|
|
1094
|
+
//#region src/injector/batch.d.ts
|
|
1378
1095
|
/**
|
|
1379
|
-
*
|
|
1096
|
+
* Deferred CSSOM writes ("batched injection").
|
|
1097
|
+
*
|
|
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`, ...).
|
|
1380
1147
|
*/
|
|
1381
|
-
interface
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
featureValue?: string;
|
|
1389
|
-
mediaType?: 'print' | 'screen' | 'all' | 'speech';
|
|
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;
|
|
1390
1155
|
}
|
|
1156
|
+
/** Whether any write is still waiting to hit a stylesheet. */
|
|
1157
|
+
declare function hasPendingStyleWrites(): boolean;
|
|
1391
1158
|
/**
|
|
1392
|
-
*
|
|
1159
|
+
* Drain every pending sheet write, in insertion order.
|
|
1160
|
+
*
|
|
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.
|
|
1393
1165
|
*/
|
|
1394
|
-
|
|
1395
|
-
type: 'container';
|
|
1396
|
-
subtype: 'dimension' | 'style' | 'raw';
|
|
1397
|
-
containerName?: string;
|
|
1398
|
-
dimension?: 'width' | 'height' | 'inline-size' | 'block-size';
|
|
1399
|
-
lowerBound?: NumericBound;
|
|
1400
|
-
upperBound?: NumericBound;
|
|
1401
|
-
property?: string;
|
|
1402
|
-
propertyValue?: string;
|
|
1403
|
-
rawCondition?: string;
|
|
1404
|
-
}
|
|
1166
|
+
declare function flushStyles(): void;
|
|
1405
1167
|
/**
|
|
1406
|
-
*
|
|
1168
|
+
* Drop every pending write without applying it. Test helper — production code
|
|
1169
|
+
* should call `flushStyles()` instead.
|
|
1407
1170
|
*/
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1171
|
+
declare function resetStyleBatch(): void;
|
|
1172
|
+
//#endregion
|
|
1173
|
+
//#region src/injector/types.d.ts
|
|
1174
|
+
declare global {
|
|
1175
|
+
interface Window {
|
|
1176
|
+
__TASTY__?: string[];
|
|
1177
|
+
}
|
|
1411
1178
|
}
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1179
|
+
interface InjectResult {
|
|
1180
|
+
className: string;
|
|
1181
|
+
dispose: () => void;
|
|
1182
|
+
}
|
|
1183
|
+
interface GlobalInjectResult {
|
|
1184
|
+
dispose: () => void;
|
|
1185
|
+
}
|
|
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';
|
|
1419
1221
|
}
|
|
1420
1222
|
/**
|
|
1421
|
-
*
|
|
1223
|
+
* Per-className usage tracking for GC.
|
|
1422
1224
|
*/
|
|
1423
|
-
interface OwnCondition extends BaseStateCondition {
|
|
1424
|
-
type: 'own';
|
|
1425
|
-
innerCondition: ConditionNode;
|
|
1426
|
-
}
|
|
1427
1225
|
/**
|
|
1428
|
-
*
|
|
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.
|
|
1429
1229
|
*/
|
|
1430
|
-
interface
|
|
1431
|
-
|
|
1230
|
+
interface StyleUsage {
|
|
1231
|
+
lastTouchedAt: number;
|
|
1432
1232
|
}
|
|
1433
1233
|
/**
|
|
1434
|
-
*
|
|
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.
|
|
1435
1239
|
*/
|
|
1436
|
-
interface
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
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;
|
|
1440
1266
|
}
|
|
1441
1267
|
/**
|
|
1442
|
-
*
|
|
1268
|
+
* Per-call options for inject().
|
|
1443
1269
|
*/
|
|
1444
|
-
|
|
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;
|
|
1282
|
+
}
|
|
1445
1283
|
/**
|
|
1446
|
-
*
|
|
1284
|
+
* Per-call options for gc().
|
|
1447
1285
|
*/
|
|
1448
|
-
interface
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1286
|
+
interface GCOptions {
|
|
1287
|
+
root?: Document | ShadowRoot;
|
|
1288
|
+
/** Bypass capacity threshold and remove ALL unused styles. */
|
|
1289
|
+
force?: boolean;
|
|
1290
|
+
}
|
|
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[];
|
|
1301
|
+
}
|
|
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[];
|
|
1321
|
+
}
|
|
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;
|
|
1452
1423
|
}
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
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;
|
|
1458
1431
|
}
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1432
|
+
type KeyframeStep = string | Record<string, string | number>;
|
|
1433
|
+
type KeyframesSteps = Record<string, KeyframeStep>;
|
|
1434
|
+
interface KeyframesResult {
|
|
1435
|
+
toString(): string;
|
|
1436
|
+
dispose: () => void;
|
|
1464
1437
|
}
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
type: 'media' | 'container' | 'root' | 'parent' | 'own' | 'starting' | 'predefined' | 'modifier';
|
|
1476
|
-
condition: string;
|
|
1477
|
-
containerName?: string;
|
|
1478
|
-
raw: string;
|
|
1479
|
-
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;
|
|
1480
1448
|
}
|
|
1481
1449
|
/**
|
|
1482
|
-
*
|
|
1450
|
+
* Definition for a CSS @property at-rule.
|
|
1451
|
+
* Used to define custom property syntax, inheritance, and initial value.
|
|
1483
1452
|
*/
|
|
1484
|
-
interface
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
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;
|
|
1488
1460
|
}
|
|
1489
1461
|
/**
|
|
1490
|
-
*
|
|
1462
|
+
* Options for registering a CSS `@property`.
|
|
1463
|
+
* Extends {@link PropertyDefinition} with an optional injection root.
|
|
1491
1464
|
*/
|
|
1492
|
-
interface
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
name?: string;
|
|
1496
|
-
condition: string;
|
|
1497
|
-
}[];
|
|
1498
|
-
startingStyle?: boolean;
|
|
1499
|
-
rootStates?: string[];
|
|
1500
|
-
negatedRootStates?: string[];
|
|
1465
|
+
interface PropertyOptions extends PropertyDefinition {
|
|
1466
|
+
/** Shadow root or document to inject into */
|
|
1467
|
+
root?: Document | ShadowRoot;
|
|
1501
1468
|
}
|
|
1502
1469
|
/**
|
|
1503
|
-
*
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
*
|
|
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.
|
|
1508
1475
|
*/
|
|
1509
|
-
|
|
1476
|
+
type FunctionParameter = true | string | {
|
|
1477
|
+
syntax?: string;
|
|
1478
|
+
default?: string | number;
|
|
1479
|
+
};
|
|
1510
1480
|
/**
|
|
1511
|
-
*
|
|
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
|
+
* ```
|
|
1512
1492
|
*/
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
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;
|
|
1519
1505
|
}
|
|
1520
1506
|
/**
|
|
1521
|
-
*
|
|
1522
|
-
*/
|
|
1523
|
-
declare function parseStateKey(stateKey: string, options?: ParseStateKeyOptions): ConditionNode;
|
|
1524
|
-
//#endregion
|
|
1525
|
-
//#region src/pipeline/index.d.ts
|
|
1526
|
-
/**
|
|
1527
|
-
* Matches the old StyleResult interface for backward compatibility
|
|
1507
|
+
* Descriptors for a CSS @font-face at-rule.
|
|
1528
1508
|
*/
|
|
1529
|
-
interface
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
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;
|
|
1537
1534
|
}
|
|
1535
|
+
/** Single descriptor or array of descriptors for multiple weights/styles. */
|
|
1536
|
+
type FontFaceInput = FontFaceDescriptors | FontFaceDescriptors[];
|
|
1538
1537
|
/**
|
|
1539
|
-
*
|
|
1538
|
+
* Descriptors for a CSS @counter-style at-rule.
|
|
1540
1539
|
*/
|
|
1541
|
-
interface
|
|
1542
|
-
|
|
1543
|
-
|
|
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;
|
|
1544
1561
|
}
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
*/
|
|
1548
|
-
declare function isSelector(key: string): boolean;
|
|
1549
|
-
/**
|
|
1550
|
-
* Options for renderStyles when using direct selector mode.
|
|
1551
|
-
*/
|
|
1552
|
-
interface RenderStylesOptions {
|
|
1553
|
-
/**
|
|
1554
|
-
* Whether to double the class selector for increased specificity.
|
|
1555
|
-
* When true, `.myClass` becomes `.myClass.myClass` for higher specificity.
|
|
1556
|
-
*
|
|
1557
|
-
* @default false - User-provided selectors are not doubled.
|
|
1558
|
-
*
|
|
1559
|
-
* Note: This only applies when a classNameOrSelector is provided.
|
|
1560
|
-
* When renderStyles returns RenderResult with needsClassName=true,
|
|
1561
|
-
* the injector handles doubling automatically.
|
|
1562
|
-
*/
|
|
1563
|
-
doubleSelector?: boolean;
|
|
1562
|
+
interface RawCSSResult {
|
|
1563
|
+
dispose: () => void;
|
|
1564
1564
|
}
|
|
1565
|
-
/**
|
|
1566
|
-
* Render styles to CSS rules.
|
|
1567
|
-
*
|
|
1568
|
-
* When called without classNameOrSelector, returns RenderResult with needsClassName=true.
|
|
1569
|
-
* When called with a selector/className string, returns StyleResult[] for direct injection.
|
|
1570
|
-
*/
|
|
1571
|
-
declare function renderStyles(styles?: Styles, classNameOrSelector?: undefined, options?: undefined, pipelineCacheKey?: string): RenderResult;
|
|
1572
|
-
declare function renderStyles(styles: Styles | undefined, classNameOrSelector: string, options?: RenderStylesOptions): StyleResult[];
|
|
1573
1565
|
//#endregion
|
|
1574
|
-
export {
|
|
1575
|
-
//# sourceMappingURL=
|
|
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-DJEM_BOJ.d.ts.map
|