{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button",
  "type": "registry:ui",
  "title": "<ui-button>",
  "description": "Carbon-style button (Carbon `Button`). 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-button",
    "@kanok-ui/shared-element",
    "@kanok-ui/shared-field",
    "@kanok-ui/shared-form-control",
    "@kanok-ui/shared-localize",
    "@kanok-ui/shared-navigate",
    "@kanok-ui/shared-skeleton",
    "@kanok-ui/shared-slots",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/button/button-skeleton.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/button/button-skeleton.ts",
      "content": "import { html, css } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { skeletonStyles, UiSkeletonElement } from '../shared/skeleton.ts';\nimport type { ButtonSize } from './button.ts';\n\n/**\n * Carbon `ButtonSkeleton` (`cds-button-skeleton`): a 150px bar at the button's height (sm 32 / md 40 / lg 48 / xl 64 / 2xl 80px).\n * Hidden from assistive tech.\n *\n * @csspart bone - The bar\n */\n@customElement('ui-button-skeleton')\nexport class UiButtonSkeleton extends UiSkeletonElement {\n    static override readonly styles = [\n        skeletonStyles,\n        css`\n            :host {\n                display: inline-block;\n                vertical-align: middle;\n            }\n\n            .bone {\n                inline-size: 150px;\n                block-size: var(--ui-button-height-lg, var(--ui-field-height-lg, 48px));\n                border-radius: var(--ui-button-radius, var(--ui-skeleton-radius)); /* the button's corners */\n            }\n\n            :host([size='sm']) .bone {\n                block-size: var(--ui-field-height-sm, 32px);\n            }\n\n            :host([size='md']) .bone {\n                block-size: var(--ui-field-height-md, 40px);\n            }\n\n            :host([size='xl']) .bone {\n                block-size: var(--ui-button-height-xl, 64px);\n            }\n\n            :host([size='2xl']) .bone {\n                block-size: var(--ui-button-height-2xl, 80px);\n            }\n        `,\n    ];\n\n    @property({ reflect: true }) size: ButtonSize = 'lg';\n\n    override render() {\n        return html`<div class=\"bone\" part=\"bone\"></div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-button-skeleton': UiButtonSkeleton;\n    }\n}\n"
    },
    {
      "path": "src/primitives/button/button.styles.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/button/button.styles.ts",
      "content": "import { css } from 'lit';\n\n/** Styles of `<ui-button>`. */\nexport const buttonStyles = css`\n    :host {\n        display: inline-block;\n        vertical-align: middle;\n    }\n\n    :host([full-width]) {\n        display: block;\n    }\n\n    .button {\n        position: relative; /* for a badge indicator in its corner */\n        box-sizing: border-box;\n        display: inline-flex;\n        align-items: var(--ui-button-align, var(--_ui-button-align, center));\n        /* Carbon: label at the start, icon at the end; a design can centre it (--ui-button-justify, --ui-button-gap) */\n        justify-content: var(--ui-button-justify, space-between);\n        /* Carbon: text 15px from the start (+1px border), 63px of room at the end: 16px icon at 16px, text at least 31px before it */\n        gap: var(--ui-button-gap, 32px);\n        width: 100%;\n        /* lg, the default size (always reflected): 48px in Carbon; --ui-button-height-lg lets a design change it */\n        min-height: var(--ui-button-height-lg, var(--ui-field-height-lg, 48px));\n        margin: 0;\n        padding-block: var(--ui-button-padding-top, var(--_ui-button-padding-top, 0)) 0;\n        /* --_ui-button-pad: the padding of a size that has its own (xl / 2xl, when a design sets one) */\n        padding-inline: var(--_ui-button-pad, var(--ui-button-padding-start, 15px)) var(--_ui-button-pad, var(--ui-button-padding-end, 63px));\n        border: 1px solid transparent;\n        /* the button setting; a joined control (the combo button) squares the side that joins, with --_ui-button-radius-start / -end */\n        border-start-start-radius: var(--_ui-button-radius-start, var(--ui-button-radius, var(--ui-radius-none)));\n        border-end-start-radius: var(--_ui-button-radius-start, var(--ui-button-radius, var(--ui-radius-none)));\n        border-start-end-radius: var(--_ui-button-radius-end, var(--ui-button-radius, var(--ui-radius-none)));\n        border-end-end-radius: var(--_ui-button-radius-end, var(--ui-button-radius, var(--ui-radius-none)));\n        font: var(--ui-font-button);\n        letter-spacing: var(--ui-tracking-body);\n        text-align: start;\n        cursor: pointer;\n        /* Carbon button-base: background, box-shadow, border-color, outline at fast-01 with the entrance easing (the text colour switches at once) */\n        transition:\n            background-color var(--ui-duration-fast) var(--ui-easing-entrance),\n            box-shadow var(--ui-duration-fast) var(--ui-easing-entrance),\n            border-color var(--ui-duration-fast) var(--ui-easing-entrance),\n            outline var(--ui-duration-fast) var(--ui-easing-entrance);\n    }\n\n    .button.has-suffix {\n        padding-inline-end: 16px; /* icon edge 16px inside the padding box, as Carbon's absolute icon (17px from the outer edge) */\n    }\n\n    :host([size='sm']) .button {\n        min-height: var(--ui-field-height-sm, 32px);\n    }\n\n\n    :host([size='md']) .button {\n        min-height: var(--ui-field-height-md, 40px);\n    }\n\n    :host([size='lg']) .button {\n        min-height: var(--ui-button-height-lg, var(--ui-field-height-lg, 48px));\n    }\n\n    :host([size='xl']) .button {\n        min-height: var(--ui-button-height-xl, 64px);\n    }\n\n    :host([size='2xl']) .button {\n        min-height: var(--ui-button-height-2xl, 80px);\n    }\n\n    :host([size='xl']) {\n        --_ui-button-pad: var(--ui-button-padding-xl);\n    }\n\n    :host([size='2xl']) {\n        --_ui-button-pad: var(--ui-button-padding-2xl);\n    }\n\n    /*\n     * Carbon xl / 2xl: padding-block is min((height - 18px) / 2 - 1px, lg's 14px), so the content stays at the\n     * top, 14px inside the border; the icon (Carbon btn__icon: the same 14px + 1px margin) sits 1px lower.\n     * --ui-button-tall-align / -padding-top / -icon-offset let a design centre it (Kanok: 40 / 48px pills).\n     */\n    :host([size='xl']:not([icon-only])),\n    :host([size='2xl']:not([icon-only])) {\n        --_ui-button-align: var(--ui-button-tall-align, flex-start);\n        --_ui-button-padding-top: var(--ui-button-tall-padding-top, 14px);\n    }\n\n    /* !important on the slotted icon: a page-level reset (Tailwind preflight's * { margin: 0 }) beats ::slotted rules */\n    :host([size='xl']:not([icon-only])) ::slotted(svg),\n    :host([size='2xl']:not([icon-only])) ::slotted(svg) {\n        margin-block-start: var(--ui-button-tall-icon-offset, 1px) !important;\n    }\n\n    :host([size='xl']:not([icon-only])) .spinner,\n    :host([size='2xl']:not([icon-only])) .spinner {\n        margin-block-start: var(--ui-button-tall-icon-offset, 1px);\n    }\n\n    /*\n     * Carbon focus (:focus, so a mouse click shows it too): 2px focus ring + 1px focus-inset line inside it.\n     * Carbon: 1px focus border + inset 1px focus + inset 2px background. The inset starts inside the 1px\n     * border, so 2px reaches 3px from the edge and the 2px outline leaves 1px of it showing.\n     */\n    .button:focus {\n        outline: var(--ui-focus-width, 2px) solid var(--ui-focus);\n        /* --ui-focus-offset / --ui-focus-inset-width: a design can move the ring outside and drop the inner line */\n        outline-offset: var(--ui-focus-offset, -2px);\n        box-shadow: inset 0 0 0 var(--ui-focus-inset-width, 2px) var(--ui-focus-inset);\n    }\n\n    /* a mouse or touch focus shows no ring in a design that sets --ui-pointer-focus (Kanok: keyboard only) */\n    .button:focus:not(:focus-visible) {\n        outline-color: var(--ui-pointer-focus, var(--ui-focus));\n        transition-property: background-color, box-shadow, border-color;\n    }\n\n    ::slotted(svg) {\n        flex-shrink: 0;\n        width: 16px;\n        height: 16px;\n        fill: currentColor; /* an icon takes the text colour of the kind (Carbon btn__icon) */\n    }\n\n    /* primary */\n    .button {\n        background-color: var(--ui-primary);\n        color: var(--ui-on-primary);\n    }\n    .button:hover {\n        background-color: var(--ui-blue-hover);\n    }\n    .button:active {\n        background-color: var(--ui-blue-80);\n    }\n\n    /* secondary — charcoal (Carbon); --ui-button-secondary-* let a design restyle the button alone (other parts use --ui-secondary) */\n    :host([kind='secondary']) .button {\n        border-color: var(--ui-button-secondary-border, transparent);\n        background-color: var(--ui-button-secondary, var(--ui-secondary)); /* Carbon button-secondary */\n        color: var(--ui-on-button-secondary, var(--ui-on-primary)); /* text-on-color */\n    }\n    :host([kind='secondary']) .button:hover {\n        background-color: var(--ui-button-secondary-hover, var(--ui-secondary-hover));\n    }\n    :host([kind='secondary']) .button:active {\n        background-color: var(--ui-button-secondary-active, var(--ui-secondary-active));\n    }\n\n    /* tertiary — blue outline, fills on hover (a design can lighten the outline and text on a dark theme) */\n    :host([kind='tertiary']) .button {\n        background-color: transparent;\n        border-width: var(--ui-button-tertiary-border-width, 1px);\n        border-color: var(--ui-button-tertiary-border, var(--ui-primary));\n        color: var(--ui-button-tertiary-ink, var(--ui-primary));\n    }\n    /* --ui-button-tertiary-hover / -active / -focus (and -state-ink): Carbon fills it as a primary; a design can tint it,\n       keeping its outline and text, so it never turns into a second primary */\n    :host([kind='tertiary']) .button:hover {\n        background-color: var(--ui-button-tertiary-hover, var(--ui-blue-hover));\n        color: var(--ui-button-tertiary-state-ink, var(--ui-on-primary));\n    }\n    :host([kind='tertiary']) .button:focus {\n        background-color: var(--ui-button-tertiary-focus, var(--ui-primary));\n        color: var(--ui-button-tertiary-state-ink, var(--ui-on-primary));\n    }\n    :host([kind='tertiary']) .button:active {\n        background-color: var(--ui-button-tertiary-active, var(--ui-blue-80));\n        border-color: var(--ui-button-tertiary-active-border, var(--ui-blue-80));\n        color: var(--ui-button-tertiary-state-ink, var(--ui-on-primary));\n    }\n\n    /* ghost — text only until hover */\n    :host([kind='ghost']) .button {\n        background-color: transparent;\n        color: var(--ui-link); /* Carbon link-primary */\n        justify-content: var(--ui-button-ghost-justify, flex-start);\n        gap: var(--ui-space-xs);\n        padding-inline-end: var(--_ui-button-pad, var(--ui-button-ghost-padding-end, 15px));\n    }\n    /* Carbon: background-hover / background-active (theme level, not the layer set) */\n    :host([kind='ghost']) .button:hover {\n        background-color: var(--ui-canvas-hover);\n        color: var(--ui-blue-60);\n    }\n    :host([kind='ghost']) .button:active {\n        background-color: var(--ui-canvas-active);\n    }\n\n    /* danger */\n    :host([kind='danger']) .button {\n        background-color: var(--ui-button-danger);\n        color: var(--ui-on-primary);\n    }\n    :host([kind='danger']) .button:hover {\n        background-color: var(--ui-error-hover);\n    }\n    :host([kind='danger']) .button:active {\n        background-color: var(--ui-error-active);\n    }\n\n    /* danger-tertiary — red outline, fills on hover */\n    :host([kind='danger-tertiary']) .button {\n        background-color: transparent;\n        border-width: var(--ui-button-tertiary-border-width, 1px);\n        border-color: var(--ui-error);\n        color: var(--ui-error);\n    }\n    :host([kind='danger-tertiary']) .button:hover,\n    :host([kind='danger-tertiary']) .button:focus {\n        background-color: var(--ui-error-hover);\n        border-color: var(--ui-error-hover);\n        color: var(--ui-on-primary);\n    }\n    :host([kind='danger-tertiary']) .button:active {\n        background-color: var(--ui-error-active);\n        border-color: var(--ui-error-active);\n        color: var(--ui-on-primary);\n    }\n\n    /* danger-ghost — red text, fills on hover */\n    :host([kind='danger-ghost']) .button {\n        background-color: transparent;\n        color: var(--ui-error);\n        justify-content: var(--ui-button-ghost-justify, flex-start);\n        gap: var(--ui-space-xs);\n        padding-inline-end: var(--_ui-button-pad, var(--ui-button-ghost-padding-end, 15px));\n    }\n    :host([kind='danger-ghost']) .button:hover {\n        background-color: var(--ui-error-hover);\n        color: var(--ui-on-primary);\n    }\n    :host([kind='danger-ghost']) .button:active {\n        background-color: var(--ui-error-active);\n        color: var(--ui-on-primary);\n    }\n\n    /* toggle buttons (ghost icon buttons in toolbars): Carbon btn--selected, background-selected */\n    :host([pressed]) .button[aria-pressed='true'] {\n        background-color: var(--ui-canvas-selected);\n        color: var(--ui-ink);\n    }\n\n    a.button {\n        text-decoration: none;\n    }\n\n    /*\n     * loading: the small Loading spinner of Carbon's InlineLoading (a layer-accent track, an interactive arc, 690ms\n     * a turn), on the label's line. The label and the loading text share one grid cell, so the button keeps the\n     * wider of the two; what is hidden is see-through (the label stays the button's name).\n     */\n    .label {\n        display: inline-grid;\n        align-items: var(--ui-button-align, var(--_ui-button-align, center));\n    }\n\n    .label > * {\n        grid-area: 1 / 1;\n    }\n\n    .label.replaced .label-text,\n    .label .busy.reserve {\n        opacity: 0;\n    }\n\n    /* Carbon InlineLoading: 8px between the spinner and its text */\n    .busy {\n        display: inline-flex;\n        align-items: center;\n        gap: 8px;\n    }\n\n    .busy-mark {\n        position: absolute;\n        inset-block: 0;\n        box-sizing: border-box;\n        display: flex;\n        align-items: var(--ui-button-align, var(--_ui-button-align, center));\n        padding-block-start: var(--ui-button-padding-top, var(--_ui-button-padding-top, 0));\n        pointer-events: none;\n    }\n\n    /* where Carbon's trailing icon goes (16px inside the padding box), the place of the ActionSet's spinner */\n    .busy-mark.end {\n        inset-inline-end: 16px;\n    }\n\n    .busy-mark.start {\n        inset-inline-start: var(--ui-button-padding-start, 15px);\n    }\n\n    .busy-mark.center {\n        inset-inline: 0;\n        justify-content: center;\n    }\n\n    /* on the slot, not ::slotted: what it holds inherits it, a slot passed through (ui-icon-button's) too */\n    /* the spinner at the end of a button with no trailing icon: room for it after the label (Carbon's 63px has it) */\n    .button.busy-end {\n        padding-inline-end: max(var(--_ui-button-pad, var(--ui-button-padding-end, 63px)), 40px);\n    }\n\n    .button.hide-prefix slot[name='prefix'],\n    .button.hide-suffix slot[name='suffix'] {\n        visibility: hidden;\n    }\n\n    .spinner {\n        inline-size: 16px;\n        block-size: 16px;\n        fill: transparent;\n        animation: spin 690ms linear infinite;\n    }\n\n    .spinner circle {\n        stroke-dasharray: 276.46 276.46;\n        stroke-linecap: butt;\n        stroke-width: 16;\n    }\n\n    .spinner .track {\n        stroke: var(--ui-layer-accent);\n        stroke-dashoffset: -22;\n    }\n\n    .spinner .arc {\n        stroke: var(--ui-interactive);\n        stroke-dashoffset: 143.76; /* 48 % */\n    }\n\n    @keyframes spin {\n        to {\n            transform: rotate(360deg);\n        }\n    }\n\n    @media (prefers-reduced-motion: reduce) {\n        .spinner {\n            animation-duration: 2s;\n        }\n    }\n\n    /*\n     * disabled (Carbon button mixin): button-disabled fill and border, text-on-color-disabled; tertiary kinds keep\n     * the border on a clear fill, ghost kinds are clear. :host([…]) selectors so no kind's hover / active wins.\n     */\n    :host([disabled]) .button,\n    :host([disabled]) .button:hover,\n    :host([disabled]) .button:active,\n    :host([disabled]) .button:focus,\n    :host([disabled-focusable]) .button,\n    :host([disabled-focusable]) .button:hover,\n    :host([disabled-focusable]) .button:active,\n    :host([disabled-focusable]) .button:focus,\n    :host([loading]) .button,\n    :host([loading]) .button:hover,\n    :host([loading]) .button:active,\n    :host([loading]) .button:focus {\n        border-color: var(--ui-button-disabled);\n        background-color: var(--ui-button-disabled);\n        box-shadow: none;\n        color: var(--ui-on-color-disabled);\n        cursor: not-allowed;\n    }\n    :host([kind='tertiary'][disabled]) .button,\n    :host([kind='tertiary'][disabled]) .button:hover,\n    :host([kind='tertiary'][disabled]) .button:active,\n    :host([kind='tertiary'][disabled]) .button:focus,\n    :host([kind='tertiary'][disabled-focusable]) .button,\n    :host([kind='tertiary'][disabled-focusable]) .button:hover,\n    :host([kind='tertiary'][disabled-focusable]) .button:active,\n    :host([kind='tertiary'][disabled-focusable]) .button:focus,\n    :host([kind='tertiary'][loading]) .button,\n    :host([kind='tertiary'][loading]) .button:hover,\n    :host([kind='tertiary'][loading]) .button:active,\n    :host([kind='tertiary'][loading]) .button:focus,\n    :host([kind='danger-tertiary'][disabled]) .button,\n    :host([kind='danger-tertiary'][disabled]) .button:hover,\n    :host([kind='danger-tertiary'][disabled]) .button:active,\n    :host([kind='danger-tertiary'][disabled]) .button:focus,\n    :host([kind='danger-tertiary'][disabled-focusable]) .button,\n    :host([kind='danger-tertiary'][disabled-focusable]) .button:hover,\n    :host([kind='danger-tertiary'][disabled-focusable]) .button:active,\n    :host([kind='danger-tertiary'][disabled-focusable]) .button:focus,\n    :host([kind='danger-tertiary'][loading]) .button,\n    :host([kind='danger-tertiary'][loading]) .button:hover,\n    :host([kind='danger-tertiary'][loading]) .button:active,\n    :host([kind='danger-tertiary'][loading]) .button:focus {\n        background-color: transparent;\n        color: var(--ui-ink-disabled);\n    }\n    :host([kind='ghost'][disabled]) .button,\n    :host([kind='ghost'][disabled]) .button:hover,\n    :host([kind='ghost'][disabled]) .button:active,\n    :host([kind='ghost'][disabled]) .button:focus,\n    :host([kind='ghost'][disabled-focusable]) .button,\n    :host([kind='ghost'][disabled-focusable]) .button:hover,\n    :host([kind='ghost'][disabled-focusable]) .button:active,\n    :host([kind='ghost'][disabled-focusable]) .button:focus,\n    :host([kind='ghost'][loading]) .button,\n    :host([kind='ghost'][loading]) .button:hover,\n    :host([kind='ghost'][loading]) .button:active,\n    :host([kind='ghost'][loading]) .button:focus,\n    :host([kind='danger-ghost'][disabled]) .button,\n    :host([kind='danger-ghost'][disabled]) .button:hover,\n    :host([kind='danger-ghost'][disabled]) .button:active,\n    :host([kind='danger-ghost'][disabled]) .button:focus,\n    :host([kind='danger-ghost'][disabled-focusable]) .button,\n    :host([kind='danger-ghost'][disabled-focusable]) .button:hover,\n    :host([kind='danger-ghost'][disabled-focusable]) .button:active,\n    :host([kind='danger-ghost'][disabled-focusable]) .button:focus,\n    :host([kind='danger-ghost'][loading]) .button,\n    :host([kind='danger-ghost'][loading]) .button:hover,\n    :host([kind='danger-ghost'][loading]) .button:active,\n    :host([kind='danger-ghost'][loading]) .button:focus {\n        border-color: transparent;\n        background-color: transparent;\n        color: var(--ui-ink-disabled);\n    }\n    /* a focusable disabled (or loading) button still shows where focus is */\n    :host([disabled-focusable]) .button:focus,\n    :host([loading]) .button:focus {\n        outline: var(--ui-focus-width, 2px) solid var(--ui-focus);\n        outline-offset: var(--ui-focus-offset, -2px);\n    }\n    :host([disabled-focusable]) .button:focus:not(:focus-visible),\n    :host([loading]) .button:focus:not(:focus-visible) {\n        outline-color: var(--ui-pointer-focus, var(--ui-focus)); /* keyboard only in Kanok, as an enabled button */\n        transition-property: background-color, box-shadow, border-color;\n    }\n\n    /* Carbon icon-only: a square the height of the button, icon centred (ui-icon-button) */\n    :host([icon-only]) .button,\n    :host([icon-only][kind='ghost']) .button,\n    :host([icon-only][kind='danger-ghost']) .button {\n        inline-size: var(--ui-button-height-lg, var(--ui-field-height-lg, 48px));\n        min-inline-size: 0;\n        padding-block: 0;\n        padding-inline: 0;\n        justify-content: center;\n        gap: 0;\n    }\n\n    :host([icon-only][size='md']) .button {\n        inline-size: var(--ui-field-height-md, 40px);\n    }\n\n    :host([icon-only][size='lg']) .button {\n        inline-size: var(--ui-button-height-lg, var(--ui-field-height-lg, 48px));\n    }\n\n    :host([icon-only][size='sm']) .button {\n        inline-size: var(--ui-field-height-sm, 32px);\n    }\n\n    /* Carbon btn--icon-only: a square of the layout height (layout.size('height')), xl and 2xl too */\n    :host([icon-only][size='xl']) .button {\n        inline-size: var(--ui-button-height-xl, 64px);\n    }\n\n    :host([icon-only][size='2xl']) .button {\n        inline-size: var(--ui-button-height-2xl, 80px);\n    }\n\n    /* Carbon btn--icon-only.btn--ghost:focus: the 2px ring only, no focus-inset line */\n    :host([icon-only][kind='ghost']) .button:focus {\n        box-shadow: none;\n    }\n\n    /* not while disabled: the ghost's disabled grey (above) must win, as Carbon's btn--ghost:disabled */\n    :host([icon-only][kind='ghost']:not([disabled], [disabled-focusable], [loading])) .button {\n        color: var(--ui-icon-primary);\n    }\n\n    @media (forced-colors: active) {\n        .button {\n            border-color: ButtonText;\n        }\n        .spinner .track {\n            stroke: GrayText;\n        }\n        .spinner .arc {\n            stroke: CanvasText;\n        }\n        .button:focus {\n            outline-color: Highlight;\n        }\n    }\n\n    /* focused by its dialog right after a click (shared/quiet-focus): no keyboard ring in a design that sets --ui-pointer-focus */\n    :host([data-quiet-focus]) .button:focus {\n        outline-color: var(--ui-pointer-focus, var(--ui-focus));\n    }\n`;\n"
    },
    {
      "path": "src/primitives/button/button.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/button/button.ts",
      "content": "import { LitElement, html, nothing, svg } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { srOnlyStyles, uid } from '../shared/field.ts';\nimport { FormControlController } from '../shared/form-control.ts';\nimport { SlotController } from '../shared/slots.ts';\nimport { LocalizeController } from '../shared/localize.ts';\nimport { UiElement } from '../shared/element.ts';\nimport { followLink } from '../shared/navigate.ts';\nimport { busyPlace, type ButtonLoadingPosition } from '../../core/button.ts';\nimport { buttonStyles } from './button.styles.ts';\n\n/** Carbon's small Loading spinner (InlineLoading): a track and a 48 % arc on a 100-unit circle. */\nconst spinner = svg`<svg class=\"spinner\" viewBox=\"0 0 100 100\"><circle class=\"track\" cx=\"50%\" cy=\"50%\" r=\"42\"></circle><circle class=\"arc\" cx=\"50%\" cy=\"50%\" r=\"42\"></circle></svg>`;\n\nexport type ButtonKind =\n    | 'primary'\n    | 'secondary'\n    | 'tertiary'\n    | 'ghost'\n    | 'danger'\n    | 'danger-tertiary'\n    | 'danger-ghost';\n/** Same as `ButtonKind` (for code written with `variant`). */\nexport type ButtonVariant = ButtonKind; // NOSONAR S6564: public alias for teams used to `variant` (shadcn, MUI)\n/** Heights: sm 32px · md 40px · lg 48px (Carbon touch target) · xl 64px · 2xl 80px (Carbon: the label at the top). */\nexport type ButtonSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl';\nexport type { ButtonLoadingPosition } from '../../core/button.ts';\n\n/**\n * Carbon-style button (Carbon `Button`).\n *\n * Renders a native `<button>` so keyboard, focus and screen-reader semantics come for free.\n * Form-associated: `type=\"submit\"` / `type=\"reset\"` act on the surrounding `<form>`.\n *\n * Icon-only buttons must set `label` — aria-label on the host would not reach the inner `<button>`.\n *\n * - `href` renders a real link (`<a>`), announced as a link — use it for navigation.\n * - `loading`: looks disabled with Carbon's small spinner and never gets narrower; unlike Carbon it keeps focus\n *   (aria-disabled, not disabled), ignores clicks and announces `loading-label` (else `loading-text`) politely.\n *   `loading-position` (as MUI's `loadingPosition`): `end` (default; Carbon for IBM Products ActionSet) puts it where\n *   the trailing icon goes — in the room kept for one, the label stays; `start` puts it in the `prefix` icon's place,\n *   or without one in the label's place (Carbon Modal `loadingStatus`); `center` hides the content and centres it.\n *   Ghost kinds keep no room at the end, so `end` centres there; an icon-only button always centres it. `loading-text` (Carbon Modal\n *   `loadingDescription`) shows in the label's place; the button grows only if it is longer than the label.\n * - `disabled-focusable`: looks and acts disabled (aria-disabled, clicks and submit ignored) but stays in the\n *   Tab order, so a tooltip can say why — e.g. an action the user lacks permission for (Fluent UI\n *   `disabledFocusable`; Carbon's `disabled` removes it from the Tab order).\n * - `pressed` makes it a toggle button (aria-pressed).\n * - `haspopup` + `expanded` describe a button that opens a menu / listbox / dialog.\n * - `size`: sm 32 / md 40 / lg 48 (default) / xl 64 / 2xl 80px. Carbon's padding stops growing at lg's 14px, so on\n *   xl and 2xl the label and its icon stay at the top (the icon 1px lower, on the label's 18px line).\n * - `danger-description` (Carbon `dangerDescription`): what screen readers hear after the name of a danger kind\n *   (danger, danger-tertiary, danger-ghost), e.g. \"Deletes the contract for good\"; none by default, as Carbon.\n *\n * @slot - Label\n * @slot prefix - Leading icon\n * @slot suffix - Trailing icon (e.g. the ghost-button chevron)\n * @csspart base - The native button or link\n * @csspart prefix - The leading icon slot\n * @csspart suffix - The trailing icon slot\n * @csspart loading - The spinner's place: at the end, the start or the centre (`loading` only; not when it takes the label's place)\n * @cssprop --ui-button-align - `align-items` of the content (ui-modal sets `flex-start` for its 64px footer buttons)\n * @cssprop --ui-button-padding-top - Top padding of the content (ui-modal footer: 14px)\n * @cssprop --ui-button-padding-start - Start padding (default 15px; ui-table-batch-actions: 16px)\n * @cssprop --ui-button-padding-end - End padding (default 63px, Carbon's room for an icon; ui-table-batch-actions: 16px)\n * @attr variant - Same as `kind`, kept for teams used to `variant` (shadcn, MUI); `kind` is Carbon's name and the one in the docs\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-button-height-lg - Height of `size=\"lg\"`, the default (default: `--ui-field-height-lg`, 48px; Kanok: 32px)\n * @cssprop --ui-button-radius - Corner radius (default 0; Kanok: 6px)\n * @cssprop --ui-button-justify - `justify-content` of label and icon (default `space-between`, Carbon's label-start / icon-end; Kanok: `center`)\n * @cssprop --ui-button-gap - Gap between label and icon (default 32px; Kanok: 8px)\n * @cssprop --ui-button-ghost-justify - `justify-content` of the ghost kinds (default `flex-start`)\n * @cssprop --ui-button-ghost-padding-end - End padding of the ghost kinds (default 15px)\n * @cssprop --ui-button-secondary - Fill of `kind=\"secondary\"` (default `--ui-secondary`); also `--ui-button-secondary-hover`, `--ui-button-secondary-active`\n * @cssprop --ui-on-button-secondary - Text of `kind=\"secondary\"` (default `--ui-on-primary`)\n * @cssprop --ui-button-secondary-border - Border colour of `kind=\"secondary\"` (default transparent)\n * @cssprop --ui-button-height-xl - Height of `size=\"xl\"` (default 64px; Kanok: 40px); also `--ui-button-height-2xl` (80px; Kanok: 48px)\n * @cssprop --ui-button-padding-xl - Start and end padding of `size=\"xl\"` (default: the button's own); also `--ui-button-padding-2xl`\n * @cssprop --ui-button-tall-align - `align-items` of xl / 2xl content (default `flex-start`, Carbon's label at the top; Kanok: `center`)\n * @cssprop --ui-button-tall-padding-top - Top padding of xl / 2xl content (default 14px; Kanok: 0px); also `--ui-button-tall-icon-offset` (1px)\n * @cssprop --ui-focus-offset - `outline-offset` of the focus ring (default -2px, inside; Kanok: 2px, outside)\n * @cssprop --ui-focus-inset-width - Width of the inner focus-inset line (default 2px; Kanok: 0)\n * @cssprop --ui-button-tertiary-hover / --ui-button-tertiary-active / --ui-button-tertiary-focus - Tertiary fills (default primary, its hover and active; Kanok: the highlight tint)\n * @cssprop --ui-button-tertiary-state-ink / --ui-button-tertiary-active-border - Tertiary text on those fills and the pressed border (default text-on-color, the button's border)\n */\n@customElement('ui-button')\nexport class UiButton extends UiElement {\n    static readonly formAssociated = true;\n\n    static override readonly shadowRootOptions: ShadowRootInit = {\n        ...LitElement.shadowRootOptions,\n        delegatesFocus: true,\n    };\n\n    static override readonly styles = [srOnlyStyles, buttonStyles];\n\n    private readonly localize = new LocalizeController(this);\n\n    /** Carbon `kind`: primary, secondary, tertiary, ghost, danger, danger-tertiary, danger-ghost. */\n    @property({ type: String, reflect: true })\n    kind: ButtonKind = 'primary';\n\n    /** Same as `kind` (permanent alias for teams used to `variant`); a `variant` attribute works too. */\n    get variant(): ButtonKind {\n        return this.kind;\n    }\n\n    set variant(value: ButtonKind) {\n        this.kind = value;\n        if (this.hasAttribute('variant')) this.setAttribute('variant', value); // no stale attribute next to `kind`\n    }\n\n    static override get observedAttributes() {\n        return [...super.observedAttributes, 'variant'];\n    }\n\n    override attributeChangedCallback(name: string, old: string | null, value: string | null) {\n        if (name !== 'variant') super.attributeChangedCallback(name, old, value);\n        else if (value !== null) this.kind = value as ButtonKind;\n    }\n\n    @property({ type: String, reflect: true })\n    size: ButtonSize = 'lg';\n\n    @property({ type: Boolean, reflect: true })\n    disabled = false;\n\n    /** Disabled, but still focusable: aria-disabled, ignores clicks — so a tooltip can explain why. */\n    @property({ type: Boolean, reflect: true, attribute: 'disabled-focusable' })\n    disabledFocusable = false;\n\n    @property({ type: String })\n    type: 'button' | 'submit' | 'reset' = 'button';\n\n    /** Stretch to the container width. */\n    @property({ type: Boolean, reflect: true, attribute: 'full-width' })\n    fullWidth = false;\n\n    /**\n     * Square button (as wide as it is tall, no padding) with its content centred: put the icon in the `prefix`\n     * slot and leave the label empty — nothing is hidden for you. Set `label` for its name; it shows no tooltip\n     * (use `<ui-icon-button>` for one).\n     */\n    @property({ type: Boolean, reflect: true, attribute: 'icon-only' })\n    iconOnly = false;\n\n    /** Accessible name; required when the button shows only an icon. */\n    @property() label = '';\n\n    /** Accessible description (set by ui-tooltip). */\n    @property() description = '';\n\n    /**\n     * Carbon `dangerDescription`: read after the name of a danger kind (danger, danger-tertiary, danger-ghost), e.g.\n     * \"Deletes the contract for good\". Empty by default, as Carbon v11 (React `ButtonBase`, WC `cds-button`).\n     */\n    @property({ attribute: 'danger-description' }) dangerDescription = '';\n\n    /** Render as a link. */\n    @property() href = '';\n\n    @property() target: '_self' | '_blank' = '_self';\n\n    /** Busy: looks disabled with a spinner, ignores clicks, keeps focus, announces `loading-label`. */\n    @property({ type: Boolean, reflect: true }) loading = false;\n\n    /** What `loading` announces (default: `loading-text`, else the translation's \"Loading\"). */\n    @property({ attribute: 'loading-label' }) loadingLabel = '';\n\n    /** Where the spinner goes (MUI `loadingPosition`): `end` (Carbon ActionSet), `start`, `center`. */\n    @property({ attribute: 'loading-position', reflect: true }) loadingPosition: ButtonLoadingPosition = 'end';\n\n    /** Shown in the label's place while loading, e.g. \"Saving…\" (Carbon Modal `loadingDescription`). */\n    @property({ attribute: 'loading-text' }) loadingText = '';\n\n    /** Toggle-button state; leave unset for a normal button. */\n    @property({ type: Boolean, reflect: true }) pressed?: boolean;\n\n    /** The button opens a popup: rendered as `aria-haspopup` (e.g. `menu`, `listbox`, `dialog`). */\n    @property() haspopup = '';\n\n    /** Whether the popup / disclosed content is open (`aria-expanded`); left unset, only a `haspopup` button reports it. */\n    @property({ type: Boolean, reflect: true }) expanded?: boolean;\n\n    private readonly descriptionId = uid('ui-button-desc');\n    private readonly dangerId = uid('ui-button-danger');\n\n    /** Disabled as natively: its own `disabled`, a disabled `<fieldset>` or `<ui-form-group>` around it. */\n    private readonly formControl = new FormControlController(this);\n\n    /** The `<form>` the button submits or resets, as a native button's `form`. */\n    get form() {\n        return this.internals.form;\n    }\n\n    /** From an ancestor `<fieldset>`; kept apart so it never overwrites the author's `disabled`. */\n    formDisabledCallback(disabled: boolean) {\n        this.formControl.setFieldsetDisabled(disabled);\n    }\n\n    private get isDisabled() {\n        return this.formControl.disabled;\n    }\n\n    private handleClick(event: MouseEvent) {\n        if (this.isDisabled || this.disabledFocusable || this.loading) {\n            event.preventDefault();\n            event.stopImmediatePropagation();\n            return;\n        }\n        // The native button lives in shadow DOM, so it can't reach the outer `<form>` itself.\n        const form = this.internals.form;\n        if (!form) return;\n        if (this.type === 'submit') form.requestSubmit();\n        if (this.type === 'reset') form.reset();\n    }\n\n    /** Where the spinner goes: an icon-only button centres it in place of the icon; ghost kinds keep no room at the end, so `end` centres there. */\n    private get busyPlace(): ButtonLoadingPosition {\n        return busyPlace(this.loadingPosition, this.kind, this.iconOnly);\n    }\n\n    /** `start` with no prefix icon: the spinner (and its text) take the label's place, as Carbon Modal's InlineLoading. */\n    private get busyInline() {\n        return this.busyPlace === 'start' && !this.slots.has('prefix');\n    }\n\n    /** Which icons give way to the spinner. */\n    private get busyClass() {\n        if (!this.loading) return '';\n        const place = this.busyPlace;\n        if (place === 'center') return 'hide-prefix hide-suffix';\n        if (place === 'end') return this.slots.has('suffix') ? 'hide-suffix' : 'busy-end';\n        return this.busyInline ? '' : 'hide-prefix';\n    }\n\n    /** The label, and while loading the loading text (and spinner) in the same cell. */\n    private renderLabel() {\n        // a link has no loading state; an icon-only button's spinner replaces the icon, not a label\n        if (!this.loading || this.href || this.iconOnly) return html`<slot></slot>`;\n        const center = this.busyPlace === 'center';\n        const withSpinner = this.busyInline || center;\n        if (!withSpinner && !this.loadingText) return html`<span class=\"label\"><span class=\"label-text\"><slot></slot></span></span>`;\n        // centred, the spinner shows on its own (renderBusyMark): this see-through copy only keeps the room\n        const busy = this.renderBusy(withSpinner, center ? 'reserve' : '');\n        return html`<span class=\"label replaced\"><span class=\"label-text\"><slot></slot></span>${busy}</span>`;\n    }\n\n    /** The spinner and / or the loading text, 8px apart (Carbon InlineLoading). */\n    private renderBusy(withSpinner: boolean, extra = '') {\n        const text = this.loadingText ? html`<span>${this.loadingText}</span>` : nothing;\n        return html`<span class=\"busy ${extra}\" aria-hidden=\"true\">${withSpinner ? spinner : nothing}${text}</span>`;\n    }\n\n    /** The spinner on its own: at the trailing icon's place, the prefix icon's, or centred with the loading text. */\n    private renderBusyMark() {\n        const place = this.busyPlace;\n        if (!this.loading || this.busyInline) return nothing;\n        // centred, the loading text goes with it; at the end or the prefix's place it stays in the label's place\n        const mark = place === 'center' ? this.renderBusy(true) : html`<span class=\"busy\">${spinner}</span>`;\n        return html`<span class=\"busy-mark ${place}\" part=\"loading\" aria-hidden=\"true\">${mark}</span>`;\n    }\n\n    private renderContent() {\n        return html`\n            <slot name=\"prefix\" part=\"prefix\"></slot>\n            ${this.renderLabel()}\n            <slot name=\"suffix\" part=\"suffix\"></slot>\n            <slot name=\"badge-indicator\"></slot>\n        `;\n    }\n\n    /** Carbon reads `dangerDescription` only for the danger kinds. */\n    private get hasDangerDescription() {\n        return this.kind.startsWith('danger') && !!this.dangerDescription;\n    }\n\n    /** The danger description first (Carbon's), then the tooltip's. */\n    private get describedBy() {\n        const ids = [this.hasDangerDescription ? this.dangerId : '', this.description ? this.descriptionId : ''].filter(Boolean);\n        return ids.length ? ids.join(' ') : nothing;\n    }\n\n    /** A visually hidden description, beside the control: inside it (as Carbon's danger one) it would also join the button's name. */\n    private renderHidden(id: string, text: string) {\n        return text ? html`<span class=\"sr-only\" id=${id}>${text}</span>` : nothing;\n    }\n\n    private renderDescription() {\n        return [this.renderHidden(this.dangerId, this.hasDangerDescription ? this.dangerDescription : ''), this.renderHidden(this.descriptionId, this.description)];\n    }\n\n    private readonly slots = new SlotController(this);\n\n    private get suffixClass() {\n        return this.slots.has('suffix') ? 'has-suffix' : '';\n    }\n\n    /**\n     * A real link; disabled links drop href so they can't be followed or focused.\n     * Both renders carry tabindex=\"0\" as Carbon's cds-button does: without it Safari neither focuses the\n     * control on click (no :focus ring) nor stops on it with Tab.\n     */\n    private renderLink() {\n        const external = this.target === '_blank';\n        return html`<a\n            part=\"base\"\n            class=\"button ${this.isDisabled || this.disabledFocusable ? 'is-disabled' : ''} ${this.suffixClass}\"\n            href=${this.isDisabled || this.disabledFocusable ? nothing : this.href}\n            target=${this.isDisabled || this.disabledFocusable ? nothing : this.target}\n            rel=${external ? 'noopener noreferrer' : nothing}\n            role=${this.disabledFocusable ? 'link' : nothing}\n            tabindex=${this.isDisabled && !this.disabledFocusable ? nothing : '0'}\n            aria-disabled=${this.isDisabled || this.disabledFocusable ? 'true' : nothing}\n            aria-label=${this.label || nothing}\n            aria-describedby=${this.describedBy}\n            @click=${followLink}\n        >\n            ${this.renderContent()}\n        </a>`;\n    }\n\n    private renderButton() {\n        return html`<button\n            part=\"base\"\n            class=\"button ${this.suffixClass} ${this.busyClass}\"\n            type=\"button\"\n            tabindex=\"0\"\n            ?disabled=${this.isDisabled}\n            aria-disabled=${this.loading || this.disabledFocusable ? 'true' : nothing}\n            aria-pressed=${this.pressed === undefined ? nothing : String(this.pressed)}\n            aria-haspopup=${this.haspopup || nothing}\n            aria-expanded=${this.haspopup || this.expanded !== undefined ? String(!!this.expanded) : nothing}\n            aria-label=${this.label || nothing}\n            aria-describedby=${this.describedBy}\n            @click=${this.handleClick}\n        >\n            ${this.renderContent()}\n            ${this.renderBusyMark()}\n        </button>`;\n    }\n\n    override render() {\n        return html`\n            ${this.href ? this.renderLink() : this.renderButton()}\n            ${this.renderDescription()}\n            <span class=\"sr-only\" role=\"status\">${this.loading ? this.loadingLabel || this.loadingText || this.localize.t.common.loading : ''}</span>\n        `;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-button': UiButton;\n    }\n}\n"
    }
  ]
}
