@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.
Files changed (80) 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 +263 -0
  45. package/URL.android.js.map +1 -0
  46. package/URL.ios.d.ts +37 -0
  47. package/URL.ios.js +196 -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 +16 -24
  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 +472 -562
  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/async-release.aar +0 -0
  72. package/platforms/android/include.gradle +2 -2
  73. package/resize.js +8 -10
  74. package/resize.js.map +1 -1
  75. package/window.d.ts +1 -1
  76. package/window.js +57 -85
  77. package/window.js.map +1 -1
  78. package/URL.d.ts +0 -5
  79. package/URL.js +0 -46
  80. 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',
@@ -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,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 http_1.Http();
106
+ this._http = new Http();
114
107
  this._upload = new TNSXMLHttpRequestUpload(this);
115
108
  }
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
- }
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
- 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++) {
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
- TNSXMLHttpRequest.prototype._setResponseType = function () {
211
- var header = this.getResponseHeader('Content-Type') || this.getResponseHeader('content-type');
212
- var contentType = header && header.toLowerCase();
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
- TNSXMLHttpRequest.prototype.getAllResponseHeaders = function () {
176
+ }
177
+ getAllResponseHeaders() {
229
178
  if (this._readyState < 2) {
230
179
  return '';
231
180
  }
232
- var result = '';
181
+ let result = '';
233
182
  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];
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
- TNSXMLHttpRequest.prototype.getResponseHeader = function (header) {
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
- 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();
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
- TNSXMLHttpRequest.prototype.overrideMimeType = function (mime) { };
260
- TNSXMLHttpRequest.prototype._addToStringOnResponse = function () {
261
- var _this = this;
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 (types_1.isNullOrUndefined(this.response)) {
219
+ if (isNullOrUndefined(this.response)) {
265
220
  return;
266
221
  }
267
222
  if (this.response instanceof ArrayBuffer) {
268
223
  return;
269
224
  }
270
- if (types_1.isObject(this.response)) {
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: function () { return _this.responseText; },
230
+ value: () => this.responseText,
276
231
  });
277
232
  }
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];
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
- var encoding = java.nio.charset.Charset.forName(encodingType);
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
- 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; }
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: method,
308
- url: url,
309
- async: async,
310
- username: username,
311
- password: password,
261
+ method,
262
+ url,
263
+ async,
264
+ username,
265
+ password,
312
266
  };
313
267
  this._updateReadyStateChange(this.OPENED);
314
- };
315
- TNSXMLHttpRequest.prototype.setRequestHeader = function (header, value) {
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
- TNSXMLHttpRequest.prototype.send = function (body) {
324
- var _this = this;
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
- var path = void 0;
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 = core_1.path.join(core_1.knownFolders.currentApp().path, this._request.url.replace('~/', ''));
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
- 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;
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: contentLength_1 > -1,
306
+ lengthComputable: contentLength > -1,
351
307
  loaded: 0,
352
- total: contentLength_1,
308
+ total: contentLength,
353
309
  target: this,
354
310
  };
355
- var startEvent = new http_request_common_1.ProgressEvent('loadstart', this._lastProgress);
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
- file_1.FileManager.readFile(path, {}, function (error, data) {
317
+ FileManager.readFile(path, {}, (error, data) => {
362
318
  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);
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 (!_this.responseType) {
378
- _this._setResponseType();
379
- }
380
- _this._status = 200;
381
- _this._httpContent = data;
382
- _this._responseURL = responseURL_1;
383
- if (_this.responseType === XMLHttpRequestResponseType.json) {
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 (core_1.isAndroid) {
386
- _this._responseText = _this._toJSString(data);
387
- _this._response = JSON.parse(_this._responseText);
342
+ if (global.isAndroid) {
343
+ this._responseText = this._toJSString(data);
344
+ this._response = JSON.parse(this._responseText);
388
345
  }
389
346
  else {
390
- _this._responseText = NSString.alloc().initWithDataEncoding(data, NSUTF8StringEncoding);
391
- if (!_this._responseText) {
392
- _this._responseText = NSString.alloc().initWithDataEncoding(data, NSISOLatin1StringEncoding);
347
+ this._responseText = NSString.alloc().initWithDataEncoding(data, NSUTF8StringEncoding);
348
+ if (!this._responseText) {
349
+ this._responseText = NSString.alloc().initWithDataEncoding(data, NSISOLatin1StringEncoding);
393
350
  }
394
- _this._response = JSON.parse(_this._responseText);
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 (_this.responseType === XMLHttpRequestResponseType.text) {
403
- if (core_1.isIOS) {
404
- var code = NSUTF8StringEncoding; // long:4
405
- var encodedString = NSString.alloc().initWithDataEncoding(data, code);
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
- _this._responseText = _this._response = encodedString.toString();
368
+ this._responseText = this._response = encodedString.toString();
412
369
  }
413
370
  else {
414
- var response = _this._toJSString(data);
415
- _this._responseText = _this._response = response ? response.toString() : '';
371
+ const response = this._toJSString(data);
372
+ this._responseText = this._response = response ? response.toString() : '';
416
373
  }
417
374
  }
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);
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
- _this._responseText = _this._response = encodedString.toString();
384
+ this._responseText = this._response = encodedString.toString();
428
385
  }
429
386
  else {
430
- var response = _this._toJSString(data);
431
- _this._responseText = _this._response = response ? response : '';
387
+ let response = this._toJSString(data);
388
+ this._responseText = this._response = response ? response : '';
432
389
  }
433
390
  }
434
- else if (_this.responseType === XMLHttpRequestResponseType.arraybuffer) {
435
- if (core_1.isIOS) {
436
- _this._response = interop.bufferFromData(data);
391
+ else if (this.responseType === XMLHttpRequestResponseType.arraybuffer) {
392
+ if (global.isIOS) {
393
+ this._response = interop.bufferFromData(data);
437
394
  }
438
395
  else {
439
- _this._response = ArrayBuffer.from(java.nio.ByteBuffer.wrap(data));
396
+ this._response = ArrayBuffer.from(data);
397
+ size = data.byteLength;
440
398
  }
441
399
  }
442
- else if (_this.responseType === XMLHttpRequestResponseType.blob) {
443
- var buffer = void 0;
444
- if (core_1.isIOS) {
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
- var buf = java.nio.ByteBuffer.wrap(data);
449
- buffer = ArrayBuffer.from(buf);
406
+ buffer = ArrayBuffer.from(data);
407
+ size = buffer.byteLength;
450
408
  }
451
- _this._response = new Blob([buffer]);
409
+ this._response = new Blob([buffer]);
452
410
  }
453
- var size = 0;
454
- if (core_1.isIOS) {
455
- if (data instanceof NSData) {
456
- size = data.length;
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
- else {
460
- size = data ? data.length : 0;
461
- }
462
- _this._lastProgress = {
463
- lengthComputable: contentLength_1 > -1,
421
+ this._lastProgress = {
422
+ lengthComputable: contentLength > -1,
464
423
  loaded: size,
465
- total: contentLength_1,
466
- target: _this,
424
+ total: contentLength,
425
+ target: this,
467
426
  };
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);
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
- var method = this._request.method.toLowerCase();
490
- var request = {
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: function () {
496
- if (_this.onloadstart) {
497
- _this.onloadstart();
454
+ onLoading: () => {
455
+ if (this.onloadstart) {
456
+ this.onloadstart();
498
457
  }
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;
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 (_this._headers['content-length']) {
505
- contentLength = parseInt(_this._headers['content-length'], 10) || -1;
463
+ if (this._headers['content-length']) {
464
+ contentLength = parseInt(this._headers['content-length'], 10) || -1;
506
465
  }
507
466
  }
508
- _this._lastProgress = {
467
+ this._lastProgress = {
509
468
  lengthComputable: contentLength > -1,
510
469
  loaded: 0,
511
470
  total: contentLength,
512
- target: _this,
471
+ target: this,
513
472
  };
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);
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
- _this.emitEvent('loadstart', loadStartEvent);
519
- _this._updateReadyStateChange(_this.LOADING);
477
+ this.emitEvent('loadstart', loadStartEvent);
478
+ this._updateReadyStateChange(this.LOADING);
520
479
  },
521
- onHeaders: function (event) {
480
+ onHeaders: (event) => {
522
481
  if (!isNaN(event.status)) {
523
- _this._status = event.status;
482
+ this._status = event.status;
524
483
  }
525
484
  if (event.headers) {
526
- _this._headers = event.headers;
485
+ this._headers = event.headers;
527
486
  }
528
- _this._updateReadyStateChange(_this.HEADERS_RECEIVED);
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 = function (event) {
537
- _this._lastProgress = __assign({}, (_this._lastProgress || {}), event);
495
+ request.onProgress = (event) => {
496
+ this._lastProgress = Object.assign(Object.assign({}, (this._lastProgress || {})), event);
538
497
  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);
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
- _this.emitEvent('progress', progressEvent);
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(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) {
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
- _this._responseText = res.content;
520
+ this._responseText = res.content;
560
521
  try {
561
- _this._response = JSON.parse(_this.responseText);
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
- _this._response = res.content;
569
- _this._responseText = res.responseText;
529
+ this._response = res.content;
530
+ this._responseText = res.responseText;
570
531
  }
571
532
  else {
572
- if (core_1.isIOS) {
533
+ if (global.isIOS) {
573
534
  if (res.content instanceof NSData) {
574
- var code = NSUTF8StringEncoding; // long:4
575
- var encodedString = NSString.alloc().initWithDataEncoding(res.content, code);
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
- _this._responseText = encodedString.toString();
582
- _this._response = JSON.parse(_this._responseText);
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
- _this._responseText = _this._toJSString(res.content.array());
588
- _this._response = JSON.parse(_this._responseText);
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 (_this.responseType === XMLHttpRequestResponseType.text) {
554
+ else if (this.responseType === XMLHttpRequestResponseType.text) {
594
555
  if (typeof res.content === 'string') {
595
- _this._responseText = res.content;
556
+ this._responseText = res.content;
596
557
  }
597
558
  else if (typeof res.content === 'object') {
598
- _this._responseText = JSON.stringify(res.content); // Stringify or build manually 🧐
559
+ this._responseText = JSON.stringify(res.content); // Stringify or build manually 🧐
599
560
  }
600
561
  else {
601
- if (core_1.isIOS) {
562
+ if (global.isIOS) {
602
563
  if (res.content instanceof NSData) {
603
- var code = NSUTF8StringEncoding; // long:4
604
- var encodedString = NSString.alloc().initWithDataEncoding(res.content, code);
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
- _this._responseText = _this._response = encodedString.toString();
571
+ this._responseText = this._response = encodedString.toString();
611
572
  }
612
573
  }
613
574
  else {
614
575
  if (res.content instanceof java.nio.ByteBuffer) {
615
- _this._responseText = _this._response = _this._toJSString(res.content.array());
576
+ this._responseText = this._response = this._toJSString(res.content.array());
616
577
  }
617
578
  }
618
579
  }
619
- _this._response = _this._responseText;
580
+ this._response = this._responseText;
620
581
  }
621
- else if (_this.responseType === XMLHttpRequestResponseType.document) {
582
+ else if (this.responseType === XMLHttpRequestResponseType.document) {
622
583
  if (typeof res.content === 'string') {
623
- _this._responseText = res.content;
584
+ this._responseText = res.content;
624
585
  }
625
586
  else {
626
- if (core_1.isIOS) {
587
+ if (global.isIOS) {
627
588
  if (res.content instanceof NSData) {
628
- var code = NSUTF8StringEncoding; // long:4
629
- var encodedString = NSString.alloc().initWithDataEncoding(res.content, code);
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
- _this._responseText = _this._response = encodedString.toString();
596
+ this._responseText = this._response = encodedString.toString();
636
597
  }
637
598
  }
638
599
  else {
639
600
  if (res.content instanceof java.nio.ByteBuffer) {
640
- _this._responseText = _this._response = _this._toJSString(res.content.array());
601
+ this._responseText = this._response = this._toJSString(res.content.array());
641
602
  }
642
603
  }
643
604
  }
644
605
  }
645
- else if (_this.responseType === XMLHttpRequestResponseType.arraybuffer) {
646
- if (core_1.isIOS) {
647
- _this._response = interop.bufferFromData(res.content);
606
+ else if (this.responseType === XMLHttpRequestResponseType.arraybuffer) {
607
+ if (global.isIOS) {
608
+ this._response = interop.bufferFromData(res.content);
648
609
  }
649
610
  else {
650
- _this._response = ArrayBuffer.from(res.content);
611
+ this._response = ArrayBuffer.from(res.content);
651
612
  }
652
613
  }
653
- else if (_this.responseType === XMLHttpRequestResponseType.blob) {
654
- var buffer = ArrayBuffer.from(res.content);
655
- _this._response = new Blob([buffer]);
614
+ else if (this.responseType === XMLHttpRequestResponseType.blob) {
615
+ const buffer = ArrayBuffer.from(res.content);
616
+ this._response = new Blob([buffer]);
656
617
  }
657
- _this._addToStringOnResponse();
658
- if (_this.onload) {
659
- _this.onload();
618
+ this._addToStringOnResponse();
619
+ if (this.onload) {
620
+ this.onload();
660
621
  }
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);
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
- _this.emitEvent('load', loadEvent);
666
- if (_this.onloadend) {
667
- _this.onloadend();
626
+ this.emitEvent('load', loadEvent);
627
+ if (this.onloadend) {
628
+ this.onloadend();
668
629
  }
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);
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
- _this.emitEvent('loadend', loadendEvent);
674
- _this._updateReadyStateChange(_this.DONE);
634
+ this.emitEvent('loadend', loadendEvent);
635
+ this._updateReadyStateChange(this.DONE);
675
636
  })
676
- .catch(function (error) {
677
- var type = error.type;
678
- var method = _this._request.method.toLowerCase();
637
+ .catch((error) => {
638
+ const type = error.type;
639
+ const method = this._request.method.toLowerCase();
679
640
  switch (type) {
680
- case http_request_common_1.HttpError.Cancelled:
681
- if (_this.onabort) {
682
- _this.onabort();
641
+ case HttpError.Cancelled:
642
+ if (this.onabort) {
643
+ this.onabort();
683
644
  }
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);
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
- _this.emitEvent('abort', abortEvent);
689
- if (_this.onloadend) {
690
- _this.onloadend();
649
+ this.emitEvent('abort', abortEvent);
650
+ if (this.onloadend) {
651
+ this.onloadend();
691
652
  }
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);
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
- _this.emitEvent('loadend', _loadendEvent);
697
- if (_this._readyState === _this.UNSENT || _this._readyState === _this.OPENED || _this._readyState === _this.DONE) {
698
- _this._updateReadyStateChange(_this.UNSENT);
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
- _this._updateReadyStateChange(_this.DONE);
662
+ this._updateReadyStateChange(this.DONE);
702
663
  }
703
- _this._currentRequest = null;
664
+ this._currentRequest = null;
704
665
  break;
705
- case http_request_common_1.HttpError.Timeout:
706
- if (_this.ontimeout) {
707
- _this.ontimeout();
666
+ case HttpError.Timeout:
667
+ if (this.ontimeout) {
668
+ this.ontimeout();
708
669
  }
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);
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
- _this.emitEvent('timeout', timeoutEvent);
674
+ this.emitEvent('timeout', timeoutEvent);
714
675
  break;
715
- case http_request_common_1.HttpError.Error:
716
- if (_this.onerror) {
717
- _this.onerror(error.message);
676
+ case HttpError.Error:
677
+ if (this.onerror) {
678
+ this.onerror(error.message);
718
679
  }
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);
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
- _this.emitEvent('error', errorEvent);
724
- if (_this.onloadend) {
725
- _this.onloadend();
684
+ this.emitEvent('error', errorEvent);
685
+ if (this.onloadend) {
686
+ this.onloadend();
726
687
  }
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);
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
- _this.emitEvent('loadend', loadendEvent);
692
+ this.emitEvent('loadend', loadendEvent);
732
693
  break;
733
694
  }
734
- _this._updateReadyStateChange(_this.DONE);
695
+ this._updateReadyStateChange(this.DONE);
735
696
  });
736
- };
737
- TNSXMLHttpRequest.prototype.abort = function () {
697
+ }
698
+ abort() {
738
699
  if (this._currentRequest) {
739
700
  this._currentRequest.cancel();
740
701
  }
741
- };
742
- TNSXMLHttpRequest.prototype.addEventListener = function (eventName, handler) {
743
- var handlers = this._listeners.get(eventName) || [];
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
- TNSXMLHttpRequest.prototype.removeEventListener = function (eventName, toDetach) {
748
- var handlers = this._listeners.get(eventName) || [];
749
- handlers = handlers.filter(function (handler) { return handler !== toDetach; });
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
- 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));
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
- TNSXMLHttpRequest.prototype.dispatchEvent = function (event) {
718
+ }
719
+ dispatchEvent(event) {
764
720
  return false;
765
- };
766
- TNSXMLHttpRequest.prototype._updateReadyStateChange = function (state) {
721
+ }
722
+ _updateReadyStateChange(state) {
767
723
  this._readyState = state;
768
724
  if (this.onreadystatechange) {
769
725
  this.onreadystatechange();
770
726
  }
771
- };
772
- return TNSXMLHttpRequest;
773
- }());
774
- exports.TNSXMLHttpRequest = TNSXMLHttpRequest;
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
- FormData.prototype.append = function (name, value) {
733
+ append(name, value) {
780
734
  this._data.set(name, value);
781
- };
782
- FormData.prototype.toString = function () {
783
- var arr = new Array();
735
+ }
736
+ toString() {
737
+ let arr = new Array();
784
738
  this._data.forEach(function (value, name, map) {
785
- arr.push(encodeURIComponent(name) + "=" + encodeURIComponent(value));
739
+ arr.push(`${encodeURIComponent(name)}=${encodeURIComponent(value)}`);
786
740
  });
787
741
  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];
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
- var textEncoder = new TextEncoder();
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
- var textEncoder = new TextEncoder();
763
+ const textEncoder = new TextEncoder();
815
764
  dataChunks.push(textEncoder.encode(String(chunk)));
816
765
  }
817
766
  }
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];
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
- 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 () {
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
- Blob.prototype.text = function () {
854
- var textDecoder = new TextDecoder();
793
+ }
794
+ text() {
795
+ const textDecoder = new TextDecoder();
855
796
  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);
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
- Blob.prototype.stream = function () {
801
+ }
802
+ stream() {
862
803
  throw new Error('stream is currently not supported');
863
- };
864
- Blob.prototype.toString = function () {
804
+ }
805
+ toString() {
865
806
  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 () {
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
- return File;
907
- }(Blob));
908
- exports.File = File;
909
- var FileReader = /** @class */ (function () {
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[Symbol.toStringTag] = 'FileReader';
840
+ this[_c] = 'FileReader';
916
841
  //
917
842
  }
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) {
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
- FileReader.prototype._read = function (blob, kind) {
956
- var _this = this;
871
+ }
872
+ _read(blob, kind) {
957
873
  if (!(blob instanceof Blob)) {
958
- throw new TypeError("Failed to execute '" + kind + "' on 'FileReader': parameter 1 is not of type 'Blob'.");
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(function () {
962
- _this._readyState = _this.LOADING;
963
- _this.emitEvent('load');
964
- _this.emitEvent('loadend');
877
+ setTimeout(() => {
878
+ this._readyState = this.LOADING;
879
+ this.emitEvent('load');
880
+ this.emitEvent('loadend');
965
881
  });
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));
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
- FileReader.prototype.addEventListener = function (eventName, handler) {
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
- var handlers = this._listeners.get(eventName) || [];
896
+ let handlers = this._listeners.get(eventName) || [];
986
897
  handlers.push(handler);
987
898
  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; });
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
- FileReader.prototype.readAsDataURL = function (blob) {
904
+ }
905
+ readAsDataURL(blob) {
995
906
  this._read(blob, 'readAsDataURL');
996
- this._result = "data:" + blob.type + ";base64," + this._array2base64(Blob.InternalAccessor.getBuffer(blob));
997
- };
998
- FileReader.prototype.readAsText = function (blob) {
907
+ this._result = `data:${blob.type};base64,${this._array2base64(Blob.InternalAccessor.getBuffer(blob))}`;
908
+ }
909
+ readAsText(blob) {
999
910
  this._read(blob, 'readAsText');
1000
- var textDecoder = new TextDecoder();
911
+ const textDecoder = new TextDecoder();
1001
912
  this._result = textDecoder.decode(Blob.InternalAccessor.getBuffer(blob));
1002
- };
1003
- FileReader.prototype.readAsArrayBuffer = function (blob) {
913
+ }
914
+ readAsArrayBuffer(blob) {
1004
915
  this._read(blob, 'readAsArrayBuffer');
1005
916
  this._result = Blob.InternalAccessor.getBuffer(blob).buffer.slice(0);
1006
- };
1007
- FileReader.prototype.abort = function () {
917
+ }
918
+ abort() {
1008
919
  //
1009
- };
1010
- FileReader.prototype.toString = function () {
920
+ }
921
+ toString() {
1011
922
  return '[object FileReader]';
1012
- };
1013
- return FileReader;
1014
- }());
1015
- exports.FileReader = FileReader;
923
+ }
924
+ }
925
+ _c = Symbol.toStringTag;
1016
926
  //# sourceMappingURL=TNSXMLHttpRequest.js.map