polyfill.mjs 3.9 KB

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