praxis-kit 4.0.1 → 4.1.0

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,9 +1,11 @@
1
- import { Except, RequireAtLeastOne, Simplify, ReadonlyDeep } from 'type-fest';
1
+ import { RequireAtLeastOne, Simplify, ReadonlyDeep } from 'type-fest';
2
+ import { Diagnostics, DiagnosticInput } from '../_shared/diagnostics.js';
2
3
  import * as vue from 'vue';
3
4
  import { AllowedComponentProps } from 'vue';
4
5
 
5
6
  type StringMap<T = unknown> = Record<string, T>;
6
7
  type AnyRecord = StringMap<unknown>;
8
+ type EmptyRecord = Record<never, never>;
7
9
 
8
10
  type IntrinsicTag = keyof HTMLElementTagNameMap;
9
11
 
@@ -14,7 +16,6 @@ type KnownAriaRole = (typeof KNOWN_ARIA_ROLES)[number];
14
16
 
15
17
  type Booleanish = boolean | 'true' | 'false';
16
18
  type ClassName = string | string[];
17
- type EmptyRecord = Record<never, never>;
18
19
  type NonEmptyArray<T> = [T, ...T[]];
19
20
  type Numberish = number | `${number}`;
20
21
  type Primitive = string | number | boolean;
@@ -24,148 +25,6 @@ type IntrinsicProps = AnyRecord & {
24
25
  };
25
26
  type TagMap = Partial<Record<IntrinsicTag | (string & {}), ClassName>>;
26
27
 
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
- }
39
-
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
- }
103
-
104
- interface SourcePosition {
105
- line: number;
106
- col: number;
107
- }
108
- interface SourceLocation {
109
- file: string;
110
- start: SourcePosition;
111
- end?: SourcePosition;
112
- }
113
-
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
- }
127
-
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
- }
156
-
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
28
  type MinMax = {
170
29
  min: number;
171
30
  max: number;
@@ -193,34 +52,16 @@ type ValidResult = {
193
52
  valid: true;
194
53
  };
195
54
 
196
- type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
197
- type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
198
- type CompoundVariantConditions<V extends VariantMap> = Simplify<{
199
- [K in keyof V]: CompoundVariantConditionValue<V, K>;
200
- }>;
201
- type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
202
- type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
203
- type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
204
- class: VariantValue;
205
- };
206
-
207
- interface CVACompounds<V extends VariantMap> {
208
- compoundVariants?: readonly CompoundVariant<V>[];
209
- }
210
-
211
- interface CVADefaults<V extends VariantMap> {
212
- defaultVariants?: DefaultVariants<V>;
213
- }
214
-
215
- interface CVAVariants<V extends VariantMap> {
216
- variants?: V;
217
- }
218
-
219
55
  type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
56
+
220
57
  type VariantValue = string | string[];
58
+
221
59
  type VariantStates<K extends string = string> = Record<K, VariantValue>;
60
+
222
61
  type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
62
+
223
63
  type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
64
+
224
65
  /**
225
66
  * A partial selection of variant states authored at factory definition time.
226
67
  *
@@ -230,14 +71,17 @@ type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof
230
71
  type VariantSelection<V extends VariantMap> = {
231
72
  [K in keyof V]?: keyof V[K];
232
73
  };
74
+
233
75
  /** The full optional prop surface exposed to callers for a given variant map. */
234
76
  type VariantProps<V extends VariantMap> = {
235
77
  [K in keyof V]?: VariantKey<V, K>;
236
78
  };
79
+
237
80
  type NormalizedVariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
238
81
  type DefaultVariants<V extends VariantMap> = {
239
82
  [K in keyof V]?: NormalizedVariantValue<keyof V[K] & string>;
240
83
  };
84
+
241
85
  /**
242
86
  * A static, immutable map of named presets to partial variant selections.
243
87
  *
@@ -245,7 +89,9 @@ type DefaultVariants<V extends VariantMap> = {
245
89
  * avoiding the need to repeat variant combinations at each call site.
246
90
  */
247
91
  type RecipeMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
92
+
248
93
  type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
94
+
249
95
  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> {
250
96
  default: TDefault;
251
97
  props: Props;
@@ -258,6 +104,29 @@ type RecipeOf<T extends PolymorphicGenerics> = T['preset'];
258
104
  type DefaultOf<T extends PolymorphicGenerics> = T['default'];
259
105
  type PropsOf<T extends PolymorphicGenerics> = T['props'];
260
106
 
107
+ type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
108
+ type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
109
+ type CompoundVariantConditions<V extends VariantMap> = Simplify<{
110
+ [K in keyof V]: CompoundVariantConditionValue<V, K>;
111
+ }>;
112
+ type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
113
+ type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
114
+ type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
115
+ class: VariantValue;
116
+ };
117
+
118
+ interface CVACompounds<V extends VariantMap> {
119
+ compoundVariants?: readonly CompoundVariant<V>[];
120
+ }
121
+
122
+ interface CVADefaults<V extends VariantMap> {
123
+ defaultVariants?: DefaultVariants<V>;
124
+ }
125
+
126
+ interface CVAVariants<V extends VariantMap> {
127
+ variants?: V;
128
+ }
129
+
261
130
  interface BaseClassOptions {
262
131
  baseClassName?: ClassName;
263
132
  }
@@ -289,7 +158,11 @@ type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
289
158
  }>;
290
159
 
291
160
  type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, diagnostics: Diagnostics) => ClassPlugin<TProps>;
292
- type ExtractPluginProps<TPlugin extends ClassPluginFactory<AnyRecord> | undefined> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? EmptyRecord : T : EmptyRecord;
161
+ /** `ClassPluginFactory` with its plugin-owned-props generic erased the common form used
162
+ * wherever a factory's concrete plugin-props shape isn't tracked (factory generics,
163
+ * capability wiring). */
164
+ type AnyClassPluginFactory = ClassPluginFactory<AnyRecord> | undefined;
165
+ type ExtractPluginProps<TPlugin extends AnyClassPluginFactory> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? EmptyRecord : T : EmptyRecord;
293
166
 
294
167
  type AriaContext = {
295
168
  readonly tag: IntrinsicTag;
@@ -349,7 +222,7 @@ type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
349
222
  readonly allowedAs?: readonly TAllowed[];
350
223
  };
351
224
 
352
- type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined> = {
225
+ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory> = {
353
226
  readonly base?: ClassName;
354
227
  readonly variants?: V;
355
228
  readonly defaults?: Partial<DefaultVariants<V>>;
@@ -363,8 +236,8 @@ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPre
363
236
  type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
364
237
  normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
365
238
  }['normalize'];
366
- type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, ClassPluginFactory<AnyRecord> | undefined>;
367
- 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> = {
239
+ type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, AnyClassPluginFactory>;
240
+ type FactoryOptions<TDefault extends ElementType = ElementType, Props extends AnyRecord = EmptyRecord, V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory, TAllowed extends ElementType = ElementType> = {
368
241
  readonly tag?: TDefault;
369
242
  readonly name?: string;
370
243
  readonly defaults?: Partial<NoInfer<Props>>;
@@ -386,9 +259,9 @@ declare const Slottable: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNod
386
259
  [key: string]: any;
387
260
  }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
388
261
 
389
- type UnknownProps = Record<string, unknown>;
262
+ type UnknownProps = AnyRecord;
390
263
 
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> & {
264
+ type VueFactoryOptions<TDefault extends ElementType, Props extends UnknownProps, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory> = FactoryOptions<TDefault, Props, Variants, TPreset, TPlugin> & {
392
265
  /**
393
266
  * Return true for any prop key that should be consumed but not forwarded to
394
267
  * the DOM. Variant keys are always stripped automatically.
@@ -434,6 +307,6 @@ type PolymorphicComponent<G extends PolymorphicGenerics> = {
434
307
  displayName?: string;
435
308
  };
436
309
 
437
- declare function createContractComponent<TDefault extends ElementType, Props extends UnknownProps = EmptyRecord, Variants extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined>(options: VueFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>>;
310
+ declare function createContractComponent<TDefault extends ElementType, Props extends UnknownProps = EmptyRecord, Variants extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory>(options: VueFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>>;
438
311
 
439
312
  export { type AnyFactoryOptions, type ElementType, type EmptyRecord, type PolymorphicComponent, type PolymorphicGenerics, type PolymorphicProps, type PolymorphicWithAsChild, Slottable, type SlottableProps, type VueFactoryOptions, createContractComponent, defineContractComponent };