项目原始demo,不改动
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
Bu depo arşivlendi. Dosyaları görüntüleyebilir ve klonlayabilirsiniz ama işlem gönderemez ve konu/değişiklik isteği açamazsınız.
 
 
 
 

296 satır
8.4 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = exports.Ripple = void 0;
  6. require("../../../src/directives/ripple/VRipple.sass");
  7. var _console = require("../../util/console");
  8. var _helpers = require("../../util/helpers");
  9. // Styles
  10. // Utilities
  11. function transform(el, value) {
  12. el.style['transform'] = value;
  13. el.style['webkitTransform'] = value;
  14. }
  15. function opacity(el, value) {
  16. el.style['opacity'] = value.toString();
  17. }
  18. function isTouchEvent(e) {
  19. return e.constructor.name === 'TouchEvent';
  20. }
  21. function isKeyboardEvent(e) {
  22. return e.constructor.name === 'KeyboardEvent';
  23. }
  24. var calculate = function calculate(e, el) {
  25. var value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  26. var localX = 0;
  27. var localY = 0;
  28. if (!isKeyboardEvent(e)) {
  29. var offset = el.getBoundingClientRect();
  30. var target = isTouchEvent(e) ? e.touches[e.touches.length - 1] : e;
  31. localX = target.clientX - offset.left;
  32. localY = target.clientY - offset.top;
  33. }
  34. var radius = 0;
  35. var scale = 0.3;
  36. if (el._ripple && el._ripple.circle) {
  37. scale = 0.15;
  38. radius = el.clientWidth / 2;
  39. radius = value.center ? radius : radius + Math.sqrt(Math.pow(localX - radius, 2) + Math.pow(localY - radius, 2)) / 4;
  40. } else {
  41. radius = Math.sqrt(Math.pow(el.clientWidth, 2) + Math.pow(el.clientHeight, 2)) / 2;
  42. }
  43. var centerX = "".concat((el.clientWidth - radius * 2) / 2, "px");
  44. var centerY = "".concat((el.clientHeight - radius * 2) / 2, "px");
  45. var x = value.center ? centerX : "".concat(localX - radius, "px");
  46. var y = value.center ? centerY : "".concat(localY - radius, "px");
  47. return {
  48. radius: radius,
  49. scale: scale,
  50. x: x,
  51. y: y,
  52. centerX: centerX,
  53. centerY: centerY
  54. };
  55. };
  56. var ripples = {
  57. /* eslint-disable max-statements */
  58. show: function show(e, el) {
  59. var value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  60. if (!el._ripple || !el._ripple.enabled) {
  61. return;
  62. }
  63. var container = document.createElement('span');
  64. var animation = document.createElement('span');
  65. container.appendChild(animation);
  66. container.className = 'v-ripple__container';
  67. if (value.class) {
  68. container.className += " ".concat(value.class);
  69. }
  70. var _calculate = calculate(e, el, value),
  71. radius = _calculate.radius,
  72. scale = _calculate.scale,
  73. x = _calculate.x,
  74. y = _calculate.y,
  75. centerX = _calculate.centerX,
  76. centerY = _calculate.centerY;
  77. var size = "".concat(radius * 2, "px");
  78. animation.className = 'v-ripple__animation';
  79. animation.style.width = size;
  80. animation.style.height = size;
  81. el.appendChild(container);
  82. var computed = window.getComputedStyle(el);
  83. if (computed && computed.position === 'static') {
  84. el.style.position = 'relative';
  85. el.dataset.previousPosition = 'static';
  86. }
  87. animation.classList.add('v-ripple__animation--enter');
  88. animation.classList.add('v-ripple__animation--visible');
  89. transform(animation, "translate(".concat(x, ", ").concat(y, ") scale3d(").concat(scale, ",").concat(scale, ",").concat(scale, ")"));
  90. opacity(animation, 0);
  91. animation.dataset.activated = String(performance.now());
  92. setTimeout(function () {
  93. animation.classList.remove('v-ripple__animation--enter');
  94. animation.classList.add('v-ripple__animation--in');
  95. transform(animation, "translate(".concat(centerX, ", ").concat(centerY, ") scale3d(1,1,1)"));
  96. opacity(animation, 0.25);
  97. }, 0);
  98. },
  99. hide: function hide(el) {
  100. if (!el || !el._ripple || !el._ripple.enabled) return;
  101. var ripples = el.getElementsByClassName('v-ripple__animation');
  102. if (ripples.length === 0) return;
  103. var animation = ripples[ripples.length - 1];
  104. if (animation.dataset.isHiding) return;else animation.dataset.isHiding = 'true';
  105. var diff = performance.now() - Number(animation.dataset.activated);
  106. var delay = Math.max(250 - diff, 0);
  107. setTimeout(function () {
  108. animation.classList.remove('v-ripple__animation--in');
  109. animation.classList.add('v-ripple__animation--out');
  110. opacity(animation, 0);
  111. setTimeout(function () {
  112. var ripples = el.getElementsByClassName('v-ripple__animation');
  113. if (ripples.length === 1 && el.dataset.previousPosition) {
  114. el.style.position = el.dataset.previousPosition;
  115. delete el.dataset.previousPosition;
  116. }
  117. animation.parentNode && el.removeChild(animation.parentNode);
  118. }, 300);
  119. }, delay);
  120. }
  121. };
  122. function isRippleEnabled(value) {
  123. return typeof value === 'undefined' || !!value;
  124. }
  125. function rippleShow(e) {
  126. var value = {};
  127. var element = e.currentTarget;
  128. if (!element || !element._ripple || element._ripple.touched) return;
  129. if (isTouchEvent(e)) {
  130. element._ripple.touched = true;
  131. element._ripple.isTouch = true;
  132. } else {
  133. // It's possible for touch events to fire
  134. // as mouse events on Android/iOS, this
  135. // will skip the event call if it has
  136. // already been registered as touch
  137. if (element._ripple.isTouch) return;
  138. }
  139. value.center = element._ripple.centered || isKeyboardEvent(e);
  140. if (element._ripple.class) {
  141. value.class = element._ripple.class;
  142. }
  143. ripples.show(e, element, value);
  144. }
  145. function rippleHide(e) {
  146. var element = e.currentTarget;
  147. if (!element) return;
  148. window.setTimeout(function () {
  149. if (element._ripple) {
  150. element._ripple.touched = false;
  151. }
  152. });
  153. ripples.hide(element);
  154. }
  155. var keyboardRipple = false;
  156. function keyboardRippleShow(e) {
  157. if (!keyboardRipple && (e.keyCode === _helpers.keyCodes.enter || e.keyCode === _helpers.keyCodes.space)) {
  158. keyboardRipple = true;
  159. rippleShow(e);
  160. }
  161. }
  162. function keyboardRippleHide(e) {
  163. keyboardRipple = false;
  164. rippleHide(e);
  165. }
  166. function updateRipple(el, binding, wasEnabled) {
  167. var enabled = isRippleEnabled(binding.value);
  168. if (!enabled) {
  169. ripples.hide(el);
  170. }
  171. el._ripple = el._ripple || {};
  172. el._ripple.enabled = enabled;
  173. var value = binding.value || {};
  174. if (value.center) {
  175. el._ripple.centered = true;
  176. }
  177. if (value.class) {
  178. el._ripple.class = binding.value.class;
  179. }
  180. if (value.circle) {
  181. el._ripple.circle = value.circle;
  182. }
  183. if (enabled && !wasEnabled) {
  184. el.addEventListener('touchstart', rippleShow, {
  185. passive: true
  186. });
  187. el.addEventListener('touchend', rippleHide, {
  188. passive: true
  189. });
  190. el.addEventListener('touchcancel', rippleHide);
  191. el.addEventListener('mousedown', rippleShow);
  192. el.addEventListener('mouseup', rippleHide);
  193. el.addEventListener('mouseleave', rippleHide);
  194. el.addEventListener('keydown', keyboardRippleShow);
  195. el.addEventListener('keyup', keyboardRippleHide); // Anchor tags can be dragged, causes other hides to fail - #1537
  196. el.addEventListener('dragstart', rippleHide, {
  197. passive: true
  198. });
  199. } else if (!enabled && wasEnabled) {
  200. removeListeners(el);
  201. }
  202. }
  203. function removeListeners(el) {
  204. el.removeEventListener('mousedown', rippleShow);
  205. el.removeEventListener('touchstart', rippleShow);
  206. el.removeEventListener('touchend', rippleHide);
  207. el.removeEventListener('touchcancel', rippleHide);
  208. el.removeEventListener('mouseup', rippleHide);
  209. el.removeEventListener('mouseleave', rippleHide);
  210. el.removeEventListener('keydown', keyboardRippleShow);
  211. el.removeEventListener('keyup', keyboardRippleHide);
  212. el.removeEventListener('dragstart', rippleHide);
  213. }
  214. function directive(el, binding, node) {
  215. updateRipple(el, binding, false);
  216. if (process.env.NODE_ENV === 'development') {
  217. // warn if an inline element is used, waiting for el to be in the DOM first
  218. node.context && node.context.$nextTick(function () {
  219. var computed = window.getComputedStyle(el);
  220. if (computed && computed.display === 'inline') {
  221. var context = node.fnOptions ? [node.fnOptions, node.context] : [node.componentInstance];
  222. _console.consoleWarn.apply(void 0, ['v-ripple can only be used on block-level elements'].concat(context));
  223. }
  224. });
  225. }
  226. }
  227. function unbind(el) {
  228. delete el._ripple;
  229. removeListeners(el);
  230. }
  231. function update(el, binding) {
  232. if (binding.value === binding.oldValue) {
  233. return;
  234. }
  235. var wasEnabled = isRippleEnabled(binding.oldValue);
  236. updateRipple(el, binding, wasEnabled);
  237. }
  238. var Ripple = {
  239. bind: directive,
  240. unbind: unbind,
  241. update: update
  242. };
  243. exports.Ripple = Ripple;
  244. var _default = Ripple;
  245. exports.default = _default;
  246. //# sourceMappingURL=index.js.map