static-injector 5.0.2 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/import/change_detection/scheduling/zoneless_scheduling.d.ts +37 -0
  2. package/import/change_detection/scheduling/zoneless_scheduling_impl.d.ts +16 -0
  3. package/import/core_reactivity_export_internal.d.ts +17 -0
  4. package/import/di/contextual.d.ts +36 -0
  5. package/{typings → import}/di/create_injector.d.ts +1 -1
  6. package/{typings → import}/di/forward_ref.d.ts +2 -2
  7. package/import/di/index.d.ts +3 -0
  8. package/{typings → import}/di/initializer_token.d.ts +8 -1
  9. package/{typings → import}/di/inject_switch.d.ts +2 -2
  10. package/{typings → import}/di/injectable.d.ts +2 -2
  11. package/{typings → import}/di/injection_token.d.ts +3 -4
  12. package/{typings → import}/di/injector.d.ts +1 -1
  13. package/{typings → import}/di/injector_compatibility.d.ts +1 -1
  14. package/{typings → import}/di/injector_marker.d.ts +1 -1
  15. package/{typings → import}/di/injector_token.d.ts +1 -1
  16. package/{typings → import}/di/interface/defs.d.ts +1 -1
  17. package/{typings → import}/di/interface/injector.d.ts +1 -1
  18. package/{typings → import}/di/interface/provider.d.ts +1 -1
  19. package/{typings → import}/di/internal_tokens.d.ts +1 -1
  20. package/{typings → import}/di/metadata.d.ts +5 -9
  21. package/{typings → import}/di/null_injector.d.ts +1 -1
  22. package/{typings → import}/di/provider_collection.d.ts +31 -3
  23. package/{typings → import}/di/provider_token.d.ts +1 -1
  24. package/{typings → import}/di/r3_injector.d.ts +2 -2
  25. package/{typings → import}/di/scope.d.ts +1 -1
  26. package/{typings → import}/di.d.ts +1 -1
  27. package/import/error_handler.d.ts +45 -0
  28. package/{typings → import}/errors.d.ts +9 -7
  29. package/import/index.d.ts +37 -0
  30. package/{typings → import}/interface/lifecycle_hooks.d.ts +1 -1
  31. package/{typings → import}/interface/type.d.ts +4 -9
  32. package/import/linker/destroy_ref.d.ts +44 -0
  33. package/import/pending_tasks.d.ts +78 -0
  34. package/{typings → import}/render3/definition_factory.d.ts +1 -1
  35. package/{typings → import}/render3/errors_di.d.ts +1 -1
  36. package/{typings → import}/render3/fields.d.ts +1 -1
  37. package/{typings → import}/render3/instructions/di.d.ts +1 -1
  38. package/import/render3/reactivity/api.d.ts +27 -0
  39. package/import/render3/reactivity/asserts.d.ts +16 -0
  40. package/import/render3/reactivity/computed.d.ts +25 -0
  41. package/import/render3/reactivity/effect.d.ts +121 -0
  42. package/import/render3/reactivity/linked_signal.d.ts +33 -0
  43. package/import/render3/reactivity/microtask_effect.d.ts +21 -0
  44. package/import/render3/reactivity/patch.d.ts +11 -0
  45. package/import/render3/reactivity/root_effect_scheduler.d.ts +54 -0
  46. package/import/render3/reactivity/signal.d.ts +61 -0
  47. package/import/render3/reactivity/untracked.d.ts +12 -0
  48. package/import/resource/api.d.ts +219 -0
  49. package/{es2022/di/injectable.js → import/resource/index.d.ts} +3 -2
  50. package/import/resource/resource.d.ts +89 -0
  51. package/import/util/callback_scheduler.d.ts +35 -0
  52. package/{typings → import}/util/closure.d.ts +1 -1
  53. package/{typings → import}/util/decorators.d.ts +3 -3
  54. package/{typings → import}/util/empty.d.ts +1 -1
  55. package/{es2022/di/provider_token.js → import/util/noop.d.ts} +2 -2
  56. package/{typings → import}/util/property.d.ts +1 -1
  57. package/{typings → import}/util/stringify.d.ts +1 -1
  58. package/index.js +2349 -0
  59. package/index.js.map +7 -0
  60. package/index.mjs +2258 -0
  61. package/index.mjs.map +7 -0
  62. package/package.json +19 -10
  63. package/primitives/signals/index.d.ts +15 -0
  64. package/primitives/signals/src/computed.d.ts +55 -0
  65. package/primitives/signals/src/equality.d.ts +15 -0
  66. package/primitives/signals/src/errors.d.ts +10 -0
  67. package/primitives/signals/src/graph.d.ts +182 -0
  68. package/primitives/signals/src/linked_signal.d.ts +72 -0
  69. package/primitives/signals/src/signal.d.ts +29 -0
  70. package/primitives/signals/src/watch.d.ts +43 -0
  71. package/{es2022/di/injector_marker.js → primitives/signals/src/weak_ref.d.ts} +2 -2
  72. package/readme.md +17 -13
  73. package/commonjs/index.js +0 -1586
  74. package/es2022/di/create_injector.js +0 -32
  75. package/es2022/di/forward_ref.js +0 -80
  76. package/es2022/di/index.js +0 -1
  77. package/es2022/di/initializer_token.js +0 -15
  78. package/es2022/di/inject_switch.js +0 -51
  79. package/es2022/di/injection_token.js +0 -93
  80. package/es2022/di/injector.js +0 -60
  81. package/es2022/di/injector_compatibility.js +0 -265
  82. package/es2022/di/injector_token.js +0 -20
  83. package/es2022/di/interface/defs.js +0 -110
  84. package/es2022/di/interface/injector.js +0 -26
  85. package/es2022/di/interface/provider.js +0 -10
  86. package/es2022/di/internal_tokens.js +0 -9
  87. package/es2022/di/metadata.js +0 -48
  88. package/es2022/di/null_injector.js +0 -19
  89. package/es2022/di/provider_collection.js +0 -104
  90. package/es2022/di/r3_injector.js +0 -449
  91. package/es2022/di/scope.js +0 -14
  92. package/es2022/di.js +0 -24
  93. package/es2022/errors.js +0 -44
  94. package/es2022/index.js +0 -19
  95. package/es2022/interface/lifecycle_hooks.js +0 -8
  96. package/es2022/interface/type.js +0 -21
  97. package/es2022/render3/definition_factory.js +0 -10
  98. package/es2022/render3/errors_di.js +0 -13
  99. package/es2022/render3/fields.js +0 -22
  100. package/es2022/render3/instructions/di.js +0 -23
  101. package/es2022/render3/util/stringify_utils.js +0 -38
  102. package/es2022/util/closure.js +0 -19
  103. package/es2022/util/decorators.js +0 -31
  104. package/es2022/util/empty.js +0 -18
  105. package/es2022/util/property.js +0 -15
  106. package/es2022/util/stringify.js +0 -45
  107. package/fesm2022/index.js +0 -1547
  108. package/typings/di/index.d.ts +0 -1
  109. package/typings/index.d.ts +0 -18
  110. package/typings/render3/util/stringify_utils.d.ts +0 -21
package/index.mjs ADDED
@@ -0,0 +1,2258 @@
1
+ // src/import/errors.ts
2
+ var RuntimeError = class extends Error {
3
+ constructor(code, message) {
4
+ super(formatRuntimeError(code, message));
5
+ this.code = code;
6
+ }
7
+ };
8
+ function formatRuntimeError(code, message) {
9
+ const fullCode = `NG0${Math.abs(code)}`;
10
+ const errorMessage = `${fullCode}${message ? ": " + message : ""}`;
11
+ if (false) {
12
+ }
13
+ return errorMessage;
14
+ }
15
+
16
+ // src/import/render3/definition_factory.ts
17
+ function getFactoryDef(type, throwNotFound) {
18
+ return () => new type();
19
+ }
20
+
21
+ // src/import/util/property.ts
22
+ function getClosureSafeProperty(objWithPropertyToExtract) {
23
+ for (const key in objWithPropertyToExtract) {
24
+ if (objWithPropertyToExtract[key] === getClosureSafeProperty) {
25
+ return key;
26
+ }
27
+ }
28
+ throw Error("Could not find renamed property on target object.");
29
+ }
30
+
31
+ // src/import/render3/fields.ts
32
+ var NG_FACTORY_DEF = getClosureSafeProperty({
33
+ ɵfac: getClosureSafeProperty
34
+ });
35
+ var NG_ENV_ID = getClosureSafeProperty({
36
+ __NG_ENV_ID__: getClosureSafeProperty
37
+ });
38
+
39
+ // src/import/util/empty.ts
40
+ var EMPTY_ARRAY = [];
41
+ if (false) {
42
+ }
43
+
44
+ // src/import/util/stringify.ts
45
+ function stringify(token) {
46
+ if (typeof token === "string") {
47
+ return token;
48
+ }
49
+ if (Array.isArray(token)) {
50
+ return `[${token.map(stringify).join(", ")}]`;
51
+ }
52
+ if (token == null) {
53
+ return "" + token;
54
+ }
55
+ const name = token.overriddenName || token.name;
56
+ if (name) {
57
+ return `${name}`;
58
+ }
59
+ const result = token.toString();
60
+ if (result == null) {
61
+ return "" + result;
62
+ }
63
+ const newLineIndex = result.indexOf("\n");
64
+ return newLineIndex >= 0 ? result.slice(0, newLineIndex) : result;
65
+ }
66
+
67
+ // src/import/di/forward_ref.ts
68
+ var __forward_ref__ = getClosureSafeProperty({
69
+ __forward_ref__: getClosureSafeProperty
70
+ });
71
+ function forwardRef(forwardRefFn) {
72
+ forwardRefFn.__forward_ref__ = forwardRef;
73
+ forwardRefFn.toString = function() {
74
+ return stringify(this());
75
+ };
76
+ return forwardRefFn;
77
+ }
78
+ function resolveForwardRef(type) {
79
+ return isForwardRef(type) ? type() : type;
80
+ }
81
+ function isForwardRef(fn) {
82
+ return typeof fn === "function" && fn.hasOwnProperty(__forward_ref__) && fn.__forward_ref__ === forwardRef;
83
+ }
84
+
85
+ // src/import/di/interface/defs.ts
86
+ function ɵɵdefineInjectable(opts) {
87
+ return {
88
+ token: opts.token,
89
+ providedIn: opts.providedIn || null,
90
+ factory: opts.factory,
91
+ value: void 0
92
+ };
93
+ }
94
+ function ɵɵdefineInjector(options) {
95
+ return { providers: options.providers || [], imports: options.imports || [] };
96
+ }
97
+ function getInjectableDef(type) {
98
+ return getOwnDefinition(type, NG_PROV_DEF) || {
99
+ token: type,
100
+ factory: () => new type(),
101
+ ...type.injectOptions
102
+ };
103
+ }
104
+ function isInjectable(type) {
105
+ return getInjectableDef(type) !== null;
106
+ }
107
+ function getOwnDefinition(type, field) {
108
+ return type.hasOwnProperty(field) ? type[field] : null;
109
+ }
110
+ function getInheritedInjectableDef(type) {
111
+ const def = type && (type[NG_PROV_DEF] || null);
112
+ if (def) {
113
+ return def;
114
+ } else {
115
+ return null;
116
+ }
117
+ }
118
+ function getInjectorDef(type) {
119
+ return type && (type.hasOwnProperty(NG_INJ_DEF) || false) ? type[NG_INJ_DEF] : null;
120
+ }
121
+ var NG_PROV_DEF = getClosureSafeProperty({
122
+ ɵprov: getClosureSafeProperty
123
+ });
124
+ var NG_INJ_DEF = getClosureSafeProperty({
125
+ ɵinj: getClosureSafeProperty
126
+ });
127
+
128
+ // src/import/di/injection_token.ts
129
+ var InjectionToken = class {
130
+ /**
131
+ * @param _desc Description for the token,
132
+ * used only for debugging purposes,
133
+ * it should but does not need to be unique
134
+ * @param options Options for the token's usage, as described above
135
+ */
136
+ constructor(_desc, options) {
137
+ this._desc = _desc;
138
+ this.ɵprov = void 0;
139
+ if (typeof options === "number") {
140
+ } else if (options !== void 0) {
141
+ this.ɵprov = ɵɵdefineInjectable({
142
+ token: this,
143
+ providedIn: options.providedIn || "root",
144
+ factory: options.factory
145
+ });
146
+ }
147
+ }
148
+ /** @internal */
149
+ ngMetadataName = "InjectionToken";
150
+ ɵprov;
151
+ /**
152
+ * @internal
153
+ */
154
+ get multi() {
155
+ return this;
156
+ }
157
+ toString() {
158
+ return `InjectionToken ${this._desc}`;
159
+ }
160
+ };
161
+
162
+ // src/import/di/initializer_token.ts
163
+ var ENVIRONMENT_INITIALIZER = new InjectionToken("");
164
+
165
+ // src/import/render3/errors_di.ts
166
+ function throwProviderNotFoundError(token, injectorName) {
167
+ const errorMessage = null;
168
+ throw new RuntimeError(-201 /* PROVIDER_NOT_FOUND */, errorMessage);
169
+ }
170
+
171
+ // src/import/di/interface/injector.ts
172
+ var DecoratorFlags = /* @__PURE__ */ ((DecoratorFlags2) => {
173
+ DecoratorFlags2[DecoratorFlags2["Inject"] = -1] = "Inject";
174
+ return DecoratorFlags2;
175
+ })(DecoratorFlags || {});
176
+ var InjectFlags = /* @__PURE__ */ ((InjectFlags2) => {
177
+ InjectFlags2[InjectFlags2["Default"] = 0] = "Default";
178
+ InjectFlags2[InjectFlags2["Self"] = 2] = "Self";
179
+ InjectFlags2[InjectFlags2["SkipSelf"] = 4] = "SkipSelf";
180
+ InjectFlags2[InjectFlags2["Optional"] = 8] = "Optional";
181
+ return InjectFlags2;
182
+ })(InjectFlags || {});
183
+ var InternalInjectFlags = /* @__PURE__ */ ((InternalInjectFlags2) => {
184
+ InternalInjectFlags2[InternalInjectFlags2["Default"] = 0] = "Default";
185
+ InternalInjectFlags2[InternalInjectFlags2["Self"] = 2] = "Self";
186
+ InternalInjectFlags2[InternalInjectFlags2["SkipSelf"] = 4] = "SkipSelf";
187
+ InternalInjectFlags2[InternalInjectFlags2["Optional"] = 8] = "Optional";
188
+ return InternalInjectFlags2;
189
+ })(InternalInjectFlags || {});
190
+
191
+ // src/import/di/inject_switch.ts
192
+ var _injectImplementation;
193
+ function getInjectImplementation() {
194
+ return _injectImplementation;
195
+ }
196
+ function setInjectImplementation(impl) {
197
+ const previous = _injectImplementation;
198
+ _injectImplementation = impl;
199
+ return previous;
200
+ }
201
+ function injectRootLimpMode(token, notFoundValue, flags) {
202
+ const injectableDef = getInjectableDef(token);
203
+ if (injectableDef && injectableDef.providedIn == "root") {
204
+ return injectableDef.value === void 0 ? injectableDef.value = injectableDef.factory() : injectableDef.value;
205
+ }
206
+ if (flags & 8 /* Optional */) return null;
207
+ if (notFoundValue !== void 0) return notFoundValue;
208
+ throwProviderNotFoundError(token, "Injector");
209
+ }
210
+
211
+ // src/import/di/injector_compatibility.ts
212
+ var _THROW_IF_NOT_FOUND = {};
213
+ var THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;
214
+ var DI_DECORATOR_FLAG = "__NG_DI_FLAG__";
215
+ var NG_TEMP_TOKEN_PATH = "ngTempTokenPath";
216
+ var NG_TOKEN_PATH = "ngTokenPath";
217
+ var NEW_LINE = /\n/gm;
218
+ var NO_NEW_LINE = "ɵ";
219
+ var SOURCE = "__source";
220
+ var _currentInjector = void 0;
221
+ function getCurrentInjector() {
222
+ return _currentInjector;
223
+ }
224
+ function setCurrentInjector(injector) {
225
+ const former = _currentInjector;
226
+ _currentInjector = injector;
227
+ return former;
228
+ }
229
+ function injectInjectorOnly(token, flags = 0 /* Default */) {
230
+ if (_currentInjector === void 0) {
231
+ throw new RuntimeError(-203 /* MISSING_INJECTION_CONTEXT */, null);
232
+ } else if (_currentInjector === null) {
233
+ return injectRootLimpMode(token, void 0, flags);
234
+ } else {
235
+ const value = _currentInjector.get(
236
+ token,
237
+ flags & 8 /* Optional */ ? null : void 0,
238
+ flags
239
+ );
240
+ return value;
241
+ }
242
+ }
243
+ function ɵɵinject(token, flags = 0 /* Default */) {
244
+ return (getInjectImplementation() || injectInjectorOnly)(
245
+ resolveForwardRef(token),
246
+ flags
247
+ );
248
+ }
249
+ function ɵɵinvalidFactoryDep(index) {
250
+ throw new RuntimeError(202 /* INVALID_FACTORY_DEPENDENCY */, null);
251
+ }
252
+ function inject(token, flags = 0 /* Default */) {
253
+ return ɵɵinject(token, convertToBitFlags(flags));
254
+ }
255
+ function convertToBitFlags(flags) {
256
+ if (typeof flags === "undefined" || typeof flags === "number") {
257
+ return flags;
258
+ }
259
+ return 0 /* Default */ | // comment to force a line break in the formatter
260
+ (flags.optional && 8 /* Optional */) | 0 | (flags.self && 2 /* Self */) | (flags.skipSelf && 4 /* SkipSelf */);
261
+ }
262
+ function injectArgs(types) {
263
+ const args = [];
264
+ for (let i = 0; i < types.length; i++) {
265
+ const arg = resolveForwardRef(types[i]);
266
+ if (Array.isArray(arg)) {
267
+ if (arg.length === 0) {
268
+ throw new RuntimeError(900 /* INVALID_DIFFER_INPUT */, null);
269
+ }
270
+ let type = void 0;
271
+ let flags = 0 /* Default */;
272
+ for (let j = 0; j < arg.length; j++) {
273
+ const meta = arg[j];
274
+ const flag = getInjectFlag(meta);
275
+ if (typeof flag === "number") {
276
+ if (flag === -1 /* Inject */) {
277
+ type = meta.token;
278
+ } else {
279
+ flags |= flag;
280
+ }
281
+ } else {
282
+ type = meta;
283
+ }
284
+ }
285
+ args.push(ɵɵinject(type, flags));
286
+ } else {
287
+ args.push(ɵɵinject(arg));
288
+ }
289
+ }
290
+ return args;
291
+ }
292
+ function attachInjectFlag(decorator, flag) {
293
+ decorator[DI_DECORATOR_FLAG] = flag;
294
+ decorator.prototype[DI_DECORATOR_FLAG] = flag;
295
+ return decorator;
296
+ }
297
+ function getInjectFlag(token) {
298
+ return token[DI_DECORATOR_FLAG];
299
+ }
300
+ function catchInjectorError(e, token, injectorErrorName, source) {
301
+ const tokenPath = e[NG_TEMP_TOKEN_PATH];
302
+ if (token[SOURCE]) {
303
+ tokenPath.unshift(token[SOURCE]);
304
+ }
305
+ e.message = formatError(
306
+ "\n" + e.message,
307
+ tokenPath,
308
+ injectorErrorName,
309
+ source
310
+ );
311
+ e[NG_TOKEN_PATH] = tokenPath;
312
+ e[NG_TEMP_TOKEN_PATH] = null;
313
+ throw e;
314
+ }
315
+ function formatError(text, obj, injectorErrorName, source = null) {
316
+ text = text && text.charAt(0) === "\n" && text.charAt(1) == NO_NEW_LINE ? text.slice(2) : text;
317
+ let context = stringify(obj);
318
+ if (Array.isArray(obj)) {
319
+ context = obj.map(stringify).join(" -> ");
320
+ } else if (typeof obj === "object") {
321
+ const parts = [];
322
+ for (const key in obj) {
323
+ if (obj.hasOwnProperty(key)) {
324
+ const value = obj[key];
325
+ parts.push(
326
+ key + ":" + (typeof value === "string" ? JSON.stringify(value) : stringify(value))
327
+ );
328
+ }
329
+ }
330
+ context = `{${parts.join(", ")}}`;
331
+ }
332
+ return `${injectorErrorName}${source ? "(" + source + ")" : ""}[${context}]: ${text.replace(
333
+ NEW_LINE,
334
+ "\n "
335
+ )}`;
336
+ }
337
+
338
+ // src/import/di/injector_token.ts
339
+ var INJECTOR = new InjectionToken(
340
+ "",
341
+ // Disable tslint because this is const enum which gets inlined not top level prop access.
342
+ // tslint:disable-next-line: no-toplevel-property-access
343
+ -1 /* Injector */
344
+ // Special value used by Ivy to identify `Injector`.
345
+ );
346
+
347
+ // src/import/di/interface/provider.ts
348
+ function isEnvironmentProviders(value) {
349
+ return value && !!value.ɵproviders;
350
+ }
351
+
352
+ // src/import/di/internal_tokens.ts
353
+ var INJECTOR_DEF_TYPES = new InjectionToken("");
354
+
355
+ // src/import/di/null_injector.ts
356
+ var NullInjector = class {
357
+ get(token, notFoundValue = THROW_IF_NOT_FOUND) {
358
+ if (notFoundValue === THROW_IF_NOT_FOUND) {
359
+ const error = new Error(
360
+ `NullInjectorError: No provider for ${stringify(token)}!`
361
+ );
362
+ error.name = "NullInjectorError";
363
+ throw error;
364
+ }
365
+ return notFoundValue;
366
+ }
367
+ };
368
+
369
+ // src/import/di/provider_collection.ts
370
+ function importProvidersFrom(...sources) {
371
+ return {
372
+ ɵproviders: internalImportProvidersFrom(true, sources),
373
+ ɵfromNgModule: true
374
+ };
375
+ }
376
+ function internalImportProvidersFrom(checkForStandaloneCmp, ...sources) {
377
+ const providersOut = [];
378
+ const dedup = /* @__PURE__ */ new Set();
379
+ let injectorTypesWithProviders;
380
+ const collectProviders = (provider) => {
381
+ providersOut.push(provider);
382
+ };
383
+ if (injectorTypesWithProviders !== void 0) {
384
+ processInjectorTypesWithProviders(
385
+ injectorTypesWithProviders,
386
+ collectProviders
387
+ );
388
+ }
389
+ return providersOut;
390
+ }
391
+ function processInjectorTypesWithProviders(typesWithProviders, visitor) {
392
+ for (let i = 0; i < typesWithProviders.length; i++) {
393
+ const { ngModule, providers } = typesWithProviders[i];
394
+ }
395
+ }
396
+ var USE_VALUE = getClosureSafeProperty({
397
+ provide: String,
398
+ useValue: getClosureSafeProperty
399
+ });
400
+ function isValueProvider(value) {
401
+ return value !== null && typeof value === "object" && USE_VALUE in value;
402
+ }
403
+ function isExistingProvider(value) {
404
+ return !!(value && value.useExisting);
405
+ }
406
+ function isFactoryProvider(value) {
407
+ return !!(value && value.useFactory);
408
+ }
409
+ function isTypeProvider(value) {
410
+ return typeof value === "function";
411
+ }
412
+
413
+ // src/import/di/scope.ts
414
+ var INJECTOR_SCOPE = new InjectionToken("");
415
+
416
+ // src/import/di/r3_injector.ts
417
+ var NOT_YET = {};
418
+ var CIRCULAR = {};
419
+ var NULL_INJECTOR = void 0;
420
+ function getNullInjector() {
421
+ if (NULL_INJECTOR === void 0) {
422
+ NULL_INJECTOR = new NullInjector();
423
+ }
424
+ return NULL_INJECTOR;
425
+ }
426
+ var EnvironmentInjector = class {
427
+ };
428
+ var R3Injector = class extends EnvironmentInjector {
429
+ constructor(providers, parent, source, scopes) {
430
+ super();
431
+ this.parent = parent;
432
+ this.source = source;
433
+ this.scopes = scopes;
434
+ forEachSingleProvider(
435
+ providers,
436
+ (provider) => this.processProvider(provider)
437
+ );
438
+ this.records.set(INJECTOR, makeRecord(void 0, this));
439
+ if (scopes.has("environment")) {
440
+ this.records.set(EnvironmentInjector, makeRecord(void 0, this));
441
+ }
442
+ const record = this.records.get(
443
+ INJECTOR_SCOPE
444
+ );
445
+ if (record != null && typeof record.value === "string") {
446
+ this.scopes.add(record.value);
447
+ }
448
+ this.injectorDefTypes = new Set(
449
+ this.get(INJECTOR_DEF_TYPES, EMPTY_ARRAY, 2 /* Self */)
450
+ );
451
+ }
452
+ /**
453
+ * Map of tokens to records which contain the instances of those tokens.
454
+ * - `null` value implies that we don't have the record. Used by tree-shakable injectors
455
+ * to prevent further searches.
456
+ */
457
+ records = /* @__PURE__ */ new Map();
458
+ /**
459
+ * Set of values instantiated by this injector which contain `ngOnDestroy` lifecycle hooks.
460
+ */
461
+ _ngOnDestroyHooks = /* @__PURE__ */ new Set();
462
+ _onDestroyHooks = [];
463
+ /**
464
+ * Flag indicating that this injector was previously destroyed.
465
+ */
466
+ get destroyed() {
467
+ return this._destroyed;
468
+ }
469
+ _destroyed = false;
470
+ injectorDefTypes;
471
+ /**
472
+ * Destroy the injector and release references to every instance or provider associated with it.
473
+ *
474
+ * Also calls the `OnDestroy` lifecycle hooks of every instance that was created for which a
475
+ * hook was found.
476
+ */
477
+ destroy() {
478
+ assertNotDestroyed(this);
479
+ this._destroyed = true;
480
+ try {
481
+ for (const service of this._ngOnDestroyHooks) {
482
+ service.ngOnDestroy();
483
+ }
484
+ const onDestroyHooks = this._onDestroyHooks;
485
+ this._onDestroyHooks = [];
486
+ for (const hook of onDestroyHooks) {
487
+ hook();
488
+ }
489
+ } finally {
490
+ this.records.clear();
491
+ this._ngOnDestroyHooks.clear();
492
+ this.injectorDefTypes.clear();
493
+ }
494
+ }
495
+ onDestroy(callback) {
496
+ assertNotDestroyed(this);
497
+ this._onDestroyHooks.push(callback);
498
+ return () => this.removeOnDestroy(callback);
499
+ }
500
+ runInContext(fn) {
501
+ assertNotDestroyed(this);
502
+ const previousInjector = setCurrentInjector(this);
503
+ const previousInjectImplementation = setInjectImplementation(void 0);
504
+ if (false) {
505
+ }
506
+ try {
507
+ return fn();
508
+ } finally {
509
+ setCurrentInjector(previousInjector);
510
+ setInjectImplementation(previousInjectImplementation);
511
+ }
512
+ }
513
+ get(token, notFoundValue = THROW_IF_NOT_FOUND, flags = 0 /* Default */) {
514
+ assertNotDestroyed(this);
515
+ if (token.hasOwnProperty(NG_ENV_ID)) {
516
+ return token[NG_ENV_ID](this);
517
+ }
518
+ flags = convertToBitFlags(flags);
519
+ if (false) {
520
+ }
521
+ const previousInjector = setCurrentInjector(this);
522
+ const previousInjectImplementation = setInjectImplementation(void 0);
523
+ try {
524
+ if (!(flags & 4 /* SkipSelf */)) {
525
+ let record = this.records.get(token);
526
+ if (record === void 0) {
527
+ const def = couldBeInjectableType(token) && getInjectableDef(token);
528
+ if (def && this.injectableDefInScope(def)) {
529
+ if (false) {
530
+ }
531
+ record = makeRecord(
532
+ injectableDefOrInjectorDefFactory(token),
533
+ NOT_YET
534
+ );
535
+ } else {
536
+ record = null;
537
+ }
538
+ this.records.set(token, record);
539
+ }
540
+ if (record != null) {
541
+ return this.hydrate(token, record);
542
+ }
543
+ }
544
+ const nextInjector = !(flags & 2 /* Self */) ? this.parent : getNullInjector();
545
+ notFoundValue = flags & 8 /* Optional */ && notFoundValue === THROW_IF_NOT_FOUND ? null : notFoundValue;
546
+ return nextInjector.get(token, notFoundValue);
547
+ } catch (e) {
548
+ if (e.name === "NullInjectorError") {
549
+ const path = e[NG_TEMP_TOKEN_PATH] = e[NG_TEMP_TOKEN_PATH] || [];
550
+ path.unshift(stringify(token));
551
+ if (previousInjector) {
552
+ throw e;
553
+ } else {
554
+ return catchInjectorError(e, token, "R3InjectorError", this.source);
555
+ }
556
+ } else {
557
+ throw e;
558
+ }
559
+ } finally {
560
+ setInjectImplementation(previousInjectImplementation);
561
+ setCurrentInjector(previousInjector);
562
+ }
563
+ }
564
+ /** @internal */
565
+ resolveInjectorInitializers() {
566
+ const previousInjector = setCurrentInjector(this);
567
+ const previousInjectImplementation = setInjectImplementation(void 0);
568
+ if (false) {
569
+ }
570
+ try {
571
+ const initializers = this.get(
572
+ ENVIRONMENT_INITIALIZER,
573
+ EMPTY_ARRAY,
574
+ 2 /* Self */
575
+ );
576
+ if (false) {
577
+ }
578
+ for (const initializer of initializers) {
579
+ initializer();
580
+ }
581
+ } finally {
582
+ setCurrentInjector(previousInjector);
583
+ setInjectImplementation(previousInjectImplementation);
584
+ }
585
+ }
586
+ toString() {
587
+ const tokens = [];
588
+ const records = this.records;
589
+ for (const token of records.keys()) {
590
+ tokens.push(stringify(token));
591
+ }
592
+ return `R3Injector[${tokens.join(", ")}]`;
593
+ }
594
+ /**
595
+ * Process a `SingleProvider` and add it.
596
+ */
597
+ processProvider(provider) {
598
+ provider = resolveForwardRef(provider);
599
+ let token = isTypeProvider(provider) ? provider : resolveForwardRef(provider && provider.provide);
600
+ const record = providerToRecord(provider);
601
+ if (false) {
602
+ }
603
+ if (!isTypeProvider(provider) && provider.multi === true) {
604
+ let multiRecord = this.records.get(token);
605
+ if (multiRecord) {
606
+ if (false) {
607
+ }
608
+ } else {
609
+ multiRecord = makeRecord(void 0, NOT_YET, true);
610
+ multiRecord.factory = () => injectArgs(multiRecord.multi);
611
+ this.records.set(token, multiRecord);
612
+ }
613
+ token = provider;
614
+ multiRecord.multi.push(provider);
615
+ } else {
616
+ if (false) {
617
+ }
618
+ }
619
+ this.records.set(token, record);
620
+ }
621
+ hydrate(token, record) {
622
+ try {
623
+ if (false) {
624
+ } else if (record.value === NOT_YET) {
625
+ record.value = CIRCULAR;
626
+ if (false) {
627
+ } else {
628
+ record.value = record.factory();
629
+ }
630
+ }
631
+ if (typeof record.value === "object" && record.value && hasOnDestroy(record.value)) {
632
+ this._ngOnDestroyHooks.add(record.value);
633
+ }
634
+ return record.value;
635
+ } finally {
636
+ }
637
+ }
638
+ injectableDefInScope(def) {
639
+ if (!def.providedIn) {
640
+ return false;
641
+ }
642
+ const providedIn = resolveForwardRef(def.providedIn);
643
+ if (typeof providedIn === "string") {
644
+ return providedIn === "any" || this.scopes.has(providedIn);
645
+ } else {
646
+ return this.injectorDefTypes.has(providedIn);
647
+ }
648
+ }
649
+ removeOnDestroy(callback) {
650
+ const destroyCBIdx = this._onDestroyHooks.indexOf(callback);
651
+ if (destroyCBIdx !== -1) {
652
+ this._onDestroyHooks.splice(destroyCBIdx, 1);
653
+ }
654
+ }
655
+ };
656
+ function injectableDefOrInjectorDefFactory(token) {
657
+ const injectableDef = getInjectableDef(token);
658
+ const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token);
659
+ if (factory !== null) {
660
+ return factory;
661
+ }
662
+ if (token instanceof InjectionToken) {
663
+ throw new RuntimeError(204 /* INVALID_INJECTION_TOKEN */, null);
664
+ }
665
+ if (token instanceof Function) {
666
+ return getUndecoratedInjectableFactory(token);
667
+ }
668
+ throw new RuntimeError(204 /* INVALID_INJECTION_TOKEN */, null);
669
+ }
670
+ function getUndecoratedInjectableFactory(token) {
671
+ const paramLength = token.length;
672
+ if (paramLength > 0) {
673
+ throw new RuntimeError(204 /* INVALID_INJECTION_TOKEN */, null);
674
+ }
675
+ const inheritedInjectableDef = getInheritedInjectableDef(token);
676
+ if (inheritedInjectableDef !== null) {
677
+ return () => inheritedInjectableDef.factory(token);
678
+ } else {
679
+ return () => new token();
680
+ }
681
+ }
682
+ function providerToRecord(provider) {
683
+ if (isValueProvider(provider)) {
684
+ return makeRecord(void 0, provider.useValue);
685
+ } else {
686
+ const factory = providerToFactory(provider);
687
+ return makeRecord(factory, NOT_YET);
688
+ }
689
+ }
690
+ function providerToFactory(provider, ngModuleType, providers) {
691
+ let factory = void 0;
692
+ if (false) {
693
+ }
694
+ if (isTypeProvider(provider)) {
695
+ const unwrappedProvider = resolveForwardRef(provider);
696
+ return getFactoryDef(unwrappedProvider) || injectableDefOrInjectorDefFactory(unwrappedProvider);
697
+ } else {
698
+ if (isValueProvider(provider)) {
699
+ factory = () => resolveForwardRef(provider.useValue);
700
+ } else if (isFactoryProvider(provider)) {
701
+ factory = () => provider.useFactory(...injectArgs(provider.deps || []));
702
+ } else if (isExistingProvider(provider)) {
703
+ factory = () => ɵɵinject(resolveForwardRef(provider.useExisting));
704
+ } else {
705
+ const classRef = resolveForwardRef(
706
+ provider && (provider.useClass || provider.provide)
707
+ );
708
+ if (false) {
709
+ }
710
+ if (hasDeps(provider)) {
711
+ factory = () => new classRef(...injectArgs(provider.deps));
712
+ } else {
713
+ return getFactoryDef(classRef) || injectableDefOrInjectorDefFactory(classRef);
714
+ }
715
+ }
716
+ }
717
+ return factory;
718
+ }
719
+ function assertNotDestroyed(injector) {
720
+ if (injector.destroyed) {
721
+ throw new RuntimeError(205 /* INJECTOR_ALREADY_DESTROYED */, null);
722
+ }
723
+ }
724
+ function makeRecord(factory, value, multi = false) {
725
+ return {
726
+ factory,
727
+ value,
728
+ multi: multi ? [] : void 0
729
+ };
730
+ }
731
+ function hasDeps(value) {
732
+ return !!value.deps;
733
+ }
734
+ function hasOnDestroy(value) {
735
+ return value !== null && typeof value === "object" && typeof value.ngOnDestroy === "function";
736
+ }
737
+ function couldBeInjectableType(value) {
738
+ return typeof value === "function" || typeof value === "object" && value instanceof InjectionToken;
739
+ }
740
+ function forEachSingleProvider(providers, fn) {
741
+ for (const provider of providers) {
742
+ if (Array.isArray(provider)) {
743
+ forEachSingleProvider(provider, fn);
744
+ } else if (provider && isEnvironmentProviders(provider)) {
745
+ forEachSingleProvider(provider.ɵproviders, fn);
746
+ } else {
747
+ fn(provider);
748
+ }
749
+ }
750
+ }
751
+
752
+ // src/import/util/closure.ts
753
+ function noSideEffects(fn) {
754
+ return { toString: fn }.toString();
755
+ }
756
+
757
+ // src/import/util/decorators.ts
758
+ function makeMetadataCtor(props) {
759
+ return function ctor(...args) {
760
+ if (props) {
761
+ const values = props(...args);
762
+ for (const propName in values) {
763
+ this[propName] = values[propName];
764
+ }
765
+ }
766
+ };
767
+ }
768
+ function makeParamDecorator(name, props, parentClass) {
769
+ return noSideEffects(() => {
770
+ const metaCtor = makeMetadataCtor(props);
771
+ function ParamDecoratorFactory(...args) {
772
+ metaCtor.apply(this, args);
773
+ return this;
774
+ }
775
+ if (parentClass) {
776
+ }
777
+ return ParamDecoratorFactory;
778
+ });
779
+ }
780
+
781
+ // src/import/di/metadata.ts
782
+ var Inject = attachInjectFlag(
783
+ // Disable tslint because `DecoratorFlags` is a const enum which gets inlined.
784
+ makeParamDecorator("Inject", (token) => ({ token })),
785
+ // tslint:disable-next-line: no-toplevel-property-access
786
+ -1 /* Inject */
787
+ );
788
+ var Optional = (
789
+ // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
790
+ // tslint:disable-next-line: no-toplevel-property-access
791
+ attachInjectFlag(
792
+ makeParamDecorator("Optional"),
793
+ 8 /* Optional */
794
+ )
795
+ );
796
+ var Self = (
797
+ // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
798
+ // tslint:disable-next-line: no-toplevel-property-access
799
+ attachInjectFlag(makeParamDecorator("Self"), 2 /* Self */)
800
+ );
801
+ var SkipSelf = (
802
+ // Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
803
+ // tslint:disable-next-line: no-toplevel-property-access
804
+ attachInjectFlag(
805
+ makeParamDecorator("SkipSelf"),
806
+ 4 /* SkipSelf */
807
+ )
808
+ );
809
+
810
+ // src/import/di/create_injector.ts
811
+ function createInjector(defType, parent = null, additionalProviders = null, name) {
812
+ const injector = createInjectorWithoutInjectorInstances(
813
+ defType,
814
+ parent,
815
+ additionalProviders,
816
+ name
817
+ );
818
+ injector.resolveInjectorInitializers();
819
+ return injector;
820
+ }
821
+ function createInjectorWithoutInjectorInstances(defType, parent = null, additionalProviders = null, name, scopes = /* @__PURE__ */ new Set()) {
822
+ const providers = [
823
+ additionalProviders || EMPTY_ARRAY,
824
+ importProvidersFrom(defType)
825
+ ];
826
+ name = name || (typeof defType === "object" ? void 0 : stringify(defType));
827
+ return new R3Injector(
828
+ providers,
829
+ parent || getNullInjector(),
830
+ name || null,
831
+ scopes
832
+ );
833
+ }
834
+
835
+ // src/import/di/injector.ts
836
+ var Injector = class _Injector {
837
+ static THROW_IF_NOT_FOUND = THROW_IF_NOT_FOUND;
838
+ static NULL = /* @__PURE__ */ new NullInjector();
839
+ static create(options, parent) {
840
+ if (Array.isArray(options)) {
841
+ return createInjector({ name: "" }, parent, options, "");
842
+ } else {
843
+ const name = options.name ?? "";
844
+ return createInjector({ name }, options.parent, options.providers, name);
845
+ }
846
+ }
847
+ /** @nocollapse */
848
+ static ɵprov = (
849
+ /** @pureOrBreakMyCode */
850
+ /* @__PURE__ */ ɵɵdefineInjectable({
851
+ token: _Injector,
852
+ providedIn: "any",
853
+ factory: () => ɵɵinject(INJECTOR)
854
+ })
855
+ );
856
+ /**
857
+ * @internal
858
+ * @nocollapse
859
+ */
860
+ static __NG_ELEMENT_ID__ = -1 /* Injector */;
861
+ };
862
+
863
+ // src/import/render3/instructions/di.ts
864
+ function ɵɵinvalidFactory() {
865
+ const msg = "invalid";
866
+ throw new Error(msg);
867
+ }
868
+
869
+ // src/primitives/signals/src/equality.ts
870
+ function defaultEquals(a, b) {
871
+ return Object.is(a, b);
872
+ }
873
+
874
+ // src/primitives/signals/src/graph.ts
875
+ var activeConsumer = null;
876
+ var inNotificationPhase = false;
877
+ var epoch = 1;
878
+ var SIGNAL = /* @__PURE__ */ Symbol("SIGNAL");
879
+ function setActiveConsumer(consumer) {
880
+ const prev = activeConsumer;
881
+ activeConsumer = consumer;
882
+ return prev;
883
+ }
884
+ function getActiveConsumer() {
885
+ return activeConsumer;
886
+ }
887
+ function isInNotificationPhase() {
888
+ return inNotificationPhase;
889
+ }
890
+ var REACTIVE_NODE = {
891
+ version: 0,
892
+ lastCleanEpoch: 0,
893
+ dirty: false,
894
+ producerNode: void 0,
895
+ producerLastReadVersion: void 0,
896
+ producerIndexOfThis: void 0,
897
+ nextProducerIndex: 0,
898
+ liveConsumerNode: void 0,
899
+ liveConsumerIndexOfThis: void 0,
900
+ consumerAllowSignalWrites: false,
901
+ consumerIsAlwaysLive: false,
902
+ kind: "unknown",
903
+ producerMustRecompute: () => false,
904
+ producerRecomputeValue: () => {
905
+ },
906
+ consumerMarkedDirty: () => {
907
+ },
908
+ consumerOnSignalRead: () => {
909
+ }
910
+ };
911
+ function producerAccessed(node) {
912
+ if (inNotificationPhase) {
913
+ throw new Error(
914
+ false ? `Assertion error: signal read during notification phase` : ""
915
+ );
916
+ }
917
+ if (activeConsumer === null) {
918
+ return;
919
+ }
920
+ activeConsumer.consumerOnSignalRead(node);
921
+ const idx = activeConsumer.nextProducerIndex++;
922
+ assertConsumerNode(activeConsumer);
923
+ if (idx < activeConsumer.producerNode.length && activeConsumer.producerNode[idx] !== node) {
924
+ if (consumerIsLive(activeConsumer)) {
925
+ const staleProducer = activeConsumer.producerNode[idx];
926
+ producerRemoveLiveConsumerAtIndex(
927
+ staleProducer,
928
+ activeConsumer.producerIndexOfThis[idx]
929
+ );
930
+ }
931
+ }
932
+ if (activeConsumer.producerNode[idx] !== node) {
933
+ activeConsumer.producerNode[idx] = node;
934
+ activeConsumer.producerIndexOfThis[idx] = consumerIsLive(activeConsumer) ? producerAddLiveConsumer(node, activeConsumer, idx) : 0;
935
+ }
936
+ activeConsumer.producerLastReadVersion[idx] = node.version;
937
+ }
938
+ function producerIncrementEpoch() {
939
+ epoch++;
940
+ }
941
+ function producerUpdateValueVersion(node) {
942
+ if (consumerIsLive(node) && !node.dirty) {
943
+ return;
944
+ }
945
+ if (!node.dirty && node.lastCleanEpoch === epoch) {
946
+ return;
947
+ }
948
+ if (!node.producerMustRecompute(node) && !consumerPollProducersForChange(node)) {
949
+ producerMarkClean(node);
950
+ return;
951
+ }
952
+ node.producerRecomputeValue(node);
953
+ producerMarkClean(node);
954
+ }
955
+ function producerNotifyConsumers(node) {
956
+ if (node.liveConsumerNode === void 0) {
957
+ return;
958
+ }
959
+ const prev = inNotificationPhase;
960
+ inNotificationPhase = true;
961
+ try {
962
+ for (const consumer of node.liveConsumerNode) {
963
+ if (!consumer.dirty) {
964
+ consumerMarkDirty(consumer);
965
+ }
966
+ }
967
+ } finally {
968
+ inNotificationPhase = prev;
969
+ }
970
+ }
971
+ function producerUpdatesAllowed() {
972
+ return activeConsumer?.consumerAllowSignalWrites !== false;
973
+ }
974
+ function consumerMarkDirty(node) {
975
+ node.dirty = true;
976
+ producerNotifyConsumers(node);
977
+ node.consumerMarkedDirty?.(node);
978
+ }
979
+ function producerMarkClean(node) {
980
+ node.dirty = false;
981
+ node.lastCleanEpoch = epoch;
982
+ }
983
+ function consumerBeforeComputation(node) {
984
+ node && (node.nextProducerIndex = 0);
985
+ return setActiveConsumer(node);
986
+ }
987
+ function consumerAfterComputation(node, prevConsumer) {
988
+ setActiveConsumer(prevConsumer);
989
+ if (!node || node.producerNode === void 0 || node.producerIndexOfThis === void 0 || node.producerLastReadVersion === void 0) {
990
+ return;
991
+ }
992
+ if (consumerIsLive(node)) {
993
+ for (let i = node.nextProducerIndex; i < node.producerNode.length; i++) {
994
+ producerRemoveLiveConsumerAtIndex(
995
+ node.producerNode[i],
996
+ node.producerIndexOfThis[i]
997
+ );
998
+ }
999
+ }
1000
+ while (node.producerNode.length > node.nextProducerIndex) {
1001
+ node.producerNode.pop();
1002
+ node.producerLastReadVersion.pop();
1003
+ node.producerIndexOfThis.pop();
1004
+ }
1005
+ }
1006
+ function consumerPollProducersForChange(node) {
1007
+ assertConsumerNode(node);
1008
+ for (let i = 0; i < node.producerNode.length; i++) {
1009
+ const producer = node.producerNode[i];
1010
+ const seenVersion = node.producerLastReadVersion[i];
1011
+ if (seenVersion !== producer.version) {
1012
+ return true;
1013
+ }
1014
+ producerUpdateValueVersion(producer);
1015
+ if (seenVersion !== producer.version) {
1016
+ return true;
1017
+ }
1018
+ }
1019
+ return false;
1020
+ }
1021
+ function consumerDestroy(node) {
1022
+ assertConsumerNode(node);
1023
+ if (consumerIsLive(node)) {
1024
+ for (let i = 0; i < node.producerNode.length; i++) {
1025
+ producerRemoveLiveConsumerAtIndex(
1026
+ node.producerNode[i],
1027
+ node.producerIndexOfThis[i]
1028
+ );
1029
+ }
1030
+ }
1031
+ node.producerNode.length = node.producerLastReadVersion.length = node.producerIndexOfThis.length = 0;
1032
+ if (node.liveConsumerNode) {
1033
+ node.liveConsumerNode.length = node.liveConsumerIndexOfThis.length = 0;
1034
+ }
1035
+ }
1036
+ function producerAddLiveConsumer(node, consumer, indexOfThis) {
1037
+ assertProducerNode(node);
1038
+ if (node.liveConsumerNode.length === 0 && isConsumerNode(node)) {
1039
+ for (let i = 0; i < node.producerNode.length; i++) {
1040
+ node.producerIndexOfThis[i] = producerAddLiveConsumer(
1041
+ node.producerNode[i],
1042
+ node,
1043
+ i
1044
+ );
1045
+ }
1046
+ }
1047
+ node.liveConsumerIndexOfThis.push(indexOfThis);
1048
+ return node.liveConsumerNode.push(consumer) - 1;
1049
+ }
1050
+ function producerRemoveLiveConsumerAtIndex(node, idx) {
1051
+ assertProducerNode(node);
1052
+ if (false) {
1053
+ throw new Error(
1054
+ `Assertion error: active consumer index ${idx} is out of bounds of ${node.liveConsumerNode.length} consumers)`
1055
+ );
1056
+ }
1057
+ if (node.liveConsumerNode.length === 1 && isConsumerNode(node)) {
1058
+ for (let i = 0; i < node.producerNode.length; i++) {
1059
+ producerRemoveLiveConsumerAtIndex(
1060
+ node.producerNode[i],
1061
+ node.producerIndexOfThis[i]
1062
+ );
1063
+ }
1064
+ }
1065
+ const lastIdx = node.liveConsumerNode.length - 1;
1066
+ node.liveConsumerNode[idx] = node.liveConsumerNode[lastIdx];
1067
+ node.liveConsumerIndexOfThis[idx] = node.liveConsumerIndexOfThis[lastIdx];
1068
+ node.liveConsumerNode.length--;
1069
+ node.liveConsumerIndexOfThis.length--;
1070
+ if (idx < node.liveConsumerNode.length) {
1071
+ const idxProducer = node.liveConsumerIndexOfThis[idx];
1072
+ const consumer = node.liveConsumerNode[idx];
1073
+ assertConsumerNode(consumer);
1074
+ consumer.producerIndexOfThis[idxProducer] = idx;
1075
+ }
1076
+ }
1077
+ function consumerIsLive(node) {
1078
+ return node.consumerIsAlwaysLive || (node?.liveConsumerNode?.length ?? 0) > 0;
1079
+ }
1080
+ function assertConsumerNode(node) {
1081
+ node.producerNode ??= [];
1082
+ node.producerIndexOfThis ??= [];
1083
+ node.producerLastReadVersion ??= [];
1084
+ }
1085
+ function assertProducerNode(node) {
1086
+ node.liveConsumerNode ??= [];
1087
+ node.liveConsumerIndexOfThis ??= [];
1088
+ }
1089
+ function isConsumerNode(node) {
1090
+ return node.producerNode !== void 0;
1091
+ }
1092
+
1093
+ // src/primitives/signals/src/computed.ts
1094
+ function createComputed(computation) {
1095
+ const node = Object.create(COMPUTED_NODE);
1096
+ node.computation = computation;
1097
+ const computed2 = () => {
1098
+ producerUpdateValueVersion(node);
1099
+ producerAccessed(node);
1100
+ if (node.value === ERRORED) {
1101
+ throw node.error;
1102
+ }
1103
+ return node.value;
1104
+ };
1105
+ computed2[SIGNAL] = node;
1106
+ return computed2;
1107
+ }
1108
+ var UNSET = /* @__PURE__ */ Symbol("UNSET");
1109
+ var COMPUTING = /* @__PURE__ */ Symbol("COMPUTING");
1110
+ var ERRORED = /* @__PURE__ */ Symbol("ERRORED");
1111
+ var COMPUTED_NODE = /* @__PURE__ */ (() => ({
1112
+ ...REACTIVE_NODE,
1113
+ value: UNSET,
1114
+ dirty: true,
1115
+ error: null,
1116
+ equal: defaultEquals,
1117
+ kind: "computed",
1118
+ producerMustRecompute(node) {
1119
+ return node.value === UNSET || node.value === COMPUTING;
1120
+ },
1121
+ producerRecomputeValue(node) {
1122
+ if (node.value === COMPUTING) {
1123
+ throw new Error("Detected cycle in computations.");
1124
+ }
1125
+ const oldValue = node.value;
1126
+ node.value = COMPUTING;
1127
+ const prevConsumer = consumerBeforeComputation(node);
1128
+ let newValue;
1129
+ let wasEqual = false;
1130
+ try {
1131
+ newValue = node.computation();
1132
+ setActiveConsumer(null);
1133
+ wasEqual = oldValue !== UNSET && oldValue !== ERRORED && newValue !== ERRORED && node.equal(oldValue, newValue);
1134
+ } catch (err) {
1135
+ newValue = ERRORED;
1136
+ node.error = err;
1137
+ } finally {
1138
+ consumerAfterComputation(node, prevConsumer);
1139
+ }
1140
+ if (wasEqual) {
1141
+ node.value = oldValue;
1142
+ return;
1143
+ }
1144
+ node.value = newValue;
1145
+ node.version++;
1146
+ }
1147
+ }))();
1148
+
1149
+ // src/primitives/signals/src/errors.ts
1150
+ function defaultThrowError() {
1151
+ throw new Error();
1152
+ }
1153
+ var throwInvalidWriteToSignalErrorFn = defaultThrowError;
1154
+ function throwInvalidWriteToSignalError(node) {
1155
+ throwInvalidWriteToSignalErrorFn(node);
1156
+ }
1157
+
1158
+ // src/primitives/signals/src/signal.ts
1159
+ var postSignalSetFn = null;
1160
+ function createSignal(initialValue) {
1161
+ const node = Object.create(SIGNAL_NODE);
1162
+ node.value = initialValue;
1163
+ const getter = () => {
1164
+ producerAccessed(node);
1165
+ return node.value;
1166
+ };
1167
+ getter[SIGNAL] = node;
1168
+ return getter;
1169
+ }
1170
+ function signalSetFn(node, newValue) {
1171
+ if (!producerUpdatesAllowed()) {
1172
+ throwInvalidWriteToSignalError(node);
1173
+ }
1174
+ if (!node.equal(node.value, newValue)) {
1175
+ node.value = newValue;
1176
+ signalValueChanged(node);
1177
+ }
1178
+ }
1179
+ function signalUpdateFn(node, updater) {
1180
+ if (!producerUpdatesAllowed()) {
1181
+ throwInvalidWriteToSignalError(node);
1182
+ }
1183
+ signalSetFn(node, updater(node.value));
1184
+ }
1185
+ var SIGNAL_NODE = /* @__PURE__ */ (() => ({
1186
+ ...REACTIVE_NODE,
1187
+ equal: defaultEquals,
1188
+ value: void 0,
1189
+ kind: "signal"
1190
+ }))();
1191
+ function signalValueChanged(node) {
1192
+ node.version++;
1193
+ producerIncrementEpoch();
1194
+ producerNotifyConsumers(node);
1195
+ postSignalSetFn?.();
1196
+ }
1197
+
1198
+ // src/primitives/signals/src/linked_signal.ts
1199
+ function createLinkedSignal(sourceFn, computationFn, equalityFn) {
1200
+ const node = Object.create(LINKED_SIGNAL_NODE);
1201
+ node.source = sourceFn;
1202
+ node.computation = computationFn;
1203
+ if (equalityFn != void 0) {
1204
+ node.equal = equalityFn;
1205
+ }
1206
+ const linkedSignalGetter = () => {
1207
+ producerUpdateValueVersion(node);
1208
+ producerAccessed(node);
1209
+ if (node.value === ERRORED) {
1210
+ throw node.error;
1211
+ }
1212
+ return node.value;
1213
+ };
1214
+ const getter = linkedSignalGetter;
1215
+ getter[SIGNAL] = node;
1216
+ return getter;
1217
+ }
1218
+ function linkedSignalSetFn(node, newValue) {
1219
+ producerUpdateValueVersion(node);
1220
+ signalSetFn(node, newValue);
1221
+ producerMarkClean(node);
1222
+ }
1223
+ function linkedSignalUpdateFn(node, updater) {
1224
+ producerUpdateValueVersion(node);
1225
+ signalUpdateFn(node, updater);
1226
+ producerMarkClean(node);
1227
+ }
1228
+ var LINKED_SIGNAL_NODE = /* @__PURE__ */ (() => ({
1229
+ ...REACTIVE_NODE,
1230
+ value: UNSET,
1231
+ dirty: true,
1232
+ error: null,
1233
+ equal: defaultEquals,
1234
+ producerMustRecompute(node) {
1235
+ return node.value === UNSET || node.value === COMPUTING;
1236
+ },
1237
+ producerRecomputeValue(node) {
1238
+ if (node.value === COMPUTING) {
1239
+ throw new Error("Detected cycle in computations.");
1240
+ }
1241
+ const oldValue = node.value;
1242
+ node.value = COMPUTING;
1243
+ const prevConsumer = consumerBeforeComputation(node);
1244
+ let newValue;
1245
+ try {
1246
+ const newSourceValue = node.source();
1247
+ const prev = oldValue === UNSET || oldValue === ERRORED ? void 0 : {
1248
+ source: node.sourceValue,
1249
+ value: oldValue
1250
+ };
1251
+ newValue = node.computation(newSourceValue, prev);
1252
+ node.sourceValue = newSourceValue;
1253
+ } catch (err) {
1254
+ newValue = ERRORED;
1255
+ node.error = err;
1256
+ } finally {
1257
+ consumerAfterComputation(node, prevConsumer);
1258
+ }
1259
+ if (oldValue !== UNSET && newValue !== ERRORED && node.equal(oldValue, newValue)) {
1260
+ node.value = oldValue;
1261
+ return;
1262
+ }
1263
+ node.value = newValue;
1264
+ node.version++;
1265
+ }
1266
+ }))();
1267
+
1268
+ // src/primitives/signals/src/watch.ts
1269
+ function createWatch(fn, schedule, allowSignalWrites) {
1270
+ const node = Object.create(WATCH_NODE);
1271
+ if (allowSignalWrites) {
1272
+ node.consumerAllowSignalWrites = true;
1273
+ }
1274
+ node.fn = fn;
1275
+ node.schedule = schedule;
1276
+ const registerOnCleanup = (cleanupFn) => {
1277
+ node.cleanupFn = cleanupFn;
1278
+ };
1279
+ function isWatchNodeDestroyed(node2) {
1280
+ return node2.fn === null && node2.schedule === null;
1281
+ }
1282
+ function destroyWatchNode(node2) {
1283
+ if (!isWatchNodeDestroyed(node2)) {
1284
+ consumerDestroy(node2);
1285
+ node2.cleanupFn();
1286
+ node2.fn = null;
1287
+ node2.schedule = null;
1288
+ node2.cleanupFn = NOOP_CLEANUP_FN;
1289
+ }
1290
+ }
1291
+ const run = () => {
1292
+ if (node.fn === null) {
1293
+ return;
1294
+ }
1295
+ if (isInNotificationPhase()) {
1296
+ throw new Error(
1297
+ `Schedulers cannot synchronously execute watches while scheduling.`
1298
+ );
1299
+ }
1300
+ node.dirty = false;
1301
+ if (node.hasRun && !consumerPollProducersForChange(node)) {
1302
+ return;
1303
+ }
1304
+ node.hasRun = true;
1305
+ const prevConsumer = consumerBeforeComputation(node);
1306
+ try {
1307
+ node.cleanupFn();
1308
+ node.cleanupFn = NOOP_CLEANUP_FN;
1309
+ node.fn(registerOnCleanup);
1310
+ } finally {
1311
+ consumerAfterComputation(node, prevConsumer);
1312
+ }
1313
+ };
1314
+ node.ref = {
1315
+ notify: () => consumerMarkDirty(node),
1316
+ run,
1317
+ cleanup: () => node.cleanupFn(),
1318
+ destroy: () => destroyWatchNode(node),
1319
+ [SIGNAL]: node
1320
+ };
1321
+ return node.ref;
1322
+ }
1323
+ var NOOP_CLEANUP_FN = () => {
1324
+ };
1325
+ var WATCH_NODE = /* @__PURE__ */ (() => ({
1326
+ ...REACTIVE_NODE,
1327
+ consumerIsAlwaysLive: true,
1328
+ consumerAllowSignalWrites: false,
1329
+ consumerMarkedDirty: (node) => {
1330
+ if (node.schedule !== null) {
1331
+ node.schedule(node.ref);
1332
+ }
1333
+ },
1334
+ hasRun: false,
1335
+ cleanupFn: NOOP_CLEANUP_FN
1336
+ }))();
1337
+
1338
+ // src/import/render3/reactivity/api.ts
1339
+ function isSignal(value) {
1340
+ return typeof value === "function" && value[SIGNAL] !== void 0;
1341
+ }
1342
+
1343
+ // src/import/render3/reactivity/computed.ts
1344
+ function computed(computation, options) {
1345
+ const getter = createComputed(computation);
1346
+ if (options?.equal) {
1347
+ getter[SIGNAL].equal = options.equal;
1348
+ }
1349
+ if (false) {
1350
+ }
1351
+ return getter;
1352
+ }
1353
+
1354
+ // src/import/render3/reactivity/signal.ts
1355
+ function ɵunwrapWritableSignal(value) {
1356
+ return null;
1357
+ }
1358
+ function signal(initialValue, options) {
1359
+ const signalFn = createSignal(initialValue);
1360
+ const node = signalFn[SIGNAL];
1361
+ if (options?.equal) {
1362
+ node.equal = options.equal;
1363
+ }
1364
+ signalFn.set = (newValue) => signalSetFn(node, newValue);
1365
+ signalFn.update = (updateFn) => signalUpdateFn(node, updateFn);
1366
+ signalFn.asReadonly = signalAsReadonlyFn.bind(
1367
+ signalFn
1368
+ );
1369
+ if (false) {
1370
+ }
1371
+ return signalFn;
1372
+ }
1373
+ function signalAsReadonlyFn() {
1374
+ const node = this[SIGNAL];
1375
+ if (node.readonlyFn === void 0) {
1376
+ const readonlyFn = () => this();
1377
+ readonlyFn[SIGNAL] = node;
1378
+ node.readonlyFn = readonlyFn;
1379
+ }
1380
+ return node.readonlyFn;
1381
+ }
1382
+
1383
+ // src/import/render3/reactivity/linked_signal.ts
1384
+ var identityFn = (v) => v;
1385
+ function linkedSignal(optionsOrComputation, options) {
1386
+ if (typeof optionsOrComputation === "function") {
1387
+ const getter = createLinkedSignal(
1388
+ optionsOrComputation,
1389
+ identityFn,
1390
+ options?.equal
1391
+ );
1392
+ return upgradeLinkedSignalGetter(getter);
1393
+ } else {
1394
+ const getter = createLinkedSignal(
1395
+ optionsOrComputation.source,
1396
+ optionsOrComputation.computation,
1397
+ optionsOrComputation.equal
1398
+ );
1399
+ return upgradeLinkedSignalGetter(getter);
1400
+ }
1401
+ }
1402
+ function upgradeLinkedSignalGetter(getter) {
1403
+ if (false) {
1404
+ }
1405
+ const node = getter[SIGNAL];
1406
+ const upgradedGetter = getter;
1407
+ upgradedGetter.set = (newValue) => linkedSignalSetFn(node, newValue);
1408
+ upgradedGetter.update = (updateFn) => linkedSignalUpdateFn(node, updateFn);
1409
+ upgradedGetter.asReadonly = signalAsReadonlyFn.bind(
1410
+ getter
1411
+ );
1412
+ return upgradedGetter;
1413
+ }
1414
+
1415
+ // src/import/render3/reactivity/untracked.ts
1416
+ function untracked(nonReactiveReadsFn) {
1417
+ const prevConsumer = setActiveConsumer(null);
1418
+ try {
1419
+ return nonReactiveReadsFn();
1420
+ } finally {
1421
+ setActiveConsumer(prevConsumer);
1422
+ }
1423
+ }
1424
+
1425
+ // src/import/render3/reactivity/asserts.ts
1426
+ function assertNotInReactiveContext(debugFn, extraContext) {
1427
+ if (getActiveConsumer() !== null) {
1428
+ throw new RuntimeError(
1429
+ -602 /* ASSERTION_NOT_INSIDE_REACTIVE_CONTEXT */,
1430
+ null
1431
+ );
1432
+ }
1433
+ }
1434
+
1435
+ // src/import/di/contextual.ts
1436
+ function isInInjectionContext() {
1437
+ return getInjectImplementation() !== void 0 || getCurrentInjector() != null;
1438
+ }
1439
+ function assertInInjectionContext(debugFn) {
1440
+ if (!isInInjectionContext()) {
1441
+ throw new RuntimeError(-203 /* MISSING_INJECTION_CONTEXT */, null);
1442
+ }
1443
+ }
1444
+
1445
+ // src/import/linker/destroy_ref.ts
1446
+ var DestroyRef = class {
1447
+ /**
1448
+ * @internal
1449
+ * @nocollapse
1450
+ */
1451
+ /**
1452
+ * @internal
1453
+ * @nocollapse
1454
+ */
1455
+ static __NG_ENV_ID__ = (injector) => injector;
1456
+ };
1457
+
1458
+ // src/import/util/noop.ts
1459
+ function noop(...args) {
1460
+ }
1461
+
1462
+ // src/import/change_detection/scheduling/zoneless_scheduling.ts
1463
+ var NotificationSource = /* @__PURE__ */ ((NotificationSource2) => {
1464
+ NotificationSource2[NotificationSource2["MarkAncestorsForTraversal"] = 0] = "MarkAncestorsForTraversal";
1465
+ NotificationSource2[NotificationSource2["SetInput"] = 1] = "SetInput";
1466
+ NotificationSource2[NotificationSource2["DeferBlockStateUpdate"] = 2] = "DeferBlockStateUpdate";
1467
+ NotificationSource2[NotificationSource2["DebugApplyChanges"] = 3] = "DebugApplyChanges";
1468
+ NotificationSource2[NotificationSource2["MarkForCheck"] = 4] = "MarkForCheck";
1469
+ NotificationSource2[NotificationSource2["Listener"] = 5] = "Listener";
1470
+ NotificationSource2[NotificationSource2["CustomElement"] = 6] = "CustomElement";
1471
+ NotificationSource2[NotificationSource2["RenderHook"] = 7] = "RenderHook";
1472
+ NotificationSource2[NotificationSource2["ViewAttached"] = 8] = "ViewAttached";
1473
+ NotificationSource2[NotificationSource2["ViewDetachedFromDOM"] = 9] = "ViewDetachedFromDOM";
1474
+ NotificationSource2[NotificationSource2["AsyncAnimationsLoaded"] = 10] = "AsyncAnimationsLoaded";
1475
+ NotificationSource2[NotificationSource2["PendingTaskRemoved"] = 11] = "PendingTaskRemoved";
1476
+ NotificationSource2[NotificationSource2["RootEffect"] = 12] = "RootEffect";
1477
+ NotificationSource2[NotificationSource2["ViewEffect"] = 13] = "ViewEffect";
1478
+ return NotificationSource2;
1479
+ })(NotificationSource || {});
1480
+ var ChangeDetectionScheduler = class {
1481
+ };
1482
+ var ZONELESS_ENABLED = new InjectionToken(
1483
+ false ? "Zoneless enabled" : "",
1484
+ { providedIn: "root", factory: () => false }
1485
+ );
1486
+ var PROVIDED_ZONELESS = new InjectionToken(
1487
+ false ? "Zoneless provided" : "",
1488
+ { providedIn: "root", factory: () => false }
1489
+ );
1490
+ var ZONELESS_SCHEDULER_DISABLED = new InjectionToken(
1491
+ false ? "scheduler disabled" : ""
1492
+ );
1493
+ var SCHEDULE_IN_ROOT_ZONE = new InjectionToken(
1494
+ false ? "run changes outside zone in root" : ""
1495
+ );
1496
+
1497
+ // src/import/render3/reactivity/root_effect_scheduler.ts
1498
+ var EffectScheduler = class _EffectScheduler {
1499
+ /** @nocollapse */
1500
+ static ɵprov = (
1501
+ /** @pureOrBreakMyCode */
1502
+ /* @__PURE__ */ ɵɵdefineInjectable({
1503
+ token: _EffectScheduler,
1504
+ providedIn: "root",
1505
+ factory: () => new ZoneAwareEffectScheduler()
1506
+ })
1507
+ );
1508
+ };
1509
+ var ZoneAwareEffectScheduler = class {
1510
+ queuedEffectCount = 0;
1511
+ queues = /* @__PURE__ */ new Map();
1512
+ schedule(handle) {
1513
+ this.enqueue(handle);
1514
+ }
1515
+ remove(handle) {
1516
+ const zone = handle.zone;
1517
+ const queue = this.queues.get(zone);
1518
+ if (!queue.has(handle)) {
1519
+ return;
1520
+ }
1521
+ queue.delete(handle);
1522
+ this.queuedEffectCount--;
1523
+ }
1524
+ enqueue(handle) {
1525
+ const zone = handle.zone;
1526
+ if (!this.queues.has(zone)) {
1527
+ this.queues.set(zone, /* @__PURE__ */ new Set());
1528
+ }
1529
+ const queue = this.queues.get(zone);
1530
+ if (queue.has(handle)) {
1531
+ return;
1532
+ }
1533
+ this.queuedEffectCount++;
1534
+ queue.add(handle);
1535
+ }
1536
+ /**
1537
+ * Run all scheduled effects.
1538
+ *
1539
+ * Execution order of effects within the same zone is guaranteed to be FIFO, but there is no
1540
+ * ordering guarantee between effects scheduled in different zones.
1541
+ */
1542
+ flush() {
1543
+ while (this.queuedEffectCount > 0) {
1544
+ for (const [zone, queue] of this.queues) {
1545
+ if (zone === null) {
1546
+ this.flushQueue(queue);
1547
+ } else {
1548
+ zone.run(() => this.flushQueue(queue));
1549
+ }
1550
+ }
1551
+ }
1552
+ }
1553
+ flushQueue(queue) {
1554
+ for (const handle of queue) {
1555
+ queue.delete(handle);
1556
+ this.queuedEffectCount--;
1557
+ handle.run();
1558
+ }
1559
+ }
1560
+ };
1561
+
1562
+ // src/import/render3/reactivity/patch.ts
1563
+ var USE_MICROTASK_EFFECT_BY_DEFAULT = false;
1564
+
1565
+ // src/import/error_handler.ts
1566
+ var ErrorHandler = class {
1567
+ /**
1568
+ * @internal
1569
+ */
1570
+ _console = console;
1571
+ handleError(error) {
1572
+ this._console.error("ERROR", error);
1573
+ }
1574
+ };
1575
+
1576
+ // src/import/pending_tasks.ts
1577
+ import { BehaviorSubject } from "rxjs";
1578
+ var PendingTasksInternal = class _PendingTasksInternal {
1579
+ taskId = 0;
1580
+ pendingTasks = /* @__PURE__ */ new Set();
1581
+ get _hasPendingTasks() {
1582
+ return this.hasPendingTasks.value;
1583
+ }
1584
+ hasPendingTasks = new BehaviorSubject(false);
1585
+ add() {
1586
+ if (!this._hasPendingTasks) {
1587
+ this.hasPendingTasks.next(true);
1588
+ }
1589
+ const taskId = this.taskId++;
1590
+ this.pendingTasks.add(taskId);
1591
+ return taskId;
1592
+ }
1593
+ has(taskId) {
1594
+ return this.pendingTasks.has(taskId);
1595
+ }
1596
+ remove(taskId) {
1597
+ this.pendingTasks.delete(taskId);
1598
+ if (this.pendingTasks.size === 0 && this._hasPendingTasks) {
1599
+ this.hasPendingTasks.next(false);
1600
+ }
1601
+ }
1602
+ ngOnDestroy() {
1603
+ this.pendingTasks.clear();
1604
+ if (this._hasPendingTasks) {
1605
+ this.hasPendingTasks.next(false);
1606
+ }
1607
+ }
1608
+ /** @nocollapse */
1609
+ static ɵprov = (
1610
+ /** @pureOrBreakMyCode */
1611
+ /* @__PURE__ */ ɵɵdefineInjectable({
1612
+ token: _PendingTasksInternal,
1613
+ providedIn: "root",
1614
+ factory: () => new _PendingTasksInternal()
1615
+ })
1616
+ );
1617
+ };
1618
+ var PendingTasks = class _PendingTasks {
1619
+ internalPendingTasks = inject(PendingTasksInternal);
1620
+ scheduler = inject(ChangeDetectionScheduler);
1621
+ /**
1622
+ * Adds a new task that should block application's stability.
1623
+ * @returns A cleanup function that removes a task when called.
1624
+ */
1625
+ add() {
1626
+ const taskId = this.internalPendingTasks.add();
1627
+ return () => {
1628
+ if (!this.internalPendingTasks.has(taskId)) {
1629
+ return;
1630
+ }
1631
+ this.scheduler.notify(11 /* PendingTaskRemoved */);
1632
+ this.internalPendingTasks.remove(taskId);
1633
+ };
1634
+ }
1635
+ /**
1636
+ * Runs an asynchronous function and blocks the application's stability until the function completes.
1637
+ *
1638
+ * ```ts
1639
+ * pendingTasks.run(async () => {
1640
+ * const userData = await fetch('/api/user');
1641
+ * this.userData.set(userData);
1642
+ * });
1643
+ * ```
1644
+ *
1645
+ * Application stability is at least delayed until the next tick after the `run` method resolves
1646
+ * so it is safe to make additional updates to application state that would require UI synchronization:
1647
+ *
1648
+ * ```ts
1649
+ * const userData = await pendingTasks.run(() => fetch('/api/user'));
1650
+ * this.userData.set(userData);
1651
+ * ```
1652
+ *
1653
+ * @param fn The asynchronous function to execute
1654
+ */
1655
+ async run(fn) {
1656
+ const removeTask = this.add();
1657
+ try {
1658
+ return await fn();
1659
+ } finally {
1660
+ removeTask();
1661
+ }
1662
+ }
1663
+ /** @nocollapse */
1664
+ static ɵprov = (
1665
+ /** @pureOrBreakMyCode */
1666
+ /* @__PURE__ */ ɵɵdefineInjectable({
1667
+ token: _PendingTasks,
1668
+ providedIn: "root",
1669
+ factory: () => new _PendingTasks()
1670
+ })
1671
+ );
1672
+ };
1673
+
1674
+ // src/import/render3/reactivity/microtask_effect.ts
1675
+ var MicrotaskEffectScheduler = class _MicrotaskEffectScheduler extends ZoneAwareEffectScheduler {
1676
+ pendingTasks = inject(PendingTasksInternal);
1677
+ taskId = null;
1678
+ schedule(effect3) {
1679
+ super.schedule(effect3);
1680
+ if (this.taskId === null) {
1681
+ this.taskId = this.pendingTasks.add();
1682
+ queueMicrotask(() => this.flush());
1683
+ }
1684
+ }
1685
+ flush() {
1686
+ try {
1687
+ super.flush();
1688
+ } finally {
1689
+ if (this.taskId !== null) {
1690
+ this.pendingTasks.remove(this.taskId);
1691
+ this.taskId = null;
1692
+ }
1693
+ }
1694
+ }
1695
+ /** @nocollapse */
1696
+ static ɵprov = (
1697
+ /** @pureOrBreakMyCode */
1698
+ /* @__PURE__ */ ɵɵdefineInjectable({
1699
+ token: _MicrotaskEffectScheduler,
1700
+ providedIn: "root",
1701
+ factory: () => new _MicrotaskEffectScheduler()
1702
+ })
1703
+ );
1704
+ };
1705
+ var EffectHandle = class {
1706
+ constructor(scheduler, effectFn, zone, destroyRef, injector, allowSignalWrites) {
1707
+ this.scheduler = scheduler;
1708
+ this.effectFn = effectFn;
1709
+ this.zone = zone;
1710
+ this.injector = injector;
1711
+ this.watcher = createWatch(
1712
+ (onCleanup) => this.runEffect(onCleanup),
1713
+ () => this.schedule(),
1714
+ allowSignalWrites
1715
+ );
1716
+ this.unregisterOnDestroy = destroyRef?.onDestroy(() => this.destroy());
1717
+ }
1718
+ unregisterOnDestroy;
1719
+ watcher;
1720
+ runEffect(onCleanup) {
1721
+ try {
1722
+ this.effectFn(onCleanup);
1723
+ } catch (err) {
1724
+ const errorHandler = this.injector.get(ErrorHandler, null, {
1725
+ optional: true
1726
+ });
1727
+ errorHandler?.handleError(err);
1728
+ }
1729
+ }
1730
+ run() {
1731
+ this.watcher.run();
1732
+ }
1733
+ schedule() {
1734
+ this.scheduler.schedule(this);
1735
+ }
1736
+ destroy() {
1737
+ this.watcher.destroy();
1738
+ this.unregisterOnDestroy?.();
1739
+ }
1740
+ };
1741
+ function effect() {
1742
+ }
1743
+ function microtaskEffect(effectFn, options) {
1744
+ !options?.injector && assertInInjectionContext(effect);
1745
+ const injector = options?.injector ?? inject(Injector);
1746
+ const destroyRef = options?.manualCleanup !== true ? injector.get(DestroyRef) : null;
1747
+ const handle = new EffectHandle(
1748
+ injector.get(MicrotaskEffectScheduler),
1749
+ effectFn,
1750
+ true ? null : (void 0).current,
1751
+ destroyRef,
1752
+ injector,
1753
+ options?.allowSignalWrites ?? false
1754
+ );
1755
+ handle.watcher.notify();
1756
+ return handle;
1757
+ }
1758
+
1759
+ // src/import/render3/reactivity/effect.ts
1760
+ var useMicrotaskEffectsByDefault = USE_MICROTASK_EFFECT_BY_DEFAULT;
1761
+ var EffectRefImpl = class {
1762
+ [SIGNAL];
1763
+ constructor(node) {
1764
+ this[SIGNAL] = node;
1765
+ }
1766
+ destroy() {
1767
+ this[SIGNAL].destroy();
1768
+ }
1769
+ };
1770
+ function effect2(effectFn, options) {
1771
+ if (useMicrotaskEffectsByDefault) {
1772
+ if (false) {
1773
+ throw new Error(
1774
+ `Cannot use 'forceRoot' option with microtask effects on`
1775
+ );
1776
+ }
1777
+ return microtaskEffect(effectFn, options);
1778
+ }
1779
+ !options?.injector && assertInInjectionContext(effect2);
1780
+ if (false) {
1781
+ console.warn(
1782
+ `The 'allowSignalWrites' flag is deprecated and no longer impacts effect() (writes are always allowed)`
1783
+ );
1784
+ }
1785
+ const injector = options?.injector ?? inject(Injector);
1786
+ const destroyRef = options?.manualCleanup !== true ? injector.get(DestroyRef) : null;
1787
+ let node;
1788
+ const notifier = injector.get(ChangeDetectionScheduler);
1789
+ node = createRootEffect(effectFn, injector.get(EffectScheduler), notifier);
1790
+ node.injector = injector;
1791
+ if (destroyRef !== null) {
1792
+ node.onDestroyFn = destroyRef.onDestroy(() => node.destroy());
1793
+ }
1794
+ const effectRef = new EffectRefImpl(node);
1795
+ return effectRef;
1796
+ }
1797
+ var BASE_EFFECT_NODE = /* @__PURE__ */ (() => ({
1798
+ ...REACTIVE_NODE,
1799
+ consumerIsAlwaysLive: true,
1800
+ consumerAllowSignalWrites: true,
1801
+ dirty: true,
1802
+ hasRun: false,
1803
+ cleanupFns: void 0,
1804
+ zone: null,
1805
+ kind: "effect",
1806
+ onDestroyFn: noop,
1807
+ run() {
1808
+ this.dirty = false;
1809
+ if (false) {
1810
+ throw new Error(
1811
+ `Schedulers cannot synchronously execute watches while scheduling.`
1812
+ );
1813
+ }
1814
+ if (this.hasRun && !consumerPollProducersForChange(this)) {
1815
+ return;
1816
+ }
1817
+ this.hasRun = true;
1818
+ const registerCleanupFn = (cleanupFn) => (this.cleanupFns ??= []).push(cleanupFn);
1819
+ const prevNode = consumerBeforeComputation(this);
1820
+ try {
1821
+ this.maybeCleanup();
1822
+ this.fn(registerCleanupFn);
1823
+ } finally {
1824
+ consumerAfterComputation(this, prevNode);
1825
+ }
1826
+ },
1827
+ maybeCleanup() {
1828
+ if (!this.cleanupFns?.length) {
1829
+ return;
1830
+ }
1831
+ try {
1832
+ while (this.cleanupFns.length) {
1833
+ this.cleanupFns.pop()();
1834
+ }
1835
+ } finally {
1836
+ this.cleanupFns = [];
1837
+ }
1838
+ }
1839
+ }))();
1840
+ var ROOT_EFFECT_NODE = /* @__PURE__ */ (() => ({
1841
+ ...BASE_EFFECT_NODE,
1842
+ consumerMarkedDirty() {
1843
+ this.scheduler.schedule(this);
1844
+ this.notifier.notify(12 /* RootEffect */);
1845
+ },
1846
+ destroy() {
1847
+ consumerDestroy(this);
1848
+ this.onDestroyFn();
1849
+ this.maybeCleanup();
1850
+ this.scheduler.remove(this);
1851
+ }
1852
+ }))();
1853
+ function createRootEffect(fn, scheduler, notifier) {
1854
+ const node = Object.create(ROOT_EFFECT_NODE);
1855
+ node.fn = fn;
1856
+ node.scheduler = scheduler;
1857
+ node.notifier = notifier;
1858
+ node.zone = false ? (void 0).current : null;
1859
+ node.scheduler.schedule(node);
1860
+ node.notifier.notify(12 /* RootEffect */);
1861
+ return node;
1862
+ }
1863
+
1864
+ // src/import/util/callback_scheduler.ts
1865
+ function scheduleCallbackWithRafRace(callback) {
1866
+ let timeoutId;
1867
+ let animationFrameId;
1868
+ function cleanup() {
1869
+ callback = noop;
1870
+ try {
1871
+ if (animationFrameId !== void 0 && typeof cancelAnimationFrame === "function") {
1872
+ cancelAnimationFrame(animationFrameId);
1873
+ }
1874
+ if (timeoutId !== void 0) {
1875
+ clearTimeout(timeoutId);
1876
+ }
1877
+ } catch {
1878
+ }
1879
+ }
1880
+ timeoutId = setTimeout(() => {
1881
+ callback();
1882
+ cleanup();
1883
+ });
1884
+ if (typeof requestAnimationFrame === "function") {
1885
+ animationFrameId = requestAnimationFrame(() => {
1886
+ callback();
1887
+ cleanup();
1888
+ });
1889
+ }
1890
+ return () => cleanup();
1891
+ }
1892
+
1893
+ // src/import/change_detection/scheduling/zoneless_scheduling_impl.ts
1894
+ var ChangeDetectionSchedulerImpl = class {
1895
+ runningTick = false;
1896
+ #rootEffectScheduler = inject(EffectScheduler);
1897
+ cancelScheduledCallback = null;
1898
+ notify(source) {
1899
+ this.cancelScheduledCallback = scheduleCallbackWithRafRace(() => {
1900
+ this.#rootEffectScheduler.flush();
1901
+ });
1902
+ }
1903
+ cleanup() {
1904
+ this.runningTick = false;
1905
+ this.cancelScheduledCallback?.();
1906
+ this.cancelScheduledCallback = null;
1907
+ }
1908
+ ngOnDestroy() {
1909
+ this.cleanup();
1910
+ }
1911
+ };
1912
+
1913
+ // src/import/resource/api.ts
1914
+ var ResourceStatus = /* @__PURE__ */ ((ResourceStatus2) => {
1915
+ ResourceStatus2[ResourceStatus2["Idle"] = 0] = "Idle";
1916
+ ResourceStatus2[ResourceStatus2["Error"] = 1] = "Error";
1917
+ ResourceStatus2[ResourceStatus2["Loading"] = 2] = "Loading";
1918
+ ResourceStatus2[ResourceStatus2["Reloading"] = 3] = "Reloading";
1919
+ ResourceStatus2[ResourceStatus2["Resolved"] = 4] = "Resolved";
1920
+ ResourceStatus2[ResourceStatus2["Local"] = 5] = "Local";
1921
+ return ResourceStatus2;
1922
+ })(ResourceStatus || {});
1923
+
1924
+ // src/import/resource/resource.ts
1925
+ function resource(options) {
1926
+ options?.injector || assertInInjectionContext(resource);
1927
+ const request = options.request ?? (() => null);
1928
+ return new ResourceImpl(
1929
+ request,
1930
+ getLoader(options),
1931
+ options.defaultValue,
1932
+ options.equal ? wrapEqualityFn(options.equal) : void 0,
1933
+ options.injector ?? inject(Injector)
1934
+ );
1935
+ }
1936
+ var BaseWritableResource = class {
1937
+ value;
1938
+ constructor(value) {
1939
+ this.value = value;
1940
+ this.value.set = this.set.bind(this);
1941
+ this.value.update = this.update.bind(this);
1942
+ this.value.asReadonly = signalAsReadonlyFn;
1943
+ }
1944
+ update(updateFn) {
1945
+ this.set(updateFn(untracked(this.value)));
1946
+ }
1947
+ isLoading = computed(
1948
+ () => this.status() === 2 /* Loading */ || this.status() === 3 /* Reloading */
1949
+ );
1950
+ hasValue() {
1951
+ return this.value() !== void 0;
1952
+ }
1953
+ asReadonly() {
1954
+ return this;
1955
+ }
1956
+ };
1957
+ var ResourceImpl = class extends BaseWritableResource {
1958
+ constructor(request, loaderFn, defaultValue, equal, injector) {
1959
+ super(
1960
+ // Feed a computed signal for the value to `BaseWritableResource`, which will upgrade it to a
1961
+ // `WritableSignal` that delegates to `ResourceImpl.set`.
1962
+ computed(
1963
+ () => {
1964
+ const streamValue = this.state().stream?.();
1965
+ return streamValue && isResolved(streamValue) ? streamValue.value : this.defaultValue;
1966
+ },
1967
+ { equal }
1968
+ )
1969
+ );
1970
+ this.loaderFn = loaderFn;
1971
+ this.defaultValue = defaultValue;
1972
+ this.equal = equal;
1973
+ this.extRequest = linkedSignal({
1974
+ source: request,
1975
+ computation: (request2) => ({ request: request2, reload: 0 })
1976
+ });
1977
+ this.state = linkedSignal({
1978
+ // Whenever the request changes,
1979
+ source: this.extRequest,
1980
+ // Compute the state of the resource given a change in status.
1981
+ computation: (extRequest, previous) => {
1982
+ const status = extRequest.request === void 0 ? 0 /* Idle */ : 2 /* Loading */;
1983
+ if (!previous) {
1984
+ return {
1985
+ extRequest,
1986
+ status,
1987
+ previousStatus: 0 /* Idle */,
1988
+ stream: void 0
1989
+ };
1990
+ } else {
1991
+ return {
1992
+ extRequest,
1993
+ status,
1994
+ previousStatus: projectStatusOfState(previous.value),
1995
+ // If the request hasn't changed, keep the previous stream.
1996
+ stream: previous.value.extRequest.request === extRequest.request ? previous.value.stream : void 0
1997
+ };
1998
+ }
1999
+ }
2000
+ });
2001
+ this.effectRef = effect2(this.loadEffect.bind(this), {
2002
+ injector,
2003
+ manualCleanup: true
2004
+ });
2005
+ this.pendingTasks = injector.get(PendingTasks);
2006
+ injector.get(DestroyRef).onDestroy(() => this.destroy());
2007
+ }
2008
+ pendingTasks;
2009
+ /**
2010
+ * The current state of the resource. Status, value, and error are derived from this.
2011
+ */
2012
+ state;
2013
+ /**
2014
+ * Combines the current request with a reload counter which allows the resource to be reloaded on
2015
+ * imperative command.
2016
+ */
2017
+ extRequest;
2018
+ effectRef;
2019
+ pendingController;
2020
+ resolvePendingTask = void 0;
2021
+ destroyed = false;
2022
+ status = computed(() => projectStatusOfState(this.state()));
2023
+ error = computed(() => {
2024
+ const stream = this.state().stream?.();
2025
+ return stream && !isResolved(stream) ? stream.error : void 0;
2026
+ });
2027
+ /**
2028
+ * Called either directly via `WritableResource.set` or via `.value.set()`.
2029
+ */
2030
+ set(value) {
2031
+ if (this.destroyed) {
2032
+ return;
2033
+ }
2034
+ const current = untracked(this.value);
2035
+ const state = untracked(this.state);
2036
+ if (state.status === 5 /* Local */ && (this.equal ? this.equal(current, value) : current === value)) {
2037
+ return;
2038
+ }
2039
+ this.state.set({
2040
+ extRequest: state.extRequest,
2041
+ status: 5 /* Local */,
2042
+ previousStatus: 5 /* Local */,
2043
+ stream: signal({ value })
2044
+ });
2045
+ this.abortInProgressLoad();
2046
+ }
2047
+ reload() {
2048
+ const { status } = untracked(this.state);
2049
+ if (status === 0 /* Idle */ || status === 2 /* Loading */) {
2050
+ return false;
2051
+ }
2052
+ this.extRequest.update(({ request, reload }) => ({
2053
+ request,
2054
+ reload: reload + 1
2055
+ }));
2056
+ return true;
2057
+ }
2058
+ destroy() {
2059
+ this.destroyed = true;
2060
+ this.effectRef.destroy();
2061
+ this.abortInProgressLoad();
2062
+ this.state.set({
2063
+ extRequest: { request: void 0, reload: 0 },
2064
+ status: 0 /* Idle */,
2065
+ previousStatus: 0 /* Idle */,
2066
+ stream: void 0
2067
+ });
2068
+ }
2069
+ async loadEffect() {
2070
+ const extRequest = this.extRequest();
2071
+ const { status: currentStatus, previousStatus } = untracked(this.state);
2072
+ if (extRequest.request === void 0) {
2073
+ return;
2074
+ } else if (currentStatus !== 2 /* Loading */) {
2075
+ return;
2076
+ }
2077
+ this.abortInProgressLoad();
2078
+ let resolvePendingTask = this.resolvePendingTask = this.pendingTasks.add();
2079
+ const { signal: abortSignal } = this.pendingController = new AbortController();
2080
+ try {
2081
+ const stream = await untracked(
2082
+ () => this.loaderFn({
2083
+ request: extRequest.request,
2084
+ abortSignal,
2085
+ previous: {
2086
+ status: previousStatus
2087
+ }
2088
+ })
2089
+ );
2090
+ if (abortSignal.aborted || untracked(this.extRequest) !== extRequest) {
2091
+ return;
2092
+ }
2093
+ this.state.set({
2094
+ extRequest,
2095
+ status: 4 /* Resolved */,
2096
+ previousStatus: 4 /* Resolved */,
2097
+ stream
2098
+ });
2099
+ } catch (err) {
2100
+ if (abortSignal.aborted || untracked(this.extRequest) !== extRequest) {
2101
+ return;
2102
+ }
2103
+ this.state.set({
2104
+ extRequest,
2105
+ status: 4 /* Resolved */,
2106
+ previousStatus: 1 /* Error */,
2107
+ stream: signal({ error: err })
2108
+ });
2109
+ } finally {
2110
+ resolvePendingTask?.();
2111
+ resolvePendingTask = void 0;
2112
+ }
2113
+ }
2114
+ abortInProgressLoad() {
2115
+ untracked(() => this.pendingController?.abort());
2116
+ this.pendingController = void 0;
2117
+ this.resolvePendingTask?.();
2118
+ this.resolvePendingTask = void 0;
2119
+ }
2120
+ };
2121
+ function wrapEqualityFn(equal) {
2122
+ return (a, b) => a === void 0 || b === void 0 ? a === b : equal(a, b);
2123
+ }
2124
+ function getLoader(options) {
2125
+ if (isStreamingResourceOptions(options)) {
2126
+ return options.stream;
2127
+ }
2128
+ return async (params) => {
2129
+ try {
2130
+ return signal({ value: await options.loader(params) });
2131
+ } catch (err) {
2132
+ return signal({ error: err });
2133
+ }
2134
+ };
2135
+ }
2136
+ function isStreamingResourceOptions(options) {
2137
+ return !!options.stream;
2138
+ }
2139
+ function projectStatusOfState(state) {
2140
+ switch (state.status) {
2141
+ case 2 /* Loading */:
2142
+ return state.extRequest.reload === 0 ? 2 /* Loading */ : 3 /* Reloading */;
2143
+ case 4 /* Resolved */:
2144
+ return isResolved(untracked(state.stream)) ? 4 /* Resolved */ : 1 /* Error */;
2145
+ default:
2146
+ return state.status;
2147
+ }
2148
+ }
2149
+ function isResolved(state) {
2150
+ return state.error === void 0;
2151
+ }
2152
+
2153
+ // src/import/index.ts
2154
+ var StaticInjectOptions = class {
2155
+ static injectOptions;
2156
+ };
2157
+ var RootStaticInjectOptions = class {
2158
+ static injectOptions = {
2159
+ providedIn: "root"
2160
+ };
2161
+ };
2162
+ function createInjector2(options) {
2163
+ return new R3Injector(
2164
+ options.providers,
2165
+ options.parent ?? getNullInjector(),
2166
+ options.name ?? "",
2167
+ options.scopes ?? /* @__PURE__ */ new Set([])
2168
+ );
2169
+ }
2170
+ function createRootInjector(options) {
2171
+ return new R3Injector(
2172
+ [
2173
+ ...options.providers,
2174
+ {
2175
+ provide: INJECTOR_SCOPE,
2176
+ useValue: "root"
2177
+ }
2178
+ ],
2179
+ getNullInjector(),
2180
+ options.name ?? "",
2181
+ options.scopes ?? /* @__PURE__ */ new Set([])
2182
+ );
2183
+ }
2184
+ export {
2185
+ ChangeDetectionScheduler,
2186
+ ChangeDetectionSchedulerImpl,
2187
+ DecoratorFlags,
2188
+ EnvironmentInjector,
2189
+ INJECTOR_SCOPE,
2190
+ Inject,
2191
+ InjectFlags,
2192
+ InjectionToken,
2193
+ Injector,
2194
+ InternalInjectFlags,
2195
+ NG_INJ_DEF,
2196
+ NG_PROV_DEF,
2197
+ NG_TEMP_TOKEN_PATH,
2198
+ NotificationSource,
2199
+ NullInjector,
2200
+ Optional,
2201
+ PROVIDED_ZONELESS,
2202
+ R3Injector,
2203
+ ResourceStatus,
2204
+ RootStaticInjectOptions,
2205
+ SCHEDULE_IN_ROOT_ZONE,
2206
+ SOURCE,
2207
+ Self,
2208
+ SkipSelf,
2209
+ StaticInjectOptions,
2210
+ THROW_IF_NOT_FOUND,
2211
+ ZONELESS_ENABLED,
2212
+ ZONELESS_SCHEDULER_DISABLED,
2213
+ assertNotDestroyed,
2214
+ assertNotInReactiveContext,
2215
+ attachInjectFlag,
2216
+ catchInjectorError,
2217
+ computed,
2218
+ convertToBitFlags,
2219
+ createInjector2 as createInjector,
2220
+ createRootInjector,
2221
+ effect2 as effect,
2222
+ formatError,
2223
+ getCurrentInjector,
2224
+ getInheritedInjectableDef,
2225
+ getInjectFlag,
2226
+ getInjectableDef,
2227
+ getInjectorDef,
2228
+ getNullInjector,
2229
+ inject,
2230
+ injectArgs,
2231
+ injectInjectorOnly,
2232
+ isInjectable,
2233
+ isSignal,
2234
+ linkedSignal,
2235
+ providerToFactory,
2236
+ resource,
2237
+ setCurrentInjector,
2238
+ signal,
2239
+ untracked,
2240
+ EffectScheduler as ɵEffectScheduler,
2241
+ MicrotaskEffectScheduler as ɵMicrotaskEffectScheduler,
2242
+ SIGNAL as ɵSIGNAL,
2243
+ microtaskEffect as ɵmicrotaskEffect,
2244
+ ɵunwrapWritableSignal,
2245
+ ɵɵdefineInjectable,
2246
+ ɵɵdefineInjector,
2247
+ ɵɵinject,
2248
+ ɵɵinvalidFactory,
2249
+ ɵɵinvalidFactoryDep
2250
+ };
2251
+ /**
2252
+ * @license
2253
+ * Copyright Google LLC All Rights Reserved.
2254
+ *
2255
+ * Use of this source code is governed by an MIT-style license that can be
2256
+ * found in the LICENSE file at https://angular.dev/license
2257
+ */
2258
+ //# sourceMappingURL=index.mjs.map