clava 0.2.4 → 0.4.0
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/CHANGELOG.md +90 -0
- package/README.md +552 -0
- package/dist/index.d.ts +22 -30
- package/dist/index.js +356 -171
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/rolldown.config.ts +1 -0
- package/src/index.ts +718 -285
- package/src/types.ts +44 -49
- package/tests/_utils.ts +1 -3
- package/tests/build.test.ts +18 -0
- package/tests/component-api.test.ts +284 -15
- package/tests/extend.test.ts +6 -6
- package/tests/{computed-variants.test.ts → function-variants.test.ts} +105 -25
- package/tests/prototype-pollution.test.ts +6 -6
- package/tests/{computed.test.ts → refine.test.ts} +517 -100
- package/tests/solid.test.ts +30 -0
- package/tests/split-props.test.ts +73 -1
- package/tests/variants-inference.test.ts +252 -0
package/dist/index.d.ts
CHANGED
|
@@ -28,10 +28,11 @@ type ComponentResultValue<K extends AllComponentResultKeys> = K extends "style"
|
|
|
28
28
|
type NullableComponentResult = { [K in AllComponentResultKeys]?: ComponentResultValue<K> | null };
|
|
29
29
|
type ComponentProps<V = {}> = VariantValues<V> & NullableComponentResult;
|
|
30
30
|
type GetVariants<V> = (variants?: VariantValues<V>) => VariantValues<V>;
|
|
31
|
+
type ComponentPropKey<R extends ComponentResult> = keyof R | (R extends StyleClassProps ? "className" : never);
|
|
31
32
|
type KeySourceArray = readonly string[];
|
|
32
33
|
type KeySourceComponent = {
|
|
33
|
-
|
|
34
|
-
variantKeys: readonly
|
|
34
|
+
propKeys: readonly string[];
|
|
35
|
+
variantKeys: readonly string[];
|
|
35
36
|
getVariants: () => Record<string, unknown>;
|
|
36
37
|
};
|
|
37
38
|
type KeySource = KeySourceArray | KeySourceComponent;
|
|
@@ -39,7 +40,7 @@ type IsComponent<S> = S extends {
|
|
|
39
40
|
getVariants: () => unknown;
|
|
40
41
|
} ? true : false;
|
|
41
42
|
type SourceKeys<S> = S extends readonly (infer K)[] ? K : S extends {
|
|
42
|
-
|
|
43
|
+
propKeys: readonly (infer K)[];
|
|
43
44
|
} ? K : never;
|
|
44
45
|
type SourceVariantKeys<S> = S extends readonly (infer K)[] ? K : S extends {
|
|
45
46
|
variantKeys: readonly (infer K)[];
|
|
@@ -57,25 +58,20 @@ interface ModalComponent<V, R extends ComponentResult> {
|
|
|
57
58
|
class: (props?: ComponentProps<V>) => string;
|
|
58
59
|
style: (props?: ComponentProps<V>) => R["style"];
|
|
59
60
|
getVariants: GetVariants<V>;
|
|
60
|
-
keys: (keyof V | keyof NullableComponentResult)[];
|
|
61
61
|
variantKeys: (keyof V)[];
|
|
62
|
-
propKeys: (keyof V |
|
|
62
|
+
propKeys: (keyof V | ComponentPropKey<R>)[];
|
|
63
63
|
}
|
|
64
|
-
interface CVComponent<V extends Variants = {},
|
|
65
|
-
jsx: ModalComponent<MergeVariants<V,
|
|
66
|
-
html: ModalComponent<MergeVariants<V,
|
|
67
|
-
htmlObj: ModalComponent<MergeVariants<V,
|
|
64
|
+
interface CVComponent<V extends Variants = {}, E extends AnyComponent[] = [], R extends ComponentResult = StyleClassProps> extends ModalComponent<MergeVariants<V, E>, R> {
|
|
65
|
+
jsx: ModalComponent<MergeVariants<V, E>, JSXProps>;
|
|
66
|
+
html: ModalComponent<MergeVariants<V, E>, HTMLProps>;
|
|
67
|
+
htmlObj: ModalComponent<MergeVariants<V, E>, HTMLObjProps>;
|
|
68
68
|
}
|
|
69
|
-
type AnyComponent = CVComponent<any, any, any
|
|
69
|
+
type AnyComponent = CVComponent<any, any, any> | ModalComponent<any, any>;
|
|
70
70
|
type MergeExtendedVariants<T> = T extends readonly [infer First, ...infer Rest] ? ExtractVariants<First> & MergeExtendedVariants<Rest> : {};
|
|
71
|
-
type
|
|
72
|
-
type
|
|
73
|
-
type ExtractComputedVariants<T> = T extends CVComponent<any, infer CV, infer E, any> ? CV & Omit<MergeExtendedComputedVariants<E>, keyof CV> : {};
|
|
74
|
-
type MergeVariantDefinition<Child, Parent> = Child extends Record<string, any> ? Parent extends Record<string, any> ? Omit<Parent, keyof Child> & Child : Child : Child;
|
|
71
|
+
type ExtractVariants<T> = T extends CVComponent<infer V, infer E, any> ? MergeVariantMaps<V, MergeExtendedVariants<E>> : {};
|
|
72
|
+
type MergeVariantDefinition<Child, Parent> = Child extends ((...args: any[]) => any) ? Child : Parent extends ((...args: any[]) => any) ? Child : Child extends Record<string, any> ? Parent extends Record<string, any> ? Omit<Parent, keyof Child> & Child : Child : Child;
|
|
75
73
|
type MergeVariantMaps<Child, Parent> = Omit<Parent, keyof Child> & Child & { [K in keyof Child & keyof Parent]: MergeVariantDefinition<Child[K], Parent[K]> };
|
|
76
|
-
type
|
|
77
|
-
type MergeBaseVariants<V, E extends AnyComponent[]> = MergeVariantMaps<NoInfer<V>, MergeExtendedAllVariants<E>>;
|
|
78
|
-
type MergeVariants<V, CV, E extends AnyComponent[]> = NoInfer<CV> & Omit<MergeBaseVariants<V, E>, keyof CV>;
|
|
74
|
+
type MergeVariants<V, E extends AnyComponent[]> = MergeVariantMaps<NoInfer<V>, MergeExtendedVariants<E>>;
|
|
79
75
|
type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
|
80
76
|
type VariantValue = ClassValue | StyleClassValue;
|
|
81
77
|
type NonNullKeys<T> = { [K in keyof T]: T[K] extends null ? never : K }[keyof T];
|
|
@@ -88,34 +84,30 @@ interface StyleClassValue {
|
|
|
88
84
|
style?: StyleValue;
|
|
89
85
|
class?: ClassValue;
|
|
90
86
|
}
|
|
91
|
-
interface
|
|
87
|
+
interface RefineContext<V> {
|
|
92
88
|
variants: VariantValues<V>;
|
|
93
89
|
setVariants: (variants: VariantValues<V>) => void;
|
|
94
90
|
setDefaultVariants: (variants: VariantValues<V>) => void;
|
|
95
91
|
addClass: (className: ClassValue) => void;
|
|
96
92
|
addStyle: (style: StyleValue) => void;
|
|
97
93
|
}
|
|
98
|
-
type
|
|
99
|
-
type
|
|
100
|
-
type ComputedVariants = Record<string, ComputedVariant>;
|
|
101
|
-
type Variant$1 = ClassValue | Record<string, VariantValue>;
|
|
94
|
+
type Refine<V> = (context: RefineContext<V>) => VariantValue;
|
|
95
|
+
type Variant$1 = ClassValue | Record<string, VariantValue> | ((value: any) => VariantValue);
|
|
102
96
|
type Variants = Record<string, Variant$1>;
|
|
103
|
-
type ExtendedVariants<E extends AnyComponent[]> = MergeExtendedVariants<E> & MergeExtendedComputedVariants<E>;
|
|
104
97
|
type NullablePartial<T> = T extends Record<string, any> ? { [K in keyof T]?: T[K] | null } : T | null;
|
|
105
|
-
type ExtendableVariants<V extends Variants, E extends AnyComponent[]> = V & { [K in keyof
|
|
98
|
+
type ExtendableVariants<V extends Variants, E extends AnyComponent[]> = V & { [K in keyof MergeExtendedVariants<E>]?: NullablePartial<MergeExtendedVariants<E>[K]> | Variant$1 };
|
|
106
99
|
//#endregion
|
|
107
100
|
//#region src/index.d.ts
|
|
108
101
|
type VariantProps<T extends Pick<AnyComponent, "getVariants">> = ReturnType<T["getVariants"]>;
|
|
109
102
|
type VariantKey<T> = T extends boolean ? "true" | "false" : Extract<T, string>;
|
|
110
103
|
type Variant<T extends Pick<AnyComponent, "getVariants">, K extends keyof VariantProps<T>> = Record<VariantKey<NonNullable<VariantProps<T>[K]>>, ClassValue | StyleClassValue>;
|
|
111
|
-
interface CVConfig<V extends Variants = {},
|
|
104
|
+
interface CVConfig<V extends Variants = {}, E extends AnyComponent[] = []> {
|
|
112
105
|
extend?: E;
|
|
113
106
|
class?: ClassValue;
|
|
114
107
|
style?: StyleValue;
|
|
115
108
|
variants?: ExtendableVariants<V, E>;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
computed?: Computed<MergeVariants<V, CV, E>>;
|
|
109
|
+
defaultVariants?: VariantValues<MergeVariants<V, E>>;
|
|
110
|
+
refine?: Refine<MergeVariants<V, E>>;
|
|
119
111
|
}
|
|
120
112
|
interface CreateParams {
|
|
121
113
|
transformClass?: (className: string) => string;
|
|
@@ -135,10 +127,10 @@ declare const splitProps: SplitPropsFunction;
|
|
|
135
127
|
declare function create({
|
|
136
128
|
transformClass
|
|
137
129
|
}?: CreateParams): {
|
|
138
|
-
cv: <V extends Variants = {},
|
|
130
|
+
cv: <V extends Variants = {}, const E extends AnyComponent[] = []>(config?: CVConfig<V, E>) => CVComponent<V, E>;
|
|
139
131
|
cx: (...classes: ClassValue$1[]) => string;
|
|
140
132
|
};
|
|
141
|
-
declare const cv: <V extends Variants = {},
|
|
133
|
+
declare const cv: <V extends Variants = {}, const E extends AnyComponent[] = []>(config?: CVConfig<V, E>) => CVComponent<V, E>, cx: (...classes: ClassValue$1[]) => string;
|
|
142
134
|
//#endregion
|
|
143
135
|
export { type CVComponent, CVConfig, type ClassValue, type HTMLObjProps, type HTMLProps, type JSXProps, type StyleClassProps, type StyleClassValue, type StyleValue, Variant, VariantProps, create, cv, cx, splitProps };
|
|
144
136
|
//# sourceMappingURL=index.d.ts.map
|