blob: 415739b0aacacf29e57aedd16e6497b5229e1060 [file] [log] [blame]
'use strict';(function(f){function n(a){"string"!==typeof a&&(a=String(a));if(/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(a))throw new h("Invalid character in header field name");return a.toLowerCase()}function w(a){"string"!==typeof a&&(a=String(a));var b;var c=0;for(b=a.length;c<b;c++){var d=a.charCodeAt(c);if(9!==d&&10!==d&&13!==d&&32!==d)break}for(b=a.length-1;b>c&&(d=a.charCodeAt(b),9===d||10===d||13===d||32===d);b--);a=a.substring(c,b+1);c=0;for(b=a.length;c<b;c++)if(d=a.charCodeAt(c),256<=d||0===d||
10===d||13===d)throw new h("Invalid character in header field value");return a}function e(a){this.map=new q;if(void 0!==a){if(null===a||"object"!==typeof a)throw new h("Constructing Headers with invalid parameters");a instanceof e?a.forEach(function(a,c){this.append(c,a)},this):m.isArray(a)?a.forEach(function(a){if(2!==a.length)throw new h("Constructing Headers with invalid parameters");this.append(a[0],a[1])},this):Object.getOwnPropertyNames(a).forEach(function(b){this.append(b,a[b])},this)}}function r(a){if(a.bodyUsed)return t(new h("Body already read"));
if(null===a.body)return A(new k(0));if(B(a.body))return t(new h("ReadableStream already locked"));var b=a.body.getReader(),c=[],d=0;return b.read().then(function C(a){if(a.done){if(0===c.length)a=new k(0);else if(1===c.length)a=new k(c[0]);else{a=new k(d);for(var f=0,e=c.length,g=0;f<e;f++)a.set(c[f],g),g+=c[f].length}return a}return a.value instanceof k?(d+=a.value.length,c.push(a.value),b.read().then(C)):t(new h("Invalid stream read value type"))})}function D(a){a=unescape(encodeURIComponent(a));
for(var b=new k(a.length),c=0,d=a.length;c<d;c++)b[c]=a.charCodeAt(c);return b}function x(){this._initBody=function(a){this._bodyUsed=!1;this.body=null===a||void 0===a?null:a instanceof u?a:new u({start:function(b){if(a)if("string"===typeof a)b.enqueue(D(a));else if(y.prototype.isPrototypeOf(a))b.enqueue(new k(a));else if(E(a))b.enqueue(new k(a.buffer));else throw new h("Unsupported BodyInit type");b.close()}});this.headers.get("content-type")||"string"===typeof a&&this.headers.set("content-type",
"text/plain;charset=UTF-8")};Object.defineProperty(this,"bodyUsed",{get:function(){return this._bodyUsed?!0:this.body?!!F(this.body):!1}});this.arrayBuffer=function(){return r(this).then(function(a){return a.buffer})};this.text=function(){return r(this).then(function(a){return 0===a.length?"":decodeURIComponent(escape(String.fromCharCode.apply(null,a)))})};this.json=function(){return this.text().then(JSON.parse)};return this}function p(a,b){b=b||{};var c=b.body;if(a instanceof p){if(a.bodyUsed)throw new h("Request body already read");
this.url=a.url;this.credentials=a.credentials;b.headers||(this.headers=new e(a.headers));this.method=a.method;this.mode=a.mode;c||null===a.body||(c=a.body,a._bodyUsed=!0)}else this.url=String(a);this.credentials=b.credentials||this.credentials||"omit";if(b.headers||!this.headers)this.headers=new e(b.headers);a=b.method||this.method||"GET";var d=a.toUpperCase();this.method=-1<G.indexOf(d)?d:a;this.mode=b.mode||this.mode||null;this.referrer=null;if(("GET"===this.method||"HEAD"===this.method)&&c)throw new h("Body not allowed for GET or HEAD requests");
this._initBody(c)}function H(a){var b=new e;a.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(a){var c=a.split(":");if(a=c.shift().trim())c=c.join(":").trim(),b.append(a,c)});return b}function l(a,b){b||(b={});this.type="default";this.status="status"in b?b.status:200;this.ok=200<=this.status&&300>this.status;this.statusText="statusText"in b?b.statusText:"OK";this.headers=new e(b.headers);this.url=b.url||"";this._initBody(a)}if(!f.fetch){var m=f.Array,y=f.ArrayBuffer,I=f.Symbol.iterator,
q=f.Map,J=f.RangeError,h=f.TypeError,k=f.Uint8Array,v=f.Promise,t=v.reject,A=v.resolve,u=f.ReadableStream,z=f.ReadableStreamTee,F=f.IsReadableStreamDisturbed,B=f.IsReadableStreamLocked,K="[object Int8Array];[object Uint8Array];[object Uint8ClampedArray];[object Int16Array];[object Uint16Array];[object Int32Array];[object Uint32Array];[object Float32Array];[object Float64Array]".split(";"),E=y.isView||function(a){return a&&-1<K.indexOf(Object.prototype.toString.call(a))};e.prototype.append=function(a,
b){if(2!==arguments.length)throw h("Invalid parameters to append");a=n(a);b=w(b);this.map.has(a)?this.map.set(a,this.map.get(a)+", "+b):this.map.set(a,b)};e.prototype["delete"]=function(a){if(1!==arguments.length)throw h("Invalid parameters to delete");this.map.delete(n(a))};e.prototype.get=function(a){if(1!==arguments.length)throw h("Invalid parameters to get");a=n(a);var b=this.map.get(a);return void 0!==b?b:null};e.prototype.has=function(a){if(1!==arguments.length)throw h("Invalid parameters to has");
return this.map.has(n(a))};e.prototype.set=function(a,b){if(2!==arguments.length)throw h("Invalid parameters to set");this.map.set(n(a),w(b))};e.prototype.forEach=function(a,b){var c=this;m.from(this.map.entries()).sort().forEach(function(d){a.call(b,d[1],d[0],c)})};e.prototype.keys=function(){return(new q(m.from(this.map.entries()).sort())).keys()};e.prototype.values=function(){return(new q(m.from(this.map.entries()).sort())).values()};e.prototype.entries=function(){return(new q(m.from(this.map.entries()).sort())).entries()};
e.prototype[I]=e.prototype.entries;var G="DELETE GET HEAD OPTIONS POST PUT".split(" ");p.prototype.clone=function(){var a=null;null!==this.body&&(a=z(this.body,!0),this.body=a[0],a=a[1]);return new p(this,{body:a})};x.call(p.prototype);x.call(l.prototype);l.prototype.clone=function(){var a=null;null!==this.body&&(a=z(this.body,!0),this.body=a[0],a=a[1]);return new l(a,{status:this.status,statusText:this.statusText,headers:new e(this.headers),url:this.url})};l.error=function(){var a=new l(null,{status:0,
statusText:""});a.type="error";return a};var L=[301,302,303,307,308];l.redirect=function(a,b){if(-1===L.indexOf(b))throw new J("Invalid status code");return new l(null,{status:b,headers:{location:a}})};f.Headers=e;f.Request=p;f.Response=l;f.fetch=function(a,b){return new v(function(c,d){var f=!1,e=new p(a,b),g=new XMLHttpRequest,k=null,n=new u({start:function(a){k=a},cancel:function(a){f=!0;g.abort()}});g.onload=function(){k.close()};g.onreadystatechange=function(){if(g.readyState===g.HEADERS_RECEIVED){var a=
{status:g.status,statusText:g.statusText,headers:H(g.getAllResponseHeaders()||"")};a.url="responseURL"in g?g.responseURL:a.headers.get("X-Request-URL");c(new l(n,a))}};g.onerror=function(){k.error(new h("Network request failed"));d(new h("Network request failed"))};g.ontimeout=function(){k.error(new h("Network request failed"));d(new h("Network request failed"))};g.open(e.method,e.url,!0);"include"===e.credentials&&(g.withCredentials=!0);e.headers.forEach(function(a,b){g.setRequestHeader(b,a)});var m=
function(a){f||k.enqueue(a)};null===e.body?g.fetch(m,null):r(e).then(function(a){g.fetch(m,a)})})};f.fetch.polyfill=!0}})(this);