@mux/mux-uploader
Advanced tools
Comparing version
"use strict";(()=>{var zt=Object.defineProperty;var Ne=e=>{throw TypeError(e)};var Pt=(e,t)=>{for(var r in t)zt(e,r,{get:t[r],enumerable:!0})};var je=(e,t,r)=>t.has(e)||Ne("Cannot "+r);var i=(e,t,r)=>(je(e,t,"read from private field"),r?r.call(e):t.get(e)),c=(e,t,r)=>t.has(e)?Ne("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),f=(e,t,r,n)=>(je(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r);var we={};Pt(we,{ProgressTypes:()=>F});var F={BAR:"bar",RADIAL:"radial",PERCENTAGE:"percentage"};var H=class{addEventListener(){}removeEventListener(){}dispatchEvent(t){return!0}};if(typeof DocumentFragment=="undefined"){class e extends H{}globalThis.DocumentFragment=e}var K=class extends H{},xe=class extends H{},Ot={get(e){},define(e,t,r){},getName(e){return null},upgrade(e){},whenDefined(e){return Promise.resolve(K)}},Y,Ae=class{constructor(t,r={}){c(this,Y);f(this,Y,r==null?void 0:r.detail)}get detail(){return i(this,Y)}initCustomEvent(){}};Y=new WeakMap;function Ut(e,t){return new K}var $e={document:{createElement:Ut},DocumentFragment,customElements:Ot,CustomEvent:Ae,EventTarget:H,HTMLElement:K,HTMLVideoElement:xe},We=typeof window=="undefined"||typeof globalThis.customElements=="undefined",d=We?$e:globalThis,v=We?$e.document:globalThis.document;var Bt=Object.create,tt=Object.defineProperty,It=Object.getOwnPropertyDescriptor,rt=Object.getOwnPropertyNames,Dt=Object.getPrototypeOf,Ft=Object.prototype.hasOwnProperty,Q=(e,t)=>function(){return t||(0,e[rt(e)[0]])((t={exports:{}}).exports,t),t.exports},Ht=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of rt(t))!Ft.call(e,s)&&s!==r&&tt(e,s,{get:()=>t[s],enumerable:!(n=It(t,s))||n.enumerable});return e},Nt=(e,t,r)=>(r=e!=null?Bt(Dt(e)):{},Ht(t||!e||!e.__esModule?tt(r,"default",{value:e,enumerable:!0}):r,e)),jt=Q({"node_modules/global/window.js"(e,t){var r;typeof window!="undefined"?r=window:typeof global!="undefined"?r=global:typeof self!="undefined"?r=self:r={},t.exports=r}}),$t=Q({"node_modules/is-function/index.js"(e,t){t.exports=n;var r=Object.prototype.toString;function n(s){if(!s)return!1;var o=r.call(s);return o==="[object Function]"||typeof s=="function"&&o!=="[object RegExp]"||typeof window!="undefined"&&(s===window.setTimeout||s===window.alert||s===window.confirm||s===window.prompt)}}}),Wt=Q({"node_modules/parse-headers/parse-headers.js"(e,t){var r=function(s){return s.replace(/^\s+|\s+$/g,"")},n=function(s){return Object.prototype.toString.call(s)==="[object Array]"};t.exports=function(s){if(!s)return{};for(var o={},l=r(s).split(` | ||
`),u=0;u<l.length;u++){var p=l[u],y=p.indexOf(":"),E=r(p.slice(0,y)).toLowerCase(),S=r(p.slice(y+1));typeof o[E]=="undefined"?o[E]=S:n(o[E])?o[E].push(S):o[E]=[o[E],S]}return o}}}),Xt=Q({"node_modules/xtend/immutable.js"(e,t){t.exports=n;var r=Object.prototype.hasOwnProperty;function n(){for(var s={},o=0;o<arguments.length;o++){var l=arguments[o];for(var u in l)r.call(l,u)&&(s[u]=l[u])}return s}}}),qt=Q({"node_modules/xhr/index.js"(e,t){"use strict";var r=jt(),n=$t(),s=Wt(),o=Xt();t.exports=y,t.exports.default=y,y.XMLHttpRequest=r.XMLHttpRequest||ye,y.XDomainRequest="withCredentials"in new y.XMLHttpRequest?y.XMLHttpRequest:r.XDomainRequest,l(["get","put","post","patch","head","delete"],function(a){y[a==="delete"?"del":a]=function(k,C,U){return C=p(k,C,U),C.method=a.toUpperCase(),E(C)}});function l(a,k){for(var C=0;C<a.length;C++)k(a[C])}function u(a){for(var k in a)if(a.hasOwnProperty(k))return!1;return!0}function p(a,k,C){var U=a;return n(k)?(C=k,typeof a=="string"&&(U={uri:a})):U=o(k,{uri:a}),U.callback=C,U}function y(a,k,C){return k=p(a,k,C),E(k)}function E(a){if(typeof a.callback=="undefined")throw new Error("callback argument missing");var k=!1,C=function(D,ae,Mt){k||(k=!0,a.callback(D,ae,Mt))};function U(){h.readyState===4&&setTimeout(De,0)}function _t(){var g=void 0;if(h.response?g=h.response:g=h.responseText||S(h),Fe)try{g=JSON.parse(g)}catch{}return g}function Ee(g){return clearTimeout(Se),g instanceof Error||(g=new Error(""+(g||"Unknown XMLHttpRequest Error"))),g.statusCode=0,C(g,He)}function De(){if(!oe){var g;clearTimeout(Se),a.useXDR&&h.status===void 0?g=200:g=h.status===1223?204:h.status;var D=He,ae=null;return g!==0?(D={body:_t(),statusCode:g,method:V,headers:{},url:ve,rawRequest:h},h.getAllResponseHeaders&&(D.headers=s(h.getAllResponseHeaders()))):ae=new Error("Internal XMLHttpRequest Error"),C(ae,D,D.body)}}var h=a.xhr||null;h||(a.cors||a.useXDR?h=new y.XDomainRequest:h=new y.XMLHttpRequest);var ie,oe,ve=h.url=a.uri||a.url,V=h.method=a.method||"GET",ke=a.body||a.data,M=h.headers=a.headers||{},Ce=!!a.sync,Fe=!1,Se,He={body:void 0,headers:{},statusCode:0,method:V,url:ve,rawRequest:h};if("json"in a&&a.json!==!1&&(Fe=!0,M.accept||M.Accept||(M.Accept="application/json"),V!=="GET"&&V!=="HEAD"&&(M["content-type"]||M["Content-Type"]||(M["Content-Type"]="application/json"),ke=JSON.stringify(a.json===!0?ke:a.json))),h.onreadystatechange=U,h.onload=De,h.onerror=Ee,h.onprogress=function(){},h.onabort=function(){oe=!0},h.ontimeout=Ee,h.open(V,ve,!Ce,a.username,a.password),Ce||(h.withCredentials=!!a.withCredentials),!Ce&&a.timeout>0&&(Se=setTimeout(function(){if(!oe){oe=!0,h.abort("timeout");var g=new Error("XMLHttpRequest timeout");g.code="ETIMEDOUT",Ee(g)}},a.timeout)),h.setRequestHeader)for(ie in M)M.hasOwnProperty(ie)&&h.setRequestHeader(ie,M[ie]);else if(a.headers&&!u(a.headers))throw new Error("Headers cannot be set on an XDomainRequest object");return"responseType"in a&&(h.responseType=a.responseType),"beforeSend"in a&&typeof a.beforeSend=="function"&&a.beforeSend(h),h.send(ke||null),h}function S(a){try{if(a.responseType==="document")return a.responseXML;var k=a.responseXML&&a.responseXML.documentElement.nodeName==="parsererror";if(a.responseType===""&&!k)return a.responseXML}catch{}return null}function ye(){}}});function ze(e,t,...r){if(!e)throw new TypeError(nt(t,r))}function nt(e,t){let r=0;return e.replace(/%[os]/gu,()=>st(t[r++]))}function st(e){return typeof e!="object"||e===null?String(e):Object.prototype.toString.call(e)}var Xe;function Gt(e){try{let t=e instanceof Error?e:new Error(st(e));if(Xe){Xe(t);return}if(typeof dispatchEvent=="function"&&typeof ErrorEvent=="function")dispatchEvent(new ErrorEvent("error",{error:t,message:t.message}));else if(typeof process!="undefined"&&typeof process.emit=="function"){process.emit("uncaughtException",t);return}console.error(t)}catch{}}var L=typeof window!="undefined"?window:typeof self!="undefined"?self:typeof global!="undefined"?global:typeof globalThis!="undefined"?globalThis:void 0,qe,z=class{constructor(e,t){this.code=e,this.message=t}warn(...e){var t;try{if(qe){qe({...this,args:e});return}let r=((t=new Error().stack)!==null&&t!==void 0?t:"").replace(/^(?:.+?\n){2}/gu,` | ||
`);console.warn(this.message,...e,r)}catch{}}},Vt=new z("W01","Unable to initialize event under dispatching."),Kt=new z("W02","Assigning any falsy value to 'cancelBubble' property has no effect."),Yt=new z("W03","Assigning any truthy value to 'returnValue' property has no effect."),Zt=new z("W04","Unable to preventDefault on non-cancelable events."),Jt=new z("W05","Unable to preventDefault inside passive event listener invocation."),Qt=new z("W06","An event listener wasn't added because it has been added already: %o, %o"),Te=new z("W07","The %o option value was abandoned because the event listener wasn't added as duplicated."),Ge=new z("W08","The 'callback' argument must be a function or an object that has 'handleEvent' method: %o"),zr=new z("W09","Event attribute handler must be a function: %o"),P=class{static get NONE(){return Ve}static get CAPTURING_PHASE(){return Ke}static get AT_TARGET(){return Ye}static get BUBBLING_PHASE(){return Ze}constructor(e,t){Object.defineProperty(this,"isTrusted",{value:!1,enumerable:!0});let r=t!=null?t:{};Me.set(this,{type:String(e),bubbles:!!r.bubbles,cancelable:!!r.cancelable,composed:!!r.composed,target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1,inPassiveListenerFlag:!1,dispatchFlag:!1,timeStamp:Date.now()})}get type(){return m(this).type}get target(){return m(this).target}get srcElement(){return m(this).target}get currentTarget(){return m(this).currentTarget}composedPath(){let e=m(this).currentTarget;return e?[e]:[]}get NONE(){return Ve}get CAPTURING_PHASE(){return Ke}get AT_TARGET(){return Ye}get BUBBLING_PHASE(){return Ze}get eventPhase(){return m(this).dispatchFlag?2:0}stopPropagation(){m(this).stopPropagationFlag=!0}get cancelBubble(){return m(this).stopPropagationFlag}set cancelBubble(e){e?m(this).stopPropagationFlag=!0:Kt.warn()}stopImmediatePropagation(){let e=m(this);e.stopPropagationFlag=e.stopImmediatePropagationFlag=!0}get bubbles(){return m(this).bubbles}get cancelable(){return m(this).cancelable}get returnValue(){return!m(this).canceledFlag}set returnValue(e){e?Yt.warn():Je(m(this))}preventDefault(){Je(m(this))}get defaultPrevented(){return m(this).canceledFlag}get composed(){return m(this).composed}get isTrusted(){return!1}get timeStamp(){return m(this).timeStamp}initEvent(e,t=!1,r=!1){let n=m(this);if(n.dispatchFlag){Vt.warn();return}Me.set(this,{...n,type:String(e),bubbles:!!t,cancelable:!!r,target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1})}},Ve=0,Ke=1,Ye=2,Ze=3,Me=new WeakMap;function m(e,t="this"){let r=Me.get(e);return ze(r!=null,"'%s' must be an object that Event constructor created, but got another one: %o",t,e),r}function Je(e){if(e.inPassiveListenerFlag){Jt.warn();return}if(!e.cancelable){Zt.warn();return}e.canceledFlag=!0}Object.defineProperty(P,"NONE",{enumerable:!0});Object.defineProperty(P,"CAPTURING_PHASE",{enumerable:!0});Object.defineProperty(P,"AT_TARGET",{enumerable:!0});Object.defineProperty(P,"BUBBLING_PHASE",{enumerable:!0});var Le=Object.getOwnPropertyNames(P.prototype);for(let e=0;e<Le.length;++e)Le[e]!=="constructor"&&Object.defineProperty(P.prototype,Le[e],{enumerable:!0});typeof L!="undefined"&&typeof L.Event!="undefined"&&Object.setPrototypeOf(P.prototype,L.Event.prototype);function er(e){return L.DOMException?new L.DOMException(e,"InvalidStateError"):(N==null&&(N=class it extends Error{constructor(r){super(r),Error.captureStackTrace&&Error.captureStackTrace(this,it)}get code(){return 11}get name(){return"InvalidStateError"}},Object.defineProperties(N.prototype,{code:{enumerable:!0},name:{enumerable:!0}}),et(N),et(N.prototype)),new N(e))}var N,Qe={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 et(e){let t=Object.keys(Qe);for(let r=0;r<t.length;++r){let n=t[r],s=Qe[n];Object.defineProperty(e,n,{get(){return s},configurable:!0,enumerable:!0})}}var ue=class extends P{static wrap(e){return new(at(e))(e)}constructor(e){super(e.type,{bubbles:e.bubbles,cancelable:e.cancelable,composed:e.composed}),e.cancelBubble&&super.stopPropagation(),e.defaultPrevented&&super.preventDefault(),ot.set(this,{original:e});let t=Object.keys(e);for(let r=0;r<t.length;++r){let n=t[r];n in this||Object.defineProperty(this,n,lt(e,n))}}stopPropagation(){super.stopPropagation();let{original:e}=B(this);"stopPropagation"in e&&e.stopPropagation()}get cancelBubble(){return super.cancelBubble}set cancelBubble(e){super.cancelBubble=e;let{original:t}=B(this);"cancelBubble"in t&&(t.cancelBubble=e)}stopImmediatePropagation(){super.stopImmediatePropagation();let{original:e}=B(this);"stopImmediatePropagation"in e&&e.stopImmediatePropagation()}get returnValue(){return super.returnValue}set returnValue(e){super.returnValue=e;let{original:t}=B(this);"returnValue"in t&&(t.returnValue=e)}preventDefault(){super.preventDefault();let{original:e}=B(this);"preventDefault"in e&&e.preventDefault()}get timeStamp(){let{original:e}=B(this);return"timeStamp"in e?e.timeStamp:super.timeStamp}},ot=new WeakMap;function B(e){let t=ot.get(e);return ze(t!=null,"'this' is expected an Event object, but got",e),t}var le=new WeakMap;le.set(Object.prototype,ue);typeof L!="undefined"&&typeof L.Event!="undefined"&&le.set(L.Event.prototype,ue);function at(e){let t=Object.getPrototypeOf(e);if(t==null)return ue;let r=le.get(t);return r==null&&(r=tr(at(t),t),le.set(t,r)),r}function tr(e,t){class r extends e{}let n=Object.keys(t);for(let s=0;s<n.length;++s)Object.defineProperty(r.prototype,n[s],lt(t,n[s]));return r}function lt(e,t){let r=Object.getOwnPropertyDescriptor(e,t);return{get(){let n=B(this).original,s=n[t];return typeof s=="function"?s.bind(n):s},set(n){let s=B(this).original;s[t]=n},configurable:r.configurable,enumerable:r.enumerable}}function rr(e,t,r,n,s,o){return{callback:e,flags:(t?1:0)|(r?2:0)|(n?4:0),signal:s,signalListener:o}}function nr(e){e.flags|=8}function ut(e){return(e.flags&1)===1}function dt(e){return(e.flags&2)===2}function ht(e){return(e.flags&4)===4}function sr(e){return(e.flags&8)===8}function ir({callback:e},t,r){try{typeof e=="function"?e.call(t,r):typeof e.handleEvent=="function"&&e.handleEvent(r)}catch(n){Gt(n)}}function pt({listeners:e},t,r){for(let n=0;n<e.length;++n)if(e[n].callback===t&&ut(e[n])===r)return n;return-1}function or(e,t,r,n,s,o){let l;o&&(l=ct.bind(null,e,t,r),o.addEventListener("abort",l));let u=rr(t,r,n,s,o,l);return e.cow?(e.cow=!1,e.listeners=[...e.listeners,u]):e.listeners.push(u),u}function ct(e,t,r){let n=pt(e,t,r);return n!==-1?ft(e,n):!1}function ft(e,t,r=!1){let n=e.listeners[t];return nr(n),n.signal&&n.signal.removeEventListener("abort",n.signalListener),e.cow&&!r?(e.cow=!1,e.listeners=e.listeners.filter((s,o)=>o!==t),!1):(e.listeners.splice(t,1),!0)}function ar(){return Object.create(null)}function lr(e,t){var r;return(r=e[t])!==null&&r!==void 0?r:e[t]={attrCallback:void 0,attrListener:void 0,cow:!1,listeners:[]}}var de=class{constructor(){gt.set(this,ar())}addEventListener(e,t,r){let n=Re(this),{callback:s,capture:o,once:l,passive:u,signal:p,type:y}=ur(e,t,r);if(s==null||p!=null&&p.aborted)return;let E=lr(n,y),S=pt(E,s,o);if(S!==-1){hr(E.listeners[S],u,l,p);return}or(E,s,o,u,l,p)}removeEventListener(e,t,r){let n=Re(this),{callback:s,capture:o,type:l}=dr(e,t,r),u=n[l];s!=null&&u&&ct(u,s,o)}dispatchEvent(e){let t=Re(this)[String(e.type)];if(t==null)return!0;let r=e instanceof P?e:ue.wrap(e),n=m(r,"event");if(n.dispatchFlag)throw er("This event has been in dispatching.");if(n.dispatchFlag=!0,n.target=n.currentTarget=this,!n.stopPropagationFlag){let{cow:s,listeners:o}=t;t.cow=!0;for(let l=0;l<o.length;++l){let u=o[l];if(!sr(u)&&(ht(u)&&ft(t,l,!s)&&(l-=1),n.inPassiveListenerFlag=dt(u),ir(u,this,r),n.inPassiveListenerFlag=!1,n.stopImmediatePropagationFlag))break}s||(t.cow=!1)}return n.target=null,n.currentTarget=null,n.stopImmediatePropagationFlag=!1,n.stopPropagationFlag=!1,n.dispatchFlag=!1,!n.canceledFlag}},gt=new WeakMap;function Re(e,t="this"){let r=gt.get(e);return ze(r!=null,"'%s' must be an object that EventTarget constructor created, but got another one: %o",t,e),r}function ur(e,t,r){var n;return mt(t),typeof r=="object"&&r!==null?{type:String(e),callback:t!=null?t:void 0,capture:!!r.capture,passive:!!r.passive,once:!!r.once,signal:(n=r.signal)!==null&&n!==void 0?n:void 0}:{type:String(e),callback:t!=null?t:void 0,capture:!!r,passive:!1,once:!1,signal:void 0}}function dr(e,t,r){return mt(t),typeof r=="object"&&r!==null?{type:String(e),callback:t!=null?t:void 0,capture:!!r.capture}:{type:String(e),callback:t!=null?t:void 0,capture:!!r}}function mt(e){if(!(typeof e=="function"||typeof e=="object"&&e!==null&&typeof e.handleEvent=="function")){if(e==null||typeof e=="object"){Ge.warn(e);return}throw new TypeError(nt(Ge.message,[e]))}}function hr(e,t,r,n){Qt.warn(ut(e)?"capture":"bubble",e.callback),dt(e)!==t&&Te.warn("passive"),ht(e)!==r&&Te.warn("once"),e.signal!==n&&Te.warn("signal")}var _e=Object.getOwnPropertyNames(de.prototype);for(let e=0;e<_e.length;++e)_e[e]!=="constructor"&&Object.defineProperty(de.prototype,_e[e],{enumerable:!0});typeof L!="undefined"&&typeof L.EventTarget!="undefined"&&Object.setPrototypeOf(de.prototype,L.EventTarget.prototype);var pr=Nt(qt()),Pe=30720,ee=512e3,te=256,Z=(e,{minChunkSize:t=te,maxChunkSize:r=ee}={})=>e==null||typeof e=="number"&&e>=256&&e%256===0&&e>=t&&e<=r,J=(e,{minChunkSize:t=te,maxChunkSize:r=ee}={})=>new TypeError(`chunkSize ${e} must be a positive number in multiples of 256, between ${t} and ${r}`),cr=class{constructor(e,t={}){this.readableStream=e;var r,n,s;if(!Z(t.defaultChunkSize,t))throw J(t.defaultChunkSize,t);this.defaultChunkSize=(r=t.defaultChunkSize)!=null?r:Pe,this.minChunkSize=(n=t.minChunkSize)!=null?n:te,this.maxChunkSize=(s=t.maxChunkSize)!=null?s:ee}get chunkSize(){var e;return(e=this._chunkSize)!=null?e:this.defaultChunkSize}set chunkSize(e){if(!Z(e,this))throw J(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}get error(){return this._error}async*[Symbol.asyncIterator](){let e,t=this.readableStream.getReader();try{for(;;){let{done:r,value:n}=await t.read();if(r){if(e){let o=e;e=void 0,yield o}break}let s=n instanceof Uint8Array?new Blob([n],{type:"application/octet-stream"}):n;for(e=e?new Blob([e,s]):s;e;)if(e.size===this.chunkByteSize){let o=e;e=void 0,yield o;break}else{if(e.size<this.chunkByteSize)break;{let o=e.slice(0,this.chunkByteSize);e=e.slice(this.chunkByteSize),yield o}}}}catch(r){this._error=r}finally{if(e){let r=e;e=void 0,yield r}t.releaseLock();return}}},fr=class{constructor(e,t={}){this.file=e;var r,n,s;if(!Z(t.defaultChunkSize,t))throw J(t.defaultChunkSize,t);this.defaultChunkSize=(r=t.defaultChunkSize)!=null?r:Pe,this.minChunkSize=(n=t.minChunkSize)!=null?n:te,this.maxChunkSize=(s=t.maxChunkSize)!=null?s:ee}get chunkSize(){var e;return(e=this._chunkSize)!=null?e:this.defaultChunkSize}set chunkSize(e){if(!Z(e,this))throw J(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}get error(){return this._error}async*[Symbol.asyncIterator](){let e=new FileReader,t=0,r=()=>new Promise(n=>{if(t>=this.file.size){n(void 0);return}let s=Math.min(this.chunkByteSize,this.file.size-t);e.onload=()=>{e.result!==null?n(new Blob([e.result],{type:"application/octet-stream"})):n(void 0)},e.readAsArrayBuffer(this.file.slice(t,t+s))});try{for(;;){let n=await r();if(n)t+=n.size,yield n;else break}}catch(n){this._error=n}}},gr=[200,201,202,204,308],bt=[408,502,503,504],mr=[308],yt=(e,t)=>!!e&&gr.includes(e.statusCode),br=(e,{retryCodes:t=bt})=>!e||t.includes(e.statusCode),yr=(e,t)=>t.attemptCount>=t.attempts||!(yt(e)||br(e,t)),Er=(e,t)=>{var r;if(!e||!mr.includes(e.statusCode)||!((r=e.headers)!=null&&r.range))return!1;let n=e.headers.range.match(/bytes=(\d+)-(\d+)/);return n?parseInt(n[2],10)!==t.currentChunkEndByte:!1},Oe=class{static createUpload(e){return new Oe(e)}constructor(e){if(this.eventTarget=new de,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||bt,this.dynamicChunkSize=e.dynamicChunkSize||!1,this.maxFileBytes=(e.maxFileSize||0)*1024,this.chunkCount=0,this.attemptCount=0,this._offline=typeof window!="undefined"&&!window.navigator.onLine,this._paused=!1,this.success=!1,this.nextChunkRangeStart=0,e.useLargeFileWorkaround){let t=r=>{this.chunkedIterable.error&&(console.warn(`Unable to read file of size ${this.file.size} bytes via a ReadableStream. Falling back to in-memory FileReader!`),r.stopImmediatePropagation(),this.chunkedIterable=new fr(this.file,{...e,defaultChunkSize:e.chunkSize}),this.chunkedIterator=this.chunkedIterable[Symbol.asyncIterator](),this.getEndpoint().then(()=>{this.sendChunks()}),this.off("error",t))};this.on("error",t)}this.chunkedIterable=new cr(this.file.stream(),{...e,defaultChunkSize:e.chunkSize}),this.chunkedIterator=this.chunkedIterable[Symbol.asyncIterator](),this.totalChunks=Math.ceil(this.file.size/this.chunkByteSize),this.validateOptions(),this.getEndpoint().then(()=>this.sendChunks()),typeof window!="undefined"&&(window.addEventListener("online",()=>{this.offline&&(this._offline=!1,this.dispatch("online"),this.sendChunks())}),window.addEventListener("offline",()=>{this.offline||(this._offline=!0,this.dispatch("offline"))}))}get maxChunkSize(){var e,t;return(t=(e=this.chunkedIterable)==null?void 0:e.maxChunkSize)!=null?t:ee}get minChunkSize(){var e,t;return(t=(e=this.chunkedIterable)==null?void 0:e.minChunkSize)!=null?t:te}get chunkSize(){var e,t;return(t=(e=this.chunkedIterable)==null?void 0:e.chunkSize)!=null?t:Pe}set chunkSize(e){this.chunkedIterable.chunkSize=e}get chunkByteSize(){return this.chunkedIterable.chunkByteSize}get totalChunkSize(){return Math.ceil(this.file.size/this.chunkByteSize)}on(e,t){this.eventTarget.addEventListener(e,t)}once(e,t){this.eventTarget.addEventListener(e,t,{once:!0})}off(e,t){this.eventTarget.removeEventListener(e,t)}get offline(){return this._offline}get paused(){return this._paused}abort(){var e;this.pause(),(e=this.currentXhr)==null||e.abort()}pause(){this._paused=!0}resume(){this._paused&&(this._paused=!1,this.sendChunks())}get successfulPercentage(){return this.nextChunkRangeStart/this.file.size}dispatch(e,t){let r=new CustomEvent(e,{detail:t});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(!Z(this.chunkSize,{maxChunkSize:this.maxChunkSize,minChunkSize:this.minChunkSize}))throw J(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 t=r=>{r.upload.onprogress=n=>{var s;let o=this.totalChunks-this.chunkCount,l=(this.file.size-this.nextChunkRangeStart)/this.file.size/o,p=n.loaded/((s=n.total)!=null?s:this.chunkByteSize)*l;this.dispatch("progress",Math.min((this.successfulPercentage+p)*100,100))}};return new Promise((r,n)=>{this.currentXhr=(0,pr.default)({...e,beforeSend:t},(s,o)=>(this.currentXhr=void 0,s?n(s):r(o)))})}async sendChunk(e){let t=this.nextChunkRangeStart,r=t+e.size-1,s={...await(typeof this.headers=="function"?this.headers():this.headers),"Content-Type":this.file.type,"Content-Range":`bytes ${t}-${r}/${this.file.size}`};return this.dispatch("attempt",{chunkNumber:this.chunkCount,totalChunks:this.totalChunks,chunkSize:this.chunkSize}),this.xhrPromise({headers:s,url:this.endpointValue,method:this.method,body:e})}async sendChunkWithRetries(e){let t=async(l,u)=>{var p;let E=(new Date().getTime()-this.lastChunkStart.getTime())/1e3;if(this.dispatch("chunkSuccess",{chunk:this.chunkCount,chunkSize:this.chunkSize,attempts:this.attemptCount,timeInterval:E,response:l}),this.attemptCount=0,this.chunkCount=((p=this.chunkCount)!=null?p:0)+1,this.nextChunkRangeStart=this.nextChunkRangeStart+this.chunkByteSize,this.dynamicChunkSize){let S=this.chunkSize;E<10?S=Math.min(this.chunkSize*2,this.maxChunkSize):E>30&&(S=Math.max(this.chunkSize/2,this.minChunkSize)),this.chunkSize=Math.ceil(S/256)*256;let ye=(this.file.size-this.nextChunkRangeStart)/this.chunkByteSize;this.totalChunks=Math.ceil(this.chunkCount+ye)}return!0},r=async(l,u)=>(this.dispatch("progress",Math.min(this.successfulPercentage*100,100)),this.dispatch("error",{message:`Server responded with ${l.statusCode}. Stopping upload.`,chunk:this.chunkCount,attempts:this.attemptCount,response:l}),!1),n=async(l,u)=>(this.dispatch("attemptFailure",{message:`An error occured uploading chunk ${this.chunkCount}. ${this.attempts-this.attemptCount} retries left.`,chunkNumber:this.chunkCount,attemptsLeft:this.attempts-this.attemptCount,response:l}),new Promise(p=>{setTimeout(async()=>{if(this._paused||this.offline){this.pendingChunk=e,p(!1);return}let y=await this.sendChunkWithRetries(e);p(y)},this.delayBeforeAttempt*1e3)})),s;try{this.attemptCount=this.attemptCount+1,this.lastChunkStart=new Date,s=await this.sendChunk(e)}catch(l){typeof(l==null?void 0:l.statusCode)=="number"&&(s=l)}let o={retryCodes:this.retryCodes,attemptCount:this.attemptCount,attempts:this.attempts,currentChunkEndByte:this.nextChunkRangeStart+e.size-1};return Er(s,o)?n(s,e):yt(s,o)?t(s,e):yr(s,o)?r(s,e):n(s,e)}async sendChunks(){if(this.pendingChunk&&!(this._paused||this.offline)){let e=this.pendingChunk;this.pendingChunk=void 0;let t=await this.sendChunkWithRetries(e);this.success&&t&&this.dispatch("success")}for(;!(this.success||this._paused||this.offline);){let{value:e,done:t}=await this.chunkedIterator.next(),r=!e&&t;if(e&&(r=await this.sendChunkWithRetries(e)),this.chunkedIterable.error){r=!1,this.dispatch("error",{message:`Unable to read file of size ${this.file.size} bytes. Try loading from another browser.`});return}if(this.success=!!t,this.success&&r&&this.dispatch("success"),!r)return}}};var Et=(e,t)=>{if(!e)return null;let r=e.closest(t);return r||Et(e.getRootNode().host,t)},w=e=>{let t=e.getAttribute("mux-uploader");return t?document.getElementById(t):Et(e,"mux-uploader")};var vt=v.createElement("template");vt.innerHTML=` | ||
`);console.warn(this.message,...e,r)}catch{}}},Vt=new z("W01","Unable to initialize event under dispatching."),Kt=new z("W02","Assigning any falsy value to 'cancelBubble' property has no effect."),Yt=new z("W03","Assigning any truthy value to 'returnValue' property has no effect."),Zt=new z("W04","Unable to preventDefault on non-cancelable events."),Jt=new z("W05","Unable to preventDefault inside passive event listener invocation."),Qt=new z("W06","An event listener wasn't added because it has been added already: %o, %o"),Te=new z("W07","The %o option value was abandoned because the event listener wasn't added as duplicated."),Ge=new z("W08","The 'callback' argument must be a function or an object that has 'handleEvent' method: %o"),zr=new z("W09","Event attribute handler must be a function: %o"),P=class{static get NONE(){return Ve}static get CAPTURING_PHASE(){return Ke}static get AT_TARGET(){return Ye}static get BUBBLING_PHASE(){return Ze}constructor(e,t){Object.defineProperty(this,"isTrusted",{value:!1,enumerable:!0});let r=t!=null?t:{};Me.set(this,{type:String(e),bubbles:!!r.bubbles,cancelable:!!r.cancelable,composed:!!r.composed,target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1,inPassiveListenerFlag:!1,dispatchFlag:!1,timeStamp:Date.now()})}get type(){return m(this).type}get target(){return m(this).target}get srcElement(){return m(this).target}get currentTarget(){return m(this).currentTarget}composedPath(){let e=m(this).currentTarget;return e?[e]:[]}get NONE(){return Ve}get CAPTURING_PHASE(){return Ke}get AT_TARGET(){return Ye}get BUBBLING_PHASE(){return Ze}get eventPhase(){return m(this).dispatchFlag?2:0}stopPropagation(){m(this).stopPropagationFlag=!0}get cancelBubble(){return m(this).stopPropagationFlag}set cancelBubble(e){e?m(this).stopPropagationFlag=!0:Kt.warn()}stopImmediatePropagation(){let e=m(this);e.stopPropagationFlag=e.stopImmediatePropagationFlag=!0}get bubbles(){return m(this).bubbles}get cancelable(){return m(this).cancelable}get returnValue(){return!m(this).canceledFlag}set returnValue(e){e?Yt.warn():Je(m(this))}preventDefault(){Je(m(this))}get defaultPrevented(){return m(this).canceledFlag}get composed(){return m(this).composed}get isTrusted(){return!1}get timeStamp(){return m(this).timeStamp}initEvent(e,t=!1,r=!1){let n=m(this);if(n.dispatchFlag){Vt.warn();return}Me.set(this,{...n,type:String(e),bubbles:!!t,cancelable:!!r,target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1})}},Ve=0,Ke=1,Ye=2,Ze=3,Me=new WeakMap;function m(e,t="this"){let r=Me.get(e);return ze(r!=null,"'%s' must be an object that Event constructor created, but got another one: %o",t,e),r}function Je(e){if(e.inPassiveListenerFlag){Jt.warn();return}if(!e.cancelable){Zt.warn();return}e.canceledFlag=!0}Object.defineProperty(P,"NONE",{enumerable:!0});Object.defineProperty(P,"CAPTURING_PHASE",{enumerable:!0});Object.defineProperty(P,"AT_TARGET",{enumerable:!0});Object.defineProperty(P,"BUBBLING_PHASE",{enumerable:!0});var Le=Object.getOwnPropertyNames(P.prototype);for(let e=0;e<Le.length;++e)Le[e]!=="constructor"&&Object.defineProperty(P.prototype,Le[e],{enumerable:!0});typeof L!="undefined"&&typeof L.Event!="undefined"&&Object.setPrototypeOf(P.prototype,L.Event.prototype);function er(e){return L.DOMException?new L.DOMException(e,"InvalidStateError"):(N==null&&(N=class it extends Error{constructor(r){super(r),Error.captureStackTrace&&Error.captureStackTrace(this,it)}get code(){return 11}get name(){return"InvalidStateError"}},Object.defineProperties(N.prototype,{code:{enumerable:!0},name:{enumerable:!0}}),et(N),et(N.prototype)),new N(e))}var N,Qe={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 et(e){let t=Object.keys(Qe);for(let r=0;r<t.length;++r){let n=t[r],s=Qe[n];Object.defineProperty(e,n,{get(){return s},configurable:!0,enumerable:!0})}}var ue=class extends P{static wrap(e){return new(at(e))(e)}constructor(e){super(e.type,{bubbles:e.bubbles,cancelable:e.cancelable,composed:e.composed}),e.cancelBubble&&super.stopPropagation(),e.defaultPrevented&&super.preventDefault(),ot.set(this,{original:e});let t=Object.keys(e);for(let r=0;r<t.length;++r){let n=t[r];n in this||Object.defineProperty(this,n,lt(e,n))}}stopPropagation(){super.stopPropagation();let{original:e}=B(this);"stopPropagation"in e&&e.stopPropagation()}get cancelBubble(){return super.cancelBubble}set cancelBubble(e){super.cancelBubble=e;let{original:t}=B(this);"cancelBubble"in t&&(t.cancelBubble=e)}stopImmediatePropagation(){super.stopImmediatePropagation();let{original:e}=B(this);"stopImmediatePropagation"in e&&e.stopImmediatePropagation()}get returnValue(){return super.returnValue}set returnValue(e){super.returnValue=e;let{original:t}=B(this);"returnValue"in t&&(t.returnValue=e)}preventDefault(){super.preventDefault();let{original:e}=B(this);"preventDefault"in e&&e.preventDefault()}get timeStamp(){let{original:e}=B(this);return"timeStamp"in e?e.timeStamp:super.timeStamp}},ot=new WeakMap;function B(e){let t=ot.get(e);return ze(t!=null,"'this' is expected an Event object, but got",e),t}var le=new WeakMap;le.set(Object.prototype,ue);typeof L!="undefined"&&typeof L.Event!="undefined"&&le.set(L.Event.prototype,ue);function at(e){let t=Object.getPrototypeOf(e);if(t==null)return ue;let r=le.get(t);return r==null&&(r=tr(at(t),t),le.set(t,r)),r}function tr(e,t){class r extends e{}let n=Object.keys(t);for(let s=0;s<n.length;++s)Object.defineProperty(r.prototype,n[s],lt(t,n[s]));return r}function lt(e,t){let r=Object.getOwnPropertyDescriptor(e,t);return{get(){let n=B(this).original,s=n[t];return typeof s=="function"?s.bind(n):s},set(n){let s=B(this).original;s[t]=n},configurable:r.configurable,enumerable:r.enumerable}}function rr(e,t,r,n,s,o){return{callback:e,flags:(t?1:0)|(r?2:0)|(n?4:0),signal:s,signalListener:o}}function nr(e){e.flags|=8}function ut(e){return(e.flags&1)===1}function dt(e){return(e.flags&2)===2}function ht(e){return(e.flags&4)===4}function sr(e){return(e.flags&8)===8}function ir({callback:e},t,r){try{typeof e=="function"?e.call(t,r):typeof e.handleEvent=="function"&&e.handleEvent(r)}catch(n){Gt(n)}}function pt({listeners:e},t,r){for(let n=0;n<e.length;++n)if(e[n].callback===t&&ut(e[n])===r)return n;return-1}function or(e,t,r,n,s,o){let l;o&&(l=ct.bind(null,e,t,r),o.addEventListener("abort",l));let u=rr(t,r,n,s,o,l);return e.cow?(e.cow=!1,e.listeners=[...e.listeners,u]):e.listeners.push(u),u}function ct(e,t,r){let n=pt(e,t,r);return n!==-1?ft(e,n):!1}function ft(e,t,r=!1){let n=e.listeners[t];return nr(n),n.signal&&n.signal.removeEventListener("abort",n.signalListener),e.cow&&!r?(e.cow=!1,e.listeners=e.listeners.filter((s,o)=>o!==t),!1):(e.listeners.splice(t,1),!0)}function ar(){return Object.create(null)}function lr(e,t){var r;return(r=e[t])!==null&&r!==void 0?r:e[t]={attrCallback:void 0,attrListener:void 0,cow:!1,listeners:[]}}var de=class{constructor(){gt.set(this,ar())}addEventListener(e,t,r){let n=Re(this),{callback:s,capture:o,once:l,passive:u,signal:p,type:y}=ur(e,t,r);if(s==null||p!=null&&p.aborted)return;let E=lr(n,y),S=pt(E,s,o);if(S!==-1){hr(E.listeners[S],u,l,p);return}or(E,s,o,u,l,p)}removeEventListener(e,t,r){let n=Re(this),{callback:s,capture:o,type:l}=dr(e,t,r),u=n[l];s!=null&&u&&ct(u,s,o)}dispatchEvent(e){let t=Re(this)[String(e.type)];if(t==null)return!0;let r=e instanceof P?e:ue.wrap(e),n=m(r,"event");if(n.dispatchFlag)throw er("This event has been in dispatching.");if(n.dispatchFlag=!0,n.target=n.currentTarget=this,!n.stopPropagationFlag){let{cow:s,listeners:o}=t;t.cow=!0;for(let l=0;l<o.length;++l){let u=o[l];if(!sr(u)&&(ht(u)&&ft(t,l,!s)&&(l-=1),n.inPassiveListenerFlag=dt(u),ir(u,this,r),n.inPassiveListenerFlag=!1,n.stopImmediatePropagationFlag))break}s||(t.cow=!1)}return n.target=null,n.currentTarget=null,n.stopImmediatePropagationFlag=!1,n.stopPropagationFlag=!1,n.dispatchFlag=!1,!n.canceledFlag}},gt=new WeakMap;function Re(e,t="this"){let r=gt.get(e);return ze(r!=null,"'%s' must be an object that EventTarget constructor created, but got another one: %o",t,e),r}function ur(e,t,r){var n;return mt(t),typeof r=="object"&&r!==null?{type:String(e),callback:t!=null?t:void 0,capture:!!r.capture,passive:!!r.passive,once:!!r.once,signal:(n=r.signal)!==null&&n!==void 0?n:void 0}:{type:String(e),callback:t!=null?t:void 0,capture:!!r,passive:!1,once:!1,signal:void 0}}function dr(e,t,r){return mt(t),typeof r=="object"&&r!==null?{type:String(e),callback:t!=null?t:void 0,capture:!!r.capture}:{type:String(e),callback:t!=null?t:void 0,capture:!!r}}function mt(e){if(!(typeof e=="function"||typeof e=="object"&&e!==null&&typeof e.handleEvent=="function")){if(e==null||typeof e=="object"){Ge.warn(e);return}throw new TypeError(nt(Ge.message,[e]))}}function hr(e,t,r,n){Qt.warn(ut(e)?"capture":"bubble",e.callback),dt(e)!==t&&Te.warn("passive"),ht(e)!==r&&Te.warn("once"),e.signal!==n&&Te.warn("signal")}var _e=Object.getOwnPropertyNames(de.prototype);for(let e=0;e<_e.length;++e)_e[e]!=="constructor"&&Object.defineProperty(de.prototype,_e[e],{enumerable:!0});typeof L!="undefined"&&typeof L.EventTarget!="undefined"&&Object.setPrototypeOf(de.prototype,L.EventTarget.prototype);var pr=Nt(qt()),Pe=30720,ee=512e3,te=256,Z=(e,{minChunkSize:t=te,maxChunkSize:r=ee}={})=>e==null||typeof e=="number"&&e>=256&&e%256===0&&e>=t&&e<=r,J=(e,{minChunkSize:t=te,maxChunkSize:r=ee}={})=>new TypeError(`chunkSize ${e} must be a positive number in multiples of 256, between ${t} and ${r}`),cr=class{constructor(e,t={}){this.readableStream=e;var r,n,s;if(!Z(t.defaultChunkSize,t))throw J(t.defaultChunkSize,t);this.defaultChunkSize=(r=t.defaultChunkSize)!=null?r:Pe,this.minChunkSize=(n=t.minChunkSize)!=null?n:te,this.maxChunkSize=(s=t.maxChunkSize)!=null?s:ee}get chunkSize(){var e;return(e=this._chunkSize)!=null?e:this.defaultChunkSize}set chunkSize(e){if(!Z(e,this))throw J(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}get error(){return this._error}async*[Symbol.asyncIterator](){let e,t=this.readableStream.getReader();try{for(;;){let{done:r,value:n}=await t.read();if(r){if(e){let o=e;e=void 0,yield o}break}let s=n instanceof Uint8Array?new Blob([n],{type:"application/octet-stream"}):n;for(e=e?new Blob([e,s]):s;e;)if(e.size===this.chunkByteSize){let o=e;e=void 0,yield o;break}else{if(e.size<this.chunkByteSize)break;{let o=e.slice(0,this.chunkByteSize);e=e.slice(this.chunkByteSize),yield o}}}}catch(r){this._error=r}finally{if(e){let r=e;e=void 0,yield r}t.releaseLock();return}}},fr=class{constructor(e,t={}){this.file=e;var r,n,s;if(!Z(t.defaultChunkSize,t))throw J(t.defaultChunkSize,t);this.defaultChunkSize=(r=t.defaultChunkSize)!=null?r:Pe,this.minChunkSize=(n=t.minChunkSize)!=null?n:te,this.maxChunkSize=(s=t.maxChunkSize)!=null?s:ee}get chunkSize(){var e;return(e=this._chunkSize)!=null?e:this.defaultChunkSize}set chunkSize(e){if(!Z(e,this))throw J(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}get error(){return this._error}async*[Symbol.asyncIterator](){let e=new FileReader,t=0,r=()=>new Promise(n=>{if(t>=this.file.size){n(void 0);return}let s=Math.min(this.chunkByteSize,this.file.size-t);e.onload=()=>{e.result!==null?n(new Blob([e.result],{type:"application/octet-stream"})):n(void 0)},e.readAsArrayBuffer(this.file.slice(t,t+s))});try{for(;;){let n=await r();if(n)t+=n.size,yield n;else break}}catch(n){this._error=n}}},gr=[200,201,202,204,308],bt=[408,502,503,504],mr=[308],yt=(e,t)=>!!e&&gr.includes(e.statusCode),br=(e,{retryCodes:t=bt})=>!e||t.includes(e.statusCode),yr=(e,t)=>t.attemptCount>=t.attempts||!(yt(e)||br(e,t)),Er=(e,t)=>{var r;if(!e||!mr.includes(e.statusCode)||!((r=e.headers)!=null&&r.range))return!1;let n=e.headers.range.match(/bytes=(\d+)-(\d+)/);return n?parseInt(n[2],10)<t.currentChunkEndByte:!1},Oe=class{static createUpload(e){return new Oe(e)}constructor(e){if(this.eventTarget=new de,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||bt,this.dynamicChunkSize=e.dynamicChunkSize||!1,this.maxFileBytes=(e.maxFileSize||0)*1024,this.chunkCount=0,this.attemptCount=0,this._offline=typeof window!="undefined"&&!window.navigator.onLine,this._paused=!1,this.success=!1,this.nextChunkRangeStart=0,e.useLargeFileWorkaround){let t=r=>{this.chunkedIterable.error&&(console.warn(`Unable to read file of size ${this.file.size} bytes via a ReadableStream. Falling back to in-memory FileReader!`),r.stopImmediatePropagation(),this.chunkedIterable=new fr(this.file,{...e,defaultChunkSize:e.chunkSize}),this.chunkedIterator=this.chunkedIterable[Symbol.asyncIterator](),this.getEndpoint().then(()=>{this.sendChunks()}).catch(n=>{let s=n!=null&&n.message?`: ${n.message}`:"";this.dispatch("error",{message:`Failed to get endpoint${s}`})}),this.off("error",t))};this.on("error",t)}this.chunkedIterable=new cr(this.file.stream(),{...e,defaultChunkSize:e.chunkSize}),this.chunkedIterator=this.chunkedIterable[Symbol.asyncIterator](),this.totalChunks=Math.ceil(this.file.size/this.chunkByteSize),this.validateOptions(),this.getEndpoint().then(()=>this.sendChunks()).catch(t=>{let r=t!=null&&t.message?`: ${t.message}`:"";this.dispatch("error",{message:`Failed to get endpoint${r}`})}),typeof window!="undefined"&&(window.addEventListener("online",()=>{this.offline&&(this._offline=!1,this.dispatch("online"),this.sendChunks())}),window.addEventListener("offline",()=>{this.offline||(this._offline=!0,this.dispatch("offline"))}))}get maxChunkSize(){var e,t;return(t=(e=this.chunkedIterable)==null?void 0:e.maxChunkSize)!=null?t:ee}get minChunkSize(){var e,t;return(t=(e=this.chunkedIterable)==null?void 0:e.minChunkSize)!=null?t:te}get chunkSize(){var e,t;return(t=(e=this.chunkedIterable)==null?void 0:e.chunkSize)!=null?t:Pe}set chunkSize(e){this.chunkedIterable.chunkSize=e}get chunkByteSize(){return this.chunkedIterable.chunkByteSize}get totalChunkSize(){return Math.ceil(this.file.size/this.chunkByteSize)}on(e,t){this.eventTarget.addEventListener(e,t)}once(e,t){this.eventTarget.addEventListener(e,t,{once:!0})}off(e,t){this.eventTarget.removeEventListener(e,t)}get offline(){return this._offline}get paused(){return this._paused}abort(){var e;this.pause(),(e=this.currentXhr)==null||e.abort()}pause(){this._paused=!0}resume(){this._paused&&(this._paused=!1,this.sendChunks())}get successfulPercentage(){return this.nextChunkRangeStart/this.file.size}dispatch(e,t){let r=new CustomEvent(e,{detail:t});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(!Z(this.chunkSize,{maxChunkSize:this.maxChunkSize,minChunkSize:this.minChunkSize}))throw J(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=>{if(this.endpointValue=e,typeof e!="string")throw new TypeError("endpoint must return a string");return this.endpointValue})}xhrPromise(e){let t=r=>{r.upload.onprogress=n=>{var s;let o=this.totalChunks-this.chunkCount,l=(this.file.size-this.nextChunkRangeStart)/this.file.size/o,p=n.loaded/((s=n.total)!=null?s:this.chunkByteSize)*l;this.dispatch("progress",Math.min((this.successfulPercentage+p)*100,100))}};return new Promise((r,n)=>{this.currentXhr=(0,pr.default)({...e,beforeSend:t},(s,o)=>(this.currentXhr=void 0,s?n(s):r(o)))})}async sendChunk(e){let t=this.nextChunkRangeStart,r=t+e.size-1,s={...await(typeof this.headers=="function"?this.headers():this.headers),"Content-Type":this.file.type,"Content-Range":`bytes ${t}-${r}/${this.file.size}`};return this.dispatch("attempt",{chunkNumber:this.chunkCount,totalChunks:this.totalChunks,chunkSize:this.chunkSize}),this.xhrPromise({headers:s,url:this.endpointValue,method:this.method,body:e})}async sendChunkWithRetries(e){let t=async(l,u)=>{var p;let E=(new Date().getTime()-this.lastChunkStart.getTime())/1e3;if(this.dispatch("chunkSuccess",{chunk:this.chunkCount,chunkSize:this.chunkSize,attempts:this.attemptCount,timeInterval:E,response:l}),this.attemptCount=0,this.chunkCount=((p=this.chunkCount)!=null?p:0)+1,this.nextChunkRangeStart=this.nextChunkRangeStart+this.chunkByteSize,this.dynamicChunkSize){let S=this.chunkSize;E<10?S=Math.min(this.chunkSize*2,this.maxChunkSize):E>30&&(S=Math.max(this.chunkSize/2,this.minChunkSize)),this.chunkSize=Math.ceil(S/256)*256;let ye=(this.file.size-this.nextChunkRangeStart)/this.chunkByteSize;this.totalChunks=Math.ceil(this.chunkCount+ye)}return!0},r=async(l,u)=>(this.dispatch("progress",Math.min(this.successfulPercentage*100,100)),this.dispatch("error",{message:`Server responded with ${l.statusCode}. Stopping upload.`,chunk:this.chunkCount,attempts:this.attemptCount,response:l}),!1),n=async(l,u)=>(this.dispatch("attemptFailure",{message:`An error occured uploading chunk ${this.chunkCount}. ${this.attempts-this.attemptCount} retries left.`,chunkNumber:this.chunkCount,attemptsLeft:this.attempts-this.attemptCount,response:l}),new Promise(p=>{setTimeout(async()=>{if(this._paused||this.offline){this.pendingChunk=e,p(!1);return}let y=await this.sendChunkWithRetries(e);p(y)},this.delayBeforeAttempt*1e3)})),s;try{this.attemptCount=this.attemptCount+1,this.lastChunkStart=new Date,s=await this.sendChunk(e)}catch(l){typeof(l==null?void 0:l.statusCode)=="number"&&(s=l)}let o={retryCodes:this.retryCodes,attemptCount:this.attemptCount,attempts:this.attempts,currentChunkEndByte:this.nextChunkRangeStart+e.size-1};return Er(s,o)?n(s,e):yt(s,o)?t(s,e):yr(s,o)?r(s,e):n(s,e)}async sendChunks(){if(this.pendingChunk&&!(this._paused||this.offline)){let e=this.pendingChunk;this.pendingChunk=void 0;let t=await this.sendChunkWithRetries(e);this.success&&t&&this.dispatch("success")}for(;!(this.success||this._paused||this.offline);){let{value:e,done:t}=await this.chunkedIterator.next(),r=!e&&t;if(e&&(r=await this.sendChunkWithRetries(e)),this.chunkedIterable.error){r=!1,this.dispatch("error",{message:`Unable to read file of size ${this.file.size} bytes. Try loading from another browser.`});return}if(this.success=!!t,this.success&&r&&this.dispatch("success"),!r)return}}};var Et=(e,t)=>{if(!e)return null;let r=e.closest(t);return r||Et(e.getRootNode().host,t)},w=e=>{let t=e.getAttribute("mux-uploader");return t?document.getElementById(t):Et(e,"mux-uploader")};var vt=v.createElement("template");vt.innerHTML=` | ||
<style> | ||
@@ -5,0 +5,0 @@ :host { |
{ | ||
"name": "@mux/mux-uploader", | ||
"version": "1.1.2", | ||
"version": "1.1.3-canary.0", | ||
"description": "An uploader elements to be used with Mux Direct Uploads", | ||
@@ -68,3 +68,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@mux/upchunk": "^3.4.0" | ||
"@mux/upchunk": "^3.5.0" | ||
}, | ||
@@ -71,0 +71,0 @@ "devDependencies": { |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
729163
0.4%1919
0.1%3
50%Updated