An unfinished system to manage all your paper documentation in an easy way.
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.

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