praxis-kit 1.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.
- package/LICENSE +21 -0
- package/dist/chunk-KDUNVQK2.js +2059 -0
- package/dist/codemod/index.d.ts +21 -0
- package/dist/codemod/index.js +241955 -0
- package/dist/eslint/index.d.ts +84 -0
- package/dist/eslint/index.js +1068 -0
- package/dist/lit/index.d.ts +304 -0
- package/dist/lit/index.js +1887 -0
- package/dist/merge-refs-CfBqh1UO.d.ts +374 -0
- package/dist/preact/index.d.ts +292 -0
- package/dist/preact/index.js +2062 -0
- package/dist/react/index.d.ts +27 -0
- package/dist/react/index.js +197 -0
- package/dist/react/legacy.d.ts +21 -0
- package/dist/react/legacy.js +209 -0
- package/dist/solid/index.d.ts +287 -0
- package/dist/solid/index.js +1837 -0
- package/dist/svelte/index.d.ts +343 -0
- package/dist/svelte/index.js +1723 -0
- package/dist/tailwind/index.d.ts +138 -0
- package/dist/tailwind/index.js +508 -0
- package/dist/ts-plugin/index.cjs +191 -0
- package/dist/ts-plugin/index.d.cts +10 -0
- package/dist/vite-plugin/index.d.ts +395 -0
- package/dist/vite-plugin/index.js +1329 -0
- package/dist/vue/index.d.ts +309 -0
- package/dist/vue/index.js +1922 -0
- package/dist/web/index.d.ts +302 -0
- package/dist/web/index.js +1858 -0
- package/package.json +176 -0
|
@@ -0,0 +1,302 @@
|
|
|
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 ClassName = string | string[];
|
|
15
|
+
|
|
16
|
+
type EmptyRecord = Record<never, never>;
|
|
17
|
+
|
|
18
|
+
type IntrinsicProps = AnyRecord & {
|
|
19
|
+
role?: AriaRole;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type NonEmptyArray<T> = [T, ...T[]];
|
|
23
|
+
|
|
24
|
+
type TagMap = Partial<Record<IntrinsicTag | (string & {}), ClassName>>;
|
|
25
|
+
|
|
26
|
+
type StrictMode = boolean | 'warn' | 'async-warn' | 'throw';
|
|
27
|
+
|
|
28
|
+
type CardinalityInput = {
|
|
29
|
+
min?: number;
|
|
30
|
+
max?: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type ChildRuleMatch<T, U extends T = T> = (child: T) => child is U;
|
|
34
|
+
|
|
35
|
+
type ChildRulePosition = 'first' | 'last' | 'any';
|
|
36
|
+
|
|
37
|
+
type ChildRuleInput<T = unknown, U extends T = T> = {
|
|
38
|
+
name: string;
|
|
39
|
+
match: ChildRuleMatch<T, U>;
|
|
40
|
+
cardinality?: CardinalityInput;
|
|
41
|
+
position?: ChildRulePosition;
|
|
42
|
+
/**
|
|
43
|
+
* Optional component-type reference for O(1) dispatch index.
|
|
44
|
+
* When provided for every rule, the matcher reads child.type instead of
|
|
45
|
+
* calling every match function on every child (O(n×m) → O(n+m)).
|
|
46
|
+
*/
|
|
47
|
+
type?: unknown;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type ValidResult = {
|
|
51
|
+
valid: true;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
|
|
55
|
+
|
|
56
|
+
type VariantValue = string | string[];
|
|
57
|
+
|
|
58
|
+
type VariantStates<K extends string = string> = Record<K, VariantValue>;
|
|
59
|
+
|
|
60
|
+
type VariantMap<V extends string = string, K extends string = string> = Record<V, VariantStates<K>>;
|
|
61
|
+
|
|
62
|
+
type VariantKey<V extends VariantMap, K extends keyof V> = StringToBoolean<keyof V[K] & string>;
|
|
63
|
+
|
|
64
|
+
type RequireAtLeastOneIfNotEmpty<T> = keyof T extends never ? EmptyRecord : RequireAtLeastOne<T>;
|
|
65
|
+
type CompoundVariantConditionValue<V extends VariantMap, K extends keyof V> = VariantKey<V, K> | NonEmptyArray<VariantKey<V, K>>;
|
|
66
|
+
type CompoundVariantConditions<V extends VariantMap> = Simplify<{
|
|
67
|
+
[K in keyof V]: CompoundVariantConditionValue<V, K>;
|
|
68
|
+
}>;
|
|
69
|
+
type CompoundVariantRequiredConditions<V extends VariantMap> = RequireAtLeastOneIfNotEmpty<CompoundVariantConditions<V>>;
|
|
70
|
+
type CompoundVariantBase<V extends VariantMap> = keyof V extends never ? EmptyRecord : CompoundVariantRequiredConditions<V>;
|
|
71
|
+
type CompoundVariant<V extends VariantMap> = CompoundVariantBase<V> & {
|
|
72
|
+
class: VariantValue;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
interface CVACompounds<V extends VariantMap> {
|
|
76
|
+
compoundVariants?: readonly CompoundVariant<V>[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The full optional prop surface exposed to callers for a given variant map. */
|
|
80
|
+
type VariantProps<V extends VariantMap> = {
|
|
81
|
+
[K in keyof V]?: VariantKey<V, K>;
|
|
82
|
+
};
|
|
83
|
+
type DefaultVariants<V extends VariantMap> = {
|
|
84
|
+
[K in keyof V]?: VariantKey<V, K>;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
interface CVADefaults<V extends VariantMap> {
|
|
88
|
+
defaultVariants?: DefaultVariants<V>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface CVAVariants<V extends VariantMap> {
|
|
92
|
+
variants?: V;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A partial selection of variant states authored at factory definition time.
|
|
97
|
+
*
|
|
98
|
+
* Uses `keyof V[K]` directly (not `VariantKey`) so TypeScript can eagerly
|
|
99
|
+
* resolve the union at constraint-check time without deferred conditional types.
|
|
100
|
+
*/
|
|
101
|
+
type VariantSelection<V extends VariantMap> = {
|
|
102
|
+
[K in keyof V]?: keyof V[K];
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A static, immutable map of named presets to partial variant selections.
|
|
107
|
+
*
|
|
108
|
+
* Presets are named bundles of variant props that callers activate by key,
|
|
109
|
+
* avoiding the need to repeat variant combinations at each call site.
|
|
110
|
+
*/
|
|
111
|
+
type PresetMap<V extends VariantMap = VariantMap> = Readonly<Record<string, VariantSelection<V>>>;
|
|
112
|
+
|
|
113
|
+
type PresetTarget<TVariants extends VariantMap = VariantMap> = VariantSelection<TVariants>;
|
|
114
|
+
|
|
115
|
+
interface BaseClassOptions {
|
|
116
|
+
baseClassName?: ClassName;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
type ClassPipelineFn = (tag: unknown, props: AnyRecord, className?: ClassName, variantKey?: string) => string;
|
|
120
|
+
|
|
121
|
+
interface PresetOptions<TVariants extends VariantMap = VariantMap> {
|
|
122
|
+
presetMap?: Record<string, PresetTarget<TVariants>>;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
interface TagMapOptions {
|
|
126
|
+
tagMap?: TagMap;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
type CompositionOptions<TVariants extends VariantMap = VariantMap> = Simplify<TagMapOptions & PresetOptions<TVariants>>;
|
|
130
|
+
|
|
131
|
+
type CVASystemOptions<TVariants extends VariantMap = VariantMap> = Simplify<CVAVariants<TVariants> & CVADefaults<TVariants> & CVACompounds<TVariants>>;
|
|
132
|
+
|
|
133
|
+
type StyleOptions<TVariants extends VariantMap = VariantMap> = Simplify<BaseClassOptions & CVASystemOptions<TVariants>>;
|
|
134
|
+
|
|
135
|
+
type ClassPipelineOptions<TVariants extends VariantMap = VariantMap> = Simplify<StyleOptions<TVariants> & CompositionOptions<TVariants>>;
|
|
136
|
+
|
|
137
|
+
type OwnedPropKeys = ReadonlySet<string>;
|
|
138
|
+
|
|
139
|
+
type ClassPlugin<TProps extends AnyRecord = EmptyRecord> = Readonly<{
|
|
140
|
+
pipeline: ClassPipelineFn;
|
|
141
|
+
ownedKeys?: OwnedPropKeys;
|
|
142
|
+
readonly _pluginProps?: TProps;
|
|
143
|
+
}>;
|
|
144
|
+
|
|
145
|
+
type ClassPluginFactory<TProps extends AnyRecord = EmptyRecord> = <V extends VariantMap>(options: ClassPipelineOptions<V>, strict: StrictMode) => ClassPlugin<TProps>;
|
|
146
|
+
|
|
147
|
+
type AriaContext = {
|
|
148
|
+
readonly tag: IntrinsicTag;
|
|
149
|
+
readonly implicitRole: AriaRole | undefined;
|
|
150
|
+
readonly effectiveRole: string | undefined;
|
|
151
|
+
readonly props: ReadonlyDeep<IntrinsicProps>;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
type RemoveAttributeFixKind = `removeAttribute:${string}`;
|
|
155
|
+
type InjectLiveFixKind = `injectLive:${string}`;
|
|
156
|
+
type FixKind = 'removeRole' | 'setRole' | 'normalizeRelevantAll' | RemoveAttributeFixKind | InjectLiveFixKind;
|
|
157
|
+
|
|
158
|
+
type AriaFixResult = {
|
|
159
|
+
applied: false;
|
|
160
|
+
next: ReadonlyDeep<IntrinsicProps>;
|
|
161
|
+
} | {
|
|
162
|
+
applied: true;
|
|
163
|
+
next: ReadonlyDeep<IntrinsicProps>;
|
|
164
|
+
previous: ReadonlyDeep<IntrinsicProps>;
|
|
165
|
+
};
|
|
166
|
+
type AriaFix = {
|
|
167
|
+
readonly kind: FixKind;
|
|
168
|
+
readonly priority?: number;
|
|
169
|
+
readonly source?: string;
|
|
170
|
+
readonly apply: (context: AriaContext) => AriaFixResult;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
type Severity = 'error' | 'warning' | (string & {});
|
|
174
|
+
|
|
175
|
+
type AriaInvalidBase<M extends string = string> = {
|
|
176
|
+
valid: false;
|
|
177
|
+
severity: Severity;
|
|
178
|
+
message: M;
|
|
179
|
+
attribute?: string;
|
|
180
|
+
};
|
|
181
|
+
type AriaInvalidWithFix<M extends string = string> = AriaInvalidBase<M> & {
|
|
182
|
+
fixable: true;
|
|
183
|
+
fix: AriaFix;
|
|
184
|
+
};
|
|
185
|
+
type AriaInvalidWithoutFix<M extends string = string> = AriaInvalidBase<M> & {
|
|
186
|
+
fixable: false;
|
|
187
|
+
};
|
|
188
|
+
type AriaInvalidResult<M extends string = string> = AriaInvalidWithFix<M> | AriaInvalidWithoutFix<M>;
|
|
189
|
+
type AriaResult = ValidResult | AriaInvalidResult;
|
|
190
|
+
|
|
191
|
+
type AriaRule<C extends AriaContext = AriaContext> = (context: C) => readonly AriaResult[];
|
|
192
|
+
|
|
193
|
+
type PropNormalizer = (props: Readonly<AnyRecord & IntrinsicProps>) => Partial<AnyRecord & IntrinsicProps>;
|
|
194
|
+
|
|
195
|
+
type EnforcementOptions<TAllowed extends ElementType = ElementType> = {
|
|
196
|
+
readonly strict?: StrictMode;
|
|
197
|
+
readonly aria?: readonly AriaRule[];
|
|
198
|
+
readonly children?: readonly ChildRuleInput[];
|
|
199
|
+
readonly props?: readonly PropNormalizer[];
|
|
200
|
+
/** Restricts the `as` prop to this set of tags. Violations route through strict mode. */
|
|
201
|
+
readonly allowedAs?: readonly TAllowed[];
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
type StylingOptions<V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends PresetMap<V> = Readonly<EmptyRecord>, TPluginProps extends AnyRecord = EmptyRecord> = {
|
|
205
|
+
readonly base?: ClassName;
|
|
206
|
+
readonly variants?: V;
|
|
207
|
+
readonly defaults?: Partial<VariantProps<V>>;
|
|
208
|
+
readonly compounds?: readonly CompoundVariant<V>[];
|
|
209
|
+
readonly presets?: TPreset;
|
|
210
|
+
readonly tags?: Readonly<TagMap>;
|
|
211
|
+
readonly plugin?: ClassPluginFactory<TPluginProps>;
|
|
212
|
+
readonly precomputedClasses?: Readonly<Record<string, string>>;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
type NormalizeFn<Props extends AnyRecord = AnyRecord> = {
|
|
216
|
+
normalize(props: Readonly<Props & IntrinsicProps>): Props & IntrinsicProps;
|
|
217
|
+
}['normalize'];
|
|
218
|
+
type FactoryOptions<TDefault extends ElementType = ElementType, Props extends AnyRecord = EmptyRecord, V extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends PresetMap<V> = Readonly<EmptyRecord>, TPluginProps extends AnyRecord = EmptyRecord, TAllowed extends ElementType = ElementType> = {
|
|
219
|
+
readonly tag?: TDefault;
|
|
220
|
+
readonly name?: string;
|
|
221
|
+
readonly defaults?: Partial<NoInfer<Props>>;
|
|
222
|
+
readonly normalize?: NormalizeFn<NoInfer<Props>>;
|
|
223
|
+
readonly styling?: StylingOptions<V, TPreset, TPluginProps>;
|
|
224
|
+
readonly enforcement?: EnforcementOptions<TAllowed>;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
type FilterPredicate = (key: string, variantKeys: ReadonlySet<string>) => boolean;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Options accepted by createContractComponent in the web adapter.
|
|
231
|
+
*
|
|
232
|
+
* Identical shape to LitFactoryOptions — a plain HTMLElement subclass with
|
|
233
|
+
* no framework dependency. Light DOM only; Shadow DOM is out of scope.
|
|
234
|
+
*/
|
|
235
|
+
type WebFactoryOptions<TDefault extends ElementType = ElementType, TProps extends AnyRecord = EmptyRecord, TVariants extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends PresetMap<TVariants> = Readonly<EmptyRecord>, TPluginProps extends AnyRecord = EmptyRecord> = FactoryOptions<TDefault, TProps, TVariants, TPreset, TPluginProps> & {
|
|
236
|
+
readonly filterProps?: FilterPredicate;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
type UnknownProps = Record<string, unknown>;
|
|
240
|
+
/**
|
|
241
|
+
* Constructor type returned by createContractComponent.
|
|
242
|
+
*
|
|
243
|
+
* Describes the public contract without exposing HTMLElement's internal members.
|
|
244
|
+
* Variant key instance properties are typed via TVariants.
|
|
245
|
+
*/
|
|
246
|
+
type WebContractComponent<TVariants extends Readonly<VariantMap> = Readonly<EmptyRecord>> = {
|
|
247
|
+
new (): HTMLElement & {
|
|
248
|
+
as: string | undefined;
|
|
249
|
+
variantKey: string | undefined;
|
|
250
|
+
praxisClass: string | undefined;
|
|
251
|
+
/** Re-runs the pipeline — call after setting non-reactive attributes (aria-*, role, data-*). */
|
|
252
|
+
update(): void;
|
|
253
|
+
} & {
|
|
254
|
+
[K in Extract<keyof TVariants, string>]?: string | null;
|
|
255
|
+
};
|
|
256
|
+
/** The resolved strict mode for this component — usable by subclasses for custom enforcement. */
|
|
257
|
+
readonly strict: Exclude<StrictMode, undefined>;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Creates a plain `HTMLElement` subclass with praxis-kit contracts applied.
|
|
262
|
+
*
|
|
263
|
+
* No framework dependency. Register with `customElements.define()`:
|
|
264
|
+
*
|
|
265
|
+
* ```ts
|
|
266
|
+
* const Button = createContractComponent({
|
|
267
|
+
* tag: 'button',
|
|
268
|
+
* name: 'Button',
|
|
269
|
+
* styling: {
|
|
270
|
+
* base: 'btn',
|
|
271
|
+
* variants: { intent: { primary: 'btn--primary', ghost: 'btn--ghost' } },
|
|
272
|
+
* defaults: { intent: 'primary' },
|
|
273
|
+
* },
|
|
274
|
+
* enforcement: { strict: 'warn' },
|
|
275
|
+
* })
|
|
276
|
+
*
|
|
277
|
+
* customElements.define('praxis-button', Button)
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* The pipeline runs synchronously on `connectedCallback` and on every
|
|
281
|
+
* `attributeChangedCallback` for praxis-owned attributes (variant keys,
|
|
282
|
+
* `as`, `variant-key`, `praxis-class`).
|
|
283
|
+
*
|
|
284
|
+
* For non-reactive attributes (`aria-*`, `role`, `data-*`) call `element.update()`
|
|
285
|
+
* after setting them to trigger an explicit pipeline re-run.
|
|
286
|
+
*/
|
|
287
|
+
declare function createContractComponent<TDefault extends ElementType, TProps extends UnknownProps = EmptyRecord, TVariants extends Readonly<VariantMap> = Readonly<EmptyRecord>, TPreset extends PresetMap<TVariants> = Readonly<EmptyRecord>, TPluginProps extends AnyRecord = EmptyRecord>(options: WebFactoryOptions<TDefault, TProps, TVariants, TPreset, TPluginProps>): WebContractComponent<TVariants>;
|
|
288
|
+
|
|
289
|
+
declare function defineContractComponent<O extends FactoryOptions>(options: O): <R>(factory: (options: O) => R) => R;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Renders a praxis-kit web component to an HTML string without requiring a DOM.
|
|
293
|
+
*
|
|
294
|
+
* Tag polymorphism works correctly in SSR — `options.tag` and the `as` prop
|
|
295
|
+
* are resolved directly to the HTML element tag.
|
|
296
|
+
*
|
|
297
|
+
* `innerHTML` is treated as a pre-sanitized HTML string and inserted verbatim.
|
|
298
|
+
* Callers are responsible for escaping any untrusted content before passing it.
|
|
299
|
+
*/
|
|
300
|
+
declare function renderToString(component: WebContractComponent, props?: UnknownProps, innerHTML?: string): string;
|
|
301
|
+
|
|
302
|
+
export { type WebContractComponent, type WebFactoryOptions, createContractComponent, defineContractComponent, renderToString };
|