tua-body-scroll-lock
Advanced tools
Comparing version 1.2.1 to 1.2.2-0
/** | ||
* tua-body-scroll-lock v1.2.1 | ||
* (c) 2021 Evinma, BuptStEve | ||
* tua-body-scroll-lock v1.2.2-0 | ||
* (c) 2023 Evinma, BuptStEve | ||
* @license MIT | ||
@@ -27,6 +27,7 @@ */ | ||
isSupportOptions = true; | ||
return; | ||
return undefined; | ||
}, | ||
}; | ||
/* istanbul ignore next */ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
const noop = () => { }; | ||
@@ -54,10 +55,14 @@ const testEvent = '__TUA_BSL_TEST_PASSIVE__'; | ||
const setOverflowHiddenPc = () => { | ||
const $html = document.documentElement; | ||
const $body = document.body; | ||
const htmlStyle = Object.assign({}, $html.style); | ||
const bodyStyle = Object.assign({}, $body.style); | ||
const scrollBarWidth = window.innerWidth - $body.clientWidth; | ||
$body.style.overflow = 'hidden'; | ||
$body.style.boxSizing = 'border-box'; | ||
$body.style.paddingRight = `${scrollBarWidth}px`; | ||
[$html, $body].forEach(element => { | ||
element.style.overflow = 'hidden'; | ||
element.style.boxSizing = 'border-box'; | ||
element.style.paddingRight = `${window.innerWidth - element.clientWidth}px`; | ||
}); | ||
return () => { | ||
['overflow', 'boxSizing', 'paddingRight'].forEach((x) => { | ||
$html.style[x] = htmlStyle[x] || ''; | ||
$body.style[x] = bodyStyle[x] || ''; | ||
@@ -86,8 +91,5 @@ }); | ||
}); | ||
const scrollToOptions = { top: scrollTop, behavior: 'instant' }; | ||
supportsNativeSmoothScroll | ||
? window.scrollTo({ | ||
top: scrollTop, | ||
// @ts-ignore | ||
behavior: 'instant', | ||
}) | ||
? window.scrollTo(scrollToOptions) | ||
: window.scrollTo(0, scrollTop); | ||
@@ -124,4 +126,4 @@ }; | ||
return; | ||
console.warn(`If scrolling is also required in the floating layer, ` + | ||
`the target element must be provided.`); | ||
console.warn('If scrolling is also required in the floating layer, ' + | ||
'the target element must be provided.'); | ||
}; | ||
@@ -128,0 +130,0 @@ const lock = (targetElement) => { |
@@ -1,1 +0,6 @@ | ||
const e=()=>"undefined"==typeof window,t=e=>{e=e||navigator.userAgent;const t=/(iPad).*OS\s([\d_]+)/.test(e);return{ios:!t&&/(iPhone\sOS)\s([\d_]+)/.test(e)||t,android:/(Android);?[\s\/]+([\d.]+)?/.test(e)}};let o=0,n=0,i=0,s=null,r=!1;const l=[],c=function(t){if(e())return!1;if(!t)throw new Error("options must be provided");let o=!1;const n={get passive(){o=!0}},i=()=>{};window.addEventListener("__TUA_BSL_TEST_PASSIVE__",i,n),window.removeEventListener("__TUA_BSL_TEST_PASSIVE__",i,n);const{capture:s}=t;return o?t:void 0!==s&&s}({passive:!1}),d=!e()&&"scrollBehavior"in document.documentElement.style,h=e=>{e.cancelable&&e.preventDefault()},a=a=>{if(!e()){if(t().ios){if(a){(Array.isArray(a)?a:[a]).forEach(e=>{e&&-1===l.indexOf(e)&&(e.ontouchstart=e=>{n=e.targetTouches[0].clientY,i=e.targetTouches[0].clientX},e.ontouchmove=t=>{1===t.targetTouches.length&&((e,t)=>{if(t){const{scrollTop:o,scrollLeft:s,scrollWidth:r,scrollHeight:l,clientWidth:c,clientHeight:d}=t,a=e.targetTouches[0].clientX-i,u=e.targetTouches[0].clientY-n,f=Math.abs(u)>Math.abs(a),p=u>0&&0===o,v=a>0&&0===s,g=a<0&&s+c+1>=r,y=u<0&&o+d+1>=l;if(f&&(p||y)||!f&&(v||g))return h(e)}e.stopPropagation()})(t,e)},l.push(e))})}r||(document.addEventListener("touchmove",h,c),r=!0)}else o<=0&&(s=t().android?(()=>{const e=document.documentElement,t=document.body,o=e.scrollTop||t.scrollTop,n=Object.assign({},e.style),i=Object.assign({},t.style);return e.style.height="100%",e.style.overflow="hidden",t.style.top=`-${o}px`,t.style.width="100%",t.style.height="auto",t.style.position="fixed",t.style.overflow="hidden",()=>{e.style.height=n.height||"",e.style.overflow=n.overflow||"",["top","width","height","overflow","position"].forEach(e=>{t.style[e]=i[e]||""}),d?window.scrollTo({top:o,behavior:"instant"}):window.scrollTo(0,o)}})():(()=>{const e=document.body,t=Object.assign({},e.style),o=window.innerWidth-e.clientWidth;return e.style.overflow="hidden",e.style.boxSizing="border-box",e.style.paddingRight=`${o}px`,()=>{["overflow","boxSizing","paddingRight"].forEach(o=>{e.style[o]=t[o]||""})}})());o+=1}},u=n=>{if(!(e()||(o-=1)>0))if(t().ios||"function"!=typeof s){if(n){(Array.isArray(n)?n:[n]).forEach(e=>{const t=l.indexOf(e);-1!==t&&(e.ontouchmove=null,e.ontouchstart=null,l.splice(t,1))})}r&&(document.removeEventListener("touchmove",h,c),r=!1)}else s()},f=()=>{if(!e())if(o=0,t().ios||"function"!=typeof s){if(l.length){let e=l.pop();for(;e;)e.ontouchmove=null,e.ontouchstart=null,e=l.pop()}r&&(document.removeEventListener("touchmove",h,c),r=!1)}else s()};export{f as clearBodyLocks,a as lock,u as unlock}; | ||
/** | ||
* tua-body-scroll-lock v1.2.2-0 | ||
* (c) 2023 Evinma, BuptStEve | ||
* @license MIT | ||
*/ | ||
const e=()=>"undefined"==typeof window,t=e=>{e=e||navigator.userAgent;const t=/(iPad).*OS\s([\d_]+)/.test(e);return{ios:!t&&/(iPhone\sOS)\s([\d_]+)/.test(e)||t,android:/(Android);?[\s/]+([\d.]+)?/.test(e)}};let o=0,n=0,i=0,s=null,l=!1;const r=[],c=function(t){if(e())return!1;if(!t)throw new Error("options must be provided");let o=!1;const n={get passive(){o=!0}},i=()=>{},s="__TUA_BSL_TEST_PASSIVE__";window.addEventListener(s,i,n),window.removeEventListener(s,i,n);const{capture:l}=t;return o?t:void 0!==l&&l}({passive:!1}),d=!e()&&"scrollBehavior"in document.documentElement.style,h=e=>{e.cancelable&&e.preventDefault()},a=a=>{if(!e()){if(t().ios){if(a){(Array.isArray(a)?a:[a]).forEach((e=>{e&&-1===r.indexOf(e)&&(e.ontouchstart=e=>{n=e.targetTouches[0].clientY,i=e.targetTouches[0].clientX},e.ontouchmove=t=>{1===t.targetTouches.length&&((e,t)=>{if(t){const{scrollTop:o,scrollLeft:s,scrollWidth:l,scrollHeight:r,clientWidth:c,clientHeight:d}=t,a=e.targetTouches[0].clientX-i,u=e.targetTouches[0].clientY-n,f=Math.abs(u)>Math.abs(a);if(f&&(u>0&&0===o||u<0&&o+d+1>=r)||!f&&(a>0&&0===s||a<0&&s+c+1>=l))return h(e)}e.stopPropagation()})(t,e)},r.push(e))}))}l||(document.addEventListener("touchmove",h,c),l=!0)}else o<=0&&(s=t().android?(()=>{const e=document.documentElement,t=document.body,o=e.scrollTop||t.scrollTop,n=Object.assign({},e.style),i=Object.assign({},t.style);return e.style.height="100%",e.style.overflow="hidden",t.style.top=`-${o}px`,t.style.width="100%",t.style.height="auto",t.style.position="fixed",t.style.overflow="hidden",()=>{e.style.height=n.height||"",e.style.overflow=n.overflow||"",["top","width","height","overflow","position"].forEach((e=>{t.style[e]=i[e]||""}));const s={top:o,behavior:"instant"};d?window.scrollTo(s):window.scrollTo(0,o)}})():(()=>{const e=document.documentElement,t=document.body,o=Object.assign({},e.style),n=Object.assign({},t.style);return[e,t].forEach((e=>{e.style.overflow="hidden",e.style.boxSizing="border-box",e.style.paddingRight=window.innerWidth-e.clientWidth+"px"})),()=>{["overflow","boxSizing","paddingRight"].forEach((i=>{e.style[i]=o[i]||"",t.style[i]=n[i]||""}))}})());o+=1}},u=n=>{if(!(e()||(o-=1,o>0)))if(t().ios||"function"!=typeof s){if(n){(Array.isArray(n)?n:[n]).forEach((e=>{const t=r.indexOf(e);-1!==t&&(e.ontouchmove=null,e.ontouchstart=null,r.splice(t,1))}))}l&&(document.removeEventListener("touchmove",h,c),l=!1)}else s()},f=()=>{if(!e())if(o=0,t().ios||"function"!=typeof s){if(r.length){let e=r.pop();for(;e;)e.ontouchmove=null,e.ontouchstart=null,e=r.pop()}l&&(document.removeEventListener("touchmove",h,c),l=!1)}else s()};export{f as clearBodyLocks,a as lock,u as unlock}; |
/** | ||
* tua-body-scroll-lock v1.2.1 | ||
* (c) 2021 Evinma, BuptStEve | ||
* tua-body-scroll-lock v1.2.2-0 | ||
* (c) 2023 Evinma, BuptStEve | ||
* @license MIT | ||
@@ -10,4 +10,4 @@ */ | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.bodyScrollLock = {})); | ||
}(this, function (exports) { 'use strict'; | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.bodyScrollLock = {})); | ||
})(this, (function (exports) { 'use strict'; | ||
@@ -31,7 +31,5 @@ var isServer = function isServer() { | ||
if (isServer()) return false; | ||
if (!options) { | ||
throw new Error('options must be provided'); | ||
} | ||
var isSupportOptions = false; | ||
@@ -41,10 +39,8 @@ var listenerOptions = { | ||
isSupportOptions = true; | ||
return; | ||
return undefined; | ||
} | ||
}; | ||
/* istanbul ignore next */ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
var noop = function noop() {}; | ||
var testEvent = '__TUA_BSL_TEST_PASSIVE__'; | ||
@@ -55,3 +51,2 @@ window.addEventListener(testEvent, noop, listenerOptions); | ||
/* istanbul ignore next */ | ||
return isSupportOptions ? options : typeof capture !== 'undefined' ? capture : false; | ||
@@ -70,12 +65,15 @@ } | ||
var supportsNativeSmoothScroll = !isServer() && 'scrollBehavior' in document.documentElement.style; | ||
var setOverflowHiddenPc = function setOverflowHiddenPc() { | ||
var $html = document.documentElement; | ||
var $body = document.body; | ||
var htmlStyle = Object.assign({}, $html.style); | ||
var bodyStyle = Object.assign({}, $body.style); | ||
var scrollBarWidth = window.innerWidth - $body.clientWidth; | ||
$body.style.overflow = 'hidden'; | ||
$body.style.boxSizing = 'border-box'; | ||
$body.style.paddingRight = "".concat(scrollBarWidth, "px"); | ||
[$html, $body].forEach(function (element) { | ||
element.style.overflow = 'hidden'; | ||
element.style.boxSizing = 'border-box'; | ||
element.style.paddingRight = "".concat(window.innerWidth - element.clientWidth, "px"); | ||
}); | ||
return function () { | ||
['overflow', 'boxSizing', 'paddingRight'].forEach(function (x) { | ||
$html.style[x] = htmlStyle[x] || ''; | ||
$body.style[x] = bodyStyle[x] || ''; | ||
@@ -85,3 +83,2 @@ }); | ||
}; | ||
var setOverflowHiddenMobile = function setOverflowHiddenMobile() { | ||
@@ -106,10 +103,9 @@ var $html = document.documentElement; | ||
}); | ||
supportsNativeSmoothScroll ? window.scrollTo({ | ||
var scrollToOptions = { | ||
top: scrollTop, | ||
// @ts-ignore | ||
behavior: 'instant' | ||
}) : window.scrollTo(0, scrollTop); | ||
}; | ||
supportsNativeSmoothScroll ? window.scrollTo(scrollToOptions) : window.scrollTo(0, scrollTop); | ||
}; | ||
}; | ||
var preventDefault = function preventDefault(event) { | ||
@@ -119,11 +115,10 @@ if (!event.cancelable) return; | ||
}; | ||
var handleScroll = function handleScroll(event, targetElement) { | ||
if (targetElement) { | ||
var scrollTop = targetElement.scrollTop, | ||
scrollLeft = targetElement.scrollLeft, | ||
scrollWidth = targetElement.scrollWidth, | ||
scrollHeight = targetElement.scrollHeight, | ||
clientWidth = targetElement.clientWidth, | ||
clientHeight = targetElement.clientHeight; | ||
scrollLeft = targetElement.scrollLeft, | ||
scrollWidth = targetElement.scrollWidth, | ||
scrollHeight = targetElement.scrollHeight, | ||
clientWidth = targetElement.clientWidth, | ||
clientHeight = targetElement.clientHeight; | ||
var clientX = event.targetTouches[0].clientX - initialClientX; | ||
@@ -136,3 +131,2 @@ var clientY = event.targetTouches[0].clientY - initialClientY; | ||
var isOnBottom = clientY < 0 && scrollTop + clientHeight + 1 >= scrollHeight; | ||
if (isVertical && (isOnTop || isOnBottom) || !isVertical && (isOnLeft || isOnRight)) { | ||
@@ -142,17 +136,13 @@ return preventDefault(event); | ||
} | ||
event.stopPropagation(); | ||
return true; | ||
}; | ||
var checkTargetElement = function checkTargetElement(targetElement) { | ||
if (targetElement) return; | ||
if (targetElement === null) return; | ||
console.warn("If scrolling is also required in the floating layer, " + "the target element must be provided."); | ||
console.warn('If scrolling is also required in the floating layer, ' + 'the target element must be provided.'); | ||
}; | ||
var lock = function lock(targetElement) { | ||
if (isServer()) return; | ||
checkTargetElement(targetElement); | ||
if (detectOS().ios) { | ||
@@ -168,3 +158,2 @@ // iOS | ||
}; | ||
element.ontouchmove = function (event) { | ||
@@ -174,3 +163,2 @@ if (event.targetTouches.length !== 1) return; | ||
}; | ||
lockedElements.push(element); | ||
@@ -180,3 +168,2 @@ } | ||
} | ||
if (!documentListenerAdded) { | ||
@@ -189,6 +176,4 @@ document.addEventListener('touchmove', preventDefault, eventListenerOptions); | ||
} | ||
lockedNum += 1; | ||
}; | ||
var unlock = function unlock(targetElement) { | ||
@@ -199,9 +184,7 @@ if (isServer()) return; | ||
if (lockedNum > 0) return; | ||
if (!detectOS().ios && typeof unLockCallback === 'function') { | ||
unLockCallback(); | ||
return; | ||
} // iOS | ||
} | ||
// iOS | ||
if (targetElement) { | ||
@@ -211,3 +194,2 @@ var elementArray = Array.isArray(targetElement) ? targetElement : [targetElement]; | ||
var index = lockedElements.indexOf(element); | ||
if (index !== -1) { | ||
@@ -220,3 +202,2 @@ element.ontouchmove = null; | ||
} | ||
if (documentListenerAdded) { | ||
@@ -227,17 +208,13 @@ document.removeEventListener('touchmove', preventDefault, eventListenerOptions); | ||
}; | ||
var clearBodyLocks = function clearBodyLocks() { | ||
if (isServer()) return; | ||
lockedNum = 0; | ||
if (!detectOS().ios && typeof unLockCallback === 'function') { | ||
unLockCallback(); | ||
return; | ||
} // IOS | ||
} | ||
// IOS | ||
if (lockedElements.length) { | ||
// clear events | ||
var element = lockedElements.pop(); | ||
while (element) { | ||
@@ -249,3 +226,2 @@ element.ontouchmove = null; | ||
} | ||
if (documentListenerAdded) { | ||
@@ -261,4 +237,2 @@ document.removeEventListener('touchmove', preventDefault, eventListenerOptions); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); |
@@ -1,1 +0,6 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).bodyScrollLock={})}(this,function(e){"use strict";var t=function(){return"undefined"==typeof window},o=function(e){e=e||navigator.userAgent;var t=/(iPad).*OS\s([\d_]+)/.test(e);return{ios:!t&&/(iPhone\sOS)\s([\d_]+)/.test(e)||t,android:/(Android);?[\s\/]+([\d.]+)?/.test(e)}};var n=0,i=0,r=0,c=null,s=!1,l=[],u=function(e){if(t())return!1;if(!e)throw new Error("options must be provided");var o=!1,n={get passive(){o=!0}},i=function(){};window.addEventListener("__TUA_BSL_TEST_PASSIVE__",i,n),window.removeEventListener("__TUA_BSL_TEST_PASSIVE__",i,n);var r=e.capture;return o?e:void 0!==r&&r}({passive:!1}),d=!t()&&"scrollBehavior"in document.documentElement.style,f=function(e){e.cancelable&&e.preventDefault()};e.clearBodyLocks=function(){if(!t())if(n=0,o().ios||"function"!=typeof c){if(l.length)for(var e=l.pop();e;)e.ontouchmove=null,e.ontouchstart=null,e=l.pop();s&&(document.removeEventListener("touchmove",f,u),s=!1)}else c()},e.lock=function(e){if(!t()){if(o().ios){if(e)(Array.isArray(e)?e:[e]).forEach(function(e){e&&-1===l.indexOf(e)&&(e.ontouchstart=function(e){i=e.targetTouches[0].clientY,r=e.targetTouches[0].clientX},e.ontouchmove=function(t){1===t.targetTouches.length&&function(e,t){if(t){var o=t.scrollTop,n=t.scrollLeft,c=t.scrollWidth,s=t.scrollHeight,l=t.clientWidth,u=t.clientHeight,d=e.targetTouches[0].clientX-r,a=e.targetTouches[0].clientY-i,h=Math.abs(a)>Math.abs(d);if(h&&(a>0&&0===o||a<0&&o+u+1>=s)||!h&&(d>0&&0===n||d<0&&n+l+1>=c))return f(e)}e.stopPropagation()}(t,e)},l.push(e))});s||(document.addEventListener("touchmove",f,u),s=!0)}else n<=0&&(c=o().android?(a=document.documentElement,h=document.body,v=a.scrollTop||h.scrollTop,p=Object.assign({},a.style),y=Object.assign({},h.style),a.style.height="100%",a.style.overflow="hidden",h.style.top="-".concat(v,"px"),h.style.width="100%",h.style.height="auto",h.style.position="fixed",h.style.overflow="hidden",function(){a.style.height=p.height||"",a.style.overflow=p.overflow||"",["top","width","height","overflow","position"].forEach(function(e){h.style[e]=y[e]||""}),d?window.scrollTo({top:v,behavior:"instant"}):window.scrollTo(0,v)}):function(){var e=document.body,t=Object.assign({},e.style),o=window.innerWidth-e.clientWidth;return e.style.overflow="hidden",e.style.boxSizing="border-box",e.style.paddingRight="".concat(o,"px"),function(){["overflow","boxSizing","paddingRight"].forEach(function(o){e.style[o]=t[o]||""})}}());var a,h,v,p,y;n+=1}},e.unlock=function(e){if(!(t()||(n-=1)>0))if(o().ios||"function"!=typeof c){if(e)(Array.isArray(e)?e:[e]).forEach(function(e){var t=l.indexOf(e);-1!==t&&(e.ontouchmove=null,e.ontouchstart=null,l.splice(t,1))});s&&(document.removeEventListener("touchmove",f,u),s=!1)}else c()},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
/** | ||
* tua-body-scroll-lock v1.2.2-0 | ||
* (c) 2023 Evinma, BuptStEve | ||
* @license MIT | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).bodyScrollLock={})}(this,(function(t){"use strict";var e=function(){return"undefined"==typeof window},o=function(t){t=t||navigator.userAgent;var e=/(iPad).*OS\s([\d_]+)/.test(t);return{ios:!e&&/(iPhone\sOS)\s([\d_]+)/.test(t)||e,android:/(Android);?[\s/]+([\d.]+)?/.test(t)}};var n=0,i=0,r=0,s=null,c=!1,l=[],u=function(t){if(e())return!1;if(!t)throw new Error("options must be provided");var o=!1,n={get passive(){o=!0}},i=function(){},r="__TUA_BSL_TEST_PASSIVE__";window.addEventListener(r,i,n),window.removeEventListener(r,i,n);var s=t.capture;return o?t:void 0!==s&&s}({passive:!1}),d=!e()&&"scrollBehavior"in document.documentElement.style,f=function(t){t.cancelable&&t.preventDefault()};t.clearBodyLocks=function(){if(!e())if(n=0,o().ios||"function"!=typeof s){if(l.length)for(var t=l.pop();t;)t.ontouchmove=null,t.ontouchstart=null,t=l.pop();c&&(document.removeEventListener("touchmove",f,u),c=!1)}else s()},t.lock=function(t){if(!e()){if(o().ios){if(t)(Array.isArray(t)?t:[t]).forEach((function(t){t&&-1===l.indexOf(t)&&(t.ontouchstart=function(t){i=t.targetTouches[0].clientY,r=t.targetTouches[0].clientX},t.ontouchmove=function(e){1===e.targetTouches.length&&function(t,e){if(e){var o=e.scrollTop,n=e.scrollLeft,s=e.scrollWidth,c=e.scrollHeight,l=e.clientWidth,u=e.clientHeight,d=t.targetTouches[0].clientX-r,a=t.targetTouches[0].clientY-i,h=Math.abs(a)>Math.abs(d);if(h&&(a>0&&0===o||a<0&&o+u+1>=c)||!h&&(d>0&&0===n||d<0&&n+l+1>=s))return f(t)}t.stopPropagation()}(e,t)},l.push(t))}));c||(document.addEventListener("touchmove",f,u),c=!0)}else n<=0&&(s=o().android?(a=document.documentElement,h=document.body,v=a.scrollTop||h.scrollTop,p=Object.assign({},a.style),y=Object.assign({},h.style),a.style.height="100%",a.style.overflow="hidden",h.style.top="-".concat(v,"px"),h.style.width="100%",h.style.height="auto",h.style.position="fixed",h.style.overflow="hidden",function(){a.style.height=p.height||"",a.style.overflow=p.overflow||"",["top","width","height","overflow","position"].forEach((function(t){h.style[t]=y[t]||""}));var t={top:v,behavior:"instant"};d?window.scrollTo(t):window.scrollTo(0,v)}):function(){var t=document.documentElement,e=document.body,o=Object.assign({},t.style),n=Object.assign({},e.style);return[t,e].forEach((function(t){t.style.overflow="hidden",t.style.boxSizing="border-box",t.style.paddingRight="".concat(window.innerWidth-t.clientWidth,"px")})),function(){["overflow","boxSizing","paddingRight"].forEach((function(i){t.style[i]=o[i]||"",e.style[i]=n[i]||""}))}}());var a,h,v,p,y;n+=1}},t.unlock=function(t){if(!(e()||(n-=1)>0))if(o().ios||"function"!=typeof s){if(t)(Array.isArray(t)?t:[t]).forEach((function(t){var e=l.indexOf(t);-1!==e&&(t.ontouchmove=null,t.ontouchstart=null,l.splice(e,1))}));c&&(document.removeEventListener("touchmove",f,u),c=!1)}else s()}})); |
{ | ||
"name": "tua-body-scroll-lock", | ||
"version": "1.2.1", | ||
"version": "1.2.2-0", | ||
"description": "🔐Body scroll locking that just works with everything", | ||
"main": "dist/tua-bsl.umd.js", | ||
"module": "dist/tua-bsl.esm.js", | ||
"unpkg": "dist/tua-bsl.umd.js", | ||
"jsdelivr": "dist/tua-bsl.umd.js", | ||
"module": "dist/tua-bsl.mjs", | ||
"unpkg": "dist/tua-bsl.umd.min.js", | ||
"jsdelivr": "dist/tua-bsl.umd.min.js", | ||
"typings": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "dist/index.d.ts", | ||
"import": "dist/tua-bsl.mjs", | ||
"require": "dist/tua-bsl.umd.js" | ||
} | ||
}, | ||
"scripts": { | ||
"cov": "open coverage/lcov-report/index.html", | ||
"prepare": "is-ci || husky install", | ||
"clean": "rimraf dist/*", | ||
"type-check": "tsc --noEmit", | ||
@@ -17,4 +26,4 @@ "type-check:watch": "npm run type-check -- --watch", | ||
"test": "npm run type-check && cross-env NODE_ENV=test jest", | ||
"test:tdd": "cross-env NODE_ENV=test jest --watch", | ||
"prebuild": "rimraf dist/* & npm test", | ||
"test:unit:tdd": "cross-env NODE_ENV=test jest --watch", | ||
"prebuild": "concurrently npm:clean npm:test", | ||
"build": "npm run lint && cross-env NODE_ENV=production rollup -c && cp index.html dist/index.html", | ||
@@ -34,46 +43,42 @@ "next": "npm --no-git-tag-version version prerelease", | ||
], | ||
"husky": { | ||
"hooks": { | ||
"pre-push": "npm run build", | ||
"pre-commit": "lint-staged", | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS" | ||
} | ||
}, | ||
"lint-staged": { | ||
"{src,test}/**/*.js": [ | ||
"eslint --fix", | ||
"git add" | ||
"{src,test}/**/*.ts": [ | ||
"eslint --fix" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.3.3", | ||
"@babel/preset-env": "^7.3.1", | ||
"@babel/preset-typescript": "^7.3.3", | ||
"@commitlint/cli": "^7.5.2", | ||
"@commitlint/config-conventional": "^7.5.0", | ||
"@types/jest": "^24.0.17", | ||
"@typescript-eslint/eslint-plugin": "^1.13.0", | ||
"@typescript-eslint/parser": "^1.13.0", | ||
"all-contributors-cli": "^6.3.0", | ||
"babel-eslint": "^10.0.1", | ||
"babel-jest": "^24.8.0", | ||
"cross-env": "^5.2.0", | ||
"eslint-config-standard": "^12.0.0", | ||
"eslint-plugin-import": "^2.16.0", | ||
"eslint-plugin-node": "^8.0.1", | ||
"eslint-plugin-promise": "^4.0.1", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"gh-pages": "^2.0.1", | ||
"husky": "^1.3.1", | ||
"jest": "^24.8.0", | ||
"jest-environment-jsdom-thirteen": "^1.0.1", | ||
"lint-staged": "^8.1.4", | ||
"rollup": "^1.2.2", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-eslint": "^5.0.0", | ||
"rollup-plugin-json": "^3.1.0", | ||
"rollup-plugin-replace": "^2.1.0", | ||
"rollup-plugin-terser": "^5.0.0", | ||
"rollup-plugin-typescript2": "^0.22.1", | ||
"typescript": "^3.5.3" | ||
"@babel/core": "^7.22.5", | ||
"@babel/preset-env": "^7.22.5", | ||
"@babel/preset-typescript": "^7.22.5", | ||
"@commitlint/cli": "^17.6.6", | ||
"@commitlint/config-conventional": "^17.6.6", | ||
"@rollup/plugin-babel": "^6.0.3", | ||
"@rollup/plugin-eslint": "^9.0.4", | ||
"@rollup/plugin-replace": "^5.0.2", | ||
"@rollup/plugin-terser": "^0.4.3", | ||
"@types/jest": "^29.5.2", | ||
"@types/node": "^20.3.3", | ||
"@typescript-eslint/eslint-plugin": "^5.60.1", | ||
"@typescript-eslint/parser": "^5.60.1", | ||
"all-contributors-cli": "^6.26.0", | ||
"babel-eslint": "^10.1.0", | ||
"babel-jest": "^29.5.0", | ||
"concurrently": "^8.2.0", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.44.0", | ||
"eslint-config-standard": "^17.1.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-n": "^16.0.1", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"gh-pages": "^5.0.0", | ||
"husky": "^8.0.3", | ||
"is-ci": "^3.0.1", | ||
"jest": "^29.5.0", | ||
"jest-environment-jsdom": "^29.5.0", | ||
"lint-staged": "^13.2.3", | ||
"rimraf": "^5.0.1", | ||
"rollup": "^3.26.0", | ||
"rollup-plugin-typescript2": "^0.35.0", | ||
"typescript": "~5.0" | ||
}, | ||
@@ -80,0 +85,0 @@ "repository": { |
@@ -14,3 +14,3 @@ import { | ||
let initialClientX = 0 | ||
let unLockCallback: any = null | ||
let unLockCallback: null | (() => void) = null | ||
let documentListenerAdded = false | ||
@@ -23,12 +23,16 @@ | ||
const setOverflowHiddenPc = () => { | ||
const $html = document.documentElement | ||
const $body = document.body | ||
const htmlStyle = { ...$html.style } | ||
const bodyStyle = { ...$body.style } | ||
const scrollBarWidth = window.innerWidth - $body.clientWidth | ||
$body.style.overflow = 'hidden' | ||
$body.style.boxSizing = 'border-box' | ||
$body.style.paddingRight = `${scrollBarWidth}px` | ||
;[$html, $body].forEach(element => { | ||
element.style.overflow = 'hidden' | ||
element.style.boxSizing = 'border-box' | ||
element.style.paddingRight = `${window.innerWidth - element.clientWidth}px` | ||
}) | ||
return () => { | ||
;['overflow', 'boxSizing', 'paddingRight'].forEach((x: OverflowHiddenPcStyleType) => { | ||
['overflow', 'boxSizing', 'paddingRight'].forEach((x: OverflowHiddenPcStyleType) => { | ||
$html.style[x] = htmlStyle[x] || '' | ||
$body.style[x] = bodyStyle[x] || '' | ||
@@ -63,8 +67,5 @@ }) | ||
const scrollToOptions = { top: scrollTop, behavior: 'instant' } | ||
supportsNativeSmoothScroll | ||
? window.scrollTo({ | ||
top: scrollTop, | ||
// @ts-ignore | ||
behavior: 'instant', | ||
}) | ||
? window.scrollTo(scrollToOptions as unknown as ScrollToOptions) | ||
: window.scrollTo(0, scrollTop) | ||
@@ -117,4 +118,4 @@ } | ||
console.warn( | ||
`If scrolling is also required in the floating layer, ` + | ||
`the target element must be provided.` | ||
'If scrolling is also required in the floating layer, ' + | ||
'the target element must be provided.', | ||
) | ||
@@ -192,3 +193,2 @@ } | ||
}) | ||
} | ||
@@ -195,0 +195,0 @@ |
@@ -25,3 +25,3 @@ export const isServer = () => typeof window === 'undefined' | ||
isSupportOptions = true | ||
return | ||
return undefined | ||
}, | ||
@@ -31,2 +31,3 @@ } | ||
/* istanbul ignore next */ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
const noop = () => {} | ||
@@ -33,0 +34,0 @@ const testEvent = '__TUA_BSL_TEST_PASSIVE__' |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
55783
14
899
34
2