32
function getStyleComputedProperty(element, property) {
33
if (element.nodeType !== 1) {
37
var window = element.ownerDocument.defaultView;
38
var css = window.getComputedStyle(element, null);
39
return property ? css[property] : css;
49
function getParentNode(element) {
50
if (element.nodeName === 'HTML') {
53
return element.parentNode || element.host;
63
function getScrollParent(element) {
69
switch (element.nodeName) {
72
return element.ownerDocument.body;
79
var _getStyleComputedProp = getStyleComputedProperty(element),
80
overflow = _getStyleComputedProp.overflow,
81
overflowX = _getStyleComputedProp.overflowX,
82
overflowY = _getStyleComputedProp.overflowY;
84
if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
88
return getScrollParent(getParentNode(element));
98
function getReferenceNode(reference) {
99
return reference && reference.referenceNode ? reference.referenceNode : reference;
102
var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && typeof navigator !== 'undefined';
104
var isIE11 = isBrowser && !!(window.MSInputMethodContext && document.documentMode);
105
var isIE10 = isBrowser && /MSIE 10/.test(navigator.userAgent);
114
function isIE(version) {
115
if (version === 11) {
118
if (version === 10) {
121
return isIE11 || isIE10;
131
function getOffsetParent(element) {
133
return document.documentElement;
136
var noOffsetParent = isIE(10) ? document.body : null;
139
var offsetParent = element.offsetParent || null;
141
while (offsetParent === noOffsetParent && element.nextElementSibling) {
142
offsetParent = (element = element.nextElementSibling).offsetParent;
145
var nodeName = offsetParent && offsetParent.nodeName;
147
if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
148
return element ? element.ownerDocument.documentElement : document.documentElement;
153
if (['TH', 'TD', 'TABLE'].indexOf(offsetParent.nodeName) !== -1 && getStyleComputedProperty(offsetParent, 'position') === 'static') {
154
return getOffsetParent(offsetParent);
160
function isOffsetContainer(element) {
161
var nodeName = element.nodeName;
163
if (nodeName === 'BODY') {
166
return nodeName === 'HTML' || getOffsetParent(element.firstElementChild) === element;
176
function getRoot(node) {
177
if (node.parentNode !== null) {
178
return getRoot(node.parentNode);
192
function findCommonOffsetParent(element1, element2) {
194
if (!element1 || !element1.nodeType || !element2 || !element2.nodeType) {
195
return document.documentElement;
199
var order = element1.compareDocumentPosition(element2) & Node.DOCUMENT_POSITION_FOLLOWING;
200
var start = order ? element1 : element2;
201
var end = order ? element2 : element1;
204
var range = document.createRange();
205
range.setStart(start, 0);
206
range.setEnd(end, 0);
207
var commonAncestorContainer = range.commonAncestorContainer;
211
if (element1 !== commonAncestorContainer && element2 !== commonAncestorContainer || start.contains(end)) {
212
if (isOffsetContainer(commonAncestorContainer)) {
213
return commonAncestorContainer;
216
return getOffsetParent(commonAncestorContainer);
220
var element1root = getRoot(element1);
221
if (element1root.host) {
222
return findCommonOffsetParent(element1root.host, element2);
224
return findCommonOffsetParent(element1, getRoot(element2).host);
236
function getScroll(element) {
237
var side = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'top';
239
var upperSide = side === 'top' ? 'scrollTop' : 'scrollLeft';
240
var nodeName = element.nodeName;
242
if (nodeName === 'BODY' || nodeName === 'HTML') {
243
var html = element.ownerDocument.documentElement;
244
var scrollingElement = element.ownerDocument.scrollingElement || html;
245
return scrollingElement[upperSide];
248
return element[upperSide];
260
function includeScroll(rect, element) {
261
var subtract = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
263
var scrollTop = getScroll(element, 'top');
264
var scrollLeft = getScroll(element, 'left');
265
var modifier = subtract ? -1 : 1;
266
rect.top += scrollTop * modifier;
267
rect.bottom += scrollTop * modifier;
268
rect.left += scrollLeft * modifier;
269
rect.right += scrollLeft * modifier;
283
function getBordersSize(styles, axis) {
284
var sideA = axis === 'x' ? 'Left' : 'Top';
285
var sideB = sideA === 'Left' ? 'Right' : 'Bottom';
287
return parseFloat(styles['border' + sideA + 'Width']) + parseFloat(styles['border' + sideB + 'Width']);
290
function getSize(axis, body, html, computedStyle) {
291
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);
294
function getWindowSizes(document) {
295
var body = document.body;
296
var html = document.documentElement;
297
var computedStyle = isIE(10) && getComputedStyle(html);
300
height: getSize('Height', body, html, computedStyle),
301
width: getSize('Width', body, html, computedStyle)
305
var _extends = Object.assign || function (target) {
306
for (var i = 1; i < arguments.length; i++) {
307
var source = arguments[i];
309
for (var key in source) {
310
if (Object.prototype.hasOwnProperty.call(source, key)) {
311
target[key] = source[key];
326
function getClientRect(offsets) {
327
return _extends({}, offsets, {
328
right: offsets.left + offsets.width,
329
bottom: offsets.top + offsets.height
340
function getBoundingClientRect(element) {
348
rect = element.getBoundingClientRect();
349
var scrollTop = getScroll(element, 'top');
350
var scrollLeft = getScroll(element, 'left');
351
rect.top += scrollTop;
352
rect.left += scrollLeft;
353
rect.bottom += scrollTop;
354
rect.right += scrollLeft;
356
rect = element.getBoundingClientRect();
363
width: rect.right - rect.left,
364
height: rect.bottom - rect.top
368
var sizes = element.nodeName === 'HTML' ? getWindowSizes(element.ownerDocument) : {};
369
var width = sizes.width || element.clientWidth || result.width;
370
var height = sizes.height || element.clientHeight || result.height;
372
var horizScrollbar = element.offsetWidth - width;
373
var vertScrollbar = element.offsetHeight - height;
377
if (horizScrollbar || vertScrollbar) {
378
var styles = getStyleComputedProperty(element);
379
horizScrollbar -= getBordersSize(styles, 'x');
380
vertScrollbar -= getBordersSize(styles, 'y');
382
result.width -= horizScrollbar;
383
result.height -= vertScrollbar;
386
return getClientRect(result);
389
function getOffsetRectRelativeToArbitraryNode(children, parent) {
390
var fixedPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
392
var isIE10 = isIE(10);
393
var isHTML = parent.nodeName === 'HTML';
394
var childrenRect = getBoundingClientRect(children);
395
var parentRect = getBoundingClientRect(parent);
396
var scrollParent = getScrollParent(children);
398
var styles = getStyleComputedProperty(parent);
399
var borderTopWidth = parseFloat(styles.borderTopWidth);
400
var borderLeftWidth = parseFloat(styles.borderLeftWidth);
403
if (fixedPosition && isHTML) {
404
parentRect.top = Math.max(parentRect.top, 0);
405
parentRect.left = Math.max(parentRect.left, 0);
407
var offsets = getClientRect({
408
top: childrenRect.top - parentRect.top - borderTopWidth,
409
left: childrenRect.left - parentRect.left - borderLeftWidth,
410
width: childrenRect.width,
411
height: childrenRect.height
413
offsets.marginTop = 0;
414
offsets.marginLeft = 0;
420
if (!isIE10 && isHTML) {
421
var marginTop = parseFloat(styles.marginTop);
422
var marginLeft = parseFloat(styles.marginLeft);
424
offsets.top -= borderTopWidth - marginTop;
425
offsets.bottom -= borderTopWidth - marginTop;
426
offsets.left -= borderLeftWidth - marginLeft;
427
offsets.right -= borderLeftWidth - marginLeft;
430
offsets.marginTop = marginTop;
431
offsets.marginLeft = marginLeft;
434
if (isIE10 && !fixedPosition ? parent.contains(scrollParent) : parent === scrollParent && scrollParent.nodeName !== 'BODY') {
435
offsets = includeScroll(offsets, parent);
441
function getViewportOffsetRectRelativeToArtbitraryNode(element) {
442
var excludeScroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
444
var html = element.ownerDocument.documentElement;
445
var relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html);
446
var width = Math.max(html.clientWidth, window.innerWidth || 0);
447
var height = Math.max(html.clientHeight, window.innerHeight || 0);
449
var scrollTop = !excludeScroll ? getScroll(html) : 0;
450
var scrollLeft = !excludeScroll ? getScroll(html, 'left') : 0;
453
top: scrollTop - relativeOffset.top + relativeOffset.marginTop,
454
left: scrollLeft - relativeOffset.left + relativeOffset.marginLeft,
459
return getClientRect(offset);
470
function isFixed(element) {
471
var nodeName = element.nodeName;
472
if (nodeName === 'BODY' || nodeName === 'HTML') {
475
if (getStyleComputedProperty(element, 'position') === 'fixed') {
478
var parentNode = getParentNode(element);
482
return isFixed(parentNode);
493
function getFixedPositionOffsetParent(element) {
495
if (!element || !element.parentElement || isIE()) {
496
return document.documentElement;
498
var el = element.parentElement;
499
while (el && getStyleComputedProperty(el, 'transform') === 'none') {
500
el = el.parentElement;
502
return el || document.documentElement;
516
function getBoundaries(popper, reference, padding, boundariesElement) {
517
var fixedPosition = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
521
var boundaries = { top: 0, left: 0 };
522
var offsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, getReferenceNode(reference));
525
if (boundariesElement === 'viewport') {
526
boundaries = getViewportOffsetRectRelativeToArtbitraryNode(offsetParent, fixedPosition);
529
var boundariesNode = void 0;
530
if (boundariesElement === 'scrollParent') {
531
boundariesNode = getScrollParent(getParentNode(reference));
532
if (boundariesNode.nodeName === 'BODY') {
533
boundariesNode = popper.ownerDocument.documentElement;
535
} else if (boundariesElement === 'window') {
536
boundariesNode = popper.ownerDocument.documentElement;
538
boundariesNode = boundariesElement;
541
var offsets = getOffsetRectRelativeToArbitraryNode(boundariesNode, offsetParent, fixedPosition);
544
if (boundariesNode.nodeName === 'HTML' && !isFixed(offsetParent)) {
545
var _getWindowSizes = getWindowSizes(popper.ownerDocument),
546
height = _getWindowSizes.height,
547
width = _getWindowSizes.width;
549
boundaries.top += offsets.top - offsets.marginTop;
550
boundaries.bottom = height + offsets.top;
551
boundaries.left += offsets.left - offsets.marginLeft;
552
boundaries.right = width + offsets.left;
555
boundaries = offsets;
560
padding = padding || 0;
561
var isPaddingNumber = typeof padding === 'number';
562
boundaries.left += isPaddingNumber ? padding : padding.left || 0;
563
boundaries.top += isPaddingNumber ? padding : padding.top || 0;
564
boundaries.right -= isPaddingNumber ? padding : padding.right || 0;
565
boundaries.bottom -= isPaddingNumber ? padding : padding.bottom || 0;
570
function getArea(_ref) {
571
var width = _ref.width,
572
height = _ref.height;
574
return width * height;
586
function computeAutoPlacement(placement, refRect, popper, reference, boundariesElement) {
587
var padding = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
589
if (placement.indexOf('auto') === -1) {
593
var boundaries = getBoundaries(popper, reference, padding, boundariesElement);
597
width: boundaries.width,
598
height: refRect.top - boundaries.top
601
width: boundaries.right - refRect.right,
602
height: boundaries.height
605
width: boundaries.width,
606
height: boundaries.bottom - refRect.bottom
609
width: refRect.left - boundaries.left,
610
height: boundaries.height
614
var sortedAreas = Object.keys(rects).map(function (key) {
618
area: getArea(rects[key])
620
}).sort(function (a, b) {
621
return b.area - a.area;
624
var filteredAreas = sortedAreas.filter(function (_ref2) {
625
var width = _ref2.width,
626
height = _ref2.height;
627
return width >= popper.clientWidth && height >= popper.clientHeight;
630
var computedPlacement = filteredAreas.length > 0 ? filteredAreas[0].key : sortedAreas[0].key;
632
var variation = placement.split('-')[1];
634
return computedPlacement + (variation ? '-' + variation : '');
637
var timeoutDuration = function () {
638
var longerTimeoutBrowsers = ['Edge', 'Trident', 'Firefox'];
639
for (var i = 0; i < longerTimeoutBrowsers.length; i += 1) {
640
if (isBrowser && navigator.userAgent.indexOf(longerTimeoutBrowsers[i]) >= 0) {
647
function microtaskDebounce(fn) {
654
window.Promise.resolve().then(function () {
661
function taskDebounce(fn) {
662
var scheduled = false;
666
setTimeout(function () {
674
var supportsMicroTasks = isBrowser && window.Promise;
685
var debounce = supportsMicroTasks ? microtaskDebounce : taskDebounce;
696
function find(arr, check) {
698
if (Array.prototype.find) {
699
return arr.find(check);
703
return arr.filter(check)[0];
715
function findIndex(arr, prop, value) {
717
if (Array.prototype.findIndex) {
718
return arr.findIndex(function (cur) {
719
return cur[prop] === value;
724
var match = find(arr, function (obj) {
725
return obj[prop] === value;
727
return arr.indexOf(match);
737
function getOffsetRect(element) {
738
var elementRect = void 0;
739
if (element.nodeName === 'HTML') {
740
var _getWindowSizes = getWindowSizes(element.ownerDocument),
741
width = _getWindowSizes.width,
742
height = _getWindowSizes.height;
752
width: element.offsetWidth,
753
height: element.offsetHeight,
754
left: element.offsetLeft,
755
top: element.offsetTop
760
return getClientRect(elementRect);
770
function getOuterSizes(element) {
771
var window = element.ownerDocument.defaultView;
772
var styles = window.getComputedStyle(element);
773
var x = parseFloat(styles.marginTop || 0) + parseFloat(styles.marginBottom || 0);
774
var y = parseFloat(styles.marginLeft || 0) + parseFloat(styles.marginRight || 0);
776
width: element.offsetWidth + y,
777
height: element.offsetHeight + x
789
function getOppositePlacement(placement) {
790
var hash = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' };
791
return placement.replace(/left|right|bottom|top/g, function (matched) {
792
return hash[matched];
806
function getPopperOffsets(popper, referenceOffsets, placement) {
807
placement = placement.split('-')[0];
810
var popperRect = getOuterSizes(popper);
813
var popperOffsets = {
814
width: popperRect.width,
815
height: popperRect.height
819
var isHoriz = ['right', 'left'].indexOf(placement) !== -1;
820
var mainSide = isHoriz ? 'top' : 'left';
821
var secondarySide = isHoriz ? 'left' : 'top';
822
var measurement = isHoriz ? 'height' : 'width';
823
var secondaryMeasurement = !isHoriz ? 'height' : 'width';
825
popperOffsets[mainSide] = referenceOffsets[mainSide] + referenceOffsets[measurement] / 2 - popperRect[measurement] / 2;
826
if (placement === secondarySide) {
827
popperOffsets[secondarySide] = referenceOffsets[secondarySide] - popperRect[secondaryMeasurement];
829
popperOffsets[secondarySide] = referenceOffsets[getOppositePlacement(secondarySide)];
832
return popperOffsets;
845
function getReferenceOffsets(state, popper, reference) {
846
var fixedPosition = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
848
var commonOffsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, getReferenceNode(reference));
849
return getOffsetRectRelativeToArbitraryNode(reference, commonOffsetParent, fixedPosition);
859
function getSupportedPropertyName(property) {
860
var prefixes = [false, 'ms', 'Webkit', 'Moz', 'O'];
861
var upperProp = property.charAt(0).toUpperCase() + property.slice(1);
863
for (var i = 0; i < prefixes.length; i++) {
864
var prefix = prefixes[i];
865
var toCheck = prefix ? '' + prefix + upperProp : property;
866
if (typeof document.body.style[toCheck] !== 'undefined') {
880
function isFunction(functionToCheck) {
882
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
891
function isModifierEnabled(modifiers, modifierName) {
892
return modifiers.some(function (_ref) {
893
var name = _ref.name,
894
enabled = _ref.enabled;
895
return enabled && name === modifierName;
909
function isModifierRequired(modifiers, requestingName, requestedName) {
910
var requesting = find(modifiers, function (_ref) {
911
var name = _ref.name;
912
return name === requestingName;
915
var isRequired = !!requesting && modifiers.some(function (modifier) {
916
return modifier.name === requestedName && modifier.enabled && modifier.order < requesting.order;
920
var _requesting = '`' + requestingName + '`';
921
var requested = '`' + requestedName + '`';
922
console.warn(requested + ' modifier is required by ' + _requesting + ' modifier in order to work, be sure to include it before ' + _requesting + '!');
934
function isNumeric(n) {
935
return n !== '' && !isNaN(parseFloat(n)) && isFinite(n);
943
function getWindow(element) {
944
var ownerDocument = element.ownerDocument;
945
return ownerDocument ? ownerDocument.defaultView : window;
954
function removeEventListeners(reference, state) {
956
getWindow(reference).removeEventListener('resize', state.updateBound);
959
state.scrollParents.forEach(function (target) {
960
target.removeEventListener('scroll', state.updateBound);
964
state.updateBound = null;
965
state.scrollParents = [];
966
state.scrollElement = null;
967
state.eventsEnabled = false;
981
function runModifiers(modifiers, data, ends) {
982
var modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex(modifiers, 'name', ends));
984
modifiersToRun.forEach(function (modifier) {
985
if (modifier['function']) {
987
console.warn('`modifier.function` is deprecated, use `modifier.fn`!');
989
var fn = modifier['function'] || modifier.fn;
990
if (modifier.enabled && isFunction(fn)) {
994
data.offsets.popper = getClientRect(data.offsets.popper);
995
data.offsets.reference = getClientRect(data.offsets.reference);
997
data = fn(data, modifier);
1012
function setAttributes(element, attributes) {
1013
Object.keys(attributes).forEach(function (prop) {
1014
var value = attributes[prop];
1015
if (value !== false) {
1016
element.setAttribute(prop, attributes[prop]);
1018
element.removeAttribute(prop);
1031
function setStyles(element, styles) {
1032
Object.keys(styles).forEach(function (prop) {
1035
if (['width', 'height', 'top', 'right', 'bottom', 'left'].indexOf(prop) !== -1 && isNumeric(styles[prop])) {
1038
element.style[prop] = styles[prop] + unit;
1042
function attachToScrollParents(scrollParent, event, callback, scrollParents) {
1043
var isBody = scrollParent.nodeName === 'BODY';
1044
var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent;
1045
target.addEventListener(event, callback, { passive: true });
1048
attachToScrollParents(getScrollParent(target.parentNode), event, callback, scrollParents);
1050
scrollParents.push(target);
1059
function setupEventListeners(reference, options, state, updateBound) {
1061
state.updateBound = updateBound;
1062
getWindow(reference).addEventListener('resize', state.updateBound, { passive: true });
1065
var scrollElement = getScrollParent(reference);
1066
attachToScrollParents(scrollElement, 'scroll', state.updateBound, state.scrollParents);
1067
state.scrollElement = scrollElement;
1068
state.eventsEnabled = true;
1080
computeAutoPlacement: computeAutoPlacement,
1082
findIndex: findIndex,
1083
getBordersSize: getBordersSize,
1084
getBoundaries: getBoundaries,
1085
getBoundingClientRect: getBoundingClientRect,
1086
getClientRect: getClientRect,
1087
getOffsetParent: getOffsetParent,
1088
getOffsetRect: getOffsetRect,
1089
getOffsetRectRelativeToArbitraryNode: getOffsetRectRelativeToArbitraryNode,
1090
getOuterSizes: getOuterSizes,
1091
getParentNode: getParentNode,
1092
getPopperOffsets: getPopperOffsets,
1093
getReferenceOffsets: getReferenceOffsets,
1094
getScroll: getScroll,
1095
getScrollParent: getScrollParent,
1096
getStyleComputedProperty: getStyleComputedProperty,
1097
getSupportedPropertyName: getSupportedPropertyName,
1098
getWindowSizes: getWindowSizes,
1100
isFunction: isFunction,
1101
isModifierEnabled: isModifierEnabled,
1102
isModifierRequired: isModifierRequired,
1103
isNumeric: isNumeric,
1104
removeEventListeners: removeEventListeners,
1105
runModifiers: runModifiers,
1106
setAttributes: setAttributes,
1107
setStyles: setStyles,
1108
setupEventListeners: setupEventListeners
1111
export { computeAutoPlacement, debounce, findIndex, getBordersSize, getBoundaries, getBoundingClientRect, getClientRect, getOffsetParent, getOffsetRect, getOffsetRectRelativeToArbitraryNode, getOuterSizes, getParentNode, getPopperOffsets, getReferenceOffsets, getScroll, getScrollParent, getStyleComputedProperty, getSupportedPropertyName, getWindowSizes, isFixed, isFunction, isModifierEnabled, isModifierRequired, isNumeric, removeEventListeners, runModifiers, setAttributes, setStyles, setupEventListeners };
1112
export default index;