{"version":3,"file":"davidlj95-ngx-meta-routing.mjs","sources":["../../src/routing/src/route-metadata/default-route-metadata-strategy.ts","../../src/routing/src/module-name.ts","../../src/routing/src/listener/router-listener.ts","../../src/routing/src/providers/provide-ngx-meta-routing.ts","../../src/routing/src/providers/ngx-meta-routing.module.ts","../../src/routing/davidlj95-ngx-meta-routing.ts"],"sourcesContent":["import { FactoryProvider } from '@angular/core'\nimport { ActivatedRoute, ActivatedRouteSnapshot } from '@angular/router'\nimport { _routeMetadataStrategy } from '@davidlj95/ngx-meta/core'\nimport { NgxMetaRouteData } from './ngx-meta-route-data'\n\nexport const DEFAULT_ROUTE_METADATA_STRATEGY_PROVIDER: FactoryProvider = {\n  provide: _routeMetadataStrategy(),\n  useFactory: (activatedRoute: ActivatedRoute) => () => {\n    let currentRouteSnapshot: ActivatedRouteSnapshot = activatedRoute.snapshot\n    while (currentRouteSnapshot.firstChild != null) {\n      currentRouteSnapshot = currentRouteSnapshot.firstChild\n    }\n    return currentRouteSnapshot.data['meta' satisfies keyof NgxMetaRouteData]\n  },\n  deps: [ActivatedRoute],\n}\n","export const MODULE_NAME = 'routing'\n","import { inject, OnDestroy } from '@angular/core'\nimport { NavigationEnd, Router } from '@angular/router'\nimport { filter, Subscription } from 'rxjs'\nimport {\n  _formatDevMessage,\n  _makeInjectionToken,\n  NgxMetaService,\n} from '@davidlj95/ngx-meta/core'\nimport { MODULE_NAME } from '../module-name'\n\n// WTF is this? Why not just import `EventType`? Well, compatibility reasons 🙃\n// See https://github.com/davidlj95/ngx/pull/246 for the details\nconst NAVIGATION_END_EVENT_TYPE = new NavigationEnd(0, '', '').type\n\nexport const routerListener = () =>\n  _makeInjectionToken(ngDevMode ? 'Router listener' : 'RL', () => {\n    const router = inject(Router)\n    const ngxMetaService = inject(NgxMetaService)\n    let subscription: Subscription | undefined\n    return {\n      listen() {\n        /* istanbul ignore next https://github.com/istanbuljs/istanbuljs/issues/719 */\n        if (ngDevMode && subscription) {\n          console.warn(\n            _formatDevMessage(\n              [\n                'prevented listening for route changes twice',\n                'Ensure routing provider or module is only imported once',\n              ].join('\\n'),\n              { module: MODULE_NAME },\n            ),\n          )\n        }\n        /* istanbul ignore next https://github.com/istanbuljs/istanbuljs/issues/719 */\n        if (subscription) {\n          return\n        }\n        subscription = router.events\n          .pipe(filter(({ type }) => type === NAVIGATION_END_EVENT_TYPE))\n          .subscribe({\n            next: () => ngxMetaService.set(),\n          })\n      },\n      // Can't use DestroyRef is introduced in Angular v16\n      // https://github.com/angular/angular/pull/49158\n      // It uses EnvironmentInjector's internal `onDestroy` under the hood\n      // Tried that too, but it's @internal + raises some errors. So back to the `ngOnDestroy`\n      ngOnDestroy: () => subscription?.unsubscribe(),\n    }\n  })\n\n/** @visibleForTesting */\nexport type RouterListener = { listen: () => void } & OnDestroy\n","import {\n  ENVIRONMENT_INITIALIZER,\n  EnvironmentProviders,\n  inject,\n  makeEnvironmentProviders,\n} from '@angular/core'\nimport { DEFAULT_ROUTE_METADATA_STRATEGY_PROVIDER } from '../route-metadata/default-route-metadata-strategy'\nimport { routerListener } from '../listener/router-listener'\n\n/**\n * Enables managing metadata of a page by specifying it in its Angular\n * {@link https://angular.dev/api/router/Route#data | Route#data}\n *\n * @remarks\n *\n * This is the standalone, recommended API. Using this API is preferred.\n * However, you may also use {@link NgxMetaRoutingModule.(forRoot:1)} as the Angular module-based equivalent API.\n *\n * @public\n */\nexport const provideNgxMetaRouting = (): EnvironmentProviders =>\n  makeEnvironmentProviders([\n    DEFAULT_ROUTE_METADATA_STRATEGY_PROVIDER,\n    {\n      provide: ENVIRONMENT_INITIALIZER,\n      multi: true,\n      useFactory: () => inject(routerListener()).listen,\n    },\n  ])\n","import { ModuleWithProviders, NgModule } from '@angular/core'\nimport { provideNgxMetaRouting } from './provide-ngx-meta-routing'\n\n/**\n * Enables managing metadata of a page by specifying it in its Angular\n * {@link https://angular.dev/api/router/Route#data | Route#data}\n *\n * Use {@link NgxMetaRoutingModule.forRoot} method. Importing the module class alone does nothing.\n *\n * Check out {@link provideNgxMetaRouting} for the standalone, recommended API.\n *\n * @public\n */\n@NgModule()\nexport class NgxMetaRoutingModule {\n  /**\n   * {@inheritDoc NgxMetaRoutingModule}\n   */\n  static forRoot(): ModuleWithProviders<NgxMetaRoutingModule> {\n    /* istanbul ignore next - simple enough */\n    return {\n      ngModule: NgxMetaRoutingModule,\n      providers: [provideNgxMetaRouting()],\n    }\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAKO,MAAM,wCAAwC,GAAoB;IACvE,OAAO,EAAE,sBAAsB,EAAE;AACjC,IAAA,UAAU,EAAE,CAAC,cAA8B,KAAK,MAAK;AACnD,QAAA,IAAI,oBAAoB,GAA2B,cAAc,CAAC,QAAQ,CAAA;AAC1E,QAAA,OAAO,oBAAoB,CAAC,UAAU,IAAI,IAAI,EAAE;AAC9C,YAAA,oBAAoB,GAAG,oBAAoB,CAAC,UAAU,CAAA;SACvD;AACD,QAAA,OAAO,oBAAoB,CAAC,IAAI,CAAC,MAAuC,CAAC,CAAA;KAC1E;IACD,IAAI,EAAE,CAAC,cAAc,CAAC;CACvB;;ACfM,MAAM,WAAW,GAAG,SAAS;;ACUpC;AACA;AACA,MAAM,yBAAyB,GAAG,IAAI,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAA;AAE5D,MAAM,cAAc,GAAG,MAC5B,mBAAmB,CAAC,SAAS,GAAG,iBAAiB,GAAG,IAAI,EAAE,MAAK;AAC7D,IAAA,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;AAC7B,IAAA,MAAM,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;AAC7C,IAAA,IAAI,YAAsC,CAAA;IAC1C,OAAO;QACL,MAAM,GAAA;;AAEJ,YAAA,IAAI,SAAS,IAAI,YAAY,EAAE;AAC7B,gBAAA,OAAO,CAAC,IAAI,CACV,iBAA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