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.

1086 lines
36 KiB

  1. /**
  2. * @popperjs/core v2.11.5 - 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 getBoundingClientRect(element, includeScale) {
  36. if (includeScale === void 0) {
  37. includeScale = false;
  38. }
  39. var rect = element.getBoundingClientRect();
  40. var scaleX = 1;
  41. var scaleY = 1;
  42. if (isHTMLElement(element) && includeScale) {
  43. var offsetHeight = element.offsetHeight;
  44. var offsetWidth = element.offsetWidth; // Do not attempt to divide by 0, otherwise we get `Infinity` as scale
  45. // Fallback to 1 in case both values are `0`
  46. if (offsetWidth > 0) {
  47. scaleX = round(rect.width) / offsetWidth || 1;
  48. }
  49. if (offsetHeight > 0) {
  50. scaleY = round(rect.height) / offsetHeight || 1;
  51. }
  52. }
  53. return {
  54. width: rect.width / scaleX,
  55. height: rect.height / scaleY,
  56. top: rect.top / scaleY,
  57. right: rect.right / scaleX,
  58. bottom: rect.bottom / scaleY,
  59. left: rect.left / scaleX,
  60. x: rect.left / scaleX,
  61. y: rect.top / scaleY
  62. };
  63. }
  64. function getWindowScroll(node) {
  65. var win = getWindow(node);
  66. var scrollLeft = win.pageXOffset;
  67. var scrollTop = win.pageYOffset;
  68. return {
  69. scrollLeft: scrollLeft,
  70. scrollTop: scrollTop
  71. };
  72. }
  73. function getHTMLElementScroll(element) {
  74. return {
  75. scrollLeft: element.scrollLeft,
  76. scrollTop: element.scrollTop
  77. };
  78. }
  79. function getNodeScroll(node) {
  80. if (node === getWindow(node) || !isHTMLElement(node)) {
  81. return getWindowScroll(node);
  82. } else {
  83. return getHTMLElementScroll(node);
  84. }
  85. }
  86. function getNodeName(element) {
  87. return element ? (element.nodeName || '').toLowerCase() : null;
  88. }
  89. function getDocumentElement(element) {
  90. // $FlowFixMe[incompatible-return]: assume body is always available
  91. return ((isElement(element) ? element.ownerDocument : // $FlowFixMe[prop-missing]
  92. element.document) || window.document).documentElement;
  93. }
  94. function getWindowScrollBarX(element) {
  95. // If <html> has a CSS width greater than the viewport, then this will be
  96. // incorrect for RTL.
  97. // Popper 1 is broken in this case and never had a bug report so let's assume
  98. // it's not an issue. I don't think anyone ever specifies width on <html>
  99. // anyway.
  100. // Browsers where the left scrollbar doesn't cause an issue report `0` for
  101. // this (e.g. Edge 2019, IE11, Safari)
  102. return getBoundingClientRect(getDocumentElement(element)).left + getWindowScroll(element).scrollLeft;
  103. }
  104. function getComputedStyle(element) {
  105. return getWindow(element).getComputedStyle(element);
  106. }
  107. function isScrollParent(element) {
  108. // Firefox wants us to check `-x` and `-y` variations as well
  109. var _getComputedStyle = getComputedStyle(element),
  110. overflow = _getComputedStyle.overflow,
  111. overflowX = _getComputedStyle.overflowX,
  112. overflowY = _getComputedStyle.overflowY;
  113. return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
  114. }
  115. function isElementScaled(element) {
  116. var rect = element.getBoundingClientRect();
  117. var scaleX = round(rect.width) / element.offsetWidth || 1;
  118. var scaleY = round(rect.height) / element.offsetHeight || 1;
  119. return scaleX !== 1 || scaleY !== 1;
  120. } // Returns the composite rect of an element relative to its offsetParent.
  121. // Composite means it takes into account transforms as well as layout.
  122. function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
  123. if (isFixed === void 0) {
  124. isFixed = false;
  125. }
  126. var isOffsetParentAnElement = isHTMLElement(offsetParent);
  127. var offsetParentIsScaled = isHTMLElement(offsetParent) && isElementScaled(offsetParent);
  128. var documentElement = getDocumentElement(offsetParent);
  129. var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled);
  130. var scroll = {
  131. scrollLeft: 0,
  132. scrollTop: 0
  133. };
  134. var offsets = {
  135. x: 0,
  136. y: 0
  137. };
  138. if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
  139. if (getNodeName(offsetParent) !== 'body' || // https://github.com/popperjs/popper-core/issues/1078
  140. isScrollParent(documentElement)) {
  141. scroll = getNodeScroll(offsetParent);
  142. }
  143. if (isHTMLElement(offsetParent)) {
  144. offsets = getBoundingClientRect(offsetParent, true);
  145. offsets.x += offsetParent.clientLeft;
  146. offsets.y += offsetParent.clientTop;
  147. } else if (documentElement) {
  148. offsets.x = getWindowScrollBarX(documentElement);
  149. }
  150. }
  151. return {
  152. x: rect.left + scroll.scrollLeft - offsets.x,
  153. y: rect.top + scroll.scrollTop - offsets.y,
  154. width: rect.width,
  155. height: rect.height
  156. };
  157. }
  158. // means it doesn't take into account transforms.
  159. function getLayoutRect(element) {
  160. var clientRect = getBoundingClientRect(element); // Use the clientRect sizes if it's not been transformed.
  161. // Fixes https://github.com/popperjs/popper-core/issues/1223
  162. var width = element.offsetWidth;
  163. var height = element.offsetHeight;
  164. if (Math.abs(clientRect.width - width) <= 1) {
  165. width = clientRect.width;
  166. }
  167. if (Math.abs(clientRect.height - height) <= 1) {
  168. height = clientRect.height;
  169. }
  170. return {
  171. x: element.offsetLeft,
  172. y: element.offsetTop,
  173. width: width,
  174. height: height
  175. };
  176. }
  177. function getParentNode(element) {
  178. if (getNodeName(element) === 'html') {
  179. return element;
  180. }
  181. return (// this is a quicker (but less type safe) way to save quite some bytes from the bundle
  182. // $FlowFixMe[incompatible-return]
  183. // $FlowFixMe[prop-missing]
  184. element.assignedSlot || // step into the shadow DOM of the parent of a slotted node
  185. element.parentNode || ( // DOM Element detected
  186. isShadowRoot(element) ? element.host : null) || // ShadowRoot detected
  187. // $FlowFixMe[incompatible-call]: HTMLElement is a Node
  188. getDocumentElement(element) // fallback
  189. );
  190. }
  191. function getScrollParent(node) {
  192. if (['html', 'body', '#document'].indexOf(getNodeName(node)) >= 0) {
  193. // $FlowFixMe[incompatible-return]: assume body is always available
  194. return node.ownerDocument.body;
  195. }
  196. if (isHTMLElement(node) && isScrollParent(node)) {
  197. return node;
  198. }
  199. return getScrollParent(getParentNode(node));
  200. }
  201. /*
  202. given a DOM element, return the list of all scroll parents, up the list of ancesors
  203. until we get to the top window object. This list is what we attach scroll listeners
  204. to, because if any of these parent elements scroll, we'll need to re-calculate the
  205. reference element's position.
  206. */
  207. function listScrollParents(element, list) {
  208. var _element$ownerDocumen;
  209. if (list === void 0) {
  210. list = [];
  211. }
  212. var scrollParent = getScrollParent(element);
  213. var isBody = scrollParent === ((_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body);
  214. var win = getWindow(scrollParent);
  215. var target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
  216. var updatedList = list.concat(target);
  217. return isBody ? updatedList : // $FlowFixMe[incompatible-call]: isBody tells us target will be an HTMLElement here
  218. updatedList.concat(listScrollParents(getParentNode(target)));
  219. }
  220. function isTableElement(element) {
  221. return ['table', 'td', 'th'].indexOf(getNodeName(element)) >= 0;
  222. }
  223. function getTrueOffsetParent(element) {
  224. if (!isHTMLElement(element) || // https://github.com/popperjs/popper-core/issues/837
  225. getComputedStyle(element).position === 'fixed') {
  226. return null;
  227. }
  228. return element.offsetParent;
  229. } // `.offsetParent` reports `null` for fixed elements, while absolute elements
  230. // return the containing block
  231. function getContainingBlock(element) {
  232. var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') !== -1;
  233. var isIE = navigator.userAgent.indexOf('Trident') !== -1;
  234. if (isIE && isHTMLElement(element)) {
  235. // In IE 9, 10 and 11 fixed elements containing block is always established by the viewport
  236. var elementCss = getComputedStyle(element);
  237. if (elementCss.position === 'fixed') {
  238. return null;
  239. }
  240. }
  241. var currentNode = getParentNode(element);
  242. if (isShadowRoot(currentNode)) {
  243. currentNode = currentNode.host;
  244. }
  245. while (isHTMLElement(currentNode) && ['html', 'body'].indexOf(getNodeName(currentNode)) < 0) {
  246. var css = getComputedStyle(currentNode); // This is non-exhaustive but covers the most common CSS properties that
  247. // create a containing block.
  248. // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
  249. 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') {
  250. return currentNode;
  251. } else {
  252. currentNode = currentNode.parentNode;
  253. }
  254. }
  255. return null;
  256. } // Gets the closest ancestor positioned element. Handles some edge cases,
  257. // such as table ancestors and cross browser bugs.
  258. function getOffsetParent(element) {
  259. var window = getWindow(element);
  260. var offsetParent = getTrueOffsetParent(element);
  261. while (offsetParent && isTableElement(offsetParent) && getComputedStyle(offsetParent).position === 'static') {
  262. offsetParent = getTrueOffsetParent(offsetParent);
  263. }
  264. if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle(offsetParent).position === 'static')) {
  265. return window;
  266. }
  267. return offsetParent || getContainingBlock(element) || window;
  268. }
  269. var top = 'top';
  270. var bottom = 'bottom';
  271. var right = 'right';
  272. var left = 'left';
  273. var auto = 'auto';
  274. var basePlacements = [top, bottom, right, left];
  275. var start = 'start';
  276. var end = 'end';
  277. var clippingParents = 'clippingParents';
  278. var viewport = 'viewport';
  279. var popper = 'popper';
  280. var reference = 'reference';
  281. var beforeRead = 'beforeRead';
  282. var read = 'read';
  283. var afterRead = 'afterRead'; // pure-logic modifiers
  284. var beforeMain = 'beforeMain';
  285. var main = 'main';
  286. var afterMain = 'afterMain'; // modifier with the purpose to write to the DOM (or write into a framework state)
  287. var beforeWrite = 'beforeWrite';
  288. var write = 'write';
  289. var afterWrite = 'afterWrite';
  290. var modifierPhases = [beforeRead, read, afterRead, beforeMain, main, afterMain, beforeWrite, write, afterWrite];
  291. function order(modifiers) {
  292. var map = new Map();
  293. var visited = new Set();
  294. var result = [];
  295. modifiers.forEach(function (modifier) {
  296. map.set(modifier.name, modifier);
  297. }); // On visiting object, check for its dependencies and visit them recursively
  298. function sort(modifier) {
  299. visited.add(modifier.name);
  300. var requires = [].concat(modifier.requires || [], modifier.requiresIfExists || []);
  301. requires.forEach(function (dep) {
  302. if (!visited.has(dep)) {
  303. var depModifier = map.get(dep);
  304. if (depModifier) {
  305. sort(depModifier);
  306. }
  307. }
  308. });
  309. result.push(modifier);
  310. }
  311. modifiers.forEach(function (modifier) {
  312. if (!visited.has(modifier.name)) {
  313. // check for visited object
  314. sort(modifier);
  315. }
  316. });
  317. return result;
  318. }
  319. function orderModifiers(modifiers) {
  320. // order based on dependencies
  321. var orderedModifiers = order(modifiers); // order based on phase
  322. return modifierPhases.reduce(function (acc, phase) {
  323. return acc.concat(orderedModifiers.filter(function (modifier) {
  324. return modifier.phase === phase;
  325. }));
  326. }, []);
  327. }
  328. function debounce(fn) {
  329. var pending;
  330. return function () {
  331. if (!pending) {
  332. pending = new Promise(function (resolve) {
  333. Promise.resolve().then(function () {
  334. pending = undefined;
  335. resolve(fn());
  336. });
  337. });
  338. }
  339. return pending;
  340. };
  341. }
  342. function format(str) {
  343. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  344. args[_key - 1] = arguments[_key];
  345. }
  346. return [].concat(args).reduce(function (p, c) {
  347. return p.replace(/%s/, c);
  348. }, str);
  349. }
  350. var INVALID_MODIFIER_ERROR = 'Popper: modifier "%s" provided an invalid %s property, expected %s but got %s';
  351. var MISSING_DEPENDENCY_ERROR = 'Popper: modifier "%s" requires "%s", but "%s" modifier is not available';
  352. var VALID_PROPERTIES = ['name', 'enabled', 'phase', 'fn', 'effect', 'requires', 'options'];
  353. function validateModifiers(modifiers) {
  354. modifiers.forEach(function (modifier) {
  355. [].concat(Object.keys(modifier), VALID_PROPERTIES) // IE11-compatible replacement for `new Set(iterable)`
  356. .filter(function (value, index, self) {
  357. return self.indexOf(value) === index;
  358. }).forEach(function (key) {
  359. switch (key) {
  360. case 'name':
  361. if (typeof modifier.name !== 'string') {
  362. console.error(format(INVALID_MODIFIER_ERROR, String(modifier.name), '"name"', '"string"', "\"" + String(modifier.name) + "\""));
  363. }
  364. break;
  365. case 'enabled':
  366. if (typeof modifier.enabled !== 'boolean') {
  367. console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"enabled"', '"boolean"', "\"" + String(modifier.enabled) + "\""));
  368. }
  369. break;
  370. case 'phase':
  371. if (modifierPhases.indexOf(modifier.phase) < 0) {
  372. console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"phase"', "either " + modifierPhases.join(', '), "\"" + String(modifier.phase) + "\""));
  373. }
  374. break;
  375. case 'fn':
  376. if (typeof modifier.fn !== 'function') {
  377. console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"fn"', '"function"', "\"" + String(modifier.fn) + "\""));
  378. }
  379. break;
  380. case 'effect':
  381. if (modifier.effect != null && typeof modifier.effect !== 'function') {
  382. console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"effect"', '"function"', "\"" + String(modifier.fn) + "\""));
  383. }
  384. break;
  385. case 'requires':
  386. if (modifier.requires != null && !Array.isArray(modifier.requires)) {
  387. console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"requires"', '"array"', "\"" + String(modifier.requires) + "\""));
  388. }
  389. break;
  390. case 'requiresIfExists':
  391. if (!Array.isArray(modifier.requiresIfExists)) {
  392. console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"requiresIfExists"', '"array"', "\"" + String(modifier.requiresIfExists) + "\""));
  393. }
  394. break;
  395. case 'options':
  396. case 'data':
  397. break;
  398. default:
  399. console.error("PopperJS: an invalid property has been provided to the \"" + modifier.name + "\" modifier, valid properties are " + VALID_PROPERTIES.map(function (s) {
  400. return "\"" + s + "\"";
  401. }).join(', ') + "; but \"" + key + "\" was provided.");
  402. }
  403. modifier.requires && modifier.requires.forEach(function (requirement) {
  404. if (modifiers.find(function (mod) {
  405. return mod.name === requirement;
  406. }) == null) {
  407. console.error(format(MISSING_DEPENDENCY_ERROR, String(modifier.name), requirement, requirement));
  408. }
  409. });
  410. });
  411. });
  412. }
  413. function uniqueBy(arr, fn) {
  414. var identifiers = new Set();
  415. return arr.filter(function (item) {
  416. var identifier = fn(item);
  417. if (!identifiers.has(identifier)) {
  418. identifiers.add(identifier);
  419. return true;
  420. }
  421. });
  422. }
  423. function getBasePlacement(placement) {
  424. return placement.split('-')[0];
  425. }
  426. function mergeByName(modifiers) {
  427. var merged = modifiers.reduce(function (merged, current) {
  428. var existing = merged[current.name];
  429. merged[current.name] = existing ? Object.assign({}, existing, current, {
  430. options: Object.assign({}, existing.options, current.options),
  431. data: Object.assign({}, existing.data, current.data)
  432. }) : current;
  433. return merged;
  434. }, {}); // IE11 does not support Object.values
  435. return Object.keys(merged).map(function (key) {
  436. return merged[key];
  437. });
  438. }
  439. function getViewportRect(element) {
  440. var win = getWindow(element);
  441. var html = getDocumentElement(element);
  442. var visualViewport = win.visualViewport;
  443. var width = html.clientWidth;
  444. var height = html.clientHeight;
  445. var x = 0;
  446. var y = 0; // NB: This isn't supported on iOS <= 12. If the keyboard is open, the popper
  447. // can be obscured underneath it.
  448. // Also, `html.clientHeight` adds the bottom bar height in Safari iOS, even
  449. // if it isn't open, so if this isn't available, the popper will be detected
  450. // to overflow the bottom of the screen too early.
  451. if (visualViewport) {
  452. width = visualViewport.width;
  453. height = visualViewport.height; // Uses Layout Viewport (like Chrome; Safari does not currently)
  454. // In Chrome, it returns a value very close to 0 (+/-) but contains rounding
  455. // errors due to floating point numbers, so we need to check precision.
  456. // Safari returns a number <= 0, usually < -1 when pinch-zoomed
  457. // Feature detection fails in mobile emulation mode in Chrome.
  458. // Math.abs(win.innerWidth / visualViewport.scale - visualViewport.width) <
  459. // 0.001
  460. // Fallback here: "Not Safari" userAgent
  461. if (!/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
  462. x = visualViewport.offsetLeft;
  463. y = visualViewport.offsetTop;
  464. }
  465. }
  466. return {
  467. width: width,
  468. height: height,
  469. x: x + getWindowScrollBarX(element),
  470. y: y
  471. };
  472. }
  473. // of the `<html>` and `<body>` rect bounds if horizontally scrollable
  474. function getDocumentRect(element) {
  475. var _element$ownerDocumen;
  476. var html = getDocumentElement(element);
  477. var winScroll = getWindowScroll(element);
  478. var body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
  479. var width = max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
  480. var height = max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
  481. var x = -winScroll.scrollLeft + getWindowScrollBarX(element);
  482. var y = -winScroll.scrollTop;
  483. if (getComputedStyle(body || html).direction === 'rtl') {
  484. x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
  485. }
  486. return {
  487. width: width,
  488. height: height,
  489. x: x,
  490. y: y
  491. };
  492. }
  493. function contains(parent, child) {
  494. var rootNode = child.getRootNode && child.getRootNode(); // First, attempt with faster native method
  495. if (parent.contains(child)) {
  496. return true;
  497. } // then fallback to custom implementation with Shadow DOM support
  498. else if (rootNode && isShadowRoot(rootNode)) {
  499. var next = child;
  500. do {
  501. if (next && parent.isSameNode(next)) {
  502. return true;
  503. } // $FlowFixMe[prop-missing]: need a better way to handle this...
  504. next = next.parentNode || next.host;
  505. } while (next);
  506. } // Give up, the result is false
  507. return false;
  508. }
  509. function rectToClientRect(rect) {
  510. return Object.assign({}, rect, {
  511. left: rect.x,
  512. top: rect.y,
  513. right: rect.x + rect.width,
  514. bottom: rect.y + rect.height
  515. });
  516. }
  517. function getInnerBoundingClientRect(element) {
  518. var rect = getBoundingClientRect(element);
  519. rect.top = rect.top + element.clientTop;
  520. rect.left = rect.left + element.clientLeft;
  521. rect.bottom = rect.top + element.clientHeight;
  522. rect.right = rect.left + element.clientWidth;
  523. rect.width = element.clientWidth;
  524. rect.height = element.clientHeight;
  525. rect.x = rect.left;
  526. rect.y = rect.top;
  527. return rect;
  528. }
  529. function getClientRectFromMixedType(element, clippingParent) {
  530. return clippingParent === viewport ? rectToClientRect(getViewportRect(element)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
  531. } // A "clipping parent" is an overflowable container with the characteristic of
  532. // clipping (or hiding) overflowing elements with a position different from
  533. // `initial`
  534. function getClippingParents(element) {
  535. var clippingParents = listScrollParents(getParentNode(element));
  536. var canEscapeClipping = ['absolute', 'fixed'].indexOf(getComputedStyle(element).position) >= 0;
  537. var clipperElement = canEscapeClipping && isHTMLElement(element) ? getOffsetParent(element) : element;
  538. if (!isElement(clipperElement)) {
  539. return [];
  540. } // $FlowFixMe[incompatible-return]: https://github.com/facebook/flow/issues/1414
  541. return clippingParents.filter(function (clippingParent) {
  542. return isElement(clippingParent) && contains(clippingParent, clipperElement) && getNodeName(clippingParent) !== 'body';
  543. });
  544. } // Gets the maximum area that the element is visible in due to any number of
  545. // clipping parents
  546. function getClippingRect(element, boundary, rootBoundary) {
  547. var mainClippingParents = boundary === 'clippingParents' ? getClippingParents(element) : [].concat(boundary);
  548. var clippingParents = [].concat(mainClippingParents, [rootBoundary]);
  549. var firstClippingParent = clippingParents[0];
  550. var clippingRect = clippingParents.reduce(function (accRect, clippingParent) {
  551. var rect = getClientRectFromMixedType(element, clippingParent);
  552. accRect.top = max(rect.top, accRect.top);
  553. accRect.right = min(rect.right, accRect.right);
  554. accRect.bottom = min(rect.bottom, accRect.bottom);
  555. accRect.left = max(rect.left, accRect.left);
  556. return accRect;
  557. }, getClientRectFromMixedType(element, firstClippingParent));
  558. clippingRect.width = clippingRect.right - clippingRect.left;
  559. clippingRect.height = clippingRect.bottom - clippingRect.top;
  560. clippingRect.x = clippingRect.left;
  561. clippingRect.y = clippingRect.top;
  562. return clippingRect;
  563. }
  564. function getVariation(placement) {
  565. return placement.split('-')[1];
  566. }
  567. function getMainAxisFromPlacement(placement) {
  568. return ['top', 'bottom'].indexOf(placement) >= 0 ? 'x' : 'y';
  569. }
  570. function computeOffsets(_ref) {
  571. var reference = _ref.reference,
  572. element = _ref.element,
  573. placement = _ref.placement;
  574. var basePlacement = placement ? getBasePlacement(placement) : null;
  575. var variation = placement ? getVariation(placement) : null;
  576. var commonX = reference.x + reference.width / 2 - element.width / 2;
  577. var commonY = reference.y + reference.height / 2 - element.height / 2;
  578. var offsets;
  579. switch (basePlacement) {
  580. case top:
  581. offsets = {
  582. x: commonX,
  583. y: reference.y - element.height
  584. };
  585. break;
  586. case bottom:
  587. offsets = {
  588. x: commonX,
  589. y: reference.y + reference.height
  590. };
  591. break;
  592. case right:
  593. offsets = {
  594. x: reference.x + reference.width,
  595. y: commonY
  596. };
  597. break;
  598. case left:
  599. offsets = {
  600. x: reference.x - element.width,
  601. y: commonY
  602. };
  603. break;
  604. default:
  605. offsets = {
  606. x: reference.x,
  607. y: reference.y
  608. };
  609. }
  610. var mainAxis = basePlacement ? getMainAxisFromPlacement(basePlacement) : null;
  611. if (mainAxis != null) {
  612. var len = mainAxis === 'y' ? 'height' : 'width';
  613. switch (variation) {
  614. case start:
  615. offsets[mainAxis] = offsets[mainAxis] - (reference[len] / 2 - element[len] / 2);
  616. break;
  617. case end:
  618. offsets[mainAxis] = offsets[mainAxis] + (reference[len] / 2 - element[len] / 2);
  619. break;
  620. }
  621. }
  622. return offsets;
  623. }
  624. function getFreshSideObject() {
  625. return {
  626. top: 0,
  627. right: 0,
  628. bottom: 0,
  629. left: 0
  630. };
  631. }
  632. function mergePaddingObject(paddingObject) {
  633. return Object.assign({}, getFreshSideObject(), paddingObject);
  634. }
  635. function expandToHashMap(value, keys) {
  636. return keys.reduce(function (hashMap, key) {
  637. hashMap[key] = value;
  638. return hashMap;
  639. }, {});
  640. }
  641. function detectOverflow(state, options) {
  642. if (options === void 0) {
  643. options = {};
  644. }
  645. var _options = options,
  646. _options$placement = _options.placement,
  647. placement = _options$placement === void 0 ? state.placement : _options$placement,
  648. _options$boundary = _options.boundary,
  649. boundary = _options$boundary === void 0 ? clippingParents : _options$boundary,
  650. _options$rootBoundary = _options.rootBoundary,
  651. rootBoundary = _options$rootBoundary === void 0 ? viewport : _options$rootBoundary,
  652. _options$elementConte = _options.elementContext,
  653. elementContext = _options$elementConte === void 0 ? popper : _options$elementConte,
  654. _options$altBoundary = _options.altBoundary,
  655. altBoundary = _options$altBoundary === void 0 ? false : _options$altBoundary,
  656. _options$padding = _options.padding,
  657. padding = _options$padding === void 0 ? 0 : _options$padding;
  658. var paddingObject = mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
  659. var altContext = elementContext === popper ? reference : popper;
  660. var popperRect = state.rects.popper;
  661. var element = state.elements[altBoundary ? altContext : elementContext];
  662. var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary);
  663. var referenceClientRect = getBoundingClientRect(state.elements.reference);
  664. var popperOffsets = computeOffsets({
  665. reference: referenceClientRect,
  666. element: popperRect,
  667. strategy: 'absolute',
  668. placement: placement
  669. });
  670. var popperClientRect = rectToClientRect(Object.assign({}, popperRect, popperOffsets));
  671. var elementClientRect = elementContext === popper ? popperClientRect : referenceClientRect; // positive = overflowing the clipping rect
  672. // 0 or negative = within the clipping rect
  673. var overflowOffsets = {
  674. top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
  675. bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
  676. left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
  677. right: elementClientRect.right - clippingClientRect.right + paddingObject.right
  678. };
  679. var offsetData = state.modifiersData.offset; // Offsets can be applied only to the popper element
  680. if (elementContext === popper && offsetData) {
  681. var offset = offsetData[placement];
  682. Object.keys(overflowOffsets).forEach(function (key) {
  683. var multiply = [right, bottom].indexOf(key) >= 0 ? 1 : -1;
  684. var axis = [top, bottom].indexOf(key) >= 0 ? 'y' : 'x';
  685. overflowOffsets[key] += offset[axis] * multiply;
  686. });
  687. }
  688. return overflowOffsets;
  689. }
  690. var INVALID_ELEMENT_ERROR = 'Popper: Invalid reference or popper argument provided. They must be either a DOM element or virtual element.';
  691. var INFINITE_LOOP_ERROR = 'Popper: An infinite loop in the modifiers cycle has been detected! The cycle has been interrupted to prevent a browser crash.';
  692. var DEFAULT_OPTIONS = {
  693. placement: 'bottom',
  694. modifiers: [],
  695. strategy: 'absolute'
  696. };
  697. function areValidElements() {
  698. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  699. args[_key] = arguments[_key];
  700. }
  701. return !args.some(function (element) {
  702. return !(element && typeof element.getBoundingClientRect === 'function');
  703. });
  704. }
  705. function popperGenerator(generatorOptions) {
  706. if (generatorOptions === void 0) {
  707. generatorOptions = {};
  708. }
  709. var _generatorOptions = generatorOptions,
  710. _generatorOptions$def = _generatorOptions.defaultModifiers,
  711. defaultModifiers = _generatorOptions$def === void 0 ? [] : _generatorOptions$def,
  712. _generatorOptions$def2 = _generatorOptions.defaultOptions,
  713. defaultOptions = _generatorOptions$def2 === void 0 ? DEFAULT_OPTIONS : _generatorOptions$def2;
  714. return function createPopper(reference, popper, options) {
  715. if (options === void 0) {
  716. options = defaultOptions;
  717. }
  718. var state = {
  719. placement: 'bottom',
  720. orderedModifiers: [],
  721. options: Object.assign({}, DEFAULT_OPTIONS, defaultOptions),
  722. modifiersData: {},
  723. elements: {
  724. reference: reference,
  725. popper: popper
  726. },
  727. attributes: {},
  728. styles: {}
  729. };
  730. var effectCleanupFns = [];
  731. var isDestroyed = false;
  732. var instance = {
  733. state: state,
  734. setOptions: function setOptions(setOptionsAction) {
  735. var options = typeof setOptionsAction === 'function' ? setOptionsAction(state.options) : setOptionsAction;
  736. cleanupModifierEffects();
  737. state.options = Object.assign({}, defaultOptions, state.options, options);
  738. state.scrollParents = {
  739. reference: isElement(reference) ? listScrollParents(reference) : reference.contextElement ? listScrollParents(reference.contextElement) : [],
  740. popper: listScrollParents(popper)
  741. }; // Orders the modifiers based on their dependencies and `phase`
  742. // properties
  743. var orderedModifiers = orderModifiers(mergeByName([].concat(defaultModifiers, state.options.modifiers))); // Strip out disabled modifiers
  744. state.orderedModifiers = orderedModifiers.filter(function (m) {
  745. return m.enabled;
  746. }); // Validate the provided modifiers so that the consumer will get warned
  747. // if one of the modifiers is invalid for any reason
  748. if (process.env.NODE_ENV !== "production") {
  749. var modifiers = uniqueBy([].concat(orderedModifiers, state.options.modifiers), function (_ref) {
  750. var name = _ref.name;
  751. return name;
  752. });
  753. validateModifiers(modifiers);
  754. if (getBasePlacement(state.options.placement) === auto) {
  755. var flipModifier = state.orderedModifiers.find(function (_ref2) {
  756. var name = _ref2.name;
  757. return name === 'flip';
  758. });
  759. if (!flipModifier) {
  760. console.error(['Popper: "auto" placements require the "flip" modifier be', 'present and enabled to work.'].join(' '));
  761. }
  762. }
  763. var _getComputedStyle = getComputedStyle(popper),
  764. marginTop = _getComputedStyle.marginTop,
  765. marginRight = _getComputedStyle.marginRight,
  766. marginBottom = _getComputedStyle.marginBottom,
  767. marginLeft = _getComputedStyle.marginLeft; // We no longer take into account `margins` on the popper, and it can
  768. // cause bugs with positioning, so we'll warn the consumer
  769. if ([marginTop, marginRight, marginBottom, marginLeft].some(function (margin) {
  770. return parseFloat(margin);
  771. })) {
  772. console.warn(['Popper: CSS "margin" styles cannot be used to apply padding', 'between the popper and its reference element or boundary.', 'To replicate margin, use the `offset` modifier, as well as', 'the `padding` option in the `preventOverflow` and `flip`', 'modifiers.'].join(' '));
  773. }
  774. }
  775. runModifierEffects();
  776. return instance.update();
  777. },
  778. // Sync update – it will always be executed, even if not necessary. This
  779. // is useful for low frequency updates where sync behavior simplifies the
  780. // logic.
  781. // For high frequency updates (e.g. `resize` and `scroll` events), always
  782. // prefer the async Popper#update method
  783. forceUpdate: function forceUpdate() {
  784. if (isDestroyed) {
  785. return;
  786. }
  787. var _state$elements = state.elements,
  788. reference = _state$elements.reference,
  789. popper = _state$elements.popper; // Don't proceed if `reference` or `popper` are not valid elements
  790. // anymore
  791. if (!areValidElements(reference, popper)) {
  792. if (process.env.NODE_ENV !== "production") {
  793. console.error(INVALID_ELEMENT_ERROR);
  794. }
  795. return;
  796. } // Store the reference and popper rects to be read by modifiers
  797. state.rects = {
  798. reference: getCompositeRect(reference, getOffsetParent(popper), state.options.strategy === 'fixed'),
  799. popper: getLayoutRect(popper)
  800. }; // Modifiers have the ability to reset the current update cycle. The
  801. // most common use case for this is the `flip` modifier changing the
  802. // placement, which then needs to re-run all the modifiers, because the
  803. // logic was previously ran for the previous placement and is therefore
  804. // stale/incorrect
  805. state.reset = false;
  806. state.placement = state.options.placement; // On each update cycle, the `modifiersData` property for each modifier
  807. // is filled with the initial data specified by the modifier. This means
  808. // it doesn't persist and is fresh on each update.
  809. // To ensure persistent data, use `${name}#persistent`
  810. state.orderedModifiers.forEach(function (modifier) {
  811. return state.modifiersData[modifier.name] = Object.assign({}, modifier.data);
  812. });
  813. var __debug_loops__ = 0;
  814. for (var index = 0; index < state.orderedModifiers.length; index++) {
  815. if (process.env.NODE_ENV !== "production") {
  816. __debug_loops__ += 1;
  817. if (__debug_loops__ > 100) {
  818. console.error(INFINITE_LOOP_ERROR);
  819. break;
  820. }
  821. }
  822. if (state.reset === true) {
  823. state.reset = false;
  824. index = -1;
  825. continue;
  826. }
  827. var _state$orderedModifie = state.orderedModifiers[index],
  828. fn = _state$orderedModifie.fn,
  829. _state$orderedModifie2 = _state$orderedModifie.options,
  830. _options = _state$orderedModifie2 === void 0 ? {} : _state$orderedModifie2,
  831. name = _state$orderedModifie.name;
  832. if (typeof fn === 'function') {
  833. state = fn({
  834. state: state,
  835. options: _options,
  836. name: name,
  837. instance: instance
  838. }) || state;
  839. }
  840. }
  841. },
  842. // Async and optimistically optimized update – it will not be executed if
  843. // not necessary (debounced to run at most once-per-tick)
  844. update: debounce(function () {
  845. return new Promise(function (resolve) {
  846. instance.forceUpdate();
  847. resolve(state);
  848. });
  849. }),
  850. destroy: function destroy() {
  851. cleanupModifierEffects();
  852. isDestroyed = true;
  853. }
  854. };
  855. if (!areValidElements(reference, popper)) {
  856. if (process.env.NODE_ENV !== "production") {
  857. console.error(INVALID_ELEMENT_ERROR);
  858. }
  859. return instance;
  860. }
  861. instance.setOptions(options).then(function (state) {
  862. if (!isDestroyed && options.onFirstUpdate) {
  863. options.onFirstUpdate(state);
  864. }
  865. }); // Modifiers have the ability to execute arbitrary code before the first
  866. // update cycle runs. They will be executed in the same order as the update
  867. // cycle. This is useful when a modifier adds some persistent data that
  868. // other modifiers need to use, but the modifier is run after the dependent
  869. // one.
  870. function runModifierEffects() {
  871. state.orderedModifiers.forEach(function (_ref3) {
  872. var name = _ref3.name,
  873. _ref3$options = _ref3.options,
  874. options = _ref3$options === void 0 ? {} : _ref3$options,
  875. effect = _ref3.effect;
  876. if (typeof effect === 'function') {
  877. var cleanupFn = effect({
  878. state: state,
  879. name: name,
  880. instance: instance,
  881. options: options
  882. });
  883. var noopFn = function noopFn() {};
  884. effectCleanupFns.push(cleanupFn || noopFn);
  885. }
  886. });
  887. }
  888. function cleanupModifierEffects() {
  889. effectCleanupFns.forEach(function (fn) {
  890. return fn();
  891. });
  892. effectCleanupFns = [];
  893. }
  894. return instance;
  895. };
  896. }
  897. var createPopper = /*#__PURE__*/popperGenerator(); // eslint-disable-next-line import/no-unused-modules
  898. exports.createPopper = createPopper;
  899. exports.detectOverflow = detectOverflow;
  900. exports.popperGenerator = popperGenerator;
  901. //# sourceMappingURL=popper-base.js.map