{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "core-slider",
  "type": "registry:lib",
  "title": "core/slider",
  "description": "Framework-free behaviour shared by the ui-* components (slider); no DOM, no lit. 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": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/core/slider.ts",
      "type": "registry:lib",
      "target": "components/ui/core/slider.ts",
      "content": "/**\n * Carbon `Slider` behaviour, framework-free: where a value sits on the track, the nearest step,\n * what each key does on the thumb, and how a number typed into the box is committed.\n */\n\nexport interface SliderRange {\n    min: number;\n    max: number;\n    step: number;\n}\n\nexport const clampToRange = (value: number, min: number, max: number) => Math.min(Math.max(value, min), max);\n\nconst decimalsOfStep = (step: number) => (String(step).split('.')[1] ?? '').length;\n\n/** 0…1 position of `value` on the track. */\nexport function sliderFraction(value: number, { min, max }: Pick<SliderRange, 'min' | 'max'>): number {\n    const range = max - min;\n    return range === 0 ? 0 : clampToRange((value - min) / range, 0, 1);\n}\n\n/** The nearest allowed step to `value`, rounded to the step's precision and clamped. */\nexport function nearestStep(value: number, { min, max, step }: SliderRange): number {\n    const steps = Math.round((value - min) / step);\n    return clampToRange(Number((min + steps * step).toFixed(decimalsOfStep(step))), min, max);\n}\n\n/** The value at `fraction` (0…1) of the track, snapped to a step. */\nexport const valueAtFraction = (fraction: number, range: SliderRange) => nearestStep(range.min + clampToRange(fraction, 0, 1) * (range.max - range.min), range);\n\n/**\n * The value a key on the thumb asks for (unclamped), or undefined for other keys: Left / Down and\n * Right / Up move by `step` (× `multiplier` with Shift), Home / End jump to the ends. Stepping up\n * from an in-between value snaps to the step first (Carbon `calcValueForDelta`: 51 → 52, not 54).\n * Right-to-left (`rtl`, the track mirrored) Left and Right swap, so the thumb moves the way the arrow points, as a\n * native range input's.\n */\nexport function sliderKeyValue(key: string, shift: boolean, value: number, range: SliderRange & { multiplier: number; rtl?: boolean }): number | undefined {\n    const side = range.rtl ? -1 : 1;\n    const delta = ({ ArrowLeft: -side, ArrowDown: -1, ArrowRight: side, ArrowUp: 1 } as Record<string, number>)[key];\n    if (delta) {\n        const amount = delta * range.step * (shift ? range.multiplier : 1);\n        const base = amount > 0 ? Math.round(value / range.step) * range.step : value;\n        return Number((base + amount).toFixed(decimalsOfStep(range.step)));\n    }\n    if (key === 'Home') return range.min;\n    if (key === 'End') return range.max;\n    return undefined;\n}\n\n/** While typing (Carbon): a number in range applies at once (snapped); anything else waits for blur / Enter. */\nexport function typedSliderValue(text: string, range: SliderRange): number | undefined {\n    const typed = Number.parseFloat(text);\n    return Number.isNaN(typed) || typed < range.min || typed > range.max ? undefined : nearestStep(typed, range);\n}\n\n/**\n * Blur / Enter on the number box (Carbon): text that isn't a number is invalid; an out-of-range\n * number is clamped and `corrected` holds the typed number to announce.\n */\nexport function commitSliderText(text: string, range: SliderRange): { notANumber: true } | { notANumber: false; value: number; corrected?: number } {\n    const typed = Number.parseFloat(text);\n    if (Number.isNaN(typed)) return { notANumber: true };\n    const adjusted = clampToRange(typed, range.min, range.max);\n    return { notANumber: false, value: nearestStep(adjusted, range), corrected: adjusted === typed ? undefined : typed };\n}\n\n/** A range slider's two thumbs (Carbon `unstable_valueUpper`). */\nexport type SliderHandle = 'lower' | 'upper';\n\n/**\n * Which thumb a click on a range slider's track moves: the nearer one; on a tie the one on the side the click is\n * (past the upper → upper, else lower), so a click between two thumbs on the same value can still widen the range.\n */\nexport function nearestHandle(value: number, lower: number, upper: number): SliderHandle {\n    const toLower = Math.abs(value - lower);\n    const toUpper = Math.abs(value - upper);\n    if (toLower === toUpper) return value > upper ? 'upper' : 'lower';\n    return toLower < toUpper ? 'lower' : 'upper';\n}\n\n/** A thumb's next value kept on the track and on its own side of the other thumb (the lower never passes the upper). */\nexport function boundedHandleValue(handle: SliderHandle, next: number, lower: number, upper: number, { min, max }: Pick<SliderRange, 'min' | 'max'>): number {\n    return handle === 'lower' ? clampToRange(next, min, upper) : clampToRange(next, lower, max);\n}\n\n/**\n * How wide the number box must be, in characters, to show any value of the range: the longer of min and max, with the\n * decimals the step (or the bounds) allow, and half a character for the caret. The box is never narrower than Carbon's\n * 64px, so it widens only where a value wouldn't fit: 1000 in Carbon's 14px (its 64px box clips it by 2px), 100 in\n * Kanok's 16px, 50000 ฿ everywhere.\n */\nexport function sliderInputChars(min: number, max: number, step: number): number {\n    const decimals = (n: number) => (String(n).split('.')[1] ?? '').length;\n    const whole = (n: number) => String(Math.trunc(Math.abs(n))).length + (n < 0 ? 1 : 0);\n    const places = Math.max(decimals(min), decimals(max), decimals(step));\n    const chars = Math.max(whole(min), whole(max)) + (places ? places + 1 : 0);\n    return chars + 0.5;\n}\n\n/**\n * Whether a slider's row (number boxes, labels, the track at its 200px minimum, the gaps between them) is too wide for\n * the room it has, so it should wrap instead of widening the page (a phone). Half a pixel of give: Carbon's own rows\n * can be a fraction of a pixel too wide (font metrics) and stay on one line.\n */\nexport function sliderRowWraps(itemWidths: readonly number[], gap: number, available: number): boolean {\n    const need = itemWidths.reduce((sum, width) => sum + width, 0) + gap * Math.max(0, itemWidths.length - 1);\n    return need > available + 0.5;\n}\n"
    }
  ]
}
