source: imaps-frontend/node_modules/@popperjs/core/dist/cjs/popper-base.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 29.8 KB
Line 
1/**
2 * @popperjs/core v2.11.8 - MIT License
3 */
4
5'use strict';
6
7Object.defineProperty(exports, '__esModule', { value: true });
8
9function getWindow(node) {
10 if (node == null) {
11 return window;
12 }
13
14 if (node.toString() !== '[object Window]') {
15 var ownerDocument = node.ownerDocument;
16 return ownerDocument ? ownerDocument.defaultView || window : window;
17 }
18
19 return node;
20}
21
22function isElement(node) {
23 var OwnElement = getWindow(node).Element;
24 return node instanceof OwnElement || node instanceof Element;
25}
26
27function isHTMLElement(node) {
28 var OwnElement = getWindow(node).HTMLElement;
29 return node instanceof OwnElement || node instanceof HTMLElement;
30}
31
32function isShadowRoot(node) {
33 // IE 11 has no ShadowRoot
34 if (typeof ShadowRoot === 'undefined') {
35 return false;
36 }
37
38 var OwnElement = getWindow(node).ShadowRoot;
39 return node instanceof OwnElement || node instanceof ShadowRoot;
40}
41
42var max = Math.max;
43var min = Math.min;
44var round = Math.round;
45
46function getUAString() {
47 var uaData = navigator.userAgentData;
48
49 if (uaData != null && uaData.brands && Array.isArray(uaData.brands)) {
50 return uaData.brands.map(function (item) {
51 return item.brand + "/" + item.version;
52 }).join(' ');
53 }
54
55 return navigator.userAgent;
56}
57
58function isLayoutViewport() {
59 return !/^((?!chrome|android).)*safari/i.test(getUAString());
60}
61
62function getBoundingClientRect(element, includeScale, isFixedStrategy) {
63 if (includeScale === void 0) {
64 includeScale = false;
65 }
66
67 if (isFixedStrategy === void 0) {
68 isFixedStrategy = false;
69 }
70
71 var clientRect = element.getBoundingClientRect();
72 var scaleX = 1;
73 var scaleY = 1;
74
75 if (includeScale && isHTMLElement(element)) {
76 scaleX = element.offsetWidth > 0 ? round(clientRect.width) / element.offsetWidth || 1 : 1;
77 scaleY = element.offsetHeight > 0 ? round(clientRect.height) / element.offsetHeight || 1 : 1;
78 }
79
80 var _ref = isElement(element) ? getWindow(element) : window,
81 visualViewport = _ref.visualViewport;
82
83 var addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
84 var x = (clientRect.left + (addVisualOffsets && visualViewport ? visualViewport.offsetLeft : 0)) / scaleX;
85 var y = (clientRect.top + (addVisualOffsets && visualViewport ? visualViewport.offsetTop : 0)) / scaleY;
86 var width = clientRect.width / scaleX;
87 var height = clientRect.height / scaleY;
88 return {
89 width: width,
90 height: height,
91 top: y,
92 right: x + width,
93 bottom: y + height,
94 left: x,
95 x: x,
96 y: y
97 };
98}
99
100function getWindowScroll(node) {
101 var win = getWindow(node);
102 var scrollLeft = win.pageXOffset;
103 var scrollTop = win.pageYOffset;
104 return {
105 scrollLeft: scrollLeft,
106 scrollTop: scrollTop
107 };
108}
109
110function getHTMLElementScroll(element) {
111 return {
112 scrollLeft: element.scrollLeft,
113 scrollTop: element.scrollTop
114 };
115}
116
117function getNodeScroll(node) {
118 if (node === getWindow(node) || !isHTMLElement(node)) {
119 return getWindowScroll(node);
120 } else {
121 return getHTMLElementScroll(node);
122 }
123}
124
125function getNodeName(element) {
126 return element ? (element.nodeName || '').toLowerCase() : null;
127}
128
129function getDocumentElement(element) {
130 // $FlowFixMe[incompatible-return]: assume body is always available
131 return ((isElement(element) ? element.ownerDocument : // $FlowFixMe[prop-missing]
132 element.document) || window.document).documentElement;
133}
134
135function getWindowScrollBarX(element) {
136 // If <html> has a CSS width greater than the viewport, then this will be
137 // incorrect for RTL.
138 // Popper 1 is broken in this case and never had a bug report so let's assume
139 // it's not an issue. I don't think anyone ever specifies width on <html>
140 // anyway.
141 // Browsers where the left scrollbar doesn't cause an issue report `0` for
142 // this (e.g. Edge 2019, IE11, Safari)
143 return getBoundingClientRect(getDocumentElement(element)).left + getWindowScroll(element).scrollLeft;
144}
145
146function getComputedStyle(element) {
147 return getWindow(element).getComputedStyle(element);
148}
149
150function isScrollParent(element) {
151 // Firefox wants us to check `-x` and `-y` variations as well
152 var _getComputedStyle = getComputedStyle(element),
153 overflow = _getComputedStyle.overflow,
154 overflowX = _getComputedStyle.overflowX,
155 overflowY = _getComputedStyle.overflowY;
156
157 return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
158}
159
160function isElementScaled(element) {
161 var rect = element.getBoundingClientRect();
162 var scaleX = round(rect.width) / element.offsetWidth || 1;
163 var scaleY = round(rect.height) / element.offsetHeight || 1;
164 return scaleX !== 1 || scaleY !== 1;
165} // Returns the composite rect of an element relative to its offsetParent.
166// Composite means it takes into account transforms as well as layout.
167
168
169function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
170 if (isFixed === void 0) {
171 isFixed = false;
172 }
173
174 var isOffsetParentAnElement = isHTMLElement(offsetParent);
175 var offsetParentIsScaled = isHTMLElement(offsetParent) && isElementScaled(offsetParent);
176 var documentElement = getDocumentElement(offsetParent);
177 var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled, isFixed);
178 var scroll = {
179 scrollLeft: 0,
180 scrollTop: 0
181 };
182 var offsets = {
183 x: 0,
184 y: 0
185 };
186
187 if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
188 if (getNodeName(offsetParent) !== 'body' || // https://github.com/popperjs/popper-core/issues/1078
189 isScrollParent(documentElement)) {
190 scroll = getNodeScroll(offsetParent);
191 }
192
193 if (isHTMLElement(offsetParent)) {
194 offsets = getBoundingClientRect(offsetParent, true);
195 offsets.x += offsetParent.clientLeft;
196 offsets.y += offsetParent.clientTop;
197 } else if (documentElement) {
198 offsets.x = getWindowScrollBarX(documentElement);
199 }
200 }
201
202 return {
203 x: rect.left + scroll.scrollLeft - offsets.x,
204 y: rect.top + scroll.scrollTop - offsets.y,
205 width: rect.width,
206 height: rect.height
207 };
208}
209
210// means it doesn't take into account transforms.
211
212function getLayoutRect(element) {
213 var clientRect = getBoundingClientRect(element); // Use the clientRect sizes if it's not been transformed.
214 // Fixes https://github.com/popperjs/popper-core/issues/1223
215
216 var width = element.offsetWidth;
217 var height = element.offsetHeight;
218
219 if (Math.abs(clientRect.width - width) <= 1) {
220 width = clientRect.width;
221 }
222
223 if (Math.abs(clientRect.height - height) <= 1) {
224 height = clientRect.height;
225 }
226
227 return {
228 x: element.offsetLeft,
229 y: element.offsetTop,
230 width: width,
231 height: height
232 };
233}
234
235function getParentNode(element) {
236 if (getNodeName(element) === 'html') {
237 return element;
238 }
239
240 return (// this is a quicker (but less type safe) way to save quite some bytes from the bundle
241 // $FlowFixMe[incompatible-return]
242 // $FlowFixMe[prop-missing]
243 element.assignedSlot || // step into the shadow DOM of the parent of a slotted node
244 element.parentNode || ( // DOM Element detected
245 isShadowRoot(element) ? element.host : null) || // ShadowRoot detected
246 // $FlowFixMe[incompatible-call]: HTMLElement is a Node
247 getDocumentElement(element) // fallback
248
249 );
250}
251
252function getScrollParent(node) {
253 if (['html', 'body', '#document'].indexOf(getNodeName(node)) >= 0) {
254 // $FlowFixMe[incompatible-return]: assume body is always available
255 return node.ownerDocument.body;
256 }
257
258 if (isHTMLElement(node) && isScrollParent(node)) {
259 return node;
260 }
261
262 return getScrollParent(getParentNode(node));
263}
264
265/*
266given a DOM element, return the list of all scroll parents, up the list of ancesors
267until we get to the top window object. This list is what we attach scroll listeners
268to, because if any of these parent elements scroll, we'll need to re-calculate the
269reference element's position.
270*/
271
272function listScrollParents(element, list) {
273 var _element$ownerDocumen;
274
275 if (list === void 0) {
276 list = [];
277 }
278
279 var scrollParent = getScrollParent(element);
280 var isBody = scrollParent === ((_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body);
281 var win = getWindow(scrollParent);
282 var target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
283 var updatedList = list.concat(target);
284 return isBody ? updatedList : // $FlowFixMe[incompatible-call]: isBody tells us target will be an HTMLElement here
285 updatedList.concat(listScrollParents(getParentNode(target)));
286}
287
288function isTableElement(element) {
289 return ['table', 'td', 'th'].indexOf(getNodeName(element)) >= 0;
290}
291
292function getTrueOffsetParent(element) {
293 if (!isHTMLElement(element) || // https://github.com/popperjs/popper-core/issues/837
294 getComputedStyle(element).position === 'fixed') {
295 return null;
296 }
297
298 return element.offsetParent;
299} // `.offsetParent` reports `null` for fixed elements, while absolute elements
300// return the containing block
301
302
303function getContainingBlock(element) {
304 var isFirefox = /firefox/i.test(getUAString());
305 var isIE = /Trident/i.test(getUAString());
306
307 if (isIE && isHTMLElement(element)) {
308 // In IE 9, 10 and 11 fixed elements containing block is always established by the viewport
309 var elementCss = getComputedStyle(element);
310
311 if (elementCss.position === 'fixed') {
312 return null;
313 }
314 }
315
316 var currentNode = getParentNode(element);
317
318 if (isShadowRoot(currentNode)) {
319 currentNode = currentNode.host;
320 }
321
322 while (isHTMLElement(currentNode) && ['html', 'body'].indexOf(getNodeName(currentNode)) < 0) {
323 var css = getComputedStyle(currentNode); // This is non-exhaustive but covers the most common CSS properties that
324 // create a containing block.
325 // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
326
327 if (css.transform !== 'none' || css.perspective !== 'none' || css.contain === 'paint' || ['transform', 'perspective'].indexOf(css.willChange) !== -1 || isFirefox && css.willChange === 'filter' || isFirefox && css.filter && css.filter !== 'none') {
328 return currentNode;
329 } else {
330 currentNode = currentNode.parentNode;
331 }
332 }
333
334 return null;
335} // Gets the closest ancestor positioned element. Handles some edge cases,
336// such as table ancestors and cross browser bugs.
337
338
339function getOffsetParent(element) {
340 var window = getWindow(element);
341 var offsetParent = getTrueOffsetParent(element);
342
343 while (offsetParent && isTableElement(offsetParent) && getComputedStyle(offsetParent).position === 'static') {
344 offsetParent = getTrueOffsetParent(offsetParent);
345 }
346
347 if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle(offsetParent).position === 'static')) {
348 return window;
349 }
350
351 return offsetParent || getContainingBlock(element) || window;
352}
353
354var top = 'top';
355var bottom = 'bottom';
356var right = 'right';
357var left = 'left';
358var basePlacements = [top, bottom, right, left];
359var start = 'start';
360var end = 'end';
361var clippingParents = 'clippingParents';
362var viewport = 'viewport';
363var popper = 'popper';
364var reference = 'reference';
365
366var beforeRead = 'beforeRead';
367var read = 'read';
368var afterRead = 'afterRead'; // pure-logic modifiers
369
370var beforeMain = 'beforeMain';
371var main = 'main';
372var afterMain = 'afterMain'; // modifier with the purpose to write to the DOM (or write into a framework state)
373
374var beforeWrite = 'beforeWrite';
375var write = 'write';
376var afterWrite = 'afterWrite';
377var modifierPhases = [beforeRead, read, afterRead, beforeMain, main, afterMain, beforeWrite, write, afterWrite];
378
379function order(modifiers) {
380 var map = new Map();
381 var visited = new Set();
382 var result = [];
383 modifiers.forEach(function (modifier) {
384 map.set(modifier.name, modifier);
385 }); // On visiting object, check for its dependencies and visit them recursively
386
387 function sort(modifier) {
388 visited.add(modifier.name);
389 var requires = [].concat(modifier.requires || [], modifier.requiresIfExists || []);
390 requires.forEach(function (dep) {
391 if (!visited.has(dep)) {
392 var depModifier = map.get(dep);
393
394 if (depModifier) {
395 sort(depModifier);
396 }
397 }
398 });
399 result.push(modifier);
400 }
401
402 modifiers.forEach(function (modifier) {
403 if (!visited.has(modifier.name)) {
404 // check for visited object
405 sort(modifier);
406 }
407 });
408 return result;
409}
410
411function orderModifiers(modifiers) {
412 // order based on dependencies
413 var orderedModifiers = order(modifiers); // order based on phase
414
415 return modifierPhases.reduce(function (acc, phase) {
416 return acc.concat(orderedModifiers.filter(function (modifier) {
417 return modifier.phase === phase;
418 }));
419 }, []);
420}
421
422function debounce(fn) {
423 var pending;
424 return function () {
425 if (!pending) {
426 pending = new Promise(function (resolve) {
427 Promise.resolve().then(function () {
428 pending = undefined;
429 resolve(fn());
430 });
431 });
432 }
433
434 return pending;
435 };
436}
437
438function mergeByName(modifiers) {
439 var merged = modifiers.reduce(function (merged, current) {
440 var existing = merged[current.name];
441 merged[current.name] = existing ? Object.assign({}, existing, current, {
442 options: Object.assign({}, existing.options, current.options),
443 data: Object.assign({}, existing.data, current.data)
444 }) : current;
445 return merged;
446 }, {}); // IE11 does not support Object.values
447
448 return Object.keys(merged).map(function (key) {
449 return merged[key];
450 });
451}
452
453function getViewportRect(element, strategy) {
454 var win = getWindow(element);
455 var html = getDocumentElement(element);
456 var visualViewport = win.visualViewport;
457 var width = html.clientWidth;
458 var height = html.clientHeight;
459 var x = 0;
460 var y = 0;
461
462 if (visualViewport) {
463 width = visualViewport.width;
464 height = visualViewport.height;
465 var layoutViewport = isLayoutViewport();
466
467 if (layoutViewport || !layoutViewport && strategy === 'fixed') {
468 x = visualViewport.offsetLeft;
469 y = visualViewport.offsetTop;
470 }
471 }
472
473 return {
474 width: width,
475 height: height,
476 x: x + getWindowScrollBarX(element),
477 y: y
478 };
479}
480
481// of the `<html>` and `<body>` rect bounds if horizontally scrollable
482
483function getDocumentRect(element) {
484 var _element$ownerDocumen;
485
486 var html = getDocumentElement(element);
487 var winScroll = getWindowScroll(element);
488 var body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
489 var width = max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
490 var height = max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
491 var x = -winScroll.scrollLeft + getWindowScrollBarX(element);
492 var y = -winScroll.scrollTop;
493
494 if (getComputedStyle(body || html).direction === 'rtl') {
495 x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
496 }
497
498 return {
499 width: width,
500 height: height,
501 x: x,
502 y: y
503 };
504}
505
506function contains(parent, child) {
507 var rootNode = child.getRootNode && child.getRootNode(); // First, attempt with faster native method
508
509 if (parent.contains(child)) {
510 return true;
511 } // then fallback to custom implementation with Shadow DOM support
512 else if (rootNode && isShadowRoot(rootNode)) {
513 var next = child;
514
515 do {
516 if (next && parent.isSameNode(next)) {
517 return true;
518 } // $FlowFixMe[prop-missing]: need a better way to handle this...
519
520
521 next = next.parentNode || next.host;
522 } while (next);
523 } // Give up, the result is false
524
525
526 return false;
527}
528
529function rectToClientRect(rect) {
530 return Object.assign({}, rect, {
531 left: rect.x,
532 top: rect.y,
533 right: rect.x + rect.width,
534 bottom: rect.y + rect.height
535 });
536}
537
538function getInnerBoundingClientRect(element, strategy) {
539 var rect = getBoundingClientRect(element, false, strategy === 'fixed');
540 rect.top = rect.top + element.clientTop;
541 rect.left = rect.left + element.clientLeft;
542 rect.bottom = rect.top + element.clientHeight;
543 rect.right = rect.left + element.clientWidth;
544 rect.width = element.clientWidth;
545 rect.height = element.clientHeight;
546 rect.x = rect.left;
547 rect.y = rect.top;
548 return rect;
549}
550
551function getClientRectFromMixedType(element, clippingParent, strategy) {
552 return clippingParent === viewport ? rectToClientRect(getViewportRect(element, strategy)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent, strategy) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
553} // A "clipping parent" is an overflowable container with the characteristic of
554// clipping (or hiding) overflowing elements with a position different from
555// `initial`
556
557
558function getClippingParents(element) {
559 var clippingParents = listScrollParents(getParentNode(element));
560 var canEscapeClipping = ['absolute', 'fixed'].indexOf(getComputedStyle(element).position) >= 0;
561 var clipperElement = canEscapeClipping && isHTMLElement(element) ? getOffsetParent(element) : element;
562
563 if (!isElement(clipperElement)) {
564 return [];
565 } // $FlowFixMe[incompatible-return]: https://github.com/facebook/flow/issues/1414
566
567
568 return clippingParents.filter(function (clippingParent) {
569 return isElement(clippingParent) && contains(clippingParent, clipperElement) && getNodeName(clippingParent) !== 'body';
570 });
571} // Gets the maximum area that the element is visible in due to any number of
572// clipping parents
573
574
575function getClippingRect(element, boundary, rootBoundary, strategy) {
576 var mainClippingParents = boundary === 'clippingParents' ? getClippingParents(element) : [].concat(boundary);
577 var clippingParents = [].concat(mainClippingParents, [rootBoundary]);
578 var firstClippingParent = clippingParents[0];
579 var clippingRect = clippingParents.reduce(function (accRect, clippingParent) {
580 var rect = getClientRectFromMixedType(element, clippingParent, strategy);
581 accRect.top = max(rect.top, accRect.top);
582 accRect.right = min(rect.right, accRect.right);
583 accRect.bottom = min(rect.bottom, accRect.bottom);
584 accRect.left = max(rect.left, accRect.left);
585 return accRect;
586 }, getClientRectFromMixedType(element, firstClippingParent, strategy));
587 clippingRect.width = clippingRect.right - clippingRect.left;
588 clippingRect.height = clippingRect.bottom - clippingRect.top;
589 clippingRect.x = clippingRect.left;
590 clippingRect.y = clippingRect.top;
591 return clippingRect;
592}
593
594function getBasePlacement(placement) {
595 return placement.split('-')[0];
596}
597
598function getVariation(placement) {
599 return placement.split('-')[1];
600}
601
602function getMainAxisFromPlacement(placement) {
603 return ['top', 'bottom'].indexOf(placement) >= 0 ? 'x' : 'y';
604}
605
606function computeOffsets(_ref) {
607 var reference = _ref.reference,
608 element = _ref.element,
609 placement = _ref.placement;
610 var basePlacement = placement ? getBasePlacement(placement) : null;
611 var variation = placement ? getVariation(placement) : null;
612 var commonX = reference.x + reference.width / 2 - element.width / 2;
613 var commonY = reference.y + reference.height / 2 - element.height / 2;
614 var offsets;
615
616 switch (basePlacement) {
617 case top:
618 offsets = {
619 x: commonX,
620 y: reference.y - element.height
621 };
622 break;
623
624 case bottom:
625 offsets = {
626 x: commonX,
627 y: reference.y + reference.height
628 };
629 break;
630
631 case right:
632 offsets = {
633 x: reference.x + reference.width,
634 y: commonY
635 };
636 break;
637
638 case left:
639 offsets = {
640 x: reference.x - element.width,
641 y: commonY
642 };
643 break;
644
645 default:
646 offsets = {
647 x: reference.x,
648 y: reference.y
649 };
650 }
651
652 var mainAxis = basePlacement ? getMainAxisFromPlacement(basePlacement) : null;
653
654 if (mainAxis != null) {
655 var len = mainAxis === 'y' ? 'height' : 'width';
656
657 switch (variation) {
658 case start:
659 offsets[mainAxis] = offsets[mainAxis] - (reference[len] / 2 - element[len] / 2);
660 break;
661
662 case end:
663 offsets[mainAxis] = offsets[mainAxis] + (reference[len] / 2 - element[len] / 2);
664 break;
665 }
666 }
667
668 return offsets;
669}
670
671function getFreshSideObject() {
672 return {
673 top: 0,
674 right: 0,
675 bottom: 0,
676 left: 0
677 };
678}
679
680function mergePaddingObject(paddingObject) {
681 return Object.assign({}, getFreshSideObject(), paddingObject);
682}
683
684function expandToHashMap(value, keys) {
685 return keys.reduce(function (hashMap, key) {
686 hashMap[key] = value;
687 return hashMap;
688 }, {});
689}
690
691function detectOverflow(state, options) {
692 if (options === void 0) {
693 options = {};
694 }
695
696 var _options = options,
697 _options$placement = _options.placement,
698 placement = _options$placement === void 0 ? state.placement : _options$placement,
699 _options$strategy = _options.strategy,
700 strategy = _options$strategy === void 0 ? state.strategy : _options$strategy,
701 _options$boundary = _options.boundary,
702 boundary = _options$boundary === void 0 ? clippingParents : _options$boundary,
703 _options$rootBoundary = _options.rootBoundary,
704 rootBoundary = _options$rootBoundary === void 0 ? viewport : _options$rootBoundary,
705 _options$elementConte = _options.elementContext,
706 elementContext = _options$elementConte === void 0 ? popper : _options$elementConte,
707 _options$altBoundary = _options.altBoundary,
708 altBoundary = _options$altBoundary === void 0 ? false : _options$altBoundary,
709 _options$padding = _options.padding,
710 padding = _options$padding === void 0 ? 0 : _options$padding;
711 var paddingObject = mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
712 var altContext = elementContext === popper ? reference : popper;
713 var popperRect = state.rects.popper;
714 var element = state.elements[altBoundary ? altContext : elementContext];
715 var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary, strategy);
716 var referenceClientRect = getBoundingClientRect(state.elements.reference);
717 var popperOffsets = computeOffsets({
718 reference: referenceClientRect,
719 element: popperRect,
720 strategy: 'absolute',
721 placement: placement
722 });
723 var popperClientRect = rectToClientRect(Object.assign({}, popperRect, popperOffsets));
724 var elementClientRect = elementContext === popper ? popperClientRect : referenceClientRect; // positive = overflowing the clipping rect
725 // 0 or negative = within the clipping rect
726
727 var overflowOffsets = {
728 top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
729 bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
730 left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
731 right: elementClientRect.right - clippingClientRect.right + paddingObject.right
732 };
733 var offsetData = state.modifiersData.offset; // Offsets can be applied only to the popper element
734
735 if (elementContext === popper && offsetData) {
736 var offset = offsetData[placement];
737 Object.keys(overflowOffsets).forEach(function (key) {
738 var multiply = [right, bottom].indexOf(key) >= 0 ? 1 : -1;
739 var axis = [top, bottom].indexOf(key) >= 0 ? 'y' : 'x';
740 overflowOffsets[key] += offset[axis] * multiply;
741 });
742 }
743
744 return overflowOffsets;
745}
746
747var DEFAULT_OPTIONS = {
748 placement: 'bottom',
749 modifiers: [],
750 strategy: 'absolute'
751};
752
753function areValidElements() {
754 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
755 args[_key] = arguments[_key];
756 }
757
758 return !args.some(function (element) {
759 return !(element && typeof element.getBoundingClientRect === 'function');
760 });
761}
762
763function popperGenerator(generatorOptions) {
764 if (generatorOptions === void 0) {
765 generatorOptions = {};
766 }
767
768 var _generatorOptions = generatorOptions,
769 _generatorOptions$def = _generatorOptions.defaultModifiers,
770 defaultModifiers = _generatorOptions$def === void 0 ? [] : _generatorOptions$def,
771 _generatorOptions$def2 = _generatorOptions.defaultOptions,
772 defaultOptions = _generatorOptions$def2 === void 0 ? DEFAULT_OPTIONS : _generatorOptions$def2;
773 return function createPopper(reference, popper, options) {
774 if (options === void 0) {
775 options = defaultOptions;
776 }
777
778 var state = {
779 placement: 'bottom',
780 orderedModifiers: [],
781 options: Object.assign({}, DEFAULT_OPTIONS, defaultOptions),
782 modifiersData: {},
783 elements: {
784 reference: reference,
785 popper: popper
786 },
787 attributes: {},
788 styles: {}
789 };
790 var effectCleanupFns = [];
791 var isDestroyed = false;
792 var instance = {
793 state: state,
794 setOptions: function setOptions(setOptionsAction) {
795 var options = typeof setOptionsAction === 'function' ? setOptionsAction(state.options) : setOptionsAction;
796 cleanupModifierEffects();
797 state.options = Object.assign({}, defaultOptions, state.options, options);
798 state.scrollParents = {
799 reference: isElement(reference) ? listScrollParents(reference) : reference.contextElement ? listScrollParents(reference.contextElement) : [],
800 popper: listScrollParents(popper)
801 }; // Orders the modifiers based on their dependencies and `phase`
802 // properties
803
804 var orderedModifiers = orderModifiers(mergeByName([].concat(defaultModifiers, state.options.modifiers))); // Strip out disabled modifiers
805
806 state.orderedModifiers = orderedModifiers.filter(function (m) {
807 return m.enabled;
808 });
809 runModifierEffects();
810 return instance.update();
811 },
812 // Sync update – it will always be executed, even if not necessary. This
813 // is useful for low frequency updates where sync behavior simplifies the
814 // logic.
815 // For high frequency updates (e.g. `resize` and `scroll` events), always
816 // prefer the async Popper#update method
817 forceUpdate: function forceUpdate() {
818 if (isDestroyed) {
819 return;
820 }
821
822 var _state$elements = state.elements,
823 reference = _state$elements.reference,
824 popper = _state$elements.popper; // Don't proceed if `reference` or `popper` are not valid elements
825 // anymore
826
827 if (!areValidElements(reference, popper)) {
828 return;
829 } // Store the reference and popper rects to be read by modifiers
830
831
832 state.rects = {
833 reference: getCompositeRect(reference, getOffsetParent(popper), state.options.strategy === 'fixed'),
834 popper: getLayoutRect(popper)
835 }; // Modifiers have the ability to reset the current update cycle. The
836 // most common use case for this is the `flip` modifier changing the
837 // placement, which then needs to re-run all the modifiers, because the
838 // logic was previously ran for the previous placement and is therefore
839 // stale/incorrect
840
841 state.reset = false;
842 state.placement = state.options.placement; // On each update cycle, the `modifiersData` property for each modifier
843 // is filled with the initial data specified by the modifier. This means
844 // it doesn't persist and is fresh on each update.
845 // To ensure persistent data, use `${name}#persistent`
846
847 state.orderedModifiers.forEach(function (modifier) {
848 return state.modifiersData[modifier.name] = Object.assign({}, modifier.data);
849 });
850
851 for (var index = 0; index < state.orderedModifiers.length; index++) {
852 if (state.reset === true) {
853 state.reset = false;
854 index = -1;
855 continue;
856 }
857
858 var _state$orderedModifie = state.orderedModifiers[index],
859 fn = _state$orderedModifie.fn,
860 _state$orderedModifie2 = _state$orderedModifie.options,
861 _options = _state$orderedModifie2 === void 0 ? {} : _state$orderedModifie2,
862 name = _state$orderedModifie.name;
863
864 if (typeof fn === 'function') {
865 state = fn({
866 state: state,
867 options: _options,
868 name: name,
869 instance: instance
870 }) || state;
871 }
872 }
873 },
874 // Async and optimistically optimized update – it will not be executed if
875 // not necessary (debounced to run at most once-per-tick)
876 update: debounce(function () {
877 return new Promise(function (resolve) {
878 instance.forceUpdate();
879 resolve(state);
880 });
881 }),
882 destroy: function destroy() {
883 cleanupModifierEffects();
884 isDestroyed = true;
885 }
886 };
887
888 if (!areValidElements(reference, popper)) {
889 return instance;
890 }
891
892 instance.setOptions(options).then(function (state) {
893 if (!isDestroyed && options.onFirstUpdate) {
894 options.onFirstUpdate(state);
895 }
896 }); // Modifiers have the ability to execute arbitrary code before the first
897 // update cycle runs. They will be executed in the same order as the update
898 // cycle. This is useful when a modifier adds some persistent data that
899 // other modifiers need to use, but the modifier is run after the dependent
900 // one.
901
902 function runModifierEffects() {
903 state.orderedModifiers.forEach(function (_ref) {
904 var name = _ref.name,
905 _ref$options = _ref.options,
906 options = _ref$options === void 0 ? {} : _ref$options,
907 effect = _ref.effect;
908
909 if (typeof effect === 'function') {
910 var cleanupFn = effect({
911 state: state,
912 name: name,
913 instance: instance,
914 options: options
915 });
916
917 var noopFn = function noopFn() {};
918
919 effectCleanupFns.push(cleanupFn || noopFn);
920 }
921 });
922 }
923
924 function cleanupModifierEffects() {
925 effectCleanupFns.forEach(function (fn) {
926 return fn();
927 });
928 effectCleanupFns = [];
929 }
930
931 return instance;
932 };
933}
934var createPopper = /*#__PURE__*/popperGenerator(); // eslint-disable-next-line import/no-unused-modules
935
936exports.createPopper = createPopper;
937exports.detectOverflow = detectOverflow;
938exports.popperGenerator = popperGenerator;
939//# sourceMappingURL=popper-base.js.map
Note: See TracBrowser for help on using the repository browser.