{"version":3,"file":"overlay.cjs","names":[],"sources":["../../src/core/overlay.ts"],"sourcesContent":["/**\n * Why an overlay was opened.\n * - `'click'`       — user clicked the trigger element\n * - `'focus'`       — focus entered the trigger (tooltip, popover)\n * - `'hover'`       — pointer entered the trigger (tooltip)\n * - `'keyboard'`    — keyboard shortcut or Enter/Space on a trigger\n * - `'programmatic'` — opened via the JS API without a user gesture\n * - `'trigger'`     — opened via the Invoker Commands API (`command=\"show-modal\"`)\n */\nexport type OverlayOpenReason = 'click' | 'focus' | 'hover' | 'keyboard' | 'programmatic' | 'trigger';\n\n/** Close reasons valid for modal dialogs (includes 'swipe' for drawer). */\nexport type DialogCloseReason = 'escape' | 'outsideClick' | 'programmatic' | 'swipe' | 'trigger';\n/** Close reasons valid for dropdown overlays (no swipe). */\nexport type DropdownCloseReason = Exclude<DialogCloseReason, 'swipe'> | 'select';\n\n/** Detail shape for overlay open events emitted by components. */\nexport type OverlayOpenDetail = { reason: OverlayOpenReason };\n/** Detail shape for overlay close events emitted by components. */\nexport type OverlayCloseDetail = { reason: DialogCloseReason };\n/** Detail shape for state changes emitted by overlay components. */\nexport type OverlayOpenChangeDetail = {\n  open: boolean;\n  reason: DialogCloseReason | DropdownCloseReason | OverlayOpenReason;\n};\n\nexport type OutsidePointerDismissalOptions = {\n  getTargets: () => Array<Element | null | undefined>;\n  isActive: () => boolean;\n  onDismiss: () => void;\n  signal: AbortSignal;\n};\n\n/**\n * Dismisses an active floating surface when a pointer begins outside all of its\n * supplied boundary elements. Components retain ownership of their open state.\n */\nexport const createOutsidePointerDismissal = (options: OutsidePointerDismissalOptions): (() => void) => {\n  const onPointerDown = (event: PointerEvent): void => {\n    if (!options.isActive()) return;\n\n    const path = event.composedPath();\n    const target = path[0] instanceof Node ? path[0] : event.target instanceof Node ? event.target : null;\n    const inside = options.getTargets().some((element) => {\n      return (\n        element !== null &&\n        element !== undefined &&\n        (path.includes(element) || Boolean(target && element.contains(target)))\n      );\n    });\n\n    if (!inside) options.onDismiss();\n  };\n\n  const dispose = (): void => {\n    document.removeEventListener('pointerdown', onPointerDown, { capture: true });\n  };\n\n  document.addEventListener('pointerdown', onPointerDown, { capture: true });\n  options.signal.addEventListener('abort', dispose, { once: true });\n\n  return dispose;\n};\n"],"mappings":"AAqCA,IAAa,EAAiC,GAA0D,CACtG,IAAM,EAAiB,GAA8B,CACnD,GAAI,CAAC,EAAQ,SAAS,EAAG,OAEzB,IAAM,EAAO,EAAM,aAAa,EAC1B,EAAS,EAAK,aAAc,KAAO,EAAK,GAAK,EAAM,kBAAkB,KAAO,EAAM,OAAS,KAClF,EAAQ,WAAW,CAAC,CAAC,KAAM,GAEtC,GAAY,OAEX,EAAK,SAAS,CAAO,GAAK,GAAQ,GAAU,EAAQ,SAAS,CAAM,GAInE,GAAQ,EAAQ,UAAU,CACjC,EAEM,MAAsB,CAC1B,SAAS,oBAAoB,cAAe,EAAe,CAAE,QAAS,EAAK,CAAC,CAC9E,EAKA,OAHA,SAAS,iBAAiB,cAAe,EAAe,CAAE,QAAS,EAAK,CAAC,EACzE,EAAQ,OAAO,iBAAiB,QAAS,EAAS,CAAE,KAAM,EAAK,CAAC,EAEzD,CACT"}