{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "elements-range",
  "type": "registry:component",
  "title": "Elements Range",
  "description": "Range normalization for the elements family: clamping a caller's counts, indexes, and shares to what the element can render.",
  "files": [
    {
      "type": "registry:lib",
      "path": "components/elements/range.ts",
      "content": "/**\n * Range normalization for the numeric props the elements take.\n *\n * Elements are driven by a caller's state, so a prop can arrive negative, past\n * the end of its collection, or NaN. Left raw, those reach the DOM: a negative\n * percentage is an invalid CSS width that the browser drops, leaving a bar at\n * its natural full width, and a negative slice length counts from the end of\n * the array instead of returning nothing.\n */\n\n/**\n * Constrains a value to `min…max`. NaN is decided first and maps to `min`.\n * For any other value, an empty collection can invert the bounds and `max`\n * wins there: `clamp(3, 1, 0)` is `0`, which is what lets a floor of one item\n * still yield none.\n */\nexport function clamp(value: number, min: number, max: number) {\n  if (Number.isNaN(value)) return min;\n  return Math.min(max, Math.max(min, value));\n}\n\n/** The first `count` items, for a `count` that may be out of range. */\nexport function take<T>(items: readonly T[], count: number) {\n  return items.slice(0, Math.floor(clamp(count, 0, items.length)));\n}\n\n/** The position `index` names in `items`, for an `index` out of range. */\nexport function indexIn<T>(items: readonly T[], index: number) {\n  return Math.floor(clamp(index, 0, Math.max(0, items.length - 1)));\n}\n\n/** The item at `index`, for an `index` that may be out of range. */\nexport function at<T>(items: readonly T[], index: number) {\n  if (items.length === 0) return undefined;\n  return items[indexIn(items, index)];\n}\n\n/** `value` as a share of `total`, as a percentage in `0…100`. */\nexport function pct(value: number, total: number) {\n  if (!(total > 0)) return 0;\n  return clamp((value / total) * 100, 0, 100);\n}\n\n/** A count of completed items out of `total`, in `0…total`. */\nexport function progressOf(index: number, total: number) {\n  if (!(total > 0)) return 0;\n  return Math.floor(clamp(index, 0, total));\n}\n"
    }
  ]
}