ion-ripple-effect.cjs.entry.js 5.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. 'use strict';
  5. Object.defineProperty(exports, '__esModule', { value: true });
  6. const index = require('./index-2e236a04.js');
  7. const ionicGlobal = require('./ionic-global-6dea5a96.js');
  8. require('./index-cc858e97.js');
  9. const rippleEffectCss = ":host{left:0;right:0;top:0;bottom:0;position:absolute;contain:strict;pointer-events:none}:host(.unbounded){contain:layout size style}.ripple-effect{border-radius:50%;position:absolute;background-color:currentColor;color:inherit;contain:strict;opacity:0;-webkit-animation:225ms rippleAnimation forwards, 75ms fadeInAnimation forwards;animation:225ms rippleAnimation forwards, 75ms fadeInAnimation forwards;will-change:transform, opacity;pointer-events:none}.fade-out{-webkit-transform:translate(var(--translate-end)) scale(var(--final-scale, 1));transform:translate(var(--translate-end)) scale(var(--final-scale, 1));-webkit-animation:150ms fadeOutAnimation forwards;animation:150ms fadeOutAnimation forwards}@-webkit-keyframes rippleAnimation{from{-webkit-animation-timing-function:cubic-bezier(0.4, 0, 0.2, 1);animation-timing-function:cubic-bezier(0.4, 0, 0.2, 1);-webkit-transform:scale(1);transform:scale(1)}to{-webkit-transform:translate(var(--translate-end)) scale(var(--final-scale, 1));transform:translate(var(--translate-end)) scale(var(--final-scale, 1))}}@keyframes rippleAnimation{from{-webkit-animation-timing-function:cubic-bezier(0.4, 0, 0.2, 1);animation-timing-function:cubic-bezier(0.4, 0, 0.2, 1);-webkit-transform:scale(1);transform:scale(1)}to{-webkit-transform:translate(var(--translate-end)) scale(var(--final-scale, 1));transform:translate(var(--translate-end)) scale(var(--final-scale, 1))}}@-webkit-keyframes fadeInAnimation{from{-webkit-animation-timing-function:linear;animation-timing-function:linear;opacity:0}to{opacity:0.16}}@keyframes fadeInAnimation{from{-webkit-animation-timing-function:linear;animation-timing-function:linear;opacity:0}to{opacity:0.16}}@-webkit-keyframes fadeOutAnimation{from{-webkit-animation-timing-function:linear;animation-timing-function:linear;opacity:0.16}to{opacity:0}}@keyframes fadeOutAnimation{from{-webkit-animation-timing-function:linear;animation-timing-function:linear;opacity:0.16}to{opacity:0}}";
  10. const IonRippleEffectStyle0 = rippleEffectCss;
  11. const RippleEffect = class {
  12. constructor(hostRef) {
  13. index.registerInstance(this, hostRef);
  14. this.type = 'bounded';
  15. }
  16. /**
  17. * Adds the ripple effect to the parent element.
  18. *
  19. * @param x The horizontal coordinate of where the ripple should start.
  20. * @param y The vertical coordinate of where the ripple should start.
  21. */
  22. async addRipple(x, y) {
  23. return new Promise((resolve) => {
  24. index.readTask(() => {
  25. const rect = this.el.getBoundingClientRect();
  26. const width = rect.width;
  27. const height = rect.height;
  28. const hypotenuse = Math.sqrt(width * width + height * height);
  29. const maxDim = Math.max(height, width);
  30. const maxRadius = this.unbounded ? maxDim : hypotenuse + PADDING;
  31. const initialSize = Math.floor(maxDim * INITIAL_ORIGIN_SCALE);
  32. const finalScale = maxRadius / initialSize;
  33. let posX = x - rect.left;
  34. let posY = y - rect.top;
  35. if (this.unbounded) {
  36. posX = width * 0.5;
  37. posY = height * 0.5;
  38. }
  39. const styleX = posX - initialSize * 0.5;
  40. const styleY = posY - initialSize * 0.5;
  41. const moveX = width * 0.5 - posX;
  42. const moveY = height * 0.5 - posY;
  43. index.writeTask(() => {
  44. const div = document.createElement('div');
  45. div.classList.add('ripple-effect');
  46. const style = div.style;
  47. style.top = styleY + 'px';
  48. style.left = styleX + 'px';
  49. style.width = style.height = initialSize + 'px';
  50. style.setProperty('--final-scale', `${finalScale}`);
  51. style.setProperty('--translate-end', `${moveX}px, ${moveY}px`);
  52. const container = this.el.shadowRoot || this.el;
  53. container.appendChild(div);
  54. setTimeout(() => {
  55. resolve(() => {
  56. removeRipple(div);
  57. });
  58. }, 225 + 100);
  59. });
  60. });
  61. });
  62. }
  63. get unbounded() {
  64. return this.type === 'unbounded';
  65. }
  66. render() {
  67. const mode = ionicGlobal.getIonMode(this);
  68. return (index.h(index.Host, { key: '40c7f73e7f5f67e29f83e1236a61c6e1c9943c42', role: "presentation", class: {
  69. [mode]: true,
  70. unbounded: this.unbounded,
  71. } }));
  72. }
  73. get el() { return index.getElement(this); }
  74. };
  75. const removeRipple = (ripple) => {
  76. ripple.classList.add('fade-out');
  77. setTimeout(() => {
  78. ripple.remove();
  79. }, 200);
  80. };
  81. const PADDING = 10;
  82. const INITIAL_ORIGIN_SCALE = 0.5;
  83. RippleEffect.style = IonRippleEffectStyle0;
  84. exports.ion_ripple_effect = RippleEffect;