UNPKG

angular-file-saver

Version:

An AngularJS service that implements the HTML5 W3C saveAs() in browsers that do not natively support it

1 lines 6.59 kB
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var o in n)("object"==typeof exports?exports:t)[o]=n[o]}}(this,function(){return function(t){function e(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return t[o].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";t.exports="ngFileSaver",angular.module("ngFileSaver",[]).factory("FileSaver",["Blob","SaveAs","FileSaverUtils",n(1)]).factory("FileSaverUtils",[n(2)]).factory("Blob",["$window",n(3)]).factory("SaveAs",[n(5)])},function(t,e){"use strict";t.exports=function(t,e,n){function o(t,o,r){try{e(t,o,r)}catch(i){n.handleErrors(i.message)}}return{saveAs:function(t,e,r){return n.isBlobInstance(t)||n.handleErrors("Data argument should be a blob instance"),n.isString(e)||n.handleErrors("Filename argument should be a string"),o(t,e,r)}}}},function(t,e){"use strict";t.exports=function(){return{handleErrors:function(t){throw new Error(t)},isString:function(t){return"string"==typeof t||t instanceof String},isUndefined:function(t){return"undefined"==typeof t},isBlobInstance:function(t){return t instanceof Blob}}}},function(t,e,n){"use strict";n(4),t.exports=function(t){return t.Blob}},function(t,e){!function(t){"use strict";if(t.URL=t.URL||t.webkitURL,t.Blob&&t.URL)try{return void new Blob}catch(e){}var n=t.BlobBuilder||t.WebKitBlobBuilder||t.MozBlobBuilder||function(t){var e=function(t){return Object.prototype.toString.call(t).match(/^\[object\s(.*)\]$/)[1]},n=function(){this.data=[]},o=function(t,e,n){this.data=t,this.size=t.length,this.type=e,this.encoding=n},r=n.prototype,i=o.prototype,a=t.FileReaderSync,c=function(t){this.code=this[this.name=t]},s="NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR".split(" "),u=s.length,f=t.URL||t.webkitURL||t,l=f.createObjectURL,d=f.revokeObjectURL,p=f,h=t.btoa,b=t.atob,v=t.ArrayBuffer,w=t.Uint8Array,g=/^[\w-]+:\/*\[?[\w\.:-]+\]?(?::[0-9]+)?/;for(o.fake=i.fake=!0;u--;)c.prototype[s[u]]=u+1;return f.createObjectURL||(p=t.URL=function(t){var e,n=document.createElementNS("http://www.w3.org/1999/xhtml","a");return n.href=t,"origin"in n||("data:"===n.protocol.toLowerCase()?n.origin=null:(e=t.match(g),n.origin=e&&e[1])),n}),p.createObjectURL=function(t){var e,n=t.type;return null===n&&(n="application/octet-stream"),t instanceof o?(e="data:"+n,"base64"===t.encoding?e+";base64,"+t.data:"URI"===t.encoding?e+","+decodeURIComponent(t.data):h?e+";base64,"+h(t.data):e+","+encodeURIComponent(t.data)):l?l.call(f,t):void 0},p.revokeObjectURL=function(t){"data:"!==t.substring(0,5)&&d&&d.call(f,t)},r.append=function(t){var n=this.data;if(w&&(t instanceof v||t instanceof w)){for(var r="",i=new w(t),s=0,u=i.length;s<u;s++)r+=String.fromCharCode(i[s]);n.push(r)}else if("Blob"===e(t)||"File"===e(t)){if(!a)throw new c("NOT_READABLE_ERR");var f=new a;n.push(f.readAsBinaryString(t))}else t instanceof o?"base64"===t.encoding&&b?n.push(b(t.data)):"URI"===t.encoding?n.push(decodeURIComponent(t.data)):"raw"===t.encoding&&n.push(t.data):("string"!=typeof t&&(t+=""),n.push(unescape(encodeURIComponent(t))))},r.getBlob=function(t){return arguments.length||(t=null),new o(this.data.join(""),t,"raw")},r.toString=function(){return"[object BlobBuilder]"},i.slice=function(t,e,n){var r=arguments.length;return r<3&&(n=null),new o(this.data.slice(t,r>1?e:this.data.length),n,this.encoding)},i.toString=function(){return"[object Blob]"},i.close=function(){this.size=0,delete this.data},n}(t);t.Blob=function(t,e){var o=e?e.type||"":"",r=new n;if(t)for(var i=0,a=t.length;i<a;i++)Uint8Array&&t[i]instanceof Uint8Array?r.append(t[i].buffer):r.append(t[i]);var c=r.getBlob(o);return!c.slice&&c.webkitSlice&&(c.slice=c.webkitSlice),c};var o=Object.getPrototypeOf||function(t){return t.__proto__};t.Blob.prototype=o(new t.Blob)}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content||this)},function(t,e,n){"use strict";t.exports=function(){return n(6).saveAs||function(){}}},function(t,e,n){var o,r=r||function(t){"use strict";if(!("undefined"==typeof t||"undefined"!=typeof navigator&&/MSIE [1-9]\./.test(navigator.userAgent))){var e=t.document,n=function(){return t.URL||t.webkitURL||t},o=e.createElementNS("http://www.w3.org/1999/xhtml","a"),r="download"in o,i=function(t){var e=new MouseEvent("click");t.dispatchEvent(e)},a=/constructor/i.test(t.HTMLElement)||t.safari,c=/CriOS\/[\d]+/.test(navigator.userAgent),s=function(e){(t.setImmediate||t.setTimeout)(function(){throw e},0)},u="application/octet-stream",f=4e4,l=function(t){var e=function(){"string"==typeof t?n().revokeObjectURL(t):t.remove()};setTimeout(e,f)},d=function(t,e,n){e=[].concat(e);for(var o=e.length;o--;){var r=t["on"+e[o]];if("function"==typeof r)try{r.call(t,n||t)}catch(i){s(i)}}},p=function(t){return/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(t.type)?new Blob([String.fromCharCode(65279),t],{type:t.type}):t},h=function(e,s,f){f||(e=p(e));var h,b=this,v=e.type,w=v===u,g=function(){d(b,"writestart progress write writeend".split(" "))},y=function(){if((c||w&&a)&&t.FileReader){var o=new FileReader;return o.onloadend=function(){var e=c?o.result:o.result.replace(/^data:[^;]*;/,"data:attachment/file;"),n=t.open(e,"_blank");n||(t.location.href=e),e=void 0,b.readyState=b.DONE,g()},o.readAsDataURL(e),void(b.readyState=b.INIT)}if(h||(h=n().createObjectURL(e)),w)t.location.href=h;else{var r=t.open(h,"_blank");r||(t.location.href=h)}b.readyState=b.DONE,g(),l(h)};return b.readyState=b.INIT,r?(h=n().createObjectURL(e),void setTimeout(function(){o.href=h,o.download=s,i(o),g(),l(h),b.readyState=b.DONE})):void y()},b=h.prototype,v=function(t,e,n){return new h(t,e||t.name||"download",n)};return"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob?function(t,e,n){return e=e||t.name||"download",n||(t=p(t)),navigator.msSaveOrOpenBlob(t,e)}:(b.abort=function(){},b.readyState=b.INIT=0,b.WRITING=1,b.DONE=2,b.error=b.onwritestart=b.onprogress=b.onwrite=b.onabort=b.onerror=b.onwriteend=null,v)}}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content);"undefined"!=typeof t&&t.exports?t.exports.saveAs=r:null!==n(7)&&null!==n(8)&&(o=function(){return r}.call(e,n,e,t),!(void 0!==o&&(t.exports=o)))},function(t,e){t.exports=function(){throw new Error("define cannot be used indirect")}},function(t,e){(function(e){t.exports=e}).call(e,{})}])});