praxis-kit 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,385 @@
1
- export { AnyFactoryOptions, PropNormalizer, activeProps, disabledProps, expandedProps, invalidProps, loadingProps, pressedProps, readonlyProps, selectedProps } from '@praxis-kit/core';
2
- export { activeContract, disabledContract, expandedContract, invalidContract, loadingContract, mergeContracts, pressedContract, readonlyContract, selectedContract } from '@praxis-kit/core/contract';
1
+ import { Except, RequireAtLeastOne, Simplify, ReadonlyDeep } from 'type-fest';
2
+
3
+ type StringMap<T = unknown> = Record<string, T>;
4
+ type AnyRecord = StringMap<unknown>;
5
+
6
+ type IntrinsicTag = keyof HTMLElementTagNameMap;
7
+
8
+ type ElementType = IntrinsicTag | (string & {});
9
+
10
+ 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"];
11
+ type KnownAriaRole = (typeof KNOWN_ARIA_ROLES)[number];
12
+
13
+ type Booleanish = boolean | 'true' | 'false';
14
+ type ClassName = string | string[];
15
+ type EmptyRecord = Record<never, never>;
16
+ type NonEmptyArray<T> = [T, ...T[]];
17
+ type Numberish = number | `${number}`;
18
+ type Primitive = string | number | boolean;
19
+ type AriaRole = KnownAriaRole | (string & {});
20
+ type IntrinsicProps = AnyRecord & {
21
+ role?: AriaRole;
22
+ };
23
+ type TagMap = Partial<Record<IntrinsicTag | (string & {}), ClassName>>;
24
+
25
+ declare enum DiagnosticCategory {
26
+ Contract = 0,
27
+ HTML = 1,
28
+ ARIA = 2,
29
+ Composition = 3,
30
+ Rendering = 4,
31
+ Accessibility = 5,
32
+ Performance = 6,
33
+ Internal = 7,
34
+ Deprecation = 8,
35
+ Lint = 9
36
+ }
37
+
38
+ declare enum DiagnosticCode {
39
+ MissingRequiredChild = "COMP1001",
40
+ InvalidParent = "COMP1002",
41
+ InvalidChild = "COMP1003",
42
+ UnexpectedChild = "COMP1004",
43
+ AmbiguousChild = "COMP1005",
44
+ CardinalityMin = "COMP1006",
45
+ CardinalityMax = "COMP1007",
46
+ PositionViolation = "COMP1008",
47
+ AllowedAsViolation = "COMP1009",
48
+ SlotExclusive = "SLOT1001",
49
+ SlotSingleChild = "SLOT1002",
50
+ SlotDiscardedChildren = "SLOT1003",
51
+ SlotRenderFn = "SLOT1004",
52
+ MissingAriaRelationship = "ARIA2001",
53
+ AriaViolation = "ARIA2002",
54
+ AriaAttributeInvalid = "ARIA2003",
55
+ AriaMissingLiveRegion = "ARIA2004",
56
+ AriaMissingAtomic = "ARIA2005",
57
+ AriaRelevantInvalidToken = "ARIA2006",
58
+ AriaRelevantSuperseded = "ARIA2007",
59
+ AriaInvalidRole = "ARIA2008",
60
+ AriaMissingAccessibleName = "ARIA2009",
61
+ AriaAttributeOnPresentational = "ARIA2010",
62
+ AriaHiddenOnFocusable = "ARIA2011",
63
+ AriaRequiredProperty = "ARIA2012",
64
+ AriaInvalidAttributeValue = "ARIA2013",
65
+ AriaRedundantLevelAttribute = "ARIA2014",
66
+ InvalidHeadingHierarchy = "HTML3001",
67
+ HtmlEmptyRole = "HTML3002",
68
+ HtmlImplicitRoleRedundant = "HTML3003",
69
+ HtmlImplicitRoleOverride = "HTML3004",
70
+ HtmlStandaloneRegionOverride = "HTML3005",
71
+ HtmlLandmarkRoleOverride = "HTML3006",
72
+ HtmlInvalidChild = "HTML3007",
73
+ InvalidRenderingTarget = "RENDER4001",
74
+ LintDeadCompoundKey = "LINT5001",
75
+ LintDeadCompoundValue = "LINT5002",
76
+ LintDeadCompoundNonLiteral = "LINT5003",
77
+ LintMissingStrict = "LINT5004",
78
+ LintInvalidDefaultKey = "LINT5005",
79
+ LintInvalidDefaultValue = "LINT5006",
80
+ LintInvalidDefaultNonLiteral = "LINT5007",
81
+ LintNegativeMin = "LINT5008",
82
+ LintNegativeMax = "LINT5009",
83
+ LintMaxLessThanMin = "LINT5010",
84
+ LintZeroMax = "LINT5011",
85
+ LintMultipleFirst = "LINT5012",
86
+ LintMultipleLast = "LINT5013",
87
+ LintMinSumExceedsCapacity = "LINT5014",
88
+ LintCardinalityViolation = "LINT5015",
89
+ LintAriaTagOverride = "LINT5016",
90
+ ContractUnknownVariantDim = "COMP1010",
91
+ ContractUnknownVariantValue = "COMP1011",
92
+ ContractUnknownRecipeKey = "COMP1012",
93
+ ContractInvalidVariantValue = "COMP1013",
94
+ TailwindMultipleDisplayProps = "CSS6001",
95
+ TailwindReservedLayoutLiteral = "CSS6002",
96
+ TailwindDeadVariantClass = "CSS6003",
97
+ PluginInvalidShape = "PLUGIN7001",
98
+ PluginPipelineReturnType = "PLUGIN7002",
99
+ InternalError = "INTERNAL9000"
100
+ }
101
+
102
+ interface SourcePosition {
103
+ line: number;
104
+ col: number;
105
+ }
106
+ interface SourceLocation {
107
+ file: string;
108
+ start: SourcePosition;
109
+ end?: SourcePosition;
110
+ }
111
+
112
+ declare enum Severity$1 {
113
+ Debug = 0,
114
+ Info = 1,
115
+ Warning = 2,
116
+ Error = 3,
117
+ Fatal = 4
118
+ }
119
+
120
+ interface DiagnosticSuggestion {
121
+ title: string;
122
+ description?: string;
123
+ fix?: string;
124
+ }
125
+
126
+ type Context = AnyRecord;
127
+ type Metadata = AnyRecord;
128
+ interface Diagnostic {
129
+ code: DiagnosticCode;
130
+ severity: Severity$1;
131
+ category: DiagnosticCategory;
132
+ message: string;
133
+ rationale?: string;
134
+ component?: string;
135
+ contract?: string;
136
+ location?: SourceLocation;
137
+ suggestions?: DiagnosticSuggestion[];
138
+ context?: Context;
139
+ metadata?: Metadata;
140
+ }
141
+
142
+ declare enum Enforcement {
143
+ Ignore = 0,
144
+ Report = 1,
145
+ Throw = 2
146
+ }
147
+ interface DiagnosticPolicy {
148
+ resolve(diagnostic: Diagnostic): Enforcement;
149
+ }
150
+
151
+ interface DiagnosticReporter {
152
+ report(diagnostic: Diagnostic): void;
153
+ }
154
+
155
+ type DiagnosticInput = Except<Diagnostic, 'severity'>;
156
+ declare class Diagnostics {
157
+ private readonly reporter;
158
+ private readonly policy;
159
+ readonly active: boolean;
160
+ constructor(reporter: DiagnosticReporter, policy?: DiagnosticPolicy);
161
+ report(diagnostic: Diagnostic): Diagnostic;
162
+ warn(input: DiagnosticInput): Diagnostic;
163
+ error(input: DiagnosticInput): Diagnostic;
164
+ info(input: DiagnosticInput): Diagnostic;
165
+ }
166
+
167
+ type MinMax = {
168
+ min: number;
169
+ max: number;
170
+ };
171
+ type CardinalityInput = Partial<MinMax>;
172
+
173
+ type ChildRuleMatch<T, U extends T = T> = (child: T) => child is U;
174
+
175
+ type ChildRulePosition = 'first' | 'last' | 'any';
176
+
177
+ type ChildRuleInput<T = unknown, U extends T = T> = {
178
+ name: string;
179
+ match: ChildRuleMatch<T, U>;
180
+ cardinality?: CardinalityInput;
181
+ position?: ChildRulePosition;
182
+ /**
183
+ * Optional component-type reference for O(1) dispatch index.
184
+ * When provided for every rule, the matcher reads child.type instead of
185
+ * calling every match function on every child (O(n×m) → O(n+m)).
186
+ */
187
+ type?: unknown;
188
+ };
189
+
190
+ type ValidResult = {
191
+ valid: true;
192
+ };
193
+
194
+ type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
195
+ type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
196
+ type CompoundVariantConditions<V extends VariantMap> = Simplify<{
197
+ [K in keyof V]: CompoundVariantConditionValue<V, K>;
198
+ }>;
199
+ type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
200
+ type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
201
+ type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
202
+ class: VariantValue;
203
+ };
204
+
205
+ interface CVACompounds<V extends VariantMap> {
206
+ compoundVariants?: readonly CompoundVariant<V>[];
207
+ }
208
+
209
+ interface CVADefaults<V extends VariantMap> {
210
+ defaultVariants?: DefaultVariants<V>;
211
+ }
212
+
213
+ interface CVAVariants<V extends VariantMap> {
214
+ variants?: V;
215
+ }
216
+
217
+ type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
218
+ type VariantValue = string | string[];
219
+ type VariantStates<K extends string = string> = Record<K, VariantValue>;
220
+ type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
221
+ type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
222
+ /**
223
+ * A partial selection of variant states authored at factory definition time.
224
+ *
225
+ * Uses `keyof V[K]` directly (not `VariantKey`) so TypeScript can eagerly
226
+ * resolve the union at constraint-check time without deferred conditional types.
227
+ */
228
+ type VariantSelection<V extends VariantMap> = {
229
+ [K in keyof V]?: keyof V[K];
230
+ };
231
+ type NormalizedVariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
232
+ type DefaultVariants<V extends VariantMap> = {
233
+ [K in keyof V]?: NormalizedVariantValue<keyof V[K] & string>;
234
+ };
235
+ /**
236
+ * A static, immutable map of named presets to partial variant selections.
237
+ *
238
+ * Presets are named bundles of variant props that callers activate by key,
239
+ * avoiding the need to repeat variant combinations at each call site.
240
+ */
241
+ type RecipeMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
242
+ type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
243
+
244
+ interface BaseClassOptions {
245
+ baseClassName?: ClassName;
246
+ }
247
+
248
+ type ClassPipelineFn = (tag: unknown, props: AnyRecord, className?: ClassName, recipe?: string) => string;
249
+
250
+ interface RecipeOptions<TVariants extends VariantMap = VariantMap> {
251
+ recipeMap?: Record<string, RecipeTarget<TVariants>>;
252
+ }
253
+
254
+ interface TagMapOptions {
255
+ tagMap?: TagMap;
256
+ }
257
+
258
+ type CompositionOptions<TVariants extends VariantMap = VariantMap> = Simplify<TagMapOptions & RecipeOptions<TVariants>>;
259
+
260
+ type CVASystemOptions<TVariants extends VariantMap = VariantMap> = Simplify<CVAVariants<TVariants> & CVADefaults<TVariants> & CVACompounds<TVariants>>;
261
+
262
+ type StyleOptions<TVariants extends VariantMap = VariantMap> = Simplify<BaseClassOptions & CVASystemOptions<TVariants>>;
263
+
264
+ type ClassPipelineOptions<TVariants extends VariantMap = VariantMap> = Simplify<StyleOptions<TVariants> & CompositionOptions<TVariants>>;
265
+
266
+ type OwnedPropKeys = ReadonlySet<string>;
267
+
268
+ type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
269
+ pipeline: ClassPipelineFn;
270
+ ownedKeys?: OwnedPropKeys;
271
+ readonly _pluginProps?: TProps;
272
+ }>;
273
+
274
+ type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, diagnostics: Diagnostics) => ClassPlugin<TProps>;
275
+
276
+ type AriaContext = {
277
+ readonly tag: IntrinsicTag;
278
+ readonly implicitRole: AriaRole | undefined;
279
+ readonly effectiveRole: string | undefined;
280
+ readonly props: ReadonlyDeep<IntrinsicProps>;
281
+ };
282
+
283
+ type RemoveAttributeFixKind = `removeAttribute:${string}`;
284
+ type InjectLiveFixKind = `injectLive:${string}`;
285
+ type FixKind = 'removeRole' | 'setRole' | 'normalizeRelevantAll' | RemoveAttributeFixKind | InjectLiveFixKind;
286
+
287
+ type AriaFixResult = {
288
+ applied: false;
289
+ next: ReadonlyDeep<IntrinsicProps>;
290
+ } | {
291
+ applied: true;
292
+ next: ReadonlyDeep<IntrinsicProps>;
293
+ previous: ReadonlyDeep<IntrinsicProps>;
294
+ };
295
+ type AriaFix = {
296
+ readonly kind: FixKind;
297
+ readonly priority?: number;
298
+ readonly source?: string;
299
+ readonly apply: (context: AriaContext) => AriaFixResult;
300
+ };
301
+
302
+ type Severity = 'error' | 'warning' | (string & {});
303
+
304
+ type AriaInvalidBase<M extends string = string> = {
305
+ valid: false;
306
+ severity: Severity;
307
+ message?: M;
308
+ attribute?: string;
309
+ diagnostic?: DiagnosticInput;
310
+ };
311
+ type AriaInvalidWithFix<M extends string = string> = AriaInvalidBase<M> & {
312
+ fixable: true;
313
+ fix: AriaFix;
314
+ };
315
+ type AriaInvalidWithoutFix<M extends string = string> = AriaInvalidBase<M> & {
316
+ fixable: false;
317
+ };
318
+ type AriaInvalidResult<M extends string = string> = AriaInvalidWithFix<M> | AriaInvalidWithoutFix<M>;
319
+ type AriaResult = ValidResult | AriaInvalidResult;
320
+
321
+ type AriaRule<C extends AriaContext = AriaContext> = (context: C) => readonly AriaResult[];
322
+
323
+ type PropNormalizer = (props: Readonly<AnyRecord & IntrinsicProps>) => Partial<AnyRecord & IntrinsicProps>;
324
+
325
+ type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
326
+ readonly diagnostics?: Diagnostics;
327
+ readonly aria?: readonly AriaRule[];
328
+ readonly children?: readonly ChildRuleInput[];
329
+ readonly props?: readonly PropNormalizer[];
330
+ /** Restricts the `as` prop to this set of tags. Violations route through diagnostics. */
331
+ readonly allowedAs?: readonly TAllowed[];
332
+ };
333
+
334
+ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined> = {
335
+ readonly base?: ClassName;
336
+ readonly variants?: V;
337
+ readonly defaults?: Partial<DefaultVariants<V>>;
338
+ readonly compounds?: readonly CompoundVariant<V>[];
339
+ readonly presets?: TPreset;
340
+ readonly tags?: Readonly<TagMap>;
341
+ readonly plugin?: TPlugin;
342
+ readonly precomputedClasses?: Readonly<Record<string, string>>;
343
+ };
344
+
345
+ type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
346
+ normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
347
+ }['normalize'];
348
+ type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, ClassPluginFactory<AnyRecord> | undefined>;
349
+ type FactoryOptions<TDefault extends ElementType = ElementType, Props extends AnyRecord = EmptyRecord, V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined, TAllowed extends ElementType = ElementType> = {
350
+ readonly tag?: TDefault;
351
+ readonly name?: string;
352
+ readonly defaults?: Partial<NoInfer<Props>>;
353
+ readonly normalize?: NormalizeFn<NoInfer<Props>>;
354
+ readonly styling?: StylingOptions<V, TPreset, TPlugin>;
355
+ readonly enforcement?: EnforcementOptions<TAllowed>;
356
+ };
357
+
358
+ declare const activeProps: PropNormalizer;
359
+
360
+ declare const disabledProps: PropNormalizer;
361
+
362
+ declare const expandedProps: PropNormalizer;
363
+
364
+ declare const invalidProps: PropNormalizer;
365
+
366
+ declare const loadingProps: PropNormalizer;
367
+
368
+ declare const pressedProps: PropNormalizer;
369
+
370
+ declare const readonlyProps: PropNormalizer;
371
+
372
+ declare const selectedProps: PropNormalizer;
373
+
374
+ declare const activeContract: EnforcementOptions;
375
+ declare const disabledContract: EnforcementOptions;
376
+ declare const expandedContract: EnforcementOptions;
377
+ declare const invalidContract: EnforcementOptions;
378
+ declare const loadingContract: EnforcementOptions;
379
+ declare const pressedContract: EnforcementOptions;
380
+ declare const readonlyContract: EnforcementOptions;
381
+ declare const selectedContract: EnforcementOptions;
382
+
383
+ declare function mergeContracts(...contracts: readonly EnforcementOptions[]): EnforcementOptions;
384
+
385
+ export { type AnyFactoryOptions, type PropNormalizer, activeContract, activeProps, disabledContract, disabledProps, expandedContract, expandedProps, invalidContract, invalidProps, loadingContract, loadingProps, mergeContracts, pressedContract, pressedProps, readonlyContract, readonlyProps, selectedContract, selectedProps };