{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-input",
  "type": "registry:ui",
  "title": "<ui-text-input>",
  "description": "Carbon-style text input (Carbon `TextInput`). 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-field",
    "@kanok-ui/core-mask",
    "@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/tooltip",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/text-input/text-input-skeleton.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/text-input/text-input-skeleton.ts",
      "content": "import { customElement } from 'lit/decorators.js';\nimport { UiFieldSkeleton } from '../shared/skeleton.ts';\n\n/**\n * Carbon `TextInputSkeleton` (`cds-text-input-skeleton`): the shape of a `<ui-text-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-text-input-skeleton')\nexport class UiTextInputSkeleton extends UiFieldSkeleton {}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-text-input-skeleton': UiTextInputSkeleton;\n    }\n}\n"
    },
    {
      "path": "src/primitives/text-input/text-input.styles.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/text-input/text-input.styles.ts",
      "content": "import { css } from 'lit';\n\n/** Styles of `<ui-text-input>`. */\nexport const textInputStyles = css`\n    :host {\n        display: block;\n        font-family: var(--ui-font-family);\n    }\n\n    .field {\n        position: relative;\n        display: flex;\n        align-items: center;\n    }\n\n    .top {\n        display: flex;\n        justify-content: space-between;\n        gap: var(--ui-space-xs);\n    }\n\n    .counter {\n        margin-inline-start: auto;\n        font: var(--ui-font-caption);\n        letter-spacing: var(--ui-tracking-caption);\n        color: var(--ui-ink-muted);\n    }\n\n    .counter.over {\n        color: var(--ui-error);\n    }\n\n    input {\n        box-sizing: border-box;\n        width: 100%;\n        min-height: var(--ui-field-height-lg, 48px);\n        margin: 0;\n        padding: 0 var(--end-pad, var(--ui-space-md)) 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        /* ink-subtle keeps the 3:1 non-text contrast WCAG 1.4.11 asks of input edges */\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        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 text-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    :host([size='sm']) input {\n        min-height: var(--ui-field-height-sm, 32px);\n    }\n\n    :host([size='md']) input {\n        min-height: var(--ui-field-height-md, 40px);\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:disabled::placeholder {\n        color: var(--ui-ink-disabled);\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    /* the value starts after the prefix and stops before the suffix (widths measured, see measureAffixes) */\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(--end-pad) + var(--suffix-width, 0px) + var(--ui-space-xs));\n    }\n\n    /* the toggle brings no gap of its own */\n    .field:has(.suffix):has(.reveal) input {\n        padding-inline-end: calc(var(--end-pad) + var(--suffix-width, 0px) + 2 * var(--ui-space-xs));\n    }\n\n    .prefix,\n    .suffix {\n        font: var(--ui-font-body-sm);\n        letter-spacing: var(--ui-tracking-body);\n        color: var(--ui-ink-muted);\n        white-space: nowrap;\n    }\n\n    /* clicks go through to the input */\n    .prefix {\n        position: absolute;\n        inset-block: 0;\n        inset-inline-start: var(--ui-space-md);\n        display: flex;\n        align-items: center;\n        pointer-events: none;\n    }\n\n    input:disabled ~ .prefix,\n    input:disabled ~ .adornments .suffix {\n        color: var(--ui-ink-disabled);\n    }\n\n    .adornments {\n        position: absolute;\n        inset-block: 0;\n        inset-inline-end: 0;\n        display: flex;\n        align-items: center;\n        gap: var(--ui-space-xs);\n        padding-inline-end: var(--ui-space-md);\n        /* Let clicks on the empty area reach the input; the toggle opts back in */\n        pointer-events: none;\n    }\n\n    .adornments:has(.reveal) {\n        padding-inline-end: 0;\n    }\n\n    .reveal {\n        display: grid;\n        place-items: center;\n        width: 40px;\n        height: 40px;\n        padding: 0;\n        border: none;\n        background: transparent;\n        color: var(--ui-ink);\n        cursor: pointer;\n        pointer-events: auto;\n        /* Carbon password visibility toggle: its outline at fast-01 */\n        outline: var(--ui-focus-width, 2px) solid transparent;\n        outline-offset: -2px;\n        transition: outline-color var(--ui-duration-fast) var(--ui-easing);\n        border-radius: var(--ui-icon-control-radius, 0); /* round in a design that rounds icon controls (Kanok) */\n    }\n\n    .reveal svg {\n        width: 16px;\n        height: 16px;\n        fill: currentColor;\n    }\n\n\n    .reveal:focus-visible {\n        outline: var(--ui-focus-width, 2px) solid var(--ui-focus);\n        outline-offset: -2px;\n    }\n\n    .reveal:disabled {\n        color: var(--ui-ink-disabled);\n        cursor: not-allowed;\n        background: transparent;\n    }\n\n    /*\n     * Carbon inline (text-input-wrapper--inline): label, field and message in one row, centred; the label and\n     * the message each at most 142px and 8px from the field, which takes the rest (flex: 8).\n     */\n    :host([inline]:not([data-fluid])) {\n        display: flex;\n        align-items: center;\n    }\n\n    :host([inline]:not([data-fluid])) .top {\n        flex: 0 1 auto;\n        max-inline-size: 142px;\n        margin-inline-end: var(--ui-space-xs);\n        overflow-wrap: break-word;\n    }\n\n    :host([inline]:not([data-fluid])) .label {\n        margin: 0;\n        word-break: break-word;\n    }\n\n    :host([inline]:not([data-fluid])) .field {\n        flex: 8;\n    }\n\n    .inline-message {\n        flex: 0 1 auto;\n        max-inline-size: 142px;\n        margin-inline-start: var(--ui-space-xs);\n        overflow-wrap: break-word;\n    }\n\n    .inline-message > p {\n        margin: 0;\n    }\n\n    @media (forced-colors: active) {\n        input {\n            border: 1px solid FieldText;\n        }\n        input:focus {\n            outline-color: Highlight;\n        }\n    }\n`;\n\n/** Styles of `<ui-text-input>` when fluid (`fluid`, or inside a `<ui-fluid-form>`): the 64px box with the label inside. */\nexport const textInputFluidStyles = css`\n    :host([data-fluid]) input {\n        block-size: 64px;\n        min-height: 64px;\n        padding-block: 32px 13px;\n    }\n\n    :host([data-fluid]) .adornments {\n        --ui-fluid-icon-end: var(--ui-space-md);\n        inset-block: 24px auto;\n        block-size: 40px;\n    }\n\n    /* on the value's line (32px down, 18px tall) */\n    :host([data-fluid]) .prefix {\n        inset-block: 32px auto;\n        block-size: 18px;\n    }\n\n    :host([data-fluid]) .suffix {\n        align-self: flex-start;\n        margin-block-start: 8px;\n    }\n`;\n"
    },
    {
      "path": "src/primitives/text-input/text-input.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/text-input/text-input.ts",
      "content": "import { LitElement, html, nothing, type PropertyValues } from 'lit';\nimport { customElement, property, query, state } from 'lit/decorators.js';\nimport { fieldTextStyles, messageId, pickMessage, renderMessage, renderStatusIcon, uid, renderLabelText, barWhenDisabled, submitOnEnter, customErrorMessage, nativeValidationMessage, syncFluid, fluidFieldStyles, markStatus, hasData, type FieldMessage, type MessageKind } from '../shared/field.ts';\nimport { FormControlController } from '../shared/form-control.ts';\nimport { AffixSizes, affixDescribedBy, renderAffix } from '../shared/affixes.ts';\nimport { SlotController } from '../shared/slots.ts';\nimport { LocalizeController } from '../shared/localize.ts';\nimport { UiElement } from '../shared/element.ts';\nimport { characterCount } from '../../core/field.ts';\nimport '../tooltip/tooltip.ts';\nimport { applyMask, maskDeletion, maskEdit, maskInputMode, unmask } from '../../core/mask.ts';\nimport { textInputStyles, textInputFluidStyles } from './text-input.styles.ts';\n\nexport type TextInputType = 'text' | 'email' | 'password' | 'search' | 'tel' | 'url' | 'number';\n/** Heights: sm 32px · md 40px · lg 48px (Carbon touch target). */\nexport type TextInputSize = 'sm' | 'md' | 'lg';\n\nconst eyeIcon = html`<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n    <path\n        d=\"M15.5 7.8C14.3 4.7 11.3 2.5 8 2.5S1.7 4.7.5 7.8v.4c1.2 3.1 4.2 5.3 7.5 5.3s6.3-2.2 7.5-5.3v-.4ZM8 12.5c-2.7 0-5.4-1.9-6.5-4.5C2.6 5.4 5.3 3.5 8 3.5s5.4 1.9 6.5 4.5c-1.1 2.6-3.8 4.5-6.5 4.5Z\"\n    />\n    <path d=\"M8 5a3 3 0 1 0 0 6 3 3 0 0 0 0-6Zm0 5a2 2 0 1 1 0-4 2 2 0 0 1 0 4Z\" />\n</svg>`;\n\nconst eyeOffIcon = html`<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n    <path\n        d=\"m2.6 11.3.7-.7C2.5 9.9 1.9 9 1.5 8c1.1-2.6 3.8-4.5 6.5-4.5.9 0 1.7.2 2.5.5l.8-.8c-1-.4-2.1-.7-3.3-.7C4.7 2.5 1.7 4.7.5 7.8v.4c.5 1.2 1.2 2.3 2.1 3.1ZM6 7.9A2 2 0 0 1 7.9 6l.9-.9A3 3 0 0 0 5.1 8.8l.9-.9ZM15.5 7.8c-.6-1.5-1.5-2.8-2.7-3.8L15 1.7 14.3 1 1 14.3l.7.7 2.5-2.5c1.1.6 2.4 1 3.8 1 3.3 0 6.3-2.2 7.5-5.3v-.4ZM10 8a2 2 0 0 1-2 2c-.3 0-.6-.1-.9-.2l2.7-2.7c.1.3.2.6.2.9Zm-2 4.5c-1.1 0-2.1-.3-3-.8L6.4 10.3c.5.4 1 .7 1.6.7a3 3 0 0 0 3-3c0-.6-.3-1.2-.7-1.6L12 4.7c1.1.9 2 2 2.5 3.3-1.1 2.6-3.8 4.5-6.5 4.5Z\"\n    />\n</svg>`;\n\n/**\n * Carbon-style text input (Carbon `TextInput`).\n *\n * Label, helper / warning / error text live in the same shadow root as the `<input>`,\n * so `for` / `aria-describedby` references resolve. Form-associated: takes\n * part in `<form>` submit, reset, and native constraint validation.\n *\n * Errors appear after the user leaves the field (or tries to submit), never\n * while they are still typing. `warn` shows a non-blocking warning.\n * `type=\"password\"` adds a show/hide toggle (Carbon PasswordInput): its icon tooltip, below and lined up with its end,\n * is also its name — `show-password-label` while hidden, `hide-password-label` while shown — and each press fires\n * `ui-toggle` (Carbon `onTogglePasswordVisibility`).\n * `inline` (Carbon `inline`) puts the label before the field and the helper / error text after it, in one row\n * centred: each side at most 142px, 8px from the field (not while fluid).\n * `max-count` shows a character counter; going over doesn't cut the text off (users can\n * paste and then trim) — it becomes an error and screen readers hear when the limit is near\n * or exceeded.\n *\n * `prefix-text` / `suffix-text` put a currency or a unit inside the field (฿, kg), and `mask`\n * formats the value as the user types (`0-0000-00000-00-0`) — neither has a Carbon counterpart\n * (Carbon puts both in the label or helper text); they follow USWDS.\n *\n * State on the host for styling: `data-show-error` while the error shows, `data-show-warn` while the\n * warning shows, `data-password-visible` while the password is shown as text.\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 * @cssstate password-visible - While the password is shown as text (also `[data-password-visible]`)\n * @fires input - Native input event (already composed, so it reaches the host)\n * @fires change - Re-dispatched from the native input (native change is not composed)\n * @fires ui-toggle - detail: { visible } when the password toggle shows or hides the password (Carbon `onTogglePasswordVisibility`)\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 field box around the input\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 password-toggle - The show / hide password button\n * @csspart password-tooltip - The `<ui-tooltip>` around it (its name)\n * @csspart counter - The character counter\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-text-input')\nexport class UiTextInput extends UiElement {\n    static override hostStates: readonly string[] = ['show-error', 'show-warn', 'password-visible'];\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        textInputStyles,\n        fluidFieldStyles,\n        textInputFluidStyles,\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 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    /** Message shown when invalid. Falls back to the browser's validation message. */\n    @property({ attribute: 'invalid-text' }) invalidText = '';\n\n    /** Force the error state (e.g. a server-side error). */\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    @property() value = '';\n\n    /** Reflected: form-associated elements submit under the `name` attribute. */\n    @property({ reflect: true }) name = '';\n\n    @property() type: TextInputType = 'text';\n\n    /** Field height: sm 32px, md 40px, lg 48px (tokens `--ui-field-height-*`). */\n    @property({ type: String, reflect: true }) size: TextInputSize = 'md'; // Carbon default (40px)\n\n    @property() placeholder = '';\n\n    @property() autocomplete = '';\n\n    /** Passed to the text box: the virtual keyboard to show (`numeric`, `decimal`, `email`, `tel`, `url`, `search`…). */\n    @property() inputmode = '';\n\n    /** Passed to the text box: the label of the virtual keyboard's Enter key (`search`, `send`, `next`, `done`…). */\n    @property() enterkeyhint = '';\n\n    @property() pattern = '';\n\n    /** Text inside the field before the value, e.g. a currency (`฿`). 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`). Part of the field's description for screen readers. */\n    @property({ attribute: 'suffix-text' }) suffixText = '';\n\n    /**\n     * Formats the value as the user types: `0` a digit, `a` a letter, `*` either; any other\n     * character is a separator added for the user (`\\` makes a pattern character one).\n     * E.g. `0-0000-00000-00-0` (Thai citizen ID), `000-000-0000`. `value` and the form get the\n     * formatted text, `rawValue` what was typed. Put the format in the helper text too (Carbon).\n     */\n    @property() mask = '';\n\n    @property({ type: Number }) minlength?: number;\n\n    @property({ type: Number }) maxlength?: number;\n\n    /** Soft limit with a visible counter (unlike maxlength, extra text isn't blocked). */\n    @property({ type: Number, attribute: 'max-count' }) maxCount?: number;\n\n    /** Error when over `max-count`; `{max}` is replaced with the limit. */\n    @property({ attribute: 'too-long-text' }) tooLongText = '';\n\n    /** Announced once when the remaining characters drop to 10% or less. */\n    @property({ attribute: 'near-limit-text' }) nearLimitText = '';\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    /** Carbon `FluidTextInput`: 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\n    /** Blocks form submission while the field is empty. */\n    @property({ type: Boolean, reflect: true }) required = false;\n\n    /** The password toggle's name and tooltip while the password is hidden (Carbon `showPasswordLabel`; default: the translation's \"Show password\"). */\n    @property({ attribute: 'show-password-label' }) showPasswordLabel = '';\n\n    /** The password toggle's name and tooltip while the password shows (Carbon `hidePasswordLabel`; default: the translation's \"Hide password\"). */\n    @property({ attribute: 'hide-password-label' }) hidePasswordLabel = '';\n\n    /** Carbon `inline`: the label before the field, the helper / error text after it (ignored while fluid). */\n    @property({ type: Boolean, reflect: true }) inline = false;\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), implicitSubmission: true });\n\n    @state() private passwordVisible = false;\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-text-input');\n    private defaultValue = '';\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    protected override willUpdate(changed: PropertyValues<this>) {\n        syncFluid(this, this.fluid);\n        // a value set by the app (raw or formatted) shows formatted\n        if (this.mask && (changed.has('value') || changed.has('mask'))) this.value = applyMask(this.value, this.mask);\n    }\n\n    /** The characters typed, without the mask's separators (`value` when there is no mask). */\n    get rawValue() {\n        return this.mask ? unmask(this.value, this.mask) : this.value;\n    }\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        // Fired by the form when submit is blocked by this field — reveal the error now.\n    }\n\n    override disconnectedCallback() {\n        super.disconnectedCallback();\n        this.removeEventListener('keydown', this.onEnterKey);\n        this.affixSizes.disconnect();\n    }\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    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        this.toggleAttribute('data-password-visible', this.type === 'password' && this.passwordVisible);\n    }\n\n    /** Follows the prefix / suffix widths so the value never runs under them. */\n    private readonly affixSizes = new AffixSizes();\n\n    formResetCallback() {\n        this.value = this.defaultValue;\n        this.touched = false;\n        this.passwordVisible = false;\n    }\n\n    /** Back/forward cache and autofill hand the saved value back here. */\n    formStateRestoreCallback(state: string | File | FormData | null) {\n        if (typeof state === 'string') this.value = state;\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 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        if (customError) {\n            this.internals.setValidity({ customError: true }, customError, this.input);\n        } else if (this.overLimit) {\n            this.internals.setValidity({ tooLong: true }, this.tooLongMessage, 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: InputEvent) {\n        const input = event.target as HTMLInputElement;\n        if (this.mask && !event.isComposing) {\n            const edit = maskEdit(this.value, input.value, input.selectionStart ?? input.value.length, this.mask, maskDeletion(event.inputType));\n            input.value = edit.value;\n            // email / number inputs have no caret to place\n            if (input.selectionStart !== null) input.setSelectionRange(edit.caret, edit.caret);\n        }\n        this.value = input.value;\n    }\n\n    private onChange() {\n        this.dispatchEvent(new Event('change', { bubbles: true }));\n    }\n\n    private onBlur() {\n        this.touched = true;\n    }\n\n    /** A press of the toggle (a click, Enter or Space): Carbon `onTogglePasswordVisibility`. */\n    private togglePassword() {\n        this.passwordVisible = !this.passwordVisible;\n        this.dispatchEvent(new CustomEvent('ui-toggle', { detail: { visible: this.passwordVisible }, bubbles: true, composed: true }));\n    }\n\n    private get interactive() {\n        return !this.isDisabled && !this.readonly;\n    }\n\n    /** core/field: over the soft limit (an error) / within its last 10% (announced). */\n    private get count() {\n        return characterCount(this.value.length, this.maxCount);\n    }\n\n    private get overLimit() {\n        return this.count.over;\n    }\n\n    private get tooLongMessage() {\n        return (this.tooLongText || this.localize.t.field.tooLong).replace('{max}', String(this.maxCount));\n    }\n\n    /** Over the limit shows at once (the counter already turned red); other errors wait for blur. */\n    private get showError() {\n        if (!this.interactive) return false;\n        if (this.invalid || this.overLimit) return true;\n        return this.touched && (!!this.customValidityMessage || (!!this.input && !this.input.validity.valid));\n    }\n\n    /** Changes only when crossing into \"near\" or \"over\", so typing isn't announced per keystroke. */\n    private get counterAnnouncement() {\n        if (this.count.over) return this.tooLongMessage;\n        return this.count.near ? this.nearLimitText || this.localize.t.field.nearLimit : '';\n    }\n\n    private renderCounter() {\n        if (this.maxCount === undefined) return nothing;\n        return html`<span class=\"counter ${this.overLimit ? 'over' : ''}\" part=\"counter\" aria-hidden=\"true\">\n                ${this.value.length}/${this.maxCount}\n            </span>\n            <span class=\"sr-only\" aria-live=\"polite\">${this.counterAnnouncement}</span>`;\n    }\n\n    private get errorText() {\n        if (this.customValidityMessage && !this.invalid) return this.customValidityMessage;\n        if (this.invalidText) return this.invalidText;\n        if (this.overLimit) return this.tooLongMessage;\n        return this.input ? nativeValidationMessage(this.input, this.localize.t.field.required) : '';\n    }\n\n    private readonly slots = new SlotController(this);\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    /** What the toggle does next, as Carbon: its name and tooltip change with it (so no aria-pressed). */\n    private get revealLabel() {\n        const t = this.localize.t.field;\n        return this.passwordVisible ? this.hidePasswordLabel || t.hidePassword : this.showPasswordLabel || t.showPassword;\n    }\n\n    /** Carbon PasswordInput: an icon tooltip below the toggle, lined up with its end (tooltipPosition bottom, tooltipAlignment end). */\n    private renderReveal() {\n        if (this.type !== 'password') return nothing;\n        const label = this.revealLabel;\n        return html`<ui-tooltip as-label part=\"password-tooltip\" text=${label} placement=\"bottom-end\"\n            ><button class=\"reveal\" part=\"password-toggle\" type=\"button\" aria-label=${label} ?disabled=${this.isDisabled} @click=${this.togglePassword}>\n                ${this.passwordVisible ? eyeOffIcon : eyeIcon}\n            </button></ui-tooltip\n        >`;\n    }\n\n    /** Inline, the message sits after the field in a box of its own, kept (8px) when there is none, as Carbon's. */\n    private renderMessageBox(message: FieldMessage | null) {\n        const box = renderMessage(this.inputId, message);\n        if (!this.inline || hasData(this, 'fluid')) return box;\n        return html`<div class=\"inline-message\">${box}</div>`;\n    }\n\n    /** The virtual keyboard: the author's, else the one a digits-only mask wants. */\n    private get keyboard() {\n        return this.inputmode || (this.mask && maskInputMode(this.mask)) || nothing;\n    }\n\n    private get inputType() {\n        if (this.type === 'password' && this.passwordVisible) return 'text';\n        return this.type;\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 describedBy = messageId(this.inputId, message);\n        // Room for the status icon (16px + gap) and the password toggle (40px)\n        // (fluid: the status icon sits in the message row instead)\n        const iconPad = message && message.kind !== 'helper' && !hasData(this, 'fluid') ? 24 : 0;\n        const revealPad = this.type === 'password' ? 40 : 16;\n\n        return html`\n            <div class=\"top\">${this.renderLabel()}${this.renderCounter()}</div>\n            <div class=\"field ${showError ? 'invalid' : ''}\" part=\"base\" style=\"--end-pad: ${iconPad + revealPad}px\">\n                <input\n                    part=\"input\"\n                    id=${this.inputId}\n                    .value=${this.value}\n                    type=${this.inputType}\n                    name=${this.name || nothing}\n                    placeholder=${this.placeholder || nothing}\n                    autocomplete=${this.autocomplete || nothing}\n                    inputmode=${this.keyboard}\n                    enterkeyhint=${this.enterkeyhint || nothing}\n                    pattern=${this.pattern || nothing}\n                    minlength=${this.minlength ?? nothing}\n                    maxlength=${this.maxlength ?? nothing}\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, describedBy)}\n                    @input=${this.onInput}\n                    @change=${this.onChange}\n                    @blur=${this.onBlur}\n                />\n                ${renderAffix(this.inputId, 'prefix', this.prefixText)}\n                <span class=\"adornments\">${renderAffix(this.inputId, 'suffix', this.suffixText)}${renderStatusIcon(message)}${this.renderReveal()}</span>\n            </div>\n            ${this.renderMessageBox(message)}\n        `;\n    }\n}\n\nexport interface UiTextInputEventMap extends HTMLElementEventMap {\n    'ui-toggle': CustomEvent<{ visible: boolean }>;\n}\n\n/** Typed listeners for UiTextInput's events (declaration merging with the class). */\nexport interface UiTextInput {\n    addEventListener<K extends keyof UiTextInputEventMap>(type: K, listener: (this: UiTextInput, event: UiTextInputEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;\n    addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;\n    removeEventListener<K extends keyof UiTextInputEventMap>(type: K, listener: (this: UiTextInput, event: UiTextInputEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;\n    removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-text-input': UiTextInput;\n    }\n}\n"
    }
  ]
}
