939c96e46ef82a2c12b1d407ace2d6.blob 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. "use strict";
  2. var global = arguments[3];
  3. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  4. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  5. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  6. var HMR_HOST = null;
  7. var HMR_PORT = 12345;
  8. var HMR_ENV_HASH = "d751713988987e9331980363e24189ce";
  9. module.bundle.HMR_BUNDLE_ID = "9677950b377d8783c801420daf7bdb91";
  10. /* global HMR_HOST, HMR_PORT, HMR_ENV_HASH */
  11. var OVERLAY_ID = '__parcel__error__overlay__';
  12. var OldModule = module.bundle.Module;
  13. function Module(moduleName) {
  14. OldModule.call(this, moduleName);
  15. this.hot = {
  16. data: module.bundle.hotData,
  17. _acceptCallbacks: [],
  18. _disposeCallbacks: [],
  19. accept: function accept(fn) {
  20. this._acceptCallbacks.push(fn || function () {});
  21. },
  22. dispose: function dispose(fn) {
  23. this._disposeCallbacks.push(fn);
  24. }
  25. };
  26. module.bundle.hotData = null;
  27. }
  28. module.bundle.Module = Module;
  29. var checkedAssets, assetsToAccept, acceptedAssets; // eslint-disable-next-line no-redeclare
  30. var parent = module.bundle.parent;
  31. if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
  32. var hostname = HMR_HOST || (location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost');
  33. var port = HMR_PORT || location.port;
  34. var protocol = location.protocol === 'https:' ? 'wss' : 'ws';
  35. var ws = new WebSocket(protocol + '://' + hostname + (port ? ':' + port : '') + '/');
  36. ws.onmessage = function (event) {
  37. checkedAssets = {};
  38. assetsToAccept = [];
  39. acceptedAssets = {};
  40. var data = JSON.parse(event.data);
  41. if (data.type === 'update') {
  42. // Remove error overlay if there is one
  43. removeErrorOverlay();
  44. var assets = data.assets.filter(function (asset) {
  45. return asset.envHash === HMR_ENV_HASH;
  46. }); // Handle HMR Update
  47. var handled = false;
  48. assets.forEach(function (asset) {
  49. var didAccept = hmrAcceptCheck(global.parcelRequire, asset.id);
  50. if (didAccept) {
  51. handled = true;
  52. }
  53. });
  54. if (handled) {
  55. console.clear();
  56. assets.forEach(function (asset) {
  57. hmrApply(global.parcelRequire, asset);
  58. });
  59. for (var i = 0; i < assetsToAccept.length; i++) {
  60. var id = assetsToAccept[i][1];
  61. if (!acceptedAssets[id]) {
  62. hmrAcceptRun(assetsToAccept[i][0], id);
  63. }
  64. }
  65. } else {
  66. window.location.reload();
  67. }
  68. }
  69. if (data.type === 'error') {
  70. // Log parcel errors to console
  71. var _iterator = _createForOfIteratorHelper(data.diagnostics.ansi),
  72. _step;
  73. try {
  74. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  75. var ansiDiagnostic = _step.value;
  76. var stack = ansiDiagnostic.codeframe ? ansiDiagnostic.codeframe : ansiDiagnostic.stack;
  77. console.error('🚨 [parcel]: ' + ansiDiagnostic.message + '\n' + stack + '\n\n' + ansiDiagnostic.hints.join('\n'));
  78. } // Render the fancy html overlay
  79. } catch (err) {
  80. _iterator.e(err);
  81. } finally {
  82. _iterator.f();
  83. }
  84. removeErrorOverlay();
  85. var overlay = createErrorOverlay(data.diagnostics.html);
  86. document.body.appendChild(overlay);
  87. }
  88. };
  89. ws.onerror = function (e) {
  90. console.error(e.message);
  91. };
  92. ws.onclose = function (e) {
  93. console.warn('[parcel] 🚨 Connection to the HMR server was lost');
  94. };
  95. }
  96. function removeErrorOverlay() {
  97. var overlay = document.getElementById(OVERLAY_ID);
  98. if (overlay) {
  99. overlay.remove();
  100. console.log('[parcel] ✨ Error resolved');
  101. }
  102. }
  103. function createErrorOverlay(diagnostics) {
  104. var overlay = document.createElement('div');
  105. overlay.id = OVERLAY_ID;
  106. var errorHTML = '<div style="background: black; opacity: 0.85; font-size: 16px; color: white; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; padding: 30px; font-family: Menlo, Consolas, monospace; z-index: 9999;">';
  107. var _iterator2 = _createForOfIteratorHelper(diagnostics),
  108. _step2;
  109. try {
  110. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  111. var diagnostic = _step2.value;
  112. var stack = diagnostic.codeframe ? diagnostic.codeframe : diagnostic.stack;
  113. errorHTML += "\n <div>\n <div style=\"font-size: 18px; font-weight: bold; margin-top: 20px;\">\n \uD83D\uDEA8 ".concat(diagnostic.message, "\n </div>\n <pre>\n ").concat(stack, "\n </pre>\n <div>\n ").concat(diagnostic.hints.map(function (hint) {
  114. return '<div>' + hint + '</div>';
  115. }).join(''), "\n </div>\n </div>\n ");
  116. }
  117. } catch (err) {
  118. _iterator2.e(err);
  119. } finally {
  120. _iterator2.f();
  121. }
  122. errorHTML += '</div>';
  123. overlay.innerHTML = errorHTML;
  124. return overlay;
  125. }
  126. function getParents(bundle, id) {
  127. var modules = bundle.modules;
  128. if (!modules) {
  129. return [];
  130. }
  131. var parents = [];
  132. var k, d, dep;
  133. for (k in modules) {
  134. for (d in modules[k][1]) {
  135. dep = modules[k][1][d];
  136. if (dep === id || Array.isArray(dep) && dep[dep.length - 1] === id) {
  137. parents.push([bundle, k]);
  138. }
  139. }
  140. }
  141. if (bundle.parent) {
  142. parents = parents.concat(getParents(bundle.parent, id));
  143. }
  144. return parents;
  145. }
  146. function hmrApply(bundle, asset) {
  147. var modules = bundle.modules;
  148. if (!modules) {
  149. return;
  150. }
  151. if (modules[asset.id] || !bundle.parent) {
  152. if (asset.type === 'css') {
  153. var newStyle = document.createElement('style');
  154. newStyle.innerHTML = asset.output;
  155. document.body.appendChild(newStyle);
  156. } else {
  157. var fn = new Function('require', 'module', 'exports', asset.output);
  158. modules[asset.id] = [fn, asset.depsByBundle[bundle.HMR_BUNDLE_ID]];
  159. }
  160. } else if (bundle.parent) {
  161. hmrApply(bundle.parent, asset);
  162. }
  163. }
  164. function hmrAcceptCheck(bundle, id) {
  165. var modules = bundle.modules;
  166. if (!modules) {
  167. return;
  168. }
  169. if (!modules[id] && bundle.parent) {
  170. return hmrAcceptCheck(bundle.parent, id);
  171. }
  172. if (checkedAssets[id]) {
  173. return;
  174. }
  175. checkedAssets[id] = true;
  176. var cached = bundle.cache[id];
  177. assetsToAccept.push([bundle, id]);
  178. if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
  179. return true;
  180. }
  181. return getParents(global.parcelRequire, id).some(function (v) {
  182. return hmrAcceptCheck(v[0], v[1]);
  183. });
  184. }
  185. function hmrAcceptRun(bundle, id) {
  186. var cached = bundle.cache[id];
  187. bundle.hotData = {};
  188. if (cached && cached.hot) {
  189. cached.hot.data = bundle.hotData;
  190. }
  191. if (cached && cached.hot && cached.hot._disposeCallbacks.length) {
  192. cached.hot._disposeCallbacks.forEach(function (cb) {
  193. cb(bundle.hotData);
  194. });
  195. }
  196. delete bundle.cache[id];
  197. bundle(id);
  198. cached = bundle.cache[id];
  199. if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
  200. cached.hot._acceptCallbacks.forEach(function (cb) {
  201. var assetsToAlsoAccept = cb(function () {
  202. return getParents(global.parcelRequire, id);
  203. });
  204. if (assetsToAlsoAccept && assetsToAccept.length) {
  205. assetsToAccept.push.apply(assetsToAccept, assetsToAlsoAccept);
  206. }
  207. });
  208. }
  209. acceptedAssets[id] = true;
  210. }