{"version":3,"file":"talenra-ngx-base-tooltip.mjs","sources":["../../../projects/ngx-base/tooltip/src/tooltip/tooltip.component.ts","../../../projects/ngx-base/tooltip/src/tooltip/tooltip.component.html","../../../projects/ngx-base/tooltip/src/tooltip/tooltip.connect-position.ts","../../../projects/ngx-base/tooltip/src/tooltip/tooltip.directive.ts","../../../projects/ngx-base/tooltip/src/tooltip/tooltip.types.ts","../../../projects/ngx-base/tooltip/talenra-ngx-base-tooltip.ts"],"sourcesContent":["import { ChangeDetectionStrategy, ChangeDetectorRef, Component, inject } from '@angular/core';\n\n/**\n * Used by Tooltip directive to display a tooltip.\n *\n * @internal\n */\n@Component({\n  selector: 'talenra-tooltip',\n  templateUrl: './tooltip.component.html',\n  styleUrl: './tooltip.component.scss',\n  changeDetection: ChangeDetectionStrategy.OnPush,\n  host: {\n    '[class]': 'hostClass',\n  },\n})\nexport class TooltipComponent {\n  /** Text displayed in tooltip */\n  text: string = '';\n\n  /**\n   * Used for visual transitions. When `active`, Tooltip is visible or fading-in, while `inactive` Tooltip is invisible\n   * or fading-out.\n   */\n  public get state(): 'active' | 'inactive' {\n    return this._state;\n  }\n  public set state(value: 'active' | 'inactive') {\n    if (value === this._state) return;\n    this._state = value;\n    this.changeDetector.markForCheck();\n  }\n\n  /** State is set 'inactive' while fade-out transition is in progress. */\n  private _state: 'active' | 'inactive' = 'inactive';\n\n  /** Helper: Add classes to host element (hooks for styling) */\n  private get hostClass(): string {\n    return `state--${this.state}`;\n  }\n\n  private changeDetector: ChangeDetectorRef = inject(ChangeDetectorRef);\n}\n","{{ text }}\n","import { ConnectedPosition } from '@angular/cdk/overlay';\nimport { TTooltipPosition } from './tooltip.types';\n\n/**\n * Type used for position maps. Represents a dictionary of ConnectedPosition for different positions. The keys of the\n * dictionary are the positions, and the values are objects containing key-value pairs for ConnectedPosition of the cdk-overlay.\n *\n * ```typescript\n * export const positions: Dictionary = {\n *  'north': {\n *       originX: 'center',\n *       originY: 'top',\n *       overlayX: 'center',\n *       overlayY: 'bottom',\n *  },\n *  'east': {\n *       originX: 'end',\n *       originY: 'center',\n *       overlayX: 'start',\n *       overlayY: 'center',\n *     },\n *     ...\n *  },\n * ```\n */\nexport type TTooltipConnectedPosition = Record<TTooltipPosition, ConnectedPosition>;\n\n/** @internal */\nexport const TooltipConnectedPosition: TTooltipConnectedPosition = {\n  south: {\n    originX: 'center',\n    originY: 'bottom',\n    overlayX: 'center',\n    overlayY: 'top',\n  },\n  west: {\n    originX: 'start',\n    originY: 'center',\n    overlayX: 'end',\n    overlayY: 'center',\n  },\n  north: {\n    originX: 'center',\n    originY: 'top',\n    overlayX: 'center',\n    overlayY: 'bottom',\n  },\n  east: {\n    originX: 'end',\n    originY: 'center',\n    overlayX: 'start',\n    overlayY: 'center',\n  },\n};\n","import { booleanAttribute, Directive, ElementRef, input, OnDestroy, inject } from '@angular/core';\nimport { ConnectedPosition, Overlay, OverlayRef } from '@angular/cdk/overlay';\nimport { ComponentPortal } from '@angular/cdk/portal';\nimport { TTooltipPosition } from './tooltip.types';\nimport { TooltipComponent } from './tooltip.component';\nimport { TooltipConnectedPosition } from './tooltip.connect-position';\n\n/**\n * Transition duration in seconds. Value must sync with TooltipComponent stylesheet.\n *\n * @internal\n */\nconst TRANSITION_DURATION: number = 0.3;\n\n/**\n * Tooltip provides an explanatory text which is displayed when the hosting element is hovered. By default the Tooltip\n * is displayed below the hosting element (south). The preferred position can be changed (s. {@link #position|talenraTooltipPosition}). If\n * space is limited, position is adjusted automatically.\n *\n * ```html\n * <span talenraTooltip=\"Tooltip text\">Hover me</span>\n * ```\n *\n * ### Import\n *\n * ```typescript\n * import { TooltipDirective } from '@talenra/ngx-base/tooltip';\n * ```\n *\n * <example-url>../../#/tooltip</example-url>\n */\n@Directive({\n  selector: '[talenraTooltip]',\n  host: {\n    '(focus)': 'handleFocus()',\n    '(mouseenter)': 'show()',\n    '(document:keydown.escape)': 'hide()',\n    '(blur)': 'hide()',\n    '(mouseleave)': 'hide()',\n    '(click)': 'hide()',\n  },\n})\nexport class TooltipDirective implements OnDestroy {\n  /**\n   * Text displayed in Tooltip.\n   *\n   * ```html\n   * <span talenraTooltip=\"Tooltip text\">Hover me</span>\n   * ```\n   */\n  text = input<string>('', { alias: 'talenraTooltip' });\n\n  /**\n   * The Tooltip's position relative to the hosting element ('north', 'east', …). Defaults to 'south'.\n   *\n   * ```html\n   * <span talenraTooltip=\"Tooltip text\" talenraTooltipPosition=\"north\">Hover me</span>\n   * ```\n   *\n   * @see {@link TooltipPosition}\n   */\n  position = input<TTooltipPosition>('south', { alias: 'talenraTooltipPosition' });\n\n  /**\n   * Determines whether Tooltip is displayed when the hosting element is hovered. Use this property to conditionally\n   * de-/activate a Tooltip (e.g. based on the app's state, user interaction or content).\n   *\n   * ```html\n   * <span talenraTooltip=\"Tooltip text\" [talenraTooltipDisabled]=\"disableTooltip\">Hover me</span>\n   * ```\n   */\n  disabled = input(false, { alias: 'talenraTooltipDisabled', transform: booleanAttribute });\n\n  /** The Material CDK Overlay reference. It is used to create/display and destroy the tooltip. */\n  private overlayRef: OverlayRef | null = null;\n  /** TooltipComponent instance displayes in the overlay */\n  private tooltipInstance?: TooltipComponent;\n  /** Timeout id used to detach after fade-out transition has completed */\n  private detachTimeoutId?: number;\n\n  private elementRef = inject(ElementRef);\n  private overlay = inject(Overlay);\n\n  /** @internal */\n  ngOnDestroy(): void {\n    this.detach();\n  }\n\n  /** Returns the position strategy based on the position input. */\n  private getPositionStrategy(): ConnectedPosition[] {\n    const strategies: ConnectedPosition[] = [\n      TooltipConnectedPosition.south,\n      TooltipConnectedPosition.west,\n      TooltipConnectedPosition.north,\n      TooltipConnectedPosition.east,\n      TooltipConnectedPosition.south,\n      TooltipConnectedPosition.west,\n      TooltipConnectedPosition.north,\n    ];\n    const indexes = { south: 0, west: 1, north: 2, east: 3 };\n    const index: number = indexes[this.position()] || 0;\n    return strategies.slice(index, index + 4);\n  }\n\n  /** Handler for focus events. Shows Tooltip unless it is already visible (includes fade-out in progress). */\n  private handleFocus(): void {\n    if (this.tooltipInstance) return;\n    this.show();\n  }\n\n  /** Creates the overlay */\n  private createOverlay(): OverlayRef {\n    const positionStrategy = this.overlay\n      .position()\n      .flexibleConnectedTo(this.elementRef)\n      .withPositions(this.getPositionStrategy());\n    return this.overlay.create({\n      hasBackdrop: false,\n      positionStrategy,\n      scrollStrategy: this.overlay.scrollStrategies.reposition(),\n      panelClass: 'talenra-tooltip',\n    });\n  }\n\n  /** Fade in tooltip, create it if not existing */\n  private show(): void {\n    // Guard clause: Exit if the tooltip is disabled, text is missing or the tooltip is already displayed\n    if (this.disabled() || !this.text()) return;\n    // Detach existing tooltip first\n    this.tooltipInstance && this.detach();\n    // Create overlay if not existing\n    this.overlayRef = this.overlayRef || this.createOverlay();\n    const tooltipComponentPortal = new ComponentPortal(TooltipComponent);\n    // Create tooltip instance if not existing and update the tooltip text\n    this.tooltipInstance = this.tooltipInstance || this.overlayRef.attach(tooltipComponentPortal).instance;\n    this.tooltipInstance.text = this.text();\n    // Clear eventually pending detach-timeout\n    this.detachTimeoutId && window.clearTimeout(this.detachTimeoutId);\n    // Update tooltip state slightly delayed to trigger fade-in transition\n    window.setTimeout(() => {\n      if (this.tooltipInstance) {\n        this.tooltipInstance.state = 'active';\n      }\n    });\n  }\n\n  /** Fade out and detach tooltip */\n  private hide(): void {\n    if (!this.overlayRef) return;\n    // Update tooltip state to trigger fade-out transition\n    if (this.tooltipInstance) {\n      this.tooltipInstance.state = 'inactive';\n    }\n    // Detach overlay after fade-out transition has completed\n    this.detachTimeoutId = window.setTimeout(() => this.detach(), TRANSITION_DURATION * 1000);\n  }\n\n  /** Detach tooltip immediately */\n  private detach(): void {\n    window.clearTimeout(this.detachTimeoutId);\n    this.overlayRef?.detach();\n    this.tooltipInstance = undefined;\n  }\n}\n","/**\n * Values accepted by `Toolltip`'s `talenraTooltipPosition` property. Determines the position of the tooltip relative to\n * the hosting element.\n *\n * ```html\n * <span talenraTooltip=\"Tooltip text\" talenraTooltipPosition=\"north\">Hover me</span>\n * ```\n *\n * ### Import\n *\n * ```typescript\n * import { TooltipPosition } from '@talenra/ngx-base/tooltip';\n * ```\n *\n * @see {@link TooltipDirective}\n */\nexport const TooltipPosition = {\n  South: 'south',\n  West: 'west',\n  North: 'north',\n  East: 'east',\n} as const;\n\n/**\n * Type of values accepted by `Toolltip`'s `talenraTooltipPosition` property.\n *\n * ### Import\n *\n * ```typescript\n * import { TTooltipPosition } from '@talenra/ngx-base/tooltip';\n * ```\n *\n * @see {@link TooltipDirective}\n */\nexport type TTooltipPosition = (typeof TooltipPosition)[keyof typeof TooltipPosition];\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAEA;;;;AAIG;MAUU,gBAAgB,CAAA;AAT7B,IAAA,WAAA,GAAA;;QAWE,IAAI,CAAA,IAAA,GAAW,EAAE;;QAgBT,IAAM,CAAA,MAAA,GAA0B,UAAU;AAO1C,QAAA,IAAA,CAAA,cAAc,GAAsB,MAAM,CAAC,iBAAiB,CAAC;AACtE;AAtBC;;;AAGG;AACH,IAAA,IAAW,KAAK,GAAA;QACd,OAAO,IAAI,CAAC,MAAM;;IAEpB,IAAW,KAAK,CAAC,KAA4B,EAAA;AAC3C,QAAA,IAAI,KAAK,KAAK,IAAI,CAAC,MAAM;YAAE;AAC3B,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;AACnB,QAAA,IAAI,CAAC,cAAc,CAAC,YAAY,EAAE;;;AAOpC,IAAA,IAAY,SAAS,GAAA;AACnB,QAAA,OAAO,CAAU,OAAA,EAAA,IAAI,CAAC,KAAK,EAAE;;8GAtBpB,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,QAA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