@a11y-hud/react 0.2.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 +26 -0
- package/dist/index.cjs +70 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arthur Vasconcelos
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
This software includes icons from Lucide (https://lucide.dev/).
|
|
26
|
+
See LICENSE-ICONS.md for details.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var a11yHud = require('a11y-hud');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
// src/hook.ts
|
|
7
|
+
function useA11yHud(options = {}) {
|
|
8
|
+
const { theme, scope, autoScan, debounce } = options;
|
|
9
|
+
const instanceRef = react.useRef(null);
|
|
10
|
+
const elementRef = react.useRef(null);
|
|
11
|
+
react.useEffect(() => {
|
|
12
|
+
const instance = a11yHud.mount({
|
|
13
|
+
...theme !== void 0 && { theme },
|
|
14
|
+
...autoScan !== void 0 && { autoScan },
|
|
15
|
+
...debounce !== void 0 && { debounce }
|
|
16
|
+
});
|
|
17
|
+
instanceRef.current = instance;
|
|
18
|
+
elementRef.current = document.querySelector("a11y-hud");
|
|
19
|
+
return () => {
|
|
20
|
+
instance.unmount();
|
|
21
|
+
instanceRef.current = null;
|
|
22
|
+
elementRef.current = null;
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
25
|
+
react.useEffect(() => {
|
|
26
|
+
if (theme !== void 0) instanceRef.current?.setTheme(theme);
|
|
27
|
+
}, [theme]);
|
|
28
|
+
react.useEffect(() => {
|
|
29
|
+
const el = elementRef.current;
|
|
30
|
+
if (!el) return;
|
|
31
|
+
if (autoScan === false) {
|
|
32
|
+
el.removeAttribute("auto-scan");
|
|
33
|
+
} else {
|
|
34
|
+
el.setAttribute("auto-scan", "");
|
|
35
|
+
}
|
|
36
|
+
}, [autoScan]);
|
|
37
|
+
react.useEffect(() => {
|
|
38
|
+
const el = elementRef.current;
|
|
39
|
+
if (!el || debounce === void 0) return;
|
|
40
|
+
el.setAttribute("debounce", String(debounce));
|
|
41
|
+
}, [debounce]);
|
|
42
|
+
react.useEffect(() => {
|
|
43
|
+
const instance = instanceRef.current;
|
|
44
|
+
if (!instance) return;
|
|
45
|
+
const el = elementRef.current;
|
|
46
|
+
if (el) {
|
|
47
|
+
el.scopeElement = scope?.current ?? void 0;
|
|
48
|
+
}
|
|
49
|
+
void instance.runScan();
|
|
50
|
+
});
|
|
51
|
+
const runScan = react.useCallback(
|
|
52
|
+
() => instanceRef.current?.runScan() ?? Promise.resolve(null),
|
|
53
|
+
[]
|
|
54
|
+
);
|
|
55
|
+
const setTheme = react.useCallback((t) => {
|
|
56
|
+
instanceRef.current?.setTheme(t);
|
|
57
|
+
}, []);
|
|
58
|
+
return { runScan, setTheme };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/component.tsx
|
|
62
|
+
function A11yHud(props) {
|
|
63
|
+
useA11yHud(props);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.A11yHud = A11yHud;
|
|
68
|
+
exports.useA11yHud = useA11yHud;
|
|
69
|
+
//# sourceMappingURL=index.cjs.map
|
|
70
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hook.ts","../src/component.tsx"],"names":["useRef","useEffect","mount","useCallback"],"mappings":";;;;;;AAKO,SAAS,UAAA,CAAW,OAAA,GAA6B,EAAC,EAAqB;AAC5E,EAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAO,QAAA,EAAU,UAAS,GAAI,OAAA;AAC7C,EAAA,MAAM,WAAA,GAAcA,aAA+B,IAAI,CAAA;AACvD,EAAA,MAAM,UAAA,GAAaA,aAA8B,IAAI,CAAA;AAKrD,EAAAC,eAAA,CAAU,MAAM;AAGd,IAAA,MAAM,WAAWC,aAAA,CAAM;AAAA,MACrB,GAAI,KAAA,KAAU,MAAA,IAAa,EAAE,KAAA,EAAM;AAAA,MACnC,GAAI,QAAA,KAAa,MAAA,IAAa,EAAE,QAAA,EAAS;AAAA,MACzC,GAAI,QAAA,KAAa,MAAA,IAAa,EAAE,QAAA;AAAS,KAC1C,CAAA;AACD,IAAA,WA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N,MAAA,EAAA,CAAG,YAAA,GAAe,OAAO,OAAA,IAAW,MAAA;AAAA,IACtC;AACA,IAAA,KAAK,SAAS,OAAA,EAAQ;AAAA,EACxB,CAAC,CAAA;AAED,EAAA,MAAM,OAAA,GAAUE,iBAAA;AAAA,IACd,MACE,WAAA,CAAY,OAAA,EAAS,SAAQ,IAAK,OAAA,CAAQ,QAAQ,IAA6B,CAAA;AAAA,IACjF;AAAC,GACH;AAEA,EAAA,MAAM,QAAA,GAAWA,iBAAA,CAAY,CAAC,CAAA,KAAmB;AAC/C,IAAA,WAAA,CAAY,OAAA,EAAS,SAAS,CAAC,CAAA;AAAA,EACjC,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,OAAO,EAAE,SAAS,QAAA,EAAS;AAC7B;;;ACzEO,SAAS,QAAQ,KAAA,EAA2B;AACjD,EAAA,UAAA,CAAW,KAAK,CAAA;AAChB,EAAA,OAAO,IAAA;AACT","file":"index.cjs","sourcesContent":["import type { A11yHudElement, A11yHudInstance, AxeResults, Theme } from \"a11y-hud\";\nimport { mount } from \"a11y-hud\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport type { UseA11yHudOptions, UseA11yHudReturn } from \"./types.js\";\n\nexport function useA11yHud(options: UseA11yHudOptions = {}): UseA11yHudReturn {\n const { theme, scope, autoScan, debounce } = options;\n const instanceRef = useRef<A11yHudInstance | null>(null);\n const elementRef = useRef<A11yHudElement | null>(null);\n\n // Mount the CE once. Capture the element reference immediately after mount()\n // so subsequent effects can access it without re-querying the DOM.\n // biome-ignore lint/correctness/useExhaustiveDependencies: intentional mount-once effect; initial options are applied here, changes are tracked by the separate sync effects below\n useEffect(() => {\n // exactOptionalPropertyTypes forbids passing `undefined` for optional props;\n // build the options object conditionally to satisfy the constraint.\n const instance = mount({\n ...(theme !== undefined && { theme }),\n ...(autoScan !== undefined && { autoScan }),\n ...(debounce !== undefined && { debounce }),\n });\n instanceRef.current = instance;\n elementRef.current = document.querySelector<A11yHudElement>(\"a11y-hud\");\n return () => {\n instance.unmount();\n instanceRef.current = null;\n elementRef.current = null;\n };\n }, []);\n\n useEffect(() => {\n if (theme !== undefined) instanceRef.current?.setTheme(theme);\n }, [theme]);\n\n useEffect(() => {\n const el = elementRef.current;\n if (!el) return;\n if (autoScan === false) {\n el.removeAttribute(\"auto-scan\");\n } else {\n el.setAttribute(\"auto-scan\", \"\");\n }\n }, [autoScan]);\n\n useEffect(() => {\n const el = elementRef.current;\n if (!el || debounce === undefined) return;\n el.setAttribute(\"debounce\", String(debounce));\n }, [debounce]);\n\n // Render-settled signal: runs after every React commit. Always syncs scope\n // (including clearing it when scope becomes undefined), then triggers a\n // rescan. This is the adapter's core value — rescans fire after React\n // finishes rendering, catching route changes and prop-driven ARIA mutations\n // that the MutationObserver may coalesce.\n useEffect(() => {\n const instance = instanceRef.current;\n if (!instance) return;\n const el = elementRef.current;\n if (el) {\n el.scopeElement = scope?.current ?? undefined;\n }\n void instance.runScan();\n });\n\n const runScan = useCallback(\n (): Promise<AxeResults> =>\n instanceRef.current?.runScan() ?? Promise.resolve(null as unknown as AxeResults),\n []\n );\n\n const setTheme = useCallback((t: Theme): void => {\n instanceRef.current?.setTheme(t);\n }, []);\n\n return { runScan, setTheme };\n}\n","import { useA11yHud } from \"./hook.js\";\nimport type { A11yHudProps } from \"./types.js\";\n\nexport function A11yHud(props: A11yHudProps): null {\n useA11yHud(props);\n return null;\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Theme, AxeResults } from 'a11y-hud';
|
|
2
|
+
import { RefObject } from 'react';
|
|
3
|
+
|
|
4
|
+
interface UseA11yHudOptions {
|
|
5
|
+
theme?: Theme;
|
|
6
|
+
scope?: RefObject<Element | null>;
|
|
7
|
+
autoScan?: boolean;
|
|
8
|
+
debounce?: number;
|
|
9
|
+
}
|
|
10
|
+
type A11yHudProps = UseA11yHudOptions;
|
|
11
|
+
interface UseA11yHudReturn {
|
|
12
|
+
runScan(): Promise<AxeResults>;
|
|
13
|
+
setTheme(theme: Theme): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare function A11yHud(props: A11yHudProps): null;
|
|
17
|
+
|
|
18
|
+
declare function useA11yHud(options?: UseA11yHudOptions): UseA11yHudReturn;
|
|
19
|
+
|
|
20
|
+
export { A11yHud, type A11yHudProps, type UseA11yHudOptions, type UseA11yHudReturn, useA11yHud };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Theme, AxeResults } from 'a11y-hud';
|
|
2
|
+
import { RefObject } from 'react';
|
|
3
|
+
|
|
4
|
+
interface UseA11yHudOptions {
|
|
5
|
+
theme?: Theme;
|
|
6
|
+
scope?: RefObject<Element | null>;
|
|
7
|
+
autoScan?: boolean;
|
|
8
|
+
debounce?: number;
|
|
9
|
+
}
|
|
10
|
+
type A11yHudProps = UseA11yHudOptions;
|
|
11
|
+
interface UseA11yHudReturn {
|
|
12
|
+
runScan(): Promise<AxeResults>;
|
|
13
|
+
setTheme(theme: Theme): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare function A11yHud(props: A11yHudProps): null;
|
|
17
|
+
|
|
18
|
+
declare function useA11yHud(options?: UseA11yHudOptions): UseA11yHudReturn;
|
|
19
|
+
|
|
20
|
+
export { A11yHud, type A11yHudProps, type UseA11yHudOptions, type UseA11yHudReturn, useA11yHud };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { mount } from 'a11y-hud';
|
|
2
|
+
import { useRef, useEffect, useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
// src/hook.ts
|
|
5
|
+
function useA11yHud(options = {}) {
|
|
6
|
+
const { theme, scope, autoScan, debounce } = options;
|
|
7
|
+
const instanceRef = useRef(null);
|
|
8
|
+
const elementRef = useRef(null);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const instance = mount({
|
|
11
|
+
...theme !== void 0 && { theme },
|
|
12
|
+
...autoScan !== void 0 && { autoScan },
|
|
13
|
+
...debounce !== void 0 && { debounce }
|
|
14
|
+
});
|
|
15
|
+
instanceRef.current = instance;
|
|
16
|
+
elementRef.current = document.querySelector("a11y-hud");
|
|
17
|
+
return () => {
|
|
18
|
+
instance.unmount();
|
|
19
|
+
instanceRef.current = null;
|
|
20
|
+
elementRef.current = null;
|
|
21
|
+
};
|
|
22
|
+
}, []);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (theme !== void 0) instanceRef.current?.setTheme(theme);
|
|
25
|
+
}, [theme]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const el = elementRef.current;
|
|
28
|
+
if (!el) return;
|
|
29
|
+
if (autoScan === false) {
|
|
30
|
+
el.removeAttribute("auto-scan");
|
|
31
|
+
} else {
|
|
32
|
+
el.setAttribute("auto-scan", "");
|
|
33
|
+
}
|
|
34
|
+
}, [autoScan]);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const el = elementRef.current;
|
|
37
|
+
if (!el || debounce === void 0) return;
|
|
38
|
+
el.setAttribute("debounce", String(debounce));
|
|
39
|
+
}, [debounce]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const instance = instanceRef.current;
|
|
42
|
+
if (!instance) return;
|
|
43
|
+
const el = elementRef.current;
|
|
44
|
+
if (el) {
|
|
45
|
+
el.scopeElement = scope?.current ?? void 0;
|
|
46
|
+
}
|
|
47
|
+
void instance.runScan();
|
|
48
|
+
});
|
|
49
|
+
const runScan = useCallback(
|
|
50
|
+
() => instanceRef.current?.runScan() ?? Promise.resolve(null),
|
|
51
|
+
[]
|
|
52
|
+
);
|
|
53
|
+
const setTheme = useCallback((t) => {
|
|
54
|
+
instanceRef.current?.setTheme(t);
|
|
55
|
+
}, []);
|
|
56
|
+
return { runScan, setTheme };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/component.tsx
|
|
60
|
+
function A11yHud(props) {
|
|
61
|
+
useA11yHud(props);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { A11yHud, useA11yHud };
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hook.ts","../src/component.tsx"],"names":[],"mappings":";;;;AAKO,SAAS,UAAA,CAAW,OAAA,GAA6B,EAAC,EAAqB;AAC5E,EAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAO,QAAA,EAAU,UAAS,GAAI,OAAA;AAC7C,EAAA,MAAM,WAAA,GAAc,OAA+B,IAAI,CAAA;AACvD,EAAA,MAAM,UAAA,GAAa,OAA8B,IAAI,CAAA;AAKrD,EAAA,SAAA,CAAU,MAAM;AAGd,IAAA,MAAM,WAAW,KAAA,CAAM;AAAA,MACrB,GAAI,KAAA,KAAU,MAAA,IAAa,EAAE,KAAA,EAAM;AAAA,MACnC,GAAI,QAAA,KAAa,MAAA,IAAa,EAAE,QAAA,EAAS;AAAA,MACzC,GAAI,QAAA,KAAa,MAAA,IAAa,EAAE,QAAA;AAAS,KAC1C,CAAA;AACD,IAAA,WAAA,CAAY,OAAA,GAAU,QAAA;AACtB,IAAA,UAAA,CAAW,OAAA,GAAU,QAAA,CAAS,aAAA,CAA8B,UAAU,CAAA;AACtE,IAAA,OAAO,MAAM;AACX,MAAA,QAAA,CAAS,OAAA,EAAQ;AACjB,MAAA,WAAA,CAAY,OAAA,GAAU,IAAA;AACtB,MAAA,UAAA,CAAW,OAAA,GAAU,IAAA;AAAA,IACvB,CAAA;AAAA,EACF,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,KAAA,KAAU,MAAA,EAAW,WAAA,CAAY,OAAA,EAAS,SAAS,KAAK,CAAA;AAAA,EAC9D,CAAA,EAAG,CAAC,KAAK,CAAC,CAAA;AAEV,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,MAAM,KAAK,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AAA,UAAA,CAAW,KAAK,CAAA;AAChB,EAAA,OAAO,IAAA;AACT","file":"index.js","sourcesContent":["import type { A11yHudElement, A11yHudInstance, AxeResults, Theme } from \"a11y-hud\";\nimport { mount } from \"a11y-hud\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport type { UseA11yHudOptions, UseA11yHudReturn } from \"./types.js\";\n\nexport function useA11yHud(options: UseA11yHudOptions = {}): UseA11yHudReturn {\n const { theme, scope, autoScan, debounce } = options;\n const instanceRef = useRef<A11yHudInstance | null>(null);\n const elementRef = useRef<A11yHudElement | null>(null);\n\n // Mount the CE once. Capture the element reference immediately after mount()\n // so subsequent effects can access it without re-querying the DOM.\n // biome-ignore lint/correctness/useExhaustiveDependencies: intentional mount-once effect; initial options are applied here, changes are tracked by the separate sync effects below\n useEffect(() => {\n // exactOptionalPropertyTypes forbids passing `undefined` for optional props;\n // build the options object conditionally to satisfy the constraint.\n const instance = mount({\n ...(theme !== undefined && { theme }),\n ...(autoScan !== undefined && { autoScan }),\n ...(debounce !== undefined && { debounce }),\n });\n instanceRef.current = instance;\n elementRef.current = document.querySelector<A11yHudElement>(\"a11y-hud\");\n return () => {\n instance.unmount();\n instanceRef.current = null;\n elementRef.current = null;\n };\n }, []);\n\n useEffect(() => {\n if (theme !== undefined) instanceRef.current?.setTheme(theme);\n }, [theme]);\n\n useEffect(() => {\n const el = elementRef.current;\n if (!el) return;\n if (autoScan === false) {\n el.removeAttribute(\"auto-scan\");\n } else {\n el.setAttribute(\"auto-scan\", \"\");\n }\n }, [autoScan]);\n\n useEffect(() => {\n const el = elementRef.current;\n if (!el || debounce === undefined) return;\n el.setAttribute(\"debounce\", String(debounce));\n }, [debounce]);\n\n // Render-settled signal: runs after every React commit. Always syncs scope\n // (including clearing it when scope becomes undefined), then triggers a\n // rescan. This is the adapter's core value — rescans fire after React\n // finishes rendering, catching route changes and prop-driven ARIA mutations\n // that the MutationObserver may coalesce.\n useEffect(() => {\n const instance = instanceRef.current;\n if (!instance) return;\n const el = elementRef.current;\n if (el) {\n el.scopeElement = scope?.current ?? undefined;\n }\n void instance.runScan();\n });\n\n const runScan = useCallback(\n (): Promise<AxeResults> =>\n instanceRef.current?.runScan() ?? Promise.resolve(null as unknown as AxeResults),\n []\n );\n\n const setTheme = useCallback((t: Theme): void => {\n instanceRef.current?.setTheme(t);\n }, []);\n\n return { runScan, setTheme };\n}\n","import { useA11yHud } from \"./hook.js\";\nimport type { A11yHudProps } from \"./types.js\";\n\nexport function A11yHud(props: A11yHudProps): null {\n useA11yHud(props);\n return null;\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@a11y-hud/react",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "React adapter for a11y-hud — run axe-core accessibility audits in your React app with no DevTools required.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"require": "./dist/index.cjs"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.cjs",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"a11y-hud": "0.1.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": ">=18",
|
|
26
|
+
"react-dom": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@playwright/test": "^1.49.1",
|
|
30
|
+
"@testing-library/react": "^16.3.0",
|
|
31
|
+
"@types/react": "^19.0.0",
|
|
32
|
+
"@types/react-dom": "^19.0.0",
|
|
33
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
34
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
35
|
+
"jsdom": "^29.1.1",
|
|
36
|
+
"react": "^19.0.0",
|
|
37
|
+
"react-dom": "^19.0.0",
|
|
38
|
+
"tsup": "^8.3.5",
|
|
39
|
+
"vitest": "^4.1.5"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=22"
|
|
43
|
+
},
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"homepage": "https://github.com/arthurvasconcelos/a11y-hud#readme",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/arthurvasconcelos/a11y-hud.git",
|
|
49
|
+
"directory": "packages/react"
|
|
50
|
+
},
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/arthurvasconcelos/a11y-hud/issues"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"accessibility",
|
|
56
|
+
"a11y",
|
|
57
|
+
"axe",
|
|
58
|
+
"axe-core",
|
|
59
|
+
"wcag",
|
|
60
|
+
"react",
|
|
61
|
+
"dev-tools",
|
|
62
|
+
"overlay",
|
|
63
|
+
"hud"
|
|
64
|
+
],
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsup",
|
|
67
|
+
"dev": "tsup --watch",
|
|
68
|
+
"test": "vitest run",
|
|
69
|
+
"test:watch": "vitest",
|
|
70
|
+
"test:coverage": "vitest run --coverage",
|
|
71
|
+
"test:e2e": "playwright test",
|
|
72
|
+
"typecheck": "tsc --noEmit"
|
|
73
|
+
}
|
|
74
|
+
}
|