@nativescript/canvas-polyfill 1.0.14-v6 → 1.1.0-alpha.0

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