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