@zag-js/live-region 0.0.0-dev-20220709181637

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/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @zag-js/live-region
2
+
3
+ Implementing live region for screen readers
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ yarn add @zag-js/live-region
9
+ # or
10
+ npm i @zag-js/live-region
11
+ ```
12
+
13
+ ## Contribution
14
+
15
+ Yes please! See the [contributing guidelines](https://github.com/chakra-ui/zag/blob/main/CONTRIBUTING.md) for details.
16
+
17
+ ## Licence
18
+
19
+ This project is licensed under the terms of the [MIT license](https://github.com/chakra-ui/zag/blob/main/LICENSE).
@@ -0,0 +1,12 @@
1
+ export declare type LiveRegionOptions = {
2
+ level: "polite" | "assertive";
3
+ document?: Document;
4
+ root?: HTMLElement | null;
5
+ delay?: number;
6
+ };
7
+ export declare type LiveRegion = ReturnType<typeof createLiveRegion>;
8
+ export declare function createLiveRegion(opts?: Partial<LiveRegionOptions>): {
9
+ announce: (message: string, delay?: number) => void;
10
+ destroy: () => void;
11
+ toJSON(): string;
12
+ };
package/dist/index.js ADDED
@@ -0,0 +1,78 @@
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 src_exports = {};
22
+ __export(src_exports, {
23
+ createLiveRegion: () => createLiveRegion
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // ../dom/src/visually-hidden.ts
28
+ var visuallyHiddenStyle = {
29
+ border: "0",
30
+ clip: "rect(0 0 0 0)",
31
+ height: "1px",
32
+ margin: "-1px",
33
+ overflow: "hidden",
34
+ padding: "0",
35
+ position: "absolute",
36
+ width: "1px",
37
+ whiteSpace: "nowrap",
38
+ wordWrap: "normal"
39
+ };
40
+ function setVisuallyHidden(el) {
41
+ Object.assign(el.style, visuallyHiddenStyle);
42
+ }
43
+
44
+ // src/index.ts
45
+ var ID = "__live-region__";
46
+ function createLiveRegion(opts = {}) {
47
+ var _a;
48
+ const { level = "polite", document: doc = document, root, delay: _delay = 0 } = opts;
49
+ const win = (_a = doc.defaultView) != null ? _a : window;
50
+ const parent = root != null ? root : doc.body;
51
+ function announce(message, delay) {
52
+ const oldRegion = doc.getElementById(ID);
53
+ oldRegion == null ? void 0 : oldRegion.remove();
54
+ delay = delay != null ? delay : _delay;
55
+ const region = doc.createElement("span");
56
+ region.id = ID;
57
+ region.dataset.liveAnnouncer = "true";
58
+ const role = level !== "assertive" ? "status" : "alert";
59
+ region.setAttribute("aria-live", level);
60
+ region.setAttribute("role", role);
61
+ setVisuallyHidden(region);
62
+ parent.appendChild(region);
63
+ win.setTimeout(() => {
64
+ region.textContent = message;
65
+ }, delay);
66
+ }
67
+ function destroy() {
68
+ const oldRegion = doc.getElementById(ID);
69
+ oldRegion == null ? void 0 : oldRegion.remove();
70
+ }
71
+ return {
72
+ announce,
73
+ destroy,
74
+ toJSON() {
75
+ return ID;
76
+ }
77
+ };
78
+ }
package/dist/index.mjs ADDED
@@ -0,0 +1,55 @@
1
+ // ../dom/src/visually-hidden.ts
2
+ var visuallyHiddenStyle = {
3
+ border: "0",
4
+ clip: "rect(0 0 0 0)",
5
+ height: "1px",
6
+ margin: "-1px",
7
+ overflow: "hidden",
8
+ padding: "0",
9
+ position: "absolute",
10
+ width: "1px",
11
+ whiteSpace: "nowrap",
12
+ wordWrap: "normal"
13
+ };
14
+ function setVisuallyHidden(el) {
15
+ Object.assign(el.style, visuallyHiddenStyle);
16
+ }
17
+
18
+ // src/index.ts
19
+ var ID = "__live-region__";
20
+ function createLiveRegion(opts = {}) {
21
+ var _a;
22
+ const { level = "polite", document: doc = document, root, delay: _delay = 0 } = opts;
23
+ const win = (_a = doc.defaultView) != null ? _a : window;
24
+ const parent = root != null ? root : doc.body;
25
+ function announce(message, delay) {
26
+ const oldRegion = doc.getElementById(ID);
27
+ oldRegion == null ? void 0 : oldRegion.remove();
28
+ delay = delay != null ? delay : _delay;
29
+ const region = doc.createElement("span");
30
+ region.id = ID;
31
+ region.dataset.liveAnnouncer = "true";
32
+ const role = level !== "assertive" ? "status" : "alert";
33
+ region.setAttribute("aria-live", level);
34
+ region.setAttribute("role", role);
35
+ setVisuallyHidden(region);
36
+ parent.appendChild(region);
37
+ win.setTimeout(() => {
38
+ region.textContent = message;
39
+ }, delay);
40
+ }
41
+ function destroy() {
42
+ const oldRegion = doc.getElementById(ID);
43
+ oldRegion == null ? void 0 : oldRegion.remove();
44
+ }
45
+ return {
46
+ announce,
47
+ destroy,
48
+ toJSON() {
49
+ return ID;
50
+ }
51
+ };
52
+ }
53
+ export {
54
+ createLiveRegion
55
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@zag-js/live-region",
3
+ "version": "0.0.0-dev-20220709181637",
4
+ "description": "Implementing live region for screen readers",
5
+ "keywords": [
6
+ "js",
7
+ "utils",
8
+ "live-region"
9
+ ],
10
+ "author": "Segun Adebayo <sage@adebayosegun.com>",
11
+ "homepage": "https://github.com/chakra-ui/zag#readme",
12
+ "license": "MIT",
13
+ "main": "dist/index.js",
14
+ "module": "dist/index.mjs",
15
+ "types": "dist/index.d.ts",
16
+ "repository": "https://github.com/chakra-ui/zag/tree/main/packages/utilities/live-region",
17
+ "sideEffects": false,
18
+ "files": [
19
+ "dist/**/*"
20
+ ],
21
+ "scripts": {
22
+ "build:fast": "yarn zag build",
23
+ "start": "yarn zag build --watch",
24
+ "build": "yarn zag build --prod",
25
+ "test": "jest --config ../../../jest.config.js --rootDir tests",
26
+ "lint": "eslint src --ext .ts,.tsx",
27
+ "test:ci": "yarn test --ci --runInBand --updateSnapshot",
28
+ "test:watch": "yarn test --watchAll"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/chakra-ui/zag/issues"
35
+ }
36
+ }