{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "track",
  "title": "Track",
  "description": "The thin track and fill that Slider, Progress and Meter share, with the label and value above them, so a value reads the same way in all three.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/number-format.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/lib/track.ts",
      "content": "import { numberFormatter } from '@/registry/lib/number-format'\nimport type { CSSProperties } from 'react'\n\n/**\n * The thin track that Slider, Progress and Meter share, and the parts around\n * it, so a value reads the same way in all three: the column, the row of\n * label and value above the track, the track and its fill. Each adds how its\n * fill moves: the Slider clips it between its thumbs, Progress and Meter\n * slide it in from the start.\n */\n\n/** Where `value` sits between `min` and `max`, from 0 to 100; 0 when it is unknown. */\nexport function valuePercent(value: number | null, min: number, max: number) {\n  if (value === null || !Number.isFinite(value) || max <= min) return 0\n  return Math.min(100, Math.max(0, ((value - min) / (max - min)) * 100))\n}\n\n/** `--track-dir`: 1, or -1 right to left, for what moves along a track or across an area. */\nexport const trackDirClassName = '[--track-dir:1] rtl:[--track-dir:-1]'\n\n/** The column the header and track sit in, with `--track-dir` for what moves along it. */\nexport const trackRootClassName = `flex w-full min-w-0 flex-col gap-2 ${trackDirClassName}`\n\n/** The row above the track: the label, then the value at its end. */\nexport const trackHeaderClassName = 'flex min-w-0 items-baseline gap-3 text-sm'\n\n/** The label: a long one wraps, so the whole of it shows. */\nexport const trackLabelClassName = 'min-w-0 flex-1 font-medium wrap-break-word'\n\n/**\n * In forced colours the muted background goes, so an outline keeps the\n * track's length visible. An outline takes no room, so the fill keeps its place.\n */\nexport const trackClassName =\n  'bg-muted relative h-1.5 w-full rounded-full forced-colors:outline'\n\n/**\n * A thumb's dot, inside a thumb marked `group/thumb`: the Slider's, and the\n * Color picker's. Held or dragged (`data-dragging`), it shrinks by three\n * times the feel's press scale, as a Checkbox does; hovered, or focused\n * itself or inside, it takes a ring. Each gives it its own look.\n */\nexport const thumbDotClassName =\n  'block rounded-full border-2 transition-[box-shadow,scale] duration-(--motion-press-duration) ease-[var(--motion-press-fade-easing),var(--motion-press-easing)] group-active/thumb:duration-[calc(var(--motion-press-duration)*0.4)] motion-safe:group-active/thumb:scale-[calc(1_-_(1_-_var(--motion-press-scale))_*_3)] motion-safe:group-data-dragging/thumb:scale-[calc(1_-_(1_-_var(--motion-press-scale))_*_3)] group-hover/thumb:ring-ring/30 group-hover/thumb:ring-4 group-has-focus-visible/thumb:ring-ring/50 group-has-focus-visible/thumb:ring-4 forced-colors:group-has-focus-visible/thumb:outline-2 forced-colors:group-has-focus-visible/thumb:outline-[Highlight] group-focus-visible/thumb:ring-ring/50 group-focus-visible/thumb:ring-4 forced-colors:group-focus-visible/thumb:outline-2 forced-colors:group-focus-visible/thumb:outline-[Highlight]'\n\n/** In forced colours the fill takes the system highlight whatever colour a state gives it, since backgrounds go. */\nexport const trackFillClassName =\n  'bg-primary absolute inset-y-0 rounded-full forced-colors:bg-[Highlight]!'\n\n/**\n * A fill as wide as the track that slides in from the start, so it draws on\n * the compositor and its end stays round. Its track clips it.\n */\nexport const slidingFillClassName =\n  'bg-primary absolute inset-y-0 w-full! rounded-full transition-[background-color,translate] duration-(--motion-draw-duration) ease-[var(--motion-draw-fade-easing),var(--motion-draw-easing)] motion-reduce:transition-[background-color] motion-reduce:ease-(--motion-draw-fade-easing) forced-colors:bg-[Highlight]!'\n\n/**\n * Places a sliding fill at `percent`. ui-sdk sizes its indicator with an\n * inline `width`, which motion.md won't let us animate, so the fill's class\n * keeps it as wide as the track and this moves it into place.\n */\nexport function slidingFillStyle(percent: number): CSSProperties {\n  return {\n    insetInlineStart: 0,\n    translate: `calc(var(--track-dir) * ${percent - 100}%) 0`,\n  }\n}\n\n/**\n * A mark that glides along a track to its place, such as a target's notch or\n * a score's marker: a layer as wide as the track, placed with\n * `slidingFillStyle` so its end is at the value, with the mark at that end.\n * It moves on the `layout` role, since a mark changes place rather than draws.\n */\nexport const slidingMarkClassName =\n  'pointer-events-none absolute inset-0 flex justify-end transition-[translate] duration-(--motion-layout-duration) ease-(--motion-layout-easing) motion-reduce:transition-none'\n\n/**\n * How a Meter or Progress writes its value, for its `format`: with `format`'s\n * options, or where it sits between `min` and `max` as a percentage without\n * them or with a percent style, as ui-sdk does, through `numberFormatter`.\n */\nexport function gaugeText(\n  value: number,\n  {\n    min,\n    max,\n    locale,\n    format,\n  }: {\n    min: number\n    max: number\n    locale?: Intl.LocalesArgument\n    format?: Intl.NumberFormatOptions\n  },\n) {\n  if (format && format.style !== 'percent')\n    return numberFormatter(locale, format).format(value)\n  return numberFormatter(locale, format ?? { style: 'percent' }).format(\n    valuePercent(value, min, max) / 100,\n  )\n}\n",
      "type": "registry:lib",
      "target": "@lib/track.ts"
    }
  ],
  "type": "registry:lib"
}