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 } from 'type-fest';
1
+ import { Except, RequireAtLeastOne, Simplify, ReadonlyDeep } from 'type-fest';
2
2
  import { LitElement } from 'lit';
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
+ }
32
126
 
33
- type StrictMode = boolean | 'warn' | 'async-warn' | 'throw';
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
+ }
34
142
 
35
- type CardinalityInput = {
36
- min?: number;
37
- max?: number;
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
+ }
155
+
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
+ }
167
+
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,18 +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
- type VariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
87
- type DefaultVariants<V extends VariantMap> = {
88
- [K in keyof V]?: VariantValue<keyof V[K] & string>;
89
- };
90
-
91
210
  interface CVADefaults<V extends VariantMap> {
92
211
  defaultVariants?: DefaultVariants<V>;
93
212
  }
@@ -96,6 +215,11 @@ interface CVAVariants<V extends VariantMap> {
96
215
  variants?: V;
97
216
  }
98
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>;
99
223
  /**
100
224
  * A partial selection of variant states authored at factory definition time.
101
225
  *
@@ -105,7 +229,10 @@ interface CVAVariants<V extends VariantMap> {
105
229
  type VariantSelection<V extends VariantMap> = {
106
230
  [K in keyof V]?: keyof V[K];
107
231
  };
108
-
232
+ type NormalizedVariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
233
+ type DefaultVariants<V extends VariantMap> = {
234
+ [K in keyof V]?: NormalizedVariantValue<keyof V[K] & string>;
235
+ };
109
236
  /**
110
237
  * A static, immutable map of named presets to partial variant selections.
111
238
  *
@@ -113,7 +240,6 @@ type VariantSelection<V extends VariantMap> = {
113
240
  * avoiding the need to repeat variant combinations at each call site.
114
241
  */
115
242
  type RecipeMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
116
-
117
243
  type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
118
244
 
119
245
  interface BaseClassOptions {
@@ -146,7 +272,7 @@ type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
146
272
  readonly _pluginProps?: TProps;
147
273
  }>;
148
274
 
149
- type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, strict: StrictMode) => ClassPlugin<TProps>;
275
+ type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, diagnostics: Diagnostics) => ClassPlugin<TProps>;
150
276
  type ExtractPluginProps<TPlugin extends ClassPluginFactory<AnyRecord> | undefined> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? EmptyRecord : T : EmptyRecord;
151
277
 
152
278
  type AriaContext = {
@@ -180,8 +306,9 @@ type Severity = 'error' | 'warning' | (string & {});
180
306
  type AriaInvalidBase<M extends string = string> = {
181
307
  valid: false;
182
308
  severity: Severity;
183
- message: M;
309
+ message?: M;
184
310
  attribute?: string;
311
+ diagnostic?: DiagnosticInput;
185
312
  };
186
313
  type AriaInvalidWithFix<M extends string = string> = AriaInvalidBase<M> & {
187
314
  fixable: true;
@@ -198,11 +325,11 @@ type AriaRule<C extends AriaContext = AriaContext> = (context: C) => readonly Ar
198
325
  type PropNormalizer = (props: Readonly<AnyRecord & IntrinsicProps>) => Partial<AnyRecord & IntrinsicProps>;
199
326
 
200
327
  type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
201
- readonly strict?: StrictMode;
328
+ readonly diagnostics?: Diagnostics;
202
329
  readonly aria?: readonly AriaRule[];
203
330
  readonly children?: readonly ChildRuleInput[];
204
331
  readonly props?: readonly PropNormalizer[];
205
- /** Restricts the `as` prop to this set of tags. Violations route through strict mode. */
332
+ /** Restricts the `as` prop to this set of tags. Violations route through diagnostics. */
206
333
  readonly allowedAs?: readonly TAllowed[];
207
334
  };
208
335