@react-aria/live-announcer 3.4.3 → 3.5.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/dist/import.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import {announce as $319e236875307eab$export$a9b970dcc4ae71a9, clearAnnouncer as $319e236875307eab$export$d10ae4f68404609a, destroyAnnouncer as $319e236875307eab$export$d8686216b8b81b2f} from "./LiveAnnouncer.mjs";
1
+ import {announce as $e5a8c0eef40ba0e6$re_export$announce, clearAnnouncer as $e5a8c0eef40ba0e6$re_export$clearAnnouncer, destroyAnnouncer as $e5a8c0eef40ba0e6$re_export$destroyAnnouncer} from "react-aria/private/live-announcer/LiveAnnouncer";
2
2
 
3
3
  /*
4
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {announce as $319e236875307eab$export$a9b970dcc4ae71a9, clearAnnouncer as
13
13
  */
14
14
 
15
15
 
16
- export {$319e236875307eab$export$a9b970dcc4ae71a9 as announce, $319e236875307eab$export$d10ae4f68404609a as clearAnnouncer, $319e236875307eab$export$d8686216b8b81b2f as destroyAnnouncer};
16
+ export {$e5a8c0eef40ba0e6$re_export$announce as announce, $e5a8c0eef40ba0e6$re_export$clearAnnouncer as clearAnnouncer, $e5a8c0eef40ba0e6$re_export$destroyAnnouncer as destroyAnnouncer};
17
17
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,13 +1,13 @@
1
- var $97cebfa4133ebec3$exports = require("./LiveAnnouncer.main.js");
1
+ var $9MBvR$reactariaprivateliveannouncerLiveAnnouncer = require("react-aria/private/live-announcer/LiveAnnouncer");
2
2
 
3
3
 
4
4
  function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
7
 
8
- $parcel$export(module.exports, "announce", () => $97cebfa4133ebec3$exports.announce);
9
- $parcel$export(module.exports, "clearAnnouncer", () => $97cebfa4133ebec3$exports.clearAnnouncer);
10
- $parcel$export(module.exports, "destroyAnnouncer", () => $97cebfa4133ebec3$exports.destroyAnnouncer);
8
+ $parcel$export(module.exports, "announce", function () { return $9MBvR$reactariaprivateliveannouncerLiveAnnouncer.announce; });
9
+ $parcel$export(module.exports, "clearAnnouncer", function () { return $9MBvR$reactariaprivateliveannouncerLiveAnnouncer.clearAnnouncer; });
10
+ $parcel$export(module.exports, "destroyAnnouncer", function () { return $9MBvR$reactariaprivateliveannouncerLiveAnnouncer.destroyAnnouncer; });
11
11
  /*
12
12
  * Copyright 2020 Adobe. All rights reserved.
13
13
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/live-announcer/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {announce, clearAnnouncer, destroyAnnouncer} from './LiveAnnouncer';\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/live-announcer/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {announce, clearAnnouncer, destroyAnnouncer} from 'react-aria/private/live-announcer/LiveAnnouncer';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import {announce as $319e236875307eab$export$a9b970dcc4ae71a9, clearAnnouncer as $319e236875307eab$export$d10ae4f68404609a, destroyAnnouncer as $319e236875307eab$export$d8686216b8b81b2f} from "./LiveAnnouncer.module.js";
1
+ import {announce as $e5a8c0eef40ba0e6$re_export$announce, clearAnnouncer as $e5a8c0eef40ba0e6$re_export$clearAnnouncer, destroyAnnouncer as $e5a8c0eef40ba0e6$re_export$destroyAnnouncer} from "react-aria/private/live-announcer/LiveAnnouncer";
2
2
 
3
3
  /*
4
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {announce as $319e236875307eab$export$a9b970dcc4ae71a9, clearAnnouncer as
13
13
  */
14
14
 
15
15
 
16
- export {$319e236875307eab$export$a9b970dcc4ae71a9 as announce, $319e236875307eab$export$d10ae4f68404609a as clearAnnouncer, $319e236875307eab$export$d8686216b8b81b2f as destroyAnnouncer};
16
+ export {$e5a8c0eef40ba0e6$re_export$announce as announce, $e5a8c0eef40ba0e6$re_export$clearAnnouncer as clearAnnouncer, $e5a8c0eef40ba0e6$re_export$destroyAnnouncer as destroyAnnouncer};
17
17
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/live-announcer/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {announce, clearAnnouncer, destroyAnnouncer} from './LiveAnnouncer';\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/live-announcer/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {announce, clearAnnouncer, destroyAnnouncer} from 'react-aria/private/live-announcer/LiveAnnouncer';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1 @@
1
+ export { announce, clearAnnouncer, destroyAnnouncer } from 'react-aria/private/live-announcer/LiveAnnouncer';
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@react-aria/live-announcer",
3
- "version": "3.4.3",
3
+ "version": "3.5.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
8
  "exports": {
9
- "source": "./src/index.ts",
10
- "types": [
11
- "./dist/types.d.ts",
12
- "./src/index.ts"
13
- ],
14
- "import": "./dist/import.mjs",
15
- "require": "./dist/main.js"
9
+ ".": {
10
+ "source": "./src/index.ts",
11
+ "types": "./dist/types/src/index.d.ts",
12
+ "import": "./dist/import.mjs",
13
+ "require": "./dist/main.js"
14
+ },
15
+ "./package.json": "./package.json"
16
16
  },
17
- "types": "dist/types.d.ts",
17
+ "types": "dist/types/src/index.d.ts",
18
18
  "source": "src/index.ts",
19
19
  "files": [
20
20
  "dist",
@@ -26,10 +26,18 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@swc/helpers": "^0.5.0"
29
+ "@swc/helpers": "^0.5.0",
30
+ "react-aria": "3.48.0"
30
31
  },
31
32
  "publishConfig": {
32
33
  "access": "public"
33
34
  },
34
- "gitHead": "265b4d7f107905ee1c6e87a8af1613ab440a6849"
35
+ "targets": {
36
+ "types": false
37
+ },
38
+ "peerDependencies": {
39
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
40
+ "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
41
+ },
42
+ "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
35
43
  }
package/src/index.ts CHANGED
@@ -9,4 +9,4 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- export {announce, clearAnnouncer, destroyAnnouncer} from './LiveAnnouncer';
12
+ export {announce, clearAnnouncer, destroyAnnouncer} from 'react-aria/private/live-announcer/LiveAnnouncer';
@@ -1,119 +0,0 @@
1
-
2
- function $parcel$export(e, n, v, s) {
3
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
4
- }
5
-
6
- $parcel$export(module.exports, "announce", () => $97cebfa4133ebec3$export$a9b970dcc4ae71a9);
7
- $parcel$export(module.exports, "clearAnnouncer", () => $97cebfa4133ebec3$export$d10ae4f68404609a);
8
- $parcel$export(module.exports, "destroyAnnouncer", () => $97cebfa4133ebec3$export$d8686216b8b81b2f);
9
- /*
10
- * Copyright 2020 Adobe. All rights reserved.
11
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License. You may obtain a copy
13
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software distributed under
16
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
- * OF ANY KIND, either express or implied. See the License for the specific language
18
- * governing permissions and limitations under the License.
19
- */ /* Inspired by https://github.com/AlmeroSteyn/react-aria-live */ const $97cebfa4133ebec3$var$LIVEREGION_TIMEOUT_DELAY = 7000;
20
- let $97cebfa4133ebec3$var$liveAnnouncer = null;
21
- function $97cebfa4133ebec3$export$a9b970dcc4ae71a9(message, assertiveness = 'assertive', timeout = $97cebfa4133ebec3$var$LIVEREGION_TIMEOUT_DELAY) {
22
- if (!$97cebfa4133ebec3$var$liveAnnouncer) {
23
- $97cebfa4133ebec3$var$liveAnnouncer = new $97cebfa4133ebec3$var$LiveAnnouncer();
24
- // wait for the live announcer regions to be added to the dom, then announce
25
- // otherwise Safari won't announce the message if it's added too quickly
26
- // found most times less than 100ms were not consistent when announcing with Safari
27
- // IS_REACT_ACT_ENVIRONMENT is used by React 18. Previous versions checked for the `jest` global.
28
- // https://github.com/reactwg/react-18/discussions/102
29
- // if we're in a test environment, announce without waiting
30
- // @ts-ignore
31
- if (!(typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined')) setTimeout(()=>{
32
- if ($97cebfa4133ebec3$var$liveAnnouncer === null || $97cebfa4133ebec3$var$liveAnnouncer === void 0 ? void 0 : $97cebfa4133ebec3$var$liveAnnouncer.isAttached()) $97cebfa4133ebec3$var$liveAnnouncer === null || $97cebfa4133ebec3$var$liveAnnouncer === void 0 ? void 0 : $97cebfa4133ebec3$var$liveAnnouncer.announce(message, assertiveness, timeout);
33
- }, 100);
34
- else $97cebfa4133ebec3$var$liveAnnouncer.announce(message, assertiveness, timeout);
35
- } else $97cebfa4133ebec3$var$liveAnnouncer.announce(message, assertiveness, timeout);
36
- }
37
- function $97cebfa4133ebec3$export$d10ae4f68404609a(assertiveness) {
38
- if ($97cebfa4133ebec3$var$liveAnnouncer) $97cebfa4133ebec3$var$liveAnnouncer.clear(assertiveness);
39
- }
40
- function $97cebfa4133ebec3$export$d8686216b8b81b2f() {
41
- if ($97cebfa4133ebec3$var$liveAnnouncer) {
42
- $97cebfa4133ebec3$var$liveAnnouncer.destroy();
43
- $97cebfa4133ebec3$var$liveAnnouncer = null;
44
- }
45
- }
46
- // LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18
47
- // ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a
48
- // subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.
49
- // As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer
50
- // is simple enough to implement without React, so that's what we do here.
51
- // See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638
52
- class $97cebfa4133ebec3$var$LiveAnnouncer {
53
- isAttached() {
54
- var _this_node;
55
- return (_this_node = this.node) === null || _this_node === void 0 ? void 0 : _this_node.isConnected;
56
- }
57
- createLog(ariaLive) {
58
- let node = document.createElement('div');
59
- node.setAttribute('role', 'log');
60
- node.setAttribute('aria-live', ariaLive);
61
- node.setAttribute('aria-relevant', 'additions');
62
- return node;
63
- }
64
- destroy() {
65
- if (!this.node) return;
66
- document.body.removeChild(this.node);
67
- this.node = null;
68
- }
69
- announce(message, assertiveness = 'assertive', timeout = $97cebfa4133ebec3$var$LIVEREGION_TIMEOUT_DELAY) {
70
- var _this_assertiveLog, _this_politeLog;
71
- if (!this.node) return;
72
- let node = document.createElement('div');
73
- if (typeof message === 'object') {
74
- // To read an aria-labelledby, the element must have an appropriate role, such as img.
75
- node.setAttribute('role', 'img');
76
- node.setAttribute('aria-labelledby', message['aria-labelledby']);
77
- } else node.textContent = message;
78
- if (assertiveness === 'assertive') (_this_assertiveLog = this.assertiveLog) === null || _this_assertiveLog === void 0 ? void 0 : _this_assertiveLog.appendChild(node);
79
- else (_this_politeLog = this.politeLog) === null || _this_politeLog === void 0 ? void 0 : _this_politeLog.appendChild(node);
80
- if (message !== '') setTimeout(()=>{
81
- node.remove();
82
- }, timeout);
83
- }
84
- clear(assertiveness) {
85
- if (!this.node) return;
86
- if ((!assertiveness || assertiveness === 'assertive') && this.assertiveLog) this.assertiveLog.innerHTML = '';
87
- if ((!assertiveness || assertiveness === 'polite') && this.politeLog) this.politeLog.innerHTML = '';
88
- }
89
- constructor(){
90
- this.node = null;
91
- this.assertiveLog = null;
92
- this.politeLog = null;
93
- if (typeof document !== 'undefined') {
94
- this.node = document.createElement('div');
95
- this.node.dataset.liveAnnouncer = 'true';
96
- // copied from VisuallyHidden
97
- Object.assign(this.node.style, {
98
- border: 0,
99
- clip: 'rect(0 0 0 0)',
100
- clipPath: 'inset(50%)',
101
- height: '1px',
102
- margin: '-1px',
103
- overflow: 'hidden',
104
- padding: 0,
105
- position: 'absolute',
106
- width: '1px',
107
- whiteSpace: 'nowrap'
108
- });
109
- this.assertiveLog = this.createLog('assertive');
110
- this.node.appendChild(this.assertiveLog);
111
- this.politeLog = this.createLog('polite');
112
- this.node.appendChild(this.politeLog);
113
- document.body.prepend(this.node);
114
- }
115
- }
116
- }
117
-
118
-
119
- //# sourceMappingURL=LiveAnnouncer.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":"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","sources":["packages/@react-aria/live-announcer/src/LiveAnnouncer.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\ntype Assertiveness = 'assertive' | 'polite';\n\n/* Inspired by https://github.com/AlmeroSteyn/react-aria-live */\nconst LIVEREGION_TIMEOUT_DELAY = 7000;\n\nlet liveAnnouncer: LiveAnnouncer | null = null;\n\ntype Message = string | {'aria-labelledby': string};\n\n/**\n * Announces the message using screen reader technology.\n */\nexport function announce(\n message: Message,\n assertiveness: Assertiveness = 'assertive',\n timeout = LIVEREGION_TIMEOUT_DELAY\n): void {\n if (!liveAnnouncer) {\n liveAnnouncer = new LiveAnnouncer();\n // wait for the live announcer regions to be added to the dom, then announce\n // otherwise Safari won't announce the message if it's added too quickly\n // found most times less than 100ms were not consistent when announcing with Safari\n\n // IS_REACT_ACT_ENVIRONMENT is used by React 18. Previous versions checked for the `jest` global.\n // https://github.com/reactwg/react-18/discussions/102\n // if we're in a test environment, announce without waiting\n // @ts-ignore\n if (!(typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined')) {\n setTimeout(() => {\n if (liveAnnouncer?.isAttached()) {\n liveAnnouncer?.announce(message, assertiveness, timeout);\n }\n }, 100);\n } else {\n liveAnnouncer.announce(message, assertiveness, timeout);\n }\n } else {\n liveAnnouncer.announce(message, assertiveness, timeout);\n }\n}\n\n/**\n * Stops all queued announcements.\n */\nexport function clearAnnouncer(assertiveness: Assertiveness): void {\n if (liveAnnouncer) {\n liveAnnouncer.clear(assertiveness);\n }\n}\n\n/**\n * Removes the announcer from the DOM.\n */\nexport function destroyAnnouncer(): void {\n if (liveAnnouncer) {\n liveAnnouncer.destroy();\n liveAnnouncer = null;\n }\n}\n\n// LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18\n// ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a\n// subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.\n// As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer\n// is simple enough to implement without React, so that's what we do here.\n// See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638\nclass LiveAnnouncer {\n node: HTMLElement | null = null;\n assertiveLog: HTMLElement | null = null;\n politeLog: HTMLElement | null = null;\n\n constructor() {\n if (typeof document !== 'undefined') {\n this.node = document.createElement('div');\n this.node.dataset.liveAnnouncer = 'true';\n // copied from VisuallyHidden\n Object.assign(this.node.style, {\n border: 0,\n clip: 'rect(0 0 0 0)',\n clipPath: 'inset(50%)',\n height: '1px',\n margin: '-1px',\n overflow: 'hidden',\n padding: 0,\n position: 'absolute',\n width: '1px',\n whiteSpace: 'nowrap'\n });\n\n this.assertiveLog = this.createLog('assertive');\n this.node.appendChild(this.assertiveLog);\n\n this.politeLog = this.createLog('polite');\n this.node.appendChild(this.politeLog);\n\n document.body.prepend(this.node);\n }\n }\n\n isAttached() {\n return this.node?.isConnected;\n }\n\n createLog(ariaLive: string) {\n let node = document.createElement('div');\n node.setAttribute('role', 'log');\n node.setAttribute('aria-live', ariaLive);\n node.setAttribute('aria-relevant', 'additions');\n return node;\n }\n\n destroy() {\n if (!this.node) {\n return;\n }\n\n document.body.removeChild(this.node);\n this.node = null;\n }\n\n announce(message: Message, assertiveness = 'assertive', timeout = LIVEREGION_TIMEOUT_DELAY) {\n if (!this.node) {\n return;\n }\n\n let node = document.createElement('div');\n if (typeof message === 'object') {\n // To read an aria-labelledby, the element must have an appropriate role, such as img.\n node.setAttribute('role', 'img');\n node.setAttribute('aria-labelledby', message['aria-labelledby']);\n } else {\n node.textContent = message;\n }\n\n if (assertiveness === 'assertive') {\n this.assertiveLog?.appendChild(node);\n } else {\n this.politeLog?.appendChild(node);\n }\n\n if (message !== '') {\n setTimeout(() => {\n node.remove();\n }, timeout);\n }\n }\n\n clear(assertiveness: Assertiveness) {\n if (!this.node) {\n return;\n }\n\n if ((!assertiveness || assertiveness === 'assertive') && this.assertiveLog) {\n this.assertiveLog.innerHTML = '';\n }\n\n if ((!assertiveness || assertiveness === 'polite') && this.politeLog) {\n this.politeLog.innerHTML = '';\n }\n }\n}\n"],"names":[],"version":3,"file":"LiveAnnouncer.main.js.map"}
@@ -1,112 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */ /* Inspired by https://github.com/AlmeroSteyn/react-aria-live */ const $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY = 7000;
12
- let $319e236875307eab$var$liveAnnouncer = null;
13
- function $319e236875307eab$export$a9b970dcc4ae71a9(message, assertiveness = 'assertive', timeout = $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY) {
14
- if (!$319e236875307eab$var$liveAnnouncer) {
15
- $319e236875307eab$var$liveAnnouncer = new $319e236875307eab$var$LiveAnnouncer();
16
- // wait for the live announcer regions to be added to the dom, then announce
17
- // otherwise Safari won't announce the message if it's added too quickly
18
- // found most times less than 100ms were not consistent when announcing with Safari
19
- // IS_REACT_ACT_ENVIRONMENT is used by React 18. Previous versions checked for the `jest` global.
20
- // https://github.com/reactwg/react-18/discussions/102
21
- // if we're in a test environment, announce without waiting
22
- // @ts-ignore
23
- if (!(typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined')) setTimeout(()=>{
24
- if ($319e236875307eab$var$liveAnnouncer === null || $319e236875307eab$var$liveAnnouncer === void 0 ? void 0 : $319e236875307eab$var$liveAnnouncer.isAttached()) $319e236875307eab$var$liveAnnouncer === null || $319e236875307eab$var$liveAnnouncer === void 0 ? void 0 : $319e236875307eab$var$liveAnnouncer.announce(message, assertiveness, timeout);
25
- }, 100);
26
- else $319e236875307eab$var$liveAnnouncer.announce(message, assertiveness, timeout);
27
- } else $319e236875307eab$var$liveAnnouncer.announce(message, assertiveness, timeout);
28
- }
29
- function $319e236875307eab$export$d10ae4f68404609a(assertiveness) {
30
- if ($319e236875307eab$var$liveAnnouncer) $319e236875307eab$var$liveAnnouncer.clear(assertiveness);
31
- }
32
- function $319e236875307eab$export$d8686216b8b81b2f() {
33
- if ($319e236875307eab$var$liveAnnouncer) {
34
- $319e236875307eab$var$liveAnnouncer.destroy();
35
- $319e236875307eab$var$liveAnnouncer = null;
36
- }
37
- }
38
- // LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18
39
- // ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a
40
- // subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.
41
- // As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer
42
- // is simple enough to implement without React, so that's what we do here.
43
- // See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638
44
- class $319e236875307eab$var$LiveAnnouncer {
45
- isAttached() {
46
- var _this_node;
47
- return (_this_node = this.node) === null || _this_node === void 0 ? void 0 : _this_node.isConnected;
48
- }
49
- createLog(ariaLive) {
50
- let node = document.createElement('div');
51
- node.setAttribute('role', 'log');
52
- node.setAttribute('aria-live', ariaLive);
53
- node.setAttribute('aria-relevant', 'additions');
54
- return node;
55
- }
56
- destroy() {
57
- if (!this.node) return;
58
- document.body.removeChild(this.node);
59
- this.node = null;
60
- }
61
- announce(message, assertiveness = 'assertive', timeout = $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY) {
62
- var _this_assertiveLog, _this_politeLog;
63
- if (!this.node) return;
64
- let node = document.createElement('div');
65
- if (typeof message === 'object') {
66
- // To read an aria-labelledby, the element must have an appropriate role, such as img.
67
- node.setAttribute('role', 'img');
68
- node.setAttribute('aria-labelledby', message['aria-labelledby']);
69
- } else node.textContent = message;
70
- if (assertiveness === 'assertive') (_this_assertiveLog = this.assertiveLog) === null || _this_assertiveLog === void 0 ? void 0 : _this_assertiveLog.appendChild(node);
71
- else (_this_politeLog = this.politeLog) === null || _this_politeLog === void 0 ? void 0 : _this_politeLog.appendChild(node);
72
- if (message !== '') setTimeout(()=>{
73
- node.remove();
74
- }, timeout);
75
- }
76
- clear(assertiveness) {
77
- if (!this.node) return;
78
- if ((!assertiveness || assertiveness === 'assertive') && this.assertiveLog) this.assertiveLog.innerHTML = '';
79
- if ((!assertiveness || assertiveness === 'polite') && this.politeLog) this.politeLog.innerHTML = '';
80
- }
81
- constructor(){
82
- this.node = null;
83
- this.assertiveLog = null;
84
- this.politeLog = null;
85
- if (typeof document !== 'undefined') {
86
- this.node = document.createElement('div');
87
- this.node.dataset.liveAnnouncer = 'true';
88
- // copied from VisuallyHidden
89
- Object.assign(this.node.style, {
90
- border: 0,
91
- clip: 'rect(0 0 0 0)',
92
- clipPath: 'inset(50%)',
93
- height: '1px',
94
- margin: '-1px',
95
- overflow: 'hidden',
96
- padding: 0,
97
- position: 'absolute',
98
- width: '1px',
99
- whiteSpace: 'nowrap'
100
- });
101
- this.assertiveLog = this.createLog('assertive');
102
- this.node.appendChild(this.assertiveLog);
103
- this.politeLog = this.createLog('polite');
104
- this.node.appendChild(this.politeLog);
105
- document.body.prepend(this.node);
106
- }
107
- }
108
- }
109
-
110
-
111
- export {$319e236875307eab$export$a9b970dcc4ae71a9 as announce, $319e236875307eab$export$d10ae4f68404609a as clearAnnouncer, $319e236875307eab$export$d8686216b8b81b2f as destroyAnnouncer};
112
- //# sourceMappingURL=LiveAnnouncer.module.js.map
@@ -1,112 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */ /* Inspired by https://github.com/AlmeroSteyn/react-aria-live */ const $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY = 7000;
12
- let $319e236875307eab$var$liveAnnouncer = null;
13
- function $319e236875307eab$export$a9b970dcc4ae71a9(message, assertiveness = 'assertive', timeout = $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY) {
14
- if (!$319e236875307eab$var$liveAnnouncer) {
15
- $319e236875307eab$var$liveAnnouncer = new $319e236875307eab$var$LiveAnnouncer();
16
- // wait for the live announcer regions to be added to the dom, then announce
17
- // otherwise Safari won't announce the message if it's added too quickly
18
- // found most times less than 100ms were not consistent when announcing with Safari
19
- // IS_REACT_ACT_ENVIRONMENT is used by React 18. Previous versions checked for the `jest` global.
20
- // https://github.com/reactwg/react-18/discussions/102
21
- // if we're in a test environment, announce without waiting
22
- // @ts-ignore
23
- if (!(typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined')) setTimeout(()=>{
24
- if ($319e236875307eab$var$liveAnnouncer === null || $319e236875307eab$var$liveAnnouncer === void 0 ? void 0 : $319e236875307eab$var$liveAnnouncer.isAttached()) $319e236875307eab$var$liveAnnouncer === null || $319e236875307eab$var$liveAnnouncer === void 0 ? void 0 : $319e236875307eab$var$liveAnnouncer.announce(message, assertiveness, timeout);
25
- }, 100);
26
- else $319e236875307eab$var$liveAnnouncer.announce(message, assertiveness, timeout);
27
- } else $319e236875307eab$var$liveAnnouncer.announce(message, assertiveness, timeout);
28
- }
29
- function $319e236875307eab$export$d10ae4f68404609a(assertiveness) {
30
- if ($319e236875307eab$var$liveAnnouncer) $319e236875307eab$var$liveAnnouncer.clear(assertiveness);
31
- }
32
- function $319e236875307eab$export$d8686216b8b81b2f() {
33
- if ($319e236875307eab$var$liveAnnouncer) {
34
- $319e236875307eab$var$liveAnnouncer.destroy();
35
- $319e236875307eab$var$liveAnnouncer = null;
36
- }
37
- }
38
- // LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18
39
- // ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a
40
- // subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.
41
- // As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer
42
- // is simple enough to implement without React, so that's what we do here.
43
- // See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638
44
- class $319e236875307eab$var$LiveAnnouncer {
45
- isAttached() {
46
- var _this_node;
47
- return (_this_node = this.node) === null || _this_node === void 0 ? void 0 : _this_node.isConnected;
48
- }
49
- createLog(ariaLive) {
50
- let node = document.createElement('div');
51
- node.setAttribute('role', 'log');
52
- node.setAttribute('aria-live', ariaLive);
53
- node.setAttribute('aria-relevant', 'additions');
54
- return node;
55
- }
56
- destroy() {
57
- if (!this.node) return;
58
- document.body.removeChild(this.node);
59
- this.node = null;
60
- }
61
- announce(message, assertiveness = 'assertive', timeout = $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY) {
62
- var _this_assertiveLog, _this_politeLog;
63
- if (!this.node) return;
64
- let node = document.createElement('div');
65
- if (typeof message === 'object') {
66
- // To read an aria-labelledby, the element must have an appropriate role, such as img.
67
- node.setAttribute('role', 'img');
68
- node.setAttribute('aria-labelledby', message['aria-labelledby']);
69
- } else node.textContent = message;
70
- if (assertiveness === 'assertive') (_this_assertiveLog = this.assertiveLog) === null || _this_assertiveLog === void 0 ? void 0 : _this_assertiveLog.appendChild(node);
71
- else (_this_politeLog = this.politeLog) === null || _this_politeLog === void 0 ? void 0 : _this_politeLog.appendChild(node);
72
- if (message !== '') setTimeout(()=>{
73
- node.remove();
74
- }, timeout);
75
- }
76
- clear(assertiveness) {
77
- if (!this.node) return;
78
- if ((!assertiveness || assertiveness === 'assertive') && this.assertiveLog) this.assertiveLog.innerHTML = '';
79
- if ((!assertiveness || assertiveness === 'polite') && this.politeLog) this.politeLog.innerHTML = '';
80
- }
81
- constructor(){
82
- this.node = null;
83
- this.assertiveLog = null;
84
- this.politeLog = null;
85
- if (typeof document !== 'undefined') {
86
- this.node = document.createElement('div');
87
- this.node.dataset.liveAnnouncer = 'true';
88
- // copied from VisuallyHidden
89
- Object.assign(this.node.style, {
90
- border: 0,
91
- clip: 'rect(0 0 0 0)',
92
- clipPath: 'inset(50%)',
93
- height: '1px',
94
- margin: '-1px',
95
- overflow: 'hidden',
96
- padding: 0,
97
- position: 'absolute',
98
- width: '1px',
99
- whiteSpace: 'nowrap'
100
- });
101
- this.assertiveLog = this.createLog('assertive');
102
- this.node.appendChild(this.assertiveLog);
103
- this.politeLog = this.createLog('polite');
104
- this.node.appendChild(this.politeLog);
105
- document.body.prepend(this.node);
106
- }
107
- }
108
- }
109
-
110
-
111
- export {$319e236875307eab$export$a9b970dcc4ae71a9 as announce, $319e236875307eab$export$d10ae4f68404609a as clearAnnouncer, $319e236875307eab$export$d8686216b8b81b2f as destroyAnnouncer};
112
- //# sourceMappingURL=LiveAnnouncer.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":"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","sources":["packages/@react-aria/live-announcer/src/LiveAnnouncer.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\ntype Assertiveness = 'assertive' | 'polite';\n\n/* Inspired by https://github.com/AlmeroSteyn/react-aria-live */\nconst LIVEREGION_TIMEOUT_DELAY = 7000;\n\nlet liveAnnouncer: LiveAnnouncer | null = null;\n\ntype Message = string | {'aria-labelledby': string};\n\n/**\n * Announces the message using screen reader technology.\n */\nexport function announce(\n message: Message,\n assertiveness: Assertiveness = 'assertive',\n timeout = LIVEREGION_TIMEOUT_DELAY\n): void {\n if (!liveAnnouncer) {\n liveAnnouncer = new LiveAnnouncer();\n // wait for the live announcer regions to be added to the dom, then announce\n // otherwise Safari won't announce the message if it's added too quickly\n // found most times less than 100ms were not consistent when announcing with Safari\n\n // IS_REACT_ACT_ENVIRONMENT is used by React 18. Previous versions checked for the `jest` global.\n // https://github.com/reactwg/react-18/discussions/102\n // if we're in a test environment, announce without waiting\n // @ts-ignore\n if (!(typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined')) {\n setTimeout(() => {\n if (liveAnnouncer?.isAttached()) {\n liveAnnouncer?.announce(message, assertiveness, timeout);\n }\n }, 100);\n } else {\n liveAnnouncer.announce(message, assertiveness, timeout);\n }\n } else {\n liveAnnouncer.announce(message, assertiveness, timeout);\n }\n}\n\n/**\n * Stops all queued announcements.\n */\nexport function clearAnnouncer(assertiveness: Assertiveness): void {\n if (liveAnnouncer) {\n liveAnnouncer.clear(assertiveness);\n }\n}\n\n/**\n * Removes the announcer from the DOM.\n */\nexport function destroyAnnouncer(): void {\n if (liveAnnouncer) {\n liveAnnouncer.destroy();\n liveAnnouncer = null;\n }\n}\n\n// LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18\n// ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a\n// subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.\n// As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer\n// is simple enough to implement without React, so that's what we do here.\n// See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638\nclass LiveAnnouncer {\n node: HTMLElement | null = null;\n assertiveLog: HTMLElement | null = null;\n politeLog: HTMLElement | null = null;\n\n constructor() {\n if (typeof document !== 'undefined') {\n this.node = document.createElement('div');\n this.node.dataset.liveAnnouncer = 'true';\n // copied from VisuallyHidden\n Object.assign(this.node.style, {\n border: 0,\n clip: 'rect(0 0 0 0)',\n clipPath: 'inset(50%)',\n height: '1px',\n margin: '-1px',\n overflow: 'hidden',\n padding: 0,\n position: 'absolute',\n width: '1px',\n whiteSpace: 'nowrap'\n });\n\n this.assertiveLog = this.createLog('assertive');\n this.node.appendChild(this.assertiveLog);\n\n this.politeLog = this.createLog('polite');\n this.node.appendChild(this.politeLog);\n\n document.body.prepend(this.node);\n }\n }\n\n isAttached() {\n return this.node?.isConnected;\n }\n\n createLog(ariaLive: string) {\n let node = document.createElement('div');\n node.setAttribute('role', 'log');\n node.setAttribute('aria-live', ariaLive);\n node.setAttribute('aria-relevant', 'additions');\n return node;\n }\n\n destroy() {\n if (!this.node) {\n return;\n }\n\n document.body.removeChild(this.node);\n this.node = null;\n }\n\n announce(message: Message, assertiveness = 'assertive', timeout = LIVEREGION_TIMEOUT_DELAY) {\n if (!this.node) {\n return;\n }\n\n let node = document.createElement('div');\n if (typeof message === 'object') {\n // To read an aria-labelledby, the element must have an appropriate role, such as img.\n node.setAttribute('role', 'img');\n node.setAttribute('aria-labelledby', message['aria-labelledby']);\n } else {\n node.textContent = message;\n }\n\n if (assertiveness === 'assertive') {\n this.assertiveLog?.appendChild(node);\n } else {\n this.politeLog?.appendChild(node);\n }\n\n if (message !== '') {\n setTimeout(() => {\n node.remove();\n }, timeout);\n }\n }\n\n clear(assertiveness: Assertiveness) {\n if (!this.node) {\n return;\n }\n\n if ((!assertiveness || assertiveness === 'assertive') && this.assertiveLog) {\n this.assertiveLog.innerHTML = '';\n }\n\n if ((!assertiveness || assertiveness === 'polite') && this.politeLog) {\n this.politeLog.innerHTML = '';\n }\n }\n}\n"],"names":[],"version":3,"file":"LiveAnnouncer.module.js.map"}
package/dist/types.d.ts DELETED
@@ -1,18 +0,0 @@
1
- type Assertiveness = 'assertive' | 'polite';
2
- type Message = string | {
3
- 'aria-labelledby': string;
4
- };
5
- /**
6
- * Announces the message using screen reader technology.
7
- */
8
- export function announce(message: Message, assertiveness?: Assertiveness, timeout?: number): void;
9
- /**
10
- * Stops all queued announcements.
11
- */
12
- export function clearAnnouncer(assertiveness: Assertiveness): void;
13
- /**
14
- * Removes the announcer from the DOM.
15
- */
16
- export function destroyAnnouncer(): void;
17
-
18
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"mappings":"AAYA,qBAAqB,WAAW,GAAG,QAAQ,CAAC;AAO5C,eAAe,MAAM,GAAG;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAC,CAAC;AAEpD;;GAEG;AACH,yBACE,OAAO,EAAE,OAAO,EAChB,aAAa,GAAE,aAA2B,EAC1C,OAAO,SAA2B,GACjC,IAAI,CAuBN;AAED;;GAEG;AACH,+BAA+B,aAAa,EAAE,aAAa,GAAG,IAAI,CAIjE;AAED;;GAEG;AACH,oCAAoC,IAAI,CAKvC","sources":["packages/@react-aria/live-announcer/src/packages/@react-aria/live-announcer/src/LiveAnnouncer.tsx","packages/@react-aria/live-announcer/src/packages/@react-aria/live-announcer/src/index.ts","packages/@react-aria/live-announcer/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {announce, clearAnnouncer, destroyAnnouncer} from './LiveAnnouncer';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -1,173 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- type Assertiveness = 'assertive' | 'polite';
14
-
15
- /* Inspired by https://github.com/AlmeroSteyn/react-aria-live */
16
- const LIVEREGION_TIMEOUT_DELAY = 7000;
17
-
18
- let liveAnnouncer: LiveAnnouncer | null = null;
19
-
20
- type Message = string | {'aria-labelledby': string};
21
-
22
- /**
23
- * Announces the message using screen reader technology.
24
- */
25
- export function announce(
26
- message: Message,
27
- assertiveness: Assertiveness = 'assertive',
28
- timeout = LIVEREGION_TIMEOUT_DELAY
29
- ): void {
30
- if (!liveAnnouncer) {
31
- liveAnnouncer = new LiveAnnouncer();
32
- // wait for the live announcer regions to be added to the dom, then announce
33
- // otherwise Safari won't announce the message if it's added too quickly
34
- // found most times less than 100ms were not consistent when announcing with Safari
35
-
36
- // IS_REACT_ACT_ENVIRONMENT is used by React 18. Previous versions checked for the `jest` global.
37
- // https://github.com/reactwg/react-18/discussions/102
38
- // if we're in a test environment, announce without waiting
39
- // @ts-ignore
40
- if (!(typeof IS_REACT_ACT_ENVIRONMENT === 'boolean' ? IS_REACT_ACT_ENVIRONMENT : typeof jest !== 'undefined')) {
41
- setTimeout(() => {
42
- if (liveAnnouncer?.isAttached()) {
43
- liveAnnouncer?.announce(message, assertiveness, timeout);
44
- }
45
- }, 100);
46
- } else {
47
- liveAnnouncer.announce(message, assertiveness, timeout);
48
- }
49
- } else {
50
- liveAnnouncer.announce(message, assertiveness, timeout);
51
- }
52
- }
53
-
54
- /**
55
- * Stops all queued announcements.
56
- */
57
- export function clearAnnouncer(assertiveness: Assertiveness): void {
58
- if (liveAnnouncer) {
59
- liveAnnouncer.clear(assertiveness);
60
- }
61
- }
62
-
63
- /**
64
- * Removes the announcer from the DOM.
65
- */
66
- export function destroyAnnouncer(): void {
67
- if (liveAnnouncer) {
68
- liveAnnouncer.destroy();
69
- liveAnnouncer = null;
70
- }
71
- }
72
-
73
- // LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18
74
- // ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a
75
- // subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.
76
- // As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer
77
- // is simple enough to implement without React, so that's what we do here.
78
- // See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638
79
- class LiveAnnouncer {
80
- node: HTMLElement | null = null;
81
- assertiveLog: HTMLElement | null = null;
82
- politeLog: HTMLElement | null = null;
83
-
84
- constructor() {
85
- if (typeof document !== 'undefined') {
86
- this.node = document.createElement('div');
87
- this.node.dataset.liveAnnouncer = 'true';
88
- // copied from VisuallyHidden
89
- Object.assign(this.node.style, {
90
- border: 0,
91
- clip: 'rect(0 0 0 0)',
92
- clipPath: 'inset(50%)',
93
- height: '1px',
94
- margin: '-1px',
95
- overflow: 'hidden',
96
- padding: 0,
97
- position: 'absolute',
98
- width: '1px',
99
- whiteSpace: 'nowrap'
100
- });
101
-
102
- this.assertiveLog = this.createLog('assertive');
103
- this.node.appendChild(this.assertiveLog);
104
-
105
- this.politeLog = this.createLog('polite');
106
- this.node.appendChild(this.politeLog);
107
-
108
- document.body.prepend(this.node);
109
- }
110
- }
111
-
112
- isAttached() {
113
- return this.node?.isConnected;
114
- }
115
-
116
- createLog(ariaLive: string) {
117
- let node = document.createElement('div');
118
- node.setAttribute('role', 'log');
119
- node.setAttribute('aria-live', ariaLive);
120
- node.setAttribute('aria-relevant', 'additions');
121
- return node;
122
- }
123
-
124
- destroy() {
125
- if (!this.node) {
126
- return;
127
- }
128
-
129
- document.body.removeChild(this.node);
130
- this.node = null;
131
- }
132
-
133
- announce(message: Message, assertiveness = 'assertive', timeout = LIVEREGION_TIMEOUT_DELAY) {
134
- if (!this.node) {
135
- return;
136
- }
137
-
138
- let node = document.createElement('div');
139
- if (typeof message === 'object') {
140
- // To read an aria-labelledby, the element must have an appropriate role, such as img.
141
- node.setAttribute('role', 'img');
142
- node.setAttribute('aria-labelledby', message['aria-labelledby']);
143
- } else {
144
- node.textContent = message;
145
- }
146
-
147
- if (assertiveness === 'assertive') {
148
- this.assertiveLog?.appendChild(node);
149
- } else {
150
- this.politeLog?.appendChild(node);
151
- }
152
-
153
- if (message !== '') {
154
- setTimeout(() => {
155
- node.remove();
156
- }, timeout);
157
- }
158
- }
159
-
160
- clear(assertiveness: Assertiveness) {
161
- if (!this.node) {
162
- return;
163
- }
164
-
165
- if ((!assertiveness || assertiveness === 'assertive') && this.assertiveLog) {
166
- this.assertiveLog.innerHTML = '';
167
- }
168
-
169
- if ((!assertiveness || assertiveness === 'polite') && this.politeLog) {
170
- this.politeLog.innerHTML = '';
171
- }
172
- }
173
- }