{"version":3,"file":"tstdl-angular-tooltip.mjs","sources":["../../../../projects/tstdl/angular/tooltip/source/tooltip.component.ts","../../../../projects/tstdl/angular/tooltip/source/tooltip.component.html","../../../../projects/tstdl/angular/tooltip/source/tooltip.directive.ts","../../../../projects/tstdl/angular/tooltip/tstdl-angular-tooltip.ts"],"sourcesContent":["import { ChangeDetectionStrategy, Component, model, ViewEncapsulation } from '@angular/core';\nimport { DynamicTextPipe, fadeInOutAnimation } from '@tstdl/angular';\nimport type { DynamicText } from '@tstdl/base/text';\n\n@Component({\n  selector: 'tsl-tooltip',\n  imports: [DynamicTextPipe],\n  templateUrl: './tooltip.component.html',\n  styleUrls: ['./tooltip.component.scss'],\n  changeDetection: ChangeDetectionStrategy.OnPush,\n  encapsulation: ViewEncapsulation.None,\n  animations: [\n    fadeInOutAnimation()\n  ],\n  host: {\n    '[@fadeInOut]': 'true'\n  }\n})\nexport class TooltipComponent {\n  readonly text = model<DynamicText | null>();\n}\n","<ng-content></ng-content>\n\n@if (text(); as text) {\n  <span>{{ text | dynamicText }}</span>\n}\n","import { Overlay, OverlayPositionBuilder, OverlayRef, type PositionStrategy } from '@angular/cdk/overlay';\nimport { ComponentPortal, TemplatePortal } from '@angular/cdk/portal';\nimport { ComponentRef, Directive, ElementRef, EmbeddedViewRef, Input, type OnDestroy, TemplateRef, ViewContainerRef, inject, isSignal } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport type { DynamicText } from '@tstdl/base/text';\nimport type { Type } from '@tstdl/base/types';\nimport { isDefined, isFunction, isNotNullOrUndefined, isNull, isString } from '@tstdl/base/utils';\nimport { combineLatest, delay, distinctUntilChanged, fromEvent, isObservable, map, merge, of, startWith, switchMap } from 'rxjs';\n\nimport { TooltipComponent } from './tooltip.component';\n\n@Directive({\n  selector: '[tslTooltip]'\n})\nexport class TooltipDirective<Component extends Type, Context> implements OnDestroy {\n  private readonly elementRef = inject<ElementRef<HTMLElement>>(ElementRef);\n  private readonly viewContainerRef = inject(ViewContainerRef);\n  private readonly overlay = inject(Overlay);\n  private readonly overlayPositionBuilder = inject(OverlayPositionBuilder);\n  private readonly positionStrategy: PositionStrategy;\n\n  private overlayRef: OverlayRef | undefined;\n\n  @Input('tslTooltip') content: DynamicText | Component | TemplateRef<Context> | ComponentPortal<Component> | TemplatePortal<Context> | null;\n  @Input() tooltipContainer = true;\n  @Input() tooltipContext: Context | null | undefined;\n  @Input() tooltipDelay: number = 500;\n\n  tooltipComponentRef: ComponentRef<Component> | undefined;\n  tooltipViewRef: EmbeddedViewRef<Context> | undefined;\n\n  constructor() {\n    const showFromMouse$ = merge(\n      fromEvent(this.elementRef.nativeElement, 'mouseenter').pipe(map(() => true)),\n      fromEvent(this.elementRef.nativeElement, 'mouseleave').pipe(map(() => false)),\n    ).pipe(startWith(false));\n\n    const showFromFocus$ = merge(\n      fromEvent(this.elementRef.nativeElement, 'focusin').pipe(map(() => true)),\n      fromEvent(this.elementRef.nativeElement, 'focusout').pipe(map(() => false)),\n    ).pipe(startWith(false));\n\n    combineLatest([showFromMouse$, showFromFocus$])\n      .pipe(\n        map(([mouse, focus]) => mouse || focus),\n        distinctUntilChanged(),\n        switchMap((show) => (show ? of(true).pipe(delay(this.tooltipDelay)) : of(false))),\n        distinctUntilChanged(),\n        takeUntilDestroyed(),\n      )\n      .subscribe((show) => (show ? this.show() : this.hide()));\n\n    this.positionStrategy = this.overlayPositionBuilder\n      .flexibleConnectedTo(this.elementRef)\n      .withPositions([{\n        originX: 'center',\n        originY: 'top',\n        overlayX: 'center',\n        overlayY: 'bottom'\n      }])\n      .withViewportMargin(5)\n      .withDefaultOffsetY(-5)\n      .withPush(true);\n  }\n\n  ngOnDestroy(): void {\n    this.hide();\n  }\n\n  show(): void {\n    if (isNull(this.content)) {\n      return;\n    }\n\n    this.overlayRef = this.overlay.create({ positionStrategy: this.positionStrategy });\n\n    const templatePortal = (this.content instanceof TemplatePortal)\n      ? this.content\n      : (this.content instanceof TemplateRef)\n        ? new TemplatePortal(this.content, this.viewContainerRef)\n        : undefined;\n\n    const componentPortal = (this.content instanceof ComponentPortal)\n      ? this.content\n      : (isFunction(this.content) && !isSignal(this.content))\n        ? new ComponentPortal(this.content as Component, this.viewContainerRef)\n        : undefined;\n\n    if (isDefined(templatePortal)) {\n      this.tooltipViewRef = this.overlayRef.attach(templatePortal);\n\n      if (isNotNullOrUndefined(this.tooltipContext)) {\n        this.tooltipViewRef.context = this.tooltipContext;\n      }\n    }\n    else if (isDefined(componentPortal)) {\n      this.tooltipComponentRef = this.overlayRef.attach(this.content);\n    }\n    else {\n      const tooltipComponentPortal = new ComponentPortal(TooltipComponent);\n      const tooltipComponentRef = this.overlayRef.attach(tooltipComponentPortal);\n\n      if (isString(this.content) || isSignal(this.content) || isObservable(this.content)) {\n        tooltipComponentRef.instance.text.set(this.content as DynamicText);\n      }\n    }\n  }\n\n  hide(): void {\n    this.overlayRef?.dispose();\n    this.tooltipViewRef = undefined;\n    this.tooltipComponentRef = undefined;\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;MAkBa,gBAAgB,CAAA;AAd7B,IAAA,WAAA,GAAA;QAeW,IAAA,CAAA,IAAI,GAAG,KAAK,CAAA,IAAA,SAAA,GAAA,CAAA,SAAA,EAAA,EAAA,SAAA,EAAA,MAAA,EAAA,CAAA,8BAAA,EAAA,CAAA,CAAsB;AAC5C,IAAA;8GAFY,gBAAgB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA,CAAA;AAAhB,IAAA,SAAA,IAAA,CAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,IAAA,EAAA,gBAAgB,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,aAAA,EAAA,MAAA,EAAA,EAAA,IAAA,EAAA,E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