seamless-scroll-polyfill
Advanced tools
Comparing version 0.5.0 to 0.5.1
(function () { | ||
'use strict'; | ||
var seamless=function(a){function b(){D=!0,m.clearTimeout(p),p=m.setTimeout(c,q);}function c(){D=!1,m.removeEventListener("wheel",b),m.removeEventListener("touchmove",b);}function d(){if(void 0!==arguments[0]){if(!0===x(arguments[0]))return void s.scroll.call(m,void 0===arguments[0].left?"object"==typeof arguments[0]?m.scrollX||m.pageXOffset:arguments[0]:arguments[0].left,void 0===arguments[0].top?void 0===arguments[1]?m.scrollY||m.pageYOffset:arguments[1]:arguments[0].top);var a=arguments[0],b=a.left,c=void 0===b?m.scrollX||m.pageXOffset:b,d=a.top,e=void 0===d?m.scrollY||m.pageYOffset:d;E.call(m,o.body,~~c,~~e);}}function e(){return void 0===arguments[0]?void 0:x(arguments[0])?void s.scrollBy.call(m,void 0===arguments[0].left?"object"==typeof arguments[0]?0:arguments[0]:arguments[0].left,void 0===arguments[0].top?void 0===arguments[1]?0:arguments[1]:arguments[0].top):void E.call(m,o.body,~~arguments[0].left+(m.scrollX||m.pageXOffset),~~arguments[0].top+(m.scrollY||m.pageYOffset))}function f(){if(void 0!==arguments[0]){if(!0===x(arguments[0])){if("number"==typeof arguments[0]&&void 0===arguments[1])throw new SyntaxError("Value could not be converted");return void s.elementScroll.call(this,void 0===arguments[0].left?"object"==typeof arguments[0]?this.scrollLeft:~~arguments[0]:~~arguments[0].left,void 0===arguments[0].top?void 0===arguments[1]?this.scrollTop:~~arguments[1]:~~arguments[0].top)}var a=arguments[0],b=a.left,c=void 0===b?this.scrollLeft:b,d=a.top,e=void 0===d?this.scrollTop:d;E.call(this,this,~~c,~~e);}}function g(){return void 0===arguments[0]?void 0:!0===x(arguments[0])?void s.elementScroll.call(this,void 0===arguments[0].left?~~arguments[0]+this.scrollLeft:~~arguments[0].left+this.scrollLeft,void 0===arguments[0].top?~~arguments[1]+this.scrollTop:~~arguments[0].top+this.scrollTop):void this.scroll({left:~~arguments[0].left+this.scrollLeft,top:~~arguments[0].top+this.scrollTop,behavior:arguments[0].behavior})}var h=void 0===a?{}:a,i=h.force,j=h.duration,k=void 0===j?468:j,l=h.win,m=void 0===l?window:l,n=h.doc,o=void 0===n?document:n;if(!("scrollBehavior"in o.documentElement.style&&!0!==(void 0!==i&&i))){var p,q=~~k,r=function(a,b){this.scrollLeft=a,this.scrollTop=b;},s={scroll:m.scroll||m.scrollTo,scrollBy:m.scrollBy,elementScroll:m.Element.prototype.scroll||r,scrollIntoView:m.Element.prototype.scrollIntoView},t=m.performance&&m.performance.now?m.performance.now.bind(m.performance):Date.now,u=function(a){return new RegExp(["MSIE ","Trident/","Edge/"].join("|")).test(a)},v=u(m.navigator.userAgent)?1:0,w=function(a){return .5*(1-Math.cos(Math.PI*a))},x=function(a){if(null===a||"object"!=typeof a||void 0===a.behavior||"auto"===a.behavior||"instant"===a.behavior)return !0;if("object"==typeof a&&"smooth"===a.behavior)return !1;throw new TypeError("behavior member of ScrollOptions "+a.behavior+" is not a valid value for enumeration ScrollBehavior.")},y=function(a,b){return "Y"===b?a.clientHeight+v<a.scrollHeight:"X"===b&&a.clientWidth+v<a.scrollWidth},z=function(a,b){var c=m.getComputedStyle(a,null)["overflow"+b];return "auto"===c||"scroll"===c},A=function(a){var b=y(a,"Y")&&z(a,"Y"),c=y(a,"X")&&z(a,"X");return b||c},B=function(a){var b=a;do b=b.parentElement;while(b!==o.body&&!1===A(b));return b},C=function(a){if(!D){var b=t(),c=(b-a.startTime)/q;c=1<c?1:c;var d=w(c),e=a.startX+(a.x-a.startX)*d,f=a.startY+(a.y-a.startY)*d;a.method.call(a.scrollable,e,f),(e!==a.x||f!==a.y)&&m.requestAnimationFrame(C.bind(m,a));}},D=!1,E=function(a,c,d){var e,f,g,h,i=t();a===o.body?(e=m,f=m.scrollX||m.pageXOffset,g=m.scrollY||m.pageYOffset,h=s.scroll):(e=a,f=a.scrollLeft,g=a.scrollTop,h=r),m.addEventListener("wheel",b,{passive:!0,once:!0}),m.addEventListener("touchmove",b,{passive:!0,once:!0}),C({scrollable:e,method:h,startTime:i,startX:f,startY:g,x:c,y:d});};m.scroll=m.scrollTo=d,m.scrollBy=e,m.Element.prototype.scroll=m.Element.prototype.scrollTo=f,m.Element.prototype.scrollBy=g;var F=function(a,b,c,d){var e=0===b&&c||1===b&&!c?a.inline:a.block;return "center"===e?1:"nearest"===e?0:"start"===e?0===b?d?5:4:2:"end"===e?0===b?d?4:5:3:c?0===b?0:2:0===b?4:0};m.Element.prototype.scrollIntoView=function(a){if(void 0===a||!0===a||!1===a||!0===x(a))return void s.scrollIntoView.call(this,void 0===a||a);var b=B(this),c=b.getBoundingClientRect(),d=this.getBoundingClientRect(),e=m.getComputedStyle(this).writingMode,f="horizontal-tb"===e,g="vertical-rl"===e,h=F(a,0,f,g),i=F(a,1,f,g),j=0,k=0,l=0,n=0,p=0,q=0;4===h?(j=d.left-c.left,p=c.left,l=d.left):1===h?(j=d.left-c.left+d.width/2-c.width/2,p=(c.left+c.right-m.innerWidth)/2,l=(d.left+d.right-m.innerWidth)/2):5===h?(j=d.right-c.right,p=c.right-m.innerWidth,l=d.right-m.innerWidth):0===h?d.left<c.left&&d.width<c.width||d.right>c.right&&d.width>c.width?(j=d.left-c.left,p=c.left,l=d.left):(d.left<c.left&&d.width>c.width||d.right>c.right&&d.width<c.width)&&(j=d.right-c.right,p=c.right-m.innerWidth,l=d.right-m.innerWidth):void 0,2===i?(k=d.top-c.top,q=c.top,n=d.top):1===i?(k=d.top-c.top+d.height/2-c.height/2,q=(c.top+c.bottom-m.innerHeight)/2,n=(d.top+d.bottom-m.innerHeight)/2):3===i?(k=d.bottom-c.bottom,q=c.bottom-m.innerHeight,n=d.bottom-m.innerHeight):0===i?d.top<c.top&&d.height<c.height||d.bottom>c.bottom&&d.height>c.height?(k=d.top-c.top,q=c.top,n=d.top):(d.top<c.top&&d.height>c.height||d.bottom>c.bottom&&d.height<c.height)&&(k=d.bottom-c.bottom,q=c.bottom-m.innerHeight,n=d.bottom-m.innerHeight):void 0,b===o.body?m.scrollBy({left:l,top:n,behavior:"smooth"}):(E.call(this,b,b.scrollLeft+j,b.scrollTop+k),"fixed"!==m.getComputedStyle(b).position&&m.scrollBy({left:p,top:q,behavior:"smooth"}));};}}; | ||
var seamless=function(a){function b(){D=!0,m.clearTimeout(p),p=m.setTimeout(c,q);}function c(){D=!1,m.removeEventListener("wheel",b),m.removeEventListener("touchmove",b);}function d(a,b){if(void 0!==a){if(!0===x(a))return void s.scroll.call(m,void 0===a.left?"object"==typeof a?m.scrollX||m.pageXOffset:a:a.left,void 0===a.top?void 0===b?m.scrollY||m.pageYOffset:b:a.top);var c=a,d=c.left,e=void 0===d?m.scrollX||m.pageXOffset:d,f=c.top,g=void 0===f?m.scrollY||m.pageYOffset:f;E.call(m,o.body,~~e,~~g);}}function e(a,b){return void 0===a?void 0:x(a)?void s.scrollBy.call(m,void 0===a.left?"object"==typeof a?0:a:a.left,void 0===a.top?void 0===b?0:b:a.top):void E.call(m,o.body,~~a.left+(m.scrollX||m.pageXOffset),~~a.top+(m.scrollY||m.pageYOffset))}function f(a,b){if(void 0!==a){if(!0===x(a)){if("number"==typeof a&&void 0===b)throw new SyntaxError("Value could not be converted");return void s.elementScroll.call(this,void 0===a.left?"object"==typeof a?this.scrollLeft:~~a:~~a.left,void 0===a.top?void 0===b?this.scrollTop:~~b:~~a.top)}var c=a,d=c.left,e=void 0===d?this.scrollLeft:d,f=c.top,g=void 0===f?this.scrollTop:f;E.call(this,this,~~e,~~g);}}function g(a,b){return void 0===a?void 0:!0===x(a)?void s.elementScroll.call(this,void 0===a.left?~~a+this.scrollLeft:~~a.left+this.scrollLeft,void 0===a.top?~~b+this.scrollTop:~~a.top+this.scrollTop):void this.scroll({left:~~a.left+this.scrollLeft,top:~~a.top+this.scrollTop,behavior:a.behavior})}var h=void 0===a?{}:a,i=h.force,j=h.duration,k=void 0===j?468:j,l=h.win,m=void 0===l?window:l,n=h.doc,o=void 0===n?document:n;if(!("scrollBehavior"in o.documentElement.style&&!0!==(void 0!==i&&i))){var p,q=~~k,r=function(a,b){this.scrollLeft=a,this.scrollTop=b;},s={scroll:m.scroll||m.scrollTo,scrollBy:m.scrollBy,elementScroll:m.Element.prototype.scroll||r,scrollIntoView:m.Element.prototype.scrollIntoView},t=m.performance&&m.performance.now?m.performance.now.bind(m.performance):Date.now,u=function(a){return new RegExp(["MSIE ","Trident/","Edge/"].join("|")).test(a)},v=u(m.navigator.userAgent)?1:0,w=function(a){return .5*(1-Math.cos(Math.PI*a))},x=function(a){if(null===a||"object"!=typeof a||void 0===a.behavior||"auto"===a.behavior||"instant"===a.behavior)return !0;if("object"==typeof a&&"smooth"===a.behavior)return !1;throw new TypeError("behavior member of ScrollOptions "+a.behavior+" is not a valid value for enumeration ScrollBehavior.")},y=function(a,b){return "Y"===b?a.clientHeight+v<a.scrollHeight:"X"===b&&a.clientWidth+v<a.scrollWidth},z=function(a,b){var c=m.getComputedStyle(a,null)["overflow"+b];return "auto"===c||"scroll"===c},A=function(a){var b=y(a,"Y")&&z(a,"Y"),c=y(a,"X")&&z(a,"X");return b||c},B=function(a){var b=a;do b=b.parentElement;while(b!==o.body&&!1===A(b));return b},C=function(a){if(!D){var b=t(),c=(b-a.startTime)/q;c=1<c?1:c;var d=w(c),e=a.startX+(a.x-a.startX)*d,f=a.startY+(a.y-a.startY)*d;a.method.call(a.scrollable,e,f),(e!==a.x||f!==a.y)&&m.requestAnimationFrame(C.bind(m,a));}},D=!1,E=function(a,c,d){var e,f,g,h,i=t();a===o.body?(e=m,f=m.scrollX||m.pageXOffset,g=m.scrollY||m.pageYOffset,h=s.scroll):(e=a,f=a.scrollLeft,g=a.scrollTop,h=r),m.addEventListener("wheel",b,{passive:!0,once:!0}),m.addEventListener("touchmove",b,{passive:!0,once:!0}),C({scrollable:e,method:h,startTime:i,startX:f,startY:g,x:c,y:d});};m.scroll=m.scrollTo=d,m.scrollBy=e,m.Element.prototype.scroll=m.Element.prototype.scrollTo=f,m.Element.prototype.scrollBy=g;var F=function(a,b,c,d){var e=0===b&&c||1===b&&!c?a.inline:a.block;return "center"===e?1:"nearest"===e?0:"start"===e?0===b?d?5:4:2:"end"===e?0===b?d?4:5:3:c?0===b?0:2:0===b?4:0};m.Element.prototype.scrollIntoView=function(a){if(void 0===a||!0===a||!1===a||!0===x(a))return void s.scrollIntoView.call(this,void 0===a||a);var b=B(this),c=b.getBoundingClientRect(),d=this.getBoundingClientRect(),e=c.left,f=c.right,g=c.top,h=c.bottom,i=c.height,j=c.width,k=d.left,l=d.right,n=d.top,p=d.bottom,q=d.height,r=d.width,t=m.innerHeight,u=m.innerWidth,v=m.getComputedStyle(this).writingMode,w="horizontal-tb"===v,y="vertical-rl"===v,z=F(a,0,w,y),A=F(a,1,w,y),C=0,D=0,G=0,H=0,I=0,J=0;switch(z){case 4:C=k-e,I=e,G=k;break;case 1:C=k-e+r/2-j/2,I=(e+f-u)/2,G=(k+l-u)/2;break;case 5:C=l-f,I=f-u,G=l-u;break;case 0:{var K=k+C;k<e&&r<j||l>f&&r>j?(C=k-e,K=e):(k<e&&r>j||l>f&&r<j)&&(C=l-f,K=f-r),0>K&&r<u||K+r>u&&r>u?I=K:(0>K&&r>u||K+r>u&&r<u)&&(I=K+r-u),G=C+I;}}switch(A){case 2:D=n-g,J=g,H=n;break;case 1:D=n-g+q/2-i/2,J=(g+h-t)/2,H=(n+p-t)/2;break;case 3:D=p-h,J=h-t,H=p-t;break;case 0:{var K=n+D;n<g&&q<i||p>h&&q>i?(D=n-g,K=g):(n<g&&q>i||p>h&&q<i)&&(D=p-h,K=h-q),0>K&&q<t||K+q>t&&q>t?J=K:(0>K&&q>t||K+q>t&&q<t)&&(J=K+q-t),H=D+J;}}b===o.body?m.scrollBy({left:G,top:H,behavior:"smooth"}):(E.call(this,b,b.scrollLeft+C,b.scrollTop+D),"fixed"!==m.getComputedStyle(b).position&&m.scrollBy({left:I,top:J,behavior:"smooth"}));};}}; | ||
@@ -6,0 +6,0 @@ var currentScript="undefined"!=typeof document&&(document.currentScript||document.querySelector("script[data-seamless]"));if(currentScript){var force=currentScript.dataset.polyfill,duration=~~currentScript.dataset.duration;duration=0<duration?duration:void 0,seamless({force:"force"===force,duration});}else global.seamless=seamless; |
@@ -150,23 +150,23 @@ const seamless = ({ force = false, duration = 468, win = window, doc = document, } = {}) => { | ||
}; | ||
function winScrollTo() { | ||
function winScrollTo(firstArg, secondArg) { | ||
// avoid action when no arguments are passed | ||
if (arguments[0] === undefined) { | ||
if (firstArg === undefined) { | ||
return; | ||
} | ||
// avoid smooth behavior if not required | ||
if (shouldBailOut(arguments[0]) === true) { | ||
original.scroll.call(win, arguments[0].left !== undefined | ||
? arguments[0].left | ||
: typeof arguments[0] !== "object" | ||
? arguments[0] | ||
if (shouldBailOut(firstArg) === true) { | ||
original.scroll.call(win, firstArg.left !== undefined | ||
? firstArg.left | ||
: typeof firstArg !== "object" | ||
? firstArg | ||
: win.scrollX || win.pageXOffset, | ||
// use top prop, second argument if present or fallback to scrollY | ||
arguments[0].top !== undefined | ||
? arguments[0].top | ||
: arguments[1] !== undefined | ||
? arguments[1] | ||
firstArg.top !== undefined | ||
? firstArg.top | ||
: secondArg !== undefined | ||
? secondArg | ||
: win.scrollY || win.pageYOffset); | ||
return; | ||
} | ||
const { left = win.scrollX || win.pageXOffset, top = win.scrollY || win.pageYOffset, } = arguments[0]; | ||
const { left = win.scrollX || win.pageXOffset, top = win.scrollY || win.pageYOffset, } = firstArg; | ||
// LET THE SMOOTHNESS BEGIN! | ||
@@ -176,17 +176,17 @@ seamlessScroll.call(win, doc.body, ~~left, ~~top); | ||
win.scroll = win.scrollTo = winScrollTo; | ||
function winScrollBy() { | ||
function winScrollBy(firstArg, secondArg) { | ||
// avoid action when no arguments are passed | ||
if (arguments[0] === undefined) { | ||
if (firstArg === undefined) { | ||
return; | ||
} | ||
// avoid smooth behavior if not required | ||
if (shouldBailOut(arguments[0])) { | ||
original.scrollBy.call(win, arguments[0].left !== undefined | ||
? arguments[0].left | ||
: typeof arguments[0] !== "object" | ||
? arguments[0] | ||
: 0, arguments[0].top !== undefined | ||
? arguments[0].top | ||
: arguments[1] !== undefined | ||
? arguments[1] | ||
if (shouldBailOut(firstArg)) { | ||
original.scrollBy.call(win, firstArg.left !== undefined | ||
? firstArg.left | ||
: typeof firstArg !== "object" | ||
? firstArg | ||
: 0, firstArg.top !== undefined | ||
? firstArg.top | ||
: secondArg !== undefined | ||
? secondArg | ||
: 0); | ||
@@ -196,14 +196,14 @@ return; | ||
// LET THE SMOOTHNESS BEGIN! | ||
seamlessScroll.call(win, doc.body, ~~arguments[0].left + (win.scrollX || win.pageXOffset), ~~arguments[0].top + (win.scrollY || win.pageYOffset)); | ||
seamlessScroll.call(win, doc.body, ~~firstArg.left + (win.scrollX || win.pageXOffset), ~~firstArg.top + (win.scrollY || win.pageYOffset)); | ||
} | ||
win.scrollBy = winScrollBy; | ||
function eleScrollTo() { | ||
function eleScrollTo(firstArg, secondArg) { | ||
// avoid action when no arguments are passed | ||
if (arguments[0] === undefined) { | ||
if (firstArg === undefined) { | ||
return; | ||
} | ||
// avoid smooth behavior if not required | ||
if (shouldBailOut(arguments[0]) === true) { | ||
if (shouldBailOut(firstArg) === true) { | ||
// if one number is passed, throw error to match Firefox implementation | ||
if (typeof arguments[0] === "number" && arguments[1] === undefined) { | ||
if (typeof firstArg === "number" && secondArg === undefined) { | ||
throw new SyntaxError("Value could not be converted"); | ||
@@ -213,16 +213,16 @@ } | ||
// use left prop, first number argument or fallback to scrollLeft | ||
arguments[0].left !== undefined | ||
? ~~arguments[0].left | ||
: typeof arguments[0] !== "object" | ||
? ~~arguments[0] | ||
firstArg.left !== undefined | ||
? ~~firstArg.left | ||
: typeof firstArg !== "object" | ||
? ~~firstArg | ||
: this.scrollLeft, | ||
// use top prop, second argument or fallback to scrollTop | ||
arguments[0].top !== undefined | ||
? ~~arguments[0].top | ||
: arguments[1] !== undefined | ||
? ~~arguments[1] | ||
firstArg.top !== undefined | ||
? ~~firstArg.top | ||
: secondArg !== undefined | ||
? ~~secondArg | ||
: this.scrollTop); | ||
return; | ||
} | ||
const { left = this.scrollLeft, top = this.scrollTop, } = arguments[0]; | ||
const { left = this.scrollLeft, top = this.scrollTop, } = firstArg; | ||
// LET THE SMOOTHNESS BEGIN! | ||
@@ -232,20 +232,20 @@ seamlessScroll.call(this, this, ~~left, ~~top); | ||
win.Element.prototype.scroll = win.Element.prototype.scrollTo = eleScrollTo; | ||
function eleScrollBy() { | ||
function eleScrollBy(firstArg, secondArg) { | ||
// avoid action when no arguments are passed | ||
if (arguments[0] === undefined) { | ||
if (firstArg === undefined) { | ||
return; | ||
} | ||
// avoid smooth behavior if not required | ||
if (shouldBailOut(arguments[0]) === true) { | ||
original.elementScroll.call(this, arguments[0].left !== undefined | ||
? ~~arguments[0].left + this.scrollLeft | ||
: ~~arguments[0] + this.scrollLeft, arguments[0].top !== undefined | ||
? ~~arguments[0].top + this.scrollTop | ||
: ~~arguments[1] + this.scrollTop); | ||
if (shouldBailOut(firstArg) === true) { | ||
original.elementScroll.call(this, firstArg.left !== undefined | ||
? ~~firstArg.left + this.scrollLeft | ||
: ~~firstArg + this.scrollLeft, firstArg.top !== undefined | ||
? ~~firstArg.top + this.scrollTop | ||
: ~~secondArg + this.scrollTop); | ||
return; | ||
} | ||
this.scroll({ | ||
left: ~~arguments[0].left + this.scrollLeft, | ||
top: ~~arguments[0].top + this.scrollTop, | ||
behavior: arguments[0].behavior, | ||
left: ~~firstArg.left + this.scrollLeft, | ||
top: ~~firstArg.top + this.scrollTop, | ||
behavior: firstArg.behavior, | ||
}); | ||
@@ -305,2 +305,5 @@ } | ||
const clientRects = this.getBoundingClientRect(); | ||
const { left: parentLeft, right: parentRight, top: parentTop, bottom: parentBottom, height: parentHeight, width: parentWidth, } = parentRects; | ||
const { left: clientLeft, right: clientRight, top: clientTop, bottom: clientBottom, height: clientHeight, width: clientWidth, } = clientRects; | ||
const { innerHeight: winInnerHeight, innerWidth: winInnerWidth } = win; | ||
const { writingMode } = win.getComputedStyle(this); | ||
@@ -319,38 +322,40 @@ const isHorizontalWritingMode = writingMode === "horizontal-tb"; | ||
case 4 /* AlignLeftAlways */: | ||
cx = clientRects.left - parentRects.left; | ||
px = parentRects.left; | ||
dx = clientRects.left; | ||
cx = clientLeft - parentLeft; | ||
px = parentLeft; | ||
dx = clientLeft; | ||
break; | ||
case 1 /* AlignCenterAlways */: | ||
cx = | ||
clientRects.left - | ||
parentRects.left + | ||
clientRects.width / 2 - | ||
parentRects.width / 2; | ||
px = (parentRects.left + parentRects.right - win.innerWidth) / 2; | ||
dx = (clientRects.left + clientRects.right - win.innerWidth) / 2; | ||
cx = clientLeft - parentLeft + clientWidth / 2 - parentWidth / 2; | ||
px = (parentLeft + parentRight - winInnerWidth) / 2; | ||
dx = (clientLeft + clientRight - winInnerWidth) / 2; | ||
break; | ||
case 5 /* AlignRightAlways */: | ||
cx = clientRects.right - parentRects.right; | ||
px = parentRects.right - win.innerWidth; | ||
dx = clientRects.right - win.innerWidth; | ||
cx = clientRight - parentRight; | ||
px = parentRight - winInnerWidth; | ||
dx = clientRight - winInnerWidth; | ||
break; | ||
case 0 /* AlignToEdgeIfNeeded */: | ||
{ | ||
if ((clientRects.left < parentRects.left && | ||
clientRects.width < parentRects.width) || | ||
(clientRects.right > parentRects.right && | ||
clientRects.width > parentRects.width)) { | ||
cx = clientRects.left - parentRects.left; | ||
px = parentRects.left; | ||
dx = clientRects.left; | ||
let targetStart = clientLeft + cx; | ||
if ((clientLeft < parentLeft && clientWidth < parentWidth) || | ||
(clientRight > parentRight && clientWidth > parentWidth)) { | ||
cx = clientLeft - parentLeft; | ||
targetStart = parentLeft; | ||
} | ||
else if ((clientRects.left < parentRects.left && | ||
clientRects.width > parentRects.width) || | ||
(clientRects.right > parentRects.right && | ||
clientRects.width < parentRects.width)) { | ||
cx = clientRects.right - parentRects.right; | ||
px = parentRects.right - win.innerWidth; | ||
dx = clientRects.right - win.innerWidth; | ||
else if ((clientLeft < parentLeft && clientWidth > parentWidth) || | ||
(clientRight > parentRight && clientWidth < parentWidth)) { | ||
cx = clientRight - parentRight; | ||
targetStart = parentRight - clientWidth; | ||
} | ||
if ((targetStart < 0 && clientWidth < winInnerWidth) || | ||
(targetStart + clientWidth > winInnerWidth && | ||
clientWidth > winInnerWidth)) { | ||
px = targetStart; | ||
} | ||
else if ((targetStart < 0 && clientWidth > winInnerWidth) || | ||
(targetStart + clientWidth > winInnerWidth && | ||
clientWidth < winInnerWidth)) { | ||
px = targetStart + clientWidth - winInnerWidth; | ||
} | ||
dx = cx + px; | ||
} | ||
@@ -361,38 +366,40 @@ break; | ||
case 2 /* AlignTopAlways */: | ||
cy = clientRects.top - parentRects.top; | ||
py = parentRects.top; | ||
dy = clientRects.top; | ||
cy = clientTop - parentTop; | ||
py = parentTop; | ||
dy = clientTop; | ||
break; | ||
case 1 /* AlignCenterAlways */: | ||
cy = | ||
clientRects.top - | ||
parentRects.top + | ||
clientRects.height / 2 - | ||
parentRects.height / 2; | ||
py = (parentRects.top + parentRects.bottom - win.innerHeight) / 2; | ||
dy = (clientRects.top + clientRects.bottom - win.innerHeight) / 2; | ||
cy = clientTop - parentTop + clientHeight / 2 - parentHeight / 2; | ||
py = (parentTop + parentBottom - winInnerHeight) / 2; | ||
dy = (clientTop + clientBottom - winInnerHeight) / 2; | ||
break; | ||
case 3 /* AlignBottomAlways */: | ||
cy = clientRects.bottom - parentRects.bottom; | ||
py = parentRects.bottom - win.innerHeight; | ||
dy = clientRects.bottom - win.innerHeight; | ||
cy = clientBottom - parentBottom; | ||
py = parentBottom - winInnerHeight; | ||
dy = clientBottom - winInnerHeight; | ||
break; | ||
case 0 /* AlignToEdgeIfNeeded */: | ||
{ | ||
if ((clientRects.top < parentRects.top && | ||
clientRects.height < parentRects.height) || | ||
(clientRects.bottom > parentRects.bottom && | ||
clientRects.height > parentRects.height)) { | ||
cy = clientRects.top - parentRects.top; | ||
py = parentRects.top; | ||
dy = clientRects.top; | ||
let targetStart = clientTop + cy; | ||
if ((clientTop < parentTop && clientHeight < parentHeight) || | ||
(clientBottom > parentBottom && clientHeight > parentHeight)) { | ||
cy = clientTop - parentTop; | ||
targetStart = parentTop; | ||
} | ||
else if ((clientRects.top < parentRects.top && | ||
clientRects.height > parentRects.height) || | ||
(clientRects.bottom > parentRects.bottom && | ||
clientRects.height < parentRects.height)) { | ||
cy = clientRects.bottom - parentRects.bottom; | ||
py = parentRects.bottom - win.innerHeight; | ||
dy = clientRects.bottom - win.innerHeight; | ||
else if ((clientTop < parentTop && clientHeight > parentHeight) || | ||
(clientBottom > parentBottom && clientHeight < parentHeight)) { | ||
cy = clientBottom - parentBottom; | ||
targetStart = parentBottom - clientHeight; | ||
} | ||
if ((targetStart < 0 && clientHeight < winInnerHeight) || | ||
(targetStart + clientHeight > winInnerHeight && | ||
clientHeight > winInnerHeight)) { | ||
py = targetStart; | ||
} | ||
else if ((targetStart < 0 && clientHeight > winInnerHeight) || | ||
(targetStart + clientHeight > winInnerHeight && | ||
clientHeight < winInnerHeight)) { | ||
py = targetStart + clientHeight - winInnerHeight; | ||
} | ||
dy = cy + py; | ||
} | ||
@@ -399,0 +406,0 @@ break; |
@@ -1,4 +0,4 @@ | ||
const seamless=({force:a=!1,duration:b=468,win:c=window,doc:d=document}={})=>{function e(){t=!0,c.clearTimeout(s),s=c.setTimeout(f,g);}function f(){t=!1,c.removeEventListener("wheel",e),c.removeEventListener("touchmove",e);}if("scrollBehavior"in d.documentElement.style&&!0!==a)return;const g=~~b,h=function(a,b){this.scrollLeft=a,this.scrollTop=b;},i={scroll:c.scroll||c.scrollTo,scrollBy:c.scrollBy,elementScroll:c.Element.prototype.scroll||h,scrollIntoView:c.Element.prototype.scrollIntoView},j=c.performance&&c.performance.now?c.performance.now.bind(c.performance):Date.now,k=(a=>{return new RegExp(["MSIE ","Trident/","Edge/"].join("|")).test(a)})(c.navigator.userAgent)?1:0,l=a=>.5*(1-Math.cos(Math.PI*a)),m=a=>{if(null===a||"object"!=typeof a||a.behavior===void 0||"auto"===a.behavior||"instant"===a.behavior)return !0;if("object"==typeof a&&"smooth"===a.behavior)return !1;throw new TypeError("behavior member of ScrollOptions "+a.behavior+" is not a valid value for enumeration ScrollBehavior.")},n=(a,b)=>"Y"===b?a.clientHeight+k<a.scrollHeight:"X"===b&&a.clientWidth+k<a.scrollWidth,o=(a,b)=>{const d=c.getComputedStyle(a,null)["overflow"+b];return "auto"===d||"scroll"===d},p=a=>{const b=n(a,"Y")&&o(a,"Y"),c=n(a,"X")&&o(a,"X");return b||c},q=a=>{let b=a;do b=b.parentElement;while(b!==d.body&&!1===p(b));return b},r=a=>{if(t)return;const b=j();let d=(b-a.startTime)/g;d=1<d?1:d;const e=l(d),f=a.startX+(a.x-a.startX)*e,h=a.startY+(a.y-a.startY)*e;a.method.call(a.scrollable,f,h),(f!==a.x||h!==a.y)&&c.requestAnimationFrame(r.bind(c,a));};let s,t=!1;const u=(a,b,f)=>{let g,k,l,m;const n=j();a===d.body?(g=c,k=c.scrollX||c.pageXOffset,l=c.scrollY||c.pageYOffset,m=i.scroll):(g=a,k=a.scrollLeft,l=a.scrollTop,m=h),c.addEventListener("wheel",e,{passive:!0,once:!0}),c.addEventListener("touchmove",e,{passive:!0,once:!0}),r({scrollable:g,method:m,startTime:n,startX:k,startY:l,x:b,y:f});};c.scroll=c.scrollTo=function(){if(void 0!==arguments[0]){if(!0===m(arguments[0]))return void i.scroll.call(c,void 0===arguments[0].left?"object"==typeof arguments[0]?c.scrollX||c.pageXOffset:arguments[0]:arguments[0].left,void 0===arguments[0].top?void 0===arguments[1]?c.scrollY||c.pageYOffset:arguments[1]:arguments[0].top);const{left:a=c.scrollX||c.pageXOffset,top:b=c.scrollY||c.pageYOffset}=arguments[0];u.call(c,d.body,~~a,~~b);}},c.scrollBy=function(){return void 0===arguments[0]?void 0:m(arguments[0])?void i.scrollBy.call(c,void 0===arguments[0].left?"object"==typeof arguments[0]?0:arguments[0]:arguments[0].left,void 0===arguments[0].top?void 0===arguments[1]?0:arguments[1]:arguments[0].top):void u.call(c,d.body,~~arguments[0].left+(c.scrollX||c.pageXOffset),~~arguments[0].top+(c.scrollY||c.pageYOffset))},c.Element.prototype.scroll=c.Element.prototype.scrollTo=function(){if(void 0!==arguments[0]){if(!0===m(arguments[0])){if("number"==typeof arguments[0]&&void 0===arguments[1])throw new SyntaxError("Value could not be converted");return void i.elementScroll.call(this,void 0===arguments[0].left?"object"==typeof arguments[0]?this.scrollLeft:~~arguments[0]:~~arguments[0].left,void 0===arguments[0].top?void 0===arguments[1]?this.scrollTop:~~arguments[1]:~~arguments[0].top)}const{left:a=this.scrollLeft,top:b=this.scrollTop}=arguments[0];u.call(this,this,~~a,~~b);}},c.Element.prototype.scrollBy=function(){return void 0===arguments[0]?void 0:!0===m(arguments[0])?void i.elementScroll.call(this,void 0===arguments[0].left?~~arguments[0]+this.scrollLeft:~~arguments[0].left+this.scrollLeft,void 0===arguments[0].top?~~arguments[1]+this.scrollTop:~~arguments[0].top+this.scrollTop):void this.scroll({left:~~arguments[0].left+this.scrollLeft,top:~~arguments[0].top+this.scrollTop,behavior:arguments[0].behavior})};const v=(a,b,c,d)=>{const e=0===b&&c||1===b&&!c?a.inline:a.block;return "center"===e?1:"nearest"===e?0:"start"===e?0===b?d?5:4:2:"end"===e?0===b?d?4:5:3:c?0===b?0:2:0===b?4:0};c.Element.prototype.scrollIntoView=function(a){if(void 0===a||!0===a||!1===a||!0===m(a))return void i.scrollIntoView.call(this,void 0===a||a);const b=q(this),e=b.getBoundingClientRect(),f=this.getBoundingClientRect(),{writingMode:g}=c.getComputedStyle(this),h="horizontal-tb"===g,j="vertical-rl"===g,k=v(a,0,h,j),l=v(a,1,h,j);let n=0,o=0,p=0,r=0,s=0,t=0;4===k?(n=f.left-e.left,s=e.left,p=f.left):1===k?(n=f.left-e.left+f.width/2-e.width/2,s=(e.left+e.right-c.innerWidth)/2,p=(f.left+f.right-c.innerWidth)/2):5===k?(n=f.right-e.right,s=e.right-c.innerWidth,p=f.right-c.innerWidth):0===k?f.left<e.left&&f.width<e.width||f.right>e.right&&f.width>e.width?(n=f.left-e.left,s=e.left,p=f.left):(f.left<e.left&&f.width>e.width||f.right>e.right&&f.width<e.width)&&(n=f.right-e.right,s=e.right-c.innerWidth,p=f.right-c.innerWidth):void 0;2===l?(o=f.top-e.top,t=e.top,r=f.top):1===l?(o=f.top-e.top+f.height/2-e.height/2,t=(e.top+e.bottom-c.innerHeight)/2,r=(f.top+f.bottom-c.innerHeight)/2):3===l?(o=f.bottom-e.bottom,t=e.bottom-c.innerHeight,r=f.bottom-c.innerHeight):0===l?f.top<e.top&&f.height<e.height||f.bottom>e.bottom&&f.height>e.height?(o=f.top-e.top,t=e.top,r=f.top):(f.top<e.top&&f.height>e.height||f.bottom>e.bottom&&f.height<e.height)&&(o=f.bottom-e.bottom,t=e.bottom-c.innerHeight,r=f.bottom-c.innerHeight):void 0;b===d.body?c.scrollBy({left:p,top:r,behavior:"smooth"}):(u.call(this,b,b.scrollLeft+n,b.scrollTop+o),"fixed"!==c.getComputedStyle(b).position&&c.scrollBy({left:s,top:t,behavior:"smooth"}));};}; | ||
const seamless=({force:a=!1,duration:b=468,win:c=window,doc:d=document}={})=>{function e(){t=!0,c.clearTimeout(s),s=c.setTimeout(f,g);}function f(){t=!1,c.removeEventListener("wheel",e),c.removeEventListener("touchmove",e);}if("scrollBehavior"in d.documentElement.style&&!0!==a)return;const g=~~b,h=function(a,b){this.scrollLeft=a,this.scrollTop=b;},i={scroll:c.scroll||c.scrollTo,scrollBy:c.scrollBy,elementScroll:c.Element.prototype.scroll||h,scrollIntoView:c.Element.prototype.scrollIntoView},j=c.performance&&c.performance.now?c.performance.now.bind(c.performance):Date.now,k=(a=>{return new RegExp(["MSIE ","Trident/","Edge/"].join("|")).test(a)})(c.navigator.userAgent)?1:0,l=a=>.5*(1-Math.cos(Math.PI*a)),m=a=>{if(null===a||"object"!=typeof a||a.behavior===void 0||"auto"===a.behavior||"instant"===a.behavior)return !0;if("object"==typeof a&&"smooth"===a.behavior)return !1;throw new TypeError("behavior member of ScrollOptions "+a.behavior+" is not a valid value for enumeration ScrollBehavior.")},n=(a,b)=>"Y"===b?a.clientHeight+k<a.scrollHeight:"X"===b&&a.clientWidth+k<a.scrollWidth,o=(a,b)=>{const d=c.getComputedStyle(a,null)["overflow"+b];return "auto"===d||"scroll"===d},p=a=>{const b=n(a,"Y")&&o(a,"Y"),c=n(a,"X")&&o(a,"X");return b||c},q=a=>{let b=a;do b=b.parentElement;while(b!==d.body&&!1===p(b));return b},r=a=>{if(t)return;const b=j();let d=(b-a.startTime)/g;d=1<d?1:d;const e=l(d),f=a.startX+(a.x-a.startX)*e,h=a.startY+(a.y-a.startY)*e;a.method.call(a.scrollable,f,h),(f!==a.x||h!==a.y)&&c.requestAnimationFrame(r.bind(c,a));};let s,t=!1;const u=(a,b,f)=>{let g,k,l,m;const n=j();a===d.body?(g=c,k=c.scrollX||c.pageXOffset,l=c.scrollY||c.pageYOffset,m=i.scroll):(g=a,k=a.scrollLeft,l=a.scrollTop,m=h),c.addEventListener("wheel",e,{passive:!0,once:!0}),c.addEventListener("touchmove",e,{passive:!0,once:!0}),r({scrollable:g,method:m,startTime:n,startX:k,startY:l,x:b,y:f});};c.scroll=c.scrollTo=function(a,b){if(void 0!==a){if(!0===m(a))return void i.scroll.call(c,void 0===a.left?"object"==typeof a?c.scrollX||c.pageXOffset:a:a.left,void 0===a.top?void 0===b?c.scrollY||c.pageYOffset:b:a.top);const{left:e=c.scrollX||c.pageXOffset,top:f=c.scrollY||c.pageYOffset}=a;u.call(c,d.body,~~e,~~f);}},c.scrollBy=function(a,b){return void 0===a?void 0:m(a)?void i.scrollBy.call(c,void 0===a.left?"object"==typeof a?0:a:a.left,void 0===a.top?void 0===b?0:b:a.top):void u.call(c,d.body,~~a.left+(c.scrollX||c.pageXOffset),~~a.top+(c.scrollY||c.pageYOffset))},c.Element.prototype.scroll=c.Element.prototype.scrollTo=function(a,b){if(void 0!==a){if(!0===m(a)){if("number"==typeof a&&void 0===b)throw new SyntaxError("Value could not be converted");return void i.elementScroll.call(this,void 0===a.left?"object"==typeof a?this.scrollLeft:~~a:~~a.left,void 0===a.top?void 0===b?this.scrollTop:~~b:~~a.top)}const{left:c=this.scrollLeft,top:d=this.scrollTop}=a;u.call(this,this,~~c,~~d);}},c.Element.prototype.scrollBy=function(a,b){return void 0===a?void 0:!0===m(a)?void i.elementScroll.call(this,void 0===a.left?~~a+this.scrollLeft:~~a.left+this.scrollLeft,void 0===a.top?~~b+this.scrollTop:~~a.top+this.scrollTop):void this.scroll({left:~~a.left+this.scrollLeft,top:~~a.top+this.scrollTop,behavior:a.behavior})};const v=(a,b,c,d)=>{const e=0===b&&c||1===b&&!c?a.inline:a.block;return "center"===e?1:"nearest"===e?0:"start"===e?0===b?d?5:4:2:"end"===e?0===b?d?4:5:3:c?0===b?0:2:0===b?4:0};c.Element.prototype.scrollIntoView=function(a){if(void 0===a||!0===a||!1===a||!0===m(a))return void i.scrollIntoView.call(this,void 0===a||a);const b=q(this),e=b.getBoundingClientRect(),f=this.getBoundingClientRect(),{left:g,right:h,top:j,bottom:k,height:l,width:n}=e,{left:o,right:p,top:r,bottom:s,height:t,width:w}=f,{innerHeight:x,innerWidth:y}=c,{writingMode:z}=c.getComputedStyle(this),A="horizontal-tb"===z,B="vertical-rl"===z,C=v(a,0,A,B),D=v(a,1,A,B);let E=0,F=0,G=0,H=0,I=0,J=0;switch(C){case 4:E=o-g,I=g,G=o;break;case 1:E=o-g+w/2-n/2,I=(g+h-y)/2,G=(o+p-y)/2;break;case 5:E=p-h,I=h-y,G=p-y;break;case 0:{let a=o+E;o<g&&w<n||p>h&&w>n?(E=o-g,a=g):(o<g&&w>n||p>h&&w<n)&&(E=p-h,a=h-w),0>a&&w<y||a+w>y&&w>y?I=a:(0>a&&w>y||a+w>y&&w<y)&&(I=a+w-y),G=E+I;}}switch(D){case 2:F=r-j,J=j,H=r;break;case 1:F=r-j+t/2-l/2,J=(j+k-x)/2,H=(r+s-x)/2;break;case 3:F=s-k,J=k-x,H=s-x;break;case 0:{let a=r+F;r<j&&t<l||s>k&&t>l?(F=r-j,a=j):(r<j&&t>l||s>k&&t<l)&&(F=s-k,a=k-t),0>a&&t<x||a+t>x&&t>x?J=a:(0>a&&t>x||a+t>x&&t<x)&&(J=a+t-x),H=F+J;}}b===d.body?c.scrollBy({left:G,top:H,behavior:"smooth"}):(u.call(this,b,b.scrollLeft+E,b.scrollTop+F),"fixed"!==c.getComputedStyle(b).position&&c.scrollBy({left:I,top:J,behavior:"smooth"}));};}; | ||
export { seamless }; | ||
//# sourceMappingURL=seamless.esm.min.js.map |
@@ -156,23 +156,23 @@ (function (global, factory) { | ||
}; | ||
function winScrollTo() { | ||
function winScrollTo(firstArg, secondArg) { | ||
// avoid action when no arguments are passed | ||
if (arguments[0] === undefined) { | ||
if (firstArg === undefined) { | ||
return; | ||
} | ||
// avoid smooth behavior if not required | ||
if (shouldBailOut(arguments[0]) === true) { | ||
original.scroll.call(win, arguments[0].left !== undefined | ||
? arguments[0].left | ||
: typeof arguments[0] !== "object" | ||
? arguments[0] | ||
if (shouldBailOut(firstArg) === true) { | ||
original.scroll.call(win, firstArg.left !== undefined | ||
? firstArg.left | ||
: typeof firstArg !== "object" | ||
? firstArg | ||
: win.scrollX || win.pageXOffset, | ||
// use top prop, second argument if present or fallback to scrollY | ||
arguments[0].top !== undefined | ||
? arguments[0].top | ||
: arguments[1] !== undefined | ||
? arguments[1] | ||
firstArg.top !== undefined | ||
? firstArg.top | ||
: secondArg !== undefined | ||
? secondArg | ||
: win.scrollY || win.pageYOffset); | ||
return; | ||
} | ||
const { left = win.scrollX || win.pageXOffset, top = win.scrollY || win.pageYOffset, } = arguments[0]; | ||
const { left = win.scrollX || win.pageXOffset, top = win.scrollY || win.pageYOffset, } = firstArg; | ||
// LET THE SMOOTHNESS BEGIN! | ||
@@ -182,17 +182,17 @@ seamlessScroll.call(win, doc.body, ~~left, ~~top); | ||
win.scroll = win.scrollTo = winScrollTo; | ||
function winScrollBy() { | ||
function winScrollBy(firstArg, secondArg) { | ||
// avoid action when no arguments are passed | ||
if (arguments[0] === undefined) { | ||
if (firstArg === undefined) { | ||
return; | ||
} | ||
// avoid smooth behavior if not required | ||
if (shouldBailOut(arguments[0])) { | ||
original.scrollBy.call(win, arguments[0].left !== undefined | ||
? arguments[0].left | ||
: typeof arguments[0] !== "object" | ||
? arguments[0] | ||
: 0, arguments[0].top !== undefined | ||
? arguments[0].top | ||
: arguments[1] !== undefined | ||
? arguments[1] | ||
if (shouldBailOut(firstArg)) { | ||
original.scrollBy.call(win, firstArg.left !== undefined | ||
? firstArg.left | ||
: typeof firstArg !== "object" | ||
? firstArg | ||
: 0, firstArg.top !== undefined | ||
? firstArg.top | ||
: secondArg !== undefined | ||
? secondArg | ||
: 0); | ||
@@ -202,14 +202,14 @@ return; | ||
// LET THE SMOOTHNESS BEGIN! | ||
seamlessScroll.call(win, doc.body, ~~arguments[0].left + (win.scrollX || win.pageXOffset), ~~arguments[0].top + (win.scrollY || win.pageYOffset)); | ||
seamlessScroll.call(win, doc.body, ~~firstArg.left + (win.scrollX || win.pageXOffset), ~~firstArg.top + (win.scrollY || win.pageYOffset)); | ||
} | ||
win.scrollBy = winScrollBy; | ||
function eleScrollTo() { | ||
function eleScrollTo(firstArg, secondArg) { | ||
// avoid action when no arguments are passed | ||
if (arguments[0] === undefined) { | ||
if (firstArg === undefined) { | ||
return; | ||
} | ||
// avoid smooth behavior if not required | ||
if (shouldBailOut(arguments[0]) === true) { | ||
if (shouldBailOut(firstArg) === true) { | ||
// if one number is passed, throw error to match Firefox implementation | ||
if (typeof arguments[0] === "number" && arguments[1] === undefined) { | ||
if (typeof firstArg === "number" && secondArg === undefined) { | ||
throw new SyntaxError("Value could not be converted"); | ||
@@ -219,16 +219,16 @@ } | ||
// use left prop, first number argument or fallback to scrollLeft | ||
arguments[0].left !== undefined | ||
? ~~arguments[0].left | ||
: typeof arguments[0] !== "object" | ||
? ~~arguments[0] | ||
firstArg.left !== undefined | ||
? ~~firstArg.left | ||
: typeof firstArg !== "object" | ||
? ~~firstArg | ||
: this.scrollLeft, | ||
// use top prop, second argument or fallback to scrollTop | ||
arguments[0].top !== undefined | ||
? ~~arguments[0].top | ||
: arguments[1] !== undefined | ||
? ~~arguments[1] | ||
firstArg.top !== undefined | ||
? ~~firstArg.top | ||
: secondArg !== undefined | ||
? ~~secondArg | ||
: this.scrollTop); | ||
return; | ||
} | ||
const { left = this.scrollLeft, top = this.scrollTop, } = arguments[0]; | ||
const { left = this.scrollLeft, top = this.scrollTop, } = firstArg; | ||
// LET THE SMOOTHNESS BEGIN! | ||
@@ -238,20 +238,20 @@ seamlessScroll.call(this, this, ~~left, ~~top); | ||
win.Element.prototype.scroll = win.Element.prototype.scrollTo = eleScrollTo; | ||
function eleScrollBy() { | ||
function eleScrollBy(firstArg, secondArg) { | ||
// avoid action when no arguments are passed | ||
if (arguments[0] === undefined) { | ||
if (firstArg === undefined) { | ||
return; | ||
} | ||
// avoid smooth behavior if not required | ||
if (shouldBailOut(arguments[0]) === true) { | ||
original.elementScroll.call(this, arguments[0].left !== undefined | ||
? ~~arguments[0].left + this.scrollLeft | ||
: ~~arguments[0] + this.scrollLeft, arguments[0].top !== undefined | ||
? ~~arguments[0].top + this.scrollTop | ||
: ~~arguments[1] + this.scrollTop); | ||
if (shouldBailOut(firstArg) === true) { | ||
original.elementScroll.call(this, firstArg.left !== undefined | ||
? ~~firstArg.left + this.scrollLeft | ||
: ~~firstArg + this.scrollLeft, firstArg.top !== undefined | ||
? ~~firstArg.top + this.scrollTop | ||
: ~~secondArg + this.scrollTop); | ||
return; | ||
} | ||
this.scroll({ | ||
left: ~~arguments[0].left + this.scrollLeft, | ||
top: ~~arguments[0].top + this.scrollTop, | ||
behavior: arguments[0].behavior, | ||
left: ~~firstArg.left + this.scrollLeft, | ||
top: ~~firstArg.top + this.scrollTop, | ||
behavior: firstArg.behavior, | ||
}); | ||
@@ -311,2 +311,5 @@ } | ||
const clientRects = this.getBoundingClientRect(); | ||
const { left: parentLeft, right: parentRight, top: parentTop, bottom: parentBottom, height: parentHeight, width: parentWidth, } = parentRects; | ||
const { left: clientLeft, right: clientRight, top: clientTop, bottom: clientBottom, height: clientHeight, width: clientWidth, } = clientRects; | ||
const { innerHeight: winInnerHeight, innerWidth: winInnerWidth } = win; | ||
const { writingMode } = win.getComputedStyle(this); | ||
@@ -325,38 +328,40 @@ const isHorizontalWritingMode = writingMode === "horizontal-tb"; | ||
case 4 /* AlignLeftAlways */: | ||
cx = clientRects.left - parentRects.left; | ||
px = parentRects.left; | ||
dx = clientRects.left; | ||
cx = clientLeft - parentLeft; | ||
px = parentLeft; | ||
dx = clientLeft; | ||
break; | ||
case 1 /* AlignCenterAlways */: | ||
cx = | ||
clientRects.left - | ||
parentRects.left + | ||
clientRects.width / 2 - | ||
parentRects.width / 2; | ||
px = (parentRects.left + parentRects.right - win.innerWidth) / 2; | ||
dx = (clientRects.left + clientRects.right - win.innerWidth) / 2; | ||
cx = clientLeft - parentLeft + clientWidth / 2 - parentWidth / 2; | ||
px = (parentLeft + parentRight - winInnerWidth) / 2; | ||
dx = (clientLeft + clientRight - winInnerWidth) / 2; | ||
break; | ||
case 5 /* AlignRightAlways */: | ||
cx = clientRects.right - parentRects.right; | ||
px = parentRects.right - win.innerWidth; | ||
dx = clientRects.right - win.innerWidth; | ||
cx = clientRight - parentRight; | ||
px = parentRight - winInnerWidth; | ||
dx = clientRight - winInnerWidth; | ||
break; | ||
case 0 /* AlignToEdgeIfNeeded */: | ||
{ | ||
if ((clientRects.left < parentRects.left && | ||
clientRects.width < parentRects.width) || | ||
(clientRects.right > parentRects.right && | ||
clientRects.width > parentRects.width)) { | ||
cx = clientRects.left - parentRects.left; | ||
px = parentRects.left; | ||
dx = clientRects.left; | ||
let targetStart = clientLeft + cx; | ||
if ((clientLeft < parentLeft && clientWidth < parentWidth) || | ||
(clientRight > parentRight && clientWidth > parentWidth)) { | ||
cx = clientLeft - parentLeft; | ||
targetStart = parentLeft; | ||
} | ||
else if ((clientRects.left < parentRects.left && | ||
clientRects.width > parentRects.width) || | ||
(clientRects.right > parentRects.right && | ||
clientRects.width < parentRects.width)) { | ||
cx = clientRects.right - parentRects.right; | ||
px = parentRects.right - win.innerWidth; | ||
dx = clientRects.right - win.innerWidth; | ||
else if ((clientLeft < parentLeft && clientWidth > parentWidth) || | ||
(clientRight > parentRight && clientWidth < parentWidth)) { | ||
cx = clientRight - parentRight; | ||
targetStart = parentRight - clientWidth; | ||
} | ||
if ((targetStart < 0 && clientWidth < winInnerWidth) || | ||
(targetStart + clientWidth > winInnerWidth && | ||
clientWidth > winInnerWidth)) { | ||
px = targetStart; | ||
} | ||
else if ((targetStart < 0 && clientWidth > winInnerWidth) || | ||
(targetStart + clientWidth > winInnerWidth && | ||
clientWidth < winInnerWidth)) { | ||
px = targetStart + clientWidth - winInnerWidth; | ||
} | ||
dx = cx + px; | ||
} | ||
@@ -367,38 +372,40 @@ break; | ||
case 2 /* AlignTopAlways */: | ||
cy = clientRects.top - parentRects.top; | ||
py = parentRects.top; | ||
dy = clientRects.top; | ||
cy = clientTop - parentTop; | ||
py = parentTop; | ||
dy = clientTop; | ||
break; | ||
case 1 /* AlignCenterAlways */: | ||
cy = | ||
clientRects.top - | ||
parentRects.top + | ||
clientRects.height / 2 - | ||
parentRects.height / 2; | ||
py = (parentRects.top + parentRects.bottom - win.innerHeight) / 2; | ||
dy = (clientRects.top + clientRects.bottom - win.innerHeight) / 2; | ||
cy = clientTop - parentTop + clientHeight / 2 - parentHeight / 2; | ||
py = (parentTop + parentBottom - winInnerHeight) / 2; | ||
dy = (clientTop + clientBottom - winInnerHeight) / 2; | ||
break; | ||
case 3 /* AlignBottomAlways */: | ||
cy = clientRects.bottom - parentRects.bottom; | ||
py = parentRects.bottom - win.innerHeight; | ||
dy = clientRects.bottom - win.innerHeight; | ||
cy = clientBottom - parentBottom; | ||
py = parentBottom - winInnerHeight; | ||
dy = clientBottom - winInnerHeight; | ||
break; | ||
case 0 /* AlignToEdgeIfNeeded */: | ||
{ | ||
if ((clientRects.top < parentRects.top && | ||
clientRects.height < parentRects.height) || | ||
(clientRects.bottom > parentRects.bottom && | ||
clientRects.height > parentRects.height)) { | ||
cy = clientRects.top - parentRects.top; | ||
py = parentRects.top; | ||
dy = clientRects.top; | ||
let targetStart = clientTop + cy; | ||
if ((clientTop < parentTop && clientHeight < parentHeight) || | ||
(clientBottom > parentBottom && clientHeight > parentHeight)) { | ||
cy = clientTop - parentTop; | ||
targetStart = parentTop; | ||
} | ||
else if ((clientRects.top < parentRects.top && | ||
clientRects.height > parentRects.height) || | ||
(clientRects.bottom > parentRects.bottom && | ||
clientRects.height < parentRects.height)) { | ||
cy = clientRects.bottom - parentRects.bottom; | ||
py = parentRects.bottom - win.innerHeight; | ||
dy = clientRects.bottom - win.innerHeight; | ||
else if ((clientTop < parentTop && clientHeight > parentHeight) || | ||
(clientBottom > parentBottom && clientHeight < parentHeight)) { | ||
cy = clientBottom - parentBottom; | ||
targetStart = parentBottom - clientHeight; | ||
} | ||
if ((targetStart < 0 && clientHeight < winInnerHeight) || | ||
(targetStart + clientHeight > winInnerHeight && | ||
clientHeight > winInnerHeight)) { | ||
py = targetStart; | ||
} | ||
else if ((targetStart < 0 && clientHeight > winInnerHeight) || | ||
(targetStart + clientHeight > winInnerHeight && | ||
clientHeight < winInnerHeight)) { | ||
py = targetStart + clientHeight - winInnerHeight; | ||
} | ||
dy = cy + py; | ||
} | ||
@@ -405,0 +412,0 @@ break; |
@@ -7,3 +7,3 @@ (function (global, factory) { | ||
const seamless=({force:a=!1,duration:b=468,win:c=window,doc:d=document}={})=>{function e(){t=!0,c.clearTimeout(s),s=c.setTimeout(f,g);}function f(){t=!1,c.removeEventListener("wheel",e),c.removeEventListener("touchmove",e);}if("scrollBehavior"in d.documentElement.style&&!0!==a)return;const g=~~b,h=function(a,b){this.scrollLeft=a,this.scrollTop=b;},i={scroll:c.scroll||c.scrollTo,scrollBy:c.scrollBy,elementScroll:c.Element.prototype.scroll||h,scrollIntoView:c.Element.prototype.scrollIntoView},j=c.performance&&c.performance.now?c.performance.now.bind(c.performance):Date.now,k=(a=>{return new RegExp(["MSIE ","Trident/","Edge/"].join("|")).test(a)})(c.navigator.userAgent)?1:0,l=a=>.5*(1-Math.cos(Math.PI*a)),m=a=>{if(null===a||"object"!=typeof a||a.behavior===void 0||"auto"===a.behavior||"instant"===a.behavior)return !0;if("object"==typeof a&&"smooth"===a.behavior)return !1;throw new TypeError("behavior member of ScrollOptions "+a.behavior+" is not a valid value for enumeration ScrollBehavior.")},n=(a,b)=>"Y"===b?a.clientHeight+k<a.scrollHeight:"X"===b&&a.clientWidth+k<a.scrollWidth,o=(a,b)=>{const d=c.getComputedStyle(a,null)["overflow"+b];return "auto"===d||"scroll"===d},p=a=>{const b=n(a,"Y")&&o(a,"Y"),c=n(a,"X")&&o(a,"X");return b||c},q=a=>{let b=a;do b=b.parentElement;while(b!==d.body&&!1===p(b));return b},r=a=>{if(t)return;const b=j();let d=(b-a.startTime)/g;d=1<d?1:d;const e=l(d),f=a.startX+(a.x-a.startX)*e,h=a.startY+(a.y-a.startY)*e;a.method.call(a.scrollable,f,h),(f!==a.x||h!==a.y)&&c.requestAnimationFrame(r.bind(c,a));};let s,t=!1;const u=(a,b,f)=>{let g,k,l,m;const n=j();a===d.body?(g=c,k=c.scrollX||c.pageXOffset,l=c.scrollY||c.pageYOffset,m=i.scroll):(g=a,k=a.scrollLeft,l=a.scrollTop,m=h),c.addEventListener("wheel",e,{passive:!0,once:!0}),c.addEventListener("touchmove",e,{passive:!0,once:!0}),r({scrollable:g,method:m,startTime:n,startX:k,startY:l,x:b,y:f});};c.scroll=c.scrollTo=function(){if(void 0!==arguments[0]){if(!0===m(arguments[0]))return void i.scroll.call(c,void 0===arguments[0].left?"object"==typeof arguments[0]?c.scrollX||c.pageXOffset:arguments[0]:arguments[0].left,void 0===arguments[0].top?void 0===arguments[1]?c.scrollY||c.pageYOffset:arguments[1]:arguments[0].top);const{left:a=c.scrollX||c.pageXOffset,top:b=c.scrollY||c.pageYOffset}=arguments[0];u.call(c,d.body,~~a,~~b);}},c.scrollBy=function(){return void 0===arguments[0]?void 0:m(arguments[0])?void i.scrollBy.call(c,void 0===arguments[0].left?"object"==typeof arguments[0]?0:arguments[0]:arguments[0].left,void 0===arguments[0].top?void 0===arguments[1]?0:arguments[1]:arguments[0].top):void u.call(c,d.body,~~arguments[0].left+(c.scrollX||c.pageXOffset),~~arguments[0].top+(c.scrollY||c.pageYOffset))},c.Element.prototype.scroll=c.Element.prototype.scrollTo=function(){if(void 0!==arguments[0]){if(!0===m(arguments[0])){if("number"==typeof arguments[0]&&void 0===arguments[1])throw new SyntaxError("Value could not be converted");return void i.elementScroll.call(this,void 0===arguments[0].left?"object"==typeof arguments[0]?this.scrollLeft:~~arguments[0]:~~arguments[0].left,void 0===arguments[0].top?void 0===arguments[1]?this.scrollTop:~~arguments[1]:~~arguments[0].top)}const{left:a=this.scrollLeft,top:b=this.scrollTop}=arguments[0];u.call(this,this,~~a,~~b);}},c.Element.prototype.scrollBy=function(){return void 0===arguments[0]?void 0:!0===m(arguments[0])?void i.elementScroll.call(this,void 0===arguments[0].left?~~arguments[0]+this.scrollLeft:~~arguments[0].left+this.scrollLeft,void 0===arguments[0].top?~~arguments[1]+this.scrollTop:~~arguments[0].top+this.scrollTop):void this.scroll({left:~~arguments[0].left+this.scrollLeft,top:~~arguments[0].top+this.scrollTop,behavior:arguments[0].behavior})};const v=(a,b,c,d)=>{const e=0===b&&c||1===b&&!c?a.inline:a.block;return "center"===e?1:"nearest"===e?0:"start"===e?0===b?d?5:4:2:"end"===e?0===b?d?4:5:3:c?0===b?0:2:0===b?4:0};c.Element.prototype.scrollIntoView=function(a){if(void 0===a||!0===a||!1===a||!0===m(a))return void i.scrollIntoView.call(this,void 0===a||a);const b=q(this),e=b.getBoundingClientRect(),f=this.getBoundingClientRect(),{writingMode:g}=c.getComputedStyle(this),h="horizontal-tb"===g,j="vertical-rl"===g,k=v(a,0,h,j),l=v(a,1,h,j);let n=0,o=0,p=0,r=0,s=0,t=0;4===k?(n=f.left-e.left,s=e.left,p=f.left):1===k?(n=f.left-e.left+f.width/2-e.width/2,s=(e.left+e.right-c.innerWidth)/2,p=(f.left+f.right-c.innerWidth)/2):5===k?(n=f.right-e.right,s=e.right-c.innerWidth,p=f.right-c.innerWidth):0===k?f.left<e.left&&f.width<e.width||f.right>e.right&&f.width>e.width?(n=f.left-e.left,s=e.left,p=f.left):(f.left<e.left&&f.width>e.width||f.right>e.right&&f.width<e.width)&&(n=f.right-e.right,s=e.right-c.innerWidth,p=f.right-c.innerWidth):void 0;2===l?(o=f.top-e.top,t=e.top,r=f.top):1===l?(o=f.top-e.top+f.height/2-e.height/2,t=(e.top+e.bottom-c.innerHeight)/2,r=(f.top+f.bottom-c.innerHeight)/2):3===l?(o=f.bottom-e.bottom,t=e.bottom-c.innerHeight,r=f.bottom-c.innerHeight):0===l?f.top<e.top&&f.height<e.height||f.bottom>e.bottom&&f.height>e.height?(o=f.top-e.top,t=e.top,r=f.top):(f.top<e.top&&f.height>e.height||f.bottom>e.bottom&&f.height<e.height)&&(o=f.bottom-e.bottom,t=e.bottom-c.innerHeight,r=f.bottom-c.innerHeight):void 0;b===d.body?c.scrollBy({left:p,top:r,behavior:"smooth"}):(u.call(this,b,b.scrollLeft+n,b.scrollTop+o),"fixed"!==c.getComputedStyle(b).position&&c.scrollBy({left:s,top:t,behavior:"smooth"}));};}; | ||
const seamless=({force:a=!1,duration:b=468,win:c=window,doc:d=document}={})=>{function e(){t=!0,c.clearTimeout(s),s=c.setTimeout(f,g);}function f(){t=!1,c.removeEventListener("wheel",e),c.removeEventListener("touchmove",e);}if("scrollBehavior"in d.documentElement.style&&!0!==a)return;const g=~~b,h=function(a,b){this.scrollLeft=a,this.scrollTop=b;},i={scroll:c.scroll||c.scrollTo,scrollBy:c.scrollBy,elementScroll:c.Element.prototype.scroll||h,scrollIntoView:c.Element.prototype.scrollIntoView},j=c.performance&&c.performance.now?c.performance.now.bind(c.performance):Date.now,k=(a=>{return new RegExp(["MSIE ","Trident/","Edge/"].join("|")).test(a)})(c.navigator.userAgent)?1:0,l=a=>.5*(1-Math.cos(Math.PI*a)),m=a=>{if(null===a||"object"!=typeof a||a.behavior===void 0||"auto"===a.behavior||"instant"===a.behavior)return !0;if("object"==typeof a&&"smooth"===a.behavior)return !1;throw new TypeError("behavior member of ScrollOptions "+a.behavior+" is not a valid value for enumeration ScrollBehavior.")},n=(a,b)=>"Y"===b?a.clientHeight+k<a.scrollHeight:"X"===b&&a.clientWidth+k<a.scrollWidth,o=(a,b)=>{const d=c.getComputedStyle(a,null)["overflow"+b];return "auto"===d||"scroll"===d},p=a=>{const b=n(a,"Y")&&o(a,"Y"),c=n(a,"X")&&o(a,"X");return b||c},q=a=>{let b=a;do b=b.parentElement;while(b!==d.body&&!1===p(b));return b},r=a=>{if(t)return;const b=j();let d=(b-a.startTime)/g;d=1<d?1:d;const e=l(d),f=a.startX+(a.x-a.startX)*e,h=a.startY+(a.y-a.startY)*e;a.method.call(a.scrollable,f,h),(f!==a.x||h!==a.y)&&c.requestAnimationFrame(r.bind(c,a));};let s,t=!1;const u=(a,b,f)=>{let g,k,l,m;const n=j();a===d.body?(g=c,k=c.scrollX||c.pageXOffset,l=c.scrollY||c.pageYOffset,m=i.scroll):(g=a,k=a.scrollLeft,l=a.scrollTop,m=h),c.addEventListener("wheel",e,{passive:!0,once:!0}),c.addEventListener("touchmove",e,{passive:!0,once:!0}),r({scrollable:g,method:m,startTime:n,startX:k,startY:l,x:b,y:f});};c.scroll=c.scrollTo=function(a,b){if(void 0!==a){if(!0===m(a))return void i.scroll.call(c,void 0===a.left?"object"==typeof a?c.scrollX||c.pageXOffset:a:a.left,void 0===a.top?void 0===b?c.scrollY||c.pageYOffset:b:a.top);const{left:e=c.scrollX||c.pageXOffset,top:f=c.scrollY||c.pageYOffset}=a;u.call(c,d.body,~~e,~~f);}},c.scrollBy=function(a,b){return void 0===a?void 0:m(a)?void i.scrollBy.call(c,void 0===a.left?"object"==typeof a?0:a:a.left,void 0===a.top?void 0===b?0:b:a.top):void u.call(c,d.body,~~a.left+(c.scrollX||c.pageXOffset),~~a.top+(c.scrollY||c.pageYOffset))},c.Element.prototype.scroll=c.Element.prototype.scrollTo=function(a,b){if(void 0!==a){if(!0===m(a)){if("number"==typeof a&&void 0===b)throw new SyntaxError("Value could not be converted");return void i.elementScroll.call(this,void 0===a.left?"object"==typeof a?this.scrollLeft:~~a:~~a.left,void 0===a.top?void 0===b?this.scrollTop:~~b:~~a.top)}const{left:c=this.scrollLeft,top:d=this.scrollTop}=a;u.call(this,this,~~c,~~d);}},c.Element.prototype.scrollBy=function(a,b){return void 0===a?void 0:!0===m(a)?void i.elementScroll.call(this,void 0===a.left?~~a+this.scrollLeft:~~a.left+this.scrollLeft,void 0===a.top?~~b+this.scrollTop:~~a.top+this.scrollTop):void this.scroll({left:~~a.left+this.scrollLeft,top:~~a.top+this.scrollTop,behavior:a.behavior})};const v=(a,b,c,d)=>{const e=0===b&&c||1===b&&!c?a.inline:a.block;return "center"===e?1:"nearest"===e?0:"start"===e?0===b?d?5:4:2:"end"===e?0===b?d?4:5:3:c?0===b?0:2:0===b?4:0};c.Element.prototype.scrollIntoView=function(a){if(void 0===a||!0===a||!1===a||!0===m(a))return void i.scrollIntoView.call(this,void 0===a||a);const b=q(this),e=b.getBoundingClientRect(),f=this.getBoundingClientRect(),{left:g,right:h,top:j,bottom:k,height:l,width:n}=e,{left:o,right:p,top:r,bottom:s,height:t,width:w}=f,{innerHeight:x,innerWidth:y}=c,{writingMode:z}=c.getComputedStyle(this),A="horizontal-tb"===z,B="vertical-rl"===z,C=v(a,0,A,B),D=v(a,1,A,B);let E=0,F=0,G=0,H=0,I=0,J=0;switch(C){case 4:E=o-g,I=g,G=o;break;case 1:E=o-g+w/2-n/2,I=(g+h-y)/2,G=(o+p-y)/2;break;case 5:E=p-h,I=h-y,G=p-y;break;case 0:{let a=o+E;o<g&&w<n||p>h&&w>n?(E=o-g,a=g):(o<g&&w>n||p>h&&w<n)&&(E=p-h,a=h-w),0>a&&w<y||a+w>y&&w>y?I=a:(0>a&&w>y||a+w>y&&w<y)&&(I=a+w-y),G=E+I;}}switch(D){case 2:F=r-j,J=j,H=r;break;case 1:F=r-j+t/2-l/2,J=(j+k-x)/2,H=(r+s-x)/2;break;case 3:F=s-k,J=k-x,H=s-x;break;case 0:{let a=r+F;r<j&&t<l||s>k&&t>l?(F=r-j,a=j):(r<j&&t>l||s>k&&t<l)&&(F=s-k,a=k-t),0>a&&t<x||a+t>x&&t>x?J=a:(0>a&&t>x||a+t>x&&t<x)&&(J=a+t-x),H=F+J;}}b===d.body?c.scrollBy({left:G,top:H,behavior:"smooth"}):(u.call(this,b,b.scrollLeft+E,b.scrollTop+F),"fixed"!==c.getComputedStyle(b).position&&c.scrollBy({left:I,top:J,behavior:"smooth"}));};}; | ||
@@ -10,0 +10,0 @@ exports.seamless = seamless; |
@@ -5,3 +5,3 @@ { | ||
"description": "Smooth Scroll behavior polyfill", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"author": { | ||
@@ -8,0 +8,0 @@ "name": "Dustan Kasten", |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
208326
925
0