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,154 +23,19 @@ 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;
170
29
  };
171
30
  type CardinalityInput = Partial<MinMax>;
172
31
 
32
+ /** Structural counterpart to `@praxis-kit/contract`'s `ChildrenEvaluator` class — `lib/primitive`
33
+ * may not depend on `lib/contract` (see `primitive-no-upper-layers` in .dependency-cruiser.cjs),
34
+ * so this describes only the shape consumers actually call. Mirrors `AriaEngine`'s pattern. */
35
+ type ChildrenEvaluator$1 = {
36
+ evaluate: (children: unknown[]) => void;
37
+ };
38
+
173
39
  type ChildRuleMatch<T, U extends T = T> = (child: T) => child is U;
174
40
 
175
41
  type ChildRulePosition = 'first' | 'last' | 'any';
@@ -197,34 +63,16 @@ type ValidResult = {
197
63
  valid: true;
198
64
  };
199
65
 
200
- type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
201
- type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
202
- type CompoundVariantConditions<V extends VariantMap> = Simplify<{
203
- [K in keyof V]: CompoundVariantConditionValue<V, K>;
204
- }>;
205
- type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
206
- type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
207
- type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
208
- class: VariantValue;
209
- };
210
-
211
- interface CVACompounds<V extends VariantMap> {
212
- compoundVariants?: readonly CompoundVariant<V>[];
213
- }
214
-
215
- interface CVADefaults<V extends VariantMap> {
216
- defaultVariants?: DefaultVariants<V>;
217
- }
218
-
219
- interface CVAVariants<V extends VariantMap> {
220
- variants?: V;
221
- }
222
-
223
66
  type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
67
+
224
68
  type VariantValue = string | string[];
69
+
225
70
  type VariantStates<K extends string = string> = Record<K, VariantValue>;
71
+
226
72
  type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
73
+
227
74
  type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
75
+
228
76
  /**
229
77
  * A partial selection of variant states authored at factory definition time.
230
78
  *
@@ -234,10 +82,12 @@ type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof
234
82
  type VariantSelection<V extends VariantMap> = {
235
83
  [K in keyof V]?: keyof V[K];
236
84
  };
85
+
237
86
  type NormalizedVariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
238
87
  type DefaultVariants<V extends VariantMap> = {
239
88
  [K in keyof V]?: NormalizedVariantValue<keyof V[K] & string>;
240
89
  };
90
+
241
91
  /**
242
92
  * A static, immutable map of named presets to partial variant selections.
243
93
  *
@@ -245,7 +95,9 @@ type DefaultVariants<V extends VariantMap> = {
245
95
  * avoiding the need to repeat variant combinations at each call site.
246
96
  */
247
97
  type RecipeMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
98
+
248
99
  type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
100
+
249
101
  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
102
  default: TDefault;
251
103
  props: Props;
@@ -254,6 +106,29 @@ interface PolymorphicGenerics<TDefault extends ElementType = ElementType, Props
254
106
  allowed: TAllowed;
255
107
  }
256
108
 
109
+ type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
110
+ type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
111
+ type CompoundVariantConditions<V extends VariantMap> = Simplify<{
112
+ [K in keyof V]: CompoundVariantConditionValue<V, K>;
113
+ }>;
114
+ type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
115
+ type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
116
+ type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
117
+ class: VariantValue;
118
+ };
119
+
120
+ interface CVACompounds<V extends VariantMap> {
121
+ compoundVariants?: readonly CompoundVariant<V>[];
122
+ }
123
+
124
+ interface CVADefaults<V extends VariantMap> {
125
+ defaultVariants?: DefaultVariants<V>;
126
+ }
127
+
128
+ interface CVAVariants<V extends VariantMap> {
129
+ variants?: V;
130
+ }
131
+
257
132
  interface BaseClassOptions {
258
133
  baseClassName?: ClassName;
259
134
  }
@@ -285,8 +160,12 @@ type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
285
160
  }>;
286
161
 
287
162
  type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, diagnostics: Diagnostics) => ClassPlugin<TProps>;
288
- type ExtractPluginProps<TPlugin extends ClassPluginFactory<AnyRecord> | undefined> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? EmptyRecord : T : EmptyRecord;
289
- type PluginInstance<TPlugin extends ClassPluginFactory<AnyRecord> | undefined> = TPlugin extends ClassPluginFactory<infer TProps> ? ClassPlugin<TProps> : undefined;
163
+ /** `ClassPluginFactory` with its plugin-owned-props generic erased the common form used
164
+ * wherever a factory's concrete plugin-props shape isn't tracked (factory generics,
165
+ * capability wiring). */
166
+ type AnyClassPluginFactory = ClassPluginFactory<AnyRecord> | undefined;
167
+ type ExtractPluginProps<TPlugin extends AnyClassPluginFactory> = TPlugin extends ClassPluginFactory<infer T> ? string extends keyof T ? EmptyRecord : T : EmptyRecord;
168
+ type PluginInstance<TPlugin extends AnyClassPluginFactory> = TPlugin extends ClassPluginFactory<infer TProps> ? ClassPlugin<TProps> : undefined;
290
169
 
291
170
  type AriaContext = {
292
171
  readonly tag: IntrinsicTag;
@@ -346,7 +225,7 @@ type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
346
225
  readonly allowedAs?: readonly TAllowed[];
347
226
  };
348
227
 
349
- type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined> = {
228
+ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory> = {
350
229
  readonly base?: ClassName;
351
230
  readonly variants?: V;
352
231
  readonly defaults?: Partial<DefaultVariants<V>>;
@@ -360,8 +239,8 @@ type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPre
360
239
  type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
361
240
  normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
362
241
  }['normalize'];
363
- type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, ClassPluginFactory<AnyRecord> | undefined>;
364
- 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> = {
242
+ type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, AnyClassPluginFactory>;
243
+ 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> = {
365
244
  readonly tag?: TDefault;
366
245
  readonly name?: string;
367
246
  readonly defaults?: Partial<NoInfer<Props>>;
@@ -384,6 +263,7 @@ type ResolvedFactoryOptions<TDefault extends ElementType = ElementType, Props ex
384
263
  readonly variantKeys: ReadonlySet<string>;
385
264
  readonly normalizeFn?: NormalizeFn<Props>;
386
265
  readonly htmlPropNormalizersFn?: (tag: unknown) => readonly PropNormalizer[] | undefined;
266
+ readonly htmlChildrenEvaluatorFn?: (tag: unknown) => ChildrenEvaluator$1 | undefined;
387
267
  readonly childRules?: readonly ChildRuleInput[];
388
268
  readonly ariaRules?: readonly AriaRule[];
389
269
  readonly allowedAs?: readonly ElementType[];
@@ -428,7 +308,7 @@ declare class ChildrenEvaluator extends InvariantBase {
428
308
  evaluate(children: unknown[]): void;
429
309
  }
430
310
 
431
- declare function createPolymorphic<TDefault extends ElementType, Props extends AnyRecord, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends ClassPluginFactory<AnyRecord> | undefined = ClassPluginFactory<AnyRecord> | undefined>(options?: FactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicRuntime<TDefault, Props, Variants, Extract<keyof TPreset, string>, TPreset, PluginInstance<TPlugin>>;
311
+ declare function createPolymorphic2<TDefault extends ElementType, Props extends AnyRecord, Variants extends Readonly<VariantMap>, TPreset extends RecipeMap<Variants> = Readonly<EmptyRecord>, TPlugin extends AnyClassPluginFactory = AnyClassPluginFactory>(options?: FactoryOptions<TDefault, Props, Variants, TPreset, TPlugin>): PolymorphicRuntime<TDefault, Props, Variants, Extract<keyof TPreset, string>, TPreset, PluginInstance<TPlugin>>;
432
312
 
433
313
  declare class SlotValidator extends InvariantBase {
434
314
  #private;
@@ -450,9 +330,9 @@ type BuiltChildrenEvaluator<TOptions extends WithChildRules> = TOptions extends
450
330
 
451
331
  declare function defineContractComponent<O extends FactoryOptions>(options: O): <R>(factory: (options: O) => R) => R;
452
332
 
453
- type UnknownProps = Record<string, unknown>;
333
+ type UnknownProps = AnyRecord;
454
334
 
455
- type SvelteFactoryOptions<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> & {
335
+ type SvelteFactoryOptions<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> & {
456
336
  /**
457
337
  * Return true for any prop key that should be consumed but not forwarded to the DOM.
458
338
  * Receives `runtime.options.variantKeys` as a convenience if needed.
@@ -460,7 +340,7 @@ type SvelteFactoryOptions<TDefault extends ElementType, Props extends UnknownPro
460
340
  filterProps?: (key: string, variantKeys: ReadonlySet<string>) => boolean;
461
341
  };
462
342
 
463
- type TypedRuntime<G extends PolymorphicGenerics> = ReturnType<typeof createPolymorphic<DefaultOf<G>, PropsOf<G>, VariantsOf<G>, RecipeOf<G>>>;
343
+ type TypedRuntime<G extends PolymorphicGenerics> = ReturnType<typeof createPolymorphic2<DefaultOf<G>, PropsOf<G>, VariantsOf<G>, RecipeOf<G>>>;
464
344
 
465
345
  type BuiltRuntime<G extends PolymorphicGenerics = PolymorphicGenerics, TOptions extends WithChildRules = WithChildRules> = BuiltChildrenEvaluator<TOptions> & {
466
346
  runtime: TypedRuntime<G>;
@@ -468,6 +348,6 @@ type BuiltRuntime<G extends PolymorphicGenerics = PolymorphicGenerics, TOptions
468
348
  slotValidator: SlotValidator;
469
349
  };
470
350
 
471
- 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, TOptions extends WithChildRules = SvelteFactoryOptions<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>>(options: SvelteFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin> & TOptions): BuiltRuntime<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>, TOptions>;
351
+ 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, TOptions extends WithChildRules = SvelteFactoryOptions<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>>(options: SvelteFactoryOptions<TDefault, Props, Variants, TPreset, TPlugin> & TOptions): BuiltRuntime<PolymorphicGenerics<TDefault, Props & ExtractPluginProps<TPlugin>, Variants, TPreset>, TOptions>;
472
352
 
473
353
  export { type AnyFactoryOptions, type BuiltRuntime, type ElementType, type EmptyRecord, type FilterPredicate, type PolymorphicGenerics, type SvelteFactoryOptions, type UnknownProps, type WithChildRules, createContractComponent, defineContractComponent };