{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notification",
  "type": "registry:ui",
  "title": "<ui-notification>",
  "description": "Carbon notification in one element: `InlineNotification` (default), `ToastNotification` (`variant=\"toast\"`), `ActionableNotification` (any variant with `action-label`) and `Callout` (`variant=\"callout\"`: static inline box with no role, no close button and no autofocus — for persistent on-page guidance; its action button is described by the title). Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "lit@^3.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/core-notification",
    "@kanok-ui/shared-element",
    "@kanok-ui/shared-events",
    "@kanok-ui/shared-field",
    "@kanok-ui/shared-localize",
    "@kanok-ui/shared-slots",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/notification/notification.styles.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/notification/notification.styles.ts",
      "content": "import { css } from 'lit';\n\n/** Styles of `<ui-notification>`. */\nexport const notificationStyles = css`\n    :host {\n        display: block;\n        font-family: var(--ui-font-family);\n    }\n\n    :host(:not([open])),\n    :host([open='false']) {\n        display: none;\n    }\n\n    /* Carbon inline notification: 288px min, responsive max, 48px min height, 3px status bar */\n    .box {\n        position: relative;\n        box-sizing: border-box;\n        display: flex;\n        flex-wrap: wrap;\n        width: 100%;\n        min-width: 288px;\n        max-width: 288px;\n        min-height: 48px;\n        border-inline-start: var(--ui-notification-bar-width, 3px) solid var(--_kind); /* the status bar (Kanok: none, the icon tells) */\n        border-radius: var(--ui-notification-radius, 0); /* Carbon: square */\n        /* the high-contrast surface: Carbon's inverse; a design can make it an elevated light / raised one (--ui-notification-*) */\n        background-color: var(--ui-notification-background, var(--ui-inverse-canvas));\n        color: var(--ui-notification-ink, var(--ui-inverse-ink));\n    }\n\n    :host(:not([low-contrast])) .box {\n        box-shadow: var(--ui-notification-edge, none);\n    }\n\n    @media (min-width: 672px) {\n        .box {\n            flex-wrap: nowrap;\n            max-width: 608px;\n        }\n    }\n\n    @media (min-width: 1056px) {\n        .box {\n            max-width: 736px;\n        }\n    }\n\n    @media (min-width: 1584px) {\n        .box {\n            max-width: 832px;\n        }\n    }\n\n    /* a banner across its container (no Carbon counterpart), however narrow; a toast keeps its 288px */\n    :host([full-width]:not([variant='toast'])) .box {\n        min-width: 0;\n        max-width: none;\n    }\n\n    /* small screens: the text takes its own line so the action wraps under it, clear of the close button (as in 288px) */\n    @media (max-width: 671.98px) {\n        :host([full-width]:not([variant='toast'])) .details {\n            flex-basis: calc(100% - 61px);\n        }\n    }\n\n    :host([kind='error']) .box {\n        --_kind: var(--ui-error);\n        --_bg: var(--ui-notification-background-error);\n    }\n    :host([kind='success']) .box {\n        --_kind: var(--ui-success);\n        --_bg: var(--ui-notification-background-success);\n    }\n    :host([kind='info']) .box,\n    :host([kind='info-square']) .box {\n        --_kind: var(--ui-info);\n        --_bg: var(--ui-notification-background-info);\n    }\n    :host([kind='warning']) .box,\n    :host([kind='warning-alt']) .box {\n        --_kind: var(--ui-warning);\n        --_bg: var(--ui-notification-background-warning);\n    }\n\n    /* low contrast: tinted surface, primary text, 1px status border on the other three sides */\n    :host([low-contrast]) .box {\n        background-color: var(--_bg);\n        color: var(--ui-ink);\n    }\n\n    :host([low-contrast]) .box::before {\n        content: '';\n        position: absolute;\n        inset: 0;\n        box-sizing: border-box;\n        border: 1px solid var(--_kind);\n        border-inline-start-width: var(--ui-notification-frame-start, 0); /* the frame's fourth side, where there is no bar */\n        border-radius: inherit;\n        filter: opacity(0.4); /* Carbon: the frame at 40% (the status bar stays full) */\n        pointer-events: none;\n    }\n\n    .details {\n        display: flex;\n        flex-grow: 1;\n        margin-inline: 13px 48px;\n    }\n\n    @media (min-width: 672px) {\n        .details {\n            margin: 0 13px;\n        }\n    }\n\n    .icon {\n        flex-shrink: 0;\n        width: 20px;\n        height: 20px;\n        margin-block-start: 14px;\n        margin-inline-end: var(--ui-space-md);\n        fill: var(--_kind);\n    }\n\n    :host([kind='warning']) .icon .mark,\n    :host([kind='warning-alt']) .icon .mark {\n        fill: #161616; /* Carbon $black-100: the mark stays black on the yellow */\n    }\n\n    .text {\n        display: flex;\n        flex-wrap: wrap;\n        padding: 15px 0;\n    }\n\n    .title {\n        margin-inline-end: var(--ui-space-xxs);\n        font: var(--ui-font-body-emphasis); /* heading-compact-01 */\n        line-height: 18px; /* exact, so 15 + 18 + 15 = Carbon's 48px */\n        letter-spacing: var(--ui-tracking-body);\n    }\n\n    .subtitle,\n    .caption,\n    ::slotted(*) {\n        font: var(--ui-font-body-sm);\n        line-height: 18px;\n        letter-spacing: var(--ui-tracking-body);\n        overflow-wrap: anywhere;\n    }\n\n    .caption {\n        width: 100%;\n        padding-block-start: var(--ui-space-xs);\n    }\n\n    ::slotted(a) {\n        color: var(--ui-notification-link, var(--ui-link-inverse));\n        text-decoration: none;\n    }\n\n    :host([low-contrast]) ::slotted(a) {\n        color: var(--ui-primary);\n    }\n\n    ::slotted(a:hover) {\n        text-decoration: underline;\n    }\n\n    /* --ui-close-size / --ui-close-inset / --ui-icon-control-radius: a design can make it a smaller round button set in from the corner (Carbon: a 48px square in the corner) */\n    .close {\n        position: absolute;\n        top: 0;\n        inset-inline-end: 0;\n        display: flex;\n        align-items: center;\n        justify-content: center;\n        width: var(--ui-close-size, 48px);\n        height: var(--ui-close-size, 48px);\n        min-width: var(--ui-close-size, 48px);\n        min-height: var(--ui-close-size, 48px);\n        margin: var(--ui-close-inset, 0);\n        padding: 0;\n        border: none;\n        border-radius: var(--ui-icon-control-radius, 0);\n        background: transparent;\n        color: inherit;\n        cursor: pointer;\n        /* Carbon inline / actionable close button: 110ms, standard productive */\n        transition:\n            outline var(--ui-duration-moderate) var(--ui-easing),\n            background-color var(--ui-duration-moderate) var(--ui-easing);\n    }\n\n    /* Carbon toast close button: 250ms (no token) with the default easing; reduced motion: none, as the tokens */\n    @media (prefers-reduced-motion: no-preference) {\n        :host([variant='toast']) .close:not(.action + .close) {\n            transition:\n                outline 250ms,\n                background-color 250ms;\n        }\n    }\n\n    /* Carbon: in the row from md up (after the action), absolute only on small screens and in toasts */\n    @media (min-width: 672px) {\n        :host(:not([variant='toast'])) .close {\n            position: static;\n        }\n    }\n\n    .close-icon {\n        width: 20px;\n        height: 20px;\n        fill: currentColor;\n    }\n\n    /* Carbon: the close button has no hover fill (only the action button does), so it never covers the low-contrast frame */\n\n    .close:focus-visible {\n        outline: var(--ui-focus-width, 2px) solid var(--ui-notification-focus, var(--ui-inverse-ink));\n        outline-offset: var(--ui-focus-offset, -2px);\n    }\n\n    :host([low-contrast]) .close:focus-visible {\n        outline-color: var(--ui-focus);\n    }\n\n    /* inline action: Carbon ghost button, 32px, 32px before it */\n    .action {\n        box-sizing: border-box;\n        display: inline-flex;\n        align-items: center;\n        height: 32px;\n        margin-block-end: var(--ui-space-xs);\n        margin-inline-start: var(--ui-space-xl);\n        padding: 0 var(--ui-space-md);\n        border: 1px solid transparent;\n        border-radius: var(--ui-button-radius, 0); /* a button: the button setting (Kanok: a pill) */\n        background: transparent;\n        color: var(--ui-notification-link, var(--ui-link-inverse));\n        font: var(--ui-font-button);\n        letter-spacing: var(--ui-tracking-body);\n        cursor: pointer;\n        /* Carbon .cds--btn: 70ms, entrance productive */\n        transition:\n            background var(--ui-duration-fast) var(--ui-easing-entrance),\n            box-shadow var(--ui-duration-fast) var(--ui-easing-entrance),\n            border-color var(--ui-duration-fast) var(--ui-easing-entrance),\n            outline var(--ui-duration-fast) var(--ui-easing-entrance);\n    }\n\n    @media (min-width: 672px) {\n        .action {\n            margin: var(--ui-space-xs) 0;\n        }\n    }\n\n    .action:hover {\n        background-color: var(--ui-notification-hover, var(--ui-inverse-hover));\n    }\n\n    .action:focus-visible {\n        outline: var(--ui-focus-width, 2px) solid var(--ui-notification-focus, var(--ui-inverse-ink));\n        outline-offset: var(--ui-focus-offset, -2px);\n    }\n\n    :host([low-contrast]) .action {\n        color: var(--ui-button-tertiary-ink, var(--ui-primary));\n    }\n\n    :host([low-contrast]) .action:hover {\n        background-color: var(--ui-notification-action-hover, var(--ui-ghost-hover));\n    }\n\n    :host([low-contrast]) .action:focus-visible {\n        outline-color: var(--ui-focus);\n    }\n\n    /* ---- toast: 288px, shadow, text stacked, action as a tertiary button below ---- */\n    :host([variant='toast']) .box {\n        flex-wrap: wrap;\n        width: 288px;\n        min-width: 288px;\n        max-width: 288px;\n        min-height: 0;\n        padding-inline-start: 13px;\n        box-shadow: var(--ui-toast-shadow, 0 2px 6px 0 rgb(0 0 0 / 0.2));\n    }\n\n    :host([variant='toast']) .details {\n        display: flex;\n        flex-grow: 1;\n        margin: 0;\n        margin-block-end: var(--ui-space-md);\n        margin-inline-end: 48px; /* Carbon spacing-09: clear of the close button, so an action wraps below */\n    }\n\n    :host([variant='toast']) .icon {\n        margin-block-start: var(--ui-space-md);\n    }\n\n    :host([variant='toast']) .text {\n        display: block;\n        padding: 0;\n    }\n\n    :host([variant='toast']) .title {\n        display: block;\n        margin: var(--ui-space-md) 0 0;\n        overflow-wrap: anywhere;\n    }\n\n    :host([variant='toast']) .subtitle {\n        display: block;\n        margin: 0 0 var(--ui-space-md);\n    }\n\n    :host([variant='toast']) .action {\n        margin: 0 0 var(--ui-space-md) 49px;\n        border-color: var(--ui-notification-action-tertiary-inverse);\n        color: var(--ui-notification-action-tertiary-inverse);\n    }\n\n    :host([variant='toast']) .action:hover {\n        background-color: var(--ui-notification-action-tertiary-inverse-hover);\n        color: var(--ui-notification-action-tertiary-inverse-text);\n    }\n\n    :host([variant='toast']) .action:active {\n        background-color: var(--ui-notification-action-tertiary-inverse-active);\n    }\n\n    :host([variant='toast'][low-contrast]) .action {\n        border-color: var(--ui-button-tertiary-border, var(--ui-primary));\n        color: var(--ui-button-tertiary-ink, var(--ui-primary));\n    }\n\n    :host([variant='toast'][low-contrast]) .action:hover {\n        background-color: var(--ui-primary);\n        color: var(--ui-on-primary);\n    }\n\n    @media (forced-colors: active) {\n        .box {\n            border: 1px solid CanvasText;\n            border-inline-start-width: 3px;\n        }\n        .close,\n        .action {\n            border: 1px solid ButtonText;\n        }\n    }\n`;\n"
    },
    {
      "path": "src/primitives/notification/notification.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/notification/notification.ts",
      "content": "import { html, nothing, svg, type TemplateResult } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport { moveTitleToHeading, uid, defaultTrue, deepActiveElement } from '../shared/field.ts';\nimport { SlotController } from '../shared/slots.ts';\nimport { LocalizeController } from '../shared/localize.ts';\nimport type { CloseDetail } from '../shared/events.ts';\nimport { UiElement } from '../shared/element.ts';\nimport { Countdown, notificationRole, wrapTab, type NotificationKind, type NotificationRole, type NotificationVariant } from '../../core/notification.ts';\nimport { notificationStyles } from './notification.styles.ts';\n\nexport type { NotificationKind, NotificationVariant, NotificationRole } from '../../core/notification.ts';\n\n// `svg` templates: fragments rendered inside an <svg> must be created in the SVG namespace, or they stay invisible\nconst ICONS: Record<NotificationKind, TemplateResult> = {\n    error: svg`<path d=\"M10 1a9 9 0 1 0 0 18 9 9 0 0 0 0-18Zm3.5 13.5L10 11l-3.5 3.5L5 13l3.5-3.5L5 6l1.5-1.5L10 8l3.5-3.5L15 6l-3.5 3.5L15 13z\" />`,\n    success: svg`<path d=\"M10 1a9 9 0 1 0 0 18 9 9 0 0 0 0-18ZM8.5 14 4.4 9.9l1.4-1.4 2.7 2.7 5.7-5.7 1.4 1.4z\" />`,\n    info: svg`<path d=\"M10 1a9 9 0 1 0 0 18 9 9 0 0 0 0-18Zm0 3.5a1.25 1.25 0 1 1 0 2.5 1.25 1.25 0 0 1 0-2.5ZM12.5 15h-5v-1.5H9V10H7.5V8.5H11v5h1.5z\" />`,\n    'info-square': svg`<path d=\"M17 1H3a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2Zm-7 3.5a1.25 1.25 0 1 1 0 2.5 1.25 1.25 0 0 1 0-2.5ZM12.5 15h-5v-1.5H9V10H7.5V8.5H11v5h1.5z\" />`,\n    warning: svg`<path class=\"mark-bg\" d=\"M10 1a9 9 0 1 0 0 18 9 9 0 0 0 0-18Z\" /><path class=\"mark\" fill=\"#161616\" d=\"M9.25 5h1.5v6.5h-1.5zM10 15.3a1.1 1.1 0 1 1 0-2.2 1.1 1.1 0 0 1 0 2.2Z\" />`,\n    'warning-alt': svg`<path class=\"mark-bg\" d=\"M10.9 1.6a1 1 0 0 0-1.8 0L1.2 17a1 1 0 0 0 .9 1.5h15.8a1 1 0 0 0 .9-1.5z\" /><path class=\"mark\" fill=\"#161616\" d=\"M9.25 7h1.5v5.5h-1.5zM10 16.3a1.1 1.1 0 1 1 0-2.2 1.1 1.1 0 0 1 0 2.2Z\" />`,\n};\n\n/** What Tab stops on in the content (links, controls, our own elements that take focus). */\nconst TABBABLE = 'a[href], button, input, select, textarea, [tabindex]:not([tabindex=\"-1\"]), ui-link, ui-button, ui-icon-button';\n\nconst closeIcon = html`<svg class=\"close-icon\" viewBox=\"0 0 20 20\" aria-hidden=\"true\"><path d=\"M15 6.4 13.6 5 10 8.6 6.4 5 5 6.4 8.6 10 5 13.6 6.4 15l3.6-3.6 3.6 3.6 1.4-1.4-3.6-3.6z\" /></svg>`;\n\n/**\n * Carbon notification in one element: `InlineNotification` (default), `ToastNotification`\n * (`variant=\"toast\"`), `ActionableNotification` (any variant with `action-label`) and `Callout`\n * (`variant=\"callout\"`: static inline box with no role, no close button and no autofocus — for\n * persistent on-page guidance; its action button is described by the title).\n *\n * Follows Carbon's SCSS: 3px status bar on the start edge, 20px status icon, high-contrast\n * (inverse) surface by default or `low-contrast` tinted surface with a 1px status border,\n * 48px close button, inline min-height 48px / toast width 288px with a drop shadow.\n * `role` defaults to `status`; with `action-label` it becomes `alertdialog`, focus moves to the\n * action button, Tab stays inside it (Carbon `wrapFocus`) and Esc closes it while focus is inside\n * (Carbon `hasFocus` / `closeOnEscape`). `full-width` lets an inline notification fill its container (no Carbon\n * counterpart: Carbon caps it at 288 / 608 / 736 / 832px by breakpoint). A toast with `timeout`\n * closes itself — the countdown pauses while it is hovered or focused, and a notification with an\n * action never closes on its own (WCAG 2.2.1).\n *\n * Closing: the close button, Esc or the timeout fire a cancelable `ui-request-close`; unless\n * prevented the element sets `open` to false (hidden, still in the DOM) and fires `ui-close`.\n *\n * @slot - Extra content after the subtitle (links, details)\n * @slot title - Title with markup; the `heading` attribute is the plain-text fallback\n * @slot subtitle - Subtitle with markup; the `subtitle` attribute is the plain-text fallback\n * @fires ui-request-close - Cancelable; detail: { reason: 'close-button' | 'escape' | 'timeout' }\n * @fires ui-close - After it closed\n * @fires ui-action - The action button was pressed\n * @csspart base - The notification box\n * @csspart icon - The status icon\n * @csspart title - The title\n * @csspart subtitle - The subtitle\n * @csspart caption - The toast caption\n * @csspart action-button - The action button\n * @csspart close-button - The close button\n * @cssprop --ui-notification-radius - Corner radius (default 0; Kanok: 8px)\n * @cssprop --ui-notification-bar-width - Width of the status bar at the start (default 3px; Kanok: 0, the icon tells the kind)\n * @cssprop --ui-notification-frame-start - Low contrast: the frame's start side (default 0, the bar is there; Kanok: 1px)\n * @cssprop --ui-notification-background / --ui-notification-ink / --ui-notification-edge - The high-contrast box: fill, text and an extra `box-shadow` (default Carbon's inverse block, none; Kanok: the raised floating surface)\n * @cssprop --ui-notification-link / --ui-notification-hover / --ui-notification-focus - On that box: links and the action, the action's hover and the focus ring (default link-inverse, inverse hover, inverse ink)\n * @cssprop --ui-toast-shadow - A toast's shadow (default `0 2px 6px 0 rgb(0 0 0 / 0.2)`)\n * @cssprop --ui-close-size - Size of the × button (default 48px; Kanok: 32px)\n * @cssprop --ui-close-inset - Margin that sets the × in from the corner (default 0; Kanok: 8px)\n * @cssprop --ui-icon-control-radius - Corners of the ×, its hover fill and its ring (default 0; Kanok: round)\n * @cssprop --ui-focus-offset - `outline-offset` of the ×'s focus ring (default -2px: inside; Kanok: 2px outside)\n */\n@customElement('ui-notification')\nexport class UiNotification extends UiElement {\n    static override readonly styles = notificationStyles;\n\n    /** Inline (default) or toast. */\n    @property({ reflect: true }) variant: NotificationVariant = 'inline';\n\n    private readonly localize = new LocalizeController(this);\n    /** Status kind; sets the colour and the icon. */\n    @property({ reflect: true }) kind: NotificationKind = 'error';\n    /** Tinted surface with primary text instead of the inverse surface. */\n    @property({ type: Boolean, reflect: true, attribute: 'low-contrast' }) lowContrast = false;\n    /** Bold title; the `title` slot replaces it when markup is needed. (Before 0.5: the `title` attribute, still accepted.) */\n    @property() heading = '';\n\n    /** @deprecated Use `heading` (a `title` attribute also shows the browser's tooltip). */\n    get titleText() {\n        return this.heading;\n    }\n\n    set titleText(value: string) {\n        this.heading = value;\n    }\n\n    static override get observedAttributes() {\n        return [...super.observedAttributes, 'title', 'role'];\n    }\n\n    override attributeChangedCallback(name: string, old: string | null, value: string | null) {\n        if (moveTitleToHeading(this, name, value)) return;\n        // `role` configures the inner box; left on the host it would make a second, nested live region\n        if (name === 'role') {\n            if (value !== null) {\n                this.role = value as NotificationRole;\n                this.removeAttribute('role');\n            }\n            return;\n        }\n        super.attributeChangedCallback(name, old, value);\n    }\n    /** Body text; the `subtitle` slot replaces it when markup is needed. */\n    @property() subtitle = '';\n    /** Toast only: small text under the subtitle, e.g. the time. */\n    @property() caption = '';\n    /** Label of the action button; set it to get Carbon's actionable notification. */\n    @property({ attribute: 'action-label' }) actionLabel = '';\n    /** ARIA role of the notification box; defaults to `status`, or `alertdialog` when there is an action button. A `role` attribute is read and moved inside. */\n    @property({ attribute: false }) role: NotificationRole | null = null;\n    /** Milliseconds after which the notification closes itself (toast); 0 = never. Paused on hover / focus; ignored with `action-label`. */\n    @property({ type: Number }) timeout = 0;\n    @property({ type: Boolean, attribute: 'hide-close-button' }) hideCloseButton = false;\n    /** Esc closes an actionable notification while focus is inside it (Carbon `closeOnEscape`). */\n    @property({ attribute: 'close-on-escape', converter: defaultTrue }) closeOnEscape = true;\n    /** Keep focus where it is instead of moving it to the action button (Carbon `hasFocus={false}`). */\n    @property({ type: Boolean, attribute: 'no-autofocus' }) noAutofocus = false;\n    /** Fills its container instead of Carbon's 288–832px cap (inline / callout; a toast stays 288px). */\n    @property({ type: Boolean, reflect: true, attribute: 'full-width' }) fullWidth = false;\n    /** Accessible name of the close button. */\n    @property({ attribute: 'close-label' }) closeLabel = '';\n    /** Accessible description of the status icon; defaults to \"`kind` icon\" (e.g. \"error icon\") like Carbon. */\n    @property({ attribute: 'icon-label' }) iconLabel = '';\n    /** False once closed (reflects `open=\"false\"`); set back to true to show it again. */\n    @property({ reflect: true, converter: defaultTrue }) open = true;\n\n    @query('.action') private readonly actionButton?: HTMLButtonElement;\n\n    private readonly ids = uid('ui-notification');\n    private readonly slots = new SlotController(this);\n    private timer?: ReturnType<typeof setTimeout>;\n\n    override connectedCallback() {\n        super.connectedCallback();\n        this.addEventListener('pointerenter', this.onPointerEnter);\n        this.addEventListener('pointerleave', this.onPointerLeave);\n        this.addEventListener('focusin', this.onFocusIn);\n        this.addEventListener('focusout', this.onFocusOut);\n        this.addEventListener('keydown', this.onTabKey);\n        this.startTimer();\n    }\n\n    override disconnectedCallback() {\n        super.disconnectedCallback();\n        clearTimeout(this.timer);\n        this.removeEventListener('pointerenter', this.onPointerEnter);\n        this.removeEventListener('pointerleave', this.onPointerLeave);\n        this.removeEventListener('focusin', this.onFocusIn);\n        this.removeEventListener('focusout', this.onFocusOut);\n        this.removeEventListener('keydown', this.onTabKey);\n        document.removeEventListener('keydown', this.onKeydown, true);\n    }\n\n    protected override firstUpdated() {\n        // Carbon: an alertdialog notification takes focus on its action button\n        if (this.effectiveRole === 'alertdialog' && !this.noAutofocus) {\n            this.returnFocus = deepActiveElement();\n            this.actionButton?.focus();\n        }\n    }\n\n    protected override updated(changed: Map<string, unknown>) {\n        const actionable = this.effectiveRole === 'alertdialog' && this.open;\n        if (actionable && this.closeOnEscape) document.addEventListener('keydown', this.onKeydown, true);\n        else document.removeEventListener('keydown', this.onKeydown, true);\n        if (changed.has('open') && this.open && changed.get('open') === false) this.startTimer();\n    }\n\n    /** core/notification: the asked role, none for a callout (static content), alertdialog with an action, status otherwise. */\n    private get effectiveRole(): NotificationRole | undefined {\n        return notificationRole(this.role, this.variant, !!this.actionLabel);\n    }\n\n    /** Time left before `timeout` closes the toast; paused while it is hovered or holds focus (WCAG 2.2.1). */\n    private countdown = new Countdown(0);\n    private hovered = false;\n    private focusWithin = false;\n\n    private startTimer() {\n        clearTimeout(this.timer);\n        this.countdown = new Countdown(this.timeout);\n        this.resumeTimer();\n    }\n\n    private resumeTimer() {\n        clearTimeout(this.timer);\n        // a notification with an action never closes on its own: the user may need longer than any timeout\n        const wait = this.countdown.resume(Date.now(), !this.open || !!this.actionLabel || this.hovered || this.focusWithin);\n        if (wait !== undefined) this.timer = setTimeout(() => this.close('timeout'), wait);\n    }\n\n    private pauseTimer() {\n        if (this.timer === undefined) return;\n        clearTimeout(this.timer);\n        this.timer = undefined;\n        this.countdown.pause(Date.now());\n    }\n\n    private readonly onPointerEnter = () => {\n        this.hovered = true;\n        this.pauseTimer();\n    };\n\n    private readonly onPointerLeave = () => {\n        this.hovered = false;\n        this.resumeTimer();\n    };\n\n    /** Where focus came from; closing while focus is inside sends it back there instead of to `<body>`. */\n    private returnFocus: HTMLElement | null = null;\n\n    private readonly onFocusIn = (event: FocusEvent) => {\n        const from = event.relatedTarget as HTMLElement | null;\n        if (!this.focusWithin && from && !this.contains(from) && !this.shadowRoot?.contains(from)) this.returnFocus = from;\n        this.focusWithin = true;\n        this.pauseTimer();\n    };\n\n    private readonly onFocusOut = (event: FocusEvent) => {\n        if (this.contains(event.relatedTarget as Node | null) || this.shadowRoot?.contains(event.relatedTarget as Node | null)) return;\n        this.focusWithin = false;\n        this.resumeTimer();\n    };\n\n    /** Carbon `useEscapeToClose`: Esc closes it only while focus is inside it, so it never takes an Esc meant for another notification or a modal. */\n    private readonly onKeydown = (event: KeyboardEvent) => {\n        if (event.key !== 'Escape' || event.defaultPrevented || !this.holdsFocus()) return;\n        // taken: a modal or side panel around it stays open (core/overlay.ts)\n        event.preventDefault();\n        this.close('escape');\n    };\n\n    private holdsFocus() {\n        const active = deepActiveElement();\n        return !!active && (this.contains(active) || !!this.shadowRoot?.contains(active));\n    }\n\n    /** The Tab stops in order: links / controls in the content, then the action and close buttons. */\n    private get tabStops(): HTMLElement[] {\n        const own = [...this.querySelectorAll<HTMLElement>(TABBABLE)].filter((el) => !(el as HTMLElement & { disabled?: boolean }).disabled && el.getClientRects().length > 0);\n        const buttons = [...(this.shadowRoot?.querySelectorAll<HTMLElement>('.action, .close') ?? [])];\n        return [...own, ...buttons];\n    }\n\n    /** Carbon `wrapFocus`: in an alertdialog notification Tab and Shift+Tab go round its stops. */\n    private readonly onTabKey = (event: KeyboardEvent) => {\n        if (event.key !== 'Tab' || !this.open || this.effectiveRole !== 'alertdialog') return;\n        const stops = this.tabStops;\n        const path = event.composedPath();\n        const next = wrapTab(stops, stops.find((stop) => path.includes(stop)), event.shiftKey);\n        if (!next) return;\n        event.preventDefault();\n        next.focus();\n    };\n\n    /** Asks to close (`ui-request-close`, cancelable); hides and fires `ui-close` unless prevented. */\n    close(reason: NotificationCloseReason = 'close-button') {\n        if (!this.open) return;\n        const request = new CustomEvent('ui-request-close', { detail: { reason }, bubbles: true, composed: true, cancelable: true });\n        if (!this.dispatchEvent(request)) return;\n        clearTimeout(this.timer);\n        const hadFocus = this.holdsFocus();\n        this.open = false;\n        if (hadFocus && this.returnFocus?.isConnected) this.returnFocus.focus();\n        this.returnFocus = null;\n        this.dispatchEvent(new CustomEvent('ui-close', { detail: { reason }, bubbles: true, composed: true }));\n    }\n\n    private onAction() {\n        this.dispatchEvent(new CustomEvent('ui-action', { bubbles: true, composed: true }));\n    }\n\n    private renderAction() {\n        if (!this.actionLabel) return nothing;\n        const describedBy = this.variant === 'callout' && (this.heading || this.slots.has('title')) ? `${this.ids}-title` : undefined;\n        return html`<button class=\"action\" part=\"action-button\" type=\"button\" tabindex=\"0\" aria-describedby=${ifDefined(describedBy)} @click=${this.onAction}>${this.actionLabel}</button>`;\n    }\n\n    private renderClose() {\n        if (this.hideCloseButton || this.variant === 'callout') return nothing;\n        return html`<button class=\"close\" part=\"close-button\" type=\"button\" aria-label=${this.closeLabel || this.localize.t.common.closeNotification} title=${this.closeLabel || this.localize.t.common.closeNotification} @click=${() => this.close('close-button')}>\n            ${closeIcon}\n        </button>`;\n    }\n\n    /** Focus the action button, else the close button. */\n    override focus(options?: FocusOptions) {\n        (this.actionButton ?? this.shadowRoot?.querySelector<HTMLElement>('.close'))?.focus(options);\n    }\n\n    override render() {\n        const role = this.effectiveRole;\n        const hasTitle = this.heading || this.slots.has('title');\n        const hasSubtitle = this.subtitle || this.slots.has('subtitle');\n        return html`\n            <div\n                class=\"box\"\n                part=\"base\"\n                role=${ifDefined(role)}\n                aria-labelledby=${role === 'alertdialog' && hasTitle ? `${this.ids}-title` : nothing}\n                aria-describedby=${role === 'alertdialog' && hasSubtitle ? `${this.ids}-subtitle` : nothing}\n            >\n                <div class=\"details\">\n                    <svg class=\"icon\" part=\"icon\" viewBox=\"0 0 20 20\" role=\"img\" aria-label=${this.iconLabel || `${this.kind} icon`}>\n                        ${ICONS[this.kind]}\n                    </svg>\n                    <div class=\"text\">\n                        ${hasTitle ? html`<span class=\"title\" part=\"title\" id=\"${this.ids}-title\"><slot name=\"title\">${this.heading}</slot></span>` : nothing}\n                        ${hasSubtitle ? html`<span class=\"subtitle\" part=\"subtitle\" id=\"${this.ids}-subtitle\"><slot name=\"subtitle\">${this.subtitle}</slot></span>` : nothing}\n                        <slot></slot>\n                        ${this.caption ? html`<span class=\"caption\" part=\"caption\">${this.caption}</span>` : nothing}\n                    </div>\n                </div>\n                ${this.renderAction()}\n                ${this.renderClose()}\n            </div>\n        `;\n    }\n}\n\nexport type NotificationCloseReason = 'close-button' | 'escape' | 'timeout';\n\nexport interface UiNotificationEventMap extends HTMLElementEventMap {\n    'ui-close': CustomEvent<CloseDetail<NotificationCloseReason>>;\n    'ui-action': CustomEvent<null>;\n    'ui-request-close': CustomEvent<CloseDetail<NotificationCloseReason>>;\n}\n\n/** Typed listeners for UiNotification's events (declaration merging with the class). */\nexport interface UiNotification {\n    addEventListener<K extends keyof UiNotificationEventMap>(type: K, listener: (this: UiNotification, event: UiNotificationEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;\n    addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;\n    removeEventListener<K extends keyof UiNotificationEventMap>(type: K, listener: (this: UiNotification, event: UiNotificationEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;\n    removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-notification': UiNotification;\n    }\n}\n"
    }
  ]
}
