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