You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1046 lines
33 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /**!
  2. * @fileOverview Kickass library to create and place poppers near their reference elements.
  3. * @version 1.14.5
  4. * @license
  5. * Copyright (c) 2016 Federico Zivolo and contributors
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. */
  25. /**
  26. * Get CSS computed property of the given element
  27. * @method
  28. * @memberof Popper.Utils
  29. * @argument {Eement} element
  30. * @argument {String} property
  31. */
  32. function getStyleComputedProperty(element, property) {
  33. if (element.nodeType !== 1) {
  34. return [];
  35. }
  36. // NOTE: 1 DOM access here
  37. const window = element.ownerDocument.defaultView;
  38. const css = window.getComputedStyle(element, null);
  39. return property ? css[property] : css;
  40. }
  41. /**
  42. * Returns the parentNode or the host of the element
  43. * @method
  44. * @memberof Popper.Utils
  45. * @argument {Element} element
  46. * @returns {Element} parent
  47. */
  48. function getParentNode(element) {
  49. if (element.nodeName === 'HTML') {
  50. return element;
  51. }
  52. return element.parentNode || element.host;
  53. }
  54. /**
  55. * Returns the scrolling parent of the given element
  56. * @method
  57. * @memberof Popper.Utils
  58. * @argument {Element} element
  59. * @returns {Element} scroll parent
  60. */
  61. function getScrollParent(element) {
  62. // Return body, `getScroll` will take care to get the correct `scrollTop` from it
  63. if (!element) {
  64. return document.body;
  65. }
  66. switch (element.nodeName) {
  67. case 'HTML':
  68. case 'BODY':
  69. return element.ownerDocument.body;
  70. case '#document':
  71. return element.body;
  72. }
  73. // Firefox want us to check `-x` and `-y` variations as well
  74. const { overflow, overflowX, overflowY } = getStyleComputedProperty(element);
  75. if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
  76. return element;
  77. }
  78. return getScrollParent(getParentNode(element));
  79. }
  80. var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
  81. const isIE11 = isBrowser && !!(window.MSInputMethodContext && document.documentMode);
  82. const isIE10 = isBrowser && /MSIE 10/.test(navigator.userAgent);
  83. /**
  84. * Determines if the browser is Internet Explorer
  85. * @method
  86. * @memberof Popper.Utils
  87. * @param {Number} version to check
  88. * @returns {Boolean} isIE
  89. */
  90. function isIE(version) {
  91. if (version === 11) {
  92. return isIE11;
  93. }
  94. if (version === 10) {
  95. return isIE10;
  96. }
  97. return isIE11 || isIE10;
  98. }
  99. /**
  100. * Returns the offset parent of the given element
  101. * @method
  102. * @memberof Popper.Utils
  103. * @argument {Element} element
  104. * @returns {Element} offset parent
  105. */
  106. function getOffsetParent(element) {
  107. if (!element) {
  108. return document.documentElement;
  109. }
  110. const noOffsetParent = isIE(10) ? document.body : null;
  111. // NOTE: 1 DOM access here
  112. let offsetParent = element.offsetParent || null;
  113. // Skip hidden elements which don't have an offsetParent
  114. while (offsetParent === noOffsetParent && element.nextElementSibling) {
  115. offsetParent = (element = element.nextElementSibling).offsetParent;
  116. }
  117. const nodeName = offsetParent && offsetParent.nodeName;
  118. if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
  119. return element ? element.ownerDocument.documentElement : document.documentElement;
  120. }
  121. // .offsetParent will return the closest TH, TD or TABLE in case
  122. // no offsetParent is present, I hate this job...
  123. if (['TH', 'TD', 'TABLE'].indexOf(offsetParent.nodeName) !== -1 && getStyleComputedProperty(offsetParent, 'position') === 'static') {
  124. return getOffsetParent(offsetParent);
  125. }
  126. return offsetParent;
  127. }
  128. function isOffsetContainer(element) {
  129. const { nodeName } = element;
  130. if (nodeName === 'BODY') {
  131. return false;
  132. }
  133. return nodeName === 'HTML' || getOffsetParent(element.firstElementChild) === element;
  134. }
  135. /**
  136. * Finds the root node (document, shadowDOM root) of the given element
  137. * @method
  138. * @memberof Popper.Utils
  139. * @argument {Element} node
  140. * @returns {Element} root node
  141. */
  142. function getRoot(node) {
  143. if (node.parentNode !== null) {
  144. return getRoot(node.parentNode);
  145. }
  146. return node;
  147. }
  148. /**
  149. * Finds the offset parent common to the two provided nodes
  150. * @method
  151. * @memberof Popper.Utils
  152. * @argument {Element} element1
  153. * @argument {Element} element2
  154. * @returns {Element} common offset parent
  155. */
  156. function findCommonOffsetParent(element1, element2) {
  157. // This check is needed to avoid errors in case one of the elements isn't defined for any reason
  158. if (!element1 || !element1.nodeType || !element2 || !element2.nodeType) {
  159. return document.documentElement;
  160. }
  161. // Here we make sure to give as "start" the element that comes first in the DOM
  162. const order = element1.compareDocumentPosition(element2) & Node.DOCUMENT_POSITION_FOLLOWING;
  163. const start = order ? element1 : element2;
  164. const end = order ? element2 : element1;
  165. // Get common ancestor container
  166. const range = document.createRange();
  167. range.setStart(start, 0);
  168. range.setEnd(end, 0);
  169. const { commonAncestorContainer } = range;
  170. // Both nodes are inside #document
  171. if (element1 !== commonAncestorContainer && element2 !== commonAncestorContainer || start.contains(end)) {
  172. if (isOffsetContainer(commonAncestorContainer)) {
  173. return commonAncestorContainer;
  174. }
  175. return getOffsetParent(commonAncestorContainer);
  176. }
  177. // one of the nodes is inside shadowDOM, find which one
  178. const element1root = getRoot(element1);
  179. if (element1root.host) {
  180. return findCommonOffsetParent(element1root.host, element2);
  181. } else {
  182. return findCommonOffsetParent(element1, getRoot(element2).host);
  183. }
  184. }
  185. /**
  186. * Gets the scroll value of the given element in the given side (top and left)
  187. * @method
  188. * @memberof Popper.Utils
  189. * @argument {Element} element
  190. * @argument {String} side `top` or `left`
  191. * @returns {number} amount of scrolled pixels
  192. */
  193. function getScroll(element, side = 'top') {
  194. const upperSide = side === 'top' ? 'scrollTop' : 'scrollLeft';
  195. const nodeName = element.nodeName;
  196. if (nodeName === 'BODY' || nodeName === 'HTML') {
  197. const html = element.ownerDocument.documentElement;
  198. const scrollingElement = element.ownerDocument.scrollingElement || html;
  199. return scrollingElement[upperSide];
  200. }
  201. return element[upperSide];
  202. }
  203. /*
  204. * Sum or subtract the element scroll values (left and top) from a given rect object
  205. * @method
  206. * @memberof Popper.Utils
  207. * @param {Object} rect - Rect object you want to change
  208. * @param {HTMLElement} element - The element from the function reads the scroll values
  209. * @param {Boolean} subtract - set to true if you want to subtract the scroll values
  210. * @return {Object} rect - The modifier rect object
  211. */
  212. function includeScroll(rect, element, subtract = false) {
  213. const scrollTop = getScroll(element, 'top');
  214. const scrollLeft = getScroll(element, 'left');
  215. const modifier = subtract ? -1 : 1;
  216. rect.top += scrollTop * modifier;
  217. rect.bottom += scrollTop * modifier;
  218. rect.left += scrollLeft * modifier;
  219. rect.right += scrollLeft * modifier;
  220. return rect;
  221. }
  222. /*
  223. * Helper to detect borders of a given element
  224. * @method
  225. * @memberof Popper.Utils
  226. * @param {CSSStyleDeclaration} styles
  227. * Result of `getStyleComputedProperty` on the given element
  228. * @param {String} axis - `x` or `y`
  229. * @return {number} borders - The borders size of the given axis
  230. */
  231. function getBordersSize(styles, axis) {
  232. const sideA = axis === 'x' ? 'Left' : 'Top';
  233. const sideB = sideA === 'Left' ? 'Right' : 'Bottom';
  234. return parseFloat(styles[`border${sideA}Width`], 10) + parseFloat(styles[`border${sideB}Width`], 10);
  235. }
  236. function getSize(axis, body, html, computedStyle) {
  237. return Math.max(body[`offset${axis}`], body[`scroll${axis}`], html[`client${axis}`], html[`offset${axis}`], html[`scroll${axis}`], isIE(10) ? parseInt(html[`offset${axis}`]) + parseInt(computedStyle[`margin${axis === 'Height' ? 'Top' : 'Left'}`]) + parseInt(computedStyle[`margin${axis === 'Height' ? 'Bottom' : 'Right'}`]) : 0);
  238. }
  239. function getWindowSizes(document) {
  240. const body = document.body;
  241. const html = document.documentElement;
  242. const computedStyle = isIE(10) && getComputedStyle(html);
  243. return {
  244. height: getSize('Height', body, html, computedStyle),
  245. width: getSize('Width', body, html, computedStyle)
  246. };
  247. }
  248. var _extends = Object.assign || function (target) {
  249. for (var i = 1; i < arguments.length; i++) {
  250. var source = arguments[i];
  251. for (var key in source) {
  252. if (Object.prototype.hasOwnProperty.call(source, key)) {
  253. target[key] = source[key];
  254. }
  255. }
  256. }
  257. return target;
  258. };
  259. /**
  260. * Given element offsets, generate an output similar to getBoundingClientRect
  261. * @method
  262. * @memberof Popper.Utils
  263. * @argument {Object} offsets
  264. * @returns {Object} ClientRect like output
  265. */
  266. function getClientRect(offsets) {
  267. return _extends({}, offsets, {
  268. right: offsets.left + offsets.width,
  269. bottom: offsets.top + offsets.height
  270. });
  271. }
  272. /**
  273. * Get bounding client rect of given element
  274. * @method
  275. * @memberof Popper.Utils
  276. * @param {HTMLElement} element
  277. * @return {Object} client rect
  278. */
  279. function getBoundingClientRect(element) {
  280. let rect = {};
  281. // IE10 10 FIX: Please, don't ask, the element isn't
  282. // considered in DOM in some circumstances...
  283. // This isn't reproducible in IE10 compatibility mode of IE11
  284. try {
  285. if (isIE(10)) {
  286. rect = element.getBoundingClientRect();
  287. const scrollTop = getScroll(element, 'top');
  288. const scrollLeft = getScroll(element, 'left');
  289. rect.top += scrollTop;
  290. rect.left += scrollLeft;
  291. rect.bottom += scrollTop;
  292. rect.right += scrollLeft;
  293. } else {
  294. rect = element.getBoundingClientRect();
  295. }
  296. } catch (e) {}
  297. const result = {
  298. left: rect.left,
  299. top: rect.top,
  300. width: rect.right - rect.left,
  301. height: rect.bottom - rect.top
  302. };
  303. // subtract scrollbar size from sizes
  304. const sizes = element.nodeName === 'HTML' ? getWindowSizes(element.ownerDocument) : {};
  305. const width = sizes.width || element.clientWidth || result.right - result.left;
  306. const height = sizes.height || element.clientHeight || result.bottom - result.top;
  307. let horizScrollbar = element.offsetWidth - width;
  308. let vertScrollbar = element.offsetHeight - height;
  309. // if an hypothetical scrollbar is detected, we must be sure it's not a `border`
  310. // we make this check conditional for performance reasons
  311. if (horizScrollbar || vertScrollbar) {
  312. const styles = getStyleComputedProperty(element);
  313. horizScrollbar -= getBordersSize(styles, 'x');
  314. vertScrollbar -= getBordersSize(styles, 'y');
  315. result.width -= horizScrollbar;
  316. result.height -= vertScrollbar;
  317. }
  318. return getClientRect(result);
  319. }
  320. function getOffsetRectRelativeToArbitraryNode(children, parent, fixedPosition = false) {
  321. const isIE10 = isIE(10);
  322. const isHTML = parent.nodeName === 'HTML';
  323. const childrenRect = getBoundingClientRect(children);
  324. const parentRect = getBoundingClientRect(parent);
  325. const scrollParent = getScrollParent(children);
  326. const styles = getStyleComputedProperty(parent);
  327. const borderTopWidth = parseFloat(styles.borderTopWidth, 10);
  328. const borderLeftWidth = parseFloat(styles.borderLeftWidth, 10);
  329. // In cases where the parent is fixed, we must ignore negative scroll in offset calc
  330. if (fixedPosition && isHTML) {
  331. parentRect.top = Math.max(parentRect.top, 0);
  332. parentRect.left = Math.max(parentRect.left, 0);
  333. }
  334. let offsets = getClientRect({
  335. top: childrenRect.top - parentRect.top - borderTopWidth,
  336. left: childrenRect.left - parentRect.left - borderLeftWidth,
  337. width: childrenRect.width,
  338. height: childrenRect.height
  339. });
  340. offsets.marginTop = 0;
  341. offsets.marginLeft = 0;
  342. // Subtract margins of documentElement in case it's being used as parent
  343. // we do this only on HTML because it's the only element that behaves
  344. // differently when margins are applied to it. The margins are included in
  345. // the box of the documentElement, in the other cases not.
  346. if (!isIE10 && isHTML) {
  347. const marginTop = parseFloat(styles.marginTop, 10);
  348. const marginLeft = parseFloat(styles.marginLeft, 10);
  349. offsets.top -= borderTopWidth - marginTop;
  350. offsets.bottom -= borderTopWidth - marginTop;
  351. offsets.left -= borderLeftWidth - marginLeft;
  352. offsets.right -= borderLeftWidth - marginLeft;
  353. // Attach marginTop and marginLeft because in some circumstances we may need them
  354. offsets.marginTop = marginTop;
  355. offsets.marginLeft = marginLeft;
  356. }
  357. if (isIE10 && !fixedPosition ? parent.contains(scrollParent) : parent === scrollParent && scrollParent.nodeName !== 'BODY') {
  358. offsets = includeScroll(offsets, parent);
  359. }
  360. return offsets;
  361. }
  362. function getViewportOffsetRectRelativeToArtbitraryNode(element, excludeScroll = false) {
  363. const html = element.ownerDocument.documentElement;
  364. const relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html);
  365. const width = Math.max(html.clientWidth, window.innerWidth || 0);
  366. const height = Math.max(html.clientHeight, window.innerHeight || 0);
  367. const scrollTop = !excludeScroll ? getScroll(html) : 0;
  368. const scrollLeft = !excludeScroll ? getScroll(html, 'left') : 0;
  369. const offset = {
  370. top: scrollTop - relativeOffset.top + relativeOffset.marginTop,
  371. left: scrollLeft - relativeOffset.left + relativeOffset.marginLeft,
  372. width,
  373. height
  374. };
  375. return getClientRect(offset);
  376. }
  377. /**
  378. * Check if the given element is fixed or is inside a fixed parent
  379. * @method
  380. * @memberof Popper.Utils
  381. * @argument {Element} element
  382. * @argument {Element} customContainer
  383. * @returns {Boolean} answer to "isFixed?"
  384. */
  385. function isFixed(element) {
  386. const nodeName = element.nodeName;
  387. if (nodeName === 'BODY' || nodeName === 'HTML') {
  388. return false;
  389. }
  390. if (getStyleComputedProperty(element, 'position') === 'fixed') {
  391. return true;
  392. }
  393. return isFixed(getParentNode(element));
  394. }
  395. /**
  396. * Finds the first parent of an element that has a transformed property defined
  397. * @method
  398. * @memberof Popper.Utils
  399. * @argument {Element} element
  400. * @returns {Element} first transformed parent or documentElement
  401. */
  402. function getFixedPositionOffsetParent(element) {
  403. // This check is needed to avoid errors in case one of the elements isn't defined for any reason
  404. if (!element || !element.parentElement || isIE()) {
  405. return document.documentElement;
  406. }
  407. let el = element.parentElement;
  408. while (el && getStyleComputedProperty(el, 'transform') === 'none') {
  409. el = el.parentElement;
  410. }
  411. return el || document.documentElement;
  412. }
  413. /**
  414. * Computed the boundaries limits and return them
  415. * @method
  416. * @memberof Popper.Utils
  417. * @param {HTMLElement} popper
  418. * @param {HTMLElement} reference
  419. * @param {number} padding
  420. * @param {HTMLElement} boundariesElement - Element used to define the boundaries
  421. * @param {Boolean} fixedPosition - Is in fixed position mode
  422. * @returns {Object} Coordinates of the boundaries
  423. */
  424. function getBoundaries(popper, reference, padding, boundariesElement, fixedPosition = false) {
  425. // NOTE: 1 DOM access here
  426. let boundaries = { top: 0, left: 0 };
  427. const offsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, reference);
  428. // Handle viewport case
  429. if (boundariesElement === 'viewport') {
  430. boundaries = getViewportOffsetRectRelativeToArtbitraryNode(offsetParent, fixedPosition);
  431. } else {
  432. // Handle other cases based on DOM element used as boundaries
  433. let boundariesNode;
  434. if (boundariesElement === 'scrollParent') {
  435. boundariesNode = getScrollParent(getParentNode(reference));
  436. if (boundariesNode.nodeName === 'BODY') {
  437. boundariesNode = popper.ownerDocument.documentElement;
  438. }
  439. } else if (boundariesElement === 'window') {
  440. boundariesNode = popper.ownerDocument.documentElement;
  441. } else {
  442. boundariesNode = boundariesElement;
  443. }
  444. const offsets = getOffsetRectRelativeToArbitraryNode(boundariesNode, offsetParent, fixedPosition);
  445. // In case of HTML, we need a different computation
  446. if (boundariesNode.nodeName === 'HTML' && !isFixed(offsetParent)) {
  447. const { height, width } = getWindowSizes(popper.ownerDocument);
  448. boundaries.top += offsets.top - offsets.marginTop;
  449. boundaries.bottom = height + offsets.top;
  450. boundaries.left += offsets.left - offsets.marginLeft;
  451. boundaries.right = width + offsets.left;
  452. } else {
  453. // for all the other DOM elements, this one is good
  454. boundaries = offsets;
  455. }
  456. }
  457. // Add paddings
  458. padding = padding || 0;
  459. const isPaddingNumber = typeof padding === 'number';
  460. boundaries.left += isPaddingNumber ? padding : padding.left || 0;
  461. boundaries.top += isPaddingNumber ? padding : padding.top || 0;
  462. boundaries.right -= isPaddingNumber ? padding : padding.right || 0;
  463. boundaries.bottom -= isPaddingNumber ? padding : padding.bottom || 0;
  464. return boundaries;
  465. }
  466. function getArea({ width, height }) {
  467. return width * height;
  468. }
  469. /**
  470. * Utility used to transform the `auto` placement to the placement with more
  471. * available space.
  472. * @method
  473. * @memberof Popper.Utils
  474. * @argument {Object} data - The data object generated by update method
  475. * @argument {Object} options - Modifiers configuration and options
  476. * @returns {Object} The data object, properly modified
  477. */
  478. function computeAutoPlacement(placement, refRect, popper, reference, boundariesElement, padding = 0) {
  479. if (placement.indexOf('auto') === -1) {
  480. return placement;
  481. }
  482. const boundaries = getBoundaries(popper, reference, padding, boundariesElement);
  483. const rects = {
  484. top: {
  485. width: boundaries.width,
  486. height: refRect.top - boundaries.top
  487. },
  488. right: {
  489. width: boundaries.right - refRect.right,
  490. height: boundaries.height
  491. },
  492. bottom: {
  493. width: boundaries.width,
  494. height: boundaries.bottom - refRect.bottom
  495. },
  496. left: {
  497. width: refRect.left - boundaries.left,
  498. height: boundaries.height
  499. }
  500. };
  501. const sortedAreas = Object.keys(rects).map(key => _extends({
  502. key
  503. }, rects[key], {
  504. area: getArea(rects[key])
  505. })).sort((a, b) => b.area - a.area);
  506. const filteredAreas = sortedAreas.filter(({ width, height }) => width >= popper.clientWidth && height >= popper.clientHeight);
  507. const computedPlacement = filteredAreas.length > 0 ? filteredAreas[0].key : sortedAreas[0].key;
  508. const variation = placement.split('-')[1];
  509. return computedPlacement + (variation ? `-${variation}` : '');
  510. }
  511. const longerTimeoutBrowsers = ['Edge', 'Trident', 'Firefox'];
  512. let timeoutDuration = 0;
  513. for (let i = 0; i < longerTimeoutBrowsers.length; i += 1) {
  514. if (isBrowser && navigator.userAgent.indexOf(longerTimeoutBrowsers[i]) >= 0) {
  515. timeoutDuration = 1;
  516. break;
  517. }
  518. }
  519. function microtaskDebounce(fn) {
  520. let called = false;
  521. return () => {
  522. if (called) {
  523. return;
  524. }
  525. called = true;
  526. window.Promise.resolve().then(() => {
  527. called = false;
  528. fn();
  529. });
  530. };
  531. }
  532. function taskDebounce(fn) {
  533. let scheduled = false;
  534. return () => {
  535. if (!scheduled) {
  536. scheduled = true;
  537. setTimeout(() => {
  538. scheduled = false;
  539. fn();
  540. }, timeoutDuration);
  541. }
  542. };
  543. }
  544. const supportsMicroTasks = isBrowser && window.Promise;
  545. /**
  546. * Create a debounced version of a method, that's asynchronously deferred
  547. * but called in the minimum time possible.
  548. *
  549. * @method
  550. * @memberof Popper.Utils
  551. * @argument {Function} fn
  552. * @returns {Function}
  553. */
  554. var debounce = supportsMicroTasks ? microtaskDebounce : taskDebounce;
  555. /**
  556. * Mimics the `find` method of Array
  557. * @method
  558. * @memberof Popper.Utils
  559. * @argument {Array} arr
  560. * @argument prop
  561. * @argument value
  562. * @returns index or -1
  563. */
  564. function find(arr, check) {
  565. // use native find if supported
  566. if (Array.prototype.find) {
  567. return arr.find(check);
  568. }
  569. // use `filter` to obtain the same behavior of `find`
  570. return arr.filter(check)[0];
  571. }
  572. /**
  573. * Return the index of the matching object
  574. * @method
  575. * @memberof Popper.Utils
  576. * @argument {Array} arr
  577. * @argument prop
  578. * @argument value
  579. * @returns index or -1
  580. */
  581. function findIndex(arr, prop, value) {
  582. // use native findIndex if supported
  583. if (Array.prototype.findIndex) {
  584. return arr.findIndex(cur => cur[prop] === value);
  585. }
  586. // use `find` + `indexOf` if `findIndex` isn't supported
  587. const match = find(arr, obj => obj[prop] === value);
  588. return arr.indexOf(match);
  589. }
  590. /**
  591. * Get the position of the given element, relative to its offset parent
  592. * @method
  593. * @memberof Popper.Utils
  594. * @param {Element} element
  595. * @return {Object} position - Coordinates of the element and its `scrollTop`
  596. */
  597. function getOffsetRect(element) {
  598. let elementRect;
  599. if (element.nodeName === 'HTML') {
  600. const { width, height } = getWindowSizes(element.ownerDocument);
  601. elementRect = {
  602. width,
  603. height,
  604. left: 0,
  605. top: 0
  606. };
  607. } else {
  608. elementRect = {
  609. width: element.offsetWidth,
  610. height: element.offsetHeight,
  611. left: element.offsetLeft,
  612. top: element.offsetTop
  613. };
  614. }
  615. // position
  616. return getClientRect(elementRect);
  617. }
  618. /**
  619. * Get the outer sizes of the given element (offset size + margins)
  620. * @method
  621. * @memberof Popper.Utils
  622. * @argument {Element} element
  623. * @returns {Object} object containing width and height properties
  624. */
  625. function getOuterSizes(element) {
  626. const window = element.ownerDocument.defaultView;
  627. const styles = window.getComputedStyle(element);
  628. const x = parseFloat(styles.marginTop) + parseFloat(styles.marginBottom);
  629. const y = parseFloat(styles.marginLeft) + parseFloat(styles.marginRight);
  630. const result = {
  631. width: element.offsetWidth + y,
  632. height: element.offsetHeight + x
  633. };
  634. return result;
  635. }
  636. /**
  637. * Get the opposite placement of the given one
  638. * @method
  639. * @memberof Popper.Utils
  640. * @argument {String} placement
  641. * @returns {String} flipped placement
  642. */
  643. function getOppositePlacement(placement) {
  644. const hash = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' };
  645. return placement.replace(/left|right|bottom|top/g, matched => hash[matched]);
  646. }
  647. /**
  648. * Get offsets to the popper
  649. * @method
  650. * @memberof Popper.Utils
  651. * @param {Object} position - CSS position the Popper will get applied
  652. * @param {HTMLElement} popper - the popper element
  653. * @param {Object} referenceOffsets - the reference offsets (the popper will be relative to this)
  654. * @param {String} placement - one of the valid placement options
  655. * @returns {Object} popperOffsets - An object containing the offsets which will be applied to the popper
  656. */
  657. function getPopperOffsets(popper, referenceOffsets, placement) {
  658. placement = placement.split('-')[0];
  659. // Get popper node sizes
  660. const popperRect = getOuterSizes(popper);
  661. // Add position, width and height to our offsets object
  662. const popperOffsets = {
  663. width: popperRect.width,
  664. height: popperRect.height
  665. };
  666. // depending by the popper placement we have to compute its offsets slightly differently
  667. const isHoriz = ['right', 'left'].indexOf(placement) !== -1;
  668. const mainSide = isHoriz ? 'top' : 'left';
  669. const secondarySide = isHoriz ? 'left' : 'top';
  670. const measurement = isHoriz ? 'height' : 'width';
  671. const secondaryMeasurement = !isHoriz ? 'height' : 'width';
  672. popperOffsets[mainSide] = referenceOffsets[mainSide] + referenceOffsets[measurement] / 2 - popperRect[measurement] / 2;
  673. if (placement === secondarySide) {
  674. popperOffsets[secondarySide] = referenceOffsets[secondarySide] - popperRect[secondaryMeasurement];
  675. } else {
  676. popperOffsets[secondarySide] = referenceOffsets[getOppositePlacement(secondarySide)];
  677. }
  678. return popperOffsets;
  679. }
  680. /**
  681. * Get offsets to the reference element
  682. * @method
  683. * @memberof Popper.Utils
  684. * @param {Object} state
  685. * @param {Element} popper - the popper element
  686. * @param {Element} reference - the reference element (the popper will be relative to this)
  687. * @param {Element} fixedPosition - is in fixed position mode
  688. * @returns {Object} An object containing the offsets which will be applied to the popper
  689. */
  690. function getReferenceOffsets(state, popper, reference, fixedPosition = null) {
  691. const commonOffsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, reference);
  692. return getOffsetRectRelativeToArbitraryNode(reference, commonOffsetParent, fixedPosition);
  693. }
  694. /**
  695. * Get the prefixed supported property name
  696. * @method
  697. * @memberof Popper.Utils
  698. * @argument {String} property (camelCase)
  699. * @returns {String} prefixed property (camelCase or PascalCase, depending on the vendor prefix)
  700. */
  701. function getSupportedPropertyName(property) {
  702. const prefixes = [false, 'ms', 'Webkit', 'Moz', 'O'];
  703. const upperProp = property.charAt(0).toUpperCase() + property.slice(1);
  704. for (let i = 0; i < prefixes.length; i++) {
  705. const prefix = prefixes[i];
  706. const toCheck = prefix ? `${prefix}${upperProp}` : property;
  707. if (typeof document.body.style[toCheck] !== 'undefined') {
  708. return toCheck;
  709. }
  710. }
  711. return null;
  712. }
  713. /**
  714. * Check if the given variable is a function
  715. * @method
  716. * @memberof Popper.Utils
  717. * @argument {Any} functionToCheck - variable to check
  718. * @returns {Boolean} answer to: is a function?
  719. */
  720. function isFunction(functionToCheck) {
  721. const getType = {};
  722. return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
  723. }
  724. /**
  725. * Helper used to know if the given modifier is enabled.
  726. * @method
  727. * @memberof Popper.Utils
  728. * @returns {Boolean}
  729. */
  730. function isModifierEnabled(modifiers, modifierName) {
  731. return modifiers.some(({ name, enabled }) => enabled && name === modifierName);
  732. }
  733. /**
  734. * Helper used to know if the given modifier depends from another one.<br />
  735. * It checks if the needed modifier is listed and enabled.
  736. * @method
  737. * @memberof Popper.Utils
  738. * @param {Array} modifiers - list of modifiers
  739. * @param {String} requestingName - name of requesting modifier
  740. * @param {String} requestedName - name of requested modifier
  741. * @returns {Boolean}
  742. */
  743. function isModifierRequired(modifiers, requestingName, requestedName) {
  744. const requesting = find(modifiers, ({ name }) => name === requestingName);
  745. const isRequired = !!requesting && modifiers.some(modifier => {
  746. return modifier.name === requestedName && modifier.enabled && modifier.order < requesting.order;
  747. });
  748. if (!isRequired) {
  749. const requesting = `\`${requestingName}\``;
  750. const requested = `\`${requestedName}\``;
  751. console.warn(`${requested} modifier is required by ${requesting} modifier in order to work, be sure to include it before ${requesting}!`);
  752. }
  753. return isRequired;
  754. }
  755. /**
  756. * Tells if a given input is a number
  757. * @method
  758. * @memberof Popper.Utils
  759. * @param {*} input to check
  760. * @return {Boolean}
  761. */
  762. function isNumeric(n) {
  763. return n !== '' && !isNaN(parseFloat(n)) && isFinite(n);
  764. }
  765. /**
  766. * Get the window associated with the element
  767. * @argument {Element} element
  768. * @returns {Window}
  769. */
  770. function getWindow(element) {
  771. const ownerDocument = element.ownerDocument;
  772. return ownerDocument ? ownerDocument.defaultView : window;
  773. }
  774. /**
  775. * Remove event listeners used to update the popper position
  776. * @method
  777. * @memberof Popper.Utils
  778. * @private
  779. */
  780. function removeEventListeners(reference, state) {
  781. // Remove resize event listener on window
  782. getWindow(reference).removeEventListener('resize', state.updateBound);
  783. // Remove scroll event listener on scroll parents
  784. state.scrollParents.forEach(target => {
  785. target.removeEventListener('scroll', state.updateBound);
  786. });
  787. // Reset state
  788. state.updateBound = null;
  789. state.scrollParents = [];
  790. state.scrollElement = null;
  791. state.eventsEnabled = false;
  792. return state;
  793. }
  794. /**
  795. * Loop trough the list of modifiers and run them in order,
  796. * each of them will then edit the data object.
  797. * @method
  798. * @memberof Popper.Utils
  799. * @param {dataObject} data
  800. * @param {Array} modifiers
  801. * @param {String} ends - Optional modifier name used as stopper
  802. * @returns {dataObject}
  803. */
  804. function runModifiers(modifiers, data, ends) {
  805. const modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex(modifiers, 'name', ends));
  806. modifiersToRun.forEach(modifier => {
  807. if (modifier['function']) {
  808. // eslint-disable-line dot-notation
  809. console.warn('`modifier.function` is deprecated, use `modifier.fn`!');
  810. }
  811. const fn = modifier['function'] || modifier.fn; // eslint-disable-line dot-notation
  812. if (modifier.enabled && isFunction(fn)) {
  813. // Add properties to offsets to make them a complete clientRect object
  814. // we do this before each modifier to make sure the previous one doesn't
  815. // mess with these values
  816. data.offsets.popper = getClientRect(data.offsets.popper);
  817. data.offsets.reference = getClientRect(data.offsets.reference);
  818. data = fn(data, modifier);
  819. }
  820. });
  821. return data;
  822. }
  823. /**
  824. * Set the attributes to the given popper
  825. * @method
  826. * @memberof Popper.Utils
  827. * @argument {Element} element - Element to apply the attributes to
  828. * @argument {Object} styles
  829. * Object with a list of properties and values which will be applied to the element
  830. */
  831. function setAttributes(element, attributes) {
  832. Object.keys(attributes).forEach(function (prop) {
  833. const value = attributes[prop];
  834. if (value !== false) {
  835. element.setAttribute(prop, attributes[prop]);
  836. } else {
  837. element.removeAttribute(prop);
  838. }
  839. });
  840. }
  841. /**
  842. * Set the style to the given popper
  843. * @method
  844. * @memberof Popper.Utils
  845. * @argument {Element} element - Element to apply the style to
  846. * @argument {Object} styles
  847. * Object with a list of properties and values which will be applied to the element
  848. */
  849. function setStyles(element, styles) {
  850. Object.keys(styles).forEach(prop => {
  851. let unit = '';
  852. // add unit if the value is numeric and is one of the following
  853. if (['width', 'height', 'top', 'right', 'bottom', 'left'].indexOf(prop) !== -1 && isNumeric(styles[prop])) {
  854. unit = 'px';
  855. }
  856. element.style[prop] = styles[prop] + unit;
  857. });
  858. }
  859. function attachToScrollParents(scrollParent, event, callback, scrollParents) {
  860. const isBody = scrollParent.nodeName === 'BODY';
  861. const target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent;
  862. target.addEventListener(event, callback, { passive: true });
  863. if (!isBody) {
  864. attachToScrollParents(getScrollParent(target.parentNode), event, callback, scrollParents);
  865. }
  866. scrollParents.push(target);
  867. }
  868. /**
  869. * Setup needed event listeners used to update the popper position
  870. * @method
  871. * @memberof Popper.Utils
  872. * @private
  873. */
  874. function setupEventListeners(reference, options, state, updateBound) {
  875. // Resize event listener on window
  876. state.updateBound = updateBound;
  877. getWindow(reference).addEventListener('resize', state.updateBound, { passive: true });
  878. // Scroll event listener on scroll parents
  879. const scrollElement = getScrollParent(reference);
  880. attachToScrollParents(scrollElement, 'scroll', state.updateBound, state.scrollParents);
  881. state.scrollElement = scrollElement;
  882. state.eventsEnabled = true;
  883. return state;
  884. }
  885. // This is here just for backward compatibility with versions lower than v1.10.3
  886. // you should import the utilities using named exports, if you want them all use:
  887. // ```
  888. // import * as PopperUtils from 'popper-utils';
  889. // ```
  890. // The default export will be removed in the next major version.
  891. var index = {
  892. computeAutoPlacement,
  893. debounce,
  894. findIndex,
  895. getBordersSize,
  896. getBoundaries,
  897. getBoundingClientRect,
  898. getClientRect,
  899. getOffsetParent,
  900. getOffsetRect,
  901. getOffsetRectRelativeToArbitraryNode,
  902. getOuterSizes,
  903. getParentNode,
  904. getPopperOffsets,
  905. getReferenceOffsets,
  906. getScroll,
  907. getScrollParent,
  908. getStyleComputedProperty,
  909. getSupportedPropertyName,
  910. getWindowSizes,
  911. isFixed,
  912. isFunction,
  913. isModifierEnabled,
  914. isModifierRequired,
  915. isNumeric,
  916. removeEventListeners,
  917. runModifiers,
  918. setAttributes,
  919. setStyles,
  920. setupEventListeners
  921. };
  922. export { computeAutoPlacement, debounce, findIndex, getBordersSize, getBoundaries, getBoundingClientRect, getClientRect, getOffsetParent, getOffsetRect, getOffsetRectRelativeToArbitraryNode, getOuterSizes, getParentNode, getPopperOffsets, getReferenceOffsets, getScroll, getScrollParent, getStyleComputedProperty, getSupportedPropertyName, getWindowSizes, isFixed, isFunction, isModifierEnabled, isModifierRequired, isNumeric, removeEventListeners, runModifiers, setAttributes, setStyles, setupEventListeners };
  923. export default index;
  924. //# sourceMappingURL=popper-utils.js.map