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,7 +1,8 @@
1
- import { RequireAtLeastOne, Simplify, ReadonlyDeep, OmitIndexSignature } from 'type-fest';
1
+ import { Except, RequireAtLeastOne, Simplify, ReadonlyDeep, OmitIndexSignature } from 'type-fest';
2
2
  import { JSX } from 'solid-js';
3
3
 
4
- type AnyRecord = Record<string, unknown>;
4
+ type StringMap<T = unknown> = Record<string, T>;
5
+ type AnyRecord = StringMap<unknown>;
5
6
 
6
7
  type IntrinsicTag = keyof HTMLElementTagNameMap;
7
8
 
@@ -10,32 +11,165 @@ 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"];
11
12
  type KnownAriaRole = (typeof KNOWN_ARIA_ROLES)[number];
12
13
 
13
- type AriaRole = KnownAriaRole | (string & {});
14
-
15
14
  type Booleanish = boolean | 'true' | 'false';
16
-
17
15
  type ClassName = string | string[];
18
-
19
16
  type EmptyRecord = Record<never, never>;
20
-
17
+ type NonEmptyArray<T> = [T, ...T[]];
18
+ type Numberish = number | `${number}`;
19
+ type Primitive = string | number | boolean;
20
+ type AriaRole = KnownAriaRole | (string & {});
21
21
  type IntrinsicProps = AnyRecord & {
22
22
  role?: AriaRole;
23
23
  };
24
+ type TagMap = Partial<Record<IntrinsicTag | (string & {}), ClassName>>;
24
25
 
25
- type NonEmptyArray<T> = [T, ...T[]];
26
+ declare enum DiagnosticCategory {
27
+ Contract = 0,
28
+ HTML = 1,
29
+ ARIA = 2,
30
+ Composition = 3,
31
+ Rendering = 4,
32
+ Accessibility = 5,
33
+ Performance = 6,
34
+ Internal = 7,
35
+ Deprecation = 8,
36
+ Lint = 9
37
+ }
26
38
 
27
- type Numberish = number | `${number}`;
39
+ declare enum DiagnosticCode {
40
+ MissingRequiredChild = "COMP1001",
41
+ InvalidParent = "COMP1002",
42
+ InvalidChild = "COMP1003",
43
+ UnexpectedChild = "COMP1004",
44
+ AmbiguousChild = "COMP1005",
45
+ CardinalityMin = "COMP1006",
46
+ CardinalityMax = "COMP1007",
47
+ PositionViolation = "COMP1008",
48
+ AllowedAsViolation = "COMP1009",
49
+ SlotExclusive = "SLOT1001",
50
+ SlotSingleChild = "SLOT1002",
51
+ SlotDiscardedChildren = "SLOT1003",
52
+ SlotRenderFn = "SLOT1004",
53
+ MissingAriaRelationship = "ARIA2001",
54
+ AriaViolation = "ARIA2002",
55
+ AriaAttributeInvalid = "ARIA2003",
56
+ AriaMissingLiveRegion = "ARIA2004",
57
+ AriaMissingAtomic = "ARIA2005",
58
+ AriaRelevantInvalidToken = "ARIA2006",
59
+ AriaRelevantSuperseded = "ARIA2007",
60
+ AriaInvalidRole = "ARIA2008",
61
+ AriaMissingAccessibleName = "ARIA2009",
62
+ AriaAttributeOnPresentational = "ARIA2010",
63
+ AriaHiddenOnFocusable = "ARIA2011",
64
+ AriaRequiredProperty = "ARIA2012",
65
+ AriaInvalidAttributeValue = "ARIA2013",
66
+ AriaRedundantLevelAttribute = "ARIA2014",
67
+ InvalidHeadingHierarchy = "HTML3001",
68
+ HtmlEmptyRole = "HTML3002",
69
+ HtmlImplicitRoleRedundant = "HTML3003",
70
+ HtmlImplicitRoleOverride = "HTML3004",
71
+ HtmlStandaloneRegionOverride = "HTML3005",
72
+ HtmlLandmarkRoleOverride = "HTML3006",
73
+ HtmlInvalidChild = "HTML3007",
74
+ InvalidRenderingTarget = "RENDER4001",
75
+ LintDeadCompoundKey = "LINT5001",
76
+ LintDeadCompoundValue = "LINT5002",
77
+ LintDeadCompoundNonLiteral = "LINT5003",
78
+ LintMissingStrict = "LINT5004",
79
+ LintInvalidDefaultKey = "LINT5005",
80
+ LintInvalidDefaultValue = "LINT5006",
81
+ LintInvalidDefaultNonLiteral = "LINT5007",
82
+ LintNegativeMin = "LINT5008",
83
+ LintNegativeMax = "LINT5009",
84
+ LintMaxLessThanMin = "LINT5010",
85
+ LintZeroMax = "LINT5011",
86
+ LintMultipleFirst = "LINT5012",
87
+ LintMultipleLast = "LINT5013",
88
+ LintMinSumExceedsCapacity = "LINT5014",
89
+ LintCardinalityViolation = "LINT5015",
90
+ LintAriaTagOverride = "LINT5016",
91
+ ContractUnknownVariantDim = "COMP1010",
92
+ ContractUnknownVariantValue = "COMP1011",
93
+ ContractUnknownRecipeKey = "COMP1012",
94
+ ContractInvalidVariantValue = "COMP1013",
95
+ TailwindMultipleDisplayProps = "CSS6001",
96
+ TailwindReservedLayoutLiteral = "CSS6002",
97
+ TailwindDeadVariantClass = "CSS6003",
98
+ PluginInvalidShape = "PLUGIN7001",
99
+ PluginPipelineReturnType = "PLUGIN7002",
100
+ InternalError = "INTERNAL9000"
101
+ }
28
102
 
29
- type Primitive = string | number | boolean;
103
+ interface SourcePosition {
104
+ line: number;
105
+ col: number;
106
+ }
107
+ interface SourceLocation {
108
+ file: string;
109
+ start: SourcePosition;
110
+ end?: SourcePosition;
111
+ }
30
112
 
31
- type TagMap = Partial<Record<IntrinsicTag | (string & {}), ClassName>>;
113
+ declare enum Severity$1 {
114
+ Debug = 0,
115
+ Info = 1,
116
+ Warning = 2,
117
+ Error = 3,
118
+ Fatal = 4
119
+ }
120
+
121
+ interface DiagnosticSuggestion {
122
+ title: string;
123
+ description?: string;
124
+ fix?: string;
125
+ }
126
+
127
+ type Context = AnyRecord;
128
+ type Metadata = AnyRecord;
129
+ interface Diagnostic {
130
+ code: DiagnosticCode;
131
+ severity: Severity$1;
132
+ category: DiagnosticCategory;
133
+ message: string;
134
+ rationale?: string;
135
+ component?: string;
136
+ contract?: string;
137
+ location?: SourceLocation;
138
+ suggestions?: DiagnosticSuggestion[];
139
+ context?: Context;
140
+ metadata?: Metadata;
141
+ }
142
+
143
+ declare enum Enforcement {
144
+ Ignore = 0,
145
+ Report = 1,
146
+ Throw = 2
147
+ }
148
+ interface DiagnosticPolicy {
149
+ resolve(diagnostic: Diagnostic): Enforcement;
150
+ }
151
+
152
+ interface DiagnosticReporter {
153
+ report(diagnostic: Diagnostic): void;
154
+ }
32
155
 
33
- type StrictMode = boolean | 'warn' | 'async-warn' | 'throw';
156
+ type DiagnosticInput = Except<Diagnostic, 'severity'>;
157
+ declare class Diagnostics {
158
+ private readonly reporter;
159
+ private readonly policy;
160
+ readonly active: boolean;
161
+ constructor(reporter: DiagnosticReporter, policy?: DiagnosticPolicy);
162
+ report(diagnostic: Diagnostic): Diagnostic;
163
+ warn(input: DiagnosticInput): Diagnostic;
164
+ error(input: DiagnosticInput): Diagnostic;
165
+ info(input: DiagnosticInput): Diagnostic;
166
+ }
34
167
 
35
- type CardinalityInput = {
36
- min?: number;
37
- max?: number;
168
+ type MinMax = {
169
+ min: number;
170
+ max: number;
38
171
  };
172
+ type CardinalityInput = Partial<MinMax>;
39
173
 
40
174
  type ChildRuleMatch<T, U extends T = T> = (child: T) => child is U;
41
175
 
@@ -58,16 +192,6 @@ type ValidResult = {
58
192
  valid: true;
59
193
  };
60
194
 
61
- type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
62
-
63
- type VariantValue$1 = string | string[];
64
-
65
- type VariantStates<K extends string = string> = Record<K, VariantValue$1>;
66
-
67
- type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
68
-
69
- type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
70
-
71
195
  type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
72
196
  type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
73
197
  type CompoundVariantConditions<V extends VariantMap> = Simplify<{
@@ -76,22 +200,13 @@ type CompoundVariantConditions<V extends VariantMap> = Simplify<{
76
200
  type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
77
201
  type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
78
202
  type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
79
- class: VariantValue$1;
203
+ class: VariantValue;
80
204
  };
81
205
 
82
206
  interface CVACompounds<V extends VariantMap> {
83
207
  compoundVariants?: readonly CompoundVariant<V>[];
84
208
  }
85
209
 
86
- /** The full optional prop surface exposed to callers for a given variant map. */
87
- type VariantProps<V extends VariantMap> = {
88
- [K in keyof V]?: VariantKey<V, K>;
89
- };
90
- type VariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
91
- type DefaultVariants<V extends VariantMap> = {
92
- [K in keyof V]?: VariantValue<keyof V[K] & string>;
93
- };
94
-
95
210
  interface CVADefaults<V extends VariantMap> {
96
211
  defaultVariants?: DefaultVariants<V>;
97
212
  }
@@ -100,6 +215,11 @@ interface CVAVariants<V extends VariantMap> {
100
215
  variants?: V;
101
216
  }
102
217
 
218
+ type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
219
+ type VariantValue = string | string[];
220
+ type VariantStates<K extends string = string> = Record<K, VariantValue>;
221
+ type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
222
+ type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
103
223
  /**
104
224
  * A partial selection of variant states authored at factory definition time.
105
225
  *
@@ -109,7 +229,14 @@ interface CVAVariants<V extends VariantMap> {
109
229
  type VariantSelection<V extends VariantMap> = {
110
230
  [K in keyof V]?: keyof V[K];
111
231
  };
112
-
232
+ /** The full optional prop surface exposed to callers for a given variant map. */
233
+ type VariantProps<V extends VariantMap> = {
234
+ [K in keyof V]?: VariantKey<V, K>;
235
+ };
236
+ type NormalizedVariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
237
+ type DefaultVariants<V extends VariantMap> = {
238
+ [K in keyof V]?: NormalizedVariantValue<keyof V[K] & string>;
239
+ };
113
240
  /**
114
241
  * A static, immutable map of named presets to partial variant selections.
115
242
  *
@@ -117,7 +244,7 @@ type VariantSelection<V extends VariantMap> = {
117
244
  * avoiding the need to repeat variant combinations at each call site.
118
245
  */
119
246
  type RecipeMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
120
-
247
+ type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
121
248
  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> {
122
249
  default: TDefault;
123
250
  props: Props;
@@ -127,8 +254,8 @@ interface PolymorphicGenerics<TDefault extends ElementType = ElementType, Props
127
254
  }
128
255
  type VariantsOf<T extends PolymorphicGenerics> = T['variants'];
129
256
  type RecipeOf<T extends PolymorphicGenerics> = T['preset'];
130
-
131
- type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
257
+ type DefaultOf<T extends PolymorphicGenerics> = T['default'];
258
+ type PropsOf<T extends PolymorphicGenerics> = T['props'];
132
259
 
133
260
  interface BaseClassOptions {
134
261
  baseClassName?: ClassName;
@@ -160,7 +287,7 @@ type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
160
287
  readonly _pluginProps?: TProps;
161
288
  }>;
162
289
 
163
- type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, strict: StrictMode) => ClassPlugin<TProps>;
290
+ type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, diagnostics: Diagnostics) => ClassPlugin<TProps>;
164
291
  type ExtractPluginProps<TPlugin extends ClassPluginFactory<AnyRecord> | undefined> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? EmptyRecord : T : EmptyRecord;
165
292
 
166
293
  type AriaContext = {
@@ -194,8 +321,9 @@ type Severity = 'error' | 'warning' | (string & {});
194
321
  type AriaInvalidBase<M extends string = string> = {
195
322
  valid: false;
196
323
  severity: Severity;
197
- message: M;
324
+ message?: M;
198
325
  attribute?: string;
326
+ diagnostic?: DiagnosticInput;
199
327
  };
200
328
  type AriaInvalidWithFix<M extends string = string> = AriaInvalidBase<M> & {
201
329
  fixable: true;
@@ -212,11 +340,11 @@ type AriaRule<C extends AriaContext = AriaContext> = (context: C) => readonly Ar
212
340
  type PropNormalizer = (props: Readonly<AnyRecord & IntrinsicProps>) => Partial<AnyRecord & IntrinsicProps>;
213
341
 
214
342
  type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
215
- readonly strict?: StrictMode;
343
+ readonly diagnostics?: Diagnostics;
216
344
  readonly aria?: readonly AriaRule[];
217
345
  readonly children?: readonly ChildRuleInput[];
218
346
  readonly props?: readonly PropNormalizer[];
219
- /** Restricts the `as` prop to this set of tags. Violations route through strict mode. */
347
+ /** Restricts the `as` prop to this set of tags. Violations route through diagnostics. */
220
348
  readonly allowedAs?: readonly TAllowed[];
221
349
  };
222
350
 
@@ -244,9 +372,6 @@ type FactoryOptions<TDefault extends ElementType = ElementType, Props extends An
244
372
  readonly enforcement?: EnforcementOptions<TAllowed>;
245
373
  };
246
374
 
247
- type DefaultOf<T extends PolymorphicGenerics> = T['default'];
248
- type PropsOf<T extends PolymorphicGenerics> = T['props'];
249
-
250
375
  declare function defineContractComponent<O extends FactoryOptions>(options: O): <R>(factory: (options: O) => R) => R;
251
376
 
252
377
  type UnknownProps = Record<string, unknown>;