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,7 +1,9 @@
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
 
3
4
  type StringMap<T = unknown> = Record<string, T>;
4
5
  type AnyRecord = StringMap<unknown>;
6
+ type EmptyRecord = Record<never, never>;
5
7
 
6
8
  type IntrinsicTag = keyof HTMLElementTagNameMap;
7
9
 
@@ -12,7 +14,6 @@ type KnownAriaRole = (typeof KNOWN_ARIA_ROLES)[number];
12
14
 
13
15
  type Booleanish = boolean | 'true' | 'false';
14
16
  type ClassName = string | string[];
15
- type EmptyRecord = Record<never, never>;
16
17
  type NonEmptyArray<T> = [T, ...T[]];
17
18
  type Numberish = number | `${number}`;
18
19
  type Primitive = string | number | boolean;
@@ -22,148 +23,6 @@ type IntrinsicProps = AnyRecord & {
22
23
  };
23
24
  type TagMap = Partial<Record<IntrinsicTag | (string & {}), ClassName>>;
24
25
 
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
- }
37
-
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
- }
101
-
102
- interface SourcePosition {
103
- line: number;
104
- col: number;
105
- }
106
- interface SourceLocation {
107
- file: string;
108
- start: SourcePosition;
109
- end?: SourcePosition;
110
- }
111
-
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
- }
154
-
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
- }
166
-
167
26
  type MinMax = {
168
27
  min: number;
169
28
  max: number;
@@ -191,34 +50,16 @@ type ValidResult = {
191
50
  valid: true;
192
51
  };
193
52
 
194
- type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
195
- type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
196
- type CompoundVariantConditions<V extends VariantMap> = Simplify<{
197
- [K in keyof V]: CompoundVariantConditionValue<V, K>;
198
- }>;
199
- type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
200
- type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
201
- type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
202
- class: VariantValue;
203
- };
204
-
205
- interface CVACompounds<V extends VariantMap> {
206
- compoundVariants?: readonly CompoundVariant<V>[];
207
- }
208
-
209
- interface CVADefaults<V extends VariantMap> {
210
- defaultVariants?: DefaultVariants<V>;
211
- }
212
-
213
- interface CVAVariants<V extends VariantMap> {
214
- variants?: V;
215
- }
216
-
217
53
  type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
54
+
218
55
  type VariantValue = string | string[];
56
+
219
57
  type VariantStates<K extends string = string> = Record<K, VariantValue>;
58
+
220
59
  type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
60
+
221
61
  type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
62
+
222
63
  /**
223
64
  * A partial selection of variant states authored at factory definition time.
224
65
  *
@@ -228,10 +69,12 @@ type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof
228
69
  type VariantSelection<V extends VariantMap> = {
229
70
  [K in keyof V]?: keyof V[K];
230
71
  };
72
+
231
73
  type NormalizedVariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
232
74
  type DefaultVariants<V extends VariantMap> = {
233
75
  [K in keyof V]?: NormalizedVariantValue<keyof V[K] & string>;
234
76
  };
77
+
235
78
  /**
236
79
  * A static, immutable map of named presets to partial variant selections.
237
80
  *
@@ -239,8 +82,32 @@ type DefaultVariants<V extends VariantMap> = {
239
82
  * avoiding the need to repeat variant combinations at each call site.
240
83
  */
241
84
  type RecipeMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
85
+
242
86
  type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
243
87
 
88
+ type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
89
+ type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
90
+ type CompoundVariantConditions<V extends VariantMap> = Simplify<{
91
+ [K in keyof V]: CompoundVariantConditionValue<V, K>;
92
+ }>;
93
+ type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
94
+ type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
95
+ type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
96
+ class: VariantValue;
97
+ };
98
+
99
+ interface CVACompounds<V extends VariantMap> {
100
+ compoundVariants?: readonly CompoundVariant<V>[];
101
+ }
102
+
103
+ interface CVADefaults<V extends VariantMap> {
104
+ defaultVariants?: DefaultVariants<V>;
105
+ }
106
+
107
+ interface CVAVariants<V extends VariantMap> {
108
+ variants?: V;
109
+ }
110
+
244
111
  interface BaseClassOptions {
245
112
  baseClassName?: ClassName;
246
113
  }
@@ -272,7 +139,11 @@ type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
272
139
  }>;
273
140
 
274
141
  type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, diagnostics: Diagnostics) => ClassPlugin<TProps>;
275
- type ExtractPluginProps<TPlugin extends ClassPluginFactory<AnyRecord> | undefined> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? EmptyRecord : T : EmptyRecord;
142
+ /** `ClassPluginFactory` with its plugin-owned-props generic erased the common form used
143
+ * wherever a factory's concrete plugin-props shape isn't tracked (factory generics,
144
+ * capability wiring). */
145
+ type AnyClassPluginFactory = ClassPluginFactory<AnyRecord> | undefined;
146
+ type ExtractPluginProps<TPlugin extends AnyClassPluginFactory> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? EmptyRecord : T : EmptyRecord;
276
147
 
277
148
  type AriaContext = {
278
149
  readonly tag: IntrinsicTag;
@@ -332,7 +203,7 @@ type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
332
203
  readonly allowedAs?: readonly TAllowed[];
333
204
  };
334
205
 
335
- type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined> = {
206
+ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory> = {
336
207
  readonly base?: ClassName;
337
208
  readonly variants?: V;
338
209
  readonly defaults?: Partial<DefaultVariants<V>>;
@@ -346,8 +217,8 @@ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPre
346
217
  type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
347
218
  normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
348
219
  }['normalize'];
349
- type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, ClassPluginFactory<AnyRecord> | undefined>;
350
- 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> = {
220
+ type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, AnyClassPluginFactory>;
221
+ 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> = {
351
222
  readonly tag?: TDefault;
352
223
  readonly name?: string;
353
224
  readonly defaults?: Partial<NoInfer<Props>>;
@@ -366,11 +237,11 @@ declare function defineContractComponent<O extends FactoryOptions>(options: O):
366
237
  * Identical shape to LitFactoryOptions — a plain HTMLElement subclass with
367
238
  * no framework dependency. Light DOM only; Shadow DOM is out of scope.
368
239
  */
369
- type WebFactoryOptions<TDefault extends ElementType = ElementType, TProps extends AnyRecord = EmptyRecord, TVariants extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<TVariants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined> = FactoryOptions<TDefault, TProps, TVariants, TPreset, TPlugin> & {
240
+ type WebFactoryOptions<TDefault extends ElementType = ElementType, TProps extends AnyRecord = EmptyRecord, TVariants extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<TVariants> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory> = FactoryOptions<TDefault, TProps, TVariants, TPreset, TPlugin> & {
370
241
  readonly filterProps?: FilterPredicate;
371
242
  };
372
243
 
373
- type UnknownProps = Record<string, unknown>;
244
+ type UnknownProps = AnyRecord;
374
245
  /**
375
246
  * Constructor type returned by createContractComponent.
376
247
  *
@@ -418,7 +289,7 @@ type WebContractComponent<TVariants extends Readonly<VariantMap> = Readonly<Empt
418
289
  * For non-reactive attributes (`aria-*`, `role`, `data-*`) call `element.update()`
419
290
  * after setting them to trigger an explicit pipeline re-run.
420
291
  */
421
- declare function createContractComponent<TDefault extends ElementType, TProps extends UnknownProps = EmptyRecord, TVariants extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<TVariants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined>(options: WebFactoryOptions<TDefault, TProps, TVariants, TPreset, TPlugin>): WebContractComponent<TVariants, ExtractPluginProps<TPlugin>>;
292
+ declare function createContractComponent<TDefault extends ElementType, TProps extends UnknownProps = EmptyRecord, TVariants extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<TVariants> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory>(options: WebFactoryOptions<TDefault, TProps, TVariants, TPreset, TPlugin>): WebContractComponent<TVariants, ExtractPluginProps<TPlugin>>;
422
293
 
423
294
  /**
424
295
  * Renders a praxis-kit web component to an HTML string without requiring a DOM.