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