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