1import{n as e,r as t}from"./polymer-C_GypsRJ.js";var n={UNSENT:`UNSENT`,SENDING:`SENDING`,SUCCESS:`SUCCESS`,CANCELLED:`CANCELLED`,ERROR:`ERROR`};function r(){return`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(e^(typeof crypto>`u`?window.msCrypto:crypto).getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))}var i=class{constructor(e,t=`file`){this.id=r(),this.file=e,this.parameterName=t}},a=class{constructor(){this.queue=[],this.percentComplete=0,this.status=n.UNSENT,this.xhr=new XMLHttpRequest,this._boundProgress=e=>this.progress(e),this._boundLoaded=e=>this.loaded(e),this._boundError=e=>this.error(e),this._boundAborted=e=>this.aborted(e)}beforeSend(){}upload(e,t,r){this.status=n.UNSENT;let i=r||new FormData;this.queue.forEach(e=>{i.append(e.parameterName,e.file)}),this.xhr.upload.addEventListener(`progress`,this._boundProgress,!1),this.xhr.addEventListener(`abort`,this._boundAborted,!1),this.xhr.addEventListener(`load`,this._boundLoaded,!1),this.xhr.addEventListener(`error`,this._boundError,!1),this.xhr.open(e,t,!0),this.beforeSend(),this.xhr.send(i),this.status=n.SENDING}progress(e){this.percentComplete=Math.round((e.lengthComputable?e.loaded/e.total:0)*1e3)/10}loaded(e){this.xhr.status<200||this.xhr.status>=300?(this.status=n.ERROR,this.percentComplete=0):(this.status=n.SUCCESS,this.percentComplete=100),this._cleanup(e)}error(e){this.status=n.ERROR,this._cleanup(e)}aborted(e){this.status=n.CANCELLED,this._cleanup(e)}_cleanup(e){this.xhr.upload.removeEventListener(`progress`,this._boundProgress,!1),this.xhr.removeEventListener(`abort`,this._boundAborted,!1),this.xhr.removeEventListener(`load`,this._boundLoaded,!1),this.xhr.removeEventListener(`error`,this._boundError,!1)}};function o(e){e.preventDefault(),e.dataTransfer.dropEffect=`none`}window.PolymerFileUploader=class extends e{static get is(){return`polymer-file-uploader`}static get properties(){return{name:{type:String,value:`file`},type:String,showSelect:{type:Boolean,value:!1},multiple:{type:Boolean,value:!1},accept:String,reject:String,bodyData:Object,queue:{type:Array,value:()=>[]}}}
1connectedCallback(){if(super.connectedCallback(),!this.type)throw Error("Please pass `type` to polymerFileUploader");this.type===`select`&&this._generateSelect(),document.addEventListener(`dragenter`,o),document.addEventListener(`dragover`,o)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(`dragenter`,o),document.removeEventListener(`dragover`,o)}_isEqual(e,t){return e===t}_createInputFile(e,t,n,r){let i=document.createElement(`INPUT`);return i.setAttribute(`type`,`file`),i.setAttribute(`name`,e),t&&i.setAttribute(`multiple`,``),n||i.setAttribute(`style`,`display:none;`),r&&i.setAttribute(`accept`,r),i}_generateSelect(){let e=this._createInputFile(this.name,this.multiple,this.showSelect,this.accept),t=this.shadowRoot.querySelector(`.render`);e.onchange=async()=>{let t=[].slice.call(e.files),n=await Promise.all(t.map(async e=>new File([await e.arrayBuffer()],e.name,{type:e.type,lastModified:e.lastModified})));e.value=``,this._processFiles(n)},t.appendChild(e)}_processFiles(e){e.length!==0&&(this.multiple||(e=e.slice(0,1)),e.forEach(e=>{let t=this.accept&&this.accept.split(`,`),n=this.accept&&t.some(t=>{let n=t.trim().toLowerCase(),r=e.name.split(`.`).pop().toLowerCase();return e.type.match(n)||`.${r}`===n});if(this.accept&&!n)return this.dispatchEvent(new CustomEvent(`file-error`,{bubbles:!0,composed:!0,detail:{message:`${e.name} filetype doesn't match ${this.accept}`,filename:e.name,filetype:e.type}}));if(this.reject&&this.reject.split(`,`).some(t=>{let n=t.trim().toLowerCase(),r=e.name.split(`.`).pop().toLowerCase();return e.type===n||`.${r}`===n}))return this.dispatchEvent(new CustomEvent(`file-error`,{bubbles:!0,composed:!0,detail:{message:`${e.name}'s file type '${e.type}' is not allowed.`,filename:e.name,filetype:e.type}}));this.push(JSCompiler_renameProperty(`queue`,this),new i(e,this.name))}),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,composed:!0,detail:{queue:this.queue}})))}upload(e,t,n){this._upload(this.queue,e,t,n),this.queue=[]}uploadFile(e,t,n,r){let i=this.queue.find(t=>t.id===e);i&&(this.removeFile(i),this._upload([i],t,n,r))}removeFile(e){let t=this.queue.indexOf(e);t>=0&&this.splice(JSCompiler_renameProperty(`queue`,this),t,1)}_upload(e,t,n,r){let i=new a;i.queue=e,i.error=e=>{a.prototype.error.call(i,e),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,composed:!0,detail:{uploader:i}}))},i.aborted=e=>{a.prototype.aborted.call(i,e),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,composed:!0,detail:{uploader:i}}))},i.loaded=e=>{a.prototype.loaded.call(i,e),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,composed:!0,detail:{uploader:i}}))},i.progress=e=>{a.prototype.progress.call(i,e),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,composed:!0,detail:{uploader:i}}))},i.upload(t,n,r),this.dispatchEvent(new CustomEvent(`change`,{bubbles:!0,composed:!0,detail:{uploader:i}}))}_toggleFileHover(e){let t=this.shadowRoot.querySelector(`.drop-zone`);t.className=e?`drop-zone file-hover`:`drop-zone`}_handleDrop(e){e.preventDefault(),this._processFiles([].slice.call(e.dataTransfer.files)),this._toggleFileHover(!1)}_handleDragOver(e){e.preventDefault(),e.stopImmediatePropagation(),e.dataTransfer.dropEffect=`copy`}_handleDragEnd(e){e.dataTransfer.clearData()}_handleDragEnter(e){(!e.relatedTarget||e.relatedTarget.tagName===`ARTICLE`||e.relatedTarget.tagName===`ASSETS-UPLOAD-AREA`)&&this._toggleFileHover(!0)}_handleDragLeave(e){(!e.relatedTarget||e.relatedTarget.tagName===`ARTICLE`||e.relatedTarget.tagName===`ASSETS-UPLOAD-AREA`)&&this._toggleFileHover(!1)}_handleSlotClick(e){let t=e.composedPath().find(e=>e.tagName===`DIV`&&e.className.includes(`render`)).querySelector(`input`),n=new MouseEvent(`click`,{bubbles:!0,cancelable:!1,view:window});t.dispatchEvent(n)}static get template(){return t`<style>:host{display:block}.drop-zone{justify-content:center;align-items:center;height:100px;padding:40px 0;display:flex}.file-hover{background-color:var(--jha-border-color)}.render{width:100%}.render>div:not(.drop-zone){display:var(--polymer-file-uploader-slot-display,block)}:host ::slotted([icon]){width:20px;height:20px;margin-right:8px;box-sizing:initial!important}</style> <div class="render"> <template is="dom-if" if="[[_isEqual(type, 'drop')]]"> <div class="drop-zone" on-drop="_handleDrop" on-dragover="_handleDragOver" on-dragend="_handleDragEnd" on-dragenter="_handleDragEnter" on-dragleave="_handleDragLeave"> <slot></slot> </div> </template> <template is="dom-if" if="[[_isEqual(type, 'select')]]">
1 <slot on-click="_handleSlotClick"></slot> </template></div>`}},window.PolymerFileUploader.UploadQueue=a,window.PolymerFileUploader.UploadFile=i,customElements.define(window.PolymerFileUploader.is,window.PolymerFileUploader);var s=window.PolymerFileUploader;export{s as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.