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,8 +1,10 @@
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 { LitElement } from 'lit';
3
4
 
4
5
  type StringMap<T = unknown> = Record<string, T>;
5
6
  type AnyRecord = StringMap<unknown>;
7
+ type EmptyRecord = Record<never, never>;
6
8
 
7
9
  type IntrinsicTag = keyof HTMLElementTagNameMap;
8
10
 
@@ -13,7 +15,6 @@ type KnownAriaRole = (typeof KNOWN_ARIA_ROLES)[number];
13
15
 
14
16
  type Booleanish = boolean | 'true' | 'false';
15
17
  type ClassName = string | string[];
16
- type EmptyRecord = Record<never, never>;
17
18
  type NonEmptyArray<T> = [T, ...T[]];
18
19
  type Numberish = number | `${number}`;
19
20
  type Primitive = string | number | boolean;
@@ -23,148 +24,6 @@ type IntrinsicProps = AnyRecord & {
23
24
  };
24
25
  type TagMap = Partial<Record<IntrinsicTag | (string & {}), ClassName>>;
25
26
 
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
- }
38
-
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
- }
102
-
103
- interface SourcePosition {
104
- line: number;
105
- col: number;
106
- }
107
- interface SourceLocation {
108
- file: string;
109
- start: SourcePosition;
110
- end?: SourcePosition;
111
- }
112
-
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
- }
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
27
  type MinMax = {
169
28
  min: number;
170
29
  max: number;
@@ -192,34 +51,16 @@ type ValidResult = {
192
51
  valid: true;
193
52
  };
194
53
 
195
- type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
196
- type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
197
- type CompoundVariantConditions<V extends VariantMap> = Simplify<{
198
- [K in keyof V]: CompoundVariantConditionValue<V, K>;
199
- }>;
200
- type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
201
- type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
202
- type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
203
- class: VariantValue;
204
- };
205
-
206
- interface CVACompounds<V extends VariantMap> {
207
- compoundVariants?: readonly CompoundVariant<V>[];
208
- }
209
-
210
- interface CVADefaults<V extends VariantMap> {
211
- defaultVariants?: DefaultVariants<V>;
212
- }
213
-
214
- interface CVAVariants<V extends VariantMap> {
215
- variants?: V;
216
- }
217
-
218
54
  type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
55
+
219
56
  type VariantValue = string | string[];
57
+
220
58
  type VariantStates<K extends string = string> = Record<K, VariantValue>;
59
+
221
60
  type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
61
+
222
62
  type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
63
+
223
64
  /**
224
65
  * A partial selection of variant states authored at factory definition time.
225
66
  *
@@ -229,10 +70,12 @@ type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof
229
70
  type VariantSelection<V extends VariantMap> = {
230
71
  [K in keyof V]?: keyof V[K];
231
72
  };
73
+
232
74
  type NormalizedVariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
233
75
  type DefaultVariants<V extends VariantMap> = {
234
76
  [K in keyof V]?: NormalizedVariantValue<keyof V[K] & string>;
235
77
  };
78
+
236
79
  /**
237
80
  * A static, immutable map of named presets to partial variant selections.
238
81
  *
@@ -240,8 +83,32 @@ type DefaultVariants<V extends VariantMap> = {
240
83
  * avoiding the need to repeat variant combinations at each call site.
241
84
  */
242
85
  type RecipeMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
86
+
243
87
  type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
244
88
 
89
+ type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
90
+ type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
91
+ type CompoundVariantConditions<V extends VariantMap> = Simplify<{
92
+ [K in keyof V]: CompoundVariantConditionValue<V, K>;
93
+ }>;
94
+ type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
95
+ type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
96
+ type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
97
+ class: VariantValue;
98
+ };
99
+
100
+ interface CVACompounds<V extends VariantMap> {
101
+ compoundVariants?: readonly CompoundVariant<V>[];
102
+ }
103
+
104
+ interface CVADefaults<V extends VariantMap> {
105
+ defaultVariants?: DefaultVariants<V>;
106
+ }
107
+
108
+ interface CVAVariants<V extends VariantMap> {
109
+ variants?: V;
110
+ }
111
+
245
112
  interface BaseClassOptions {
246
113
  baseClassName?: ClassName;
247
114
  }
@@ -273,7 +140,11 @@ type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
273
140
  }>;
274
141
 
275
142
  type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, diagnostics: Diagnostics) => ClassPlugin<TProps>;
276
- type ExtractPluginProps<TPlugin extends ClassPluginFactory<AnyRecord> | undefined> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? EmptyRecord : T : EmptyRecord;
143
+ /** `ClassPluginFactory` with its plugin-owned-props generic erased the common form used
144
+ * wherever a factory's concrete plugin-props shape isn't tracked (factory generics,
145
+ * capability wiring). */
146
+ type AnyClassPluginFactory = ClassPluginFactory<AnyRecord> | undefined;
147
+ type ExtractPluginProps<TPlugin extends AnyClassPluginFactory> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? EmptyRecord : T : EmptyRecord;
277
148
 
278
149
  type AriaContext = {
279
150
  readonly tag: IntrinsicTag;
@@ -333,7 +204,7 @@ type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
333
204
  readonly allowedAs?: readonly TAllowed[];
334
205
  };
335
206
 
336
- type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined> = {
207
+ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory> = {
337
208
  readonly base?: ClassName;
338
209
  readonly variants?: V;
339
210
  readonly defaults?: Partial<DefaultVariants<V>>;
@@ -347,8 +218,8 @@ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPre
347
218
  type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
348
219
  normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
349
220
  }['normalize'];
350
- type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, ClassPluginFactory<AnyRecord> | undefined>;
351
- 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> = {
221
+ type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, AnyClassPluginFactory>;
222
+ 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> = {
352
223
  readonly tag?: TDefault;
353
224
  readonly name?: string;
354
225
  readonly defaults?: Partial<NoInfer<Props>>;
@@ -372,7 +243,7 @@ declare function defineContractComponent<O extends FactoryOptions>(options: O):
372
243
  * Note: this adapter targets Light DOM composition only. Shadow DOM slot
373
244
  * protocol is intentionally out of scope.
374
245
  */
375
- type LitFactoryOptions<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> & {
246
+ type LitFactoryOptions<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> & {
376
247
  readonly filterProps?: FilterPredicate;
377
248
  };
378
249
 
@@ -414,7 +285,7 @@ type LitContractComponent<TVariants extends Readonly<VariantMap> = Readonly<Empt
414
285
  * customElements.define('praxis-button', Button)
415
286
  * ```
416
287
  */
417
- 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: LitFactoryOptions<TDefault, TProps, TVariants, TPreset, TPlugin>): LitContractComponent<TVariants, ExtractPluginProps<TPlugin>>;
288
+ 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: LitFactoryOptions<TDefault, TProps, TVariants, TPreset, TPlugin>): LitContractComponent<TVariants, ExtractPluginProps<TPlugin>>;
418
289
 
419
290
  /**
420
291
  * Renders a praxis-kit Lit component to an HTML string without requiring a DOM.