{"version":3,"sources":["../../../../src/sensors/useFocusWithin/core.ts"],"sourcesContent":["import { observable, type Observable } from \"@legendapp/state\";\nimport { get } from \"@usels/core\";\nimport type { MaybeEventTarget } from \"../../types\";\nimport { createEventListener } from \"../../browser/useEventListener/core\";\n\nexport interface UseFocusWithinReturn {\n  /** Whether focus is within the container or any descendants (read-only) */\n  focused$: Observable<boolean>;\n}\n\n/**\n * Framework-agnostic tracker for whether focus is within a target element or\n * any of its descendants.\n *\n * Uses `focusin`/`focusout` events with `el.matches(':focus-within')` to\n * reliably detect focus state. This approach delegates the check to the\n * browser's CSS engine, correctly handling edge cases like iframes and\n * Shadow DOM boundaries where `relatedTarget` would be `null`.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function createFocusWithin(target: MaybeEventTarget): UseFocusWithinReturn {\n  const focused$ = observable<boolean>(false);\n\n  createEventListener(target, \"focusin\", () => {\n    focused$.set(true);\n  });\n\n  createEventListener(target, \"focusout\", () => {\n    const el = get(target) as HTMLElement | null;\n    if (!el) return;\n    focused$.set(el.matches(\":focus-within\"));\n  });\n\n  return { focused$ };\n}\n"],"mappings":"AAAA,SAAS,kBAAmC;AAC5C,SAAS,WAAW;AAEpB,SAAS,2BAA2B;AAAA;AAiB7B,SAAS,kBAAkB,QAAgD;AAChF,QAAM,WAAW,WAAoB,KAAK;AAE1C,sBAAoB,QAAQ,WAAW,MAAM;AAC3C,aAAS,IAAI,IAAI;AAAA,EACnB,CAAC;AAED,sBAAoB,QAAQ,YAAY,MAAM;AAC5C,UAAM,KAAK,IAAI,MAAM;AACrB,QAAI,CAAC,GAAI;AACT,aAAS,IAAI,GAAG,QAAQ,eAAe,CAAC;AAAA,EAC1C,CAAC;AAED,SAAO,EAAE,SAAS;AACpB;","names":[]}