clava 0.6.4 → 0.7.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/src/index.ts CHANGED
@@ -7,19 +7,20 @@ import {
7
7
  warnRefineLimit,
8
8
  } from "./refine-warning.ts";
9
9
  import type {
10
- AnyComponent,
11
- CVComponent,
10
+ AnyRecipe,
12
11
  ClassValue,
13
- ComponentProps,
14
- ComponentResult,
15
12
  DefaultVariants,
16
13
  ExtendableVariants,
17
14
  HTMLObjProps,
18
15
  HTMLProps,
19
16
  JSXProps,
20
- KeySourceComponent,
17
+ KeySourceRecipe,
21
18
  MergeVariants,
22
- ModalComponent,
19
+ ModalRecipe,
20
+ Recipe,
21
+ RecipeLike,
22
+ RecipeProps,
23
+ RecipeResult,
23
24
  Refine,
24
25
  SplitPropsFunction,
25
26
  StyleClassProps,
@@ -38,8 +39,8 @@ import {
38
39
  } from "./utils.ts";
39
40
 
40
41
  // Internal compute path: pushes the variant classes contributed by this
41
- // component (and its extends chain) into `classesOut` and merges any styles
42
- // into `styleOut`. Base class is handled by callers via ComponentMeta.baseClass
42
+ // recipe (and its extends chain) into `classesOut` and merges any styles
43
+ // into `styleOut`. Base class is handled by callers via RecipeMeta.baseClass
43
44
  // to avoid string-parsing round trips. Both outputs are mutated in place to
44
45
  // avoid intermediate allocations.
45
46
  type ComputeFn = (
@@ -82,38 +83,38 @@ type ComputedDefaultVariantFn = (
82
83
  variants: Readonly<Record<string, unknown>>,
83
84
  ) => unknown;
84
85
 
85
- // Internal metadata stored on components but hidden from public types.
86
- interface ComponentMeta {
86
+ // Internal metadata stored on recipes but hidden from public types.
87
+ interface RecipeMeta {
87
88
  identity?: object;
88
- extends?: ComponentMeta[];
89
- rebuild?: (extensions: ComponentMeta[]) => ComponentMeta;
89
+ extends?: RecipeMeta[];
90
+ rebuild?: (extensions: RecipeMeta[]) => RecipeMeta;
90
91
  baseClass: string;
91
92
  staticDefaults: Record<string, unknown>;
92
- // Performs a single compute pass for extending components, returning the
93
+ // Performs a single compute pass for extending recipes, returning the
93
94
  // resolved variants while pushing classes and styles into the output values.
94
95
  compute: ComputeOnceFn;
95
96
  resolveRefine: ResolveRefineOnceFn | null;
96
97
  // Reference identity is used to detect mixed-factory `extend`. When a
97
- // component is extended by a parent from a different `create()` call, the
98
+ // recipe is extended by a parent from a different `create()` call, the
98
99
  // parent applies this transform to the extend's contribution before joining,
99
100
  // preserving each factory's transform boundary.
100
101
  transformClass: (className: string) => string;
101
- // Variant keys whose effective definition in this component's chain is a
102
- // function. An extending component that supplies a non-function variant for
102
+ // Variant keys whose effective definition in this recipe's chain is a
103
+ // function. An extending recipe that supplies a non-function variant for
103
104
  // the same key uses this to tell us to skip that key (matching the
104
105
  // type-level "function variant is replaced by anything in the child" rule).
105
106
  // Empty when no key in this chain is a function variant.
106
107
  functionVariantKeys: Set<string>;
107
- // Variant keys with computed defaults anywhere in this component's chain.
108
- // Child components use this to preserve inherited computed defaults through
108
+ // Variant keys with computed defaults anywhere in this recipe's chain.
109
+ // Child recipes use this to preserve inherited computed defaults through
109
110
  // `defaultValue` without preserving their own prior computed result.
110
111
  computedDefaultKeys: Set<string>;
111
112
  }
112
113
 
113
114
  const META_KEY = "__meta";
114
115
 
115
- interface ComponentWithMeta {
116
- [META_KEY]?: ComponentMeta;
116
+ interface RecipeWithMeta {
117
+ [META_KEY]?: RecipeMeta;
117
118
  }
118
119
 
119
120
  const EMPTY_DEFAULTS: Record<string, unknown> = {};
@@ -121,13 +122,13 @@ const EMPTY_DEFAULTS: Record<string, unknown> = {};
121
122
  // Prune shared recipes before compiling their parent's compute path. Keeping
122
123
  // the first path preserves its overrides and factory transform boundaries.
123
124
  function deduplicateExtensions(
124
- extensions: ComponentMeta[],
125
+ extensions: RecipeMeta[],
125
126
  seen = new Set<object>(),
126
- ): ComponentMeta[] {
127
+ ): RecipeMeta[] {
127
128
  if (extensions.length === 0) {
128
129
  return extensions;
129
130
  }
130
- const result: ComponentMeta[] = [];
131
+ const result: RecipeMeta[] = [];
131
132
  let changed = false;
132
133
  for (const meta of extensions) {
133
134
  const identity = getOwn(meta, "identity") ?? meta;
@@ -206,12 +207,13 @@ export type {
206
207
  JSXProps,
207
208
  HTMLProps,
208
209
  HTMLObjProps,
209
- CVComponent,
210
+ Recipe,
211
+ RecipeLike,
210
212
  };
211
213
 
212
214
  /**
213
- * Extracts the variant props inferred for a Clava component. Use it to add a
214
- * component's variant props to framework component props.
215
+ * Extracts the variant props inferred for a Clava recipe. Use it to add a
216
+ * recipe's variant props to framework component props.
215
217
  *
216
218
  * @example
217
219
  * ```ts
@@ -235,15 +237,48 @@ export type {
235
237
  * };
236
238
  * ```
237
239
  */
238
- export type VariantProps<T extends Pick<AnyComponent, "getVariants">> =
239
- ReturnType<T["getVariants"]>;
240
+ export type VariantProps<T extends Pick<AnyRecipe, "getVariants">> = ReturnType<
241
+ T["getVariants"]
242
+ >;
243
+
244
+ /**
245
+ * Combines variant props with a recipe prop named `recipe` by default. The
246
+ * prop is optional when the selected recipe is assignable to the base type,
247
+ * and required when the selected recipe adds variants. Pass a third type
248
+ * argument to use another prop name.
249
+ *
250
+ * When inferring `R`, passing `undefined` or forwarding an optional recipe
251
+ * can fail the recipe constraint. Resolve the optional value before passing
252
+ * it, for example with `recipe: override ?? disclosure`.
253
+ *
254
+ * @example
255
+ * ```ts
256
+ * import { type RecipeLike, type VariantPropsWithRecipe, cv } from "clava";
257
+ *
258
+ * const disclosure = cv({ variants: { $open: "open" } });
259
+ *
260
+ * type DisclosureProps<
261
+ * R extends RecipeLike<typeof disclosure, R> = typeof disclosure,
262
+ * > = VariantPropsWithRecipe<typeof disclosure, R>;
263
+ *
264
+ * type StyledDisclosureProps<
265
+ * R extends RecipeLike<typeof disclosure, R> = typeof disclosure,
266
+ * > = VariantPropsWithRecipe<typeof disclosure, R, "styles">;
267
+ * ```
268
+ */
269
+ export type VariantPropsWithRecipe<
270
+ Base extends Recipe<any, any, any>,
271
+ R extends RecipeLike<Base, R>,
272
+ Name extends string = "recipe",
273
+ > = VariantProps<R> &
274
+ ([R] extends [Base] ? { [Key in Name]?: R } : { [Key in Name]: R });
240
275
 
241
276
  // Variant props expose booleans, but variant object keys are always strings.
242
277
  type VariantKey<T> = T extends boolean ? "true" | "false" : Extract<T, string>;
243
278
 
244
279
  /**
245
280
  * Constrains a variant map to the same value keys as a variant on another
246
- * component. Boolean variants are represented with `"true"` and `"false"`
281
+ * recipe. Boolean variants are represented with `"true"` and `"false"`
247
282
  * object keys.
248
283
  *
249
284
  * @example
@@ -268,7 +303,7 @@ type VariantKey<T> = T extends boolean ? "true" | "false" : Extract<T, string>;
268
303
  * ```
269
304
  */
270
305
  export type Variant<
271
- T extends Pick<AnyComponent, "getVariants">,
306
+ T extends Pick<AnyRecipe, "getVariants">,
272
307
  K extends keyof VariantProps<T>,
273
308
  > = Record<
274
309
  VariantKey<NonNullable<VariantProps<T>[K]>>,
@@ -277,7 +312,7 @@ export type Variant<
277
312
 
278
313
  /**
279
314
  * The configuration object accepted by `cv()`. It defines base class/style
280
- * output, variants, default variants, component extensions, and refinement
315
+ * output, variants, default variants, recipe extensions, and refinement
281
316
  * logic.
282
317
  *
283
318
  * @example
@@ -301,10 +336,7 @@ export type Variant<
301
336
  * const alert = cv(config);
302
337
  * ```
303
338
  */
304
- export interface CVConfig<
305
- V extends Variants = {},
306
- E extends AnyComponent[] = [],
307
- > {
339
+ export interface CVConfig<V extends Variants = {}, E extends AnyRecipe[] = []> {
308
340
  extend?: E;
309
341
  class?: ClassValue;
310
342
  style?: StyleValue;
@@ -344,7 +376,7 @@ function normalizeStyle(style: unknown): StyleValue {
344
376
 
345
377
  /**
346
378
  * Pre-extracts the class and (normalized) style from a variant value once at
347
- * component creation time. Returns `null` if the value contributes nothing.
379
+ * recipe creation time. Returns `null` if the value contributes nothing.
348
380
  */
349
381
  interface PrebuiltValue {
350
382
  class: ClassValue;
@@ -387,7 +419,7 @@ function getVariantValueKey(value: unknown): string | undefined {
387
419
 
388
420
  const EMPTY_KEYS: readonly string[] = [];
389
421
 
390
- function isComponentKeySource(source: unknown): source is KeySourceComponent {
422
+ function isRecipeKeySource(source: unknown): source is KeySourceRecipe {
391
423
  if (!source) return false;
392
424
  if (typeof source !== "object" && typeof source !== "function") {
393
425
  return false;
@@ -400,19 +432,19 @@ function isComponentKeySource(source: unknown): source is KeySourceComponent {
400
432
 
401
433
  /**
402
434
  * Splits props into multiple groups based on key sources. Only the first
403
- * component claims styling props (class/className/style). Subsequent components
435
+ * recipe claims styling props (class/className/style). Subsequent recipes
404
436
  * only receive variant props. Arrays always receive their listed keys but don't
405
437
  * claim styling props.
406
438
  */
407
439
  function splitPropsImpl(
408
440
  selfKeys: readonly string[],
409
- selfIsComponent: boolean,
441
+ selfIsRecipe: boolean,
410
442
  props: Record<string, unknown>,
411
443
  sources: unknown[],
412
444
  ): Record<string, unknown>[] {
413
445
  const sourcesLength = sources.length;
414
446
  const results: Record<string, unknown>[] = [];
415
- let stylingClaimed = selfIsComponent;
447
+ let stylingClaimed = selfIsRecipe;
416
448
 
417
449
  const selfResult: Record<string, unknown> = {};
418
450
  const selfKeysLength = selfKeys.length;
@@ -431,12 +463,12 @@ function splitPropsImpl(
431
463
  for (let s = 0; s < sourcesLength; s++) {
432
464
  const source = sources[s];
433
465
  const sourceResult: Record<string, unknown> = {};
434
- let sourceIsComponent = false;
466
+ let sourceIsRecipe = false;
435
467
  let effectiveKeys: readonly string[];
436
468
  if (Array.isArray(source)) {
437
469
  effectiveKeys = source;
438
- } else if (isComponentKeySource(source)) {
439
- sourceIsComponent = true;
470
+ } else if (isRecipeKeySource(source)) {
471
+ sourceIsRecipe = true;
440
472
  effectiveKeys = stylingClaimed ? source.variantKeys : source.propKeys;
441
473
  } else {
442
474
  effectiveKeys = EMPTY_KEYS;
@@ -452,7 +484,7 @@ function splitPropsImpl(
452
484
  results.push(sourceResult);
453
485
  effectiveKeyArrays.push(effectiveKeys);
454
486
 
455
- if (sourceIsComponent && !stylingClaimed) {
487
+ if (sourceIsRecipe && !stylingClaimed) {
456
488
  stylingClaimed = true;
457
489
  }
458
490
  }
@@ -481,8 +513,8 @@ function splitPropsImpl(
481
513
 
482
514
  /**
483
515
  * Splits props into multiple groups based on key sources. Each source gets its
484
- * own result object containing all its matching keys. The first component
485
- * source claims styling props (class/className/style). Subsequent components
516
+ * own result object containing all its matching keys. The first recipe
517
+ * source claims styling props (class/className/style). Subsequent recipes
486
518
  * only receive variant props. Arrays receive their listed keys but don't claim
487
519
  * styling props. The last element is always the "rest" containing keys not
488
520
  * claimed by any source.
@@ -495,7 +527,7 @@ export const splitProps: SplitPropsFunction = ((
495
527
  if (Array.isArray(source1)) {
496
528
  return splitPropsImpl(source1, false, props, sources);
497
529
  }
498
- if (isComponentKeySource(source1)) {
530
+ if (isRecipeKeySource(source1)) {
499
531
  return splitPropsImpl(source1.propKeys, true, props, sources);
500
532
  }
501
533
  return splitPropsImpl(EMPTY_KEYS, false, props, sources);
@@ -558,12 +590,12 @@ export function create(params: CreateParams = {}) {
558
590
 
559
591
  const cx = (...classes: ClsxClassValue[]) => transformClass(clsx(classes));
560
592
 
561
- const buildComponent = <
593
+ const buildRecipe = <
562
594
  V extends Variants = {},
563
- const E extends AnyComponent[] = [],
595
+ const E extends AnyRecipe[] = [],
564
596
  >(
565
597
  config: CVConfig<V, E> = {},
566
- ): { component: CVComponent<V, E>; meta: ComponentMeta } => {
598
+ ): { recipe: Recipe<V, E>; meta: RecipeMeta } => {
567
599
  type MergedVariants = MergeVariants<V, E>;
568
600
 
569
601
  // Compile caller-owned configuration once. Rebuilding a pruned branch
@@ -576,7 +608,7 @@ export function create(params: CreateParams = {}) {
576
608
  const baseClassValue = getOwn(config, "class");
577
609
  const variantKeySet = new Set<string>();
578
610
  const inheritedComputedDefaultKeys = new Set<string>();
579
- const originalExtMetas: ComponentMeta[] = [];
611
+ const originalExtMetas: RecipeMeta[] = [];
580
612
  if (extend) {
581
613
  for (const ext of extend) {
582
614
  const extKeys = ext.variantKeys as readonly string[];
@@ -585,7 +617,7 @@ export function create(params: CreateParams = {}) {
585
617
  if (key === undefined) continue;
586
618
  variantKeySet.add(key);
587
619
  }
588
- const meta = (ext as AnyComponent & ComponentWithMeta)[META_KEY];
620
+ const meta = (ext as AnyRecipe & RecipeWithMeta)[META_KEY];
589
621
  if (!meta) continue;
590
622
  originalExtMetas.push(meta);
591
623
  // A later branch can read a computed default contributed by the first
@@ -682,10 +714,10 @@ export function create(params: CreateParams = {}) {
682
714
  // Only extension-dependent state is rebuilt. Own tables, callbacks,
683
715
  // inheritance visibility, and the creation frame stay shared and unchanged.
684
716
  const build = (
685
- extMetas: ComponentMeta[],
717
+ extMetas: RecipeMeta[],
686
718
  ): {
687
- component: CVComponent<V, E>;
688
- meta: ComponentMeta;
719
+ recipe: Recipe<V, E>;
720
+ meta: RecipeMeta;
689
721
  } => {
690
722
  const hasExtend = extMetas.length > 0;
691
723
  const extCount = extMetas.length;
@@ -733,9 +765,9 @@ export function create(params: CreateParams = {}) {
733
765
  }
734
766
 
735
767
  // Filter to only extends with computed default or refine work in their
736
- // chain. Those are the components that can change resolved variants across
768
+ // chain. Those are the recipes that can change resolved variants across
737
769
  // fixed-point iterations.
738
- const extMetasWithRefine: ComponentMeta[] = [];
770
+ const extMetasWithRefine: RecipeMeta[] = [];
739
771
  for (let i = 0; i < extCount; i++) {
740
772
  const meta = extMetas[i];
741
773
  if (meta.resolveRefine) {
@@ -747,7 +779,7 @@ export function create(params: CreateParams = {}) {
747
779
  // Only a `refine` callback protects variants, through `setVariants`. This
748
780
  // over-approximates: `extMetasWithRefineCount` also counts extends that
749
781
  // only have computed defaults. Tightening it would mean tracking `refine`
750
- // separately in `ComponentMeta` to save one allocation. The record inside
782
+ // separately in `RecipeMeta` to save one allocation. The record inside
751
783
  // the holder is created only when a callback assigns something.
752
784
  const canProtectVariants = !!refine || extMetasWithRefineCount > 0;
753
785
 
@@ -761,10 +793,10 @@ export function create(params: CreateParams = {}) {
761
793
  computedDefaultCount > 0 || inheritedComputedDefaultKeys.size > 0;
762
794
 
763
795
  // Function variant keys inherited from extends, filtered through this
764
- // component's own variants: a static (object/shorthand) variant in this
765
- // component replaces an inherited function variant for the same key.
766
- // The closure is exposed on `ComponentMeta` so any further extending
767
- // component can detect "ancestor's effective variant for K is a function"
796
+ // recipe's own variants: a static (object/shorthand) variant in this
797
+ // recipe replaces an inherited function variant for the same key.
798
+ // The closure is exposed on `RecipeMeta` so any further extending
799
+ // recipe can detect "ancestor's effective variant for K is a function"
768
800
  // and skip it when overriding K with a non-function.
769
801
  const functionVariantKeys = new Set<string>();
770
802
  for (let i = 0; i < extCount; i++) {
@@ -778,8 +810,8 @@ export function create(params: CreateParams = {}) {
778
810
  functionVariantKeys.add(functionVariantNames[i]);
779
811
  }
780
812
  for (let i = 0; i < variantEntryCount; i++) {
781
- // A static variant in this component replaces an inherited function
782
- // variant for the same key; from this component onward, the key is no
813
+ // A static variant in this recipe replaces an inherited function
814
+ // variant for the same key; from this recipe onward, the key is no
783
815
  // longer a function variant.
784
816
  functionVariantKeys.delete(variantEntryNames[i]);
785
817
  }
@@ -803,7 +835,7 @@ export function create(params: CreateParams = {}) {
803
835
  }
804
836
  }
805
837
 
806
- // A static variant in this component replaces an inherited function
838
+ // A static variant in this recipe replaces an inherited function
807
839
  // variant, so the ancestor must skip that key.
808
840
  if (variantEntryCount > 0 && extCount > 0) {
809
841
  for (let i = 0; i < variantEntryCount; i++) {
@@ -1016,7 +1048,7 @@ export function create(params: CreateParams = {}) {
1016
1048
  if (refine) {
1017
1049
  let ownVariants = resolved;
1018
1050
  if (filterOwnVariants) {
1019
- // When this component is being extended, `resolved` is the parent's
1051
+ // When this recipe is being extended, `resolved` is the parent's
1020
1052
  // workingResolved (a superset of our variant keys). Filter to our own
1021
1053
  // keys for `ctx.variants` so the user's `refine` callback sees the
1022
1054
  // shape declared by `VariantValues<V>` and not foreign parent keys.
@@ -1049,7 +1081,7 @@ export function create(params: CreateParams = {}) {
1049
1081
  }
1050
1082
  for (const key in newVariants) {
1051
1083
  if (!hasOwn(newVariants, key)) continue;
1052
- // `disabledVariantKeys` is empty unless this component disables a
1084
+ // `disabledVariantKeys` is empty unless this recipe disables a
1053
1085
  // variant, so the lookup replaces a `hasAnyDisabled` branch. The
1054
1086
  // key is checked before the value is read, because reading it can
1055
1087
  // run a caller-defined accessor.
@@ -1128,8 +1160,8 @@ export function create(params: CreateParams = {}) {
1128
1160
  };
1129
1161
 
1130
1162
  // Core compute path. Called both for top-level rendering (via
1131
- // `computeResult`) and recursively when this component is used as an
1132
- // `extend` target by another component. Pushes variant classes (excluding
1163
+ // `computeResult`) and recursively when this recipe is used as an
1164
+ // `extend` target by another recipe. Pushes variant classes (excluding
1133
1165
  // base class) into `classesOut` and merges styles into `styleOut`.
1134
1166
  const computeOnce: ComputeOnceFn = (
1135
1167
  resolved,
@@ -1234,8 +1266,8 @@ export function create(params: CreateParams = {}) {
1234
1266
  }
1235
1267
  }
1236
1268
 
1237
- // Run own computed defaults after extended components so defaults resolve
1238
- // from base to child. They still run before this component's `refine`.
1269
+ // Run own computed defaults after extended recipes so defaults resolve
1270
+ // from base to child. They still run before this recipe's `refine`.
1239
1271
  if (!renderOnly && computedDefaultCount > 0) {
1240
1272
  workingResolved = runComputedDefaults(
1241
1273
  workingResolved,
@@ -1247,7 +1279,7 @@ export function create(params: CreateParams = {}) {
1247
1279
  }
1248
1280
 
1249
1281
  // Run own `refine` (if any). May modify resolved variants and emit
1250
- // classes and styles that are applied after this component's variants.
1282
+ // classes and styles that are applied after this recipe's variants.
1251
1283
  if (refine) {
1252
1284
  const refineResult = runRefineContext(
1253
1285
  workingResolved,
@@ -1602,7 +1634,7 @@ export function create(params: CreateParams = {}) {
1602
1634
  // Top-level: resolves variants from user props, calls compute, then
1603
1635
  // assembles className and style with user-provided class/style overrides.
1604
1636
  const computeResult = (
1605
- props: ComponentProps<MergedVariants> = EMPTY_DEFAULTS as ComponentProps<MergedVariants>,
1637
+ props: RecipeProps<MergedVariants> = EMPTY_DEFAULTS as RecipeProps<MergedVariants>,
1606
1638
  ): { className: string; style: StyleValue } => {
1607
1639
  const propsRecord = props as Record<string, unknown>;
1608
1640
 
@@ -1684,7 +1716,7 @@ export function create(params: CreateParams = {}) {
1684
1716
  // this record cannot see an undeclared key as an explicitly passed
1685
1717
  // variant, and cannot re-run a caller accessor once per refine pass. The
1686
1718
  // gate is narrower than that purpose: it misses a chain whose only
1687
- // computed default is this component's own.
1719
+ // computed default is this recipe's own.
1688
1720
  // See https://github.com/ariakit/clava/issues/494
1689
1721
  if (variants && extMetasWithRefineCount > 0) {
1690
1722
  variantProps = {};
@@ -1716,11 +1748,11 @@ export function create(params: CreateParams = {}) {
1716
1748
  ? clsx(extBaseClassesArr, baseClass)
1717
1749
  : baseClass;
1718
1750
 
1719
- // Shared closures across the default and modal components.
1720
- const classFn = (props: ComponentProps<MergedVariants> = {}) => {
1751
+ // Shared closures across the default and modal recipes.
1752
+ const classFn = (props: RecipeProps<MergedVariants> = {}) => {
1721
1753
  return computeResult(props).className;
1722
1754
  };
1723
- const meta: ComponentMeta = {
1755
+ const meta: RecipeMeta = {
1724
1756
  identity,
1725
1757
  extends: extMetas,
1726
1758
  rebuild: (extensions) => build(extensions).meta,
@@ -1733,81 +1765,75 @@ export function create(params: CreateParams = {}) {
1733
1765
  computedDefaultKeys,
1734
1766
  };
1735
1767
 
1736
- const initComponent = <
1737
- R extends ComponentResult,
1738
- T extends ModalComponent<MergedVariants, R>,
1768
+ const initRecipe = <
1769
+ R extends RecipeResult,
1770
+ T extends ModalRecipe<MergedVariants, R>,
1739
1771
  >(
1740
- c: T,
1772
+ recipe: T,
1741
1773
  propKeys: string[],
1742
1774
  style: T["style"],
1743
1775
  ): T => {
1744
- c.class = classFn;
1745
- c.style = style;
1746
- c.getVariants = getVariants;
1747
- c.variantKeys = variantKeys;
1748
- c.propKeys = propKeys;
1749
- (c as AnyComponent & ComponentWithMeta)[META_KEY] = meta;
1750
- return c;
1776
+ recipe.class = classFn;
1777
+ recipe.style = style;
1778
+ recipe.getVariants = getVariants;
1779
+ recipe.variantKeys = variantKeys;
1780
+ recipe.propKeys = propKeys;
1781
+ (recipe as AnyRecipe & RecipeWithMeta)[META_KEY] = meta;
1782
+ return recipe;
1751
1783
  };
1752
1784
 
1753
- // Default component
1754
- const defaultComponent = ((
1755
- props: ComponentProps<MergedVariants> = {},
1756
- ) => {
1785
+ // Default recipe
1786
+ const defaultRecipe = ((props: RecipeProps<MergedVariants> = {}) => {
1757
1787
  const { className, style } = computeResult(props);
1758
1788
  return { class: className, style };
1759
- }) as CVComponent<V, E>;
1760
- initComponent(defaultComponent, inputPropsKeys, (props = {}) => {
1789
+ }) as Recipe<V, E>;
1790
+ initRecipe(defaultRecipe, inputPropsKeys, (props = {}) => {
1761
1791
  return computeResult(props).style;
1762
1792
  });
1763
1793
 
1764
- // JSX component
1765
- const jsxComponent = ((props: ComponentProps<MergedVariants> = {}) => {
1794
+ // JSX recipe
1795
+ const jsxRecipe = ((props: RecipeProps<MergedVariants> = {}) => {
1766
1796
  const { className, style } = computeResult(props);
1767
1797
  return { className, style };
1768
- }) as ModalComponent<MergedVariants, JSXProps>;
1769
- initComponent(
1770
- jsxComponent,
1798
+ }) as ModalRecipe<MergedVariants, JSXProps>;
1799
+ initRecipe(
1800
+ jsxRecipe,
1771
1801
  ["className", "style", ...variantKeys],
1772
1802
  (props = {}) => computeResult(props).style,
1773
1803
  );
1774
1804
 
1775
- // HTML component
1776
- const htmlComponent = ((props: ComponentProps<MergedVariants> = {}) => {
1805
+ // HTML recipe
1806
+ const htmlRecipe = ((props: RecipeProps<MergedVariants> = {}) => {
1777
1807
  const { className, style } = computeResult(props);
1778
1808
  return { class: className, style: styleValueToHTMLStyle(style) };
1779
- }) as ModalComponent<MergedVariants, HTMLProps>;
1780
- initComponent(
1781
- htmlComponent,
1782
- ["class", "style", ...variantKeys],
1783
- (props = {}) => styleValueToHTMLStyle(computeResult(props).style),
1809
+ }) as ModalRecipe<MergedVariants, HTMLProps>;
1810
+ initRecipe(htmlRecipe, ["class", "style", ...variantKeys], (props = {}) =>
1811
+ styleValueToHTMLStyle(computeResult(props).style),
1784
1812
  );
1785
1813
 
1786
- // HTMLObj component
1787
- const htmlObjComponent = ((
1788
- props: ComponentProps<MergedVariants> = {},
1789
- ) => {
1814
+ // HTMLObj recipe
1815
+ const htmlObjRecipe = ((props: RecipeProps<MergedVariants> = {}) => {
1790
1816
  const { className, style } = computeResult(props);
1791
1817
  return { class: className, style: styleValueToHTMLObjStyle(style) };
1792
- }) as ModalComponent<MergedVariants, HTMLObjProps>;
1793
- initComponent(
1794
- htmlObjComponent,
1818
+ }) as ModalRecipe<MergedVariants, HTMLObjProps>;
1819
+ initRecipe(
1820
+ htmlObjRecipe,
1795
1821
  ["class", "style", ...variantKeys],
1796
1822
  (props = {}) => styleValueToHTMLObjStyle(computeResult(props).style),
1797
1823
  );
1798
1824
 
1799
- defaultComponent.jsx = jsxComponent;
1800
- defaultComponent.html = htmlComponent;
1801
- defaultComponent.htmlObj = htmlObjComponent;
1825
+ defaultRecipe.jsx = jsxRecipe;
1826
+ defaultRecipe.html = htmlRecipe;
1827
+ defaultRecipe.htmlObj = htmlObjRecipe;
1802
1828
 
1803
- return { component: defaultComponent, meta };
1829
+ return { recipe: defaultRecipe, meta };
1804
1830
  };
1805
1831
  return build(initialExtensions);
1806
1832
  };
1807
1833
 
1808
- const cv = <V extends Variants = {}, const E extends AnyComponent[] = []>(
1834
+ const cv = <V extends Variants = {}, const E extends AnyRecipe[] = []>(
1809
1835
  config: CVConfig<V, E> = {},
1810
- ): CVComponent<V, E> => buildComponent(config).component;
1836
+ ): Recipe<V, E> => buildRecipe(config).recipe;
1811
1837
 
1812
1838
  return { cv, cx };
1813
1839
  }
@@ -23,7 +23,7 @@ export const REFINE_UNSTABLE_TRACKING_WINDOW = 10;
23
23
  // build time can drop the entire warning machinery. The underlying `.stack`
24
24
  // string is formatted lazily on first access in every major engine (V8,
25
25
  // SpiderMonkey, JavaScriptCore), so holding the captured frame for the
26
- // lifetime of the component is cheap when no warning fires.
26
+ // lifetime of the recipe is cheap when no warning fires.
27
27
  export function captureCreationFrame(
28
28
  skipFn: Function,
29
29
  ): CreationFrame | undefined {
@@ -36,7 +36,7 @@ export function captureCreationFrame(
36
36
  // Engines without `Error.captureStackTrace` (SpiderMonkey, JavaScriptCore)
37
37
  // can't strip internal frames, but their `Error.stack` getter is still
38
38
  // lazy, so returning the Error instance defers the format cost. The
39
- // resulting trace includes extra frames from this helper, `buildComponent`,
39
+ // resulting trace includes extra frames from this helper, `buildRecipe`,
40
40
  // and `cv` itself.
41
41
  return new Error();
42
42
  }
@@ -68,9 +68,9 @@ export function formatCreationStack(frame: CreationFrame): string | undefined {
68
68
 
69
69
  function isInternalCreationFrame(line: string): boolean {
70
70
  if (line.includes("captureCreationFrame")) return true;
71
- if (line.startsWith("at buildComponent ")) return true;
72
- if (line.startsWith("at buildComponent(")) return true;
73
- if (line.startsWith("buildComponent@")) return true;
71
+ if (line.startsWith("at buildRecipe ")) return true;
72
+ if (line.startsWith("at buildRecipe(")) return true;
73
+ if (line.startsWith("buildRecipe@")) return true;
74
74
  if (line.startsWith("at cv ")) return true;
75
75
  if (line.startsWith("at cv(")) return true;
76
76
  if (line.startsWith("cv@")) return true;
@@ -151,7 +151,7 @@ export function warnRefineLimit({
151
151
  if (creationFrame) {
152
152
  const creationStack = formatCreationStack(creationFrame);
153
153
  if (creationStack) {
154
- message += `\nComponent created at:\n${creationStack}`;
154
+ message += `\nRecipe created at:\n${creationStack}`;
155
155
  }
156
156
  }
157
157
  console.warn(message);