{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tearsheet",
  "type": "registry:ui",
  "title": "<ui-tearsheet>",
  "description": "Carbon for IBM Products `Tearsheet` (`c4p-tearsheet`): a large modal that rises from the bottom of the screen (240ms) over the dimmed page — `width=\"narrow\"` (Carbon's small modal: 60% / 42% / 36% of the screen from md / lg / xlg, 130px from the top) or `wide` (all but 64px each side, 90px from the top). Header: `label`, `heading` (heading-04 wide, heading-03 narrow), `description` (or `slot=\"description\"`), and in a wide one `slot=\"header-actions\"` and `slot=\"header-navigation\"` (tabs); a wide one may have an `slot=\"influencer\"` pane (`influencer-placement` left / right, `influencer-width` narrow 256px / wide 320px). Content on the background (wide, layer 0) or the layer (narrow, layer 1). `slot=\"actions\"`: up to four `<ui-button>`s laid out as Carbon's ActionSet (64px; 80px wide). The × shows with `has-close-icon` or when there are no actions. Esc, × and a click outside (unless `prevent-close-on-click-outside`) ask to close; Tab stays inside. Opening another tearsheet over it scales this one back (95%, then 90%) and dims the page less, up to three deep. 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-modal",
    "@kanok-ui/core-motion",
    "@kanok-ui/core-overlay",
    "@kanok-ui/layer",
    "@kanok-ui/shared-action-set",
    "@kanok-ui/shared-element",
    "@kanok-ui/shared-events",
    "@kanok-ui/shared-focus-ring",
    "@kanok-ui/shared-localize",
    "@kanok-ui/shared-quiet-focus",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/tearsheet/tearsheet.styles.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/tearsheet/tearsheet.styles.ts",
      "content": "import { css } from 'lit';\nimport { focusRing } from '../shared/focus-ring.ts';\n\n/** Styles of `<ui-tearsheet>`. */\nexport const tearsheetStyles = css`\n    dialog {\n        box-sizing: border-box;\n        inline-size: 100%;\n        block-size: 100%;\n        max-inline-size: none;\n        max-block-size: none;\n        margin: 0;\n        padding: 0;\n        border: none;\n        background: transparent;\n        color: var(--ui-ink);\n        font-family: var(--ui-font-family);\n    }\n\n    dialog[open] {\n        display: flex;\n        flex-direction: column;\n        align-items: center;\n        justify-content: flex-end;\n    }\n\n    dialog::backdrop {\n        background-color: var(--ui-overlay);\n    }\n\n    :host([data-stack='1-of-2']) dialog::backdrop {\n        opacity: 0.67;\n    }\n\n    :host([data-stack='1-of-3']) dialog::backdrop {\n        opacity: 0.22;\n    }\n\n    :host([data-stack='2-of-2']) dialog::backdrop,\n    :host([data-stack='2-of-3']) dialog::backdrop,\n    :host([data-stack='3-of-3']) dialog::backdrop {\n        opacity: 0.5;\n    }\n\n    .container {\n        --_top: 90px;\n        --_actions-height: 64px;\n        /* the sheet's surface; a design can raise it (--ui-overlay-background; Carbon: layer 1) */\n        --_surface: var(--ui-overlay-background, var(--ui-layer-1));\n\n        position: relative;\n        display: flex;\n        flex-direction: column;\n        box-sizing: border-box;\n        inline-size: 100%;\n        block-size: 100%;\n        max-block-size: calc(100% - var(--_top) + var(--_stack-room, 0px));\n        border: var(--ui-overlay-border, 1px solid var(--ui-border-subtle-2));\n        /* the top corners can round (--ui-tearsheet-radius; Carbon: square); the actions row follows */\n        border-start-start-radius: var(--ui-tearsheet-radius, 0);\n        border-start-end-radius: var(--ui-tearsheet-radius, 0);\n        background-color: var(--_surface);\n        outline: none;\n    }\n\n    :host([vertical-position='lower']) .container,\n    :host([data-lower]:not([vertical-position])) .container {\n        --_top: 130px;\n    }\n\n    :host([width='wide']) .container {\n        --_actions-height: 80px;\n    }\n\n    @media (prefers-reduced-motion: no-preference) {\n        .container {\n            transition:\n                transform var(--ui-duration-moderate-02) cubic-bezier(0, 0, 0.3, 1),\n                max-height var(--ui-duration-moderate-02) cubic-bezier(0, 0, 0.3, 1);\n        }\n    }\n\n    /* an older tearsheet under newer ones: scaled back, a little taller */\n    :host([data-stack='1-of-2']) .container,\n    :host([data-stack='2-of-3']) .container {\n        --_stack-room: 16px;\n\n        transform: scale(0.95);\n    }\n\n    :host([data-stack='1-of-3']) .container {\n        --_stack-room: 32px;\n\n        transform: scale(0.9);\n    }\n\n    /* Carbon's small modal widths */\n    @media (min-width: 42rem) {\n        :host([width='wide']) .container {\n            inline-size: calc(100% - 128px);\n        }\n\n        :host(:not([width='wide'])) .container {\n            inline-size: 60%;\n        }\n    }\n\n    @media (min-width: 66rem) {\n        :host(:not([width='wide'])) .container {\n            inline-size: 42%;\n        }\n    }\n\n    @media (min-width: 82rem) {\n        :host(:not([width='wide'])) .container {\n            inline-size: 36%;\n        }\n    }\n\n    @media (max-width: 41.98rem) {\n        .container {\n            max-block-size: 100%;\n        }\n    }\n\n    .header {\n        position: relative;\n        flex: none;\n        padding: var(--ui-space-md);\n        background-color: var(--_surface);\n        border-block-end: 1px solid var(--ui-border-subtle-2);\n    }\n\n    :host([width='wide']) .header {\n        padding: var(--ui-space-lg) var(--ui-space-xl);\n    }\n\n    :host([width='wide']) .header.has-close {\n        padding-inline-end: 80px;\n    }\n\n    :host([width='wide']) .header.has-navigation {\n        padding-block-end: 0;\n    }\n\n    .label {\n        margin: 0 0 var(--ui-space-xxs);\n        color: var(--ui-ink-muted);\n        font: var(--ui-font-caption);\n        letter-spacing: var(--ui-tracking-caption);\n    }\n\n    h2 {\n        margin: 0;\n        padding-inline-end: calc(20% - 3rem);\n        font: var(--ui-font-heading-03);\n    }\n\n    :host([width='wide']) h2 {\n        font: var(--ui-font-heading-04);\n    }\n\n    .description {\n        display: inline-flex;\n        max-inline-size: 80%;\n        margin-block-start: var(--ui-space-xs);\n        font: var(--ui-font-body-sm);\n        letter-spacing: var(--ui-tracking-body);\n    }\n\n    :host([width='wide']) .description {\n        max-inline-size: 100%;\n        margin-block-start: var(--ui-space-md);\n    }\n\n    @media (min-width: 42rem) {\n        :host([width='wide']) .description {\n            max-inline-size: 60%;\n        }\n    }\n\n    .header-actions {\n        position: absolute;\n        z-index: 1;\n        inset-block-start: var(--ui-space-md);\n        inset-inline-end: 160px;\n        display: flex;\n        gap: var(--ui-space-xs);\n    }\n\n    .navigation {\n        margin-block-start: var(--ui-space-sm);\n    }\n\n    [hidden] {\n        display: none !important;\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        z-index: 1;\n        inset-block-start: var(--ui-space-xs);\n        inset-inline-end: var(--ui-space-md);\n        display: grid;\n        place-items: center;\n        inline-size: var(--ui-close-size, 48px);\n        block-size: 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: var(--ui-ink);\n        cursor: pointer;\n    }\n\n    .close:hover {\n        background-color: var(--ui-ghost-hover);\n    }\n\n    .close:focus-visible {\n        ${focusRing}\n    }\n\n    /* focused on opening right after a click (shared/quiet-focus): no keyboard ring in Kanok */\n    .close[data-quiet-focus]:focus-visible {\n        outline-color: var(--ui-pointer-focus, var(--ui-focus));\n    }\n\n    .close svg {\n        inline-size: 20px;\n        block-size: 20px;\n        fill: currentColor;\n    }\n\n    .body {\n        display: flex;\n        flex: 1;\n        min-block-size: 0;\n        overflow: hidden;\n    }\n\n    .influencer {\n        flex: 0 0 257px;\n        box-sizing: border-box;\n        overflow-y: auto;\n        border-inline-end: 1px solid var(--ui-border-subtle-2);\n    }\n\n    .influencer.wide {\n        flex-basis: 321px;\n    }\n\n    .main .influencer {\n        background-color: var(--_surface);\n        border-inline-end: none;\n        border-inline-start: 1px solid var(--ui-border-subtle-2);\n    }\n\n    @media (max-width: 41.98rem) {\n        .influencer {\n            flex-basis: auto;\n        }\n    }\n\n    .right {\n        display: grid;\n        flex-grow: 1;\n        grid-template-columns: 100%;\n        grid-template-rows: 1fr auto;\n        min-inline-size: 0;\n    }\n\n    .main {\n        display: flex;\n        min-block-size: 0;\n        min-inline-size: 0;\n        background-color: var(--_surface);\n    }\n\n    :host([width='wide']) .main {\n        background-color: var(--ui-canvas);\n    }\n\n    .content {\n        flex-grow: 1;\n        min-inline-size: 0;\n        overflow: auto;\n    }\n\n    .button-row {\n        min-block-size: fit-content;\n        overflow-x: auto;\n    }\n\n    .actions {\n        box-sizing: border-box; /* the actions padding (--ui-actions-padding) stays inside the full width */\n        min-inline-size: 100%;\n        background-color: var(--_surface);\n        border-block-start: 1px solid var(--ui-border-subtle-2);\n    }\n\n    :host([width='wide']) .actions {\n        background-color: var(--ui-canvas);\n    }\n\n    .actions ::slotted(*) {\n        --ui-field-height-lg: var(--_actions-height);\n    }\n\n    @media (forced-colors: active) {\n        .container {\n            border-color: CanvasText;\n        }\n    }\n`;\n"
    },
    {
      "path": "src/primitives/tearsheet/tearsheet.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/tearsheet/tearsheet.ts",
      "content": "import { html, nothing, type PropertyValues } from 'lit';\nimport { customElement, property, query, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { FOCUSABLE, isOutside } from '../../core/modal.ts';\nimport { closeOverlay, isTopOverlay, lockScroll, openOverlay, unlockScroll, type OverlayLayer } from '../../core/overlay.ts';\nimport { cssDuration } from '../../core/motion.ts';\nimport { actionSetStyles, layoutActions, slottedActions, warnActionProblems } from '../shared/action-set.ts';\nimport { focusQuietly } from '../shared/quiet-focus.ts';\nimport { LocalizeController } from '../shared/localize.ts';\nimport { UiElement } from '../shared/element.ts';\nimport type { CloseDetail } from '../shared/events.ts';\nimport '../layer/layer.ts';\nimport { tearsheetStyles } from './tearsheet.styles.ts';\n\nexport type TearsheetCloseReason = 'escape' | 'close-button' | 'outside';\n\nconst MAX_ACTIONS = 4;\nconst MAX_STACK = 3;\n\n/** Open tearsheets, oldest first: each knows its place to scale back and dim less under the newer ones (Carbon). */\nconst stack: UiTearsheet[] = [];\n\nfunction restack() {\n    const depth = Math.min(stack.length, MAX_STACK);\n    stack.forEach((sheet, index) => { sheet.placeInStack(index + 1, depth); });\n}\n\n/** Tab stops inside `root` in composed order (native controls, hosts that delegate focus), through slots. */\nfunction tabStops(root: Element, out: HTMLElement[] = []): HTMLElement[] {\n    const children = root instanceof HTMLSlotElement ? root.assignedElements({ flatten: true }) : [...root.children];\n    for (const child of children) {\n        if (!(child instanceof HTMLElement) || child.hidden || child.inert) continue;\n        if (child.matches(FOCUSABLE) && !child.matches('[tabindex=\"-1\"]')) out.push(child);\n        else if (child.shadowRoot?.delegatesFocus && !child.hasAttribute('disabled')) out.push(child);\n        else if (child.shadowRoot) tabStops(child.shadowRoot as unknown as Element, out);\n        else tabStops(child, out);\n    }\n    return out;\n}\n\nconst closeIcon = html`<svg viewBox=\"0 0 32 32\" aria-hidden=\"true\"><path d=\"M24 9.4 22.6 8 16 14.6 9.4 8 8 9.4l6.6 6.6L8 22.6 9.4 24l6.6-6.6 6.6 6.6 1.4-1.4-6.6-6.6z\" /></svg>`;\n\n/**\n * Carbon for IBM Products `Tearsheet` (`c4p-tearsheet`): a large modal that rises from the bottom of the screen\n * (240ms) over the dimmed page — `width=\"narrow\"` (Carbon's small modal: 60% / 42% / 36% of the screen from md /\n * lg / xlg, 130px from the top) or `wide` (all but 64px each side, 90px from the top). Header: `label`, `heading`\n * (heading-04 wide, heading-03 narrow), `description` (or `slot=\"description\"`), and in a wide one\n * `slot=\"header-actions\"` and `slot=\"header-navigation\"` (tabs); a wide one may have an `slot=\"influencer\"` pane\n * (`influencer-placement` left / right, `influencer-width` narrow 256px / wide 320px). Content on the background\n * (wide, layer 0) or the layer (narrow, layer 1). `slot=\"actions\"`: up to four `<ui-button>`s laid out as Carbon's\n * ActionSet (64px; 80px wide). The × shows with `has-close-icon` or when there are no actions. Esc, × and a click\n * outside (unless `prevent-close-on-click-outside`) ask to close; Tab stays inside. Opening another tearsheet over it\n * scales this one back (95%, then 90%) and dims the page less, up to three deep.\n *\n * @fires ui-request-close - Cancelable; detail: { reason: 'escape' | 'close-button' | 'outside' }\n * @fires ui-close - After it closed\n * @slot - The content\n * @slot label - Rich label (instead of `label`)\n * @slot description - Rich description (instead of `description`), e.g. a `<ui-truncated-text>`\n * @slot header-actions - Small buttons in the header (wide)\n * @slot header-navigation - Tabs under the header text (wide)\n * @slot influencer - A side pane beside the content (wide)\n * @slot actions - Up to four action buttons\n * @csspart dialog - The full-screen dialog\n * @csspart container - The sheet\n * @csspart header - The header\n * @csspart heading - The heading\n * @csspart close-button - The ×\n * @csspart influencer - The side pane\n * @csspart content - The content's box\n * @csspart actions - The row of action buttons\n * @cssprop --ui-tearsheet-radius - Corner radius of the top corners (default 0; Kanok: 12px)\n * @cssprop --ui-actions-gap / --ui-actions-padding - Gap between the action buttons and padding round them (default none: full-bleed buttons that touch; Kanok: 8px / 16px 20px)\n * @cssprop --ui-actions-button-flex - `flex` of each action button (default: Carbon's widths by count; Kanok: their own width)\n * @cssprop --ui-actions-button-align / --ui-actions-button-padding-top - Where a button's label sits (default: at the top, 16px in)\n * @cssprop --ui-actions-stacked-direction / --ui-actions-stacked-wrap / --ui-actions-stacked-width - Where Carbon stacks the actions (narrow): `flex-direction`, `flex-wrap` and each button's width (default column-reverse, nowrap, 100%; Kanok: one row that wraps)\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-tearsheet')\nexport class UiTearsheet extends UiElement {\n    static override readonly styles = [\n        actionSetStyles('.actions'),\n        tearsheetStyles,\n    ];\n\n    @property({ type: Boolean, reflect: true }) open = false;\n\n    /** narrow: Carbon's small modal; wide: the whole screen but 64px each side. */\n    @property({ reflect: true }) width: 'narrow' | 'wide' = 'narrow';\n\n    /** How far from the top the sheet starts: normal 90px, lower 130px (default lower for a narrow one). */\n    @property({ reflect: true, attribute: 'vertical-position' }) verticalPosition?: 'normal' | 'lower';\n\n    @property() heading = '';\n\n    /** A small label above the heading. */\n    @property() label = '';\n\n    @property() description = '';\n\n    @property({ attribute: 'influencer-placement' }) influencerPlacement: 'left' | 'right' = 'right';\n\n    @property({ attribute: 'influencer-width' }) influencerWidth: 'narrow' | 'wide' = 'narrow';\n\n    /** Show the × even with actions (it always shows without them). */\n    @property({ type: Boolean, attribute: 'has-close-icon' }) hasCloseIcon = false;\n\n    /** The ×'s name (default \"Close\", translated). */\n    @property({ attribute: 'close-icon-description' }) closeIconDescription = '';\n\n    @property({ type: Boolean, attribute: 'prevent-close-on-click-outside' }) preventCloseOnClickOutside = false;\n\n    /** What takes focus on open (a selector in the content), else × or the first control. */\n    @property({ attribute: 'selector-initial-focus' }) selectorInitialFocus = '';\n\n    @state() private slotted = new Set<string>();\n    @state() private actionCount = 0;\n\n    @query('dialog') private readonly dialog?: HTMLDialogElement;\n    @query('.container') private readonly container?: HTMLElement;\n    @query('.actions') private readonly actionsEl?: HTMLElement;\n\n    private readonly localize = new LocalizeController(this);\n    private launcher: HTMLElement | null = null;\n    private closeTimer?: ReturnType<typeof setTimeout>;\n    /** Its place on the page's overlay stack: Esc reaches it only while it is the topmost layer. */\n    private readonly layer: OverlayLayer = { escape: () => this.requestClose('escape'), modal: true };\n    private pointerDownOutside = false;\n\n    private get wide() {\n        return this.width === 'wide';\n    }\n\n    private get showsClose() {\n        return this.hasCloseIcon || this.actionCount === 0;\n    }\n\n    /** Called by the stack: this sheet's place among the open ones (position 1 = oldest) and how many show. */\n    placeInStack(position: number, depth: number) {\n        if (depth > 1 && position <= depth) this.dataset.stack = `${position}-of-${depth}`;\n        else delete this.dataset.stack;\n    }\n\n    override disconnectedCallback() {\n        super.disconnectedCallback();\n        this.leaveStack();\n        clearTimeout(this.closeTimer);\n        this.stopAnimations();\n        this.release();\n    }\n\n    protected override willUpdate(changed: PropertyValues<this>) {\n        // a narrow sheet sits lower unless vertical-position says otherwise (Carbon TearsheetNarrow)\n        if (changed.has('width')) this.toggleAttribute('data-lower', !this.wide);\n    }\n\n    protected override updated(changed: PropertyValues<this>) {\n        super.updated(changed);\n        if (changed.has('width')) this.layout();\n        if (!changed.has('open') || (changed.get('open') === undefined && !this.open)) return;\n        if (this.open) void this.opened();\n        else this.closed();\n    }\n\n    private duration() {\n        return cssDuration(getComputedStyle(this).getPropertyValue('--ui-duration-moderate-02'));\n    }\n\n    private async opened() {\n        const dialog = this.dialog;\n        if (!dialog || dialog.open) return;\n        clearTimeout(this.closeTimer);\n        this.launcher = this.deepActive();\n        dialog.showModal();\n        stack.push(this);\n        restack();\n        openOverlay(this.layer, globalThis);\n        lockScroll(this, document.documentElement);\n        this.rise(true);\n        this.layout();\n        const pending = [...this.querySelectorAll('*')].map((el) => (el as { updateComplete?: Promise<unknown> }).updateComplete).filter((p): p is Promise<unknown> => p !== undefined);\n        await Promise.all(pending);\n        if (this.open) this.focusInitial();\n    }\n\n    private closed() {\n        this.leaveStack();\n        this.release();\n        const target = this.launcher;\n        this.launcher = null;\n        if (target?.isConnected) focusQuietly(target);\n        this.closeTimer = setTimeout(() => {\n            this.dialog?.close();\n            this.dispatchEvent(new Event('ui-close', { bubbles: true, composed: true }));\n        }, this.rise(false));\n    }\n\n    private leaveStack() {\n        const index = stack.indexOf(this);\n        if (index < 0) return;\n        stack.splice(index, 1);\n        delete this.dataset.stack;\n        restack();\n    }\n\n    /** Off the overlay stack, and its hold on the page's scrolling let go (the page scrolls once the last overlay has). */\n    private release() {\n        closeOverlay(this.layer);\n        unlockScroll(this, document.documentElement);\n    }\n\n    private deepActive(): HTMLElement | null {\n        let el = document.activeElement;\n        while (el?.shadowRoot?.activeElement) el = el.shadowRoot.activeElement;\n        return el as HTMLElement | null;\n    }\n\n    /** Rises from below (240ms, entrance expressive) or sinks back (exit expressive) and fades the backdrop; returns how long. */\n    private rise(entering: boolean) {\n        const container = this.container;\n        const dialog = this.dialog;\n        const duration = this.duration();\n        // the last sink still holds the sheet down and the backdrop clear (it fills forwards): drop it first\n        this.stopAnimations();\n        // a hidden page doesn't run animations: one started there would hold the sheet down until it shows\n        if (!container || !dialog || duration <= 0 || typeof container.animate !== 'function' || document.hidden) return 0;\n        const down = 'translateY(min(95vh, 500px))';\n        const easing = entering ? 'cubic-bezier(0, 0, 0.3, 1)' : 'cubic-bezier(0.4, 0.14, 1, 1)';\n        const fill = entering ? 'none' : 'forwards';\n        this.animations = [\n            container.animate(entering ? [{ transform: down }, {}] : [{}, { transform: down }], { duration, easing, fill }),\n            dialog.animate(entering ? [{ opacity: 0 }, { opacity: 1 }] : [{ opacity: 1 }, { opacity: 0 }], { duration, easing, fill, pseudoElement: '::backdrop' }),\n        ];\n        return duration;\n    }\n\n    /**\n     * The rise / sink animations: kept, because a running animation holds its element, and the shadow root's\n     * getAnimations() lists neither the ::backdrop one nor any once the sheet is off the page.\n     */\n    private animations: Animation[] = [];\n\n    private stopAnimations() {\n        for (const a of [...this.animations, ...(this.shadowRoot?.getAnimations() ?? [])]) a.cancel();\n        this.animations = [];\n    }\n\n    private layout() {\n        const slot = this.actionsEl?.querySelector('slot');\n        if (!this.actionsEl || !slot) return;\n        const buttons = slottedActions(slot);\n        warnActionProblems(this, buttons, this.wide ? '2xl' : 'xl');\n        // Carbon allows four; any more are hidden\n        buttons.slice(MAX_ACTIONS).forEach((b) => { b.hidden = true; });\n        layoutActions(this.actionsEl, buttons.slice(0, MAX_ACTIONS), this.wide ? '2xl' : 'xl');\n    }\n\n    private focusInitial() {\n        const chosen = this.selectorInitialFocus ? this.querySelector<HTMLElement>(this.selectorInitialFocus) : null;\n        if (chosen) {\n            focusQuietly(chosen);\n            return;\n        }\n        const close = this.shadowRoot?.querySelector<HTMLElement>('.close');\n        focusQuietly(close ?? (this.container ? tabStops(this.container)[0] : undefined));\n    }\n\n    /** Asks to close (cancelable `ui-request-close`), then closes. */\n    requestClose(reason: TearsheetCloseReason) {\n        const request = new CustomEvent<CloseDetail<TearsheetCloseReason>>('ui-request-close', { detail: { reason }, bubbles: true, composed: true, cancelable: true });\n        if (this.dispatchEvent(request)) this.open = false;\n    }\n\n    /** A close request the page's Esc listener didn't take (core/overlay.ts; e.g. Android's back gesture): only for the topmost layer. */\n    private onCancel(event: Event) {\n        event.preventDefault();\n        if (isTopOverlay(this.layer)) this.requestClose('escape');\n    }\n\n    /** The dialog closed while still `open`: the browser closed it without asking (its close watcher). That's a request; vetoed, it opens again. */\n    private onClose() {\n        // taken off the page while open, the browser closes the dialog too: nothing to ask (and no exit animation to start)\n        if (!this.open || !this.isConnected) return;\n        const request = new CustomEvent<CloseDetail<TearsheetCloseReason>>('ui-request-close', { detail: { reason: 'escape' }, bubbles: true, composed: true, cancelable: true });\n        if (this.dispatchEvent(request)) this.open = false;\n        else this.dialog?.showModal();\n    }\n\n    private onPointerDown(event: PointerEvent) {\n        this.pointerDownOutside = event.target === this.dialog && !!this.container && isOutside(this.container.getBoundingClientRect(), event.clientX, event.clientY);\n    }\n\n    private onClick(event: MouseEvent) {\n        if (this.preventCloseOnClickOutside || !this.pointerDownOutside || event.target !== this.dialog) return;\n        if (this.container && isOutside(this.container.getBoundingClientRect(), event.clientX, event.clientY)) this.requestClose('outside');\n    }\n\n    /** Tab stays inside the sheet (Carbon). */\n    private onKeydown(event: KeyboardEvent) {\n        if (event.key !== 'Tab' || !this.container) return;\n        const stops = tabStops(this.container);\n        const first = stops[0];\n        const last = stops.at(-1);\n        if (!first || !last) return;\n        if (event.shiftKey && first.matches(':focus-within')) {\n            event.preventDefault();\n            last.focus();\n        } else if (!event.shiftKey && last.matches(':focus-within')) {\n            event.preventDefault();\n            first.focus();\n        }\n    }\n\n    private onSlotChange(event: Event) {\n        const slot = event.target as HTMLSlotElement;\n        const key = slot.name || 'default';\n        const next = new Set(this.slotted);\n        if (slot.assignedNodes().length > 0) next.add(key);\n        else next.delete(key);\n        this.slotted = next;\n    }\n\n    private onActionsChange(event: Event) {\n        this.actionCount = Math.min(slottedActions(event.target as HTMLSlotElement).length, MAX_ACTIONS);\n        this.layout();\n    }\n\n    private renderInfluencer(placement: 'left' | 'right') {\n        if (this.influencerPlacement !== placement) return nothing;\n        const shown = this.wide && this.slotted.has('influencer');\n        return html`<div class=${classMap({ influencer: true, wide: this.influencerWidth === 'wide' })} part=\"influencer\" ?hidden=${!shown}><slot name=\"influencer\" @slotchange=${this.onSlotChange}></slot></div>`;\n    }\n\n    private renderHeader() {\n        const has = (name: string) => this.slotted.has(name);\n        const classes = { header: true, 'has-close': this.showsClose, 'has-navigation': this.wide && has('header-navigation') };\n        const closeLabel = this.closeIconDescription || this.localize.t.common.close;\n        return html`<div class=${classMap(classes)} part=\"header\">\n            <p class=\"label\" ?hidden=${!this.label && !has('label')}><slot name=\"label\" @slotchange=${this.onSlotChange}>${this.label}</slot></p>\n            <h2 part=\"heading\" id=\"heading\" ?hidden=${!this.heading}>${this.heading}</h2>\n            <div class=\"description\" ?hidden=${!this.description && !has('description')}><slot name=\"description\" @slotchange=${this.onSlotChange}>${this.description}</slot></div>\n            <div class=\"header-actions\" ?hidden=${!this.wide || !has('header-actions')}><slot name=\"header-actions\" @slotchange=${this.onSlotChange}></slot></div>\n            <div class=\"navigation\" ?hidden=${!this.wide || !has('header-navigation')}><slot name=\"header-navigation\" @slotchange=${this.onSlotChange}></slot></div>\n            ${this.showsClose ? html`<button class=\"close\" part=\"close-button\" type=\"button\" aria-label=${closeLabel} @click=${() => this.requestClose('close-button')}>${closeIcon}</button>` : nothing}\n        </div>`;\n    }\n\n    override render() {\n        return html`<dialog\n            part=\"dialog\"\n            aria-labelledby=${this.heading ? 'heading' : nothing}\n            @cancel=${this.onCancel}\n            @close=${this.onClose}\n            @pointerdown=${this.onPointerDown}\n            @click=${this.onClick}\n            @keydown=${this.onKeydown}\n        >\n            <div class=\"container\" part=\"container\">\n                ${this.renderHeader()}\n                <div class=\"body\">\n                    ${this.renderInfluencer('left')}\n                    <div class=\"right\">\n                        <div class=\"main\">\n                            <ui-layer class=\"content\" part=\"content\" .level=${this.wide ? 0 : 1}><slot></slot></ui-layer>\n                            ${this.renderInfluencer('right')}\n                        </div>\n                        <div class=\"button-row\" ?hidden=${this.actionCount === 0}>\n                            <div class=\"actions\" part=\"actions\"><slot name=\"actions\" @slotchange=${this.onActionsChange}></slot></div>\n                        </div>\n                    </div>\n                </div>\n            </div>\n        </dialog>`;\n    }\n}\n\nexport interface UiTearsheetEventMap extends HTMLElementEventMap {\n    'ui-request-close': CustomEvent<CloseDetail<TearsheetCloseReason>>;\n    'ui-close': Event;\n}\n\nexport interface UiTearsheet {\n    addEventListener<K extends keyof UiTearsheetEventMap>(type: K, listener: (this: UiTearsheet, event: UiTearsheetEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;\n    addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;\n    removeEventListener<K extends keyof UiTearsheetEventMap>(type: K, listener: (this: UiTearsheet, event: UiTearsheetEventMap[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-tearsheet': UiTearsheet;\n    }\n}\n"
    }
  ]
}
