PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 All 205 releases
booking / vendors / _custom / tippy.js / dist / tippy.esm.js

tippy.esm.js in Booking Calendar 11.9, at vendors/_custom/tippy.js/dist/tippy.esm.js

2,487 lines 72.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**!
2 * tippy.js v6.3.7
3 * (c) 2017-2021 atomiks
4 * MIT License
5 */
6 import { createPopper, applyStyles } from '@popperjs/core';
7
8 var ROUND_ARROW = '<svg width="16" height="6" xmlns="http://www.w3.org/2000/svg"><path d="M0 6s1.796-.013 4.67-3.615C5.851.9 6.93.006 8 0c1.07-.006 2.148.887 3.343 2.385C14.233 6.005 16 6 16 6H0z"></svg>';
9 var BOX_CLASS = "tippy-box";
10 var CONTENT_CLASS = "tippy-content";
11 var BACKDROP_CLASS = "tippy-backdrop";
12 var ARROW_CLASS = "tippy-arrow";
13 var SVG_ARROW_CLASS = "tippy-svg-arrow";
14 var TOUCH_OPTIONS = {
15 passive: true,
16 capture: true
17 };
18 var TIPPY_DEFAULT_APPEND_TO = function TIPPY_DEFAULT_APPEND_TO() {
19 return document.body;
20 };
21
22 function hasOwnProperty(obj, key) {
23 return {}.hasOwnProperty.call(obj, key);
24 }
25 function getValueAtIndexOrReturn(value, index, defaultValue) {
26 if (Array.isArray(value)) {
27 var v = value[index];
28 return v == null ? Array.isArray(defaultValue) ? defaultValue[index] : defaultValue : v;
29 }
30
31 return value;
32 }
33 function isType(value, type) {
34 var str = {}.toString.call(value);
35 return str.indexOf('[object') === 0 && str.indexOf(type + "]") > -1;
36 }
37 function invokeWithArgsOrReturn(value, args) {
38 return typeof value === 'function' ? value.apply(void 0, args) : value;
39 }
40 function debounce(fn, ms) {
41 // Avoid wrapping in `setTimeout` if ms is 0 anyway
42 if (ms === 0) {
43 return fn;
44 }
45
46 var timeout;
47 return function (arg) {
48 clearTimeout(timeout);
49 timeout = setTimeout(function () {
50 fn(arg);
51 }, ms);
52 };
53 }
54 function removeProperties(obj, keys) {
55 var clone = Object.assign({}, obj);
56 keys.forEach(function (key) {
57 delete clone[key];
58 });
59 return clone;
60 }
61 function splitBySpaces(value) {
62 return value.split(/\s+/).filter(Boolean);
63 }
64 function normalizeToArray(value) {
65 return [].concat(value);
66 }
67 function pushIfUnique(arr, value) {
68 if (arr.indexOf(value) === -1) {
69 arr.push(value);
70 }
71 }
72 function unique(arr) {
73 return arr.filter(function (item, index) {
74 return arr.indexOf(item) === index;
75 });
76 }
77 function getBasePlacement(placement) {
78 return placement.split('-')[0];
79 }
80 function arrayFrom(value) {
81 return [].slice.call(value);
82 }
83 function removeUndefinedProps(obj) {
84 return Object.keys(obj).reduce(function (acc, key) {
85 if (obj[key] !== undefined) {
86 acc[key] = obj[key];
87 }
88
89 return acc;
90 }, {});
91 }
92
93 function div() {
94 return document.createElement('div');
95 }
96 function isElement(value) {
97 return ['Element', 'Fragment'].some(function (type) {
98 return isType(value, type);
99 });
100 }
101 function isNodeList(value) {
102 return isType(value, 'NodeList');
103 }
104 function isMouseEvent(value) {
105 return isType(value, 'MouseEvent');
106 }
107 function isReferenceElement(value) {
108 return !!(value && value._tippy && value._tippy.reference === value);
109 }
110 function getArrayOfElements(value) {
111 if (isElement(value)) {
112 return [value];
113 }
114
115 if (isNodeList(value)) {
116 return arrayFrom(value);
117 }
118
119 if (Array.isArray(value)) {
120 return value;
121 }
122
123 return arrayFrom(document.querySelectorAll(value));
124 }
125 function setTransitionDuration(els, value) {
126 els.forEach(function (el) {
127 if (el) {
128 el.style.transitionDuration = value + "ms";
129 }
130 });
131 }
132 function setVisibilityState(els, state) {
133 els.forEach(function (el) {
134 if (el) {
135 el.setAttribute('data-state', state);
136 }
137 });
138 }
139 function getOwnerDocument(elementOrElements) {
140 var _element$ownerDocumen;
141
142 var _normalizeToArray = normalizeToArray(elementOrElements),
143 element = _normalizeToArray[0]; // Elements created via a <template> have an ownerDocument with no reference to the body
144
145
146 return element != null && (_element$ownerDocumen = element.ownerDocument) != null && _element$ownerDocumen.body ? element.ownerDocument : document;
147 }
148 function isCursorOutsideInteractiveBorder(popperTreeData, event) {
149 var clientX = event.clientX,
150 clientY = event.clientY;
151 return popperTreeData.every(function (_ref) {
152 var popperRect = _ref.popperRect,
153 popperState = _ref.popperState,
154 props = _ref.props;
155 var interactiveBorder = props.interactiveBorder;
156 var basePlacement = getBasePlacement(popperState.placement);
157 var offsetData = popperState.modifiersData.offset;
158
159 if (!offsetData) {
160 return true;
161 }
162
163 var topDistance = basePlacement === 'bottom' ? offsetData.top.y : 0;
164 var bottomDistance = basePlacement === 'top' ? offsetData.bottom.y : 0;
165 var leftDistance = basePlacement === 'right' ? offsetData.left.x : 0;
166 var rightDistance = basePlacement === 'left' ? offsetData.right.x : 0;
167 var exceedsTop = popperRect.top - clientY + topDistance > interactiveBorder;
168 var exceedsBottom = clientY - popperRect.bottom - bottomDistance > interactiveBorder;
169 var exceedsLeft = popperRect.left - clientX + leftDistance > interactiveBorder;
170 var exceedsRight = clientX - popperRect.right - rightDistance > interactiveBorder;
171 return exceedsTop || exceedsBottom || exceedsLeft || exceedsRight;
172 });
173 }
174 function updateTransitionEndListener(box, action, listener) {
175 var method = action + "EventListener"; // some browsers apparently support `transition` (unprefixed) but only fire
176 // `webkitTransitionEnd`...
177
178 ['transitionend', 'webkitTransitionEnd'].forEach(function (event) {
179 box[method](event, listener);
180 });
181 }
182 /**
183 * Compared to xxx.contains, this function works for dom structures with shadow
184 * dom
185 */
186
187 function actualContains(parent, child) {
188 var target = child;
189
190 while (target) {
191 var _target$getRootNode;
192
193 if (parent.contains(target)) {
194 return true;
195 }
196
197 target = target.getRootNode == null ? void 0 : (_target$getRootNode = target.getRootNode()) == null ? void 0 : _target$getRootNode.host;
198 }
199
200 return false;
201 }
202
203 var currentInput = {
204 isTouch: false
205 };
206 var lastMouseMoveTime = 0;
207 /**
208 * When a `touchstart` event is fired, it's assumed the user is using touch
209 * input. We'll bind a `mousemove` event listener to listen for mouse input in
210 * the future. This way, the `isTouch` property is fully dynamic and will handle
211 * hybrid devices that use a mix of touch + mouse input.
212 */
213
214 function onDocumentTouchStart() {
215 if (currentInput.isTouch) {
216 return;
217 }
218
219 currentInput.isTouch = true;
220
221 if (window.performance) {
222 document.addEventListener('mousemove', onDocumentMouseMove);
223 }
224 }
225 /**
226 * When two `mousemove` event are fired consecutively within 20ms, it's assumed
227 * the user is using mouse input again. `mousemove` can fire on touch devices as
228 * well, but very rarely that quickly.
229 */
230
231 function onDocumentMouseMove() {
232 var now = performance.now();
233
234 if (now - lastMouseMoveTime < 20) {
235 currentInput.isTouch = false;
236 document.removeEventListener('mousemove', onDocumentMouseMove);
237 }
238
239 lastMouseMoveTime = now;
240 }
241 /**
242 * When an element is in focus and has a tippy, leaving the tab/window and
243 * returning causes it to show again. For mouse users this is unexpected, but
244 * for keyboard use it makes sense.
245 * TODO: find a better technique to solve this problem
246 */
247
248 function onWindowBlur() {
249 var activeElement = document.activeElement;
250
251 if (isReferenceElement(activeElement)) {
252 var instance = activeElement._tippy;
253
254 if (activeElement.blur && !instance.state.isVisible) {
255 activeElement.blur();
256 }
257 }
258 }
259 function bindGlobalEventListeners() {
260 document.addEventListener('touchstart', onDocumentTouchStart, TOUCH_OPTIONS);
261 window.addEventListener('blur', onWindowBlur);
262 }
263
264 var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
265 var isIE11 = isBrowser ? // @ts-ignore
266 !!window.msCrypto : false;
267
268 function createMemoryLeakWarning(method) {
269 var txt = method === 'destroy' ? 'n already-' : ' ';
270 return [method + "() was called on a" + txt + "destroyed instance. This is a no-op but", 'indicates a potential memory leak.'].join(' ');
271 }
272 function clean(value) {
273 var spacesAndTabs = /[ \t]{2,}/g;
274 var lineStartWithSpaces = /^[ \t]*/gm;
275 return value.replace(spacesAndTabs, ' ').replace(lineStartWithSpaces, '').trim();
276 }
277
278 function getDevMessage(message) {
279 return clean("\n %ctippy.js\n\n %c" + clean(message) + "\n\n %c\uD83D\uDC77\u200D This is a development-only message. It will be removed in production.\n ");
280 }
281
282 function getFormattedMessage(message) {
283 return [getDevMessage(message), // title
284 'color: #00C584; font-size: 1.3em; font-weight: bold;', // message
285 'line-height: 1.5', // footer
286 'color: #a6a095;'];
287 } // Assume warnings and errors never have the same message
288
289 var visitedMessages;
290
291 if (process.env.NODE_ENV !== "production") {
292 resetVisitedMessages();
293 }
294
295 function resetVisitedMessages() {
296 visitedMessages = new Set();
297 }
298 function warnWhen(condition, message) {
299 if (condition && !visitedMessages.has(message)) {
300 var _console;
301
302 visitedMessages.add(message);
303
304 (_console = console).warn.apply(_console, getFormattedMessage(message));
305 }
306 }
307 function errorWhen(condition, message) {
308 if (condition && !visitedMessages.has(message)) {
309 var _console2;
310
311 visitedMessages.add(message);
312
313 (_console2 = console).error.apply(_console2, getFormattedMessage(message));
314 }
315 }
316 function validateTargets(targets) {
317 var didPassFalsyValue = !targets;
318 var didPassPlainObject = Object.prototype.toString.call(targets) === '[object Object]' && !targets.addEventListener;
319 errorWhen(didPassFalsyValue, ['tippy() was passed', '`' + String(targets) + '`', 'as its targets (first) argument. Valid types are: String, Element,', 'Element[], or NodeList.'].join(' '));
320 errorWhen(didPassPlainObject, ['tippy() was passed a plain object which is not supported as an argument', 'for virtual positioning. Use props.getReferenceClientRect instead.'].join(' '));
321 }
322
323 var pluginProps = {
324 animateFill: false,
325 followCursor: false,
326 inlinePositioning: false,
327 sticky: false
328 };
329 var renderProps = {
330 allowHTML: false,
331 animation: 'fade',
332 arrow: true,
333 content: '',
334 inertia: false,
335 maxWidth: 350,
336 role: 'tooltip',
337 theme: '',
338 zIndex: 9999
339 };
340 var defaultProps = Object.assign({
341 appendTo: TIPPY_DEFAULT_APPEND_TO,
342 aria: {
343 content: 'auto',
344 expanded: 'auto'
345 },
346 delay: 0,
347 duration: [300, 250],
348 getReferenceClientRect: null,
349 hideOnClick: true,
350 ignoreAttributes: false,
351 interactive: false,
352 interactiveBorder: 2,
353 interactiveDebounce: 0,
354 moveTransition: '',
355 offset: [0, 10],
356 onAfterUpdate: function onAfterUpdate() {},
357 onBeforeUpdate: function onBeforeUpdate() {},
358 onCreate: function onCreate() {},
359 onDestroy: function onDestroy() {},
360 onHidden: function onHidden() {},
361 onHide: function onHide() {},
362 onMount: function onMount() {},
363 onShow: function onShow() {},
364 onShown: function onShown() {},
365 onTrigger: function onTrigger() {},
366 onUntrigger: function onUntrigger() {},
367 onClickOutside: function onClickOutside() {},
368 placement: 'top',
369 plugins: [],
370 popperOptions: {},
371 render: null,
372 showOnCreate: false,
373 touch: true,
374 trigger: 'mouseenter focus',
375 triggerTarget: null
376 }, pluginProps, renderProps);
377 var defaultKeys = Object.keys(defaultProps);
378 var setDefaultProps = function setDefaultProps(partialProps) {
379 /* istanbul ignore else */
380 if (process.env.NODE_ENV !== "production") {
381 validateProps(partialProps, []);
382 }
383
384 var keys = Object.keys(partialProps);
385 keys.forEach(function (key) {
386 defaultProps[key] = partialProps[key];
387 });
388 };
389 function getExtendedPassedProps(passedProps) {
390 var plugins = passedProps.plugins || [];
391 var pluginProps = plugins.reduce(function (acc, plugin) {
392 var name = plugin.name,
393 defaultValue = plugin.defaultValue;
394
395 if (name) {
396 var _name;
397
398 acc[name] = passedProps[name] !== undefined ? passedProps[name] : (_name = defaultProps[name]) != null ? _name : defaultValue;
399 }
400
401 return acc;
402 }, {});
403 return Object.assign({}, passedProps, pluginProps);
404 }
405 function getDataAttributeProps(reference, plugins) {
406 var propKeys = plugins ? Object.keys(getExtendedPassedProps(Object.assign({}, defaultProps, {
407 plugins: plugins
408 }))) : defaultKeys;
409 var props = propKeys.reduce(function (acc, key) {
410 var valueAsString = (reference.getAttribute("data-tippy-" + key) || '').trim();
411
412 if (!valueAsString) {
413 return acc;
414 }
415
416 if (key === 'content') {
417 acc[key] = valueAsString;
418 } else {
419 try {
420 acc[key] = JSON.parse(valueAsString);
421 } catch (e) {
422 acc[key] = valueAsString;
423 }
424 }
425
426 return acc;
427 }, {});
428 return props;
429 }
430 function evaluateProps(reference, props) {
431 var out = Object.assign({}, props, {
432 content: invokeWithArgsOrReturn(props.content, [reference])
433 }, props.ignoreAttributes ? {} : getDataAttributeProps(reference, props.plugins));
434 out.aria = Object.assign({}, defaultProps.aria, out.aria);
435 out.aria = {
436 expanded: out.aria.expanded === 'auto' ? props.interactive : out.aria.expanded,
437 content: out.aria.content === 'auto' ? props.interactive ? null : 'describedby' : out.aria.content
438 };
439 return out;
440 }
441 function validateProps(partialProps, plugins) {
442 if (partialProps === void 0) {
443 partialProps = {};
444 }
445
446 if (plugins === void 0) {
447 plugins = [];
448 }
449
450 var keys = Object.keys(partialProps);
451 keys.forEach(function (prop) {
452 var nonPluginProps = removeProperties(defaultProps, Object.keys(pluginProps));
453 var didPassUnknownProp = !hasOwnProperty(nonPluginProps, prop); // Check if the prop exists in `plugins`
454
455 if (didPassUnknownProp) {
456 didPassUnknownProp = plugins.filter(function (plugin) {
457 return plugin.name === prop;
458 }).length === 0;
459 }
460
461 warnWhen(didPassUnknownProp, ["`" + prop + "`", "is not a valid prop. You may have spelled it incorrectly, or if it's", 'a plugin, forgot to pass it in an array as props.plugins.', '\n\n', 'All props: https://atomiks.github.io/tippyjs/v6/all-props/\n', 'Plugins: https://atomiks.github.io/tippyjs/v6/plugins/'].join(' '));
462 });
463 }
464
465 var innerHTML = function innerHTML() {
466 return 'innerHTML';
467 };
468
469 function dangerouslySetInnerHTML(element, html) {
470 element[innerHTML()] = html;
471 }
472
473 function createArrowElement(value) {
474 var arrow = div();
475
476 if (value === true) {
477 arrow.className = ARROW_CLASS;
478 } else {
479 arrow.className = SVG_ARROW_CLASS;
480
481 if (isElement(value)) {
482 arrow.appendChild(value);
483 } else {
484 dangerouslySetInnerHTML(arrow, value);
485 }
486 }
487
488 return arrow;
489 }
490
491 function setContent(content, props) {
492 if (isElement(props.content)) {
493 dangerouslySetInnerHTML(content, '');
494 content.appendChild(props.content);
495 } else if (typeof props.content !== 'function') {
496 if (props.allowHTML) {
497 dangerouslySetInnerHTML(content, props.content);
498 } else {
499 content.textContent = props.content;
500 }
501 }
502 }
503 function getChildren(popper) {
504 var box = popper.firstElementChild;
505 var boxChildren = arrayFrom(box.children);
506 return {
507 box: box,
508 content: boxChildren.find(function (node) {
509 return node.classList.contains(CONTENT_CLASS);
510 }),
511 arrow: boxChildren.find(function (node) {
512 return node.classList.contains(ARROW_CLASS) || node.classList.contains(SVG_ARROW_CLASS);
513 }),
514 backdrop: boxChildren.find(function (node) {
515 return node.classList.contains(BACKDROP_CLASS);
516 })
517 };
518 }
519 function render(instance) {
520 var popper = div();
521 var box = div();
522 box.className = BOX_CLASS;
523 box.setAttribute('data-state', 'hidden');
524 box.setAttribute('tabindex', '-1');
525 var content = div();
526 content.className = CONTENT_CLASS;
527 content.setAttribute('data-state', 'hidden');
528 setContent(content, instance.props);
529 popper.appendChild(box);
530 box.appendChild(content);
531 onUpdate(instance.props, instance.props);
532
533 function onUpdate(prevProps, nextProps) {
534 var _getChildren = getChildren(popper),
535 box = _getChildren.box,
536 content = _getChildren.content,
537 arrow = _getChildren.arrow;
538
539 if (nextProps.theme) {
540 box.setAttribute('data-theme', nextProps.theme);
541 } else {
542 box.removeAttribute('data-theme');
543 }
544
545 if (typeof nextProps.animation === 'string') {
546 box.setAttribute('data-animation', nextProps.animation);
547 } else {
548 box.removeAttribute('data-animation');
549 }
550
551 if (nextProps.inertia) {
552 box.setAttribute('data-inertia', '');
553 } else {
554 box.removeAttribute('data-inertia');
555 }
556
557 box.style.maxWidth = typeof nextProps.maxWidth === 'number' ? nextProps.maxWidth + "px" : nextProps.maxWidth;
558
559 if (nextProps.role) {
560 box.setAttribute('role', nextProps.role);
561 } else {
562 box.removeAttribute('role');
563 }
564
565 if (prevProps.content !== nextProps.content || prevProps.allowHTML !== nextProps.allowHTML) {
566 setContent(content, instance.props);
567 }
568
569 if (nextProps.arrow) {
570 if (!arrow) {
571 box.appendChild(createArrowElement(nextProps.arrow));
572 } else if (prevProps.arrow !== nextProps.arrow) {
573 box.removeChild(arrow);
574 box.appendChild(createArrowElement(nextProps.arrow));
575 }
576 } else if (arrow) {
577 box.removeChild(arrow);
578 }
579 }
580
581 return {
582 popper: popper,
583 onUpdate: onUpdate
584 };
585 } // Runtime check to identify if the render function is the default one; this
586 // way we can apply default CSS transitions logic and it can be tree-shaken away
587
588 render.$$tippy = true;
589
590 var idCounter = 1;
591 var mouseMoveListeners = []; // Used by `hideAll()`
592
593 var mountedInstances = [];
594 function createTippy(reference, passedProps) {
595 var props = evaluateProps(reference, Object.assign({}, defaultProps, getExtendedPassedProps(removeUndefinedProps(passedProps)))); // ===========================================================================
596 // 🔒 Private members
597 // ===========================================================================
598
599 var showTimeout;
600 var hideTimeout;
601 var scheduleHideAnimationFrame;
602 var isVisibleFromClick = false;
603 var didHideDueToDocumentMouseDown = false;
604 var didTouchMove = false;
605 var ignoreOnFirstUpdate = false;
606 var lastTriggerEvent;
607 var currentTransitionEndListener;
608 var onFirstUpdate;
609 var listeners = [];
610 var debouncedOnMouseMove = debounce(onMouseMove, props.interactiveDebounce);
611 var currentTarget; // ===========================================================================
612 // 🔑 Public members
613 // ===========================================================================
614
615 var id = idCounter++;
616 var popperInstance = null;
617 var plugins = unique(props.plugins);
618 var state = {
619 // Is the instance currently enabled?
620 isEnabled: true,
621 // Is the tippy currently showing and not transitioning out?
622 isVisible: false,
623 // Has the instance been destroyed?
624 isDestroyed: false,
625 // Is the tippy currently mounted to the DOM?
626 isMounted: false,
627 // Has the tippy finished transitioning in?
628 isShown: false
629 };
630 var instance = {
631 // properties
632 id: id,
633 reference: reference,
634 popper: div(),
635 popperInstance: popperInstance,
636 props: props,
637 state: state,
638 plugins: plugins,
639 // methods
640 clearDelayTimeouts: clearDelayTimeouts,
641 setProps: setProps,
642 setContent: setContent,
643 show: show,
644 hide: hide,
645 hideWithInteractivity: hideWithInteractivity,
646 enable: enable,
647 disable: disable,
648 unmount: unmount,
649 destroy: destroy
650 }; // TODO: Investigate why this early return causes a TDZ error in the tests —
651 // it doesn't seem to happen in the browser
652
653 /* istanbul ignore if */
654
655 if (!props.render) {
656 if (process.env.NODE_ENV !== "production") {
657 errorWhen(true, 'render() function has not been supplied.');
658 }
659
660 return instance;
661 } // ===========================================================================
662 // Initial mutations
663 // ===========================================================================
664
665
666 var _props$render = props.render(instance),
667 popper = _props$render.popper,
668 onUpdate = _props$render.onUpdate;
669
670 popper.setAttribute('data-tippy-root', '');
671 popper.id = "tippy-" + instance.id;
672 instance.popper = popper;
673 reference._tippy = instance;
674 popper._tippy = instance;
675 var pluginsHooks = plugins.map(function (plugin) {
676 return plugin.fn(instance);
677 });
678 var hasAriaExpanded = reference.hasAttribute('aria-expanded');
679 addListeners();
680 handleAriaExpandedAttribute();
681 handleStyles();
682 invokeHook('onCreate', [instance]);
683
684 if (props.showOnCreate) {
685 scheduleShow();
686 } // Prevent a tippy with a delay from hiding if the cursor left then returned
687 // before it started hiding
688
689
690 popper.addEventListener('mouseenter', function () {
691 if (instance.props.interactive && instance.state.isVisible) {
692 instance.clearDelayTimeouts();
693 }
694 });
695 popper.addEventListener('mouseleave', function () {
696 if (instance.props.interactive && instance.props.trigger.indexOf('mouseenter') >= 0) {
697 getDocument().addEventListener('mousemove', debouncedOnMouseMove);
698 }
699 });
700 return instance; // ===========================================================================
701 // 🔒 Private methods
702 // ===========================================================================
703
704 function getNormalizedTouchSettings() {
705 var touch = instance.props.touch;
706 return Array.isArray(touch) ? touch : [touch, 0];
707 }
708
709 function getIsCustomTouchBehavior() {
710 return getNormalizedTouchSettings()[0] === 'hold';
711 }
712
713 function getIsDefaultRenderFn() {
714 var _instance$props$rende;
715
716 // @ts-ignore
717 return !!((_instance$props$rende = instance.props.render) != null && _instance$props$rende.$$tippy);
718 }
719
720 function getCurrentTarget() {
721 return currentTarget || reference;
722 }
723
724 function getDocument() {
725 var parent = getCurrentTarget().parentNode;
726 return parent ? getOwnerDocument(parent) : document;
727 }
728
729 function getDefaultTemplateChildren() {
730 return getChildren(popper);
731 }
732
733 function getDelay(isShow) {
734 // For touch or keyboard input, force `0` delay for UX reasons
735 // Also if the instance is mounted but not visible (transitioning out),
736 // ignore delay
737 if (instance.state.isMounted && !instance.state.isVisible || currentInput.isTouch || lastTriggerEvent && lastTriggerEvent.type === 'focus') {
738 return 0;
739 }
740
741 return getValueAtIndexOrReturn(instance.props.delay, isShow ? 0 : 1, defaultProps.delay);
742 }
743
744 function handleStyles(fromHide) {
745 if (fromHide === void 0) {
746 fromHide = false;
747 }
748
749 popper.style.pointerEvents = instance.props.interactive && !fromHide ? '' : 'none';
750 popper.style.zIndex = "" + instance.props.zIndex;
751 }
752
753 function invokeHook(hook, args, shouldInvokePropsHook) {
754 if (shouldInvokePropsHook === void 0) {
755 shouldInvokePropsHook = true;
756 }
757
758 pluginsHooks.forEach(function (pluginHooks) {
759 if (pluginHooks[hook]) {
760 pluginHooks[hook].apply(pluginHooks, args);
761 }
762 });
763
764 if (shouldInvokePropsHook) {
765 var _instance$props;
766
767 (_instance$props = instance.props)[hook].apply(_instance$props, args);
768 }
769 }
770
771 function handleAriaContentAttribute() {
772 var aria = instance.props.aria;
773
774 if (!aria.content) {
775 return;
776 }
777
778 var attr = "aria-" + aria.content;
779 var id = popper.id;
780 var nodes = normalizeToArray(instance.props.triggerTarget || reference);
781 nodes.forEach(function (node) {
782 var currentValue = node.getAttribute(attr);
783
784 if (instance.state.isVisible) {
785 node.setAttribute(attr, currentValue ? currentValue + " " + id : id);
786 } else {
787 var nextValue = currentValue && currentValue.replace(id, '').trim();
788
789 if (nextValue) {
790 node.setAttribute(attr, nextValue);
791 } else {
792 node.removeAttribute(attr);
793 }
794 }
795 });
796 }
797
798 function handleAriaExpandedAttribute() {
799 if (hasAriaExpanded || !instance.props.aria.expanded) {
800 return;
801 }
802
803 var nodes = normalizeToArray(instance.props.triggerTarget || reference);
804 nodes.forEach(function (node) {
805 if (instance.props.interactive) {
806 node.setAttribute('aria-expanded', instance.state.isVisible && node === getCurrentTarget() ? 'true' : 'false');
807 } else {
808 node.removeAttribute('aria-expanded');
809 }
810 });
811 }
812
813 function cleanupInteractiveMouseListeners() {
814 getDocument().removeEventListener('mousemove', debouncedOnMouseMove);
815 mouseMoveListeners = mouseMoveListeners.filter(function (listener) {
816 return listener !== debouncedOnMouseMove;
817 });
818 }
819
820 function onDocumentPress(event) {
821 // Moved finger to scroll instead of an intentional tap outside
822 if (currentInput.isTouch) {
823 if (didTouchMove || event.type === 'mousedown') {
824 return;
825 }
826 }
827
828 var actualTarget = event.composedPath && event.composedPath()[0] || event.target; // Clicked on interactive popper
829
830 if (instance.props.interactive && actualContains(popper, actualTarget)) {
831 return;
832 } // Clicked on the event listeners target
833
834
835 if (normalizeToArray(instance.props.triggerTarget || reference).some(function (el) {
836 return actualContains(el, actualTarget);
837 })) {
838 if (currentInput.isTouch) {
839 return;
840 }
841
842 if (instance.state.isVisible && instance.props.trigger.indexOf('click') >= 0) {
843 return;
844 }
845 } else {
846 invokeHook('onClickOutside', [instance, event]);
847 }
848
849 if (instance.props.hideOnClick === true) {
850 instance.clearDelayTimeouts();
851 instance.hide(); // `mousedown` event is fired right before `focus` if pressing the
852 // currentTarget. This lets a tippy with `focus` trigger know that it
853 // should not show
854
855 didHideDueToDocumentMouseDown = true;
856 setTimeout(function () {
857 didHideDueToDocumentMouseDown = false;
858 }); // The listener gets added in `scheduleShow()`, but this may be hiding it
859 // before it shows, and hide()'s early bail-out behavior can prevent it
860 // from being cleaned up
861
862 if (!instance.state.isMounted) {
863 removeDocumentPress();
864 }
865 }
866 }
867
868 function onTouchMove() {
869 didTouchMove = true;
870 }
871
872 function onTouchStart() {
873 didTouchMove = false;
874 }
875
876 function addDocumentPress() {
877 var doc = getDocument();
878 doc.addEventListener('mousedown', onDocumentPress, true);
879 doc.addEventListener('touchend', onDocumentPress, TOUCH_OPTIONS);
880 doc.addEventListener('touchstart', onTouchStart, TOUCH_OPTIONS);
881 doc.addEventListener('touchmove', onTouchMove, TOUCH_OPTIONS);
882 }
883
884 function removeDocumentPress() {
885 var doc = getDocument();
886 doc.removeEventListener('mousedown', onDocumentPress, true);
887 doc.removeEventListener('touchend', onDocumentPress, TOUCH_OPTIONS);
888 doc.removeEventListener('touchstart', onTouchStart, TOUCH_OPTIONS);
889 doc.removeEventListener('touchmove', onTouchMove, TOUCH_OPTIONS);
890 }
891
892 function onTransitionedOut(duration, callback) {
893 onTransitionEnd(duration, function () {
894 if (!instance.state.isVisible && popper.parentNode && popper.parentNode.contains(popper)) {
895 callback();
896 }
897 });
898 }
899
900 function onTransitionedIn(duration, callback) {
901 onTransitionEnd(duration, callback);
902 }
903
904 function onTransitionEnd(duration, callback) {
905 var box = getDefaultTemplateChildren().box;
906
907 function listener(event) {
908 if (event.target === box) {
909 updateTransitionEndListener(box, 'remove', listener);
910 callback();
911 }
912 } // Make callback synchronous if duration is 0
913 // `transitionend` won't fire otherwise
914
915
916 if (duration === 0) {
917 return callback();
918 }
919
920 updateTransitionEndListener(box, 'remove', currentTransitionEndListener);
921 updateTransitionEndListener(box, 'add', listener);
922 currentTransitionEndListener = listener;
923 }
924
925 function on(eventType, handler, options) {
926 if (options === void 0) {
927 options = false;
928 }
929
930 var nodes = normalizeToArray(instance.props.triggerTarget || reference);
931 nodes.forEach(function (node) {
932 node.addEventListener(eventType, handler, options);
933 listeners.push({
934 node: node,
935 eventType: eventType,
936 handler: handler,
937 options: options
938 });
939 });
940 }
941
942 function addListeners() {
943 if (getIsCustomTouchBehavior()) {
944 on('touchstart', onTrigger, {
945 passive: true
946 });
947 on('touchend', onMouseLeave, {
948 passive: true
949 });
950 }
951
952 splitBySpaces(instance.props.trigger).forEach(function (eventType) {
953 if (eventType === 'manual') {
954 return;
955 }
956
957 on(eventType, onTrigger);
958
959 switch (eventType) {
960 case 'mouseenter':
961 on('mouseleave', onMouseLeave);
962 break;
963
964 case 'focus':
965 on(isIE11 ? 'focusout' : 'blur', onBlurOrFocusOut);
966 break;
967
968 case 'focusin':
969 on('focusout', onBlurOrFocusOut);
970 break;
971 }
972 });
973 }
974
975 function removeListeners() {
976 listeners.forEach(function (_ref) {
977 var node = _ref.node,
978 eventType = _ref.eventType,
979 handler = _ref.handler,
980 options = _ref.options;
981 node.removeEventListener(eventType, handler, options);
982 });
983 listeners = [];
984 }
985
986 function onTrigger(event) {
987 var _lastTriggerEvent;
988
989 var shouldScheduleClickHide = false;
990
991 if (!instance.state.isEnabled || isEventListenerStopped(event) || didHideDueToDocumentMouseDown) {
992 return;
993 }
994
995 var wasFocused = ((_lastTriggerEvent = lastTriggerEvent) == null ? void 0 : _lastTriggerEvent.type) === 'focus';
996 lastTriggerEvent = event;
997 currentTarget = event.currentTarget;
998 handleAriaExpandedAttribute();
999
1000 if (!instance.state.isVisible && isMouseEvent(event)) {
1001 // If scrolling, `mouseenter` events can be fired if the cursor lands
1002 // over a new target, but `mousemove` events don't get fired. This
1003 // causes interactive tooltips to get stuck open until the cursor is
1004 // moved
1005 mouseMoveListeners.forEach(function (listener) {
1006 return listener(event);
1007 });
1008 } // Toggle show/hide when clicking click-triggered tooltips
1009
1010
1011 if (event.type === 'click' && (instance.props.trigger.indexOf('mouseenter') < 0 || isVisibleFromClick) && instance.props.hideOnClick !== false && instance.state.isVisible) {
1012 shouldScheduleClickHide = true;
1013 } else {
1014 scheduleShow(event);
1015 }
1016
1017 if (event.type === 'click') {
1018 isVisibleFromClick = !shouldScheduleClickHide;
1019 }
1020
1021 if (shouldScheduleClickHide && !wasFocused) {
1022 scheduleHide(event);
1023 }
1024 }
1025
1026 function onMouseMove(event) {
1027 var target = event.target;
1028 var isCursorOverReferenceOrPopper = getCurrentTarget().contains(target) || popper.contains(target);
1029
1030 if (event.type === 'mousemove' && isCursorOverReferenceOrPopper) {
1031 return;
1032 }
1033
1034 var popperTreeData = getNestedPopperTree().concat(popper).map(function (popper) {
1035 var _instance$popperInsta;
1036
1037 var instance = popper._tippy;
1038 var state = (_instance$popperInsta = instance.popperInstance) == null ? void 0 : _instance$popperInsta.state;
1039
1040 if (state) {
1041 return {
1042 popperRect: popper.getBoundingClientRect(),
1043 popperState: state,
1044 props: props
1045 };
1046 }
1047
1048 return null;
1049 }).filter(Boolean);
1050
1051 if (isCursorOutsideInteractiveBorder(popperTreeData, event)) {
1052 cleanupInteractiveMouseListeners();
1053 scheduleHide(event);
1054 }
1055 }
1056
1057 function onMouseLeave(event) {
1058 var shouldBail = isEventListenerStopped(event) || instance.props.trigger.indexOf('click') >= 0 && isVisibleFromClick;
1059
1060 if (shouldBail) {
1061 return;
1062 }
1063
1064 if (instance.props.interactive) {
1065 instance.hideWithInteractivity(event);
1066 return;
1067 }
1068
1069 scheduleHide(event);
1070 }
1071
1072 function onBlurOrFocusOut(event) {
1073 if (instance.props.trigger.indexOf('focusin') < 0 && event.target !== getCurrentTarget()) {
1074 return;
1075 } // If focus was moved to within the popper
1076
1077
1078 if (instance.props.interactive && event.relatedTarget && popper.contains(event.relatedTarget)) {
1079 return;
1080 }
1081
1082 scheduleHide(event);
1083 }
1084
1085 function isEventListenerStopped(event) {
1086 return currentInput.isTouch ? getIsCustomTouchBehavior() !== event.type.indexOf('touch') >= 0 : false;
1087 }
1088
1089 function createPopperInstance() {
1090 destroyPopperInstance();
1091 var _instance$props2 = instance.props,
1092 popperOptions = _instance$props2.popperOptions,
1093 placement = _instance$props2.placement,
1094 offset = _instance$props2.offset,
1095 getReferenceClientRect = _instance$props2.getReferenceClientRect,
1096 moveTransition = _instance$props2.moveTransition;
1097 var arrow = getIsDefaultRenderFn() ? getChildren(popper).arrow : null;
1098 var computedReference = getReferenceClientRect ? {
1099 getBoundingClientRect: getReferenceClientRect,
1100 contextElement: getReferenceClientRect.contextElement || getCurrentTarget()
1101 } : reference;
1102 var tippyModifier = {
1103 name: '$$tippy',
1104 enabled: true,
1105 phase: 'beforeWrite',
1106 requires: ['computeStyles'],
1107 fn: function fn(_ref2) {
1108 var state = _ref2.state;
1109
1110 if (getIsDefaultRenderFn()) {
1111 var _getDefaultTemplateCh = getDefaultTemplateChildren(),
1112 box = _getDefaultTemplateCh.box;
1113
1114 ['placement', 'reference-hidden', 'escaped'].forEach(function (attr) {
1115 if (attr === 'placement') {
1116 box.setAttribute('data-placement', state.placement);
1117 } else {
1118 if (state.attributes.popper["data-popper-" + attr]) {
1119 box.setAttribute("data-" + attr, '');
1120 } else {
1121 box.removeAttribute("data-" + attr);
1122 }
1123 }
1124 });
1125 state.attributes.popper = {};
1126 }
1127 }
1128 };
1129 var modifiers = [{
1130 name: 'offset',
1131 options: {
1132 offset: offset
1133 }
1134 }, {
1135 name: 'preventOverflow',
1136 options: {
1137 padding: {
1138 top: 2,
1139 bottom: 2,
1140 left: 5,
1141 right: 5
1142 }
1143 }
1144 }, {
1145 name: 'flip',
1146 options: {
1147 padding: 5
1148 }
1149 }, {
1150 name: 'computeStyles',
1151 options: {
1152 adaptive: !moveTransition
1153 }
1154 }, tippyModifier];
1155
1156 if (getIsDefaultRenderFn() && arrow) {
1157 modifiers.push({
1158 name: 'arrow',
1159 options: {
1160 element: arrow,
1161 padding: 3
1162 }
1163 });
1164 }
1165
1166 modifiers.push.apply(modifiers, (popperOptions == null ? void 0 : popperOptions.modifiers) || []);
1167 instance.popperInstance = createPopper(computedReference, popper, Object.assign({}, popperOptions, {
1168 placement: placement,
1169 onFirstUpdate: onFirstUpdate,
1170 modifiers: modifiers
1171 }));
1172 }
1173
1174 function destroyPopperInstance() {
1175 if (instance.popperInstance) {
1176 instance.popperInstance.destroy();
1177 instance.popperInstance = null;
1178 }
1179 }
1180
1181 function mount() {
1182 var appendTo = instance.props.appendTo;
1183 var parentNode; // By default, we'll append the popper to the triggerTargets's parentNode so
1184 // it's directly after the reference element so the elements inside the
1185 // tippy can be tabbed to
1186 // If there are clipping issues, the user can specify a different appendTo
1187 // and ensure focus management is handled correctly manually
1188
1189 var node = getCurrentTarget();
1190
1191 if (instance.props.interactive && appendTo === TIPPY_DEFAULT_APPEND_TO || appendTo === 'parent') {
1192 parentNode = node.parentNode;
1193 } else {
1194 parentNode = invokeWithArgsOrReturn(appendTo, [node]);
1195 } // The popper element needs to exist on the DOM before its position can be
1196 // updated as Popper needs to read its dimensions
1197
1198
1199 if (!parentNode.contains(popper)) {
1200 parentNode.appendChild(popper);
1201 }
1202
1203 instance.state.isMounted = true;
1204 createPopperInstance();
1205 /* istanbul ignore else */
1206
1207 if (process.env.NODE_ENV !== "production") {
1208 // Accessibility check
1209 warnWhen(instance.props.interactive && appendTo === defaultProps.appendTo && node.nextElementSibling !== popper, ['Interactive tippy element may not be accessible via keyboard', 'navigation because it is not directly after the reference element', 'in the DOM source order.', '\n\n', 'Using a wrapper <div> or <span> tag around the reference element', 'solves this by creating a new parentNode context.', '\n\n', 'Specifying `appendTo: document.body` silences this warning, but it', 'assumes you are using a focus management solution to handle', 'keyboard navigation.', '\n\n', 'See: https://atomiks.github.io/tippyjs/v6/accessibility/#interactivity'].join(' '));
1210 }
1211 }
1212
1213 function getNestedPopperTree() {
1214 return arrayFrom(popper.querySelectorAll('[data-tippy-root]'));
1215 }
1216
1217 function scheduleShow(event) {
1218 instance.clearDelayTimeouts();
1219
1220 if (event) {
1221 invokeHook('onTrigger', [instance, event]);
1222 }
1223
1224 addDocumentPress();
1225 var delay = getDelay(true);
1226
1227 var _getNormalizedTouchSe = getNormalizedTouchSettings(),
1228 touchValue = _getNormalizedTouchSe[0],
1229 touchDelay = _getNormalizedTouchSe[1];
1230
1231 if (currentInput.isTouch && touchValue === 'hold' && touchDelay) {
1232 delay = touchDelay;
1233 }
1234
1235 if (delay) {
1236 showTimeout = setTimeout(function () {
1237 instance.show();
1238 }, delay);
1239 } else {
1240 instance.show();
1241 }
1242 }
1243
1244 function scheduleHide(event) {
1245 instance.clearDelayTimeouts();
1246 invokeHook('onUntrigger', [instance, event]);
1247
1248 if (!instance.state.isVisible) {
1249 removeDocumentPress();
1250 return;
1251 } // For interactive tippies, scheduleHide is added to a document.body handler
1252 // from onMouseLeave so must intercept scheduled hides from mousemove/leave
1253 // events when trigger contains mouseenter and click, and the tip is
1254 // currently shown as a result of a click.
1255
1256
1257 if (instance.props.trigger.indexOf('mouseenter') >= 0 && instance.props.trigger.indexOf('click') >= 0 && ['mouseleave', 'mousemove'].indexOf(event.type) >= 0 && isVisibleFromClick) {
1258 return;
1259 }
1260
1261 var delay = getDelay(false);
1262
1263 if (delay) {
1264 hideTimeout = setTimeout(function () {
1265 if (instance.state.isVisible) {
1266 instance.hide();
1267 }
1268 }, delay);
1269 } else {
1270 // Fixes a `transitionend` problem when it fires 1 frame too
1271 // late sometimes, we don't want hide() to be called.
1272 scheduleHideAnimationFrame = requestAnimationFrame(function () {
1273 instance.hide();
1274 });
1275 }
1276 } // ===========================================================================
1277 // 🔑 Public methods
1278 // ===========================================================================
1279
1280
1281 function enable() {
1282 instance.state.isEnabled = true;
1283 }
1284
1285 function disable() {
1286 // Disabling the instance should also hide it
1287 // https://github.com/atomiks/tippy.js-react/issues/106
1288 instance.hide();
1289 instance.state.isEnabled = false;
1290 }
1291
1292 function clearDelayTimeouts() {
1293 clearTimeout(showTimeout);
1294 clearTimeout(hideTimeout);
1295 cancelAnimationFrame(scheduleHideAnimationFrame);
1296 }
1297
1298 function setProps(partialProps) {
1299 /* istanbul ignore else */
1300 if (process.env.NODE_ENV !== "production") {
1301 warnWhen(instance.state.isDestroyed, createMemoryLeakWarning('setProps'));
1302 }
1303
1304 if (instance.state.isDestroyed) {
1305 return;
1306 }
1307
1308 invokeHook('onBeforeUpdate', [instance, partialProps]);
1309 removeListeners();
1310 var prevProps = instance.props;
1311 var nextProps = evaluateProps(reference, Object.assign({}, prevProps, removeUndefinedProps(partialProps), {
1312 ignoreAttributes: true
1313 }));
1314 instance.props = nextProps;
1315 addListeners();
1316
1317 if (prevProps.interactiveDebounce !== nextProps.interactiveDebounce) {
1318 cleanupInteractiveMouseListeners();
1319 debouncedOnMouseMove = debounce(onMouseMove, nextProps.interactiveDebounce);
1320 } // Ensure stale aria-expanded attributes are removed
1321
1322
1323 if (prevProps.triggerTarget && !nextProps.triggerTarget) {
1324 normalizeToArray(prevProps.triggerTarget).forEach(function (node) {
1325 node.removeAttribute('aria-expanded');
1326 });
1327 } else if (nextProps.triggerTarget) {
1328 reference.removeAttribute('aria-expanded');
1329 }
1330
1331 handleAriaExpandedAttribute();
1332 handleStyles();
1333
1334 if (onUpdate) {
1335 onUpdate(prevProps, nextProps);
1336 }
1337
1338 if (instance.popperInstance) {
1339 createPopperInstance(); // Fixes an issue with nested tippies if they are all getting re-rendered,
1340 // and the nested ones get re-rendered first.
1341 // https://github.com/atomiks/tippyjs-react/issues/177
1342 // TODO: find a cleaner / more efficient solution(!)
1343
1344 getNestedPopperTree().forEach(function (nestedPopper) {
1345 // React (and other UI libs likely) requires a rAF wrapper as it flushes
1346 // its work in one
1347 requestAnimationFrame(nestedPopper._tippy.popperInstance.forceUpdate);
1348 });
1349 }
1350
1351 invokeHook('onAfterUpdate', [instance, partialProps]);
1352 }
1353
1354 function setContent(content) {
1355 instance.setProps({
1356 content: content
1357 });
1358 }
1359
1360 function show() {
1361 /* istanbul ignore else */
1362 if (process.env.NODE_ENV !== "production") {
1363 warnWhen(instance.state.isDestroyed, createMemoryLeakWarning('show'));
1364 } // Early bail-out
1365
1366
1367 var isAlreadyVisible = instance.state.isVisible;
1368 var isDestroyed = instance.state.isDestroyed;
1369 var isDisabled = !instance.state.isEnabled;
1370 var isTouchAndTouchDisabled = currentInput.isTouch && !instance.props.touch;
1371 var duration = getValueAtIndexOrReturn(instance.props.duration, 0, defaultProps.duration);
1372
1373 if (isAlreadyVisible || isDestroyed || isDisabled || isTouchAndTouchDisabled) {
1374 return;
1375 } // Normalize `disabled` behavior across browsers.
1376 // Firefox allows events on disabled elements, but Chrome doesn't.
1377 // Using a wrapper element (i.e. <span>) is recommended.
1378
1379
1380 if (getCurrentTarget().hasAttribute('disabled')) {
1381 return;
1382 }
1383
1384 invokeHook('onShow', [instance], false);
1385
1386 if (instance.props.onShow(instance) === false) {
1387 return;
1388 }
1389
1390 instance.state.isVisible = true;
1391
1392 if (getIsDefaultRenderFn()) {
1393 popper.style.visibility = 'visible';
1394 }
1395
1396 handleStyles();
1397 addDocumentPress();
1398
1399 if (!instance.state.isMounted) {
1400 popper.style.transition = 'none';
1401 } // If flipping to the opposite side after hiding at least once, the
1402 // animation will use the wrong placement without resetting the duration
1403
1404
1405 if (getIsDefaultRenderFn()) {
1406 var _getDefaultTemplateCh2 = getDefaultTemplateChildren(),
1407 box = _getDefaultTemplateCh2.box,
1408 content = _getDefaultTemplateCh2.content;
1409
1410 setTransitionDuration([box, content], 0);
1411 }
1412
1413 onFirstUpdate = function onFirstUpdate() {
1414 var _instance$popperInsta2;
1415
1416 if (!instance.state.isVisible || ignoreOnFirstUpdate) {
1417 return;
1418 }
1419
1420 ignoreOnFirstUpdate = true; // reflow
1421
1422 void popper.offsetHeight;
1423 popper.style.transition = instance.props.moveTransition;
1424
1425 if (getIsDefaultRenderFn() && instance.props.animation) {
1426 var _getDefaultTemplateCh3 = getDefaultTemplateChildren(),
1427 _box = _getDefaultTemplateCh3.box,
1428 _content = _getDefaultTemplateCh3.content;
1429
1430 setTransitionDuration([_box, _content], duration);
1431 setVisibilityState([_box, _content], 'visible');
1432 }
1433
1434 handleAriaContentAttribute();
1435 handleAriaExpandedAttribute();
1436 pushIfUnique(mountedInstances, instance); // certain modifiers (e.g. `maxSize`) require a second update after the
1437 // popper has been positioned for the first time
1438
1439 (_instance$popperInsta2 = instance.popperInstance) == null ? void 0 : _instance$popperInsta2.forceUpdate();
1440 invokeHook('onMount', [instance]);
1441
1442 if (instance.props.animation && getIsDefaultRenderFn()) {
1443 onTransitionedIn(duration, function () {
1444 instance.state.isShown = true;
1445 invokeHook('onShown', [instance]);
1446 });
1447 }
1448 };
1449
1450 mount();
1451 }
1452
1453 function hide() {
1454 /* istanbul ignore else */
1455 if (process.env.NODE_ENV !== "production") {
1456 warnWhen(instance.state.isDestroyed, createMemoryLeakWarning('hide'));
1457 } // Early bail-out
1458
1459
1460 var isAlreadyHidden = !instance.state.isVisible;
1461 var isDestroyed = instance.state.isDestroyed;
1462 var isDisabled = !instance.state.isEnabled;
1463 var duration = getValueAtIndexOrReturn(instance.props.duration, 1, defaultProps.duration);
1464
1465 if (isAlreadyHidden || isDestroyed || isDisabled) {
1466 return;
1467 }
1468
1469 invokeHook('onHide', [instance], false);
1470
1471 if (instance.props.onHide(instance) === false) {
1472 return;
1473 }
1474
1475 instance.state.isVisible = false;
1476 instance.state.isShown = false;
1477 ignoreOnFirstUpdate = false;
1478 isVisibleFromClick = false;
1479
1480 if (getIsDefaultRenderFn()) {
1481 popper.style.visibility = 'hidden';
1482 }
1483
1484 cleanupInteractiveMouseListeners();
1485 removeDocumentPress();
1486 handleStyles(true);
1487
1488 if (getIsDefaultRenderFn()) {
1489 var _getDefaultTemplateCh4 = getDefaultTemplateChildren(),
1490 box = _getDefaultTemplateCh4.box,
1491 content = _getDefaultTemplateCh4.content;
1492
1493 if (instance.props.animation) {
1494 setTransitionDuration([box, content], duration);
1495 setVisibilityState([box, content], 'hidden');
1496 }
1497 }
1498
1499 handleAriaContentAttribute();
1500 handleAriaExpandedAttribute();
1501
1502 if (instance.props.animation) {
1503 if (getIsDefaultRenderFn()) {
1504 onTransitionedOut(duration, instance.unmount);
1505 }
1506 } else {
1507 instance.unmount();
1508 }
1509 }
1510
1511 function hideWithInteractivity(event) {
1512 /* istanbul ignore else */
1513 if (process.env.NODE_ENV !== "production") {
1514 warnWhen(instance.state.isDestroyed, createMemoryLeakWarning('hideWithInteractivity'));
1515 }
1516
1517 getDocument().addEventListener('mousemove', debouncedOnMouseMove);
1518 pushIfUnique(mouseMoveListeners, debouncedOnMouseMove);
1519 debouncedOnMouseMove(event);
1520 }
1521
1522 function unmount() {
1523 /* istanbul ignore else */
1524 if (process.env.NODE_ENV !== "production") {
1525 warnWhen(instance.state.isDestroyed, createMemoryLeakWarning('unmount'));
1526 }
1527
1528 if (instance.state.isVisible) {
1529 instance.hide();
1530 }
1531
1532 if (!instance.state.isMounted) {
1533 return;
1534 }
1535
1536 destroyPopperInstance(); // If a popper is not interactive, it will be appended outside the popper
1537 // tree by default. This seems mainly for interactive tippies, but we should
1538 // find a workaround if possible
1539
1540 getNestedPopperTree().forEach(function (nestedPopper) {
1541 nestedPopper._tippy.unmount();
1542 });
1543
1544 if (popper.parentNode) {
1545 popper.parentNode.removeChild(popper);
1546 }
1547
1548 mountedInstances = mountedInstances.filter(function (i) {
1549 return i !== instance;
1550 });
1551 instance.state.isMounted = false;
1552 invokeHook('onHidden', [instance]);
1553 }
1554
1555 function destroy() {
1556 /* istanbul ignore else */
1557 if (process.env.NODE_ENV !== "production") {
1558 warnWhen(instance.state.isDestroyed, createMemoryLeakWarning('destroy'));
1559 }
1560
1561 if (instance.state.isDestroyed) {
1562 return;
1563 }
1564
1565 instance.clearDelayTimeouts();
1566 instance.unmount();
1567 removeListeners();
1568 delete reference._tippy;
1569 instance.state.isDestroyed = true;
1570 invokeHook('onDestroy', [instance]);
1571 }
1572 }
1573
1574 function tippy(targets, optionalProps) {
1575 if (optionalProps === void 0) {
1576 optionalProps = {};
1577 }
1578
1579 var plugins = defaultProps.plugins.concat(optionalProps.plugins || []);
1580 /* istanbul ignore else */
1581
1582 if (process.env.NODE_ENV !== "production") {
1583 validateTargets(targets);
1584 validateProps(optionalProps, plugins);
1585 }
1586
1587 bindGlobalEventListeners();
1588 var passedProps = Object.assign({}, optionalProps, {
1589 plugins: plugins
1590 });
1591 var elements = getArrayOfElements(targets);
1592 /* istanbul ignore else */
1593
1594 if (process.env.NODE_ENV !== "production") {
1595 var isSingleContentElement = isElement(passedProps.content);
1596 var isMoreThanOneReferenceElement = elements.length > 1;
1597 warnWhen(isSingleContentElement && isMoreThanOneReferenceElement, ['tippy() was passed an Element as the `content` prop, but more than', 'one tippy instance was created by this invocation. This means the', 'content element will only be appended to the last tippy instance.', '\n\n', 'Instead, pass the .innerHTML of the element, or use a function that', 'returns a cloned version of the element instead.', '\n\n', '1) content: element.innerHTML\n', '2) content: () => element.cloneNode(true)'].join(' '));
1598 }
1599
1600 var instances = elements.reduce(function (acc, reference) {
1601 var instance = reference && createTippy(reference, passedProps);
1602
1603 if (instance) {
1604 acc.push(instance);
1605 }
1606
1607 return acc;
1608 }, []);
1609 return isElement(targets) ? instances[0] : instances;
1610 }
1611
1612 tippy.defaultProps = defaultProps;
1613 tippy.setDefaultProps = setDefaultProps;
1614 tippy.currentInput = currentInput;
1615 var hideAll = function hideAll(_temp) {
1616 var _ref = _temp === void 0 ? {} : _temp,
1617 excludedReferenceOrInstance = _ref.exclude,
1618 duration = _ref.duration;
1619
1620 mountedInstances.forEach(function (instance) {
1621 var isExcluded = false;
1622
1623 if (excludedReferenceOrInstance) {
1624 isExcluded = isReferenceElement(excludedReferenceOrInstance) ? instance.reference === excludedReferenceOrInstance : instance.popper === excludedReferenceOrInstance.popper;
1625 }
1626
1627 if (!isExcluded) {
1628 var originalDuration = instance.props.duration;
1629 instance.setProps({
1630 duration: duration
1631 });
1632 instance.hide();
1633
1634 if (!instance.state.isDestroyed) {
1635 instance.setProps({
1636 duration: originalDuration
1637 });
1638 }
1639 }
1640 });
1641 };
1642
1643 // every time the popper is destroyed (i.e. a new target), removing the styles
1644 // and causing transitions to break for singletons when the console is open, but
1645 // most notably for non-transform styles being used, `gpuAcceleration: false`.
1646
1647 var applyStylesModifier = Object.assign({}, applyStyles, {
1648 effect: function effect(_ref) {
1649 var state = _ref.state;
1650 var initialStyles = {
1651 popper: {
1652 position: state.options.strategy,
1653 left: '0',
1654 top: '0',
1655 margin: '0'
1656 },
1657 arrow: {
1658 position: 'absolute'
1659 },
1660 reference: {}
1661 };
1662 Object.assign(state.elements.popper.style, initialStyles.popper);
1663 state.styles = initialStyles;
1664
1665 if (state.elements.arrow) {
1666 Object.assign(state.elements.arrow.style, initialStyles.arrow);
1667 } // intentionally return no cleanup function
1668 // return () => { ... }
1669
1670 }
1671 });
1672
1673 var createSingleton = function createSingleton(tippyInstances, optionalProps) {
1674 var _optionalProps$popper;
1675
1676 if (optionalProps === void 0) {
1677 optionalProps = {};
1678 }
1679
1680 /* istanbul ignore else */
1681 if (process.env.NODE_ENV !== "production") {
1682 errorWhen(!Array.isArray(tippyInstances), ['The first argument passed to createSingleton() must be an array of', 'tippy instances. The passed value was', String(tippyInstances)].join(' '));
1683 }
1684
1685 var individualInstances = tippyInstances;
1686 var references = [];
1687 var triggerTargets = [];
1688 var currentTarget;
1689 var overrides = optionalProps.overrides;
1690 var interceptSetPropsCleanups = [];
1691 var shownOnCreate = false;
1692
1693 function setTriggerTargets() {
1694 triggerTargets = individualInstances.map(function (instance) {
1695 return normalizeToArray(instance.props.triggerTarget || instance.reference);
1696 }).reduce(function (acc, item) {
1697 return acc.concat(item);
1698 }, []);
1699 }
1700
1701 function setReferences() {
1702 references = individualInstances.map(function (instance) {
1703 return instance.reference;
1704 });
1705 }
1706
1707 function enableInstances(isEnabled) {
1708 individualInstances.forEach(function (instance) {
1709 if (isEnabled) {
1710 instance.enable();
1711 } else {
1712 instance.disable();
1713 }
1714 });
1715 }
1716
1717 function interceptSetProps(singleton) {
1718 return individualInstances.map(function (instance) {
1719 var originalSetProps = instance.setProps;
1720
1721 instance.setProps = function (props) {
1722 originalSetProps(props);
1723
1724 if (instance.reference === currentTarget) {
1725 singleton.setProps(props);
1726 }
1727 };
1728
1729 return function () {
1730 instance.setProps = originalSetProps;
1731 };
1732 });
1733 } // have to pass singleton, as it maybe undefined on first call
1734
1735
1736 function prepareInstance(singleton, target) {
1737 var index = triggerTargets.indexOf(target); // bail-out
1738
1739 if (target === currentTarget) {
1740 return;
1741 }
1742
1743 currentTarget = target;
1744 var overrideProps = (overrides || []).concat('content').reduce(function (acc, prop) {
1745 acc[prop] = individualInstances[index].props[prop];
1746 return acc;
1747 }, {});
1748 singleton.setProps(Object.assign({}, overrideProps, {
1749 getReferenceClientRect: typeof overrideProps.getReferenceClientRect === 'function' ? overrideProps.getReferenceClientRect : function () {
1750 var _references$index;
1751
1752 return (_references$index = references[index]) == null ? void 0 : _references$index.getBoundingClientRect();
1753 }
1754 }));
1755 }
1756
1757 enableInstances(false);
1758 setReferences();
1759 setTriggerTargets();
1760 var plugin = {
1761 fn: function fn() {
1762 return {
1763 onDestroy: function onDestroy() {
1764 enableInstances(true);
1765 },
1766 onHidden: function onHidden() {
1767 currentTarget = null;
1768 },
1769 onClickOutside: function onClickOutside(instance) {
1770 if (instance.props.showOnCreate && !shownOnCreate) {
1771 shownOnCreate = true;
1772 currentTarget = null;
1773 }
1774 },
1775 onShow: function onShow(instance) {
1776 if (instance.props.showOnCreate && !shownOnCreate) {
1777 shownOnCreate = true;
1778 prepareInstance(instance, references[0]);
1779 }
1780 },
1781 onTrigger: function onTrigger(instance, event) {
1782 prepareInstance(instance, event.currentTarget);
1783 }
1784 };
1785 }
1786 };
1787 var singleton = tippy(div(), Object.assign({}, removeProperties(optionalProps, ['overrides']), {
1788 plugins: [plugin].concat(optionalProps.plugins || []),
1789 triggerTarget: triggerTargets,
1790 popperOptions: Object.assign({}, optionalProps.popperOptions, {
1791 modifiers: [].concat(((_optionalProps$popper = optionalProps.popperOptions) == null ? void 0 : _optionalProps$popper.modifiers) || [], [applyStylesModifier])
1792 })
1793 }));
1794 var originalShow = singleton.show;
1795
1796 singleton.show = function (target) {
1797 originalShow(); // first time, showOnCreate or programmatic call with no params
1798 // default to showing first instance
1799
1800 if (!currentTarget && target == null) {
1801 return prepareInstance(singleton, references[0]);
1802 } // triggered from event (do nothing as prepareInstance already called by onTrigger)
1803 // programmatic call with no params when already visible (do nothing again)
1804
1805
1806 if (currentTarget && target == null) {
1807 return;
1808 } // target is index of instance
1809
1810
1811 if (typeof target === 'number') {
1812 return references[target] && prepareInstance(singleton, references[target]);
1813 } // target is a child tippy instance
1814
1815
1816 if (individualInstances.indexOf(target) >= 0) {
1817 var ref = target.reference;
1818 return prepareInstance(singleton, ref);
1819 } // target is a ReferenceElement
1820
1821
1822 if (references.indexOf(target) >= 0) {
1823 return prepareInstance(singleton, target);
1824 }
1825 };
1826
1827 singleton.showNext = function () {
1828 var first = references[0];
1829
1830 if (!currentTarget) {
1831 return singleton.show(0);
1832 }
1833
1834 var index = references.indexOf(currentTarget);
1835 singleton.show(references[index + 1] || first);
1836 };
1837
1838 singleton.showPrevious = function () {
1839 var last = references[references.length - 1];
1840
1841 if (!currentTarget) {
1842 return singleton.show(last);
1843 }
1844
1845 var index = references.indexOf(currentTarget);
1846 var target = references[index - 1] || last;
1847 singleton.show(target);
1848 };
1849
1850 var originalSetProps = singleton.setProps;
1851
1852 singleton.setProps = function (props) {
1853 overrides = props.overrides || overrides;
1854 originalSetProps(props);
1855 };
1856
1857 singleton.setInstances = function (nextInstances) {
1858 enableInstances(true);
1859 interceptSetPropsCleanups.forEach(function (fn) {
1860 return fn();
1861 });
1862 individualInstances = nextInstances;
1863 enableInstances(false);
1864 setReferences();
1865 setTriggerTargets();
1866 interceptSetPropsCleanups = interceptSetProps(singleton);
1867 singleton.setProps({
1868 triggerTarget: triggerTargets
1869 });
1870 };
1871
1872 interceptSetPropsCleanups = interceptSetProps(singleton);
1873 return singleton;
1874 };
1875
1876 var BUBBLING_EVENTS_MAP = {
1877 mouseover: 'mouseenter',
1878 focusin: 'focus',
1879 click: 'click'
1880 };
1881 /**
1882 * Creates a delegate instance that controls the creation of tippy instances
1883 * for child elements (`target` CSS selector).
1884 */
1885
1886 function delegate(targets, props) {
1887 /* istanbul ignore else */
1888 if (process.env.NODE_ENV !== "production") {
1889 errorWhen(!(props && props.target), ['You must specity a `target` prop indicating a CSS selector string matching', 'the target elements that should receive a tippy.'].join(' '));
1890 }
1891
1892 var listeners = [];
1893 var childTippyInstances = [];
1894 var disabled = false;
1895 var target = props.target;
1896 var nativeProps = removeProperties(props, ['target']);
1897 var parentProps = Object.assign({}, nativeProps, {
1898 trigger: 'manual',
1899 touch: false
1900 });
1901 var childProps = Object.assign({
1902 touch: defaultProps.touch
1903 }, nativeProps, {
1904 showOnCreate: true
1905 });
1906 var returnValue = tippy(targets, parentProps);
1907 var normalizedReturnValue = normalizeToArray(returnValue);
1908
1909 function onTrigger(event) {
1910 if (!event.target || disabled) {
1911 return;
1912 }
1913
1914 var targetNode = event.target.closest(target);
1915
1916 if (!targetNode) {
1917 return;
1918 } // Get relevant trigger with fallbacks:
1919 // 1. Check `data-tippy-trigger` attribute on target node
1920 // 2. Fallback to `trigger` passed to `delegate()`
1921 // 3. Fallback to `defaultProps.trigger`
1922
1923
1924 var trigger = targetNode.getAttribute('data-tippy-trigger') || props.trigger || defaultProps.trigger; // @ts-ignore
1925
1926 if (targetNode._tippy) {
1927 return;
1928 }
1929
1930 if (event.type === 'touchstart' && typeof childProps.touch === 'boolean') {
1931 return;
1932 }
1933
1934 if (event.type !== 'touchstart' && trigger.indexOf(BUBBLING_EVENTS_MAP[event.type]) < 0) {
1935 return;
1936 }
1937
1938 var instance = tippy(targetNode, childProps);
1939
1940 if (instance) {
1941 childTippyInstances = childTippyInstances.concat(instance);
1942 }
1943 }
1944
1945 function on(node, eventType, handler, options) {
1946 if (options === void 0) {
1947 options = false;
1948 }
1949
1950 node.addEventListener(eventType, handler, options);
1951 listeners.push({
1952 node: node,
1953 eventType: eventType,
1954 handler: handler,
1955 options: options
1956 });
1957 }
1958
1959 function addEventListeners(instance) {
1960 var reference = instance.reference;
1961 on(reference, 'touchstart', onTrigger, TOUCH_OPTIONS);
1962 on(reference, 'mouseover', onTrigger);
1963 on(reference, 'focusin', onTrigger);
1964 on(reference, 'click', onTrigger);
1965 }
1966
1967 function removeEventListeners() {
1968 listeners.forEach(function (_ref) {
1969 var node = _ref.node,
1970 eventType = _ref.eventType,
1971 handler = _ref.handler,
1972 options = _ref.options;
1973 node.removeEventListener(eventType, handler, options);
1974 });
1975 listeners = [];
1976 }
1977
1978 function applyMutations(instance) {
1979 var originalDestroy = instance.destroy;
1980 var originalEnable = instance.enable;
1981 var originalDisable = instance.disable;
1982
1983 instance.destroy = function (shouldDestroyChildInstances) {
1984 if (shouldDestroyChildInstances === void 0) {
1985 shouldDestroyChildInstances = true;
1986 }
1987
1988 if (shouldDestroyChildInstances) {
1989 childTippyInstances.forEach(function (instance) {
1990 instance.destroy();
1991 });
1992 }
1993
1994 childTippyInstances = [];
1995 removeEventListeners();
1996 originalDestroy();
1997 };
1998
1999 instance.enable = function () {
2000 originalEnable();
2001 childTippyInstances.forEach(function (instance) {
2002 return instance.enable();
2003 });
2004 disabled = false;
2005 };
2006
2007 instance.disable = function () {
2008 originalDisable();
2009 childTippyInstances.forEach(function (instance) {
2010 return instance.disable();
2011 });
2012 disabled = true;
2013 };
2014
2015 addEventListeners(instance);
2016 }
2017
2018 normalizedReturnValue.forEach(applyMutations);
2019 return returnValue;
2020 }
2021
2022 var animateFill = {
2023 name: 'animateFill',
2024 defaultValue: false,
2025 fn: function fn(instance) {
2026 var _instance$props$rende;
2027
2028 // @ts-ignore
2029 if (!((_instance$props$rende = instance.props.render) != null && _instance$props$rende.$$tippy)) {
2030 if (process.env.NODE_ENV !== "production") {
2031 errorWhen(instance.props.animateFill, 'The `animateFill` plugin requires the default render function.');
2032 }
2033
2034 return {};
2035 }
2036
2037 var _getChildren = getChildren(instance.popper),
2038 box = _getChildren.box,
2039 content = _getChildren.content;
2040
2041 var backdrop = instance.props.animateFill ? createBackdropElement() : null;
2042 return {
2043 onCreate: function onCreate() {
2044 if (backdrop) {
2045 box.insertBefore(backdrop, box.firstElementChild);
2046 box.setAttribute('data-animatefill', '');
2047 box.style.overflow = 'hidden';
2048 instance.setProps({
2049 arrow: false,
2050 animation: 'shift-away'
2051 });
2052 }
2053 },
2054 onMount: function onMount() {
2055 if (backdrop) {
2056 var transitionDuration = box.style.transitionDuration;
2057 var duration = Number(transitionDuration.replace('ms', '')); // The content should fade in after the backdrop has mostly filled the
2058 // tooltip element. `clip-path` is the other alternative but is not
2059 // well-supported and is buggy on some devices.
2060
2061 content.style.transitionDelay = Math.round(duration / 10) + "ms";
2062 backdrop.style.transitionDuration = transitionDuration;
2063 setVisibilityState([backdrop], 'visible');
2064 }
2065 },
2066 onShow: function onShow() {
2067 if (backdrop) {
2068 backdrop.style.transitionDuration = '0ms';
2069 }
2070 },
2071 onHide: function onHide() {
2072 if (backdrop) {
2073 setVisibilityState([backdrop], 'hidden');
2074 }
2075 }
2076 };
2077 }
2078 };
2079
2080 function createBackdropElement() {
2081 var backdrop = div();
2082 backdrop.className = BACKDROP_CLASS;
2083 setVisibilityState([backdrop], 'hidden');
2084 return backdrop;
2085 }
2086
2087 var mouseCoords = {
2088 clientX: 0,
2089 clientY: 0
2090 };
2091 var activeInstances = [];
2092
2093 function storeMouseCoords(_ref) {
2094 var clientX = _ref.clientX,
2095 clientY = _ref.clientY;
2096 mouseCoords = {
2097 clientX: clientX,
2098 clientY: clientY
2099 };
2100 }
2101
2102 function addMouseCoordsListener(doc) {
2103 doc.addEventListener('mousemove', storeMouseCoords);
2104 }
2105
2106 function removeMouseCoordsListener(doc) {
2107 doc.removeEventListener('mousemove', storeMouseCoords);
2108 }
2109
2110 var followCursor = {
2111 name: 'followCursor',
2112 defaultValue: false,
2113 fn: function fn(instance) {
2114 var reference = instance.reference;
2115 var doc = getOwnerDocument(instance.props.triggerTarget || reference);
2116 var isInternalUpdate = false;
2117 var wasFocusEvent = false;
2118 var isUnmounted = true;
2119 var prevProps = instance.props;
2120
2121 function getIsInitialBehavior() {
2122 return instance.props.followCursor === 'initial' && instance.state.isVisible;
2123 }
2124
2125 function addListener() {
2126 doc.addEventListener('mousemove', onMouseMove);
2127 }
2128
2129 function removeListener() {
2130 doc.removeEventListener('mousemove', onMouseMove);
2131 }
2132
2133 function unsetGetReferenceClientRect() {
2134 isInternalUpdate = true;
2135 instance.setProps({
2136 getReferenceClientRect: null
2137 });
2138 isInternalUpdate = false;
2139 }
2140
2141 function onMouseMove(event) {
2142 // If the instance is interactive, avoid updating the position unless it's
2143 // over the reference element
2144 var isCursorOverReference = event.target ? reference.contains(event.target) : true;
2145 var followCursor = instance.props.followCursor;
2146 var clientX = event.clientX,
2147 clientY = event.clientY;
2148 var rect = reference.getBoundingClientRect();
2149 var relativeX = clientX - rect.left;
2150 var relativeY = clientY - rect.top;
2151
2152 if (isCursorOverReference || !instance.props.interactive) {
2153 instance.setProps({
2154 // @ts-ignore - unneeded DOMRect properties
2155 getReferenceClientRect: function getReferenceClientRect() {
2156 var rect = reference.getBoundingClientRect();
2157 var x = clientX;
2158 var y = clientY;
2159
2160 if (followCursor === 'initial') {
2161 x = rect.left + relativeX;
2162 y = rect.top + relativeY;
2163 }
2164
2165 var top = followCursor === 'horizontal' ? rect.top : y;
2166 var right = followCursor === 'vertical' ? rect.right : x;
2167 var bottom = followCursor === 'horizontal' ? rect.bottom : y;
2168 var left = followCursor === 'vertical' ? rect.left : x;
2169 return {
2170 width: right - left,
2171 height: bottom - top,
2172 top: top,
2173 right: right,
2174 bottom: bottom,
2175 left: left
2176 };
2177 }
2178 });
2179 }
2180 }
2181
2182 function create() {
2183 if (instance.props.followCursor) {
2184 activeInstances.push({
2185 instance: instance,
2186 doc: doc
2187 });
2188 addMouseCoordsListener(doc);
2189 }
2190 }
2191
2192 function destroy() {
2193 activeInstances = activeInstances.filter(function (data) {
2194 return data.instance !== instance;
2195 });
2196
2197 if (activeInstances.filter(function (data) {
2198 return data.doc === doc;
2199 }).length === 0) {
2200 removeMouseCoordsListener(doc);
2201 }
2202 }
2203
2204 return {
2205 onCreate: create,
2206 onDestroy: destroy,
2207 onBeforeUpdate: function onBeforeUpdate() {
2208 prevProps = instance.props;
2209 },
2210 onAfterUpdate: function onAfterUpdate(_, _ref2) {
2211 var followCursor = _ref2.followCursor;
2212
2213 if (isInternalUpdate) {
2214 return;
2215 }
2216
2217 if (followCursor !== undefined && prevProps.followCursor !== followCursor) {
2218 destroy();
2219
2220 if (followCursor) {
2221 create();
2222
2223 if (instance.state.isMounted && !wasFocusEvent && !getIsInitialBehavior()) {
2224 addListener();
2225 }
2226 } else {
2227 removeListener();
2228 unsetGetReferenceClientRect();
2229 }
2230 }
2231 },
2232 onMount: function onMount() {
2233 if (instance.props.followCursor && !wasFocusEvent) {
2234 if (isUnmounted) {
2235 onMouseMove(mouseCoords);
2236 isUnmounted = false;
2237 }
2238
2239 if (!getIsInitialBehavior()) {
2240 addListener();
2241 }
2242 }
2243 },
2244 onTrigger: function onTrigger(_, event) {
2245 if (isMouseEvent(event)) {
2246 mouseCoords = {
2247 clientX: event.clientX,
2248 clientY: event.clientY
2249 };
2250 }
2251
2252 wasFocusEvent = event.type === 'focus';
2253 },
2254 onHidden: function onHidden() {
2255 if (instance.props.followCursor) {
2256 unsetGetReferenceClientRect();
2257 removeListener();
2258 isUnmounted = true;
2259 }
2260 }
2261 };
2262 }
2263 };
2264
2265 function getProps(props, modifier) {
2266 var _props$popperOptions;
2267
2268 return {
2269 popperOptions: Object.assign({}, props.popperOptions, {
2270 modifiers: [].concat((((_props$popperOptions = props.popperOptions) == null ? void 0 : _props$popperOptions.modifiers) || []).filter(function (_ref) {
2271 var name = _ref.name;
2272 return name !== modifier.name;
2273 }), [modifier])
2274 })
2275 };
2276 }
2277
2278 var inlinePositioning = {
2279 name: 'inlinePositioning',
2280 defaultValue: false,
2281 fn: function fn(instance) {
2282 var reference = instance.reference;
2283
2284 function isEnabled() {
2285 return !!instance.props.inlinePositioning;
2286 }
2287
2288 var placement;
2289 var cursorRectIndex = -1;
2290 var isInternalUpdate = false;
2291 var triedPlacements = [];
2292 var modifier = {
2293 name: 'tippyInlinePositioning',
2294 enabled: true,
2295 phase: 'afterWrite',
2296 fn: function fn(_ref2) {
2297 var state = _ref2.state;
2298
2299 if (isEnabled()) {
2300 if (triedPlacements.indexOf(state.placement) !== -1) {
2301 triedPlacements = [];
2302 }
2303
2304 if (placement !== state.placement && triedPlacements.indexOf(state.placement) === -1) {
2305 triedPlacements.push(state.placement);
2306 instance.setProps({
2307 // @ts-ignore - unneeded DOMRect properties
2308 getReferenceClientRect: function getReferenceClientRect() {
2309 return _getReferenceClientRect(state.placement);
2310 }
2311 });
2312 }
2313
2314 placement = state.placement;
2315 }
2316 }
2317 };
2318
2319 function _getReferenceClientRect(placement) {
2320 return getInlineBoundingClientRect(getBasePlacement(placement), reference.getBoundingClientRect(), arrayFrom(reference.getClientRects()), cursorRectIndex);
2321 }
2322
2323 function setInternalProps(partialProps) {
2324 isInternalUpdate = true;
2325 instance.setProps(partialProps);
2326 isInternalUpdate = false;
2327 }
2328
2329 function addModifier() {
2330 if (!isInternalUpdate) {
2331 setInternalProps(getProps(instance.props, modifier));
2332 }
2333 }
2334
2335 return {
2336 onCreate: addModifier,
2337 onAfterUpdate: addModifier,
2338 onTrigger: function onTrigger(_, event) {
2339 if (isMouseEvent(event)) {
2340 var rects = arrayFrom(instance.reference.getClientRects());
2341 var cursorRect = rects.find(function (rect) {
2342 return rect.left - 2 <= event.clientX && rect.right + 2 >= event.clientX && rect.top - 2 <= event.clientY && rect.bottom + 2 >= event.clientY;
2343 });
2344 var index = rects.indexOf(cursorRect);
2345 cursorRectIndex = index > -1 ? index : cursorRectIndex;
2346 }
2347 },
2348 onHidden: function onHidden() {
2349 cursorRectIndex = -1;
2350 }
2351 };
2352 }
2353 };
2354 function getInlineBoundingClientRect(currentBasePlacement, boundingRect, clientRects, cursorRectIndex) {
2355 // Not an inline element, or placement is not yet known
2356 if (clientRects.length < 2 || currentBasePlacement === null) {
2357 return boundingRect;
2358 } // There are two rects and they are disjoined
2359
2360
2361 if (clientRects.length === 2 && cursorRectIndex >= 0 && clientRects[0].left > clientRects[1].right) {
2362 return clientRects[cursorRectIndex] || boundingRect;
2363 }
2364
2365 switch (currentBasePlacement) {
2366 case 'top':
2367 case 'bottom':
2368 {
2369 var firstRect = clientRects[0];
2370 var lastRect = clientRects[clientRects.length - 1];
2371 var isTop = currentBasePlacement === 'top';
2372 var top = firstRect.top;
2373 var bottom = lastRect.bottom;
2374 var left = isTop ? firstRect.left : lastRect.left;
2375 var right = isTop ? firstRect.right : lastRect.right;
2376 var width = right - left;
2377 var height = bottom - top;
2378 return {
2379 top: top,
2380 bottom: bottom,
2381 left: left,
2382 right: right,
2383 width: width,
2384 height: height
2385 };
2386 }
2387
2388 case 'left':
2389 case 'right':
2390 {
2391 var minLeft = Math.min.apply(Math, clientRects.map(function (rects) {
2392 return rects.left;
2393 }));
2394 var maxRight = Math.max.apply(Math, clientRects.map(function (rects) {
2395 return rects.right;
2396 }));
2397 var measureRects = clientRects.filter(function (rect) {
2398 return currentBasePlacement === 'left' ? rect.left === minLeft : rect.right === maxRight;
2399 });
2400 var _top = measureRects[0].top;
2401 var _bottom = measureRects[measureRects.length - 1].bottom;
2402 var _left = minLeft;
2403 var _right = maxRight;
2404
2405 var _width = _right - _left;
2406
2407 var _height = _bottom - _top;
2408
2409 return {
2410 top: _top,
2411 bottom: _bottom,
2412 left: _left,
2413 right: _right,
2414 width: _width,
2415 height: _height
2416 };
2417 }
2418
2419 default:
2420 {
2421 return boundingRect;
2422 }
2423 }
2424 }
2425
2426 var sticky = {
2427 name: 'sticky',
2428 defaultValue: false,
2429 fn: function fn(instance) {
2430 var reference = instance.reference,
2431 popper = instance.popper;
2432
2433 function getReference() {
2434 return instance.popperInstance ? instance.popperInstance.state.elements.reference : reference;
2435 }
2436
2437 function shouldCheck(value) {
2438 return instance.props.sticky === true || instance.props.sticky === value;
2439 }
2440
2441 var prevRefRect = null;
2442 var prevPopRect = null;
2443
2444 function updatePosition() {
2445 var currentRefRect = shouldCheck('reference') ? getReference().getBoundingClientRect() : null;
2446 var currentPopRect = shouldCheck('popper') ? popper.getBoundingClientRect() : null;
2447
2448 if (currentRefRect && areRectsDifferent(prevRefRect, currentRefRect) || currentPopRect && areRectsDifferent(prevPopRect, currentPopRect)) {
2449 if (instance.popperInstance) {
2450 instance.popperInstance.update();
2451 }
2452 }
2453
2454 prevRefRect = currentRefRect;
2455 prevPopRect = currentPopRect;
2456
2457 if (instance.state.isMounted) {
2458 requestAnimationFrame(updatePosition);
2459 }
2460 }
2461
2462 return {
2463 onMount: function onMount() {
2464 if (instance.props.sticky) {
2465 updatePosition();
2466 }
2467 }
2468 };
2469 }
2470 };
2471
2472 function areRectsDifferent(rectA, rectB) {
2473 if (rectA && rectB) {
2474 return rectA.top !== rectB.top || rectA.right !== rectB.right || rectA.bottom !== rectB.bottom || rectA.left !== rectB.left;
2475 }
2476
2477 return true;
2478 }
2479
2480 tippy.setDefaultProps({
2481 render: render
2482 });
2483
2484 export default tippy;
2485 export { animateFill, createSingleton, delegate, followCursor, hideAll, inlinePositioning, ROUND_ARROW as roundArrow, sticky };
2486 //# sourceMappingURL=tippy.esm.js.map
2487