smooth-scroll-into-view-if-needed
Advanced tools
Comparing version 1.1.9 to 1.1.10
@@ -29,3 +29,3 @@ import scrollIntoView from 'scroll-into-view-if-needed'; | ||
if (duration === void 0) { | ||
duration = 450; | ||
duration = 600; | ||
} | ||
@@ -43,22 +43,11 @@ | ||
var method; | ||
scrollable = el; | ||
startX = el.scrollLeft; | ||
startY = el.scrollTop; | ||
if (el === document.documentElement) { | ||
scrollable = window; | ||
startX = window.scrollX || window.pageXOffset; | ||
startY = window.scrollY || window.pageYOffset; | ||
method = function method(x, y) { | ||
el.scrollLeft = x; | ||
el.scrollTop = y; | ||
}; | ||
method = function method(x, y) { | ||
return window.scroll(x, y); | ||
}; | ||
} else { | ||
scrollable = el; | ||
startX = el.scrollLeft; | ||
startY = el.scrollTop; | ||
method = function method(x, y) { | ||
el.scrollLeft = x; | ||
el.scrollTop = y; | ||
}; | ||
} | ||
step({ | ||
@@ -65,0 +54,0 @@ scrollable: scrollable, |
27
index.js
@@ -37,3 +37,3 @@ "use strict"; | ||
if (duration === void 0) { | ||
duration = 450; | ||
duration = 600; | ||
} | ||
@@ -51,22 +51,11 @@ | ||
var method; | ||
scrollable = el; | ||
startX = el.scrollLeft; | ||
startY = el.scrollTop; | ||
if (el === document.documentElement) { | ||
scrollable = window; | ||
startX = window.scrollX || window.pageXOffset; | ||
startY = window.scrollY || window.pageYOffset; | ||
method = function method(x, y) { | ||
el.scrollLeft = x; | ||
el.scrollTop = y; | ||
}; | ||
method = function method(x, y) { | ||
return window.scroll(x, y); | ||
}; | ||
} else { | ||
scrollable = el; | ||
startX = el.scrollLeft; | ||
startY = el.scrollTop; | ||
method = function method(x, y) { | ||
el.scrollLeft = x; | ||
el.scrollTop = y; | ||
}; | ||
} | ||
step({ | ||
@@ -73,0 +62,0 @@ scrollable: scrollable, |
@@ -11,3 +11,3 @@ { | ||
}, | ||
"version": "1.1.9", | ||
"version": "1.1.10", | ||
"main": "index.js", | ||
@@ -30,8 +30,8 @@ "module": "es/index.js", | ||
"precommit": "lint-staged", | ||
"dev": "concurrently 'tsc --watch' 'yarn build:cjs --watch'", | ||
"dev": "concurrently 'tsc --noEmit --watch' 'yarn build:cjs --watch' 'yarn build:es --watch' 'yarn build:umd --watch' 'yarn build:umd.min --watch'", | ||
"prepublishOnly": "unset npm_config_cafile && yarn build", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"peerDependencies": { | ||
"scroll-into-view-if-needed": "^2.2.1" | ||
"dependencies": { | ||
"scroll-into-view-if-needed": "2.2.9" | ||
}, | ||
@@ -48,3 +48,3 @@ "devDependencies": { | ||
"concurrently": "3.6.0", | ||
"eslint": "5.0.0", | ||
"eslint": "5.0.1", | ||
"eslint-config-prettier": "2.9.0", | ||
@@ -55,7 +55,7 @@ "eslint-plugin-import": "2.13.0", | ||
"lint-staged": "7.2.0", | ||
"prettier": "1.13.6", | ||
"prettier": "1.13.7", | ||
"prettier-package-json": "1.6.0", | ||
"rimraf": "2.6.2", | ||
"rollup": "0.61.2", | ||
"rollup-plugin-babel": "4.0.0-beta.5", | ||
"rollup": "0.62.0", | ||
"rollup-plugin-babel": "4.0.0-beta.7", | ||
"rollup-plugin-commonjs": "9.1.3", | ||
@@ -65,3 +65,2 @@ "rollup-plugin-node-resolve": "3.3.0", | ||
"rollup-plugin-terser": "1.0.1", | ||
"scroll-into-view-if-needed": "2.2.8", | ||
"semantic-release": "15.6.0", | ||
@@ -92,7 +91,4 @@ "typescript": "2.9.2" | ||
"path": "./umd/smooth-scroll-into-view-if-needed.min.js", | ||
"maxSize": "2 kB" | ||
}, | ||
{ | ||
"path": "./umd/smooth-scroll-into-view-if-needed.js", | ||
"maxSize": "3.5 kB" | ||
"maxSize": "5 kB", | ||
"compression": "none" | ||
} | ||
@@ -99,0 +95,0 @@ ], |
@@ -18,3 +18,3 @@ [![CircleCI Status](https://img.shields.io/circleci/project/github/stipsan/smooth-scroll-into-view-if-needed.svg?style=flat-square)](https://circleci.com/gh/stipsan/smooth-scroll-into-view-if-needed) | ||
```bash | ||
yarn add smooth-scroll-into-view-if-needed scroll-into-view-if-needed | ||
yarn add smooth-scroll-into-view-if-needed | ||
``` | ||
@@ -21,0 +21,0 @@ |
@@ -7,13 +7,2 @@ (function (global, factory) { | ||
var viewport; | ||
var getViewport = (function () { | ||
var doc = document; | ||
if (!viewport) { | ||
viewport = doc.compatMode !== 'CSS1Compat' && doc.scrollingElement || doc.documentElement; | ||
} | ||
return viewport; | ||
}); | ||
function isElement(el) { | ||
@@ -23,14 +12,17 @@ return el != null && typeof el === 'object' && (el.nodeType === 1 || el.nodeType === 11); | ||
function canOverflow(el, axis, skipOverflowHiddenElements) { | ||
var overflowValue = getComputedStyle(el, null)[axis]; | ||
if (skipOverflowHiddenElements && overflowValue === 'hidden') { | ||
function canOverflow(overflow, skipOverflowHiddenElements) { | ||
if (skipOverflowHiddenElements && overflow === 'hidden') { | ||
return false; | ||
} | ||
return overflowValue !== 'visible' && overflowValue !== 'clip'; | ||
return overflow !== 'visible' && overflow !== 'clip'; | ||
} | ||
function isScrollable(el, skipOverflowHiddenElements) { | ||
return el === getViewport() || el.clientHeight < el.scrollHeight && canOverflow(el, 'overflowY', skipOverflowHiddenElements) || el.clientWidth < el.scrollWidth && canOverflow(el, 'overflowX', skipOverflowHiddenElements); | ||
if (el.clientHeight < el.scrollHeight || el.clientWidth < el.scrollWidth) { | ||
var style = getComputedStyle(el, null); | ||
return canOverflow(style.overflowY, skipOverflowHiddenElements) || canOverflow(style.overflowX, skipOverflowHiddenElements); | ||
} | ||
return false; | ||
} | ||
@@ -68,54 +60,53 @@ | ||
var targetRect = target.getBoundingClientRect(); | ||
var scrollingElement = document.scrollingElement || document.documentElement; | ||
var frames = []; | ||
var parent; | ||
var cursor = target; | ||
while (isElement(parent = target.parentNode || target.host) && checkBoundary(target)) { | ||
if (isScrollable(parent, skipOverflowHiddenElements)) { | ||
frames.push(parent); | ||
while (isElement(cursor) && checkBoundary(cursor)) { | ||
cursor = cursor.parentNode || cursor.host; | ||
if (cursor === scrollingElement) { | ||
frames.push(cursor); | ||
break; | ||
} | ||
target = parent; | ||
if (isScrollable(cursor, skipOverflowHiddenElements)) { | ||
frames.push(cursor); | ||
} | ||
} | ||
var viewport = getViewport(); | ||
var viewportWidth = window.visualViewport ? window.visualViewport.width : Math.min(viewport.clientWidth, window.innerWidth); | ||
var viewportHeight = window.visualViewport ? window.visualViewport.height : Math.min(viewport.clientHeight, window.innerHeight); | ||
var viewportX = window.scrollX || window.pageXOffset; | ||
var viewportY = window.scrollY || window.pageYOffset; | ||
var viewportWidth = window.visualViewport ? visualViewport.width : innerWidth; | ||
var viewportHeight = window.visualViewport ? visualViewport.height : innerHeight; | ||
var viewportX = window.scrollX || pageXOffset; | ||
var viewportY = window.scrollY || pageYOffset; | ||
if (scrollMode === 'if-needed') { | ||
var isVisible = frames.every(function (frame) { | ||
var frameRect = frame.getBoundingClientRect(); | ||
var _target$getBoundingCl = target.getBoundingClientRect(), | ||
targetHeight = _target$getBoundingCl.height, | ||
targetWidth = _target$getBoundingCl.width, | ||
targetTop = _target$getBoundingCl.top, | ||
targetRight = _target$getBoundingCl.right, | ||
targetBottom = _target$getBoundingCl.bottom, | ||
targetLeft = _target$getBoundingCl.left; | ||
if (targetRect.top < frameRect.top) { | ||
return false; | ||
} | ||
var targetBlock = block === 'start' || block === 'nearest' ? targetTop : block === 'end' ? targetBottom : targetTop + targetHeight / 2; | ||
var targetInline = inline === 'center' ? targetLeft + targetWidth / 2 : inline === 'end' ? targetRight : targetLeft; | ||
var computations = []; | ||
if (targetRect.bottom > frameRect.bottom) { | ||
return false; | ||
} | ||
for (var index = 0; index < frames.length; index++) { | ||
var frame = frames[index]; | ||
if (frame === viewport) { | ||
if (targetRect.bottom > viewportHeight || targetRect.top < 0) { | ||
return false; | ||
} | ||
var _frame$getBoundingCli = frame.getBoundingClientRect(), | ||
_height = _frame$getBoundingCli.height, | ||
_width = _frame$getBoundingCli.width, | ||
top = _frame$getBoundingCli.top, | ||
right = _frame$getBoundingCli.right, | ||
bottom = _frame$getBoundingCli.bottom, | ||
left = _frame$getBoundingCli.left; | ||
if (targetRect.left > viewportWidth || targetRect.right < 0) { | ||
return false; | ||
} | ||
if (scrollMode === 'if-needed') { | ||
if (frame === scrollingElement ? targetBottom <= viewportHeight && targetTop >= 0 && targetLeft <= viewportWidth && targetRight >= 0 : targetTop >= top && targetBottom <= bottom) { | ||
return computations; | ||
} | ||
return true; | ||
}); | ||
if (isVisible) { | ||
return []; | ||
} | ||
} | ||
var targetBlock = block === 'start' ? targetRect.top : block === 'end' ? targetRect.bottom : block === 'nearest' ? targetRect.top : targetRect.top + targetRect.height / 2; | ||
var targetInline = inline === 'start' ? targetRect.left : inline === 'center' ? targetRect.left + targetRect.width / 2 : inline === 'end' ? targetRect.right : targetRect.left; | ||
var computations = frames.map(function (frame) { | ||
var frameRect = frame.getBoundingClientRect(); | ||
var frameStyle = getComputedStyle(frame); | ||
@@ -126,35 +117,66 @@ var borderLeft = parseInt(frameStyle.borderLeftWidth, 10); | ||
var borderBottom = parseInt(frameStyle.borderBottomWidth, 10); | ||
var blockScroll = 0; | ||
var inlineScroll = 0; | ||
var scrollbarWidth = 'offsetWidth' in frame ? frame.offsetWidth - frame.clientWidth - borderLeft - borderRight : 0; | ||
var scrollbarHeight = 'offsetHeight' in frame ? frame.offsetHeight - frame.clientHeight - borderTop - borderBottom : 0; | ||
var blockScroll = 0; | ||
var inlineScroll = 0; | ||
if (block === 'start') { | ||
blockScroll = viewport === frame ? viewportY + targetBlock : targetBlock - frameRect.top - borderTop; | ||
} else if (block === 'end') { | ||
blockScroll = viewport === frame ? viewportY + (targetBlock - viewportHeight) : frame.scrollTop - (frameRect.bottom - targetBlock) + borderBottom + scrollbarHeight; | ||
} else if (block === 'nearest') { | ||
blockScroll = viewport === frame ? viewportY + alignNearest(viewportY, viewportY + viewportHeight, viewportHeight, borderTop, borderBottom, viewportY + targetBlock, viewportY + targetBlock + targetRect.height, targetRect.height) : frame.scrollTop + alignNearest(frameRect.top, frameRect.bottom, frameRect.height, borderTop, borderBottom + scrollbarHeight, targetBlock, targetBlock + targetRect.height, targetRect.height); | ||
if (scrollingElement === frame) { | ||
if (block === 'start') { | ||
blockScroll = targetBlock; | ||
} else if (block === 'end') { | ||
blockScroll = targetBlock - viewportHeight; | ||
} else if (block === 'nearest') { | ||
blockScroll = alignNearest(viewportY, viewportY + viewportHeight, viewportHeight, borderTop, borderBottom, viewportY + targetBlock, viewportY + targetBlock + targetHeight, targetHeight); | ||
} else { | ||
blockScroll = targetBlock - viewportHeight / 2; | ||
} | ||
if (inline === 'start') { | ||
inlineScroll = targetInline; | ||
} else if (inline === 'center') { | ||
inlineScroll = targetInline - viewportWidth / 2; | ||
} else if (inline === 'end') { | ||
inlineScroll = targetInline - viewportWidth; | ||
} else { | ||
inlineScroll = alignNearest(viewportX, viewportX + viewportWidth, viewportWidth, borderLeft, borderRight, viewportX + targetInline, viewportX + targetInline + targetWidth, targetWidth); | ||
} | ||
blockScroll += viewportY; | ||
inlineScroll += viewportX; | ||
} else { | ||
blockScroll = viewport === frame ? viewportY + targetBlock - viewportHeight / 2 : frame.scrollTop - (frameRect.top + frameRect.height / 2 - targetBlock); | ||
} | ||
if (block === 'start') { | ||
blockScroll = targetBlock - top - borderTop; | ||
} else if (block === 'end') { | ||
blockScroll = targetBlock - bottom + borderBottom + scrollbarHeight; | ||
} else if (block === 'nearest') { | ||
blockScroll = alignNearest(top, bottom, _height, borderTop, borderBottom + scrollbarHeight, targetBlock, targetBlock + targetHeight, targetHeight); | ||
} else { | ||
blockScroll = targetBlock - (top + _height / 2) + scrollbarHeight / 2; | ||
} | ||
if (inline === 'start') { | ||
inlineScroll = viewport === frame ? viewportX + targetInline : frame.scrollLeft + (targetInline - frameRect.left) - borderLeft; | ||
} else if (inline === 'center') { | ||
inlineScroll = viewport === frame ? viewportX + targetInline - viewportWidth / 2 : frame.scrollLeft - (frameRect.left + frameRect.width / 2 - targetInline); | ||
} else if (inline === 'end') { | ||
inlineScroll = viewport === frame ? viewportX + (targetInline - viewportWidth) : frame.scrollLeft - (frameRect.right - targetInline) + borderRight + scrollbarWidth; | ||
} else { | ||
inlineScroll = viewport === frame ? viewportX + alignNearest(viewportX, viewportX + viewportWidth, viewportWidth, borderLeft, borderRight, viewportX + targetInline, viewportX + targetInline + targetRect.width, targetRect.width) : frame.scrollLeft + alignNearest(frameRect.left, frameRect.right, frameRect.width, borderLeft, borderRight + scrollbarWidth, targetInline, targetInline + targetRect.width, targetRect.width); | ||
if (inline === 'start') { | ||
inlineScroll = targetInline - left - borderLeft; | ||
} else if (inline === 'center') { | ||
inlineScroll = targetInline - (left + _width / 2) + scrollbarWidth / 2; | ||
} else if (inline === 'end') { | ||
inlineScroll = targetInline - right + borderRight + scrollbarWidth; | ||
} else { | ||
inlineScroll = alignNearest(left, right, _width, borderLeft, borderRight + scrollbarWidth, targetInline, targetInline + targetWidth, targetWidth); | ||
} | ||
var scrollLeft = frame.scrollLeft, | ||
scrollTop = frame.scrollTop; | ||
blockScroll = Math.max(0, Math.min(scrollTop + blockScroll, frame.scrollHeight - _height + scrollbarHeight)); | ||
inlineScroll = Math.max(0, Math.min(scrollLeft + inlineScroll, frame.scrollWidth - _width + scrollbarWidth)); | ||
targetBlock += scrollTop - blockScroll; | ||
targetInline += scrollLeft - inlineScroll; | ||
} | ||
targetBlock += frame.scrollTop - blockScroll; | ||
targetInline += frame.scrollLeft - inlineScroll; | ||
return { | ||
computations.push({ | ||
el: frame, | ||
top: blockScroll, | ||
left: inlineScroll | ||
}; | ||
}); | ||
}); | ||
} | ||
return computations; | ||
@@ -172,3 +194,3 @@ }); | ||
var viewport = getViewport(); | ||
var canSmoothScroll = 'scrollBehavior' in document.body.style; | ||
actions.forEach(function (_ref) { | ||
@@ -179,3 +201,3 @@ var el = _ref.el, | ||
if (el.scroll && 'scrollBehavior' in viewport.style) { | ||
if (el.scroll && canSmoothScroll) { | ||
el.scroll({ | ||
@@ -187,8 +209,4 @@ top: top, | ||
} else { | ||
if (el === viewport) { | ||
scrollTo(left, top); | ||
} else { | ||
el.scrollTop = top; | ||
el.scrollLeft = left; | ||
} | ||
el.scrollTop = top; | ||
el.scrollLeft = left; | ||
} | ||
@@ -252,3 +270,3 @@ }); | ||
if (duration === void 0) { | ||
duration = 450; | ||
duration = 600; | ||
} | ||
@@ -266,22 +284,11 @@ | ||
var method; | ||
scrollable = el; | ||
startX = el.scrollLeft; | ||
startY = el.scrollTop; | ||
if (el === document.documentElement) { | ||
scrollable = window; | ||
startX = window.scrollX || window.pageXOffset; | ||
startY = window.scrollY || window.pageYOffset; | ||
method = function method(x, y) { | ||
el.scrollLeft = x; | ||
el.scrollTop = y; | ||
}; | ||
method = function method(x, y) { | ||
return window.scroll(x, y); | ||
}; | ||
} else { | ||
scrollable = el; | ||
startX = el.scrollLeft; | ||
startY = el.scrollTop; | ||
method = function method(x, y) { | ||
el.scrollLeft = x; | ||
el.scrollTop = y; | ||
}; | ||
} | ||
step({ | ||
@@ -288,0 +295,0 @@ scrollable: scrollable, |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.scrollIntoView=e()}(this,function(){"use strict";var t,e=function(){var e=document;return t||(t="CSS1Compat"!==e.compatMode&&e.scrollingElement||e.documentElement),t};function o(t){return null!=t&&"object"==typeof t&&(1===t.nodeType||11===t.nodeType)}function n(t,e,o){var n=getComputedStyle(t,null)[e];return(!o||"hidden"!==n)&&("visible"!==n&&"clip"!==n)}function r(t,o){return t===e()||t.clientHeight<t.scrollHeight&&n(t,"overflowY",o)||t.clientWidth<t.scrollWidth&&n(t,"overflowX",o)}function i(t,e,o,n,r,i,l,c){return i<t&&l>e||i>t&&l<e?0:i<t&&c<o||l>e&&c>o?i-t-n:l>e&&c<o||i<t&&c>o?l-e+r:0}var l,c=function(t,n){var l=n.scrollMode,c=n.block,f=n.inline,u=n.boundary,d=n.skipOverflowHiddenElements,s="function"==typeof u?u:function(t){return t!==u};if(!o(t))throw new Error("Element is required in scrollIntoView");for(var a,h=t.getBoundingClientRect(),p=[];o(a=t.parentNode||t.host)&&s(t);)r(a,d)&&p.push(a),t=a;var w=e(),m=window.visualViewport?window.visualViewport.width:Math.min(w.clientWidth,window.innerWidth),v=window.visualViewport?window.visualViewport.height:Math.min(w.clientHeight,window.innerHeight),g=window.scrollX||window.pageXOffset,b=window.scrollY||window.pageYOffset;if("if-needed"===l&&p.every(function(t){var e=t.getBoundingClientRect();if(h.top<e.top)return!1;if(h.bottom>e.bottom)return!1;if(t===w){if(h.bottom>v||h.top<0)return!1;if(h.left>m||h.right<0)return!1}return!0}))return[];var y="start"===c?h.top:"end"===c?h.bottom:"nearest"===c?h.top:h.top+h.height/2,T="start"===f?h.left:"center"===f?h.left+h.width/2:"end"===f?h.right:h.left;return p.map(function(t){var e=t.getBoundingClientRect(),o=getComputedStyle(t),n=parseInt(o.borderLeftWidth,10),r=parseInt(o.borderTopWidth,10),l=parseInt(o.borderRightWidth,10),u=parseInt(o.borderBottomWidth,10),d="offsetWidth"in t?t.offsetWidth-t.clientWidth-n-l:0,s="offsetHeight"in t?t.offsetHeight-t.clientHeight-r-u:0,a=0,p=0;return a="start"===c?w===t?b+y:y-e.top-r:"end"===c?w===t?b+(y-v):t.scrollTop-(e.bottom-y)+u+s:"nearest"===c?w===t?b+i(b,b+v,v,r,u,b+y,b+y+h.height,h.height):t.scrollTop+i(e.top,e.bottom,e.height,r,u+s,y,y+h.height,h.height):w===t?b+y-v/2:t.scrollTop-(e.top+e.height/2-y),p="start"===f?w===t?g+T:t.scrollLeft+(T-e.left)-n:"center"===f?w===t?g+T-m/2:t.scrollLeft-(e.left+e.width/2-T):"end"===f?w===t?g+(T-m):t.scrollLeft-(e.right-T)+l+d:w===t?g+i(g,g+m,m,n,l,g+T,g+T+h.width,h.width):t.scrollLeft+i(e.left,e.right,e.width,n,l+d,T,T+h.width,h.width),y+=t.scrollTop-a,T+=t.scrollLeft-p,{el:t,top:a,left:p}})};function f(t){return t===Object(t)&&0!==Object.keys(t).length}function u(t,o){if(f(o)&&"function"==typeof o.behavior)return o.behavior(c(t,o));var n=function(t){return!1===t?{block:"end",inline:"nearest"}:f(t)?t:{block:"start",inline:"nearest"}}(o);return function(t,o){void 0===o&&(o="auto");var n=e();t.forEach(function(t){var e=t.el,r=t.top,i=t.left;e.scroll&&"scrollBehavior"in n.style?e.scroll({top:r,left:i,behavior:o}):e===n?scrollTo(i,r):(e.scrollTop=r,e.scrollLeft=i)})}(c(t,n),n.behavior)}var d=function(){return l||(l="performance"in window?performance.now.bind(performance):Date.now),l()};function s(t,e,o,n,r,i){var l,c,f,u;void 0===n&&(n=450),void 0===r&&(r=function(t){return 1+--t*t*t*t*t}),t===document.documentElement?(l=window,c=window.scrollX||window.pageXOffset,f=window.scrollY||window.pageYOffset,u=function(t,e){return window.scroll(t,e)}):(l=t,c=t.scrollLeft,f=t.scrollTop,u=function(e,o){t.scrollLeft=e,t.scrollTop=o}),function t(e){var o=d(),n=Math.min((o-e.startTime)/e.duration,1),r=e.ease(n),i=e.startX+(e.x-e.startX)*r,l=e.startY+(e.y-e.startY)*r;e.method(i,l),i===e.x&&l===e.y||requestAnimationFrame(function(){return t(e)})}({scrollable:l,method:u,startTime:d(),startX:c,startY:f,x:e,y:o,duration:n,ease:r,cb:i})}var a=function(t){return t&&!t.behavior||"smooth"===t.behavior};return function(t,e){if(a(e)){var o=e||{};return u(t,{block:o.block,inline:o.inline,scrollMode:o.scrollMode,boundary:o.boundary,behavior:function(t){return Promise.all(t.map(function(t){var e=t.el,n=t.left,r=t.top;return new Promise(function(t){return s(e,n,r,o.duration,o.ease,function(){return t()})})}))}})}return u(t,e)}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.scrollIntoView=e()}(this,function(){"use strict";function t(t){return null!=t&&"object"==typeof t&&(1===t.nodeType||11===t.nodeType)}function e(t,e){return(!e||"hidden"!==t)&&("visible"!==t&&"clip"!==t)}function n(t,n){if(t.clientHeight<t.scrollHeight||t.clientWidth<t.scrollWidth){var r=getComputedStyle(t,null);return e(r.overflowY,n)||e(r.overflowX,n)}return!1}function r(t,e,n,r,o,i,l,a){return i<t&&l>e||i>t&&l<e?0:i<t&&a<n||l>e&&a>n?i-t-r:l>e&&a<n||i<t&&a>n?l-e+o:0}var o,i=function(e,o){var i=o.scrollMode,l=o.block,a=o.inline,c=o.boundary,u=o.skipOverflowHiddenElements,s="function"==typeof c?c:function(t){return t!==c};if(!t(e))throw new Error("Element is required in scrollIntoView");for(var f=document.scrollingElement||document.documentElement,d=[],h=e;t(h)&&s(h);){if((h=h.parentNode||h.host)===f){d.push(h);break}n(h,u)&&d.push(h)}for(var p=window.visualViewport?visualViewport.width:innerWidth,v=window.visualViewport?visualViewport.height:innerHeight,m=window.scrollX||pageXOffset,b=window.scrollY||pageYOffset,w=e.getBoundingClientRect(),g=w.height,y=w.width,W=w.top,T=w.right,k=w.bottom,H=w.left,M="start"===l||"nearest"===l?W:"end"===l?k:W+g/2,x="center"===a?H+y/2:"end"===a?T:H,E=[],I=0;I<d.length;I++){var V=d[I],X=V.getBoundingClientRect(),Y=X.height,L=X.width,O=X.top,j=X.right,B=X.bottom,C=X.left;if("if-needed"===i&&(V===f?k<=v&&W>=0&&H<=p&&T>=0:W>=O&&k<=B))return E;var R=getComputedStyle(V),q=parseInt(R.borderLeftWidth,10),P=parseInt(R.borderTopWidth,10),S=parseInt(R.borderRightWidth,10),A=parseInt(R.borderBottomWidth,10),D=0,F=0,N="offsetWidth"in V?V.offsetWidth-V.clientWidth-q-S:0,z="offsetHeight"in V?V.offsetHeight-V.clientHeight-P-A:0;if(f===V)D="start"===l?M:"end"===l?M-v:"nearest"===l?r(b,b+v,v,P,A,b+M,b+M+g,g):M-v/2,F="start"===a?x:"center"===a?x-p/2:"end"===a?x-p:r(m,m+p,p,q,S,m+x,m+x+y,y),D+=b,F+=m;else{D="start"===l?M-O-P:"end"===l?M-B+A+z:"nearest"===l?r(O,B,Y,P,A+z,M,M+g,g):M-(O+Y/2)+z/2,F="start"===a?x-C-q:"center"===a?x-(C+L/2)+N/2:"end"===a?x-j+S+N:r(C,j,L,q,S+N,x,x+y,y);var G=V.scrollLeft,J=V.scrollTop;M+=J-(D=Math.max(0,Math.min(J+D,V.scrollHeight-Y+z))),x+=G-(F=Math.max(0,Math.min(G+F,V.scrollWidth-L+N)))}E.push({el:V,top:D,left:F})}return E};function l(t){return t===Object(t)&&0!==Object.keys(t).length}function a(t,e){if(l(e)&&"function"==typeof e.behavior)return e.behavior(i(t,e));var n=function(t){return!1===t?{block:"end",inline:"nearest"}:l(t)?t:{block:"start",inline:"nearest"}}(e);return function(t,e){void 0===e&&(e="auto");var n="scrollBehavior"in document.body.style;t.forEach(function(t){var r=t.el,o=t.top,i=t.left;r.scroll&&n?r.scroll({top:o,left:i,behavior:e}):(r.scrollTop=o,r.scrollLeft=i)})}(i(t,n),n.behavior)}var c=function(){return o||(o="performance"in window?performance.now.bind(performance):Date.now),o()};function u(t,e,n,r,o,i){var l,a,u;void 0===r&&(r=600),void 0===o&&(o=function(t){return 1+--t*t*t*t*t}),l=t,a=t.scrollLeft,u=t.scrollTop,function t(e){var n=c(),r=Math.min((n-e.startTime)/e.duration,1),o=e.ease(r),i=e.startX+(e.x-e.startX)*o,l=e.startY+(e.y-e.startY)*o;e.method(i,l),i===e.x&&l===e.y||requestAnimationFrame(function(){return t(e)})}({scrollable:l,method:function(e,n){t.scrollLeft=e,t.scrollTop=n},startTime:c(),startX:a,startY:u,x:e,y:n,duration:r,ease:o,cb:i})}var s=function(t){return t&&!t.behavior||"smooth"===t.behavior};return function(t,e){if(s(e)){var n=e||{};return a(t,{block:n.block,inline:n.inline,scrollMode:n.scrollMode,boundary:n.boundary,behavior:function(t){return Promise.all(t.map(function(t){var e=t.el,r=t.left,o=t.top;return new Promise(function(t){return u(e,r,o,n.duration,n.ease,function(){return t()})})}))}})}return a(t,e)}}); |
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
26
30524
478
+ Addedscroll-into-view-if-needed@2.2.9(transitive)
- Removedcompute-scroll-into-view@1.0.20(transitive)
- Removedscroll-into-view-if-needed@2.2.31(transitive)