1/** 2 * Bundled by jsDelivr using Rollup v4.62.2 and esbuild v0.28.1. 3 * Original file: /npm/[email protected]/src/liteuploader.js 4 * 5 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files 6 */ 7var d=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},l={exports:{}},h;function c(){return h||(h=1,(function(p){(function(s){p.exports=s(d.$)})(function(s){s&&s.fn&&(s.fn.liteUploader=function(t){return this.each(function(){t.ref=t.ref||s(this).attr("name");var e=function(){return s(this).get(0).files}.bind(this),r=function(i,n){s(this).trigger.bind(s(this))(i,[n])}.bind(this);s.data(this,"liteUploader",new u(t,r,e))})});function u(t,e,r){this.options=this._applyDefaults(t),this._getFiles=r||function(){return null},this._triggerEvent=e,this.xhrs=[]}return u.prototype={_applyDefaults:function(t){return Object.assign({url:null,ref:null,method:"POST",rules:{},params:{},headers:{},validators:[],singleFileUploads:!1,withCredentials:!1,beforeRequest:null,sendAsFormData:!0},t)},_init:function(t){if(t=t||this._getFiles(),!t||!t.length)throw new Error("No files");return Promise.all([this._validateOptions(),this._validateFiles(t)]).then(function(e){var r=e[0];r||(r=e[1]),r?this._triggerEvent("lu:errors",{errors:r}):(this._triggerEvent("lu:start",{files:t}),this.xhrs=[],this._startUpload(t))}.bind(this))},_startUpload:function(t){const e=this._splitFiles(t).map(function(r){return this._buildXhrObject(r).then(function(i){return this._beforeRequest(r).then(function(n){return!this.options.sendAsFormData&&this.options.singleFileUploads?i.send(r[0]):i.send(n)}.bind(this))}.bind(this))}.bind(this));return Promise.all(e)},_splitFiles:function(t){return this.options.singleFileUploads?Array.prototype.map.call(t,function(e){return[e]}):[t]},_beforeRequest:function(t){this._triggerEvent("lu:before",{files:t});var e=this._collateFormData(t);return this.options.beforeRequest?this.options.beforeRequest(t,e):Promise.resolve(e)},_validateOptions:function(){var t=["url","ref"],e=t.reduce(function(r,i){return this.options[i]||r.push({type:i+"Required"}),r}.bind(this),[]);return e.length?[{name:"_options",errors:e}]:null},_allowedFileTypeValidator:function(t,e){var r=t.split(","),i=/([a-z]+)\/\*$/;if(r.indexOf(e.type)===-1){var n=r.reduce(function(o,a){if(o)return o;var f=a.match(i)||[];return f[1]===e.type.split("/")[0]},!1);if(!n)return{type:"type",rule:t,given:e.type}}},_maxSizeValidator:function(t,e){if(e.size>t)return{type:"size",rule:t,given:e.size}},_validateFiles:function(t){var e=Array.prototype.map.call(t,function(r){return this._validateFile(r)}.bind(this));return Promise.all(e).then(function(r){var i=r.filter(function(n){return n.errors.length});return i.length?i:null})},_validateFile:function(t){var e={allowedFileTypes:this._allowedFileTypeValidator,maxSize:this._maxSizeValidator},r=Object.keys(this.options.rules).reduce(function(n,o){var a=this.options.rules[o];return a&&e[o]&&n.push(e[o](a,t)),n}.bind(this),[]),i=this.options.validators.map(function(n){return n(t)});return Promise.all(r.concat(i)).then(function(n){return{name:t.name,errors:n.filter(function(o){return!!o})}})},_getFormDataObject:function(){return new FormData},_collateFormData:function(t){var e=this._getFormDataObject();for(var r in this.options.params)e.append(r,this.options.params[r]);return Array.prototype.forEach.call(t,function(i){e.append(this.options.ref,i)}.bind(this)),e},_getXmlHttpRequestObject:function(){return new XMLHttpRequest},_getScriptUrl:function(t){return typeof this.options.url=="function"?this.options.url(t):Promise.resolve(this.options.url)},_buildXhrObject:function(t){return this._getScriptUrl(t).then(function(e){var r=this._getXmlHttpRequestObject();r.open(this.options.method,e),this.options.withCredentials&&(r.withCredentials=!0);for(var i in this.options.headers)r.setRequestHeader(i,this.options.headers[i]);return r.upload.addEventListener("progress",this._onXHRProgress.bind(this,t),!1),r.onreadystatechange=function(){this._onXHRResponse(t,r)}.bind(this),this.xhrs.push(r),r}.bind(this))},_onXHRProgress:function(t,e){e.lengthComputable&&this._triggerEvent("lu:progress",{files:t,percentage:Math.floor(e.loaded/e.total*100)})},_onXHRResponse:function(t,e){e.readyState===4&&(this._triggerEvent("lu:finish"),e.status>=200&&e.status<300?this._triggerEvent("lu:success",{files:t,response:e.responseText}):this._triggerEvent("lu:fail",{xhr:e}))},startUpload:function(t){this._init(t)},addParam:function(t,e){this.options.params[t]=e},cancelUpload:function(){this._triggerEvent("lu:cancelled"),this.xhrs.forEac
7h(function(t){t.abort()})}},u})})(l)),l.exports}var g=c();export{g 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.