{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-dom",
  "type": "registry:lib",
  "title": "react-tw/lib/dom",
  "description": "react-tw/lib/dom 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": [
    "@purpurabog/ui@^2.3.0"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/react-tw/lib/dom.ts",
      "type": "registry:lib",
      "target": "components/ui/react-tw/lib/dom.ts",
      "content": "/**\n * Lookups that respect the tree a component lives in. A micro app may mount React inside a shadow root:\n * there `document.activeElement` is only the shadow host and `document.getElementById` can't see in, so\n * components ask the root of their own node (the document, or that shadow root) instead.\n */\ntype Scope = Document | ShadowRoot;\n\nconst scopeOf = (node: Node | null | undefined): Scope => {\n    const root = node?.getRootNode();\n    return root instanceof ShadowRoot || root instanceof Document ? root : document;\n};\n\n/** The focused element in `node`'s tree (null when nothing in it has focus). */\nexport const activeElementOf = (node: Node | null | undefined) => scopeOf(node).activeElement as HTMLElement | null;\n\n/** An element with this id in `node`'s tree. */\nexport const elementByIdIn = (node: Node | null | undefined, id: string) => scopeOf(node).getElementById(id);\n\nconst TAB_STOP =\n    'input:not([disabled]):not([type=\"hidden\"]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), a[href], [tabindex]:not([tabindex=\"-1\"]), [contenteditable=\"true\"]';\n\n/** Tab stops inside `root` in order: native controls, and custom elements that delegate focus (a Lit field) as one stop. */\nexport function tabStops(root: Element): HTMLElement[] {\n    const stops: HTMLElement[] = [];\n    const walk = (el: Element) => {\n        for (const child of el.children) {\n            if (!(child instanceof HTMLElement) || child.hidden || child.inert) continue;\n            if (child.matches(TAB_STOP)) stops.push(child);\n            else if (child.shadowRoot?.delegatesFocus && !child.hasAttribute('disabled')) stops.push(child);\n            else walk(child);\n        }\n    };\n    walk(root);\n    return stops;\n}\n\n/** Whether focus is on `container` or inside it. */\nexport const hasFocusWithin = (container: Element | null | undefined) => !!container?.contains(activeElementOf(container));\n\n/** copyToClipboard lives in the headless layer (its Copy needs it too); re-exported for the styled components. */\nexport { copyToClipboard } from '@purpurabog/ui/headless';\n\n/** An element's width with every flex item at its natural size (shrinking off for the moment): what an overflow handler measures. */\nexport function naturalWidth(el: HTMLElement) {\n    const shrink = el.style.flexShrink;\n    el.style.flexShrink = '0';\n    const width = el.getBoundingClientRect().width;\n    el.style.flexShrink = shrink;\n    return width;\n}\n\n/** Show every one of `nodes` (drop `data-hidden`) to measure them; the returned function puts back what was hidden. */\nexport function revealForMeasure(nodes: readonly HTMLElement[]) {\n    const hidden = nodes.filter((node) => 'hidden' in node.dataset);\n    for (const node of hidden) delete node.dataset.hidden;\n    return () => {\n        for (const node of hidden) node.dataset.hidden = '';\n    };\n}\n"
    }
  ]
}
