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, OmitIndexSignature } from 'type-fest';
1
+ import { RequireAtLeastOne, Simplify, ReadonlyDeep, OmitIndexSignature } from 'type-fest';
2
+ import { Diagnostics, DiagnosticInput } from '../_shared/diagnostics.js';
2
3
  import { ComponentChildren, VNode, ComponentType, JSX, Ref } from 'preact';
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,14 +70,17 @@ 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
  /** The full optional prop surface exposed to callers for a given variant map. */
233
75
  type VariantProps<V extends VariantMap> = {
234
76
  [K in keyof V]?: VariantKey<V, K>;
235
77
  };
78
+
236
79
  type NormalizedVariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
237
80
  type DefaultVariants<V extends VariantMap> = {
238
81
  [K in keyof V]?: NormalizedVariantValue<keyof V[K] & string>;
239
82
  };
83
+
240
84
  /**
241
85
  * A static, immutable map of named presets to partial variant selections.
242
86
  *
@@ -244,7 +88,9 @@ type DefaultVariants<V extends VariantMap> = {
244
88
  * avoiding the need to repeat variant combinations at each call site.
245
89
  */
246
90
  type RecipeMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
91
+
247
92
  type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
93
+
248
94
  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> {
249
95
  default: TDefault;
250
96
  props: Props;
@@ -257,6 +103,29 @@ type RecipeOf<T extends PolymorphicGenerics> = T['preset'];
257
103
  type DefaultOf<T extends PolymorphicGenerics> = T['default'];
258
104
  type PropsOf<T extends PolymorphicGenerics> = T['props'];
259
105
 
106
+ type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
107
+ type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
108
+ type CompoundVariantConditions<V extends VariantMap> = Simplify<{
109
+ [K in keyof V]: CompoundVariantConditionValue<V, K>;
110
+ }>;
111
+ type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
112
+ type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
113
+ type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
114
+ class: VariantValue;
115
+ };
116
+
117
+ interface CVACompounds<V extends VariantMap> {
118
+ compoundVariants?: readonly CompoundVariant<V>[];
119
+ }
120
+
121
+ interface CVADefaults<V extends VariantMap> {
122
+ defaultVariants?: DefaultVariants<V>;
123
+ }
124
+
125
+ interface CVAVariants<V extends VariantMap> {
126
+ variants?: V;
127
+ }
128
+
260
129
  interface BaseClassOptions {
261
130
  baseClassName?: ClassName;
262
131
  }
@@ -288,7 +157,11 @@ type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
288
157
  }>;
289
158
 
290
159
  type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, diagnostics: Diagnostics) => ClassPlugin<TProps>;
291
- type ExtractPluginProps<TPlugin extends ClassPluginFactory<AnyRecord> | undefined> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? EmptyRecord : T : EmptyRecord;
160
+ /** `ClassPluginFactory` with its plugin-owned-props generic erased the common form used
161
+ * wherever a factory's concrete plugin-props shape isn't tracked (factory generics,
162
+ * capability wiring). */
163
+ type AnyClassPluginFactory = ClassPluginFactory<AnyRecord> | undefined;
164
+ type ExtractPluginProps<TPlugin extends AnyClassPluginFactory> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? EmptyRecord : T : EmptyRecord;
292
165
 
293
166
  type AriaContext = {
294
167
  readonly tag: IntrinsicTag;
@@ -348,7 +221,7 @@ type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
348
221
  readonly allowedAs?: readonly TAllowed[];
349
222
  };
350
223
 
351
- type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined> = {
224
+ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory> = {
352
225
  readonly base?: ClassName;
353
226
  readonly variants?: V;
354
227
  readonly defaults?: Partial<DefaultVariants<V>>;
@@ -362,8 +235,8 @@ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPre
362
235
  type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
363
236
  normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
364
237
  }['normalize'];
365
- type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, ClassPluginFactory<AnyRecord> | undefined>;
366
- 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> = {
238
+ type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, AnyClassPluginFactory>;
239
+ 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> = {
367
240
  readonly tag?: TDefault;
368
241
  readonly name?: string;
369
242
  readonly defaults?: Partial<NoInfer<Props>>;
@@ -379,11 +252,11 @@ type SlottableProps = {
379
252
  };
380
253
  declare function Slottable({ children }: SlottableProps): AnyVNode;
381
254
 
382
- type UnknownProps = Record<string, unknown>;
255
+ type UnknownProps = AnyRecord;
383
256
  type SlotComponent = ComponentType<UnknownProps>;
384
257
  type AnyVNode = VNode<any>;
385
258
 
386
- type PreactFactoryOptions<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> & {
259
+ type PreactFactoryOptions<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> & {
387
260
  /** Component used to render the asChild slot. Defaults to the built-in Slot. */
388
261
  slotComponent?: SlotComponent;
389
262
  /**
@@ -417,6 +290,6 @@ type PolymorphicComponent<G extends PolymorphicGenerics> = {
417
290
  displayName?: string;
418
291
  };
419
292
 
420
- 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: PreactFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>>;
293
+ 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: PreactFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicComponent<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>>;
421
294
 
422
295
  export { type AnyFactoryOptions, type ElementRef, type ElementType, type EmptyRecord, type PolymorphicComponent, type PolymorphicGenerics, type PolymorphicProps, type PolymorphicWithAsChild, type PreactFactoryOptions, Slottable, createContractComponent, defineContractComponent };