@zag-js/remove-scroll 2.0.0-next.0 → 2.0.0-next.1
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 +8 -3
- package/dist/index.mjs +9 -4
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -36,22 +36,27 @@ function hasStableScrollbarGutter(element) {
|
|
|
36
36
|
const scrollbarGutter = styles?.scrollbarGutter;
|
|
37
37
|
return scrollbarGutter === "stable" || scrollbarGutter?.startsWith("stable ") === true;
|
|
38
38
|
}
|
|
39
|
+
function getScrollContainer(doc) {
|
|
40
|
+
const { documentElement, body } = doc;
|
|
41
|
+
return (0, import_dom_query.isOverflowElement)(documentElement) ? documentElement : body;
|
|
42
|
+
}
|
|
39
43
|
function applyLock(doc) {
|
|
40
44
|
const win = doc.defaultView ?? window;
|
|
41
45
|
const { documentElement, body } = doc;
|
|
46
|
+
const scroller = getScrollContainer(doc);
|
|
42
47
|
const hasStableGutter = hasStableScrollbarGutter(documentElement) || hasStableScrollbarGutter(body);
|
|
43
48
|
const scrollbarWidth = win.innerWidth - documentElement.clientWidth;
|
|
44
49
|
body.setAttribute(LOCK_CLASSNAME, "");
|
|
45
50
|
const setScrollbarWidthProperty = () => (0, import_dom_query.setStyleProperty)(documentElement, "--scrollbar-width", `${scrollbarWidth}px`);
|
|
46
51
|
const paddingProperty = getPaddingProperty(documentElement);
|
|
47
|
-
const
|
|
52
|
+
const setScrollerStyle = () => {
|
|
48
53
|
const styles = {
|
|
49
54
|
overflow: "hidden"
|
|
50
55
|
};
|
|
51
56
|
if (!hasStableGutter && scrollbarWidth > 0) {
|
|
52
57
|
styles[paddingProperty] = `${scrollbarWidth}px`;
|
|
53
58
|
}
|
|
54
|
-
return (0, import_dom_query.setStyle)(
|
|
59
|
+
return (0, import_dom_query.setStyle)(scroller, styles);
|
|
55
60
|
};
|
|
56
61
|
const setBodyStyleIOS = () => {
|
|
57
62
|
const { scrollX, scrollY, visualViewport } = win;
|
|
@@ -73,7 +78,7 @@ function applyLock(doc) {
|
|
|
73
78
|
win.scrollTo({ left: scrollX, top: scrollY, behavior: "instant" });
|
|
74
79
|
};
|
|
75
80
|
};
|
|
76
|
-
const cleanups = [setScrollbarWidthProperty(), (0, import_dom_query.isIos)() ? setBodyStyleIOS() :
|
|
81
|
+
const cleanups = [setScrollbarWidthProperty(), (0, import_dom_query.isIos)() ? setBodyStyleIOS() : setScrollerStyle()];
|
|
77
82
|
return () => {
|
|
78
83
|
cleanups.forEach((fn) => fn?.());
|
|
79
84
|
body.removeAttribute(LOCK_CLASSNAME);
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { getComputedStyle, isIos, setStyleProperty, setStyle } from "@zag-js/dom-query";
|
|
2
|
+
import { getComputedStyle, isIos, isOverflowElement, setStyleProperty, setStyle } from "@zag-js/dom-query";
|
|
3
3
|
var LOCK_CLASSNAME = "data-scroll-lock";
|
|
4
4
|
var lockMap = /* @__PURE__ */ new WeakMap();
|
|
5
5
|
function getPaddingProperty(documentElement) {
|
|
@@ -12,22 +12,27 @@ function hasStableScrollbarGutter(element) {
|
|
|
12
12
|
const scrollbarGutter = styles?.scrollbarGutter;
|
|
13
13
|
return scrollbarGutter === "stable" || scrollbarGutter?.startsWith("stable ") === true;
|
|
14
14
|
}
|
|
15
|
+
function getScrollContainer(doc) {
|
|
16
|
+
const { documentElement, body } = doc;
|
|
17
|
+
return isOverflowElement(documentElement) ? documentElement : body;
|
|
18
|
+
}
|
|
15
19
|
function applyLock(doc) {
|
|
16
20
|
const win = doc.defaultView ?? window;
|
|
17
21
|
const { documentElement, body } = doc;
|
|
22
|
+
const scroller = getScrollContainer(doc);
|
|
18
23
|
const hasStableGutter = hasStableScrollbarGutter(documentElement) || hasStableScrollbarGutter(body);
|
|
19
24
|
const scrollbarWidth = win.innerWidth - documentElement.clientWidth;
|
|
20
25
|
body.setAttribute(LOCK_CLASSNAME, "");
|
|
21
26
|
const setScrollbarWidthProperty = () => setStyleProperty(documentElement, "--scrollbar-width", `${scrollbarWidth}px`);
|
|
22
27
|
const paddingProperty = getPaddingProperty(documentElement);
|
|
23
|
-
const
|
|
28
|
+
const setScrollerStyle = () => {
|
|
24
29
|
const styles = {
|
|
25
30
|
overflow: "hidden"
|
|
26
31
|
};
|
|
27
32
|
if (!hasStableGutter && scrollbarWidth > 0) {
|
|
28
33
|
styles[paddingProperty] = `${scrollbarWidth}px`;
|
|
29
34
|
}
|
|
30
|
-
return setStyle(
|
|
35
|
+
return setStyle(scroller, styles);
|
|
31
36
|
};
|
|
32
37
|
const setBodyStyleIOS = () => {
|
|
33
38
|
const { scrollX, scrollY, visualViewport } = win;
|
|
@@ -49,7 +54,7 @@ function applyLock(doc) {
|
|
|
49
54
|
win.scrollTo({ left: scrollX, top: scrollY, behavior: "instant" });
|
|
50
55
|
};
|
|
51
56
|
};
|
|
52
|
-
const cleanups = [setScrollbarWidthProperty(), isIos() ? setBodyStyleIOS() :
|
|
57
|
+
const cleanups = [setScrollbarWidthProperty(), isIos() ? setBodyStyleIOS() : setScrollerStyle()];
|
|
53
58
|
return () => {
|
|
54
59
|
cleanups.forEach((fn) => fn?.());
|
|
55
60
|
body.removeAttribute(LOCK_CLASSNAME);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/remove-scroll",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.1",
|
|
4
4
|
"description": "JavaScript utility to remove scroll on body",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
"author": "Segun Adebayo <sage@adebayosegun.com>",
|
|
11
11
|
"homepage": "https://github.com/chakra-ui/zag#readme",
|
|
12
12
|
"license": "MIT",
|
|
13
|
-
"repository":
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/chakra-ui/zag/tree/main/packages/utilities/remove-scroll"
|
|
16
|
+
},
|
|
14
17
|
"sideEffects": false,
|
|
15
18
|
"files": [
|
|
16
19
|
"dist"
|
|
@@ -19,7 +22,7 @@
|
|
|
19
22
|
"access": "public"
|
|
20
23
|
},
|
|
21
24
|
"dependencies": {
|
|
22
|
-
"@zag-js/dom-query": "2.0.0-next.
|
|
25
|
+
"@zag-js/dom-query": "2.0.0-next.1"
|
|
23
26
|
},
|
|
24
27
|
"devDependencies": {
|
|
25
28
|
"clean-package": "2.2.0"
|