@nativescript/core 9.0.12-next.4 → 9.0.12-next.6

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.
@@ -0,0 +1,535 @@
1
+ "use strict";
2
+
3
+ var support = {
4
+ searchParams: "URLSearchParams" in global,
5
+ iterable: "Symbol" in global && "iterator" in Symbol,
6
+ blob:
7
+ "FileReader" in global &&
8
+ "Blob" in global &&
9
+ (function () {
10
+ try {
11
+ new Blob();
12
+ return true;
13
+ } catch (e) {
14
+ return false;
15
+ }
16
+ })(),
17
+ formData: "FormData" in global,
18
+ arrayBuffer: "ArrayBuffer" in global
19
+ };
20
+
21
+ function isDataView(obj) {
22
+ return obj && DataView.prototype.isPrototypeOf(obj);
23
+ }
24
+
25
+ if (support.arrayBuffer) {
26
+ var viewClasses = [
27
+ "[object Int8Array]",
28
+ "[object Uint8Array]",
29
+ "[object Uint8ClampedArray]",
30
+ "[object Int16Array]",
31
+ "[object Uint16Array]",
32
+ "[object Int32Array]",
33
+ "[object Uint32Array]",
34
+ "[object Float32Array]",
35
+ "[object Float64Array]"
36
+ ];
37
+
38
+ var isArrayBufferView =
39
+ ArrayBuffer.isView ||
40
+ function (obj) {
41
+ return (
42
+ obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
43
+ );
44
+ };
45
+ }
46
+
47
+ function normalizeName(name) {
48
+ if (typeof name !== "string") {
49
+ name = String(name);
50
+ }
51
+ if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) {
52
+ throw new TypeError("Invalid character in header field name");
53
+ }
54
+ return name.toLowerCase();
55
+ }
56
+
57
+ function normalizeValue(value) {
58
+ if (typeof value !== "string") {
59
+ value = String(value);
60
+ }
61
+ return value;
62
+ }
63
+
64
+ // Build a destructive iterator for the value list
65
+ function iteratorFor(items) {
66
+ var iterator = {
67
+ next: function () {
68
+ var value = items.shift();
69
+ return { done: value === undefined, value: value };
70
+ }
71
+ };
72
+
73
+ if (support.iterable) {
74
+ iterator[Symbol.iterator] = function () {
75
+ return iterator;
76
+ };
77
+ }
78
+
79
+ return iterator;
80
+ }
81
+
82
+ function Headers(headers) {
83
+ this.map = {};
84
+
85
+ if (headers instanceof Headers) {
86
+ headers.forEach(function (value, name) {
87
+ this.append(name, value);
88
+ }, this);
89
+ } else if (Array.isArray(headers)) {
90
+ headers.forEach(function (header) {
91
+ this.append(header[0], header[1]);
92
+ }, this);
93
+ } else if (headers) {
94
+ Object.getOwnPropertyNames(headers).forEach(function (name) {
95
+ this.append(name, headers[name]);
96
+ }, this);
97
+ }
98
+ }
99
+
100
+ Headers.prototype.append = function (name, value) {
101
+ name = normalizeName(name);
102
+ value = normalizeValue(value);
103
+ var oldValue = this.map[name];
104
+ this.map[name] = oldValue ? oldValue + ", " + value : value;
105
+ };
106
+
107
+ Headers.prototype["delete"] = function (name) {
108
+ delete this.map[normalizeName(name)];
109
+ };
110
+
111
+ Headers.prototype.get = function (name) {
112
+ name = normalizeName(name);
113
+ return this.has(name) ? this.map[name] : null;
114
+ };
115
+
116
+ Headers.prototype.has = function (name) {
117
+ return this.map.hasOwnProperty(normalizeName(name));
118
+ };
119
+
120
+ Headers.prototype.set = function (name, value) {
121
+ this.map[normalizeName(name)] = normalizeValue(value);
122
+ };
123
+
124
+ Headers.prototype.forEach = function (callback, thisArg) {
125
+ for (var name in this.map) {
126
+ if (this.map.hasOwnProperty(name)) {
127
+ callback.call(thisArg, this.map[name], name, this);
128
+ }
129
+ }
130
+ };
131
+
132
+ Headers.prototype.keys = function () {
133
+ var items = [];
134
+ this.forEach(function (value, name) {
135
+ items.push(name);
136
+ });
137
+ return iteratorFor(items);
138
+ };
139
+
140
+ Headers.prototype.values = function () {
141
+ var items = [];
142
+ this.forEach(function (value) {
143
+ items.push(value);
144
+ });
145
+ return iteratorFor(items);
146
+ };
147
+
148
+ Headers.prototype.entries = function () {
149
+ var items = [];
150
+ this.forEach(function (value, name) {
151
+ items.push([name, value]);
152
+ });
153
+ return iteratorFor(items);
154
+ };
155
+
156
+ if (support.iterable) {
157
+ Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
158
+ }
159
+
160
+ function consumed(body) {
161
+ if (body.bodyUsed) {
162
+ return Promise.reject(new TypeError("Already read"));
163
+ }
164
+ body.bodyUsed = true;
165
+ }
166
+
167
+ function fileReaderReady(reader) {
168
+ return new Promise(function (resolve, reject) {
169
+ reader.onload = function () {
170
+ resolve(reader.result);
171
+ };
172
+ reader.onerror = function () {
173
+ reject(reader.error);
174
+ };
175
+ });
176
+ }
177
+
178
+ function readBlobAsArrayBuffer(blob) {
179
+ var reader = new FileReader();
180
+ var promise = fileReaderReady(reader);
181
+ reader.readAsArrayBuffer(blob);
182
+ return promise;
183
+ }
184
+
185
+ function readBlobAsText(blob) {
186
+ var reader = new FileReader();
187
+ var promise = fileReaderReady(reader);
188
+ reader.readAsText(blob);
189
+ return promise;
190
+ }
191
+
192
+ function readArrayBufferAsText(buf) {
193
+ var view = new Uint8Array(buf);
194
+ var chars = new Array(view.length);
195
+
196
+ for (var i = 0; i < view.length; i++) {
197
+ chars[i] = String.fromCharCode(view[i]);
198
+ }
199
+ return chars.join("");
200
+ }
201
+
202
+ function bufferClone(buf) {
203
+ if (buf.slice) {
204
+ return buf.slice(0);
205
+ } else {
206
+ var view = new Uint8Array(buf.byteLength);
207
+ view.set(new Uint8Array(buf));
208
+ return view.buffer;
209
+ }
210
+ }
211
+
212
+ function Body() {
213
+ this.bodyUsed = false;
214
+
215
+ this._initBody = function (body) {
216
+ this._bodyInit = body;
217
+ if (!body) {
218
+ this._bodyText = "";
219
+ } else if (typeof body === "string") {
220
+ this._bodyText = body;
221
+ } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
222
+ this._bodyBlob = body;
223
+ } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
224
+ this._bodyFormData = body;
225
+ } else if (
226
+ support.searchParams &&
227
+ URLSearchParams.prototype.isPrototypeOf(body)
228
+ ) {
229
+ this._bodyText = body.toString();
230
+ } else if (support.arrayBuffer && support.blob && isDataView(body)) {
231
+ this._bodyArrayBuffer = bufferClone(body.buffer);
232
+ // IE 10-11 can't handle a DataView body.
233
+ this._bodyInit = new Blob([this._bodyArrayBuffer]);
234
+ } else if (
235
+ support.arrayBuffer &&
236
+ (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))
237
+ ) {
238
+ this._bodyArrayBuffer = bufferClone(body);
239
+ } else {
240
+ this._bodyText = body = Object.prototype.toString.call(body);
241
+ }
242
+
243
+ if (!this.headers.get("content-type")) {
244
+ if (typeof body === "string") {
245
+ this.headers.set("content-type", "text/plain;charset=UTF-8");
246
+ } else if (this._bodyBlob && this._bodyBlob.type) {
247
+ this.headers.set("content-type", this._bodyBlob.type);
248
+ } else if (
249
+ support.searchParams &&
250
+ URLSearchParams.prototype.isPrototypeOf(body)
251
+ ) {
252
+ this.headers.set(
253
+ "content-type",
254
+ "application/x-www-form-urlencoded;charset=UTF-8"
255
+ );
256
+ }
257
+ }
258
+ };
259
+
260
+ if (support.blob) {
261
+ this.blob = function () {
262
+ var rejected = consumed(this);
263
+ if (rejected) {
264
+ return rejected;
265
+ }
266
+
267
+ if (this._bodyBlob) {
268
+ return Promise.resolve(this._bodyBlob);
269
+ } else if (this._bodyArrayBuffer) {
270
+ return Promise.resolve(new Blob([this._bodyArrayBuffer]));
271
+ } else if (this._bodyFormData) {
272
+ throw new Error("could not read FormData body as blob");
273
+ } else {
274
+ return Promise.resolve(new Blob([this._bodyText]));
275
+ }
276
+ };
277
+
278
+ this.arrayBuffer = function () {
279
+ if (this._bodyArrayBuffer) {
280
+ return consumed(this) || Promise.resolve(this._bodyArrayBuffer);
281
+ } else {
282
+ return this.blob().then(readBlobAsArrayBuffer);
283
+ }
284
+ };
285
+ }
286
+
287
+ this.text = function () {
288
+ var rejected = consumed(this);
289
+ if (rejected) {
290
+ return rejected;
291
+ }
292
+
293
+ if (this._bodyBlob) {
294
+ return readBlobAsText(this._bodyBlob);
295
+ } else if (this._bodyArrayBuffer) {
296
+ return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer));
297
+ } else if (this._bodyFormData) {
298
+ throw new Error("could not read FormData body as text");
299
+ } else {
300
+ return Promise.resolve(this._bodyText);
301
+ }
302
+ };
303
+
304
+ if (support.formData) {
305
+ this.formData = function () {
306
+ return this.text().then(decode);
307
+ };
308
+ }
309
+
310
+ this.json = function () {
311
+ return this.text().then(JSON.parse);
312
+ };
313
+
314
+ return this;
315
+ }
316
+
317
+ // HTTP methods whose capitalization should be normalized
318
+ var methods = ["DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT"];
319
+
320
+ function normalizeMethod(method) {
321
+ var upcased = method.toUpperCase();
322
+ return methods.indexOf(upcased) > -1 ? upcased : method;
323
+ }
324
+
325
+ function Request(input, options) {
326
+ options = options || {};
327
+ var body = options.body;
328
+
329
+ if (input instanceof Request) {
330
+ if (input.bodyUsed) {
331
+ throw new TypeError("Already read");
332
+ }
333
+ this.url = input.url;
334
+ this.credentials = input.credentials;
335
+ if (!options.headers) {
336
+ this.headers = new Headers(input.headers);
337
+ }
338
+ this.method = input.method;
339
+ this.mode = input.mode;
340
+ this.signal = input.signal;
341
+ if (!body && input._bodyInit != null) {
342
+ body = input._bodyInit;
343
+ input.bodyUsed = true;
344
+ }
345
+ } else {
346
+ this.url = String(input);
347
+ }
348
+
349
+ this.credentials = options.credentials || this.credentials || "same-origin";
350
+ if (options.headers || !this.headers) {
351
+ this.headers = new Headers(options.headers);
352
+ }
353
+ this.method = normalizeMethod(options.method || this.method || "GET");
354
+ this.mode = options.mode || this.mode || null;
355
+ this.signal = options.signal || this.signal;
356
+ this.referrer = null;
357
+
358
+ if ((this.method === "GET" || this.method === "HEAD") && body) {
359
+ throw new TypeError("Body not allowed for GET or HEAD requests");
360
+ }
361
+ this._initBody(body);
362
+ }
363
+
364
+ Request.prototype.clone = function () {
365
+ return new Request(this, { body: this._bodyInit });
366
+ };
367
+
368
+ function decode(body) {
369
+ var form = new FormData();
370
+ body
371
+ .trim()
372
+ .split("&")
373
+ .forEach(function (bytes) {
374
+ if (bytes) {
375
+ var split = bytes.split("=");
376
+ var name = split.shift().replace(/\+/g, " ");
377
+ var value = split.join("=").replace(/\+/g, " ");
378
+ form.append(decodeURIComponent(name), decodeURIComponent(value));
379
+ }
380
+ });
381
+ return form;
382
+ }
383
+
384
+ function parseHeaders(rawHeaders) {
385
+ var headers = new Headers();
386
+ // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
387
+ // https://tools.ietf.org/html/rfc7230#section-3.2
388
+ var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, " ");
389
+ preProcessedHeaders.split(/\r?\n/).forEach(function (line) {
390
+ var parts = line.split(":");
391
+ var key = parts.shift().trim();
392
+ if (key) {
393
+ var value = parts.join(":").trim();
394
+ headers.append(key, value);
395
+ }
396
+ });
397
+ return headers;
398
+ }
399
+
400
+ Body.call(Request.prototype);
401
+
402
+ function Response(bodyInit, options) {
403
+ if (!options) {
404
+ options = {};
405
+ }
406
+
407
+ this.type = "default";
408
+ this.status = options.status === undefined ? 200 : options.status;
409
+ this.ok = this.status >= 200 && this.status < 300;
410
+ this.statusText = "statusText" in options ? options.statusText : "OK";
411
+ this.headers = new Headers(options.headers);
412
+ this.url = options.url || "";
413
+ this._initBody(bodyInit);
414
+ }
415
+
416
+ Body.call(Response.prototype);
417
+
418
+ Response.prototype.clone = function () {
419
+ return new Response(this._bodyInit, {
420
+ status: this.status,
421
+ statusText: this.statusText,
422
+ headers: new Headers(this.headers),
423
+ url: this.url
424
+ });
425
+ };
426
+
427
+ Response.error = function () {
428
+ var response = new Response(null, { status: 0, statusText: "" });
429
+ response.type = "error";
430
+ return response;
431
+ };
432
+
433
+ var redirectStatuses = [301, 302, 303, 307, 308];
434
+
435
+ Response.redirect = function (url, status) {
436
+ if (redirectStatuses.indexOf(status) === -1) {
437
+ throw new RangeError("Invalid status code");
438
+ }
439
+
440
+ return new Response(null, { status: status, headers: { location: url } });
441
+ };
442
+
443
+ export let DOMException = global.DOMException;
444
+ try {
445
+ new DOMException();
446
+ } catch (err) {
447
+ DOMException = function (message, name) {
448
+ this.message = message;
449
+ this.name = name;
450
+ var error = Error(message);
451
+ this.stack = error.stack;
452
+ };
453
+ DOMException.prototype = Object.create(Error.prototype);
454
+ DOMException.prototype.constructor = DOMException;
455
+ }
456
+
457
+ function fetch(input, init) {
458
+ return new Promise(function (resolve, reject) {
459
+ var request = new Request(input, init);
460
+
461
+ if (request.signal && request.signal.aborted) {
462
+ return reject(new exports.DOMException("Aborted", "AbortError"));
463
+ }
464
+
465
+ var xhr = new XMLHttpRequest();
466
+
467
+ function abortXhr() {
468
+ xhr.abort();
469
+ }
470
+
471
+ xhr.onload = function () {
472
+ var options = {
473
+ status: xhr.status,
474
+ statusText: xhr.statusText,
475
+ headers: parseHeaders(xhr.getAllResponseHeaders() || "")
476
+ };
477
+ options.url =
478
+ "responseURL" in xhr
479
+ ? xhr.responseURL
480
+ : options.headers.get("X-Request-URL");
481
+ var body = "response" in xhr ? xhr.response : xhr.responseText;
482
+ resolve(new Response(body, options));
483
+ };
484
+
485
+ xhr.onerror = function () {
486
+ reject(new TypeError("Network request failed"));
487
+ };
488
+
489
+ xhr.ontimeout = function () {
490
+ reject(new TypeError("Network request failed"));
491
+ };
492
+
493
+ xhr.onabort = function () {
494
+ reject(new exports.DOMException("Aborted", "AbortError"));
495
+ };
496
+
497
+ xhr.open(request.method, request.url, true);
498
+
499
+ if (request.credentials === "include") {
500
+ xhr.withCredentials = true;
501
+ } else if (request.credentials === "omit") {
502
+ xhr.withCredentials = false;
503
+ }
504
+
505
+ if ("responseType" in xhr && support.blob) {
506
+ xhr.responseType = "blob";
507
+ }
508
+
509
+ request.headers.forEach(function (value, name) {
510
+ xhr.setRequestHeader(name, value);
511
+ });
512
+
513
+ if (request.signal) {
514
+ request.signal.addEventListener("abort", abortXhr);
515
+
516
+ xhr.onreadystatechange = function () {
517
+ // DONE (success or failure)
518
+ if (xhr.readyState === 4) {
519
+ request.signal.removeEventListener("abort", abortXhr);
520
+ }
521
+ };
522
+ }
523
+
524
+ xhr.send(
525
+ typeof request._bodyInit === "undefined" ? null : request._bodyInit
526
+ );
527
+ });
528
+ }
529
+
530
+ fetch.polyfill = true;
531
+
532
+ export { Headers };
533
+ export { Request };
534
+ export { Response };
535
+ export { fetch };
@@ -1,3 +1,3 @@
1
- import '../fetch';
1
+ import './polyfills/polyfill-xhr';
2
2
  export declare function installPolyfills(moduleName: string, exportNames: string[]): void;
3
3
  import '../application';
package/globals/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import tslib from 'tslib';
2
+ import { installPolyfillsFromModule } from './polyfills/utils';
3
+ import './polyfills/polyfill-xhr';
2
4
  import * as timer from '../timer';
3
5
  import * as animationFrame from '../animation-frame';
4
6
  import * as mediaQueryList from '../media-query-list';
5
7
  import * as text from '../text';
6
- import * as xhrImpl from '../xhr';
7
- import '../fetch';
8
- import * as fetchPolyfill from '../fetch';
8
+ import * as fetchPolyfill from '../fetch/index.mjs';
9
9
  import * as wgc from '../wgc';
10
10
  import * as cryptoImpl from '../wgc/crypto';
11
11
  import * as subtleCryptoImpl from '../wgc/crypto/SubtleCrypto';
@@ -222,6 +222,10 @@ global.loadModule = function loadModule(name) {
222
222
  return null;
223
223
  };
224
224
  function registerOnGlobalContext(moduleName, exportName) {
225
+ if (global[exportName]) {
226
+ // already registered
227
+ return;
228
+ }
225
229
  Object.defineProperty(global, exportName, {
226
230
  get: function () {
227
231
  // We do not need to cache require() call since it is already cached in the runtime.
@@ -241,7 +245,7 @@ function registerOnGlobalContext(moduleName, exportName) {
241
245
  export function installPolyfills(moduleName, exportNames) {
242
246
  if (global.__snapshot) {
243
247
  const loadedModule = global.loadModule(moduleName);
244
- exportNames.forEach((exportName) => (global[exportName] = loadedModule[exportName]));
248
+ installPolyfillsFromModule(loadedModule, exportNames);
245
249
  }
246
250
  else {
247
251
  exportNames.forEach((exportName) => registerOnGlobalContext(moduleName, exportName));
@@ -250,61 +254,26 @@ export function installPolyfills(moduleName, exportNames) {
250
254
  if (!global.NativeScriptHasPolyfilled) {
251
255
  global.NativeScriptHasPolyfilled = true;
252
256
  // console.log('Installing polyfills...');
253
- // DOM api polyfills
254
- const glb = global;
255
- if (__COMMONJS__) {
256
- global.registerModule('timer', () => timer);
257
- installPolyfills('timer', ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval']);
258
- global.registerModule('animation', () => animationFrame);
259
- installPolyfills('animation', ['requestAnimationFrame', 'cancelAnimationFrame']);
260
- global.registerModule('media-query-list', () => mediaQueryList);
261
- installPolyfills('media-query-list', ['matchMedia', 'MediaQueryList']);
262
- global.registerModule('text', () => text);
263
- installPolyfills('text', ['TextDecoder', 'TextEncoder']);
264
- global.registerModule('xhr', () => xhrImpl);
265
- installPolyfills('xhr', ['XMLHttpRequest', 'FormData', 'Blob', 'File', 'FileReader']);
266
- global.registerModule('fetch', () => fetchPolyfill);
267
- installPolyfills('fetch', ['fetch', 'Headers', 'Request', 'Response']);
268
- global.registerModule('wgc', () => wgc);
269
- installPolyfills('wgc', ['atob', 'btoa']);
270
- global.registerModule('crypto', () => cryptoImpl);
271
- installPolyfills('crypto', ['Crypto']);
272
- global.registerModule('subtle', () => subtleCryptoImpl);
273
- installPolyfills('subtle-crypto', ['Subtle']);
274
- }
275
- else {
276
- // timers
277
- glb.setTimeout = timer.setTimeout;
278
- glb.clearTimeout = timer.clearTimeout;
279
- glb.setInterval = timer.setInterval;
280
- glb.clearInterval = timer.clearInterval;
281
- // animation frame
282
- glb.requestAnimationFrame = animationFrame.requestAnimationFrame;
283
- glb.cancelAnimationFrame = animationFrame.cancelAnimationFrame;
284
- // media query list
285
- glb.matchMedia = mediaQueryList.matchMedia;
286
- glb.MediaQueryList = mediaQueryList.MediaQueryList;
287
- // text
288
- glb.TextDecoder = text.TextDecoder;
289
- glb.TextEncoder = text.TextEncoder;
290
- // xhr
291
- glb.XMLHttpRequest = xhrImpl.XMLHttpRequest;
292
- glb.FormData = xhrImpl.FormData;
293
- glb.Blob = xhrImpl.Blob;
294
- glb.File = xhrImpl.File;
295
- glb.FileReader = xhrImpl.FileReader;
296
- // fetch
297
- glb.fetch = fetchPolyfill.fetch;
298
- glb.Headers = fetchPolyfill.Headers;
299
- glb.Request = fetchPolyfill.Request;
300
- glb.Response = fetchPolyfill.Response;
301
- // wgc
302
- glb.atob = wgc.atob;
303
- glb.btoa = wgc.btoa;
304
- // wgc
305
- glb.SubtleCrypto = subtleCryptoImpl.SubtleCrypto;
306
- }
307
- glb.crypto = new cryptoImpl.Crypto();
257
+ global.registerModule('timer', () => timer);
258
+ installPolyfills('timer', ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval']);
259
+ global.registerModule('animation', () => animationFrame);
260
+ installPolyfills('animation', ['requestAnimationFrame', 'cancelAnimationFrame']);
261
+ global.registerModule('media-query-list', () => mediaQueryList);
262
+ installPolyfills('media-query-list', ['matchMedia', 'MediaQueryList']);
263
+ global.registerModule('text', () => text);
264
+ installPolyfills('text', ['TextDecoder', 'TextEncoder']);
265
+ // TODO: fix this. This is currently being polyfilled by the polyfill-xhr.ts
266
+ // global.registerModule('xhr', () => xhrImpl);
267
+ // installPolyfills('xhr', ['XMLHttpRequest', 'FormData', 'Blob', 'File', 'FileReader']);
268
+ global.registerModule('fetch', () => fetchPolyfill);
269
+ installPolyfills('fetch', ['fetch', 'Headers', 'Request', 'Response']);
270
+ global.registerModule('wgc', () => wgc);
271
+ installPolyfills('wgc', ['atob', 'btoa']);
272
+ global.registerModule('crypto', () => cryptoImpl);
273
+ installPolyfills('crypto', ['Crypto']);
274
+ global.registerModule('subtle', () => subtleCryptoImpl);
275
+ installPolyfills('subtle', ['SubtleCrypto']);
276
+ global.crypto = new cryptoImpl.Crypto();
308
277
  // global.registerModule('abortcontroller', () => require('../abortcontroller'));
309
278
  // installPolyfills('abortcontroller', ['AbortController', 'AbortSignal']);
310
279
  }