Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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