Socket
Socket
Sign inDemoInstall

@mux/upchunk

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mux/upchunk - npm Package Compare versions

Comparing version 3.3.3 to 3.4.0

6

dist/upchunk.cjs.js

@@ -1,4 +0,4 @@

var Ne=Object.create;var P=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Fe=Object.getPrototypeOf,Xe=Object.prototype.hasOwnProperty;var T=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),He=(t,e)=>{for(var n in e)P(t,n,{get:e[n],enumerable:!0})},G=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of De(e))!Xe.call(t,i)&&i!==n&&P(t,i,{get:()=>e[i],enumerable:!(r=Me(e,i))||r.enumerable});return t};var je=(t,e,n)=>(n=t!=null?Ne(Fe(t)):{},G(e||!t||!t.__esModule?P(n,"default",{value:t,enumerable:!0}):n,t)),We=t=>G(P({},"__esModule",{value:!0}),t);var ke=T((At,Ce)=>{var z;typeof window!="undefined"?z=window:typeof global!="undefined"?z=global:typeof self!="undefined"?z=self:z={};Ce.exports=z});var Se=T((Lt,Ee)=>{Ee.exports=ht;var ct=Object.prototype.toString;function ht(t){if(!t)return!1;var e=ct.call(t);return e==="[object Function]"||typeof t=="function"&&e!=="[object RegExp]"||typeof window!="undefined"&&(t===window.setTimeout||t===window.alert||t===window.confirm||t===window.prompt)}});var we=T((It,ve)=>{var W=function(t){return t.replace(/^\s+|\s+$/g,"")},dt=function(t){return Object.prototype.toString.call(t)==="[object Array]"};ve.exports=function(t){if(!t)return{};for(var e={},n=W(t).split(`
`),r=0;r<n.length;r++){var i=n[r],a=i.indexOf(":"),o=W(i.slice(0,a)).toLowerCase(),s=W(i.slice(a+1));typeof e[o]=="undefined"?e[o]=s:dt(e[o])?e[o].push(s):e[o]=[e[o],s]}return e}});var Te=T((Bt,Re)=>{Re.exports=ft;var pt=Object.prototype.hasOwnProperty;function ft(){for(var t={},e=0;e<arguments.length;e++){var n=arguments[e];for(var r in n)pt.call(n,r)&&(t[r]=n[r])}return t}});var Oe=T((xt,$)=>{"use strict";var ze=ke(),mt=Se(),gt=we(),bt=Te();$.exports=C;$.exports.default=C;C.XMLHttpRequest=ze.XMLHttpRequest||Et;C.XDomainRequest="withCredentials"in new C.XMLHttpRequest?C.XMLHttpRequest:ze.XDomainRequest;yt(["get","put","post","patch","head","delete"],function(t){C[t==="delete"?"del":t]=function(e,n,r){return n=_e(e,n,r),n.method=t.toUpperCase(),Pe(n)}});function yt(t,e){for(var n=0;n<t.length;n++)e(t[n])}function Ct(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function _e(t,e,n){var r=t;return mt(e)?(n=e,typeof t=="string"&&(r={uri:t})):r=bt(e,{uri:t}),r.callback=n,r}function C(t,e,n){return e=_e(t,e,n),Pe(e)}function Pe(t){if(typeof t.callback=="undefined")throw new Error("callback argument missing");var e=!1,n=function(E,_,Ue){e||(e=!0,t.callback(E,_,Ue))};function r(){s.readyState===4&&setTimeout(o,0)}function i(){var l=void 0;if(s.response?l=s.response:l=s.responseText||kt(s),V)try{l=JSON.parse(l)}catch{}return l}function a(l){return clearTimeout(N),l instanceof Error||(l=new Error(""+(l||"Unknown XMLHttpRequest Error"))),l.statusCode=0,n(l,q)}function o(){if(!h){var l;clearTimeout(N),t.useXDR&&s.status===void 0?l=200:l=s.status===1223?204:s.status;var E=q,_=null;return l!==0?(E={body:i(),statusCode:l,method:d,headers:{},url:p,rawRequest:s},s.getAllResponseHeaders&&(E.headers=gt(s.getAllResponseHeaders()))):_=new Error("Internal XMLHttpRequest Error"),n(_,E,E.body)}}var s=t.xhr||null;s||(t.cors||t.useXDR?s=new C.XDomainRequest:s=new C.XMLHttpRequest);var u,h,p=s.url=t.uri||t.url,d=s.method=t.method||"GET",y=t.body||t.data,f=s.headers=t.headers||{},U=!!t.sync,V=!1,N,q={body:void 0,headers:{},statusCode:0,method:d,url:p,rawRequest:s};if("json"in t&&t.json!==!1&&(V=!0,f.accept||f.Accept||(f.Accept="application/json"),d!=="GET"&&d!=="HEAD"&&(f["content-type"]||f["Content-Type"]||(f["Content-Type"]="application/json"),y=JSON.stringify(t.json===!0?y:t.json))),s.onreadystatechange=r,s.onload=o,s.onerror=a,s.onprogress=function(){},s.onabort=function(){h=!0},s.ontimeout=a,s.open(d,p,!U,t.username,t.password),U||(s.withCredentials=!!t.withCredentials),!U&&t.timeout>0&&(N=setTimeout(function(){if(!h){h=!0,s.abort("timeout");var l=new Error("XMLHttpRequest timeout");l.code="ETIMEDOUT",a(l)}},t.timeout)),s.setRequestHeader)for(u in f)f.hasOwnProperty(u)&&s.setRequestHeader(u,f[u]);else if(t.headers&&!Ct(t.headers))throw new Error("Headers cannot be set on an XDomainRequest object");return"responseType"in t&&(s.responseType=t.responseType),"beforeSend"in t&&typeof t.beforeSend=="function"&&t.beforeSend(s),s.send(y||null),s}function kt(t){try{if(t.responseType==="document")return t.responseXML;var e=t.responseXML&&t.responseXML.documentElement.nodeName==="parsererror";if(t.responseType===""&&!e)return t.responseXML}catch{}return null}function Et(){}});var zt={};He(zt,{ChunkedStreamIterable:()=>I,UpChunk:()=>R,createUpload:()=>Tt,getChunkSizeError:()=>L,isIncompleteChunkUploadNeedingRetry:()=>xe,isValidChunkSize:()=>A});module.exports=We(zt);function j(t,e,...n){if(!t)throw new TypeError(se(e,n))}function se(t,e){let n=0;return t.replace(/%[os]/gu,()=>ae(e[n++]))}function ae(t){return typeof t!="object"||t===null?String(t):Object.prototype.toString.call(t)}var Y;function $e(t){try{let e=t instanceof Error?t:new Error(ae(t));if(Y){Y(e);return}if(typeof dispatchEvent=="function"&&typeof ErrorEvent=="function")dispatchEvent(new ErrorEvent("error",{error:e,message:e.message}));else if(typeof process!="undefined"&&typeof process.emit=="function"){process.emit("uncaughtException",e);return}console.error(e)}catch{}}var m=typeof window!="undefined"?window:typeof self!="undefined"?self:typeof global!="undefined"?global:typeof globalThis!="undefined"?globalThis:void 0,K;var g=class{constructor(e,n){this.code=e,this.message=n}warn(...e){var n;try{if(K){K({...this,args:e});return}let r=((n=new Error().stack)!==null&&n!==void 0?n:"").replace(/^(?:.+?\n){2}/gu,`
`);console.warn(this.message,...e,r)}catch{}}},Ve=new g("W01","Unable to initialize event under dispatching."),qe=new g("W02","Assigning any falsy value to 'cancelBubble' property has no effect."),Ge=new g("W03","Assigning any truthy value to 'returnValue' property has no effect."),Ye=new g("W04","Unable to preventDefault on non-cancelable events."),Ke=new g("W05","Unable to preventDefault inside passive event listener invocation."),Ze=new g("W06","An event listener wasn't added because it has been added already: %o, %o"),M=new g("W07","The %o option value was abandoned because the event listener wasn't added as duplicated."),Z=new g("W08","The 'callback' argument must be a function or an object that has 'handleEvent' method: %o"),Pt=new g("W09","Event attribute handler must be a function: %o"),b=class{static get NONE(){return J}static get CAPTURING_PHASE(){return Q}static get AT_TARGET(){return ee}static get BUBBLING_PHASE(){return te}constructor(e,n){Object.defineProperty(this,"isTrusted",{value:!1,enumerable:!0});let r=n!=null?n:{};H.set(this,{type:String(e),bubbles:Boolean(r.bubbles),cancelable:Boolean(r.cancelable),composed:Boolean(r.composed),target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1,inPassiveListenerFlag:!1,dispatchFlag:!1,timeStamp:Date.now()})}get type(){return c(this).type}get target(){return c(this).target}get srcElement(){return c(this).target}get currentTarget(){return c(this).currentTarget}composedPath(){let e=c(this).currentTarget;return e?[e]:[]}get NONE(){return J}get CAPTURING_PHASE(){return Q}get AT_TARGET(){return ee}get BUBBLING_PHASE(){return te}get eventPhase(){return c(this).dispatchFlag?2:0}stopPropagation(){c(this).stopPropagationFlag=!0}get cancelBubble(){return c(this).stopPropagationFlag}set cancelBubble(e){e?c(this).stopPropagationFlag=!0:qe.warn()}stopImmediatePropagation(){let e=c(this);e.stopPropagationFlag=e.stopImmediatePropagationFlag=!0}get bubbles(){return c(this).bubbles}get cancelable(){return c(this).cancelable}get returnValue(){return!c(this).canceledFlag}set returnValue(e){e?Ge.warn():ne(c(this))}preventDefault(){ne(c(this))}get defaultPrevented(){return c(this).canceledFlag}get composed(){return c(this).composed}get isTrusted(){return!1}get timeStamp(){return c(this).timeStamp}initEvent(e,n=!1,r=!1){let i=c(this);if(i.dispatchFlag){Ve.warn();return}H.set(this,{...i,type:String(e),bubbles:Boolean(n),cancelable:Boolean(r),target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1})}},J=0,Q=1,ee=2,te=3,H=new WeakMap;function c(t,e="this"){let n=H.get(t);return j(n!=null,"'%s' must be an object that Event constructor created, but got another one: %o",e,t),n}function ne(t){if(t.inPassiveListenerFlag){Ke.warn();return}if(!t.cancelable){Ye.warn();return}t.canceledFlag=!0}Object.defineProperty(b,"NONE",{enumerable:!0});Object.defineProperty(b,"CAPTURING_PHASE",{enumerable:!0});Object.defineProperty(b,"AT_TARGET",{enumerable:!0});Object.defineProperty(b,"BUBBLING_PHASE",{enumerable:!0});var D=Object.getOwnPropertyNames(b.prototype);for(let t=0;t<D.length;++t)D[t]!=="constructor"&&Object.defineProperty(b.prototype,D[t],{enumerable:!0});typeof m!="undefined"&&typeof m.Event!="undefined"&&Object.setPrototypeOf(b.prototype,m.Event.prototype);function Je(t){return m.DOMException?new m.DOMException(t,"InvalidStateError"):(v==null&&(v=class oe extends Error{constructor(n){super(n),Error.captureStackTrace&&Error.captureStackTrace(this,oe)}get code(){return 11}get name(){return"InvalidStateError"}},Object.defineProperties(v.prototype,{code:{enumerable:!0},name:{enumerable:!0}}),ie(v),ie(v.prototype)),new v(t))}var v,re={INDEX_SIZE_ERR:1,DOMSTRING_SIZE_ERR:2,HIERARCHY_REQUEST_ERR:3,WRONG_DOCUMENT_ERR:4,INVALID_CHARACTER_ERR:5,NO_DATA_ALLOWED_ERR:6,NO_MODIFICATION_ALLOWED_ERR:7,NOT_FOUND_ERR:8,NOT_SUPPORTED_ERR:9,INUSE_ATTRIBUTE_ERR:10,INVALID_STATE_ERR:11,SYNTAX_ERR:12,INVALID_MODIFICATION_ERR:13,NAMESPACE_ERR:14,INVALID_ACCESS_ERR:15,VALIDATION_ERR:16,TYPE_MISMATCH_ERR:17,SECURITY_ERR:18,NETWORK_ERR:19,ABORT_ERR:20,URL_MISMATCH_ERR:21,QUOTA_EXCEEDED_ERR:22,TIMEOUT_ERR:23,INVALID_NODE_TYPE_ERR:24,DATA_CLONE_ERR:25};function ie(t){let e=Object.keys(re);for(let n=0;n<e.length;++n){let r=e[n],i=re[r];Object.defineProperty(t,r,{get(){return i},configurable:!0,enumerable:!0})}}var w=class extends b{static wrap(e){return new(le(e))(e)}constructor(e){super(e.type,{bubbles:e.bubbles,cancelable:e.cancelable,composed:e.composed}),e.cancelBubble&&super.stopPropagation(),e.defaultPrevented&&super.preventDefault(),ue.set(this,{original:e});let n=Object.keys(e);for(let r=0;r<n.length;++r){let i=n[r];i in this||Object.defineProperty(this,i,ce(e,i))}}stopPropagation(){super.stopPropagation();let{original:e}=k(this);"stopPropagation"in e&&e.stopPropagation()}get cancelBubble(){return super.cancelBubble}set cancelBubble(e){super.cancelBubble=e;let{original:n}=k(this);"cancelBubble"in n&&(n.cancelBubble=e)}stopImmediatePropagation(){super.stopImmediatePropagation();let{original:e}=k(this);"stopImmediatePropagation"in e&&e.stopImmediatePropagation()}get returnValue(){return super.returnValue}set returnValue(e){super.returnValue=e;let{original:n}=k(this);"returnValue"in n&&(n.returnValue=e)}preventDefault(){super.preventDefault();let{original:e}=k(this);"preventDefault"in e&&e.preventDefault()}get timeStamp(){let{original:e}=k(this);return"timeStamp"in e?e.timeStamp:super.timeStamp}},ue=new WeakMap;function k(t){let e=ue.get(t);return j(e!=null,"'this' is expected an Event object, but got",t),e}var O=new WeakMap;O.set(Object.prototype,w);typeof m!="undefined"&&typeof m.Event!="undefined"&&O.set(m.Event.prototype,w);function le(t){let e=Object.getPrototypeOf(t);if(e==null)return w;let n=O.get(e);return n==null&&(n=Qe(le(e),e),O.set(e,n)),n}function Qe(t,e){class n extends t{}let r=Object.keys(e);for(let i=0;i<r.length;++i)Object.defineProperty(n.prototype,r[i],ce(e,r[i]));return n}function ce(t,e){let n=Object.getOwnPropertyDescriptor(t,e);return{get(){let r=k(this).original,i=r[e];return typeof i=="function"?i.bind(r):i},set(r){let i=k(this).original;i[e]=r},configurable:n.configurable,enumerable:n.enumerable}}function et(t,e,n,r,i,a){return{callback:t,flags:(e?1:0)|(n?2:0)|(r?4:0),signal:i,signalListener:a}}function tt(t){t.flags|=8}function he(t){return(t.flags&1)===1}function de(t){return(t.flags&2)===2}function pe(t){return(t.flags&4)===4}function nt(t){return(t.flags&8)===8}function rt({callback:t},e,n){try{typeof t=="function"?t.call(e,n):typeof t.handleEvent=="function"&&t.handleEvent(n)}catch(r){$e(r)}}function fe({listeners:t},e,n){for(let r=0;r<t.length;++r)if(t[r].callback===e&&he(t[r])===n)return r;return-1}function it(t,e,n,r,i,a){let o;a&&(o=me.bind(null,t,e,n),a.addEventListener("abort",o));let s=et(e,n,r,i,a,o);return t.cow?(t.cow=!1,t.listeners=[...t.listeners,s]):t.listeners.push(s),s}function me(t,e,n){let r=fe(t,e,n);return r!==-1?ge(t,r):!1}function ge(t,e,n=!1){let r=t.listeners[e];return tt(r),r.signal&&r.signal.removeEventListener("abort",r.signalListener),t.cow&&!n?(t.cow=!1,t.listeners=t.listeners.filter((i,a)=>a!==e),!1):(t.listeners.splice(e,1),!0)}function st(){return Object.create(null)}function at(t,e){var n;return(n=t[e])!==null&&n!==void 0?n:t[e]={attrCallback:void 0,attrListener:void 0,cow:!1,listeners:[]}}var S=class{constructor(){be.set(this,st())}addEventListener(e,n,r){let i=F(this),{callback:a,capture:o,once:s,passive:u,signal:h,type:p}=ot(e,n,r);if(a==null||(h==null?void 0:h.aborted))return;let d=at(i,p),y=fe(d,a,o);if(y!==-1){lt(d.listeners[y],u,s,h);return}it(d,a,o,u,s,h)}removeEventListener(e,n,r){let i=F(this),{callback:a,capture:o,type:s}=ut(e,n,r),u=i[s];a!=null&&u&&me(u,a,o)}dispatchEvent(e){let n=F(this)[String(e.type)];if(n==null)return!0;let r=e instanceof b?e:w.wrap(e),i=c(r,"event");if(i.dispatchFlag)throw Je("This event has been in dispatching.");if(i.dispatchFlag=!0,i.target=i.currentTarget=this,!i.stopPropagationFlag){let{cow:a,listeners:o}=n;n.cow=!0;for(let s=0;s<o.length;++s){let u=o[s];if(!nt(u)&&(pe(u)&&ge(n,s,!a)&&(s-=1),i.inPassiveListenerFlag=de(u),rt(u,this,r),i.inPassiveListenerFlag=!1,i.stopImmediatePropagationFlag))break}a||(n.cow=!1)}return i.target=null,i.currentTarget=null,i.stopImmediatePropagationFlag=!1,i.stopPropagationFlag=!1,i.dispatchFlag=!1,!i.canceledFlag}},be=new WeakMap;function F(t,e="this"){let n=be.get(t);return j(n!=null,"'%s' must be an object that EventTarget constructor created, but got another one: %o",e,t),n}function ot(t,e,n){var r;return ye(e),typeof n=="object"&&n!==null?{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n.capture),passive:Boolean(n.passive),once:Boolean(n.once),signal:(r=n.signal)!==null&&r!==void 0?r:void 0}:{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n),passive:!1,once:!1,signal:void 0}}function ut(t,e,n){return ye(e),typeof n=="object"&&n!==null?{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n.capture)}:{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n)}}function ye(t){if(!(typeof t=="function"||typeof t=="object"&&t!==null&&typeof t.handleEvent=="function")){if(t==null||typeof t=="object"){Z.warn(t);return}throw new TypeError(se(Z.message,[t]))}}function lt(t,e,n,r){Ze.warn(he(t)?"capture":"bubble",t.callback),de(t)!==e&&M.warn("passive"),pe(t)!==n&&M.warn("once"),t.signal!==r&&M.warn("signal")}var X=Object.getOwnPropertyNames(S.prototype);for(let t=0;t<X.length;++t)X[t]!=="constructor"&&Object.defineProperty(S.prototype,X[t],{enumerable:!0});typeof m!="undefined"&&typeof m.EventTarget!="undefined"&&Object.setPrototypeOf(S.prototype,m.EventTarget.prototype);var Ae=je(Oe()),Le=30720,B=512e3,x=256,A=(t,{minChunkSize:e=x,maxChunkSize:n=B}={})=>t==null||typeof t=="number"&&t>=256&&t%256===0&&t>=e&&t<=n,L=(t,{minChunkSize:e=x,maxChunkSize:n=B}={})=>new TypeError(`chunkSize ${t} must be a positive number in multiples of 256, between ${e} and ${n}`),I=class{constructor(e,n={}){this.readableStream=e;var r,i,a;if(!A(n.defaultChunkSize,n))throw L(n.defaultChunkSize,n);this.defaultChunkSize=(r=n.defaultChunkSize)!=null?r:Le,this.minChunkSize=(i=n.minChunkSize)!=null?i:x,this.maxChunkSize=(a=n.maxChunkSize)!=null?a:B}get chunkSize(){var e;return(e=this._chunkSize)!=null?e:this.defaultChunkSize}set chunkSize(e){if(!A(e,this))throw L(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}get error(){return this._error}async*[Symbol.asyncIterator](){let e,n=this.readableStream.getReader();try{for(;;){let{done:r,value:i}=await n.read();if(r){if(e){let o=e;e=void 0,yield o}break}let a=i instanceof Uint8Array?new Blob([i],{type:"application/octet-stream"}):i;for(e=e?new Blob([e,a]):a;e;)if(e.size===this.chunkByteSize){let o=e;e=void 0,yield o;break}else{if(e.size<this.chunkByteSize)break;{let o=e.slice(0,this.chunkByteSize);e=e.slice(this.chunkByteSize),yield o}}}}catch(r){this._error=r}finally{if(e){let r=e;e=void 0,yield r}n.releaseLock();return}}},St=[200,201,202,204,308],Ie=[408,502,503,504],vt=[308],Be=(t,e)=>!!t&&St.includes(t.statusCode),wt=(t,{retryCodes:e=Ie})=>!t||e.includes(t.statusCode),Rt=(t,e)=>e.attemptCount>=e.attempts||!(Be(t)||wt(t,e)),xe=(t,e)=>{var i;if(!t||!vt.includes(t.statusCode)||!((i=t.headers)!=null&&i.range))return!1;let n=t.headers.range.match(/bytes=(\d+)-(\d+)/);return n?parseInt(n[2],10)!==e.currentChunkEndByte:!1},R=class{static createUpload(e){return new R(e)}constructor(e){this.endpoint=e.endpoint,this.file=e.file,this.headers=e.headers||{},this.method=e.method||"PUT",this.attempts=e.attempts||5,this.delayBeforeAttempt=e.delayBeforeAttempt||1,this.retryCodes=e.retryCodes||Ie,this.dynamicChunkSize=e.dynamicChunkSize||!1,this.maxFileBytes=(e.maxFileSize||0)*1024,this.chunkCount=0,this.attemptCount=0,this._offline=typeof window!="undefined"&&!window.navigator.onLine,this._paused=!1,this.success=!1,this.nextChunkRangeStart=0,this.chunkedStreamIterable=new I(this.file.stream(),{...e,defaultChunkSize:e.chunkSize}),this.chunkedStreamIterator=this.chunkedStreamIterable[Symbol.asyncIterator](),this.totalChunks=Math.ceil(this.file.size/this.chunkByteSize),this.eventTarget=new S,this.validateOptions(),this.getEndpoint().then(()=>this.sendChunks()),typeof window!="undefined"&&(window.addEventListener("online",()=>{!this.offline||(this._offline=!1,this.dispatch("online"),this.sendChunks())}),window.addEventListener("offline",()=>{this.offline||(this._offline=!0,this.dispatch("offline"))}))}get maxChunkSize(){var e,n;return(n=(e=this.chunkedStreamIterable)==null?void 0:e.maxChunkSize)!=null?n:B}get minChunkSize(){var e,n;return(n=(e=this.chunkedStreamIterable)==null?void 0:e.minChunkSize)!=null?n:x}get chunkSize(){var e,n;return(n=(e=this.chunkedStreamIterable)==null?void 0:e.chunkSize)!=null?n:Le}set chunkSize(e){this.chunkedStreamIterable.chunkSize=e}get chunkByteSize(){return this.chunkedStreamIterable.chunkByteSize}get totalChunkSize(){return Math.ceil(this.file.size/this.chunkByteSize)}on(e,n){this.eventTarget.addEventListener(e,n)}once(e,n){this.eventTarget.addEventListener(e,n,{once:!0})}off(e,n){this.eventTarget.removeEventListener(e,n)}get offline(){return this._offline}get paused(){return this._paused}abort(){var e;this.pause(),(e=this.currentXhr)==null||e.abort()}pause(){this._paused=!0}resume(){this._paused&&(this._paused=!1,this.sendChunks())}get successfulPercentage(){return this.nextChunkRangeStart/this.file.size}dispatch(e,n){let r=new CustomEvent(e,{detail:n});this.eventTarget.dispatchEvent(r)}validateOptions(){if(!this.endpoint||typeof this.endpoint!="function"&&typeof this.endpoint!="string")throw new TypeError("endpoint must be defined as a string or a function that returns a promise");if(!(this.file instanceof File))throw new TypeError("file must be a File object");if(this.headers&&typeof this.headers!="function"&&typeof this.headers!="object")throw new TypeError("headers must be null, an object, or a function that returns an object or a promise");if(!A(this.chunkSize,{maxChunkSize:this.maxChunkSize,minChunkSize:this.minChunkSize}))throw L(this.chunkSize,{maxChunkSize:this.maxChunkSize,minChunkSize:this.minChunkSize});if(this.maxChunkSize&&(typeof this.maxChunkSize!="number"||this.maxChunkSize<256||this.maxChunkSize%256!==0||this.maxChunkSize<this.chunkSize||this.maxChunkSize<this.minChunkSize))throw new TypeError(`maxChunkSize must be a positive number in multiples of 256, and larger than or equal to both ${this.minChunkSize} and ${this.chunkSize}`);if(this.minChunkSize&&(typeof this.minChunkSize!="number"||this.minChunkSize<256||this.minChunkSize%256!==0||this.minChunkSize>this.chunkSize||this.minChunkSize>this.maxChunkSize))throw new TypeError(`minChunkSize must be a positive number in multiples of 256, and smaller than ${this.chunkSize} and ${this.maxChunkSize}`);if(this.maxFileBytes>0&&this.maxFileBytes<this.file.size)throw new Error(`file size exceeds maximum (${this.file.size} > ${this.maxFileBytes})`);if(this.attempts&&(typeof this.attempts!="number"||this.attempts<=0))throw new TypeError("retries must be a positive number");if(this.delayBeforeAttempt&&(typeof this.delayBeforeAttempt!="number"||this.delayBeforeAttempt<0))throw new TypeError("delayBeforeAttempt must be a positive number")}getEndpoint(){return typeof this.endpoint=="string"?(this.endpointValue=this.endpoint,Promise.resolve(this.endpoint)):this.endpoint(this.file).then(e=>(this.endpointValue=e,this.endpointValue))}xhrPromise(e){let n=r=>{r.upload.onprogress=i=>{var h;let a=this.totalChunks-this.chunkCount,o=(this.file.size-this.nextChunkRangeStart)/this.file.size/a,u=i.loaded/((h=i.total)!=null?h:this.chunkByteSize)*o;this.dispatch("progress",Math.min((this.successfulPercentage+u)*100,100))}};return new Promise((r,i)=>{this.currentXhr=(0,Ae.default)({...e,beforeSend:n},(a,o)=>(this.currentXhr=void 0,a?i(a):r(o)))})}async sendChunk(e){let n=this.nextChunkRangeStart,r=n+e.size-1,a={...await(typeof this.headers=="function"?this.headers():this.headers),"Content-Type":this.file.type,"Content-Range":`bytes ${n}-${r}/${this.file.size}`};return this.dispatch("attempt",{chunkNumber:this.chunkCount,totalChunks:this.totalChunks,chunkSize:this.chunkSize}),this.xhrPromise({headers:a,url:this.endpointValue,method:this.method,body:e})}async sendChunkWithRetries(e){let n=async(s,u)=>{var d;let p=(new Date().getTime()-this.lastChunkStart.getTime())/1e3;if(this.dispatch("chunkSuccess",{chunk:this.chunkCount,chunkSize:this.chunkSize,attempts:this.attemptCount,timeInterval:p,response:s}),this.attemptCount=0,this.chunkCount=((d=this.chunkCount)!=null?d:0)+1,this.nextChunkRangeStart=this.nextChunkRangeStart+this.chunkByteSize,this.dynamicChunkSize){let y=this.chunkSize;p<10?y=Math.min(this.chunkSize*2,this.maxChunkSize):p>30&&(y=Math.max(this.chunkSize/2,this.minChunkSize)),this.chunkSize=Math.ceil(y/256)*256;let f=(this.file.size-this.nextChunkRangeStart)/this.chunkByteSize;this.totalChunks=Math.ceil(this.chunkCount+f)}return!0},r=async(s,u)=>(this.dispatch("progress",Math.min(this.successfulPercentage*100,100)),this.dispatch("error",{message:`Server responded with ${s.statusCode}. Stopping upload.`,chunk:this.chunkCount,attempts:this.attemptCount,response:s}),!1),i=async(s,u)=>(this.dispatch("attemptFailure",{message:`An error occured uploading chunk ${this.chunkCount}. ${this.attempts-this.attemptCount} retries left.`,chunkNumber:this.chunkCount,attemptsLeft:this.attempts-this.attemptCount,response:s}),new Promise(h=>{setTimeout(async()=>{if(this._paused||this.offline){this.pendingChunk=e,h(!1);return}let p=await this.sendChunkWithRetries(e);h(p)},this.delayBeforeAttempt*1e3)})),a;try{this.attemptCount=this.attemptCount+1,this.lastChunkStart=new Date,a=await this.sendChunk(e)}catch(s){typeof(s==null?void 0:s.statusCode)=="number"&&(a=s)}let o={retryCodes:this.retryCodes,attemptCount:this.attemptCount,attempts:this.attempts,currentChunkEndByte:this.nextChunkRangeStart+e.size-1};return xe(a,o)?i(a,e):Be(a,o)?n(a,e):Rt(a,o)?r(a,e):i(a,e)}async sendChunks(){if(this.pendingChunk&&!(this._paused||this.offline)){let e=this.pendingChunk;this.pendingChunk=void 0;let n=await this.sendChunkWithRetries(e);this.success&&n&&this.dispatch("success")}for(;!(this.success||this._paused||this.offline);){let{value:e,done:n}=await this.chunkedStreamIterator.next(),r=!e&&n;if(e&&(r=await this.sendChunkWithRetries(e)),this.chunkedStreamIterable.error&&(this.dispatch("error",{message:`Unable to read file of size ${this.file.size} bytes. Try loading from another browser.`}),r=!1),this.success=!!n,this.success&&r&&this.dispatch("success"),!r)return}}};function Tt(t){return R.createUpload(t)}
var Me=Object.create;var L=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Xe=Object.getPrototypeOf,He=Object.prototype.hasOwnProperty;var _=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),je=(t,e)=>{for(var n in e)L(t,n,{get:e[n],enumerable:!0})},K=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of De(e))!He.call(t,i)&&i!==n&&L(t,i,{get:()=>e[i],enumerable:!(r=Ne(e,i))||r.enumerable});return t};var We=(t,e,n)=>(n=t!=null?Me(Xe(t)):{},K(e||!t||!t.__esModule?L(n,"default",{value:t,enumerable:!0}):n,t)),$e=t=>K(L({},"__esModule",{value:!0}),t);var Ee=_((It,Se)=>{var P;typeof window!="undefined"?P=window:typeof global!="undefined"?P=global:typeof self!="undefined"?P=self:P={};Se.exports=P});var we=_((Lt,ve)=>{ve.exports=dt;var ht=Object.prototype.toString;function dt(t){if(!t)return!1;var e=ht.call(t);return e==="[object Function]"||typeof t=="function"&&e!=="[object RegExp]"||typeof window!="undefined"&&(t===window.setTimeout||t===window.alert||t===window.confirm||t===window.prompt)}});var ze=_((Bt,Re)=>{var $=function(t){return t.replace(/^\s+|\s+$/g,"")},ft=function(t){return Object.prototype.toString.call(t)==="[object Array]"};Re.exports=function(t){if(!t)return{};for(var e={},n=$(t).split(`
`),r=0;r<n.length;r++){var i=n[r],a=i.indexOf(":"),o=$(i.slice(0,a)).toLowerCase(),s=$(i.slice(a+1));typeof e[o]=="undefined"?e[o]=s:ft(e[o])?e[o].push(s):e[o]=[e[o],s]}return e}});var _e=_((xt,Te)=>{Te.exports=mt;var pt=Object.prototype.hasOwnProperty;function mt(){for(var t={},e=0;e<arguments.length;e++){var n=arguments[e];for(var r in n)pt.call(n,r)&&(t[r]=n[r])}return t}});var Ie=_((Ut,V)=>{"use strict";var Pe=Ee(),bt=we(),gt=ze(),yt=_e();V.exports=k;V.exports.default=k;k.XMLHttpRequest=Pe.XMLHttpRequest||Et;k.XDomainRequest="withCredentials"in new k.XMLHttpRequest?k.XMLHttpRequest:Pe.XDomainRequest;kt(["get","put","post","patch","head","delete"],function(t){k[t==="delete"?"del":t]=function(e,n,r){return n=Oe(e,n,r),n.method=t.toUpperCase(),Ae(n)}});function kt(t,e){for(var n=0;n<t.length;n++)e(t[n])}function Ct(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function Oe(t,e,n){var r=t;return bt(e)?(n=e,typeof t=="string"&&(r={uri:t})):r=yt(e,{uri:t}),r.callback=n,r}function k(t,e,n){return e=Oe(t,e,n),Ae(e)}function Ae(t){if(typeof t.callback=="undefined")throw new Error("callback argument missing");var e=!1,n=function(S,I,Fe){e||(e=!0,t.callback(S,I,Fe))};function r(){s.readyState===4&&setTimeout(o,0)}function i(){var l=void 0;if(s.response?l=s.response:l=s.responseText||St(s),G)try{l=JSON.parse(l)}catch{}return l}function a(l){return clearTimeout(M),l instanceof Error||(l=new Error(""+(l||"Unknown XMLHttpRequest Error"))),l.statusCode=0,n(l,Y)}function o(){if(!h){var l;clearTimeout(M),t.useXDR&&s.status===void 0?l=200:l=s.status===1223?204:s.status;var S=Y,I=null;return l!==0?(S={body:i(),statusCode:l,method:d,headers:{},url:f,rawRequest:s},s.getAllResponseHeaders&&(S.headers=gt(s.getAllResponseHeaders()))):I=new Error("Internal XMLHttpRequest Error"),n(I,S,S.body)}}var s=t.xhr||null;s||(t.cors||t.useXDR?s=new k.XDomainRequest:s=new k.XMLHttpRequest);var u,h,f=s.url=t.uri||t.url,d=s.method=t.method||"GET",y=t.body||t.data,p=s.headers=t.headers||{},F=!!t.sync,G=!1,M,Y={body:void 0,headers:{},statusCode:0,method:d,url:f,rawRequest:s};if("json"in t&&t.json!==!1&&(G=!0,p.accept||p.Accept||(p.Accept="application/json"),d!=="GET"&&d!=="HEAD"&&(p["content-type"]||p["Content-Type"]||(p["Content-Type"]="application/json"),y=JSON.stringify(t.json===!0?y:t.json))),s.onreadystatechange=r,s.onload=o,s.onerror=a,s.onprogress=function(){},s.onabort=function(){h=!0},s.ontimeout=a,s.open(d,f,!F,t.username,t.password),F||(s.withCredentials=!!t.withCredentials),!F&&t.timeout>0&&(M=setTimeout(function(){if(!h){h=!0,s.abort("timeout");var l=new Error("XMLHttpRequest timeout");l.code="ETIMEDOUT",a(l)}},t.timeout)),s.setRequestHeader)for(u in p)p.hasOwnProperty(u)&&s.setRequestHeader(u,p[u]);else if(t.headers&&!Ct(t.headers))throw new Error("Headers cannot be set on an XDomainRequest object");return"responseType"in t&&(s.responseType=t.responseType),"beforeSend"in t&&typeof t.beforeSend=="function"&&t.beforeSend(s),s.send(y||null),s}function St(t){try{if(t.responseType==="document")return t.responseXML;var e=t.responseXML&&t.responseXML.documentElement.nodeName==="parsererror";if(t.responseType===""&&!e)return t.responseXML}catch{}return null}function Et(){}});var _t={};je(_t,{ChunkedFileIterable:()=>U,ChunkedStreamIterable:()=>x,UpChunk:()=>T,createUpload:()=>Tt,getChunkSizeError:()=>z,isIncompleteChunkUploadNeedingRetry:()=>Ue,isValidChunkSize:()=>R});module.exports=$e(_t);function W(t,e,...n){if(!t)throw new TypeError(oe(e,n))}function oe(t,e){let n=0;return t.replace(/%[os]/gu,()=>ue(e[n++]))}function ue(t){return typeof t!="object"||t===null?String(t):Object.prototype.toString.call(t)}var Z;function Ve(t){try{let e=t instanceof Error?t:new Error(ue(t));if(Z){Z(e);return}if(typeof dispatchEvent=="function"&&typeof ErrorEvent=="function")dispatchEvent(new ErrorEvent("error",{error:e,message:e.message}));else if(typeof process!="undefined"&&typeof process.emit=="function"){process.emit("uncaughtException",e);return}console.error(e)}catch{}}var m=typeof window!="undefined"?window:typeof self!="undefined"?self:typeof global!="undefined"?global:typeof globalThis!="undefined"?globalThis:void 0,J;var b=class{constructor(e,n){this.code=e,this.message=n}warn(...e){var n;try{if(J){J({...this,args:e});return}let r=((n=new Error().stack)!==null&&n!==void 0?n:"").replace(/^(?:.+?\n){2}/gu,`
`);console.warn(this.message,...e,r)}catch{}}},qe=new b("W01","Unable to initialize event under dispatching."),Ge=new b("W02","Assigning any falsy value to 'cancelBubble' property has no effect."),Ye=new b("W03","Assigning any truthy value to 'returnValue' property has no effect."),Ke=new b("W04","Unable to preventDefault on non-cancelable events."),Ze=new b("W05","Unable to preventDefault inside passive event listener invocation."),Je=new b("W06","An event listener wasn't added because it has been added already: %o, %o"),N=new b("W07","The %o option value was abandoned because the event listener wasn't added as duplicated."),Q=new b("W08","The 'callback' argument must be a function or an object that has 'handleEvent' method: %o"),Ot=new b("W09","Event attribute handler must be a function: %o"),g=class{static get NONE(){return ee}static get CAPTURING_PHASE(){return te}static get AT_TARGET(){return ne}static get BUBBLING_PHASE(){return re}constructor(e,n){Object.defineProperty(this,"isTrusted",{value:!1,enumerable:!0});let r=n!=null?n:{};j.set(this,{type:String(e),bubbles:Boolean(r.bubbles),cancelable:Boolean(r.cancelable),composed:Boolean(r.composed),target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1,inPassiveListenerFlag:!1,dispatchFlag:!1,timeStamp:Date.now()})}get type(){return c(this).type}get target(){return c(this).target}get srcElement(){return c(this).target}get currentTarget(){return c(this).currentTarget}composedPath(){let e=c(this).currentTarget;return e?[e]:[]}get NONE(){return ee}get CAPTURING_PHASE(){return te}get AT_TARGET(){return ne}get BUBBLING_PHASE(){return re}get eventPhase(){return c(this).dispatchFlag?2:0}stopPropagation(){c(this).stopPropagationFlag=!0}get cancelBubble(){return c(this).stopPropagationFlag}set cancelBubble(e){e?c(this).stopPropagationFlag=!0:Ge.warn()}stopImmediatePropagation(){let e=c(this);e.stopPropagationFlag=e.stopImmediatePropagationFlag=!0}get bubbles(){return c(this).bubbles}get cancelable(){return c(this).cancelable}get returnValue(){return!c(this).canceledFlag}set returnValue(e){e?Ye.warn():ie(c(this))}preventDefault(){ie(c(this))}get defaultPrevented(){return c(this).canceledFlag}get composed(){return c(this).composed}get isTrusted(){return!1}get timeStamp(){return c(this).timeStamp}initEvent(e,n=!1,r=!1){let i=c(this);if(i.dispatchFlag){qe.warn();return}j.set(this,{...i,type:String(e),bubbles:Boolean(n),cancelable:Boolean(r),target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1})}},ee=0,te=1,ne=2,re=3,j=new WeakMap;function c(t,e="this"){let n=j.get(t);return W(n!=null,"'%s' must be an object that Event constructor created, but got another one: %o",e,t),n}function ie(t){if(t.inPassiveListenerFlag){Ze.warn();return}if(!t.cancelable){Ke.warn();return}t.canceledFlag=!0}Object.defineProperty(g,"NONE",{enumerable:!0});Object.defineProperty(g,"CAPTURING_PHASE",{enumerable:!0});Object.defineProperty(g,"AT_TARGET",{enumerable:!0});Object.defineProperty(g,"BUBBLING_PHASE",{enumerable:!0});var D=Object.getOwnPropertyNames(g.prototype);for(let t=0;t<D.length;++t)D[t]!=="constructor"&&Object.defineProperty(g.prototype,D[t],{enumerable:!0});typeof m!="undefined"&&typeof m.Event!="undefined"&&Object.setPrototypeOf(g.prototype,m.Event.prototype);function Qe(t){return m.DOMException?new m.DOMException(t,"InvalidStateError"):(v==null&&(v=class le extends Error{constructor(n){super(n),Error.captureStackTrace&&Error.captureStackTrace(this,le)}get code(){return 11}get name(){return"InvalidStateError"}},Object.defineProperties(v.prototype,{code:{enumerable:!0},name:{enumerable:!0}}),ae(v),ae(v.prototype)),new v(t))}var v,se={INDEX_SIZE_ERR:1,DOMSTRING_SIZE_ERR:2,HIERARCHY_REQUEST_ERR:3,WRONG_DOCUMENT_ERR:4,INVALID_CHARACTER_ERR:5,NO_DATA_ALLOWED_ERR:6,NO_MODIFICATION_ALLOWED_ERR:7,NOT_FOUND_ERR:8,NOT_SUPPORTED_ERR:9,INUSE_ATTRIBUTE_ERR:10,INVALID_STATE_ERR:11,SYNTAX_ERR:12,INVALID_MODIFICATION_ERR:13,NAMESPACE_ERR:14,INVALID_ACCESS_ERR:15,VALIDATION_ERR:16,TYPE_MISMATCH_ERR:17,SECURITY_ERR:18,NETWORK_ERR:19,ABORT_ERR:20,URL_MISMATCH_ERR:21,QUOTA_EXCEEDED_ERR:22,TIMEOUT_ERR:23,INVALID_NODE_TYPE_ERR:24,DATA_CLONE_ERR:25};function ae(t){let e=Object.keys(se);for(let n=0;n<e.length;++n){let r=e[n],i=se[r];Object.defineProperty(t,r,{get(){return i},configurable:!0,enumerable:!0})}}var w=class extends g{static wrap(e){return new(he(e))(e)}constructor(e){super(e.type,{bubbles:e.bubbles,cancelable:e.cancelable,composed:e.composed}),e.cancelBubble&&super.stopPropagation(),e.defaultPrevented&&super.preventDefault(),ce.set(this,{original:e});let n=Object.keys(e);for(let r=0;r<n.length;++r){let i=n[r];i in this||Object.defineProperty(this,i,de(e,i))}}stopPropagation(){super.stopPropagation();let{original:e}=C(this);"stopPropagation"in e&&e.stopPropagation()}get cancelBubble(){return super.cancelBubble}set cancelBubble(e){super.cancelBubble=e;let{original:n}=C(this);"cancelBubble"in n&&(n.cancelBubble=e)}stopImmediatePropagation(){super.stopImmediatePropagation();let{original:e}=C(this);"stopImmediatePropagation"in e&&e.stopImmediatePropagation()}get returnValue(){return super.returnValue}set returnValue(e){super.returnValue=e;let{original:n}=C(this);"returnValue"in n&&(n.returnValue=e)}preventDefault(){super.preventDefault();let{original:e}=C(this);"preventDefault"in e&&e.preventDefault()}get timeStamp(){let{original:e}=C(this);return"timeStamp"in e?e.timeStamp:super.timeStamp}},ce=new WeakMap;function C(t){let e=ce.get(t);return W(e!=null,"'this' is expected an Event object, but got",t),e}var B=new WeakMap;B.set(Object.prototype,w);typeof m!="undefined"&&typeof m.Event!="undefined"&&B.set(m.Event.prototype,w);function he(t){let e=Object.getPrototypeOf(t);if(e==null)return w;let n=B.get(e);return n==null&&(n=et(he(e),e),B.set(e,n)),n}function et(t,e){class n extends t{}let r=Object.keys(e);for(let i=0;i<r.length;++i)Object.defineProperty(n.prototype,r[i],de(e,r[i]));return n}function de(t,e){let n=Object.getOwnPropertyDescriptor(t,e);return{get(){let r=C(this).original,i=r[e];return typeof i=="function"?i.bind(r):i},set(r){let i=C(this).original;i[e]=r},configurable:n.configurable,enumerable:n.enumerable}}function tt(t,e,n,r,i,a){return{callback:t,flags:(e?1:0)|(n?2:0)|(r?4:0),signal:i,signalListener:a}}function nt(t){t.flags|=8}function fe(t){return(t.flags&1)===1}function pe(t){return(t.flags&2)===2}function me(t){return(t.flags&4)===4}function rt(t){return(t.flags&8)===8}function it({callback:t},e,n){try{typeof t=="function"?t.call(e,n):typeof t.handleEvent=="function"&&t.handleEvent(n)}catch(r){Ve(r)}}function be({listeners:t},e,n){for(let r=0;r<t.length;++r)if(t[r].callback===e&&fe(t[r])===n)return r;return-1}function st(t,e,n,r,i,a){let o;a&&(o=ge.bind(null,t,e,n),a.addEventListener("abort",o));let s=tt(e,n,r,i,a,o);return t.cow?(t.cow=!1,t.listeners=[...t.listeners,s]):t.listeners.push(s),s}function ge(t,e,n){let r=be(t,e,n);return r!==-1?ye(t,r):!1}function ye(t,e,n=!1){let r=t.listeners[e];return nt(r),r.signal&&r.signal.removeEventListener("abort",r.signalListener),t.cow&&!n?(t.cow=!1,t.listeners=t.listeners.filter((i,a)=>a!==e),!1):(t.listeners.splice(e,1),!0)}function at(){return Object.create(null)}function ot(t,e){var n;return(n=t[e])!==null&&n!==void 0?n:t[e]={attrCallback:void 0,attrListener:void 0,cow:!1,listeners:[]}}var E=class{constructor(){ke.set(this,at())}addEventListener(e,n,r){let i=X(this),{callback:a,capture:o,once:s,passive:u,signal:h,type:f}=ut(e,n,r);if(a==null||(h==null?void 0:h.aborted))return;let d=ot(i,f),y=be(d,a,o);if(y!==-1){ct(d.listeners[y],u,s,h);return}st(d,a,o,u,s,h)}removeEventListener(e,n,r){let i=X(this),{callback:a,capture:o,type:s}=lt(e,n,r),u=i[s];a!=null&&u&&ge(u,a,o)}dispatchEvent(e){let n=X(this)[String(e.type)];if(n==null)return!0;let r=e instanceof g?e:w.wrap(e),i=c(r,"event");if(i.dispatchFlag)throw Qe("This event has been in dispatching.");if(i.dispatchFlag=!0,i.target=i.currentTarget=this,!i.stopPropagationFlag){let{cow:a,listeners:o}=n;n.cow=!0;for(let s=0;s<o.length;++s){let u=o[s];if(!rt(u)&&(me(u)&&ye(n,s,!a)&&(s-=1),i.inPassiveListenerFlag=pe(u),it(u,this,r),i.inPassiveListenerFlag=!1,i.stopImmediatePropagationFlag))break}a||(n.cow=!1)}return i.target=null,i.currentTarget=null,i.stopImmediatePropagationFlag=!1,i.stopPropagationFlag=!1,i.dispatchFlag=!1,!i.canceledFlag}},ke=new WeakMap;function X(t,e="this"){let n=ke.get(t);return W(n!=null,"'%s' must be an object that EventTarget constructor created, but got another one: %o",e,t),n}function ut(t,e,n){var r;return Ce(e),typeof n=="object"&&n!==null?{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n.capture),passive:Boolean(n.passive),once:Boolean(n.once),signal:(r=n.signal)!==null&&r!==void 0?r:void 0}:{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n),passive:!1,once:!1,signal:void 0}}function lt(t,e,n){return Ce(e),typeof n=="object"&&n!==null?{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n.capture)}:{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n)}}function Ce(t){if(!(typeof t=="function"||typeof t=="object"&&t!==null&&typeof t.handleEvent=="function")){if(t==null||typeof t=="object"){Q.warn(t);return}throw new TypeError(oe(Q.message,[t]))}}function ct(t,e,n,r){Je.warn(fe(t)?"capture":"bubble",t.callback),pe(t)!==e&&N.warn("passive"),me(t)!==n&&N.warn("once"),t.signal!==r&&N.warn("signal")}var H=Object.getOwnPropertyNames(E.prototype);for(let t=0;t<H.length;++t)H[t]!=="constructor"&&Object.defineProperty(E.prototype,H[t],{enumerable:!0});typeof m!="undefined"&&typeof m.EventTarget!="undefined"&&Object.setPrototypeOf(E.prototype,m.EventTarget.prototype);var Le=We(Ie()),q=30720,O=512e3,A=256,R=(t,{minChunkSize:e=A,maxChunkSize:n=O}={})=>t==null||typeof t=="number"&&t>=256&&t%256===0&&t>=e&&t<=n,z=(t,{minChunkSize:e=A,maxChunkSize:n=O}={})=>new TypeError(`chunkSize ${t} must be a positive number in multiples of 256, between ${e} and ${n}`),x=class{constructor(e,n={}){this.readableStream=e;var r,i,a;if(!R(n.defaultChunkSize,n))throw z(n.defaultChunkSize,n);this.defaultChunkSize=(r=n.defaultChunkSize)!=null?r:q,this.minChunkSize=(i=n.minChunkSize)!=null?i:A,this.maxChunkSize=(a=n.maxChunkSize)!=null?a:O}get chunkSize(){var e;return(e=this._chunkSize)!=null?e:this.defaultChunkSize}set chunkSize(e){if(!R(e,this))throw z(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}get error(){return this._error}async*[Symbol.asyncIterator](){let e,n=this.readableStream.getReader();try{for(;;){let{done:r,value:i}=await n.read();if(r){if(e){let o=e;e=void 0,yield o}break}let a=i instanceof Uint8Array?new Blob([i],{type:"application/octet-stream"}):i;for(e=e?new Blob([e,a]):a;e;)if(e.size===this.chunkByteSize){let o=e;e=void 0,yield o;break}else{if(e.size<this.chunkByteSize)break;{let o=e.slice(0,this.chunkByteSize);e=e.slice(this.chunkByteSize),yield o}}}}catch(r){this._error=r}finally{if(e){let r=e;e=void 0,yield r}n.releaseLock();return}}},U=class{constructor(e,n={}){this.file=e;var r,i,a;if(!R(n.defaultChunkSize,n))throw z(n.defaultChunkSize,n);this.defaultChunkSize=(r=n.defaultChunkSize)!=null?r:q,this.minChunkSize=(i=n.minChunkSize)!=null?i:A,this.maxChunkSize=(a=n.maxChunkSize)!=null?a:O}get chunkSize(){var e;return(e=this._chunkSize)!=null?e:this.defaultChunkSize}set chunkSize(e){if(!R(e,this))throw z(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}get error(){return this._error}async*[Symbol.asyncIterator](){let e=new FileReader,n=0,r=()=>new Promise(i=>{if(n>=this.file.size){i(void 0);return}let a=Math.min(this.chunkByteSize,this.file.size-n);e.onload=()=>{e.result!==null?i(new Blob([e.result],{type:"application/octet-stream"})):i(void 0)},e.readAsArrayBuffer(this.file.slice(n,n+a))});try{for(;;){let i=await r();if(i)n+=i.size,yield i;else break}}catch(i){this._error=i}}},vt=[200,201,202,204,308],Be=[408,502,503,504],wt=[308],xe=(t,e)=>!!t&&vt.includes(t.statusCode),Rt=(t,{retryCodes:e=Be})=>!t||e.includes(t.statusCode),zt=(t,e)=>e.attemptCount>=e.attempts||!(xe(t)||Rt(t,e)),Ue=(t,e)=>{var i;if(!t||!wt.includes(t.statusCode)||!((i=t.headers)!=null&&i.range))return!1;let n=t.headers.range.match(/bytes=(\d+)-(\d+)/);return n?parseInt(n[2],10)!==e.currentChunkEndByte:!1},T=class{static createUpload(e){return new T(e)}constructor(e){if(this.eventTarget=new E,this.endpoint=e.endpoint,this.file=e.file,this.headers=e.headers||{},this.method=e.method||"PUT",this.attempts=e.attempts||5,this.delayBeforeAttempt=e.delayBeforeAttempt||1,this.retryCodes=e.retryCodes||Be,this.dynamicChunkSize=e.dynamicChunkSize||!1,this.maxFileBytes=(e.maxFileSize||0)*1024,this.chunkCount=0,this.attemptCount=0,this._offline=typeof window!="undefined"&&!window.navigator.onLine,this._paused=!1,this.success=!1,this.nextChunkRangeStart=0,e.useLargeFileWorkaround){let n=r=>{this.chunkedIterable.error&&(console.warn(`Unable to read file of size ${this.file.size} bytes via a ReadableStream. Falling back to in-memory FileReader!`),r.stopImmediatePropagation(),this.chunkedIterable=new U(this.file,{...e,defaultChunkSize:e.chunkSize}),this.chunkedIterator=this.chunkedIterable[Symbol.asyncIterator](),this.getEndpoint().then(()=>{this.sendChunks()}),this.off("error",n))};this.on("error",n)}this.chunkedIterable=new x(this.file.stream(),{...e,defaultChunkSize:e.chunkSize}),this.chunkedIterator=this.chunkedIterable[Symbol.asyncIterator](),this.totalChunks=Math.ceil(this.file.size/this.chunkByteSize),this.validateOptions(),this.getEndpoint().then(()=>this.sendChunks()),typeof window!="undefined"&&(window.addEventListener("online",()=>{!this.offline||(this._offline=!1,this.dispatch("online"),this.sendChunks())}),window.addEventListener("offline",()=>{this.offline||(this._offline=!0,this.dispatch("offline"))}))}get maxChunkSize(){var e,n;return(n=(e=this.chunkedIterable)==null?void 0:e.maxChunkSize)!=null?n:O}get minChunkSize(){var e,n;return(n=(e=this.chunkedIterable)==null?void 0:e.minChunkSize)!=null?n:A}get chunkSize(){var e,n;return(n=(e=this.chunkedIterable)==null?void 0:e.chunkSize)!=null?n:q}set chunkSize(e){this.chunkedIterable.chunkSize=e}get chunkByteSize(){return this.chunkedIterable.chunkByteSize}get totalChunkSize(){return Math.ceil(this.file.size/this.chunkByteSize)}on(e,n){this.eventTarget.addEventListener(e,n)}once(e,n){this.eventTarget.addEventListener(e,n,{once:!0})}off(e,n){this.eventTarget.removeEventListener(e,n)}get offline(){return this._offline}get paused(){return this._paused}abort(){var e;this.pause(),(e=this.currentXhr)==null||e.abort()}pause(){this._paused=!0}resume(){this._paused&&(this._paused=!1,this.sendChunks())}get successfulPercentage(){return this.nextChunkRangeStart/this.file.size}dispatch(e,n){let r=new CustomEvent(e,{detail:n});this.eventTarget.dispatchEvent(r)}validateOptions(){if(!this.endpoint||typeof this.endpoint!="function"&&typeof this.endpoint!="string")throw new TypeError("endpoint must be defined as a string or a function that returns a promise");if(!(this.file instanceof File))throw new TypeError("file must be a File object");if(this.headers&&typeof this.headers!="function"&&typeof this.headers!="object")throw new TypeError("headers must be null, an object, or a function that returns an object or a promise");if(!R(this.chunkSize,{maxChunkSize:this.maxChunkSize,minChunkSize:this.minChunkSize}))throw z(this.chunkSize,{maxChunkSize:this.maxChunkSize,minChunkSize:this.minChunkSize});if(this.maxChunkSize&&(typeof this.maxChunkSize!="number"||this.maxChunkSize<256||this.maxChunkSize%256!==0||this.maxChunkSize<this.chunkSize||this.maxChunkSize<this.minChunkSize))throw new TypeError(`maxChunkSize must be a positive number in multiples of 256, and larger than or equal to both ${this.minChunkSize} and ${this.chunkSize}`);if(this.minChunkSize&&(typeof this.minChunkSize!="number"||this.minChunkSize<256||this.minChunkSize%256!==0||this.minChunkSize>this.chunkSize||this.minChunkSize>this.maxChunkSize))throw new TypeError(`minChunkSize must be a positive number in multiples of 256, and smaller than ${this.chunkSize} and ${this.maxChunkSize}`);if(this.maxFileBytes>0&&this.maxFileBytes<this.file.size)throw new Error(`file size exceeds maximum (${this.file.size} > ${this.maxFileBytes})`);if(this.attempts&&(typeof this.attempts!="number"||this.attempts<=0))throw new TypeError("retries must be a positive number");if(this.delayBeforeAttempt&&(typeof this.delayBeforeAttempt!="number"||this.delayBeforeAttempt<0))throw new TypeError("delayBeforeAttempt must be a positive number")}getEndpoint(){return typeof this.endpoint=="string"?(this.endpointValue=this.endpoint,Promise.resolve(this.endpoint)):this.endpoint(this.file).then(e=>(this.endpointValue=e,this.endpointValue))}xhrPromise(e){let n=r=>{r.upload.onprogress=i=>{var h;let a=this.totalChunks-this.chunkCount,o=(this.file.size-this.nextChunkRangeStart)/this.file.size/a,u=i.loaded/((h=i.total)!=null?h:this.chunkByteSize)*o;this.dispatch("progress",Math.min((this.successfulPercentage+u)*100,100))}};return new Promise((r,i)=>{this.currentXhr=(0,Le.default)({...e,beforeSend:n},(a,o)=>(this.currentXhr=void 0,a?i(a):r(o)))})}async sendChunk(e){let n=this.nextChunkRangeStart,r=n+e.size-1,a={...await(typeof this.headers=="function"?this.headers():this.headers),"Content-Type":this.file.type,"Content-Range":`bytes ${n}-${r}/${this.file.size}`};return this.dispatch("attempt",{chunkNumber:this.chunkCount,totalChunks:this.totalChunks,chunkSize:this.chunkSize}),this.xhrPromise({headers:a,url:this.endpointValue,method:this.method,body:e})}async sendChunkWithRetries(e){let n=async(s,u)=>{var d;let f=(new Date().getTime()-this.lastChunkStart.getTime())/1e3;if(this.dispatch("chunkSuccess",{chunk:this.chunkCount,chunkSize:this.chunkSize,attempts:this.attemptCount,timeInterval:f,response:s}),this.attemptCount=0,this.chunkCount=((d=this.chunkCount)!=null?d:0)+1,this.nextChunkRangeStart=this.nextChunkRangeStart+this.chunkByteSize,this.dynamicChunkSize){let y=this.chunkSize;f<10?y=Math.min(this.chunkSize*2,this.maxChunkSize):f>30&&(y=Math.max(this.chunkSize/2,this.minChunkSize)),this.chunkSize=Math.ceil(y/256)*256;let p=(this.file.size-this.nextChunkRangeStart)/this.chunkByteSize;this.totalChunks=Math.ceil(this.chunkCount+p)}return!0},r=async(s,u)=>(this.dispatch("progress",Math.min(this.successfulPercentage*100,100)),this.dispatch("error",{message:`Server responded with ${s.statusCode}. Stopping upload.`,chunk:this.chunkCount,attempts:this.attemptCount,response:s}),!1),i=async(s,u)=>(this.dispatch("attemptFailure",{message:`An error occured uploading chunk ${this.chunkCount}. ${this.attempts-this.attemptCount} retries left.`,chunkNumber:this.chunkCount,attemptsLeft:this.attempts-this.attemptCount,response:s}),new Promise(h=>{setTimeout(async()=>{if(this._paused||this.offline){this.pendingChunk=e,h(!1);return}let f=await this.sendChunkWithRetries(e);h(f)},this.delayBeforeAttempt*1e3)})),a;try{this.attemptCount=this.attemptCount+1,this.lastChunkStart=new Date,a=await this.sendChunk(e)}catch(s){typeof(s==null?void 0:s.statusCode)=="number"&&(a=s)}let o={retryCodes:this.retryCodes,attemptCount:this.attemptCount,attempts:this.attempts,currentChunkEndByte:this.nextChunkRangeStart+e.size-1};return Ue(a,o)?i(a,e):xe(a,o)?n(a,e):zt(a,o)?r(a,e):i(a,e)}async sendChunks(){if(this.pendingChunk&&!(this._paused||this.offline)){let e=this.pendingChunk;this.pendingChunk=void 0;let n=await this.sendChunkWithRetries(e);this.success&&n&&this.dispatch("success")}for(;!(this.success||this._paused||this.offline);){let{value:e,done:n}=await this.chunkedIterator.next(),r=!e&&n;if(e&&(r=await this.sendChunkWithRetries(e)),this.chunkedIterable.error){r=!1,this.dispatch("error",{message:`Unable to read file of size ${this.file.size} bytes. Try loading from another browser.`});return}if(this.success=!!n,this.success&&r&&this.dispatch("success"),!r)return}}};function Tt(t){return T.createUpload(t)}
//# sourceMappingURL=upchunk.cjs.js.map

@@ -16,3 +16,10 @@ import type { XhrHeaders, XhrResponse } from 'xhr';

};
export declare class ChunkedStreamIterable implements AsyncIterable<Blob> {
export interface ChunkedIterable extends AsyncIterable<Blob> {
chunkSize: number;
readonly chunkByteSize: number;
readonly minChunkSize: number;
readonly maxChunkSize: number;
readonly error: Error | undefined;
}
export declare class ChunkedStreamIterable implements ChunkedIterable {
protected readableStream: ReadableStream<Uint8Array | Blob>;

@@ -31,2 +38,16 @@ protected _chunkSize: number | undefined;

}
export declare class ChunkedFileIterable implements ChunkedIterable {
protected file: File;
protected _chunkSize: number | undefined;
protected defaultChunkSize: number;
protected _error: Error | undefined;
readonly minChunkSize: number;
readonly maxChunkSize: number;
constructor(file: File, options?: ChunkedStreamIterableOptions);
get chunkSize(): number;
set chunkSize(value: number);
get chunkByteSize(): number;
get error(): Error | undefined;
[Symbol.asyncIterator](): AsyncIterator<Blob>;
}
/**

@@ -52,2 +73,3 @@ * Checks if an upload chunk was partially received (HTTP 308) and needs a retry.

minChunkSize?: number;
useLargeFileWorkaround?: boolean;
}

@@ -64,4 +86,4 @@ export declare class UpChunk {

dynamicChunkSize: boolean;
protected chunkedStreamIterable: ChunkedStreamIterable;
protected chunkedStreamIterator: AsyncIterator<Blob, any, undefined>;
protected chunkedIterable: ChunkedIterable;
protected chunkedIterator: AsyncIterator<Blob, any, undefined>;
protected pendingChunk?: Blob;

@@ -68,0 +90,0 @@ private chunkCount;

@@ -14,5 +14,5 @@ (function (g, f) {

var module = { exports };
var Ne=Object.create;var P=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Fe=Object.getPrototypeOf,Xe=Object.prototype.hasOwnProperty;var T=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),He=(t,e)=>{for(var n in e)P(t,n,{get:e[n],enumerable:!0})},G=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of De(e))!Xe.call(t,i)&&i!==n&&P(t,i,{get:()=>e[i],enumerable:!(r=Me(e,i))||r.enumerable});return t};var je=(t,e,n)=>(n=t!=null?Ne(Fe(t)):{},G(e||!t||!t.__esModule?P(n,"default",{value:t,enumerable:!0}):n,t)),We=t=>G(P({},"__esModule",{value:!0}),t);var ke=T((At,Ce)=>{var z;typeof window!="undefined"?z=window:typeof global!="undefined"?z=global:typeof self!="undefined"?z=self:z={};Ce.exports=z});var Se=T((Lt,Ee)=>{Ee.exports=ht;var ct=Object.prototype.toString;function ht(t){if(!t)return!1;var e=ct.call(t);return e==="[object Function]"||typeof t=="function"&&e!=="[object RegExp]"||typeof window!="undefined"&&(t===window.setTimeout||t===window.alert||t===window.confirm||t===window.prompt)}});var we=T((It,ve)=>{var W=function(t){return t.replace(/^\s+|\s+$/g,"")},dt=function(t){return Object.prototype.toString.call(t)==="[object Array]"};ve.exports=function(t){if(!t)return{};for(var e={},n=W(t).split(`
`),r=0;r<n.length;r++){var i=n[r],a=i.indexOf(":"),o=W(i.slice(0,a)).toLowerCase(),s=W(i.slice(a+1));typeof e[o]=="undefined"?e[o]=s:dt(e[o])?e[o].push(s):e[o]=[e[o],s]}return e}});var Te=T((Bt,Re)=>{Re.exports=ft;var pt=Object.prototype.hasOwnProperty;function ft(){for(var t={},e=0;e<arguments.length;e++){var n=arguments[e];for(var r in n)pt.call(n,r)&&(t[r]=n[r])}return t}});var Oe=T((xt,$)=>{"use strict";var ze=ke(),mt=Se(),gt=we(),bt=Te();$.exports=C;$.exports.default=C;C.XMLHttpRequest=ze.XMLHttpRequest||Et;C.XDomainRequest="withCredentials"in new C.XMLHttpRequest?C.XMLHttpRequest:ze.XDomainRequest;yt(["get","put","post","patch","head","delete"],function(t){C[t==="delete"?"del":t]=function(e,n,r){return n=_e(e,n,r),n.method=t.toUpperCase(),Pe(n)}});function yt(t,e){for(var n=0;n<t.length;n++)e(t[n])}function Ct(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function _e(t,e,n){var r=t;return mt(e)?(n=e,typeof t=="string"&&(r={uri:t})):r=bt(e,{uri:t}),r.callback=n,r}function C(t,e,n){return e=_e(t,e,n),Pe(e)}function Pe(t){if(typeof t.callback=="undefined")throw new Error("callback argument missing");var e=!1,n=function(E,_,Ue){e||(e=!0,t.callback(E,_,Ue))};function r(){s.readyState===4&&setTimeout(o,0)}function i(){var l=void 0;if(s.response?l=s.response:l=s.responseText||kt(s),V)try{l=JSON.parse(l)}catch{}return l}function a(l){return clearTimeout(N),l instanceof Error||(l=new Error(""+(l||"Unknown XMLHttpRequest Error"))),l.statusCode=0,n(l,q)}function o(){if(!h){var l;clearTimeout(N),t.useXDR&&s.status===void 0?l=200:l=s.status===1223?204:s.status;var E=q,_=null;return l!==0?(E={body:i(),statusCode:l,method:d,headers:{},url:p,rawRequest:s},s.getAllResponseHeaders&&(E.headers=gt(s.getAllResponseHeaders()))):_=new Error("Internal XMLHttpRequest Error"),n(_,E,E.body)}}var s=t.xhr||null;s||(t.cors||t.useXDR?s=new C.XDomainRequest:s=new C.XMLHttpRequest);var u,h,p=s.url=t.uri||t.url,d=s.method=t.method||"GET",y=t.body||t.data,f=s.headers=t.headers||{},U=!!t.sync,V=!1,N,q={body:void 0,headers:{},statusCode:0,method:d,url:p,rawRequest:s};if("json"in t&&t.json!==!1&&(V=!0,f.accept||f.Accept||(f.Accept="application/json"),d!=="GET"&&d!=="HEAD"&&(f["content-type"]||f["Content-Type"]||(f["Content-Type"]="application/json"),y=JSON.stringify(t.json===!0?y:t.json))),s.onreadystatechange=r,s.onload=o,s.onerror=a,s.onprogress=function(){},s.onabort=function(){h=!0},s.ontimeout=a,s.open(d,p,!U,t.username,t.password),U||(s.withCredentials=!!t.withCredentials),!U&&t.timeout>0&&(N=setTimeout(function(){if(!h){h=!0,s.abort("timeout");var l=new Error("XMLHttpRequest timeout");l.code="ETIMEDOUT",a(l)}},t.timeout)),s.setRequestHeader)for(u in f)f.hasOwnProperty(u)&&s.setRequestHeader(u,f[u]);else if(t.headers&&!Ct(t.headers))throw new Error("Headers cannot be set on an XDomainRequest object");return"responseType"in t&&(s.responseType=t.responseType),"beforeSend"in t&&typeof t.beforeSend=="function"&&t.beforeSend(s),s.send(y||null),s}function kt(t){try{if(t.responseType==="document")return t.responseXML;var e=t.responseXML&&t.responseXML.documentElement.nodeName==="parsererror";if(t.responseType===""&&!e)return t.responseXML}catch{}return null}function Et(){}});var zt={};He(zt,{ChunkedStreamIterable:()=>I,UpChunk:()=>R,createUpload:()=>Tt,getChunkSizeError:()=>L,isIncompleteChunkUploadNeedingRetry:()=>xe,isValidChunkSize:()=>A});module.exports=We(zt);function j(t,e,...n){if(!t)throw new TypeError(se(e,n))}function se(t,e){let n=0;return t.replace(/%[os]/gu,()=>ae(e[n++]))}function ae(t){return typeof t!="object"||t===null?String(t):Object.prototype.toString.call(t)}var Y;function $e(t){try{let e=t instanceof Error?t:new Error(ae(t));if(Y){Y(e);return}if(typeof dispatchEvent=="function"&&typeof ErrorEvent=="function")dispatchEvent(new ErrorEvent("error",{error:e,message:e.message}));else if(typeof process!="undefined"&&typeof process.emit=="function"){process.emit("uncaughtException",e);return}console.error(e)}catch{}}var m=typeof window!="undefined"?window:typeof self!="undefined"?self:typeof global!="undefined"?global:typeof globalThis!="undefined"?globalThis:void 0,K;var g=class{constructor(e,n){this.code=e,this.message=n}warn(...e){var n;try{if(K){K({...this,args:e});return}let r=((n=new Error().stack)!==null&&n!==void 0?n:"").replace(/^(?:.+?\n){2}/gu,`
`);console.warn(this.message,...e,r)}catch{}}},Ve=new g("W01","Unable to initialize event under dispatching."),qe=new g("W02","Assigning any falsy value to 'cancelBubble' property has no effect."),Ge=new g("W03","Assigning any truthy value to 'returnValue' property has no effect."),Ye=new g("W04","Unable to preventDefault on non-cancelable events."),Ke=new g("W05","Unable to preventDefault inside passive event listener invocation."),Ze=new g("W06","An event listener wasn't added because it has been added already: %o, %o"),M=new g("W07","The %o option value was abandoned because the event listener wasn't added as duplicated."),Z=new g("W08","The 'callback' argument must be a function or an object that has 'handleEvent' method: %o"),Pt=new g("W09","Event attribute handler must be a function: %o"),b=class{static get NONE(){return J}static get CAPTURING_PHASE(){return Q}static get AT_TARGET(){return ee}static get BUBBLING_PHASE(){return te}constructor(e,n){Object.defineProperty(this,"isTrusted",{value:!1,enumerable:!0});let r=n!=null?n:{};H.set(this,{type:String(e),bubbles:Boolean(r.bubbles),cancelable:Boolean(r.cancelable),composed:Boolean(r.composed),target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1,inPassiveListenerFlag:!1,dispatchFlag:!1,timeStamp:Date.now()})}get type(){return c(this).type}get target(){return c(this).target}get srcElement(){return c(this).target}get currentTarget(){return c(this).currentTarget}composedPath(){let e=c(this).currentTarget;return e?[e]:[]}get NONE(){return J}get CAPTURING_PHASE(){return Q}get AT_TARGET(){return ee}get BUBBLING_PHASE(){return te}get eventPhase(){return c(this).dispatchFlag?2:0}stopPropagation(){c(this).stopPropagationFlag=!0}get cancelBubble(){return c(this).stopPropagationFlag}set cancelBubble(e){e?c(this).stopPropagationFlag=!0:qe.warn()}stopImmediatePropagation(){let e=c(this);e.stopPropagationFlag=e.stopImmediatePropagationFlag=!0}get bubbles(){return c(this).bubbles}get cancelable(){return c(this).cancelable}get returnValue(){return!c(this).canceledFlag}set returnValue(e){e?Ge.warn():ne(c(this))}preventDefault(){ne(c(this))}get defaultPrevented(){return c(this).canceledFlag}get composed(){return c(this).composed}get isTrusted(){return!1}get timeStamp(){return c(this).timeStamp}initEvent(e,n=!1,r=!1){let i=c(this);if(i.dispatchFlag){Ve.warn();return}H.set(this,{...i,type:String(e),bubbles:Boolean(n),cancelable:Boolean(r),target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1})}},J=0,Q=1,ee=2,te=3,H=new WeakMap;function c(t,e="this"){let n=H.get(t);return j(n!=null,"'%s' must be an object that Event constructor created, but got another one: %o",e,t),n}function ne(t){if(t.inPassiveListenerFlag){Ke.warn();return}if(!t.cancelable){Ye.warn();return}t.canceledFlag=!0}Object.defineProperty(b,"NONE",{enumerable:!0});Object.defineProperty(b,"CAPTURING_PHASE",{enumerable:!0});Object.defineProperty(b,"AT_TARGET",{enumerable:!0});Object.defineProperty(b,"BUBBLING_PHASE",{enumerable:!0});var D=Object.getOwnPropertyNames(b.prototype);for(let t=0;t<D.length;++t)D[t]!=="constructor"&&Object.defineProperty(b.prototype,D[t],{enumerable:!0});typeof m!="undefined"&&typeof m.Event!="undefined"&&Object.setPrototypeOf(b.prototype,m.Event.prototype);function Je(t){return m.DOMException?new m.DOMException(t,"InvalidStateError"):(v==null&&(v=class oe extends Error{constructor(n){super(n),Error.captureStackTrace&&Error.captureStackTrace(this,oe)}get code(){return 11}get name(){return"InvalidStateError"}},Object.defineProperties(v.prototype,{code:{enumerable:!0},name:{enumerable:!0}}),ie(v),ie(v.prototype)),new v(t))}var v,re={INDEX_SIZE_ERR:1,DOMSTRING_SIZE_ERR:2,HIERARCHY_REQUEST_ERR:3,WRONG_DOCUMENT_ERR:4,INVALID_CHARACTER_ERR:5,NO_DATA_ALLOWED_ERR:6,NO_MODIFICATION_ALLOWED_ERR:7,NOT_FOUND_ERR:8,NOT_SUPPORTED_ERR:9,INUSE_ATTRIBUTE_ERR:10,INVALID_STATE_ERR:11,SYNTAX_ERR:12,INVALID_MODIFICATION_ERR:13,NAMESPACE_ERR:14,INVALID_ACCESS_ERR:15,VALIDATION_ERR:16,TYPE_MISMATCH_ERR:17,SECURITY_ERR:18,NETWORK_ERR:19,ABORT_ERR:20,URL_MISMATCH_ERR:21,QUOTA_EXCEEDED_ERR:22,TIMEOUT_ERR:23,INVALID_NODE_TYPE_ERR:24,DATA_CLONE_ERR:25};function ie(t){let e=Object.keys(re);for(let n=0;n<e.length;++n){let r=e[n],i=re[r];Object.defineProperty(t,r,{get(){return i},configurable:!0,enumerable:!0})}}var w=class extends b{static wrap(e){return new(le(e))(e)}constructor(e){super(e.type,{bubbles:e.bubbles,cancelable:e.cancelable,composed:e.composed}),e.cancelBubble&&super.stopPropagation(),e.defaultPrevented&&super.preventDefault(),ue.set(this,{original:e});let n=Object.keys(e);for(let r=0;r<n.length;++r){let i=n[r];i in this||Object.defineProperty(this,i,ce(e,i))}}stopPropagation(){super.stopPropagation();let{original:e}=k(this);"stopPropagation"in e&&e.stopPropagation()}get cancelBubble(){return super.cancelBubble}set cancelBubble(e){super.cancelBubble=e;let{original:n}=k(this);"cancelBubble"in n&&(n.cancelBubble=e)}stopImmediatePropagation(){super.stopImmediatePropagation();let{original:e}=k(this);"stopImmediatePropagation"in e&&e.stopImmediatePropagation()}get returnValue(){return super.returnValue}set returnValue(e){super.returnValue=e;let{original:n}=k(this);"returnValue"in n&&(n.returnValue=e)}preventDefault(){super.preventDefault();let{original:e}=k(this);"preventDefault"in e&&e.preventDefault()}get timeStamp(){let{original:e}=k(this);return"timeStamp"in e?e.timeStamp:super.timeStamp}},ue=new WeakMap;function k(t){let e=ue.get(t);return j(e!=null,"'this' is expected an Event object, but got",t),e}var O=new WeakMap;O.set(Object.prototype,w);typeof m!="undefined"&&typeof m.Event!="undefined"&&O.set(m.Event.prototype,w);function le(t){let e=Object.getPrototypeOf(t);if(e==null)return w;let n=O.get(e);return n==null&&(n=Qe(le(e),e),O.set(e,n)),n}function Qe(t,e){class n extends t{}let r=Object.keys(e);for(let i=0;i<r.length;++i)Object.defineProperty(n.prototype,r[i],ce(e,r[i]));return n}function ce(t,e){let n=Object.getOwnPropertyDescriptor(t,e);return{get(){let r=k(this).original,i=r[e];return typeof i=="function"?i.bind(r):i},set(r){let i=k(this).original;i[e]=r},configurable:n.configurable,enumerable:n.enumerable}}function et(t,e,n,r,i,a){return{callback:t,flags:(e?1:0)|(n?2:0)|(r?4:0),signal:i,signalListener:a}}function tt(t){t.flags|=8}function he(t){return(t.flags&1)===1}function de(t){return(t.flags&2)===2}function pe(t){return(t.flags&4)===4}function nt(t){return(t.flags&8)===8}function rt({callback:t},e,n){try{typeof t=="function"?t.call(e,n):typeof t.handleEvent=="function"&&t.handleEvent(n)}catch(r){$e(r)}}function fe({listeners:t},e,n){for(let r=0;r<t.length;++r)if(t[r].callback===e&&he(t[r])===n)return r;return-1}function it(t,e,n,r,i,a){let o;a&&(o=me.bind(null,t,e,n),a.addEventListener("abort",o));let s=et(e,n,r,i,a,o);return t.cow?(t.cow=!1,t.listeners=[...t.listeners,s]):t.listeners.push(s),s}function me(t,e,n){let r=fe(t,e,n);return r!==-1?ge(t,r):!1}function ge(t,e,n=!1){let r=t.listeners[e];return tt(r),r.signal&&r.signal.removeEventListener("abort",r.signalListener),t.cow&&!n?(t.cow=!1,t.listeners=t.listeners.filter((i,a)=>a!==e),!1):(t.listeners.splice(e,1),!0)}function st(){return Object.create(null)}function at(t,e){var n;return(n=t[e])!==null&&n!==void 0?n:t[e]={attrCallback:void 0,attrListener:void 0,cow:!1,listeners:[]}}var S=class{constructor(){be.set(this,st())}addEventListener(e,n,r){let i=F(this),{callback:a,capture:o,once:s,passive:u,signal:h,type:p}=ot(e,n,r);if(a==null||(h==null?void 0:h.aborted))return;let d=at(i,p),y=fe(d,a,o);if(y!==-1){lt(d.listeners[y],u,s,h);return}it(d,a,o,u,s,h)}removeEventListener(e,n,r){let i=F(this),{callback:a,capture:o,type:s}=ut(e,n,r),u=i[s];a!=null&&u&&me(u,a,o)}dispatchEvent(e){let n=F(this)[String(e.type)];if(n==null)return!0;let r=e instanceof b?e:w.wrap(e),i=c(r,"event");if(i.dispatchFlag)throw Je("This event has been in dispatching.");if(i.dispatchFlag=!0,i.target=i.currentTarget=this,!i.stopPropagationFlag){let{cow:a,listeners:o}=n;n.cow=!0;for(let s=0;s<o.length;++s){let u=o[s];if(!nt(u)&&(pe(u)&&ge(n,s,!a)&&(s-=1),i.inPassiveListenerFlag=de(u),rt(u,this,r),i.inPassiveListenerFlag=!1,i.stopImmediatePropagationFlag))break}a||(n.cow=!1)}return i.target=null,i.currentTarget=null,i.stopImmediatePropagationFlag=!1,i.stopPropagationFlag=!1,i.dispatchFlag=!1,!i.canceledFlag}},be=new WeakMap;function F(t,e="this"){let n=be.get(t);return j(n!=null,"'%s' must be an object that EventTarget constructor created, but got another one: %o",e,t),n}function ot(t,e,n){var r;return ye(e),typeof n=="object"&&n!==null?{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n.capture),passive:Boolean(n.passive),once:Boolean(n.once),signal:(r=n.signal)!==null&&r!==void 0?r:void 0}:{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n),passive:!1,once:!1,signal:void 0}}function ut(t,e,n){return ye(e),typeof n=="object"&&n!==null?{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n.capture)}:{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n)}}function ye(t){if(!(typeof t=="function"||typeof t=="object"&&t!==null&&typeof t.handleEvent=="function")){if(t==null||typeof t=="object"){Z.warn(t);return}throw new TypeError(se(Z.message,[t]))}}function lt(t,e,n,r){Ze.warn(he(t)?"capture":"bubble",t.callback),de(t)!==e&&M.warn("passive"),pe(t)!==n&&M.warn("once"),t.signal!==r&&M.warn("signal")}var X=Object.getOwnPropertyNames(S.prototype);for(let t=0;t<X.length;++t)X[t]!=="constructor"&&Object.defineProperty(S.prototype,X[t],{enumerable:!0});typeof m!="undefined"&&typeof m.EventTarget!="undefined"&&Object.setPrototypeOf(S.prototype,m.EventTarget.prototype);var Ae=je(Oe()),Le=30720,B=512e3,x=256,A=(t,{minChunkSize:e=x,maxChunkSize:n=B}={})=>t==null||typeof t=="number"&&t>=256&&t%256===0&&t>=e&&t<=n,L=(t,{minChunkSize:e=x,maxChunkSize:n=B}={})=>new TypeError(`chunkSize ${t} must be a positive number in multiples of 256, between ${e} and ${n}`),I=class{constructor(e,n={}){this.readableStream=e;var r,i,a;if(!A(n.defaultChunkSize,n))throw L(n.defaultChunkSize,n);this.defaultChunkSize=(r=n.defaultChunkSize)!=null?r:Le,this.minChunkSize=(i=n.minChunkSize)!=null?i:x,this.maxChunkSize=(a=n.maxChunkSize)!=null?a:B}get chunkSize(){var e;return(e=this._chunkSize)!=null?e:this.defaultChunkSize}set chunkSize(e){if(!A(e,this))throw L(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}get error(){return this._error}async*[Symbol.asyncIterator](){let e,n=this.readableStream.getReader();try{for(;;){let{done:r,value:i}=await n.read();if(r){if(e){let o=e;e=void 0,yield o}break}let a=i instanceof Uint8Array?new Blob([i],{type:"application/octet-stream"}):i;for(e=e?new Blob([e,a]):a;e;)if(e.size===this.chunkByteSize){let o=e;e=void 0,yield o;break}else{if(e.size<this.chunkByteSize)break;{let o=e.slice(0,this.chunkByteSize);e=e.slice(this.chunkByteSize),yield o}}}}catch(r){this._error=r}finally{if(e){let r=e;e=void 0,yield r}n.releaseLock();return}}},St=[200,201,202,204,308],Ie=[408,502,503,504],vt=[308],Be=(t,e)=>!!t&&St.includes(t.statusCode),wt=(t,{retryCodes:e=Ie})=>!t||e.includes(t.statusCode),Rt=(t,e)=>e.attemptCount>=e.attempts||!(Be(t)||wt(t,e)),xe=(t,e)=>{var i;if(!t||!vt.includes(t.statusCode)||!((i=t.headers)!=null&&i.range))return!1;let n=t.headers.range.match(/bytes=(\d+)-(\d+)/);return n?parseInt(n[2],10)!==e.currentChunkEndByte:!1},R=class{static createUpload(e){return new R(e)}constructor(e){this.endpoint=e.endpoint,this.file=e.file,this.headers=e.headers||{},this.method=e.method||"PUT",this.attempts=e.attempts||5,this.delayBeforeAttempt=e.delayBeforeAttempt||1,this.retryCodes=e.retryCodes||Ie,this.dynamicChunkSize=e.dynamicChunkSize||!1,this.maxFileBytes=(e.maxFileSize||0)*1024,this.chunkCount=0,this.attemptCount=0,this._offline=typeof window!="undefined"&&!window.navigator.onLine,this._paused=!1,this.success=!1,this.nextChunkRangeStart=0,this.chunkedStreamIterable=new I(this.file.stream(),{...e,defaultChunkSize:e.chunkSize}),this.chunkedStreamIterator=this.chunkedStreamIterable[Symbol.asyncIterator](),this.totalChunks=Math.ceil(this.file.size/this.chunkByteSize),this.eventTarget=new S,this.validateOptions(),this.getEndpoint().then(()=>this.sendChunks()),typeof window!="undefined"&&(window.addEventListener("online",()=>{!this.offline||(this._offline=!1,this.dispatch("online"),this.sendChunks())}),window.addEventListener("offline",()=>{this.offline||(this._offline=!0,this.dispatch("offline"))}))}get maxChunkSize(){var e,n;return(n=(e=this.chunkedStreamIterable)==null?void 0:e.maxChunkSize)!=null?n:B}get minChunkSize(){var e,n;return(n=(e=this.chunkedStreamIterable)==null?void 0:e.minChunkSize)!=null?n:x}get chunkSize(){var e,n;return(n=(e=this.chunkedStreamIterable)==null?void 0:e.chunkSize)!=null?n:Le}set chunkSize(e){this.chunkedStreamIterable.chunkSize=e}get chunkByteSize(){return this.chunkedStreamIterable.chunkByteSize}get totalChunkSize(){return Math.ceil(this.file.size/this.chunkByteSize)}on(e,n){this.eventTarget.addEventListener(e,n)}once(e,n){this.eventTarget.addEventListener(e,n,{once:!0})}off(e,n){this.eventTarget.removeEventListener(e,n)}get offline(){return this._offline}get paused(){return this._paused}abort(){var e;this.pause(),(e=this.currentXhr)==null||e.abort()}pause(){this._paused=!0}resume(){this._paused&&(this._paused=!1,this.sendChunks())}get successfulPercentage(){return this.nextChunkRangeStart/this.file.size}dispatch(e,n){let r=new CustomEvent(e,{detail:n});this.eventTarget.dispatchEvent(r)}validateOptions(){if(!this.endpoint||typeof this.endpoint!="function"&&typeof this.endpoint!="string")throw new TypeError("endpoint must be defined as a string or a function that returns a promise");if(!(this.file instanceof File))throw new TypeError("file must be a File object");if(this.headers&&typeof this.headers!="function"&&typeof this.headers!="object")throw new TypeError("headers must be null, an object, or a function that returns an object or a promise");if(!A(this.chunkSize,{maxChunkSize:this.maxChunkSize,minChunkSize:this.minChunkSize}))throw L(this.chunkSize,{maxChunkSize:this.maxChunkSize,minChunkSize:this.minChunkSize});if(this.maxChunkSize&&(typeof this.maxChunkSize!="number"||this.maxChunkSize<256||this.maxChunkSize%256!==0||this.maxChunkSize<this.chunkSize||this.maxChunkSize<this.minChunkSize))throw new TypeError(`maxChunkSize must be a positive number in multiples of 256, and larger than or equal to both ${this.minChunkSize} and ${this.chunkSize}`);if(this.minChunkSize&&(typeof this.minChunkSize!="number"||this.minChunkSize<256||this.minChunkSize%256!==0||this.minChunkSize>this.chunkSize||this.minChunkSize>this.maxChunkSize))throw new TypeError(`minChunkSize must be a positive number in multiples of 256, and smaller than ${this.chunkSize} and ${this.maxChunkSize}`);if(this.maxFileBytes>0&&this.maxFileBytes<this.file.size)throw new Error(`file size exceeds maximum (${this.file.size} > ${this.maxFileBytes})`);if(this.attempts&&(typeof this.attempts!="number"||this.attempts<=0))throw new TypeError("retries must be a positive number");if(this.delayBeforeAttempt&&(typeof this.delayBeforeAttempt!="number"||this.delayBeforeAttempt<0))throw new TypeError("delayBeforeAttempt must be a positive number")}getEndpoint(){return typeof this.endpoint=="string"?(this.endpointValue=this.endpoint,Promise.resolve(this.endpoint)):this.endpoint(this.file).then(e=>(this.endpointValue=e,this.endpointValue))}xhrPromise(e){let n=r=>{r.upload.onprogress=i=>{var h;let a=this.totalChunks-this.chunkCount,o=(this.file.size-this.nextChunkRangeStart)/this.file.size/a,u=i.loaded/((h=i.total)!=null?h:this.chunkByteSize)*o;this.dispatch("progress",Math.min((this.successfulPercentage+u)*100,100))}};return new Promise((r,i)=>{this.currentXhr=(0,Ae.default)({...e,beforeSend:n},(a,o)=>(this.currentXhr=void 0,a?i(a):r(o)))})}async sendChunk(e){let n=this.nextChunkRangeStart,r=n+e.size-1,a={...await(typeof this.headers=="function"?this.headers():this.headers),"Content-Type":this.file.type,"Content-Range":`bytes ${n}-${r}/${this.file.size}`};return this.dispatch("attempt",{chunkNumber:this.chunkCount,totalChunks:this.totalChunks,chunkSize:this.chunkSize}),this.xhrPromise({headers:a,url:this.endpointValue,method:this.method,body:e})}async sendChunkWithRetries(e){let n=async(s,u)=>{var d;let p=(new Date().getTime()-this.lastChunkStart.getTime())/1e3;if(this.dispatch("chunkSuccess",{chunk:this.chunkCount,chunkSize:this.chunkSize,attempts:this.attemptCount,timeInterval:p,response:s}),this.attemptCount=0,this.chunkCount=((d=this.chunkCount)!=null?d:0)+1,this.nextChunkRangeStart=this.nextChunkRangeStart+this.chunkByteSize,this.dynamicChunkSize){let y=this.chunkSize;p<10?y=Math.min(this.chunkSize*2,this.maxChunkSize):p>30&&(y=Math.max(this.chunkSize/2,this.minChunkSize)),this.chunkSize=Math.ceil(y/256)*256;let f=(this.file.size-this.nextChunkRangeStart)/this.chunkByteSize;this.totalChunks=Math.ceil(this.chunkCount+f)}return!0},r=async(s,u)=>(this.dispatch("progress",Math.min(this.successfulPercentage*100,100)),this.dispatch("error",{message:`Server responded with ${s.statusCode}. Stopping upload.`,chunk:this.chunkCount,attempts:this.attemptCount,response:s}),!1),i=async(s,u)=>(this.dispatch("attemptFailure",{message:`An error occured uploading chunk ${this.chunkCount}. ${this.attempts-this.attemptCount} retries left.`,chunkNumber:this.chunkCount,attemptsLeft:this.attempts-this.attemptCount,response:s}),new Promise(h=>{setTimeout(async()=>{if(this._paused||this.offline){this.pendingChunk=e,h(!1);return}let p=await this.sendChunkWithRetries(e);h(p)},this.delayBeforeAttempt*1e3)})),a;try{this.attemptCount=this.attemptCount+1,this.lastChunkStart=new Date,a=await this.sendChunk(e)}catch(s){typeof(s==null?void 0:s.statusCode)=="number"&&(a=s)}let o={retryCodes:this.retryCodes,attemptCount:this.attemptCount,attempts:this.attempts,currentChunkEndByte:this.nextChunkRangeStart+e.size-1};return xe(a,o)?i(a,e):Be(a,o)?n(a,e):Rt(a,o)?r(a,e):i(a,e)}async sendChunks(){if(this.pendingChunk&&!(this._paused||this.offline)){let e=this.pendingChunk;this.pendingChunk=void 0;let n=await this.sendChunkWithRetries(e);this.success&&n&&this.dispatch("success")}for(;!(this.success||this._paused||this.offline);){let{value:e,done:n}=await this.chunkedStreamIterator.next(),r=!e&&n;if(e&&(r=await this.sendChunkWithRetries(e)),this.chunkedStreamIterable.error&&(this.dispatch("error",{message:`Unable to read file of size ${this.file.size} bytes. Try loading from another browser.`}),r=!1),this.success=!!n,this.success&&r&&this.dispatch("success"),!r)return}}};function Tt(t){return R.createUpload(t)}
var Me=Object.create;var L=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Xe=Object.getPrototypeOf,He=Object.prototype.hasOwnProperty;var _=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),je=(t,e)=>{for(var n in e)L(t,n,{get:e[n],enumerable:!0})},K=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of De(e))!He.call(t,i)&&i!==n&&L(t,i,{get:()=>e[i],enumerable:!(r=Ne(e,i))||r.enumerable});return t};var We=(t,e,n)=>(n=t!=null?Me(Xe(t)):{},K(e||!t||!t.__esModule?L(n,"default",{value:t,enumerable:!0}):n,t)),$e=t=>K(L({},"__esModule",{value:!0}),t);var Ee=_((It,Se)=>{var P;typeof window!="undefined"?P=window:typeof global!="undefined"?P=global:typeof self!="undefined"?P=self:P={};Se.exports=P});var we=_((Lt,ve)=>{ve.exports=dt;var ht=Object.prototype.toString;function dt(t){if(!t)return!1;var e=ht.call(t);return e==="[object Function]"||typeof t=="function"&&e!=="[object RegExp]"||typeof window!="undefined"&&(t===window.setTimeout||t===window.alert||t===window.confirm||t===window.prompt)}});var ze=_((Bt,Re)=>{var $=function(t){return t.replace(/^\s+|\s+$/g,"")},ft=function(t){return Object.prototype.toString.call(t)==="[object Array]"};Re.exports=function(t){if(!t)return{};for(var e={},n=$(t).split(`
`),r=0;r<n.length;r++){var i=n[r],a=i.indexOf(":"),o=$(i.slice(0,a)).toLowerCase(),s=$(i.slice(a+1));typeof e[o]=="undefined"?e[o]=s:ft(e[o])?e[o].push(s):e[o]=[e[o],s]}return e}});var _e=_((xt,Te)=>{Te.exports=mt;var pt=Object.prototype.hasOwnProperty;function mt(){for(var t={},e=0;e<arguments.length;e++){var n=arguments[e];for(var r in n)pt.call(n,r)&&(t[r]=n[r])}return t}});var Ie=_((Ut,V)=>{"use strict";var Pe=Ee(),bt=we(),gt=ze(),yt=_e();V.exports=k;V.exports.default=k;k.XMLHttpRequest=Pe.XMLHttpRequest||Et;k.XDomainRequest="withCredentials"in new k.XMLHttpRequest?k.XMLHttpRequest:Pe.XDomainRequest;kt(["get","put","post","patch","head","delete"],function(t){k[t==="delete"?"del":t]=function(e,n,r){return n=Oe(e,n,r),n.method=t.toUpperCase(),Ae(n)}});function kt(t,e){for(var n=0;n<t.length;n++)e(t[n])}function Ct(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function Oe(t,e,n){var r=t;return bt(e)?(n=e,typeof t=="string"&&(r={uri:t})):r=yt(e,{uri:t}),r.callback=n,r}function k(t,e,n){return e=Oe(t,e,n),Ae(e)}function Ae(t){if(typeof t.callback=="undefined")throw new Error("callback argument missing");var e=!1,n=function(S,I,Fe){e||(e=!0,t.callback(S,I,Fe))};function r(){s.readyState===4&&setTimeout(o,0)}function i(){var l=void 0;if(s.response?l=s.response:l=s.responseText||St(s),G)try{l=JSON.parse(l)}catch{}return l}function a(l){return clearTimeout(M),l instanceof Error||(l=new Error(""+(l||"Unknown XMLHttpRequest Error"))),l.statusCode=0,n(l,Y)}function o(){if(!h){var l;clearTimeout(M),t.useXDR&&s.status===void 0?l=200:l=s.status===1223?204:s.status;var S=Y,I=null;return l!==0?(S={body:i(),statusCode:l,method:d,headers:{},url:f,rawRequest:s},s.getAllResponseHeaders&&(S.headers=gt(s.getAllResponseHeaders()))):I=new Error("Internal XMLHttpRequest Error"),n(I,S,S.body)}}var s=t.xhr||null;s||(t.cors||t.useXDR?s=new k.XDomainRequest:s=new k.XMLHttpRequest);var u,h,f=s.url=t.uri||t.url,d=s.method=t.method||"GET",y=t.body||t.data,p=s.headers=t.headers||{},F=!!t.sync,G=!1,M,Y={body:void 0,headers:{},statusCode:0,method:d,url:f,rawRequest:s};if("json"in t&&t.json!==!1&&(G=!0,p.accept||p.Accept||(p.Accept="application/json"),d!=="GET"&&d!=="HEAD"&&(p["content-type"]||p["Content-Type"]||(p["Content-Type"]="application/json"),y=JSON.stringify(t.json===!0?y:t.json))),s.onreadystatechange=r,s.onload=o,s.onerror=a,s.onprogress=function(){},s.onabort=function(){h=!0},s.ontimeout=a,s.open(d,f,!F,t.username,t.password),F||(s.withCredentials=!!t.withCredentials),!F&&t.timeout>0&&(M=setTimeout(function(){if(!h){h=!0,s.abort("timeout");var l=new Error("XMLHttpRequest timeout");l.code="ETIMEDOUT",a(l)}},t.timeout)),s.setRequestHeader)for(u in p)p.hasOwnProperty(u)&&s.setRequestHeader(u,p[u]);else if(t.headers&&!Ct(t.headers))throw new Error("Headers cannot be set on an XDomainRequest object");return"responseType"in t&&(s.responseType=t.responseType),"beforeSend"in t&&typeof t.beforeSend=="function"&&t.beforeSend(s),s.send(y||null),s}function St(t){try{if(t.responseType==="document")return t.responseXML;var e=t.responseXML&&t.responseXML.documentElement.nodeName==="parsererror";if(t.responseType===""&&!e)return t.responseXML}catch{}return null}function Et(){}});var _t={};je(_t,{ChunkedFileIterable:()=>U,ChunkedStreamIterable:()=>x,UpChunk:()=>T,createUpload:()=>Tt,getChunkSizeError:()=>z,isIncompleteChunkUploadNeedingRetry:()=>Ue,isValidChunkSize:()=>R});module.exports=$e(_t);function W(t,e,...n){if(!t)throw new TypeError(oe(e,n))}function oe(t,e){let n=0;return t.replace(/%[os]/gu,()=>ue(e[n++]))}function ue(t){return typeof t!="object"||t===null?String(t):Object.prototype.toString.call(t)}var Z;function Ve(t){try{let e=t instanceof Error?t:new Error(ue(t));if(Z){Z(e);return}if(typeof dispatchEvent=="function"&&typeof ErrorEvent=="function")dispatchEvent(new ErrorEvent("error",{error:e,message:e.message}));else if(typeof process!="undefined"&&typeof process.emit=="function"){process.emit("uncaughtException",e);return}console.error(e)}catch{}}var m=typeof window!="undefined"?window:typeof self!="undefined"?self:typeof global!="undefined"?global:typeof globalThis!="undefined"?globalThis:void 0,J;var b=class{constructor(e,n){this.code=e,this.message=n}warn(...e){var n;try{if(J){J({...this,args:e});return}let r=((n=new Error().stack)!==null&&n!==void 0?n:"").replace(/^(?:.+?\n){2}/gu,`
`);console.warn(this.message,...e,r)}catch{}}},qe=new b("W01","Unable to initialize event under dispatching."),Ge=new b("W02","Assigning any falsy value to 'cancelBubble' property has no effect."),Ye=new b("W03","Assigning any truthy value to 'returnValue' property has no effect."),Ke=new b("W04","Unable to preventDefault on non-cancelable events."),Ze=new b("W05","Unable to preventDefault inside passive event listener invocation."),Je=new b("W06","An event listener wasn't added because it has been added already: %o, %o"),N=new b("W07","The %o option value was abandoned because the event listener wasn't added as duplicated."),Q=new b("W08","The 'callback' argument must be a function or an object that has 'handleEvent' method: %o"),Ot=new b("W09","Event attribute handler must be a function: %o"),g=class{static get NONE(){return ee}static get CAPTURING_PHASE(){return te}static get AT_TARGET(){return ne}static get BUBBLING_PHASE(){return re}constructor(e,n){Object.defineProperty(this,"isTrusted",{value:!1,enumerable:!0});let r=n!=null?n:{};j.set(this,{type:String(e),bubbles:Boolean(r.bubbles),cancelable:Boolean(r.cancelable),composed:Boolean(r.composed),target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1,inPassiveListenerFlag:!1,dispatchFlag:!1,timeStamp:Date.now()})}get type(){return c(this).type}get target(){return c(this).target}get srcElement(){return c(this).target}get currentTarget(){return c(this).currentTarget}composedPath(){let e=c(this).currentTarget;return e?[e]:[]}get NONE(){return ee}get CAPTURING_PHASE(){return te}get AT_TARGET(){return ne}get BUBBLING_PHASE(){return re}get eventPhase(){return c(this).dispatchFlag?2:0}stopPropagation(){c(this).stopPropagationFlag=!0}get cancelBubble(){return c(this).stopPropagationFlag}set cancelBubble(e){e?c(this).stopPropagationFlag=!0:Ge.warn()}stopImmediatePropagation(){let e=c(this);e.stopPropagationFlag=e.stopImmediatePropagationFlag=!0}get bubbles(){return c(this).bubbles}get cancelable(){return c(this).cancelable}get returnValue(){return!c(this).canceledFlag}set returnValue(e){e?Ye.warn():ie(c(this))}preventDefault(){ie(c(this))}get defaultPrevented(){return c(this).canceledFlag}get composed(){return c(this).composed}get isTrusted(){return!1}get timeStamp(){return c(this).timeStamp}initEvent(e,n=!1,r=!1){let i=c(this);if(i.dispatchFlag){qe.warn();return}j.set(this,{...i,type:String(e),bubbles:Boolean(n),cancelable:Boolean(r),target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1})}},ee=0,te=1,ne=2,re=3,j=new WeakMap;function c(t,e="this"){let n=j.get(t);return W(n!=null,"'%s' must be an object that Event constructor created, but got another one: %o",e,t),n}function ie(t){if(t.inPassiveListenerFlag){Ze.warn();return}if(!t.cancelable){Ke.warn();return}t.canceledFlag=!0}Object.defineProperty(g,"NONE",{enumerable:!0});Object.defineProperty(g,"CAPTURING_PHASE",{enumerable:!0});Object.defineProperty(g,"AT_TARGET",{enumerable:!0});Object.defineProperty(g,"BUBBLING_PHASE",{enumerable:!0});var D=Object.getOwnPropertyNames(g.prototype);for(let t=0;t<D.length;++t)D[t]!=="constructor"&&Object.defineProperty(g.prototype,D[t],{enumerable:!0});typeof m!="undefined"&&typeof m.Event!="undefined"&&Object.setPrototypeOf(g.prototype,m.Event.prototype);function Qe(t){return m.DOMException?new m.DOMException(t,"InvalidStateError"):(v==null&&(v=class le extends Error{constructor(n){super(n),Error.captureStackTrace&&Error.captureStackTrace(this,le)}get code(){return 11}get name(){return"InvalidStateError"}},Object.defineProperties(v.prototype,{code:{enumerable:!0},name:{enumerable:!0}}),ae(v),ae(v.prototype)),new v(t))}var v,se={INDEX_SIZE_ERR:1,DOMSTRING_SIZE_ERR:2,HIERARCHY_REQUEST_ERR:3,WRONG_DOCUMENT_ERR:4,INVALID_CHARACTER_ERR:5,NO_DATA_ALLOWED_ERR:6,NO_MODIFICATION_ALLOWED_ERR:7,NOT_FOUND_ERR:8,NOT_SUPPORTED_ERR:9,INUSE_ATTRIBUTE_ERR:10,INVALID_STATE_ERR:11,SYNTAX_ERR:12,INVALID_MODIFICATION_ERR:13,NAMESPACE_ERR:14,INVALID_ACCESS_ERR:15,VALIDATION_ERR:16,TYPE_MISMATCH_ERR:17,SECURITY_ERR:18,NETWORK_ERR:19,ABORT_ERR:20,URL_MISMATCH_ERR:21,QUOTA_EXCEEDED_ERR:22,TIMEOUT_ERR:23,INVALID_NODE_TYPE_ERR:24,DATA_CLONE_ERR:25};function ae(t){let e=Object.keys(se);for(let n=0;n<e.length;++n){let r=e[n],i=se[r];Object.defineProperty(t,r,{get(){return i},configurable:!0,enumerable:!0})}}var w=class extends g{static wrap(e){return new(he(e))(e)}constructor(e){super(e.type,{bubbles:e.bubbles,cancelable:e.cancelable,composed:e.composed}),e.cancelBubble&&super.stopPropagation(),e.defaultPrevented&&super.preventDefault(),ce.set(this,{original:e});let n=Object.keys(e);for(let r=0;r<n.length;++r){let i=n[r];i in this||Object.defineProperty(this,i,de(e,i))}}stopPropagation(){super.stopPropagation();let{original:e}=C(this);"stopPropagation"in e&&e.stopPropagation()}get cancelBubble(){return super.cancelBubble}set cancelBubble(e){super.cancelBubble=e;let{original:n}=C(this);"cancelBubble"in n&&(n.cancelBubble=e)}stopImmediatePropagation(){super.stopImmediatePropagation();let{original:e}=C(this);"stopImmediatePropagation"in e&&e.stopImmediatePropagation()}get returnValue(){return super.returnValue}set returnValue(e){super.returnValue=e;let{original:n}=C(this);"returnValue"in n&&(n.returnValue=e)}preventDefault(){super.preventDefault();let{original:e}=C(this);"preventDefault"in e&&e.preventDefault()}get timeStamp(){let{original:e}=C(this);return"timeStamp"in e?e.timeStamp:super.timeStamp}},ce=new WeakMap;function C(t){let e=ce.get(t);return W(e!=null,"'this' is expected an Event object, but got",t),e}var B=new WeakMap;B.set(Object.prototype,w);typeof m!="undefined"&&typeof m.Event!="undefined"&&B.set(m.Event.prototype,w);function he(t){let e=Object.getPrototypeOf(t);if(e==null)return w;let n=B.get(e);return n==null&&(n=et(he(e),e),B.set(e,n)),n}function et(t,e){class n extends t{}let r=Object.keys(e);for(let i=0;i<r.length;++i)Object.defineProperty(n.prototype,r[i],de(e,r[i]));return n}function de(t,e){let n=Object.getOwnPropertyDescriptor(t,e);return{get(){let r=C(this).original,i=r[e];return typeof i=="function"?i.bind(r):i},set(r){let i=C(this).original;i[e]=r},configurable:n.configurable,enumerable:n.enumerable}}function tt(t,e,n,r,i,a){return{callback:t,flags:(e?1:0)|(n?2:0)|(r?4:0),signal:i,signalListener:a}}function nt(t){t.flags|=8}function fe(t){return(t.flags&1)===1}function pe(t){return(t.flags&2)===2}function me(t){return(t.flags&4)===4}function rt(t){return(t.flags&8)===8}function it({callback:t},e,n){try{typeof t=="function"?t.call(e,n):typeof t.handleEvent=="function"&&t.handleEvent(n)}catch(r){Ve(r)}}function be({listeners:t},e,n){for(let r=0;r<t.length;++r)if(t[r].callback===e&&fe(t[r])===n)return r;return-1}function st(t,e,n,r,i,a){let o;a&&(o=ge.bind(null,t,e,n),a.addEventListener("abort",o));let s=tt(e,n,r,i,a,o);return t.cow?(t.cow=!1,t.listeners=[...t.listeners,s]):t.listeners.push(s),s}function ge(t,e,n){let r=be(t,e,n);return r!==-1?ye(t,r):!1}function ye(t,e,n=!1){let r=t.listeners[e];return nt(r),r.signal&&r.signal.removeEventListener("abort",r.signalListener),t.cow&&!n?(t.cow=!1,t.listeners=t.listeners.filter((i,a)=>a!==e),!1):(t.listeners.splice(e,1),!0)}function at(){return Object.create(null)}function ot(t,e){var n;return(n=t[e])!==null&&n!==void 0?n:t[e]={attrCallback:void 0,attrListener:void 0,cow:!1,listeners:[]}}var E=class{constructor(){ke.set(this,at())}addEventListener(e,n,r){let i=X(this),{callback:a,capture:o,once:s,passive:u,signal:h,type:f}=ut(e,n,r);if(a==null||(h==null?void 0:h.aborted))return;let d=ot(i,f),y=be(d,a,o);if(y!==-1){ct(d.listeners[y],u,s,h);return}st(d,a,o,u,s,h)}removeEventListener(e,n,r){let i=X(this),{callback:a,capture:o,type:s}=lt(e,n,r),u=i[s];a!=null&&u&&ge(u,a,o)}dispatchEvent(e){let n=X(this)[String(e.type)];if(n==null)return!0;let r=e instanceof g?e:w.wrap(e),i=c(r,"event");if(i.dispatchFlag)throw Qe("This event has been in dispatching.");if(i.dispatchFlag=!0,i.target=i.currentTarget=this,!i.stopPropagationFlag){let{cow:a,listeners:o}=n;n.cow=!0;for(let s=0;s<o.length;++s){let u=o[s];if(!rt(u)&&(me(u)&&ye(n,s,!a)&&(s-=1),i.inPassiveListenerFlag=pe(u),it(u,this,r),i.inPassiveListenerFlag=!1,i.stopImmediatePropagationFlag))break}a||(n.cow=!1)}return i.target=null,i.currentTarget=null,i.stopImmediatePropagationFlag=!1,i.stopPropagationFlag=!1,i.dispatchFlag=!1,!i.canceledFlag}},ke=new WeakMap;function X(t,e="this"){let n=ke.get(t);return W(n!=null,"'%s' must be an object that EventTarget constructor created, but got another one: %o",e,t),n}function ut(t,e,n){var r;return Ce(e),typeof n=="object"&&n!==null?{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n.capture),passive:Boolean(n.passive),once:Boolean(n.once),signal:(r=n.signal)!==null&&r!==void 0?r:void 0}:{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n),passive:!1,once:!1,signal:void 0}}function lt(t,e,n){return Ce(e),typeof n=="object"&&n!==null?{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n.capture)}:{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n)}}function Ce(t){if(!(typeof t=="function"||typeof t=="object"&&t!==null&&typeof t.handleEvent=="function")){if(t==null||typeof t=="object"){Q.warn(t);return}throw new TypeError(oe(Q.message,[t]))}}function ct(t,e,n,r){Je.warn(fe(t)?"capture":"bubble",t.callback),pe(t)!==e&&N.warn("passive"),me(t)!==n&&N.warn("once"),t.signal!==r&&N.warn("signal")}var H=Object.getOwnPropertyNames(E.prototype);for(let t=0;t<H.length;++t)H[t]!=="constructor"&&Object.defineProperty(E.prototype,H[t],{enumerable:!0});typeof m!="undefined"&&typeof m.EventTarget!="undefined"&&Object.setPrototypeOf(E.prototype,m.EventTarget.prototype);var Le=We(Ie()),q=30720,O=512e3,A=256,R=(t,{minChunkSize:e=A,maxChunkSize:n=O}={})=>t==null||typeof t=="number"&&t>=256&&t%256===0&&t>=e&&t<=n,z=(t,{minChunkSize:e=A,maxChunkSize:n=O}={})=>new TypeError(`chunkSize ${t} must be a positive number in multiples of 256, between ${e} and ${n}`),x=class{constructor(e,n={}){this.readableStream=e;var r,i,a;if(!R(n.defaultChunkSize,n))throw z(n.defaultChunkSize,n);this.defaultChunkSize=(r=n.defaultChunkSize)!=null?r:q,this.minChunkSize=(i=n.minChunkSize)!=null?i:A,this.maxChunkSize=(a=n.maxChunkSize)!=null?a:O}get chunkSize(){var e;return(e=this._chunkSize)!=null?e:this.defaultChunkSize}set chunkSize(e){if(!R(e,this))throw z(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}get error(){return this._error}async*[Symbol.asyncIterator](){let e,n=this.readableStream.getReader();try{for(;;){let{done:r,value:i}=await n.read();if(r){if(e){let o=e;e=void 0,yield o}break}let a=i instanceof Uint8Array?new Blob([i],{type:"application/octet-stream"}):i;for(e=e?new Blob([e,a]):a;e;)if(e.size===this.chunkByteSize){let o=e;e=void 0,yield o;break}else{if(e.size<this.chunkByteSize)break;{let o=e.slice(0,this.chunkByteSize);e=e.slice(this.chunkByteSize),yield o}}}}catch(r){this._error=r}finally{if(e){let r=e;e=void 0,yield r}n.releaseLock();return}}},U=class{constructor(e,n={}){this.file=e;var r,i,a;if(!R(n.defaultChunkSize,n))throw z(n.defaultChunkSize,n);this.defaultChunkSize=(r=n.defaultChunkSize)!=null?r:q,this.minChunkSize=(i=n.minChunkSize)!=null?i:A,this.maxChunkSize=(a=n.maxChunkSize)!=null?a:O}get chunkSize(){var e;return(e=this._chunkSize)!=null?e:this.defaultChunkSize}set chunkSize(e){if(!R(e,this))throw z(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}get error(){return this._error}async*[Symbol.asyncIterator](){let e=new FileReader,n=0,r=()=>new Promise(i=>{if(n>=this.file.size){i(void 0);return}let a=Math.min(this.chunkByteSize,this.file.size-n);e.onload=()=>{e.result!==null?i(new Blob([e.result],{type:"application/octet-stream"})):i(void 0)},e.readAsArrayBuffer(this.file.slice(n,n+a))});try{for(;;){let i=await r();if(i)n+=i.size,yield i;else break}}catch(i){this._error=i}}},vt=[200,201,202,204,308],Be=[408,502,503,504],wt=[308],xe=(t,e)=>!!t&&vt.includes(t.statusCode),Rt=(t,{retryCodes:e=Be})=>!t||e.includes(t.statusCode),zt=(t,e)=>e.attemptCount>=e.attempts||!(xe(t)||Rt(t,e)),Ue=(t,e)=>{var i;if(!t||!wt.includes(t.statusCode)||!((i=t.headers)!=null&&i.range))return!1;let n=t.headers.range.match(/bytes=(\d+)-(\d+)/);return n?parseInt(n[2],10)!==e.currentChunkEndByte:!1},T=class{static createUpload(e){return new T(e)}constructor(e){if(this.eventTarget=new E,this.endpoint=e.endpoint,this.file=e.file,this.headers=e.headers||{},this.method=e.method||"PUT",this.attempts=e.attempts||5,this.delayBeforeAttempt=e.delayBeforeAttempt||1,this.retryCodes=e.retryCodes||Be,this.dynamicChunkSize=e.dynamicChunkSize||!1,this.maxFileBytes=(e.maxFileSize||0)*1024,this.chunkCount=0,this.attemptCount=0,this._offline=typeof window!="undefined"&&!window.navigator.onLine,this._paused=!1,this.success=!1,this.nextChunkRangeStart=0,e.useLargeFileWorkaround){let n=r=>{this.chunkedIterable.error&&(console.warn(`Unable to read file of size ${this.file.size} bytes via a ReadableStream. Falling back to in-memory FileReader!`),r.stopImmediatePropagation(),this.chunkedIterable=new U(this.file,{...e,defaultChunkSize:e.chunkSize}),this.chunkedIterator=this.chunkedIterable[Symbol.asyncIterator](),this.getEndpoint().then(()=>{this.sendChunks()}),this.off("error",n))};this.on("error",n)}this.chunkedIterable=new x(this.file.stream(),{...e,defaultChunkSize:e.chunkSize}),this.chunkedIterator=this.chunkedIterable[Symbol.asyncIterator](),this.totalChunks=Math.ceil(this.file.size/this.chunkByteSize),this.validateOptions(),this.getEndpoint().then(()=>this.sendChunks()),typeof window!="undefined"&&(window.addEventListener("online",()=>{!this.offline||(this._offline=!1,this.dispatch("online"),this.sendChunks())}),window.addEventListener("offline",()=>{this.offline||(this._offline=!0,this.dispatch("offline"))}))}get maxChunkSize(){var e,n;return(n=(e=this.chunkedIterable)==null?void 0:e.maxChunkSize)!=null?n:O}get minChunkSize(){var e,n;return(n=(e=this.chunkedIterable)==null?void 0:e.minChunkSize)!=null?n:A}get chunkSize(){var e,n;return(n=(e=this.chunkedIterable)==null?void 0:e.chunkSize)!=null?n:q}set chunkSize(e){this.chunkedIterable.chunkSize=e}get chunkByteSize(){return this.chunkedIterable.chunkByteSize}get totalChunkSize(){return Math.ceil(this.file.size/this.chunkByteSize)}on(e,n){this.eventTarget.addEventListener(e,n)}once(e,n){this.eventTarget.addEventListener(e,n,{once:!0})}off(e,n){this.eventTarget.removeEventListener(e,n)}get offline(){return this._offline}get paused(){return this._paused}abort(){var e;this.pause(),(e=this.currentXhr)==null||e.abort()}pause(){this._paused=!0}resume(){this._paused&&(this._paused=!1,this.sendChunks())}get successfulPercentage(){return this.nextChunkRangeStart/this.file.size}dispatch(e,n){let r=new CustomEvent(e,{detail:n});this.eventTarget.dispatchEvent(r)}validateOptions(){if(!this.endpoint||typeof this.endpoint!="function"&&typeof this.endpoint!="string")throw new TypeError("endpoint must be defined as a string or a function that returns a promise");if(!(this.file instanceof File))throw new TypeError("file must be a File object");if(this.headers&&typeof this.headers!="function"&&typeof this.headers!="object")throw new TypeError("headers must be null, an object, or a function that returns an object or a promise");if(!R(this.chunkSize,{maxChunkSize:this.maxChunkSize,minChunkSize:this.minChunkSize}))throw z(this.chunkSize,{maxChunkSize:this.maxChunkSize,minChunkSize:this.minChunkSize});if(this.maxChunkSize&&(typeof this.maxChunkSize!="number"||this.maxChunkSize<256||this.maxChunkSize%256!==0||this.maxChunkSize<this.chunkSize||this.maxChunkSize<this.minChunkSize))throw new TypeError(`maxChunkSize must be a positive number in multiples of 256, and larger than or equal to both ${this.minChunkSize} and ${this.chunkSize}`);if(this.minChunkSize&&(typeof this.minChunkSize!="number"||this.minChunkSize<256||this.minChunkSize%256!==0||this.minChunkSize>this.chunkSize||this.minChunkSize>this.maxChunkSize))throw new TypeError(`minChunkSize must be a positive number in multiples of 256, and smaller than ${this.chunkSize} and ${this.maxChunkSize}`);if(this.maxFileBytes>0&&this.maxFileBytes<this.file.size)throw new Error(`file size exceeds maximum (${this.file.size} > ${this.maxFileBytes})`);if(this.attempts&&(typeof this.attempts!="number"||this.attempts<=0))throw new TypeError("retries must be a positive number");if(this.delayBeforeAttempt&&(typeof this.delayBeforeAttempt!="number"||this.delayBeforeAttempt<0))throw new TypeError("delayBeforeAttempt must be a positive number")}getEndpoint(){return typeof this.endpoint=="string"?(this.endpointValue=this.endpoint,Promise.resolve(this.endpoint)):this.endpoint(this.file).then(e=>(this.endpointValue=e,this.endpointValue))}xhrPromise(e){let n=r=>{r.upload.onprogress=i=>{var h;let a=this.totalChunks-this.chunkCount,o=(this.file.size-this.nextChunkRangeStart)/this.file.size/a,u=i.loaded/((h=i.total)!=null?h:this.chunkByteSize)*o;this.dispatch("progress",Math.min((this.successfulPercentage+u)*100,100))}};return new Promise((r,i)=>{this.currentXhr=(0,Le.default)({...e,beforeSend:n},(a,o)=>(this.currentXhr=void 0,a?i(a):r(o)))})}async sendChunk(e){let n=this.nextChunkRangeStart,r=n+e.size-1,a={...await(typeof this.headers=="function"?this.headers():this.headers),"Content-Type":this.file.type,"Content-Range":`bytes ${n}-${r}/${this.file.size}`};return this.dispatch("attempt",{chunkNumber:this.chunkCount,totalChunks:this.totalChunks,chunkSize:this.chunkSize}),this.xhrPromise({headers:a,url:this.endpointValue,method:this.method,body:e})}async sendChunkWithRetries(e){let n=async(s,u)=>{var d;let f=(new Date().getTime()-this.lastChunkStart.getTime())/1e3;if(this.dispatch("chunkSuccess",{chunk:this.chunkCount,chunkSize:this.chunkSize,attempts:this.attemptCount,timeInterval:f,response:s}),this.attemptCount=0,this.chunkCount=((d=this.chunkCount)!=null?d:0)+1,this.nextChunkRangeStart=this.nextChunkRangeStart+this.chunkByteSize,this.dynamicChunkSize){let y=this.chunkSize;f<10?y=Math.min(this.chunkSize*2,this.maxChunkSize):f>30&&(y=Math.max(this.chunkSize/2,this.minChunkSize)),this.chunkSize=Math.ceil(y/256)*256;let p=(this.file.size-this.nextChunkRangeStart)/this.chunkByteSize;this.totalChunks=Math.ceil(this.chunkCount+p)}return!0},r=async(s,u)=>(this.dispatch("progress",Math.min(this.successfulPercentage*100,100)),this.dispatch("error",{message:`Server responded with ${s.statusCode}. Stopping upload.`,chunk:this.chunkCount,attempts:this.attemptCount,response:s}),!1),i=async(s,u)=>(this.dispatch("attemptFailure",{message:`An error occured uploading chunk ${this.chunkCount}. ${this.attempts-this.attemptCount} retries left.`,chunkNumber:this.chunkCount,attemptsLeft:this.attempts-this.attemptCount,response:s}),new Promise(h=>{setTimeout(async()=>{if(this._paused||this.offline){this.pendingChunk=e,h(!1);return}let f=await this.sendChunkWithRetries(e);h(f)},this.delayBeforeAttempt*1e3)})),a;try{this.attemptCount=this.attemptCount+1,this.lastChunkStart=new Date,a=await this.sendChunk(e)}catch(s){typeof(s==null?void 0:s.statusCode)=="number"&&(a=s)}let o={retryCodes:this.retryCodes,attemptCount:this.attemptCount,attempts:this.attempts,currentChunkEndByte:this.nextChunkRangeStart+e.size-1};return Ue(a,o)?i(a,e):xe(a,o)?n(a,e):zt(a,o)?r(a,e):i(a,e)}async sendChunks(){if(this.pendingChunk&&!(this._paused||this.offline)){let e=this.pendingChunk;this.pendingChunk=void 0;let n=await this.sendChunkWithRetries(e);this.success&&n&&this.dispatch("success")}for(;!(this.success||this._paused||this.offline);){let{value:e,done:n}=await this.chunkedIterator.next(),r=!e&&n;if(e&&(r=await this.sendChunkWithRetries(e)),this.chunkedIterable.error){r=!1,this.dispatch("error",{message:`Unable to read file of size ${this.file.size} bytes. Try loading from another browser.`});return}if(this.success=!!n,this.success&&r&&this.dispatch("success"),!r)return}}};function Tt(t){return T.createUpload(t)}
if (typeof module.exports == "object" && typeof exports == "object") {

@@ -19,0 +19,0 @@ var __cp = (to, from, except, desc) => {

{
"name": "@mux/upchunk",
"version": "3.3.3",
"version": "3.4.0",
"description": "Dead simple chunked file uploads using Fetch",

@@ -5,0 +5,0 @@ "main": "dist/upchunk.js",

@@ -54,3 +54,3 @@ <p align="center">

tokenId: process.env.MUX_TOKEN_ID,
tokenSecret: process.env.MUX_TOKEN_SECRET
tokenSecret: process.env.MUX_TOKEN_SECRET,
});

@@ -83,3 +83,3 @@

const getUploadUrl = () =>
fetch('/the-endpoint-above').then(res =>
fetch('/the-endpoint-above').then((res) =>
res.ok ? res.text() : throw new Error('Error getting an upload URL :(')

@@ -95,7 +95,7 @@ );

// subscribe to events
upload.on('error', err => {
upload.on('error', (err) => {
console.error('💥 🙀', err.detail);
});
upload.on('progress', progress => {
upload.on('progress', (progress) => {
console.log(`So far we've uploaded ${progress.detail}% of this file.`);

@@ -124,3 +124,3 @@ });

const url = await response.text();
const upload = UpChunk.createUpload({

@@ -131,9 +131,9 @@ endpoint: url, // Authenticated url

});
// Subscribe to events
upload.on('error', error => {
upload.on('error', (error) => {
setStatusMessage(error.detail);
});
upload.on('progress', progress => {
upload.on('progress', (progress) => {
setProgress(progress.detail);

@@ -148,3 +148,3 @@ });

}
}
};

@@ -155,10 +155,13 @@ return (

<label htmlFor="file-picker">Select a video file:</label>
<input type="file" onChange={(e) => handleUpload(e.target)}
id="file-picker" name="file-picker"/ >
<input
type="file"
onChange={(e) => handleUpload(e.target)}
id="file-picker"
name="file-picker"
/>
<label htmlFor="upload-progress">Downloading progress:</label>
<progress value={progress} max="100"/>
<progress value={progress} max="100" />
<em>{statusMessage}</em>
</div>

@@ -179,3 +182,3 @@ );

- `endpoint` <small>type: `string` | `function` (required)</small>
- `endpoint` <small>type: `string` (url) | `function` (required)</small>

@@ -192,3 +195,3 @@ URL to upload the file to. This can be either a string of the authenticated URL to upload to, or a function that returns a promise that resolves that URL string. The function will be passed the `file` as a parameter.

- `chunkSize` <small>type: `integer`, default:`30720`</small>
- `chunkSize` <small>type: `integer` (kB), default:`30720`</small>

@@ -203,8 +206,12 @@ The size in kB of the chunks to split the file into, with the exception of the final chunk which may be smaller. This parameter must be in multiples of 256.

The number of times to retry any given chunk.
The number of times to retry any given chunk if the upload attempt fails with a retriable response status (see: `retryCodes`, below). After attempting `attempts` times, an error event will be dispatched and uploading will halt.
- `delayBeforeAttempt` <small>type: `integer`, default: `1`</small>
- `delayBeforeAttempt` <small>type: `number` (seconds), default: `1.0`</small>
The time in seconds to wait before attempting to upload a chunk again.
- `retryCodes` <small>type: `number[]` (HTTP Status), default: `[408, 502, 503, 504]`</small>
The HTTP Status codes that indicate a given (failed) chunk upload request attempt is retriable. See also: `attempts` option, above.
- `method` <small>type: `"PUT" | "PATCH" | "POST"`, default: `PUT`</small>

@@ -218,10 +225,24 @@

- `maxChunkSize` <small>type: `integer`, default: `512000`</small>
- `maxChunkSize` <small>type: `integer` (kB), default: `512000`</small>
When `dynamicChunkSize` is `true`, the largest chunk size that will be used, in kB.
- `minChunkSize` <small>type: `integer`, default: `256`</small>
- `minChunkSize` <small>type: `integer` (kB), default: `256`</small>
When `dynamicChunkSize` is `true`, the smallest chunk size that will be used, in kB.
- `useLargeFileWorkaround` <small>type: `boolean`, default: `false`</small>
Falls back to reading entire file into memory for cases where support for streams is unreliable (see, e.g. [this upchunk issue](https://github.com/muxinc/upchunk/issues/134) and the corresponding [webkit bug report](https://bugs.webkit.org/show_bug.cgi?id=272600)).
### UpChunk Instance Properties
- `offline` <small>type: `(readonly) boolean` default: `false`</small>
Indicates whether or not currently offline. While offline, uploading will pause and resume automatically once back online. See also: `offline` and `online` events, below.
- `paused` <small>type: `(readonly) boolean` default: `false`</small>
Indicates whether or not uploading has been temporarily paused via the `pause()` method. See also: `pause()` and `resume()` methods, below.
### UpChunk Instance Methods

@@ -228,0 +249,0 @@

@@ -53,6 +53,14 @@ import { EventTarget, Event } from 'event-target-shim';

export interface ChunkedIterable extends AsyncIterable<Blob> {
chunkSize: number;
readonly chunkByteSize: number;
readonly minChunkSize: number;
readonly maxChunkSize: number;
readonly error: Error | undefined;
}
// An Iterable that accepts a readableStream of binary data (Blob | Uint8Array) and provides
// an asyncIterator which yields Blob values of the current chunkSize until done. Note that
// chunkSize may change between iterations.
export class ChunkedStreamIterable implements AsyncIterable<Blob> {
export class ChunkedStreamIterable implements ChunkedIterable {
protected _chunkSize: number | undefined;

@@ -154,2 +162,91 @@ protected defaultChunkSize: number;

export class ChunkedFileIterable implements ChunkedIterable {
protected _chunkSize: number | undefined;
protected defaultChunkSize: number;
protected _error: Error | undefined;
public readonly minChunkSize: number;
public readonly maxChunkSize: number;
constructor(
protected file: File,
options: ChunkedStreamIterableOptions = {}
) {
if (!isValidChunkSize(options.defaultChunkSize, options)) {
throw getChunkSizeError(options.defaultChunkSize, options);
}
this.defaultChunkSize = options.defaultChunkSize ?? DEFAULT_CHUNK_SIZE;
this.minChunkSize = options.minChunkSize ?? DEFAULT_MIN_CHUNK_SIZE;
this.maxChunkSize = options.maxChunkSize ?? DEFAULT_MAX_CHUNK_SIZE;
}
get chunkSize() {
return this._chunkSize ?? this.defaultChunkSize;
}
set chunkSize(value) {
if (!isValidChunkSize(value, this)) {
throw getChunkSizeError(value, this);
}
this._chunkSize = value;
}
get chunkByteSize() {
return this.chunkSize * 1024;
}
get error() {
return this._error;
}
async *[Symbol.asyncIterator](): AsyncIterator<Blob> {
const reader = new FileReader();
let nextChunkRangeStart = 0;
/**
* Get portion of the file of x bytes corresponding to chunkSize
*/
const getChunk = () => {
return new Promise<Blob | undefined>((resolve) => {
if (nextChunkRangeStart >= this.file.size) {
resolve(undefined);
return;
}
// We either want to slize a "chunkByteSize-worth" of the file or
// slice to the end of the file (if less than a "chunkByteSize-worth" is left)
const length = Math.min(
this.chunkByteSize,
this.file.size - nextChunkRangeStart
);
reader.onload = () => {
if (reader.result !== null) {
resolve(
new Blob([reader.result], {
type: 'application/octet-stream',
})
);
} else {
resolve(undefined);
}
};
reader.readAsArrayBuffer(
this.file.slice(nextChunkRangeStart, nextChunkRangeStart + length)
);
});
};
try {
while (true) {
const nextChunk = await getChunk();
if (!!nextChunk) {
nextChunkRangeStart += nextChunk.size;
yield nextChunk;
} else {
break;
}
}
} catch (e) {
this._error = e;
}
}
}
const SUCCESSFUL_CHUNK_UPLOAD_CODES = [200, 201, 202, 204, 308];

@@ -239,2 +336,3 @@ const TEMPORARY_ERROR_CODES = [408, 502, 503, 504]; // These error codes imply a chunk may be retried

minChunkSize?: number;
useLargeFileWorkaround?: boolean;
}

@@ -255,4 +353,4 @@

public dynamicChunkSize: boolean;
protected chunkedStreamIterable: ChunkedStreamIterable;
protected chunkedStreamIterator;
protected chunkedIterable: ChunkedIterable;
protected chunkedIterator;

@@ -275,2 +373,4 @@ protected pendingChunk?: Blob;

constructor(options: UpChunkOptions) {
this.eventTarget = new EventTarget();
this.endpoint = options.endpoint;

@@ -298,16 +398,42 @@ this.file = options.file;

if (options.useLargeFileWorkaround) {
const readableStreamErrorCallback = (event: CustomEvent) => {
// In this case, assume the error is a result of file reading via ReadableStream.
// Retry using ChunkedFileIterable, which reads the file into memory instead
// of a stream.
if (this.chunkedIterable.error) {
console.warn(
`Unable to read file of size ${this.file.size} bytes via a ReadableStream. Falling back to in-memory FileReader!`
);
event.stopImmediatePropagation();
// Re-set everything up with the fallback iterable and corresponding
// iterator
this.chunkedIterable = new ChunkedFileIterable(this.file, {
...options,
defaultChunkSize: options.chunkSize,
});
this.chunkedIterator = this.chunkedIterable[Symbol.asyncIterator]();
this.getEndpoint().then(() => {
this.sendChunks();
});
this.off('error', readableStreamErrorCallback);
}
};
this.on('error', readableStreamErrorCallback);
}
// Types appear to be getting confused in env setup, using the overloaded NodeJS Blob definition, which uses NodeJS.ReadableStream instead
// of the DOM type definitions. For definitions, See consumers.d.ts vs. lib.dom.d.ts. (CJP)
this.chunkedStreamIterable = new ChunkedStreamIterable(
this.chunkedIterable = new ChunkedStreamIterable(
this.file.stream() as unknown as ReadableStream<Uint8Array>,
{ ...options, defaultChunkSize: options.chunkSize }
);
this.chunkedStreamIterator =
this.chunkedStreamIterable[Symbol.asyncIterator]();
this.chunkedIterator = this.chunkedIterable[Symbol.asyncIterator]();
// NOTE: Since some of upchunk's properties defer "source of truth" to
// chunkedIterable, we need to do these after it's been created (CJP).
this.totalChunks = Math.ceil(this.file.size / this.chunkByteSize);
this.validateOptions();
this.eventTarget = new EventTarget();
this.validateOptions();
this.getEndpoint().then(() => this.sendChunks());

@@ -336,19 +462,19 @@

protected get maxChunkSize() {
return this.chunkedStreamIterable?.maxChunkSize ?? DEFAULT_MAX_CHUNK_SIZE;
return this.chunkedIterable?.maxChunkSize ?? DEFAULT_MAX_CHUNK_SIZE;
}
protected get minChunkSize() {
return this.chunkedStreamIterable?.minChunkSize ?? DEFAULT_MIN_CHUNK_SIZE;
return this.chunkedIterable?.minChunkSize ?? DEFAULT_MIN_CHUNK_SIZE;
}
public get chunkSize() {
return this.chunkedStreamIterable?.chunkSize ?? DEFAULT_CHUNK_SIZE;
return this.chunkedIterable?.chunkSize ?? DEFAULT_CHUNK_SIZE;
}
public set chunkSize(value) {
this.chunkedStreamIterable.chunkSize = value;
this.chunkedIterable.chunkSize = value;
}
public get chunkByteSize() {
return this.chunkedStreamIterable.chunkByteSize;
return this.chunkedIterable.chunkByteSize;
}

@@ -716,3 +842,3 @@

while (!(this.success || this._paused || this.offline)) {
const { value: chunk, done } = await this.chunkedStreamIterator.next();
const { value: chunk, done } = await this.chunkedIterator.next();
// NOTE: When `done`, `chunk` is undefined, so default `chunkUploadSuccess`

@@ -725,5 +851,8 @@ // to be `true` on this condition, otherwise `false`.

if (this.chunkedStreamIterable.error) {
this.dispatch('error', { message: `Unable to read file of size ${this.file.size} bytes. Try loading from another browser.` });
if (this.chunkedIterable.error) {
chunkUploadSuccess = false;
this.dispatch('error', {
message: `Unable to read file of size ${this.file.size} bytes. Try loading from another browser.`,
});
return;
}

@@ -730,0 +859,0 @@ // NOTE: Need to disambiguate "last chunk to upload" (done) vs. "successfully"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc