popper.js 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450
  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. var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
  26. const longerTimeoutBrowsers = ['Edge', 'Trident', 'Firefox'];
  27. let timeoutDuration = 0;
  28. for (let i = 0; i < longerTimeoutBrowsers.length; i += 1) {
  29. if (isBrowser && navigator.userAgent.indexOf(longerTimeoutBrowsers[i]) >= 0) {
  30. timeoutDuration = 1;
  31. break;
  32. }
  33. }
  34. function microtaskDebounce(fn) {
  35. let called = false;
  36. return () => {
  37. if (called) {
  38. return;
  39. }
  40. called = true;
  41. window.Promise.resolve().then(() => {
  42. called = false;
  43. fn();
  44. });
  45. };
  46. }
  47. function taskDebounce(fn) {
  48. let scheduled = false;
  49. return () => {
  50. if (!scheduled) {
  51. scheduled = true;
  52. setTimeout(() => {
  53. scheduled = false;
  54. fn();
  55. }, timeoutDuration);
  56. }
  57. };
  58. }
  59. const supportsMicroTasks = isBrowser && window.Promise;
  60. /**
  61. * Create a debounced version of a method, that's asynchronously deferred
  62. * but called in the minimum time possible.
  63. *
  64. * @method
  65. * @memberof Popper.Utils
  66. * @argument {Function} fn
  67. * @returns {Function}
  68. */
  69. var debounce = supportsMicroTasks ? microtaskDebounce : taskDebounce;
  70. /**
  71. * Check if the given variable is a function
  72. * @method
  73. * @memberof Popper.Utils
  74. * @argument {Any} functionToCheck - variable to check
  75. * @returns {Boolean} answer to: is a function?
  76. */
  77. function isFunction(functionToCheck) {
  78. const getType = {};
  79. return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
  80. }
  81. /**
  82. * Get CSS computed property of the given element
  83. * @method
  84. * @memberof Popper.Utils
  85. * @argument {Eement} element
  86. * @argument {String} property
  87. */
  88. function getStyleComputedProperty(element, property) {
  89. if (element.nodeType !== 1) {
  90. return [];
  91. }
  92. // NOTE: 1 DOM access here
  93. const window = element.ownerDocument.defaultView;
  94. const css = window.getComputedStyle(element, null);
  95. return property ? css[property] : css;
  96. }
  97. /**
  98. * Returns the parentNode or the host of the element
  99. * @method
  100. * @memberof Popper.Utils
  101. * @argument {Element} element
  102. * @returns {Element} parent
  103. */
  104. function getParentNode(element) {
  105. if (element.nodeName === 'HTML') {
  106. return element;
  107. }
  108. return element.parentNode || element.host;
  109. }
  110. /**
  111. * Returns the scrolling parent of the given element
  112. * @method
  113. * @memberof Popper.Utils
  114. * @argument {Element} element
  115. * @returns {Element} scroll parent
  116. */
  117. function getScrollParent(element) {
  118. // Return body, `getScroll` will take care to get the correct `scrollTop` from it
  119. if (!element) {
  120. return document.body;
  121. }
  122. switch (element.nodeName) {
  123. case 'HTML':
  124. case 'BODY':
  125. return element.ownerDocument.body;
  126. case '#document':
  127. return element.body;
  128. }
  129. // Firefox want us to check `-x` and `-y` variations as well
  130. const { overflow, overflowX, overflowY } = getStyleComputedProperty(element);
  131. if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
  132. return element;
  133. }
  134. return getScrollParent(getParentNode(element));
  135. }
  136. const isIE11 = isBrowser && !!(window.MSInputMethodContext && document.documentMode);
  137. const isIE10 = isBrowser && /MSIE 10/.test(navigator.userAgent);
  138. /**
  139. * Determines if the browser is Internet Explorer
  140. * @method
  141. * @memberof Popper.Utils
  142. * @param {Number} version to check
  143. * @returns {Boolean} isIE
  144. */
  145. function isIE(version) {
  146. if (version === 11) {
  147. return isIE11;
  148. }
  149. if (version === 10) {
  150. return isIE10;
  151. }
  152. return isIE11 || isIE10;
  153. }
  154. /**
  155. * Returns the offset parent of the given element
  156. * @method
  157. * @memberof Popper.Utils
  158. * @argument {Element} element
  159. * @returns {Element} offset parent
  160. */
  161. function getOffsetParent(element) {
  162. if (!element) {
  163. return document.documentElement;
  164. }
  165. const noOffsetParent = isIE(10) ? document.body : null;
  166. // NOTE: 1 DOM access here
  167. let offsetParent = element.offsetParent || null;
  168. // Skip hidden elements which don't have an offsetParent
  169. while (offsetParent === noOffsetParent && element.nextElementSibling) {
  170. offsetParent = (element = element.nextElementSibling).offsetParent;
  171. }
  172. const nodeName = offsetParent && offsetParent.nodeName;
  173. if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
  174. return element ? element.ownerDocument.documentElement : document.documentElement;
  175. }
  176. // .offsetParent will return the closest TH, TD or TABLE in case
  177. // no offsetParent is present, I hate this job...
  178. if (['TH', 'TD', 'TABLE'].indexOf(offsetParent.nodeName) !== -1 && getStyleComputedProperty(offsetParent, 'position') === 'static') {
  179. return getOffsetParent(offsetParent);
  180. }
  181. return offsetParent;
  182. }
  183. function isOffsetContainer(element) {
  184. const { nodeName } = element;
  185. if (nodeName === 'BODY') {
  186. return false;
  187. }
  188. return nodeName === 'HTML' || getOffsetParent(element.firstElementChild) === element;
  189. }
  190. /**
  191. * Finds the root node (document, shadowDOM root) of the given element
  192. * @method
  193. * @memberof Popper.Utils
  194. * @argument {Element} node
  195. * @returns {Element} root node
  196. */
  197. function getRoot(node) {
  198. if (node.parentNode !== null) {
  199. return getRoot(node.parentNode);
  200. }
  201. return node;
  202. }
  203. /**
  204. * Finds the offset parent common to the two provided nodes
  205. * @method
  206. * @memberof Popper.Utils
  207. * @argument {Element} element1
  208. * @argument {Element} element2
  209. * @returns {Element} common offset parent
  210. */
  211. function findCommonOffsetParent(element1, element2) {
  212. // This check is needed to avoid errors in case one of the elements isn't defined for any reason
  213. if (!element1 || !element1.nodeType || !element2 || !element2.nodeType) {
  214. return document.documentElement;
  215. }
  216. // Here we make sure to give as "start" the element that comes first in the DOM
  217. const order = element1.compareDocumentPosition(element2) & Node.DOCUMENT_POSITION_FOLLOWING;
  218. const start = order ? element1 : element2;
  219. const end = order ? element2 : element1;
  220. // Get common ancestor container
  221. const range = document.createRange();
  222. range.setStart(start, 0);
  223. range.setEnd(end, 0);
  224. const { commonAncestorContainer } = range;
  225. // Both nodes are inside #document
  226. if (element1 !== commonAncestorContainer && element2 !== commonAncestorContainer || start.contains(end)) {
  227. if (isOffsetContainer(commonAncestorContainer)) {
  228. return commonAncestorContainer;
  229. }
  230. return getOffsetParent(commonAncestorContainer);
  231. }
  232. // one of the nodes is inside shadowDOM, find which one
  233. const element1root = getRoot(element1);
  234. if (element1root.host) {
  235. return findCommonOffsetParent(element1root.host, element2);
  236. } else {
  237. return findCommonOffsetParent(element1, getRoot(element2).host);
  238. }
  239. }
  240. /**
  241. * Gets the scroll value of the given element in the given side (top and left)
  242. * @method
  243. * @memberof Popper.Utils
  244. * @argument {Element} element
  245. * @argument {String} side `top` or `left`
  246. * @returns {number} amount of scrolled pixels
  247. */
  248. function getScroll(element, side = 'top') {
  249. const upperSide = side === 'top' ? 'scrollTop' : 'scrollLeft';
  250. const nodeName = element.nodeName;
  251. if (nodeName === 'BODY' || nodeName === 'HTML') {
  252. const html = element.ownerDocument.documentElement;
  253. const scrollingElement = element.ownerDocument.scrollingElement || html;
  254. return scrollingElement[upperSide];
  255. }
  256. return element[upperSide];
  257. }
  258. /*
  259. * Sum or subtract the element scroll values (left and top) from a given rect object
  260. * @method
  261. * @memberof Popper.Utils
  262. * @param {Object} rect - Rect object you want to change
  263. * @param {HTMLElement} element - The element from the function reads the scroll values
  264. * @param {Boolean} subtract - set to true if you want to subtract the scroll values
  265. * @return {Object} rect - The modifier rect object
  266. */
  267. function includeScroll(rect, element, subtract = false) {
  268. const scrollTop = getScroll(element, 'top');
  269. const scrollLeft = getScroll(element, 'left');
  270. const modifier = subtract ? -1 : 1;
  271. rect.top += scrollTop * modifier;
  272. rect.bottom += scrollTop * modifier;
  273. rect.left += scrollLeft * modifier;
  274. rect.right += scrollLeft * modifier;
  275. return rect;
  276. }
  277. /*
  278. * Helper to detect borders of a given element
  279. * @method
  280. * @memberof Popper.Utils
  281. * @param {CSSStyleDeclaration} styles
  282. * Result of `getStyleComputedProperty` on the given element
  283. * @param {String} axis - `x` or `y`
  284. * @return {number} borders - The borders size of the given axis
  285. */
  286. function getBordersSize(styles, axis) {
  287. const sideA = axis === 'x' ? 'Left' : 'Top';
  288. const sideB = sideA === 'Left' ? 'Right' : 'Bottom';
  289. return parseFloat(styles[`border${sideA}Width`], 10) + parseFloat(styles[`border${sideB}Width`], 10);
  290. }
  291. function getSize(axis, body, html, computedStyle) {
  292. 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);
  293. }
  294. function getWindowSizes(document) {
  295. const body = document.body;
  296. const html = document.documentElement;
  297. const computedStyle = isIE(10) && getComputedStyle(html);
  298. return {
  299. height: getSize('Height', body, html, computedStyle),
  300. width: getSize('Width', body, html, computedStyle)
  301. };
  302. }
  303. var _extends = Object.assign || function (target) {
  304. for (var i = 1; i < arguments.length; i++) {
  305. var source = arguments[i];
  306. for (var key in source) {
  307. if (Object.prototype.hasOwnProperty.call(source, key)) {
  308. target[key] = source[key];
  309. }
  310. }
  311. }
  312. return target;
  313. };
  314. /**
  315. * Given element offsets, generate an output similar to getBoundingClientRect
  316. * @method
  317. * @memberof Popper.Utils
  318. * @argument {Object} offsets
  319. * @returns {Object} ClientRect like output
  320. */
  321. function getClientRect(offsets) {
  322. return _extends({}, offsets, {
  323. right: offsets.left + offsets.width,
  324. bottom: offsets.top + offsets.height
  325. });
  326. }
  327. /**
  328. * Get bounding client rect of given element
  329. * @method
  330. * @memberof Popper.Utils
  331. * @param {HTMLElement} element
  332. * @return {Object} client rect
  333. */
  334. function getBoundingClientRect(element) {
  335. let rect = {};
  336. // IE10 10 FIX: Please, don't ask, the element isn't
  337. // considered in DOM in some circumstances...
  338. // This isn't reproducible in IE10 compatibility mode of IE11
  339. try {
  340. if (isIE(10)) {
  341. rect = element.getBoundingClientRect();
  342. const scrollTop = getScroll(element, 'top');
  343. const scrollLeft = getScroll(element, 'left');
  344. rect.top += scrollTop;
  345. rect.left += scrollLeft;
  346. rect.bottom += scrollTop;
  347. rect.right += scrollLeft;
  348. } else {
  349. rect = element.getBoundingClientRect();
  350. }
  351. } catch (e) {}
  352. const result = {
  353. left: rect.left,
  354. top: rect.top,
  355. width: rect.right - rect.left,
  356. height: rect.bottom - rect.top
  357. };
  358. // subtract scrollbar size from sizes
  359. const sizes = element.nodeName === 'HTML' ? getWindowSizes(element.ownerDocument) : {};
  360. const width = sizes.width || element.clientWidth || result.right - result.left;
  361. const height = sizes.height || element.clientHeight || result.bottom - result.top;
  362. let horizScrollbar = element.offsetWidth - width;
  363. let vertScrollbar = element.offsetHeight - height;
  364. // if an hypothetical scrollbar is detected, we must be sure it's not a `border`
  365. // we make this check conditional for performance reasons
  366. if (horizScrollbar || vertScrollbar) {
  367. const styles = getStyleComputedProperty(element);
  368. horizScrollbar -= getBordersSize(styles, 'x');
  369. vertScrollbar -= getBordersSize(styles, 'y');
  370. result.width -= horizScrollbar;
  371. result.height -= vertScrollbar;
  372. }
  373. return getClientRect(result);
  374. }
  375. function getOffsetRectRelativeToArbitraryNode(children, parent, fixedPosition = false) {
  376. const isIE10 = isIE(10);
  377. const isHTML = parent.nodeName === 'HTML';
  378. const childrenRect = getBoundingClientRect(children);
  379. const parentRect = getBoundingClientRect(parent);
  380. const scrollParent = getScrollParent(children);
  381. const styles = getStyleComputedProperty(parent);
  382. const borderTopWidth = parseFloat(styles.borderTopWidth, 10);
  383. const borderLeftWidth = parseFloat(styles.borderLeftWidth, 10);
  384. // In cases where the parent is fixed, we must ignore negative scroll in offset calc
  385. if (fixedPosition && isHTML) {
  386. parentRect.top = Math.max(parentRect.top, 0);
  387. parentRect.left = Math.max(parentRect.left, 0);
  388. }
  389. let offsets = getClientRect({
  390. top: childrenRect.top - parentRect.top - borderTopWidth,
  391. left: childrenRect.left - parentRect.left - borderLeftWidth,
  392. width: childrenRect.width,
  393. height: childrenRect.height
  394. });
  395. offsets.marginTop = 0;
  396. offsets.marginLeft = 0;
  397. // Subtract margins of documentElement in case it's being used as parent
  398. // we do this only on HTML because it's the only element that behaves
  399. // differently when margins are applied to it. The margins are included in
  400. // the box of the documentElement, in the other cases not.
  401. if (!isIE10 && isHTML) {
  402. const marginTop = parseFloat(styles.marginTop, 10);
  403. const marginLeft = parseFloat(styles.marginLeft, 10);
  404. offsets.top -= borderTopWidth - marginTop;
  405. offsets.bottom -= borderTopWidth - marginTop;
  406. offsets.left -= borderLeftWidth - marginLeft;
  407. offsets.right -= borderLeftWidth - marginLeft;
  408. // Attach marginTop and marginLeft because in some circumstances we may need them
  409. offsets.marginTop = marginTop;
  410. offsets.marginLeft = marginLeft;
  411. }
  412. if (isIE10 && !fixedPosition ? parent.contains(scrollParent) : parent === scrollParent && scrollParent.nodeName !== 'BODY') {
  413. offsets = includeScroll(offsets, parent);
  414. }
  415. return offsets;
  416. }
  417. function getViewportOffsetRectRelativeToArtbitraryNode(element, excludeScroll = false) {
  418. const html = element.ownerDocument.documentElement;
  419. const relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html);
  420. const width = Math.max(html.clientWidth, window.innerWidth || 0);
  421. const height = Math.max(html.clientHeight, window.innerHeight || 0);
  422. const scrollTop = !excludeScroll ? getScroll(html) : 0;
  423. const scrollLeft = !excludeScroll ? getScroll(html, 'left') : 0;
  424. const offset = {
  425. top: scrollTop - relativeOffset.top + relativeOffset.marginTop,
  426. left: scrollLeft - relativeOffset.left + relativeOffset.marginLeft,
  427. width,
  428. height
  429. };
  430. return getClientRect(offset);
  431. }
  432. /**
  433. * Check if the given element is fixed or is inside a fixed parent
  434. * @method
  435. * @memberof Popper.Utils
  436. * @argument {Element} element
  437. * @argument {Element} customContainer
  438. * @returns {Boolean} answer to "isFixed?"
  439. */
  440. function isFixed(element) {
  441. const nodeName = element.nodeName;
  442. if (nodeName === 'BODY' || nodeName === 'HTML') {
  443. return false;
  444. }
  445. if (getStyleComputedProperty(element, 'position') === 'fixed') {
  446. return true;
  447. }
  448. const parentNode = getParentNode(element);
  449. if (!parentNode) {
  450. return false;
  451. }
  452. return isFixed(parentNode);
  453. }
  454. /**
  455. * Finds the first parent of an element that has a transformed property defined
  456. * @method
  457. * @memberof Popper.Utils
  458. * @argument {Element} element
  459. * @returns {Element} first transformed parent or documentElement
  460. */
  461. function getFixedPositionOffsetParent(element) {
  462. // This check is needed to avoid errors in case one of the elements isn't defined for any reason
  463. if (!element || !element.parentElement || isIE()) {
  464. return document.documentElement;
  465. }
  466. let el = element.parentElement;
  467. while (el && getStyleComputedProperty(el, 'transform') === 'none') {
  468. el = el.parentElement;
  469. }
  470. return el || document.documentElement;
  471. }
  472. /**
  473. * Computed the boundaries limits and return them
  474. * @method
  475. * @memberof Popper.Utils
  476. * @param {HTMLElement} popper
  477. * @param {HTMLElement} reference
  478. * @param {number} padding
  479. * @param {HTMLElement} boundariesElement - Element used to define the boundaries
  480. * @param {Boolean} fixedPosition - Is in fixed position mode
  481. * @returns {Object} Coordinates of the boundaries
  482. */
  483. function getBoundaries(popper, reference, padding, boundariesElement, fixedPosition = false) {
  484. // NOTE: 1 DOM access here
  485. let boundaries = { top: 0, left: 0 };
  486. const offsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, reference);
  487. // Handle viewport case
  488. if (boundariesElement === 'viewport') {
  489. boundaries = getViewportOffsetRectRelativeToArtbitraryNode(offsetParent, fixedPosition);
  490. } else {
  491. // Handle other cases based on DOM element used as boundaries
  492. let boundariesNode;
  493. if (boundariesElement === 'scrollParent') {
  494. boundariesNode = getScrollParent(getParentNode(reference));
  495. if (boundariesNode.nodeName === 'BODY') {
  496. boundariesNode = popper.ownerDocument.documentElement;
  497. }
  498. } else if (boundariesElement === 'window') {
  499. boundariesNode = popper.ownerDocument.documentElement;
  500. } else {
  501. boundariesNode = boundariesElement;
  502. }
  503. const offsets = getOffsetRectRelativeToArbitraryNode(boundariesNode, offsetParent, fixedPosition);
  504. // In case of HTML, we need a different computation
  505. if (boundariesNode.nodeName === 'HTML' && !isFixed(offsetParent)) {
  506. const { height, width } = getWindowSizes(popper.ownerDocument);
  507. boundaries.top += offsets.top - offsets.marginTop;
  508. boundaries.bottom = height + offsets.top;
  509. boundaries.left += offsets.left - offsets.marginLeft;
  510. boundaries.right = width + offsets.left;
  511. } else {
  512. // for all the other DOM elements, this one is good
  513. boundaries = offsets;
  514. }
  515. }
  516. // Add paddings
  517. padding = padding || 0;
  518. const isPaddingNumber = typeof padding === 'number';
  519. boundaries.left += isPaddingNumber ? padding : padding.left || 0;
  520. boundaries.top += isPaddingNumber ? padding : padding.top || 0;
  521. boundaries.right -= isPaddingNumber ? padding : padding.right || 0;
  522. boundaries.bottom -= isPaddingNumber ? padding : padding.bottom || 0;
  523. return boundaries;
  524. }
  525. function getArea({ width, height }) {
  526. return width * height;
  527. }
  528. /**
  529. * Utility used to transform the `auto` placement to the placement with more
  530. * available space.
  531. * @method
  532. * @memberof Popper.Utils
  533. * @argument {Object} data - The data object generated by update method
  534. * @argument {Object} options - Modifiers configuration and options
  535. * @returns {Object} The data object, properly modified
  536. */
  537. function computeAutoPlacement(placement, refRect, popper, reference, boundariesElement, padding = 0) {
  538. if (placement.indexOf('auto') === -1) {
  539. return placement;
  540. }
  541. const boundaries = getBoundaries(popper, reference, padding, boundariesElement);
  542. const rects = {
  543. top: {
  544. width: boundaries.width,
  545. height: refRect.top - boundaries.top
  546. },
  547. right: {
  548. width: boundaries.right - refRect.right,
  549. height: boundaries.height
  550. },
  551. bottom: {
  552. width: boundaries.width,
  553. height: boundaries.bottom - refRect.bottom
  554. },
  555. left: {
  556. width: refRect.left - boundaries.left,
  557. height: boundaries.height
  558. }
  559. };
  560. const sortedAreas = Object.keys(rects).map(key => _extends({
  561. key
  562. }, rects[key], {
  563. area: getArea(rects[key])
  564. })).sort((a, b) => b.area - a.area);
  565. const filteredAreas = sortedAreas.filter(({ width, height }) => width >= popper.clientWidth && height >= popper.clientHeight);
  566. const computedPlacement = filteredAreas.length > 0 ? filteredAreas[0].key : sortedAreas[0].key;
  567. const variation = placement.split('-')[1];
  568. return computedPlacement + (variation ? `-${variation}` : '');
  569. }
  570. /**
  571. * Get offsets to the reference element
  572. * @method
  573. * @memberof Popper.Utils
  574. * @param {Object} state
  575. * @param {Element} popper - the popper element
  576. * @param {Element} reference - the reference element (the popper will be relative to this)
  577. * @param {Element} fixedPosition - is in fixed position mode
  578. * @returns {Object} An object containing the offsets which will be applied to the popper
  579. */
  580. function getReferenceOffsets(state, popper, reference, fixedPosition = null) {
  581. const commonOffsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, reference);
  582. return getOffsetRectRelativeToArbitraryNode(reference, commonOffsetParent, fixedPosition);
  583. }
  584. /**
  585. * Get the outer sizes of the given element (offset size + margins)
  586. * @method
  587. * @memberof Popper.Utils
  588. * @argument {Element} element
  589. * @returns {Object} object containing width and height properties
  590. */
  591. function getOuterSizes(element) {
  592. const window = element.ownerDocument.defaultView;
  593. const styles = window.getComputedStyle(element);
  594. const x = parseFloat(styles.marginTop || 0) + parseFloat(styles.marginBottom || 0);
  595. const y = parseFloat(styles.marginLeft || 0) + parseFloat(styles.marginRight || 0);
  596. const result = {
  597. width: element.offsetWidth + y,
  598. height: element.offsetHeight + x
  599. };
  600. return result;
  601. }
  602. /**
  603. * Get the opposite placement of the given one
  604. * @method
  605. * @memberof Popper.Utils
  606. * @argument {String} placement
  607. * @returns {String} flipped placement
  608. */
  609. function getOppositePlacement(placement) {
  610. const hash = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' };
  611. return placement.replace(/left|right|bottom|top/g, matched => hash[matched]);
  612. }
  613. /**
  614. * Get offsets to the popper
  615. * @method
  616. * @memberof Popper.Utils
  617. * @param {Object} position - CSS position the Popper will get applied
  618. * @param {HTMLElement} popper - the popper element
  619. * @param {Object} referenceOffsets - the reference offsets (the popper will be relative to this)
  620. * @param {String} placement - one of the valid placement options
  621. * @returns {Object} popperOffsets - An object containing the offsets which will be applied to the popper
  622. */
  623. function getPopperOffsets(popper, referenceOffsets, placement) {
  624. placement = placement.split('-')[0];
  625. // Get popper node sizes
  626. const popperRect = getOuterSizes(popper);
  627. // Add position, width and height to our offsets object
  628. const popperOffsets = {
  629. width: popperRect.width,
  630. height: popperRect.height
  631. };
  632. // depending by the popper placement we have to compute its offsets slightly differently
  633. const isHoriz = ['right', 'left'].indexOf(placement) !== -1;
  634. const mainSide = isHoriz ? 'top' : 'left';
  635. const secondarySide = isHoriz ? 'left' : 'top';
  636. const measurement = isHoriz ? 'height' : 'width';
  637. const secondaryMeasurement = !isHoriz ? 'height' : 'width';
  638. popperOffsets[mainSide] = referenceOffsets[mainSide] + referenceOffsets[measurement] / 2 - popperRect[measurement] / 2;
  639. if (placement === secondarySide) {
  640. popperOffsets[secondarySide] = referenceOffsets[secondarySide] - popperRect[secondaryMeasurement];
  641. } else {
  642. popperOffsets[secondarySide] = referenceOffsets[getOppositePlacement(secondarySide)];
  643. }
  644. return popperOffsets;
  645. }
  646. /**
  647. * Mimics the `find` method of Array
  648. * @method
  649. * @memberof Popper.Utils
  650. * @argument {Array} arr
  651. * @argument prop
  652. * @argument value
  653. * @returns index or -1
  654. */
  655. function find(arr, check) {
  656. // use native find if supported
  657. if (Array.prototype.find) {
  658. return arr.find(check);
  659. }
  660. // use `filter` to obtain the same behavior of `find`
  661. return arr.filter(check)[0];
  662. }
  663. /**
  664. * Return the index of the matching object
  665. * @method
  666. * @memberof Popper.Utils
  667. * @argument {Array} arr
  668. * @argument prop
  669. * @argument value
  670. * @returns index or -1
  671. */
  672. function findIndex(arr, prop, value) {
  673. // use native findIndex if supported
  674. if (Array.prototype.findIndex) {
  675. return arr.findIndex(cur => cur[prop] === value);
  676. }
  677. // use `find` + `indexOf` if `findIndex` isn't supported
  678. const match = find(arr, obj => obj[prop] === value);
  679. return arr.indexOf(match);
  680. }
  681. /**
  682. * Loop trough the list of modifiers and run them in order,
  683. * each of them will then edit the data object.
  684. * @method
  685. * @memberof Popper.Utils
  686. * @param {dataObject} data
  687. * @param {Array} modifiers
  688. * @param {String} ends - Optional modifier name used as stopper
  689. * @returns {dataObject}
  690. */
  691. function runModifiers(modifiers, data, ends) {
  692. const modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex(modifiers, 'name', ends));
  693. modifiersToRun.forEach(modifier => {
  694. if (modifier['function']) {
  695. // eslint-disable-line dot-notation
  696. console.warn('`modifier.function` is deprecated, use `modifier.fn`!');
  697. }
  698. const fn = modifier['function'] || modifier.fn; // eslint-disable-line dot-notation
  699. if (modifier.enabled && isFunction(fn)) {
  700. // Add properties to offsets to make them a complete clientRect object
  701. // we do this before each modifier to make sure the previous one doesn't
  702. // mess with these values
  703. data.offsets.popper = getClientRect(data.offsets.popper);
  704. data.offsets.reference = getClientRect(data.offsets.reference);
  705. data = fn(data, modifier);
  706. }
  707. });
  708. return data;
  709. }
  710. /**
  711. * Updates the position of the popper, computing the new offsets and applying
  712. * the new style.<br />
  713. * Prefer `scheduleUpdate` over `update` because of performance reasons.
  714. * @method
  715. * @memberof Popper
  716. */
  717. function update() {
  718. // if popper is destroyed, don't perform any further update
  719. if (this.state.isDestroyed) {
  720. return;
  721. }
  722. let data = {
  723. instance: this,
  724. styles: {},
  725. arrowStyles: {},
  726. attributes: {},
  727. flipped: false,
  728. offsets: {}
  729. };
  730. // compute reference element offsets
  731. data.offsets.reference = getReferenceOffsets(this.state, this.popper, this.reference, this.options.positionFixed);
  732. // compute auto placement, store placement inside the data object,
  733. // modifiers will be able to edit `placement` if needed
  734. // and refer to originalPlacement to know the original value
  735. data.placement = computeAutoPlacement(this.options.placement, data.offsets.reference, this.popper, this.reference, this.options.modifiers.flip.boundariesElement, this.options.modifiers.flip.padding);
  736. // store the computed placement inside `originalPlacement`
  737. data.originalPlacement = data.placement;
  738. data.positionFixed = this.options.positionFixed;
  739. // compute the popper offsets
  740. data.offsets.popper = getPopperOffsets(this.popper, data.offsets.reference, data.placement);
  741. data.offsets.popper.position = this.options.positionFixed ? 'fixed' : 'absolute';
  742. // run the modifiers
  743. data = runModifiers(this.modifiers, data);
  744. // the first `update` will call `onCreate` callback
  745. // the other ones will call `onUpdate` callback
  746. if (!this.state.isCreated) {
  747. this.state.isCreated = true;
  748. this.options.onCreate(data);
  749. } else {
  750. this.options.onUpdate(data);
  751. }
  752. }
  753. /**
  754. * Helper used to know if the given modifier is enabled.
  755. * @method
  756. * @memberof Popper.Utils
  757. * @returns {Boolean}
  758. */
  759. function isModifierEnabled(modifiers, modifierName) {
  760. return modifiers.some(({ name, enabled }) => enabled && name === modifierName);
  761. }
  762. /**
  763. * Get the prefixed supported property name
  764. * @method
  765. * @memberof Popper.Utils
  766. * @argument {String} property (camelCase)
  767. * @returns {String} prefixed property (camelCase or PascalCase, depending on the vendor prefix)
  768. */
  769. function getSupportedPropertyName(property) {
  770. const prefixes = [false, 'ms', 'Webkit', 'Moz', 'O'];
  771. const upperProp = property.charAt(0).toUpperCase() + property.slice(1);
  772. for (let i = 0; i < prefixes.length; i++) {
  773. const prefix = prefixes[i];
  774. const toCheck = prefix ? `${prefix}${upperProp}` : property;
  775. if (typeof document.body.style[toCheck] !== 'undefined') {
  776. return toCheck;
  777. }
  778. }
  779. return null;
  780. }
  781. /**
  782. * Destroys the popper.
  783. * @method
  784. * @memberof Popper
  785. */
  786. function destroy() {
  787. this.state.isDestroyed = true;
  788. // touch DOM only if `applyStyle` modifier is enabled
  789. if (isModifierEnabled(this.modifiers, 'applyStyle')) {
  790. this.popper.removeAttribute('x-placement');
  791. this.popper.style.position = '';
  792. this.popper.style.top = '';
  793. this.popper.style.left = '';
  794. this.popper.style.right = '';
  795. this.popper.style.bottom = '';
  796. this.popper.style.willChange = '';
  797. this.popper.style[getSupportedPropertyName('transform')] = '';
  798. }
  799. this.disableEventListeners();
  800. // remove the popper if user explicity asked for the deletion on destroy
  801. // do not use `remove` because IE11 doesn't support it
  802. if (this.options.removeOnDestroy) {
  803. this.popper.parentNode.removeChild(this.popper);
  804. }
  805. return this;
  806. }
  807. /**
  808. * Get the window associated with the element
  809. * @argument {Element} element
  810. * @returns {Window}
  811. */
  812. function getWindow(element) {
  813. const ownerDocument = element.ownerDocument;
  814. return ownerDocument ? ownerDocument.defaultView : window;
  815. }
  816. function attachToScrollParents(scrollParent, event, callback, scrollParents) {
  817. const isBody = scrollParent.nodeName === 'BODY';
  818. const target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent;
  819. target.addEventListener(event, callback, { passive: true });
  820. if (!isBody) {
  821. attachToScrollParents(getScrollParent(target.parentNode), event, callback, scrollParents);
  822. }
  823. scrollParents.push(target);
  824. }
  825. /**
  826. * Setup needed event listeners used to update the popper position
  827. * @method
  828. * @memberof Popper.Utils
  829. * @private
  830. */
  831. function setupEventListeners(reference, options, state, updateBound) {
  832. // Resize event listener on window
  833. state.updateBound = updateBound;
  834. getWindow(reference).addEventListener('resize', state.updateBound, { passive: true });
  835. // Scroll event listener on scroll parents
  836. const scrollElement = getScrollParent(reference);
  837. attachToScrollParents(scrollElement, 'scroll', state.updateBound, state.scrollParents);
  838. state.scrollElement = scrollElement;
  839. state.eventsEnabled = true;
  840. return state;
  841. }
  842. /**
  843. * It will add resize/scroll events and start recalculating
  844. * position of the popper element when they are triggered.
  845. * @method
  846. * @memberof Popper
  847. */
  848. function enableEventListeners() {
  849. if (!this.state.eventsEnabled) {
  850. this.state = setupEventListeners(this.reference, this.options, this.state, this.scheduleUpdate);
  851. }
  852. }
  853. /**
  854. * Remove event listeners used to update the popper position
  855. * @method
  856. * @memberof Popper.Utils
  857. * @private
  858. */
  859. function removeEventListeners(reference, state) {
  860. // Remove resize event listener on window
  861. getWindow(reference).removeEventListener('resize', state.updateBound);
  862. // Remove scroll event listener on scroll parents
  863. state.scrollParents.forEach(target => {
  864. target.removeEventListener('scroll', state.updateBound);
  865. });
  866. // Reset state
  867. state.updateBound = null;
  868. state.scrollParents = [];
  869. state.scrollElement = null;
  870. state.eventsEnabled = false;
  871. return state;
  872. }
  873. /**
  874. * It will remove resize/scroll events and won't recalculate popper position
  875. * when they are triggered. It also won't trigger `onUpdate` callback anymore,
  876. * unless you call `update` method manually.
  877. * @method
  878. * @memberof Popper
  879. */
  880. function disableEventListeners() {
  881. if (this.state.eventsEnabled) {
  882. cancelAnimationFrame(this.scheduleUpdate);
  883. this.state = removeEventListeners(this.reference, this.state);
  884. }
  885. }
  886. /**
  887. * Tells if a given input is a number
  888. * @method
  889. * @memberof Popper.Utils
  890. * @param {*} input to check
  891. * @return {Boolean}
  892. */
  893. function isNumeric(n) {
  894. return n !== '' && !isNaN(parseFloat(n)) && isFinite(n);
  895. }
  896. /**
  897. * Set the style to the given popper
  898. * @method
  899. * @memberof Popper.Utils
  900. * @argument {Element} element - Element to apply the style to
  901. * @argument {Object} styles
  902. * Object with a list of properties and values which will be applied to the element
  903. */
  904. function setStyles(element, styles) {
  905. Object.keys(styles).forEach(prop => {
  906. let unit = '';
  907. // add unit if the value is numeric and is one of the following
  908. if (['width', 'height', 'top', 'right', 'bottom', 'left'].indexOf(prop) !== -1 && isNumeric(styles[prop])) {
  909. unit = 'px';
  910. }
  911. element.style[prop] = styles[prop] + unit;
  912. });
  913. }
  914. /**
  915. * Set the attributes to the given popper
  916. * @method
  917. * @memberof Popper.Utils
  918. * @argument {Element} element - Element to apply the attributes to
  919. * @argument {Object} styles
  920. * Object with a list of properties and values which will be applied to the element
  921. */
  922. function setAttributes(element, attributes) {
  923. Object.keys(attributes).forEach(function (prop) {
  924. const value = attributes[prop];
  925. if (value !== false) {
  926. element.setAttribute(prop, attributes[prop]);
  927. } else {
  928. element.removeAttribute(prop);
  929. }
  930. });
  931. }
  932. /**
  933. * @function
  934. * @memberof Modifiers
  935. * @argument {Object} data - The data object generated by `update` method
  936. * @argument {Object} data.styles - List of style properties - values to apply to popper element
  937. * @argument {Object} data.attributes - List of attribute properties - values to apply to popper element
  938. * @argument {Object} options - Modifiers configuration and options
  939. * @returns {Object} The same data object
  940. */
  941. function applyStyle(data) {
  942. // any property present in `data.styles` will be applied to the popper,
  943. // in this way we can make the 3rd party modifiers add custom styles to it
  944. // Be aware, modifiers could override the properties defined in the previous
  945. // lines of this modifier!
  946. setStyles(data.instance.popper, data.styles);
  947. // any property present in `data.attributes` will be applied to the popper,
  948. // they will be set as HTML attributes of the element
  949. setAttributes(data.instance.popper, data.attributes);
  950. // if arrowElement is defined and arrowStyles has some properties
  951. if (data.arrowElement && Object.keys(data.arrowStyles).length) {
  952. setStyles(data.arrowElement, data.arrowStyles);
  953. }
  954. return data;
  955. }
  956. /**
  957. * Set the x-placement attribute before everything else because it could be used
  958. * to add margins to the popper margins needs to be calculated to get the
  959. * correct popper offsets.
  960. * @method
  961. * @memberof Popper.modifiers
  962. * @param {HTMLElement} reference - The reference element used to position the popper
  963. * @param {HTMLElement} popper - The HTML element used as popper
  964. * @param {Object} options - Popper.js options
  965. */
  966. function applyStyleOnLoad(reference, popper, options, modifierOptions, state) {
  967. // compute reference element offsets
  968. const referenceOffsets = getReferenceOffsets(state, popper, reference, options.positionFixed);
  969. // compute auto placement, store placement inside the data object,
  970. // modifiers will be able to edit `placement` if needed
  971. // and refer to originalPlacement to know the original value
  972. const placement = computeAutoPlacement(options.placement, referenceOffsets, popper, reference, options.modifiers.flip.boundariesElement, options.modifiers.flip.padding);
  973. popper.setAttribute('x-placement', placement);
  974. // Apply `position` to popper before anything else because
  975. // without the position applied we can't guarantee correct computations
  976. setStyles(popper, { position: options.positionFixed ? 'fixed' : 'absolute' });
  977. return options;
  978. }
  979. /**
  980. * @function
  981. * @memberof Popper.Utils
  982. * @argument {Object} data - The data object generated by `update` method
  983. * @argument {Boolean} shouldRound - If the offsets should be rounded at all
  984. * @returns {Object} The popper's position offsets rounded
  985. *
  986. * The tale of pixel-perfect positioning. It's still not 100% perfect, but as
  987. * good as it can be within reason.
  988. * Discussion here: https://github.com/FezVrasta/popper.js/pull/715
  989. *
  990. * Low DPI screens cause a popper to be blurry if not using full pixels (Safari
  991. * as well on High DPI screens).
  992. *
  993. * Firefox prefers no rounding for positioning and does not have blurriness on
  994. * high DPI screens.
  995. *
  996. * Only horizontal placement and left/right values need to be considered.
  997. */
  998. function getRoundedOffsets(data, shouldRound) {
  999. const { popper, reference } = data.offsets;
  1000. const { round, floor } = Math;
  1001. const noRound = v => v;
  1002. const referenceWidth = round(reference.width);
  1003. const popperWidth = round(popper.width);
  1004. const isVertical = ['left', 'right'].indexOf(data.placement) !== -1;
  1005. const isVariation = data.placement.indexOf('-') !== -1;
  1006. const sameWidthParity = referenceWidth % 2 === popperWidth % 2;
  1007. const bothOddWidth = referenceWidth % 2 === 1 && popperWidth % 2 === 1;
  1008. const horizontalToInteger = !shouldRound ? noRound : isVertical || isVariation || sameWidthParity ? round : floor;
  1009. const verticalToInteger = !shouldRound ? noRound : round;
  1010. return {
  1011. left: horizontalToInteger(bothOddWidth && !isVariation && shouldRound ? popper.left - 1 : popper.left),
  1012. top: verticalToInteger(popper.top),
  1013. bottom: verticalToInteger(popper.bottom),
  1014. right: horizontalToInteger(popper.right)
  1015. };
  1016. }
  1017. const isFirefox = isBrowser && /Firefox/i.test(navigator.userAgent);
  1018. /**
  1019. * @function
  1020. * @memberof Modifiers
  1021. * @argument {Object} data - The data object generated by `update` method
  1022. * @argument {Object} options - Modifiers configuration and options
  1023. * @returns {Object} The data object, properly modified
  1024. */
  1025. function computeStyle(data, options) {
  1026. const { x, y } = options;
  1027. const { popper } = data.offsets;
  1028. // Remove this legacy support in Popper.js v2
  1029. const legacyGpuAccelerationOption = find(data.instance.modifiers, modifier => modifier.name === 'applyStyle').gpuAcceleration;
  1030. if (legacyGpuAccelerationOption !== undefined) {
  1031. console.warn('WARNING: `gpuAcceleration` option moved to `computeStyle` modifier and will not be supported in future versions of Popper.js!');
  1032. }
  1033. const gpuAcceleration = legacyGpuAccelerationOption !== undefined ? legacyGpuAccelerationOption : options.gpuAcceleration;
  1034. const offsetParent = getOffsetParent(data.instance.popper);
  1035. const offsetParentRect = getBoundingClientRect(offsetParent);
  1036. // Styles
  1037. const styles = {
  1038. position: popper.position
  1039. };
  1040. const offsets = getRoundedOffsets(data, window.devicePixelRatio < 2 || !isFirefox);
  1041. const sideA = x === 'bottom' ? 'top' : 'bottom';
  1042. const sideB = y === 'right' ? 'left' : 'right';
  1043. // if gpuAcceleration is set to `true` and transform is supported,
  1044. // we use `translate3d` to apply the position to the popper we
  1045. // automatically use the supported prefixed version if needed
  1046. const prefixedProperty = getSupportedPropertyName('transform');
  1047. // now, let's make a step back and look at this code closely (wtf?)
  1048. // If the content of the popper grows once it's been positioned, it
  1049. // may happen that the popper gets misplaced because of the new content
  1050. // overflowing its reference element
  1051. // To avoid this problem, we provide two options (x and y), which allow
  1052. // the consumer to define the offset origin.
  1053. // If we position a popper on top of a reference element, we can set
  1054. // `x` to `top` to make the popper grow towards its top instead of
  1055. // its bottom.
  1056. let left, top;
  1057. if (sideA === 'bottom') {
  1058. // when offsetParent is <html> the positioning is relative to the bottom of the screen (excluding the scrollbar)
  1059. // and not the bottom of the html element
  1060. if (offsetParent.nodeName === 'HTML') {
  1061. top = -offsetParent.clientHeight + offsets.bottom;
  1062. } else {
  1063. top = -offsetParentRect.height + offsets.bottom;
  1064. }
  1065. } else {
  1066. top = offsets.top;
  1067. }
  1068. if (sideB === 'right') {
  1069. if (offsetParent.nodeName === 'HTML') {
  1070. left = -offsetParent.clientWidth + offsets.right;
  1071. } else {
  1072. left = -offsetParentRect.width + offsets.right;
  1073. }
  1074. } else {
  1075. left = offsets.left;
  1076. }
  1077. if (gpuAcceleration && prefixedProperty) {
  1078. styles[prefixedProperty] = `translate3d(${left}px, ${top}px, 0)`;
  1079. styles[sideA] = 0;
  1080. styles[sideB] = 0;
  1081. styles.willChange = 'transform';
  1082. } else {
  1083. // othwerise, we use the standard `top`, `left`, `bottom` and `right` properties
  1084. const invertTop = sideA === 'bottom' ? -1 : 1;
  1085. const invertLeft = sideB === 'right' ? -1 : 1;
  1086. styles[sideA] = top * invertTop;
  1087. styles[sideB] = left * invertLeft;
  1088. styles.willChange = `${sideA}, ${sideB}`;
  1089. }
  1090. // Attributes
  1091. const attributes = {
  1092. 'x-placement': data.placement
  1093. };
  1094. // Update `data` attributes, styles and arrowStyles
  1095. data.attributes = _extends({}, attributes, data.attributes);
  1096. data.styles = _extends({}, styles, data.styles);
  1097. data.arrowStyles = _extends({}, data.offsets.arrow, data.arrowStyles);
  1098. return data;
  1099. }
  1100. /**
  1101. * Helper used to know if the given modifier depends from another one.<br />
  1102. * It checks if the needed modifier is listed and enabled.
  1103. * @method
  1104. * @memberof Popper.Utils
  1105. * @param {Array} modifiers - list of modifiers
  1106. * @param {String} requestingName - name of requesting modifier
  1107. * @param {String} requestedName - name of requested modifier
  1108. * @returns {Boolean}
  1109. */
  1110. function isModifierRequired(modifiers, requestingName, requestedName) {
  1111. const requesting = find(modifiers, ({ name }) => name === requestingName);
  1112. const isRequired = !!requesting && modifiers.some(modifier => {
  1113. return modifier.name === requestedName && modifier.enabled && modifier.order < requesting.order;
  1114. });
  1115. if (!isRequired) {
  1116. const requesting = `\`${requestingName}\``;
  1117. const requested = `\`${requestedName}\``;
  1118. console.warn(`${requested} modifier is required by ${requesting} modifier in order to work, be sure to include it before ${requesting}!`);
  1119. }
  1120. return isRequired;
  1121. }
  1122. /**
  1123. * @function
  1124. * @memberof Modifiers
  1125. * @argument {Object} data - The data object generated by update method
  1126. * @argument {Object} options - Modifiers configuration and options
  1127. * @returns {Object} The data object, properly modified
  1128. */
  1129. function arrow(data, options) {
  1130. // arrow depends on keepTogether in order to work
  1131. if (!isModifierRequired(data.instance.modifiers, 'arrow', 'keepTogether')) {
  1132. return data;
  1133. }
  1134. let arrowElement = options.element;
  1135. // if arrowElement is a string, suppose it's a CSS selector
  1136. if (typeof arrowElement === 'string') {
  1137. arrowElement = data.instance.popper.querySelector(arrowElement);
  1138. // if arrowElement is not found, don't run the modifier
  1139. if (!arrowElement) {
  1140. return data;
  1141. }
  1142. } else {
  1143. // if the arrowElement isn't a query selector we must check that the
  1144. // provided DOM node is child of its popper node
  1145. if (!data.instance.popper.contains(arrowElement)) {
  1146. console.warn('WARNING: `arrow.element` must be child of its popper element!');
  1147. return data;
  1148. }
  1149. }
  1150. const placement = data.placement.split('-')[0];
  1151. const { popper, reference } = data.offsets;
  1152. const isVertical = ['left', 'right'].indexOf(placement) !== -1;
  1153. const len = isVertical ? 'height' : 'width';
  1154. const sideCapitalized = isVertical ? 'Top' : 'Left';
  1155. const side = sideCapitalized.toLowerCase();
  1156. const altSide = isVertical ? 'left' : 'top';
  1157. const opSide = isVertical ? 'bottom' : 'right';
  1158. const arrowElementSize = getOuterSizes(arrowElement)[len];
  1159. //
  1160. // extends keepTogether behavior making sure the popper and its
  1161. // reference have enough pixels in conjunction
  1162. //
  1163. // top/left side
  1164. if (reference[opSide] - arrowElementSize < popper[side]) {
  1165. data.offsets.popper[side] -= popper[side] - (reference[opSide] - arrowElementSize);
  1166. }
  1167. // bottom/right side
  1168. if (reference[side] + arrowElementSize > popper[opSide]) {
  1169. data.offsets.popper[side] += reference[side] + arrowElementSize - popper[opSide];
  1170. }
  1171. data.offsets.popper = getClientRect(data.offsets.popper);
  1172. // compute center of the popper
  1173. const center = reference[side] + reference[len] / 2 - arrowElementSize / 2;
  1174. // Compute the sideValue using the updated popper offsets
  1175. // take popper margin in account because we don't have this info available
  1176. const css = getStyleComputedProperty(data.instance.popper);
  1177. const popperMarginSide = parseFloat(css[`margin${sideCapitalized}`], 10);
  1178. const popperBorderSide = parseFloat(css[`border${sideCapitalized}Width`], 10);
  1179. let sideValue = center - data.offsets.popper[side] - popperMarginSide - popperBorderSide;
  1180. // prevent arrowElement from being placed not contiguously to its popper
  1181. sideValue = Math.max(Math.min(popper[len] - arrowElementSize, sideValue), 0);
  1182. data.arrowElement = arrowElement;
  1183. data.offsets.arrow = {
  1184. [side]: Math.round(sideValue),
  1185. [altSide]: '' // make sure to unset any eventual altSide value from the DOM node
  1186. };
  1187. return data;
  1188. }
  1189. /**
  1190. * Get the opposite placement variation of the given one
  1191. * @method
  1192. * @memberof Popper.Utils
  1193. * @argument {String} placement variation
  1194. * @returns {String} flipped placement variation
  1195. */
  1196. function getOppositeVariation(variation) {
  1197. if (variation === 'end') {
  1198. return 'start';
  1199. } else if (variation === 'start') {
  1200. return 'end';
  1201. }
  1202. return variation;
  1203. }
  1204. /**
  1205. * List of accepted placements to use as values of the `placement` option.<br />
  1206. * Valid placements are:
  1207. * - `auto`
  1208. * - `top`
  1209. * - `right`
  1210. * - `bottom`
  1211. * - `left`
  1212. *
  1213. * Each placement can have a variation from this list:
  1214. * - `-start`
  1215. * - `-end`
  1216. *
  1217. * Variations are interpreted easily if you think of them as the left to right
  1218. * written languages. Horizontally (`top` and `bottom`), `start` is left and `end`
  1219. * is right.<br />
  1220. * Vertically (`left` and `right`), `start` is top and `end` is bottom.
  1221. *
  1222. * Some valid examples are:
  1223. * - `top-end` (on top of reference, right aligned)
  1224. * - `right-start` (on right of reference, top aligned)
  1225. * - `bottom` (on bottom, centered)
  1226. * - `auto-end` (on the side with more space available, alignment depends by placement)
  1227. *
  1228. * @static
  1229. * @type {Array}
  1230. * @enum {String}
  1231. * @readonly
  1232. * @method placements
  1233. * @memberof Popper
  1234. */
  1235. var placements = ['auto-start', 'auto', 'auto-end', 'top-start', 'top', 'top-end', 'right-start', 'right', 'right-end', 'bottom-end', 'bottom', 'bottom-start', 'left-end', 'left', 'left-start'];
  1236. // Get rid of `auto` `auto-start` and `auto-end`
  1237. const validPlacements = placements.slice(3);
  1238. /**
  1239. * Given an initial placement, returns all the subsequent placements
  1240. * clockwise (or counter-clockwise).
  1241. *
  1242. * @method
  1243. * @memberof Popper.Utils
  1244. * @argument {String} placement - A valid placement (it accepts variations)
  1245. * @argument {Boolean} counter - Set to true to walk the placements counterclockwise
  1246. * @returns {Array} placements including their variations
  1247. */
  1248. function clockwise(placement, counter = false) {
  1249. const index = validPlacements.indexOf(placement);
  1250. const arr = validPlacements.slice(index + 1).concat(validPlacements.slice(0, index));
  1251. return counter ? arr.reverse() : arr;
  1252. }
  1253. const BEHAVIORS = {
  1254. FLIP: 'flip',
  1255. CLOCKWISE: 'clockwise',
  1256. COUNTERCLOCKWISE: 'counterclockwise'
  1257. };
  1258. /**
  1259. * @function
  1260. * @memberof Modifiers
  1261. * @argument {Object} data - The data object generated by update method
  1262. * @argument {Object} options - Modifiers configuration and options
  1263. * @returns {Object} The data object, properly modified
  1264. */
  1265. function flip(data, options) {
  1266. // if `inner` modifier is enabled, we can't use the `flip` modifier
  1267. if (isModifierEnabled(data.instance.modifiers, 'inner')) {
  1268. return data;
  1269. }
  1270. if (data.flipped && data.placement === data.originalPlacement) {
  1271. // seems like flip is trying to loop, probably there's not enough space on any of the flippable sides
  1272. return data;
  1273. }
  1274. const boundaries = getBoundaries(data.instance.popper, data.instance.reference, options.padding, options.boundariesElement, data.positionFixed);
  1275. let placement = data.placement.split('-')[0];
  1276. let placementOpposite = getOppositePlacement(placement);
  1277. let variation = data.placement.split('-')[1] || '';
  1278. let flipOrder = [];
  1279. switch (options.behavior) {
  1280. case BEHAVIORS.FLIP:
  1281. flipOrder = [placement, placementOpposite];
  1282. break;
  1283. case BEHAVIORS.CLOCKWISE:
  1284. flipOrder = clockwise(placement);
  1285. break;
  1286. case BEHAVIORS.COUNTERCLOCKWISE:
  1287. flipOrder = clockwise(placement, true);
  1288. break;
  1289. default:
  1290. flipOrder = options.behavior;
  1291. }
  1292. flipOrder.forEach((step, index) => {
  1293. if (placement !== step || flipOrder.length === index + 1) {
  1294. return data;
  1295. }
  1296. placement = data.placement.split('-')[0];
  1297. placementOpposite = getOppositePlacement(placement);
  1298. const popperOffsets = data.offsets.popper;
  1299. const refOffsets = data.offsets.reference;
  1300. // using floor because the reference offsets may contain decimals we are not going to consider here
  1301. const floor = Math.floor;
  1302. const overlapsRef = placement === 'left' && floor(popperOffsets.right) > floor(refOffsets.left) || placement === 'right' && floor(popperOffsets.left) < floor(refOffsets.right) || placement === 'top' && floor(popperOffsets.bottom) > floor(refOffsets.top) || placement === 'bottom' && floor(popperOffsets.top) < floor(refOffsets.bottom);
  1303. const overflowsLeft = floor(popperOffsets.left) < floor(boundaries.left);
  1304. const overflowsRight = floor(popperOffsets.right) > floor(boundaries.right);
  1305. const overflowsTop = floor(popperOffsets.top) < floor(boundaries.top);
  1306. const overflowsBottom = floor(popperOffsets.bottom) > floor(boundaries.bottom);
  1307. const overflowsBoundaries = placement === 'left' && overflowsLeft || placement === 'right' && overflowsRight || placement === 'top' && overflowsTop || placement === 'bottom' && overflowsBottom;
  1308. // flip the variation if required
  1309. const isVertical = ['top', 'bottom'].indexOf(placement) !== -1;
  1310. // flips variation if reference element overflows boundaries
  1311. const flippedVariationByRef = !!options.flipVariations && (isVertical && variation === 'start' && overflowsLeft || isVertical && variation === 'end' && overflowsRight || !isVertical && variation === 'start' && overflowsTop || !isVertical && variation === 'end' && overflowsBottom);
  1312. // flips variation if popper content overflows boundaries
  1313. const flippedVariationByContent = !!options.flipVariationsByContent && (isVertical && variation === 'start' && overflowsRight || isVertical && variation === 'end' && overflowsLeft || !isVertical && variation === 'start' && overflowsBottom || !isVertical && variation === 'end' && overflowsTop);
  1314. const flippedVariation = flippedVariationByRef || flippedVariationByContent;
  1315. if (overlapsRef || overflowsBoundaries || flippedVariation) {
  1316. // this boolean to detect any flip loop
  1317. data.flipped = true;
  1318. if (overlapsRef || overflowsBoundaries) {
  1319. placement = flipOrder[index + 1];
  1320. }
  1321. if (flippedVariation) {
  1322. variation = getOppositeVariation(variation);
  1323. }
  1324. data.placement = placement + (variation ? '-' + variation : '');
  1325. // this object contains `position`, we want to preserve it along with
  1326. // any additional property we may add in the future
  1327. data.offsets.popper = _extends({}, data.offsets.popper, getPopperOffsets(data.instance.popper, data.offsets.reference, data.placement));
  1328. data = runModifiers(data.instance.modifiers, data, 'flip');
  1329. }
  1330. });
  1331. return data;
  1332. }
  1333. /**
  1334. * @function
  1335. * @memberof Modifiers
  1336. * @argument {Object} data - The data object generated by update method
  1337. * @argument {Object} options - Modifiers configuration and options
  1338. * @returns {Object} The data object, properly modified
  1339. */
  1340. function keepTogether(data) {
  1341. const { popper, reference } = data.offsets;
  1342. const placement = data.placement.split('-')[0];
  1343. const floor = Math.floor;
  1344. const isVertical = ['top', 'bottom'].indexOf(placement) !== -1;
  1345. const side = isVertical ? 'right' : 'bottom';
  1346. const opSide = isVertical ? 'left' : 'top';
  1347. const measurement = isVertical ? 'width' : 'height';
  1348. if (popper[side] < floor(reference[opSide])) {
  1349. data.offsets.popper[opSide] = floor(reference[opSide]) - popper[measurement];
  1350. }
  1351. if (popper[opSide] > floor(reference[side])) {
  1352. data.offsets.popper[opSide] = floor(reference[side]);
  1353. }
  1354. return data;
  1355. }
  1356. /**
  1357. * Converts a string containing value + unit into a px value number
  1358. * @function
  1359. * @memberof {modifiers~offset}
  1360. * @private
  1361. * @argument {String} str - Value + unit string
  1362. * @argument {String} measurement - `height` or `width`
  1363. * @argument {Object} popperOffsets
  1364. * @argument {Object} referenceOffsets
  1365. * @returns {Number|String}
  1366. * Value in pixels, or original string if no values were extracted
  1367. */
  1368. function toValue(str, measurement, popperOffsets, referenceOffsets) {
  1369. // separate value from unit
  1370. const split = str.match(/((?:\-|\+)?\d*\.?\d*)(.*)/);
  1371. const value = +split[1];
  1372. const unit = split[2];
  1373. // If it's not a number it's an operator, I guess
  1374. if (!value) {
  1375. return str;
  1376. }
  1377. if (unit.indexOf('%') === 0) {
  1378. let element;
  1379. switch (unit) {
  1380. case '%p':
  1381. element = popperOffsets;
  1382. break;
  1383. case '%':
  1384. case '%r':
  1385. default:
  1386. element = referenceOffsets;
  1387. }
  1388. const rect = getClientRect(element);
  1389. return rect[measurement] / 100 * value;
  1390. } else if (unit === 'vh' || unit === 'vw') {
  1391. // if is a vh or vw, we calculate the size based on the viewport
  1392. let size;
  1393. if (unit === 'vh') {
  1394. size = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
  1395. } else {
  1396. size = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
  1397. }
  1398. return size / 100 * value;
  1399. } else {
  1400. // if is an explicit pixel unit, we get rid of the unit and keep the value
  1401. // if is an implicit unit, it's px, and we return just the value
  1402. return value;
  1403. }
  1404. }
  1405. /**
  1406. * Parse an `offset` string to extrapolate `x` and `y` numeric offsets.
  1407. * @function
  1408. * @memberof {modifiers~offset}
  1409. * @private
  1410. * @argument {String} offset
  1411. * @argument {Object} popperOffsets
  1412. * @argument {Object} referenceOffsets
  1413. * @argument {String} basePlacement
  1414. * @returns {Array} a two cells array with x and y offsets in numbers
  1415. */
  1416. function parseOffset(offset, popperOffsets, referenceOffsets, basePlacement) {
  1417. const offsets = [0, 0];
  1418. // Use height if placement is left or right and index is 0 otherwise use width
  1419. // in this way the first offset will use an axis and the second one
  1420. // will use the other one
  1421. const useHeight = ['right', 'left'].indexOf(basePlacement) !== -1;
  1422. // Split the offset string to obtain a list of values and operands
  1423. // The regex addresses values with the plus or minus sign in front (+10, -20, etc)
  1424. const fragments = offset.split(/(\+|\-)/).map(frag => frag.trim());
  1425. // Detect if the offset string contains a pair of values or a single one
  1426. // they could be separated by comma or space
  1427. const divider = fragments.indexOf(find(fragments, frag => frag.search(/,|\s/) !== -1));
  1428. if (fragments[divider] && fragments[divider].indexOf(',') === -1) {
  1429. console.warn('Offsets separated by white space(s) are deprecated, use a comma (,) instead.');
  1430. }
  1431. // If divider is found, we divide the list of values and operands to divide
  1432. // them by ofset X and Y.
  1433. const splitRegex = /\s*,\s*|\s+/;
  1434. let ops = divider !== -1 ? [fragments.slice(0, divider).concat([fragments[divider].split(splitRegex)[0]]), [fragments[divider].split(splitRegex)[1]].concat(fragments.slice(divider + 1))] : [fragments];
  1435. // Convert the values with units to absolute pixels to allow our computations
  1436. ops = ops.map((op, index) => {
  1437. // Most of the units rely on the orientation of the popper
  1438. const measurement = (index === 1 ? !useHeight : useHeight) ? 'height' : 'width';
  1439. let mergeWithPrevious = false;
  1440. return op
  1441. // This aggregates any `+` or `-` sign that aren't considered operators
  1442. // e.g.: 10 + +5 => [10, +, +5]
  1443. .reduce((a, b) => {
  1444. if (a[a.length - 1] === '' && ['+', '-'].indexOf(b) !== -1) {
  1445. a[a.length - 1] = b;
  1446. mergeWithPrevious = true;
  1447. return a;
  1448. } else if (mergeWithPrevious) {
  1449. a[a.length - 1] += b;
  1450. mergeWithPrevious = false;
  1451. return a;
  1452. } else {
  1453. return a.concat(b);
  1454. }
  1455. }, [])
  1456. // Here we convert the string values into number values (in px)
  1457. .map(str => toValue(str, measurement, popperOffsets, referenceOffsets));
  1458. });
  1459. // Loop trough the offsets arrays and execute the operations
  1460. ops.forEach((op, index) => {
  1461. op.forEach((frag, index2) => {
  1462. if (isNumeric(frag)) {
  1463. offsets[index] += frag * (op[index2 - 1] === '-' ? -1 : 1);
  1464. }
  1465. });
  1466. });
  1467. return offsets;
  1468. }
  1469. /**
  1470. * @function
  1471. * @memberof Modifiers
  1472. * @argument {Object} data - The data object generated by update method
  1473. * @argument {Object} options - Modifiers configuration and options
  1474. * @argument {Number|String} options.offset=0
  1475. * The offset value as described in the modifier description
  1476. * @returns {Object} The data object, properly modified
  1477. */
  1478. function offset(data, { offset }) {
  1479. const { placement, offsets: { popper, reference } } = data;
  1480. const basePlacement = placement.split('-')[0];
  1481. let offsets;
  1482. if (isNumeric(+offset)) {
  1483. offsets = [+offset, 0];
  1484. } else {
  1485. offsets = parseOffset(offset, popper, reference, basePlacement);
  1486. }
  1487. if (basePlacement === 'left') {
  1488. popper.top += offsets[0];
  1489. popper.left -= offsets[1];
  1490. } else if (basePlacement === 'right') {
  1491. popper.top += offsets[0];
  1492. popper.left += offsets[1];
  1493. } else if (basePlacement === 'top') {
  1494. popper.left += offsets[0];
  1495. popper.top -= offsets[1];
  1496. } else if (basePlacement === 'bottom') {
  1497. popper.left += offsets[0];
  1498. popper.top += offsets[1];
  1499. }
  1500. data.popper = popper;
  1501. return data;
  1502. }
  1503. /**
  1504. * @function
  1505. * @memberof Modifiers
  1506. * @argument {Object} data - The data object generated by `update` method
  1507. * @argument {Object} options - Modifiers configuration and options
  1508. * @returns {Object} The data object, properly modified
  1509. */
  1510. function preventOverflow(data, options) {
  1511. let boundariesElement = options.boundariesElement || getOffsetParent(data.instance.popper);
  1512. // If offsetParent is the reference element, we really want to
  1513. // go one step up and use the next offsetParent as reference to
  1514. // avoid to make this modifier completely useless and look like broken
  1515. if (data.instance.reference === boundariesElement) {
  1516. boundariesElement = getOffsetParent(boundariesElement);
  1517. }
  1518. // NOTE: DOM access here
  1519. // resets the popper's position so that the document size can be calculated excluding
  1520. // the size of the popper element itself
  1521. const transformProp = getSupportedPropertyName('transform');
  1522. const popperStyles = data.instance.popper.style; // assignment to help minification
  1523. const { top, left, [transformProp]: transform } = popperStyles;
  1524. popperStyles.top = '';
  1525. popperStyles.left = '';
  1526. popperStyles[transformProp] = '';
  1527. const boundaries = getBoundaries(data.instance.popper, data.instance.reference, options.padding, boundariesElement, data.positionFixed);
  1528. // NOTE: DOM access here
  1529. // restores the original style properties after the offsets have been computed
  1530. popperStyles.top = top;
  1531. popperStyles.left = left;
  1532. popperStyles[transformProp] = transform;
  1533. options.boundaries = boundaries;
  1534. const order = options.priority;
  1535. let popper = data.offsets.popper;
  1536. const check = {
  1537. primary(placement) {
  1538. let value = popper[placement];
  1539. if (popper[placement] < boundaries[placement] && !options.escapeWithReference) {
  1540. value = Math.max(popper[placement], boundaries[placement]);
  1541. }
  1542. return { [placement]: value };
  1543. },
  1544. secondary(placement) {
  1545. const mainSide = placement === 'right' ? 'left' : 'top';
  1546. let value = popper[mainSide];
  1547. if (popper[placement] > boundaries[placement] && !options.escapeWithReference) {
  1548. value = Math.min(popper[mainSide], boundaries[placement] - (placement === 'right' ? popper.width : popper.height));
  1549. }
  1550. return { [mainSide]: value };
  1551. }
  1552. };
  1553. order.forEach(placement => {
  1554. const side = ['left', 'top'].indexOf(placement) !== -1 ? 'primary' : 'secondary';
  1555. popper = _extends({}, popper, check[side](placement));
  1556. });
  1557. data.offsets.popper = popper;
  1558. return data;
  1559. }
  1560. /**
  1561. * @function
  1562. * @memberof Modifiers
  1563. * @argument {Object} data - The data object generated by `update` method
  1564. * @argument {Object} options - Modifiers configuration and options
  1565. * @returns {Object} The data object, properly modified
  1566. */
  1567. function shift(data) {
  1568. const placement = data.placement;
  1569. const basePlacement = placement.split('-')[0];
  1570. const shiftvariation = placement.split('-')[1];
  1571. // if shift shiftvariation is specified, run the modifier
  1572. if (shiftvariation) {
  1573. const { reference, popper } = data.offsets;
  1574. const isVertical = ['bottom', 'top'].indexOf(basePlacement) !== -1;
  1575. const side = isVertical ? 'left' : 'top';
  1576. const measurement = isVertical ? 'width' : 'height';
  1577. const shiftOffsets = {
  1578. start: { [side]: reference[side] },
  1579. end: {
  1580. [side]: reference[side] + reference[measurement] - popper[measurement]
  1581. }
  1582. };
  1583. data.offsets.popper = _extends({}, popper, shiftOffsets[shiftvariation]);
  1584. }
  1585. return data;
  1586. }
  1587. /**
  1588. * @function
  1589. * @memberof Modifiers
  1590. * @argument {Object} data - The data object generated by update method
  1591. * @argument {Object} options - Modifiers configuration and options
  1592. * @returns {Object} The data object, properly modified
  1593. */
  1594. function hide(data) {
  1595. if (!isModifierRequired(data.instance.modifiers, 'hide', 'preventOverflow')) {
  1596. return data;
  1597. }
  1598. const refRect = data.offsets.reference;
  1599. const bound = find(data.instance.modifiers, modifier => modifier.name === 'preventOverflow').boundaries;
  1600. if (refRect.bottom < bound.top || refRect.left > bound.right || refRect.top > bound.bottom || refRect.right < bound.left) {
  1601. // Avoid unnecessary DOM access if visibility hasn't changed
  1602. if (data.hide === true) {
  1603. return data;
  1604. }
  1605. data.hide = true;
  1606. data.attributes['x-out-of-boundaries'] = '';
  1607. } else {
  1608. // Avoid unnecessary DOM access if visibility hasn't changed
  1609. if (data.hide === false) {
  1610. return data;
  1611. }
  1612. data.hide = false;
  1613. data.attributes['x-out-of-boundaries'] = false;
  1614. }
  1615. return data;
  1616. }
  1617. /**
  1618. * @function
  1619. * @memberof Modifiers
  1620. * @argument {Object} data - The data object generated by `update` method
  1621. * @argument {Object} options - Modifiers configuration and options
  1622. * @returns {Object} The data object, properly modified
  1623. */
  1624. function inner(data) {
  1625. const placement = data.placement;
  1626. const basePlacement = placement.split('-')[0];
  1627. const { popper, reference } = data.offsets;
  1628. const isHoriz = ['left', 'right'].indexOf(basePlacement) !== -1;
  1629. const subtractLength = ['top', 'left'].indexOf(basePlacement) === -1;
  1630. popper[isHoriz ? 'left' : 'top'] = reference[basePlacement] - (subtractLength ? popper[isHoriz ? 'width' : 'height'] : 0);
  1631. data.placement = getOppositePlacement(placement);
  1632. data.offsets.popper = getClientRect(popper);
  1633. return data;
  1634. }
  1635. /**
  1636. * Modifier function, each modifier can have a function of this type assigned
  1637. * to its `fn` property.<br />
  1638. * These functions will be called on each update, this means that you must
  1639. * make sure they are performant enough to avoid performance bottlenecks.
  1640. *
  1641. * @function ModifierFn
  1642. * @argument {dataObject} data - The data object generated by `update` method
  1643. * @argument {Object} options - Modifiers configuration and options
  1644. * @returns {dataObject} The data object, properly modified
  1645. */
  1646. /**
  1647. * Modifiers are plugins used to alter the behavior of your poppers.<br />
  1648. * Popper.js uses a set of 9 modifiers to provide all the basic functionalities
  1649. * needed by the library.
  1650. *
  1651. * Usually you don't want to override the `order`, `fn` and `onLoad` props.
  1652. * All the other properties are configurations that could be tweaked.
  1653. * @namespace modifiers
  1654. */
  1655. var modifiers = {
  1656. /**
  1657. * Modifier used to shift the popper on the start or end of its reference
  1658. * element.<br />
  1659. * It will read the variation of the `placement` property.<br />
  1660. * It can be one either `-end` or `-start`.
  1661. * @memberof modifiers
  1662. * @inner
  1663. */
  1664. shift: {
  1665. /** @prop {number} order=100 - Index used to define the order of execution */
  1666. order: 100,
  1667. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1668. enabled: true,
  1669. /** @prop {ModifierFn} */
  1670. fn: shift
  1671. },
  1672. /**
  1673. * The `offset` modifier can shift your popper on both its axis.
  1674. *
  1675. * It accepts the following units:
  1676. * - `px` or unit-less, interpreted as pixels
  1677. * - `%` or `%r`, percentage relative to the length of the reference element
  1678. * - `%p`, percentage relative to the length of the popper element
  1679. * - `vw`, CSS viewport width unit
  1680. * - `vh`, CSS viewport height unit
  1681. *
  1682. * For length is intended the main axis relative to the placement of the popper.<br />
  1683. * This means that if the placement is `top` or `bottom`, the length will be the
  1684. * `width`. In case of `left` or `right`, it will be the `height`.
  1685. *
  1686. * You can provide a single value (as `Number` or `String`), or a pair of values
  1687. * as `String` divided by a comma or one (or more) white spaces.<br />
  1688. * The latter is a deprecated method because it leads to confusion and will be
  1689. * removed in v2.<br />
  1690. * Additionally, it accepts additions and subtractions between different units.
  1691. * Note that multiplications and divisions aren't supported.
  1692. *
  1693. * Valid examples are:
  1694. * ```
  1695. * 10
  1696. * '10%'
  1697. * '10, 10'
  1698. * '10%, 10'
  1699. * '10 + 10%'
  1700. * '10 - 5vh + 3%'
  1701. * '-10px + 5vh, 5px - 6%'
  1702. * ```
  1703. * > **NB**: If you desire to apply offsets to your poppers in a way that may make them overlap
  1704. * > with their reference element, unfortunately, you will have to disable the `flip` modifier.
  1705. * > You can read more on this at this [issue](https://github.com/FezVrasta/popper.js/issues/373).
  1706. *
  1707. * @memberof modifiers
  1708. * @inner
  1709. */
  1710. offset: {
  1711. /** @prop {number} order=200 - Index used to define the order of execution */
  1712. order: 200,
  1713. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1714. enabled: true,
  1715. /** @prop {ModifierFn} */
  1716. fn: offset,
  1717. /** @prop {Number|String} offset=0
  1718. * The offset value as described in the modifier description
  1719. */
  1720. offset: 0
  1721. },
  1722. /**
  1723. * Modifier used to prevent the popper from being positioned outside the boundary.
  1724. *
  1725. * A scenario exists where the reference itself is not within the boundaries.<br />
  1726. * We can say it has "escaped the boundaries" — or just "escaped".<br />
  1727. * In this case we need to decide whether the popper should either:
  1728. *
  1729. * - detach from the reference and remain "trapped" in the boundaries, or
  1730. * - if it should ignore the boundary and "escape with its reference"
  1731. *
  1732. * When `escapeWithReference` is set to`true` and reference is completely
  1733. * outside its boundaries, the popper will overflow (or completely leave)
  1734. * the boundaries in order to remain attached to the edge of the reference.
  1735. *
  1736. * @memberof modifiers
  1737. * @inner
  1738. */
  1739. preventOverflow: {
  1740. /** @prop {number} order=300 - Index used to define the order of execution */
  1741. order: 300,
  1742. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1743. enabled: true,
  1744. /** @prop {ModifierFn} */
  1745. fn: preventOverflow,
  1746. /**
  1747. * @prop {Array} [priority=['left','right','top','bottom']]
  1748. * Popper will try to prevent overflow following these priorities by default,
  1749. * then, it could overflow on the left and on top of the `boundariesElement`
  1750. */
  1751. priority: ['left', 'right', 'top', 'bottom'],
  1752. /**
  1753. * @prop {number} padding=5
  1754. * Amount of pixel used to define a minimum distance between the boundaries
  1755. * and the popper. This makes sure the popper always has a little padding
  1756. * between the edges of its container
  1757. */
  1758. padding: 5,
  1759. /**
  1760. * @prop {String|HTMLElement} boundariesElement='scrollParent'
  1761. * Boundaries used by the modifier. Can be `scrollParent`, `window`,
  1762. * `viewport` or any DOM element.
  1763. */
  1764. boundariesElement: 'scrollParent'
  1765. },
  1766. /**
  1767. * Modifier used to make sure the reference and its popper stay near each other
  1768. * without leaving any gap between the two. Especially useful when the arrow is
  1769. * enabled and you want to ensure that it points to its reference element.
  1770. * It cares only about the first axis. You can still have poppers with margin
  1771. * between the popper and its reference element.
  1772. * @memberof modifiers
  1773. * @inner
  1774. */
  1775. keepTogether: {
  1776. /** @prop {number} order=400 - Index used to define the order of execution */
  1777. order: 400,
  1778. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1779. enabled: true,
  1780. /** @prop {ModifierFn} */
  1781. fn: keepTogether
  1782. },
  1783. /**
  1784. * This modifier is used to move the `arrowElement` of the popper to make
  1785. * sure it is positioned between the reference element and its popper element.
  1786. * It will read the outer size of the `arrowElement` node to detect how many
  1787. * pixels of conjunction are needed.
  1788. *
  1789. * It has no effect if no `arrowElement` is provided.
  1790. * @memberof modifiers
  1791. * @inner
  1792. */
  1793. arrow: {
  1794. /** @prop {number} order=500 - Index used to define the order of execution */
  1795. order: 500,
  1796. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1797. enabled: true,
  1798. /** @prop {ModifierFn} */
  1799. fn: arrow,
  1800. /** @prop {String|HTMLElement} element='[x-arrow]' - Selector or node used as arrow */
  1801. element: '[x-arrow]'
  1802. },
  1803. /**
  1804. * Modifier used to flip the popper's placement when it starts to overlap its
  1805. * reference element.
  1806. *
  1807. * Requires the `preventOverflow` modifier before it in order to work.
  1808. *
  1809. * **NOTE:** this modifier will interrupt the current update cycle and will
  1810. * restart it if it detects the need to flip the placement.
  1811. * @memberof modifiers
  1812. * @inner
  1813. */
  1814. flip: {
  1815. /** @prop {number} order=600 - Index used to define the order of execution */
  1816. order: 600,
  1817. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1818. enabled: true,
  1819. /** @prop {ModifierFn} */
  1820. fn: flip,
  1821. /**
  1822. * @prop {String|Array} behavior='flip'
  1823. * The behavior used to change the popper's placement. It can be one of
  1824. * `flip`, `clockwise`, `counterclockwise` or an array with a list of valid
  1825. * placements (with optional variations)
  1826. */
  1827. behavior: 'flip',
  1828. /**
  1829. * @prop {number} padding=5
  1830. * The popper will flip if it hits the edges of the `boundariesElement`
  1831. */
  1832. padding: 5,
  1833. /**
  1834. * @prop {String|HTMLElement} boundariesElement='viewport'
  1835. * The element which will define the boundaries of the popper position.
  1836. * The popper will never be placed outside of the defined boundaries
  1837. * (except if `keepTogether` is enabled)
  1838. */
  1839. boundariesElement: 'viewport',
  1840. /**
  1841. * @prop {Boolean} flipVariations=false
  1842. * The popper will switch placement variation between `-start` and `-end` when
  1843. * the reference element overlaps its boundaries.
  1844. *
  1845. * The original placement should have a set variation.
  1846. */
  1847. flipVariations: false,
  1848. /**
  1849. * @prop {Boolean} flipVariationsByContent=false
  1850. * The popper will switch placement variation between `-start` and `-end` when
  1851. * the popper element overlaps its reference boundaries.
  1852. *
  1853. * The original placement should have a set variation.
  1854. */
  1855. flipVariationsByContent: false
  1856. },
  1857. /**
  1858. * Modifier used to make the popper flow toward the inner of the reference element.
  1859. * By default, when this modifier is disabled, the popper will be placed outside
  1860. * the reference element.
  1861. * @memberof modifiers
  1862. * @inner
  1863. */
  1864. inner: {
  1865. /** @prop {number} order=700 - Index used to define the order of execution */
  1866. order: 700,
  1867. /** @prop {Boolean} enabled=false - Whether the modifier is enabled or not */
  1868. enabled: false,
  1869. /** @prop {ModifierFn} */
  1870. fn: inner
  1871. },
  1872. /**
  1873. * Modifier used to hide the popper when its reference element is outside of the
  1874. * popper boundaries. It will set a `x-out-of-boundaries` attribute which can
  1875. * be used to hide with a CSS selector the popper when its reference is
  1876. * out of boundaries.
  1877. *
  1878. * Requires the `preventOverflow` modifier before it in order to work.
  1879. * @memberof modifiers
  1880. * @inner
  1881. */
  1882. hide: {
  1883. /** @prop {number} order=800 - Index used to define the order of execution */
  1884. order: 800,
  1885. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1886. enabled: true,
  1887. /** @prop {ModifierFn} */
  1888. fn: hide
  1889. },
  1890. /**
  1891. * Computes the style that will be applied to the popper element to gets
  1892. * properly positioned.
  1893. *
  1894. * Note that this modifier will not touch the DOM, it just prepares the styles
  1895. * so that `applyStyle` modifier can apply it. This separation is useful
  1896. * in case you need to replace `applyStyle` with a custom implementation.
  1897. *
  1898. * This modifier has `850` as `order` value to maintain backward compatibility
  1899. * with previous versions of Popper.js. Expect the modifiers ordering method
  1900. * to change in future major versions of the library.
  1901. *
  1902. * @memberof modifiers
  1903. * @inner
  1904. */
  1905. computeStyle: {
  1906. /** @prop {number} order=850 - Index used to define the order of execution */
  1907. order: 850,
  1908. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1909. enabled: true,
  1910. /** @prop {ModifierFn} */
  1911. fn: computeStyle,
  1912. /**
  1913. * @prop {Boolean} gpuAcceleration=true
  1914. * If true, it uses the CSS 3D transformation to position the popper.
  1915. * Otherwise, it will use the `top` and `left` properties
  1916. */
  1917. gpuAcceleration: true,
  1918. /**
  1919. * @prop {string} [x='bottom']
  1920. * Where to anchor the X axis (`bottom` or `top`). AKA X offset origin.
  1921. * Change this if your popper should grow in a direction different from `bottom`
  1922. */
  1923. x: 'bottom',
  1924. /**
  1925. * @prop {string} [x='left']
  1926. * Where to anchor the Y axis (`left` or `right`). AKA Y offset origin.
  1927. * Change this if your popper should grow in a direction different from `right`
  1928. */
  1929. y: 'right'
  1930. },
  1931. /**
  1932. * Applies the computed styles to the popper element.
  1933. *
  1934. * All the DOM manipulations are limited to this modifier. This is useful in case
  1935. * you want to integrate Popper.js inside a framework or view library and you
  1936. * want to delegate all the DOM manipulations to it.
  1937. *
  1938. * Note that if you disable this modifier, you must make sure the popper element
  1939. * has its position set to `absolute` before Popper.js can do its work!
  1940. *
  1941. * Just disable this modifier and define your own to achieve the desired effect.
  1942. *
  1943. * @memberof modifiers
  1944. * @inner
  1945. */
  1946. applyStyle: {
  1947. /** @prop {number} order=900 - Index used to define the order of execution */
  1948. order: 900,
  1949. /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
  1950. enabled: true,
  1951. /** @prop {ModifierFn} */
  1952. fn: applyStyle,
  1953. /** @prop {Function} */
  1954. onLoad: applyStyleOnLoad,
  1955. /**
  1956. * @deprecated since version 1.10.0, the property moved to `computeStyle` modifier
  1957. * @prop {Boolean} gpuAcceleration=true
  1958. * If true, it uses the CSS 3D transformation to position the popper.
  1959. * Otherwise, it will use the `top` and `left` properties
  1960. */
  1961. gpuAcceleration: undefined
  1962. }
  1963. };
  1964. /**
  1965. * The `dataObject` is an object containing all the information used by Popper.js.
  1966. * This object is passed to modifiers and to the `onCreate` and `onUpdate` callbacks.
  1967. * @name dataObject
  1968. * @property {Object} data.instance The Popper.js instance
  1969. * @property {String} data.placement Placement applied to popper
  1970. * @property {String} data.originalPlacement Placement originally defined on init
  1971. * @property {Boolean} data.flipped True if popper has been flipped by flip modifier
  1972. * @property {Boolean} data.hide True if the reference element is out of boundaries, useful to know when to hide the popper
  1973. * @property {HTMLElement} data.arrowElement Node used as arrow by arrow modifier
  1974. * @property {Object} data.styles Any CSS property defined here will be applied to the popper. It expects the JavaScript nomenclature (eg. `marginBottom`)
  1975. * @property {Object} data.arrowStyles Any CSS property defined here will be applied to the popper arrow. It expects the JavaScript nomenclature (eg. `marginBottom`)
  1976. * @property {Object} data.boundaries Offsets of the popper boundaries
  1977. * @property {Object} data.offsets The measurements of popper, reference and arrow elements
  1978. * @property {Object} data.offsets.popper `top`, `left`, `width`, `height` values
  1979. * @property {Object} data.offsets.reference `top`, `left`, `width`, `height` values
  1980. * @property {Object} data.offsets.arrow] `top` and `left` offsets, only one of them will be different from 0
  1981. */
  1982. /**
  1983. * Default options provided to Popper.js constructor.<br />
  1984. * These can be overridden using the `options` argument of Popper.js.<br />
  1985. * To override an option, simply pass an object with the same
  1986. * structure of the `options` object, as the 3rd argument. For example:
  1987. * ```
  1988. * new Popper(ref, pop, {
  1989. * modifiers: {
  1990. * preventOverflow: { enabled: false }
  1991. * }
  1992. * })
  1993. * ```
  1994. * @type {Object}
  1995. * @static
  1996. * @memberof Popper
  1997. */
  1998. var Defaults = {
  1999. /**
  2000. * Popper's placement.
  2001. * @prop {Popper.placements} placement='bottom'
  2002. */
  2003. placement: 'bottom',
  2004. /**
  2005. * Set this to true if you want popper to position it self in 'fixed' mode
  2006. * @prop {Boolean} positionFixed=false
  2007. */
  2008. positionFixed: false,
  2009. /**
  2010. * Whether events (resize, scroll) are initially enabled.
  2011. * @prop {Boolean} eventsEnabled=true
  2012. */
  2013. eventsEnabled: true,
  2014. /**
  2015. * Set to true if you want to automatically remove the popper when
  2016. * you call the `destroy` method.
  2017. * @prop {Boolean} removeOnDestroy=false
  2018. */
  2019. removeOnDestroy: false,
  2020. /**
  2021. * Callback called when the popper is created.<br />
  2022. * By default, it is set to no-op.<br />
  2023. * Access Popper.js instance with `data.instance`.
  2024. * @prop {onCreate}
  2025. */
  2026. onCreate: () => {},
  2027. /**
  2028. * Callback called when the popper is updated. This callback is not called
  2029. * on the initialization/creation of the popper, but only on subsequent
  2030. * updates.<br />
  2031. * By default, it is set to no-op.<br />
  2032. * Access Popper.js instance with `data.instance`.
  2033. * @prop {onUpdate}
  2034. */
  2035. onUpdate: () => {},
  2036. /**
  2037. * List of modifiers used to modify the offsets before they are applied to the popper.
  2038. * They provide most of the functionalities of Popper.js.
  2039. * @prop {modifiers}
  2040. */
  2041. modifiers
  2042. };
  2043. /**
  2044. * @callback onCreate
  2045. * @param {dataObject} data
  2046. */
  2047. /**
  2048. * @callback onUpdate
  2049. * @param {dataObject} data
  2050. */
  2051. // Utils
  2052. // Methods
  2053. class Popper {
  2054. /**
  2055. * Creates a new Popper.js instance.
  2056. * @class Popper
  2057. * @param {Element|referenceObject} reference - The reference element used to position the popper
  2058. * @param {Element} popper - The HTML / XML element used as the popper
  2059. * @param {Object} options - Your custom options to override the ones defined in [Defaults](#defaults)
  2060. * @return {Object} instance - The generated Popper.js instance
  2061. */
  2062. constructor(reference, popper, options = {}) {
  2063. this.scheduleUpdate = () => requestAnimationFrame(this.update);
  2064. // make update() debounced, so that it only runs at most once-per-tick
  2065. this.update = debounce(this.update.bind(this));
  2066. // with {} we create a new object with the options inside it
  2067. this.options = _extends({}, Popper.Defaults, options);
  2068. // init state
  2069. this.state = {
  2070. isDestroyed: false,
  2071. isCreated: false,
  2072. scrollParents: []
  2073. };
  2074. // get reference and popper elements (allow jQuery wrappers)
  2075. this.reference = reference && reference.jquery ? reference[0] : reference;
  2076. this.popper = popper && popper.jquery ? popper[0] : popper;
  2077. // Deep merge modifiers options
  2078. this.options.modifiers = {};
  2079. Object.keys(_extends({}, Popper.Defaults.modifiers, options.modifiers)).forEach(name => {
  2080. this.options.modifiers[name] = _extends({}, Popper.Defaults.modifiers[name] || {}, options.modifiers ? options.modifiers[name] : {});
  2081. });
  2082. // Refactoring modifiers' list (Object => Array)
  2083. this.modifiers = Object.keys(this.options.modifiers).map(name => _extends({
  2084. name
  2085. }, this.options.modifiers[name]))
  2086. // sort the modifiers by order
  2087. .sort((a, b) => a.order - b.order);
  2088. // modifiers have the ability to execute arbitrary code when Popper.js get inited
  2089. // such code is executed in the same order of its modifier
  2090. // they could add new properties to their options configuration
  2091. // BE AWARE: don't add options to `options.modifiers.name` but to `modifierOptions`!
  2092. this.modifiers.forEach(modifierOptions => {
  2093. if (modifierOptions.enabled && isFunction(modifierOptions.onLoad)) {
  2094. modifierOptions.onLoad(this.reference, this.popper, this.options, modifierOptions, this.state);
  2095. }
  2096. });
  2097. // fire the first update to position the popper in the right place
  2098. this.update();
  2099. const eventsEnabled = this.options.eventsEnabled;
  2100. if (eventsEnabled) {
  2101. // setup event listeners, they will take care of update the position in specific situations
  2102. this.enableEventListeners();
  2103. }
  2104. this.state.eventsEnabled = eventsEnabled;
  2105. }
  2106. // We can't use class properties because they don't get listed in the
  2107. // class prototype and break stuff like Sinon stubs
  2108. update() {
  2109. return update.call(this);
  2110. }
  2111. destroy() {
  2112. return destroy.call(this);
  2113. }
  2114. enableEventListeners() {
  2115. return enableEventListeners.call(this);
  2116. }
  2117. disableEventListeners() {
  2118. return disableEventListeners.call(this);
  2119. }
  2120. /**
  2121. * Schedules an update. It will run on the next UI update available.
  2122. * @method scheduleUpdate
  2123. * @memberof Popper
  2124. */
  2125. /**
  2126. * Collection of utilities useful when writing custom modifiers.
  2127. * Starting from version 1.7, this method is available only if you
  2128. * include `popper-utils.js` before `popper.js`.
  2129. *
  2130. * **DEPRECATION**: This way to access PopperUtils is deprecated
  2131. * and will be removed in v2! Use the PopperUtils module directly instead.
  2132. * Due to the high instability of the methods contained in Utils, we can't
  2133. * guarantee them to follow semver. Use them at your own risk!
  2134. * @static
  2135. * @private
  2136. * @type {Object}
  2137. * @deprecated since version 1.8
  2138. * @member Utils
  2139. * @memberof Popper
  2140. */
  2141. }
  2142. /**
  2143. * The `referenceObject` is an object that provides an interface compatible with Popper.js
  2144. * and lets you use it as replacement of a real DOM node.<br />
  2145. * You can use this method to position a popper relatively to a set of coordinates
  2146. * in case you don't have a DOM node to use as reference.
  2147. *
  2148. * ```
  2149. * new Popper(referenceObject, popperNode);
  2150. * ```
  2151. *
  2152. * NB: This feature isn't supported in Internet Explorer 10.
  2153. * @name referenceObject
  2154. * @property {Function} data.getBoundingClientRect
  2155. * A function that returns a set of coordinates compatible with the native `getBoundingClientRect` method.
  2156. * @property {number} data.clientWidth
  2157. * An ES6 getter that will return the width of the virtual reference element.
  2158. * @property {number} data.clientHeight
  2159. * An ES6 getter that will return the height of the virtual reference element.
  2160. */
  2161. Popper.Utils = (typeof window !== 'undefined' ? window : global).PopperUtils;
  2162. Popper.placements = placements;
  2163. Popper.Defaults = Defaults;
  2164. export default Popper;
  2165. //# sourceMappingURL=popper.js.map