@angular/cdk
Version:
Angular Material Component Development Kit
1 lines • 3.39 kB
Source Map (JSON)
{"version":3,"file":"_style-loader-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/cdk/private/style-loader.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {\n ApplicationRef,\n ComponentRef,\n createComponent,\n EnvironmentInjector,\n inject,\n Service,\n Injector,\n Type,\n} from '@angular/core';\n\n/** Apps in which we've loaded styles. */\nconst appsWithLoaders = new WeakMap<\n ApplicationRef,\n {\n /** Style loaders that have been added. */\n loaders: Set<Type<unknown>>;\n\n /** References to the instantiated loaders. */\n refs: ComponentRef<unknown>[];\n }\n>();\n\n/**\n * Service that loads structural styles dynamically\n * and ensures that they're only loaded once per app.\n */\n@Service()\nexport class _CdkPrivateStyleLoader {\n private _appRef: ApplicationRef | undefined;\n private _injector = inject(Injector);\n private _environmentInjector = inject(EnvironmentInjector);\n\n /**\n * Loads a set of styles.\n * @param loader Component which will be instantiated to load the styles.\n */\n load(loader: Type<unknown>): void {\n // Resolve the app ref lazily to avoid circular dependency errors if this is called too early.\n const appRef = (this._appRef = this._appRef || this._injector.get(ApplicationRef));\n let data = appsWithLoaders.get(appRef);\n\n // If we haven't loaded for this app before, we have to initialize it.\n if (!data) {\n data = {loaders: new Set(), refs: []};\n appsWithLoaders.set(appRef, data);\n\n // When the app is destroyed, we need to clean up all the related loaders.\n appRef.onDestroy(() => {\n appsWithLoaders.get(appRef)?.refs.forEach(ref => ref.destroy());\n appsWithLoaders.delete(appRef);\n });\n }\n\n // If the loader hasn't been loaded before, we need to instatiate it.\n if (!data.loaders.has(loader)) {\n data.loaders.add(loader);\n data.refs.push(createComponent(loader, {environmentInjector: this._environmentInjector}));\n }\n }\n}\n"],"names":[],"mappings":";;;AAoBA,MAAM,eAAe,GAAG,IAAI,OAAO,EASh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