praxis-kit 0.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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +77 -0
  3. package/dist/_shared/diagnostics.d.ts +312 -0
  4. package/dist/_shared/diagnostics.js +360 -0
  5. package/dist/build-runtime-CJ_nQEaZ.js +5065 -0
  6. package/dist/codemod/index.d.ts +2 -0
  7. package/dist/codemod/index.js +176520 -0
  8. package/dist/contract/index.d.ts +677 -0
  9. package/dist/contract/index.js +341 -0
  10. package/dist/eslint/index.d.ts +90 -0
  11. package/dist/eslint/index.js +1047 -0
  12. package/dist/guards/index.d.ts +78 -0
  13. package/dist/guards/index.js +118 -0
  14. package/dist/html/index.d.ts +151 -0
  15. package/dist/html/index.js +1244 -0
  16. package/dist/index-BIBd_iPD.d.ts +951 -0
  17. package/dist/lit/index.d.ts +862 -0
  18. package/dist/lit/index.js +4893 -0
  19. package/dist/preact/index.d.ts +796 -0
  20. package/dist/preact/index.js +5043 -0
  21. package/dist/react/index.d.ts +28 -0
  22. package/dist/react/index.js +205 -0
  23. package/dist/react/legacy.d.ts +29 -0
  24. package/dist/react/legacy.js +80 -0
  25. package/dist/solid/index.d.ts +728 -0
  26. package/dist/solid/index.js +4821 -0
  27. package/dist/svelte/Polymorphic.svelte +190 -0
  28. package/dist/svelte/_polymorphic-runtime.d.ts +102 -0
  29. package/dist/svelte/_polymorphic-runtime.js +371 -0
  30. package/dist/svelte/index.d.ts +994 -0
  31. package/dist/svelte/index.js +4482 -0
  32. package/dist/tailwind/index.d.ts +197 -0
  33. package/dist/tailwind/index.js +767 -0
  34. package/dist/tailwind/safelist.css +20 -0
  35. package/dist/ts-plugin/index.cjs +166 -0
  36. package/dist/ts-plugin/index.d.cts +9 -0
  37. package/dist/utils/index.d.ts +19 -0
  38. package/dist/utils/index.js +21 -0
  39. package/dist/vite-plugin/index.d.ts +200 -0
  40. package/dist/vite-plugin/index.js +2106 -0
  41. package/dist/vue/index.d.ts +729 -0
  42. package/dist/vue/index.js +4945 -0
  43. package/dist/web/index.d.ts +832 -0
  44. package/dist/web/index.js +4868 -0
  45. package/package.json +258 -0
@@ -0,0 +1,78 @@
1
+ import "clsx";
2
+ import "../_shared/diagnostics.js";
3
+ import "type-fest";
4
+ //#region ../../lib/foundation/src/string-map.d.ts
5
+ /**
6
+ * A string-keyed object whose values are of type `T`.
7
+ */
8
+ type StringMap<T = unknown> = Record<string, T>;
9
+ /**
10
+ * A string-keyed object with values of unknown type.
11
+ */
12
+ type AnyRecord = StringMap<unknown>;
13
+ //#endregion
14
+ //#region ../../lib/foundation/src/type-guards.d.ts
15
+ export declare function isString(value: unknown): value is string;
16
+ export declare function isObject(value: unknown, excludeArrays: true): value is AnyRecord;
17
+ export declare function isObject(value: unknown, excludeArrays?: false): value is object;
18
+ //#endregion
19
+ //#region ../../lib/primitive/src/guards/children/component-id.d.ts
20
+ /**
21
+ * Well-known Symbol stamped onto every component created by praxis-kit factories.
22
+ * Stores the factory's defaultTag — the tag that renders when no `as` prop is given.
23
+ * HOC wrappers must propagate it: `Wrapped[COMPONENT_DEFAULT_TAG] = Original[COMPONENT_DEFAULT_TAG]`.
24
+ */
25
+ export declare const COMPONENT_DEFAULT_TAG: unique symbol;
26
+ /**
27
+ * Stamps `COMPONENT_DEFAULT_TAG` onto a component function/object, so `isTag()`
28
+ * (and every built-in/custom `enforcement.children` rule built on it) resolves it
29
+ * to `tag` — the same recognition a component created via `createContractComponent`
30
+ * gets automatically. A transparent wrapper around a praxis-kit component (added
31
+ * purely to narrow prop types, for example) is a *different* function object with
32
+ * no `COMPONENT_DEFAULT_TAG` of its own, so without this it silently stops being
33
+ * recognized as a valid child by every parent contract. Returns `component` for
34
+ * call-site chaining, e.g. `export const Wrapped = markComponentTag(WrapperFn, 'source')`.
35
+ */
36
+ export declare function markComponentTag<T extends object>(component: T, tag: string): T;
37
+ /** Reads `COMPONENT_DEFAULT_TAG` off a component function/object, if present. */
38
+ export declare function getComponentDefaultTag(component: unknown): string | undefined;
39
+ //#endregion
40
+ //#region ../../lib/primitive/src/guards/children/is-tag.d.ts
41
+ /**
42
+ * Resolves the effective HTML tag for a vnode:
43
+ * - native element: returns its type string directly
44
+ * - praxis-kit component: resolves `as ?? defaultTag`, mirroring render-time logic
45
+ * - anything else: returns undefined
46
+ */
47
+ export declare function getTag(child: unknown): string | undefined;
48
+ /**
49
+ * Checks whether a vnode resolves to one of the given intrinsic tag names.
50
+ * Matches native elements directly, and praxis-kit components by resolving
51
+ * `as ?? defaultTag` — the same logic used at render time.
52
+ *
53
+ * Two call forms are supported:
54
+ * isTag('img')(child) — curried, composable with Array#filter
55
+ * isTag(child, 'img') — direct, reads naturally in if-blocks
56
+ */
57
+ type TagChild = {
58
+ type: unknown;
59
+ };
60
+ export declare function isTag(tag: string, ...tags: readonly string[]): (child: unknown) => child is TagChild;
61
+ export declare function isTag(child: unknown, tag: string, ...tags: readonly string[]): boolean;
62
+ /**
63
+ * A vnode (or text node) that qualifies as flow content: text nodes
64
+ * (string/number) always qualify, and elements/components qualify unless
65
+ * their resolved tag is blocked — see `isFlowContent`.
66
+ */
67
+ type FlowContentChild = string | number | TagChild;
68
+ /**
69
+ * Checks whether a vnode is flow content per the HTML content model: text nodes
70
+ * (string/number) always qualify, and elements/components qualify unless their
71
+ * resolved tag is in the blocked set.
72
+ *
73
+ * Returns a type guard (not a plain boolean predicate) so it can be used
74
+ * directly as a `ChildRuleInput.match`, which requires the narrowed type.
75
+ */
76
+ export declare function isFlowContent(...blockedTags: readonly string[]): (child: unknown) => child is FlowContentChild;
77
+ //#endregion
78
+ export type { FlowContentChild, TagChild };
@@ -0,0 +1,118 @@
1
+ //#region ../../lib/foundation/src/type-guards.ts
2
+ function isString(value) {
3
+ return typeof value === "string";
4
+ }
5
+ function isNumber(value) {
6
+ return typeof value === "number";
7
+ }
8
+ function isFunction(value) {
9
+ return typeof value === "function";
10
+ }
11
+ function isObject(value, excludeArrays = false) {
12
+ if (value === null || typeof value !== "object") return false;
13
+ return excludeArrays ? !Array.isArray(value) : true;
14
+ }
15
+ //#endregion
16
+ //#region ../../lib/primitive/src/guards/children/component-id.ts
17
+ /**
18
+ * Well-known Symbol stamped onto every component created by praxis-kit factories.
19
+ * Stores the factory's defaultTag — the tag that renders when no `as` prop is given.
20
+ * HOC wrappers must propagate it: `Wrapped[COMPONENT_DEFAULT_TAG] = Original[COMPONENT_DEFAULT_TAG]`.
21
+ */
22
+ const COMPONENT_DEFAULT_TAG = Symbol.for("praxis.component-default-tag");
23
+ function isMarkable(value) {
24
+ return isFunction(value) || isObject(value);
25
+ }
26
+ /**
27
+ * Stamps one or more `WithComponentId` keys onto a component function/object as
28
+ * non-writable, non-enumerable properties — accidental plain-assignment overwrite
29
+ * (`Wrapped[COMPONENT_DEFAULT_TAG] = 'div'` clobbering an already-stamped value) is
30
+ * rejected, but `configurable: true` keeps it re-stampable through this same helper
31
+ * (e.g. a component factory re-running in dev/HMR), rather than throwing outright.
32
+ * Single choke point every `mark*` helper below funnels through, so future metadata
33
+ * keys only need a property list here, not a new stamping mechanism.
34
+ */
35
+ function defineComponentMetadata(component, metadata) {
36
+ for (const key of Object.getOwnPropertySymbols(metadata)) Object.defineProperty(component, key, {
37
+ value: metadata[key],
38
+ writable: false,
39
+ configurable: true,
40
+ enumerable: false
41
+ });
42
+ return component;
43
+ }
44
+ /**
45
+ * Stamps `COMPONENT_DEFAULT_TAG` onto a component function/object, so `isTag()`
46
+ * (and every built-in/custom `enforcement.children` rule built on it) resolves it
47
+ * to `tag` — the same recognition a component created via `createContractComponent`
48
+ * gets automatically. A transparent wrapper around a praxis-kit component (added
49
+ * purely to narrow prop types, for example) is a *different* function object with
50
+ * no `COMPONENT_DEFAULT_TAG` of its own, so without this it silently stops being
51
+ * recognized as a valid child by every parent contract. Returns `component` for
52
+ * call-site chaining, e.g. `export const Wrapped = markComponentTag(WrapperFn, 'source')`.
53
+ */
54
+ function markComponentTag(component, tag) {
55
+ return defineComponentMetadata(component, { [COMPONENT_DEFAULT_TAG]: tag });
56
+ }
57
+ /** Reads `COMPONENT_DEFAULT_TAG` off a component function/object, if present. */
58
+ function getComponentDefaultTag(component) {
59
+ if (!isMarkable(component)) return void 0;
60
+ const tag = component[COMPONENT_DEFAULT_TAG];
61
+ return typeof tag === "string" ? tag : void 0;
62
+ }
63
+ //#endregion
64
+ //#region ../../lib/primitive/src/guards/children/is-tag.ts
65
+ function getAsProp(child) {
66
+ if (!isObject(child) || !("props" in child)) return void 0;
67
+ const { props } = child;
68
+ if (!isObject(props)) return void 0;
69
+ const as = Reflect.get(props, "as");
70
+ return isString(as) && as !== "" ? as : void 0;
71
+ }
72
+ /**
73
+ * Resolves the effective HTML tag for a vnode:
74
+ * - native element: returns its type string directly
75
+ * - praxis-kit component: resolves `as ?? defaultTag`, mirroring render-time logic
76
+ * - anything else: returns undefined
77
+ */
78
+ function getTag(child) {
79
+ if (!isObject(child) || !("type" in child)) return void 0;
80
+ const { type: t } = child;
81
+ if (isString(t)) return t;
82
+ if (typeof t === "function" || isObject(t)) {
83
+ const defaultTag = Reflect.get(t, COMPONENT_DEFAULT_TAG);
84
+ if (!isString(defaultTag)) return void 0;
85
+ return getAsProp(child) ?? defaultTag;
86
+ }
87
+ }
88
+ function isTag(...args) {
89
+ if (isString(args[0])) {
90
+ const set = new Set(args);
91
+ return (child) => {
92
+ const tag = getTag(child);
93
+ return tag !== void 0 && set.has(tag);
94
+ };
95
+ }
96
+ const [child, ...tags] = args;
97
+ const set = new Set(tags);
98
+ const tag = getTag(child);
99
+ return tag !== void 0 && set.has(tag);
100
+ }
101
+ /**
102
+ * Checks whether a vnode is flow content per the HTML content model: text nodes
103
+ * (string/number) always qualify, and elements/components qualify unless their
104
+ * resolved tag is in the blocked set.
105
+ *
106
+ * Returns a type guard (not a plain boolean predicate) so it can be used
107
+ * directly as a `ChildRuleInput.match`, which requires the narrowed type.
108
+ */
109
+ function isFlowContent(...blockedTags) {
110
+ const set = new Set(blockedTags);
111
+ return (child) => {
112
+ if (isString(child) || isNumber(child)) return true;
113
+ const tag = getTag(child);
114
+ return tag === void 0 || !set.has(tag);
115
+ };
116
+ }
117
+ //#endregion
118
+ export { COMPONENT_DEFAULT_TAG, getComponentDefaultTag, getTag, isFlowContent, isObject, isString, isTag, markComponentTag };
@@ -0,0 +1,151 @@
1
+ import "clsx";
2
+ import { DiagnosticCode, DiagnosticInput } from "../_shared/diagnostics.js";
3
+ import { ReadonlyDeep } from "type-fest";
4
+ //#region ../../lib/foundation/src/string-map.d.ts
5
+ /**
6
+ * A string-keyed object whose values are of type `T`.
7
+ */
8
+ type StringMap<T = unknown> = Record<string, T>;
9
+ /**
10
+ * A string-keyed object with values of unknown type.
11
+ */
12
+ type AnyRecord = StringMap<unknown>;
13
+ //#endregion
14
+ //#region ../../lib/primitive/src/types/intrinsic-tag.d.ts
15
+ type IntrinsicTag = keyof HTMLElementTagNameMap;
16
+ //#endregion
17
+ //#region ../../lib/primitive/src/constants/aria/known-aria-roles.d.ts
18
+ 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"];
19
+ type KnownAriaRole = (typeof KNOWN_ARIA_ROLES)[number];
20
+ //#endregion
21
+ //#region ../../lib/primitive/src/types/primitives/index.d.ts
22
+ type AriaRole = KnownAriaRole | (string & {});
23
+ type IntrinsicProps = AnyRecord & {
24
+ role?: AriaRole;
25
+ };
26
+ //#endregion
27
+ //#region ../../lib/primitive/src/types/validation/valid-result.d.ts
28
+ type ValidResult = {
29
+ valid: true;
30
+ };
31
+ //#endregion
32
+ //#region ../../lib/primitive/src/types/aria-rule/aria-context.d.ts
33
+ type AriaContext = {
34
+ /**
35
+ * The intrinsic HTML tag being evaluated.
36
+ */
37
+ readonly tag: IntrinsicTag;
38
+ /**
39
+ * The implicit ARIA role associated with the intrinsic tag.
40
+ */
41
+ readonly implicitRole: AriaRole | undefined;
42
+ /**
43
+ * The effective ARIA role after considering the element's explicit
44
+ * `role` attribute or component-provided role.
45
+ */
46
+ readonly effectiveRole: string | undefined;
47
+ /**
48
+ * The component's props available to the ARIA policy engine.
49
+ */
50
+ readonly props: ReadonlyDeep<IntrinsicProps>;
51
+ /**
52
+ * Variant prop names declared by the component.
53
+ *
54
+ * The adapter uses these names to determine which props are intercepted
55
+ * before reaching the DOM. A rule asserting a fact about a real HTML
56
+ * attribute should therefore treat a key present here as a component
57
+ * variant rather than a DOM attribute.
58
+ *
59
+ * An empty set indicates no variant props are declared — the case for
60
+ * evaluations with no factory context, such as `AriaPolicyEngine.evaluate`.
61
+ */
62
+ readonly variantKeys: ReadonlySet<string>;
63
+ };
64
+ //#endregion
65
+ //#region ../../lib/primitive/src/types/aria-rule/fix-kind.d.ts
66
+ type RemoveAttributeFixKind = 'removeAttribute';
67
+ type InjectLiveFixKind = 'injectLive';
68
+ type FixKind = 'removeRole' | 'setRole' | 'normalizeRelevantAll' | RemoveAttributeFixKind | InjectLiveFixKind;
69
+ //#endregion
70
+ //#region ../../lib/primitive/src/types/aria-rule/aria-fix.d.ts
71
+ type AriaFixResult = {
72
+ applied: false;
73
+ next: ReadonlyDeep<IntrinsicProps>;
74
+ } | {
75
+ applied: true;
76
+ next: ReadonlyDeep<IntrinsicProps>;
77
+ previous: ReadonlyDeep<IntrinsicProps>;
78
+ };
79
+ type AriaFix = {
80
+ readonly kind: FixKind;
81
+ /** The attribute a `'removeAttribute'`/`'injectLive'` fix targets — always set for those
82
+ * kinds, absent for kinds with no single-attribute target (`'removeRole'`, etc.). */
83
+ readonly attribute?: string;
84
+ readonly priority?: number;
85
+ readonly source?: string;
86
+ readonly apply: (context: AriaContext) => AriaFixResult;
87
+ };
88
+ //#endregion
89
+ //#region ../../lib/primitive/src/types/aria-rule/severity.d.ts
90
+ type Severity = 'error' | 'warning' | (string & {});
91
+ //#endregion
92
+ //#region ../../lib/primitive/src/types/aria-rule/aria-result.d.ts
93
+ type AriaInvalidBase<M extends string = string> = {
94
+ valid: false;
95
+ severity: Severity;
96
+ message?: M;
97
+ attribute?: string;
98
+ diagnostic?: DiagnosticInput;
99
+ };
100
+ type AriaInvalidWithFix<M extends string = string> = AriaInvalidBase<M> & {
101
+ fixable: true;
102
+ fix: AriaFix;
103
+ };
104
+ type AriaInvalidWithoutFix<M extends string = string> = AriaInvalidBase<M> & {
105
+ fixable: false;
106
+ };
107
+ type AriaInvalidResult<M extends string = string> = AriaInvalidWithFix<M> | AriaInvalidWithoutFix<M>;
108
+ type AriaResult = ValidResult | AriaInvalidResult;
109
+ //#endregion
110
+ //#region ../../lib/primitive/src/types/aria-rule/aria-rule.d.ts
111
+ type AriaRule<C extends AriaContext = AriaContext> = ((context: C) => readonly AriaResult[]) & {
112
+ readonly readsProps?: readonly string[];
113
+ readonly tags?: readonly string[];
114
+ };
115
+ //#endregion
116
+ //#region ../core/src/html/aria-rules.d.ts
117
+ export declare const landmarkRoleRule: AriaRule;
118
+ export declare function requireAccessibleName({ tag, props }: AriaContext): readonly AriaResult[];
119
+ export declare const landmarkAccessibleNameRule: AriaRule;
120
+ export declare const HTML_ARIA_RULES: readonly AriaRule[];
121
+ //#endregion
122
+ //#region ../core/src/html/role-restrictions.d.ts
123
+ export declare const roleNotPermittedRule: AriaRule;
124
+ //#endregion
125
+ //#region ../core/src/html/anchor-rules.d.ts
126
+ export declare const dangerousHrefRule: AriaRule;
127
+ export declare const roleButtonWithHrefRule: AriaRule;
128
+ export declare const ariaDisabledInertRule: AriaRule;
129
+ export declare const ANCHOR_RULES: readonly AriaRule[];
130
+ //#endregion
131
+ //#region ../core/src/html/input-rules.d.ts
132
+ export declare const supportedInputTypeRule: AriaRule;
133
+ export declare const checkedRequiresCheckableTypeRule: AriaRule;
134
+ export declare const multipleRequiresSupportedTypeRule: AriaRule;
135
+ export declare const maxLengthRequiresTextTypeRule: AriaRule;
136
+ export declare const minLengthRequiresTextTypeRule: AriaRule;
137
+ export declare const patternRequiresTextTypeRule: AriaRule;
138
+ export declare const minRequiresNumericTypeRule: AriaRule;
139
+ export declare const maxRequiresNumericTypeRule: AriaRule;
140
+ export declare const stepRequiresNumericTypeRule: AriaRule;
141
+ export declare const acceptRequiresFileTypeRule: AriaRule;
142
+ export declare const captureRequiresFileTypeRule: AriaRule;
143
+ export declare const sizeRequiresTextTypeRule: AriaRule;
144
+ export declare const altRequiresImageTypeRule: AriaRule;
145
+ export declare const heightRequiresImageTypeRule: AriaRule;
146
+ export declare const widthRequiresImageTypeRule: AriaRule;
147
+ export declare const inputAccessibleNameRule: AriaRule;
148
+ export declare const passwordAutocompleteRule: AriaRule;
149
+ export declare const requiredReadOnlyConflictRule: AriaRule;
150
+ export declare const INPUT_RULES: readonly AriaRule[];
151
+ //#endregion