praxis-kit 3.1.1 → 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,6 +1,7 @@
1
- import { RequireAtLeastOne, Simplify, ReadonlyDeep } from 'type-fest';
1
+ import { Except, RequireAtLeastOne, Simplify, ReadonlyDeep } from 'type-fest';
2
2
 
3
- type AnyRecord = Record<string, unknown>;
3
+ type StringMap<T = unknown> = Record<string, T>;
4
+ type AnyRecord = StringMap<unknown>;
4
5
 
5
6
  type IntrinsicTag = keyof HTMLElementTagNameMap;
6
7
 
@@ -9,32 +10,165 @@ 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"];
10
11
  type KnownAriaRole = (typeof KNOWN_ARIA_ROLES)[number];
11
12
 
12
- type AriaRole = KnownAriaRole | (string & {});
13
-
14
13
  type Booleanish = boolean | 'true' | 'false';
15
-
16
14
  type ClassName = string | string[];
17
-
18
15
  type EmptyRecord = Record<never, never>;
19
-
16
+ type NonEmptyArray<T> = [T, ...T[]];
17
+ type Numberish = number | `${number}`;
18
+ type Primitive = string | number | boolean;
19
+ type AriaRole = KnownAriaRole | (string & {});
20
20
  type IntrinsicProps = AnyRecord & {
21
21
  role?: AriaRole;
22
22
  };
23
+ type TagMap = Partial<Record<IntrinsicTag | (string & {}), ClassName>>;
23
24
 
24
- type NonEmptyArray<T> = [T, ...T[]];
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
+ }
25
37
 
26
- type Numberish = number | `${number}`;
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
+ }
27
101
 
28
- type Primitive = string | number | boolean;
102
+ interface SourcePosition {
103
+ line: number;
104
+ col: number;
105
+ }
106
+ interface SourceLocation {
107
+ file: string;
108
+ start: SourcePosition;
109
+ end?: SourcePosition;
110
+ }
29
111
 
30
- type TagMap = Partial<Record<IntrinsicTag | (string & {}), ClassName>>;
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
+ }
31
154
 
32
- type StrictMode = boolean | 'warn' | 'async-warn' | 'throw';
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
+ }
33
166
 
34
- type CardinalityInput = {
35
- min?: number;
36
- max?: number;
167
+ type MinMax = {
168
+ min: number;
169
+ max: number;
37
170
  };
171
+ type CardinalityInput = Partial<MinMax>;
38
172
 
39
173
  type ChildRuleMatch<T, U extends T = T> = (child: T) => child is U;
40
174
 
@@ -63,16 +197,6 @@ type ValidResult = {
63
197
  valid: true;
64
198
  };
65
199
 
66
- type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
67
-
68
- type VariantValue$1 = string | string[];
69
-
70
- type VariantStates<K extends string = string> = Record<K, VariantValue$1>;
71
-
72
- type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
73
-
74
- type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
75
-
76
200
  type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
77
201
  type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
78
202
  type CompoundVariantConditions<V extends VariantMap> = Simplify<{
@@ -81,18 +205,13 @@ type CompoundVariantConditions<V extends VariantMap> = Simplify<{
81
205
  type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
82
206
  type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
83
207
  type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
84
- class: VariantValue$1;
208
+ class: VariantValue;
85
209
  };
86
210
 
87
211
  interface CVACompounds<V extends VariantMap> {
88
212
  compoundVariants?: readonly CompoundVariant<V>[];
89
213
  }
90
214
 
91
- type VariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
92
- type DefaultVariants<V extends VariantMap> = {
93
- [K in keyof V]?: VariantValue<keyof V[K] & string>;
94
- };
95
-
96
215
  interface CVADefaults<V extends VariantMap> {
97
216
  defaultVariants?: DefaultVariants<V>;
98
217
  }
@@ -101,6 +220,11 @@ interface CVAVariants<V extends VariantMap> {
101
220
  variants?: V;
102
221
  }
103
222
 
223
+ type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
224
+ type VariantValue = string | string[];
225
+ type VariantStates<K extends string = string> = Record<K, VariantValue>;
226
+ type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
227
+ type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
104
228
  /**
105
229
  * A partial selection of variant states authored at factory definition time.
106
230
  *
@@ -110,7 +234,10 @@ interface CVAVariants<V extends VariantMap> {
110
234
  type VariantSelection<V extends VariantMap> = {
111
235
  [K in keyof V]?: keyof V[K];
112
236
  };
113
-
237
+ type NormalizedVariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
238
+ type DefaultVariants<V extends VariantMap> = {
239
+ [K in keyof V]?: NormalizedVariantValue<keyof V[K] & string>;
240
+ };
114
241
  /**
115
242
  * A static, immutable map of named presets to partial variant selections.
116
243
  *
@@ -118,7 +245,7 @@ type VariantSelection<V extends VariantMap> = {
118
245
  * avoiding the need to repeat variant combinations at each call site.
119
246
  */
120
247
  type RecipeMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
121
-
248
+ type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
122
249
  interface PolymorphicGenerics<TDefault extends ElementType = ElementType, Props extends AnyRecord = AnyRecord, Variants extends Readonly<VariantMap> = Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TAllowed extends ElementType = ElementType> {
123
250
  default: TDefault;
124
251
  props: Props;
@@ -127,8 +254,6 @@ interface PolymorphicGenerics<TDefault extends ElementType = ElementType, Props
127
254
  allowed: TAllowed;
128
255
  }
129
256
 
130
- type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
131
-
132
257
  interface BaseClassOptions {
133
258
  baseClassName?: ClassName;
134
259
  }
@@ -159,7 +284,7 @@ type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
159
284
  readonly _pluginProps?: TProps;
160
285
  }>;
161
286
 
162
- type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, strict: StrictMode) => ClassPlugin<TProps>;
287
+ type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, diagnostics: Diagnostics) => ClassPlugin<TProps>;
163
288
  type ExtractPluginProps<TPlugin extends ClassPluginFactory<AnyRecord> | undefined> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? EmptyRecord : T : EmptyRecord;
164
289
  type PluginInstance<TPlugin extends ClassPluginFactory<AnyRecord> | undefined> = TPlugin extends ClassPluginFactory<infer TProps> ? ClassPlugin<TProps> : undefined;
165
290
 
@@ -194,8 +319,9 @@ type Severity = 'error' | 'warning' | (string & {});
194
319
  type AriaInvalidBase<M extends string = string> = {
195
320
  valid: false;
196
321
  severity: Severity;
197
- message: M;
322
+ message?: M;
198
323
  attribute?: string;
324
+ diagnostic?: DiagnosticInput;
199
325
  };
200
326
  type AriaInvalidWithFix<M extends string = string> = AriaInvalidBase<M> & {
201
327
  fixable: true;
@@ -212,11 +338,11 @@ type AriaRule<C extends AriaContext = AriaContext> = (context: C) => readonly Ar
212
338
  type PropNormalizer = (props: Readonly<AnyRecord & IntrinsicProps>) => Partial<AnyRecord & IntrinsicProps>;
213
339
 
214
340
  type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
215
- readonly strict?: StrictMode;
341
+ readonly diagnostics?: Diagnostics;
216
342
  readonly aria?: readonly AriaRule[];
217
343
  readonly children?: readonly ChildRuleInput[];
218
344
  readonly props?: readonly PropNormalizer[];
219
- /** Restricts the `as` prop to this set of tags. Violations route through strict mode. */
345
+ /** Restricts the `as` prop to this set of tags. Violations route through diagnostics. */
220
346
  readonly allowedAs?: readonly TAllowed[];
221
347
  };
222
348
 
@@ -254,7 +380,7 @@ type ResolvedFactoryOptions<TDefault extends ElementType = ElementType, Props ex
254
380
  readonly defaultVariants?: Partial<DefaultVariants<V>>;
255
381
  readonly compoundVariants?: readonly CompoundVariant<V>[];
256
382
  readonly displayName?: string;
257
- readonly strict: StrictMode;
383
+ readonly diagnostics: Diagnostics;
258
384
  readonly variantKeys: ReadonlySet<string>;
259
385
  readonly normalizeFn?: NormalizeFn<Props>;
260
386
  readonly htmlPropNormalizersFn?: (tag: unknown) => readonly PropNormalizer[] | undefined;
@@ -287,25 +413,26 @@ type PolymorphicRuntime<TDefault extends ElementType, Props extends AnyRecord, V
287
413
  readonly resolveAria: ResolveAriaFn;
288
414
  };
289
415
 
290
- declare abstract class StrictBase {
291
- protected readonly strict: StrictMode;
292
- constructor(strict: StrictMode);
293
- protected violate(message: string): void;
294
- protected warn(message: string): void;
295
- protected invariant(condition: unknown, message: string): void;
416
+ declare abstract class InvariantBase {
417
+ private readonly diagnostics;
418
+ constructor(diagnostics: Diagnostics);
419
+ protected get active(): boolean;
420
+ protected violate(input: DiagnosticInput): void;
421
+ protected warn(input: DiagnosticInput): void;
422
+ protected invariant(condition: unknown, input: DiagnosticInput): void;
296
423
  }
297
424
 
298
- declare class ChildrenEvaluator extends StrictBase {
425
+ declare class ChildrenEvaluator extends InvariantBase {
299
426
  #private;
300
- constructor(rules: readonly ChildRuleInput[], strict?: StrictMode, context?: string);
427
+ constructor(rules: readonly ChildRuleInput[], diagnostics: Diagnostics, context?: string);
301
428
  evaluate(children: unknown[]): void;
302
429
  }
303
430
 
304
431
  declare function createPolymorphic<TDefault extends ElementType, Props extends AnyRecord, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined>(options?: FactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicRuntime<TDefault, Props, Variants, Extract<keyof TPreset, string>, TPreset, PluginInstance<TPlugin>>;
305
432
 
306
- declare class SlotValidator extends StrictBase {
433
+ declare class SlotValidator extends InvariantBase {
307
434
  #private;
308
- constructor(name: string, strict: StrictMode, elementTerm: string);
435
+ constructor(name: string, diagnostics: Diagnostics, elementTerm: string);
309
436
  assertExclusive(): void;
310
437
  warnDiscardedChildren(count: number): void;
311
438
  assertSingleChild(count: number): void;