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.2.0 to 3.2.1

6

dist/upchunk.cjs.js

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

var Ue=Object.create;var _=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var De=Object.getPrototypeOf,Me=Object.prototype.hasOwnProperty;var T=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Xe=(t,e)=>{for(var n in e)_(t,n,{get:e[n],enumerable:!0})},G=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ne(e))!Me.call(t,i)&&i!==n&&_(t,i,{get:()=>e[i],enumerable:!(r=Fe(e,i))||r.enumerable});return t};var He=(t,e,n)=>(n=t!=null?Ue(De(t)):{},G(e||!t||!t.__esModule?_(n,"default",{value:t,enumerable:!0}):n,t)),je=t=>G(_({},"__esModule",{value:!0}),t);var Ee=T((_t,Ce)=>{var z;typeof window!="undefined"?z=window:typeof global!="undefined"?z=global:typeof self!="undefined"?z=self:z={};Ce.exports=z});var ke=T((At,Se)=>{Se.exports=ct;var lt=Object.prototype.toString;function ct(t){if(!t)return!1;var e=lt.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((Ot,ve)=>{var W=function(t){return t.replace(/^\s+|\s+$/g,"")},ht=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:ht(e[o])?e[o].push(s):e[o]=[e[o],s]}return e}});var Te=T((It,Re)=>{Re.exports=dt;var pt=Object.prototype.hasOwnProperty;function dt(){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 Ae=T((Lt,$)=>{"use strict";var ze=Ee(),ft=ke(),mt=we(),gt=Te();$.exports=C;$.exports.default=C;C.XMLHttpRequest=ze.XMLHttpRequest||Et;C.XDomainRequest="withCredentials"in new C.XMLHttpRequest?C.XMLHttpRequest:ze.XDomainRequest;bt(["get","put","post","patch","head","delete"],function(t){C[t==="delete"?"del":t]=function(e,n,r){return n=Pe(e,n,r),n.method=t.toUpperCase(),_e(n)}});function bt(t,e){for(var n=0;n<t.length;n++)e(t[n])}function yt(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function Pe(t,e,n){var r=t;return ft(e)?(n=e,typeof t=="string"&&(r={uri:t})):r=gt(e,{uri:t}),r.callback=n,r}function C(t,e,n){return e=Pe(t,e,n),_e(e)}function _e(t){if(typeof t.callback=="undefined")throw new Error("callback argument missing");var e=!1,n=function(S,P,xe){e||(e=!0,t.callback(S,P,xe))};function r(){s.readyState===4&&setTimeout(o,0)}function i(){var u=void 0;if(s.response?u=s.response:u=s.responseText||Ct(s),V)try{u=JSON.parse(u)}catch{}return u}function a(u){return clearTimeout(F),u instanceof Error||(u=new Error(""+(u||"Unknown XMLHttpRequest Error"))),u.statusCode=0,n(u,q)}function o(){if(!h){var u;clearTimeout(F),t.useXDR&&s.status===void 0?u=200:u=s.status===1223?204:s.status;var S=q,P=null;return u!==0?(S={body:i(),statusCode:u,method:d,headers:{},url:p,rawRequest:s},s.getAllResponseHeaders&&(S.headers=mt(s.getAllResponseHeaders()))):P=new Error("Internal XMLHttpRequest Error"),n(P,S,S.body)}}var s=t.xhr||null;s||(t.cors||t.useXDR?s=new C.XDomainRequest:s=new C.XMLHttpRequest);var c,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,F,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&&(F=setTimeout(function(){if(!h){h=!0,s.abort("timeout");var u=new Error("XMLHttpRequest timeout");u.code="ETIMEDOUT",a(u)}},t.timeout)),s.setRequestHeader)for(c in f)f.hasOwnProperty(c)&&s.setRequestHeader(c,f[c]);else if(t.headers&&!yt(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 Ct(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 Rt={};Xe(Rt,{ChunkedStreamIterable:()=>L,UpChunk:()=>R,createUpload:()=>wt,getChunkSizeError:()=>I,isValidChunkSize:()=>O});module.exports=je(Rt);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 We(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{}}},$e=new g("W01","Unable to initialize event under dispatching."),Ve=new g("W02","Assigning any falsy value to 'cancelBubble' property has no effect."),qe=new g("W03","Assigning any truthy value to 'returnValue' property has no effect."),Ge=new g("W04","Unable to preventDefault on non-cancelable events."),Ye=new g("W05","Unable to preventDefault inside passive event listener invocation."),Ke=new g("W06","An event listener wasn't added because it has been added already: %o, %o"),N=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"),zt=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 l(this).type}get target(){return l(this).target}get srcElement(){return l(this).target}get currentTarget(){return l(this).currentTarget}composedPath(){let e=l(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 l(this).dispatchFlag?2:0}stopPropagation(){l(this).stopPropagationFlag=!0}get cancelBubble(){return l(this).stopPropagationFlag}set cancelBubble(e){e?l(this).stopPropagationFlag=!0:Ve.warn()}stopImmediatePropagation(){let e=l(this);e.stopPropagationFlag=e.stopImmediatePropagationFlag=!0}get bubbles(){return l(this).bubbles}get cancelable(){return l(this).cancelable}get returnValue(){return!l(this).canceledFlag}set returnValue(e){e?qe.warn():ne(l(this))}preventDefault(){ne(l(this))}get defaultPrevented(){return l(this).canceledFlag}get composed(){return l(this).composed}get isTrusted(){return!1}get timeStamp(){return l(this).timeStamp}initEvent(e,n=!1,r=!1){let i=l(this);if(i.dispatchFlag){$e.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 l(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){Ye.warn();return}if(!t.cancelable){Ge.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 Ze(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}=E(this);"stopPropagation"in e&&e.stopPropagation()}get cancelBubble(){return super.cancelBubble}set cancelBubble(e){super.cancelBubble=e;let{original:n}=E(this);"cancelBubble"in n&&(n.cancelBubble=e)}stopImmediatePropagation(){super.stopImmediatePropagation();let{original:e}=E(this);"stopImmediatePropagation"in e&&e.stopImmediatePropagation()}get returnValue(){return super.returnValue}set returnValue(e){super.returnValue=e;let{original:n}=E(this);"returnValue"in n&&(n.returnValue=e)}preventDefault(){super.preventDefault();let{original:e}=E(this);"preventDefault"in e&&e.preventDefault()}get timeStamp(){let{original:e}=E(this);return"timeStamp"in e?e.timeStamp:super.timeStamp}},ue=new WeakMap;function E(t){let e=ue.get(t);return j(e!=null,"'this' is expected an Event object, but got",t),e}var A=new WeakMap;A.set(Object.prototype,w);typeof m!="undefined"&&typeof m.Event!="undefined"&&A.set(m.Event.prototype,w);function le(t){let e=Object.getPrototypeOf(t);if(e==null)return w;let n=A.get(e);return n==null&&(n=Je(le(e),e),A.set(e,n)),n}function Je(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=E(this).original,i=r[e];return typeof i=="function"?i.bind(r):i},set(r){let i=E(this).original;i[e]=r},configurable:n.configurable,enumerable:n.enumerable}}function Qe(t,e,n,r,i,a){return{callback:t,flags:(e?1:0)|(n?2:0)|(r?4:0),signal:i,signalListener:a}}function et(t){t.flags|=8}function he(t){return(t.flags&1)===1}function pe(t){return(t.flags&2)===2}function de(t){return(t.flags&4)===4}function tt(t){return(t.flags&8)===8}function nt({callback:t},e,n){try{typeof t=="function"?t.call(e,n):typeof t.handleEvent=="function"&&t.handleEvent(n)}catch(r){We(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 rt(t,e,n,r,i,a){let o;a&&(o=me.bind(null,t,e,n),a.addEventListener("abort",o));let s=Qe(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 et(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 it(){return Object.create(null)}function st(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 k=class{constructor(){be.set(this,it())}addEventListener(e,n,r){let i=M(this),{callback:a,capture:o,once:s,passive:c,signal:h,type:p}=at(e,n,r);if(a==null||(h==null?void 0:h.aborted))return;let d=st(i,p),y=fe(d,a,o);if(y!==-1){ut(d.listeners[y],c,s,h);return}rt(d,a,o,c,s,h)}removeEventListener(e,n,r){let i=M(this),{callback:a,capture:o,type:s}=ot(e,n,r),c=i[s];a!=null&&c&&me(c,a,o)}dispatchEvent(e){let n=M(this)[String(e.type)];if(n==null)return!0;let r=e instanceof b?e:w.wrap(e),i=l(r,"event");if(i.dispatchFlag)throw Ze("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 c=o[s];if(!tt(c)&&(de(c)&&ge(n,s,!a)&&(s-=1),i.inPassiveListenerFlag=pe(c),nt(c,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 M(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 at(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 ot(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 ut(t,e,n,r){Ke.warn(he(t)?"capture":"bubble",t.callback),pe(t)!==e&&N.warn("passive"),de(t)!==n&&N.warn("once"),t.signal!==r&&N.warn("signal")}var X=Object.getOwnPropertyNames(k.prototype);for(let t=0;t<X.length;++t)X[t]!=="constructor"&&Object.defineProperty(k.prototype,X[t],{enumerable:!0});typeof m!="undefined"&&typeof m.EventTarget!="undefined"&&Object.setPrototypeOf(k.prototype,m.EventTarget.prototype);var Oe=He(Ae()),Ie=30720,B=512e3,x=256,O=(t,{minChunkSize:e=x,maxChunkSize:n=B}={})=>t==null||typeof t=="number"&&t>=256&&t%256===0&&t>=e&&t<=n,I=(t,{minChunkSize:e=x,maxChunkSize:n=B}={})=>new TypeError(`chunkSize ${t} must be a positive number in multiples of 256, between ${e} and ${n}`),L=class{constructor(e,n={}){this.readableStream=e;var r,i,a;if(!O(n.defaultChunkSize,n))throw I(n.defaultChunkSize,n);this.defaultChunkSize=(r=n.defaultChunkSize)!=null?r:Ie,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(!O(e,this))throw I(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}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}}}}finally{if(e){let r=e;e=void 0,yield r}n.releaseLock();return}}},St=[200,201,202,204,308],Le=[408,502,503,504],Be=(t,e)=>!!t&&St.includes(t.statusCode),kt=(t,{retryCodes:e=Le})=>!t||e.includes(t.statusCode),vt=(t,e)=>e.attemptCount>=e.attempts||!(Be(t)||kt(t,e)),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||Le,this.dynamicChunkSize=e.dynamicChunkSize||!1,this.maxFileBytes=(e.maxFileSize||0)*1024,this.chunkCount=0,this.attemptCount=0,this.offline=!1,this._paused=!1,this.success=!1,this.nextChunkRangeStart=0,this.chunkedStreamIterable=new L(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 k,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=!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:Ie}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 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())}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(!O(this.chunkSize,{maxChunkSize:this.maxChunkSize,minChunkSize:this.minChunkSize}))throw I(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 p;let a=this.totalChunks-this.chunkCount,o=(this.file.size-this.nextChunkRangeStart)/this.file.size/a,s=this.nextChunkRangeStart/this.file.size,h=i.loaded/((p=i.total)!=null?p:this.chunkByteSize)*o;this.dispatch("progress",Math.min((s+h)*100,100))}};return new Promise((r,i)=>{this.currentXhr=(0,Oe.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,c)=>{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,c)=>(this.dispatch("error",{message:`Server responded with ${s.statusCode}. Stopping upload.`,chunk:this.chunkCount,attempts:this.attemptCount}),!1),i=async(s,c)=>(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}),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{}let o={retryCodes:this.retryCodes,attemptCount:this.attemptCount,attempts:this.attempts};return Be(a,o)?n(a,e):vt(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.success=!!n,this.success&&r&&this.dispatch("success"),!r)return}}},wt=R.createUpload;
var Ue=Object.create;var _=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var De=Object.getPrototypeOf,Me=Object.prototype.hasOwnProperty;var T=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Xe=(t,e)=>{for(var n in e)_(t,n,{get:e[n],enumerable:!0})},G=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ne(e))!Me.call(t,i)&&i!==n&&_(t,i,{get:()=>e[i],enumerable:!(r=Fe(e,i))||r.enumerable});return t};var He=(t,e,n)=>(n=t!=null?Ue(De(t)):{},G(e||!t||!t.__esModule?_(n,"default",{value:t,enumerable:!0}):n,t)),je=t=>G(_({},"__esModule",{value:!0}),t);var Ee=T((_t,Ce)=>{var z;typeof window!="undefined"?z=window:typeof global!="undefined"?z=global:typeof self!="undefined"?z=self:z={};Ce.exports=z});var ke=T((Ot,Se)=>{Se.exports=ct;var lt=Object.prototype.toString;function ct(t){if(!t)return!1;var e=lt.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((At,ve)=>{var W=function(t){return t.replace(/^\s+|\s+$/g,"")},ht=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:ht(e[o])?e[o].push(s):e[o]=[e[o],s]}return e}});var Te=T((It,Re)=>{Re.exports=dt;var pt=Object.prototype.hasOwnProperty;function dt(){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((Lt,$)=>{"use strict";var ze=Ee(),ft=ke(),mt=we(),gt=Te();$.exports=C;$.exports.default=C;C.XMLHttpRequest=ze.XMLHttpRequest||Et;C.XDomainRequest="withCredentials"in new C.XMLHttpRequest?C.XMLHttpRequest:ze.XDomainRequest;bt(["get","put","post","patch","head","delete"],function(t){C[t==="delete"?"del":t]=function(e,n,r){return n=Pe(e,n,r),n.method=t.toUpperCase(),_e(n)}});function bt(t,e){for(var n=0;n<t.length;n++)e(t[n])}function yt(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function Pe(t,e,n){var r=t;return ft(e)?(n=e,typeof t=="string"&&(r={uri:t})):r=gt(e,{uri:t}),r.callback=n,r}function C(t,e,n){return e=Pe(t,e,n),_e(e)}function _e(t){if(typeof t.callback=="undefined")throw new Error("callback argument missing");var e=!1,n=function(S,P,xe){e||(e=!0,t.callback(S,P,xe))};function r(){s.readyState===4&&setTimeout(o,0)}function i(){var u=void 0;if(s.response?u=s.response:u=s.responseText||Ct(s),V)try{u=JSON.parse(u)}catch{}return u}function a(u){return clearTimeout(F),u instanceof Error||(u=new Error(""+(u||"Unknown XMLHttpRequest Error"))),u.statusCode=0,n(u,q)}function o(){if(!h){var u;clearTimeout(F),t.useXDR&&s.status===void 0?u=200:u=s.status===1223?204:s.status;var S=q,P=null;return u!==0?(S={body:i(),statusCode:u,method:d,headers:{},url:p,rawRequest:s},s.getAllResponseHeaders&&(S.headers=mt(s.getAllResponseHeaders()))):P=new Error("Internal XMLHttpRequest Error"),n(P,S,S.body)}}var s=t.xhr||null;s||(t.cors||t.useXDR?s=new C.XDomainRequest:s=new C.XMLHttpRequest);var c,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,F,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&&(F=setTimeout(function(){if(!h){h=!0,s.abort("timeout");var u=new Error("XMLHttpRequest timeout");u.code="ETIMEDOUT",a(u)}},t.timeout)),s.setRequestHeader)for(c in f)f.hasOwnProperty(c)&&s.setRequestHeader(c,f[c]);else if(t.headers&&!yt(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 Ct(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 Rt={};Xe(Rt,{ChunkedStreamIterable:()=>L,UpChunk:()=>R,createUpload:()=>wt,getChunkSizeError:()=>I,isValidChunkSize:()=>A});module.exports=je(Rt);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 We(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{}}},$e=new g("W01","Unable to initialize event under dispatching."),Ve=new g("W02","Assigning any falsy value to 'cancelBubble' property has no effect."),qe=new g("W03","Assigning any truthy value to 'returnValue' property has no effect."),Ge=new g("W04","Unable to preventDefault on non-cancelable events."),Ye=new g("W05","Unable to preventDefault inside passive event listener invocation."),Ke=new g("W06","An event listener wasn't added because it has been added already: %o, %o"),N=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"),zt=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 l(this).type}get target(){return l(this).target}get srcElement(){return l(this).target}get currentTarget(){return l(this).currentTarget}composedPath(){let e=l(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 l(this).dispatchFlag?2:0}stopPropagation(){l(this).stopPropagationFlag=!0}get cancelBubble(){return l(this).stopPropagationFlag}set cancelBubble(e){e?l(this).stopPropagationFlag=!0:Ve.warn()}stopImmediatePropagation(){let e=l(this);e.stopPropagationFlag=e.stopImmediatePropagationFlag=!0}get bubbles(){return l(this).bubbles}get cancelable(){return l(this).cancelable}get returnValue(){return!l(this).canceledFlag}set returnValue(e){e?qe.warn():ne(l(this))}preventDefault(){ne(l(this))}get defaultPrevented(){return l(this).canceledFlag}get composed(){return l(this).composed}get isTrusted(){return!1}get timeStamp(){return l(this).timeStamp}initEvent(e,n=!1,r=!1){let i=l(this);if(i.dispatchFlag){$e.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 l(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){Ye.warn();return}if(!t.cancelable){Ge.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 Ze(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}=E(this);"stopPropagation"in e&&e.stopPropagation()}get cancelBubble(){return super.cancelBubble}set cancelBubble(e){super.cancelBubble=e;let{original:n}=E(this);"cancelBubble"in n&&(n.cancelBubble=e)}stopImmediatePropagation(){super.stopImmediatePropagation();let{original:e}=E(this);"stopImmediatePropagation"in e&&e.stopImmediatePropagation()}get returnValue(){return super.returnValue}set returnValue(e){super.returnValue=e;let{original:n}=E(this);"returnValue"in n&&(n.returnValue=e)}preventDefault(){super.preventDefault();let{original:e}=E(this);"preventDefault"in e&&e.preventDefault()}get timeStamp(){let{original:e}=E(this);return"timeStamp"in e?e.timeStamp:super.timeStamp}},ue=new WeakMap;function E(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=Je(le(e),e),O.set(e,n)),n}function Je(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=E(this).original,i=r[e];return typeof i=="function"?i.bind(r):i},set(r){let i=E(this).original;i[e]=r},configurable:n.configurable,enumerable:n.enumerable}}function Qe(t,e,n,r,i,a){return{callback:t,flags:(e?1:0)|(n?2:0)|(r?4:0),signal:i,signalListener:a}}function et(t){t.flags|=8}function he(t){return(t.flags&1)===1}function pe(t){return(t.flags&2)===2}function de(t){return(t.flags&4)===4}function tt(t){return(t.flags&8)===8}function nt({callback:t},e,n){try{typeof t=="function"?t.call(e,n):typeof t.handleEvent=="function"&&t.handleEvent(n)}catch(r){We(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 rt(t,e,n,r,i,a){let o;a&&(o=me.bind(null,t,e,n),a.addEventListener("abort",o));let s=Qe(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 et(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 it(){return Object.create(null)}function st(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 k=class{constructor(){be.set(this,it())}addEventListener(e,n,r){let i=M(this),{callback:a,capture:o,once:s,passive:c,signal:h,type:p}=at(e,n,r);if(a==null||(h==null?void 0:h.aborted))return;let d=st(i,p),y=fe(d,a,o);if(y!==-1){ut(d.listeners[y],c,s,h);return}rt(d,a,o,c,s,h)}removeEventListener(e,n,r){let i=M(this),{callback:a,capture:o,type:s}=ot(e,n,r),c=i[s];a!=null&&c&&me(c,a,o)}dispatchEvent(e){let n=M(this)[String(e.type)];if(n==null)return!0;let r=e instanceof b?e:w.wrap(e),i=l(r,"event");if(i.dispatchFlag)throw Ze("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 c=o[s];if(!tt(c)&&(de(c)&&ge(n,s,!a)&&(s-=1),i.inPassiveListenerFlag=pe(c),nt(c,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 M(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 at(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 ot(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 ut(t,e,n,r){Ke.warn(he(t)?"capture":"bubble",t.callback),pe(t)!==e&&N.warn("passive"),de(t)!==n&&N.warn("once"),t.signal!==r&&N.warn("signal")}var X=Object.getOwnPropertyNames(k.prototype);for(let t=0;t<X.length;++t)X[t]!=="constructor"&&Object.defineProperty(k.prototype,X[t],{enumerable:!0});typeof m!="undefined"&&typeof m.EventTarget!="undefined"&&Object.setPrototypeOf(k.prototype,m.EventTarget.prototype);var Ae=He(Oe()),Ie=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,I=(t,{minChunkSize:e=x,maxChunkSize:n=B}={})=>new TypeError(`chunkSize ${t} must be a positive number in multiples of 256, between ${e} and ${n}`),L=class{constructor(e,n={}){this.readableStream=e;var r,i,a;if(!A(n.defaultChunkSize,n))throw I(n.defaultChunkSize,n);this.defaultChunkSize=(r=n.defaultChunkSize)!=null?r:Ie,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 I(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}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}}}}finally{if(e){let r=e;e=void 0,yield r}n.releaseLock();return}}},St=[200,201,202,204,308],Le=[408,502,503,504],Be=(t,e)=>!!t&&St.includes(t.statusCode),kt=(t,{retryCodes:e=Le})=>!t||e.includes(t.statusCode),vt=(t,e)=>e.attemptCount>=e.attempts||!(Be(t)||kt(t,e)),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||Le,this.dynamicChunkSize=e.dynamicChunkSize||!1,this.maxFileBytes=(e.maxFileSize||0)*1024,this.chunkCount=0,this.attemptCount=0,this.offline=!1,this._paused=!1,this.success=!1,this.nextChunkRangeStart=0,this.chunkedStreamIterable=new L(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 k,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=!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:Ie}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 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())}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 I(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 p;let a=this.totalChunks-this.chunkCount,o=(this.file.size-this.nextChunkRangeStart)/this.file.size/a,s=this.nextChunkRangeStart/this.file.size,h=i.loaded/((p=i.total)!=null?p:this.chunkByteSize)*o;this.dispatch("progress",Math.min((s+h)*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,c)=>{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,c)=>(this.dispatch("error",{message:`Server responded with ${s.statusCode}. Stopping upload.`,chunk:this.chunkCount,attempts:this.attemptCount}),!1),i=async(s,c)=>(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}),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{}let o={retryCodes:this.retryCodes,attemptCount:this.attemptCount,attempts:this.attempts};return Be(a,o)?n(a,e):vt(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.success=!!n,this.success&&r&&this.dispatch("success"),!r)return}}};function wt(t){return R.createUpload(t)}
//# sourceMappingURL=upchunk.cjs.js.map

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

}
export declare const createUpload: typeof UpChunk.createUpload;
export declare function createUpload(options: UpChunkOptions): UpChunk;
export {};

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

var UpChunk=(()=>{var Ue=Object.create;var _=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var De=Object.getPrototypeOf,Me=Object.prototype.hasOwnProperty;var T=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Xe=(t,e)=>{for(var n in e)_(t,n,{get:e[n],enumerable:!0})},G=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ne(e))!Me.call(t,i)&&i!==n&&_(t,i,{get:()=>e[i],enumerable:!(r=Fe(e,i))||r.enumerable});return t};var He=(t,e,n)=>(n=t!=null?Ue(De(t)):{},G(e||!t||!t.__esModule?_(n,"default",{value:t,enumerable:!0}):n,t)),je=t=>G(_({},"__esModule",{value:!0}),t);var Ee=T((_t,Ce)=>{var z;typeof window!="undefined"?z=window:typeof global!="undefined"?z=global:typeof self!="undefined"?z=self:z={};Ce.exports=z});var ke=T((At,Se)=>{Se.exports=ct;var lt=Object.prototype.toString;function ct(t){if(!t)return!1;var e=lt.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((Ot,ve)=>{var W=function(t){return t.replace(/^\s+|\s+$/g,"")},ht=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:ht(e[o])?e[o].push(s):e[o]=[e[o],s]}return e}});var Te=T((It,Re)=>{Re.exports=dt;var pt=Object.prototype.hasOwnProperty;function dt(){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 Ae=T((Lt,$)=>{"use strict";var ze=Ee(),ft=ke(),mt=we(),gt=Te();$.exports=C;$.exports.default=C;C.XMLHttpRequest=ze.XMLHttpRequest||Et;C.XDomainRequest="withCredentials"in new C.XMLHttpRequest?C.XMLHttpRequest:ze.XDomainRequest;bt(["get","put","post","patch","head","delete"],function(t){C[t==="delete"?"del":t]=function(e,n,r){return n=Pe(e,n,r),n.method=t.toUpperCase(),_e(n)}});function bt(t,e){for(var n=0;n<t.length;n++)e(t[n])}function yt(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function Pe(t,e,n){var r=t;return ft(e)?(n=e,typeof t=="string"&&(r={uri:t})):r=gt(e,{uri:t}),r.callback=n,r}function C(t,e,n){return e=Pe(t,e,n),_e(e)}function _e(t){if(typeof t.callback=="undefined")throw new Error("callback argument missing");var e=!1,n=function(S,P,xe){e||(e=!0,t.callback(S,P,xe))};function r(){s.readyState===4&&setTimeout(o,0)}function i(){var u=void 0;if(s.response?u=s.response:u=s.responseText||Ct(s),V)try{u=JSON.parse(u)}catch{}return u}function a(u){return clearTimeout(F),u instanceof Error||(u=new Error(""+(u||"Unknown XMLHttpRequest Error"))),u.statusCode=0,n(u,q)}function o(){if(!h){var u;clearTimeout(F),t.useXDR&&s.status===void 0?u=200:u=s.status===1223?204:s.status;var S=q,P=null;return u!==0?(S={body:i(),statusCode:u,method:d,headers:{},url:p,rawRequest:s},s.getAllResponseHeaders&&(S.headers=mt(s.getAllResponseHeaders()))):P=new Error("Internal XMLHttpRequest Error"),n(P,S,S.body)}}var s=t.xhr||null;s||(t.cors||t.useXDR?s=new C.XDomainRequest:s=new C.XMLHttpRequest);var c,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,F,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&&(F=setTimeout(function(){if(!h){h=!0,s.abort("timeout");var u=new Error("XMLHttpRequest timeout");u.code="ETIMEDOUT",a(u)}},t.timeout)),s.setRequestHeader)for(c in f)f.hasOwnProperty(c)&&s.setRequestHeader(c,f[c]);else if(t.headers&&!yt(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 Ct(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 Rt={};Xe(Rt,{ChunkedStreamIterable:()=>L,UpChunk:()=>R,createUpload:()=>wt,getChunkSizeError:()=>I,isValidChunkSize:()=>O});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 We(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{}}},$e=new g("W01","Unable to initialize event under dispatching."),Ve=new g("W02","Assigning any falsy value to 'cancelBubble' property has no effect."),qe=new g("W03","Assigning any truthy value to 'returnValue' property has no effect."),Ge=new g("W04","Unable to preventDefault on non-cancelable events."),Ye=new g("W05","Unable to preventDefault inside passive event listener invocation."),Ke=new g("W06","An event listener wasn't added because it has been added already: %o, %o"),N=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"),zt=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 l(this).type}get target(){return l(this).target}get srcElement(){return l(this).target}get currentTarget(){return l(this).currentTarget}composedPath(){let e=l(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 l(this).dispatchFlag?2:0}stopPropagation(){l(this).stopPropagationFlag=!0}get cancelBubble(){return l(this).stopPropagationFlag}set cancelBubble(e){e?l(this).stopPropagationFlag=!0:Ve.warn()}stopImmediatePropagation(){let e=l(this);e.stopPropagationFlag=e.stopImmediatePropagationFlag=!0}get bubbles(){return l(this).bubbles}get cancelable(){return l(this).cancelable}get returnValue(){return!l(this).canceledFlag}set returnValue(e){e?qe.warn():ne(l(this))}preventDefault(){ne(l(this))}get defaultPrevented(){return l(this).canceledFlag}get composed(){return l(this).composed}get isTrusted(){return!1}get timeStamp(){return l(this).timeStamp}initEvent(e,n=!1,r=!1){let i=l(this);if(i.dispatchFlag){$e.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 l(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){Ye.warn();return}if(!t.cancelable){Ge.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 Ze(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}=E(this);"stopPropagation"in e&&e.stopPropagation()}get cancelBubble(){return super.cancelBubble}set cancelBubble(e){super.cancelBubble=e;let{original:n}=E(this);"cancelBubble"in n&&(n.cancelBubble=e)}stopImmediatePropagation(){super.stopImmediatePropagation();let{original:e}=E(this);"stopImmediatePropagation"in e&&e.stopImmediatePropagation()}get returnValue(){return super.returnValue}set returnValue(e){super.returnValue=e;let{original:n}=E(this);"returnValue"in n&&(n.returnValue=e)}preventDefault(){super.preventDefault();let{original:e}=E(this);"preventDefault"in e&&e.preventDefault()}get timeStamp(){let{original:e}=E(this);return"timeStamp"in e?e.timeStamp:super.timeStamp}},ue=new WeakMap;function E(t){let e=ue.get(t);return j(e!=null,"'this' is expected an Event object, but got",t),e}var A=new WeakMap;A.set(Object.prototype,w);typeof m!="undefined"&&typeof m.Event!="undefined"&&A.set(m.Event.prototype,w);function le(t){let e=Object.getPrototypeOf(t);if(e==null)return w;let n=A.get(e);return n==null&&(n=Je(le(e),e),A.set(e,n)),n}function Je(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=E(this).original,i=r[e];return typeof i=="function"?i.bind(r):i},set(r){let i=E(this).original;i[e]=r},configurable:n.configurable,enumerable:n.enumerable}}function Qe(t,e,n,r,i,a){return{callback:t,flags:(e?1:0)|(n?2:0)|(r?4:0),signal:i,signalListener:a}}function et(t){t.flags|=8}function he(t){return(t.flags&1)===1}function pe(t){return(t.flags&2)===2}function de(t){return(t.flags&4)===4}function tt(t){return(t.flags&8)===8}function nt({callback:t},e,n){try{typeof t=="function"?t.call(e,n):typeof t.handleEvent=="function"&&t.handleEvent(n)}catch(r){We(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 rt(t,e,n,r,i,a){let o;a&&(o=me.bind(null,t,e,n),a.addEventListener("abort",o));let s=Qe(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 et(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 it(){return Object.create(null)}function st(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 k=class{constructor(){be.set(this,it())}addEventListener(e,n,r){let i=M(this),{callback:a,capture:o,once:s,passive:c,signal:h,type:p}=at(e,n,r);if(a==null||(h==null?void 0:h.aborted))return;let d=st(i,p),y=fe(d,a,o);if(y!==-1){ut(d.listeners[y],c,s,h);return}rt(d,a,o,c,s,h)}removeEventListener(e,n,r){let i=M(this),{callback:a,capture:o,type:s}=ot(e,n,r),c=i[s];a!=null&&c&&me(c,a,o)}dispatchEvent(e){let n=M(this)[String(e.type)];if(n==null)return!0;let r=e instanceof b?e:w.wrap(e),i=l(r,"event");if(i.dispatchFlag)throw Ze("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 c=o[s];if(!tt(c)&&(de(c)&&ge(n,s,!a)&&(s-=1),i.inPassiveListenerFlag=pe(c),nt(c,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 M(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 at(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 ot(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 ut(t,e,n,r){Ke.warn(he(t)?"capture":"bubble",t.callback),pe(t)!==e&&N.warn("passive"),de(t)!==n&&N.warn("once"),t.signal!==r&&N.warn("signal")}var X=Object.getOwnPropertyNames(k.prototype);for(let t=0;t<X.length;++t)X[t]!=="constructor"&&Object.defineProperty(k.prototype,X[t],{enumerable:!0});typeof m!="undefined"&&typeof m.EventTarget!="undefined"&&Object.setPrototypeOf(k.prototype,m.EventTarget.prototype);var Oe=He(Ae()),Ie=30720,B=512e3,x=256,O=(t,{minChunkSize:e=x,maxChunkSize:n=B}={})=>t==null||typeof t=="number"&&t>=256&&t%256===0&&t>=e&&t<=n,I=(t,{minChunkSize:e=x,maxChunkSize:n=B}={})=>new TypeError(`chunkSize ${t} must be a positive number in multiples of 256, between ${e} and ${n}`),L=class{constructor(e,n={}){this.readableStream=e;var r,i,a;if(!O(n.defaultChunkSize,n))throw I(n.defaultChunkSize,n);this.defaultChunkSize=(r=n.defaultChunkSize)!=null?r:Ie,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(!O(e,this))throw I(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}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}}}}finally{if(e){let r=e;e=void 0,yield r}n.releaseLock();return}}},St=[200,201,202,204,308],Le=[408,502,503,504],Be=(t,e)=>!!t&&St.includes(t.statusCode),kt=(t,{retryCodes:e=Le})=>!t||e.includes(t.statusCode),vt=(t,e)=>e.attemptCount>=e.attempts||!(Be(t)||kt(t,e)),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||Le,this.dynamicChunkSize=e.dynamicChunkSize||!1,this.maxFileBytes=(e.maxFileSize||0)*1024,this.chunkCount=0,this.attemptCount=0,this.offline=!1,this._paused=!1,this.success=!1,this.nextChunkRangeStart=0,this.chunkedStreamIterable=new L(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 k,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=!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:Ie}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 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())}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(!O(this.chunkSize,{maxChunkSize:this.maxChunkSize,minChunkSize:this.minChunkSize}))throw I(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 p;let a=this.totalChunks-this.chunkCount,o=(this.file.size-this.nextChunkRangeStart)/this.file.size/a,s=this.nextChunkRangeStart/this.file.size,h=i.loaded/((p=i.total)!=null?p:this.chunkByteSize)*o;this.dispatch("progress",Math.min((s+h)*100,100))}};return new Promise((r,i)=>{this.currentXhr=(0,Oe.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,c)=>{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,c)=>(this.dispatch("error",{message:`Server responded with ${s.statusCode}. Stopping upload.`,chunk:this.chunkCount,attempts:this.attemptCount}),!1),i=async(s,c)=>(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}),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{}let o={retryCodes:this.retryCodes,attemptCount:this.attemptCount,attempts:this.attempts};return Be(a,o)?n(a,e):vt(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.success=!!n,this.success&&r&&this.dispatch("success"),!r)return}}},wt=R.createUpload;return je(Rt);})();
var UpChunk=(()=>{var Ue=Object.create;var _=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var De=Object.getPrototypeOf,Me=Object.prototype.hasOwnProperty;var T=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Xe=(t,e)=>{for(var n in e)_(t,n,{get:e[n],enumerable:!0})},G=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ne(e))!Me.call(t,i)&&i!==n&&_(t,i,{get:()=>e[i],enumerable:!(r=Fe(e,i))||r.enumerable});return t};var He=(t,e,n)=>(n=t!=null?Ue(De(t)):{},G(e||!t||!t.__esModule?_(n,"default",{value:t,enumerable:!0}):n,t)),je=t=>G(_({},"__esModule",{value:!0}),t);var Ee=T((_t,Ce)=>{var z;typeof window!="undefined"?z=window:typeof global!="undefined"?z=global:typeof self!="undefined"?z=self:z={};Ce.exports=z});var ke=T((Ot,Se)=>{Se.exports=ct;var lt=Object.prototype.toString;function ct(t){if(!t)return!1;var e=lt.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((At,ve)=>{var W=function(t){return t.replace(/^\s+|\s+$/g,"")},ht=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:ht(e[o])?e[o].push(s):e[o]=[e[o],s]}return e}});var Te=T((It,Re)=>{Re.exports=dt;var pt=Object.prototype.hasOwnProperty;function dt(){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((Lt,$)=>{"use strict";var ze=Ee(),ft=ke(),mt=we(),gt=Te();$.exports=C;$.exports.default=C;C.XMLHttpRequest=ze.XMLHttpRequest||Et;C.XDomainRequest="withCredentials"in new C.XMLHttpRequest?C.XMLHttpRequest:ze.XDomainRequest;bt(["get","put","post","patch","head","delete"],function(t){C[t==="delete"?"del":t]=function(e,n,r){return n=Pe(e,n,r),n.method=t.toUpperCase(),_e(n)}});function bt(t,e){for(var n=0;n<t.length;n++)e(t[n])}function yt(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function Pe(t,e,n){var r=t;return ft(e)?(n=e,typeof t=="string"&&(r={uri:t})):r=gt(e,{uri:t}),r.callback=n,r}function C(t,e,n){return e=Pe(t,e,n),_e(e)}function _e(t){if(typeof t.callback=="undefined")throw new Error("callback argument missing");var e=!1,n=function(S,P,xe){e||(e=!0,t.callback(S,P,xe))};function r(){s.readyState===4&&setTimeout(o,0)}function i(){var u=void 0;if(s.response?u=s.response:u=s.responseText||Ct(s),V)try{u=JSON.parse(u)}catch{}return u}function a(u){return clearTimeout(F),u instanceof Error||(u=new Error(""+(u||"Unknown XMLHttpRequest Error"))),u.statusCode=0,n(u,q)}function o(){if(!h){var u;clearTimeout(F),t.useXDR&&s.status===void 0?u=200:u=s.status===1223?204:s.status;var S=q,P=null;return u!==0?(S={body:i(),statusCode:u,method:d,headers:{},url:p,rawRequest:s},s.getAllResponseHeaders&&(S.headers=mt(s.getAllResponseHeaders()))):P=new Error("Internal XMLHttpRequest Error"),n(P,S,S.body)}}var s=t.xhr||null;s||(t.cors||t.useXDR?s=new C.XDomainRequest:s=new C.XMLHttpRequest);var c,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,F,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&&(F=setTimeout(function(){if(!h){h=!0,s.abort("timeout");var u=new Error("XMLHttpRequest timeout");u.code="ETIMEDOUT",a(u)}},t.timeout)),s.setRequestHeader)for(c in f)f.hasOwnProperty(c)&&s.setRequestHeader(c,f[c]);else if(t.headers&&!yt(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 Ct(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 Rt={};Xe(Rt,{ChunkedStreamIterable:()=>L,UpChunk:()=>R,createUpload:()=>wt,getChunkSizeError:()=>I,isValidChunkSize:()=>A});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 We(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{}}},$e=new g("W01","Unable to initialize event under dispatching."),Ve=new g("W02","Assigning any falsy value to 'cancelBubble' property has no effect."),qe=new g("W03","Assigning any truthy value to 'returnValue' property has no effect."),Ge=new g("W04","Unable to preventDefault on non-cancelable events."),Ye=new g("W05","Unable to preventDefault inside passive event listener invocation."),Ke=new g("W06","An event listener wasn't added because it has been added already: %o, %o"),N=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"),zt=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 l(this).type}get target(){return l(this).target}get srcElement(){return l(this).target}get currentTarget(){return l(this).currentTarget}composedPath(){let e=l(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 l(this).dispatchFlag?2:0}stopPropagation(){l(this).stopPropagationFlag=!0}get cancelBubble(){return l(this).stopPropagationFlag}set cancelBubble(e){e?l(this).stopPropagationFlag=!0:Ve.warn()}stopImmediatePropagation(){let e=l(this);e.stopPropagationFlag=e.stopImmediatePropagationFlag=!0}get bubbles(){return l(this).bubbles}get cancelable(){return l(this).cancelable}get returnValue(){return!l(this).canceledFlag}set returnValue(e){e?qe.warn():ne(l(this))}preventDefault(){ne(l(this))}get defaultPrevented(){return l(this).canceledFlag}get composed(){return l(this).composed}get isTrusted(){return!1}get timeStamp(){return l(this).timeStamp}initEvent(e,n=!1,r=!1){let i=l(this);if(i.dispatchFlag){$e.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 l(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){Ye.warn();return}if(!t.cancelable){Ge.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 Ze(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}=E(this);"stopPropagation"in e&&e.stopPropagation()}get cancelBubble(){return super.cancelBubble}set cancelBubble(e){super.cancelBubble=e;let{original:n}=E(this);"cancelBubble"in n&&(n.cancelBubble=e)}stopImmediatePropagation(){super.stopImmediatePropagation();let{original:e}=E(this);"stopImmediatePropagation"in e&&e.stopImmediatePropagation()}get returnValue(){return super.returnValue}set returnValue(e){super.returnValue=e;let{original:n}=E(this);"returnValue"in n&&(n.returnValue=e)}preventDefault(){super.preventDefault();let{original:e}=E(this);"preventDefault"in e&&e.preventDefault()}get timeStamp(){let{original:e}=E(this);return"timeStamp"in e?e.timeStamp:super.timeStamp}},ue=new WeakMap;function E(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=Je(le(e),e),O.set(e,n)),n}function Je(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=E(this).original,i=r[e];return typeof i=="function"?i.bind(r):i},set(r){let i=E(this).original;i[e]=r},configurable:n.configurable,enumerable:n.enumerable}}function Qe(t,e,n,r,i,a){return{callback:t,flags:(e?1:0)|(n?2:0)|(r?4:0),signal:i,signalListener:a}}function et(t){t.flags|=8}function he(t){return(t.flags&1)===1}function pe(t){return(t.flags&2)===2}function de(t){return(t.flags&4)===4}function tt(t){return(t.flags&8)===8}function nt({callback:t},e,n){try{typeof t=="function"?t.call(e,n):typeof t.handleEvent=="function"&&t.handleEvent(n)}catch(r){We(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 rt(t,e,n,r,i,a){let o;a&&(o=me.bind(null,t,e,n),a.addEventListener("abort",o));let s=Qe(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 et(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 it(){return Object.create(null)}function st(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 k=class{constructor(){be.set(this,it())}addEventListener(e,n,r){let i=M(this),{callback:a,capture:o,once:s,passive:c,signal:h,type:p}=at(e,n,r);if(a==null||(h==null?void 0:h.aborted))return;let d=st(i,p),y=fe(d,a,o);if(y!==-1){ut(d.listeners[y],c,s,h);return}rt(d,a,o,c,s,h)}removeEventListener(e,n,r){let i=M(this),{callback:a,capture:o,type:s}=ot(e,n,r),c=i[s];a!=null&&c&&me(c,a,o)}dispatchEvent(e){let n=M(this)[String(e.type)];if(n==null)return!0;let r=e instanceof b?e:w.wrap(e),i=l(r,"event");if(i.dispatchFlag)throw Ze("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 c=o[s];if(!tt(c)&&(de(c)&&ge(n,s,!a)&&(s-=1),i.inPassiveListenerFlag=pe(c),nt(c,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 M(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 at(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 ot(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 ut(t,e,n,r){Ke.warn(he(t)?"capture":"bubble",t.callback),pe(t)!==e&&N.warn("passive"),de(t)!==n&&N.warn("once"),t.signal!==r&&N.warn("signal")}var X=Object.getOwnPropertyNames(k.prototype);for(let t=0;t<X.length;++t)X[t]!=="constructor"&&Object.defineProperty(k.prototype,X[t],{enumerable:!0});typeof m!="undefined"&&typeof m.EventTarget!="undefined"&&Object.setPrototypeOf(k.prototype,m.EventTarget.prototype);var Ae=He(Oe()),Ie=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,I=(t,{minChunkSize:e=x,maxChunkSize:n=B}={})=>new TypeError(`chunkSize ${t} must be a positive number in multiples of 256, between ${e} and ${n}`),L=class{constructor(e,n={}){this.readableStream=e;var r,i,a;if(!A(n.defaultChunkSize,n))throw I(n.defaultChunkSize,n);this.defaultChunkSize=(r=n.defaultChunkSize)!=null?r:Ie,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 I(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}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}}}}finally{if(e){let r=e;e=void 0,yield r}n.releaseLock();return}}},St=[200,201,202,204,308],Le=[408,502,503,504],Be=(t,e)=>!!t&&St.includes(t.statusCode),kt=(t,{retryCodes:e=Le})=>!t||e.includes(t.statusCode),vt=(t,e)=>e.attemptCount>=e.attempts||!(Be(t)||kt(t,e)),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||Le,this.dynamicChunkSize=e.dynamicChunkSize||!1,this.maxFileBytes=(e.maxFileSize||0)*1024,this.chunkCount=0,this.attemptCount=0,this.offline=!1,this._paused=!1,this.success=!1,this.nextChunkRangeStart=0,this.chunkedStreamIterable=new L(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 k,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=!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:Ie}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 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())}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 I(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 p;let a=this.totalChunks-this.chunkCount,o=(this.file.size-this.nextChunkRangeStart)/this.file.size/a,s=this.nextChunkRangeStart/this.file.size,h=i.loaded/((p=i.total)!=null?p:this.chunkByteSize)*o;this.dispatch("progress",Math.min((s+h)*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,c)=>{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,c)=>(this.dispatch("error",{message:`Server responded with ${s.statusCode}. Stopping upload.`,chunk:this.chunkCount,attempts:this.attemptCount}),!1),i=async(s,c)=>(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}),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{}let o={retryCodes:this.retryCodes,attemptCount:this.attemptCount,attempts:this.attempts};return Be(a,o)?n(a,e):vt(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.success=!!n,this.success&&r&&this.dispatch("success"),!r)return}}};function wt(t){return R.createUpload(t)}return je(Rt);})();
//# sourceMappingURL=upchunk.js.map
{
"name": "@mux/upchunk",
"version": "3.2.0",
"version": "3.2.1",
"description": "Dead simple chunked file uploads using Fetch",

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

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

```
<script src="https://unpkg.com/@mux/upchunk@2"></script>
<script src="https://unpkg.com/@mux/upchunk@3"></script>
```

@@ -44,0 +44,0 @@

@@ -659,2 +659,4 @@ import { EventTarget, Event } from 'event-target-shim';

export const createUpload = UpChunk.createUpload;
export function createUpload(options: UpChunkOptions) {
return UpChunk.createUpload(options);
}

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