UNPKG

@angular/core

Version:

Angular - the core framework

1,558 lines (1,522 loc) 98.5 kB
/** * @license Angular v21.0.5 * (c) 2010-2025 Google LLC. https://angular.dev/ * License: MIT */ import { getActiveConsumer, setActiveConsumer as setActiveConsumer$1, createSignal, SIGNAL, consumerDestroy, BASE_EFFECT_NODE, isInNotificationPhase, runEffect, untracked as untracked$1 } from './_effect-chunk.mjs'; import { BehaviorSubject, Observable, Subject, Subscription } from 'rxjs'; import { isNotFound, getCurrentInjector, setCurrentInjector } from './_not_found-chunk.mjs'; import { setActiveConsumer } from '@angular/core/primitives/signals'; import { isNotFound as isNotFound$1 } from '@angular/core/primitives/di'; class Version { full; major; minor; patch; constructor(full) { this.full = full; const parts = full.split('.'); this.major = parts[0]; this.minor = parts[1]; this.patch = parts.slice(2).join('.'); } } const VERSION = /* @__PURE__ */new Version('21.0.5'); const ERROR_DETAILS_PAGE_BASE_URL = (() => { const versionSubDomain = VERSION.major !== '0' ? `v${VERSION.major}.` : ''; return `https://${versionSubDomain}angular.dev/errors`; })(); const XSS_SECURITY_URL = 'https://angular.dev/best-practices/security#preventing-cross-site-scripting-xss'; class RuntimeError extends Error { code; constructor(code, message) { super(formatRuntimeError(code, message)); this.code = code; } } function formatRuntimeErrorCode(code) { return `NG0${Math.abs(code)}`; } function formatRuntimeError(code, message) { const fullCode = formatRuntimeErrorCode(code); let errorMessage = `${fullCode}${message ? ': ' + message : ''}`; if (ngDevMode && code < 0) { const addPeriodSeparator = !errorMessage.match(/[.,;!?\n]$/); const separator = addPeriodSeparator ? '.' : ''; errorMessage = `${errorMessage}${separator} Find more at ${ERROR_DETAILS_PAGE_BASE_URL}/${fullCode}`; } return errorMessage; } const _global = globalThis; function ngDevModeResetPerfCounters() { const locationString = typeof location !== 'undefined' ? location.toString() : ''; const newCounters = { hydratedNodes: 0, hydratedComponents: 0, dehydratedViewsRemoved: 0, dehydratedViewsCleanupRuns: 0, componentsSkippedHydration: 0, deferBlocksWithIncrementalHydration: 0 }; const allowNgDevModeTrue = locationString.indexOf('ngDevMode=false') === -1; if (!allowNgDevModeTrue) { _global['ngDevMode'] = false; } else { if (typeof _global['ngDevMode'] !== 'object') { _global['ngDevMode'] = {}; } Object.assign(_global['ngDevMode'], newCounters); } return newCounters; } function initNgDevMode() { if (typeof ngDevMode === 'undefined' || ngDevMode) { if (typeof ngDevMode !== 'object' || Object.keys(ngDevMode).length === 0) { ngDevModeResetPerfCounters(); } return typeof ngDevMode !== 'undefined' && !!ngDevMode; } return false; } function getClosureSafeProperty(objWithPropertyToExtract) { for (let key in objWithPropertyToExtract) { if (objWithPropertyToExtract[key] === getClosureSafeProperty) { return key; } } throw Error(typeof ngDevMode !== 'undefined' && ngDevMode ? 'Could not find renamed property on target object.' : ''); } function fillProperties(target, source) { for (const key in source) { if (source.hasOwnProperty(key) && !target.hasOwnProperty(key)) { target[key] = source[key]; } } } function stringify(token) { if (typeof token === 'string') { return token; } if (Array.isArray(token)) { return `[${token.map(stringify).join(', ')}]`; } if (token == null) { return '' + token; } const name = token.overriddenName || token.name; if (name) { return `${name}`; } const result = token.toString(); if (result == null) { return '' + result; } const newLineIndex = result.indexOf('\n'); return newLineIndex >= 0 ? result.slice(0, newLineIndex) : result; } function concatStringsWithSpace(before, after) { if (!before) return after || ''; if (!after) return before; return `${before} ${after}`; } function truncateMiddle(str, maxLength = 100) { if (!str || maxLength < 1 || str.length <= maxLength) return str; if (maxLength == 1) return str.substring(0, 1) + '...'; const halfLimit = Math.round(maxLength / 2); return str.substring(0, halfLimit) + '...' + str.substring(str.length - halfLimit); } const __forward_ref__ = getClosureSafeProperty({ __forward_ref__: getClosureSafeProperty }); function forwardRef(forwardRefFn) { forwardRefFn.__forward_ref__ = forwardRef; forwardRefFn.toString = function () { return stringify(this()); }; return forwardRefFn; } function resolveForwardRef(type) { return isForwardRef(type) ? type() : type; } function isForwardRef(fn) { return typeof fn === 'function' && fn.hasOwnProperty(__forward_ref__) && fn.__forward_ref__ === forwardRef; } function assertNumber(actual, msg) { if (!(typeof actual === 'number')) { throwError(msg, typeof actual, 'number', '==='); } } function assertNumberInRange(actual, minInclusive, maxInclusive) { assertNumber(actual, 'Expected a number'); assertLessThanOrEqual(actual, maxInclusive, 'Expected number to be less than or equal to'); assertGreaterThanOrEqual(actual, minInclusive, 'Expected number to be greater than or equal to'); } function assertString(actual, msg) { if (!(typeof actual === 'string')) { throwError(msg, actual === null ? 'null' : typeof actual, 'string', '==='); } } function assertFunction(actual, msg) { if (!(typeof actual === 'function')) { throwError(msg, actual === null ? 'null' : typeof actual, 'function', '==='); } } function assertEqual(actual, expected, msg) { if (!(actual == expected)) { throwError(msg, actual, expected, '=='); } } function assertNotEqual(actual, expected, msg) { if (!(actual != expected)) { throwError(msg, actual, expected, '!='); } } function assertSame(actual, expected, msg) { if (!(actual === expected)) { throwError(msg, actual, expected, '==='); } } function assertNotSame(actual, expected, msg) { if (!(actual !== expected)) { throwError(msg, actual, expected, '!=='); } } function assertLessThan(actual, expected, msg) { if (!(actual < expected)) { throwError(msg, actual, expected, '<'); } } function assertLessThanOrEqual(actual, expected, msg) { if (!(actual <= expected)) { throwError(msg, actual, expected, '<='); } } function assertGreaterThan(actual, expected, msg) { if (!(actual > expected)) { throwError(msg, actual, expected, '>'); } } function assertGreaterThanOrEqual(actual, expected, msg) { if (!(actual >= expected)) { throwError(msg, actual, expected, '>='); } } function assertNotDefined(actual, msg) { if (actual != null) { throwError(msg, actual, null, '=='); } } function assertDefined(actual, msg) { if (actual == null) { throwError(msg, actual, null, '!='); } } function throwError(msg, actual, expected, comparison) { throw new Error(`ASSERTION ERROR: ${msg}` + (comparison == null ? '' : ` [Expected=> ${expected} ${comparison} ${actual} <=Actual]`)); } function assertDomNode(node) { if (!(node instanceof Node)) { throwError(`The provided value must be an instance of a DOM Node but got ${stringify(node)}`); } } function assertElement(node) { if (!(node instanceof Element)) { throwError(`The provided value must be an element but got ${stringify(node)}`); } } function assertIndexInRange(arr, index) { assertDefined(arr, 'Array must be defined.'); const maxLen = arr.length; if (index < 0 || index >= maxLen) { throwError(`Index expected to be less than ${maxLen} but got ${index}`); } } function assertOneOf(value, ...validValues) { if (validValues.indexOf(value) !== -1) return true; throwError(`Expected value to be one of ${JSON.stringify(validValues)} but was ${JSON.stringify(value)}.`); } function assertNotReactive(fn) { if (getActiveConsumer() !== null) { throwError(`${fn}() should never be called in a reactive context.`); } } function ɵɵdefineInjectable(opts) { return { token: opts.token, providedIn: opts.providedIn || null, factory: opts.factory, value: undefined }; } function ɵɵdefineInjector(options) { return { providers: options.providers || [], imports: options.imports || [] }; } function getInjectableDef(type) { return getOwnDefinition(type, NG_PROV_DEF); } function isInjectable(type) { return getInjectableDef(type) !== null; } function getOwnDefinition(type, field) { return type.hasOwnProperty(field) && type[field] || null; } function getInheritedInjectableDef(type) { const def = type?.[NG_PROV_DEF] ?? null; if (def) { ngDevMode && console.warn(`DEPRECATED: DI is instantiating a token "${type.name}" that inherits its @Injectable decorator but does not provide one itself.\n` + `This will become an error in a future version of Angular. Please add @Injectable() to the "${type.name}" class.`); return def; } else { return null; } } function getInjectorDef(type) { return type && type.hasOwnProperty(NG_INJ_DEF) ? type[NG_INJ_DEF] : null; } const NG_PROV_DEF = getClosureSafeProperty({ ɵprov: getClosureSafeProperty }); const NG_INJ_DEF = getClosureSafeProperty({ ɵinj: getClosureSafeProperty }); class InjectionToken { _desc; ngMetadataName = 'InjectionToken'; ɵprov; constructor(_desc, options) { this._desc = _desc; this.ɵprov = undefined; if (typeof options == 'number') { (typeof ngDevMode === 'undefined' || ngDevMode) && assertLessThan(options, 0, 'Only negative numbers are supported here'); this.__NG_ELEMENT_ID__ = options; } else if (options !== undefined) { this.ɵprov = ɵɵdefineInjectable({ token: this, providedIn: options.providedIn || 'root', factory: options.factory }); } } get multi() { return this; } toString() { return `InjectionToken ${this._desc}`; } } let _injectorProfilerContext; function getInjectorProfilerContext() { !ngDevMode && throwError('getInjectorProfilerContext should never be called in production mode'); return _injectorProfilerContext; } function setInjectorProfilerContext(context) { !ngDevMode && throwError('setInjectorProfilerContext should never be called in production mode'); const previous = _injectorProfilerContext; _injectorProfilerContext = context; return previous; } const injectorProfilerCallbacks = []; const NOOP_PROFILER_REMOVAL = () => {}; function removeProfiler(profiler) { const profilerIdx = injectorProfilerCallbacks.indexOf(profiler); if (profilerIdx !== -1) { injectorProfilerCallbacks.splice(profilerIdx, 1); } } function setInjectorProfiler(injectorProfiler) { !ngDevMode && throwError('setInjectorProfiler should never be called in production mode'); if (injectorProfiler !== null) { if (!injectorProfilerCallbacks.includes(injectorProfiler)) { injectorProfilerCallbacks.push(injectorProfiler); } return () => removeProfiler(injectorProfiler); } else { injectorProfilerCallbacks.length = 0; return NOOP_PROFILER_REMOVAL; } } function injectorProfiler(event) { !ngDevMode && throwError('Injector profiler should never be called in production mode'); for (let i = 0; i < injectorProfilerCallbacks.length; i++) { const injectorProfilerCallback = injectorProfilerCallbacks[i]; injectorProfilerCallback(event); } } function emitProviderConfiguredEvent(eventProvider, isViewProvider = false) { !ngDevMode && throwError('Injector profiler should never be called in production mode'); let token; if (typeof eventProvider === 'function') { token = eventProvider; } else if (eventProvider instanceof InjectionToken) { token = eventProvider; } else { token = resolveForwardRef(eventProvider.provide); } let provider = eventProvider; if (eventProvider instanceof InjectionToken) { provider = eventProvider.ɵprov || eventProvider; } injectorProfiler({ type: 2, context: getInjectorProfilerContext(), providerRecord: { token, provider, isViewProvider } }); } function emitInjectorToCreateInstanceEvent(token) { !ngDevMode && throwError('Injector profiler should never be called in production mode'); injectorProfiler({ type: 5, context: getInjectorProfilerContext(), token: token }); } function emitInstanceCreatedByInjectorEvent(instance) { !ngDevMode && throwError('Injector profiler should never be called in production mode'); injectorProfiler({ type: 1, context: getInjectorProfilerContext(), instance: { value: instance } }); } function emitInjectEvent(token, value, flags) { !ngDevMode && throwError('Injector profiler should never be called in production mode'); injectorProfiler({ type: 0, context: getInjectorProfilerContext(), service: { token, value, flags } }); } function emitEffectCreatedEvent(effect) { !ngDevMode && throwError('Injector profiler should never be called in production mode'); injectorProfiler({ type: 3, context: getInjectorProfilerContext(), effect }); } function emitAfterRenderEffectPhaseCreatedEvent(effectPhase) { !ngDevMode && throwError('Injector profiler should never be called in production mode'); injectorProfiler({ type: 4, context: getInjectorProfilerContext(), effectPhase }); } function runInInjectorProfilerContext(injector, token, callback) { !ngDevMode && throwError('runInInjectorProfilerContext should never be called in production mode'); const prevInjectContext = setInjectorProfilerContext({ injector, token }); try { callback(); } finally { setInjectorProfilerContext(prevInjectContext); } } function isEnvironmentProviders(value) { return value && !!value.ɵproviders; } const NG_COMP_DEF = getClosureSafeProperty({ ɵcmp: getClosureSafeProperty }); const NG_DIR_DEF = getClosureSafeProperty({ ɵdir: getClosureSafeProperty }); const NG_PIPE_DEF = getClosureSafeProperty({ ɵpipe: getClosureSafeProperty }); const NG_MOD_DEF = getClosureSafeProperty({ ɵmod: getClosureSafeProperty }); const NG_FACTORY_DEF = getClosureSafeProperty({ ɵfac: getClosureSafeProperty }); const NG_ELEMENT_ID = getClosureSafeProperty({ __NG_ELEMENT_ID__: getClosureSafeProperty }); const NG_ENV_ID = getClosureSafeProperty({ __NG_ENV_ID__: getClosureSafeProperty }); function getNgModuleDef(type) { return type[NG_MOD_DEF] || null; } function getNgModuleDefOrThrow(type) { const ngModuleDef = getNgModuleDef(type); if (!ngModuleDef) { throw new RuntimeError(915, (typeof ngDevMode === 'undefined' || ngDevMode) && `Type ${stringify(type)} does not have 'ɵmod' property.`); } return ngModuleDef; } function getComponentDef(type) { return type[NG_COMP_DEF] || null; } function getDirectiveDefOrThrow(type) { const def = getDirectiveDef(type); if (!def) { throw new RuntimeError(916, (typeof ngDevMode === 'undefined' || ngDevMode) && `Type ${stringify(type)} does not have 'ɵdir' property.`); } return def; } function getDirectiveDef(type) { return type[NG_DIR_DEF] || null; } function getPipeDef(type) { return type[NG_PIPE_DEF] || null; } function isStandalone(type) { const def = getComponentDef(type) || getDirectiveDef(type) || getPipeDef(type); return def !== null && def.standalone; } function renderStringify(value) { if (typeof value === 'string') return value; if (value == null) return ''; return String(value); } function stringifyForError(value) { if (typeof value === 'function') return value.name || value.toString(); if (typeof value === 'object' && value != null && typeof value.type === 'function') { return value.type.name || value.type.toString(); } return renderStringify(value); } function debugStringifyTypeForError(type) { const componentDef = getComponentDef(type); if (componentDef !== null && componentDef.debugInfo) { return stringifyTypeFromDebugInfo(componentDef.debugInfo); } return stringifyForError(type); } function stringifyTypeFromDebugInfo(debugInfo) { if (!debugInfo.filePath || !debugInfo.lineNumber) { return debugInfo.className; } else { return `${debugInfo.className} (at ${debugInfo.filePath}:${debugInfo.lineNumber})`; } } const NG_RUNTIME_ERROR_CODE = getClosureSafeProperty({ 'ngErrorCode': getClosureSafeProperty }); const NG_RUNTIME_ERROR_MESSAGE = getClosureSafeProperty({ 'ngErrorMessage': getClosureSafeProperty }); const NG_TOKEN_PATH = getClosureSafeProperty({ 'ngTokenPath': getClosureSafeProperty }); function cyclicDependencyError(token, path) { const message = ngDevMode ? `Circular dependency detected for \`${token}\`.` : ''; return createRuntimeError(message, -200, path); } function cyclicDependencyErrorWithDetails(token, path) { return augmentRuntimeError(cyclicDependencyError(token, path), null); } function throwMixedMultiProviderError() { throw new Error(`Cannot mix multi providers and regular providers`); } function throwInvalidProviderError(ngModuleType, providers, provider) { if (ngModuleType && providers) { const providerDetail = providers.map(v => v == provider ? '?' + provider + '?' : '...'); throw new Error(`Invalid provider for the NgModule '${stringify(ngModuleType)}' - only instances of Provider and Type are allowed, got: [${providerDetail.join(', ')}]`); } else if (isEnvironmentProviders(provider)) { if (provider.ɵfromNgModule) { throw new RuntimeError(207, `Invalid providers from 'importProvidersFrom' present in a non-environment injector. 'importProvidersFrom' can't be used for component providers.`); } else { throw new RuntimeError(207, `Invalid providers present in a non-environment injector. 'EnvironmentProviders' can't be used for component providers.`); } } else { throw new Error('Invalid provider'); } } function throwProviderNotFoundError(token, injectorName) { const errorMessage = ngDevMode && `No provider for ${stringifyForError(token)} found${injectorName ? ` in ${injectorName}` : ''}`; throw new RuntimeError(-201, errorMessage); } function prependTokenToDependencyPath(error, token) { error[NG_TOKEN_PATH] ??= []; const currentPath = error[NG_TOKEN_PATH]; let pathStr; if (typeof token === 'object' && 'multi' in token && token?.multi === true) { assertDefined(token.provide, 'Token with multi: true should have a provide property'); pathStr = stringifyForError(token.provide); } else { pathStr = stringifyForError(token); } if (currentPath[0] !== pathStr) { error[NG_TOKEN_PATH].unshift(pathStr); } } function augmentRuntimeError(error, source) { const tokenPath = error[NG_TOKEN_PATH]; const errorCode = error[NG_RUNTIME_ERROR_CODE]; const message = error[NG_RUNTIME_ERROR_MESSAGE] || error.message; error.message = formatErrorMessage(message, errorCode, tokenPath, source); return error; } function createRuntimeError(message, code, path) { const error = new RuntimeError(code, message); error[NG_RUNTIME_ERROR_CODE] = code; error[NG_RUNTIME_ERROR_MESSAGE] = message; if (path) { error[NG_TOKEN_PATH] = path; } return error; } function getRuntimeErrorCode(error) { return error[NG_RUNTIME_ERROR_CODE]; } function formatErrorMessage(text, code, path = [], source = null) { let pathDetails = ''; if (path && path.length > 1) { pathDetails = ` Path: ${path.join(' -> ')}.`; } const sourceDetails = source ? ` Source: ${source}.` : ''; return formatRuntimeError(code, `${text}${sourceDetails}${pathDetails}`); } let _injectImplementation; function getInjectImplementation() { return _injectImplementation; } function setInjectImplementation(impl) { const previous = _injectImplementation; _injectImplementation = impl; return previous; } function injectRootLimpMode(token, notFoundValue, flags) { const injectableDef = getInjectableDef(token); if (injectableDef && injectableDef.providedIn == 'root') { return injectableDef.value === undefined ? injectableDef.value = injectableDef.factory() : injectableDef.value; } if (flags & 8) return null; if (notFoundValue !== undefined) return notFoundValue; throwProviderNotFoundError(token, 'Injector'); } function assertInjectImplementationNotEqual(fn) { ngDevMode && assertNotEqual(_injectImplementation, fn, 'Calling ɵɵinject would cause infinite recursion'); } const _THROW_IF_NOT_FOUND = {}; const THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND; const DI_DECORATOR_FLAG = '__NG_DI_FLAG__'; class RetrievingInjector { injector; constructor(injector) { this.injector = injector; } retrieve(token, options) { const flags = convertToBitFlags(options) || 0; try { return this.injector.get(token, flags & 8 ? null : THROW_IF_NOT_FOUND, flags); } catch (e) { if (isNotFound(e)) { return e; } throw e; } } } function injectInjectorOnly(token, flags = 0) { const currentInjector = getCurrentInjector(); if (currentInjector === undefined) { throw new RuntimeError(-203, ngDevMode && `The \`${stringify(token)}\` token injection failed. \`inject()\` function must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with \`runInInjectionContext\`.`); } else if (currentInjector === null) { return injectRootLimpMode(token, undefined, flags); } else { const options = convertToInjectOptions(flags); const value = currentInjector.retrieve(token, options); ngDevMode && emitInjectEvent(token, value, flags); if (isNotFound(value)) { if (options.optional) { return null; } throw value; } return value; } } function ɵɵinject(token, flags = 0) { return (getInjectImplementation() || injectInjectorOnly)(resolveForwardRef(token), flags); } function ɵɵinvalidFactoryDep(index) { throw new RuntimeError(202, ngDevMode && `This constructor is not compatible with Angular Dependency Injection because its dependency at index ${index} of the parameter list is invalid. This can happen if the dependency type is a primitive like a string or if an ancestor of this class is missing an Angular decorator. Please check that 1) the type for the parameter at index ${index} is correct and 2) the correct Angular decorators are defined for this class and its ancestors.`); } function inject(token, options) { return ɵɵinject(token, convertToBitFlags(options)); } function convertToBitFlags(flags) { if (typeof flags === 'undefined' || typeof flags === 'number') { return flags; } return 0 | (flags.optional && 8) | (flags.host && 1) | (flags.self && 2) | (flags.skipSelf && 4); } function convertToInjectOptions(flags) { return { optional: !!(flags & 8), host: !!(flags & 1), self: !!(flags & 2), skipSelf: !!(flags & 4) }; } function injectArgs(types) { const args = []; for (let i = 0; i < types.length; i++) { const arg = resolveForwardRef(types[i]); if (Array.isArray(arg)) { if (arg.length === 0) { throw new RuntimeError(900, ngDevMode && 'Arguments array must have arguments.'); } let type = undefined; let flags = 0; for (let j = 0; j < arg.length; j++) { const meta = arg[j]; const flag = getInjectFlag(meta); if (typeof flag === 'number') { if (flag === -1) { type = meta.token; } else { flags |= flag; } } else { type = meta; } } args.push(ɵɵinject(type, flags)); } else { args.push(ɵɵinject(arg)); } } return args; } function attachInjectFlag(decorator, flag) { decorator[DI_DECORATOR_FLAG] = flag; decorator.prototype[DI_DECORATOR_FLAG] = flag; return decorator; } function getInjectFlag(token) { return token[DI_DECORATOR_FLAG]; } function getFactoryDef(type, throwNotFound) { const hasFactoryDef = type.hasOwnProperty(NG_FACTORY_DEF); if (!hasFactoryDef && throwNotFound === true && ngDevMode) { throw new Error(`Type ${stringify(type)} does not have 'ɵfac' property.`); } return hasFactoryDef ? type[NG_FACTORY_DEF] : null; } function arrayEquals(a, b, identityAccessor) { if (a.length !== b.length) return false; for (let i = 0; i < a.length; i++) { let valueA = a[i]; let valueB = b[i]; if (identityAccessor) { valueA = identityAccessor(valueA); valueB = identityAccessor(valueB); } if (valueB !== valueA) { return false; } } return true; } function flatten(list) { return list.flat(Number.POSITIVE_INFINITY); } function deepForEach(input, fn) { input.forEach(value => Array.isArray(value) ? deepForEach(value, fn) : fn(value)); } function addToArray(arr, index, value) { if (index >= arr.length) { arr.push(value); } else { arr.splice(index, 0, value); } } function removeFromArray(arr, index) { if (index >= arr.length - 1) { return arr.pop(); } else { return arr.splice(index, 1)[0]; } } function newArray(size, value) { const list = []; for (let i = 0; i < size; i++) { list.push(value); } return list; } function arraySplice(array, index, count) { const length = array.length - count; while (index < length) { array[index] = array[index + count]; index++; } while (count--) { array.pop(); } } function arrayInsert2(array, index, value1, value2) { ngDevMode && assertLessThanOrEqual(index, array.length, "Can't insert past array end."); let end = array.length; if (end == index) { array.push(value1, value2); } else if (end === 1) { array.push(value2, array[0]); array[0] = value1; } else { end--; array.push(array[end - 1], array[end]); while (end > index) { const previousEnd = end - 2; array[end] = array[previousEnd]; end--; } array[index] = value1; array[index + 1] = value2; } } function keyValueArraySet(keyValueArray, key, value) { let index = keyValueArrayIndexOf(keyValueArray, key); if (index >= 0) { keyValueArray[index | 1] = value; } else { index = ~index; arrayInsert2(keyValueArray, index, key, value); } return index; } function keyValueArrayGet(keyValueArray, key) { const index = keyValueArrayIndexOf(keyValueArray, key); if (index >= 0) { return keyValueArray[index | 1]; } return undefined; } function keyValueArrayIndexOf(keyValueArray, key) { return _arrayIndexOfSorted(keyValueArray, key, 1); } function _arrayIndexOfSorted(array, value, shift) { ngDevMode && assertEqual(Array.isArray(array), true, 'Expecting an array'); let start = 0; let end = array.length >> shift; while (end !== start) { const middle = start + (end - start >> 1); const current = array[middle << shift]; if (value === current) { return middle << shift; } else if (current > value) { end = middle; } else { start = middle + 1; } } return ~(end << shift); } const EMPTY_OBJ = {}; const EMPTY_ARRAY = []; if ((typeof ngDevMode === 'undefined' || ngDevMode) && initNgDevMode()) { Object.freeze(EMPTY_OBJ); Object.freeze(EMPTY_ARRAY); } const ENVIRONMENT_INITIALIZER = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'ENVIRONMENT_INITIALIZER' : ''); const INJECTOR$1 = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'INJECTOR' : '', -1); const INJECTOR_DEF_TYPES = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'INJECTOR_DEF_TYPES' : ''); class NullInjector { get(token, notFoundValue = THROW_IF_NOT_FOUND) { if (notFoundValue === THROW_IF_NOT_FOUND) { const message = ngDevMode ? `No provider found for \`${stringify(token)}\`.` : ''; const error = createRuntimeError(message, -201); error.name = 'ɵNotFound'; throw error; } return notFoundValue; } } function makeEnvironmentProviders(providers) { return { ɵproviders: providers }; } function provideEnvironmentInitializer(initializerFn) { return makeEnvironmentProviders([{ provide: ENVIRONMENT_INITIALIZER, multi: true, useValue: initializerFn }]); } function importProvidersFrom(...sources) { return { ɵproviders: internalImportProvidersFrom(true, sources), ɵfromNgModule: true }; } function internalImportProvidersFrom(checkForStandaloneCmp, ...sources) { const providersOut = []; const dedup = new Set(); let injectorTypesWithProviders; const collectProviders = provider => { providersOut.push(provider); }; deepForEach(sources, source => { if ((typeof ngDevMode === 'undefined' || ngDevMode) && checkForStandaloneCmp) { const cmpDef = getComponentDef(source); if (cmpDef?.standalone) { throw new RuntimeError(800, `Importing providers supports NgModule or ModuleWithProviders but got a standalone component "${stringifyForError(source)}"`); } } const internalSource = source; if (walkProviderTree(internalSource, collectProviders, [], dedup)) { injectorTypesWithProviders ||= []; injectorTypesWithProviders.push(internalSource); } }); if (injectorTypesWithProviders !== undefined) { processInjectorTypesWithProviders(injectorTypesWithProviders, collectProviders); } return providersOut; } function processInjectorTypesWithProviders(typesWithProviders, visitor) { for (let i = 0; i < typesWithProviders.length; i++) { const { ngModule, providers } = typesWithProviders[i]; deepForEachProvider(providers, provider => { ngDevMode && validateProvider(provider, providers || EMPTY_ARRAY, ngModule); visitor(provider, ngModule); }); } } function walkProviderTree(container, visitor, parents, dedup) { container = resolveForwardRef(container); if (!container) return false; let defType = null; let injDef = getInjectorDef(container); const cmpDef = !injDef && getComponentDef(container); if (!injDef && !cmpDef) { const ngModule = container.ngModule; injDef = getInjectorDef(ngModule); if (injDef) { defType = ngModule; } else { return false; } } else if (cmpDef && !cmpDef.standalone) { return false; } else { defType = container; } if (ngDevMode && parents.indexOf(defType) !== -1) { const defName = stringify(defType); const path = parents.map(stringify).concat(defName); throw cyclicDependencyErrorWithDetails(defName, path); } const isDuplicate = dedup.has(defType); if (cmpDef) { if (isDuplicate) { return false; } dedup.add(defType); if (cmpDef.dependencies) { const deps = typeof cmpDef.dependencies === 'function' ? cmpDef.dependencies() : cmpDef.dependencies; for (const dep of deps) { walkProviderTree(dep, visitor, parents, dedup); } } } else if (injDef) { if (injDef.imports != null && !isDuplicate) { ngDevMode && parents.push(defType); dedup.add(defType); let importTypesWithProviders; try { deepForEach(injDef.imports, imported => { if (walkProviderTree(imported, visitor, parents, dedup)) { importTypesWithProviders ||= []; importTypesWithProviders.push(imported); } }); } finally { ngDevMode && parents.pop(); } if (importTypesWithProviders !== undefined) { processInjectorTypesWithProviders(importTypesWithProviders, visitor); } } if (!isDuplicate) { const factory = getFactoryDef(defType) || (() => new defType()); visitor({ provide: defType, useFactory: factory, deps: EMPTY_ARRAY }, defType); visitor({ provide: INJECTOR_DEF_TYPES, useValue: defType, multi: true }, defType); visitor({ provide: ENVIRONMENT_INITIALIZER, useValue: () => ɵɵinject(defType), multi: true }, defType); } const defProviders = injDef.providers; if (defProviders != null && !isDuplicate) { const injectorType = container; deepForEachProvider(defProviders, provider => { ngDevMode && validateProvider(provider, defProviders, injectorType); visitor(provider, injectorType); }); } } else { return false; } return defType !== container && container.providers !== undefined; } function validateProvider(provider, providers, containerType) { if (isTypeProvider(provider) || isValueProvider(provider) || isFactoryProvider(provider) || isExistingProvider(provider)) { return; } const classRef = resolveForwardRef(provider && (provider.useClass || provider.provide)); if (!classRef) { throwInvalidProviderError(containerType, providers, provider); } } function deepForEachProvider(providers, fn) { for (let provider of providers) { if (isEnvironmentProviders(provider)) { provider = provider.ɵproviders; } if (Array.isArray(provider)) { deepForEachProvider(provider, fn); } else { fn(provider); } } } const USE_VALUE = getClosureSafeProperty({ provide: String, useValue: getClosureSafeProperty }); function isValueProvider(value) { return value !== null && typeof value == 'object' && USE_VALUE in value; } function isExistingProvider(value) { return !!(value && value.useExisting); } function isFactoryProvider(value) { return !!(value && value.useFactory); } function isTypeProvider(value) { return typeof value === 'function'; } function isClassProvider(value) { return !!value.useClass; } const INJECTOR_SCOPE = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'Set Injector scope.' : ''); const NOT_YET = {}; const CIRCULAR = {}; let NULL_INJECTOR = undefined; function getNullInjector() { if (NULL_INJECTOR === undefined) { NULL_INJECTOR = new NullInjector(); } return NULL_INJECTOR; } class EnvironmentInjector {} class R3Injector extends EnvironmentInjector { parent; source; scopes; records = new Map(); _ngOnDestroyHooks = new Set(); _onDestroyHooks = []; get destroyed() { return this._destroyed; } _destroyed = false; injectorDefTypes; constructor(providers, parent, source, scopes) { super(); this.parent = parent; this.source = source; this.scopes = scopes; forEachSingleProvider(providers, provider => this.processProvider(provider)); this.records.set(INJECTOR$1, makeRecord(undefined, this)); if (scopes.has('environment')) { this.records.set(EnvironmentInjector, makeRecord(undefined, this)); } const record = this.records.get(INJECTOR_SCOPE); if (record != null && typeof record.value === 'string') { this.scopes.add(record.value); } this.injectorDefTypes = new Set(this.get(INJECTOR_DEF_TYPES, EMPTY_ARRAY, { self: true })); } retrieve(token, options) { const flags = convertToBitFlags(options) || 0; try { return this.get(token, THROW_IF_NOT_FOUND, flags); } catch (e) { if (isNotFound$1(e)) { return e; } throw e; } } destroy() { assertNotDestroyed(this); this._destroyed = true; const prevConsumer = setActiveConsumer(null); try { for (const service of this._ngOnDestroyHooks) { service.ngOnDestroy(); } const onDestroyHooks = this._onDestroyHooks; this._onDestroyHooks = []; for (const hook of onDestroyHooks) { hook(); } } finally { this.records.clear(); this._ngOnDestroyHooks.clear(); this.injectorDefTypes.clear(); setActiveConsumer(prevConsumer); } } onDestroy(callback) { assertNotDestroyed(this); this._onDestroyHooks.push(callback); return () => this.removeOnDestroy(callback); } runInContext(fn) { assertNotDestroyed(this); const previousInjector = setCurrentInjector(this); const previousInjectImplementation = setInjectImplementation(undefined); let prevInjectContext; if (ngDevMode) { prevInjectContext = setInjectorProfilerContext({ injector: this, token: null }); } try { return fn(); } finally { setCurrentInjector(previousInjector); setInjectImplementation(previousInjectImplementation); ngDevMode && setInjectorProfilerContext(prevInjectContext); } } get(token, notFoundValue = THROW_IF_NOT_FOUND, options) { assertNotDestroyed(this); if (token.hasOwnProperty(NG_ENV_ID)) { return token[NG_ENV_ID](this); } const flags = convertToBitFlags(options); let prevInjectContext; if (ngDevMode) { prevInjectContext = setInjectorProfilerContext({ injector: this, token: token }); } const previousInjector = setCurrentInjector(this); const previousInjectImplementation = setInjectImplementation(undefined); try { if (!(flags & 4)) { let record = this.records.get(token); if (record === undefined) { const def = couldBeInjectableType(token) && getInjectableDef(token); if (def && this.injectableDefInScope(def)) { if (ngDevMode) { runInInjectorProfilerContext(this, token, () => { emitProviderConfiguredEvent(token); }); } record = makeRecord(injectableDefOrInjectorDefFactory(token), NOT_YET); } else { record = null; } this.records.set(token, record); } if (record != null) { return this.hydrate(token, record, flags); } } const nextInjector = !(flags & 2) ? this.parent : getNullInjector(); notFoundValue = flags & 8 && notFoundValue === THROW_IF_NOT_FOUND ? null : notFoundValue; return nextInjector.get(token, notFoundValue); } catch (error) { const errorCode = getRuntimeErrorCode(error); if (errorCode === -200 || errorCode === -201) { if (ngDevMode) { prependTokenToDependencyPath(error, token); if (previousInjector) { throw error; } else { throw augmentRuntimeError(error, this.source); } } else { throw new RuntimeError(errorCode, null); } } else { throw error; } } finally { setInjectImplementation(previousInjectImplementation); setCurrentInjector(previousInjector); ngDevMode && setInjectorProfilerContext(prevInjectContext); } } resolveInjectorInitializers() { const prevConsumer = setActiveConsumer(null); const previousInjector = setCurrentInjector(this); const previousInjectImplementation = setInjectImplementation(undefined); let prevInjectContext; if (ngDevMode) { prevInjectContext = setInjectorProfilerContext({ injector: this, token: null }); } try { const initializers = this.get(ENVIRONMENT_INITIALIZER, EMPTY_ARRAY, { self: true }); if (ngDevMode && !Array.isArray(initializers)) { throw new RuntimeError(-209, 'Unexpected type of the `ENVIRONMENT_INITIALIZER` token value ' + `(expected an array, but got ${typeof initializers}). ` + 'Please check that the `ENVIRONMENT_INITIALIZER` token is configured as a ' + '`multi: true` provider.'); } for (const initializer of initializers) { initializer(); } } finally { setCurrentInjector(previousInjector); setInjectImplementation(previousInjectImplementation); ngDevMode && setInjectorProfilerContext(prevInjectContext); setActiveConsumer(prevConsumer); } } toString() { const tokens = []; const records = this.records; for (const token of records.keys()) { tokens.push(stringify(token)); } return `R3Injector[${tokens.join(', ')}]`; } processProvider(provider) { provider = resolveForwardRef(provider); let token = isTypeProvider(provider) ? provider : resolveForwardRef(provider && provider.provide); const record = providerToRecord(provider); if (ngDevMode) { runInInjectorProfilerContext(this, token, () => { if (isValueProvider(provider)) { emitInjectorToCreateInstanceEvent(token); emitInstanceCreatedByInjectorEvent(provider.useValue); } emitProviderConfiguredEvent(provider); }); } if (!isTypeProvider(provider) && provider.multi === true) { let multiRecord = this.records.get(token); if (multiRecord) { if (ngDevMode && multiRecord.multi === undefined) { throwMixedMultiProviderError(); } } else { multiRecord = makeRecord(undefined, NOT_YET, true); multiRecord.factory = () => injectArgs(multiRecord.multi); this.records.set(token, multiRecord); } token = provider; multiRecord.multi.push(provider); } else { if (ngDevMode) { const existing = this.records.get(token); if (existing && existing.multi !== undefined) { throwMixedMultiProviderError(); } } } this.records.set(token, record); } hydrate(token, record, flags) { const prevConsumer = setActiveConsumer(null); try { if (record.value === CIRCULAR) { throw cyclicDependencyError(stringify(token)); } else if (record.value === NOT_YET) { record.value = CIRCULAR; if (ngDevMode) { runInInjectorProfilerContext(this, token, () => { emitInjectorToCreateInstanceEvent(token); record.value = record.factory(undefined, flags); emitInstanceCreatedByInjectorEvent(record.value); }); } else { record.value = record.factory(undefined, flags); } } if (typeof record.value === 'object' && record.value && hasOnDestroy(record.value)) { this._ngOnDestroyHooks.add(record.value); } return record.value; } finally { setActiveConsumer(prevConsumer); } } injectableDefInScope(def) { if (!def.providedIn) { return false; } const providedIn = resolveForwardRef(def.providedIn); if (typeof providedIn === 'string') { return providedIn === 'any' || this.scopes.has(providedIn); } else { return this.injectorDefTypes.has(providedIn); } } removeOnDestroy(callback) { const destroyCBIdx = this._onDestroyHooks.indexOf(callback); if (destroyCBIdx !== -1) { this._onDestroyHooks.splice(destroyCBIdx, 1); } } } function injectableDefOrInjectorDefFactory(token) { const injectableDef = getInjectableDef(token); const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token); if (factory !== null) { return factory; } if (token instanceof InjectionToken) { throw new RuntimeError(204, ngDevMode && `Token ${stringify(token)} is missing a ɵprov definition.`); } if (token instanceof Function) { return getUndecoratedInjectableFactory(token); } throw new RuntimeError(204, ngDevMode && 'unreachable'); } function getUndecoratedInjectableFactory(token) { const paramLength = token.length; if (paramLength > 0) { throw new RuntimeError(204, ngDevMode && `Can't resolve all parameters for ${stringify(token)}: (${newArray(paramLength, '?').join(', ')}).`); } const inheritedInjectableDef = getInheritedInjectableDef(token); if (inheritedInjectableDef !== null) { return () => inheritedInjectableDef.factory(token); } else { return () => new token(); } } function providerToRecord(provider) { if (isValueProvider(provider)) { return makeRecord(undefined, provider.useValue); } else { const factory = providerToFactory(provider); return makeRecord(factory, NOT_YET); } } function providerToFactory(provider, ngModuleType, providers) { let factory = undefined; if (ngDevMode && isEnvironmentProviders(provider)) { throwInvalidProviderError(undefined, providers, provider); } if (isTypeProvider(provider)) { const unwrappedProvider = resolveForwardRef(provider); return getFactoryDef(unwrappedProvider) || injectableDefOrInjectorDefFactory(unwrappedProvider); } else { if (isValueProvider(provider)) { factory = () => resolveForwardRef(provider.useValue); } else if (isFactoryProvider(provider)) { factory = () => provider.useFactory(...injectArgs(provider.deps || [])); } else if (isExistingProvider(provider)) { factory = (_, flags) => ɵɵinject(resolveForwardRef(provider.useExisting), flags !== undefined && flags & 8 ? 8 : undefined); } else { const classRef = resolveForwardRef(provider && (provider.useClass || provider.provide)); if (ngDevMode && !classRef) { throwInvalidProviderError(ngModuleType, providers, provider); } if (hasDeps(provider)) { factory = () => new classRef(...injectArgs(provider.deps)); } else { return getFactoryDef(classRef) || injectableDefOrInjectorDefFactory(classRef); } } } return factory; } function assertNotDestroyed(injector) { if (injector.destroyed) { throw new RuntimeError(205, ngDevMode && 'Injector has already been destroyed.'); } } function makeRecord(factory, value, multi = false) { return { factory: factory, value: value, multi: multi ? [] : undefined }; } function hasDeps(value) { return !!value.deps; } function hasOnDestroy(value) { return value !== null && typeof value === 'object' && typeof value.ngOnDestroy === 'function'; } function couldBeInjectableType(value) { return typeof value === 'function' || typeof value === 'object' && value.ngMetadataName === 'InjectionToken'; } function forEachSingleProvider(providers, fn) { for (const provider of providers) { if (Array.isArray(provider)) { forEachSingleProvider(provider, fn); } else if (provider && isEnvironmentProviders(provider)) { forEachSingleProvider(provider.ɵproviders, fn); } else { fn(provider); } } } function runInInjectionContext(injector, fn) { let internalInjector; if (injector instanceof R3Injector) { assertNotDestroyed(injector); internalInjector = injector; } else { internalInjector = new RetrievingInjector(injector); } let prevInjectorProfilerContext; if (ngDevMode) { prevInjectorProfilerContext = setInjectorProfilerContext({ injector, token: null }); } const prevInjector = setCurrentInjector(internalInjector); const previousInjectImplementation = setInjectImplementation(undefined); try { return fn(); } finally { setCurrentInjector(prevInjector); ngDevMode && setInjectorProfilerContext(prevInjectorProfilerContext); setInjectImplementation(previousInjectImplementation); } } function isInInjectionContext() { return getInjectImplementation() !== undefined || getCurrentInjector() != null; } function assertInInjectionContext(debugFn) { if (!isInInjectionContext()) { throw new RuntimeError(-203, ngDevMode && debugFn.name + '() can only be used within an injection context such as a constructor, a factory function, a field initializer, or a function used with `runInInjectionContext`'); } } const HOST = 0; const TVIEW = 1; const FLAGS = 2; const PARENT = 3; const NEXT = 4; const T_HOST = 5; const HYDRATION = 6; const CLEANUP = 7; const CONTEXT = 8; const INJECTOR = 9; const ENVIRONMENT = 10; const RENDERER = 11; const CHILD_HEAD = 12; const CHILD_TAIL = 13; const DECLARATION_VIEW = 14; const DECLARATION_COMPONENT_VIEW = 15; const DECLARATION_LCONTAINER = 16; const PREORDER_HOOK_FLAGS = 17; const QUERIES = 18; const ID = 19; const EMBEDDED_VIEW_INJECTOR = 20; const ON_DESTROY_HOOKS = 21; const EFFECTS_TO_SCHEDULE = 22; const EFFECTS = 23; const REACTIVE_TEMPLATE_CONSUMER = 24; const AFTER_RENDER_SEQUENCES_TO_ADD = 25; const ANIMATIONS = 26; const HEADER_OFFSET = 27; const TYPE = 1; const DEHYDRATED_VIEWS = 6; const NATIVE = 7; const VIEW_REFS = 8; const MOVED_VIEWS = 9; const CONTAINER_HEADER_OFFSET = 10; function isLView(value) { return Array.isArray(value) && typeof value[TYPE] === 'object'; } function isLContainer(value) { return Array.isArray(value) && value[TYPE] === true; } function isContentQueryHost(tNode) { return (tNode.flags & 4) !== 0; } function isComponentHost(tNode) { return tNode.componentOffset > -1; } function isDirectiveHost(tNode) { return (tNode.flags & 1) === 1; } function isComponentDef(def) { return !!def.template; } function isRootView(target) { return (target[FLAGS] & 512) !== 0; } function isProjectionTNode(tNode) { return (tNode.type & 16) === 16; } function hasI18n(lView) { return (lView[FLAGS] & 32) === 32; } function isDestroyed(lView) { return (lView[FLAGS] & 256) === 256; } function assertTNodeForLView(tNode, lView) { assertTNodeForTView(tNode, lView[TVIEW]); } function assertTNodeCreationIndex(lView, index) { const adjustedIndex = index + HEADER_OFFSET; assertIndexInRange(lView, adjustedIndex); assertLessThan(adjustedIndex, lView[TVIEW].bindingStartIndex, 'TNodes should be created before any bindings'); } function assertTNodeForTView(tNode, tView) { assertTNode(tNode); const tData = tView.data; for (let i = HEADER_OFFSET; i < tData.length; i++) { if (tData[i] === tNode) { return; } } throwError('This TNode does not belong to this TView.'); } function assertTNode(tNode) { assertDefined(tNode, 'TNode must be defined'); if (!(tNode && typeof tNode === 'object' && tNode.hasOwnProperty('directiveStylingLast'))) { throwError('Not of type TNode, got: ' + tNode); } } function assertTIcu(tIcu) { assertDefined(tIcu, 'Expected TIcu to be defined'); if (!(typeof tIcu.currentCaseLViewIndex === 'number')) { throwError('Object is not of TIcu type.'); } } function assertComponentType(actual, msg = "Type passed in is not ComponentType, it does not have 'ɵcmp' property.") { if (!getComponentDef