@angular/cdk
Version:
Angular Material Component Development Kit
1 lines • 3.65 kB
Source Map (JSON)
{"version":3,"file":"style-loader-09eecacc.mjs","sources":["../../../../../k8-fastbuild-ST-46c76129e412/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 Injectable,\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@Injectable({providedIn: 'root'})\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":";;;AAmBA;AACA,MAAM,eAAe,GAAG,IA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