@nativescript/canvas-polyfill 1.0.14-v6 → 1.1.0-alpha.0
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/DOM/CharacterData.js +5 -10
- package/DOM/CharacterData.js.map +1 -1
- package/DOM/Document.d.ts +7 -5
- package/DOM/Document.js +55 -59
- package/DOM/Document.js.map +1 -1
- package/DOM/Element.d.ts +21 -19
- package/DOM/Element.js +64 -137
- package/DOM/Element.js.map +1 -1
- package/DOM/HTMLCanvasElement.d.ts +7 -1
- package/DOM/HTMLCanvasElement.js +35 -11
- package/DOM/HTMLCanvasElement.js.map +1 -1
- package/DOM/HTMLImageElement.d.ts +6 -3
- package/DOM/HTMLImageElement.js +113 -140
- package/DOM/HTMLImageElement.js.map +1 -1
- package/DOM/HTMLVideoElement.d.ts +14 -7
- package/DOM/HTMLVideoElement.js +81 -111
- package/DOM/HTMLVideoElement.js.map +1 -1
- package/DOM/Node.d.ts +7 -1
- package/DOM/Node.js +57 -42
- package/DOM/Node.js.map +1 -1
- package/DOM/Text.js +5 -10
- package/DOM/Text.js.map +1 -1
- package/DOM/XMLDocument.js +3 -11
- package/DOM/XMLDocument.js.map +1 -1
- package/DOM/svg/SVGCircleElement.d.ts +13 -0
- package/DOM/svg/SVGCircleElement.js +39 -0
- package/DOM/svg/SVGCircleElement.js.map +1 -0
- package/DOM/svg/SVGElement.d.ts +17 -0
- package/DOM/svg/SVGElement.js +59 -0
- package/DOM/svg/SVGElement.js.map +1 -0
- package/DOM/svg/SVGGGElement.d.ts +13 -0
- package/DOM/svg/SVGGGElement.js +39 -0
- package/DOM/svg/SVGGGElement.js.map +1 -0
- package/DOM/svg/SVGPathElement.d.ts +13 -0
- package/DOM/svg/SVGPathElement.js +39 -0
- package/DOM/svg/SVGPathElement.js.map +1 -0
- package/DOM/svg/SVGRectElement.d.ts +13 -0
- package/DOM/svg/SVGRectElement.js +39 -0
- package/DOM/svg/SVGRectElement.js.map +1 -0
- package/DOM/svg/index.d.ts +5 -0
- package/DOM/svg/index.js +6 -0
- package/DOM/svg/index.js.map +1 -0
- package/URL.android.d.ts +38 -0
- package/URL.android.js +266 -0
- package/URL.android.js.map +1 -0
- package/URL.ios.d.ts +37 -0
- package/URL.ios.js +209 -0
- package/URL.ios.js.map +1 -0
- package/async/async.js +3 -8
- package/async/async.js.map +1 -1
- package/async/file/file.android.js +13 -21
- package/async/file/file.android.js.map +1 -1
- package/async/file/file.ios.js +21 -29
- package/async/file/file.ios.js.map +1 -1
- package/async/http/http-request-common.d.ts +5 -5
- package/async/http/http-request-common.js +36 -67
- package/async/http/http-request-common.js.map +1 -1
- package/async/http/http.android.js +194 -201
- package/async/http/http.android.js.map +1 -1
- package/async/http/http.ios.js +135 -142
- package/async/http/http.ios.js.map +1 -1
- package/async/xhr/TNSXMLHttpRequest.d.ts +17 -15
- package/async/xhr/TNSXMLHttpRequest.js +527 -585
- package/async/xhr/TNSXMLHttpRequest.js.map +1 -1
- package/index.js +45 -21
- package/index.js.map +1 -1
- package/package.json +6 -8
- package/performance.d.ts +0 -1
- package/performance.js +12 -15
- package/performance.js.map +1 -1
- package/platforms/android/include.gradle +2 -2
- package/resize.js +8 -10
- package/resize.js.map +1 -1
- package/window.d.ts +1 -1
- package/window.js +57 -85
- package/window.js.map +1 -1
- package/URL.d.ts +0 -5
- package/URL.js +0 -46
- package/URL.js.map +0 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var core_1 = require("@nativescript/core");
|
|
1
|
+
var _a, _b, _c;
|
|
2
|
+
import { Http } from '../http/http';
|
|
3
|
+
import { HttpError, ProgressEvent } from '../http/http-request-common';
|
|
4
|
+
import { FileManager } from '../file/file';
|
|
5
|
+
import { isNullOrUndefined, isObject, isFunction } from '@nativescript/core/utils/types';
|
|
6
|
+
import { knownFolders, path as filePath, File as fsFile } from '@nativescript/core';
|
|
8
7
|
var XMLHttpRequestResponseType;
|
|
9
8
|
(function (XMLHttpRequestResponseType) {
|
|
10
9
|
XMLHttpRequestResponseType["empty"] = "";
|
|
@@ -14,7 +13,7 @@ var XMLHttpRequestResponseType;
|
|
|
14
13
|
XMLHttpRequestResponseType["arraybuffer"] = "arraybuffer";
|
|
15
14
|
XMLHttpRequestResponseType["blob"] = "blob";
|
|
16
15
|
})(XMLHttpRequestResponseType || (XMLHttpRequestResponseType = {}));
|
|
17
|
-
|
|
16
|
+
const statuses = {
|
|
18
17
|
100: 'Continue',
|
|
19
18
|
101: 'Switching Protocols',
|
|
20
19
|
200: 'OK',
|
|
@@ -54,7 +53,7 @@ var statuses = {
|
|
|
54
53
|
502: 'Bad Gateway',
|
|
55
54
|
503: 'Service Unavailable',
|
|
56
55
|
504: 'Gateway Timeout',
|
|
57
|
-
505: 'HTTP Version Not Supported'
|
|
56
|
+
505: 'HTTP Version Not Supported'
|
|
58
57
|
};
|
|
59
58
|
var Status;
|
|
60
59
|
(function (Status) {
|
|
@@ -63,37 +62,30 @@ var Status;
|
|
|
63
62
|
Status[Status["LOADING"] = 200] = "LOADING";
|
|
64
63
|
Status[Status["DONE"] = 200] = "DONE";
|
|
65
64
|
})(Status || (Status = {}));
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
export class TNSXMLHttpRequestUpload {
|
|
66
|
+
constructor(req) {
|
|
68
67
|
this._listeners = new Map();
|
|
69
68
|
this._request = req;
|
|
70
69
|
}
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
addEventListener(eventName, handler) {
|
|
71
|
+
const handlers = this._listeners.get(eventName) || [];
|
|
73
72
|
handlers.push(handler);
|
|
74
73
|
this._listeners.set(eventName, handlers);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
handlers = handlers.filter(
|
|
74
|
+
}
|
|
75
|
+
removeEventListener(eventName, toDetach) {
|
|
76
|
+
let handlers = this._listeners.get(eventName) || [];
|
|
77
|
+
handlers = handlers.filter(handler => handler !== toDetach);
|
|
79
78
|
this._listeners.set(eventName, handlers);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
args[_i - 1] = arguments[_i];
|
|
86
|
-
}
|
|
87
|
-
var handlers = this._listeners.get(eventName) || [];
|
|
88
|
-
handlers.forEach(function (handler) {
|
|
89
|
-
handler.apply.apply(handler, [_this].concat(args));
|
|
79
|
+
}
|
|
80
|
+
_emitEvent(eventName, ...args) {
|
|
81
|
+
const handlers = this._listeners.get(eventName) || [];
|
|
82
|
+
handlers.forEach(handler => {
|
|
83
|
+
handler.apply(this, ...args);
|
|
90
84
|
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
var TNSXMLHttpRequest = /** @class */ (function () {
|
|
96
|
-
function TNSXMLHttpRequest() {
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export class TNSXMLHttpRequest {
|
|
88
|
+
constructor() {
|
|
97
89
|
this.UNSENT = 0;
|
|
98
90
|
this.OPENED = 1;
|
|
99
91
|
this.HEADERS_RECEIVED = 2;
|
|
@@ -108,114 +100,83 @@ var TNSXMLHttpRequest = /** @class */ (function () {
|
|
|
108
100
|
this._lastProgress = { lengthComputable: false, loaded: 0, total: 0, target: this };
|
|
109
101
|
this._responseURL = '';
|
|
110
102
|
this._listeners = new Map();
|
|
111
|
-
this.
|
|
103
|
+
this._didUserSetResponseType = false;
|
|
104
|
+
this.textTypes = [
|
|
105
|
+
'text/plain',
|
|
106
|
+
'application/xml',
|
|
107
|
+
'application/rss+xml',
|
|
108
|
+
'text/html',
|
|
109
|
+
'text/xml',
|
|
110
|
+
];
|
|
112
111
|
this._status = Status.UNSENT;
|
|
113
|
-
this._http = new
|
|
112
|
+
this._http = new Http();
|
|
114
113
|
this._upload = new TNSXMLHttpRequestUpload(this);
|
|
115
114
|
}
|
|
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
|
-
enumerable: true,
|
|
143
|
-
configurable: true
|
|
144
|
-
});
|
|
145
|
-
Object.defineProperty(TNSXMLHttpRequest.prototype, "responseText", {
|
|
146
|
-
get: function () {
|
|
147
|
-
if (this._responseType === XMLHttpRequestResponseType.text || this._responseType === XMLHttpRequestResponseType.json) {
|
|
148
|
-
return this._responseText;
|
|
149
|
-
}
|
|
150
|
-
return null;
|
|
151
|
-
},
|
|
152
|
-
enumerable: true,
|
|
153
|
-
configurable: true
|
|
154
|
-
});
|
|
155
|
-
Object.defineProperty(TNSXMLHttpRequest.prototype, "responseURL", {
|
|
156
|
-
get: function () {
|
|
157
|
-
return this._responseURL;
|
|
158
|
-
},
|
|
159
|
-
enumerable: true,
|
|
160
|
-
configurable: true
|
|
161
|
-
});
|
|
162
|
-
Object.defineProperty(TNSXMLHttpRequest.prototype, "status", {
|
|
163
|
-
get: function () {
|
|
164
|
-
return this._status;
|
|
165
|
-
},
|
|
166
|
-
enumerable: true,
|
|
167
|
-
configurable: true
|
|
168
|
-
});
|
|
169
|
-
Object.defineProperty(TNSXMLHttpRequest.prototype, "statusText", {
|
|
170
|
-
get: function () {
|
|
171
|
-
if (this._readyState === this.UNSENT || this._readyState === this.OPENED) {
|
|
172
|
-
return '';
|
|
173
|
-
}
|
|
174
|
-
return statuses[this.status];
|
|
175
|
-
},
|
|
176
|
-
enumerable: true,
|
|
177
|
-
configurable: true
|
|
178
|
-
});
|
|
179
|
-
Object.defineProperty(TNSXMLHttpRequest.prototype, "upload", {
|
|
180
|
-
get: function () {
|
|
181
|
-
return this._upload;
|
|
182
|
-
},
|
|
183
|
-
enumerable: true,
|
|
184
|
-
configurable: true
|
|
185
|
-
});
|
|
186
|
-
Object.defineProperty(TNSXMLHttpRequest.prototype, "responseXML", {
|
|
187
|
-
get: function () {
|
|
188
|
-
var header = this.getResponseHeader('Content-Type') || this.getResponseHeader('content-type');
|
|
189
|
-
var contentType = header && header.toLowerCase();
|
|
190
|
-
if (this.isTextContentType(contentType)) {
|
|
191
|
-
if (this._responseType === XMLHttpRequestResponseType.document) {
|
|
192
|
-
return this.responseText;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
115
|
+
get readyState() {
|
|
116
|
+
return this._readyState;
|
|
117
|
+
}
|
|
118
|
+
get response() {
|
|
119
|
+
return this._response;
|
|
120
|
+
}
|
|
121
|
+
get responseType() {
|
|
122
|
+
return this._responseType;
|
|
123
|
+
}
|
|
124
|
+
get responseText() {
|
|
125
|
+
if (this._responseType === XMLHttpRequestResponseType.text ||
|
|
126
|
+
this._responseType === XMLHttpRequestResponseType.json) {
|
|
127
|
+
return this._responseText;
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
get responseURL() {
|
|
132
|
+
return this._responseURL;
|
|
133
|
+
}
|
|
134
|
+
get status() {
|
|
135
|
+
return this._status;
|
|
136
|
+
}
|
|
137
|
+
get statusText() {
|
|
138
|
+
if (this._readyState === this.UNSENT ||
|
|
139
|
+
this._readyState === this.OPENED) {
|
|
195
140
|
return '';
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
141
|
+
}
|
|
142
|
+
return statuses[this.status];
|
|
143
|
+
}
|
|
144
|
+
get upload() {
|
|
145
|
+
return this._upload;
|
|
146
|
+
}
|
|
147
|
+
get responseXML() {
|
|
148
|
+
const header = this.getResponseHeader('Content-Type') ||
|
|
149
|
+
this.getResponseHeader('content-type');
|
|
150
|
+
const contentType = header && header.toLowerCase();
|
|
151
|
+
if (this.isTextContentType(contentType)) {
|
|
152
|
+
if (this._responseType === XMLHttpRequestResponseType.document) {
|
|
153
|
+
return this.responseText;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return '';
|
|
157
|
+
}
|
|
158
|
+
isTextContentType(contentType) {
|
|
159
|
+
let result = false;
|
|
160
|
+
for (let i = 0; i < this.textTypes.length; i++) {
|
|
203
161
|
if (contentType.toLowerCase().indexOf(this.textTypes[i]) >= 0) {
|
|
204
162
|
result = true;
|
|
205
163
|
break;
|
|
206
164
|
}
|
|
207
165
|
}
|
|
208
166
|
return result;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
167
|
+
}
|
|
168
|
+
_setResponseType() {
|
|
169
|
+
const header = this.getResponseHeader('Content-Type') ||
|
|
170
|
+
this.getResponseHeader('content-type');
|
|
171
|
+
const contentType = header && header.toLowerCase();
|
|
213
172
|
if (contentType) {
|
|
214
|
-
if (contentType.indexOf('application/json') >= 0 ||
|
|
173
|
+
if (contentType.indexOf('application/json') >= 0 ||
|
|
174
|
+
contentType.indexOf('+json') >= 0) {
|
|
215
175
|
this._responseType = XMLHttpRequestResponseType.json;
|
|
216
176
|
}
|
|
217
177
|
else if (this.isTextContentType(contentType)) {
|
|
218
|
-
if (contentType.indexOf('text/html') ||
|
|
178
|
+
if (contentType.indexOf('text/html') ||
|
|
179
|
+
contentType.indexOf('text/xml')) {
|
|
219
180
|
this._responseType = XMLHttpRequestResponseType.document;
|
|
220
181
|
}
|
|
221
182
|
this._responseType = XMLHttpRequestResponseType.text;
|
|
@@ -224,29 +185,29 @@ var TNSXMLHttpRequest = /** @class */ (function () {
|
|
|
224
185
|
else {
|
|
225
186
|
this._responseType = XMLHttpRequestResponseType.text;
|
|
226
187
|
}
|
|
227
|
-
}
|
|
228
|
-
|
|
188
|
+
}
|
|
189
|
+
getAllResponseHeaders() {
|
|
229
190
|
if (this._readyState < 2) {
|
|
230
191
|
return '';
|
|
231
192
|
}
|
|
232
|
-
|
|
193
|
+
let result = '';
|
|
233
194
|
if (typeof this._headers === 'object') {
|
|
234
|
-
|
|
235
|
-
for (
|
|
236
|
-
var key = keys_1[_i];
|
|
195
|
+
const keys = Object.keys(this._headers);
|
|
196
|
+
for (let key of keys) {
|
|
237
197
|
result += key + ': ' + this._headers[key] + '\r\n';
|
|
238
198
|
}
|
|
239
199
|
}
|
|
240
200
|
return result.substr(0, result.length - 2);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (typeof header === 'string' &&
|
|
201
|
+
}
|
|
202
|
+
getResponseHeader(header) {
|
|
203
|
+
if (typeof header === 'string' &&
|
|
204
|
+
this._readyState > 1 &&
|
|
205
|
+
this._headers) {
|
|
244
206
|
header = header.toLowerCase();
|
|
245
207
|
if (typeof this._headers === 'object') {
|
|
246
|
-
|
|
247
|
-
for (
|
|
248
|
-
|
|
249
|
-
var item = key.toLowerCase();
|
|
208
|
+
const keys = Object.keys(this._headers);
|
|
209
|
+
for (let key of keys) {
|
|
210
|
+
const item = key.toLowerCase();
|
|
250
211
|
if (item === header) {
|
|
251
212
|
return this._headers[key];
|
|
252
213
|
}
|
|
@@ -255,143 +216,155 @@ var TNSXMLHttpRequest = /** @class */ (function () {
|
|
|
255
216
|
return null;
|
|
256
217
|
}
|
|
257
218
|
return null;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
219
|
+
}
|
|
220
|
+
overrideMimeType(mime) {
|
|
221
|
+
}
|
|
222
|
+
set responseType(value) {
|
|
223
|
+
this._didUserSetResponseType = true;
|
|
224
|
+
if (value === XMLHttpRequestResponseType.empty ||
|
|
225
|
+
value in XMLHttpRequestResponseType) {
|
|
226
|
+
this._responseType = value;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
throw new Error(`Response type of '${value}' not supported.`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
_addToStringOnResponse() {
|
|
262
233
|
// Add toString() method to ease debugging and
|
|
263
234
|
// make Angular2 response.text() method work properly.
|
|
264
|
-
if (
|
|
235
|
+
if (isNullOrUndefined(this.response)) {
|
|
265
236
|
return;
|
|
266
237
|
}
|
|
267
238
|
if (this.response instanceof ArrayBuffer) {
|
|
268
239
|
return;
|
|
269
240
|
}
|
|
270
|
-
if (
|
|
241
|
+
if (isObject(this.response)) {
|
|
271
242
|
Object.defineProperty(this._response, 'toString', {
|
|
272
243
|
configurable: true,
|
|
273
244
|
enumerable: false,
|
|
274
245
|
writable: true,
|
|
275
|
-
value:
|
|
246
|
+
value: () => this.responseText,
|
|
276
247
|
});
|
|
277
248
|
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
for (
|
|
284
|
-
|
|
249
|
+
}
|
|
250
|
+
_toJSString(data) {
|
|
251
|
+
const encodings = ['UTF-8', 'US-ASCII', 'ISO-8859-1', null];
|
|
252
|
+
let value;
|
|
253
|
+
const count = encodings.length;
|
|
254
|
+
for (let i = 0; i < count; i++) {
|
|
255
|
+
let encodingType = encodings[i];
|
|
285
256
|
// let java decide :D
|
|
286
257
|
if (encodingType === null) {
|
|
287
|
-
value = new java.lang.String(data).toString();
|
|
258
|
+
value = (new java.lang.String(data)).toString();
|
|
288
259
|
break;
|
|
289
260
|
}
|
|
290
261
|
try {
|
|
291
|
-
|
|
292
|
-
value = new java.lang.String(data, encoding).toString();
|
|
262
|
+
let encoding = java.nio.charset.Charset.forName(encodingType);
|
|
263
|
+
value = (new java.lang.String(data, encoding)).toString();
|
|
293
264
|
break;
|
|
294
265
|
}
|
|
295
|
-
catch (e) {
|
|
266
|
+
catch (e) {
|
|
267
|
+
}
|
|
296
268
|
}
|
|
297
269
|
return value;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (async === void 0) { async = true; }
|
|
301
|
-
if (username === void 0) { username = null; }
|
|
302
|
-
if (password === void 0) { password = null; }
|
|
270
|
+
}
|
|
271
|
+
open(method, url, async = true, username = null, password = null) {
|
|
303
272
|
this._headers = {};
|
|
304
273
|
this._responseURL = '';
|
|
305
274
|
this._httpContent = null;
|
|
306
275
|
this._request = {
|
|
307
|
-
method
|
|
308
|
-
url
|
|
309
|
-
async
|
|
310
|
-
username
|
|
311
|
-
password
|
|
276
|
+
method,
|
|
277
|
+
url,
|
|
278
|
+
async,
|
|
279
|
+
username,
|
|
280
|
+
password,
|
|
312
281
|
};
|
|
313
282
|
this._updateReadyStateChange(this.OPENED);
|
|
314
|
-
}
|
|
315
|
-
|
|
283
|
+
}
|
|
284
|
+
setRequestHeader(header, value) {
|
|
316
285
|
if (this._readyState !== this.OPENED) {
|
|
317
286
|
throw new Error("Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED.");
|
|
318
287
|
}
|
|
319
288
|
if (typeof this._headers === 'object') {
|
|
320
289
|
this._headers[header] = value;
|
|
321
290
|
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
var
|
|
325
|
-
if (body === void 0) { body = null; }
|
|
291
|
+
}
|
|
292
|
+
send(body = null) {
|
|
293
|
+
var _d, _e;
|
|
326
294
|
if (this._readyState !== this.OPENED) {
|
|
327
295
|
throw new Error("Failed to execute 'send' on 'XMLHttpRequest': The object's state must be OPENED");
|
|
328
296
|
}
|
|
329
297
|
if (!this._headers['Accept']) {
|
|
330
298
|
this._headers['Accept'] = '*/*';
|
|
331
299
|
}
|
|
332
|
-
if (typeof this._request.method === 'string' &&
|
|
333
|
-
|
|
300
|
+
if (typeof this._request.method === 'string' &&
|
|
301
|
+
this._request.method.toLowerCase() === 'get' &&
|
|
302
|
+
typeof this._request.url === 'string' && !this._request.url.startsWith('http')) {
|
|
303
|
+
let path;
|
|
334
304
|
if (this._request.url.startsWith('file://')) {
|
|
335
305
|
path = this._request.url.replace('file://', '');
|
|
336
306
|
}
|
|
337
307
|
else if (this._request.url.startsWith('~/')) {
|
|
338
|
-
path =
|
|
308
|
+
path = filePath.join(knownFolders.currentApp().path, this._request.url.replace('~/', ''));
|
|
339
309
|
}
|
|
340
310
|
else if (this._request.url.startsWith('/')) {
|
|
341
311
|
path = this._request.url;
|
|
342
312
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
313
|
+
else if (this._request.url.startsWith('blob:nativescript')) {
|
|
314
|
+
path = (_e = (_d = URL === null || URL === void 0 ? void 0 : URL.InternalAccessor) === null || _d === void 0 ? void 0 : _d.getPath) === null || _e === void 0 ? void 0 : _e.call(_d, this._request.url);
|
|
315
|
+
}
|
|
316
|
+
const responseURL = `file://${path}`;
|
|
317
|
+
let contentLength = -1;
|
|
318
|
+
const file = fsFile.fromPath(path);
|
|
319
|
+
if (fsFile.exists(path)) {
|
|
320
|
+
contentLength = file.size;
|
|
348
321
|
}
|
|
349
322
|
this._lastProgress = {
|
|
350
|
-
lengthComputable:
|
|
323
|
+
lengthComputable: contentLength > -1,
|
|
351
324
|
loaded: 0,
|
|
352
|
-
total:
|
|
325
|
+
total: contentLength,
|
|
353
326
|
target: this,
|
|
354
327
|
};
|
|
355
|
-
|
|
328
|
+
const startEvent = new ProgressEvent('loadstart', this._lastProgress);
|
|
356
329
|
if (this.onloadstart) {
|
|
357
330
|
this.onloadstart(startEvent);
|
|
358
331
|
}
|
|
359
332
|
this.emitEvent('loadstart', startEvent);
|
|
360
333
|
this._updateReadyStateChange(this.LOADING);
|
|
361
|
-
|
|
334
|
+
FileManager.readFile(path, {}, (error, data) => {
|
|
362
335
|
if (error) {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
if (
|
|
366
|
-
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
if (
|
|
371
|
-
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
336
|
+
const errorEvent = new ProgressEvent('error', this._lastProgress);
|
|
337
|
+
this._responseText = error.message;
|
|
338
|
+
if (this.onerror) {
|
|
339
|
+
this.onerror(errorEvent);
|
|
340
|
+
}
|
|
341
|
+
this.emitEvent('error', errorEvent);
|
|
342
|
+
const loadendEvent = new ProgressEvent('loadend', this._lastProgress);
|
|
343
|
+
if (this.onloadend) {
|
|
344
|
+
this.onloadend(loadendEvent);
|
|
345
|
+
}
|
|
346
|
+
this.emitEvent('loadend', loadendEvent);
|
|
347
|
+
this._updateReadyStateChange(this.DONE);
|
|
375
348
|
}
|
|
376
349
|
else {
|
|
377
|
-
if (!
|
|
378
|
-
|
|
350
|
+
if (!this._didUserSetResponseType) {
|
|
351
|
+
this._setResponseType();
|
|
379
352
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
if (
|
|
353
|
+
this._status = 200;
|
|
354
|
+
this._httpContent = data;
|
|
355
|
+
this._responseURL = responseURL;
|
|
356
|
+
if (this.responseType === XMLHttpRequestResponseType.json) {
|
|
384
357
|
try {
|
|
385
|
-
if (
|
|
386
|
-
|
|
387
|
-
|
|
358
|
+
if (global.isAndroid) {
|
|
359
|
+
this._responseText = this._toJSString(data);
|
|
360
|
+
this._response = JSON.parse(this._responseText);
|
|
388
361
|
}
|
|
389
362
|
else {
|
|
390
|
-
|
|
391
|
-
if (!
|
|
392
|
-
|
|
363
|
+
this._responseText = NSString.alloc().initWithDataEncoding(data, NSUTF8StringEncoding);
|
|
364
|
+
if (!this._responseText) {
|
|
365
|
+
this._responseText = NSString.alloc().initWithDataEncoding(data, NSISOLatin1StringEncoding);
|
|
393
366
|
}
|
|
394
|
-
|
|
367
|
+
this._response = JSON.parse(this._responseText);
|
|
395
368
|
}
|
|
396
369
|
}
|
|
397
370
|
catch (e) {
|
|
@@ -399,59 +372,63 @@ var TNSXMLHttpRequest = /** @class */ (function () {
|
|
|
399
372
|
// this should probably be caught before the promise resolves
|
|
400
373
|
}
|
|
401
374
|
}
|
|
402
|
-
else if (
|
|
403
|
-
if (
|
|
404
|
-
|
|
405
|
-
|
|
375
|
+
else if (this.responseType === XMLHttpRequestResponseType.text) {
|
|
376
|
+
if (global.isIOS) {
|
|
377
|
+
let code = NSUTF8StringEncoding; // long:4
|
|
378
|
+
let encodedString = NSString.alloc().initWithDataEncoding(data, code);
|
|
406
379
|
// If UTF8 string encoding fails try with ISO-8859-1
|
|
407
380
|
if (!encodedString) {
|
|
408
381
|
code = NSISOLatin1StringEncoding; // long:5
|
|
409
382
|
encodedString = NSString.alloc().initWithDataEncoding(data, code);
|
|
410
383
|
}
|
|
411
|
-
|
|
384
|
+
this._responseText = this._response = encodedString.toString();
|
|
412
385
|
}
|
|
413
386
|
else {
|
|
414
|
-
|
|
415
|
-
|
|
387
|
+
const response = this._toJSString(data);
|
|
388
|
+
this._responseText = this._response = response
|
|
389
|
+
? response.toString()
|
|
390
|
+
: '';
|
|
416
391
|
}
|
|
417
392
|
}
|
|
418
|
-
else if (
|
|
419
|
-
if (
|
|
420
|
-
|
|
421
|
-
|
|
393
|
+
else if (this.responseType === XMLHttpRequestResponseType.document) {
|
|
394
|
+
if (global.isIOS) {
|
|
395
|
+
let code = NSUTF8StringEncoding; // long:4
|
|
396
|
+
let encodedString = NSString.alloc().initWithDataEncoding(data, code);
|
|
422
397
|
// If UTF8 string encoding fails try with ISO-8859-1
|
|
423
398
|
if (!encodedString) {
|
|
424
399
|
code = NSISOLatin1StringEncoding; // long:5
|
|
425
400
|
encodedString = NSString.alloc().initWithDataEncoding(data, code);
|
|
426
401
|
}
|
|
427
|
-
|
|
402
|
+
this._responseText = this._response = encodedString.toString();
|
|
428
403
|
}
|
|
429
404
|
else {
|
|
430
|
-
|
|
431
|
-
|
|
405
|
+
let response = this._toJSString(data);
|
|
406
|
+
this._responseText = this._response = response
|
|
407
|
+
? response
|
|
408
|
+
: '';
|
|
432
409
|
}
|
|
433
410
|
}
|
|
434
|
-
else if (
|
|
435
|
-
if (
|
|
436
|
-
|
|
411
|
+
else if (this.responseType === XMLHttpRequestResponseType.arraybuffer) {
|
|
412
|
+
if (global.isIOS) {
|
|
413
|
+
this._response = interop.bufferFromData(data);
|
|
437
414
|
}
|
|
438
415
|
else {
|
|
439
|
-
|
|
416
|
+
this._response = ArrayBuffer.from(java.nio.ByteBuffer.wrap(data));
|
|
440
417
|
}
|
|
441
418
|
}
|
|
442
|
-
else if (
|
|
443
|
-
|
|
444
|
-
if (
|
|
419
|
+
else if (this.responseType === XMLHttpRequestResponseType.blob) {
|
|
420
|
+
let buffer;
|
|
421
|
+
if (global.isIOS) {
|
|
445
422
|
buffer = interop.bufferFromData(data);
|
|
446
423
|
}
|
|
447
424
|
else {
|
|
448
|
-
|
|
425
|
+
const buf = java.nio.ByteBuffer.wrap(data);
|
|
449
426
|
buffer = ArrayBuffer.from(buf);
|
|
450
427
|
}
|
|
451
|
-
|
|
428
|
+
this._response = new Blob([buffer]);
|
|
452
429
|
}
|
|
453
|
-
|
|
454
|
-
if (
|
|
430
|
+
let size = 0;
|
|
431
|
+
if (global.isIOS) {
|
|
455
432
|
if (data instanceof NSData) {
|
|
456
433
|
size = data.length;
|
|
457
434
|
}
|
|
@@ -459,73 +436,75 @@ var TNSXMLHttpRequest = /** @class */ (function () {
|
|
|
459
436
|
else {
|
|
460
437
|
size = data ? data.length : 0;
|
|
461
438
|
}
|
|
462
|
-
|
|
463
|
-
lengthComputable:
|
|
439
|
+
this._lastProgress = {
|
|
440
|
+
lengthComputable: contentLength > -1,
|
|
464
441
|
loaded: size,
|
|
465
|
-
total:
|
|
466
|
-
target:
|
|
442
|
+
total: contentLength,
|
|
443
|
+
target: this,
|
|
467
444
|
};
|
|
468
|
-
|
|
469
|
-
if (
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
if (
|
|
476
|
-
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
if (
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
|
|
445
|
+
const progressEvent = new ProgressEvent('progress', this._lastProgress);
|
|
446
|
+
if (this.onprogress) {
|
|
447
|
+
this.onprogress(progressEvent);
|
|
448
|
+
}
|
|
449
|
+
this.emitEvent('progress', progressEvent);
|
|
450
|
+
this._addToStringOnResponse();
|
|
451
|
+
const loadEvent = new ProgressEvent('load', this._lastProgress);
|
|
452
|
+
if (this.onload) {
|
|
453
|
+
this.onload(loadEvent);
|
|
454
|
+
}
|
|
455
|
+
this.emitEvent('load', loadEvent);
|
|
456
|
+
const loadendEvent = new ProgressEvent('loadend', this._lastProgress);
|
|
457
|
+
if (this.onloadend) {
|
|
458
|
+
this.onloadend(loadendEvent);
|
|
459
|
+
}
|
|
460
|
+
this.emitEvent('loadend', loadendEvent);
|
|
461
|
+
this._updateReadyStateChange(this.DONE);
|
|
485
462
|
}
|
|
486
463
|
});
|
|
487
464
|
return;
|
|
488
465
|
}
|
|
489
|
-
|
|
490
|
-
|
|
466
|
+
const method = this._request.method.toLowerCase();
|
|
467
|
+
const request = {
|
|
491
468
|
content: body,
|
|
492
469
|
method: this._request.method,
|
|
493
470
|
url: this._request.url,
|
|
494
471
|
headers: this._headers,
|
|
495
|
-
onLoading:
|
|
496
|
-
if (
|
|
497
|
-
|
|
472
|
+
onLoading: () => {
|
|
473
|
+
if (this.onloadstart) {
|
|
474
|
+
this.onloadstart();
|
|
498
475
|
}
|
|
499
|
-
|
|
500
|
-
if (typeof
|
|
501
|
-
if (
|
|
502
|
-
contentLength =
|
|
476
|
+
let contentLength = -1;
|
|
477
|
+
if (typeof this._headers === 'object') {
|
|
478
|
+
if (this._headers['Content-Length']) {
|
|
479
|
+
contentLength =
|
|
480
|
+
parseInt(this._headers['Content-Length'], 10) || -1;
|
|
503
481
|
}
|
|
504
|
-
if (
|
|
505
|
-
contentLength =
|
|
482
|
+
if (this._headers['content-length']) {
|
|
483
|
+
contentLength =
|
|
484
|
+
parseInt(this._headers['content-length'], 10) || -1;
|
|
506
485
|
}
|
|
507
486
|
}
|
|
508
|
-
|
|
487
|
+
this._lastProgress = {
|
|
509
488
|
lengthComputable: contentLength > -1,
|
|
510
489
|
loaded: 0,
|
|
511
490
|
total: contentLength,
|
|
512
|
-
target:
|
|
491
|
+
target: this,
|
|
513
492
|
};
|
|
514
|
-
|
|
515
|
-
if (
|
|
516
|
-
|
|
493
|
+
const loadStartEvent = new ProgressEvent('loadstart', this._lastProgress);
|
|
494
|
+
if (this._upload && (method === 'post' || method === 'put')) {
|
|
495
|
+
this._upload._emitEvent('loadstart', loadStartEvent);
|
|
517
496
|
}
|
|
518
|
-
|
|
519
|
-
|
|
497
|
+
this.emitEvent('loadstart', loadStartEvent);
|
|
498
|
+
this._updateReadyStateChange(this.LOADING);
|
|
520
499
|
},
|
|
521
|
-
onHeaders:
|
|
500
|
+
onHeaders: (event) => {
|
|
522
501
|
if (!isNaN(event.status)) {
|
|
523
|
-
|
|
502
|
+
this._status = event.status;
|
|
524
503
|
}
|
|
525
504
|
if (event.headers) {
|
|
526
|
-
|
|
505
|
+
this._headers = event.headers;
|
|
527
506
|
}
|
|
528
|
-
|
|
507
|
+
this._updateReadyStateChange(this.HEADERS_RECEIVED);
|
|
529
508
|
},
|
|
530
509
|
};
|
|
531
510
|
// TODO: ideally we could avoid wiring up progress since it's chatty
|
|
@@ -533,14 +512,14 @@ var TNSXMLHttpRequest = /** @class */ (function () {
|
|
|
533
512
|
// right now for brevity since GET requests are for more frequent than others,
|
|
534
513
|
// just enabling for post and put temporarily
|
|
535
514
|
if (method === 'post' || method === 'put') {
|
|
536
|
-
request.onProgress =
|
|
537
|
-
|
|
515
|
+
request.onProgress = (event) => {
|
|
516
|
+
this._lastProgress = Object.assign(Object.assign({}, (this._lastProgress || {})), event);
|
|
538
517
|
if (event.loaded > 0) {
|
|
539
|
-
|
|
540
|
-
if (
|
|
541
|
-
|
|
518
|
+
const progressEvent = new ProgressEvent('progress', this._lastProgress);
|
|
519
|
+
if (this._upload && (method === 'post' || method === 'put')) {
|
|
520
|
+
this._upload._emitEvent('progress', progressEvent);
|
|
542
521
|
}
|
|
543
|
-
|
|
522
|
+
this.emitEvent('progress', progressEvent);
|
|
544
523
|
}
|
|
545
524
|
};
|
|
546
525
|
}
|
|
@@ -549,388 +528,358 @@ var TNSXMLHttpRequest = /** @class */ (function () {
|
|
|
549
528
|
}
|
|
550
529
|
this._currentRequest = this._http.request(request);
|
|
551
530
|
this._currentRequest
|
|
552
|
-
.then(
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
531
|
+
.then((res) => {
|
|
532
|
+
if (!this._didUserSetResponseType) {
|
|
533
|
+
this._setResponseType();
|
|
534
|
+
}
|
|
535
|
+
this._status = res.statusCode;
|
|
536
|
+
this._httpContent = res.content;
|
|
537
|
+
this._responseURL = res.url;
|
|
538
|
+
if (this.responseType === XMLHttpRequestResponseType.json) {
|
|
558
539
|
if (typeof res.content === 'string') {
|
|
559
|
-
|
|
540
|
+
this._responseText = res.content;
|
|
560
541
|
try {
|
|
561
|
-
|
|
542
|
+
this._response = JSON.parse(this.responseText);
|
|
562
543
|
}
|
|
563
544
|
catch (err) {
|
|
564
545
|
// this should probably be caught before the promise resolves
|
|
565
546
|
}
|
|
566
547
|
}
|
|
567
548
|
else if (typeof res.content === 'object') {
|
|
568
|
-
|
|
569
|
-
|
|
549
|
+
this._response = res.content;
|
|
550
|
+
this._responseText = res.responseText;
|
|
570
551
|
}
|
|
571
552
|
else {
|
|
572
|
-
if (
|
|
553
|
+
if (global.isIOS) {
|
|
573
554
|
if (res.content instanceof NSData) {
|
|
574
|
-
|
|
575
|
-
|
|
555
|
+
let code = NSUTF8StringEncoding; // long:4
|
|
556
|
+
let encodedString = NSString.alloc().initWithDataEncoding(res.content, code);
|
|
576
557
|
// If UTF8 string encoding fails try with ISO-8859-1
|
|
577
558
|
if (!encodedString) {
|
|
578
559
|
code = NSISOLatin1StringEncoding; // long:5
|
|
579
560
|
encodedString = NSString.alloc().initWithDataEncoding(res.content, code);
|
|
580
561
|
}
|
|
581
|
-
|
|
582
|
-
|
|
562
|
+
this._responseText = encodedString.toString();
|
|
563
|
+
this._response = JSON.parse(this._responseText);
|
|
583
564
|
}
|
|
584
565
|
}
|
|
585
566
|
else {
|
|
586
567
|
if (res.content instanceof java.nio.ByteBuffer) {
|
|
587
|
-
|
|
588
|
-
|
|
568
|
+
this._responseText = this._toJSString(res.content.array());
|
|
569
|
+
this._response = JSON.parse(this._responseText);
|
|
589
570
|
}
|
|
590
571
|
}
|
|
591
572
|
}
|
|
592
573
|
}
|
|
593
|
-
else if (
|
|
574
|
+
else if (this.responseType === XMLHttpRequestResponseType.text) {
|
|
594
575
|
if (typeof res.content === 'string') {
|
|
595
|
-
|
|
576
|
+
this._responseText = res.content;
|
|
596
577
|
}
|
|
597
578
|
else if (typeof res.content === 'object') {
|
|
598
|
-
|
|
579
|
+
this._responseText = JSON.stringify(res.content); // Stringify or build manually 🧐
|
|
599
580
|
}
|
|
600
581
|
else {
|
|
601
|
-
if (
|
|
582
|
+
if (global.isIOS) {
|
|
602
583
|
if (res.content instanceof NSData) {
|
|
603
|
-
|
|
604
|
-
|
|
584
|
+
let code = NSUTF8StringEncoding; // long:4
|
|
585
|
+
let encodedString = NSString.alloc().initWithDataEncoding(res.content, code);
|
|
605
586
|
// If UTF8 string encoding fails try with ISO-8859-1
|
|
606
587
|
if (!encodedString) {
|
|
607
588
|
code = NSISOLatin1StringEncoding; // long:5
|
|
608
589
|
encodedString = NSString.alloc().initWithDataEncoding(res.content, code);
|
|
609
590
|
}
|
|
610
|
-
|
|
591
|
+
this._responseText = this._response = encodedString.toString();
|
|
611
592
|
}
|
|
612
593
|
}
|
|
613
594
|
else {
|
|
614
595
|
if (res.content instanceof java.nio.ByteBuffer) {
|
|
615
|
-
|
|
596
|
+
this._responseText = this._response = this._toJSString(res.content.array());
|
|
616
597
|
}
|
|
617
598
|
}
|
|
618
599
|
}
|
|
619
|
-
|
|
600
|
+
this._response = this._responseText;
|
|
620
601
|
}
|
|
621
|
-
else if (
|
|
602
|
+
else if (this.responseType === XMLHttpRequestResponseType.document) {
|
|
622
603
|
if (typeof res.content === 'string') {
|
|
623
|
-
|
|
604
|
+
this._responseText = res.content;
|
|
624
605
|
}
|
|
625
606
|
else {
|
|
626
|
-
if (
|
|
607
|
+
if (global.isIOS) {
|
|
627
608
|
if (res.content instanceof NSData) {
|
|
628
|
-
|
|
629
|
-
|
|
609
|
+
let code = NSUTF8StringEncoding; // long:4
|
|
610
|
+
let encodedString = NSString.alloc().initWithDataEncoding(res.content, code);
|
|
630
611
|
// If UTF8 string encoding fails try with ISO-8859-1
|
|
631
612
|
if (!encodedString) {
|
|
632
613
|
code = NSISOLatin1StringEncoding; // long:5
|
|
633
614
|
encodedString = NSString.alloc().initWithDataEncoding(res.content, code);
|
|
634
615
|
}
|
|
635
|
-
|
|
616
|
+
this._responseText = this._response = encodedString.toString();
|
|
636
617
|
}
|
|
637
618
|
}
|
|
638
619
|
else {
|
|
639
620
|
if (res.content instanceof java.nio.ByteBuffer) {
|
|
640
|
-
|
|
621
|
+
this._responseText = this._response = this._toJSString(res.content.array());
|
|
641
622
|
}
|
|
642
623
|
}
|
|
643
624
|
}
|
|
644
625
|
}
|
|
645
|
-
else if (
|
|
646
|
-
if (
|
|
647
|
-
|
|
626
|
+
else if (this.responseType === XMLHttpRequestResponseType.arraybuffer) {
|
|
627
|
+
if (global.isIOS) {
|
|
628
|
+
this._response = interop.bufferFromData(res.content);
|
|
648
629
|
}
|
|
649
630
|
else {
|
|
650
|
-
|
|
631
|
+
this._response = ArrayBuffer.from(res.content);
|
|
651
632
|
}
|
|
652
633
|
}
|
|
653
|
-
else if (
|
|
654
|
-
|
|
655
|
-
|
|
634
|
+
else if (this.responseType === XMLHttpRequestResponseType.blob) {
|
|
635
|
+
const buffer = ArrayBuffer.from(res.content);
|
|
636
|
+
this._response = new Blob([buffer]);
|
|
656
637
|
}
|
|
657
|
-
|
|
658
|
-
if (
|
|
659
|
-
|
|
638
|
+
this._addToStringOnResponse();
|
|
639
|
+
if (this.onload) {
|
|
640
|
+
this.onload();
|
|
660
641
|
}
|
|
661
|
-
|
|
662
|
-
if (
|
|
663
|
-
|
|
642
|
+
const loadEvent = new ProgressEvent('load', this._lastProgress);
|
|
643
|
+
if (this._upload && (method === 'post' || method === 'put')) {
|
|
644
|
+
this._upload._emitEvent('load', loadEvent);
|
|
664
645
|
}
|
|
665
|
-
|
|
666
|
-
if (
|
|
667
|
-
|
|
646
|
+
this.emitEvent('load', loadEvent);
|
|
647
|
+
if (this.onloadend) {
|
|
648
|
+
this.onloadend();
|
|
668
649
|
}
|
|
669
|
-
|
|
670
|
-
if (
|
|
671
|
-
|
|
650
|
+
const loadendEvent = new ProgressEvent('loadend', this._lastProgress);
|
|
651
|
+
if (this._upload && (method === 'post' || method === 'put')) {
|
|
652
|
+
this._upload._emitEvent('loadend', loadendEvent);
|
|
672
653
|
}
|
|
673
|
-
|
|
674
|
-
|
|
654
|
+
this.emitEvent('loadend', loadendEvent);
|
|
655
|
+
this._updateReadyStateChange(this.DONE);
|
|
675
656
|
})
|
|
676
|
-
.catch(
|
|
677
|
-
|
|
678
|
-
|
|
657
|
+
.catch((error) => {
|
|
658
|
+
const type = error.type;
|
|
659
|
+
const method = this._request.method.toLowerCase();
|
|
679
660
|
switch (type) {
|
|
680
|
-
case
|
|
681
|
-
if (
|
|
682
|
-
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
if (
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
661
|
+
case HttpError.Cancelled:
|
|
662
|
+
if (this.onabort) {
|
|
663
|
+
this.onabort();
|
|
664
|
+
}
|
|
665
|
+
const abortEvent = new ProgressEvent('abort', this._lastProgress);
|
|
666
|
+
if (this._upload &&
|
|
667
|
+
(method === 'post' || method === 'put')) {
|
|
668
|
+
this._upload._emitEvent('abort', abortEvent);
|
|
669
|
+
}
|
|
670
|
+
this.emitEvent('abort', abortEvent);
|
|
671
|
+
if (this.onloadend) {
|
|
672
|
+
this.onloadend();
|
|
673
|
+
}
|
|
674
|
+
const _loadendEvent = new ProgressEvent('loadend', this._lastProgress);
|
|
675
|
+
if (this._upload &&
|
|
676
|
+
(method === 'post' || method === 'put')) {
|
|
677
|
+
this._upload._emitEvent('loadend', _loadendEvent);
|
|
678
|
+
}
|
|
679
|
+
this.emitEvent('loadend', _loadendEvent);
|
|
680
|
+
if (this._readyState === this.UNSENT ||
|
|
681
|
+
this._readyState === this.OPENED ||
|
|
682
|
+
this._readyState === this.DONE) {
|
|
683
|
+
this._updateReadyStateChange(this.UNSENT);
|
|
699
684
|
}
|
|
700
685
|
else {
|
|
701
|
-
|
|
686
|
+
this._updateReadyStateChange(this.DONE);
|
|
702
687
|
}
|
|
703
|
-
|
|
688
|
+
this._currentRequest = null;
|
|
704
689
|
break;
|
|
705
|
-
case
|
|
706
|
-
if (
|
|
707
|
-
|
|
690
|
+
case HttpError.Timeout:
|
|
691
|
+
if (this.ontimeout) {
|
|
692
|
+
this.ontimeout();
|
|
708
693
|
}
|
|
709
|
-
|
|
710
|
-
if (
|
|
711
|
-
|
|
694
|
+
const timeoutEvent = new ProgressEvent('timeout', this._lastProgress);
|
|
695
|
+
if (this._upload &&
|
|
696
|
+
(method === 'post' || method === 'put')) {
|
|
697
|
+
this._upload._emitEvent('timeout', timeoutEvent);
|
|
712
698
|
}
|
|
713
|
-
|
|
699
|
+
this.emitEvent('timeout', timeoutEvent);
|
|
714
700
|
break;
|
|
715
|
-
case
|
|
716
|
-
if (
|
|
717
|
-
|
|
701
|
+
case HttpError.Error:
|
|
702
|
+
if (this.onerror) {
|
|
703
|
+
this.onerror(error.message);
|
|
718
704
|
}
|
|
719
|
-
|
|
720
|
-
if (
|
|
721
|
-
|
|
705
|
+
const errorEvent = new ProgressEvent('error', this._lastProgress);
|
|
706
|
+
if (this._upload &&
|
|
707
|
+
(method === 'post' || method === 'put')) {
|
|
708
|
+
this._upload._emitEvent('error', errorEvent);
|
|
722
709
|
}
|
|
723
|
-
|
|
724
|
-
if (
|
|
725
|
-
|
|
710
|
+
this.emitEvent('error', errorEvent);
|
|
711
|
+
if (this.onloadend) {
|
|
712
|
+
this.onloadend();
|
|
726
713
|
}
|
|
727
|
-
|
|
728
|
-
if (
|
|
729
|
-
|
|
714
|
+
const loadendEvent = new ProgressEvent('loadend', this._lastProgress);
|
|
715
|
+
if (this._upload &&
|
|
716
|
+
(method === 'post' || method === 'put')) {
|
|
717
|
+
this._upload._emitEvent('loadend', loadendEvent);
|
|
730
718
|
}
|
|
731
|
-
|
|
719
|
+
this.emitEvent('loadend', loadendEvent);
|
|
732
720
|
break;
|
|
733
721
|
}
|
|
734
|
-
|
|
722
|
+
this._updateReadyStateChange(this.DONE);
|
|
735
723
|
});
|
|
736
|
-
}
|
|
737
|
-
|
|
724
|
+
}
|
|
725
|
+
abort() {
|
|
738
726
|
if (this._currentRequest) {
|
|
739
727
|
this._currentRequest.cancel();
|
|
740
728
|
}
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
|
|
729
|
+
}
|
|
730
|
+
addEventListener(eventName, handler) {
|
|
731
|
+
const handlers = this._listeners.get(eventName) || [];
|
|
744
732
|
handlers.push(handler);
|
|
745
733
|
this._listeners.set(eventName, handlers);
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
handlers = handlers.filter(
|
|
734
|
+
}
|
|
735
|
+
removeEventListener(eventName, toDetach) {
|
|
736
|
+
let handlers = this._listeners.get(eventName) || [];
|
|
737
|
+
handlers = handlers.filter((handler) => handler !== toDetach);
|
|
750
738
|
this._listeners.set(eventName, handlers);
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
args[_i - 1] = arguments[_i];
|
|
757
|
-
}
|
|
758
|
-
var handlers = this._listeners.get(eventName) || [];
|
|
759
|
-
handlers.forEach(function (handler) {
|
|
760
|
-
handler.apply.apply(handler, [_this].concat(args));
|
|
739
|
+
}
|
|
740
|
+
emitEvent(eventName, ...args) {
|
|
741
|
+
const handlers = this._listeners.get(eventName) || [];
|
|
742
|
+
handlers.forEach((handler) => {
|
|
743
|
+
handler.apply(this, ...args);
|
|
761
744
|
});
|
|
762
|
-
}
|
|
763
|
-
|
|
745
|
+
}
|
|
746
|
+
dispatchEvent(event) {
|
|
764
747
|
return false;
|
|
765
|
-
}
|
|
766
|
-
|
|
748
|
+
}
|
|
749
|
+
_updateReadyStateChange(state) {
|
|
767
750
|
this._readyState = state;
|
|
768
751
|
if (this.onreadystatechange) {
|
|
769
752
|
this.onreadystatechange();
|
|
770
753
|
}
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
var FormData = /** @class */ (function () {
|
|
776
|
-
function FormData() {
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
export class FormData {
|
|
757
|
+
constructor() {
|
|
777
758
|
this._data = new Map();
|
|
778
759
|
}
|
|
779
|
-
|
|
760
|
+
append(name, value) {
|
|
780
761
|
this._data.set(name, value);
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
|
|
762
|
+
}
|
|
763
|
+
toString() {
|
|
764
|
+
let arr = new Array();
|
|
784
765
|
this._data.forEach(function (value, name, map) {
|
|
785
|
-
arr.push(encodeURIComponent(name)
|
|
766
|
+
arr.push(`${encodeURIComponent(name)}=${encodeURIComponent(value)}`);
|
|
786
767
|
});
|
|
787
|
-
return arr.join(
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
if (opts === void 0) { opts = {}; }
|
|
796
|
-
this[Symbol.toStringTag] = 'Blob';
|
|
797
|
-
var dataChunks = [];
|
|
798
|
-
for (var _i = 0, chunks_1 = chunks; _i < chunks_1.length; _i++) {
|
|
799
|
-
var chunk = chunks_1[_i];
|
|
768
|
+
return arr.join("&");
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
export class Blob {
|
|
772
|
+
constructor(chunks = [], opts = {}) {
|
|
773
|
+
this[_a] = "Blob";
|
|
774
|
+
const dataChunks = [];
|
|
775
|
+
for (const chunk of chunks) {
|
|
800
776
|
if (chunk instanceof Blob) {
|
|
801
777
|
dataChunks.push(chunk._buffer);
|
|
802
778
|
}
|
|
803
|
-
else if (typeof chunk ===
|
|
804
|
-
|
|
779
|
+
else if (typeof chunk === "string") {
|
|
780
|
+
const textEncoder = new TextEncoder();
|
|
805
781
|
dataChunks.push(textEncoder.encode(chunk));
|
|
806
782
|
}
|
|
807
783
|
else if (chunk instanceof DataView) {
|
|
808
784
|
dataChunks.push(new Uint8Array(chunk.buffer.slice(0)));
|
|
809
785
|
}
|
|
810
786
|
else if (chunk instanceof ArrayBuffer || ArrayBuffer.isView(chunk)) {
|
|
811
|
-
dataChunks.push(new Uint8Array(ArrayBuffer.isView(chunk)
|
|
787
|
+
dataChunks.push(new Uint8Array(ArrayBuffer.isView(chunk)
|
|
788
|
+
? chunk.buffer.slice(0)
|
|
789
|
+
: chunk.slice(0)));
|
|
812
790
|
}
|
|
813
791
|
else {
|
|
814
|
-
|
|
792
|
+
const textEncoder = new TextEncoder();
|
|
815
793
|
dataChunks.push(textEncoder.encode(String(chunk)));
|
|
816
794
|
}
|
|
817
795
|
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
for (
|
|
822
|
-
|
|
796
|
+
const size = dataChunks.reduce((size, chunk) => size + chunk.byteLength, 0);
|
|
797
|
+
const buffer = new Uint8Array(size);
|
|
798
|
+
let offset = 0;
|
|
799
|
+
for (let i = 0; i < dataChunks.length; i++) {
|
|
800
|
+
const chunk = dataChunks[i];
|
|
823
801
|
buffer.set(chunk, offset);
|
|
824
802
|
offset += chunk.byteLength;
|
|
825
803
|
}
|
|
826
804
|
this._buffer = buffer;
|
|
827
805
|
this._size = this._buffer.byteLength;
|
|
828
|
-
this._type = opts.type ||
|
|
806
|
+
this._type = opts.type || "";
|
|
829
807
|
if (/[^\u0020-\u007E]/.test(this._type)) {
|
|
830
|
-
this._type =
|
|
808
|
+
this._type = "";
|
|
831
809
|
}
|
|
832
810
|
else {
|
|
833
811
|
this._type = this._type.toLowerCase();
|
|
834
812
|
}
|
|
835
813
|
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
Object.defineProperty(Blob.prototype, "type", {
|
|
844
|
-
get: function () {
|
|
845
|
-
return this._type;
|
|
846
|
-
},
|
|
847
|
-
enumerable: true,
|
|
848
|
-
configurable: true
|
|
849
|
-
});
|
|
850
|
-
Blob.prototype.arrayBuffer = function () {
|
|
814
|
+
get size() {
|
|
815
|
+
return this._size;
|
|
816
|
+
}
|
|
817
|
+
get type() {
|
|
818
|
+
return this._type;
|
|
819
|
+
}
|
|
820
|
+
arrayBuffer() {
|
|
851
821
|
return Promise.resolve(this._buffer);
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
|
|
822
|
+
}
|
|
823
|
+
text() {
|
|
824
|
+
const textDecoder = new TextDecoder();
|
|
855
825
|
return Promise.resolve(textDecoder.decode(this._buffer));
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
|
|
826
|
+
}
|
|
827
|
+
slice(start, end, type) {
|
|
828
|
+
const slice = this._buffer.slice(start || 0, end || this._buffer.length);
|
|
859
829
|
return new Blob([slice], { type: type });
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
throw new Error(
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
return
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
return this._lastModified;
|
|
899
|
-
},
|
|
900
|
-
enumerable: true,
|
|
901
|
-
configurable: true
|
|
902
|
-
});
|
|
903
|
-
File.prototype.toString = function () {
|
|
904
|
-
return '[object File]';
|
|
905
|
-
};
|
|
906
|
-
return File;
|
|
907
|
-
}(Blob));
|
|
908
|
-
exports.File = File;
|
|
909
|
-
var FileReader = /** @class */ (function () {
|
|
910
|
-
function FileReader() {
|
|
830
|
+
}
|
|
831
|
+
stream() {
|
|
832
|
+
throw new Error("stream is currently not supported");
|
|
833
|
+
}
|
|
834
|
+
toString() {
|
|
835
|
+
return "[object Blob]";
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
_a = Symbol.toStringTag;
|
|
839
|
+
// Note: only for use by XHR
|
|
840
|
+
Blob.InternalAccessor = class {
|
|
841
|
+
static getBuffer(blob) {
|
|
842
|
+
return blob._buffer;
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
export class File extends Blob {
|
|
846
|
+
constructor(chunks, name, opts = {}) {
|
|
847
|
+
super(chunks, opts);
|
|
848
|
+
this[_b] = "File";
|
|
849
|
+
this._name = name.replace(/\//g, ":");
|
|
850
|
+
this._lastModified =
|
|
851
|
+
opts.lastModified
|
|
852
|
+
? new Date(opts.lastModified).valueOf()
|
|
853
|
+
: Date.now();
|
|
854
|
+
}
|
|
855
|
+
get name() {
|
|
856
|
+
return this._name;
|
|
857
|
+
}
|
|
858
|
+
get lastModified() {
|
|
859
|
+
return this._lastModified;
|
|
860
|
+
}
|
|
861
|
+
toString() {
|
|
862
|
+
return "[object File]";
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
_b = Symbol.toStringTag;
|
|
866
|
+
export class FileReader {
|
|
867
|
+
constructor() {
|
|
911
868
|
this.EMPTY = 0;
|
|
912
869
|
this.LOADING = 1;
|
|
913
870
|
this.DONE = 2;
|
|
914
871
|
this._listeners = new Map();
|
|
915
|
-
this[
|
|
872
|
+
this[_c] = "FileReader";
|
|
916
873
|
//
|
|
917
874
|
}
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
get: function () {
|
|
927
|
-
return this._result;
|
|
928
|
-
},
|
|
929
|
-
enumerable: true,
|
|
930
|
-
configurable: true
|
|
931
|
-
});
|
|
932
|
-
FileReader.prototype._array2base64 = function (input) {
|
|
933
|
-
var byteToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
875
|
+
get readyState() {
|
|
876
|
+
return this._readyState;
|
|
877
|
+
}
|
|
878
|
+
get result() {
|
|
879
|
+
return this._result;
|
|
880
|
+
}
|
|
881
|
+
_array2base64(input) {
|
|
882
|
+
var byteToCharMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
934
883
|
var output = [];
|
|
935
884
|
for (var i = 0; i < input.length; i += 3) {
|
|
936
885
|
var byte1 = input[i];
|
|
@@ -940,8 +889,8 @@ var FileReader = /** @class */ (function () {
|
|
|
940
889
|
var byte3 = haveByte3 ? input[i + 2] : 0;
|
|
941
890
|
var outByte1 = byte1 >> 2;
|
|
942
891
|
var outByte2 = ((byte1 & 0x03) << 4) | (byte2 >> 4);
|
|
943
|
-
var outByte3 = ((byte2 &
|
|
944
|
-
var outByte4 = byte3 &
|
|
892
|
+
var outByte3 = ((byte2 & 0x0F) << 2) | (byte3 >> 6);
|
|
893
|
+
var outByte4 = byte3 & 0x3F;
|
|
945
894
|
if (!haveByte3) {
|
|
946
895
|
outByte4 = 64;
|
|
947
896
|
if (!haveByte2) {
|
|
@@ -950,67 +899,60 @@ var FileReader = /** @class */ (function () {
|
|
|
950
899
|
}
|
|
951
900
|
output.push(byteToCharMap[outByte1], byteToCharMap[outByte2], byteToCharMap[outByte3], byteToCharMap[outByte4]);
|
|
952
901
|
}
|
|
953
|
-
return output.join(
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
var _this = this;
|
|
902
|
+
return output.join("");
|
|
903
|
+
}
|
|
904
|
+
_read(blob, kind) {
|
|
957
905
|
if (!(blob instanceof Blob)) {
|
|
958
|
-
throw new TypeError(
|
|
906
|
+
throw new TypeError(`Failed to execute '${kind}' on 'FileReader': parameter 1 is not of type 'Blob'.`);
|
|
959
907
|
}
|
|
960
|
-
this._result =
|
|
961
|
-
setTimeout(
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
908
|
+
this._result = "";
|
|
909
|
+
setTimeout(() => {
|
|
910
|
+
this._readyState = this.LOADING;
|
|
911
|
+
this.emitEvent("load");
|
|
912
|
+
this.emitEvent("loadend");
|
|
965
913
|
});
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
this['on' + eventName].apply(this, args);
|
|
975
|
-
}
|
|
976
|
-
var handlers = this._listeners.get(eventName) || [];
|
|
977
|
-
handlers.forEach(function (handler) {
|
|
978
|
-
handler.apply(void 0, [_this].concat(args));
|
|
914
|
+
}
|
|
915
|
+
emitEvent(eventName, ...args) {
|
|
916
|
+
if (isFunction(this["on" + eventName])) {
|
|
917
|
+
this["on" + eventName](...args);
|
|
918
|
+
}
|
|
919
|
+
let handlers = this._listeners.get(eventName) || [];
|
|
920
|
+
handlers.forEach((handler) => {
|
|
921
|
+
handler(this, ...args);
|
|
979
922
|
});
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
if ([
|
|
983
|
-
throw new Error(
|
|
923
|
+
}
|
|
924
|
+
addEventListener(eventName, handler) {
|
|
925
|
+
if (["abort", "error", "load", "loadend", "loadstart", "progress"].indexOf(eventName) === -1) {
|
|
926
|
+
throw new Error("Event not supported: " + eventName);
|
|
984
927
|
}
|
|
985
|
-
|
|
928
|
+
let handlers = this._listeners.get(eventName) || [];
|
|
986
929
|
handlers.push(handler);
|
|
987
930
|
this._listeners.set(eventName, handlers);
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
handlers = handlers.filter(
|
|
931
|
+
}
|
|
932
|
+
removeEventListener(eventName, toDetach) {
|
|
933
|
+
let handlers = this._listeners.get(eventName) || [];
|
|
934
|
+
handlers = handlers.filter((handler) => handler !== toDetach);
|
|
992
935
|
this._listeners.set(eventName, handlers);
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
this._read(blob,
|
|
996
|
-
this._result =
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
this._read(blob,
|
|
1000
|
-
|
|
936
|
+
}
|
|
937
|
+
readAsDataURL(blob) {
|
|
938
|
+
this._read(blob, "readAsDataURL");
|
|
939
|
+
this._result = `data:${blob.type};base64,${this._array2base64(Blob.InternalAccessor.getBuffer(blob))}`;
|
|
940
|
+
}
|
|
941
|
+
readAsText(blob) {
|
|
942
|
+
this._read(blob, "readAsText");
|
|
943
|
+
const textDecoder = new TextDecoder();
|
|
1001
944
|
this._result = textDecoder.decode(Blob.InternalAccessor.getBuffer(blob));
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
this._read(blob,
|
|
945
|
+
}
|
|
946
|
+
readAsArrayBuffer(blob) {
|
|
947
|
+
this._read(blob, "readAsArrayBuffer");
|
|
1005
948
|
this._result = Blob.InternalAccessor.getBuffer(blob).buffer.slice(0);
|
|
1006
|
-
}
|
|
1007
|
-
|
|
949
|
+
}
|
|
950
|
+
abort() {
|
|
1008
951
|
//
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
return
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
exports.FileReader = FileReader;
|
|
952
|
+
}
|
|
953
|
+
toString() {
|
|
954
|
+
return "[object FileReader]";
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
_c = Symbol.toStringTag;
|
|
1016
958
|
//# sourceMappingURL=TNSXMLHttpRequest.js.map
|