popper.js 82 KB

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