Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e865e37af9 | ||
|
|
a606064f37 | ||
|
|
28a86d90c4 | ||
|
|
5914e2a573 | ||
|
|
6356c3f6f6 | ||
|
|
24f9aaca80 | ||
|
|
f1959c87cd | ||
|
|
dfd58561fb | ||
|
|
a5dbf55c17 | ||
|
|
5978f3c577 | ||
|
|
9570cf7362 | ||
|
|
b1158d0c33 | ||
|
|
b6c236d96d | ||
|
|
164deec5ab | ||
|
|
99a89750b0 | ||
|
|
ff675f8052 | ||
|
|
17d5c67eb3 | ||
|
|
70bb521e5d | ||
|
|
b4c11367c0 | ||
|
|
281a1c1a93 | ||
|
|
d02373e40d | ||
|
|
d7f5db3244 | ||
|
|
b4a918669a | ||
|
|
5733e40e5a | ||
|
|
74f089808e | ||
|
|
fe42ec4055 | ||
|
|
0b90542535 | ||
|
|
c3e4a45021 | ||
|
|
db089ce81e | ||
|
|
1bf9b35b54 | ||
|
|
c347c51f6e | ||
|
|
945f08bc74 | ||
|
|
dffa3a4989 | ||
|
|
4db4a78aad | ||
|
|
d89ed13171 | ||
|
|
aa9f4e0e03 | ||
|
|
cafa1bfebb | ||
|
|
5ed507ef8a | ||
|
|
eb8d76f845 | ||
|
|
8739c467c6 | ||
|
|
d8870ded68 | ||
|
|
9751591281 | ||
|
|
b3cad8efea | ||
|
|
3843680045 | ||
|
|
4ac2c6d6c2 | ||
|
|
f1a8bf9fb0 | ||
|
|
b2bf6d86f5 | ||
|
|
0b137cf80a | ||
|
|
d84a5c2f3a | ||
|
|
47ff4cd74a | ||
|
|
c0c85f387b | ||
|
|
7b242c2d78 |
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
["env", {
|
||||||
|
"targets": {
|
||||||
|
"browsers": [
|
||||||
|
"ie > 9"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
"transform-es2015-modules-umd"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"production": {
|
||||||
|
"presets": ["minify"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
node_modules/
|
||||||
|
.DS_Store
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
/dist/
|
||||||
Vendored
-2
@@ -1,2 +0,0 @@
|
|||||||
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
|
|
||||||
var saveAs=saveAs||function(r){"use strict";if("undefined"==typeof navigator||!/MSIE [1-9]\./.test(navigator.userAgent)){var e=r.document,o=function(){return r.URL||r.webkitURL||r},t=e.createElementNS("http://www.w3.org/1999/xhtml","a"),f="download"in t,n=function(r){var e=new MouseEvent("click");r.dispatchEvent(e)},i=/Version\/[\d\.]+.*Safari/.test(navigator.userAgent),a=r.webkitRequestFileSystem,d=r.requestFileSystem||a||r.mozRequestFileSystem,C=function(e){(r.setImmediate||r.setTimeout)(function(){throw e},0)},m="application/octet-stream",S=0,h=4e4,g=function(r){var e=function(){"string"==typeof r?o().revokeObjectURL(r):r.remove()};setTimeout(e,h)},c=function(r,e,o){e=[].concat(e);for(var t=e.length;t--;){var f=r["on"+e[t]];if("function"==typeof f)try{f.call(r,o||r)}catch(n){C(n)}}},u=function(r){return/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(r.type)?new Blob([String.fromCharCode(65279),r],{type:r.type}):r},s=function(e,C,h){h||(e=u(e));var s,l,v,p=this,w=e.type,y=!1,x=function(){c(p,"writestart progress write writeend".split(" "))},R=function(){if(l&&i&&"undefined"!=typeof FileReader){var t=new FileReader;return t.onloadend=function(){var r=t.result;l.location.href="data:attachment/file"+r.slice(r.search(/[,;]/)),p.readyState=p.DONE,x()},t.readAsDataURL(e),void(p.readyState=p.INIT)}if((y||!s)&&(s=o().createObjectURL(e)),l)l.location.href=s;else{var f=r.open(s,"_blank");void 0===f&&i&&(r.location.href=s)}p.readyState=p.DONE,x(),g(s)},O=function(r){return function(){return p.readyState!==p.DONE?r.apply(this,arguments):void 0}},b={create:!0,exclusive:!1};return p.readyState=p.INIT,C||(C="download"),f?(s=o().createObjectURL(e),void setTimeout(function(){t.href=s,t.download=C,n(t),x(),g(s),p.readyState=p.DONE})):(r.chrome&&w&&w!==m&&(v=e.slice||e.webkitSlice,e=v.call(e,0,e.size,m),y=!0),a&&"download"!==C&&(C+=".download"),(w===m||a)&&(l=r),d?(S+=e.size,void d(r.TEMPORARY,S,O(function(r){r.root.getDirectory("saved",b,O(function(r){var o=function(){r.getFile(C,b,O(function(r){r.createWriter(O(function(o){o.onwriteend=function(e){l.location.href=r.toURL(),p.readyState=p.DONE,c(p,"writeend",e),g(r)},o.onerror=function(){var r=o.error;r.code!==r.ABORT_ERR&&R()},"writestart progress write abort".split(" ").forEach(function(r){o["on"+r]=p["on"+r]}),o.write(e),p.abort=function(){o.abort(),p.readyState=p.DONE},p.readyState=p.WRITING}),R)}),R)};r.getFile(C,{create:!1},O(function(r){r.remove(),o()}),O(function(r){r.code===r.NOT_FOUND_ERR?o():R()}))}),R)}),R)):void R())},l=s.prototype,v=function(r,e,o){return new s(r,e,o)};return"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob?function(r,e,o){return o||(r=u(r)),navigator.msSaveOrOpenBlob(r,e||"download")}:(l.abort=function(){var r=this;r.readyState=r.DONE,c(r,"abort")},l.readyState=l.INIT=0,l.WRITING=1,l.DONE=2,l.error=l.onwritestart=l.onprogress=l.onwrite=l.onabort=l.onerror=l.onwriteend=null,v)}}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content);"undefined"!=typeof module&&module.exports?module.exports.saveAs=saveAs:"undefined"!=typeof define&&null!==define&&null!==define.amd&&define([],function(){return saveAs});
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
The MIT License
|
||||||
|
|
||||||
Copyright © 2016 [Eli Grey][1].
|
Copyright © 2016 [Eli Grey][1].
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
If you need to save really large files bigger then the blob's size limitation or don't have
|
||||||
|
enough RAM, then have a look at the more advanced [StreamSaver.js](https://github.com/jimmywarting/StreamSaver.js)
|
||||||
|
that can save data directly to the hard drive asynchronously with the power of the new streams API. That will have
|
||||||
|
support for progress, cancelation and knowing when it's done writing
|
||||||
|
|
||||||
FileSaver.js
|
FileSaver.js
|
||||||
============
|
============
|
||||||
|
|
||||||
@@ -27,6 +32,7 @@ Supported browsers
|
|||||||
| Opera < 15 | data: URI | No | n/a | [Blob.js](https://github.com/eligrey/Blob.js) |
|
| Opera < 15 | data: URI | No | n/a | [Blob.js](https://github.com/eligrey/Blob.js) |
|
||||||
| Safari 6.1+* | Blob | No | ? | None |
|
| Safari 6.1+* | Blob | No | ? | None |
|
||||||
| Safari < 6 | data: URI | No | n/a | [Blob.js](https://github.com/eligrey/Blob.js) |
|
| Safari < 6 | data: URI | No | n/a | [Blob.js](https://github.com/eligrey/Blob.js) |
|
||||||
|
| Safari 10.1+ | Blob | Yes | n/a | None |
|
||||||
|
|
||||||
Feature detection is possible:
|
Feature detection is possible:
|
||||||
|
|
||||||
@@ -62,11 +68,18 @@ Pass `true` for `disableAutoBOM` if you don't want FileSaver.js to automatically
|
|||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
### Saving text using require
|
||||||
|
```js
|
||||||
|
var FileSaver = require('file-saver');
|
||||||
|
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
|
||||||
|
FileSaver.saveAs(blob, "hello world.txt");
|
||||||
|
```
|
||||||
|
|
||||||
### Saving text
|
### Saving text
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
|
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
|
||||||
saveAs(blob, "hello world.txt");
|
FileSaver.saveAs(blob, "hello world.txt");
|
||||||
```
|
```
|
||||||
|
|
||||||
The standard W3C File API [`Blob`][4] interface is not available in all browsers.
|
The standard W3C File API [`Blob`][4] interface is not available in all browsers.
|
||||||
@@ -82,6 +95,9 @@ canvas.toBlob(function(blob) {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note: The standard HTML5 `canvas.toBlob()` method is not available in all browsers.
|
||||||
|
[canvas-toBlob.js][6] is a cross-browser `canvas.toBlob()` that polyfills this.
|
||||||
|
|
||||||
### Saving File
|
### Saving File
|
||||||
|
|
||||||
You can save a File constructor without specifying a filename. The
|
You can save a File constructor without specifying a filename. The
|
||||||
@@ -91,11 +107,9 @@ But if you still want to change the name, then you can change it in the 2nd argu
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
var file = new File(["Hello, world!"], "hello world.txt", {type: "text/plain;charset=utf-8"});
|
var file = new File(["Hello, world!"], "hello world.txt", {type: "text/plain;charset=utf-8"});
|
||||||
saveAs(file);
|
FileSaver.saveAs(file);
|
||||||
```
|
```
|
||||||
|
|
||||||
Note: The standard HTML5 `canvas.toBlob()` method is not available in all browsers.
|
|
||||||
[canvas-toBlob.js][6] is a cross-browser `canvas.toBlob()` that polyfills this.
|
|
||||||
|
|
||||||
|
|
||||||

|

|
||||||
@@ -107,19 +121,6 @@ Note: The standard HTML5 `canvas.toBlob()` method is not available in all browse
|
|||||||
[5]: https://github.com/eligrey/Blob.js
|
[5]: https://github.com/eligrey/Blob.js
|
||||||
[6]: https://github.com/eligrey/canvas-toBlob.js
|
[6]: https://github.com/eligrey/canvas-toBlob.js
|
||||||
|
|
||||||
Contributing
|
|
||||||
------------
|
|
||||||
|
|
||||||
The `FileSaver.js` distribution file is compiled with Uglify.js like so:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
uglifyjs FileSaver.js --mangle --comments /@source/ > FileSaver.min.js
|
|
||||||
# or simply:
|
|
||||||
npm run build
|
|
||||||
```
|
|
||||||
|
|
||||||
Please make sure you build a production version before submitting a pull request.
|
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
@@ -127,3 +128,9 @@ Installation
|
|||||||
npm install file-saver --save
|
npm install file-saver --save
|
||||||
bower install file-saver
|
bower install file-saver
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Additionally, TypeScript definitions can be installed via:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install @types/file-saver --save-dev
|
||||||
|
```
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "file-saver",
|
"name": "file-saver",
|
||||||
"main": "FileSaver.js",
|
"main": "dist/FileSaver.js",
|
||||||
"version": "1.3.0",
|
"version": "1.3.8",
|
||||||
"homepage": "https://github.com/eligrey/FileSaver.js",
|
"homepage": "https://github.com/eligrey/FileSaver.js",
|
||||||
"authors": [
|
"authors": [
|
||||||
"Eli Grey <[email protected]>"
|
"Eli Grey <[email protected]>"
|
||||||
|
|||||||
Regular → Executable
+1
-1
@@ -195,7 +195,7 @@ html_options_form.addEventListener("submit", function(event) {
|
|||||||
saveAs(
|
saveAs(
|
||||||
new BB(
|
new BB(
|
||||||
[xml_serializer.serializeToString(doc)]
|
[xml_serializer.serializeToString(doc)]
|
||||||
, {type: "application/xhtml+xml;charset=" + document.characterSet}
|
, {type: "text/plain;charset=" + document.characterSet}
|
||||||
)
|
)
|
||||||
, (html_filename.value || html_filename.placeholder) + ".xhtml"
|
, (html_filename.value || html_filename.placeholder) + ".xhtml"
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/demo/demo.js */
|
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/demo/demo.js */
|
||||||
(function(n){"use strict";var s=n.document,g=function(A){return s.getElementById(A)},b=n.sessionStorage,x=function(){return n.Blob},f=g("canvas"),r=g("canvas-options"),y=g("canvas-filename"),p=g("canvas-clear"),q=g("text"),t=g("text-options"),h=g("text-filename"),m=g("html"),e=g("html-options"),i=g("html-filename"),u=f.getContext("2d"),z=false,a=b.x_points||[],o=b.y_points||[],d=b.drag_points||[],j=function(A,C,B){a.push(A);o.push(C);d.push(B)},l=function(){f.width=f.width;u.lineWidth=6;u.lineJoin="round";u.strokeStyle="#000000";var B=0,A=a.length;for(;B<A;B++){u.beginPath();if(B&&d[B]){u.moveTo(a[B-1],o[B-1])}else{u.moveTo(a[B]-1,o[B])}u.lineTo(a[B],o[B]);u.closePath();u.stroke()}},c=function(){z=false},w=function(E){var D="h6 h5 h4 h3 h2 h1".split(" "),C=D.length,F,G;while(C--){F=E.getElementsByTagName(D[C]);for(var B=0,A=F.length;B<A;B++){G=F[B].textContent.trim();if(G){return G}}}},v=s.implementation,k=function(D){var B=v.createDocumentType("html",null,null),J=v.createDocument("http://www.w3.org/1999/xhtml","html",B),A=J.documentElement,H=A.appendChild(J.createElement("head")),K=H.appendChild(J.createElement("meta")),I=H.appendChild(J.createElement("title")),E=A.appendChild(J.createElement("body")),C=0,G=D.childNodes.length;K.setAttribute("charset",D.ownerDocument.characterSet);for(;C<G;C++){E.appendChild(J.importNode(D.childNodes.item(C),true))}var F=w(J);if(F){I.appendChild(J.createTextNode(F))}return J};f.width=500;f.height=300;if(typeof a==="string"){a=JSON.parse(a)}if(typeof o==="string"){o=JSON.parse(o)}if(typeof d==="string"){d=JSON.parse(d)}if(b.canvas_filename){y.value=b.canvas_filename}if(b.text){q.value=b.text}if(b.text_filename){h.value=b.text_filename}if(b.html){m.innerHTML=b.html}if(b.html_filename){i.value=b.html_filename}z=true;l();z=false;p.addEventListener("click",function(){f.width=f.width;a.length=o.length=d.length=0},false);f.addEventListener("mousedown",function(A){A.preventDefault();z=true;j(A.pageX-f.offsetLeft,A.pageY-f.offsetTop,false);l()},false);f.addEventListener("mousemove",function(A){if(z){j(A.pageX-f.offsetLeft,A.pageY-f.offsetTop,true);l()}},false);f.addEventListener("mouseup",c,false);f.addEventListener("mouseout",c,false);r.addEventListener("submit",function(A){A.preventDefault();f.toBlobHD(function(B){saveAs(B,(y.value||y.placeholder)+".png")},"image/png")},false);t.addEventListener("submit",function(A){A.preventDefault();var B=x();saveAs(new B([q.value||q.placeholder],{type:"text/plain;charset="+s.characterSet}),(h.value||h.placeholder)+".txt")},false);e.addEventListener("submit",function(B){B.preventDefault();var D=x(),A=new XMLSerializer,C=k(m);saveAs(new D([A.serializeToString(C)],{type:"application/xhtml+xml;charset="+s.characterSet}),(i.value||i.placeholder)+".xhtml")},false);n.addEventListener("unload",function(){b.x_points=JSON.stringify(a);b.y_points=JSON.stringify(o);b.drag_points=JSON.stringify(d);b.canvas_filename=y.value;b.text=q.value;b.text_filename=h.value;b.html=m.innerHTML;b.html_filename=i.value},false)}(self));
|
(function(n){"use strict";var s=n.document,g=function(A){return s.getElementById(A)},b=n.sessionStorage,x=function(){return n.Blob},f=g("canvas"),r=g("canvas-options"),y=g("canvas-filename"),p=g("canvas-clear"),q=g("text"),t=g("text-options"),h=g("text-filename"),m=g("html"),e=g("html-options"),i=g("html-filename"),u=f.getContext("2d"),z=false,a=b.x_points||[],o=b.y_points||[],d=b.drag_points||[],j=function(A,C,B){a.push(A);o.push(C);d.push(B)},l=function(){f.width=f.width;u.lineWidth=6;u.lineJoin="round";u.strokeStyle="#000000";var B=0,A=a.length;for(;B<A;B++){u.beginPath();if(B&&d[B]){u.moveTo(a[B-1],o[B-1])}else{u.moveTo(a[B]-1,o[B])}u.lineTo(a[B],o[B]);u.closePath();u.stroke()}},c=function(){z=false},w=function(E){var D="h6 h5 h4 h3 h2 h1".split(" "),C=D.length,F,G;while(C--){F=E.getElementsByTagName(D[C]);for(var B=0,A=F.length;B<A;B++){G=F[B].textContent.trim();if(G){return G}}}},v=s.implementation,k=function(D){var B=v.createDocumentType("html",null,null),J=v.createDocument("http://www.w3.org/1999/xhtml","html",B),A=J.documentElement,H=A.appendChild(J.createElement("head")),K=H.appendChild(J.createElement("meta")),I=H.appendChild(J.createElement("title")),E=A.appendChild(J.createElement("body")),C=0,G=D.childNodes.length;K.setAttribute("charset",D.ownerDocument.characterSet);for(;C<G;C++){E.appendChild(J.importNode(D.childNodes.item(C),true))}var F=w(J);if(F){I.appendChild(J.createTextNode(F))}return J};f.width=500;f.height=300;if(typeof a==="string"){a=JSON.parse(a)}if(typeof o==="string"){o=JSON.parse(o)}if(typeof d==="string"){d=JSON.parse(d)}if(b.canvas_filename){y.value=b.canvas_filename}if(b.text){q.value=b.text}if(b.text_filename){h.value=b.text_filename}if(b.html){m.innerHTML=b.html}if(b.html_filename){i.value=b.html_filename}z=true;l();z=false;p.addEventListener("click",function(){f.width=f.width;a.length=o.length=d.length=0},false);f.addEventListener("mousedown",function(A){A.preventDefault();z=true;j(A.pageX-f.offsetLeft,A.pageY-f.offsetTop,false);l()},false);f.addEventListener("mousemove",function(A){if(z){j(A.pageX-f.offsetLeft,A.pageY-f.offsetTop,true);l()}},false);f.addEventListener("mouseup",c,false);f.addEventListener("mouseout",c,false);r.addEventListener("submit",function(A){A.preventDefault();f.toBlobHD(function(B){saveAs(B,(y.value||y.placeholder)+".png")},"image/png")},false);t.addEventListener("submit",function(A){A.preventDefault();var B=x();saveAs(new B([q.value||q.placeholder],{type:"text/plain;charset="+s.characterSet}),(h.value||h.placeholder)+".txt")},false);e.addEventListener("submit",function(B){B.preventDefault();var D=x(),A=new XMLSerializer,C=k(m);saveAs(new D([A.serializeToString(C)],{type:"text/plain;charset="+s.characterSet}),(i.value||i.placeholder)+".xhtml")},false);n.addEventListener("unload",function(){b.x_points=JSON.stringify(a);b.y_points=JSON.stringify(o);b.drag_points=JSON.stringify(d);b.canvas_filename=y.value;b.text=q.value;b.text_filename=h.value;b.html=m.innerHTML;b.html_filename=i.value},false)}(self));
|
||||||
Generated
+2783
File diff suppressed because it is too large
Load Diff
+16
-4
@@ -1,11 +1,20 @@
|
|||||||
{
|
{
|
||||||
"name": "file-saver",
|
"name": "file-saver",
|
||||||
"version": "1.3.0",
|
"version": "1.3.8",
|
||||||
"description": "An HTML5 saveAs() FileSaver implementation",
|
"description": "An HTML5 saveAs() FileSaver implementation",
|
||||||
"main": "FileSaver.js",
|
"main": "dist/FileSaver.js",
|
||||||
|
"module": "src/FileSaver.js",
|
||||||
|
"files": [
|
||||||
|
"dist/FileSaver.js",
|
||||||
|
"dist/FileSaver.min.js",
|
||||||
|
"src/FileSaver.js"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 0",
|
"test": "echo \"Error: no test specified\" && exit 0",
|
||||||
"build": "node_modules/.bin/uglifyjs FileSaver.js --mangle --comments /@source/ > FileSaver.min.js"
|
"build:development": "mkdir -p dist && babel src/FileSaver.js --out-file=dist/FileSaver.js",
|
||||||
|
"build:production": "NODE_ENV=production npm run build:development -- --out-file=dist/FileSaver.min.js",
|
||||||
|
"build": "npm run build:development && npm run build:production",
|
||||||
|
"prepublishOnly": "npm run build"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -23,6 +32,9 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/eligrey/FileSaver.js#readme",
|
"homepage": "https://github.com/eligrey/FileSaver.js#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"uglify-js": "^2.6.2"
|
"babel-cli": "^6.26.0",
|
||||||
|
"babel-plugin-transform-es2015-modules-umd": "^6.24.1",
|
||||||
|
"babel-preset-env": "^1.6.1",
|
||||||
|
"babel-preset-minify": "^0.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
/* FileSaver.js
|
/* FileSaver.js
|
||||||
* A saveAs() FileSaver implementation.
|
* A saveAs() FileSaver implementation.
|
||||||
* 1.3.0
|
* 1.3.8
|
||||||
|
* 2018-03-22 14:03:47
|
||||||
*
|
*
|
||||||
* By Eli Grey, http://eligrey.com
|
* By Eli Grey, https://eligrey.com
|
||||||
* License: MIT
|
* License: MIT
|
||||||
* See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
|
* See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
|
||||||
*/
|
*/
|
||||||
@@ -10,9 +11,9 @@
|
|||||||
/*global self */
|
/*global self */
|
||||||
/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
|
/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
|
||||||
|
|
||||||
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
|
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/src/FileSaver.js */
|
||||||
|
|
||||||
var saveAs = saveAs || (function(view) {
|
export var saveAs = saveAs || (function(view) {
|
||||||
"use strict";
|
"use strict";
|
||||||
// IE <10 is explicitly unsupported
|
// IE <10 is explicitly unsupported
|
||||||
if (typeof view === "undefined" || typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
|
if (typeof view === "undefined" || typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
|
||||||
@@ -30,9 +31,11 @@ var saveAs = saveAs || (function(view) {
|
|||||||
var event = new MouseEvent("click");
|
var event = new MouseEvent("click");
|
||||||
node.dispatchEvent(event);
|
node.dispatchEvent(event);
|
||||||
}
|
}
|
||||||
, is_safari = /constructor/i.test(view.HTMLElement)
|
, is_safari = /constructor/i.test(view.HTMLElement) || view.safari
|
||||||
|
, is_chrome_ios =/CriOS\/[\d]+/.test(navigator.userAgent)
|
||||||
|
, setImmediate = view.setImmediate || view.setTimeout
|
||||||
, throw_outside = function(ex) {
|
, throw_outside = function(ex) {
|
||||||
(view.setImmediate || view.setTimeout)(function() {
|
setImmediate(function() {
|
||||||
throw ex;
|
throw ex;
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
@@ -86,12 +89,14 @@ var saveAs = saveAs || (function(view) {
|
|||||||
}
|
}
|
||||||
// on any filesys errors revert to saving with object URLs
|
// on any filesys errors revert to saving with object URLs
|
||||||
, fs_error = function() {
|
, fs_error = function() {
|
||||||
if (force && is_safari && view.FileReader) {
|
if ((is_chrome_ios || (force && is_safari)) && view.FileReader) {
|
||||||
// Safari doesn't allow downloading of blob urls
|
// Safari doesn't allow downloading of blob urls
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
reader.onloadend = function() {
|
reader.onloadend = function() {
|
||||||
var base64Data = reader.result;
|
var url = is_chrome_ios ? reader.result : reader.result.replace(/^data:[^;]*;/, 'data:attachment/file;');
|
||||||
view.location.href = "data:attachment/file" + base64Data.slice(base64Data.search(/[,;]/));
|
var popup = view.open(url, '_blank');
|
||||||
|
if(!popup) view.location.href = url;
|
||||||
|
url=undefined; // release reference before dispatching
|
||||||
filesaver.readyState = filesaver.DONE;
|
filesaver.readyState = filesaver.DONE;
|
||||||
dispatch_all();
|
dispatch_all();
|
||||||
};
|
};
|
||||||
@@ -121,14 +126,14 @@ var saveAs = saveAs || (function(view) {
|
|||||||
|
|
||||||
if (can_use_save_link) {
|
if (can_use_save_link) {
|
||||||
object_url = get_URL().createObjectURL(blob);
|
object_url = get_URL().createObjectURL(blob);
|
||||||
setTimeout(function() {
|
setImmediate(function() {
|
||||||
save_link.href = object_url;
|
save_link.href = object_url;
|
||||||
save_link.download = name;
|
save_link.download = name;
|
||||||
click(save_link);
|
click(save_link);
|
||||||
dispatch_all();
|
dispatch_all();
|
||||||
revoke(object_url);
|
revoke(object_url);
|
||||||
filesaver.readyState = filesaver.DONE;
|
filesaver.readyState = filesaver.DONE;
|
||||||
});
|
}, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +144,7 @@ var saveAs = saveAs || (function(view) {
|
|||||||
return new FileSaver(blob, name || blob.name || "download", no_auto_bom);
|
return new FileSaver(blob, name || blob.name || "download", no_auto_bom);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
// IE 10+ (native saveAs)
|
// IE 10+ (native saveAs)
|
||||||
if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
|
if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
|
||||||
return function(blob, name, no_auto_bom) {
|
return function(blob, name, no_auto_bom) {
|
||||||
@@ -151,6 +157,9 @@ var saveAs = saveAs || (function(view) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: detect chrome extensions & packaged apps
|
||||||
|
//save_link.target = "_blank";
|
||||||
|
|
||||||
FS_proto.abort = function(){};
|
FS_proto.abort = function(){};
|
||||||
FS_proto.readyState = FS_proto.INIT = 0;
|
FS_proto.readyState = FS_proto.INIT = 0;
|
||||||
FS_proto.WRITING = 1;
|
FS_proto.WRITING = 1;
|
||||||
@@ -169,16 +178,5 @@ var saveAs = saveAs || (function(view) {
|
|||||||
}(
|
}(
|
||||||
typeof self !== "undefined" && self
|
typeof self !== "undefined" && self
|
||||||
|| typeof window !== "undefined" && window
|
|| typeof window !== "undefined" && window
|
||||||
|| this.content
|
|| this
|
||||||
));
|
));
|
||||||
// `self` is undefined in Firefox for Android content script context
|
|
||||||
// while `this` is nsIContentFrameMessageManager
|
|
||||||
// with an attribute `content` that corresponds to the window
|
|
||||||
|
|
||||||
if (typeof module !== "undefined" && module.exports) {
|
|
||||||
module.exports.saveAs = saveAs;
|
|
||||||
} else if ((typeof define !== "undefined" && define !== null) && (define.amd !== null)) {
|
|
||||||
define([], function() {
|
|
||||||
return saveAs;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user