Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 | 5x 5x 5x 5x 1x 1x 1x 1x 1x 19x 5x 146x 1x 1x 145x 5x 119x 5x 98x 294x 5x 867x 177x 5x 104x 589x 5x 8x 5x 89x 78x 11x 1x 10x 4x 6x 6x 1x 15x 5x 95x 76x 76x 19x 5x 25x 25x 5x 5x 20x 25x 5x 134x 134x 134x 134x 5x 7x 7x 5x 2x 2x 5x 3x 5x 2x 5x 141x 141x 141x 141x 141x 141x 141x 141x 141x 141x 141x 145x 141x 141x 141x 4x 141x 15x 141x 132x 132x 141x 1x 141x 141x 141x 141x 1x 3x 1x 141x 5x 23x 23x 23x 23x 23x 3x 23x 1x 1x 22x 6x 6x 23x 7x 16x 2x 23x 1x 23x 1x 22x 1x 23x 1x 22x 1x 23x 2x 4x 2x 4x 5x 5x 14x 14x 13x 5x 123x 5289x 5289x 5281x 8x 2x 6x 1x 5x 2x 3x 2x 1x 8x 5x 2x 1x 44x 1x 1x 1x 1x 1x 2x 18x 2x 5x 5x 5x 5x 5x 15x 2x 2x 3x 1x 5x 7x 15x 12x 5x 1x 1x 1x 1x 5x 39x 5x 17x 5x 28x 28x 28x 4x 24x 24x 12x 12x 24x 12x 12x 8x 4x 24x 5x 24x 24x 5x 18x 18x 5x 5x 6x 6x 6x 6x 6x 6x 5x 57x 116x 5x 8x 8x 8x 9x 9x 9x 7x 1x 5x 44x 44x 44x 44x 39x 39x 39x 39x 39x 44x 1x 5x 5x 5x 41x 1x 40x 40x 40x 40x 40x 40x 40x 5x 73x 5x 94x 94x 5x 126x 126x 12x 126x 118x 126x 1x 126x 5x 74x 5x 1x 2x 2x | import { Selectors } from './selectors' import { Defaults } from './defaults' /** * Firefox extensions doesn't allow 'innerHTML' to be set but we can trick it * + aid for minifiers not to remove the trick */ const FF_EXTENSION_TRICK = { x: true } /** * Determines if the runtime is a browser */ export const isBrowser = typeof window !== 'undefined' /** * Determines if the browser is supported */ export const isBrowserSupported = isBrowser && 'MutationObserver' in window /** * Injects a string of CSS styles to the style node in the document head */ export const injectCSS = css => { Eif (isBrowserSupported) { const style = document.createElement('style') style.type = 'text/css' style.innerHTML = css document.head.insertBefore(style, document.head.firstChild) } } /** * Ponyfill for Array.from; converts iterable values to an array */ export const toArray = value => [].slice.call(value) /** * Sets the content of a tooltip */ export const setContent = (contentEl, props) => { if (props.content instanceof Element) { setInnerHTML(contentEl, '') contentEl.appendChild(props.content) } else { contentEl[props.allowHTML ? 'innerHTML' : 'textContent'] = props.content } } /** * Determines if an element can receive focus */ export const elementCanReceiveFocus = el => el instanceof Element ? matches.call( el, 'a[href],area[href],button,details,input,textarea,select,iframe,[tabindex]' ) && !el.hasAttribute('disabled') : true /** * Applies a transition duration to a list of elements */ export const applyTransitionDuration = (els, value) => { els.filter(Boolean).forEach(el => { el.style.transitionDuration = `${value}ms` }) } /** * Returns the child elements of a popper element */ export const getChildren = popper => { const select = s => popper.querySelector(s) return { tooltip: select(Selectors.TOOLTIP), backdrop: select(Selectors.BACKDROP), content: select(Selectors.CONTENT), arrow: select(Selectors.ARROW) || select(Selectors.ROUND_ARROW) } } /** * Determines if a value is a plain object */ export const isPlainObject = value => ({}.toString.call(value) === '[object Object]') /** * Creates and returns a div element */ export const div = () => document.createElement('div') /** * Sets the innerHTML of an element while tricking linters & minifiers */ export const setInnerHTML = (el, html) => { el[FF_EXTENSION_TRICK.x && 'innerHTML'] = html instanceof Element ? html[FF_EXTENSION_TRICK.x && 'innerHTML'] : html } /** * Returns an array of elements based on the value */ export const getArrayOfElements = value => { if (value instanceof Element || isPlainObject(value)) { return [value] } if (value instanceof NodeList) { return toArray(value) } if (Array.isArray(value)) { return value } try { return toArray(document.querySelectorAll(value)) } catch (e) { return [] } } /** * Determines if a value is numeric */ export const isNumeric = value => !isNaN(value) && !isNaN(parseFloat(value)) /** * Returns a value at a given index depending on if it's an array or number */ export const getValue = (value, index, defaultValue) => { if (Array.isArray(value)) { const v = value[index] return v == null ? defaultValue : v } return value } /** * Creates an arrow element and returns it */ export const createArrowElement = arrowType => { const arrow = div() if (arrowType === 'round') { arrow.className = 'tippy-roundarrow' setInnerHTML( arrow, '<svg viewBox="0 0 24 8" xmlns="http://www.w3.org/2000/svg"><path d="M3 8s2.021-.015 5.253-4.218C9.584 2.051 10.797 1.007 12 1c1.203-.007 2.416 1.035 3.761 2.782C19.012 8.005 21 8 21 8H3z"/></svg>' ) } else { arrow.className = 'tippy-arrow' } return arrow } /** * Creates a backdrop element and returns it */ export const createBackdropElement = () => { const backdrop = div() backdrop.className = 'tippy-backdrop' backdrop.setAttribute('data-state', 'hidden') return backdrop } /** * Adds interactive attributes */ export const addInteractive = (popper, tooltip) => { popper.setAttribute('tabindex', '-1') tooltip.setAttribute('data-interactive', '') } /** * Removes interactive attributes */ export const removeInteractive = (popper, tooltip) => { popper.removeAttribute('tabindex') tooltip.removeAttribute('data-interactive') } /** * Adds inertia attribute */ export const addInertia = tooltip => { tooltip.setAttribute('data-inertia', '') } /** * Removes inertia attribute */ export const removeInertia = tooltip => { tooltip.removeAttribute('data-inertia') } /** * Constructs the popper element and returns it */ export const createPopperElement = (id, props) => { const popper = div() popper.className = 'tippy-popper' popper.setAttribute('role', 'tooltip') popper.id = `tippy-${id}` popper.style.zIndex = props.zIndex const tooltip = div() tooltip.className = 'tippy-tooltip' tooltip.setAttribute('data-size', props.size) tooltip.setAttribute('data-animation', props.animation) tooltip.setAttribute('data-state', 'hidden') props.theme.split(' ').forEach(t => { tooltip.classList.add(t + '-theme') }) const content = div() content.className = 'tippy-content' if (props.interactive) { addInteractive(popper, tooltip) } if (props.arrow) { tooltip.appendChild(createArrowElement(props.arrowType)) } if (props.animateFill) { tooltip.appendChild(createBackdropElement()) tooltip.setAttribute('data-animatefill', '') } if (props.inertia) { tooltip.setAttribute('data-inertia', '') } setContent(content, props) tooltip.appendChild(content) popper.appendChild(tooltip) popper.addEventListener('focusout', e => { Eif ( e.relatedTarget && popper._tippy && !closestCallback(e.relatedTarget, el => el === popper) && popper._tippy.props.shouldPopperHideOnBlur(e) ) { popper._tippy.hide() } }) return popper } /** * Updates the popper element based on the new props */ export const updatePopperElement = (popper, prevProps, nextProps) => { const { tooltip, content, backdrop, arrow } = getChildren(popper) popper.style.zIndex = nextProps.zIndex tooltip.setAttribute('data-size', nextProps.size) tooltip.setAttribute('data-animation', nextProps.animation) if (prevProps.content !== nextProps.content) { setContent(content, nextProps) } // animateFill if (!prevProps.animateFill && nextProps.animateFill) { tooltip.appendChild(createBackdropElement()) tooltip.setAttribute('data-animatefill', '') } else if (prevProps.animateFill && !nextProps.animateFill) { tooltip.removeChild(backdrop) tooltip.removeAttribute('data-animatefill') } // arrow if (!prevProps.arrow && nextProps.arrow) { tooltip.appendChild(createArrowElement(nextProps.arrowType)) } else if (prevProps.arrow && !nextProps.arrow) { tooltip.removeChild(arrow) } // arrowType if ( prevProps.arrow && nextProps.arrow && prevProps.arrowType !== nextProps.arrowType ) { tooltip.replaceChild(createArrowElement(nextProps.arrowType), arrow) } // interactive if (!prevProps.interactive && nextProps.interactive) { addInteractive(popper, tooltip) } else if (prevProps.interactive && !nextProps.interactive) { removeInteractive(popper, tooltip) } // inertia if (!prevProps.inertia && nextProps.inertia) { addInertia(tooltip) } else if (prevProps.inertia && !nextProps.inertia) { removeInertia(tooltip) } // theme if (prevProps.theme !== nextProps.theme) { prevProps.theme.split(' ').forEach(theme => { tooltip.classList.remove(theme + '-theme') }) nextProps.theme.split(' ').forEach(theme => { tooltip.classList.add(theme + '-theme') }) } } /** * Hides all visible poppers on the document */ export const hideAllPoppers = excludeTippy => { toArray(document.querySelectorAll(Selectors.POPPER)).forEach(popper => { const tip = popper._tippy if ( tip && tip.props.hideOnClick === true && (!excludeTippy || popper !== excludeTippy.popper) ) { tip.hide() } }) } /** * Returns an object of optional props from data-tippy-* attributes */ export const getDataAttributeOptions = reference => Object.keys(Defaults).reduce((acc, key) => { const valueAsString = ( reference.getAttribute(`data-tippy-${key}`) || '' ).trim() if (!valueAsString) { return acc } if (valueAsString === 'true') { acc[key] = true } else if (valueAsString === 'false') { acc[key] = false } else if (isNumeric(valueAsString)) { acc[key] = Number(valueAsString) } else if (key !== 'target' && valueAsString[0] === '[') { acc[key] = JSON.parse(valueAsString) } else { acc[key] = valueAsString } return acc }, {}) /** * Polyfills the virtual reference (plain object) with needed props * Mutating because DOM elements are mutated, adds _tippy property */ export const polyfillVirtualReferenceProps = virtualReference => { const polyfills = { isVirtual: true, attributes: virtualReference.attributes || {}, setAttribute(key, value) { virtualReference.attributes[key] = value }, getAttribute(key) { return virtualReference.attributes[key] }, removeAttribute(key) { delete virtualReference.attributes[key] }, hasAttribute(key) { return key in virtualReference.attributes }, addEventListener() {}, removeEventListener() {}, classList: { classNames: {}, add(key) { virtualReference.classList.classNames[key] = true }, remove(key) { delete virtualReference.classList.classNames[key] }, contains(key) { return key in virtualReference.classList.classNames } } } for (const key in polyfills) { virtualReference[key] = polyfills[key] } return virtualReference } /** * Ponyfill for Element.prototype.matches */ export const matches = (() => { Eif (isBrowser) { const e = Element.prototype return ( e.matches || e.matchesSelector || e.webkitMatchesSelector || e.mozMatchesSelector || e.msMatchesSelector ) } })() /** * Ponyfill for Element.prototype.closest */ export const closest = (element, parentSelector) => ( Element.prototype.closest || function(selector) { let el = this while (el) { if (matches.call(el, selector)) return el el = el.parentElement } } ).call(element, parentSelector) /** * Works like Element.prototype.closest, but uses a callback instead */ export const closestCallback = (element, callback) => { while (element) { if (callback(element)) return element element = element.parentElement } } /** * Focuses an element while preventing a scroll jump if it's not within the viewport */ export const focus = el => { const x = window.scrollX || window.pageXOffset const y = window.scrollY || window.pageYOffset el.focus() scroll(x, y) } /** * Triggers reflow */ export const reflow = popper => { void popper.offsetHeight } /** * Transforms the x/y axis ased on the placement */ export const transformAxisBasedOnPlacement = (axis, isVertical) => (isVertical ? axis : { X: 'Y', Y: 'X' }[axis]) || '' /** * Transforms the scale/translate numbers based on the placement */ export const transformNumbersBasedOnPlacement = ( type, numbers, isVertical, isReverse ) => { /** * Avoid destructuring because a large boilerplate function is generated * by Babel */ const a = numbers[0] const b = numbers[1] if (!a && !b) { return '' } const transforms = { scale: (() => { if (!b) { return `${a}` } else { return isVertical ? `${a}, ${b}` : `${b}, ${a}` } })(), translate: (() => { if (!b) { return isReverse ? `${-a}px` : `${a}px` } else { if (isVertical) { return isReverse ? `${a}px, ${-b}px` : `${a}px, ${b}px` } else { return isReverse ? `${-b}px, ${a}px` : `${b}px, ${a}px` } } })() } return transforms[type] } /** * Returns the axis for a CSS function (translate or scale) */ export const getTransformAxis = (str, cssFunction) => { const match = str.match(new RegExp(cssFunction + '([XY])')) return match ? match[1] : '' } /** * Returns the numbers given to the CSS function */ export const getTransformNumbers = (str, regex) => { const match = str.match(regex) return match ? match[1].split(',').map(parseFloat) : [] } export const TRANSFORM_NUMBER_RE = { translate: /translateX?Y?\(([^)]+)\)/, scale: /scaleX?Y?\(([^)]+)\)/ } /** * Computes the arrow's transform so that it is correct for any placement */ export const computeArrowTransform = (arrow, arrowTransform) => { const placement = getPopperPlacement(closest(arrow, Selectors.POPPER)) const isVertical = placement === 'top' || placement === 'bottom' const isReverse = placement === 'right' || placement === 'bottom' const matches = { translate: { axis: getTransformAxis(arrowTransform, 'translate'), numbers: getTransformNumbers( arrowTransform, TRANSFORM_NUMBER_RE.translate ) }, scale: { axis: getTransformAxis(arrowTransform, 'scale'), numbers: getTransformNumbers(arrowTransform, TRANSFORM_NUMBER_RE.scale) } } const computedTransform = arrowTransform .replace( TRANSFORM_NUMBER_RE.translate, `translate${transformAxisBasedOnPlacement( matches.translate.axis, isVertical )}(${transformNumbersBasedOnPlacement( 'translate', matches.translate.numbers, isVertical, isReverse )})` ) .replace( TRANSFORM_NUMBER_RE.scale, `scale${transformAxisBasedOnPlacement( matches.scale.axis, isVertical )}(${transformNumbersBasedOnPlacement( 'scale', matches.scale.numbers, isVertical, isReverse )})` ) arrow.style[prefix('transform')] = computedTransform } /** * Sets the visibility state of a popper so it can begin to transition in or out */ export const setVisibilityState = (els, type) => { els.filter(Boolean).forEach(el => { el.setAttribute('data-state', type) }) } /** * Prefixes a CSS property with the one supported by the browser */ export const prefix = property => { const prefixes = ['', 'webkit'] const upperProp = property[0].toUpperCase() + property.slice(1) for (let i = 0; i < prefixes.length; i++) { const prefix = prefixes[i] const prefixedProp = prefix ? prefix + upperProp : property if (typeof document.body.style[prefixedProp] !== 'undefined') { return prefixedProp } } return null } /** * Update's a popper's position and runs a callback onUpdate; wrapper for async updates */ export const updatePopperPosition = ( popperInstance, callback, updateAlreadyCalled ) => { const { popper, options } = popperInstance const onCreate = options.onCreate const onUpdate = options.onUpdate options.onCreate = options.onUpdate = () => { reflow(popper) callback && callback() onUpdate() options.onCreate = onCreate options.onUpdate = onUpdate } if (!updateAlreadyCalled) { popperInstance.scheduleUpdate() } } /** * Defers a function's execution until the call stack has cleared */ export const defer = fn => { setTimeout(fn, 1) } /** * Determines if the mouse cursor is outside of the popper's interactive border * region */ export const isCursorOutsideInteractiveBorder = ( popperPlacement, popperRect, event, props ) => { if (!popperPlacement) { return true } const { clientX: x, clientY: y } = event const { interactiveBorder, distance } = props const exceedsTop = popperRect.top - y > (popperPlacement === 'top' ? interactiveBorder + distance : interactiveBorder) const exceedsBottom = y - popperRect.bottom > (popperPlacement === 'bottom' ? interactiveBorder + distance : interactiveBorder) const exceedsLeft = popperRect.left - x > (popperPlacement === 'left' ? interactiveBorder + distance : interactiveBorder) const exceedsRight = x - popperRect.right > (popperPlacement === 'right' ? interactiveBorder + distance : interactiveBorder) return exceedsTop || exceedsBottom || exceedsLeft || exceedsRight } /** * Returns the distance offset, taking into account the default offset due to * the transform: translate() rule in CSS */ export const getOffsetDistanceInPx = (distance, defaultDistance) => -(distance - defaultDistance) + 'px' /** * Returns the popper's placement, ignoring shifting (top-start, etc) */ export const getPopperPlacement = popper => { const fullPlacement = popper.getAttribute('x-placement') return fullPlacement ? fullPlacement.split('-')[0] : '' } /** * Evaluates props */ export const evaluateProps = (reference, props) => { const out = { ...props, ...(props.performance ? {} : getDataAttributeOptions(reference)) } if (out.arrow) { out.animateFill = false } if (typeof out.appendTo === 'function') { out.appendTo = props.appendTo(reference) } if (typeof out.content === 'function') { out.content = props.content(reference) } return out } /** * Add/remove transitionend listener from tooltip */ export const toggleTransitionEndListener = (tooltip, action, listener) => { tooltip[action + 'EventListener']('transitionend', listener) } /** * Debounce utility */ export const debounce = (fn, ms) => { let timeoutId return function() { clearTimeout(timeoutId) timeoutId = setTimeout(() => fn.apply(this, arguments), ms) } } |