{"version":3,"file":"disableBodyScrollLock.mjs","names":[],"sources":["../../../src/utils/disableBodyScrollLock/disableBodyScrollLock.ts"],"sourcesContent":["import { isServer } from '../isServer/index.ts';\n\n/**\n * Data attribute key for storing scroll position\n */\nconst SCROLL_POSITION_ATTR = 'data-simplikit-scroll-y';\n\n/**\n * @description\n * `disableBodyScrollLock` is a utility function that unlocks the body scroll.\n * It restores the scroll locked by `enableBodyScrollLock` and returns to the saved scroll position.\n *\n * Safe to call in SSR environment (no-op on server).\n * Safe to call even if not locked (no-op).\n *\n * @returns {void}\n *\n * @example\n * // When modal opens\n * enableBodyScrollLock();\n *\n * // When modal closes\n * disableBodyScrollLock();\n */\nexport function disableBodyScrollLock(): void {\n  if (isServer()) {\n    return;\n  }\n\n  const savedScrollY = document.body.getAttribute(SCROLL_POSITION_ATTR);\n\n  if (savedScrollY == null) {\n    return;\n  }\n\n  removeScrollLockStyles();\n  restoreScrollPosition(savedScrollY);\n  clearSavedScrollPosition();\n}\n\nfunction removeScrollLockStyles(): void {\n  const { body } = document;\n  body.style.removeProperty('overflow');\n  body.style.removeProperty('position');\n  body.style.removeProperty('top');\n  body.style.removeProperty('left');\n  body.style.removeProperty('right');\n  body.style.removeProperty('bottom');\n}\n\nfunction restoreScrollPosition(savedScrollY: string): void {\n  const scrollY = Number(savedScrollY);\n\n  if (Number.isNaN(scrollY)) {\n    console.warn('[@react-simplikit/mobile] Invalid scroll position, defaulting to 0');\n    window.scrollTo(0, 0);\n    return;\n  }\n\n  window.scrollTo(0, scrollY);\n}\n\nfunction clearSavedScrollPosition(): void {\n  document.body.removeAttribute(SCROLL_POSITION_ATTR);\n}\n"],"mappings":";;;;;;AAKA,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;AAmB7B,SAAgB,wBAA8B;CAC5C,IAAI,SAAS,GACX;CAGF,MAAM,eAAe,SAAS,KAAK,aAAa,oBAAoB;CAEpE,IAAI,gBAAgB,MAClB;CAGF,uBAAuB;CACvB,sBAAsB,YAAY;CAClC,yBAAyB;AAC3B;AAEA,SAAS,yBAA+B;CACtC,MAAM,EAAE,SAAS;CACjB,KAAK,MAAM,eAAe,UAAU;CACpC,KAAK,MAAM,eAAe,UAAU;CACpC,KAAK,MAAM,eAAe,KAAK;CAC/B,KAAK,MAAM,eAAe,MAAM;CAChC,KAAK,MAAM,eAAe,OAAO;CACjC,KAAK,MAAM,eAAe,QAAQ;AACpC;AAEA,SAAS,sBAAsB,cAA4B;CACzD,MAAM,UAAU,OAAO,YAAY;CAEnC,IAAI,OAAO,MAAM,OAAO,GAAG;EACzB,QAAQ,KAAK,oEAAoE;EACjF,OAAO,SAAS,GAAG,CAAC;EACpB;CACF;CAEA,OAAO,SAAS,GAAG,OAAO;AAC5B;AAEA,SAAS,2BAAiC;CACxC,SAAS,KAAK,gBAAgB,oBAAoB;AACpD"}