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,343 @@
1
+ import { RequireAtLeastOne, Simplify, ReadonlyDeep } from 'type-fest';
2
+
3
+ type AnyRecord = Record<string, unknown>;
4
+
5
+ type IntrinsicTag = keyof HTMLElementTagNameMap;
6
+
7
+ type ElementType = IntrinsicTag | (string & {});
8
+
9
+ 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"];
10
+ type KnownAriaRole = (typeof KNOWN_ARIA_ROLES)[number];
11
+
12
+ type AriaRole = KnownAriaRole | (string & {});
13
+
14
+ type ClassName = string | string[];
15
+
16
+ type EmptyRecord = Record<never, never>;
17
+
18
+ type IntrinsicProps = AnyRecord & {
19
+ role?: AriaRole;
20
+ };
21
+
22
+ type NonEmptyArray<T> = [T, ...T[]];
23
+
24
+ type TagMap = Partial<Record<IntrinsicTag | (string & {}), ClassName>>;
25
+
26
+ type StrictMode = boolean | 'warn' | 'async-warn' | 'throw';
27
+
28
+ type CardinalityInput = {
29
+ min?: number;
30
+ max?: number;
31
+ };
32
+
33
+ type ChildRuleMatch<T, U extends T = T> = (child: T) => child is U;
34
+
35
+ type ChildRulePosition = 'first' | 'last' | 'any';
36
+
37
+ type ChildRuleInput<T = unknown, U extends T = T> = {
38
+ name: string;
39
+ match: ChildRuleMatch<T, U>;
40
+ cardinality?: CardinalityInput;
41
+ position?: ChildRulePosition;
42
+ /**
43
+ * Optional component-type reference for O(1) dispatch index.
44
+ * When provided for every rule, the matcher reads child.type instead of
45
+ * calling every match function on every child (O(n×m) → O(n+m)).
46
+ */
47
+ type?: unknown;
48
+ };
49
+
50
+ type WithChildRules = {
51
+ enforcement?: {
52
+ children?: readonly unknown[];
53
+ };
54
+ };
55
+
56
+ type ValidResult = {
57
+ valid: true;
58
+ };
59
+
60
+ type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
61
+
62
+ type VariantValue = string | string[];
63
+
64
+ type VariantStates<K extends string = string> = Record<K, VariantValue>;
65
+
66
+ type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
67
+
68
+ type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
69
+
70
+ type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
71
+ type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
72
+ type CompoundVariantConditions<V extends VariantMap> = Simplify<{
73
+ [K in keyof V]: CompoundVariantConditionValue<V, K>;
74
+ }>;
75
+ type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
76
+ type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
77
+ type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
78
+ class: VariantValue;
79
+ };
80
+
81
+ interface CVACompounds<V extends VariantMap> {
82
+ compoundVariants?: readonly CompoundVariant<V>[];
83
+ }
84
+
85
+ /** The full optional prop surface exposed to callers for a given variant map. */
86
+ type VariantProps<V extends VariantMap> = {
87
+ [K in keyof V]?: VariantKey<V, K>;
88
+ };
89
+ type DefaultVariants<V extends VariantMap> = {
90
+ [K in keyof V]?: VariantKey<V, K>;
91
+ };
92
+
93
+ interface CVADefaults<V extends VariantMap> {
94
+ defaultVariants?: DefaultVariants<V>;
95
+ }
96
+
97
+ interface CVAVariants<V extends VariantMap> {
98
+ variants?: V;
99
+ }
100
+
101
+ /**
102
+ * A partial selection of variant states authored at factory definition time.
103
+ *
104
+ * Uses `keyof V[K]` directly (not `VariantKey`) so TypeScript can eagerly
105
+ * resolve the union at constraint-check time without deferred conditional types.
106
+ */
107
+ type VariantSelection<V extends VariantMap> = {
108
+ [K in keyof V]?: keyof V[K];
109
+ };
110
+
111
+ /**
112
+ * A static, immutable map of named presets to partial variant selections.
113
+ *
114
+ * Presets are named bundles of variant props that callers activate by key,
115
+ * avoiding the need to repeat variant combinations at each call site.
116
+ */
117
+ type PresetMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
118
+
119
+ 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> {
120
+ default: TDefault;
121
+ props: Props;
122
+ variants: Variants;
123
+ preset: TPreset;
124
+ allowed: TAllowed;
125
+ }
126
+
127
+ type PresetTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
128
+
129
+ interface BaseClassOptions {
130
+ baseClassName?: ClassName;
131
+ }
132
+
133
+ type ClassPipelineFn = (tag: unknown, props: AnyRecord, className?: ClassName, variantKey?: string) => string;
134
+
135
+ interface PresetOptions<TVariants extends VariantMap = VariantMap> {
136
+ presetMap?: Record<string, PresetTarget<TVariants>>;
137
+ }
138
+
139
+ interface TagMapOptions {
140
+ tagMap?: TagMap;
141
+ }
142
+
143
+ type CompositionOptions<TVariants extends VariantMap = VariantMap> = Simplify<TagMapOptions & PresetOptions<TVariants>>;
144
+
145
+ type CVASystemOptions<TVariants extends VariantMap = VariantMap> = Simplify<CVAVariants<TVariants> & CVADefaults<TVariants> & CVACompounds<TVariants>>;
146
+
147
+ type StyleOptions<TVariants extends VariantMap = VariantMap> = Simplify<BaseClassOptions & CVASystemOptions<TVariants>>;
148
+
149
+ type ClassPipelineOptions<TVariants extends VariantMap = VariantMap> = Simplify<StyleOptions<TVariants> & CompositionOptions<TVariants>>;
150
+
151
+ type OwnedPropKeys = ReadonlySet<string>;
152
+
153
+ type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
154
+ pipeline: ClassPipelineFn;
155
+ ownedKeys?: OwnedPropKeys;
156
+ readonly _pluginProps?: TProps;
157
+ }>;
158
+
159
+ type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, strict: StrictMode) => ClassPlugin<TProps>;
160
+
161
+ type AriaContext = {
162
+ readonly tag: IntrinsicTag;
163
+ readonly implicitRole: AriaRole | undefined;
164
+ readonly effectiveRole: string | undefined;
165
+ readonly props: ReadonlyDeep<IntrinsicProps>;
166
+ };
167
+
168
+ type RemoveAttributeFixKind = `removeAttribute:${string}`;
169
+ type InjectLiveFixKind = `injectLive:${string}`;
170
+ type FixKind = 'removeRole' | 'setRole' | 'normalizeRelevantAll' | RemoveAttributeFixKind | InjectLiveFixKind;
171
+
172
+ type AriaFixResult = {
173
+ applied: false;
174
+ next: ReadonlyDeep<IntrinsicProps>;
175
+ } | {
176
+ applied: true;
177
+ next: ReadonlyDeep<IntrinsicProps>;
178
+ previous: ReadonlyDeep<IntrinsicProps>;
179
+ };
180
+ type AriaFix = {
181
+ readonly kind: FixKind;
182
+ readonly priority?: number;
183
+ readonly source?: string;
184
+ readonly apply: (context: AriaContext) => AriaFixResult;
185
+ };
186
+
187
+ type Severity = 'error' | 'warning' | (string & {});
188
+
189
+ type AriaInvalidBase<M extends string = string> = {
190
+ valid: false;
191
+ severity: Severity;
192
+ message: M;
193
+ attribute?: string;
194
+ };
195
+ type AriaInvalidWithFix<M extends string = string> = AriaInvalidBase<M> & {
196
+ fixable: true;
197
+ fix: AriaFix;
198
+ };
199
+ type AriaInvalidWithoutFix<M extends string = string> = AriaInvalidBase<M> & {
200
+ fixable: false;
201
+ };
202
+ type AriaInvalidResult<M extends string = string> = AriaInvalidWithFix<M> | AriaInvalidWithoutFix<M>;
203
+ type AriaResult = ValidResult | AriaInvalidResult;
204
+
205
+ type AriaRule<C extends AriaContext = AriaContext> = (context: C) => readonly AriaResult[];
206
+
207
+ type PropNormalizer = (props: Readonly<AnyRecord & IntrinsicProps>) => Partial<AnyRecord & IntrinsicProps>;
208
+
209
+ type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
210
+ readonly strict?: StrictMode;
211
+ readonly aria?: readonly AriaRule[];
212
+ readonly children?: readonly ChildRuleInput[];
213
+ readonly props?: readonly PropNormalizer[];
214
+ /** Restricts the `as` prop to this set of tags. Violations route through strict mode. */
215
+ readonly allowedAs?: readonly TAllowed[];
216
+ };
217
+
218
+ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends PresetMap<V> = Readonly<EmptyRecord>, TPluginProps extends AnyRecord = EmptyRecord> = {
219
+ readonly base?: ClassName;
220
+ readonly variants?: V;
221
+ readonly defaults?: Partial<VariantProps<V>>;
222
+ readonly compounds?: readonly CompoundVariant<V>[];
223
+ readonly presets?: TPreset;
224
+ readonly tags?: Readonly<TagMap>;
225
+ readonly plugin?: ClassPluginFactory<TPluginProps>;
226
+ readonly precomputedClasses?: Readonly<Record<string, string>>;
227
+ };
228
+
229
+ type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
230
+ normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
231
+ }['normalize'];
232
+ 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> = {
233
+ readonly tag?: TDefault;
234
+ readonly name?: string;
235
+ readonly defaults?: Partial<NoInfer<Props>>;
236
+ readonly normalize?: NormalizeFn<NoInfer<Props>>;
237
+ readonly styling?: StylingOptions<V, TPreset, TPluginProps>;
238
+ readonly enforcement?: EnforcementOptions<TAllowed>;
239
+ };
240
+
241
+ type ResolvedFactoryOptions<TDefault extends ElementType = ElementType, Props extends AnyRecord = EmptyRecord, V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends PresetMap<V> = Readonly<EmptyRecord>> = {
242
+ readonly defaultTag: TDefault;
243
+ readonly baseClassName?: ClassName;
244
+ readonly defaultProps?: Partial<Props>;
245
+ readonly tagMap?: Readonly<TagMap>;
246
+ readonly presetMap?: TPreset;
247
+ readonly variants?: V;
248
+ readonly defaultVariants?: Partial<VariantProps<V>>;
249
+ readonly compoundVariants?: readonly CompoundVariant<V>[];
250
+ readonly displayName?: string;
251
+ readonly strict: StrictMode;
252
+ readonly variantKeys: ReadonlySet<string>;
253
+ readonly normalizeFn?: NormalizeFn<Props>;
254
+ readonly childRules?: readonly ChildRuleInput[];
255
+ readonly ariaRules?: readonly AriaRule[];
256
+ readonly allowedAs?: readonly ElementType[];
257
+ readonly precomputedClasses?: Readonly<Record<string, string>>;
258
+ };
259
+
260
+ type ResolveAriaFn = <P extends IntrinsicProps>(tag: ElementType, props: P) => {
261
+ props: P;
262
+ };
263
+
264
+ type ResolveClassNameFn<Props extends AnyRecord, TSlot extends string = never> = (tag: ElementType, props: Props, className?: ClassName, variantKey?: TSlot) => string;
265
+
266
+ type ResolvePropsFn<Props extends AnyRecord> = <P extends Partial<Props>>(props: P) => Simplify<Omit<Props, keyof P> & P>;
267
+
268
+ type ResolveTagFn<TDefault extends ElementType> = <T extends ElementType | undefined = undefined>(as?: T) => T extends ElementType ? T : TDefault;
269
+
270
+ type RuntimePluginField<TPlugin extends ClassPlugin | undefined> = TPlugin extends ClassPlugin ? {
271
+ readonly classPlugin: TPlugin;
272
+ readonly hasStyling: true;
273
+ } : EmptyRecord;
274
+
275
+ type PolymorphicRuntime<TDefault extends ElementType, Props extends AnyRecord, Variants extends VariantMap, TSlot extends string = never, TPreset extends PresetMap<Variants> = Readonly<Record<string, VariantSelection<Variants>>>, TPlugin extends ClassPlugin | undefined = ClassPlugin | undefined> = RuntimePluginField<TPlugin> & {
276
+ readonly options: Readonly<ResolvedFactoryOptions<TDefault, Props, Variants, TPreset>>;
277
+ readonly resolveTag: ResolveTagFn<TDefault>;
278
+ readonly resolveProps: ResolvePropsFn<Props>;
279
+ readonly resolveClasses: ResolveClassNameFn<Props, TSlot>;
280
+ readonly resolveAria: ResolveAriaFn;
281
+ };
282
+
283
+ declare abstract class StrictBase {
284
+ protected readonly strict: StrictMode;
285
+ constructor(strict: StrictMode);
286
+ protected violate(message: string): void;
287
+ protected warn(message: string): void;
288
+ protected invariant(condition: unknown, message: string): void;
289
+ }
290
+
291
+ declare class ChildrenEvaluator extends StrictBase {
292
+ #private;
293
+ constructor(rules: readonly ChildRuleInput[], strict?: StrictMode, context?: string);
294
+ evaluate(children: unknown[]): void;
295
+ }
296
+
297
+ declare const disabledProps: PropNormalizer;
298
+
299
+ declare const invalidProps: PropNormalizer;
300
+
301
+ declare function createPolymorphic<TDefault extends ElementType, Props extends AnyRecord, Variants extends Readonly<VariantMap>, TPreset extends PresetMap<Variants> = Readonly<EmptyRecord>>(options?: FactoryOptions<TDefault, Props, Variants, TPreset>): PolymorphicRuntime<TDefault, Props, Variants, Extract<keyof TPreset, string>, TPreset>;
302
+
303
+ declare class SlotValidator extends StrictBase {
304
+ #private;
305
+ constructor(name: string, strict: StrictMode, elementTerm: string);
306
+ assertExclusive(): void;
307
+ warnDiscardedChildren(count: number): void;
308
+ assertSingleChild(count: number): void;
309
+ }
310
+
311
+ type FilterPredicate = (key: string, variantKeys: ReadonlySet<string>) => boolean;
312
+
313
+ type BuiltChildrenEvaluator<TOptions extends WithChildRules> = TOptions extends {
314
+ enforcement: {
315
+ children: readonly unknown[];
316
+ };
317
+ } ? {
318
+ childrenEvaluator: ChildrenEvaluator;
319
+ } : EmptyRecord;
320
+
321
+ type UnknownProps = Record<string, unknown>;
322
+
323
+ type SvelteFactoryOptions<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> & {
324
+ /**
325
+ * Return true for any prop key that should be consumed but not forwarded to the DOM.
326
+ * Receives `runtime.options.variantKeys` as a convenience if needed.
327
+ */
328
+ filterProps?: (key: string, variantKeys: ReadonlySet<string>) => boolean;
329
+ };
330
+
331
+ type TypedRuntime<G extends PolymorphicGenerics> = ReturnType<typeof createPolymorphic<DefaultOf<G>, PropsOf<G>, VariantsOf<G>, PresetOf<G>>>;
332
+
333
+ type BuiltRuntime<G extends PolymorphicGenerics = PolymorphicGenerics, TOptions extends WithChildRules = WithChildRules> = BuiltChildrenEvaluator<TOptions> & {
334
+ runtime: TypedRuntime<G>;
335
+ filterProps: FilterPredicate;
336
+ slotValidator: SlotValidator;
337
+ };
338
+
339
+ 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, TOptions extends WithChildRules = SvelteFactoryOptions<TDefault, Props & TPluginProps, Variants, TPreset>>(options: SvelteFactoryOptions<TDefault, Props, Variants, TPreset, TPluginProps> & TOptions): BuiltRuntime<PolymorphicGenerics<TDefault, Props & TPluginProps, Variants, TPreset>, TOptions>;
340
+
341
+ declare function defineContractComponent<O extends FactoryOptions>(options: O): <R>(factory: (options: O) => R) => R;
342
+
343
+ export { type BuiltRuntime, type FilterPredicate, type SvelteFactoryOptions, type UnknownProps, type WithChildRules, createContractComponent, defineContractComponent, disabledProps, invalidProps };