{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "card",
  "type": "registry:ui",
  "title": "<ui-card>",
  "description": "Carbon `Card` (preview in Carbon, `cds-card`): a `$layer` box — no border, no shadow, square — built from parts: `<ui-card-media>`, `<ui-card-header>` (with `<ui-card-header-media>`, `<ui-card-title-media>`, `<ui-card-title>`, `<ui-card-actions>`), `<ui-card-body>` and `<ui-card-footer>` (with `<ui-card-action>`s). It follows the `<ui-layer>` it sits on. 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-field",
    "@kanok-ui/shared-localize",
    "@kanok-ui/shared-navigate",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/card/card-action.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/card/card-action.ts",
      "content": "import { css, html } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { UiElement } from '../shared/element.ts';\n\n/**\n * One action (Carbon `CardAction`): in the footer a `<ui-button>` stretches to share the row and a\n * `<ui-icon-button>` keeps its size at the end; in `<ui-card-actions>` it is one of the header's buttons.\n *\n * @slot - A `<ui-button>` or `<ui-icon-button>`\n */\n@customElement('ui-card-action')\nexport class UiCardAction extends UiElement {\n    static override readonly styles = css`\n        :host {\n            display: inline-flex;\n            flex: 1 0 0;\n            min-inline-size: 0;\n        }\n\n        :host([data-icon-only]),\n        :host([data-in-header]) {\n            flex: 0 0 auto;\n        }\n\n        :host([data-hidden]) {\n            display: none;\n        }\n\n        .action {\n            display: inline-flex;\n            flex: 1;\n            min-inline-size: 0;\n        }\n\n        :host(:not([data-icon-only], [data-in-header])) ::slotted(ui-button) {\n            display: block;\n            flex: 1;\n            width: 100%;\n        }\n    `;\n\n    /** Its name in the header's overflow menu (else the button's label or text). */\n    @property() label = '';\n\n    private readonly onSlotChange = () => {\n        this.toggleAttribute('data-icon-only', !!this.querySelector(':scope > ui-icon-button'));\n    };\n\n    override connectedCallback() {\n        super.connectedCallback();\n        this.toggleAttribute('data-in-header', this.parentElement?.localName === 'ui-card-actions');\n    }\n\n    override render() {\n        return html`<div class=\"action\" part=\"base\"><slot @slotchange=${this.onSlotChange}></slot></div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-card-action': UiCardAction;\n    }\n}\n"
    },
    {
      "path": "src/primitives/card/card-actions.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/card/card-actions.ts",
      "content": "import { css, html, nothing } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { visibleCount } from '../../core/overflow.ts';\nimport { LocalizeController } from '../shared/localize.ts';\nimport { UiElement } from '../shared/element.ts';\nimport '../overflow-menu/overflow-menu.ts';\nimport '../menu/menu.ts';\n\ninterface ActionItem {\n    action: HTMLElement;\n    label: string;\n}\n\n/** An action's name: its `label`, else its button's label, tooltip or text. */\nfunction actionLabel(action: HTMLElement, index: number) {\n    const button = action.querySelector<HTMLElement>('ui-button, ui-icon-button, button');\n    return action.getAttribute('label') || button?.getAttribute('label') || button?.textContent?.trim() || `Action ${index + 1}`;\n}\n\n/**\n * The header's actions (Carbon `CardActions`): small buttons in the top-end corner, 4px apart, in at most half the\n * header; those that don't fit move to an overflow menu (choosing an item clicks that action's button).\n *\n * @slot - `<ui-card-action>`s, each with a small `<ui-icon-button>` (or `<ui-button size=\"sm\">`)\n */\n@customElement('ui-card-actions')\nexport class UiCardActions extends UiElement {\n    static override readonly styles = css`\n        :host {\n            position: absolute;\n            inset-block-start: var(--ui-space-xs);\n            inset-inline-end: var(--ui-space-xs);\n            inline-size: calc(50% - var(--ui-space-xs));\n            max-inline-size: calc(50% - var(--ui-space-xs));\n        }\n\n        .actions {\n            display: flex;\n            align-items: center;\n            justify-content: flex-end;\n            gap: var(--ui-space-xxs);\n            block-size: 32px;\n        }\n    `;\n\n    /** The overflow menu's name (default: the translation's \"More actions\"). */\n    @property({ attribute: 'overflow-menu-label' }) overflowMenuLabel = '';\n\n    @state() private overflowed: ActionItem[] = [];\n\n    private readonly localize = new LocalizeController(this);\n    private observer?: ResizeObserver;\n    private frame = 0;\n\n    override connectedCallback() {\n        super.connectedCallback();\n        this.observer = new ResizeObserver(this.schedule);\n        this.observer.observe(this);\n        // a click on an action is the action's own, not the card's\n        this.addEventListener('click', this.stop);\n    }\n\n    override disconnectedCallback() {\n        super.disconnectedCallback();\n        this.observer?.disconnect();\n        cancelAnimationFrame(this.frame);\n        this.removeEventListener('click', this.stop);\n    }\n\n    private readonly stop = (event: Event) => event.stopPropagation();\n\n    private readonly schedule = () => {\n        cancelAnimationFrame(this.frame);\n        this.frame = requestAnimationFrame(this.measure);\n    };\n\n    private get actions() {\n        return [...this.children].filter((el): el is HTMLElement => el.localName === 'ui-card-action');\n    }\n\n    /** Which actions fit beside the overflow button (core/overflow, as Carbon's createOverflowHandler). */\n    private readonly measure = () => {\n        const actions = this.actions;\n        const gap = 4;\n        const sizes = actions.map((action) => {\n            const hidden = 'hidden' in action.dataset;\n            delete action.dataset.hidden;\n            const width = action.getBoundingClientRect().width + gap;\n            if (hidden) action.dataset.hidden = '';\n            return width;\n        });\n        const count = visibleCount({ container: this.clientWidth, sizes, offset: 32 + gap, gap });\n        actions.forEach((action, index) => { action.toggleAttribute('data-hidden', index >= count); });\n        const hidden = actions.slice(count).map((action, index) => ({ action, label: actionLabel(action, count + index) }));\n        if (hidden.length !== this.overflowed.length || hidden.some((item, i) => item.action !== this.overflowed[i]?.action)) this.overflowed = hidden;\n    };\n\n    private readonly onPick = (event: CustomEvent<{ value: string }>) => {\n        const item = this.overflowed[Number(event.detail.value)];\n        item?.action.querySelector<HTMLElement>('ui-button, ui-icon-button, button')?.click();\n    };\n\n    override render() {\n        return html`<div class=\"actions\" part=\"base\">\n            <slot @slotchange=${this.schedule}></slot>\n            ${this.overflowed.length\n                ? html`<ui-overflow-menu size=\"sm\" placement=\"bottom-end\" label=${this.overflowMenuLabel || this.localize.t.common.moreActions} @ui-select=${this.onPick}>\n                      ${this.overflowed.map((item, index) => html`<ui-menu-item label=${item.label} value=${String(index)}></ui-menu-item>`)}\n                  </ui-overflow-menu>`\n                : nothing}\n        </div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-card-actions': UiCardActions;\n    }\n}\n"
    },
    {
      "path": "src/primitives/card/card-body.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/card/card-body.ts",
      "content": "import { css, html } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { UiElement } from '../shared/element.ts';\n\n/**\n * The card's body (Carbon `CardBody`): body-compact-01 with 16px padding, or none with `is-flush`.\n *\n * @slot - The content\n */\n@customElement('ui-card-body')\nexport class UiCardBody extends UiElement {\n    static override readonly styles = css`\n        :host {\n            display: block;\n        }\n\n        .body {\n            padding: var(--ui-space-md);\n            color: var(--_card-ink, var(--ui-ink));\n            font: var(--ui-font-body-sm);\n            line-height: 18px;\n            letter-spacing: var(--ui-tracking-body);\n        }\n\n        :host([is-flush]) .body {\n            padding: 0;\n        }\n\n        /* a horizontal card's body takes the room above the footer */\n        :host([data-horizontal]) {\n            flex: 1 0 auto;\n        }\n    `;\n\n    @property({ type: Boolean, reflect: true, attribute: 'is-flush' }) isFlush = false;\n\n    override render() {\n        return html`<div class=\"body\" part=\"base\"><slot></slot></div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-card-body': UiCardBody;\n    }\n}\n"
    },
    {
      "path": "src/primitives/card/card-footer.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/card/card-footer.ts",
      "content": "import { css, html } from 'lit';\nimport { customElement } from 'lit/decorators.js';\nimport { UiElement } from '../shared/element.ts';\n\n/**\n * The card's footer (Carbon `CardFooter`): content with 16px padding, or a row of `<ui-card-action>`s across the\n * card under a `border-subtle` line (buttons stretch, icon buttons sit at the end). Not in a linked or clickable card.\n *\n * @slot - Content or `<ui-card-action>`s\n * @cssprop --ui-card-actions-padding / --ui-card-actions-gap - Around and between the footer's buttons (default 0 and 1px: full-bleed; Kanok: 8px and 8px)\n */\n@customElement('ui-card-footer')\nexport class UiCardFooter extends UiElement {\n    static override readonly styles = css`\n        :host {\n            display: block;\n        }\n\n        :host([data-in-linked-card]) {\n            display: none;\n        }\n\n        .footer {\n            display: flex;\n            align-items: center;\n            padding: var(--ui-space-md);\n        }\n\n        /* --ui-card-actions-padding / -gap: a design can inset the buttons, so a round button's fill and outside ring stay\n           clear of the card's corners (Carbon: full-bleed buttons 1px apart) */\n        :host([data-actions]) .footer {\n            overflow: hidden;\n            justify-content: flex-end;\n            gap: var(--ui-card-actions-gap, 1px);\n            padding: var(--ui-card-actions-padding, 0);\n            border-block-start: 1px solid var(--ui-hairline);\n        }\n    `;\n\n    private readonly onSlotChange = () => {\n        this.toggleAttribute('data-actions', [...this.children].some((el) => el.localName === 'ui-card-action'));\n    };\n\n    override render() {\n        return html`<div class=\"footer\" part=\"base\"><slot @slotchange=${this.onSlotChange}></slot></div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-card-footer': UiCardFooter;\n    }\n}\n"
    },
    {
      "path": "src/primitives/card/card-header-media.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/card/card-header-media.ts",
      "content": "import { css, html } from 'lit';\nimport { customElement } from 'lit/decorators.js';\nimport { UiElement } from '../shared/element.ts';\n\n/**\n * Media across the top of the header (Carbon `CardHeaderMedia`), e.g. a pictogram; 16px in, at most 64px tall.\n *\n * @slot - The media\n */\n@customElement('ui-card-header-media')\nexport class UiCardHeaderMedia extends UiElement {\n    static override readonly styles = css`\n        :host {\n            display: block;\n        }\n\n        .media {\n            display: flex;\n            align-items: flex-start;\n            justify-content: flex-start;\n            max-block-size: 64px;\n            margin-block: var(--ui-space-md);\n            margin-inline-start: var(--ui-space-md);\n        }\n    `;\n\n    override render() {\n        return html`<div class=\"media\" part=\"base\"><slot></slot></div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-card-header-media': UiCardHeaderMedia;\n    }\n}\n"
    },
    {
      "path": "src/primitives/card/card-header.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/card/card-header.ts",
      "content": "import { css, html } from 'lit';\nimport { customElement } from 'lit/decorators.js';\nimport { UiElement } from '../shared/element.ts';\n\n/**\n * The card's header (Carbon `CardHeader`): media, title media, the title and its actions on a grid.\n *\n * @slot - `<ui-card-header-media>`, `<ui-card-title-media>`, `<ui-card-title>`, `<ui-card-actions>`\n */\n@customElement('ui-card-header')\nexport class UiCardHeader extends UiElement {\n    static override readonly styles = css`\n        :host {\n            display: block;\n        }\n\n        .header {\n            position: relative;\n            display: grid;\n            container-type: inline-size;\n            grid-template-columns: auto minmax(0, 1fr);\n            row-gap: 0;\n        }\n\n        ::slotted(ui-card-header-media) {\n            grid-column: 1 / -1;\n        }\n\n        ::slotted(ui-card-title-media) {\n            grid-column: 1;\n        }\n\n        ::slotted(ui-card-title) {\n            grid-column: 2;\n        }\n    `;\n\n    /** The title knows what sits beside it (its margins and width follow). */\n    private readonly onSlotChange = () => {\n        const children = [...this.children];\n        const titleMedia = children.some((el) => el.localName === 'ui-card-title-media');\n        const actions = children.some((el) => el.localName === 'ui-card-actions');\n        for (const title of children.filter((el) => el.localName === 'ui-card-title')) {\n            title.toggleAttribute('data-after-media', titleMedia);\n            title.toggleAttribute('data-beside-actions', actions);\n        }\n    };\n\n    override render() {\n        return html`<div class=\"header\" part=\"base\"><slot @slotchange=${this.onSlotChange}></slot></div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-card-header': UiCardHeader;\n    }\n}\n"
    },
    {
      "path": "src/primitives/card/card-media.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/card/card-media.ts",
      "content": "import { css, html } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { styleMap } from 'lit/directives/style-map.js';\nimport { UiElement } from '../shared/element.ts';\n\nexport type CardMediaRatio = '16x9' | '9x16' | '2x1' | '1x2' | '4x3' | '3x4' | '3x2' | '2x3' | '1x1';\n\n/**\n * The card's media (Carbon `CardMedia`): an image or video filling the card's width at `ratio`; beside the content in\n * a horizontal card, `media-width` wide.\n *\n * @slot - An `<img>`, `<video>`, …\n */\n@customElement('ui-card-media')\nexport class UiCardMedia extends UiElement {\n    static override readonly styles = css`\n        :host {\n            display: block;\n        }\n\n        :host([data-horizontal]) {\n            overflow: hidden;\n            flex-basis: var(--_media-width, 33.33%);\n            flex-shrink: 0;\n            align-self: stretch;\n        }\n\n        .media {\n            width: 100%;\n            height: 100%;\n            aspect-ratio: var(--_ratio, auto);\n        }\n\n        /* beside the content it takes the card's height instead */\n        :host([data-horizontal]) .media {\n            aspect-ratio: auto;\n        }\n\n        .media ::slotted(*) {\n            display: block;\n            width: 100%;\n            height: 100%;\n            object-fit: cover;\n        }\n    `;\n\n    @property({ reflect: true }) ratio: CardMediaRatio | '' = '';\n\n    /** A horizontal card's media width (Carbon's default 33.33%). */\n    @property({ attribute: 'media-width' }) mediaWidth = '33.33%';\n\n    protected override updated() {\n        this.style.setProperty('--_media-width', this.mediaWidth);\n    }\n\n    override render() {\n        return html`<div class=\"media\" part=\"base\" style=${styleMap({ '--_ratio': this.ratio ? this.ratio.replace('x', ' / ') : null })}><slot></slot></div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-card-media': UiCardMedia;\n    }\n}\n"
    },
    {
      "path": "src/primitives/card/card-title-media.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/card/card-title-media.ts",
      "content": "import { css, html } from 'lit';\nimport { customElement } from 'lit/decorators.js';\nimport { UiElement } from '../shared/element.ts';\n\n/**\n * Media before the title (Carbon `CardTitleMedia`), e.g. a 48–64px logo.\n *\n * @slot - The media\n */\n@customElement('ui-card-title-media')\nexport class UiCardTitleMedia extends UiElement {\n    static override readonly styles = css`\n        :host {\n            display: block;\n        }\n\n        .media {\n            display: flex;\n            flex-shrink: 0;\n            align-items: flex-start;\n            justify-content: center;\n            max-block-size: 64px;\n            margin-block-start: var(--ui-space-md);\n            padding-inline: var(--ui-space-md);\n        }\n    `;\n\n    override render() {\n        return html`<div class=\"media\" part=\"base\"><slot></slot></div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-card-title-media': UiCardTitleMedia;\n    }\n}\n"
    },
    {
      "path": "src/primitives/card/card-title.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/card/card-title.ts",
      "content": "import { css, html, nothing } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { styleMap } from 'lit/directives/style-map.js';\nimport { UiElement } from '../shared/element.ts';\n\n/** `title-truncate` and friends: absent = wrap, present = one line with an ellipsis, a number = that many lines. */\nfunction truncation(value: string | null): false | true | number {\n    if (value === null) return false;\n    const lines = Number(value);\n    return Number.isInteger(lines) && lines > 0 ? lines : true;\n}\n\n/**\n * The card's title (Carbon `CardTitle`): an optional label above, the title (heading-compact-02, or heading-03 in an\n * expressive card) and an optional description below, each of them truncatable.\n *\n * @slot - The title text\n * @slot label - Replaces `label`\n * @slot description - Replaces `description`\n * @slot title-start - An icon before the title\n * @slot title-end - An icon after the title\n */\n@customElement('ui-card-title')\nexport class UiCardTitle extends UiElement {\n    static override readonly styles = css`\n        :host {\n            display: block;\n            min-inline-size: 0;\n        }\n\n        .title {\n            display: flex;\n            flex-direction: column;\n            gap: 2px; /* Carbon spacing-01 */\n            min-inline-size: 0;\n            margin: var(--ui-space-md);\n        }\n\n        :host([data-after-media]) .title {\n            margin-inline-start: 0;\n        }\n\n        :host([data-beside-actions]) .title {\n            max-inline-size: calc(50cqw - var(--ui-space-xs));\n        }\n\n        .label,\n        .description,\n        ::slotted([slot='label']),\n        ::slotted([slot='description']) {\n            color: var(--_card-ink-muted, var(--ui-ink-muted));\n            font: var(--ui-font-caption);\n            line-height: 16px; /* label-01 */\n            letter-spacing: var(--ui-tracking-caption);\n        }\n\n        .row {\n            display: block;\n            color: var(--_card-ink, var(--ui-ink));\n            font: var(--_card-title-font, 600 16px/22px var(--ui-font-family));\n        }\n\n        .with-start {\n            display: flex;\n            align-items: flex-start;\n            gap: var(--ui-space-xs);\n        }\n\n        /* Carbon keeps the (empty) start-icon box with its 2px top margin, so the row is 2px taller than its line */\n        .start {\n            display: flex;\n            flex-shrink: 0;\n            margin-block-start: 2px;\n        }\n\n        .end {\n            display: inline-flex;\n            align-items: center;\n            margin-inline-start: var(--ui-space-xs);\n            vertical-align: middle;\n        }\n\n        .end:not(.filled) {\n            display: none;\n        }\n\n        .one-line {\n            overflow: hidden;\n            text-overflow: ellipsis;\n            white-space: nowrap;\n        }\n\n        .lines {\n            display: -webkit-box;\n            overflow: hidden;\n            -webkit-box-orient: vertical;\n            -webkit-line-clamp: var(--_lines);\n            text-overflow: ellipsis;\n        }\n    `;\n\n    @property() label = '';\n\n    @property() description = '';\n\n    @property({ attribute: 'title-truncate' }) titleTruncate: string | null = null;\n\n    @property({ attribute: 'label-truncate' }) labelTruncate: string | null = null;\n\n    @property({ attribute: 'description-truncate' }) descriptionTruncate: string | null = null;\n\n    /** A truncated title's widest. */\n    @property({ attribute: 'max-width' }) maxWidth = '100%';\n\n    @state() private hasStart = false;\n\n    @state() private hasEnd = false;\n\n    private textClasses(base: string, value: string | null) {\n        const lines = truncation(value);\n        return { classes: classMap({ [base]: true, 'one-line': lines === true, lines: typeof lines === 'number' }), style: styleMap(typeof lines === 'number' ? { '--_lines': String(lines) } : {}) };\n    }\n\n    override render() {\n        const label = this.textClasses('label', this.labelTruncate);\n        const description = this.textClasses('description', this.descriptionTruncate);\n        const titleLines = truncation(this.titleTruncate);\n        const row = classMap({ row: true, 'one-line': titleLines === true, lines: typeof titleLines === 'number', 'with-start': this.hasStart });\n        const rowStyle = styleMap(titleLines === false ? {} : { maxInlineSize: this.maxWidth, '--_lines': typeof titleLines === 'number' ? String(titleLines) : null });\n        return html`<div class=\"title\" part=\"base\">\n            <slot name=\"label\">${this.label ? html`<div class=${label.classes} style=${label.style}>${this.label}</div>` : nothing}</slot>\n            <span class=${row} style=${rowStyle} part=\"title\"\n                ><span class=\"start\"><slot name=\"title-start\" @slotchange=${(e: Event) => (this.hasStart = (e.target as HTMLSlotElement).assignedElements().length > 0)}></slot></span\n                ><slot></slot\n                ><span class=${classMap({ end: true, filled: this.hasEnd })}><slot name=\"title-end\" @slotchange=${(e: Event) => (this.hasEnd = (e.target as HTMLSlotElement).assignedElements().length > 0)}></slot></span\n            ></span>\n            <slot name=\"description\">${this.description ? html`<div class=${description.classes} style=${description.style}>${this.description}</div>` : nothing}</slot>\n        </div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-card-title': UiCardTitle;\n    }\n}\n"
    },
    {
      "path": "src/primitives/card/card.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/card/card.ts",
      "content": "// Its child elements are one per file beside it; this module re-exports them (one entry point).\nimport { LitElement, css, html, nothing, type PropertyValues } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { LocalizeController } from '../shared/localize.ts';\nimport { UiElement } from '../shared/element.ts';\nimport { srOnlyStyles } from '../shared/field.ts';\nimport { followLink } from '../shared/navigate.ts';\nimport '../overflow-menu/overflow-menu.ts';\nimport '../menu/menu.ts';\nexport * from './card-media.ts';\nexport * from './card-header.ts';\nexport * from './card-header-media.ts';\nexport * from './card-title-media.ts';\nexport * from './card-title.ts';\nexport * from './card-body.ts';\nexport * from './card-footer.ts';\nexport * from './card-action.ts';\nexport * from './card-actions.ts';\n\n/** Carbon card (preview, `cds-card`): productive titles are heading-compact-02, expressive ones heading-03. */\nexport type CardDensity = 'productive' | 'expressive';\n\nconst PARTS = 'ui-card-media, ui-card-header, ui-card-body, ui-card-footer';\n\n/**\n * Carbon `Card` (preview in Carbon, `cds-card`): a `$layer` box — no border, no shadow, square — built from parts:\n * `<ui-card-media>`, `<ui-card-header>` (with `<ui-card-header-media>`, `<ui-card-title-media>`, `<ui-card-title>`,\n * `<ui-card-actions>`), `<ui-card-body>` and `<ui-card-footer>` (with `<ui-card-action>`s). It follows the\n * `<ui-layer>` it sits on.\n *\n * - `href`: the whole card is one link; `clickable`: the whole card is one button (`click`, Enter, Space) — both\n *   get a 1px `border-tile-01`, `layer-hover` / `layer-active` and an arrow footer (`clickable`). Name it with `label`\n *   and don't put other controls inside (Carbon: \"clickable cards should not contain interactive elements\"). As in\n *   Carbon, its `<ui-card-footer>` is not shown; `<ui-card-actions>` still shows, nested in the one control.\n * - `selected` (beyond Carbon, whose card has no chosen state): a clickable card looks like a checked\n *   `<ui-selectable-tile>` (the same `--ui-tile-selected-*` tokens) and reports `aria-pressed`; the card doesn't\n *   toggle itself, the app sets it on `click`. `hide-footer-icon` (beyond Carbon) drops the arrow footer.\n * - `disabled`: text and arrow greyed, no clicks.\n * - `horizontal`: the media beside the content (`media-position` start | end, its width from `media-width`).\n *\n * @slot - The parts\n * @slot media - (filled for you) the media of a horizontal card\n * @slot footer-icon - Replaces the clickable card's arrow\n * @csspart base - The card (`<div>`, or `<a>` with `href`)\n * @fires ui-navigate - detail: { href } (cancelable) on a plain click of a linked card; cancel it to route client-side (README: SPA router)\n * @cssprop --ui-card-radius - Corner radius (default 0; Kanok: 12px)\n * @cssprop --ui-card-border - Border of every card, not only clickable ones (default none; Kanok: a hairline)\n * @cssprop --ui-card-background - Its fill (default `--ui-surface-1`; Kanok paper: a cool grey that sets it apart from the page, no border)\n * @cssprop --ui-card-clickable-border - Border of a clickable card (default 1px `--ui-border-tile-1`; Kanok: none)\n * @cssprop --ui-card-overflow - `overflow` of the card (default visible; Kanok: clip, so media follow the rounded corners)\n * @cssprop --ui-tile-selected-border - Border of a `selected` card, as a checked tile's (default `--ui-layer-selected-inverse`); `--ui-tile-selected-background` / `--ui-tile-selected-hover` its fill\n */\n@customElement('ui-card')\nexport class UiCard extends UiElement {\n    static override readonly shadowRootOptions: ShadowRootInit = { ...LitElement.shadowRootOptions, delegatesFocus: true };\n\n    static override readonly styles = [srOnlyStyles, css`\n        /* what the parts read: the title's type by density, greyed text when disabled */\n        :host {\n            display: block;\n            --_card-title-font: 600 16px/22px var(--ui-font-family);\n            --_card-ink: var(--ui-ink);\n            --_card-ink-muted: var(--ui-ink-muted);\n        }\n\n        :host([density='expressive']) {\n            --_card-title-font: var(--ui-font-subhead);\n        }\n\n        :host([disabled]) {\n            --_card-ink: var(--ui-ink-disabled);\n            --_card-ink-muted: var(--ui-ink-disabled);\n        }\n\n        /* Carbon .cds--card */\n        .card {\n            position: relative;\n            display: block;\n            box-sizing: border-box;\n            height: 100%;\n            /* Carbon: square, a border only when clickable (below); --ui-card-* let a design round and outline every card */\n            border: var(--ui-card-border, none);\n            border-radius: var(--ui-card-radius, 0);\n            overflow: var(--ui-card-overflow, visible); /* Kanok clips: the media follows the rounded corners */\n            outline: var(--ui-focus-width, 2px) solid transparent;\n            background-color: var(--ui-card-background, var(--ui-surface-1));\n            color: var(--_card-ink);\n            font: var(--ui-font-body);\n            text-decoration: none;\n        }\n\n        .clickable {\n            border: var(--ui-card-clickable-border, 1px solid var(--ui-border-tile-1)); /* Kanok: none, the fill sets it apart */\n            cursor: pointer;\n            transition: background-color var(--ui-duration-moderate) var(--ui-easing);\n        }\n\n        .clickable:hover {\n            background-color: var(--ui-ghost-hover);\n        }\n\n        .clickable:active {\n            background-color: var(--ui-ghost-active);\n        }\n\n        /* selected (beyond Carbon): the chosen look of <ui-selectable-tile checked>, its tokens and values */\n        .clickable.selected {\n            border: 1px solid var(--ui-tile-selected-border, var(--ui-layer-selected-inverse));\n            background-color: var(--ui-tile-selected-background, var(--ui-highlight, var(--ui-card-background)));\n        }\n\n        .clickable.selected:hover {\n            background-color: var(--ui-tile-selected-hover, var(--ui-tile-selected-background, var(--ui-highlight, var(--ui-card-background))));\n        }\n\n        /* the ring on :focus (a click too), as Carbon React's clickable card */\n        .clickable:focus {\n            outline-color: var(--ui-focus);\n            outline-offset: 0;\n        }\n\n        /* a mouse or touch focus shows no ring in a design that sets --ui-pointer-focus (Kanok: keyboard only) */\n        .clickable:focus:not(:focus-visible) {\n            outline-color: var(--ui-pointer-focus, var(--ui-focus));\n        }\n\n        .disabled {\n            border-color: var(--ui-border-disabled);\n            cursor: not-allowed;\n        }\n\n        .horizontal {\n            display: flex;\n            flex-direction: row;\n            align-items: stretch;\n        }\n\n        .content {\n            display: flex;\n            flex: 1 1 0;\n            flex-direction: column;\n            min-inline-size: 0;\n        }\n\n        .footer-icon {\n            display: flex;\n            align-items: center;\n            justify-content: flex-end;\n            padding: var(--ui-space-md);\n            color: var(--ui-icon-interactive);\n            fill: currentColor;\n        }\n\n        .disabled .footer-icon {\n            color: var(--ui-icon-disabled);\n        }\n\n        .footer-icon svg,\n        .footer-icon ::slotted(svg) {\n            display: block;\n            width: 16px;\n            height: 16px;\n        }\n\n        @media (forced-colors: active) {\n            .card {\n                border: 1px solid CanvasText;\n            }\n        }\n    `];\n\n    /** Makes the whole card one link. */\n    @property() href = '';\n\n    @property() target: '_self' | '_blank' = '_self';\n\n    /** Makes the whole card one button (listen for `click`). */\n    @property({ type: Boolean, reflect: true }) clickable = false;\n\n    /** A clickable card shown chosen, as a checked selectable tile, with `aria-pressed` (beyond Carbon; the app toggles it). */\n    @property({ type: Boolean, reflect: true }) selected?: boolean;\n\n    /** Removes the clickable card's arrow footer (beyond Carbon). */\n    @property({ type: Boolean, attribute: 'hide-footer-icon' }) hideFooterIcon = false;\n\n    @property({ type: Boolean, reflect: true }) disabled = false;\n\n    /** The accessible name of a linked or clickable card (Carbon asks for one). */\n    @property() label = '';\n\n    @property({ reflect: true }) density: CardDensity = 'productive';\n\n    @property({ type: Boolean, reflect: true }) horizontal = false;\n\n    /** Where a horizontal card's media goes. */\n    @property({ reflect: true, attribute: 'media-position' }) mediaPosition: 'start' | 'end' = 'start';\n\n    private readonly localize = new LocalizeController(this);\n\n    protected override updated(changed: PropertyValues<this>) {\n        if (changed.has('horizontal') || changed.has('clickable') || changed.has('href') || changed.has('disabled')) this.syncParts();\n    }\n\n    /** The parts read the card's state (a horizontal card's media goes to its own slot; a clickable card has no footer). */\n    private readonly syncParts = () => {\n        const linked = this.clickable || !!this.href;\n        for (const part of this.querySelectorAll<HTMLElement>(PARTS)) {\n            if (part.closest('ui-card') !== this) continue;\n            if (part.localName === 'ui-card-media') {\n                if (this.horizontal) part.setAttribute('slot', 'media');\n                else part.removeAttribute('slot');\n            }\n            part.toggleAttribute('data-horizontal', this.horizontal);\n            part.toggleAttribute('data-in-linked-card', linked);\n        }\n    };\n\n    private readonly onKeydown = (event: KeyboardEvent) => {\n        // only when the card itself has focus: Enter on a control inside is that control's\n        if (this.disabled || event.composedPath()[0] !== event.currentTarget || (event.key !== 'Enter' && event.key !== ' ')) return;\n        event.preventDefault();\n        (event.currentTarget as HTMLElement).click();\n    };\n\n    private readonly onDisabledClick = (event: Event) => {\n        if (!this.disabled) return;\n        event.preventDefault();\n        event.stopImmediatePropagation();\n    };\n\n    /** `aria-pressed` of a clickable card, only once `selected` is used (else the markup stays as Carbon's). */\n    private pressed() {\n        if (this.selected === undefined) return nothing;\n        return this.selected ? 'true' : 'false';\n    }\n\n    private renderContent() {\n        if (!this.horizontal) return html`<slot @slotchange=${this.syncParts}></slot>`;\n        const media = html`<slot name=\"media\"></slot>`;\n        const content = html`<div class=\"content\"><slot @slotchange=${this.syncParts}></slot></div>`;\n        return this.mediaPosition === 'end' ? html`${content}${media}` : html`${media}${content}`;\n    }\n\n    private renderInner() {\n        // Carbon's ArrowRight (16), the clickable card's affordance; decorative\n        const arrow = this.clickable && !this.hideFooterIcon\n            ? html`<div class=\"footer-icon\" aria-hidden=\"true\">\n                  <slot name=\"footer-icon\"><svg viewBox=\"0 0 16 16\"><path d=\"M9.3 3.7 13.1 7.5H1v1h12.1l-3.8 3.8.7.7 5-5-5-5z\" /></svg></slot>\n              </div>`\n            : nothing;\n        return html`${this.renderContent()}${arrow}`;\n    }\n\n    override render() {\n        const classes = classMap({ card: true, clickable: this.clickable && !this.disabled, selected: !!this.selected, disabled: this.disabled, horizontal: this.horizontal });\n        // tabindex=\"0\" as Carbon's links: without it Safari neither focuses the card on click nor stops on it with Tab\n        if (this.href && !this.disabled) {\n            const external = this.target === '_blank';\n            return html`<a\n                class=${classes}\n                part=\"base\"\n                href=${this.href}\n                target=${this.target}\n                rel=${external ? 'noopener noreferrer' : nothing}\n                aria-label=${this.label || nothing}\n                tabindex=\"0\"\n                @click=${followLink}\n                >${this.renderInner()}${external ? html`<span class=\"sr-only\">${this.localize.t.common.opensInNewTab}</span>` : nothing}</a\n            >`;\n        }\n        if (this.clickable) {\n            return html`<div\n                class=${classes}\n                part=\"base\"\n                role=\"button\"\n                tabindex=${this.disabled ? '-1' : '0'}\n                aria-disabled=${this.disabled ? 'true' : 'false'}\n                aria-pressed=${this.pressed()}\n                aria-label=${this.label || nothing}\n                @click=${this.onDisabledClick}\n                @keydown=${this.onKeydown}\n            >\n                ${this.renderInner()}\n            </div>`;\n        }\n        return html`<div class=${classes} part=\"base\" aria-disabled=${this.disabled ? 'true' : nothing}>${this.renderInner()}</div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-card': UiCard;\n    }\n}\n"
    }
  ]
}
