You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@zag-js/remove-scroll

Package Overview
Dependencies
Maintainers
1
Versions
792
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/remove-scroll - npm Package Compare versions

Comparing version

to
0.51.0

97

dist/index.js

@@ -1,97 +0,2 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
preventBodyScroll: () => preventBodyScroll
});
module.exports = __toCommonJS(src_exports);
var import_dom_query = require("@zag-js/dom-query");
var LOCK_CLASSNAME = "data-zag-scroll-lock";
function assignStyle(el, style) {
if (!el)
return;
const previousStyle = el.style.cssText;
Object.assign(el.style, style);
return () => {
el.style.cssText = previousStyle;
};
}
function setCSSProperty(el, property, value) {
if (!el)
return;
const previousValue = el.style.getPropertyValue(property);
el.style.setProperty(property, value);
return () => {
if (previousValue) {
el.style.setProperty(property, previousValue);
} else {
el.style.removeProperty(property);
}
};
}
function getPaddingProperty(documentElement) {
const documentLeft = documentElement.getBoundingClientRect().left;
const scrollbarX = Math.round(documentLeft) + documentElement.scrollLeft;
return scrollbarX ? "paddingLeft" : "paddingRight";
}
function preventBodyScroll(_document) {
const doc = _document ?? document;
const win = doc.defaultView ?? window;
const { documentElement, body } = doc;
const locked = body.hasAttribute(LOCK_CLASSNAME);
if (locked)
return;
body.setAttribute(LOCK_CLASSNAME, "");
const scrollbarWidth = win.innerWidth - documentElement.clientWidth;
const setScrollbarWidthProperty = () => setCSSProperty(documentElement, "--scrollbar-width", `${scrollbarWidth}px`);
const paddingProperty = getPaddingProperty(documentElement);
const setStyle = () => assignStyle(body, {
overflow: "hidden",
[paddingProperty]: `${scrollbarWidth}px`
});
const setIOSStyle = () => {
const { scrollX, scrollY, visualViewport } = win;
const offsetLeft = visualViewport?.offsetLeft ?? 0;
const offsetTop = visualViewport?.offsetTop ?? 0;
const restoreStyle = assignStyle(body, {
position: "fixed",
overflow: "hidden",
top: `${-(scrollY - Math.floor(offsetTop))}px`,
left: `${-(scrollX - Math.floor(offsetLeft))}px`,
right: "0",
[paddingProperty]: `${scrollbarWidth}px`
});
return () => {
restoreStyle?.();
win.scrollTo({ left: scrollX, top: scrollY, behavior: "instant" });
};
};
const cleanups = [setScrollbarWidthProperty(), (0, import_dom_query.isIos)() ? setIOSStyle() : setStyle()];
return () => {
cleanups.forEach((fn) => fn?.());
body.removeAttribute(LOCK_CLASSNAME);
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
preventBodyScroll
});
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var src_exports={};__export(src_exports,{preventBodyScroll:()=>preventBodyScroll});module.exports=__toCommonJS(src_exports);var import_dom_query=require("@zag-js/dom-query");var LOCK_CLASSNAME="data-zag-scroll-lock";function assignStyle(el,style){if(!el)return;const previousStyle=el.style.cssText;Object.assign(el.style,style);return()=>{el.style.cssText=previousStyle}}function setCSSProperty(el,property,value){if(!el)return;const previousValue=el.style.getPropertyValue(property);el.style.setProperty(property,value);return()=>{if(previousValue){el.style.setProperty(property,previousValue)}else{el.style.removeProperty(property)}}}function getPaddingProperty(documentElement){const documentLeft=documentElement.getBoundingClientRect().left;const scrollbarX=Math.round(documentLeft)+documentElement.scrollLeft;return scrollbarX?"paddingLeft":"paddingRight"}function preventBodyScroll(_document){const doc=_document??document;const win=doc.defaultView??window;const{documentElement,body}=doc;const locked=body.hasAttribute(LOCK_CLASSNAME);if(locked)return;body.setAttribute(LOCK_CLASSNAME,"");const scrollbarWidth=win.innerWidth-documentElement.clientWidth;const setScrollbarWidthProperty=()=>setCSSProperty(documentElement,"--scrollbar-width",`${scrollbarWidth}px`);const paddingProperty=getPaddingProperty(documentElement);const setStyle=()=>assignStyle(body,{overflow:"hidden",[paddingProperty]:`${scrollbarWidth}px`});const setIOSStyle=()=>{const{scrollX,scrollY,visualViewport}=win;const offsetLeft=visualViewport?.offsetLeft??0;const offsetTop=visualViewport?.offsetTop??0;const restoreStyle=assignStyle(body,{position:"fixed",overflow:"hidden",top:`${-(scrollY-Math.floor(offsetTop))}px`,left:`${-(scrollX-Math.floor(offsetLeft))}px`,right:"0",[paddingProperty]:`${scrollbarWidth}px`});return()=>{restoreStyle?.();win.scrollTo({left:scrollX,top:scrollY,behavior:"instant"})}};const cleanups=[setScrollbarWidthProperty(),(0,import_dom_query.isIos)()?setIOSStyle():setStyle()];return()=>{cleanups.forEach(fn=>fn?.());body.removeAttribute(LOCK_CLASSNAME)}}0&&(module.exports={preventBodyScroll});
//# sourceMappingURL=index.js.map

4

package.json
{
"name": "@zag-js/remove-scroll",
"version": "0.50.0",
"version": "0.51.0",
"description": "JavaScript utility to remove scroll on body",

@@ -23,3 +23,3 @@ "keywords": [

"dependencies": {
"@zag-js/dom-query": "0.50.0"
"@zag-js/dom-query": "0.51.0"
},

@@ -26,0 +26,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet