polyfills.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /**
  2. * This file includes polyfills needed by Angular and is loaded before the app.
  3. * You can add your own extra polyfills to this file.
  4. *
  5. * This file is divided into 2 sections:
  6. * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
  7. * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
  8. * file.
  9. *
  10. * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
  11. * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
  12. * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
  13. *
  14. * Learn more in https://angular.io/guide/browser-support
  15. */
  16. // Array.prototype.includes()兼容问题,2021年7月21日-seimin
  17. if (!Array.prototype.includes) {
  18. Object.defineProperty(Array.prototype, "includes", {
  19. value: function (valueToFind, fromIndex) {
  20. if (this == null) {
  21. throw new TypeError('"this" is null or not defined');
  22. }
  23. // 1. Let O be ? ToObject(this value).
  24. var o = Object(this);
  25. // 2. Let len be ? ToLength(? Get(O, "length")).
  26. var len = o.length >>> 0;
  27. // 3. If len is 0, return false.
  28. if (len === 0) {
  29. return false;
  30. }
  31. // 4. Let n be ? ToInteger(fromIndex).
  32. // (If fromIndex is undefined, this step produces the value 0.)
  33. var n = fromIndex | 0;
  34. // 5. If n ≥ 0, then
  35. // a. Let k be n.
  36. // 6. Else n < 0,
  37. // a. Let k be len + n.
  38. // b. If k < 0, let k be 0.
  39. var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
  40. function sameValueZero(x, y) {
  41. return (
  42. x === y ||
  43. (typeof x === "number" &&
  44. typeof y === "number" &&
  45. isNaN(x) &&
  46. isNaN(y))
  47. );
  48. }
  49. // 7. Repeat, while k < len
  50. while (k < len) {
  51. // a. Let elementK be the result of ? Get(O, ! ToString(k)).
  52. // b. If SameValueZero(valueToFind, elementK) is true, return true.
  53. if (sameValueZero(o[k], valueToFind)) {
  54. return true;
  55. }
  56. // c. Increase k by 1.
  57. k++;
  58. }
  59. // 8. Return false
  60. return false;
  61. },
  62. });
  63. }
  64. if (!Object.values) {
  65. Object.values = function(obj) {
  66. if (obj !== Object(obj)) throw new TypeError('Object.values called on a non-object');
  67. var val=[],key;
  68. for (key in obj) {
  69. if (Object.prototype.hasOwnProperty.call(obj,key)) {
  70. val.push(obj[key]);
  71. }
  72. }
  73. return val;
  74. }
  75. }
  76. if(!Array.prototype['flat']){
  77. Array.prototype['flat'] = function(depth = 1) {
  78. if (!Number(depth) || Number(depth) < 0) {
  79. return this
  80. }
  81. let arr = this // 获得调用 fakeFlat 函数的数组
  82. while (depth > 0) {
  83. if (arr.some(item => Array.isArray(item))) {
  84. // 数组中还有数组元素的话并且 num > 0,继续展开一层数组
  85. arr = [].concat.apply([], arr)
  86. } else {
  87. break // 数组中没有数组元素并且不管 num 是否依旧大于 0,停止循环。
  88. }
  89. depth--
  90. }
  91. return arr
  92. }
  93. }
  94. // (function () {
  95. // Object.setPrototypeOf = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array ? setProtoOf : mixinProperties);
  96. // function setProtoOf(obj, proto) {
  97. // obj.__proto__ = proto;
  98. // return obj;
  99. // }
  100. // function mixinProperties(obj, proto) {
  101. // for (const prop in proto) {
  102. // if (!obj.hasOwnProperty(prop)) {
  103. // obj[prop] = proto[prop];
  104. // }
  105. // }
  106. // return obj;
  107. // }
  108. // })();
  109. // // This polyfill adds compatibility to all Browsers supporting ES5:
  110. // if ((window as any).NodeList && !NodeList.prototype.forEach) {
  111. // NodeList.prototype.forEach = function (callback, thisArg) {
  112. // thisArg = thisArg || window;
  113. // for (let i = 0; i < this.length; i++) {
  114. // callback.call(thisArg, this[i], i, this);
  115. // }
  116. // };
  117. // }
  118. // // 解决ie下报错 对象不支持matches
  119. // if (!Element.prototype.matches) {
  120. // Element.prototype.matches =
  121. // (Element.prototype as any).matchesSelector ||
  122. // (Element.prototype as any).mozMatchesSelector ||
  123. // (Element.prototype as any).msMatchesSelector ||
  124. // (Element.prototype as any).oMatchesSelector ||
  125. // Element.prototype.webkitMatchesSelector ||
  126. // function (s) {
  127. // const matches = (this.document || this.ownerDocument).querySelectorAll(s);
  128. // let i = matches.length;
  129. // while (--i >= 0 && matches.item(i) !== this) { }
  130. // return i > -1;
  131. // };
  132. // }
  133. // if (!('classList' in document.documentElement)) {
  134. // Object.defineProperty(HTMLElement.prototype, 'classList', {
  135. // get: function () {
  136. // var self = this;
  137. // function update(fn) {
  138. // return function (value) {
  139. // var classes = self.className.split(/\s+/g);
  140. // var index = classes.indexOf(value);
  141. // fn(classes, index, value);
  142. // self.className = classes.join(' ');
  143. // };
  144. // }
  145. // return {
  146. // add: update(function (classes, index, value) {
  147. // if (!~index) classes.push(value);
  148. // }),
  149. // remove: update(function (classes, index) {
  150. // if (~index) classes.splice(index, 1);
  151. // }),
  152. // toggle: update(function (classes, index, value) {
  153. // if (~index) { classes.splice(index, 1); } else { classes.push(value); }
  154. // }),
  155. // contains: function (value) {
  156. // return !!~self.className.split(/\s+/g).indexOf(value);
  157. // },
  158. // item: function (i) {
  159. // return self.className.split(/\s+/g)[i] || null;
  160. // },
  161. // };
  162. // },
  163. // });
  164. // }
  165. /***************************************************************************************************
  166. * BROWSER POLYFILLS
  167. */
  168. // import 'core-js/es/symbol';
  169. // import 'core-js/es/object';
  170. // import 'core-js/es/function';
  171. // import 'core-js/es/parse-int';
  172. // import 'core-js/es/parse-float';
  173. // import 'core-js/es/number';
  174. // import 'core-js/es/math';
  175. // import 'core-js/es/string';
  176. // import 'core-js/es/date';
  177. // import 'core-js/es/array';
  178. // import 'core-js/es/regexp';
  179. // import 'core-js/es/map';
  180. // import 'core-js/es/weak-map';
  181. // import 'core-js/es/set';
  182. // import 'babel-polyfill';
  183. // /** IE10 and IE11 requires the following for NgClass support on SVG elements */
  184. // import 'classlist.js'; // Run `npm install --save classlist.js`.
  185. // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
  186. // import 'core-js/es/reflect';
  187. /**
  188. * Web Animations `@angular/platform-browser/animations`
  189. * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
  190. * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
  191. */
  192. /**
  193. * By default, zone.js will patch all possible macroTask and DomEvents
  194. * user can disable parts of macroTask/DomEvents patch by setting following flags
  195. * because those flags need to be set before `zone.js` being loaded, and webpack
  196. * will put import in the top of bundle, so user need to create a separate file
  197. * in this directory (for example: zone-flags.ts), and put the following flags
  198. * into that file, and then add the following code before importing zone.js.
  199. * import './zone-flags.ts';
  200. *
  201. * The flags allowed in zone-flags.ts are listed here.
  202. *
  203. * The following flags will work for all browsers.
  204. *
  205. * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
  206. * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
  207. * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
  208. *
  209. * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
  210. * with the following flag, it will bypass `zone.js` patch for IE/Edge
  211. *
  212. * (window as any).__Zone_enable_cross_context_check = true;
  213. *
  214. */
  215. /***************************************************************************************************
  216. * Zone JS is required by default for Angular itself.
  217. */
  218. // import 'zone.js';
  219. // import 'zone.js/dist/long-stack-trace-zone.js';
  220. /***************************************************************************************************
  221. * APPLICATION IMPORTS
  222. */
  223. import "zone.js/dist/zone"; // Included with Angular CLI.
  224. // import 'babel-polyfill';
  225. // zone.js需在babel-polyfill之前引入