praxis-kit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +77 -0
- package/dist/_shared/diagnostics.d.ts +312 -0
- package/dist/_shared/diagnostics.js +360 -0
- package/dist/build-runtime-CJ_nQEaZ.js +5065 -0
- package/dist/codemod/index.d.ts +2 -0
- package/dist/codemod/index.js +176520 -0
- package/dist/contract/index.d.ts +677 -0
- package/dist/contract/index.js +341 -0
- package/dist/eslint/index.d.ts +90 -0
- package/dist/eslint/index.js +1047 -0
- package/dist/guards/index.d.ts +78 -0
- package/dist/guards/index.js +118 -0
- package/dist/html/index.d.ts +151 -0
- package/dist/html/index.js +1244 -0
- package/dist/index-BIBd_iPD.d.ts +951 -0
- package/dist/lit/index.d.ts +862 -0
- package/dist/lit/index.js +4893 -0
- package/dist/preact/index.d.ts +796 -0
- package/dist/preact/index.js +5043 -0
- package/dist/react/index.d.ts +28 -0
- package/dist/react/index.js +205 -0
- package/dist/react/legacy.d.ts +29 -0
- package/dist/react/legacy.js +80 -0
- package/dist/solid/index.d.ts +728 -0
- package/dist/solid/index.js +4821 -0
- package/dist/svelte/Polymorphic.svelte +190 -0
- package/dist/svelte/_polymorphic-runtime.d.ts +102 -0
- package/dist/svelte/_polymorphic-runtime.js +371 -0
- package/dist/svelte/index.d.ts +994 -0
- package/dist/svelte/index.js +4482 -0
- package/dist/tailwind/index.d.ts +197 -0
- package/dist/tailwind/index.js +767 -0
- package/dist/tailwind/safelist.css +20 -0
- package/dist/ts-plugin/index.cjs +166 -0
- package/dist/ts-plugin/index.d.cts +9 -0
- package/dist/utils/index.d.ts +19 -0
- package/dist/utils/index.js +21 -0
- package/dist/vite-plugin/index.d.ts +200 -0
- package/dist/vite-plugin/index.js +2106 -0
- package/dist/vue/index.d.ts +729 -0
- package/dist/vue/index.js +4945 -0
- package/dist/web/index.d.ts +832 -0
- package/dist/web/index.js +4868 -0
- package/package.json +258 -0
|
@@ -0,0 +1,951 @@
|
|
|
1
|
+
import "clsx";
|
|
2
|
+
import { DiagnosticCode, DiagnosticInput, Diagnostics, DiagnosticsMode } from "./_shared/diagnostics.js";
|
|
3
|
+
import { ComponentType, JSX, PropsWithChildren, ReactElement, ReactNode, Ref } from "react";
|
|
4
|
+
import { NonEmptyTuple, ReadonlyDeep, RequireAtLeastOne, Simplify } from "type-fest";
|
|
5
|
+
//#region ../../lib/foundation/src/string-map.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A string-keyed object whose values are of type `T`.
|
|
8
|
+
*/
|
|
9
|
+
type StringMap<T = unknown> = Record<string, T>;
|
|
10
|
+
/**
|
|
11
|
+
* A string-keyed object with values of unknown type.
|
|
12
|
+
*/
|
|
13
|
+
type AnyRecord = StringMap<unknown>;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region ../../lib/primitive/src/types/any-record.d.ts
|
|
16
|
+
/**
|
|
17
|
+
* An object type with no named properties.
|
|
18
|
+
*
|
|
19
|
+
* Unlike `{}`, this excludes arbitrary properties during type operations while
|
|
20
|
+
* still satisfying `extends object`.
|
|
21
|
+
*/
|
|
22
|
+
type EmptyRecord = Record<never, never>;
|
|
23
|
+
/**
|
|
24
|
+
* A compound component's named sub-components, for example
|
|
25
|
+
* `{ Header, Content, Footer }`.
|
|
26
|
+
*/
|
|
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
|
+
/**
|
|
43
|
+
* Fallback for `ExtractPluginProps<TPlugin>` when a plugin contributes no
|
|
44
|
+
* props, including the no-plugin case.
|
|
45
|
+
*
|
|
46
|
+
* Structurally identical to `EmptyRecord`, but named separately so editor
|
|
47
|
+
* hovers remain self-descriptive.
|
|
48
|
+
*/
|
|
49
|
+
type NoPluginProps = EmptyRecord;
|
|
50
|
+
/**
|
|
51
|
+
* Determines whether an object type should be treated as empty.
|
|
52
|
+
*
|
|
53
|
+
* `keyof T` ignores call and construct signatures...
|
|
54
|
+
*/
|
|
55
|
+
type IsEmptyRecord<T extends object> = T extends ((...args: never[]) => unknown) ? false : T extends (new (...args: never[]) => unknown) ? false : keyof T extends never ? true : false;
|
|
56
|
+
/**
|
|
57
|
+
* Merges two object types while eliding empty operands.
|
|
58
|
+
*
|
|
59
|
+
* If either operand is {@link EmptyRecord}, the other operand is returned
|
|
60
|
+
* directly instead of producing intersections such as
|
|
61
|
+
* `Component & EmptyRecord` in editor hovers.
|
|
62
|
+
*
|
|
63
|
+
* Unlike a homomorphic mapped type (for example `Simplify<T>`), this preserves
|
|
64
|
+
* call and construct signatures. Many component types are callable objects,
|
|
65
|
+
* and mapped types silently discard those signatures.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* Instantiate `MergeRecords` directly. Introducing an intermediate alias for
|
|
69
|
+
* one operand (for example `type C = PolymorphicComponent<G>`) can prevent
|
|
70
|
+
* `IsEmptyRecord` from evaluating eagerly, which breaks assignability under
|
|
71
|
+
* `exactOptionalPropertyTypes`.
|
|
72
|
+
*/
|
|
73
|
+
type MergeRecords<A extends object, B extends object> = IsEmptyRecord<A> extends true ? B : IsEmptyRecord<B> extends true ? A : A & B;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region ../../lib/primitive/src/types/intrinsic-tag.d.ts
|
|
76
|
+
type IntrinsicTag = keyof HTMLElementTagNameMap;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region ../../lib/primitive/src/types/element-type.d.ts
|
|
79
|
+
type ElementType = IntrinsicTag | (string & {});
|
|
80
|
+
/**
|
|
81
|
+
* Resolves a component's default tag to its real DOM interface — `HTMLDialogElement` for
|
|
82
|
+
* `'dialog'`, `HTMLDetailsElement` for `'details'`, and so on — falling back to `HTMLElement`
|
|
83
|
+
* for custom-element tags or anything not in `HTMLElementTagNameMap`. Used to type
|
|
84
|
+
* `FactoryOptions.onElement`'s `element` param so component authors get direct, correctly-typed
|
|
85
|
+
* access to tag-specific native members (`dialogEl.showModal()`) without an unsafe cast.
|
|
86
|
+
*
|
|
87
|
+
* The fallback is `HTMLElement`, not the more generic `Element` — every tag reachable through
|
|
88
|
+
* `IntrinsicTag` extends it, and so does every custom element per spec, so members `HTMLElement`
|
|
89
|
+
* itself declares (`showPopover()`/`hidePopover()`/`togglePopover()`, the `popover` attribute)
|
|
90
|
+
* stay directly accessible even for tags with no dedicated entry in `HTMLElementTagNameMap`.
|
|
91
|
+
*/
|
|
92
|
+
type ElementForTag<TDefault extends ElementType> = TDefault extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[TDefault] : HTMLElement;
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region ../../lib/primitive/src/constants/aria/known-aria-roles.d.ts
|
|
95
|
+
declare const KNOWN_ARIA_ROLES: readonly ["alert", "alertdialog", "application", "article", "banner", "blockquote", "button", "caption", "cell", "checkbox", "code", "columnheader", "combobox", "complementary", "contentinfo", "definition", "deletion", "dialog", "document", "emphasis", "feed", "figure", "form", "generic", "grid", "gridcell", "group", "heading", "img", "insertion", "link", "list", "listbox", "listitem", "log", "main", "marquee", "math", "menu", "menubar", "menuitem", "menuitemcheckbox", "menuitemradio", "meter", "navigation", "none", "note", "option", "paragraph", "presentation", "progressbar", "radio", "radiogroup", "region", "row", "rowgroup", "rowheader", "scrollbar", "search", "searchbox", "separator", "slider", "spinbutton", "status", "strong", "subscript", "superscript", "switch", "tab", "table", "tablist", "tabpanel", "term", "textbox", "time", "timer", "toolbar", "tooltip", "tree", "treegrid", "treeitem"];
|
|
96
|
+
type KnownAriaRole = (typeof KNOWN_ARIA_ROLES)[number];
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region ../../lib/primitive/src/types/primitives/index.d.ts
|
|
99
|
+
type Booleanish = boolean | 'true' | 'false';
|
|
100
|
+
type ClassName = string | string[];
|
|
101
|
+
type NonEmptyArray<T> = [T, ...T[]];
|
|
102
|
+
type Numberish = number | `${number}`;
|
|
103
|
+
type Primitive = string | number | boolean;
|
|
104
|
+
type AriaRole = KnownAriaRole | (string & {});
|
|
105
|
+
type IntrinsicProps = AnyRecord & {
|
|
106
|
+
role?: AriaRole;
|
|
107
|
+
};
|
|
108
|
+
type TagMap = Partial<Record<IntrinsicTag | (string & {}), ClassName>>;
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region ../../lib/primitive/src/types/contracts/cardinality.d.ts
|
|
111
|
+
type MinMax = {
|
|
112
|
+
min: number;
|
|
113
|
+
max: number;
|
|
114
|
+
};
|
|
115
|
+
type CardinalityInput = Partial<MinMax>;
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region ../../lib/primitive/src/types/contracts/child-rule-context.d.ts
|
|
118
|
+
/**
|
|
119
|
+
* Resolved per-instance state available to a dynamic (`dynamic(...)`) child
|
|
120
|
+
* rule field — the same tag/props every adapter already computes before
|
|
121
|
+
* evaluating children, exposed so a rule can vary by them (e.g. cardinality
|
|
122
|
+
* that depends on the resolved `as` tag).
|
|
123
|
+
*/
|
|
124
|
+
type ChildRuleContext = {
|
|
125
|
+
readonly tag: unknown;
|
|
126
|
+
readonly props: Readonly<AnyRecord>;
|
|
127
|
+
};
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region ../../lib/primitive/src/rule/rule-brand.d.ts
|
|
130
|
+
declare const RULE_BRAND: unique symbol;
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region ../../lib/primitive/src/types/rule/dynamic-rule.d.ts
|
|
133
|
+
type DynamicRule<T, C = unknown> = {
|
|
134
|
+
readonly [RULE_BRAND]: true;
|
|
135
|
+
resolve(context: C): T;
|
|
136
|
+
};
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region ../../lib/primitive/src/types/rule/rule.d.ts
|
|
139
|
+
type Rule<T, C = unknown> = T | DynamicRule<T, C>;
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region ../../lib/primitive/src/types/contracts/child-rule-match.d.ts
|
|
142
|
+
type ChildRuleMatch<T, U extends T = T> = (child: T) => child is U;
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region ../../lib/primitive/src/types/contracts/child-rule-position.d.ts
|
|
145
|
+
type ChildRulePosition = 'first' | 'last' | 'any';
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region ../../lib/primitive/src/types/contracts/child-rule-input.d.ts
|
|
148
|
+
type ChildRuleInput<T = unknown, U extends T = T> = {
|
|
149
|
+
name: string;
|
|
150
|
+
match: ChildRuleMatch<T, U>;
|
|
151
|
+
/**
|
|
152
|
+
* Either a static cardinality, or `dynamic((ctx) => ...)` to derive it from
|
|
153
|
+
* the resolved tag/props (e.g. a different max depending on `as`). `match`
|
|
154
|
+
* stays static-only — it's already a function, so a dynamic wrapper would
|
|
155
|
+
* be indistinguishable from the predicate itself without one.
|
|
156
|
+
*/
|
|
157
|
+
cardinality?: Rule<CardinalityInput, ChildRuleContext>;
|
|
158
|
+
position?: ChildRulePosition;
|
|
159
|
+
/**
|
|
160
|
+
* Optional component-type reference for O(1) dispatch index.
|
|
161
|
+
* When provided for every rule, the matcher reads child.type instead of
|
|
162
|
+
* calling every match function on every child (O(n×m) → O(n+m)).
|
|
163
|
+
*/
|
|
164
|
+
type?: unknown;
|
|
165
|
+
};
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region ../../lib/primitive/src/types/validation/valid-result.d.ts
|
|
168
|
+
type ValidResult = {
|
|
169
|
+
valid: true;
|
|
170
|
+
};
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region ../../lib/primitive/src/types/variants/string-to-boolean.d.ts
|
|
173
|
+
type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region ../../lib/primitive/src/types/variants/variant-value.d.ts
|
|
176
|
+
type VariantValue = string | string[];
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region ../../lib/primitive/src/types/variants/variant-states.d.ts
|
|
179
|
+
type VariantStates<K extends string = string> = Record<K, VariantValue>;
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region ../../lib/primitive/src/types/variants/variant-map.d.ts
|
|
182
|
+
type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region ../../lib/primitive/src/types/variants/variant-key.d.ts
|
|
185
|
+
type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region ../../lib/primitive/src/types/variants/variant-selection.d.ts
|
|
188
|
+
/**
|
|
189
|
+
* A partial selection of variant states authored at factory definition time.
|
|
190
|
+
*
|
|
191
|
+
* Uses `keyof V[K]` directly (not `VariantKey`) so TypeScript can eagerly
|
|
192
|
+
* resolve the union at constraint-check time without deferred conditional types.
|
|
193
|
+
*/
|
|
194
|
+
type VariantSelection<V extends VariantMap> = { [K in keyof V]?: keyof V[K]; };
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region ../../lib/primitive/src/types/variants/variant-props.d.ts
|
|
197
|
+
/** The full optional prop surface exposed to callers for a given variant map. */
|
|
198
|
+
type VariantProps<V extends VariantMap> = { [K in keyof V]?: VariantKey<V, K>; };
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region ../../lib/primitive/src/types/variants/default-variants.d.ts
|
|
201
|
+
type NormalizedVariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
|
|
202
|
+
type DefaultVariants<V extends VariantMap> = { [K in keyof V]?: NormalizedVariantValue<keyof V[K] & string>; };
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region ../../lib/primitive/src/types/variants/recipe-map.d.ts
|
|
205
|
+
/**
|
|
206
|
+
* A static, immutable map of named presets to partial variant selections.
|
|
207
|
+
*
|
|
208
|
+
* Presets are named bundles of variant props that callers activate by key,
|
|
209
|
+
* avoiding the need to repeat variant combinations at each call site.
|
|
210
|
+
*/
|
|
211
|
+
type RecipeMap<V extends VariantMap = VariantMap> = Readonly<StringMap<VariantSelection<V>>>;
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region ../../lib/primitive/src/types/variants/recipe-target.d.ts
|
|
214
|
+
type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region ../../lib/primitive/src/types/variants/polymorphic-generics.d.ts
|
|
217
|
+
/**
|
|
218
|
+
* The framework-neutral descriptor for a single praxis-kit component's contract — every render
|
|
219
|
+
* mechanism (tag resolution, prop merging, classes, ARIA) and every framework adapter's
|
|
220
|
+
* component type is built from this one shape. Deliberately just data: five type parameters and
|
|
221
|
+
* their corresponding properties, with no notion of JSX, call signatures, refs, or any
|
|
222
|
+
* framework-specific rendering concern. Each adapter (React, Vue, Svelte, Solid, Lit, Web) builds
|
|
223
|
+
* its own idiomatic component type on top of a `PolymorphicGenerics<...>` instantiation — see
|
|
224
|
+
* `PolymorphicComponent<G>` (`adapters/react/src/shared/types/polymorphic-props.ts`) for the
|
|
225
|
+
* React example — rather than this interface knowing anything about any of them.
|
|
226
|
+
*
|
|
227
|
+
* Use the `*Of<T>` accessor aliases below (`DefaultOf<G>`, `PropsOf<G>`, etc.) to read a single
|
|
228
|
+
* field back out of an already-resolved `G`, instead of indexing `G['default']` etc. directly at
|
|
229
|
+
* call sites — same rationale as any accessor: the property name stays an implementation detail,
|
|
230
|
+
* and every reader benefits together if it ever needs to change.
|
|
231
|
+
*/
|
|
232
|
+
interface PolymorphicGenerics<
|
|
233
|
+
/**
|
|
234
|
+
* The element/tag this component renders as when the consumer doesn't override it via `as`
|
|
235
|
+
* (`AllowedOf<G>` permitting) — e.g. `'button'`, `'div'`. Defaults to the widest `ElementType`
|
|
236
|
+
* so a generic `PolymorphicGenerics` reference (with nothing else specified) still compiles.
|
|
237
|
+
*/
|
|
238
|
+
TDefault extends ElementType = ElementType,
|
|
239
|
+
/**
|
|
240
|
+
* The props this specific component declares — its own contract, before variants are mixed
|
|
241
|
+
* in. Defaults to `AnyRecord` for the same "still compiles unspecified" reason as `TDefault`.
|
|
242
|
+
*/
|
|
243
|
+
Props extends AnyRecord = AnyRecord,
|
|
244
|
+
/**
|
|
245
|
+
* This component's variant definitions (e.g. `{ intent: { primary: ..., ghost: ... } }`).
|
|
246
|
+
* Constrained to `Readonly<VariantMap>` — not the wider `AnyRecord` — specifically so `TPreset`
|
|
247
|
+
* below can be expressed as `RecipeMap<Variants>` and get real per-variant-key checking,
|
|
248
|
+
* instead of falling back to an unconstrained `RecipeMap<VariantMap>`.
|
|
249
|
+
*/
|
|
250
|
+
Variants extends Readonly<VariantMap> = Readonly<VariantMap>,
|
|
251
|
+
/**
|
|
252
|
+
* Named presets (`RecipeMap<Variants>`) — bundles of variant selections a consumer activates
|
|
253
|
+
* by key instead of repeating the same variant combination at every call site. Tied to
|
|
254
|
+
* `Variants`, not `AnyRecord`, precisely so a preset can only ever select keys/values that
|
|
255
|
+
* `Variants` actually defines — an invalid preset is a type error, not a silent no-op.
|
|
256
|
+
* Defaults to `Readonly<EmptyRecord>` (no presets), which is the common case: a component can
|
|
257
|
+
* have variants without necessarily defining any named presets over them, and most don't.
|
|
258
|
+
*/
|
|
259
|
+
TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>,
|
|
260
|
+
/**
|
|
261
|
+
* The set of elements/tags a consumer is allowed to switch to via `as`. Defaults to the widest
|
|
262
|
+
* `ElementType`, under which `AllowedOf<G>` imposes no restriction at all (see
|
|
263
|
+
* `PolymorphicControlProps.as`'s own comment in the React adapter for the concrete effect this
|
|
264
|
+
* has at a component's actual call site).
|
|
265
|
+
*/
|
|
266
|
+
TAllowed extends ElementType = ElementType> {
|
|
267
|
+
default: TDefault;
|
|
268
|
+
props: Props;
|
|
269
|
+
variants: Variants;
|
|
270
|
+
preset: TPreset;
|
|
271
|
+
allowed: TAllowed;
|
|
272
|
+
}
|
|
273
|
+
/** This component's variant definitions. See `PolymorphicGenerics`'s `Variants` parameter. */
|
|
274
|
+
type VariantsOf<T extends PolymorphicGenerics> = T['variants'];
|
|
275
|
+
/** This component's named presets. See `PolymorphicGenerics`'s `TPreset` parameter. */
|
|
276
|
+
type RecipeOf<T extends PolymorphicGenerics> = T['preset'];
|
|
277
|
+
/** The set of elements/tags this component may render as via `as`. See `PolymorphicGenerics`'s
|
|
278
|
+
* `TAllowed` parameter. */
|
|
279
|
+
type AllowedOf<T extends PolymorphicGenerics> = T['allowed'];
|
|
280
|
+
/** The element/tag this component renders as by default. See `PolymorphicGenerics`'s `TDefault`
|
|
281
|
+
* parameter. */
|
|
282
|
+
type DefaultOf<T extends PolymorphicGenerics> = T['default'];
|
|
283
|
+
/** This component's own declared props, before variants are mixed in. See `PolymorphicGenerics`'s
|
|
284
|
+
* `Props` parameter. */
|
|
285
|
+
type PropsOf<T extends PolymorphicGenerics> = T['props'];
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region ../../lib/primitive/src/types/variants/compound/compound-variant.d.ts
|
|
288
|
+
type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
|
|
289
|
+
type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
|
|
290
|
+
type CompoundVariantConditions<V extends VariantMap> = Simplify<{ [K in keyof V]: CompoundVariantConditionValue<V, K>; }>;
|
|
291
|
+
type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
|
|
292
|
+
type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
|
|
293
|
+
type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
|
|
294
|
+
class: VariantValue;
|
|
295
|
+
};
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region ../../lib/primitive/src/types/variants/compound/cva-compounds.d.ts
|
|
298
|
+
interface CVACompounds<V extends VariantMap> {
|
|
299
|
+
compoundVariants?: readonly CompoundVariant<V>[];
|
|
300
|
+
}
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region ../../lib/primitive/src/types/variants/compound/cva-defaults.d.ts
|
|
303
|
+
interface CVADefaults<V extends VariantMap> {
|
|
304
|
+
defaultVariants?: DefaultVariants<V>;
|
|
305
|
+
}
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region ../../lib/primitive/src/types/variants/compound/cva-variants.d.ts
|
|
308
|
+
interface CVAVariants<V extends VariantMap> {
|
|
309
|
+
variants?: V;
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region ../../lib/primitive/src/types/pipeline/base-class-options.d.ts
|
|
313
|
+
interface BaseClassOptions {
|
|
314
|
+
baseClassName?: ClassName;
|
|
315
|
+
}
|
|
316
|
+
//#endregion
|
|
317
|
+
//#region ../../lib/primitive/src/types/pipeline/class-pipeline-fn.d.ts
|
|
318
|
+
type ClassPipelineFn = (tag: unknown, props: AnyRecord, className?: ClassName, recipe?: string) => string | undefined;
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region ../../lib/primitive/src/types/pipeline/recipe-options.d.ts
|
|
321
|
+
interface RecipeOptions<TVariants extends VariantMap = VariantMap> {
|
|
322
|
+
recipeMap?: StringMap<RecipeTarget<TVariants>>;
|
|
323
|
+
}
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region ../../lib/primitive/src/types/pipeline/tag-map-options.d.ts
|
|
326
|
+
interface TagMapOptions {
|
|
327
|
+
tagMap?: TagMap;
|
|
328
|
+
}
|
|
329
|
+
//#endregion
|
|
330
|
+
//#region ../../lib/primitive/src/types/pipeline/composition-options.d.ts
|
|
331
|
+
type CompositionOptions<TVariants extends VariantMap = VariantMap> = Simplify<TagMapOptions & RecipeOptions<TVariants>>;
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region ../../lib/primitive/src/types/pipeline/cva-system-options.d.ts
|
|
334
|
+
type CVASystemOptions<TVariants extends VariantMap = VariantMap> = Simplify<CVAVariants<TVariants> & CVADefaults<TVariants> & CVACompounds<TVariants>>;
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region ../../lib/primitive/src/types/pipeline/style-options.d.ts
|
|
337
|
+
type StyleOptions<TVariants extends VariantMap = VariantMap> = Simplify<BaseClassOptions & CVASystemOptions<TVariants>>;
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region ../../lib/primitive/src/types/pipeline/class-pipeline-options.d.ts
|
|
340
|
+
type ClassPipelineOptions<TVariants extends VariantMap = VariantMap> = Simplify<StyleOptions<TVariants> & CompositionOptions<TVariants>>;
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region ../../lib/primitive/src/types/class/owned-prop-keys.d.ts
|
|
343
|
+
type OwnedPropKeys = ReadonlySet<string>;
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region ../../lib/primitive/src/types/class/class-plugin.d.ts
|
|
346
|
+
type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
|
|
347
|
+
pipeline: ClassPipelineFn;
|
|
348
|
+
ownedKeys?: OwnedPropKeys;
|
|
349
|
+
readonly _pluginProps?: TProps;
|
|
350
|
+
}>;
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region ../../lib/primitive/src/types/class/class-plugin-factory.d.ts
|
|
353
|
+
type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, diagnostics: Diagnostics) => ClassPlugin<TProps>;
|
|
354
|
+
/** `ClassPluginFactory` with its plugin-owned-props generic erased — the common form used
|
|
355
|
+
* wherever a factory's concrete plugin-props shape isn't tracked (factory generics,
|
|
356
|
+
* capability wiring). */
|
|
357
|
+
type AnyClassPluginFactory = ClassPluginFactory<AnyRecord> | undefined;
|
|
358
|
+
type ExtractPluginProps<TPlugin extends AnyClassPluginFactory> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? NoPluginProps : T : NoPluginProps;
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region ../../lib/primitive/src/types/aria-rule/aria-context.d.ts
|
|
361
|
+
type AriaContext = {
|
|
362
|
+
/**
|
|
363
|
+
* The intrinsic HTML tag being evaluated.
|
|
364
|
+
*/
|
|
365
|
+
readonly tag: IntrinsicTag;
|
|
366
|
+
/**
|
|
367
|
+
* The implicit ARIA role associated with the intrinsic tag.
|
|
368
|
+
*/
|
|
369
|
+
readonly implicitRole: AriaRole | undefined;
|
|
370
|
+
/**
|
|
371
|
+
* The effective ARIA role after considering the element's explicit
|
|
372
|
+
* `role` attribute or component-provided role.
|
|
373
|
+
*/
|
|
374
|
+
readonly effectiveRole: string | undefined;
|
|
375
|
+
/**
|
|
376
|
+
* The component's props available to the ARIA policy engine.
|
|
377
|
+
*/
|
|
378
|
+
readonly props: ReadonlyDeep<IntrinsicProps>;
|
|
379
|
+
/**
|
|
380
|
+
* Variant prop names declared by the component.
|
|
381
|
+
*
|
|
382
|
+
* The adapter uses these names to determine which props are intercepted
|
|
383
|
+
* before reaching the DOM. A rule asserting a fact about a real HTML
|
|
384
|
+
* attribute should therefore treat a key present here as a component
|
|
385
|
+
* variant rather than a DOM attribute.
|
|
386
|
+
*
|
|
387
|
+
* An empty set indicates no variant props are declared — the case for
|
|
388
|
+
* evaluations with no factory context, such as `AriaPolicyEngine.evaluate`.
|
|
389
|
+
*/
|
|
390
|
+
readonly variantKeys: ReadonlySet<string>;
|
|
391
|
+
};
|
|
392
|
+
//#endregion
|
|
393
|
+
//#region ../../lib/primitive/src/types/aria-rule/fix-kind.d.ts
|
|
394
|
+
type RemoveAttributeFixKind = 'removeAttribute';
|
|
395
|
+
type InjectLiveFixKind = 'injectLive';
|
|
396
|
+
type FixKind = 'removeRole' | 'setRole' | 'normalizeRelevantAll' | RemoveAttributeFixKind | InjectLiveFixKind;
|
|
397
|
+
//#endregion
|
|
398
|
+
//#region ../../lib/primitive/src/types/aria-rule/aria-fix.d.ts
|
|
399
|
+
type AriaFixResult = {
|
|
400
|
+
applied: false;
|
|
401
|
+
next: ReadonlyDeep<IntrinsicProps>;
|
|
402
|
+
} | {
|
|
403
|
+
applied: true;
|
|
404
|
+
next: ReadonlyDeep<IntrinsicProps>;
|
|
405
|
+
previous: ReadonlyDeep<IntrinsicProps>;
|
|
406
|
+
};
|
|
407
|
+
type AriaFix = {
|
|
408
|
+
readonly kind: FixKind;
|
|
409
|
+
/** The attribute a `'removeAttribute'`/`'injectLive'` fix targets — always set for those
|
|
410
|
+
* kinds, absent for kinds with no single-attribute target (`'removeRole'`, etc.). */
|
|
411
|
+
readonly attribute?: string;
|
|
412
|
+
readonly priority?: number;
|
|
413
|
+
readonly source?: string;
|
|
414
|
+
readonly apply: (context: AriaContext) => AriaFixResult;
|
|
415
|
+
};
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region ../../lib/primitive/src/types/aria-rule/severity.d.ts
|
|
418
|
+
type Severity = 'error' | 'warning' | (string & {});
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region ../../lib/primitive/src/types/aria-rule/aria-result.d.ts
|
|
421
|
+
type AriaInvalidBase<M extends string = string> = {
|
|
422
|
+
valid: false;
|
|
423
|
+
severity: Severity;
|
|
424
|
+
message?: M;
|
|
425
|
+
attribute?: string;
|
|
426
|
+
diagnostic?: DiagnosticInput;
|
|
427
|
+
};
|
|
428
|
+
type AriaInvalidWithFix<M extends string = string> = AriaInvalidBase<M> & {
|
|
429
|
+
fixable: true;
|
|
430
|
+
fix: AriaFix;
|
|
431
|
+
};
|
|
432
|
+
type AriaInvalidWithoutFix<M extends string = string> = AriaInvalidBase<M> & {
|
|
433
|
+
fixable: false;
|
|
434
|
+
};
|
|
435
|
+
type AriaInvalidResult<M extends string = string> = AriaInvalidWithFix<M> | AriaInvalidWithoutFix<M>;
|
|
436
|
+
type AriaResult = ValidResult | AriaInvalidResult;
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region ../../lib/primitive/src/types/aria-rule/aria-rule.d.ts
|
|
439
|
+
type AriaRule<C extends AriaContext = AriaContext> = ((context: C) => readonly AriaResult[]) & {
|
|
440
|
+
readonly readsProps?: readonly string[];
|
|
441
|
+
readonly tags?: readonly string[];
|
|
442
|
+
};
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region ../../lib/primitive/src/types/factory/prop-normalizer.d.ts
|
|
445
|
+
type PropNormalizer = (props: Readonly<AnyRecord & IntrinsicProps>) => Partial<AnyRecord & IntrinsicProps>;
|
|
446
|
+
//#endregion
|
|
447
|
+
//#region ../../lib/primitive/src/types/factory/enforcement-options.d.ts
|
|
448
|
+
type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
|
|
449
|
+
/**
|
|
450
|
+
* Accepts a preset name (`'warn'`, `'throw'`, `'silent'`) or a full `Diagnostics`
|
|
451
|
+
* instance for custom reporting/policy. The string form needs no import from
|
|
452
|
+
* `@praxis-kit/diagnostics`.
|
|
453
|
+
*/
|
|
454
|
+
readonly diagnostics?: Diagnostics | DiagnosticsMode;
|
|
455
|
+
/**
|
|
456
|
+
* ARIA/accessibility rules evaluated against the resolved tag and props on every render.
|
|
457
|
+
* Each rule is a function receiving the current context and returning zero or more
|
|
458
|
+
* violations, some of which can carry an auto-applicable fix (see `createRemoveAttributeRule`
|
|
459
|
+
* and friends in `praxis-kit/contract`).
|
|
460
|
+
*/
|
|
461
|
+
readonly aria?: readonly AriaRule[];
|
|
462
|
+
/**
|
|
463
|
+
* Rules that need `AriaPolicyEngine`'s fix-application/caching machinery
|
|
464
|
+
* (`AriaRule`'s `readsProps`, fixable `AriaFix` results) but have no
|
|
465
|
+
* relationship to ARIA semantics — an HTML fact or a security check like a
|
|
466
|
+
* dangerous-URL-scheme guard, for example. Evaluated together with `aria`
|
|
467
|
+
* (both run through the same engine, merged into one rule set) — this is a
|
|
468
|
+
* separate bucket purely so a non-ARIA rule doesn't have to sit under the
|
|
469
|
+
* misleading `aria` name to get the machinery it needs.
|
|
470
|
+
*/
|
|
471
|
+
readonly rules?: readonly AriaRule[];
|
|
472
|
+
/**
|
|
473
|
+
* Declares which children are valid, by name, match predicate, and cardinality (e.g. "at
|
|
474
|
+
* least 1, at most 4 `Button` children"). Open by default — children matching no rule are
|
|
475
|
+
* still allowed unless `exclusiveChildren` is set.
|
|
476
|
+
*/
|
|
477
|
+
readonly children?: readonly ChildRuleInput[];
|
|
478
|
+
/**
|
|
479
|
+
* When true, only children matching a `children` rule (or text, per `allowText`)
|
|
480
|
+
* are valid — anything else is rejected. Default: false (open — children not
|
|
481
|
+
* matching any rule are allowed).
|
|
482
|
+
*/
|
|
483
|
+
readonly exclusiveChildren?: boolean;
|
|
484
|
+
/**
|
|
485
|
+
* When false, text/number child nodes are rejected regardless of exclusiveChildren
|
|
486
|
+
* or any listed rule. Default: true.
|
|
487
|
+
*/
|
|
488
|
+
readonly allowText?: boolean;
|
|
489
|
+
/**
|
|
490
|
+
* Prop transforms composed with the component's own `normalize` (from `FactoryOptions`) and
|
|
491
|
+
* run before it. Unlike `normalize`, these live in the enforcement bucket because they
|
|
492
|
+
* typically encode a built-in HTML/ARIA fact rather than component-specific behavior.
|
|
493
|
+
*/
|
|
494
|
+
readonly props?: readonly PropNormalizer[];
|
|
495
|
+
/** Restricts the `as` prop to this set of tags. Violations route through diagnostics. */
|
|
496
|
+
readonly allowedAs?: readonly TAllowed[];
|
|
497
|
+
};
|
|
498
|
+
//#endregion
|
|
499
|
+
//#region ../../lib/primitive/src/types/factory/styling-options.d.ts
|
|
500
|
+
type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory> = {
|
|
501
|
+
/** Class applied to every instance regardless of variant selection. */
|
|
502
|
+
readonly base?: ClassName;
|
|
503
|
+
/**
|
|
504
|
+
* Named variant groups (e.g. `intent`, `size`), each mapping its possible values to a
|
|
505
|
+
* class string. A consumer selects a value per group as a prop (`<Button intent="primary">`).
|
|
506
|
+
*/
|
|
507
|
+
readonly variants?: V;
|
|
508
|
+
/** Value used for a variant group when the consumer doesn't pass one explicitly. */
|
|
509
|
+
readonly defaults?: Partial<DefaultVariants<V>>;
|
|
510
|
+
/**
|
|
511
|
+
* Applies an extra class only when a specific *combination* of variant selections matches —
|
|
512
|
+
* for cases `variants` alone can't express (e.g. `intent: 'primary'` + `size: 'lg'` together
|
|
513
|
+
* need a class neither variant would add on its own).
|
|
514
|
+
*/
|
|
515
|
+
readonly compounds?: readonly CompoundVariant<V>[];
|
|
516
|
+
/**
|
|
517
|
+
* Named bundles of variant values a component defines up front. A caller activates one by name
|
|
518
|
+
* through the `recipe` prop (e.g. `<Button recipe="cta">` instead of setting `intent`/`size`
|
|
519
|
+
* individually) — `presets` is the store, `recipe` is the selector, which is why the field and
|
|
520
|
+
* the prop read differently. Explicit props always win over the activated bundle. The value type
|
|
521
|
+
* is `RecipeMap` (see `lib/primitive/src/types/variants/recipe-map.ts`).
|
|
522
|
+
*/
|
|
523
|
+
readonly presets?: TPreset;
|
|
524
|
+
/** Maps a resolved tag directly to a raw class string, independent of the variant system. */
|
|
525
|
+
readonly tags?: Readonly<TagMap>;
|
|
526
|
+
/**
|
|
527
|
+
* A `ClassPluginFactory` (e.g. the Tailwind layout pipeline) that extends class resolution
|
|
528
|
+
* with its own owned props, layered on top of `variants`/`presets`/`tags`.
|
|
529
|
+
*/
|
|
530
|
+
readonly plugin?: TPlugin;
|
|
531
|
+
/**
|
|
532
|
+
* A cache-key → resolved-class-string lookup for every statically-known variant
|
|
533
|
+
* combination, skipping runtime class computation entirely when a match is found. Normally
|
|
534
|
+
* generated by a build-time class-extraction plugin rather than hand-authored.
|
|
535
|
+
*/
|
|
536
|
+
readonly precomputedClasses?: Readonly<StringMap<string>>;
|
|
537
|
+
};
|
|
538
|
+
//#endregion
|
|
539
|
+
//#region ../../lib/primitive/src/types/factory/factory-options.d.ts
|
|
540
|
+
type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
|
|
541
|
+
normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
|
|
542
|
+
}['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
|
+
/**
|
|
554
|
+
* The framework-neutral component-authoring config passed to `createContractComponent` in every
|
|
555
|
+
* adapter: default tag + name, own-prop defaults, a `normalize` transform, `styling` (variants,
|
|
556
|
+
* base classes, presets, class plugin), `enforcement` (ARIA + children contracts), `subComponents`,
|
|
557
|
+
* and `onElement`.
|
|
558
|
+
*
|
|
559
|
+
* `satisfies FactoryOptions<TDefault, Props, typeof variants, ...>` on a config object narrows
|
|
560
|
+
* `styling.compounds` conditions to the real per-variant-key shape — including resolving a
|
|
561
|
+
* 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.
|
|
563
|
+
*/
|
|
564
|
+
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
|
+
/** The intrinsic tag the component renders by default. Overridable per instance via `as`. */
|
|
566
|
+
readonly tag?: TDefault;
|
|
567
|
+
/** Display name used in diagnostics, dev tools, and generated component naming. */
|
|
568
|
+
readonly name?: string;
|
|
569
|
+
/** Values used for the component's own (non-variant) props when the consumer omits them. */
|
|
570
|
+
readonly defaults?: Partial<NoInfer<Props>>;
|
|
571
|
+
/**
|
|
572
|
+
* A pure `(props) => props` transform run on every render, after `enforcement.props`'s
|
|
573
|
+
* normalizers see the same input. Use this for component-specific prop shaping — anything
|
|
574
|
+
* that depends on live instance state or the real DOM element belongs in `onElement` instead.
|
|
575
|
+
*
|
|
576
|
+
* Accepts either a single transform or an array of them, mirroring the `enforcement.props`
|
|
577
|
+
* array convention. An array is composed left to right — each entry receives the previous
|
|
578
|
+
* entry's *complete* output, not a merged patch — so unlike an `enforcement.props` normalizer
|
|
579
|
+
* (which returns a partial patch), a later `normalize` entry can also remove a key an earlier
|
|
580
|
+
* one added. An empty array is treated as no transform.
|
|
581
|
+
*/
|
|
582
|
+
readonly normalize?: NormalizeFn<NoInfer<Props>> | ReadonlyArray<NormalizeFn<NoInfer<Props>>>;
|
|
583
|
+
/** Variant groups, base classes, presets, and the optional class-resolution plugin. */
|
|
584
|
+
readonly styling?: StylingOptions<V, TPreset, TPlugin>;
|
|
585
|
+
/** ARIA rules, child-content contracts, and other runtime validation for this component. */
|
|
586
|
+
readonly enforcement?: EnforcementOptions<TAllowed>;
|
|
587
|
+
/**
|
|
588
|
+
* Adapter-resolved diagnostics default, spread in by `resolveAdapterCommonOptions`. Not meant to
|
|
589
|
+
* be set directly by component authors — use `enforcement.diagnostics` to override per component.
|
|
590
|
+
*/
|
|
591
|
+
readonly diagnostics?: Diagnostics;
|
|
592
|
+
/**
|
|
593
|
+
* Sub-components to attach to the generated root component, producing a
|
|
594
|
+
* compound component API (for example, `Card.Header`, `Card.Content`,
|
|
595
|
+
* and `Card.Footer`). Purely additive — has no effect on
|
|
596
|
+
* `enforcement.children`; author child rules explicitly if the component
|
|
597
|
+
* needs to validate its children.
|
|
598
|
+
*/
|
|
599
|
+
readonly subComponents?: SubComponentMap;
|
|
600
|
+
/**
|
|
601
|
+
* Called once per instance, when the real underlying DOM element first
|
|
602
|
+
* exists, in every adapter — via that adapter's own native mount
|
|
603
|
+
* lifecycle, never through the props/attribute pipeline. Use this for
|
|
604
|
+
* wiring that needs the actual element (native imperative methods like
|
|
605
|
+
* `dialogEl.showModal()`, native events like `close`/`cancel` that have
|
|
606
|
+
* no prop-based equivalent), not for anything expressible as a plain
|
|
607
|
+
* prop.
|
|
608
|
+
*
|
|
609
|
+
* `element` is typed to the real DOM interface of every tag the rendered
|
|
610
|
+
* element could actually be — `TDefault` plus whatever `enforcement.allowed`
|
|
611
|
+
* permits via `as` (`HTMLDialogElement` for `tag: 'dialog'`,
|
|
612
|
+
* `HTMLDetailsElement` for `tag: 'details'`, and so on) — no cast needed to
|
|
613
|
+
* reach tag-specific members. A component that leaves `allowed`
|
|
614
|
+
* unconstrained (any tag reachable via `as`) falls back to `HTMLElement`,
|
|
615
|
+
* which still covers members every element shares (`showPopover()` and
|
|
616
|
+
* friends); restrict `enforcement.allowed` to the tags `onElement`
|
|
617
|
+
* actually knows how to handle to get real narrowing.
|
|
618
|
+
*
|
|
619
|
+
* `getProps` returns the instance's *current* resolved props at call
|
|
620
|
+
* time — read it from inside a listener registered once at mount, rather
|
|
621
|
+
* than re-subscribing on every prop change.
|
|
622
|
+
*
|
|
623
|
+
* Return a cleanup function to run when the instance unmounts.
|
|
624
|
+
*/
|
|
625
|
+
readonly onElement?: (element: ElementForTag<TDefault | TAllowed>, getProps: () => Readonly<Props>) => void | (() => void);
|
|
626
|
+
};
|
|
627
|
+
//#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;
|
|
630
|
+
//#endregion
|
|
631
|
+
//#region ../../lib/pipeline/src/types/primitives.d.ts
|
|
632
|
+
/** Free-form key/value bag a pass may attach to its result for downstream
|
|
633
|
+
* tooling. Not merged into the pipeline context. */
|
|
634
|
+
type MetadataMap = AnyRecord;
|
|
635
|
+
//#endregion
|
|
636
|
+
//#region ../../lib/pipeline/src/types/diagnostic.d.ts
|
|
637
|
+
/** A single problem reported by a pass. The pipeline engine only carries these
|
|
638
|
+
* through — interpreting, formatting, and failing on them is the caller's job. */
|
|
639
|
+
interface Diagnostic {
|
|
640
|
+
code: string;
|
|
641
|
+
message: string;
|
|
642
|
+
severity: 'error' | 'warning' | 'info';
|
|
643
|
+
}
|
|
644
|
+
//#endregion
|
|
645
|
+
//#region ../../lib/runtime/src/pipeline-compat.d.ts
|
|
646
|
+
/** Opaque identifier for a node in a component/native tree. */
|
|
647
|
+
type NodeId = string;
|
|
648
|
+
/** A component's boolean capability flags, keyed by capability name. */
|
|
649
|
+
type CapabilityMap = StringMap<boolean>;
|
|
650
|
+
//#endregion
|
|
651
|
+
//#region ../../lib/runtime/src/types/component-identity.d.ts
|
|
652
|
+
interface ComponentIdentity {
|
|
653
|
+
id: NodeId;
|
|
654
|
+
name: string;
|
|
655
|
+
tag: string;
|
|
656
|
+
}
|
|
657
|
+
//#endregion
|
|
658
|
+
//#region ../../lib/runtime/src/types/component-definition.d.ts
|
|
659
|
+
interface ComponentDefinition {
|
|
660
|
+
identity: ComponentIdentity;
|
|
661
|
+
capabilities: CapabilityMap;
|
|
662
|
+
metadata: MetadataMap;
|
|
663
|
+
diagnostics: Diagnostic[];
|
|
664
|
+
}
|
|
665
|
+
//#endregion
|
|
666
|
+
//#region ../../adapters/react/src/shared/merge-refs.d.ts
|
|
667
|
+
declare function mergeRefs<T>(...refs: (Ref<T> | null | undefined)[]): Ref<T> | null;
|
|
668
|
+
//#endregion
|
|
669
|
+
//#region ../../adapters/react/src/shared/slot/Slottable.d.ts
|
|
670
|
+
type SlottableProps = PropsWithChildren;
|
|
671
|
+
declare function Slottable({ children }: SlottableProps): ReactElement;
|
|
672
|
+
//#endregion
|
|
673
|
+
//#region ../../adapters/react/src/shared/types/primitives.d.ts
|
|
674
|
+
type UnknownProps = AnyRecord;
|
|
675
|
+
type SlotComponent = ComponentType<UnknownProps>;
|
|
676
|
+
//#endregion
|
|
677
|
+
//#region ../../lib/contract-props/src/mode.d.ts
|
|
678
|
+
/**
|
|
679
|
+
* The three render modes a praxis-kit component's props can be typed for, shared across every
|
|
680
|
+
* adapter that has more than one — not every adapter supports all three (e.g. Preact has no
|
|
681
|
+
* `'render'` mode), but the union itself stays one canonical type here rather than each adapter
|
|
682
|
+
* redeclaring its own (partial, drift-prone) copy.
|
|
683
|
+
*
|
|
684
|
+
* - `'normal'` — the default render mode; `as` selects the host/intrinsic element.
|
|
685
|
+
* - `'asChild'` — slot rendering: props merge onto a child element instead of a host element.
|
|
686
|
+
* - `'render'` — a render callback receives the fully-resolved props and renders anything.
|
|
687
|
+
*
|
|
688
|
+
* Location note: this is the only canonical definition in the repo, and today only the
|
|
689
|
+
* overloaded-callable adapters (React, Preact) consume it — hence its home here alongside
|
|
690
|
+
* `HasGenerics`/`PickMode`. It is really a *render-protocol* concept, though; if `lib/primitive`'s
|
|
691
|
+
* slot protocol or `packages/core` ends up needing it, hoist it there so it is not gated behind
|
|
692
|
+
* this (React/Preact-specific) package. Tracked in `.vscode/MIGRATION.md`.
|
|
693
|
+
*/
|
|
694
|
+
type Mode = 'normal' | 'asChild' | 'render';
|
|
695
|
+
//#endregion
|
|
696
|
+
//#region ../../lib/contract-props/src/has-generics.d.ts
|
|
697
|
+
/**
|
|
698
|
+
* The phantom-marker shape read back via `T extends HasGenerics<infer G> ? G : never`. See the
|
|
699
|
+
* README for why this exists.
|
|
700
|
+
*
|
|
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.
|
|
709
|
+
*
|
|
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.
|
|
713
|
+
*/
|
|
714
|
+
interface HasGenerics<G> {
|
|
715
|
+
readonly __generics?: G;
|
|
716
|
+
}
|
|
717
|
+
//#endregion
|
|
718
|
+
//#region ../../lib/contract-props/src/pick-mode.d.ts
|
|
719
|
+
/**
|
|
720
|
+
* Selects the concrete prop shape for a render mode.
|
|
721
|
+
*
|
|
722
|
+
* The prop shapes themselves remain adapter-specific (see the README for why); this helper only
|
|
723
|
+
* centralizes the `Mode extends ... ? ... : ...` dispatch itself.
|
|
724
|
+
*
|
|
725
|
+
* Adapters that don't support a mode (e.g. Preact has no `'render'`) pass `never` for that slot
|
|
726
|
+
* and narrow their own `Mode` type parameter to exclude it.
|
|
727
|
+
*
|
|
728
|
+
* The dispatch is written **exhaustively** (one `extends` per `Mode` member, `never` fallback)
|
|
729
|
+
* rather than `… : TNormal`, so adding a member to `Mode` makes `PickMode` resolve to `never` for
|
|
730
|
+
* it until someone consciously wires it up — instead of silently aliasing it to `TNormal`.
|
|
731
|
+
*/
|
|
732
|
+
type PickMode<M extends Mode, TNormal, TAsChild, TRender> = M extends 'normal' ? TNormal : M extends 'asChild' ? TAsChild : M extends 'render' ? TRender : never;
|
|
733
|
+
//#endregion
|
|
734
|
+
//#region ../../adapters/react/src/shared/types/props.d.ts
|
|
735
|
+
/**
|
|
736
|
+
* Props passed to the `render` callback — the component's resolved className,
|
|
737
|
+
* filtered own props, and ref. Spread these onto the target element.
|
|
738
|
+
*
|
|
739
|
+
* Typed loosely to accommodate any element tag the user chooses.
|
|
740
|
+
*/
|
|
741
|
+
type RenderCallbackProps = Readonly<AnyRecord>;
|
|
742
|
+
//#endregion
|
|
743
|
+
//#region ../../adapters/react/src/shared/types/polymorphic-props.d.ts
|
|
744
|
+
/**
|
|
745
|
+
* Resolves the instance type exposed through `ref` for a polymorphic
|
|
746
|
+
* element.
|
|
747
|
+
*
|
|
748
|
+
* Intrinsic HTML elements map to their corresponding DOM element type;
|
|
749
|
+
* custom React components currently resolve to `unknown`.
|
|
750
|
+
*/
|
|
751
|
+
type ElementRef<T extends ElementType> = T extends IntrinsicTag ? HTMLElementTagNameMap[T] : unknown;
|
|
752
|
+
/**
|
|
753
|
+
* React's intrinsic JSX props for an element type.
|
|
754
|
+
*
|
|
755
|
+
* Custom components intentionally resolve to `UnknownProps`; their own
|
|
756
|
+
* prop definitions determine the accepted props.
|
|
757
|
+
*/
|
|
758
|
+
type IntrinsicJSXProps<T extends ElementType> = T extends IntrinsicTag ? JSX.IntrinsicElements[T] : UnknownProps;
|
|
759
|
+
/**
|
|
760
|
+
* Removes index signatures while preserving explicitly declared
|
|
761
|
+
* properties.
|
|
762
|
+
*
|
|
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>>;
|
|
770
|
+
/** Variant props generated from the component's variant definitions. */
|
|
771
|
+
type ComponentVariants<G extends PolymorphicGenerics> = StripIndexSignature<VariantProps<VariantsOf<G>>>;
|
|
772
|
+
/**
|
|
773
|
+
* Props defined by the component itself.
|
|
774
|
+
*
|
|
775
|
+
* These override intrinsic JSX props with the same name.
|
|
776
|
+
*/
|
|
777
|
+
type OwnedProps<G extends PolymorphicGenerics> = ComponentProps<G> & ComponentVariants<G>;
|
|
778
|
+
/**
|
|
779
|
+
* Props that control how the component renders.
|
|
780
|
+
*
|
|
781
|
+
* `children` and `asChild` are intentionally omitted so each render
|
|
782
|
+
* strategy can define its own contract.
|
|
783
|
+
*/
|
|
784
|
+
type PolymorphicControlProps<G extends PolymorphicGenerics, TAs extends ElementType> = {
|
|
785
|
+
/**
|
|
786
|
+
* Restrict `as` to `allowedAs` when configured.
|
|
787
|
+
*
|
|
788
|
+
* Without `allowedAs`, `AllowedOf<G>` resolves to `ElementType`,
|
|
789
|
+
* so the intersection becomes `TAs`.
|
|
790
|
+
*/
|
|
791
|
+
as?: TAs & AllowedOf<G>;
|
|
792
|
+
/**
|
|
793
|
+
* Explicit `undefined` keeps wrapper components compatible with
|
|
794
|
+
* `exactOptionalPropertyTypes`.
|
|
795
|
+
*/
|
|
796
|
+
className?: ClassName | undefined;
|
|
797
|
+
recipe?: keyof RecipeOf<G>;
|
|
798
|
+
/** Ref type follows the resolved element. */
|
|
799
|
+
ref?: Ref<ElementRef<TAs>>;
|
|
800
|
+
};
|
|
801
|
+
/**
|
|
802
|
+
* All props reserved by the polymorphic component.
|
|
803
|
+
*
|
|
804
|
+
* Used primarily to exclude conflicting intrinsic JSX props.
|
|
805
|
+
*/
|
|
806
|
+
type ControlProps<G extends PolymorphicGenerics, TAs extends ElementType> = OwnedProps<G> & PolymorphicControlProps<G, TAs>;
|
|
807
|
+
/**
|
|
808
|
+
* Intrinsic JSX props after removing every reserved component prop.
|
|
809
|
+
*
|
|
810
|
+
* Component-defined props always take precedence.
|
|
811
|
+
*/
|
|
812
|
+
type IntrinsicPropsWithoutOwned<G extends PolymorphicGenerics, TAs extends ElementType> = Omit<IntrinsicJSXProps<TAs>, keyof ControlProps<G, TAs> | 'children'>;
|
|
813
|
+
/**
|
|
814
|
+
* Props shared by every rendering strategy.
|
|
815
|
+
*
|
|
816
|
+
* Each render mode contributes only its discriminating props.
|
|
817
|
+
*/
|
|
818
|
+
type BaseProps<G extends PolymorphicGenerics, TAs extends ElementType> = IntrinsicPropsWithoutOwned<G, TAs> & ControlProps<G, TAs>;
|
|
819
|
+
/** Standard rendering (`asChild` absent or false). */
|
|
820
|
+
type NormalRenderMode = {
|
|
821
|
+
asChild?: false;
|
|
822
|
+
children?: ReactNode | undefined;
|
|
823
|
+
};
|
|
824
|
+
/**
|
|
825
|
+
* Slot rendering.
|
|
826
|
+
*
|
|
827
|
+
* Requires one or more React elements and forbids `as`, since the child
|
|
828
|
+
* determines the rendered element.
|
|
829
|
+
*/
|
|
830
|
+
type SlotRenderMode = {
|
|
831
|
+
asChild: true;
|
|
832
|
+
as?: never;
|
|
833
|
+
children: ReactElement | NonEmptyTuple<ReactElement>;
|
|
834
|
+
};
|
|
835
|
+
/**
|
|
836
|
+
* Render callback mode.
|
|
837
|
+
*
|
|
838
|
+
* Receives the fully resolved props and returns the rendered element.
|
|
839
|
+
*/
|
|
840
|
+
type CallbackRenderMode = {
|
|
841
|
+
render: (props: RenderCallbackProps) => ReactElement;
|
|
842
|
+
asChild?: never;
|
|
843
|
+
children?: never;
|
|
844
|
+
};
|
|
845
|
+
/**
|
|
846
|
+
* Standard polymorphic props.
|
|
847
|
+
*
|
|
848
|
+
* HTML attributes are inferred from `as`.
|
|
849
|
+
*/
|
|
850
|
+
type PolymorphicProps<G extends PolymorphicGenerics, TAs extends ElementType = DefaultOf<G>> = Simplify<BaseProps<G, TAs> & NormalRenderMode>;
|
|
851
|
+
/**
|
|
852
|
+
* Slot rendering props.
|
|
853
|
+
*
|
|
854
|
+
* Requires one or more ReactElement children.
|
|
855
|
+
*/
|
|
856
|
+
type PolymorphicWithAsChild<G extends PolymorphicGenerics, TAs extends ElementType = DefaultOf<G>> = Simplify<BaseProps<G, TAs> & SlotRenderMode>;
|
|
857
|
+
/**
|
|
858
|
+
* Render callback props.
|
|
859
|
+
*/
|
|
860
|
+
type PolymorphicWithRender<G extends PolymorphicGenerics, TAs extends ElementType = DefaultOf<G>> = Simplify<BaseProps<G, TAs> & CallbackRenderMode>;
|
|
861
|
+
/**
|
|
862
|
+
* A polymorphic React component.
|
|
863
|
+
*
|
|
864
|
+
* Overloads provide three rendering strategies:
|
|
865
|
+
*
|
|
866
|
+
* - `render` — render callback
|
|
867
|
+
* - `asChild` — slot rendering
|
|
868
|
+
* - default — standard polymorphic rendering
|
|
869
|
+
*/
|
|
870
|
+
type PolymorphicComponent<G extends PolymorphicGenerics> = {
|
|
871
|
+
<TAs extends ElementType = DefaultOf<G>>(props: PolymorphicWithRender<G, TAs>): ReactElement;
|
|
872
|
+
<TAs extends ElementType = DefaultOf<G>>(props: PolymorphicWithAsChild<G, TAs>): ReactElement;
|
|
873
|
+
<TAs extends ElementType = DefaultOf<G>>(props: PolymorphicProps<G, TAs>): ReactElement;
|
|
874
|
+
/**
|
|
875
|
+
* Non-generic fallback overload used for type extraction.
|
|
876
|
+
*
|
|
877
|
+
* TypeScript resolves conditional types such as
|
|
878
|
+
* `React.ComponentProps<typeof Component>` against only the final
|
|
879
|
+
* overload. Anchoring that overload to the default element preserves
|
|
880
|
+
* correct prop inference for tools such as Storybook and
|
|
881
|
+
* `React.ComponentProps`.
|
|
882
|
+
*/
|
|
883
|
+
(props: PolymorphicProps<G, DefaultOf<G>>): ReactElement;
|
|
884
|
+
/**
|
|
885
|
+
* Type-only; never assigned at runtime. See `HasGenerics<G>` (`@praxis-kit/contract-props`) for
|
|
886
|
+
* the full rationale — kept as an inline field rather than `HasGenerics<G> & {...}` because
|
|
887
|
+
* intersecting it onto this callable type changes how `PolymorphicComponent<any>` (used by
|
|
888
|
+
* test helpers like `box()`) resolves against concrete instantiations; structurally identical
|
|
889
|
+
* to `HasGenerics<G>` either way, which is what lets `ContractProps` constrain against it.
|
|
890
|
+
*/
|
|
891
|
+
readonly __generics?: G;
|
|
892
|
+
displayName?: string;
|
|
893
|
+
};
|
|
894
|
+
/**
|
|
895
|
+
* Recovers a built `PolymorphicComponent<G>`'s prop shape for a specific render mode, from
|
|
896
|
+
* outside the file that built it — the missing piece `React.ComponentProps<typeof Component>`
|
|
897
|
+
* can't provide, since it always resolves against `PolymorphicComponent`'s normal-mode fallback
|
|
898
|
+
* overload (see that type's own doc comment).
|
|
899
|
+
*
|
|
900
|
+
* ```tsx
|
|
901
|
+
* const Container = createContractComponent({ tag: 'div', name: 'Container', /* ... *\/ })
|
|
902
|
+
*
|
|
903
|
+
* // Normal-mode props (equivalent to ComponentProps<typeof Container>, but works for every mode):
|
|
904
|
+
* type ContainerProps = ContractProps<typeof Container>
|
|
905
|
+
*
|
|
906
|
+
* // A wrapper that always renders Container with asChild — ComponentProps<typeof Container>
|
|
907
|
+
* // fails here ("Type 'true' is not assignable to type 'false'"); ContractProps doesn't.
|
|
908
|
+
* type ContainerAsChildProps = ContractProps<typeof Container, 'asChild'>
|
|
909
|
+
* ```
|
|
910
|
+
*
|
|
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.
|
|
915
|
+
*
|
|
916
|
+
* Always resolves against the component's *default* element (`PolymorphicWithAsChild<G,
|
|
917
|
+
* DefaultOf<G>>`, etc.) — the same ceiling `React.ComponentProps<typeof Component>` already has
|
|
918
|
+
* for its one mode, not a new limitation `ContractProps` introduces. `ContractProps<typeof
|
|
919
|
+
* Button>` is "`Button`'s contract for its default element," not a substitute for
|
|
920
|
+
* `PolymorphicProps<G, 'a'>` when a caller needs a specific non-default `as` — those remain two
|
|
921
|
+
* different questions with two different answers.
|
|
922
|
+
*/
|
|
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;
|
|
924
|
+
//#endregion
|
|
925
|
+
//#region ../../adapters/react/src/shared/react-options.d.ts
|
|
926
|
+
/** Structural subset of `CompiledComponentArtifact` consumed by the React adapter. */
|
|
927
|
+
interface CompiledArtifact {
|
|
928
|
+
readonly definition: ComponentDefinition;
|
|
929
|
+
readonly precomputed?: {
|
|
930
|
+
readonly variantLookup?: StringMap<string>;
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* Extends FactoryOptions with React-specific configuration.
|
|
935
|
+
* slotComponent is intentionally not in core — it is a React rendering concern.
|
|
936
|
+
*/
|
|
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> & {
|
|
938
|
+
/** Component used to render the asChild slot. Defaults to the built-in Slot. */
|
|
939
|
+
slotComponent?: SlotComponent;
|
|
940
|
+
/**
|
|
941
|
+
* Return true for any prop key that should be consumed but not forwarded to the DOM.
|
|
942
|
+
* The adapter strips nothing by default — implementations decide what is safe to drop.
|
|
943
|
+
* Receives `runtime.options.variantKeys` as a convenience if needed.
|
|
944
|
+
*/
|
|
945
|
+
filterProps?: (key: string, variantKeys: ReadonlySet<string>) => boolean;
|
|
946
|
+
/** Pre-compiled artifact from the praxis-kit compiler. When provided, replaces the stub
|
|
947
|
+
* definition and enables the precomputed variant lookup fast path. */
|
|
948
|
+
artifact?: CompiledArtifact;
|
|
949
|
+
};
|
|
950
|
+
//#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 };
|