{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "announce",
  "title": "Announce",
  "description": "Tells a screen reader what changed, such as a tag or a file joining a list, politely, through ui-sdk’s live regions. The same words said twice are heard twice, and what is said in one go is read as one message.",
  "dependencies": [
    "@ui-sdk/core"
  ],
  "files": [
    {
      "path": "registry/lib/announce.ts",
      "content": "import { prepareAnnouncements, announce as say } from '@ui-sdk/core'\n\n/*\n * Tells a screen reader what changed, for parts whose changes it can't see\n * happen, such as a chip or a file joining a list. It speaks through ui-sdk's\n * live regions, one pair per page, which ui-sdk's own components share.\n */\n\n// Some screen readers hear only a region that was in the page before its words.\nif (typeof document !== 'undefined') prepareAnnouncements(document)\n\nlet waiting: string[] | null = null\n\n/**\n * Says `text` politely. What is said in one go, such as several uploads\n * ending in one render, is read as one message, so a later one doesn't cut an\n * earlier one off, and the same words twice in it are read once.\n */\nfunction announce(text: string) {\n  if (!text) return\n  if (waiting) {\n    waiting.push(text)\n    return\n  }\n  const said = (waiting = [text])\n  queueMicrotask(() => {\n    waiting = null\n    say(joinSaid(said))\n  })\n}\n\n/** Messages as one: each once, in order, a full stop between them unless one already ends a sentence. */\nfunction joinSaid(said: readonly string[]) {\n  return [...new Set(said)].reduce((message, next) =>\n    /[.!?…]$/.test(message) ? `${message} ${next}` : `${message}. ${next}`,\n  )\n}\n\nexport { announce, joinSaid }\n",
      "type": "registry:lib",
      "target": "@lib/announce.ts"
    }
  ],
  "type": "registry:lib"
}