{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "number-input",
  "type": "registry:ui",
  "title": "<ui-number-input>",
  "description": "Carbon-style number input (`NumberInput`): a native `type=\"number\"` field with the browser spinner replaced by Carbon's two 40px stepper buttons (− then +, divided by hairlines) at the end of the field. ↑ / ↓ step as well. The value is kept as text so the field can be empty. 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-number-format",
    "@kanok-ui/shared-affixes",
    "@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/number-input/number-input-skeleton.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/number-input/number-input-skeleton.ts",
      "content": "import { customElement } from 'lit/decorators.js';\nimport { UiFieldSkeleton } from '../shared/skeleton.ts';\n\n/**\n * Carbon `NumberInputSkeleton` (`cds-number-input-skeleton`): the shape of a `<ui-number-input>` while its data loads — a 75×14 label bar, 8px, then\n * the field's bar at its `size` (sm 32 / md 40 / lg 48px). Hidden from assistive tech.\n *\n * @csspart label - The label bar\n * @csspart field - The field bar\n */\n@customElement('ui-number-input-skeleton')\nexport class UiNumberInputSkeleton extends UiFieldSkeleton {}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-number-input-skeleton': UiNumberInputSkeleton;\n    }\n}\n"
    },
    {
      "path": "src/primitives/number-input/number-input.styles.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/number-input/number-input.styles.ts",
      "content": "import { css } from 'lit';\n\n/** Styles of `<ui-number-input>`. */\nexport const numberInputStyles = css`\n    :host {\n        --_h: var(--ui-field-height-lg, 48px);\n\n        display: block;\n        font-family: var(--ui-font-family);\n    }\n\n    :host([size='sm']) {\n        --_h: var(--ui-field-height-sm, 32px);\n    }\n\n    /* the steppers' width */\n    :host {\n        --_ctrl: 80px;\n    }\n\n    :host([hide-steppers]) {\n        --_ctrl: 0px;\n    }\n\n    :host([size='md']) {\n        --_h: var(--ui-field-height-md, 40px);\n    }\n\n    .field {\n        position: relative;\n        display: flex;\n        align-items: center;\n    }\n\n    /* Carbon number input: 150px min width, controls 80px at the end (+32px when a status icon shows) */\n    input {\n        box-sizing: border-box;\n        width: 100%;\n        min-width: 150px;\n        height: var(--_h);\n        margin: 0;\n        padding: 0 96px 0 var(--ui-space-md);\n        /* Carbon: an underline only; --ui-field-border (all sides), --ui-field-radius and --ui-field-background let a design outline the box */\n        border: var(--ui-field-border, none);\n        border-bottom: 1px solid var(--ui-field-underline-color, var(--ui-ink-subtle));\n        border-radius: var(--ui-field-radius, var(--ui-radius-none));\n        background-color: var(--ui-field-background, var(--ui-surface-1));\n        color: var(--ui-ink);\n        font: var(--ui-font-body-sm);\n        font-size: var(--ui-field-font-size, 14px);\n        letter-spacing: var(--ui-tracking-body);\n        appearance: textfield;\n        outline: var(--ui-field-focus-width, 2px) solid transparent; /* the ring's width (Kanok: 1.5px, on the field's own border) */\n        outline-offset: calc(-1 * var(--ui-field-focus-width, 2px));\n        /* Carbon number input: background-color and outline at fast-01 */\n        transition:\n            background-color var(--ui-duration-fast) var(--ui-easing),\n            outline-color var(--ui-duration-fast) var(--ui-easing);\n    }\n\n    input:hover:not(:disabled):not(:focus) {\n        border-color: var(--ui-field-hover-border-color, var(--ui-border-strong-1));\n        border-bottom-color: var(--ui-field-hover-border-color, var(--ui-border-strong-1));\n    }\n\n    input::-webkit-inner-spin-button,\n    input::-webkit-outer-spin-button {\n        appearance: none;\n        margin: 0;\n    }\n\n    .has-status input {\n        padding-inline-end: 128px;\n    }\n\n    :host([hide-steppers]) input {\n        padding-inline-end: var(--ui-space-md);\n    }\n\n    :host([hide-steppers]) .has-status input {\n        padding-inline-end: calc(var(--ui-space-md) * 2 + 16px);\n    }\n\n    input::placeholder {\n        color: var(--ui-ink-placeholder);\n        opacity: 1;\n    }\n\n    input:focus {\n        border-color: var(--ui-field-focus-border-color, inherit);\n        border-bottom-color: var(--ui-field-focus-border-color, var(--ui-ink-subtle));\n        outline-color: var(--ui-focus);\n        box-shadow: var(--ui-field-focus-halo, none); /* a design's halo outside the ring (Kanok: none) */\n    }\n\n    .invalid input {\n        outline-color: var(--ui-error);\n        box-shadow: var(--ui-field-invalid-halo, none); /* a design's error halo (Kanok: Pixiv's red ring) */\n    }\n\n    .invalid input:focus {\n        border-color: var(--ui-field-focus-border-color, inherit);\n        border-bottom-color: var(--ui-field-focus-border-color, var(--ui-ink-subtle));\n        outline-color: var(--ui-focus);\n        box-shadow: var(--ui-field-invalid-halo, var(--ui-field-focus-halo, none)); /* an error keeps its halo while focused (Kanok: Pixiv's red) */\n    }\n\n    input:disabled {\n        border-color: var(--ui-field-disabled-border-color, currentColor currentColor transparent);\n        color: var(--ui-ink-disabled);\n        cursor: not-allowed;\n    }\n\n    input:read-only:not(:disabled) {\n        background-color: var(--ui-field-readonly-background, transparent);\n        border-color: var(--ui-field-readonly-border-color, currentColor currentColor var(--ui-hairline));\n    }\n\n    /* prefix / suffix: the value 8px clear of them (widths measured, see AffixSizes); the suffix sits before the status icon */\n    .field:has(.prefix) input {\n        padding-inline-start: calc(var(--ui-space-md) + var(--prefix-width, 0px) + var(--ui-space-xs));\n    }\n\n    .field:has(.suffix) input {\n        padding-inline-end: calc(var(--_ctrl) + var(--ui-space-md) + var(--suffix-width, 0px) + var(--ui-space-xs));\n    }\n\n    .field.has-status:has(.suffix) input {\n        padding-inline-end: calc(var(--_ctrl) + var(--ui-space-md) + 16px + var(--ui-space-xs) + var(--suffix-width, 0px) + var(--ui-space-xs));\n    }\n\n    .prefix,\n    .suffix {\n        position: absolute;\n        inset-block: 0;\n        display: flex;\n        align-items: center;\n        color: var(--ui-ink-muted);\n        font: var(--ui-font-body-sm);\n        letter-spacing: var(--ui-tracking-body);\n        white-space: nowrap;\n        /* clicks go through to the input */\n        pointer-events: none;\n    }\n\n    .prefix {\n        inset-inline-start: var(--ui-space-md);\n    }\n\n    .suffix {\n        inset-inline-end: calc(var(--_ctrl) + var(--ui-space-md));\n    }\n\n    .has-status .suffix {\n        inset-inline-end: calc(var(--_ctrl) + var(--ui-space-md) + 16px + var(--ui-space-xs));\n    }\n\n    input:disabled ~ :is(.prefix, .suffix) {\n        color: var(--ui-ink-disabled);\n    }\n\n    .status {\n        position: absolute;\n        inset-block: 0;\n        inset-inline-end: 80px;\n        display: flex;\n        align-items: center;\n        padding-inline-end: var(--ui-space-md);\n        pointer-events: none;\n    }\n\n    :host([hide-steppers]) .status {\n        inset-inline-end: 0;\n    }\n\n    .controls {\n        position: absolute;\n        inset-block: 0;\n        inset-inline-end: 0;\n        display: flex;\n        align-items: center;\n        width: 80px;\n    }\n\n    .step {\n        position: relative;\n        display: inline-flex;\n        align-items: center;\n        justify-content: center;\n        width: 40px;\n        height: 100%;\n        padding: 0;\n        border: none;\n        background: transparent;\n        color: var(--ui-ink);\n        cursor: pointer;\n        border-radius: var(--ui-icon-control-radius, 0); /* round in a design that rounds icon controls (Kanok) */\n    }\n\n    .step svg {\n        width: 16px;\n        height: 16px;\n        fill: currentColor;\n    }\n\n    .step:hover {\n        background-color: var(--ui-ghost-hover);\n        box-shadow: 0 -1px 0 var(--ui-ink-subtle) inset;\n    }\n\n    .step:focus-visible {\n        outline: var(--ui-focus-width, 2px) solid var(--ui-focus);\n        outline-offset: -2px;\n    }\n\n    .step:disabled {\n        color: var(--ui-ink-disabled);\n        cursor: not-allowed;\n        background: transparent;\n        box-shadow: none;\n    }\n\n    /* Carbon rule-divider: a 16px hairline at the start edge of each button, drawn over it so the buttons stay 40px */\n    .step::before {\n        content: '';\n        position: absolute;\n        inset-inline-start: 0;\n        top: 50%;\n        width: 1px;\n        height: 16px;\n        translate: 0 -50%;\n        background-color: var(--ui-hairline);\n    }\n\n    input:disabled ~ .controls .step::before {\n        background-color: transparent;\n    }\n\n    /*\n     * the field focused, a hovered stepper keeps the field's 2px focus line (as Carbon keeps it for search's ×):\n     * its fill is drawn inside it — 2px in from the top and bottom (and the end, for the last one) — under the icon\n     */\n    .step svg {\n        position: relative;\n        z-index: 1;\n    }\n\n    input:focus ~ .controls .step:hover {\n        background-color: transparent;\n        box-shadow: none;\n    }\n\n    input:focus ~ .controls .step:hover::after {\n        content: '';\n        position: absolute;\n        inset-block: 2px;\n        inset-inline: 0;\n        background-color: var(--ui-ghost-hover);\n        pointer-events: none;\n    }\n\n    input:focus ~ .controls .step:last-child:hover::after {\n        inset-inline-end: 2px;\n    }\n\n    @media (forced-colors: active) {\n        input {\n            border: 1px solid FieldText;\n        }\n        input:focus {\n            outline-color: Highlight;\n        }\n        .step {\n            border: 1px solid ButtonText;\n        }\n    }\n`;\n\n/** Styles of `<ui-number-input>` when fluid (`fluid`, or inside a `<ui-fluid-form>`): the 64px box with the label inside. */\nexport const numberInputFluidStyles = css`\n    :host([data-fluid]) {\n        --_h: 64px;\n    }\n\n    :host([data-fluid]) input,\n    :host([data-fluid]) .has-status input {\n        padding-block: 32px 13px;\n        padding-inline-end: 80px;\n    }\n\n    :host([data-fluid][hide-steppers]) input {\n        padding-inline-end: var(--ui-space-md);\n    }\n\n    /* the status icon sits in the message row: the suffix keeps its place; both on the value's line */\n    :host([data-fluid]) .field:has(.suffix) input {\n        padding-inline-end: calc(var(--_ctrl) + var(--ui-space-md) + var(--suffix-width, 0px) + var(--ui-space-xs));\n    }\n\n    :host([data-fluid]) :is(.prefix, .suffix) {\n        inset-block: 32px auto;\n        block-size: 18px;\n    }\n\n    :host([data-fluid]) .has-status .suffix {\n        inset-inline-end: calc(var(--_ctrl) + var(--ui-space-md));\n    }\n\n    /* Carbon fluid number input: the 40px steppers sit 23px down, level with the value */\n    :host([data-fluid]) .controls {\n        inset-block: 23px auto;\n        block-size: 40px;\n    }\n\n    :host([data-fluid]) .status {\n        --ui-fluid-icon-end: var(--ui-space-md);\n        inset-inline-end: 0;\n    }\n`;\n"
    },
    {
      "path": "src/primitives/number-input/number-input.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/number-input/number-input.ts",
      "content": "import { LitElement, html, nothing, type PropertyValues } from 'lit';\nimport { customElement, property, query, state } from 'lit/decorators.js';\nimport { live } from 'lit/directives/live.js';\nimport { fieldTextStyles, messageId, pickMessage, renderMessage, renderStatusIcon, uid, renderLabelText, barWhenDisabled, submitOnEnter, customErrorMessage, nativeValidationMessage, syncFluid, fluidFieldStyles, markStatus, type MessageKind } from '../shared/field.ts';\nimport { FormControlController } from '../shared/form-control.ts';\nimport { SlotController } from '../shared/slots.ts';\nimport { AffixSizes, affixDescribedBy, renderAffix } from '../shared/affixes.ts';\nimport { LocalizeController } from '../shared/localize.ts';\nimport { UiElement } from '../shared/element.ts';\nimport { isFloatText, localeNumberFormat, stepNumber, stepperLimits, type LocaleNumberFormat } from '../../core/number-format.ts';\nimport { numberInputStyles, numberInputFluidStyles } from './number-input.styles.ts';\n\nexport type NumberInputSize = 'sm' | 'md' | 'lg';\nexport type NumberInputType = 'number' | 'text';\n\nconst subtractIcon = html`<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=\"M3 7.5h10v1H3z\" /></svg>`;\nconst addIcon = html`<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=\"M8.5 3v4.5H13v1H8.5V13h-1V8.5H3v-1h4.5V3z\" /></svg>`;\n\n/**\n * Carbon-style number input (`NumberInput`): a native `type=\"number\"` field with the browser\n * spinner replaced by Carbon's two 40px stepper buttons (− then +, divided by hairlines) at the\n * end of the field. ↑ / ↓ step as well. The value is kept as text so the field can be empty.\n *\n * Validation follows Carbon: out of `min` / `max` is invalid, so is an empty field unless\n * `allow-empty` (both via native constraint validation, so forms block submit). Steppers clamp\n * to the range and round to the precision of the value or `step`, whichever has more decimals;\n * from an empty field they start at `step-start-value`, else ±1, else `min` (Carbon).\n *\n * `type=\"text\"` formats the number for a locale (Carbon `type=\"text\"` + `locale` +\n * `formatOptions`): thousands separators, currency, percent, units, accounting brackets, all\n * from `Intl.NumberFormat` options in `format-options`. The text is free while typing and is\n * reformatted on blur; `value` (and the submitted form value) stays a plain number, e.g.\n * `1234.5` for `฿1,234.50`, and a percent style gives the fraction (`0.5` for `50%`), as `Intl`.\n * Two deliberate differences from cds-number-input: `value` stays a plain number after blur\n * (Carbon's getter returns the formatted text; its event detail and Carbon React give the number),\n * and an empty `locale` follows the page language instead of `en-US`.\n *\n * `prefix-text` / `suffix-text` put text inside the field before / after the value — a unit or a\n * currency that stays in view while typing and is not part of `value` (`kg`, `บาท/เดือน`, `฿`), as\n * `<ui-text-input>`. No Carbon counterpart (Carbon writes a unit into the text with `type=\"text\"` +\n * `format-options` `{ style: 'unit' }`, which works here too).\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 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 * @fires change - After a committed change (blur / Enter / stepper; with `type=\"text\"`, on blur when the number changed)\n * @fires input - On every keystroke or stepper click\n * @csspart base - The field box\n * @csspart label - The label\n * @csspart input - The native input\n * @csspart prefix - The text before the value\n * @csspart suffix - The text after the value\n * @csspart controls - The stepper group\n * @csspart decrement-button - The − button\n * @csspart increment-button - The + button\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-field-border - Border on every side of the box (default none: Carbon's underline only; Kanok: a 1px outline)\n * @cssprop --ui-field-disabled-border-color - Border colour when disabled (default: the underline transparent)\n * @cssprop --ui-field-readonly-border-color - Border colour when read-only (default: a hairline underline)\n * @cssprop --ui-field-radius - Corner radius of the box (default 0; Kanok: 6px)\n * @cssprop --ui-field-background - Fill of the box (default `--ui-surface-1`; Kanok: transparent)\n * @cssprop --ui-label-font - Font of the label (default `--ui-font-caption`; Kanok: 14px semibold)\n * @cssprop --ui-label-color - Colour of the label (default `--ui-ink-muted`; Kanok: `--ui-ink`)\n * @cssprop --ui-field-readonly-background - The box's fill when read-only (default transparent; Kanok: a faint ink tint, so read-only reads as set and never weaker than disabled)\n * @cssprop --ui-fluid-background / --ui-fluid-gap - A fluid box's fill and the space under it (default the layer's fill, 0: boxes that touch; Kanok: transparent, 8px)\n * @cssprop --ui-icon-control-radius - Corners of its small icon buttons, their hover fill and ring (default 0; Kanok: round)\n */\n@customElement('ui-number-input')\nexport class UiNumberInput 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        numberInputStyles,\n        fluidFieldStyles,\n        numberInputFluidStyles,\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    /** Keep the label for screen readers but don't show it. */\n    @property({ type: Boolean, attribute: 'hide-label' }) hideLabel = false;\n    /** Helper text under the field, shown while there is no error or warning. */\n    @property({ attribute: 'helper-text' }) helperText = '';\n    /** Error text shown while `invalid` or while the field fails validation. */\n    @property({ attribute: 'invalid-text' }) invalidText = '';\n    /** Forces the error state, e.g. after server-side validation. */\n    @property({ type: Boolean, reflect: true }) invalid = false;\n    /** Non-blocking warning; shown when there is no error. */\n    @property({ type: Boolean, reflect: true }) warn = false;\n    /** Text of the warning shown while `warn`. */\n    @property({ attribute: 'warn-text' }) warnText = '';\n    /** The field text; `valueAsNumber` gives the parsed number (NaN while empty or invalid). */\n    @property() value = '';\n    /** Reflected: form-associated elements submit under the `name` attribute. */\n    @property({ reflect: true }) name = '';\n    @property() placeholder = '';\n\n    /** Text inside the field before the value, e.g. a currency (`฿`); not part of `value`. Part of the field's description for screen readers. */\n    @property({ attribute: 'prefix-text' }) prefixText = '';\n\n    /** Text inside the field after the value, e.g. a unit (`kg`); not part of `value`. Part of the field's description for screen readers. */\n    @property({ attribute: 'suffix-text' }) suffixText = '';\n    @property({ type: Number }) min?: number;\n    @property({ type: Number }) max?: number;\n    /** Step of the ± buttons and ↑ / ↓; with `type=\"number\"` also the allowed precision. */\n    @property({ type: Number }) step = 1;\n    /** Where the steppers start from an empty field (Carbon `stepStartValue`); 0 = Carbon's rule: ±1, or `min` when only a minimum is set. */\n    @property({ type: Number, attribute: 'step-start-value' }) stepStartValue = 0;\n    /** `number`: a native number field. `text`: a text field formatted for `locale` with `format-options` (Carbon `type=\"text\"`). */\n    @property({ reflect: true }) type: NumberInputType = 'number';\n    /** BCP 47 locale of the formatting with `type=\"text\"`; empty = the page language (`lang` on the element, an ancestor or `<html>`), as `ui-date-picker`. */\n    @property() locale = '';\n    /** `Intl.NumberFormat` options with `type=\"text\"`, e.g. `{\"style\":\"currency\",\"currency\":\"THB\"}` or `{\"maximumFractionDigits\":2}`. */\n    @property({ type: Object, attribute: 'format-options' }) formatOptions: Intl.NumberFormatOptions = {};\n    /** An empty field is valid (Carbon `allowEmpty`); otherwise empty counts as missing. */\n    @property({ type: Boolean, attribute: 'allow-empty' }) allowEmpty = false;\n    /** Remove the − / + buttons (keyboard stepping still works). */\n    @property({ type: Boolean, reflect: true, attribute: 'hide-steppers' }) hideSteppers = false;\n    /** Ignore mouse-wheel changes while focused (Carbon `disableWheel`). */\n    @property({ type: Boolean, attribute: 'disable-wheel' }) disableWheel = false;\n    /** Field height: sm 32px, md 40px, lg 48px (tokens `--ui-field-height-*`). */\n    @property({ reflect: true }) size: NumberInputSize = 'md'; // Carbon default (40px)\n    /** Disables the control; a disabled `<fieldset>` ancestor does the same. */\n    @property({ type: Boolean, reflect: true }) disabled = false;\n    /** Shows and submits the value but blocks changes. */\n    @property({ type: Boolean, reflect: true }) readonly = false;\n\n    /** Carbon `FluidNumberInput`: the label inside a 64px box, an error / warning inside it. `<ui-fluid-form>` sets it for every field inside. */\n    @property({ type: Boolean, reflect: true }) fluid = false;\n    /** Blocks form submission while the field is empty. */\n    @property({ type: Boolean, reflect: true }) required = false;\n    /** Accessible name of the − button. */\n    @property({ attribute: 'decrement-label' }) decrementLabel = '';\n    /** Accessible name of the + button. */\n    @property({ attribute: 'increment-label' }) incrementLabel = '';\n\n    @state() private touched = false;\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), implicitSubmission: true });\n    /** The text shown with `type=\"text\"`: as typed while focused, formatted otherwise. */\n    @state() private text = '';\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.syncFormState();\n        this.requestUpdate();\n    }\n    private readonly inputId = uid('ui-number-input');\n    private readonly slots = new SlotController(this);\n    private defaultValue = '';\n    /** `value` as last derived from typing, so willUpdate doesn't reformat what the user is typing. */\n    private typedValue?: string;\n    /** `value` at the last commit (focus, blur, stepper): blur fires `change` when it differs. */\n    private committedValue = '';\n    /** Locale + options the text was last formatted with. */\n    private formatKey = '';\n\n    /** The parsed value, NaN while empty or not a number. */\n    get valueAsNumber() {\n        return this.value.trim() === '' ? Number.NaN : Number(this.value);\n    }\n\n    /** Enter in the text box submits the form, like a native input. */\n    private readonly onEnterKey = (event: KeyboardEvent) => submitOnEnter(this, event);\n\n    override connectedCallback() {\n        super.connectedCallback();\n        syncFluid(this, this.fluid);\n        this.addEventListener('keydown', this.onEnterKey);\n        // first connection only: moving the element must not change what reset goes back to\n        this.formControl.captureDefaults(() => {\n            this.defaultValue = this.value;\n        });\n    }\n\n    override disconnectedCallback() {\n        super.disconnectedCallback();\n        this.removeEventListener('keydown', this.onEnterKey);\n        this.affixSizes.disconnect();\n    }\n\n    /** Follows the prefix / suffix widths so the value never runs under them. */\n    private readonly affixSizes = new AffixSizes();\n\n    get validity() {\n        return this.internals.validity;\n    }\n\n    get validationMessage() {\n        return this.internals.validationMessage;\n    }\n\n    get form() {\n        return this.internals.form;\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    checkValidity() {\n        return this.internals.checkValidity();\n    }\n\n    reportValidity() {\n        this.touched = true;\n        return this.formControl.reportValidity(this.internals);\n    }\n\n    /**\n     * Native `<input type=number>` sanitizes a non-number value to '' (so `value = 'abc'` can't be submitted).\n     * With `type=\"text\"` a formatted value (`1,234.5`) is parsed for the locale first, as Carbon's `value` setter.\n     */\n    protected override willUpdate(changed: Map<string, unknown>) {\n        syncFluid(this, this.fluid);\n        if (changed.has('value') && this.value !== '' && !isFloatText(this.value)) {\n            const parsed = this.type === 'text' ? this.numberFormat.parse(this.value) : Number.NaN;\n            this.value = Number.isNaN(parsed) ? '' : String(parsed);\n        }\n        if (this.type !== 'text') return;\n        const format = this.numberFormat;\n        const key = `${format.locale}|${JSON.stringify(this.formatOptions)}`;\n        if (key !== this.formatKey || changed.has('type') || (changed.has('value') && this.value !== this.typedValue)) {\n            this.formatKey = key;\n            this.showValue();\n        }\n    }\n\n    /** The formatter for `type=\"text\"`; invalid `locale` / `format-options` fall back to plain English formatting, with a console warning. */\n    private get numberFormat(): LocaleNumberFormat {\n        const locale = this.locale || this.localize.lang();\n        try {\n            return localeNumberFormat(locale, this.formatOptions ?? {});\n        } catch (error) {\n            console.warn(`ui-number-input: invalid locale \"${locale}\" or format-options`, error);\n            return localeNumberFormat('en');\n        }\n    }\n\n    /** Shows `value` formatted and forgets the typed text. */\n    private showValue() {\n        this.typedValue = undefined;\n        this.text = this.value === '' ? '' : this.numberFormat.format(Number(this.value));\n    }\n\n    protected override updated(changed: PropertyValues<this>) {\n        this.syncFormState();\n        if (changed.has('prefixText') || changed.has('suffixText')) this.affixSizes.follow(this.renderRoot, this.input);\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    formResetCallback() {\n        this.value = this.defaultValue;\n        this.committedValue = this.value;\n        this.touched = false;\n        if (this.type === 'text') this.showValue();\n    }\n\n    formStateRestoreCallback(state: string | File | FormData | null) {\n        if (typeof state !== 'string') return;\n        this.value = state;\n        if (this.type === 'text') this.showValue();\n    }\n\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 isEmpty() {\n        return this.type === 'text' ? this.text.trim() === '' : this.value.trim() === '';\n    }\n\n    /** `type=\"text\"` holding text that doesn't parse as a number. */\n    private get badText() {\n        return this.type === 'text' && !this.isEmpty && this.value === '';\n    }\n\n    /** `type=\"text\"` has no native min / max, so the range is checked here (number mode leaves it to the native input). */\n    private rangeError(): [ValidityStateFlags, string] | undefined {\n        const n = this.valueAsNumber;\n        if (this.type !== 'text' || Number.isNaN(n)) return undefined;\n        const { field } = this.localize.t;\n        if (this.min !== undefined && n < this.min) return [{ rangeUnderflow: true }, this.invalidText || field.rangeUnderflow.replace('{min}', this.numberFormat.format(this.min))];\n        if (this.max !== undefined && n > this.max) return [{ rangeOverflow: true }, this.invalidText || field.rangeOverflow.replace('{max}', this.numberFormat.format(this.max))];\n        return undefined;\n    }\n\n    private syncFormState() {\n        if (barWhenDisabled(this.internals, this.isDisabled)) return;\n        this.internals.setFormValue(this.value);\n        const customError = customErrorMessage(this.invalid, this.invalidText, this.customValidityMessage);\n        const rangeError = this.rangeError();\n        if (customError) {\n            this.internals.setValidity({ customError: true }, customError, this.input);\n        } else if (this.badText) {\n            this.internals.setValidity({ badInput: true }, this.invalidText || this.localize.t.field.enterNumber, this.input);\n        } else if (this.isEmpty && !this.allowEmpty && !this.required) {\n            // Carbon: an empty number is not a number unless allowEmpty\n            this.internals.setValidity({ valueMissing: true }, this.invalidText || this.input.validationMessage || this.localize.t.field.enterNumber, this.input);\n        } else if (rangeError) {\n            this.internals.setValidity(rangeError[0], rangeError[1], this.input);\n        } else if (this.input.validity.valid) {\n            this.internals.setValidity({});\n        } else {\n            this.internals.setValidity(this.input.validity, nativeValidationMessage(this.input, this.localize.t.field.required), this.input);\n        }\n    }\n\n    private onInput(event: Event) {\n        const raw = (event.target as HTMLInputElement).value;\n        if (this.type !== 'text') {\n            this.value = raw;\n            return;\n        }\n        // Carbon type=\"text\": the text stays as typed; value follows whenever it parses\n        const parsed = this.numberFormat.parse(raw);\n        this.text = raw;\n        this.value = Number.isNaN(parsed) ? '' : String(parsed);\n        this.typedValue = this.value;\n    }\n\n    /** The native change isn't composed; `type=\"text\"` fires its own on blur, after formatting. */\n    private onChange() {\n        if (this.type !== 'text') this.dispatchEvent(new Event('change', { bubbles: true }));\n    }\n\n    private onFocus() {\n        this.committedValue = this.value;\n    }\n\n    /**\n     * Carbon type=\"text\": reformat on blur, `change` when the number changed. Text that isn't a number (\"20,000 บาท\") stays,\n     * invalid (badInput), for the user to correct; Carbon cleared it.\n     */\n    private onBlur() {\n        this.touched = true;\n        if (this.type !== 'text') return;\n        if (!this.badText) {\n            const rounded = this.numberFormat.round(this.valueAsNumber);\n            this.value = Number.isNaN(rounded) ? '' : String(rounded);\n            this.showValue();\n        }\n        if (this.value === this.committedValue) return;\n        this.committedValue = this.value;\n        this.dispatchEvent(new Event('change', { bubbles: true }));\n    }\n\n    private onKeydown(event: KeyboardEvent) {\n        if (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') return;\n        event.preventDefault(); // the native spinner would step without clamping / rounding\n        this.stepBy(event.key === 'ArrowUp' ? 1 : -1);\n    }\n\n    private onWheel(event: WheelEvent) {\n        if (this.disableWheel) event.preventDefault();\n    }\n\n    /** Carbon stepper (core `stepNumber`): current ± step (or the start value), rounded to the precision of the value or step, clamped to min / max. */\n    private stepBy(direction: 1 | -1) {\n        if (!this.interactive) return;\n        let next = stepNumber(this.valueAsNumber, direction, { step: this.step, min: this.min, max: this.max, stepStartValue: this.stepStartValue });\n        if (this.type === 'text') next = this.numberFormat.round(next);\n        const text = String(next);\n        if (text === this.value) return;\n        this.value = text;\n        this.committedValue = text;\n        if (this.type === 'text') this.showValue();\n        this.touched = true;\n        this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));\n        this.dispatchEvent(new Event('change', { bubbles: true }));\n    }\n\n    private get showError() {\n        if (!this.interactive) return false;\n        if (this.invalid) return true;\n        return this.touched && !this.internals.validity.valid;\n    }\n\n    private get errorText() {\n        if (this.customValidityMessage && !this.invalid) return this.customValidityMessage;\n        return this.invalidText || this.internals.validationMessage || '';\n    }\n\n    private renderLabel() {\n        // no label of its own: an unseen one with the name given from outside (aria-label, a <label for>), if any\n        const unlabelled = !this.label && !this.slots.has('label');\n        const outside = unlabelled ? this.formControl.fallbackName(this.label, this.internals) : '';\n        if (unlabelled && !outside) return nothing;\n        return html`<label class=${this.hideLabel || unlabelled ? 'sr-only' : 'label'} part=\"label\" for=${this.inputId}>${renderLabelText(this.label, outside)}</label>`;\n    }\n\n    private renderSteppers() {\n        if (this.hideSteppers) return nothing;\n        const { atMin, atMax } = stepperLimits(this.valueAsNumber, this.min, this.max);\n        return html`<span class=\"controls\" part=\"controls\">\n            <button class=\"step\" part=\"decrement-button\" type=\"button\" tabindex=\"-1\" aria-label=${this.decrementLabel || this.localize.t.field.decrement} ?disabled=${!this.interactive || atMin} @click=${() => this.stepBy(-1)}>\n                ${subtractIcon}\n            </button>\n            <button class=\"step\" part=\"increment-button\" type=\"button\" tabindex=\"-1\" aria-label=${this.incrementLabel || this.localize.t.field.increment} ?disabled=${!this.interactive || atMax} @click=${() => this.stepBy(1)}>\n                ${addIcon}\n            </button>\n        </span>`;\n    }\n\n    override render() {\n        const showError = this.showError;\n        const message = pickMessage({\n            showError,\n            errorText: this.errorText,\n            showWarn: this.warn && this.interactive,\n            warnText: this.warnText,\n            helperText: this.helperText,\n            slots: this.slots,\n        });\n        markStatus(this, message);\n        this.shownKind = message?.kind;\n        const classes = [showError ? 'invalid' : '', message && message.kind !== 'helper' ? 'has-status' : ''].filter(Boolean).join(' ');\n\n        return html`\n            ${this.renderLabel()}\n            <div class=\"field ${classes}\" part=\"base\">\n                <input\n                    part=\"input\"\n                    id=${this.inputId}\n                    type=${this.type === 'text' ? 'text' : 'number'}\n                    inputmode=\"decimal\"\n                    .value=${live(this.type === 'text' ? this.text : this.value)}\n                    name=${this.name || nothing}\n                    placeholder=${this.placeholder || nothing}\n                    min=${this.type === 'text' ? nothing : (this.min ?? nothing)}\n                    max=${this.type === 'text' ? nothing : (this.max ?? nothing)}\n                    step=${this.type === 'text' ? nothing : this.step}\n                    ?disabled=${this.isDisabled}\n                    ?readonly=${this.readonly}\n                    ?required=${this.required}\n                    aria-invalid=${showError ? 'true' : 'false'}\n                    aria-describedby=${affixDescribedBy(this.inputId, this.prefixText, this.suffixText, messageId(this.inputId, message))}\n                    @input=${this.onInput}\n                    @change=${this.onChange}\n                    @keydown=${this.onKeydown}\n                    @wheel=${this.onWheel}\n                    @focus=${this.onFocus}\n                    @blur=${this.onBlur}\n                />\n                ${renderAffix(this.inputId, 'prefix', this.prefixText)}${renderAffix(this.inputId, 'suffix', this.suffixText)}\n                <span class=\"status\">${renderStatusIcon(message)}</span>\n                ${this.renderSteppers()}\n            </div>\n            ${renderMessage(this.inputId, message)}\n        `;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-number-input': UiNumberInput;\n    }\n}\n"
    }
  ]
}
