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/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,65 @@ 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 `R` is a union of recipes, the variant props include only the
251
+ * variants that every member defines.
252
+ *
253
+ * When inferring `R`, passing `undefined` or forwarding an optional recipe
254
+ * can fail the recipe constraint. Resolve the optional value before passing
255
+ * it, for example with `recipe: override ?? disclosure`.
256
+ *
257
+ * @example
258
+ * ```ts
259
+ * import { type RecipeLike, type VariantPropsWithRecipe, cv } from "clava";
260
+ *
261
+ * const disclosure = cv({ variants: { $open: "open" } });
262
+ *
263
+ * type DisclosureProps<
264
+ * R extends RecipeLike<typeof disclosure, R> = typeof disclosure,
265
+ * > = VariantPropsWithRecipe<typeof disclosure, R>;
266
+ *
267
+ * type StyledDisclosureProps<
268
+ * R extends RecipeLike<typeof disclosure, R> = typeof disclosure,
269
+ * > = VariantPropsWithRecipe<typeof disclosure, R, "styles">;
270
+ * ```
271
+ */
272
+ export type VariantPropsWithRecipe<
273
+ Base extends Recipe<any, any, any>,
274
+ R extends RecipeLike<Base, R>,
275
+ Name extends string = "recipe",
276
+ > = VariantProps<R> &
277
+ PartialVariantKeys<R> &
278
+ ([R] extends [Base] ? { [Key in Name]?: R } : { [Key in Name]: R });
279
+
280
+ // Blocks variants that only some union members define, because the selected
281
+ // member may not process them. With no such keys, this is `unknown` so props
282
+ // keep their exact shape instead of gaining an empty `{}` intersection member.
283
+ type PartialVariantKeys<
284
+ R extends Pick<AnyRecipe, "getVariants">,
285
+ Key extends PropertyKey = Exclude<
286
+ UnionKeys<VariantProps<R>>,
287
+ keyof VariantProps<R>
288
+ >,
289
+ > = [Key] extends [never] ? unknown : { [K in Key]?: never };
290
+
291
+ type UnionKeys<T> = T extends unknown ? keyof T : never;
240
292
 
241
293
  // Variant props expose booleans, but variant object keys are always strings.
242
294
  type VariantKey<T> = T extends boolean ? "true" | "false" : Extract<T, string>;
243
295
 
244
296
  /**
245
297
  * Constrains a variant map to the same value keys as a variant on another
246
- * component. Boolean variants are represented with `"true"` and `"false"`
298
+ * recipe. Boolean variants are represented with `"true"` and `"false"`
247
299
  * object keys.
248
300
  *
249
301
  * @example
@@ -268,7 +320,7 @@ type VariantKey<T> = T extends boolean ? "true" | "false" : Extract<T, string>;
268
320
  * ```
269
321
  */
270
322
  export type Variant<
271
- T extends Pick<AnyComponent, "getVariants">,
323
+ T extends Pick<AnyRecipe, "getVariants">,
272
324
  K extends keyof VariantProps<T>,
273
325
  > = Record<
274
326
  VariantKey<NonNullable<VariantProps<T>[K]>>,
@@ -277,7 +329,7 @@ export type Variant<
277
329
 
278
330
  /**
279
331
  * The configuration object accepted by `cv()`. It defines base class/style
280
- * output, variants, default variants, component extensions, and refinement
332
+ * output, variants, default variants, recipe extensions, and refinement
281
333
  * logic.
282
334
  *
283
335
  * @example
@@ -301,10 +353,7 @@ export type Variant<
301
353
  * const alert = cv(config);
302
354
  * ```
303
355
  */
304
- export interface CVConfig<
305
- V extends Variants = {},
306
- E extends AnyComponent[] = [],
307
- > {
356
+ export interface CVConfig<V extends Variants = {}, E extends AnyRecipe[] = []> {
308
357
  extend?: E;
309
358
  class?: ClassValue;
310
359
  style?: StyleValue;
@@ -344,7 +393,7 @@ function normalizeStyle(style: unknown): StyleValue {
344
393
 
345
394
  /**
346
395
  * Pre-extracts the class and (normalized) style from a variant value once at
347
- * component creation time. Returns `null` if the value contributes nothing.
396
+ * recipe creation time. Returns `null` if the value contributes nothing.
348
397
  */
349
398
  interface PrebuiltValue {
350
399
  class: ClassValue;
@@ -387,7 +436,7 @@ function getVariantValueKey(value: unknown): string | undefined {
387
436
 
388
437
  const EMPTY_KEYS: readonly string[] = [];
389
438
 
390
- function isComponentKeySource(source: unknown): source is KeySourceComponent {
439
+ function isRecipeKeySource(source: unknown): source is KeySourceRecipe {
391
440
  if (!source) return false;
392
441
  if (typeof source !== "object" && typeof source !== "function") {
393
442
  return false;
@@ -400,19 +449,19 @@ function isComponentKeySource(source: unknown): source is KeySourceComponent {
400
449
 
401
450
  /**
402
451
  * Splits props into multiple groups based on key sources. Only the first
403
- * component claims styling props (class/className/style). Subsequent components
452
+ * recipe claims styling props (class/className/style). Subsequent recipes
404
453
  * only receive variant props. Arrays always receive their listed keys but don't
405
454
  * claim styling props.
406
455
  */
407
456
  function splitPropsImpl(
408
457
  selfKeys: readonly string[],
409
- selfIsComponent: boolean,
458
+ selfIsRecipe: boolean,
410
459
  props: Record<string, unknown>,
411
460
  sources: unknown[],
412
461
  ): Record<string, unknown>[] {
413
462
  const sourcesLength = sources.length;
414
463
  const results: Record<string, unknown>[] = [];
415
- let stylingClaimed = selfIsComponent;
464
+ let stylingClaimed = selfIsRecipe;
416
465
 
417
466
  const selfResult: Record<string, unknown> = {};
418
467
  const selfKeysLength = selfKeys.length;
@@ -431,12 +480,12 @@ function splitPropsImpl(
431
480
  for (let s = 0; s < sourcesLength; s++) {
432
481
  const source = sources[s];
433
482
  const sourceResult: Record<string, unknown> = {};
434
- let sourceIsComponent = false;
483
+ let sourceIsRecipe = false;
435
484
  let effectiveKeys: readonly string[];
436
485
  if (Array.isArray(source)) {
437
486
  effectiveKeys = source;
438
- } else if (isComponentKeySource(source)) {
439
- sourceIsComponent = true;
487
+ } else if (isRecipeKeySource(source)) {
488
+ sourceIsRecipe = true;
440
489
  effectiveKeys = stylingClaimed ? source.variantKeys : source.propKeys;
441
490
  } else {
442
491
  effectiveKeys = EMPTY_KEYS;
@@ -452,7 +501,7 @@ function splitPropsImpl(
452
501
  results.push(sourceResult);
453
502
  effectiveKeyArrays.push(effectiveKeys);
454
503
 
455
- if (sourceIsComponent && !stylingClaimed) {
504
+ if (sourceIsRecipe && !stylingClaimed) {
456
505
  stylingClaimed = true;
457
506
  }
458
507
  }
@@ -481,8 +530,8 @@ function splitPropsImpl(
481
530
 
482
531
  /**
483
532
  * 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
533
+ * own result object containing all its matching keys. The first recipe
534
+ * source claims styling props (class/className/style). Subsequent recipes
486
535
  * only receive variant props. Arrays receive their listed keys but don't claim
487
536
  * styling props. The last element is always the "rest" containing keys not
488
537
  * claimed by any source.
@@ -495,7 +544,7 @@ export const splitProps: SplitPropsFunction = ((
495
544
  if (Array.isArray(source1)) {
496
545
  return splitPropsImpl(source1, false, props, sources);
497
546
  }
498
- if (isComponentKeySource(source1)) {
547
+ if (isRecipeKeySource(source1)) {
499
548
  return splitPropsImpl(source1.propKeys, true, props, sources);
500
549
  }
501
550
  return splitPropsImpl(EMPTY_KEYS, false, props, sources);
@@ -558,12 +607,12 @@ export function create(params: CreateParams = {}) {
558
607
 
559
608
  const cx = (...classes: ClsxClassValue[]) => transformClass(clsx(classes));
560
609
 
561
- const buildComponent = <
610
+ const buildRecipe = <
562
611
  V extends Variants = {},
563
- const E extends AnyComponent[] = [],
612
+ const E extends AnyRecipe[] = [],
564
613
  >(
565
614
  config: CVConfig<V, E> = {},
566
- ): { component: CVComponent<V, E>; meta: ComponentMeta } => {
615
+ ): { recipe: Recipe<V, E>; meta: RecipeMeta } => {
567
616
  type MergedVariants = MergeVariants<V, E>;
568
617
 
569
618
  // Compile caller-owned configuration once. Rebuilding a pruned branch
@@ -576,7 +625,7 @@ export function create(params: CreateParams = {}) {
576
625
  const baseClassValue = getOwn(config, "class");
577
626
  const variantKeySet = new Set<string>();
578
627
  const inheritedComputedDefaultKeys = new Set<string>();
579
- const originalExtMetas: ComponentMeta[] = [];
628
+ const originalExtMetas: RecipeMeta[] = [];
580
629
  if (extend) {
581
630
  for (const ext of extend) {
582
631
  const extKeys = ext.variantKeys as readonly string[];
@@ -585,7 +634,7 @@ export function create(params: CreateParams = {}) {
585
634
  if (key === undefined) continue;
586
635
  variantKeySet.add(key);
587
636
  }
588
- const meta = (ext as AnyComponent & ComponentWithMeta)[META_KEY];
637
+ const meta = (ext as AnyRecipe & RecipeWithMeta)[META_KEY];
589
638
  if (!meta) continue;
590
639
  originalExtMetas.push(meta);
591
640
  // A later branch can read a computed default contributed by the first
@@ -682,10 +731,10 @@ export function create(params: CreateParams = {}) {
682
731
  // Only extension-dependent state is rebuilt. Own tables, callbacks,
683
732
  // inheritance visibility, and the creation frame stay shared and unchanged.
684
733
  const build = (
685
- extMetas: ComponentMeta[],
734
+ extMetas: RecipeMeta[],
686
735
  ): {
687
- component: CVComponent<V, E>;
688
- meta: ComponentMeta;
736
+ recipe: Recipe<V, E>;
737
+ meta: RecipeMeta;
689
738
  } => {
690
739
  const hasExtend = extMetas.length > 0;
691
740
  const extCount = extMetas.length;
@@ -733,9 +782,9 @@ export function create(params: CreateParams = {}) {
733
782
  }
734
783
 
735
784
  // Filter to only extends with computed default or refine work in their
736
- // chain. Those are the components that can change resolved variants across
785
+ // chain. Those are the recipes that can change resolved variants across
737
786
  // fixed-point iterations.
738
- const extMetasWithRefine: ComponentMeta[] = [];
787
+ const extMetasWithRefine: RecipeMeta[] = [];
739
788
  for (let i = 0; i < extCount; i++) {
740
789
  const meta = extMetas[i];
741
790
  if (meta.resolveRefine) {
@@ -747,7 +796,7 @@ export function create(params: CreateParams = {}) {
747
796
  // Only a `refine` callback protects variants, through `setVariants`. This
748
797
  // over-approximates: `extMetasWithRefineCount` also counts extends that
749
798
  // only have computed defaults. Tightening it would mean tracking `refine`
750
- // separately in `ComponentMeta` to save one allocation. The record inside
799
+ // separately in `RecipeMeta` to save one allocation. The record inside
751
800
  // the holder is created only when a callback assigns something.
752
801
  const canProtectVariants = !!refine || extMetasWithRefineCount > 0;
753
802
 
@@ -761,10 +810,10 @@ export function create(params: CreateParams = {}) {
761
810
  computedDefaultCount > 0 || inheritedComputedDefaultKeys.size > 0;
762
811
 
763
812
  // 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"
813
+ // recipe's own variants: a static (object/shorthand) variant in this
814
+ // recipe replaces an inherited function variant for the same key.
815
+ // The closure is exposed on `RecipeMeta` so any further extending
816
+ // recipe can detect "ancestor's effective variant for K is a function"
768
817
  // and skip it when overriding K with a non-function.
769
818
  const functionVariantKeys = new Set<string>();
770
819
  for (let i = 0; i < extCount; i++) {
@@ -778,8 +827,8 @@ export function create(params: CreateParams = {}) {
778
827
  functionVariantKeys.add(functionVariantNames[i]);
779
828
  }
780
829
  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
830
+ // A static variant in this recipe replaces an inherited function
831
+ // variant for the same key; from this recipe onward, the key is no
783
832
  // longer a function variant.
784
833
  functionVariantKeys.delete(variantEntryNames[i]);
785
834
  }
@@ -803,7 +852,7 @@ export function create(params: CreateParams = {}) {
803
852
  }
804
853
  }
805
854
 
806
- // A static variant in this component replaces an inherited function
855
+ // A static variant in this recipe replaces an inherited function
807
856
  // variant, so the ancestor must skip that key.
808
857
  if (variantEntryCount > 0 && extCount > 0) {
809
858
  for (let i = 0; i < variantEntryCount; i++) {
@@ -1016,7 +1065,7 @@ export function create(params: CreateParams = {}) {
1016
1065
  if (refine) {
1017
1066
  let ownVariants = resolved;
1018
1067
  if (filterOwnVariants) {
1019
- // When this component is being extended, `resolved` is the parent's
1068
+ // When this recipe is being extended, `resolved` is the parent's
1020
1069
  // workingResolved (a superset of our variant keys). Filter to our own
1021
1070
  // keys for `ctx.variants` so the user's `refine` callback sees the
1022
1071
  // shape declared by `VariantValues<V>` and not foreign parent keys.
@@ -1049,7 +1098,7 @@ export function create(params: CreateParams = {}) {
1049
1098
  }
1050
1099
  for (const key in newVariants) {
1051
1100
  if (!hasOwn(newVariants, key)) continue;
1052
- // `disabledVariantKeys` is empty unless this component disables a
1101
+ // `disabledVariantKeys` is empty unless this recipe disables a
1053
1102
  // variant, so the lookup replaces a `hasAnyDisabled` branch. The
1054
1103
  // key is checked before the value is read, because reading it can
1055
1104
  // run a caller-defined accessor.
@@ -1128,8 +1177,8 @@ export function create(params: CreateParams = {}) {
1128
1177
  };
1129
1178
 
1130
1179
  // 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
1180
+ // `computeResult`) and recursively when this recipe is used as an
1181
+ // `extend` target by another recipe. Pushes variant classes (excluding
1133
1182
  // base class) into `classesOut` and merges styles into `styleOut`.
1134
1183
  const computeOnce: ComputeOnceFn = (
1135
1184
  resolved,
@@ -1234,8 +1283,8 @@ export function create(params: CreateParams = {}) {
1234
1283
  }
1235
1284
  }
1236
1285
 
1237
- // Run own computed defaults after extended components so defaults resolve
1238
- // from base to child. They still run before this component's `refine`.
1286
+ // Run own computed defaults after extended recipes so defaults resolve
1287
+ // from base to child. They still run before this recipe's `refine`.
1239
1288
  if (!renderOnly && computedDefaultCount > 0) {
1240
1289
  workingResolved = runComputedDefaults(
1241
1290
  workingResolved,
@@ -1247,7 +1296,7 @@ export function create(params: CreateParams = {}) {
1247
1296
  }
1248
1297
 
1249
1298
  // Run own `refine` (if any). May modify resolved variants and emit
1250
- // classes and styles that are applied after this component's variants.
1299
+ // classes and styles that are applied after this recipe's variants.
1251
1300
  if (refine) {
1252
1301
  const refineResult = runRefineContext(
1253
1302
  workingResolved,
@@ -1602,7 +1651,7 @@ export function create(params: CreateParams = {}) {
1602
1651
  // Top-level: resolves variants from user props, calls compute, then
1603
1652
  // assembles className and style with user-provided class/style overrides.
1604
1653
  const computeResult = (
1605
- props: ComponentProps<MergedVariants> = EMPTY_DEFAULTS as ComponentProps<MergedVariants>,
1654
+ props: RecipeProps<MergedVariants> = EMPTY_DEFAULTS as RecipeProps<MergedVariants>,
1606
1655
  ): { className: string; style: StyleValue } => {
1607
1656
  const propsRecord = props as Record<string, unknown>;
1608
1657
 
@@ -1684,7 +1733,7 @@ export function create(params: CreateParams = {}) {
1684
1733
  // this record cannot see an undeclared key as an explicitly passed
1685
1734
  // variant, and cannot re-run a caller accessor once per refine pass. The
1686
1735
  // gate is narrower than that purpose: it misses a chain whose only
1687
- // computed default is this component's own.
1736
+ // computed default is this recipe's own.
1688
1737
  // See https://github.com/ariakit/clava/issues/494
1689
1738
  if (variants && extMetasWithRefineCount > 0) {
1690
1739
  variantProps = {};
@@ -1716,11 +1765,11 @@ export function create(params: CreateParams = {}) {
1716
1765
  ? clsx(extBaseClassesArr, baseClass)
1717
1766
  : baseClass;
1718
1767
 
1719
- // Shared closures across the default and modal components.
1720
- const classFn = (props: ComponentProps<MergedVariants> = {}) => {
1768
+ // Shared closures across the default and modal recipes.
1769
+ const classFn = (props: RecipeProps<MergedVariants> = {}) => {
1721
1770
  return computeResult(props).className;
1722
1771
  };
1723
- const meta: ComponentMeta = {
1772
+ const meta: RecipeMeta = {
1724
1773
  identity,
1725
1774
  extends: extMetas,
1726
1775
  rebuild: (extensions) => build(extensions).meta,
@@ -1733,81 +1782,75 @@ export function create(params: CreateParams = {}) {
1733
1782
  computedDefaultKeys,
1734
1783
  };
1735
1784
 
1736
- const initComponent = <
1737
- R extends ComponentResult,
1738
- T extends ModalComponent<MergedVariants, R>,
1785
+ const initRecipe = <
1786
+ R extends RecipeResult,
1787
+ T extends ModalRecipe<MergedVariants, R>,
1739
1788
  >(
1740
- c: T,
1789
+ recipe: T,
1741
1790
  propKeys: string[],
1742
1791
  style: T["style"],
1743
1792
  ): 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;
1793
+ recipe.class = classFn;
1794
+ recipe.style = style;
1795
+ recipe.getVariants = getVariants;
1796
+ recipe.variantKeys = variantKeys;
1797
+ recipe.propKeys = propKeys;
1798
+ (recipe as AnyRecipe & RecipeWithMeta)[META_KEY] = meta;
1799
+ return recipe;
1751
1800
  };
1752
1801
 
1753
- // Default component
1754
- const defaultComponent = ((
1755
- props: ComponentProps<MergedVariants> = {},
1756
- ) => {
1802
+ // Default recipe
1803
+ const defaultRecipe = ((props: RecipeProps<MergedVariants> = {}) => {
1757
1804
  const { className, style } = computeResult(props);
1758
1805
  return { class: className, style };
1759
- }) as CVComponent<V, E>;
1760
- initComponent(defaultComponent, inputPropsKeys, (props = {}) => {
1806
+ }) as Recipe<V, E>;
1807
+ initRecipe(defaultRecipe, inputPropsKeys, (props = {}) => {
1761
1808
  return computeResult(props).style;
1762
1809
  });
1763
1810
 
1764
- // JSX component
1765
- const jsxComponent = ((props: ComponentProps<MergedVariants> = {}) => {
1811
+ // JSX recipe
1812
+ const jsxRecipe = ((props: RecipeProps<MergedVariants> = {}) => {
1766
1813
  const { className, style } = computeResult(props);
1767
1814
  return { className, style };
1768
- }) as ModalComponent<MergedVariants, JSXProps>;
1769
- initComponent(
1770
- jsxComponent,
1815
+ }) as ModalRecipe<MergedVariants, JSXProps>;
1816
+ initRecipe(
1817
+ jsxRecipe,
1771
1818
  ["className", "style", ...variantKeys],
1772
1819
  (props = {}) => computeResult(props).style,
1773
1820
  );
1774
1821
 
1775
- // HTML component
1776
- const htmlComponent = ((props: ComponentProps<MergedVariants> = {}) => {
1822
+ // HTML recipe
1823
+ const htmlRecipe = ((props: RecipeProps<MergedVariants> = {}) => {
1777
1824
  const { className, style } = computeResult(props);
1778
1825
  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),
1826
+ }) as ModalRecipe<MergedVariants, HTMLProps>;
1827
+ initRecipe(htmlRecipe, ["class", "style", ...variantKeys], (props = {}) =>
1828
+ styleValueToHTMLStyle(computeResult(props).style),
1784
1829
  );
1785
1830
 
1786
- // HTMLObj component
1787
- const htmlObjComponent = ((
1788
- props: ComponentProps<MergedVariants> = {},
1789
- ) => {
1831
+ // HTMLObj recipe
1832
+ const htmlObjRecipe = ((props: RecipeProps<MergedVariants> = {}) => {
1790
1833
  const { className, style } = computeResult(props);
1791
1834
  return { class: className, style: styleValueToHTMLObjStyle(style) };
1792
- }) as ModalComponent<MergedVariants, HTMLObjProps>;
1793
- initComponent(
1794
- htmlObjComponent,
1835
+ }) as ModalRecipe<MergedVariants, HTMLObjProps>;
1836
+ initRecipe(
1837
+ htmlObjRecipe,
1795
1838
  ["class", "style", ...variantKeys],
1796
1839
  (props = {}) => styleValueToHTMLObjStyle(computeResult(props).style),
1797
1840
  );
1798
1841
 
1799
- defaultComponent.jsx = jsxComponent;
1800
- defaultComponent.html = htmlComponent;
1801
- defaultComponent.htmlObj = htmlObjComponent;
1842
+ defaultRecipe.jsx = jsxRecipe;
1843
+ defaultRecipe.html = htmlRecipe;
1844
+ defaultRecipe.htmlObj = htmlObjRecipe;
1802
1845
 
1803
- return { component: defaultComponent, meta };
1846
+ return { recipe: defaultRecipe, meta };
1804
1847
  };
1805
1848
  return build(initialExtensions);
1806
1849
  };
1807
1850
 
1808
- const cv = <V extends Variants = {}, const E extends AnyComponent[] = []>(
1851
+ const cv = <V extends Variants = {}, const E extends AnyRecipe[] = []>(
1809
1852
  config: CVConfig<V, E> = {},
1810
- ): CVComponent<V, E> => buildComponent(config).component;
1853
+ ): Recipe<V, E> => buildRecipe(config).recipe;
1811
1854
 
1812
1855
  return { cv, cx };
1813
1856
  }
@@ -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);