ng-zorro-antd-core-polyfill.mjs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Use of this source code is governed by an MIT-style license that can be
  3. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  4. */
  5. const availablePrefixes = ['moz', 'ms', 'webkit'];
  6. function requestAnimationFramePolyfill() {
  7. let lastTime = 0;
  8. return function (callback) {
  9. const currTime = new Date().getTime();
  10. const timeToCall = Math.max(0, 16 - (currTime - lastTime));
  11. const id = window.setTimeout(() => {
  12. callback(currTime + timeToCall);
  13. }, timeToCall);
  14. lastTime = currTime + timeToCall;
  15. return id;
  16. };
  17. }
  18. function getRequestAnimationFrame() {
  19. if (typeof window === 'undefined') {
  20. return () => 0;
  21. }
  22. if (window.requestAnimationFrame) {
  23. // https://github.com/vuejs/vue/issues/4465
  24. return window.requestAnimationFrame.bind(window);
  25. }
  26. const prefix = availablePrefixes.filter(key => `${key}RequestAnimationFrame` in window)[0];
  27. return prefix ? window[`${prefix}RequestAnimationFrame`] : requestAnimationFramePolyfill();
  28. }
  29. function cancelRequestAnimationFrame(id) {
  30. if (typeof window === 'undefined') {
  31. return null;
  32. }
  33. if (window.cancelAnimationFrame) {
  34. return window.cancelAnimationFrame(id);
  35. }
  36. const prefix = availablePrefixes.filter(key => `${key}CancelAnimationFrame` in window || `${key}CancelRequestAnimationFrame` in window)[0];
  37. return prefix
  38. ? (window[`${prefix}CancelAnimationFrame`] ||
  39. window[`${prefix}CancelRequestAnimationFrame`])
  40. // @ts-ignore
  41. .call(this, id)
  42. : clearTimeout(id);
  43. }
  44. const reqAnimFrame = getRequestAnimationFrame();
  45. /**
  46. * Use of this source code is governed by an MIT-style license that can be
  47. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  48. */
  49. /**
  50. * Generated bundle index. Do not edit.
  51. */
  52. export { cancelRequestAnimationFrame, reqAnimFrame };
  53. //# sourceMappingURL=ng-zorro-antd-core-polyfill.mjs.map