praxis-kit 0.1.0 → 1.0.2

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,7 +1,7 @@
1
1
  import "clsx";
2
2
  import { DiagnosticCode, DiagnosticInput, Diagnostics, DiagnosticsMode } from "./_shared/diagnostics.js";
3
3
  import { ComponentType, JSX, PropsWithChildren, ReactElement, ReactNode, Ref } from "react";
4
- import { NonEmptyTuple, ReadonlyDeep, RequireAtLeastOne, Simplify } from "type-fest";
4
+ import { NonEmptyTuple, OmitIndexSignature, ReadonlyDeep, RequireAtLeastOne, Simplify } from "type-fest";
5
5
  //#region ../../lib/foundation/src/string-map.d.ts
6
6
  /**
7
7
  * A string-keyed object whose values are of type `T`.
@@ -25,20 +25,6 @@ type EmptyRecord = Record<never, never>;
25
25
  * `{ Header, Content, Footer }`.
26
26
  */
27
27
  type SubComponentMap = Readonly<AnyRecord>;
28
- /**
29
- * Default `Variants` type for components that declare no variants.
30
- *
31
- * Structurally identical to `Readonly<EmptyRecord>`, but named separately so
32
- * editor hovers remain self-descriptive.
33
- */
34
- type NoVariants = Readonly<EmptyRecord>;
35
- /**
36
- * Default `TPreset` type for components that declare no named presets.
37
- *
38
- * Structurally identical to `Readonly<EmptyRecord>`, but named separately so
39
- * editor hovers remain self-descriptive.
40
- */
41
- type NoPreset = Readonly<EmptyRecord>;
42
28
  /**
43
29
  * Fallback for `ExtractPluginProps<TPlugin>` when a plugin contributes no
44
30
  * props, including the no-plugin case.
@@ -540,16 +526,6 @@ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPre
540
526
  type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
541
527
  normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
542
528
  }['normalize'];
543
- /**
544
- * The type-erased shape of {@link FactoryOptions} — every generic parameter widened to its bound.
545
- *
546
- * Use it for a value that must hold *any* factory config (a registry, a generic wrapper). It
547
- * cannot check `styling.compounds` conditions against the real variant keys/values, because it
548
- * has forgotten what they are — for that, annotate against `FactoryOptions<...>` with the concrete
549
- * generics (or `satisfies FactoryOptions<'button', Props, typeof variants>`), which keeps an
550
- * invalid compound condition a type error rather than a silent no-op.
551
- */
552
- type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, AnyClassPluginFactory>;
553
529
  /**
554
530
  * The framework-neutral component-authoring config passed to `createContractComponent` in every
555
531
  * adapter: default tag + name, own-prop defaults, a `normalize` transform, `styling` (variants,
@@ -559,7 +535,9 @@ type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, Reci
559
535
  * `satisfies FactoryOptions<TDefault, Props, typeof variants, ...>` on a config object narrows
560
536
  * `styling.compounds` conditions to the real per-variant-key shape — including resolving a
561
537
  * boolean-shaped axis (`{ true, false }`) to a real `boolean` — so a condition naming a variant or
562
- * value that does not exist is a compile error. `AnyFactoryOptions` cannot do this.
538
+ * value that does not exist is a compile error. Leaving `V` at the bare `VariantMap` instead
539
+ * (whether via `FactoryOptions`'s own default or an explicit erased instantiation) forgets that
540
+ * shape entirely, so the same invalid condition becomes a silent no-op instead.
563
541
  */
564
542
  type FactoryOptions<TDefault extends ElementType = ElementType, Props extends AnyRecord = EmptyRecord, V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory, TAllowed extends ElementType = ElementType> = {
565
543
  /** The intrinsic tag the component renders by default. Overridable per instance via `as`. */
@@ -568,6 +546,33 @@ type FactoryOptions<TDefault extends ElementType = ElementType, Props extends An
568
546
  readonly name?: string;
569
547
  /** Values used for the component's own (non-variant) props when the consumer omits them. */
570
548
  readonly defaults?: Partial<NoInfer<Props>>;
549
+ /**
550
+ * Optional, type-only declaration of this component's complete own-prop shape — present purely
551
+ * for type recovery, never read at runtime (see `declareProps` in `@praxis-kit/adapter-utils`).
552
+ *
553
+ * `defaults` alone can only prove a prop *has a default*, not that it's the complete prop model
554
+ * a component accepts — a `defaults: { size: 'md' }` component may still take `onClick`,
555
+ * `disabled`, and other props with no default at all, none of which a `defaults`-only recovery
556
+ * can see (see `ContractPropsFrom`'s own doc comment for the general shape of this problem).
557
+ * `props` closes that gap: when present, `ContractPropsOf<C>` / `ContractProps<typeof Component>`
558
+ * recover this declared type directly and exactly, in place of the necessarily-partial,
559
+ * literal-widened recovery `defaults` alone allows.
560
+ *
561
+ * Typed as `object | undefined`, not `NoInfer<Props> | undefined` like `defaults`/`onElement` —
562
+ * deliberately decoupled from this interface's own `Props` generic, unlike those two fields.
563
+ * `defaults`/`onElement` are tied to `Props` because real runtime code reads them against a
564
+ * concretely-resolved `Props` for a real call; `props` is never read at runtime at all (see
565
+ * above), so it has no such need, and tying it to `Props extends AnyRecord` would force every
566
+ * hand-declared prop `interface`/`type` an author passes through `declareProps<Props>()` to
567
+ * structurally satisfy `Record<string, unknown>` — a real TypeScript limitation (a named type
568
+ * without an index signature never satisfies that, even via plain assignment, only a fresh
569
+ * object literal does) that would make this field far more awkward to use for its one real job:
570
+ * carrying an author's own already-precise prop type through untouched. `ContractPropsFrom`
571
+ * (`contract-model.ts`) recovers the real value here structurally, straight off `O`'s own
572
+ * literal type — independent of this field's declared type, same as every other `Contract*From`
573
+ * derivation in that file.
574
+ */
575
+ readonly props?: object | undefined;
571
576
  /**
572
577
  * A pure `(props) => props` transform run on every render, after `enforcement.props`'s
573
578
  * normalizers see the same input. Use this for component-specific prop shaping — anything
@@ -622,11 +627,156 @@ type FactoryOptions<TDefault extends ElementType = ElementType, Props extends An
622
627
  *
623
628
  * Return a cleanup function to run when the instance unmounts.
624
629
  */
625
- readonly onElement?: (element: ElementForTag<TDefault | TAllowed>, getProps: () => Readonly<Props>) => void | (() => void);
630
+ readonly onElement?: {
631
+ onElement(element: ElementForTag<TDefault | TAllowed>, getProps: () => Readonly<Props>): void | (() => void);
632
+ }['onElement'];
633
+ };
634
+ //#endregion
635
+ //#region ../../lib/primitive/src/types/factory/contract-model.d.ts
636
+ /**
637
+ * The pipeline this file implements:
638
+ *
639
+ * ```text
640
+ * O (a raw contract literal)
641
+ * → Contract*From<O> one derivation per dimension, straight off O's own shape
642
+ * → ContractDimensions<O> the six derivations, assembled
643
+ * → ContractModel<...> the same six values, as a required-field carrier
644
+ * → ContractModelOf<C> resolves an already-`defineContract`-ed C's real model,
645
+ * or reconstructs one from a raw C via ContractModelFrom
646
+ * ```
647
+ *
648
+ * See `DECISIONS.md`'s `defineContract` entry for the TypeScript limitations that shaped the
649
+ * derivations below.
650
+ */
651
+ /**
652
+ * Canonical type-level representation of a contract's dimensions — the contract-level counterpart
653
+ * to `PolymorphicGenerics`. Every field is required, so a field's presence is never ambiguous the
654
+ * way it is on an optional `FactoryOptions` field.
655
+ */
656
+ interface ContractModel<TDefault extends ElementType = ElementType, Props extends AnyRecord = AnyRecord, V extends Readonly<VariantMap> = Readonly<VariantMap>, TPreset extends RecipeMap<VariantMap> = RecipeMap<VariantMap>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory, TAllowed extends ElementType = ElementType> {
657
+ readonly tag: TDefault;
658
+ readonly props: Props;
659
+ readonly variants: V;
660
+ readonly preset: TPreset;
661
+ readonly plugin: TPlugin;
662
+ readonly allowed: TAllowed;
663
+ }
664
+ /**
665
+ * The phantom-marker shape read back via `T extends HasContractModel<infer M> ? M : ...` — the
666
+ * contract-level counterpart to `lib/contract-props`'s `HasGenerics<G>`. Type-only: never assigned
667
+ * at runtime.
668
+ *
669
+ * `__model` is **required**, not optional like `HasGenerics<G>`'s `__generics?` — an optional field
670
+ * would make `C extends HasContractModel<infer M>` trivially succeed for any `C`, defeating the
671
+ * one thing this marker exists to answer: did `C` really go through `defineContract`?
672
+ */
673
+ interface HasContractModel<M extends ContractModel = ContractModel> {
674
+ readonly __model: M;
675
+ }
676
+ type ContractTagFrom<O> = O extends {
677
+ tag: infer TDefault extends ElementType;
678
+ } ? TDefault : ElementType;
679
+ /** `'img'` → `string`, `1` → `number`, `true` → `boolean` — undoes `defineContract`'s `const O`
680
+ * literal narrowing so a `defaults` value doesn't become the only value a caller may pass. */
681
+ type WidenLiteral<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T;
682
+ type WidenShallow<T> = { [K in keyof T]: WidenLiteral<T[K]>; };
683
+ /** What the author explicitly declared, via `props: declareProps<Props>()`
684
+ * (`@praxis-kit/adapter-utils`) — used exactly as declared, no `Partial`/widening/`data-*`
685
+ * stripping (see `DefaultPropsFrom` for why those exist there but not here). */
686
+ type DeclaredPropsFrom<O> = O extends {
687
+ props: infer Props extends object | undefined;
688
+ } ? [NonNullable<Props>] extends [never] ? never : NonNullable<Props> & AnyRecord : never;
689
+ /** What can be inferred from `defaults` — partial at best, since a default only proves a prop
690
+ * *has* one, not that it's the complete prop set. `Partial`: a defaulted prop is optional to the
691
+ * caller by definition. `data-*` keys are dropped — every adapter has its own passthrough for
692
+ * those already (finding #43). */
693
+ type DefaultPropsFrom<O> = O extends {
694
+ defaults: infer Props extends AnyRecord;
695
+ } ? Partial<WidenShallow<Omit<Props, Extract<keyof Props, `data-${string}`>>>> : never;
696
+ /** Declared beats defaulted beats nothing. `[X] extends [never]`, not bare `X extends never` —
697
+ * tuple-wrapped so the check doesn't distribute if `X` is ever a union containing `never`. */
698
+ type ContractPropsFrom<O> = [DeclaredPropsFrom<O>] extends [never] ? [DefaultPropsFrom<O>] extends [never] ? EmptyRecord : DefaultPropsFrom<O> : DeclaredPropsFrom<O>;
699
+ type ContractVariantsFrom<O> = O extends {
700
+ styling: {
701
+ variants: infer V extends Readonly<VariantMap>;
702
+ };
703
+ } ? V : Readonly<EmptyRecord>;
704
+ type ContractPresetFrom<O> = O extends {
705
+ styling: {
706
+ presets: infer TPreset extends RecipeMap<VariantMap>;
707
+ };
708
+ } ? TPreset : Readonly<EmptyRecord>;
709
+ type ContractPluginFrom<O> = O extends {
710
+ styling: {
711
+ plugin: infer TPlugin extends AnyClassPluginFactory;
712
+ };
713
+ } ? TPlugin : AnyClassPluginFactory;
714
+ type ContractAllowedFrom<O> = O extends {
715
+ enforcement: {
716
+ allowedAs: readonly (infer TAllowed extends ElementType)[];
717
+ };
718
+ } ? TAllowed : ElementType;
719
+ /** The six derivations above, assembled — the direct input to `ContractModel`. */
720
+ type ContractDimensions<O> = {
721
+ readonly tag: ContractTagFrom<O>;
722
+ readonly props: ContractPropsFrom<O>;
723
+ readonly variants: ContractVariantsFrom<O>;
724
+ readonly preset: ContractPresetFrom<O>;
725
+ readonly plugin: ContractPluginFrom<O>;
726
+ readonly allowed: ContractAllowedFrom<O>;
626
727
  };
728
+ /**
729
+ * Builds a `ContractModel` from a raw literal `O` — the fallback path `ContractModelOf<C>` uses
730
+ * when `C` never went through `defineContract` (no `__model` marker to read directly), and what
731
+ * `defineContract` itself attaches as that marker for a `C` that did.
732
+ */
733
+ type ContractModelFrom<O> = ContractDimensions<O> extends (infer D extends ContractDimensions<O>) ? ContractModel<D['tag'], D['props'], D['variants'], D['preset'], D['plugin'], D['allowed']> : never;
734
+ /**
735
+ * Resolves "does `C` carry a real `ContractModel` already, or do we need to build one from its raw
736
+ * shape" — every `Contract*Of` accessor (`contract-of.ts`) is a one-line projection off this.
737
+ */
738
+ type ContractModelOf<C> = C extends HasContractModel<infer M> ? M : ContractModelFrom<C>;
627
739
  //#endregion
628
- //#region ../../lib/adapter-utils/src/runtime/define-component.d.ts
629
- declare function defineContractComponent<O extends FactoryOptions>(options: O): <R>(factory: (options: O) => R) => R;
740
+ //#region ../../lib/primitive/src/types/factory/contract-of.d.ts
741
+ /**
742
+ * `FactoryOptions`-level accessor family, mirroring `polymorphic-generics.ts`'s `*Of<T>`
743
+ * convention (`DefaultOf<G>`, `PropsOf<G>`, etc.) but applied one layer up, to a contract itself
744
+ * rather than to the `PolymorphicGenerics` an adapter derives from it.
745
+ *
746
+ * Named with a `Contract` prefix specifically to avoid colliding with `polymorphic-generics.ts`'s
747
+ * own `PropsOf`/`VariantsOf`/`RecipeOf`/`AllowedOf`/`DefaultOf` — both families are re-exported
748
+ * from `@praxis-kit/core`, so a name clash would be a real conflict, not a style nit.
749
+ *
750
+ * Each accessor is a trivial projection off `ContractModelOf<C>` (`contract-model.ts`) — the one
751
+ * place that resolves "does `C` carry a real `ContractModel` (via `defineContract`) or does one
752
+ * need reconstructing from `C`'s raw shape," so every accessor shares one implementation of that
753
+ * resolution rather than repeating it. See `contract-model.ts`'s own doc comments for the
754
+ * `ContractXFrom<O>` derivation each of these ultimately reads through, and `DECISIONS.md`'s
755
+ * `defineContract` entry for the design history behind the required-pattern-match technique.
756
+ */
757
+ type ContractTagOf<C extends FactoryOptions> = ContractModelOf<C>['tag'];
758
+ /** See this file's own doc comment. Best-effort when `C` has no `ContractModel` marker — see
759
+ * `ContractPropsFrom`'s own doc comment for why. */
760
+ type ContractPropsOf<C extends FactoryOptions> = ContractModelOf<C>['props'];
761
+ /** See this file's own doc comment. */
762
+ type ContractVariantsOf<C extends FactoryOptions> = ContractModelOf<C>['variants'];
763
+ /** See this file's own doc comment. */
764
+ type ContractPresetOf<C extends FactoryOptions> = ContractModelOf<C>['preset'];
765
+ /** See this file's own doc comment. */
766
+ type ContractPluginOf<C extends FactoryOptions> = ContractModelOf<C>['plugin'];
767
+ /** See this file's own doc comment. */
768
+ type ContractAllowedOf<C extends FactoryOptions> = ContractModelOf<C>['allowed'];
769
+ //#endregion
770
+ //#region ../../lib/primitive/src/types/factory/contract-generics.d.ts
771
+ /**
772
+ * Same projection as `ContractGenericsOf`, additionally threading `TAllowed` through to
773
+ * `PolymorphicGenerics`'s own `TAllowed` parameter. Only React's `createContractComponent`
774
+ * currently uses this variant — every other adapter uses the plain `ContractGenericsOf` above,
775
+ * matching their current behavior of not narrowing `as` via `enforcement.allowedAs` at the type
776
+ * level (the ARIA/tag-resolution engine still enforces `allowedAs` identically at runtime for all
777
+ * adapters regardless of which projection their types use).
778
+ */
779
+ type ContractGenericsWithAllowedOf<C extends FactoryOptions> = PolymorphicGenerics<ContractTagOf<C>, MergeRecords<ContractPropsOf<C>, ExtractPluginProps<ContractPluginOf<C>>>, ContractVariantsOf<C>, ContractPresetOf<C>, ContractAllowedOf<C>>;
630
780
  //#endregion
631
781
  //#region ../../lib/pipeline/src/types/primitives.d.ts
632
782
  /** Free-form key/value bag a pass may attach to its result for downstream
@@ -674,6 +824,34 @@ declare function Slottable({ children }: SlottableProps): ReactElement;
674
824
  type UnknownProps = AnyRecord;
675
825
  type SlotComponent = ComponentType<UnknownProps>;
676
826
  //#endregion
827
+ //#region ../../lib/tailwind/src/layout-keys.d.ts
828
+ /**
829
+ * Canonical list of reserved layout prop names.
830
+ *
831
+ * This array is the single source of truth for every supported CSS `display`
832
+ * value exposed as a boolean prop. The `LayoutKey` type is derived directly
833
+ * from this list.
834
+ *
835
+ * To add a new display mode:
836
+ * 1. Add the display value here.
837
+ * 2. Register its layout family in `LAYOUT_FAMILY_MAP`.
838
+ *
839
+ * Prop names intentionally match the corresponding Tailwind/CSS display
840
+ * utilities, so no additional prop-to-class mapping is required.
841
+ */
842
+ declare const layoutKeys: readonly ["flex", "inline-flex", "grid", "inline-grid", "block", "inline-block", "inline", "hidden", "contents", "flow-root", "list-item", "table", "inline-table", "table-caption", "table-cell", "table-column", "table-column-group", "table-footer-group", "table-header-group", "table-row-group", "table-row"];
843
+ /**
844
+ * The concrete union of layout prop names — the pre-resolved form of
845
+ * `LayoutKey<typeof layoutKeys>`, colocated with the tuple it derives from.
846
+ *
847
+ * For code that needs to *name* the layout keys in a type without also importing the runtime
848
+ * tuple. A framework adapter uses it to collapse the mutually-exclusive `LayoutProps` union back
849
+ * out of an *extracted* prop type (`ContractProps<typeof Component>`): there a caller wants "the
850
+ * layout props exist and are optional `true`s", not the ~22-member discriminated union that the
851
+ * component's own call signature carries — where "only one may be `true`" is a useful error.
852
+ */
853
+ type LayoutKeyName = (typeof layoutKeys)[number];
854
+ //#endregion
677
855
  //#region ../../lib/contract-props/src/mode.d.ts
678
856
  /**
679
857
  * The three render modes a praxis-kit component's props can be typed for, shared across every
@@ -693,26 +871,32 @@ type SlotComponent = ComponentType<UnknownProps>;
693
871
  */
694
872
  type Mode = 'normal' | 'asChild' | 'render';
695
873
  //#endregion
696
- //#region ../../lib/contract-props/src/has-generics.d.ts
874
+ //#region ../../lib/contract-props/src/has-contract.d.ts
697
875
  /**
698
- * The phantom-marker shape read back via `T extends HasGenerics<infer G> ? G : never`. See the
699
- * README for why this exists.
876
+ * The phantom-marker shape read back via `T extends HasContract<infer C> ? C : never` — the
877
+ * contract-retention counterpart to `HasGenerics<G>` in this same package. Where `HasGenerics<G>`
878
+ * lets a built component recover the `PolymorphicGenerics` an adapter derived for it,
879
+ * `HasContract<C>` lets it recover the *complete, authoritative contract* (`C`, the argument
880
+ * `createContractComponent<C extends XFactoryOptions>` was actually called with) it was derived
881
+ * from — the two are deliberately separate markers, not one broadened to do both jobs: `G` is
882
+ * "what the adapter needs to implement the component," `C` is "what the component was configured
883
+ * with" (see `DECISIONS.md`'s `defineContract` entry). A component carries both.
884
+ *
885
+ * Type-only: never assigned at runtime, same rationale as `HasGenerics<G>` (see that type's own
886
+ * doc comment) — a `createContractComponent` return value gets this shape via a type assertion,
887
+ * not a real property write.
700
888
  *
701
- * Type-only: never assigned at runtime. In React's `PolymorphicComponent<G>`, declaring `readonly
702
- * __generics?: G` inline (structurally matching this shape) rather than writing `HasGenerics<G> &
703
- * { ...call signatures... }` was necessary to keep `PolymorphicComponent<any>`-typed test helpers
704
- * assignable — confirmed directly against that adapter's own real component type (see
705
- * `adapters/react/src/shared/types/polymorphic-props.test.ts`), not reproducible in an isolated
706
- * minimal mock (see this file's own `has-generics.test.ts`), so treat "inline, not intersected"
707
- * as an adapter-level implementation detail this package's marker shape must stay compatible
708
- * with, not a property `HasGenerics<G>` itself enforces.
889
+ * Unconstrained (no `C extends FactoryOptions` bound), matching `HasGenerics<G>`'s own choice —
890
+ * this package has no dependency on `@praxis-kit/core`/`@praxis-kit/primitive`, and adding one
891
+ * just to write a bound here isn't worth it: the accessor types that actually consume `C`
892
+ * (`ContractTagOf<C>`, etc., in `@praxis-kit/primitive`) already declare their own constraint.
709
893
  *
710
- * Do **not** "harden" this with a `unique symbol` or other nominal brand: the whole point is that
711
- * an adapter's real callable component type structurally satisfies this shape by declaring the
712
- * same optional string-keyed field inline. Nominal purity here would break that compatibility.
894
+ * Do **not** "harden" this with a `unique symbol` or other nominal brand, for the same reason
895
+ * `HasGenerics<G>` doesn't: a real component's callable type needs to structurally satisfy this
896
+ * shape by declaring the same inline optional field, not by importing a nominal brand.
713
897
  */
714
- interface HasGenerics<G> {
715
- readonly __generics?: G;
898
+ interface HasContract<C> {
899
+ readonly __contract?: C;
716
900
  }
717
901
  //#endregion
718
902
  //#region ../../lib/contract-props/src/pick-mode.d.ts
@@ -756,19 +940,15 @@ type ElementRef<T extends ElementType> = T extends IntrinsicTag ? HTMLElementTag
756
940
  * prop definitions determine the accepted props.
757
941
  */
758
942
  type IntrinsicJSXProps<T extends ElementType> = T extends IntrinsicTag ? JSX.IntrinsicElements[T] : UnknownProps;
759
- /**
760
- * Removes index signatures while preserving explicitly declared
761
- * properties.
943
+ /** Props explicitly declared by the component.
762
944
  *
763
- * Prevents broad index signatures (for example `Record<string, unknown>`)
764
- * from causing `keyof T` to become `string`, which would otherwise erase
765
- * every intrinsic prop during `Omit`.
766
- */
767
- type StripIndexSignature<T> = { [K in keyof T as string extends K ? never : K]: T[K]; };
768
- /** Props explicitly declared by the component. */
769
- type ComponentProps<G extends PolymorphicGenerics> = StripIndexSignature<PropsOf<G>>;
945
+ * `OmitIndexSignature` (type-fest) — not a hand-rolled version — matches every other adapter's
946
+ * own `polymorphic-props.ts` (Preact/Vue/Solid all import the same utility for this exact
947
+ * purpose): strips a broad index signature (e.g. `Record<string, unknown>`) so `keyof T` doesn't
948
+ * become `string`, which would otherwise erase every intrinsic prop during the `Omit` below. */
949
+ type ComponentProps<G extends PolymorphicGenerics> = OmitIndexSignature<PropsOf<G>>;
770
950
  /** Variant props generated from the component's variant definitions. */
771
- type ComponentVariants<G extends PolymorphicGenerics> = StripIndexSignature<VariantProps<VariantsOf<G>>>;
951
+ type ComponentVariants<G extends PolymorphicGenerics> = OmitIndexSignature<VariantProps<VariantsOf<G>>>;
772
952
  /**
773
953
  * Props defined by the component itself.
774
954
  *
@@ -810,12 +990,35 @@ type ControlProps<G extends PolymorphicGenerics, TAs extends ElementType> = Owne
810
990
  * Component-defined props always take precedence.
811
991
  */
812
992
  type IntrinsicPropsWithoutOwned<G extends PolymorphicGenerics, TAs extends ElementType> = Omit<IntrinsicJSXProps<TAs>, keyof ControlProps<G, TAs> | 'children'>;
993
+ /**
994
+ * `data-*` attribute passthrough.
995
+ *
996
+ * React's `JSX.IntrinsicElements[tag]` prop types carry no `data-*` index — the JSX checker
997
+ * special-cases `data-*` at the call site instead — so `IntrinsicPropsWithoutOwned` (which is
998
+ * `Omit<JSX.IntrinsicElements[tag], …>`) has no `data-*` key either. A polymorphic component
999
+ * always renders to a host element (or forwards to one via `asChild`) and its runtime prop
1000
+ * pipeline forwards `data-*` unchanged, so the extracted prop type must admit them: without this,
1001
+ * a wrapper can't destructure a `data-*` the contract sets in `defaults` (`data-slot` is the
1002
+ * common case — a styling hook every design system sets and overrides) — `ContractProps<typeof
1003
+ * Component>['data-slot']` would be a type error even though `<Component data-slot="…" />` is
1004
+ * accepted.
1005
+ *
1006
+ * The value type is `string | number | boolean | undefined` by deliberate choice — exactly what
1007
+ * React serializes onto a `data-*` attribute (`true`/`false` render as the strings `"true"` /
1008
+ * `"false"`, not omitted; `undefined` omits) and what survives praxis-kit's prop pipeline
1009
+ * unchanged. It is intentionally tighter than the framework-neutral `unknown` the core contract
1010
+ * uses, so a wrapper can destructure a `data-*` and forward it without a cast — the whole point.
1011
+ */
1012
+ type DataAttribute = `data-${string}`;
1013
+ type DataAttributes = {
1014
+ [key: DataAttribute]: string | number | boolean | undefined;
1015
+ };
813
1016
  /**
814
1017
  * Props shared by every rendering strategy.
815
1018
  *
816
1019
  * Each render mode contributes only its discriminating props.
817
1020
  */
818
- type BaseProps<G extends PolymorphicGenerics, TAs extends ElementType> = IntrinsicPropsWithoutOwned<G, TAs> & ControlProps<G, TAs>;
1021
+ type BaseProps<G extends PolymorphicGenerics, TAs extends ElementType> = IntrinsicPropsWithoutOwned<G, TAs> & ControlProps<G, TAs> & DataAttributes;
819
1022
  /** Standard rendering (`asChild` absent or false). */
820
1023
  type NormalRenderMode = {
821
1024
  asChild?: false;
@@ -858,6 +1061,60 @@ type PolymorphicWithAsChild<G extends PolymorphicGenerics, TAs extends ElementTy
858
1061
  * Render callback props.
859
1062
  */
860
1063
  type PolymorphicWithRender<G extends PolymorphicGenerics, TAs extends ElementType = DefaultOf<G>> = Simplify<BaseProps<G, TAs> & CallbackRenderMode>;
1064
+ /**
1065
+ * Whether a single (already-distributed) union member `M` declares `K` as exactly `true` — the
1066
+ * "this key is the active one *on this member*" check `KeyTrueInAnyMember` runs once per member.
1067
+ * `K extends keyof M` first, so a member that doesn't declare `K` at all (not even `?: never`)
1068
+ * answers `false` rather than erroring on the indexed access. `[M[K]] extends [true]` (not a bare
1069
+ * `M[K] extends true`) rejects plain `boolean` — a component's *own* same-named prop or the
1070
+ * intrinsic `hidden` attribute — so only the literal `true` `ExclusiveTrueProp` itself produces
1071
+ * counts, matching `LayoutPluginKeys`'s own contract.
1072
+ */
1073
+ type IsKeyTrueOn<M, K extends PropertyKey> = K extends keyof M ? [M[K]] extends [true] ? true : false : false;
1074
+ /**
1075
+ * Whether *any* member of the (possibly still-union) `P` sets `K` to `true` — `K` itself if so,
1076
+ * `never` otherwise. `P extends infer M ? ... : never` distributes the check across each member
1077
+ * of `P` individually via `IsKeyTrueOn`, rather than computing `keyof`/an indexed access over the
1078
+ * union as a whole (which only sees keys common to *every* member, via `keyof`'s intersection
1079
+ * rule for unions — confirmed empirically: a union with one member that omits a key entirely,
1080
+ * rather than declaring it `?: never`, silently loses that key everywhere if checked against
1081
+ * `keyof P` directly). `ExclusiveTrueProp` (`@praxis-kit/tailwind`) happens to declare every
1082
+ * layout key on every member today, so that particular gap isn't live — but per-member
1083
+ * distribution costs nothing extra and doesn't depend on that continuing to hold.
1084
+ */
1085
+ type KeyTrueInAnyMember<P, K extends PropertyKey> = P extends (infer M) ? IsKeyTrueOn<M, K> extends true ? K : never : never;
1086
+ /**
1087
+ * The layout keys a prop-union actually carries as the tailwind plugin's mutually-exclusive
1088
+ * shape: for each known layout key, keep it only if `KeyTrueInAnyMember` finds it `true`
1089
+ * somewhere in `P`. A component with no `styling.plugin` yields `never` (no member of a
1090
+ * plugin-less `P` ever sets a layout key `true`).
1091
+ */
1092
+ type LayoutPluginKeys<P> = { [K in LayoutKeyName]-?: KeyTrueInAnyMember<P, K>; }[LayoutKeyName];
1093
+ /**
1094
+ * Collapses the mutually-exclusive `LayoutProps` union down to one flat shape — every layout key
1095
+ * an optional `true` — for the **type-extraction** path (`ContractProps<T>`) only.
1096
+ *
1097
+ * `styling.plugin: createTailwindPipeline` contributes `ExclusiveTrueProp<LayoutKey>` — a ~22-way
1098
+ * union (`{ flex: true } | { grid: true } | …`) that distributes through every downstream type,
1099
+ * so `PolymorphicProps<G>` (and a `ContractProps<T>` built from it) becomes a ~22-member union
1100
+ * whose members share no common layout key. That makes the extracted type hostile to every
1101
+ * structural operation a consumer does with it: a spread matches no member on any extra/missing
1102
+ * key (`not assignable to '… | … 20 more … | …'`), `Omit`/`Pick`/`Merge` trips `TS2590 union too
1103
+ * complex`, a rest-destructure trips `TS2700`.
1104
+ *
1105
+ * A consumer extracting props to build a wrapper wants "the layout props exist and are optional",
1106
+ * not the discriminated union — so flatten it here. The strict union stays on
1107
+ * `PolymorphicComponent<G>`'s call overloads, where "only one display prop may be `true`" is the
1108
+ * whole point of the compile error. See finding #44 /
1109
+ * `praxis-kit-0.1.x-contractprops-regression.md` item #2.
1110
+ *
1111
+ * `Omit<P, LayoutKeyName>` (a static key set, so cheap) drops every layout key from every member
1112
+ * — the members only ever differed there — so the union dedupes to one; the flat
1113
+ * `{ flex?: true; … }` is added back from just the keys the union really had. The
1114
+ * `LayoutPluginKeys<P> extends never` fast-path returns `P` untouched for a plugin-less
1115
+ * component, so the expensive `Omit` never runs on the (large) intrinsic-prop object there.
1116
+ */
1117
+ type FlattenLayout<P> = [P] extends [never] ? never : [LayoutPluginKeys<P>] extends [never] ? P : Simplify<Omit<P, LayoutKeyName> & { [K in LayoutPluginKeys<P>]?: true; }>;
861
1118
  /**
862
1119
  * A polymorphic React component.
863
1120
  *
@@ -867,7 +1124,7 @@ type PolymorphicWithRender<G extends PolymorphicGenerics, TAs extends ElementTyp
867
1124
  * - `asChild` — slot rendering
868
1125
  * - default — standard polymorphic rendering
869
1126
  */
870
- type PolymorphicComponent<G extends PolymorphicGenerics> = {
1127
+ type PolymorphicComponent<G extends PolymorphicGenerics, C extends FactoryOptions = FactoryOptions> = {
871
1128
  <TAs extends ElementType = DefaultOf<G>>(props: PolymorphicWithRender<G, TAs>): ReactElement;
872
1129
  <TAs extends ElementType = DefaultOf<G>>(props: PolymorphicWithAsChild<G, TAs>): ReactElement;
873
1130
  <TAs extends ElementType = DefaultOf<G>>(props: PolymorphicProps<G, TAs>): ReactElement;
@@ -879,6 +1136,13 @@ type PolymorphicComponent<G extends PolymorphicGenerics> = {
879
1136
  * overload. Anchoring that overload to the default element preserves
880
1137
  * correct prop inference for tools such as Storybook and
881
1138
  * `React.ComponentProps`.
1139
+ *
1140
+ * Deliberately *not* run through `FlattenLayout`: this overload is still a
1141
+ * real call signature (it catches calls the three generic overloads reject),
1142
+ * so flattening it here would make `<Component flex grid />` — two
1143
+ * mutually-exclusive layout props — compile. `ContractProps<T>` does the
1144
+ * flattening instead, on the pure type-extraction path. `React.ComponentProps`
1145
+ * keeps the strict union it already had.
882
1146
  */
883
1147
  (props: PolymorphicProps<G, DefaultOf<G>>): ReactElement;
884
1148
  /**
@@ -886,13 +1150,30 @@ type PolymorphicComponent<G extends PolymorphicGenerics> = {
886
1150
  * the full rationale — kept as an inline field rather than `HasGenerics<G> & {...}` because
887
1151
  * intersecting it onto this callable type changes how `PolymorphicComponent<any>` (used by
888
1152
  * test helpers like `box()`) resolves against concrete instantiations; structurally identical
889
- * to `HasGenerics<G>` either way, which is what lets `ContractProps` constrain against it.
1153
+ * to `HasGenerics<G>` either way.
1154
+ *
1155
+ * `ContractProps` no longer reads this field directly (Phase 4: it projects `G` from the
1156
+ * retained `__contract` below instead) — kept per Phase 3's migration policy (added alongside
1157
+ * `__contract`, not replaced by it, until every adapter and test proves the new relationship
1158
+ * out), and because other code may still constrain against `HasGenerics<G>` directly.
890
1159
  */
891
1160
  readonly __generics?: G;
1161
+ /**
1162
+ * Type-only; never assigned at runtime — same rationale as `__generics` above, and the same
1163
+ * "inline field, not intersected" reason (see `HasContract<C>`, `@praxis-kit/contract-props`).
1164
+ * Carries the *complete* contract this component was built from (`C`, the argument
1165
+ * `createContractComponent<C extends ReactFactoryOptions>` was actually called with) —
1166
+ * deliberately a second, separate marker from `__generics`, not `__generics` broadened to do
1167
+ * both jobs: `G` answers "what does the adapter need to implement this component," `C` answers
1168
+ * "what was this component configured with" — related questions, different answers (see
1169
+ * `DECISIONS.md`'s `defineContract` entry). Defaults to the widest `FactoryOptions` so every
1170
+ * existing two-argument `PolymorphicComponent<G>` reference keeps resolving exactly as before.
1171
+ */
1172
+ readonly __contract?: C;
892
1173
  displayName?: string;
893
1174
  };
894
1175
  /**
895
- * Recovers a built `PolymorphicComponent<G>`'s prop shape for a specific render mode, from
1176
+ * Recovers a built `PolymorphicComponent<G, C>`'s prop shape for a specific render mode, from
896
1177
  * outside the file that built it — the missing piece `React.ComponentProps<typeof Component>`
897
1178
  * can't provide, since it always resolves against `PolymorphicComponent`'s normal-mode fallback
898
1179
  * overload (see that type's own doc comment).
@@ -908,10 +1189,21 @@ type PolymorphicComponent<G extends PolymorphicGenerics> = {
908
1189
  * type ContainerAsChildProps = ContractProps<typeof Container, 'asChild'>
909
1190
  * ```
910
1191
  *
911
- * `T` accepts any built component value (`PolymorphicComponent<G>` or `CompoundComponent<G, S>` —
912
- * the latter's sub-component intersection doesn't disturb `__generics`, which lives on the root
913
- * call signature) via its own `__generics` marker; the `never` branch below only fires for a
914
- * non-praxis-kit component, which has no `__generics` field to infer from at all.
1192
+ * Projects off the component's retained `__contract` (`C`, via `HasContract<C>` —
1193
+ * `@praxis-kit/contract-props`), not `__generics` (`G`) — a deliberate Phase 4 rewire, not a new
1194
+ * mechanism: `G` is *derived* from `C` (`ContractGenericsWithAllowedOf<C>`, the same canonical
1195
+ * projection `createContractComponent`'s own return type already uses), so reading `C` and
1196
+ * projecting `G` from it recovers exactly the same `G` `__generics` would have, without needing a
1197
+ * second, independently-populated marker to stay in sync with the first. `FlattenLayout`,
1198
+ * `PickMode`, `Mode`, and the three `Polymorphic*` prop-shape types below are unchanged — only
1199
+ * where `G` comes from moved. `__generics` itself is untouched (Phase 3's migration policy: added
1200
+ * alongside `__contract`, not replaced by it, until every adapter and test proves the new
1201
+ * relationship out — see that field's own doc comment).
1202
+ *
1203
+ * `T` accepts any built component value (`PolymorphicComponent<G, C>` or `CompoundComponent<G, S>`
1204
+ * — the latter's sub-component intersection doesn't disturb `__contract`, which lives on the root
1205
+ * call signature) via its own `__contract` marker; the `never` branch below only fires for a
1206
+ * non-praxis-kit component, which has no `__contract` field to infer from at all.
915
1207
  *
916
1208
  * Always resolves against the component's *default* element (`PolymorphicWithAsChild<G,
917
1209
  * DefaultOf<G>>`, etc.) — the same ceiling `React.ComponentProps<typeof Component>` already has
@@ -920,7 +1212,7 @@ type PolymorphicComponent<G extends PolymorphicGenerics> = {
920
1212
  * `PolymorphicProps<G, 'a'>` when a caller needs a specific non-default `as` — those remain two
921
1213
  * different questions with two different answers.
922
1214
  */
923
- type ContractProps<T extends HasGenerics<PolymorphicGenerics>, M extends Mode = 'normal'> = T extends HasGenerics<infer G extends PolymorphicGenerics> ? PickMode<M, PolymorphicProps<G, DefaultOf<G>>, PolymorphicWithAsChild<G, DefaultOf<G>>, PolymorphicWithRender<G, DefaultOf<G>>> : never;
1215
+ type ContractProps<T extends HasContract<FactoryOptions>, M extends Mode = 'normal'> = T extends HasContract<infer C extends FactoryOptions> ? ContractGenericsWithAllowedOf<C> extends (infer G extends PolymorphicGenerics) ? PickMode<M, FlattenLayout<PolymorphicProps<G, DefaultOf<G>>>, FlattenLayout<PolymorphicWithAsChild<G, DefaultOf<G>>>, FlattenLayout<PolymorphicWithRender<G, DefaultOf<G>>>> : never : never;
924
1216
  //#endregion
925
1217
  //#region ../../adapters/react/src/shared/react-options.d.ts
926
1218
  /** Structural subset of `CompiledComponentArtifact` consumed by the React adapter. */
@@ -933,8 +1225,15 @@ interface CompiledArtifact {
933
1225
  /**
934
1226
  * Extends FactoryOptions with React-specific configuration.
935
1227
  * slotComponent is intentionally not in core — it is a React rendering concern.
1228
+ *
1229
+ * Every generic parameter has a default (widened to that parameter's own *bound*, matching
1230
+ * a wide-bound, type-erased philosophy, not `FactoryOptions`'s own narrower `EmptyRecord`-style
1231
+ * defaults) so `ReactFactoryOptions` can be used bare, as `createContractComponent`'s single
1232
+ * `C extends ReactFactoryOptions` constraint — a real contract's non-empty `variants`/`presets`
1233
+ * must structurally satisfy that bound, which narrow defaults would reject (confirmed while
1234
+ * building `ContractInput`, the same fix applied there for the same reason).
936
1235
  */
937
- type ReactFactoryOptions<TDefault extends ElementType, Props extends UnknownProps, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = NoPreset, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory, TAllowed extends ElementType = ElementType> = FactoryOptions<TDefault, Props, Variants, TPreset, TPlugin, TAllowed> & {
1236
+ type ReactFactoryOptions<TDefault extends ElementType = ElementType, Props extends UnknownProps = UnknownProps, Variants extends Readonly<VariantMap> = Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = RecipeMap<Variants>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory, TAllowed extends ElementType = ElementType> = FactoryOptions<TDefault, Props, Variants, TPreset, TPlugin, TAllowed> & {
938
1237
  /** Component used to render the asChild slot. Defaults to the built-in Slot. */
939
1238
  slotComponent?: SlotComponent;
940
1239
  /**
@@ -948,4 +1247,4 @@ type ReactFactoryOptions<TDefault extends ElementType, Props extends UnknownProp
948
1247
  artifact?: CompiledArtifact;
949
1248
  };
950
1249
  //#endregion
951
- export { MergeRecords as C, AnyRecord as E, EmptyRecord as S, NoVariants as T, ExtractPluginProps as _, PolymorphicProps as a, VariantMap as b, RenderCallbackProps as c, SlottableProps as d, mergeRefs as f, AnyClassPluginFactory as g, FactoryOptions as h, PolymorphicComponent as i, UnknownProps as l, AnyFactoryOptions as m, ContractProps as n, PolymorphicWithAsChild as o, defineContractComponent as p, ElementRef as r, PolymorphicWithRender as s, ReactFactoryOptions as t, Slottable as u, PolymorphicGenerics as v, NoPreset as w, ElementType as x, RecipeMap as y };
1250
+ export { RecipeMap as C, MergeRecords as D, EmptyRecord as E, AnyRecord as O, PolymorphicGenerics as S, ElementType as T, ContractTagOf as _, PolymorphicProps as a, AnyClassPluginFactory as b, RenderCallbackProps as c, SlottableProps as d, mergeRefs as f, ContractPropsOf as g, ContractPresetOf as h, PolymorphicComponent as i, UnknownProps as l, ContractPluginOf as m, ContractProps as n, PolymorphicWithAsChild as o, ContractAllowedOf as p, ElementRef as r, PolymorphicWithRender as s, ReactFactoryOptions as t, Slottable as u, ContractVariantsOf as v, VariantMap as w, ExtractPluginProps as x, FactoryOptions as y };