32
function getStyleComputedProperty(element, property) {
33
if (element.nodeType !== 1) {
37
const window = element.ownerDocument.defaultView;
38
const 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;
78
const { overflow, overflowX, overflowY } = getStyleComputedProperty(element);
79
if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
83
return getScrollParent(getParentNode(element));
93
function getReferenceNode(reference) {
94
return reference && reference.referenceNode ? reference.referenceNode : reference;
97
var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && typeof navigator !== 'undefined';
99
const isIE11 = isBrowser && !!(window.MSInputMethodContext && document.documentMode);
100
const isIE10 = isBrowser && /MSIE 10/.test(navigator.userAgent);
109
function isIE(version) {
110
if (version === 11) {
113
if (version === 10) {
116
return isIE11 || isIE10;
126
function getOffsetParent(element) {
128
return document.documentElement;
131
const noOffsetParent = isIE(10) ? document.body : null;
134
let offsetParent = element.offsetParent || null;
136
while (offsetParent === noOffsetParent && element.nextElementSibling) {
137
offsetParent = (element = element.nextElementSibling).offsetParent;
140
const nodeName = offsetParent && offsetParent.nodeName;
142
if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
143
return element ? element.ownerDocument.documentElement : document.documentElement;
148
if (['TH', 'TD', 'TABLE'].indexOf(offsetParent.nodeName) !== -1 && getStyleComputedProperty(offsetParent, 'position') === 'static') {
149
return getOffsetParent(offsetParent);
155
function isOffsetContainer(element) {
156
const { nodeName } = element;
157
if (nodeName === 'BODY') {
160
return nodeName === 'HTML' || getOffsetParent(element.firstElementChild) === element;
170
function getRoot(node) {
171
if (node.parentNode !== null) {
172
return getRoot(node.parentNode);
186
function findCommonOffsetParent(element1, element2) {
188
if (!element1 || !element1.nodeType || !element2 || !element2.nodeType) {
189
return document.documentElement;
193
const order = element1.compareDocumentPosition(element2) & Node.DOCUMENT_POSITION_FOLLOWING;
194
const start = order ? element1 : element2;
195
const end = order ? element2 : element1;
198
const range = document.createRange();
199
range.setStart(start, 0);
200
range.setEnd(end, 0);
201
const { commonAncestorContainer } = range;
204
if (element1 !== commonAncestorContainer && element2 !== commonAncestorContainer || start.contains(end)) {
205
if (isOffsetContainer(commonAncestorContainer)) {
206
return commonAncestorContainer;
209
return getOffsetParent(commonAncestorContainer);
213
const element1root = getRoot(element1);
214
if (element1root.host) {
215
return findCommonOffsetParent(element1root.host, element2);
217
return findCommonOffsetParent(element1, getRoot(element2).host);
229
function getScroll(element, side = 'top') {
230
const upperSide = side === 'top' ? 'scrollTop' : 'scrollLeft';
231
const nodeName = element.nodeName;
233
if (nodeName === 'BODY' || nodeName === 'HTML') {
234
const html = element.ownerDocument.documentElement;
235
const scrollingElement = element.ownerDocument.scrollingElement || html;
236
return scrollingElement[upperSide];
239
return element[upperSide];
251
function includeScroll(rect, element, subtract = false) {
252
const scrollTop = getScroll(element, 'top');
253
const scrollLeft = getScroll(element, 'left');
254
const modifier = subtract ? -1 : 1;
255
rect.top += scrollTop * modifier;
256
rect.bottom += scrollTop * modifier;
257
rect.left += scrollLeft * modifier;
258
rect.right += scrollLeft * modifier;
272
function getBordersSize(styles, axis) {
273
const sideA = axis === 'x' ? 'Left' : 'Top';
274
const sideB = sideA === 'Left' ? 'Right' : 'Bottom';
276
return parseFloat(styles[`border${sideA}Width`]) + parseFloat(styles[`border${sideB}Width`]);
279
function getSize(axis, body, html, computedStyle) {
280
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);
283
function getWindowSizes(document) {
284
const body = document.body;
285
const html = document.documentElement;
286
const computedStyle = isIE(10) && getComputedStyle(html);
289
height: getSize('Height', body, html, computedStyle),
290
width: getSize('Width', body, html, computedStyle)
294
var _extends = Object.assign || function (target) {
295
for (var i = 1; i < arguments.length; i++) {
296
var source = arguments[i];
298
for (var key in source) {
299
if (Object.prototype.hasOwnProperty.call(source, key)) {
300
target[key] = source[key];
315
function getClientRect(offsets) {
316
return _extends({}, offsets, {
317
right: offsets.left + offsets.width,
318
bottom: offsets.top + offsets.height
329
function getBoundingClientRect(element) {
337
rect = element.getBoundingClientRect();
338
const scrollTop = getScroll(element, 'top');
339
const scrollLeft = getScroll(element, 'left');
340
rect.top += scrollTop;
341
rect.left += scrollLeft;
342
rect.bottom += scrollTop;
343
rect.right += scrollLeft;
345
rect = element.getBoundingClientRect();
352
width: rect.right - rect.left,
353
height: rect.bottom - rect.top
357
const sizes = element.nodeName === 'HTML' ? getWindowSizes(element.ownerDocument) : {};
358
const width = sizes.width || element.clientWidth || result.width;
359
const height = sizes.height || element.clientHeight || result.height;
361
let horizScrollbar = element.offsetWidth - width;
362
let vertScrollbar = element.offsetHeight - height;
366
if (horizScrollbar || vertScrollbar) {
367
const styles = getStyleComputedProperty(element);
368
horizScrollbar -= getBordersSize(styles, 'x');
369
vertScrollbar -= getBordersSize(styles, 'y');
371
result.width -= horizScrollbar;
372
result.height -= vertScrollbar;
375
return getClientRect(result);
378
function getOffsetRectRelativeToArbitraryNode(children, parent, fixedPosition = false) {
379
const isIE10 = isIE(10);
380
const isHTML = parent.nodeName === 'HTML';
381
const childrenRect = getBoundingClientRect(children);
382
const parentRect = getBoundingClientRect(parent);
383
const scrollParent = getScrollParent(children);
385
const styles = getStyleComputedProperty(parent);
386
const borderTopWidth = parseFloat(styles.borderTopWidth);
387
const borderLeftWidth = parseFloat(styles.borderLeftWidth);
390
if (fixedPosition && isHTML) {
391
parentRect.top = Math.max(parentRect.top, 0);
392
parentRect.left = Math.max(parentRect.left, 0);
394
let offsets = getClientRect({
395
top: childrenRect.top - parentRect.top - borderTopWidth,
396
left: childrenRect.left - parentRect.left - borderLeftWidth,
397
width: childrenRect.width,
398
height: childrenRect.height
400
offsets.marginTop = 0;
401
offsets.marginLeft = 0;
407
if (!isIE10 && isHTML) {
408
const marginTop = parseFloat(styles.marginTop);
409
const marginLeft = parseFloat(styles.marginLeft);
411
offsets.top -= borderTopWidth - marginTop;
412
offsets.bottom -= borderTopWidth - marginTop;
413
offsets.left -= borderLeftWidth - marginLeft;
414
offsets.right -= borderLeftWidth - marginLeft;
417
offsets.marginTop = marginTop;
418
offsets.marginLeft = marginLeft;
421
if (isIE10 && !fixedPosition ? parent.contains(scrollParent) : parent === scrollParent && scrollParent.nodeName !== 'BODY') {
422
offsets = includeScroll(offsets, parent);
428
function getViewportOffsetRectRelativeToArtbitraryNode(element, excludeScroll = false) {
429
const html = element.ownerDocument.documentElement;
430
const relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html);
431
const width = Math.max(html.clientWidth, window.innerWidth || 0);
432
const height = Math.max(html.clientHeight, window.innerHeight || 0);
434
const scrollTop = !excludeScroll ? getScroll(html) : 0;
435
const scrollLeft = !excludeScroll ? getScroll(html, 'left') : 0;
438
top: scrollTop - relativeOffset.top + relativeOffset.marginTop,
439
left: scrollLeft - relativeOffset.left + relativeOffset.marginLeft,
444
return getClientRect(offset);
455
function isFixed(element) {
456
const nodeName = element.nodeName;
457
if (nodeName === 'BODY' || nodeName === 'HTML') {
460
if (getStyleComputedProperty(element, 'position') === 'fixed') {
463
const parentNode = getParentNode(element);
467
return isFixed(parentNode);
478
function getFixedPositionOffsetParent(element) {
480
if (!element || !element.parentElement || isIE()) {
481
return document.documentElement;
483
let el = element.parentElement;
484
while (el && getStyleComputedProperty(el, 'transform') === 'none') {
485
el = el.parentElement;
487
return el || document.documentElement;
501
function getBoundaries(popper, reference, padding, boundariesElement, fixedPosition = false) {
504
let boundaries = { top: 0, left: 0 };
505
const offsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, getReferenceNode(reference));
508
if (boundariesElement === 'viewport') {
509
boundaries = getViewportOffsetRectRelativeToArtbitraryNode(offsetParent, fixedPosition);
513
if (boundariesElement === 'scrollParent') {
514
boundariesNode = getScrollParent(getParentNode(reference));
515
if (boundariesNode.nodeName === 'BODY') {
516
boundariesNode = popper.ownerDocument.documentElement;
518
} else if (boundariesElement === 'window') {
519
boundariesNode = popper.ownerDocument.documentElement;
521
boundariesNode = boundariesElement;
524
const offsets = getOffsetRectRelativeToArbitraryNode(boundariesNode, offsetParent, fixedPosition);
527
if (boundariesNode.nodeName === 'HTML' && !isFixed(offsetParent)) {
528
const { height, width } = getWindowSizes(popper.ownerDocument);
529
boundaries.top += offsets.top - offsets.marginTop;
530
boundaries.bottom = height + offsets.top;
531
boundaries.left += offsets.left - offsets.marginLeft;
532
boundaries.right = width + offsets.left;
535
boundaries = offsets;
540
padding = padding || 0;
541
const isPaddingNumber = typeof padding === 'number';
542
boundaries.left += isPaddingNumber ? padding : padding.left || 0;
543
boundaries.top += isPaddingNumber ? padding : padding.top || 0;
544
boundaries.right -= isPaddingNumber ? padding : padding.right || 0;
545
boundaries.bottom -= isPaddingNumber ? padding : padding.bottom || 0;
550
function getArea({ width, height }) {
551
return width * height;
563
function computeAutoPlacement(placement, refRect, popper, reference, boundariesElement, padding = 0) {
564
if (placement.indexOf('auto') === -1) {
568
const boundaries = getBoundaries(popper, reference, padding, boundariesElement);
572
width: boundaries.width,
573
height: refRect.top - boundaries.top
576
width: boundaries.right - refRect.right,
577
height: boundaries.height
580
width: boundaries.width,
581
height: boundaries.bottom - refRect.bottom
584
width: refRect.left - boundaries.left,
585
height: boundaries.height
589
const sortedAreas = Object.keys(rects).map(key => _extends({
592
area: getArea(rects[key])
593
})).sort((a, b) => b.area - a.area);
595
const filteredAreas = sortedAreas.filter(({ width, height }) => width >= popper.clientWidth && height >= popper.clientHeight);
597
const computedPlacement = filteredAreas.length > 0 ? filteredAreas[0].key : sortedAreas[0].key;
599
const variation = placement.split('-')[1];
601
return computedPlacement + (variation ? `-${variation}` : '');
604
const timeoutDuration = function () {
605
const longerTimeoutBrowsers = ['Edge', 'Trident', 'Firefox'];
606
for (let i = 0; i < longerTimeoutBrowsers.length; i += 1) {
607
if (isBrowser && navigator.userAgent.indexOf(longerTimeoutBrowsers[i]) >= 0) {
614
function microtaskDebounce(fn) {
621
window.Promise.resolve().then(() => {
628
function taskDebounce(fn) {
629
let scheduled = false;
641
const supportsMicroTasks = isBrowser && window.Promise;
652
var debounce = supportsMicroTasks ? microtaskDebounce : taskDebounce;
663
function find(arr, check) {
665
if (Array.prototype.find) {
666
return arr.find(check);
670
return arr.filter(check)[0];
682
function findIndex(arr, prop, value) {
684
if (Array.prototype.findIndex) {
685
return arr.findIndex(cur => cur[prop] === value);
689
const match = find(arr, obj => obj[prop] === value);
690
return arr.indexOf(match);
700
function getOffsetRect(element) {
702
if (element.nodeName === 'HTML') {
703
const { width, height } = getWindowSizes(element.ownerDocument);
712
width: element.offsetWidth,
713
height: element.offsetHeight,
714
left: element.offsetLeft,
715
top: element.offsetTop
720
return getClientRect(elementRect);
730
function getOuterSizes(element) {
731
const window = element.ownerDocument.defaultView;
732
const styles = window.getComputedStyle(element);
733
const x = parseFloat(styles.marginTop || 0) + parseFloat(styles.marginBottom || 0);
734
const y = parseFloat(styles.marginLeft || 0) + parseFloat(styles.marginRight || 0);
736
width: element.offsetWidth + y,
737
height: element.offsetHeight + x
749
function getOppositePlacement(placement) {
750
const hash = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' };
751
return placement.replace(/left|right|bottom|top/g, matched => hash[matched]);
764
function getPopperOffsets(popper, referenceOffsets, placement) {
765
placement = placement.split('-')[0];
768
const popperRect = getOuterSizes(popper);
771
const popperOffsets = {
772
width: popperRect.width,
773
height: popperRect.height
777
const isHoriz = ['right', 'left'].indexOf(placement) !== -1;
778
const mainSide = isHoriz ? 'top' : 'left';
779
const secondarySide = isHoriz ? 'left' : 'top';
780
const measurement = isHoriz ? 'height' : 'width';
781
const secondaryMeasurement = !isHoriz ? 'height' : 'width';
783
popperOffsets[mainSide] = referenceOffsets[mainSide] + referenceOffsets[measurement] / 2 - popperRect[measurement] / 2;
784
if (placement === secondarySide) {
785
popperOffsets[secondarySide] = referenceOffsets[secondarySide] - popperRect[secondaryMeasurement];
787
popperOffsets[secondarySide] = referenceOffsets[getOppositePlacement(secondarySide)];
790
return popperOffsets;
803
function getReferenceOffsets(state, popper, reference, fixedPosition = null) {
804
const commonOffsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, getReferenceNode(reference));
805
return getOffsetRectRelativeToArbitraryNode(reference, commonOffsetParent, fixedPosition);
815
function getSupportedPropertyName(property) {
816
const prefixes = [false, 'ms', 'Webkit', 'Moz', 'O'];
817
const upperProp = property.charAt(0).toUpperCase() + property.slice(1);
819
for (let i = 0; i < prefixes.length; i++) {
820
const prefix = prefixes[i];
821
const toCheck = prefix ? `${prefix}${upperProp}` : property;
822
if (typeof document.body.style[toCheck] !== 'undefined') {
836
function isFunction(functionToCheck) {
838
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
847
function isModifierEnabled(modifiers, modifierName) {
848
return modifiers.some(({ name, enabled }) => enabled && name === modifierName);
861
function isModifierRequired(modifiers, requestingName, requestedName) {
862
const requesting = find(modifiers, ({ name }) => name === requestingName);
864
const isRequired = !!requesting && modifiers.some(modifier => {
865
return modifier.name === requestedName && modifier.enabled && modifier.order < requesting.order;
869
const requesting = `\`${requestingName}\``;
870
const requested = `\`${requestedName}\``;
871
console.warn(`${requested} modifier is required by ${requesting} modifier in order to work, be sure to include it before ${requesting}!`);
883
function isNumeric(n) {
884
return n !== '' && !isNaN(parseFloat(n)) && isFinite(n);
892
function getWindow(element) {
893
const ownerDocument = element.ownerDocument;
894
return ownerDocument ? ownerDocument.defaultView : window;
903
function removeEventListeners(reference, state) {
905
getWindow(reference).removeEventListener('resize', state.updateBound);
908
state.scrollParents.forEach(target => {
909
target.removeEventListener('scroll', state.updateBound);
913
state.updateBound = null;
914
state.scrollParents = [];
915
state.scrollElement = null;
916
state.eventsEnabled = false;
930
function runModifiers(modifiers, data, ends) {
931
const modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex(modifiers, 'name', ends));
933
modifiersToRun.forEach(modifier => {
934
if (modifier['function']) {
936
console.warn('`modifier.function` is deprecated, use `modifier.fn`!');
938
const fn = modifier['function'] || modifier.fn;
939
if (modifier.enabled && isFunction(fn)) {
943
data.offsets.popper = getClientRect(data.offsets.popper);
944
data.offsets.reference = getClientRect(data.offsets.reference);
946
data = fn(data, modifier);
961
function setAttributes(element, attributes) {
962
Object.keys(attributes).forEach(function (prop) {
963
const value = attributes[prop];
964
if (value !== false) {
965
element.setAttribute(prop, attributes[prop]);
967
element.removeAttribute(prop);
980
function setStyles(element, styles) {
981
Object.keys(styles).forEach(prop => {
984
if (['width', 'height', 'top', 'right', 'bottom', 'left'].indexOf(prop) !== -1 && isNumeric(styles[prop])) {
987
element.style[prop] = styles[prop] + unit;
991
function attachToScrollParents(scrollParent, event, callback, scrollParents) {
992
const isBody = scrollParent.nodeName === 'BODY';
993
const target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent;
994
target.addEventListener(event, callback, { passive: true });
997
attachToScrollParents(getScrollParent(target.parentNode), event, callback, scrollParents);
999
scrollParents.push(target);
1008
function setupEventListeners(reference, options, state, updateBound) {
1010
state.updateBound = updateBound;
1011
getWindow(reference).addEventListener('resize', state.updateBound, { passive: true });
1014
const scrollElement = getScrollParent(reference);
1015
attachToScrollParents(scrollElement, 'scroll', state.updateBound, state.scrollParents);
1016
state.scrollElement = scrollElement;
1017
state.eventsEnabled = true;
1029
computeAutoPlacement,
1034
getBoundingClientRect,
1038
getOffsetRectRelativeToArbitraryNode,
1042
getReferenceOffsets,
1045
getStyleComputedProperty,
1046
getSupportedPropertyName,
1053
removeEventListeners,
1060
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 };
1061
export default index;