/** * @license uploadcare-widget v3.24.0 * * Copyright (c) 2026 Uploadcare, Inc. * * This source code is licensed under the BSD 2-Clause License * found in the LICENSE file in the root directory of this source tree. */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).uploadcare=t(e.$)}(this,(function(e){"use strict";function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=t(e);function n(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,i)}return a}function r(e){for(var t=1;te.length)&&(t=e.length);for(var a=0,i=new Array(t);a1&&void 0!==arguments[1]?arguments[1]:{};return P(a,e,t,i)}})),j()&&window.XDomainRequest&&a.default.ajaxTransport((function(e){var t;if(e.crossDomain&&e.async)return e.timeout&&(e.xdrTimeout=e.timeout,delete e.timeout),{send:function(a,i){function n(e,a,n,r){t.onload=t.onerror=t.ontimeout=function(){},t=void 0,i(e,a,n,r)}(t=new XDomainRequest).onload=function(){n(200,"OK",{text:t.responseText},"Content-Type: "+t.contentType)},t.onerror=function(){n(404,"Not Found")},t.onprogress=function(){},t.ontimeout=function(){n(0,"timeout")},t.timeout=e.xdrTimeout||Number.MAX_VALUE,t.open(e.type,e.url.replace(/^https?:/,"")),t.send(e.hasContent&&e.data||null)},abort:function(){t&&(t.onerror=function(){},t.abort())}}}));var M=j()&&!!(window.File&&window.FileList&&window.FileReader),O=j()&&!(!window.FormData||!M),E=j()&&function(){var e;return"draggable"in(e=document.createElement("div"))||"ondragstart"in e&&"ondrop"in e}(),B=j()&&function(){var e;return!(!(e=document.createElement("canvas")).getContext||!e.getContext("2d"))}(),U=M&&E,R=null,L=j()&&/^[^(]+\(iP(?:hone|od|ad);\s*(.+?)\)/.exec(navigator.userAgent);if(L){var V=/OS (\d*)_(\d*)/.exec(L[1]);V&&(R=+V[1]+V[2]/10)}var N=j()&&navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform),q=!1;try{j()&&new window.Blob&&(q=window.Blob)}catch(e){}var K=j()&&(window.URL||window.webkitURL||!1),H=K&&K.createObjectURL&&K,W=j()&&(null!=window.FileReader?window.FileReader.prototype.readAsArrayBuffer:void 0)&&window.FileReader,G=[].indexOf,Z=function(e){var t,a,i,n;for(n=[],a=0,i=e.length;a1&&void 0!==arguments[1]?arguments[1]:"i";return t=a.default.map(e.split("*"),ue),new RegExp("^"+t.join(".+")+"$",i)},de=function(e){var t;return"http:"!==(t=document.location.protocol)&&(t="https:"),e.replace(/^\/\//,t+"//").replace(/\/+$/,"")},pe=function(e,t){if(e.length>t){var a=Math.ceil((t-3)/2),i=Math.floor((t-3)/2);return e.slice(0,a)+"..."+e.slice(-i)}return e},fe=function(e,t,a){var i,n;return e[0]>t[0]||e[1]>t[1]||a?(n=t[0]/e[0],i=t[1]/e[1],!t[0]||t[1]&&n>i?[Math.round(i*e[0]),t[1]]:[t[0],Math.round(n*e[1])]):e.slice()},he=function(e,t,i,n){var r,o,l,s,u,c,d;if(c=n.width,o=n.height,s=t.preferedSize,l="",(d=c===i[0]&&o===i[1])||(l+="-/crop/".concat(c,"x").concat(o,"/").concat(n.left,",").concat(n.top,"/")),r=t.downscale&&(c>s[0]||o>s[1]),u=t.upscale&&(c'):a.default('')).attr("accept",n).css({position:"absolute",top:0,opacity:0,margin:0,padding:0,width:"auto",height:"auto",cursor:e.css("cursor")}).on("change",(function(){return i(this),a.default(this).hide(),o()})),e.append(r)})(),e.css({position:"relative",overflow:"hidden"}).mousemove((function(e){var t,i,n,o=a.default(this).offset();return t=o.left,i=o.top,n=r.width(),r.css({left:e.pageX-t-n+10,top:e.pageY-i-10})}))},_e=function(e,t,i){var n,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return""===(n=t.inputAcceptTypes)&&(n=t.imagesOnly?me:null),a.default(t.multiple?'':'').attr("accept",n).attr(r).css({position:"fixed",bottom:0,opacity:0}).on("change",(function(){return i(this),a.default(this).remove()})).appendTo(e).focus().click().hide()},ve="B KB MB GB TB PB EB ZB YB".split(" "),be=function(e){var t,a,i,n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";if(e=parseInt(e,10),isNaN(e))return r;for(t=2,i=0,n=1e3-5*Math.pow(10,2-Math.max(t,3));e>n&&i3&&void 0!==arguments[3]?arguments[3]:{},r=a.default.ajax(a.default.extend({url:e,type:t,data:i},n,ye)).retry(n.retryConfig).fail((function(t,a,i){var n="".concat(a," (").concat(i,")");S("JSONP unexpected error: ".concat(n," while loading ").concat(e))})),o=r.then((function(e){var t,i;return e.error?("string"==typeof e.error?(t=e.error,i=e.error_code):(t=e.error.content,i=e.error.error_code),a.default.Deferred().reject({message:t,code:i})):e}));return o.abort=r.abort.bind(r),o},xe=function(e,t,a,i){var n,r,o,l,s,u;if(window.HTMLCanvasElement.prototype.toBlob)return e.toBlob(i,t,a);for(o=(o=e.toDataURL(t,a)).split(","),r=window.atob(o[1]),n=new Uint8Array(r.length),l=s=0,u=r.length;s1?t-1:0),n=1;na&&o)return r;if(r=e*t})),r=Oe.dimension.find((function(a){return a>=e&&a>=t}));if(!n||!r)return i.reject();var o=[Re(n,n),Le(r,1)];return a.default.when.apply(a.default,o).done((function(e,t){e&&t?i.resolve():i.reject()})),i.promise()}const Ne=e=>{if(e<=0n)return"0";let t="";for(;e>0n;){t="0123456789abcdefghijklmnopqrstuvwxyz"[Number(e%36n)]+t,e/=36n}return t},qe="0123456789abcdef".split(""),Ke=[-2147483648,8388608,32768,128],He=[24,16,8,0],We=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]; /** * [js-sha256]{@link https://github.com/emn178/js-sha256} * * @license MIT * @version 0.11.1 * @author Chen, Yi-Cyuan [emn178@gmail.com] * @copyright Chen, Yi-Cyuan 2014-2025 */class Ge{blocks;h0;h1;h2;h3;h4;h5;h6;h7;block;start;bytes;hBytes;first;lastByteIndex;constructor(){this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],this.h0=1779033703,this.h1=3144134277,this.h2=1013904242,this.h3=2773480762,this.h4=1359893119,this.h5=2600822924,this.h6=528734635,this.h7=1541459225,this.block=this.start=this.bytes=this.hBytes=0,this.first=!0,this.lastByteIndex=0}update(e){let t,a,i=0;const n=e.length,r=this.blocks;for(;i>>2]|=t<>>2]|=(192|t>>>6)<>>2]|=(128|63&t)<=57344?(r[a>>>2]|=(224|t>>>12)<>>2]|=(128|t>>>6&63)<>>2]|=(128|63&t)<>>2]|=(240|t>>>18)<>>2]|=(128|t>>>12&63)<>>2]|=(128|t>>>6&63)<>>2]|=(128|63&t)<=64?(this.block=r[16],this.start=a-64,this.hash()):this.start=a}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}finalize(){const e=this.blocks,t=this.lastByteIndex;e[16]=this.block,e[t>>>2]|=Ke[3&t],this.block=e[16],t>=56&&(e[0]=this.block,e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=this.hBytes<<3|this.bytes>>>29,e[15]=this.bytes<<3,this.hash()}hash(){let e,t,a,i,n,r,o,l,s,u,c,d=this.h0,p=this.h1,f=this.h2,h=this.h3,m=this.h4,g=this.h5,_=this.h6,v=this.h7;const b=this.blocks;for(e=16;e<64;++e)n=b[e-15],t=(n>>>7|n<<25)^(n>>>18|n<<14)^n>>>3,n=b[e-2],a=(n>>>17|n<<15)^(n>>>19|n<<13)^n>>>10,b[e]=b[e-16]+t+b[e-7]+a<<0;for(c=p&f,e=0;e<64;e+=4)this.first?(l=704751109,n=b[0]-210244248,v=n-1521486534<<0,h=n+143694565<<0,this.first=!1):(t=(d>>>2|d<<30)^(d>>>13|d<<19)^(d>>>22|d<<10),a=(m>>>6|m<<26)^(m>>>11|m<<21)^(m>>>25|m<<7),l=d&p,i=l^d&f^c,o=m&g^~m&_,n=v+a+o+We[e]+b[e],r=t+i,v=h+n<<0,h=n+r<<0),t=(h>>>2|h<<30)^(h>>>13|h<<19)^(h>>>22|h<<10),a=(v>>>6|v<<26)^(v>>>11|v<<21)^(v>>>25|v<<7),s=h&d,i=s^h&p^l,o=v&m^~v&g,n=_+a+o+We[e+1]+b[e+1],r=t+i,_=f+n<<0,f=n+r<<0,t=(f>>>2|f<<30)^(f>>>13|f<<19)^(f>>>22|f<<10),a=(_>>>6|_<<26)^(_>>>11|_<<21)^(_>>>25|_<<7),u=f&h,i=u^f&d^s,o=_&v^~_&m,n=g+a+o+We[e+2]+b[e+2],r=t+i,g=p+n<<0,p=n+r<<0,t=(p>>>2|p<<30)^(p>>>13|p<<19)^(p>>>22|p<<10),a=(g>>>6|g<<26)^(g>>>11|g<<21)^(g>>>25|g<<7),c=p&f,i=c^p&h^u,o=g&_^~g&v,n=m+a+o+We[e+3]+b[e+3],r=t+i,m=d+n<<0,d=n+r<<0;this.h0=this.h0+d<<0,this.h1=this.h1+p<<0,this.h2=this.h2+f<<0,this.h3=this.h3+h<<0,this.h4=this.h4+m<<0,this.h5=this.h5+g<<0,this.h6=this.h6+_<<0,this.h7=this.h7+v<<0}hex(){this.finalize();const e=this.h0,t=this.h1,a=this.h2,i=this.h3,n=this.h4,r=this.h5,o=this.h6,l=this.h7;return qe[e>>>28&15]+qe[e>>>24&15]+qe[e>>>20&15]+qe[e>>>16&15]+qe[e>>>12&15]+qe[e>>>8&15]+qe[e>>>4&15]+qe[15&e]+qe[t>>>28&15]+qe[t>>>24&15]+qe[t>>>20&15]+qe[t>>>16&15]+qe[t>>>12&15]+qe[t>>>8&15]+qe[t>>>4&15]+qe[15&t]+qe[a>>>28&15]+qe[a>>>24&15]+qe[a>>>20&15]+qe[a>>>16&15]+qe[a>>>12&15]+qe[a>>>8&15]+qe[a>>>4&15]+qe[15&a]+qe[i>>>28&15]+qe[i>>>24&15]+qe[i>>>20&15]+qe[i>>>16&15]+qe[i>>>12&15]+qe[i>>>8&15]+qe[i>>>4&15]+qe[15&i]+qe[n>>>28&15]+qe[n>>>24&15]+qe[n>>>20&15]+qe[n>>>16&15]+qe[n>>>12&15]+qe[n>>>8&15]+qe[n>>>4&15]+qe[15&n]+qe[r>>>28&15]+qe[r>>>24&15]+qe[r>>>20&15]+qe[r>>>16&15]+qe[r>>>12&15]+qe[r>>>8&15]+qe[r>>>4&15]+qe[15&r]+qe[o>>>28&15]+qe[o>>>24&15]+qe[o>>>20&15]+qe[o>>>16&15]+qe[o>>>12&15]+qe[o>>>8&15]+qe[o>>>4&15]+qe[15&o]+qe[l>>>28&15]+qe[l>>>24&15]+qe[l>>>20&15]+qe[l>>>16&15]+qe[l>>>12&15]+qe[l>>>8&15]+qe[l>>>4&15]+qe[15&l]}}const Ze=e=>{const t=function(e){const t=new Ge;t.update(e);const a=t.hex();return BigInt("0x"+a)}(e);return Ne(t).slice(0,10)},Xe=(e,t)=>((e,t)=>{const a=new URL(t);return a.hostname=`${e}.${a.hostname}`,a.toString().replace(/\/$/,"")})(Ze(e),t);var Ye,Je,Qe,$e,et,tt,at,it,nt,rt,ot,lt,st,ut,ct,dt,pt,ft,ht,mt,gt,_t,vt,bt=[].indexOf;et={live:!0,manualStart:!1,locale:null,localePluralize:null,localeTranslations:null,systemDialog:!1,crop:!1,previewStep:!1,imagesOnly:!1,clearable:!1,multiple:!1,multipleMax:1e3,multipleMin:1,multipleMaxStrict:!1,imageShrink:!1,pathValue:!0,tabs:"file camera url facebook gdrive gphotos dropbox instagram evernote flickr onedrive",preferredTypes:"",inputAcceptTypes:"",doNotStore:!1,publicKey:null,secureSignature:"",secureExpire:"",pusherKey:"79ae88bd931ea68464d9",cdnBase:"https://ucarecdn.com",cdnBasePrefixed:"https://ucarecd.net",urlBase:"https://upload.uploadcare.com",socialBase:"https://social.uploadcare.com",previewProxy:null,previewUrlCallback:null,remoteTabSessionKey:null,metadata:null,metadataCallback:null,imagePreviewMaxSize:26214400,multipartMinSize:10485760,multipartPartSize:5242880,multipartMinLastPartSize:1048576,multipartConcurrency:4,multipartMaxAttempts:null,retryAttempts:3,retryThrottledAttempts:10,retryBaseTimeout:1e3,retryFactor:2,parallelDirectUploads:10,passWindowOpen:!1,cameraMirrorDefault:!0,enableAudioRecording:!0,enableVideoRecording:!0,videoPreferredMimeTypes:null,audioBitsPerSecond:null,videoBitsPerSecond:null,topLevelOrigin:null,scriptBase:"//ucarecdn.com/widget/".concat("3.24.0","/uploadcare/"),debugUploads:!1,integration:""},tt=r({},et),ht={multipleMax:{from:0,to:1e3}},Qe={multipleMax:{min:1,max:1e3}},ct={tabs:{all:"file camera url facebook gdrive gphotos dropbox instagram evernote flickr onedrive box vk huddle",default:et.tabs}},dt=j()&&(document.currentScript||(vt=document.getElementsByTagName("script"))[vt.length-1]),(nt=j()&&a.default(dt).data("integration"))&&null!=nt&&(et=a.default.extend(et,{integration:nt})),pt=function(e){return a.default.isArray(e)||(e=(e=a.default.trim(e))?e.split(" "):[]),e},Ye=function(e,t){var a,i,n,r,o,l,s,u,c=Object.prototype.hasOwnProperty;for(a=0,o=t.length;an?(T("Shrinked size can not be larger than ".concat(Math.floor(n/1e3/1e3),"MP. ")+"You have set ".concat(t[1],"x").concat(t[2]," (")+"".concat(Math.ceil(i/1e3/100)/10,"MP).")),!1):{quality:t[3]?t[3]/100:void 0,size:i}},$e=function(e,t){var a,i,n,r;return this.previewProxy?(i=(n=!/\?/.test(this.previewProxy))||!/=$/.test(this.previewProxy),a=!n&&!/[&?=]$/.test(this.previewProxy),r=encodeURIComponent(e),i&&(r="url="+r),a&&(r="&"+r),n&&(r="?"+r),this.previewProxy+r):e},lt=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];Ye(e,["tabs","preferredTypes","videoPreferredMimeTypes"]),mt(e,["cdnBase","socialBase","urlBase","scriptBase","cdnBasePrefixed","topLevelOrigin"]),at(e,["doNotStore","imagesOnly","multiple","clearable","pathValue","previewStep","systemDialog","debugUploads","multipleMaxStrict","cameraMirrorDefault"]),it(e,["multipleMax","multipleMin","multipartMinSize","multipartPartSize","multipartMinLastPartSize","multipartConcurrency","multipartMaxAttempts","retryAttempts","retryThrottledAttempts","retryBaseTimeout","retryFactor","parallelDirectUploads"]),gt(e,["previewUrlCallback","metadataCallback"]),_t(e,["metadata"]),ft(e,ht),Je(e,Qe),rt(e),ot(e),!1===e.crop||a.default.isArray(e.crop)||(/^(disabled?|false|null)$/i.test(e.crop)?e.crop=!1:a.default.isPlainObject(e.crop)?e.crop=[e.crop]:e.crop=a.default.map((""+e.crop).split(","),st)),e.imageShrink&&!a.default.isPlainObject(e.imageShrink)&&(e.imageShrink=ut(e.imageShrink)),(e.crop||e.multiple)&&(e.previewStep=!0),O||(e.systemDialog=!1),e.validators&&(e.validators=e.validators.slice()),e.previewProxy&&!e.previewUrlCallback&&(e.previewUrlCallback=$e);var i=e.tabs.indexOf("skydrive");return-1!==i&&(e.tabs[i]="onedrive"),!t.includes("cdnBase")&&e.publicKey&&e.cdnBase===tt.cdnBase&&(e.cdnBase=Xe(e.publicKey,e.cdnBasePrefixed)),e};var yt,wt=function(){var e={},t=[];for(var a in et){var i=window["UPLOADCARE_".concat(te(a))];null!=i&&(t.push(a),e[a]=i)}return Object.defineProperty(e,"__dirtyKeys",{value:t,enumerable:!1,writable:!1,configurable:!1}),e},xt=J((function(e,t){var i=[];if(!t){var n=wt();i.push.apply(i,x(n.__dirtyKeys)),et=a.default.extend(et,n)}var r=e||{};i.push.apply(i,x(Object.keys(r)));var o=lt(a.default.extend(et,r),i);return zt.fire(o),Object.defineProperty(o,"__dirtyKeys",{value:i,enumerable:!1,writable:!1,configurable:!1}),o})),kt=function(e){var t=[],i=xt();t.push.apply(t,x(i.__dirtyKeys));var n=a.default.extend({},i);if(!a.default.isEmptyObject(e)){var r=Object.keys(e);t.push.apply(t,r),n=lt(a.default.extend(n,e),t)}return n},zt=j()&&a.default.Callbacks("once memory"),At=function(){function e(){u(this,e),this.urls=[],this.styles=[]}return d(e,[{key:"addUrl",value:function(e){if(!/^https?:\/\//i.test(e))throw new Error("Embedded urls should be absolute. "+e);if(!(bt.call(this.urls,e)>=0))return this.urls.push(e)}},{key:"addStyle",value:function(e){return this.styles.push(e)}}]),e}(),Ct=function(e,t){var i;return i=a.default.Deferred(),t&&(e.src=t),e.complete?i.resolve(e):(a.default(e).one("load",(function(){return i.resolve(e)})),a.default(e).one("error",(function(){return i.reject(e)}))),i.promise()},St=function e(t){return a.default.isArray(t)?a.default.when.apply(null,a.default.map(t,e)):t.src?Ct(t):Ct(new window.Image,t)},Ft=function(e){var t=a.default.Deferred();return a.default("").on("loadeddata",t.resolve).on("error",t.reject).attr("src",e).get(0).load(),t.promise()},Tt=function(){var e=a.default.Deferred();if(void 0!==yt)e.resolve(yt);else{var t=new window.Image;t.onload=function(){yt=t.naturalWidth=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,o=!0,l=!1;return{s:function(){a=a.call(e)},n:function(){var e=a.next();return o=e.done,e},e:function(e){l=!0,r=e},f:function(){try{o||null==a.return||a.return()}finally{if(l)throw r}}}}(o);try{var d=function(){var e=w(u.value,2),n=e[0],r=e[1];s=s.then((function(e){var t=a.default.Deferred();return Ve(n,r).then((function(){return t.resolve(e,!1)})).fail((function(){return t.resolve(e,!0)})),t.promise()})).then((function(e,t){return t?e:jt(e,n,r)})).then((function(e){return l.notify((t-n)/(t-i)),e}))};for(c.s();!(u=c.n()).done;)d()}catch(e){c.e(e)}finally{c.f()}return s.done((function(e){l.resolve(e)})),s.fail((function(e){l.reject(e)})),l.promise()},It=function(e,t){var i=a.default.Deferred();if(.71*e.width*e.height*.710&&(r=r.then((function(e){return Nt(e,l)})).catch((function(){return t}))),r.done(i.resolve),r.fail((function(){return i.resolve(t)}))}))}))}))}))})),i.promise()):i.reject("support")},Et=function(e,t,i,n,r){var o,l;return o=a.default.Deferred(),H?((l=St(H.createObjectURL(e))).always((function(e){return H.revokeObjectURL(e.src)})),l.fail((function(){return o.reject("not image")})),l.done((function(l){return o.always((function(){l.src="//:0"})),r&&l.width*l.height>r?o.reject("max source"):a.default.when(Rt(e),Tt()).always((function(e,a){var r=a?1:Wt(e)||1,s=r>4,u=s?[l.height,l.width]:[l.width,l.height],c=w(fe(u,[t,i]),2),d=c[0],p=c[1],f=[[1,0,0,1,0,0],[-1,0,0,1,d,0],[-1,0,0,-1,d,p],[1,0,0,-1,0,p],[0,1,1,0,0,0],[0,1,-1,0,d,0],[0,-1,-1,0,d,p],[0,-1,1,0,0,p]][r-1];if(!f)return o.reject("bad image");var h=document.createElement("canvas");h.width=d,h.height=p;var m=h.getContext("2d");if(m.transform.apply(m,f),s){var g=[p,d];d=g[0],p=g[1]}return n&&(m.fillStyle=n,m.fillRect(0,0,d,p)),m.drawImage(l,0,0,d,p),o.resolve(h,u)}))})),o.promise()):o.reject("support")},Bt=function(e){var t,i,n,r,o;return o=function(e,a){var i;return(i=new W).onload=function(){return a(new Pt(i.result))},i.onerror=function(e){return t.reject("reader",e)},i.readAsArrayBuffer(e)},n=function(){return o(e.slice(i,i+128),(function(e){var t,a,n;for(t=a=0,n=e.byteLength;n>=0?an;t=n>=0?++a:--a)if(255===e.getUint8(t)){i+=t;break}return r()}))},r=function(){var a;return a=i,o(e.slice(i,i+=4),(function(r){var l,s;return 4!==r.byteLength||255!==r.getUint8(0)?t.reject("corrupted"):218===(s=r.getUint8(1))?t.resolve():(l=r.getUint16(2)-2,o(e.slice(i,i+=l),(function(e){return e.byteLength!==l?t.reject("corrupted"):(t.notify(a,l,s,e),n())})))}))},t=a.default.Deferred(),W&&Pt?(i=2,o(e.slice(0,2),(function(e){return 65496!==e.getUint16(0)?t.reject("not jpeg"):n()})),t.promise()):t.reject("support")},Ut=function(e,t,i){var n,r,o,l;return n=a.default.Deferred(),o=[],r=[],(l=Bt(e)).fail(n.reject),l.progress((function(e,a,i){if(i===t)return o.push(e),r.push(a)})),l.done((function(){var a,l,s,u,c,d,p,f,h;for(p=[e.slice(0,2)],u=0,d=i.length;u=0?ch;l=h>=0?++c:--c)o[l]>f&&p.push(e.slice(f,o[l])),f=o[l]+r[l]+4;return p.push(e.slice(f,e.size)),n.resolve(new q(p,{type:e.type}))})),n.promise()},Rt=function(e){var t=null,i=Bt(e);return i.progress((function(e,a,i,n){if(!t&&225===i&&n.byteLength>=14&&1165519206===n.getUint32(0)&&0===n.getUint16(4))return t=n})),i.then((function(){return t}),(function(){return a.default.Deferred().reject(t)}))},Lt=function(e){var t=[],i=Bt(e);return i.progress((function(e,a,i,n){226===i&&1229144927===n.getUint32(0)&&1347571526===n.getUint32(4)&&1229735168===n.getUint32(8)&&t.push(n)})),i.then((function(){return t}),(function(){return a.default.Deferred().reject(t)}))},Vt=function(e,t,a){return a&&Ht(t,1),Ut(e,225,[t.buffer])},Nt=function(e,t){return Ut(e,226,t.map((function(e){return e.buffer})))},qt=function(e){var t=a.default.Deferred();return Nt(e,[]).catch((function(){return e})).then((function(e){var a=St(H.createObjectURL(e));a.always((function(e){H.revokeObjectURL(e.src)})),a.fail((function(){t.reject()})),a.done((function(e){t.resolve(e)}))})).fail((function(){t.reject()})),t.promise()},Kt=function(e){var t=[1,3],a=[192,193,194,195,197,198,199,201,202,203,205,206,207],i=!1,n=Bt(e);return n.progress((function(e,n,r,o){if(!i&&a.indexOf(r)>=0){var l=o.getUint8(5);t.indexOf(l)<0&&(i=!0)}})),n.then((function(){return i})).catch((function(){return i}))},Ht=function(e,t){Gt(e,(function(a,i){return e.setUint16(a,t,i)}))},Wt=function(e){return Gt(e,(function(t,a){return e.getUint16(t,a)}))},Gt=function(e,t){var a,i,n,r;if(!e||e.byteLength<14||1165519206!==e.getUint32(0)||0!==e.getUint16(4))return null;if(18761===e.getUint16(6))i=!0;else{if(19789!==e.getUint16(6))return null;i=!1}if(42!==e.getUint16(8,i))return null;for(n=8+e.getUint32(10,i),a=0,r=e.getUint16(n-2,i);r>=0?ar;r>=0?++a:--a){if(e.byteLength2&&void 0!==arguments[2]?arguments[2]:{};u(this,e),this.settings=a,this.sourceInfo=n,this.fileId=null,this.fileName=null,this.sanitizedName=null,this.fileSize=null,this.isStored=null,this.cdnUrlModifiers=null,this.isImage=null,this.imageInfo=null,this.videoInfo=null,this.contentInfo=null,this.mimeType=null,this.s3Bucket=null,this.metadata=null,(i=this.sourceInfo).source||(i.source=this.sourceName),this.__setupValidation(),this.__initApi()}return d(e,[{key:"__startUpload",value:function(){return a.default.Deferred().resolve()}},{key:"__completeUpload",value:function(){var e,t,a,i,n=this;return a=0,this.settings.debugUploads&&(C("Load file info.",this.fileId,this.settings.publicKey),t=setInterval((function(){return C("Still waiting for file ready.",a,n.fileId,n.settings.publicKey)}),5e3),this.apiDeferred.done((function(){return C("File uploaded.",a,n.fileId,n.settings.publicKey)})).always((function(){return clearInterval(t)}))),i=100,(e=function(){if("pending"===n.apiDeferred.state())return a+=1,n.__updateInfo().done((function(){return setTimeout(e,i),i+=50}))})()}},{key:"__updateInfo",value:function(){var e=this;return we("".concat(this.settings.urlBase,"/info/"),"GET",{jsonerrors:1,file_id:this.fileId,pub_key:this.settings.publicKey,wait_is_ready:+(null===this.isImage)},{headers:{"X-UC-User-Agent":this.settings._userAgent},retryConfig:this.settings.retryConfig}).fail((function(t){return e.settings.debugUploads&&A("Can't load file info. Probably removed.",e.fileId,e.settings.publicKey,t.message),e.__rejectApi("info",t)})).done(this.__handleFileData.bind(this))}},{key:"__handleFileData",value:function(e){if(this.fileName=e.original_filename,this.sanitizedName=e.filename,this.fileSize=e.size,this.isImage=e.is_image,this.imageInfo=e.image_info,this.videoInfo=e.video_info,this.contentInfo=e.content_info,this.mimeType=e.mime_type,this.isStored=e.is_stored,this.s3Bucket=e.s3_bucket,this.metadata=e.metadata,e.default_effects&&(this.cdnUrlModifiers="-/"+e.default_effects),this.s3Bucket&&this.cdnUrlModifiers&&this.__rejectApi("baddata"),this.__runValidators(),e.is_ready)return this.__resolveApi()}},{key:"__progressInfo",value:function(){var e;return{state:this.__progressState,uploadProgress:this.__progress,progress:"ready"===(e=this.__progressState)||"error"===e?1:.9*this.__progress,incompleteFileInfo:this.__fileInfo()}}},{key:"__fileInfo",value:function(){var e;return e=this.s3Bucket?"https://".concat(this.s3Bucket,".s3.amazonaws.com/").concat(this.fileId,"/").concat(this.sanitizedName):"".concat(this.settings.cdnBase,"/").concat(this.fileId,"/"),{uuid:this.fileId,name:this.fileName,size:this.fileSize,isStored:this.isStored,isImage:this.isImage,originalImageInfo:this.imageInfo,originalVideoInfo:this.videoInfo,originalContentInfo:this.contentInfo,mimeType:this.mimeType,originalUrl:this.fileId?e:null,cdnUrl:this.fileId?"".concat(e).concat(this.cdnUrlModifiers||""):null,cdnUrlModifiers:this.cdnUrlModifiers,sourceInfo:this.sourceInfo,metadata:this.metadata}}},{key:"__setupValidation",value:function(){if(this.validators=this.settings.validators||this.settings.__validators||[],this.settings.imagesOnly)return this.validators.push((function(e){if(!1===e.isImage)throw new Error("image")}))}},{key:"__runValidators",value:function(){var e,t,a,i,n,r,o;a=this.__fileInfo();try{for(n=this.validators,r=[],t=0,i=n.length;tt.__progress)return t.__progress=e,t.__notifyApi()})),e.fail((function(e){return t.__rejectApi("upload",e)})),this.apiDeferred.always(e.reject))),this.__apiPromise}}]),e}(),Yt=null,Jt=function(e){f(i,e);var t=v(i);function i(e){var a;return u(this,i),(a=t.apply(this,arguments)).__file=e,a.fileName=a.__file.name||"original",a.__notifyApi(),a}return d(i,[{key:"setFile",value:function(e){if(e&&(this.__file=e),this.sourceInfo.file=this.__file,this.__file)return this.fileSize=this.__file.size,this.fileType=this.__file.type||"application/octet-stream",this.settings.debugUploads&&C("Use local file.",this.fileName,this.fileType,this.fileSize),this.__runValidators(),this.__notifyApi()}},{key:"__startUpload",value:function(){var e,t,i,n=this;return this.apiDeferred.always((function(){return n.__file=null,n.__file})),this.__file.size>=this.settings.multipartMinSize&&q?(this.setFile(),this.multipartUpload()):(t=R,!this.settings.imageShrink||t&&t<8?(this.setFile(),this.directUpload()):(e=a.default.Deferred(),i=.4,Ot(this.__file,this.settings.imageShrink).progress((function(t){return e.notify(t*i)})).done(this.setFile.bind(this)).fail((function(){return n.setFile(),i*=.1})).always((function(){return e.notify(i),n.directUpload().done(e.resolve).fail(e.reject).progress((function(t){return e.notify(i+t*(1-i))}))})),e))}},{key:"__autoAbort",value:function(e){return this.apiDeferred.fail((function(){return e.abort()})),e}},{key:"directRunner",value:function(e){return Yt||(Yt=ke(this.settings.parallelDirectUploads)),Yt(e)}},{key:"directUpload",value:function(){var e,t=this;return e=a.default.Deferred(),this.__file?this.fileSize>104857600?(this.__rejectApi("size"),e):(this.directRunner((function(i){if(e.always(i),"pending"===t.apiDeferred.state()){var n=new window.FormData;return n.append("UPLOADCARE_PUB_KEY",t.settings.publicKey),n.append("signature",t.settings.secureSignature),n.append("expire",t.settings.secureExpire),n.append("UPLOADCARE_STORE",t.settings.doNotStore?"":"auto"),n.append("file",t.__file,t.fileName),n.append("file_name",t.fileName),n.append("source",t.sourceInfo.source),a.default.each(Ce(t.settings),(function(e,t){n.append("metadata[".concat(e,"]"),t)})),t.__autoAbort(a.default.ajax({xhr:function(){var t;return t=a.default.ajaxSettings.xhr(),t.upload&&t.upload.addEventListener("progress",(function(t){return e.notify(t.loaded/t.total)}),!1),t},crossDomain:!0,type:"POST",url:"".concat(t.settings.urlBase,"/base/?jsonerrors=1"),headers:{"X-UC-User-Agent":t.settings._userAgent},contentType:!1,processData:!1,data:n,dataType:"json"}).retry(t.settings.retryConfig).done((function(a){if(null!=a?a.file:void 0)return t.fileId=a.file,e.resolve();if(a.error){var i=a.error,n=i.content,r=i.error_code;return e.reject({message:n,code:r})}return e.reject()})).fail(e.reject))}})),e):(this.__rejectApi("baddata"),e)}},{key:"multipartUpload",value:function(){var e,t=this;return e=a.default.Deferred(),this.__file?(this.multipartStart().done((function(a){return t.uploadParts(a.parts,a.uuid).done((function(){return t.multipartComplete(a.uuid).done((function(a){return t.fileId=a.uuid,t.__handleFileData(a),e.resolve()})).fail(e.reject)})).progress(e.notify).fail(e.reject)})).fail(e.reject),e):e}},{key:"multipartStart",value:function(){var e=this,t={UPLOADCARE_PUB_KEY:this.settings.publicKey,signature:this.settings.secureSignature,expire:this.settings.secureExpire,filename:this.fileName,source:this.sourceInfo.source,size:this.fileSize,content_type:this.fileType,part_size:this.settings.multipartPartSize,UPLOADCARE_STORE:this.settings.doNotStore?"":"auto"};return a.default.each(Ce(this.settings),(function(e,a){t["metadata[".concat(e,"]")]=a})),this.__autoAbort(we("".concat(this.settings.urlBase,"/multipart/start/?jsonerrors=1"),"POST",t,{headers:{"X-UC-User-Agent":this.settings._userAgent},retryConfig:this.settings.retryConfig})).fail((function(a){if(e.settings.debugUploads)return A("Can't start multipart upload.",a.message,t)}))}},{key:"uploadParts",value:function(e,t){var i,n,o,l,s,u,c,d,p,f,h=this;for(s=[],l=Date.now(),f=function(e,t){var a,n,r;if(s[e]=t,!(Date.now()-l<250)){for(l=Date.now(),r=0,a=0,n=s.length;a=h.fileSize)){var o=d+h.settings.multipartPartSize;h.fileSize=0?ou;u>=0?++o:--o)c();return i}},{key:"multipartComplete",value:function(e){var t,a=this;return t={UPLOADCARE_PUB_KEY:this.settings.publicKey,uuid:e},this.__autoAbort(we("".concat(this.settings.urlBase,"/multipart/complete/?jsonerrors=1"),"POST",t,{headers:{"X-UC-User-Agent":this.settings._userAgent},retryConfig:this.settings.retryConfig})).fail((function(t){if(a.settings.debugUploads)return A("Can't complete multipart upload.",e,a.settings.publicKey,t.message)}))}}]),i}(Xt);Jt.prototype.sourceName="local";var Qt=function(e){f(i,e);var t=v(i);function i(e){var n;return u(this,i),(n=t.apply(this,arguments)).__input=e,n.fileId=ie(),n.fileName=a.default(n.__input).val().split("\\").pop(),n.__notifyApi(),n}return d(i,[{key:"__startUpload",value:function(){var e,t,i,n;return e=a.default.Deferred(),n="".concat(this.settings.urlBase,"/iframe/"),i="uploadcare--iframe-".concat(this.fileId),this.__iframe=a.default("