// @rails/activestorage@8.1.300 downloaded from https://ga.jspm.io/npm:@rails/activestorage@8.1.300/app/assets/javascripts/activestorage.esm.js var e={exports:{}};(function(e,t){(function(t){e.exports=t()})((function(e){var t=[`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`a`,`b`,`c`,`d`,`e`,`f`];function n(e,t){var n=e[0],r=e[1],i=e[2],a=e[3];n+=(r&i|~r&a)+t[0]-680876936|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[1]-389564586|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[2]+606105819|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[3]-1044525330|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+t[4]-176418897|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[5]+1200080426|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[6]-1473231341|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[7]-45705983|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+t[8]+1770035416|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[9]-1958414417|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[10]-42063|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[11]-1990404162|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+t[12]+1804603682|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[13]-40341101|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[14]-1502002290|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[15]+1236535329|0,r=(r<<22|r>>>10)+i|0,n+=(r&a|i&~a)+t[1]-165796510|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[6]-1069501632|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[11]+643717713|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[0]-373897302|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+t[5]-701558691|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[10]+38016083|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[15]-660478335|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[4]-405537848|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+t[9]+568446438|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[14]-1019803690|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[3]-187363961|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[8]+1163531501|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+t[13]-1444681467|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[2]-51403784|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[7]+1735328473|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[12]-1926607734|0,r=(r<<20|r>>>12)+i|0,n+=(r^i^a)+t[5]-378558|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[8]-2022574463|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[11]+1839030562|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[14]-35309556|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+t[1]-1530992060|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[4]+1272893353|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[7]-155497632|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[10]-1094730640|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+t[13]+681279174|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[0]-358537222|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[3]-722521979|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[6]+76029189|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+t[9]-640364487|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[12]-421815835|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[15]+530742520|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[2]-995338651|0,r=(r<<23|r>>>9)+i|0,n+=(i^(r|~a))+t[0]-198630844|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[7]+1126891415|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[14]-1416354905|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[5]-57434055|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+t[12]+1700485571|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[3]-1894986606|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[10]-1051523|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[1]-2054922799|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+t[8]+1873313359|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[15]-30611744|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[6]-1560198380|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[13]+1309151649|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+t[4]-145523070|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[11]-1120210379|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[2]+718787259|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[9]-343485551|0,r=(r<<21|r>>>11)+i|0,e[0]=n+e[0]|0,e[1]=r+e[1]|0,e[2]=i+e[2]|0,e[3]=a+e[3]|0}function r(e){var t=[],n;for(n=0;n<64;n+=4)t[n>>2]=e.charCodeAt(n)+(e.charCodeAt(n+1)<<8)+(e.charCodeAt(n+2)<<16)+(e.charCodeAt(n+3)<<24);return t}function i(e){var t=[],n;for(n=0;n<64;n+=4)t[n>>2]=e[n]+(e[n+1]<<8)+(e[n+2]<<16)+(e[n+3]<<24);return t}function a(e){var t=e.length,i=[1732584193,-271733879,-1732584194,271733878],a,o,s,c,l,u;for(a=64;a<=t;a+=64)n(i,r(e.substring(a-64,a)));for(e=e.substring(a-64),o=e.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=0;a>2]|=e.charCodeAt(a)<<(a%4<<3);if(s[a>>2]|=128<<(a%4<<3),a>55)for(n(i,s),a=0;a<16;a+=1)s[a]=0;return c=t*8,c=c.toString(16).match(/(.*?)(.{0,8})$/),l=parseInt(c[2],16),u=parseInt(c[1],16)||0,s[14]=l,s[15]=u,n(i,s),i}function o(e){var t=e.length,r=[1732584193,-271733879,-1732584194,271733878],a,o,s,c,l,u;for(a=64;a<=t;a+=64)n(r,i(e.subarray(a-64,a)));for(e=a-64>2]|=e[a]<<(a%4<<3);if(s[a>>2]|=128<<(a%4<<3),a>55)for(n(r,s),a=0;a<16;a+=1)s[a]=0;return c=t*8,c=c.toString(16).match(/(.*?)(.{0,8})$/),l=parseInt(c[2],16),u=parseInt(c[1],16)||0,s[14]=l,s[15]=u,n(r,s),r}function s(e){var n=``,r;for(r=0;r<4;r+=1)n+=t[e>>r*8+4&15]+t[e>>r*8&15];return n}function c(e){var t;for(t=0;to?/* @__PURE__ */ new ArrayBuffer(0):(s=o-a,c=new ArrayBuffer(s),l=new Uint8Array(c),u=new Uint8Array(this,a,s),l.set(u),c)}})();function l(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function u(e,t){var n=e.length,r=new ArrayBuffer(n),i=new Uint8Array(r),a;for(a=0;a>2]|=t.charCodeAt(r)<<(r%4<<3);return this._finish(i,n),a=c(this._hash),e&&(a=p(a)),this.reset(),a},m.prototype.reset=function(){return this._buff=``,this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},m.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},m.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},m.prototype._finish=function(e,t){var r=t,i,a,o;if(e[r>>2]|=128<<(r%4<<3),r>55)for(n(this._hash,e),r=0;r<16;r+=1)e[r]=0;i=this._length*8,i=i.toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(i[2],16),o=parseInt(i[1],16)||0,e[14]=a,e[15]=o,n(this._hash,e)},m.hash=function(e,t){return m.hashBinary(l(e),t)},m.hashBinary=function(e,t){var n=c(a(e));return t?p(n):n},m.ArrayBuffer=function(){this.reset()},m.ArrayBuffer.prototype.append=function(e){var t=f(this._buff.buffer,e,!0),r=t.length,a;for(this._length+=e.byteLength,a=64;a<=r;a+=64)n(this._hash,i(t.subarray(a-64,a)));return this._buff=a-64>2]|=t[i]<<(i%4<<3);return this._finish(r,n),a=c(this._hash),e&&(a=p(a)),this.reset(),a},m.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array,this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.ArrayBuffer.prototype.getState=function(){var e=m.prototype.getState.call(this);return e.buff=d(e.buff),e},m.ArrayBuffer.prototype.setState=function(e){return e.buff=u(e.buff,!0),m.prototype.setState.call(this,e)},m.ArrayBuffer.prototype.destroy=m.prototype.destroy,m.ArrayBuffer.prototype._finish=m.prototype._finish,m.ArrayBuffer.hash=function(e,t){var n=c(o(new Uint8Array(e)));return t?p(n):n},m}))})(e);var t=e.exports;const n=File.prototype.slice||File.prototype.mozSlice||File.prototype.webkitSlice;class FileChecksum{static create(e,t){new FileChecksum(e).create(t)}constructor(e){this.file=e,this.chunkSize=2097152,this.chunkCount=Math.ceil(this.file.size/this.chunkSize),this.chunkIndex=0}create(e){this.callback=e,this.md5Buffer=new t.ArrayBuffer,this.fileReader=new FileReader,this.fileReader.addEventListener(`load`,(e=>this.fileReaderDidLoad(e))),this.fileReader.addEventListener(`error`,(e=>this.fileReaderDidError(e))),this.readNextChunk()}fileReaderDidLoad(e){if(this.md5Buffer.append(e.target.result),!this.readNextChunk()){let e=this.md5Buffer.end(!0),t=btoa(e);this.callback(null,t)}}fileReaderDidError(e){this.callback(`Error reading ${this.file.name}`)}readNextChunk(){if(this.chunkIndex{this.xhr.setRequestHeader(e,i[e])}));let a=r(`csrf-token`);a!=null&&this.xhr.setRequestHeader(`X-CSRF-Token`,a),this.xhr.addEventListener(`load`,(e=>this.requestDidLoad(e))),this.xhr.addEventListener(`error`,(e=>this.requestDidError(e)))}get status(){return this.xhr.status}get response(){let{responseType:e,response:t}=this.xhr;return e==`json`?t:JSON.parse(t)}create(e){this.callback=e,this.xhr.send(JSON.stringify({blob:this.attributes}))}requestDidLoad(e){if(this.status>=200&&this.status<300){let{response:e}=this,{direct_upload:t}=e;delete e.direct_upload,this.attributes=e,this.directUploadData=t,this.callback(null,this.toJSON())}else this.requestDidError(e)}requestDidError(e){this.callback(`Error creating Blob for "${this.file.name}". Status: ${this.status}`)}toJSON(){let e={};for(let t in this.attributes)e[t]=this.attributes[t];return e}}class BlobUpload{constructor(e){this.blob=e,this.file=e.file;let{url:t,headers:n}=e.directUploadData;this.xhr=new XMLHttpRequest,this.xhr.open(`PUT`,t,!0),this.xhr.responseType=`text`;for(let e in n)this.xhr.setRequestHeader(e,n[e]);this.xhr.addEventListener(`load`,(e=>this.requestDidLoad(e))),this.xhr.addEventListener(`error`,(e=>this.requestDidError(e)))}create(e){this.callback=e,this.xhr.send(this.file.slice())}requestDidLoad(e){let{status:t,response:n}=this.xhr;t>=200&&t<300?this.callback(null,n):this.requestDidError(e)}requestDidError(e){this.callback(`Error storing "${this.file.name}". Status: ${this.xhr.status}`)}}let c=0;class DirectUpload{constructor(e,t,n,r={}){this.id=++c,this.file=e,this.url=t,this.delegate=n,this.customHeaders=r}create(e){FileChecksum.create(this.file,((t,n)=>{if(t){e(t);return}let r=new BlobRecord(this.file,n,this.url,this.customHeaders);l(this.delegate,`directUploadWillCreateBlobWithXHR`,r.xhr),r.create((t=>{if(t)e(t);else{let t=new BlobUpload(r);l(this.delegate,`directUploadWillStoreFileWithXHR`,t.xhr),t.create((t=>{t?e(t):e(null,r.toJSON())}))}}))}))}}function l(e,t,...n){if(e&&typeof e[t]==`function`)return e[t](...n)}class DirectUploadController{constructor(e,t){this.input=e,this.file=t,this.directUpload=new DirectUpload(this.file,this.url,this),this.dispatch(`initialize`)}start(e){let t=document.createElement(`input`);t.type=`hidden`,t.name=this.input.name,this.input.insertAdjacentElement(`beforebegin`,t),this.dispatch(`start`),this.directUpload.create(((n,r)=>{n?(t.parentNode.removeChild(t),this.dispatchError(n)):t.value=r.signed_id,this.dispatch(`end`),e(n)}))}uploadRequestDidProgress(e){let t=e.loaded/e.total*90;t&&this.dispatch(`progress`,{progress:t})}get url(){return this.input.getAttribute(`data-direct-upload-url`)}dispatch(e,t={}){return t.file=this.file,t.id=this.directUpload.id,o(this.input,`direct-upload:${e}`,{detail:t})}dispatchError(e){this.dispatch(`error`,{error:e}).defaultPrevented||alert(e)}directUploadWillCreateBlobWithXHR(e){this.dispatch(`before-blob-request`,{xhr:e})}directUploadWillStoreFileWithXHR(e){this.dispatch(`before-storage-request`,{xhr:e}),e.upload.addEventListener(`progress`,(e=>this.uploadRequestDidProgress(e))),e.upload.addEventListener(`loadend`,(()=>{this.simulateResponseProgress(e)}))}simulateResponseProgress(e){let t=90,n=Date.now(),r=()=>{let i=Date.now()-n,a=this.estimateResponseTime();t=90+Math.min(i/a,1)*9,this.dispatch(`progress`,{progress:t}),e.readyState!==XMLHttpRequest.DONE&&t<99&&requestAnimationFrame(r)};e.addEventListener(`loadend`,(()=>{this.dispatch(`progress`,{progress:100})})),requestAnimationFrame(r)}estimateResponseTime(){let e=this.file.size,t=1024*1024;return ee.files.length))}start(e){let t=this.createDirectUploadControllers(),n=()=>{let r=t.shift();r?r.start((t=>{t?(e(t),this.dispatch(`end`)):n()})):(e(),this.dispatch(`end`))};this.dispatch(`start`),n()}createDirectUploadControllers(){let e=[];return this.inputs.forEach((t=>{s(t.files).forEach((n=>{let r=new DirectUploadController(t,n);e.push(r)}))})),e}dispatch(e,t={}){return o(this.form,`direct-uploads:${e}`,{detail:t})}}const d=`data-direct-uploads-processing`,f=/* @__PURE__ */ new WeakMap;let p=!1;function m(){p||(p=!0,document.addEventListener(`click`,h,!0),document.addEventListener(`submit`,g,!0),document.addEventListener(`ajax:before`,_))}function h(e){let t=e.target.closest(`button, input`);t&&t.type===`submit`&&t.form&&f.set(t.form,t)}function g(e){v(e)}function _(e){e.target.tagName==`FORM`&&v(e)}function v(e){let t=e.target;if(t.hasAttribute(d)){e.preventDefault();return}let n=new DirectUploadsController(t),{inputs:r}=n;r.length&&(e.preventDefault(),t.setAttribute(d,``),r.forEach(b),n.start((e=>{t.removeAttribute(d),e?r.forEach(x):y(t)})))}function y(e){let t=f.get(e)||a(e,`input[type=submit], button[type=submit]`);if(t){let{disabled:e}=t;t.disabled=!1,t.focus(),t.click(),t.disabled=e}else t=document.createElement(`input`),t.type=`submit`,t.style.display=`none`,e.appendChild(t),t.click(),e.removeChild(t);f.delete(e)}function b(e){e.disabled=!0}function x(e){e.disabled=!1}function S(){window.ActiveStorage&&m()}setTimeout(S,1);export{DirectUpload,DirectUploadController,DirectUploadsController,o as dispatchEvent,m as start};