popper.js 82 KB

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