62 Commits
Author SHA1 Message Date
Eli GreyandGitHub 648ff96f8b Use FileReader in macOS native apps using WebKit (#613)
Use FileReader in macOS native apps using WebKit
2020-01-30 16:44:01 -08:00
Rajiv Shah 7a8ff3cc6a Switch isWebKit and isSafari conditions to maintain behavior
Using isWebKit before isSafari could cause Safari to use FileReader even if force === false, since the user agent for Safari also includes AppleWebKit
2020-01-30 19:40:57 -05:00
Rajiv Shah 0a2e868b48 Rebuild dist 2020-01-30 19:20:04 -05:00
Rajiv Shah 16a8bb9e8f Bump version to 2.0.3 2020-01-30 19:18:02 -05:00
Rajiv Shah 572f254834 Ensure Chrome iOS still works 2020-01-30 19:00:37 -05:00
Rajiv Shah d3d2bd20d6 Merge branch 'master' into feature/webkit-macos 2020-01-30 18:50:01 -05:00
Susanne GerberandJimmy Wärting 480d547986 fix small spelling error 2020-01-25 23:06:39 +01:00
Rajiv Shah db7880179f Use FileReader in macOS native apps using WebKit 2019-12-21 17:41:53 -05:00
Eli GreyandGitHub 9a0a1e4ae2 Add GitHub Sponsors funding method 2019-10-22 10:42:27 -07:00
Eli GreyandGitHub 1ea2325a75 Bump mixin-deep from 1.3.1 to 1.3.2 (#601)
Bump mixin-deep from 1.3.1 to 1.3.2
2019-10-14 13:13:09 -07:00
dependabot[bot]andGitHub 35e9d8127d Bump mixin-deep from 1.3.1 to 1.3.2
Bumps [mixin-deep](https://github.com/jonschlinkert/mixin-deep) from 1.3.1 to 1.3.2.
- [Release notes](https://github.com/jonschlinkert/mixin-deep/releases)
- [Commits](https://github.com/jonschlinkert/mixin-deep/compare/1.3.1...1.3.2)

Signed-off-by: dependabot[bot] <[email protected]>
2019-10-14 18:22:49 +00:00
Eli GreyandGitHub 538c4b5751 Bump lodash from 4.17.11 to 4.17.14 (#575)
Bump lodash from 4.17.11 to 4.17.14
2019-10-14 11:21:37 -07:00
Eli GreyandGitHub 556db1f6df Merge pull request #577 from chrisdoble/master
Fix downloads in Chrome iOS
2019-07-15 23:34:35 -07:00
Chris Doble b95a82a3ec Check that FileReader exists, not that it's an object
Fixes #576
2019-07-16 16:14:44 +10:00
dependabot[bot]andGitHub 35f0e568d9 Bump lodash from 4.17.11 to 4.17.14
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.11 to 4.17.14.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.11...4.17.14)

Signed-off-by: dependabot[bot] <[email protected]>
2019-07-11 03:41:59 +00:00
Eli GreyandGitHub a7e1ccfc44 Create FUNDING.yml 2019-06-11 22:39:07 -07:00
Jimmy Wärting 1bc9ed39c4 bump minor version 2019-05-14 10:00:17 +02:00
Marcin RybackiandJimmy Wärting 71f266f93e Missing dist build 2019-05-14 09:46:41 +02:00
Marcin RybackiandJimmy Wärting 9bd5261f60 Catching an exception on Send. This happens when request for HEAD returns 405 Method Not Allowed. Instead of error http status, this may throw an exception. Return false and fallback to link download. 2019-05-14 09:46:41 +02:00
Oskar KöökandJimmy Wärting 3caf053bbd fix autoBom documentation 2019-05-14 09:45:57 +02:00
josephroccaandJimmy Wärting 04ca36440d Updated Chrome data 2019-03-01 09:47:36 +01:00
zachary parrishandJimmy Wärting d87b419616 Update README.md
Just made some minor grammar changes
2019-02-17 17:45:48 +01:00
Jimmy WärtingandGitHub 3e46b73052 Update package.json 2019-02-17 15:24:08 +01:00
TypeError64andJimmy Wärting b1ab588946 Update README.md 2019-02-01 11:29:14 +01:00
Nathan Phillip BrinkandJimmy Wärting 4a73fd7a2d Fix a few spelling errors. 2019-01-07 13:02:54 +01:00
Alexander СветлыйandJimmy Wärting 0e905a3e06 Update README.md
Fix import
2018-12-29 11:02:50 +01:00
segoviaandJimmy Wärting 283f438c31 Fix accidental rewrite of global saveAs function
The change is just to put parentheses around the code after `var saveAs = _global.saveAs ||`
and then indent it properly.

closes #498
2018-12-29 11:01:25 +01:00
Jimmy Wärting be09a02e8c Removed eval
closes #491
2018-11-14 12:34:32 +01:00
NeeEooandJimmy Wärting 72effade4d Fixed grammar and punctuation 2018-11-02 19:45:09 +01:00
Vasyl ZuzyakandJimmy Wärting 3ecf5a9f55 fix: make typo go away 2018-11-02 14:02:44 +01:00
asaarnakandJimmy Wärting 6d09d0980b Add sourcemap to /dist folder. #481 2018-10-25 13:11:46 +02:00
Jimmy Wärting 00183093bf don’t throw on module.exports 2018-10-18 11:40:36 +02:00
Ben NiandJimmy Wärting cf70d125b0 replaced the non-breaking space at with space
This is causing IE to unable to recognize the { on line 49
2018-10-16 23:58:13 +02:00
Eli GreyandGitHub bbecae4d41 Merge pull request #477 from jeffbdye/patch-1
Minor misspellings in comments
2018-10-10 12:21:16 -07:00
Jeff DyeandGitHub b08a6d256c Minor misspellings in comments
Just some quick fixes for comments in the file.
2018-10-10 15:12:43 -04:00
Patrick LöckerandJimmy Wärting 767f830766 Fix spelling of click-function 2018-09-28 15:01:52 +02:00
Jimmy Wärting 74846b33fe switched export method 2018-09-27 21:00:17 +02:00
Jimmy WärtingandGitHub 556af82e6a changed the way how you import 2018-09-26 19:33:47 +02:00
Jimmy WärtingandGitHub 15d96ca835 Update CHANGELOG.md 2018-09-26 19:27:47 +02:00
Jimmy WärtingandGitHub 047fa34d15 Rename changelog.md to CHANGELOG.md 2018-09-26 18:57:34 +02:00
Joshua RipponandJimmy Wärting 5183da9c57 Updated how saveAs is imported 2018-09-26 18:48:39 +02:00
Jimmy WärtingandGitHub b796e069a9 reference another issue 2018-09-26 17:12:48 +02:00
Jimmy WärtingandGitHub 410208d4f9 made issues to links 2018-09-26 17:10:49 +02:00
Jimmy Wärting 70c261d026 rc.2
Dispatch event instead of using a.click()
closes #465

added a changelog
closes #466

Made third argument as a object instead for easier transition to v2
2018-09-26 17:04:34 +02:00
Jimmy WärtingandGitHub f3b45ae580 Remove the implementation
The spec was abandoned.

Many download files from the server so recommend them to use headers instead
2018-09-26 12:40:14 +02:00
Jimmy WärtingandGitHub 31eccd14f9 everything but dist folder 2018-09-26 12:19:51 +02:00
Jimmy WärtingandGitHub eb11f655e6 fix bom api docs 2018-09-26 12:12:52 +02:00
Jimmy Wärting eaeac8dc3c fix BOM api docs 2018-09-26 12:09:50 +02:00
Jimmy Wärting 9e931126f5 docs for using url 2018-09-26 12:00:35 +02:00
Jimmy Wärting 37d757bbc6 don’t crash in worker 2018-09-26 12:00:35 +02:00
Jimmy Wärting 4de5ebccc8 new version 2018-09-26 12:00:35 +02:00
Jimmy Wärting 5cbe331ec8 include the list folder 2018-09-26 12:00:35 +02:00
Jimmy Wärting a67731daf4 update dev rep 2018-09-26 12:00:35 +02:00
Jimmy Wärting 660c35cdb8 remove old demos 2018-09-26 12:00:35 +02:00
Owen BlackerandJimmy Wärting 5db588a568 Amended link to Apple's WebKit bug (#454)
WebKit bug №102914 is no longer the ticket referencing the "iOS can't do this" problem — that ticket has been closed since it was resolved on MacOS.

The appropriate WebKit bug ticket is №167341: [iOS] Add support for the download attribute, so I have updated the link appropriately.
2018-09-20 23:18:25 +02:00
Jimmy WärtingandGitHub 1144ac42bb Add precaution note about file constructor
closes #455
2018-08-07 19:44:51 +02:00
Eli GreyandGitHub 00e540fda5 Merge pull request #450 from ps011/master
Added import statement in syntax section for ease of use
2018-07-17 10:50:43 -07:00
Soni 23d400231f Added import statement in syntax section for ease of use 2018-07-03 14:31:01 +05:30
Eli Grey e865e37af9 Revert #408 2018-03-22 14:09:13 -07:00
Christopher HuntandJimmy Wärting a606064f37 Revert interface change. (#411) 2018-03-22 19:48:05 +01:00
Bryan WainandJimmy Wärting 28a86d90c4 Fix files included with npm (#413)
the files pointed to by main and module are not included in the npm installation
2018-03-22 19:47:45 +01:00
Eli Grey 5914e2a573 Version bump for 1.3.7 2018-03-20 14:30:18 -07:00
16 changed files with 2462 additions and 2621 deletions
-19
View File
@@ -1,19 +0,0 @@
{
"presets": [
["env", {
"targets": {
"browsers": [
"ie > 9"
]
}
}]
],
"plugins": [
"transform-es2015-modules-umd"
],
"env": {
"production": {
"presets": ["minify"]
}
}
}
+3
View File
@@ -0,0 +1,3 @@
# These are supported funding model platforms
github: eligrey
-3
View File
@@ -1,6 +1,3 @@
node_modules/ node_modules/
.DS_Store .DS_Store
.idea/ .idea/
# Generated files
/dist/
+60
View File
@@ -0,0 +1,60 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [2.0.2] - 2019-05-14
- Catching an exception on Send (HEAD) ([#534])
## [2.0.0] - 2018-10-17
- Removed eval to resolve CSP ([#465])
## [2.0.0-rc.4] - 2018-10-17
- Dont throw on module.exports
## [2.0.0-rc.3] - 2018-09-27
- Switch export method
## [2.0.0-rc.2] - 2018-09-26
- Added a changelog.md
- Reverted `a.click()` to use dispatch with a try-catch ([#465], [#382])
- Made third argument to an object where you have to pass `{ autoBom: true }`
- boolean are depricated but still works
## [2.0.0-rc.1] - 2018-09-26
- saveAs don't return anything
- The object that dispatched `writestart progress write writeend` are gone
- detecting such features was never possible and nobody seems to use it.
- Removed the demo folder
- Removed date/version from top of the file
- Dosen't crash in web workers ([#449])
- Support saving urls ([#260] with workarounds for cross origin)
- Uses babel universal module pattern (UMD) to export the package
- Provides source map now as well.
- use a[download] before msSaveAs ([#193], [#294])
- removed dist from .gitignore (npm uses it if it don't find a .npmignore)
- autoBom is now reversed so you have to tell when you want to use autoBom ([#432])
- `a.click()` since there are new and depricated event constructors that works differently ([#382])
- opens up a new popup (tab) directly for the fallback method since the FileReader is async
- removed the explicitly MSIE [1-9] check
- Uses new anchor link for each save (might solve multiple download problems)
[#382]: https://github.com/eligrey/FileSaver.js/issues/382
[#449]: https://github.com/eligrey/FileSaver.js/issues/449
[#260]: https://github.com/eligrey/FileSaver.js/issues/260
[#193]: https://github.com/eligrey/FileSaver.js/issues/193
[#294]: https://github.com/eligrey/FileSaver.js/issues/294
[#432]: https://github.com/eligrey/FileSaver.js/issues/432
[#382]: https://github.com/eligrey/FileSaver.js/issues/382
[#465]: https://github.com/eligrey/FileSaver.js/issues/465
[#469]: https://github.com/eligrey/FileSaver.js/issues/469
[#470]: https://github.com/eligrey/FileSaver.js/issues/470
[#491]: https://github.com/eligrey/FileSaver.js/issues/491
[#534]: https://github.com/eligrey/FileSaver.js/issues/534
+38 -24
View File
@@ -1,31 +1,27 @@
If you need to save really large files bigger then the blob's size limitation or don't have If you need to save really large files bigger than 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) enough RAM, then have a look at the more advanced [StreamSaver.js][7]
that can save data directly to the hard drive asynchronously with the power of the new streams API. That will have 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 support for progress, cancelation and knowing when it's done writing
FileSaver.js FileSaver.js
============ ============
FileSaver.js implements the `saveAs()` FileSaver interface in browsers that do
not natively support it. There is a [FileSaver.js demo][1] that demonstrates saving
various media types.
FileSaver.js is the solution to saving files on the client-side, and is perfect for FileSaver.js is the solution to saving files on the client-side, and is perfect for
webapps that need to generate files, or for saving sensitive information that shouldn't be web apps that generates files on the client, However if the file is coming from the
sent to an external server. server we recommend you to first try to use [Content-Disposition][8] attachment response header as it has more cross-browser compatiblity.
Looking for `canvas.toBlob()` for saving canvases? Check out Looking for `canvas.toBlob()` for saving canvases? Check out
[canvas-toBlob.js][2] for a cross-browser implementation. [canvas-toBlob.js][2] for a cross-browser implementation.
Supported browsers Supported Browsers
------------------ ------------------
| Browser | Constructs as | Filenames | Max Blob Size | Dependencies | | Browser | Constructs as | Filenames | Max Blob Size | Dependencies |
| -------------- | ------------- | ------------ | ------------- | ------------ | | -------------- | ------------- | ------------ | ------------- | ------------ |
| Firefox 20+ | Blob | Yes | 800 MiB | None | | Firefox 20+ | Blob | Yes | 800 MiB | None |
| Firefox < 20 | data: URI | No | n/a | [Blob.js](https://github.com/eligrey/Blob.js) | | Firefox < 20 | data: URI | No | n/a | [Blob.js](https://github.com/eligrey/Blob.js) |
| Chrome | Blob | Yes | [500 MiB][3] | None | | Chrome | Blob | Yes | [2GB][3] | None |
| Chrome for Android | Blob | Yes | [500 MiB][3] | None | | Chrome for Android | Blob | Yes | [RAM/5][3] | None |
| Edge | Blob | Yes | ? | None | | Edge | Blob | Yes | ? | None |
| IE 10+ | Blob | Yes | 600 MiB | None | | IE 10+ | Blob | Yes | 600 MiB | None |
| Opera 15+ | Blob | Yes | 500 MiB | None | | Opera 15+ | Blob | Yes | 500 MiB | None |
@@ -54,21 +50,25 @@ press <kbd>⌘</kbd>+<kbd>S</kbd> to save the file after it is opened. Using the
### iOS ### iOS
saveAs must be run within a user interaction event such as onTouchDown or onClick; setTimeout will prevent saveAs from triggering. Due to restrictions in iOS saveAs opens in a new window instead of downloading, if you want this fixed please [tell Apple](https://bugs.webkit.org/show_bug.cgi?id=102914) how this bug is affecting you. saveAs must be run within a user interaction event such as onTouchDown or onClick; setTimeout will prevent saveAs from triggering. Due to restrictions in iOS saveAs opens in a new window instead of downloading, if you want this fixed please [tell Apple how this WebKit bug is affecting you](https://bugs.webkit.org/show_bug.cgi?id=167341).
Syntax Syntax
------ ------
### Import `saveAs()` from file-saver
```js ```js
FileSaver saveAs(Blob/File data, optional DOMString filename, optional Boolean disableAutoBOM) import { saveAs } from 'file-saver';
``` ```
Pass `true` for `disableAutoBOM` if you don't want FileSaver.js to automatically provide Unicode text encoding hints (see: [byte order mark](https://en.wikipedia.org/wiki/Byte_order_mark)). ```js
FileSaver saveAs(Blob/File/Url, optional DOMString filename, optional Object { autoBom })
```
Pass `{ autoBom: true }` if you want FileSaver.js to automatically provide Unicode text encoding hints (see: [byte order mark](https://en.wikipedia.org/wiki/Byte_order_mark)). Note that this is only done if your blob type has `charset=utf-8` set.
Examples Examples
-------- --------
### Saving text using require ### Saving text using `require()`
```js ```js
var FileSaver = require('file-saver'); var FileSaver = require('file-saver');
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"}); var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
@@ -82,14 +82,22 @@ var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
FileSaver.saveAs(blob, "hello world.txt"); FileSaver.saveAs(blob, "hello world.txt");
``` ```
### Saving URLs
```js
FileSaver.saveAs("https://httpbin.org/image", "image.jpg");
```
Using URLs within the same origin will just use `a[download]`.
Otherwise, it will first check if it supports cors header with a synchronous head request.
If it does, it will download the data and save using blob URLs.
If not, it will try to download it using `a[download]`.
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.
[Blob.js][5] is a cross-browser `Blob` implementation that solves this. [Blob.js][5] is a cross-browser `Blob` implementation that solves this.
### Saving a canvas ### Saving a canvas
```js ```js
var canvas = document.getElementById("my-canvas"), ctx = canvas.getContext("2d"); var canvas = document.getElementById("my-canvas");
// draw to canvas...
canvas.toBlob(function(blob) { canvas.toBlob(function(blob) {
saveAs(blob, "pretty image.png"); saveAs(blob, "pretty image.png");
}); });
@@ -100,12 +108,14 @@ Note: The standard HTML5 `canvas.toBlob()` method is not available in all browse
### 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. If the
File itself already contains a name, There is a hand full of ways to get a file file itself already contains a name, there is a hand full of ways to get a file
instance (from storage, file input, new constructor) instance (from storage, file input, new constructor, clipboard event).
But if you still want to change the name, then you can change it in the 2nd argument If you still want to change the name, then you can change it in the 2nd argument.
```js ```js
// Note: Ie and Edge don't support the new File constructor,
// so it's better to construct blobs and use saveAs(blob, filename)
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"});
FileSaver.saveAs(file); FileSaver.saveAs(file);
``` ```
@@ -116,15 +126,18 @@ FileSaver.saveAs(file);
[1]: http://eligrey.com/demos/FileSaver.js/ [1]: http://eligrey.com/demos/FileSaver.js/
[2]: https://github.com/eligrey/canvas-toBlob.js [2]: https://github.com/eligrey/canvas-toBlob.js
[3]: https://code.google.com/p/chromium/issues/detail?id=375297 [3]: https://bugs.chromium.org/p/chromium/issues/detail?id=375297#c107
[4]: https://developer.mozilla.org/en-US/docs/DOM/Blob [4]: https://developer.mozilla.org/en-US/docs/DOM/Blob
[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
[7]: https://github.com/jimmywarting/StreamSaver.js
[8]: https://github.com/eligrey/FileSaver.js/wiki/Saving-a-remote-file#using-http-header
Installation Installation
------------------ ------------------
```bash ```bash
# Basic Node.JS installation
npm install file-saver --save npm install file-saver --save
bower install file-saver bower install file-saver
``` ```
@@ -132,5 +145,6 @@ bower install file-saver
Additionally, TypeScript definitions can be installed via: Additionally, TypeScript definitions can be installed via:
```bash ```bash
# Additional typescript definitions
npm install @types/file-saver --save-dev npm install @types/file-saver --save-dev
``` ```
+3 -3
View File
@@ -1,7 +1,7 @@
{ {
"name": "file-saver", "name": "file-saver",
"main": "dist/FileSaver.js", "main": "dist/FileSaver.min.js",
"version": "1.3.3", "version": "2.0.0-rc.3",
"homepage": "https://github.com/eligrey/FileSaver.js", "homepage": "https://github.com/eligrey/FileSaver.js",
"authors": [ "authors": [
"Eli Grey <[email protected]>" "Eli Grey <[email protected]>"
@@ -15,7 +15,7 @@
"license": "MIT", "license": "MIT",
"ignore": [ "ignore": [
"*", "*",
"!FileSaver.*js", "!dist/*",
"!LICENSE.md" "!LICENSE.md"
] ]
} }
-50
View File
@@ -1,50 +0,0 @@
html {
background-color: #DDD;
}
body {
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
width: 900px;
margin: 0 auto;
font-family: Verdana, Helvetica, Arial, sans-serif;
-webkit-box-shadow: 0 0 10px 2px rgba(0, 0, 0, .5);
-moz-box-shadow: 0 0 10px 2px rgba(0, 0, 0, .5);
box-shadow: 0 0 10px 2px rgba(0, 0, 0, .5);
padding: 7px 25px 70px;
background-color: #FFF;
}
h1, h2, h3, h4, h5, h6 {
font-family: Georgia, "Times New Roman", serif;
}
h2, form {
text-align: center;
}
form {
margin-top: 5px;
}
.input {
width: 500px;
height: 300px;
margin: 0 auto;
display: block;
}
section {
margin-top: 40px;
}
#canvas {
cursor: crosshair;
}
#canvas, #html {
border: 1px solid #000;
}
.filename {
text-align: right;
}
#html {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
overflow: auto;
padding: 1em;
}
-216
View File
@@ -1,216 +0,0 @@
/*! FileSaver.js demo script
* 2016-05-26
*
* By Eli Grey, http://eligrey.com
* License: MIT
* See LICENSE.md
*/
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/demo/demo.js */
/*jshint laxbreak: true, laxcomma: true, smarttabs: true*/
/*global saveAs, self*/
(function(view) {
"use strict";
// The canvas drawing portion of the demo is based off the demo at
// http://www.williammalone.com/articles/create-html5-canvas-javascript-drawing-app/
var
document = view.document
, $ = function(id) {
return document.getElementById(id);
}
, session = view.sessionStorage
// only get URL when necessary in case Blob.js hasn't defined it yet
, get_blob = function() {
return view.Blob;
}
, canvas = $("canvas")
, canvas_options_form = $("canvas-options")
, canvas_filename = $("canvas-filename")
, canvas_clear_button = $("canvas-clear")
, text = $("text")
, text_options_form = $("text-options")
, text_filename = $("text-filename")
, html = $("html")
, html_options_form = $("html-options")
, html_filename = $("html-filename")
, ctx = canvas.getContext("2d")
, drawing = false
, x_points = session.x_points || []
, y_points = session.y_points || []
, drag_points = session.drag_points || []
, add_point = function(x, y, dragging) {
x_points.push(x);
y_points.push(y);
drag_points.push(dragging);
}
, draw = function(){
canvas.width = canvas.width;
ctx.lineWidth = 6;
ctx.lineJoin = "round";
ctx.strokeStyle = "#000000";
var
i = 0
, len = x_points.length
;
for(; i < len; i++) {
ctx.beginPath();
if (i && drag_points[i]) {
ctx.moveTo(x_points[i-1], y_points[i-1]);
} else {
ctx.moveTo(x_points[i]-1, y_points[i]);
}
ctx.lineTo(x_points[i], y_points[i]);
ctx.closePath();
ctx.stroke();
}
}
, stop_drawing = function() {
drawing = false;
}
// Title guesser and document creator available at https://gist.github.com/1059648
, guess_title = function(doc) {
var
h = "h6 h5 h4 h3 h2 h1".split(" ")
, i = h.length
, headers
, header_text
;
while (i--) {
headers = doc.getElementsByTagName(h[i]);
for (var j = 0, len = headers.length; j < len; j++) {
header_text = headers[j].textContent.trim();
if (header_text) {
return header_text;
}
}
}
}
, doc_impl = document.implementation
, create_html_doc = function(html) {
var
dt = doc_impl.createDocumentType('html', null, null)
, doc = doc_impl.createDocument("http://www.w3.org/1999/xhtml", "html", dt)
, doc_el = doc.documentElement
, head = doc_el.appendChild(doc.createElement("head"))
, charset_meta = head.appendChild(doc.createElement("meta"))
, title = head.appendChild(doc.createElement("title"))
, body = doc_el.appendChild(doc.createElement("body"))
, i = 0
, len = html.childNodes.length
;
charset_meta.setAttribute("charset", html.ownerDocument.characterSet);
for (; i < len; i++) {
body.appendChild(doc.importNode(html.childNodes.item(i), true));
}
var title_text = guess_title(doc);
if (title_text) {
title.appendChild(doc.createTextNode(title_text));
}
return doc;
}
;
canvas.width = 500;
canvas.height = 300;
if (typeof x_points === "string") {
x_points = JSON.parse(x_points);
} if (typeof y_points === "string") {
y_points = JSON.parse(y_points);
} if (typeof drag_points === "string") {
drag_points = JSON.parse(drag_points);
} if (session.canvas_filename) {
canvas_filename.value = session.canvas_filename;
} if (session.text) {
text.value = session.text;
} if (session.text_filename) {
text_filename.value = session.text_filename;
} if (session.html) {
html.innerHTML = session.html;
} if (session.html_filename) {
html_filename.value = session.html_filename;
}
drawing = true;
draw();
drawing = false;
canvas_clear_button.addEventListener("click", function() {
canvas.width = canvas.width;
x_points.length =
y_points.length =
drag_points.length =
0;
}, false);
canvas.addEventListener("mousedown", function(event) {
event.preventDefault();
drawing = true;
add_point(event.pageX - canvas.offsetLeft, event.pageY - canvas.offsetTop, false);
draw();
}, false);
canvas.addEventListener("mousemove", function(event) {
if (drawing) {
add_point(event.pageX - canvas.offsetLeft, event.pageY - canvas.offsetTop, true);
draw();
}
}, false);
canvas.addEventListener("mouseup", stop_drawing, false);
canvas.addEventListener("mouseout", stop_drawing, false);
canvas_options_form.addEventListener("submit", function(event) {
event.preventDefault();
canvas.toBlobHD(function(blob) {
saveAs(
blob
, (canvas_filename.value || canvas_filename.placeholder) + ".png"
);
}, "image/png");
}, false);
text_options_form.addEventListener("submit", function(event) {
event.preventDefault();
var BB = get_blob();
saveAs(
new BB(
[text.value || text.placeholder]
, {type: "text/plain;charset=" + document.characterSet}
)
, (text_filename.value || text_filename.placeholder) + ".txt"
);
}, false);
html_options_form.addEventListener("submit", function(event) {
event.preventDefault();
var
BB = get_blob()
, xml_serializer = new XMLSerializer()
, doc = create_html_doc(html)
;
saveAs(
new BB(
[xml_serializer.serializeToString(doc)]
, {type: "text/plain;charset=" + document.characterSet}
)
, (html_filename.value || html_filename.placeholder) + ".xhtml"
);
}, false);
view.addEventListener("unload", function() {
session.x_points = JSON.stringify(x_points);
session.y_points = JSON.stringify(y_points);
session.drag_points = JSON.stringify(drag_points);
session.canvas_filename = canvas_filename.value;
session.text = text.value;
session.text_filename = text_filename.value;
session.html = html.innerHTML;
session.html_filename = html_filename.value;
}, false);
}(self));
-2
View File
@@ -1,2 +0,0 @@
/*! @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:"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));
-57
View File
@@ -1,57 +0,0 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US-x-Hixie">
<head>
<meta charset="utf-8"/>
<title>FileSaver.js demo</title>
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/eligrey/FileSaver.js/702cd2e820b680f88a0f299e33085c196806fc52/demo/demo.css"/>
</head>
<body>
<h1><a href="https://github.com/eligrey/FileSaver.js">FileSaver.js</a> demo</h1>
<p>
The following examples demonstrate how it is possible to generate and save any type of data right in the browser using the <code>saveAs()</code> FileSaver interface, without contacting any servers.
</p>
<section id="image-demo">
<h2>Saving an image</h2>
<canvas class="input" id="canvas" width="500" height="300"/>
<form id="canvas-options">
<label>Filename: <input type="text" class="filename" id="canvas-filename" placeholder="doodle"/>.png</label>
<input type="submit" value="Save"/>
<input type="button" id="canvas-clear" value="Clear"/>
</form>
</section>
<section id="text-demo">
<h2>Saving text</h2>
<textarea class="input" id="text" placeholder="Once upon a time..."/>
<form id="text-options">
<label>Filename: <input type="text" class="filename" id="text-filename" placeholder="a plain document"/>.txt</label>
<input type="submit" value="Save"/>
</form>
</section>
<section id="html-demo">
<h2>Saving rich text</h2>
<div class="input" id="html" contenteditable="">
<h3>Some example rich text</h3>
<ul>
<li><del>Plain</del> <ins>Boring</ins> text.</li>
<li><em>Emphasized text!</em></li>
<li><strong>Strong text!</strong></li>
<li>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="70" height="70">
<circle cx="35" cy="35" r="35" fill="red"/>
<text x="10" y="40">image</text>
</svg>
</li>
<li><a href="https://github.com/eligrey/FileSaver.js">A link.</a></li>
</ul>
</div>
<form id="html-options">
<label>Filename: <input type="text" class="filename" id="html-filename" placeholder="a rich document"/>.xhtml</label>
<input type="submit" value="Save"/>
</form>
</section>
<script async="" src="https://cdn.rawgit.com/eligrey/Blob.js/0cef2746414269b16834878a8abc52eb9d53e6bd/Blob.js"/>
<script async="" src="https://cdn.rawgit.com/eligrey/canvas-toBlob.js/f1a01896135ab378aa5c0118eadd81da55e698d8/canvas-toBlob.js"/>
<script async="" src="https://cdn.rawgit.com/eligrey/FileSaver.js/e9d941381475b5df8b7d7691013401e171014e89/FileSaver.min.js"/>
<script async="" src="https://cdn.rawgit.com/eligrey/FileSaver.js/597b6cd0207ce408a6d34890b5b2826b13450714/demo/demo.js"/>
</body>
</html>
+186
View File
@@ -0,0 +1,186 @@
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define([], factory);
} else if (typeof exports !== "undefined") {
factory();
} else {
var mod = {
exports: {}
};
factory();
global.FileSaver = mod.exports;
}
})(this, function () {
"use strict";
/*
* FileSaver.js
* A saveAs() FileSaver implementation.
*
* By Eli Grey, http://eligrey.com
*
* License : https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md (MIT)
* source : http://purl.eligrey.com/github/FileSaver.js
*/
// The one and only way of getting global scope in all environments
// https://stackoverflow.com/q/3277182/1008999
var _global = typeof window === 'object' && window.window === window ? window : typeof self === 'object' && self.self === self ? self : typeof global === 'object' && global.global === global ? global : void 0;
function bom(blob, opts) {
if (typeof opts === 'undefined') opts = {
autoBom: false
};else if (typeof opts !== 'object') {
console.warn('Deprecated: Expected third argument to be a object');
opts = {
autoBom: !opts
};
} // prepend BOM for UTF-8 XML and text/* types (including HTML)
// note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
if (opts.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
return new Blob([String.fromCharCode(0xFEFF), blob], {
type: blob.type
});
}
return blob;
}
function download(url, name, opts) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.onload = function () {
saveAs(xhr.response, name, opts);
};
xhr.onerror = function () {
console.error('could not download file');
};
xhr.send();
}
function corsEnabled(url) {
var xhr = new XMLHttpRequest(); // use sync to avoid popup blocker
xhr.open('HEAD', url, false);
try {
xhr.send();
} catch (e) {}
return xhr.status >= 200 && xhr.status <= 299;
} // `a.click()` doesn't work for all browsers (#465)
function click(node) {
try {
node.dispatchEvent(new MouseEvent('click'));
} catch (e) {
var evt = document.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
node.dispatchEvent(evt);
}
} // Detect WebKit inside a native macOS app
var isWebKit = /AppleWebKit/.test(navigator.userAgent);
var saveAs = _global.saveAs || ( // probably in some web worker
typeof window !== 'object' || window !== _global ? function saveAs() {}
/* noop */
// Use download attribute first if possible (#193 Lumia mobile) unless this is a native macOS app
: 'download' in HTMLAnchorElement.prototype && !isWebKit ? function saveAs(blob, name, opts) {
var URL = _global.URL || _global.webkitURL;
var a = document.createElement('a');
name = name || blob.name || 'download';
a.download = name;
a.rel = 'noopener'; // tabnabbing
// TODO: detect chrome extensions & packaged apps
// a.target = '_blank'
if (typeof blob === 'string') {
// Support regular links
a.href = blob;
if (a.origin !== location.origin) {
corsEnabled(a.href) ? download(blob, name, opts) : click(a, a.target = '_blank');
} else {
click(a);
}
} else {
// Support blobs
a.href = URL.createObjectURL(blob);
setTimeout(function () {
URL.revokeObjectURL(a.href);
}, 4E4); // 40s
setTimeout(function () {
click(a);
}, 0);
}
} // Use msSaveOrOpenBlob as a second approach
: 'msSaveOrOpenBlob' in navigator ? function saveAs(blob, name, opts) {
name = name || blob.name || 'download';
if (typeof blob === 'string') {
if (corsEnabled(blob)) {
download(blob, name, opts);
} else {
var a = document.createElement('a');
a.href = blob;
a.target = '_blank';
setTimeout(function () {
click(a);
});
}
} else {
navigator.msSaveOrOpenBlob(bom(blob, opts), name);
}
} // Fallback to using FileReader and a popup
: function saveAs(blob, name, opts, popup) {
// Open a popup immediately do go around popup blocker
// Mostly only available on user interaction and the fileReader is async so...
popup = popup || open('', '_blank');
if (popup) {
popup.document.title = popup.document.body.innerText = 'downloading...';
}
if (typeof blob === 'string') return download(blob, name, opts);
var force = blob.type === 'application/octet-stream';
var isSafari = /constructor/i.test(_global.HTMLElement) || _global.safari;
var isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent);
if ((isChromeIOS || force && isSafari || isWebKit) && typeof FileReader !== 'undefined') {
// Safari doesn't allow downloading of blob URLs
var reader = new FileReader();
reader.onloadend = function () {
var url = reader.result;
url = isChromeIOS ? url : url.replace(/^data:[^;]*;/, 'data:attachment/file;');
if (popup) popup.location.href = url;else location = url;
popup = null; // reverse-tabnabbing #460
};
reader.readAsDataURL(blob);
} else {
var URL = _global.URL || _global.webkitURL;
var url = URL.createObjectURL(blob);
if (popup) popup.location = url;else location.href = url;
popup = null; // reverse-tabnabbing #460
setTimeout(function () {
URL.revokeObjectURL(url);
}, 4E4); // 40s
}
});
_global.saveAs = saveAs.saveAs = saveAs;
if (typeof module !== 'undefined') {
module.exports = saveAs;
}
});
+3
View File
@@ -0,0 +1,3 @@
(function(a,b){if("function"==typeof define&&define.amd)define([],b);else if("undefined"!=typeof exports)b();else{b(),a.FileSaver={exports:{}}.exports}})(this,function(){"use strict";function b(a,b){return"undefined"==typeof b?b={autoBom:!1}:"object"!=typeof b&&(console.warn("Deprecated: Expected third argument to be a object"),b={autoBom:!b}),b.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(a.type)?new Blob(["\uFEFF",a],{type:a.type}):a}function c(a,b,c){var d=new XMLHttpRequest;d.open("GET",a),d.responseType="blob",d.onload=function(){g(d.response,b,c)},d.onerror=function(){console.error("could not download file")},d.send()}function d(a){var b=new XMLHttpRequest;b.open("HEAD",a,!1);try{b.send()}catch(a){}return 200<=b.status&&299>=b.status}function e(a){try{a.dispatchEvent(new MouseEvent("click"))}catch(c){var b=document.createEvent("MouseEvents");b.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),a.dispatchEvent(b)}}var f="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof global&&global.global===global?global:void 0,a=/AppleWebKit/.test(navigator.userAgent),g=f.saveAs||("object"!=typeof window||window!==f?function(){}:"download"in HTMLAnchorElement.prototype&&!a?function(b,g,h){var i=f.URL||f.webkitURL,j=document.createElement("a");g=g||b.name||"download",j.download=g,j.rel="noopener","string"==typeof b?(j.href=b,j.origin===location.origin?e(j):d(j.href)?c(b,g,h):e(j,j.target="_blank")):(j.href=i.createObjectURL(b),setTimeout(function(){i.revokeObjectURL(j.href)},4E4),setTimeout(function(){e(j)},0))}:"msSaveOrOpenBlob"in navigator?function(f,g,h){if(g=g||f.name||"download","string"!=typeof f)navigator.msSaveOrOpenBlob(b(f,h),g);else if(d(f))c(f,g,h);else{var i=document.createElement("a");i.href=f,i.target="_blank",setTimeout(function(){e(i)})}}:function(b,d,e,g){if(g=g||open("","_blank"),g&&(g.document.title=g.document.body.innerText="downloading..."),"string"==typeof b)return c(b,d,e);var h="application/octet-stream"===b.type,i=/constructor/i.test(f.HTMLElement)||f.safari,j=/CriOS\/[\d]+/.test(navigator.userAgent);if((j||h&&i||a)&&"undefined"!=typeof FileReader){var k=new FileReader;k.onloadend=function(){var a=k.result;a=j?a:a.replace(/^data:[^;]*;/,"data:attachment/file;"),g?g.location.href=a:location=a,g=null},k.readAsDataURL(b)}else{var l=f.URL||f.webkitURL,m=l.createObjectURL(b);g?g.location=m:location.href=m,g=null,setTimeout(function(){l.revokeObjectURL(m)},4E4)}});f.saveAs=g.saveAs=g,"undefined"!=typeof module&&(module.exports=g)});
//# sourceMappingURL=FileSaver.min.js.map
+1
View File
File diff suppressed because one or more lines are too long
+1998 -2067
View File
File diff suppressed because it is too large Load Diff
+12 -10
View File
@@ -1,16 +1,18 @@
{ {
"name": "file-saver", "name": "file-saver",
"version": "1.3.4", "version": "2.0.3",
"description": "An HTML5 saveAs() FileSaver implementation", "description": "An HTML5 saveAs() FileSaver implementation",
"main": "dist/FileSaver.js", "main": "dist/FileSaver.min.js",
"module": "src/FileSaver.js",
"files": [ "files": [
"dist/FileSaver.min.js" "dist/FileSaver.js",
"dist/FileSaver.min.js",
"dist/FileSaver.min.js.map",
"src/FileSaver.js"
], ],
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 0", "test": "echo \"Error: no test specified\" && exit 0",
"build:development": "mkdir -p dist && babel src/FileSaver.js --out-file=dist/FileSaver.js", "build:development": "babel -o dist/FileSaver.js --plugins @babel/plugin-transform-modules-umd src/FileSaver.js",
"build:production": "NODE_ENV=production npm run build:development -- --out-file=dist/FileSaver.min.js", "build:production": "babel -o dist/FileSaver.min.js -s --plugins @babel/plugin-transform-modules-umd --presets minify src/FileSaver.js",
"build": "npm run build:development && npm run build:production", "build": "npm run build:development && npm run build:production",
"prepublishOnly": "npm run build" "prepublishOnly": "npm run build"
}, },
@@ -30,9 +32,9 @@
}, },
"homepage": "https://github.com/eligrey/FileSaver.js#readme", "homepage": "https://github.com/eligrey/FileSaver.js#readme",
"devDependencies": { "devDependencies": {
"babel-cli": "^6.26.0", "@babel/cli": "^7.1.0",
"babel-plugin-transform-es2015-modules-umd": "^6.24.1", "@babel/core": "^7.1.0",
"babel-preset-env": "^1.6.1", "@babel/plugin-transform-modules-umd": "^7.1.0",
"babel-preset-minify": "^0.2.0" "babel-preset-minify": "^0.4.3"
} }
} }
+158 -170
View File
@@ -1,181 +1,169 @@
/* FileSaver.js /*
* A saveAs() FileSaver implementation. * FileSaver.js
* 1.3.6 * A saveAs() FileSaver implementation.
* 2018-03-16 14:39:40 *
* * By Eli Grey, http://eligrey.com
* By Eli Grey, https://eligrey.com *
* License: MIT * License : https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md (MIT)
* See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md * source : http://purl.eligrey.com/github/FileSaver.js
*/ */
/*global self */ // The one and only way of getting global scope in all environments
/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */ // https://stackoverflow.com/q/3277182/1008999
var _global = typeof window === 'object' && window.window === window
? window : typeof self === 'object' && self.self === self
? self : typeof global === 'object' && global.global === global
? global
: this
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/src/FileSaver.js */ function bom (blob, opts) {
if (typeof opts === 'undefined') opts = { autoBom: false }
else if (typeof opts !== 'object') {
console.warn('Deprecated: Expected third argument to be a object')
opts = { autoBom: !opts }
}
export default var saveAs = saveAs || (function(view) { // prepend BOM for UTF-8 XML and text/* types (including HTML)
"use strict"; // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
// IE <10 is explicitly unsupported if (opts.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
if (typeof view === "undefined" || typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) { return new Blob([String.fromCharCode(0xFEFF), blob], { type: blob.type })
return; }
} return blob
var }
doc = view.document
// only get URL when necessary in case Blob.js hasn't overridden it yet
, get_URL = function() {
return view.URL || view.webkitURL || view;
}
, save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
, can_use_save_link = "download" in save_link
, click = function(node) {
var event = new MouseEvent("click");
node.dispatchEvent(event);
}
, 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) {
setImmediate(function() {
throw ex;
}, 0);
}
, force_saveable_type = "application/octet-stream"
// the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to
, arbitrary_revoke_timeout = 1000 * 40 // in ms
, revoke = function(file) {
var revoker = function() {
if (typeof file === "string") { // file is an object URL
get_URL().revokeObjectURL(file);
} else { // file is a File
file.remove();
}
};
setTimeout(revoker, arbitrary_revoke_timeout);
}
, dispatch = function(filesaver, event_types, event) {
event_types = [].concat(event_types);
var i = event_types.length;
while (i--) {
var listener = filesaver["on" + event_types[i]];
if (typeof listener === "function") {
try {
listener.call(filesaver, event || filesaver);
} catch (ex) {
throw_outside(ex);
}
}
}
}
, auto_bom = function(blob) {
// prepend BOM for UTF-8 XML and text/* types (including HTML)
// note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
return new Blob([String.fromCharCode(0xFEFF), blob], {type: blob.type});
}
return blob;
}
, FileSaver = function(blob, name, no_auto_bom) {
if (!no_auto_bom) {
blob = auto_bom(blob);
}
// First try a.download, then web filesystem, then object URLs
var
filesaver = this
, type = blob.type
, force = type === force_saveable_type
, object_url
, dispatch_all = function() {
dispatch(filesaver, "writestart progress write writeend".split(" "));
}
// on any filesys errors revert to saving with object URLs
, fs_error = function() {
if ((is_chrome_ios || (force && is_safari)) && view.FileReader) {
// Safari doesn't allow downloading of blob urls
var reader = new FileReader();
reader.onloadend = function() {
var url = is_chrome_ios ? reader.result : reader.result.replace(/^data:[^;]*;/, 'data:attachment/file;');
var popup = view.open(url, '_blank');
if(!popup) view.location.href = url;
url=undefined; // release reference before dispatching
filesaver.readyState = filesaver.DONE;
dispatch_all();
};
reader.readAsDataURL(blob);
filesaver.readyState = filesaver.INIT;
return;
}
// don't create more object URLs than needed
if (!object_url) {
object_url = get_URL().createObjectURL(blob);
}
if (force) {
view.location.href = object_url;
} else {
var opened = view.open(object_url, "_blank");
if (!opened) {
// Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html
view.location.href = object_url;
}
}
filesaver.readyState = filesaver.DONE;
dispatch_all();
revoke(object_url);
}
;
filesaver.readyState = filesaver.INIT;
if (can_use_save_link) { function download (url, name, opts) {
object_url = get_URL().createObjectURL(blob); var xhr = new XMLHttpRequest()
setImmediate(function() { xhr.open('GET', url)
save_link.href = object_url; xhr.responseType = 'blob'
save_link.download = name; xhr.onload = function () {
click(save_link); saveAs(xhr.response, name, opts)
dispatch_all(); }
revoke(object_url); xhr.onerror = function () {
filesaver.readyState = filesaver.DONE; console.error('could not download file')
}, 0); }
return; xhr.send()
} }
fs_error(); function corsEnabled (url) {
} var xhr = new XMLHttpRequest()
, FS_proto = FileSaver.prototype // use sync to avoid popup blocker
, saveAs = function(blob, name, no_auto_bom) { xhr.open('HEAD', url, false)
return new FileSaver(blob, name || blob.name || "download", no_auto_bom); try {
} xhr.send()
; } catch (e) {}
return xhr.status >= 200 && xhr.status <= 299
}
// IE 10+ (native saveAs) // `a.click()` doesn't work for all browsers (#465)
if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) { function click (node) {
return function(blob, name, no_auto_bom) { try {
name = name || blob.name || "download"; node.dispatchEvent(new MouseEvent('click'))
} catch (e) {
var evt = document.createEvent('MouseEvents')
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80,
20, false, false, false, false, 0, null)
node.dispatchEvent(evt)
}
}
if (!no_auto_bom) { // Detect WebKit inside a native macOS app
blob = auto_bom(blob); var isWebKit = /AppleWebKit/.test(navigator.userAgent)
}
return navigator.msSaveOrOpenBlob(blob, name);
};
}
save_link.target = "_blank"; var saveAs = _global.saveAs || (
// probably in some web worker
(typeof window !== 'object' || window !== _global)
? function saveAs () { /* noop */ }
FS_proto.abort = function(){}; // Use download attribute first if possible (#193 Lumia mobile) unless this is a native macOS app
FS_proto.readyState = FS_proto.INIT = 0; : ('download' in HTMLAnchorElement.prototype && !isWebKit)
FS_proto.WRITING = 1; ? function saveAs (blob, name, opts) {
FS_proto.DONE = 2; var URL = _global.URL || _global.webkitURL
var a = document.createElement('a')
name = name || blob.name || 'download'
FS_proto.error = a.download = name
FS_proto.onwritestart = a.rel = 'noopener' // tabnabbing
FS_proto.onprogress =
FS_proto.onwrite =
FS_proto.onabort =
FS_proto.onerror =
FS_proto.onwriteend =
null;
return saveAs; // TODO: detect chrome extensions & packaged apps
}( // a.target = '_blank'
typeof self !== "undefined" && self
|| typeof window !== "undefined" && window if (typeof blob === 'string') {
|| this // Support regular links
)); a.href = blob
if (a.origin !== location.origin) {
corsEnabled(a.href)
? download(blob, name, opts)
: click(a, a.target = '_blank')
} else {
click(a)
}
} else {
// Support blobs
a.href = URL.createObjectURL(blob)
setTimeout(function () { URL.revokeObjectURL(a.href) }, 4E4) // 40s
setTimeout(function () { click(a) }, 0)
}
}
// Use msSaveOrOpenBlob as a second approach
: 'msSaveOrOpenBlob' in navigator
? function saveAs (blob, name, opts) {
name = name || blob.name || 'download'
if (typeof blob === 'string') {
if (corsEnabled(blob)) {
download(blob, name, opts)
} else {
var a = document.createElement('a')
a.href = blob
a.target = '_blank'
setTimeout(function () { click(a) })
}
} else {
navigator.msSaveOrOpenBlob(bom(blob, opts), name)
}
}
// Fallback to using FileReader and a popup
: function saveAs (blob, name, opts, popup) {
// Open a popup immediately do go around popup blocker
// Mostly only available on user interaction and the fileReader is async so...
popup = popup || open('', '_blank')
if (popup) {
popup.document.title =
popup.document.body.innerText = 'downloading...'
}
if (typeof blob === 'string') return download(blob, name, opts)
var force = blob.type === 'application/octet-stream'
var isSafari = /constructor/i.test(_global.HTMLElement) || _global.safari
var isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent)
if ((isChromeIOS || (force && isSafari) || isWebKit) && typeof FileReader !== 'undefined') {
// Safari doesn't allow downloading of blob URLs
var reader = new FileReader()
reader.onloadend = function () {
var url = reader.result
url = isChromeIOS ? url : url.replace(/^data:[^;]*;/, 'data:attachment/file;')
if (popup) popup.location.href = url
else location = url
popup = null // reverse-tabnabbing #460
}
reader.readAsDataURL(blob)
} else {
var URL = _global.URL || _global.webkitURL
var url = URL.createObjectURL(blob)
if (popup) popup.location = url
else location.href = url
popup = null // reverse-tabnabbing #460
setTimeout(function () { URL.revokeObjectURL(url) }, 4E4) // 40s
}
}
)
_global.saveAs = saveAs.saveAs = saveAs
if (typeof module !== 'undefined') {
module.exports = saveAs;
}