{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "breadcrumb",
  "type": "registry:ui",
  "title": "<ui-breadcrumb>",
  "description": "Carbon `Breadcrumb`: a `<nav aria-label=\"Breadcrumb\">` holding an ordered list of `<ui-breadcrumb-item>`s separated by slashes. `no-trailing-slash` drops the slash after the last item; `size=\"sm\"` uses label-01 type. 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-overflow",
    "@kanok-ui/menu",
    "@kanok-ui/overflow-menu",
    "@kanok-ui/shared-element",
    "@kanok-ui/shared-localize",
    "@kanok-ui/shared-navigate",
    "@kanok-ui/shared-skeleton",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/breadcrumb/breadcrumb-item.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/breadcrumb/breadcrumb-item.ts",
      "content": "import { LitElement, css, html, nothing, type CSSResultGroup } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { UiElement } from '../shared/element.ts';\nimport { followLink } from '../shared/navigate.ts';\n\n/**\n * Carbon `BreadcrumbItem`: a link in the trail, or the current page (`current`, rendered as text with\n * `aria-current=\"page\"`). Place inside `<ui-breadcrumb>`.\n *\n * @slot - The item text\n * @csspart base - The link or the current-page text\n * @fires ui-navigate - detail: { href } (cancelable) on a plain click of the link; cancel it to route client-side (README: SPA router)\n * @cssprop --ui-breadcrumb-trailing-slash - `display` of the slash after the last item (default inline; Kanok: none)\n */\n@customElement('ui-breadcrumb-item')\nexport class UiBreadcrumbItem extends UiElement {\n    /** `el.focus()` lands on the control inside. */\n    static override readonly shadowRootOptions: ShadowRootInit = { ...LitElement.shadowRootOptions, delegatesFocus: true };\n\n    static override readonly styles: CSSResultGroup = css`\n        :host {\n            display: inline-flex;\n            align-items: center;\n            font-family: var(--ui-font-family);\n            font: var(--ui-font-body-sm);\n            letter-spacing: var(--ui-tracking-body);\n        }\n\n        :host([data-size='sm']) {\n            font: var(--ui-font-caption);\n            letter-spacing: var(--ui-tracking-caption);\n        }\n\n        /* gone into the trail's overflow menu */\n        :host([data-hidden]) {\n            display: none;\n        }\n\n        /*\n         * Carbon: a \"/\" after every item (the last one too, unless the trail has no-trailing-slash). Drawn\n         * by a part, not :host::after, so a page-wide CSS reset can't take its spacing; the 8px after\n         * the item is the trail's gap.\n         */\n        .slash::after {\n            content: '/';\n            margin-inline-start: var(--ui-space-xs);\n            color: var(--ui-ink);\n        }\n\n        :host([data-size='sm']) .slash::after {\n            margin-inline-start: var(--ui-space-xxs);\n        }\n\n        /* Carbon keeps the last item's slash; a design can drop it (--ui-breadcrumb-trailing-slash: none) */\n        :host([data-last]) .slash {\n            display: var(--ui-breadcrumb-trailing-slash, inline);\n        }\n\n        :host([data-last][data-no-trailing-slash]) .slash {\n            display: none;\n        }\n\n        a {\n            color: var(--ui-link);\n            text-decoration: none;\n            outline: var(--ui-focus-width, 2px) solid transparent;\n            outline-offset: 1px;\n            border-radius: var(--ui-link-focus-radius, 0); /* the ring's corners, as a link's (Kanok: 4px) */\n            transition: color var(--ui-duration-fast) var(--ui-easing);\n        }\n\n        /* Carbon .breadcrumb .link: one line */\n        a,\n        .current {\n            white-space: nowrap;\n        }\n\n        a:visited {\n            color: var(--ui-link);\n        }\n\n        a:hover,\n        a:visited:hover {\n            color: var(--ui-link-hover);\n            text-decoration: underline;\n        }\n\n        a:active {\n            color: var(--ui-ink);\n        }\n\n        a:focus-visible {\n            outline-color: var(--ui-focus);\n        }\n\n        .current {\n            color: var(--ui-ink);\n        }\n\n        @media (forced-colors: active) {\n            a:focus-visible {\n                outline: 2px solid Highlight;\n            }\n\n            :host([current]) a,\n            .slash::after {\n                color: CanvasText;\n            }\n        }\n\n    `;\n\n    @property() href = '';\n    /** The page the user is on: plain text with `aria-current=\"page\"`. */\n    @property({ type: Boolean, reflect: true }) current = false;\n\n    override render() {\n        if (this.current || !this.href) {\n            return html`<span class=\"current\" part=\"base\" aria-current=${this.current ? 'page' : nothing}><slot></slot></span><span class=\"slash\"></span>`;\n        }\n        // tabindex: as Carbon's cds-breadcrumb-link, so Safari focuses it on click and Tab reaches it\n        return html`<a part=\"base\" href=${this.href} tabindex=\"0\" @click=${followLink}><slot></slot></a><span class=\"slash\"></span>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-breadcrumb-item': UiBreadcrumbItem;\n    }\n}\n"
    },
    {
      "path": "src/primitives/breadcrumb/breadcrumb-skeleton.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/breadcrumb/breadcrumb-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 `BreadcrumbSkeleton` (`cds-breadcrumb-skeleton`): `items` bars of 100×16, each followed by the trail's \"/\"\n * (not after the last with `no-trailing-slash`). Hidden from assistive tech.\n *\n * @csspart item - Each bar\n */\n@customElement('ui-breadcrumb-skeleton')\nexport class UiBreadcrumbSkeleton extends UiSkeletonElement {\n    static override readonly styles = [\n        skeletonStyles,\n        css`\n            :host {\n                display: block;\n                font: var(--ui-font-body-sm);\n                letter-spacing: var(--ui-tracking-body);\n            }\n\n            :host([size='sm']) {\n                font: var(--ui-font-caption);\n                letter-spacing: var(--ui-tracking-caption);\n            }\n\n            .trail {\n                display: flex;\n                flex-wrap: wrap;\n                column-gap: var(--ui-space-xs);\n            }\n\n            :host([size='sm']) .trail {\n                column-gap: var(--ui-space-xxs);\n            }\n\n            .item {\n                display: inline-flex;\n                align-items: center;\n                line-height: 18px;\n            }\n\n            .bone {\n                inline-size: 100px;\n                block-size: 16px;\n            }\n\n            .item::after {\n                content: '/';\n                margin-inline-start: var(--ui-space-xs);\n                color: var(--ui-ink);\n            }\n\n            :host([size='sm']) .item::after {\n                margin-inline-start: var(--ui-space-xxs);\n            }\n\n            :host([no-trailing-slash]) .item:last-child::after {\n                content: none;\n            }\n        `,\n    ];\n\n    @property({ type: Number }) items = 3;\n\n    @property({ type: Boolean, reflect: true, attribute: 'no-trailing-slash' }) noTrailingSlash = false;\n\n    @property({ reflect: true }) size: 'sm' | 'md' = 'md';\n\n    override render() {\n        const item = html`<span class=\"item\"><span class=\"bone\" part=\"item\"></span></span>`;\n        return html`<div class=\"trail\">${Array.from({ length: Math.max(1, this.items) }, () => item)}</div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-breadcrumb-skeleton': UiBreadcrumbSkeleton;\n    }\n}\n"
    },
    {
      "path": "src/primitives/breadcrumb/breadcrumb.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/breadcrumb/breadcrumb.ts",
      "content": "// Its child elements are one per file beside it; this module re-exports them (one entry point).\nimport { svg, css, html, nothing } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { LocalizeController } from '../shared/localize.ts';\nimport { UiElement } from '../shared/element.ts';\nimport { visibleCount } from '../../core/overflow.ts';\nimport { UiBreadcrumbItem } from './breadcrumb-item.ts';\nimport '../overflow-menu/overflow-menu.ts';\nimport '../menu/menu.ts';\nexport * from './breadcrumb-item.ts';\n\n/** Carbon's OverflowMenuHorizontal (16px), the \"…\" of a collapsed trail. */\nconst moreIcon = svg`<svg slot=\"icon\" viewBox=\"0 0 32 32\" aria-hidden=\"true\"><circle cx=\"8\" cy=\"16\" r=\"2\"></circle><circle cx=\"16\" cy=\"16\" r=\"2\"></circle><circle cx=\"24\" cy=\"16\" r=\"2\"></circle></svg>`;\n\nexport type BreadcrumbSize = 'sm' | 'md';\n\n/**\n * Carbon `Breadcrumb`: a `<nav aria-label=\"Breadcrumb\">` holding an ordered list of\n * `<ui-breadcrumb-item>`s separated by slashes. `no-trailing-slash` drops the slash after the\n * last item; `size=\"sm\"` uses label-01 type.\n *\n * `overflow` (Carbon for IBM Products' page header breadcrumbs): on one line, the crumbs that don't fit go — from the\n * end, the first ones stay — into a \"…\" overflow menu just before the last crumb (the page, which always stays);\n * choosing one follows its link. The last crumb is given `slot=\"end\"` for that.\n *\n * @cssprop --ui-breadcrumb-wrap - `nowrap` keeps the trail on one line (the page header's bar does)\n * @slot - `<ui-breadcrumb-item>` elements\n * @csspart base - The `<nav>`\n * @csspart list - The `<ol>`\n * @csspart overflow - The \"…\" item holding the overflow menu (`overflow` only)\n */\n@customElement('ui-breadcrumb')\nexport class UiBreadcrumb extends UiElement {\n    static override readonly styles = css`\n        :host {\n            display: block;\n            font-family: var(--ui-font-family);\n        }\n\n        /* the space after each item (Carbon margin-inline-end), as a gap: a page-wide CSS reset would remove a margin on the items */\n        ol {\n            display: inline-flex;\n            flex-wrap: var(--ui-breadcrumb-wrap, wrap);\n            max-inline-size: 100%;\n            align-items: center;\n            column-gap: var(--ui-space-xs);\n            margin: 0;\n            padding: 0;\n            list-style: none;\n        }\n\n        :host([size='sm']) ol {\n            column-gap: var(--ui-space-xxs);\n        }\n\n        :host([overflow]) ol {\n            flex-wrap: nowrap;\n        }\n\n        .more {\n            display: inline-flex;\n            flex: none;\n            align-items: center;\n            font: var(--ui-font-body-sm);\n            letter-spacing: var(--ui-tracking-body);\n        }\n\n        :host([size='sm']) .more {\n            font: var(--ui-font-caption);\n            letter-spacing: var(--ui-tracking-caption);\n        }\n\n        .more[hidden] {\n            display: none;\n        }\n\n        .more::after {\n            content: '/';\n            margin-inline-start: var(--ui-space-xs);\n            color: var(--ui-ink);\n        }\n\n        :host([size='sm']) .more::after {\n            margin-inline-start: var(--ui-space-xxs);\n        }\n\n        /* Carbon breadcrumb-item overflow menu: a 16 × 18 link-coloured \"…\", a 12px line under it on hover / focus */\n        ui-overflow-menu::part(trigger) {\n            position: relative;\n            inline-size: 16px;\n            block-size: 18px;\n            background-color: transparent;\n            box-shadow: none;\n            color: var(--ui-link);\n        }\n\n        :host([size='sm']) ui-overflow-menu::part(trigger) {\n            block-size: 16px;\n        }\n\n        ui-overflow-menu::part(trigger):hover {\n            color: var(--ui-link-hover);\n        }\n\n        ui-overflow-menu::part(trigger):active {\n            color: var(--ui-icon-primary);\n        }\n\n        ui-overflow-menu::part(trigger):focus-visible {\n            outline: 1px solid var(--ui-focus);\n            outline-offset: 0;\n        }\n\n        ui-overflow-menu::part(trigger)::after {\n            content: '';\n            position: absolute;\n            inset-block-end: 2px;\n            inset-inline-start: 0;\n            inline-size: 12px;\n            block-size: 1px;\n            background: var(--ui-focus);\n            opacity: 0;\n            transition: opacity var(--ui-duration-fast) var(--ui-easing);\n        }\n\n        ui-overflow-menu::part(trigger):hover::after {\n            background: var(--ui-link-hover);\n            opacity: 1;\n        }\n\n        ui-overflow-menu::part(trigger):focus-visible::after {\n            opacity: 1;\n        }\n\n        ui-overflow-menu::part(trigger):active::after {\n            background: var(--ui-ink);\n        }\n\n        @media (prefers-reduced-motion: reduce) {\n            ui-overflow-menu::part(trigger)::after {\n                transition: none;\n            }\n        }\n\n        @media (forced-colors: active) {\n            .more::after {\n                color: CanvasText;\n            }\n        }\n    `;\n\n    /** Accessible name of the navigation landmark. */\n    @property() label = '';\n\n    private readonly localize = new LocalizeController(this);\n    @property({ type: Boolean, reflect: true, attribute: 'no-trailing-slash' }) noTrailingSlash = false;\n    @property({ reflect: true }) size: BreadcrumbSize = 'md';\n\n    /** On one line, the crumbs that don't fit go into a \"…\" menu before the last one. */\n    @property({ type: Boolean, reflect: true }) overflow = false;\n\n    /** The overflow menu's name (default: the translation's \"More breadcrumbs\"). */\n    @property({ attribute: 'overflow-label' }) overflowLabel = '';\n\n    /** The crumbs in the overflow menu. */\n    @state() private collapsed: UiBreadcrumbItem[] = [];\n\n    private observer?: ResizeObserver;\n    private frame = 0;\n\n    override disconnectedCallback() {\n        super.disconnectedCallback();\n        this.stopWatching();\n    }\n\n    protected override updated(changed: Map<string, unknown>) {\n        this.sync();\n        if (changed.has('overflow')) {\n            this.stopWatching();\n            if (this.overflow) {\n                this.observer = new ResizeObserver(this.schedule);\n                this.observer.observe(this);\n            }\n            this.schedule();\n        }\n    }\n\n    private stopWatching() {\n        this.observer?.disconnect();\n        this.observer = undefined;\n        cancelAnimationFrame(this.frame);\n    }\n\n    /** ui-breadcrumb-item and the elements built on it (the page header's title crumb). */\n    private get items() {\n        return [...this.children].filter((el): el is UiBreadcrumbItem => el instanceof UiBreadcrumbItem);\n    }\n\n    private sync() {\n        const items = this.items;\n        items.forEach((item, i) => {\n            item.dataset.size = this.size;\n            item.toggleAttribute('data-last', i === items.length - 1);\n            item.toggleAttribute('data-no-trailing-slash', this.noTrailingSlash);\n            // each item is a list item of the trail, outside this shadow root\n            item.setAttribute('role', 'listitem');\n            // with overflow, the last crumb goes after the \"…\" (its own slot); the attribute is ours to set and take\n            const end = this.overflow && items.length > 1 && i === items.length - 1;\n            if (end) item.slot = 'end';\n            else if (item.slot === 'end') item.removeAttribute('slot');\n            if (!this.overflow) delete item.dataset.hidden;\n        });\n        if (!this.overflow && this.collapsed.length) this.collapsed = [];\n    }\n\n    private readonly schedule = () => {\n        cancelAnimationFrame(this.frame);\n        if (this.overflow) this.frame = requestAnimationFrame(this.measure);\n    };\n\n    /**\n     * Which crumbs fit (core/overflow, as Carbon's createOverflowHandler): every one measured at its natural width;\n     * the last one is kept — up to half the trail, as it shrinks with an ellipsis (the page header's title crumb).\n     */\n    private readonly measure = () => {\n        const items = this.items;\n        const more = this.renderRoot.querySelector<HTMLElement>('.more');\n        if (items.length < 2 || !more) return;\n        const gap = this.size === 'sm' ? 4 : 8;\n        const wasHidden = more.hidden;\n        more.hidden = false;\n        const natural = (el: HTMLElement) => {\n            const shrink = el.style.flexShrink;\n            el.style.flexShrink = '0';\n            const width = el.getBoundingClientRect().width;\n            el.style.flexShrink = shrink;\n            return width;\n        };\n        const sizes = items.slice(0, -1).map((item) => {\n            delete item.dataset.hidden;\n            return natural(item) + gap;\n        });\n        const container = this.clientWidth;\n        const last = Math.min(natural(items.at(-1)!), container / 2);\n        const offset = natural(more) + gap;\n        more.hidden = wasHidden;\n        const count = visibleCount({ container, sizes, fixedSizes: [last], offset, gap, keepFirst: false });\n        const hidden = items.slice(0, -1).filter((item, index) => {\n            item.toggleAttribute('data-hidden', index >= count);\n            return index >= count;\n        });\n        if (hidden.length !== this.collapsed.length || hidden.some((item, i) => item !== this.collapsed[i])) this.collapsed = hidden;\n    };\n\n    /** A crumb chosen in the menu: follow its link. */\n    private readonly onPick = (event: CustomEvent<{ value: string }>) => {\n        const item = this.collapsed[Number(event.detail.value)];\n        item?.shadowRoot?.querySelector<HTMLElement>('a')?.click();\n    };\n\n    /** Focus the first crumb's link. */\n    override focus(options?: FocusOptions) {\n        this.querySelector<HTMLElement>('ui-breadcrumb-item')?.focus(options);\n    }\n\n    override render() {\n        const more = this.overflow\n            ? html`<li class=\"more\" part=\"overflow\" ?hidden=${this.collapsed.length === 0}>\n                  <ui-overflow-menu size=\"sm\" placement=\"bottom-start\" label=${this.overflowLabel || this.localize.t.common.moreBreadcrumbs} @ui-select=${this.onPick}>\n                      ${moreIcon}${this.collapsed.map((item, index) => html`<ui-menu-item label=${item.textContent?.trim() ?? ''} value=${String(index)}></ui-menu-item>`)}\n                  </ui-overflow-menu>\n              </li>`\n            : nothing;\n        const changed = () => {\n            this.sync();\n            this.schedule();\n        };\n        return html`<nav part=\"base\" aria-label=${this.label || this.localize.t.common.breadcrumb}>\n            <ol part=\"list\" role=\"list\"><slot @slotchange=${changed}></slot>${more}<slot name=\"end\" @slotchange=${changed}></slot></ol>\n        </nav>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-breadcrumb': UiBreadcrumb;\n    }\n}\n"
    }
  ]
}
