{"version":3,"file":"chunk-dcap9to1.js","sources":["packages/sports/libs/common/ui/overflow/src/lib/when-overflowed.directive.ts","packages/sports/web/app/src/event-details/event-switcher/services/switcher-toggle.service.ts"],"sourcesContent":["import { ChangeDetectorRef, DestroyRef, Directive, ElementRef, HostBinding, Input, OnInit, Renderer2, inject } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\n\nimport { MutationObserverService, ResizeObserverService } from '@frontend/sports/common/core/utils/dom';\nimport { WINDOW } from '@frontend/vanilla/core';\nimport { distinctUntilChanged, filter, map } from 'rxjs';\n\nexport interface WhenOverflowedOptions {\n classNameToAdd?: string;\n resizeFont?: boolean;\n minFontSize?: number;\n listenToResize?: boolean;\n manualMutationCheck?: boolean;\n adjustRatio?: number;\n}\n\n@Directive({\n selector: '[msWhenOverflowed]',\n standalone: true,\n})\nexport class WhenOverflowedDirective implements OnInit {\n @Input('msWhenOverflowed') options: WhenOverflowedOptions = {};\n\n @HostBinding('style.font-size.px') fontSize?: number;\n\n private defaultFont = 0;\n private readonly destroyRef = inject(DestroyRef);\n private readonly _window = inject(WINDOW);\n\n constructor(\n private elementRef: ElementRef,\n private renderer: Renderer2,\n private mutationObserver: MutationObserverService,\n private resizeObserver: ResizeObserverService,\n private changeDetectionRef: ChangeDetectorRef,\n ) {}\n\n ngOnInit(): void {\n if (!this.options.manualMutationCheck && (this.options.classNameToAdd || this.options.resizeFont)) {\n this.initMutationObserver();\n }\n\n if (this.options.listenToResize) {\n this.initResizeObserver();\n }\n }\n\n private get element(): HTMLElement {\n return this.elementRef.nativeElement;\n }\n\n forceRefresh(): void {\n this.recalculate();\n }\n\n private initResizeObserver(): void {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n this.resizeObserver\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n .observe(this.elementRef)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n .pipe(\n map((entry: ResizeObserverEntry) => Math.round(entry.contentRect.width)),\n filter((w) => w > 0),\n distinctUntilChanged(),\n takeUntilDestroyed(this.destroyRef),\n )\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n .subscribe(() => this.recalculate());\n }\n\n private initMutationObserver(): void {\n const options = {\n characterData: true,\n childList: true,\n subtree: true,\n };\n\n this.mutationObserver\n .observe(this.element, options)\n .pipe(takeUntilDestroyed(this.destroyRef))\n .subscribe(() => this.recalculate());\n }\n\n private recalculate(): void {\n this.renderer.removeClass(this.element, this.options.classNameToAdd ?? '');\n this.fontSize = undefined;\n this.changeDetectionRef.detectChanges();\n\n if (this.options.resizeFont && !this.defaultFont) {\n const style = this._window.getComputedStyle(this.element);\n this.defaultFont = parseFloat(style.fontSize);\n }\n\n if (this.overflowRatio < 1) {\n if (this.options.resizeFont && this.options.minFontSize) {\n const newFont = +Math.max(\n this.options.minFontSize,\n Math.min(this.defaultFont, this.defaultFont * this.overflowRatio * (this.options.adjustRatio ?? 1)),\n ).toFixed(2);\n this.fontSize = newFont;\n }\n\n this.renderer.addClass(this.element, this.options.classNameToAdd ?? '');\n this.changeDetectionRef.detectChanges();\n }\n }\n\n private get overflowRatio(): number {\n return this.element.offsetWidth / this.element.scrollWidth;\n }\n}\n","import { Type, inject } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\n\nimport { ModalDialogOptions, ModalDialogService, ModalRef } from '@frontend/sports/modal/feature';\nimport { HtmlNode, WINDOW } from '@frontend/vanilla/core';\nimport { BehaviorSubject, Observable, filter, fromEvent, skip, switchMap, takeUntil } from 'rxjs';\n\nexport abstract class SwitcherToggleService {\n private dialogRef?: ModalRef;\n private visible$ = new BehaviorSubject(false);\n private readonly _window = inject(WINDOW);\n private readonly switcherEnabled: boolean;\n\n constructor(\n private dialogService: ModalDialogService,\n private htmlNode: HtmlNode,\n isSwitcherEnabled: boolean,\n ) {\n this.switcherEnabled = isSwitcherEnabled;\n\n const show$ = this.visible$.pipe(filter((v) => v));\n const hide$ = this.visible$.pipe(filter((v) => !v));\n show$\n .pipe(\n switchMap(() => fromEvent(this._window, 'click').pipe(skip(1), takeUntil(hide$))),\n takeUntilDestroyed(),\n )\n .subscribe(() => this.close());\n }\n\n get expanded$(): Observable {\n return this.visible$.asObservable();\n }\n\n get expanded(): boolean {\n return this.visible$.getValue();\n }\n\n protected open(component: Type, options: ModalDialogOptions | void>): void {\n if (!this.switcherEnabled) {\n return;\n }\n this.toggleHtmlClasses(true);\n this.dialogRef = this.dialogService.openDialog(component, options);\n this.visible$.next(true);\n }\n\n close(): void {\n if (!this.expanded) {\n return;\n }\n this.toggleHtmlClasses(false);\n this.dialogRef?.close();\n this.dialogRef = undefined;\n this.visible$.next(false);\n }\n\n closeSwitcher(): void {\n this.close();\n }\n\n getHtmlToggleClass(): string {\n return 'event-switcher-visible';\n }\n\n private toggleHtmlClasses(visible: boolean): void {\n this.htmlNode.setCssClass(this.getHtmlToggleClass(), visible);\n }\n}\n"],"names":["WhenOverflowedDirective","constructor","elementRef","renderer","mutationObserver","resizeObserver","changeDetectionRef","options","defaultFont","destroyRef","inject","DestroyRef","_window","WINDOW","ngOnInit","manualMutationCheck","classNameToAdd","resizeFont","initMutationObserver","listenToResize","initResizeObserver","element","nativeElement","forceRefresh","recalculate","observe","pipe","map","entry","Math","round","contentRect","width","filter","w","distinctUntilChanged","takeUntilDestroyed","subscribe","characterData","childList","subtree","removeClass","fontSize","undefined","detectChanges","style","getComputedStyle","parseFloat","overflowRatio","minFontSize","newFont","max","min","adjustRatio","toFixed","addClass","offsetWidth","scrollWidth","ɵɵdirectiveInject","ElementRef","Renderer2","MutationObserverService","ResizeObserverService","ChangeDetectorRef","R","selectors","hostVars","hostBindings","rf","ctx","ɵɵstyleProp","_WhenOverflowedDirective","SwitcherToggleService","dialogService","htmlNode","isSwitcherEnabled","visible$","BehaviorSubject","switcherEnabled","show$","v","hide$","switchMap","fromEvent","skip","takeUntil","close","expanded$","asObservable","expanded","getValue","open","component","toggleHtmlClasses","dialogRef","openDialog","next","_a","clos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