1 | import type { DistributiveOmit, Pretty } from "../utils";
|
2 | import type { ConditionalValue, SystemStyleObject } from "./css.types";
|
3 | import type { ColorPalette } from "./generated/token.gen";
|
4 | type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
5 | export type RecipeVariantRecord = Record<any, Record<any, SystemStyleObject>>;
|
6 | export type RecipeSelection<T extends RecipeVariantRecord | SlotRecipeVariantRecord<string>> = keyof any extends keyof T ? {} : {
|
7 | [K in keyof T]?: ConditionalValue<StringToBoolean<keyof T[K]> | undefined>;
|
8 | };
|
9 | export type RecipeVariantFn<T extends RecipeVariantRecord> = (props?: RecipeSelection<T>) => string;
|
10 | export type RecipeVariantProps<T extends RecipeDefinition | SlotRecipeDefinition> = T extends RecipeDefinition<infer U> ? RecipeSelection<U> : T extends SlotRecipeDefinition<string, infer U> ? RecipeSelection<U> : never;
|
11 | export type RecipeVariantMap<T extends RecipeVariantRecord> = {
|
12 | [K in keyof T]: Array<keyof T[K]>;
|
13 | };
|
14 | export interface RecipeRuntimeFn<T extends RecipeVariantRecord> extends RecipeVariantFn<T> {
|
15 | __type: RecipeSelection<T>;
|
16 | variantKeys: (keyof T)[];
|
17 | variantMap: RecipeVariantMap<T>;
|
18 | config: RecipeDefinition<T>;
|
19 | splitVariantProps<Props extends RecipeSelection<T>>(props: Props): [RecipeSelection<T>, Pretty<DistributiveOmit<Props, keyof T>>];
|
20 | merge: any;
|
21 | }
|
22 | type OneOrMore<T> = T | Array<T>;
|
23 | export type RecipeCompoundSelection<T> = {
|
24 | [K in keyof T]?: OneOrMore<StringToBoolean<keyof T[K]>> | undefined;
|
25 | } & {
|
26 | colorPalette?: OneOrMore<ColorPalette> | undefined;
|
27 | };
|
28 | export type RecipeCompoundVariant<T> = T & {
|
29 | css: SystemStyleObject;
|
30 | };
|
31 | export interface RecipeDefinition<T extends RecipeVariantRecord = RecipeVariantRecord> {
|
32 | |
33 |
|
34 |
|
35 | className?: string;
|
36 | |
37 |
|
38 |
|
39 | base?: SystemStyleObject;
|
40 | |
41 |
|
42 |
|
43 | variants?: T;
|
44 | |
45 |
|
46 |
|
47 | defaultVariants?: RecipeSelection<T> & {
|
48 | colorPalette?: ColorPalette;
|
49 | };
|
50 | |
51 |
|
52 |
|
53 | compoundVariants?: Pretty<RecipeCompoundVariant<RecipeCompoundSelection<T>>>[];
|
54 | }
|
55 | export type RecipeCreatorFn = <T extends RecipeVariantRecord>(config: RecipeDefinition<T>) => RecipeRuntimeFn<T>;
|
56 | export type RecipeIdentityFn = <T extends RecipeVariantRecord>(config: RecipeDefinition<T>) => RecipeDefinition<T>;
|
57 | type SlotRecord<S extends string, T> = Partial<Record<S, T>>;
|
58 | export type SlotRecipeVariantRecord<S extends string> = Record<any, Record<any, SlotRecord<S, SystemStyleObject>>>;
|
59 | export type SlotRecipeVariantFn<S extends string, T extends RecipeVariantRecord> = (props?: RecipeSelection<T>) => SlotRecord<S, string>;
|
60 | export interface SlotRecipeRuntimeFn<S extends string, T extends SlotRecipeVariantRecord<S>> extends SlotRecipeVariantFn<S, T> {
|
61 | classNameMap: Record<S, string>;
|
62 | variantKeys: (keyof T)[];
|
63 | variantMap: RecipeVariantMap<T>;
|
64 | splitVariantProps<Props extends RecipeSelection<T>>(props: Props): [RecipeSelection<T>, Pretty<Omit<Props, keyof T>>];
|
65 | }
|
66 | export type SlotRecipeCompoundVariant<S extends string, T> = T & {
|
67 | css: SlotRecord<S, SystemStyleObject>;
|
68 | };
|
69 | export interface SlotRecipeDefinition<S extends string = string, T extends SlotRecipeVariantRecord<S> = SlotRecipeVariantRecord<S>> {
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | className?: string;
|
77 | |
78 |
|
79 |
|
80 | slots: S[] | Readonly<S[]>;
|
81 | |
82 |
|
83 |
|
84 | base?: SlotRecord<S, SystemStyleObject>;
|
85 | |
86 |
|
87 |
|
88 | variants?: T;
|
89 | |
90 |
|
91 |
|
92 | defaultVariants?: RecipeSelection<T> & {
|
93 | colorPalette?: ColorPalette;
|
94 | };
|
95 | |
96 |
|
97 |
|
98 | compoundVariants?: Pretty<SlotRecipeCompoundVariant<S, RecipeCompoundSelection<T>>>[];
|
99 | }
|
100 | export type SlotRecipeCreatorFn = <S extends string, T extends SlotRecipeVariantRecord<S>>(config: SlotRecipeDefinition<S, T>) => SlotRecipeRuntimeFn<S, T>;
|
101 | export type SlotRecipeIdentityFn = <S extends string, T extends SlotRecipeVariantRecord<S>>(config: SlotRecipeDefinition<S, T>) => SlotRecipeDefinition<S, T>;
|
102 | export type SlotRecipeConfig<S extends string = string, T extends SlotRecipeVariantRecord<S> = SlotRecipeVariantRecord<S>> = SlotRecipeDefinition<S, T>;
|
103 | export interface SystemRecipeFn<VP, VM> {
|
104 | __type: Partial<VP>;
|
105 | (props?: Partial<VP>): SystemStyleObject;
|
106 | className: string;
|
107 | variantMap: VM;
|
108 | variantKeys: Array<keyof VP>;
|
109 | splitVariantProps<P extends VP>(props: P): [VP, Pretty<DistributiveOmit<P, keyof VP>>];
|
110 | }
|
111 | export interface SystemSlotRecipeFn<S extends string, VP, VM> {
|
112 | __type: Partial<VP>;
|
113 | (props?: Partial<VP>): Record<S, SystemStyleObject>;
|
114 | classNameMap: Record<S, string>;
|
115 | variantMap: VM;
|
116 | variantKeys: Array<keyof VP>;
|
117 | splitVariantProps<P extends VP & {
|
118 | recipe?: any;
|
119 | }>(props: P): [VP, Pretty<DistributiveOmit<P, keyof VP | "recipe">>];
|
120 | }
|
121 | export {};
|