system.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. (function () {
  2. 'use strict';
  3. function errMsg(errCode, msg) {
  4. return (msg || "") + " (SystemJS Error#" + errCode + " " + "https://git.io/JvFET#" + errCode + ")";
  5. }
  6. var hasSymbol = typeof Symbol !== 'undefined';
  7. var hasSelf = typeof self !== 'undefined';
  8. var hasDocument = typeof document !== 'undefined';
  9. var envGlobal = hasSelf ? self : global;
  10. var baseUrl;
  11. if (hasDocument) {
  12. var baseEl = document.querySelector('base[href]');
  13. if (baseEl)
  14. baseUrl = baseEl.href;
  15. }
  16. if (!baseUrl && typeof location !== 'undefined') {
  17. baseUrl = location.href.split('#')[0].split('?')[0];
  18. var lastSepIndex = baseUrl.lastIndexOf('/');
  19. if (lastSepIndex !== -1)
  20. baseUrl = baseUrl.slice(0, lastSepIndex + 1);
  21. }
  22. var backslashRegEx = /\\/g;
  23. function resolveIfNotPlainOrUrl (relUrl, parentUrl) {
  24. if (relUrl.indexOf('\\') !== -1)
  25. relUrl = relUrl.replace(backslashRegEx, '/');
  26. // protocol-relative
  27. if (relUrl[0] === '/' && relUrl[1] === '/') {
  28. return parentUrl.slice(0, parentUrl.indexOf(':') + 1) + relUrl;
  29. }
  30. // relative-url
  31. else if (relUrl[0] === '.' && (relUrl[1] === '/' || relUrl[1] === '.' && (relUrl[2] === '/' || relUrl.length === 2 && (relUrl += '/')) ||
  32. relUrl.length === 1 && (relUrl += '/')) ||
  33. relUrl[0] === '/') {
  34. var parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
  35. // Disabled, but these cases will give inconsistent results for deep backtracking
  36. //if (parentUrl[parentProtocol.length] !== '/')
  37. // throw Error('Cannot resolve');
  38. // read pathname from parent URL
  39. // pathname taken to be part after leading "/"
  40. var pathname;
  41. if (parentUrl[parentProtocol.length + 1] === '/') {
  42. // resolving to a :// so we need to read out the auth and host
  43. if (parentProtocol !== 'file:') {
  44. pathname = parentUrl.slice(parentProtocol.length + 2);
  45. pathname = pathname.slice(pathname.indexOf('/') + 1);
  46. }
  47. else {
  48. pathname = parentUrl.slice(8);
  49. }
  50. }
  51. else {
  52. // resolving to :/ so pathname is the /... part
  53. pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === '/'));
  54. }
  55. if (relUrl[0] === '/')
  56. return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
  57. // join together and split for removal of .. and . segments
  58. // looping the string instead of anything fancy for perf reasons
  59. // '../../../../../z' resolved to 'x/y' is just 'z'
  60. var segmented = pathname.slice(0, pathname.lastIndexOf('/') + 1) + relUrl;
  61. var output = [];
  62. var segmentIndex = -1;
  63. for (var i = 0; i < segmented.length; i++) {
  64. // busy reading a segment - only terminate on '/'
  65. if (segmentIndex !== -1) {
  66. if (segmented[i] === '/') {
  67. output.push(segmented.slice(segmentIndex, i + 1));
  68. segmentIndex = -1;
  69. }
  70. }
  71. // new segment - check if it is relative
  72. else if (segmented[i] === '.') {
  73. // ../ segment
  74. if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
  75. output.pop();
  76. i += 2;
  77. }
  78. // ./ segment
  79. else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
  80. i += 1;
  81. }
  82. else {
  83. // the start of a new segment as below
  84. segmentIndex = i;
  85. }
  86. }
  87. // it is the start of a new segment
  88. else {
  89. segmentIndex = i;
  90. }
  91. }
  92. // finish reading out the last segment
  93. if (segmentIndex !== -1)
  94. output.push(segmented.slice(segmentIndex));
  95. return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
  96. }
  97. }
  98. /*
  99. * Import maps implementation
  100. *
  101. * To make lookups fast we pre-resolve the entire import map
  102. * and then match based on backtracked hash lookups
  103. *
  104. */
  105. function resolveUrl (relUrl, parentUrl) {
  106. return resolveIfNotPlainOrUrl(relUrl, parentUrl) || (relUrl.indexOf(':') !== -1 ? relUrl : resolveIfNotPlainOrUrl('./' + relUrl, parentUrl));
  107. }
  108. function resolveAndComposePackages (packages, outPackages, baseUrl, parentMap, parentUrl) {
  109. for (var p in packages) {
  110. var resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
  111. var rhs = packages[p];
  112. // package fallbacks not currently supported
  113. if (typeof rhs !== 'string')
  114. continue;
  115. var mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(rhs, baseUrl) || rhs, parentUrl);
  116. if (!mapped) {
  117. targetWarning('W1', p, rhs, 'bare specifier did not resolve');
  118. }
  119. else
  120. outPackages[resolvedLhs] = mapped;
  121. }
  122. }
  123. function resolveAndComposeImportMap (json, baseUrl, outMap) {
  124. if (json.imports)
  125. resolveAndComposePackages(json.imports, outMap.imports, baseUrl, outMap, null);
  126. var u;
  127. for (u in json.scopes || {}) {
  128. var resolvedScope = resolveUrl(u, baseUrl);
  129. resolveAndComposePackages(json.scopes[u], outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}), baseUrl, outMap, resolvedScope);
  130. }
  131. for (u in json.depcache || {})
  132. outMap.depcache[resolveUrl(u, baseUrl)] = json.depcache[u];
  133. for (u in json.integrity || {})
  134. outMap.integrity[resolveUrl(u, baseUrl)] = json.integrity[u];
  135. }
  136. function getMatch (path, matchObj) {
  137. if (matchObj[path])
  138. return path;
  139. var sepIndex = path.length;
  140. do {
  141. var segment = path.slice(0, sepIndex + 1);
  142. if (segment in matchObj)
  143. return segment;
  144. } while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1)
  145. }
  146. function applyPackages (id, packages) {
  147. var pkgName = getMatch(id, packages);
  148. if (pkgName) {
  149. var pkg = packages[pkgName];
  150. if (pkg === null) return;
  151. if (id.length > pkgName.length && pkg[pkg.length - 1] !== '/') {
  152. targetWarning('W2', pkgName, pkg, "should have a trailing '/'");
  153. }
  154. else
  155. return pkg + id.slice(pkgName.length);
  156. }
  157. }
  158. function targetWarning (code, match, target, msg) {
  159. console.warn(errMsg(code, "Package target " + msg + ", resolving target '" + target + "' for " + match));
  160. }
  161. function resolveImportMap (importMap, resolvedOrPlain, parentUrl) {
  162. var scopes = importMap.scopes;
  163. var scopeUrl = parentUrl && getMatch(parentUrl, scopes);
  164. while (scopeUrl) {
  165. var packageResolution = applyPackages(resolvedOrPlain, scopes[scopeUrl]);
  166. if (packageResolution)
  167. return packageResolution;
  168. scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), scopes);
  169. }
  170. return applyPackages(resolvedOrPlain, importMap.imports) || resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain;
  171. }
  172. /*
  173. * SystemJS Core
  174. *
  175. * Provides
  176. * - System.import
  177. * - System.register support for
  178. * live bindings, function hoisting through circular references,
  179. * reexports, dynamic import, import.meta.url, top-level await
  180. * - System.getRegister to get the registration
  181. * - Symbol.toStringTag support in Module objects
  182. * - Hookable System.createContext to customize import.meta
  183. * - System.onload(err, id, deps) handler for tracing / hot-reloading
  184. *
  185. * Core comes with no System.prototype.resolve or
  186. * System.prototype.instantiate implementations
  187. */
  188. var toStringTag$1 = hasSymbol && Symbol.toStringTag;
  189. var REGISTRY = hasSymbol ? Symbol() : '@';
  190. function SystemJS () {
  191. this[REGISTRY] = {};
  192. }
  193. var systemJSPrototype$1 = SystemJS.prototype;
  194. systemJSPrototype$1.import = function (id, parentUrl) {
  195. var loader = this;
  196. return Promise.resolve(loader.prepareImport())
  197. .then(function() {
  198. return loader.resolve(id, parentUrl);
  199. })
  200. .then(function (id) {
  201. var load = getOrCreateLoad(loader, id);
  202. return load.C || topLevelLoad(loader, load);
  203. });
  204. };
  205. // Hookable createContext function -> allowing eg custom import meta
  206. systemJSPrototype$1.createContext = function (parentId) {
  207. var loader = this;
  208. return {
  209. url: parentId,
  210. resolve: function (id, parentUrl) {
  211. return Promise.resolve(loader.resolve(id, parentUrl || parentId));
  212. }
  213. };
  214. };
  215. // onLoad(err, id, deps) provided for tracing / hot-reloading
  216. systemJSPrototype$1.onload = function () {};
  217. function loadToId (load) {
  218. return load.id;
  219. }
  220. function triggerOnload (loader, load, err, isErrSource) {
  221. loader.onload(err, load.id, load.d && load.d.map(loadToId), !!isErrSource);
  222. if (err)
  223. throw err;
  224. }
  225. var lastRegister;
  226. systemJSPrototype$1.register = function (deps, declare) {
  227. lastRegister = [deps, declare];
  228. };
  229. /*
  230. * getRegister provides the last anonymous System.register call
  231. */
  232. systemJSPrototype$1.getRegister = function () {
  233. var _lastRegister = lastRegister;
  234. lastRegister = undefined;
  235. return _lastRegister;
  236. };
  237. function getOrCreateLoad (loader, id, firstParentUrl) {
  238. var load = loader[REGISTRY][id];
  239. if (load)
  240. return load;
  241. var importerSetters = [];
  242. var ns = Object.create(null);
  243. if (toStringTag$1)
  244. Object.defineProperty(ns, toStringTag$1, { value: 'Module' });
  245. var instantiatePromise = Promise.resolve()
  246. .then(function () {
  247. return loader.instantiate(id, firstParentUrl);
  248. })
  249. .then(function (registration) {
  250. if (!registration)
  251. throw Error(errMsg(2, 'Module ' + id + ' did not instantiate'));
  252. function _export (name, value) {
  253. // note if we have hoisted exports (including reexports)
  254. load.h = true;
  255. var changed = false;
  256. if (typeof name === 'string') {
  257. if (!(name in ns) || ns[name] !== value) {
  258. ns[name] = value;
  259. changed = true;
  260. }
  261. }
  262. else {
  263. for (var p in name) {
  264. var value = name[p];
  265. if (!(p in ns) || ns[p] !== value) {
  266. ns[p] = value;
  267. changed = true;
  268. }
  269. }
  270. if (name.__esModule) {
  271. ns.__esModule = name.__esModule;
  272. }
  273. }
  274. if (changed)
  275. for (var i = 0; i < importerSetters.length; i++) {
  276. var setter = importerSetters[i];
  277. if (setter) setter(ns);
  278. }
  279. return value;
  280. }
  281. var declared = registration[1](_export, registration[1].length === 2 ? {
  282. import: function (importId) {
  283. return loader.import(importId, id);
  284. },
  285. meta: loader.createContext(id)
  286. } : undefined);
  287. load.e = declared.execute || function () {};
  288. return [registration[0], declared.setters || []];
  289. }, function (err) {
  290. load.e = null;
  291. load.er = err;
  292. triggerOnload(loader, load, err, true);
  293. throw err;
  294. });
  295. var linkPromise = instantiatePromise
  296. .then(function (instantiation) {
  297. return Promise.all(instantiation[0].map(function (dep, i) {
  298. var setter = instantiation[1][i];
  299. return Promise.resolve(loader.resolve(dep, id))
  300. .then(function (depId) {
  301. var depLoad = getOrCreateLoad(loader, depId, id);
  302. // depLoad.I may be undefined for already-evaluated
  303. return Promise.resolve(depLoad.I)
  304. .then(function () {
  305. if (setter) {
  306. depLoad.i.push(setter);
  307. // only run early setters when there are hoisted exports of that module
  308. // the timing works here as pending hoisted export calls will trigger through importerSetters
  309. if (depLoad.h || !depLoad.I)
  310. setter(depLoad.n);
  311. }
  312. return depLoad;
  313. });
  314. });
  315. }))
  316. .then(function (depLoads) {
  317. load.d = depLoads;
  318. });
  319. });
  320. // Capital letter = a promise function
  321. return load = loader[REGISTRY][id] = {
  322. id: id,
  323. // importerSetters, the setters functions registered to this dependency
  324. // we retain this to add more later
  325. i: importerSetters,
  326. // module namespace object
  327. n: ns,
  328. // instantiate
  329. I: instantiatePromise,
  330. // link
  331. L: linkPromise,
  332. // whether it has hoisted exports
  333. h: false,
  334. // On instantiate completion we have populated:
  335. // dependency load records
  336. d: undefined,
  337. // execution function
  338. e: undefined,
  339. // On execution we have populated:
  340. // the execution error if any
  341. er: undefined,
  342. // in the case of TLA, the execution promise
  343. E: undefined,
  344. // On execution, L, I, E cleared
  345. // Promise for top-level completion
  346. C: undefined,
  347. // parent instantiator / executor
  348. p: undefined
  349. };
  350. }
  351. function instantiateAll (loader, load, parent, loaded) {
  352. if (!loaded[load.id]) {
  353. loaded[load.id] = true;
  354. // load.L may be undefined for already-instantiated
  355. return Promise.resolve(load.L)
  356. .then(function () {
  357. if (!load.p || load.p.e === null)
  358. load.p = parent;
  359. return Promise.all(load.d.map(function (dep) {
  360. return instantiateAll(loader, dep, parent, loaded);
  361. }));
  362. })
  363. .catch(function (err) {
  364. if (load.er)
  365. throw err;
  366. load.e = null;
  367. triggerOnload(loader, load, err, false);
  368. throw err;
  369. });
  370. }
  371. }
  372. function topLevelLoad (loader, load) {
  373. return load.C = instantiateAll(loader, load, load, {})
  374. .then(function () {
  375. return postOrderExec(loader, load, {});
  376. })
  377. .then(function () {
  378. return load.n;
  379. });
  380. }
  381. // the closest we can get to call(undefined)
  382. var nullContext = Object.freeze(Object.create(null));
  383. // Equivalent to `Promise.prototype.finally`
  384. // https://gist.github.com/developit/d970bac18430943e4b3392b029a2a96c
  385. var promisePrototypeFinally = Promise.prototype.finally || function (callback) {
  386. if (typeof callback !== 'function') {
  387. return this.then(callback, callback);
  388. }
  389. const P = this.constructor || Promise;
  390. return this.then(
  391. value => P.resolve(callback()).then(() => value),
  392. err => P.resolve(callback()).then(() => { throw err; }),
  393. );
  394. };
  395. // returns a promise if and only if a top-level await subgraph
  396. // throws on sync errors
  397. function postOrderExec (loader, load, seen) {
  398. if (seen[load.id]) {
  399. return load.E;
  400. }
  401. seen[load.id] = true;
  402. if (!load.e) {
  403. if (load.er)
  404. throw load.er;
  405. if (load.E)
  406. return load.E;
  407. return;
  408. }
  409. // From here we're about to execute the load.
  410. // Because the execution may be async, we pop the `load.e` first.
  411. // So `load.e === null` always means the load has been executed or is executing.
  412. // To inspect the state:
  413. // - If `load.er` is truthy, the execution has threw or has been rejected;
  414. // - otherwise, either the `load.E` is a promise, means it's under async execution, or
  415. // - the `load.E` is null, means the load has completed the execution or has been async resolved.
  416. const exec = load.e;
  417. load.e = null;
  418. // deps execute first, unless circular
  419. var depLoadPromises;
  420. load.d.forEach(function (depLoad) {
  421. try {
  422. var depLoadPromise = postOrderExec(loader, depLoad, seen);
  423. if (depLoadPromise)
  424. (depLoadPromises = depLoadPromises || []).push(depLoadPromise);
  425. }
  426. catch (err) {
  427. load.er = err;
  428. triggerOnload(loader, load, err, false);
  429. throw err;
  430. }
  431. });
  432. if (depLoadPromises)
  433. return load.E = promisePrototypeFinally.call(Promise.all(depLoadPromises).then(doExec), function() {
  434. load.E = null;
  435. });
  436. var execPromise = doExec();
  437. if (execPromise) {
  438. return load.E = promisePrototypeFinally.call(execPromise, function() {
  439. load.E = null;
  440. });
  441. }
  442. function doExec () {
  443. try {
  444. var execPromise = exec.call(nullContext);
  445. if (execPromise) {
  446. execPromise = execPromise.then(function () {
  447. load.C = load.n;
  448. if (!false) triggerOnload(loader, load, null, true);
  449. }, function (err) {
  450. load.er = err;
  451. if (!false) triggerOnload(loader, load, err, true);
  452. throw err;
  453. });
  454. return execPromise;
  455. }
  456. // (should be a promise, but a minify optimization to leave out Promise.resolve)
  457. load.C = load.n;
  458. load.L = load.I = undefined;
  459. }
  460. catch (err) {
  461. load.er = err;
  462. throw err;
  463. }
  464. finally {
  465. triggerOnload(loader, load, load.er, true);
  466. }
  467. }
  468. }
  469. envGlobal.System = new SystemJS();
  470. const globalObj = (function getGlobalObj() {
  471. if (typeof $global !== 'undefined') {
  472. return $global;
  473. }
  474. else if (typeof getApp === 'function') {
  475. return getApp().GameGlobal;
  476. }
  477. })();
  478. const systemGlobal = (typeof globalObj !== 'undefined' ? globalObj.System : System);
  479. const systemJSPrototype = systemGlobal.constructor.prototype;
  480. systemJSPrototype.instantiate = function (url, firstParentUrl) {
  481. throw new Error(`Unable to instantiate ${url} from ${firstParentUrl}`);
  482. };
  483. var toStringTag = typeof Symbol !== 'undefined' && Symbol.toStringTag;
  484. systemJSPrototype$1.get = function (id) {
  485. var load = this[REGISTRY][id];
  486. if (load && load.e === null && !load.E) {
  487. if (load.er)
  488. return null;
  489. return load.n;
  490. }
  491. };
  492. systemJSPrototype$1.set = function (id, module) {
  493. {
  494. try {
  495. // No page-relative URLs allowed
  496. new URL(id);
  497. } catch (err) {
  498. console.warn(Error(errMsg('W3', '"' + id + '" is not a valid URL to set in the module registry')));
  499. }
  500. }
  501. var ns;
  502. if (toStringTag && module[toStringTag] === 'Module') {
  503. ns = module;
  504. }
  505. else {
  506. ns = Object.assign(Object.create(null), module);
  507. if (toStringTag)
  508. Object.defineProperty(ns, toStringTag, { value: 'Module' });
  509. }
  510. var done = Promise.resolve(ns);
  511. var load = this[REGISTRY][id] || (this[REGISTRY][id] = {
  512. id: id,
  513. i: [],
  514. h: false,
  515. d: [],
  516. e: null,
  517. er: undefined,
  518. E: undefined
  519. });
  520. if (load.e || load.E)
  521. return false;
  522. Object.assign(load, {
  523. n: ns,
  524. I: undefined,
  525. L: undefined,
  526. C: done
  527. });
  528. return ns;
  529. };
  530. systemJSPrototype$1.has = function (id) {
  531. var load = this[REGISTRY][id];
  532. return !!load;
  533. };
  534. // Delete function provided for hot-reloading use cases
  535. systemJSPrototype$1.delete = function (id) {
  536. var registry = this[REGISTRY];
  537. var load = registry[id];
  538. // in future we can support load.E case by failing load first
  539. // but that will require TLA callbacks to be implemented
  540. if (!load || (load.p && load.p.e !== null) || load.E)
  541. return false;
  542. var importerSetters = load.i;
  543. // remove from importerSetters
  544. // (release for gc)
  545. if (load.d)
  546. load.d.forEach(function (depLoad) {
  547. var importerIndex = depLoad.i.indexOf(load);
  548. if (importerIndex !== -1)
  549. depLoad.i.splice(importerIndex, 1);
  550. });
  551. delete registry[id];
  552. return function () {
  553. var load = registry[id];
  554. if (!load || !importerSetters || load.e !== null || load.E)
  555. return false;
  556. // add back the old setters
  557. importerSetters.forEach(function (setter) {
  558. load.i.push(setter);
  559. setter(load.n);
  560. });
  561. importerSetters = null;
  562. };
  563. };
  564. var iterator = typeof Symbol !== 'undefined' && Symbol.iterator;
  565. systemJSPrototype$1.entries = function () {
  566. var loader = this, keys = Object.keys(loader[REGISTRY]);
  567. var index = 0, ns, key;
  568. var result = {
  569. next: function () {
  570. while (
  571. (key = keys[index++]) !== undefined &&
  572. (ns = loader.get(key)) === undefined
  573. );
  574. return {
  575. done: key === undefined,
  576. value: key !== undefined && [key, ns]
  577. };
  578. }
  579. };
  580. result[iterator] = function() { return this };
  581. return result;
  582. };
  583. /*
  584. * SystemJS browser attachments for script and import map processing
  585. */
  586. var importMapPromise = Promise.resolve();
  587. var importMap = { imports: {}, scopes: {}, depcache: {}, integrity: {} };
  588. // Scripts are processed immediately, on the first System.import, and on DOMReady.
  589. // Import map scripts are processed only once (by being marked) and in order for each phase.
  590. // This is to avoid using DOM mutation observers in core, although that would be an alternative.
  591. var processFirst = hasDocument;
  592. systemJSPrototype$1.prepareImport = function (doProcessScripts) {
  593. if (processFirst || doProcessScripts) {
  594. processScripts();
  595. processFirst = false;
  596. }
  597. return importMapPromise;
  598. };
  599. if (hasDocument) {
  600. processScripts();
  601. window.addEventListener('DOMContentLoaded', processScripts);
  602. }
  603. function processScripts () {
  604. [].forEach.call(document.querySelectorAll('script'), function (script) {
  605. if (script.sp) // sp marker = systemjs processed
  606. return;
  607. // TODO: deprecate systemjs-module in next major now that we have auto import
  608. if (script.type === 'systemjs-module') {
  609. script.sp = true;
  610. if (!script.src)
  611. return;
  612. System.import(script.src.slice(0, 7) === 'import:' ? script.src.slice(7) : resolveUrl(script.src, baseUrl)).catch(function (e) {
  613. // if there is a script load error, dispatch an "error" event
  614. // on the script tag.
  615. if (e.message.indexOf('https://git.io/JvFET#3') > -1) {
  616. var event = document.createEvent('Event');
  617. event.initEvent('error', false, false);
  618. script.dispatchEvent(event);
  619. }
  620. return Promise.reject(e);
  621. });
  622. }
  623. else if (script.type === 'systemjs-importmap') {
  624. script.sp = true;
  625. var fetchPromise = script.src ? fetch(script.src, { integrity: script.integrity }).then(function (res) {
  626. if (!res.ok)
  627. throw Error('Invalid status code: ' + res.status);
  628. return res.text();
  629. }).catch(function (err) {
  630. err.message = errMsg('W4', 'Error fetching systemjs-import map ' + script.src) + '\n' + err.message;
  631. console.warn(err);
  632. return '{}';
  633. }) : script.innerHTML;
  634. importMapPromise = importMapPromise.then(function () {
  635. return fetchPromise;
  636. }).then(function (text) {
  637. extendImportMap(importMap, text, script.src || baseUrl);
  638. });
  639. }
  640. });
  641. }
  642. function extendImportMap (importMap, newMapText, newMapUrl) {
  643. var newMap = {};
  644. try {
  645. newMap = JSON.parse(newMapText);
  646. } catch (err) {
  647. console.warn(Error((errMsg('W5', "systemjs-importmap contains invalid JSON") + '\n\n' + newMapText + '\n' )));
  648. }
  649. resolveAndComposeImportMap(newMap, newMapUrl, importMap);
  650. }
  651. /*
  652. * Script instantiation loading
  653. */
  654. if (hasDocument) {
  655. window.addEventListener('error', function (evt) {
  656. lastWindowErrorUrl = evt.filename;
  657. lastWindowError = evt.error;
  658. });
  659. var baseOrigin = location.origin;
  660. }
  661. systemJSPrototype$1.createScript = function (url) {
  662. var script = document.createElement('script');
  663. script.async = true;
  664. // Only add cross origin for actual cross origin
  665. // this is because Safari triggers for all
  666. // - https://bugs.webkit.org/show_bug.cgi?id=171566
  667. if (url.indexOf(baseOrigin + '/'))
  668. script.crossOrigin = 'anonymous';
  669. var integrity = importMap.integrity[url];
  670. if (integrity)
  671. script.integrity = integrity;
  672. script.src = url;
  673. return script;
  674. };
  675. // Auto imports -> script tags can be inlined directly for load phase
  676. var lastAutoImportDeps, lastAutoImportTimeout;
  677. var autoImportCandidates = {};
  678. var systemRegister = systemJSPrototype$1.register;
  679. systemJSPrototype$1.register = function (deps, declare) {
  680. if (hasDocument && document.readyState === 'loading' && typeof deps !== 'string') {
  681. var scripts = document.querySelectorAll('script[src]');
  682. var lastScript = scripts[scripts.length - 1];
  683. if (lastScript) {
  684. lastScript.src;
  685. lastAutoImportDeps = deps;
  686. // if this is already a System load, then the instantiate has already begun
  687. // so this re-import has no consequence
  688. var loader = this;
  689. lastAutoImportTimeout = setTimeout(function () {
  690. autoImportCandidates[lastScript.src] = [deps, declare];
  691. loader.import(lastScript.src);
  692. });
  693. }
  694. }
  695. else {
  696. lastAutoImportDeps = undefined;
  697. }
  698. return systemRegister.call(this, deps, declare);
  699. };
  700. var lastWindowErrorUrl, lastWindowError;
  701. systemJSPrototype$1.instantiate = function (url, firstParentUrl) {
  702. var autoImportRegistration = autoImportCandidates[url];
  703. if (autoImportRegistration) {
  704. delete autoImportCandidates[url];
  705. return autoImportRegistration;
  706. }
  707. var loader = this;
  708. return new Promise(function (resolve, reject) {
  709. var script = systemJSPrototype$1.createScript(url);
  710. script.addEventListener('error', function () {
  711. reject(Error(errMsg(3, 'Error loading ' + url + (firstParentUrl ? ' from ' + firstParentUrl : ''))));
  712. });
  713. script.addEventListener('load', function () {
  714. document.head.removeChild(script);
  715. // Note that if an error occurs that isn't caught by this if statement,
  716. // that getRegister will return null and a "did not instantiate" error will be thrown.
  717. if (lastWindowErrorUrl === url) {
  718. reject(lastWindowError);
  719. }
  720. else {
  721. var register = loader.getRegister();
  722. // Clear any auto import registration for dynamic import scripts during load
  723. if (register && register[0] === lastAutoImportDeps)
  724. clearTimeout(lastAutoImportTimeout);
  725. resolve(register);
  726. }
  727. });
  728. document.head.appendChild(script);
  729. });
  730. };
  731. /*
  732. * Fetch loader, sets up shouldFetch and fetch hooks
  733. */
  734. systemJSPrototype$1.shouldFetch = function () {
  735. return false;
  736. };
  737. if (typeof fetch !== 'undefined')
  738. systemJSPrototype$1.fetch = fetch;
  739. var instantiate = systemJSPrototype$1.instantiate;
  740. var jsContentTypeRegEx = /^(text|application)\/(x-)?javascript(;|$)/;
  741. systemJSPrototype$1.instantiate = function (url, parent) {
  742. var loader = this;
  743. if (!this.shouldFetch(url))
  744. return instantiate.apply(this, arguments);
  745. return this.fetch(url, {
  746. credentials: 'same-origin',
  747. integrity: importMap.integrity[url]
  748. })
  749. .then(function (res) {
  750. if (!res.ok)
  751. throw Error(errMsg(7, res.status + ' ' + res.statusText + ', loading ' + url + (parent ? ' from ' + parent : '')));
  752. var contentType = res.headers.get('content-type');
  753. if (!contentType || !jsContentTypeRegEx.test(contentType))
  754. throw Error(errMsg(4, 'Unknown Content-Type "' + contentType + '", loading ' + url + (parent ? ' from ' + parent : '')));
  755. return res.text().then(function (source) {
  756. if (source.indexOf('//# sourceURL=') < 0)
  757. source += '\n//# sourceURL=' + url;
  758. (0, eval)(source);
  759. return loader.getRegister();
  760. });
  761. });
  762. };
  763. systemJSPrototype$1.resolve = function (id, parentUrl) {
  764. parentUrl = parentUrl || !true || baseUrl;
  765. return resolveImportMap((importMap), resolveIfNotPlainOrUrl(id, parentUrl) || id, parentUrl) || throwUnresolved(id, parentUrl);
  766. };
  767. function throwUnresolved (id, parentUrl) {
  768. throw Error(errMsg(8, "Unable to resolve bare specifier '" + id + (parentUrl ? "' from " + parentUrl : "'")));
  769. }
  770. var systemInstantiate = systemJSPrototype$1.instantiate;
  771. systemJSPrototype$1.instantiate = function (url, firstParentUrl) {
  772. var preloads = (importMap).depcache[url];
  773. if (preloads) {
  774. for (var i = 0; i < preloads.length; i++)
  775. getOrCreateLoad(this, this.resolve(preloads[i], url), url);
  776. }
  777. return systemInstantiate.call(this, url, firstParentUrl);
  778. };
  779. /*
  780. * Supports loading System.register in workers
  781. */
  782. if (hasSelf && typeof importScripts === 'function')
  783. systemJSPrototype$1.instantiate = function (url) {
  784. var loader = this;
  785. return Promise.resolve().then(function () {
  786. importScripts(url);
  787. return loader.getRegister();
  788. });
  789. };
  790. /*
  791. * SystemJS global script loading support
  792. * Extra for the s.js build only
  793. * (Included by default in system.js build)
  794. */
  795. (function (global) {
  796. var systemJSPrototype = global.System.constructor.prototype;
  797. // safari unpredictably lists some new globals first or second in object order
  798. var firstGlobalProp, secondGlobalProp, lastGlobalProp;
  799. function getGlobalProp (useFirstGlobalProp) {
  800. var cnt = 0;
  801. var foundLastProp, result;
  802. for (var p in global) {
  803. // do not check frames cause it could be removed during import
  804. if (shouldSkipProperty(p))
  805. continue;
  806. if (cnt === 0 && p !== firstGlobalProp || cnt === 1 && p !== secondGlobalProp)
  807. return p;
  808. if (foundLastProp) {
  809. lastGlobalProp = p;
  810. result = useFirstGlobalProp && result || p;
  811. }
  812. else {
  813. foundLastProp = p === lastGlobalProp;
  814. }
  815. cnt++;
  816. }
  817. return result;
  818. }
  819. function noteGlobalProps () {
  820. // alternatively Object.keys(global).pop()
  821. // but this may be faster (pending benchmarks)
  822. firstGlobalProp = secondGlobalProp = undefined;
  823. for (var p in global) {
  824. // do not check frames cause it could be removed during import
  825. if (shouldSkipProperty(p))
  826. continue;
  827. if (!firstGlobalProp)
  828. firstGlobalProp = p;
  829. else if (!secondGlobalProp)
  830. secondGlobalProp = p;
  831. lastGlobalProp = p;
  832. }
  833. return lastGlobalProp;
  834. }
  835. var impt = systemJSPrototype.import;
  836. systemJSPrototype.import = function (id, parentUrl) {
  837. noteGlobalProps();
  838. return impt.call(this, id, parentUrl);
  839. };
  840. var emptyInstantiation = [[], function () { return {} }];
  841. var getRegister = systemJSPrototype.getRegister;
  842. systemJSPrototype.getRegister = function () {
  843. var lastRegister = getRegister.call(this);
  844. if (lastRegister)
  845. return lastRegister;
  846. // no registration -> attempt a global detection as difference from snapshot
  847. // when multiple globals, we take the global value to be the last defined new global object property
  848. // for performance, this will not support multi-version / global collisions as previous SystemJS versions did
  849. // note in Edge, deleting and re-adding a global does not change its ordering
  850. var globalProp = getGlobalProp(this.firstGlobalProp);
  851. if (!globalProp)
  852. return emptyInstantiation;
  853. var globalExport;
  854. try {
  855. globalExport = global[globalProp];
  856. }
  857. catch (e) {
  858. return emptyInstantiation;
  859. }
  860. return [[], function (_export) {
  861. return {
  862. execute: function () {
  863. _export(globalExport);
  864. _export({ default: globalExport, __useDefault: true });
  865. }
  866. };
  867. }];
  868. };
  869. var isIE11 = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('Trident') !== -1;
  870. function shouldSkipProperty(p) {
  871. return !global.hasOwnProperty(p)
  872. || !isNaN(p) && p < global.length
  873. || isIE11 && global[p] && typeof window !== 'undefined' && global[p].parent === window;
  874. }
  875. })(typeof self !== 'undefined' ? self : global);
  876. /*
  877. * Loads JSON, CSS, Wasm module types based on file extension
  878. * filters and content type verifications
  879. */
  880. (function(global) {
  881. var systemJSPrototype = global.System.constructor.prototype;
  882. var moduleTypesRegEx = /^[^#?]+\.(css|html|json|wasm)([?#].*)?$/;
  883. systemJSPrototype.shouldFetch = function (url) {
  884. return moduleTypesRegEx.test(url);
  885. };
  886. var jsonContentType = /^application\/json(;|$)/;
  887. var cssContentType = /^text\/css(;|$)/;
  888. var wasmContentType = /^application\/wasm(;|$)/;
  889. var fetch = systemJSPrototype.fetch;
  890. systemJSPrototype.fetch = function (url, options) {
  891. return fetch(url, options)
  892. .then(function (res) {
  893. if (!res.ok)
  894. return res;
  895. var contentType = res.headers.get('content-type');
  896. if (jsonContentType.test(contentType))
  897. return res.json()
  898. .then(function (json) {
  899. return new Response(new Blob([
  900. 'System.register([],function(e){return{execute:function(){e("default",' + JSON.stringify(json) + ')}}})'
  901. ], {
  902. type: 'application/javascript'
  903. }));
  904. });
  905. if (cssContentType.test(contentType))
  906. return res.text()
  907. .then(function (source) {
  908. return new Response(new Blob([
  909. 'System.register([],function(e){return{execute:function(){var s=new CSSStyleSheet();s.replaceSync(' + JSON.stringify(source) + ');e("default",s)}}})'
  910. ], {
  911. type: 'application/javascript'
  912. }));
  913. });
  914. if (wasmContentType.test(contentType))
  915. return (WebAssembly.compileStreaming ? WebAssembly.compileStreaming(res) : res.arrayBuffer().then(WebAssembly.compile))
  916. .then(function (module) {
  917. if (!global.System.wasmModules)
  918. global.System.wasmModules = Object.create(null);
  919. global.System.wasmModules[url] = module;
  920. // we can only set imports if supported (eg early Safari doesnt support)
  921. var deps = [];
  922. var setterSources = [];
  923. if (WebAssembly.Module.imports)
  924. WebAssembly.Module.imports(module).forEach(function (impt) {
  925. var key = JSON.stringify(impt.module);
  926. if (deps.indexOf(key) === -1) {
  927. deps.push(key);
  928. setterSources.push('function(m){i[' + key + ']=m}');
  929. }
  930. });
  931. return new Response(new Blob([
  932. 'System.register([' + deps.join(',') + '],function(e){var i={};return{setters:[' + setterSources.join(',') +
  933. '],execute:function(){return WebAssembly.instantiate(System.wasmModules[' + JSON.stringify(url) +
  934. '],i).then(function(m){e(m.exports)})}}})'
  935. ], {
  936. type: 'application/javascript'
  937. }));
  938. });
  939. return res;
  940. });
  941. };
  942. })(typeof self !== 'undefined' ? self : global);
  943. /*
  944. * SystemJS named register extension
  945. * Supports System.register('name', [..deps..], function (_export, _context) { ... })
  946. *
  947. * Names are written to the registry as-is
  948. * System.register('x', ...) can be imported as System.import('x')
  949. */
  950. (function (global) {
  951. var System = global.System;
  952. setRegisterRegistry(System);
  953. var systemJSPrototype = System.constructor.prototype;
  954. var constructor = System.constructor;
  955. var SystemJS = function () {
  956. constructor.call(this);
  957. setRegisterRegistry(this);
  958. };
  959. SystemJS.prototype = systemJSPrototype;
  960. System.constructor = SystemJS;
  961. var firstNamedDefine;
  962. function setRegisterRegistry(systemInstance) {
  963. systemInstance.registerRegistry = Object.create(null);
  964. }
  965. var register = systemJSPrototype.register;
  966. systemJSPrototype.register = function (name, deps, declare) {
  967. if (typeof name !== 'string')
  968. return register.apply(this, arguments);
  969. var define = [deps, declare];
  970. this.registerRegistry[name] = define;
  971. if (!firstNamedDefine) {
  972. firstNamedDefine = define;
  973. Promise.resolve().then(function () {
  974. firstNamedDefine = null;
  975. });
  976. }
  977. return register.apply(this, arguments);
  978. };
  979. var resolve = systemJSPrototype.resolve;
  980. systemJSPrototype.resolve = function (id, parentURL) {
  981. try {
  982. // Prefer import map (or other existing) resolution over the registerRegistry
  983. return resolve.call(this, id, parentURL);
  984. } catch (err) {
  985. if (id in this.registerRegistry) {
  986. return id;
  987. }
  988. throw err;
  989. }
  990. };
  991. var instantiate = systemJSPrototype.instantiate;
  992. systemJSPrototype.instantiate = function (url, firstParentUrl) {
  993. var result = this.registerRegistry[url];
  994. if (result) {
  995. this.registerRegistry[url] = null;
  996. return result;
  997. } else {
  998. return instantiate.call(this, url, firstParentUrl);
  999. }
  1000. };
  1001. var getRegister = systemJSPrototype.getRegister;
  1002. systemJSPrototype.getRegister = function () {
  1003. // Calling getRegister() because other extras need to know it was called so they can perform side effects
  1004. var register = getRegister.call(this);
  1005. var result = firstNamedDefine || register;
  1006. firstNamedDefine = null;
  1007. return result;
  1008. };
  1009. })(typeof self !== 'undefined' ? self : global);
  1010. let resolutionDetailMap = {};
  1011. function createDetailResolver() {
  1012. const logger = (message) => {
  1013. let log;
  1014. switch (message.level) {
  1015. default:
  1016. case 'log': log = console.log; break;
  1017. case 'warn': log = console.warn; break;
  1018. case 'error': log = console.error; break;
  1019. }
  1020. log.call(console, message.text);
  1021. };
  1022. return function resolve(specifier, importer) {
  1023. return new Promise((resolve, reject) => {
  1024. const detail = resolutionDetailMap[importer]?.[specifier];
  1025. if (!detail) {
  1026. resolve();
  1027. return;
  1028. }
  1029. const { error, messages } = detail;
  1030. if (messages) {
  1031. for (const message of messages) {
  1032. logger(message);
  1033. }
  1034. }
  1035. if (error) {
  1036. reject(error);
  1037. } else {
  1038. resolve();
  1039. }
  1040. });
  1041. };
  1042. }
  1043. function setResolutionDetailMap (map, mapUrl) {
  1044. resolutionDetailMap = {};
  1045. for (const [moduleUrl, _] of Object.entries(map)) {
  1046. const normalized = resolveIfNotPlainOrUrl(moduleUrl, mapUrl);
  1047. resolutionDetailMap[normalized] = _;
  1048. }
  1049. }
  1050. const setResolutionDetailMapCallbackTag = hasSymbol ? Symbol('[[setResolutionDetailMapCallback]]') : 'setResolutionDetailMapCallback';
  1051. // @ts-ignore for editor only
  1052. systemJSPrototype.setResolutionDetailMapCallback = function (callback) {
  1053. // @ts-ignore for editor only
  1054. this[setResolutionDetailMapCallbackTag] = callback;
  1055. };
  1056. let setupResolutionDetailMapPromise = null;
  1057. const vendorPrepareImport = systemJSPrototype.prepareImport;
  1058. systemJSPrototype.prepareImport = async function () {
  1059. if (!setupResolutionDetailMapPromise) {
  1060. setupResolutionDetailMapPromise = (async () => {
  1061. try {
  1062. await (async () => {
  1063. // @ts-ignore for editor only
  1064. const { json, url } = await this[setResolutionDetailMapCallbackTag]();
  1065. setResolutionDetailMap(json, url);
  1066. })();
  1067. } catch (err) {
  1068. console.debug(`Failed to load resolution detail map: ${err}`);
  1069. }
  1070. })();
  1071. }
  1072. await setupResolutionDetailMapPromise;
  1073. vendorPrepareImport.apply(this, arguments);
  1074. };
  1075. const resolveDetailMap = createDetailResolver();
  1076. const vendorResolve = systemJSPrototype.resolve;
  1077. systemJSPrototype.resolve = function (specifier, importer) {
  1078. return resolveDetailMap(specifier, importer).then(() => {
  1079. return vendorResolve.apply(this, arguments);
  1080. });
  1081. };
  1082. })();
  1083. //# sourceMappingURL=system.js.map