popper.js 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771
  1. function getWindow(node) {
  2. if (node == null) {
  3. return window;
  4. }
  5. if (node.toString() !== '[object Window]') {
  6. var ownerDocument = node.ownerDocument;
  7. return ownerDocument ? ownerDocument.defaultView || window : window;
  8. }
  9. return node;
  10. };
  11. function isElement(node) {
  12. var OwnElement = getWindow(node).Element;
  13. return node instanceof OwnElement || node instanceof Element;
  14. };
  15. function isHTMLElement(node) {
  16. var OwnElement = getWindow(node).HTMLElement;
  17. return node instanceof OwnElement || node instanceof HTMLElement;
  18. }
  19. var math_max = Math.max;
  20. var math_min = Math.min;
  21. var round = Math.round;
  22. function getBoundingClientRect(element, includeScale) {
  23. if (includeScale === void 0) {
  24. includeScale = false;
  25. }
  26. var rect = element.getBoundingClientRect();
  27. var scaleX = 1;
  28. var scaleY = 1;
  29. if (isHTMLElement(element) && includeScale) {
  30. var offsetHeight = element.offsetHeight;
  31. var offsetWidth = element.offsetWidth; // Do not attempt to divide by 0, otherwise we get `Infinity` as scale
  32. // Fallback to 1 in case both values are `0`
  33. if (offsetWidth > 0) {
  34. scaleX = round(rect.width) / offsetWidth || 1;
  35. }
  36. if (offsetHeight > 0) {
  37. scaleY = round(rect.height) / offsetHeight || 1;
  38. }
  39. }
  40. return {
  41. width: rect.width / scaleX,
  42. height: rect.height / scaleY,
  43. top: rect.top / scaleY,
  44. right: rect.right / scaleX,
  45. bottom: rect.bottom / scaleY,
  46. left: rect.left / scaleX,
  47. x: rect.left / scaleX,
  48. y: rect.top / scaleY
  49. };
  50. };
  51. function getWindowScroll(node) {
  52. var win = getWindow(node);
  53. var scrollLeft = win.pageXOffset;
  54. var scrollTop = win.pageYOffset;
  55. return {
  56. scrollLeft: scrollLeft,
  57. scrollTop: scrollTop
  58. };
  59. };
  60. function getHTMLElementScroll(element) {
  61. return {
  62. scrollLeft: element.scrollLeft,
  63. scrollTop: element.scrollTop
  64. };
  65. };
  66. function getNodeScroll(node) {
  67. if (node === getWindow(node) || !isHTMLElement(node)) {
  68. return getWindowScroll(node);
  69. } else {
  70. return getHTMLElementScroll(node);
  71. }
  72. };
  73. function getNodeName(element) {
  74. return element ? (element.nodeName || '').toLowerCase() : null;
  75. };
  76. function getDocumentElement(element) {
  77. // $FlowFixMe[incompatible-return]: assume body is always available
  78. return ((isElement(element) ? element.ownerDocument : // $FlowFixMe[prop-missing]
  79. element.document) || window.document).documentElement;
  80. }
  81. function getWindowScrollBarX(element) {
  82. // If <html> has a CSS width greater than the viewport, then this will be
  83. // incorrect for RTL.
  84. // Popper 1 is broken in this case and never had a bug report so let's assume
  85. // it's not an issue. I don't think anyone ever specifies width on <html>
  86. // anyway.
  87. // Browsers where the left scrollbar doesn't cause an issue report `0` for
  88. // this (e.g. Edge 2019, IE11, Safari)
  89. return getBoundingClientRect(getDocumentElement(element)).left + getWindowScroll(element).scrollLeft;
  90. };
  91. function isScrollParent(element) {
  92. // Firefox wants us to check `-x` and `-y` variations as well
  93. var _getComputedStyle = getComputedStyle(element),
  94. overflow = _getComputedStyle.overflow,
  95. overflowX = _getComputedStyle.overflowX,
  96. overflowY = _getComputedStyle.overflowY;
  97. return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
  98. };
  99. function isElementScaled(element) {
  100. var rect = element.getBoundingClientRect();
  101. var scaleX = round(rect.width) / element.offsetWidth || 1;
  102. var scaleY = round(rect.height) / element.offsetHeight || 1;
  103. return scaleX !== 1 || scaleY !== 1;
  104. };
  105. function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
  106. if (isFixed === void 0) {
  107. isFixed = false;
  108. }
  109. var isOffsetParentAnElement = isHTMLElement(offsetParent);
  110. var offsetParentIsScaled = isHTMLElement(offsetParent) && isElementScaled(offsetParent);
  111. var documentElement = getDocumentElement(offsetParent);
  112. var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled);
  113. var scroll = {
  114. scrollLeft: 0,
  115. scrollTop: 0
  116. };
  117. var offsets = {
  118. x: 0,
  119. y: 0
  120. };
  121. if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
  122. if (getNodeName(offsetParent) !== 'body' || // https://github.com/popperjs/popper-core/issues/1078
  123. isScrollParent(documentElement)) {
  124. scroll = getNodeScroll(offsetParent);
  125. }
  126. if (isHTMLElement(offsetParent)) {
  127. offsets = getBoundingClientRect(offsetParent, true);
  128. offsets.x += offsetParent.clientLeft;
  129. offsets.y += offsetParent.clientTop;
  130. } else if (documentElement) {
  131. offsets.x = getWindowScrollBarX(documentElement);
  132. }
  133. }
  134. return {
  135. x: rect.left + scroll.scrollLeft - offsets.x,
  136. y: rect.top + scroll.scrollTop - offsets.y,
  137. width: rect.width,
  138. height: rect.height
  139. };
  140. };
  141. function getLayoutRect(element) {
  142. var clientRect = getBoundingClientRect(element); // Use the clientRect sizes if it's not been transformed.
  143. // Fixes https://github.com/popperjs/popper-core/issues/1223
  144. var width = element.offsetWidth;
  145. var height = element.offsetHeight;
  146. if (Math.abs(clientRect.width - width) <= 1) {
  147. width = clientRect.width;
  148. }
  149. if (Math.abs(clientRect.height - height) <= 1) {
  150. height = clientRect.height;
  151. }
  152. return {
  153. x: element.offsetLeft,
  154. y: element.offsetTop,
  155. width: width,
  156. height: height
  157. };
  158. };
  159. function getParentNode(element) {
  160. if (getNodeName(element) === 'html') {
  161. return element;
  162. }
  163. return (// this is a quicker (but less type safe) way to save quite some bytes from the bundle
  164. // $FlowFixMe[incompatible-return]
  165. // $FlowFixMe[prop-missing]
  166. element.assignedSlot || // step into the shadow DOM of the parent of a slotted node
  167. element.parentNode || ( // DOM Element detected
  168. isShadowRoot(element) ? element.host : null) || // ShadowRoot detected
  169. // $FlowFixMe[incompatible-call]: HTMLElement is a Node
  170. getDocumentElement(element) // fallback
  171. );
  172. };
  173. function getScrollParent(node) {
  174. if (['html', 'body', '#document'].indexOf(getNodeName(node)) >= 0) {
  175. // $FlowFixMe[incompatible-return]: assume body is always available
  176. return node.ownerDocument.body;
  177. }
  178. if (isHTMLElement(node) && isScrollParent(node)) {
  179. return node;
  180. }
  181. return getScrollParent(getParentNode(node));
  182. };
  183. function listScrollParents(element, list) {
  184. var _element$ownerDocumen;
  185. if (list === void 0) {
  186. list = [];
  187. }
  188. var scrollParent = getScrollParent(element);
  189. var isBody = scrollParent === ((_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body);
  190. var win = getWindow(scrollParent);
  191. var target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
  192. var updatedList = list.concat(target);
  193. return isBody ? updatedList : // $FlowFixMe[incompatible-call]: isBody tells us target will be an HTMLElement here
  194. updatedList.concat(listScrollParents(getParentNode(target)));
  195. };
  196. function isTableElement(element) {
  197. return ['table', 'td', 'th'].indexOf(getNodeName(element)) >= 0;
  198. };
  199. function getTrueOffsetParent(element) {
  200. if (!isHTMLElement(element) || // https://github.com/popperjs/popper-core/issues/837
  201. getComputedStyle(element).position === 'fixed') {
  202. return null;
  203. }
  204. return element.offsetParent;
  205. };
  206. function getContainingBlock(element) {
  207. var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') !== -1;
  208. var isIE = navigator.userAgent.indexOf('Trident') !== -1;
  209. if (isIE && isHTMLElement(element)) {
  210. // In IE 9, 10 and 11 fixed elements containing block is always established by the viewport
  211. var elementCss = getComputedStyle(element);
  212. if (elementCss.position === 'fixed') {
  213. return null;
  214. }
  215. }
  216. var currentNode = getParentNode(element);
  217. while (isHTMLElement(currentNode) && ['html', 'body'].indexOf(getNodeName(currentNode)) < 0) {
  218. var css = getComputedStyle(currentNode); // This is non-exhaustive but covers the most common CSS properties that
  219. // create a containing block.
  220. // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
  221. if (css.transform !== 'none' || css.perspective !== 'none' || css.contain === 'paint' || ['transform', 'perspective'].indexOf(css.willChange) !== -1 || isFirefox && css.willChange === 'filter' || isFirefox && css.filter && css.filter !== 'none') {
  222. return currentNode;
  223. } else {
  224. currentNode = currentNode.parentNode;
  225. }
  226. }
  227. return null;
  228. };
  229. function getOffsetParent(element) {
  230. var window = getWindow(element);
  231. var offsetParent = getTrueOffsetParent(element);
  232. while (offsetParent && isTableElement(offsetParent) && getComputedStyle(offsetParent).position === 'static') {
  233. offsetParent = getTrueOffsetParent(offsetParent);
  234. }
  235. if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle(offsetParent).position === 'static')) {
  236. return window;
  237. }
  238. return offsetParent || getContainingBlock(element) || window;
  239. };
  240. var enums_top = 'top';
  241. var bottom = 'bottom';
  242. var right = 'right';
  243. var left = 'left';
  244. var auto = 'auto';
  245. var basePlacements = [enums_top, bottom, right, left];
  246. var start = 'start';
  247. var end = 'end';
  248. var clippingParents = 'clippingParents';
  249. var viewport = 'viewport';
  250. var popper = 'popper';
  251. var reference = 'reference';
  252. var variationPlacements = /*#__PURE__*/basePlacements.reduce(function (acc, placement) {
  253. return acc.concat([placement + "-" + start, placement + "-" + end]);
  254. }, []);
  255. var enums_placements = /*#__PURE__*/[].concat(basePlacements, [auto]).reduce(function (acc, placement) {
  256. return acc.concat([placement, placement + "-" + start, placement + "-" + end]);
  257. }, []); // modifiers that need to read the DOM
  258. var beforeRead = 'beforeRead';
  259. var read = 'read';
  260. var afterRead = 'afterRead'; // pure-logic modifiers
  261. var beforeMain = 'beforeMain';
  262. var main = 'main';
  263. var afterMain = 'afterMain'; // modifier with the purpose to write to the DOM (or write into a framework state)
  264. var beforeWrite = 'beforeWrite';
  265. var write = 'write';
  266. var afterWrite = 'afterWrite';
  267. var modifierPhases = [beforeRead, read, afterRead, beforeMain, main, afterMain, beforeWrite, write, afterWrite];
  268. function order(modifiers) {
  269. var map = new Map();
  270. var visited = new Set();
  271. var result = [];
  272. modifiers.forEach(function (modifier) {
  273. map.set(modifier.name, modifier);
  274. }); // On visiting object, check for its dependencies and visit them recursively
  275. function sort(modifier) {
  276. visited.add(modifier.name);
  277. var requires = [].concat(modifier.requires || [], modifier.requiresIfExists || []);
  278. requires.forEach(function (dep) {
  279. if (!visited.has(dep)) {
  280. var depModifier = map.get(dep);
  281. if (depModifier) {
  282. sort(depModifier);
  283. }
  284. }
  285. });
  286. result.push(modifier);
  287. }
  288. modifiers.forEach(function (modifier) {
  289. if (!visited.has(modifier.name)) {
  290. // check for visited object
  291. sort(modifier);
  292. }
  293. });
  294. return result;
  295. };
  296. function orderModifiers(modifiers) {
  297. // order based on dependencies
  298. var orderedModifiers = order(modifiers); // order based on phase
  299. return modifierPhases.reduce(function (acc, phase) {
  300. return acc.concat(orderedModifiers.filter(function (modifier) {
  301. return modifier.phase === phase;
  302. }));
  303. }, []);
  304. };
  305. function debounce(fn) {
  306. var pending;
  307. return function () {
  308. if (!pending) {
  309. pending = new Promise(function (resolve) {
  310. Promise.resolve().then(function () {
  311. pending = undefined;
  312. resolve(fn());
  313. });
  314. });
  315. }
  316. return pending;
  317. };
  318. };
  319. function mergeByName(modifiers) {
  320. var merged = modifiers.reduce(function (merged, current) {
  321. var existing = merged[current.name];
  322. merged[current.name] = existing ? Object.assign({}, existing, current, {
  323. options: Object.assign({}, existing.options, current.options),
  324. data: Object.assign({}, existing.data, current.data)
  325. }) : current;
  326. return merged;
  327. }, {}); // IE11 does not support Object.values
  328. return Object.keys(merged).map(function (key) {
  329. return merged[key];
  330. });
  331. };
  332. var INVALID_ELEMENT_ERROR = 'Popper: Invalid reference or popper argument provided. They must be either a DOM element or virtual element.';
  333. var INFINITE_LOOP_ERROR = 'Popper: An infinite loop in the modifiers cycle has been detected! The cycle has been interrupted to prevent a browser crash.';
  334. var DEFAULT_OPTIONS = {
  335. placement: 'bottom',
  336. modifiers: [],
  337. strategy: 'absolute'
  338. };
  339. function areValidElements() {
  340. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  341. args[_key] = arguments[_key];
  342. }
  343. return !args.some(function (element) {
  344. return !(element && typeof element.getBoundingClientRect === 'function');
  345. });
  346. };
  347. function popperGenerator(generatorOptions) {
  348. if (generatorOptions === void 0) {
  349. generatorOptions = {};
  350. }
  351. var _generatorOptions = generatorOptions,
  352. _generatorOptions$def = _generatorOptions.defaultModifiers,
  353. defaultModifiers = _generatorOptions$def === void 0 ? [] : _generatorOptions$def,
  354. _generatorOptions$def2 = _generatorOptions.defaultOptions,
  355. defaultOptions = _generatorOptions$def2 === void 0 ? DEFAULT_OPTIONS : _generatorOptions$def2;
  356. return function createPopper(reference, popper, options) {
  357. if (options === void 0) {
  358. options = defaultOptions;
  359. }
  360. var state = {
  361. placement: 'bottom',
  362. orderedModifiers: [],
  363. options: Object.assign({}, DEFAULT_OPTIONS, defaultOptions),
  364. modifiersData: {},
  365. elements: {
  366. reference: reference,
  367. popper: popper
  368. },
  369. attributes: {},
  370. styles: {}
  371. };
  372. var effectCleanupFns = [];
  373. var isDestroyed = false;
  374. var instance = {
  375. state: state,
  376. setOptions: function setOptions(setOptionsAction) {
  377. var options = typeof setOptionsAction === 'function' ? setOptionsAction(state.options) : setOptionsAction;
  378. cleanupModifierEffects();
  379. state.options = Object.assign({}, defaultOptions, state.options, options);
  380. state.scrollParents = {
  381. reference: isElement(reference) ? listScrollParents(reference) : reference.contextElement ? listScrollParents(reference.contextElement) : [],
  382. popper: listScrollParents(popper)
  383. }; // Orders the modifiers based on their dependencies and `phase`
  384. // properties
  385. var orderedModifiers = orderModifiers(mergeByName([].concat(defaultModifiers, state.options.modifiers))); // Strip out disabled modifiers
  386. state.orderedModifiers = orderedModifiers.filter(function (m) {
  387. return m.enabled;
  388. }); // Validate the provided modifiers so that the consumer will get warned
  389. // if one of the modifiers is invalid for any reason
  390. if (false) { var _getComputedStyle, marginTop, marginRight, marginBottom, marginLeft, flipModifier, modifiers; }
  391. runModifierEffects();
  392. return instance.update();
  393. },
  394. // Sync update – it will always be executed, even if not necessary. This
  395. // is useful for low frequency updates where sync behavior simplifies the
  396. // logic.
  397. // For high frequency updates (e.g. `resize` and `scroll` events), always
  398. // prefer the async Popper#update method
  399. forceUpdate: function forceUpdate() {
  400. if (isDestroyed) {
  401. return;
  402. }
  403. var _state$elements = state.elements,
  404. reference = _state$elements.reference,
  405. popper = _state$elements.popper; // Don't proceed if `reference` or `popper` are not valid elements
  406. // anymore
  407. if (!areValidElements(reference, popper)) {
  408. if (false) {}
  409. return;
  410. } // Store the reference and popper rects to be read by modifiers
  411. state.rects = {
  412. reference: getCompositeRect(reference, getOffsetParent(popper), state.options.strategy === 'fixed'),
  413. popper: getLayoutRect(popper)
  414. }; // Modifiers have the ability to reset the current update cycle. The
  415. // most common use case for this is the `flip` modifier changing the
  416. // placement, which then needs to re-run all the modifiers, because the
  417. // logic was previously ran for the previous placement and is therefore
  418. // stale/incorrect
  419. state.reset = false;
  420. state.placement = state.options.placement; // On each update cycle, the `modifiersData` property for each modifier
  421. // is filled with the initial data specified by the modifier. This means
  422. // it doesn't persist and is fresh on each update.
  423. // To ensure persistent data, use `${name}#persistent`
  424. state.orderedModifiers.forEach(function (modifier) {
  425. return state.modifiersData[modifier.name] = Object.assign({}, modifier.data);
  426. });
  427. var __debug_loops__ = 0;
  428. for (var index = 0; index < state.orderedModifiers.length; index++) {
  429. if (false) {}
  430. if (state.reset === true) {
  431. state.reset = false;
  432. index = -1;
  433. continue;
  434. }
  435. var _state$orderedModifie = state.orderedModifiers[index],
  436. fn = _state$orderedModifie.fn,
  437. _state$orderedModifie2 = _state$orderedModifie.options,
  438. _options = _state$orderedModifie2 === void 0 ? {} : _state$orderedModifie2,
  439. name = _state$orderedModifie.name;
  440. if (typeof fn === 'function') {
  441. state = fn({
  442. state: state,
  443. options: _options,
  444. name: name,
  445. instance: instance
  446. }) || state;
  447. }
  448. }
  449. },
  450. // Async and optimistically optimized update – it will not be executed if
  451. // not necessary (debounced to run at most once-per-tick)
  452. update: debounce(function () {
  453. return new Promise(function (resolve) {
  454. instance.forceUpdate();
  455. resolve(state);
  456. });
  457. }),
  458. destroy: function destroy() {
  459. cleanupModifierEffects();
  460. isDestroyed = true;
  461. }
  462. };
  463. if (!areValidElements(reference, popper)) {
  464. if (false) {}
  465. return instance;
  466. }
  467. instance.setOptions(options).then(function (state) {
  468. if (!isDestroyed && options.onFirstUpdate) {
  469. options.onFirstUpdate(state);
  470. }
  471. }); // Modifiers have the ability to execute arbitrary code before the first
  472. // update cycle runs. They will be executed in the same order as the update
  473. // cycle. This is useful when a modifier adds some persistent data that
  474. // other modifiers need to use, but the modifier is run after the dependent
  475. // one.
  476. function runModifierEffects() {
  477. state.orderedModifiers.forEach(function (_ref3) {
  478. var name = _ref3.name,
  479. _ref3$options = _ref3.options,
  480. options = _ref3$options === void 0 ? {} : _ref3$options,
  481. effect = _ref3.effect;
  482. if (typeof effect === 'function') {
  483. var cleanupFn = effect({
  484. state: state,
  485. name: name,
  486. instance: instance,
  487. options: options
  488. });
  489. var noopFn = function noopFn() {};
  490. effectCleanupFns.push(cleanupFn || noopFn);
  491. }
  492. });
  493. }
  494. function cleanupModifierEffects() {
  495. effectCleanupFns.forEach(function (fn) {
  496. return fn();
  497. });
  498. effectCleanupFns = [];
  499. }
  500. return instance;
  501. };
  502. }
  503. var createPopper = ( null && (0));
  504. var passive = {
  505. passive: true
  506. };
  507. function effect(_ref) {
  508. var state = _ref.state,
  509. instance = _ref.instance,
  510. options = _ref.options;
  511. var _options$scroll = options.scroll,
  512. scroll = _options$scroll === void 0 ? true : _options$scroll,
  513. _options$resize = options.resize,
  514. resize = _options$resize === void 0 ? true : _options$resize;
  515. var window = getWindow(state.elements.popper);
  516. var scrollParents = [].concat(state.scrollParents.reference, state.scrollParents.popper);
  517. if (scroll) {
  518. scrollParents.forEach(function (scrollParent) {
  519. scrollParent.addEventListener('scroll', instance.update, passive);
  520. });
  521. }
  522. if (resize) {
  523. window.addEventListener('resize', instance.update, passive);
  524. }
  525. return function () {
  526. if (scroll) {
  527. scrollParents.forEach(function (scrollParent) {
  528. scrollParent.removeEventListener('scroll', instance.update, passive);
  529. });
  530. }
  531. if (resize) {
  532. window.removeEventListener('resize', instance.update, passive);
  533. }
  534. };
  535. };
  536. const eventListeners = ({
  537. name: 'eventListeners',
  538. enabled: true,
  539. phase: 'write',
  540. fn: function fn() {},
  541. effect: effect,
  542. data: {}
  543. });
  544. function getBasePlacement(placement) {
  545. return placement.split('-')[0];
  546. };
  547. function getVariation(placement) {
  548. return placement.split('-')[1];
  549. };
  550. function getMainAxisFromPlacement(placement) {
  551. return ['top', 'bottom'].indexOf(placement) >= 0 ? 'x' : 'y';
  552. };
  553. /**
  554. * OFFSET
  555. */
  556. function computeOffsets(_ref) {
  557. var reference = _ref.reference,
  558. element = _ref.element,
  559. placement = _ref.placement;
  560. var basePlacement = placement ? getBasePlacement(placement) : null;
  561. var variation = placement ? getVariation(placement) : null;
  562. var commonX = reference.x + reference.width / 2 - element.width / 2;
  563. var commonY = reference.y + reference.height / 2 - element.height / 2;
  564. var offsets;
  565. switch (basePlacement) {
  566. case enums_top:
  567. offsets = {
  568. x: commonX,
  569. y: reference.y - element.height
  570. };
  571. break;
  572. case bottom:
  573. offsets = {
  574. x: commonX,
  575. y: reference.y + reference.height
  576. };
  577. break;
  578. case right:
  579. offsets = {
  580. x: reference.x + reference.width,
  581. y: commonY
  582. };
  583. break;
  584. case left:
  585. offsets = {
  586. x: reference.x - element.width,
  587. y: commonY
  588. };
  589. break;
  590. default:
  591. offsets = {
  592. x: reference.x,
  593. y: reference.y
  594. };
  595. }
  596. var mainAxis = basePlacement ? getMainAxisFromPlacement(basePlacement) : null;
  597. if (mainAxis != null) {
  598. var len = mainAxis === 'y' ? 'height' : 'width';
  599. switch (variation) {
  600. case start:
  601. offsets[mainAxis] = offsets[mainAxis] - (reference[len] / 2 - element[len] / 2);
  602. break;
  603. case end:
  604. offsets[mainAxis] = offsets[mainAxis] + (reference[len] / 2 - element[len] / 2);
  605. break;
  606. default:
  607. }
  608. }
  609. return offsets;
  610. };
  611. function popperOffsets(_ref) {
  612. var state = _ref.state,
  613. name = _ref.name;
  614. // Offsets are the actual position the popper needs to have to be
  615. // properly positioned near its reference element
  616. // This is the most basic placement, and will be adjusted by
  617. // the modifiers in the next step
  618. state.modifiersData[name] = computeOffsets({
  619. reference: state.rects.reference,
  620. element: state.rects.popper,
  621. strategy: 'absolute',
  622. placement: state.placement
  623. });
  624. };
  625. const modifiers_popperOffsets = ({
  626. name: 'popperOffsets',
  627. enabled: true,
  628. phase: 'read',
  629. fn: popperOffsets,
  630. data: {}
  631. });
  632. /**
  633. * STYLES
  634. */
  635. var unsetSides = {
  636. top: 'auto',
  637. right: 'auto',
  638. bottom: 'auto',
  639. left: 'auto'
  640. };
  641. function roundOffsetsByDPR(_ref) {
  642. var x = _ref.x,
  643. y = _ref.y;
  644. var win = window;
  645. var dpr = win.devicePixelRatio || 1;
  646. return {
  647. x: round(x * dpr) / dpr || 0,
  648. y: round(y * dpr) / dpr || 0
  649. };
  650. };
  651. function mapToStyles(_ref2) {
  652. var _Object$assign2;
  653. var popper = _ref2.popper,
  654. popperRect = _ref2.popperRect,
  655. placement = _ref2.placement,
  656. variation = _ref2.variation,
  657. offsets = _ref2.offsets,
  658. position = _ref2.position,
  659. gpuAcceleration = _ref2.gpuAcceleration,
  660. adaptive = _ref2.adaptive,
  661. roundOffsets = _ref2.roundOffsets,
  662. isFixed = _ref2.isFixed;
  663. var _ref3 = roundOffsets === true ? roundOffsetsByDPR(offsets) : typeof roundOffsets === 'function' ? roundOffsets(offsets) : offsets,
  664. _ref3$x = _ref3.x,
  665. x = _ref3$x === void 0 ? 0 : _ref3$x,
  666. _ref3$y = _ref3.y,
  667. y = _ref3$y === void 0 ? 0 : _ref3$y;
  668. var hasX = offsets.hasOwnProperty('x');
  669. var hasY = offsets.hasOwnProperty('y');
  670. var sideX = left;
  671. var sideY = enums_top;
  672. var win = window;
  673. if (adaptive) {
  674. var offsetParent = getOffsetParent(popper);
  675. var heightProp = 'clientHeight';
  676. var widthProp = 'clientWidth';
  677. if (offsetParent === getWindow(popper)) {
  678. offsetParent = getDocumentElement(popper);
  679. if (getComputedStyle(offsetParent).position !== 'static' && position === 'absolute') {
  680. heightProp = 'scrollHeight';
  681. widthProp = 'scrollWidth';
  682. }
  683. } // $FlowFixMe[incompatible-cast]: force type refinement, we compare offsetParent with window above, but Flow doesn't detect it
  684. offsetParent = offsetParent;
  685. if (placement === enums_top || (placement === left || placement === right) && variation === end) {
  686. sideY = bottom;
  687. var offsetY = isFixed && win.visualViewport ? win.visualViewport.height : // $FlowFixMe[prop-missing]
  688. offsetParent[heightProp];
  689. y -= offsetY - popperRect.height;
  690. y *= gpuAcceleration ? 1 : -1;
  691. }
  692. if (placement === left || (placement === enums_top || placement === bottom) && variation === end) {
  693. sideX = right;
  694. var offsetX = isFixed && win.visualViewport ? win.visualViewport.width : // $FlowFixMe[prop-missing]
  695. offsetParent[widthProp];
  696. x -= offsetX - popperRect.width;
  697. x *= gpuAcceleration ? 1 : -1;
  698. }
  699. }
  700. var commonStyles = Object.assign({
  701. position: position
  702. }, adaptive && unsetSides);
  703. if (gpuAcceleration) {
  704. var _Object$assign;
  705. return Object.assign({}, commonStyles, (_Object$assign = {}, _Object$assign[sideY] = hasY ? '0' : '', _Object$assign[sideX] = hasX ? '0' : '', _Object$assign.transform = (win.devicePixelRatio || 1) <= 1 ? "translate(" + x + "px, " + y + "px)" : "translate3d(" + x + "px, " + y + "px, 0)", _Object$assign));
  706. }
  707. return Object.assign({}, commonStyles, (_Object$assign2 = {}, _Object$assign2[sideY] = hasY ? y + "px" : '', _Object$assign2[sideX] = hasX ? x + "px" : '', _Object$assign2.transform = '', _Object$assign2));
  708. };
  709. function computeStyles(_ref4) {
  710. var state = _ref4.state,
  711. options = _ref4.options;
  712. var _options$gpuAccelerat = options.gpuAcceleration,
  713. gpuAcceleration = _options$gpuAccelerat === void 0 ? true : _options$gpuAccelerat,
  714. _options$adaptive = options.adaptive,
  715. adaptive = _options$adaptive === void 0 ? true : _options$adaptive,
  716. _options$roundOffsets = options.roundOffsets,
  717. roundOffsets = _options$roundOffsets === void 0 ? true : _options$roundOffsets;
  718. if (false) { var transitionProperty; }
  719. var commonStyles = {
  720. placement: getBasePlacement(state.placement),
  721. variation: getVariation(state.placement),
  722. popper: state.elements.popper,
  723. popperRect: state.rects.popper,
  724. gpuAcceleration: gpuAcceleration,
  725. isFixed: state.options.strategy === 'fixed'
  726. };
  727. if (state.modifiersData.popperOffsets != null) {
  728. state.styles.popper = Object.assign({}, state.styles.popper, mapToStyles(Object.assign({}, commonStyles, {
  729. offsets: state.modifiersData.popperOffsets,
  730. position: state.options.strategy,
  731. adaptive: adaptive,
  732. roundOffsets: roundOffsets
  733. })));
  734. }
  735. if (state.modifiersData.arrow != null) {
  736. state.styles.arrow = Object.assign({}, state.styles.arrow, mapToStyles(Object.assign({}, commonStyles, {
  737. offsets: state.modifiersData.arrow,
  738. position: 'absolute',
  739. adaptive: false,
  740. roundOffsets: roundOffsets
  741. })));
  742. }
  743. state.attributes.popper = Object.assign({}, state.attributes.popper, {
  744. 'data-popper-placement': state.placement
  745. });
  746. };
  747. const modifiers_computeStyles = ({
  748. name: 'computeStyles',
  749. enabled: true,
  750. phase: 'beforeWrite',
  751. fn: computeStyles,
  752. data: {}
  753. });
  754. function applyStyles(_ref) {
  755. var state = _ref.state;
  756. Object.keys(state.elements).forEach(function (name) {
  757. var style = state.styles[name] || {};
  758. var attributes = state.attributes[name] || {};
  759. var element = state.elements[name]; // arrow is optional + virtual elements
  760. if (!isHTMLElement(element) || !getNodeName(element)) {
  761. return;
  762. } // Flow doesn't support to extend this property, but it's the most
  763. // effective way to apply styles to an HTMLElement
  764. // $FlowFixMe[cannot-write]
  765. Object.assign(element.style, style);
  766. Object.keys(attributes).forEach(function (name) {
  767. var value = attributes[name];
  768. if (value === false) {
  769. element.removeAttribute(name);
  770. } else {
  771. element.setAttribute(name, value === true ? '' : value);
  772. }
  773. });
  774. });
  775. };
  776. function applyStyles_effect(_ref2) {
  777. var state = _ref2.state;
  778. var initialStyles = {
  779. popper: {
  780. position: state.options.strategy,
  781. left: '0',
  782. top: '0',
  783. margin: '0'
  784. },
  785. arrow: {
  786. position: 'absolute'
  787. },
  788. reference: {}
  789. };
  790. Object.assign(state.elements.popper.style, initialStyles.popper);
  791. state.styles = initialStyles;
  792. if (state.elements.arrow) {
  793. Object.assign(state.elements.arrow.style, initialStyles.arrow);
  794. }
  795. return function () {
  796. Object.keys(state.elements).forEach(function (name) {
  797. var element = state.elements[name];
  798. var attributes = state.attributes[name] || {};
  799. var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? state.styles[name] : initialStyles[name]); // Set all values to an empty string to unset them
  800. var style = styleProperties.reduce(function (style, property) {
  801. style[property] = '';
  802. return style;
  803. }, {}); // arrow is optional + virtual elements
  804. if (!isHTMLElement(element) || !getNodeName(element)) {
  805. return;
  806. }
  807. Object.assign(element.style, style);
  808. Object.keys(attributes).forEach(function (attribute) {
  809. element.removeAttribute(attribute);
  810. });
  811. });
  812. };
  813. };
  814. const modifiers_applyStyles = ({
  815. name: 'applyStyles',
  816. enabled: true,
  817. phase: 'write',
  818. fn: applyStyles,
  819. effect: applyStyles_effect,
  820. requires: ['computeStyles']
  821. });
  822. /**
  823. * OFFSET
  824. */
  825. function distanceAndSkiddingToXY(placement, rects, offset) {
  826. var basePlacement = getBasePlacement(placement);
  827. var invertDistance = [left, enums_top].indexOf(basePlacement) >= 0 ? -1 : 1;
  828. var _ref = typeof offset === 'function' ? offset(Object.assign({}, rects, {
  829. placement: placement
  830. })) : offset,
  831. skidding = _ref[0],
  832. distance = _ref[1];
  833. skidding = skidding || 0;
  834. distance = (distance || 0) * invertDistance;
  835. return [left, right].indexOf(basePlacement) >= 0 ? {
  836. x: distance,
  837. y: skidding
  838. } : {
  839. x: skidding,
  840. y: distance
  841. };
  842. };
  843. function offset(_ref2) {
  844. var state = _ref2.state,
  845. options = _ref2.options,
  846. name = _ref2.name;
  847. var _options$offset = options.offset,
  848. offset = _options$offset === void 0 ? [0, 0] : _options$offset;
  849. var data = enums_placements.reduce(function (acc, placement) {
  850. acc[placement] = distanceAndSkiddingToXY(placement, state.rects, offset);
  851. return acc;
  852. }, {});
  853. var _data$state$placement = data[state.placement],
  854. x = _data$state$placement.x,
  855. y = _data$state$placement.y;
  856. if (state.modifiersData.popperOffsets != null) {
  857. state.modifiersData.popperOffsets.x += x;
  858. state.modifiersData.popperOffsets.y += y;
  859. }
  860. state.modifiersData[name] = data;
  861. };
  862. const modifiers_offset = ({
  863. name: 'offset',
  864. enabled: true,
  865. phase: 'main',
  866. requires: ['popperOffsets'],
  867. fn: offset
  868. });
  869. var hash = {
  870. left: 'right',
  871. right: 'left',
  872. bottom: 'top',
  873. top: 'bottom'
  874. };
  875. function getOppositePlacement(placement) {
  876. return placement.replace(/left|right|bottom|top/g, function (matched) {
  877. return hash[matched];
  878. });
  879. };
  880. var getOppositeVariationPlacement_hash = {
  881. start: 'end',
  882. end: 'start'
  883. };
  884. function getOppositeVariationPlacement(placement) {
  885. return placement.replace(/start|end/g, function (matched) {
  886. return getOppositeVariationPlacement_hash[matched];
  887. });
  888. };
  889. function getViewportRect(element) {
  890. var win = getWindow(element);
  891. var html = getDocumentElement(element);
  892. var visualViewport = win.visualViewport;
  893. var width = html.clientWidth;
  894. var height = html.clientHeight;
  895. var x = 0;
  896. var y = 0; // NB: This isn't supported on iOS <= 12. If the keyboard is open, the popper
  897. // can be obscured underneath it.
  898. // Also, `html.clientHeight` adds the bottom bar height in Safari iOS, even
  899. // if it isn't open, so if this isn't available, the popper will be detected
  900. // to overflow the bottom of the screen too early.
  901. if (visualViewport) {
  902. width = visualViewport.width;
  903. height = visualViewport.height; // Uses Layout Viewport (like Chrome; Safari does not currently)
  904. // In Chrome, it returns a value very close to 0 (+/-) but contains rounding
  905. // errors due to floating point numbers, so we need to check precision.
  906. // Safari returns a number <= 0, usually < -1 when pinch-zoomed
  907. // Feature detection fails in mobile emulation mode in Chrome.
  908. // Math.abs(win.innerWidth / visualViewport.scale - visualViewport.width) <
  909. // 0.001
  910. // Fallback here: "Not Safari" userAgent
  911. if (!/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
  912. x = visualViewport.offsetLeft;
  913. y = visualViewport.offsetTop;
  914. }
  915. }
  916. return {
  917. width: width,
  918. height: height,
  919. x: x + getWindowScrollBarX(element),
  920. y: y
  921. };
  922. };
  923. function getDocumentRect(element) {
  924. var _element$ownerDocumen;
  925. var html = getDocumentElement(element);
  926. var winScroll = getWindowScroll(element);
  927. var body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
  928. var width = math_max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
  929. var height = math_max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
  930. var x = -winScroll.scrollLeft + getWindowScrollBarX(element);
  931. var y = -winScroll.scrollTop;
  932. if (getComputedStyle(body || html).direction === 'rtl') {
  933. x += math_max(html.clientWidth, body ? body.clientWidth : 0) - width;
  934. }
  935. return {
  936. width: width,
  937. height: height,
  938. x: x,
  939. y: y
  940. };
  941. };
  942. function contains(parent, child) {
  943. var rootNode = child.getRootNode && child.getRootNode(); // First, attempt with faster native method
  944. if (parent.contains(child)) {
  945. return true;
  946. } // then fallback to custom implementation with Shadow DOM support
  947. else if (rootNode && isShadowRoot(rootNode)) {
  948. var next = child;
  949. do {
  950. if (next && parent.isSameNode(next)) {
  951. return true;
  952. } // $FlowFixMe[prop-missing]: need a better way to handle this...
  953. next = next.parentNode || next.host;
  954. } while (next);
  955. } // Give up, the result is false
  956. return false;
  957. };
  958. function rectToClientRect(rect) {
  959. return Object.assign({}, rect, {
  960. left: rect.x,
  961. top: rect.y,
  962. right: rect.x + rect.width,
  963. bottom: rect.y + rect.height
  964. });
  965. };
  966. function getInnerBoundingClientRect(element) {
  967. var rect = getBoundingClientRect(element);
  968. rect.top = rect.top + element.clientTop;
  969. rect.left = rect.left + element.clientLeft;
  970. rect.bottom = rect.top + element.clientHeight;
  971. rect.right = rect.left + element.clientWidth;
  972. rect.width = element.clientWidth;
  973. rect.height = element.clientHeight;
  974. rect.x = rect.left;
  975. rect.y = rect.top;
  976. return rect;
  977. }
  978. function getClientRectFromMixedType(element, clippingParent) {
  979. return clippingParent === viewport ? rectToClientRect(getViewportRect(element)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
  980. };
  981. function getClippingParents(element) {
  982. var clippingParents = listScrollParents(getParentNode(element));
  983. var canEscapeClipping = ['absolute', 'fixed'].indexOf(getComputedStyle(element).position) >= 0;
  984. var clipperElement = canEscapeClipping && isHTMLElement(element) ? getOffsetParent(element) : element;
  985. if (!isElement(clipperElement)) {
  986. return [];
  987. } // $FlowFixMe[incompatible-return]: https://github.com/facebook/flow/issues/1414
  988. return clippingParents.filter(function (clippingParent) {
  989. return isElement(clippingParent) && contains(clippingParent, clipperElement) && getNodeName(clippingParent) !== 'body' && (canEscapeClipping ? getComputedStyle(clippingParent).position !== 'static' : true);
  990. });
  991. };
  992. function getClippingRect(element, boundary, rootBoundary) {
  993. var mainClippingParents = boundary === 'clippingParents' ? getClippingParents(element) : [].concat(boundary);
  994. var clippingParents = [].concat(mainClippingParents, [rootBoundary]);
  995. var firstClippingParent = clippingParents[0];
  996. var clippingRect = clippingParents.reduce(function (accRect, clippingParent) {
  997. var rect = getClientRectFromMixedType(element, clippingParent);
  998. accRect.top = math_max(rect.top, accRect.top);
  999. accRect.right = math_min(rect.right, accRect.right);
  1000. accRect.bottom = math_min(rect.bottom, accRect.bottom);
  1001. accRect.left = math_max(rect.left, accRect.left);
  1002. return accRect;
  1003. }, getClientRectFromMixedType(element, firstClippingParent));
  1004. clippingRect.width = clippingRect.right - clippingRect.left;
  1005. clippingRect.height = clippingRect.bottom - clippingRect.top;
  1006. clippingRect.x = clippingRect.left;
  1007. clippingRect.y = clippingRect.top;
  1008. return clippingRect;
  1009. };
  1010. function getFreshSideObject() {
  1011. return {
  1012. top: 0,
  1013. right: 0,
  1014. bottom: 0,
  1015. left: 0
  1016. };
  1017. };
  1018. function mergePaddingObject(paddingObject) {
  1019. return Object.assign({}, getFreshSideObject(), paddingObject);
  1020. };
  1021. function expandToHashMap(value, keys) {
  1022. return keys.reduce(function (hashMap, key) {
  1023. hashMap[key] = value;
  1024. return hashMap;
  1025. }, {});
  1026. };
  1027. function detectOverflow(state, options) {
  1028. if (options === void 0) {
  1029. options = {};
  1030. }
  1031. var _options = options,
  1032. _options$placement = _options.placement,
  1033. placement = _options$placement === void 0 ? state.placement : _options$placement,
  1034. _options$boundary = _options.boundary,
  1035. boundary = _options$boundary === void 0 ? clippingParents : _options$boundary,
  1036. _options$rootBoundary = _options.rootBoundary,
  1037. rootBoundary = _options$rootBoundary === void 0 ? viewport : _options$rootBoundary,
  1038. _options$elementConte = _options.elementContext,
  1039. elementContext = _options$elementConte === void 0 ? popper : _options$elementConte,
  1040. _options$altBoundary = _options.altBoundary,
  1041. altBoundary = _options$altBoundary === void 0 ? false : _options$altBoundary,
  1042. _options$padding = _options.padding,
  1043. padding = _options$padding === void 0 ? 0 : _options$padding;
  1044. var paddingObject = mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
  1045. var altContext = elementContext === popper ? reference : popper;
  1046. var popperRect = state.rects.popper;
  1047. var element = state.elements[altBoundary ? altContext : elementContext];
  1048. var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary);
  1049. var referenceClientRect = getBoundingClientRect(state.elements.reference);
  1050. var popperOffsets = computeOffsets({
  1051. reference: referenceClientRect,
  1052. element: popperRect,
  1053. strategy: 'absolute',
  1054. placement: placement
  1055. });
  1056. var popperClientRect = rectToClientRect(Object.assign({}, popperRect, popperOffsets));
  1057. var elementClientRect = elementContext === popper ? popperClientRect : referenceClientRect; // positive = overflowing the clipping rect
  1058. // 0 or negative = within the clipping rect
  1059. var overflowOffsets = {
  1060. top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
  1061. bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
  1062. left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
  1063. right: elementClientRect.right - clippingClientRect.right + paddingObject.right
  1064. };
  1065. var offsetData = state.modifiersData.offset; // Offsets can be applied only to the popper element
  1066. if (elementContext === popper && offsetData) {
  1067. var offset = offsetData[placement];
  1068. Object.keys(overflowOffsets).forEach(function (key) {
  1069. var multiply = [right, bottom].indexOf(key) >= 0 ? 1 : -1;
  1070. var axis = [enums_top, bottom].indexOf(key) >= 0 ? 'y' : 'x';
  1071. overflowOffsets[key] += offset[axis] * multiply;
  1072. });
  1073. }
  1074. return overflowOffsets;
  1075. };
  1076. /**
  1077. * FLIP
  1078. */
  1079. function getExpandedFallbackPlacements(placement) {
  1080. if (getBasePlacement(placement) === auto) {
  1081. return [];
  1082. }
  1083. var oppositePlacement = getOppositePlacement(placement);
  1084. return [getOppositeVariationPlacement(placement), oppositePlacement, getOppositeVariationPlacement(oppositePlacement)];
  1085. };
  1086. function flip(_ref) {
  1087. var state = _ref.state,
  1088. options = _ref.options,
  1089. name = _ref.name;
  1090. if (state.modifiersData[name]._skip) {
  1091. return;
  1092. }
  1093. var _options$mainAxis = options.mainAxis,
  1094. checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis,
  1095. _options$altAxis = options.altAxis,
  1096. checkAltAxis = _options$altAxis === void 0 ? true : _options$altAxis,
  1097. specifiedFallbackPlacements = options.fallbackPlacements,
  1098. padding = options.padding,
  1099. boundary = options.boundary,
  1100. rootBoundary = options.rootBoundary,
  1101. altBoundary = options.altBoundary,
  1102. _options$flipVariatio = options.flipVariations,
  1103. flipVariations = _options$flipVariatio === void 0 ? true : _options$flipVariatio,
  1104. allowedAutoPlacements = options.allowedAutoPlacements;
  1105. var preferredPlacement = state.options.placement;
  1106. var basePlacement = getBasePlacement(preferredPlacement);
  1107. var isBasePlacement = basePlacement === preferredPlacement;
  1108. var fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipVariations ? [getOppositePlacement(preferredPlacement)] : getExpandedFallbackPlacements(preferredPlacement));
  1109. var placements = [preferredPlacement].concat(fallbackPlacements).reduce(function (acc, placement) {
  1110. return acc.concat(getBasePlacement(placement) === auto ? computeAutoPlacement(state, {
  1111. placement: placement,
  1112. boundary: boundary,
  1113. rootBoundary: rootBoundary,
  1114. padding: padding,
  1115. flipVariations: flipVariations,
  1116. allowedAutoPlacements: allowedAutoPlacements
  1117. }) : placement);
  1118. }, []);
  1119. var referenceRect = state.rects.reference;
  1120. var popperRect = state.rects.popper;
  1121. var checksMap = new Map();
  1122. var makeFallbackChecks = true;
  1123. var firstFittingPlacement = placements[0];
  1124. for (var i = 0; i < placements.length; i++) {
  1125. var placement = placements[i];
  1126. var _basePlacement = getBasePlacement(placement);
  1127. var isStartVariation = getVariation(placement) === start;
  1128. var isVertical = [enums_top, bottom].indexOf(_basePlacement) >= 0;
  1129. var len = isVertical ? 'width' : 'height';
  1130. var overflow = detectOverflow(state, {
  1131. placement: placement,
  1132. boundary: boundary,
  1133. rootBoundary: rootBoundary,
  1134. altBoundary: altBoundary,
  1135. padding: padding
  1136. });
  1137. var mainVariationSide = isVertical ? isStartVariation ? right : left : isStartVariation ? bottom : enums_top;
  1138. if (referenceRect[len] > popperRect[len]) {
  1139. mainVariationSide = getOppositePlacement(mainVariationSide);
  1140. }
  1141. var altVariationSide = getOppositePlacement(mainVariationSide);
  1142. var checks = [];
  1143. if (checkMainAxis) {
  1144. checks.push(overflow[_basePlacement] <= 0);
  1145. }
  1146. if (checkAltAxis) {
  1147. checks.push(overflow[mainVariationSide] <= 0, overflow[altVariationSide] <= 0);
  1148. }
  1149. if (checks.every(function (check) {
  1150. return check;
  1151. })) {
  1152. firstFittingPlacement = placement;
  1153. makeFallbackChecks = false;
  1154. break;
  1155. }
  1156. checksMap.set(placement, checks);
  1157. }
  1158. if (makeFallbackChecks) {
  1159. // `2` may be desired in some cases – research later
  1160. var numberOfChecks = flipVariations ? 3 : 1;
  1161. var _loop = function _loop(_i) {
  1162. var fittingPlacement = placements.find(function (placement) {
  1163. var checks = checksMap.get(placement);
  1164. if (checks) {
  1165. return checks.slice(0, _i).every(function (check) {
  1166. return check;
  1167. });
  1168. }
  1169. });
  1170. if (fittingPlacement) {
  1171. firstFittingPlacement = fittingPlacement;
  1172. return "break";
  1173. }
  1174. };
  1175. for (var _i = numberOfChecks; _i > 0; _i--) {
  1176. var _ret = _loop(_i);
  1177. if (_ret === "break") break;
  1178. }
  1179. }
  1180. if (state.placement !== firstFittingPlacement) {
  1181. state.modifiersData[name]._skip = true;
  1182. state.placement = firstFittingPlacement;
  1183. state.reset = true;
  1184. }
  1185. };
  1186. const modifiers_flip = ({
  1187. name: 'flip',
  1188. enabled: true,
  1189. phase: 'main',
  1190. fn: flip,
  1191. requiresIfExists: ['offset'],
  1192. data: {
  1193. _skip: false
  1194. }
  1195. });
  1196. function getAltAxis(axis) {
  1197. return axis === 'x' ? 'y' : 'x';
  1198. };
  1199. function within(min, value, max) {
  1200. return math_max(min, math_min(value, max));
  1201. };
  1202. function withinMaxClamp(min, value, max) {
  1203. var v = within(min, value, max);
  1204. return v > max ? max : v;
  1205. };
  1206. /**
  1207. * OVERFLOW
  1208. */
  1209. function preventOverflow(_ref) {
  1210. var state = _ref.state,
  1211. options = _ref.options,
  1212. name = _ref.name;
  1213. var _options$mainAxis = options.mainAxis,
  1214. checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis,
  1215. _options$altAxis = options.altAxis,
  1216. checkAltAxis = _options$altAxis === void 0 ? false : _options$altAxis,
  1217. boundary = options.boundary,
  1218. rootBoundary = options.rootBoundary,
  1219. altBoundary = options.altBoundary,
  1220. padding = options.padding,
  1221. _options$tether = options.tether,
  1222. tether = _options$tether === void 0 ? true : _options$tether,
  1223. _options$tetherOffset = options.tetherOffset,
  1224. tetherOffset = _options$tetherOffset === void 0 ? 0 : _options$tetherOffset;
  1225. var overflow = detectOverflow(state, {
  1226. boundary: boundary,
  1227. rootBoundary: rootBoundary,
  1228. padding: padding,
  1229. altBoundary: altBoundary
  1230. });
  1231. var basePlacement = getBasePlacement(state.placement);
  1232. var variation = getVariation(state.placement);
  1233. var isBasePlacement = !variation;
  1234. var mainAxis = getMainAxisFromPlacement(basePlacement);
  1235. var altAxis = getAltAxis(mainAxis);
  1236. var popperOffsets = state.modifiersData.popperOffsets;
  1237. var referenceRect = state.rects.reference;
  1238. var popperRect = state.rects.popper;
  1239. var tetherOffsetValue = typeof tetherOffset === 'function' ? tetherOffset(Object.assign({}, state.rects, {
  1240. placement: state.placement
  1241. })) : tetherOffset;
  1242. var normalizedTetherOffsetValue = typeof tetherOffsetValue === 'number' ? {
  1243. mainAxis: tetherOffsetValue,
  1244. altAxis: tetherOffsetValue
  1245. } : Object.assign({
  1246. mainAxis: 0,
  1247. altAxis: 0
  1248. }, tetherOffsetValue);
  1249. var offsetModifierState = state.modifiersData.offset ? state.modifiersData.offset[state.placement] : null;
  1250. var data = {
  1251. x: 0,
  1252. y: 0
  1253. };
  1254. if (!popperOffsets) {
  1255. return;
  1256. }
  1257. if (checkMainAxis) {
  1258. var _offsetModifierState$;
  1259. var mainSide = mainAxis === 'y' ? enums_top : left;
  1260. var altSide = mainAxis === 'y' ? bottom : right;
  1261. var len = mainAxis === 'y' ? 'height' : 'width';
  1262. var offset = popperOffsets[mainAxis];
  1263. var min = offset + overflow[mainSide];
  1264. var max = offset - overflow[altSide];
  1265. var additive = tether ? -popperRect[len] / 2 : 0;
  1266. var minLen = variation === start ? referenceRect[len] : popperRect[len];
  1267. var maxLen = variation === start ? -popperRect[len] : -referenceRect[len]; // We need to include the arrow in the calculation so the arrow doesn't go
  1268. // outside the reference bounds
  1269. var arrowElement = state.elements.arrow;
  1270. var arrowRect = tether && arrowElement ? getLayoutRect(arrowElement) : {
  1271. width: 0,
  1272. height: 0
  1273. };
  1274. var arrowPaddingObject = state.modifiersData['arrow#persistent'] ? state.modifiersData['arrow#persistent'].padding : getFreshSideObject();
  1275. var arrowPaddingMin = arrowPaddingObject[mainSide];
  1276. var arrowPaddingMax = arrowPaddingObject[altSide]; // If the reference length is smaller than the arrow length, we don't want
  1277. // to include its full size in the calculation. If the reference is small
  1278. // and near the edge of a boundary, the popper can overflow even if the
  1279. // reference is not overflowing as well (e.g. virtual elements with no
  1280. // width or height)
  1281. var arrowLen = within(0, referenceRect[len], arrowRect[len]);
  1282. var minOffset = isBasePlacement ? referenceRect[len] / 2 - additive - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis : minLen - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis;
  1283. var maxOffset = isBasePlacement ? -referenceRect[len] / 2 + additive + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis : maxLen + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis;
  1284. var arrowOffsetParent = state.elements.arrow && getOffsetParent(state.elements.arrow);
  1285. var clientOffset = arrowOffsetParent ? mainAxis === 'y' ? arrowOffsetParent.clientTop || 0 : arrowOffsetParent.clientLeft || 0 : 0;
  1286. var offsetModifierValue = (_offsetModifierState$ = offsetModifierState == null ? void 0 : offsetModifierState[mainAxis]) != null ? _offsetModifierState$ : 0;
  1287. var tetherMin = offset + minOffset - offsetModifierValue - clientOffset;
  1288. var tetherMax = offset + maxOffset - offsetModifierValue;
  1289. var preventedOffset = within(tether ? math_min(min, tetherMin) : min, offset, tether ? math_max(max, tetherMax) : max);
  1290. popperOffsets[mainAxis] = preventedOffset;
  1291. data[mainAxis] = preventedOffset - offset;
  1292. }
  1293. if (checkAltAxis) {
  1294. var _offsetModifierState$2;
  1295. var _mainSide = mainAxis === 'x' ? enums_top : left;
  1296. var _altSide = mainAxis === 'x' ? bottom : right;
  1297. var _offset = popperOffsets[altAxis];
  1298. var _len = altAxis === 'y' ? 'height' : 'width';
  1299. var _min = _offset + overflow[_mainSide];
  1300. var _max = _offset - overflow[_altSide];
  1301. var isOriginSide = [enums_top, left].indexOf(basePlacement) !== -1;
  1302. var _offsetModifierValue = (_offsetModifierState$2 = offsetModifierState == null ? void 0 : offsetModifierState[altAxis]) != null ? _offsetModifierState$2 : 0;
  1303. var _tetherMin = isOriginSide ? _min : _offset - referenceRect[_len] - popperRect[_len] - _offsetModifierValue + normalizedTetherOffsetValue.altAxis;
  1304. var _tetherMax = isOriginSide ? _offset + referenceRect[_len] + popperRect[_len] - _offsetModifierValue - normalizedTetherOffsetValue.altAxis : _max;
  1305. var _preventedOffset = tether && isOriginSide ? withinMaxClamp(_tetherMin, _offset, _tetherMax) : within(tether ? _tetherMin : _min, _offset, tether ? _tetherMax : _max);
  1306. popperOffsets[altAxis] = _preventedOffset;
  1307. data[altAxis] = _preventedOffset - _offset;
  1308. }
  1309. state.modifiersData[name] = data;
  1310. };
  1311. const modifiers_preventOverflow = ({
  1312. name: 'preventOverflow',
  1313. enabled: true,
  1314. phase: 'main',
  1315. fn: preventOverflow,
  1316. requiresIfExists: ['offset']
  1317. });
  1318. /**
  1319. * ARROW
  1320. */
  1321. var toPaddingObject = function toPaddingObject(padding, state) {
  1322. padding = typeof padding === 'function' ? padding(Object.assign({}, state.rects, {
  1323. placement: state.placement
  1324. })) : padding;
  1325. return mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
  1326. };
  1327. function arrow(_ref) {
  1328. var _state$modifiersData$;
  1329. var state = _ref.state,
  1330. name = _ref.name,
  1331. options = _ref.options;
  1332. var arrowElement = state.elements.arrow;
  1333. var popperOffsets = state.modifiersData.popperOffsets;
  1334. var basePlacement = getBasePlacement(state.placement);
  1335. var axis = getMainAxisFromPlacement(basePlacement);
  1336. var isVertical = [left, right].indexOf(basePlacement) >= 0;
  1337. var len = isVertical ? 'height' : 'width';
  1338. if (!arrowElement || !popperOffsets) {
  1339. return;
  1340. }
  1341. var paddingObject = toPaddingObject(options.padding, state);
  1342. var arrowRect = getLayoutRect(arrowElement);
  1343. var minProp = axis === 'y' ? enums_top : left;
  1344. var maxProp = axis === 'y' ? bottom : right;
  1345. var endDiff = state.rects.reference[len] + state.rects.reference[axis] - popperOffsets[axis] - state.rects.popper[len];
  1346. var startDiff = popperOffsets[axis] - state.rects.reference[axis];
  1347. var arrowOffsetParent = getOffsetParent(arrowElement);
  1348. var clientSize = arrowOffsetParent ? axis === 'y' ? arrowOffsetParent.clientHeight || 0 : arrowOffsetParent.clientWidth || 0 : 0;
  1349. var centerToReference = endDiff / 2 - startDiff / 2; // Make sure the arrow doesn't overflow the popper if the center point is
  1350. // outside of the popper bounds
  1351. var min = paddingObject[minProp];
  1352. var max = clientSize - arrowRect[len] - paddingObject[maxProp];
  1353. var center = clientSize / 2 - arrowRect[len] / 2 + centerToReference;
  1354. var offset = within(min, center, max); // Prevents breaking syntax highlighting...
  1355. var axisProp = axis;
  1356. state.modifiersData[name] = (_state$modifiersData$ = {}, _state$modifiersData$[axisProp] = offset, _state$modifiersData$.centerOffset = offset - center, _state$modifiersData$);
  1357. };
  1358. function arrow_effect(_ref2) {
  1359. var state = _ref2.state,
  1360. options = _ref2.options;
  1361. var _options$element = options.element,
  1362. arrowElement = _options$element === void 0 ? '[data-popper-arrow]' : _options$element;
  1363. if (arrowElement == null) {
  1364. return;
  1365. } // CSS selector
  1366. if (typeof arrowElement === 'string') {
  1367. arrowElement = state.elements.popper.querySelector(arrowElement);
  1368. if (!arrowElement) {
  1369. return;
  1370. }
  1371. }
  1372. if (false) {}
  1373. if (!contains(state.elements.popper, arrowElement)) {
  1374. if (false) {}
  1375. return;
  1376. }
  1377. state.elements.arrow = arrowElement;
  1378. };
  1379. const modifiers_arrow = ({
  1380. name: 'arrow',
  1381. enabled: true,
  1382. phase: 'main',
  1383. fn: arrow,
  1384. effect: arrow_effect,
  1385. requires: ['popperOffsets'],
  1386. requiresIfExists: ['preventOverflow']
  1387. });
  1388. /**
  1389. * HIDE
  1390. */
  1391. function getSideOffsets(overflow, rect, preventedOffsets) {
  1392. if (preventedOffsets === void 0) {
  1393. preventedOffsets = {
  1394. x: 0,
  1395. y: 0
  1396. };
  1397. }
  1398. return {
  1399. top: overflow.top - rect.height - preventedOffsets.y,
  1400. right: overflow.right - rect.width + preventedOffsets.x,
  1401. bottom: overflow.bottom - rect.height + preventedOffsets.y,
  1402. left: overflow.left - rect.width - preventedOffsets.x
  1403. };
  1404. };
  1405. function isAnySideFullyClipped(overflow) {
  1406. return [enums_top, right, bottom, left].some(function (side) {
  1407. return overflow[side] >= 0;
  1408. });
  1409. };
  1410. function hide(_ref) {
  1411. var state = _ref.state,
  1412. name = _ref.name;
  1413. var referenceRect = state.rects.reference;
  1414. var popperRect = state.rects.popper;
  1415. var preventedOffsets = state.modifiersData.preventOverflow;
  1416. var referenceOverflow = detectOverflow(state, {
  1417. elementContext: 'reference'
  1418. });
  1419. var popperAltOverflow = detectOverflow(state, {
  1420. altBoundary: true
  1421. });
  1422. var referenceClippingOffsets = getSideOffsets(referenceOverflow, referenceRect);
  1423. var popperEscapeOffsets = getSideOffsets(popperAltOverflow, popperRect, preventedOffsets);
  1424. var isReferenceHidden = isAnySideFullyClipped(referenceClippingOffsets);
  1425. var hasPopperEscaped = isAnySideFullyClipped(popperEscapeOffsets);
  1426. state.modifiersData[name] = {
  1427. referenceClippingOffsets: referenceClippingOffsets,
  1428. popperEscapeOffsets: popperEscapeOffsets,
  1429. isReferenceHidden: isReferenceHidden,
  1430. hasPopperEscaped: hasPopperEscaped
  1431. };
  1432. state.attributes.popper = Object.assign({}, state.attributes.popper, {
  1433. 'data-popper-reference-hidden': isReferenceHidden,
  1434. 'data-popper-escaped': hasPopperEscaped
  1435. });
  1436. };
  1437. const modifiers_hide = ({
  1438. name: 'hide',
  1439. enabled: true,
  1440. phase: 'main',
  1441. requiresIfExists: ['preventOverflow'],
  1442. fn: hide
  1443. });
  1444. /**
  1445. *
  1446. * INIT
  1447. *
  1448. */
  1449. var defaultModifiers = [eventListeners, modifiers_popperOffsets, modifiers_computeStyles, modifiers_applyStyles, modifiers_offset, modifiers_flip, modifiers_preventOverflow, modifiers_arrow, modifiers_hide];
  1450. var popper_createPopper = popperGenerator({
  1451. defaultModifiers: defaultModifiers
  1452. });
  1453. $(document).ready(function() {
  1454. document.querySelectorAll('[data-dropdown-toggle]').forEach(function (dropdownToggleEl) {
  1455. const dropdownMenuId = dropdownToggleEl.getAttribute('data-dropdown-toggle');
  1456. const dropdownMenuEl = document.getElementById(dropdownMenuId); // options
  1457. const placement = dropdownToggleEl.getAttribute('data-dropdown-placement');
  1458. dropdownToggleEl.addEventListener('click', function (event) {
  1459. var element = event.target;
  1460. while (element.nodeName !== "A") {
  1461. element = element.parentNode;
  1462. }
  1463. popper_createPopper(element, dropdownMenuEl, {
  1464. placement: placement ? placement : 'bottom-start',
  1465. modifiers: [{
  1466. name: 'offset',
  1467. options: {
  1468. offset: [0, 10]
  1469. }
  1470. }]
  1471. }); // toggle when click on the button
  1472. dropdownMenuEl.classList.toggle('hidden');
  1473. dropdownMenuEl.classList.toggle('block');
  1474. function handleDropdownOutsideClick(event) {
  1475. var targetElement = event.target; // clicked element
  1476. if (targetElement !== dropdownMenuEl && targetElement !== dropdownToggleEl && !dropdownToggleEl.contains(targetElement)) {
  1477. dropdownMenuEl.classList.add('hidden');
  1478. dropdownMenuEl.classList.remove('block');
  1479. document.body.removeEventListener('click', handleDropdownOutsideClick, true);
  1480. }
  1481. } // hide popper when clicking outside the element
  1482. document.body.addEventListener('click', handleDropdownOutsideClick, true);
  1483. });
  1484. });
  1485. });