compute-scroll-into-view 1.0.11 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,7 +47,11 @@ const actions = computeScrollIntoView(node, {
47
47
 
48
48
  // same behavior as Element.scrollIntoViewIfNeeded(true)
49
49
  // see: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded
50
- const actions = computeScrollIntoView(node, { scrollMode: 'if-needed' block: 'center', inline: 'center' })
50
+ const actions = computeScrollIntoView(node, {
51
+ scrollMode: 'if-needed',
52
+ block: 'center',
53
+ inline: 'center',
54
+ })
51
55
 
52
56
  // Then perform the scrolling, use scroll-into-view-if-needed if you don't want to implement this part
53
57
  actions.forEach(({ el, top, left }) => {
@@ -124,8 +128,6 @@ This package follows the convention [adopted by Firefox](https://hg.mozilla.org/
124
128
 
125
129
  This library ships with library definitions for TypeScript.
126
130
 
127
- > FlowType definitions is coming soon...
128
-
129
131
  [gzip-badge]: http://img.badgesize.io/https://unpkg.com/compute-scroll-into-view/umd/compute-scroll-into-view.min.js?compression=gzip&label=gzip%20size&style=flat-square
130
132
  [size-badge]: http://img.badgesize.io/https://unpkg.com/compute-scroll-into-view/umd/compute-scroll-into-view.min.js?label=size&style=flat-square
131
133
  [unpkg-dist]: https://unpkg.com/compute-scroll-into-view/umd/
package/es/index.js CHANGED
@@ -10,10 +10,28 @@ function canOverflow(overflow, skipOverflowHiddenElements) {
10
10
  return overflow !== 'visible' && overflow !== 'clip';
11
11
  }
12
12
 
13
+ function getFrameElement(el) {
14
+ if (!el.ownerDocument || !el.ownerDocument.defaultView) {
15
+ return null;
16
+ }
17
+
18
+ return el.ownerDocument.defaultView.frameElement;
19
+ }
20
+
21
+ function isHiddenByFrame(el) {
22
+ var frame = getFrameElement(el);
23
+
24
+ if (!frame) {
25
+ return false;
26
+ }
27
+
28
+ return frame.clientHeight < el.scrollHeight || frame.clientWidth < el.scrollWidth;
29
+ }
30
+
13
31
  function isScrollable(el, skipOverflowHiddenElements) {
14
32
  if (el.clientHeight < el.scrollHeight || el.clientWidth < el.scrollWidth) {
15
33
  var style = getComputedStyle(el, null);
16
- return canOverflow(style.overflowY, skipOverflowHiddenElements) || canOverflow(style.overflowX, skipOverflowHiddenElements);
34
+ return canOverflow(style.overflowY, skipOverflowHiddenElements) || canOverflow(style.overflowX, skipOverflowHiddenElements) || isHiddenByFrame(el);
17
35
  }
18
36
 
19
37
  return false;
@@ -91,14 +109,14 @@ export default (function (target, options) {
91
109
  var frame = frames[index];
92
110
 
93
111
  var _frame$getBoundingCli = frame.getBoundingClientRect(),
94
- _height = _frame$getBoundingCli.height,
95
- _width = _frame$getBoundingCli.width,
96
- _top = _frame$getBoundingCli.top,
112
+ height = _frame$getBoundingCli.height,
113
+ width = _frame$getBoundingCli.width,
114
+ top = _frame$getBoundingCli.top,
97
115
  right = _frame$getBoundingCli.right,
98
116
  bottom = _frame$getBoundingCli.bottom,
99
- _left = _frame$getBoundingCli.left;
117
+ left = _frame$getBoundingCli.left;
100
118
 
101
- if (scrollMode === 'if-needed' && targetTop >= 0 && targetLeft >= 0 && targetBottom <= viewportHeight && targetRight <= viewportWidth && targetTop >= _top && targetBottom <= bottom && targetLeft >= _left && targetRight <= right) {
119
+ if (scrollMode === 'if-needed' && targetTop >= 0 && targetLeft >= 0 && targetBottom <= viewportHeight && targetRight <= viewportWidth && targetTop >= top && targetBottom <= bottom && targetLeft >= left && targetRight <= right) {
102
120
  return computations;
103
121
  }
104
122
 
@@ -137,29 +155,29 @@ export default (function (target, options) {
137
155
  inlineScroll = Math.max(0, inlineScroll + viewportX);
138
156
  } else {
139
157
  if (block === 'start') {
140
- blockScroll = targetBlock - _top - borderTop;
158
+ blockScroll = targetBlock - top - borderTop;
141
159
  } else if (block === 'end') {
142
160
  blockScroll = targetBlock - bottom + borderBottom + scrollbarHeight;
143
161
  } else if (block === 'nearest') {
144
- blockScroll = alignNearest(_top, bottom, _height, borderTop, borderBottom + scrollbarHeight, targetBlock, targetBlock + targetHeight, targetHeight);
162
+ blockScroll = alignNearest(top, bottom, height, borderTop, borderBottom + scrollbarHeight, targetBlock, targetBlock + targetHeight, targetHeight);
145
163
  } else {
146
- blockScroll = targetBlock - (_top + _height / 2) + scrollbarHeight / 2;
164
+ blockScroll = targetBlock - (top + height / 2) + scrollbarHeight / 2;
147
165
  }
148
166
 
149
167
  if (inline === 'start') {
150
- inlineScroll = targetInline - _left - borderLeft;
168
+ inlineScroll = targetInline - left - borderLeft;
151
169
  } else if (inline === 'center') {
152
- inlineScroll = targetInline - (_left + _width / 2) + scrollbarWidth / 2;
170
+ inlineScroll = targetInline - (left + width / 2) + scrollbarWidth / 2;
153
171
  } else if (inline === 'end') {
154
172
  inlineScroll = targetInline - right + borderRight + scrollbarWidth;
155
173
  } else {
156
- inlineScroll = alignNearest(_left, right, _width, borderLeft, borderRight + scrollbarWidth, targetInline, targetInline + targetWidth, targetWidth);
174
+ inlineScroll = alignNearest(left, right, width, borderLeft, borderRight + scrollbarWidth, targetInline, targetInline + targetWidth, targetWidth);
157
175
  }
158
176
 
159
177
  var scrollLeft = frame.scrollLeft,
160
178
  scrollTop = frame.scrollTop;
161
- blockScroll = Math.max(0, Math.min(scrollTop + blockScroll, frame.scrollHeight - _height + scrollbarHeight));
162
- inlineScroll = Math.max(0, Math.min(scrollLeft + inlineScroll, frame.scrollWidth - _width + scrollbarWidth));
179
+ blockScroll = Math.max(0, Math.min(scrollTop + blockScroll, frame.scrollHeight - height + scrollbarHeight));
180
+ inlineScroll = Math.max(0, Math.min(scrollLeft + inlineScroll, frame.scrollWidth - width + scrollbarWidth));
163
181
  targetBlock += scrollTop - blockScroll;
164
182
  targetInline += scrollLeft - inlineScroll;
165
183
  }
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.default = void 0;
4
+ exports["default"] = void 0;
5
5
 
6
6
  function isElement(el) {
7
7
  return el != null && typeof el === 'object' && el.nodeType === 1;
@@ -15,10 +15,28 @@ function canOverflow(overflow, skipOverflowHiddenElements) {
15
15
  return overflow !== 'visible' && overflow !== 'clip';
16
16
  }
17
17
 
18
+ function getFrameElement(el) {
19
+ if (!el.ownerDocument || !el.ownerDocument.defaultView) {
20
+ return null;
21
+ }
22
+
23
+ return el.ownerDocument.defaultView.frameElement;
24
+ }
25
+
26
+ function isHiddenByFrame(el) {
27
+ var frame = getFrameElement(el);
28
+
29
+ if (!frame) {
30
+ return false;
31
+ }
32
+
33
+ return frame.clientHeight < el.scrollHeight || frame.clientWidth < el.scrollWidth;
34
+ }
35
+
18
36
  function isScrollable(el, skipOverflowHiddenElements) {
19
37
  if (el.clientHeight < el.scrollHeight || el.clientWidth < el.scrollWidth) {
20
38
  var style = getComputedStyle(el, null);
21
- return canOverflow(style.overflowY, skipOverflowHiddenElements) || canOverflow(style.overflowX, skipOverflowHiddenElements);
39
+ return canOverflow(style.overflowY, skipOverflowHiddenElements) || canOverflow(style.overflowX, skipOverflowHiddenElements) || isHiddenByFrame(el);
22
40
  }
23
41
 
24
42
  return false;
@@ -96,14 +114,14 @@ var _default = function _default(target, options) {
96
114
  var frame = frames[index];
97
115
 
98
116
  var _frame$getBoundingCli = frame.getBoundingClientRect(),
99
- _height = _frame$getBoundingCli.height,
100
- _width = _frame$getBoundingCli.width,
101
- _top = _frame$getBoundingCli.top,
117
+ height = _frame$getBoundingCli.height,
118
+ width = _frame$getBoundingCli.width,
119
+ top = _frame$getBoundingCli.top,
102
120
  right = _frame$getBoundingCli.right,
103
121
  bottom = _frame$getBoundingCli.bottom,
104
- _left = _frame$getBoundingCli.left;
122
+ left = _frame$getBoundingCli.left;
105
123
 
106
- if (scrollMode === 'if-needed' && targetTop >= 0 && targetLeft >= 0 && targetBottom <= viewportHeight && targetRight <= viewportWidth && targetTop >= _top && targetBottom <= bottom && targetLeft >= _left && targetRight <= right) {
124
+ if (scrollMode === 'if-needed' && targetTop >= 0 && targetLeft >= 0 && targetBottom <= viewportHeight && targetRight <= viewportWidth && targetTop >= top && targetBottom <= bottom && targetLeft >= left && targetRight <= right) {
107
125
  return computations;
108
126
  }
109
127
 
@@ -142,29 +160,29 @@ var _default = function _default(target, options) {
142
160
  inlineScroll = Math.max(0, inlineScroll + viewportX);
143
161
  } else {
144
162
  if (block === 'start') {
145
- blockScroll = targetBlock - _top - borderTop;
163
+ blockScroll = targetBlock - top - borderTop;
146
164
  } else if (block === 'end') {
147
165
  blockScroll = targetBlock - bottom + borderBottom + scrollbarHeight;
148
166
  } else if (block === 'nearest') {
149
- blockScroll = alignNearest(_top, bottom, _height, borderTop, borderBottom + scrollbarHeight, targetBlock, targetBlock + targetHeight, targetHeight);
167
+ blockScroll = alignNearest(top, bottom, height, borderTop, borderBottom + scrollbarHeight, targetBlock, targetBlock + targetHeight, targetHeight);
150
168
  } else {
151
- blockScroll = targetBlock - (_top + _height / 2) + scrollbarHeight / 2;
169
+ blockScroll = targetBlock - (top + height / 2) + scrollbarHeight / 2;
152
170
  }
153
171
 
154
172
  if (inline === 'start') {
155
- inlineScroll = targetInline - _left - borderLeft;
173
+ inlineScroll = targetInline - left - borderLeft;
156
174
  } else if (inline === 'center') {
157
- inlineScroll = targetInline - (_left + _width / 2) + scrollbarWidth / 2;
175
+ inlineScroll = targetInline - (left + width / 2) + scrollbarWidth / 2;
158
176
  } else if (inline === 'end') {
159
177
  inlineScroll = targetInline - right + borderRight + scrollbarWidth;
160
178
  } else {
161
- inlineScroll = alignNearest(_left, right, _width, borderLeft, borderRight + scrollbarWidth, targetInline, targetInline + targetWidth, targetWidth);
179
+ inlineScroll = alignNearest(left, right, width, borderLeft, borderRight + scrollbarWidth, targetInline, targetInline + targetWidth, targetWidth);
162
180
  }
163
181
 
164
182
  var scrollLeft = frame.scrollLeft,
165
183
  scrollTop = frame.scrollTop;
166
- blockScroll = Math.max(0, Math.min(scrollTop + blockScroll, frame.scrollHeight - _height + scrollbarHeight));
167
- inlineScroll = Math.max(0, Math.min(scrollLeft + inlineScroll, frame.scrollWidth - _width + scrollbarWidth));
184
+ blockScroll = Math.max(0, Math.min(scrollTop + blockScroll, frame.scrollHeight - height + scrollbarHeight));
185
+ inlineScroll = Math.max(0, Math.min(scrollLeft + inlineScroll, frame.scrollWidth - width + scrollbarWidth));
168
186
  targetBlock += scrollTop - blockScroll;
169
187
  targetInline += scrollLeft - inlineScroll;
170
188
  }
@@ -179,5 +197,5 @@ var _default = function _default(target, options) {
179
197
  return computations;
180
198
  };
181
199
 
182
- exports.default = _default;
200
+ exports["default"] = _default;
183
201
  module.exports = exports.default;
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/stipsan/compute-scroll-into-view.git"
10
10
  },
11
- "version": "1.0.11",
11
+ "version": "1.0.12",
12
12
  "main": "index.js",
13
13
  "module": "es/index.js",
14
14
  "files": [
@@ -32,34 +32,34 @@
32
32
  "typecheck": "tsc --noEmit"
33
33
  },
34
34
  "devDependencies": {
35
- "@babel/cli": "7.1.2",
36
- "@babel/core": "7.1.2",
37
- "@babel/plugin-external-helpers": "7.0.0",
38
- "@babel/preset-env": "7.1.0",
39
- "@babel/preset-typescript": "7.1.0",
40
- "babel-plugin-add-module-exports": "1.0.0",
41
- "babel-plugin-dev-expression": "0.2.1",
42
- "concurrently": "4.0.1",
43
- "husky": "1.1.1",
35
+ "@babel/cli": "7.7.7",
36
+ "@babel/core": "7.7.7",
37
+ "@babel/plugin-external-helpers": "7.7.4",
38
+ "@babel/preset-env": "7.7.7",
39
+ "@babel/preset-typescript": "7.7.7",
40
+ "babel-plugin-add-module-exports": "1.0.2",
41
+ "babel-plugin-dev-expression": "0.2.2",
42
+ "concurrently": "5.0.2",
43
+ "husky": "3.1.0",
44
44
  "jest": "23.6.0",
45
- "jest-junit": "5.2.0",
46
- "jest-puppeteer": "3.4.0",
47
- "lint-staged": "7.3.0",
48
- "prettier": "1.14.3",
49
- "prettier-package-json": "2.0.1",
50
- "puppeteer": "1.9.0",
51
- "rimraf": "2.6.2",
52
- "rollup": "0.66.4",
53
- "rollup-plugin-babel": "4.0.3",
54
- "rollup-plugin-commonjs": "9.1.8",
55
- "rollup-plugin-node-resolve": "3.4.0",
56
- "rollup-plugin-replace": "2.1.0",
57
- "rollup-plugin-terser": "3.0.0",
58
- "semantic-release": "15.9.17",
59
- "serve": "10.0.2",
60
- "tslint": "5.11.0",
61
- "tslint-config-prettier": "1.15.0",
62
- "typescript": "3.1.1"
45
+ "jest-junit": "10.0.0",
46
+ "jest-puppeteer": "4.4.0",
47
+ "lint-staged": "9.5.0",
48
+ "prettier": "1.19.1",
49
+ "prettier-package-json": "2.1.3",
50
+ "puppeteer": "2.0.0",
51
+ "rimraf": "3.0.0",
52
+ "rollup": "1.27.14",
53
+ "rollup-plugin-babel": "4.3.3",
54
+ "rollup-plugin-commonjs": "10.1.0",
55
+ "rollup-plugin-node-resolve": "5.2.0",
56
+ "rollup-plugin-replace": "2.2.0",
57
+ "rollup-plugin-terser": "5.1.3",
58
+ "semantic-release": "15.14.0",
59
+ "serve": "11.3.0",
60
+ "tslint": "5.20.1",
61
+ "tslint-config-prettier": "1.18.0",
62
+ "typescript": "3.7.4"
63
63
  },
64
64
  "keywords": [
65
65
  "if-needed",
@@ -1,7 +1,7 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
3
  typeof define === 'function' && define.amd ? define(factory) :
4
- (global.computeScrollIntoView = factory());
4
+ (global = global || self, global.computeScrollIntoView = factory());
5
5
  }(this, (function () { 'use strict';
6
6
 
7
7
  function isElement(el) {
@@ -16,10 +16,28 @@
16
16
  return overflow !== 'visible' && overflow !== 'clip';
17
17
  }
18
18
 
19
+ function getFrameElement(el) {
20
+ if (!el.ownerDocument || !el.ownerDocument.defaultView) {
21
+ return null;
22
+ }
23
+
24
+ return el.ownerDocument.defaultView.frameElement;
25
+ }
26
+
27
+ function isHiddenByFrame(el) {
28
+ var frame = getFrameElement(el);
29
+
30
+ if (!frame) {
31
+ return false;
32
+ }
33
+
34
+ return frame.clientHeight < el.scrollHeight || frame.clientWidth < el.scrollWidth;
35
+ }
36
+
19
37
  function isScrollable(el, skipOverflowHiddenElements) {
20
38
  if (el.clientHeight < el.scrollHeight || el.clientWidth < el.scrollWidth) {
21
39
  var style = getComputedStyle(el, null);
22
- return canOverflow(style.overflowY, skipOverflowHiddenElements) || canOverflow(style.overflowX, skipOverflowHiddenElements);
40
+ return canOverflow(style.overflowY, skipOverflowHiddenElements) || canOverflow(style.overflowX, skipOverflowHiddenElements) || isHiddenByFrame(el);
23
41
  }
24
42
 
25
43
  return false;
@@ -97,14 +115,14 @@
97
115
  var frame = frames[index];
98
116
 
99
117
  var _frame$getBoundingCli = frame.getBoundingClientRect(),
100
- _height = _frame$getBoundingCli.height,
101
- _width = _frame$getBoundingCli.width,
102
- _top = _frame$getBoundingCli.top,
118
+ height = _frame$getBoundingCli.height,
119
+ width = _frame$getBoundingCli.width,
120
+ top = _frame$getBoundingCli.top,
103
121
  right = _frame$getBoundingCli.right,
104
122
  bottom = _frame$getBoundingCli.bottom,
105
- _left = _frame$getBoundingCli.left;
123
+ left = _frame$getBoundingCli.left;
106
124
 
107
- if (scrollMode === 'if-needed' && targetTop >= 0 && targetLeft >= 0 && targetBottom <= viewportHeight && targetRight <= viewportWidth && targetTop >= _top && targetBottom <= bottom && targetLeft >= _left && targetRight <= right) {
125
+ if (scrollMode === 'if-needed' && targetTop >= 0 && targetLeft >= 0 && targetBottom <= viewportHeight && targetRight <= viewportWidth && targetTop >= top && targetBottom <= bottom && targetLeft >= left && targetRight <= right) {
108
126
  return computations;
109
127
  }
110
128
 
@@ -143,29 +161,29 @@
143
161
  inlineScroll = Math.max(0, inlineScroll + viewportX);
144
162
  } else {
145
163
  if (block === 'start') {
146
- blockScroll = targetBlock - _top - borderTop;
164
+ blockScroll = targetBlock - top - borderTop;
147
165
  } else if (block === 'end') {
148
166
  blockScroll = targetBlock - bottom + borderBottom + scrollbarHeight;
149
167
  } else if (block === 'nearest') {
150
- blockScroll = alignNearest(_top, bottom, _height, borderTop, borderBottom + scrollbarHeight, targetBlock, targetBlock + targetHeight, targetHeight);
168
+ blockScroll = alignNearest(top, bottom, height, borderTop, borderBottom + scrollbarHeight, targetBlock, targetBlock + targetHeight, targetHeight);
151
169
  } else {
152
- blockScroll = targetBlock - (_top + _height / 2) + scrollbarHeight / 2;
170
+ blockScroll = targetBlock - (top + height / 2) + scrollbarHeight / 2;
153
171
  }
154
172
 
155
173
  if (inline === 'start') {
156
- inlineScroll = targetInline - _left - borderLeft;
174
+ inlineScroll = targetInline - left - borderLeft;
157
175
  } else if (inline === 'center') {
158
- inlineScroll = targetInline - (_left + _width / 2) + scrollbarWidth / 2;
176
+ inlineScroll = targetInline - (left + width / 2) + scrollbarWidth / 2;
159
177
  } else if (inline === 'end') {
160
178
  inlineScroll = targetInline - right + borderRight + scrollbarWidth;
161
179
  } else {
162
- inlineScroll = alignNearest(_left, right, _width, borderLeft, borderRight + scrollbarWidth, targetInline, targetInline + targetWidth, targetWidth);
180
+ inlineScroll = alignNearest(left, right, width, borderLeft, borderRight + scrollbarWidth, targetInline, targetInline + targetWidth, targetWidth);
163
181
  }
164
182
 
165
183
  var scrollLeft = frame.scrollLeft,
166
184
  scrollTop = frame.scrollTop;
167
- blockScroll = Math.max(0, Math.min(scrollTop + blockScroll, frame.scrollHeight - _height + scrollbarHeight));
168
- inlineScroll = Math.max(0, Math.min(scrollLeft + inlineScroll, frame.scrollWidth - _width + scrollbarWidth));
185
+ blockScroll = Math.max(0, Math.min(scrollTop + blockScroll, frame.scrollHeight - height + scrollbarHeight));
186
+ inlineScroll = Math.max(0, Math.min(scrollLeft + inlineScroll, frame.scrollWidth - width + scrollbarWidth));
169
187
  targetBlock += scrollTop - blockScroll;
170
188
  targetInline += scrollLeft - inlineScroll;
171
189
  }
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.computeScrollIntoView=e()}(this,function(){"use strict";function t(t){return null!=t&&"object"==typeof t&&1===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 i=getComputedStyle(t,null);return e(i.overflowY,n)||e(i.overflowX,n)}return!1}function i(t,e,n,i,o,r,d,l){return r<t&&d>e||r>t&&d<e?0:r<=t&&l<=n||d>=e&&l>=n?r-t-i:d>e&&l<n||r<t&&l>n?d-e+o:0}return function(e,o){var r=o.scrollMode,d=o.block,l=o.inline,f=o.boundary,s=o.skipOverflowHiddenElements,u="function"==typeof f?f:function(t){return t!==f};if(!t(e))throw new TypeError("Invalid target");for(var h=document.scrollingElement||document.documentElement,c=[],a=e;t(a)&&u(a);){if((a=a.parentNode)===h){c.push(a);break}a===document.body&&n(a)&&!n(document.documentElement)||n(a,s)&&c.push(a)}for(var p=window.visualViewport?visualViewport.width:innerWidth,m=window.visualViewport?visualViewport.height:innerHeight,g=window.scrollX||pageXOffset,w=window.scrollY||pageYOffset,v=e.getBoundingClientRect(),b=v.height,y=v.width,W=v.top,H=v.right,M=v.bottom,x=v.left,I="start"===d||"nearest"===d?W:"end"===d?M:W+b/2,E="center"===l?x+y/2:"end"===l?H:x,V=[],C=0;C<c.length;C++){var T=c[C],k=T.getBoundingClientRect(),B=k.height,O=k.width,R=k.top,S=k.right,X=k.bottom,Y=k.left;if("if-needed"===r&&W>=0&&x>=0&&M<=m&&H<=p&&W>=R&&M<=X&&x>=Y&&H<=S)return V;var j=getComputedStyle(T),L=parseInt(j.borderLeftWidth,10),N=parseInt(j.borderTopWidth,10),q=parseInt(j.borderRightWidth,10),z=parseInt(j.borderBottomWidth,10),A=0,D=0,F="offsetWidth"in T?T.offsetWidth-T.clientWidth-L-q:0,G="offsetHeight"in T?T.offsetHeight-T.clientHeight-N-z:0;if(h===T)A="start"===d?I:"end"===d?I-m:"nearest"===d?i(w,w+m,m,N,z,w+I,w+I+b,b):I-m/2,D="start"===l?E:"center"===l?E-p/2:"end"===l?E-p:i(g,g+p,p,L,q,g+E,g+E+y,y),A=Math.max(0,A+w),D=Math.max(0,D+g);else{A="start"===d?I-R-N:"end"===d?I-X+z+G:"nearest"===d?i(R,X,B,N,z+G,I,I+b,b):I-(R+B/2)+G/2,D="start"===l?E-Y-L:"center"===l?E-(Y+O/2)+F/2:"end"===l?E-S+q+F:i(Y,S,O,L,q+F,E,E+y,y);var J=T.scrollLeft,K=T.scrollTop;I+=K-(A=Math.max(0,Math.min(K+A,T.scrollHeight-B+G))),E+=J-(D=Math.max(0,Math.min(J+D,T.scrollWidth-O+F)))}V.push({el:T,top:A,left:D})}return V}});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).computeScrollIntoView=t()}(this,(function(){"use strict";function e(e){return null!=e&&"object"==typeof e&&1===e.nodeType}function t(e,t){return(!t||"hidden"!==e)&&("visible"!==e&&"clip"!==e)}function n(e,n){if(e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth){var i=getComputedStyle(e,null);return t(i.overflowY,n)||t(i.overflowX,n)||function(e){var t=function(e){return e.ownerDocument&&e.ownerDocument.defaultView?e.ownerDocument.defaultView.frameElement:null}(e);return!!t&&(t.clientHeight<e.scrollHeight||t.clientWidth<e.scrollWidth)}(e)}return!1}function i(e,t,n,i,o,r,l,d){return r<e&&l>t||r>e&&l<t?0:r<=e&&d<=n||l>=t&&d>=n?r-e-i:l>t&&d<n||r<e&&d>n?l-t+o:0}return function(t,o){var r=o.scrollMode,l=o.block,d=o.inline,u=o.boundary,f=o.skipOverflowHiddenElements,c="function"==typeof u?u:function(e){return e!==u};if(!e(t))throw new TypeError("Invalid target");for(var h=document.scrollingElement||document.documentElement,s=[],a=t;e(a)&&c(a);){if((a=a.parentNode)===h){s.push(a);break}a===document.body&&n(a)&&!n(document.documentElement)||n(a,f)&&s.push(a)}for(var p=window.visualViewport?visualViewport.width:innerWidth,m=window.visualViewport?visualViewport.height:innerHeight,g=window.scrollX||pageXOffset,w=window.scrollY||pageYOffset,v=t.getBoundingClientRect(),b=v.height,W=v.width,y=v.top,H=v.right,M=v.bottom,V=v.left,x="start"===l||"nearest"===l?y:"end"===l?M:y+b/2,E="center"===d?V+W/2:"end"===d?H:V,I=[],C=0;C<s.length;C++){var T=s[C],k=T.getBoundingClientRect(),B=k.height,D=k.width,O=k.top,R=k.right,S=k.bottom,X=k.left;if("if-needed"===r&&y>=0&&V>=0&&M<=m&&H<=p&&y>=O&&M<=S&&V>=X&&H<=R)return I;var Y=getComputedStyle(T),j=parseInt(Y.borderLeftWidth,10),L=parseInt(Y.borderTopWidth,10),N=parseInt(Y.borderRightWidth,10),q=parseInt(Y.borderBottomWidth,10),z=0,A=0,F="offsetWidth"in T?T.offsetWidth-T.clientWidth-j-N:0,G="offsetHeight"in T?T.offsetHeight-T.clientHeight-L-q:0;if(h===T)z="start"===l?x:"end"===l?x-m:"nearest"===l?i(w,w+m,m,L,q,w+x,w+x+b,b):x-m/2,A="start"===d?E:"center"===d?E-p/2:"end"===d?E-p:i(g,g+p,p,j,N,g+E,g+E+W,W),z=Math.max(0,z+w),A=Math.max(0,A+g);else{z="start"===l?x-O-L:"end"===l?x-S+q+G:"nearest"===l?i(O,S,B,L,q+G,x,x+b,b):x-(O+B/2)+G/2,A="start"===d?E-X-j:"center"===d?E-(X+D/2)+F/2:"end"===d?E-R+N+F:i(X,R,D,j,N+F,E,E+W,W);var J=T.scrollLeft,K=T.scrollTop;x+=K-(z=Math.max(0,Math.min(K+z,T.scrollHeight-B+G))),E+=J-(A=Math.max(0,Math.min(J+A,T.scrollWidth-D+F)))}I.push({el:T,top:z,left:A})}return I}}));