@zag-js/remove-scroll
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,7 +0,1 @@ | ||
interface BodyScrollOptions { | ||
disabled?: boolean; | ||
document?: Document; | ||
} | ||
export declare function preventBodyScroll(options?: BodyScrollOptions): () => void; | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map | ||
export declare function preventBodyScroll(_document?: Document): () => void; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
@@ -26,3 +27,3 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
// ../core/dist/index.mjs | ||
// ../dom/dist/index.mjs | ||
var isDom = () => typeof window !== "undefined"; | ||
@@ -35,3 +36,3 @@ function getPlatform() { | ||
var pt = (v) => isDom() && v.test(getPlatform()); | ||
var isTouchDevice = isDom() && !!navigator.maxTouchPoints; | ||
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints; | ||
var isMac = () => pt(/^Mac/) && !isTouchDevice; | ||
@@ -42,3 +43,3 @@ var isApple = () => pt(/mac|iphone|ipad|ipod/i); | ||
// src/index.ts | ||
var identifier = "data-scroll-lock"; | ||
var LOCK_CLASSNAME = "data-scroll-lock"; | ||
function assignStyle(el, style) { | ||
@@ -73,14 +74,11 @@ if (!el) | ||
} | ||
function preventBodyScroll(options = {}) { | ||
function preventBodyScroll(_document) { | ||
var _a; | ||
const { document: docProp, disabled } = options; | ||
if (disabled) | ||
return; | ||
const doc = docProp != null ? docProp : document; | ||
const win = (_a = doc == null ? void 0 : doc.defaultView) != null ? _a : window; | ||
const doc = _document != null ? _document : document; | ||
const win = (_a = doc.defaultView) != null ? _a : window; | ||
const { documentElement, body } = doc; | ||
const locked = body.hasAttribute(identifier); | ||
const locked = body.hasAttribute(LOCK_CLASSNAME); | ||
if (locked) | ||
return; | ||
body.setAttribute(identifier, ""); | ||
body.setAttribute(LOCK_CLASSNAME, ""); | ||
const scrollbarWidth = win.innerWidth - documentElement.clientWidth; | ||
@@ -114,5 +112,4 @@ const setScrollbarWidthProperty = () => setCSSProperty(documentElement, "--scrollbar-width", `${scrollbarWidth}px`); | ||
cleanups.forEach((cleanup) => cleanup()); | ||
body.removeAttribute(identifier); | ||
body.removeAttribute(LOCK_CLASSNAME); | ||
}; | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@zag-js/remove-scroll", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "JavaScript utility to remove scroll on body", | ||
@@ -34,3 +34,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/utils": "0.1.2" | ||
"@zag-js/dom-utils": "0.1.6" | ||
}, | ||
@@ -37,0 +37,0 @@ "bugs": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8421
5
194
+ Added@zag-js/dom-utils@0.1.6
+ Added@zag-js/dom-utils@0.1.6(transitive)
+ Added@zag-js/types@0.2.1(transitive)
+ Addedcsstype@3.1.0(transitive)
- Removed@zag-js/utils@0.1.2