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