dropzone.mjs 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111
  1. import $ewBKy$justextend from "just-extend";
  2. function $parcel$interopDefault(a) {
  3. return a && a.__esModule ? a.default : a;
  4. }
  5. class $4040acfd8584338d$export$2e2bcd8739ae039 {
  6. // Add an event listener for given event
  7. on(event, fn) {
  8. this._callbacks = this._callbacks || {
  9. };
  10. // Create namespace for this event
  11. if (!this._callbacks[event]) this._callbacks[event] = [];
  12. this._callbacks[event].push(fn);
  13. return this;
  14. }
  15. emit(event, ...args) {
  16. this._callbacks = this._callbacks || {
  17. };
  18. let callbacks = this._callbacks[event];
  19. if (callbacks) for (let callback of callbacks)callback.apply(this, args);
  20. // trigger a corresponding DOM event
  21. if (this.element) this.element.dispatchEvent(this.makeEvent("dropzone:" + event, {
  22. args: args
  23. }));
  24. return this;
  25. }
  26. makeEvent(eventName, detail) {
  27. let params = {
  28. bubbles: true,
  29. cancelable: true,
  30. detail: detail
  31. };
  32. if (typeof window.CustomEvent === "function") return new CustomEvent(eventName, params);
  33. else {
  34. // IE 11 support
  35. // https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
  36. var evt = document.createEvent("CustomEvent");
  37. evt.initCustomEvent(eventName, params.bubbles, params.cancelable, params.detail);
  38. return evt;
  39. }
  40. }
  41. // Remove event listener for given event. If fn is not provided, all event
  42. // listeners for that event will be removed. If neither is provided, all
  43. // event listeners will be removed.
  44. off(event, fn) {
  45. if (!this._callbacks || arguments.length === 0) {
  46. this._callbacks = {
  47. };
  48. return this;
  49. }
  50. // specific event
  51. let callbacks = this._callbacks[event];
  52. if (!callbacks) return this;
  53. // remove all handlers
  54. if (arguments.length === 1) {
  55. delete this._callbacks[event];
  56. return this;
  57. }
  58. // remove specific handler
  59. for(let i = 0; i < callbacks.length; i++){
  60. let callback = callbacks[i];
  61. if (callback === fn) {
  62. callbacks.splice(i, 1);
  63. break;
  64. }
  65. }
  66. return this;
  67. }
  68. }
  69. var $fd6031f88dce2e32$exports = {};
  70. $fd6031f88dce2e32$exports = "<div class=\"dz-preview dz-file-preview\">\n <div class=\"dz-image\"><img data-dz-thumbnail=\"\"></div>\n <div class=\"dz-details\">\n <div class=\"dz-size\"><span data-dz-size=\"\"></span></div>\n <div class=\"dz-filename\"><span data-dz-name=\"\"></span></div>\n </div>\n <div class=\"dz-progress\">\n <span class=\"dz-upload\" data-dz-uploadprogress=\"\"></span>\n </div>\n <div class=\"dz-error-message\"><span data-dz-errormessage=\"\"></span></div>\n <div class=\"dz-success-mark\">\n <svg width=\"54\" height=\"54\" viewBox=\"0 0 54 54\" fill=\"white\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M10.2071 29.7929L14.2929 25.7071C14.6834 25.3166 15.3166 25.3166 15.7071 25.7071L21.2929 31.2929C21.6834 31.6834 22.3166 31.6834 22.7071 31.2929L38.2929 15.7071C38.6834 15.3166 39.3166 15.3166 39.7071 15.7071L43.7929 19.7929C44.1834 20.1834 44.1834 20.8166 43.7929 21.2071L22.7071 42.2929C22.3166 42.6834 21.6834 42.6834 21.2929 42.2929L10.2071 31.2071C9.81658 30.8166 9.81658 30.1834 10.2071 29.7929Z\"></path>\n </svg>\n </div>\n <div class=\"dz-error-mark\">\n <svg width=\"54\" height=\"54\" viewBox=\"0 0 54 54\" fill=\"white\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M26.2929 20.2929L19.2071 13.2071C18.8166 12.8166 18.1834 12.8166 17.7929 13.2071L13.2071 17.7929C12.8166 18.1834 12.8166 18.8166 13.2071 19.2071L20.2929 26.2929C20.6834 26.6834 20.6834 27.3166 20.2929 27.7071L13.2071 34.7929C12.8166 35.1834 12.8166 35.8166 13.2071 36.2071L17.7929 40.7929C18.1834 41.1834 18.8166 41.1834 19.2071 40.7929L26.2929 33.7071C26.6834 33.3166 27.3166 33.3166 27.7071 33.7071L34.7929 40.7929C35.1834 41.1834 35.8166 41.1834 36.2071 40.7929L40.7929 36.2071C41.1834 35.8166 41.1834 35.1834 40.7929 34.7929L33.7071 27.7071C33.3166 27.3166 33.3166 26.6834 33.7071 26.2929L40.7929 19.2071C41.1834 18.8166 41.1834 18.1834 40.7929 17.7929L36.2071 13.2071C35.8166 12.8166 35.1834 12.8166 34.7929 13.2071L27.7071 20.2929C27.3166 20.6834 26.6834 20.6834 26.2929 20.2929Z\"></path>\n </svg>\n </div>\n</div>\n";
  71. let $4ca367182776f80b$var$defaultOptions = {
  72. /**
  73. * Has to be specified on elements other than form (or when the form doesn't
  74. * have an `action` attribute).
  75. *
  76. * You can also provide a function that will be called with `files` and
  77. * `dataBlocks` and must return the url as string.
  78. */ url: null,
  79. /**
  80. * Can be changed to `"put"` if necessary. You can also provide a function
  81. * that will be called with `files` and must return the method (since `v3.12.0`).
  82. */ method: "post",
  83. /**
  84. * Will be set on the XHRequest.
  85. */ withCredentials: false,
  86. /**
  87. * The timeout for the XHR requests in milliseconds (since `v4.4.0`).
  88. * If set to null or 0, no timeout is going to be set.
  89. */ timeout: null,
  90. /**
  91. * How many file uploads to process in parallel (See the
  92. * Enqueuing file uploads documentation section for more info)
  93. */ parallelUploads: 2,
  94. /**
  95. * Whether to send multiple files in one request. If
  96. * this it set to true, then the fallback file input element will
  97. * have the `multiple` attribute as well. This option will
  98. * also trigger additional events (like `processingmultiple`). See the events
  99. * documentation section for more information.
  100. */ uploadMultiple: false,
  101. /**
  102. * Whether you want files to be uploaded in chunks to your server. This can't be
  103. * used in combination with `uploadMultiple`.
  104. *
  105. * See [chunksUploaded](#config-chunksUploaded) for the callback to finalise an upload.
  106. */ chunking: false,
  107. /**
  108. * If `chunking` is enabled, this defines whether **every** file should be chunked,
  109. * even if the file size is below chunkSize. This means, that the additional chunk
  110. * form data will be submitted and the `chunksUploaded` callback will be invoked.
  111. */ forceChunking: false,
  112. /**
  113. * If `chunking` is `true`, then this defines the chunk size in bytes.
  114. */ chunkSize: 2097152,
  115. /**
  116. * If `true`, the individual chunks of a file are being uploaded simultaneously.
  117. */ parallelChunkUploads: false,
  118. /**
  119. * Whether a chunk should be retried if it fails.
  120. */ retryChunks: false,
  121. /**
  122. * If `retryChunks` is true, how many times should it be retried.
  123. */ retryChunksLimit: 3,
  124. /**
  125. * The maximum filesize (in MiB) that is allowed to be uploaded.
  126. */ maxFilesize: 256,
  127. /**
  128. * The name of the file param that gets transferred.
  129. * **NOTE**: If you have the option `uploadMultiple` set to `true`, then
  130. * Dropzone will append `[]` to the name.
  131. */ paramName: "file",
  132. /**
  133. * Whether thumbnails for images should be generated
  134. */ createImageThumbnails: true,
  135. /**
  136. * In MB. When the filename exceeds this limit, the thumbnail will not be generated.
  137. */ maxThumbnailFilesize: 10,
  138. /**
  139. * If `null`, the ratio of the image will be used to calculate it.
  140. */ thumbnailWidth: 120,
  141. /**
  142. * The same as `thumbnailWidth`. If both are null, images will not be resized.
  143. */ thumbnailHeight: 120,
  144. /**
  145. * How the images should be scaled down in case both, `thumbnailWidth` and `thumbnailHeight` are provided.
  146. * Can be either `contain` or `crop`.
  147. */ thumbnailMethod: "crop",
  148. /**
  149. * If set, images will be resized to these dimensions before being **uploaded**.
  150. * If only one, `resizeWidth` **or** `resizeHeight` is provided, the original aspect
  151. * ratio of the file will be preserved.
  152. *
  153. * The `options.transformFile` function uses these options, so if the `transformFile` function
  154. * is overridden, these options don't do anything.
  155. */ resizeWidth: null,
  156. /**
  157. * See `resizeWidth`.
  158. */ resizeHeight: null,
  159. /**
  160. * The mime type of the resized image (before it gets uploaded to the server).
  161. * If `null` the original mime type will be used. To force jpeg, for example, use `image/jpeg`.
  162. * See `resizeWidth` for more information.
  163. */ resizeMimeType: null,
  164. /**
  165. * The quality of the resized images. See `resizeWidth`.
  166. */ resizeQuality: 0.8,
  167. /**
  168. * How the images should be scaled down in case both, `resizeWidth` and `resizeHeight` are provided.
  169. * Can be either `contain` or `crop`.
  170. */ resizeMethod: "contain",
  171. /**
  172. * The base that is used to calculate the **displayed** filesize. You can
  173. * change this to 1024 if you would rather display kibibytes, mebibytes,
  174. * etc... 1024 is technically incorrect, because `1024 bytes` are `1 kibibyte`
  175. * not `1 kilobyte`. You can change this to `1024` if you don't care about
  176. * validity.
  177. */ filesizeBase: 1000,
  178. /**
  179. * If not `null` defines how many files this Dropzone handles. If it exceeds,
  180. * the event `maxfilesexceeded` will be called. The dropzone element gets the
  181. * class `dz-max-files-reached` accordingly so you can provide visual
  182. * feedback.
  183. */ maxFiles: null,
  184. /**
  185. * An optional object to send additional headers to the server. Eg:
  186. * `{ "My-Awesome-Header": "header value" }`
  187. */ headers: null,
  188. /**
  189. * Should the default headers be set or not?
  190. * Accept: application/json <- for requesting json response
  191. * Cache-Control: no-cache <- Request shouldnt be cached
  192. * X-Requested-With: XMLHttpRequest <- We sent the request via XMLHttpRequest
  193. */ defaultHeaders: true,
  194. /**
  195. * If `true`, the dropzone element itself will be clickable, if `false`
  196. * nothing will be clickable.
  197. *
  198. * You can also pass an HTML element, a CSS selector (for multiple elements)
  199. * or an array of those. In that case, all of those elements will trigger an
  200. * upload when clicked.
  201. */ clickable: true,
  202. /**
  203. * Whether hidden files in directories should be ignored.
  204. */ ignoreHiddenFiles: true,
  205. /**
  206. * The default implementation of `accept` checks the file's mime type or
  207. * extension against this list. This is a comma separated list of mime
  208. * types or file extensions.
  209. *
  210. * Eg.: `image/*,application/pdf,.psd`
  211. *
  212. * If the Dropzone is `clickable` this option will also be used as
  213. * [`accept`](https://developer.mozilla.org/en-US/docs/HTML/Element/input#attr-accept)
  214. * parameter on the hidden file input as well.
  215. */ acceptedFiles: null,
  216. /**
  217. * **Deprecated!**
  218. * Use acceptedFiles instead.
  219. */ acceptedMimeTypes: null,
  220. /**
  221. * If false, files will be added to the queue but the queue will not be
  222. * processed automatically.
  223. * This can be useful if you need some additional user input before sending
  224. * files (or if you want want all files sent at once).
  225. * If you're ready to send the file simply call `myDropzone.processQueue()`.
  226. *
  227. * See the [enqueuing file uploads](#enqueuing-file-uploads) documentation
  228. * section for more information.
  229. */ autoProcessQueue: true,
  230. /**
  231. * If false, files added to the dropzone will not be queued by default.
  232. * You'll have to call `enqueueFile(file)` manually.
  233. */ autoQueue: true,
  234. /**
  235. * If `true`, this will add a link to every file preview to remove or cancel (if
  236. * already uploading) the file. The `dictCancelUpload`, `dictCancelUploadConfirmation`
  237. * and `dictRemoveFile` options are used for the wording.
  238. */ addRemoveLinks: false,
  239. /**
  240. * Defines where to display the file previews – if `null` the
  241. * Dropzone element itself is used. Can be a plain `HTMLElement` or a CSS
  242. * selector. The element should have the `dropzone-previews` class so
  243. * the previews are displayed properly.
  244. */ previewsContainer: null,
  245. /**
  246. * Set this to `true` if you don't want previews to be shown.
  247. */ disablePreviews: false,
  248. /**
  249. * This is the element the hidden input field (which is used when clicking on the
  250. * dropzone to trigger file selection) will be appended to. This might
  251. * be important in case you use frameworks to switch the content of your page.
  252. *
  253. * Can be a selector string, or an element directly.
  254. */ hiddenInputContainer: "body",
  255. /**
  256. * If null, no capture type will be specified
  257. * If camera, mobile devices will skip the file selection and choose camera
  258. * If microphone, mobile devices will skip the file selection and choose the microphone
  259. * If camcorder, mobile devices will skip the file selection and choose the camera in video mode
  260. * On apple devices multiple must be set to false. AcceptedFiles may need to
  261. * be set to an appropriate mime type (e.g. "image/*", "audio/*", or "video/*").
  262. */ capture: null,
  263. /**
  264. * **Deprecated**. Use `renameFile` instead.
  265. */ renameFilename: null,
  266. /**
  267. * A function that is invoked before the file is uploaded to the server and renames the file.
  268. * This function gets the `File` as argument and can use the `file.name`. The actual name of the
  269. * file that gets used during the upload can be accessed through `file.upload.filename`.
  270. */ renameFile: null,
  271. /**
  272. * If `true` the fallback will be forced. This is very useful to test your server
  273. * implementations first and make sure that everything works as
  274. * expected without dropzone if you experience problems, and to test
  275. * how your fallbacks will look.
  276. */ forceFallback: false,
  277. /**
  278. * The text used before any files are dropped.
  279. */ dictDefaultMessage: "Drop files here to upload",
  280. /**
  281. * The text that replaces the default message text it the browser is not supported.
  282. */ dictFallbackMessage: "Your browser does not support drag'n'drop file uploads.",
  283. /**
  284. * The text that will be added before the fallback form.
  285. * If you provide a fallback element yourself, or if this option is `null` this will
  286. * be ignored.
  287. */ dictFallbackText: "Please use the fallback form below to upload your files like in the olden days.",
  288. /**
  289. * If the filesize is too big.
  290. * `{{filesize}}` and `{{maxFilesize}}` will be replaced with the respective configuration values.
  291. */ dictFileTooBig: "File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB.",
  292. /**
  293. * If the file doesn't match the file type.
  294. */ dictInvalidFileType: "You can't upload files of this type.",
  295. /**
  296. * If the server response was invalid.
  297. * `{{statusCode}}` will be replaced with the servers status code.
  298. */ dictResponseError: "Server responded with {{statusCode}} code.",
  299. /**
  300. * If `addRemoveLinks` is true, the text to be used for the cancel upload link.
  301. */ dictCancelUpload: "Cancel upload",
  302. /**
  303. * The text that is displayed if an upload was manually canceled
  304. */ dictUploadCanceled: "Upload canceled.",
  305. /**
  306. * If `addRemoveLinks` is true, the text to be used for confirmation when cancelling upload.
  307. */ dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?",
  308. /**
  309. * If `addRemoveLinks` is true, the text to be used to remove a file.
  310. */ dictRemoveFile: "Remove file",
  311. /**
  312. * If this is not null, then the user will be prompted before removing a file.
  313. */ dictRemoveFileConfirmation: null,
  314. /**
  315. * Displayed if `maxFiles` is st and exceeded.
  316. * The string `{{maxFiles}}` will be replaced by the configuration value.
  317. */ dictMaxFilesExceeded: "You can not upload any more files.",
  318. /**
  319. * Allows you to translate the different units. Starting with `tb` for terabytes and going down to
  320. * `b` for bytes.
  321. */ dictFileSizeUnits: {
  322. tb: "TB",
  323. gb: "GB",
  324. mb: "MB",
  325. kb: "KB",
  326. b: "b"
  327. },
  328. /**
  329. * Called when dropzone initialized
  330. * You can add event listeners here
  331. */ init () {
  332. },
  333. /**
  334. * Can be an **object** of additional parameters to transfer to the server, **or** a `Function`
  335. * that gets invoked with the `files`, `xhr` and, if it's a chunked upload, `chunk` arguments. In case
  336. * of a function, this needs to return a map.
  337. *
  338. * The default implementation does nothing for normal uploads, but adds relevant information for
  339. * chunked uploads.
  340. *
  341. * This is the same as adding hidden input fields in the form element.
  342. */ params (files, xhr, chunk) {
  343. if (chunk) return {
  344. dzuuid: chunk.file.upload.uuid,
  345. dzchunkindex: chunk.index,
  346. dztotalfilesize: chunk.file.size,
  347. dzchunksize: this.options.chunkSize,
  348. dztotalchunkcount: chunk.file.upload.totalChunkCount,
  349. dzchunkbyteoffset: chunk.index * this.options.chunkSize
  350. };
  351. },
  352. /**
  353. * A function that gets a [file](https://developer.mozilla.org/en-US/docs/DOM/File)
  354. * and a `done` function as parameters.
  355. *
  356. * If the done function is invoked without arguments, the file is "accepted" and will
  357. * be processed. If you pass an error message, the file is rejected, and the error
  358. * message will be displayed.
  359. * This function will not be called if the file is too big or doesn't match the mime types.
  360. */ accept (file, done) {
  361. return done();
  362. },
  363. /**
  364. * The callback that will be invoked when all chunks have been uploaded for a file.
  365. * It gets the file for which the chunks have been uploaded as the first parameter,
  366. * and the `done` function as second. `done()` needs to be invoked when everything
  367. * needed to finish the upload process is done.
  368. */ chunksUploaded: function(file, done) {
  369. done();
  370. },
  371. /**
  372. * Sends the file as binary blob in body instead of form data.
  373. * If this is set, the `params` option will be ignored.
  374. * It's an error to set this to `true` along with `uploadMultiple` since
  375. * multiple files cannot be in a single binary body.
  376. */ binaryBody: false,
  377. /**
  378. * Gets called when the browser is not supported.
  379. * The default implementation shows the fallback input field and adds
  380. * a text.
  381. */ fallback () {
  382. // This code should pass in IE7... :(
  383. let messageElement;
  384. this.element.className = `${this.element.className} dz-browser-not-supported`;
  385. for (let child of this.element.getElementsByTagName("div"))if (/(^| )dz-message($| )/.test(child.className)) {
  386. messageElement = child;
  387. child.className = "dz-message"; // Removes the 'dz-default' class
  388. break;
  389. }
  390. if (!messageElement) {
  391. messageElement = $3ed269f2f0fb224b$export$2e2bcd8739ae039.createElement('<div class="dz-message"><span></span></div>');
  392. this.element.appendChild(messageElement);
  393. }
  394. let span = messageElement.getElementsByTagName("span")[0];
  395. if (span) {
  396. if (span.textContent != null) span.textContent = this.options.dictFallbackMessage;
  397. else if (span.innerText != null) span.innerText = this.options.dictFallbackMessage;
  398. }
  399. return this.element.appendChild(this.getFallbackForm());
  400. },
  401. /**
  402. * Gets called to calculate the thumbnail dimensions.
  403. *
  404. * It gets `file`, `width` and `height` (both may be `null`) as parameters and must return an object containing:
  405. *
  406. * - `srcWidth` & `srcHeight` (required)
  407. * - `trgWidth` & `trgHeight` (required)
  408. * - `srcX` & `srcY` (optional, default `0`)
  409. * - `trgX` & `trgY` (optional, default `0`)
  410. *
  411. * Those values are going to be used by `ctx.drawImage()`.
  412. */ resize (file, width, height, resizeMethod) {
  413. let info = {
  414. srcX: 0,
  415. srcY: 0,
  416. srcWidth: file.width,
  417. srcHeight: file.height
  418. };
  419. let srcRatio = file.width / file.height;
  420. // Automatically calculate dimensions if not specified
  421. if (width == null && height == null) {
  422. width = info.srcWidth;
  423. height = info.srcHeight;
  424. } else if (width == null) width = height * srcRatio;
  425. else if (height == null) height = width / srcRatio;
  426. // Make sure images aren't upscaled
  427. width = Math.min(width, info.srcWidth);
  428. height = Math.min(height, info.srcHeight);
  429. let trgRatio = width / height;
  430. if (info.srcWidth > width || info.srcHeight > height) {
  431. // Image is bigger and needs rescaling
  432. if (resizeMethod === "crop") {
  433. if (srcRatio > trgRatio) {
  434. info.srcHeight = file.height;
  435. info.srcWidth = info.srcHeight * trgRatio;
  436. } else {
  437. info.srcWidth = file.width;
  438. info.srcHeight = info.srcWidth / trgRatio;
  439. }
  440. } else if (resizeMethod === "contain") {
  441. // Method 'contain'
  442. if (srcRatio > trgRatio) height = width / srcRatio;
  443. else width = height * srcRatio;
  444. } else throw new Error(`Unknown resizeMethod '${resizeMethod}'`);
  445. }
  446. info.srcX = (file.width - info.srcWidth) / 2;
  447. info.srcY = (file.height - info.srcHeight) / 2;
  448. info.trgWidth = width;
  449. info.trgHeight = height;
  450. return info;
  451. },
  452. /**
  453. * Can be used to transform the file (for example, resize an image if necessary).
  454. *
  455. * The default implementation uses `resizeWidth` and `resizeHeight` (if provided) and resizes
  456. * images according to those dimensions.
  457. *
  458. * Gets the `file` as the first parameter, and a `done()` function as the second, that needs
  459. * to be invoked with the file when the transformation is done.
  460. */ transformFile (file, done) {
  461. if ((this.options.resizeWidth || this.options.resizeHeight) && file.type.match(/image.*/)) return this.resizeImage(file, this.options.resizeWidth, this.options.resizeHeight, this.options.resizeMethod, done);
  462. else return done(file);
  463. },
  464. /**
  465. * A string that contains the template used for each dropped
  466. * file. Change it to fulfill your needs but make sure to properly
  467. * provide all elements.
  468. *
  469. * If you want to use an actual HTML element instead of providing a String
  470. * as a config option, you could create a div with the id `tpl`,
  471. * put the template inside it and provide the element like this:
  472. *
  473. * document
  474. * .querySelector('#tpl')
  475. * .innerHTML
  476. *
  477. */ previewTemplate: (/*@__PURE__*/$parcel$interopDefault($fd6031f88dce2e32$exports)),
  478. /*
  479. Those functions register themselves to the events on init and handle all
  480. the user interface specific stuff. Overwriting them won't break the upload
  481. but can break the way it's displayed.
  482. You can overwrite them if you don't like the default behavior. If you just
  483. want to add an additional event handler, register it on the dropzone object
  484. and don't overwrite those options.
  485. */ // Those are self explanatory and simply concern the DragnDrop.
  486. drop (e) {
  487. return this.element.classList.remove("dz-drag-hover");
  488. },
  489. dragstart (e) {
  490. },
  491. dragend (e) {
  492. return this.element.classList.remove("dz-drag-hover");
  493. },
  494. dragenter (e) {
  495. return this.element.classList.add("dz-drag-hover");
  496. },
  497. dragover (e) {
  498. return this.element.classList.add("dz-drag-hover");
  499. },
  500. dragleave (e) {
  501. return this.element.classList.remove("dz-drag-hover");
  502. },
  503. paste (e) {
  504. },
  505. // Called whenever there are no files left in the dropzone anymore, and the
  506. // dropzone should be displayed as if in the initial state.
  507. reset () {
  508. return this.element.classList.remove("dz-started");
  509. },
  510. // Called when a file is added to the queue
  511. // Receives `file`
  512. addedfile (file) {
  513. if (this.element === this.previewsContainer) this.element.classList.add("dz-started");
  514. if (this.previewsContainer && !this.options.disablePreviews) {
  515. file.previewElement = $3ed269f2f0fb224b$export$2e2bcd8739ae039.createElement(this.options.previewTemplate.trim());
  516. file.previewTemplate = file.previewElement; // Backwards compatibility
  517. this.previewsContainer.appendChild(file.previewElement);
  518. for (var node of file.previewElement.querySelectorAll("[data-dz-name]"))node.textContent = file.name;
  519. for (node of file.previewElement.querySelectorAll("[data-dz-size]"))node.innerHTML = this.filesize(file.size);
  520. if (this.options.addRemoveLinks) {
  521. file._removeLink = $3ed269f2f0fb224b$export$2e2bcd8739ae039.createElement(`<a class="dz-remove" href="javascript:undefined;" data-dz-remove>${this.options.dictRemoveFile}</a>`);
  522. file.previewElement.appendChild(file._removeLink);
  523. }
  524. let removeFileEvent = (e)=>{
  525. e.preventDefault();
  526. e.stopPropagation();
  527. if (file.status === $3ed269f2f0fb224b$export$2e2bcd8739ae039.UPLOADING) return $3ed269f2f0fb224b$export$2e2bcd8739ae039.confirm(this.options.dictCancelUploadConfirmation, ()=>this.removeFile(file)
  528. );
  529. else {
  530. if (this.options.dictRemoveFileConfirmation) return $3ed269f2f0fb224b$export$2e2bcd8739ae039.confirm(this.options.dictRemoveFileConfirmation, ()=>this.removeFile(file)
  531. );
  532. else return this.removeFile(file);
  533. }
  534. };
  535. for (let removeLink of file.previewElement.querySelectorAll("[data-dz-remove]"))removeLink.addEventListener("click", removeFileEvent);
  536. }
  537. },
  538. // Called whenever a file is removed.
  539. removedfile (file) {
  540. if (file.previewElement != null && file.previewElement.parentNode != null) file.previewElement.parentNode.removeChild(file.previewElement);
  541. return this._updateMaxFilesReachedClass();
  542. },
  543. // Called when a thumbnail has been generated
  544. // Receives `file` and `dataUrl`
  545. thumbnail (file, dataUrl) {
  546. if (file.previewElement) {
  547. file.previewElement.classList.remove("dz-file-preview");
  548. for (let thumbnailElement of file.previewElement.querySelectorAll("[data-dz-thumbnail]")){
  549. thumbnailElement.alt = file.name;
  550. thumbnailElement.src = dataUrl;
  551. }
  552. return setTimeout(()=>file.previewElement.classList.add("dz-image-preview")
  553. , 1);
  554. }
  555. },
  556. // Called whenever an error occurs
  557. // Receives `file` and `message`
  558. error (file, message) {
  559. if (file.previewElement) {
  560. file.previewElement.classList.add("dz-error");
  561. if (typeof message !== "string" && message.error) message = message.error;
  562. for (let node of file.previewElement.querySelectorAll("[data-dz-errormessage]"))node.textContent = message;
  563. }
  564. },
  565. errormultiple () {
  566. },
  567. // Called when a file gets processed. Since there is a cue, not all added
  568. // files are processed immediately.
  569. // Receives `file`
  570. processing (file) {
  571. if (file.previewElement) {
  572. file.previewElement.classList.add("dz-processing");
  573. if (file._removeLink) return file._removeLink.innerHTML = this.options.dictCancelUpload;
  574. }
  575. },
  576. processingmultiple () {
  577. },
  578. // Called whenever the upload progress gets updated.
  579. // Receives `file`, `progress` (percentage 0-100) and `bytesSent`.
  580. // To get the total number of bytes of the file, use `file.size`
  581. uploadprogress (file, progress, bytesSent) {
  582. if (file.previewElement) for (let node of file.previewElement.querySelectorAll("[data-dz-uploadprogress]"))node.nodeName === "PROGRESS" ? node.value = progress : node.style.width = `${progress}%`;
  583. },
  584. // Called whenever the total upload progress gets updated.
  585. // Called with totalUploadProgress (0-100), totalBytes and totalBytesSent
  586. totaluploadprogress () {
  587. },
  588. // Called just before the file is sent. Gets the `xhr` object as second
  589. // parameter, so you can modify it (for example to add a CSRF token) and a
  590. // `formData` object to add additional information.
  591. sending () {
  592. },
  593. sendingmultiple () {
  594. },
  595. // When the complete upload is finished and successful
  596. // Receives `file`
  597. success (file) {
  598. if (file.previewElement) return file.previewElement.classList.add("dz-success");
  599. },
  600. successmultiple () {
  601. },
  602. // When the upload is canceled.
  603. canceled (file) {
  604. return this.emit("error", file, this.options.dictUploadCanceled);
  605. },
  606. canceledmultiple () {
  607. },
  608. // When the upload is finished, either with success or an error.
  609. // Receives `file`
  610. complete (file) {
  611. if (file._removeLink) file._removeLink.innerHTML = this.options.dictRemoveFile;
  612. if (file.previewElement) return file.previewElement.classList.add("dz-complete");
  613. },
  614. completemultiple () {
  615. },
  616. maxfilesexceeded () {
  617. },
  618. maxfilesreached () {
  619. },
  620. queuecomplete () {
  621. },
  622. addedfiles () {
  623. }
  624. };
  625. var $4ca367182776f80b$export$2e2bcd8739ae039 = $4ca367182776f80b$var$defaultOptions;
  626. class $3ed269f2f0fb224b$export$2e2bcd8739ae039 extends $4040acfd8584338d$export$2e2bcd8739ae039 {
  627. static initClass() {
  628. // Exposing the emitter class, mainly for tests
  629. this.prototype.Emitter = $4040acfd8584338d$export$2e2bcd8739ae039;
  630. /*
  631. This is a list of all available events you can register on a dropzone object.
  632. You can register an event handler like this:
  633. dropzone.on("dragEnter", function() { });
  634. */ this.prototype.events = [
  635. "drop",
  636. "dragstart",
  637. "dragend",
  638. "dragenter",
  639. "dragover",
  640. "dragleave",
  641. "addedfile",
  642. "addedfiles",
  643. "removedfile",
  644. "thumbnail",
  645. "error",
  646. "errormultiple",
  647. "processing",
  648. "processingmultiple",
  649. "uploadprogress",
  650. "totaluploadprogress",
  651. "sending",
  652. "sendingmultiple",
  653. "success",
  654. "successmultiple",
  655. "canceled",
  656. "canceledmultiple",
  657. "complete",
  658. "completemultiple",
  659. "reset",
  660. "maxfilesexceeded",
  661. "maxfilesreached",
  662. "queuecomplete",
  663. ];
  664. this.prototype._thumbnailQueue = [];
  665. this.prototype._processingThumbnail = false;
  666. }
  667. // Returns all files that have been accepted
  668. getAcceptedFiles() {
  669. return this.files.filter((file)=>file.accepted
  670. ).map((file)=>file
  671. );
  672. }
  673. // Returns all files that have been rejected
  674. // Not sure when that's going to be useful, but added for completeness.
  675. getRejectedFiles() {
  676. return this.files.filter((file)=>!file.accepted
  677. ).map((file)=>file
  678. );
  679. }
  680. getFilesWithStatus(status) {
  681. return this.files.filter((file)=>file.status === status
  682. ).map((file)=>file
  683. );
  684. }
  685. // Returns all files that are in the queue
  686. getQueuedFiles() {
  687. return this.getFilesWithStatus($3ed269f2f0fb224b$export$2e2bcd8739ae039.QUEUED);
  688. }
  689. getUploadingFiles() {
  690. return this.getFilesWithStatus($3ed269f2f0fb224b$export$2e2bcd8739ae039.UPLOADING);
  691. }
  692. getAddedFiles() {
  693. return this.getFilesWithStatus($3ed269f2f0fb224b$export$2e2bcd8739ae039.ADDED);
  694. }
  695. // Files that are either queued or uploading
  696. getActiveFiles() {
  697. return this.files.filter((file)=>file.status === $3ed269f2f0fb224b$export$2e2bcd8739ae039.UPLOADING || file.status === $3ed269f2f0fb224b$export$2e2bcd8739ae039.QUEUED
  698. ).map((file)=>file
  699. );
  700. }
  701. // The function that gets called when Dropzone is initialized. You
  702. // can (and should) setup event listeners inside this function.
  703. init() {
  704. // In case it isn't set already
  705. if (this.element.tagName === "form") this.element.setAttribute("enctype", "multipart/form-data");
  706. if (this.element.classList.contains("dropzone") && !this.element.querySelector(".dz-message")) this.element.appendChild($3ed269f2f0fb224b$export$2e2bcd8739ae039.createElement(`<div class="dz-default dz-message"><button class="dz-button" type="button">${this.options.dictDefaultMessage}</button></div>`));
  707. if (this.clickableElements.length) {
  708. let setupHiddenFileInput = ()=>{
  709. if (this.hiddenFileInput) this.hiddenFileInput.parentNode.removeChild(this.hiddenFileInput);
  710. this.hiddenFileInput = document.createElement("input");
  711. this.hiddenFileInput.setAttribute("type", "file");
  712. if (this.options.maxFiles === null || this.options.maxFiles > 1) this.hiddenFileInput.setAttribute("multiple", "multiple");
  713. this.hiddenFileInput.className = "dz-hidden-input";
  714. if (this.options.acceptedFiles !== null) this.hiddenFileInput.setAttribute("accept", this.options.acceptedFiles);
  715. if (this.options.capture !== null) this.hiddenFileInput.setAttribute("capture", this.options.capture);
  716. // Making sure that no one can "tab" into this field.
  717. this.hiddenFileInput.setAttribute("tabindex", "-1");
  718. // Not setting `display="none"` because some browsers don't accept clicks
  719. // on elements that aren't displayed.
  720. this.hiddenFileInput.style.visibility = "hidden";
  721. this.hiddenFileInput.style.position = "absolute";
  722. this.hiddenFileInput.style.top = "0";
  723. this.hiddenFileInput.style.left = "0";
  724. this.hiddenFileInput.style.height = "0";
  725. this.hiddenFileInput.style.width = "0";
  726. $3ed269f2f0fb224b$export$2e2bcd8739ae039.getElement(this.options.hiddenInputContainer, "hiddenInputContainer").appendChild(this.hiddenFileInput);
  727. this.hiddenFileInput.addEventListener("change", ()=>{
  728. let { files: files } = this.hiddenFileInput;
  729. if (files.length) for (let file of files)this.addFile(file);
  730. this.emit("addedfiles", files);
  731. setupHiddenFileInput();
  732. });
  733. };
  734. setupHiddenFileInput();
  735. }
  736. this.URL = window.URL !== null ? window.URL : window.webkitURL;
  737. // Setup all event listeners on the Dropzone object itself.
  738. // They're not in @setupEventListeners() because they shouldn't be removed
  739. // again when the dropzone gets disabled.
  740. for (let eventName of this.events)this.on(eventName, this.options[eventName]);
  741. this.on("uploadprogress", ()=>this.updateTotalUploadProgress()
  742. );
  743. this.on("removedfile", ()=>this.updateTotalUploadProgress()
  744. );
  745. this.on("canceled", (file)=>this.emit("complete", file)
  746. );
  747. // Emit a `queuecomplete` event if all files finished uploading.
  748. this.on("complete", (file)=>{
  749. if (this.getAddedFiles().length === 0 && this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) // This needs to be deferred so that `queuecomplete` really triggers after `complete`
  750. return setTimeout(()=>this.emit("queuecomplete")
  751. , 0);
  752. });
  753. const containsFiles = function(e) {
  754. if (e.dataTransfer.types) // Because e.dataTransfer.types is an Object in
  755. // IE, we need to iterate like this instead of
  756. // using e.dataTransfer.types.some()
  757. for(var i = 0; i < e.dataTransfer.types.length; i++){
  758. if (e.dataTransfer.types[i] === "Files") return true;
  759. }
  760. return false;
  761. };
  762. let noPropagation = function(e) {
  763. // If there are no files, we don't want to stop
  764. // propagation so we don't interfere with other
  765. // drag and drop behaviour.
  766. if (!containsFiles(e)) return;
  767. e.stopPropagation();
  768. if (e.preventDefault) return e.preventDefault();
  769. else return e.returnValue = false;
  770. };
  771. // Create the listeners
  772. this.listeners = [
  773. {
  774. element: this.element,
  775. events: {
  776. dragstart: (e)=>{
  777. return this.emit("dragstart", e);
  778. },
  779. dragenter: (e)=>{
  780. noPropagation(e);
  781. return this.emit("dragenter", e);
  782. },
  783. dragover: (e)=>{
  784. // Makes it possible to drag files from chrome's download bar
  785. // http://stackoverflow.com/questions/19526430/drag-and-drop-file-uploads-from-chrome-downloads-bar
  786. // Try is required to prevent bug in Internet Explorer 11 (SCRIPT65535 exception)
  787. let efct;
  788. try {
  789. efct = e.dataTransfer.effectAllowed;
  790. } catch (error) {
  791. }
  792. e.dataTransfer.dropEffect = "move" === efct || "linkMove" === efct ? "move" : "copy";
  793. noPropagation(e);
  794. return this.emit("dragover", e);
  795. },
  796. dragleave: (e)=>{
  797. return this.emit("dragleave", e);
  798. },
  799. drop: (e)=>{
  800. noPropagation(e);
  801. return this.drop(e);
  802. },
  803. dragend: (e)=>{
  804. return this.emit("dragend", e);
  805. }
  806. }
  807. },
  808. ];
  809. this.clickableElements.forEach((clickableElement)=>{
  810. return this.listeners.push({
  811. element: clickableElement,
  812. events: {
  813. click: (evt)=>{
  814. // Only the actual dropzone or the message element should trigger file selection
  815. if (clickableElement !== this.element || evt.target === this.element || $3ed269f2f0fb224b$export$2e2bcd8739ae039.elementInside(evt.target, this.element.querySelector(".dz-message"))) this.hiddenFileInput.click(); // Forward the click
  816. return true;
  817. }
  818. }
  819. });
  820. });
  821. this.enable();
  822. return this.options.init.call(this);
  823. }
  824. // Not fully tested yet
  825. destroy() {
  826. this.disable();
  827. this.removeAllFiles(true);
  828. if (this.hiddenFileInput != null ? this.hiddenFileInput.parentNode : undefined) {
  829. this.hiddenFileInput.parentNode.removeChild(this.hiddenFileInput);
  830. this.hiddenFileInput = null;
  831. }
  832. delete this.element.dropzone;
  833. return $3ed269f2f0fb224b$export$2e2bcd8739ae039.instances.splice($3ed269f2f0fb224b$export$2e2bcd8739ae039.instances.indexOf(this), 1);
  834. }
  835. updateTotalUploadProgress() {
  836. let totalUploadProgress;
  837. let totalBytesSent = 0;
  838. let totalBytes = 0;
  839. let activeFiles = this.getActiveFiles();
  840. if (activeFiles.length) {
  841. for (let file of this.getActiveFiles()){
  842. totalBytesSent += file.upload.bytesSent;
  843. totalBytes += file.upload.total;
  844. }
  845. totalUploadProgress = 100 * totalBytesSent / totalBytes;
  846. } else totalUploadProgress = 100;
  847. return this.emit("totaluploadprogress", totalUploadProgress, totalBytes, totalBytesSent);
  848. }
  849. // @options.paramName can be a function taking one parameter rather than a string.
  850. // A parameter name for a file is obtained simply by calling this with an index number.
  851. _getParamName(n) {
  852. if (typeof this.options.paramName === "function") return this.options.paramName(n);
  853. else return `${this.options.paramName}${this.options.uploadMultiple ? `[${n}]` : ""}`;
  854. }
  855. // If @options.renameFile is a function,
  856. // the function will be used to rename the file.name before appending it to the formData
  857. _renameFile(file) {
  858. if (typeof this.options.renameFile !== "function") return file.name;
  859. return this.options.renameFile(file);
  860. }
  861. // Returns a form that can be used as fallback if the browser does not support DragnDrop
  862. //
  863. // If the dropzone is already a form, only the input field and button are returned. Otherwise a complete form element is provided.
  864. // This code has to pass in IE7 :(
  865. getFallbackForm() {
  866. let existingFallback, form;
  867. if (existingFallback = this.getExistingFallback()) return existingFallback;
  868. let fieldsString = '<div class="dz-fallback">';
  869. if (this.options.dictFallbackText) fieldsString += `<p>${this.options.dictFallbackText}</p>`;
  870. fieldsString += `<input type="file" name="${this._getParamName(0)}" ${this.options.uploadMultiple ? 'multiple="multiple"' : undefined} /><input type="submit" value="Upload!"></div>`;
  871. let fields = $3ed269f2f0fb224b$export$2e2bcd8739ae039.createElement(fieldsString);
  872. if (this.element.tagName !== "FORM") {
  873. form = $3ed269f2f0fb224b$export$2e2bcd8739ae039.createElement(`<form action="${this.options.url}" enctype="multipart/form-data" method="${this.options.method}"></form>`);
  874. form.appendChild(fields);
  875. } else {
  876. // Make sure that the enctype and method attributes are set properly
  877. this.element.setAttribute("enctype", "multipart/form-data");
  878. this.element.setAttribute("method", this.options.method);
  879. }
  880. return form != null ? form : fields;
  881. }
  882. // Returns the fallback elements if they exist already
  883. //
  884. // This code has to pass in IE7 :(
  885. getExistingFallback() {
  886. let getFallback = function(elements) {
  887. for (let el of elements){
  888. if (/(^| )fallback($| )/.test(el.className)) return el;
  889. }
  890. };
  891. for (let tagName of [
  892. "div",
  893. "form"
  894. ]){
  895. var fallback;
  896. if (fallback = getFallback(this.element.getElementsByTagName(tagName))) return fallback;
  897. }
  898. }
  899. // Activates all listeners stored in @listeners
  900. setupEventListeners() {
  901. return this.listeners.map((elementListeners)=>(()=>{
  902. let result = [];
  903. for(let event in elementListeners.events){
  904. let listener = elementListeners.events[event];
  905. result.push(elementListeners.element.addEventListener(event, listener, false));
  906. }
  907. return result;
  908. })()
  909. );
  910. }
  911. // Deactivates all listeners stored in @listeners
  912. removeEventListeners() {
  913. return this.listeners.map((elementListeners)=>(()=>{
  914. let result = [];
  915. for(let event in elementListeners.events){
  916. let listener = elementListeners.events[event];
  917. result.push(elementListeners.element.removeEventListener(event, listener, false));
  918. }
  919. return result;
  920. })()
  921. );
  922. }
  923. // Removes all event listeners and cancels all files in the queue or being processed.
  924. disable() {
  925. this.clickableElements.forEach((element)=>element.classList.remove("dz-clickable")
  926. );
  927. this.removeEventListeners();
  928. this.disabled = true;
  929. return this.files.map((file)=>this.cancelUpload(file)
  930. );
  931. }
  932. enable() {
  933. delete this.disabled;
  934. this.clickableElements.forEach((element)=>element.classList.add("dz-clickable")
  935. );
  936. return this.setupEventListeners();
  937. }
  938. // Returns a nicely formatted filesize
  939. filesize(size) {
  940. let selectedSize = 0;
  941. let selectedUnit = "b";
  942. if (size > 0) {
  943. let units = [
  944. "tb",
  945. "gb",
  946. "mb",
  947. "kb",
  948. "b"
  949. ];
  950. for(let i = 0; i < units.length; i++){
  951. let unit = units[i];
  952. let cutoff = Math.pow(this.options.filesizeBase, 4 - i) / 10;
  953. if (size >= cutoff) {
  954. selectedSize = size / Math.pow(this.options.filesizeBase, 4 - i);
  955. selectedUnit = unit;
  956. break;
  957. }
  958. }
  959. selectedSize = Math.round(10 * selectedSize) / 10; // Cutting of digits
  960. }
  961. return `<strong>${selectedSize}</strong> ${this.options.dictFileSizeUnits[selectedUnit]}`;
  962. }
  963. // Adds or removes the `dz-max-files-reached` class from the form.
  964. _updateMaxFilesReachedClass() {
  965. if (this.options.maxFiles != null && this.getAcceptedFiles().length >= this.options.maxFiles) {
  966. if (this.getAcceptedFiles().length === this.options.maxFiles) this.emit("maxfilesreached", this.files);
  967. return this.element.classList.add("dz-max-files-reached");
  968. } else return this.element.classList.remove("dz-max-files-reached");
  969. }
  970. drop(e) {
  971. if (!e.dataTransfer) return;
  972. this.emit("drop", e);
  973. // Convert the FileList to an Array
  974. // This is necessary for IE11
  975. let files = [];
  976. for(let i = 0; i < e.dataTransfer.files.length; i++)files[i] = e.dataTransfer.files[i];
  977. // Even if it's a folder, files.length will contain the folders.
  978. if (files.length) {
  979. let { items: items } = e.dataTransfer;
  980. if (items && items.length && items[0].webkitGetAsEntry != null) // The browser supports dropping of folders, so handle items instead of files
  981. this._addFilesFromItems(items);
  982. else this.handleFiles(files);
  983. }
  984. this.emit("addedfiles", files);
  985. }
  986. paste(e) {
  987. if ($3ed269f2f0fb224b$var$__guard__(e != null ? e.clipboardData : undefined, (x)=>x.items
  988. ) == null) return;
  989. this.emit("paste", e);
  990. let { items: items } = e.clipboardData;
  991. if (items.length) return this._addFilesFromItems(items);
  992. }
  993. handleFiles(files) {
  994. for (let file of files)this.addFile(file);
  995. }
  996. // When a folder is dropped (or files are pasted), items must be handled
  997. // instead of files.
  998. _addFilesFromItems(items) {
  999. return (()=>{
  1000. let result = [];
  1001. for (let item of items){
  1002. var entry;
  1003. if (item.webkitGetAsEntry != null && (entry = item.webkitGetAsEntry())) {
  1004. if (entry.isFile) result.push(this.addFile(item.getAsFile()));
  1005. else if (entry.isDirectory) // Append all files from that directory to files
  1006. result.push(this._addFilesFromDirectory(entry, entry.name));
  1007. else result.push(undefined);
  1008. } else if (item.getAsFile != null) {
  1009. if (item.kind == null || item.kind === "file") result.push(this.addFile(item.getAsFile()));
  1010. else result.push(undefined);
  1011. } else result.push(undefined);
  1012. }
  1013. return result;
  1014. })();
  1015. }
  1016. // Goes through the directory, and adds each file it finds recursively
  1017. _addFilesFromDirectory(directory, path) {
  1018. let dirReader = directory.createReader();
  1019. let errorHandler = (error)=>$3ed269f2f0fb224b$var$__guardMethod__(console, "log", (o)=>o.log(error)
  1020. )
  1021. ;
  1022. var readEntries = ()=>{
  1023. return dirReader.readEntries((entries)=>{
  1024. if (entries.length > 0) {
  1025. for (let entry of entries){
  1026. if (entry.isFile) entry.file((file)=>{
  1027. if (this.options.ignoreHiddenFiles && file.name.substring(0, 1) === ".") return;
  1028. file.fullPath = `${path}/${file.name}`;
  1029. return this.addFile(file);
  1030. });
  1031. else if (entry.isDirectory) this._addFilesFromDirectory(entry, `${path}/${entry.name}`);
  1032. }
  1033. // Recursively call readEntries() again, since browser only handle
  1034. // the first 100 entries.
  1035. // See: https://developer.mozilla.org/en-US/docs/Web/API/DirectoryReader#readEntries
  1036. readEntries();
  1037. }
  1038. return null;
  1039. }, errorHandler);
  1040. };
  1041. return readEntries();
  1042. }
  1043. // If `done()` is called without argument the file is accepted
  1044. // If you call it with an error message, the file is rejected
  1045. // (This allows for asynchronous validation)
  1046. //
  1047. // This function checks the filesize, and if the file.type passes the
  1048. // `acceptedFiles` check.
  1049. accept(file, done) {
  1050. if (this.options.maxFilesize && file.size > this.options.maxFilesize * 1048576) done(this.options.dictFileTooBig.replace("{{filesize}}", Math.round(file.size / 1024 / 10.24) / 100).replace("{{maxFilesize}}", this.options.maxFilesize));
  1051. else if (!$3ed269f2f0fb224b$export$2e2bcd8739ae039.isValidFile(file, this.options.acceptedFiles)) done(this.options.dictInvalidFileType);
  1052. else if (this.options.maxFiles != null && this.getAcceptedFiles().length >= this.options.maxFiles) {
  1053. done(this.options.dictMaxFilesExceeded.replace("{{maxFiles}}", this.options.maxFiles));
  1054. this.emit("maxfilesexceeded", file);
  1055. } else this.options.accept.call(this, file, done);
  1056. }
  1057. addFile(file) {
  1058. file.upload = {
  1059. uuid: $3ed269f2f0fb224b$export$2e2bcd8739ae039.uuidv4(),
  1060. progress: 0,
  1061. // Setting the total upload size to file.size for the beginning
  1062. // It's actual different than the size to be transmitted.
  1063. total: file.size,
  1064. bytesSent: 0,
  1065. filename: this._renameFile(file)
  1066. };
  1067. this.files.push(file);
  1068. file.status = $3ed269f2f0fb224b$export$2e2bcd8739ae039.ADDED;
  1069. this.emit("addedfile", file);
  1070. this._enqueueThumbnail(file);
  1071. this.accept(file, (error)=>{
  1072. if (error) {
  1073. file.accepted = false;
  1074. this._errorProcessing([
  1075. file
  1076. ], error); // Will set the file.status
  1077. } else {
  1078. file.accepted = true;
  1079. if (this.options.autoQueue) this.enqueueFile(file);
  1080. // Will set .accepted = true
  1081. }
  1082. this._updateMaxFilesReachedClass();
  1083. });
  1084. }
  1085. // Wrapper for enqueueFile
  1086. enqueueFiles(files) {
  1087. for (let file of files)this.enqueueFile(file);
  1088. return null;
  1089. }
  1090. enqueueFile(file) {
  1091. if (file.status === $3ed269f2f0fb224b$export$2e2bcd8739ae039.ADDED && file.accepted === true) {
  1092. file.status = $3ed269f2f0fb224b$export$2e2bcd8739ae039.QUEUED;
  1093. if (this.options.autoProcessQueue) return setTimeout(()=>this.processQueue()
  1094. , 0); // Deferring the call
  1095. } else throw new Error("This file can't be queued because it has already been processed or was rejected.");
  1096. }
  1097. _enqueueThumbnail(file) {
  1098. if (this.options.createImageThumbnails && file.type.match(/image.*/) && file.size <= this.options.maxThumbnailFilesize * 1048576) {
  1099. this._thumbnailQueue.push(file);
  1100. return setTimeout(()=>this._processThumbnailQueue()
  1101. , 0); // Deferring the call
  1102. }
  1103. }
  1104. _processThumbnailQueue() {
  1105. if (this._processingThumbnail || this._thumbnailQueue.length === 0) return;
  1106. this._processingThumbnail = true;
  1107. let file = this._thumbnailQueue.shift();
  1108. return this.createThumbnail(file, this.options.thumbnailWidth, this.options.thumbnailHeight, this.options.thumbnailMethod, true, (dataUrl)=>{
  1109. this.emit("thumbnail", file, dataUrl);
  1110. this._processingThumbnail = false;
  1111. return this._processThumbnailQueue();
  1112. });
  1113. }
  1114. // Can be called by the user to remove a file
  1115. removeFile(file) {
  1116. if (file.status === $3ed269f2f0fb224b$export$2e2bcd8739ae039.UPLOADING) this.cancelUpload(file);
  1117. this.files = $3ed269f2f0fb224b$var$without(this.files, file);
  1118. this.emit("removedfile", file);
  1119. if (this.files.length === 0) return this.emit("reset");
  1120. }
  1121. // Removes all files that aren't currently processed from the list
  1122. removeAllFiles(cancelIfNecessary) {
  1123. // Create a copy of files since removeFile() changes the @files array.
  1124. if (cancelIfNecessary == null) cancelIfNecessary = false;
  1125. for (let file of this.files.slice())if (file.status !== $3ed269f2f0fb224b$export$2e2bcd8739ae039.UPLOADING || cancelIfNecessary) this.removeFile(file);
  1126. return null;
  1127. }
  1128. // Resizes an image before it gets sent to the server. This function is the default behavior of
  1129. // `options.transformFile` if `resizeWidth` or `resizeHeight` are set. The callback is invoked with
  1130. // the resized blob.
  1131. resizeImage(file, width, height, resizeMethod, callback) {
  1132. return this.createThumbnail(file, width, height, resizeMethod, true, (dataUrl, canvas)=>{
  1133. if (canvas == null) // The image has not been resized
  1134. return callback(file);
  1135. else {
  1136. let { resizeMimeType: resizeMimeType } = this.options;
  1137. if (resizeMimeType == null) resizeMimeType = file.type;
  1138. let resizedDataURL = canvas.toDataURL(resizeMimeType, this.options.resizeQuality);
  1139. if (resizeMimeType === "image/jpeg" || resizeMimeType === "image/jpg") // Now add the original EXIF information
  1140. resizedDataURL = $3ed269f2f0fb224b$var$ExifRestore.restore(file.dataURL, resizedDataURL);
  1141. return callback($3ed269f2f0fb224b$export$2e2bcd8739ae039.dataURItoBlob(resizedDataURL));
  1142. }
  1143. });
  1144. }
  1145. createThumbnail(file, width, height, resizeMethod, fixOrientation, callback) {
  1146. let fileReader = new FileReader();
  1147. fileReader.onload = ()=>{
  1148. file.dataURL = fileReader.result;
  1149. // Don't bother creating a thumbnail for SVG images since they're vector
  1150. if (file.type === "image/svg+xml") {
  1151. if (callback != null) callback(fileReader.result);
  1152. return;
  1153. }
  1154. this.createThumbnailFromUrl(file, width, height, resizeMethod, fixOrientation, callback);
  1155. };
  1156. fileReader.readAsDataURL(file);
  1157. }
  1158. // `mockFile` needs to have these attributes:
  1159. //
  1160. // { name: 'name', size: 12345, imageUrl: '' }
  1161. //
  1162. // `callback` will be invoked when the image has been downloaded and displayed.
  1163. // `crossOrigin` will be added to the `img` tag when accessing the file.
  1164. displayExistingFile(mockFile, imageUrl, callback, crossOrigin, resizeThumbnail = true) {
  1165. this.emit("addedfile", mockFile);
  1166. this.emit("complete", mockFile);
  1167. if (!resizeThumbnail) {
  1168. this.emit("thumbnail", mockFile, imageUrl);
  1169. if (callback) callback();
  1170. } else {
  1171. let onDone = (thumbnail)=>{
  1172. this.emit("thumbnail", mockFile, thumbnail);
  1173. if (callback) callback();
  1174. };
  1175. mockFile.dataURL = imageUrl;
  1176. this.createThumbnailFromUrl(mockFile, this.options.thumbnailWidth, this.options.thumbnailHeight, this.options.thumbnailMethod, this.options.fixOrientation, onDone, crossOrigin);
  1177. }
  1178. }
  1179. createThumbnailFromUrl(file, width, height, resizeMethod, fixOrientation, callback, crossOrigin) {
  1180. // Not using `new Image` here because of a bug in latest Chrome versions.
  1181. // See https://github.com/enyo/dropzone/pull/226
  1182. let img = document.createElement("img");
  1183. if (crossOrigin) img.crossOrigin = crossOrigin;
  1184. // fixOrientation is not needed anymore with browsers handling imageOrientation
  1185. fixOrientation = getComputedStyle(document.body)["imageOrientation"] == "from-image" ? false : fixOrientation;
  1186. img.onload = ()=>{
  1187. let loadExif = (callback)=>callback(1)
  1188. ;
  1189. if (typeof EXIF !== "undefined" && EXIF !== null && fixOrientation) loadExif = (callback)=>EXIF.getData(img, function() {
  1190. return callback(EXIF.getTag(this, "Orientation"));
  1191. })
  1192. ;
  1193. return loadExif((orientation)=>{
  1194. file.width = img.width;
  1195. file.height = img.height;
  1196. let resizeInfo = this.options.resize.call(this, file, width, height, resizeMethod);
  1197. let canvas = document.createElement("canvas");
  1198. let ctx = canvas.getContext("2d");
  1199. canvas.width = resizeInfo.trgWidth;
  1200. canvas.height = resizeInfo.trgHeight;
  1201. if (orientation > 4) {
  1202. canvas.width = resizeInfo.trgHeight;
  1203. canvas.height = resizeInfo.trgWidth;
  1204. }
  1205. switch(orientation){
  1206. case 2:
  1207. // horizontal flip
  1208. ctx.translate(canvas.width, 0);
  1209. ctx.scale(-1, 1);
  1210. break;
  1211. case 3:
  1212. // 180° rotate left
  1213. ctx.translate(canvas.width, canvas.height);
  1214. ctx.rotate(Math.PI);
  1215. break;
  1216. case 4:
  1217. // vertical flip
  1218. ctx.translate(0, canvas.height);
  1219. ctx.scale(1, -1);
  1220. break;
  1221. case 5:
  1222. // vertical flip + 90 rotate right
  1223. ctx.rotate(0.5 * Math.PI);
  1224. ctx.scale(1, -1);
  1225. break;
  1226. case 6:
  1227. // 90° rotate right
  1228. ctx.rotate(0.5 * Math.PI);
  1229. ctx.translate(0, -canvas.width);
  1230. break;
  1231. case 7:
  1232. // horizontal flip + 90 rotate right
  1233. ctx.rotate(0.5 * Math.PI);
  1234. ctx.translate(canvas.height, -canvas.width);
  1235. ctx.scale(-1, 1);
  1236. break;
  1237. case 8:
  1238. // 90° rotate left
  1239. ctx.rotate(-0.5 * Math.PI);
  1240. ctx.translate(-canvas.height, 0);
  1241. break;
  1242. }
  1243. // This is a bugfix for iOS' scaling bug.
  1244. $3ed269f2f0fb224b$var$drawImageIOSFix(ctx, img, resizeInfo.srcX != null ? resizeInfo.srcX : 0, resizeInfo.srcY != null ? resizeInfo.srcY : 0, resizeInfo.srcWidth, resizeInfo.srcHeight, resizeInfo.trgX != null ? resizeInfo.trgX : 0, resizeInfo.trgY != null ? resizeInfo.trgY : 0, resizeInfo.trgWidth, resizeInfo.trgHeight);
  1245. let thumbnail = canvas.toDataURL("image/png");
  1246. if (callback != null) return callback(thumbnail, canvas);
  1247. });
  1248. };
  1249. if (callback != null) img.onerror = callback;
  1250. return img.src = file.dataURL;
  1251. }
  1252. // Goes through the queue and processes files if there aren't too many already.
  1253. processQueue() {
  1254. let { parallelUploads: parallelUploads } = this.options;
  1255. let processingLength = this.getUploadingFiles().length;
  1256. let i = processingLength;
  1257. // There are already at least as many files uploading than should be
  1258. if (processingLength >= parallelUploads) return;
  1259. let queuedFiles = this.getQueuedFiles();
  1260. if (!(queuedFiles.length > 0)) return;
  1261. if (this.options.uploadMultiple) // The files should be uploaded in one request
  1262. return this.processFiles(queuedFiles.slice(0, parallelUploads - processingLength));
  1263. else while(i < parallelUploads){
  1264. if (!queuedFiles.length) return;
  1265. // Nothing left to process
  1266. this.processFile(queuedFiles.shift());
  1267. i++;
  1268. }
  1269. }
  1270. // Wrapper for `processFiles`
  1271. processFile(file) {
  1272. return this.processFiles([
  1273. file
  1274. ]);
  1275. }
  1276. // Loads the file, then calls finishedLoading()
  1277. processFiles(files) {
  1278. for (let file of files){
  1279. file.processing = true; // Backwards compatibility
  1280. file.status = $3ed269f2f0fb224b$export$2e2bcd8739ae039.UPLOADING;
  1281. this.emit("processing", file);
  1282. }
  1283. if (this.options.uploadMultiple) this.emit("processingmultiple", files);
  1284. return this.uploadFiles(files);
  1285. }
  1286. _getFilesWithXhr(xhr) {
  1287. let files;
  1288. return files = this.files.filter((file)=>file.xhr === xhr
  1289. ).map((file)=>file
  1290. );
  1291. }
  1292. // Cancels the file upload and sets the status to CANCELED
  1293. // **if** the file is actually being uploaded.
  1294. // If it's still in the queue, the file is being removed from it and the status
  1295. // set to CANCELED.
  1296. cancelUpload(file) {
  1297. if (file.status === $3ed269f2f0fb224b$export$2e2bcd8739ae039.UPLOADING) {
  1298. let groupedFiles = this._getFilesWithXhr(file.xhr);
  1299. for (let groupedFile of groupedFiles)groupedFile.status = $3ed269f2f0fb224b$export$2e2bcd8739ae039.CANCELED;
  1300. if (typeof file.xhr !== "undefined") file.xhr.abort();
  1301. for (let groupedFile1 of groupedFiles)this.emit("canceled", groupedFile1);
  1302. if (this.options.uploadMultiple) this.emit("canceledmultiple", groupedFiles);
  1303. } else if (file.status === $3ed269f2f0fb224b$export$2e2bcd8739ae039.ADDED || file.status === $3ed269f2f0fb224b$export$2e2bcd8739ae039.QUEUED) {
  1304. file.status = $3ed269f2f0fb224b$export$2e2bcd8739ae039.CANCELED;
  1305. this.emit("canceled", file);
  1306. if (this.options.uploadMultiple) this.emit("canceledmultiple", [
  1307. file
  1308. ]);
  1309. }
  1310. if (this.options.autoProcessQueue) return this.processQueue();
  1311. }
  1312. resolveOption(option, ...args) {
  1313. if (typeof option === "function") return option.apply(this, args);
  1314. return option;
  1315. }
  1316. uploadFile(file) {
  1317. return this.uploadFiles([
  1318. file
  1319. ]);
  1320. }
  1321. uploadFiles(files) {
  1322. this._transformFiles(files, (transformedFiles)=>{
  1323. if (this.options.chunking) {
  1324. // Chunking is not allowed to be used with `uploadMultiple` so we know
  1325. // that there is only __one__file.
  1326. let transformedFile = transformedFiles[0];
  1327. files[0].upload.chunked = this.options.chunking && (this.options.forceChunking || transformedFile.size > this.options.chunkSize);
  1328. files[0].upload.totalChunkCount = Math.ceil(transformedFile.size / this.options.chunkSize);
  1329. }
  1330. if (files[0].upload.chunked) {
  1331. // This file should be sent in chunks!
  1332. // If the chunking option is set, we **know** that there can only be **one** file, since
  1333. // uploadMultiple is not allowed with this option.
  1334. let file = files[0];
  1335. let transformedFile = transformedFiles[0];
  1336. let startedChunkCount = 0;
  1337. file.upload.chunks = [];
  1338. let handleNextChunk = ()=>{
  1339. let chunkIndex = 0;
  1340. // Find the next item in file.upload.chunks that is not defined yet.
  1341. while(file.upload.chunks[chunkIndex] !== undefined)chunkIndex++;
  1342. // This means, that all chunks have already been started.
  1343. if (chunkIndex >= file.upload.totalChunkCount) return;
  1344. startedChunkCount++;
  1345. let start = chunkIndex * this.options.chunkSize;
  1346. let end = Math.min(start + this.options.chunkSize, transformedFile.size);
  1347. let dataBlock = {
  1348. name: this._getParamName(0),
  1349. data: transformedFile.webkitSlice ? transformedFile.webkitSlice(start, end) : transformedFile.slice(start, end),
  1350. filename: file.upload.filename,
  1351. chunkIndex: chunkIndex
  1352. };
  1353. file.upload.chunks[chunkIndex] = {
  1354. file: file,
  1355. index: chunkIndex,
  1356. dataBlock: dataBlock,
  1357. status: $3ed269f2f0fb224b$export$2e2bcd8739ae039.UPLOADING,
  1358. progress: 0,
  1359. retries: 0
  1360. };
  1361. this._uploadData(files, [
  1362. dataBlock
  1363. ]);
  1364. };
  1365. file.upload.finishedChunkUpload = (chunk, response)=>{
  1366. let allFinished = true;
  1367. chunk.status = $3ed269f2f0fb224b$export$2e2bcd8739ae039.SUCCESS;
  1368. // Clear the data from the chunk
  1369. chunk.dataBlock = null;
  1370. chunk.response = chunk.xhr.responseText;
  1371. chunk.responseHeaders = chunk.xhr.getAllResponseHeaders();
  1372. // Leaving this reference to xhr will cause memory leaks.
  1373. chunk.xhr = null;
  1374. for(let i = 0; i < file.upload.totalChunkCount; i++){
  1375. if (file.upload.chunks[i] === undefined) return handleNextChunk();
  1376. if (file.upload.chunks[i].status !== $3ed269f2f0fb224b$export$2e2bcd8739ae039.SUCCESS) allFinished = false;
  1377. }
  1378. if (allFinished) this.options.chunksUploaded(file, ()=>{
  1379. this._finished(files, response, null);
  1380. });
  1381. };
  1382. if (this.options.parallelChunkUploads) for(let i = 0; i < file.upload.totalChunkCount; i++)handleNextChunk();
  1383. else handleNextChunk();
  1384. } else {
  1385. let dataBlocks = [];
  1386. for(let i = 0; i < files.length; i++)dataBlocks[i] = {
  1387. name: this._getParamName(i),
  1388. data: transformedFiles[i],
  1389. filename: files[i].upload.filename
  1390. };
  1391. this._uploadData(files, dataBlocks);
  1392. }
  1393. });
  1394. }
  1395. /// Returns the right chunk for given file and xhr
  1396. _getChunk(file, xhr) {
  1397. for(let i = 0; i < file.upload.totalChunkCount; i++){
  1398. if (file.upload.chunks[i] !== undefined && file.upload.chunks[i].xhr === xhr) return file.upload.chunks[i];
  1399. }
  1400. }
  1401. // This function actually uploads the file(s) to the server.
  1402. //
  1403. // If dataBlocks contains the actual data to upload (meaning, that this could
  1404. // either be transformed files, or individual chunks for chunked upload) then
  1405. // they will be used for the actual data to upload.
  1406. _uploadData(files, dataBlocks) {
  1407. let xhr = new XMLHttpRequest();
  1408. // Put the xhr object in the file objects to be able to reference it later.
  1409. for (let file of files)file.xhr = xhr;
  1410. if (files[0].upload.chunked) // Put the xhr object in the right chunk object, so it can be associated
  1411. // later, and found with _getChunk.
  1412. files[0].upload.chunks[dataBlocks[0].chunkIndex].xhr = xhr;
  1413. let method = this.resolveOption(this.options.method, files, dataBlocks);
  1414. let url = this.resolveOption(this.options.url, files, dataBlocks);
  1415. xhr.open(method, url, true);
  1416. // Setting the timeout after open because of IE11 issue: https://gitlab.com/meno/dropzone/issues/8
  1417. let timeout = this.resolveOption(this.options.timeout, files);
  1418. if (timeout) xhr.timeout = this.resolveOption(this.options.timeout, files);
  1419. // Has to be after `.open()`. See https://github.com/enyo/dropzone/issues/179
  1420. xhr.withCredentials = !!this.options.withCredentials;
  1421. xhr.onload = (e)=>{
  1422. this._finishedUploading(files, xhr, e);
  1423. };
  1424. xhr.ontimeout = ()=>{
  1425. this._handleUploadError(files, xhr, `Request timedout after ${this.options.timeout / 1000} seconds`);
  1426. };
  1427. xhr.onerror = ()=>{
  1428. this._handleUploadError(files, xhr);
  1429. };
  1430. // Some browsers do not have the .upload property
  1431. let progressObj = xhr.upload != null ? xhr.upload : xhr;
  1432. progressObj.onprogress = (e)=>this._updateFilesUploadProgress(files, xhr, e)
  1433. ;
  1434. let headers = this.options.defaultHeaders ? {
  1435. Accept: "application/json",
  1436. "Cache-Control": "no-cache",
  1437. "X-Requested-With": "XMLHttpRequest"
  1438. } : {
  1439. };
  1440. if (this.options.binaryBody) headers["Content-Type"] = files[0].type;
  1441. if (this.options.headers) $ewBKy$justextend(headers, this.options.headers);
  1442. for(let headerName in headers){
  1443. let headerValue = headers[headerName];
  1444. if (headerValue) xhr.setRequestHeader(headerName, headerValue);
  1445. }
  1446. if (this.options.binaryBody) {
  1447. // Since the file is going to be sent as binary body, it doesn't make
  1448. // any sense to generate `FormData` for it.
  1449. for (let file of files)this.emit("sending", file, xhr);
  1450. if (this.options.uploadMultiple) this.emit("sendingmultiple", files, xhr);
  1451. this.submitRequest(xhr, null, files);
  1452. } else {
  1453. let formData = new FormData();
  1454. // Adding all @options parameters
  1455. if (this.options.params) {
  1456. let additionalParams = this.options.params;
  1457. if (typeof additionalParams === "function") additionalParams = additionalParams.call(this, files, xhr, files[0].upload.chunked ? this._getChunk(files[0], xhr) : null);
  1458. for(let key in additionalParams){
  1459. let value = additionalParams[key];
  1460. if (Array.isArray(value)) // The additional parameter contains an array,
  1461. // so lets iterate over it to attach each value
  1462. // individually.
  1463. for(let i = 0; i < value.length; i++)formData.append(key, value[i]);
  1464. else formData.append(key, value);
  1465. }
  1466. }
  1467. // Let the user add additional data if necessary
  1468. for (let file of files)this.emit("sending", file, xhr, formData);
  1469. if (this.options.uploadMultiple) this.emit("sendingmultiple", files, xhr, formData);
  1470. this._addFormElementData(formData);
  1471. // Finally add the files
  1472. // Has to be last because some servers (eg: S3) expect the file to be the last parameter
  1473. for(let i = 0; i < dataBlocks.length; i++){
  1474. let dataBlock = dataBlocks[i];
  1475. formData.append(dataBlock.name, dataBlock.data, dataBlock.filename);
  1476. }
  1477. this.submitRequest(xhr, formData, files);
  1478. }
  1479. }
  1480. // Transforms all files with this.options.transformFile and invokes done with the transformed files when done.
  1481. _transformFiles(files, done) {
  1482. let transformedFiles = [];
  1483. // Clumsy way of handling asynchronous calls, until I get to add a proper Future library.
  1484. let doneCounter = 0;
  1485. for(let i = 0; i < files.length; i++)this.options.transformFile.call(this, files[i], (transformedFile)=>{
  1486. transformedFiles[i] = transformedFile;
  1487. if (++doneCounter === files.length) done(transformedFiles);
  1488. });
  1489. }
  1490. // Takes care of adding other input elements of the form to the AJAX request
  1491. _addFormElementData(formData) {
  1492. // Take care of other input elements
  1493. if (this.element.tagName === "FORM") for (let input of this.element.querySelectorAll("input, textarea, select, button")){
  1494. let inputName = input.getAttribute("name");
  1495. let inputType = input.getAttribute("type");
  1496. if (inputType) inputType = inputType.toLowerCase();
  1497. // If the input doesn't have a name, we can't use it.
  1498. if (typeof inputName === "undefined" || inputName === null) continue;
  1499. if (input.tagName === "SELECT" && input.hasAttribute("multiple")) {
  1500. // Possibly multiple values
  1501. for (let option of input.options)if (option.selected) formData.append(inputName, option.value);
  1502. } else if (!inputType || inputType !== "checkbox" && inputType !== "radio" || input.checked) formData.append(inputName, input.value);
  1503. }
  1504. }
  1505. // Invoked when there is new progress information about given files.
  1506. // If e is not provided, it is assumed that the upload is finished.
  1507. _updateFilesUploadProgress(files, xhr, e) {
  1508. if (!files[0].upload.chunked) // Handle file uploads without chunking
  1509. for (let file of files){
  1510. if (file.upload.total && file.upload.bytesSent && file.upload.bytesSent == file.upload.total) continue;
  1511. if (e) {
  1512. file.upload.progress = 100 * e.loaded / e.total;
  1513. file.upload.total = e.total;
  1514. file.upload.bytesSent = e.loaded;
  1515. } else {
  1516. // No event, so we're at 100%
  1517. file.upload.progress = 100;
  1518. file.upload.bytesSent = file.upload.total;
  1519. }
  1520. this.emit("uploadprogress", file, file.upload.progress, file.upload.bytesSent);
  1521. }
  1522. else {
  1523. // Handle chunked file uploads
  1524. // Chunked upload is not compatible with uploading multiple files in one
  1525. // request, so we know there's only one file.
  1526. let file = files[0];
  1527. // Since this is a chunked upload, we need to update the appropriate chunk
  1528. // progress.
  1529. let chunk = this._getChunk(file, xhr);
  1530. if (e) {
  1531. chunk.progress = 100 * e.loaded / e.total;
  1532. chunk.total = e.total;
  1533. chunk.bytesSent = e.loaded;
  1534. } else {
  1535. // No event, so we're at 100%
  1536. chunk.progress = 100;
  1537. chunk.bytesSent = chunk.total;
  1538. }
  1539. // Now tally the *file* upload progress from its individual chunks
  1540. file.upload.progress = 0;
  1541. file.upload.total = 0;
  1542. file.upload.bytesSent = 0;
  1543. for(let i = 0; i < file.upload.totalChunkCount; i++)if (file.upload.chunks[i] && typeof file.upload.chunks[i].progress !== "undefined") {
  1544. file.upload.progress += file.upload.chunks[i].progress;
  1545. file.upload.total += file.upload.chunks[i].total;
  1546. file.upload.bytesSent += file.upload.chunks[i].bytesSent;
  1547. }
  1548. // Since the process is a percentage, we need to divide by the amount of
  1549. // chunks we've used.
  1550. file.upload.progress = file.upload.progress / file.upload.totalChunkCount;
  1551. this.emit("uploadprogress", file, file.upload.progress, file.upload.bytesSent);
  1552. }
  1553. }
  1554. _finishedUploading(files, xhr, e) {
  1555. let response;
  1556. if (files[0].status === $3ed269f2f0fb224b$export$2e2bcd8739ae039.CANCELED) return;
  1557. if (xhr.readyState !== 4) return;
  1558. if (xhr.responseType !== "arraybuffer" && xhr.responseType !== "blob") {
  1559. response = xhr.responseText;
  1560. if (xhr.getResponseHeader("content-type") && ~xhr.getResponseHeader("content-type").indexOf("application/json")) try {
  1561. response = JSON.parse(response);
  1562. } catch (error) {
  1563. e = error;
  1564. response = "Invalid JSON response from server.";
  1565. }
  1566. }
  1567. this._updateFilesUploadProgress(files, xhr);
  1568. if (!(200 <= xhr.status && xhr.status < 300)) this._handleUploadError(files, xhr, response);
  1569. else if (files[0].upload.chunked) files[0].upload.finishedChunkUpload(this._getChunk(files[0], xhr), response);
  1570. else this._finished(files, response, e);
  1571. }
  1572. _handleUploadError(files, xhr, response) {
  1573. if (files[0].status === $3ed269f2f0fb224b$export$2e2bcd8739ae039.CANCELED) return;
  1574. if (files[0].upload.chunked && this.options.retryChunks) {
  1575. let chunk = this._getChunk(files[0], xhr);
  1576. if ((chunk.retries++) < this.options.retryChunksLimit) {
  1577. this._uploadData(files, [
  1578. chunk.dataBlock
  1579. ]);
  1580. return;
  1581. } else console.warn("Retried this chunk too often. Giving up.");
  1582. }
  1583. this._errorProcessing(files, response || this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr);
  1584. }
  1585. submitRequest(xhr, formData, files) {
  1586. if (xhr.readyState != 1) {
  1587. console.warn("Cannot send this request because the XMLHttpRequest.readyState is not OPENED.");
  1588. return;
  1589. }
  1590. if (this.options.binaryBody) {
  1591. if (files[0].upload.chunked) {
  1592. const chunk = this._getChunk(files[0], xhr);
  1593. xhr.send(chunk.dataBlock.data);
  1594. } else xhr.send(files[0]);
  1595. } else xhr.send(formData);
  1596. }
  1597. // Called internally when processing is finished.
  1598. // Individual callbacks have to be called in the appropriate sections.
  1599. _finished(files, responseText, e) {
  1600. for (let file of files){
  1601. file.status = $3ed269f2f0fb224b$export$2e2bcd8739ae039.SUCCESS;
  1602. this.emit("success", file, responseText, e);
  1603. this.emit("complete", file);
  1604. }
  1605. if (this.options.uploadMultiple) {
  1606. this.emit("successmultiple", files, responseText, e);
  1607. this.emit("completemultiple", files);
  1608. }
  1609. if (this.options.autoProcessQueue) return this.processQueue();
  1610. }
  1611. // Called internally when processing is finished.
  1612. // Individual callbacks have to be called in the appropriate sections.
  1613. _errorProcessing(files, message, xhr) {
  1614. for (let file of files){
  1615. file.status = $3ed269f2f0fb224b$export$2e2bcd8739ae039.ERROR;
  1616. this.emit("error", file, message, xhr);
  1617. this.emit("complete", file);
  1618. }
  1619. if (this.options.uploadMultiple) {
  1620. this.emit("errormultiple", files, message, xhr);
  1621. this.emit("completemultiple", files);
  1622. }
  1623. if (this.options.autoProcessQueue) return this.processQueue();
  1624. }
  1625. static uuidv4() {
  1626. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
  1627. let r = Math.random() * 16 | 0, v = c === "x" ? r : r & 3 | 8;
  1628. return v.toString(16);
  1629. });
  1630. }
  1631. constructor(el, options){
  1632. super();
  1633. let fallback, left;
  1634. this.element = el;
  1635. this.clickableElements = [];
  1636. this.listeners = [];
  1637. this.files = []; // All files
  1638. if (typeof this.element === "string") this.element = document.querySelector(this.element);
  1639. // Not checking if instance of HTMLElement or Element since IE9 is extremely weird.
  1640. if (!this.element || this.element.nodeType == null) throw new Error("Invalid dropzone element.");
  1641. if (this.element.dropzone) throw new Error("Dropzone already attached.");
  1642. // Now add this dropzone to the instances.
  1643. $3ed269f2f0fb224b$export$2e2bcd8739ae039.instances.push(this);
  1644. // Put the dropzone inside the element itself.
  1645. this.element.dropzone = this;
  1646. let elementOptions = (left = $3ed269f2f0fb224b$export$2e2bcd8739ae039.optionsForElement(this.element)) != null ? left : {
  1647. };
  1648. this.options = $ewBKy$justextend(true, {
  1649. }, $4ca367182776f80b$export$2e2bcd8739ae039, elementOptions, options != null ? options : {
  1650. });
  1651. this.options.previewTemplate = this.options.previewTemplate.replace(/\n*/g, "");
  1652. // If the browser failed, just call the fallback and leave
  1653. if (this.options.forceFallback || !$3ed269f2f0fb224b$export$2e2bcd8739ae039.isBrowserSupported()) return this.options.fallback.call(this);
  1654. // @options.url = @element.getAttribute "action" unless @options.url?
  1655. if (this.options.url == null) this.options.url = this.element.getAttribute("action");
  1656. if (!this.options.url) throw new Error("No URL provided.");
  1657. if (this.options.acceptedFiles && this.options.acceptedMimeTypes) throw new Error("You can't provide both 'acceptedFiles' and 'acceptedMimeTypes'. 'acceptedMimeTypes' is deprecated.");
  1658. if (this.options.uploadMultiple && this.options.chunking) throw new Error("You cannot set both: uploadMultiple and chunking.");
  1659. if (this.options.binaryBody && this.options.uploadMultiple) throw new Error("You cannot set both: binaryBody and uploadMultiple.");
  1660. // Backwards compatibility
  1661. if (this.options.acceptedMimeTypes) {
  1662. this.options.acceptedFiles = this.options.acceptedMimeTypes;
  1663. delete this.options.acceptedMimeTypes;
  1664. }
  1665. // Backwards compatibility
  1666. if (this.options.renameFilename != null) this.options.renameFile = (file)=>this.options.renameFilename.call(this, file.name, file)
  1667. ;
  1668. if (typeof this.options.method === "string") this.options.method = this.options.method.toUpperCase();
  1669. if ((fallback = this.getExistingFallback()) && fallback.parentNode) // Remove the fallback
  1670. fallback.parentNode.removeChild(fallback);
  1671. // Display previews in the previewsContainer element or the Dropzone element unless explicitly set to false
  1672. if (this.options.previewsContainer !== false) {
  1673. if (this.options.previewsContainer) this.previewsContainer = $3ed269f2f0fb224b$export$2e2bcd8739ae039.getElement(this.options.previewsContainer, "previewsContainer");
  1674. else this.previewsContainer = this.element;
  1675. }
  1676. if (this.options.clickable) {
  1677. if (this.options.clickable === true) this.clickableElements = [
  1678. this.element
  1679. ];
  1680. else this.clickableElements = $3ed269f2f0fb224b$export$2e2bcd8739ae039.getElements(this.options.clickable, "clickable");
  1681. }
  1682. this.init();
  1683. }
  1684. }
  1685. $3ed269f2f0fb224b$export$2e2bcd8739ae039.initClass();
  1686. // This is a map of options for your different dropzones. Add configurations
  1687. // to this object for your different dropzone elemens.
  1688. //
  1689. // Example:
  1690. //
  1691. // Dropzone.options.myDropzoneElementId = { maxFilesize: 1 };
  1692. //
  1693. // And in html:
  1694. //
  1695. // <form action="/upload" id="my-dropzone-element-id" class="dropzone"></form>
  1696. $3ed269f2f0fb224b$export$2e2bcd8739ae039.options = {
  1697. };
  1698. // Returns the options for an element or undefined if none available.
  1699. $3ed269f2f0fb224b$export$2e2bcd8739ae039.optionsForElement = function(element) {
  1700. // Get the `Dropzone.options.elementId` for this element if it exists
  1701. if (element.getAttribute("id")) return $3ed269f2f0fb224b$export$2e2bcd8739ae039.options[$3ed269f2f0fb224b$var$camelize(element.getAttribute("id"))];
  1702. else return undefined;
  1703. };
  1704. // Holds a list of all dropzone instances
  1705. $3ed269f2f0fb224b$export$2e2bcd8739ae039.instances = [];
  1706. // Returns the dropzone for given element if any
  1707. $3ed269f2f0fb224b$export$2e2bcd8739ae039.forElement = function(element) {
  1708. if (typeof element === "string") element = document.querySelector(element);
  1709. if ((element != null ? element.dropzone : undefined) == null) throw new Error("No Dropzone found for given element. This is probably because you're trying to access it before Dropzone had the time to initialize. Use the `init` option to setup any additional observers on your Dropzone.");
  1710. return element.dropzone;
  1711. };
  1712. // Looks for all .dropzone elements and creates a dropzone for them
  1713. $3ed269f2f0fb224b$export$2e2bcd8739ae039.discover = function() {
  1714. let dropzones;
  1715. if (document.querySelectorAll) dropzones = document.querySelectorAll(".dropzone");
  1716. else {
  1717. dropzones = [];
  1718. // IE :(
  1719. let checkElements = (elements)=>(()=>{
  1720. let result = [];
  1721. for (let el of elements)if (/(^| )dropzone($| )/.test(el.className)) result.push(dropzones.push(el));
  1722. else result.push(undefined);
  1723. return result;
  1724. })()
  1725. ;
  1726. checkElements(document.getElementsByTagName("div"));
  1727. checkElements(document.getElementsByTagName("form"));
  1728. }
  1729. return (()=>{
  1730. let result = [];
  1731. for (let dropzone of dropzones)// Create a dropzone unless auto discover has been disabled for specific element
  1732. if ($3ed269f2f0fb224b$export$2e2bcd8739ae039.optionsForElement(dropzone) !== false) result.push(new $3ed269f2f0fb224b$export$2e2bcd8739ae039(dropzone));
  1733. else result.push(undefined);
  1734. return result;
  1735. })();
  1736. };
  1737. // Some browsers support drag and drog functionality, but not correctly.
  1738. //
  1739. // So I created a blocklist of userAgents. Yes, yes. Browser sniffing, I know.
  1740. // But what to do when browsers *theoretically* support an API, but crash
  1741. // when using it.
  1742. //
  1743. // This is a list of regular expressions tested against navigator.userAgent
  1744. //
  1745. // ** It should only be used on browser that *do* support the API, but
  1746. // incorrectly **
  1747. $3ed269f2f0fb224b$export$2e2bcd8739ae039.blockedBrowsers = [
  1748. // The mac os and windows phone version of opera 12 seems to have a problem with the File drag'n'drop API.
  1749. /opera.*(Macintosh|Windows Phone).*version\/12/i,
  1750. ];
  1751. // Checks if the browser is supported
  1752. $3ed269f2f0fb224b$export$2e2bcd8739ae039.isBrowserSupported = function() {
  1753. let capableBrowser = true;
  1754. if (window.File && window.FileReader && window.FileList && window.Blob && window.FormData && document.querySelector) {
  1755. if (!("classList" in document.createElement("a"))) capableBrowser = false;
  1756. else {
  1757. if ($3ed269f2f0fb224b$export$2e2bcd8739ae039.blacklistedBrowsers !== undefined) // Since this has been renamed, this makes sure we don't break older
  1758. // configuration.
  1759. $3ed269f2f0fb224b$export$2e2bcd8739ae039.blockedBrowsers = $3ed269f2f0fb224b$export$2e2bcd8739ae039.blacklistedBrowsers;
  1760. // The browser supports the API, but may be blocked.
  1761. for (let regex of $3ed269f2f0fb224b$export$2e2bcd8739ae039.blockedBrowsers)if (regex.test(navigator.userAgent)) {
  1762. capableBrowser = false;
  1763. continue;
  1764. }
  1765. }
  1766. } else capableBrowser = false;
  1767. return capableBrowser;
  1768. };
  1769. $3ed269f2f0fb224b$export$2e2bcd8739ae039.dataURItoBlob = function(dataURI) {
  1770. // convert base64 to raw binary data held in a string
  1771. // doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
  1772. let byteString = atob(dataURI.split(",")[1]);
  1773. // separate out the mime component
  1774. let mimeString = dataURI.split(",")[0].split(":")[1].split(";")[0];
  1775. // write the bytes of the string to an ArrayBuffer
  1776. let ab = new ArrayBuffer(byteString.length);
  1777. let ia = new Uint8Array(ab);
  1778. for(let i = 0, end = byteString.length, asc = 0 <= end; asc ? i <= end : i >= end; asc ? i++ : i--)ia[i] = byteString.charCodeAt(i);
  1779. // write the ArrayBuffer to a blob
  1780. return new Blob([
  1781. ab
  1782. ], {
  1783. type: mimeString
  1784. });
  1785. };
  1786. // Returns an array without the rejected item
  1787. const $3ed269f2f0fb224b$var$without = (list, rejectedItem)=>list.filter((item)=>item !== rejectedItem
  1788. ).map((item)=>item
  1789. )
  1790. ;
  1791. // abc-def_ghi -> abcDefGhi
  1792. const $3ed269f2f0fb224b$var$camelize = (str)=>str.replace(/[\-_](\w)/g, (match)=>match.charAt(1).toUpperCase()
  1793. )
  1794. ;
  1795. // Creates an element from string
  1796. $3ed269f2f0fb224b$export$2e2bcd8739ae039.createElement = function(string) {
  1797. let div = document.createElement("div");
  1798. div.innerHTML = string;
  1799. return div.childNodes[0];
  1800. };
  1801. // Tests if given element is inside (or simply is) the container
  1802. $3ed269f2f0fb224b$export$2e2bcd8739ae039.elementInside = function(element, container) {
  1803. if (element === container) return true;
  1804. // Coffeescript doesn't support do/while loops
  1805. while(element = element.parentNode){
  1806. if (element === container) return true;
  1807. }
  1808. return false;
  1809. };
  1810. $3ed269f2f0fb224b$export$2e2bcd8739ae039.getElement = function(el, name) {
  1811. let element;
  1812. if (typeof el === "string") element = document.querySelector(el);
  1813. else if (el.nodeType != null) element = el;
  1814. if (element == null) throw new Error(`Invalid \`${name}\` option provided. Please provide a CSS selector or a plain HTML element.`);
  1815. return element;
  1816. };
  1817. $3ed269f2f0fb224b$export$2e2bcd8739ae039.getElements = function(els, name) {
  1818. let el, elements;
  1819. if (els instanceof Array) {
  1820. elements = [];
  1821. try {
  1822. for (el of els)elements.push(this.getElement(el, name));
  1823. } catch (e) {
  1824. elements = null;
  1825. }
  1826. } else if (typeof els === "string") {
  1827. elements = [];
  1828. for (el of document.querySelectorAll(els))elements.push(el);
  1829. } else if (els.nodeType != null) elements = [
  1830. els
  1831. ];
  1832. if (elements == null || !elements.length) throw new Error(`Invalid \`${name}\` option provided. Please provide a CSS selector, a plain HTML element or a list of those.`);
  1833. return elements;
  1834. };
  1835. // Asks the user the question and calls accepted or rejected accordingly
  1836. //
  1837. // The default implementation just uses `window.confirm` and then calls the
  1838. // appropriate callback.
  1839. $3ed269f2f0fb224b$export$2e2bcd8739ae039.confirm = function(question, accepted, rejected) {
  1840. if (window.confirm(question)) return accepted();
  1841. else if (rejected != null) return rejected();
  1842. };
  1843. // Validates the mime type like this:
  1844. //
  1845. // https://developer.mozilla.org/en-US/docs/HTML/Element/input#attr-accept
  1846. $3ed269f2f0fb224b$export$2e2bcd8739ae039.isValidFile = function(file, acceptedFiles) {
  1847. if (!acceptedFiles) return true;
  1848. // If there are no accepted mime types, it's OK
  1849. acceptedFiles = acceptedFiles.split(",");
  1850. let mimeType = file.type;
  1851. let baseMimeType = mimeType.replace(/\/.*$/, "");
  1852. for (let validType of acceptedFiles){
  1853. validType = validType.trim();
  1854. if (validType.charAt(0) === ".") {
  1855. if (file.name.toLowerCase().indexOf(validType.toLowerCase(), file.name.length - validType.length) !== -1) return true;
  1856. } else if (/\/\*$/.test(validType)) {
  1857. // This is something like a image/* mime type
  1858. if (baseMimeType === validType.replace(/\/.*$/, "")) return true;
  1859. } else {
  1860. if (mimeType === validType) return true;
  1861. }
  1862. }
  1863. return false;
  1864. };
  1865. // Augment jQuery
  1866. if (typeof jQuery !== "undefined" && jQuery !== null) jQuery.fn.dropzone = function(options) {
  1867. return this.each(function() {
  1868. return new $3ed269f2f0fb224b$export$2e2bcd8739ae039(this, options);
  1869. });
  1870. };
  1871. // Dropzone file status codes
  1872. $3ed269f2f0fb224b$export$2e2bcd8739ae039.ADDED = "added";
  1873. $3ed269f2f0fb224b$export$2e2bcd8739ae039.QUEUED = "queued";
  1874. // For backwards compatibility. Now, if a file is accepted, it's either queued
  1875. // or uploading.
  1876. $3ed269f2f0fb224b$export$2e2bcd8739ae039.ACCEPTED = $3ed269f2f0fb224b$export$2e2bcd8739ae039.QUEUED;
  1877. $3ed269f2f0fb224b$export$2e2bcd8739ae039.UPLOADING = "uploading";
  1878. $3ed269f2f0fb224b$export$2e2bcd8739ae039.PROCESSING = $3ed269f2f0fb224b$export$2e2bcd8739ae039.UPLOADING; // alias
  1879. $3ed269f2f0fb224b$export$2e2bcd8739ae039.CANCELED = "canceled";
  1880. $3ed269f2f0fb224b$export$2e2bcd8739ae039.ERROR = "error";
  1881. $3ed269f2f0fb224b$export$2e2bcd8739ae039.SUCCESS = "success";
  1882. /*
  1883. Bugfix for iOS 6 and 7
  1884. Source: http://stackoverflow.com/questions/11929099/html5-canvas-drawimage-ratio-bug-ios
  1885. based on the work of https://github.com/stomita/ios-imagefile-megapixel
  1886. */ // Detecting vertical squash in loaded image.
  1887. // Fixes a bug which squash image vertically while drawing into canvas for some images.
  1888. // This is a bug in iOS6 devices. This function from https://github.com/stomita/ios-imagefile-megapixel
  1889. let $3ed269f2f0fb224b$var$detectVerticalSquash = function(img) {
  1890. let iw = img.naturalWidth;
  1891. let ih = img.naturalHeight;
  1892. let canvas = document.createElement("canvas");
  1893. canvas.width = 1;
  1894. canvas.height = ih;
  1895. let ctx = canvas.getContext("2d");
  1896. ctx.drawImage(img, 0, 0);
  1897. let { data: data } = ctx.getImageData(1, 0, 1, ih);
  1898. // search image edge pixel position in case it is squashed vertically.
  1899. let sy = 0;
  1900. let ey = ih;
  1901. let py = ih;
  1902. while(py > sy){
  1903. let alpha = data[(py - 1) * 4 + 3];
  1904. if (alpha === 0) ey = py;
  1905. else sy = py;
  1906. py = ey + sy >> 1;
  1907. }
  1908. let ratio = py / ih;
  1909. if (ratio === 0) return 1;
  1910. else return ratio;
  1911. };
  1912. // A replacement for context.drawImage
  1913. // (args are for source and destination).
  1914. var $3ed269f2f0fb224b$var$drawImageIOSFix = function(ctx, img, sx, sy, sw, sh, dx, dy, dw, dh) {
  1915. let vertSquashRatio = $3ed269f2f0fb224b$var$detectVerticalSquash(img);
  1916. return ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio);
  1917. };
  1918. // Based on MinifyJpeg
  1919. // Source: http://www.perry.cz/files/ExifRestorer.js
  1920. // http://elicon.blog57.fc2.com/blog-entry-206.html
  1921. class $3ed269f2f0fb224b$var$ExifRestore {
  1922. static initClass() {
  1923. this.KEY_STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  1924. }
  1925. static encode64(input) {
  1926. let output = "";
  1927. let chr1 = undefined;
  1928. let chr2 = undefined;
  1929. let chr3 = "";
  1930. let enc1 = undefined;
  1931. let enc2 = undefined;
  1932. let enc3 = undefined;
  1933. let enc4 = "";
  1934. let i = 0;
  1935. while(true){
  1936. chr1 = input[i++];
  1937. chr2 = input[i++];
  1938. chr3 = input[i++];
  1939. enc1 = chr1 >> 2;
  1940. enc2 = (chr1 & 3) << 4 | chr2 >> 4;
  1941. enc3 = (chr2 & 15) << 2 | chr3 >> 6;
  1942. enc4 = chr3 & 63;
  1943. if (isNaN(chr2)) enc3 = enc4 = 64;
  1944. else if (isNaN(chr3)) enc4 = 64;
  1945. output = output + this.KEY_STR.charAt(enc1) + this.KEY_STR.charAt(enc2) + this.KEY_STR.charAt(enc3) + this.KEY_STR.charAt(enc4);
  1946. chr1 = chr2 = chr3 = "";
  1947. enc1 = enc2 = enc3 = enc4 = "";
  1948. if (!(i < input.length)) break;
  1949. }
  1950. return output;
  1951. }
  1952. static restore(origFileBase64, resizedFileBase64) {
  1953. if (!origFileBase64.match("data:image/jpeg;base64,")) return resizedFileBase64;
  1954. let rawImage = this.decode64(origFileBase64.replace("data:image/jpeg;base64,", ""));
  1955. let segments = this.slice2Segments(rawImage);
  1956. let image = this.exifManipulation(resizedFileBase64, segments);
  1957. return `data:image/jpeg;base64,${this.encode64(image)}`;
  1958. }
  1959. static exifManipulation(resizedFileBase64, segments) {
  1960. let exifArray = this.getExifArray(segments);
  1961. let newImageArray = this.insertExif(resizedFileBase64, exifArray);
  1962. let aBuffer = new Uint8Array(newImageArray);
  1963. return aBuffer;
  1964. }
  1965. static getExifArray(segments) {
  1966. let seg = undefined;
  1967. let x = 0;
  1968. while(x < segments.length){
  1969. seg = segments[x];
  1970. if (seg[0] === 255 & seg[1] === 225) return seg;
  1971. x++;
  1972. }
  1973. return [];
  1974. }
  1975. static insertExif(resizedFileBase64, exifArray) {
  1976. let imageData = resizedFileBase64.replace("data:image/jpeg;base64,", "");
  1977. let buf = this.decode64(imageData);
  1978. let separatePoint = buf.indexOf(255, 3);
  1979. let mae = buf.slice(0, separatePoint);
  1980. let ato = buf.slice(separatePoint);
  1981. let array = mae;
  1982. array = array.concat(exifArray);
  1983. array = array.concat(ato);
  1984. return array;
  1985. }
  1986. static slice2Segments(rawImageArray) {
  1987. let head = 0;
  1988. let segments = [];
  1989. while(true){
  1990. var length;
  1991. if (rawImageArray[head] === 255 & rawImageArray[head + 1] === 218) break;
  1992. if (rawImageArray[head] === 255 & rawImageArray[head + 1] === 216) head += 2;
  1993. else {
  1994. length = rawImageArray[head + 2] * 256 + rawImageArray[head + 3];
  1995. let endPoint = head + length + 2;
  1996. let seg = rawImageArray.slice(head, endPoint);
  1997. segments.push(seg);
  1998. head = endPoint;
  1999. }
  2000. if (head > rawImageArray.length) break;
  2001. }
  2002. return segments;
  2003. }
  2004. static decode64(input) {
  2005. let output = "";
  2006. let chr1 = undefined;
  2007. let chr2 = undefined;
  2008. let chr3 = "";
  2009. let enc1 = undefined;
  2010. let enc2 = undefined;
  2011. let enc3 = undefined;
  2012. let enc4 = "";
  2013. let i = 0;
  2014. let buf = [];
  2015. // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
  2016. let base64test = /[^A-Za-z0-9\+\/\=]/g;
  2017. if (base64test.exec(input)) console.warn("There were invalid base64 characters in the input text.\nValid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\nExpect errors in decoding.");
  2018. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  2019. while(true){
  2020. enc1 = this.KEY_STR.indexOf(input.charAt(i++));
  2021. enc2 = this.KEY_STR.indexOf(input.charAt(i++));
  2022. enc3 = this.KEY_STR.indexOf(input.charAt(i++));
  2023. enc4 = this.KEY_STR.indexOf(input.charAt(i++));
  2024. chr1 = enc1 << 2 | enc2 >> 4;
  2025. chr2 = (enc2 & 15) << 4 | enc3 >> 2;
  2026. chr3 = (enc3 & 3) << 6 | enc4;
  2027. buf.push(chr1);
  2028. if (enc3 !== 64) buf.push(chr2);
  2029. if (enc4 !== 64) buf.push(chr3);
  2030. chr1 = chr2 = chr3 = "";
  2031. enc1 = enc2 = enc3 = enc4 = "";
  2032. if (!(i < input.length)) break;
  2033. }
  2034. return buf;
  2035. }
  2036. }
  2037. $3ed269f2f0fb224b$var$ExifRestore.initClass();
  2038. /*
  2039. * contentloaded.js
  2040. *
  2041. * Author: Diego Perini (diego.perini at gmail.com)
  2042. * Summary: cross-browser wrapper for DOMContentLoaded
  2043. * Updated: 20101020
  2044. * License: MIT
  2045. * Version: 1.2
  2046. *
  2047. * URL:
  2048. * http://javascript.nwbox.com/ContentLoaded/
  2049. * http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE
  2050. */ // @win window reference
  2051. // @fn function reference
  2052. let $3ed269f2f0fb224b$var$contentLoaded = function(win, fn) {
  2053. let done = false;
  2054. let top = true;
  2055. let doc = win.document;
  2056. let root = doc.documentElement;
  2057. let add = doc.addEventListener ? "addEventListener" : "attachEvent";
  2058. let rem = doc.addEventListener ? "removeEventListener" : "detachEvent";
  2059. let pre = doc.addEventListener ? "" : "on";
  2060. var init = function(e) {
  2061. if (e.type === "readystatechange" && doc.readyState !== "complete") return;
  2062. (e.type === "load" ? win : doc)[rem](pre + e.type, init, false);
  2063. if (!done && (done = true)) return fn.call(win, e.type || e);
  2064. };
  2065. var poll = function() {
  2066. try {
  2067. root.doScroll("left");
  2068. } catch (e) {
  2069. setTimeout(poll, 50);
  2070. return;
  2071. }
  2072. return init("poll");
  2073. };
  2074. if (doc.readyState !== "complete") {
  2075. if (doc.createEventObject && root.doScroll) {
  2076. try {
  2077. top = !win.frameElement;
  2078. } catch (error) {
  2079. }
  2080. if (top) poll();
  2081. }
  2082. doc[add](pre + "DOMContentLoaded", init, false);
  2083. doc[add](pre + "readystatechange", init, false);
  2084. return win[add](pre + "load", init, false);
  2085. }
  2086. };
  2087. function $3ed269f2f0fb224b$var$__guard__(value, transform) {
  2088. return typeof value !== "undefined" && value !== null ? transform(value) : undefined;
  2089. }
  2090. function $3ed269f2f0fb224b$var$__guardMethod__(obj, methodName, transform) {
  2091. if (typeof obj !== "undefined" && obj !== null && typeof obj[methodName] === "function") return transform(obj, methodName);
  2092. else return undefined;
  2093. }
  2094. export {$3ed269f2f0fb224b$export$2e2bcd8739ae039 as default, $3ed269f2f0fb224b$export$2e2bcd8739ae039 as Dropzone};
  2095. //# sourceMappingURL=dropzone.mjs.map