{"version":3,"sources":["../src/hooks/usePositioning/usePlacementObserver.ts"],"sourcesContent":["'use client';\n\nimport { useIsomorphicLayoutEffect, useEventCallback } from '@fluentui/react-utilities';\nimport { computePosition, debounce } from './utils';\n\n/**\n * Mirrors the placement that the browser actually resolves for an\n * anchored element into its `data-placement` attribute. Useful when CSS\n * `position-try-fallbacks` flips the surface after a layout shift, scroll,\n * or content reflow — consumers can style the surface (arrows, animations)\n * via `[data-placement^=\"above\"]` and friends and stay in sync.\n *\n */\nexport function usePlacementObserver(\n  containerEl: HTMLElement | null,\n  targetEl: HTMLElement | null,\n  targetDocument: Document | undefined,\n  disabled = false,\n): () => void {\n  const update = useEventCallback(() => {\n    if (!containerEl || !targetEl) {\n      return;\n    }\n\n    const result = computePosition(targetEl, containerEl);\n    if (!result) {\n      return;\n    }\n\n    if (containerEl.getAttribute('data-placement') !== result.placement) {\n      containerEl.setAttribute('data-placement', result.placement);\n    }\n  });\n\n  useIsomorphicLayoutEffect(() => {\n    if (disabled || !containerEl || !targetEl) {\n      return;\n    }\n\n    const win = targetDocument?.defaultView;\n    if (!win) {\n      return;\n    }\n\n    const debouncedUpdate = debounce(update);\n\n    const ResizeObserverCtor = win.ResizeObserver;\n    const resizeObserver = ResizeObserverCtor\n      ? new ResizeObserverCtor(entries => {\n          const allLaidOut = entries.every(entry => entry.contentRect.width > 0 && entry.contentRect.height > 0);\n          if (allLaidOut) {\n            debouncedUpdate();\n          }\n        })\n      : null;\n\n    resizeObserver?.observe(containerEl);\n    resizeObserver?.observe(targetEl);\n\n    win.addEventListener('scroll', debouncedUpdate, { capture: true, passive: true });\n    win.addEventListener('resize', debouncedUpdate);\n\n    debouncedUpdate();\n\n    return () => {\n      resizeObserver?.disconnect();\n      win.removeEventListener('scroll', debouncedUpdate, { capture: true });\n      win.removeEventListener('resize', debouncedUpdate);\n    };\n  }, [containerEl, targetEl, targetDocument, disabled, update]);\n\n  return update;\n}\n"],"names":["usePlacementObserver","containerEl","targetEl","targetDocument","disabled","update","useEventCallback","result","computePosition","getAttribute","placement","setAttribute","useIsomorphicLayoutEffect","win","defaultView","debouncedUpdate","debounce","ResizeObserverCtor","ResizeObserver","resizeObserver","entries","allLaidOut","every","entry","contentRect","width","height","observe","addEventListener","capture","passive","disconnect","removeEventListener"],"mappings":"AAAA;;;;;+BAagBA;;;eAAAA;;;gCAX4C;uBAClB;AAUnC,SAASA,qBACdC,WAA+B,EAC/BC,QAA4B,EAC5BC,cAAoC,EACpCC,WAAW,KAAK;IAEhB,MAAMC,SAASC,IAAAA,gCAAgB,EAAC;QAC9B,IAAI,CAACL,eAAe,CAACC,UAAU;YAC7B;QACF;QAEA,MAAMK,SAASC,IAAAA,sBAAe,EAACN,UAAUD;QACzC,IAAI,CAACM,QAAQ;YACX;QACF;QAEA,IAAIN,YAAYQ,YAAY,CAAC,sBAAsBF,OAAOG,SAAS,EAAE;YACnET,YAAYU,YAAY,CAAC,kBAAkBJ,OAAOG,SAAS;QAC7D;IACF;IAEAE,IAAAA,yCAAyB,EAAC;QACxB,IAAIR,YAAY,CAACH,eAAe,CAACC,UAAU;YACzC;QACF;QAEA,MAAMW,MAAMV,gBAAgBW;QAC5B,IAAI,CAACD,KAAK;YACR;QACF;QAEA,MAAME,kBAAkBC,IAAAA,eAAQ,EAACX;QAEjC,MAAMY,qBAAqBJ,IAAIK,cAAc;QAC7C,MAAMC,iBAAiBF,qBACnB,IAAIA,mBAAmBG,CAAAA;YACrB,MAAMC,aAAaD,QAAQE,KAAK,CAACC,CAAAA,QAASA,MAAMC,WAAW,CAACC,KAAK,GAAG,KAAKF,MAAMC,WAAW,CAACE,MAAM,GAAG;YACpG,IAAIL,YAAY;gBACdN;YACF;QACF,KACA;QAEJI,gBAAgBQ,QAAQ1B;QACxBkB,gBAAgBQ,QAAQzB;QAExBW,IAAIe,gBAAgB,CAAC,UAAUb,iBAAiB;YAAEc,SAAS;YAAMC,SAAS;QAAK;QAC/EjB,IAAIe,gBAAgB,CAAC,UAAUb;QAE/BA;QAEA,OAAO;YACLI,gBAAgBY;YAChBlB,IAAImB,mBAAmB,CAAC,UAAUjB,iBAAiB;gBAAEc,SAAS;YAAK;YACnEhB,IAAImB,mBAAmB,CAAC,UAAUjB;QACpC;IACF,GAAG;QAACd;QAAaC;QAAUC;QAAgBC;QAAUC;KAAO;IAE5D,OAAOA;AACT"}