{"version":3,"file":"odx-angular-breakpoints.mjs","sources":["../../../../libs/angular/breakpoints/src/lib/helpers/configure-breakpoint.ts","../../../../libs/angular/breakpoints/src/lib/breakpoints.config.ts","../../../../libs/angular/breakpoints/src/lib/breakpoints.service.ts","../../../../libs/angular/breakpoints/src/lib/directives/match-breakpoints.directive.ts","../../../../libs/angular/breakpoints/src/lib/breakpoints.module.ts","../../../../libs/angular/breakpoints/src/odx-angular-breakpoints.ts"],"sourcesContent":["type BreakpointOperators = '<' | '=' | '>';\ntype BreakpointConfig<T extends string> = Record<`${BreakpointOperators}${T}`, string>;\n\n/**\n * Generates a configuration object containing CSS media query strings for a named breakpoint.\n * The function creates media queries for three scenarios: below (`<`), exactly (`=`), and above (`>`) the specified breakpoint.\n *\n * @template T - The string literal type representing the name of the breakpoint.\n * @param {T} name - The name of the breakpoint (e.g., 'md' for medium).\n * @param {number} min - The minimum width (inclusive) where the breakpoint starts.\n * @param {number} max - The maximum width (exclusive) where the breakpoint ends.\n * @returns {BreakpointConfig<T>} An object containing media query strings for targeting screen sizes relative to the breakpoint.\n *\n * @example\n * ```ts\n * // Define a medium (md) breakpoint\n * const mdBreakpoint = configureBreakpoint('md', 768, 1024);\n * console.log(mdBreakpoint['<md']); // Outputs: \"(max-width: 767px)\"\n * console.log(mdBreakpoint['=md']); // Outputs: \"(min-width: 768px) and (max-width: 1023px)\"\n * console.log(mdBreakpoint['>md']); // Outputs: \"(min-width: 768px)\"\n * ```\n */\nexport function configureBreakpoint<T extends string>(name: T, min: number, max: number): BreakpointConfig<T> {\n  return {\n    [`<${name}` as const]: `(max-width: ${min - 1}px)`,\n    [`=${name}` as const]: `(min-width: ${min}px) and (max-width: ${max - 1}px)`,\n    [`>${name}` as const]: `(min-width: ${min}px)`,\n  } as BreakpointConfig<T>;\n}\n","import { createConfigTokens } from '@odx/angular/utils';\nimport { configureBreakpoint } from './helpers/configure-breakpoint';\n\n/**\n * Defines default responsive breakpoints for the application. These breakpoints are used to\n * apply responsive styles and behaviors across various device sizes. Each breakpoint is\n * configured with a name, a minimum width, and a maximum width, defining the range of device\n * sizes it targets.\n *\n * @constant\n * @type {Record<string, string>}\n *\n * @example\n * ```ts\n * // Accessing a breakpoint value\n * console.log(DEFAULT_BREAKPOINTS['=phone']); // Outputs: \"(min-width: 480px) and (max-width: 767px)\"\n * ```\n */\nexport const DEFAULT_BREAKPOINTS = {\n  ...configureBreakpoint('phone-s', 360, 480),\n  ...configureBreakpoint('phone', 480, 768),\n  ...configureBreakpoint('tablet', 768, 960),\n  ...configureBreakpoint('desktop-s', 960, 1200),\n  ...configureBreakpoint('desktop', 1200, 9999),\n} as const;\n\nexport interface BreakpointsConfig {\n  breakpoints: Partial<OdxAngular.Breakpoints>;\n}\n\n/**\n * Provides Angular dependency injection tokens for accessing and configuring breakpoints\n * within the application. This enables a type-safe and modular way to manage responsive\n * design breakpoints across the app.\n *\n * @example\n * ```ts\n * // Providing custom breakpoints in an Angular module\n * import { NgModule } from '@angular/core';\n * import { provideBreakpointsConfig } from '@odx/angular/breakpoints';\n *\n * @NgModule({\n *   providers: [\n *     provideBreakpointsConfig({\n *       breakpoints: {\n *         ...configureBreakpoint('custom-tablet', 640, 1024),\n *       },\n *     }),\n *   ],\n * })\n * export class CustomModule {}\n * ```\n */\nexport const { BreakpointsConfig, BreakpointsDefaultConfig, injectBreakpointsConfig, provideBreakpointsConfig } = createConfigTokens(\n  'Breakpoints',\n  '@odx/angular/breakpoints',\n  {\n    breakpoints: DEFAULT_BREAKPOINTS,\n  } as BreakpointsConfig,\n);\n","import { BreakpointObserver } from '@angular/cdk/layout';\nimport { inject, Injectable } from '@angular/core';\nimport { distinctUntilChanged, map, Observable, of, shareReplay } from 'rxjs';\nimport { injectBreakpointsConfig } from './breakpoints.config';\nimport { BreakpointName } from './models';\n\n/**\n * Service to observe and react to changes in viewport size based on predefined breakpoints.\n * Utilizes Angular CDK's BreakpointObserver for listening to media query changes and integrates\n * it with the application's custom breakpoints configuration.\n *\n * @Injectable({ providedIn: 'root' })\n */\n@Injectable({ providedIn: 'root' })\nexport class BreakpointsService {\n  private readonly breakpointObserver = inject(BreakpointObserver);\n  private readonly config = injectBreakpointsConfig();\n\n  /**\n   * Observes the specified breakpoints and returns an Observable that emits true if any\n   * of the specified breakpoints match the current viewport size, and false otherwise.\n   *\n   * @param {BreakpointName[]} breakpoints - An array of breakpoints to observe.\n   * @returns {Observable<boolean>} - An Observable that emits true if the viewport matches the specified breakpoints.\n   *\n   * @example\n   * ```ts\n   * // Component that uses BreakpointsService to apply dynamic styles based on breakpoints\n   * @Component({\n   *   selector: 'app-responsive-component',\n   *   templateUrl: './responsive-component.component.html',\n   * })\n   * export class ResponsiveComponent {\n   *   isMobile$: Observable<boolean>;\n   *\n   *   constructor(private breakpointsService: BreakpointsService) {\n   *     this.isMobile$ = this.breakpointsService.observe(['phone', 'tablet']);\n   *   }\n   * }\n   * ```\n   */\n  public observe(breakpoints: BreakpointName[]): Observable<boolean> {\n    const mediaQueries = this.getMediaQueries(breakpoints);\n\n    return this.createBreakpointObserver(mediaQueries);\n  }\n\n  /**\n   * Checks if any of the specified breakpoints match the current viewport size.\n   *\n   * @param {BreakpointName[]} breakpoints - An array of breakpoints to check.\n   * @returns {boolean} - Returns true if the viewport matches the specified breakpoints, false otherwise.\n   *\n   * @example\n   * ```ts\n   * // Checking if the current viewport matches the 'desktop' breakpoint\n   * const isDesktop = this.breakpointsService.matches(['desktop']);\n   * console.log(`Is desktop view? ${isDesktop}`);\n   * ```\n   */\n  public matches(breakpoints: BreakpointName[]): boolean {\n    const mediaQueries = this.getMediaQueries(breakpoints);\n\n    return this.breakpointObserver.isMatched(mediaQueries);\n  }\n\n  private getMediaQueries(breakpointNames: BreakpointName[]): string[] {\n    return breakpointNames.map((name) => this.config.breakpoints[name] as string).filter(Boolean);\n  }\n\n  private createBreakpointObserver(mediaQueries: string[]): Observable<boolean> {\n    if (mediaQueries.length < 1) return of(false);\n\n    return this.breakpointObserver.observe(mediaQueries).pipe(\n      map(({ matches }) => matches),\n      distinctUntilChanged(),\n      shareReplay({ bufferSize: 1, refCount: true }),\n    );\n  }\n}\n","import { Directive, inject, Input, OnInit, TemplateRef, ViewContainerRef } from '@angular/core';\nimport { coerceArray, untilDestroyed } from '@odx/angular/utils';\nimport { BehaviorSubject, switchMap, tap } from 'rxjs';\nimport { BreakpointsService } from '../breakpoints.service';\nimport { BreakpointName } from '../models';\n\n/**\n * A structural directive that conditionally includes an Angular template based on whether the viewport matches\n * specified breakpoints. It leverages the BreakpointsService to observe changes in viewport size and apply\n * the appropriate template.\n *\n * @Directive\n * @param {BreakpointsService} breakpointsService - Injects BreakpointsService to observe breakpoint changes.\n * @param {TemplateRef} template - Injects the Angular template to render when breakpoints match.\n * @param {ViewContainerRef} viewContainer - Injects the container where the template will be rendered.\n *\n * @example\n * ```html\n * // Usage in a component template to conditionally display content based on breakpoints\n * // Assume 'mobile' and 'tablet' are defined breakpoints\n * <ng-template [odxMatchBreakpoints]=\"['mobile', 'tablet']\">\n *   Content to display on mobile and tablet sizes.\n * </ng-template>\n * <ng-template [odxMatchBreakpoints]=\"['desktop']\" [odxMatchBreakpointsElse]=\"elseTemplate\">\n *   Content to display on desktop size.\n * </ng-template>\n * <ng-template #elseTemplate>\n *   Content to display when not on desktop size.\n * </ng-template>\n * ```\n */\n@Directive({\n  standalone: true,\n  selector: 'ng-template[odxMatchBreakpoints]',\n})\nexport class MatchBreakpointsDirective implements OnInit {\n  private readonly breakpoints$$ = new BehaviorSubject<BreakpointName[]>([]);\n  private readonly breakpointsService = inject(BreakpointsService);\n  private readonly takeUntilDestroyed = untilDestroyed();\n  private readonly template = inject(TemplateRef);\n  private readonly viewContainer = inject(ViewContainerRef);\n\n  /**\n   * Sets the breakpoints to observe. The directive's content is displayed if the current viewport matches\n   * any of the specified breakpoints.\n   *\n   * @param {BreakpointName | BreakpointName[]} value - The breakpoint(s) to match against the current viewport size.\n   */\n  @Input('odxMatchBreakpoints')\n  public set breakpoints(value: BreakpointName | BreakpointName[] | null | undefined) {\n    this.breakpoints$$.next(coerceArray(value ?? []));\n  }\n\n  /**\n   * Optionally specifies a template to render when the viewport does not match the specified breakpoints.\n   *\n   * @param {TemplateRef<unknown>} elseTemplate - The template to render when the viewport does not match the breakpoints.\n   */\n  // eslint-disable-next-line @angular-eslint/no-input-rename\n  @Input('odxMatchBreakpointsElse')\n  public elseTemplate?: TemplateRef<unknown> | null = null;\n\n  public ngOnInit(): void {\n    this.breakpoints$$\n      .pipe(\n        switchMap((breakpoints) => this.breakpointsService.observe(breakpoints)),\n        tap((matchesBreakpoints) => this.render(matchesBreakpoints)),\n        this.takeUntilDestroyed(),\n      )\n      .subscribe();\n  }\n\n  private render(matchesBreakpoints: boolean): void {\n    this.viewContainer.clear();\n    const template = matchesBreakpoints ? this.template : this.elseTemplate;\n    if (template) {\n      const viewRef = this.viewContainer.createEmbeddedView(template);\n      viewRef.markForCheck();\n    }\n  }\n}\n","import { NgModule } from '@angular/core';\nimport { MatchBreakpointsDirective } from './directives';\n\nconst modules = [MatchBreakpointsDirective];\n\n@NgModule({\n  imports: modules,\n  exports: modules,\n})\nexport class BreakpointsModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAGA;;;;;;;;;;;;;;;;;;AAkBG;SACa,mBAAmB,CAAmB,IAAO,EAAE,GAAW,EAAE,GAAW,EAAA;IACrF,OAAO;QACL,CAAC,CAAA,CAAA,EAAI,IAAI,CAAA,CAAW,GAAG,CAAA,YAAA,EAAe,GAAG,GAAG,CAAC,CAAA,GAAA,CAAK;QAClD,CAAC,CAAA,CAAA,EAAI,IAAI,CAAA,CAAW,GAAG,CAAA,YAAA,EAAe,GAAG,CAAA,oBAAA,EAAuB,GAAG,GAAG,CAAC,CAAA,GAAA,CAAK;AAC5E,QAAA,CAAC,IAAI,IAAI,CAAA,CAAW,GAAG,CAAA,YAAA,EAAe,GAAG,CAAA,GAAA,CAAK;KACxB;AAC1B;;ACzBA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