{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slider",
  "type": "registry:ui",
  "title": "<ui-slider>",
  "description": "Carbon `Slider` (single handle): a 2px track with a 14px round thumb (`role=slider`), min / max labels and a 64px number input that mirrors the value. Drag or click the track; Left / Down and Right / Up move by `step` (× `step-multiplier` with Shift), Home / End jump to the ends. Typing applies at once while the number is in range; on blur or Enter an out-of-range number is clamped (announced politely) and text that is not a number marks the field invalid. `hide-text-input` replaces the input with a value tooltip on the thumb. 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-slider",
    "@kanok-ui/shared-element",
    "@kanok-ui/shared-field",
    "@kanok-ui/shared-form-control",
    "@kanok-ui/shared-localize",
    "@kanok-ui/shared-row-wrap",
    "@kanok-ui/shared-skeleton",
    "@kanok-ui/shared-slots",
    "@kanok-ui/tooltip",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/slider/slider-skeleton.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/slider/slider-skeleton.ts",
      "content": "import { html, css, svg } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { skeletonStyles, UiSkeletonElement } from '../shared/skeleton.ts';\n\n// Carbon's two-handle thumb icons (16 × 24), as <ui-slider value-upper>\nconst lowerHandle = svg`<path d=\"M15.08 6.46H16v11.08h-.92zM4.46 17.54c-.25 0-.46-.21-.46-.46V6.92a.465.465 0 0 1 .69-.4l8.77 5.08a.46.46 0 0 1 0 .8l-8.77 5.08c-.07.04-.15.06-.23.06Z\" />`;\nconst upperHandle = svg`<path d=\"M0 6.46h.92v11.08H0zM11.54 6.46c.25 0 .46.21.46.46v10.15a.465.465 0 0 1-.69.4L2.54 12.4a.46.46 0 0 1 0-.8l8.77-5.08c.07-.04.15-.06.23-.06Z\" />`;\nconst handles = html`<svg class=\"handle lower\" viewBox=\"0 0 16 24\">${lowerHandle}</svg><svg class=\"handle upper\" viewBox=\"0 0 16 24\">${upperHandle}</svg>`;\nconst thumb = html`<span class=\"thumb\"></span>`;\n\n/**\n * Carbon `SliderSkeleton` (`cds-slider-skeleton`): a 75×14 label bar, 8px, then the slider's row — 20×12 min / max\n * bars around the track with its centre tick, the filled track and a 14px thumb in the middle. `two-handles` (Carbon\n * `twoHandles`): the track 4px in from each side, the lower handle just before its start and the upper one just after\n * its end. Hidden from assistive tech.\n *\n * @csspart label - The label bar\n * @csspart range-label - The min / max bars\n */\n@customElement('ui-slider-skeleton')\nexport class UiSliderSkeleton extends UiSkeletonElement {\n    static override readonly styles = [\n        skeletonStyles,\n        css`\n            :host {\n                display: block;\n            }\n\n            .label {\n                display: block;\n                inline-size: 75px;\n                block-size: 14px;\n                margin-block-end: var(--ui-space-xs);\n            }\n\n            :host([hide-label]) .label {\n                display: none;\n            }\n\n            /* as <ui-slider>: 16px apart, the track 100% wide between 200 and 640px */\n            .container {\n                display: flex;\n                align-items: center;\n                gap: var(--ui-space-md);\n            }\n\n            .range {\n                flex: 0 1 20px;\n                block-size: 12px;\n            }\n\n            .slider {\n                position: relative;\n                box-sizing: border-box;\n                inline-size: 100%;\n                min-inline-size: 200px;\n                max-inline-size: 640px;\n                block-size: 32px;\n            }\n\n            .track,\n            .filled {\n                position: absolute;\n                inset-block-start: 15px;\n                inline-size: 100%;\n                block-size: 2px;\n            }\n\n            .track {\n                background: var(--ui-hairline);\n            }\n\n            .track::before {\n                content: '';\n                position: absolute;\n                inset-block-start: -5px;\n                inset-inline-start: 50%;\n                inline-size: 2px;\n                block-size: 4px;\n                background: var(--ui-hairline);\n                transform: translateX(-50%);\n            }\n\n            .filled {\n                background: var(--ui-slider-fill, var(--ui-layer-selected-inverse));\n            }\n\n            :host([two-handles]) .slider {\n                margin-inline: var(--ui-space-xxs);\n            }\n\n            /* the handles' flat sides meet the track's ends; in RTL Carbon swaps the icons, the same as a mirror */\n            .handle {\n                position: absolute;\n                inset-block-start: 4px;\n                display: block;\n                inline-size: 16px;\n                block-size: 24px;\n                fill: var(--ui-slider-fill, var(--ui-layer-selected-inverse));\n            }\n\n            .handle.lower {\n                inset-inline-end: 100%;\n            }\n\n            .handle.upper {\n                inset-inline-start: 100%;\n            }\n\n            :host(:dir(rtl)) .handle {\n                transform: scaleX(-1);\n            }\n\n            .thumb {\n                position: absolute;\n                inset-block-start: 9px;\n                inset-inline-start: calc(50% - 7px);\n                inline-size: 14px;\n                block-size: 14px;\n                border-radius: 50%;\n                background: var(--ui-slider-fill, var(--ui-layer-selected-inverse));\n            }\n        `,\n    ];\n\n    @property({ type: Boolean, reflect: true, attribute: 'hide-label' }) hideLabel = false;\n\n    /** The skeleton of a two-thumb slider (`<ui-slider value-upper>`). */\n    @property({ type: Boolean, reflect: true, attribute: 'two-handles' }) twoHandles = false;\n\n    override render() {\n        return html`<span class=\"bone label\" part=\"label\"></span>\n            <div class=\"container\">\n                <span class=\"bone range\" part=\"range-label\"></span>\n                <div class=\"slider\">\n                    <span class=\"track\"></span><span class=\"filled\"></span>\n                    ${this.twoHandles ? handles : thumb}\n                </div>\n                <span class=\"bone range\" part=\"range-label\"></span>\n            </div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-slider-skeleton': UiSliderSkeleton;\n    }\n}\n"
    },
    {
      "path": "src/primitives/slider/slider.styles.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/slider/slider.styles.ts",
      "content": "import { css } from 'lit';\n\n/** Styles of `<ui-slider>`. */\nexport const sliderStyles = css`\n    :host {\n        display: block;\n        font-family: var(--ui-font-family);\n    }\n\n    .label {\n        display: block;\n    }\n\n    .container {\n        position: relative;\n        display: flex;\n        align-items: center;\n        gap: var(--ui-space-md);\n        user-select: none;\n    }\n\n    /* too narrow for the track's 200px and the boxes (a phone; set by the slider): the row wraps instead of widening the page */\n    .container.wrap {\n        flex-wrap: wrap;\n    }\n\n    .container.wrap .slider {\n        flex: 1 1 200px;\n    }\n\n    .range-label {\n        color: var(--ui-ink);\n        font: var(--ui-font-body-sm);\n        line-height: 18px; /* body-compact-01 */\n        letter-spacing: var(--ui-tracking-body);\n        white-space: nowrap;\n    }\n\n    .slider {\n        position: relative;\n        box-sizing: border-box;\n        inline-size: 100%;\n        min-inline-size: 200px;\n        max-inline-size: 640px;\n        padding: var(--ui-space-md) 0;\n        cursor: pointer;\n        touch-action: none;\n    }\n\n    .track {\n        position: absolute;\n        inline-size: 100%;\n        block-size: 2px;\n        background: var(--ui-hairline);\n        transform: translate(0, -50%);\n    }\n\n    .track::before {\n        content: '';\n        position: absolute;\n        inset-block-start: -5px;\n        inset-inline-start: 50%;\n        display: var(--ui-slider-tick, inline-block); /* Carbon's mark at the middle; a design can drop it (none) */\n        inline-size: 2px;\n        block-size: 4px;\n        background: var(--ui-hairline);\n        transform: translate(-50%, 0);\n    }\n\n    .filled-track {\n        position: absolute;\n        inline-size: 100%;\n        block-size: 2px;\n        background: var(--ui-slider-fill, var(--ui-layer-selected-inverse));\n        pointer-events: none;\n        transform-origin: left;\n        /* from the lower thumb (a range) or the start, to the (upper) thumb */\n        transform: translate(calc(var(--_p0, 0) * 100%), -50%) scaleX(calc(var(--_p, 0) - var(--_p0, 0)));\n        transition: background var(--ui-duration-moderate) var(--ui-easing);\n    }\n\n    .thumb-wrapper {\n        position: absolute;\n        z-index: 3;\n        inline-size: 14px;\n        block-size: 14px;\n        inset-inline-start: calc(var(--_p, 0) * 100%);\n        transform: translate(-50%, -50%);\n    }\n\n    :host(:dir(rtl)) .thumb-wrapper {\n        transform: translate(50%, -50%);\n    }\n\n    :host(:dir(rtl)) .filled-track {\n        transform-origin: right;\n        transform: translate(calc(var(--_p0, 0) * -100%), -50%) scaleX(calc(var(--_p, 0) - var(--_p0, 0)));\n    }\n\n    /* ---- two thumbs (Carbon cds--slider-container--two-handles) ---- */\n    .range .slider {\n        margin-inline: var(--ui-space-xxs);\n    }\n\n    /*\n     * --ui-slider-range-*: Carbon's two flag icons, before and after their values; a design can centre round thumbs on\n     * their values instead (a 24px hit area round a smaller dot: the -inset), as the single slider's\n     */\n    .range .thumb-wrapper {\n        inline-size: var(--ui-slider-range-handle-width, 16px);\n        block-size: var(--ui-slider-range-handle-height, 24px);\n    }\n\n    /* the lower thumb sits before its value, the upper one after */\n    .range .thumb-wrapper.lower {\n        inset-inline-start: calc(var(--_p0, 0) * 100%);\n        transform: translate(var(--ui-slider-range-lower-offset, -100%), -50%);\n    }\n\n    .range .thumb-wrapper.upper {\n        transform: translate(var(--ui-slider-range-upper-offset, 0%), -50%);\n    }\n\n    :host(:dir(rtl)) .range .thumb-wrapper.lower {\n        transform: translate(calc(-1 * var(--ui-slider-range-lower-offset, -100%)), -50%);\n    }\n\n    :host(:dir(rtl)) .range .thumb-wrapper.upper {\n        transform: translate(calc(-1 * var(--ui-slider-range-upper-offset, 0%)), -50%);\n    }\n\n    .range .thumb,\n    .range .thumb:hover,\n    .range .thumb:focus,\n    .range .thumb:active {\n        inset: var(--ui-slider-range-thumb-inset, 0px);\n        border-radius: var(--ui-slider-range-thumb-radius, 0);\n        background: var(--ui-slider-range-thumb, transparent);\n        box-shadow: none;\n        transform: none;\n    }\n\n    .range .thumb:hover {\n        background: var(--ui-slider-range-thumb-hover, var(--ui-slider-range-thumb, transparent));\n    }\n\n    .range .thumb:focus {\n        box-shadow: var(--ui-slider-range-focus-ring, none);\n    }\n\n    /* Carbon: a 6×2 page-coloured gap where the thumb's flat side meets the track (the whole width while focused) */\n    .range .thumb::before {\n        content: '';\n        position: absolute;\n        z-index: -1;\n        inset-block-start: calc(50% - 1px);\n        inline-size: 6px;\n        block-size: 2px;\n        background: var(--ui-slider-range-gap, var(--ui-canvas));\n    }\n\n    .range .thumb[data-handle='lower']::before {\n        inset-inline-end: 0;\n    }\n\n    .range .thumb[data-handle='upper']::before {\n        inset-inline-start: 0;\n    }\n\n    .range .thumb:focus::before {\n        inline-size: 100%;\n    }\n\n    .handle-icon {\n        position: absolute;\n        inset: 0;\n        display: block;\n        inline-size: 16px;\n        block-size: 24px;\n        fill: var(--ui-slider-fill, var(--ui-layer-selected-inverse));\n        opacity: var(--ui-slider-range-icon-opacity, 1);\n    }\n\n    /* Carbon swaps the lower / upper icons in RTL so the flat side still meets the track: the same as a mirror */\n    :host(:dir(rtl)) .handle-icon {\n        transform: scaleX(-1);\n    }\n\n    .handle-icon.focus,\n    .thumb:focus .handle-icon:not(.focus) {\n        display: none;\n    }\n\n    .thumb:focus .handle-icon.focus {\n        display: block;\n        fill: var(--ui-interactive, var(--ui-primary));\n    }\n\n    .thumb:hover .handle-icon:not(.focus) {\n        fill: var(--ui-slider-handle-hover, var(--ui-ink-muted));\n    }\n\n    .disabled .handle-icon,\n    .disabled .thumb:hover .handle-icon:not(.focus) {\n        fill: var(--ui-border-disabled);\n    }\n\n    .readonly.range .thumb {\n        inline-size: 0;\n        block-size: 0;\n    }\n\n    .readonly.range .handle-icon {\n        display: none;\n    }\n\n    ui-tooltip {\n        display: block;\n        inline-size: 100%;\n        block-size: 100%;\n    }\n\n    .thumb {\n        position: absolute;\n        inset: 0;\n        border-radius: 50%;\n        background: var(--ui-slider-fill, var(--ui-layer-selected-inverse));\n        box-shadow:\n            inset 0 0 0 1px transparent,\n            inset 0 0 0 2px transparent;\n        outline: none;\n        transition:\n            transform var(--ui-duration-moderate) var(--ui-easing),\n            background var(--ui-duration-moderate) var(--ui-easing),\n            box-shadow var(--ui-duration-moderate) var(--ui-easing);\n    }\n\n    .thumb:hover {\n        transform: scale(1.4286);\n    }\n\n    /* Carbon cds--slider__thumb:focus (a click or drag too, not only the keyboard): blue fill, 2px blue + layer ring, scaled */\n    .thumb:focus {\n        background-color: var(--ui-interactive, var(--ui-primary));\n        box-shadow:\n            inset 0 0 0 2px var(--ui-interactive, var(--ui-primary)),\n            inset 0 0 0 3px var(--ui-surface-1);\n        transform: scale(1.4286);\n    }\n\n    .thumb:active {\n        box-shadow: inset 0 0 0 2px var(--ui-interactive, var(--ui-primary));\n        transform: scale(1.4286);\n    }\n\n    .thumb-wrapper:focus-within ~ .filled-track {\n        background-color: var(--ui-border-interactive);\n    }\n\n    .input-wrapper {\n        position: relative;\n    }\n\n    /* Carbon's 64px, wider for numbers that wouldn't fit in its own font and size (--_chars: the longest value's characters, set by the slider) */\n    input {\n        box-sizing: border-box;\n        inline-size: max(64px, calc(var(--_chars, 0) * 1ch + 2 * var(--ui-space-md)));\n        block-size: 40px;\n        margin: 0;\n        padding: 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-focus-width, 2px) solid transparent;\n        outline-offset: -2px;\n        /* Carbon slider-text-input is a 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::-webkit-inner-spin-button,\n    input::-webkit-outer-spin-button {\n        appearance: none;\n        margin: 0;\n    }\n\n    input:focus {\n        outline-color: var(--ui-focus);\n    }\n\n    .has-status input {\n        inline-size: max(96px, calc(var(--_chars, 0) * 1ch + var(--ui-space-md) + var(--ui-space-xxl)));\n        padding-inline-end: var(--ui-space-xxl);\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        outline-color: var(--ui-focus);\n    }\n\n    .status {\n        position: absolute;\n        inset-block-start: 50%;\n        inset-inline-end: var(--ui-space-md);\n        display: flex;\n        transform: translateY(-50%);\n        pointer-events: none;\n    }\n\n    /* disabled */\n    .disabled .slider {\n        cursor: not-allowed;\n    }\n\n    .disabled .range-label,\n    :host([data-disabled]) .label {\n        color: var(--ui-ink-disabled);\n    }\n\n    .disabled .thumb,\n    .disabled .thumb:hover,\n    .disabled .thumb:focus,\n    .disabled .filled-track,\n    .disabled .thumb-wrapper:focus-within ~ .filled-track {\n        background: var(--ui-border-disabled);\n        box-shadow: none;\n        transform: translate(calc(var(--_p0, 0) * 100%), -50%) scaleX(calc(var(--_p, 0) - var(--_p0, 0)));\n    }\n\n    /* the whole track greys, at its full width (Carbon cds--slider--disabled .cds--slider__track) */\n    .disabled .track {\n        background: var(--ui-border-disabled);\n    }\n\n    .disabled .thumb,\n    .disabled .thumb:hover {\n        transform: none;\n        cursor: not-allowed;\n    }\n\n    .disabled input,\n    .disabled input:focus {\n        border-color: var(--ui-field-disabled-border-color, currentColor currentColor transparent);\n        color: var(--ui-ink-disabled);\n        cursor: not-allowed;\n        outline: none;\n    }\n\n    /* read-only */\n    .readonly .slider {\n        cursor: default;\n    }\n\n    .readonly .thumb {\n        inline-size: 0;\n        block-size: 0;\n        inset: auto;\n    }\n\n    /* read-only without the number box: the hidden thumb still takes focus (like a read-only input), so ring the track */\n    .readonly .slider:has(.thumb:focus) {\n        outline: var(--ui-focus-width, 2px) solid var(--ui-focus);\n        outline-offset: 2px;\n    }\n\n    .readonly input {\n        background-color: transparent;\n    }\n\n    .sr-live {\n        position: absolute;\n        width: 1px;\n        height: 1px;\n        overflow: hidden;\n        clip-path: inset(50%);\n    }\n\n    @media (forced-colors: active) {\n        .track,\n        .filled-track {\n            background: CanvasText;\n        }\n\n        .thumb {\n            border: 1px solid CanvasText;\n        }\n\n        .thumb:focus {\n            outline: 2px solid Highlight;\n        }\n    }\n`;\n"
    },
    {
      "path": "src/primitives/slider/slider.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/slider/slider.ts",
      "content": "import { html, nothing, svg } from 'lit';\nimport { customElement, property, query, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { live } from 'lit/directives/live.js';\nimport { styleMap } from 'lit/directives/style-map.js';\nimport { fieldTextStyles, messageId, pickMessage, renderLabelText, renderMessage, renderStatusIcon, uid, barWhenDisabled, isLabelClick, customErrorMessage, pickErrorText, type MessageKind } from '../shared/field.ts';\nimport { FormControlController } from '../shared/form-control.ts';\nimport { SlotController } from '../shared/slots.ts';\nimport { RowWrapController } from '../shared/row-wrap.ts';\nimport '../tooltip/tooltip.ts';\nimport { LocalizeController } from '../shared/localize.ts';\nimport { UiElement } from '../shared/element.ts';\nimport { boundedHandleValue, clampToRange as clamp, commitSliderText, nearestHandle, sliderFraction, sliderInputChars, sliderKeyValue, typedSliderValue, valueAtFraction, type SliderHandle } from '../../core/slider.ts';\nimport { sliderStyles } from './slider.styles.ts';\n\nexport type SliderFormatLabel = (value: number, label?: string) => string;\n\n/**\n * Carbon `Slider` (single handle): a 2px track with a 14px round thumb (`role=slider`), min / max\n * labels and a 64px number input that mirrors the value. Drag or click the track; Left / Down and\n * Right / Up move by `step` (× `step-multiplier` with Shift), Home / End jump to the ends. Typing\n * applies at once while the number is in range; on blur or Enter an out-of-range number is\n * clamped (announced politely) and text that is not a number marks the field invalid.\n * `hide-text-input` replaces the input with a value tooltip on the thumb.\n *\n * Form-associated: submits `value` under `name`. Fires `input` while dragging / stepping and\n * `change` when the value is committed (pointer released, key handled, input committed).\n *\n * Two thumbs (Carbon `unstable_valueUpper`): set `value-upper` and the slider picks a range — the lower and upper\n * thumbs (Carbon's handle icons, named \"Lower bound\" / \"Upper bound\") never pass each other, a click on the track\n * moves the nearer one, and each has its number box (lower before the track, upper after). The form gets both\n * values: under `name`, or the upper one under `name-upper`.\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 - Rich label (overrides `label`)\n * @slot invalid-text - Rich error text\n * @slot warn-text - Rich warning text\n * @csspart label - The label\n * @csspart base - Row with labels, track and input\n * @csspart min-label - Minimum label\n * @csspart max-label - Maximum label\n * @csspart track - The 2px track\n * @csspart filled-track - The filled part\n * @csspart thumb - The handle (`role=slider`)\n * @csspart thumb-lower - With `value-upper`: the lower handle (also `thumb`)\n * @csspart thumb-upper - With `value-upper`: the upper handle (also `thumb`)\n * @csspart input - The number input\n * @csspart input-lower - With `value-upper`: the lower bound's input (also `input`)\n * @csspart input-upper - With `value-upper`: the upper bound's input (also `input`)\n * @csspart error-text - Error text below\n * @csspart invalid-text - Same line as `error-text` (named after the `invalid-text` attribute / slot)\n * @csspart warning-text - Warning text below\n * @csspart warn-text - Same line as `warning-text` (named after the `warn-text` attribute / slot)\n * @cssprop --ui-field-border / --ui-field-radius / --ui-field-background - The number box, as the other fields\n * @cssprop --ui-slider-fill - The thumb, the filled track and the range handles (default `--ui-layer-selected-inverse`; Kanok: `--ui-interactive`)\n * @cssprop --ui-slider-handle-hover - A range handle under the pointer (default `--ui-ink-muted`)\n * @cssprop --ui-slider-tick - `display` of the mark at the middle of the track (default inline-block; Kanok: none)\n * @cssprop --ui-slider-range-handle-width / --ui-slider-range-handle-height / --ui-slider-range-lower-offset / --ui-slider-range-upper-offset - A range's handle box and where it sits on its value (default 16 × 24px, beside the value: Carbon's flags)\n * @cssprop --ui-slider-range-thumb / --ui-slider-range-thumb-hover / --ui-slider-range-thumb-inset / --ui-slider-range-thumb-radius / --ui-slider-range-focus-ring - A range thumb drawn in the handle (default none: the flag icons only; Kanok: a round dot)\n * @cssprop --ui-slider-range-gap / --ui-slider-range-icon-opacity - The gap where a flag meets the track and the flags' opacity (default the page colour, 1)\n */\n@customElement('ui-slider')\nexport class UiSlider extends UiElement {\n    static override hostStates: readonly string[] = ['show-error', 'show-warn'];\n\n    static readonly formAssociated = true;\n\n    static override readonly styles = [fieldTextStyles, sliderStyles];\n\n    @property() label = '';\n\n    private readonly localize = new LocalizeController(this);\n\n    @property({ type: Boolean, attribute: 'hide-label' }) hideLabel = false;\n\n    @property({ type: Number }) value = 0;\n\n    /** A second thumb: the slider picks the range `value`…`value-upper` (Carbon `unstable_valueUpper`). */\n    @property({ type: Number, attribute: 'value-upper' }) valueUpper: number | null = null;\n\n    /** The name the upper value is submitted under (default: `name`, so the form gets both under one name). */\n    @property({ attribute: 'name-upper' }) nameUpper = '';\n\n    /** Accessible name of the upper number box (Carbon `unstable_ariaLabelInputUpper`; default \"Upper bound\"). */\n    @property({ attribute: 'upper-input-label' }) upperInputLabel = '';\n\n    @property({ type: Number }) min = 0;\n\n    @property({ type: Number }) max = 100;\n\n    @property({ type: Number }) step = 1;\n\n    /** Shift + arrow moves by `step × step-multiplier`. */\n    @property({ type: Number, attribute: 'step-multiplier' }) stepMultiplier = 4;\n\n    /** Appended to the min / max numbers, e.g. \"%\" (Carbon `minLabel` / `maxLabel`). */\n    @property({ attribute: 'min-label' }) minLabel = '';\n\n    @property({ attribute: 'max-label' }) maxLabel = '';\n\n    /** Formats min / max labels and the value tooltip (Carbon `formatLabel`). */\n    @property({ attribute: false }) formatLabel: SliderFormatLabel = (value, label) => `${value}${label ?? ''}`;\n\n    /** Accessible name of the number input (Carbon `ariaLabelInput`). */\n    @property({ attribute: 'input-label' }) inputLabel = '';\n\n    @property({ type: Boolean, reflect: true, attribute: 'hide-text-input' }) hideTextInput = false;\n\n    @property({ reflect: true }) name = '';\n\n    @property({ type: Boolean, reflect: true }) disabled = false;\n\n    @property({ type: Boolean, reflect: true }) readonly = false;\n\n    @property({ type: Boolean, reflect: true }) required = false;\n\n    @property({ type: Boolean, reflect: true }) invalid = false;\n\n    @property({ attribute: 'invalid-text' }) invalidText = '';\n\n    @property({ type: Boolean, reflect: true }) warn = false;\n\n    @property({ attribute: 'warn-text' }) warnText = '';\n\n    /** Announcement after an out-of-range number is clamped; `{value}` is the typed number (Carbon auto-correct message). */\n    @property({ attribute: 'corrected-text' }) correctedText = '';\n\n    /** Text in the input while the user types (may be a partial number). */\n    @state() private text = '';\n\n    /** Text in the upper number box (a range slider). */\n    @state() private textUpper = '';\n\n    /** The input holds something that is not a number (Carbon `isValid = false`). */\n    @state() private notANumber = false;\n\n    @state() private corrected = '';\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);\n\n    @query('.thumb') private readonly thumb!: HTMLElement;\n\n    @query('.slider') private readonly sliderEl!: HTMLElement;\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 slots = new SlotController(this);\n    /** Too narrow for the row at the track's 200px (a phone): the row wraps instead of widening the page. */\n    private readonly rowWrap = new RowWrapController(this, '.container', '.slider');\n    private readonly ids = uid('ui-slider');\n    private defaultValue = 0;\n    private defaultValueUpper: number | null = null;\n    private dragging = false;\n    /** The thumb a pointer drag moves. */\n    private dragHandle: SliderHandle = 'lower';\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        return this.formControl.reportValidity(this.internals);\n    }\n\n    formResetCallback() {\n        this.value = this.defaultValue;\n        this.valueUpper = this.defaultValueUpper;\n        this.notANumber = false;\n    }\n\n    formStateRestoreCallback(state: string | File | FormData | null) {\n        if (typeof state === 'string') this.value = Number(state);\n        if (state instanceof FormData) {\n            const [lower, upper] = [...state.values()].map(Number);\n            this.value = lower;\n            this.valueUpper = upper ?? this.valueUpper;\n        }\n    }\n\n    formDisabledCallback(disabled: boolean) {\n        this.formControl.setFieldsetDisabled(disabled);\n    }\n\n    constructor() {\n        super();\n        this.addEventListener('click', this.onLabelClick);\n    }\n\n    /** `<label for>` / a wrapping label: focus the thumb, as a label focuses its range input. */\n    private readonly onLabelClick = (event: MouseEvent) => {\n        if (isLabelClick(this, event) && this.interactive) this.thumb.focus();\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.defaultValue = this.value;\n            this.defaultValueUpper = this.valueUpper;\n        });\n        this.text = String(this.value);\n        this.textUpper = String(this.upper);\n    }\n\n    override disconnectedCallback() {\n        super.disconnectedCallback();\n        this.stopDrag();\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    /** Two thumbs (`value-upper` set). */\n    get isRange() {\n        return this.valueUpper !== null && this.valueUpper !== undefined;\n    }\n\n    /** The upper thumb's value (the max while there is none). */\n    private get upper() {\n        return this.valueUpper ?? this.max;\n    }\n\n    /** 0..1 position of the value on the track (the upper thumb's in a range). */\n    private get fraction() {\n        return sliderFraction(this.isRange ? this.upper : this.value, this);\n    }\n\n    /** 0..1 where the filled track starts: the lower thumb in a range, else the start. */\n    private get fractionStart() {\n        return this.isRange ? sliderFraction(this.value, this) : 0;\n    }\n\n    /** Where a thumb may go: the track, up to (or from) the other thumb in a range (Carbon's number boxes' min / max). */\n    private boundsOf(handle: SliderHandle) {\n        if (!this.isRange) return { min: this.min, max: this.max, step: this.step };\n        return handle === 'upper' ? { min: this.value, max: this.max, step: this.step } : { min: this.min, max: this.upper, step: this.step };\n    }\n\n    private handleValue(handle: SliderHandle) {\n        return handle === 'upper' ? this.upper : this.value;\n    }\n\n    protected override willUpdate(changed: Map<string, unknown>) {\n        if (changed.has('value') && !this.notANumber) this.text = String(this.value);\n        if (changed.has('valueUpper') && !this.notANumber) this.textUpper = String(this.upper);\n        if (changed.has('min') || changed.has('max') || changed.has('value') || changed.has('valueUpper')) {\n            if (this.isRange) {\n                // the thumbs stay on the track and in order\n                this.valueUpper = clamp(this.upper, this.min, this.max);\n                this.value = clamp(this.value, this.min, this.upper);\n            } else if (changed.has('min') || changed.has('max')) {\n                this.value = clamp(this.value, this.min, this.max);\n            }\n        }\n    }\n\n    protected override updated() {\n        this.toggleAttribute('data-disabled', this.isDisabled);\n        this.syncFormState();\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 syncFormState() {\n        if (barWhenDisabled(this.internals, this.isDisabled)) return;\n        if (this.isRange && this.name) {\n            const data = new FormData();\n            data.append(this.name, String(this.value));\n            data.append(this.nameUpper || this.name, String(this.upper));\n            this.internals.setFormValue(data);\n        } else {\n            this.internals.setFormValue(String(this.value));\n        }\n        const customError = customErrorMessage(this.invalid, this.invalidText, this.customValidityMessage);\n        if (customError) this.internals.setValidity({ customError: true }, customError, this.thumb);\n        else if (this.notANumber) this.internals.setValidity({ badInput: true }, this.invalidText || this.localize.t.field.enterNumber, this.thumb);\n        else this.internals.setValidity({});\n    }\n\n    /** The thumb is the tab stop when the slider is usable, and also when it is read-only with no number box to focus instead. */\n    private get thumbFocusable() {\n        return this.interactive || (this.readonly && this.hideTextInput && !this.isDisabled);\n    }\n\n    private get showError() {\n        return this.interactive && (this.invalid || this.notANumber || !!this.customValidityMessage);\n    }\n\n    private commit(next: number, final: boolean, handle: SliderHandle = 'lower') {\n        const value = this.isRange ? boundedHandleValue(handle, next, this.value, this.upper, this) : clamp(next, this.min, this.max);\n        const changed = value !== this.handleValue(handle);\n        if (handle === 'upper') this.valueUpper = value;\n        else this.value = value;\n        this.notANumber = false;\n        if (changed) this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));\n        if (final && changed) this.dispatchEvent(new Event('change', { bubbles: true }));\n        return changed;\n    }\n\n    // ---- pointer ----\n\n    private valueAt(clientX: number) {\n        const rect = this.sliderEl.getBoundingClientRect();\n        let fraction = rect.width === 0 ? 0 : clamp((clientX - rect.left) / rect.width, 0, 1);\n        if (getComputedStyle(this).direction === 'rtl') fraction = 1 - fraction;\n        return valueAtFraction(fraction, this);\n    }\n\n    private onPointerDown(event: PointerEvent) {\n        if (!this.interactive || event.button !== 0) return;\n        event.preventDefault();\n        const at = this.valueAt(event.clientX);\n        // a range: the thumb pressed, else the one nearer the click\n        const pressed = (event.composedPath()[0] as Element | undefined)?.closest?.<HTMLElement>('[data-handle]')?.dataset.handle as SliderHandle | undefined;\n        this.dragHandle = this.isRange ? (pressed ?? nearestHandle(at, this.value, this.upper)) : 'lower';\n        this.dragging = true;\n        this.valueBeforeDrag = this.handleValue(this.dragHandle);\n        this.corrected = '';\n        try {\n            this.sliderEl.setPointerCapture(event.pointerId);\n        } catch {\n            /* synthetic events have no active pointer */\n        }\n        globalThis.addEventListener('pointermove', this.onPointerMove);\n        globalThis.addEventListener('pointerup', this.onPointerUp);\n        globalThis.addEventListener('pointercancel', this.onPointerUp);\n        this.commit(at, false, this.dragHandle);\n        this.thumbOf(this.dragHandle)?.focus({ preventScroll: true });\n    }\n\n    private thumbOf(handle: SliderHandle) {\n        return this.renderRoot.querySelector<HTMLElement>(`.thumb[data-handle=\"${handle}\"]`) ?? this.thumb;\n    }\n\n    private readonly onPointerMove = (event: PointerEvent) => {\n        if (this.dragging) this.commit(this.valueAt(event.clientX), false, this.dragHandle);\n    };\n\n    private readonly onPointerUp = (event: PointerEvent) => {\n        if (!this.dragging) return;\n        this.commit(this.valueAt(event.clientX), false, this.dragHandle);\n        this.stopDrag();\n        if (this.handleValue(this.dragHandle) !== this.valueBeforeDrag) this.dispatchEvent(new Event('change', { bubbles: true }));\n    };\n\n    /** Value when the drag started: release fires `change` only when it moved. */\n    private valueBeforeDrag = 0;\n\n    private stopDrag() {\n        this.dragging = false;\n        globalThis.removeEventListener('pointermove', this.onPointerMove);\n        globalThis.removeEventListener('pointerup', this.onPointerUp);\n        globalThis.removeEventListener('pointercancel', this.onPointerUp);\n    }\n\n    // ---- keyboard on the thumb ----\n\n    private onThumbKeydown(event: KeyboardEvent, handle: SliderHandle = 'lower') {\n        if (!this.interactive) return;\n        const rtl = getComputedStyle(this).direction === 'rtl';\n        const next = sliderKeyValue(event.key, event.shiftKey, this.handleValue(handle), { min: this.min, max: this.max, step: this.step, multiplier: this.stepMultiplier, rtl });\n        if (next === undefined) return;\n        event.preventDefault();\n        this.corrected = '';\n        this.commit(next, true, handle);\n    }\n\n    // ---- number input ----\n\n    /** Typing changed the value since the last blur / Enter. */\n    private textChangePending = false;\n\n    private onInput(event: Event, handle: SliderHandle = 'lower') {\n        // the inner input's composed `input` would reach the page alongside the one commit() dispatches\n        event.stopPropagation();\n        if (!this.interactive) return;\n        const input = event.target as HTMLInputElement;\n        if (handle === 'upper') this.textUpper = input.value;\n        else this.text = input.value;\n        // Carbon: in-range numbers apply immediately; out-of-range waits for blur / Enter\n        const typed = typedSliderValue(input.value, this.boundsOf(handle));\n        if (typed !== undefined && this.commit(typed, false, handle)) this.textChangePending = true;\n    }\n\n    /** Blur / Enter: clamp out-of-range numbers (and say so), flag text that is not a number. */\n    private processText(handle: SliderHandle = 'lower') {\n        const result = commitSliderText(handle === 'upper' ? this.textUpper : this.text, this.boundsOf(handle));\n        if (result.notANumber) {\n            this.notANumber = true;\n            this.corrected = '';\n            return;\n        }\n        this.corrected = result.corrected === undefined ? '' : (this.correctedText || this.localize.t.field.sliderCorrected).replace('{value}', String(result.corrected));\n        this.notANumber = false;\n        // typing already applied in-range values (input only); blur / Enter commits them with one `change`\n        const changed = this.commit(result.value, true, handle);\n        if (!changed && this.textChangePending) this.dispatchEvent(new Event('change', { bubbles: true }));\n        this.textChangePending = false;\n        // a number past the other thumb was held back to it: the box shows where the thumb is\n        this.text = String(this.value);\n        this.textUpper = String(this.upper);\n    }\n\n    private onInputKeydown(event: KeyboardEvent, handle: SliderHandle = 'lower') {\n        if (event.key === 'Enter') this.processText(handle);\n    }\n\n    /** Carbon's range thumb icons (16 × 24): the plain one, and the focused one with its box. */\n    private handleIcons(handle: SliderHandle) {\n        const shape =\n            handle === 'lower'\n                ? svg`<path d=\"M15.08 6.46H16v11.08h-.92zM4.46 17.54c-.25 0-.46-.21-.46-.46V6.92a.465.465 0 0 1 .69-.4l8.77 5.08a.46.46 0 0 1 0 .8l-8.77 5.08c-.07.04-.15.06-.23.06Z\" />`\n                : svg`<path d=\"M0 6.46h.92v11.08H0zM11.54 6.46c.25 0 .46.21.46.46v10.15a.465.465 0 0 1-.69.4L2.54 12.4a.46.46 0 0 1 0-.8l8.77-5.08c.07-.04.15-.06.23-.06Z\" />`;\n        const box =\n            handle === 'lower'\n                ? svg`<path d=\"M15.08 0H16v6.46h-.92zM0 0h.92v24H0zM15.08 0H16v24h-.92zM0 .92V0h16v.92zM0 24v-.92h16V24z\" />`\n                : svg`<path d=\"M.92 24H0v-6.46h.92zM16 24h-.92V0H16zM.92 24H0V0h.92zM16 23.08V24H0v-.92zM16 0v.92H0V0z\" />`;\n        return html`<svg class=\"handle-icon\" viewBox=\"0 0 16 24\" aria-hidden=\"true\">${shape}</svg><svg class=\"handle-icon focus\" viewBox=\"0 0 16 24\" aria-hidden=\"true\">${shape}${box}</svg>`;\n    }\n\n    /** The thumb is the slider control, so it carries the error state and message too (the only control with `hide-text-input`). */\n    private renderThumb(showError: boolean, described: string | undefined, handle: SliderHandle = 'lower') {\n        const range = this.isRange;\n        const value = this.handleValue(handle);\n        // a range: each thumb is named by the slider's label and its bound, and can't pass the other\n        const labelledBy = range ? `${this.ids}-label ${this.ids}-${handle}-name` : `${this.ids}-label`;\n        const thumb = html`<div\n            class=\"thumb\"\n            part=${range ? `thumb thumb-${handle}` : 'thumb'}\n            role=\"slider\"\n            data-handle=${handle}\n            id=${`${this.ids}-${range ? handle : 'thumb'}`}\n            tabindex=${ifDefined(this.thumbFocusable ? 0 : undefined)}\n            aria-valuemin=${range && handle === 'upper' ? this.value : this.min}\n            aria-valuemax=${range && handle === 'lower' ? this.upper : this.max}\n            aria-valuenow=${value}\n            aria-valuetext=${this.formatLabel(value)}\n            aria-labelledby=${labelledBy}\n            aria-disabled=${ifDefined(this.isDisabled ? 'true' : undefined)}\n            aria-readonly=${ifDefined(this.readonly ? 'true' : undefined)}\n            aria-invalid=${ifDefined(showError ? 'true' : undefined)}\n            aria-describedby=${ifDefined(described)}\n            @keydown=${(event: KeyboardEvent) => this.onThumbKeydown(event, handle)}\n        >${range ? this.handleIcons(handle) : nothing}</div>`;\n        if (!this.hideTextInput) return thumb;\n        return html`<ui-tooltip text=${this.formatLabel(value)} placement=\"top\">${thumb}</ui-tooltip>`;\n    }\n\n    private renderInput(showError: boolean, described: string | undefined, hasStatus: boolean, icon: unknown, handle: SliderHandle = 'lower') {\n        if (this.hideTextInput) return nothing;\n        const range = this.isRange;\n        let name = this.inputLabel || this.localize.t.field.sliderInput;\n        if (range) name = handle === 'upper' ? this.upperInputLabel || this.localize.t.field.sliderUpper : this.inputLabel || this.localize.t.field.sliderLower;\n        // a range: the status icon sits in the upper box, the one after the track\n        const status = !range || handle === 'upper';\n        const id = range ? `${this.ids}-${handle}-input` : `${this.ids}-input`;\n        return html`<div class=\"input-wrapper ${classMap({ 'has-status': hasStatus && status })}\">\n            <input\n                part=${range ? `input input-${handle}` : 'input'}\n                id=${id}\n                type=\"number\"\n                inputmode=\"decimal\"\n                style=${styleMap({ '--_chars': String(sliderInputChars(this.min, this.max, this.step)) })}\n                .value=${live(handle === 'upper' ? this.textUpper : this.text)}\n                aria-label=${name}\n                min=${range && handle === 'upper' ? this.value : this.min}\n                max=${range && handle === 'lower' ? this.upper : this.max}\n                step=${this.step}\n                ?disabled=${this.isDisabled}\n                ?readonly=${this.readonly}\n                ?required=${this.required}\n                aria-invalid=${showError ? 'true' : 'false'}\n                aria-describedby=${ifDefined(described)}\n                @input=${(event: Event) => this.onInput(event, handle)}\n                @blur=${() => this.processText(handle)}\n                @keydown=${(event: KeyboardEvent) => this.onInputKeydown(event, handle)}\n            />\n            ${status ? html`<span class=\"status\">${icon}</span>` : nothing}\n        </div>`;\n    }\n\n    /** Focus the handle. */\n    override focus(options?: FocusOptions) {\n        this.thumb?.focus(options);\n    }\n\n    /** One thumb, or a range's two with the \"Lower bound\" / \"Upper bound\" names their `aria-labelledby` points at. */\n    private renderThumbs(showError: boolean, described: string | undefined) {\n        if (!this.isRange) return html`<div class=\"thumb-wrapper\">${this.renderThumb(showError, described)}</div>`;\n        const [lowerName, upperName] = [`${this.ids}-lower-name`, `${this.ids}-upper-name`];\n        return html`<div class=\"thumb-wrapper lower\">${this.renderThumb(showError, described, 'lower')}</div>\n            <div class=\"thumb-wrapper upper\">${this.renderThumb(showError, described, 'upper')}</div>\n            <span class=\"sr-only\" id=${lowerName}>${this.localize.t.field.sliderLower}</span>\n            <span class=\"sr-only\" id=${upperName}>${this.localize.t.field.sliderUpper}</span>`;\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.notANumber ? this.localize.t.field.enterNumber : '')),\n            showWarn: this.warn && this.interactive,\n            warnText: this.warnText,\n            helperText: '',\n            slots: this.slots,\n        });\n        this.shownKind = message?.kind;\n        const hasStatus = !!message && message.kind !== 'helper';\n        const classes = { container: true, wrap: this.rowWrap.wraps, range: this.isRange, invalid: showError, disabled: this.isDisabled, readonly: this.readonly };\n        const described = messageId(this.ids, message);\n        const icon = renderStatusIcon(message);\n        return html`\n            <label class=${this.hideLabel ? 'sr-only' : 'label'} part=\"label\" id=${`${this.ids}-label`} for=${`${this.ids}-${this.isRange ? 'lower' : 'thumb'}`}>${renderLabelText(this.label, this.formControl.fallbackName(this.label, this.internals))}</label>\n            <div\n                class=${classMap(classes)}\n                part=\"base\"\n                role=\"group\"\n                aria-labelledby=${`${this.ids}-label`}\n                aria-disabled=${ifDefined(this.isDisabled ? 'true' : undefined)}\n                style=${`--_p: ${this.fraction}; --_p0: ${this.fractionStart}`}\n            >\n                ${this.isRange ? this.renderInput(showError, described, hasStatus, icon, 'lower') : nothing}\n                <span class=\"range-label\" part=\"min-label\">${this.formatLabel(this.min, this.minLabel)}</span>\n                <div class=\"slider\" part=\"track-wrapper\" @pointerdown=${this.onPointerDown}>\n                    ${this.renderThumbs(showError, described)}\n                    <div class=\"track\" part=\"track\"></div>\n                    <div class=\"filled-track\" part=\"filled-track\"></div>\n                </div>\n                <span class=\"range-label\" part=\"max-label\">${this.formatLabel(this.max, this.maxLabel)}</span>\n                ${this.renderInput(showError, described, hasStatus, icon, this.isRange ? 'upper' : 'lower')}\n            </div>\n            ${renderMessage(this.ids, message)}\n            <div class=\"sr-live\" aria-live=\"polite\">${this.corrected}</div>\n        `;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-slider': UiSlider;\n    }\n}\n"
    }
  ]
}
