!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.jsFileDownloader=e():t.jsFileDownloader=e()}(this,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=2)}([function(t,e,r){t.exports=r(1)},function(t,e,r){var n=function(t){"use strict";var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var o=e&&e.prototype instanceof f?e:f,i=Object.create(o.prototype),a=new E(n||[]);return i._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return L()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=b(a,r);if(u){if(u===l)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=s(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===l)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(t,r,a),i}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var l={};function f(){}function p(){}function h(){}var d={};u(d,o,(function(){return this}));var y=Object.getPrototypeOf,v=y&&y(y(O([])));v&&v!==e&&r.call(v,o)&&(d=v);var m=h.prototype=f.prototype=Object.create(d);function w(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function g(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,u){var c=s(t[o],t,i);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):e.resolve(f).then((function(t){l.value=t,a(l)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function b(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,b(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,l;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function O(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(u&&c){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),x(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;x(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=n}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=n:Function("r","regeneratorRuntime = r")(n)}},function(t,e,r){"use strict";r.r(e);var n=r(0),o=r.n(n);function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(t,e){if(e&&("object"===i(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||(r=t,-1===Function.toString.call(r).indexOf("[native code]")))return t;var r;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return c(t,arguments,f(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),l(n,t)})(t)}function c(t,e,r){return(c=s()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&l(o,r.prototype),o}).apply(null,arguments)}function s(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function l(t,e){return(l=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function f(t){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var p=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&l(t,e)}(o,t);var e,r,n=(e=o,r=s(),function(){var t,n=f(e);if(r){var o=f(this).constructor;t=Reflect.construct(n,arguments,o)}else t=n.apply(this,arguments);return a(this,t)});function o(t,e){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,o),(r=n.call(this,"Downloader error: ".concat(t))).request=e,r.name="DownloadException",r}return o}(u(Error)),h={"89504E47":"image/png",25504446:"application/pdf"}; /*! * JS File Downloader v 1.1.24 * https://github.com/AleeeKoi/js-file-downloader * * Copyright Alessandro Pellizzari * Released under the MIT license * http://opensource.org/licenses/MIT */ function d(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function y(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){d(i,n,o,a,u,"next",t)}function u(t){d(i,n,o,a,u,"throw",t)}a(void 0)}))}}function v(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function m(t,e){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:{};return v(this,t),this.params=Object.assign({},w,e),this.link=this.createLink(),this.request=null,this.downloadedFile=null,this.params.autoStart?this.downloadFile():this}var e,r,n,i,a;return e=t,(r=[{key:"start",value:function(){return this.downloadFile()}},{key:"downloadFile",value:function(){var t=this;return new Promise((function(e,r){t.initDownload(e,r)}))}},{key:"initDownload",value:function(t,e){var r=this,n=function(){r.link.target="_blank",r.link.href=r.params.url,r.clickLink()};return!("download"in this.link)||this.isMobile()?(n(),t()):(this.request=this.createRequest(),this.params.url?(this.request.onload=y(o.a.mark((function n(){return o.a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(200===parseInt(r.request.status,10)){n.next=2;break}return n.abrupt("return",e(new p("status code [".concat(r.request.status,"]"),r.request)));case 2:return n.next=4,r.startDownload();case 4:return n.abrupt("return",t(r));case 5:case"end":return n.stop()}}),n)}))),this.request.ontimeout=function(){e(new p("request timeout",r.request))},this.request.onerror=function(){r.params.nativeFallbackOnError?(n(),t(r)):e(new p("network error",r.request))},this.request.send(this.params.body),this):e(new p("url param not defined!",this.request)))}},{key:"isMobile",value:function(){return!this.params.forceDesktopMode&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}},{key:"createRequest",value:function(){var t=new XMLHttpRequest;return t.open(this.params.method,this.params.url,!0),!1!==this.params.contentType&&t.setRequestHeader("Content-type",this.params.contentType),this.params.headers.forEach((function(e){t.setRequestHeader(e.name,e.value)})),t.responseType="arraybuffer",this.params.process&&"function"==typeof this.params.process&&t.addEventListener("progress",this.params.process),this.params.onloadstart&&"function"==typeof this.params.onloadstart&&(t.onloadstart=this.params.onloadstart),t.timeout=this.params.timeout,t.withCredentials=!!this.params.withCredentials||!!this.params.includeCredentials,t}},{key:"getFileName",value:function(){if("string"==typeof this.params.filename)return this.params.filename;var t=this.request.getResponseHeader("Content-Disposition"),e=[];t&&(e=t.replace(/["']/g,"").match(/filename\*?=([^;]+)/));var r=e&&e.length>=1?e[1]:this.params.url.split("/").pop().split("?")[0];return this.params.nameCallback(r)}},{key:"getContentTypeFromFileSignature",value:function(t){var e=Object.assign({},h,this.params.customFileSignatures);return new Promise((function(r,n){var o=new FileReader,i=t.slice(0,4);o.onloadend=function(t){if(t.target.readyState===FileReader.DONE){var o=new Uint8Array(t.target.result),i=[];o.forEach((function(t){i.push(t.toString(16))}));var a=i.join("").toUpperCase();r(e[a])}else n()},o.onerror=n,o.readAsArrayBuffer(i)}))}},{key:"getContentTypeFromResponseHeader",value:function(){return this.request.getResponseHeader("content-type")}},{key:"getContentType",value:function(t){var e=this;return new Promise(function(){var r=y(o.a.mark((function r(n){var i,a,u,c,s,l,f,p;return o.a.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(i=e.params.contentTypeDetermination,a="application/octet-stream","header"!==i&&"full"!==i||(u=e.getContentTypeFromResponseHeader()),"signature"!==i&&"full"!==i){r.next=7;break}return r.next=6,e.getContentTypeFromFileSignature(new Blob([t]));case 6:c=r.sent;case 7:n("header"===i?null!==(s=u)&&void 0!==s?s:a:"signature"===i?null!==(l=c)&&void 0!==l?l:a:"full"===i&&null!==(f=null!==(p=c)&&void 0!==p?p:u)&&void 0!==f?f:a);case 8:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}())}},{key:"createLink",value:function(){var t=document.createElement("a");return t.style.display="none",t}},{key:"clickLink",value:function(){var t;try{t=new MouseEvent("click")}catch(e){(t=document.createEvent("MouseEvent")).initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null)}this.link.dispatchEvent(t)}},{key:"getFile",value:(a=y(o.a.mark((function t(e,r){var n,i,a;return o.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getContentType(e);case 2:n=t.sent,a={type:n};try{i=new File([e],r,a)}catch(t){(i=new Blob([e],a)).name=r,i.lastModifiedDate=new Date}return t.abrupt("return",i);case 6:case"end":return t.stop()}}),t,this)}))),function(t,e){return a.apply(this,arguments)})},{key:"startDownload",value:(i=y(o.a.mark((function t(){var e,r;return o.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.getFileName(),t.next=3,this.getFile(this.request.response,e);case 3:if(this.downloadedFile=t.sent,!("msSaveOrOpenBlob"in window.navigator)){t.next=6;break}return t.abrupt("return",window.navigator.msSaveOrOpenBlob(this.downloadedFile,e));case 6:return r=window.URL.createObjectURL(this.downloadedFile),this.link.href=r,this.link.download=e,this.clickLink(),setTimeout((function(){(window.URL||window.webkitURL||window).revokeObjectURL(r)}),4e4),t.abrupt("return",this.downloadedFile);case 12:case"end":return t.stop()}}),t,this)}))),function(){return i.apply(this,arguments)})}])&&m(e.prototype,r),n&&m(e,n),t}();e.default=g}]).default})); //# sourceMappingURL=js-file-downloader.min.js.map