style-loader-Cu9AvjH9.mjs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import * as i0 from '@angular/core';
  2. import { inject, Injector, EnvironmentInjector, ApplicationRef, createComponent, Injectable } from '@angular/core';
  3. /** Apps in which we've loaded styles. */
  4. const appsWithLoaders = new WeakMap();
  5. /**
  6. * Service that loads structural styles dynamically
  7. * and ensures that they're only loaded once per app.
  8. */
  9. class _CdkPrivateStyleLoader {
  10. _appRef;
  11. _injector = inject(Injector);
  12. _environmentInjector = inject(EnvironmentInjector);
  13. /**
  14. * Loads a set of styles.
  15. * @param loader Component which will be instantiated to load the styles.
  16. */
  17. load(loader) {
  18. // Resolve the app ref lazily to avoid circular dependency errors if this is called too early.
  19. const appRef = (this._appRef = this._appRef || this._injector.get(ApplicationRef));
  20. let data = appsWithLoaders.get(appRef);
  21. // If we haven't loaded for this app before, we have to initialize it.
  22. if (!data) {
  23. data = { loaders: new Set(), refs: [] };
  24. appsWithLoaders.set(appRef, data);
  25. // When the app is destroyed, we need to clean up all the related loaders.
  26. appRef.onDestroy(() => {
  27. appsWithLoaders.get(appRef)?.refs.forEach(ref => ref.destroy());
  28. appsWithLoaders.delete(appRef);
  29. });
  30. }
  31. // If the loader hasn't been loaded before, we need to instatiate it.
  32. if (!data.loaders.has(loader)) {
  33. data.loaders.add(loader);
  34. data.refs.push(createComponent(loader, { environmentInjector: this._environmentInjector }));
  35. }
  36. }
  37. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: _CdkPrivateStyleLoader, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  38. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: _CdkPrivateStyleLoader, providedIn: 'root' });
  39. }
  40. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: _CdkPrivateStyleLoader, decorators: [{
  41. type: Injectable,
  42. args: [{ providedIn: 'root' }]
  43. }] });
  44. export { _CdkPrivateStyleLoader as _ };
  45. //# sourceMappingURL=style-loader-Cu9AvjH9.mjs.map