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