@nativescript/canvas-polyfill 1.0.0-beta.1 → 1.0.0-beta.13

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