@zag-js/remove-scroll 0.2.1 → 0.2.3

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.
package/dist/index.js CHANGED
@@ -23,22 +23,8 @@ __export(src_exports, {
23
23
  preventBodyScroll: () => preventBodyScroll
24
24
  });
25
25
  module.exports = __toCommonJS(src_exports);
26
-
27
- // ../dom/src/platform.ts
28
- var isDom = () => typeof window !== "undefined";
29
- function getPlatform() {
30
- var _a;
31
- const agent = navigator.userAgentData;
32
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
33
- }
34
- var pt = (v) => isDom() && v.test(getPlatform());
35
- var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
36
- var isMac = () => pt(/^Mac/) && !isTouchDevice;
37
- var isApple = () => pt(/mac|iphone|ipad|ipod/i);
38
- var isIos = () => isApple() && !isMac();
39
-
40
- // src/index.ts
41
- var LOCK_CLASSNAME = "data-scroll-lock";
26
+ var import_dom_query = require("@zag-js/dom-query");
27
+ var LOCK_CLASSNAME = "data-zag-scroll-lock";
42
28
  function assignStyle(el, style) {
43
29
  if (!el)
44
30
  return () => {
@@ -69,9 +55,8 @@ function getPaddingProperty(documentElement) {
69
55
  return scrollbarX ? "paddingLeft" : "paddingRight";
70
56
  }
71
57
  function preventBodyScroll(_document) {
72
- var _a;
73
- const doc = _document != null ? _document : document;
74
- const win = (_a = doc.defaultView) != null ? _a : window;
58
+ const doc = _document ?? document;
59
+ const win = doc.defaultView ?? window;
75
60
  const { documentElement, body } = doc;
76
61
  const locked = body.hasAttribute(LOCK_CLASSNAME);
77
62
  if (locked)
@@ -85,10 +70,9 @@ function preventBodyScroll(_document) {
85
70
  [paddingProperty]: `${scrollbarWidth}px`
86
71
  });
87
72
  const setIOSStyle = () => {
88
- var _a2, _b;
89
73
  const { scrollX, scrollY, visualViewport } = win;
90
- const offsetLeft = (_a2 = visualViewport == null ? void 0 : visualViewport.offsetLeft) != null ? _a2 : 0;
91
- const offsetTop = (_b = visualViewport == null ? void 0 : visualViewport.offsetTop) != null ? _b : 0;
74
+ const offsetLeft = visualViewport?.offsetLeft ?? 0;
75
+ const offsetTop = visualViewport?.offsetTop ?? 0;
92
76
  const restoreStyle = assignStyle(body, {
93
77
  position: "fixed",
94
78
  overflow: "hidden",
@@ -102,7 +86,7 @@ function preventBodyScroll(_document) {
102
86
  win.scrollTo(scrollX, scrollY);
103
87
  };
104
88
  };
105
- const cleanups = [setScrollbarWidthProperty(), isIos() ? setIOSStyle() : setStyle()];
89
+ const cleanups = [setScrollbarWidthProperty(), (0, import_dom_query.isIos)() ? setIOSStyle() : setStyle()];
106
90
  return () => {
107
91
  cleanups.forEach((cleanup) => cleanup());
108
92
  body.removeAttribute(LOCK_CLASSNAME);
package/dist/index.mjs CHANGED
@@ -1,18 +1,6 @@
1
- // ../dom/src/platform.ts
2
- var isDom = () => typeof window !== "undefined";
3
- function getPlatform() {
4
- var _a;
5
- const agent = navigator.userAgentData;
6
- return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
7
- }
8
- var pt = (v) => isDom() && v.test(getPlatform());
9
- var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
10
- var isMac = () => pt(/^Mac/) && !isTouchDevice;
11
- var isApple = () => pt(/mac|iphone|ipad|ipod/i);
12
- var isIos = () => isApple() && !isMac();
13
-
14
1
  // src/index.ts
15
- var LOCK_CLASSNAME = "data-scroll-lock";
2
+ import { isIos } from "@zag-js/dom-query";
3
+ var LOCK_CLASSNAME = "data-zag-scroll-lock";
16
4
  function assignStyle(el, style) {
17
5
  if (!el)
18
6
  return () => {
@@ -43,9 +31,8 @@ function getPaddingProperty(documentElement) {
43
31
  return scrollbarX ? "paddingLeft" : "paddingRight";
44
32
  }
45
33
  function preventBodyScroll(_document) {
46
- var _a;
47
- const doc = _document != null ? _document : document;
48
- const win = (_a = doc.defaultView) != null ? _a : window;
34
+ const doc = _document ?? document;
35
+ const win = doc.defaultView ?? window;
49
36
  const { documentElement, body } = doc;
50
37
  const locked = body.hasAttribute(LOCK_CLASSNAME);
51
38
  if (locked)
@@ -59,10 +46,9 @@ function preventBodyScroll(_document) {
59
46
  [paddingProperty]: `${scrollbarWidth}px`
60
47
  });
61
48
  const setIOSStyle = () => {
62
- var _a2, _b;
63
49
  const { scrollX, scrollY, visualViewport } = win;
64
- const offsetLeft = (_a2 = visualViewport == null ? void 0 : visualViewport.offsetLeft) != null ? _a2 : 0;
65
- const offsetTop = (_b = visualViewport == null ? void 0 : visualViewport.offsetTop) != null ? _b : 0;
50
+ const offsetLeft = visualViewport?.offsetLeft ?? 0;
51
+ const offsetTop = visualViewport?.offsetTop ?? 0;
66
52
  const restoreStyle = assignStyle(body, {
67
53
  position: "fixed",
68
54
  overflow: "hidden",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/remove-scroll",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "JavaScript utility to remove scroll on body",
5
5
  "keywords": [
6
6
  "js",
@@ -18,9 +18,11 @@
18
18
  "publishConfig": {
19
19
  "access": "public"
20
20
  },
21
+ "dependencies": {
22
+ "@zag-js/dom-query": "0.1.3"
23
+ },
21
24
  "devDependencies": {
22
- "clean-package": "2.2.0",
23
- "@zag-js/dom-utils": "0.2.2"
25
+ "clean-package": "2.2.0"
24
26
  },
25
27
  "bugs": {
26
28
  "url": "https://github.com/chakra-ui/zag/issues"