UNPKG

102 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
7var slicedToArray = require('./slicedToArray-0711941d.js');
8require('./unsupportedIterableToArray-68db1d3b.js');
9var React = require('react');
10var React__default = _interopDefault(React);
11require('./_commonjsHelpers-72d386ba.js');
12require('./index-b0606964.js');
13var defineProperty$1 = require('./defineProperty-0921a47c.js');
14var toConsumableArray = require('./toConsumableArray-d8a4a2c3.js');
15var _styled = require('styled-components');
16var _styled__default = _interopDefault(_styled);
17var getPrototypeOf = require('./getPrototypeOf-2a661a20.js');
18require('./color.js');
19var components = require('./components.js');
20require('./contains-component.js');
21require('./css.js');
22require('./dayjs.min-e07657bf.js');
23require('./date.js');
24var miscellaneous = require('./miscellaneous.js');
25var environment = require('./environment.js');
26require('./font.js');
27require('./math-f4029164.js');
28require('./characters.js');
29require('./format.js');
30var keycodes = require('./keycodes.js');
31require('./url.js');
32require('./web3.js');
33var constants = require('./constants.js');
34require('./breakpoints.js');
35var springs = require('./springs.js');
36require('./text-styles.js');
37require('./theme-dark.js');
38require('./theme-light.js');
39var Theme = require('./Theme.js');
40var _extends$1 = require('./extends-40571110.js');
41var objectWithoutProperties = require('./objectWithoutProperties-35db8ab0.js');
42require('./isObject-ec755c87.js');
43require('./Viewport-15101437.js');
44require('./objectWithoutPropertiesLoose-1af20ad0.js');
45require('react-dom');
46var web = require('./web-d0294535.js');
47require('./getDisplayName-7ab6d318.js');
48require('./index-bc84a358.js');
49var index$1$1 = require('./index-0db71dc1.js');
50var RootPortal = require('./RootPortal.js');
51var proptypes = require('./proptypes-5b34673d.js');
52require('./observe.js');
53require('./index-030bfca8.js');
54require('./providers.js');
55
56/**!
57 * @fileOverview Kickass library to create and place poppers near their reference elements.
58 * @version 1.16.1
59 * @license
60 * Copyright (c) 2016 Federico Zivolo and contributors
61 *
62 * Permission is hereby granted, free of charge, to any person obtaining a copy
63 * of this software and associated documentation files (the "Software"), to deal
64 * in the Software without restriction, including without limitation the rights
65 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
66 * copies of the Software, and to permit persons to whom the Software is
67 * furnished to do so, subject to the following conditions:
68 *
69 * The above copyright notice and this permission notice shall be included in all
70 * copies or substantial portions of the Software.
71 *
72 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
73 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
74 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
75 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
76 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
77 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
78 * SOFTWARE.
79 */
80var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && typeof navigator !== 'undefined';
81
82var timeoutDuration = function () {
83 var longerTimeoutBrowsers = ['Edge', 'Trident', 'Firefox'];
84 for (var i = 0; i < longerTimeoutBrowsers.length; i += 1) {
85 if (isBrowser && navigator.userAgent.indexOf(longerTimeoutBrowsers[i]) >= 0) {
86 return 1;
87 }
88 }
89 return 0;
90}();
91
92function microtaskDebounce(fn) {
93 var called = false;
94 return function () {
95 if (called) {
96 return;
97 }
98 called = true;
99 window.Promise.resolve().then(function () {
100 called = false;
101 fn();
102 });
103 };
104}
105
106function taskDebounce(fn) {
107 var scheduled = false;
108 return function () {
109 if (!scheduled) {
110 scheduled = true;
111 setTimeout(function () {
112 scheduled = false;
113 fn();
114 }, timeoutDuration);
115 }
116 };
117}
118
119var supportsMicroTasks = isBrowser && window.Promise;
120
121/**
122* Create a debounced version of a method, that's asynchronously deferred
123* but called in the minimum time possible.
124*
125* @method
126* @memberof Popper.Utils
127* @argument {Function} fn
128* @returns {Function}
129*/
130var debounce = supportsMicroTasks ? microtaskDebounce : taskDebounce;
131
132/**
133 * Check if the given variable is a function
134 * @method
135 * @memberof Popper.Utils
136 * @argument {Any} functionToCheck - variable to check
137 * @returns {Boolean} answer to: is a function?
138 */
139function isFunction(functionToCheck) {
140 var getType = {};
141 return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
142}
143
144/**
145 * Get CSS computed property of the given element
146 * @method
147 * @memberof Popper.Utils
148 * @argument {Eement} element
149 * @argument {String} property
150 */
151function getStyleComputedProperty(element, property) {
152 if (element.nodeType !== 1) {
153 return [];
154 }
155 // NOTE: 1 DOM access here
156 var window = element.ownerDocument.defaultView;
157 var css = window.getComputedStyle(element, null);
158 return property ? css[property] : css;
159}
160
161/**
162 * Returns the parentNode or the host of the element
163 * @method
164 * @memberof Popper.Utils
165 * @argument {Element} element
166 * @returns {Element} parent
167 */
168function getParentNode(element) {
169 if (element.nodeName === 'HTML') {
170 return element;
171 }
172 return element.parentNode || element.host;
173}
174
175/**
176 * Returns the scrolling parent of the given element
177 * @method
178 * @memberof Popper.Utils
179 * @argument {Element} element
180 * @returns {Element} scroll parent
181 */
182function getScrollParent(element) {
183 // Return body, `getScroll` will take care to get the correct `scrollTop` from it
184 if (!element) {
185 return document.body;
186 }
187
188 switch (element.nodeName) {
189 case 'HTML':
190 case 'BODY':
191 return element.ownerDocument.body;
192 case '#document':
193 return element.body;
194 }
195
196 // Firefox want us to check `-x` and `-y` variations as well
197
198 var _getStyleComputedProp = getStyleComputedProperty(element),
199 overflow = _getStyleComputedProp.overflow,
200 overflowX = _getStyleComputedProp.overflowX,
201 overflowY = _getStyleComputedProp.overflowY;
202
203 if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
204 return element;
205 }
206
207 return getScrollParent(getParentNode(element));
208}
209
210/**
211 * Returns the reference node of the reference object, or the reference object itself.
212 * @method
213 * @memberof Popper.Utils
214 * @param {Element|Object} reference - the reference element (the popper will be relative to this)
215 * @returns {Element} parent
216 */
217function getReferenceNode(reference) {
218 return reference && reference.referenceNode ? reference.referenceNode : reference;
219}
220
221var isIE11 = isBrowser && !!(window.MSInputMethodContext && document.documentMode);
222var isIE10 = isBrowser && /MSIE 10/.test(navigator.userAgent);
223
224/**
225 * Determines if the browser is Internet Explorer
226 * @method
227 * @memberof Popper.Utils
228 * @param {Number} version to check
229 * @returns {Boolean} isIE
230 */
231function isIE(version) {
232 if (version === 11) {
233 return isIE11;
234 }
235 if (version === 10) {
236 return isIE10;
237 }
238 return isIE11 || isIE10;
239}
240
241/**
242 * Returns the offset parent of the given element
243 * @method
244 * @memberof Popper.Utils
245 * @argument {Element} element
246 * @returns {Element} offset parent
247 */
248function getOffsetParent(element) {
249 if (!element) {
250 return document.documentElement;
251 }
252
253 var noOffsetParent = isIE(10) ? document.body : null;
254
255 // NOTE: 1 DOM access here
256 var offsetParent = element.offsetParent || null;
257 // Skip hidden elements which don't have an offsetParent
258 while (offsetParent === noOffsetParent && element.nextElementSibling) {
259 offsetParent = (element = element.nextElementSibling).offsetParent;
260 }
261
262 var nodeName = offsetParent && offsetParent.nodeName;
263
264 if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
265 return element ? element.ownerDocument.documentElement : document.documentElement;
266 }
267
268 // .offsetParent will return the closest TH, TD or TABLE in case
269 // no offsetParent is present, I hate this job...
270 if (['TH', 'TD', 'TABLE'].indexOf(offsetParent.nodeName) !== -1 && getStyleComputedProperty(offsetParent, 'position') === 'static') {
271 return getOffsetParent(offsetParent);
272 }
273
274 return offsetParent;
275}
276
277function isOffsetContainer(element) {
278 var nodeName = element.nodeName;
279
280 if (nodeName === 'BODY') {
281 return false;
282 }
283 return nodeName === 'HTML' || getOffsetParent(element.firstElementChild) === element;
284}
285
286/**
287 * Finds the root node (document, shadowDOM root) of the given element
288 * @method
289 * @memberof Popper.Utils
290 * @argument {Element} node
291 * @returns {Element} root node
292 */
293function getRoot(node) {
294 if (node.parentNode !== null) {
295 return getRoot(node.parentNode);
296 }
297
298 return node;
299}
300
301/**
302 * Finds the offset parent common to the two provided nodes
303 * @method
304 * @memberof Popper.Utils
305 * @argument {Element} element1
306 * @argument {Element} element2
307 * @returns {Element} common offset parent
308 */
309function findCommonOffsetParent(element1, element2) {
310 // This check is needed to avoid errors in case one of the elements isn't defined for any reason
311 if (!element1 || !element1.nodeType || !element2 || !element2.nodeType) {
312 return document.documentElement;
313 }
314
315 // Here we make sure to give as "start" the element that comes first in the DOM
316 var order = element1.compareDocumentPosition(element2) & Node.DOCUMENT_POSITION_FOLLOWING;
317 var start = order ? element1 : element2;
318 var end = order ? element2 : element1;
319
320 // Get common ancestor container
321 var range = document.createRange();
322 range.setStart(start, 0);
323 range.setEnd(end, 0);
324 var commonAncestorContainer = range.commonAncestorContainer;
325
326 // Both nodes are inside #document
327
328 if (element1 !== commonAncestorContainer && element2 !== commonAncestorContainer || start.contains(end)) {
329 if (isOffsetContainer(commonAncestorContainer)) {
330 return commonAncestorContainer;
331 }
332
333 return getOffsetParent(commonAncestorContainer);
334 }
335
336 // one of the nodes is inside shadowDOM, find which one
337 var element1root = getRoot(element1);
338 if (element1root.host) {
339 return findCommonOffsetParent(element1root.host, element2);
340 } else {
341 return findCommonOffsetParent(element1, getRoot(element2).host);
342 }
343}
344
345/**
346 * Gets the scroll value of the given element in the given side (top and left)
347 * @method
348 * @memberof Popper.Utils
349 * @argument {Element} element
350 * @argument {String} side `top` or `left`
351 * @returns {number} amount of scrolled pixels
352 */
353function getScroll(element) {
354 var side = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'top';
355
356 var upperSide = side === 'top' ? 'scrollTop' : 'scrollLeft';
357 var nodeName = element.nodeName;
358
359 if (nodeName === 'BODY' || nodeName === 'HTML') {
360 var html = element.ownerDocument.documentElement;
361 var scrollingElement = element.ownerDocument.scrollingElement || html;
362 return scrollingElement[upperSide];
363 }
364
365 return element[upperSide];
366}
367
368/*
369 * Sum or subtract the element scroll values (left and top) from a given rect object
370 * @method
371 * @memberof Popper.Utils
372 * @param {Object} rect - Rect object you want to change
373 * @param {HTMLElement} element - The element from the function reads the scroll values
374 * @param {Boolean} subtract - set to true if you want to subtract the scroll values
375 * @return {Object} rect - The modifier rect object
376 */
377function includeScroll(rect, element) {
378 var subtract = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
379
380 var scrollTop = getScroll(element, 'top');
381 var scrollLeft = getScroll(element, 'left');
382 var modifier = subtract ? -1 : 1;
383 rect.top += scrollTop * modifier;
384 rect.bottom += scrollTop * modifier;
385 rect.left += scrollLeft * modifier;
386 rect.right += scrollLeft * modifier;
387 return rect;
388}
389
390/*
391 * Helper to detect borders of a given element
392 * @method
393 * @memberof Popper.Utils
394 * @param {CSSStyleDeclaration} styles
395 * Result of `getStyleComputedProperty` on the given element
396 * @param {String} axis - `x` or `y`
397 * @return {number} borders - The borders size of the given axis
398 */
399
400function getBordersSize(styles, axis) {
401 var sideA = axis === 'x' ? 'Left' : 'Top';
402 var sideB = sideA === 'Left' ? 'Right' : 'Bottom';
403
404 return parseFloat(styles['border' + sideA + 'Width']) + parseFloat(styles['border' + sideB + 'Width']);
405}
406
407function getSize(axis, body, html, computedStyle) {
408 return Math.max(body['offset' + axis], body['scroll' + axis], html['client' + axis], html['offset' + axis], html['scroll' + axis], isIE(10) ? parseInt(html['offset' + axis]) + parseInt(computedStyle['margin' + (axis === 'Height' ? 'Top' : 'Left')]) + parseInt(computedStyle['margin' + (axis === 'Height' ? 'Bottom' : 'Right')]) : 0);
409}
410
411function getWindowSizes(document) {
412 var body = document.body;
413 var html = document.documentElement;
414 var computedStyle = isIE(10) && getComputedStyle(html);
415
416 return {
417 height: getSize('Height', body, html, computedStyle),
418 width: getSize('Width', body, html, computedStyle)
419 };
420}
421
422var classCallCheck = function (instance, Constructor) {
423 if (!(instance instanceof Constructor)) {
424 throw new TypeError("Cannot call a class as a function");
425 }
426};
427
428var createClass = function () {
429 function defineProperties(target, props) {
430 for (var i = 0; i < props.length; i++) {
431 var descriptor = props[i];
432 descriptor.enumerable = descriptor.enumerable || false;
433 descriptor.configurable = true;
434 if ("value" in descriptor) descriptor.writable = true;
435 Object.defineProperty(target, descriptor.key, descriptor);
436 }
437 }
438
439 return function (Constructor, protoProps, staticProps) {
440 if (protoProps) defineProperties(Constructor.prototype, protoProps);
441 if (staticProps) defineProperties(Constructor, staticProps);
442 return Constructor;
443 };
444}();
445
446
447
448
449
450var defineProperty = function (obj, key, value) {
451 if (key in obj) {
452 Object.defineProperty(obj, key, {
453 value: value,
454 enumerable: true,
455 configurable: true,
456 writable: true
457 });
458 } else {
459 obj[key] = value;
460 }
461
462 return obj;
463};
464
465var _extends = Object.assign || function (target) {
466 for (var i = 1; i < arguments.length; i++) {
467 var source = arguments[i];
468
469 for (var key in source) {
470 if (Object.prototype.hasOwnProperty.call(source, key)) {
471 target[key] = source[key];
472 }
473 }
474 }
475
476 return target;
477};
478
479/**
480 * Given element offsets, generate an output similar to getBoundingClientRect
481 * @method
482 * @memberof Popper.Utils
483 * @argument {Object} offsets
484 * @returns {Object} ClientRect like output
485 */
486function getClientRect(offsets) {
487 return _extends({}, offsets, {
488 right: offsets.left + offsets.width,
489 bottom: offsets.top + offsets.height
490 });
491}
492
493/**
494 * Get bounding client rect of given element
495 * @method
496 * @memberof Popper.Utils
497 * @param {HTMLElement} element
498 * @return {Object} client rect
499 */
500function getBoundingClientRect(element) {
501 var rect = {};
502
503 // IE10 10 FIX: Please, don't ask, the element isn't
504 // considered in DOM in some circumstances...
505 // This isn't reproducible in IE10 compatibility mode of IE11
506 try {
507 if (isIE(10)) {
508 rect = element.getBoundingClientRect();
509 var scrollTop = getScroll(element, 'top');
510 var scrollLeft = getScroll(element, 'left');
511 rect.top += scrollTop;
512 rect.left += scrollLeft;
513 rect.bottom += scrollTop;
514 rect.right += scrollLeft;
515 } else {
516 rect = element.getBoundingClientRect();
517 }
518 } catch (e) {}
519
520 var result = {
521 left: rect.left,
522 top: rect.top,
523 width: rect.right - rect.left,
524 height: rect.bottom - rect.top
525 };
526
527 // subtract scrollbar size from sizes
528 var sizes = element.nodeName === 'HTML' ? getWindowSizes(element.ownerDocument) : {};
529 var width = sizes.width || element.clientWidth || result.width;
530 var height = sizes.height || element.clientHeight || result.height;
531
532 var horizScrollbar = element.offsetWidth - width;
533 var vertScrollbar = element.offsetHeight - height;
534
535 // if an hypothetical scrollbar is detected, we must be sure it's not a `border`
536 // we make this check conditional for performance reasons
537 if (horizScrollbar || vertScrollbar) {
538 var styles = getStyleComputedProperty(element);
539 horizScrollbar -= getBordersSize(styles, 'x');
540 vertScrollbar -= getBordersSize(styles, 'y');
541
542 result.width -= horizScrollbar;
543 result.height -= vertScrollbar;
544 }
545
546 return getClientRect(result);
547}
548
549function getOffsetRectRelativeToArbitraryNode(children, parent) {
550 var fixedPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
551
552 var isIE10 = isIE(10);
553 var isHTML = parent.nodeName === 'HTML';
554 var childrenRect = getBoundingClientRect(children);
555 var parentRect = getBoundingClientRect(parent);
556 var scrollParent = getScrollParent(children);
557
558 var styles = getStyleComputedProperty(parent);
559 var borderTopWidth = parseFloat(styles.borderTopWidth);
560 var borderLeftWidth = parseFloat(styles.borderLeftWidth);
561
562 // In cases where the parent is fixed, we must ignore negative scroll in offset calc
563 if (fixedPosition && isHTML) {
564 parentRect.top = Math.max(parentRect.top, 0);
565 parentRect.left = Math.max(parentRect.left, 0);
566 }
567 var offsets = getClientRect({
568 top: childrenRect.top - parentRect.top - borderTopWidth,
569 left: childrenRect.left - parentRect.left - borderLeftWidth,
570 width: childrenRect.width,
571 height: childrenRect.height
572 });
573 offsets.marginTop = 0;
574 offsets.marginLeft = 0;
575
576 // Subtract margins of documentElement in case it's being used as parent
577 // we do this only on HTML because it's the only element that behaves
578 // differently when margins are applied to it. The margins are included in
579 // the box of the documentElement, in the other cases not.
580 if (!isIE10 && isHTML) {
581 var marginTop = parseFloat(styles.marginTop);
582 var marginLeft = parseFloat(styles.marginLeft);
583
584 offsets.top -= borderTopWidth - marginTop;
585 offsets.bottom -= borderTopWidth - marginTop;
586 offsets.left -= borderLeftWidth - marginLeft;
587 offsets.right -= borderLeftWidth - marginLeft;
588
589 // Attach marginTop and marginLeft because in some circumstances we may need them
590 offsets.marginTop = marginTop;
591 offsets.marginLeft = marginLeft;
592 }
593
594 if (isIE10 && !fixedPosition ? parent.contains(scrollParent) : parent === scrollParent && scrollParent.nodeName !== 'BODY') {
595 offsets = includeScroll(offsets, parent);
596 }
597
598 return offsets;
599}
600
601function getViewportOffsetRectRelativeToArtbitraryNode(element) {
602 var excludeScroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
603
604 var html = element.ownerDocument.documentElement;
605 var relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html);
606 var width = Math.max(html.clientWidth, window.innerWidth || 0);
607 var height = Math.max(html.clientHeight, window.innerHeight || 0);
608
609 var scrollTop = !excludeScroll ? getScroll(html) : 0;
610 var scrollLeft = !excludeScroll ? getScroll(html, 'left') : 0;
611
612 var offset = {
613 top: scrollTop - relativeOffset.top + relativeOffset.marginTop,
614 left: scrollLeft - relativeOffset.left + relativeOffset.marginLeft,
615 width: width,
616 height: height
617 };
618
619 return getClientRect(offset);
620}
621
622/**
623 * Check if the given element is fixed or is inside a fixed parent
624 * @method
625 * @memberof Popper.Utils
626 * @argument {Element} element
627 * @argument {Element} customContainer
628 * @returns {Boolean} answer to "isFixed?"
629 */
630function isFixed(element) {
631 var nodeName = element.nodeName;
632 if (nodeName === 'BODY' || nodeName === 'HTML') {
633 return false;
634 }
635 if (getStyleComputedProperty(element, 'position') === 'fixed') {
636 return true;
637 }
638 var parentNode = getParentNode(element);
639 if (!parentNode) {
640 return false;
641 }
642 return isFixed(parentNode);
643}
644
645/**
646 * Finds the first parent of an element that has a transformed property defined
647 * @method
648 * @memberof Popper.Utils
649 * @argument {Element} element
650 * @returns {Element} first transformed parent or documentElement
651 */
652
653function getFixedPositionOffsetParent(element) {
654 // This check is needed to avoid errors in case one of the elements isn't defined for any reason
655 if (!element || !element.parentElement || isIE()) {
656 return document.documentElement;
657 }
658 var el = element.parentElement;
659 while (el && getStyleComputedProperty(el, 'transform') === 'none') {
660 el = el.parentElement;
661 }
662 return el || document.documentElement;
663}
664
665/**
666 * Computed the boundaries limits and return them
667 * @method
668 * @memberof Popper.Utils
669 * @param {HTMLElement} popper
670 * @param {HTMLElement} reference
671 * @param {number} padding
672 * @param {HTMLElement} boundariesElement - Element used to define the boundaries
673 * @param {Boolean} fixedPosition - Is in fixed position mode
674 * @returns {Object} Coordinates of the boundaries
675 */
676function getBoundaries(popper, reference, padding, boundariesElement) {
677 var fixedPosition = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
678
679 // NOTE: 1 DOM access here
680
681 var boundaries = { top: 0, left: 0 };
682 var offsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, getReferenceNode(reference));
683
684 // Handle viewport case
685 if (boundariesElement === 'viewport') {
686 boundaries = getViewportOffsetRectRelativeToArtbitraryNode(offsetParent, fixedPosition);
687 } else {
688 // Handle other cases based on DOM element used as boundaries
689 var boundariesNode = void 0;
690 if (boundariesElement === 'scrollParent') {
691 boundariesNode = getScrollParent(getParentNode(reference));
692 if (boundariesNode.nodeName === 'BODY') {
693 boundariesNode = popper.ownerDocument.documentElement;
694 }
695 } else if (boundariesElement === 'window') {
696 boundariesNode = popper.ownerDocument.documentElement;
697 } else {
698 boundariesNode = boundariesElement;
699 }
700
701 var offsets = getOffsetRectRelativeToArbitraryNode(boundariesNode, offsetParent, fixedPosition);
702
703 // In case of HTML, we need a different computation
704 if (boundariesNode.nodeName === 'HTML' && !isFixed(offsetParent)) {
705 var _getWindowSizes = getWindowSizes(popper.ownerDocument),
706 height = _getWindowSizes.height,
707 width = _getWindowSizes.width;
708
709 boundaries.top += offsets.top - offsets.marginTop;
710 boundaries.bottom = height + offsets.top;
711 boundaries.left += offsets.left - offsets.marginLeft;
712 boundaries.right = width + offsets.left;
713 } else {
714 // for all the other DOM elements, this one is good
715 boundaries = offsets;
716 }
717 }
718
719 // Add paddings
720 padding = padding || 0;
721 var isPaddingNumber = typeof padding === 'number';
722 boundaries.left += isPaddingNumber ? padding : padding.left || 0;
723 boundaries.top += isPaddingNumber ? padding : padding.top || 0;
724 boundaries.right -= isPaddingNumber ? padding : padding.right || 0;
725 boundaries.bottom -= isPaddingNumber ? padding : padding.bottom || 0;
726
727 return boundaries;
728}
729
730function getArea(_ref) {
731 var width = _ref.width,
732 height = _ref.height;
733
734 return width * height;
735}
736
737/**
738 * Utility used to transform the `auto` placement to the placement with more
739 * available space.
740 * @method
741 * @memberof Popper.Utils
742 * @argument {Object} data - The data object generated by update method
743 * @argument {Object} options - Modifiers configuration and options
744 * @returns {Object} The data object, properly modified
745 */
746function computeAutoPlacement(placement, refRect, popper, reference, boundariesElement) {
747 var padding = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
748
749 if (placement.indexOf('auto') === -1) {
750 return placement;
751 }
752
753 var boundaries = getBoundaries(popper, reference, padding, boundariesElement);
754
755 var rects = {
756 top: {
757 width: boundaries.width,
758 height: refRect.top - boundaries.top
759 },
760 right: {
761 width: boundaries.right - refRect.right,
762 height: boundaries.height
763 },
764 bottom: {
765 width: boundaries.width,
766 height: boundaries.bottom - refRect.bottom
767 },
768 left: {
769 width: refRect.left - boundaries.left,
770 height: boundaries.height
771 }
772 };
773
774 var sortedAreas = Object.keys(rects).map(function (key) {
775 return _extends({
776 key: key
777 }, rects[key], {
778 area: getArea(rects[key])
779 });
780 }).sort(function (a, b) {
781 return b.area - a.area;
782 });
783
784 var filteredAreas = sortedAreas.filter(function (_ref2) {
785 var width = _ref2.width,
786 height = _ref2.height;
787 return width >= popper.clientWidth && height >= popper.clientHeight;
788 });
789
790 var computedPlacement = filteredAreas.length > 0 ? filteredAreas[0].key : sortedAreas[0].key;
791
792 var variation = placement.split('-')[1];
793
794 return computedPlacement + (variation ? '-' + variation : '');
795}
796
797/**
798 * Get offsets to the reference element
799 * @method
800 * @memberof Popper.Utils
801 * @param {Object} state
802 * @param {Element} popper - the popper element
803 * @param {Element} reference - the reference element (the popper will be relative to this)
804 * @param {Element} fixedPosition - is in fixed position mode
805 * @returns {Object} An object containing the offsets which will be applied to the popper
806 */
807function getReferenceOffsets(state, popper, reference) {
808 var fixedPosition = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
809
810 var commonOffsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, getReferenceNode(reference));
811 return getOffsetRectRelativeToArbitraryNode(reference, commonOffsetParent, fixedPosition);
812}
813
814/**
815 * Get the outer sizes of the given element (offset size + margins)
816 * @method
817 * @memberof Popper.Utils
818 * @argument {Element} element
819 * @returns {Object} object containing width and height properties
820 */
821function getOuterSizes(element) {
822 var window = element.ownerDocument.defaultView;
823 var styles = window.getComputedStyle(element);
824 var x = parseFloat(styles.marginTop || 0) + parseFloat(styles.marginBottom || 0);
825 var y = parseFloat(styles.marginLeft || 0) + parseFloat(styles.marginRight || 0);
826 var result = {
827 width: element.offsetWidth + y,
828 height: element.offsetHeight + x
829 };
830 return result;
831}
832
833/**
834 * Get the opposite placement of the given one
835 * @method
836 * @memberof Popper.Utils
837 * @argument {String} placement
838 * @returns {String} flipped placement
839 */
840function getOppositePlacement(placement) {
841 var hash = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' };
842 return placement.replace(/left|right|bottom|top/g, function (matched) {
843 return hash[matched];
844 });
845}
846
847/**
848 * Get offsets to the popper
849 * @method
850 * @memberof Popper.Utils
851 * @param {Object} position - CSS position the Popper will get applied
852 * @param {HTMLElement} popper - the popper element
853 * @param {Object} referenceOffsets - the reference offsets (the popper will be relative to this)
854 * @param {String} placement - one of the valid placement options
855 * @returns {Object} popperOffsets - An object containing the offsets which will be applied to the popper
856 */
857function getPopperOffsets(popper, referenceOffsets, placement) {
858 placement = placement.split('-')[0];
859
860 // Get popper node sizes
861 var popperRect = getOuterSizes(popper);
862
863 // Add position, width and height to our offsets object
864 var popperOffsets = {
865 width: popperRect.width,
866 height: popperRect.height
867 };
868
869 // depending by the popper placement we have to compute its offsets slightly differently
870 var isHoriz = ['right', 'left'].indexOf(placement) !== -1;
871 var mainSide = isHoriz ? 'top' : 'left';
872 var secondarySide = isHoriz ? 'left' : 'top';
873 var measurement = isHoriz ? 'height' : 'width';
874 var secondaryMeasurement = !isHoriz ? 'height' : 'width';
875
876 popperOffsets[mainSide] = referenceOffsets[mainSide] + referenceOffsets[measurement] / 2 - popperRect[measurement] / 2;
877 if (placement === secondarySide) {
878 popperOffsets[secondarySide] = referenceOffsets[secondarySide] - popperRect[secondaryMeasurement];
879 } else {
880 popperOffsets[secondarySide] = referenceOffsets[getOppositePlacement(secondarySide)];
881 }
882
883 return popperOffsets;
884}
885
886/**
887 * Mimics the `find` method of Array
888 * @method
889 * @memberof Popper.Utils
890 * @argument {Array} arr
891 * @argument prop
892 * @argument value
893 * @returns index or -1
894 */
895function find(arr, check) {
896 // use native find if supported
897 if (Array.prototype.find) {
898 return arr.find(check);
899 }
900
901 // use `filter` to obtain the same behavior of `find`
902 return arr.filter(check)[0];
903}
904
905/**
906 * Return the index of the matching object
907 * @method
908 * @memberof Popper.Utils
909 * @argument {Array} arr
910 * @argument prop
911 * @argument value
912 * @returns index or -1
913 */
914function findIndex(arr, prop, value) {
915 // use native findIndex if supported
916 if (Array.prototype.findIndex) {
917 return arr.findIndex(function (cur) {
918 return cur[prop] === value;
919 });
920 }
921
922 // use `find` + `indexOf` if `findIndex` isn't supported
923 var match = find(arr, function (obj) {
924 return obj[prop] === value;
925 });
926 return arr.indexOf(match);
927}
928
929/**
930 * Loop trough the list of modifiers and run them in order,
931 * each of them will then edit the data object.
932 * @method
933 * @memberof Popper.Utils
934 * @param {dataObject} data
935 * @param {Array} modifiers
936 * @param {String} ends - Optional modifier name used as stopper
937 * @returns {dataObject}
938 */
939function runModifiers(modifiers, data, ends) {
940 var modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex(modifiers, 'name', ends));
941
942 modifiersToRun.forEach(function (modifier) {
943 if (modifier['function']) {
944 // eslint-disable-line dot-notation
945 console.warn('`modifier.function` is deprecated, use `modifier.fn`!');
946 }
947 var fn = modifier['function'] || modifier.fn; // eslint-disable-line dot-notation
948 if (modifier.enabled && isFunction(fn)) {
949 // Add properties to offsets to make them a complete clientRect object
950 // we do this before each modifier to make sure the previous one doesn't
951 // mess with these values
952 data.offsets.popper = getClientRect(data.offsets.popper);
953 data.offsets.reference = getClientRect(data.offsets.reference);
954
955 data = fn(data, modifier);
956 }
957 });
958
959 return data;
960}
961
962/**
963 * Updates the position of the popper, computing the new offsets and applying
964 * the new style.<br />
965 * Prefer `scheduleUpdate` over `update` because of performance reasons.
966 * @method
967 * @memberof Popper
968 */
969function update() {
970 // if popper is destroyed, don't perform any further update
971 if (this.state.isDestroyed) {
972 return;
973 }
974
975 var data = {
976 instance: this,
977 styles: {},
978 arrowStyles: {},
979 attributes: {},
980 flipped: false,
981 offsets: {}
982 };
983
984 // compute reference element offsets
985 data.offsets.reference = getReferenceOffsets(this.state, this.popper, this.reference, this.options.positionFixed);
986
987 // compute auto placement, store placement inside the data object,
988 // modifiers will be able to edit `placement` if needed
989 // and refer to originalPlacement to know the original value
990 data.placement = computeAutoPlacement(this.options.placement, data.offsets.reference, this.popper, this.reference, this.options.modifiers.flip.boundariesElement, this.options.modifiers.flip.padding);
991
992 // store the computed placement inside `originalPlacement`
993 data.originalPlacement = data.placement;
994
995 data.positionFixed = this.options.positionFixed;
996
997 // compute the popper offsets
998 data.offsets.popper = getPopperOffsets(this.popper, data.offsets.reference, data.placement);
999
1000 data.offsets.popper.position = this.options.positionFixed ? 'fixed' : 'absolute';
1001
1002 // run the modifiers
1003 data = runModifiers(this.modifiers, data);
1004
1005 // the first `update` will call `onCreate` callback
1006 // the other ones will call `onUpdate` callback
1007 if (!this.state.isCreated) {
1008 this.state.isCreated = true;
1009 this.options.onCreate(data);
1010 } else {
1011 this.options.onUpdate(data);
1012 }
1013}
1014
1015/**
1016 * Helper used to know if the given modifier is enabled.
1017 * @method
1018 * @memberof Popper.Utils
1019 * @returns {Boolean}
1020 */
1021function isModifierEnabled(modifiers, modifierName) {
1022 return modifiers.some(function (_ref) {
1023 var name = _ref.name,
1024 enabled = _ref.enabled;
1025 return enabled && name === modifierName;
1026 });
1027}
1028
1029/**
1030 * Get the prefixed supported property name
1031 * @method
1032 * @memberof Popper.Utils
1033 * @argument {String} property (camelCase)
1034 * @returns {String} prefixed property (camelCase or PascalCase, depending on the vendor prefix)
1035 */
1036function getSupportedPropertyName(property) {
1037 var prefixes = [false, 'ms', 'Webkit', 'Moz', 'O'];
1038 var upperProp = property.charAt(0).toUpperCase() + property.slice(1);
1039
1040 for (var i = 0; i < prefixes.length; i++) {
1041 var prefix = prefixes[i];
1042 var toCheck = prefix ? '' + prefix + upperProp : property;
1043 if (typeof document.body.style[toCheck] !== 'undefined') {
1044 return toCheck;
1045 }
1046 }
1047 return null;
1048}
1049
1050/**
1051 * Destroys the popper.
1052 * @method
1053 * @memberof Popper
1054 */
1055function destroy() {
1056 this.state.isDestroyed = true;
1057
1058 // touch DOM only if `applyStyle` modifier is enabled
1059 if (isModifierEnabled(this.modifiers, 'applyStyle')) {
1060 this.popper.removeAttribute('x-placement');
1061 this.popper.style.position = '';
1062 this.popper.style.top = '';
1063 this.popper.style.left = '';
1064 this.popper.style.right = '';
1065 this.popper.style.bottom = '';
1066 this.popper.style.willChange = '';
1067 this.popper.style[getSupportedPropertyName('transform')] = '';
1068 }
1069
1070 this.disableEventListeners();
1071
1072 // remove the popper if user explicitly asked for the deletion on destroy
1073 // do not use `remove` because IE11 doesn't support it
1074 if (this.options.removeOnDestroy) {
1075 this.popper.parentNode.removeChild(this.popper);
1076 }
1077 return this;
1078}
1079
1080/**
1081 * Get the window associated with the element
1082 * @argument {Element} element
1083 * @returns {Window}
1084 */
1085function getWindow(element) {
1086 var ownerDocument = element.ownerDocument;
1087 return ownerDocument ? ownerDocument.defaultView : window;
1088}
1089
1090function attachToScrollParents(scrollParent, event, callback, scrollParents) {
1091 var isBody = scrollParent.nodeName === 'BODY';
1092 var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent;
1093 target.addEventListener(event, callback, { passive: true });
1094
1095 if (!isBody) {
1096 attachToScrollParents(getScrollParent(target.parentNode), event, callback, scrollParents);
1097 }
1098 scrollParents.push(target);
1099}
1100
1101/**
1102 * Setup needed event listeners used to update the popper position
1103 * @method
1104 * @memberof Popper.Utils
1105 * @private
1106 */
1107function setupEventListeners(reference, options, state, updateBound) {
1108 // Resize event listener on window
1109 state.updateBound = updateBound;
1110 getWindow(reference).addEventListener('resize', state.updateBound, { passive: true });
1111
1112 // Scroll event listener on scroll parents
1113 var scrollElement = getScrollParent(reference);
1114 attachToScrollParents(scrollElement, 'scroll', state.updateBound, state.scrollParents);
1115 state.scrollElement = scrollElement;
1116 state.eventsEnabled = true;
1117
1118 return state;
1119}
1120
1121/**
1122 * It will add resize/scroll events and start recalculating
1123 * position of the popper element when they are triggered.
1124 * @method
1125 * @memberof Popper
1126 */
1127function enableEventListeners() {
1128 if (!this.state.eventsEnabled) {
1129 this.state = setupEventListeners(this.reference, this.options, this.state, this.scheduleUpdate);
1130 }
1131}
1132
1133/**
1134 * Remove event listeners used to update the popper position
1135 * @method
1136 * @memberof Popper.Utils
1137 * @private
1138 */
1139function removeEventListeners(reference, state) {
1140 // Remove resize event listener on window
1141 getWindow(reference).removeEventListener('resize', state.updateBound);
1142
1143 // Remove scroll event listener on scroll parents
1144 state.scrollParents.forEach(function (target) {
1145 target.removeEventListener('scroll', state.updateBound);
1146 });
1147
1148 // Reset state
1149 state.updateBound = null;
1150 state.scrollParents = [];
1151 state.scrollElement = null;
1152 state.eventsEnabled = false;
1153 return state;
1154}
1155
1156/**
1157 * It will remove resize/scroll events and won't recalculate popper position
1158 * when they are triggered. It also won't trigger `onUpdate` callback anymore,
1159 * unless you call `update` method manually.
1160 * @method
1161 * @memberof Popper
1162 */
1163function disableEventListeners() {
1164 if (this.state.eventsEnabled) {
1165 cancelAnimationFrame(this.scheduleUpdate);
1166 this.state = removeEventListeners(this.reference, this.state);
1167 }
1168}
1169
1170/**
1171 * Tells if a given input is a number
1172 * @method
1173 * @memberof Popper.Utils
1174 * @param {*} input to check
1175 * @return {Boolean}
1176 */
1177function isNumeric(n) {
1178 return n !== '' && !isNaN(parseFloat(n)) && isFinite(n);
1179}
1180
1181/**
1182 * Set the style to the given popper
1183 * @method
1184 * @memberof Popper.Utils
1185 * @argument {Element} element - Element to apply the style to
1186 * @argument {Object} styles
1187 * Object with a list of properties and values which will be applied to the element
1188 */
1189function setStyles(element, styles) {
1190 Object.keys(styles).forEach(function (prop) {
1191 var unit = '';
1192 // add unit if the value is numeric and is one of the following
1193 if (['width', 'height', 'top', 'right', 'bottom', 'left'].indexOf(prop) !== -1 && isNumeric(styles[prop])) {
1194 unit = 'px';
1195 }
1196 element.style[prop] = styles[prop] + unit;
1197 });
1198}
1199
1200/**
1201 * Set the attributes to the given popper
1202 * @method
1203 * @memberof Popper.Utils
1204 * @argument {Element} element - Element to apply the attributes to
1205 * @argument {Object} styles
1206 * Object with a list of properties and values which will be applied to the element
1207 */
1208function setAttributes(element, attributes) {
1209 Object.keys(attributes).forEach(function (prop) {
1210 var value = attributes[prop];
1211 if (value !== false) {
1212 element.setAttribute(prop, attributes[prop]);
1213 } else {
1214 element.removeAttribute(prop);
1215 }
1216 });
1217}
1218
1219/**
1220 * @function
1221 * @memberof Modifiers
1222 * @argument {Object} data - The data object generated by `update` method
1223 * @argument {Object} data.styles - List of style properties - values to apply to popper element
1224 * @argument {Object} data.attributes - List of attribute properties - values to apply to popper element
1225 * @argument {Object} options - Modifiers configuration and options
1226 * @returns {Object} The same data object
1227 */
1228function applyStyle(data) {
1229 // any property present in `data.styles` will be applied to the popper,
1230 // in this way we can make the 3rd party modifiers add custom styles to it
1231 // Be aware, modifiers could override the properties defined in the previous
1232 // lines of this modifier!
1233 setStyles(data.instance.popper, data.styles);
1234
1235 // any property present in `data.attributes` will be applied to the popper,
1236 // they will be set as HTML attributes of the element
1237 setAttributes(data.instance.popper, data.attributes);
1238
1239 // if arrowElement is defined and arrowStyles has some properties
1240 if (data.arrowElement && Object.keys(data.arrowStyles).length) {
1241 setStyles(data.arrowElement, data.arrowStyles);
1242 }
1243
1244 return data;
1245}
1246
1247/**
1248 * Set the x-placement attribute before everything else because it could be used
1249 * to add margins to the popper margins needs to be calculated to get the
1250 * correct popper offsets.
1251 * @method
1252 * @memberof Popper.modifiers
1253 * @param {HTMLElement} reference - The reference element used to position the popper
1254 * @param {HTMLElement} popper - The HTML element used as popper
1255 * @param {Object} options - Popper.js options
1256 */
1257function applyStyleOnLoad(reference, popper, options, modifierOptions, state) {
1258 // compute reference element offsets
1259 var referenceOffsets = getReferenceOffsets(state, popper, reference, options.positionFixed);
1260
1261 // compute auto placement, store placement inside the data object,
1262 // modifiers will be able to edit `placement` if needed
1263 // and refer to originalPlacement to know the original value
1264 var placement = computeAutoPlacement(options.placement, referenceOffsets, popper, reference, options.modifiers.flip.boundariesElement, options.modifiers.flip.padding);
1265
1266 popper.setAttribute('x-placement', placement);
1267
1268 // Apply `position` to popper before anything else because
1269 // without the position applied we can't guarantee correct computations
1270 setStyles(popper, { position: options.positionFixed ? 'fixed' : 'absolute' });
1271
1272 return options;
1273}
1274
1275/**
1276 * @function
1277 * @memberof Popper.Utils
1278 * @argument {Object} data - The data object generated by `update` method
1279 * @argument {Boolean} shouldRound - If the offsets should be rounded at all
1280 * @returns {Object} The popper's position offsets rounded
1281 *
1282 * The tale of pixel-perfect positioning. It's still not 100% perfect, but as
1283 * good as it can be within reason.
1284 * Discussion here: https://github.com/FezVrasta/popper.js/pull/715
1285 *
1286 * Low DPI screens cause a popper to be blurry if not using full pixels (Safari
1287 * as well on High DPI screens).
1288 *
1289 * Firefox prefers no rounding for positioning and does not have blurriness on
1290 * high DPI screens.
1291 *
1292 * Only horizontal placement and left/right values need to be considered.
1293 */
1294function getRoundedOffsets(data, shouldRound) {
1295 var _data$offsets = data.offsets,
1296 popper = _data$offsets.popper,
1297 reference = _data$offsets.reference;
1298 var round = Math.round,
1299 floor = Math.floor;
1300
1301 var noRound = function noRound(v) {
1302 return v;
1303 };
1304
1305 var referenceWidth = round(reference.width);
1306 var popperWidth = round(popper.width);
1307
1308 var isVertical = ['left', 'right'].indexOf(data.placement) !== -1;
1309 var isVariation = data.placement.indexOf('-') !== -1;
1310 var sameWidthParity = referenceWidth % 2 === popperWidth % 2;
1311 var bothOddWidth = referenceWidth % 2 === 1 && popperWidth % 2 === 1;
1312
1313 var horizontalToInteger = !shouldRound ? noRound : isVertical || isVariation || sameWidthParity ? round : floor;
1314 var verticalToInteger = !shouldRound ? noRound : round;
1315
1316 return {
1317 left: horizontalToInteger(bothOddWidth && !isVariation && shouldRound ? popper.left - 1 : popper.left),
1318 top: verticalToInteger(popper.top),
1319 bottom: verticalToInteger(popper.bottom),
1320 right: horizontalToInteger(popper.right)
1321 };
1322}
1323
1324var isFirefox = isBrowser && /Firefox/i.test(navigator.userAgent);
1325
1326/**
1327 * @function
1328 * @memberof Modifiers
1329 * @argument {Object} data - The data object generated by `update` method
1330 * @argument {Object} options - Modifiers configuration and options
1331 * @returns {Object} The data object, properly modified
1332 */
1333function computeStyle(data, options) {
1334 var x = options.x,
1335 y = options.y;
1336 var popper = data.offsets.popper;
1337
1338 // Remove this legacy support in Popper.js v2
1339
1340 var legacyGpuAccelerationOption = find(data.instance.modifiers, function (modifier) {
1341 return modifier.name === 'applyStyle';
1342 }).gpuAcceleration;
1343 if (legacyGpuAccelerationOption !== undefined) {
1344 console.warn('WARNING: `gpuAcceleration` option moved to `computeStyle` modifier and will not be supported in future versions of Popper.js!');
1345 }
1346 var gpuAcceleration = legacyGpuAccelerationOption !== undefined ? legacyGpuAccelerationOption : options.gpuAcceleration;
1347
1348 var offsetParent = getOffsetParent(data.instance.popper);
1349 var offsetParentRect = getBoundingClientRect(offsetParent);
1350
1351 // Styles
1352 var styles = {
1353 position: popper.position
1354 };
1355
1356 var offsets = getRoundedOffsets(data, window.devicePixelRatio < 2 || !isFirefox);
1357
1358 var sideA = x === 'bottom' ? 'top' : 'bottom';
1359 var sideB = y === 'right' ? 'left' : 'right';
1360
1361 // if gpuAcceleration is set to `true` and transform is supported,
1362 // we use `translate3d` to apply the position to the popper we
1363 // automatically use the supported prefixed version if needed
1364 var prefixedProperty = getSupportedPropertyName('transform');
1365
1366 // now, let's make a step back and look at this code closely (wtf?)
1367 // If the content of the popper grows once it's been positioned, it
1368 // may happen that the popper gets misplaced because of the new content
1369 // overflowing its reference element
1370 // To avoid this problem, we provide two options (x and y), which allow
1371 // the consumer to define the offset origin.
1372 // If we position a popper on top of a reference element, we can set
1373 // `x` to `top` to make the popper grow towards its top instead of
1374 // its bottom.
1375 var left = void 0,
1376 top = void 0;
1377 if (sideA === 'bottom') {
1378 // when offsetParent is <html> the positioning is relative to the bottom of the screen (excluding the scrollbar)
1379 // and not the bottom of the html element
1380 if (offsetParent.nodeName === 'HTML') {
1381 top = -offsetParent.clientHeight + offsets.bottom;
1382 } else {
1383 top = -offsetParentRect.height + offsets.bottom;
1384 }
1385 } else {
1386 top = offsets.top;
1387 }
1388 if (sideB === 'right') {
1389 if (offsetParent.nodeName === 'HTML') {
1390 left = -offsetParent.clientWidth + offsets.right;
1391 } else {
1392 left = -offsetParentRect.width + offsets.right;
1393 }
1394 } else {
1395 left = offsets.left;
1396 }
1397 if (gpuAcceleration && prefixedProperty) {
1398 styles[prefixedProperty] = 'translate3d(' + left + 'px, ' + top + 'px, 0)';
1399 styles[sideA] = 0;
1400 styles[sideB] = 0;
1401 styles.willChange = 'transform';
1402 } else {
1403 // othwerise, we use the standard `top`, `left`, `bottom` and `right` properties
1404 var invertTop = sideA === 'bottom' ? -1 : 1;
1405 var invertLeft = sideB === 'right' ? -1 : 1;
1406 styles[sideA] = top * invertTop;
1407 styles[sideB] = left * invertLeft;
1408 styles.willChange = sideA + ', ' + sideB;
1409 }
1410
1411 // Attributes
1412 var attributes = {
1413 'x-placement': data.placement
1414 };
1415
1416 // Update `data` attributes, styles and arrowStyles
1417 data.attributes = _extends({}, attributes, data.attributes);
1418 data.styles = _extends({}, styles, data.styles);
1419 data.arrowStyles = _extends({}, data.offsets.arrow, data.arrowStyles);
1420
1421 return data;
1422}
1423
1424/**
1425 * Helper used to know if the given modifier depends from another one.<br />
1426 * It checks if the needed modifier is listed and enabled.
1427 * @method
1428 * @memberof Popper.Utils
1429 * @param {Array} modifiers - list of modifiers
1430 * @param {String} requestingName - name of requesting modifier
1431 * @param {String} requestedName - name of requested modifier
1432 * @returns {Boolean}
1433 */
1434function isModifierRequired(modifiers, requestingName, requestedName) {
1435 var requesting = find(modifiers, function (_ref) {
1436 var name = _ref.name;
1437 return name === requestingName;
1438 });
1439
1440 var isRequired = !!requesting && modifiers.some(function (modifier) {
1441 return modifier.name === requestedName && modifier.enabled && modifier.order < requesting.order;
1442 });
1443
1444 if (!isRequired) {
1445 var _requesting = '`' + requestingName + '`';
1446 var requested = '`' + requestedName + '`';
1447 console.warn(requested + ' modifier is required by ' + _requesting + ' modifier in order to work, be sure to include it before ' + _requesting + '!');
1448 }
1449 return isRequired;
1450}
1451
1452/**
1453 * @function
1454 * @memberof Modifiers
1455 * @argument {Object} data - The data object generated by update method
1456 * @argument {Object} options - Modifiers configuration and options
1457 * @returns {Object} The data object, properly modified
1458 */
1459function arrow(data, options) {
1460 var _data$offsets$arrow;
1461
1462 // arrow depends on keepTogether in order to work
1463 if (!isModifierRequired(data.instance.modifiers, 'arrow', 'keepTogether')) {
1464 return data;
1465 }
1466
1467 var arrowElement = options.element;
1468
1469 // if arrowElement is a string, suppose it's a CSS selector
1470 if (typeof arrowElement === 'string') {
1471 arrowElement = data.instance.popper.querySelector(arrowElement);
1472
1473 // if arrowElement is not found, don't run the modifier
1474 if (!arrowElement) {
1475 return data;
1476 }
1477 } else {
1478 // if the arrowElement isn't a query selector we must check that the
1479 // provided DOM node is child of its popper node
1480 if (!data.instance.popper.contains(arrowElement)) {
1481 console.warn('WARNING: `arrow.element` must be child of its popper element!');
1482 return data;
1483 }
1484 }
1485
1486 var placement = data.placement.split('-')[0];
1487 var _data$offsets = data.offsets,
1488 popper = _data$offsets.popper,
1489 reference = _data$offsets.reference;
1490
1491 var isVertical = ['left', 'right'].indexOf(placement) !== -1;
1492
1493 var len = isVertical ? 'height' : 'width';
1494 var sideCapitalized = isVertical ? 'Top' : 'Left';
1495 var side = sideCapitalized.toLowerCase();
1496 var altSide = isVertical ? 'left' : 'top';
1497 var opSide = isVertical ? 'bottom' : 'right';
1498 var arrowElementSize = getOuterSizes(arrowElement)[len];
1499
1500 //
1501 // extends keepTogether behavior making sure the popper and its
1502 // reference have enough pixels in conjunction
1503 //
1504
1505 // top/left side
1506 if (reference[opSide] - arrowElementSize < popper[side]) {
1507 data.offsets.popper[side] -= popper[side] - (reference[opSide] - arrowElementSize);
1508 }
1509 // bottom/right side
1510 if (reference[side] + arrowElementSize > popper[opSide]) {
1511 data.offsets.popper[side] += reference[side] + arrowElementSize - popper[opSide];
1512 }
1513 data.offsets.popper = getClientRect(data.offsets.popper);
1514
1515 // compute center of the popper
1516 var center = reference[side] + reference[len] / 2 - arrowElementSize / 2;
1517
1518 // Compute the sideValue using the updated popper offsets
1519 // take popper margin in account because we don't have this info available
1520 var css = getStyleComputedProperty(data.instance.popper);
1521 var popperMarginSide = parseFloat(css['margin' + sideCapitalized]);
1522 var popperBorderSide = parseFloat(css['border' + sideCapitalized + 'Width']);
1523 var sideValue = center - data.offsets.popper[side] - popperMarginSide - popperBorderSide;
1524
1525 // prevent arrowElement from being placed not contiguously to its popper
1526 sideValue = Math.max(Math.min(popper[len] - arrowElementSize, sideValue), 0);
1527
1528 data.arrowElement = arrowElement;
1529 data.offsets.arrow = (_data$offsets$arrow = {}, defineProperty(_data$offsets$arrow, side, Math.round(sideValue)), defineProperty(_data$offsets$arrow, altSide, ''), _data$offsets$arrow);
1530
1531 return data;
1532}
1533
1534/**
1535 * Get the opposite placement variation of the given one
1536 * @method
1537 * @memberof Popper.Utils
1538 * @argument {String} placement variation
1539 * @returns {String} flipped placement variation
1540 */
1541function getOppositeVariation(variation) {
1542 if (variation === 'end') {
1543 return 'start';
1544 } else if (variation === 'start') {
1545 return 'end';
1546 }
1547 return variation;
1548}
1549
1550/**
1551 * List of accepted placements to use as values of the `placement` option.<br />
1552 * Valid placements are:
1553 * - `auto`
1554 * - `top`
1555 * - `right`
1556 * - `bottom`
1557 * - `left`
1558 *
1559 * Each placement can have a variation from this list:
1560 * - `-start`
1561 * - `-end`
1562 *
1563 * Variations are interpreted easily if you think of them as the left to right
1564 * written languages. Horizontally (`top` and `bottom`), `start` is left and `end`
1565 * is right.<br />
1566 * Vertically (`left` and `right`), `start` is top and `end` is bottom.
1567 *
1568 * Some valid examples are:
1569 * - `top-end` (on top of reference, right aligned)
1570 * - `right-start` (on right of reference, top aligned)
1571 * - `bottom` (on bottom, centered)
1572 * - `auto-end` (on the side with more space available, alignment depends by placement)
1573 *
1574 * @static
1575 * @type {Array}
1576 * @enum {String}
1577 * @readonly
1578 * @method placements
1579 * @memberof Popper
1580 */
1581var placements = ['auto-start', 'auto', 'auto-end', 'top-start', 'top', 'top-end', 'right-start', 'right', 'right-end', 'bottom-end', 'bottom', 'bottom-start', 'left-end', 'left', 'left-start'];
1582
1583// Get rid of `auto` `auto-start` and `auto-end`
1584var validPlacements = placements.slice(3);
1585
1586/**
1587 * Given an initial placement, returns all the subsequent placements
1588 * clockwise (or counter-clockwise).
1589 *
1590 * @method
1591 * @memberof Popper.Utils
1592 * @argument {String} placement - A valid placement (it accepts variations)
1593 * @argument {Boolean} counter - Set to true to walk the placements counterclockwise
1594 * @returns {Array} placements including their variations
1595 */
1596function clockwise(placement) {
1597 var counter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1598
1599 var index = validPlacements.indexOf(placement);
1600 var arr = validPlacements.slice(index + 1).concat(validPlacements.slice(0, index));
1601 return counter ? arr.reverse() : arr;
1602}
1603
1604var BEHAVIORS = {
1605 FLIP: 'flip',
1606 CLOCKWISE: 'clockwise',
1607 COUNTERCLOCKWISE: 'counterclockwise'
1608};
1609
1610/**
1611 * @function
1612 * @memberof Modifiers
1613 * @argument {Object} data - The data object generated by update method
1614 * @argument {Object} options - Modifiers configuration and options
1615 * @returns {Object} The data object, properly modified
1616 */
1617function flip(data, options) {
1618 // if `inner` modifier is enabled, we can't use the `flip` modifier
1619 if (isModifierEnabled(data.instance.modifiers, 'inner')) {
1620 return data;
1621 }
1622
1623 if (data.flipped && data.placement === data.originalPlacement) {
1624 // seems like flip is trying to loop, probably there's not enough space on any of the flippable sides
1625 return data;
1626 }
1627
1628 var boundaries = getBoundaries(data.instance.popper, data.instance.reference, options.padding, options.boundariesElement, data.positionFixed);
1629
1630 var placement = data.placement.split('-')[0];
1631 var placementOpposite = getOppositePlacement(placement);
1632 var variation = data.placement.split('-')[1] || '';
1633
1634 var flipOrder = [];
1635
1636 switch (options.behavior) {
1637 case BEHAVIORS.FLIP:
1638 flipOrder = [placement, placementOpposite];
1639 break;
1640 case BEHAVIORS.CLOCKWISE:
1641 flipOrder = clockwise(placement);
1642 break;
1643 case BEHAVIORS.COUNTERCLOCKWISE:
1644 flipOrder = clockwise(placement, true);
1645 break;
1646 default:
1647 flipOrder = options.behavior;
1648 }
1649
1650 flipOrder.forEach(function (step, index) {
1651 if (placement !== step || flipOrder.length === index + 1) {
1652 return data;
1653 }
1654
1655 placement = data.placement.split('-')[0];
1656 placementOpposite = getOppositePlacement(placement);
1657
1658 var popperOffsets = data.offsets.popper;
1659 var refOffsets = data.offsets.reference;
1660
1661 // using floor because the reference offsets may contain decimals we are not going to consider here
1662 var floor = Math.floor;
1663 var overlapsRef = placement === 'left' && floor(popperOffsets.right) > floor(refOffsets.left) || placement === 'right' && floor(popperOffsets.left) < floor(refOffsets.right) || placement === 'top' && floor(popperOffsets.bottom) > floor(refOffsets.top) || placement === 'bottom' && floor(popperOffsets.top) < floor(refOffsets.bottom);
1664
1665 var overflowsLeft = floor(popperOffsets.left) < floor(boundaries.left);
1666 var overflowsRight = floor(popperOffsets.right) > floor(boundaries.right);
1667 var overflowsTop = floor(popperOffsets.top) < floor(boundaries.top);
1668 var overflowsBottom = floor(popperOffsets.bottom) > floor(boundaries.bottom);
1669
1670 var overflowsBoundaries = placement === 'left' && overflowsLeft || placement === 'right' && overflowsRight || placement === 'top' && overflowsTop || placement === 'bottom' && overflowsBottom;
1671
1672 // flip the variation if required
1673 var isVertical = ['top', 'bottom'].indexOf(placement) !== -1;
1674
1675 // flips variation if reference element overflows boundaries
1676 var flippedVariationByRef = !!options.flipVariations && (isVertical && variation === 'start' && overflowsLeft || isVertical && variation === 'end' && overflowsRight || !isVertical && variation === 'start' && overflowsTop || !isVertical && variation === 'end' && overflowsBottom);
1677
1678 // flips variation if popper content overflows boundaries
1679 var flippedVariationByContent = !!options.flipVariationsByContent && (isVertical && variation === 'start' && overflowsRight || isVertical && variation === 'end' && overflowsLeft || !isVertical && variation === 'start' && overflowsBottom || !isVertical && variation === 'end' && overflowsTop);
1680
1681 var flippedVariation = flippedVariationByRef || flippedVariationByContent;
1682
1683 if (overlapsRef || overflowsBoundaries || flippedVariation) {
1684 // this boolean to detect any flip loop
1685 data.flipped = true;
1686
1687 if (overlapsRef || overflowsBoundaries) {
1688 placement = flipOrder[index + 1];
1689 }
1690
1691 if (flippedVariation) {
1692 variation = getOppositeVariation(variation);
1693 }
1694
1695 data.placement = placement + (variation ? '-' + variation : '');
1696
1697 // this object contains `position`, we want to preserve it along with
1698 // any additional property we may add in the future
1699 data.offsets.popper = _extends({}, data.offsets.popper, getPopperOffsets(data.instance.popper, data.offsets.reference, data.placement));
1700
1701 data = runModifiers(data.instance.modifiers, data, 'flip');
1702 }
1703 });
1704 return data;
1705}
1706
1707/**
1708 * @function
1709 * @memberof Modifiers
1710 * @argument {Object} data - The data object generated by update method
1711 * @argument {Object} options - Modifiers configuration and options
1712 * @returns {Object} The data object, properly modified
1713 */
1714function keepTogether(data) {
1715 var _data$offsets = data.offsets,
1716 popper = _data$offsets.popper,
1717 reference = _data$offsets.reference;
1718
1719 var placement = data.placement.split('-')[0];
1720 var floor = Math.floor;
1721 var isVertical = ['top', 'bottom'].indexOf(placement) !== -1;
1722 var side = isVertical ? 'right' : 'bottom';
1723 var opSide = isVertical ? 'left' : 'top';
1724 var measurement = isVertical ? 'width' : 'height';
1725
1726 if (popper[side] < floor(reference[opSide])) {
1727 data.offsets.popper[opSide] = floor(reference[opSide]) - popper[measurement];
1728 }
1729 if (popper[opSide] > floor(reference[side])) {
1730 data.offsets.popper[opSide] = floor(reference[side]);
1731 }
1732
1733 return data;
1734}
1735
1736/**
1737 * Converts a string containing value + unit into a px value number
1738 * @function
1739 * @memberof {modifiers~offset}
1740 * @private
1741 * @argument {String} str - Value + unit string
1742 * @argument {String} measurement - `height` or `width`
1743 * @argument {Object} popperOffsets
1744 * @argument {Object} referenceOffsets
1745 * @returns {Number|String}
1746 * Value in pixels, or original string if no values were extracted
1747 */
1748function toValue(str, measurement, popperOffsets, referenceOffsets) {
1749 // separate value from unit
1750 var split = str.match(/((?:\-|\+)?\d*\.?\d*)(.*)/);
1751 var value = +split[1];
1752 var unit = split[2];
1753
1754 // If it's not a number it's an operator, I guess
1755 if (!value) {
1756 return str;
1757 }
1758
1759 if (unit.indexOf('%') === 0) {
1760 var element = void 0;
1761 switch (unit) {
1762 case '%p':
1763 element = popperOffsets;
1764 break;
1765 case '%':
1766 case '%r':
1767 default:
1768 element = referenceOffsets;
1769 }
1770
1771 var rect = getClientRect(element);
1772 return rect[measurement] / 100 * value;
1773 } else if (unit === 'vh' || unit === 'vw') {
1774 // if is a vh or vw, we calculate the size based on the viewport
1775 var size = void 0;
1776 if (unit === 'vh') {
1777 size = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
1778 } else {
1779 size = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
1780 }
1781 return size / 100 * value;
1782 } else {
1783 // if is an explicit pixel unit, we get rid of the unit and keep the value
1784 // if is an implicit unit, it's px, and we return just the value
1785 return value;
1786 }
1787}
1788
1789/**
1790 * Parse an `offset` string to extrapolate `x` and `y` numeric offsets.
1791 * @function
1792 * @memberof {modifiers~offset}
1793 * @private
1794 * @argument {String} offset
1795 * @argument {Object} popperOffsets
1796 * @argument {Object} referenceOffsets
1797 * @argument {String} basePlacement
1798 * @returns {Array} a two cells array with x and y offsets in numbers
1799 */
1800function parseOffset(offset, popperOffsets, referenceOffsets, basePlacement) {
1801 var offsets = [0, 0];
1802
1803 // Use height if placement is left or right and index is 0 otherwise use width
1804 // in this way the first offset will use an axis and the second one
1805 // will use the other one
1806 var useHeight = ['right', 'left'].indexOf(basePlacement) !== -1;
1807
1808 // Split the offset string to obtain a list of values and operands
1809 // The regex addresses values with the plus or minus sign in front (+10, -20, etc)
1810 var fragments = offset.split(/(\+|\-)/).map(function (frag) {
1811 return frag.trim();
1812 });
1813
1814 // Detect if the offset string contains a pair of values or a single one
1815 // they could be separated by comma or space
1816 var divider = fragments.indexOf(find(fragments, function (frag) {
1817 return frag.search(/,|\s/) !== -1;
1818 }));
1819
1820 if (fragments[divider] && fragments[divider].indexOf(',') === -1) {
1821 console.warn('Offsets separated by white space(s) are deprecated, use a comma (,) instead.');
1822 }
1823
1824 // If divider is found, we divide the list of values and operands to divide
1825 // them by ofset X and Y.
1826 var splitRegex = /\s*,\s*|\s+/;
1827 var ops = divider !== -1 ? [fragments.slice(0, divider).concat([fragments[divider].split(splitRegex)[0]]), [fragments[divider].split(splitRegex)[1]].concat(fragments.slice(divider + 1))] : [fragments];
1828
1829 // Convert the values with units to absolute pixels to allow our computations
1830 ops = ops.map(function (op, index) {
1831 // Most of the units rely on the orientation of the popper
1832 var measurement = (index === 1 ? !useHeight : useHeight) ? 'height' : 'width';
1833 var mergeWithPrevious = false;
1834 return op
1835 // This aggregates any `+` or `-` sign that aren't considered operators
1836 // e.g.: 10 + +5 => [10, +, +5]
1837 .reduce(function (a, b) {
1838 if (a[a.length - 1] === '' && ['+', '-'].indexOf(b) !== -1) {
1839 a[a.length - 1] = b;
1840 mergeWithPrevious = true;
1841 return a;
1842 } else if (mergeWithPrevious) {
1843 a[a.length - 1] += b;
1844 mergeWithPrevious = false;
1845 return a;
1846 } else {
1847 return a.concat(b);
1848 }
1849 }, [])
1850 // Here we convert the string values into number values (in px)
1851 .map(function (str) {
1852 return toValue(str, measurement, popperOffsets, referenceOffsets);
1853 });
1854 });
1855
1856 // Loop trough the offsets arrays and execute the operations
1857 ops.forEach(function (op, index) {
1858 op.forEach(function (frag, index2) {
1859 if (isNumeric(frag)) {
1860 offsets[index] += frag * (op[index2 - 1] === '-' ? -1 : 1);
1861 }
1862 });
1863 });
1864 return offsets;
1865}
1866
1867/**
1868 * @function
1869 * @memberof Modifiers
1870 * @argument {Object} data - The data object generated by update method
1871 * @argument {Object} options - Modifiers configuration and options
1872 * @argument {Number|String} options.offset=0
1873 * The offset value as described in the modifier description
1874 * @returns {Object} The data object, properly modified
1875 */
1876function offset(data, _ref) {
1877 var offset = _ref.offset;
1878 var placement = data.placement,
1879 _data$offsets = data.offsets,
1880 popper = _data$offsets.popper,
1881 reference = _data$offsets.reference;
1882
1883 var basePlacement = placement.split('-')[0];
1884
1885 var offsets = void 0;
1886 if (isNumeric(+offset)) {
1887 offsets = [+offset, 0];
1888 } else {
1889 offsets = parseOffset(offset, popper, reference, basePlacement);
1890 }
1891
1892 if (basePlacement === 'left') {
1893 popper.top += offsets[0];
1894 popper.left -= offsets[1];
1895 } else if (basePlacement === 'right') {
1896 popper.top += offsets[0];
1897 popper.left += offsets[1];
1898 } else if (basePlacement === 'top') {
1899 popper.left += offsets[0];
1900 popper.top -= offsets[1];
1901 } else if (basePlacement === 'bottom') {
1902 popper.left += offsets[0];
1903 popper.top += offsets[1];
1904 }
1905
1906 data.popper = popper;
1907 return data;
1908}
1909
1910/**
1911 * @function
1912 * @memberof Modifiers
1913 * @argument {Object} data - The data object generated by `update` method
1914 * @argument {Object} options - Modifiers configuration and options
1915 * @returns {Object} The data object, properly modified
1916 */
1917function preventOverflow(data, options) {
1918 var boundariesElement = options.boundariesElement || getOffsetParent(data.instance.popper);
1919
1920 // If offsetParent is the reference element, we really want to
1921 // go one step up and use the next offsetParent as reference to
1922 // avoid to make this modifier completely useless and look like broken
1923 if (data.instance.reference === boundariesElement) {
1924 boundariesElement = getOffsetParent(boundariesElement);
1925 }
1926
1927 // NOTE: DOM access here
1928 // resets the popper's position so that the document size can be calculated excluding
1929 // the size of the popper element itself
1930 var transformProp = getSupportedPropertyName('transform');
1931 var popperStyles = data.instance.popper.style; // assignment to help minification
1932 var top = popperStyles.top,
1933 left = popperStyles.left,
1934 transform = popperStyles[transformProp];
1935
1936 popperStyles.top = '';
1937 popperStyles.left = '';
1938 popperStyles[transformProp] = '';
1939
1940 var boundaries = getBoundaries(data.instance.popper, data.instance.reference, options.padding, boundariesElement, data.positionFixed);
1941
1942 // NOTE: DOM access here
1943 // restores the original style properties after the offsets have been computed
1944 popperStyles.top = top;
1945 popperStyles.left = left;
1946 popperStyles[transformProp] = transform;
1947
1948 options.boundaries = boundaries;
1949
1950 var order = options.priority;
1951 var popper = data.offsets.popper;
1952
1953 var check = {
1954 primary: function primary(placement) {
1955 var value = popper[placement];
1956 if (popper[placement] < boundaries[placement] && !options.escapeWithReference) {
1957 value = Math.max(popper[placement], boundaries[placement]);
1958 }
1959 return defineProperty({}, placement, value);
1960 },
1961 secondary: function secondary(placement) {
1962 var mainSide = placement === 'right' ? 'left' : 'top';
1963 var value = popper[mainSide];
1964 if (popper[placement] > boundaries[placement] && !options.escapeWithReference) {
1965 value = Math.min(popper[mainSide], boundaries[placement] - (placement === 'right' ? popper.width : popper.height));
1966 }
1967 return defineProperty({}, mainSide, value);
1968 }
1969 };
1970
1971 order.forEach(function (placement) {
1972 var side = ['left', 'top'].indexOf(placement) !== -1 ? 'primary' : 'secondary';
1973 popper = _extends({}, popper, check[side](placement));
1974 });
1975
1976 data.offsets.popper = popper;
1977
1978 return data;
1979}
1980
1981/**
1982 * @function
1983 * @memberof Modifiers
1984 * @argument {Object} data - The data object generated by `update` method
1985 * @argument {Object} options - Modifiers configuration and options
1986 * @returns {Object} The data object, properly modified
1987 */
1988function shift(data) {
1989 var placement = data.placement;
1990 var basePlacement = placement.split('-')[0];
1991 var shiftvariation = placement.split('-')[1];
1992
1993 // if shift shiftvariation is specified, run the modifier
1994 if (shiftvariation) {
1995 var _data$offsets = data.offsets,
1996 reference = _data$offsets.reference,
1997 popper = _data$offsets.popper;
1998
1999 var isVertical = ['bottom', 'top'].indexOf(basePlacement) !== -1;
2000 var side = isVertical ? 'left' : 'top';
2001 var measurement = isVertical ? 'width' : 'height';
2002
2003 var shiftOffsets = {
2004 start: defineProperty({}, side, reference[side]),
2005 end: defineProperty({}, side, reference[side] + reference[measurement] - popper[measurement])
2006 };
2007
2008 data.offsets.popper = _extends({}, popper, shiftOffsets[shiftvariation]);
2009 }
2010
2011 return data;
2012}
2013
2014/**
2015 * @function
2016 * @memberof Modifiers
2017 * @argument {Object} data - The data object generated by update method
2018 * @argument {Object} options - Modifiers configuration and options
2019 * @returns {Object} The data object, properly modified
2020 */
2021function hide(data) {
2022 if (!isModifierRequired(data.instance.modifiers, 'hide', 'preventOverflow')) {
2023 return data;
2024 }
2025
2026 var refRect = data.offsets.reference;
2027 var bound = find(data.instance.modifiers, function (modifier) {
2028 return modifier.name === 'preventOverflow';
2029 }).boundaries;
2030
2031 if (refRect.bottom < bound.top || refRect.left > bound.right || refRect.top > bound.bottom || refRect.right < bound.left) {
2032 // Avoid unnecessary DOM access if visibility hasn't changed
2033 if (data.hide === true) {
2034 return data;
2035 }
2036
2037 data.hide = true;
2038 data.attributes['x-out-of-boundaries'] = '';
2039 } else {
2040 // Avoid unnecessary DOM access if visibility hasn't changed
2041 if (data.hide === false) {
2042 return data;
2043 }
2044
2045 data.hide = false;
2046 data.attributes['x-out-of-boundaries'] = false;
2047 }
2048
2049 return data;
2050}
2051
2052/**
2053 * @function
2054 * @memberof Modifiers
2055 * @argument {Object} data - The data object generated by `update` method
2056 * @argument {Object} options - Modifiers configuration and options
2057 * @returns {Object} The data object, properly modified
2058 */
2059function inner(data) {
2060 var placement = data.placement;
2061 var basePlacement = placement.split('-')[0];
2062 var _data$offsets = data.offsets,
2063 popper = _data$offsets.popper,
2064 reference = _data$offsets.reference;
2065
2066 var isHoriz = ['left', 'right'].indexOf(basePlacement) !== -1;
2067
2068 var subtractLength = ['top', 'left'].indexOf(basePlacement) === -1;
2069
2070 popper[isHoriz ? 'left' : 'top'] = reference[basePlacement] - (subtractLength ? popper[isHoriz ? 'width' : 'height'] : 0);
2071
2072 data.placement = getOppositePlacement(placement);
2073 data.offsets.popper = getClientRect(popper);
2074
2075 return data;
2076}
2077
2078/**
2079 * Modifier function, each modifier can have a function of this type assigned
2080 * to its `fn` property.<br />
2081 * These functions will be called on each update, this means that you must
2082 * make sure they are performant enough to avoid performance bottlenecks.
2083 *
2084 * @function ModifierFn
2085 * @argument {dataObject} data - The data object generated by `update` method
2086 * @argument {Object} options - Modifiers configuration and options
2087 * @returns {dataObject} The data object, properly modified
2088 */
2089
2090/**
2091 * Modifiers are plugins used to alter the behavior of your poppers.<br />
2092 * Popper.js uses a set of 9 modifiers to provide all the basic functionalities
2093 * needed by the library.
2094 *
2095 * Usually you don't want to override the `order`, `fn` and `onLoad` props.
2096 * All the other properties are configurations that could be tweaked.
2097 * @namespace modifiers
2098 */
2099var modifiers = {
2100 /**
2101 * Modifier used to shift the popper on the start or end of its reference
2102 * element.<br />
2103 * It will read the variation of the `placement` property.<br />
2104 * It can be one either `-end` or `-start`.
2105 * @memberof modifiers
2106 * @inner
2107 */
2108 shift: {
2109 /** @prop {number} order=100 - Index used to define the order of execution */
2110 order: 100,
2111 /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
2112 enabled: true,
2113 /** @prop {ModifierFn} */
2114 fn: shift
2115 },
2116
2117 /**
2118 * The `offset` modifier can shift your popper on both its axis.
2119 *
2120 * It accepts the following units:
2121 * - `px` or unit-less, interpreted as pixels
2122 * - `%` or `%r`, percentage relative to the length of the reference element
2123 * - `%p`, percentage relative to the length of the popper element
2124 * - `vw`, CSS viewport width unit
2125 * - `vh`, CSS viewport height unit
2126 *
2127 * For length is intended the main axis relative to the placement of the popper.<br />
2128 * This means that if the placement is `top` or `bottom`, the length will be the
2129 * `width`. In case of `left` or `right`, it will be the `height`.
2130 *
2131 * You can provide a single value (as `Number` or `String`), or a pair of values
2132 * as `String` divided by a comma or one (or more) white spaces.<br />
2133 * The latter is a deprecated method because it leads to confusion and will be
2134 * removed in v2.<br />
2135 * Additionally, it accepts additions and subtractions between different units.
2136 * Note that multiplications and divisions aren't supported.
2137 *
2138 * Valid examples are:
2139 * ```
2140 * 10
2141 * '10%'
2142 * '10, 10'
2143 * '10%, 10'
2144 * '10 + 10%'
2145 * '10 - 5vh + 3%'
2146 * '-10px + 5vh, 5px - 6%'
2147 * ```
2148 * > **NB**: If you desire to apply offsets to your poppers in a way that may make them overlap
2149 * > with their reference element, unfortunately, you will have to disable the `flip` modifier.
2150 * > You can read more on this at this [issue](https://github.com/FezVrasta/popper.js/issues/373).
2151 *
2152 * @memberof modifiers
2153 * @inner
2154 */
2155 offset: {
2156 /** @prop {number} order=200 - Index used to define the order of execution */
2157 order: 200,
2158 /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
2159 enabled: true,
2160 /** @prop {ModifierFn} */
2161 fn: offset,
2162 /** @prop {Number|String} offset=0
2163 * The offset value as described in the modifier description
2164 */
2165 offset: 0
2166 },
2167
2168 /**
2169 * Modifier used to prevent the popper from being positioned outside the boundary.
2170 *
2171 * A scenario exists where the reference itself is not within the boundaries.<br />
2172 * We can say it has "escaped the boundaries" — or just "escaped".<br />
2173 * In this case we need to decide whether the popper should either:
2174 *
2175 * - detach from the reference and remain "trapped" in the boundaries, or
2176 * - if it should ignore the boundary and "escape with its reference"
2177 *
2178 * When `escapeWithReference` is set to`true` and reference is completely
2179 * outside its boundaries, the popper will overflow (or completely leave)
2180 * the boundaries in order to remain attached to the edge of the reference.
2181 *
2182 * @memberof modifiers
2183 * @inner
2184 */
2185 preventOverflow: {
2186 /** @prop {number} order=300 - Index used to define the order of execution */
2187 order: 300,
2188 /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
2189 enabled: true,
2190 /** @prop {ModifierFn} */
2191 fn: preventOverflow,
2192 /**
2193 * @prop {Array} [priority=['left','right','top','bottom']]
2194 * Popper will try to prevent overflow following these priorities by default,
2195 * then, it could overflow on the left and on top of the `boundariesElement`
2196 */
2197 priority: ['left', 'right', 'top', 'bottom'],
2198 /**
2199 * @prop {number} padding=5
2200 * Amount of pixel used to define a minimum distance between the boundaries
2201 * and the popper. This makes sure the popper always has a little padding
2202 * between the edges of its container
2203 */
2204 padding: 5,
2205 /**
2206 * @prop {String|HTMLElement} boundariesElement='scrollParent'
2207 * Boundaries used by the modifier. Can be `scrollParent`, `window`,
2208 * `viewport` or any DOM element.
2209 */
2210 boundariesElement: 'scrollParent'
2211 },
2212
2213 /**
2214 * Modifier used to make sure the reference and its popper stay near each other
2215 * without leaving any gap between the two. Especially useful when the arrow is
2216 * enabled and you want to ensure that it points to its reference element.
2217 * It cares only about the first axis. You can still have poppers with margin
2218 * between the popper and its reference element.
2219 * @memberof modifiers
2220 * @inner
2221 */
2222 keepTogether: {
2223 /** @prop {number} order=400 - Index used to define the order of execution */
2224 order: 400,
2225 /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
2226 enabled: true,
2227 /** @prop {ModifierFn} */
2228 fn: keepTogether
2229 },
2230
2231 /**
2232 * This modifier is used to move the `arrowElement` of the popper to make
2233 * sure it is positioned between the reference element and its popper element.
2234 * It will read the outer size of the `arrowElement` node to detect how many
2235 * pixels of conjunction are needed.
2236 *
2237 * It has no effect if no `arrowElement` is provided.
2238 * @memberof modifiers
2239 * @inner
2240 */
2241 arrow: {
2242 /** @prop {number} order=500 - Index used to define the order of execution */
2243 order: 500,
2244 /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
2245 enabled: true,
2246 /** @prop {ModifierFn} */
2247 fn: arrow,
2248 /** @prop {String|HTMLElement} element='[x-arrow]' - Selector or node used as arrow */
2249 element: '[x-arrow]'
2250 },
2251
2252 /**
2253 * Modifier used to flip the popper's placement when it starts to overlap its
2254 * reference element.
2255 *
2256 * Requires the `preventOverflow` modifier before it in order to work.
2257 *
2258 * **NOTE:** this modifier will interrupt the current update cycle and will
2259 * restart it if it detects the need to flip the placement.
2260 * @memberof modifiers
2261 * @inner
2262 */
2263 flip: {
2264 /** @prop {number} order=600 - Index used to define the order of execution */
2265 order: 600,
2266 /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
2267 enabled: true,
2268 /** @prop {ModifierFn} */
2269 fn: flip,
2270 /**
2271 * @prop {String|Array} behavior='flip'
2272 * The behavior used to change the popper's placement. It can be one of
2273 * `flip`, `clockwise`, `counterclockwise` or an array with a list of valid
2274 * placements (with optional variations)
2275 */
2276 behavior: 'flip',
2277 /**
2278 * @prop {number} padding=5
2279 * The popper will flip if it hits the edges of the `boundariesElement`
2280 */
2281 padding: 5,
2282 /**
2283 * @prop {String|HTMLElement} boundariesElement='viewport'
2284 * The element which will define the boundaries of the popper position.
2285 * The popper will never be placed outside of the defined boundaries
2286 * (except if `keepTogether` is enabled)
2287 */
2288 boundariesElement: 'viewport',
2289 /**
2290 * @prop {Boolean} flipVariations=false
2291 * The popper will switch placement variation between `-start` and `-end` when
2292 * the reference element overlaps its boundaries.
2293 *
2294 * The original placement should have a set variation.
2295 */
2296 flipVariations: false,
2297 /**
2298 * @prop {Boolean} flipVariationsByContent=false
2299 * The popper will switch placement variation between `-start` and `-end` when
2300 * the popper element overlaps its reference boundaries.
2301 *
2302 * The original placement should have a set variation.
2303 */
2304 flipVariationsByContent: false
2305 },
2306
2307 /**
2308 * Modifier used to make the popper flow toward the inner of the reference element.
2309 * By default, when this modifier is disabled, the popper will be placed outside
2310 * the reference element.
2311 * @memberof modifiers
2312 * @inner
2313 */
2314 inner: {
2315 /** @prop {number} order=700 - Index used to define the order of execution */
2316 order: 700,
2317 /** @prop {Boolean} enabled=false - Whether the modifier is enabled or not */
2318 enabled: false,
2319 /** @prop {ModifierFn} */
2320 fn: inner
2321 },
2322
2323 /**
2324 * Modifier used to hide the popper when its reference element is outside of the
2325 * popper boundaries. It will set a `x-out-of-boundaries` attribute which can
2326 * be used to hide with a CSS selector the popper when its reference is
2327 * out of boundaries.
2328 *
2329 * Requires the `preventOverflow` modifier before it in order to work.
2330 * @memberof modifiers
2331 * @inner
2332 */
2333 hide: {
2334 /** @prop {number} order=800 - Index used to define the order of execution */
2335 order: 800,
2336 /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
2337 enabled: true,
2338 /** @prop {ModifierFn} */
2339 fn: hide
2340 },
2341
2342 /**
2343 * Computes the style that will be applied to the popper element to gets
2344 * properly positioned.
2345 *
2346 * Note that this modifier will not touch the DOM, it just prepares the styles
2347 * so that `applyStyle` modifier can apply it. This separation is useful
2348 * in case you need to replace `applyStyle` with a custom implementation.
2349 *
2350 * This modifier has `850` as `order` value to maintain backward compatibility
2351 * with previous versions of Popper.js. Expect the modifiers ordering method
2352 * to change in future major versions of the library.
2353 *
2354 * @memberof modifiers
2355 * @inner
2356 */
2357 computeStyle: {
2358 /** @prop {number} order=850 - Index used to define the order of execution */
2359 order: 850,
2360 /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
2361 enabled: true,
2362 /** @prop {ModifierFn} */
2363 fn: computeStyle,
2364 /**
2365 * @prop {Boolean} gpuAcceleration=true
2366 * If true, it uses the CSS 3D transformation to position the popper.
2367 * Otherwise, it will use the `top` and `left` properties
2368 */
2369 gpuAcceleration: true,
2370 /**
2371 * @prop {string} [x='bottom']
2372 * Where to anchor the X axis (`bottom` or `top`). AKA X offset origin.
2373 * Change this if your popper should grow in a direction different from `bottom`
2374 */
2375 x: 'bottom',
2376 /**
2377 * @prop {string} [x='left']
2378 * Where to anchor the Y axis (`left` or `right`). AKA Y offset origin.
2379 * Change this if your popper should grow in a direction different from `right`
2380 */
2381 y: 'right'
2382 },
2383
2384 /**
2385 * Applies the computed styles to the popper element.
2386 *
2387 * All the DOM manipulations are limited to this modifier. This is useful in case
2388 * you want to integrate Popper.js inside a framework or view library and you
2389 * want to delegate all the DOM manipulations to it.
2390 *
2391 * Note that if you disable this modifier, you must make sure the popper element
2392 * has its position set to `absolute` before Popper.js can do its work!
2393 *
2394 * Just disable this modifier and define your own to achieve the desired effect.
2395 *
2396 * @memberof modifiers
2397 * @inner
2398 */
2399 applyStyle: {
2400 /** @prop {number} order=900 - Index used to define the order of execution */
2401 order: 900,
2402 /** @prop {Boolean} enabled=true - Whether the modifier is enabled or not */
2403 enabled: true,
2404 /** @prop {ModifierFn} */
2405 fn: applyStyle,
2406 /** @prop {Function} */
2407 onLoad: applyStyleOnLoad,
2408 /**
2409 * @deprecated since version 1.10.0, the property moved to `computeStyle` modifier
2410 * @prop {Boolean} gpuAcceleration=true
2411 * If true, it uses the CSS 3D transformation to position the popper.
2412 * Otherwise, it will use the `top` and `left` properties
2413 */
2414 gpuAcceleration: undefined
2415 }
2416};
2417
2418/**
2419 * The `dataObject` is an object containing all the information used by Popper.js.
2420 * This object is passed to modifiers and to the `onCreate` and `onUpdate` callbacks.
2421 * @name dataObject
2422 * @property {Object} data.instance The Popper.js instance
2423 * @property {String} data.placement Placement applied to popper
2424 * @property {String} data.originalPlacement Placement originally defined on init
2425 * @property {Boolean} data.flipped True if popper has been flipped by flip modifier
2426 * @property {Boolean} data.hide True if the reference element is out of boundaries, useful to know when to hide the popper
2427 * @property {HTMLElement} data.arrowElement Node used as arrow by arrow modifier
2428 * @property {Object} data.styles Any CSS property defined here will be applied to the popper. It expects the JavaScript nomenclature (eg. `marginBottom`)
2429 * @property {Object} data.arrowStyles Any CSS property defined here will be applied to the popper arrow. It expects the JavaScript nomenclature (eg. `marginBottom`)
2430 * @property {Object} data.boundaries Offsets of the popper boundaries
2431 * @property {Object} data.offsets The measurements of popper, reference and arrow elements
2432 * @property {Object} data.offsets.popper `top`, `left`, `width`, `height` values
2433 * @property {Object} data.offsets.reference `top`, `left`, `width`, `height` values
2434 * @property {Object} data.offsets.arrow] `top` and `left` offsets, only one of them will be different from 0
2435 */
2436
2437/**
2438 * Default options provided to Popper.js constructor.<br />
2439 * These can be overridden using the `options` argument of Popper.js.<br />
2440 * To override an option, simply pass an object with the same
2441 * structure of the `options` object, as the 3rd argument. For example:
2442 * ```
2443 * new Popper(ref, pop, {
2444 * modifiers: {
2445 * preventOverflow: { enabled: false }
2446 * }
2447 * })
2448 * ```
2449 * @type {Object}
2450 * @static
2451 * @memberof Popper
2452 */
2453var Defaults = {
2454 /**
2455 * Popper's placement.
2456 * @prop {Popper.placements} placement='bottom'
2457 */
2458 placement: 'bottom',
2459
2460 /**
2461 * Set this to true if you want popper to position it self in 'fixed' mode
2462 * @prop {Boolean} positionFixed=false
2463 */
2464 positionFixed: false,
2465
2466 /**
2467 * Whether events (resize, scroll) are initially enabled.
2468 * @prop {Boolean} eventsEnabled=true
2469 */
2470 eventsEnabled: true,
2471
2472 /**
2473 * Set to true if you want to automatically remove the popper when
2474 * you call the `destroy` method.
2475 * @prop {Boolean} removeOnDestroy=false
2476 */
2477 removeOnDestroy: false,
2478
2479 /**
2480 * Callback called when the popper is created.<br />
2481 * By default, it is set to no-op.<br />
2482 * Access Popper.js instance with `data.instance`.
2483 * @prop {onCreate}
2484 */
2485 onCreate: function onCreate() {},
2486
2487 /**
2488 * Callback called when the popper is updated. This callback is not called
2489 * on the initialization/creation of the popper, but only on subsequent
2490 * updates.<br />
2491 * By default, it is set to no-op.<br />
2492 * Access Popper.js instance with `data.instance`.
2493 * @prop {onUpdate}
2494 */
2495 onUpdate: function onUpdate() {},
2496
2497 /**
2498 * List of modifiers used to modify the offsets before they are applied to the popper.
2499 * They provide most of the functionalities of Popper.js.
2500 * @prop {modifiers}
2501 */
2502 modifiers: modifiers
2503};
2504
2505/**
2506 * @callback onCreate
2507 * @param {dataObject} data
2508 */
2509
2510/**
2511 * @callback onUpdate
2512 * @param {dataObject} data
2513 */
2514
2515// Utils
2516// Methods
2517var Popper = function () {
2518 /**
2519 * Creates a new Popper.js instance.
2520 * @class Popper
2521 * @param {Element|referenceObject} reference - The reference element used to position the popper
2522 * @param {Element} popper - The HTML / XML element used as the popper
2523 * @param {Object} options - Your custom options to override the ones defined in [Defaults](#defaults)
2524 * @return {Object} instance - The generated Popper.js instance
2525 */
2526 function Popper(reference, popper) {
2527 var _this = this;
2528
2529 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2530 classCallCheck(this, Popper);
2531
2532 this.scheduleUpdate = function () {
2533 return requestAnimationFrame(_this.update);
2534 };
2535
2536 // make update() debounced, so that it only runs at most once-per-tick
2537 this.update = debounce(this.update.bind(this));
2538
2539 // with {} we create a new object with the options inside it
2540 this.options = _extends({}, Popper.Defaults, options);
2541
2542 // init state
2543 this.state = {
2544 isDestroyed: false,
2545 isCreated: false,
2546 scrollParents: []
2547 };
2548
2549 // get reference and popper elements (allow jQuery wrappers)
2550 this.reference = reference && reference.jquery ? reference[0] : reference;
2551 this.popper = popper && popper.jquery ? popper[0] : popper;
2552
2553 // Deep merge modifiers options
2554 this.options.modifiers = {};
2555 Object.keys(_extends({}, Popper.Defaults.modifiers, options.modifiers)).forEach(function (name) {
2556 _this.options.modifiers[name] = _extends({}, Popper.Defaults.modifiers[name] || {}, options.modifiers ? options.modifiers[name] : {});
2557 });
2558
2559 // Refactoring modifiers' list (Object => Array)
2560 this.modifiers = Object.keys(this.options.modifiers).map(function (name) {
2561 return _extends({
2562 name: name
2563 }, _this.options.modifiers[name]);
2564 })
2565 // sort the modifiers by order
2566 .sort(function (a, b) {
2567 return a.order - b.order;
2568 });
2569
2570 // modifiers have the ability to execute arbitrary code when Popper.js get inited
2571 // such code is executed in the same order of its modifier
2572 // they could add new properties to their options configuration
2573 // BE AWARE: don't add options to `options.modifiers.name` but to `modifierOptions`!
2574 this.modifiers.forEach(function (modifierOptions) {
2575 if (modifierOptions.enabled && isFunction(modifierOptions.onLoad)) {
2576 modifierOptions.onLoad(_this.reference, _this.popper, _this.options, modifierOptions, _this.state);
2577 }
2578 });
2579
2580 // fire the first update to position the popper in the right place
2581 this.update();
2582
2583 var eventsEnabled = this.options.eventsEnabled;
2584 if (eventsEnabled) {
2585 // setup event listeners, they will take care of update the position in specific situations
2586 this.enableEventListeners();
2587 }
2588
2589 this.state.eventsEnabled = eventsEnabled;
2590 }
2591
2592 // We can't use class properties because they don't get listed in the
2593 // class prototype and break stuff like Sinon stubs
2594
2595
2596 createClass(Popper, [{
2597 key: 'update',
2598 value: function update$$1() {
2599 return update.call(this);
2600 }
2601 }, {
2602 key: 'destroy',
2603 value: function destroy$$1() {
2604 return destroy.call(this);
2605 }
2606 }, {
2607 key: 'enableEventListeners',
2608 value: function enableEventListeners$$1() {
2609 return enableEventListeners.call(this);
2610 }
2611 }, {
2612 key: 'disableEventListeners',
2613 value: function disableEventListeners$$1() {
2614 return disableEventListeners.call(this);
2615 }
2616
2617 /**
2618 * Schedules an update. It will run on the next UI update available.
2619 * @method scheduleUpdate
2620 * @memberof Popper
2621 */
2622
2623
2624 /**
2625 * Collection of utilities useful when writing custom modifiers.
2626 * Starting from version 1.7, this method is available only if you
2627 * include `popper-utils.js` before `popper.js`.
2628 *
2629 * **DEPRECATION**: This way to access PopperUtils is deprecated
2630 * and will be removed in v2! Use the PopperUtils module directly instead.
2631 * Due to the high instability of the methods contained in Utils, we can't
2632 * guarantee them to follow semver. Use them at your own risk!
2633 * @static
2634 * @private
2635 * @type {Object}
2636 * @deprecated since version 1.8
2637 * @member Utils
2638 * @memberof Popper
2639 */
2640
2641 }]);
2642 return Popper;
2643}();
2644
2645/**
2646 * The `referenceObject` is an object that provides an interface compatible with Popper.js
2647 * and lets you use it as replacement of a real DOM node.<br />
2648 * You can use this method to position a popper relatively to a set of coordinates
2649 * in case you don't have a DOM node to use as reference.
2650 *
2651 * ```
2652 * new Popper(referenceObject, popperNode);
2653 * ```
2654 *
2655 * NB: This feature isn't supported in Internet Explorer 10.
2656 * @name referenceObject
2657 * @property {Function} data.getBoundingClientRect
2658 * A function that returns a set of coordinates compatible with the native `getBoundingClientRect` method.
2659 * @property {number} data.clientWidth
2660 * An ES6 getter that will return the width of the virtual reference element.
2661 * @property {number} data.clientHeight
2662 * An ES6 getter that will return the height of the virtual reference element.
2663 */
2664
2665
2666Popper.Utils = (typeof window !== 'undefined' ? window : global).PopperUtils;
2667Popper.placements = placements;
2668Popper.Defaults = Defaults;
2669
2670var _ref3;
2671
2672function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
2673
2674function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { defineProperty$1._defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
2675
2676function _createSuper(Derived) { return function () { var Super = getPrototypeOf._getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = getPrototypeOf._getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return getPrototypeOf._possibleConstructorReturn(this, result); }; }
2677
2678function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
2679
2680var _StyledAnimatedDiv = _styled__default(web.extendedAnimated.div).withConfig({
2681 displayName: "Popover___StyledAnimatedDiv",
2682 componentId: "sc-1hohxqp-0"
2683})(["position:absolute;top:0;left:0;"]);
2684
2685var _StyledAnimatedDiv2 = _styled__default(web.extendedAnimated.div).withConfig({
2686 displayName: "Popover___StyledAnimatedDiv2",
2687 componentId: "sc-1hohxqp-1"
2688})(["background:", ";border:1px solid ", ";border-radius:", "px;filter:drop-shadow(0 4px 4px rgba(0,0,0,0.15));&:focus{outline:0;}overflow-y:auto;"], function (p) {
2689 return p._css;
2690}, function (p) {
2691 return p._css2;
2692}, constants.RADIUS);
2693
2694var PopoverBase = /*#__PURE__*/function (_React$Component) {
2695 getPrototypeOf._inherits(PopoverBase, _React$Component);
2696
2697 var _super = _createSuper(PopoverBase);
2698
2699 function PopoverBase() {
2700 var _this;
2701
2702 getPrototypeOf._classCallCheck(this, PopoverBase);
2703
2704 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2705 args[_key] = arguments[_key];
2706 }
2707
2708 _this = _super.call.apply(_super, [this].concat(args));
2709
2710 defineProperty$1._defineProperty(getPrototypeOf._assertThisInitialized(_this), "_cardElement", React__default.createRef());
2711
2712 defineProperty$1._defineProperty(getPrototypeOf._assertThisInitialized(_this), "_popperElement", React__default.createRef());
2713
2714 defineProperty$1._defineProperty(getPrototypeOf._assertThisInitialized(_this), "_document", null);
2715
2716 defineProperty$1._defineProperty(getPrototypeOf._assertThisInitialized(_this), "_popper", null);
2717
2718 defineProperty$1._defineProperty(getPrototypeOf._assertThisInitialized(_this), "handleEscape", function (_ref) {
2719 var keyCode = _ref.keyCode;
2720
2721 if (keyCode === keycodes.KEY_ESC) {
2722 // On escape, we always move the focus back to the opener.
2723 _this.props.opener.focus();
2724
2725 _this.attemptClose();
2726 }
2727 });
2728
2729 defineProperty$1._defineProperty(getPrototypeOf._assertThisInitialized(_this), "handleBlur", function (event) {
2730 var _this$props = _this.props,
2731 closeOnOpenerFocus = _this$props.closeOnOpenerFocus,
2732 opener = _this$props.opener;
2733 var focusedElement = event.relatedTarget; // Do not close if:
2734 // - The blur event is emitted from an element inside of the popover.
2735 // - The focused target is the opener and closeOnOpenerFocus is true.
2736
2737 if (_this._cardElement.current && _this._cardElement.current.contains(focusedElement) || closeOnOpenerFocus && opener && opener.contains(focusedElement)) {
2738 if (closeOnOpenerFocus && (opener.tagName === 'BUTTON' || opener.tagName === 'INPUT')) {
2739 environment.warn('Popover: using "closeOnOpenerFocus" with a <button> or <input> may lead to bugs due ' + 'to cross-environment focus event handling. ' + 'See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus ' + 'for more information.');
2740 }
2741
2742 return;
2743 } // Probably a click outside, that doesn’t focus anything else: move the
2744 // focus back to the opener.
2745
2746
2747 if (!focusedElement) {
2748 opener.focus();
2749 }
2750
2751 _this.attemptClose();
2752 });
2753
2754 return _this;
2755 }
2756
2757 getPrototypeOf._createClass(PopoverBase, [{
2758 key: "componentDidMount",
2759 value: function componentDidMount() {
2760 this._document = this._popperElement.current.ownerDocument;
2761
2762 this._document.addEventListener('keydown', this.handleEscape);
2763
2764 this.focus();
2765 this.initPopper();
2766 }
2767 }, {
2768 key: "componentWillUnmount",
2769 value: function componentWillUnmount() {
2770 this.destroyPopper();
2771
2772 this._document.removeEventListener('keydown', this.handleEscape);
2773
2774 delete this._document;
2775 delete this._popper;
2776 }
2777 }, {
2778 key: "componentDidUpdate",
2779 value: function componentDidUpdate(prevProps, prevState) {
2780 var _this$props2 = this.props,
2781 placement = _this$props2.placement,
2782 children = _this$props2.children,
2783 opener = _this$props2.opener;
2784
2785 if (prevProps.placement !== placement || prevProps.children !== children || prevProps.opener !== opener) {
2786 this.destroyPopper();
2787 this.initPopper();
2788 }
2789 }
2790 }, {
2791 key: "focus",
2792 value: function focus() {
2793 if (this._cardElement.current) {
2794 this._cardElement.current.focus();
2795 }
2796 }
2797 }, {
2798 key: "getPopperSettings",
2799 value: function getPopperSettings() {
2800 var _this$props3 = this.props,
2801 placement = _this$props3.placement,
2802 rootBoundary = _this$props3.rootBoundary;
2803 var settings = {
2804 placement: placement,
2805 modifiers: {
2806 preventOverflow: {
2807 enabled: true,
2808 padding: 10,
2809 boundariesElement: rootBoundary || 'window'
2810 }
2811 },
2812 positionFixed: false
2813 };
2814
2815 if (placement !== 'center') {
2816 return settings;
2817 }
2818
2819 return _objectSpread({}, settings, {
2820 placement: 'top-start',
2821 modifiers: _objectSpread({}, settings.modifiers, {
2822 arrow: {
2823 enabled: false
2824 },
2825 flip: {
2826 enabled: false
2827 },
2828 offset: {
2829 enabled: true,
2830 offset: '50% - 50%p, -50%p - 50%'
2831 }
2832 })
2833 });
2834 }
2835 }, {
2836 key: "initPopper",
2837 value: function initPopper() {
2838 var opener = this.props.opener;
2839
2840 if (!this._popper) {
2841 this._popper = new Popper(opener, this._popperElement.current, this.getPopperSettings());
2842 }
2843 }
2844 }, {
2845 key: "destroyPopper",
2846 value: function destroyPopper() {
2847 if (this._popper) {
2848 this._popper.destroy();
2849
2850 this._popper = null;
2851 }
2852 }
2853 }, {
2854 key: "attemptClose",
2855 value: function attemptClose() {
2856 var accepted = this.props.onClose(); // If closing the popover is not accepted, we need to focus it again so
2857 // that it can react to onBlur events.
2858
2859 if (accepted === false) {
2860 this.focus();
2861 }
2862 }
2863 }, {
2864 key: "boundaryDimensions",
2865 value: function boundaryDimensions() {
2866 var rootBoundary = this.props.rootBoundary;
2867 var hasWindow = typeof window !== 'undefined';
2868 return rootBoundary ? [rootBoundary.clientWidth, rootBoundary.clientHeight] : [hasWindow ? window.innerWidth : 0, hasWindow ? window.innerHeight : 0];
2869 }
2870 }, {
2871 key: "render",
2872 value: function render() {
2873 var _this$props4 = this.props,
2874 children = _this$props4.children,
2875 theme = _this$props4.theme,
2876 transitionStyles = _this$props4.transitionStyles,
2877 zIndex = _this$props4.zIndex;
2878 var scale = transitionStyles.scale,
2879 opacity = transitionStyles.opacity;
2880
2881 var _this$boundaryDimensi = this.boundaryDimensions(),
2882 _this$boundaryDimensi2 = slicedToArray._slicedToArray(_this$boundaryDimensi, 2),
2883 maxWidth = _this$boundaryDimensi2[0],
2884 maxHeight = _this$boundaryDimensi2[1];
2885
2886 return /*#__PURE__*/React__default.createElement(_StyledAnimatedDiv, {
2887 ref: this._popperElement,
2888 style: {
2889 zIndex: zIndex
2890 }
2891 }, /*#__PURE__*/React__default.createElement(_StyledAnimatedDiv2, _extends$1._extends({
2892 tabIndex: "0",
2893 onBlur: this.handleBlur,
2894 ref: this._cardElement,
2895 style: {
2896 opacity: opacity,
2897 transform: scale.interpolate(function (v) {
2898 return "scale3d(".concat(v, ", ").concat(v, ", 1)");
2899 }),
2900 maxHeight: "".concat(maxHeight - 2 * constants.GU, "px"),
2901 maxWidth: "".concat(maxWidth - 2 * constants.GU, "px")
2902 }
2903 }, components.stylingProps(this), {
2904 _css: theme.surface,
2905 _css2: theme.border
2906 }), children));
2907 }
2908 }]);
2909
2910 return PopoverBase;
2911}(React__default.Component);
2912
2913defineProperty$1._defineProperty(PopoverBase, "propTypes", {
2914 children: proptypes.PropTypes.node,
2915 closeOnOpenerFocus: proptypes.PropTypes.bool,
2916 onClose: proptypes.PropTypes.func,
2917 opener: proptypes.PropTypes._element,
2918 placement: proptypes.PropTypes.oneOf( // "center" is a value that doesn’t exist in Popper, but we are using it
2919 // to define custom Popper settings (see getPopperSettings() below).
2920 (_ref3 = ['center']).concat.apply(_ref3, toConsumableArray._toConsumableArray(['auto', 'top', 'right', 'bottom', 'left'].map(function (position) {
2921 return [position, "".concat(position, "-start"), "".concat(position, "-end")];
2922 })))),
2923 rootBoundary: proptypes.PropTypes._element,
2924 theme: proptypes.PropTypes.object,
2925 transitionStyles: proptypes.PropTypes.object,
2926 zIndex: proptypes.PropTypes.number
2927});
2928
2929defineProperty$1._defineProperty(PopoverBase, "defaultProps", {
2930 closeOnOpenerFocus: false,
2931 opener: null,
2932 placement: 'center',
2933 onClose: miscellaneous.noop,
2934 zIndex: 999
2935});
2936
2937function Popover(_ref2) {
2938 var scaleEffect = _ref2.scaleEffect,
2939 visible = _ref2.visible,
2940 props = objectWithoutProperties._objectWithoutProperties(_ref2, ["scaleEffect", "visible"]);
2941
2942 var theme = Theme.useTheme();
2943 var root = index$1$1.useRoot();
2944 return /*#__PURE__*/React__default.createElement(RootPortal.default, null, /*#__PURE__*/React__default.createElement(web.Transition, {
2945 items: visible,
2946 config: springs.springs.swift,
2947 from: {
2948 scale: scaleEffect ? 0.9 : 1,
2949 opacity: 0
2950 },
2951 enter: {
2952 scale: 1,
2953 opacity: 1
2954 },
2955 leave: {
2956 scale: scaleEffect ? 0.9 : 1,
2957 opacity: 0
2958 },
2959 native: true
2960 }, function (visible) {
2961 return visible && function (transitionStyles) {
2962 return /*#__PURE__*/React__default.createElement(PopoverBase, _extends$1._extends({}, props, {
2963 rootBoundary: root,
2964 theme: theme,
2965 transitionStyles: transitionStyles
2966 }));
2967 };
2968 }));
2969}
2970
2971Popover.propTypes = _objectSpread({}, PopoverBase.propTypes, {
2972 scaleEffect: proptypes.PropTypes.bool,
2973 visible: proptypes.PropTypes.bool
2974});
2975Popover.defaultProps = _objectSpread({}, PopoverBase.defaultProps, {
2976 scaleEffect: true,
2977 visible: true
2978});
2979
2980exports.default = Popover;
2981//# sourceMappingURL=Popover.js.map