praxis-kit 3.1.0 → 4.0.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,236 +1,8 @@
1
- import { RequireAtLeastOne, Simplify, ReadonlyDeep } from 'type-fest';
2
-
3
- type AnyRecord = Record<string, unknown>;
4
-
5
- type IntrinsicTag = keyof HTMLElementTagNameMap;
6
-
7
- type ElementType = IntrinsicTag | (string & {});
8
-
9
- declare const KNOWN_ARIA_ROLES: readonly ["alert", "alertdialog", "application", "article", "banner", "blockquote", "button", "caption", "cell", "checkbox", "code", "columnheader", "combobox", "complementary", "contentinfo", "definition", "deletion", "dialog", "document", "emphasis", "feed", "figure", "form", "generic", "grid", "gridcell", "group", "heading", "img", "insertion", "link", "list", "listbox", "listitem", "log", "main", "marquee", "math", "menu", "menubar", "menuitem", "menuitemcheckbox", "menuitemradio", "meter", "navigation", "none", "note", "option", "paragraph", "presentation", "progressbar", "radio", "radiogroup", "region", "row", "rowgroup", "rowheader", "scrollbar", "search", "searchbox", "separator", "slider", "spinbutton", "status", "strong", "subscript", "superscript", "switch", "tab", "table", "tablist", "tabpanel", "term", "textbox", "time", "timer", "toolbar", "tooltip", "tree", "treegrid", "treeitem"];
10
- type KnownAriaRole = (typeof KNOWN_ARIA_ROLES)[number];
11
-
12
- type AriaRole = KnownAriaRole | (string & {});
13
-
14
- type Booleanish = boolean | 'true' | 'false';
15
-
16
- type ClassName = string | string[];
17
-
18
- type EmptyRecord = Record<never, never>;
19
-
20
- type IntrinsicProps = AnyRecord & {
21
- role?: AriaRole;
22
- };
23
-
24
- type NonEmptyArray<T> = [T, ...T[]];
25
-
26
- type Numberish = number | `${number}`;
27
-
28
- type Primitive = string | number | boolean;
29
-
30
- type TagMap = Partial<Record<IntrinsicTag | (string & {}), ClassName>>;
31
-
32
- type StrictMode = boolean | 'warn' | 'async-warn' | 'throw';
33
-
34
- type CardinalityInput = {
35
- min?: number;
36
- max?: number;
37
- };
38
-
39
- type ChildRuleMatch<T, U extends T = T> = (child: T) => child is U;
40
-
41
- type ChildRulePosition = 'first' | 'last' | 'any';
42
-
43
- type ChildRuleInput<T = unknown, U extends T = T> = {
44
- name: string;
45
- match: ChildRuleMatch<T, U>;
46
- cardinality?: CardinalityInput;
47
- position?: ChildRulePosition;
48
- /**
49
- * Optional component-type reference for O(1) dispatch index.
50
- * When provided for every rule, the matcher reads child.type instead of
51
- * calling every match function on every child (O(n×m) → O(n+m)).
52
- */
53
- type?: unknown;
54
- };
55
-
56
- type ValidResult = {
57
- valid: true;
58
- };
59
-
60
- type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
61
-
62
- type VariantValue$1 = string | string[];
63
-
64
- type VariantStates<K extends string = string> = Record<K, VariantValue$1>;
65
-
66
- type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
67
-
68
- type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
69
-
70
- type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
71
- type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
72
- type CompoundVariantConditions<V extends VariantMap> = Simplify<{
73
- [K in keyof V]: CompoundVariantConditionValue<V, K>;
74
- }>;
75
- type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
76
- type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
77
- type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
78
- class: VariantValue$1;
79
- };
80
-
81
- interface CVACompounds<V extends VariantMap> {
82
- compoundVariants?: readonly CompoundVariant<V>[];
83
- }
84
-
85
- type VariantValue<K extends string> = string extends K ? Primitive : K extends 'true' | 'false' ? Booleanish : K extends `${number}` ? Numberish : K;
86
- type DefaultVariants<V extends VariantMap> = {
87
- [K in keyof V]?: VariantValue<keyof V[K] & string>;
88
- };
89
-
90
- interface CVADefaults<V extends VariantMap> {
91
- defaultVariants?: DefaultVariants<V>;
92
- }
93
-
94
- interface CVAVariants<V extends VariantMap> {
95
- variants?: V;
96
- }
97
-
98
- /**
99
- * A partial selection of variant states authored at factory definition time.
100
- *
101
- * Uses `keyof V[K]` directly (not `VariantKey`) so TypeScript can eagerly
102
- * resolve the union at constraint-check time without deferred conditional types.
103
- */
104
- type VariantSelection<V extends VariantMap> = {
105
- [K in keyof V]?: keyof V[K];
106
- };
107
-
108
- /**
109
- * A static, immutable map of named presets to partial variant selections.
110
- *
111
- * Presets are named bundles of variant props that callers activate by key,
112
- * avoiding the need to repeat variant combinations at each call site.
113
- */
114
- type RecipeMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
115
-
116
- type RecipeTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
117
-
118
- interface BaseClassOptions {
119
- baseClassName?: ClassName;
120
- }
121
-
122
- type ClassPipelineFn = (tag: unknown, props: AnyRecord, className?: ClassName, recipe?: string) => string;
123
-
124
- interface RecipeOptions<TVariants extends VariantMap = VariantMap> {
125
- recipeMap?: Record<string, RecipeTarget<TVariants>>;
126
- }
127
-
128
- interface TagMapOptions {
129
- tagMap?: TagMap;
130
- }
131
-
132
- type CompositionOptions<TVariants extends VariantMap = VariantMap> = Simplify<TagMapOptions & RecipeOptions<TVariants>>;
133
-
134
- type CVASystemOptions<TVariants extends VariantMap = VariantMap> = Simplify<CVAVariants<TVariants> & CVADefaults<TVariants> & CVACompounds<TVariants>>;
135
-
136
- type StyleOptions<TVariants extends VariantMap = VariantMap> = Simplify<BaseClassOptions & CVASystemOptions<TVariants>>;
137
-
138
- type ClassPipelineOptions<TVariants extends VariantMap = VariantMap> = Simplify<StyleOptions<TVariants> & CompositionOptions<TVariants>>;
139
-
140
- type OwnedPropKeys = ReadonlySet<string>;
141
-
142
- type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
143
- pipeline: ClassPipelineFn;
144
- ownedKeys?: OwnedPropKeys;
145
- readonly _pluginProps?: TProps;
146
- }>;
147
-
148
- type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, strict: StrictMode) => ClassPlugin<TProps>;
149
-
150
- type AriaContext = {
151
- readonly tag: IntrinsicTag;
152
- readonly implicitRole: AriaRole | undefined;
153
- readonly effectiveRole: string | undefined;
154
- readonly props: ReadonlyDeep<IntrinsicProps>;
155
- };
156
-
157
- type RemoveAttributeFixKind = `removeAttribute:${string}`;
158
- type InjectLiveFixKind = `injectLive:${string}`;
159
- type FixKind = 'removeRole' | 'setRole' | 'normalizeRelevantAll' | RemoveAttributeFixKind | InjectLiveFixKind;
160
-
161
- type AriaFixResult = {
162
- applied: false;
163
- next: ReadonlyDeep<IntrinsicProps>;
164
- } | {
165
- applied: true;
166
- next: ReadonlyDeep<IntrinsicProps>;
167
- previous: ReadonlyDeep<IntrinsicProps>;
168
- };
169
- type AriaFix = {
170
- readonly kind: FixKind;
171
- readonly priority?: number;
172
- readonly source?: string;
173
- readonly apply: (context: AriaContext) => AriaFixResult;
174
- };
175
-
176
- type Severity = 'error' | 'warning' | (string & {});
177
-
178
- type AriaInvalidBase<M extends string = string> = {
179
- valid: false;
180
- severity: Severity;
181
- message: M;
182
- attribute?: string;
183
- };
184
- type AriaInvalidWithFix<M extends string = string> = AriaInvalidBase<M> & {
185
- fixable: true;
186
- fix: AriaFix;
187
- };
188
- type AriaInvalidWithoutFix<M extends string = string> = AriaInvalidBase<M> & {
189
- fixable: false;
190
- };
191
- type AriaInvalidResult<M extends string = string> = AriaInvalidWithFix<M> | AriaInvalidWithoutFix<M>;
192
- type AriaResult = ValidResult | AriaInvalidResult;
193
-
194
- type AriaRule<C extends AriaContext = AriaContext> = (context: C) => readonly AriaResult[];
195
-
196
- type PropNormalizer = (props: Readonly<AnyRecord & IntrinsicProps>) => Partial<AnyRecord & IntrinsicProps>;
197
-
198
- type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
199
- readonly strict?: StrictMode;
200
- readonly aria?: readonly AriaRule[];
201
- readonly children?: readonly ChildRuleInput[];
202
- readonly props?: readonly PropNormalizer[];
203
- /** Restricts the `as` prop to this set of tags. Violations route through strict mode. */
204
- readonly allowedAs?: readonly TAllowed[];
205
- };
206
-
207
- type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPluginProps extends AnyRecord = EmptyRecord> = {
208
- readonly base?: ClassName;
209
- readonly variants?: V;
210
- readonly defaults?: Partial<DefaultVariants<V>>;
211
- readonly compounds?: readonly CompoundVariant<V>[];
212
- readonly presets?: TPreset;
213
- readonly tags?: Readonly<TagMap>;
214
- readonly plugin?: ClassPluginFactory<TPluginProps>;
215
- readonly precomputedClasses?: Readonly<Record<string, string>>;
216
- };
217
-
218
- type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
219
- normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
220
- }['normalize'];
221
- type AnyFactoryOptions = FactoryOptions<ElementType, AnyRecord, VariantMap, RecipeMap<VariantMap>, AnyRecord>;
222
- type FactoryOptions<TDefault extends ElementType = ElementType, Props extends AnyRecord = EmptyRecord, V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<V> = Readonly<EmptyRecord>, TPluginProps extends AnyRecord = EmptyRecord, TAllowed extends ElementType = ElementType> = {
223
- readonly tag?: TDefault;
224
- readonly name?: string;
225
- readonly defaults?: Partial<NoInfer<Props>>;
226
- readonly normalize?: NormalizeFn<NoInfer<Props>>;
227
- readonly styling?: StylingOptions<V, TPreset, TPluginProps>;
228
- readonly enforcement?: EnforcementOptions<TAllowed>;
229
- };
230
-
231
- type FilterPredicate = (key: string, variantKeys: ReadonlySet<string>) => boolean;
232
-
233
- declare function defineContractComponent<O extends FactoryOptions>(options: O): <R>(factory: (options: O) => R) => R;
1
+ import { ElementType, AnyRecord, EmptyRecord, VariantMap, RecipeMap, ClassPluginFactory, FactoryOptions, ExtractPluginProps } from '@praxis-kit/core';
2
+ export { AnyFactoryOptions } from '@praxis-kit/core';
3
+ import { FilterPredicate } from '@praxis-kit/adapter-utils';
4
+ export { defineContractComponent } from '@praxis-kit/adapter-utils';
5
+ import { Diagnostics } from '@praxis-kit/diagnostics';
234
6
 
235
7
  /**
236
8
  * Options accepted by createContractComponent in the web adapter.
@@ -238,7 +10,7 @@ declare function defineContractComponent<O extends FactoryOptions>(options: O):
238
10
  * Identical shape to LitFactoryOptions — a plain HTMLElement subclass with
239
11
  * no framework dependency. Light DOM only; Shadow DOM is out of scope.
240
12
  */
241
- type WebFactoryOptions<TDefault extends ElementType = ElementType, TProps extends AnyRecord = EmptyRecord, TVariants extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<TVariants> = Readonly<EmptyRecord>, TPluginProps extends AnyRecord = EmptyRecord> = FactoryOptions<TDefault, TProps, TVariants, TPreset, TPluginProps> & {
13
+ 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> & {
242
14
  readonly filterProps?: FilterPredicate;
243
15
  };
244
16
 
@@ -249,7 +21,7 @@ type UnknownProps = Record<string, unknown>;
249
21
  * Describes the public contract without exposing HTMLElement's internal members.
250
22
  * Variant key instance properties are typed via TVariants.
251
23
  */
252
- type WebContractComponent<TVariants extends Readonly<VariantMap> = Readonly<EmptyRecord>> = {
24
+ type WebContractComponent<TVariants extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPluginProps extends AnyRecord = EmptyRecord> = {
253
25
  new (): HTMLElement & {
254
26
  as: string | undefined;
255
27
  recipe: string | undefined;
@@ -258,9 +30,9 @@ type WebContractComponent<TVariants extends Readonly<VariantMap> = Readonly<Empt
258
30
  update(): void;
259
31
  } & {
260
32
  [K in Extract<keyof TVariants, string>]?: string | null;
261
- };
262
- /** The resolved strict mode for this component — usable by subclasses for custom enforcement. */
263
- readonly strict: Exclude<StrictMode, undefined>;
33
+ } & TPluginProps;
34
+ /** The resolved diagnostics for this component — usable by subclasses for custom enforcement. */
35
+ readonly diagnostics: Diagnostics;
264
36
  };
265
37
 
266
38
  /**
@@ -277,7 +49,7 @@ type WebContractComponent<TVariants extends Readonly<VariantMap> = Readonly<Empt
277
49
  * variants: { intent: { primary: 'btn--primary', ghost: 'btn--ghost' } },
278
50
  * defaults: { intent: 'primary' },
279
51
  * },
280
- * enforcement: { strict: 'warn' },
52
+ * enforcement: { diagnostics: warnDiagnostics },
281
53
  * })
282
54
  *
283
55
  * customElements.define('praxis-button', Button)
@@ -290,7 +62,7 @@ type WebContractComponent<TVariants extends Readonly<VariantMap> = Readonly<Empt
290
62
  * For non-reactive attributes (`aria-*`, `role`, `data-*`) call `element.update()`
291
63
  * after setting them to trigger an explicit pipeline re-run.
292
64
  */
293
- declare function createContractComponent<TDefault extends ElementType, TProps extends UnknownProps = EmptyRecord, TVariants extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends RecipeMap<TVariants> = Readonly<EmptyRecord>, TPluginProps extends AnyRecord = EmptyRecord>(options: WebFactoryOptions<TDefault, TProps, TVariants, TPreset, TPluginProps>): WebContractComponent<TVariants>;
65
+ 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>>;
294
66
 
295
67
  /**
296
68
  * Renders a praxis-kit web component to an HTML string without requiring a DOM.
@@ -303,4 +75,4 @@ declare function createContractComponent<TDefault extends ElementType, TProps ex
303
75
  */
304
76
  declare function renderToString(component: WebContractComponent, props?: UnknownProps, innerHTML?: string): string;
305
77
 
306
- export { type AnyFactoryOptions, type WebContractComponent, type WebFactoryOptions, createContractComponent, defineContractComponent, renderToString };
78
+ export { type WebContractComponent, type WebFactoryOptions, createContractComponent, renderToString };