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.

1266 lines
42 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 basePlacements = [top, bottom, right, left];
  292. var start = 'start';
  293. var end = 'end';
  294. var clippingParents = 'clippingParents';
  295. var viewport = 'viewport';
  296. var popper = 'popper';
  297. var reference = 'reference';
  298. var beforeRead = 'beforeRead';
  299. var read = 'read';
  300. var afterRead = 'afterRead'; // pure-logic modifiers
  301. var beforeMain = 'beforeMain';
  302. var main = 'main';
  303. var afterMain = 'afterMain'; // modifier with the purpose to write to the DOM (or write into a framework state)
  304. var beforeWrite = 'beforeWrite';
  305. var write = 'write';
  306. var afterWrite = 'afterWrite';
  307. var modifierPhases = [beforeRead, read, afterRead, beforeMain, main, afterMain, beforeWrite, write, afterWrite];
  308. function order(modifiers) {
  309. var map = new Map();
  310. var visited = new Set();
  311. var result = [];
  312. modifiers.forEach(function (modifier) {
  313. map.set(modifier.name, modifier);
  314. }); // On visiting object, check for its dependencies and visit them recursively
  315. function sort(modifier) {
  316. visited.add(modifier.name);
  317. var requires = [].concat(modifier.requires || [], modifier.requiresIfExists || []);
  318. requires.forEach(function (dep) {
  319. if (!visited.has(dep)) {
  320. var depModifier = map.get(dep);
  321. if (depModifier) {
  322. sort(depModifier);
  323. }
  324. }
  325. });
  326. result.push(modifier);
  327. }
  328. modifiers.forEach(function (modifier) {
  329. if (!visited.has(modifier.name)) {
  330. // check for visited object
  331. sort(modifier);
  332. }
  333. });
  334. return result;
  335. }
  336. function orderModifiers(modifiers) {
  337. // order based on dependencies
  338. var orderedModifiers = order(modifiers); // order based on phase
  339. return modifierPhases.reduce(function (acc, phase) {
  340. return acc.concat(orderedModifiers.filter(function (modifier) {
  341. return modifier.phase === phase;
  342. }));
  343. }, []);
  344. }
  345. function debounce(fn) {
  346. var pending;
  347. return function () {
  348. if (!pending) {
  349. pending = new Promise(function (resolve) {
  350. Promise.resolve().then(function () {
  351. pending = undefined;
  352. resolve(fn());
  353. });
  354. });
  355. }
  356. return pending;
  357. };
  358. }
  359. function mergeByName(modifiers) {
  360. var merged = modifiers.reduce(function (merged, current) {
  361. var existing = merged[current.name];
  362. merged[current.name] = existing ? Object.assign({}, existing, current, {
  363. options: Object.assign({}, existing.options, current.options),
  364. data: Object.assign({}, existing.data, current.data)
  365. }) : current;
  366. return merged;
  367. }, {}); // IE11 does not support Object.values
  368. return Object.keys(merged).map(function (key) {
  369. return merged[key];
  370. });
  371. }
  372. function getViewportRect(element, strategy) {
  373. var win = getWindow(element);
  374. var html = getDocumentElement(element);
  375. var visualViewport = win.visualViewport;
  376. var width = html.clientWidth;
  377. var height = html.clientHeight;
  378. var x = 0;
  379. var y = 0;
  380. if (visualViewport) {
  381. width = visualViewport.width;
  382. height = visualViewport.height;
  383. var layoutViewport = isLayoutViewport();
  384. if (layoutViewport || !layoutViewport && strategy === 'fixed') {
  385. x = visualViewport.offsetLeft;
  386. y = visualViewport.offsetTop;
  387. }
  388. }
  389. return {
  390. width: width,
  391. height: height,
  392. x: x + getWindowScrollBarX(element),
  393. y: y
  394. };
  395. }
  396. // of the `<html>` and `<body>` rect bounds if horizontally scrollable
  397. function getDocumentRect(element) {
  398. var _element$ownerDocumen;
  399. var html = getDocumentElement(element);
  400. var winScroll = getWindowScroll(element);
  401. var body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
  402. var width = max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
  403. var height = max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
  404. var x = -winScroll.scrollLeft + getWindowScrollBarX(element);
  405. var y = -winScroll.scrollTop;
  406. if (getComputedStyle(body || html).direction === 'rtl') {
  407. x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
  408. }
  409. return {
  410. width: width,
  411. height: height,
  412. x: x,
  413. y: y
  414. };
  415. }
  416. function contains(parent, child) {
  417. var rootNode = child.getRootNode && child.getRootNode(); // First, attempt with faster native method
  418. if (parent.contains(child)) {
  419. return true;
  420. } // then fallback to custom implementation with Shadow DOM support
  421. else if (rootNode && isShadowRoot(rootNode)) {
  422. var next = child;
  423. do {
  424. if (next && parent.isSameNode(next)) {
  425. return true;
  426. } // $FlowFixMe[prop-missing]: need a better way to handle this...
  427. next = next.parentNode || next.host;
  428. } while (next);
  429. } // Give up, the result is false
  430. return false;
  431. }
  432. function rectToClientRect(rect) {
  433. return Object.assign({}, rect, {
  434. left: rect.x,
  435. top: rect.y,
  436. right: rect.x + rect.width,
  437. bottom: rect.y + rect.height
  438. });
  439. }
  440. function getInnerBoundingClientRect(element, strategy) {
  441. var rect = getBoundingClientRect(element, false, strategy === 'fixed');
  442. rect.top = rect.top + element.clientTop;
  443. rect.left = rect.left + element.clientLeft;
  444. rect.bottom = rect.top + element.clientHeight;
  445. rect.right = rect.left + element.clientWidth;
  446. rect.width = element.clientWidth;
  447. rect.height = element.clientHeight;
  448. rect.x = rect.left;
  449. rect.y = rect.top;
  450. return rect;
  451. }
  452. function getClientRectFromMixedType(element, clippingParent, strategy) {
  453. return clippingParent === viewport ? rectToClientRect(getViewportRect(element, strategy)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent, strategy) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
  454. } // A "clipping parent" is an overflowable container with the characteristic of
  455. // clipping (or hiding) overflowing elements with a position different from
  456. // `initial`
  457. function getClippingParents(element) {
  458. var clippingParents = listScrollParents(getParentNode(element));
  459. var canEscapeClipping = ['absolute', 'fixed'].indexOf(getComputedStyle(element).position) >= 0;
  460. var clipperElement = canEscapeClipping && isHTMLElement(element) ? getOffsetParent(element) : element;
  461. if (!isElement(clipperElement)) {
  462. return [];
  463. } // $FlowFixMe[incompatible-return]: https://github.com/facebook/flow/issues/1414
  464. return clippingParents.filter(function (clippingParent) {
  465. return isElement(clippingParent) && contains(clippingParent, clipperElement) && getNodeName(clippingParent) !== 'body';
  466. });
  467. } // Gets the maximum area that the element is visible in due to any number of
  468. // clipping parents
  469. function getClippingRect(element, boundary, rootBoundary, strategy) {
  470. var mainClippingParents = boundary === 'clippingParents' ? getClippingParents(element) : [].concat(boundary);
  471. var clippingParents = [].concat(mainClippingParents, [rootBoundary]);
  472. var firstClippingParent = clippingParents[0];
  473. var clippingRect = clippingParents.reduce(function (accRect, clippingParent) {
  474. var rect = getClientRectFromMixedType(element, clippingParent, strategy);
  475. accRect.top = max(rect.top, accRect.top);
  476. accRect.right = min(rect.right, accRect.right);
  477. accRect.bottom = min(rect.bottom, accRect.bottom);
  478. accRect.left = max(rect.left, accRect.left);
  479. return accRect;
  480. }, getClientRectFromMixedType(element, firstClippingParent, strategy));
  481. clippingRect.width = clippingRect.right - clippingRect.left;
  482. clippingRect.height = clippingRect.bottom - clippingRect.top;
  483. clippingRect.x = clippingRect.left;
  484. clippingRect.y = clippingRect.top;
  485. return clippingRect;
  486. }
  487. function getBasePlacement(placement) {
  488. return placement.split('-')[0];
  489. }
  490. function getVariation(placement) {
  491. return placement.split('-')[1];
  492. }
  493. function getMainAxisFromPlacement(placement) {
  494. return ['top', 'bottom'].indexOf(placement) >= 0 ? 'x' : 'y';
  495. }
  496. function computeOffsets(_ref) {
  497. var reference = _ref.reference,
  498. element = _ref.element,
  499. placement = _ref.placement;
  500. var basePlacement = placement ? getBasePlacement(placement) : null;
  501. var variation = placement ? getVariation(placement) : null;
  502. var commonX = reference.x + reference.width / 2 - element.width / 2;
  503. var commonY = reference.y + reference.height / 2 - element.height / 2;
  504. var offsets;
  505. switch (basePlacement) {
  506. case top:
  507. offsets = {
  508. x: commonX,
  509. y: reference.y - element.height
  510. };
  511. break;
  512. case bottom:
  513. offsets = {
  514. x: commonX,
  515. y: reference.y + reference.height
  516. };
  517. break;
  518. case right:
  519. offsets = {
  520. x: reference.x + reference.width,
  521. y: commonY
  522. };
  523. break;
  524. case left:
  525. offsets = {
  526. x: reference.x - element.width,
  527. y: commonY
  528. };
  529. break;
  530. default:
  531. offsets = {
  532. x: reference.x,
  533. y: reference.y
  534. };
  535. }
  536. var mainAxis = basePlacement ? getMainAxisFromPlacement(basePlacement) : null;
  537. if (mainAxis != null) {
  538. var len = mainAxis === 'y' ? 'height' : 'width';
  539. switch (variation) {
  540. case start:
  541. offsets[mainAxis] = offsets[mainAxis] - (reference[len] / 2 - element[len] / 2);
  542. break;
  543. case end:
  544. offsets[mainAxis] = offsets[mainAxis] + (reference[len] / 2 - element[len] / 2);
  545. break;
  546. }
  547. }
  548. return offsets;
  549. }
  550. function getFreshSideObject() {
  551. return {
  552. top: 0,
  553. right: 0,
  554. bottom: 0,
  555. left: 0
  556. };
  557. }
  558. function mergePaddingObject(paddingObject) {
  559. return Object.assign({}, getFreshSideObject(), paddingObject);
  560. }
  561. function expandToHashMap(value, keys) {
  562. return keys.reduce(function (hashMap, key) {
  563. hashMap[key] = value;
  564. return hashMap;
  565. }, {});
  566. }
  567. function detectOverflow(state, options) {
  568. if (options === void 0) {
  569. options = {};
  570. }
  571. var _options = options,
  572. _options$placement = _options.placement,
  573. placement = _options$placement === void 0 ? state.placement : _options$placement,
  574. _options$strategy = _options.strategy,
  575. strategy = _options$strategy === void 0 ? state.strategy : _options$strategy,
  576. _options$boundary = _options.boundary,
  577. boundary = _options$boundary === void 0 ? clippingParents : _options$boundary,
  578. _options$rootBoundary = _options.rootBoundary,
  579. rootBoundary = _options$rootBoundary === void 0 ? viewport : _options$rootBoundary,
  580. _options$elementConte = _options.elementContext,
  581. elementContext = _options$elementConte === void 0 ? popper : _options$elementConte,
  582. _options$altBoundary = _options.altBoundary,
  583. altBoundary = _options$altBoundary === void 0 ? false : _options$altBoundary,
  584. _options$padding = _options.padding,
  585. padding = _options$padding === void 0 ? 0 : _options$padding;
  586. var paddingObject = mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
  587. var altContext = elementContext === popper ? reference : popper;
  588. var popperRect = state.rects.popper;
  589. var element = state.elements[altBoundary ? altContext : elementContext];
  590. var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary, strategy);
  591. var referenceClientRect = getBoundingClientRect(state.elements.reference);
  592. var popperOffsets = computeOffsets({
  593. reference: referenceClientRect,
  594. element: popperRect,
  595. strategy: 'absolute',
  596. placement: placement
  597. });
  598. var popperClientRect = rectToClientRect(Object.assign({}, popperRect, popperOffsets));
  599. var elementClientRect = elementContext === popper ? popperClientRect : referenceClientRect; // positive = overflowing the clipping rect
  600. // 0 or negative = within the clipping rect
  601. var overflowOffsets = {
  602. top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
  603. bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
  604. left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
  605. right: elementClientRect.right - clippingClientRect.right + paddingObject.right
  606. };
  607. var offsetData = state.modifiersData.offset; // Offsets can be applied only to the popper element
  608. if (elementContext === popper && offsetData) {
  609. var offset = offsetData[placement];
  610. Object.keys(overflowOffsets).forEach(function (key) {
  611. var multiply = [right, bottom].indexOf(key) >= 0 ? 1 : -1;
  612. var axis = [top, bottom].indexOf(key) >= 0 ? 'y' : 'x';
  613. overflowOffsets[key] += offset[axis] * multiply;
  614. });
  615. }
  616. return overflowOffsets;
  617. }
  618. var DEFAULT_OPTIONS = {
  619. placement: 'bottom',
  620. modifiers: [],
  621. strategy: 'absolute'
  622. };
  623. function areValidElements() {
  624. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  625. args[_key] = arguments[_key];
  626. }
  627. return !args.some(function (element) {
  628. return !(element && typeof element.getBoundingClientRect === 'function');
  629. });
  630. }
  631. function popperGenerator(generatorOptions) {
  632. if (generatorOptions === void 0) {
  633. generatorOptions = {};
  634. }
  635. var _generatorOptions = generatorOptions,
  636. _generatorOptions$def = _generatorOptions.defaultModifiers,
  637. defaultModifiers = _generatorOptions$def === void 0 ? [] : _generatorOptions$def,
  638. _generatorOptions$def2 = _generatorOptions.defaultOptions,
  639. defaultOptions = _generatorOptions$def2 === void 0 ? DEFAULT_OPTIONS : _generatorOptions$def2;
  640. return function createPopper(reference, popper, options) {
  641. if (options === void 0) {
  642. options = defaultOptions;
  643. }
  644. var state = {
  645. placement: 'bottom',
  646. orderedModifiers: [],
  647. options: Object.assign({}, DEFAULT_OPTIONS, defaultOptions),
  648. modifiersData: {},
  649. elements: {
  650. reference: reference,
  651. popper: popper
  652. },
  653. attributes: {},
  654. styles: {}
  655. };
  656. var effectCleanupFns = [];
  657. var isDestroyed = false;
  658. var instance = {
  659. state: state,
  660. setOptions: function setOptions(setOptionsAction) {
  661. var options = typeof setOptionsAction === 'function' ? setOptionsAction(state.options) : setOptionsAction;
  662. cleanupModifierEffects();
  663. state.options = Object.assign({}, defaultOptions, state.options, options);
  664. state.scrollParents = {
  665. reference: isElement(reference) ? listScrollParents(reference) : reference.contextElement ? listScrollParents(reference.contextElement) : [],
  666. popper: listScrollParents(popper)
  667. }; // Orders the modifiers based on their dependencies and `phase`
  668. // properties
  669. var orderedModifiers = orderModifiers(mergeByName([].concat(defaultModifiers, state.options.modifiers))); // Strip out disabled modifiers
  670. state.orderedModifiers = orderedModifiers.filter(function (m) {
  671. return m.enabled;
  672. });
  673. runModifierEffects();
  674. return instance.update();
  675. },
  676. // Sync update – it will always be executed, even if not necessary. This
  677. // is useful for low frequency updates where sync behavior simplifies the
  678. // logic.
  679. // For high frequency updates (e.g. `resize` and `scroll` events), always
  680. // prefer the async Popper#update method
  681. forceUpdate: function forceUpdate() {
  682. if (isDestroyed) {
  683. return;
  684. }
  685. var _state$elements = state.elements,
  686. reference = _state$elements.reference,
  687. popper = _state$elements.popper; // Don't proceed if `reference` or `popper` are not valid elements
  688. // anymore
  689. if (!areValidElements(reference, popper)) {
  690. return;
  691. } // Store the reference and popper rects to be read by modifiers
  692. state.rects = {
  693. reference: getCompositeRect(reference, getOffsetParent(popper), state.options.strategy === 'fixed'),
  694. popper: getLayoutRect(popper)
  695. }; // Modifiers have the ability to reset the current update cycle. The
  696. // most common use case for this is the `flip` modifier changing the
  697. // placement, which then needs to re-run all the modifiers, because the
  698. // logic was previously ran for the previous placement and is therefore
  699. // stale/incorrect
  700. state.reset = false;
  701. state.placement = state.options.placement; // On each update cycle, the `modifiersData` property for each modifier
  702. // is filled with the initial data specified by the modifier. This means
  703. // it doesn't persist and is fresh on each update.
  704. // To ensure persistent data, use `${name}#persistent`
  705. state.orderedModifiers.forEach(function (modifier) {
  706. return state.modifiersData[modifier.name] = Object.assign({}, modifier.data);
  707. });
  708. for (var index = 0; index < state.orderedModifiers.length; index++) {
  709. if (state.reset === true) {
  710. state.reset = false;
  711. index = -1;
  712. continue;
  713. }
  714. var _state$orderedModifie = state.orderedModifiers[index],
  715. fn = _state$orderedModifie.fn,
  716. _state$orderedModifie2 = _state$orderedModifie.options,
  717. _options = _state$orderedModifie2 === void 0 ? {} : _state$orderedModifie2,
  718. name = _state$orderedModifie.name;
  719. if (typeof fn === 'function') {
  720. state = fn({
  721. state: state,
  722. options: _options,
  723. name: name,
  724. instance: instance
  725. }) || state;
  726. }
  727. }
  728. },
  729. // Async and optimistically optimized update – it will not be executed if
  730. // not necessary (debounced to run at most once-per-tick)
  731. update: debounce(function () {
  732. return new Promise(function (resolve) {
  733. instance.forceUpdate();
  734. resolve(state);
  735. });
  736. }),
  737. destroy: function destroy() {
  738. cleanupModifierEffects();
  739. isDestroyed = true;
  740. }
  741. };
  742. if (!areValidElements(reference, popper)) {
  743. return instance;
  744. }
  745. instance.setOptions(options).then(function (state) {
  746. if (!isDestroyed && options.onFirstUpdate) {
  747. options.onFirstUpdate(state);
  748. }
  749. }); // Modifiers have the ability to execute arbitrary code before the first
  750. // update cycle runs. They will be executed in the same order as the update
  751. // cycle. This is useful when a modifier adds some persistent data that
  752. // other modifiers need to use, but the modifier is run after the dependent
  753. // one.
  754. function runModifierEffects() {
  755. state.orderedModifiers.forEach(function (_ref) {
  756. var name = _ref.name,
  757. _ref$options = _ref.options,
  758. options = _ref$options === void 0 ? {} : _ref$options,
  759. effect = _ref.effect;
  760. if (typeof effect === 'function') {
  761. var cleanupFn = effect({
  762. state: state,
  763. name: name,
  764. instance: instance,
  765. options: options
  766. });
  767. var noopFn = function noopFn() {};
  768. effectCleanupFns.push(cleanupFn || noopFn);
  769. }
  770. });
  771. }
  772. function cleanupModifierEffects() {
  773. effectCleanupFns.forEach(function (fn) {
  774. return fn();
  775. });
  776. effectCleanupFns = [];
  777. }
  778. return instance;
  779. };
  780. }
  781. var passive = {
  782. passive: true
  783. };
  784. function effect$1(_ref) {
  785. var state = _ref.state,
  786. instance = _ref.instance,
  787. options = _ref.options;
  788. var _options$scroll = options.scroll,
  789. scroll = _options$scroll === void 0 ? true : _options$scroll,
  790. _options$resize = options.resize,
  791. resize = _options$resize === void 0 ? true : _options$resize;
  792. var window = getWindow(state.elements.popper);
  793. var scrollParents = [].concat(state.scrollParents.reference, state.scrollParents.popper);
  794. if (scroll) {
  795. scrollParents.forEach(function (scrollParent) {
  796. scrollParent.addEventListener('scroll', instance.update, passive);
  797. });
  798. }
  799. if (resize) {
  800. window.addEventListener('resize', instance.update, passive);
  801. }
  802. return function () {
  803. if (scroll) {
  804. scrollParents.forEach(function (scrollParent) {
  805. scrollParent.removeEventListener('scroll', instance.update, passive);
  806. });
  807. }
  808. if (resize) {
  809. window.removeEventListener('resize', instance.update, passive);
  810. }
  811. };
  812. } // eslint-disable-next-line import/no-unused-modules
  813. var eventListeners = {
  814. name: 'eventListeners',
  815. enabled: true,
  816. phase: 'write',
  817. fn: function fn() {},
  818. effect: effect$1,
  819. data: {}
  820. };
  821. function popperOffsets(_ref) {
  822. var state = _ref.state,
  823. name = _ref.name;
  824. // Offsets are the actual position the popper needs to have to be
  825. // properly positioned near its reference element
  826. // This is the most basic placement, and will be adjusted by
  827. // the modifiers in the next step
  828. state.modifiersData[name] = computeOffsets({
  829. reference: state.rects.reference,
  830. element: state.rects.popper,
  831. strategy: 'absolute',
  832. placement: state.placement
  833. });
  834. } // eslint-disable-next-line import/no-unused-modules
  835. var popperOffsets$1 = {
  836. name: 'popperOffsets',
  837. enabled: true,
  838. phase: 'read',
  839. fn: popperOffsets,
  840. data: {}
  841. };
  842. var unsetSides = {
  843. top: 'auto',
  844. right: 'auto',
  845. bottom: 'auto',
  846. left: 'auto'
  847. }; // Round the offsets to the nearest suitable subpixel based on the DPR.
  848. // Zooming can change the DPR, but it seems to report a value that will
  849. // cleanly divide the values into the appropriate subpixels.
  850. function roundOffsetsByDPR(_ref, win) {
  851. var x = _ref.x,
  852. y = _ref.y;
  853. var dpr = win.devicePixelRatio || 1;
  854. return {
  855. x: round(x * dpr) / dpr || 0,
  856. y: round(y * dpr) / dpr || 0
  857. };
  858. }
  859. function mapToStyles(_ref2) {
  860. var _Object$assign2;
  861. var popper = _ref2.popper,
  862. popperRect = _ref2.popperRect,
  863. placement = _ref2.placement,
  864. variation = _ref2.variation,
  865. offsets = _ref2.offsets,
  866. position = _ref2.position,
  867. gpuAcceleration = _ref2.gpuAcceleration,
  868. adaptive = _ref2.adaptive,
  869. roundOffsets = _ref2.roundOffsets,
  870. isFixed = _ref2.isFixed;
  871. var _offsets$x = offsets.x,
  872. x = _offsets$x === void 0 ? 0 : _offsets$x,
  873. _offsets$y = offsets.y,
  874. y = _offsets$y === void 0 ? 0 : _offsets$y;
  875. var _ref3 = typeof roundOffsets === 'function' ? roundOffsets({
  876. x: x,
  877. y: y
  878. }) : {
  879. x: x,
  880. y: y
  881. };
  882. x = _ref3.x;
  883. y = _ref3.y;
  884. var hasX = offsets.hasOwnProperty('x');
  885. var hasY = offsets.hasOwnProperty('y');
  886. var sideX = left;
  887. var sideY = top;
  888. var win = window;
  889. if (adaptive) {
  890. var offsetParent = getOffsetParent(popper);
  891. var heightProp = 'clientHeight';
  892. var widthProp = 'clientWidth';
  893. if (offsetParent === getWindow(popper)) {
  894. offsetParent = getDocumentElement(popper);
  895. if (getComputedStyle(offsetParent).position !== 'static' && position === 'absolute') {
  896. heightProp = 'scrollHeight';
  897. widthProp = 'scrollWidth';
  898. }
  899. } // $FlowFixMe[incompatible-cast]: force type refinement, we compare offsetParent with window above, but Flow doesn't detect it
  900. offsetParent = offsetParent;
  901. if (placement === top || (placement === left || placement === right) && variation === end) {
  902. sideY = bottom;
  903. var offsetY = isFixed && offsetParent === win && win.visualViewport ? win.visualViewport.height : // $FlowFixMe[prop-missing]
  904. offsetParent[heightProp];
  905. y -= offsetY - popperRect.height;
  906. y *= gpuAcceleration ? 1 : -1;
  907. }
  908. if (placement === left || (placement === top || placement === bottom) && variation === end) {
  909. sideX = right;
  910. var offsetX = isFixed && offsetParent === win && win.visualViewport ? win.visualViewport.width : // $FlowFixMe[prop-missing]
  911. offsetParent[widthProp];
  912. x -= offsetX - popperRect.width;
  913. x *= gpuAcceleration ? 1 : -1;
  914. }
  915. }
  916. var commonStyles = Object.assign({
  917. position: position
  918. }, adaptive && unsetSides);
  919. var _ref4 = roundOffsets === true ? roundOffsetsByDPR({
  920. x: x,
  921. y: y
  922. }, getWindow(popper)) : {
  923. x: x,
  924. y: y
  925. };
  926. x = _ref4.x;
  927. y = _ref4.y;
  928. if (gpuAcceleration) {
  929. var _Object$assign;
  930. 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));
  931. }
  932. return Object.assign({}, commonStyles, (_Object$assign2 = {}, _Object$assign2[sideY] = hasY ? y + "px" : '', _Object$assign2[sideX] = hasX ? x + "px" : '', _Object$assign2.transform = '', _Object$assign2));
  933. }
  934. function computeStyles(_ref5) {
  935. var state = _ref5.state,
  936. options = _ref5.options;
  937. var _options$gpuAccelerat = options.gpuAcceleration,
  938. gpuAcceleration = _options$gpuAccelerat === void 0 ? true : _options$gpuAccelerat,
  939. _options$adaptive = options.adaptive,
  940. adaptive = _options$adaptive === void 0 ? true : _options$adaptive,
  941. _options$roundOffsets = options.roundOffsets,
  942. roundOffsets = _options$roundOffsets === void 0 ? true : _options$roundOffsets;
  943. var commonStyles = {
  944. placement: getBasePlacement(state.placement),
  945. variation: getVariation(state.placement),
  946. popper: state.elements.popper,
  947. popperRect: state.rects.popper,
  948. gpuAcceleration: gpuAcceleration,
  949. isFixed: state.options.strategy === 'fixed'
  950. };
  951. if (state.modifiersData.popperOffsets != null) {
  952. state.styles.popper = Object.assign({}, state.styles.popper, mapToStyles(Object.assign({}, commonStyles, {
  953. offsets: state.modifiersData.popperOffsets,
  954. position: state.options.strategy,
  955. adaptive: adaptive,
  956. roundOffsets: roundOffsets
  957. })));
  958. }
  959. if (state.modifiersData.arrow != null) {
  960. state.styles.arrow = Object.assign({}, state.styles.arrow, mapToStyles(Object.assign({}, commonStyles, {
  961. offsets: state.modifiersData.arrow,
  962. position: 'absolute',
  963. adaptive: false,
  964. roundOffsets: roundOffsets
  965. })));
  966. }
  967. state.attributes.popper = Object.assign({}, state.attributes.popper, {
  968. 'data-popper-placement': state.placement
  969. });
  970. } // eslint-disable-next-line import/no-unused-modules
  971. var computeStyles$1 = {
  972. name: 'computeStyles',
  973. enabled: true,
  974. phase: 'beforeWrite',
  975. fn: computeStyles,
  976. data: {}
  977. };
  978. // and applies them to the HTMLElements such as popper and arrow
  979. function applyStyles(_ref) {
  980. var state = _ref.state;
  981. Object.keys(state.elements).forEach(function (name) {
  982. var style = state.styles[name] || {};
  983. var attributes = state.attributes[name] || {};
  984. var element = state.elements[name]; // arrow is optional + virtual elements
  985. if (!isHTMLElement(element) || !getNodeName(element)) {
  986. return;
  987. } // Flow doesn't support to extend this property, but it's the most
  988. // effective way to apply styles to an HTMLElement
  989. // $FlowFixMe[cannot-write]
  990. Object.assign(element.style, style);
  991. Object.keys(attributes).forEach(function (name) {
  992. var value = attributes[name];
  993. if (value === false) {
  994. element.removeAttribute(name);
  995. } else {
  996. element.setAttribute(name, value === true ? '' : value);
  997. }
  998. });
  999. });
  1000. }
  1001. function effect(_ref2) {
  1002. var state = _ref2.state;
  1003. var initialStyles = {
  1004. popper: {
  1005. position: state.options.strategy,
  1006. left: '0',
  1007. top: '0',
  1008. margin: '0'
  1009. },
  1010. arrow: {
  1011. position: 'absolute'
  1012. },
  1013. reference: {}
  1014. };
  1015. Object.assign(state.elements.popper.style, initialStyles.popper);
  1016. state.styles = initialStyles;
  1017. if (state.elements.arrow) {
  1018. Object.assign(state.elements.arrow.style, initialStyles.arrow);
  1019. }
  1020. return function () {
  1021. Object.keys(state.elements).forEach(function (name) {
  1022. var element = state.elements[name];
  1023. var attributes = state.attributes[name] || {};
  1024. var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? state.styles[name] : initialStyles[name]); // Set all values to an empty string to unset them
  1025. var style = styleProperties.reduce(function (style, property) {
  1026. style[property] = '';
  1027. return style;
  1028. }, {}); // arrow is optional + virtual elements
  1029. if (!isHTMLElement(element) || !getNodeName(element)) {
  1030. return;
  1031. }
  1032. Object.assign(element.style, style);
  1033. Object.keys(attributes).forEach(function (attribute) {
  1034. element.removeAttribute(attribute);
  1035. });
  1036. });
  1037. };
  1038. } // eslint-disable-next-line import/no-unused-modules
  1039. var applyStyles$1 = {
  1040. name: 'applyStyles',
  1041. enabled: true,
  1042. phase: 'write',
  1043. fn: applyStyles,
  1044. effect: effect,
  1045. requires: ['computeStyles']
  1046. };
  1047. var defaultModifiers = [eventListeners, popperOffsets$1, computeStyles$1, applyStyles$1];
  1048. var createPopper = /*#__PURE__*/popperGenerator({
  1049. defaultModifiers: defaultModifiers
  1050. }); // eslint-disable-next-line import/no-unused-modules
  1051. exports.createPopper = createPopper;
  1052. exports.defaultModifiers = defaultModifiers;
  1053. exports.detectOverflow = detectOverflow;
  1054. exports.popperGenerator = popperGenerator;
  1055. Object.defineProperty(exports, '__esModule', { value: true });
  1056. })));
  1057. //# sourceMappingURL=popper-lite.js.map