mirror of
https://github.com/systemjs/systemjs.git
synced 2026-01-25 14:57:38 +00:00
4 lines
6.6 KiB
JavaScript
4 lines
6.6 KiB
JavaScript
/*
|
|
* SystemJS 2.0.0-dev
|
|
*/
|
|
!function(){const t="undefined"!=typeof self,n=t?self:global;let e;if("undefined"!=typeof location){const t=(e=location.href.split("#")[0].split("?")[0]).lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}const r=/\\/g;function o(t,n){if(-1!==t.indexOf("\\")&&(t=t.replace(r,"/")),"/"===t[0]&&"/"===t[1])return n.slice(0,n.indexOf(":")+1)+t;if("."===t[0]&&("/"===t[1]||"."===t[1]&&("/"===t[2]||2===t.length&&(t+="/"))||1===t.length&&(t+="/"))||"/"===t[0]){const e=n.slice(0,n.indexOf(":")+1);let r;if(r="/"===n[e.length+1]?"file:"!==e?(r=n.slice(e.length+2)).slice(r.indexOf("/")+1):n.slice(8):n.slice(e.length+1),"/"===t[0])return n.slice(0,n.length-r.length-1)+t;const o=r.slice(0,r.lastIndexOf("/")+1)+t,i=[];let c=-1;for(let t=0;t<o.length;t++)-1!==c?"/"===o[t]&&(i.push(o.slice(c,t+1)),c=-1):"."===o[t]?"."!==o[t+1]||"/"!==o[t+2]&&t+2!==o.length?"/"===o[t+1]||t+1===o.length?t+=1:c=t:(i.pop(),t+=2):c=t;return-1!==c&&i.push(o.slice(c)),n.slice(0,n.length-r.length)+i.join("")}}function i(t,n){return o(t,n)||-1!==t.indexOf(":")&&t||o("./"+t,n)}function c(t,n){t.path_prefix&&"/"!==(n=i(t.path_prefix,pageBaseUrl))[n.length-1]&&(n+="/");const e=t.packages||{},r={};if(t.scopes)for(let e in t.scopes){const o=t.scopes[e];if(o.path_prefix)throw new Error("Scope path_prefix not currently supported");if(o.scopes)throw new Error("Nested scopes not currently supported");let c=i(e,n);"/"===c[c.length-1]&&(c=c.substr(0,c.length-1)),r[c]=o.packages||{}}function o(t,n){let e=t.length;do{const r=t.slice(0,e);if(r in n)return r}while(-1!==(e=t.lastIndexOf("/",e-1)))}function c(t,n,e){const r=o(t,n);if(r){const o=n[r];if(r===t){if("string"==typeof o)return i(o,e+r+"/");if(!o.main)throw new Error("Package "+r+" has no main");return i((o.path?o.path+("/"===o.path[o.path.length-1]?"":"/"):r+"/")+o.main,e)}return i(("string"!=typeof o&&o.path?o.path+("/"===o.path[o.path.length-1]?"":"/"):r+"/")+t.slice(r.length+1),e)}}return function(t,i){const s=o(i,r);if(s){const n=c(t,r[s],s+"/");if(n)return n}return c(t,e,n)||throwBare(t,i)}}const s="undefined"!=typeof Symbol,u=s&&Symbol.toStringTag,f=s?Symbol():"@";function l(){this[f]={}}const a=l.prototype;let h;a.import=function(t,n){const e=this;return Promise.resolve(e.resolve(t,n)).then(function(t){const n=function t(n,e,r){let o=n[f][e];if(o)return o;const i=[],c=Object.create(null);u&&Object.defineProperty(c,u,{value:"Module"});let s=Promise.resolve().then(function(){return n.instantiate(e,r)}).then(function(t){if(!t)throw new Error("Module "+e+" did not instantiate");const r=t[1](function(t,n){o.h=!0;let e=!1;if("object"!=typeof t)t in c&&c[t]===n||(c[t]=n,e=!0);else for(let n in t){let r=t[n];n in c&&c[n]===r||(c[n]=r,e=!0)}if(e)for(let t=0;t<i.length;t++)i[t](c);return n},2===t[1].length?{import:function(t){return n.import(t,e)},meta:n.createContext(e)}:void 0);return o.e=r.execute||function(){},[t[0],r.setters||[]]});const l=(s=s.catch(function(t){throw n.onload(o.id,t),t})).then(function(r){return Promise.all(r[0].map(function(o,i){const c=r[1][i];return Promise.resolve(n.resolve(o,e)).then(function(r){const o=t(n,r,e);return Promise.resolve(o.I).then(function(){return c&&(o.i.push(c),!o.h&&o.I||c(o.n)),o})})})).then(function(t){o.d=t})});return l.catch(function(){}),o=n[f][e]={id:e,i:i,n:c,I:s,L:l,h:!1,d:void 0,e:void 0,eE:void 0,E:void 0,C:void 0}}(e,t);return n.C||function(t,n){return n.C=function t(n,e,r){if(!r[e.id])return r[e.id]=!0,Promise.resolve(e.L).then(function(){return Promise.all(e.d.map(function(e){return t(n,e,r)}))})}(t,n,{}).then(function(){return function t(n,e,r){if(r[e.id])return;if(r[e.id]=!0,!e.e){if(e.eE)throw e.eE;return}let o;return e.d.forEach(function(i){try{const c=t(n,i,r);c&&(o=o||[]).push(c)}catch(t){throw n.onload(e.id,t),t}}),o?Promise.all(o).then(i).catch(function(t){throw n.onload(e.id,t),t}):i();function i(){try{if(e.E)return e.E;let t=e.e.call(d);if(t)return(t=t.then(function(){e.C=e.n,e.E=null,n.onload(e.id,null)},function(){throw n.onload(e.id,err),err})).catch(function(){}),e.E=t;e.C=e.n,n.onload(e.id,null)}catch(t){throw n.onload(e.id,t),e.eE=t,t}finally{e.L=e.I=void 0,e.e=null}}}(t,n,{})}).then(function(){return n.n})}(e,n)})},a.createContext=function(t){return{url:t}},a.onload=function(){},a.register=function(t,n){h=[t,n]},a.getRegister=function(){const t=h;return h=void 0,t};const d=Object.freeze(Object.create(null));let p,m,g;function w(){let t;for(let e in n)n.hasOwnProperty(e)&&(t=e);return t}n.System=new l,"undefined"!=typeof window&&window.addEventListener("error",function(t){p=t.filename,m=t.error}),a.instantiate=function(t,n){const e=this;return new Promise(function(r,o){const i=document.createElement("script");i.charset="utf-8",i.async=!0,i.addEventListener("error",function(){o(new Error("Error loading "+t+(n?" from "+n:"")))}),i.addEventListener("load",function(){if(p===t)return o(m);r(e.getRegister()),document.head.removeChild(i)}),i.src=t,document.head.appendChild(i)})},t&&"function"==typeof importScripts&&(a.instantiate=function(t){const n=this;return new Promise(function(e,r){try{importScripts(t)}catch(t){r(t)}e(n.getRegister())})});const y=a.import;a.import=function(t,n){return g=w(),y.call(this,t,n)};const E=[[],function(){return{}}],v=a.getRegister;a.getRegister=function(){const t=v.call(this);if(t)return t;const e=w();if(g===e)return E;let r;g=e;try{r=n[e]}catch(t){return E}return[[],function(t){return{execute:function(){t("default",r)}}}]};const x=a.instantiate;let b,O;if(a.instantiate=function(t,n){return".wasm"!==t.slice(-5)?x.call(this,t,n):fetch(t).then(function(t){if(!t.ok)throw new Error("Fetch error "+t.status+" "+t.statusText+(n?" loading from "+n:""));return WebAssembly.compileStreaming(t)}).then(function(t){const n=[],e=[],r={};return WebAssembly.Module.imports&&WebAssembly.Module.imports(t).forEach(function(t){const o=t.module;e.push(function(t){r[o]=t}),-1===n.indexOf(o)&&n.push(o)}),[n,function(n){return{setters:e,execute:function(){n(new WebAssembly.Instance(t,r).exports)}}}]})},"undefined"!=typeof document){const t=document.getElementsByTagName("script");for(let n=0;n<t.length;n++){const r=t[n];if("systemjs-packagemap"===r.type){r.src?b=fetch(r.src).then(function(t){return t.json()}).then(function(t){O=c(t,r.src),b=void 0},function(){O=P,b=void 0}):(O=c(JSON.parse(r.innerHTML),e),b=Promise.resolve());break}}}function P(t,n){throw new Error('Unable to resolve bare specifier "'+t+(n?'" from '+n:'"'))}b||(O=P),a.resolve=function(t,n){return o(t,n=n||e)||(-1!==t.indexOf(":")?t:b?b.then(function(){return O(t,n)}):O(t,n))},a.get=function(t){const n=this[f][t];if(n&&null===n.e&&!n.E)return n.eE?null:n.n},a.delete=function(t){const n=this.get(t);return void 0!==n&&(n&&n.d&&n.d.forEach(function(t){const e=t.i.indexOf(n);-1!==e&&t.i.splice(e,1)}),delete this[f][t])}}(); |