!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("@firebase/app")):"function"==typeof define&&define.amd?define(["@firebase/app"],e):e(t.firebase)}(this,function(t){"use strict";try{(function(){t=t&&t.hasOwnProperty("default")?t.default:t;var e="https://firebasestorage.googleapis.com",r="https://firebasestorage.googleapis.com",n="/v0",o="/v0",i=12e4,a=6e4,s=-9007199254740991,u=function(){function t(t,e){this.code_=l(t),this.message_="Firebase Storage: "+e,this.serverResponse_=null,this.name_="FirebaseError"}return t.prototype.codeProp=function(){return this.code},t.prototype.codeEquals=function(t){return l(t)===this.codeProp()},t.prototype.serverResponseProp=function(){return this.serverResponse_},t.prototype.setServerResponseProp=function(t){this.serverResponse_=t},Object.defineProperty(t.prototype,"name",{get:function(){return this.name_},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"code",{get:function(){return this.code_},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"message",{get:function(){return this.message_},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"serverResponse",{get:function(){return this.serverResponse_},enumerable:!0,configurable:!0}),t}(),c={UNKNOWN:"unknown",OBJECT_NOT_FOUND:"object-not-found",BUCKET_NOT_FOUND:"bucket-not-found",PROJECT_NOT_FOUND:"project-not-found",QUOTA_EXCEEDED:"quota-exceeded",UNAUTHENTICATED:"unauthenticated",UNAUTHORIZED:"unauthorized",RETRY_LIMIT_EXCEEDED:"retry-limit-exceeded",INVALID_CHECKSUM:"invalid-checksum",CANCELED:"canceled",INVALID_EVENT_NAME:"invalid-event-name",INVALID_URL:"invalid-url",INVALID_DEFAULT_BUCKET:"invalid-default-bucket",NO_DEFAULT_BUCKET:"no-default-bucket",CANNOT_SLICE_BLOB:"cannot-slice-blob",SERVER_FILE_WRONG_SIZE:"server-file-wrong-size",NO_DOWNLOAD_URL:"no-download-url",INVALID_ARGUMENT:"invalid-argument",INVALID_ARGUMENT_COUNT:"invalid-argument-count",APP_DELETED:"app-deleted",INVALID_ROOT_OPERATION:"invalid-root-operation",INVALID_FORMAT:"invalid-format",INTERNAL_ERROR:"internal-error"};function l(t){return"storage/"+t}function p(){return new u(c.UNKNOWN,"An unknown error occurred, please check the error payload for server response.")}function h(){return new u(c.CANCELED,"User canceled the upload/download.")}function f(){return new u(c.CANNOT_SLICE_BLOB,"Cannot slice blob for upload. Please retry the upload.")}function d(t,e,r){return new u(c.INVALID_ARGUMENT,"Invalid argument in `"+e+"` at index "+t+": "+r)}function _(){return new u(c.APP_DELETED,"The Firebase app was deleted.")}function v(t,e){return new u(c.INVALID_FORMAT,"String does not match format '"+t+"': "+e)}function m(t){throw new u(c.INTERNAL_ERROR,"Internal error: "+t)}var b={RAW:"raw",BASE64:"base64",BASE64URL:"base64url",DATA_URL:"data_url"};function g(t){switch(t){case b.RAW:case b.BASE64:case b.BASE64URL:case b.DATA_URL:return;default:throw"Expected one of the event types: ["+b.RAW+", "+b.BASE64+", "+b.BASE64URL+", "+b.DATA_URL+"]."}}var y=function(){return function(t,e){this.data=t,this.contentType=e||null}}();function R(t,e){switch(t){case b.RAW:return new y(E(e));case b.BASE64:case b.BASE64URL:return new y(w(t,e));case b.DATA_URL:return new y(function(t){var e=new T(t);return e.base64?w(b.BASE64,e.rest):function(t){var e;try{e=decodeURIComponent(t)}catch(t){throw v(b.DATA_URL,"Malformed data URL.")}return E(e)}(e.rest)}(e),function(t){return new T(t).contentType}(e))}throw p()}function E(t){for(var e=[],r=0;r>6,128|63&n);else if(55296==(64512&n))if(r>18,128|n>>12&63,128|n>>6&63,128|63&n);else e.push(239,191,189);else 56320==(64512&n)?e.push(239,191,189):e.push(224|n>>12,128|n>>6&63,128|63&n)}return new Uint8Array(e)}function w(t,e){switch(t){case b.BASE64:var r=-1!==e.indexOf("-"),n=-1!==e.indexOf("_");if(r||n)throw v(t,"Invalid character '"+(r?"-":"_")+"' found: is it base64url encoded?");break;case b.BASE64URL:var o=-1!==e.indexOf("+"),i=-1!==e.indexOf("/");if(o||i)throw v(t,"Invalid character '"+(o?"+":"/")+"' found: is it base64 encoded?");e=e.replace(/-/g,"+").replace(/_/g,"/")}var a;try{a=atob(e)}catch(e){throw v(t,"Invalid character found")}for(var s=new Uint8Array(a.length),u=0;u][;base64],");var r=e[1]||null;null!=r&&(this.base64=(n=r,o=";base64",n.length>=o.length&&n.substring(n.length-o.length)===o),this.contentType=this.base64?r.substring(0,r.length-";base64".length):r),this.rest=t.substring(t.indexOf(",")+1);var n,o}}();var U,A={STATE_CHANGED:"state_changed"},N={RUNNING:"running",PAUSING:"pausing",PAUSED:"paused",SUCCESS:"success",CANCELING:"canceling",CANCELED:"canceled",ERROR:"error"},O={RUNNING:"running",PAUSED:"paused",SUCCESS:"success",CANCELED:"canceled",ERROR:"error"};function C(t){switch(t){case N.RUNNING:case N.PAUSING:case N.CANCELING:return O.RUNNING;case N.PAUSED:return O.PAUSED;case N.SUCCESS:return O.SUCCESS;case N.CANCELED:return O.CANCELED;case N.ERROR:default:return O.ERROR}}function S(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function k(t,e){for(var r in t)S(t,r)&&e(r,t[r])}function I(t){if(null==t)return{};var e={};return k(t,function(t,r){e[t]=r}),e}function P(t){return new Promise(t)}function x(t){return Promise.resolve(t)}function L(t){return null!=t}function D(t){return void 0!==t}function M(t){return"function"==typeof t}function W(t){return"object"==typeof t}function B(t){return W(t)&&null!==t}function G(t){return"string"==typeof t||t instanceof String}function j(t){return q()&&t instanceof Blob}function q(){return"undefined"!=typeof Blob}!function(t){t[t.NO_ERROR=0]="NO_ERROR",t[t.NETWORK_ERROR=1]="NETWORK_ERROR",t[t.ABORT=2]="ABORT"}(U||(U={}));var F=function(){function t(){var t=this;this.sent_=!1,this.xhr_=new XMLHttpRequest,this.errorCode_=U.NO_ERROR,this.sendPromise_=P(function(e,r){t.xhr_.addEventListener("abort",function(r){t.errorCode_=U.ABORT,e(t)}),t.xhr_.addEventListener("error",function(r){t.errorCode_=U.NETWORK_ERROR,e(t)}),t.xhr_.addEventListener("load",function(r){e(t)})})}return t.prototype.send=function(t,e,r,n){var o=this;if(this.sent_)throw m("cannot .send() more than once");(this.sent_=!0,this.xhr_.open(e,t,!0),L(n))&&k(n,function(t,e){o.xhr_.setRequestHeader(t,e.toString())});return L(r)?this.xhr_.send(r):this.xhr_.send(),this.sendPromise_},t.prototype.getErrorCode=function(){if(!this.sent_)throw m("cannot .getErrorCode() before sending");return this.errorCode_},t.prototype.getStatus=function(){if(!this.sent_)throw m("cannot .getStatus() before sending");try{return this.xhr_.status}catch(t){return-1}},t.prototype.getResponseText=function(){if(!this.sent_)throw m("cannot .getResponseText() before sending");return this.xhr_.responseText},t.prototype.abort=function(){this.xhr_.abort()},t.prototype.getResponseHeader=function(t){return this.xhr_.getResponseHeader(t)},t.prototype.addUploadProgressListener=function(t){L(this.xhr_.upload)&&this.xhr_.upload.addEventListener("progress",t)},t.prototype.removeUploadProgressListener=function(t){L(this.xhr_.upload)&&this.xhr_.upload.removeEventListener("progress",t)},t}(),H=function(){function t(){}return t.prototype.createXhrIo=function(){return new F},t}();function z(t){var e,r;try{e=JSON.parse(t)}catch(t){return null}return W(r=e)&&!Array.isArray(r)?e:null}var X=function(){function t(t,e){this.bucket=t,this.path_=e}return Object.defineProperty(t.prototype,"path",{get:function(){return this.path_},enumerable:!0,configurable:!0}),t.prototype.fullServerUrl=function(){var t=encodeURIComponent;return"/b/"+t(this.bucket)+"/o/"+t(this.path)},t.prototype.bucketOnlyServerUrl=function(){return"/b/"+encodeURIComponent(this.bucket)+"/o"},t.makeFromBucketSpec=function(e){var r,n;try{r=t.makeFromUrl(e)}catch(r){return new t(e,"")}if(""===r.path)return r;throw n=e,new u(c.INVALID_DEFAULT_BUCKET,"Invalid default bucket '"+n+"'.")},t.makeFromUrl=function(e){var r=null;for(var n=[{regex:new RegExp("^gs://([A-Za-z0-9.\\-_]+)(/(.*))?$","i"),indices:{bucket:1,path:3},postModify:function(t){"/"===t.path.charAt(t.path.length-1)&&(t.path_=t.path_.slice(0,-1))}},{regex:new RegExp("^https?://firebasestorage\\.googleapis\\.com/v[A-Za-z0-9_]+/b/([A-Za-z0-9.\\-_]+)/o(/([^?#]*).*)?$","i"),indices:{bucket:1,path:3},postModify:function(t){t.path_=decodeURIComponent(t.path)}}],o=0;o=0))throw"Expected a number 0 or greater."})}function pt(t,e){return new st(function(e){if(!(null===e||L(e)&&e instanceof Object))throw"Expected an Object.";void 0!==t&&null!==t&&t(e)},e)}function ht(t){return new st(function(t){if(null!==t&&!M(t))throw"Expected a Function."},t)}function ft(){return"undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof WebKitBlobBuilder?WebKitBlobBuilder:void 0}var dt=function(){function t(t,e){var r=0,n="";j(t)?(this.data_=t,r=t.size,n=t.type):t instanceof ArrayBuffer?(e?this.data_=new Uint8Array(t):(this.data_=new Uint8Array(t.byteLength),this.data_.set(new Uint8Array(t))),r=this.data_.length):t instanceof Uint8Array&&(e?this.data_=t:(this.data_=new Uint8Array(t.length),this.data_.set(t)),r=t.length),this.size_=r,this.type_=n}return t.prototype.size=function(){return this.size_},t.prototype.type=function(){return this.type_},t.prototype.slice=function(e,r){if(j(this.data_)){var n=this.data_,o=(a=e,s=r,(i=n).webkitSlice?i.webkitSlice(a,s):i.mozSlice?i.mozSlice(a,s):i.slice?i.slice(a,s):null);return null===o?null:new t(o)}var i,a,s;return new t(new Uint8Array(this.data_.buffer,e,r-e),!0)},t.getBlob=function(){for(var e=[],r=0;r0&&(h=Math.min(h,o));var d=l.current,_=d+h,v={"X-Goog-Upload-Command":h===p?"upload, finalize":"upload","X-Goog-Upload-Offset":l.current},m=n.slice(d,_);if(null===m)throw f();var b=e.maxUploadRetryTime(),g=new vt(r,"POST",function(t,r){var o,a=Ut(t,["active","final"]),s=l.current+h,u=n.size();return o="final"===a?bt(e,i)(t,r):null,new Tt(s,u,"final"===a,o)},b);return g.headers=v,g.body=m.uploadData(),g.progressCallback=s||null,g.errorHandler=gt(t),g}var Nt=function(){return function(t,e,r){if(M(t)||L(e)||L(r))this.next=t,this.error=e||null,this.complete=r||null;else{var n=t;this.next=n.next||null,this.error=n.error||null,this.complete=n.complete||null}}}(),Ot=function(){return function(t,e,r,n,o,i){this.bytesTransferred=t,this.totalBytes=e,this.state=r,this.metadata=n,this.task=o,this.ref=i}}();function Ct(t){return function(){for(var e=[],r=0;r262144},t.prototype.start_=function(){this.state_===N.RUNNING&&null===this.request_&&(this.resumable_?null===this.uploadUrl_?this.createResumable_():this.needToFetchStatus_?this.fetchStatus_():this.needToFetchMetadata_?this.fetchMetadata_():this.continueUpload_():this.oneShotUpload_())},t.prototype.resolveToken_=function(t){var e=this;this.authWrapper_.getAuthToken().then(function(r){switch(e.state_){case N.RUNNING:t(r);break;case N.CANCELING:e.transition_(N.CANCELED);break;case N.PAUSING:e.transition_(N.PAUSED)}})},t.prototype.createResumable_=function(){var t=this;this.resolveToken_(function(e){var r=function(t,e,r,n,o){var i=e.bucketOnlyServerUrl(),a=wt(e,n,o),s={name:a.fullPath},u=Z(i),c={"X-Goog-Upload-Protocol":"resumable","X-Goog-Upload-Command":"start","X-Goog-Upload-Header-Content-Length":n.size(),"X-Goog-Upload-Header-Content-Type":a.contentType,"Content-Type":"application/json; charset=utf-8"},l=ot(a,r),p=t.maxUploadRetryTime(),h=new vt(u,"POST",function(t,e){var r;Ut(t);try{r=t.getResponseHeader("X-Goog-Upload-URL")}catch(t){mt(!1)}return mt(G(r)),r},p);return h.urlParams=s,h.headers=c,h.body=l,h.errorHandler=gt(e),h}(t.authWrapper_,t.location_,t.mappings_,t.blob_,t.metadata_),n=t.authWrapper_.makeRequest(r,e);t.request_=n,n.getPromise().then(function(e){t.request_=null,t.uploadUrl_=e,t.needToFetchStatus_=!1,t.completeTransitions_()},t.errorHandler_)})},t.prototype.fetchStatus_=function(){var t=this,e=this.uploadUrl_;this.resolveToken_(function(r){var n=function(t,e,r,n){var o=t.maxUploadRetryTime(),i=new vt(r,"POST",function(t,e){var r,o=Ut(t,["active","final"]);try{r=t.getResponseHeader("X-Goog-Upload-Size-Received")}catch(t){mt(!1)}var i=parseInt(r,10);return mt(!isNaN(i)),new Tt(i,n.size(),"final"===o)},o);return i.headers={"X-Goog-Upload-Command":"query"},i.errorHandler=gt(e),i}(t.authWrapper_,t.location_,e,t.blob_),o=t.authWrapper_.makeRequest(n,r);t.request_=o,o.getPromise().then(function(e){e=e,t.request_=null,t.updateProgress_(e.current),t.needToFetchStatus_=!1,e.finalized&&(t.needToFetchMetadata_=!0),t.completeTransitions_()},t.errorHandler_)})},t.prototype.continueUpload_=function(){var t=this,e=262144*this.chunkMultiplier_,r=new Tt(this.transferred_,this.blob_.size()),n=this.uploadUrl_;this.resolveToken_(function(o){var i;try{i=At(t.location_,t.authWrapper_,n,t.blob_,e,t.mappings_,r,t.makeProgressCallback_())}catch(e){return t.error_=e,void t.transition_(N.ERROR)}var a=t.authWrapper_.makeRequest(i,o);t.request_=a,a.getPromise().then(function(e){t.increaseMultiplier_(),t.request_=null,t.updateProgress_(e.current),e.finalized?(t.metadata_=e.metadata,t.transition_(N.SUCCESS)):t.completeTransitions_()},t.errorHandler_)})},t.prototype.increaseMultiplier_=function(){262144*this.chunkMultiplier_<33554432&&(this.chunkMultiplier_*=2)},t.prototype.fetchMetadata_=function(){var t=this;this.resolveToken_(function(e){var r=Rt(t.authWrapper_,t.location_,t.mappings_),n=t.authWrapper_.makeRequest(r,e);t.request_=n,n.getPromise().then(function(e){t.request_=null,t.metadata_=e,t.transition_(N.SUCCESS)},t.metadataErrorHandler_)})},t.prototype.oneShotUpload_=function(){var t=this;this.resolveToken_(function(e){var r=function(t,e,r,n,o){var i=e.bucketOnlyServerUrl(),a={"X-Goog-Upload-Protocol":"multipart"},s=function(){for(var t="",e=0;e<2;e++)t+=Math.random().toString().slice(2);return t}();a["Content-Type"]="multipart/related; boundary="+s;var u=wt(e,n,o),c="--"+s+"\r\nContent-Type: application/json; charset=utf-8\r\n\r\n"+ot(u,r)+"\r\n--"+s+"\r\nContent-Type: "+u.contentType+"\r\n\r\n",l="\r\n--"+s+"--",p=dt.getBlob(c,n,l);if(null===p)throw f();var h={name:u.fullPath},d=Z(i),_=t.maxUploadRetryTime(),v=new vt(d,"POST",bt(t,r),_);return v.urlParams=h,v.headers=a,v.body=p.uploadData(),v.errorHandler=gt(e),v}(t.authWrapper_,t.location_,t.mappings_,t.blob_,t.metadata_),n=t.authWrapper_.makeRequest(r,e);t.request_=n,n.getPromise().then(function(e){t.request_=null,t.metadata_=e,t.updateProgress_(t.blob_.size()),t.transition_(N.SUCCESS)},t.errorHandler_)})},t.prototype.updateProgress_=function(t){var e=this.transferred_;this.transferred_=t,this.transferred_!==e&&this.notifyObservers_()},t.prototype.transition_=function(t){if(this.state_!==t)switch(t){case N.CANCELING:case N.PAUSING:this.state_=t,null!==this.request_&&this.request_.cancel();break;case N.RUNNING:var e=this.state_===N.PAUSED;this.state_=t,e&&(this.notifyObservers_(),this.start_());break;case N.PAUSED:this.state_=t,this.notifyObservers_();break;case N.CANCELED:this.error_=h(),this.state_=t,this.notifyObservers_();break;case N.ERROR:case N.SUCCESS:this.state_=t,this.notifyObservers_()}},t.prototype.completeTransitions_=function(){switch(this.state_){case N.PAUSING:this.transition_(N.PAUSED);break;case N.CANCELING:this.transition_(N.CANCELED);break;case N.RUNNING:this.start_()}},Object.defineProperty(t.prototype,"snapshot",{get:function(){var t=C(this.state_);return new Ot(this.transferred_,this.blob_.size(),t,this.metadata_,this,this.ref_)},enumerable:!0,configurable:!0}),t.prototype.on=function(t,e,r,n){void 0===e&&(e=void 0),void 0===r&&(r=void 0),void 0===n&&(n=void 0);var o="Expected a function or an Object with one of `next`, `error`, `complete` properties.",i=ht(!0).validator,a=pt(null,!0).validator;function s(t){try{return void i(t)}catch(t){}try{if(a(t),!(D(t.next)||D(t.error)||D(t.complete)))throw"";return}catch(t){throw o}}at("on",[ut(function(e){if(t!==A.STATE_CHANGED)throw"Expected one of the event types: ["+A.STATE_CHANGED+"]."}),pt(s,!0),ht(!0),ht(!0)],arguments);var u=this;function c(t){return function(e,r,o){null!==t&&at("on",t,arguments);var i=new Nt(e,r,n);return u.addObserver_(i),function(){u.removeObserver_(i)}}}var l=[pt(function(t){if(null===t)throw o;s(t)}),ht(!0),ht(!0)];return!(D(e)||D(r)||D(n))?c(l):c(null)(e,r,n)},t.prototype.then=function(t,e){return this.promise_.then(t,e)},t.prototype.catch=function(t){return this.then(null,t)},t.prototype.addObserver_=function(t){this.observers_.push(t),this.notifyObserver_(t)},t.prototype.removeObserver_=function(t){var e,r,n;e=this.observers_,r=t,-1!==(n=e.indexOf(r))&&e.splice(n,1)},t.prototype.notifyObservers_=function(){var t,e=this;this.finishPromise_(),(t=this.observers_,Array.prototype.slice.call(t)).forEach(function(t){e.notifyObserver_(t)})},t.prototype.finishPromise_=function(){if(null!==this.resolve_){var t=!0;switch(C(this.state_)){case O.SUCCESS:Ct(this.resolve_.bind(null,this.snapshot))();break;case O.CANCELED:case O.ERROR:Ct(this.reject_.bind(null,this.error_))();break;default:t=!1}t&&(this.resolve_=null,this.reject_=null)}},t.prototype.notifyObserver_=function(t){switch(C(this.state_)){case O.RUNNING:case O.PAUSED:null!==t.next&&Ct(t.next.bind(t,this.snapshot))();break;case O.SUCCESS:null!==t.complete&&Ct(t.complete.bind(t))();break;case O.CANCELED:case O.ERROR:null!==t.error&&Ct(t.error.bind(t,this.error_))();break;default:null!==t.error&&Ct(t.error.bind(t,this.error_))()}},t.prototype.resume=function(){at("resume",[],arguments);var t=this.state_===N.PAUSED||this.state_===N.PAUSING;return t&&this.transition_(N.RUNNING),t},t.prototype.pause=function(){at("pause",[],arguments);var t=this.state_===N.RUNNING;return t&&this.transition_(N.PAUSING),t},t.prototype.cancel=function(){at("cancel",[],arguments);var t=this.state_===N.RUNNING||this.state_===N.PAUSING;return t&&this.transition_(N.CANCELING),t},t}(),kt=function(){function t(t,e){this.authWrapper=t,this.location=e instanceof X?e:X.makeFromUrl(e)}return t.prototype.toString=function(){return at("toString",[],arguments),"gs://"+this.location.bucket+"/"+this.location.path},t.prototype.newRef=function(e,r){return new t(e,r)},t.prototype.mappings=function(){return tt()},t.prototype.child=function(t){at("child",[ut()],arguments);var e=function(t,e){var r=e.split("/").filter(function(t){return t.length>0}).join("/");return 0===t.length?r:t+"/"+r}(this.location.path,t),r=new X(this.location.bucket,e);return this.newRef(this.authWrapper,r)},Object.defineProperty(t.prototype,"parent",{get:function(){var t=function(t){if(0==t.length)return null;var e=t.lastIndexOf("/");return-1===e?"":t.slice(0,e)}(this.location.path);if(null===t)return null;var e=new X(this.location.bucket,t);return this.newRef(this.authWrapper,e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){var t=new X(this.location.bucket,"");return this.newRef(this.authWrapper,t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bucket",{get:function(){return this.location.bucket},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"fullPath",{get:function(){return this.location.path},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"name",{get:function(){return V(this.location.path)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"storage",{get:function(){return this.authWrapper.service()},enumerable:!0,configurable:!0}),t.prototype.put=function(t,e){return void 0===e&&(e=null),at("put",[new st(function(t){if(!(t instanceof Uint8Array||t instanceof ArrayBuffer||q()&&t instanceof Blob))throw"Expected Blob or File."}),ct(!0)],arguments),this.throwIfRoot_("put"),new St(this,this.authWrapper,this.location,this.mappings(),new dt(t),e)},t.prototype.putString=function(t,e,r){void 0===e&&(e=b.RAW),at("putString",[ut(),ut(g,!0),ct(!0)],arguments),this.throwIfRoot_("putString");var n=R(e,t),o=I(r);return!L(o.contentType)&&L(n.contentType)&&(o.contentType=n.contentType),new St(this,this.authWrapper,this.location,this.mappings(),new dt(n.data,!0),o)},t.prototype.delete=function(){at("delete",[],arguments),this.throwIfRoot_("delete");var t=this;return this.authWrapper.getAuthToken().then(function(e){var r=function(t,e){var r=K(e.fullServerUrl()),n=t.maxOperationRetryTime(),o=new vt(r,"DELETE",function(t,e){},n);return o.successCodes=[200,204],o.errorHandler=yt(e),o}(t.authWrapper,t.location);return t.authWrapper.makeRequest(r,e).getPromise()})},t.prototype.getMetadata=function(){at("getMetadata",[],arguments),this.throwIfRoot_("getMetadata");var t=this;return this.authWrapper.getAuthToken().then(function(e){var r=Rt(t.authWrapper,t.location,t.mappings());return t.authWrapper.makeRequest(r,e).getPromise()})},t.prototype.updateMetadata=function(t){at("updateMetadata",[ct()],arguments),this.throwIfRoot_("updateMetadata");var e=this;return this.authWrapper.getAuthToken().then(function(r){var n=function(t,e,r,n){var o=K(e.fullServerUrl()),i=ot(r,n),a=t.maxOperationRetryTime(),s=new vt(o,"PATCH",bt(t,n),a);return s.headers={"Content-Type":"application/json; charset=utf-8"},s.body=i,s.errorHandler=yt(e),s}(e.authWrapper,e.location,t,e.mappings());return e.authWrapper.makeRequest(n,r).getPromise()})},t.prototype.getDownloadURL=function(){at("getDownloadURL",[],arguments),this.throwIfRoot_("getDownloadURL");var t=this;return this.authWrapper.getAuthToken().then(function(e){var r=Et(t.authWrapper,t.location,t.mappings());return t.authWrapper.makeRequest(r,e).getPromise().then(function(t){if(null===t)throw new u(c.NO_DOWNLOAD_URL,"The given file does not have any download URLs.");return t})})},t.prototype.throwIfRoot_=function(t){if(""===this.location.path)throw function(t){return new u(c.INVALID_ROOT_OPERATION,"The operation '"+t+"' cannot be performed on a root reference, create a non-root reference using child, such as .child('file.png').")}(t)},t}(),It=function(){function t(t){this.promise_=function(t){return Promise.reject(t)}(t)}return t.prototype.getPromise=function(){return this.promise_},t.prototype.cancel=function(t){void 0===t&&(t=!1)},t}(),Pt=function(){function t(){this.map_={},this.id_=s}return t.prototype.addRequest=function(t){var e=this.id_;this.id_++,this.map_[e]=t;var r=this;function n(){delete r.map_[e]}t.getPromise().then(n,n)},t.prototype.clear=function(){k(this.map_,function(t,e){e&&e.cancel(!0)}),this.map_={}},t}(),xt=function(){function t(e,r,n,o,s){if(this.bucket_=null,this.deleted_=!1,this.app_=e,null!==this.app_){var u=this.app_.options;L(u)&&(this.bucket_=t.extractBucket_(u))}this.storageRefMaker_=r,this.requestMaker_=n,this.pool_=s,this.service_=o,this.maxOperationRetryTime_=i,this.maxUploadRetryTime_=a,this.requestMap_=new Pt}return t.extractBucket_=function(t){var e=t.storageBucket||null;return null==e?null:X.makeFromBucketSpec(e).bucket},t.prototype.getAuthToken=function(){return null!==this.app_&&L(this.app_.INTERNAL)&&L(this.app_.INTERNAL.getToken)?this.app_.INTERNAL.getToken().then(function(t){return null!==t?t.accessToken:null},function(t){return null}):x(null)},t.prototype.bucket=function(){if(this.deleted_)throw _();return this.bucket_},t.prototype.service=function(){return this.service_},t.prototype.makeStorageReference=function(t){return this.storageRefMaker_(this,t)},t.prototype.makeRequest=function(t,e){if(this.deleted_)return new It(_());var r=this.requestMaker_(t,e,this.pool_);return this.requestMap_.addRequest(r),r},t.prototype.deleteApp=function(){this.deleted_=!0,this.app_=null,this.requestMap_.clear()},t.prototype.maxUploadRetryTime=function(){return this.maxUploadRetryTime_},t.prototype.setMaxUploadRetryTime=function(t){this.maxUploadRetryTime_=t},t.prototype.maxOperationRetryTime=function(){return this.maxOperationRetryTime_},t.prototype.setMaxOperationRetryTime=function(t){this.maxOperationRetryTime_=t},t}();var Lt=function(){function t(t,e,r,n,o,i,a,s,u,c,l){this.pendingXhr_=null,this.backoffId_=null,this.resolve_=null,this.reject_=null,this.canceled_=!1,this.appDelete_=!1,this.url_=t,this.method_=e,this.headers_=r,this.body_=n,this.successCodes_=o.slice(),this.additionalRetryCodes_=i.slice(),this.callback_=a,this.errorCallback_=s,this.progressCallback_=c,this.timeout_=u,this.pool_=l;var p=this;this.promise_=P(function(t,e){p.resolve_=t,p.reject_=e,p.start_()})}return t.prototype.start_=function(){var t=this;function e(e,r){var n,o=t.resolve_,i=t.reject_,a=r.xhr;if(r.wasSuccessCode)try{var s=t.callback_(a,a.getResponseText());D(s)?o(s):o()}catch(t){i(t)}else null!==a?((n=p()).setServerResponseProp(a.getResponseText()),t.errorCallback_?i(t.errorCallback_(a,n)):i(n)):r.canceled?i(n=t.appDelete_?_():h()):i(n=new u(c.RETRY_LIMIT_EXCEEDED,"Max retry time for operation exceeded, please try again."))}this.canceled_?e(0,new Dt(!1,null,!0)):this.backoffId_=function(t,e,r){var n=1,o=null,i=!1,a=0;function s(){return 2===a}var u=!1;function c(){u||(u=!0,e.apply(null,arguments))}function l(e){o=setTimeout(function(){o=null,t(p,s())},e)}function p(t){for(var e,r=[],o=1;o=500&&t<600,r=_t([408,429],t),n=_t(this.additionalRetryCodes_,t);return e||r||n},t}(),Dt=function(){return function(t,e,r){this.wasSuccessCode=t,this.xhr=e,this.canceled=!!r}}();function Mt(e,r,n){var o=J(e.urlParams),i=e.url+o,a=I(e.headers);return function(t,e){null!==e&&e.length>0&&(t.Authorization="Firebase "+e)}(a,r),function(e){var r=void 0!==t?t.SDK_VERSION:"AppManager";e["X-Firebase-Storage-Version"]="webjs/"+r}(a),new Lt(i,e.method,a,e.body,e.successCodes,e.additionalRetryCodes,e.handler,e.errorHandler,e.timeout,e.progressCallback,n)}var Wt,Bt=function(){function t(t,e,r){if(this.bucket_=null,this.authWrapper_=new xt(t,function(t,e){return new kt(t,e)},Mt,this,e),this.app_=t,null!=r)this.bucket_=X.makeFromBucketSpec(r);else{var n=this.authWrapper_.bucket();null!=n&&(this.bucket_=new X(n,""))}this.internals_=new Gt(this)}return t.prototype.ref=function(t){if(at("ref",[ut(function(t){if(/^[A-Za-z]+:\/\//.test(t))throw"Expected child path but got a URL, use refFromURL instead."},!0)],arguments),null==this.bucket_)throw new Error("No Storage Bucket defined in Firebase Options.");var e=new kt(this.authWrapper_,this.bucket_);return null!=t?e.child(t):e},t.prototype.refFromURL=function(t){return at("refFromURL",[ut(function(t){if(!/^[A-Za-z]+:\/\//.test(t))throw"Expected full URL but got a child path, use ref instead.";try{X.makeFromUrl(t)}catch(t){throw"Expected valid full URL but got an invalid one."}},!1)],arguments),new kt(this.authWrapper_,t)},Object.defineProperty(t.prototype,"maxUploadRetryTime",{get:function(){return this.authWrapper_.maxUploadRetryTime()},enumerable:!0,configurable:!0}),t.prototype.setMaxUploadRetryTime=function(t){at("setMaxUploadRetryTime",[lt()],arguments),this.authWrapper_.setMaxUploadRetryTime(t)},Object.defineProperty(t.prototype,"maxOperationRetryTime",{get:function(){return this.authWrapper_.maxOperationRetryTime()},enumerable:!0,configurable:!0}),t.prototype.setMaxOperationRetryTime=function(t){at("setMaxOperationRetryTime",[lt()],arguments),this.authWrapper_.setMaxOperationRetryTime(t)},Object.defineProperty(t.prototype,"app",{get:function(){return this.app_},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"INTERNAL",{get:function(){return this.internals_},enumerable:!0,configurable:!0}),t}(),Gt=function(){function t(t){this.service_=t}return t.prototype.delete=function(){return this.service_.authWrapper_.deleteApp(),x(void 0)},t}(),jt="storage";function qt(t,e,r){return new Bt(t,new H,r)}Wt={TaskState:O,TaskEvent:A,StringFormat:b,Storage:Bt,Reference:kt},t.INTERNAL.registerService(jt,qt,Wt,void 0,!0)}).apply(this,arguments)}catch(t){throw console.error(t),new Error("Cannot instantiate firebase-storage - be sure to load firebase-app.js first.")}}); //# sourceMappingURL=firebase-storage.js.map