praxis-kit 3.1.1 → 4.0.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.
@@ -1,18 +1,14 @@
1
- import { E as ElementType, U as UnknownProps, V as VariantMap, R as RecipeMap, a as EmptyRecord, C as ClassPluginFactory, A as AnyRecord, b as ReactFactoryOptions, P as PolymorphicComponent, c as PolymorphicGenerics, d as ExtractPluginProps } from '../merge-refs-BKyE8h8M.js';
2
- export { e as AnyFactoryOptions, f as ElementRef, F as FactoryOptions, g as PolymorphicProps, h as PolymorphicWithAsChild, i as PolymorphicWithRender, j as RenderCallbackProps, S as Slottable, k as SlottableProps, l as defineContractComponent, m as mergeRefs } from '../merge-refs-BKyE8h8M.js';
1
+ export { defineContractComponent } from '@praxis-kit/adapter-utils';
2
+ import { ElementType, EmptyRecord, VariantMap, RecipeMap, ClassPluginFactory, AnyRecord, PolymorphicGenerics, ExtractPluginProps } from '@praxis-kit/core';
3
+ export { AnyFactoryOptions, ElementType, EmptyRecord, FactoryOptions, PolymorphicGenerics } from '@praxis-kit/core';
4
+ import { U as UnknownProps, R as ReactFactoryOptions, P as PolymorphicComponent } from '../merge-refs-DUuHyTRO.js';
5
+ export { E as ElementRef, a as PolymorphicProps, b as PolymorphicWithAsChild, c as PolymorphicWithRender, d as RenderCallbackProps, S as Slottable, e as SlottableProps, m as composeRefs, m as mergeRefs } from '../merge-refs-DUuHyTRO.js';
3
6
  import { Ref, ReactElement } from 'react';
7
+ import '@praxis-kit/runtime';
4
8
  import 'type-fest';
5
9
 
6
- declare function createAriaEnforcedComponent<TDefault extends ElementType, Props extends UnknownProps, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined>(options: ReactFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>>;
7
-
8
- declare function createChildrenEnforcedComponent<TDefault extends ElementType, Props extends UnknownProps, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined>(options: ReactFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>>;
9
-
10
10
  declare function createContractComponent<TDefault extends ElementType, Props extends UnknownProps = EmptyRecord, Variants extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined, TAllowed extends ElementType = ElementType>(options: ReactFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin, TAllowed>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset, TAllowed>>;
11
11
 
12
- declare function createContractedComponent<TDefault extends ElementType, Props extends UnknownProps, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined>(options: ReactFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>>;
13
-
14
- declare function createPolymorphicComponent<TDefault extends ElementType, Props extends UnknownProps, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined>(options: ReactFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>>;
15
-
16
12
  type SlotProps = {
17
13
  ref?: Ref<unknown> | null;
18
14
  [key: string]: unknown;
@@ -22,4 +18,20 @@ declare namespace Slot {
22
18
  var displayName: string;
23
19
  }
24
20
 
25
- export { ElementType, EmptyRecord, PolymorphicComponent, PolymorphicGenerics, ReactFactoryOptions, Slot, createAriaEnforcedComponent, createChildrenEnforcedComponent, createContractComponent, createContractedComponent, createPolymorphicComponent };
21
+ type CloneInput = {
22
+ child: ReactElement;
23
+ slotProps: UnknownProps;
24
+ ref: Ref<unknown> | null;
25
+ };
26
+ declare function cloneSlotChild({ child, slotProps, ref }: CloneInput): ReactElement;
27
+
28
+ /**
29
+ * Cross-version ref extraction for React 19 elements.
30
+ * React 19 stores ref in `element.props.ref`; when a React 18-created element is passed in,
31
+ * React attaches a warning getter there instead and keeps the real ref on `element.ref`.
32
+ * `getChildRef` detects which location is live and reads from there.
33
+ */
34
+
35
+ declare function getChildRef(element: ReactElement): Ref<unknown> | null;
36
+
37
+ export { PolymorphicComponent, ReactFactoryOptions, Slot, cloneSlotChild, createContractComponent, getChildRef };
@@ -1,23 +1,35 @@
1
1
  import {
2
+ AriaPolicyEngine,
2
3
  COMPONENT_DEFAULT_TAG,
3
4
  SLOT_NAME,
4
5
  SlotValidator,
5
6
  Slottable,
7
+ applyAria,
8
+ applyAttributes,
6
9
  applyDisplayName,
10
+ applyFilterProps,
11
+ applyPropNormalizers,
12
+ applyRef,
7
13
  applySlot,
14
+ buildDefinition,
8
15
  buildEngines,
9
- buildRuntime,
16
+ buildStylePipeline,
10
17
  cloneWithProps,
11
- composeFilter,
12
- createContractedPolymorphic,
13
- createPolymorphic,
14
18
  defineContractComponent,
19
+ enforceAllowedAs,
20
+ extractDecoration,
21
+ flattenClassName,
22
+ getHtmlChildrenEvaluator,
15
23
  isFunction,
16
24
  isPlainObject,
25
+ joinClasses,
26
+ makeRenderAsChild,
17
27
  mergeRefs,
18
28
  mergeSlotProps,
19
- render
20
- } from "../chunk-6RJN5B6L.js";
29
+ renderNormally,
30
+ renderWithCallback,
31
+ resolveAdapterCommonOptions
32
+ } from "../chunk-TJRHF6MS.js";
21
33
 
22
34
  // ../../adapters/react/src/current/slot/cloneSlotChild.ts
23
35
  import { Fragment } from "react";
@@ -51,12 +63,6 @@ function cloneSlotChild({ child, slotProps, ref }) {
51
63
  return cloneWithProps(child, merged, mergedRef);
52
64
  }
53
65
 
54
- // ../../adapters/react/src/current/slot/Slot.tsx
55
- function Slot({ ref = null, children, ...slotProps }) {
56
- return applySlot(children, slotProps, ref, cloneSlotChild);
57
- }
58
- Slot.displayName = SLOT_NAME;
59
-
60
66
  // ../../adapters/react/src/current/normalize-children.ts
61
67
  import { isValidElement } from "react";
62
68
  function normalizeChildren(children) {
@@ -65,125 +71,118 @@ function normalizeChildren(children) {
65
71
  return [];
66
72
  }
67
73
 
68
- // ../../adapters/react/src/current/create-aria-enforced-component.ts
69
- function createAriaEnforcedComponent(options) {
70
- const name = options.name ?? "PolymorphicComponent";
71
- const strict = options.enforcement?.strict ?? "throw";
72
- const slotComponent = options.slotComponent ?? Slot;
73
- const runtime = createContractedPolymorphic(options);
74
- const filterProps = composeFilter(/* @__PURE__ */ new Set(), options.filterProps);
75
- const slotValidator = new SlotValidator(name, strict);
76
- function Component({ ref, ...props }) {
77
- return render({
78
- runtime,
79
- props,
80
- ref: ref ?? null,
81
- slotComponent,
82
- normalizeChildren,
83
- filterProps,
84
- slotValidator
85
- });
86
- }
87
- applyDisplayName(Component, name);
88
- return Component;
89
- }
90
-
91
- // ../../adapters/react/src/current/create-children-enforced-component.ts
92
- function createChildrenEnforcedComponent(options) {
93
- const name = options.name ?? "PolymorphicComponent";
94
- const strict = options.enforcement?.strict ?? "throw";
95
- const slotComponent = options.slotComponent ?? Slot;
96
- const runtime = createPolymorphic(options);
97
- const filterProps = composeFilter(/* @__PURE__ */ new Set(), options.filterProps);
98
- const slotValidator = new SlotValidator(name, strict);
99
- const { childrenEvaluator } = buildEngines(strict, options.enforcement?.children, name);
100
- function Component({ ref, ...props }) {
101
- return render({
102
- runtime,
103
- props,
104
- ref: ref ?? null,
105
- slotComponent,
106
- normalizeChildren,
107
- filterProps,
108
- slotValidator,
109
- ...childrenEvaluator !== void 0 && { childrenEvaluator }
110
- });
111
- }
112
- applyDisplayName(Component, name);
113
- return Component;
114
- }
115
-
116
74
  // ../../adapters/react/src/current/create-contract-component.ts
75
+ var EMPTY_SET = /* @__PURE__ */ new Set();
117
76
  function createContractComponent(options) {
118
- const bundle = buildRuntime(
119
- options,
120
- Slot,
121
- normalizeChildren
77
+ const resolved = resolveAdapterCommonOptions(options);
78
+ const displayName = resolved.name;
79
+ const defaultTag = options.tag ?? "div";
80
+ const artifact = options.artifact;
81
+ const definition = artifact?.definition ?? buildDefinition(displayName, defaultTag);
82
+ const variantKeys = new Set(Object.keys(options.styling?.variants ?? {}));
83
+ const domDefaults = options.defaults;
84
+ const stylePipeline = buildStylePipeline(
85
+ options.styling?.variants,
86
+ options.styling?.presets,
87
+ options.styling?.defaults ?? {},
88
+ options.styling?.compounds,
89
+ artifact?.precomputed?.variantLookup
90
+ );
91
+ const base = options.styling?.base !== void 0 ? flattenClassName(options.styling.base) : void 0;
92
+ const filterFn = options.filterProps;
93
+ const allowedAs = options.enforcement?.allowedAs;
94
+ const normalizeFn = options.normalize;
95
+ const enforcementNormalizers = options.enforcement?.props;
96
+ const classPlugin = options.styling?.plugin !== void 0 ? options.styling.plugin(
97
+ options.styling,
98
+ resolved.diagnostics
99
+ ) : void 0;
100
+ const pluginKeys = classPlugin?.ownedKeys ?? EMPTY_SET;
101
+ const { childrenEvaluator: explicitEvaluator } = buildEngines(
102
+ resolved.diagnostics,
103
+ options.enforcement?.children,
104
+ displayName
122
105
  );
106
+ const ariaEngine = options.enforcement !== void 0 ? new AriaPolicyEngine(resolved.diagnostics) : void 0;
107
+ const slotValidator = new SlotValidator(displayName, resolved.diagnostics, "React element");
108
+ const renderAsChild = makeRenderAsChild(cloneSlotChild);
123
109
  function Component({ ref, ...props }) {
124
- return render({ ...bundle, props, ref: ref ?? null });
110
+ const {
111
+ as,
112
+ asChild,
113
+ render,
114
+ children,
115
+ className: callerClassName,
116
+ recipe,
117
+ ...ownProps
118
+ } = props;
119
+ const tag = typeof as === "string" ? as : defaultTag;
120
+ if (allowedAs !== void 0) enforceAllowedAs(tag, allowedAs, resolved.diagnostics, displayName);
121
+ const rawBaseProps = domDefaults !== void 0 ? { ...domDefaults, ...ownProps } : ownProps;
122
+ const normalizedProps = applyPropNormalizers(tag, rawBaseProps, enforcementNormalizers);
123
+ const baseProps = normalizeFn !== void 0 ? normalizeFn(normalizedProps) : normalizedProps;
124
+ const pluginProps = {};
125
+ const propsForExtraction = pluginKeys.size > 0 ? Object.fromEntries(
126
+ Object.entries(baseProps).filter(([k]) => {
127
+ if (pluginKeys.has(k)) {
128
+ pluginProps[k] = baseProps[k];
129
+ return false;
130
+ }
131
+ return true;
132
+ })
133
+ ) : baseProps;
134
+ const rootDec = extractDecoration(propsForExtraction, variantKeys);
135
+ const decoration = applyAria(
136
+ Object.keys(rootDec).length > 0 ? { root: rootDec } : {},
137
+ tag,
138
+ ariaEngine
139
+ );
140
+ if (process.env.NODE_ENV !== "production") {
141
+ const childEval = explicitEvaluator ?? getHtmlChildrenEvaluator(tag);
142
+ childEval?.evaluate(normalizeChildren(children));
143
+ }
144
+ const recipeName = typeof recipe === "string" ? recipe : void 0;
145
+ const { variantClasses, compoundClasses } = stylePipeline ? stylePipeline.execute(decoration, recipeName) : { variantClasses: [], compoundClasses: [] };
146
+ const rawClassName = joinClasses(base, ...variantClasses, ...compoundClasses, callerClassName);
147
+ const className = classPlugin !== void 0 ? classPlugin.pipeline(tag, pluginProps, rawClassName, recipeName) : rawClassName;
148
+ if (asChild === true) {
149
+ if (typeof as === "string") {
150
+ slotValidator.assertExclusive();
151
+ } else {
152
+ return renderAsChild(children, className, ref);
153
+ }
154
+ }
155
+ let finalDecoration = className ? applyAttributes("root", { className }, decoration, variantKeys) : decoration;
156
+ finalDecoration = applyFilterProps(finalDecoration, filterFn, variantKeys);
157
+ finalDecoration = applyRef(finalDecoration, ref);
158
+ if (typeof render === "function")
159
+ return renderWithCallback(
160
+ render,
161
+ finalDecoration["root"]?.attributes ?? {},
162
+ className,
163
+ ref
164
+ );
165
+ return renderNormally(definition, tag, finalDecoration, children);
125
166
  }
126
167
  applyDisplayName(Component, options.name);
127
- if (typeof bundle.runtime.options.defaultTag === "string") {
128
- Object.assign(Component, { [COMPONENT_DEFAULT_TAG]: bundle.runtime.options.defaultTag });
129
- }
130
- return Component;
131
- }
132
-
133
- // ../../adapters/react/src/current/create-contracted-component.ts
134
- function createContractedComponent(options) {
135
- const name = options.name ?? "PolymorphicComponent";
136
- const strict = options.enforcement?.strict ?? "throw";
137
- const slotComponent = options.slotComponent ?? Slot;
138
- const runtime = createContractedPolymorphic(options);
139
- const filterProps = composeFilter(/* @__PURE__ */ new Set(), options.filterProps);
140
- const slotValidator = new SlotValidator(name, strict);
141
- const { childrenEvaluator } = buildEngines(strict, options.enforcement?.children, name);
142
- function Component({ ref, ...props }) {
143
- return render({
144
- runtime,
145
- props,
146
- ref: ref ?? null,
147
- slotComponent,
148
- normalizeChildren,
149
- filterProps,
150
- slotValidator,
151
- ...childrenEvaluator !== void 0 && { childrenEvaluator }
152
- });
168
+ if (typeof defaultTag === "string") {
169
+ Object.assign(Component, { [COMPONENT_DEFAULT_TAG]: defaultTag });
153
170
  }
154
- applyDisplayName(Component, name);
155
171
  return Component;
156
172
  }
157
173
 
158
- // ../../adapters/react/src/current/create-polymorphic-component.ts
159
- function createPolymorphicComponent(options) {
160
- const name = options.name ?? "PolymorphicComponent";
161
- const slotComponent = options.slotComponent ?? Slot;
162
- const runtime = createPolymorphic(options);
163
- const filterProps = composeFilter(/* @__PURE__ */ new Set(), options.filterProps);
164
- const slotValidator = new SlotValidator(name, "throw");
165
- function Component({ ref, ...props }) {
166
- return render({
167
- runtime,
168
- props,
169
- ref: ref ?? null,
170
- slotComponent,
171
- normalizeChildren,
172
- filterProps,
173
- slotValidator
174
- });
175
- }
176
- applyDisplayName(Component, name);
177
- return Component;
174
+ // ../../adapters/react/src/current/slot/Slot.tsx
175
+ function Slot({ ref = null, children, ...slotProps }) {
176
+ return applySlot(children, slotProps, ref, cloneSlotChild);
178
177
  }
178
+ Slot.displayName = SLOT_NAME;
179
179
  export {
180
180
  Slot,
181
181
  Slottable,
182
- createAriaEnforcedComponent,
183
- createChildrenEnforcedComponent,
182
+ cloneSlotChild,
183
+ mergeRefs as composeRefs,
184
184
  createContractComponent,
185
- createContractedComponent,
186
- createPolymorphicComponent,
187
185
  defineContractComponent,
186
+ getChildRef,
188
187
  mergeRefs
189
188
  };
@@ -1,21 +1,17 @@
1
- import { E as ElementType, U as UnknownProps, V as VariantMap, R as RecipeMap, a as EmptyRecord, C as ClassPluginFactory, A as AnyRecord, b as ReactFactoryOptions, P as PolymorphicComponent, c as PolymorphicGenerics, d as ExtractPluginProps } from '../merge-refs-BKyE8h8M.js';
2
- export { e as AnyFactoryOptions, f as ElementRef, F as FactoryOptions, g as PolymorphicProps, h as PolymorphicWithAsChild, i as PolymorphicWithRender, j as RenderCallbackProps, S as Slottable, k as SlottableProps, l as defineContractComponent, m as mergeRefs } from '../merge-refs-BKyE8h8M.js';
1
+ export { defineContractComponent } from '@praxis-kit/adapter-utils';
2
+ import { ElementType, EmptyRecord, VariantMap, RecipeMap, ClassPluginFactory, AnyRecord, PolymorphicGenerics, ExtractPluginProps } from '@praxis-kit/core';
3
+ export { AnyFactoryOptions, ElementType, EmptyRecord, FactoryOptions, PolymorphicGenerics } from '@praxis-kit/core';
4
+ import { U as UnknownProps, R as ReactFactoryOptions, P as PolymorphicComponent } from '../merge-refs-DUuHyTRO.js';
5
+ export { E as ElementRef, a as PolymorphicProps, b as PolymorphicWithAsChild, c as PolymorphicWithRender, d as RenderCallbackProps, S as Slottable, e as SlottableProps, m as mergeRefs } from '../merge-refs-DUuHyTRO.js';
3
6
  import * as react from 'react';
7
+ import '@praxis-kit/runtime';
4
8
  import 'type-fest';
5
9
 
6
- declare function createAriaEnforcedComponent<TDefault extends ElementType, Props extends UnknownProps, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined>(options: ReactFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>>;
7
-
8
- declare function createChildrenEnforcedComponent<TDefault extends ElementType, Props extends UnknownProps, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined>(options: ReactFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>>;
9
-
10
10
  declare function createContractComponent<TDefault extends ElementType, Props extends UnknownProps = EmptyRecord, Variants extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined, TAllowed extends ElementType = ElementType>(options: ReactFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin, TAllowed>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset, TAllowed>>;
11
11
 
12
- declare function createContractedComponent<TDefault extends ElementType, Props extends UnknownProps, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined>(options: ReactFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>>;
13
-
14
- declare function createPolymorphicComponent<TDefault extends ElementType, Props extends UnknownProps, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined>(options: ReactFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>>;
15
-
16
12
  type SlotProps = {
17
13
  [key: string]: unknown;
18
14
  };
19
15
  declare const Slot: react.ForwardRefExoticComponent<Omit<SlotProps, "ref"> & react.RefAttributes<unknown>>;
20
16
 
21
- export { ElementType, EmptyRecord, PolymorphicComponent, PolymorphicGenerics, ReactFactoryOptions, Slot, createAriaEnforcedComponent, createChildrenEnforcedComponent, createContractComponent, createContractedComponent, createPolymorphicComponent };
17
+ export { PolymorphicComponent, ReactFactoryOptions, Slot, createContractComponent };
@@ -1,28 +1,37 @@
1
1
  import {
2
+ AriaPolicyEngine,
2
3
  COMPONENT_DEFAULT_TAG,
3
4
  SLOT_NAME,
4
5
  SlotValidator,
5
6
  Slottable,
7
+ applyAria,
8
+ applyAttributes,
6
9
  applyDisplayName,
10
+ applyFilterProps,
11
+ applyPropNormalizers,
12
+ applyRef,
7
13
  applySlot,
14
+ buildDefinition,
8
15
  buildEngines,
9
- buildRuntime,
16
+ buildStylePipeline,
10
17
  cloneWithProps,
11
- composeFilter,
12
- createContractedPolymorphic,
13
- createPolymorphic,
14
18
  defineContractComponent,
19
+ enforceAllowedAs,
20
+ extractDecoration,
21
+ flattenClassName,
22
+ getHtmlChildrenEvaluator,
15
23
  isFunction,
16
24
  isPlainObject,
25
+ joinClasses,
26
+ makeRenderAsChild,
17
27
  mergeRefs,
18
28
  mergeSlotProps,
19
- render
20
- } from "../chunk-6RJN5B6L.js";
29
+ renderNormally,
30
+ renderWithCallback,
31
+ resolveAdapterCommonOptions
32
+ } from "../chunk-TJRHF6MS.js";
21
33
 
22
- // ../../adapters/react/src/legacy/create-aria-enforced-component.ts
23
- import { forwardRef as forwardRef2 } from "react";
24
-
25
- // ../../adapters/react/src/legacy/slot/Slot.tsx
34
+ // ../../adapters/react/src/legacy/create-contract-component.ts
26
35
  import { forwardRef } from "react";
27
36
 
28
37
  // ../../adapters/react/src/legacy/slot/cloneSlotChild.ts
@@ -57,151 +66,122 @@ function cloneSlotChild({ child, slotProps, ref }) {
57
66
  return cloneWithProps(child, merged, mergedRef);
58
67
  }
59
68
 
60
- // ../../adapters/react/src/legacy/slot/Slot.tsx
61
- var Slot = forwardRef(function Slot2({ children, ...slotProps }, ref) {
62
- return applySlot(children, slotProps, ref, cloneSlotChild);
63
- });
64
- Slot.displayName = SLOT_NAME;
65
-
66
69
  // ../../adapters/react/src/legacy/normalize-children.ts
67
70
  import { Children, isValidElement } from "react";
68
71
  function normalizeChildren(children) {
69
72
  return Children.toArray(children).filter(isValidElement);
70
73
  }
71
74
 
72
- // ../../adapters/react/src/legacy/create-aria-enforced-component.ts
73
- function createAriaEnforcedComponent(options) {
74
- const name = options.name ?? "PolymorphicComponent";
75
- const strict = options.enforcement?.strict ?? "throw";
76
- const slotComponent = options.slotComponent ?? Slot;
77
- const runtime = createContractedPolymorphic(options);
78
- const filterProps = composeFilter(/* @__PURE__ */ new Set(), options.filterProps);
79
- const slotValidator = new SlotValidator(name, strict);
80
- const Component = forwardRef2(
81
- function PolymorphicComponent(props, ref) {
82
- return render({
83
- runtime,
84
- props,
85
- ref,
86
- slotComponent,
87
- normalizeChildren,
88
- filterProps,
89
- slotValidator
90
- });
91
- }
92
- );
93
- applyDisplayName(Component, name);
94
- return Component;
95
- }
96
-
97
- // ../../adapters/react/src/legacy/create-children-enforced-component.ts
98
- import { forwardRef as forwardRef3 } from "react";
99
- function createChildrenEnforcedComponent(options) {
100
- const name = options.name ?? "PolymorphicComponent";
101
- const strict = options.enforcement?.strict ?? "throw";
102
- const slotComponent = options.slotComponent ?? Slot;
103
- const runtime = createPolymorphic(options);
104
- const filterProps = composeFilter(/* @__PURE__ */ new Set(), options.filterProps);
105
- const slotValidator = new SlotValidator(name, strict);
106
- const { childrenEvaluator } = buildEngines(strict, options.enforcement?.children, name);
107
- const Component = forwardRef3(
108
- function PolymorphicComponent(props, ref) {
109
- return render({
110
- runtime,
111
- props,
112
- ref,
113
- slotComponent,
114
- normalizeChildren,
115
- filterProps,
116
- slotValidator,
117
- ...childrenEvaluator !== void 0 && { childrenEvaluator }
118
- });
119
- }
120
- );
121
- applyDisplayName(Component, name);
122
- return Component;
123
- }
124
-
125
75
  // ../../adapters/react/src/legacy/create-contract-component.ts
126
- import { forwardRef as forwardRef4 } from "react";
76
+ var EMPTY_SET = /* @__PURE__ */ new Set();
127
77
  function createContractComponent(options) {
128
- const bundle = buildRuntime(
129
- options,
130
- Slot,
131
- normalizeChildren
78
+ const resolved = resolveAdapterCommonOptions(options);
79
+ const displayName = resolved.name;
80
+ const defaultTag = options.tag ?? "div";
81
+ const artifact = options.artifact;
82
+ const definition = artifact?.definition ?? buildDefinition(displayName, defaultTag);
83
+ const variantKeys = new Set(Object.keys(options.styling?.variants ?? {}));
84
+ const domDefaults = options.defaults;
85
+ const stylePipeline = buildStylePipeline(
86
+ options.styling?.variants,
87
+ options.styling?.presets,
88
+ options.styling?.defaults ?? {},
89
+ options.styling?.compounds,
90
+ artifact?.precomputed?.variantLookup
132
91
  );
133
- const Component = forwardRef4(
134
- function PolymorphicComponent(props, ref) {
135
- return render({ ...bundle, props, ref });
136
- }
92
+ const base = options.styling?.base !== void 0 ? flattenClassName(options.styling.base) : void 0;
93
+ const filterFn = options.filterProps;
94
+ const allowedAs = options.enforcement?.allowedAs;
95
+ const normalizeFn = options.normalize;
96
+ const enforcementNormalizers = options.enforcement?.props;
97
+ const classPlugin = options.styling?.plugin !== void 0 ? options.styling.plugin(
98
+ options.styling,
99
+ resolved.diagnostics
100
+ ) : void 0;
101
+ const pluginKeys = classPlugin?.ownedKeys ?? EMPTY_SET;
102
+ const { childrenEvaluator: explicitEvaluator } = buildEngines(
103
+ resolved.diagnostics,
104
+ options.enforcement?.children,
105
+ displayName
137
106
  );
107
+ const ariaEngine = options.enforcement !== void 0 ? new AriaPolicyEngine(resolved.diagnostics) : void 0;
108
+ const slotValidator = new SlotValidator(displayName, resolved.diagnostics, "React element");
109
+ const renderAsChild = makeRenderAsChild(cloneSlotChild);
110
+ const Component = forwardRef(function Component2(props, ref) {
111
+ const {
112
+ as,
113
+ asChild,
114
+ render,
115
+ children,
116
+ className: callerClassName,
117
+ recipe,
118
+ ...ownProps
119
+ } = props;
120
+ const tag = typeof as === "string" ? as : defaultTag;
121
+ if (allowedAs !== void 0) enforceAllowedAs(tag, allowedAs, resolved.diagnostics, displayName);
122
+ const rawBaseProps = domDefaults !== void 0 ? { ...domDefaults, ...ownProps } : ownProps;
123
+ const normalizedProps = applyPropNormalizers(tag, rawBaseProps, enforcementNormalizers);
124
+ const baseProps = normalizeFn !== void 0 ? normalizeFn(normalizedProps) : normalizedProps;
125
+ const pluginProps = {};
126
+ const propsForExtraction = pluginKeys.size > 0 ? Object.fromEntries(
127
+ Object.entries(baseProps).filter(([k]) => {
128
+ if (pluginKeys.has(k)) {
129
+ pluginProps[k] = baseProps[k];
130
+ return false;
131
+ }
132
+ return true;
133
+ })
134
+ ) : baseProps;
135
+ const rootDec = extractDecoration(propsForExtraction, variantKeys);
136
+ const decoration = applyAria(
137
+ Object.keys(rootDec).length > 0 ? { root: rootDec } : {},
138
+ tag,
139
+ ariaEngine
140
+ );
141
+ if (process.env.NODE_ENV !== "production") {
142
+ const childEval = explicitEvaluator ?? getHtmlChildrenEvaluator(tag);
143
+ childEval?.evaluate(normalizeChildren(children));
144
+ }
145
+ const recipeName = typeof recipe === "string" ? recipe : void 0;
146
+ const { variantClasses, compoundClasses } = stylePipeline ? stylePipeline.execute(decoration, recipeName) : { variantClasses: [], compoundClasses: [] };
147
+ const rawClassName = joinClasses(base, ...variantClasses, ...compoundClasses, callerClassName);
148
+ const className = classPlugin !== void 0 ? classPlugin.pipeline(tag, pluginProps, rawClassName, recipeName) : rawClassName;
149
+ if (asChild === true) {
150
+ if (typeof as === "string") {
151
+ slotValidator.assertExclusive();
152
+ } else {
153
+ return renderAsChild(children, className, ref);
154
+ }
155
+ }
156
+ let finalDecoration = className ? applyAttributes("root", { className }, decoration, variantKeys) : decoration;
157
+ finalDecoration = applyFilterProps(finalDecoration, filterFn, variantKeys);
158
+ finalDecoration = applyRef(finalDecoration, ref);
159
+ if (typeof render === "function")
160
+ return renderWithCallback(
161
+ render,
162
+ finalDecoration["root"]?.attributes ?? {},
163
+ className,
164
+ ref
165
+ );
166
+ return renderNormally(definition, tag, finalDecoration, children);
167
+ });
138
168
  applyDisplayName(Component, options.name);
139
- if (typeof bundle.runtime.options.defaultTag === "string") {
140
- Object.assign(Component, { [COMPONENT_DEFAULT_TAG]: bundle.runtime.options.defaultTag });
169
+ if (typeof defaultTag === "string") {
170
+ Object.assign(Component, { [COMPONENT_DEFAULT_TAG]: defaultTag });
141
171
  }
142
172
  return Component;
143
173
  }
144
174
 
145
- // ../../adapters/react/src/legacy/create-contracted-component.ts
146
- import { forwardRef as forwardRef5 } from "react";
147
- function createContractedComponent(options) {
148
- const name = options.name ?? "PolymorphicComponent";
149
- const strict = options.enforcement?.strict ?? "throw";
150
- const slotComponent = options.slotComponent ?? Slot;
151
- const runtime = createContractedPolymorphic(options);
152
- const filterProps = composeFilter(/* @__PURE__ */ new Set(), options.filterProps);
153
- const slotValidator = new SlotValidator(name, strict);
154
- const { childrenEvaluator } = buildEngines(strict, options.enforcement?.children, name);
155
- const Component = forwardRef5(
156
- function PolymorphicComponent(props, ref) {
157
- return render({
158
- runtime,
159
- props,
160
- ref,
161
- slotComponent,
162
- normalizeChildren,
163
- filterProps,
164
- slotValidator,
165
- ...childrenEvaluator !== void 0 && { childrenEvaluator }
166
- });
167
- }
168
- );
169
- applyDisplayName(Component, name);
170
- return Component;
171
- }
172
-
173
- // ../../adapters/react/src/legacy/create-polymorphic-component.ts
174
- import { forwardRef as forwardRef6 } from "react";
175
- function createPolymorphicComponent(options) {
176
- const name = options.name ?? "PolymorphicComponent";
177
- const slotComponent = options.slotComponent ?? Slot;
178
- const runtime = createPolymorphic(options);
179
- const filterProps = composeFilter(/* @__PURE__ */ new Set(), options.filterProps);
180
- const slotValidator = new SlotValidator(name, "throw");
181
- const Component = forwardRef6(
182
- function PolymorphicComponent(props, ref) {
183
- return render({
184
- runtime,
185
- props,
186
- ref,
187
- slotComponent,
188
- normalizeChildren,
189
- filterProps,
190
- slotValidator
191
- });
192
- }
193
- );
194
- applyDisplayName(Component, name);
195
- return Component;
196
- }
175
+ // ../../adapters/react/src/legacy/slot/Slot.tsx
176
+ import { forwardRef as forwardRef2 } from "react";
177
+ var Slot = forwardRef2(function Slot2({ children, ...slotProps }, ref) {
178
+ return applySlot(children, slotProps, ref, cloneSlotChild);
179
+ });
180
+ Slot.displayName = SLOT_NAME;
197
181
  export {
198
182
  Slot,
199
183
  Slottable,
200
- createAriaEnforcedComponent,
201
- createChildrenEnforcedComponent,
202
184
  createContractComponent,
203
- createContractedComponent,
204
- createPolymorphicComponent,
205
185
  defineContractComponent,
206
186
  mergeRefs
207
187
  };