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.

1825 lines
62 KiB

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