{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notice-web",
  "title": "Notice (Web Components)",
  "description": "A calm callout for info, success, a warning or an error, with optional actions and Dismiss.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/web@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/web/notice.ts",
      "content": "import { type NoticeApi, type NoticeOptions, noticePrimitive } from \"@kind-ui/agent-ui/core\";\nimport { createParts, type UiActionDetail, wrappedButton } from \"@ui-sdk/web\";\nimport type { AttributeProperties, UiElement } from \"@ui-sdk/web/events\";\n\nconst HEAD =\n  \"<kind-notice-icon></kind-notice-icon><kind-notice-title></kind-notice-title><kind-notice-reset></kind-notice-reset>\";\nconst DISMISS = \"<kind-notice-dismiss><button></button></kind-notice-dismiss>\";\n\n// Titles this element filled in. A title someone wrote text into keeps it, as React's `NoticeTitle` children do.\n// Kept across instances, because UI SDK rebuilds one when the element returns to the page.\nconst owned = new WeakSet<Element>();\n\ntype Movable = Element & { moveBefore?: (node: Node, child: Node | null) => void };\n\n// Dismiss stays last, so Tab reaches the text's buttons before it, however late the host adds them. `moveBefore`\n// keeps it focused where the browser has it; `append` blurs it.\nconst keepLast = (el: Movable, dismiss: Element | null) => {\n  if (!dismiss || el.lastElementChild === dismiss) return;\n  if (el.moveBefore) el.moveBefore(dismiss, null);\n  else el.append(dismiss);\n};\n\n/**\n * `<kind-notice variant=\"…\" label=\"…\" resets-at=\"…\">` takes its text inside a `<kind-notice-description>` and its buttons inside\n * a `<kind-notice-actions>`, and adds its mark and title before them and Dismiss after them, unless it has a mark\n * of its own. The `can-dismiss` attribute shows Dismiss, which fades the notice out and then fires `dismiss`:\n * remove the notice then, or call `event.detail.waitUntil(promise)` and reject it to bring the notice back.\n */\nexport function defineNotice(): void {\n  if (customElements.get(\"kind-notice\")) return;\n  createParts(noticePrimitive, {\n    root: {\n      tag: \"kind-notice\",\n      kinds: { canDismiss: \"boolean\" },\n      // Without the attribute the callback is left out; with it, `@ui-sdk/web` fills it in with an event.\n      options: (el) => ((el as KindNoticeElement).canDismiss ? {} : { onDismiss: undefined }),\n      render: (el, instance) => {\n        let dismiss: Element | null = null;\n        if (!el.querySelector(\":scope > kind-notice-icon\")) {\n          el.insertAdjacentHTML(\"afterbegin\", HEAD);\n          el.insertAdjacentHTML(\"beforeend\", DISMISS);\n          dismiss = el.lastElementChild;\n        }\n        const fill = (part: Element | null, text: string) => {\n          if (!part || (!owned.has(part) && part.textContent)) return;\n          owned.add(part);\n          if (part.textContent !== text) part.textContent = text;\n        };\n        const draw = () => {\n          const state = instance.get();\n          fill(el.querySelector(\":scope > kind-notice-title\"), state.label);\n          fill(el.querySelector(\":scope > kind-notice-reset\"), (instance.api as NoticeApi).resetText(state));\n        };\n        draw();\n        const unsubscribe = instance.subscribe(draw);\n        const arrivals = new MutationObserver(() => keepLast(el, dismiss));\n        arrivals.observe(el, { childList: true });\n        return () => {\n          unsubscribe();\n          arrivals.disconnect();\n        };\n      },\n    },\n    icon: \"kind-notice-icon\",\n    title: \"kind-notice-title\",\n    description: \"kind-notice-description\",\n    reset: \"kind-notice-reset\",\n    actions: \"kind-notice-actions\",\n    dismiss: { tag: \"kind-notice-dismiss\", target: wrappedButton, display: \"contents\" },\n  });\n}\n\nexport type KindNoticeEvents = {\n  dismiss: CustomEvent<Pick<UiActionDetail, \"waitUntil\">>;\n};\n\nexport interface KindNoticeElement\n  extends UiElement<KindNoticeEvents>,\n    AttributeProperties<typeof noticePrimitive> {\n  canDismiss: boolean;\n  /** Where focus goes when Dismiss is pressed. Defaults to the next element Tab reaches after the notice. */\n  focusFallback?: NoticeOptions[\"focusFallback\"];\n}\n\ndeclare global {\n  interface HTMLElementTagNameMap {\n    \"kind-notice\": KindNoticeElement;\n    \"kind-notice-icon\": HTMLElement;\n    \"kind-notice-title\": HTMLElement;\n    \"kind-notice-description\": HTMLElement;\n    \"kind-notice-reset\": HTMLElement;\n    \"kind-notice-actions\": HTMLElement;\n    \"kind-notice-dismiss\": HTMLElement;\n  }\n}\n",
      "type": "registry:ui",
      "target": "@ui/web/notice.ts"
    }
  ],
  "meta": {
    "layer": "web"
  },
  "type": "registry:ui"
}
