@nanahoshi/mona-ui 0.24.8 → 0.24.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/fesm2022/nanahoshi-mona-ui-button-group.mjs +37 -9
  2. package/fesm2022/nanahoshi-mona-ui-button.mjs +8 -2
  3. package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +4 -3
  4. package/fesm2022/nanahoshi-mona-ui-color-picker.mjs +2 -2
  5. package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +101 -47
  6. package/fesm2022/nanahoshi-mona-ui-dialog.mjs +342 -102
  7. package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +119 -69
  8. package/fesm2022/nanahoshi-mona-ui-editor.mjs +1054 -452
  9. package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-DdyHnUIr.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DhKLnW06.mjs} +2 -2
  10. package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-B6gq7Hu3.mjs → nanahoshi-mona-ui-grid-grid-list.component-voGbKOiB.mjs} +4 -4
  11. package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-DdUY3I7P.mjs → nanahoshi-mona-ui-grid-grid-row.component-HQ1Kv6R9.mjs} +2 -3
  12. package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-DG8Bu4Dy.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-PNLJFcuH.mjs} +4 -4
  13. package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CVqpbMcb.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BO19AVwC.mjs} +9 -9
  14. package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
  15. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +23 -0
  16. package/fesm2022/nanahoshi-mona-ui-internal.mjs +567 -33
  17. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +20 -0
  18. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +20 -0
  19. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +20 -0
  20. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +20 -0
  21. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +20 -0
  22. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +20 -0
  23. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +20 -0
  24. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +20 -0
  25. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +20 -0
  26. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +20 -0
  27. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +20 -0
  28. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +20 -0
  29. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +20 -0
  30. package/fesm2022/nanahoshi-mona-ui-menubar.mjs +127 -133
  31. package/fesm2022/nanahoshi-mona-ui-notification.mjs +473 -240
  32. package/fesm2022/nanahoshi-mona-ui-popover.mjs +202 -90
  33. package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +609 -256
  34. package/fesm2022/nanahoshi-mona-ui-popup.mjs +2 -0
  35. package/fesm2022/nanahoshi-mona-ui-sheet.mjs +45 -10
  36. package/fesm2022/nanahoshi-mona-ui-split-button.mjs +102 -58
  37. package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +286 -443
  38. package/fesm2022/nanahoshi-mona-ui-window.mjs +594 -311
  39. package/i18n/catalogs/en-US.messages.json +24 -4
  40. package/locales/ar-sa/ar-sa.messages.json +20 -0
  41. package/locales/de-de/de-de.messages.json +20 -0
  42. package/locales/es-es/es-es.messages.json +20 -0
  43. package/locales/fr-fr/fr-fr.messages.json +20 -0
  44. package/locales/id-id/id-id.messages.json +20 -0
  45. package/locales/it-it/it-it.messages.json +20 -0
  46. package/locales/ja-jp/ja-jp.messages.json +20 -0
  47. package/locales/ko-kr/ko-kr.messages.json +20 -0
  48. package/locales/pt-br/pt-br.messages.json +20 -0
  49. package/locales/ru-ru/ru-ru.messages.json +20 -0
  50. package/locales/tr-tr/tr-tr.messages.json +20 -0
  51. package/locales/zh-cn/zh-cn.messages.json +20 -0
  52. package/locales/zh-tw/zh-tw.messages.json +20 -0
  53. package/package.json +1 -1
  54. package/types/nanahoshi-mona-ui-button-group.d.ts +13 -3
  55. package/types/nanahoshi-mona-ui-button.d.ts +20 -3
  56. package/types/nanahoshi-mona-ui-contextmenu.d.ts +5 -6
  57. package/types/nanahoshi-mona-ui-dialog.d.ts +131 -20
  58. package/types/nanahoshi-mona-ui-dropdown-button.d.ts +75 -56
  59. package/types/nanahoshi-mona-ui-editor.d.ts +118 -21
  60. package/types/nanahoshi-mona-ui-i18n.d.ts +37 -0
  61. package/types/nanahoshi-mona-ui-internal.d.ts +142 -16
  62. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +20 -0
  63. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +20 -0
  64. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +20 -0
  65. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +20 -0
  66. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +20 -0
  67. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +20 -0
  68. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +20 -0
  69. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +20 -0
  70. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +20 -0
  71. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +20 -0
  72. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +20 -0
  73. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +20 -0
  74. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +20 -0
  75. package/types/nanahoshi-mona-ui-menubar.d.ts +65 -62
  76. package/types/nanahoshi-mona-ui-notification.d.ts +76 -16
  77. package/types/nanahoshi-mona-ui-popover.d.ts +44 -17
  78. package/types/nanahoshi-mona-ui-popup-menu.d.ts +110 -32
  79. package/types/nanahoshi-mona-ui-popup.d.ts +2 -0
  80. package/types/nanahoshi-mona-ui-sheet.d.ts +16 -5
  81. package/types/nanahoshi-mona-ui-split-button.d.ts +29 -7
  82. package/types/nanahoshi-mona-ui-tooltip.d.ts +43 -20
  83. package/types/nanahoshi-mona-ui-window.d.ts +103 -14
@@ -1,10 +1,11 @@
1
- import { DOCUMENT } from '@angular/common';
1
+ import { Directionality } from '@angular/cdk/bidi';
2
+ import { DOCUMENT, NgTemplateOutlet } from '@angular/common';
2
3
  import * as i0 from '@angular/core';
3
- import { inject, DestroyRef, Renderer2, computed, linkedSignal, viewChild, TemplateRef, input, output, afterRenderEffect, Component, ElementRef, EnvironmentInjector, signal, createComponent, Directive, ChangeDetectionStrategy } from '@angular/core';
4
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
5
- import { themeOverlaySurfaceClasses, createElementControlId } from '@nanahoshi/mona-ui/internal';
6
- import { PopupService, fadePopupAnimation } from '@nanahoshi/mona-ui/popup';
7
- import { take, takeUntil, Subscription, fromEvent, tap } from 'rxjs';
4
+ import { inject, DestroyRef, computed, signal, viewChild, TemplateRef, input, output, effect, untracked, ElementRef, Component, EnvironmentInjector, afterNextRender, createComponent, Directive } from '@angular/core';
5
+ import { resolveComponentDirection } from '@nanahoshi/mona-ui/i18n';
6
+ import { themeOverlaySurfaceClasses, HoverIntent, createElementControlId, listenForHover, resolveOverlaySide, overlaySidePositions, addAriaReference, onDisconnect, sideOfPosition, removeAriaReference } from '@nanahoshi/mona-ui/internal';
7
+ import { PopupService, fadePopupAnimation, PopupCloseSource } from '@nanahoshi/mona-ui/popup';
8
+ import { take, takeUntil } from 'rxjs';
8
9
  import { cva } from 'class-variance-authority';
9
10
  import { twMerge } from 'tailwind-merge';
10
11
 
@@ -50,96 +51,29 @@ const tooltipArrowThemeVariants = cva(`
50
51
  data-[position="right"]:[clip-path:inset(1px_1px_0_0)]
51
52
  `);
52
53
 
53
- /**
54
- * Derives the tooltip arrow position from a ConnectionPositionPair.
55
- * This function determines where the arrow should be positioned based on
56
- * how the popup is actually positioned relative to its anchor.
57
- */
58
- function getArrowPositionFromConnectionPair(connectionPair) {
59
- const { originX, originY, overlayX, overlayY } = connectionPair;
60
- // Tooltip is above the anchor (arrow points down)
61
- if (originY === "top" && overlayY === "bottom") {
62
- return "top";
63
- }
64
- // Tooltip is below the anchor (arrow points up)
65
- if (originY === "bottom" && overlayY === "top") {
66
- return "bottom";
67
- }
68
- // Tooltip is to the left of the anchor (arrow points right)
69
- if (originX === "start" && overlayX === "end") {
70
- return "left";
71
- }
72
- // Tooltip is to the right of the anchor (arrow points left)
73
- if (originX === "end" && overlayX === "start") {
74
- return "right";
75
- }
76
- // For center-aligned tooltips, prioritize vertical positioning
77
- if (overlayY === "bottom") {
78
- return "top";
79
- }
80
- if (overlayY === "top") {
81
- return "bottom";
82
- }
83
- if (overlayX === "end") {
84
- return "left";
85
- }
86
- if (overlayX === "start") {
87
- return "right";
88
- }
89
- return "top";
90
- }
91
- /**
92
- * Gets the appropriate offset for a tooltip based on its position.
93
- * The offset ensures proper spacing between the tooltip and its anchor element.
94
- */
95
- function getOffsetForPosition(position, arrowVisible) {
96
- const arrowOffset = arrowVisible ? 12 : 4;
97
- switch (position) {
98
- case "top":
99
- return { horizontal: 0, vertical: -arrowOffset };
100
- case "bottom":
101
- return { horizontal: 0, vertical: arrowOffset };
102
- case "right":
103
- return { horizontal: arrowOffset, vertical: 0 };
104
- case "left":
105
- return { horizontal: -arrowOffset, vertical: 0 };
106
- }
107
- }
108
- function getPositionConnectionPoints(position) {
109
- switch (position) {
110
- case "top":
111
- return { anchor: "topcenter", popup: "bottomcenter" };
112
- case "bottom":
113
- return { anchor: "bottomcenter", popup: "topcenter" };
114
- case "right":
115
- return { anchor: "centerright", popup: "centerleft" };
116
- case "left":
117
- return { anchor: "centerleft", popup: "centerright" };
118
- }
119
- }
120
-
54
+ /** The gap between a tooltip and its anchor, leaving room for the arrow. */
55
+ const TOOLTIP_GAP$1 = 12;
121
56
  class TooltipComponent {
122
57
  #destroyRef;
58
+ #directionality;
123
59
  #document;
60
+ #intent;
124
61
  #popupService;
125
- #renderer;
126
- #currentAnchor;
127
- #eventSubscription;
128
- #hideTimeoutId;
129
- #mutationObserver;
62
+ #destroyed;
130
63
  #popupRef;
131
- #showTimeoutId;
132
64
  constructor() {
133
65
  this.#destroyRef = inject(DestroyRef);
66
+ this.#directionality = inject(Directionality, { optional: true });
134
67
  this.#document = inject(DOCUMENT);
68
+ this.#intent = new HoverIntent({
69
+ hide: () => this.#popupRef?.close(),
70
+ hideDelay: () => this.hideDelay(),
71
+ show: anchor => this.#open(anchor),
72
+ showDelay: () => this.showDelay()
73
+ });
135
74
  this.#popupService = inject(PopupService);
136
- this.#renderer = inject(Renderer2);
137
- this.#currentAnchor = null;
138
- this.#eventSubscription = null;
139
- this.#hideTimeoutId = null;
140
- this.#mutationObserver = null;
75
+ this.#destroyed = false;
141
76
  this.#popupRef = null;
142
- this.#showTimeoutId = null;
143
77
  this.arrowClasses = computed(() => {
144
78
  return tooltipArrowThemeVariants();
145
79
  }, /* @ts-ignore */
@@ -149,13 +83,14 @@ class TooltipComponent {
149
83
  return tooltipBaseThemeVariants({ rounded });
150
84
  }, /* @ts-ignore */
151
85
  ...(ngDevMode ? [{ debugName: "baseClasses" }] : /* istanbul ignore next */ []));
152
- this.currentArrowPosition = linkedSignal(() => this.position(), /* @ts-ignore */
86
+ this.currentArrowPosition = signal("top", /* @ts-ignore */
153
87
  ...(ngDevMode ? [{ debugName: "currentArrowPosition" }] : /* istanbul ignore next */ []));
154
88
  this.templateRef = viewChild.required(TemplateRef, /* @ts-ignore */
155
89
  ...(ngDevMode ? [{ debugName: "templateRef" }] : /* istanbul ignore next */ []));
156
90
  this.tooltipId = createElementControlId();
157
91
  /**
158
- * @description Whether the tooltip is disabled. When disabled, the tooltip will not be shown.
92
+ * @description Whether the tooltip is disabled. When disabled, the tooltip will not be shown, and an open one
93
+ * closes.
159
94
  */
160
95
  this.disabled = input(false, /* @ts-ignore */
161
96
  ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
@@ -164,12 +99,14 @@ class TooltipComponent {
164
99
  */
165
100
  this.hidden = output();
166
101
  /**
167
- * @description The delay in milliseconds before hiding the tooltip after the trigger event ends.
102
+ * @description The delay in milliseconds before hiding the tooltip after the pointer or focus leaves. A pointer
103
+ * that leaves always gets a short grace, so it can move onto the tooltip.
168
104
  */
169
105
  this.hideDelay = input(0, /* @ts-ignore */
170
106
  ...(ngDevMode ? [{ debugName: "hideDelay" }] : /* istanbul ignore next */ []));
171
107
  /**
172
- * @description The position of the tooltip relative to the target element.
108
+ * @description The side of the target the tooltip opens on. `left` and `right` are physical; `start` and `end`
109
+ * follow the text direction. It flips to the opposite side when there isn't room.
173
110
  */
174
111
  this.position = input("top", /* @ts-ignore */
175
112
  ...(ngDevMode ? [{ debugName: "position" }] : /* istanbul ignore next */ []));
@@ -189,158 +126,85 @@ class TooltipComponent {
189
126
  this.shown = output();
190
127
  /**
191
128
  * @description The target element(s) to which the tooltip is attached.
192
- * Can be an Element, ElementRef, or CSS selector string.
129
+ * Can be an Element, ElementRef, or CSS selector string. A selector matches elements anywhere in the document,
130
+ * including ones added later.
193
131
  */
194
132
  this.target = input.required(/* @ts-ignore */
195
133
  ...(ngDevMode ? [{ debugName: "target" }] : /* istanbul ignore next */ []));
196
- afterRenderEffect({
197
- read: () => {
198
- this.target();
199
- this.position(); // reactive dependency: re-run when position changes
200
- this.#currentAnchor = null;
201
- this.#popupRef?.close();
202
- this.#refreshSubscription();
203
- this.#mutationObserver?.disconnect();
204
- this.#mutationObserver = null;
205
- if (typeof this.target() === "string") {
206
- this.#mutationObserver = new MutationObserver(() => this.#refreshSubscription());
207
- this.#mutationObserver.observe(this.#document.body, { childList: true, subtree: true });
208
- }
134
+ effect(onCleanup => {
135
+ const target = this.target();
136
+ this.position();
137
+ const stop = untracked(() => this.#listen(target));
138
+ onCleanup(() => {
139
+ stop();
140
+ this.#intent.hideNow();
141
+ });
142
+ });
143
+ effect(() => {
144
+ if (this.disabled()) {
145
+ untracked(() => this.#intent.hideNow());
209
146
  }
210
147
  });
211
148
  this.#destroyRef.onDestroy(() => {
212
- if (this.#showTimeoutId != null) {
213
- clearTimeout(this.#showTimeoutId);
214
- this.#showTimeoutId = null;
215
- }
216
- if (this.#hideTimeoutId != null) {
217
- clearTimeout(this.#hideTimeoutId);
218
- this.#hideTimeoutId = null;
219
- }
220
- this.#mutationObserver?.disconnect();
221
- this.#mutationObserver = null;
149
+ this.#destroyed = true;
150
+ this.#intent.dispose();
222
151
  this.#popupRef?.close();
223
152
  });
224
153
  }
225
- #createTooltip(anchor) {
226
- this.#currentAnchor = anchor;
227
- this.currentArrowPosition.set(this.position());
228
- const connectionPoints = getPositionConnectionPoints(this.position());
229
- const offset = getOffsetForPosition(this.position(), true);
154
+ #listen(target) {
155
+ if (typeof target === "string") {
156
+ return listenForHover(this.#document, node => node.closest(target), this.#intent);
157
+ }
158
+ const element = target instanceof ElementRef ? target.nativeElement : target;
159
+ if (!(element instanceof HTMLElement)) {
160
+ return () => undefined;
161
+ }
162
+ return listenForHover(element, node => (element.contains(node) ? element : null), this.#intent);
163
+ }
164
+ #open(anchor) {
165
+ if (this.disabled() || this.#destroyed) {
166
+ return;
167
+ }
168
+ const direction = resolveComponentDirection(anchor, this.#directionality);
169
+ const side = resolveOverlaySide(this.position(), direction);
170
+ this.currentArrowPosition.set(side);
230
171
  const popupRef = this.#popupService.create({
231
172
  anchor,
232
- anchorConnectionPoint: connectionPoints.anchor,
233
173
  animation: fadePopupAnimation,
234
174
  closeOnEscape: true,
235
175
  closeOnMouseLeave: false,
236
176
  closeOnOutsideClick: true,
237
177
  content: this.templateRef(),
238
178
  hasBackdrop: false,
239
- offset,
240
- popupConnectionPoint: connectionPoints.popup,
179
+ positions: overlaySidePositions(side, TOOLTIP_GAP$1, direction),
241
180
  restoreFocus: false,
242
181
  withPush: false
243
182
  });
244
183
  this.#popupRef = popupRef;
245
- this.#renderer.setAttribute(anchor, "aria-describedby", this.tooltipId);
246
- popupRef.opened.pipe(take(1)).subscribe(() => this.shown.emit());
247
- popupRef.closed.pipe(take(1)).subscribe(() => {
248
- if (this.#popupRef === popupRef) {
249
- this.#popupRef = null;
250
- this.#currentAnchor = null;
184
+ addAriaReference(anchor, "aria-describedby", this.tooltipId);
185
+ this.#intent.opened(anchor, popupRef.overlayRef.overlayElement);
186
+ const stopWatching = onDisconnect(anchor, () => popupRef.close());
187
+ popupRef.opened.pipe(take(1)).subscribe(() => {
188
+ if (!this.#destroyed) {
189
+ this.shown.emit();
251
190
  }
252
- this.#renderer.removeAttribute(anchor, "aria-describedby");
253
- this.hidden.emit();
254
191
  });
255
- popupRef.positionChanges
256
- .pipe(takeUntil(popupRef.closed), takeUntilDestroyed(this.#destroyRef))
257
- .subscribe(connectionPair => {
258
- const newArrowPosition = getArrowPositionFromConnectionPair(connectionPair);
259
- this.currentArrowPosition.set(newArrowPosition);
192
+ popupRef.positionChanges.pipe(takeUntil(popupRef.closeStart)).subscribe(position => {
193
+ this.currentArrowPosition.set(sideOfPosition(position, direction));
260
194
  });
261
- }
262
- #getAnchorElement(anchor) {
263
- if (anchor instanceof HTMLElement) {
264
- return anchor;
265
- }
266
- if (typeof anchor === "object" && "nativeElement" in anchor && anchor.nativeElement instanceof HTMLElement) {
267
- return anchor.nativeElement;
268
- }
269
- return null;
270
- }
271
- #handleHide() {
272
- if (!this.#popupRef) {
273
- return;
274
- }
275
- const hideDelay = this.hideDelay();
276
- if (hideDelay > 0) {
277
- const popupRef = this.#popupRef;
278
- this.#hideTimeoutId = setTimeout(() => {
279
- this.#hideTimeoutId = null;
280
- if (this.#popupRef === popupRef) {
281
- popupRef.close();
282
- }
283
- }, hideDelay);
284
- }
285
- else {
286
- this.#popupRef.close();
287
- }
288
- }
289
- #handleShow(element) {
290
- if (this.disabled()) {
291
- return;
292
- }
293
- if (this.#popupRef && this.#currentAnchor === element) {
294
- return;
295
- }
296
- this.#popupRef?.close();
297
- const showDelay = this.showDelay();
298
- if (showDelay > 0) {
299
- this.#showTimeoutId = setTimeout(() => {
300
- this.#showTimeoutId = null;
301
- if (!this.#popupRef || this.#currentAnchor !== element) {
302
- this.#createTooltip(element);
303
- }
304
- }, showDelay);
305
- }
306
- else {
307
- this.#createTooltip(element);
308
- }
309
- }
310
- #refreshSubscription() {
311
- this.#eventSubscription?.unsubscribe();
312
- this.#eventSubscription = null;
313
- const target = this.target();
314
- if (typeof target === "string") {
315
- const elements = Array.from(this.#document.querySelectorAll(target));
316
- const composite = new Subscription();
317
- for (const element of elements) {
318
- composite.add(this.#subscribeToElement(element));
195
+ popupRef.closeStart.pipe(take(1)).subscribe(event => {
196
+ stopWatching();
197
+ removeAriaReference(anchor, "aria-describedby", this.tooltipId);
198
+ this.#intent.closed(anchor, event.via === PopupCloseSource.Escape);
199
+ });
200
+ popupRef.closed.pipe(take(1)).subscribe(() => {
201
+ if (this.#popupRef === popupRef) {
202
+ this.#popupRef = null;
319
203
  }
320
- this.#eventSubscription = composite;
321
- }
322
- else {
323
- const element = this.#getAnchorElement(target);
324
- if (element) {
325
- this.#eventSubscription = this.#subscribeToElement(element);
204
+ if (!this.#destroyed) {
205
+ this.hidden.emit();
326
206
  }
327
- }
328
- }
329
- #subscribeToElement(element) {
330
- const composite = new Subscription();
331
- composite.add(fromEvent(element, "pointerenter")
332
- .pipe(takeUntilDestroyed(this.#destroyRef))
333
- .subscribe(() => this.#handleShow(element)));
334
- composite.add(fromEvent(element, "pointerleave")
335
- .pipe(takeUntilDestroyed(this.#destroyRef))
336
- .subscribe(() => this.#handleHide()));
337
- composite.add(fromEvent(element, "focusin")
338
- .pipe(takeUntilDestroyed(this.#destroyRef))
339
- .subscribe(() => this.#handleShow(element)));
340
- composite.add(fromEvent(element, "focusout")
341
- .pipe(takeUntilDestroyed(this.#destroyRef))
342
- .subscribe(() => this.#handleHide()));
343
- return composite;
207
+ });
344
208
  }
345
209
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TooltipComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
346
210
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.6", type: TooltipComponent, isStandalone: true, selector: "mona-tooltip", inputs: { disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, hideDelay: { classPropertyName: "hideDelay", publicName: "hideDelay", isSignal: true, isRequired: false, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, showDelay: { classPropertyName: "showDelay", publicName: "showDelay", isSignal: true, isRequired: false, transformFunction: null }, target: { classPropertyName: "target", publicName: "target", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { hidden: "hidden", shown: "shown" }, viewQueries: [{ propertyName: "templateRef", first: true, predicate: TemplateRef, descendants: true, isSignal: true }], ngImport: i0, template: "<ng-template>\n <div role=\"tooltip\" [id]=\"tooltipId\" [class]=\"baseClasses()\">\n <div>\n <ng-content></ng-content>\n </div>\n <div [class]=\"arrowClasses()\" [attr.data-position]=\"currentArrowPosition()\"></div>\n </div>\n</ng-template>\n", styles: [":host{display:contents}\n"] }); }
@@ -350,66 +214,83 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
350
214
  args: [{ selector: "mona-tooltip", template: "<ng-template>\n <div role=\"tooltip\" [id]=\"tooltipId\" [class]=\"baseClasses()\">\n <div>\n <ng-content></ng-content>\n </div>\n <div [class]=\"arrowClasses()\" [attr.data-position]=\"currentArrowPosition()\"></div>\n </div>\n</ng-template>\n", styles: [":host{display:contents}\n"] }]
351
215
  }], ctorParameters: () => [], propDecorators: { templateRef: [{ type: i0.ViewChild, args: [i0.forwardRef(() => TemplateRef), { isSignal: true }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], hidden: [{ type: i0.Output, args: ["hidden"] }], hideDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "hideDelay", required: false }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], showDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "showDelay", required: false }] }], shown: [{ type: i0.Output, args: ["shown"] }], target: [{ type: i0.Input, args: [{ isSignal: true, alias: "target", required: true }] }] } });
352
216
 
217
+ /** The gap between a tooltip and its anchor, leaving room for the arrow. */
218
+ const TOOLTIP_GAP = 12;
219
+ /** Where the directive keeps an element's `title`, so the browser's own tooltip never shows next to it. */
220
+ const TITLE_ATTRIBUTE = "data-mona-title";
353
221
  class TooltipDirective {
354
222
  #destroyRef;
223
+ #directionality;
355
224
  #host;
356
225
  #injector;
226
+ #intent;
227
+ /** Elements named by their title, which the directive labels with `aria-label` once the title has moved. */
228
+ #labelled;
357
229
  #popupService;
358
- #renderer;
359
- #selfTitleWrites;
360
- #currentAnchor;
361
- #hideTimeoutId;
362
- #mutationObserver;
363
- #popupRef;
364
- #showTimeoutId;
365
- #subscription;
230
+ #stripped;
366
231
  #tooltipId;
232
+ #destroyed;
233
+ #popupRef;
367
234
  constructor() {
368
235
  this.#destroyRef = inject(DestroyRef);
369
- this.#host = inject((ElementRef));
236
+ this.#directionality = inject(Directionality, { optional: true });
237
+ this.#host = inject(ElementRef);
370
238
  this.#injector = inject(EnvironmentInjector);
239
+ this.#intent = new HoverIntent({
240
+ hide: () => this.#popupRef?.close(),
241
+ hideDelay: () => this.hideDelay(),
242
+ show: anchor => this.#open(anchor),
243
+ showDelay: () => this.showDelay()
244
+ });
245
+ /** Elements named by their title, which the directive labels with `aria-label` once the title has moved. */
246
+ this.#labelled = new Set();
371
247
  this.#popupService = inject(PopupService);
372
- this.#renderer = inject(Renderer2);
373
- this.#selfTitleWrites = new Map();
374
- this.#currentAnchor = null;
375
- this.#hideTimeoutId = null;
376
- this.#mutationObserver = null;
377
- this.#popupRef = null;
378
- this.#showTimeoutId = null;
379
- this.#subscription = null;
248
+ this.#stripped = new Set();
380
249
  this.#tooltipId = createElementControlId();
381
- this.originalTitle = signal("", /* @ts-ignore */
382
- ...(ngDevMode ? [{ debugName: "originalTitle" }] : /* istanbul ignore next */ []));
250
+ this.#destroyed = false;
251
+ this.#popupRef = null;
383
252
  /**
384
- * @description Whether the tooltip is disabled. When disabled, the tooltip will not be shown.
253
+ * @description Whether the tooltip is disabled. When disabled, the tooltip will not be shown, and an open one
254
+ * closes.
385
255
  * @default false
386
256
  */
387
257
  this.disabled = input(false, /* @ts-ignore */
388
258
  ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
389
259
  /**
390
260
  * @description The filter to select elements that will have tooltips.
391
- * It can be a CSS selector that matches elements within the host element.
261
+ * It can be a CSS selector that matches elements within the host element, including ones added later.
392
262
  * Only applies when `mode` is set to `content`.
393
263
  * @default "[title]"
394
264
  */
395
265
  this.filter = input("[title]", /* @ts-ignore */
396
266
  ...(ngDevMode ? [{ debugName: "filter" }] : /* istanbul ignore next */ []));
397
267
  /**
398
- * @description The delay in milliseconds before hiding the tooltip.
268
+ * @description Emitted when the tooltip popup is hidden.
269
+ */
270
+ this.hidden = output();
271
+ /**
272
+ * @description The delay in milliseconds before hiding the tooltip after the pointer or focus leaves. A pointer
273
+ * that leaves always gets a short grace, so it can move onto the tooltip.
399
274
  * @default 0
400
275
  */
401
276
  this.hideDelay = input(0, /* @ts-ignore */
402
277
  ...(ngDevMode ? [{ debugName: "hideDelay" }] : /* istanbul ignore next */ []));
403
278
  /**
404
279
  * @description The mode of the tooltip.
405
- * "host" mode receives the tooltip from the host element's title attribute.
280
+ * "host" mode shows the host's tooltip content, or its title attribute.
406
281
  * "content" mode uses the title attribute of elements matching the filter.
407
282
  * @default "host"
408
283
  */
409
284
  this.mode = input("host", /* @ts-ignore */
410
285
  ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
411
286
  /**
412
- * @description The position of the tooltip relative to the target element.
287
+ * @description The tooltip's content in host mode: text, or a template. Without it, the host's `title` is shown.
288
+ */
289
+ this.monaTooltip = input("", /* @ts-ignore */
290
+ ...(ngDevMode ? [{ debugName: "monaTooltip" }] : /* istanbul ignore next */ []));
291
+ /**
292
+ * @description The side of the target the tooltip opens on. `left` and `right` are physical; `start` and `end`
293
+ * follow the text direction. It flips to the opposite side when there isn't room.
413
294
  * @default "top"
414
295
  */
415
296
  this.position = input("top", /* @ts-ignore */
@@ -425,237 +306,156 @@ class TooltipDirective {
425
306
  */
426
307
  this.showDelay = input(0, /* @ts-ignore */
427
308
  ...(ngDevMode ? [{ debugName: "showDelay" }] : /* istanbul ignore next */ []));
428
- /**
429
- * @description Emitted when the tooltip popup is hidden.
430
- */
431
- this.hidden = output();
432
309
  /**
433
310
  * @description Emitted when the tooltip popup is shown.
434
311
  */
435
312
  this.shown = output();
436
- afterRenderEffect({
437
- read: () => {
438
- this.mode();
439
- this.position();
440
- this.#currentAnchor = null;
441
- this.#popupRef?.close();
442
- this.#refreshSubscription();
443
- this.#mutationObserver?.disconnect();
444
- this.#mutationObserver = null;
445
- if (this.mode() === "content") {
446
- this.#mutationObserver = new MutationObserver(records => this.#onMutations(records));
447
- this.#mutationObserver.observe(this.#host.nativeElement, {
448
- attributeFilter: ["title"],
449
- attributes: true,
450
- childList: true,
451
- subtree: true
452
- });
313
+ effect(onCleanup => {
314
+ const mode = this.mode();
315
+ const filter = this.filter();
316
+ this.position();
317
+ const stop = untracked(() => this.#listen(mode, filter));
318
+ onCleanup(() => {
319
+ stop();
320
+ this.#intent.hideNow();
321
+ });
322
+ });
323
+ effect(() => {
324
+ if (this.disabled()) {
325
+ untracked(() => this.#intent.hideNow());
326
+ }
327
+ });
328
+ // The host's title moves aside at once, so the browser's tooltip never shows for it.
329
+ afterNextRender({
330
+ write: () => {
331
+ if (this.mode() === "host") {
332
+ this.#textOf(this.#host.nativeElement);
453
333
  }
454
334
  }
455
335
  });
456
336
  this.#destroyRef.onDestroy(() => {
457
- if (this.#showTimeoutId != null) {
458
- clearTimeout(this.#showTimeoutId);
459
- this.#showTimeoutId = null;
460
- }
461
- if (this.#hideTimeoutId != null) {
462
- clearTimeout(this.#hideTimeoutId);
463
- this.#hideTimeoutId = null;
464
- }
465
- this.#mutationObserver?.disconnect();
466
- this.#mutationObserver = null;
337
+ this.#destroyed = true;
338
+ this.#intent.dispose();
467
339
  this.#popupRef?.close();
340
+ for (const element of this.#stripped) {
341
+ const title = element.getAttribute(TITLE_ATTRIBUTE);
342
+ element.removeAttribute(TITLE_ATTRIBUTE);
343
+ if (this.#labelled.has(element) && element.getAttribute("aria-label") === title) {
344
+ element.removeAttribute("aria-label");
345
+ }
346
+ if (title != null && !element.hasAttribute("title")) {
347
+ element.setAttribute("title", title);
348
+ }
349
+ }
350
+ this.#labelled.clear();
351
+ this.#stripped.clear();
468
352
  });
469
353
  }
470
- #createTooltip(text, anchor) {
471
- this.#currentAnchor = anchor;
472
- const component = this.#createTooltipTemplate(text);
473
- if (!component) {
354
+ #listen(mode, filter) {
355
+ const host = this.#host.nativeElement;
356
+ if (mode === "host") {
357
+ return listenForHover(host, node => (host.contains(node) ? host : null), this.#intent);
358
+ }
359
+ // Elements whose title the directive has already moved aside no longer match a `[title]` filter.
360
+ const selector = `${filter}, [${TITLE_ATTRIBUTE}]`;
361
+ return listenForHover(host, node => {
362
+ const match = node.closest(selector);
363
+ return match && match !== host && host.contains(match) ? match : null;
364
+ }, this.#intent);
365
+ }
366
+ #open(anchor) {
367
+ if (this.disabled() || this.#destroyed) {
474
368
  return;
475
369
  }
476
- const connectionPoints = getPositionConnectionPoints(this.position());
477
- const offset = getOffsetForPosition(this.position(), true);
370
+ const content = this.mode() === "host" ? this.monaTooltip() || this.#textOf(anchor) : this.#textOf(anchor);
371
+ if (!content) {
372
+ return;
373
+ }
374
+ const direction = resolveComponentDirection(anchor, this.#directionality);
375
+ const side = resolveOverlaySide(this.position(), direction);
376
+ const component = createComponent(TooltipTemplateComponent, { environmentInjector: this.#injector });
377
+ component.setInput("content", content);
378
+ component.setInput("rounded", this.rounded());
379
+ component.setInput("tooltipId", this.#tooltipId);
380
+ component.instance.currentArrowPosition.set(side);
381
+ component.changeDetectorRef.detectChanges();
478
382
  const popupRef = this.#popupService.create({
479
383
  anchor,
480
- anchorConnectionPoint: connectionPoints.anchor,
481
384
  animation: fadePopupAnimation,
482
385
  closeOnEscape: true,
483
386
  closeOnMouseLeave: false,
484
387
  closeOnOutsideClick: true,
485
388
  content: component.instance.templateRef(),
486
389
  hasBackdrop: false,
487
- popupConnectionPoint: connectionPoints.popup,
488
- offset,
390
+ positions: overlaySidePositions(side, TOOLTIP_GAP, direction),
489
391
  restoreFocus: false,
490
392
  withPush: false
491
393
  });
492
394
  this.#popupRef = popupRef;
493
- this.#renderer.setAttribute(anchor, "aria-describedby", this.#tooltipId);
494
- popupRef.opened.pipe(take(1)).subscribe(() => this.shown.emit());
495
- popupRef.positionChanges
496
- .pipe(takeUntil(popupRef.closed), takeUntilDestroyed(this.#destroyRef))
497
- .subscribe(connectionPair => {
498
- const newArrowPosition = getArrowPositionFromConnectionPair(connectionPair);
499
- component.instance.currentArrowPosition.set(newArrowPosition);
395
+ addAriaReference(anchor, "aria-describedby", this.#tooltipId);
396
+ this.#intent.opened(anchor, popupRef.overlayRef.overlayElement);
397
+ const stopWatching = onDisconnect(anchor, () => popupRef.close());
398
+ popupRef.opened.pipe(take(1)).subscribe(() => {
399
+ if (!this.#destroyed) {
400
+ this.shown.emit();
401
+ }
402
+ });
403
+ popupRef.positionChanges.pipe(takeUntil(popupRef.closeStart)).subscribe(position => {
404
+ component.instance.currentArrowPosition.set(sideOfPosition(position, direction));
405
+ });
406
+ popupRef.closeStart.pipe(take(1)).subscribe(event => {
407
+ stopWatching();
408
+ removeAriaReference(anchor, "aria-describedby", this.#tooltipId);
409
+ this.#intent.closed(anchor, event.via === PopupCloseSource.Escape);
500
410
  });
501
411
  popupRef.closed.pipe(take(1)).subscribe(() => {
502
412
  if (this.#popupRef === popupRef) {
503
413
  this.#popupRef = null;
504
- this.#currentAnchor = null;
505
414
  }
506
- this.#renderer.removeAttribute(anchor, "aria-describedby");
507
- this.#markSelfTitleWrite(anchor);
508
- this.#renderer.setAttribute(anchor, "title", text);
509
415
  component.destroy();
510
- this.hidden.emit();
511
- });
512
- }
513
- #createTooltipTemplate(text) {
514
- if (!text) {
515
- return null;
516
- }
517
- const component = createComponent(TooltipTemplateComponent, {
518
- environmentInjector: this.#injector
519
- });
520
- component.setInput("content", text);
521
- component.setInput("position", this.position());
522
- component.setInput("rounded", this.rounded());
523
- component.setInput("tooltipId", this.#tooltipId);
524
- return component;
525
- }
526
- #handleHide() {
527
- if (!this.#popupRef) {
528
- return;
529
- }
530
- const hideDelay = this.hideDelay();
531
- if (hideDelay > 0) {
532
- const popupRef = this.#popupRef;
533
- this.#hideTimeoutId = setTimeout(() => {
534
- this.#hideTimeoutId = null;
535
- if (this.#popupRef === popupRef) {
536
- popupRef.close();
537
- }
538
- }, hideDelay);
539
- }
540
- else {
541
- this.#popupRef.close();
542
- }
543
- }
544
- #handleShow(targetElement) {
545
- if (this.disabled()) {
546
- return;
547
- }
548
- if (this.#popupRef && this.#currentAnchor === targetElement) {
549
- return;
550
- }
551
- this.#popupRef?.close();
552
- const title = targetElement.getAttribute("title") || "";
553
- if (title) {
554
- this.#markSelfTitleWrite(targetElement);
555
- }
556
- this.#renderer.removeAttribute(targetElement, "title");
557
- if (this.mode() === "host") {
558
- this.originalTitle.set(title);
559
- }
560
- if (title) {
561
- const showDelay = this.showDelay();
562
- if (showDelay > 0) {
563
- this.#showTimeoutId = setTimeout(() => {
564
- this.#showTimeoutId = null;
565
- if (!this.#popupRef || this.#currentAnchor !== targetElement) {
566
- this.#createTooltip(title, targetElement);
567
- }
568
- }, showDelay);
569
- }
570
- else {
571
- this.#createTooltip(title, targetElement);
416
+ if (!this.#destroyed) {
417
+ this.hidden.emit();
572
418
  }
573
- }
419
+ });
574
420
  }
575
421
  /**
576
- * The directive strips a `title` while its tooltip is open and restores it on close. Those writes
577
- * reach the observer too, so each one is booked ahead of time and cancelled out here — otherwise
578
- * showing a tooltip would tear down and rebuild the very subscriptions driving it.
422
+ * The tooltip text of an element. A `title` set on it (again) moves to `data-mona-title`, where it stays for
423
+ * the directive's lifetime and is put back when the directive is destroyed. An element that has no other name,
424
+ * such as an icon-only button, keeps the title as its name through `aria-label`.
579
425
  */
580
- #isSelfTitleWrite(element) {
581
- const pending = this.#selfTitleWrites.get(element) ?? 0;
582
- if (pending <= 0) {
583
- return false;
584
- }
585
- if (pending === 1) {
586
- this.#selfTitleWrites.delete(element);
587
- }
588
- else {
589
- this.#selfTitleWrites.set(element, pending - 1);
590
- }
591
- return true;
592
- }
593
- #markSelfTitleWrite(element) {
594
- this.#selfTitleWrites.set(element, (this.#selfTitleWrites.get(element) ?? 0) + 1);
595
- }
596
- #onMutations(records) {
597
- // Mapped rather than short circuited, so every self inflicted record is still cancelled out.
598
- const externalChanges = records.map(record => {
599
- if (record.type !== "attributes") {
600
- return true;
601
- }
602
- if (record.attributeName !== "title") {
603
- return false;
426
+ #textOf(element) {
427
+ const title = element.getAttribute("title");
428
+ if (title != null) {
429
+ const namedByTitle = this.#labelled.has(element) || !hasNameOfItsOwn(element);
430
+ element.setAttribute(TITLE_ATTRIBUTE, title);
431
+ element.removeAttribute("title");
432
+ this.#stripped.add(element);
433
+ if (namedByTitle && title.trim()) {
434
+ element.setAttribute("aria-label", title);
435
+ this.#labelled.add(element);
604
436
  }
605
- return !this.#isSelfTitleWrite(record.target);
606
- });
607
- if (externalChanges.some(Boolean)) {
608
- this.#refreshSubscription();
609
437
  }
610
- }
611
- #refreshSubscription() {
612
- if (this.#subscription) {
613
- this.#subscription.unsubscribe();
614
- this.#subscription = null;
615
- }
616
- this.#setSubscription();
617
- }
618
- #setSubscription() {
619
- const composite = new Subscription();
620
- let elements;
621
- if (this.mode() === "host") {
622
- elements = [this.#host.nativeElement];
623
- }
624
- else {
625
- elements = Array.from(this.#host.nativeElement.querySelectorAll(this.filter()));
626
- }
627
- composite.add(fromEvent(elements, "pointerenter")
628
- .pipe(tap(event => {
629
- const targetElement = event.currentTarget;
630
- this.#handleShow(targetElement);
631
- }), takeUntilDestroyed(this.#destroyRef))
632
- .subscribe());
633
- composite.add(fromEvent(elements, "pointerleave")
634
- .pipe(tap(() => this.#handleHide()), takeUntilDestroyed(this.#destroyRef))
635
- .subscribe());
636
- composite.add(fromEvent(elements, "focusin")
637
- .pipe(tap(event => {
638
- const targetElement = event.currentTarget;
639
- this.#handleShow(targetElement);
640
- }), takeUntilDestroyed(this.#destroyRef))
641
- .subscribe());
642
- composite.add(fromEvent(elements, "focusout")
643
- .pipe(tap(() => this.#handleHide()), takeUntilDestroyed(this.#destroyRef))
644
- .subscribe());
645
- this.#subscription = composite;
438
+ return element.getAttribute(TITLE_ATTRIBUTE) ?? "";
646
439
  }
647
440
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TooltipDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
648
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.6", type: TooltipDirective, isStandalone: true, selector: "[monaTooltip]", inputs: { disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, filter: { classPropertyName: "filter", publicName: "filter", isSignal: true, isRequired: false, transformFunction: null }, hideDelay: { classPropertyName: "hideDelay", publicName: "hideDelay", isSignal: true, isRequired: false, transformFunction: null }, mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "tooltipRounded", isSignal: true, isRequired: false, transformFunction: null }, showDelay: { classPropertyName: "showDelay", publicName: "showDelay", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { hidden: "hidden", shown: "shown" }, host: { properties: { "attr.data-mona-title": "originalTitle()" } }, ngImport: i0 }); }
441
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.6", type: TooltipDirective, isStandalone: true, selector: "[monaTooltip]", inputs: { disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, filter: { classPropertyName: "filter", publicName: "filter", isSignal: true, isRequired: false, transformFunction: null }, hideDelay: { classPropertyName: "hideDelay", publicName: "hideDelay", isSignal: true, isRequired: false, transformFunction: null }, mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, monaTooltip: { classPropertyName: "monaTooltip", publicName: "monaTooltip", isSignal: true, isRequired: false, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "tooltipRounded", isSignal: true, isRequired: false, transformFunction: null }, showDelay: { classPropertyName: "showDelay", publicName: "showDelay", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { hidden: "hidden", shown: "shown" }, ngImport: i0 }); }
649
442
  }
650
443
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TooltipDirective, decorators: [{
651
444
  type: Directive,
652
445
  args: [{
653
- selector: "[monaTooltip]",
654
- host: {
655
- "[attr.data-mona-title]": "originalTitle()"
656
- }
446
+ selector: "[monaTooltip]"
657
447
  }]
658
- }], ctorParameters: () => [], propDecorators: { disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], filter: [{ type: i0.Input, args: [{ isSignal: true, alias: "filter", required: false }] }], hideDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "hideDelay", required: false }] }], mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipRounded", required: false }] }], showDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "showDelay", required: false }] }], hidden: [{ type: i0.Output, args: ["hidden"] }], shown: [{ type: i0.Output, args: ["shown"] }] } });
448
+ }], ctorParameters: () => [], propDecorators: { disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], filter: [{ type: i0.Input, args: [{ isSignal: true, alias: "filter", required: false }] }], hidden: [{ type: i0.Output, args: ["hidden"] }], hideDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "hideDelay", required: false }] }], mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], monaTooltip: [{ type: i0.Input, args: [{ isSignal: true, alias: "monaTooltip", required: false }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipRounded", required: false }] }], showDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "showDelay", required: false }] }], shown: [{ type: i0.Output, args: ["shown"] }] } });
449
+ /** Whether an element is named by something other than its `title`: a label attribute, or text or images inside. */
450
+ function hasNameOfItsOwn(element) {
451
+ if (element.hasAttribute("aria-labelledby") || element.getAttribute("aria-label")?.trim()) {
452
+ return true;
453
+ }
454
+ if (element.labels?.length) {
455
+ return true;
456
+ }
457
+ return !!element.textContent?.trim() || element.querySelector('img[alt]:not([alt=""])') != null;
458
+ }
659
459
  class TooltipTemplateComponent {
660
460
  constructor() {
661
461
  this.arrowClasses = computed(() => {
@@ -669,59 +469,102 @@ class TooltipTemplateComponent {
669
469
  return twMerge(variants, userClasses);
670
470
  }, /* @ts-ignore */
671
471
  ...(ngDevMode ? [{ debugName: "baseClasses" }] : /* istanbul ignore next */ []));
672
- this.currentArrowPosition = linkedSignal(() => this.position(), /* @ts-ignore */
673
- ...(ngDevMode ? [{ debugName: "currentArrowPosition" }] : /* istanbul ignore next */ []));
472
+ this.contentTemplate = computed(() => {
473
+ const content = this.content();
474
+ return content instanceof TemplateRef ? content : null;
475
+ }, /* @ts-ignore */
476
+ ...(ngDevMode ? [{ debugName: "contentTemplate" }] : /* istanbul ignore next */ []));
674
477
  /**
675
- * @description The text content displayed in the tooltip.
478
+ * @description The content displayed in the tooltip: text or a template.
676
479
  */
677
480
  this.content = input.required(/* @ts-ignore */
678
481
  ...(ngDevMode ? [{ debugName: "content" }] : /* istanbul ignore next */ []));
679
- /**
680
- * @description The position of the tooltip relative to the target element.
681
- */
682
- this.position = input("top", /* @ts-ignore */
683
- ...(ngDevMode ? [{ debugName: "position" }] : /* istanbul ignore next */ []));
482
+ this.currentArrowPosition = signal("top", /* @ts-ignore */
483
+ ...(ngDevMode ? [{ debugName: "currentArrowPosition" }] : /* istanbul ignore next */ []));
684
484
  /**
685
485
  * @description The border radius of the tooltip.
686
486
  */
687
487
  this.rounded = input("medium", /* @ts-ignore */
688
488
  ...(ngDevMode ? [{ debugName: "rounded" }] : /* istanbul ignore next */ []));
489
+ this.templateRef = viewChild.required(TemplateRef, /* @ts-ignore */
490
+ ...(ngDevMode ? [{ debugName: "templateRef" }] : /* istanbul ignore next */ []));
689
491
  /**
690
492
  * @description The unique id for the tooltip element, used for aria-describedby linkage.
691
493
  */
692
494
  this.tooltipId = input("", /* @ts-ignore */
693
495
  ...(ngDevMode ? [{ debugName: "tooltipId" }] : /* istanbul ignore next */ []));
694
- this.templateRef = viewChild.required(TemplateRef, /* @ts-ignore */
695
- ...(ngDevMode ? [{ debugName: "templateRef" }] : /* istanbul ignore next */ []));
696
496
  }
697
497
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TooltipTemplateComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
698
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "22.0.6", type: TooltipTemplateComponent, isStandalone: true, selector: "ng-component", inputs: { content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: true, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, tooltipId: { classPropertyName: "tooltipId", publicName: "tooltipId", isSignal: true, isRequired: false, transformFunction: null } }, viewQueries: [{ propertyName: "templateRef", first: true, predicate: TemplateRef, descendants: true, isSignal: true }], ngImport: i0, template: `
498
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: TooltipTemplateComponent, isStandalone: true, selector: "ng-component", inputs: { content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: true, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, tooltipId: { classPropertyName: "tooltipId", publicName: "tooltipId", isSignal: true, isRequired: false, transformFunction: null } }, viewQueries: [{ propertyName: "templateRef", first: true, predicate: TemplateRef, descendants: true, isSignal: true }], ngImport: i0, template: `
699
499
  <ng-template>
700
500
  <div role="tooltip" [id]="tooltipId()" [class]="baseClasses()">
701
501
  <div>
702
- {{ content() }}
502
+ @if (contentTemplate(); as template) {
503
+ <ng-container [ngTemplateOutlet]="template"></ng-container>
504
+ } @else {
505
+ {{ content() }}
506
+ }
703
507
  </div>
704
508
  <div [class]="arrowClasses()" [attr.data-position]="currentArrowPosition()"></div>
705
509
  </div>
706
510
  </ng-template>
707
- `, isInline: true, changeDetection: i0.ChangeDetectionStrategy.Eager }); }
511
+ `, isInline: true, dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }] }); }
708
512
  }
709
513
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TooltipTemplateComponent, decorators: [{
710
514
  type: Component,
711
515
  args: [{
712
- changeDetection: ChangeDetectionStrategy.Eager,
516
+ imports: [NgTemplateOutlet],
713
517
  template: `
714
518
  <ng-template>
715
519
  <div role="tooltip" [id]="tooltipId()" [class]="baseClasses()">
716
520
  <div>
717
- {{ content() }}
521
+ @if (contentTemplate(); as template) {
522
+ <ng-container [ngTemplateOutlet]="template"></ng-container>
523
+ } @else {
524
+ {{ content() }}
525
+ }
718
526
  </div>
719
527
  <div [class]="arrowClasses()" [attr.data-position]="currentArrowPosition()"></div>
720
528
  </div>
721
529
  </ng-template>
722
530
  `
723
531
  }]
724
- }], propDecorators: { content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: true }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], tooltipId: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipId", required: false }] }], templateRef: [{ type: i0.ViewChild, args: [i0.forwardRef(() => TemplateRef), { isSignal: true }] }] } });
532
+ }], propDecorators: { content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: true }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], templateRef: [{ type: i0.ViewChild, args: [i0.forwardRef(() => TemplateRef), { isSignal: true }] }], tooltipId: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltipId", required: false }] }] } });
533
+
534
+ /**
535
+ * Gets the appropriate offset for a tooltip based on its position.
536
+ * The offset ensures proper spacing between the tooltip and its anchor element.
537
+ * @deprecated No longer used by the tooltip or popover, which keep the gap on the side they flip to and place
538
+ * `left` and `right` physically in RTL. Kept for existing callers.
539
+ */
540
+ function getOffsetForPosition(position, arrowVisible) {
541
+ const arrowOffset = arrowVisible ? 12 : 4;
542
+ switch (position) {
543
+ case "top":
544
+ return { horizontal: 0, vertical: -arrowOffset };
545
+ case "bottom":
546
+ return { horizontal: 0, vertical: arrowOffset };
547
+ case "right":
548
+ return { horizontal: arrowOffset, vertical: 0 };
549
+ case "left":
550
+ return { horizontal: -arrowOffset, vertical: 0 };
551
+ }
552
+ }
553
+ /**
554
+ * @deprecated No longer used by the tooltip or popover. Kept for existing callers.
555
+ */
556
+ function getPositionConnectionPoints(position) {
557
+ switch (position) {
558
+ case "top":
559
+ return { anchor: "topcenter", popup: "bottomcenter" };
560
+ case "bottom":
561
+ return { anchor: "bottomcenter", popup: "topcenter" };
562
+ case "right":
563
+ return { anchor: "centerright", popup: "centerleft" };
564
+ case "left":
565
+ return { anchor: "centerleft", popup: "centerright" };
566
+ }
567
+ }
725
568
 
726
569
  /*
727
570
  * Public API Surface of @nanahoshi/mona-ui/tooltip