{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tabs",
  "type": "registry:ui",
  "title": "<ui-tabs>",
  "description": "Carbon tabs: `line` (default; Carbon's product tabs) or `type=\"contained\"` — 48px tabs on layer-accent with dividers, the selected one on the layer with a blue top edge, and panels on the layer padded 16px; `full-width` splits the strip into equal columns. 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-roving",
    "@kanok-ui/layer",
    "@kanok-ui/shared-element",
    "@kanok-ui/shared-field",
    "@kanok-ui/shared-localize",
    "@kanok-ui/shared-skeleton",
    "@kanok-ui/tooltip",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/tabs/tab-panel.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/tabs/tab-panel.ts",
      "content": "import { css, html } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { uid } from '../shared/field.ts';\nimport { UiElement } from '../shared/element.ts';\n\nconst FOCUSABLE =\n    'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"]), [contenteditable=\"true\"]';\n\n/**\n * Content for one tab. Hidden (and removed from the accessibility tree) unless active.\n *\n * @slot - Panel content\n */\n@customElement('ui-tab-panel')\nexport class UiTabPanel extends UiElement {\n    static override readonly styles = css`\n        :host {\n            display: block;\n            outline: none;\n        }\n\n        /* Carbon tab-content: 16px all round — on a part, not :host, so a page-wide CSS reset can't remove it */\n        .base {\n            padding: var(--ui-space-md);\n        }\n\n        :host([hidden]) {\n            display: none;\n        }\n\n        /* vertical tabs stack every panel in one cell, so the tallest sets the height (Carbon measures it); the others stay out of sight, focus and the accessibility tree */\n        :host([data-vertical]) {\n            grid-area: 1 / 1;\n        }\n\n        :host([data-vertical][hidden]) {\n            display: block;\n            visibility: hidden;\n        }\n\n        /* Carbon: contained tabs' content sits on the layer */\n        :host([data-contained]) {\n            background-color: var(--ui-surface-1);\n        }\n\n        :host(:focus-visible) {\n            outline: var(--ui-focus-width, 2px) solid var(--ui-focus);\n            outline-offset: -2px;\n            border-radius: var(--ui-tab-focus-radius, 0); /* the tabs' ring corners (Kanok: 6px) */\n        }\n    `;\n\n    @property({ reflect: true }) name = '';\n\n    override connectedCallback() {\n        super.connectedCallback();\n        if (!this.hasAttribute('role')) this.setAttribute('role', 'tabpanel');\n        if (!this.id) this.id = uid('ui-tab-panel');\n    }\n\n    protected override updated(changed: Map<string, unknown>) {\n        // renamed after the first render: the tab list shows the panels and wires aria-controls by name\n        if (changed.has('name') && changed.get('name') !== undefined && this.parentElement?.localName === 'ui-tabs') (this.parentElement as UiElement).requestUpdate();\n    }\n\n    /** APG: make the panel a tab stop only when nothing inside it can take focus. */\n    private syncTabStop() {\n        if (this.querySelector(FOCUSABLE)) this.removeAttribute('tabindex');\n        else this.tabIndex = 0;\n    }\n\n    override render() {\n        return html`<div class=\"base\"><slot @slotchange=${this.syncTabStop}></slot></div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-tab-panel': UiTabPanel;\n    }\n}\n"
    },
    {
      "path": "src/primitives/tabs/tab.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/tabs/tab.ts",
      "content": "import { html, css, nothing } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { uid, setManagedAttribute } from '../shared/field.ts';\nimport { UiElement } from '../shared/element.ts';\nimport { LocalizeController } from '../shared/localize.ts';\nimport { UiTabs } from './tabs.ts';\nimport '../tooltip/tooltip.ts';\n\n/** Carbon Close (16). */\nconst closeIcon = html`<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=\"m12 4.7-.7-.7L8 7.3 4.7 4l-.7.7L7.3 8 4 11.3l.7.7L8 8.7l3.3 3.3.7-.7L8.7 8z\" /></svg>`;\n\n/**\n * A tab in `<ui-tabs>`. `panel` must match the `name` of a `<ui-tab-panel>`.\n * role / aria-selected / aria-controls are set on the host so the id references\n * stay in the same (light) DOM tree as the panels.\n *\n * Carbon `Tab` extras: an icon (`slot=\"icon\"`, Carbon `renderIcon`: 16px after the label, before it\n * in dismissable tabs), `secondary-label` (contained tabs: a second line, the strip grows to 64px)\n * and `icon-only` + `label` (Carbon `IconTab`: a square tab named by `label`, shown as its tooltip\n * below on hover after 100ms and on keyboard focus). In `<ui-tabs dismissable>` a close button sits\n * at the end of the tab.\n *\n * @slot - Tab label\n * @slot icon - A 16px icon (20px in icon-only tabs of `size=\"lg\"`), coloured like the label\n * @csspart secondary-label - The second line of a contained tab\n * @csspart close-button - The close button of a dismissable tab (no tab stop: Delete closes the focused tab)\n * @csspart tooltip - The `<ui-tooltip>` of an `icon-only` tab\n * @fires ui-request-close - Dismissable tabs: its close button or Delete; cancelable; detail: { name } (its `panel`)\n * @fires ui-close - Dismissable tabs: after it closed (now `hidden`); detail: { name }\n * @cssprop --ui-tab-line - The underline of every tab (default `2px solid --ui-hairline`; Kanok: transparent, the strip draws one line)\n * @cssprop --ui-tab-selected-line - The selected tab's mark (default `--ui-border-interactive`, as in Kanok)\n * @cssprop --ui-tab-hover-line - Underline colour on hover (default `--ui-ink-subtle`)\n * @cssprop --ui-tab-disabled-line - Underline colour when disabled (default `--ui-hairline`)\n * @cssprop --ui-tab-background - Fill of a line tab (default `--ui-canvas`; Kanok: transparent)\n * @cssprop --ui-tab-contained-background / --ui-tab-contained-hover / --ui-tab-contained-selected - Fills of a contained tab at rest, hovered and selected (Carbon: layer-accent, its hover, the layer)\n * @cssprop --ui-tab-contained-selected-shadow - `box-shadow` of the selected contained tab (default: a 2px top bar in `--ui-tab-selected-line`)\n * @cssprop --ui-tab-contained-radius - Corner radius of a contained tab (default 0; Kanok: 6px)\n * @cssprop --ui-tab-contained-divider - The 1px line between contained tabs (default `--ui-hairline-strong`; Kanok: none)\n * @cssprop --ui-tab-focus-radius - Corner radius of the focus ring (default 0; Kanok: 6px)\n * @cssprop --ui-tab-focus-offset / --ui-tab-contained-focus-offset - Where the focus ring sits, line and contained tabs (default -2px, over the selected underline; Kanok: -5px, clear of it, and 1px around the chip)\n * @cssprop --ui-tab-vertical-background / --ui-tab-vertical-selected / --ui-tab-vertical-bar / --ui-tab-vertical-hover-bar / --ui-tab-vertical-divider / --ui-tab-vertical-inset / --ui-tab-vertical-radius - Vertical tabs: fill, the chosen tab's fill, the side bars, the rule between tabs, inset and corners (default Carbon's layer fill with bars and rules; Kanok: inset rounded rows, the chosen one tinted)\n * @cssprop --ui-tab-vertical-mark - The chosen vertical tab's 3px start bar (default `--ui-tab-selected-line`; Kanok: none, the tint alone)\n * @cssprop --ui-icon-control-radius - Corners of its small icon buttons, their hover fill and ring (default 0; Kanok: round)\n */\n@customElement('ui-tab')\nexport class UiTab extends UiElement {\n    /* Carbon line tab (cds-tabs, size md): 40px with a 2px underline, 16px padding, 1px apart */\n    static override readonly styles = css`\n        :host {\n            flex-shrink: 0;\n            display: inline-flex;\n            min-height: var(--_tab-h, 40px);\n            background-color: var(--ui-tab-background, var(--ui-canvas));\n            color: var(--ui-ink-muted);\n            font: var(--ui-font-body-sm);\n            letter-spacing: var(--ui-tracking-body);\n            white-space: nowrap;\n            cursor: pointer;\n            outline: none;\n            /* Carbon .cds--tabs__nav-item (fill) and __nav-link (text, ring): fast-01 */\n            transition:\n                color var(--ui-duration-fast) var(--ui-easing),\n                background-color var(--ui-duration-fast) var(--ui-easing),\n                outline var(--ui-duration-fast) var(--ui-easing);\n        }\n\n        /*\n         * The padding and the underline are drawn by this part filling the tab, not by :host, so a\n         * page-wide CSS reset can't remove them (the 1px between tabs is the tab list's gap).\n         */\n        .base {\n            display: flex;\n            flex: 1;\n            align-items: center;\n            box-sizing: border-box;\n            padding: 0 var(--ui-space-md);\n            /* Carbon: a 2px track under every tab; --ui-tab-line / --ui-tabs-track let a design draw one line under the strip */\n            border-bottom: var(--ui-tab-line, 2px solid var(--ui-hairline));\n            transition: border-color var(--ui-duration-fast) var(--ui-easing);\n        }\n\n        /* closed (dismissable) */\n        :host([hidden]) {\n            display: none;\n        }\n\n        /*\n         * hovering the close button is no hover on the tab (Carbon: the button is the tab's sibling); the selected tab\n         * keeps its mark under the pointer (and on a touch screen, which leaves :hover on the tab just tapped)\n         */\n        :host(:hover:not([data-close-hover], [selected])) {\n            color: var(--ui-ink);\n        }\n\n        :host(:hover:not([data-close-hover], [selected])) .base {\n            border-bottom-color: var(--ui-tab-hover-line, var(--ui-ink-subtle));\n        }\n\n        :host([selected]) {\n            color: var(--ui-ink);\n            font: var(--ui-font-body-emphasis);\n        }\n\n        /* --ui-tab-selected-line: the selected tab's mark (Carbon and Kanok: border-interactive) */\n        :host([selected]) .base {\n            border-bottom-color: var(--ui-tab-selected-line, var(--ui-border-interactive));\n        }\n\n        /*\n         * --ui-tab-focus-radius: a design can round the focus ring as its other controls' (Carbon: square);\n         * --ui-tab-focus-offset: and draw it clear of the selected underline (Carbon: over it, -2px). Inward, not outward:\n         * the tab list scrolls, so a ring outside the tab would be cut off.\n         */\n        :host(:focus-visible) {\n            border-radius: var(--ui-tab-focus-radius, 0);\n            outline: var(--ui-focus-width, 2px) solid var(--ui-focus);\n            outline-offset: var(--ui-tab-focus-offset, -2px);\n        }\n\n        /* a contained chip: the ring around it, in the track's padding (--ui-tab-contained-focus-offset) */\n        :host([data-contained]:focus-visible) {\n            outline-offset: var(--ui-tab-contained-focus-offset, var(--ui-tab-focus-offset, -2px));\n        }\n\n        :host([disabled]) {\n            color: var(--ui-ink-disabled);\n            cursor: not-allowed;\n        }\n\n        :host([disabled]) .base {\n            border-bottom-color: var(--ui-tab-disabled-line, var(--ui-hairline));\n        }\n\n        /*\n         * Contained (Carbon tabs--contained, measured on web-components.carbondesignsystem.com): 48px on layer-accent,\n         * text-secondary, a 1px border-strong divider before each tab except the first and the one after the\n         * selected tab; hover layer-accent-hover; selected on the layer with a 2px border-interactive top edge;\n         * disabled button-disabled with text-on-color-disabled. The data attributes are set by ui-tabs.\n         */\n        /* --ui-tab-contained-*: Carbon's boxes on layer-accent; a design can make them a segmented control */\n        :host([data-contained]) {\n            position: relative;\n            min-height: var(--_tab-h, 48px);\n            border-radius: var(--ui-tab-contained-radius, 0);\n            background-color: var(--ui-tab-contained-background, var(--ui-layer-accent));\n        }\n\n        :host([data-contained]) .base {\n            border-bottom: none;\n        }\n\n        :host([data-contained])::before {\n            position: absolute;\n            inset-block: 0;\n            inset-inline-start: -1px;\n            inline-size: 1px;\n            background-color: var(--ui-tab-contained-divider, var(--ui-hairline-strong));\n            content: '';\n        }\n\n        :host([data-contained][data-first])::before,\n        :host([data-contained][data-after-selected])::before,\n        :host([data-contained][selected])::before {\n            content: none;\n        }\n\n        :host([data-contained]:hover:not([selected], [disabled], [data-close-hover])) {\n            background-color: var(--ui-tab-contained-hover, var(--ui-layer-accent-hover));\n            color: var(--ui-ink);\n        }\n\n        :host([data-contained][selected]) {\n            background-color: var(--ui-tab-contained-selected, var(--ui-surface-1));\n            box-shadow: var(--ui-tab-contained-selected-shadow, inset 0 2px 0 0 var(--ui-tab-selected-line, var(--ui-border-interactive)));\n        }\n\n        :host([data-contained][disabled]) {\n            background-color: var(--ui-tab-contained-disabled, var(--ui-button-disabled));\n            color: var(--ui-tab-contained-disabled-ink, var(--ui-on-color-disabled));\n        }\n\n        /* full-width: equal columns, long labels end in an ellipsis */\n        :host([data-full-width]) {\n            display: block;\n            min-width: 0;\n            overflow: hidden;\n            line-height: var(--_tab-h, 48px);\n        }\n\n        :host([data-full-width]) .base {\n            display: block;\n            overflow: hidden;\n            text-overflow: ellipsis;\n        }\n\n        /* Carbon: the label (and the secondary label) end in an ellipsis */\n        :host([data-full-width]) .label {\n            overflow: hidden;\n            text-overflow: ellipsis;\n        }\n\n        /*\n         * Vertical (Carbon tabs--vertical, measured on the React story): full width, layer-01 with a 1px border-subtle\n         * below and at the end and a 3px border-subtle bar at the start; hover layer-hover with a border-strong bar;\n         * selected on the layer with a border-interactive bar and no end border; labels up to two lines (sm one).\n         */\n        /* --ui-tab-vertical-*: a design can make the rows inset, rounded, undivided ones as the side nav's */\n        :host([data-vertical]) {\n            flex: none;\n            box-sizing: border-box;\n            inline-size: calc(100% - 2 * var(--ui-tab-vertical-inset, 0px));\n            min-height: 0;\n            block-size: var(--_tab-h, 64px);\n            margin-inline: var(--ui-tab-vertical-inset, 0px);\n            border-block-end: var(--ui-tab-vertical-divider, 1px solid var(--ui-hairline));\n            border-inline-end: var(--ui-tab-vertical-divider, 1px solid var(--ui-hairline));\n            border-radius: var(--ui-tab-vertical-radius, 0);\n            background-color: var(--ui-tab-vertical-background, var(--ui-surface-1));\n            box-shadow: inset 3px 0 0 0 var(--ui-tab-vertical-bar, var(--ui-hairline));\n            white-space: normal;\n        }\n\n        :host(:dir(rtl)[data-vertical]) {\n            box-shadow: inset -3px 0 0 0 var(--ui-tab-vertical-bar, var(--ui-hairline));\n        }\n\n        :host([data-vertical]) .base {\n            border-bottom: none;\n        }\n\n        :host([data-vertical]) .label {\n            display: -webkit-box;\n            overflow: hidden;\n            -webkit-box-orient: vertical;\n            -webkit-line-clamp: var(--_tab-lines, 2);\n            line-height: 18px; /* body-compact-01 */\n            text-overflow: ellipsis;\n        }\n\n        :host([data-vertical]:hover:not([selected], [disabled])) {\n            background-color: var(--ui-ghost-hover);\n            box-shadow: inset 3px 0 0 0 var(--ui-tab-vertical-hover-bar, var(--ui-hairline-strong));\n        }\n\n        :host(:dir(rtl)[data-vertical]:hover:not([selected], [disabled])) {\n            box-shadow: inset -3px 0 0 0 var(--ui-tab-vertical-hover-bar, var(--ui-hairline-strong));\n        }\n\n        :host([data-vertical][selected]) {\n            border-inline-end: none;\n            background-color: var(--ui-tab-vertical-selected, var(--ui-tab-vertical-background, var(--ui-surface-1)));\n            box-shadow: inset 3px 0 0 0 var(--ui-tab-vertical-mark, var(--ui-tab-selected-line, var(--ui-border-interactive)));\n        }\n\n        :host(:dir(rtl)[data-vertical][selected]) {\n            box-shadow: inset -3px 0 0 0 var(--ui-tab-vertical-mark, var(--ui-tab-selected-line, var(--ui-border-interactive)));\n        }\n\n        :host([data-vertical][disabled]) {\n            background-color: var(--ui-tab-vertical-background, var(--ui-surface-1));\n        }\n\n        /* the label and its icon (Carbon tabs__nav-item-label-wrapper) */\n        .row {\n            display: flex;\n            align-items: center;\n            min-inline-size: 0;\n        }\n\n        /*\n         * Carbon renderIcon (tabs__nav-item--icon): a 16px icon in the text colour after the label, 8px\n         * from it (contained and vertical: 16px); in dismissable tabs before the label, 8px from it and\n         * 1px higher (tabs__nav-item--icon-left).\n         */\n        ::slotted([slot='icon']) {\n            flex-shrink: 0;\n            inline-size: 16px;\n            block-size: 16px;\n            margin-inline-start: var(--ui-space-xs);\n            fill: currentColor;\n        }\n\n        :host([data-contained]) ::slotted([slot='icon']),\n        :host([data-vertical]) ::slotted([slot='icon']) {\n            margin-inline-start: var(--ui-space-md);\n        }\n\n        /* full width: pushed to the end */\n        :host([data-full-width]) ::slotted([slot='icon']) {\n            margin-inline-start: auto;\n        }\n\n        :host([data-dismissable]) ::slotted([slot='icon']) {\n            order: -1;\n            align-self: flex-start;\n            margin-inline: 0 var(--ui-space-xs);\n        }\n\n        /*\n         * Carbon IconTab: a square tab (its height both ways), the icon centred; icon-only contained tabs\n         * keep 1px apart. 20px icons go with size lg (Carbon iconSize=\"lg\"), set by ui-tabs.\n         */\n        :host([icon-only]) {\n            position: relative;\n            inline-size: var(--_tab-h, 40px);\n        }\n\n        :host([icon-only]) .base {\n            justify-content: center;\n            padding: 0;\n        }\n\n        :host([icon-only]) .label {\n            display: none;\n        }\n\n        :host([icon-only]) ::slotted([slot='icon']) {\n            inline-size: var(--_tab-icon, 16px);\n            block-size: var(--_tab-icon, 16px);\n            margin: 0;\n        }\n\n        :host([icon-only][data-contained]) {\n            margin-inline-end: 1px;\n        }\n\n        /* the tooltip anchors to the host and shows its bubble in the top layer; it takes no room here */\n        ui-tooltip {\n            position: absolute;\n            cursor: auto;\n            white-space: normal;\n            user-select: auto;\n        }\n\n        /*\n         * Carbon secondaryLabel (contained only, tabs--tall): every tab 64px whatever the size, the label\n         * (body-compact-01) over the secondary label (label-01, at least 16px tall, regular weight),\n         * both at the start, centred together.\n         */\n        .secondary {\n            display: none;\n        }\n\n        :host([data-tall]) {\n            min-height: 64px;\n        }\n\n        :host([data-tall]) .base {\n            flex-direction: column;\n            align-items: flex-start;\n            justify-content: center;\n        }\n\n        :host([data-tall]) .row {\n            max-inline-size: 100%;\n        }\n\n        :host([data-tall]) .secondary {\n            display: block;\n            max-inline-size: 100%;\n            min-block-size: 16px;\n            overflow: hidden;\n            font: var(--ui-font-caption);\n            letter-spacing: var(--ui-tracking-caption);\n            text-overflow: ellipsis;\n        }\n\n        :host([data-full-width][data-tall]) {\n            display: flex;\n            line-height: 1.29;\n        }\n\n        :host([data-full-width][data-tall]) .base {\n            display: flex;\n        }\n\n        /*\n         * Carbon dismissable tabs: the end padding grows to 40px (spacing-08; contained 47px) and a 24px\n         * close button sits 12px from the end, centred: a 16px text-secondary × (icon-primary on a\n         * hovered or selected tab), layer-hover under the pointer, the focus outline while pressed.\n         * Icon-only tabs get none (they have no room for it).\n         */\n        .close {\n            position: absolute;\n            inset-block: 0;\n            inset-inline-end: var(--ui-space-sm);\n            display: none;\n            place-items: center;\n            box-sizing: border-box;\n            inline-size: 24px;\n            block-size: 24px;\n            margin: auto 0;\n            padding: var(--ui-space-xxs);\n            border: none;\n            background: none;\n            color: var(--ui-ink-muted);\n            cursor: pointer;\n            outline: none;\n            border-radius: var(--ui-icon-control-radius, 0); /* round in a design that rounds icon controls (Kanok) */\n        }\n\n        :host([data-dismissable]) {\n            position: relative;\n        }\n\n        :host([data-dismissable]:not([icon-only])) .base {\n            padding-inline-end: 40px;\n        }\n\n        :host([data-dismissable][data-contained]:not([icon-only])) .base {\n            padding-inline-end: 47px;\n        }\n\n        :host([data-dismissable]:not([icon-only])) .close {\n            display: grid;\n        }\n\n        .close svg {\n            inline-size: 16px;\n            block-size: 16px;\n            fill: currentColor;\n        }\n\n        :host(:hover) .close,\n        :host([selected]) .close {\n            color: var(--ui-icon-primary);\n        }\n\n        .close:hover {\n            background-color: var(--ui-ghost-hover);\n        }\n\n        .close:focus,\n        .close:active {\n            outline: var(--ui-focus-width, 2px) solid var(--ui-focus);\n            outline-offset: -2px;\n        }\n\n        /* a mouse or touch focus shows no ring in a design that sets --ui-pointer-focus (Kanok: keyboard only) */\n        .close:focus:not(:focus-visible),\n        .close:active {\n            outline-color: var(--ui-pointer-focus, var(--ui-focus));\n        }\n\n        :host([disabled]) .close {\n            background: none;\n            color: var(--ui-icon-disabled);\n            cursor: not-allowed;\n            outline: none;\n        }\n\n        @media (forced-colors: active) {\n            :host([selected]) .base {\n                border-bottom-color: Highlight;\n            }\n            :host([data-contained][selected]) {\n                background-color: SelectedItem;\n            }\n        }\n    `;\n\n    @property({ reflect: true }) panel = '';\n\n    @property({ type: Boolean, reflect: true }) selected = false;\n\n    /** Disables the control; a disabled `<fieldset>` ancestor does the same. */\n    @property({ type: Boolean, reflect: true }) disabled = false;\n\n    /** A second line under the label (Carbon `secondaryLabel`); contained tabs only. */\n    @property({ attribute: 'secondary-label' }) secondaryLabel = '';\n\n    /** Only the `icon` slot shows (Carbon `IconTab`); `label` names the tab and is its tooltip. */\n    @property({ type: Boolean, reflect: true, attribute: 'icon-only' }) iconOnly = false;\n\n    /** Accessible name and tooltip of an `icon-only` tab — required with it. */\n    @property() label = '';\n\n    /** The slotted label's text, for the close button's title. */\n    @state() private text = '';\n\n    private readonly localize = new LocalizeController(this);\n\n    /** `hidden` too (a closed tab the app shows again): the tab list re-syncs when it changes. */\n    static override get observedAttributes() {\n        return [...super.observedAttributes, 'hidden'];\n    }\n\n    override attributeChangedCallback(name: string, old: string | null, value: string | null) {\n        super.attributeChangedCallback(name, old, value);\n        if (name === 'hidden' && old !== value) this.notifyTabs();\n    }\n\n    /** The tab list derives the selection, the roving tab stop and the edge marks from its tabs: it syncs again. */\n    private notifyTabs() {\n        if (this.parentElement instanceof UiTabs) this.parentElement.requestUpdate();\n    }\n\n    override connectedCallback() {\n        super.connectedCallback();\n        if (!this.hasAttribute('role')) this.setAttribute('role', 'tab');\n        if (!this.hasAttribute('slot')) this.slot = 'nav';\n        if (!this.id) this.id = uid('ui-tab');\n    }\n\n    protected override updated(changed: Map<string, unknown>) {\n        this.setAttribute('aria-selected', String(this.selected));\n        this.setAttribute('aria-disabled', String(this.disabled));\n        setManagedAttribute(this, 'aria-label', this.iconOnly && this.label ? this.label : null);\n        // a secondary label makes the whole contained strip tall; a tab disabled or renamed after the first render\n        // can change the selection, the tab stop and aria-controls\n        if (changed.has('secondaryLabel') || (['disabled', 'panel'] as const).some((k) => changed.has(k) && changed.get(k) !== undefined)) this.notifyTabs();\n    }\n\n    private onLabelChange(event: Event) {\n        const nodes = (event.target as HTMLSlotElement).assignedNodes({ flatten: true });\n        this.text = nodes.map((n) => n.textContent ?? '').join('').trim();\n    }\n\n    /** Carbon `hover-off`: the pointer on the close button isn't on the tab. */\n    private closeHover(on: boolean) {\n        this.toggleAttribute('data-close-hover', on);\n    }\n\n    override render() {\n        // Carbon: the close button's title, \"Remove <label> tab\"\n        const remove = this.localize.t.common.removeTab.replace('{text}', this.label || this.text).replaceAll(/\\s+/g, ' ').trim();\n        const secondary = this.secondaryLabel ? html`<span class=\"secondary\" part=\"secondary-label\" title=${this.secondaryLabel}>${this.secondaryLabel}</span>` : nothing;\n        const tooltip = this.iconOnly && this.label\n            ? html`<ui-tooltip as-label part=\"tooltip\" text=${this.label} placement=\"bottom\" .anchor=${this} @click=${(e: Event) => e.stopPropagation()}></ui-tooltip>`\n            : nothing;\n        // the close button is no tab stop and hidden from assistive tech (inside a tab its role is lost): Delete closes the tab\n        return html`<span class=\"base\"><span class=\"row\"><span class=\"label\"><slot @slotchange=${this.onLabelChange}></slot></span><slot name=\"icon\"></slot></span>${secondary}</span><button\n                class=\"close\"\n                part=\"close-button\"\n                type=\"button\"\n                tabindex=\"-1\"\n                aria-hidden=\"true\"\n                title=${remove}\n                ?disabled=${this.disabled}\n                @pointerenter=${() => this.closeHover(true)}\n                @pointerleave=${() => this.closeHover(false)}\n            >\n                ${closeIcon}\n            </button>${tooltip}`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-tab': UiTab;\n    }\n}\n"
    },
    {
      "path": "src/primitives/tabs/tabs-skeleton.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/tabs/tabs-skeleton.ts",
      "content": "import { html, css } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { skeletonStyles, UiSkeletonElement } from '../shared/skeleton.ts';\n\n/**\n * Carbon `TabsSkeleton`: `tabs` tabs of 160×40, 1px apart, each a 2px skeleton-coloured underline and a 14px bar.\n * Hidden from assistive tech.\n *\n * @csspart tab - Each tab\n */\n@customElement('ui-tabs-skeleton')\nexport class UiTabsSkeleton extends UiSkeletonElement {\n    static override readonly styles = [\n        skeletonStyles,\n        css`\n            :host {\n                display: block;\n            }\n\n            .list {\n                display: flex;\n                gap: 1px;\n            }\n\n            .tab {\n                box-sizing: border-box;\n                display: flex;\n                align-items: center;\n                inline-size: 160px;\n                block-size: 40px;\n                padding: 0 var(--ui-space-md);\n                border-block-end: 2px solid var(--ui-skeleton-element);\n            }\n\n            .bone {\n                inline-size: 100%;\n                block-size: 14px;\n            }\n        `,\n    ];\n\n    @property({ type: Number }) tabs = 5;\n\n    override render() {\n        const tab = html`<div class=\"tab\" part=\"tab\"><span class=\"bone\"></span></div>`;\n        return html`<div class=\"list\">${Array.from({ length: Math.max(1, this.tabs) }, () => tab)}</div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-tabs-skeleton': UiTabsSkeleton;\n    }\n}\n"
    },
    {
      "path": "src/primitives/tabs/tabs.styles.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/tabs/tabs.styles.ts",
      "content": "import { css } from 'lit';\n\n/** Styles of `<ui-tabs>`. */\nexport const tabsStyles = css`\n    /* tab height, inherited by the light-DOM ui-tab children */\n    :host {\n        --_tab-h: 40px;\n\n        display: block;\n        font-family: var(--ui-font-family);\n    }\n\n    :host([type='contained']) {\n        --_tab-h: var(--ui-tabs-contained-height, 48px);\n    }\n\n    :host([size='sm']) {\n        --_tab-h: 32px;\n    }\n\n    :host([size='md']) {\n        --_tab-h: 40px;\n    }\n\n    :host([size='lg']),\n    :host([size='xl']) {\n        --_tab-h: 48px; /* Carbon line tabs stop at lg */\n    }\n\n    /* Carbon iconSize=\"lg\": 20px icons in 48px icon-only tabs */\n    :host([size='lg']) {\n        --_tab-icon: 20px;\n    }\n\n    :host([type='contained'][size='xl']) {\n        --_tab-h: 64px;\n    }\n\n    .strip {\n        display: flex;\n        box-shadow: var(--ui-tabs-track, none);\n    }\n\n    /* Carbon line tabs: 1px apart */\n    .tablist {\n        flex: 1;\n        display: flex;\n        column-gap: var(--ui-tabs-gap, 1px);\n        min-width: 0;\n        overflow-x: auto;\n        scrollbar-width: none;\n    }\n\n    .tablist::-webkit-scrollbar {\n        display: none;\n    }\n\n    .scroll {\n        flex-shrink: 0;\n        display: grid;\n        place-items: center;\n        width: 40px;\n        min-height: var(--_tab-h);\n        padding: 0;\n        border: none;\n        border-bottom: var(--ui-tab-line, 2px solid var(--ui-hairline));\n        background-color: var(--ui-canvas);\n        color: var(--ui-ink);\n        cursor: pointer;\n    }\n\n    .scroll[hidden] {\n        display: none;\n    }\n\n    /* Carbon overflow nav buttons: background-hover / background-active */\n    .scroll:hover {\n        background-color: var(--ui-canvas-hover);\n    }\n\n    .scroll:active {\n        background-color: var(--ui-canvas-active);\n    }\n\n    .scroll svg {\n        width: 16px;\n        height: 16px;\n        fill: currentColor;\n    }\n\n    :host(:dir(rtl)) .scroll svg {\n        transform: scaleX(-1);\n    }\n\n    .end {\n        flex-shrink: 0;\n        display: flex;\n        align-items: center;\n        border-bottom: var(--ui-tab-line, 2px solid var(--ui-hairline));\n    }\n\n    /* Carbon contained: 48px scroll buttons on layer-accent, no underline */\n    :host([type='contained']) .scroll {\n        width: 48px;\n        border-bottom: none;\n        background-color: var(--ui-layer-accent);\n    }\n\n    :host([type='contained']) .scroll:hover {\n        background-color: var(--ui-layer-accent-hover);\n    }\n\n    :host([type='contained']) .scroll:active {\n        background-color: var(--ui-layer-accent-active);\n    }\n\n    :host([type='contained']) .end {\n        border-bottom: none;\n    }\n\n    /* --ui-tabs-contained-*: Carbon's strip runs full width; a design can draw a track that hugs the tabs */\n    :host([type='contained']) .tablist {\n        flex: var(--ui-tabs-contained-flex, 1);\n        column-gap: var(--ui-tabs-contained-gap, 0);\n        padding: var(--ui-tabs-contained-padding, 0);\n        border-radius: var(--ui-tabs-contained-radius, 0);\n        background-color: var(--ui-tabs-contained-track, transparent);\n    }\n\n    :host([type='contained']) .strip {\n        box-shadow: none; /* no line under contained tabs */\n    }\n\n    /* Carbon dismissable: the close button's box after each tab leaves 1px between contained tabs too */\n    :host([type='contained'][dismissable]:not([vertical])) .tablist {\n        column-gap: 1px;\n    }\n\n    :host([type='contained'][full-width]) .tablist {\n        display: grid;\n        grid-auto-columns: minmax(0, 1fr);\n        grid-auto-flow: column;\n    }\n\n    /* vertical below md: contained tabs in a row (Carbon), 48px unless sized */\n    :host([vertical]) {\n        --_tab-h: 48px;\n    }\n\n    :host([vertical]) .tablist {\n        column-gap: 0;\n    }\n\n    :host([vertical][size='sm']) {\n        --_tab-h: 32px;\n    }\n\n    :host([vertical][size='md']) {\n        --_tab-h: 40px;\n    }\n\n    /*\n     * Vertical (Carbon TabsVertical: a CSS grid): the tab list over 2 of 8 columns (4 of 16 from lg) on the layer\n     * with a border-subtle edge, the panels over the rest on the layer, 64px tabs (xl) unless sized.\n     */\n    :host([data-wide]) {\n        --_tab-h: 64px;\n    }\n\n    :host([data-wide][size='sm']) {\n        --_tab-h: 32px;\n        --_tab-lines: 1;\n    }\n\n    :host([data-wide][size='md']) {\n        --_tab-h: 40px;\n    }\n\n    :host([data-wide][size='lg']) {\n        --_tab-h: 48px;\n    }\n\n    .vgrid {\n        --_cols: 8;\n        --_margin: 16px;\n\n        display: grid;\n        grid-template-columns: repeat(var(--_cols), minmax(0, 1fr));\n        grid-template-rows: minmax(0, 1fr); /* fills a set height, so the tab list and the panels scroll in it */\n        box-sizing: border-box;\n        inline-size: 100%;\n        max-inline-size: 1584px;\n        margin-inline: auto;\n        padding-inline: var(--_margin);\n    }\n\n    .vlist {\n        position: relative;\n        display: flex;\n        grid-column: span 2;\n        min-block-size: 0;\n        background-color: var(--ui-tab-vertical-background, var(--ui-surface-1)); /* the tabs' own setting (tab.ts) */\n        box-shadow: inset -1px 0 var(--ui-hairline);\n    }\n\n    .vlist .tablist {\n        flex-direction: column;\n        column-gap: 0;\n        overflow: hidden auto;\n    }\n\n    .gradient {\n        position: absolute;\n        inset-inline: 0;\n        block-size: var(--ui-space-xxl);\n        pointer-events: none;\n    }\n\n    .gradient.top {\n        inset-block-start: 0;\n        background: linear-gradient(to top, transparent, var(--ui-tab-vertical-background, var(--ui-surface-1)));\n    }\n\n    .gradient.bottom {\n        inset-block-end: 0;\n        background: linear-gradient(to bottom, transparent, var(--ui-tab-vertical-background, var(--ui-surface-1)));\n    }\n\n    .vpanels {\n        display: grid;\n        grid-column: 3 / -1;\n        min-block-size: 0;\n        overflow-y: auto;\n        background-color: var(--ui-surface-1);\n    }\n\n    .vpanels ui-layer {\n        display: grid;\n    }\n\n    @media (min-width: 66rem) {\n        .vgrid {\n            --_cols: 16;\n        }\n\n        .vlist {\n            grid-column: span 4;\n        }\n\n        .vpanels {\n            grid-column: 5 / -1;\n        }\n    }\n\n    @media (min-width: 99rem) {\n        .vgrid {\n            --_margin: 24px;\n        }\n    }\n`;\n"
    },
    {
      "path": "src/primitives/tabs/tabs.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/tabs/tabs.ts",
      "content": "// Its child elements are one per file beside it; this module re-exports them (one entry point).\nimport { html, nothing } from 'lit';\nimport { customElement, property, state, query, queryAssignedElements } from 'lit/decorators.js';\nimport { styleMap } from 'lit/directives/style-map.js';\nimport { setManagedAttribute } from '../shared/field.ts';\nimport { UiElement } from '../shared/element.ts';\nimport { rovingTarget } from '../../core/roving.ts';\nimport { parentLevel } from '../layer/layer.ts';\nimport type { UiTab } from './tab.ts';\nimport type { UiTabPanel } from './tab-panel.ts';\nimport '../tooltip/tooltip.ts';\nimport { tabsStyles } from './tabs.styles.ts';\nexport * from './tab.ts';\nexport * from './tab-panel.ts';\n\n/** Carbon VERTICAL_TABS_BREAKPOINT: vertical tabs from just above md (42rem); below, contained tabs in a row. */\nexport const VERTICAL_TABS_QUERY = '(min-width: 42.01rem)';\n\n/** Carbon Tabs `activation`; `auto` is the pre-0.9 spelling, still accepted. */\nexport type TabsActivation = 'automatic' | 'manual' | 'auto';\n\n/** Carbon tab styles: `line` (default) or `contained` (cds-tabs `type=\"contained\"`, React `contained`). */\nexport type TabsType = 'line' | 'contained';\n\n/** Carbon tab heights: sm 32px, md 40px (line default), lg 48px (contained default), xl 64px (contained only). */\nexport type TabsSize = 'sm' | 'md' | 'lg' | 'xl';\n\nconst chevron = (d: string) => html`<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=${d} /></svg>`;\n\n/**\n * Carbon tabs: `line` (default; Carbon's product tabs) or\n * `type=\"contained\"` — 48px tabs on layer-accent with dividers, the selected one on the layer with a\n * blue top edge, and panels on the layer padded 16px; `full-width` splits the strip into equal columns.\n *\n * Keyboard (WAI-ARIA APG): Left/Right move with wrap, Home/End jump to the first/last tab.\n * `activation=\"automatic\"` (default; `auto` still works) selects as focus moves; `activation=\"manual\"` only moves\n * focus and selects on Enter/Space — use it when panels are slow to render.\n *\n * When tabs overflow, previous/next buttons scroll the strip for mouse users (keyboard\n * users have the arrow keys, so the buttons are skipped by Tab and hidden from AT).\n *\n * `dismissable` (Carbon `Tabs dismissable`): every tab gets a close button, and Delete closes the\n * focused tab. The tab fires a cancelable `ui-request-close`; unless prevented it is hidden (still\n * in the DOM, so a framework can drop it from its own state) and fires `ui-close`. A closed selected\n * tab passes the selection to the first enabled tab (`ui-tab-change`); focus moves to the tab now in\n * its place, else the one before it (Carbon). Not with `vertical`.\n *\n * @slot nav - `<ui-tab>` elements (assigned automatically)\n * @slot - `<ui-tab-panel>` elements\n * @slot end - Content at the end of the strip, e.g. an action button\n * @fires ui-tab-before-change - Cancelable; detail: { name, previous }. preventDefault() keeps\n *   the current tab (e.g. unsaved changes).\n * @fires ui-tab-change - detail: { name } after the user selects a tab\n * @fires ui-request-close - From a `<ui-tab>` of dismissable tabs (close button or Delete); cancelable;\n *   detail: { name }. preventDefault() keeps the tab.\n * @fires ui-close - From a `<ui-tab>` after it closed (hidden); detail: { name }\n * @csspart base - The strip holding the tab list and scroll buttons\n * @csspart tablist - The role=tablist container (tabs themselves are light-DOM `<ui-tab>`s: style the element)\n * @csspart scroll-button - The overflow scroll buttons\n * @csspart end - Wrapper of the `end` slot\n * @cssprop --ui-tabs-track - `box-shadow` of the tab strip, for one line under every tab (default none; Kanok: a 1px hairline)\n * @cssprop --ui-tabs-gap - Gap between line tabs (default 1px; Kanok: 4px)\n * @cssprop --ui-tabs-contained-height - Tab height of `type=\"contained\"` (default 48px; Kanok: 32px)\n * @cssprop --ui-tabs-contained-track / --ui-tabs-contained-padding / --ui-tabs-contained-radius / --ui-tabs-contained-gap - The track behind contained tabs (default none: Carbon's full-width strip; Kanok: a grey rounded track)\n * @cssprop --ui-tabs-contained-flex - `flex` of the contained strip (default 1, full width; Kanok: hugs the tabs)\n * @cssprop --ui-tab-vertical-background - The vertical tab list's fill (default the layer; on `<ui-tab>` with the other --ui-tab-vertical-* settings)\n */\n@customElement('ui-tabs')\nexport class UiTabs extends UiElement {\n    static override readonly styles = tabsStyles;\n\n    /** Name of the active panel. Defaults to the first enabled tab. */\n    @property({ reflect: true }) value = '';\n\n    /** Accessible name for the tab strip, e.g. \"Product details\". */\n    @property() label = '';\n\n    /** `automatic` (Carbon's name; `auto` is still accepted) or `manual`. */\n    @property({ reflect: true }) activation: TabsActivation = 'automatic';\n\n    /** `line` (default) or `contained` (Carbon cds-tabs `type=\"contained\"`). */\n    @property({ reflect: true }) type: TabsType = 'line';\n\n    /** Tab height (Carbon `size`): sm 32px, md 40px, lg 48px, xl 64px (contained only); unset = md for line, lg for contained. */\n    @property({ reflect: true }) size?: TabsSize;\n\n    /** With `type=\"contained\"`: the tabs share the full width in equal columns (Carbon `full-width` / `fullWidth`). */\n    @property({ type: Boolean, reflect: true, attribute: 'full-width' }) fullWidth = false;\n\n    /** Carbon `TabsVertical`: the tabs in a column beside the panels from md up (contained tabs in a row below). */\n    @property({ type: Boolean, reflect: true }) vertical = false;\n\n    /** A fixed height for vertical tabs (Carbon `height`), e.g. `\"400px\"`: the tab list and the panels then scroll. */\n    @property() height = '';\n\n    /** A close button on every tab, and Delete closes the focused tab (Carbon `dismissable`); not with `vertical`. */\n    @property({ type: Boolean, reflect: true }) dismissable = false;\n\n    /** Vertical and at least md wide: laid out as a column. */\n    @state() private wide = false;\n\n    @state() private canScrollUp = false;\n\n    @state() private canScrollDown = false;\n\n    private media?: MediaQueryList;\n\n    private readonly onMedia = () => {\n        this.wide = !!this.media?.matches;\n    };\n\n    @state() private canScrollStart = false;\n\n    @state() private canScrollEnd = false;\n\n    @query('.tablist') private readonly tablist!: HTMLElement;\n\n    private resizeObserver?: ResizeObserver;\n\n    /** Created on connect (not at construction, so server rendering has no ResizeObserver to need); re-observed after a move. */\n    private observeSize() {\n        this.resizeObserver ??= new ResizeObserver(() => this.updateOverflow());\n        this.resizeObserver.observe(this.tablist);\n    }\n\n    override connectedCallback() {\n        super.connectedCallback();\n        if (this.hasUpdated) this.observeSize();\n        this.media = globalThis.matchMedia?.(VERTICAL_TABS_QUERY);\n        this.media?.addEventListener('change', this.onMedia);\n        this.onMedia();\n    }\n\n    override firstUpdated() {\n        this.observeSize();\n    }\n\n    override disconnectedCallback() {\n        super.disconnectedCallback();\n        this.resizeObserver?.disconnect();\n        this.media?.removeEventListener('change', this.onMedia);\n    }\n\n    private get columnLayout() {\n        return this.vertical && this.wide;\n    }\n\n    @queryAssignedElements({ slot: 'nav', selector: 'ui-tab' }) private readonly tabs!: UiTab[];\n\n    @queryAssignedElements({ selector: 'ui-tab-panel' }) private readonly panels!: UiTabPanel[];\n\n    protected override updated(changed: Map<string, unknown>) {\n        this.toggleAttribute('data-wide', this.columnLayout);\n        // the tab list is rendered anew when the layout changes\n        if (changed.has('wide') || changed.has('vertical')) this.observeSize();\n        this.sync();\n    }\n\n    /** The tabs that aren't closed. */\n    private shownTabs() {\n        return this.tabs.filter((t) => !t.hidden);\n    }\n\n    private enabledTabs() {\n        return this.shownTabs().filter((t) => !t.disabled);\n    }\n\n    private get closable() {\n        return this.dismissable && !this.vertical;\n    }\n\n    private sync() {\n        if (!this.tabs.length) return;\n        const tabs = this.shownTabs();\n        const active = tabs.find((t) => t.panel === this.value && !t.disabled) ?? this.enabledTabs()[0];\n        if (active && active.panel !== this.value) {\n            this.value = active.panel;\n            return;\n        }\n        const column = this.columnLayout;\n        const contained = !column && (this.type === 'contained' || this.vertical);\n        // Carbon tabs--tall: a secondary label on any contained tab makes them all 64px\n        const tall = contained && tabs.some((t) => t.secondaryLabel);\n        const closable = this.closable;\n        // the roving tab stop stays on a focused tab (manual activation, or after a close), else the selected one\n        const stop = tabs.find((t) => !t.disabled && t.matches(':focus')) ?? active;\n        for (const tab of this.tabs) {\n            tab.tabIndex = tab === stop ? 0 : -1;\n            // a closed (hidden) tab is no longer the selected one\n            if (tab.hidden) tab.selected = false;\n        }\n        tabs.forEach((tab, i) => {\n            const panel = this.panels.find((p) => p.name === tab.panel);\n            tab.selected = tab === active;\n            tab.toggleAttribute('data-contained', contained);\n            tab.toggleAttribute('data-vertical', column);\n            tab.toggleAttribute('data-full-width', contained && this.fullWidth);\n            tab.toggleAttribute('data-tall', tall);\n            tab.toggleAttribute('data-dismissable', closable);\n            tab.toggleAttribute('data-first', i === 0);\n            tab.toggleAttribute('data-after-selected', i > 0 && tabs[i - 1] === active);\n            // the close button is hidden from assistive tech: the tab tells its shortcut instead\n            setManagedAttribute(tab, 'aria-keyshortcuts', closable && !tab.disabled ? 'Delete' : null);\n            if (panel) {\n                tab.setAttribute('aria-controls', panel.id);\n                panel.setAttribute('aria-labelledby', tab.id);\n            }\n        });\n        // with every tab closed no panel shows\n        const shown = tabs.length ? this.value : null;\n        for (const panel of this.panels) {\n            panel.hidden = panel.name !== shown;\n            panel.toggleAttribute('data-contained', contained);\n            panel.toggleAttribute('data-vertical', column);\n        }\n    }\n\n    /**\n     * Carbon dismissable: asks the tab to close (`ui-request-close`); unless prevented it is hidden and\n     * fires `ui-close`, the first enabled tab takes over a closed selection, and focus goes to the tab\n     * now in its place, else the one before (Carbon React; a kept tab keeps focus).\n     */\n    private async closeTab(tab: UiTab) {\n        if (tab.disabled) return;\n        const detail = { name: tab.panel };\n        const request = new CustomEvent('ui-request-close', { detail, bubbles: true, composed: true, cancelable: true });\n        if (!tab.dispatchEvent(request)) {\n            this.focusTab(tab);\n            return;\n        }\n        const before = this.shownTabs();\n        const index = before.indexOf(tab);\n        tab.hidden = true;\n        delete tab.dataset.closeHover;\n        tab.dispatchEvent(new CustomEvent('ui-close', { detail, bubbles: true, composed: true }));\n        // unless a listener chose another tab\n        const first = this.value === detail.name ? this.enabledTabs()[0] : undefined;\n        if (first) this.value = first.panel;\n        this.requestUpdate();\n        await this.updateComplete;\n        if (first) this.dispatchEvent(new CustomEvent('ui-tab-change', { detail: { name: first.panel }, bubbles: true, composed: true }));\n        const rest = before.filter((t) => t !== tab && !t.disabled);\n        const next = rest.find((t) => before.indexOf(t) > index) ?? rest.findLast((t) => before.indexOf(t) < index);\n        if (next) this.focusTab(next);\n    }\n\n    /** Move focus (and the roving tab stop) without selecting. */\n    private focusTab(tab: UiTab) {\n        for (const t of this.tabs) t.tabIndex = t === tab ? 0 : -1;\n        tab.focus();\n        tab.scrollIntoView({ block: 'nearest', inline: 'nearest' });\n        this.updateOverflow();\n    }\n\n    private select(tab: UiTab) {\n        if (tab.disabled || tab.panel === this.value) return;\n        const before = new CustomEvent('ui-tab-before-change', {\n            detail: { name: tab.panel, previous: this.value },\n            bubbles: true,\n            composed: true,\n            cancelable: true,\n        });\n        if (!this.dispatchEvent(before)) return;\n        this.value = tab.panel;\n        this.dispatchEvent(new CustomEvent('ui-tab-change', { detail: { name: tab.panel }, bubbles: true, composed: true }));\n    }\n\n    private onClick(event: MouseEvent) {\n        const tab = (event.target as Element).closest('ui-tab');\n        if (!tab || tab.disabled) return;\n        // the close button inside the tab closes it without selecting it\n        if (event.composedPath().some((node) => node instanceof Element && node.classList.contains('close') && tab.shadowRoot?.contains(node))) {\n            if (this.closable) void this.closeTab(tab);\n            return;\n        }\n        this.focusTab(tab);\n        this.select(tab);\n    }\n\n    private nextTab(current: UiTab, key: string) {\n        const tabs = this.enabledTabs();\n        const i = tabs.indexOf(current);\n        const next = rovingTarget(tabs.length, i, key, { rtl: getComputedStyle(this).direction === 'rtl', orientation: this.columnLayout ? 'vertical' : 'horizontal' });\n        return next === undefined ? undefined : tabs[next];\n    }\n\n    private onKeydown(event: KeyboardEvent) {\n        const current = (event.target as Element).closest('ui-tab');\n        if (!current || !this.enabledTabs().length) return;\n        if (event.key === 'Enter' || event.key === ' ') {\n            event.preventDefault();\n            this.select(current);\n            return;\n        }\n        // Carbon: Delete closes the focused tab of dismissable tabs\n        if (event.key === 'Delete' && this.closable) {\n            event.preventDefault();\n            void this.closeTab(current);\n            return;\n        }\n        const next = this.nextTab(current, event.key);\n        if (!next) return;\n        event.preventDefault();\n        this.focusTab(next);\n        if (this.activation !== 'manual') this.select(next);\n    }\n\n    private updateOverflow() {\n        const el = this.tablist;\n        if (!el) return;\n        if (this.columnLayout) {\n            // Carbon: a gradient where more tabs are hidden, once half a tab (32px) is out of view\n            this.canScrollUp = el.scrollTop > 32;\n            this.canScrollDown = el.scrollTop + el.clientHeight + 32 <= el.scrollHeight;\n            return;\n        }\n        // scrollLeft is negative in RTL, so measure distance from the start edge\n        const fromStart = Math.abs(el.scrollLeft);\n        this.canScrollStart = fromStart > 1;\n        this.canScrollEnd = fromStart + el.clientWidth < el.scrollWidth - 1;\n    }\n\n    private scrollStrip(direction: 1 | -1) {\n        const el = this.tablist;\n        const rtl = getComputedStyle(this).direction === 'rtl' ? -1 : 1;\n        const smooth = matchMedia('(prefers-reduced-motion: no-preference)').matches;\n        el.scrollBy({ left: direction * rtl * el.clientWidth * 0.8, behavior: smooth ? 'smooth' : 'auto' });\n    }\n\n    /** Focus the active tab (the tablist's tab stop). */\n    override focus(options?: FocusOptions) {\n        const tabs = this.shownTabs();\n        (tabs.find((t) => t.tabIndex === 0) ?? tabs[0])?.focus(options);\n    }\n\n    private renderTablist() {\n        return html`<div\n            class=\"tablist\"\n            part=\"tablist\"\n            role=\"tablist\"\n            aria-label=${this.label || nothing}\n            aria-orientation=${this.columnLayout ? 'vertical' : nothing}\n            @click=${this.onClick}\n            @keydown=${this.onKeydown}\n            @scroll=${this.updateOverflow}\n        >\n            <slot name=\"nav\" @slotchange=${() => this.sync()}></slot>\n        </div>`;\n    }\n\n    /** Vertical from md up: the tab list beside the panels in a Carbon grid; the panels a layer up for their fields (Carbon update_fields_on_layer). */\n    private renderColumns() {\n        const level = Math.min(Math.max(parentLevel(this), 0) + 1, 2);\n        return html`<div class=\"vgrid\" part=\"base\" style=${styleMap({ height: this.height || undefined })}>\n            <div class=\"vlist\">\n                ${this.renderTablist()}\n                ${this.canScrollUp ? html`<div class=\"gradient top\" aria-hidden=\"true\"></div>` : nothing}\n                ${this.canScrollDown ? html`<div class=\"gradient bottom\" aria-hidden=\"true\"></div>` : nothing}\n            </div>\n            <div class=\"vpanels\" part=\"panels\">\n                <ui-layer .level=${level}><slot @slotchange=${() => this.sync()}></slot></ui-layer>\n            </div>\n        </div>`;\n    }\n\n    override render() {\n        if (this.columnLayout) return this.renderColumns();\n        return html`\n            <div class=\"strip\" part=\"base\">\n                <button\n                    class=\"scroll\"\n                    part=\"scroll-button\"\n                    type=\"button\"\n                    tabindex=\"-1\"\n                    aria-hidden=\"true\"\n                    ?hidden=${!this.canScrollStart}\n                    @click=${() => this.scrollStrip(-1)}\n                >\n                    ${chevron('m5 8 5-5 .7.7L6.4 8l4.3 4.3-.7.7z')}\n                </button>\n                ${this.renderTablist()}\n                <button\n                    class=\"scroll\"\n                    part=\"scroll-button\"\n                    type=\"button\"\n                    tabindex=\"-1\"\n                    aria-hidden=\"true\"\n                    ?hidden=${!this.canScrollEnd}\n                    @click=${() => this.scrollStrip(1)}\n                >\n                    ${chevron('m11 8-5 5-.7-.7L9.6 8 5.3 3.7 6 3z')}\n                </button>\n                <div class=\"end\" part=\"end\"><slot name=\"end\"></slot></div>\n            </div>\n            <slot @slotchange=${() => this.sync()}></slot>\n        `;\n    }\n}\n\nexport interface TabChangeDetail {\n    name: string;\n}\n\nexport interface TabBeforeChangeDetail {\n    name: string;\n    previous: string;\n}\n\n/** `name` = the closing tab's `panel`. */\nexport interface TabCloseDetail {\n    name: string;\n}\n\nexport interface UiTabsEventMap extends HTMLElementEventMap {\n    'ui-tab-change': CustomEvent<TabChangeDetail>;\n    'ui-tab-before-change': CustomEvent<TabBeforeChangeDetail>;\n    /** Bubbles from the `<ui-tab>` of dismissable tabs. */\n    'ui-request-close': CustomEvent<TabCloseDetail>;\n    'ui-close': CustomEvent<TabCloseDetail>;\n}\n\n/** Typed listeners for UiTabs's events (declaration merging with the class). */\nexport interface UiTabs {\n    addEventListener<K extends keyof UiTabsEventMap>(type: K, listener: (this: UiTabs, event: UiTabsEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;\n    addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;\n    removeEventListener<K extends keyof UiTabsEventMap>(type: K, listener: (this: UiTabs, event: UiTabsEventMap[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-tabs': UiTabs;\n    }\n}\n"
    }
  ]
}
