{"version":3,"sources":["../src/components/Dialog/utils/scroll.ts"],"sourcesContent":["type ScrollLockState = {\n  lockCount: number;\n  previousBodyOverflow: string;\n};\n\nconst scrollLockStateByDocument = new WeakMap<Document, ScrollLockState>();\n\n/**\n * Prevents background scrolling while a modal/alert dialog is open by applying\n * `overflow: hidden` to `<body>`. The `<html>` element is intentionally left\n * untouched so host-application styles on the document element are preserved.\n *\n * Nested modal dialogs share a single lock via a reference count.\n */\nexport function lockDocumentScroll(targetDocument: Document): void {\n  const previous = scrollLockStateByDocument.get(targetDocument);\n  if (previous) {\n    previous.lockCount += 1;\n    return;\n  }\n\n  scrollLockStateByDocument.set(targetDocument, {\n    lockCount: 1,\n    previousBodyOverflow: targetDocument.body.style.overflow,\n  });\n\n  targetDocument.body.style.overflow = 'visible clip';\n}\n\n/**\n * Restores the document's scroll behavior by reverting the `overflow` style\n * on the `<body>` element to its previous value. This function is typically\n * called when a modal/alert dialog is closed.\n */\nexport function unlockDocumentScroll(targetDocument: Document): void {\n  const state = scrollLockStateByDocument.get(targetDocument);\n  if (!state) {\n    return;\n  }\n\n  state.lockCount -= 1;\n  if (state.lockCount > 0) {\n    return;\n  }\n\n  targetDocument.body.style.overflow = state.previousBodyOverflow;\n  scrollLockStateByDocument.delete(targetDocument);\n}\n"],"names":["lockDocumentScroll","unlockDocumentScroll","scrollLockStateByDocument","WeakMap","targetDocument","previous","get","lockCount","set","previousBodyOverflow","body","style","overflow","state","delete"],"mappings":";;;;;;;;;;;IAcgBA,kBAAkB;eAAlBA;;IAoBAC,oBAAoB;eAApBA;;;AA7BhB,MAAMC,4BAA4B,IAAIC;AAS/B,SAASH,mBAAmBI,cAAwB;IACzD,MAAMC,WAAWH,0BAA0BI,GAAG,CAACF;IAC/C,IAAIC,UAAU;QACZA,SAASE,SAAS,IAAI;QACtB;IACF;IAEAL,0BAA0BM,GAAG,CAACJ,gBAAgB;QAC5CG,WAAW;QACXE,sBAAsBL,eAAeM,IAAI,CAACC,KAAK,CAACC,QAAQ;IAC1D;IAEAR,eAAeM,IAAI,CAACC,KAAK,CAACC,QAAQ,GAAG;AACvC;AAOO,SAASX,qBAAqBG,cAAwB;IAC3D,MAAMS,QAAQX,0BAA0BI,GAAG,CAACF;IAC5C,IAAI,CAACS,OAAO;QACV;IACF;IAEAA,MAAMN,SAAS,IAAI;IACnB,IAAIM,MAAMN,SAAS,GAAG,GAAG;QACvB;IACF;IAEAH,eAAeM,IAAI,CAACC,KAAK,CAACC,QAAQ,GAAGC,MAAMJ,oBAAoB;IAC/DP,0BAA0BY,MAAM,CAACV;AACnC"}