popper.js 69 KB

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