@alew896/a11y-reader 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.
@@ -0,0 +1,10 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ declare function A11yOverlay(): react_jsx_runtime.JSX.Element;
4
+
5
+ declare function useA11yReader(): {
6
+ current: string;
7
+ logs: string[];
8
+ };
9
+
10
+ export { A11yOverlay, useA11yReader };
@@ -0,0 +1,10 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ declare function A11yOverlay(): react_jsx_runtime.JSX.Element;
4
+
5
+ declare function useA11yReader(): {
6
+ current: string;
7
+ logs: string[];
8
+ };
9
+
10
+ export { A11yOverlay, useA11yReader };
package/dist/index.js ADDED
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ A11yOverlay: () => A11yOverlay,
24
+ useA11yReader: () => useA11yReader
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/A11yOverlay.tsx
29
+ var import_react2 = require("react");
30
+
31
+ // src/useA11yReader.tsx
32
+ var import_react = require("react");
33
+
34
+ // src/utils/getA11yText.ts
35
+ function getA11yText(el) {
36
+ const role = el.getAttribute("role") || el.tagName.toLowerCase();
37
+ const label = el.getAttribute("aria-label") || el.textContent?.trim() || "";
38
+ const checked = el.getAttribute("aria-checked") === "true" || el.checked;
39
+ const state = checked ? "checked" : "";
40
+ return [role, label, state].filter(Boolean).join(" ");
41
+ }
42
+
43
+ // src/useA11yReader.tsx
44
+ function useA11yReader() {
45
+ const [current, setCurrent] = (0, import_react.useState)("");
46
+ const [logs, setLogs] = (0, import_react.useState)([]);
47
+ (0, import_react.useEffect)(() => {
48
+ const handler = (e) => {
49
+ const el = e.target;
50
+ const text = getA11yText(el);
51
+ setCurrent(text);
52
+ setLogs((prev) => [text, ...prev.slice(0, 20)]);
53
+ };
54
+ document.addEventListener("focusin", handler);
55
+ return () => {
56
+ document.removeEventListener("focusin", handler);
57
+ };
58
+ }, []);
59
+ return { current, logs };
60
+ }
61
+
62
+ // src/A11yOverlay.tsx
63
+ var import_jsx_runtime = require("react/jsx-runtime");
64
+ function A11yOverlay() {
65
+ const { current, logs } = useA11yReader();
66
+ const ref = (0, import_react2.useRef)(null);
67
+ (0, import_react2.useEffect)(() => {
68
+ const el = ref.current;
69
+ if (!el) return;
70
+ let isDragging = false;
71
+ el.onmousedown = () => isDragging = true;
72
+ document.onmouseup = () => isDragging = false;
73
+ document.onmousemove = (e) => {
74
+ if (!isDragging) return;
75
+ el.style.left = e.pageX + "px";
76
+ el.style.top = e.pageY + "px";
77
+ };
78
+ }, []);
79
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
80
+ "div",
81
+ {
82
+ ref,
83
+ style: {
84
+ position: "fixed",
85
+ top: 20,
86
+ right: 20,
87
+ width: 300,
88
+ background: "#111",
89
+ color: "#fff",
90
+ padding: 10,
91
+ borderRadius: 8,
92
+ zIndex: 9999,
93
+ fontSize: 12
94
+ },
95
+ children: [
96
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontWeight: "bold" }, children: "A11y Reader" }),
97
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { marginTop: 10 }, children: [
98
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "Current:" }),
99
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: current })
100
+ ] }),
101
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { marginTop: 10, maxHeight: 150, overflow: "auto" }, children: logs.map((log, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: log }, i)) })
102
+ ]
103
+ }
104
+ );
105
+ }
106
+ // Annotate the CommonJS export names for ESM import in node:
107
+ 0 && (module.exports = {
108
+ A11yOverlay,
109
+ useA11yReader
110
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,82 @@
1
+ // src/A11yOverlay.tsx
2
+ import { useRef, useEffect as useEffect2 } from "react";
3
+
4
+ // src/useA11yReader.tsx
5
+ import { useEffect, useState } from "react";
6
+
7
+ // src/utils/getA11yText.ts
8
+ function getA11yText(el) {
9
+ const role = el.getAttribute("role") || el.tagName.toLowerCase();
10
+ const label = el.getAttribute("aria-label") || el.textContent?.trim() || "";
11
+ const checked = el.getAttribute("aria-checked") === "true" || el.checked;
12
+ const state = checked ? "checked" : "";
13
+ return [role, label, state].filter(Boolean).join(" ");
14
+ }
15
+
16
+ // src/useA11yReader.tsx
17
+ function useA11yReader() {
18
+ const [current, setCurrent] = useState("");
19
+ const [logs, setLogs] = useState([]);
20
+ useEffect(() => {
21
+ const handler = (e) => {
22
+ const el = e.target;
23
+ const text = getA11yText(el);
24
+ setCurrent(text);
25
+ setLogs((prev) => [text, ...prev.slice(0, 20)]);
26
+ };
27
+ document.addEventListener("focusin", handler);
28
+ return () => {
29
+ document.removeEventListener("focusin", handler);
30
+ };
31
+ }, []);
32
+ return { current, logs };
33
+ }
34
+
35
+ // src/A11yOverlay.tsx
36
+ import { jsx, jsxs } from "react/jsx-runtime";
37
+ function A11yOverlay() {
38
+ const { current, logs } = useA11yReader();
39
+ const ref = useRef(null);
40
+ useEffect2(() => {
41
+ const el = ref.current;
42
+ if (!el) return;
43
+ let isDragging = false;
44
+ el.onmousedown = () => isDragging = true;
45
+ document.onmouseup = () => isDragging = false;
46
+ document.onmousemove = (e) => {
47
+ if (!isDragging) return;
48
+ el.style.left = e.pageX + "px";
49
+ el.style.top = e.pageY + "px";
50
+ };
51
+ }, []);
52
+ return /* @__PURE__ */ jsxs(
53
+ "div",
54
+ {
55
+ ref,
56
+ style: {
57
+ position: "fixed",
58
+ top: 20,
59
+ right: 20,
60
+ width: 300,
61
+ background: "#111",
62
+ color: "#fff",
63
+ padding: 10,
64
+ borderRadius: 8,
65
+ zIndex: 9999,
66
+ fontSize: 12
67
+ },
68
+ children: [
69
+ /* @__PURE__ */ jsx("div", { style: { fontWeight: "bold" }, children: "A11y Reader" }),
70
+ /* @__PURE__ */ jsxs("div", { style: { marginTop: 10 }, children: [
71
+ /* @__PURE__ */ jsx("strong", { children: "Current:" }),
72
+ /* @__PURE__ */ jsx("div", { children: current })
73
+ ] }),
74
+ /* @__PURE__ */ jsx("div", { style: { marginTop: 10, maxHeight: 150, overflow: "auto" }, children: logs.map((log, i) => /* @__PURE__ */ jsx("div", { children: log }, i)) })
75
+ ]
76
+ }
77
+ );
78
+ }
79
+ export {
80
+ A11yOverlay,
81
+ useA11yReader
82
+ };
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@alew896/a11y-reader",
3
+ "version": "0.1.0",
4
+ "description": "A11y text-based screen reader simulator overlay for React apps",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+
9
+ "files": ["dist"],
10
+
11
+ "scripts": {
12
+ "build": "tsup src/index.ts --dts --format esm,cjs",
13
+ "prepublishOnly": "npm run build"
14
+ },
15
+
16
+ "keywords": ["a11y", "accessibility", "screen-reader", "aria", "react"],
17
+ "author": "Chirag Athwani",
18
+ "license": "MIT",
19
+
20
+ "peerDependencies": {
21
+ "react": ">=17",
22
+ "react-dom": ">=17"
23
+ }
24
+ }