@zag-js/remove-scroll 1.34.1 → 1.35.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 +33 -10
- package/dist/index.mjs +4 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
4
19
|
|
|
5
20
|
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
preventBodyScroll: () => preventBodyScroll
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
6
27
|
var LOCK_CLASSNAME = "data-scroll-lock";
|
|
7
28
|
function getPaddingProperty(documentElement) {
|
|
8
29
|
const documentLeft = documentElement.getBoundingClientRect().left;
|
|
@@ -10,7 +31,7 @@ function getPaddingProperty(documentElement) {
|
|
|
10
31
|
return scrollbarX ? "paddingLeft" : "paddingRight";
|
|
11
32
|
}
|
|
12
33
|
function hasStableScrollbarGutter(element) {
|
|
13
|
-
const styles =
|
|
34
|
+
const styles = (0, import_dom_query.getComputedStyle)(element);
|
|
14
35
|
const scrollbarGutter = styles?.scrollbarGutter;
|
|
15
36
|
return scrollbarGutter === "stable" || scrollbarGutter?.startsWith("stable ") === true;
|
|
16
37
|
}
|
|
@@ -23,7 +44,7 @@ function preventBodyScroll(_document) {
|
|
|
23
44
|
const hasStableGutter = hasStableScrollbarGutter(documentElement) || hasStableScrollbarGutter(body);
|
|
24
45
|
const scrollbarWidth = win.innerWidth - documentElement.clientWidth;
|
|
25
46
|
body.setAttribute(LOCK_CLASSNAME, "");
|
|
26
|
-
const setScrollbarWidthProperty = () =>
|
|
47
|
+
const setScrollbarWidthProperty = () => (0, import_dom_query.setStyleProperty)(documentElement, "--scrollbar-width", `${scrollbarWidth}px`);
|
|
27
48
|
const paddingProperty = getPaddingProperty(documentElement);
|
|
28
49
|
const setBodyStyle = () => {
|
|
29
50
|
const styles = {
|
|
@@ -32,7 +53,7 @@ function preventBodyScroll(_document) {
|
|
|
32
53
|
if (!hasStableGutter && scrollbarWidth > 0) {
|
|
33
54
|
styles[paddingProperty] = `${scrollbarWidth}px`;
|
|
34
55
|
}
|
|
35
|
-
return
|
|
56
|
+
return (0, import_dom_query.setStyle)(body, styles);
|
|
36
57
|
};
|
|
37
58
|
const setBodyStyleIOS = () => {
|
|
38
59
|
const { scrollX, scrollY, visualViewport } = win;
|
|
@@ -48,17 +69,19 @@ function preventBodyScroll(_document) {
|
|
|
48
69
|
if (!hasStableGutter && scrollbarWidth > 0) {
|
|
49
70
|
styles[paddingProperty] = `${scrollbarWidth}px`;
|
|
50
71
|
}
|
|
51
|
-
const restoreStyle =
|
|
72
|
+
const restoreStyle = (0, import_dom_query.setStyle)(body, styles);
|
|
52
73
|
return () => {
|
|
53
74
|
restoreStyle?.();
|
|
54
75
|
win.scrollTo({ left: scrollX, top: scrollY, behavior: "instant" });
|
|
55
76
|
};
|
|
56
77
|
};
|
|
57
|
-
const cleanups = [setScrollbarWidthProperty(),
|
|
78
|
+
const cleanups = [setScrollbarWidthProperty(), (0, import_dom_query.isIos)() ? setBodyStyleIOS() : setBodyStyle()];
|
|
58
79
|
return () => {
|
|
59
80
|
cleanups.forEach((fn) => fn?.());
|
|
60
81
|
body.removeAttribute(LOCK_CLASSNAME);
|
|
61
82
|
};
|
|
62
83
|
}
|
|
63
|
-
|
|
64
|
-
exports
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
preventBodyScroll
|
|
87
|
+
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { isIos, setStyleProperty, setStyle, getComputedStyle } from '@zag-js/dom-query';
|
|
2
|
-
|
|
3
1
|
// src/index.ts
|
|
2
|
+
import { getComputedStyle, isIos, setStyleProperty, setStyle } from "@zag-js/dom-query";
|
|
4
3
|
var LOCK_CLASSNAME = "data-scroll-lock";
|
|
5
4
|
function getPaddingProperty(documentElement) {
|
|
6
5
|
const documentLeft = documentElement.getBoundingClientRect().left;
|
|
@@ -58,5 +57,6 @@ function preventBodyScroll(_document) {
|
|
|
58
57
|
body.removeAttribute(LOCK_CLASSNAME);
|
|
59
58
|
};
|
|
60
59
|
}
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
export {
|
|
61
|
+
preventBodyScroll
|
|
62
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/remove-scroll",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.35.1",
|
|
4
4
|
"description": "JavaScript utility to remove scroll on body",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@zag-js/dom-query": "1.
|
|
22
|
+
"@zag-js/dom-query": "1.35.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"clean-package": "2.2.0"
|