polyfill.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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. (function () {
  9. 'use strict';
  10. "use strict";
  11. if (typeof globalThis === 'undefined') {
  12. if (typeof self !== 'undefined') {
  13. // covers browsers
  14. // @ts-expect-error not-writable ts(2540) error only on node
  15. self.globalThis = self;
  16. }
  17. else if (typeof global !== 'undefined') {
  18. // covers versions of Node < 12
  19. // @ts-expect-error not-writable ts(2540) error only on node
  20. global.globalThis = global;
  21. }
  22. }
  23. /**
  24. * @this {Promise}
  25. */
  26. function finallyConstructor(callback) {
  27. var constructor = this.constructor;
  28. return this.then(
  29. function(value) {
  30. // @ts-ignore
  31. return constructor.resolve(callback()).then(function() {
  32. return value;
  33. });
  34. },
  35. function(reason) {
  36. // @ts-ignore
  37. return constructor.resolve(callback()).then(function() {
  38. // @ts-ignore
  39. return constructor.reject(reason);
  40. });
  41. }
  42. );
  43. }
  44. function allSettled(arr) {
  45. var P = this;
  46. return new P(function(resolve, reject) {
  47. if (!(arr && typeof arr.length !== 'undefined')) {
  48. return reject(
  49. new TypeError(
  50. typeof arr +
  51. ' ' +
  52. arr +
  53. ' is not iterable(cannot read property Symbol(Symbol.iterator))'
  54. )
  55. );
  56. }
  57. var args = Array.prototype.slice.call(arr);
  58. if (args.length === 0) { return resolve([]); }
  59. var remaining = args.length;
  60. function res(i, val) {
  61. if (val && (typeof val === 'object' || typeof val === 'function')) {
  62. var then = val.then;
  63. if (typeof then === 'function') {
  64. then.call(
  65. val,
  66. function(val) {
  67. res(i, val);
  68. },
  69. function(e) {
  70. args[i] = { status: 'rejected', reason: e };
  71. if (--remaining === 0) {
  72. resolve(args);
  73. }
  74. }
  75. );
  76. return;
  77. }
  78. }
  79. args[i] = { status: 'fulfilled', value: val };
  80. if (--remaining === 0) {
  81. resolve(args);
  82. }
  83. }
  84. for (var i = 0; i < args.length; i++) {
  85. res(i, args[i]);
  86. }
  87. });
  88. }
  89. // Store setTimeout reference so promise-polyfill will be unaffected by
  90. // other code modifying setTimeout (like sinon.useFakeTimers())
  91. var setTimeoutFunc = setTimeout;
  92. function isArray(x) {
  93. return Boolean(x && typeof x.length !== 'undefined');
  94. }
  95. function noop() {}
  96. // Polyfill for Function.prototype.bind
  97. function bind(fn, thisArg) {
  98. return function() {
  99. fn.apply(thisArg, arguments);
  100. };
  101. }
  102. /**
  103. * @constructor
  104. * @param {Function} fn
  105. */
  106. function Promise$1(fn) {
  107. if (!(this instanceof Promise$1))
  108. { throw new TypeError('Promises must be constructed via new'); }
  109. if (typeof fn !== 'function') { throw new TypeError('not a function'); }
  110. /** @type {!number} */
  111. this._state = 0;
  112. /** @type {!boolean} */
  113. this._handled = false;
  114. /** @type {Promise|undefined} */
  115. this._value = undefined;
  116. /** @type {!Array<!Function>} */
  117. this._deferreds = [];
  118. doResolve(fn, this);
  119. }
  120. function handle(self, deferred) {
  121. while (self._state === 3) {
  122. self = self._value;
  123. }
  124. if (self._state === 0) {
  125. self._deferreds.push(deferred);
  126. return;
  127. }
  128. self._handled = true;
  129. Promise$1._immediateFn(function() {
  130. var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
  131. if (cb === null) {
  132. (self._state === 1 ? resolve : reject)(deferred.promise, self._value);
  133. return;
  134. }
  135. var ret;
  136. try {
  137. ret = cb(self._value);
  138. } catch (e) {
  139. reject(deferred.promise, e);
  140. return;
  141. }
  142. resolve(deferred.promise, ret);
  143. });
  144. }
  145. function resolve(self, newValue) {
  146. try {
  147. // Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
  148. if (newValue === self)
  149. { throw new TypeError('A promise cannot be resolved with itself.'); }
  150. if (
  151. newValue &&
  152. (typeof newValue === 'object' || typeof newValue === 'function')
  153. ) {
  154. var then = newValue.then;
  155. if (newValue instanceof Promise$1) {
  156. self._state = 3;
  157. self._value = newValue;
  158. finale(self);
  159. return;
  160. } else if (typeof then === 'function') {
  161. doResolve(bind(then, newValue), self);
  162. return;
  163. }
  164. }
  165. self._state = 1;
  166. self._value = newValue;
  167. finale(self);
  168. } catch (e) {
  169. reject(self, e);
  170. }
  171. }
  172. function reject(self, newValue) {
  173. self._state = 2;
  174. self._value = newValue;
  175. finale(self);
  176. }
  177. function finale(self) {
  178. if (self._state === 2 && self._deferreds.length === 0) {
  179. Promise$1._immediateFn(function() {
  180. if (!self._handled) {
  181. Promise$1._unhandledRejectionFn(self._value);
  182. }
  183. });
  184. }
  185. for (var i = 0, len = self._deferreds.length; i < len; i++) {
  186. handle(self, self._deferreds[i]);
  187. }
  188. self._deferreds = null;
  189. }
  190. /**
  191. * @constructor
  192. */
  193. function Handler(onFulfilled, onRejected, promise) {
  194. this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
  195. this.onRejected = typeof onRejected === 'function' ? onRejected : null;
  196. this.promise = promise;
  197. }
  198. /**
  199. * Take a potentially misbehaving resolver function and make sure
  200. * onFulfilled and onRejected are only called once.
  201. *
  202. * Makes no guarantees about asynchrony.
  203. */
  204. function doResolve(fn, self) {
  205. var done = false;
  206. try {
  207. fn(
  208. function(value) {
  209. if (done) { return; }
  210. done = true;
  211. resolve(self, value);
  212. },
  213. function(reason) {
  214. if (done) { return; }
  215. done = true;
  216. reject(self, reason);
  217. }
  218. );
  219. } catch (ex) {
  220. if (done) { return; }
  221. done = true;
  222. reject(self, ex);
  223. }
  224. }
  225. Promise$1.prototype['catch'] = function(onRejected) {
  226. return this.then(null, onRejected);
  227. };
  228. Promise$1.prototype.then = function(onFulfilled, onRejected) {
  229. // @ts-ignore
  230. var prom = new this.constructor(noop);
  231. handle(this, new Handler(onFulfilled, onRejected, prom));
  232. return prom;
  233. };
  234. Promise$1.prototype['finally'] = finallyConstructor;
  235. Promise$1.all = function(arr) {
  236. return new Promise$1(function(resolve, reject) {
  237. if (!isArray(arr)) {
  238. return reject(new TypeError('Promise.all accepts an array'));
  239. }
  240. var args = Array.prototype.slice.call(arr);
  241. if (args.length === 0) { return resolve([]); }
  242. var remaining = args.length;
  243. function res(i, val) {
  244. try {
  245. if (val && (typeof val === 'object' || typeof val === 'function')) {
  246. var then = val.then;
  247. if (typeof then === 'function') {
  248. then.call(
  249. val,
  250. function(val) {
  251. res(i, val);
  252. },
  253. reject
  254. );
  255. return;
  256. }
  257. }
  258. args[i] = val;
  259. if (--remaining === 0) {
  260. resolve(args);
  261. }
  262. } catch (ex) {
  263. reject(ex);
  264. }
  265. }
  266. for (var i = 0; i < args.length; i++) {
  267. res(i, args[i]);
  268. }
  269. });
  270. };
  271. Promise$1.allSettled = allSettled;
  272. Promise$1.resolve = function(value) {
  273. if (value && typeof value === 'object' && value.constructor === Promise$1) {
  274. return value;
  275. }
  276. return new Promise$1(function(resolve) {
  277. resolve(value);
  278. });
  279. };
  280. Promise$1.reject = function(value) {
  281. return new Promise$1(function(resolve, reject) {
  282. reject(value);
  283. });
  284. };
  285. Promise$1.race = function(arr) {
  286. return new Promise$1(function(resolve, reject) {
  287. if (!isArray(arr)) {
  288. return reject(new TypeError('Promise.race accepts an array'));
  289. }
  290. for (var i = 0, len = arr.length; i < len; i++) {
  291. Promise$1.resolve(arr[i]).then(resolve, reject);
  292. }
  293. });
  294. };
  295. // Use polyfill for setImmediate for performance gains
  296. Promise$1._immediateFn =
  297. // @ts-ignore
  298. (typeof setImmediate === 'function' &&
  299. function(fn) {
  300. // @ts-ignore
  301. setImmediate(fn);
  302. }) ||
  303. function(fn) {
  304. setTimeoutFunc(fn, 0);
  305. };
  306. Promise$1._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  307. if (typeof console !== 'undefined' && console) {
  308. console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console
  309. }
  310. };
  311. // Support for IE 9 - 11 which does not include Promises
  312. if (!globalThis.Promise) {
  313. globalThis.Promise = Promise$1;
  314. }
  315. /*
  316. object-assign
  317. (c) Sindre Sorhus
  318. @license MIT
  319. */
  320. 'use strict';
  321. /* eslint-disable no-unused-vars */
  322. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  323. var hasOwnProperty = Object.prototype.hasOwnProperty;
  324. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  325. function toObject(val) {
  326. if (val === null || val === undefined) {
  327. throw new TypeError('Object.assign cannot be called with null or undefined');
  328. }
  329. return Object(val);
  330. }
  331. function shouldUseNative() {
  332. try {
  333. if (!Object.assign) {
  334. return false;
  335. }
  336. // Detect buggy property enumeration order in older V8 versions.
  337. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  338. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  339. test1[5] = 'de';
  340. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  341. return false;
  342. }
  343. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  344. var test2 = {};
  345. for (var i = 0; i < 10; i++) {
  346. test2['_' + String.fromCharCode(i)] = i;
  347. }
  348. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  349. return test2[n];
  350. });
  351. if (order2.join('') !== '0123456789') {
  352. return false;
  353. }
  354. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  355. var test3 = {};
  356. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  357. test3[letter] = letter;
  358. });
  359. if (Object.keys(Object.assign({}, test3)).join('') !==
  360. 'abcdefghijklmnopqrst') {
  361. return false;
  362. }
  363. return true;
  364. } catch (err) {
  365. // We don't expect any of the above to throw, but better to be safe.
  366. return false;
  367. }
  368. }
  369. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  370. var arguments$1 = arguments;
  371. var from;
  372. var to = toObject(target);
  373. var symbols;
  374. for (var s = 1; s < arguments.length; s++) {
  375. from = Object(arguments$1[s]);
  376. for (var key in from) {
  377. if (hasOwnProperty.call(from, key)) {
  378. to[key] = from[key];
  379. }
  380. }
  381. if (getOwnPropertySymbols) {
  382. symbols = getOwnPropertySymbols(from);
  383. for (var i = 0; i < symbols.length; i++) {
  384. if (propIsEnumerable.call(from, symbols[i])) {
  385. to[symbols[i]] = from[symbols[i]];
  386. }
  387. }
  388. }
  389. }
  390. return to;
  391. };
  392. // References:
  393. if (!Object.assign) {
  394. Object.assign = objectAssign;
  395. }
  396. "use strict";
  397. // References:
  398. // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
  399. // https://gist.github.com/1579671
  400. // http://updates.html5rocks.com/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision
  401. // https://gist.github.com/timhall/4078614
  402. // https://github.com/Financial-Times/polyfill-service/tree/master/polyfills/requestAnimationFrame
  403. // Expected to be used with Browserfiy
  404. // Browserify automatically detects the use of `global` and passes the
  405. // correct reference of `global`, `globalThis`, and finally `window`
  406. var ONE_FRAME_TIME = 16;
  407. // Date.now
  408. if (!(Date.now && Date.prototype.getTime)) {
  409. Date.now = function now() {
  410. return new Date().getTime();
  411. };
  412. }
  413. // performance.now
  414. if (!(globalThis.performance && globalThis.performance.now)) {
  415. var startTime_1 = Date.now();
  416. if (!globalThis.performance) {
  417. globalThis.performance = {};
  418. }
  419. globalThis.performance.now = function () { return Date.now() - startTime_1; };
  420. }
  421. // requestAnimationFrame
  422. var lastTime = Date.now();
  423. var vendors = ['ms', 'moz', 'webkit', 'o'];
  424. for (var x = 0; x < vendors.length && !globalThis.requestAnimationFrame; ++x) {
  425. var p = vendors[x];
  426. globalThis.requestAnimationFrame = globalThis[p + "RequestAnimationFrame"];
  427. globalThis.cancelAnimationFrame = globalThis[p + "CancelAnimationFrame"]
  428. || globalThis[p + "CancelRequestAnimationFrame"];
  429. }
  430. if (!globalThis.requestAnimationFrame) {
  431. globalThis.requestAnimationFrame = function (callback) {
  432. if (typeof callback !== 'function') {
  433. throw new TypeError(callback + "is not a function");
  434. }
  435. var currentTime = Date.now();
  436. var delay = ONE_FRAME_TIME + lastTime - currentTime;
  437. if (delay < 0) {
  438. delay = 0;
  439. }
  440. lastTime = currentTime;
  441. return globalThis.self.setTimeout(function () {
  442. lastTime = Date.now();
  443. callback(performance.now());
  444. }, delay);
  445. };
  446. }
  447. if (!globalThis.cancelAnimationFrame) {
  448. globalThis.cancelAnimationFrame = function (id) { return clearTimeout(id); };
  449. }
  450. "use strict";
  451. // References:
  452. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  453. if (!Math.sign) {
  454. Math.sign = function mathSign(x) {
  455. x = Number(x);
  456. if (x === 0 || isNaN(x)) {
  457. return x;
  458. }
  459. return x > 0 ? 1 : -1;
  460. };
  461. }
  462. "use strict";
  463. // References:
  464. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  465. if (!Number.isInteger) {
  466. Number.isInteger = function numberIsInteger(value) {
  467. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  468. };
  469. }
  470. if (!globalThis.ArrayBuffer) {
  471. globalThis.ArrayBuffer = Array;
  472. }
  473. if (!globalThis.Float32Array) {
  474. globalThis.Float32Array = Array;
  475. }
  476. if (!globalThis.Uint32Array) {
  477. globalThis.Uint32Array = Array;
  478. }
  479. if (!globalThis.Uint16Array) {
  480. globalThis.Uint16Array = Array;
  481. }
  482. if (!globalThis.Uint8Array) {
  483. globalThis.Uint8Array = Array;
  484. }
  485. if (!globalThis.Int32Array) {
  486. globalThis.Int32Array = Array;
  487. }
  488. })();
  489. //# sourceMappingURL=polyfill.js.map