{"version":3,"file":"bootkit-ng1-routing.mjs","sources":["../../../projects/ng1/routing/router.service.ts","../../../projects/ng1/routing/public-api.ts","../../../projects/ng1/routing/bootkit-ng1-routing.ts"],"sourcesContent":["import { inject, Injectable } from '@angular/core';\nimport { ActivatedRouteSnapshot, NavigationEnd, Router } from '@angular/router';\nimport { filter, map, Observable } from 'rxjs';\nimport { RouteData, RouterLinkValueResolver, RouterActivatedRouteSnapshot, RouteTitleResolver } from './types';\n\n/**\n * Service to interact with Angular Router.\n */\n@Injectable({ providedIn: 'root' })\nexport class RouterService {\n  private readonly _router = inject(Router);\n\n  /**\n   * Listen to activated route tree changes for specified outlets.\n   * This will emit the activated route tree whenever a navigation ends and the activated routes change.\n   * The emitted value is a tree structure representing the activated routes for the specified outlets.\n   * @param outlets List of outlets to include, default is ['primary']\n   * @returns Observable of the activated route tree\n   */\n  public listenToActivatedRouteTree(outlets: string[] = ['primary']): Observable<RouterActivatedRouteSnapshot> {\n    return this._router.events.pipe(\n      filter(x => x instanceof NavigationEnd),\n      map(e => {\n        let { root } = this._router.routerState.snapshot;\n        return this._mapRoute(root, outlets);\n      })\n    );\n  }\n\n  /**\n   * Listen to activated routes changes for a specific outlet.\n   * This will emit an array of activated routes from root to the last one for the specified outlet whenever a navigation ends and the activated routes change.\n   * @param outlet The outlet to listen for, default is 'primary'\n   * @returns Observable of the activated routes array from root to the last one for the specified outlet\n   */\n  public listenToActivatedRoutes(outlet = 'primary'): Observable<RouterActivatedRouteSnapshot[]> {\n    return this.listenToActivatedRouteTree([outlet]).pipe(\n      map(root => {\n        let result: RouterActivatedRouteSnapshot[] = [];\n        \n        do {\n          result.push(root);\n          root = root?.children[0];\n        } while (root !== undefined);\n\n        return result;\n      })\n    );\n  }\n\n  /**\n   * Get the current activated routes for a specific outlet.\n   * This will return an array of activated routes from root to the last one for the specified outlet based on the current router state snapshot.\n   * @param outlet The outlet to get activated routes for, default is 'primary'\n   * @returns Array of activated routes from root to the last one for the specified outlet\n   */\n  getActivatedRoutes(outlet = 'primary'): RouterActivatedRouteSnapshot[] {\n    let result: RouterActivatedRouteSnapshot[] = [];\n    let route = this._router.routerState.snapshot.root;\n\n    while (route) {\n      if (route.outlet === outlet) {\n        result.push(this._mapRoute(route, [outlet]));\n      }\n      route = route.children[0];\n    }\n\n    return result;\n  }\n\n  /**\n   * Map a route to RouterRouteSnapshot\n   * @param route The route to map\n   * @param outlets The outlets to include\n   * @returns The mapped RouterRouteSnapshot\n   */\n  private _mapRoute(route: ActivatedRouteSnapshot, outlets: string[]): RouterActivatedRouteSnapshot {\n    let configData = route.routeConfig?.data as RouteData | undefined;\n    let title: string | undefined;\n    \n    if(route.title && route.routeConfig?.title)\n      // Route is resolved by Angular.\n      title = route.title;\n    else if (configData?.title) {\n      title = typeof configData.title === 'function' ?\n       (configData.title as RouteTitleResolver)(route, this._router.routerState.snapshot) :\n       configData.title;\n    }\n\n    let link = configData?.link;\n    if (typeof link === 'function') {\n      link = (link as RouterLinkValueResolver)(route, this._router.routerState.snapshot);\n    }\n\n    return {\n      activatedRoute: route,\n      title,\n      description: configData?.description,\n      metaTags: configData?.metaTags,\n      link: link,\n      children: route.children\n        .filter(x => outlets.includes(x.outlet))\n        .map(x => this._mapRoute(x, outlets))\n    } as RouterActivatedRouteSnapshot;\n  }\n\n\n}","export  *  from './router.service';\nexport  *  from './types';\n// export  *  from './meta.service';","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAKA;;AAEG;MAEU,aAAa,CAAA;AACP,IAAA,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;AAEzC;;;;;;AAMG;AACI,IAAA,0BAA0B,CAAC,OAAA,GAAoB,CAAC,SAAS,CAAC,EAAA;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAC7B,MAAM,CAAC,CAAC,IAAI,CAAC,YAAY,aAAa,CAAC,EACvC,GAAG,CAAC,CAAC,IAAG;YACN,IAAI,EAAE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