@michaelyagi/shoji 0.1.0-alpha.12 → 0.1.0-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,24 +5,65 @@ import { w as waitForTransitionEnd, c as containedBox, z as zoomIn, a as zoomOut
5
5
  let lockCount = 0;
6
6
  let savedHtmlOverflow = "";
7
7
  let savedHtmlPaddingRight = "";
8
+ let savedHtmlPaddingLeft = "";
9
+ let savedScrollX = 0;
10
+ let savedScrollY = 0;
11
+ let styleObserver = null;
12
+ const LIGHTBOX_SELECTOR = ".shoji-outer";
13
+ function isRtl() {
14
+ return getComputedStyle(document.documentElement).direction === "rtl";
15
+ }
16
+ function onTouchMove(event) {
17
+ const target = event.target;
18
+ const insideLightbox = target instanceof Element && target.closest(LIGHTBOX_SELECTOR) !== null;
19
+ if (!insideLightbox) event.preventDefault();
20
+ }
21
+ function onStyleMutation() {
22
+ if (lockCount === 0) return;
23
+ const html = document.documentElement;
24
+ if (getComputedStyle(html).overflow !== "hidden") {
25
+ html.style.overflow = "hidden";
26
+ styleObserver == null ? void 0 : styleObserver.takeRecords();
27
+ }
28
+ }
8
29
  function lockBodyScroll() {
9
30
  if (lockCount === 0) {
31
+ savedScrollX = window.scrollX;
32
+ savedScrollY = window.scrollY;
10
33
  const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
34
+ const rtl = isRtl();
11
35
  savedHtmlPaddingRight = document.documentElement.style.paddingRight;
36
+ savedHtmlPaddingLeft = document.documentElement.style.paddingLeft;
12
37
  if (scrollbarWidth > 0) {
13
- const currentPaddingRight = parseFloat(getComputedStyle(document.documentElement).paddingRight) || 0;
14
- document.documentElement.style.paddingRight = `${currentPaddingRight + scrollbarWidth}px`;
38
+ if (rtl) {
39
+ const currentPaddingLeft = parseFloat(getComputedStyle(document.documentElement).paddingLeft) || 0;
40
+ document.documentElement.style.paddingLeft = `${currentPaddingLeft + scrollbarWidth}px`;
41
+ } else {
42
+ const currentPaddingRight = parseFloat(getComputedStyle(document.documentElement).paddingRight) || 0;
43
+ document.documentElement.style.paddingRight = `${currentPaddingRight + scrollbarWidth}px`;
44
+ }
15
45
  }
16
46
  savedHtmlOverflow = document.documentElement.style.overflow;
17
47
  document.documentElement.style.overflow = "hidden";
48
+ document.addEventListener("touchmove", onTouchMove, { passive: false });
49
+ styleObserver = new MutationObserver(onStyleMutation);
50
+ styleObserver.observe(document.documentElement, {
51
+ attributes: true,
52
+ attributeFilter: ["style"]
53
+ });
18
54
  }
19
55
  lockCount++;
20
56
  }
21
57
  function unlockBodyScroll() {
22
58
  lockCount = Math.max(0, lockCount - 1);
23
59
  if (lockCount === 0) {
60
+ styleObserver == null ? void 0 : styleObserver.disconnect();
61
+ styleObserver = null;
62
+ document.removeEventListener("touchmove", onTouchMove);
24
63
  document.documentElement.style.overflow = savedHtmlOverflow;
25
64
  document.documentElement.style.paddingRight = savedHtmlPaddingRight;
65
+ document.documentElement.style.paddingLeft = savedHtmlPaddingLeft;
66
+ window.scrollTo({ left: savedScrollX, top: savedScrollY, behavior: "instant" });
26
67
  }
27
68
  }
28
69
  class EventBus {