quasar-ui-danx 0.3.34 → 0.3.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/danx.es.js +2 -2
- package/dist/danx.es.js.map +1 -1
- package/dist/danx.umd.js +2 -2
- package/dist/danx.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/download.ts +189 -188
package/package.json
CHANGED
package/src/helpers/download.ts
CHANGED
@@ -9,192 +9,193 @@
|
|
9
9
|
|
10
10
|
/* eslint-disable */
|
11
11
|
export function download(data, strFileName, strMimeType) {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
12
|
+
var self = window;
|
13
|
+
// this script is only for browsers anyway...
|
14
|
+
|
15
|
+
var defaultMime = "application/octet-stream";
|
16
|
+
// this default mime also triggers iframe downloads
|
17
|
+
|
18
|
+
var mimeType = strMimeType || defaultMime;
|
19
|
+
|
20
|
+
var payload = data;
|
21
|
+
|
22
|
+
var url = !strFileName && !strMimeType && payload;
|
23
|
+
|
24
|
+
var anchor = document.createElement("a");
|
25
|
+
|
26
|
+
var toString = function (a) {
|
27
|
+
return String(a);
|
28
|
+
};
|
29
|
+
|
30
|
+
// @ts-ignore
|
31
|
+
var myBlob = self.Blob || self.MozBlob || self.WebKitBlob || toString;
|
32
|
+
|
33
|
+
var fileName = strFileName || "download";
|
34
|
+
|
35
|
+
var blob;
|
36
|
+
|
37
|
+
var reader;
|
38
|
+
myBlob = myBlob.call ? myBlob.bind(self) : Blob;
|
39
|
+
|
40
|
+
if (String(this) === "true") {
|
41
|
+
// reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback
|
42
|
+
payload = [payload, mimeType];
|
43
|
+
mimeType = payload[0];
|
44
|
+
payload = payload[1];
|
45
|
+
}
|
46
|
+
|
47
|
+
if (url && url.length < 2048) {
|
48
|
+
// if no filename and no mime, assume a url was passed as the only argument
|
49
|
+
fileName = url.split("/").pop().split("?")[0];
|
50
|
+
anchor.href = url; // assign href prop to temp anchor
|
51
|
+
|
52
|
+
// if the browser determines that it's a potentially valid url path:
|
53
|
+
if (
|
54
|
+
anchor.href.indexOf(url) !== -1 ||
|
55
|
+
anchor.href.indexOf(encodeURI(url)) !== -1 ||
|
56
|
+
anchor.href === encodeURI(url)
|
57
|
+
) {
|
58
|
+
var ajax = new XMLHttpRequest();
|
59
|
+
ajax.open("GET", url + "?no-cache=" + Date.now(), true);
|
60
|
+
ajax.responseType = "blob";
|
61
|
+
ajax.onload = function (e) {
|
62
|
+
// @ts-ignore
|
63
|
+
download(e.target.response, fileName, defaultMime);
|
64
|
+
};
|
65
|
+
ajax.onerror = function (e) {
|
66
|
+
// As a fallback, just open the request in a new tab
|
67
|
+
window.open(url, "_blank").focus();
|
68
|
+
};
|
69
|
+
setTimeout(function () {
|
70
|
+
ajax.send();
|
71
|
+
}, 0); // allows setting custom ajax headers using the return:
|
72
|
+
return ajax;
|
73
|
+
} else {
|
74
|
+
throw new Error("Invalid URL given, cannot download file: " + url);
|
75
|
+
}
|
76
|
+
} // end if url?
|
77
|
+
|
78
|
+
// go ahead and download dataURLs right away
|
79
|
+
if (/^data:[\w+-]+\/[\w+-]+[,;]/.test(payload)) {
|
80
|
+
if (payload.length > 1024 * 1024 * 1.999 && myBlob !== toString) {
|
81
|
+
payload = dataUrlToBlob(payload);
|
82
|
+
mimeType = payload.type || defaultMime;
|
83
|
+
} else {
|
84
|
+
// IE10 can't do a[download], only Blobs
|
85
|
+
// everyone else can save dataURLs un-processed
|
86
|
+
// @ts-ignore
|
87
|
+
return navigator.msSaveBlob ? navigator.msSaveBlob(dataUrlToBlob(payload), fileName) : saver(payload);
|
88
|
+
}
|
89
|
+
} // end if dataURL passed?
|
90
|
+
|
91
|
+
blob =
|
92
|
+
payload instanceof myBlob
|
93
|
+
? payload
|
94
|
+
: new myBlob([payload], { type: mimeType });
|
95
|
+
|
96
|
+
function dataUrlToBlob(strUrl) {
|
97
|
+
var parts = strUrl.split(/[:;,]/);
|
98
|
+
|
99
|
+
var type = parts[1];
|
100
|
+
|
101
|
+
var decoder = parts[2] === "base64" ? atob : decodeURIComponent;
|
102
|
+
|
103
|
+
var binData = decoder(parts.pop());
|
104
|
+
|
105
|
+
var mx = binData.length;
|
106
|
+
|
107
|
+
var i = 0;
|
108
|
+
|
109
|
+
var uiArr = new Uint8Array(mx);
|
110
|
+
|
111
|
+
for (i; i < mx; ++i) uiArr[i] = binData.charCodeAt(i);
|
112
|
+
|
113
|
+
return new myBlob([uiArr], { type: type });
|
114
|
+
}
|
115
|
+
|
116
|
+
function saver(url, winMode) {
|
117
|
+
if ("download" in anchor) {
|
118
|
+
// html5 A[download]
|
119
|
+
anchor.href = url;
|
120
|
+
anchor.setAttribute("download", fileName);
|
121
|
+
anchor.className = "download-js-link";
|
122
|
+
anchor.innerHTML = "downloading...";
|
123
|
+
anchor.style.display = "none";
|
124
|
+
anchor.target = "_blank";
|
125
|
+
document.body.appendChild(anchor);
|
126
|
+
setTimeout(function () {
|
127
|
+
anchor.click();
|
128
|
+
document.body.removeChild(anchor);
|
129
|
+
if (winMode === true) {
|
130
|
+
setTimeout(function () {
|
131
|
+
self.URL.revokeObjectURL(anchor.href);
|
132
|
+
}, 250);
|
133
|
+
}
|
134
|
+
}, 66);
|
135
|
+
return true;
|
136
|
+
}
|
137
|
+
|
138
|
+
// handle non-a[download] safari as best we can:
|
139
|
+
if (
|
140
|
+
/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent)
|
141
|
+
) {
|
142
|
+
url = url.replace(/^data:([\w/\-+]+)/, defaultMime);
|
143
|
+
if (!window.open(url)) {
|
144
|
+
// popup blocked, offer direct download:
|
145
|
+
if (
|
146
|
+
confirm(
|
147
|
+
"Displaying New Document\n\nUse Save As... to download, then click back to return to this page."
|
148
|
+
)
|
149
|
+
) {
|
150
|
+
location.href = url;
|
151
|
+
}
|
152
|
+
}
|
153
|
+
return true;
|
154
|
+
}
|
155
|
+
|
156
|
+
// do iframe dataURL download (old ch+FF):
|
157
|
+
var f = document.createElement("iframe");
|
158
|
+
document.body.appendChild(f);
|
159
|
+
|
160
|
+
if (!winMode) {
|
161
|
+
// force a mime that will download:
|
162
|
+
url = "data:" + url.replace(/^data:([\w/\-+]+)/, defaultMime);
|
163
|
+
}
|
164
|
+
f.src = url;
|
165
|
+
setTimeout(function () {
|
166
|
+
document.body.removeChild(f);
|
167
|
+
}, 333);
|
168
|
+
} // end saver
|
169
|
+
|
170
|
+
// @ts-ignore
|
171
|
+
if (navigator.msSaveBlob) {
|
172
|
+
// IE10+ : (has Blob, but not a[download] or URL)
|
173
|
+
// @ts-ignore
|
174
|
+
return navigator.msSaveBlob(blob, fileName);
|
175
|
+
}
|
176
|
+
|
177
|
+
if (self.URL) {
|
178
|
+
// simple fast and modern way using Blob and URL:
|
179
|
+
saver(self.URL.createObjectURL(blob), true);
|
180
|
+
} else {
|
181
|
+
// handle non-Blob()+non-URL browsers:
|
182
|
+
if (typeof blob === "string" || blob.constructor === toString) {
|
183
|
+
try {
|
184
|
+
// @ts-ignore
|
185
|
+
return saver("data:" + mimeType + ";base64," + self.btoa(blob));
|
186
|
+
} catch (y) {
|
187
|
+
// @ts-ignore
|
188
|
+
return saver("data:" + mimeType + "," + encodeURIComponent(blob));
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
// Blob but not URL support:
|
193
|
+
reader = new FileReader();
|
194
|
+
reader.onload = function (e) {
|
195
|
+
// @ts-ignore
|
196
|
+
saver(this.result);
|
197
|
+
};
|
198
|
+
reader.readAsDataURL(blob);
|
199
|
+
}
|
200
|
+
return true;
|
200
201
|
}
|