popper.js 66 KB

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