polyfill.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*!
  2. * @pixi/polyfill - v6.5.10
  3. * Compiled Thu, 06 Jul 2023 15:25:11 UTC
  4. *
  5. * @pixi/polyfill is licensed under the MIT License.
  6. * http://www.opensource.org/licenses/mit-license
  7. */
  8. 'use strict';
  9. var Polyfill = require('promise-polyfill');
  10. var objectAssign = require('object-assign');
  11. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  12. var Polyfill__default = /*#__PURE__*/_interopDefaultLegacy(Polyfill);
  13. var objectAssign__default = /*#__PURE__*/_interopDefaultLegacy(objectAssign);
  14. if (typeof globalThis === 'undefined') {
  15. if (typeof self !== 'undefined') {
  16. // covers browsers
  17. // @ts-expect-error not-writable ts(2540) error only on node
  18. self.globalThis = self;
  19. }
  20. else if (typeof global !== 'undefined') {
  21. // covers versions of Node < 12
  22. // @ts-expect-error not-writable ts(2540) error only on node
  23. global.globalThis = global;
  24. }
  25. }
  26. // Support for IE 9 - 11 which does not include Promises
  27. if (!globalThis.Promise) {
  28. globalThis.Promise = Polyfill__default["default"];
  29. }
  30. // References:
  31. if (!Object.assign) {
  32. Object.assign = objectAssign__default["default"];
  33. }
  34. // References:
  35. // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
  36. // https://gist.github.com/1579671
  37. // http://updates.html5rocks.com/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision
  38. // https://gist.github.com/timhall/4078614
  39. // https://github.com/Financial-Times/polyfill-service/tree/master/polyfills/requestAnimationFrame
  40. // Expected to be used with Browserfiy
  41. // Browserify automatically detects the use of `global` and passes the
  42. // correct reference of `global`, `globalThis`, and finally `window`
  43. var ONE_FRAME_TIME = 16;
  44. // Date.now
  45. if (!(Date.now && Date.prototype.getTime)) {
  46. Date.now = function now() {
  47. return new Date().getTime();
  48. };
  49. }
  50. // performance.now
  51. if (!(globalThis.performance && globalThis.performance.now)) {
  52. var startTime_1 = Date.now();
  53. if (!globalThis.performance) {
  54. globalThis.performance = {};
  55. }
  56. globalThis.performance.now = function () { return Date.now() - startTime_1; };
  57. }
  58. // requestAnimationFrame
  59. var lastTime = Date.now();
  60. var vendors = ['ms', 'moz', 'webkit', 'o'];
  61. for (var x = 0; x < vendors.length && !globalThis.requestAnimationFrame; ++x) {
  62. var p = vendors[x];
  63. globalThis.requestAnimationFrame = globalThis[p + "RequestAnimationFrame"];
  64. globalThis.cancelAnimationFrame = globalThis[p + "CancelAnimationFrame"]
  65. || globalThis[p + "CancelRequestAnimationFrame"];
  66. }
  67. if (!globalThis.requestAnimationFrame) {
  68. globalThis.requestAnimationFrame = function (callback) {
  69. if (typeof callback !== 'function') {
  70. throw new TypeError(callback + "is not a function");
  71. }
  72. var currentTime = Date.now();
  73. var delay = ONE_FRAME_TIME + lastTime - currentTime;
  74. if (delay < 0) {
  75. delay = 0;
  76. }
  77. lastTime = currentTime;
  78. return globalThis.self.setTimeout(function () {
  79. lastTime = Date.now();
  80. callback(performance.now());
  81. }, delay);
  82. };
  83. }
  84. if (!globalThis.cancelAnimationFrame) {
  85. globalThis.cancelAnimationFrame = function (id) { return clearTimeout(id); };
  86. }
  87. // References:
  88. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  89. if (!Math.sign) {
  90. Math.sign = function mathSign(x) {
  91. x = Number(x);
  92. if (x === 0 || isNaN(x)) {
  93. return x;
  94. }
  95. return x > 0 ? 1 : -1;
  96. };
  97. }
  98. // References:
  99. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  100. if (!Number.isInteger) {
  101. Number.isInteger = function numberIsInteger(value) {
  102. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  103. };
  104. }
  105. if (!globalThis.ArrayBuffer) {
  106. globalThis.ArrayBuffer = Array;
  107. }
  108. if (!globalThis.Float32Array) {
  109. globalThis.Float32Array = Array;
  110. }
  111. if (!globalThis.Uint32Array) {
  112. globalThis.Uint32Array = Array;
  113. }
  114. if (!globalThis.Uint16Array) {
  115. globalThis.Uint16Array = Array;
  116. }
  117. if (!globalThis.Uint8Array) {
  118. globalThis.Uint8Array = Array;
  119. }
  120. if (!globalThis.Int32Array) {
  121. globalThis.Int32Array = Array;
  122. }
  123. //# sourceMappingURL=polyfill.js.map