{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shared-quiet-focus",
  "type": "registry:lib",
  "title": "shared/quiet-focus",
  "description": "Internal module shared by the ui-* components (quiet-focus). 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/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/shared/quiet-focus.ts",
      "type": "registry:lib",
      "target": "components/ui/primitives/shared/quiet-focus.ts",
      "content": "/**\n * Focus a component moves itself right after a mouse or touch press (a dialog opening on a click, its calendar on a\n * tap) matches :focus-visible in Chrome, as a dialog's first focus always does, so it shows a keyboard ring the user\n * never asked for. `focusQuietly` / `markQuiet` mark the element `data-quiet-focus` when the last press was a pointer's,\n * until focus leaves it or a key is pressed; a design that rings keyboard focus only (Kanok, `--ui-pointer-focus`)\n * shows no ring on it then. Carbon: no setting, so the ring stays.\n */\nlet lastPress: 'pointer' | 'key' = 'key';\nconst marked = new Set<Element>();\n\nfunction unmark(el: Element) {\n    el.removeAttribute('data-quiet-focus');\n    marked.delete(el);\n}\n\nif (typeof document !== 'undefined') {\n    document.addEventListener('pointerdown', () => (lastPress = 'pointer'), true);\n    document.addEventListener(\n        'keydown',\n        () => {\n            lastPress = 'key';\n            for (const el of [...marked]) unmark(el); // the keyboard is in use: every ring shows again\n        },\n        true,\n    );\n}\n\n/** Marks `el` quiet if the last press was a pointer's (it then shows no ring in Kanok) until focus leaves it. */\nexport function markQuiet(el: Element | null | undefined) {\n    if (!el || lastPress !== 'pointer' || marked.has(el)) return;\n    el.setAttribute('data-quiet-focus', '');\n    marked.add(el);\n    const off = (event: Event) => {\n        if (el.contains((event as FocusEvent).relatedTarget as Node | null)) return;\n        unmark(el);\n        el.removeEventListener('focusout', off);\n    };\n    el.addEventListener('focusout', off);\n}\n\n/** `el.focus()`, marked quiet after a pointer press (see markQuiet). */\nexport function focusQuietly(el: HTMLElement | null | undefined, options?: FocusOptions) {\n    if (!el) return;\n    markQuiet(el);\n    el.focus(options);\n}\n"
    }
  ]
}
