You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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