{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shared-navigate",
  "type": "registry:lib",
  "title": "shared/navigate",
  "description": "Internal module shared by the ui-* components (navigate). 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": [
    "lit@^3.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/shared-events",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/shared/navigate.ts",
      "type": "registry:lib",
      "target": "components/ui/primitives/shared/navigate.ts",
      "content": "import type { NavigateDetail } from './events.ts';\n\nfunction isModified(event: MouseEvent) {\n    return event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;\n}\n\n/**\n * Click listener for an `<a>` a component renders in its shadow root (bind it with `@click`;\n * Lit calls it with the host as `this`). Client-side routers can't route those anchors by\n * themselves, so a plain click — main button, no modifier key, same tab, not a download, same\n * origin — first fires a cancelable, bubbling, composed `ui-navigate` { href } from the host.\n * `preventDefault()` on it stops the page load and leaves the navigation to the router.\n * Every other click (Ctrl / ⌘ / Shift / middle, `target=\"_blank\"`, other sites) stays a plain link.\n */\nexport function followLink(this: HTMLElement, event: MouseEvent) {\n    const a = event.currentTarget as HTMLAnchorElement;\n    const href = a.getAttribute('href');\n    if (event.defaultPrevented || isModified(event) || href === null || a.hasAttribute('download')) return;\n    if ((a.target && a.target !== '_self') || a.origin !== location.origin) return;\n    const navigate = new CustomEvent<NavigateDetail>('ui-navigate', { detail: { href }, bubbles: true, composed: true, cancelable: true });\n    if (!this.dispatchEvent(navigate)) event.preventDefault();\n}\n\n/**\n * A same-page link (`#id`) inside shadow roots (a micro app): the browser looks the id up in the\n * document only. When it isn't there, find it in the trees the link sits in and move focus to it\n * (made focusable with tabindex=\"-1\" first, as skip-link targets are). Returns whether it did, so\n * the caller prevents the click's default.\n */\nexport function focusFragmentTarget(link: Element, href: string): boolean {\n    if (!href.startsWith('#') || href.length < 2) return false;\n    const id = decodeURIComponent(href.slice(1));\n    if (document.getElementById(id)) return false; // the browser finds it\n    for (let tree = link.getRootNode(); tree instanceof ShadowRoot; tree = tree.host.getRootNode()) {\n        const target = tree.getElementById(id);\n        if (!(target instanceof HTMLElement)) continue;\n        if (!target.hasAttribute('tabindex')) target.tabIndex = -1;\n        target.focus();\n        return true;\n    }\n    return false;\n}\n"
    }
  ]
}
