@splenddev/kreativ-core 0.1.2 → 0.1.3
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/dist/chunk-5CYSF7C3.js +24 -0
- package/dist/chunk-5CYSF7C3.js.map +1 -0
- package/dist/{utils/index.cjs → chunk-OJSXALOI.js} +5 -41
- package/dist/chunk-OJSXALOI.js.map +1 -0
- package/dist/chunk-RV5MKKBP.js +3 -0
- package/dist/chunk-RV5MKKBP.js.map +1 -0
- package/dist/hooks/index.js +3 -88
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.js +4 -365
- package/dist/index.js.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/utils/index.js +1 -350
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/hooks/index.cjs +0 -449
- package/dist/hooks/index.cjs.map +0 -1
- package/dist/hooks/index.d.cts +0 -117
- package/dist/index.cjs +0 -559
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -363
- package/dist/types/index.cjs +0 -4
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.cts +0 -646
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.d.cts +0 -64
package/dist/index.d.cts
DELETED
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
import { TokenValue, SemanticToken, SizeToken, SizeScale, Typography, RecipeDefinition, DesignTokens, TokenDefinition, TokenReferenceString as TokenReferenceString$1, SemanticTokens, Theme, ColorMode, ResolvedTokens } from './types/index.cjs';
|
|
2
|
-
export { AnimationTokens, BaseBreakpoint, BaseColor, BaseProps, BaseVariant, BreakpointTokens, CSSPropertiesWithVars, ClearableProps, ColorModeValue, ColorProps, ColorScale, ColorTokens, ControlledProps, CustomRecipes, DeepPartial, DefaultRecipeCollection, DisabledProps, Easing, EmbeddedProps, FontSizeTokens, FontTokens, FontWeightTokens, FormFieldStatus, FullWidthProps, IntensityMap, LetterSpacingTokens, LineHeightTokens, LoadingProps, Orientation, OrientationProps, RadiusTokens, RecipeCollection, RecipeCompoundVariant, RecipeStyle, RecipeVariant, RecipeVariantValue, ReportedValidity, RequiredStateControlProps, ResponsiveStyles, ResponsiveValue, SemanticColorTokens, ShadowTokens, Size, SizeProps, SizeValue, SpacingTokens, StateControlProps, StateProps, StatusProps, StyleObject, StyleValue, Styleable, ThemeAnimation, ThemeOverride, ThemeTogglerTransition, ThemeTransition, TokenGroup, TrimProps, TypographyProps, TypographyStyle, UndoRedoProps, ValidateOn, ValidateProps, ValidationResult, ValueProps, Variant, VariantProps } from './types/index.cjs';
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
export { CreateComponentConfig, CreateFromPropsInput, KuiComponent, KuiMeta, KuiRole, KuiSkeletonHint, KuiSupports, ResolvedResponsiveValue, composeRefs, createComponent, createFromProps, deepMerge, hasKuiMeta, isResponsiveValue, mergeResponsiveValue, resolveResponsiveValue, resolveSemanticTokenReferences, resolveTokenReference, resolveTokens, resolveTypography, toKebabCase, toResponsiveClasses, tokensToCssVars } from './utils/index.cjs';
|
|
5
|
-
|
|
6
|
-
declare function defineToken<T extends TokenValue>(value: T): {
|
|
7
|
-
value: T;
|
|
8
|
-
};
|
|
9
|
-
declare function defineTokens<T extends Record<string, TokenValue>>(tokens: T): { [K in keyof T]: ReturnType<typeof defineToken<T[K]>>; };
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Defines a semantic token that shares a single value across both
|
|
13
|
-
* light and dark modes (the explicit sameForBothModes shorthand).
|
|
14
|
-
*/
|
|
15
|
-
declare function defineSemanticToken<T extends TokenValue>(value: T): SemanticToken<T>;
|
|
16
|
-
/**
|
|
17
|
-
* Defines a semantic token with distinct light and dark values.
|
|
18
|
-
*/
|
|
19
|
-
declare function defineSemanticToken<T extends TokenValue>(light: T, dark: T): SemanticToken<T>;
|
|
20
|
-
type SemanticTokenInput<T extends TokenValue> = T | {
|
|
21
|
-
light: T;
|
|
22
|
-
dark: T;
|
|
23
|
-
};
|
|
24
|
-
declare function defineSemanticTokens<T extends Record<string, SemanticTokenInput<TokenValue>>>(tokens: T): {
|
|
25
|
-
[K in keyof T]: SemanticToken<T[K] extends {
|
|
26
|
-
light: infer V;
|
|
27
|
-
dark: infer _;
|
|
28
|
-
} ? V extends TokenValue ? V : never : T[K] extends TokenValue ? T[K] : never>;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
declare function defineSize<const T extends SizeToken>(size: T): T;
|
|
32
|
-
declare function defineSizes<const T extends SizeScale>(sizes: T): T;
|
|
33
|
-
|
|
34
|
-
declare function defineTypography<const T extends Typography>(typography: T): T;
|
|
35
|
-
|
|
36
|
-
declare function defineRecipe<const T extends RecipeDefinition>(recipe: T): T;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Branded type-level error, surfaced at the defineTheme() call site
|
|
40
|
-
* when a section validator fails. Section validators wrap this in a
|
|
41
|
-
* section-named key (e.g. { semanticTokens: Invalid<...> }) rather
|
|
42
|
-
* than composing into an unreadable anonymous intersection.
|
|
43
|
-
*
|
|
44
|
-
* Path-tracking (__kuiPath) is a locked stretch goal, not yet built —
|
|
45
|
-
* ship section-named base errors first, confirm they render legibly
|
|
46
|
-
* in editor tooltips, then treat path-tracking as a follow-on.
|
|
47
|
-
*/
|
|
48
|
-
type Invalid<Message extends string> = {
|
|
49
|
-
readonly __kuiError: Message;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* A token reference string, e.g. "{colors.brand.500}" — legal for
|
|
54
|
-
* semantic tokens, but NOT legal for primitive tokens. defineToken's
|
|
55
|
-
* "no token references" rule is what makes defineTheme's cycle
|
|
56
|
-
* detection tractable (cycle detection only needs to walk
|
|
57
|
-
* semantic→semantic edges).
|
|
58
|
-
*/
|
|
59
|
-
type TokenReferenceString = `{${string}}`;
|
|
60
|
-
type IsTokenReference$1<T> = T extends TokenReferenceString ? true : false;
|
|
61
|
-
/**
|
|
62
|
-
* Recursively checks that every leaf in a token tree is a real
|
|
63
|
-
* terminal TokenValue, never a "{...}" reference string.
|
|
64
|
-
*/
|
|
65
|
-
type ValidateTokenLeaf<T> = T extends TokenDefinition<infer V> ? IsTokenReference$1<V> extends true ? Invalid<"Primitive tokens cannot contain token references — use defineSemanticToken instead"> : unknown : T extends Record<string, unknown> ? ValidateTokenTree<T> : unknown;
|
|
66
|
-
type ValidateTokenTree<T> = {
|
|
67
|
-
[K in keyof T]: ValidateTokenLeaf<T[K]>;
|
|
68
|
-
}[keyof T] extends infer Result ? Result extends Invalid<any> ? Result : unknown : never;
|
|
69
|
-
type ValidateTokens<T extends {
|
|
70
|
-
tokens?: unknown;
|
|
71
|
-
}> = T["tokens"] extends DesignTokens ? ValidateTokenTree<T["tokens"]> : unknown;
|
|
72
|
-
type ValidateTokenSection<T extends {
|
|
73
|
-
tokens?: unknown;
|
|
74
|
-
}> = ValidateTokens<T> extends infer Result ? Result extends Invalid<any> ? {
|
|
75
|
-
tokens: Result;
|
|
76
|
-
} : unknown : never;
|
|
77
|
-
|
|
78
|
-
type IsTokenReference<T> = T extends TokenReferenceString$1 ? true : false;
|
|
79
|
-
/**
|
|
80
|
-
* Strips the surrounding "{" "}" from a reference string, giving the
|
|
81
|
-
* raw dotted path, e.g. "{colors.brand.500}" -> "colors.brand.500".
|
|
82
|
-
*/
|
|
83
|
-
type ExtractPath<T extends string> = T extends `{${infer Path}}` ? Path : never;
|
|
84
|
-
/**
|
|
85
|
-
* Splits a dotted path string into a tuple of segments.
|
|
86
|
-
* "colors.brand.500" -> ["colors", "brand", "500"]
|
|
87
|
-
*/
|
|
88
|
-
type SplitPath<S extends string> = S extends `${infer Head}.${infer Rest}` ? [Head, ...SplitPath<Rest>] : [S];
|
|
89
|
-
/**
|
|
90
|
-
* Looks up a single path segment against T's keys, tolerating the
|
|
91
|
-
* common case where the segment is a numeric-looking string
|
|
92
|
-
* ("500") but the actual object key is a numeric literal (500) —
|
|
93
|
-
* e.g. color scale steps. TS's keyof does not match these directly.
|
|
94
|
-
*/
|
|
95
|
-
type LookupKey<T, Head extends string> = Head extends keyof T ? Head : Head extends `${infer N extends number}` ? N extends keyof T ? N : never : never;
|
|
96
|
-
/**
|
|
97
|
-
* Walks an object tree along a tuple of path segments. Resolves to
|
|
98
|
-
* the value at that path, or `never` if any segment doesn't exist.
|
|
99
|
-
*/
|
|
100
|
-
type ResolvePath<T, Path extends readonly string[]> = Path extends [infer Head extends string, ...infer Rest] ? LookupKey<T, Head> extends infer K ? K extends keyof T ? Rest extends readonly string[] ? Rest["length"] extends 0 ? T[K] : ResolvePath<T[K], Rest> : never : never : never : never;
|
|
101
|
-
/**
|
|
102
|
-
* True if a dotted-path reference resolves to something inside T.
|
|
103
|
-
*/
|
|
104
|
-
type PathExists<T, Ref extends string> = ResolvePath<T, SplitPath<ExtractPath<Ref>>> extends never ? false : true;
|
|
105
|
-
/**
|
|
106
|
-
* Validates that a single reference string, if it is one, actually
|
|
107
|
-
* resolves against the given tokens/semanticTokens tree. Non-reference
|
|
108
|
-
* values pass through as `unknown` (valid).
|
|
109
|
-
*/
|
|
110
|
-
type ValidateReferenceExists<Value, Tokens, _Path extends string = "unknown path"> = Value extends TokenReferenceString$1 ? PathExists<Tokens, Value> extends true ? unknown : Invalid<`References an unknown token: "${Value}"`> : unknown;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Extracts the underlying value(s) out of a semantic token's
|
|
114
|
-
* ColorModeValue, to run existence checks against each.
|
|
115
|
-
*/
|
|
116
|
-
type ExtractCheckableValues<V> = V extends {
|
|
117
|
-
sameForBothModes: true;
|
|
118
|
-
value: infer X;
|
|
119
|
-
} ? [X] : V extends {
|
|
120
|
-
light: infer L;
|
|
121
|
-
dark: infer D;
|
|
122
|
-
} ? [L, D] : [];
|
|
123
|
-
/**
|
|
124
|
-
* Validates a single semantic token leaf: every reference it
|
|
125
|
-
* contains (light and/or dark) must resolve against the combined
|
|
126
|
-
* tokens+semanticTokens tree.
|
|
127
|
-
*
|
|
128
|
-
* NOTE: semantic->semantic cycle detection is NOT done here — it
|
|
129
|
-
* was attempted at the type level and hit TypeScript inference
|
|
130
|
-
* edge cases in recursive conditional types that made it unreliable
|
|
131
|
-
* (false positives on valid semantic->primitive references). Cycle
|
|
132
|
-
* detection is handled at runtime instead — see validateNoCycles in
|
|
133
|
-
* runtime/validateCycles.ts, called from defineTheme/extendTheme.
|
|
134
|
-
*/
|
|
135
|
-
type ValidateSemanticLeaf<Leaf, AllTokens> = Leaf extends {
|
|
136
|
-
value: infer V;
|
|
137
|
-
} ? ExtractCheckableValues<V> extends infer Values extends readonly unknown[] ? {
|
|
138
|
-
[I in keyof Values]: Values[I] extends TokenReferenceString$1 ? ValidateReferenceExists<Values[I], AllTokens> : unknown;
|
|
139
|
-
}[number] extends infer Result ? Result extends Invalid<any> ? Result : unknown : never : unknown : unknown;
|
|
140
|
-
/**
|
|
141
|
-
* Recursively walks the semanticTokens tree, validating every leaf.
|
|
142
|
-
*/
|
|
143
|
-
type ValidateSemanticTree<Tree, AllTokens> = {
|
|
144
|
-
[K in keyof Tree]: Tree[K] extends {
|
|
145
|
-
value: unknown;
|
|
146
|
-
} ? ValidateSemanticLeaf<Tree[K], AllTokens> : ValidateSemanticTree<Tree[K], AllTokens>;
|
|
147
|
-
}[keyof Tree] extends infer Result ? Result extends Invalid<any> ? Result : unknown : never;
|
|
148
|
-
type ValidateSemanticTokens<T extends {
|
|
149
|
-
tokens?: unknown;
|
|
150
|
-
semanticTokens?: unknown;
|
|
151
|
-
}> = T["semanticTokens"] extends SemanticTokens ? ValidateSemanticTree<T["semanticTokens"], (T["tokens"] extends DesignTokens ? T["tokens"] : {}) & T["semanticTokens"]> : unknown;
|
|
152
|
-
type ValidateSemanticTokenSection<T extends {
|
|
153
|
-
tokens?: unknown;
|
|
154
|
-
semanticTokens?: unknown;
|
|
155
|
-
}> = ValidateSemanticTokens<T> extends infer Result ? Result extends Invalid<any> ? {
|
|
156
|
-
semanticTokens: Result;
|
|
157
|
-
} : unknown : never;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Validates a single SizeToken's fontSize: if present, it MUST be a
|
|
161
|
-
* "{typography.someVariant}"-style reference into the theme's
|
|
162
|
-
* Typography collection — a raw CSS value (e.g. "1rem") is invalid.
|
|
163
|
-
*
|
|
164
|
-
* This is a cross-section rule (spans sizes + typography), which is
|
|
165
|
-
* why it lives in defineTheme's territory rather than defineSize or
|
|
166
|
-
* defineTypography individually — neither of those functions can see
|
|
167
|
-
* the other section in isolation.
|
|
168
|
-
*/
|
|
169
|
-
type ValidateSizeFontSize<FontSize, TypographyTree> = FontSize extends undefined ? unknown : FontSize extends TokenReferenceString$1 ? ValidateReferenceExists<FontSize, {
|
|
170
|
-
typography: TypographyTree;
|
|
171
|
-
}> : Invalid<`SizeToken.fontSize must reference a typography preset (e.g. "{typography.body}"), not a raw value: "${FontSize & string}"`>;
|
|
172
|
-
/**
|
|
173
|
-
* Walks every size in the SizeScale, validating each one's fontSize.
|
|
174
|
-
*/
|
|
175
|
-
type ValidateSizeScaleFontSizes<Sizes, TypographyTree> = {
|
|
176
|
-
[K in keyof Sizes]: Sizes[K] extends {
|
|
177
|
-
fontSize?: infer F;
|
|
178
|
-
} ? ValidateSizeFontSize<F, TypographyTree> : unknown;
|
|
179
|
-
}[keyof Sizes] extends infer Result ? Result extends Invalid<any> ? Result : unknown : never;
|
|
180
|
-
type ValidateTypography<T extends {
|
|
181
|
-
typography?: unknown;
|
|
182
|
-
sizes?: unknown;
|
|
183
|
-
}> = T["sizes"] extends SizeScale ? ValidateSizeScaleFontSizes<T["sizes"], T["typography"] extends Typography ? T["typography"] : {}> : unknown;
|
|
184
|
-
/**
|
|
185
|
-
* Cross-section rule: SizeToken.fontSize -> Typography preset.
|
|
186
|
-
*
|
|
187
|
-
* Despite the name (kept for continuity with the ownership-tree
|
|
188
|
-
* discussion, which described this as "the typography section" of
|
|
189
|
-
* cross-section rules), the actual invalid DATA here always lives on
|
|
190
|
-
* the `sizes` side (a bad fontSize value on a SizeToken), never on
|
|
191
|
-
* `typography` itself — so the resulting error is keyed under
|
|
192
|
-
* `sizes`, not `typography`. Keying it under `typography` would
|
|
193
|
-
* collide with T's own real `typography` field when intersected onto
|
|
194
|
-
* T in defineTheme's signature (T & ValidateTheme<T>), since TS would
|
|
195
|
-
* then require the theme's actual typography VALUE to also satisfy
|
|
196
|
-
* the Invalid<...> shape — which is a real bug that surfaced and was
|
|
197
|
-
* fixed during end-to-end testing of defineTheme.
|
|
198
|
-
*/
|
|
199
|
-
type ValidateTypographySection<T extends {
|
|
200
|
-
typography?: unknown;
|
|
201
|
-
sizes?: unknown;
|
|
202
|
-
}> = ValidateTypography<T> extends infer Result ? Result extends Invalid<any> ? {
|
|
203
|
-
sizes: Result;
|
|
204
|
-
} : unknown : never;
|
|
205
|
-
/**
|
|
206
|
-
* Validates a single TypographyStyle field: if its value is a
|
|
207
|
-
* "{...}" reference, it MUST resolve against the theme's primitive
|
|
208
|
-
* tokens (e.g. "{fonts.body}", "{fontWeights.bold}"). A raw literal
|
|
209
|
-
* value (e.g. "16px", 400) is always valid — references are opt-in,
|
|
210
|
-
* not required. This is DIFFERENT from the sizes.fontSize rule above:
|
|
211
|
-
* there, a reference is REQUIRED; here, a reference is OPTIONAL but
|
|
212
|
-
* must resolve if present.
|
|
213
|
-
*/
|
|
214
|
-
type ValidateTypographyField<FieldValue, TokensTree> = FieldValue extends TokenReferenceString$1 ? ValidateReferenceExists<FieldValue, TokensTree> : unknown;
|
|
215
|
-
/**
|
|
216
|
-
* Walks every field of a single TypographyStyle variant (fontFamily,
|
|
217
|
-
* fontSize, fontWeight, lineHeight, letterSpacing).
|
|
218
|
-
*/
|
|
219
|
-
type ValidateTypographyStyleFields<Style, TokensTree> = {
|
|
220
|
-
[K in keyof Style]: ValidateTypographyField<Style[K], TokensTree>;
|
|
221
|
-
}[keyof Style] extends infer Result ? Result extends Invalid<any> ? Result : unknown : never;
|
|
222
|
-
/**
|
|
223
|
-
* Walks every variant in the Typography collection (body, heading,
|
|
224
|
-
* label, etc.), validating every field's token references.
|
|
225
|
-
*/
|
|
226
|
-
type ValidateTypographyTokenReferences<TypographyTree, TokensTree> = {
|
|
227
|
-
[K in keyof TypographyTree]: ValidateTypographyStyleFields<TypographyTree[K], TokensTree>;
|
|
228
|
-
}[keyof TypographyTree] extends infer Result ? Result extends Invalid<any> ? Result : unknown : never;
|
|
229
|
-
/**
|
|
230
|
-
* Cross-section rule: TypographyStyle fields (fontFamily, fontSize,
|
|
231
|
-
* fontWeight, lineHeight, letterSpacing) MAY reference primitive
|
|
232
|
-
* tokens (e.g. "{fonts.body}") — if they do, the reference must
|
|
233
|
-
* resolve. This is a genuinely typography-owned rule (the invalid
|
|
234
|
-
* data lives in `typography` itself, not `sizes`), so it's kept as
|
|
235
|
-
* its own separately-exported section validator rather than folded
|
|
236
|
-
* into ValidateTypographySection above — composing both under one
|
|
237
|
-
* name would reintroduce the same key-collision risk that rule
|
|
238
|
-
* already caused once, since this one's natural key IS `typography`.
|
|
239
|
-
*/
|
|
240
|
-
type ValidateTypographyReferencesSection<T extends {
|
|
241
|
-
typography?: unknown;
|
|
242
|
-
tokens?: unknown;
|
|
243
|
-
}> = (T["typography"] extends Typography ? ValidateTypographyTokenReferences<T["typography"], T["tokens"] extends DesignTokens ? T["tokens"] : {}> : unknown) extends infer Result ? Result extends Invalid<any> ? {
|
|
244
|
-
typography: Result;
|
|
245
|
-
} : unknown : never;
|
|
246
|
-
|
|
247
|
-
type ValidateRecipes<_T extends {
|
|
248
|
-
recipes?: unknown;
|
|
249
|
-
}> = unknown;
|
|
250
|
-
type ValidateRecipeSection<_T extends {
|
|
251
|
-
recipes?: unknown;
|
|
252
|
-
}> = unknown;
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Sizes section validator.
|
|
256
|
-
*
|
|
257
|
-
* Deliberately a no-op / pass-through. A SizeToken's fields are:
|
|
258
|
-
* height, width, paddingX, paddingY, fontSize, gap, iconSize, radius,
|
|
259
|
-
* separatorSize — and fontSize is the ONLY one of those that
|
|
260
|
-
* references another theme section (a typography preset). Every
|
|
261
|
-
* other field is a raw CSS length with no cross-section relationship
|
|
262
|
-
* to validate.
|
|
263
|
-
*
|
|
264
|
-
* The fontSize -> typography-preset rule is already fully owned by
|
|
265
|
-
* ValidateTypographySection (see typography.ts) — that's where it's
|
|
266
|
-
* implemented and tested, since it's conceptually "does this
|
|
267
|
-
* typography reference resolve", not "is this size valid". There is
|
|
268
|
-
* currently no independent rule left for ValidateSizesSection to own.
|
|
269
|
-
*
|
|
270
|
-
* This slot still exists (rather than being omitted from
|
|
271
|
-
* ValidateTheme's composition) so the "why is this empty" reasoning
|
|
272
|
-
* is documented in code, and so a real future sizes-only rule has an
|
|
273
|
-
* obvious home to land in without restructuring the composition.
|
|
274
|
-
*/
|
|
275
|
-
type ValidateSizes<_T extends {
|
|
276
|
-
sizes?: unknown;
|
|
277
|
-
}> = unknown;
|
|
278
|
-
type ValidateSizesSection<_T extends {
|
|
279
|
-
sizes?: unknown;
|
|
280
|
-
}> = unknown;
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Composes all section validators into one type. Each section
|
|
284
|
-
* resolves to `unknown` (a no-op in the intersection) on success, or
|
|
285
|
-
* a section-named `{ sectionName: Invalid<...> }` object on failure
|
|
286
|
-
* — so a failing theme surfaces as a legible, named error at the
|
|
287
|
-
* defineTheme() call site instead of an anonymous intersection wall.
|
|
288
|
-
*
|
|
289
|
-
* ValidateRecipeSection and ValidateSizesSection are currently
|
|
290
|
-
* documented no-ops (see recipes.ts / sizes.ts for why) but are kept
|
|
291
|
-
* in the composition so the full section list is visible here and
|
|
292
|
-
* either can gain real rules later without changing this shape.
|
|
293
|
-
*
|
|
294
|
-
* ValidateTypographySection and ValidateTypographyReferencesSection
|
|
295
|
-
* are two DIFFERENT rules kept as separate types (not merged): the
|
|
296
|
-
* former validates sizes.fontSize -> typography (keyed under `sizes`,
|
|
297
|
-
* required reference), the latter validates typography's own fields
|
|
298
|
-
* -> tokens (keyed under `typography`, optional reference). Merging
|
|
299
|
-
* them would risk reintroducing the same key-collision bug already
|
|
300
|
-
* found and fixed once during this effort.
|
|
301
|
-
*/
|
|
302
|
-
type ValidateTheme<T extends Theme> = ValidateTokenSection<T> & ValidateSemanticTokenSection<T> & ValidateTypographySection<T> & ValidateTypographyReferencesSection<T> & ValidateRecipeSection<T> & ValidateSizesSection<T>;
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Defines a Kreativ UI theme.
|
|
306
|
-
*
|
|
307
|
-
* Type-safe boundary for creating themes while preserving the exact
|
|
308
|
-
* structure and types of the supplied theme. Does not merge with the
|
|
309
|
-
* default theme or mutate the provided object — extension/resolution
|
|
310
|
-
* are handled separately by extendTheme.
|
|
311
|
-
*
|
|
312
|
-
* `T & ValidateTheme<T>` is what actually enforces validation at the
|
|
313
|
-
* call site: ValidateTheme<T> resolves to `unknown` (a no-op) when
|
|
314
|
-
* every section passes, or a section-named `{ tokens: Invalid<...> }`
|
|
315
|
-
* / `{ semanticTokens: Invalid<...> }` / etc. object when a section
|
|
316
|
-
* fails. Intersecting that onto the parameter type means a failing
|
|
317
|
-
* theme produces a real compile error naming the failing section and
|
|
318
|
-
* message, not just a generic "not assignable to Theme".
|
|
319
|
-
*
|
|
320
|
-
* Reference *existence* (does "{colors.brand.500}" resolve to a real
|
|
321
|
-
* token) is checked at compile time via ValidateSemanticTokenSection,
|
|
322
|
-
* as part of ValidateTheme above. Reference *cycles* (semantic token
|
|
323
|
-
* A -> B -> A) can't be reliably caught at the type level (hit TS
|
|
324
|
-
* inference edge cases in recursive conditional types), so they're
|
|
325
|
-
* checked here at call time instead, via assertNoCycles.
|
|
326
|
-
*/
|
|
327
|
-
declare function defineTheme<T extends Theme>(theme: T & ValidateTheme<T>): T;
|
|
328
|
-
|
|
329
|
-
interface CycleValidationResult {
|
|
330
|
-
valid: boolean;
|
|
331
|
-
cyclePath?: string[];
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Walks every semantic token's reference chain looking for a
|
|
335
|
-
* semantic->semantic cycle. Reference *existence* (does the path
|
|
336
|
-
* resolve at all) is validated separately at the type level via
|
|
337
|
-
* ValidateSemanticTokenSection — this function only detects cycles
|
|
338
|
-
* among references that do resolve to another semantic token.
|
|
339
|
-
*
|
|
340
|
-
* A reference that resolves to nothing (dangling) or to a primitive
|
|
341
|
-
* token is a dead end for cycle-walking purposes here, not an error
|
|
342
|
-
* this function raises — that's the type-level existence check's job.
|
|
343
|
-
*/
|
|
344
|
-
declare function validateNoCycles(semanticTokens: SemanticTokens): CycleValidationResult;
|
|
345
|
-
/**
|
|
346
|
-
* Throws a descriptive error if a semantic->semantic cycle is found.
|
|
347
|
-
* Intended to be called from defineTheme/extendTheme.
|
|
348
|
-
*/
|
|
349
|
-
declare function assertNoCycles(semanticTokens: SemanticTokens): void;
|
|
350
|
-
|
|
351
|
-
interface ThemeContextValue {
|
|
352
|
-
theme: Theme;
|
|
353
|
-
mode: ColorMode;
|
|
354
|
-
resolvedMode: "light" | "dark";
|
|
355
|
-
setMode: (mode: ColorMode) => void;
|
|
356
|
-
fallbackSize: string;
|
|
357
|
-
tokens: ResolvedTokens;
|
|
358
|
-
}
|
|
359
|
-
declare const ThemeContext: React.Context<ThemeContextValue | null>;
|
|
360
|
-
|
|
361
|
-
declare function useTheme(): ThemeContextValue;
|
|
362
|
-
|
|
363
|
-
export { ColorMode, type CycleValidationResult, DesignTokens, type ExtractPath, type Invalid, type IsTokenReference, type PathExists, RecipeDefinition, type ResolvePath, ResolvedTokens, SemanticToken, SemanticTokens, SizeScale, SizeToken, type SplitPath, Theme, ThemeContext, type ThemeContextValue, TokenDefinition, TokenReferenceString$1 as TokenReferenceString, TokenValue, Typography, type ValidateRecipeSection, type ValidateRecipes, type ValidateReferenceExists, type ValidateSemanticTokenSection, type ValidateSemanticTokens, type ValidateSizes, type ValidateSizesSection, type ValidateTheme, type ValidateTokenSection, type ValidateTokens, type ValidateTypography, type ValidateTypographyReferencesSection, type ValidateTypographySection, assertNoCycles, defineRecipe, defineSemanticToken, defineSemanticTokens, defineSize, defineSizes, defineTheme, defineToken, defineTokens, defineTypography, useTheme, validateNoCycles };
|
package/dist/types/index.cjs
DELETED
package/dist/types/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|