praxis-kit 4.0.3 → 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.
@@ -3,6 +3,7 @@ import { RequireAtLeastOne, Simplify, ReadonlyDeep } from 'type-fest';
3
3
 
4
4
  type StringMap<T = unknown> = Record<string, T>;
5
5
  type AnyRecord = StringMap<unknown>;
6
+ type EmptyRecord = Record<never, never>;
6
7
 
7
8
  type IntrinsicTag = keyof HTMLElementTagNameMap;
8
9
 
@@ -13,7 +14,6 @@ type KnownAriaRole = (typeof KNOWN_ARIA_ROLES)[number];
13
14
 
14
15
  type Booleanish = boolean | 'true' | 'false';
15
16
  type ClassName = string | string[];
16
- type EmptyRecord = Record<never, never>;
17
17
  type NonEmptyArray<T> = [T, ...T[]];
18
18
  type Numberish = number | `${number}`;
19
19
  type Primitive = string | number | boolean;
@@ -50,34 +50,16 @@ type ValidResult = {
50
50
  valid: true;
51
51
  };
52
52
 
53
- type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
54
- type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
55
- type CompoundVariantConditions<V extends VariantMap> = Simplify<{
56
- [K in keyof V]: CompoundVariantConditionValue<V, K>;
57
- }>;
58
- type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
59
- type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
60
- type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
61
- class: VariantValue;
62
- };
63
-
64
- interface CVACompounds<V extends VariantMap> {
65
- compoundVariants?: readonly CompoundVariant<V>[];
66
- }
67
-
68
- interface CVADefaults<V extends VariantMap> {
69
- defaultVariants?: DefaultVariants<V>;
70
- }
71
-
72
- interface CVAVariants<V extends VariantMap> {
73
- variants?: V;
74
- }
75
-
76
53
  type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
54
+
77
55
  type VariantValue = string | string[];
56
+
78
57
  type VariantStates<K extends string = string> = Record<K, VariantValue>;
58
+
79
59
  type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
60
+
80
61
  type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
62
+
81
63
  /**
82
64
  * A partial selection of variant states authored at factory definition time.
83
65
  *
@@ -87,10 +69,12 @@ type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof
87
69
  type VariantSelection<V extends VariantMap> = {
88
70
  [K in keyof V]?: keyof V[K];
89
71
  };
72
+
90
73
  type NormalizedVariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
91
74
  type DefaultVariants<V extends VariantMap> = {
92
75
  [K in keyof V]?: NormalizedVariantValue<keyof V[K] & string>;
93
76
  };
77
+
94
78
  /**
95
79
  * A static, immutable map of named presets to partial variant selections.
96
80
  *
@@ -98,8 +82,32 @@ type DefaultVariants<V extends VariantMap> = {
98
82
  * avoiding the need to repeat variant combinations at each call site.
99
83
  */
100
84
  type RecipeMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
85
+
101
86
  type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
102
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
+
103
111
  interface BaseClassOptions {
104
112
  baseClassName?: ClassName;
105
113
  }
@@ -131,6 +139,10 @@ type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
131
139
  }>;
132
140
 
133
141
  type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, diagnostics: Diagnostics$1) => ClassPlugin<TProps>;
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;
134
146
 
135
147
  type AriaContext = {
136
148
  readonly tag: IntrinsicTag;
@@ -190,7 +202,7 @@ type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
190
202
  readonly allowedAs?: readonly TAllowed[];
191
203
  };
192
204
 
193
- type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined> = {
205
+ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory> = {
194
206
  readonly base?: ClassName;
195
207
  readonly variants?: V;
196
208
  readonly defaults?: Partial<DefaultVariants<V>>;
@@ -204,8 +216,8 @@ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPre
204
216
  type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
205
217
  normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
206
218
  }['normalize'];
207
- type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, ClassPluginFactory<AnyRecord> | undefined>;
208
- 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> = {
219
+ type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, AnyClassPluginFactory>;
220
+ 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> = {
209
221
  readonly tag?: TDefault;
210
222
  readonly name?: string;
211
223
  readonly defaults?: Partial<NoInfer<Props>>;
@@ -4,6 +4,7 @@ import { LitElement } from 'lit';
4
4
 
5
5
  type StringMap<T = unknown> = Record<string, T>;
6
6
  type AnyRecord = StringMap<unknown>;
7
+ type EmptyRecord = Record<never, never>;
7
8
 
8
9
  type IntrinsicTag = keyof HTMLElementTagNameMap;
9
10
 
@@ -14,7 +15,6 @@ type KnownAriaRole = (typeof KNOWN_ARIA_ROLES)[number];
14
15
 
15
16
  type Booleanish = boolean | 'true' | 'false';
16
17
  type ClassName = string | string[];
17
- type EmptyRecord = Record<never, never>;
18
18
  type NonEmptyArray<T> = [T, ...T[]];
19
19
  type Numberish = number | `${number}`;
20
20
  type Primitive = string | number | boolean;
@@ -51,34 +51,16 @@ type ValidResult = {
51
51
  valid: true;
52
52
  };
53
53
 
54
- type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
55
- type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
56
- type CompoundVariantConditions<V extends VariantMap> = Simplify<{
57
- [K in keyof V]: CompoundVariantConditionValue<V, K>;
58
- }>;
59
- type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
60
- type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
61
- type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
62
- class: VariantValue;
63
- };
64
-
65
- interface CVACompounds<V extends VariantMap> {
66
- compoundVariants?: readonly CompoundVariant<V>[];
67
- }
68
-
69
- interface CVADefaults<V extends VariantMap> {
70
- defaultVariants?: DefaultVariants<V>;
71
- }
72
-
73
- interface CVAVariants<V extends VariantMap> {
74
- variants?: V;
75
- }
76
-
77
54
  type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
55
+
78
56
  type VariantValue = string | string[];
57
+
79
58
  type VariantStates<K extends string = string> = Record<K, VariantValue>;
59
+
80
60
  type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
61
+
81
62
  type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
63
+
82
64
  /**
83
65
  * A partial selection of variant states authored at factory definition time.
84
66
  *
@@ -88,10 +70,12 @@ type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof
88
70
  type VariantSelection<V extends VariantMap> = {
89
71
  [K in keyof V]?: keyof V[K];
90
72
  };
73
+
91
74
  type NormalizedVariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
92
75
  type DefaultVariants<V extends VariantMap> = {
93
76
  [K in keyof V]?: NormalizedVariantValue<keyof V[K] & string>;
94
77
  };
78
+
95
79
  /**
96
80
  * A static, immutable map of named presets to partial variant selections.
97
81
  *
@@ -99,8 +83,32 @@ type DefaultVariants<V extends VariantMap> = {
99
83
  * avoiding the need to repeat variant combinations at each call site.
100
84
  */
101
85
  type RecipeMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
86
+
102
87
  type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
103
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
+
104
112
  interface BaseClassOptions {
105
113
  baseClassName?: ClassName;
106
114
  }
@@ -132,7 +140,11 @@ type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
132
140
  }>;
133
141
 
134
142
  type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, diagnostics: Diagnostics) => ClassPlugin<TProps>;
135
- 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;
136
148
 
137
149
  type AriaContext = {
138
150
  readonly tag: IntrinsicTag;
@@ -192,7 +204,7 @@ type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
192
204
  readonly allowedAs?: readonly TAllowed[];
193
205
  };
194
206
 
195
- 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> = {
196
208
  readonly base?: ClassName;
197
209
  readonly variants?: V;
198
210
  readonly defaults?: Partial<DefaultVariants<V>>;
@@ -206,8 +218,8 @@ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPre
206
218
  type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
207
219
  normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
208
220
  }['normalize'];
209
- type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, ClassPluginFactory<AnyRecord> | undefined>;
210
- 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> = {
211
223
  readonly tag?: TDefault;
212
224
  readonly name?: string;
213
225
  readonly defaults?: Partial<NoInfer<Props>>;
@@ -231,7 +243,7 @@ declare function defineContractComponent<O extends FactoryOptions>(options: O):
231
243
  * Note: this adapter targets Light DOM composition only. Shadow DOM slot
232
244
  * protocol is intentionally out of scope.
233
245
  */
234
- 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> & {
235
247
  readonly filterProps?: FilterPredicate;
236
248
  };
237
249
 
@@ -273,7 +285,7 @@ type LitContractComponent<TVariants extends Readonly<VariantMap> = Readonly<Empt
273
285
  * customElements.define('praxis-button', Button)
274
286
  * ```
275
287
  */
276
- 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>>;
277
289
 
278
290
  /**
279
291
  * Renders a praxis-kit Lit component to an HTML string without requiring a DOM.