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