@novx/i18n 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.esm.js ADDED
@@ -0,0 +1,3465 @@
1
+ import { injectable, LRUCache, StringBuilder } from '@novx/core';
2
+
3
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
4
+
5
+ /*! *****************************************************************************
6
+ Copyright (C) Microsoft. All rights reserved.
7
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
8
+ this file except in compliance with the License. You may obtain a copy of the
9
+ License at http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
12
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
13
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
14
+ MERCHANTABLITY OR NON-INFRINGEMENT.
15
+
16
+ See the Apache Version 2.0 License for specific language governing permissions
17
+ and limitations under the License.
18
+ ***************************************************************************** */
19
+
20
+ var Reflect$1;
21
+ (function (Reflect) {
22
+ // Metadata Proposal
23
+ // https://rbuckton.github.io/reflect-metadata/
24
+ (function (factory) {
25
+ var root = typeof globalThis === "object" ? globalThis :
26
+ typeof commonjsGlobal === "object" ? commonjsGlobal :
27
+ typeof self === "object" ? self :
28
+ typeof this === "object" ? this :
29
+ sloppyModeThis();
30
+ var exporter = makeExporter(Reflect);
31
+ if (typeof root.Reflect !== "undefined") {
32
+ exporter = makeExporter(root.Reflect, exporter);
33
+ }
34
+ factory(exporter, root);
35
+ if (typeof root.Reflect === "undefined") {
36
+ root.Reflect = Reflect;
37
+ }
38
+ function makeExporter(target, previous) {
39
+ return function (key, value) {
40
+ Object.defineProperty(target, key, { configurable: true, writable: true, value: value });
41
+ if (previous)
42
+ previous(key, value);
43
+ };
44
+ }
45
+ function functionThis() {
46
+ try {
47
+ return Function("return this;")();
48
+ }
49
+ catch (_) { }
50
+ }
51
+ function indirectEvalThis() {
52
+ try {
53
+ return (void 0, eval)("(function() { return this; })()");
54
+ }
55
+ catch (_) { }
56
+ }
57
+ function sloppyModeThis() {
58
+ return functionThis() || indirectEvalThis();
59
+ }
60
+ })(function (exporter, root) {
61
+ var hasOwn = Object.prototype.hasOwnProperty;
62
+ // feature test for Symbol support
63
+ var supportsSymbol = typeof Symbol === "function";
64
+ var toPrimitiveSymbol = supportsSymbol && typeof Symbol.toPrimitive !== "undefined" ? Symbol.toPrimitive : "@@toPrimitive";
65
+ var iteratorSymbol = supportsSymbol && typeof Symbol.iterator !== "undefined" ? Symbol.iterator : "@@iterator";
66
+ var supportsCreate = typeof Object.create === "function"; // feature test for Object.create support
67
+ var supportsProto = { __proto__: [] } instanceof Array; // feature test for __proto__ support
68
+ var downLevel = !supportsCreate && !supportsProto;
69
+ var HashMap = {
70
+ // create an object in dictionary mode (a.k.a. "slow" mode in v8)
71
+ create: supportsCreate
72
+ ? function () { return MakeDictionary(Object.create(null)); }
73
+ : supportsProto
74
+ ? function () { return MakeDictionary({ __proto__: null }); }
75
+ : function () { return MakeDictionary({}); },
76
+ has: downLevel
77
+ ? function (map, key) { return hasOwn.call(map, key); }
78
+ : function (map, key) { return key in map; },
79
+ get: downLevel
80
+ ? function (map, key) { return hasOwn.call(map, key) ? map[key] : undefined; }
81
+ : function (map, key) { return map[key]; },
82
+ };
83
+ // Load global or shim versions of Map, Set, and WeakMap
84
+ var functionPrototype = Object.getPrototypeOf(Function);
85
+ var _Map = typeof Map === "function" && typeof Map.prototype.entries === "function" ? Map : CreateMapPolyfill();
86
+ var _Set = typeof Set === "function" && typeof Set.prototype.entries === "function" ? Set : CreateSetPolyfill();
87
+ var _WeakMap = typeof WeakMap === "function" ? WeakMap : CreateWeakMapPolyfill();
88
+ var registrySymbol = supportsSymbol ? Symbol.for("@reflect-metadata:registry") : undefined;
89
+ var metadataRegistry = GetOrCreateMetadataRegistry();
90
+ var metadataProvider = CreateMetadataProvider(metadataRegistry);
91
+ /**
92
+ * Applies a set of decorators to a property of a target object.
93
+ * @param decorators An array of decorators.
94
+ * @param target The target object.
95
+ * @param propertyKey (Optional) The property key to decorate.
96
+ * @param attributes (Optional) The property descriptor for the target key.
97
+ * @remarks Decorators are applied in reverse order.
98
+ * @example
99
+ *
100
+ * class Example {
101
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
102
+ * // static staticProperty;
103
+ * // property;
104
+ *
105
+ * constructor(p) { }
106
+ * static staticMethod(p) { }
107
+ * method(p) { }
108
+ * }
109
+ *
110
+ * // constructor
111
+ * Example = Reflect.decorate(decoratorsArray, Example);
112
+ *
113
+ * // property (on constructor)
114
+ * Reflect.decorate(decoratorsArray, Example, "staticProperty");
115
+ *
116
+ * // property (on prototype)
117
+ * Reflect.decorate(decoratorsArray, Example.prototype, "property");
118
+ *
119
+ * // method (on constructor)
120
+ * Object.defineProperty(Example, "staticMethod",
121
+ * Reflect.decorate(decoratorsArray, Example, "staticMethod",
122
+ * Object.getOwnPropertyDescriptor(Example, "staticMethod")));
123
+ *
124
+ * // method (on prototype)
125
+ * Object.defineProperty(Example.prototype, "method",
126
+ * Reflect.decorate(decoratorsArray, Example.prototype, "method",
127
+ * Object.getOwnPropertyDescriptor(Example.prototype, "method")));
128
+ *
129
+ */
130
+ function decorate(decorators, target, propertyKey, attributes) {
131
+ if (!IsUndefined(propertyKey)) {
132
+ if (!IsArray(decorators))
133
+ throw new TypeError();
134
+ if (!IsObject(target))
135
+ throw new TypeError();
136
+ if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes))
137
+ throw new TypeError();
138
+ if (IsNull(attributes))
139
+ attributes = undefined;
140
+ propertyKey = ToPropertyKey(propertyKey);
141
+ return DecorateProperty(decorators, target, propertyKey, attributes);
142
+ }
143
+ else {
144
+ if (!IsArray(decorators))
145
+ throw new TypeError();
146
+ if (!IsConstructor(target))
147
+ throw new TypeError();
148
+ return DecorateConstructor(decorators, target);
149
+ }
150
+ }
151
+ exporter("decorate", decorate);
152
+ // 4.1.2 Reflect.metadata(metadataKey, metadataValue)
153
+ // https://rbuckton.github.io/reflect-metadata/#reflect.metadata
154
+ /**
155
+ * A default metadata decorator factory that can be used on a class, class member, or parameter.
156
+ * @param metadataKey The key for the metadata entry.
157
+ * @param metadataValue The value for the metadata entry.
158
+ * @returns A decorator function.
159
+ * @remarks
160
+ * If `metadataKey` is already defined for the target and target key, the
161
+ * metadataValue for that key will be overwritten.
162
+ * @example
163
+ *
164
+ * // constructor
165
+ * @Reflect.metadata(key, value)
166
+ * class Example {
167
+ * }
168
+ *
169
+ * // property (on constructor, TypeScript only)
170
+ * class Example {
171
+ * @Reflect.metadata(key, value)
172
+ * static staticProperty;
173
+ * }
174
+ *
175
+ * // property (on prototype, TypeScript only)
176
+ * class Example {
177
+ * @Reflect.metadata(key, value)
178
+ * property;
179
+ * }
180
+ *
181
+ * // method (on constructor)
182
+ * class Example {
183
+ * @Reflect.metadata(key, value)
184
+ * static staticMethod() { }
185
+ * }
186
+ *
187
+ * // method (on prototype)
188
+ * class Example {
189
+ * @Reflect.metadata(key, value)
190
+ * method() { }
191
+ * }
192
+ *
193
+ */
194
+ function metadata(metadataKey, metadataValue) {
195
+ function decorator(target, propertyKey) {
196
+ if (!IsObject(target))
197
+ throw new TypeError();
198
+ if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey))
199
+ throw new TypeError();
200
+ OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
201
+ }
202
+ return decorator;
203
+ }
204
+ exporter("metadata", metadata);
205
+ /**
206
+ * Define a unique metadata entry on the target.
207
+ * @param metadataKey A key used to store and retrieve metadata.
208
+ * @param metadataValue A value that contains attached metadata.
209
+ * @param target The target object on which to define metadata.
210
+ * @param propertyKey (Optional) The property key for the target.
211
+ * @example
212
+ *
213
+ * class Example {
214
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
215
+ * // static staticProperty;
216
+ * // property;
217
+ *
218
+ * constructor(p) { }
219
+ * static staticMethod(p) { }
220
+ * method(p) { }
221
+ * }
222
+ *
223
+ * // constructor
224
+ * Reflect.defineMetadata("custom:annotation", options, Example);
225
+ *
226
+ * // property (on constructor)
227
+ * Reflect.defineMetadata("custom:annotation", options, Example, "staticProperty");
228
+ *
229
+ * // property (on prototype)
230
+ * Reflect.defineMetadata("custom:annotation", options, Example.prototype, "property");
231
+ *
232
+ * // method (on constructor)
233
+ * Reflect.defineMetadata("custom:annotation", options, Example, "staticMethod");
234
+ *
235
+ * // method (on prototype)
236
+ * Reflect.defineMetadata("custom:annotation", options, Example.prototype, "method");
237
+ *
238
+ * // decorator factory as metadata-producing annotation.
239
+ * function MyAnnotation(options): Decorator {
240
+ * return (target, key?) => Reflect.defineMetadata("custom:annotation", options, target, key);
241
+ * }
242
+ *
243
+ */
244
+ function defineMetadata(metadataKey, metadataValue, target, propertyKey) {
245
+ if (!IsObject(target))
246
+ throw new TypeError();
247
+ if (!IsUndefined(propertyKey))
248
+ propertyKey = ToPropertyKey(propertyKey);
249
+ return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
250
+ }
251
+ exporter("defineMetadata", defineMetadata);
252
+ /**
253
+ * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.
254
+ * @param metadataKey A key used to store and retrieve metadata.
255
+ * @param target The target object on which the metadata is defined.
256
+ * @param propertyKey (Optional) The property key for the target.
257
+ * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.
258
+ * @example
259
+ *
260
+ * class Example {
261
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
262
+ * // static staticProperty;
263
+ * // property;
264
+ *
265
+ * constructor(p) { }
266
+ * static staticMethod(p) { }
267
+ * method(p) { }
268
+ * }
269
+ *
270
+ * // constructor
271
+ * result = Reflect.hasMetadata("custom:annotation", Example);
272
+ *
273
+ * // property (on constructor)
274
+ * result = Reflect.hasMetadata("custom:annotation", Example, "staticProperty");
275
+ *
276
+ * // property (on prototype)
277
+ * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "property");
278
+ *
279
+ * // method (on constructor)
280
+ * result = Reflect.hasMetadata("custom:annotation", Example, "staticMethod");
281
+ *
282
+ * // method (on prototype)
283
+ * result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method");
284
+ *
285
+ */
286
+ function hasMetadata(metadataKey, target, propertyKey) {
287
+ if (!IsObject(target))
288
+ throw new TypeError();
289
+ if (!IsUndefined(propertyKey))
290
+ propertyKey = ToPropertyKey(propertyKey);
291
+ return OrdinaryHasMetadata(metadataKey, target, propertyKey);
292
+ }
293
+ exporter("hasMetadata", hasMetadata);
294
+ /**
295
+ * Gets a value indicating whether the target object has the provided metadata key defined.
296
+ * @param metadataKey A key used to store and retrieve metadata.
297
+ * @param target The target object on which the metadata is defined.
298
+ * @param propertyKey (Optional) The property key for the target.
299
+ * @returns `true` if the metadata key was defined on the target object; otherwise, `false`.
300
+ * @example
301
+ *
302
+ * class Example {
303
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
304
+ * // static staticProperty;
305
+ * // property;
306
+ *
307
+ * constructor(p) { }
308
+ * static staticMethod(p) { }
309
+ * method(p) { }
310
+ * }
311
+ *
312
+ * // constructor
313
+ * result = Reflect.hasOwnMetadata("custom:annotation", Example);
314
+ *
315
+ * // property (on constructor)
316
+ * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticProperty");
317
+ *
318
+ * // property (on prototype)
319
+ * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "property");
320
+ *
321
+ * // method (on constructor)
322
+ * result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticMethod");
323
+ *
324
+ * // method (on prototype)
325
+ * result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method");
326
+ *
327
+ */
328
+ function hasOwnMetadata(metadataKey, target, propertyKey) {
329
+ if (!IsObject(target))
330
+ throw new TypeError();
331
+ if (!IsUndefined(propertyKey))
332
+ propertyKey = ToPropertyKey(propertyKey);
333
+ return OrdinaryHasOwnMetadata(metadataKey, target, propertyKey);
334
+ }
335
+ exporter("hasOwnMetadata", hasOwnMetadata);
336
+ /**
337
+ * Gets the metadata value for the provided metadata key on the target object or its prototype chain.
338
+ * @param metadataKey A key used to store and retrieve metadata.
339
+ * @param target The target object on which the metadata is defined.
340
+ * @param propertyKey (Optional) The property key for the target.
341
+ * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
342
+ * @example
343
+ *
344
+ * class Example {
345
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
346
+ * // static staticProperty;
347
+ * // property;
348
+ *
349
+ * constructor(p) { }
350
+ * static staticMethod(p) { }
351
+ * method(p) { }
352
+ * }
353
+ *
354
+ * // constructor
355
+ * result = Reflect.getMetadata("custom:annotation", Example);
356
+ *
357
+ * // property (on constructor)
358
+ * result = Reflect.getMetadata("custom:annotation", Example, "staticProperty");
359
+ *
360
+ * // property (on prototype)
361
+ * result = Reflect.getMetadata("custom:annotation", Example.prototype, "property");
362
+ *
363
+ * // method (on constructor)
364
+ * result = Reflect.getMetadata("custom:annotation", Example, "staticMethod");
365
+ *
366
+ * // method (on prototype)
367
+ * result = Reflect.getMetadata("custom:annotation", Example.prototype, "method");
368
+ *
369
+ */
370
+ function getMetadata(metadataKey, target, propertyKey) {
371
+ if (!IsObject(target))
372
+ throw new TypeError();
373
+ if (!IsUndefined(propertyKey))
374
+ propertyKey = ToPropertyKey(propertyKey);
375
+ return OrdinaryGetMetadata(metadataKey, target, propertyKey);
376
+ }
377
+ exporter("getMetadata", getMetadata);
378
+ /**
379
+ * Gets the metadata value for the provided metadata key on the target object.
380
+ * @param metadataKey A key used to store and retrieve metadata.
381
+ * @param target The target object on which the metadata is defined.
382
+ * @param propertyKey (Optional) The property key for the target.
383
+ * @returns The metadata value for the metadata key if found; otherwise, `undefined`.
384
+ * @example
385
+ *
386
+ * class Example {
387
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
388
+ * // static staticProperty;
389
+ * // property;
390
+ *
391
+ * constructor(p) { }
392
+ * static staticMethod(p) { }
393
+ * method(p) { }
394
+ * }
395
+ *
396
+ * // constructor
397
+ * result = Reflect.getOwnMetadata("custom:annotation", Example);
398
+ *
399
+ * // property (on constructor)
400
+ * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticProperty");
401
+ *
402
+ * // property (on prototype)
403
+ * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "property");
404
+ *
405
+ * // method (on constructor)
406
+ * result = Reflect.getOwnMetadata("custom:annotation", Example, "staticMethod");
407
+ *
408
+ * // method (on prototype)
409
+ * result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method");
410
+ *
411
+ */
412
+ function getOwnMetadata(metadataKey, target, propertyKey) {
413
+ if (!IsObject(target))
414
+ throw new TypeError();
415
+ if (!IsUndefined(propertyKey))
416
+ propertyKey = ToPropertyKey(propertyKey);
417
+ return OrdinaryGetOwnMetadata(metadataKey, target, propertyKey);
418
+ }
419
+ exporter("getOwnMetadata", getOwnMetadata);
420
+ /**
421
+ * Gets the metadata keys defined on the target object or its prototype chain.
422
+ * @param target The target object on which the metadata is defined.
423
+ * @param propertyKey (Optional) The property key for the target.
424
+ * @returns An array of unique metadata keys.
425
+ * @example
426
+ *
427
+ * class Example {
428
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
429
+ * // static staticProperty;
430
+ * // property;
431
+ *
432
+ * constructor(p) { }
433
+ * static staticMethod(p) { }
434
+ * method(p) { }
435
+ * }
436
+ *
437
+ * // constructor
438
+ * result = Reflect.getMetadataKeys(Example);
439
+ *
440
+ * // property (on constructor)
441
+ * result = Reflect.getMetadataKeys(Example, "staticProperty");
442
+ *
443
+ * // property (on prototype)
444
+ * result = Reflect.getMetadataKeys(Example.prototype, "property");
445
+ *
446
+ * // method (on constructor)
447
+ * result = Reflect.getMetadataKeys(Example, "staticMethod");
448
+ *
449
+ * // method (on prototype)
450
+ * result = Reflect.getMetadataKeys(Example.prototype, "method");
451
+ *
452
+ */
453
+ function getMetadataKeys(target, propertyKey) {
454
+ if (!IsObject(target))
455
+ throw new TypeError();
456
+ if (!IsUndefined(propertyKey))
457
+ propertyKey = ToPropertyKey(propertyKey);
458
+ return OrdinaryMetadataKeys(target, propertyKey);
459
+ }
460
+ exporter("getMetadataKeys", getMetadataKeys);
461
+ /**
462
+ * Gets the unique metadata keys defined on the target object.
463
+ * @param target The target object on which the metadata is defined.
464
+ * @param propertyKey (Optional) The property key for the target.
465
+ * @returns An array of unique metadata keys.
466
+ * @example
467
+ *
468
+ * class Example {
469
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
470
+ * // static staticProperty;
471
+ * // property;
472
+ *
473
+ * constructor(p) { }
474
+ * static staticMethod(p) { }
475
+ * method(p) { }
476
+ * }
477
+ *
478
+ * // constructor
479
+ * result = Reflect.getOwnMetadataKeys(Example);
480
+ *
481
+ * // property (on constructor)
482
+ * result = Reflect.getOwnMetadataKeys(Example, "staticProperty");
483
+ *
484
+ * // property (on prototype)
485
+ * result = Reflect.getOwnMetadataKeys(Example.prototype, "property");
486
+ *
487
+ * // method (on constructor)
488
+ * result = Reflect.getOwnMetadataKeys(Example, "staticMethod");
489
+ *
490
+ * // method (on prototype)
491
+ * result = Reflect.getOwnMetadataKeys(Example.prototype, "method");
492
+ *
493
+ */
494
+ function getOwnMetadataKeys(target, propertyKey) {
495
+ if (!IsObject(target))
496
+ throw new TypeError();
497
+ if (!IsUndefined(propertyKey))
498
+ propertyKey = ToPropertyKey(propertyKey);
499
+ return OrdinaryOwnMetadataKeys(target, propertyKey);
500
+ }
501
+ exporter("getOwnMetadataKeys", getOwnMetadataKeys);
502
+ /**
503
+ * Deletes the metadata entry from the target object with the provided key.
504
+ * @param metadataKey A key used to store and retrieve metadata.
505
+ * @param target The target object on which the metadata is defined.
506
+ * @param propertyKey (Optional) The property key for the target.
507
+ * @returns `true` if the metadata entry was found and deleted; otherwise, false.
508
+ * @example
509
+ *
510
+ * class Example {
511
+ * // property declarations are not part of ES6, though they are valid in TypeScript:
512
+ * // static staticProperty;
513
+ * // property;
514
+ *
515
+ * constructor(p) { }
516
+ * static staticMethod(p) { }
517
+ * method(p) { }
518
+ * }
519
+ *
520
+ * // constructor
521
+ * result = Reflect.deleteMetadata("custom:annotation", Example);
522
+ *
523
+ * // property (on constructor)
524
+ * result = Reflect.deleteMetadata("custom:annotation", Example, "staticProperty");
525
+ *
526
+ * // property (on prototype)
527
+ * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "property");
528
+ *
529
+ * // method (on constructor)
530
+ * result = Reflect.deleteMetadata("custom:annotation", Example, "staticMethod");
531
+ *
532
+ * // method (on prototype)
533
+ * result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method");
534
+ *
535
+ */
536
+ function deleteMetadata(metadataKey, target, propertyKey) {
537
+ if (!IsObject(target))
538
+ throw new TypeError();
539
+ if (!IsUndefined(propertyKey))
540
+ propertyKey = ToPropertyKey(propertyKey);
541
+ if (!IsObject(target))
542
+ throw new TypeError();
543
+ if (!IsUndefined(propertyKey))
544
+ propertyKey = ToPropertyKey(propertyKey);
545
+ var provider = GetMetadataProvider(target, propertyKey, /*Create*/ false);
546
+ if (IsUndefined(provider))
547
+ return false;
548
+ return provider.OrdinaryDeleteMetadata(metadataKey, target, propertyKey);
549
+ }
550
+ exporter("deleteMetadata", deleteMetadata);
551
+ function DecorateConstructor(decorators, target) {
552
+ for (var i = decorators.length - 1; i >= 0; --i) {
553
+ var decorator = decorators[i];
554
+ var decorated = decorator(target);
555
+ if (!IsUndefined(decorated) && !IsNull(decorated)) {
556
+ if (!IsConstructor(decorated))
557
+ throw new TypeError();
558
+ target = decorated;
559
+ }
560
+ }
561
+ return target;
562
+ }
563
+ function DecorateProperty(decorators, target, propertyKey, descriptor) {
564
+ for (var i = decorators.length - 1; i >= 0; --i) {
565
+ var decorator = decorators[i];
566
+ var decorated = decorator(target, propertyKey, descriptor);
567
+ if (!IsUndefined(decorated) && !IsNull(decorated)) {
568
+ if (!IsObject(decorated))
569
+ throw new TypeError();
570
+ descriptor = decorated;
571
+ }
572
+ }
573
+ return descriptor;
574
+ }
575
+ // 3.1.1.1 OrdinaryHasMetadata(MetadataKey, O, P)
576
+ // https://rbuckton.github.io/reflect-metadata/#ordinaryhasmetadata
577
+ function OrdinaryHasMetadata(MetadataKey, O, P) {
578
+ var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);
579
+ if (hasOwn)
580
+ return true;
581
+ var parent = OrdinaryGetPrototypeOf(O);
582
+ if (!IsNull(parent))
583
+ return OrdinaryHasMetadata(MetadataKey, parent, P);
584
+ return false;
585
+ }
586
+ // 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P)
587
+ // https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata
588
+ function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
589
+ var provider = GetMetadataProvider(O, P, /*Create*/ false);
590
+ if (IsUndefined(provider))
591
+ return false;
592
+ return ToBoolean(provider.OrdinaryHasOwnMetadata(MetadataKey, O, P));
593
+ }
594
+ // 3.1.3.1 OrdinaryGetMetadata(MetadataKey, O, P)
595
+ // https://rbuckton.github.io/reflect-metadata/#ordinarygetmetadata
596
+ function OrdinaryGetMetadata(MetadataKey, O, P) {
597
+ var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);
598
+ if (hasOwn)
599
+ return OrdinaryGetOwnMetadata(MetadataKey, O, P);
600
+ var parent = OrdinaryGetPrototypeOf(O);
601
+ if (!IsNull(parent))
602
+ return OrdinaryGetMetadata(MetadataKey, parent, P);
603
+ return undefined;
604
+ }
605
+ // 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P)
606
+ // https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata
607
+ function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
608
+ var provider = GetMetadataProvider(O, P, /*Create*/ false);
609
+ if (IsUndefined(provider))
610
+ return;
611
+ return provider.OrdinaryGetOwnMetadata(MetadataKey, O, P);
612
+ }
613
+ // 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P)
614
+ // https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata
615
+ function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
616
+ var provider = GetMetadataProvider(O, P, /*Create*/ true);
617
+ provider.OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P);
618
+ }
619
+ // 3.1.6.1 OrdinaryMetadataKeys(O, P)
620
+ // https://rbuckton.github.io/reflect-metadata/#ordinarymetadatakeys
621
+ function OrdinaryMetadataKeys(O, P) {
622
+ var ownKeys = OrdinaryOwnMetadataKeys(O, P);
623
+ var parent = OrdinaryGetPrototypeOf(O);
624
+ if (parent === null)
625
+ return ownKeys;
626
+ var parentKeys = OrdinaryMetadataKeys(parent, P);
627
+ if (parentKeys.length <= 0)
628
+ return ownKeys;
629
+ if (ownKeys.length <= 0)
630
+ return parentKeys;
631
+ var set = new _Set();
632
+ var keys = [];
633
+ for (var _i = 0, ownKeys_1 = ownKeys; _i < ownKeys_1.length; _i++) {
634
+ var key = ownKeys_1[_i];
635
+ var hasKey = set.has(key);
636
+ if (!hasKey) {
637
+ set.add(key);
638
+ keys.push(key);
639
+ }
640
+ }
641
+ for (var _a = 0, parentKeys_1 = parentKeys; _a < parentKeys_1.length; _a++) {
642
+ var key = parentKeys_1[_a];
643
+ var hasKey = set.has(key);
644
+ if (!hasKey) {
645
+ set.add(key);
646
+ keys.push(key);
647
+ }
648
+ }
649
+ return keys;
650
+ }
651
+ // 3.1.7.1 OrdinaryOwnMetadataKeys(O, P)
652
+ // https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys
653
+ function OrdinaryOwnMetadataKeys(O, P) {
654
+ var provider = GetMetadataProvider(O, P, /*create*/ false);
655
+ if (!provider) {
656
+ return [];
657
+ }
658
+ return provider.OrdinaryOwnMetadataKeys(O, P);
659
+ }
660
+ // 6 ECMAScript Data Types and Values
661
+ // https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values
662
+ function Type(x) {
663
+ if (x === null)
664
+ return 1 /* Null */;
665
+ switch (typeof x) {
666
+ case "undefined": return 0 /* Undefined */;
667
+ case "boolean": return 2 /* Boolean */;
668
+ case "string": return 3 /* String */;
669
+ case "symbol": return 4 /* Symbol */;
670
+ case "number": return 5 /* Number */;
671
+ case "object": return x === null ? 1 /* Null */ : 6 /* Object */;
672
+ default: return 6 /* Object */;
673
+ }
674
+ }
675
+ // 6.1.1 The Undefined Type
676
+ // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-undefined-type
677
+ function IsUndefined(x) {
678
+ return x === undefined;
679
+ }
680
+ // 6.1.2 The Null Type
681
+ // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-null-type
682
+ function IsNull(x) {
683
+ return x === null;
684
+ }
685
+ // 6.1.5 The Symbol Type
686
+ // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-symbol-type
687
+ function IsSymbol(x) {
688
+ return typeof x === "symbol";
689
+ }
690
+ // 6.1.7 The Object Type
691
+ // https://tc39.github.io/ecma262/#sec-object-type
692
+ function IsObject(x) {
693
+ return typeof x === "object" ? x !== null : typeof x === "function";
694
+ }
695
+ // 7.1 Type Conversion
696
+ // https://tc39.github.io/ecma262/#sec-type-conversion
697
+ // 7.1.1 ToPrimitive(input [, PreferredType])
698
+ // https://tc39.github.io/ecma262/#sec-toprimitive
699
+ function ToPrimitive(input, PreferredType) {
700
+ switch (Type(input)) {
701
+ case 0 /* Undefined */: return input;
702
+ case 1 /* Null */: return input;
703
+ case 2 /* Boolean */: return input;
704
+ case 3 /* String */: return input;
705
+ case 4 /* Symbol */: return input;
706
+ case 5 /* Number */: return input;
707
+ }
708
+ var hint = "string" ;
709
+ var exoticToPrim = GetMethod(input, toPrimitiveSymbol);
710
+ if (exoticToPrim !== undefined) {
711
+ var result = exoticToPrim.call(input, hint);
712
+ if (IsObject(result))
713
+ throw new TypeError();
714
+ return result;
715
+ }
716
+ return OrdinaryToPrimitive(input);
717
+ }
718
+ // 7.1.1.1 OrdinaryToPrimitive(O, hint)
719
+ // https://tc39.github.io/ecma262/#sec-ordinarytoprimitive
720
+ function OrdinaryToPrimitive(O, hint) {
721
+ var valueOf, result; {
722
+ var toString_1 = O.toString;
723
+ if (IsCallable(toString_1)) {
724
+ var result = toString_1.call(O);
725
+ if (!IsObject(result))
726
+ return result;
727
+ }
728
+ var valueOf = O.valueOf;
729
+ if (IsCallable(valueOf)) {
730
+ var result = valueOf.call(O);
731
+ if (!IsObject(result))
732
+ return result;
733
+ }
734
+ }
735
+ throw new TypeError();
736
+ }
737
+ // 7.1.2 ToBoolean(argument)
738
+ // https://tc39.github.io/ecma262/2016/#sec-toboolean
739
+ function ToBoolean(argument) {
740
+ return !!argument;
741
+ }
742
+ // 7.1.12 ToString(argument)
743
+ // https://tc39.github.io/ecma262/#sec-tostring
744
+ function ToString(argument) {
745
+ return "" + argument;
746
+ }
747
+ // 7.1.14 ToPropertyKey(argument)
748
+ // https://tc39.github.io/ecma262/#sec-topropertykey
749
+ function ToPropertyKey(argument) {
750
+ var key = ToPrimitive(argument);
751
+ if (IsSymbol(key))
752
+ return key;
753
+ return ToString(key);
754
+ }
755
+ // 7.2 Testing and Comparison Operations
756
+ // https://tc39.github.io/ecma262/#sec-testing-and-comparison-operations
757
+ // 7.2.2 IsArray(argument)
758
+ // https://tc39.github.io/ecma262/#sec-isarray
759
+ function IsArray(argument) {
760
+ return Array.isArray
761
+ ? Array.isArray(argument)
762
+ : argument instanceof Object
763
+ ? argument instanceof Array
764
+ : Object.prototype.toString.call(argument) === "[object Array]";
765
+ }
766
+ // 7.2.3 IsCallable(argument)
767
+ // https://tc39.github.io/ecma262/#sec-iscallable
768
+ function IsCallable(argument) {
769
+ // NOTE: This is an approximation as we cannot check for [[Call]] internal method.
770
+ return typeof argument === "function";
771
+ }
772
+ // 7.2.4 IsConstructor(argument)
773
+ // https://tc39.github.io/ecma262/#sec-isconstructor
774
+ function IsConstructor(argument) {
775
+ // NOTE: This is an approximation as we cannot check for [[Construct]] internal method.
776
+ return typeof argument === "function";
777
+ }
778
+ // 7.2.7 IsPropertyKey(argument)
779
+ // https://tc39.github.io/ecma262/#sec-ispropertykey
780
+ function IsPropertyKey(argument) {
781
+ switch (Type(argument)) {
782
+ case 3 /* String */: return true;
783
+ case 4 /* Symbol */: return true;
784
+ default: return false;
785
+ }
786
+ }
787
+ function SameValueZero(x, y) {
788
+ return x === y || x !== x && y !== y;
789
+ }
790
+ // 7.3 Operations on Objects
791
+ // https://tc39.github.io/ecma262/#sec-operations-on-objects
792
+ // 7.3.9 GetMethod(V, P)
793
+ // https://tc39.github.io/ecma262/#sec-getmethod
794
+ function GetMethod(V, P) {
795
+ var func = V[P];
796
+ if (func === undefined || func === null)
797
+ return undefined;
798
+ if (!IsCallable(func))
799
+ throw new TypeError();
800
+ return func;
801
+ }
802
+ // 7.4 Operations on Iterator Objects
803
+ // https://tc39.github.io/ecma262/#sec-operations-on-iterator-objects
804
+ function GetIterator(obj) {
805
+ var method = GetMethod(obj, iteratorSymbol);
806
+ if (!IsCallable(method))
807
+ throw new TypeError(); // from Call
808
+ var iterator = method.call(obj);
809
+ if (!IsObject(iterator))
810
+ throw new TypeError();
811
+ return iterator;
812
+ }
813
+ // 7.4.4 IteratorValue(iterResult)
814
+ // https://tc39.github.io/ecma262/2016/#sec-iteratorvalue
815
+ function IteratorValue(iterResult) {
816
+ return iterResult.value;
817
+ }
818
+ // 7.4.5 IteratorStep(iterator)
819
+ // https://tc39.github.io/ecma262/#sec-iteratorstep
820
+ function IteratorStep(iterator) {
821
+ var result = iterator.next();
822
+ return result.done ? false : result;
823
+ }
824
+ // 7.4.6 IteratorClose(iterator, completion)
825
+ // https://tc39.github.io/ecma262/#sec-iteratorclose
826
+ function IteratorClose(iterator) {
827
+ var f = iterator["return"];
828
+ if (f)
829
+ f.call(iterator);
830
+ }
831
+ // 9.1 Ordinary Object Internal Methods and Internal Slots
832
+ // https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots
833
+ // 9.1.1.1 OrdinaryGetPrototypeOf(O)
834
+ // https://tc39.github.io/ecma262/#sec-ordinarygetprototypeof
835
+ function OrdinaryGetPrototypeOf(O) {
836
+ var proto = Object.getPrototypeOf(O);
837
+ if (typeof O !== "function" || O === functionPrototype)
838
+ return proto;
839
+ // TypeScript doesn't set __proto__ in ES5, as it's non-standard.
840
+ // Try to determine the superclass constructor. Compatible implementations
841
+ // must either set __proto__ on a subclass constructor to the superclass constructor,
842
+ // or ensure each class has a valid `constructor` property on its prototype that
843
+ // points back to the constructor.
844
+ // If this is not the same as Function.[[Prototype]], then this is definately inherited.
845
+ // This is the case when in ES6 or when using __proto__ in a compatible browser.
846
+ if (proto !== functionPrototype)
847
+ return proto;
848
+ // If the super prototype is Object.prototype, null, or undefined, then we cannot determine the heritage.
849
+ var prototype = O.prototype;
850
+ var prototypeProto = prototype && Object.getPrototypeOf(prototype);
851
+ if (prototypeProto == null || prototypeProto === Object.prototype)
852
+ return proto;
853
+ // If the constructor was not a function, then we cannot determine the heritage.
854
+ var constructor = prototypeProto.constructor;
855
+ if (typeof constructor !== "function")
856
+ return proto;
857
+ // If we have some kind of self-reference, then we cannot determine the heritage.
858
+ if (constructor === O)
859
+ return proto;
860
+ // we have a pretty good guess at the heritage.
861
+ return constructor;
862
+ }
863
+ // Global metadata registry
864
+ // - Allows `import "reflect-metadata"` and `import "reflect-metadata/no-conflict"` to interoperate.
865
+ // - Uses isolated metadata if `Reflect` is frozen before the registry can be installed.
866
+ /**
867
+ * Creates a registry used to allow multiple `reflect-metadata` providers.
868
+ */
869
+ function CreateMetadataRegistry() {
870
+ var fallback;
871
+ if (!IsUndefined(registrySymbol) &&
872
+ typeof root.Reflect !== "undefined" &&
873
+ !(registrySymbol in root.Reflect) &&
874
+ typeof root.Reflect.defineMetadata === "function") {
875
+ // interoperate with older version of `reflect-metadata` that did not support a registry.
876
+ fallback = CreateFallbackProvider(root.Reflect);
877
+ }
878
+ var first;
879
+ var second;
880
+ var rest;
881
+ var targetProviderMap = new _WeakMap();
882
+ var registry = {
883
+ registerProvider: registerProvider,
884
+ getProvider: getProvider,
885
+ setProvider: setProvider,
886
+ };
887
+ return registry;
888
+ function registerProvider(provider) {
889
+ if (!Object.isExtensible(registry)) {
890
+ throw new Error("Cannot add provider to a frozen registry.");
891
+ }
892
+ switch (true) {
893
+ case fallback === provider: break;
894
+ case IsUndefined(first):
895
+ first = provider;
896
+ break;
897
+ case first === provider: break;
898
+ case IsUndefined(second):
899
+ second = provider;
900
+ break;
901
+ case second === provider: break;
902
+ default:
903
+ if (rest === undefined)
904
+ rest = new _Set();
905
+ rest.add(provider);
906
+ break;
907
+ }
908
+ }
909
+ function getProviderNoCache(O, P) {
910
+ if (!IsUndefined(first)) {
911
+ if (first.isProviderFor(O, P))
912
+ return first;
913
+ if (!IsUndefined(second)) {
914
+ if (second.isProviderFor(O, P))
915
+ return first;
916
+ if (!IsUndefined(rest)) {
917
+ var iterator = GetIterator(rest);
918
+ while (true) {
919
+ var next = IteratorStep(iterator);
920
+ if (!next) {
921
+ return undefined;
922
+ }
923
+ var provider = IteratorValue(next);
924
+ if (provider.isProviderFor(O, P)) {
925
+ IteratorClose(iterator);
926
+ return provider;
927
+ }
928
+ }
929
+ }
930
+ }
931
+ }
932
+ if (!IsUndefined(fallback) && fallback.isProviderFor(O, P)) {
933
+ return fallback;
934
+ }
935
+ return undefined;
936
+ }
937
+ function getProvider(O, P) {
938
+ var providerMap = targetProviderMap.get(O);
939
+ var provider;
940
+ if (!IsUndefined(providerMap)) {
941
+ provider = providerMap.get(P);
942
+ }
943
+ if (!IsUndefined(provider)) {
944
+ return provider;
945
+ }
946
+ provider = getProviderNoCache(O, P);
947
+ if (!IsUndefined(provider)) {
948
+ if (IsUndefined(providerMap)) {
949
+ providerMap = new _Map();
950
+ targetProviderMap.set(O, providerMap);
951
+ }
952
+ providerMap.set(P, provider);
953
+ }
954
+ return provider;
955
+ }
956
+ function hasProvider(provider) {
957
+ if (IsUndefined(provider))
958
+ throw new TypeError();
959
+ return first === provider || second === provider || !IsUndefined(rest) && rest.has(provider);
960
+ }
961
+ function setProvider(O, P, provider) {
962
+ if (!hasProvider(provider)) {
963
+ throw new Error("Metadata provider not registered.");
964
+ }
965
+ var existingProvider = getProvider(O, P);
966
+ if (existingProvider !== provider) {
967
+ if (!IsUndefined(existingProvider)) {
968
+ return false;
969
+ }
970
+ var providerMap = targetProviderMap.get(O);
971
+ if (IsUndefined(providerMap)) {
972
+ providerMap = new _Map();
973
+ targetProviderMap.set(O, providerMap);
974
+ }
975
+ providerMap.set(P, provider);
976
+ }
977
+ return true;
978
+ }
979
+ }
980
+ /**
981
+ * Gets or creates the shared registry of metadata providers.
982
+ */
983
+ function GetOrCreateMetadataRegistry() {
984
+ var metadataRegistry;
985
+ if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
986
+ metadataRegistry = root.Reflect[registrySymbol];
987
+ }
988
+ if (IsUndefined(metadataRegistry)) {
989
+ metadataRegistry = CreateMetadataRegistry();
990
+ }
991
+ if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
992
+ Object.defineProperty(root.Reflect, registrySymbol, {
993
+ enumerable: false,
994
+ configurable: false,
995
+ writable: false,
996
+ value: metadataRegistry
997
+ });
998
+ }
999
+ return metadataRegistry;
1000
+ }
1001
+ function CreateMetadataProvider(registry) {
1002
+ // [[Metadata]] internal slot
1003
+ // https://rbuckton.github.io/reflect-metadata/#ordinary-object-internal-methods-and-internal-slots
1004
+ var metadata = new _WeakMap();
1005
+ var provider = {
1006
+ isProviderFor: function (O, P) {
1007
+ var targetMetadata = metadata.get(O);
1008
+ if (IsUndefined(targetMetadata))
1009
+ return false;
1010
+ return targetMetadata.has(P);
1011
+ },
1012
+ OrdinaryDefineOwnMetadata: OrdinaryDefineOwnMetadata,
1013
+ OrdinaryHasOwnMetadata: OrdinaryHasOwnMetadata,
1014
+ OrdinaryGetOwnMetadata: OrdinaryGetOwnMetadata,
1015
+ OrdinaryOwnMetadataKeys: OrdinaryOwnMetadataKeys,
1016
+ OrdinaryDeleteMetadata: OrdinaryDeleteMetadata,
1017
+ };
1018
+ metadataRegistry.registerProvider(provider);
1019
+ return provider;
1020
+ function GetOrCreateMetadataMap(O, P, Create) {
1021
+ var targetMetadata = metadata.get(O);
1022
+ var createdTargetMetadata = false;
1023
+ if (IsUndefined(targetMetadata)) {
1024
+ if (!Create)
1025
+ return undefined;
1026
+ targetMetadata = new _Map();
1027
+ metadata.set(O, targetMetadata);
1028
+ createdTargetMetadata = true;
1029
+ }
1030
+ var metadataMap = targetMetadata.get(P);
1031
+ if (IsUndefined(metadataMap)) {
1032
+ if (!Create)
1033
+ return undefined;
1034
+ metadataMap = new _Map();
1035
+ targetMetadata.set(P, metadataMap);
1036
+ if (!registry.setProvider(O, P, provider)) {
1037
+ targetMetadata.delete(P);
1038
+ if (createdTargetMetadata) {
1039
+ metadata.delete(O);
1040
+ }
1041
+ throw new Error("Wrong provider for target.");
1042
+ }
1043
+ }
1044
+ return metadataMap;
1045
+ }
1046
+ // 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P)
1047
+ // https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata
1048
+ function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
1049
+ var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
1050
+ if (IsUndefined(metadataMap))
1051
+ return false;
1052
+ return ToBoolean(metadataMap.has(MetadataKey));
1053
+ }
1054
+ // 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P)
1055
+ // https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata
1056
+ function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
1057
+ var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
1058
+ if (IsUndefined(metadataMap))
1059
+ return undefined;
1060
+ return metadataMap.get(MetadataKey);
1061
+ }
1062
+ // 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P)
1063
+ // https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata
1064
+ function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
1065
+ var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ true);
1066
+ metadataMap.set(MetadataKey, MetadataValue);
1067
+ }
1068
+ // 3.1.7.1 OrdinaryOwnMetadataKeys(O, P)
1069
+ // https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys
1070
+ function OrdinaryOwnMetadataKeys(O, P) {
1071
+ var keys = [];
1072
+ var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
1073
+ if (IsUndefined(metadataMap))
1074
+ return keys;
1075
+ var keysObj = metadataMap.keys();
1076
+ var iterator = GetIterator(keysObj);
1077
+ var k = 0;
1078
+ while (true) {
1079
+ var next = IteratorStep(iterator);
1080
+ if (!next) {
1081
+ keys.length = k;
1082
+ return keys;
1083
+ }
1084
+ var nextValue = IteratorValue(next);
1085
+ try {
1086
+ keys[k] = nextValue;
1087
+ }
1088
+ catch (e) {
1089
+ try {
1090
+ IteratorClose(iterator);
1091
+ }
1092
+ finally {
1093
+ throw e;
1094
+ }
1095
+ }
1096
+ k++;
1097
+ }
1098
+ }
1099
+ function OrdinaryDeleteMetadata(MetadataKey, O, P) {
1100
+ var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
1101
+ if (IsUndefined(metadataMap))
1102
+ return false;
1103
+ if (!metadataMap.delete(MetadataKey))
1104
+ return false;
1105
+ if (metadataMap.size === 0) {
1106
+ var targetMetadata = metadata.get(O);
1107
+ if (!IsUndefined(targetMetadata)) {
1108
+ targetMetadata.delete(P);
1109
+ if (targetMetadata.size === 0) {
1110
+ metadata.delete(targetMetadata);
1111
+ }
1112
+ }
1113
+ }
1114
+ return true;
1115
+ }
1116
+ }
1117
+ function CreateFallbackProvider(reflect) {
1118
+ var defineMetadata = reflect.defineMetadata, hasOwnMetadata = reflect.hasOwnMetadata, getOwnMetadata = reflect.getOwnMetadata, getOwnMetadataKeys = reflect.getOwnMetadataKeys, deleteMetadata = reflect.deleteMetadata;
1119
+ var metadataOwner = new _WeakMap();
1120
+ var provider = {
1121
+ isProviderFor: function (O, P) {
1122
+ var metadataPropertySet = metadataOwner.get(O);
1123
+ if (!IsUndefined(metadataPropertySet) && metadataPropertySet.has(P)) {
1124
+ return true;
1125
+ }
1126
+ if (getOwnMetadataKeys(O, P).length) {
1127
+ if (IsUndefined(metadataPropertySet)) {
1128
+ metadataPropertySet = new _Set();
1129
+ metadataOwner.set(O, metadataPropertySet);
1130
+ }
1131
+ metadataPropertySet.add(P);
1132
+ return true;
1133
+ }
1134
+ return false;
1135
+ },
1136
+ OrdinaryDefineOwnMetadata: defineMetadata,
1137
+ OrdinaryHasOwnMetadata: hasOwnMetadata,
1138
+ OrdinaryGetOwnMetadata: getOwnMetadata,
1139
+ OrdinaryOwnMetadataKeys: getOwnMetadataKeys,
1140
+ OrdinaryDeleteMetadata: deleteMetadata,
1141
+ };
1142
+ return provider;
1143
+ }
1144
+ /**
1145
+ * Gets the metadata provider for an object. If the object has no metadata provider and this is for a create operation,
1146
+ * then this module's metadata provider is assigned to the object.
1147
+ */
1148
+ function GetMetadataProvider(O, P, Create) {
1149
+ var registeredProvider = metadataRegistry.getProvider(O, P);
1150
+ if (!IsUndefined(registeredProvider)) {
1151
+ return registeredProvider;
1152
+ }
1153
+ if (Create) {
1154
+ if (metadataRegistry.setProvider(O, P, metadataProvider)) {
1155
+ return metadataProvider;
1156
+ }
1157
+ throw new Error("Illegal state.");
1158
+ }
1159
+ return undefined;
1160
+ }
1161
+ // naive Map shim
1162
+ function CreateMapPolyfill() {
1163
+ var cacheSentinel = {};
1164
+ var arraySentinel = [];
1165
+ var MapIterator = /** @class */ (function () {
1166
+ function MapIterator(keys, values, selector) {
1167
+ this._index = 0;
1168
+ this._keys = keys;
1169
+ this._values = values;
1170
+ this._selector = selector;
1171
+ }
1172
+ MapIterator.prototype["@@iterator"] = function () { return this; };
1173
+ MapIterator.prototype[iteratorSymbol] = function () { return this; };
1174
+ MapIterator.prototype.next = function () {
1175
+ var index = this._index;
1176
+ if (index >= 0 && index < this._keys.length) {
1177
+ var result = this._selector(this._keys[index], this._values[index]);
1178
+ if (index + 1 >= this._keys.length) {
1179
+ this._index = -1;
1180
+ this._keys = arraySentinel;
1181
+ this._values = arraySentinel;
1182
+ }
1183
+ else {
1184
+ this._index++;
1185
+ }
1186
+ return { value: result, done: false };
1187
+ }
1188
+ return { value: undefined, done: true };
1189
+ };
1190
+ MapIterator.prototype.throw = function (error) {
1191
+ if (this._index >= 0) {
1192
+ this._index = -1;
1193
+ this._keys = arraySentinel;
1194
+ this._values = arraySentinel;
1195
+ }
1196
+ throw error;
1197
+ };
1198
+ MapIterator.prototype.return = function (value) {
1199
+ if (this._index >= 0) {
1200
+ this._index = -1;
1201
+ this._keys = arraySentinel;
1202
+ this._values = arraySentinel;
1203
+ }
1204
+ return { value: value, done: true };
1205
+ };
1206
+ return MapIterator;
1207
+ }());
1208
+ var Map = /** @class */ (function () {
1209
+ function Map() {
1210
+ this._keys = [];
1211
+ this._values = [];
1212
+ this._cacheKey = cacheSentinel;
1213
+ this._cacheIndex = -2;
1214
+ }
1215
+ Object.defineProperty(Map.prototype, "size", {
1216
+ get: function () { return this._keys.length; },
1217
+ enumerable: true,
1218
+ configurable: true
1219
+ });
1220
+ Map.prototype.has = function (key) { return this._find(key, /*insert*/ false) >= 0; };
1221
+ Map.prototype.get = function (key) {
1222
+ var index = this._find(key, /*insert*/ false);
1223
+ return index >= 0 ? this._values[index] : undefined;
1224
+ };
1225
+ Map.prototype.set = function (key, value) {
1226
+ var index = this._find(key, /*insert*/ true);
1227
+ this._values[index] = value;
1228
+ return this;
1229
+ };
1230
+ Map.prototype.delete = function (key) {
1231
+ var index = this._find(key, /*insert*/ false);
1232
+ if (index >= 0) {
1233
+ var size = this._keys.length;
1234
+ for (var i = index + 1; i < size; i++) {
1235
+ this._keys[i - 1] = this._keys[i];
1236
+ this._values[i - 1] = this._values[i];
1237
+ }
1238
+ this._keys.length--;
1239
+ this._values.length--;
1240
+ if (SameValueZero(key, this._cacheKey)) {
1241
+ this._cacheKey = cacheSentinel;
1242
+ this._cacheIndex = -2;
1243
+ }
1244
+ return true;
1245
+ }
1246
+ return false;
1247
+ };
1248
+ Map.prototype.clear = function () {
1249
+ this._keys.length = 0;
1250
+ this._values.length = 0;
1251
+ this._cacheKey = cacheSentinel;
1252
+ this._cacheIndex = -2;
1253
+ };
1254
+ Map.prototype.keys = function () { return new MapIterator(this._keys, this._values, getKey); };
1255
+ Map.prototype.values = function () { return new MapIterator(this._keys, this._values, getValue); };
1256
+ Map.prototype.entries = function () { return new MapIterator(this._keys, this._values, getEntry); };
1257
+ Map.prototype["@@iterator"] = function () { return this.entries(); };
1258
+ Map.prototype[iteratorSymbol] = function () { return this.entries(); };
1259
+ Map.prototype._find = function (key, insert) {
1260
+ if (!SameValueZero(this._cacheKey, key)) {
1261
+ this._cacheIndex = -1;
1262
+ for (var i = 0; i < this._keys.length; i++) {
1263
+ if (SameValueZero(this._keys[i], key)) {
1264
+ this._cacheIndex = i;
1265
+ break;
1266
+ }
1267
+ }
1268
+ }
1269
+ if (this._cacheIndex < 0 && insert) {
1270
+ this._cacheIndex = this._keys.length;
1271
+ this._keys.push(key);
1272
+ this._values.push(undefined);
1273
+ }
1274
+ return this._cacheIndex;
1275
+ };
1276
+ return Map;
1277
+ }());
1278
+ return Map;
1279
+ function getKey(key, _) {
1280
+ return key;
1281
+ }
1282
+ function getValue(_, value) {
1283
+ return value;
1284
+ }
1285
+ function getEntry(key, value) {
1286
+ return [key, value];
1287
+ }
1288
+ }
1289
+ // naive Set shim
1290
+ function CreateSetPolyfill() {
1291
+ var Set = /** @class */ (function () {
1292
+ function Set() {
1293
+ this._map = new _Map();
1294
+ }
1295
+ Object.defineProperty(Set.prototype, "size", {
1296
+ get: function () { return this._map.size; },
1297
+ enumerable: true,
1298
+ configurable: true
1299
+ });
1300
+ Set.prototype.has = function (value) { return this._map.has(value); };
1301
+ Set.prototype.add = function (value) { return this._map.set(value, value), this; };
1302
+ Set.prototype.delete = function (value) { return this._map.delete(value); };
1303
+ Set.prototype.clear = function () { this._map.clear(); };
1304
+ Set.prototype.keys = function () { return this._map.keys(); };
1305
+ Set.prototype.values = function () { return this._map.keys(); };
1306
+ Set.prototype.entries = function () { return this._map.entries(); };
1307
+ Set.prototype["@@iterator"] = function () { return this.keys(); };
1308
+ Set.prototype[iteratorSymbol] = function () { return this.keys(); };
1309
+ return Set;
1310
+ }());
1311
+ return Set;
1312
+ }
1313
+ // naive WeakMap shim
1314
+ function CreateWeakMapPolyfill() {
1315
+ var UUID_SIZE = 16;
1316
+ var keys = HashMap.create();
1317
+ var rootKey = CreateUniqueKey();
1318
+ return /** @class */ (function () {
1319
+ function WeakMap() {
1320
+ this._key = CreateUniqueKey();
1321
+ }
1322
+ WeakMap.prototype.has = function (target) {
1323
+ var table = GetOrCreateWeakMapTable(target, /*create*/ false);
1324
+ return table !== undefined ? HashMap.has(table, this._key) : false;
1325
+ };
1326
+ WeakMap.prototype.get = function (target) {
1327
+ var table = GetOrCreateWeakMapTable(target, /*create*/ false);
1328
+ return table !== undefined ? HashMap.get(table, this._key) : undefined;
1329
+ };
1330
+ WeakMap.prototype.set = function (target, value) {
1331
+ var table = GetOrCreateWeakMapTable(target, /*create*/ true);
1332
+ table[this._key] = value;
1333
+ return this;
1334
+ };
1335
+ WeakMap.prototype.delete = function (target) {
1336
+ var table = GetOrCreateWeakMapTable(target, /*create*/ false);
1337
+ return table !== undefined ? delete table[this._key] : false;
1338
+ };
1339
+ WeakMap.prototype.clear = function () {
1340
+ // NOTE: not a real clear, just makes the previous data unreachable
1341
+ this._key = CreateUniqueKey();
1342
+ };
1343
+ return WeakMap;
1344
+ }());
1345
+ function CreateUniqueKey() {
1346
+ var key;
1347
+ do
1348
+ key = "@@WeakMap@@" + CreateUUID();
1349
+ while (HashMap.has(keys, key));
1350
+ keys[key] = true;
1351
+ return key;
1352
+ }
1353
+ function GetOrCreateWeakMapTable(target, create) {
1354
+ if (!hasOwn.call(target, rootKey)) {
1355
+ if (!create)
1356
+ return undefined;
1357
+ Object.defineProperty(target, rootKey, { value: HashMap.create() });
1358
+ }
1359
+ return target[rootKey];
1360
+ }
1361
+ function FillRandomBytes(buffer, size) {
1362
+ for (var i = 0; i < size; ++i)
1363
+ buffer[i] = Math.random() * 0xff | 0;
1364
+ return buffer;
1365
+ }
1366
+ function GenRandomBytes(size) {
1367
+ if (typeof Uint8Array === "function") {
1368
+ var array = new Uint8Array(size);
1369
+ if (typeof crypto !== "undefined") {
1370
+ crypto.getRandomValues(array);
1371
+ }
1372
+ else if (typeof msCrypto !== "undefined") {
1373
+ msCrypto.getRandomValues(array);
1374
+ }
1375
+ else {
1376
+ FillRandomBytes(array, size);
1377
+ }
1378
+ return array;
1379
+ }
1380
+ return FillRandomBytes(new Array(size), size);
1381
+ }
1382
+ function CreateUUID() {
1383
+ var data = GenRandomBytes(UUID_SIZE);
1384
+ // mark as random - RFC 4122 § 4.4
1385
+ data[6] = data[6] & 0x4f | 0x40;
1386
+ data[8] = data[8] & 0xbf | 0x80;
1387
+ var result = "";
1388
+ for (var offset = 0; offset < UUID_SIZE; ++offset) {
1389
+ var byte = data[offset];
1390
+ if (offset === 4 || offset === 6 || offset === 8)
1391
+ result += "-";
1392
+ if (byte < 16)
1393
+ result += "0";
1394
+ result += byte.toString(16).toLowerCase();
1395
+ }
1396
+ return result;
1397
+ }
1398
+ }
1399
+ // uses a heuristic used by v8 and chakra to force an object into dictionary mode.
1400
+ function MakeDictionary(obj) {
1401
+ obj.__ = undefined;
1402
+ delete obj.__;
1403
+ return obj;
1404
+ }
1405
+ });
1406
+ })(Reflect$1 || (Reflect$1 = {}));
1407
+
1408
+ /******************************************************************************
1409
+ Copyright (c) Microsoft Corporation.
1410
+
1411
+ Permission to use, copy, modify, and/or distribute this software for any
1412
+ purpose with or without fee is hereby granted.
1413
+
1414
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1415
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1416
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1417
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1418
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1419
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1420
+ PERFORMANCE OF THIS SOFTWARE.
1421
+ ***************************************************************************** */
1422
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
1423
+
1424
+ var extendStatics = function(d, b) {
1425
+ extendStatics = Object.setPrototypeOf ||
1426
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1427
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
1428
+ return extendStatics(d, b);
1429
+ };
1430
+
1431
+ function __extends(d, b) {
1432
+ if (typeof b !== "function" && b !== null)
1433
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1434
+ extendStatics(d, b);
1435
+ function __() { this.constructor = d; }
1436
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1437
+ }
1438
+
1439
+ function __decorate(decorators, target, key, desc) {
1440
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1441
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1442
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1443
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1444
+ }
1445
+
1446
+ function __metadata(metadataKey, metadataValue) {
1447
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
1448
+ }
1449
+
1450
+ function __awaiter(thisArg, _arguments, P, generator) {
1451
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1452
+ return new (P || (P = Promise))(function (resolve, reject) {
1453
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1454
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1455
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1456
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1457
+ });
1458
+ }
1459
+
1460
+ function __generator(thisArg, body) {
1461
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
1462
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1463
+ function verb(n) { return function (v) { return step([n, v]); }; }
1464
+ function step(op) {
1465
+ if (f) throw new TypeError("Generator is already executing.");
1466
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
1467
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1468
+ if (y = 0, t) op = [op[0] & 2, t.value];
1469
+ switch (op[0]) {
1470
+ case 0: case 1: t = op; break;
1471
+ case 4: _.label++; return { value: op[1], done: false };
1472
+ case 5: _.label++; y = op[1]; op = [0]; continue;
1473
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
1474
+ default:
1475
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
1476
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
1477
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
1478
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
1479
+ if (t[2]) _.ops.pop();
1480
+ _.trys.pop(); continue;
1481
+ }
1482
+ op = body.call(thisArg, _);
1483
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
1484
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1485
+ }
1486
+ }
1487
+
1488
+ function __values(o) {
1489
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
1490
+ if (m) return m.call(o);
1491
+ if (o && typeof o.length === "number") return {
1492
+ next: function () {
1493
+ if (o && i >= o.length) o = void 0;
1494
+ return { value: o && o[i++], done: !o };
1495
+ }
1496
+ };
1497
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
1498
+ }
1499
+
1500
+ function __read(o, n) {
1501
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
1502
+ if (!m) return o;
1503
+ var i = m.call(o), r, ar = [], e;
1504
+ try {
1505
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
1506
+ }
1507
+ catch (error) { e = { error: error }; }
1508
+ finally {
1509
+ try {
1510
+ if (r && !r.done && (m = i["return"])) m.call(i);
1511
+ }
1512
+ finally { if (e) throw e.error; }
1513
+ }
1514
+ return ar;
1515
+ }
1516
+
1517
+ function __spreadArray(to, from, pack) {
1518
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
1519
+ if (ar || !(i in from)) {
1520
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
1521
+ ar[i] = from[i];
1522
+ }
1523
+ }
1524
+ return to.concat(ar || Array.prototype.slice.call(from));
1525
+ }
1526
+
1527
+ function __await(v) {
1528
+ return this instanceof __await ? (this.v = v, this) : new __await(v);
1529
+ }
1530
+
1531
+ function __asyncGenerator(thisArg, _arguments, generator) {
1532
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1533
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
1534
+ return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
1535
+ function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
1536
+ function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
1537
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
1538
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
1539
+ function fulfill(value) { resume("next", value); }
1540
+ function reject(value) { resume("throw", value); }
1541
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
1542
+ }
1543
+
1544
+ function __asyncValues(o) {
1545
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1546
+ var m = o[Symbol.asyncIterator], i;
1547
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
1548
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
1549
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
1550
+ }
1551
+
1552
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1553
+ var e = new Error(message);
1554
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1555
+ };
1556
+
1557
+ function isFunction(value) {
1558
+ return typeof value === 'function';
1559
+ }
1560
+
1561
+ function createErrorClass(createImpl) {
1562
+ var _super = function (instance) {
1563
+ Error.call(instance);
1564
+ instance.stack = new Error().stack;
1565
+ };
1566
+ var ctorFunc = createImpl(_super);
1567
+ ctorFunc.prototype = Object.create(Error.prototype);
1568
+ ctorFunc.prototype.constructor = ctorFunc;
1569
+ return ctorFunc;
1570
+ }
1571
+
1572
+ var UnsubscriptionError = createErrorClass(function (_super) {
1573
+ return function UnsubscriptionErrorImpl(errors) {
1574
+ _super(this);
1575
+ this.message = errors
1576
+ ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ')
1577
+ : '';
1578
+ this.name = 'UnsubscriptionError';
1579
+ this.errors = errors;
1580
+ };
1581
+ });
1582
+
1583
+ function arrRemove(arr, item) {
1584
+ if (arr) {
1585
+ var index = arr.indexOf(item);
1586
+ 0 <= index && arr.splice(index, 1);
1587
+ }
1588
+ }
1589
+
1590
+ var Subscription = (function () {
1591
+ function Subscription(initialTeardown) {
1592
+ this.initialTeardown = initialTeardown;
1593
+ this.closed = false;
1594
+ this._parentage = null;
1595
+ this._finalizers = null;
1596
+ }
1597
+ Subscription.prototype.unsubscribe = function () {
1598
+ var e_1, _a, e_2, _b;
1599
+ var errors;
1600
+ if (!this.closed) {
1601
+ this.closed = true;
1602
+ var _parentage = this._parentage;
1603
+ if (_parentage) {
1604
+ this._parentage = null;
1605
+ if (Array.isArray(_parentage)) {
1606
+ try {
1607
+ for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
1608
+ var parent_1 = _parentage_1_1.value;
1609
+ parent_1.remove(this);
1610
+ }
1611
+ }
1612
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1613
+ finally {
1614
+ try {
1615
+ if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
1616
+ }
1617
+ finally { if (e_1) throw e_1.error; }
1618
+ }
1619
+ }
1620
+ else {
1621
+ _parentage.remove(this);
1622
+ }
1623
+ }
1624
+ var initialFinalizer = this.initialTeardown;
1625
+ if (isFunction(initialFinalizer)) {
1626
+ try {
1627
+ initialFinalizer();
1628
+ }
1629
+ catch (e) {
1630
+ errors = e instanceof UnsubscriptionError ? e.errors : [e];
1631
+ }
1632
+ }
1633
+ var _finalizers = this._finalizers;
1634
+ if (_finalizers) {
1635
+ this._finalizers = null;
1636
+ try {
1637
+ for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
1638
+ var finalizer = _finalizers_1_1.value;
1639
+ try {
1640
+ execFinalizer(finalizer);
1641
+ }
1642
+ catch (err) {
1643
+ errors = errors !== null && errors !== void 0 ? errors : [];
1644
+ if (err instanceof UnsubscriptionError) {
1645
+ errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
1646
+ }
1647
+ else {
1648
+ errors.push(err);
1649
+ }
1650
+ }
1651
+ }
1652
+ }
1653
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1654
+ finally {
1655
+ try {
1656
+ if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
1657
+ }
1658
+ finally { if (e_2) throw e_2.error; }
1659
+ }
1660
+ }
1661
+ if (errors) {
1662
+ throw new UnsubscriptionError(errors);
1663
+ }
1664
+ }
1665
+ };
1666
+ Subscription.prototype.add = function (teardown) {
1667
+ var _a;
1668
+ if (teardown && teardown !== this) {
1669
+ if (this.closed) {
1670
+ execFinalizer(teardown);
1671
+ }
1672
+ else {
1673
+ if (teardown instanceof Subscription) {
1674
+ if (teardown.closed || teardown._hasParent(this)) {
1675
+ return;
1676
+ }
1677
+ teardown._addParent(this);
1678
+ }
1679
+ (this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
1680
+ }
1681
+ }
1682
+ };
1683
+ Subscription.prototype._hasParent = function (parent) {
1684
+ var _parentage = this._parentage;
1685
+ return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));
1686
+ };
1687
+ Subscription.prototype._addParent = function (parent) {
1688
+ var _parentage = this._parentage;
1689
+ this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
1690
+ };
1691
+ Subscription.prototype._removeParent = function (parent) {
1692
+ var _parentage = this._parentage;
1693
+ if (_parentage === parent) {
1694
+ this._parentage = null;
1695
+ }
1696
+ else if (Array.isArray(_parentage)) {
1697
+ arrRemove(_parentage, parent);
1698
+ }
1699
+ };
1700
+ Subscription.prototype.remove = function (teardown) {
1701
+ var _finalizers = this._finalizers;
1702
+ _finalizers && arrRemove(_finalizers, teardown);
1703
+ if (teardown instanceof Subscription) {
1704
+ teardown._removeParent(this);
1705
+ }
1706
+ };
1707
+ Subscription.EMPTY = (function () {
1708
+ var empty = new Subscription();
1709
+ empty.closed = true;
1710
+ return empty;
1711
+ })();
1712
+ return Subscription;
1713
+ }());
1714
+ var EMPTY_SUBSCRIPTION = Subscription.EMPTY;
1715
+ function isSubscription(value) {
1716
+ return (value instanceof Subscription ||
1717
+ (value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe)));
1718
+ }
1719
+ function execFinalizer(finalizer) {
1720
+ if (isFunction(finalizer)) {
1721
+ finalizer();
1722
+ }
1723
+ else {
1724
+ finalizer.unsubscribe();
1725
+ }
1726
+ }
1727
+
1728
+ var config = {
1729
+ Promise: undefined};
1730
+
1731
+ var timeoutProvider = {
1732
+ setTimeout: function (handler, timeout) {
1733
+ var args = [];
1734
+ for (var _i = 2; _i < arguments.length; _i++) {
1735
+ args[_i - 2] = arguments[_i];
1736
+ }
1737
+ return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
1738
+ },
1739
+ clearTimeout: function (handle) {
1740
+ return (clearTimeout)(handle);
1741
+ },
1742
+ delegate: undefined,
1743
+ };
1744
+
1745
+ function reportUnhandledError(err) {
1746
+ timeoutProvider.setTimeout(function () {
1747
+ {
1748
+ throw err;
1749
+ }
1750
+ });
1751
+ }
1752
+
1753
+ function noop() { }
1754
+
1755
+ function errorContext(cb) {
1756
+ {
1757
+ cb();
1758
+ }
1759
+ }
1760
+
1761
+ var Subscriber = (function (_super) {
1762
+ __extends(Subscriber, _super);
1763
+ function Subscriber(destination) {
1764
+ var _this = _super.call(this) || this;
1765
+ _this.isStopped = false;
1766
+ if (destination) {
1767
+ _this.destination = destination;
1768
+ if (isSubscription(destination)) {
1769
+ destination.add(_this);
1770
+ }
1771
+ }
1772
+ else {
1773
+ _this.destination = EMPTY_OBSERVER;
1774
+ }
1775
+ return _this;
1776
+ }
1777
+ Subscriber.create = function (next, error, complete) {
1778
+ return new SafeSubscriber(next, error, complete);
1779
+ };
1780
+ Subscriber.prototype.next = function (value) {
1781
+ if (this.isStopped) ;
1782
+ else {
1783
+ this._next(value);
1784
+ }
1785
+ };
1786
+ Subscriber.prototype.error = function (err) {
1787
+ if (this.isStopped) ;
1788
+ else {
1789
+ this.isStopped = true;
1790
+ this._error(err);
1791
+ }
1792
+ };
1793
+ Subscriber.prototype.complete = function () {
1794
+ if (this.isStopped) ;
1795
+ else {
1796
+ this.isStopped = true;
1797
+ this._complete();
1798
+ }
1799
+ };
1800
+ Subscriber.prototype.unsubscribe = function () {
1801
+ if (!this.closed) {
1802
+ this.isStopped = true;
1803
+ _super.prototype.unsubscribe.call(this);
1804
+ this.destination = null;
1805
+ }
1806
+ };
1807
+ Subscriber.prototype._next = function (value) {
1808
+ this.destination.next(value);
1809
+ };
1810
+ Subscriber.prototype._error = function (err) {
1811
+ try {
1812
+ this.destination.error(err);
1813
+ }
1814
+ finally {
1815
+ this.unsubscribe();
1816
+ }
1817
+ };
1818
+ Subscriber.prototype._complete = function () {
1819
+ try {
1820
+ this.destination.complete();
1821
+ }
1822
+ finally {
1823
+ this.unsubscribe();
1824
+ }
1825
+ };
1826
+ return Subscriber;
1827
+ }(Subscription));
1828
+ var ConsumerObserver = (function () {
1829
+ function ConsumerObserver(partialObserver) {
1830
+ this.partialObserver = partialObserver;
1831
+ }
1832
+ ConsumerObserver.prototype.next = function (value) {
1833
+ var partialObserver = this.partialObserver;
1834
+ if (partialObserver.next) {
1835
+ try {
1836
+ partialObserver.next(value);
1837
+ }
1838
+ catch (error) {
1839
+ handleUnhandledError(error);
1840
+ }
1841
+ }
1842
+ };
1843
+ ConsumerObserver.prototype.error = function (err) {
1844
+ var partialObserver = this.partialObserver;
1845
+ if (partialObserver.error) {
1846
+ try {
1847
+ partialObserver.error(err);
1848
+ }
1849
+ catch (error) {
1850
+ handleUnhandledError(error);
1851
+ }
1852
+ }
1853
+ else {
1854
+ handleUnhandledError(err);
1855
+ }
1856
+ };
1857
+ ConsumerObserver.prototype.complete = function () {
1858
+ var partialObserver = this.partialObserver;
1859
+ if (partialObserver.complete) {
1860
+ try {
1861
+ partialObserver.complete();
1862
+ }
1863
+ catch (error) {
1864
+ handleUnhandledError(error);
1865
+ }
1866
+ }
1867
+ };
1868
+ return ConsumerObserver;
1869
+ }());
1870
+ var SafeSubscriber = (function (_super) {
1871
+ __extends(SafeSubscriber, _super);
1872
+ function SafeSubscriber(observerOrNext, error, complete) {
1873
+ var _this = _super.call(this) || this;
1874
+ var partialObserver;
1875
+ if (isFunction(observerOrNext) || !observerOrNext) {
1876
+ partialObserver = {
1877
+ next: (observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined),
1878
+ error: error !== null && error !== void 0 ? error : undefined,
1879
+ complete: complete !== null && complete !== void 0 ? complete : undefined,
1880
+ };
1881
+ }
1882
+ else {
1883
+ {
1884
+ partialObserver = observerOrNext;
1885
+ }
1886
+ }
1887
+ _this.destination = new ConsumerObserver(partialObserver);
1888
+ return _this;
1889
+ }
1890
+ return SafeSubscriber;
1891
+ }(Subscriber));
1892
+ function handleUnhandledError(error) {
1893
+ {
1894
+ reportUnhandledError(error);
1895
+ }
1896
+ }
1897
+ function defaultErrorHandler(err) {
1898
+ throw err;
1899
+ }
1900
+ var EMPTY_OBSERVER = {
1901
+ closed: true,
1902
+ next: noop,
1903
+ error: defaultErrorHandler,
1904
+ complete: noop,
1905
+ };
1906
+
1907
+ var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })();
1908
+
1909
+ function identity(x) {
1910
+ return x;
1911
+ }
1912
+
1913
+ function pipeFromArray(fns) {
1914
+ if (fns.length === 0) {
1915
+ return identity;
1916
+ }
1917
+ if (fns.length === 1) {
1918
+ return fns[0];
1919
+ }
1920
+ return function piped(input) {
1921
+ return fns.reduce(function (prev, fn) { return fn(prev); }, input);
1922
+ };
1923
+ }
1924
+
1925
+ var Observable = (function () {
1926
+ function Observable(subscribe) {
1927
+ if (subscribe) {
1928
+ this._subscribe = subscribe;
1929
+ }
1930
+ }
1931
+ Observable.prototype.lift = function (operator) {
1932
+ var observable = new Observable();
1933
+ observable.source = this;
1934
+ observable.operator = operator;
1935
+ return observable;
1936
+ };
1937
+ Observable.prototype.subscribe = function (observerOrNext, error, complete) {
1938
+ var _this = this;
1939
+ var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
1940
+ errorContext(function () {
1941
+ var _a = _this, operator = _a.operator, source = _a.source;
1942
+ subscriber.add(operator
1943
+ ?
1944
+ operator.call(subscriber, source)
1945
+ : source
1946
+ ?
1947
+ _this._subscribe(subscriber)
1948
+ :
1949
+ _this._trySubscribe(subscriber));
1950
+ });
1951
+ return subscriber;
1952
+ };
1953
+ Observable.prototype._trySubscribe = function (sink) {
1954
+ try {
1955
+ return this._subscribe(sink);
1956
+ }
1957
+ catch (err) {
1958
+ sink.error(err);
1959
+ }
1960
+ };
1961
+ Observable.prototype.forEach = function (next, promiseCtor) {
1962
+ var _this = this;
1963
+ promiseCtor = getPromiseCtor(promiseCtor);
1964
+ return new promiseCtor(function (resolve, reject) {
1965
+ var subscriber = new SafeSubscriber({
1966
+ next: function (value) {
1967
+ try {
1968
+ next(value);
1969
+ }
1970
+ catch (err) {
1971
+ reject(err);
1972
+ subscriber.unsubscribe();
1973
+ }
1974
+ },
1975
+ error: reject,
1976
+ complete: resolve,
1977
+ });
1978
+ _this.subscribe(subscriber);
1979
+ });
1980
+ };
1981
+ Observable.prototype._subscribe = function (subscriber) {
1982
+ var _a;
1983
+ return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
1984
+ };
1985
+ Observable.prototype[observable] = function () {
1986
+ return this;
1987
+ };
1988
+ Observable.prototype.pipe = function () {
1989
+ var operations = [];
1990
+ for (var _i = 0; _i < arguments.length; _i++) {
1991
+ operations[_i] = arguments[_i];
1992
+ }
1993
+ return pipeFromArray(operations)(this);
1994
+ };
1995
+ Observable.prototype.toPromise = function (promiseCtor) {
1996
+ var _this = this;
1997
+ promiseCtor = getPromiseCtor(promiseCtor);
1998
+ return new promiseCtor(function (resolve, reject) {
1999
+ var value;
2000
+ _this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); });
2001
+ });
2002
+ };
2003
+ Observable.create = function (subscribe) {
2004
+ return new Observable(subscribe);
2005
+ };
2006
+ return Observable;
2007
+ }());
2008
+ function getPromiseCtor(promiseCtor) {
2009
+ var _a;
2010
+ return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
2011
+ }
2012
+ function isObserver(value) {
2013
+ return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
2014
+ }
2015
+ function isSubscriber(value) {
2016
+ return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));
2017
+ }
2018
+
2019
+ function hasLift(source) {
2020
+ return isFunction(source === null || source === void 0 ? void 0 : source.lift);
2021
+ }
2022
+ function operate(init) {
2023
+ return function (source) {
2024
+ if (hasLift(source)) {
2025
+ return source.lift(function (liftedSource) {
2026
+ try {
2027
+ return init(liftedSource, this);
2028
+ }
2029
+ catch (err) {
2030
+ this.error(err);
2031
+ }
2032
+ });
2033
+ }
2034
+ throw new TypeError('Unable to lift unknown Observable type');
2035
+ };
2036
+ }
2037
+
2038
+ function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
2039
+ return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
2040
+ }
2041
+ var OperatorSubscriber = (function (_super) {
2042
+ __extends(OperatorSubscriber, _super);
2043
+ function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
2044
+ var _this = _super.call(this, destination) || this;
2045
+ _this.onFinalize = onFinalize;
2046
+ _this.shouldUnsubscribe = shouldUnsubscribe;
2047
+ _this._next = onNext
2048
+ ? function (value) {
2049
+ try {
2050
+ onNext(value);
2051
+ }
2052
+ catch (err) {
2053
+ destination.error(err);
2054
+ }
2055
+ }
2056
+ : _super.prototype._next;
2057
+ _this._error = onError
2058
+ ? function (err) {
2059
+ try {
2060
+ onError(err);
2061
+ }
2062
+ catch (err) {
2063
+ destination.error(err);
2064
+ }
2065
+ finally {
2066
+ this.unsubscribe();
2067
+ }
2068
+ }
2069
+ : _super.prototype._error;
2070
+ _this._complete = onComplete
2071
+ ? function () {
2072
+ try {
2073
+ onComplete();
2074
+ }
2075
+ catch (err) {
2076
+ destination.error(err);
2077
+ }
2078
+ finally {
2079
+ this.unsubscribe();
2080
+ }
2081
+ }
2082
+ : _super.prototype._complete;
2083
+ return _this;
2084
+ }
2085
+ OperatorSubscriber.prototype.unsubscribe = function () {
2086
+ var _a;
2087
+ if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
2088
+ var closed_1 = this.closed;
2089
+ _super.prototype.unsubscribe.call(this);
2090
+ !closed_1 && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this));
2091
+ }
2092
+ };
2093
+ return OperatorSubscriber;
2094
+ }(Subscriber));
2095
+
2096
+ var ObjectUnsubscribedError = createErrorClass(function (_super) {
2097
+ return function ObjectUnsubscribedErrorImpl() {
2098
+ _super(this);
2099
+ this.name = 'ObjectUnsubscribedError';
2100
+ this.message = 'object unsubscribed';
2101
+ };
2102
+ });
2103
+
2104
+ var Subject = (function (_super) {
2105
+ __extends(Subject, _super);
2106
+ function Subject() {
2107
+ var _this = _super.call(this) || this;
2108
+ _this.closed = false;
2109
+ _this.currentObservers = null;
2110
+ _this.observers = [];
2111
+ _this.isStopped = false;
2112
+ _this.hasError = false;
2113
+ _this.thrownError = null;
2114
+ return _this;
2115
+ }
2116
+ Subject.prototype.lift = function (operator) {
2117
+ var subject = new AnonymousSubject(this, this);
2118
+ subject.operator = operator;
2119
+ return subject;
2120
+ };
2121
+ Subject.prototype._throwIfClosed = function () {
2122
+ if (this.closed) {
2123
+ throw new ObjectUnsubscribedError();
2124
+ }
2125
+ };
2126
+ Subject.prototype.next = function (value) {
2127
+ var _this = this;
2128
+ errorContext(function () {
2129
+ var e_1, _a;
2130
+ _this._throwIfClosed();
2131
+ if (!_this.isStopped) {
2132
+ if (!_this.currentObservers) {
2133
+ _this.currentObservers = Array.from(_this.observers);
2134
+ }
2135
+ try {
2136
+ for (var _b = __values(_this.currentObservers), _c = _b.next(); !_c.done; _c = _b.next()) {
2137
+ var observer = _c.value;
2138
+ observer.next(value);
2139
+ }
2140
+ }
2141
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2142
+ finally {
2143
+ try {
2144
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2145
+ }
2146
+ finally { if (e_1) throw e_1.error; }
2147
+ }
2148
+ }
2149
+ });
2150
+ };
2151
+ Subject.prototype.error = function (err) {
2152
+ var _this = this;
2153
+ errorContext(function () {
2154
+ _this._throwIfClosed();
2155
+ if (!_this.isStopped) {
2156
+ _this.hasError = _this.isStopped = true;
2157
+ _this.thrownError = err;
2158
+ var observers = _this.observers;
2159
+ while (observers.length) {
2160
+ observers.shift().error(err);
2161
+ }
2162
+ }
2163
+ });
2164
+ };
2165
+ Subject.prototype.complete = function () {
2166
+ var _this = this;
2167
+ errorContext(function () {
2168
+ _this._throwIfClosed();
2169
+ if (!_this.isStopped) {
2170
+ _this.isStopped = true;
2171
+ var observers = _this.observers;
2172
+ while (observers.length) {
2173
+ observers.shift().complete();
2174
+ }
2175
+ }
2176
+ });
2177
+ };
2178
+ Subject.prototype.unsubscribe = function () {
2179
+ this.isStopped = this.closed = true;
2180
+ this.observers = this.currentObservers = null;
2181
+ };
2182
+ Object.defineProperty(Subject.prototype, "observed", {
2183
+ get: function () {
2184
+ var _a;
2185
+ return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
2186
+ },
2187
+ enumerable: false,
2188
+ configurable: true
2189
+ });
2190
+ Subject.prototype._trySubscribe = function (subscriber) {
2191
+ this._throwIfClosed();
2192
+ return _super.prototype._trySubscribe.call(this, subscriber);
2193
+ };
2194
+ Subject.prototype._subscribe = function (subscriber) {
2195
+ this._throwIfClosed();
2196
+ this._checkFinalizedStatuses(subscriber);
2197
+ return this._innerSubscribe(subscriber);
2198
+ };
2199
+ Subject.prototype._innerSubscribe = function (subscriber) {
2200
+ var _this = this;
2201
+ var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
2202
+ if (hasError || isStopped) {
2203
+ return EMPTY_SUBSCRIPTION;
2204
+ }
2205
+ this.currentObservers = null;
2206
+ observers.push(subscriber);
2207
+ return new Subscription(function () {
2208
+ _this.currentObservers = null;
2209
+ arrRemove(observers, subscriber);
2210
+ });
2211
+ };
2212
+ Subject.prototype._checkFinalizedStatuses = function (subscriber) {
2213
+ var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
2214
+ if (hasError) {
2215
+ subscriber.error(thrownError);
2216
+ }
2217
+ else if (isStopped) {
2218
+ subscriber.complete();
2219
+ }
2220
+ };
2221
+ Subject.prototype.asObservable = function () {
2222
+ var observable = new Observable();
2223
+ observable.source = this;
2224
+ return observable;
2225
+ };
2226
+ Subject.create = function (destination, source) {
2227
+ return new AnonymousSubject(destination, source);
2228
+ };
2229
+ return Subject;
2230
+ }(Observable));
2231
+ var AnonymousSubject = (function (_super) {
2232
+ __extends(AnonymousSubject, _super);
2233
+ function AnonymousSubject(destination, source) {
2234
+ var _this = _super.call(this) || this;
2235
+ _this.destination = destination;
2236
+ _this.source = source;
2237
+ return _this;
2238
+ }
2239
+ AnonymousSubject.prototype.next = function (value) {
2240
+ var _a, _b;
2241
+ (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
2242
+ };
2243
+ AnonymousSubject.prototype.error = function (err) {
2244
+ var _a, _b;
2245
+ (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
2246
+ };
2247
+ AnonymousSubject.prototype.complete = function () {
2248
+ var _a, _b;
2249
+ (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
2250
+ };
2251
+ AnonymousSubject.prototype._subscribe = function (subscriber) {
2252
+ var _a, _b;
2253
+ return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : EMPTY_SUBSCRIPTION;
2254
+ };
2255
+ return AnonymousSubject;
2256
+ }(Subject));
2257
+
2258
+ var BehaviorSubject = (function (_super) {
2259
+ __extends(BehaviorSubject, _super);
2260
+ function BehaviorSubject(_value) {
2261
+ var _this = _super.call(this) || this;
2262
+ _this._value = _value;
2263
+ return _this;
2264
+ }
2265
+ Object.defineProperty(BehaviorSubject.prototype, "value", {
2266
+ get: function () {
2267
+ return this.getValue();
2268
+ },
2269
+ enumerable: false,
2270
+ configurable: true
2271
+ });
2272
+ BehaviorSubject.prototype._subscribe = function (subscriber) {
2273
+ var subscription = _super.prototype._subscribe.call(this, subscriber);
2274
+ !subscription.closed && subscriber.next(this._value);
2275
+ return subscription;
2276
+ };
2277
+ BehaviorSubject.prototype.getValue = function () {
2278
+ var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, _value = _a._value;
2279
+ if (hasError) {
2280
+ throw thrownError;
2281
+ }
2282
+ this._throwIfClosed();
2283
+ return _value;
2284
+ };
2285
+ BehaviorSubject.prototype.next = function (value) {
2286
+ _super.prototype.next.call(this, (this._value = value));
2287
+ };
2288
+ return BehaviorSubject;
2289
+ }(Subject));
2290
+
2291
+ function last(arr) {
2292
+ return arr[arr.length - 1];
2293
+ }
2294
+ function popResultSelector(args) {
2295
+ return isFunction(last(args)) ? args.pop() : undefined;
2296
+ }
2297
+
2298
+ var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
2299
+
2300
+ function isPromise(value) {
2301
+ return isFunction(value === null || value === void 0 ? void 0 : value.then);
2302
+ }
2303
+
2304
+ function isInteropObservable(input) {
2305
+ return isFunction(input[observable]);
2306
+ }
2307
+
2308
+ function isAsyncIterable(obj) {
2309
+ return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]);
2310
+ }
2311
+
2312
+ function createInvalidObservableTypeError(input) {
2313
+ return new TypeError("You provided " + (input !== null && typeof input === 'object' ? 'an invalid object' : "'" + input + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
2314
+ }
2315
+
2316
+ function getSymbolIterator() {
2317
+ if (typeof Symbol !== 'function' || !Symbol.iterator) {
2318
+ return '@@iterator';
2319
+ }
2320
+ return Symbol.iterator;
2321
+ }
2322
+ var iterator = getSymbolIterator();
2323
+
2324
+ function isIterable(input) {
2325
+ return isFunction(input === null || input === void 0 ? void 0 : input[iterator]);
2326
+ }
2327
+
2328
+ function readableStreamLikeToAsyncGenerator(readableStream) {
2329
+ return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
2330
+ var reader, _a, value, done;
2331
+ return __generator(this, function (_b) {
2332
+ switch (_b.label) {
2333
+ case 0:
2334
+ reader = readableStream.getReader();
2335
+ _b.label = 1;
2336
+ case 1:
2337
+ _b.trys.push([1, , 9, 10]);
2338
+ _b.label = 2;
2339
+ case 2:
2340
+ return [4, __await(reader.read())];
2341
+ case 3:
2342
+ _a = _b.sent(), value = _a.value, done = _a.done;
2343
+ if (!done) return [3, 5];
2344
+ return [4, __await(void 0)];
2345
+ case 4: return [2, _b.sent()];
2346
+ case 5: return [4, __await(value)];
2347
+ case 6: return [4, _b.sent()];
2348
+ case 7:
2349
+ _b.sent();
2350
+ return [3, 2];
2351
+ case 8: return [3, 10];
2352
+ case 9:
2353
+ reader.releaseLock();
2354
+ return [7];
2355
+ case 10: return [2];
2356
+ }
2357
+ });
2358
+ });
2359
+ }
2360
+ function isReadableStreamLike(obj) {
2361
+ return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
2362
+ }
2363
+
2364
+ function innerFrom(input) {
2365
+ if (input instanceof Observable) {
2366
+ return input;
2367
+ }
2368
+ if (input != null) {
2369
+ if (isInteropObservable(input)) {
2370
+ return fromInteropObservable(input);
2371
+ }
2372
+ if (isArrayLike(input)) {
2373
+ return fromArrayLike(input);
2374
+ }
2375
+ if (isPromise(input)) {
2376
+ return fromPromise(input);
2377
+ }
2378
+ if (isAsyncIterable(input)) {
2379
+ return fromAsyncIterable(input);
2380
+ }
2381
+ if (isIterable(input)) {
2382
+ return fromIterable(input);
2383
+ }
2384
+ if (isReadableStreamLike(input)) {
2385
+ return fromReadableStreamLike(input);
2386
+ }
2387
+ }
2388
+ throw createInvalidObservableTypeError(input);
2389
+ }
2390
+ function fromInteropObservable(obj) {
2391
+ return new Observable(function (subscriber) {
2392
+ var obs = obj[observable]();
2393
+ if (isFunction(obs.subscribe)) {
2394
+ return obs.subscribe(subscriber);
2395
+ }
2396
+ throw new TypeError('Provided object does not correctly implement Symbol.observable');
2397
+ });
2398
+ }
2399
+ function fromArrayLike(array) {
2400
+ return new Observable(function (subscriber) {
2401
+ for (var i = 0; i < array.length && !subscriber.closed; i++) {
2402
+ subscriber.next(array[i]);
2403
+ }
2404
+ subscriber.complete();
2405
+ });
2406
+ }
2407
+ function fromPromise(promise) {
2408
+ return new Observable(function (subscriber) {
2409
+ promise
2410
+ .then(function (value) {
2411
+ if (!subscriber.closed) {
2412
+ subscriber.next(value);
2413
+ subscriber.complete();
2414
+ }
2415
+ }, function (err) { return subscriber.error(err); })
2416
+ .then(null, reportUnhandledError);
2417
+ });
2418
+ }
2419
+ function fromIterable(iterable) {
2420
+ return new Observable(function (subscriber) {
2421
+ var e_1, _a;
2422
+ try {
2423
+ for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
2424
+ var value = iterable_1_1.value;
2425
+ subscriber.next(value);
2426
+ if (subscriber.closed) {
2427
+ return;
2428
+ }
2429
+ }
2430
+ }
2431
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2432
+ finally {
2433
+ try {
2434
+ if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1);
2435
+ }
2436
+ finally { if (e_1) throw e_1.error; }
2437
+ }
2438
+ subscriber.complete();
2439
+ });
2440
+ }
2441
+ function fromAsyncIterable(asyncIterable) {
2442
+ return new Observable(function (subscriber) {
2443
+ process(asyncIterable, subscriber).catch(function (err) { return subscriber.error(err); });
2444
+ });
2445
+ }
2446
+ function fromReadableStreamLike(readableStream) {
2447
+ return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream));
2448
+ }
2449
+ function process(asyncIterable, subscriber) {
2450
+ var asyncIterable_1, asyncIterable_1_1;
2451
+ var e_2, _a;
2452
+ return __awaiter(this, void 0, void 0, function () {
2453
+ var value, e_2_1;
2454
+ return __generator(this, function (_b) {
2455
+ switch (_b.label) {
2456
+ case 0:
2457
+ _b.trys.push([0, 5, 6, 11]);
2458
+ asyncIterable_1 = __asyncValues(asyncIterable);
2459
+ _b.label = 1;
2460
+ case 1: return [4, asyncIterable_1.next()];
2461
+ case 2:
2462
+ if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done)) return [3, 4];
2463
+ value = asyncIterable_1_1.value;
2464
+ subscriber.next(value);
2465
+ if (subscriber.closed) {
2466
+ return [2];
2467
+ }
2468
+ _b.label = 3;
2469
+ case 3: return [3, 1];
2470
+ case 4: return [3, 11];
2471
+ case 5:
2472
+ e_2_1 = _b.sent();
2473
+ e_2 = { error: e_2_1 };
2474
+ return [3, 11];
2475
+ case 6:
2476
+ _b.trys.push([6, , 9, 10]);
2477
+ if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return))) return [3, 8];
2478
+ return [4, _a.call(asyncIterable_1)];
2479
+ case 7:
2480
+ _b.sent();
2481
+ _b.label = 8;
2482
+ case 8: return [3, 10];
2483
+ case 9:
2484
+ if (e_2) throw e_2.error;
2485
+ return [7];
2486
+ case 10: return [7];
2487
+ case 11:
2488
+ subscriber.complete();
2489
+ return [2];
2490
+ }
2491
+ });
2492
+ });
2493
+ }
2494
+
2495
+ function executeSchedule(parentSubscription, scheduler, work, delay, repeat) {
2496
+ if (delay === void 0) { delay = 0; }
2497
+ if (repeat === void 0) { repeat = false; }
2498
+ var scheduleSubscription = scheduler.schedule(function () {
2499
+ work();
2500
+ if (repeat) {
2501
+ parentSubscription.add(this.schedule(null, delay));
2502
+ }
2503
+ else {
2504
+ this.unsubscribe();
2505
+ }
2506
+ }, delay);
2507
+ parentSubscription.add(scheduleSubscription);
2508
+ if (!repeat) {
2509
+ return scheduleSubscription;
2510
+ }
2511
+ }
2512
+
2513
+ function observeOn(scheduler, delay) {
2514
+ if (delay === void 0) { delay = 0; }
2515
+ return operate(function (source, subscriber) {
2516
+ source.subscribe(createOperatorSubscriber(subscriber, function (value) { return executeSchedule(subscriber, scheduler, function () { return subscriber.next(value); }, delay); }, function () { return executeSchedule(subscriber, scheduler, function () { return subscriber.complete(); }, delay); }, function (err) { return executeSchedule(subscriber, scheduler, function () { return subscriber.error(err); }, delay); }));
2517
+ });
2518
+ }
2519
+
2520
+ function subscribeOn(scheduler, delay) {
2521
+ if (delay === void 0) { delay = 0; }
2522
+ return operate(function (source, subscriber) {
2523
+ subscriber.add(scheduler.schedule(function () { return source.subscribe(subscriber); }, delay));
2524
+ });
2525
+ }
2526
+
2527
+ function scheduleObservable(input, scheduler) {
2528
+ return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
2529
+ }
2530
+
2531
+ function schedulePromise(input, scheduler) {
2532
+ return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
2533
+ }
2534
+
2535
+ function scheduleArray(input, scheduler) {
2536
+ return new Observable(function (subscriber) {
2537
+ var i = 0;
2538
+ return scheduler.schedule(function () {
2539
+ if (i === input.length) {
2540
+ subscriber.complete();
2541
+ }
2542
+ else {
2543
+ subscriber.next(input[i++]);
2544
+ if (!subscriber.closed) {
2545
+ this.schedule();
2546
+ }
2547
+ }
2548
+ });
2549
+ });
2550
+ }
2551
+
2552
+ function scheduleIterable(input, scheduler) {
2553
+ return new Observable(function (subscriber) {
2554
+ var iterator$1;
2555
+ executeSchedule(subscriber, scheduler, function () {
2556
+ iterator$1 = input[iterator]();
2557
+ executeSchedule(subscriber, scheduler, function () {
2558
+ var _a;
2559
+ var value;
2560
+ var done;
2561
+ try {
2562
+ (_a = iterator$1.next(), value = _a.value, done = _a.done);
2563
+ }
2564
+ catch (err) {
2565
+ subscriber.error(err);
2566
+ return;
2567
+ }
2568
+ if (done) {
2569
+ subscriber.complete();
2570
+ }
2571
+ else {
2572
+ subscriber.next(value);
2573
+ }
2574
+ }, 0, true);
2575
+ });
2576
+ return function () { return isFunction(iterator$1 === null || iterator$1 === void 0 ? void 0 : iterator$1.return) && iterator$1.return(); };
2577
+ });
2578
+ }
2579
+
2580
+ function scheduleAsyncIterable(input, scheduler) {
2581
+ if (!input) {
2582
+ throw new Error('Iterable cannot be null');
2583
+ }
2584
+ return new Observable(function (subscriber) {
2585
+ executeSchedule(subscriber, scheduler, function () {
2586
+ var iterator = input[Symbol.asyncIterator]();
2587
+ executeSchedule(subscriber, scheduler, function () {
2588
+ iterator.next().then(function (result) {
2589
+ if (result.done) {
2590
+ subscriber.complete();
2591
+ }
2592
+ else {
2593
+ subscriber.next(result.value);
2594
+ }
2595
+ });
2596
+ }, 0, true);
2597
+ });
2598
+ });
2599
+ }
2600
+
2601
+ function scheduleReadableStreamLike(input, scheduler) {
2602
+ return scheduleAsyncIterable(readableStreamLikeToAsyncGenerator(input), scheduler);
2603
+ }
2604
+
2605
+ function scheduled(input, scheduler) {
2606
+ if (input != null) {
2607
+ if (isInteropObservable(input)) {
2608
+ return scheduleObservable(input, scheduler);
2609
+ }
2610
+ if (isArrayLike(input)) {
2611
+ return scheduleArray(input, scheduler);
2612
+ }
2613
+ if (isPromise(input)) {
2614
+ return schedulePromise(input, scheduler);
2615
+ }
2616
+ if (isAsyncIterable(input)) {
2617
+ return scheduleAsyncIterable(input, scheduler);
2618
+ }
2619
+ if (isIterable(input)) {
2620
+ return scheduleIterable(input, scheduler);
2621
+ }
2622
+ if (isReadableStreamLike(input)) {
2623
+ return scheduleReadableStreamLike(input, scheduler);
2624
+ }
2625
+ }
2626
+ throw createInvalidObservableTypeError(input);
2627
+ }
2628
+
2629
+ function from(input, scheduler) {
2630
+ return scheduler ? scheduled(input, scheduler) : innerFrom(input);
2631
+ }
2632
+
2633
+ function map(project, thisArg) {
2634
+ return operate(function (source, subscriber) {
2635
+ var index = 0;
2636
+ source.subscribe(createOperatorSubscriber(subscriber, function (value) {
2637
+ subscriber.next(project.call(thisArg, value, index++));
2638
+ }));
2639
+ });
2640
+ }
2641
+
2642
+ var isArray$1 = Array.isArray;
2643
+ function callOrApply(fn, args) {
2644
+ return isArray$1(args) ? fn.apply(void 0, __spreadArray([], __read(args))) : fn(args);
2645
+ }
2646
+ function mapOneOrManyArgs(fn) {
2647
+ return map(function (args) { return callOrApply(fn, args); });
2648
+ }
2649
+
2650
+ var isArray = Array.isArray;
2651
+ var getPrototypeOf = Object.getPrototypeOf, objectProto = Object.prototype, getKeys = Object.keys;
2652
+ function argsArgArrayOrObject(args) {
2653
+ if (args.length === 1) {
2654
+ var first_1 = args[0];
2655
+ if (isArray(first_1)) {
2656
+ return { args: first_1, keys: null };
2657
+ }
2658
+ if (isPOJO(first_1)) {
2659
+ var keys = getKeys(first_1);
2660
+ return {
2661
+ args: keys.map(function (key) { return first_1[key]; }),
2662
+ keys: keys,
2663
+ };
2664
+ }
2665
+ }
2666
+ return { args: args, keys: null };
2667
+ }
2668
+ function isPOJO(obj) {
2669
+ return obj && typeof obj === 'object' && getPrototypeOf(obj) === objectProto;
2670
+ }
2671
+
2672
+ function createObject(keys, values) {
2673
+ return keys.reduce(function (result, key, i) { return ((result[key] = values[i]), result); }, {});
2674
+ }
2675
+
2676
+ function mergeInternals(source, subscriber, project, concurrent, onBeforeNext, expand, innerSubScheduler, additionalFinalizer) {
2677
+ var buffer = [];
2678
+ var active = 0;
2679
+ var index = 0;
2680
+ var isComplete = false;
2681
+ var checkComplete = function () {
2682
+ if (isComplete && !buffer.length && !active) {
2683
+ subscriber.complete();
2684
+ }
2685
+ };
2686
+ var outerNext = function (value) { return (active < concurrent ? doInnerSub(value) : buffer.push(value)); };
2687
+ var doInnerSub = function (value) {
2688
+ active++;
2689
+ var innerComplete = false;
2690
+ innerFrom(project(value, index++)).subscribe(createOperatorSubscriber(subscriber, function (innerValue) {
2691
+ {
2692
+ subscriber.next(innerValue);
2693
+ }
2694
+ }, function () {
2695
+ innerComplete = true;
2696
+ }, undefined, function () {
2697
+ if (innerComplete) {
2698
+ try {
2699
+ active--;
2700
+ var _loop_1 = function () {
2701
+ var bufferedValue = buffer.shift();
2702
+ if (innerSubScheduler) ;
2703
+ else {
2704
+ doInnerSub(bufferedValue);
2705
+ }
2706
+ };
2707
+ while (buffer.length && active < concurrent) {
2708
+ _loop_1();
2709
+ }
2710
+ checkComplete();
2711
+ }
2712
+ catch (err) {
2713
+ subscriber.error(err);
2714
+ }
2715
+ }
2716
+ }));
2717
+ };
2718
+ source.subscribe(createOperatorSubscriber(subscriber, outerNext, function () {
2719
+ isComplete = true;
2720
+ checkComplete();
2721
+ }));
2722
+ return function () {
2723
+ };
2724
+ }
2725
+
2726
+ function mergeMap(project, resultSelector, concurrent) {
2727
+ if (concurrent === void 0) { concurrent = Infinity; }
2728
+ if (isFunction(resultSelector)) {
2729
+ return mergeMap(function (a, i) { return map(function (b, ii) { return resultSelector(a, b, i, ii); })(innerFrom(project(a, i))); }, concurrent);
2730
+ }
2731
+ else if (typeof resultSelector === 'number') {
2732
+ concurrent = resultSelector;
2733
+ }
2734
+ return operate(function (source, subscriber) { return mergeInternals(source, subscriber, project, concurrent); });
2735
+ }
2736
+
2737
+ function forkJoin() {
2738
+ var args = [];
2739
+ for (var _i = 0; _i < arguments.length; _i++) {
2740
+ args[_i] = arguments[_i];
2741
+ }
2742
+ var resultSelector = popResultSelector(args);
2743
+ var _a = argsArgArrayOrObject(args), sources = _a.args, keys = _a.keys;
2744
+ var result = new Observable(function (subscriber) {
2745
+ var length = sources.length;
2746
+ if (!length) {
2747
+ subscriber.complete();
2748
+ return;
2749
+ }
2750
+ var values = new Array(length);
2751
+ var remainingCompletions = length;
2752
+ var remainingEmissions = length;
2753
+ var _loop_1 = function (sourceIndex) {
2754
+ var hasValue = false;
2755
+ innerFrom(sources[sourceIndex]).subscribe(createOperatorSubscriber(subscriber, function (value) {
2756
+ if (!hasValue) {
2757
+ hasValue = true;
2758
+ remainingEmissions--;
2759
+ }
2760
+ values[sourceIndex] = value;
2761
+ }, function () { return remainingCompletions--; }, undefined, function () {
2762
+ if (!remainingCompletions || !hasValue) {
2763
+ if (!remainingEmissions) {
2764
+ subscriber.next(keys ? createObject(keys, values) : values);
2765
+ }
2766
+ subscriber.complete();
2767
+ }
2768
+ }));
2769
+ };
2770
+ for (var sourceIndex = 0; sourceIndex < length; sourceIndex++) {
2771
+ _loop_1(sourceIndex);
2772
+ }
2773
+ });
2774
+ return resultSelector ? result.pipe(mapOneOrManyArgs(resultSelector)) : result;
2775
+ }
2776
+
2777
+ function concatMap(project, resultSelector) {
2778
+ return isFunction(resultSelector) ? mergeMap(project, resultSelector, 1) : mergeMap(project, 1);
2779
+ }
2780
+
2781
+ function tap(observerOrNext, error, complete) {
2782
+ var tapObserver = isFunction(observerOrNext) || error || complete
2783
+ ?
2784
+ { next: observerOrNext, error: error, complete: complete }
2785
+ : observerOrNext;
2786
+ return tapObserver
2787
+ ? operate(function (source, subscriber) {
2788
+ var _a;
2789
+ (_a = tapObserver.subscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
2790
+ var isUnsub = true;
2791
+ source.subscribe(createOperatorSubscriber(subscriber, function (value) {
2792
+ var _a;
2793
+ (_a = tapObserver.next) === null || _a === void 0 ? void 0 : _a.call(tapObserver, value);
2794
+ subscriber.next(value);
2795
+ }, function () {
2796
+ var _a;
2797
+ isUnsub = false;
2798
+ (_a = tapObserver.complete) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
2799
+ subscriber.complete();
2800
+ }, function (err) {
2801
+ var _a;
2802
+ isUnsub = false;
2803
+ (_a = tapObserver.error) === null || _a === void 0 ? void 0 : _a.call(tapObserver, err);
2804
+ subscriber.error(err);
2805
+ }, function () {
2806
+ var _a, _b;
2807
+ if (isUnsub) {
2808
+ (_a = tapObserver.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
2809
+ }
2810
+ (_b = tapObserver.finalize) === null || _b === void 0 ? void 0 : _b.call(tapObserver);
2811
+ }));
2812
+ })
2813
+ :
2814
+ identity;
2815
+ }
2816
+
2817
+ class NoBackingStore {
2818
+ getLocale() {
2819
+ return undefined;
2820
+ }
2821
+ setLocale(_) {
2822
+ // noop
2823
+ }
2824
+ }
2825
+ /**
2826
+ * The <code>LocaleManager</code> keeps track of the current locale as a behavior subject and knows about the array of supported locales.
2827
+ * Interested parties can subscribe to the current value.
2828
+ */
2829
+ class LocaleManager {
2830
+ // instance data
2831
+ locale = new BehaviorSubject(new Intl.Locale("en"));
2832
+ backingStore;
2833
+ supportedLocales;
2834
+ listeners = [];
2835
+ dirty = false;
2836
+ // static methods
2837
+ /**
2838
+ * return the browser locale
2839
+ */
2840
+ static getBrowserLocale() {
2841
+ if (typeof globalThis !== "undefined" && globalThis.navigator) {
2842
+ if (globalThis.navigator.languages && globalThis.navigator.languages.length) {
2843
+ return new Intl.Locale(globalThis.navigator.languages[0]);
2844
+ } else {
2845
+ return new Intl.Locale(globalThis.navigator.language);
2846
+ }
2847
+ }
2848
+ // fallback if navigator is not available (Node)
2849
+ return new Intl.Locale("en");
2850
+ }
2851
+ // constructor
2852
+ constructor(configuration) {
2853
+ this.backingStore = configuration.backingStore ?? new NoBackingStore();
2854
+ const initialLocale = configuration.backingStore?.getLocale() ?? (typeof configuration.locale === "string" ? new Intl.Locale(configuration.locale) : configuration.locale) ?? LocaleManager.getBrowserLocale();
2855
+ this.setLocale(initialLocale);
2856
+ this.supportedLocales = configuration.supportedLocales ?? [this.getLocale().baseName];
2857
+ // listen for changes
2858
+ this.locale.pipe(mergeMap(locale => from(this.getListeners())), concatMap(l => l.onLocaleChange.onLocaleChange(this.locale.value))).subscribe();
2859
+ }
2860
+ // private
2861
+ getListeners() {
2862
+ if (this.dirty) {
2863
+ this.listeners.sort((a, b) => a.priority === b.priority ? 0 : a.priority < b.priority ? -1 : 1);
2864
+ this.dirty = false;
2865
+ }
2866
+ return this.listeners;
2867
+ }
2868
+ // public
2869
+ /**
2870
+ * add the specified listener to the list of listeners that will be informed on every locale change.
2871
+ * @param onLocaleChange the listener
2872
+ * @param priority the priority. Smaller priorities are called earlier.
2873
+ */
2874
+ subscribe(onLocaleChange, priority = 10) {
2875
+ const subscription = {
2876
+ onLocaleChange,
2877
+ priority
2878
+ };
2879
+ this.listeners.push(subscription);
2880
+ this.dirty = true;
2881
+ return () => {
2882
+ const index = this.listeners.indexOf(subscription);
2883
+ if (index !== -1) this.listeners.splice(index, 1);
2884
+ };
2885
+ }
2886
+ /**
2887
+ * set the current locale
2888
+ * @param locale either string or an Intl.Locale object
2889
+ */
2890
+ setLocale(locale) {
2891
+ if (typeof locale === "string") locale = new Intl.Locale(locale);
2892
+ this.backingStore.setLocale(locale);
2893
+ this.locale.next(locale);
2894
+ }
2895
+ /**
2896
+ * return the current locale
2897
+ */
2898
+ getLocale() {
2899
+ return this.locale.value;
2900
+ }
2901
+ /**
2902
+ * return the list of supported locale codes
2903
+ */
2904
+ getLocales() {
2905
+ return this.supportedLocales;
2906
+ }
2907
+ }
2908
+
2909
+ class LocalStorageLocaleBackingStore {
2910
+ key;
2911
+ // constructor
2912
+ constructor(key) {
2913
+ this.key = key;
2914
+ }
2915
+ // implement LocaleBackingStore
2916
+ getLocale() {
2917
+ const localeCode = globalThis.localStorage.getItem(this.key);
2918
+ return localeCode ? new Intl.Locale(localeCode) : undefined;
2919
+ }
2920
+ setLocale(locale) {
2921
+ globalThis.localStorage.setItem(this.key, locale.baseName);
2922
+ }
2923
+ }
2924
+
2925
+ /**
2926
+ * this interface covers the strategy how missing translation values should appear on screen.
2927
+ */
2928
+ class MissingTranslationHandler {}
2929
+
2930
+ /**
2931
+ * A <code>Translator</code> is responsible to load and fetch i18n values given keys that consist of a namespace and a path.
2932
+ */
2933
+ class Translator {
2934
+ /**
2935
+ * an observable that will emit events whenever a namespace is loaded...
2936
+ */
2937
+ events() {
2938
+ throw Error("ocuh");
2939
+ }
2940
+ /**
2941
+ * make sure that the specified namespaces are laoded
2942
+ * @param namespaces list of namespaces
2943
+ */
2944
+ checkAndLoadNamespaces(...namespaces) {
2945
+ throw Error('ocuh');
2946
+ }
2947
+ /**
2948
+ * return an observable containing the translated key or the transformed key in case of missing values
2949
+ * @param key the translation key
2950
+ */
2951
+ translate$(key) {
2952
+ throw Error('ocuh');
2953
+ }
2954
+ /**
2955
+ * return the i18n value or the transformed key in case of missing values
2956
+ * @param key
2957
+ */
2958
+ translate(key) {
2959
+ throw Error('ocuh');
2960
+ }
2961
+ /**
2962
+ * return an observable containing all values for the specific namespace
2963
+ * @param namespace
2964
+ */
2965
+ findTranslationFor$(namespace) {
2966
+ throw Error('ocuh');
2967
+ }
2968
+ /**
2969
+ * return all values for the specific namespace, assuming that they have been already loaded
2970
+ * @param namespace
2971
+ */
2972
+ findTranslationFor(namespace) {
2973
+ throw Error('ocuh');
2974
+ }
2975
+ }
2976
+
2977
+ /**
2978
+ * this interface needs to be implemented in order to load i18n values.
2979
+ */
2980
+ class I18NLoader {}
2981
+
2982
+ /**
2983
+ * an {@link AbstractCachingTranslator} is an abstract base class for translators that cache loaded translations
2984
+ */
2985
+ class AbstractCachingTranslator extends Translator {
2986
+ missingTranslationHandler;
2987
+ // instance data
2988
+ cachedNamespaces = {};
2989
+ reloading = false;
2990
+ //@logger("i18n")
2991
+ //protected logger: Logger | undefined
2992
+ // constructor
2993
+ constructor(missingTranslationHandler) {
2994
+ super();
2995
+ this.missingTranslationHandler = missingTranslationHandler;
2996
+ }
2997
+ // protected
2998
+ isLoaded(namespace) {
2999
+ return this.cachedNamespaces[namespace] != undefined;
3000
+ }
3001
+ // private
3002
+ // name.space.name OR
3003
+ // name.space:path.name
3004
+ extractNamespace(key) {
3005
+ let namespace;
3006
+ let path;
3007
+ const colon = key.indexOf(":");
3008
+ if (colon > 0) {
3009
+ namespace = key.substring(0, colon);
3010
+ path = key.substring(colon + 1);
3011
+ } else {
3012
+ // assume that everything but the last is the namespace
3013
+ const byDots = key.split(".");
3014
+ const name = byDots.pop();
3015
+ namespace = byDots.join(".");
3016
+ path = `${name}.${name}`;
3017
+ }
3018
+ return {
3019
+ namespace: namespace,
3020
+ path: path
3021
+ };
3022
+ }
3023
+ // implement Translator
3024
+ /**
3025
+ * @inheritDoc
3026
+ */
3027
+ findTranslationFor(namespace) {
3028
+ return this.cachedNamespaces[namespace];
3029
+ }
3030
+ /**
3031
+ * @inheritDoc
3032
+ */
3033
+ translate(key) {
3034
+ const {
3035
+ namespace,
3036
+ path
3037
+ } = this.extractNamespace(key);
3038
+ const translation = this.get(this.cachedNamespaces[namespace], path);
3039
+ return translation || this.missingTranslationHandler.resolve(key);
3040
+ }
3041
+ // protected
3042
+ get(values, key) {
3043
+ const path = key.split(".");
3044
+ let index = 0;
3045
+ const length = path.length;
3046
+ let object = values;
3047
+ while (object != null && index < length) object = Reflect.get(object, path[index++]);
3048
+ return index && index == length ? object : undefined;
3049
+ }
3050
+ }
3051
+
3052
+ /**
3053
+ * the {@link StandardTranslator} is a caching translator that delegates loading requests to a {@link I18NLoader}
3054
+ */
3055
+ class StandardTranslator extends AbstractCachingTranslator {
3056
+ loader;
3057
+ // instance data
3058
+ locale;
3059
+ event = new BehaviorSubject({
3060
+ type: "initial"
3061
+ });
3062
+ // constructor
3063
+ constructor(loader, missingTranslationHandler, localeManager) {
3064
+ super(missingTranslationHandler);
3065
+ this.loader = loader;
3066
+ // start with current locale
3067
+ this.locale = localeManager.getLocale();
3068
+ // subscribe to locale manager
3069
+ localeManager.subscribe(this, 0);
3070
+ }
3071
+ // public
3072
+ events() {
3073
+ return this.event;
3074
+ }
3075
+ async loadNamespace(namespace) {
3076
+ //this.logger!.info(`loading namespace '${namespace}' for locale '${this.locale.baseName}'`)
3077
+ return this.loader.loadNamespace(this.locale, namespace).then(translations => {
3078
+ //this.logger!.info(`cache namespace '${namespace}' for locale '${this.locale.baseName}'`)
3079
+ this.cachedNamespaces[namespace] = translations;
3080
+ if (!this.reloading) this.event.next({
3081
+ type: "load-namespace",
3082
+ namespace: namespace
3083
+ });
3084
+ });
3085
+ }
3086
+ async checkAndLoadNamespaces(...namespaces) {
3087
+ for (const namespace of namespaces) if (!this.cachedNamespaces[namespace]) await this.loadNamespace(namespace);
3088
+ }
3089
+ // override
3090
+ translate$(key) {
3091
+ const {
3092
+ namespace
3093
+ } = this.extractNamespace(key);
3094
+ const translations = this.cachedNamespaces[namespace];
3095
+ if (translations) return Promise.resolve(this.translate(key));else return this.loadNamespace(namespace).then(translations => Promise.resolve(this.translate(key)));
3096
+ }
3097
+ findTranslationFor$(namespace) {
3098
+ const translations = this.cachedNamespaces[namespace];
3099
+ if (translations) return Promise.resolve(translations);else return this.loadNamespace(namespace);
3100
+ }
3101
+ // implement OnLocaleChange
3102
+ /**
3103
+ * @inheritDoc
3104
+ */
3105
+ onLocaleChange(locale) {
3106
+ this.locale = locale;
3107
+ const namespaces = this.cachedNamespaces;
3108
+ this.cachedNamespaces = {};
3109
+ // reload all namespaces
3110
+ this.reloading = true;
3111
+ return forkJoin(Object.keys(namespaces).map(n => from(this.loadNamespace(n)))).pipe(tap(() => {
3112
+ this.reloading = false;
3113
+ this.event.next({
3114
+ type: "switch-locale",
3115
+ locale: locale
3116
+ });
3117
+ }));
3118
+ }
3119
+ }
3120
+
3121
+ /**
3122
+ * The default implementation of a {@link MissingTranslationHandler} that simply wraps the key with '##' around it.
3123
+ */
3124
+ class DefaultMissingTranslationHandler {
3125
+ resolve(key) {
3126
+ return `##${key}##`;
3127
+ }
3128
+ }
3129
+
3130
+ /**
3131
+ * a {@link I18NLoader} tah will load translations form the static assets
3132
+ */
3133
+ class AssetTranslationLoader {
3134
+ // instance data
3135
+ loading = {};
3136
+ path = "/i18n/";
3137
+ // constructor
3138
+ constructor(config) {
3139
+ this.path = config.path || "/i18n/";
3140
+ }
3141
+ // implement I18nLoader
3142
+ /**
3143
+ * @inheritDoc
3144
+ */
3145
+ loadNamespace(locale, namespace) {
3146
+ const key = `${locale.baseName}.${namespace}`;
3147
+ const loading = this.loading[key];
3148
+ if (loading) {
3149
+ return loading;
3150
+ } else {
3151
+ //this.logger.info(`loading namespace '${namespace}' for locale '${locale.baseName}'`)
3152
+ return this.loading[key] = fetch(`${this.path}${namespace}/${locale.baseName}.json`).then(response => response.json());
3153
+ }
3154
+ }
3155
+ }
3156
+
3157
+ let PlaceholderParser = class PlaceholderParser {
3158
+ // instance data
3159
+ variable = /^{(?<variable>\w+)}$/;
3160
+ variableFormat = /^{(?<variable>\w+)\s*:\s*(?<format>\w+)}$/;
3161
+ variableFormatArgs = /^{(?<variable>\w+)\s*:\s*(?<format>\w+)\((?<parameter>\w+\s*:\s*(\d+|'\w+')(\s*,\s*\w+\s*:\s*(-?\d+|'\w+'|true|false))*)\)}$/;
3162
+ parameter = /\s*(?<parameter>\w+)\s*:\s*(?<value>-?\d+|'\w+'|true|false)(?:,|$)*/g;
3163
+ // public
3164
+ parse(input) {
3165
+ // variable
3166
+ let result;
3167
+ if (result = input.match(this.variable)) {
3168
+ return {
3169
+ name: result.groups['variable']
3170
+ };
3171
+ }
3172
+ // variable:format
3173
+ else if (result = input.match(this.variableFormat)) {
3174
+ return {
3175
+ name: result.groups['variable'],
3176
+ format: {
3177
+ format: result.groups['format']
3178
+ }
3179
+ };
3180
+ }
3181
+ // variable:format(<param>:<value>, ...)
3182
+ else if (result = input.match(this.variableFormatArgs)) {
3183
+ const formatParameter = {};
3184
+ const format = {
3185
+ name: result.groups['variable'],
3186
+ format: {
3187
+ format: result.groups['format'],
3188
+ parameters: formatParameter
3189
+ }
3190
+ };
3191
+ const parameters = result.groups['parameter'];
3192
+ // parse parameters individually
3193
+ while (result = this.parameter.exec(parameters)) {
3194
+ const parameter = result.groups['parameter'];
3195
+ let value = result.groups['value'];
3196
+ if (value.startsWith("'")) value = value.substring(1, value.length - 1);else if (value == 'true') value = true;else if (value == 'false') value = false;else {
3197
+ if (value.startsWith('-')) value = -+value.substring(1);else value = +value;
3198
+ }
3199
+ // @ts-expect-error: dunno
3200
+ formatParameter[parameter] = value;
3201
+ }
3202
+ return format;
3203
+ } else throw new Error('could not parse ' + input);
3204
+ }
3205
+ };
3206
+ PlaceholderParser = __decorate([injectable()], PlaceholderParser);
3207
+
3208
+ var FormatterRegistry_1;
3209
+ /**
3210
+ * The <code>FormatterRegistry</code> is the registry for known formatters and the main api for formatting requests.
3211
+ */
3212
+ let FormatterRegistry = class FormatterRegistry {
3213
+ static {
3214
+ FormatterRegistry_1 = this;
3215
+ }
3216
+ localeManager;
3217
+ // instance data
3218
+ static registry = {};
3219
+ // constructor
3220
+ constructor(localeManager) {
3221
+ this.localeManager = localeManager;
3222
+ }
3223
+ // public
3224
+ /**
3225
+ * format a given value.
3226
+ * @param type the formatter name
3227
+ * @param value the value
3228
+ * @param options formatter options
3229
+ */
3230
+ format(type, value, options) {
3231
+ const formatter = FormatterRegistry_1.registry[type];
3232
+ if (formatter) return formatter.format(this.localeManager.getLocale(), value, options);else throw new Error(`unknown formatter "${type}"`);
3233
+ }
3234
+ /**
3235
+ * register a specific formatter
3236
+ * @param type the formatter name
3237
+ * @param formatter the formatter
3238
+ */
3239
+ static register(type, formatter) {
3240
+ this.registry[type] = formatter;
3241
+ }
3242
+ };
3243
+ FormatterRegistry = FormatterRegistry_1 = __decorate([injectable(), __metadata("design:paramtypes", [LocaleManager])], FormatterRegistry);
3244
+
3245
+ var FormatterRegistry$1 = /*#__PURE__*/Object.freeze({
3246
+ __proto__: null,
3247
+ get FormatterRegistry () { return FormatterRegistry; }
3248
+ });
3249
+
3250
+ const formatter = type => {
3251
+ return formatterClass => {
3252
+ Promise.resolve().then(function () { return FormatterRegistry$1; }).then(() => {
3253
+ FormatterRegistry.register(type, new formatterClass());
3254
+ });
3255
+ };
3256
+ };
3257
+
3258
+ /**
3259
+ * formatter for dates according to the Intl.DateTimeFormat
3260
+ */
3261
+ let DateFormatter = class DateFormatter {
3262
+ // implement ValueFormatter
3263
+ /**
3264
+ * @inheritdoc
3265
+ */
3266
+ format(locale, value, format) {
3267
+ return new Intl.DateTimeFormat(format?.locale ? format.locale : locale.baseName, format).format(value);
3268
+ }
3269
+ };
3270
+ DateFormatter = __decorate([formatter("date")], DateFormatter);
3271
+
3272
+ /**
3273
+ * formatter for numbers
3274
+ */
3275
+ let NumberFormatter = class NumberFormatter {
3276
+ // implement ValueFormatter
3277
+ /**
3278
+ * @inheritdoc
3279
+ */
3280
+ format(locale, value, format) {
3281
+ return new Intl.NumberFormat(format?.locale ? format.locale : locale.baseName, format).format(value);
3282
+ }
3283
+ };
3284
+ NumberFormatter = __decorate([formatter("number")], NumberFormatter);
3285
+
3286
+ /**
3287
+ * formatter for strings
3288
+ */
3289
+ let StringFormatter = class StringFormatter {
3290
+ // implement ValueFormatter
3291
+ /**
3292
+ * @inheritdoc
3293
+ */
3294
+ format(locale, value, format) {
3295
+ return value;
3296
+ }
3297
+ };
3298
+ StringFormatter = __decorate([formatter("string")], StringFormatter);
3299
+
3300
+ const isText = chunk => {
3301
+ return chunk.start !== undefined;
3302
+ };
3303
+ /**
3304
+ * The service <code>Interpolator</code> is a tiny templating engine that will replace placeholders by real values.
3305
+ * The replacements can refer to specific formatters that can respect specific formatting options.
3306
+ *
3307
+ */
3308
+ let Interpolator = class Interpolator {
3309
+ parser;
3310
+ formatterRegistry;
3311
+ // instance data
3312
+ cache = new LRUCache();
3313
+ useCaching = true;
3314
+ // constructor
3315
+ constructor(parser, formatterRegistry) {
3316
+ this.parser = parser;
3317
+ this.formatterRegistry = formatterRegistry;
3318
+ }
3319
+ // private
3320
+ interpolator(input) {
3321
+ let interpolator = this.cache.get(input);
3322
+ if (!interpolator) interpolator = this.cache.put(input, this.compile(input));
3323
+ return interpolator;
3324
+ }
3325
+ compile(input) {
3326
+ const components = [];
3327
+ let start = 0;
3328
+ let index = input.indexOf("{");
3329
+ if (index >= 0) {
3330
+ while (index >= 0) {
3331
+ // add up to first bracket
3332
+ components.push({
3333
+ start: start,
3334
+ end: index
3335
+ });
3336
+ start = index;
3337
+ index = input.indexOf("}", index + 1);
3338
+ // add bracket
3339
+ const placeholder = input.substring(start, index + 1);
3340
+ components.push(this.parser.parse(placeholder));
3341
+ // next
3342
+ start = index + 1;
3343
+ index = input.indexOf("{", start);
3344
+ } // while
3345
+ // add end
3346
+ components.push({
3347
+ start: start,
3348
+ end: input.length
3349
+ });
3350
+ } else {
3351
+ components.push({
3352
+ start: 0,
3353
+ end: input.length
3354
+ });
3355
+ }
3356
+ return parameters => {
3357
+ const builder = new StringBuilder();
3358
+ for (const element of components) {
3359
+ if (isText(element)) builder.append(input.substring(element.start, element.end));else {
3360
+ let parameter = parameters[element.name];
3361
+ if (parameter == undefined) throw new Error("unknown parameter " + element.name);
3362
+ // either we get a literal value of a Format with {value: .. format: parameters...}
3363
+ let type;
3364
+ let formatParams = undefined;
3365
+ // supplied format
3366
+ if (parameter.format !== undefined) {
3367
+ type = parameter.format;
3368
+ formatParams = parameter.parameters;
3369
+ parameter = parameter.value;
3370
+ }
3371
+ // from spec
3372
+ else if (element.format) {
3373
+ type = element.format.format;
3374
+ formatParams = element.format.parameters;
3375
+ }
3376
+ // from value
3377
+ else {
3378
+ if (parameter instanceof Date) type = "date";else type = typeof parameters[element.name]; //
3379
+ }
3380
+ builder.append(this.formatterRegistry.format(type, parameter, formatParams));
3381
+ }
3382
+ } // for
3383
+ return builder.toString();
3384
+ };
3385
+ }
3386
+ // public
3387
+ interpolate(input, parameters) {
3388
+ if (this.useCaching) return this.interpolator(input)(parameters);
3389
+ let start = 0;
3390
+ let index = input.indexOf("{");
3391
+ if (index >= 0) {
3392
+ const builder = new StringBuilder();
3393
+ while (index >= 0) {
3394
+ // add up to first bracket
3395
+ builder.append(input.substring(start, index));
3396
+ start = index;
3397
+ index = input.indexOf("}", index + 1);
3398
+ // add bracket
3399
+ builder.append(this.interpolatePlaceholder(input.substring(start, index + 1), parameters));
3400
+ // next
3401
+ start = index + 1;
3402
+ index = input.indexOf("{", start);
3403
+ } // while
3404
+ // add end
3405
+ builder.append(input.substring(start));
3406
+ // done
3407
+ return builder.toString();
3408
+ } else return input;
3409
+ }
3410
+ interpolatePlaceholder(input, parameters) {
3411
+ const placeholder = this.parser.parse(input);
3412
+ return this.formatterRegistry.format(placeholder.format.format, parameters[placeholder.name], placeholder.format.parameters);
3413
+ }
3414
+ };
3415
+ Interpolator = __decorate([injectable(), __metadata("design:paramtypes", [PlaceholderParser, FormatterRegistry])], Interpolator);
3416
+
3417
+ /**
3418
+ * <code>TranslatorBuilder</code> is s simple fluent builder used to construct a {@link Translator} instance
3419
+ */
3420
+ class TranslatorBuilder {
3421
+ // instance data
3422
+ _missingTranslationHandler;
3423
+ _I18NLoader;
3424
+ _localeManager;
3425
+ // fluent
3426
+ /**
3427
+ * set the loader
3428
+ * @param loader an {@link I18NLoader}
3429
+ */
3430
+ loader(loader) {
3431
+ this._I18NLoader = loader;
3432
+ return this;
3433
+ }
3434
+ /**
3435
+ * set the locale manager
3436
+ * @param manager an {@link LocaleManager}
3437
+ */
3438
+ localeManager(manager) {
3439
+ this._localeManager = manager;
3440
+ return this;
3441
+ }
3442
+ /**
3443
+ * set the {@link MissingTranslationHandler}
3444
+ * @param handler the {@link MissingTranslationHandler}
3445
+ */
3446
+ missingTranslationHandler(handler) {
3447
+ this._missingTranslationHandler = handler;
3448
+ return this;
3449
+ }
3450
+ // build
3451
+ /**
3452
+ * create and return the resulting {@Translator}
3453
+ */
3454
+ build() {
3455
+ // add defaults
3456
+ if (!this._missingTranslationHandler) this._missingTranslationHandler = new DefaultMissingTranslationHandler();
3457
+ // validate
3458
+ if (!this._I18NLoader) throw new Error("translator needs a loader");
3459
+ // done
3460
+ return new StandardTranslator(this._I18NLoader, this._missingTranslationHandler, this._localeManager);
3461
+ }
3462
+ }
3463
+
3464
+ export { AbstractCachingTranslator, AssetTranslationLoader, DateFormatter, DefaultMissingTranslationHandler, FormatterRegistry, I18NLoader, Interpolator, LocalStorageLocaleBackingStore, LocaleManager, MissingTranslationHandler, NumberFormatter, StandardTranslator, StringFormatter, Translator, TranslatorBuilder, formatter };
3465
+ //# sourceMappingURL=index.esm.js.map