@zag-js/live-region 0.1.3 → 0.1.4

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/dist/index.js CHANGED
@@ -1,4 +1,30 @@
1
- // ../dom/dist/index.js
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/dist/index.mjs
2
28
  var visuallyHiddenStyle = {
3
29
  border: "0",
4
30
  clip: "rect(0 0 0 0)",
@@ -49,6 +75,7 @@ function createLiveRegion(opts = {}) {
49
75
  }
50
76
  };
51
77
  }
52
- export {
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
53
80
  createLiveRegion
54
- };
81
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,54 @@
1
+ // ../dom/dist/index.mjs
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
+ const { level = "polite", document: doc = document, root, delay: _delay = 0 } = opts;
22
+ const win = doc.defaultView ?? window;
23
+ const parent = root ?? doc.body;
24
+ function announce(message, delay) {
25
+ const oldRegion = doc.getElementById(ID);
26
+ oldRegion == null ? void 0 : oldRegion.remove();
27
+ delay = delay ?? _delay;
28
+ const region = doc.createElement("span");
29
+ region.id = ID;
30
+ region.dataset.liveAnnouncer = "true";
31
+ const role = level !== "assertive" ? "status" : "alert";
32
+ region.setAttribute("aria-live", level);
33
+ region.setAttribute("role", role);
34
+ setVisuallyHidden(region);
35
+ parent.appendChild(region);
36
+ win.setTimeout(() => {
37
+ region.textContent = message;
38
+ }, delay);
39
+ }
40
+ function destroy() {
41
+ const oldRegion = doc.getElementById(ID);
42
+ oldRegion == null ? void 0 : oldRegion.remove();
43
+ }
44
+ return {
45
+ announce,
46
+ destroy,
47
+ toJSON() {
48
+ return ID;
49
+ }
50
+ };
51
+ }
52
+ export {
53
+ createLiveRegion
54
+ };
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
- "type": "module",
3
2
  "name": "@zag-js/live-region",
4
- "version": "0.1.3",
3
+ "version": "0.1.4",
5
4
  "description": "Implementing live region for screen readers",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
6
8
  "keywords": [
7
9
  "js",
8
10
  "utils",
@@ -11,15 +13,13 @@
11
13
  "author": "Segun Adebayo <sage@adebayosegun.com>",
12
14
  "homepage": "https://github.com/chakra-ui/zag#readme",
13
15
  "license": "MIT",
14
- "main": "dist/index.js",
15
- "types": "dist/index.d.ts",
16
16
  "repository": "https://github.com/chakra-ui/zag/tree/main/packages/utilities/live-region",
17
17
  "sideEffects": false,
18
18
  "files": [
19
19
  "dist/**/*"
20
20
  ],
21
21
  "devDependencies": {
22
- "@zag-js/dom-utils": "0.1.12"
22
+ "@zag-js/dom-utils": "0.1.13"
23
23
  },
24
24
  "publishConfig": {
25
25
  "access": "public"
@@ -28,9 +28,9 @@
28
28
  "url": "https://github.com/chakra-ui/zag/issues"
29
29
  },
30
30
  "scripts": {
31
- "build-fast": "tsup src/index.ts --format=esm",
31
+ "build-fast": "tsup src/index.ts --format=esm,cjs",
32
32
  "start": "pnpm build --watch",
33
- "build": "tsup src/index.ts --format=esm --dts",
33
+ "build": "tsup src/index.ts --format=esm,cjs --dts",
34
34
  "test": "jest --config ../../../jest.config.js --rootDir tests",
35
35
  "lint": "eslint src --ext .ts,.tsx",
36
36
  "test-ci": "pnpm test --ci --runInBand -u",