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

1819 lines
58 KiB

2 months ago
  1. /**
  2. * @popperjs/core v2.11.8 - 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 && Array.isArray(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 mergeByName(modifiers) {
  364. var merged = modifiers.reduce(function (merged, current) {
  365. var existing = merged[current.name];
  366. merged[current.name] = existing ? Object.assign({}, existing, current, {
  367. options: Object.assign({}, existing.options, current.options),
  368. data: Object.assign({}, existing.data, current.data)
  369. }) : current;
  370. return merged;
  371. }, {}); // IE11 does not support Object.values
  372. return Object.keys(merged).map(function (key) {
  373. return merged[key];
  374. });
  375. }
  376. function getViewportRect(element, strategy) {
  377. var win = getWindow(element);
  378. var html = getDocumentElement(element);
  379. var visualViewport = win.visualViewport;
  380. var width = html.clientWidth;
  381. var height = html.clientHeight;
  382. var x = 0;
  383. var y = 0;
  384. if (visualViewport) {
  385. width = visualViewport.width;
  386. height = visualViewport.height;
  387. var layoutViewport = isLayoutViewport();
  388. if (layoutViewport || !layoutViewport && strategy === 'fixed') {
  389. x = visualViewport.offsetLeft;
  390. y = visualViewport.offsetTop;
  391. }
  392. }
  393. return {
  394. width: width,
  395. height: height,
  396. x: x + getWindowScrollBarX(element),
  397. y: y
  398. };
  399. }
  400. // of the `<html>` and `<body>` rect bounds if horizontally scrollable
  401. function getDocumentRect(element) {
  402. var _element$ownerDocumen;
  403. var html = getDocumentElement(element);
  404. var winScroll = getWindowScroll(element);
  405. var body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
  406. var width = max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
  407. var height = max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
  408. var x = -winScroll.scrollLeft + getWindowScrollBarX(element);
  409. var y = -winScroll.scrollTop;
  410. if (getComputedStyle(body || html).direction === 'rtl') {
  411. x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
  412. }
  413. return {
  414. width: width,
  415. height: height,
  416. x: x,
  417. y: y
  418. };
  419. }
  420. function contains(parent, child) {
  421. var rootNode = child.getRootNode && child.getRootNode(); // First, attempt with faster native method
  422. if (parent.contains(child)) {
  423. return true;
  424. } // then fallback to custom implementation with Shadow DOM support
  425. else if (rootNode && isShadowRoot(rootNode)) {
  426. var next = child;
  427. do {
  428. if (next && parent.isSameNode(next)) {
  429. return true;
  430. } // $FlowFixMe[prop-missing]: need a better way to handle this...
  431. next = next.parentNode || next.host;
  432. } while (next);
  433. } // Give up, the result is false
  434. return false;
  435. }
  436. function rectToClientRect(rect) {
  437. return Object.assign({}, rect, {
  438. left: rect.x,
  439. top: rect.y,
  440. right: rect.x + rect.width,
  441. bottom: rect.y + rect.height
  442. });
  443. }
  444. function getInnerBoundingClientRect(element, strategy) {
  445. var rect = getBoundingClientRect(element, false, strategy === 'fixed');
  446. rect.top = rect.top + element.clientTop;
  447. rect.left = rect.left + element.clientLeft;
  448. rect.bottom = rect.top + element.clientHeight;
  449. rect.right = rect.left + element.clientWidth;
  450. rect.width = element.clientWidth;
  451. rect.height = element.clientHeight;
  452. rect.x = rect.left;
  453. rect.y = rect.top;
  454. return rect;
  455. }
  456. function getClientRectFromMixedType(element, clippingParent, strategy) {
  457. return clippingParent === viewport ? rectToClientRect(getViewportRect(element, strategy)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent, strategy) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
  458. } // A "clipping parent" is an overflowable container with the characteristic of
  459. // clipping (or hiding) overflowing elements with a position different from
  460. // `initial`
  461. function getClippingParents(element) {
  462. var clippingParents = listScrollParents(getParentNode(element));
  463. var canEscapeClipping = ['absolute', 'fixed'].indexOf(getComputedStyle(element).position) >= 0;
  464. var clipperElement = canEscapeClipping && isHTMLElement(element) ? getOffsetParent(element) : element;
  465. if (!isElement(clipperElement)) {
  466. return [];
  467. } // $FlowFixMe[incompatible-return]: https://github.com/facebook/flow/issues/1414
  468. return clippingParents.filter(function (clippingParent) {
  469. return isElement(clippingParent) && contains(clippingParent, clipperElement) && getNodeName(clippingParent) !== 'body';
  470. });
  471. } // Gets the maximum area that the element is visible in due to any number of
  472. // clipping parents
  473. function getClippingRect(element, boundary, rootBoundary, strategy) {
  474. var mainClippingParents = boundary === 'clippingParents' ? getClippingParents(element) : [].concat(boundary);
  475. var clippingParents = [].concat(mainClippingParents, [rootBoundary]);
  476. var firstClippingParent = clippingParents[0];
  477. var clippingRect = clippingParents.reduce(function (accRect, clippingParent) {
  478. var rect = getClientRectFromMixedType(element, clippingParent, strategy);
  479. accRect.top = max(rect.top, accRect.top);
  480. accRect.right = min(rect.right, accRect.right);
  481. accRect.bottom = min(rect.bottom, accRect.bottom);
  482. accRect.left = max(rect.left, accRect.left);
  483. return accRect;
  484. }, getClientRectFromMixedType(element, firstClippingParent, strategy));
  485. clippingRect.width = clippingRect.right - clippingRect.left;
  486. clippingRect.height = clippingRect.bottom - clippingRect.top;
  487. clippingRect.x = clippingRect.left;
  488. clippingRect.y = clippingRect.top;
  489. return clippingRect;
  490. }
  491. function getBasePlacement(placement) {
  492. return placement.split('-')[0];
  493. }
  494. function getVariation(placement) {
  495. return placement.split('-')[1];
  496. }
  497. function getMainAxisFromPlacement(placement) {
  498. return ['top', 'bottom'].indexOf(placement) >= 0 ? 'x' : 'y';
  499. }
  500. function computeOffsets(_ref) {
  501. var reference = _ref.reference,
  502. element = _ref.element,
  503. placement = _ref.placement;
  504. var basePlacement = placement ? getBasePlacement(placement) : null;
  505. var variation = placement ? getVariation(placement) : null;
  506. var commonX = reference.x + reference.width / 2 - element.width / 2;
  507. var commonY = reference.y + reference.height / 2 - element.height / 2;
  508. var offsets;
  509. switch (basePlacement) {
  510. case top:
  511. offsets = {
  512. x: commonX,
  513. y: reference.y - element.height
  514. };
  515. break;
  516. case bottom:
  517. offsets = {
  518. x: commonX,
  519. y: reference.y + reference.height
  520. };
  521. break;
  522. case right:
  523. offsets = {
  524. x: reference.x + reference.width,
  525. y: commonY
  526. };
  527. break;
  528. case left:
  529. offsets = {
  530. x: reference.x - element.width,
  531. y: commonY
  532. };
  533. break;
  534. default:
  535. offsets = {
  536. x: reference.x,
  537. y: reference.y
  538. };
  539. }
  540. var mainAxis = basePlacement ? getMainAxisFromPlacement(basePlacement) : null;
  541. if (mainAxis != null) {
  542. var len = mainAxis === 'y' ? 'height' : 'width';
  543. switch (variation) {
  544. case start:
  545. offsets[mainAxis] = offsets[mainAxis] - (reference[len] / 2 - element[len] / 2);
  546. break;
  547. case end:
  548. offsets[mainAxis] = offsets[mainAxis] + (reference[len] / 2 - element[len] / 2);
  549. break;
  550. }
  551. }
  552. return offsets;
  553. }
  554. function getFreshSideObject() {
  555. return {
  556. top: 0,
  557. right: 0,
  558. bottom: 0,
  559. left: 0
  560. };
  561. }
  562. function mergePaddingObject(paddingObject) {
  563. return Object.assign({}, getFreshSideObject(), paddingObject);
  564. }
  565. function expandToHashMap(value, keys) {
  566. return keys.reduce(function (hashMap, key) {
  567. hashMap[key] = value;
  568. return hashMap;
  569. }, {});
  570. }
  571. function detectOverflow(state, options) {
  572. if (options === void 0) {
  573. options = {};
  574. }
  575. var _options = options,
  576. _options$placement = _options.placement,
  577. placement = _options$placement === void 0 ? state.placement : _options$placement,
  578. _options$strategy = _options.strategy,
  579. strategy = _options$strategy === void 0 ? state.strategy : _options$strategy,
  580. _options$boundary = _options.boundary,
  581. boundary = _options$boundary === void 0 ? clippingParents : _options$boundary,
  582. _options$rootBoundary = _options.rootBoundary,
  583. rootBoundary = _options$rootBoundary === void 0 ? viewport : _options$rootBoundary,
  584. _options$elementConte = _options.elementContext,
  585. elementContext = _options$elementConte === void 0 ? popper : _options$elementConte,
  586. _options$altBoundary = _options.altBoundary,
  587. altBoundary = _options$altBoundary === void 0 ? false : _options$altBoundary,
  588. _options$padding = _options.padding,
  589. padding = _options$padding === void 0 ? 0 : _options$padding;
  590. var paddingObject = mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
  591. var altContext = elementContext === popper ? reference : popper;
  592. var popperRect = state.rects.popper;
  593. var element = state.elements[altBoundary ? altContext : elementContext];
  594. var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary, strategy);
  595. var referenceClientRect = getBoundingClientRect(state.elements.reference);
  596. var popperOffsets = computeOffsets({
  597. reference: referenceClientRect,
  598. element: popperRect,
  599. strategy: 'absolute',
  600. placement: placement
  601. });
  602. var popperClientRect = rectToClientRect(Object.assign({}, popperRect, popperOffsets));
  603. var elementClientRect = elementContext === popper ? popperClientRect : referenceClientRect; // positive = overflowing the clipping rect
  604. // 0 or negative = within the clipping rect
  605. var overflowOffsets = {
  606. top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
  607. bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
  608. left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
  609. right: elementClientRect.right - clippingClientRect.right + paddingObject.right
  610. };
  611. var offsetData = state.modifiersData.offset; // Offsets can be applied only to the popper element
  612. if (elementContext === popper && offsetData) {
  613. var offset = offsetData[placement];
  614. Object.keys(overflowOffsets).forEach(function (key) {
  615. var multiply = [right, bottom].indexOf(key) >= 0 ? 1 : -1;
  616. var axis = [top, bottom].indexOf(key) >= 0 ? 'y' : 'x';
  617. overflowOffsets[key] += offset[axis] * multiply;
  618. });
  619. }
  620. return overflowOffsets;
  621. }
  622. var DEFAULT_OPTIONS = {
  623. placement: 'bottom',
  624. modifiers: [],
  625. strategy: 'absolute'
  626. };
  627. function areValidElements() {
  628. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  629. args[_key] = arguments[_key];
  630. }
  631. return !args.some(function (element) {
  632. return !(element && typeof element.getBoundingClientRect === 'function');
  633. });
  634. }
  635. function popperGenerator(generatorOptions) {
  636. if (generatorOptions === void 0) {
  637. generatorOptions = {};
  638. }
  639. var _generatorOptions = generatorOptions,
  640. _generatorOptions$def = _generatorOptions.defaultModifiers,
  641. defaultModifiers = _generatorOptions$def === void 0 ? [] : _generatorOptions$def,
  642. _generatorOptions$def2 = _generatorOptions.defaultOptions,
  643. defaultOptions = _generatorOptions$def2 === void 0 ? DEFAULT_OPTIONS : _generatorOptions$def2;
  644. return function createPopper(reference, popper, options) {
  645. if (options === void 0) {
  646. options = defaultOptions;
  647. }
  648. var state = {
  649. placement: 'bottom',
  650. orderedModifiers: [],
  651. options: Object.assign({}, DEFAULT_OPTIONS, defaultOptions),
  652. modifiersData: {},
  653. elements: {
  654. reference: reference,
  655. popper: popper
  656. },
  657. attributes: {},
  658. styles: {}
  659. };
  660. var effectCleanupFns = [];
  661. var isDestroyed = false;
  662. var instance = {
  663. state: state,
  664. setOptions: function setOptions(setOptionsAction) {
  665. var options = typeof setOptionsAction === 'function' ? setOptionsAction(state.options) : setOptionsAction;
  666. cleanupModifierEffects();
  667. state.options = Object.assign({}, defaultOptions, state.options, options);
  668. state.scrollParents = {
  669. reference: isElement(reference) ? listScrollParents(reference) : reference.contextElement ? listScrollParents(reference.contextElement) : [],
  670. popper: listScrollParents(popper)
  671. }; // Orders the modifiers based on their dependencies and `phase`
  672. // properties
  673. var orderedModifiers = orderModifiers(mergeByName([].concat(defaultModifiers, state.options.modifiers))); // Strip out disabled modifiers
  674. state.orderedModifiers = orderedModifiers.filter(function (m) {
  675. return m.enabled;
  676. });
  677. runModifierEffects();
  678. return instance.update();
  679. },
  680. // Sync update – it will always be executed, even if not necessary. This
  681. // is useful for low frequency updates where sync behavior simplifies the
  682. // logic.
  683. // For high frequency updates (e.g. `resize` and `scroll` events), always
  684. // prefer the async Popper#update method
  685. forceUpdate: function forceUpdate() {
  686. if (isDestroyed) {
  687. return;
  688. }
  689. var _state$elements = state.elements,
  690. reference = _state$elements.reference,
  691. popper = _state$elements.popper; // Don't proceed if `reference` or `popper` are not valid elements
  692. // anymore
  693. if (!areValidElements(reference, popper)) {
  694. return;
  695. } // Store the reference and popper rects to be read by modifiers
  696. state.rects = {
  697. reference: getCompositeRect(reference, getOffsetParent(popper), state.options.strategy === 'fixed'),
  698. popper: getLayoutRect(popper)
  699. }; // Modifiers have the ability to reset the current update cycle. The
  700. // most common use case for this is the `flip` modifier changing the
  701. // placement, which then needs to re-run all the modifiers, because the
  702. // logic was previously ran for the previous placement and is therefore
  703. // stale/incorrect
  704. state.reset = false;
  705. state.placement = state.options.placement; // On each update cycle, the `modifiersData` property for each modifier
  706. // is filled with the initial data specified by the modifier. This means
  707. // it doesn't persist and is fresh on each update.
  708. // To ensure persistent data, use `${name}#persistent`
  709. state.orderedModifiers.forEach(function (modifier) {
  710. return state.modifiersData[modifier.name] = Object.assign({}, modifier.data);
  711. });
  712. for (var index = 0; index < state.orderedModifiers.length; index++) {
  713. if (state.reset === true) {
  714. state.reset = false;
  715. index = -1;
  716. continue;
  717. }
  718. var _state$orderedModifie = state.orderedModifiers[index],
  719. fn = _state$orderedModifie.fn,
  720. _state$orderedModifie2 = _state$orderedModifie.options,
  721. _options = _state$orderedModifie2 === void 0 ? {} : _state$orderedModifie2,
  722. name = _state$orderedModifie.name;
  723. if (typeof fn === 'function') {
  724. state = fn({
  725. state: state,
  726. options: _options,
  727. name: name,
  728. instance: instance
  729. }) || state;
  730. }
  731. }
  732. },
  733. // Async and optimistically optimized update – it will not be executed if
  734. // not necessary (debounced to run at most once-per-tick)
  735. update: debounce(function () {
  736. return new Promise(function (resolve) {
  737. instance.forceUpdate();
  738. resolve(state);
  739. });
  740. }),
  741. destroy: function destroy() {
  742. cleanupModifierEffects();
  743. isDestroyed = true;
  744. }
  745. };
  746. if (!areValidElements(reference, popper)) {
  747. return instance;
  748. }
  749. instance.setOptions(options).then(function (state) {
  750. if (!isDestroyed && options.onFirstUpdate) {
  751. options.onFirstUpdate(state);
  752. }
  753. }); // Modifiers have the ability to execute arbitrary code before the first
  754. // update cycle runs. They will be executed in the same order as the update
  755. // cycle. This is useful when a modifier adds some persistent data that
  756. // other modifiers need to use, but the modifier is run after the dependent
  757. // one.
  758. function runModifierEffects() {
  759. state.orderedModifiers.forEach(function (_ref) {
  760. var name = _ref.name,
  761. _ref$options = _ref.options,
  762. options = _ref$options === void 0 ? {} : _ref$options,
  763. effect = _ref.effect;
  764. if (typeof effect === 'function') {
  765. var cleanupFn = effect({
  766. state: state,
  767. name: name,
  768. instance: instance,
  769. options: options
  770. });
  771. var noopFn = function noopFn() {};
  772. effectCleanupFns.push(cleanupFn || noopFn);
  773. }
  774. });
  775. }
  776. function cleanupModifierEffects() {
  777. effectCleanupFns.forEach(function (fn) {
  778. return fn();
  779. });
  780. effectCleanupFns = [];
  781. }
  782. return instance;
  783. };
  784. }
  785. var passive = {
  786. passive: true
  787. };
  788. function effect$2(_ref) {
  789. var state = _ref.state,
  790. instance = _ref.instance,
  791. options = _ref.options;
  792. var _options$scroll = options.scroll,
  793. scroll = _options$scroll === void 0 ? true : _options$scroll,
  794. _options$resize = options.resize,
  795. resize = _options$resize === void 0 ? true : _options$resize;
  796. var window = getWindow(state.elements.popper);
  797. var scrollParents = [].concat(state.scrollParents.reference, state.scrollParents.popper);
  798. if (scroll) {
  799. scrollParents.forEach(function (scrollParent) {
  800. scrollParent.addEventListener('scroll', instance.update, passive);
  801. });
  802. }
  803. if (resize) {
  804. window.addEventListener('resize', instance.update, passive);
  805. }
  806. return function () {
  807. if (scroll) {
  808. scrollParents.forEach(function (scrollParent) {
  809. scrollParent.removeEventListener('scroll', instance.update, passive);
  810. });
  811. }
  812. if (resize) {
  813. window.removeEventListener('resize', instance.update, passive);
  814. }
  815. };
  816. } // eslint-disable-next-line import/no-unused-modules
  817. var eventListeners = {
  818. name: 'eventListeners',
  819. enabled: true,
  820. phase: 'write',
  821. fn: function fn() {},
  822. effect: effect$2,
  823. data: {}
  824. };
  825. function popperOffsets(_ref) {
  826. var state = _ref.state,
  827. name = _ref.name;
  828. // Offsets are the actual position the popper needs to have to be
  829. // properly positioned near its reference element
  830. // This is the most basic placement, and will be adjusted by
  831. // the modifiers in the next step
  832. state.modifiersData[name] = computeOffsets({
  833. reference: state.rects.reference,
  834. element: state.rects.popper,
  835. strategy: 'absolute',
  836. placement: state.placement
  837. });
  838. } // eslint-disable-next-line import/no-unused-modules
  839. var popperOffsets$1 = {
  840. name: 'popperOffsets',
  841. enabled: true,
  842. phase: 'read',
  843. fn: popperOffsets,
  844. data: {}
  845. };
  846. var unsetSides = {
  847. top: 'auto',
  848. right: 'auto',
  849. bottom: 'auto',
  850. left: 'auto'
  851. }; // Round the offsets to the nearest suitable subpixel based on the DPR.
  852. // Zooming can change the DPR, but it seems to report a value that will
  853. // cleanly divide the values into the appropriate subpixels.
  854. function roundOffsetsByDPR(_ref, win) {
  855. var x = _ref.x,
  856. y = _ref.y;
  857. var dpr = win.devicePixelRatio || 1;
  858. return {
  859. x: round(x * dpr) / dpr || 0,
  860. y: round(y * dpr) / dpr || 0
  861. };
  862. }
  863. function mapToStyles(_ref2) {
  864. var _Object$assign2;
  865. var popper = _ref2.popper,
  866. popperRect = _ref2.popperRect,
  867. placement = _ref2.placement,
  868. variation = _ref2.variation,
  869. offsets = _ref2.offsets,
  870. position = _ref2.position,
  871. gpuAcceleration = _ref2.gpuAcceleration,
  872. adaptive = _ref2.adaptive,
  873. roundOffsets = _ref2.roundOffsets,
  874. isFixed = _ref2.isFixed;
  875. var _offsets$x = offsets.x,
  876. x = _offsets$x === void 0 ? 0 : _offsets$x,
  877. _offsets$y = offsets.y,
  878. y = _offsets$y === void 0 ? 0 : _offsets$y;
  879. var _ref3 = typeof roundOffsets === 'function' ? roundOffsets({
  880. x: x,
  881. y: y
  882. }) : {
  883. x: x,
  884. y: y
  885. };
  886. x = _ref3.x;
  887. y = _ref3.y;
  888. var hasX = offsets.hasOwnProperty('x');
  889. var hasY = offsets.hasOwnProperty('y');
  890. var sideX = left;
  891. var sideY = top;
  892. var win = window;
  893. if (adaptive) {
  894. var offsetParent = getOffsetParent(popper);
  895. var heightProp = 'clientHeight';
  896. var widthProp = 'clientWidth';
  897. if (offsetParent === getWindow(popper)) {
  898. offsetParent = getDocumentElement(popper);
  899. if (getComputedStyle(offsetParent).position !== 'static' && position === 'absolute') {
  900. heightProp = 'scrollHeight';
  901. widthProp = 'scrollWidth';
  902. }
  903. } // $FlowFixMe[incompatible-cast]: force type refinement, we compare offsetParent with window above, but Flow doesn't detect it
  904. offsetParent = offsetParent;
  905. if (placement === top || (placement === left || placement === right) && variation === end) {
  906. sideY = bottom;
  907. var offsetY = isFixed && offsetParent === win && win.visualViewport ? win.visualViewport.height : // $FlowFixMe[prop-missing]
  908. offsetParent[heightProp];
  909. y -= offsetY - popperRect.height;
  910. y *= gpuAcceleration ? 1 : -1;
  911. }
  912. if (placement === left || (placement === top || placement === bottom) && variation === end) {
  913. sideX = right;
  914. var offsetX = isFixed && offsetParent === win && win.visualViewport ? win.visualViewport.width : // $FlowFixMe[prop-missing]
  915. offsetParent[widthProp];
  916. x -= offsetX - popperRect.width;
  917. x *= gpuAcceleration ? 1 : -1;
  918. }
  919. }
  920. var commonStyles = Object.assign({
  921. position: position
  922. }, adaptive && unsetSides);
  923. var _ref4 = roundOffsets === true ? roundOffsetsByDPR({
  924. x: x,
  925. y: y
  926. }, getWindow(popper)) : {
  927. x: x,
  928. y: y
  929. };
  930. x = _ref4.x;
  931. y = _ref4.y;
  932. if (gpuAcceleration) {
  933. var _Object$assign;
  934. 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));
  935. }
  936. return Object.assign({}, commonStyles, (_Object$assign2 = {}, _Object$assign2[sideY] = hasY ? y + "px" : '', _Object$assign2[sideX] = hasX ? x + "px" : '', _Object$assign2.transform = '', _Object$assign2));
  937. }
  938. function computeStyles(_ref5) {
  939. var state = _ref5.state,
  940. options = _ref5.options;
  941. var _options$gpuAccelerat = options.gpuAcceleration,
  942. gpuAcceleration = _options$gpuAccelerat === void 0 ? true : _options$gpuAccelerat,
  943. _options$adaptive = options.adaptive,
  944. adaptive = _options$adaptive === void 0 ? true : _options$adaptive,
  945. _options$roundOffsets = options.roundOffsets,
  946. roundOffsets = _options$roundOffsets === void 0 ? true : _options$roundOffsets;
  947. var commonStyles = {
  948. placement: getBasePlacement(state.placement),
  949. variation: getVariation(state.placement),
  950. popper: state.elements.popper,
  951. popperRect: state.rects.popper,
  952. gpuAcceleration: gpuAcceleration,
  953. isFixed: state.options.strategy === 'fixed'
  954. };
  955. if (state.modifiersData.popperOffsets != null) {
  956. state.styles.popper = Object.assign({}, state.styles.popper, mapToStyles(Object.assign({}, commonStyles, {
  957. offsets: state.modifiersData.popperOffsets,
  958. position: state.options.strategy,
  959. adaptive: adaptive,
  960. roundOffsets: roundOffsets
  961. })));
  962. }
  963. if (state.modifiersData.arrow != null) {
  964. state.styles.arrow = Object.assign({}, state.styles.arrow, mapToStyles(Object.assign({}, commonStyles, {
  965. offsets: state.modifiersData.arrow,
  966. position: 'absolute',
  967. adaptive: false,
  968. roundOffsets: roundOffsets
  969. })));
  970. }
  971. state.attributes.popper = Object.assign({}, state.attributes.popper, {
  972. 'data-popper-placement': state.placement
  973. });
  974. } // eslint-disable-next-line import/no-unused-modules
  975. var computeStyles$1 = {
  976. name: 'computeStyles',
  977. enabled: true,
  978. phase: 'beforeWrite',
  979. fn: computeStyles,
  980. data: {}
  981. };
  982. // and applies them to the HTMLElements such as popper and arrow
  983. function applyStyles(_ref) {
  984. var state = _ref.state;
  985. Object.keys(state.elements).forEach(function (name) {
  986. var style = state.styles[name] || {};
  987. var attributes = state.attributes[name] || {};
  988. var element = state.elements[name]; // arrow is optional + virtual elements
  989. if (!isHTMLElement(element) || !getNodeName(element)) {
  990. return;
  991. } // Flow doesn't support to extend this property, but it's the most
  992. // effective way to apply styles to an HTMLElement
  993. // $FlowFixMe[cannot-write]
  994. Object.assign(element.style, style);
  995. Object.keys(attributes).forEach(function (name) {
  996. var value = attributes[name];
  997. if (value === false) {
  998. element.removeAttribute(name);
  999. } else {
  1000. element.setAttribute(name, value === true ? '' : value);
  1001. }
  1002. });
  1003. });
  1004. }
  1005. function effect$1(_ref2) {
  1006. var state = _ref2.state;
  1007. var initialStyles = {
  1008. popper: {
  1009. position: state.options.strategy,
  1010. left: '0',
  1011. top: '0',
  1012. margin: '0'
  1013. },
  1014. arrow: {
  1015. position: 'absolute'
  1016. },
  1017. reference: {}
  1018. };
  1019. Object.assign(state.elements.popper.style, initialStyles.popper);
  1020. state.styles = initialStyles;
  1021. if (state.elements.arrow) {
  1022. Object.assign(state.elements.arrow.style, initialStyles.arrow);
  1023. }
  1024. return function () {
  1025. Object.keys(state.elements).forEach(function (name) {
  1026. var element = state.elements[name];
  1027. var attributes = state.attributes[name] || {};
  1028. var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? state.styles[name] : initialStyles[name]); // Set all values to an empty string to unset them
  1029. var style = styleProperties.reduce(function (style, property) {
  1030. style[property] = '';
  1031. return style;
  1032. }, {}); // arrow is optional + virtual elements
  1033. if (!isHTMLElement(element) || !getNodeName(element)) {
  1034. return;
  1035. }
  1036. Object.assign(element.style, style);
  1037. Object.keys(attributes).forEach(function (attribute) {
  1038. element.removeAttribute(attribute);
  1039. });
  1040. });
  1041. };
  1042. } // eslint-disable-next-line import/no-unused-modules
  1043. var applyStyles$1 = {
  1044. name: 'applyStyles',
  1045. enabled: true,
  1046. phase: 'write',
  1047. fn: applyStyles,
  1048. effect: effect$1,
  1049. requires: ['computeStyles']
  1050. };
  1051. function distanceAndSkiddingToXY(placement, rects, offset) {
  1052. var basePlacement = getBasePlacement(placement);
  1053. var invertDistance = [left, top].indexOf(basePlacement) >= 0 ? -1 : 1;
  1054. var _ref = typeof offset === 'function' ? offset(Object.assign({}, rects, {
  1055. placement: placement
  1056. })) : offset,
  1057. skidding = _ref[0],
  1058. distance = _ref[1];
  1059. skidding = skidding || 0;
  1060. distance = (distance || 0) * invertDistance;
  1061. return [left, right].indexOf(basePlacement) >= 0 ? {
  1062. x: distance,
  1063. y: skidding
  1064. } : {
  1065. x: skidding,
  1066. y: distance
  1067. };
  1068. }
  1069. function offset(_ref2) {
  1070. var state = _ref2.state,
  1071. options = _ref2.options,
  1072. name = _ref2.name;
  1073. var _options$offset = options.offset,
  1074. offset = _options$offset === void 0 ? [0, 0] : _options$offset;
  1075. var data = placements.reduce(function (acc, placement) {
  1076. acc[placement] = distanceAndSkiddingToXY(placement, state.rects, offset);
  1077. return acc;
  1078. }, {});
  1079. var _data$state$placement = data[state.placement],
  1080. x = _data$state$placement.x,
  1081. y = _data$state$placement.y;
  1082. if (state.modifiersData.popperOffsets != null) {
  1083. state.modifiersData.popperOffsets.x += x;
  1084. state.modifiersData.popperOffsets.y += y;
  1085. }
  1086. state.modifiersData[name] = data;
  1087. } // eslint-disable-next-line import/no-unused-modules
  1088. var offset$1 = {
  1089. name: 'offset',
  1090. enabled: true,
  1091. phase: 'main',
  1092. requires: ['popperOffsets'],
  1093. fn: offset
  1094. };
  1095. var hash$1 = {
  1096. left: 'right',
  1097. right: 'left',
  1098. bottom: 'top',
  1099. top: 'bottom'
  1100. };
  1101. function getOppositePlacement(placement) {
  1102. return placement.replace(/left|right|bottom|top/g, function (matched) {
  1103. return hash$1[matched];
  1104. });
  1105. }
  1106. var hash = {
  1107. start: 'end',
  1108. end: 'start'
  1109. };
  1110. function getOppositeVariationPlacement(placement) {
  1111. return placement.replace(/start|end/g, function (matched) {
  1112. return hash[matched];
  1113. });
  1114. }
  1115. function computeAutoPlacement(state, options) {
  1116. if (options === void 0) {
  1117. options = {};
  1118. }
  1119. var _options = options,
  1120. placement = _options.placement,
  1121. boundary = _options.boundary,
  1122. rootBoundary = _options.rootBoundary,
  1123. padding = _options.padding,
  1124. flipVariations = _options.flipVariations,
  1125. _options$allowedAutoP = _options.allowedAutoPlacements,
  1126. allowedAutoPlacements = _options$allowedAutoP === void 0 ? placements : _options$allowedAutoP;
  1127. var variation = getVariation(placement);
  1128. var placements$1 = variation ? flipVariations ? variationPlacements : variationPlacements.filter(function (placement) {
  1129. return getVariation(placement) === variation;
  1130. }) : basePlacements;
  1131. var allowedPlacements = placements$1.filter(function (placement) {
  1132. return allowedAutoPlacements.indexOf(placement) >= 0;
  1133. });
  1134. if (allowedPlacements.length === 0) {
  1135. allowedPlacements = placements$1;
  1136. } // $FlowFixMe[incompatible-type]: Flow seems to have problems with two array unions...
  1137. var overflows = allowedPlacements.reduce(function (acc, placement) {
  1138. acc[placement] = detectOverflow(state, {
  1139. placement: placement,
  1140. boundary: boundary,
  1141. rootBoundary: rootBoundary,
  1142. padding: padding
  1143. })[getBasePlacement(placement)];
  1144. return acc;
  1145. }, {});
  1146. return Object.keys(overflows).sort(function (a, b) {
  1147. return overflows[a] - overflows[b];
  1148. });
  1149. }
  1150. function getExpandedFallbackPlacements(placement) {
  1151. if (getBasePlacement(placement) === auto) {
  1152. return [];
  1153. }
  1154. var oppositePlacement = getOppositePlacement(placement);
  1155. return [getOppositeVariationPlacement(placement), oppositePlacement, getOppositeVariationPlacement(oppositePlacement)];
  1156. }
  1157. function flip(_ref) {
  1158. var state = _ref.state,
  1159. options = _ref.options,
  1160. name = _ref.name;
  1161. if (state.modifiersData[name]._skip) {
  1162. return;
  1163. }
  1164. var _options$mainAxis = options.mainAxis,
  1165. checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis,
  1166. _options$altAxis = options.altAxis,
  1167. checkAltAxis = _options$altAxis === void 0 ? true : _options$altAxis,
  1168. specifiedFallbackPlacements = options.fallbackPlacements,
  1169. padding = options.padding,
  1170. boundary = options.boundary,
  1171. rootBoundary = options.rootBoundary,
  1172. altBoundary = options.altBoundary,
  1173. _options$flipVariatio = options.flipVariations,
  1174. flipVariations = _options$flipVariatio === void 0 ? true : _options$flipVariatio,
  1175. allowedAutoPlacements = options.allowedAutoPlacements;
  1176. var preferredPlacement = state.options.placement;
  1177. var basePlacement = getBasePlacement(preferredPlacement);
  1178. var isBasePlacement = basePlacement === preferredPlacement;
  1179. var fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipVariations ? [getOppositePlacement(preferredPlacement)] : getExpandedFallbackPlacements(preferredPlacement));
  1180. var placements = [preferredPlacement].concat(fallbackPlacements).reduce(function (acc, placement) {
  1181. return acc.concat(getBasePlacement(placement) === auto ? computeAutoPlacement(state, {
  1182. placement: placement,
  1183. boundary: boundary,
  1184. rootBoundary: rootBoundary,
  1185. padding: padding,
  1186. flipVariations: flipVariations,
  1187. allowedAutoPlacements: allowedAutoPlacements
  1188. }) : placement);
  1189. }, []);
  1190. var referenceRect = state.rects.reference;
  1191. var popperRect = state.rects.popper;
  1192. var checksMap = new Map();
  1193. var makeFallbackChecks = true;
  1194. var firstFittingPlacement = placements[0];
  1195. for (var i = 0; i < placements.length; i++) {
  1196. var placement = placements[i];
  1197. var _basePlacement = getBasePlacement(placement);
  1198. var isStartVariation = getVariation(placement) === start;
  1199. var isVertical = [top, bottom].indexOf(_basePlacement) >= 0;
  1200. var len = isVertical ? 'width' : 'height';
  1201. var overflow = detectOverflow(state, {
  1202. placement: placement,
  1203. boundary: boundary,
  1204. rootBoundary: rootBoundary,
  1205. altBoundary: altBoundary,
  1206. padding: padding
  1207. });
  1208. var mainVariationSide = isVertical ? isStartVariation ? right : left : isStartVariation ? bottom : top;
  1209. if (referenceRect[len] > popperRect[len]) {
  1210. mainVariationSide = getOppositePlacement(mainVariationSide);
  1211. }
  1212. var altVariationSide = getOppositePlacement(mainVariationSide);
  1213. var checks = [];
  1214. if (checkMainAxis) {
  1215. checks.push(overflow[_basePlacement] <= 0);
  1216. }
  1217. if (checkAltAxis) {
  1218. checks.push(overflow[mainVariationSide] <= 0, overflow[altVariationSide] <= 0);
  1219. }
  1220. if (checks.every(function (check) {
  1221. return check;
  1222. })) {
  1223. firstFittingPlacement = placement;
  1224. makeFallbackChecks = false;
  1225. break;
  1226. }
  1227. checksMap.set(placement, checks);
  1228. }
  1229. if (makeFallbackChecks) {
  1230. // `2` may be desired in some cases – research later
  1231. var numberOfChecks = flipVariations ? 3 : 1;
  1232. var _loop = function _loop(_i) {
  1233. var fittingPlacement = placements.find(function (placement) {
  1234. var checks = checksMap.get(placement);
  1235. if (checks) {
  1236. return checks.slice(0, _i).every(function (check) {
  1237. return check;
  1238. });
  1239. }
  1240. });
  1241. if (fittingPlacement) {
  1242. firstFittingPlacement = fittingPlacement;
  1243. return "break";
  1244. }
  1245. };
  1246. for (var _i = numberOfChecks; _i > 0; _i--) {
  1247. var _ret = _loop(_i);
  1248. if (_ret === "break") break;
  1249. }
  1250. }
  1251. if (state.placement !== firstFittingPlacement) {
  1252. state.modifiersData[name]._skip = true;
  1253. state.placement = firstFittingPlacement;
  1254. state.reset = true;
  1255. }
  1256. } // eslint-disable-next-line import/no-unused-modules
  1257. var flip$1 = {
  1258. name: 'flip',
  1259. enabled: true,
  1260. phase: 'main',
  1261. fn: flip,
  1262. requiresIfExists: ['offset'],
  1263. data: {
  1264. _skip: false
  1265. }
  1266. };
  1267. function getAltAxis(axis) {
  1268. return axis === 'x' ? 'y' : 'x';
  1269. }
  1270. function within(min$1, value, max$1) {
  1271. return max(min$1, min(value, max$1));
  1272. }
  1273. function withinMaxClamp(min, value, max) {
  1274. var v = within(min, value, max);
  1275. return v > max ? max : v;
  1276. }
  1277. function preventOverflow(_ref) {
  1278. var state = _ref.state,
  1279. options = _ref.options,
  1280. name = _ref.name;
  1281. var _options$mainAxis = options.mainAxis,
  1282. checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis,
  1283. _options$altAxis = options.altAxis,
  1284. checkAltAxis = _options$altAxis === void 0 ? false : _options$altAxis,
  1285. boundary = options.boundary,
  1286. rootBoundary = options.rootBoundary,
  1287. altBoundary = options.altBoundary,
  1288. padding = options.padding,
  1289. _options$tether = options.tether,
  1290. tether = _options$tether === void 0 ? true : _options$tether,
  1291. _options$tetherOffset = options.tetherOffset,
  1292. tetherOffset = _options$tetherOffset === void 0 ? 0 : _options$tetherOffset;
  1293. var overflow = detectOverflow(state, {
  1294. boundary: boundary,
  1295. rootBoundary: rootBoundary,
  1296. padding: padding,
  1297. altBoundary: altBoundary
  1298. });
  1299. var basePlacement = getBasePlacement(state.placement);
  1300. var variation = getVariation(state.placement);
  1301. var isBasePlacement = !variation;
  1302. var mainAxis = getMainAxisFromPlacement(basePlacement);
  1303. var altAxis = getAltAxis(mainAxis);
  1304. var popperOffsets = state.modifiersData.popperOffsets;
  1305. var referenceRect = state.rects.reference;
  1306. var popperRect = state.rects.popper;
  1307. var tetherOffsetValue = typeof tetherOffset === 'function' ? tetherOffset(Object.assign({}, state.rects, {
  1308. placement: state.placement
  1309. })) : tetherOffset;
  1310. var normalizedTetherOffsetValue = typeof tetherOffsetValue === 'number' ? {
  1311. mainAxis: tetherOffsetValue,
  1312. altAxis: tetherOffsetValue
  1313. } : Object.assign({
  1314. mainAxis: 0,
  1315. altAxis: 0
  1316. }, tetherOffsetValue);
  1317. var offsetModifierState = state.modifiersData.offset ? state.modifiersData.offset[state.placement] : null;
  1318. var data = {
  1319. x: 0,
  1320. y: 0
  1321. };
  1322. if (!popperOffsets) {
  1323. return;
  1324. }
  1325. if (checkMainAxis) {
  1326. var _offsetModifierState$;
  1327. var mainSide = mainAxis === 'y' ? top : left;
  1328. var altSide = mainAxis === 'y' ? bottom : right;
  1329. var len = mainAxis === 'y' ? 'height' : 'width';
  1330. var offset = popperOffsets[mainAxis];
  1331. var min$1 = offset + overflow[mainSide];
  1332. var max$1 = offset - overflow[altSide];
  1333. var additive = tether ? -popperRect[len] / 2 : 0;
  1334. var minLen = variation === start ? referenceRect[len] : popperRect[len];
  1335. var maxLen = variation === start ? -popperRect[len] : -referenceRect[len]; // We need to include the arrow in the calculation so the arrow doesn't go
  1336. // outside the reference bounds
  1337. var arrowElement = state.elements.arrow;
  1338. var arrowRect = tether && arrowElement ? getLayoutRect(arrowElement) : {
  1339. width: 0,
  1340. height: 0
  1341. };
  1342. var arrowPaddingObject = state.modifiersData['arrow#persistent'] ? state.modifiersData['arrow#persistent'].padding : getFreshSideObject();
  1343. var arrowPaddingMin = arrowPaddingObject[mainSide];
  1344. var arrowPaddingMax = arrowPaddingObject[altSide]; // If the reference length is smaller than the arrow length, we don't want
  1345. // to include its full size in the calculation. If the reference is small
  1346. // and near the edge of a boundary, the popper can overflow even if the
  1347. // reference is not overflowing as well (e.g. virtual elements with no
  1348. // width or height)
  1349. var arrowLen = within(0, referenceRect[len], arrowRect[len]);
  1350. var minOffset = isBasePlacement ? referenceRect[len] / 2 - additive - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis : minLen - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis;
  1351. var maxOffset = isBasePlacement ? -referenceRect[len] / 2 + additive + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis : maxLen + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis;
  1352. var arrowOffsetParent = state.elements.arrow && getOffsetParent(state.elements.arrow);
  1353. var clientOffset = arrowOffsetParent ? mainAxis === 'y' ? arrowOffsetParent.clientTop || 0 : arrowOffsetParent.clientLeft || 0 : 0;
  1354. var offsetModifierValue = (_offsetModifierState$ = offsetModifierState == null ? void 0 : offsetModifierState[mainAxis]) != null ? _offsetModifierState$ : 0;
  1355. var tetherMin = offset + minOffset - offsetModifierValue - clientOffset;
  1356. var tetherMax = offset + maxOffset - offsetModifierValue;
  1357. var preventedOffset = within(tether ? min(min$1, tetherMin) : min$1, offset, tether ? max(max$1, tetherMax) : max$1);
  1358. popperOffsets[mainAxis] = preventedOffset;
  1359. data[mainAxis] = preventedOffset - offset;
  1360. }
  1361. if (checkAltAxis) {
  1362. var _offsetModifierState$2;
  1363. var _mainSide = mainAxis === 'x' ? top : left;
  1364. var _altSide = mainAxis === 'x' ? bottom : right;
  1365. var _offset = popperOffsets[altAxis];
  1366. var _len = altAxis === 'y' ? 'height' : 'width';
  1367. var _min = _offset + overflow[_mainSide];
  1368. var _max = _offset - overflow[_altSide];
  1369. var isOriginSide = [top, left].indexOf(basePlacement) !== -1;
  1370. var _offsetModifierValue = (_offsetModifierState$2 = offsetModifierState == null ? void 0 : offsetModifierState[altAxis]) != null ? _offsetModifierState$2 : 0;
  1371. var _tetherMin = isOriginSide ? _min : _offset - referenceRect[_len] - popperRect[_len] - _offsetModifierValue + normalizedTetherOffsetValue.altAxis;
  1372. var _tetherMax = isOriginSide ? _offset + referenceRect[_len] + popperRect[_len] - _offsetModifierValue - normalizedTetherOffsetValue.altAxis : _max;
  1373. var _preventedOffset = tether && isOriginSide ? withinMaxClamp(_tetherMin, _offset, _tetherMax) : within(tether ? _tetherMin : _min, _offset, tether ? _tetherMax : _max);
  1374. popperOffsets[altAxis] = _preventedOffset;
  1375. data[altAxis] = _preventedOffset - _offset;
  1376. }
  1377. state.modifiersData[name] = data;
  1378. } // eslint-disable-next-line import/no-unused-modules
  1379. var preventOverflow$1 = {
  1380. name: 'preventOverflow',
  1381. enabled: true,
  1382. phase: 'main',
  1383. fn: preventOverflow,
  1384. requiresIfExists: ['offset']
  1385. };
  1386. var toPaddingObject = function toPaddingObject(padding, state) {
  1387. padding = typeof padding === 'function' ? padding(Object.assign({}, state.rects, {
  1388. placement: state.placement
  1389. })) : padding;
  1390. return mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
  1391. };
  1392. function arrow(_ref) {
  1393. var _state$modifiersData$;
  1394. var state = _ref.state,
  1395. name = _ref.name,
  1396. options = _ref.options;
  1397. var arrowElement = state.elements.arrow;
  1398. var popperOffsets = state.modifiersData.popperOffsets;
  1399. var basePlacement = getBasePlacement(state.placement);
  1400. var axis = getMainAxisFromPlacement(basePlacement);
  1401. var isVertical = [left, right].indexOf(basePlacement) >= 0;
  1402. var len = isVertical ? 'height' : 'width';
  1403. if (!arrowElement || !popperOffsets) {
  1404. return;
  1405. }
  1406. var paddingObject = toPaddingObject(options.padding, state);
  1407. var arrowRect = getLayoutRect(arrowElement);
  1408. var minProp = axis === 'y' ? top : left;
  1409. var maxProp = axis === 'y' ? bottom : right;
  1410. var endDiff = state.rects.reference[len] + state.rects.reference[axis] - popperOffsets[axis] - state.rects.popper[len];
  1411. var startDiff = popperOffsets[axis] - state.rects.reference[axis];
  1412. var arrowOffsetParent = getOffsetParent(arrowElement);
  1413. var clientSize = arrowOffsetParent ? axis === 'y' ? arrowOffsetParent.clientHeight || 0 : arrowOffsetParent.clientWidth || 0 : 0;
  1414. var centerToReference = endDiff / 2 - startDiff / 2; // Make sure the arrow doesn't overflow the popper if the center point is
  1415. // outside of the popper bounds
  1416. var min = paddingObject[minProp];
  1417. var max = clientSize - arrowRect[len] - paddingObject[maxProp];
  1418. var center = clientSize / 2 - arrowRect[len] / 2 + centerToReference;
  1419. var offset = within(min, center, max); // Prevents breaking syntax highlighting...
  1420. var axisProp = axis;
  1421. state.modifiersData[name] = (_state$modifiersData$ = {}, _state$modifiersData$[axisProp] = offset, _state$modifiersData$.centerOffset = offset - center, _state$modifiersData$);
  1422. }
  1423. function effect(_ref2) {
  1424. var state = _ref2.state,
  1425. options = _ref2.options;
  1426. var _options$element = options.element,
  1427. arrowElement = _options$element === void 0 ? '[data-popper-arrow]' : _options$element;
  1428. if (arrowElement == null) {
  1429. return;
  1430. } // CSS selector
  1431. if (typeof arrowElement === 'string') {
  1432. arrowElement = state.elements.popper.querySelector(arrowElement);
  1433. if (!arrowElement) {
  1434. return;
  1435. }
  1436. }
  1437. if (!contains(state.elements.popper, arrowElement)) {
  1438. return;
  1439. }
  1440. state.elements.arrow = arrowElement;
  1441. } // eslint-disable-next-line import/no-unused-modules
  1442. var arrow$1 = {
  1443. name: 'arrow',
  1444. enabled: true,
  1445. phase: 'main',
  1446. fn: arrow,
  1447. effect: effect,
  1448. requires: ['popperOffsets'],
  1449. requiresIfExists: ['preventOverflow']
  1450. };
  1451. function getSideOffsets(overflow, rect, preventedOffsets) {
  1452. if (preventedOffsets === void 0) {
  1453. preventedOffsets = {
  1454. x: 0,
  1455. y: 0
  1456. };
  1457. }
  1458. return {
  1459. top: overflow.top - rect.height - preventedOffsets.y,
  1460. right: overflow.right - rect.width + preventedOffsets.x,
  1461. bottom: overflow.bottom - rect.height + preventedOffsets.y,
  1462. left: overflow.left - rect.width - preventedOffsets.x
  1463. };
  1464. }
  1465. function isAnySideFullyClipped(overflow) {
  1466. return [top, right, bottom, left].some(function (side) {
  1467. return overflow[side] >= 0;
  1468. });
  1469. }
  1470. function hide(_ref) {
  1471. var state = _ref.state,
  1472. name = _ref.name;
  1473. var referenceRect = state.rects.reference;
  1474. var popperRect = state.rects.popper;
  1475. var preventedOffsets = state.modifiersData.preventOverflow;
  1476. var referenceOverflow = detectOverflow(state, {
  1477. elementContext: 'reference'
  1478. });
  1479. var popperAltOverflow = detectOverflow(state, {
  1480. altBoundary: true
  1481. });
  1482. var referenceClippingOffsets = getSideOffsets(referenceOverflow, referenceRect);
  1483. var popperEscapeOffsets = getSideOffsets(popperAltOverflow, popperRect, preventedOffsets);
  1484. var isReferenceHidden = isAnySideFullyClipped(referenceClippingOffsets);
  1485. var hasPopperEscaped = isAnySideFullyClipped(popperEscapeOffsets);
  1486. state.modifiersData[name] = {
  1487. referenceClippingOffsets: referenceClippingOffsets,
  1488. popperEscapeOffsets: popperEscapeOffsets,
  1489. isReferenceHidden: isReferenceHidden,
  1490. hasPopperEscaped: hasPopperEscaped
  1491. };
  1492. state.attributes.popper = Object.assign({}, state.attributes.popper, {
  1493. 'data-popper-reference-hidden': isReferenceHidden,
  1494. 'data-popper-escaped': hasPopperEscaped
  1495. });
  1496. } // eslint-disable-next-line import/no-unused-modules
  1497. var hide$1 = {
  1498. name: 'hide',
  1499. enabled: true,
  1500. phase: 'main',
  1501. requiresIfExists: ['preventOverflow'],
  1502. fn: hide
  1503. };
  1504. var defaultModifiers$1 = [eventListeners, popperOffsets$1, computeStyles$1, applyStyles$1];
  1505. var createPopper$1 = /*#__PURE__*/popperGenerator({
  1506. defaultModifiers: defaultModifiers$1
  1507. }); // eslint-disable-next-line import/no-unused-modules
  1508. var defaultModifiers = [eventListeners, popperOffsets$1, computeStyles$1, applyStyles$1, offset$1, flip$1, preventOverflow$1, arrow$1, hide$1];
  1509. var createPopper = /*#__PURE__*/popperGenerator({
  1510. defaultModifiers: defaultModifiers
  1511. }); // eslint-disable-next-line import/no-unused-modules
  1512. exports.applyStyles = applyStyles$1;
  1513. exports.arrow = arrow$1;
  1514. exports.computeStyles = computeStyles$1;
  1515. exports.createPopper = createPopper;
  1516. exports.createPopperLite = createPopper$1;
  1517. exports.defaultModifiers = defaultModifiers;
  1518. exports.detectOverflow = detectOverflow;
  1519. exports.eventListeners = eventListeners;
  1520. exports.flip = flip$1;
  1521. exports.hide = hide$1;
  1522. exports.offset = offset$1;
  1523. exports.popperGenerator = popperGenerator;
  1524. exports.popperOffsets = popperOffsets$1;
  1525. exports.preventOverflow = preventOverflow$1;
  1526. //# sourceMappingURL=popper.js.map