praxis-kit 1.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.
@@ -0,0 +1,309 @@
1
+ import { RequireAtLeastOne, Simplify, ReadonlyDeep } from 'type-fest';
2
+ import * as vue from 'vue';
3
+ import { AllowedComponentProps } from 'vue';
4
+
5
+ type AnyRecord = Record<string, unknown>;
6
+
7
+ type IntrinsicTag = keyof HTMLElementTagNameMap;
8
+
9
+ type ElementType = IntrinsicTag | (string & {});
10
+
11
+ 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"];
12
+ type KnownAriaRole = (typeof KNOWN_ARIA_ROLES)[number];
13
+
14
+ type AriaRole = KnownAriaRole | (string & {});
15
+
16
+ type ClassName = string | string[];
17
+
18
+ type EmptyRecord = Record<never, never>;
19
+
20
+ type IntrinsicProps = AnyRecord & {
21
+ role?: AriaRole;
22
+ };
23
+
24
+ type NonEmptyArray<T> = [T, ...T[]];
25
+
26
+ type TagMap = Partial<Record<IntrinsicTag | (string & {}), ClassName>>;
27
+
28
+ type StrictMode = boolean | 'warn' | 'async-warn' | 'throw';
29
+
30
+ type CardinalityInput = {
31
+ min?: number;
32
+ max?: number;
33
+ };
34
+
35
+ type ChildRuleMatch<T, U extends T = T> = (child: T) => child is U;
36
+
37
+ type ChildRulePosition = 'first' | 'last' | 'any';
38
+
39
+ type ChildRuleInput<T = unknown, U extends T = T> = {
40
+ name: string;
41
+ match: ChildRuleMatch<T, U>;
42
+ cardinality?: CardinalityInput;
43
+ position?: ChildRulePosition;
44
+ /**
45
+ * Optional component-type reference for O(1) dispatch index.
46
+ * When provided for every rule, the matcher reads child.type instead of
47
+ * calling every match function on every child (O(n×m) → O(n+m)).
48
+ */
49
+ type?: unknown;
50
+ };
51
+
52
+ type ValidResult = {
53
+ valid: true;
54
+ };
55
+
56
+ type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
57
+
58
+ type VariantValue = string | string[];
59
+
60
+ type VariantStates<K extends string = string> = Record<K, VariantValue>;
61
+
62
+ type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
63
+
64
+ type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
65
+
66
+ type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
67
+ type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
68
+ type CompoundVariantConditions<V extends VariantMap> = Simplify<{
69
+ [K in keyof V]: CompoundVariantConditionValue<V, K>;
70
+ }>;
71
+ type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
72
+ type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
73
+ type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
74
+ class: VariantValue;
75
+ };
76
+
77
+ interface CVACompounds<V extends VariantMap> {
78
+ compoundVariants?: readonly CompoundVariant<V>[];
79
+ }
80
+
81
+ /** The full optional prop surface exposed to callers for a given variant map. */
82
+ type VariantProps<V extends VariantMap> = {
83
+ [K in keyof V]?: VariantKey<V, K>;
84
+ };
85
+ type DefaultVariants<V extends VariantMap> = {
86
+ [K in keyof V]?: VariantKey<V, K>;
87
+ };
88
+
89
+ interface CVADefaults<V extends VariantMap> {
90
+ defaultVariants?: DefaultVariants<V>;
91
+ }
92
+
93
+ interface CVAVariants<V extends VariantMap> {
94
+ variants?: V;
95
+ }
96
+
97
+ /**
98
+ * A partial selection of variant states authored at factory definition time.
99
+ *
100
+ * Uses `keyof V[K]` directly (not `VariantKey`) so TypeScript can eagerly
101
+ * resolve the union at constraint-check time without deferred conditional types.
102
+ */
103
+ type VariantSelection<V extends VariantMap> = {
104
+ [K in keyof V]?: keyof V[K];
105
+ };
106
+
107
+ /**
108
+ * A static, immutable map of named presets to partial variant selections.
109
+ *
110
+ * Presets are named bundles of variant props that callers activate by key,
111
+ * avoiding the need to repeat variant combinations at each call site.
112
+ */
113
+ type PresetMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
114
+
115
+ interface PolymorphicGenerics<TDefault extends ElementType = ElementType, Props extends AnyRecord = AnyRecord, Variants extends Readonly<VariantMap> = Readonly<VariantMap>, TPreset extends PresetMap<Variants> = Readonly<EmptyRecord>, TAllowed extends ElementType = ElementType> {
116
+ default: TDefault;
117
+ props: Props;
118
+ variants: Variants;
119
+ preset: TPreset;
120
+ allowed: TAllowed;
121
+ }
122
+ type VariantsOf<T extends PolymorphicGenerics> = T['variants'];
123
+ type PresetOf<T extends PolymorphicGenerics> = T['preset'];
124
+
125
+ type PresetTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
126
+
127
+ interface BaseClassOptions {
128
+ baseClassName?: ClassName;
129
+ }
130
+
131
+ type ClassPipelineFn = (tag: unknown, props: AnyRecord, className?: ClassName, variantKey?: string) => string;
132
+
133
+ interface PresetOptions<TVariants extends VariantMap = VariantMap> {
134
+ presetMap?: Record<string, PresetTarget<TVariants>>;
135
+ }
136
+
137
+ interface TagMapOptions {
138
+ tagMap?: TagMap;
139
+ }
140
+
141
+ type CompositionOptions<TVariants extends VariantMap = VariantMap> = Simplify<TagMapOptions & PresetOptions<TVariants>>;
142
+
143
+ type CVASystemOptions<TVariants extends VariantMap = VariantMap> = Simplify<CVAVariants<TVariants> & CVADefaults<TVariants> & CVACompounds<TVariants>>;
144
+
145
+ type StyleOptions<TVariants extends VariantMap = VariantMap> = Simplify<BaseClassOptions & CVASystemOptions<TVariants>>;
146
+
147
+ type ClassPipelineOptions<TVariants extends VariantMap = VariantMap> = Simplify<StyleOptions<TVariants> & CompositionOptions<TVariants>>;
148
+
149
+ type OwnedPropKeys = ReadonlySet<string>;
150
+
151
+ type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
152
+ pipeline: ClassPipelineFn;
153
+ ownedKeys?: OwnedPropKeys;
154
+ readonly _pluginProps?: TProps;
155
+ }>;
156
+
157
+ type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, strict: StrictMode) => ClassPlugin<TProps>;
158
+
159
+ type AriaContext = {
160
+ readonly tag: IntrinsicTag;
161
+ readonly implicitRole: AriaRole | undefined;
162
+ readonly effectiveRole: string | undefined;
163
+ readonly props: ReadonlyDeep<IntrinsicProps>;
164
+ };
165
+
166
+ type RemoveAttributeFixKind = `removeAttribute:${string}`;
167
+ type InjectLiveFixKind = `injectLive:${string}`;
168
+ type FixKind = 'removeRole' | 'setRole' | 'normalizeRelevantAll' | RemoveAttributeFixKind | InjectLiveFixKind;
169
+
170
+ type AriaFixResult = {
171
+ applied: false;
172
+ next: ReadonlyDeep<IntrinsicProps>;
173
+ } | {
174
+ applied: true;
175
+ next: ReadonlyDeep<IntrinsicProps>;
176
+ previous: ReadonlyDeep<IntrinsicProps>;
177
+ };
178
+ type AriaFix = {
179
+ readonly kind: FixKind;
180
+ readonly priority?: number;
181
+ readonly source?: string;
182
+ readonly apply: (context: AriaContext) => AriaFixResult;
183
+ };
184
+
185
+ type Severity = 'error' | 'warning' | (string & {});
186
+
187
+ type AriaInvalidBase<M extends string = string> = {
188
+ valid: false;
189
+ severity: Severity;
190
+ message: M;
191
+ attribute?: string;
192
+ };
193
+ type AriaInvalidWithFix<M extends string = string> = AriaInvalidBase<M> & {
194
+ fixable: true;
195
+ fix: AriaFix;
196
+ };
197
+ type AriaInvalidWithoutFix<M extends string = string> = AriaInvalidBase<M> & {
198
+ fixable: false;
199
+ };
200
+ type AriaInvalidResult<M extends string = string> = AriaInvalidWithFix<M> | AriaInvalidWithoutFix<M>;
201
+ type AriaResult = ValidResult | AriaInvalidResult;
202
+
203
+ type AriaRule<C extends AriaContext = AriaContext> = (context: C) => readonly AriaResult[];
204
+
205
+ type PropNormalizer = (props: Readonly<AnyRecord & IntrinsicProps>) => Partial<AnyRecord & IntrinsicProps>;
206
+
207
+ type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
208
+ readonly strict?: StrictMode;
209
+ readonly aria?: readonly AriaRule[];
210
+ readonly children?: readonly ChildRuleInput[];
211
+ readonly props?: readonly PropNormalizer[];
212
+ /** Restricts the `as` prop to this set of tags. Violations route through strict mode. */
213
+ readonly allowedAs?: readonly TAllowed[];
214
+ };
215
+
216
+ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends PresetMap<V> = Readonly<EmptyRecord>, TPluginProps extends AnyRecord = EmptyRecord> = {
217
+ readonly base?: ClassName;
218
+ readonly variants?: V;
219
+ readonly defaults?: Partial<VariantProps<V>>;
220
+ readonly compounds?: readonly CompoundVariant<V>[];
221
+ readonly presets?: TPreset;
222
+ readonly tags?: Readonly<TagMap>;
223
+ readonly plugin?: ClassPluginFactory<TPluginProps>;
224
+ readonly precomputedClasses?: Readonly<Record<string, string>>;
225
+ };
226
+
227
+ type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
228
+ normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
229
+ }['normalize'];
230
+ type FactoryOptions<TDefault extends ElementType = ElementType, Props extends AnyRecord = EmptyRecord, V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends PresetMap<V> = Readonly<EmptyRecord>, TPluginProps extends AnyRecord = EmptyRecord, TAllowed extends ElementType = ElementType> = {
231
+ readonly tag?: TDefault;
232
+ readonly name?: string;
233
+ readonly defaults?: Partial<NoInfer<Props>>;
234
+ readonly normalize?: NormalizeFn<NoInfer<Props>>;
235
+ readonly styling?: StylingOptions<V, TPreset, TPluginProps>;
236
+ readonly enforcement?: EnforcementOptions<TAllowed>;
237
+ };
238
+
239
+ declare const disabledProps: PropNormalizer;
240
+
241
+ declare const invalidProps: PropNormalizer;
242
+
243
+ type DefaultOf<T extends PolymorphicGenerics> = T['default'];
244
+ type PropsOf<T extends PolymorphicGenerics> = T['props'];
245
+
246
+ type UnknownProps = Record<string, unknown>;
247
+
248
+ type VueFactoryOptions<TDefault extends ElementType, Props extends UnknownProps, Variants extends Readonly<VariantMap>, TPreset extends PresetMap<Variants> = Readonly<EmptyRecord>, TPluginProps extends AnyRecord = EmptyRecord> = FactoryOptions<TDefault, Props, Variants, TPreset, TPluginProps> & {
249
+ /**
250
+ * Return true for any prop key that should be consumed but not forwarded to
251
+ * the DOM. Variant keys are always stripped automatically.
252
+ */
253
+ filterProps?: (key: string, variantKeys: ReadonlySet<string>) => boolean;
254
+ };
255
+
256
+ type SlottableProps = {
257
+ children?: unknown;
258
+ };
259
+ /**
260
+ * Marker component for the Slottable sibling pattern. Wrap content that should
261
+ * be passed as the asChild slot's children when additional siblings are present.
262
+ */
263
+ declare const Slottable: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
264
+ [key: string]: any;
265
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
266
+
267
+ type ControlProps<G extends PolymorphicGenerics, TAs extends ElementType> = PropsOf<G> & VariantProps<VariantsOf<G>> & {
268
+ as?: TAs;
269
+ class?: ClassName;
270
+ variantKey?: keyof PresetOf<G>;
271
+ };
272
+ /**
273
+ * Props for the normal (non-slot) render path. `asChild` is absent or `false`.
274
+ *
275
+ * `AllowedComponentProps` adds Vue system props (`key`, `ref`, lifecycle hooks).
276
+ * `UnknownProps` allows HTML attributes that aren't explicitly enumerated.
277
+ */
278
+ type PolymorphicProps<G extends PolymorphicGenerics, TAs extends ElementType = DefaultOf<G>> = Simplify<ControlProps<G, TAs> & AllowedComponentProps & {
279
+ asChild?: false;
280
+ } & UnknownProps>;
281
+ /**
282
+ * Props for the slot render path (`asChild: true`). `as` is forbidden — combining
283
+ * `as` with `asChild` is a runtime invariant violation, so it is rejected at the
284
+ * type level too.
285
+ */
286
+ type PolymorphicWithAsChild<G extends PolymorphicGenerics, TAs extends ElementType = DefaultOf<G>> = Simplify<ControlProps<G, TAs> & AllowedComponentProps & {
287
+ asChild: true;
288
+ as?: never;
289
+ } & UnknownProps>;
290
+ /**
291
+ * A Vue polymorphic component typed for use in templates and JSX via the
292
+ * `new()` instance-constructor pattern that Volar uses for prop checking.
293
+ *
294
+ * Unlike React's overloaded call signatures, Vue has no per-call-site generic
295
+ * inference for `as`, so HTML attribute narrowing based on the `as` value is
296
+ * not available — `UnknownProps` captures the open-ended attribute surface instead.
297
+ */
298
+ type PolymorphicComponent<G extends PolymorphicGenerics> = {
299
+ new (): {
300
+ $props: PolymorphicProps<G> | PolymorphicWithAsChild<G>;
301
+ };
302
+ displayName?: string;
303
+ };
304
+
305
+ declare function createContractComponent<TDefault extends ElementType, Props extends UnknownProps = EmptyRecord, Variants extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends PresetMap<Variants> = Readonly<EmptyRecord>, TPluginProps extends AnyRecord = EmptyRecord>(options: VueFactoryOptions<TDefault, Props, Variants, TPreset, TPluginProps>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & TPluginProps, Variants, TPreset>>;
306
+
307
+ declare function defineContractComponent<O extends FactoryOptions>(options: O): <R>(factory: (options: O) => R) => R;
308
+
309
+ export { type PolymorphicComponent, type PolymorphicProps, type PolymorphicWithAsChild, Slottable, type SlottableProps, type VueFactoryOptions, createContractComponent, defineContractComponent, disabledProps, invalidProps };