{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slider",
  "title": "Slider",
  "description": "A ticked track with a cut thumb and a value readout, single or range.",
  "dependencies": [
    "@ui-sdk/react@0.1.0-beta.5"
  ],
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json"
  ],
  "files": [
    {
      "path": "registry/cyber/ui/slider.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Field, FieldDescription, FieldLabel } from \"@ui-sdk/react/field\"\nimport {\n  Slider as SdkSlider,\n  SliderControl,\n  SliderIndicator,\n  SliderThumb,\n  SliderTrack,\n  SliderValue,\n  type SliderValueChangeDetails,\n} from \"@ui-sdk/react/slider\"\nimport { crosses, haptic } from \"@/registry/cyber/lib/haptics\"\nimport { createAdjustmentSound, sfx } from \"@/registry/cyber/lib/sound\"\nimport \"@/registry/cyber/ui/cyber/slider.css\"\n\n// The changes a person makes by hand. A reset, a restore or a controller\n// (which is how an agent moves it) changes the value without anyone feeling\n// for a detent.\nconst byHand = new Set([\"drag\", \"track-press\", \"step-key\", \"accessibility-adjust\"])\n\n// A value on a scale: a thin rail under a row of ticks, a cut block to drag,\n// and the reading printed in the signal color. The ticks the value has\n// passed light up. Ticking follows movement, and crossing a mark is felt.\n//\n// - Pass a number for one thumb, or an array for a range: `[20, 80]` gives\n//   two thumbs that can't cross, and the reading shows both ends.\n// - `ticks` is how many divisions the scale is ruled into (10 by default).\n// - `thumbLabels` names each thumb of a range for assistive technology and\n//   agents; without it they're \"<label> from\" and \"<label> to\".\n// - `format` (the SDK's) decides how the reading and each thumb's value are\n//   written: `{ style: \"unit\", unit: \"percent\" }`, or a function.\nfunction Slider<Value extends number | number[] = number>({\n  label,\n  hint,\n  ticks = 10,\n  thumbLabels,\n  min = 0,\n  max = 100,\n  onValueChange,\n  onValueCommit,\n  ...props\n}: Omit<React.ComponentProps<typeof SdkSlider<Value>>, \"children\"> & {\n  label: string\n  hint?: string\n  ticks?: number\n  thumbLabels?: string[]\n}) {\n  const initial = props.value ?? props.defaultValue\n  const count = Array.isArray(initial) ? initial.length : 1\n  const detent = (max - min) / Math.max(1, ticks)\n  const toList = (value: number | number[] | undefined) => (value === undefined ? [] : Array.isArray(value) ? value : [value])\n  const last = React.useRef(toList(initial))\n  const adjustment = React.useMemo(createAdjustmentSound, [])\n  React.useEffect(() => adjustment.stop, [adjustment])\n  React.useEffect(() => {\n    if (props.disabled || props.readOnly) adjustment.stop()\n  }, [adjustment, props.disabled, props.readOnly])\n  React.useEffect(() => {\n    if (props.value !== undefined) last.current = toList(props.value)\n  }, [props.value])\n\n  const change = (next: Value, details: SliderValueChangeDetails) => {\n    onValueChange?.(next, details)\n    if (details.canceled) return adjustment.stop()\n    const list = toList(next)\n    const before = last.current\n    last.current = list\n    if (!byHand.has(details.reason)) return adjustment.stop()\n    if (details.reason === \"drag\") adjustment.move()\n    else {\n      adjustment.stop()\n      // Discrete keys, track presses and accessibility adjustments may\n      // commit immediately. Give each one a complete recorded tick.\n      sfx(\"hover\")\n    }\n    if (list.some((value, index) => crosses((before[index] ?? value) - min, value - min, detent))) {\n      haptic(\"selection\")\n    }\n  }\n\n  // One mark per division, plus the one that closes the scale.\n  const marks = Array.from({ length: Math.max(1, ticks) + 1 }, (_, index) => <span key={index} />)\n  const nameOf = (index: number) => thumbLabels?.[index] ?? (count === 2 ? `${label} ${index ? \"to\" : \"from\"}` : `${label} ${index + 1}`)\n\n  return (\n    <Field data-kit=\"field\">\n      <SdkSlider<Value>\n        data-kit=\"slider\"\n        data-range={count > 1 ? \"\" : undefined}\n        min={min}\n        max={max}\n        onValueChange={change}\n        {...props}\n        onValueCommit={(value, details) => {\n          adjustment.stop()\n          onValueCommit?.(value, details)\n        }}\n        onBlur={(event) => {\n          adjustment.stop()\n          props.onBlur?.(event)\n        }}\n        onPointerCancel={(event) => {\n          adjustment.stop()\n          props.onPointerCancel?.(event)\n        }}\n        onLostPointerCapture={(event) => {\n          adjustment.stop()\n          props.onLostPointerCapture?.(event)\n        }}\n      >\n        <div data-kit=\"slider-head\">\n          <FieldLabel data-kit=\"label\">{label}</FieldLabel>\n          <SliderValue data-kit=\"slider-value\" />\n        </div>\n        <SliderControl data-kit=\"slider-control\">\n          <SliderTrack data-kit=\"slider-track\">\n            <span data-kit=\"slider-scale\" aria-hidden>\n              {marks}\n            </span>\n            {/* The same scale again, lit, inside the filled part: the\n                indicator shows only as much of it as the value has passed. */}\n            <SliderIndicator data-kit=\"slider-indicator\">\n              <span data-kit=\"slider-scale\" data-lit=\"\" aria-hidden>\n                {marks}\n              </span>\n            </SliderIndicator>\n            {count > 1 ? (\n              Array.from({ length: count }, (_, index) => (\n                <SliderThumb key={index} data-kit=\"slider-thumb\" index={index} aria-label={nameOf(index)} />\n              ))\n            ) : (\n              <SliderThumb data-kit=\"slider-thumb\" />\n            )}\n          </SliderTrack>\n        </SliderControl>\n      </SdkSlider>\n      {hint && <FieldDescription data-kit=\"hint\">{hint}</FieldDescription>}\n    </Field>\n  )\n}\n\nexport { Slider }\n",
      "type": "registry:ui",
      "target": "@ui/slider.tsx"
    },
    {
      "path": "registry/cyber/ui/cyber/slider.css",
      "content": "@layer ui-sdk, cyber.tokens, cyber.base, cyber.ui, cyber.blocks, cyber.fx, cyber.a11y;\n\n@layer cyber.ui {\n  [data-skin=\"cyber\"] [data-kit=\"slider\"] {\n    --thumb-w: 12px;\n    --thumb-h: 20px;\n\n    display: grid;\n    width: 100%;\n    min-width: 0;\n  }\n\n  /* The label, and the reading at the far end of the same line. */\n  [data-skin=\"cyber\"] [data-kit=\"slider-head\"] {\n    display: flex;\n    align-items: baseline;\n    justify-content: space-between;\n    gap: 12px;\n    min-width: 0;\n  }\n\n  /* What it reads, in the signal color like every value. */\n  [data-skin=\"cyber\"] [data-kit=\"slider-value\"] {\n    flex: none;\n    font-family: var(--cy-mono);\n    font-size: var(--cy-text-sm);\n    font-variant-numeric: tabular-nums;\n    line-height: 1;\n    color: var(--cy-signal);\n\n    &[data-disabled] {\n      color: var(--cy-ink-mute);\n    }\n  }\n\n  /* Where presses land: as tall as any control, with the rail near its foot\n     and the scale ruled above the rail. The thumb's centre runs from one end\n     of the rail to the other, so the rail is inset by half a thumb. */\n  [data-skin=\"cyber\"] [data-kit=\"slider-control\"] {\n    display: grid;\n    align-items: end;\n    height: var(--cy-h);\n    padding-block-end: calc(var(--thumb-h) / 2);\n    padding-inline: calc(var(--thumb-w) / 2);\n    cursor: pointer;\n\n    &[data-dragging] {\n      cursor: grabbing;\n    }\n\n    &[data-disabled] {\n      cursor: not-allowed;\n    }\n  }\n\n  /* The rail: a hairline, which the filled part thickens. It's a size\n     container so the lit scale inside the indicator can be as wide as the\n     whole rail, however little of it shows. */\n  [data-skin=\"cyber\"] [data-kit=\"slider-track\"] {\n    container-type: inline-size;\n    height: 3px;\n    background: linear-gradient(var(--cy-line-ctl), var(--cy-line-ctl)) 0 50% / 100% 1px no-repeat;\n\n    &[data-disabled] {\n      background-image: linear-gradient(var(--cy-line-deco), var(--cy-line-deco));\n    }\n  }\n\n  /* The scale: a mark per division, spaced edge to edge, with every fifth\n     one taller. */\n  [data-skin=\"cyber\"] [data-kit=\"slider-scale\"] {\n    position: absolute;\n    inset: auto 0 calc(100% + 4px);\n    display: flex;\n    align-items: flex-end;\n    justify-content: space-between;\n    height: 8px;\n    pointer-events: none;\n\n    & > span {\n      flex: none;\n      width: 1px;\n      height: 4px;\n      background: var(--cy-line-deco);\n\n      &:nth-child(5n + 1) {\n        height: 8px;\n        background: var(--cy-line-ctl);\n      }\n    }\n\n    /* The lit copy is laid over the first one, mark for mark: as wide as the\n       rail, and shifted back by however far along the indicator starts. */\n    &[data-lit] {\n      inset-inline: 0 auto;\n      width: 100cqw;\n      translate: calc(var(--slider-indicator-start, 0%) * -1) 0;\n\n      & > span,\n      & > span:nth-child(5n + 1) {\n        background: var(--cy-line-hot);\n      }\n\n      :dir(rtl) & {\n        translate: var(--slider-indicator-start, 0%) 0;\n      }\n    }\n\n    [data-disabled] > & > span,\n    [data-disabled] > & > span:nth-child(5n + 1) {\n      background: var(--cy-line-deco);\n    }\n  }\n\n  /* The filled part. It clips the lit scale to its own width, and lets it\n     stand above the rail. */\n  [data-skin=\"cyber\"] [data-kit=\"slider-indicator\"] {\n    background: var(--cy-accent);\n    clip-path: inset(-16px 0);\n\n    &[data-disabled] {\n      background: var(--cy-line-ctl);\n    }\n  }\n\n  /* The thumb. The block is drawn on a pseudo-element, so its cut corner\n     doesn't clip the focus ring, which belongs to the thumb itself: focus is\n     on the range input inside it. */\n  [data-skin=\"cyber\"] [data-kit=\"slider-thumb\"] {\n    width: var(--thumb-w);\n    height: var(--thumb-h);\n    cursor: grab;\n\n    &::before {\n      content: \"\";\n      position: absolute;\n      inset: 0;\n      background: var(--cy-ink-hi);\n      clip-path: polygon(0 0, 100% 0, 100% calc(100% - 4px), calc(100% - 4px) 100%, 0 100%);\n      transition: background-color var(--cy-t-fast) linear;\n    }\n\n    @media (hover: hover) {\n      /* Not while another thumb of a range is the one being dragged. */\n      [data-kit=\"slider-control\"]:hover:not([data-dragging]) > * > &:not([data-disabled])::before {\n        background: var(--cy-signal);\n      }\n    }\n\n    &[data-dragging] {\n      cursor: grabbing;\n\n      &::before {\n        background: var(--cy-signal);\n      }\n    }\n\n    &:has(:focus-visible) {\n      outline: 2px solid var(--cy-signal);\n      outline-offset: 2px;\n    }\n\n    /* Unavailable: hollow and hatched, not just dimmer. */\n    &[data-disabled] {\n      cursor: not-allowed;\n\n      &::before {\n        background:\n          repeating-linear-gradient(135deg, transparent 0 3px, var(--cy-line-ctl) 3px 4px),\n          var(--cy-panel);\n        box-shadow: inset 0 0 0 1px var(--cy-line-ctl);\n      }\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/cyber/slider.css"
    }
  ],
  "type": "registry:ui"
}
