@akanass/rx-file-upload
Version:
Library to upload a file in the browser and send it fully or in several chunks to the server.
2 lines (1 loc) • 38.4 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).RxFileUploadUnPkg={})}(this,(function(e){"use strict";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)};function n(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},r.apply(this,arguments)};function o(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{a(r.next(e))}catch(e){i(e)}}function s(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,s)}a((r=r.apply(e,t||[])).next())}))}function i(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function u(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u}function a(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}function c(e){return this instanceof c?(this.v=e,this):new c(e)}function l(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=n.apply(e,t||[]),i=[];return r={},u("next"),u("throw"),u("return"),r[Symbol.asyncIterator]=function(){return this},r;function u(e){o[e]&&(r[e]=function(t){return new Promise((function(n,r){i.push([e,t,n,r])>1||s(e,t)}))})}function s(e,t){try{(n=o[e](t)).value instanceof c?Promise.resolve(n.value.v).then(a,l):f(i[0][2],n)}catch(e){f(i[0][3],e)}var n}function a(e){s("next",e)}function l(e){s("throw",e)}function f(e,t){e(t),i.shift(),i.length&&s(i[0][0],i[0][1])}}function f(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=u(e),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(n){t[n]=e[n]&&function(t){return new Promise((function(r,o){(function(e,t,n,r){Promise.resolve(r).then((function(t){e({value:t,done:n})}),t)})(r,o,(t=e[n](t)).done,t.value)}))}}}function p(e){return"function"==typeof e}function d(e){return function(t){if(function(e){return p(null==e?void 0:e.lift)}(t))return t.lift((function(t){try{return e(t,this)}catch(e){this.error(e)}}));throw new TypeError("Unable to lift unknown Observable type")}}function h(e){var t=e((function(e){Error.call(e),e.stack=(new Error).stack}));return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var y=h((function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map((function(e,t){return t+1+") "+e.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}}));function v(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var b=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._teardowns=null}var t;return e.prototype.unsubscribe=function(){var e,t,n,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var c=u(i),l=c.next();!l.done;l=c.next()){l.value.remove(this)}}catch(t){e={error:t}}finally{try{l&&!l.done&&(t=c.return)&&t.call(c)}finally{if(e)throw e.error}}else i.remove(this);var f=this.initialTeardown;if(p(f))try{f()}catch(e){o=e instanceof y?e.errors:[e]}var d=this._teardowns;if(d){this._teardowns=null;try{for(var h=u(d),v=h.next();!v.done;v=h.next()){var b=v.value;try{_(b)}catch(e){o=null!=o?o:[],e instanceof y?o=a(a([],s(o)),s(e.errors)):o.push(e)}}}catch(e){n={error:e}}finally{try{v&&!v.done&&(r=h.return)&&r.call(h)}finally{if(n)throw n.error}}}if(o)throw new y(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)_(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._teardowns=null!==(n=this._teardowns)&&void 0!==n?n:[]).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&v(t,e)},e.prototype.remove=function(t){var n=this._teardowns;n&&v(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=((t=new e).closed=!0,t),e}(),m=b.EMPTY;function w(e){return e instanceof b||e&&"closed"in e&&p(e.remove)&&p(e.add)&&p(e.unsubscribe)}function _(e){p(e)?e():e.unsubscribe()}var g={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},x={setTimeout:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=x.delegate;return((null==n?void 0:n.setTimeout)||setTimeout).apply(void 0,a([],s(e)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function S(e){x.setTimeout((function(){throw e}))}function k(){}function C(e){e()}var P=function(e){function t(t){var n=e.call(this)||this;return n.isStopped=!1,t?(n.destination=t,w(t)&&t.add(n)):n.destination=O,n}return n(t,e),t.create=function(e,t,n){return new E(e,t,n)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(b),E=function(e){function t(t,n,r){var o,i=e.call(this)||this;if(p(t))o=t;else if(t){var u;o=t.next,n=t.error,r=t.complete,i&&g.useDeprecatedNextContext?(u=Object.create(t)).unsubscribe=function(){return i.unsubscribe()}:u=t,o=null==o?void 0:o.bind(u),n=null==n?void 0:n.bind(u),r=null==r?void 0:r.bind(u)}return i.destination={next:o?T(o):k,error:T(null!=n?n:j),complete:r?T(r):k},i}return n(t,e),t}(P);function T(e,t){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{e.apply(void 0,a([],s(t)))}catch(e){S(e)}}}function j(e){throw e}var O={closed:!0,next:k,error:j,complete:k},U=function(e){function t(t,n,r,o,i){var u=e.call(this,t)||this;return u.onFinalize=i,u._next=n?function(e){try{n(e)}catch(e){t.error(e)}}:e.prototype._next,u._error=o?function(e){try{o(e)}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._error,u._complete=r?function(){try{r()}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._complete,u}return n(t,e),t.prototype.unsubscribe=function(){var t,n=this.closed;e.prototype.unsubscribe.call(this),!n&&(null===(t=this.onFinalize)||void 0===t||t.call(this))},t}(P);function A(e,t){return d((function(n,r){var o=0;n.subscribe(new U(r,(function(n){r.next(e.call(t,n,o++))})))}))}var F="function"==typeof Symbol&&Symbol.observable||"@@observable";function B(e){return e}function D(e){return 0===e.length?B:1===e.length?e[0]:function(t){return e.reduce((function(e,t){return t(e)}),t)}}var I=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(e,t,n){var r,o=this,i=(r=e)&&r instanceof P||function(e){return e&&p(e.next)&&p(e.error)&&p(e.complete)}(r)&&w(r)?e:new E(e,t,n);return C((function(){var e=o,t=e.operator,n=e.source;i.add(t?t.call(i,n):n?o._subscribe(i):o._trySubscribe(i))})),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var n=this;return new(t=z(t))((function(t,r){var o;o=n.subscribe((function(t){try{e(t)}catch(e){r(e),null==o||o.unsubscribe()}}),r,t)}))},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[F]=function(){return this},e.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return D(e)(this)},e.prototype.toPromise=function(e){var t=this;return new(e=z(e))((function(e,n){var r;t.subscribe((function(e){return r=e}),(function(e){return n(e)}),(function(){return e(r)}))}))},e.create=function(t){return new e(t)},e}();function z(e){var t;return null!==(t=null!=e?e:g.Promise)&&void 0!==t?t:Promise}function M(e){switch(e.responseType){case"json":if("response"in e)return e.response;var t=e;return JSON.parse(t.responseText);case"document":return e.responseXML;default:return"response"in e?e.response:(t=e).responseText}}var R=function(e,t,n,r){void 0===r&&(r="download_load"),this.originalEvent=e,this.xhr=t,this.request=n,this.type=r;var o=t.status,i=t.responseType;this.status=null!=o?o:0,this.responseType=null!=i?i:"";var u=t.getAllResponseHeaders();this.responseHeaders=u?u.split("\n").reduce((function(e,t){var n=t.indexOf(": ");return e[t.slice(0,n)]=t.slice(n+2),e}),{}):{},this.response=M(t);var s=e.loaded,a=e.total;this.loaded=s,this.total=a},q=h((function(e){return function(e,t,n){var r;this.message=e,this.name="AjaxError",this.xhr=t,this.request=n,this.status=t.status,this.responseType=t.responseType;try{r=M(t)}catch(e){r=t.responseText}this.response=r}})),H=function(){function e(e,t){return q.call(this,"ajax timeout",e,t),this.name="AjaxTimeoutError",this}return e.prototype=Object.create(q.prototype),e}();function L(e,t){return J({method:"GET",url:e,headers:t})}function N(e,t,n){return J({method:"POST",url:e,body:t,headers:n})}function K(e,t){return J({method:"DELETE",url:e,headers:t})}function Y(e,t,n){return J({method:"PUT",url:e,body:t,headers:n})}function X(e,t,n){return J({method:"PATCH",url:e,body:t,headers:n})}var W=A((function(e){return e.response}));function $(e,t){return W(J({method:"GET",url:e,headers:t}))}var G,J=(G=function(e){return function(e){return new I((function(t){var n,o,i,u=e.queryParams,s=e.body,a=e.headers,c=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(e,["queryParams","body","headers"]),l=c.url;if(!l)throw new TypeError("url is required");if(u)if(l.includes("?")){var f=l.split("?");if(2<f.length)throw new TypeError("invalid url");i=new URLSearchParams(f[1]),new URLSearchParams(u).forEach((function(e,t){return i.set(t,e)})),l=f[0]+"?"+i}else l=l+"?"+(i=new URLSearchParams(u));var p={};if(a)for(var d in a)a.hasOwnProperty(d)&&(p[d.toLowerCase()]=a[d]);e.crossDomain||"x-requested-with"in p||(p["x-requested-with"]="XMLHttpRequest");var h=c.withCredentials,y=c.xsrfCookieName,v=c.xsrfHeaderName;if((h||!c.crossDomain)&&y&&v){var b=null!==(o=null===(n=null===document||void 0===document?void 0:document.cookie.match(new RegExp("(^|;\\s*)("+y+")=([^;]*)")))||void 0===n?void 0:n.pop())&&void 0!==o?o:"";b&&(p[v]=b)}var m,w=function(e,t){var n;if(!e||"string"==typeof e||function(e){return"undefined"!=typeof FormData&&e instanceof FormData}(e)||function(e){return"undefined"!=typeof URLSearchParams&&e instanceof URLSearchParams}(e)||function(e){return re(e,"ArrayBuffer")}(e)||function(e){return re(e,"File")}(e)||function(e){return re(e,"Blob")}(e)||function(e){return"undefined"!=typeof ReadableStream&&e instanceof ReadableStream}(e))return e;if(function(e){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView(e)}(e))return e.buffer;if("object"==typeof e)return t["content-type"]=null!==(n=t["content-type"])&&void 0!==n?n:"application/json;charset=utf-8",JSON.stringify(e);throw new TypeError("Unknown body type")}(s,p),_=r(r({async:!0,crossDomain:!0,withCredentials:!1,method:"GET",timeout:0,responseType:"json"},c),{url:l,headers:p,body:w});m=e.createXHR?e.createXHR():new XMLHttpRequest;var g=e.progressSubscriber,x=e.includeDownloadProgress,S=void 0!==x&&x,k=e.includeUploadProgress,C=void 0!==k&&k,P=function(e,n){m.addEventListener(e,(function(){var e,r=n();null===(e=null==g?void 0:g.error)||void 0===e||e.call(g,r),t.error(r)}))};P("timeout",(function(){return new H(m,_)})),P("abort",(function(){return new q("aborted",m,_)}));var E=function(e,t){return new R(t,m,_,e+"_"+t.type)},T=function(e,n,r){e.addEventListener(n,(function(e){t.next(E(r,e))}))};C&&[Z,ee,te].forEach((function(e){return T(m.upload,e,V)})),g&&[Z,ee].forEach((function(e){return m.upload.addEventListener(e,(function(e){var t;return null===(t=null==g?void 0:g.next)||void 0===t?void 0:t.call(g,e)}))})),S&&[Z,ee].forEach((function(e){return T(m,e,Q)}));var j=function(e){var n="ajax error"+(e?" "+e:"");t.error(new q(n,m,_))};m.addEventListener("error",(function(e){var t;null===(t=null==g?void 0:g.error)||void 0===t||t.call(g,e),j()})),m.addEventListener(te,(function(e){var n,r,o=m.status;if(o<400){null===(n=null==g?void 0:g.complete)||void 0===n||n.call(g);var i=void 0;try{i=E(Q,e)}catch(e){return void t.error(e)}t.next(i),t.complete()}else null===(r=null==g?void 0:g.error)||void 0===r||r.call(g,e),j(o)}));var O=_.user,U=_.method,A=_.async;for(var d in O?m.open(U,l,A,O,_.password):m.open(U,l,A),A&&(m.timeout=_.timeout,m.responseType=_.responseType),"withCredentials"in m&&(m.withCredentials=_.withCredentials),p)p.hasOwnProperty(d)&&m.setRequestHeader(d,p[d]);return w?m.send(w):m.send(),function(){m&&4!==m.readyState&&m.abort()}}))}("string"==typeof e?{url:e}:e)},G.get=L,G.post=N,G.delete=K,G.put=Y,G.patch=X,G.getJSON=$,G),V="upload",Q="download",Z="loadstart",ee="progress",te="load";var ne=Object.prototype.toString;function re(e,t){return ne.call(e)==="[object "+t+"]"}var oe=h((function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),ie=function(e){function t(){var t=e.call(this)||this;return t.closed=!1,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return n(t,e),t.prototype.lift=function(e){var t=new ue(this,this);return t.operator=e,t},t.prototype._throwIfClosed=function(){if(this.closed)throw new oe},t.prototype.next=function(e){var t=this;C((function(){var n,r;if(t._throwIfClosed(),!t.isStopped){var o=t.observers.slice();try{for(var i=u(o),s=i.next();!s.done;s=i.next()){s.value.next(e)}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}}}))},t.prototype.error=function(e){var t=this;C((function(){if(t._throwIfClosed(),!t.isStopped){t.hasError=t.isStopped=!0,t.thrownError=e;for(var n=t.observers;n.length;)n.shift().error(e)}}))},t.prototype.complete=function(){var e=this;C((function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var t=e.observers;t.length;)t.shift().complete()}}))},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return(null===(e=this.observers)||void 0===e?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(t){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,t)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var t=this,n=t.hasError,r=t.isStopped,o=t.observers;return n||r?m:(o.push(e),new b((function(){return v(o,e)})))},t.prototype._checkFinalizedStatuses=function(e){var t=this,n=t.hasError,r=t.thrownError,o=t.isStopped;n?e.error(r):o&&e.complete()},t.prototype.asObservable=function(){var e=new I;return e.source=this,e},t.create=function(e,t){return new ue(e,t)},t}(I),ue=function(e){function t(t,n){var r=e.call(this)||this;return r.destination=t,r.source=n,r}return n(t,e),t.prototype.next=function(e){var t,n;null===(n=null===(t=this.destination)||void 0===t?void 0:t.next)||void 0===n||n.call(t,e)},t.prototype.error=function(e){var t,n;null===(n=null===(t=this.destination)||void 0===t?void 0:t.error)||void 0===n||n.call(t,e)},t.prototype.complete=function(){var e,t;null===(t=null===(e=this.destination)||void 0===e?void 0:e.complete)||void 0===t||t.call(e)},t.prototype._subscribe=function(e){var t,n;return null!==(n=null===(t=this.source)||void 0===t?void 0:t.subscribe(e))&&void 0!==n?n:m},t}(ie),se=new I((function(e){return e.complete()}));function ae(e){return e[e.length-1]}function ce(e){return(t=ae(e))&&p(t.schedule)?e.pop():void 0;var t}function le(e,t){return"number"==typeof ae(e)?e.pop():t}var fe=function(e){return e&&"number"==typeof e.length&&"function"!=typeof e};function pe(e){return p(null==e?void 0:e.then)}function de(e){return p(e[F])}function he(e){return Symbol.asyncIterator&&p(null==e?void 0:e[Symbol.asyncIterator])}function ye(e){return new TypeError("You provided "+(null!==e&&"object"==typeof e?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}var ve="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function be(e){return p(null==e?void 0:e[ve])}function me(e){return l(this,arguments,(function(){var t,n,r;return i(this,(function(o){switch(o.label){case 0:t=e.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,c(t.read())];case 3:return n=o.sent(),r=n.value,n.done?[4,c(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,c(r)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}}))}))}function we(e){return p(null==e?void 0:e.getReader)}function _e(e){if(e instanceof I)return e;if(null!=e){if(de(e))return o=e,new I((function(e){var t=o[F]();if(p(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(fe(e))return r=e,new I((function(e){for(var t=0;t<r.length&&!e.closed;t++)e.next(r[t]);e.complete()}));if(pe(e))return n=e,new I((function(e){n.then((function(t){e.closed||(e.next(t),e.complete())}),(function(t){return e.error(t)})).then(null,S)}));if(he(e))return ge(e);if(be(e))return t=e,new I((function(e){var n,r;try{for(var o=u(t),i=o.next();!i.done;i=o.next()){var s=i.value;if(e.next(s),e.closed)return}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}e.complete()}));if(we(e))return ge(me(e))}var t,n,r,o;throw ye(e)}function ge(e){return new I((function(t){(function(e,t){var n,r,u,s;return o(this,void 0,void 0,(function(){var o,a;return i(this,(function(i){switch(i.label){case 0:i.trys.push([0,5,6,11]),n=f(e),i.label=1;case 1:return[4,n.next()];case 2:if((r=i.sent()).done)return[3,4];if(o=r.value,t.next(o),t.closed)return[2];i.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=i.sent(),u={error:a},[3,11];case 6:return i.trys.push([6,,9,10]),r&&!r.done&&(s=n.return)?[4,s.call(n)]:[3,8];case 7:i.sent(),i.label=8;case 8:return[3,10];case 9:if(u)throw u.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}}))}))})(e,t).catch((function(e){return t.error(e)}))}))}function xe(e,t,n,r,o){void 0===r&&(r=0),void 0===o&&(o=!1);var i=t.schedule((function(){n(),o?e.add(this.schedule(null,r)):this.unsubscribe()}),r);if(e.add(i),!o)return i}function Se(e,t){return void 0===t&&(t=0),d((function(n,r){n.subscribe(new U(r,(function(n){return xe(r,e,(function(){return r.next(n)}),t)}),(function(){return xe(r,e,(function(){return r.complete()}),t)}),(function(n){return xe(r,e,(function(){return r.error(n)}),t)})))}))}function ke(e,t){return void 0===t&&(t=0),d((function(n,r){r.add(e.schedule((function(){return n.subscribe(r)}),t))}))}function Ce(e,t){if(!e)throw new Error("Iterable cannot be null");return new I((function(n){xe(n,t,(function(){var r=e[Symbol.asyncIterator]();xe(n,t,(function(){r.next().then((function(e){e.done?n.complete():n.next(e.value)}))}),0,!0)}))}))}function Pe(e,t){if(null!=e){if(de(e))return function(e,t){return _e(e).pipe(ke(t),Se(t))}(e,t);if(fe(e))return function(e,t){return new I((function(n){var r=0;return t.schedule((function(){r===e.length?n.complete():(n.next(e[r++]),n.closed||this.schedule())}))}))}(e,t);if(pe(e))return function(e,t){return _e(e).pipe(ke(t),Se(t))}(e,t);if(he(e))return Ce(e,t);if(be(e))return function(e,t){return new I((function(n){var r;return xe(n,t,(function(){r=e[ve](),xe(n,t,(function(){var e,t,o;try{t=(e=r.next()).value,o=e.done}catch(e){return void n.error(e)}o?n.complete():n.next(t)}),0,!0)})),function(){return p(null==r?void 0:r.return)&&r.return()}}))}(e,t);if(we(e))return function(e,t){return Ce(me(e),t)}(e,t)}throw ye(e)}function Ee(e,t){return t?Pe(e,t):_e(e)}function Te(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=ce(e);return Ee(e,n)}function je(e,t){var n=p(e)?e:function(){return e},r=function(e){return e.error(n())};return new I(t?function(e){return t.schedule(r,0,e)}:r)}function Oe(e,t,n){return void 0===n&&(n=1/0),p(t)?Oe((function(n,r){return A((function(e,o){return t(n,e,r,o)}))(_e(e(n,r)))}),n):("number"==typeof t&&(n=t),d((function(t,r){return function(e,t,n,r,o,i,u,s){var a=[],c=0,l=0,f=!1,p=function(){!f||a.length||c||t.complete()},d=function(e){return c<r?h(e):a.push(e)},h=function(e){i&&t.next(e),c++;var s=!1;_e(n(e,l++)).subscribe(new U(t,(function(e){null==o||o(e),i?d(e):t.next(e)}),(function(){s=!0}),void 0,(function(){if(s)try{c--;for(var e=function(){var e=a.shift();u?xe(t,u,(function(){return h(e)})):h(e)};a.length&&c<r;)e();p()}catch(e){t.error(e)}})))};return e.subscribe(new U(t,d,(function(){f=!0,p()}))),function(){null==s||s()}}(t,r,e,n)})))}function Ue(e){return void 0===e&&(e=1/0),Oe(B,e)}function Ae(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=ce(e),r=le(e,1/0),o=e;return o.length?1===o.length?_e(o[0]):Ue(r)(Ee(o,n)):se}function Fe(e,t){return d((function(n,r){var o=0;n.subscribe(new U(r,(function(n){return e.call(t,n,o++)&&r.next(n)})))}))}function Be(e){return d((function(t,n){var r,o=null,i=!1;o=t.subscribe(new U(n,void 0,void 0,(function(u){r=_e(e(u,Be(e)(t))),o?(o.unsubscribe(),o=null,r.subscribe(n)):i=!0}))),i&&(o.unsubscribe(),o=null,r.subscribe(n))}))}function De(e,t,n,r,o){return function(i,u){var s=n,a=t,c=0;i.subscribe(new U(u,(function(t){var n=c++;a=s?e(a,t,n):(s=!0,t),r&&u.next(a)}),o&&function(){s&&u.next(a),u.complete()}))}}var Ie=function(e,t){return e.push(t),e};function ze(){return d((function(e,t){(function(e,t){return d(De(e,t,arguments.length>=2,!1,!0))})(Ie,[])(e).subscribe(t)}))}function Me(e){return d((function(t,n){var r=!1;t.subscribe(new U(n,(function(e){r=!0,n.next(e)}),(function(){r||n.next(e),n.complete()})))}))}function Re(e,t){return e===t}function qe(e,t,n){var r=p(e)||t||n?{next:e,error:t,complete:n}:e;return r?d((function(e,t){var n;null===(n=r.subscribe)||void 0===n||n.call(r);var o=!0;e.subscribe(new U(t,(function(e){var n;null===(n=r.next)||void 0===n||n.call(r,e),t.next(e)}),(function(){var e;o=!1,null===(e=r.complete)||void 0===e||e.call(r),t.complete()}),(function(e){var n;o=!1,null===(n=r.error)||void 0===n||n.call(r,e),t.error(e)}),(function(){var e,t;o&&(null===(e=r.unsubscribe)||void 0===e||e.call(r)),null===(t=r.finalize)||void 0===t||t.call(r)})))})):B}class He{static create(...e){return new this(...e)}mixIn(e){return Object.assign(this,e)}clone(){const e=new this.constructor;return Object.assign(e,this),e}}class Le extends He{constructor(e=[],t=4*e.length){super();let n=e;if(n instanceof ArrayBuffer&&(n=new Uint8Array(n)),(n instanceof Int8Array||n instanceof Uint8ClampedArray||n instanceof Int16Array||n instanceof Uint16Array||n instanceof Int32Array||n instanceof Uint32Array||n instanceof Float32Array||n instanceof Float64Array)&&(n=new Uint8Array(n.buffer,n.byteOffset,n.byteLength)),n instanceof Uint8Array){const e=n.byteLength,t=[];for(let r=0;r<e;r+=1)t[r>>>2]|=n[r]<<24-r%4*8;this.words=t,this.sigBytes=e}else this.words=e,this.sigBytes=t}static random(e){const t=[],n=e=>{let t=e,n=987654321;const r=4294967295;return()=>{n=36969*(65535&n)+(n>>16)&r,t=18e3*(65535&t)+(t>>16)&r;let e=(n<<16)+t&r;return e/=4294967296,e+=.5,e*(Math.random()>.5?1:-1)}};for(let r,o=0;o<e;o+=4){const e=n(4294967296*(r||Math.random()));r=987654071*e(),t.push(4294967296*e()|0)}return new Le(t,e)}toString(e=Ne){return e.stringify(this)}concat(e){const t=this.words,n=e.words,r=this.sigBytes,o=e.sigBytes;if(this.clamp(),r%4)for(let e=0;e<o;e+=1){const o=n[e>>>2]>>>24-e%4*8&255;t[r+e>>>2]|=o<<24-(r+e)%4*8}else for(let e=0;e<o;e+=4)t[r+e>>>2]=n[e>>>2];return this.sigBytes+=o,this}clamp(){const{words:e,sigBytes:t}=this;e[t>>>2]&=4294967295<<32-t%4*8,e.length=Math.ceil(t/4)}clone(){const e=super.clone.call(this);return e.words=this.words.slice(0),e}}const Ne={stringify(e){const{words:t,sigBytes:n}=e,r=[];for(let e=0;e<n;e+=1){const n=t[e>>>2]>>>24-e%4*8&255;r.push((n>>>4).toString(16)),r.push((15&n).toString(16))}return r.join("")},parse(e){const t=e.length,n=[];for(let r=0;r<t;r+=2)n[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new Le(n,t/2)}},Ke={stringify(e){const{words:t,sigBytes:n}=e,r=[];for(let e=0;e<n;e+=1){const n=t[e>>>2]>>>24-e%4*8&255;r.push(String.fromCharCode(n))}return r.join("")},parse(e){const t=e.length,n=[];for(let r=0;r<t;r+=1)n[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new Le(n,t)}},Ye={stringify(e){try{return decodeURIComponent(escape(Ke.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:e=>Ke.parse(unescape(encodeURIComponent(e)))};class Xe extends He{constructor(){super(),this._minBufferSize=0}reset(){this._data=new Le,this._nDataBytes=0}_append(e){let t=e;"string"==typeof t&&(t=Ye.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes}_process(e){let t;const{_data:n,blockSize:r}=this,o=n.words,i=n.sigBytes;let u=i/(4*r);u=e?Math.ceil(u):Math.max((0|u)-this._minBufferSize,0);const s=u*r,a=Math.min(4*s,i);if(s){for(let e=0;e<s;e+=r)this._doProcessBlock(o,e);t=o.splice(0,s),n.sigBytes-=a}return new Le(t,a)}clone(){const e=super.clone.call(this);return e._data=this._data.clone(),e}}class We extends Xe{constructor(e){super(),this.blockSize=16,this.cfg=Object.assign(new He,e),this.reset()}static _createHelper(e){return(t,n)=>new e(n).finalize(t)}static _createHmacHelper(e){return(t,n)=>new $e(e,n).finalize(t)}reset(){super.reset.call(this),this._doReset()}update(e){return this._append(e),this._process(),this}finalize(e){e&&this._append(e);return this._doFinalize()}}class $e extends He{constructor(e,t){super();const n=new e;this._hasher=n;let r=t;"string"==typeof r&&(r=Ye.parse(r));const o=n.blockSize,i=4*o;r.sigBytes>i&&(r=n.finalize(t)),r.clamp();const u=r.clone();this._oKey=u;const s=r.clone();this._iKey=s;const a=u.words,c=s.words;for(let e=0;e<o;e+=1)a[e]^=1549556828,c[e]^=909522486;u.sigBytes=i,s.sigBytes=i,this.reset()}reset(){const e=this._hasher;e.reset(),e.update(this._iKey)}update(e){return this._hasher.update(e),this}finalize(e){const t=this._hasher,n=t.finalize(e);t.reset();return t.finalize(this._oKey.clone().concat(n))}}const Ge=[],Je=[],Ve=e=>{const t=Math.sqrt(e);for(let n=2;n<=t;n+=1)if(!(e%n))return!1;return!0},Qe=e=>4294967296*(e-(0|e))|0;let Ze=2,et=0;for(;et<64;)Ve(Ze)&&(et<8&&(Ge[et]=Qe(Ze**.5)),Je[et]=Qe(Ze**(1/3)),et+=1),Ze+=1;const tt=[];const nt=We._createHelper(class extends We{_doReset(){this._hash=new Le(Ge.slice(0))}_doProcessBlock(e,t){const n=this._hash.words;let r=n[0],o=n[1],i=n[2],u=n[3],s=n[4],a=n[5],c=n[6],l=n[7];for(let n=0;n<64;n+=1){if(n<16)tt[n]=0|e[t+n];else{const e=tt[n-15],t=(e<<25|e>>>7)^(e<<14|e>>>18)^e>>>3,r=tt[n-2],o=(r<<15|r>>>17)^(r<<13|r>>>19)^r>>>10;tt[n]=t+tt[n-7]+o+tt[n-16]}const f=r&o^r&i^o&i,p=(r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22),d=l+((s<<26|s>>>6)^(s<<21|s>>>11)^(s<<7|s>>>25))+(s&a^~s&c)+Je[n]+tt[n];l=c,c=a,a=s,s=u+d|0,u=i,i=o,o=r,r=d+(p+f)|0}n[0]=n[0]+r|0,n[1]=n[1]+o|0,n[2]=n[2]+i|0,n[3]=n[3]+u|0,n[4]=n[4]+s|0,n[5]=n[5]+a|0,n[6]=n[6]+c|0,n[7]=n[7]+l|0}_doFinalize(){const e=this._data,t=e.words,n=8*this._nDataBytes,r=8*e.sigBytes;return t[r>>>5]|=128<<24-r%32,t[14+(r+64>>>9<<4)]=Math.floor(n/4294967296),t[15+(r+64>>>9<<4)]=n,e.sigBytes=4*t.length,this._process(),this._hash}clone(){const e=super.clone.call(this);return e._hash=this._hash.clone(),e}});var rt=function(){return"undefined"!=typeof window&&"function"==typeof XMLHttpRequest&&"function"==typeof FormData},ot=function(){function e(e){var t,n=this;if(this._allowedConfigProperties=["url","method","headers","timeout","user","password","crossDomain","withCredentials","xsrfCookieName","xsrfHeaderName","responseType","queryParams"],this._allowedAjaxMethods=["POST","PUT"],this._defaultAjaxMethod="POST",this._oneKb=1024,this._chunkSize=this._oneKb*this._oneKb,this._addChecksum=!1,this._useChunks=!1,this._chunkMimeType="application/octet-stream",this._disableProgressCompletion=!1,this._numberOfFilesToUpload=0,this._rxFileUploadIds=[],this._rxFileUploadIdHeaderName="X-RxFileUpload-ID",this.upload=function(e,t){return n._checkInstanceProcess().pipe(Oe((function(){return Ee([].concat(e)).pipe(Fe((function(e){return e instanceof File})),ze(),Oe((function(e){return Te(e.length).pipe(Fe((function(e){return 0===e})),Oe((function(){return je((function(){return new Error("You must provide at least one file to upload.")}))})),Me(e))})),qe((function(){return n._rxFileUploadIds=[]})),qe((function(e){return n._numberOfFilesToUpload=e.length})),Oe((function(e){return Ee(e).pipe(Oe((function(r,o){return n._uploadFile(r,t,e.length>1?o:void 0)})))})))})))},this._checkInstanceProcess=function(){return Te(n._numberOfFilesToUpload).pipe(Fe((function(e){return 0!==e})),Oe((function(){return je((function(){return new Error('Files are already being uploaded for this instance of "RxFileUpload". You must either create a new instance before calling "upload" method or send them all together.')}))})),Me(void 0))},this._uploadFile=function(e,t,r){return n._generateRxFileUploadId(r).pipe(Oe((function(){return Ae(Te(n._useChunks).pipe(Fe((function(e){return!!e})),Oe((function(){return n._sendFileWithChunks(e,t,r)}))),Te(n._useChunks).pipe(Fe((function(e){return!e})),Oe((function(){return n._sendFile(e,t,r)}))))})))},this._sendFile=function(e,t,r){return n._fileBodyData(e,t,r).pipe(Oe((function(e){return n._makeAjaxCall(e,void 0,r)})))},this._sendFileWithChunks=function(e,t,r){return n._chunkBodyData(e,t,r).pipe((o=function(e){return n._makeAjaxCall(e.formData,e.chunkSequenceData,r)},p(i)?Oe(o,i,1):Oe(o,1)));var o,i},this._makeAjaxCall=function(e,t,o){return n._ajax(n._buildConfig(e,o)).pipe(Be((function(e){return je((function(){return{status:e.status,response:e.response}}))})),Oe((function(e){return Ae(Te(e.type).pipe(Fe((function(e){return"upload_progress"===e})),A((function(){return{progress:n._calculateProgress(Math.round(100*e.loaded/e.total),t)}})),Oe((function(e){return Te(o).pipe(Fe((function(e){return"number"==typeof e})),A((function(){return r(r({},e),{fileIndex:o})})),Me(e))})),qe((function(e){return n._progress$.next(e)})),A((function(){return e}))),Te(e.type).pipe(Fe((function(e){return"upload_load"===e})),Fe((function(){return void 0===t||t.sequence===t.totalChunks})),qe((function(){return n._numberOfFilesToUpload--})),qe((function(){return 0!==n._numberOfFilesToUpload||n._disableProgressCompletion?void 0:n._progress$.complete()})),A((function(){return e}))),Te(e.type).pipe(Fe((function(e){return"download_load"===e})),A((function(){return e}))))})),Fe((function(e){return"download_load"===e.type})),A((function(e){return{status:e.status,response:e.response,responseHeaders:Object.keys(e.responseHeaders).filter((function(e){return""!==e})).reduce((function(t,n){var o;return r(r({},t),((o={})[n]=e.responseHeaders[n],o))}),{})}})),Oe((function(e){return Te(o).pipe(Fe((function(e){return"number"==typeof e})),A((function(){return r(r({},e),{fileIndex:o})})),Me(e))})))},this._calculateProgress=function(e,t){return"object"==typeof t?Math.round(e/t.totalChunks+(t.sequence-1)*(100/t.totalChunks)):e},this._fileBodyData=function(e,t,o){return n._fileDataWithAdditionalData(e,t,o).pipe(A((function(t){return{formData:new FormData,data:r(r({},t),{file:e})}})),A((function(e){return Object.keys(e.data).forEach((function(t){return e.formData.append(t,e.data[t])})),e.formData})))},this._fileDataWithAdditionalData=function(e,t,o){return Te({name:e.name,size:e.size,lastModified:e.lastModified,type:e.type}).pipe(Oe((function(t){return Te(n._addChecksum).pipe(Fe((function(e){return!!e})),Oe((function(){return n._calculateCheckSum(e).pipe(A((function(e){return r(r({},t),{sha256Checksum:e})})))})),Me(t))})),A((function(e){return{rxFileUploadId:n._rxFileUploadIds["number"==typeof o?o:0],fileData:n._serialize(e)}})),A((function(e){var o;return void 0!==t&&"string"==typeof t.fieldName&&["string","object"].includes(typeof t.data)?r(r({},e),((o={})[t.fieldName]=n._serialize(t.data),o)):e})))},this._chunkBodyData=function(e,t,o){return n._fileDataWithAdditionalData(e,t,o).pipe(Oe((function(t){return n._calculateChunkSizes(e.size).pipe(Oe((function(o){return Ee(o).pipe(A((function(i,u){return{data:r(r({},t),{chunkData:n._serialize({name:e.name+".part"+(u+1),size:i.endByte-i.startByte,lastModified:e.lastModified,type:n._chunkMimeType,sequence:u+1,totalChunks:o.length,startByte:i.startByte,endByte:i.endByte}),file:new File([e.slice(i.startByte,i.endByte)],e.name+".part"+(u+1),{type:n._chunkMimeType,lastModified:e.lastModified})}),formData:new FormData,chunkSequenceData:{sequence:u+1,totalChunks:o.length}}})),A((function(e){return Object.keys(e.data).forEach((function(t){return e.formData.append(t,e.data[t])})),{formData:e.formData,chunkSequenceData:e.chunkSequenceData}})))})))})))},this._setAjaxConfig=function(e){Object.keys(e).forEach((function(e){if(!n._allowedConfigProperties.includes(e))throw new Error('"'+e+'" isn\'t a valid property of "RxFileUploadConfig"')})),n._config=r(r({},e.headers?r(r({},e),{headers:Object.keys(e.headers).filter((function(e){return"content-type"!==e.toLowerCase()})).reduce((function(t,n){var o;return r(r({},t),((o={})[n]=e.headers[n],o))}),{})}):r({},e)),{includeUploadProgress:!0})},this._buildConfig=function(e,t){var o;return r(r({},n._config),{headers:r(r({},n._config.headers),(o={},o[n._rxFileUploadIdHeaderName]=n._rxFileUploadIds["number"==typeof t?t:0],o)),body:e})},this._calculateChunkSizes=function(e){return Ee(Array.from({length:Math.max(Math.ceil(e/n._chunkSize),1)},(function(e,t){return t++}))).pipe(A((function(t){return{startByte:t*n._chunkSize,endByte:Math.min(e,(t+1)*n._chunkSize)}})),ze())},this._calculateCheckSum=function(e){return Ee(e.arrayBuffer()).pipe(A((function(e){return nt(Le.create(new Uint8Array(e))).toString()})))},this._generateRxFileUploadId=function(e){return Te((new Date).getTime()*Math.floor(10*Math.random()+1)).pipe(A((function(e){return nt(""+e).toString()})),qe((function(t){return n._rxFileUploadIds["number"==typeof e?e:0]=t})),A((function(){})))},this._serialize=function(e){return"string"==typeof e?e:JSON.stringify(e)},!rt())throw new Error("You must be in a compatible browser to use this library !!!");if("string"!=typeof(null==e?void 0:e.url))throw new Error("You must at least provide the url in the configuration !!!");if(this._allowedAjaxMethods.includes(null===(t=e.method)||void 0===t?void 0:t.toUpperCase())?e.method=e.method.toUpperCase():e.method=this._defaultAjaxMethod,"number"==typeof e.chunkSize){if(e.chunkSize%this._oneKb!=0)throw new Error("The size of a chunk must be a multiple of 1024 bytes / 1 Kb !!!");this._chunkSize=e.chunkSize,delete e.chunkSize}"boolean"==typeof e.addChecksum&&(this._addChecksum=e.addChecksum,delete e.addChecksum),"boolean"==typeof e.useChunks&&(this._useChunks=e.useChunks,delete e.useChunks),"boolean"==typeof e.disableProgressCompletion&&(this._disableProgressCompletion=e.disableProgressCompletion,delete e.disableProgressCompletion),this._setAjaxConfig(e),this._ajax=J,this._progress$=new ie}return Object.defineProperty(e.prototype,"progress$",{get:function(){return this._progress$.pipe((void 0===t&&(t=B),e=null!=e?e:Re,d((function(n,r){var o,i=!0;n.subscribe(new U(r,(function(n){var u=t(n);!i&&e(o,u)||(i=!1,o=u,r.next(n))})))}))));var e,t},enumerable:!1,configurable:!0}),e}();e.rxFileUpload=function(e){return new ot(e)},e.supportsRxFileUpload=rt,Object.defineProperty(e,"__esModule",{value:!0})}));