{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "core-roving",
  "type": "registry:lib",
  "title": "core/roving",
  "description": "Framework-free behaviour shared by the ui-* components (roving); 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/roving.ts",
      "type": "registry:lib",
      "target": "components/ui/core/roving.ts",
      "content": "/**\n * APG roving focus over a set of items (tabs, content switcher, radio group, menu): which item an\n * arrow / Home / End key moves to. Works on positions only; pass the items that can take focus\n * (the enabled ones).\n */\n\n/**\n * `horizontal`: ←/→ (mirrored right-to-left); `vertical`: ↑/↓; `both`: ↓/→ next, ↑/← previous (radio groups, any\n * direction; ← and → mirrored right-to-left, as native radios).\n */\nexport type RovingOrientation = 'horizontal' | 'vertical' | 'both';\n\nexport interface RovingOptions {\n    orientation?: RovingOrientation;\n    /** Right-to-left text: ← moves forward in a horizontal set. */\n    rtl?: boolean;\n    /** Home / End jump to the first / last item (APG tabs, menus); radio groups leave them alone. */\n    homeEnd?: boolean;\n}\n\nfunction stepFor(key: string, { orientation = 'horizontal', rtl = false }: RovingOptions): number | undefined {\n    if (orientation === 'vertical') return { ArrowDown: 1, ArrowUp: -1 }[key];\n    if (orientation === 'both') return { ArrowDown: 1, ArrowRight: rtl ? -1 : 1, ArrowUp: -1, ArrowLeft: rtl ? 1 : -1 }[key];\n    return { ArrowRight: rtl ? -1 : 1, ArrowLeft: rtl ? 1 : -1 }[key];\n}\n\n/**\n * The index `key` moves focus to among `count` items from `current` — arrows wrap around the\n * ends; with `current` < 0 (focus on none of them) forward goes to the first, backward to the\n * last. Undefined for keys that don't move focus (and for an empty set).\n */\nexport function rovingTarget(count: number, current: number, key: string, options: RovingOptions = {}): number | undefined {\n    if (count === 0) return undefined;\n    if (options.homeEnd ?? true) {\n        if (key === 'Home') return 0;\n        if (key === 'End') return count - 1;\n    }\n    const step = stepFor(key, options);\n    if (step === undefined) return undefined;\n    if (current < 0) return step > 0 ? 0 : count - 1;\n    return (current + step + count) % count;\n}\n"
    }
  ]
}
