The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { msg } from "gt-react"; |
| 2 | |
| 3 | import { m } from "../i18n/messages"; |
| 4 | |
| 5 | let latestOpen = false; |
| 6 | let firstWritePending = false; |
| 7 | |
| 8 | /** Alternating atomic live regions allow repeated user actions to be announced, as in VS Code aria.ts. */ |
| 9 | export function announceSidebarVisibility(open: boolean) { |
| 10 | latestOpen = open; |
| 11 | if (firstWritePending) return; |
| 12 | let container = document.getElementById("workspace-visibility-alerts"); |
| 13 | const created = !container; |
| 14 | if (!container) { |
| 15 | container = document.createElement("div"); |
| 16 | container.id = "workspace-visibility-alerts"; |
| 17 | container.className = "sr-only"; |
| 18 | for (let index = 0; index < 2; index++) { |
| 19 | const alert = document.createElement("div"); |
| 20 | alert.setAttribute("aria-live", "polite"); |
| 21 | alert.setAttribute("aria-atomic", "true"); |
| 22 | container.append(alert); |
| 23 | } |
| 24 | document.body.append(container); |
| 25 | } |
| 26 | const [first, second] = Array.from(container.children); |
| 27 | const write = () => { |
| 28 | firstWritePending = false; |
| 29 | const next = first!.textContent ? second! : first!; |
| 30 | first!.textContent = ""; |
| 31 | second!.textContent = ""; |
| 32 | next.textContent = latestOpen ? m(msg("Sidebar shown")) : m(msg("Sidebar hidden")); |
| 33 | }; |
| 34 | // Screen readers ignore text written in the same task that inserts its live region. |
| 35 | // Toggles during that delay only update the state the pending write announces. |
| 36 | if (created) { |
| 37 | firstWritePending = true; |
| 38 | setTimeout(write, 100); |
| 39 | } else write(); |
| 40 | } |