clava 0.6.4 → 0.7.1
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 +76 -0
- package/README.md +128 -32
- package/dist/index.d.ts +109 -44
- package/dist/index.js +34 -34
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
- package/src/index.ts +162 -119
- package/src/refine-warning.ts +6 -6
- package/src/types.ts +104 -48
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ interface JSXCSSProperties extends CSS.Properties<string | number>, CustomProper
|
|
|
24
24
|
interface HTMLCSSProperties extends CSS.PropertiesHyphen<string | number>, CustomProperties {}
|
|
25
25
|
type StyleProperty = JSXCSSProperties | HTMLCSSProperties | CSS.Properties<string | number> | CSS.PropertiesHyphen<string | number> | string;
|
|
26
26
|
/**
|
|
27
|
-
* The prop object returned by a
|
|
27
|
+
* The prop object returned by a recipe's `.jsx()` mode.
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* ```ts
|
|
@@ -39,7 +39,7 @@ interface JSXProps {
|
|
|
39
39
|
style: JSXCSSProperties;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
* The prop object returned by a
|
|
42
|
+
* The prop object returned by a recipe's `.html()` mode. The `style` value
|
|
43
43
|
* is serialized as an HTML style string.
|
|
44
44
|
*
|
|
45
45
|
* @example
|
|
@@ -55,7 +55,7 @@ interface HTMLProps {
|
|
|
55
55
|
style: string;
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
|
-
* The prop object returned by a
|
|
58
|
+
* The prop object returned by a recipe's `.htmlObj()` mode. The `style`
|
|
59
59
|
* value uses hyphenated CSS property names.
|
|
60
60
|
*
|
|
61
61
|
* @example
|
|
@@ -71,7 +71,7 @@ interface HTMLObjProps {
|
|
|
71
71
|
style: HTMLCSSProperties;
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
* The default prop object returned by a Clava
|
|
74
|
+
* The default prop object returned by a Clava recipe. It uses `class`
|
|
75
75
|
* rather than `className` and keeps styles as a normalized object.
|
|
76
76
|
*
|
|
77
77
|
* @example
|
|
@@ -86,21 +86,21 @@ interface StyleClassProps {
|
|
|
86
86
|
class: string;
|
|
87
87
|
style: StyleValue;
|
|
88
88
|
}
|
|
89
|
-
type
|
|
90
|
-
type
|
|
91
|
-
type
|
|
92
|
-
type
|
|
93
|
-
type
|
|
89
|
+
type RecipeResult = JSXProps | HTMLProps | HTMLObjProps | StyleClassProps;
|
|
90
|
+
type AllRecipeResultKeys = keyof JSXProps | keyof HTMLProps | keyof HTMLObjProps;
|
|
91
|
+
type RecipeResultValue<K extends AllRecipeResultKeys> = K extends "style" ? StyleProperty : K extends "className" ? string : K extends "class" ? string : never;
|
|
92
|
+
type NullableRecipeResult = { [K in AllRecipeResultKeys]?: RecipeResultValue<K> | null; };
|
|
93
|
+
type RecipeProps<V = {}> = VariantValues<V> & NullableRecipeResult;
|
|
94
94
|
type GetVariants<V> = (variants?: VariantValues<V>) => VariantValues<V>;
|
|
95
|
-
type
|
|
95
|
+
type RecipePropKey<R extends RecipeResult> = keyof R | (R extends StyleClassProps ? "className" : never);
|
|
96
96
|
type KeySourceArray = readonly string[];
|
|
97
|
-
interface
|
|
97
|
+
interface KeySourceRecipe {
|
|
98
98
|
propKeys: readonly string[];
|
|
99
99
|
variantKeys: readonly string[];
|
|
100
100
|
getVariants: () => Record<string, unknown>;
|
|
101
101
|
}
|
|
102
|
-
type KeySource = KeySourceArray |
|
|
103
|
-
type
|
|
102
|
+
type KeySource = KeySourceArray | KeySourceRecipe;
|
|
103
|
+
type IsRecipe<S> = S extends {
|
|
104
104
|
getVariants: () => unknown;
|
|
105
105
|
} ? true : false;
|
|
106
106
|
type SourceKeys<S> = S extends readonly (infer K)[] ? K : S extends {
|
|
@@ -113,27 +113,27 @@ type SourceDefaults<S> = S extends {
|
|
|
113
113
|
getVariants: () => infer Defaults;
|
|
114
114
|
} ? Defaults : {};
|
|
115
115
|
type SourceResultWithStyling<T, S> = Pick<T, Extract<keyof T, SourceKeys<S>>> & Omit<SourceDefaults<S>, keyof T>;
|
|
116
|
-
type SourceResultWithoutStyling<T, S> =
|
|
117
|
-
type BuildSourceResults<T, Sources extends readonly KeySource[], StylingClaimed extends boolean, UsedKeys> = Sources extends readonly [infer Current extends KeySource, ...infer Rest extends readonly KeySource[]] ? [StylingClaimed extends true ? SourceResultWithoutStyling<T, Current> : SourceResultWithStyling<T, Current>, ...BuildSourceResults<T, Rest, StylingClaimed extends true ? true :
|
|
116
|
+
type SourceResultWithoutStyling<T, S> = IsRecipe<S> extends true ? Pick<T, Extract<keyof T, SourceVariantKeys<S>>> & Omit<SourceDefaults<S>, keyof T> : Pick<T, Extract<keyof T, SourceKeys<S>>>;
|
|
117
|
+
type BuildSourceResults<T, Sources extends readonly KeySource[], StylingClaimed extends boolean, UsedKeys> = Sources extends readonly [infer Current extends KeySource, ...infer Rest extends readonly KeySource[]] ? [StylingClaimed extends true ? SourceResultWithoutStyling<T, Current> : SourceResultWithStyling<T, Current>, ...BuildSourceResults<T, Rest, StylingClaimed extends true ? true : IsRecipe<Current>, UsedKeys | SourceKeys<Current>>] : [Omit<T, UsedKeys & (string | number | symbol)>];
|
|
118
118
|
type SplitPropsFunction = <T, const S1 extends KeySource, const Sources extends readonly KeySource[]>(props: T, source1: S1, ...sources: Sources) => SplitPropsFunctionResult<T, S1, Sources>;
|
|
119
|
-
type SplitPropsFunctionResult<T, S1 extends KeySource, Sources extends readonly KeySource[]> = [SourceResultWithStyling<T, S1>, ...BuildSourceResults<T, Sources,
|
|
120
|
-
interface
|
|
121
|
-
(props?:
|
|
122
|
-
class: (props?:
|
|
123
|
-
style: (props?:
|
|
119
|
+
type SplitPropsFunctionResult<T, S1 extends KeySource, Sources extends readonly KeySource[]> = [SourceResultWithStyling<T, S1>, ...BuildSourceResults<T, Sources, IsRecipe<S1>, SourceKeys<S1>>];
|
|
120
|
+
interface ModalRecipe<V, R extends RecipeResult> {
|
|
121
|
+
(props?: RecipeProps<V>): R;
|
|
122
|
+
class: (props?: RecipeProps<V>) => string;
|
|
123
|
+
style: (props?: RecipeProps<V>) => R["style"];
|
|
124
124
|
getVariants: GetVariants<V>;
|
|
125
125
|
variantKeys: (keyof V)[];
|
|
126
|
-
propKeys: (keyof V |
|
|
126
|
+
propKeys: (keyof V | RecipePropKey<R>)[];
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
129
|
-
* A callable Clava
|
|
129
|
+
* A callable Clava recipe returned by `cv()`. It includes the default
|
|
130
130
|
* output mode plus `.jsx()`, `.html()`, and `.htmlObj()` mode helpers.
|
|
131
131
|
*
|
|
132
132
|
* @example
|
|
133
133
|
* ```ts
|
|
134
|
-
* import { type
|
|
134
|
+
* import { type Recipe, cv } from "clava";
|
|
135
135
|
*
|
|
136
|
-
* const button:
|
|
136
|
+
* const button: Recipe<{
|
|
137
137
|
* size: { sm: string; lg: string };
|
|
138
138
|
* }> = cv({
|
|
139
139
|
* variants: {
|
|
@@ -144,17 +144,51 @@ interface ModalComponent<V, R extends ComponentResult> {
|
|
|
144
144
|
* button.jsx({ size: "lg" });
|
|
145
145
|
* ```
|
|
146
146
|
*/
|
|
147
|
-
interface
|
|
148
|
-
jsx:
|
|
149
|
-
html:
|
|
150
|
-
htmlObj:
|
|
147
|
+
interface Recipe<V extends Variants = {}, E extends AnyRecipe[] = [], R extends RecipeResult = StyleClassProps> extends ModalRecipe<MergeVariants<V, E>, R> {
|
|
148
|
+
jsx: ModalRecipe<MergeVariants<V, E>, JSXProps>;
|
|
149
|
+
html: ModalRecipe<MergeVariants<V, E>, HTMLProps>;
|
|
150
|
+
htmlObj: ModalRecipe<MergeVariants<V, E>, HTMLObjProps>;
|
|
151
151
|
}
|
|
152
|
-
type
|
|
152
|
+
type AnyRecipe = Recipe<any, any, any> | ModalRecipe<any, any>;
|
|
153
|
+
type RecipeVariantKeys<T> = T extends {
|
|
154
|
+
variantKeys: (infer Key extends string)[];
|
|
155
|
+
} ? Key : never;
|
|
156
|
+
type MissingRecipeVariantKeys<Base extends AnyRecipe, Candidate> = Candidate extends unknown ? Exclude<Base["variantKeys"][number], RecipeVariantKeys<Candidate>> : never;
|
|
157
|
+
interface RecipeLikeMode<Base extends AnyRecipe, Candidate> {
|
|
158
|
+
(props?: Parameters<Base>[0]): ReturnType<Base>;
|
|
159
|
+
class: Base["class"];
|
|
160
|
+
style: Base["style"];
|
|
161
|
+
getVariants: (variants?: Parameters<Base["getVariants"]>[0]) => ReturnType<Base["getVariants"]> & Partial<Record<RecipeVariantKeys<Candidate>, unknown>>;
|
|
162
|
+
variantKeys: RecipeVariantKeys<Candidate>[];
|
|
163
|
+
propKeys: (RecipeVariantKeys<Candidate> | RecipePropKey<ReturnType<Base>>)[];
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Constrains a recipe to one that supplies every base variant and preserves
|
|
167
|
+
* the base's input and output types. Recipes can be defined independently or
|
|
168
|
+
* through extension. Added variants retain their prop and key types in generic
|
|
169
|
+
* code. Extra metadata does not affect compatibility.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* import { type RecipeLike, type VariantPropsWithRecipe, cv } from "clava";
|
|
174
|
+
*
|
|
175
|
+
* const disclosure = cv({ variants: { $open: "open" } });
|
|
176
|
+
*
|
|
177
|
+
* type DisclosureProps<
|
|
178
|
+
* R extends RecipeLike<typeof disclosure, R> = typeof disclosure,
|
|
179
|
+
* > = VariantPropsWithRecipe<typeof disclosure, R>;
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
type RecipeLike<Base extends Recipe<any, any, any>, Candidate> = [MissingRecipeVariantKeys<Base, Candidate>] extends [never] ? RecipeLikeMode<Base, Candidate> & {
|
|
183
|
+
jsx: RecipeLikeMode<Base["jsx"], Candidate>;
|
|
184
|
+
html: RecipeLikeMode<Base["html"], Candidate>;
|
|
185
|
+
htmlObj: RecipeLikeMode<Base["htmlObj"], Candidate>;
|
|
186
|
+
} : never;
|
|
153
187
|
type MergeExtendedVariants<T> = T extends readonly [infer First, ...infer Rest] ? ExtractVariants<First> & MergeExtendedVariants<Rest> : {};
|
|
154
|
-
type ExtractVariants<T> = T extends
|
|
188
|
+
type ExtractVariants<T> = T extends ModalRecipe<infer V, any> ? V : {};
|
|
155
189
|
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;
|
|
156
190
|
type MergeVariantMaps<Child, Parent> = Omit<Parent, keyof Child> & Child & { [K in keyof Child & keyof Parent]: MergeVariantDefinition<Child[K], Parent[K]>; };
|
|
157
|
-
type MergeVariants<V, E extends
|
|
191
|
+
type MergeVariants<V, E extends AnyRecipe[]> = MergeVariantMaps<NoInfer<V>, MergeExtendedVariants<E>>;
|
|
158
192
|
type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
|
159
193
|
type VariantValue = ClassValue | StyleClassValue;
|
|
160
194
|
type NonNullKeys<T> = { [K in keyof T]: T[K] extends null ? never : K; }[keyof T];
|
|
@@ -209,12 +243,12 @@ type Refine<V> = (context: RefineContext<V>) => VariantValue;
|
|
|
209
243
|
type Variant$1 = ClassValue | Record<string, VariantValue> | ((value: any) => VariantValue);
|
|
210
244
|
type Variants = Record<string, Variant$1>;
|
|
211
245
|
type NullablePartial<T> = T extends Record<string, any> ? { [K in keyof T]?: T[K] | null; } : T | null;
|
|
212
|
-
type ExtendableVariants<V extends Variants, E extends
|
|
246
|
+
type ExtendableVariants<V extends Variants, E extends AnyRecipe[]> = V & { [K in keyof MergeExtendedVariants<E>]?: NullablePartial<MergeExtendedVariants<E>[K]> | Variant$1; };
|
|
213
247
|
//#endregion
|
|
214
248
|
//#region src/index.d.ts
|
|
215
249
|
/**
|
|
216
|
-
* Extracts the variant props inferred for a Clava
|
|
217
|
-
*
|
|
250
|
+
* Extracts the variant props inferred for a Clava recipe. Use it to add a
|
|
251
|
+
* recipe's variant props to framework component props.
|
|
218
252
|
*
|
|
219
253
|
* @example
|
|
220
254
|
* ```ts
|
|
@@ -238,11 +272,42 @@ type ExtendableVariants<V extends Variants, E extends AnyComponent[]> = V & { [K
|
|
|
238
272
|
* };
|
|
239
273
|
* ```
|
|
240
274
|
*/
|
|
241
|
-
export type VariantProps<T extends Pick<
|
|
275
|
+
export type VariantProps<T extends Pick<AnyRecipe, "getVariants">> = ReturnType<T["getVariants"]>;
|
|
276
|
+
/**
|
|
277
|
+
* Combines variant props with a recipe prop named `recipe` by default. The
|
|
278
|
+
* prop is optional when the selected recipe is assignable to the base type,
|
|
279
|
+
* and required when the selected recipe adds variants. Pass a third type
|
|
280
|
+
* argument to use another prop name.
|
|
281
|
+
*
|
|
282
|
+
* When `R` is a union of recipes, the variant props include only the
|
|
283
|
+
* variants that every member defines.
|
|
284
|
+
*
|
|
285
|
+
* When inferring `R`, passing `undefined` or forwarding an optional recipe
|
|
286
|
+
* can fail the recipe constraint. Resolve the optional value before passing
|
|
287
|
+
* it, for example with `recipe: override ?? disclosure`.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```ts
|
|
291
|
+
* import { type RecipeLike, type VariantPropsWithRecipe, cv } from "clava";
|
|
292
|
+
*
|
|
293
|
+
* const disclosure = cv({ variants: { $open: "open" } });
|
|
294
|
+
*
|
|
295
|
+
* type DisclosureProps<
|
|
296
|
+
* R extends RecipeLike<typeof disclosure, R> = typeof disclosure,
|
|
297
|
+
* > = VariantPropsWithRecipe<typeof disclosure, R>;
|
|
298
|
+
*
|
|
299
|
+
* type StyledDisclosureProps<
|
|
300
|
+
* R extends RecipeLike<typeof disclosure, R> = typeof disclosure,
|
|
301
|
+
* > = VariantPropsWithRecipe<typeof disclosure, R, "styles">;
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
export type VariantPropsWithRecipe<Base extends Recipe<any, any, any>, R extends RecipeLike<Base, R>, Name extends string = "recipe"> = VariantProps<R> & PartialVariantKeys<R> & ([R] extends [Base] ? { [Key in Name]?: R; } : { [Key in Name]: R; });
|
|
305
|
+
type PartialVariantKeys<R extends Pick<AnyRecipe, "getVariants">, Key extends PropertyKey = Exclude<UnionKeys<VariantProps<R>>, keyof VariantProps<R>>> = [Key] extends [never] ? unknown : { [K in Key]?: never; };
|
|
306
|
+
type UnionKeys<T> = T extends unknown ? keyof T : never;
|
|
242
307
|
type VariantKey<T> = T extends boolean ? "true" | "false" : Extract<T, string>;
|
|
243
308
|
/**
|
|
244
309
|
* Constrains a variant map to the same value keys as a variant on another
|
|
245
|
-
*
|
|
310
|
+
* recipe. Boolean variants are represented with `"true"` and `"false"`
|
|
246
311
|
* object keys.
|
|
247
312
|
*
|
|
248
313
|
* @example
|
|
@@ -266,10 +331,10 @@ type VariantKey<T> = T extends boolean ? "true" | "false" : Extract<T, string>;
|
|
|
266
331
|
* });
|
|
267
332
|
* ```
|
|
268
333
|
*/
|
|
269
|
-
export type Variant<T extends Pick<
|
|
334
|
+
export type Variant<T extends Pick<AnyRecipe, "getVariants">, K extends keyof VariantProps<T>> = Record<VariantKey<NonNullable<VariantProps<T>[K]>>, ClassValue | StyleClassValue>;
|
|
270
335
|
/**
|
|
271
336
|
* The configuration object accepted by `cv()`. It defines base class/style
|
|
272
|
-
* output, variants, default variants,
|
|
337
|
+
* output, variants, default variants, recipe extensions, and refinement
|
|
273
338
|
* logic.
|
|
274
339
|
*
|
|
275
340
|
* @example
|
|
@@ -293,7 +358,7 @@ export type Variant<T extends Pick<AnyComponent, "getVariants">, K extends keyof
|
|
|
293
358
|
* const alert = cv(config);
|
|
294
359
|
* ```
|
|
295
360
|
*/
|
|
296
|
-
export interface CVConfig<V extends Variants = {}, E extends
|
|
361
|
+
export interface CVConfig<V extends Variants = {}, E extends AnyRecipe[] = []> {
|
|
297
362
|
extend?: E;
|
|
298
363
|
class?: ClassValue;
|
|
299
364
|
style?: StyleValue;
|
|
@@ -306,8 +371,8 @@ interface CreateParams {
|
|
|
306
371
|
}
|
|
307
372
|
/**
|
|
308
373
|
* Splits props into multiple groups based on key sources. Each source gets its
|
|
309
|
-
* own result object containing all its matching keys. The first
|
|
310
|
-
* source claims styling props (class/className/style). Subsequent
|
|
374
|
+
* own result object containing all its matching keys. The first recipe
|
|
375
|
+
* source claims styling props (class/className/style). Subsequent recipes
|
|
311
376
|
* only receive variant props. Arrays receive their listed keys but don't claim
|
|
312
377
|
* styling props. The last element is always the "rest" containing keys not
|
|
313
378
|
* claimed by any source.
|
|
@@ -317,10 +382,10 @@ export declare const splitProps: SplitPropsFunction;
|
|
|
317
382
|
* Creates the cv and cx functions.
|
|
318
383
|
*/
|
|
319
384
|
export declare function create(params?: CreateParams): {
|
|
320
|
-
cv: <V extends Variants = {}, const E extends
|
|
385
|
+
cv: <V extends Variants = {}, const E extends AnyRecipe[] = []>(config?: CVConfig<V, E>) => Recipe<V, E>;
|
|
321
386
|
cx: (...classes: ClassValue$1[]) => string;
|
|
322
387
|
};
|
|
323
|
-
export declare const cv: <V extends Variants = {}, const E extends
|
|
388
|
+
export declare const cv: <V extends Variants = {}, const E extends AnyRecipe[] = []>(config?: CVConfig<V, E>) => Recipe<V, E>;
|
|
324
389
|
/**
|
|
325
390
|
* Joins class values without applying a class transform.
|
|
326
391
|
*
|
|
@@ -328,5 +393,5 @@ export declare const cv: <V extends Variants = {}, const E extends AnyComponent[
|
|
|
328
393
|
*/
|
|
329
394
|
export declare function cx(...classes: ClassValue$1[]): string;
|
|
330
395
|
//#endregion
|
|
331
|
-
export type {
|
|
396
|
+
export type { ClassValue, HTMLObjProps, HTMLProps, JSXProps, Recipe, RecipeLike, StyleClassProps, StyleClassValue, StyleValue };
|
|
332
397
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -256,9 +256,9 @@ function formatCreationStack(frame) {
|
|
|
256
256
|
}
|
|
257
257
|
function isInternalCreationFrame(line) {
|
|
258
258
|
if (line.includes("captureCreationFrame")) return true;
|
|
259
|
-
if (line.startsWith("at
|
|
260
|
-
if (line.startsWith("at
|
|
261
|
-
if (line.startsWith("
|
|
259
|
+
if (line.startsWith("at buildRecipe ")) return true;
|
|
260
|
+
if (line.startsWith("at buildRecipe(")) return true;
|
|
261
|
+
if (line.startsWith("buildRecipe@")) return true;
|
|
262
262
|
if (line.startsWith("at cv ")) return true;
|
|
263
263
|
if (line.startsWith("at cv(")) return true;
|
|
264
264
|
if (line.startsWith("cv@")) return true;
|
|
@@ -310,7 +310,7 @@ function warnRefineLimit({ creationFrame, unstableChanges }) {
|
|
|
310
310
|
}
|
|
311
311
|
if (creationFrame) {
|
|
312
312
|
const creationStack = formatCreationStack(creationFrame);
|
|
313
|
-
if (creationStack) message += `\
|
|
313
|
+
if (creationStack) message += `\nRecipe created at:\n${creationStack}`;
|
|
314
314
|
}
|
|
315
315
|
console.warn(message);
|
|
316
316
|
}
|
|
@@ -402,7 +402,7 @@ function getVariantValueKey(value) {
|
|
|
402
402
|
if (typeof value === "boolean") return String(value);
|
|
403
403
|
}
|
|
404
404
|
const EMPTY_KEYS = [];
|
|
405
|
-
function
|
|
405
|
+
function isRecipeKeySource(source) {
|
|
406
406
|
if (!source) return false;
|
|
407
407
|
if (typeof source !== "object" && typeof source !== "function") return false;
|
|
408
408
|
const typed = source;
|
|
@@ -410,10 +410,10 @@ function isComponentKeySource(source) {
|
|
|
410
410
|
if (!Array.isArray(typed.propKeys)) return false;
|
|
411
411
|
return Array.isArray(typed.variantKeys);
|
|
412
412
|
}
|
|
413
|
-
function splitPropsImpl(selfKeys,
|
|
413
|
+
function splitPropsImpl(selfKeys, selfIsRecipe, props, sources) {
|
|
414
414
|
const sourcesLength = sources.length;
|
|
415
415
|
const results = [];
|
|
416
|
-
let stylingClaimed =
|
|
416
|
+
let stylingClaimed = selfIsRecipe;
|
|
417
417
|
const selfResult = {};
|
|
418
418
|
const selfKeysLength = selfKeys.length;
|
|
419
419
|
for (let i = 0; i < selfKeysLength; i++) {
|
|
@@ -425,11 +425,11 @@ function splitPropsImpl(selfKeys, selfIsComponent, props, sources) {
|
|
|
425
425
|
for (let s = 0; s < sourcesLength; s++) {
|
|
426
426
|
const source = sources[s];
|
|
427
427
|
const sourceResult = {};
|
|
428
|
-
let
|
|
428
|
+
let sourceIsRecipe = false;
|
|
429
429
|
let effectiveKeys;
|
|
430
430
|
if (Array.isArray(source)) effectiveKeys = source;
|
|
431
|
-
else if (
|
|
432
|
-
|
|
431
|
+
else if (isRecipeKeySource(source)) {
|
|
432
|
+
sourceIsRecipe = true;
|
|
433
433
|
effectiveKeys = stylingClaimed ? source.variantKeys : source.propKeys;
|
|
434
434
|
} else effectiveKeys = EMPTY_KEYS;
|
|
435
435
|
const effectiveKeysLength = effectiveKeys.length;
|
|
@@ -439,7 +439,7 @@ function splitPropsImpl(selfKeys, selfIsComponent, props, sources) {
|
|
|
439
439
|
}
|
|
440
440
|
results.push(sourceResult);
|
|
441
441
|
effectiveKeyArrays.push(effectiveKeys);
|
|
442
|
-
if (
|
|
442
|
+
if (sourceIsRecipe && !stylingClaimed) stylingClaimed = true;
|
|
443
443
|
}
|
|
444
444
|
const rest = {};
|
|
445
445
|
const propKeys = Object.keys(props);
|
|
@@ -461,7 +461,7 @@ function splitPropsImpl(selfKeys, selfIsComponent, props, sources) {
|
|
|
461
461
|
}
|
|
462
462
|
const splitProps = ((props, source1, ...sources) => {
|
|
463
463
|
if (Array.isArray(source1)) return splitPropsImpl(source1, false, props, sources);
|
|
464
|
-
if (
|
|
464
|
+
if (isRecipeKeySource(source1)) return splitPropsImpl(source1.propKeys, true, props, sources);
|
|
465
465
|
return splitPropsImpl(EMPTY_KEYS, false, props, sources);
|
|
466
466
|
});
|
|
467
467
|
function buildPrebuiltVariant(variantDef) {
|
|
@@ -491,7 +491,7 @@ function buildPrebuiltVariant(variantDef) {
|
|
|
491
491
|
function create(params = {}) {
|
|
492
492
|
const transformClass = getOwn(params, "transformClass") ?? identityClass;
|
|
493
493
|
const cx = (...classes) => transformClass(clsx(classes));
|
|
494
|
-
const
|
|
494
|
+
const buildRecipe = (config = {}) => {
|
|
495
495
|
const extend = getOwn(config, "extend");
|
|
496
496
|
const variants = getOwn(config, "variants");
|
|
497
497
|
const refine = getOwn(config, "refine");
|
|
@@ -1072,72 +1072,72 @@ function create(params = {}) {
|
|
|
1072
1072
|
functionVariantKeys,
|
|
1073
1073
|
computedDefaultKeys
|
|
1074
1074
|
};
|
|
1075
|
-
const
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
return
|
|
1075
|
+
const initRecipe = (recipe, propKeys, style) => {
|
|
1076
|
+
recipe.class = classFn;
|
|
1077
|
+
recipe.style = style;
|
|
1078
|
+
recipe.getVariants = getVariants;
|
|
1079
|
+
recipe.variantKeys = variantKeys;
|
|
1080
|
+
recipe.propKeys = propKeys;
|
|
1081
|
+
recipe[META_KEY] = meta;
|
|
1082
|
+
return recipe;
|
|
1083
1083
|
};
|
|
1084
|
-
const
|
|
1084
|
+
const defaultRecipe = ((props = {}) => {
|
|
1085
1085
|
const { className, style } = computeResult(props);
|
|
1086
1086
|
return {
|
|
1087
1087
|
class: className,
|
|
1088
1088
|
style
|
|
1089
1089
|
};
|
|
1090
1090
|
});
|
|
1091
|
-
|
|
1091
|
+
initRecipe(defaultRecipe, inputPropsKeys, (props = {}) => {
|
|
1092
1092
|
return computeResult(props).style;
|
|
1093
1093
|
});
|
|
1094
|
-
const
|
|
1094
|
+
const jsxRecipe = ((props = {}) => {
|
|
1095
1095
|
const { className, style } = computeResult(props);
|
|
1096
1096
|
return {
|
|
1097
1097
|
className,
|
|
1098
1098
|
style
|
|
1099
1099
|
};
|
|
1100
1100
|
});
|
|
1101
|
-
|
|
1101
|
+
initRecipe(jsxRecipe, [
|
|
1102
1102
|
"className",
|
|
1103
1103
|
"style",
|
|
1104
1104
|
...variantKeys
|
|
1105
1105
|
], (props = {}) => computeResult(props).style);
|
|
1106
|
-
const
|
|
1106
|
+
const htmlRecipe = ((props = {}) => {
|
|
1107
1107
|
const { className, style } = computeResult(props);
|
|
1108
1108
|
return {
|
|
1109
1109
|
class: className,
|
|
1110
1110
|
style: styleValueToHTMLStyle(style)
|
|
1111
1111
|
};
|
|
1112
1112
|
});
|
|
1113
|
-
|
|
1113
|
+
initRecipe(htmlRecipe, [
|
|
1114
1114
|
"class",
|
|
1115
1115
|
"style",
|
|
1116
1116
|
...variantKeys
|
|
1117
1117
|
], (props = {}) => styleValueToHTMLStyle(computeResult(props).style));
|
|
1118
|
-
const
|
|
1118
|
+
const htmlObjRecipe = ((props = {}) => {
|
|
1119
1119
|
const { className, style } = computeResult(props);
|
|
1120
1120
|
return {
|
|
1121
1121
|
class: className,
|
|
1122
1122
|
style: styleValueToHTMLObjStyle(style)
|
|
1123
1123
|
};
|
|
1124
1124
|
});
|
|
1125
|
-
|
|
1125
|
+
initRecipe(htmlObjRecipe, [
|
|
1126
1126
|
"class",
|
|
1127
1127
|
"style",
|
|
1128
1128
|
...variantKeys
|
|
1129
1129
|
], (props = {}) => styleValueToHTMLObjStyle(computeResult(props).style));
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1130
|
+
defaultRecipe.jsx = jsxRecipe;
|
|
1131
|
+
defaultRecipe.html = htmlRecipe;
|
|
1132
|
+
defaultRecipe.htmlObj = htmlObjRecipe;
|
|
1133
1133
|
return {
|
|
1134
|
-
|
|
1134
|
+
recipe: defaultRecipe,
|
|
1135
1135
|
meta
|
|
1136
1136
|
};
|
|
1137
1137
|
};
|
|
1138
1138
|
return build(initialExtensions);
|
|
1139
1139
|
};
|
|
1140
|
-
const cv = (config = {}) =>
|
|
1140
|
+
const cv = (config = {}) => buildRecipe(config).recipe;
|
|
1141
1141
|
return {
|
|
1142
1142
|
cv,
|
|
1143
1143
|
cx
|