{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "checkbox",
  "type": "registry:ui",
  "title": "<ui-checkbox>",
  "description": "Carbon-style checkbox. Wraps a native checkbox (kept in the accessibility tree, visually replaced by a 16px square) inside a `<label>`, so the whole row is clickable. 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/shared-element",
    "@kanok-ui/shared-field",
    "@kanok-ui/shared-form-control",
    "@kanok-ui/shared-localize",
    "@kanok-ui/shared-skeleton",
    "@kanok-ui/shared-slots",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/checkbox/checkbox-group.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/checkbox/checkbox-group.ts",
      "content": "import { html, css, nothing } from 'lit';\nimport { customElement, property, queryAssignedElements, state } from 'lit/decorators.js';\nimport { fieldTextStyles, messageId, pickMessage, renderMessage, uid, renderLabelText, barWhenDisabled, customErrorMessage, pickErrorText, type MessageKind } from '../shared/field.ts';\nimport { FormControlController } from '../shared/form-control.ts';\nimport { SlotController } from '../shared/slots.ts';\nimport type { UiCheckbox } from './checkbox.ts';\nimport { LocalizeController } from '../shared/localize.ts';\nimport { UiElement } from '../shared/element.ts';\n\n/**\n * A labelled group of `<ui-checkbox>` or `<ui-selectable-tile>` (Carbon checkbox group), exposed as role=\"group\"\n * with the label as its name and the helper / warning / error text as its description.\n *\n * - `required` means \"at least one\": the form won't submit until one box is checked.\n * - `disabled` / `readonly` apply to every box without overwriting each box's own setting.\n * - Each checkbox still submits its own `name` / `value`.\n *\n * State on the host for styling: `data-show-error` while the error shows, `data-show-warn` while the\n * warning shows.\n *\n * @cssstate show-error - While its error message shows (also `[data-show-error]`)\n * @cssstate show-warn - While its warning message shows (also `[data-show-warn]`)\n * @slot - `<ui-checkbox>` or `<ui-selectable-tile>` elements\n * @slot label - Label content with markup; the `label` attribute is the plain-text fallback\n * @slot helper-text - Helper text with markup (links, bold); overrides `helper-text`\n * @slot warn-text - Warning text shown while `warn`; overrides `warn-text`\n * @slot invalid-text - Error text shown while invalid; overrides `invalid-text`\n * @csspart base - The group box holding the checkboxes\n * @csspart label - The group label\n * @csspart status-icon - The error / warning icon\n * @csspart helper-text - The helper line\n * @csspart warning-text - The warning line\n * @csspart warn-text - Same line as `warning-text` (named after the `warn-text` attribute / slot)\n * @csspart error-text - The error line\n * @csspart invalid-text - Same line as `error-text` (named after the `invalid-text` attribute / slot)\n */\n@customElement('ui-checkbox-group')\nexport class UiCheckboxGroup extends UiElement {\n    static override hostStates: readonly string[] = ['show-error', 'show-warn'];\n\n    static readonly formAssociated = true;\n\n    static override readonly styles = [\n        fieldTextStyles,\n        css`\n            :host {\n                display: block;\n                font-family: var(--ui-font-family);\n            }\n\n            .options {\n                display: flex;\n                flex-direction: column;\n            }\n\n            :host([orientation='horizontal']) .options {\n                flex-direction: row;\n                flex-wrap: wrap;\n                gap: var(--ui-space-md);\n            }\n        `,\n    ];\n\n    /** Visible label text; the `label` slot replaces it when markup is needed. */\n    @property() label = '';\n\n    private readonly localize = new LocalizeController(this);\n\n    /** Keep the group label for screen readers but don't show it. */\n    @property({ type: Boolean, attribute: 'hide-label' }) hideLabel = false;\n\n    /** Helper text under the field, shown while there is no error or warning. */\n    @property({ attribute: 'helper-text' }) helperText = '';\n\n    /** Blocks form submission while the field is empty. */\n    @property({ type: Boolean, reflect: true }) required = false;\n\n    /** Error for an empty required group. */\n    @property({ attribute: 'required-text' }) requiredText = '';\n\n    /** Forces the error state, e.g. after server-side validation. */\n    @property({ type: Boolean, reflect: true }) invalid = false;\n\n    /** Error text shown while `invalid` or while the field fails validation. */\n    @property({ attribute: 'invalid-text' }) invalidText = '';\n\n    /** Non-blocking warning; shown when there is no error. */\n    @property({ type: Boolean, reflect: true }) warn = false;\n\n    /** Text of the warning shown while `warn`. */\n    @property({ attribute: 'warn-text' }) warnText = '';\n\n    /** Disables the control; a disabled `<fieldset>` ancestor does the same. */\n    @property({ type: Boolean, reflect: true }) disabled = false;\n\n    /** Shows and submits the value but blocks changes. */\n    @property({ type: Boolean, reflect: true }) readonly = false;\n\n    @property({ reflect: true }) orientation: 'vertical' | 'horizontal' = 'vertical';\n\n    @state() private touched = false;\n\n    @state() private checkedCount = 0;\n\n    /** Disabled, reset defaults, validation on submit and the name given from outside (shared by the form fields). */\n    private readonly formControl = new FormControlController(this, { reveal: () => (this.touched = true) });\n\n    /** `ui-selectable-tile` is a `ui-checkbox` too, so tiles are members like boxes. */\n    @queryAssignedElements({ selector: 'ui-checkbox, ui-selectable-tile' }) private readonly boxes!: UiCheckbox[];\n\n\n    /** Message from `setCustomValidity()`; '' = none. */\n    private customValidityMessage = '';\n\n    /** Like `<input>.setCustomValidity()`: a non-empty message makes the field invalid (and is shown as its error once touched) until cleared with ''. */\n    setCustomValidity(message: string) {\n        this.customValidityMessage = message;\n        if (!this.hasUpdated) return;\n        this.syncValidity();\n        this.requestUpdate();\n    }\n    private readonly groupId = uid('ui-checkbox-group');\n\n    override connectedCallback() {\n        super.connectedCallback();\n        this.addEventListener('change', this.onChange);\n        this.addEventListener('focusout', this.onFocusOut);\n    }\n\n    override disconnectedCallback() {\n        super.disconnectedCallback();\n        this.removeEventListener('change', this.onChange);\n        this.removeEventListener('focusout', this.onFocusOut);\n    }\n\n    get form() {\n        return this.internals.form;\n    }\n\n    get validationMessage() {\n        return this.internals.validationMessage;\n    }\n\n    /** Whether the field takes part in constraint validation (not while disabled), as natively. */\n    get willValidate() {\n        return this.internals.willValidate;\n    }\n\n    /** The `<label>`s that point at this field. */\n    get labels() {\n        return this.internals.labels;\n    }\n\n    reportValidity() {\n        return this.formControl.reportValidity(this.internals);\n    }\n\n    get validity() {\n        return this.internals.validity;\n    }\n\n    checkValidity() {\n        return this.internals.checkValidity();\n    }\n\n    override focus(options?: FocusOptions) {\n        this.boxes[0]?.focus(options);\n    }\n\n    formResetCallback() {\n        this.touched = false;\n        // Boxes reset themselves; recount once they have.\n        queueMicrotask(() => this.recount());\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 get interactive() {\n        return !this.isDisabled && !this.readonly;\n    }\n\n    private get showError() {\n        if (!this.interactive) return false;\n        return this.invalid || (this.touched && (!!this.customValidityMessage || (this.required && this.checkedCount === 0)));\n    }\n\n    /** Count from the boxes on every update, so a box checked / unchecked from code can't leave a stale `required` state. */\n    protected override willUpdate() {\n        this.recount();\n    }\n\n    protected override updated() {\n        this.syncBoxes();\n        this.syncValidity();\n        this.syncHostState();\n    }\n\n    /** Kind of the message the last render showed, for the host state attributes. */\n    private shownKind?: MessageKind;\n\n    private syncHostState() {\n        this.toggleAttribute('data-show-error', this.shownKind === 'error');\n        this.toggleAttribute('data-show-warn', this.shownKind === 'warn');\n    }\n\n    private syncValidity() {\n        if (barWhenDisabled(this.internals, this.isDisabled)) return;\n        const anchor = this.boxes[0];\n        const customError = customErrorMessage(this.invalid, this.invalidText, this.customValidityMessage);\n        if (customError) {\n            this.internals.setValidity({ customError: true }, customError, anchor);\n        } else if (this.required && this.checkedCount === 0 && !this.isDisabled) {\n            this.internals.setValidity({ valueMissing: true }, this.invalidText || (this.requiredText || this.localize.t.field.requiredAtLeastOne), anchor);\n        } else {\n            this.internals.setValidity({});\n        }\n    }\n\n    private recount() {\n        this.checkedCount = this.boxes.filter((b) => b.checked).length;\n    }\n\n    /** The visible error text: the attribute, else the slotted `invalid-text`, else the required message. */\n    private get errorText() {\n        return this.invalidText || this.querySelector('[slot=\"invalid-text\"]')?.textContent?.trim() || (this.requiredText || this.localize.t.field.requiredAtLeastOne);\n    }\n\n    private syncBoxes() {\n        const showError = this.showError;\n        for (const box of this.boxes) {\n            box.groupDisabled = this.isDisabled;\n            box.groupReadonly = this.readonly;\n            box.toggleAttribute('data-group-invalid', showError);\n            box.groupMessage = showError ? this.errorText : '';\n        }\n    }\n\n    private readonly onChange = () => {\n        this.touched = true;\n        this.recount();\n    };\n\n    private readonly onFocusOut = (event: FocusEvent) => {\n        if (!this.contains(event.relatedTarget as Node)) this.touched = true;\n    };\n\n    private onSlotChange() {\n        this.recount();\n        this.syncBoxes();\n    }\n\n    private readonly slots = new SlotController(this);\n\n    private renderLabel() {\n        if (!this.label && !this.slots.has('label')) return nothing;\n        return html`<div class=${this.hideLabel ? 'sr-only' : 'label'} part=\"label\" id=\"${this.groupId}-label\">${renderLabelText(this.label, this.formControl.fallbackName(this.label, this.internals))}</div>`;\n    }\n\n    override render() {\n        const showError = this.showError;\n        const message = pickMessage({\n            showError,\n            errorText: pickErrorText(this.invalid, this.customValidityMessage, this.invalidText || (this.requiredText || this.localize.t.field.requiredAtLeastOne)),\n            showWarn: this.warn && this.interactive,\n            warnText: this.warnText,\n            helperText: this.helperText,\n            slots: this.slots,\n        });\n        this.shownKind = message?.kind;\n        return html`\n            ${this.renderLabel()}\n            <div\n                class=\"options\"\n                part=\"base\"\n                role=\"group\"\n                aria-labelledby=${this.label || this.slots.has('label') || this.formControl.fallbackName(this.label, this.internals) ? `${this.groupId}-label` : nothing}\n                aria-describedby=${messageId(this.groupId, message) ?? nothing}\n            >\n                <slot @slotchange=${this.onSlotChange}></slot>\n            </div>\n            ${renderMessage(this.groupId, message, true)}\n        `;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-checkbox-group': UiCheckboxGroup;\n    }\n}\n"
    },
    {
      "path": "src/primitives/checkbox/checkbox-skeleton.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/checkbox/checkbox-skeleton.ts",
      "content": "import { html, css } from 'lit';\nimport { customElement } from 'lit/decorators.js';\nimport { skeletonStyles, UiSkeletonElement } from '../shared/skeleton.ts';\n\n/**\n * Carbon `CheckboxSkeleton` (`cds-checkbox-skeleton`): an empty 16px box and a 100×16 label bar. Hidden from\n * assistive tech.\n *\n * @csspart box - The empty box\n * @csspart label - The label bar\n */\n@customElement('ui-checkbox-skeleton')\nexport class UiCheckboxSkeleton extends UiSkeletonElement {\n    static override readonly styles = [\n        skeletonStyles,\n        css`\n            :host {\n                display: block;\n            }\n\n            .row {\n                position: relative;\n                block-size: 20px;\n            }\n\n            /* where <ui-checkbox> draws its box (Carbon: 3px in, 3px down) */\n            .box {\n                position: absolute;\n                inset-block-start: 3px;\n                inset-inline-start: 3px;\n                box-sizing: border-box;\n                inline-size: 16px;\n                block-size: 16px;\n                border: 1px solid var(--ui-icon-primary);\n                border-radius: 2px;\n            }\n\n            .label {\n                position: absolute;\n                inset-block-start: 2px;\n                inset-inline-start: 26px;\n                inline-size: 100px;\n                block-size: 16px;\n            }\n        `,\n    ];\n\n    override render() {\n        return html`<div class=\"row\"><span class=\"box\" part=\"box\"></span><span class=\"bone label\" part=\"label\"></span></div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-checkbox-skeleton': UiCheckboxSkeleton;\n    }\n}\n"
    },
    {
      "path": "src/primitives/checkbox/checkbox.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/checkbox/checkbox.ts",
      "content": "import { LitElement, html, css, nothing } from 'lit';\nimport { customElement, property, query, state } from 'lit/decorators.js';\nimport { fieldTextStyles, messageId, pickMessage, renderMessage, uid, barWhenDisabled, isLabelClick, customErrorMessage, pickErrorText, type MessageKind } from '../shared/field.ts';\nimport { FormControlController } from '../shared/form-control.ts';\nimport { UiElement } from '../shared/element.ts';\n\n/**\n * Carbon-style checkbox. Wraps a native checkbox (kept in the accessibility tree,\n * visually replaced by a 16px square) inside a `<label>`, so the whole row is clickable.\n *\n * Group several in a `<ui-checkbox-group label=\"…\">` (a labelled group with its own helper / warning / error line).\n * Form-associated: submits `value` when checked; `required` blocks submit until checked.\n * `readonly` keeps the state (and submits it) but blocks toggling. `hide-label` keeps the\n * label for screen readers only (e.g. a checkbox in a table row).\n *\n * State on the host for styling: `data-show-error` while the box shows an error (its own, or its\n * `<ui-checkbox-group>`'s, which reddens every enabled, editable box), `data-show-warn` while its own\n * warning shows.\n *\n * @cssstate show-error - While its error message shows (also `[data-show-error]`)\n * @cssstate show-warn - While its warning message shows (also `[data-show-warn]`)\n * @slot - Label text\n * @fires change - When the user toggles the box\n * @csspart base - The clickable row (label element)\n * @csspart control - The native checkbox input\n * @csspart box - The drawn 16px box\n * @csspart label - The text beside the box\n * @csspart status-icon - The error / warning icon\n * @csspart helper-text - The helper line\n * @csspart warning-text - The warning line\n * @csspart warn-text - Same line as `warning-text` (named after the `warn-text` attribute / slot)\n * @csspart error-text - The error line\n * @csspart invalid-text - Same line as `error-text` (named after the `invalid-text` attribute / slot)\n * @cssprop --ui-checkbox-border - Border of the box (default `--ui-ink`; Kanok: `--ui-ink-subtle`)\n * @cssprop --ui-checkbox-checked - Fill and border when checked or mixed (default `--ui-ink`; Kanok: `--ui-primary`)\n * @cssprop --ui-checkbox-mark - Check mark colour (default `--ui-icon-inverse`; Kanok: `--ui-on-primary`)\n */\n@customElement('ui-checkbox')\nexport class UiCheckbox extends UiElement {\n    static override hostStates: readonly string[] = ['show-error', 'show-warn'];\n\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 = [\n        fieldTextStyles,\n        css`\n            :host {\n                display: block;\n                font-family: var(--ui-font-family);\n            }\n\n            label {\n                position: relative;\n                display: inline-flex;\n                align-items: flex-start;\n                gap: 14px; /* Carbon: 20px label inset + 10px text inset − 16px box */\n                min-height: 24px;\n                padding-block: 4px;\n                box-sizing: border-box;\n                font: var(--ui-font-body-sm);\n                letter-spacing: var(--ui-tracking-body);\n                color: var(--ui-ink);\n                cursor: pointer;\n            }\n\n            /* Native input sits exactly on top of the box: invisible, but focusable and clickable */\n            input {\n                position: absolute;\n                top: 4px;\n                inset-inline-start: 0;\n                z-index: 1; /* above the now-positioned .box so clicks still land on the input */\n                width: 16px;\n                height: 16px;\n                margin: 0;\n                opacity: 0;\n                cursor: inherit;\n            }\n\n            .box {\n                position: relative;\n                display: block;\n                flex-shrink: 0;\n                width: 16px;\n                height: 16px;\n                margin-top: 1px;\n                box-sizing: border-box;\n                /* --ui-checkbox-border / -checked / -mark: Carbon draws in primary ink; a design can use its brand colour */\n                border: 1px solid var(--ui-checkbox-border, var(--ui-ink));\n                border-radius: var(--ui-radius-xs);\n                background-color: transparent; /* Carbon: a filled box looks off on tinted layers */\n                color: var(--ui-checkbox-mark, var(--ui-icon-inverse)); /* Carbon: the check mark is icon-inverse on the icon-primary box */\n            }\n\n            /* Carbon's check mark: a 9×5 L of 1.5px borders rotated −45° about its bottom-right corner (checkbox.scss ::after) */\n            .box::after {\n                content: '';\n                position: absolute;\n                /* Carbon frame: box at 3px from the label, mark at 7px → 4px / 0.5px from the box edge; our frame is the 1px-bordered box, hence 3 / -0.5 */\n                top: -0.5px;\n                inset-inline-start: 3px;\n                box-sizing: border-box;\n                width: 9px;\n                height: 5px;\n                border-bottom: 1.5px solid currentColor;\n                border-left: 1.5px solid currentColor;\n                transform: scale(0) rotate(-45deg);\n                transform-origin: bottom right;\n            }\n\n            input:checked + .box,\n            input:indeterminate + .box {\n                border-color: var(--ui-checkbox-checked, var(--ui-ink));\n                background-color: var(--ui-checkbox-checked, var(--ui-ink));\n            }\n\n            input:checked + .box::after {\n                transform: scale(1) rotate(-45deg);\n            }\n\n            input:indeterminate + .box::after {\n                top: 4px; /* Carbon indeterminate: 8px bar, 2px thick, 11px − 3px margin from the label → rows 8–10 of the 16px box, 1px below centre as on Carbon (kept on purpose, user's choice 2026-10-05) */\n                inset-inline-start: 3px;\n                width: 8px;\n                border-left-width: 0;\n                border-bottom-width: 2px;\n                transform: scale(1) rotate(0deg);\n            }\n\n            /* Carbon checkbox:focus (not :focus-visible), so a click shows the ring too */\n            input:focus + .box {\n                outline: var(--ui-focus-width, 2px) solid var(--ui-focus);\n                outline-offset: 1px;\n            }\n\n            /* a mouse or touch focus shows no ring in a design that sets --ui-pointer-focus (Kanok: keyboard only) */\n            input:focus:not(:focus-visible) + .box {\n                outline-color: var(--ui-pointer-focus, var(--ui-focus));\n            }\n\n            .invalid .box,\n            :host([data-group-invalid]) .box {\n                border: 2px solid var(--ui-error);\n            }\n\n            :host([data-disabled]) label {\n                color: var(--ui-ink-disabled);\n                cursor: not-allowed;\n            }\n\n            :host([data-disabled]) .box {\n                border-color: var(--ui-ink-disabled);\n            }\n\n            :host([data-disabled]) input:checked + .box,\n            :host([data-disabled]) input:indeterminate + .box {\n                background-color: var(--ui-ink-disabled);\n            }\n\n            :host([data-readonly]) label {\n                cursor: default;\n            }\n\n            :host([data-readonly]) .box {\n                border-color: var(--ui-ink-subtle);\n            }\n\n            :host([data-readonly]) input:checked + .box,\n            :host([data-readonly]) input:indeterminate + .box {\n                background-color: var(--ui-ink-muted);\n            }\n\n            .error,\n            .warn,\n            .helper {\n                padding-inline-start: calc(16px + var(--ui-space-xs));\n            }\n\n            @media (forced-colors: active) {\n                .box {\n                    border-color: CanvasText;\n                    forced-color-adjust: none;\n                }\n                input:checked + .box,\n                input:indeterminate + .box {\n                    background-color: Highlight;\n                    color: HighlightText;\n                }\n            }\n        `,\n    ];\n\n    @property({ type: Boolean, reflect: true }) checked = false;\n\n    /** Mixed state, e.g. a \"select all\" box with some children checked. Cleared on user toggle. */\n    @property({ type: Boolean, reflect: true }) indeterminate = false;\n\n    /** Disables the control; a disabled `<fieldset>` ancestor does the same. */\n    @property({ type: Boolean, reflect: true }) disabled = false;\n\n    /** Blocks form submission while the field is empty. */\n    @property({ type: Boolean, reflect: true }) required = false;\n\n    /** Shows and submits the value but blocks changes. */\n    @property({ type: Boolean, reflect: true }) readonly = false;\n\n    /** Set by ui-checkbox-group; kept apart from the author's own disabled / readonly. */\n    @property({ attribute: false }) groupDisabled = false;\n\n    @property({ attribute: false }) groupReadonly = false;\n\n    /**\n     * Error text of the owning ui-checkbox-group while the group is invalid. The group shows it once below\n     * the boxes; each box repeats it as its own accessible description and reports aria-invalid, so a screen\n     * reader landing on the first box hears why (an IDREF cannot cross the group's shadow root).\n     */\n    @property({ attribute: false }) groupMessage = '';\n\n    /** Keep the label text for screen readers but don't show it. */\n    @property({ type: Boolean, attribute: 'hide-label' }) hideLabel = false;\n\n    /** Reflected: form-associated elements submit under the `name` attribute. */\n    @property({ reflect: true }) name = '';\n\n    @property() value = 'on';\n\n    /** Helper text under the field, shown while there is no error or warning. */\n    @property({ attribute: 'helper-text' }) helperText = '';\n\n    /** Error text shown while `invalid` or while the field fails validation. */\n    @property({ attribute: 'invalid-text' }) invalidText = '';\n\n    /** Forces the error state, e.g. after server-side validation. */\n    @property({ type: Boolean, reflect: true }) invalid = false;\n\n    /** Non-blocking warning; shown when there is no error. */\n    @property({ type: Boolean, reflect: true }) warn = false;\n\n    /** Text of the warning shown while `warn`. */\n    @property({ attribute: 'warn-text' }) warnText = '';\n\n    @state() private touched = false;\n\n    /** Disabled, reset defaults, validation on submit and the name given from outside (shared by the form fields). */\n    private readonly formControl = new FormControlController(this, { reveal: () => (this.touched = true) });\n\n    @query('input') private readonly input!: HTMLInputElement;\n\n\n    /** Message from `setCustomValidity()`; '' = none. */\n    private customValidityMessage = '';\n\n    /** Like `<input>.setCustomValidity()`: a non-empty message makes the field invalid (and is shown as its error once touched) until cleared with ''. */\n    setCustomValidity(message: string) {\n        this.customValidityMessage = message;\n        if (!this.hasUpdated) return;\n        this.syncValidity();\n        this.requestUpdate();\n    }\n    private readonly inputId = uid('ui-checkbox');\n\n    /** An explicit tabindex for the native control (none: Carbon's checkbox has none; the selectable tile sets \"0\"). */\n    protected readonly controlTabIndex: string | undefined = undefined;\n    private defaultChecked = false;\n\n    constructor() {\n        super();\n        this.addEventListener('click', this.onLabelClick);\n    }\n\n    /** `<label for>` / a wrapping label: toggle like a click on the box. */\n    private readonly onLabelClick = (event: MouseEvent) => {\n        if (isLabelClick(this, event) && !this.isDisabled && !this.isReadonly) this.input.click();\n    };\n\n    override connectedCallback() {\n        super.connectedCallback();\n        // first connection only: moving the element must not change what reset goes back to\n        this.formControl.captureDefaults(() => {\n            this.defaultChecked = this.checked;\n        });\n    }\n\n    override disconnectedCallback() {\n        super.disconnectedCallback();\n    }\n\n    get form() {\n        return this.internals.form;\n    }\n\n    get validationMessage() {\n        return this.internals.validationMessage;\n    }\n\n    /** Whether the field takes part in constraint validation (not while disabled), as natively. */\n    get willValidate() {\n        return this.internals.willValidate;\n    }\n\n    /** The `<label>`s that point at this field. */\n    get labels() {\n        return this.internals.labels;\n    }\n\n    reportValidity() {\n        return this.formControl.reportValidity(this.internals);\n    }\n\n    get validity() {\n        return this.internals.validity;\n    }\n\n    checkValidity() {\n        return this.internals.checkValidity();\n    }\n\n    formResetCallback() {\n        this.checked = this.defaultChecked;\n        this.touched = false;\n    }\n\n\n    /** Back/forward cache hands the saved checked state back here. */\n    formStateRestoreCallback(state: string | File | FormData | null) {\n        if (typeof state === 'string') this.checked = state === 'true';\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 || this.groupDisabled;\n    }\n\n    private get interactive() {\n        return !this.isDisabled && !this.isReadonly;\n    }\n\n    private get isReadonly() {\n        return this.readonly || this.groupReadonly;\n    }\n\n    protected override updated(changed: Map<string, unknown>) {\n        // a group's `required` depends on its boxes; tell it when this one changes (also from code)\n        if (changed.has('checked')) this.closest('ui-checkbox-group')?.requestUpdate();\n        this.toggleAttribute('data-disabled', this.isDisabled);\n        this.toggleAttribute('data-readonly', this.isReadonly);\n        this.input.indeterminate = this.indeterminate;\n        this.syncValidity();\n        this.syncHostState();\n    }\n\n    /** Kind of the message the last render showed, for the host state attributes. */\n    private shownKind?: MessageKind;\n\n    /** The group's error reddens the box too (`data-group-invalid`), except where disabled / read-only recolour it. */\n    private syncHostState() {\n        this.toggleAttribute('data-show-error', this.shownKind === 'error' || (this.groupMessage !== '' && this.interactive));\n        this.toggleAttribute('data-show-warn', this.shownKind === 'warn');\n    }\n\n    private syncValidity() {\n        if (barWhenDisabled(this.internals, this.isDisabled)) return;\n        this.internals.setFormValue(this.checked ? this.value : null, String(this.checked));\n        const customError = customErrorMessage(this.invalid, this.invalidText, this.customValidityMessage);\n        if (customError) {\n            this.internals.setValidity({ customError: true }, customError, this.input);\n        } else if (this.required && !this.checked) {\n            this.internals.setValidity({ valueMissing: true }, this.input.validationMessage || ' ', this.input);\n        } else {\n            this.internals.setValidity({});\n        }\n    }\n\n    /** Readonly: cancel the toggle (click and Space both arrive as a click). */\n    private onClick(event: MouseEvent) {\n        if (this.isReadonly) event.preventDefault();\n    }\n\n    /** The native `input` reaches the page after this runs, so listeners already read the new `checked`. */\n    private onInput() {\n        this.checked = this.input.checked;\n        this.indeterminate = false;\n    }\n\n    private onChange() {\n        this.checked = this.input.checked;\n        this.indeterminate = false;\n        this.touched = true;\n        this.dispatchEvent(new Event('change', { bubbles: true }));\n    }\n\n    /** The visible box next to the label (the selectable tile draws Carbon's checkbox icon instead). */\n    protected renderBox() {\n        return html`<span class=\"box\" part=\"box\" aria-hidden=\"true\"></span>`;\n    }\n\n    override render() {\n        const showError =\n            this.interactive && (this.invalid || (this.touched && (!!this.customValidityMessage || (this.required && !this.checked))));\n        const message = pickMessage({\n            showError,\n            errorText: pickErrorText(this.invalid, this.customValidityMessage, this.invalidText || this.input?.validationMessage || ''),\n            showWarn: this.warn && this.interactive,\n            warnText: this.warnText,\n            helperText: this.helperText,\n        });\n        this.shownKind = message?.kind;\n\n        const groupMessageId = this.groupMessage ? `${this.inputId}-group-message` : undefined;\n        const describedBy = [messageId(this.inputId, message), groupMessageId].filter(Boolean).join(' ') || nothing;\n\n        return html`\n            <label class=${showError ? 'invalid' : ''} part=\"base\">\n                <input\n                    part=\"control\"\n                    id=${this.inputId}\n                    type=\"checkbox\"\n                    tabindex=${this.controlTabIndex ?? nothing}\n                    .checked=${this.checked}\n                    ?disabled=${this.isDisabled}\n                    ?required=${this.required}\n                    aria-readonly=${this.isReadonly ? 'true' : nothing}\n                    aria-invalid=${showError || groupMessageId ? 'true' : 'false'}\n                    aria-describedby=${describedBy}\n                    @click=${this.onClick}\n                    @input=${this.onInput}\n                    @change=${this.onChange}\n                />\n                ${this.renderBox()}\n                <span class=${this.hideLabel ? 'sr-only' : ''} part=\"label\"><slot></slot></span>\n            </label>\n            ${renderMessage(this.inputId, message, true)}\n            ${groupMessageId ? html`<span class=\"sr-only\" id=${groupMessageId}>${this.groupMessage}</span>` : nothing}\n        `;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-checkbox': UiCheckbox;\n    }\n}\n"
    }
  ]
}
