system.js 34 KB

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