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