{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "side-panel",
  "type": "registry:ui",
  "title": "<ui-side-panel>",
  "description": "Carbon for IBM Products `SidePanel` (`c4p-side-panel`): a panel that slides in from the right (or `placement=\"left\"`) under the 48px UI shell header — `size` xs 16rem, sm 20rem, md 30rem, lg 40rem, xl 65rem, 2xl 80rem (at most 75vw from md screens). Slide-over (default) covers the page and keeps Tab inside it; `include-overlay` dims the page and a click on it closes the panel; `slide-in` instead pushes the page aside (`selector-page-content`), takes no focus and no Esc. Header: `label-text` (label-01), `heading` (heading-03), `slot=\"subtitle\"` (body-compact-01), the × button (tooltip left), `current-step` > 0 a back button, `slot=\"action-toolbar\"` small buttons under it. As the content scrolls, the label and subtitle fade and the heading shrinks to heading-compact-02 (`animate-title`, Carbon's default; off with reduced motion). `slot=\"actions\"`: up to four `<ui-button>`s, laid out as Carbon's ActionSet for the panel's size (64px; 48px `condensed-actions`). The content sits on layer 1 (fields are field-02). A slide-over panel is on the page's overlay stack: one Esc closes only the topmost layer (a modal opened from the panel closes first), and a panel opened from a modal opens over it, as a modal dialog of its own, so it can be used. 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-action-set",
    "@kanok-ui/core-modal",
    "@kanok-ui/core-motion",
    "@kanok-ui/core-overlay",
    "@kanok-ui/core-position",
    "@kanok-ui/icon-button",
    "@kanok-ui/layer",
    "@kanok-ui/shared-action-set",
    "@kanok-ui/shared-element",
    "@kanok-ui/shared-events",
    "@kanok-ui/shared-field",
    "@kanok-ui/shared-localize",
    "@kanok-ui/shared-quiet-focus",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/side-panel/side-panel.styles.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/side-panel/side-panel.styles.ts",
      "content": "import { css } from 'lit';\n\n/** Styles of `<ui-side-panel>`. */\nexport const sidePanelStyles = css`\n    :host {\n        display: contents;\n    }\n\n    .overlay {\n        position: fixed;\n        z-index: 6000;\n        inset: 0;\n        background-color: var(--ui-overlay);\n    }\n\n    .panel {\n        --_progress: 0;\n        --_title-pad-end: var(--ui-space-xl);\n        --_title-pad-bottom: var(--ui-space-md);\n        --_actions-height: 64px;\n        /* every band of the panel takes this 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: fixed;\n        z-index: 9000;\n        inset-block-start: var(--ui-side-panel-top, 3rem);\n        display: grid;\n        box-sizing: border-box;\n        block-size: calc(100% - var(--ui-side-panel-top, 3rem));\n        inline-size: clamp(16rem, var(--_size), 100%);\n        min-inline-size: 16rem;\n        max-inline-size: 100%;\n        grid-template-rows: auto 1fr auto;\n        background-color: var(--_surface);\n        color: var(--ui-ink);\n        box-shadow: 0 2px 4px var(--ui-overlay);\n        /* a containing block for the fixed back and close buttons */\n        transform: translateX(0);\n    }\n\n    .panel *,\n    .panel *::before {\n        box-sizing: border-box;\n    }\n\n    @media (min-width: 42rem) {\n        .panel {\n            max-inline-size: 75vw;\n        }\n    }\n\n    /* the edge that faces the page can round (--ui-side-panel-radius; Carbon: square) */\n    .panel[data-placement='right'] {\n        inset-inline-end: 0;\n        border-inline-start: var(--ui-overlay-border, 1px solid var(--ui-border-subtle-2));\n        border-start-start-radius: var(--ui-side-panel-radius, 0);\n        border-end-start-radius: var(--ui-side-panel-radius, 0);\n    }\n\n    .panel[data-placement='left'] {\n        inset-inline-start: 0;\n        border-inline-end: var(--ui-overlay-border, 1px solid var(--ui-border-subtle-2));\n        border-start-end-radius: var(--ui-side-panel-radius, 0);\n        border-end-end-radius: var(--ui-side-panel-radius, 0);\n    }\n\n    .panel.slide-in {\n        box-shadow: none;\n    }\n\n    .panel.animated {\n        grid-template-rows: 1fr auto;\n    }\n\n    .panel.toolbar {\n        --_title-pad-end: 64px;\n    }\n\n    .panel.condensed {\n        --_actions-height: 48px;\n    }\n\n    /* animated title: header and content scroll together; static: the content scrolls under the header */\n    .scroller {\n        display: contents;\n    }\n\n    .animated .scroller,\n    .body.scrolls {\n        overflow: hidden auto;\n    }\n\n    .animated .scroller {\n        display: grid;\n        grid-template-rows: auto 1fr;\n    }\n\n    .header {\n        position: relative;\n        z-index: 4;\n        min-block-size: 40px;\n        padding: var(--ui-space-md) var(--ui-space-md) 0;\n        background-color: var(--_surface);\n    }\n\n    .header.has-heading {\n        min-block-size: auto;\n    }\n\n    .header.has-subtitle {\n        --_title-pad-bottom: var(--ui-space-xs);\n    }\n\n    .header.has-back {\n        padding-block-start: var(--ui-space-xl);\n    }\n\n    .header.has-back.md-buttons {\n        padding-block-start: 40px;\n    }\n\n    /* the line under the header: there from the start when static, faded in by the scroll when animated */\n    .header::before {\n        position: absolute;\n        z-index: 9;\n        inset-block-end: 0;\n        inset-inline-start: 0;\n        inline-size: 100%;\n        block-size: 1px;\n        background-color: var(--ui-border-subtle-2);\n        content: '';\n        opacity: 1;\n    }\n\n    .header:not(.has-heading)::before,\n    .header.has-toolbar::before {\n        content: none;\n    }\n\n    .animated .header {\n        position: sticky;\n        inset-block-start: calc(-1px * var(--_distance, 0));\n    }\n\n    .animated .header::before {\n        opacity: var(--_progress);\n    }\n\n    .header.has-toolbar {\n        margin-block-end: var(--ui-space-xs);\n    }\n\n    .label {\n        margin: 0;\n        padding-inline-end: var(--_title-pad-end);\n        font: var(--ui-font-caption);\n        letter-spacing: var(--ui-tracking-caption);\n        opacity: calc(1 - var(--_progress));\n    }\n\n    .title {\n        position: relative;\n        z-index: 4;\n        background-color: var(--_surface);\n        border-block-end: var(--_title-pad-bottom) solid transparent;\n    }\n\n    .animated .title {\n        position: sticky;\n        inset-block-start: var(--ui-space-md);\n    }\n\n    h2 {\n        margin: 0;\n        padding-inline-end: var(--_title-pad-end);\n        font: var(--ui-font-heading-03);\n    }\n\n    .title-text {\n        opacity: calc(1 - var(--_progress));\n    }\n\n    .collapsed {\n        position: absolute;\n        inset-block-start: 0;\n        font: var(--ui-font-heading-compact-02);\n        opacity: var(--_progress);\n    }\n\n    .no-label .title-text {\n        transform: translateY(calc(-1 * var(--ui-space-md) * var(--_progress)));\n    }\n\n    .no-label .collapsed {\n        transform: translateY(calc(var(--ui-space-md) * (1 - var(--_progress))));\n    }\n\n    .subtitle {\n        margin: 0;\n        padding-block-end: var(--ui-space-md);\n        padding-inline-end: var(--_title-pad-end);\n        font: var(--ui-font-body-sm);\n        letter-spacing: var(--ui-tracking-body);\n        opacity: calc(1 - var(--_progress));\n    }\n\n    .subtitle[hidden],\n    .toolbar-row[hidden] {\n        display: none;\n    }\n\n    .toolbar-row {\n        position: sticky;\n        z-index: 4;\n        display: flex;\n        align-items: center;\n        background-color: var(--_surface);\n    }\n\n    .toolbar-row ::slotted(:first-child) {\n        margin-inline-end: var(--ui-space-xs);\n    }\n\n    .close-area {\n        position: fixed;\n        z-index: 10;\n        inset-block-start: 0;\n        inset-inline-end: 0;\n        display: flex;\n    }\n\n    .back {\n        position: fixed;\n        z-index: 5;\n        inset-block-start: 0;\n        inset-inline-start: 0;\n    }\n\n    .body {\n        min-block-size: 0;\n        padding: 0 var(--ui-space-md) var(--ui-space-md);\n    }\n\n    .header.has-toolbar + .body {\n        padding-block-start: var(--ui-space-xs);\n    }\n\n    .actions {\n        position: sticky;\n        inset-block-end: 0;\n        inline-size: 100%;\n        background-color: var(--_surface);\n        border-block-start: 1px solid var(--ui-border-subtle-2);\n    }\n\n    .actions ::slotted(*) {\n        --ui-field-height-lg: var(--_actions-height);\n    }\n\n    .actions[hidden] {\n        display: none;\n    }\n\n    /* opened over a modal: a modal dialog of its own (the top layer) that draws nothing itself; the panel keeps its place */\n    dialog.layer {\n        position: fixed;\n        inset: 0;\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        overflow: visible;\n    }\n\n    dialog.layer::backdrop {\n        background: transparent;\n    }\n\n    @media (forced-colors: active) {\n        .panel {\n            border: 1px solid CanvasText;\n        }\n    }\n`;\n"
    },
    {
      "path": "src/primitives/side-panel/side-panel.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/side-panel/side-panel.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 type { Placement } from '../../core/position.ts';\nimport { FOCUSABLE } from '../../core/modal.ts';\nimport { closeOverlay, isTopOverlay, lockScroll, modalOverlayOpen, openOverlay, unlockScroll, type OverlayLayer } from '../../core/overlay.ts';\nimport type { ActionSetSize } from '../../core/action-set.ts';\nimport { cssDuration } from '../../core/motion.ts';\nimport { actionSetStyles, layoutActions, slottedActions, warnActionProblems } from '../shared/action-set.ts';\nimport { defaultTrue } from '../shared/field.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 '../icon-button/icon-button.ts';\nimport { sidePanelStyles } from './side-panel.styles.ts';\n\nexport type SidePanelSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';\nexport type SidePanelCloseReason = 'escape' | 'close-button' | 'overlay';\n\nconst closeIcon = html`<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=\"M12 4.7 11.3 4 8 7.3 4.7 4 4 4.7 7.3 8 4 11.3l.7.7L8 8.7l3.3 3.3.7-.7L8.7 8z\" /></svg>`;\nconst backIcon = html`<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=\"M7 12.3 3.2 8.5H15v-1H3.2L7 3.7 6.3 3 1.3 8l5 5z\" /></svg>`;\n\n/** The deepest focused element (through shadow roots). */\nfunction deepActive(): Element | null {\n    let el = document.activeElement;\n    while (el?.shadowRoot?.activeElement) el = el.shadowRoot.activeElement;\n    return el;\n}\n\n/** Tab stops in composed order: native controls and hosts that delegate focus, walking into other shadow roots and slots. */\nfunction tabStops(root: Node, out: HTMLElement[] = []): HTMLElement[] {\n    const children = root instanceof HTMLSlotElement ? root.assignedElements({ flatten: true }) : [...((root as Element).shadowRoot?.children ?? (root as ParentNode).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 tabStops(child, out);\n        // a slotted host's own light children were walked through its slot already\n    }\n    return out;\n}\n\n/**\n * Carbon for IBM Products `SidePanel` (`c4p-side-panel`): a panel that slides in from the right (or `placement=\"left\"`)\n * under the 48px UI shell header — `size` xs 16rem, sm 20rem, md 30rem, lg 40rem, xl 65rem, 2xl 80rem (at most 75vw\n * from md screens). Slide-over (default) covers the page and keeps Tab inside it; `include-overlay` dims the page and a\n * click on it closes the panel; `slide-in` instead pushes the page aside (`selector-page-content`), takes no focus\n * and no Esc. Header: `label-text` (label-01), `heading` (heading-03), `slot=\"subtitle\"` (body-compact-01), the ×\n * button (tooltip left), `current-step` > 0 a back button, `slot=\"action-toolbar\"` small buttons under it. As the\n * content scrolls, the label and subtitle fade and the heading shrinks to heading-compact-02 (`animate-title`, Carbon's\n * default; off with reduced motion). `slot=\"actions\"`: up to four `<ui-button>`s, laid out as Carbon's ActionSet for\n * the panel's size (64px; 48px `condensed-actions`). The content sits on layer 1 (fields are field-02). A slide-over\n * panel is on the page's overlay stack: one Esc closes only the topmost layer (a modal opened from the panel closes\n * first), and a panel opened from a modal opens over it, as a modal dialog of its own, so it can be used.\n *\n * @fires ui-request-close - Cancelable; detail: { reason: 'escape' | 'close-button' | 'overlay' }\n * @fires ui-close - After it closed\n * @fires ui-navigate-back - The back button (`current-step` > 0) was pressed\n * @slot - The content\n * @slot subtitle - Text under the heading\n * @slot above-title - Content above the label and heading\n * @slot below-title - Content under the subtitle\n * @slot action-toolbar - Small buttons under the header (the first one with its label)\n * @slot actions - The action buttons\n * @csspart panel - The panel\n * @csspart overlay - The overlay of `include-overlay`\n * @csspart header - The header\n * @csspart heading - The heading\n * @csspart body - The content's box\n * @csspart actions - The row of action buttons\n * @cssprop --ui-side-panel-top - Where the panel starts (default 3rem, under the UI shell header)\n * @cssprop --ui-side-panel-radius - Corner radius of the edge facing the page (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 */\n@customElement('ui-side-panel')\nexport class UiSidePanel extends UiElement {\n    static override readonly styles = [\n        actionSetStyles('.actions'),\n        sidePanelStyles,\n    ];\n\n    @property({ type: Boolean, reflect: true }) open = false;\n\n    @property({ reflect: true }) placement: 'right' | 'left' = 'right';\n\n    /** xs 16rem, sm 20rem, md 30rem, lg 40rem, xl 65rem, 2xl 80rem. */\n    @property({ reflect: true }) size: SidePanelSize = 'md';\n\n    /** The heading (Carbon `title`); also the panel's accessible name. */\n    @property() heading = '';\n\n    /** A small label above the heading. */\n    @property({ attribute: 'label-text' }) labelText = '';\n\n    /** Push the page aside (`selector-page-content`) instead of covering it; no focus trap, no Esc. */\n    @property({ type: Boolean, reflect: true, attribute: 'slide-in' }) slideIn = false;\n\n    /** Dim the page; a click on it closes the panel (unless `prevent-close-on-click-outside`). */\n    @property({ type: Boolean, reflect: true, attribute: 'include-overlay' }) includeOverlay = false;\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 the first control. */\n    @property({ attribute: 'selector-initial-focus' }) selectorInitialFocus = '';\n\n    /** The page element a slide-in panel pushes aside. */\n    @property({ attribute: 'selector-page-content' }) selectorPageContent = '';\n\n    @property({ type: Boolean, attribute: 'hide-close-button' }) hideCloseButton = false;\n\n    /** The × button's name and tooltip (default \"Close\", translated). */\n    @property({ attribute: 'close-icon-description' }) closeIconDescription = '';\n\n    @property({ attribute: 'close-icon-tooltip-alignment' }) closeIconTooltipAlignment: Placement = 'left';\n\n    /** The back button's name and tooltip (default \"Back\", translated). */\n    @property({ attribute: 'navigation-back-icon-description' }) navigationBackIconDescription = '';\n\n    /** Above 0 shows the back button (a panel with steps). */\n    @property({ type: Number, attribute: 'current-step' }) currentStep = 0;\n\n    /** 48px action buttons instead of 64px. */\n    @property({ type: Boolean, reflect: true, attribute: 'condensed-actions' }) condensedActions = false;\n\n    /** Shrink the heading as the content scrolls (Carbon's default). */\n    @property({ attribute: 'animate-title', converter: defaultTrue }) animateTitle = true;\n\n    /** Rendered: open, or animating closed. */\n    @state() private shown = false;\n    @state() private animated = false;\n    @state() private hasSubtitle = false;\n    @state() private hasToolbar = false;\n    @state() private actionCount = 0;\n    /** Opened over a modal dialog: rendered in a modal `<dialog>` of its own, in the top layer above it. */\n    @state() private overModal = false;\n\n    @query('.panel') private readonly panel?: HTMLElement;\n    @query('.overlay') private readonly overlay?: HTMLElement;\n    @query('.scroller') private readonly scroller?: HTMLElement;\n    @query('.body') private readonly body?: HTMLElement;\n    @query('.label') private readonly labelEl?: HTMLElement;\n    @query('.subtitle') private readonly subtitleEl?: HTMLElement;\n    @query('.title') private readonly titleEl?: HTMLElement;\n    @query('.actions') private readonly actionsEl?: HTMLElement;\n    @query('dialog.layer') private readonly layerDialog?: HTMLDialogElement;\n\n    private readonly localize = new LocalizeController(this);\n    private launcher: HTMLElement | null = null;\n    /** The page element pushed aside on open, so close resets the same one. */\n    private pushedPage: HTMLElement | null = null;\n    /** Its place on the page's overlay stack while open (a slide-over panel): Esc reaches it only as the topmost layer. */\n    private layer: OverlayLayer | null = null;\n    private closeTimer?: ReturnType<typeof setTimeout>;\n    private resizeObserver?: ResizeObserver;\n\n    override disconnectedCallback() {\n        super.disconnectedCallback();\n        this.release();\n        clearTimeout(this.closeTimer);\n        // a running animation holds its element\n        for (const a of this.animations) a.cancel();\n        this.animations = [];\n        this.shown = false;\n    }\n\n    private get actionSize(): ActionSetSize {\n        return this.size === 'xs' ? 'sm' : this.size;\n    }\n\n    private duration(name: '--ui-duration-moderate-01' | '--ui-duration-moderate-02') {\n        return cssDuration(getComputedStyle(this).getPropertyValue(name));\n    }\n\n    protected override willUpdate(changed: PropertyValues<this>) {\n        if (changed.has('open') && this.open) {\n            clearTimeout(this.closeTimer);\n            this.shown = true;\n            // a panel opened from a modal goes over it (a page-level panel would sit under the modal's backdrop, inert)\n            this.overModal = !this.slideIn && modalOverlayOpen();\n        }\n    }\n\n    protected override updated(changed: PropertyValues<this>) {\n        super.updated(changed);\n        if (changed.has('currentStep')) (this.animated ? this.scroller : this.body)?.scrollTo?.({ top: 0 });\n        if (changed.has('size')) this.layout();\n        // what fades (label, subtitle, toolbar) or how much there is to scroll may have changed\n        if (this.open && !changed.has('open')) this.measureTitle();\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 async opened() {\n        this.launcher = deepActive() as HTMLElement | null;\n        if (this.overModal && this.layerDialog && !this.layerDialog.open) this.layerDialog.showModal();\n        if (this.includeOverlay) lockScroll(this, document.documentElement);\n        if (!this.slideIn) {\n            this.layer = { escape: () => this.requestClose('escape'), modal: this.overModal };\n            openOverlay(this.layer, globalThis);\n        }\n        this.resizeObserver = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(() => this.measureTitle());\n        if (this.panel) this.resizeObserver?.observe(this.panel);\n        const sliding = this.slide(true);\n        this.pushPage();\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        this.measureTitle();\n        // focus once in place, as Carbon (when its animation is complete): focusing a field still off to the side scrolls a box that holds the panel\n        await sliding?.finished.catch(() => undefined);\n        if (this.open) this.focusInitial();\n    }\n\n    private closed() {\n        this.release();\n        // over a modal: out of the top layer first, so focus can go back into the modal below\n        if (this.layerDialog?.open) this.layerDialog.close();\n        this.pushPage();\n        this.slide(false);\n        const target = this.launcher;\n        this.launcher = null;\n        if (target?.isConnected) focusQuietly(target);\n        this.closeTimer = setTimeout(() => {\n            this.shown = false;\n            this.dispatchEvent(new Event('ui-close', { bubbles: true, composed: true }));\n        }, this.duration('--ui-duration-moderate-01'));\n    }\n\n    /** Undo what an open panel set up on the page. */\n    private release() {\n        if (this.layer) closeOverlay(this.layer);\n        this.layer = null;\n        this.resizeObserver?.disconnect();\n        unlockScroll(this, document.documentElement);\n    }\n\n    /**\n     * Carbon for IBM Products 2.x: 320px in from its edge while it fades in (150ms, entrance), or out the same way\n     * (150ms, exit), the overlay fading with it; reduced motion: none. Returns the panel's animation.\n     */\n    private slide(entering: boolean) {\n        const panel = this.panel;\n        // a hidden page doesn't run animations: one started there would hold the panel off screen until it shows\n        if (!panel || typeof panel.animate !== 'function' || document.hidden) return undefined;\n        const duration = this.duration('--ui-duration-moderate-01');\n        if (duration <= 0) return undefined;\n        const away = { opacity: 0, transform: `translateX(${this.placement === 'left' ? '-320px' : '320px'})` };\n        const shown = { opacity: 1, transform: 'translateX(0)' };\n        const easing = entering ? 'cubic-bezier(0, 0, 0.38, 0.9)' : 'cubic-bezier(0.2, 0, 1, 0.9)';\n        const fill = entering ? 'none' : 'forwards';\n        const sliding = panel.animate(entering ? [away, shown] : [shown, away], { duration, easing, fill });\n        const fading = this.overlay?.animate([{ opacity: entering ? 0 : 1 }, { opacity: entering ? 1 : 0 }], { duration, easing, fill });\n        this.animations = fading ? [sliding, fading] : [sliding];\n        return sliding;\n    }\n\n    /**\n     * The slide and fade animations: kept, because a running animation holds its element, and once the panel is off the\n     * page its shadow root's getAnimations() no longer lists them.\n     */\n    private animations: Animation[] = [];\n\n    /** The page element a slide-in panel pushes aside: in the panel's own tree first (a micro app's shadow root), else the document. */\n    private pageContent() {\n        const root = this.getRootNode() as Document | ShadowRoot;\n        return root.querySelector<HTMLElement>(this.selectorPageContent) ?? document.querySelector<HTMLElement>(this.selectorPageContent);\n    }\n\n    /** A slide-in panel makes room for itself beside the page content. */\n    private pushPage() {\n        if (!this.slideIn || !this.selectorPageContent) return;\n        const page = this.open ? this.pageContent() : this.pushedPage;\n        this.pushedPage = this.open ? page : null;\n        if (!page) return;\n        const width = this.open ? `${this.panel?.offsetWidth ?? 0}px` : '';\n        page.style.transition = `margin var(--ui-duration-moderate-02) var(--ui-easing)`;\n        page.style.marginInlineStart = this.placement === 'left' ? width : '';\n        page.style.marginInlineEnd = this.placement === 'right' ? width : '';\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.actionSize);\n        layoutActions(this.actionsEl, buttons, this.actionSize);\n    }\n\n    /** How far the content scrolls before the header is collapsed: the label, the subtitle (and the title's gap with a toolbar). */\n    private distance() {\n        const title = this.titleEl;\n        const border = this.hasToolbar && title ? title.offsetHeight - title.clientHeight : 0;\n        return (this.labelEl?.offsetHeight ?? 0) + (this.hasSubtitle ? (this.subtitleEl?.offsetHeight ?? 0) : 0) + border;\n    }\n\n    /** Carbon animates the title only when there is something to fade and enough to scroll. */\n    private measureTitle() {\n        const panel = this.panel;\n        if (!panel || !this.open) return;\n        const distance = this.distance();\n        panel.style.setProperty('--_distance', String(distance));\n        const motion = this.duration('--ui-duration-moderate-02') > 0;\n        const scroller = this.animated ? this.scroller : this.body;\n        const room = scroller ? scroller.scrollHeight - scroller.clientHeight : 0;\n        this.animated = this.animateTitle && motion && !!this.heading && distance > 0 && (!!this.labelText || this.hasToolbar || this.hasSubtitle) && room >= distance + 16;\n        if (!this.animated) panel.style.setProperty('--_progress', '0');\n    }\n\n    private readonly onScroll = (event: Event) => {\n        if (!this.animated || !this.panel) return;\n        const distance = this.distance() || 1;\n        const progress = Math.min((event.target as HTMLElement).scrollTop, distance) / distance;\n        this.panel.style.setProperty('--_progress', String(progress));\n    };\n\n    /** The browser's own close request for the dialog over a modal (Esc itself goes through core/overlay.ts): a request, as Esc. */\n    private onLayerCancel(event: Event) {\n        event.preventDefault();\n        if (this.layer && isTopOverlay(this.layer)) this.requestClose('escape');\n    }\n\n    /** Tab stays inside a slide-over panel (Carbon). */\n    private readonly onKeydown = (event: KeyboardEvent) => {\n        if (event.key !== 'Tab' || this.slideIn || !this.panel) return;\n        const stops = tabStops(this.panel);\n        if (!stops.length) return;\n        const first = stops[0];\n        const last = stops.at(-1)!;\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 focusInitial() {\n        const chosen = this.selectorInitialFocus ? this.querySelector<HTMLElement>(this.selectorInitialFocus) : null;\n        if (chosen) {\n            focusQuietly(chosen);\n            return;\n        }\n        if (!this.slideIn && this.panel) focusQuietly(tabStops(this.panel)[0]);\n    }\n\n    /** Asks to close (cancelable `ui-request-close`), then closes. */\n    requestClose(reason: SidePanelCloseReason) {\n        const request = new CustomEvent<CloseDetail<SidePanelCloseReason>>('ui-request-close', { detail: { reason }, bubbles: true, composed: true, cancelable: true });\n        if (this.dispatchEvent(request)) this.open = false;\n    }\n\n    private onOverlayClick() {\n        if (!this.preventCloseOnClickOutside) this.requestClose('overlay');\n    }\n\n    private onBack() {\n        this.dispatchEvent(new Event('ui-navigate-back', { bubbles: true, composed: true }));\n    }\n\n    private onActionsChange(event: Event) {\n        this.actionCount = slottedActions(event.target as HTMLSlotElement).length;\n        this.layout();\n    }\n\n    private renderTitle() {\n        const collapsed = this.animated ? html`<h2 class=\"collapsed\" aria-hidden=\"true\">${this.heading}</h2>` : nothing;\n        return html`<div class=${classMap({ title: true, 'no-label': !this.labelText })}><h2 class=\"title-text\" part=\"heading\">${this.heading}</h2>${collapsed}</div>`;\n    }\n\n    private renderHeader() {\n        const t = this.localize.t.common;\n        const iconSize = this.actionCount > 0 && /l/.test(this.size) ? 'md' : 'sm';\n        const classes = { header: true, 'has-heading': !!this.heading, 'has-subtitle': this.hasSubtitle, 'has-back': this.currentStep > 0, 'has-toolbar': this.hasToolbar, 'md-buttons': iconSize === 'md' };\n        return html`<div class=${classMap(classes)} part=\"header\">\n            ${this.currentStep > 0\n                ? html`<ui-icon-button class=\"back\" kind=\"ghost\" size=${iconSize} label=${this.navigationBackIconDescription || t.back} tooltip-placement=\"bottom-start\" @click=${this.onBack}>${backIcon}</ui-icon-button>`\n                : nothing}\n            <slot name=\"above-title\"></slot>\n            ${this.heading && this.labelText ? html`<p class=\"label\">${this.labelText}</p>` : nothing}\n            ${this.heading ? this.renderTitle() : nothing}\n            <div class=\"close-area\">\n                ${this.hideCloseButton\n                    ? nothing\n                    : html`<ui-icon-button class=\"close\" kind=\"ghost\" size=${iconSize} label=${this.closeIconDescription || t.close} tooltip-placement=${this.closeIconTooltipAlignment} @click=${() => this.requestClose('close-button')}>${closeIcon}</ui-icon-button>`}\n            </div>\n            <p class=\"subtitle\" ?hidden=${!this.hasSubtitle}><slot name=\"subtitle\" @slotchange=${(e: Event) => (this.hasSubtitle = (e.target as HTMLSlotElement).assignedNodes().length > 0)}></slot></p>\n            <slot name=\"below-title\"></slot>\n            <div class=\"toolbar-row\" ?hidden=${!this.hasToolbar}>\n                <slot name=\"action-toolbar\" @slotchange=${(e: Event) => (this.hasToolbar = (e.target as HTMLSlotElement).assignedElements().length > 0)}></slot>\n            </div>\n        </div>`;\n    }\n\n    override render() {\n        if (!this.shown) return nothing;\n        const classes = { panel: true, animated: this.animated, 'slide-in': this.slideIn, toolbar: this.hasToolbar, condensed: this.condensedActions };\n        const sizes: Record<SidePanelSize, string> = { xs: '16rem', sm: '20rem', md: '30rem', lg: '40rem', xl: '65rem', '2xl': '80rem' };\n        const overlay = this.includeOverlay ? html`<div class=\"overlay\" part=\"overlay\" @click=${this.onOverlayClick}></div>` : nothing;\n        const content = html`${overlay}\n            <ui-layer\n                class=${classMap(classes)}\n                part=\"panel\"\n                level=\"1\"\n                role=\"complementary\"\n                aria-label=${this.heading || nothing}\n                data-placement=${this.placement}\n                style=\"--_size: ${sizes[this.size] ?? sizes.md}\"\n                @keydown=${this.onKeydown}\n            >\n                <div class=\"scroller\" @scroll=${this.onScroll}>\n                    ${this.renderHeader()}\n                    <div class=${classMap({ body: true, scrolls: !this.animated })} part=\"body\" @scroll=${this.onScroll}><slot @slotchange=${() => this.measureTitle()}></slot></div>\n                </div>\n                <div class=\"actions\" part=\"actions\" ?hidden=${this.actionCount === 0} ?data-condensed=${this.condensedActions}><slot name=\"actions\" @slotchange=${this.onActionsChange}></slot></div>\n            </ui-layer>`;\n        return this.overModal ? html`<dialog class=\"layer\" @cancel=${this.onLayerCancel}>${content}</dialog>` : content;\n    }\n}\n\nexport interface UiSidePanelEventMap extends HTMLElementEventMap {\n    'ui-request-close': CustomEvent<CloseDetail<SidePanelCloseReason>>;\n    'ui-close': Event;\n    'ui-navigate-back': Event;\n}\n\nexport interface UiSidePanel {\n    addEventListener<K extends keyof UiSidePanelEventMap>(type: K, listener: (this: UiSidePanel, event: UiSidePanelEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;\n    addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;\n    removeEventListener<K extends keyof UiSidePanelEventMap>(type: K, listener: (this: UiSidePanel, event: UiSidePanelEventMap[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-side-panel': UiSidePanel;\n    }\n}\n"
    }
  ]
}
