Showing
21 changed files
with
750 additions
and
37 deletions
.DS_Store
0 → 100644
No preview for this file type
1 | +# Changelog | ||
2 | +All notable changes to this project will be documented in this file. | ||
3 | + | ||
4 | +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
5 | +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
6 | + | ||
7 | +## [2.0.2] - 2019-05-14 | ||
8 | + | ||
9 | +- Catching an exception on Send (HEAD) ([#534]) | ||
10 | + | ||
11 | +## [2.0.0] - 2018-10-17 | ||
12 | + | ||
13 | +- Removed eval to resolve CSP ([#465]) | ||
14 | + | ||
15 | +## [2.0.0-rc.4] - 2018-10-17 | ||
16 | + | ||
17 | +- Don’t throw on module.exports | ||
18 | + | ||
19 | +## [2.0.0-rc.3] - 2018-09-27 | ||
20 | + | ||
21 | +- Switch export method | ||
22 | + | ||
23 | +## [2.0.0-rc.2] - 2018-09-26 | ||
24 | + | ||
25 | +- Added a changelog.md | ||
26 | +- Reverted `a.click()` to use dispatch with a try-catch ([#465], [#382]) | ||
27 | +- Made third argument to an object where you have to pass `{ autoBom: true }` | ||
28 | + - boolean are depricated but still works | ||
29 | + | ||
30 | +## [2.0.0-rc.1] - 2018-09-26 | ||
31 | + | ||
32 | +- saveAs don't return anything | ||
33 | + - The object that dispatched `writestart progress write writeend` are gone | ||
34 | + - detecting such features was never possible and nobody seems to use it. | ||
35 | +- Removed the demo folder | ||
36 | +- Removed date/version from top of the file | ||
37 | +- Dosen't crash in web workers ([#449]) | ||
38 | +- Support saving urls ([#260] with workarounds for cross origin) | ||
39 | +- Uses babel universal module pattern (UMD) to export the package | ||
40 | +- Provides source map now as well. | ||
41 | +- use a[download] before msSaveAs ([#193], [#294]) | ||
42 | +- removed dist from .gitignore (npm uses it if it don't find a .npmignore) | ||
43 | +- autoBom is now reversed so you have to tell when you want to use autoBom ([#432]) | ||
44 | +- `a.click()` since there are new and depricated event constructors that works differently ([#382]) | ||
45 | +- opens up a new popup (tab) directly for the fallback method since the FileReader is async | ||
46 | +- removed the explicitly MSIE [1-9] check | ||
47 | +- Uses new anchor link for each save (might solve multiple download problems) | ||
48 | + | ||
49 | + [#382]: https://github.com/eligrey/FileSaver.js/issues/382 | ||
50 | + [#449]: https://github.com/eligrey/FileSaver.js/issues/449 | ||
51 | + [#260]: https://github.com/eligrey/FileSaver.js/issues/260 | ||
52 | + [#193]: https://github.com/eligrey/FileSaver.js/issues/193 | ||
53 | + [#294]: https://github.com/eligrey/FileSaver.js/issues/294 | ||
54 | + [#432]: https://github.com/eligrey/FileSaver.js/issues/432 | ||
55 | + [#382]: https://github.com/eligrey/FileSaver.js/issues/382 | ||
56 | + [#465]: https://github.com/eligrey/FileSaver.js/issues/465 | ||
57 | + [#469]: https://github.com/eligrey/FileSaver.js/issues/469 | ||
58 | + [#470]: https://github.com/eligrey/FileSaver.js/issues/470 | ||
59 | + [#491]: https://github.com/eligrey/FileSaver.js/issues/491 | ||
60 | + [#534]: https://github.com/eligrey/FileSaver.js/issues/534 |
1 | +The MIT License | ||
2 | + | ||
3 | +Copyright © 2016 [Eli Grey][1]. | ||
4 | + | ||
5 | +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: | ||
6 | + | ||
7 | +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
8 | + | ||
9 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
10 | + | ||
11 | + [1]: http://eligrey.com |
1 | +If you need to save really large files bigger then the blob's size limitation or don't have | ||
2 | +enough RAM, then have a look at the more advanced [StreamSaver.js][7] | ||
3 | +that can save data directly to the hard drive asynchronously with the power of the new streams API. That will have | ||
4 | +support for progress, cancelation and knowing when it's done writing | ||
5 | + | ||
6 | +FileSaver.js | ||
7 | +============ | ||
8 | + | ||
9 | +FileSaver.js is the solution to saving files on the client-side, and is perfect for | ||
10 | +web apps that generates files on the client, However if the file is coming from the | ||
11 | +server we recommend you to first try to use [Content-Disposition][8] attachment response header as it has more cross-browser compatiblity. | ||
12 | + | ||
13 | +Looking for `canvas.toBlob()` for saving canvases? Check out | ||
14 | +[canvas-toBlob.js][2] for a cross-browser implementation. | ||
15 | + | ||
16 | +Supported Browsers | ||
17 | +------------------ | ||
18 | + | ||
19 | +| Browser | Constructs as | Filenames | Max Blob Size | Dependencies | | ||
20 | +| -------------- | ------------- | ------------ | ------------- | ------------ | | ||
21 | +| Firefox 20+ | Blob | Yes | 800 MiB | None | | ||
22 | +| Firefox < 20 | data: URI | No | n/a | [Blob.js](https://github.com/eligrey/Blob.js) | | ||
23 | +| Chrome | Blob | Yes | [2GB][3] | None | | ||
24 | +| Chrome for Android | Blob | Yes | [RAM/5][3] | None | | ||
25 | +| Edge | Blob | Yes | ? | None | | ||
26 | +| IE 10+ | Blob | Yes | 600 MiB | None | | ||
27 | +| Opera 15+ | Blob | Yes | 500 MiB | None | | ||
28 | +| Opera < 15 | data: URI | No | n/a | [Blob.js](https://github.com/eligrey/Blob.js) | | ||
29 | +| Safari 6.1+* | Blob | No | ? | None | | ||
30 | +| Safari < 6 | data: URI | No | n/a | [Blob.js](https://github.com/eligrey/Blob.js) | | ||
31 | +| Safari 10.1+ | Blob | Yes | n/a | None | | ||
32 | + | ||
33 | +Feature detection is possible: | ||
34 | + | ||
35 | +```js | ||
36 | +try { | ||
37 | + var isFileSaverSupported = !!new Blob; | ||
38 | +} catch (e) {} | ||
39 | +``` | ||
40 | + | ||
41 | +### IE < 10 | ||
42 | + | ||
43 | +It is possible to save text files in IE < 10 without Flash-based polyfills. | ||
44 | +See [ChenWenBrian and koffsyrup's `saveTextAs()`](https://github.com/koffsyrup/FileSaver.js#examples) for more details. | ||
45 | + | ||
46 | +### Safari 6.1+ | ||
47 | + | ||
48 | +Blobs may be opened instead of saved sometimes—you may have to direct your Safari users to manually | ||
49 | +press <kbd>⌘</kbd>+<kbd>S</kbd> to save the file after it is opened. Using the `application/octet-stream` MIME type to force downloads [can cause issues in Safari](https://github.com/eligrey/FileSaver.js/issues/12#issuecomment-47247096). | ||
50 | + | ||
51 | +### iOS | ||
52 | + | ||
53 | +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). | ||
54 | + | ||
55 | +Syntax | ||
56 | +------ | ||
57 | +### Import `saveAs()` from file-saver | ||
58 | +```js | ||
59 | +import { saveAs } from 'file-saver'; | ||
60 | +``` | ||
61 | + | ||
62 | +```js | ||
63 | +FileSaver saveAs(Blob/File/Url, optional DOMString filename, optional Object { autoBom }) | ||
64 | +``` | ||
65 | + | ||
66 | +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. | ||
67 | + | ||
68 | +Examples | ||
69 | +-------- | ||
70 | + | ||
71 | +### Saving text using `require()` | ||
72 | +```js | ||
73 | +var FileSaver = require('file-saver'); | ||
74 | +var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"}); | ||
75 | +FileSaver.saveAs(blob, "hello world.txt"); | ||
76 | +``` | ||
77 | + | ||
78 | +### Saving text | ||
79 | + | ||
80 | +```js | ||
81 | +var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"}); | ||
82 | +FileSaver.saveAs(blob, "hello world.txt"); | ||
83 | +``` | ||
84 | + | ||
85 | +### Saving URLs | ||
86 | + | ||
87 | +```js | ||
88 | +FileSaver.saveAs("https://httpbin.org/image", "image.jpg"); | ||
89 | +``` | ||
90 | +Using URLs within the same origin will just use `a[download]`. | ||
91 | +Otherwise, it will first check if it supports cors header with a synchronous head request. | ||
92 | +If it does, it will download the data and save using blob URLs. | ||
93 | +If not, it will try to download it using `a[download]`. | ||
94 | + | ||
95 | +The standard W3C File API [`Blob`][4] interface is not available in all browsers. | ||
96 | +[Blob.js][5] is a cross-browser `Blob` implementation that solves this. | ||
97 | + | ||
98 | +### Saving a canvas | ||
99 | +```js | ||
100 | +var canvas = document.getElementById("my-canvas"); | ||
101 | +canvas.toBlob(function(blob) { | ||
102 | + saveAs(blob, "pretty image.png"); | ||
103 | +}); | ||
104 | +``` | ||
105 | + | ||
106 | +Note: The standard HTML5 `canvas.toBlob()` method is not available in all browsers. | ||
107 | +[canvas-toBlob.js][6] is a cross-browser `canvas.toBlob()` that polyfills this. | ||
108 | + | ||
109 | +### Saving File | ||
110 | + | ||
111 | +You can save a File constructor without specifying a filename. If the | ||
112 | +file itself already contains a name, there is a hand full of ways to get a file | ||
113 | +instance (from storage, file input, new constructor, clipboard event). | ||
114 | +If you still want to change the name, then you can change it in the 2nd argument. | ||
115 | + | ||
116 | +```js | ||
117 | +// Note: Ie and Edge don't support the new File constructor, | ||
118 | +// so it's better to construct blobs and use saveAs(blob, filename) | ||
119 | +var file = new File(["Hello, world!"], "hello world.txt", {type: "text/plain;charset=utf-8"}); | ||
120 | +FileSaver.saveAs(file); | ||
121 | +``` | ||
122 | + | ||
123 | + | ||
124 | + | ||
125 | +![Tracking image](https://in.getclicky.com/212712ns.gif) | ||
126 | + | ||
127 | + [1]: http://eligrey.com/demos/FileSaver.js/ | ||
128 | + [2]: https://github.com/eligrey/canvas-toBlob.js | ||
129 | + [3]: https://bugs.chromium.org/p/chromium/issues/detail?id=375297#c107 | ||
130 | + [4]: https://developer.mozilla.org/en-US/docs/DOM/Blob | ||
131 | + [5]: https://github.com/eligrey/Blob.js | ||
132 | + [6]: https://github.com/eligrey/canvas-toBlob.js | ||
133 | + [7]: https://github.com/jimmywarting/StreamSaver.js | ||
134 | + [8]: https://github.com/eligrey/FileSaver.js/wiki/Saving-a-remote-file#using-http-header | ||
135 | + | ||
136 | +Installation | ||
137 | +------------------ | ||
138 | + | ||
139 | +```bash | ||
140 | +# Basic Node.JS installation | ||
141 | +npm install file-saver --save | ||
142 | +bower install file-saver | ||
143 | +``` | ||
144 | + | ||
145 | +Additionally, TypeScript definitions can be installed via: | ||
146 | + | ||
147 | +```bash | ||
148 | +# Additional typescript definitions | ||
149 | +npm install @types/file-saver --save-dev | ||
150 | +``` |
1 | +(function (global, factory) { | ||
2 | + if (typeof define === "function" && define.amd) { | ||
3 | + define([], factory); | ||
4 | + } else if (typeof exports !== "undefined") { | ||
5 | + factory(); | ||
6 | + } else { | ||
7 | + var mod = { | ||
8 | + exports: {} | ||
9 | + }; | ||
10 | + factory(); | ||
11 | + global.FileSaver = mod.exports; | ||
12 | + } | ||
13 | +})(this, function () { | ||
14 | + "use strict"; | ||
15 | + | ||
16 | + /* | ||
17 | + * FileSaver.js | ||
18 | + * A saveAs() FileSaver implementation. | ||
19 | + * | ||
20 | + * By Eli Grey, http://eligrey.com | ||
21 | + * | ||
22 | + * License : https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md (MIT) | ||
23 | + * source : http://purl.eligrey.com/github/FileSaver.js | ||
24 | + */ | ||
25 | + // The one and only way of getting global scope in all environments | ||
26 | + // https://stackoverflow.com/q/3277182/1008999 | ||
27 | + 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; | ||
28 | + | ||
29 | + function bom(blob, opts) { | ||
30 | + if (typeof opts === 'undefined') opts = { | ||
31 | + autoBom: false | ||
32 | + };else if (typeof opts !== 'object') { | ||
33 | + console.warn('Deprecated: Expected third argument to be a object'); | ||
34 | + opts = { | ||
35 | + autoBom: !opts | ||
36 | + }; | ||
37 | + } // prepend BOM for UTF-8 XML and text/* types (including HTML) | ||
38 | + // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF | ||
39 | + | ||
40 | + if (opts.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) { | ||
41 | + return new Blob([String.fromCharCode(0xFEFF), blob], { | ||
42 | + type: blob.type | ||
43 | + }); | ||
44 | + } | ||
45 | + | ||
46 | + return blob; | ||
47 | + } | ||
48 | + | ||
49 | + function download(url, name, opts) { | ||
50 | + var xhr = new XMLHttpRequest(); | ||
51 | + xhr.open('GET', url); | ||
52 | + xhr.responseType = 'blob'; | ||
53 | + | ||
54 | + xhr.onload = function () { | ||
55 | + saveAs(xhr.response, name, opts); | ||
56 | + }; | ||
57 | + | ||
58 | + xhr.onerror = function () { | ||
59 | + console.error('could not download file'); | ||
60 | + }; | ||
61 | + | ||
62 | + xhr.send(); | ||
63 | + } | ||
64 | + | ||
65 | + function corsEnabled(url) { | ||
66 | + var xhr = new XMLHttpRequest(); // use sync to avoid popup blocker | ||
67 | + | ||
68 | + xhr.open('HEAD', url, false); | ||
69 | + | ||
70 | + try { | ||
71 | + xhr.send(); | ||
72 | + } catch (e) {} | ||
73 | + | ||
74 | + return xhr.status >= 200 && xhr.status <= 299; | ||
75 | + } // `a.click()` doesn't work for all browsers (#465) | ||
76 | + | ||
77 | + | ||
78 | + function click(node) { | ||
79 | + try { | ||
80 | + node.dispatchEvent(new MouseEvent('click')); | ||
81 | + } catch (e) { | ||
82 | + var evt = document.createEvent('MouseEvents'); | ||
83 | + evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null); | ||
84 | + node.dispatchEvent(evt); | ||
85 | + } | ||
86 | + } | ||
87 | + | ||
88 | + var saveAs = _global.saveAs || ( // probably in some web worker | ||
89 | + typeof window !== 'object' || window !== _global ? function saveAs() {} | ||
90 | + /* noop */ | ||
91 | + // Use download attribute first if possible (#193 Lumia mobile) | ||
92 | + : 'download' in HTMLAnchorElement.prototype ? function saveAs(blob, name, opts) { | ||
93 | + var URL = _global.URL || _global.webkitURL; | ||
94 | + var a = document.createElement('a'); | ||
95 | + name = name || blob.name || 'download'; | ||
96 | + a.download = name; | ||
97 | + a.rel = 'noopener'; // tabnabbing | ||
98 | + // TODO: detect chrome extensions & packaged apps | ||
99 | + // a.target = '_blank' | ||
100 | + | ||
101 | + if (typeof blob === 'string') { | ||
102 | + // Support regular links | ||
103 | + a.href = blob; | ||
104 | + | ||
105 | + if (a.origin !== location.origin) { | ||
106 | + corsEnabled(a.href) ? download(blob, name, opts) : click(a, a.target = '_blank'); | ||
107 | + } else { | ||
108 | + click(a); | ||
109 | + } | ||
110 | + } else { | ||
111 | + // Support blobs | ||
112 | + a.href = URL.createObjectURL(blob); | ||
113 | + setTimeout(function () { | ||
114 | + URL.revokeObjectURL(a.href); | ||
115 | + }, 4E4); // 40s | ||
116 | + | ||
117 | + setTimeout(function () { | ||
118 | + click(a); | ||
119 | + }, 0); | ||
120 | + } | ||
121 | + } // Use msSaveOrOpenBlob as a second approach | ||
122 | + : 'msSaveOrOpenBlob' in navigator ? function saveAs(blob, name, opts) { | ||
123 | + name = name || blob.name || 'download'; | ||
124 | + | ||
125 | + if (typeof blob === 'string') { | ||
126 | + if (corsEnabled(blob)) { | ||
127 | + download(blob, name, opts); | ||
128 | + } else { | ||
129 | + var a = document.createElement('a'); | ||
130 | + a.href = blob; | ||
131 | + a.target = '_blank'; | ||
132 | + setTimeout(function () { | ||
133 | + click(a); | ||
134 | + }); | ||
135 | + } | ||
136 | + } else { | ||
137 | + navigator.msSaveOrOpenBlob(bom(blob, opts), name); | ||
138 | + } | ||
139 | + } // Fallback to using FileReader and a popup | ||
140 | + : function saveAs(blob, name, opts, popup) { | ||
141 | + // Open a popup immediately do go around popup blocker | ||
142 | + // Mostly only available on user interaction and the fileReader is async so... | ||
143 | + popup = popup || open('', '_blank'); | ||
144 | + | ||
145 | + if (popup) { | ||
146 | + popup.document.title = popup.document.body.innerText = 'downloading...'; | ||
147 | + } | ||
148 | + | ||
149 | + if (typeof blob === 'string') return download(blob, name, opts); | ||
150 | + var force = blob.type === 'application/octet-stream'; | ||
151 | + | ||
152 | + var isSafari = /constructor/i.test(_global.HTMLElement) || _global.safari; | ||
153 | + | ||
154 | + var isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent); | ||
155 | + | ||
156 | + if ((isChromeIOS || force && isSafari) && typeof FileReader === 'object') { | ||
157 | + // Safari doesn't allow downloading of blob URLs | ||
158 | + var reader = new FileReader(); | ||
159 | + | ||
160 | + reader.onloadend = function () { | ||
161 | + var url = reader.result; | ||
162 | + url = isChromeIOS ? url : url.replace(/^data:[^;]*;/, 'data:attachment/file;'); | ||
163 | + if (popup) popup.location.href = url;else location = url; | ||
164 | + popup = null; // reverse-tabnabbing #460 | ||
165 | + }; | ||
166 | + | ||
167 | + reader.readAsDataURL(blob); | ||
168 | + } else { | ||
169 | + var URL = _global.URL || _global.webkitURL; | ||
170 | + var url = URL.createObjectURL(blob); | ||
171 | + if (popup) popup.location = url;else location.href = url; | ||
172 | + popup = null; // reverse-tabnabbing #460 | ||
173 | + | ||
174 | + setTimeout(function () { | ||
175 | + URL.revokeObjectURL(url); | ||
176 | + }, 4E4); // 40s | ||
177 | + } | ||
178 | + }); | ||
179 | + _global.saveAs = saveAs.saveAs = saveAs; | ||
180 | + | ||
181 | + if (typeof module !== 'undefined') { | ||
182 | + module.exports = saveAs; | ||
183 | + } | ||
184 | +}); |
1 | +(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(b,c,d){var e=new XMLHttpRequest;e.open("GET",b),e.responseType="blob",e.onload=function(){a(e.response,c,d)},e.onerror=function(){console.error("could not download file")},e.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=f.saveAs||("object"!=typeof window||window!==f?function(){}:"download"in HTMLAnchorElement.prototype?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(a,b,d,e){if(e=e||open("","_blank"),e&&(e.document.title=e.document.body.innerText="downloading..."),"string"==typeof a)return c(a,b,d);var g="application/octet-stream"===a.type,h=/constructor/i.test(f.HTMLElement)||f.safari,i=/CriOS\/[\d]+/.test(navigator.userAgent);if((i||g&&h)&&"object"==typeof FileReader){var j=new FileReader;j.onloadend=function(){var a=j.result;a=i?a:a.replace(/^data:[^;]*;/,"data:attachment/file;"),e?e.location.href=a:location=a,e=null},j.readAsDataURL(a)}else{var k=f.URL||f.webkitURL,l=k.createObjectURL(a);e?e.location=l:location.href=l,e=null,setTimeout(function(){k.revokeObjectURL(l)},4E4)}});f.saveAs=a.saveAs=a,"undefined"!=typeof module&&(module.exports=a)}); | ||
2 | + | ||
3 | +//# sourceMappingURL=FileSaver.min.js.map | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +{"version":3,"sources":["../src/FileSaver.js"],"names":[],"mappings":"uLAkBA,QAAS,CAAA,CAAT,CAAc,CAAd,CAAoB,CAApB,CAA0B,OACJ,WAAhB,QAAO,CAAA,CADa,CACS,CAAI,CAAG,CAAE,OAAO,GAAT,CADhB,CAEC,QAAhB,QAAO,CAAA,CAFQ,GAGtB,OAAO,CAAC,IAAR,CAAa,oDAAb,CAHsB,CAItB,CAAI,CAAG,CAAE,OAAO,CAAE,CAAC,CAAZ,CAJe,EASpB,CAAI,CAAC,OAAL,EAAgB,6EAA6E,IAA7E,CAAkF,CAAI,CAAC,IAAvF,CATI,CAUf,GAAI,CAAA,IAAJ,CAAS,UAA8B,CAA9B,CAAT,CAA8C,CAAE,IAAI,CAAE,CAAI,CAAC,IAAb,CAA9C,CAVe,CAYjB,CACR,CAED,QAAS,CAAA,CAAT,CAAmB,CAAnB,CAAwB,CAAxB,CAA8B,CAA9B,CAAoC,CAClC,GAAI,CAAA,CAAG,CAAG,GAAI,CAAA,cAAd,CACA,CAAG,CAAC,IAAJ,CAAS,KAAT,CAAgB,CAAhB,CAFkC,CAGlC,CAAG,CAAC,YAAJ,CAAmB,MAHe,CAIlC,CAAG,CAAC,MAAJ,CAAa,UAAY,CACvB,CAAM,CAAC,CAAG,CAAC,QAAL,CAAe,CAAf,CAAqB,CAArB,CACP,CANiC,CAOlC,CAAG,CAAC,OAAJ,CAAc,UAAY,CACxB,OAAO,CAAC,KAAR,CAAc,yBAAd,CACD,CATiC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a,CAK7B,CAAK,CAAG,IACT,CATyE,CAU1E,CAAM,CAAC,aAAP,CAAqB,CAArB,CACD,CAXD,IAWO,IACD,CAAA,CAAG,CAAG,CAAO,CAAC,GAAR,EAAe,CAAO,CAAC,SAD5B,CAED,CAAG,CAAG,CAAG,CAAC,eAAJ,CAAoB,CAApB,CAFL,CAGD,CAHC,CAGM,CAAK,CAAC,QAAN,CAAiB,CAHvB,CAIA,QAAQ,CAAC,IAAT,CAAgB,CAJhB,CAKL,CAAK,CAAG,IALH,CAML,UAAU,CAAC,UAAY,CAAE,CAAG,CAAC,eAAJ,CAAoB,CAApB,CAA0B,CAAzC,CAA2C,GAA3C,CACX,CACF,CA1FU,C,CA6Fb,CAAO,CAAC,MAAR,CAAiB,CAAM,CAAC,MAAP,CAAgB,C,CAEX,WAAlB,QAAO,CAAA,M,GACT,MAAM,CAAC,OAAP,CAAiB,C","file":"FileSaver.min.js","sourcesContent":["/*\n* FileSaver.js\n* A saveAs() FileSaver implementation.\n*\n* By Eli Grey, http://eligrey.com\n*\n* License : https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md (MIT)\n* source : http://purl.eligrey.com/github/FileSaver.js\n*/\n\n// The one and only way of getting global scope in all environments\n// https://stackoverflow.com/q/3277182/1008999\nvar _global = typeof window === 'object' && window.window === window\n ? window : typeof self === 'object' && self.self === self\n ? self : typeof global === 'object' && global.global === global\n ? global\n : this\n\nfunction bom (blob, opts) {\n if (typeof opts === 'undefined') opts = { autoBom: false }\n else if (typeof opts !== 'object') {\n console.warn('Deprecated: Expected third argument to be a object')\n opts = { autoBom: !opts }\n }\n\n // prepend BOM for UTF-8 XML and text/* types (including HTML)\n // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF\n if (opts.autoBom && /^\\s*(?:text\\/\\S*|application\\/xml|\\S*\\/\\S*\\+xml)\\s*;.*charset\\s*=\\s*utf-8/i.test(blob.type)) {\n return new Blob([String.fromCharCode(0xFEFF), blob], { type: blob.type })\n }\n return blob\n}\n\nfunction download (url, name, opts) {\n var xhr = new XMLHttpRequest()\n xhr.open('GET', url)\n xhr.responseType = 'blob'\n xhr.onload = function () {\n saveAs(xhr.response, name, opts)\n }\n xhr.onerror = function () {\n console.error('could not download file')\n }\n xhr.send()\n}\n\nfunction corsEnabled (url) {\n var xhr = new XMLHttpRequest()\n // use sync to avoid popup blocker\n xhr.open('HEAD', url, false)\n try {\n xhr.send()\n } catch (e) {}\n return xhr.status >= 200 && xhr.status <= 299\n}\n\n// `a.click()` doesn't work for all browsers (#465)\nfunction click (node) {\n try {\n node.dispatchEvent(new MouseEvent('click'))\n } catch (e) {\n var evt = document.createEvent('MouseEvents')\n evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80,\n 20, false, false, false, false, 0, null)\n node.dispatchEvent(evt)\n }\n}\n\nvar saveAs = _global.saveAs || (\n // probably in some web worker\n (typeof window !== 'object' || window !== _global)\n ? function saveAs () { /* noop */ }\n\n // Use download attribute first if possible (#193 Lumia mobile)\n : 'download' in HTMLAnchorElement.prototype\n ? function saveAs (blob, name, opts) {\n var URL = _global.URL || _global.webkitURL\n var a = document.createElement('a')\n name = name || blob.name || 'download'\n\n a.download = name\n a.rel = 'noopener' // tabnabbing\n\n // TODO: detect chrome extensions & packaged apps\n // a.target = '_blank'\n\n if (typeof blob === 'string') {\n // Support regular links\n a.href = blob\n if (a.origin !== location.origin) {\n corsEnabled(a.href)\n ? download(blob, name, opts)\n : click(a, a.target = '_blank')\n } else {\n click(a)\n }\n } else {\n // Support blobs\n a.href = URL.createObjectURL(blob)\n setTimeout(function () { URL.revokeObjectURL(a.href) }, 4E4) // 40s\n setTimeout(function () { click(a) }, 0)\n }\n }\n\n // Use msSaveOrOpenBlob as a second approach\n : 'msSaveOrOpenBlob' in navigator\n ? function saveAs (blob, name, opts) {\n name = name || blob.name || 'download'\n\n if (typeof blob === 'string') {\n if (corsEnabled(blob)) {\n download(blob, name, opts)\n } else {\n var a = document.createElement('a')\n a.href = blob\n a.target = '_blank'\n setTimeout(function () { click(a) })\n }\n } else {\n navigator.msSaveOrOpenBlob(bom(blob, opts), name)\n }\n }\n\n // Fallback to using FileReader and a popup\n : function saveAs (blob, name, opts, popup) {\n // Open a popup immediately do go around popup blocker\n // Mostly only available on user interaction and the fileReader is async so...\n popup = popup || open('', '_blank')\n if (popup) {\n popup.document.title =\n popup.document.body.innerText = 'downloading...'\n }\n\n if (typeof blob === 'string') return download(blob, name, opts)\n\n var force = blob.type === 'application/octet-stream'\n var isSafari = /constructor/i.test(_global.HTMLElement) || _global.safari\n var isChromeIOS = /CriOS\\/[\\d]+/.test(navigator.userAgent)\n\n if ((isChromeIOS || (force && isSafari)) && typeof FileReader === 'object') {\n // Safari doesn't allow downloading of blob URLs\n var reader = new FileReader()\n reader.onloadend = function () {\n var url = reader.result\n url = isChromeIOS ? url : url.replace(/^data:[^;]*;/, 'data:attachment/file;')\n if (popup) popup.location.href = url\n else location = url\n popup = null // reverse-tabnabbing #460\n }\n reader.readAsDataURL(blob)\n } else {\n var URL = _global.URL || _global.webkitURL\n var url = URL.createObjectURL(blob)\n if (popup) popup.location = url\n else location.href = url\n popup = null // reverse-tabnabbing #460\n setTimeout(function () { URL.revokeObjectURL(url) }, 4E4) // 40s\n }\n }\n)\n\n_global.saveAs = saveAs.saveAs = saveAs\n\nif (typeof module !== 'undefined') {\n module.exports = saveAs;\n}\n"]} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +{ | ||
2 | + "name": "file-saver", | ||
3 | + "version": "2.0.2", | ||
4 | + "description": "An HTML5 saveAs() FileSaver implementation", | ||
5 | + "main": "dist/FileSaver.min.js", | ||
6 | + "files": [ | ||
7 | + "dist/FileSaver.js", | ||
8 | + "dist/FileSaver.min.js", | ||
9 | + "dist/FileSaver.min.js.map", | ||
10 | + "src/FileSaver.js" | ||
11 | + ], | ||
12 | + "scripts": { | ||
13 | + "test": "echo \"Error: no test specified\" && exit 0", | ||
14 | + "build:development": "babel -o dist/FileSaver.js --plugins @babel/plugin-transform-modules-umd src/FileSaver.js", | ||
15 | + "build:production": "babel -o dist/FileSaver.min.js -s --plugins @babel/plugin-transform-modules-umd --presets minify src/FileSaver.js", | ||
16 | + "build": "npm run build:development && npm run build:production", | ||
17 | + "prepublishOnly": "npm run build" | ||
18 | + }, | ||
19 | + "repository": { | ||
20 | + "type": "git", | ||
21 | + "url": "https://github.com/eligrey/FileSaver.js" | ||
22 | + }, | ||
23 | + "keywords": [ | ||
24 | + "filesaver", | ||
25 | + "saveas", | ||
26 | + "blob" | ||
27 | + ], | ||
28 | + "author": "Eli Grey <me@eligrey.com>", | ||
29 | + "license": "MIT", | ||
30 | + "bugs": { | ||
31 | + "url": "https://github.com/eligrey/FileSaver.js/issues" | ||
32 | + }, | ||
33 | + "homepage": "https://github.com/eligrey/FileSaver.js#readme", | ||
34 | + "devDependencies": { | ||
35 | + "@babel/cli": "^7.1.0", | ||
36 | + "@babel/core": "^7.1.0", | ||
37 | + "@babel/plugin-transform-modules-umd": "^7.1.0", | ||
38 | + "babel-preset-minify": "^0.4.3" | ||
39 | + } | ||
40 | + | ||
41 | +,"_resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.2.tgz" | ||
42 | +,"_integrity": "sha512-Wz3c3XQ5xroCxd1G8b7yL0Ehkf0TC9oYC6buPFkNnU9EnaPlifeAFCyCh+iewXTyFRcg0a6j3J7FmJsIhlhBdw==" | ||
43 | +,"_from": "file-saver@latest" | ||
44 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | +* FileSaver.js | ||
3 | +* A saveAs() FileSaver implementation. | ||
4 | +* | ||
5 | +* By Eli Grey, http://eligrey.com | ||
6 | +* | ||
7 | +* License : https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md (MIT) | ||
8 | +* source : http://purl.eligrey.com/github/FileSaver.js | ||
9 | +*/ | ||
10 | + | ||
11 | +// The one and only way of getting global scope in all environments | ||
12 | +// https://stackoverflow.com/q/3277182/1008999 | ||
13 | +var _global = typeof window === 'object' && window.window === window | ||
14 | + ? window : typeof self === 'object' && self.self === self | ||
15 | + ? self : typeof global === 'object' && global.global === global | ||
16 | + ? global | ||
17 | + : this | ||
18 | + | ||
19 | +function bom (blob, opts) { | ||
20 | + if (typeof opts === 'undefined') opts = { autoBom: false } | ||
21 | + else if (typeof opts !== 'object') { | ||
22 | + console.warn('Deprecated: Expected third argument to be a object') | ||
23 | + opts = { autoBom: !opts } | ||
24 | + } | ||
25 | + | ||
26 | + // prepend BOM for UTF-8 XML and text/* types (including HTML) | ||
27 | + // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF | ||
28 | + if (opts.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) { | ||
29 | + return new Blob([String.fromCharCode(0xFEFF), blob], { type: blob.type }) | ||
30 | + } | ||
31 | + return blob | ||
32 | +} | ||
33 | + | ||
34 | +function download (url, name, opts) { | ||
35 | + var xhr = new XMLHttpRequest() | ||
36 | + xhr.open('GET', url) | ||
37 | + xhr.responseType = 'blob' | ||
38 | + xhr.onload = function () { | ||
39 | + saveAs(xhr.response, name, opts) | ||
40 | + } | ||
41 | + xhr.onerror = function () { | ||
42 | + console.error('could not download file') | ||
43 | + } | ||
44 | + xhr.send() | ||
45 | +} | ||
46 | + | ||
47 | +function corsEnabled (url) { | ||
48 | + var xhr = new XMLHttpRequest() | ||
49 | + // use sync to avoid popup blocker | ||
50 | + xhr.open('HEAD', url, false) | ||
51 | + try { | ||
52 | + xhr.send() | ||
53 | + } catch (e) {} | ||
54 | + return xhr.status >= 200 && xhr.status <= 299 | ||
55 | +} | ||
56 | + | ||
57 | +// `a.click()` doesn't work for all browsers (#465) | ||
58 | +function click (node) { | ||
59 | + try { | ||
60 | + node.dispatchEvent(new MouseEvent('click')) | ||
61 | + } catch (e) { | ||
62 | + var evt = document.createEvent('MouseEvents') | ||
63 | + evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80, | ||
64 | + 20, false, false, false, false, 0, null) | ||
65 | + node.dispatchEvent(evt) | ||
66 | + } | ||
67 | +} | ||
68 | + | ||
69 | +var saveAs = _global.saveAs || ( | ||
70 | + // probably in some web worker | ||
71 | + (typeof window !== 'object' || window !== _global) | ||
72 | + ? function saveAs () { /* noop */ } | ||
73 | + | ||
74 | + // Use download attribute first if possible (#193 Lumia mobile) | ||
75 | + : 'download' in HTMLAnchorElement.prototype | ||
76 | + ? function saveAs (blob, name, opts) { | ||
77 | + var URL = _global.URL || _global.webkitURL | ||
78 | + var a = document.createElement('a') | ||
79 | + name = name || blob.name || 'download' | ||
80 | + | ||
81 | + a.download = name | ||
82 | + a.rel = 'noopener' // tabnabbing | ||
83 | + | ||
84 | + // TODO: detect chrome extensions & packaged apps | ||
85 | + // a.target = '_blank' | ||
86 | + | ||
87 | + if (typeof blob === 'string') { | ||
88 | + // Support regular links | ||
89 | + a.href = blob | ||
90 | + if (a.origin !== location.origin) { | ||
91 | + corsEnabled(a.href) | ||
92 | + ? download(blob, name, opts) | ||
93 | + : click(a, a.target = '_blank') | ||
94 | + } else { | ||
95 | + click(a) | ||
96 | + } | ||
97 | + } else { | ||
98 | + // Support blobs | ||
99 | + a.href = URL.createObjectURL(blob) | ||
100 | + setTimeout(function () { URL.revokeObjectURL(a.href) }, 4E4) // 40s | ||
101 | + setTimeout(function () { click(a) }, 0) | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + // Use msSaveOrOpenBlob as a second approach | ||
106 | + : 'msSaveOrOpenBlob' in navigator | ||
107 | + ? function saveAs (blob, name, opts) { | ||
108 | + name = name || blob.name || 'download' | ||
109 | + | ||
110 | + if (typeof blob === 'string') { | ||
111 | + if (corsEnabled(blob)) { | ||
112 | + download(blob, name, opts) | ||
113 | + } else { | ||
114 | + var a = document.createElement('a') | ||
115 | + a.href = blob | ||
116 | + a.target = '_blank' | ||
117 | + setTimeout(function () { click(a) }) | ||
118 | + } | ||
119 | + } else { | ||
120 | + navigator.msSaveOrOpenBlob(bom(blob, opts), name) | ||
121 | + } | ||
122 | + } | ||
123 | + | ||
124 | + // Fallback to using FileReader and a popup | ||
125 | + : function saveAs (blob, name, opts, popup) { | ||
126 | + // Open a popup immediately do go around popup blocker | ||
127 | + // Mostly only available on user interaction and the fileReader is async so... | ||
128 | + popup = popup || open('', '_blank') | ||
129 | + if (popup) { | ||
130 | + popup.document.title = | ||
131 | + popup.document.body.innerText = 'downloading...' | ||
132 | + } | ||
133 | + | ||
134 | + if (typeof blob === 'string') return download(blob, name, opts) | ||
135 | + | ||
136 | + var force = blob.type === 'application/octet-stream' | ||
137 | + var isSafari = /constructor/i.test(_global.HTMLElement) || _global.safari | ||
138 | + var isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent) | ||
139 | + | ||
140 | + if ((isChromeIOS || (force && isSafari)) && typeof FileReader === 'object') { | ||
141 | + // Safari doesn't allow downloading of blob URLs | ||
142 | + var reader = new FileReader() | ||
143 | + reader.onloadend = function () { | ||
144 | + var url = reader.result | ||
145 | + url = isChromeIOS ? url : url.replace(/^data:[^;]*;/, 'data:attachment/file;') | ||
146 | + if (popup) popup.location.href = url | ||
147 | + else location = url | ||
148 | + popup = null // reverse-tabnabbing #460 | ||
149 | + } | ||
150 | + reader.readAsDataURL(blob) | ||
151 | + } else { | ||
152 | + var URL = _global.URL || _global.webkitURL | ||
153 | + var url = URL.createObjectURL(blob) | ||
154 | + if (popup) popup.location = url | ||
155 | + else location.href = url | ||
156 | + popup = null // reverse-tabnabbing #460 | ||
157 | + setTimeout(function () { URL.revokeObjectURL(url) }, 4E4) // 40s | ||
158 | + } | ||
159 | + } | ||
160 | +) | ||
161 | + | ||
162 | +_global.saveAs = saveAs.saveAs = saveAs | ||
163 | + | ||
164 | +if (typeof module !== 'undefined') { | ||
165 | + module.exports = saveAs; | ||
166 | +} |
... | @@ -12,6 +12,7 @@ | ... | @@ -12,6 +12,7 @@ |
12 | "@types/react": "^16.9.34", | 12 | "@types/react": "^16.9.34", |
13 | "@types/react-dom": "^16.9.6", | 13 | "@types/react-dom": "^16.9.6", |
14 | "@types/react-router-dom": "^5.1.5", | 14 | "@types/react-router-dom": "^5.1.5", |
15 | + "file-saver": "^2.0.2", | ||
15 | "node-sass": "^4.14.0", | 16 | "node-sass": "^4.14.0", |
16 | "react": "^16.13.1", | 17 | "react": "^16.13.1", |
17 | "react-dom": "^16.13.1", | 18 | "react-dom": "^16.13.1", | ... | ... |
... | @@ -2,7 +2,7 @@ import React from "react"; | ... | @@ -2,7 +2,7 @@ import React from "react"; |
2 | import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; | 2 | import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; |
3 | 3 | ||
4 | import EditorPage from "pages/Editor"; | 4 | import EditorPage from "pages/Editor"; |
5 | -import LoginPage from "pages/Login"; | 5 | +// import LoginPage from "pages/Login"; |
6 | 6 | ||
7 | import "./App.css"; | 7 | import "./App.css"; |
8 | 8 | ||
... | @@ -11,8 +11,7 @@ function App() { | ... | @@ -11,8 +11,7 @@ function App() { |
11 | <div className="App"> | 11 | <div className="App"> |
12 | <Router> | 12 | <Router> |
13 | <Switch> | 13 | <Switch> |
14 | - <Route path="/editor" component={EditorPage} /> | 14 | + <Route path="/" component={EditorPage} /> |
15 | - <Route path="/" component={LoginPage} /> | ||
16 | </Switch> | 15 | </Switch> |
17 | </Router> | 16 | </Router> |
18 | </div> | 17 | </div> | ... | ... |
... | @@ -96,4 +96,13 @@ | ... | @@ -96,4 +96,13 @@ |
96 | display: none; | 96 | display: none; |
97 | } | 97 | } |
98 | } | 98 | } |
99 | +} | ||
100 | + | ||
101 | +@for $scale from 1 through 3 { | ||
102 | + .my-editor.tui-image-editor-container.size-#{$scale} { | ||
103 | + .tui-image-editor-canvas-container { | ||
104 | + transform: scale(#{$scale}); | ||
105 | + } | ||
106 | + } | ||
107 | + | ||
99 | } | 108 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -2,23 +2,28 @@ | ... | @@ -2,23 +2,28 @@ |
2 | position: fixed; | 2 | position: fixed; |
3 | width: 100%; | 3 | width: 100%; |
4 | height: 50px; | 4 | height: 50px; |
5 | - //background: white; | ||
6 | z-index: 10; | 5 | z-index: 10; |
7 | 6 | ||
8 | button { | 7 | button { |
8 | + background: none; | ||
9 | + color: white; | ||
9 | float: right; | 10 | float: right; |
10 | height: 35px; | 11 | height: 35px; |
11 | margin-top: 20px; | 12 | margin-top: 20px; |
12 | - font-size: 14px; | 13 | + font-size: 25px; |
13 | border: none; | 14 | border: none; |
14 | border-radius: 5px; | 15 | border-radius: 5px; |
15 | - margin-right: 10px; | 16 | + margin-right: 15px; |
16 | cursor: pointer; | 17 | cursor: pointer; |
17 | padding: 0 10px; | 18 | padding: 0 10px; |
18 | 19 | ||
19 | &:focus { | 20 | &:focus { |
20 | outline: none; | 21 | outline: none; |
21 | } | 22 | } |
23 | + &:hover { | ||
24 | + transition: 0.2s; | ||
25 | + transform: scale(1.2); | ||
26 | + } | ||
22 | } | 27 | } |
23 | 28 | ||
24 | .submenu-toggle { | 29 | .submenu-toggle { |
... | @@ -41,6 +46,7 @@ | ... | @@ -41,6 +46,7 @@ |
41 | .file-box { | 46 | .file-box { |
42 | .file-box-button { | 47 | .file-box-button { |
43 | //background: white; | 48 | //background: white; |
49 | + cursor: pointer; | ||
44 | } | 50 | } |
45 | 51 | ||
46 | #input-image-file { | 52 | #input-image-file { | ... | ... |
1 | import React, { ChangeEvent } from "react"; | 1 | import React, { ChangeEvent } from "react"; |
2 | import ToastEditor from "tui-image-editor"; | 2 | import ToastEditor from "tui-image-editor"; |
3 | +// @ts-ignore | ||
4 | +import { saveAs } from "file-saver"; | ||
3 | 5 | ||
4 | import { SubmenuContext } from "context/Submenu"; | 6 | import { SubmenuContext } from "context/Submenu"; |
5 | 7 | ||
... | @@ -11,10 +13,31 @@ import "./EditorHeader.scss"; | ... | @@ -11,10 +13,31 @@ import "./EditorHeader.scss"; |
11 | 13 | ||
12 | interface EditorHeaderProps { | 14 | interface EditorHeaderProps { |
13 | editor: ToastEditor; | 15 | editor: ToastEditor; |
14 | - imageLoad: boolean | ||
15 | } | 16 | } |
16 | 17 | ||
17 | -function EditorHeader({ editor, imageLoad }: EditorHeaderProps) { | 18 | +const rImageType = /data:(image\/.+);base64,/; |
19 | + | ||
20 | +function base64ToBlob(data: any) { | ||
21 | + let mimeString = ''; | ||
22 | + let raw, uInt8Array, i, rawLength; | ||
23 | + | ||
24 | + raw = data.replace(rImageType, function(header: string, imageType: string) { | ||
25 | + mimeString = imageType; | ||
26 | + return ''; | ||
27 | + }); | ||
28 | + | ||
29 | + raw = atob(raw); | ||
30 | + rawLength = raw.length; | ||
31 | + uInt8Array = new Uint8Array(rawLength); // eslint-disable-line | ||
32 | + | ||
33 | + for (i = 0; i < rawLength; i += 1) { | ||
34 | + uInt8Array[i] = raw.charCodeAt(i); | ||
35 | + } | ||
36 | + | ||
37 | + return new Blob([uInt8Array], {type: mimeString}); | ||
38 | +} | ||
39 | + | ||
40 | +function EditorHeader({ editor }: EditorHeaderProps) { | ||
18 | function onLoadImage(e: ChangeEvent<HTMLInputElement>): void { | 41 | function onLoadImage(e: ChangeEvent<HTMLInputElement>): void { |
19 | const { files } = e.target; | 42 | const { files } = e.target; |
20 | if (files) { | 43 | if (files) { |
... | @@ -23,15 +46,22 @@ function EditorHeader({ editor, imageLoad }: EditorHeaderProps) { | ... | @@ -23,15 +46,22 @@ function EditorHeader({ editor, imageLoad }: EditorHeaderProps) { |
23 | } | 46 | } |
24 | } | 47 | } |
25 | 48 | ||
26 | - function toggleSubmenu() { | 49 | + function onSaveImage() { |
27 | - console.log("toggle Submenu"); | 50 | + let imageName = editor.getImageName(); |
51 | + const dataURL = editor.toDataURL(); | ||
52 | + | ||
53 | + const blob = base64ToBlob(dataURL); | ||
54 | + const type = blob.type.split('/')[1]; | ||
55 | + if (imageName.split('.').pop() !== type) { | ||
56 | + imageName += '.' + type; | ||
57 | + } | ||
58 | + saveAs(blob, imageName); | ||
28 | } | 59 | } |
29 | 60 | ||
30 | return ( | 61 | return ( |
31 | <div className="my-header"> | 62 | <div className="my-header"> |
32 | <SubmenuContext.Consumer> | 63 | <SubmenuContext.Consumer> |
33 | {({ visible, onChange }) => { | 64 | {({ visible, onChange }) => { |
34 | - console.log(visible); | ||
35 | return ( | 65 | return ( |
36 | <button className={`submenu-toggle ${visible && "activate"}`} onClick={() => onChange()}> | 66 | <button className={`submenu-toggle ${visible && "activate"}`} onClick={() => onChange()}> |
37 | <i className="fas fa-list" /> | 67 | <i className="fas fa-list" /> |
... | @@ -40,24 +70,13 @@ function EditorHeader({ editor, imageLoad }: EditorHeaderProps) { | ... | @@ -40,24 +70,13 @@ function EditorHeader({ editor, imageLoad }: EditorHeaderProps) { |
40 | }} | 70 | }} |
41 | </SubmenuContext.Consumer> | 71 | </SubmenuContext.Consumer> |
42 | 72 | ||
43 | - {/*<button>다크모드</button>*/} | 73 | + <button onClick={onSaveImage}><i className="fas fa-save" /></button> |
44 | - {imageLoad ? ( | 74 | + <span className="file-box"> |
45 | - <> | 75 | + <button><label htmlFor="input-image-file" className="file-box-button"> |
46 | - <button>다운로드</button> | 76 | + <i className="fas fa-upload" /> |
47 | - <button>저장하기</button> | 77 | + </label></button> |
48 | - <button>새 작업</button> | 78 | + <input type="file" accept="image/*" id="input-image-file" onChange={(e: ChangeEvent<HTMLInputElement>) => onLoadImage(e)}/> |
49 | - </> | 79 | + </span> |
50 | - ) : ( | ||
51 | - <> | ||
52 | - <span className="file-box"> | ||
53 | - <button><label htmlFor="input-image-file" className="file-box-button">파일 로드</label></button> | ||
54 | - <input type="file" accept="image/*" id="input-image-file" onChange={(e: ChangeEvent<HTMLInputElement>) => onLoadImage(e)}/> | ||
55 | - </span> | ||
56 | - | ||
57 | - <button>URL 로드</button> | ||
58 | - </> | ||
59 | - )} | ||
60 | - | ||
61 | </div> | 80 | </div> |
62 | ); | 81 | ); |
63 | } | 82 | } | ... | ... |
... | @@ -2,9 +2,9 @@ import React, { useRef, useEffect, useState } from "react"; | ... | @@ -2,9 +2,9 @@ import React, { useRef, useEffect, useState } from "react"; |
2 | import ToastEditor from "tui-image-editor"; | 2 | import ToastEditor from "tui-image-editor"; |
3 | 3 | ||
4 | import EditorHeader from "./EditorHeader"; | 4 | import EditorHeader from "./EditorHeader"; |
5 | +import ImageResizer from "./ImageResizer"; | ||
5 | 6 | ||
6 | import { editorOptions } from "utils/editorOptions"; | 7 | import { editorOptions } from "utils/editorOptions"; |
7 | -import { ImageLoadContext } from "context/ImageLoad"; | ||
8 | import { SubmenuContext } from "context/Submenu"; | 8 | import { SubmenuContext } from "context/Submenu"; |
9 | 9 | ||
10 | import "tui-image-editor/dist/tui-image-editor.css"; | 10 | import "tui-image-editor/dist/tui-image-editor.css"; |
... | @@ -14,11 +14,15 @@ import "./EditorPage.scss"; | ... | @@ -14,11 +14,15 @@ import "./EditorPage.scss"; |
14 | // @ts-ignore | 14 | // @ts-ignore |
15 | const initialEditor:ToastEditor = new ToastEditor(document.querySelector("#hidden-editor"), editorOptions); | 15 | const initialEditor:ToastEditor = new ToastEditor(document.querySelector("#hidden-editor"), editorOptions); |
16 | 16 | ||
17 | +function getEditorClass(size: number, subMenuVisible: boolean) { | ||
18 | + return `my-editor tui-image-editor-container left ${!subMenuVisible ? "submenu-hidden" : ""} size-${size}`; | ||
19 | +} | ||
20 | + | ||
17 | function EditorPage() { | 21 | function EditorPage() { |
18 | const imageEditorRef = useRef<HTMLDivElement>(null); | 22 | const imageEditorRef = useRef<HTMLDivElement>(null); |
19 | const [editor, setEditor] = useState(initialEditor); | 23 | const [editor, setEditor] = useState(initialEditor); |
20 | - const [imageLoad, setImageLoad]: [boolean, Function] = useState(false); | ||
21 | const [submenuVisible, setSubmenuVisible] = useState(true); | 24 | const [submenuVisible, setSubmenuVisible] = useState(true); |
25 | + const [size, setSize] = useState(1); | ||
22 | 26 | ||
23 | useEffect(() => { | 27 | useEffect(() => { |
24 | // @ts-ignore | 28 | // @ts-ignore |
... | @@ -36,10 +40,9 @@ function EditorPage() { | ... | @@ -36,10 +40,9 @@ function EditorPage() { |
36 | return ( | 40 | return ( |
37 | <> | 41 | <> |
38 | <SubmenuContext.Provider value={{ visible: submenuVisible, onChange: onChangeSubmenuVisible }}> | 42 | <SubmenuContext.Provider value={{ visible: submenuVisible, onChange: onChangeSubmenuVisible }}> |
39 | - <ImageLoadContext.Provider value={{ imageLoad, setImageLoad }}> | 43 | + <EditorHeader editor={editor} /> |
40 | - <EditorHeader editor={editor} imageLoad={false} /> | 44 | + <div className={getEditorClass(size, submenuVisible)} ref={imageEditorRef} /> |
41 | - <div className={`my-editor tui-image-editor-container left ${!submenuVisible && "submenu-hidden"}`} ref={imageEditorRef} /> | 45 | + <ImageResizer size={size} setSize={setSize} /> |
42 | - </ImageLoadContext.Provider> | ||
43 | </SubmenuContext.Provider> | 46 | </SubmenuContext.Provider> |
44 | </> | 47 | </> |
45 | ); | 48 | ); | ... | ... |
1 | +.image-resize-button { | ||
2 | + position: absolute; | ||
3 | + bottom: 20px; | ||
4 | + right: 20px; | ||
5 | + | ||
6 | + button { | ||
7 | + background: none; | ||
8 | + border: none; | ||
9 | + color: white; | ||
10 | + font-size: 23px; | ||
11 | + margin-right: 10px; | ||
12 | + cursor: pointer; | ||
13 | + | ||
14 | + &:focus { | ||
15 | + outline: none; | ||
16 | + } | ||
17 | + &:hover { | ||
18 | + transition: 0.2s; | ||
19 | + transform: scale(1.2); | ||
20 | + } | ||
21 | + } | ||
22 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | import React from "react"; | 1 | import React from "react"; |
2 | 2 | ||
3 | +import "./ImageResizer.scss"; | ||
4 | + | ||
5 | +interface ImageResizerType { | ||
6 | + size: number, | ||
7 | + setSize: Function, | ||
8 | +} | ||
9 | + | ||
10 | +interface SizeInfoType { | ||
11 | + max: number, | ||
12 | + min: number, | ||
13 | + gap: number, | ||
14 | +} | ||
15 | + | ||
16 | +const SIZE_INFO: SizeInfoType = { | ||
17 | + max: 3, | ||
18 | + min: 1, | ||
19 | + gap: 1 | ||
20 | +}; | ||
21 | + | ||
22 | +function ImageResizer({ size, setSize }: ImageResizerType) { | ||
23 | + const handleResize = (isMagnify: boolean) => { | ||
24 | + if (isMagnify) { // 확대 | ||
25 | + if (size >= SIZE_INFO.max) return; | ||
26 | + setSize(size += SIZE_INFO.gap); | ||
27 | + return; | ||
28 | + } | ||
29 | + | ||
30 | + // 축소 | ||
31 | + if (size <= SIZE_INFO.min) { | ||
32 | + return; | ||
33 | + } | ||
34 | + setSize(size -= SIZE_INFO.gap); | ||
35 | + }; | ||
3 | 36 | ||
4 | -function ImageResizer() { | ||
5 | return ( | 37 | return ( |
6 | - <div>이미지 크기 변경</div> | 38 | + <div className="image-resize-button"> |
39 | + <button onClick={() => handleResize(true)}><i className="fas fa-search-plus" /></button> | ||
40 | + <button onClick={() => handleResize(false)}><i className="fas fa-search-minus" /></button> | ||
41 | + </div> | ||
7 | ); | 42 | ); |
8 | } | 43 | } |
9 | 44 | ... | ... |
캡스톤디자인2 결과보고서.docx
0 → 100644
This file is too large to display.
캡스톤디자인2 결과보고서.pdf
0 → 100644
No preview for this file type
캡스톤디자인2 면담확인서 (2).docx
0 → 100644
This file is too large to display.
캡스톤디자인2 면담확인서 (2).pdf
0 → 100644
No preview for this file type
-
Please register or login to post a comment