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,994 @@
|
|
|
1
|
+
import "clsx";
|
|
2
|
+
import { DiagnosticCode, DiagnosticInput, Diagnostics, DiagnosticsMode } from "../_shared/diagnostics.js";
|
|
3
|
+
import { OmitIndexSignature, ReadonlyDeep, RequireAtLeastOne, Simplify } from "type-fest";
|
|
4
|
+
import { Snippet } from "svelte";
|
|
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/types/contracts/children-evaluator.d.ts
|
|
130
|
+
/** Structural counterpart to the runtime `ChildrenEvaluator` class — `lib/primitive`
|
|
131
|
+
* may not depend on `lib/contract` (the layer boundary `eslint-plugin-boundaries` enforces via
|
|
132
|
+
* `configs/architecture.ts`), so this describes only the shape consumers actually call. Mirrors
|
|
133
|
+
* `AriaEngine`'s pattern. */
|
|
134
|
+
type ChildrenEvaluator$1 = {
|
|
135
|
+
evaluate: (children: unknown[], context?: ChildRuleContext) => void;
|
|
136
|
+
};
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region ../../lib/primitive/src/rule/rule-brand.d.ts
|
|
139
|
+
declare const RULE_BRAND: unique symbol;
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region ../../lib/primitive/src/types/rule/dynamic-rule.d.ts
|
|
142
|
+
type DynamicRule<T, C = unknown> = {
|
|
143
|
+
readonly [RULE_BRAND]: true;
|
|
144
|
+
resolve(context: C): T;
|
|
145
|
+
};
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region ../../lib/primitive/src/types/rule/rule.d.ts
|
|
148
|
+
type Rule<T, C = unknown> = T | DynamicRule<T, C>;
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region ../../lib/primitive/src/types/contracts/child-rule-match.d.ts
|
|
151
|
+
type ChildRuleMatch<T, U extends T = T> = (child: T) => child is U;
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region ../../lib/primitive/src/types/contracts/child-rule-position.d.ts
|
|
154
|
+
type ChildRulePosition = 'first' | 'last' | 'any';
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region ../../lib/primitive/src/types/contracts/child-rule-input.d.ts
|
|
157
|
+
type ChildRuleInput<T = unknown, U extends T = T> = {
|
|
158
|
+
name: string;
|
|
159
|
+
match: ChildRuleMatch<T, U>;
|
|
160
|
+
/**
|
|
161
|
+
* Either a static cardinality, or `dynamic((ctx) => ...)` to derive it from
|
|
162
|
+
* the resolved tag/props (e.g. a different max depending on `as`). `match`
|
|
163
|
+
* stays static-only — it's already a function, so a dynamic wrapper would
|
|
164
|
+
* be indistinguishable from the predicate itself without one.
|
|
165
|
+
*/
|
|
166
|
+
cardinality?: Rule<CardinalityInput, ChildRuleContext>;
|
|
167
|
+
position?: ChildRulePosition;
|
|
168
|
+
/**
|
|
169
|
+
* Optional component-type reference for O(1) dispatch index.
|
|
170
|
+
* When provided for every rule, the matcher reads child.type instead of
|
|
171
|
+
* calling every match function on every child (O(n×m) → O(n+m)).
|
|
172
|
+
*/
|
|
173
|
+
type?: unknown;
|
|
174
|
+
};
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region ../../lib/primitive/src/types/contracts/with-child-rules.d.ts
|
|
177
|
+
/** The **minimal structural bound** for "a component-options object that may
|
|
178
|
+
* carry child rules". Used as the upper bound on generic parameters
|
|
179
|
+
* (`TOptions extends WithChildRules`) and as the wildcard in inference
|
|
180
|
+
* positions (`BuiltRuntime<infer G, WithChildRules>`), so it stays as loose as
|
|
181
|
+
* possible on purpose — everything downstream must be assignable to it.
|
|
182
|
+
*
|
|
183
|
+
* It is **not** the type that decides whether children enforcement is active.
|
|
184
|
+
* That narrowing is done downstream (adapter-utils' `WithChildrenEnforcement`
|
|
185
|
+
* checks for a *non-empty* `children` array); `WithChildRules` only says the
|
|
186
|
+
* slot exists and, now, that its element shape is `ChildRuleInput` rather than
|
|
187
|
+
* `unknown`. */
|
|
188
|
+
type WithChildRules = {
|
|
189
|
+
enforcement?: {
|
|
190
|
+
children?: readonly ChildRuleInput[];
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region ../../lib/primitive/src/types/validation/valid-result.d.ts
|
|
195
|
+
type ValidResult = {
|
|
196
|
+
valid: true;
|
|
197
|
+
};
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region ../../lib/primitive/src/types/variants/string-to-boolean.d.ts
|
|
200
|
+
type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region ../../lib/primitive/src/types/variants/variant-value.d.ts
|
|
203
|
+
type VariantValue = string | string[];
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region ../../lib/primitive/src/types/variants/variant-states.d.ts
|
|
206
|
+
type VariantStates<K extends string = string> = Record<K, VariantValue>;
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region ../../lib/primitive/src/types/variants/variant-map.d.ts
|
|
209
|
+
type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region ../../lib/primitive/src/types/variants/variant-key.d.ts
|
|
212
|
+
type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region ../../lib/primitive/src/types/variants/variant-selection.d.ts
|
|
215
|
+
/**
|
|
216
|
+
* A partial selection of variant states authored at factory definition time.
|
|
217
|
+
*
|
|
218
|
+
* Uses `keyof V[K]` directly (not `VariantKey`) so TypeScript can eagerly
|
|
219
|
+
* resolve the union at constraint-check time without deferred conditional types.
|
|
220
|
+
*/
|
|
221
|
+
type VariantSelection<V extends VariantMap> = { [K in keyof V]?: keyof V[K]; };
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region ../../lib/primitive/src/types/variants/variant-props.d.ts
|
|
224
|
+
/** The full optional prop surface exposed to callers for a given variant map. */
|
|
225
|
+
type VariantProps<V extends VariantMap> = { [K in keyof V]?: VariantKey<V, K>; };
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region ../../lib/primitive/src/types/variants/default-variants.d.ts
|
|
228
|
+
type NormalizedVariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
|
|
229
|
+
type DefaultVariants<V extends VariantMap> = { [K in keyof V]?: NormalizedVariantValue<keyof V[K] & string>; };
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region ../../lib/primitive/src/types/variants/recipe-map.d.ts
|
|
232
|
+
/**
|
|
233
|
+
* A static, immutable map of named presets to partial variant selections.
|
|
234
|
+
*
|
|
235
|
+
* Presets are named bundles of variant props that callers activate by key,
|
|
236
|
+
* avoiding the need to repeat variant combinations at each call site.
|
|
237
|
+
*/
|
|
238
|
+
type RecipeMap<V extends VariantMap = VariantMap> = Readonly<StringMap<VariantSelection<V>>>;
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region ../../lib/primitive/src/types/variants/recipe-target.d.ts
|
|
241
|
+
type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region ../../lib/primitive/src/types/variants/polymorphic-generics.d.ts
|
|
244
|
+
/**
|
|
245
|
+
* The framework-neutral descriptor for a single praxis-kit component's contract — every render
|
|
246
|
+
* mechanism (tag resolution, prop merging, classes, ARIA) and every framework adapter's
|
|
247
|
+
* component type is built from this one shape. Deliberately just data: five type parameters and
|
|
248
|
+
* their corresponding properties, with no notion of JSX, call signatures, refs, or any
|
|
249
|
+
* framework-specific rendering concern. Each adapter (React, Vue, Svelte, Solid, Lit, Web) builds
|
|
250
|
+
* its own idiomatic component type on top of a `PolymorphicGenerics<...>` instantiation — see
|
|
251
|
+
* `PolymorphicComponent<G>` (`adapters/react/src/shared/types/polymorphic-props.ts`) for the
|
|
252
|
+
* React example — rather than this interface knowing anything about any of them.
|
|
253
|
+
*
|
|
254
|
+
* Use the `*Of<T>` accessor aliases below (`DefaultOf<G>`, `PropsOf<G>`, etc.) to read a single
|
|
255
|
+
* field back out of an already-resolved `G`, instead of indexing `G['default']` etc. directly at
|
|
256
|
+
* call sites — same rationale as any accessor: the property name stays an implementation detail,
|
|
257
|
+
* and every reader benefits together if it ever needs to change.
|
|
258
|
+
*/
|
|
259
|
+
interface PolymorphicGenerics<
|
|
260
|
+
/**
|
|
261
|
+
* The element/tag this component renders as when the consumer doesn't override it via `as`
|
|
262
|
+
* (`AllowedOf<G>` permitting) — e.g. `'button'`, `'div'`. Defaults to the widest `ElementType`
|
|
263
|
+
* so a generic `PolymorphicGenerics` reference (with nothing else specified) still compiles.
|
|
264
|
+
*/
|
|
265
|
+
TDefault extends ElementType = ElementType,
|
|
266
|
+
/**
|
|
267
|
+
* The props this specific component declares — its own contract, before variants are mixed
|
|
268
|
+
* in. Defaults to `AnyRecord` for the same "still compiles unspecified" reason as `TDefault`.
|
|
269
|
+
*/
|
|
270
|
+
Props extends AnyRecord = AnyRecord,
|
|
271
|
+
/**
|
|
272
|
+
* This component's variant definitions (e.g. `{ intent: { primary: ..., ghost: ... } }`).
|
|
273
|
+
* Constrained to `Readonly<VariantMap>` — not the wider `AnyRecord` — specifically so `TPreset`
|
|
274
|
+
* below can be expressed as `RecipeMap<Variants>` and get real per-variant-key checking,
|
|
275
|
+
* instead of falling back to an unconstrained `RecipeMap<VariantMap>`.
|
|
276
|
+
*/
|
|
277
|
+
Variants extends Readonly<VariantMap> = Readonly<VariantMap>,
|
|
278
|
+
/**
|
|
279
|
+
* Named presets (`RecipeMap<Variants>`) — bundles of variant selections a consumer activates
|
|
280
|
+
* by key instead of repeating the same variant combination at every call site. Tied to
|
|
281
|
+
* `Variants`, not `AnyRecord`, precisely so a preset can only ever select keys/values that
|
|
282
|
+
* `Variants` actually defines — an invalid preset is a type error, not a silent no-op.
|
|
283
|
+
* Defaults to `Readonly<EmptyRecord>` (no presets), which is the common case: a component can
|
|
284
|
+
* have variants without necessarily defining any named presets over them, and most don't.
|
|
285
|
+
*/
|
|
286
|
+
TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>,
|
|
287
|
+
/**
|
|
288
|
+
* The set of elements/tags a consumer is allowed to switch to via `as`. Defaults to the widest
|
|
289
|
+
* `ElementType`, under which `AllowedOf<G>` imposes no restriction at all (see
|
|
290
|
+
* `PolymorphicControlProps.as`'s own comment in the React adapter for the concrete effect this
|
|
291
|
+
* has at a component's actual call site).
|
|
292
|
+
*/
|
|
293
|
+
TAllowed extends ElementType = ElementType> {
|
|
294
|
+
default: TDefault;
|
|
295
|
+
props: Props;
|
|
296
|
+
variants: Variants;
|
|
297
|
+
preset: TPreset;
|
|
298
|
+
allowed: TAllowed;
|
|
299
|
+
}
|
|
300
|
+
/** This component's variant definitions. See `PolymorphicGenerics`'s `Variants` parameter. */
|
|
301
|
+
type VariantsOf<T extends PolymorphicGenerics> = T['variants'];
|
|
302
|
+
/** This component's named presets. See `PolymorphicGenerics`'s `TPreset` parameter. */
|
|
303
|
+
type RecipeOf<T extends PolymorphicGenerics> = T['preset'];
|
|
304
|
+
/** The set of elements/tags this component may render as via `as`. See `PolymorphicGenerics`'s
|
|
305
|
+
* `TAllowed` parameter. */
|
|
306
|
+
type AllowedOf<T extends PolymorphicGenerics> = T['allowed'];
|
|
307
|
+
/** The element/tag this component renders as by default. See `PolymorphicGenerics`'s `TDefault`
|
|
308
|
+
* parameter. */
|
|
309
|
+
type DefaultOf<T extends PolymorphicGenerics> = T['default'];
|
|
310
|
+
/** This component's own declared props, before variants are mixed in. See `PolymorphicGenerics`'s
|
|
311
|
+
* `Props` parameter. */
|
|
312
|
+
type PropsOf<T extends PolymorphicGenerics> = T['props'];
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region ../../lib/primitive/src/types/variants/compound/compound-variant.d.ts
|
|
315
|
+
type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
|
|
316
|
+
type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
|
|
317
|
+
type CompoundVariantConditions<V extends VariantMap> = Simplify<{ [K in keyof V]: CompoundVariantConditionValue<V, K>; }>;
|
|
318
|
+
type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
|
|
319
|
+
type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
|
|
320
|
+
type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
|
|
321
|
+
class: VariantValue;
|
|
322
|
+
};
|
|
323
|
+
//#endregion
|
|
324
|
+
//#region ../../lib/primitive/src/types/variants/compound/cva-compounds.d.ts
|
|
325
|
+
interface CVACompounds<V extends VariantMap> {
|
|
326
|
+
compoundVariants?: readonly CompoundVariant<V>[];
|
|
327
|
+
}
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region ../../lib/primitive/src/types/variants/compound/cva-defaults.d.ts
|
|
330
|
+
interface CVADefaults<V extends VariantMap> {
|
|
331
|
+
defaultVariants?: DefaultVariants<V>;
|
|
332
|
+
}
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region ../../lib/primitive/src/types/variants/compound/cva-variants.d.ts
|
|
335
|
+
interface CVAVariants<V extends VariantMap> {
|
|
336
|
+
variants?: V;
|
|
337
|
+
}
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region ../../lib/primitive/src/types/pipeline/base-class-options.d.ts
|
|
340
|
+
interface BaseClassOptions {
|
|
341
|
+
baseClassName?: ClassName;
|
|
342
|
+
}
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region ../../lib/primitive/src/types/pipeline/class-pipeline-fn.d.ts
|
|
345
|
+
type ClassPipelineFn = (tag: unknown, props: AnyRecord, className?: ClassName, recipe?: string) => string | undefined;
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region ../../lib/primitive/src/types/pipeline/recipe-options.d.ts
|
|
348
|
+
interface RecipeOptions<TVariants extends VariantMap = VariantMap> {
|
|
349
|
+
recipeMap?: StringMap<RecipeTarget<TVariants>>;
|
|
350
|
+
}
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region ../../lib/primitive/src/types/pipeline/tag-map-options.d.ts
|
|
353
|
+
interface TagMapOptions {
|
|
354
|
+
tagMap?: TagMap;
|
|
355
|
+
}
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region ../../lib/primitive/src/types/pipeline/composition-options.d.ts
|
|
358
|
+
type CompositionOptions<TVariants extends VariantMap = VariantMap> = Simplify<TagMapOptions & RecipeOptions<TVariants>>;
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region ../../lib/primitive/src/types/pipeline/cva-system-options.d.ts
|
|
361
|
+
type CVASystemOptions<TVariants extends VariantMap = VariantMap> = Simplify<CVAVariants<TVariants> & CVADefaults<TVariants> & CVACompounds<TVariants>>;
|
|
362
|
+
//#endregion
|
|
363
|
+
//#region ../../lib/primitive/src/types/pipeline/style-options.d.ts
|
|
364
|
+
type StyleOptions<TVariants extends VariantMap = VariantMap> = Simplify<BaseClassOptions & CVASystemOptions<TVariants>>;
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region ../../lib/primitive/src/types/pipeline/class-pipeline-options.d.ts
|
|
367
|
+
type ClassPipelineOptions<TVariants extends VariantMap = VariantMap> = Simplify<StyleOptions<TVariants> & CompositionOptions<TVariants>>;
|
|
368
|
+
//#endregion
|
|
369
|
+
//#region ../../lib/primitive/src/types/class/owned-prop-keys.d.ts
|
|
370
|
+
type OwnedPropKeys = ReadonlySet<string>;
|
|
371
|
+
//#endregion
|
|
372
|
+
//#region ../../lib/primitive/src/types/class/class-plugin.d.ts
|
|
373
|
+
type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
|
|
374
|
+
pipeline: ClassPipelineFn;
|
|
375
|
+
ownedKeys?: OwnedPropKeys;
|
|
376
|
+
readonly _pluginProps?: TProps;
|
|
377
|
+
}>;
|
|
378
|
+
//#endregion
|
|
379
|
+
//#region ../../lib/primitive/src/types/class/class-plugin-factory.d.ts
|
|
380
|
+
type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, diagnostics: Diagnostics) => ClassPlugin<TProps>;
|
|
381
|
+
/** `ClassPluginFactory` with its plugin-owned-props generic erased — the common form used
|
|
382
|
+
* wherever a factory's concrete plugin-props shape isn't tracked (factory generics,
|
|
383
|
+
* capability wiring). */
|
|
384
|
+
type AnyClassPluginFactory = ClassPluginFactory<AnyRecord> | undefined;
|
|
385
|
+
type ExtractPluginProps<TPlugin extends AnyClassPluginFactory> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? NoPluginProps : T : NoPluginProps;
|
|
386
|
+
type PluginInstance<TPlugin extends AnyClassPluginFactory> = TPlugin extends ClassPluginFactory<infer TProps> ? ClassPlugin<TProps> : undefined;
|
|
387
|
+
//#endregion
|
|
388
|
+
//#region ../../lib/primitive/src/types/aria-rule/aria-context.d.ts
|
|
389
|
+
type AriaContext = {
|
|
390
|
+
/**
|
|
391
|
+
* The intrinsic HTML tag being evaluated.
|
|
392
|
+
*/
|
|
393
|
+
readonly tag: IntrinsicTag;
|
|
394
|
+
/**
|
|
395
|
+
* The implicit ARIA role associated with the intrinsic tag.
|
|
396
|
+
*/
|
|
397
|
+
readonly implicitRole: AriaRole | undefined;
|
|
398
|
+
/**
|
|
399
|
+
* The effective ARIA role after considering the element's explicit
|
|
400
|
+
* `role` attribute or component-provided role.
|
|
401
|
+
*/
|
|
402
|
+
readonly effectiveRole: string | undefined;
|
|
403
|
+
/**
|
|
404
|
+
* The component's props available to the ARIA policy engine.
|
|
405
|
+
*/
|
|
406
|
+
readonly props: ReadonlyDeep<IntrinsicProps>;
|
|
407
|
+
/**
|
|
408
|
+
* Variant prop names declared by the component.
|
|
409
|
+
*
|
|
410
|
+
* The adapter uses these names to determine which props are intercepted
|
|
411
|
+
* before reaching the DOM. A rule asserting a fact about a real HTML
|
|
412
|
+
* attribute should therefore treat a key present here as a component
|
|
413
|
+
* variant rather than a DOM attribute.
|
|
414
|
+
*
|
|
415
|
+
* An empty set indicates no variant props are declared — the case for
|
|
416
|
+
* evaluations with no factory context, such as `AriaPolicyEngine.evaluate`.
|
|
417
|
+
*/
|
|
418
|
+
readonly variantKeys: ReadonlySet<string>;
|
|
419
|
+
};
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region ../../lib/primitive/src/types/aria-rule/fix-kind.d.ts
|
|
422
|
+
type RemoveAttributeFixKind = 'removeAttribute';
|
|
423
|
+
type InjectLiveFixKind = 'injectLive';
|
|
424
|
+
type FixKind = 'removeRole' | 'setRole' | 'normalizeRelevantAll' | RemoveAttributeFixKind | InjectLiveFixKind;
|
|
425
|
+
//#endregion
|
|
426
|
+
//#region ../../lib/primitive/src/types/aria-rule/aria-fix.d.ts
|
|
427
|
+
type AriaFixResult = {
|
|
428
|
+
applied: false;
|
|
429
|
+
next: ReadonlyDeep<IntrinsicProps>;
|
|
430
|
+
} | {
|
|
431
|
+
applied: true;
|
|
432
|
+
next: ReadonlyDeep<IntrinsicProps>;
|
|
433
|
+
previous: ReadonlyDeep<IntrinsicProps>;
|
|
434
|
+
};
|
|
435
|
+
type AriaFix = {
|
|
436
|
+
readonly kind: FixKind;
|
|
437
|
+
/** The attribute a `'removeAttribute'`/`'injectLive'` fix targets — always set for those
|
|
438
|
+
* kinds, absent for kinds with no single-attribute target (`'removeRole'`, etc.). */
|
|
439
|
+
readonly attribute?: string;
|
|
440
|
+
readonly priority?: number;
|
|
441
|
+
readonly source?: string;
|
|
442
|
+
readonly apply: (context: AriaContext) => AriaFixResult;
|
|
443
|
+
};
|
|
444
|
+
//#endregion
|
|
445
|
+
//#region ../../lib/primitive/src/types/aria-rule/severity.d.ts
|
|
446
|
+
type Severity = 'error' | 'warning' | (string & {});
|
|
447
|
+
//#endregion
|
|
448
|
+
//#region ../../lib/primitive/src/types/aria-rule/aria-result.d.ts
|
|
449
|
+
type AriaInvalidBase<M extends string = string> = {
|
|
450
|
+
valid: false;
|
|
451
|
+
severity: Severity;
|
|
452
|
+
message?: M;
|
|
453
|
+
attribute?: string;
|
|
454
|
+
diagnostic?: DiagnosticInput;
|
|
455
|
+
};
|
|
456
|
+
type AriaInvalidWithFix<M extends string = string> = AriaInvalidBase<M> & {
|
|
457
|
+
fixable: true;
|
|
458
|
+
fix: AriaFix;
|
|
459
|
+
};
|
|
460
|
+
type AriaInvalidWithoutFix<M extends string = string> = AriaInvalidBase<M> & {
|
|
461
|
+
fixable: false;
|
|
462
|
+
};
|
|
463
|
+
type AriaInvalidResult<M extends string = string> = AriaInvalidWithFix<M> | AriaInvalidWithoutFix<M>;
|
|
464
|
+
type AriaResult = ValidResult | AriaInvalidResult;
|
|
465
|
+
//#endregion
|
|
466
|
+
//#region ../../lib/primitive/src/types/aria-rule/aria-rule.d.ts
|
|
467
|
+
type AriaRule<C extends AriaContext = AriaContext> = ((context: C) => readonly AriaResult[]) & {
|
|
468
|
+
readonly readsProps?: readonly string[];
|
|
469
|
+
readonly tags?: readonly string[];
|
|
470
|
+
};
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region ../../lib/primitive/src/types/factory/prop-normalizer.d.ts
|
|
473
|
+
type PropNormalizer = (props: Readonly<AnyRecord & IntrinsicProps>) => Partial<AnyRecord & IntrinsicProps>;
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region ../../lib/primitive/src/types/factory/enforcement-options.d.ts
|
|
476
|
+
type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
|
|
477
|
+
/**
|
|
478
|
+
* Accepts a preset name (`'warn'`, `'throw'`, `'silent'`) or a full `Diagnostics`
|
|
479
|
+
* instance for custom reporting/policy. The string form needs no import from
|
|
480
|
+
* `@praxis-kit/diagnostics`.
|
|
481
|
+
*/
|
|
482
|
+
readonly diagnostics?: Diagnostics | DiagnosticsMode;
|
|
483
|
+
/**
|
|
484
|
+
* ARIA/accessibility rules evaluated against the resolved tag and props on every render.
|
|
485
|
+
* Each rule is a function receiving the current context and returning zero or more
|
|
486
|
+
* violations, some of which can carry an auto-applicable fix (see `createRemoveAttributeRule`
|
|
487
|
+
* and friends in `praxis-kit/contract`).
|
|
488
|
+
*/
|
|
489
|
+
readonly aria?: readonly AriaRule[];
|
|
490
|
+
/**
|
|
491
|
+
* Rules that need `AriaPolicyEngine`'s fix-application/caching machinery
|
|
492
|
+
* (`AriaRule`'s `readsProps`, fixable `AriaFix` results) but have no
|
|
493
|
+
* relationship to ARIA semantics — an HTML fact or a security check like a
|
|
494
|
+
* dangerous-URL-scheme guard, for example. Evaluated together with `aria`
|
|
495
|
+
* (both run through the same engine, merged into one rule set) — this is a
|
|
496
|
+
* separate bucket purely so a non-ARIA rule doesn't have to sit under the
|
|
497
|
+
* misleading `aria` name to get the machinery it needs.
|
|
498
|
+
*/
|
|
499
|
+
readonly rules?: readonly AriaRule[];
|
|
500
|
+
/**
|
|
501
|
+
* Declares which children are valid, by name, match predicate, and cardinality (e.g. "at
|
|
502
|
+
* least 1, at most 4 `Button` children"). Open by default — children matching no rule are
|
|
503
|
+
* still allowed unless `exclusiveChildren` is set.
|
|
504
|
+
*/
|
|
505
|
+
readonly children?: readonly ChildRuleInput[];
|
|
506
|
+
/**
|
|
507
|
+
* When true, only children matching a `children` rule (or text, per `allowText`)
|
|
508
|
+
* are valid — anything else is rejected. Default: false (open — children not
|
|
509
|
+
* matching any rule are allowed).
|
|
510
|
+
*/
|
|
511
|
+
readonly exclusiveChildren?: boolean;
|
|
512
|
+
/**
|
|
513
|
+
* When false, text/number child nodes are rejected regardless of exclusiveChildren
|
|
514
|
+
* or any listed rule. Default: true.
|
|
515
|
+
*/
|
|
516
|
+
readonly allowText?: boolean;
|
|
517
|
+
/**
|
|
518
|
+
* Prop transforms composed with the component's own `normalize` (from `FactoryOptions`) and
|
|
519
|
+
* run before it. Unlike `normalize`, these live in the enforcement bucket because they
|
|
520
|
+
* typically encode a built-in HTML/ARIA fact rather than component-specific behavior.
|
|
521
|
+
*/
|
|
522
|
+
readonly props?: readonly PropNormalizer[];
|
|
523
|
+
/** Restricts the `as` prop to this set of tags. Violations route through diagnostics. */
|
|
524
|
+
readonly allowedAs?: readonly TAllowed[];
|
|
525
|
+
};
|
|
526
|
+
//#endregion
|
|
527
|
+
//#region ../../lib/primitive/src/types/factory/styling-options.d.ts
|
|
528
|
+
type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory> = {
|
|
529
|
+
/** Class applied to every instance regardless of variant selection. */
|
|
530
|
+
readonly base?: ClassName;
|
|
531
|
+
/**
|
|
532
|
+
* Named variant groups (e.g. `intent`, `size`), each mapping its possible values to a
|
|
533
|
+
* class string. A consumer selects a value per group as a prop (`<Button intent="primary">`).
|
|
534
|
+
*/
|
|
535
|
+
readonly variants?: V;
|
|
536
|
+
/** Value used for a variant group when the consumer doesn't pass one explicitly. */
|
|
537
|
+
readonly defaults?: Partial<DefaultVariants<V>>;
|
|
538
|
+
/**
|
|
539
|
+
* Applies an extra class only when a specific *combination* of variant selections matches —
|
|
540
|
+
* for cases `variants` alone can't express (e.g. `intent: 'primary'` + `size: 'lg'` together
|
|
541
|
+
* need a class neither variant would add on its own).
|
|
542
|
+
*/
|
|
543
|
+
readonly compounds?: readonly CompoundVariant<V>[];
|
|
544
|
+
/**
|
|
545
|
+
* Named bundles of variant values a component defines up front. A caller activates one by name
|
|
546
|
+
* through the `recipe` prop (e.g. `<Button recipe="cta">` instead of setting `intent`/`size`
|
|
547
|
+
* individually) — `presets` is the store, `recipe` is the selector, which is why the field and
|
|
548
|
+
* the prop read differently. Explicit props always win over the activated bundle. The value type
|
|
549
|
+
* is `RecipeMap` (see `lib/primitive/src/types/variants/recipe-map.ts`).
|
|
550
|
+
*/
|
|
551
|
+
readonly presets?: TPreset;
|
|
552
|
+
/** Maps a resolved tag directly to a raw class string, independent of the variant system. */
|
|
553
|
+
readonly tags?: Readonly<TagMap>;
|
|
554
|
+
/**
|
|
555
|
+
* A `ClassPluginFactory` (e.g. the Tailwind layout pipeline) that extends class resolution
|
|
556
|
+
* with its own owned props, layered on top of `variants`/`presets`/`tags`.
|
|
557
|
+
*/
|
|
558
|
+
readonly plugin?: TPlugin;
|
|
559
|
+
/**
|
|
560
|
+
* A cache-key → resolved-class-string lookup for every statically-known variant
|
|
561
|
+
* combination, skipping runtime class computation entirely when a match is found. Normally
|
|
562
|
+
* generated by a build-time class-extraction plugin rather than hand-authored.
|
|
563
|
+
*/
|
|
564
|
+
readonly precomputedClasses?: Readonly<StringMap<string>>;
|
|
565
|
+
};
|
|
566
|
+
//#endregion
|
|
567
|
+
//#region ../../lib/primitive/src/types/factory/factory-options.d.ts
|
|
568
|
+
type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
|
|
569
|
+
normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
|
|
570
|
+
}['normalize'];
|
|
571
|
+
/**
|
|
572
|
+
* The type-erased shape of {@link FactoryOptions} — every generic parameter widened to its bound.
|
|
573
|
+
*
|
|
574
|
+
* Use it for a value that must hold *any* factory config (a registry, a generic wrapper). It
|
|
575
|
+
* cannot check `styling.compounds` conditions against the real variant keys/values, because it
|
|
576
|
+
* has forgotten what they are — for that, annotate against `FactoryOptions<...>` with the concrete
|
|
577
|
+
* generics (or `satisfies FactoryOptions<'button', Props, typeof variants>`), which keeps an
|
|
578
|
+
* invalid compound condition a type error rather than a silent no-op.
|
|
579
|
+
*/
|
|
580
|
+
type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, AnyClassPluginFactory>;
|
|
581
|
+
/**
|
|
582
|
+
* The framework-neutral component-authoring config passed to `createContractComponent` in every
|
|
583
|
+
* adapter: default tag + name, own-prop defaults, a `normalize` transform, `styling` (variants,
|
|
584
|
+
* base classes, presets, class plugin), `enforcement` (ARIA + children contracts), `subComponents`,
|
|
585
|
+
* and `onElement`.
|
|
586
|
+
*
|
|
587
|
+
* `satisfies FactoryOptions<TDefault, Props, typeof variants, ...>` on a config object narrows
|
|
588
|
+
* `styling.compounds` conditions to the real per-variant-key shape — including resolving a
|
|
589
|
+
* boolean-shaped axis (`{ true, false }`) to a real `boolean` — so a condition naming a variant or
|
|
590
|
+
* value that does not exist is a compile error. `AnyFactoryOptions` cannot do this.
|
|
591
|
+
*/
|
|
592
|
+
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> = {
|
|
593
|
+
/** The intrinsic tag the component renders by default. Overridable per instance via `as`. */
|
|
594
|
+
readonly tag?: TDefault;
|
|
595
|
+
/** Display name used in diagnostics, dev tools, and generated component naming. */
|
|
596
|
+
readonly name?: string;
|
|
597
|
+
/** Values used for the component's own (non-variant) props when the consumer omits them. */
|
|
598
|
+
readonly defaults?: Partial<NoInfer<Props>>;
|
|
599
|
+
/**
|
|
600
|
+
* A pure `(props) => props` transform run on every render, after `enforcement.props`'s
|
|
601
|
+
* normalizers see the same input. Use this for component-specific prop shaping — anything
|
|
602
|
+
* that depends on live instance state or the real DOM element belongs in `onElement` instead.
|
|
603
|
+
*
|
|
604
|
+
* Accepts either a single transform or an array of them, mirroring the `enforcement.props`
|
|
605
|
+
* array convention. An array is composed left to right — each entry receives the previous
|
|
606
|
+
* entry's *complete* output, not a merged patch — so unlike an `enforcement.props` normalizer
|
|
607
|
+
* (which returns a partial patch), a later `normalize` entry can also remove a key an earlier
|
|
608
|
+
* one added. An empty array is treated as no transform.
|
|
609
|
+
*/
|
|
610
|
+
readonly normalize?: NormalizeFn<NoInfer<Props>> | ReadonlyArray<NormalizeFn<NoInfer<Props>>>;
|
|
611
|
+
/** Variant groups, base classes, presets, and the optional class-resolution plugin. */
|
|
612
|
+
readonly styling?: StylingOptions<V, TPreset, TPlugin>;
|
|
613
|
+
/** ARIA rules, child-content contracts, and other runtime validation for this component. */
|
|
614
|
+
readonly enforcement?: EnforcementOptions<TAllowed>;
|
|
615
|
+
/**
|
|
616
|
+
* Adapter-resolved diagnostics default, spread in by `resolveAdapterCommonOptions`. Not meant to
|
|
617
|
+
* be set directly by component authors — use `enforcement.diagnostics` to override per component.
|
|
618
|
+
*/
|
|
619
|
+
readonly diagnostics?: Diagnostics;
|
|
620
|
+
/**
|
|
621
|
+
* Sub-components to attach to the generated root component, producing a
|
|
622
|
+
* compound component API (for example, `Card.Header`, `Card.Content`,
|
|
623
|
+
* and `Card.Footer`). Purely additive — has no effect on
|
|
624
|
+
* `enforcement.children`; author child rules explicitly if the component
|
|
625
|
+
* needs to validate its children.
|
|
626
|
+
*/
|
|
627
|
+
readonly subComponents?: SubComponentMap;
|
|
628
|
+
/**
|
|
629
|
+
* Called once per instance, when the real underlying DOM element first
|
|
630
|
+
* exists, in every adapter — via that adapter's own native mount
|
|
631
|
+
* lifecycle, never through the props/attribute pipeline. Use this for
|
|
632
|
+
* wiring that needs the actual element (native imperative methods like
|
|
633
|
+
* `dialogEl.showModal()`, native events like `close`/`cancel` that have
|
|
634
|
+
* no prop-based equivalent), not for anything expressible as a plain
|
|
635
|
+
* prop.
|
|
636
|
+
*
|
|
637
|
+
* `element` is typed to the real DOM interface of every tag the rendered
|
|
638
|
+
* element could actually be — `TDefault` plus whatever `enforcement.allowed`
|
|
639
|
+
* permits via `as` (`HTMLDialogElement` for `tag: 'dialog'`,
|
|
640
|
+
* `HTMLDetailsElement` for `tag: 'details'`, and so on) — no cast needed to
|
|
641
|
+
* reach tag-specific members. A component that leaves `allowed`
|
|
642
|
+
* unconstrained (any tag reachable via `as`) falls back to `HTMLElement`,
|
|
643
|
+
* which still covers members every element shares (`showPopover()` and
|
|
644
|
+
* friends); restrict `enforcement.allowed` to the tags `onElement`
|
|
645
|
+
* actually knows how to handle to get real narrowing.
|
|
646
|
+
*
|
|
647
|
+
* `getProps` returns the instance's *current* resolved props at call
|
|
648
|
+
* time — read it from inside a listener registered once at mount, rather
|
|
649
|
+
* than re-subscribing on every prop change.
|
|
650
|
+
*
|
|
651
|
+
* Return a cleanup function to run when the instance unmounts.
|
|
652
|
+
*/
|
|
653
|
+
readonly onElement?: (element: ElementForTag<TDefault | TAllowed>, getProps: () => Readonly<Props>) => void | (() => void);
|
|
654
|
+
};
|
|
655
|
+
//#endregion
|
|
656
|
+
//#region ../../lib/primitive/src/types/factory/resolved-factory-options.d.ts
|
|
657
|
+
/**
|
|
658
|
+
* The fully-resolved component definition — rendering, styling, variants, and
|
|
659
|
+
* enforcement (child rules, ARIA rules, `allowedAs`) settled into one object.
|
|
660
|
+
*
|
|
661
|
+
* ⚠️ Complexity boundary: this type is close to "the entire resolved component
|
|
662
|
+
* state". Adding a whole new concern (events, refs, lifecycle, slots, context,
|
|
663
|
+
* SSR/hydration) should **not** just append fields here — split it into a
|
|
664
|
+
* composition first: `ResolvedRenderingOptions & ResolvedStylingOptions &
|
|
665
|
+
* ResolvedEnforcementOptions & …`.
|
|
666
|
+
*/
|
|
667
|
+
type ResolvedFactoryOptions<TDefault extends ElementType = ElementType, Props extends AnyRecord = EmptyRecord, V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>> = {
|
|
668
|
+
readonly defaultTag: TDefault;
|
|
669
|
+
readonly baseClassName?: ClassName;
|
|
670
|
+
readonly defaultProps?: Partial<Props>;
|
|
671
|
+
readonly tagMap?: Readonly<TagMap>;
|
|
672
|
+
readonly recipeMap?: TPreset;
|
|
673
|
+
readonly variants?: V;
|
|
674
|
+
readonly defaultVariants?: Partial<DefaultVariants<V>>;
|
|
675
|
+
readonly compoundVariants?: readonly CompoundVariant<V>[];
|
|
676
|
+
readonly displayName?: string;
|
|
677
|
+
readonly diagnostics: Diagnostics;
|
|
678
|
+
readonly variantKeys: ReadonlySet<string>;
|
|
679
|
+
readonly normalizeFn?: NormalizeFn<Props>;
|
|
680
|
+
readonly htmlPropNormalizersFn?: (tag: unknown) => readonly PropNormalizer[] | undefined;
|
|
681
|
+
readonly htmlChildrenEvaluatorFn?: (tag: unknown) => ChildrenEvaluator$1 | undefined;
|
|
682
|
+
readonly childRules?: readonly ChildRuleInput[];
|
|
683
|
+
readonly exclusiveChildren?: boolean;
|
|
684
|
+
readonly allowText?: boolean;
|
|
685
|
+
readonly ariaRules?: readonly AriaRule[];
|
|
686
|
+
readonly allowedAs?: readonly ElementType[];
|
|
687
|
+
readonly precomputedClasses?: Readonly<StringMap<string>>;
|
|
688
|
+
};
|
|
689
|
+
//#endregion
|
|
690
|
+
//#region ../../lib/primitive/src/types/polymorphic-runtime/resolve-aria-fn.d.ts
|
|
691
|
+
type ResolveAriaFn = <P extends IntrinsicProps>(tag: ElementType, props: P, extraProps?: IntrinsicProps) => {
|
|
692
|
+
props: P;
|
|
693
|
+
};
|
|
694
|
+
//#endregion
|
|
695
|
+
//#region ../../lib/primitive/src/types/polymorphic-runtime/resolve-class-name-fn.d.ts
|
|
696
|
+
type ResolveClassNameFn<Props extends AnyRecord, TSlot extends string = never> = (tag: ElementType, props: Props, className?: ClassName, recipe?: TSlot) => string | undefined;
|
|
697
|
+
//#endregion
|
|
698
|
+
//#region ../../lib/primitive/src/types/polymorphic-runtime/resolve-props-fn.d.ts
|
|
699
|
+
type ResolvePropsFn<Props extends AnyRecord> = <P extends Partial<Props>>(props: P) => Simplify<Omit<Props, keyof P> & P>;
|
|
700
|
+
//#endregion
|
|
701
|
+
//#region ../../lib/primitive/src/types/polymorphic-runtime/resolve-tag-fn.d.ts
|
|
702
|
+
type ResolveTagFn<TDefault extends ElementType> = <T extends ElementType | undefined = undefined>(as?: T) => T extends ElementType ? T : TDefault;
|
|
703
|
+
//#endregion
|
|
704
|
+
//#region ../../lib/primitive/src/types/polymorphic-runtime/runtime-plugin-field.d.ts
|
|
705
|
+
type RuntimePluginField<TPlugin extends ClassPlugin | undefined> = TPlugin extends ClassPlugin ? {
|
|
706
|
+
readonly classPlugin: TPlugin;
|
|
707
|
+
readonly hasStyling: true;
|
|
708
|
+
} : EmptyRecord;
|
|
709
|
+
//#endregion
|
|
710
|
+
//#region ../../lib/primitive/src/types/polymorphic-runtime/polymorphic-runtime.d.ts
|
|
711
|
+
type PolymorphicRuntime<TDefault extends ElementType, Props extends AnyRecord, Variants extends VariantMap, TSlot extends string = never, TPreset extends RecipeMap<Variants> = Readonly<StringMap<VariantSelection<Variants>>>, TPlugin extends ClassPlugin | undefined = ClassPlugin | undefined> = RuntimePluginField<TPlugin> & {
|
|
712
|
+
readonly options: Readonly<ResolvedFactoryOptions<TDefault, Props, Variants, TPreset>>;
|
|
713
|
+
readonly resolveTag: ResolveTagFn<TDefault>;
|
|
714
|
+
readonly resolveProps: ResolvePropsFn<Props>;
|
|
715
|
+
readonly resolveClasses: ResolveClassNameFn<Props, TSlot>;
|
|
716
|
+
readonly resolveAria: ResolveAriaFn;
|
|
717
|
+
};
|
|
718
|
+
//#endregion
|
|
719
|
+
//#region ../../lib/contract/src/strict/invariant-base.d.ts
|
|
720
|
+
declare abstract class InvariantBase {
|
|
721
|
+
private readonly diagnostics;
|
|
722
|
+
constructor(diagnostics: Diagnostics);
|
|
723
|
+
protected get warnActive(): boolean;
|
|
724
|
+
protected violate(input: DiagnosticInput): void;
|
|
725
|
+
protected warn(input: DiagnosticInput): void;
|
|
726
|
+
protected invariant(condition: unknown, input: DiagnosticInput): void;
|
|
727
|
+
}
|
|
728
|
+
//#endregion
|
|
729
|
+
//#region ../../lib/contract/src/children/children-evaluator.d.ts
|
|
730
|
+
type ChildrenEvaluatorOptions = {
|
|
731
|
+
/**
|
|
732
|
+
* When true, only children matching a rule (or text, per `allowText`) are
|
|
733
|
+
* valid — anything else is rejected. Default: false (open — children not
|
|
734
|
+
* matching any rule are allowed).
|
|
735
|
+
*/
|
|
736
|
+
readonly exclusiveChildren?: boolean | undefined;
|
|
737
|
+
/**
|
|
738
|
+
* When false, text/number child nodes are rejected regardless of
|
|
739
|
+
* exclusiveChildren or any listed rule. Default: true.
|
|
740
|
+
*/
|
|
741
|
+
readonly allowText?: boolean | undefined;
|
|
742
|
+
};
|
|
743
|
+
declare class ChildrenEvaluator extends InvariantBase {
|
|
744
|
+
#private;
|
|
745
|
+
constructor(rules: readonly ChildRuleInput[], diagnostics: Diagnostics, context?: string, options?: ChildrenEvaluatorOptions);
|
|
746
|
+
/**
|
|
747
|
+
* @param context Required when any rule has a `dynamic(...)` cardinality —
|
|
748
|
+
* supplies the resolved tag/props those rules are evaluated against.
|
|
749
|
+
*/
|
|
750
|
+
evaluate(children: unknown[], context?: ChildRuleContext): void;
|
|
751
|
+
}
|
|
752
|
+
//#endregion
|
|
753
|
+
//#region ../core/src/factory/create-polymorphic.d.ts
|
|
754
|
+
declare function createPolymorphic<TDefault extends ElementType, Props extends AnyRecord, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory>(options?: FactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicRuntime<TDefault, Props, Variants, Extract<keyof TPreset, string>, TPreset, PluginInstance<TPlugin>>;
|
|
755
|
+
//#endregion
|
|
756
|
+
//#region ../../lib/adapter-utils/src/types/built-children-evaluator.d.ts
|
|
757
|
+
/**
|
|
758
|
+
* Matches option types for which `buildEngines` constructs a {@link ChildrenEvaluator}. That
|
|
759
|
+
* happens for **any** of three knobs, so this mirrors all three rather than just child rules:
|
|
760
|
+
*
|
|
761
|
+
* - `enforcement.children` — a non-empty rule array
|
|
762
|
+
* - `enforcement.exclusiveChildren: true` — closed children, even with no rules
|
|
763
|
+
* - `enforcement.allowText: false` — text children rejected, even with no rules
|
|
764
|
+
*
|
|
765
|
+
* The last two only match when the option type carries the literal `true` / `false` (an author
|
|
766
|
+
* writing `exclusiveChildren: true` in a `const`-inferred options object); a widened `boolean`
|
|
767
|
+
* that happens to be `true` at runtime is an unavoidable gap between a value check and a type.
|
|
768
|
+
*/
|
|
769
|
+
type WithChildrenEnforcement = {
|
|
770
|
+
enforcement: {
|
|
771
|
+
children: readonly unknown[];
|
|
772
|
+
};
|
|
773
|
+
} | {
|
|
774
|
+
enforcement: {
|
|
775
|
+
exclusiveChildren: true;
|
|
776
|
+
};
|
|
777
|
+
} | {
|
|
778
|
+
enforcement: {
|
|
779
|
+
allowText: false;
|
|
780
|
+
};
|
|
781
|
+
};
|
|
782
|
+
/**
|
|
783
|
+
* The bundle of child evaluation services produced when
|
|
784
|
+
* child enforcement rules are configured.
|
|
785
|
+
*/
|
|
786
|
+
type ChildrenEvaluatorBundle = {
|
|
787
|
+
childrenEvaluator: ChildrenEvaluator;
|
|
788
|
+
};
|
|
789
|
+
/**
|
|
790
|
+
* Conditionally includes a {@link ChildrenEvaluator} in the
|
|
791
|
+
* built bundle when child enforcement rules are present.
|
|
792
|
+
*
|
|
793
|
+
* When no child enforcement rules are configured, this type
|
|
794
|
+
* resolves to {@link EmptyRecord}, omitting the property
|
|
795
|
+
* entirely rather than making it optional. Consumers can
|
|
796
|
+
* safely narrow using:
|
|
797
|
+
*
|
|
798
|
+
* ```ts
|
|
799
|
+
* if ('childrenEvaluator' in bundle) {
|
|
800
|
+
* // bundle.childrenEvaluator is available
|
|
801
|
+
* }
|
|
802
|
+
* ```
|
|
803
|
+
*
|
|
804
|
+
* @typeParam TOptions - The component configuration options.
|
|
805
|
+
*/
|
|
806
|
+
type BuiltChildrenEvaluator<TOptions extends WithChildRules> = TOptions extends WithChildrenEnforcement ? ChildrenEvaluatorBundle : EmptyRecord;
|
|
807
|
+
//#endregion
|
|
808
|
+
//#region ../../lib/adapter-utils/src/types/filter-predicate.d.ts
|
|
809
|
+
/**
|
|
810
|
+
* Determines whether a prop should be stripped before forwarding to the
|
|
811
|
+
* rendered element.
|
|
812
|
+
*
|
|
813
|
+
* Returning `true` excludes the prop from the output; returning `false`
|
|
814
|
+
* keeps it. This is the inverse polarity of `shouldForwardProp`-style
|
|
815
|
+
* predicates (Emotion/styled-components), where `true` means include.
|
|
816
|
+
*
|
|
817
|
+
* @param key - The prop name being evaluated.
|
|
818
|
+
* @param variantKeys - The set of configured variant prop names.
|
|
819
|
+
* @returns `true` to strip the prop; `false` to forward it.
|
|
820
|
+
*/
|
|
821
|
+
type FilterPredicate = (key: string, variantKeys: ReadonlySet<string>) => boolean;
|
|
822
|
+
//#endregion
|
|
823
|
+
//#region ../../lib/adapter-utils/src/slot/slot-validator.d.ts
|
|
824
|
+
declare class SlotValidator extends InvariantBase {
|
|
825
|
+
#private;
|
|
826
|
+
constructor(name: string, diagnostics: Diagnostics, elementTerm: string);
|
|
827
|
+
assertExclusive(): void;
|
|
828
|
+
warnDiscardedChildren(count: number): void;
|
|
829
|
+
assertSingleChild(count: number): void;
|
|
830
|
+
}
|
|
831
|
+
//#endregion
|
|
832
|
+
//#region ../../lib/adapter-utils/src/runtime/define-component.d.ts
|
|
833
|
+
export declare function defineContractComponent<O extends FactoryOptions>(options: O): <R>(factory: (options: O) => R) => R;
|
|
834
|
+
//#endregion
|
|
835
|
+
//#region ../../adapters/svelte/src/types/primitives.d.ts
|
|
836
|
+
type UnknownProps = AnyRecord;
|
|
837
|
+
type ResolvedProps = Readonly<UnknownProps>;
|
|
838
|
+
//#endregion
|
|
839
|
+
//#region ../../adapters/svelte/src/svelte-options.d.ts
|
|
840
|
+
type SvelteFactoryOptions<TDefault extends ElementType, Props extends UnknownProps, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = NoPreset, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory> = FactoryOptions<TDefault, Props, Variants, TPreset, TPlugin> & {
|
|
841
|
+
/**
|
|
842
|
+
* Return true for any prop key that should be consumed but not forwarded to the DOM.
|
|
843
|
+
* Receives `runtime.options.variantKeys` as a convenience if needed.
|
|
844
|
+
*/
|
|
845
|
+
filterProps?: (key: string, variantKeys: ReadonlySet<string>) => boolean;
|
|
846
|
+
};
|
|
847
|
+
//#endregion
|
|
848
|
+
//#region ../../adapters/svelte/src/types/runtime.d.ts
|
|
849
|
+
type RuntimeOptions = Readonly<Pick<ResolvedFactoryOptions, 'displayName' | 'diagnostics' | 'variantKeys' | 'childRules' | 'allowedAs' | 'normalizeFn' | 'htmlPropNormalizersFn' | 'htmlChildrenEvaluatorFn'>>;
|
|
850
|
+
type TagResolver = Readonly<{
|
|
851
|
+
resolveTag(as?: ElementType): ElementType;
|
|
852
|
+
}>;
|
|
853
|
+
type PropsResolver = Readonly<{
|
|
854
|
+
resolveProps(props: UnknownProps): ResolvedProps;
|
|
855
|
+
}>;
|
|
856
|
+
type ClassResolver = Readonly<{
|
|
857
|
+
resolveClasses(tag: ElementType, props: ResolvedProps, className?: ClassName, recipe?: string): string | undefined;
|
|
858
|
+
}>;
|
|
859
|
+
type AriaResolver = Readonly<{
|
|
860
|
+
resolveAria<P extends IntrinsicProps>(tag: ElementType, props: P, extraProps?: IntrinsicProps): {
|
|
861
|
+
props: P;
|
|
862
|
+
};
|
|
863
|
+
}>;
|
|
864
|
+
type Runtime = Readonly<TagResolver & PropsResolver & ClassResolver & AriaResolver & {
|
|
865
|
+
options: RuntimeOptions;
|
|
866
|
+
}>;
|
|
867
|
+
type TypedRuntime<G extends PolymorphicGenerics> = ReturnType<typeof createPolymorphic<DefaultOf<G>, PropsOf<G>, VariantsOf<G>, RecipeOf<G>>>;
|
|
868
|
+
//#endregion
|
|
869
|
+
//#region ../../adapters/svelte/src/types/built-runtime.d.ts
|
|
870
|
+
type OnElementFn<G extends PolymorphicGenerics = PolymorphicGenerics> = (element: ElementForTag<DefaultOf<G> | AllowedOf<G>>, getProps: () => Readonly<PropsOf<G>>) => void | (() => void);
|
|
871
|
+
type BuiltRuntime<G extends PolymorphicGenerics = PolymorphicGenerics, TOptions extends WithChildRules = WithChildRules> = BuiltChildrenEvaluator<TOptions> & {
|
|
872
|
+
runtime: TypedRuntime<G>;
|
|
873
|
+
filterProps: FilterPredicate;
|
|
874
|
+
slotValidator: SlotValidator;
|
|
875
|
+
onElement?: OnElementFn<G>;
|
|
876
|
+
};
|
|
877
|
+
type AnyBuiltRuntime = {
|
|
878
|
+
runtime: Runtime;
|
|
879
|
+
filterProps: FilterPredicate;
|
|
880
|
+
slotValidator: SlotValidator;
|
|
881
|
+
childrenEvaluator?: ChildrenEvaluator;
|
|
882
|
+
onElement?: OnElementFn;
|
|
883
|
+
};
|
|
884
|
+
//#endregion
|
|
885
|
+
//#region ../../adapters/svelte/src/types/props.d.ts
|
|
886
|
+
/**
|
|
887
|
+
* Props accepted by `<Polymorphic>`, the component every `createContractComponent` bundle
|
|
888
|
+
* renders through in the Svelte adapter — distinct from `KnownProps` above, which describes
|
|
889
|
+
* the abstract polymorphic-prop contract rather than this specific component's props (it also
|
|
890
|
+
* carries the runtime bundle).
|
|
891
|
+
*
|
|
892
|
+
* `children` is intentionally generic-erased (`Snippet | Snippet<[UnknownProps]>`, not typed
|
|
893
|
+
* against any particular bundle's `PolymorphicGenerics`) — a deliberate design decision, not a
|
|
894
|
+
* type-system workaround. One physical `Polymorphic.svelte` (and its `.svelte.d.ts`) serves every
|
|
895
|
+
* bundle's `G`; it cannot become `Polymorphic<G1>` vs. `Polymorphic<G2>` per call site the way a
|
|
896
|
+
* generic React function component can. Bundle-specific prop precision for an `asChild` snippet is
|
|
897
|
+
* recovered on the *caller's* side instead, via `ResolvedSlotProps<GenericsOf<typeof bundle>>` —
|
|
898
|
+
* see that type's own doc comment.
|
|
899
|
+
*/
|
|
900
|
+
interface PolymorphicComponentProps {
|
|
901
|
+
/** The contract bundle to render, from `createContractComponent`. */
|
|
902
|
+
bundle: AnyBuiltRuntime;
|
|
903
|
+
/** Overrides the default tag. String-only: `<svelte:element>` only accepts string tags. */
|
|
904
|
+
as?: string;
|
|
905
|
+
/** Renders `children` as a snippet receiving the resolved props, instead of the host element. */
|
|
906
|
+
asChild?: boolean;
|
|
907
|
+
/** Caller class, merged with the resolved variant classes. */
|
|
908
|
+
class?: string;
|
|
909
|
+
/** Selects a named preset from `styling.presets`. */
|
|
910
|
+
recipe?: string;
|
|
911
|
+
children?: Snippet | Snippet<[UnknownProps]>;
|
|
912
|
+
[key: string]: unknown;
|
|
913
|
+
}
|
|
914
|
+
//#endregion
|
|
915
|
+
//#region ../../adapters/svelte/src/types/resolved-slot-props.d.ts
|
|
916
|
+
/**
|
|
917
|
+
* Recovers a bundle's `PolymorphicGenerics` descriptor from its own value type — the Svelte
|
|
918
|
+
* analog of React's/Preact's `__generics` marker recovery, but
|
|
919
|
+
* needs no marker at all: `createContractComponent` already returns `BuiltRuntime<G, TOptions>`
|
|
920
|
+
* directly (not an erased type), so `G` is a plain, ordinary type parameter to `infer` back out.
|
|
921
|
+
* The second type argument is fixed to `WithChildRules` (its own upper bound) rather than
|
|
922
|
+
* `infer`'d, since nothing here needs `TOptions` itself, only `G`. Falls back to the widest
|
|
923
|
+
* `PolymorphicGenerics` for any non-praxis-kit bundle, the same "no marker, nothing to recover"
|
|
924
|
+
* case `HasGenerics<G>`'s own `never` branch covers for React/Preact — a caller annotation, not an
|
|
925
|
+
* internal assertion, so a mismatched bundle should degrade gracefully rather than poison the
|
|
926
|
+
* whole expression with `never`.
|
|
927
|
+
*/
|
|
928
|
+
type GenericsOf<T extends AnyBuiltRuntime> = T extends BuiltRuntime<infer G, WithChildRules> ? G : PolymorphicGenerics;
|
|
929
|
+
/**
|
|
930
|
+
* Props an `asChild` snippet receives once defaults, variant classes, and ARIA role resolution
|
|
931
|
+
* have all run (see `buildSlotProps` in `Polymorphic.svelte`). `class` is narrowed to a resolved
|
|
932
|
+
* `string`. `ref`, `role`, and `style` are intentionally left off the type — a snippet that
|
|
933
|
+
* specifically needs one casts locally. `<Polymorphic>` itself can't be typed against this
|
|
934
|
+
* directly (its own `children` prop stays the erased `Snippet<[UnknownProps]>`, since one
|
|
935
|
+
* `.svelte` file/`.d.ts` serves every bundle's `G`) — annotate your own snippet parameter with it
|
|
936
|
+
* instead:
|
|
937
|
+
*
|
|
938
|
+
* ```svelte
|
|
939
|
+
* <Polymorphic bundle={buttonBundle} asChild>
|
|
940
|
+
* {#snippet children(props: ResolvedSlotProps<GenericsOf<typeof buttonBundle>>)}
|
|
941
|
+
* <a {...props} href="/foo">Go</a>
|
|
942
|
+
* {/snippet}
|
|
943
|
+
* </Polymorphic>
|
|
944
|
+
* ```
|
|
945
|
+
*
|
|
946
|
+
* The `ref`/`role`/`style` omissions are real design intent, not obvious from the type alone —
|
|
947
|
+
* see `DECISIONS.md` → "`adapters/svelte` — `ResolvedSlotProps`'s omitted fields" for the full
|
|
948
|
+
* case (Svelte has no `ref` prop concept; `role`/`style` can't be given a type that's safe to
|
|
949
|
+
* spread onto an unknown target element).
|
|
950
|
+
*/
|
|
951
|
+
type ResolvedSlotProps<G extends PolymorphicGenerics> = Partial<OmitIndexSignature<PropsOf<G>>> & OmitIndexSignature<VariantProps<VariantsOf<G>>> & {
|
|
952
|
+
class?: string | undefined;
|
|
953
|
+
};
|
|
954
|
+
//#endregion
|
|
955
|
+
//#region ../../adapters/svelte/src/create-contract-component.d.ts
|
|
956
|
+
/**
|
|
957
|
+
* Creates a praxis-kit contract bundle for use with Svelte's `<Polymorphic>` component.
|
|
958
|
+
*
|
|
959
|
+
* Unlike the other adapters, this returns a plain bundle object rather than a component —
|
|
960
|
+
* Svelte components must come from `.svelte` files, a compile-time constraint — so the bundle
|
|
961
|
+
* is passed as the `bundle` prop:
|
|
962
|
+
*
|
|
963
|
+
* ```ts
|
|
964
|
+
* // button.ts
|
|
965
|
+
* export const buttonBundle = createContractComponent({
|
|
966
|
+
* tag: 'button',
|
|
967
|
+
* name: 'Button',
|
|
968
|
+
* styling: {
|
|
969
|
+
* base: 'btn',
|
|
970
|
+
* variants: { intent: { primary: 'btn--primary', ghost: 'btn--ghost' } },
|
|
971
|
+
* defaults: { intent: 'primary' },
|
|
972
|
+
* },
|
|
973
|
+
* })
|
|
974
|
+
* ```
|
|
975
|
+
*
|
|
976
|
+
* ```svelte
|
|
977
|
+
* <!-- Button.svelte -->
|
|
978
|
+
* <script lang="ts">
|
|
979
|
+
* import Polymorphic from 'praxis-kit/svelte/Polymorphic.svelte'
|
|
980
|
+
* import { buttonBundle } from './button'
|
|
981
|
+
* </script>
|
|
982
|
+
* <Polymorphic bundle={buttonBundle} intent="ghost" as="a" href="/home">Home</Polymorphic>
|
|
983
|
+
* ```
|
|
984
|
+
*
|
|
985
|
+
* Pass `subComponents` to attach named sub-components (`Card.Header`) — `Object.assign` works
|
|
986
|
+
* the same way on a plain bundle as on a component function/class, so `Card.Header` is itself
|
|
987
|
+
* just another bundle, passed to its own `<Polymorphic bundle={Card.Header}>`. Pass `onElement`
|
|
988
|
+
* to run setup once the real DOM element exists.
|
|
989
|
+
*/
|
|
990
|
+
export declare function createContractComponent<TDefault extends ElementType, Props extends UnknownProps = EmptyRecord, Variants extends Readonly<VariantMap> = NoVariants, TPreset extends RecipeMap<Variants> = NoPreset, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory, TSubComponents extends Readonly<AnyRecord> = EmptyRecord, TOptions extends WithChildRules = SvelteFactoryOptions<TDefault, MergeRecords<Props, ExtractPluginProps<TPlugin>>, Variants, TPreset>>(options: SvelteFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin> & TOptions & {
|
|
991
|
+
readonly subComponents?: TSubComponents;
|
|
992
|
+
}): MergeRecords<BuiltRuntime<PolymorphicGenerics<TDefault, MergeRecords<Props, ExtractPluginProps<TPlugin>>, Variants, TPreset>, TOptions>, TSubComponents>;
|
|
993
|
+
//#endregion
|
|
994
|
+
export type { AnyBuiltRuntime, AnyFactoryOptions, BuiltRuntime, ElementType, EmptyRecord, FactoryOptions, GenericsOf, PolymorphicComponentProps, PolymorphicGenerics, ResolvedSlotProps, SvelteFactoryOptions };
|