ember-attacher 4.4.0 → 5.0.0-beta.2

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 (50) hide show
  1. package/README.md +416 -0
  2. package/dist/{attacher-core-m7x5g04q.js → attacher-core-DIAMEQR6.js} +1001 -978
  3. package/dist/attacher-core-DIAMEQR6.js.map +1 -0
  4. package/dist/attacher-overlay-BCAfauc_.js +40 -0
  5. package/dist/attacher-overlay-BCAfauc_.js.map +1 -0
  6. package/dist/components/attach-popover.d.ts +10 -12
  7. package/dist/components/attach-popover.js +7 -4
  8. package/dist/components/attach-popover.js.map +1 -1
  9. package/dist/components/attach-tooltip.d.ts +11 -13
  10. package/dist/components/attach-tooltip.js +10 -7
  11. package/dist/components/attach-tooltip.js.map +1 -1
  12. package/dist/components/attacher.d.ts +12 -12
  13. package/dist/components/attacher.js +7 -15
  14. package/dist/components/attacher.js.map +1 -1
  15. package/dist/defaults.d.ts +27 -28
  16. package/dist/defaults.js +11 -11
  17. package/dist/defaults.js.map +1 -1
  18. package/dist/index.d.ts +9 -60
  19. package/dist/index.js +13 -3
  20. package/dist/index.js.map +1 -1
  21. package/dist/{is-visible-DQGdmVDv.js → is-visible-CeN9qZyc.js} +6 -3
  22. package/dist/is-visible-CeN9qZyc.js.map +1 -0
  23. package/dist/lib/a11y.d.ts +77 -0
  24. package/dist/lib/attacher-core.d.ts +342 -0
  25. package/dist/lib/attacher-overlay.d.ts +18 -0
  26. package/dist/lib/attachment-tree.d.ts +32 -0
  27. package/dist/lib/delay-group.d.ts +15 -0
  28. package/dist/lib/dom.d.ts +40 -0
  29. package/dist/lib/host.d.ts +21 -0
  30. package/dist/lib/positioning.d.ts +27 -0
  31. package/dist/lib/schedule.d.ts +12 -0
  32. package/dist/lib/singleton-tooltip-pool.d.ts +32 -0
  33. package/dist/lib/target-resolution.d.ts +44 -0
  34. package/dist/modifiers/tooltip.d.ts +18 -15
  35. package/dist/modifiers/tooltip.js +55 -67
  36. package/dist/modifiers/tooltip.js.map +1 -1
  37. package/dist/styles/ember-attacher.css +1 -1
  38. package/dist/template-registry.d.ts +7 -11
  39. package/dist/test-support/assert-attached.d.ts +27 -0
  40. package/dist/test-support/index.d.ts +2 -2
  41. package/dist/test-support/index.js +95 -1
  42. package/dist/test-support/index.js.map +1 -1
  43. package/dist/test-support/is-visible.d.ts +1 -2
  44. package/package.json +18 -7
  45. package/dist/_app_/components/basic-attacher.js +0 -1
  46. package/dist/attacher-core-m7x5g04q.js.map +0 -1
  47. package/dist/components/basic-attacher.d.ts +0 -151
  48. package/dist/components/basic-attacher.js +0 -44
  49. package/dist/components/basic-attacher.js.map +0 -1
  50. package/dist/is-visible-DQGdmVDv.js.map +0 -1
@@ -1,14 +1,11 @@
1
- import { schedule, cancel, later, next, debounce, run } from '@ember/runloop';
2
1
  import { getOwner } from '@ember/application';
3
- import { guidFor } from '@ember/object/internals';
4
2
  import { isDestroying, isDestroyed, registerDestructor } from '@ember/destroyable';
5
- import { isHTMLSafe } from '@ember/template';
6
- import { runInDebug, warn, assert, deprecate } from '@ember/debug';
3
+ import { runInDebug, warn, assert } from '@ember/debug';
7
4
  import { arrow, flip, shift, limitShift, autoUpdate, computePosition } from '@floating-ui/dom';
8
- import { buildWaiter } from '@ember/test-waiters';
9
5
  import { tracked } from '@glimmer/tracking';
10
6
  import Modifier, { modifier } from 'ember-modifier';
11
- import DEFAULTS from './defaults.js';
7
+ import DEFAULTS, { POPOVER_DEFAULTS } from './defaults.js';
8
+ import { buildWaiter } from '@ember/test-waiters';
12
9
 
13
10
  function _applyDecoratedDescriptor(i, e, r, n, l) {
14
11
  var a = {};
@@ -28,20 +25,97 @@ function _initializerDefineProperty(e, i, r, l) {
28
25
  }
29
26
 
30
27
  /**
31
- * Accessibility and ARIA attribute management for BasicAttacher.
28
+ * Accessibility and ARIA attribute management for ember-attacher.
32
29
  *
33
- * Manages token-safe open-only `aria-describedby` for tooltips, automatic
34
- * disclosure attributes (`aria-expanded`, `aria-controls`, `aria-haspopup`)
35
- * for popovers when not supplied by callers, and focus restoration on Escape.
30
+ * Implements modern-web-guidance smart tooltip ARIA:
31
+ * - Binds token-safe `aria-labelledby` when a trigger has no accessible name of its own.
32
+ * - Suppresses `aria-describedby` when the tooltip text duplicates the trigger's accessible name.
33
+ * - Otherwise binds token-safe open-only `aria-describedby` for tooltips, and automatic
34
+ * disclosure attributes (`aria-expanded`, `aria-controls`, `aria-haspopup`) for popovers.
35
+ * - Restores focus on Escape when focus lives inside an interactive popover.
36
36
  */
37
37
 
38
38
  const KNOWN_HASPOPUP_ROLES = new Set(['dialog', 'menu', 'listbox', 'tree', 'grid', 'true', 'false']);
39
39
  function splitTokens(value) {
40
40
  return value ? value.trim().split(/\s+/).filter(Boolean) : [];
41
41
  }
42
+ function normalizeText(value) {
43
+ return value ? String(value).replace(/\s+/g, ' ').trim() : '';
44
+ }
45
+ function collectAccessibleText(node, ignoreId) {
46
+ if (!node) {
47
+ return '';
48
+ }
49
+ if (node.nodeType === 3 /* Node.TEXT_NODE */) {
50
+ return node.nodeValue || '';
51
+ }
52
+ if (node.nodeType !== 1 /* Node.ELEMENT_NODE */) {
53
+ return '';
54
+ }
55
+ const el = node;
56
+ if (ignoreId && el.id === ignoreId || el.classList?.contains('ember-attacher') || el.getAttribute('aria-hidden') === 'true' || el.hidden) {
57
+ return '';
58
+ }
59
+ const tag = el.tagName ? el.tagName.toLowerCase() : '';
60
+ if (tag === 'img' || tag === 'area') {
61
+ return ` ${el.getAttribute('alt') || ''} `;
62
+ }
63
+ if (tag === 'input') {
64
+ const type = (el.getAttribute('type') || '').toLowerCase();
65
+ if (type === 'button' || type === 'submit' || type === 'reset') {
66
+ return ` ${el.getAttribute('value') || ''} `;
67
+ }
68
+ return '';
69
+ }
70
+ if (tag === 'svg') {
71
+ const svgLabel = el.getAttribute('aria-label');
72
+ if (svgLabel) {
73
+ return ` ${svgLabel} `;
74
+ }
75
+ const titleEl = el.querySelector('title');
76
+ return titleEl ? ` ${titleEl.textContent || ''} ` : '';
77
+ }
78
+ let text = '';
79
+ const children = el.childNodes;
80
+ for (let i = 0; i < children.length; i += 1) {
81
+ text += collectAccessibleText(children[i], ignoreId);
82
+ }
83
+ return text;
84
+ }
42
85
 
43
86
  /**
44
- * Tracks and restores ARIA attributes owned by a single BasicAttacher instance
87
+ * Resolve a target Element's accessible name per modern-web-guidance rules
88
+ * (`aria-labelledby` excluding `ignoreId`, `aria-label`, text/alt content, `title`).
89
+ *
90
+ * @param {Element | null} target
91
+ * @param {string | null} [ignoreId]
92
+ * @returns {string}
93
+ */
94
+ function getTargetAccessibleName(target, ignoreId = null) {
95
+ if (!target || typeof target.getAttribute !== 'function') {
96
+ return '';
97
+ }
98
+ const doc = target.ownerDocument || (typeof document !== 'undefined' ? document : null);
99
+ const labelledByIds = splitTokens(target.getAttribute('aria-labelledby')).filter(token => token !== ignoreId);
100
+ if (labelledByIds.length > 0 && doc) {
101
+ const labelText = labelledByIds.map(id => doc.getElementById(id)?.textContent || '').map(normalizeText).filter(Boolean).join(' ');
102
+ if (labelText) {
103
+ return labelText;
104
+ }
105
+ }
106
+ const ariaLabel = normalizeText(target.getAttribute('aria-label'));
107
+ if (ariaLabel) {
108
+ return ariaLabel;
109
+ }
110
+ const contentText = normalizeText(collectAccessibleText(target, ignoreId));
111
+ if (contentText) {
112
+ return contentText;
113
+ }
114
+ return normalizeText(target.getAttribute('title'));
115
+ }
116
+
117
+ /**
118
+ * Tracks and restores ARIA attributes owned by a single AttacherCore instance
45
119
  * without clobbering pre-existing caller attributes or tokens.
46
120
  */
47
121
  class AttachmentAriaController {
@@ -50,7 +124,9 @@ class AttachmentAriaController {
50
124
  this._isTooltip = false;
51
125
  this._attachmentId = null;
52
126
  this._ariaRole = undefined;
127
+ this._tooltipMode = 'describedby';
53
128
  this._addedDescribedByToken = false;
129
+ this._addedLabelledByToken = false;
54
130
  this._ownsHasPopup = false;
55
131
  this._ownsControls = false;
56
132
  this._ownsExpanded = false;
@@ -59,13 +135,22 @@ class AttachmentAriaController {
59
135
  * Bind ARIA metadata to a target Element (no-op when target is null/non-Element).
60
136
  *
61
137
  * @param {Element | null} target
62
- * @param {{ isTooltip: boolean, id: string, ariaRole?: string, isOpen: boolean }} options
138
+ * @param {{
139
+ * isTooltip: boolean,
140
+ * id: string,
141
+ * ariaRole?: string,
142
+ * isOpen: boolean,
143
+ * attachmentEl?: Element | null,
144
+ * tooltipText?: string | null,
145
+ * }} options
63
146
  */
64
147
  bind(target, {
65
148
  isTooltip,
66
149
  id,
67
150
  ariaRole,
68
- isOpen
151
+ isOpen,
152
+ attachmentEl = null,
153
+ tooltipText = null
69
154
  }) {
70
155
  if (this._boundTarget && (this._boundTarget !== target || this._attachmentId !== id || this._isTooltip !== isTooltip || this._ariaRole !== ariaRole)) {
71
156
  this.unbind();
@@ -96,6 +181,18 @@ class AttachmentAriaController {
96
181
  target.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
97
182
  this._ownsExpanded = true;
98
183
  }
184
+ } else {
185
+ const targetName = getTargetAccessibleName(target, id);
186
+ const rawTip = tooltipText != null && tooltipText !== '' ? tooltipText : attachmentEl?.textContent || '';
187
+ const normalizedTip = normalizeText(rawTip);
188
+ const hasExternalLabelledBy = splitTokens(target.getAttribute('aria-labelledby')).some(token => token !== id);
189
+ if (!targetName && !hasExternalLabelledBy) {
190
+ this._tooltipMode = 'labelledby';
191
+ } else if (normalizedTip && targetName === normalizedTip) {
192
+ this._tooltipMode = 'none';
193
+ } else {
194
+ this._tooltipMode = 'describedby';
195
+ }
99
196
  }
100
197
  this.setOpen(isOpen);
101
198
  }
@@ -111,7 +208,28 @@ class AttachmentAriaController {
111
208
  return;
112
209
  }
113
210
  if (this._isTooltip) {
114
- this._setDescribedByOpen(target, isOpen);
211
+ if (this._tooltipMode === 'labelledby') {
212
+ if (this._addedDescribedByToken) {
213
+ this._removeAttributeToken(target, 'aria-describedby', this._attachmentId);
214
+ this._addedDescribedByToken = false;
215
+ }
216
+ this._addedLabelledByToken = this._ensureAttributeToken(target, 'aria-labelledby', this._attachmentId, this._addedLabelledByToken);
217
+ } else if (this._tooltipMode === 'none') {
218
+ if (this._addedDescribedByToken) {
219
+ this._removeAttributeToken(target, 'aria-describedby', this._attachmentId);
220
+ this._addedDescribedByToken = false;
221
+ }
222
+ if (this._addedLabelledByToken) {
223
+ this._removeAttributeToken(target, 'aria-labelledby', this._attachmentId);
224
+ this._addedLabelledByToken = false;
225
+ }
226
+ } else {
227
+ if (this._addedLabelledByToken) {
228
+ this._removeAttributeToken(target, 'aria-labelledby', this._attachmentId);
229
+ this._addedLabelledByToken = false;
230
+ }
231
+ this._setTokenOnOpen(target, 'aria-describedby', isOpen);
232
+ }
115
233
  } else if (this._ownsExpanded) {
116
234
  target.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
117
235
  }
@@ -126,9 +244,13 @@ class AttachmentAriaController {
126
244
  return;
127
245
  }
128
246
  if (this._addedDescribedByToken) {
129
- this._removeDescribedByToken(target, this._attachmentId);
247
+ this._removeAttributeToken(target, 'aria-describedby', this._attachmentId);
130
248
  this._addedDescribedByToken = false;
131
249
  }
250
+ if (this._addedLabelledByToken) {
251
+ this._removeAttributeToken(target, 'aria-labelledby', this._attachmentId);
252
+ this._addedLabelledByToken = false;
253
+ }
132
254
  if (this._ownsHasPopup) {
133
255
  target.removeAttribute('aria-haspopup');
134
256
  this._ownsHasPopup = false;
@@ -144,47 +266,56 @@ class AttachmentAriaController {
144
266
  this._boundTarget = null;
145
267
  this._attachmentId = null;
146
268
  this._isTooltip = false;
269
+ this._tooltipMode = 'describedby';
147
270
  this._ariaRole = undefined;
148
271
  }
149
- _setDescribedByOpen(target, isOpen) {
272
+ _setTokenOnOpen(target, attrName, isOpen) {
150
273
  const id = this._attachmentId;
151
274
  if (!id) {
152
275
  return;
153
276
  }
154
277
  if (isOpen) {
155
- const tokens = splitTokens(target.getAttribute('aria-describedby'));
156
- if (!tokens.includes(id)) {
157
- tokens.push(id);
158
- target.setAttribute('aria-describedby', tokens.join(' '));
159
- this._addedDescribedByToken = true;
160
- }
278
+ this._addedDescribedByToken = this._ensureAttributeToken(target, attrName, id, this._addedDescribedByToken);
161
279
  } else if (this._addedDescribedByToken) {
162
- this._removeDescribedByToken(target, id);
280
+ this._removeAttributeToken(target, attrName, id);
163
281
  this._addedDescribedByToken = false;
164
282
  }
165
283
  }
166
- _removeDescribedByToken(target, token) {
284
+ _ensureAttributeToken(target, attrName, token, alreadyOwned) {
285
+ if (!token) {
286
+ return alreadyOwned;
287
+ }
288
+ const tokens = splitTokens(target.getAttribute(attrName));
289
+ if (!tokens.includes(token)) {
290
+ tokens.push(token);
291
+ target.setAttribute(attrName, tokens.join(' '));
292
+ return true;
293
+ }
294
+ return alreadyOwned;
295
+ }
296
+ _removeAttributeToken(target, attrName, token) {
167
297
  if (!token) {
168
298
  return;
169
299
  }
170
- const remaining = splitTokens(target.getAttribute('aria-describedby')).filter(t => t !== token);
300
+ const remaining = splitTokens(target.getAttribute(attrName)).filter(t => t !== token);
171
301
  if (remaining.length > 0) {
172
- target.setAttribute('aria-describedby', remaining.join(' '));
302
+ target.setAttribute(attrName, remaining.join(' '));
173
303
  } else {
174
- target.removeAttribute('aria-describedby');
304
+ target.removeAttribute(attrName);
175
305
  }
176
306
  }
177
307
  }
178
308
 
179
309
  /**
180
310
  * Restore focus to the Target if focus currently lives inside the floating attachment
181
- * or on another element outside the Target when dismissed via Escape.
311
+ * when dismissed via Escape.
182
312
  *
183
313
  * @param {Element | null} target
184
314
  * @param {Element | null} floatingElement
185
315
  */
186
316
  function restoreFocusOnEscape(target, floatingElement) {
187
- if (!target || typeof target.focus !== 'function' || typeof document === 'undefined') {
317
+ const focusable = target;
318
+ if (!focusable || typeof focusable.focus !== 'function' || typeof document === 'undefined') {
188
319
  return;
189
320
  }
190
321
  const active = document.activeElement;
@@ -194,11 +325,11 @@ function restoreFocusOnEscape(target, floatingElement) {
194
325
  const focusInsideAttachment = Boolean(floatingElement && active && floatingElement.contains(active));
195
326
  if (focusInsideAttachment) {
196
327
  try {
197
- target.focus({
328
+ focusable.focus({
198
329
  preventScroll: true
199
330
  });
200
331
  } catch {
201
- target.focus();
332
+ focusable.focus();
202
333
  }
203
334
  }
204
335
  }
@@ -214,9 +345,6 @@ function restoreFocusOnEscape(target, floatingElement) {
214
345
  * removed from the DOM during event handling (e.g. self-disappearing buttons).
215
346
  * Falls back to `element.contains(event.target)` when `composedPath` is unavailable.
216
347
  *
217
- * @param {Element | null | undefined} element
218
- * @param {Event | null | undefined} event
219
- * @returns {boolean}
220
348
  */
221
349
  function elementContainsEvent(element, event) {
222
350
  if (!element) {
@@ -226,7 +354,70 @@ function elementContainsEvent(element, event) {
226
354
  if (path && path.length > 0) {
227
355
  return path.includes(element);
228
356
  }
229
- return Boolean(event?.target && element.contains(event.target));
357
+ return Boolean(typeof Node !== 'undefined' && event?.target instanceof Node && element.contains(event.target));
358
+ }
359
+ function getEventClientPoint(event) {
360
+ if (!event) {
361
+ return null;
362
+ }
363
+ const touch = event.changedTouches?.[0];
364
+ if (touch) {
365
+ return {
366
+ x: touch.clientX,
367
+ y: touch.clientY
368
+ };
369
+ }
370
+ if ('clientX' in event && 'clientY' in event) {
371
+ const mouseEvent = event;
372
+ const x = mouseEvent.clientX;
373
+ const y = mouseEvent.clientY;
374
+ // Keyboard/synthetic clicks without pointer coordinates default to (0, 0) with detail === 0.
375
+ if (x === 0 && y === 0 && !mouseEvent.detail) {
376
+ return null;
377
+ }
378
+ return {
379
+ x,
380
+ y
381
+ };
382
+ }
383
+ return null;
384
+ }
385
+ function isPointWithinElementBoxes(element, x, y) {
386
+ const rect = element.getBoundingClientRect();
387
+ if (rect.width === 0 && rect.height === 0) {
388
+ return true;
389
+ }
390
+ if (isPointInRect(x, y, rect)) {
391
+ return true;
392
+ }
393
+ for (const child of element.children) {
394
+ const childRect = child.getBoundingClientRect();
395
+ if ((childRect.width > 0 || childRect.height > 0) && isPointInRect(x, y, childRect)) {
396
+ return true;
397
+ }
398
+ }
399
+ return false;
400
+ }
401
+
402
+ /**
403
+ * Determine whether a click/touch event landed inside a floating host element.
404
+ *
405
+ * Unlike `elementContainsEvent`, direct hits targeting a Top-Layer `[popover]`'s
406
+ * `::backdrop` (`event.target === element` with pointer coordinates outside the
407
+ * popover's rendered boxes) return `false` so clickout dismisses the popover.
408
+ */
409
+ function floatingElementContainsEvent(element, event) {
410
+ if (!elementContainsEvent(element, event)) {
411
+ return false;
412
+ }
413
+ if (!element || event?.target !== element) {
414
+ return true;
415
+ }
416
+ const point = getEventClientPoint(event);
417
+ if (!point) {
418
+ return true;
419
+ }
420
+ return isPointWithinElementBoxes(element, point.x, point.y);
230
421
  }
231
422
  const CORRIDOR_BUFFER = 2;
232
423
  function isPointInRect(x, y, rect) {
@@ -255,11 +446,6 @@ function pointInQuad(px, py, x1, y1, x2, y2, x3, y3, x4, y4) {
255
446
  *
256
447
  * Supports both DOM Elements and Floating UI VirtualElements via `getBoundingClientRect()`.
257
448
  *
258
- * @param {MouseEvent | { clientX: number, clientY: number }} event
259
- * @param {{ x: number, y: number } | null | undefined} origin
260
- * @param {Element | { getBoundingClientRect: Function } | null | undefined} target
261
- * @param {Element | { getBoundingClientRect: Function } | null | undefined} floatingElement
262
- * @returns {boolean}
263
449
  */
264
450
  function isCursorInSafePolygon(event, origin, target, floatingElement) {
265
451
  if (!event || !target || !floatingElement || typeof target.getBoundingClientRect !== 'function' || typeof floatingElement.getBoundingClientRect !== 'function') {
@@ -275,7 +461,7 @@ function isCursorInSafePolygon(event, origin, target, floatingElement) {
275
461
  if (isPointInRect(px, py, targetRect) || isPointInRect(px, py, floatingRect)) {
276
462
  return true;
277
463
  }
278
- const hasRealOrigin = Boolean(origin) && (origin.x !== 0 || origin.y !== 0 || isPointInRect(0, 0, targetRect));
464
+ const hasRealOrigin = origin != null && (origin.x !== 0 || origin.y !== 0 || isPointInRect(0, 0, targetRect));
279
465
 
280
466
  // Attachment is above target: gap is between floatingRect.bottom and targetRect.top
281
467
  if (floatingRect.bottom <= targetRect.top + CORRIDOR_BUFFER) {
@@ -283,7 +469,7 @@ function isCursorInSafePolygon(event, origin, target, floatingElement) {
283
469
  const by = floatingRect.bottom;
284
470
  const cx = floatingRect.right + CORRIDOR_BUFFER;
285
471
  const cy = floatingRect.bottom;
286
- if (hasRealOrigin) {
472
+ if (origin && hasRealOrigin) {
287
473
  return pointInTriangle(px, py, origin.x, origin.y + CORRIDOR_BUFFER, bx, by, cx, cy);
288
474
  }
289
475
  return pointInQuad(px, py, targetRect.left, targetRect.top + CORRIDOR_BUFFER, targetRect.right, targetRect.top + CORRIDOR_BUFFER, cx, cy, bx, by);
@@ -295,7 +481,7 @@ function isCursorInSafePolygon(event, origin, target, floatingElement) {
295
481
  const by = floatingRect.top;
296
482
  const cx = floatingRect.right + CORRIDOR_BUFFER;
297
483
  const cy = floatingRect.top;
298
- if (hasRealOrigin) {
484
+ if (origin && hasRealOrigin) {
299
485
  return pointInTriangle(px, py, origin.x, origin.y - CORRIDOR_BUFFER, bx, by, cx, cy);
300
486
  }
301
487
  return pointInQuad(px, py, targetRect.left, targetRect.bottom - CORRIDOR_BUFFER, targetRect.right, targetRect.bottom - CORRIDOR_BUFFER, cx, cy, bx, by);
@@ -307,7 +493,7 @@ function isCursorInSafePolygon(event, origin, target, floatingElement) {
307
493
  const by = floatingRect.top - CORRIDOR_BUFFER;
308
494
  const cx = floatingRect.right;
309
495
  const cy = floatingRect.bottom + CORRIDOR_BUFFER;
310
- if (hasRealOrigin) {
496
+ if (origin && hasRealOrigin) {
311
497
  return pointInTriangle(px, py, origin.x + CORRIDOR_BUFFER, origin.y, bx, by, cx, cy);
312
498
  }
313
499
  return pointInQuad(px, py, targetRect.left + CORRIDOR_BUFFER, targetRect.top, targetRect.left + CORRIDOR_BUFFER, targetRect.bottom, cx, cy, bx, by);
@@ -319,7 +505,7 @@ function isCursorInSafePolygon(event, origin, target, floatingElement) {
319
505
  const by = floatingRect.top - CORRIDOR_BUFFER;
320
506
  const cx = floatingRect.left;
321
507
  const cy = floatingRect.bottom + CORRIDOR_BUFFER;
322
- if (hasRealOrigin) {
508
+ if (origin && hasRealOrigin) {
323
509
  return pointInTriangle(px, py, origin.x - CORRIDOR_BUFFER, origin.y, bx, by, cx, cy);
324
510
  }
325
511
  return pointInQuad(px, py, targetRect.right - CORRIDOR_BUFFER, targetRect.top, targetRect.right - CORRIDOR_BUFFER, targetRect.bottom, cx, cy, bx, by);
@@ -331,34 +517,23 @@ const activeAttachers = new Set();
331
517
  const floatingElementParentMap = new WeakMap();
332
518
  const handledEscapeEvents = new WeakSet();
333
519
 
334
- /**
335
- * Register a mounted AttacherCore instance in the in-process attachment tree.
336
- *
337
- * @param {object} attacher
338
- */
520
+ /** Register a mounted `AttacherCore` instance in the in-process attachment tree. */
339
521
  function registerAttacher(attacher) {
340
522
  activeAttachers.add(attacher);
341
523
  }
342
524
 
343
- /**
344
- * Unregister a destroyed AttacherCore instance from the in-process attachment tree.
345
- *
346
- * @param {object} attacher
347
- */
525
+ /** Unregister a destroyed `AttacherCore` instance from the in-process attachment tree. */
348
526
  function unregisterAttacher(attacher) {
349
527
  activeAttachers.delete(attacher);
350
528
  }
351
529
 
352
530
  /**
353
- * Resolve the logical parent AttacherCore whose floating element contains
354
- * this attacher's target or template parent element.
355
- *
356
- * @param {object} child
357
- * @returns {object | null}
531
+ * Resolve the logical parent `AttacherCore` whose floating element contains
532
+ * this attacher's listener target.
358
533
  */
359
534
  function getParentAttacher(child) {
360
- const anchors = [child._listenerTarget, child.parentElement].filter(Boolean);
361
- if (activeAttachers.size > 1 && anchors.length > 0) {
535
+ const anchor = child._listenerTarget;
536
+ if (activeAttachers.size > 1 && anchor) {
362
537
  const byFloatingEl = new Map();
363
538
  for (const candidate of activeAttachers) {
364
539
  if (candidate !== child && candidate._floatingElement) {
@@ -366,24 +541,22 @@ function getParentAttacher(child) {
366
541
  }
367
542
  }
368
543
  if (byFloatingEl.size > 0) {
369
- for (const anchor of anchors) {
370
- let node = anchor === child._floatingElement ? anchor.parentElement : anchor;
371
- while (node) {
372
- if (node !== child._floatingElement) {
373
- const candidate = byFloatingEl.get(node);
374
- if (candidate) {
375
- if (child._floatingElement) {
376
- floatingElementParentMap.set(child._floatingElement, candidate);
377
- }
378
- return candidate;
544
+ let node = anchor === child._floatingElement ? anchor.parentElement : anchor;
545
+ while (node) {
546
+ if (node !== child._floatingElement) {
547
+ const candidate = byFloatingEl.get(node);
548
+ if (candidate) {
549
+ if (child._floatingElement) {
550
+ floatingElementParentMap.set(child._floatingElement, candidate);
379
551
  }
552
+ return candidate;
380
553
  }
381
- node = node.parentElement;
382
554
  }
555
+ node = node.parentElement;
383
556
  }
384
557
  }
385
558
  }
386
- if (anchors.some(anchor => anchor.isConnected)) {
559
+ if (anchor && anchor.isConnected) {
387
560
  if (child._floatingElement) {
388
561
  floatingElementParentMap.delete(child._floatingElement);
389
562
  }
@@ -397,21 +570,13 @@ function getParentAttacher(child) {
397
570
 
398
571
  /**
399
572
  * Cache the parent attachment relationship on the child's floating element so
400
- * clicks that unmount the child mid-event still trace back to the parent via composedPath.
401
- *
402
- * @param {object} attacher
573
+ * clicks that unmount the child mid-event still trace back to the parent via `composedPath`.
403
574
  */
404
575
  function syncParentAttachment(attacher) {
405
576
  getParentAttacher(attacher);
406
577
  }
407
578
 
408
- /**
409
- * Check whether `candidate` is a logical descendant of `ancestor` in the attachment tree.
410
- *
411
- * @param {object} candidate
412
- * @param {object} ancestor
413
- * @returns {boolean}
414
- */
579
+ /** Check whether `candidate` is a logical descendant of `ancestor` in the attachment tree. */
415
580
  function isDescendantOf(candidate, ancestor) {
416
581
  const visited = new Set();
417
582
  let current = getParentAttacher(candidate);
@@ -428,10 +593,6 @@ function isDescendantOf(candidate, ancestor) {
428
593
  /**
429
594
  * Determine whether a DOM event originated inside any logical descendant Attachment
430
595
  * (or its Target) of `parent`.
431
- *
432
- * @param {object} parent
433
- * @param {Event} event
434
- * @returns {boolean}
435
596
  */
436
597
  function descendantAttachmentContainsEvent(parent, event) {
437
598
  if (activeAttachers.size > 1) {
@@ -440,7 +601,7 @@ function descendantAttachmentContainsEvent(parent, event) {
440
601
  continue;
441
602
  }
442
603
  if (isDescendantOf(candidate, parent)) {
443
- if (elementContainsEvent(candidate._floatingElement, event) || elementContainsEvent(candidate._listenerTarget, event)) {
604
+ if (floatingElementContainsEvent(candidate._floatingElement, event) || elementContainsEvent(candidate._listenerTarget, event)) {
444
605
  return true;
445
606
  }
446
607
  }
@@ -449,6 +610,9 @@ function descendantAttachmentContainsEvent(parent, event) {
449
610
  const path = typeof event?.composedPath === 'function' ? event.composedPath() : null;
450
611
  if (path) {
451
612
  for (const node of path) {
613
+ if (node instanceof Element && node === event?.target && !floatingElementContainsEvent(node, event)) {
614
+ continue;
615
+ }
452
616
  let currentParent = floatingElementParentMap.get(node);
453
617
  const visited = new Set();
454
618
  while (currentParent && !visited.has(currentParent)) {
@@ -456,7 +620,7 @@ function descendantAttachmentContainsEvent(parent, event) {
456
620
  return true;
457
621
  }
458
622
  visited.add(currentParent);
459
- currentParent = getParentAttacher(currentParent) ?? (currentParent._floatingElement ? floatingElementParentMap.get(currentParent._floatingElement) : null);
623
+ currentParent = getParentAttacher(currentParent) ?? (currentParent._floatingElement ? floatingElementParentMap.get(currentParent._floatingElement) : undefined);
460
624
  }
461
625
  }
462
626
  }
@@ -466,10 +630,6 @@ function descendantAttachmentContainsEvent(parent, event) {
466
630
  /**
467
631
  * Determine whether a DOM node is contained inside any logical descendant Attachment
468
632
  * (or its Target) of `parent`.
469
- *
470
- * @param {object} parent
471
- * @param {Node | null | undefined} node
472
- * @returns {boolean}
473
633
  */
474
634
  function descendantAttachmentContainsNode(parent, node) {
475
635
  if (!node || activeAttachers.size <= 1) {
@@ -491,10 +651,6 @@ function descendantAttachmentContainsNode(parent, node) {
491
651
  /**
492
652
  * Enforce LIFO Escape dismissal across nested Attachments: only the deepest
493
653
  * currently open escapable Attachment handles a given Escape keydown event.
494
- *
495
- * @param {object} attacher
496
- * @param {KeyboardEvent} event
497
- * @returns {boolean}
498
654
  */
499
655
  function shouldHandleEscapeKey(attacher, event) {
500
656
  if (handledEscapeEvents.has(event)) {
@@ -502,7 +658,7 @@ function shouldHandleEscapeKey(attacher, event) {
502
658
  }
503
659
  if (activeAttachers.size > 1) {
504
660
  for (const candidate of activeAttachers) {
505
- if (candidate !== attacher && !candidate.isDestroyed && !candidate.isDestroying && !candidate._isHiding && !candidate._positioningSuspended && Boolean(candidate._hideListenersOnDocumentByEvent?.keydown) && isDescendantOf(candidate, attacher)) {
661
+ if (candidate !== attacher && !candidate.isDestroyed && !candidate.isDestroying && !candidate._isHiding && !candidate._positioningSuspended && Boolean(candidate._hideListenersOnDocumentByEvent.keydown) && isDescendantOf(candidate, attacher)) {
506
662
  return false;
507
663
  }
508
664
  }
@@ -514,7 +670,6 @@ function shouldHandleEscapeKey(attacher, event) {
514
670
  // Owner-scoped delay group isolating 300ms warm tooltip handoff per app/test container.
515
671
 
516
672
  const DEFAULT_WARM_WINDOW_MS = 300;
517
- const groupsByOwner = new WeakMap();
518
673
  class TooltipDelayGroup {
519
674
  constructor() {
520
675
  this._openTooltips = new Set();
@@ -540,6 +695,7 @@ class TooltipDelayGroup {
540
695
  return this._openTooltips.size > 0 || this._closedAt > 0 && Date.now() - this._closedAt < this._windowMs;
541
696
  }
542
697
  }
698
+ const groupsByOwner = new WeakMap();
543
699
 
544
700
  // Read-only lookup safe during owner teardown (never allocates).
545
701
  function peekDelayGroup(owner) {
@@ -561,29 +717,18 @@ function getDelayGroup(owner) {
561
717
  }
562
718
 
563
719
  /**
564
- * Target resolution seam for BasicAttacher.
720
+ * Target resolution seam.
565
721
  *
566
722
  * Keeps listener target and Floating UI reference selection in one private
567
- * module so explicit targets (elements, virtual references, and selectors)
568
- * can be resolved cleanly without cluttering positioning or lifecycle logic.
723
+ * module so targets (elements, virtual references, and selectors) can be
724
+ * resolved cleanly without cluttering positioning or lifecycle logic.
569
725
  */
570
726
 
571
- /**
572
- * Determine whether a target is a DOM Element.
573
- *
574
- * @param {unknown} value
575
- * @returns {boolean}
576
- */
577
727
  function isElementTarget(value) {
578
728
  return typeof Element !== 'undefined' && value instanceof Element;
579
729
  }
580
730
 
581
- /**
582
- * Floating UI virtual references are plain objects with `getBoundingClientRect`.
583
- *
584
- * @param {unknown} value
585
- * @returns {boolean}
586
- */
731
+ /** Floating UI virtual references are plain objects with `getBoundingClientRect`. */
587
732
  function isVirtualReference(value) {
588
733
  if (value == null || typeof value !== 'object') {
589
734
  return false;
@@ -595,16 +740,11 @@ function isVirtualReference(value) {
595
740
  }
596
741
 
597
742
  /**
598
- * Resolve a public `@explicitTarget` value (Element | selector | virtual ref).
743
+ * Resolve a public `@target` value (Element | selector | virtual ref).
599
744
  *
600
- * Selector strings use `querySelectorAll` and must match exactly one node
601
- * (same contract as `@floatingElementContainer`).
602
- *
603
- * @param {Element | string | { getBoundingClientRect: Function } | null | undefined} value
604
- * @param {ParentNode | Document | null | undefined} root
605
- * @returns {Element | { getBoundingClientRect: Function } | null}
745
+ * Selector strings use `querySelectorAll` and must match exactly one node.
606
746
  */
607
- function coerceExplicitTarget(value, root) {
747
+ function coerceTarget(value, root) {
608
748
  if (value == null) {
609
749
  return null;
610
750
  }
@@ -613,12 +753,12 @@ function coerceExplicitTarget(value, root) {
613
753
  }
614
754
  if (typeof value === 'string') {
615
755
  const doc = root ?? (typeof document !== 'undefined' ? document : null);
616
- assert(`explicitTarget selector "${value}" cannot be resolved without a document`, doc != null);
756
+ assert(`@target selector "${value}" cannot be resolved without a document`, doc != null);
617
757
  const matches = doc.querySelectorAll(value);
618
- assert(`explicitTarget selector "${value}" found ${matches.length} possible targets when there should be exactly 1`, matches.length === 1);
619
- return matches[0];
758
+ assert(`@target selector "${value}" found ${matches.length} possible targets when there should be exactly 1`, matches.length === 1);
759
+ return matches[0] ?? null;
620
760
  }
621
- assert('explicitTarget must be an Element, a CSS selector string, or a Floating UI virtual reference with getBoundingClientRect', false);
761
+ assert('@target must be an Element, a CSS selector string, or a Floating UI virtual reference with getBoundingClientRect', false);
622
762
  return null;
623
763
  }
624
764
  function escapeAttributeSelectorValue(value) {
@@ -627,64 +767,60 @@ function escapeAttributeSelectorValue(value) {
627
767
  }
628
768
  return String(value).replace(/["\\]/g, '\\$&');
629
769
  }
630
- function findPopoverTargetElements(id, root) {
770
+ /** Find native `[popovertarget="<id>"]` / `[interestfor="<id>"]` triggers for an attachment id. */
771
+ function findTriggerTargetElements(id, root) {
772
+ const empty = {
773
+ popoverTargets: [],
774
+ interestTargets: [],
775
+ allTargets: []
776
+ };
631
777
  if (!id || typeof id !== 'string') {
632
- return [];
778
+ return empty;
633
779
  }
634
780
  const doc = (typeof document !== 'undefined' ? document : null);
635
781
  if (!doc || typeof doc.querySelectorAll !== 'function') {
636
- return [];
637
- }
638
- return Array.from(doc.querySelectorAll(`[popovertarget="${escapeAttributeSelectorValue(id)}"]`));
782
+ return empty;
783
+ }
784
+ const escaped = escapeAttributeSelectorValue(id);
785
+ const popoverTargets = Array.from(doc.querySelectorAll(`[popovertarget="${escaped}"]`));
786
+ const interestTargets = Array.from(doc.querySelectorAll(`[interestfor="${escaped}"]`));
787
+ const seen = new Set(popoverTargets);
788
+ const allTargets = [...popoverTargets];
789
+ for (const el of interestTargets) {
790
+ if (!seen.has(el)) {
791
+ seen.add(el);
792
+ allTargets.push(el);
793
+ }
794
+ }
795
+ return {
796
+ popoverTargets,
797
+ interestTargets,
798
+ allTargets
799
+ };
639
800
  }
640
-
641
- // Pick the Floating UI reference: explicit arg (@target / @explicitTarget),
642
- // then yielded registration, then parent. Accepts options-bag or positional args.
643
- function resolveAttachmentTarget(optionsOrExplicit, registeredOrParent, parentElement, root) {
644
- let explicitTarget;
645
- let registeredTarget;
646
- let popoverTargets;
647
- let parent;
648
- let allowParentFallback = true;
649
- let searchRoot;
650
- if (optionsOrExplicit != null && typeof optionsOrExplicit === 'object' && !isElementTarget(optionsOrExplicit) && !isVirtualReference(optionsOrExplicit)) {
651
- ({
652
- explicitTarget,
653
- registeredTarget,
654
- popoverTargets,
655
- parentElement: parent,
656
- allowParentFallback = true,
657
- root: searchRoot
658
- } = optionsOrExplicit);
659
- } else {
660
- explicitTarget = optionsOrExplicit;
661
- if (arguments.length <= 2) {
662
- parent = registeredOrParent;
663
- } else {
664
- registeredTarget = registeredOrParent;
665
- parent = parentElement;
666
- searchRoot = root;
667
- }
668
- }
669
- if (explicitTarget != null) {
670
- return coerceExplicitTarget(explicitTarget, searchRoot);
801
+ /** Pick the Floating UI reference: `@target`, then yielded registration, then native triggers. */
802
+ function resolveAttachmentTarget({
803
+ target,
804
+ registeredTarget,
805
+ triggerTargets,
806
+ root
807
+ }) {
808
+ if (target != null) {
809
+ return coerceTarget(target, root);
671
810
  }
672
811
  if (registeredTarget != null) {
673
812
  return registeredTarget;
674
813
  }
675
- if (Array.isArray(popoverTargets) && popoverTargets.length > 0) {
676
- return popoverTargets[0];
814
+ if (triggerTargets && triggerTargets.length > 0) {
815
+ return triggerTargets[0] ?? null;
677
816
  }
678
- return allowParentFallback ? parent ?? null : null;
817
+ return null;
679
818
  }
680
819
 
681
820
  /**
682
821
  * Extract the DOM Element that should receive event listeners.
683
822
  * Real Elements receive events directly. Virtual references may provide a
684
823
  * `contextElement`; virtual references without a contextElement attach no listeners.
685
- *
686
- * @param {Element | { getBoundingClientRect: Function, contextElement?: Element } | null | undefined} target
687
- * @returns {Element | null}
688
824
  */
689
825
  function getListenerTarget(target) {
690
826
  if (isElementTarget(target)) {
@@ -698,8 +834,6 @@ function getListenerTarget(target) {
698
834
 
699
835
  /**
700
836
  * Whether the current browser environment supports Top-Layer `[popover="manual"]`.
701
- *
702
- * @returns {boolean}
703
837
  */
704
838
  function supportsPopoverHost() {
705
839
  return typeof HTMLElement !== 'undefined' && typeof HTMLElement.prototype.showPopover === 'function';
@@ -710,8 +844,6 @@ function supportsPopoverHost() {
710
844
  * so Top-Layer attachments opened inside `showModal()` stay DOM-inside the modal
711
845
  * and do not become inert.
712
846
  *
713
- * @param {Element | null | undefined} contextNode
714
- * @returns {Element | null}
715
847
  */
716
848
  function getModalDialogContainer(contextNode) {
717
849
  if (!isElementTarget(contextNode) || typeof contextNode.closest !== 'function') {
@@ -724,59 +856,13 @@ function getModalDialogContainer(contextNode) {
724
856
  }
725
857
  }
726
858
 
727
- /**
728
- * Resolve the DOM destination element for `MaybeInElement`.
729
- *
730
- * @param {{
731
- * renderInPlace: boolean,
732
- * parentElement: Element | null,
733
- * maybeContainer: Element | string | null | undefined,
734
- * hasCustomContainer: boolean,
735
- * modalContainer: Element | null,
736
- * usePopoverHost: boolean,
737
- * }} options
738
- * @returns {Element | undefined}
739
- */
740
- function resolveHostContainer({
741
- renderInPlace,
742
- parentElement,
743
- maybeContainer,
744
- hasCustomContainer,
745
- modalContainer,
746
- usePopoverHost
747
- }) {
748
- if (renderInPlace) {
749
- return parentElement;
750
- }
751
- if (maybeContainer instanceof Element) {
752
- return maybeContainer;
753
- }
754
- if (!hasCustomContainer && modalContainer) {
755
- return modalContainer;
756
- }
757
- if (typeof maybeContainer === 'string') {
758
- const possibleContainers = document.querySelectorAll(maybeContainer);
759
-
760
- // DEFAULTS.floatingElementContainer is '.ember-application'; embedded or
761
- // standalone Top-Layer mounts without .ember-application fall back to body.
762
- if (possibleContainers.length === 0 && !hasCustomContainer && usePopoverHost) {
763
- return document.body;
764
- }
765
- assert(`floatingElementContainer selector "${maybeContainer}" found ` + `${possibleContainers.length} possible containers when there should be exactly 1`, possibleContainers.length === 1);
766
- return possibleContainers[0];
767
- }
768
- return undefined;
769
- }
770
-
771
859
  /**
772
860
  * Promote a `[popover]` host element into the browser Top Layer.
773
861
  * If `showPopover()` throws, logs a debug warning and removes `[popover]` so the
774
- * `{{#in-element}}` portal fallback stays visible instead of matching UA `:not(:popover-open)`.
775
- *
776
- * @param {Element | null | undefined} el
862
+ * in-place host remains visible instead of matching UA `:not(:popover-open)`.
777
863
  */
778
864
  function showPopoverHost(el) {
779
- if (el && el.isConnected && el.hasAttribute('popover') && typeof el.showPopover === 'function') {
865
+ if (el instanceof HTMLElement && el.isConnected && el.hasAttribute('popover') && typeof el.showPopover === 'function') {
780
866
  try {
781
867
  if (!el.matches(':popover-open')) {
782
868
  el.showPopover();
@@ -792,11 +878,9 @@ function showPopoverHost(el) {
792
878
 
793
879
  /**
794
880
  * Remove a `[popover]` host element from the browser Top Layer.
795
- *
796
- * @param {Element | null | undefined} el
797
881
  */
798
882
  function hidePopoverHost(el) {
799
- if (el && el.isConnected && el.hasAttribute('popover') && typeof el.hidePopover === 'function') {
883
+ if (el instanceof HTMLElement && el.isConnected && el.hasAttribute('popover') && typeof el.hidePopover === 'function') {
800
884
  try {
801
885
  if (el.matches(':popover-open')) {
802
886
  el.hidePopover();
@@ -809,56 +893,9 @@ function hidePopoverHost(el) {
809
893
  }
810
894
  }
811
895
 
812
- function consume(positional) {
813
- for (let i = 0; i < positional.length; i++) {
814
- void positional[i];
815
- }
816
- }
896
+ const DEFAULT_SHIFT_PADDING = 5;
817
897
 
818
- /**
819
- * Run once per element, after render, so tracked writes do not hit the modifier's tracking frame.
820
- *
821
- * @param {Function} fn
822
- * @returns {import('ember-modifier').ModifierFunction}
823
- */
824
- function onInsert(fn) {
825
- const seen = new WeakSet();
826
- return modifier(element => {
827
- if (seen.has(element)) {
828
- return;
829
- }
830
- seen.add(element);
831
- const timer = schedule('actions', fn, element);
832
- return () => cancel(timer);
833
- });
834
- }
835
-
836
- /**
837
- * Skip install ({{did-update}} semantics). Each factory has its own WeakSet so two
838
- * onUpdate modifiers on the same node do not steal each other's first run.
839
- *
840
- * @param {Function} fn
841
- * @returns {import('ember-modifier').ModifierFunction}
842
- */
843
- function onUpdate(fn) {
844
- const seen = new WeakSet();
845
- return modifier((element, positional) => {
846
- consume(positional);
847
- if (!seen.has(element)) {
848
- seen.add(element);
849
- return;
850
- }
851
- const timer = schedule('actions', fn);
852
- return () => cancel(timer);
853
- });
854
- }
855
-
856
- /**
857
- * Check whether an attachment target (DOM Element or VirtualElement) is still connected.
858
- *
859
- * @param {Element | { contextElement?: Element } | null | undefined} target
860
- * @returns {boolean}
861
- */
898
+ /** Check whether an attachment target (DOM Element or VirtualElement) is still connected. */
862
899
  function isTargetConnected(target) {
863
900
  if (!target) {
864
901
  return false;
@@ -871,84 +908,61 @@ function isTargetConnected(target) {
871
908
  }
872
909
  return true;
873
910
  }
874
-
875
911
  /**
876
912
  * Normalize and deduplicate the Floating UI middleware array without mutating
877
913
  * caller-supplied middleware objects.
878
- *
879
- * @param {{
880
- * rawMiddleware: Array<any> | null | undefined,
881
- * arrowElement: Element | null,
882
- * flipOption: string | null | undefined,
883
- * overflowPadding: number | boolean | undefined,
884
- * arrowEnabled: boolean,
885
- * }} options
886
- * @returns {Array<any>}
887
914
  */
888
915
  function buildMiddleware({
889
916
  rawMiddleware,
890
917
  arrowElement,
891
- flipOption,
892
- overflowPadding,
893
918
  arrowEnabled
894
919
  }) {
895
- const middleware = (rawMiddleware || []).map(m => {
896
- if (m?.name === 'arrow' && arrowElement) {
920
+ const middleware = [];
921
+ for (const m of rawMiddleware || []) {
922
+ if (!m) {
923
+ continue;
924
+ }
925
+ if (m.name === 'arrow' && arrowElement) {
897
926
  if (typeof m.options === 'function') {
898
- return arrow(state => {
899
- const resolved = m.options(state) || {};
927
+ const optionsFn = m.options;
928
+ middleware.push(arrow(state => {
929
+ const resolved = optionsFn(state) || {};
900
930
  return resolved.element ? resolved : {
901
931
  ...resolved,
902
932
  element: arrowElement
903
933
  };
904
- });
934
+ }));
935
+ continue;
905
936
  }
906
937
  if (!m.options?.element) {
907
- return arrow({
938
+ middleware.push(arrow({
908
939
  ...m.options,
909
940
  element: arrowElement
910
- });
941
+ }));
942
+ continue;
911
943
  }
912
944
  }
913
- return m;
914
- });
915
- if (!middleware.some(m => m?.name === 'flip')) {
916
- if (flipOption) {
917
- middleware.push(flip({
918
- fallbackPlacements: flipOption.split(' ')
919
- }));
920
- } else if (overflowPadding !== false) {
921
- middleware.push(flip());
922
- }
945
+ middleware.push(m);
923
946
  }
924
- if (overflowPadding !== false && !middleware.some(m => m?.name === 'shift')) {
947
+ if (!middleware.some(m => m.name === 'flip')) {
948
+ middleware.push(flip());
949
+ }
950
+ if (!middleware.some(m => m.name === 'shift')) {
925
951
  middleware.push(shift({
926
952
  limiter: limitShift(),
927
- padding: overflowPadding
953
+ padding: DEFAULT_SHIFT_PADDING
928
954
  }));
929
955
  }
930
- if (arrowEnabled && arrowElement && !middleware.some(m => m?.name === 'arrow')) {
956
+ if (arrowEnabled && arrowElement && !middleware.some(m => m.name === 'arrow')) {
931
957
  middleware.push(arrow({
932
958
  element: arrowElement
933
959
  }));
934
960
  }
935
961
  return middleware;
936
962
  }
937
-
938
963
  /**
939
964
  * Apply the resolved `computePosition` coordinates, arrow offset, `middlewareData.hide`
940
- * attributes, and `x-placement` to the floating and arrow elements.
941
- *
942
- * @param {Element} floatingElement
943
- * @param {Element | null} arrowElement
944
- * @param {{
945
- * x: number,
946
- * y: number,
947
- * placement: string,
948
- * strategy: string,
949
- * middlewareData: Record<string, any>,
950
- * isHidden: boolean,
951
- * }} result
965
+ * attributes, `data-placement`, and `x-placement` to the floating and arrow elements.
952
966
  */
953
967
  function applyPositionResult(floatingElement, arrowElement, {
954
968
  x,
@@ -973,11 +987,13 @@ function applyPositionResult(floatingElement, arrowElement, {
973
987
  top: arrowY != null ? `${arrowY}px` : ''
974
988
  });
975
989
  }
990
+ let hiddenByMiddleware = false;
976
991
  if (middlewareData.hide) {
977
992
  const {
978
993
  referenceHidden,
979
994
  escaped
980
995
  } = middlewareData.hide;
996
+ hiddenByMiddleware = Boolean(referenceHidden || escaped);
981
997
  if (referenceHidden) {
982
998
  floatingElement.setAttribute('data-reference-hidden', '');
983
999
  } else {
@@ -988,60 +1004,108 @@ function applyPositionResult(floatingElement, arrowElement, {
988
1004
  } else {
989
1005
  floatingElement.removeAttribute('data-escaped');
990
1006
  }
991
- if (referenceHidden || escaped) {
992
- floatingElement.style.visibility = 'hidden';
993
- } else if (!isHidden) {
994
- floatingElement.style.visibility = '';
995
- }
1007
+ } else {
1008
+ floatingElement.removeAttribute('data-reference-hidden');
1009
+ floatingElement.removeAttribute('data-escaped');
1010
+ }
1011
+ if (hiddenByMiddleware) {
1012
+ floatingElement.style.visibility = 'hidden';
1013
+ } else if (!isHidden) {
1014
+ floatingElement.style.visibility = '';
996
1015
  }
1016
+ floatingElement.setAttribute('data-placement', placement);
997
1017
  floatingElement.setAttribute('x-placement', placement);
998
1018
  }
999
1019
 
1000
- var _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor0, _descriptor1, _descriptor10;
1001
- function resolveTooltipClass(envConfig) {
1002
- const {
1003
- tooltip,
1004
- tooltipClass
1005
- } = envConfig || {};
1006
- return tooltip?.tooltipClass ?? tooltipClass ?? DEFAULTS.tooltipClass;
1020
+ const attacherWaiter = buildWaiter('ember-attacher');
1021
+
1022
+ /** Cancel a scheduled task handle if present. */
1023
+ function cancelScheduled(handle) {
1024
+ handle?.cancel?.();
1007
1025
  }
1008
- function createTargetModifier(core) {
1009
- return class AttacherTargetModifier extends Modifier {
1010
- constructor(owner, args) {
1011
- super(owner, args);
1012
- this._element = null;
1013
- this._installed = false;
1014
- this._destroyed = false;
1015
- this._mountTimer = null;
1016
- registerDestructor(this, () => {
1017
- this._destroyed = true;
1018
- cancel(this._mountTimer);
1019
- if (this._element) {
1020
- core.unregisterTargetElement(this._element);
1021
- this._element = null;
1022
- }
1023
- });
1026
+
1027
+ /** Defer a callback to a microtask while holding a test-waiter token until it runs or cancels. */
1028
+ function scheduleMicrotask(fn) {
1029
+ let active = true;
1030
+ const token = attacherWaiter.beginAsync();
1031
+ queueMicrotask(() => {
1032
+ if (!active) {
1033
+ return;
1024
1034
  }
1025
- modify(element, positional, named) {
1026
- if (this._destroyed || core.isDestroyed) {
1027
- return;
1035
+ active = false;
1036
+ attacherWaiter.endAsync(token);
1037
+ fn();
1038
+ });
1039
+ return {
1040
+ cancel() {
1041
+ if (active) {
1042
+ active = false;
1043
+ attacherWaiter.endAsync(token);
1028
1044
  }
1029
- const data = positional.length > 0 ? positional[0] : named?.data;
1030
- const entry = core.registerTargetElement(element, data, null, getOwner(this));
1031
- if (!this._installed) {
1032
- this._installed = true;
1033
- this._element = element;
1034
- this._mountTimer = schedule('actions', () => {
1035
- this._mountTimer = null;
1036
- if (!this._destroyed && !core.isDestroyed) {
1037
- core._onRegisteredEntryMounted(element, entry.data);
1038
- }
1039
- });
1045
+ }
1046
+ };
1047
+ }
1048
+
1049
+ /** Schedule a `setTimeout` tracked by `@ember/test-waiters`, returning a cancellable handle. */
1050
+ function scheduleTimeout(fn, ms) {
1051
+ let active = true;
1052
+ const token = attacherWaiter.beginAsync();
1053
+ const timerId = setTimeout(() => {
1054
+ if (!active) {
1055
+ return;
1056
+ }
1057
+ active = false;
1058
+ attacherWaiter.endAsync(token);
1059
+ fn();
1060
+ }, ms);
1061
+ return {
1062
+ cancel() {
1063
+ if (active) {
1064
+ active = false;
1065
+ clearTimeout(timerId);
1066
+ attacherWaiter.endAsync(token);
1040
1067
  }
1041
1068
  }
1042
1069
  };
1043
1070
  }
1044
- const animationTestWaiter = buildWaiter('basic-attacher');
1071
+
1072
+ /** Cancel any existing handle and either run synchronously (`immediate` or `!ms`) or after `ms`. */
1073
+ function debounceTimeout(currentHandle, fn, ms, immediate = false) {
1074
+ cancelScheduled(currentHandle);
1075
+ if (immediate || !ms) {
1076
+ fn();
1077
+ return null;
1078
+ }
1079
+ return scheduleTimeout(fn, ms);
1080
+ }
1081
+
1082
+ var _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9;
1083
+ let nextInstanceNumber = 0;
1084
+ function nextFloatingId() {
1085
+ nextInstanceNumber += 1;
1086
+ return `ember-attacher-${nextInstanceNumber}-floating`;
1087
+ }
1088
+ function resolveTooltipClass(envConfig) {
1089
+ const {
1090
+ tooltip,
1091
+ tooltipClass
1092
+ } = envConfig || {};
1093
+ return tooltip?.tooltipClass ?? tooltipClass ?? DEFAULTS.tooltipClass;
1094
+ }
1095
+ const TRUTHY_OPTION_KEYS = new Set(['animation', 'class']);
1096
+ const REMOVED_4X_ARGS = {
1097
+ explicitTarget: 'Use `@target` instead.',
1098
+ flip: 'Pass `flip()` in `@middleware` instead.',
1099
+ overflowPadding: 'Pass `shift({ padding })` / `flip({ padding })` in `@middleware` instead.',
1100
+ floatingUiOptions: 'Use `@placement`, `@strategy`, and `@middleware` instead.',
1101
+ floatingElementContainer: 'Use the default Top-Layer host or `@renderInPlace={{true}}`.',
1102
+ isOffset: 'Remove; the diagonal safePolygon corridor is active automatically when `@interactive={{true}}`.',
1103
+ style: 'Style via `@class` / `class="..."` or `--ember-attacher-*` CSS custom properties instead.',
1104
+ additionalClass: 'Use `@class` or `class="..."` instead.',
1105
+ onInitializeAttacher: 'Use an element modifier on the Target or Attachment instead.',
1106
+ onWillDestroy: 'Use an element modifier teardown or `registerDestructor` instead.',
1107
+ configKey: 'Use `<AttachTooltip>` or `<AttachPopover>` instead.'
1108
+ };
1045
1109
  const EMPTY_OBJECT = Object.freeze({});
1046
1110
  const rawEnvByOwner = new WeakMap();
1047
1111
  function readEmberAttacherEnv(owner) {
@@ -1055,6 +1119,26 @@ function readEmberAttacherEnv(owner) {
1055
1119
  }
1056
1120
  return env?.emberAttacher || EMPTY_OBJECT;
1057
1121
  }
1122
+ function resolveOwnerRootElement(owner, doc) {
1123
+ if (!doc) {
1124
+ return null;
1125
+ }
1126
+ let root = null;
1127
+ if (owner && typeof owner.lookup === 'function') {
1128
+ const app = owner.lookup('application:main');
1129
+ root = app?.rootElement ?? null;
1130
+ }
1131
+ if (root instanceof Element) {
1132
+ return root;
1133
+ }
1134
+ if (typeof root === 'string') {
1135
+ const matched = doc.querySelector(root);
1136
+ if (matched) {
1137
+ return matched;
1138
+ }
1139
+ }
1140
+ return doc.querySelector('.ember-application') || doc.body;
1141
+ }
1058
1142
  function shallowValueEqual(a, b) {
1059
1143
  if (a === b) {
1060
1144
  return true;
@@ -1062,21 +1146,25 @@ function shallowValueEqual(a, b) {
1062
1146
  if (!a || !b || typeof a !== 'object' || typeof b !== 'object') {
1063
1147
  return false;
1064
1148
  }
1065
- const keysA = Object.keys(a);
1066
- const keysB = Object.keys(b);
1149
+ const objA = a;
1150
+ const objB = b;
1151
+ const keysA = Object.keys(objA);
1152
+ const keysB = Object.keys(objB);
1067
1153
  if (keysA.length !== keysB.length) {
1068
1154
  return false;
1069
1155
  }
1070
1156
  return keysA.every(key => {
1071
- const valA = a[key];
1072
- const valB = b[key];
1157
+ const valA = objA[key];
1158
+ const valB = objB[key];
1073
1159
  if (valA === valB) {
1074
1160
  return true;
1075
1161
  }
1076
1162
  if (valA && valB && typeof valA === 'object' && typeof valB === 'object') {
1077
- const subKeysA = Object.keys(valA);
1078
- const subKeysB = Object.keys(valB);
1079
- return subKeysA.length === subKeysB.length && subKeysA.every(subKey => valA[subKey] === valB[subKey]);
1163
+ const subA = valA;
1164
+ const subB = valB;
1165
+ const subKeysA = Object.keys(subA);
1166
+ const subKeysB = Object.keys(subB);
1167
+ return subKeysA.length === subKeysB.length && subKeysA.every(subKey => subA[subKey] === subB[subKey]);
1080
1168
  }
1081
1169
  return false;
1082
1170
  });
@@ -1085,32 +1173,85 @@ function normalizeTriggerList(value, fallback) {
1085
1173
  const resolved = value === undefined ? fallback : value;
1086
1174
  return resolved === null ? [] : resolved.split(' ').filter(Boolean);
1087
1175
  }
1176
+ function createTargetModifier(core) {
1177
+ class AttacherTargetModifierImpl extends Modifier {
1178
+ constructor(owner, args) {
1179
+ super(owner, args);
1180
+ this._element = null;
1181
+ this._installed = false;
1182
+ this._destroyed = false;
1183
+ this._mountHandle = null;
1184
+ this._lastBoundData = undefined;
1185
+ registerDestructor(this, () => {
1186
+ this._destroyed = true;
1187
+ cancelScheduled(this._mountHandle);
1188
+ if (this._element) {
1189
+ core.unregisterTargetElement(this._element);
1190
+ this._element = null;
1191
+ }
1192
+ });
1193
+ }
1194
+ modify(element, positional, named) {
1195
+ if (this._destroyed || core.isDestroyed) {
1196
+ return;
1197
+ }
1198
+ core._usedTargetModifier = true;
1199
+ const boundData = positional.length > 0 ? positional[0] : named?.data;
1200
+ const data = this._installed && element === this._element && boundData === this._lastBoundData ? core._registeredEntries.get(element)?.data : boundData;
1201
+ this._lastBoundData = boundData;
1202
+ const entry = core.registerTargetElement(element, data, null, getOwner(this) ?? null);
1203
+ if (!this._installed) {
1204
+ this._installed = true;
1205
+ this._element = element;
1206
+ this._mountHandle = scheduleMicrotask(() => {
1207
+ this._mountHandle = null;
1208
+ if (!this._destroyed && !core.isDestroyed) {
1209
+ core._onRegisteredEntryMounted(element, entry.data);
1210
+ }
1211
+ });
1212
+ }
1213
+ }
1214
+ }
1215
+ return AttacherTargetModifierImpl;
1216
+ }
1088
1217
 
1089
- // Shared reactive controller backing <BasicAttacher> and <Attacher>.
1218
+ /**
1219
+ * Shared reactive controller backing `<AttachTooltip>`, `<AttachPopover>`,
1220
+ * `<Attacher>`, and the `{{tooltip}}` singleton pool.
1221
+ */
1090
1222
  let AttacherCore = (_class = class AttacherCore {
1091
1223
  constructor(ownerContext, getArgs, {
1092
1224
  defaultConfigKey = null,
1093
1225
  defaultAriaRole = undefined,
1094
- getAdditionalClass = null,
1095
- allowParentFallback = true,
1226
+ getDefaultClass = null,
1096
1227
  isComponentHost = true,
1097
1228
  onRenderStateChange = null
1098
1229
  } = {}) {
1099
- _initializerDefineProperty(this, "_parentNotFound", _descriptor, this);
1100
- _initializerDefineProperty(this, "_parentElement", _descriptor2, this);
1101
- _initializerDefineProperty(this, "_isStartingAnimation", _descriptor3, this);
1102
- _initializerDefineProperty(this, "_arrowElement", _descriptor4, this);
1103
- _initializerDefineProperty(this, "_currentTarget", _descriptor5, this);
1104
- _initializerDefineProperty(this, "_registeredTarget", _descriptor6, this);
1105
- _initializerDefineProperty(this, "_mustRender", _descriptor7, this);
1106
- _initializerDefineProperty(this, "_modalContainer", _descriptor8, this);
1107
- _initializerDefineProperty(this, "_isShown", _descriptor9, this);
1108
- _initializerDefineProperty(this, "_data", _descriptor0, this);
1109
- _initializerDefineProperty(this, "_resolvedPlacement", _descriptor1, this);
1110
- _initializerDefineProperty(this, "_middlewareData", _descriptor10, this);
1111
- this._defaultId = null;
1230
+ _initializerDefineProperty(this, "_arrowElement", _descriptor, this);
1231
+ _initializerDefineProperty(this, "_currentTarget", _descriptor2, this);
1232
+ _initializerDefineProperty(this, "_registeredTarget", _descriptor3, this);
1233
+ _initializerDefineProperty(this, "_mustRender", _descriptor4, this);
1234
+ _initializerDefineProperty(this, "_modalContainer", _descriptor5, this);
1235
+ _initializerDefineProperty(this, "_isShown", _descriptor6, this);
1236
+ _initializerDefineProperty(this, "_data", _descriptor7, this);
1237
+ _initializerDefineProperty(this, "_resolvedPlacement", _descriptor8, this);
1238
+ _initializerDefineProperty(this, "_middlewareData", _descriptor9, this);
1239
+ this._ownerContext = void 0;
1240
+ this._owner = void 0;
1241
+ this._getArgs = void 0;
1242
+ this._defaultConfigKey = void 0;
1243
+ this._defaultAriaRole = void 0;
1244
+ this._getDefaultClass = void 0;
1245
+ this._isComponentHost = void 0;
1246
+ this._onRenderStateChange = void 0;
1247
+ this._defaultId = void 0;
1112
1248
  this._elementId = null;
1113
- this._setReferenceTimer = null;
1249
+ this._hasTargetBlock = false;
1250
+ this._usedTargetModifier = false;
1251
+ this._usedSetTarget = false;
1252
+ this._hasCheckedInitialTarget = false;
1253
+ this._setTargetHandle = null;
1254
+ this._syncArgsHandle = null;
1114
1255
  // Untracked copy of the node listeners are on so `_removeHideEventListeners`
1115
1256
  // does not read `_currentTarget` in the same frame that writes it.
1116
1257
  this._listenerTarget = null;
@@ -1125,45 +1266,41 @@ let AttacherCore = (_class = class AttacherCore {
1125
1266
  this._skipNativePopoverToggle = false;
1126
1267
  this._addedManagedPopover = false;
1127
1268
  this._attachedPopoverEventsOn = null;
1128
- this._syncArgsTimer = null;
1129
1269
  this._prevSyncedIsShown = undefined;
1130
1270
  this._prevSyncedTargetKey = undefined;
1131
- this._lastShownByDelay = 0;
1132
- this.parentFinder = modifier((element, [hasTargetBlock]) => {
1133
- if (hasTargetBlock !== undefined) {
1134
- this._allowParentFallback = !hasTargetBlock;
1135
- }
1136
- const timer = schedule('actions', () => {
1137
- if (!this._isDestroyed) {
1138
- this._setTracked('_parentElement', element.parentElement);
1139
- this._initializeAttacher();
1140
- }
1141
- });
1142
- return () => cancel(timer);
1143
- });
1144
- // Insert + autoUpdate teardown. Must not read tracked state synchronously in
1145
- // the modifier callback (the scheduled fn is fine) or tracked updates will re-fire teardown.
1271
+ this._prevSyncedTarget = undefined;
1272
+ this._closeGeneration = 0;
1273
+ this._activeCloseCancel = null;
1274
+ this._delayedVisibilityToggle = null;
1275
+ this._isHidden = true;
1276
+ this._isHiding = false;
1277
+ this._positioningSuspended = true;
1278
+ this._isDestroyed = false;
1279
+ this._hideListenersOnDocumentByEvent = {};
1280
+ this._hideListenersOnTargetByEvent = {};
1281
+ this._targetShowListenersByEvent = {};
1282
+ this._aria = new AttachmentAriaController();
1283
+ this._ariaOpen = false;
1284
+ this._mouseLeaveOrigin = null;
1285
+ this._restoreFocusOnHide = false;
1286
+ this._suppressFocusShow = false;
1287
+ this._lastUseCaptureArgumentValue = void 0;
1288
+ this._warnedRemovedArgs = new Set();
1289
+ this._cleanup = null;
1290
+ this.api = void 0;
1291
+ /** Tracks template args read inside `<template>` and schedules an idle args sync. */
1292
+ this.syncArgs = (..._positional) => {
1293
+ this.scheduleArgsSync();
1294
+ return '';
1295
+ };
1296
+ // In-place host mount & cleanup for `<AttachTooltip>` / `<AttachPopover>` (pass 1).
1146
1297
  this.setupFloatingElement = modifier((element, [hasTargetBlock]) => {
1147
- if (hasTargetBlock !== undefined) {
1148
- this._allowParentFallback = !hasTargetBlock;
1149
- }
1298
+ this._hasTargetBlock = Boolean(hasTargetBlock);
1150
1299
  this._floatingElement = element;
1151
1300
  registerAttacher(this);
1152
- const timer = schedule('actions', () => {
1153
- if (this._isDestroyed) {
1154
- return;
1155
- }
1156
- this._floatingElement = element;
1157
- this._attachPopoverEvents(element);
1158
- if (this.renderInPlace) {
1159
- this._setTracked('_parentElement', element.parentElement);
1160
- this._initializeAttacher();
1161
- } else {
1162
- syncParentAttachment(this);
1163
- }
1164
- });
1301
+ this._attachPopoverEvents(element);
1302
+ this.scheduleArgsSync();
1165
1303
  return () => {
1166
- cancel(timer);
1167
1304
  this._detachPopoverEvents(element);
1168
1305
  if (this._floatingElement === element) {
1169
1306
  this._floatingElement = null;
@@ -1172,10 +1309,11 @@ let AttacherCore = (_class = class AttacherCore {
1172
1309
  this._cleanup = null;
1173
1310
  };
1174
1311
  });
1312
+ // Headless `<Attacher as |a|>` floating element modifier.
1175
1313
  this.attachment = modifier(element => {
1176
1314
  this._floatingElement = element;
1177
1315
  registerAttacher(this);
1178
- const timer = schedule('actions', () => {
1316
+ const handle = scheduleMicrotask(() => {
1179
1317
  if (this._isDestroyed) {
1180
1318
  return;
1181
1319
  }
@@ -1189,15 +1327,12 @@ let AttacherCore = (_class = class AttacherCore {
1189
1327
  if (elementHadExplicitId && !hadId && !this._arg('id') || !hadTarget) {
1190
1328
  this._initializeAttacher();
1191
1329
  } else if (this._isShown && !this._isHiding) {
1192
- if (element.style.display !== 'block') {
1193
- this._cancelAnimation();
1194
- this._applyVisibility(true);
1195
- }
1196
- this._startShowAnimation();
1330
+ this._applyVisibility(true);
1331
+ this._update();
1197
1332
  }
1198
1333
  });
1199
1334
  return () => {
1200
- cancel(timer);
1335
+ cancelScheduled(handle);
1201
1336
  this._detachPopoverEvents(element);
1202
1337
  if (this._addedManagedPopover && element.getAttribute('popover') === 'manual') {
1203
1338
  element.removeAttribute('popover');
@@ -1210,13 +1345,8 @@ let AttacherCore = (_class = class AttacherCore {
1210
1345
  this._cleanup = null;
1211
1346
  };
1212
1347
  });
1213
- this.insertArrow = onInsert(element => {
1214
- if (!this._isDestroyed) {
1215
- this._setTracked('_arrowElement', element);
1216
- }
1217
- });
1218
1348
  this.arrowModifier = modifier(element => {
1219
- const timer = schedule('actions', () => {
1349
+ const handle = scheduleMicrotask(() => {
1220
1350
  if (this._isDestroyed) {
1221
1351
  return;
1222
1352
  }
@@ -1226,64 +1356,28 @@ let AttacherCore = (_class = class AttacherCore {
1226
1356
  }
1227
1357
  });
1228
1358
  return () => {
1229
- cancel(timer);
1359
+ cancelScheduled(handle);
1230
1360
  if (!this._isDestroyed && this._arrowElement === element) {
1231
1361
  this._setTracked('_arrowElement', null);
1232
1362
  }
1233
1363
  };
1234
1364
  });
1235
- this.isShownDidUpdate = onUpdate(() => this._syncIsShown());
1236
- this.targetDidUpdate = onUpdate(() => this._initializeAttacher());
1237
- this.optionsDidUpdate = onUpdate(() => {
1238
- this._checkDeprecatedArgs(this._getArgs());
1239
- this._ensureArgumentsAreValid();
1240
- if (this._floatingElement && !this._isComponentHost) {
1241
- this._syncHeadlessAttachmentElement(this._floatingElement);
1242
- }
1243
- this._syncAria();
1244
- this._update();
1245
- });
1365
+ this.insertArrow = this.arrowModifier;
1246
1366
  this.target = createTargetModifier(this);
1247
- this.reference = modifier(element => {
1248
- this._deprecateOnce('ember-attacher.api.reference', '[ember-attacher] The yielded `reference` modifier is deprecated and will be removed in ember-attacher 5.0.0. Use `target` (e.g. `{{a.target}}`) instead.');
1249
- this.setReference(element);
1250
- return () => {
1251
- if (!this._isDestroyed && this._registeredTarget === element) {
1252
- this.setReference(null);
1253
- }
1254
- };
1255
- });
1256
1367
  this._ownerContext = ownerContext;
1257
- this._owner = ownerContext && typeof ownerContext === 'object' ? getOwner(ownerContext) : null;
1368
+ this._owner = ownerContext && typeof ownerContext === 'object' ? getOwner(ownerContext) ?? null : null;
1258
1369
  this._getArgs = getArgs;
1259
1370
  this._defaultConfigKey = defaultConfigKey;
1260
1371
  this._defaultAriaRole = defaultAriaRole;
1261
- this._getAdditionalClass = getAdditionalClass;
1262
- this._allowParentFallback = allowParentFallback;
1372
+ this._getDefaultClass = getDefaultClass;
1263
1373
  this._isComponentHost = isComponentHost;
1264
1374
  this._onRenderStateChange = onRenderStateChange;
1265
- this._defaultId = `${guidFor(this)}-floating`;
1266
- this._delayedVisibilityToggle = null;
1267
- this._isHidden = true;
1268
- this._isHiding = false;
1269
- this._positioningSuspended = true;
1270
- this._pendingRafs = new Set();
1271
- this._isDestroyed = false;
1272
- this._warnedDeprecations = new Set();
1273
- this._hideListenersOnDocumentByEvent = {};
1274
- this._hideListenersOnTargetByEvent = {};
1275
- this._legacyShowListenersOnTargetByEvent = {};
1276
- this._aria = new AttachmentAriaController();
1277
- this._ariaOpen = false;
1278
- this._mouseLeaveOrigin = null;
1279
- this._restoreFocusOnHide = false;
1280
- this._suppressFocusShow = false;
1375
+ this._defaultId = nextFloatingId();
1281
1376
  this.hide = this.hide.bind(this);
1282
1377
  this.show = this.show.bind(this);
1283
1378
  this.toggle = this.toggle.bind(this);
1284
1379
  this.update = this.update.bind(this);
1285
1380
  this.setTarget = this.setTarget.bind(this);
1286
- this.setReference = this.setReference.bind(this);
1287
1381
  this._hide = this._hide.bind(this);
1288
1382
  this._hideAfterDelay = this._hideAfterDelay.bind(this);
1289
1383
  this._hideIfMouseOutsideTargetOrAttachment = this._hideIfMouseOutsideTargetOrAttachment.bind(this);
@@ -1296,35 +1390,38 @@ let AttacherCore = (_class = class AttacherCore {
1296
1390
  this._updatePosition = this._updatePosition.bind(this);
1297
1391
  this._onPopoverTargetClick = this._onPopoverTargetClick.bind(this);
1298
1392
  this._onPopoverBeforeToggle = this._onPopoverBeforeToggle.bind(this);
1299
- this._lastUseCaptureArgumentValue = this.useCapture;
1300
- const core = this;
1301
- this.api = {
1393
+ this._lastUseCaptureArgumentValue = Boolean(this._opt('useCapture'));
1394
+ this.api = Object.defineProperties({
1302
1395
  target: this.target,
1303
1396
  attachment: this.attachment,
1304
1397
  arrow: this.arrowModifier,
1305
- reference: this.reference,
1306
1398
  setTarget: this.setTarget,
1307
- setReference: this.setReference,
1308
1399
  show: this.show,
1309
1400
  hide: this.hide,
1310
1401
  toggle: this.toggle,
1311
- update: this.update,
1312
- get isShown() {
1313
- return core.liveIsShown;
1402
+ update: this.update
1403
+ }, {
1404
+ isShown: {
1405
+ enumerable: true,
1406
+ get: () => this.liveIsShown
1314
1407
  },
1315
- get shouldRender() {
1316
- return core.shouldRenderFloatingElement;
1408
+ shouldRender: {
1409
+ enumerable: true,
1410
+ get: () => this.shouldRenderFloatingElement
1317
1411
  },
1318
- get data() {
1319
- return core._data;
1412
+ data: {
1413
+ enumerable: true,
1414
+ get: () => this._data
1320
1415
  },
1321
- get placement() {
1322
- return core._resolvedPlacement ?? core.placement;
1416
+ placement: {
1417
+ enumerable: true,
1418
+ get: () => this._resolvedPlacement ?? this._opt('placement')
1323
1419
  },
1324
- get middlewareData() {
1325
- return core._middlewareData;
1420
+ middlewareData: {
1421
+ enumerable: true,
1422
+ get: () => this._middlewareData
1326
1423
  }
1327
- };
1424
+ });
1328
1425
  if (ownerContext && typeof ownerContext === 'object') {
1329
1426
  registerDestructor(ownerContext, () => this.destroy());
1330
1427
  }
@@ -1334,36 +1431,6 @@ let AttacherCore = (_class = class AttacherCore {
1334
1431
  this[field] = value;
1335
1432
  }
1336
1433
  }
1337
- _deprecateOnce(id, message) {
1338
- runInDebug(() => {
1339
- if (!this._warnedDeprecations.has(id)) {
1340
- this._warnedDeprecations.add(id);
1341
- deprecate(message, false, {
1342
- id,
1343
- until: '5.0.0',
1344
- for: 'ember-attacher',
1345
- since: {
1346
- available: '4.4.0',
1347
- enabled: '4.4.0'
1348
- }
1349
- });
1350
- }
1351
- });
1352
- }
1353
- _checkDeprecatedArgs(args) {
1354
- if (!args) {
1355
- return;
1356
- }
1357
- runInDebug(() => {
1358
- const deprecatedArgs = [['explicitTarget', 'ember-attacher.arg.explicit-target', 'Use @target instead.'], ['flip', 'ember-attacher.arg.flip', 'Pass `flip()` in @middleware instead.'], ['overflowPadding', 'ember-attacher.arg.overflow-padding', 'Pass `shift({ padding })` / `flip({ padding })` in @middleware instead.'], ['floatingUiOptions', 'ember-attacher.arg.floating-ui-options', 'Use @placement, @strategy, and @middleware instead.'], ['floatingElementContainer', 'ember-attacher.arg.floating-element-container', 'Attachments promote into the browser Top Layer via [popover="manual"] by default, or use @renderInPlace={{true}}.'], ['isOffset', 'ember-attacher.arg.is-offset', 'The interactive safePolygon hover corridor is active automatically when @interactive={{true}}.'], ['style', 'ember-attacher.arg.style', 'Style the attachment via CSS classes or custom properties instead.'], ['additionalClass', 'ember-attacher.arg.additional-class', 'Use @class or `class="..."` instead.'], ['onInitializeAttacher', 'ember-attacher.arg.on-initialize-attacher', 'Use an element modifier on the Target or Attachment instead.'], ['onWillDestroy', 'ember-attacher.arg.on-will-destroy', 'Use an element modifier or `registerDestructor` instead.']];
1359
- for (let i = 0; i < deprecatedArgs.length; i++) {
1360
- const [argName, id, hint] = deprecatedArgs[i];
1361
- if (args[argName] !== undefined) {
1362
- this._deprecateOnce(id, `[ember-attacher] Passing @${argName} is deprecated and will be removed in ember-attacher 5.0.0. ${hint}`);
1363
- }
1364
- }
1365
- });
1366
- }
1367
1434
  _arg(key) {
1368
1435
  const entryOpts = this._activeEntryOptions;
1369
1436
  if (entryOpts && entryOpts[key] !== undefined) {
@@ -1371,143 +1438,70 @@ let AttacherCore = (_class = class AttacherCore {
1371
1438
  }
1372
1439
  return this._getArgs()?.[key];
1373
1440
  }
1441
+ _defaultFor(key) {
1442
+ if (!this._isTooltip && this.configKey === 'popover' && key in POPOVER_DEFAULTS) {
1443
+ return POPOVER_DEFAULTS[key];
1444
+ }
1445
+ return DEFAULTS[key];
1446
+ }
1374
1447
  _opt(key) {
1375
1448
  const argVal = this._arg(key);
1376
- if (argVal != null) {
1449
+ if ((key === 'showOn' || key === 'hideOn') && argVal === null) {
1450
+ return null;
1451
+ }
1452
+ const truthyOnly = TRUTHY_OPTION_KEYS.has(key);
1453
+ if (truthyOnly ? argVal : argVal != null) {
1377
1454
  return argVal;
1378
1455
  }
1379
1456
  const env = this._envConfig;
1380
1457
  const keyed = env[this.configKey];
1381
- if (keyed && keyed[key] != null) {
1382
- return keyed[key];
1458
+ const keyedVal = keyed?.[key];
1459
+ if (truthyOnly ? keyedVal : keyedVal != null) {
1460
+ return keyedVal;
1383
1461
  }
1384
- if (env[key] != null) {
1385
- return env[key];
1462
+ const envVal = env[key];
1463
+ if (truthyOnly ? envVal : envVal != null) {
1464
+ return envVal;
1386
1465
  }
1387
- return DEFAULTS[key];
1388
- }
1389
- get arrow() {
1390
- return this._opt('arrow');
1391
- }
1392
- get autoUpdate() {
1393
- return this._opt('autoUpdate');
1394
- }
1395
- get animation() {
1396
- return this._arg('animation') || this._envConfig[this.configKey]?.animation || this._envConfig.animation || DEFAULTS.animation;
1397
- }
1398
- get flip() {
1399
- return this._opt('flip');
1400
- }
1401
- get hideDelay() {
1402
- return this._opt('hideDelay');
1403
- }
1404
- get hideDuration() {
1405
- return this._opt('hideDuration');
1406
- }
1407
- get hideOn() {
1408
- return this._arg('hideOn') === null ? null : this._opt('hideOn');
1409
- }
1410
- get interactive() {
1411
- return this._opt('interactive');
1412
- }
1413
- get isOffset() {
1414
- return this._opt('isOffset');
1415
- }
1416
- get controlledIsShown() {
1417
- return this._opt('isShown');
1418
- }
1419
- get liveIsShown() {
1420
- return this._isShown;
1421
- }
1422
- get lazyRender() {
1423
- return this._opt('lazyRender');
1424
- }
1425
- get overflowPadding() {
1426
- return this._opt('overflowPadding');
1427
- }
1428
- get placement() {
1429
- return this._opt('placement');
1430
- }
1431
- get renderInPlace() {
1432
- return this._opt('renderInPlace');
1433
- }
1434
- get showDelay() {
1435
- return this._opt('showDelay');
1436
- }
1437
- get showDuration() {
1438
- return this._opt('showDuration');
1439
- }
1440
- get showOn() {
1441
- return this._arg('showOn') === null ? null : this._opt('showOn');
1442
- }
1443
- get strategy() {
1444
- return this._opt('strategy');
1445
- }
1446
- get style() {
1447
- return this._opt('style');
1448
- }
1449
- get useCapture() {
1450
- return this._opt('useCapture');
1451
- }
1452
- get class() {
1453
- return this._arg('class') || this._envConfig[this.configKey]?.class || this._envConfig.class;
1466
+ return this._defaultFor(key);
1454
1467
  }
1455
1468
  get ariaRole() {
1456
1469
  return this._arg('ariaRole') || this._defaultAriaRole;
1457
1470
  }
1458
- get explicitTarget() {
1459
- const targetArg = this._arg('target');
1460
- return targetArg !== undefined ? targetArg : this._arg('explicitTarget');
1461
- }
1462
- get floatingElementContainer() {
1463
- return this._arg('floatingElementContainer') || this._envConfig[this.configKey]?.floatingElementContainer || this._envConfig.floatingElementContainer || DEFAULTS.floatingElementContainer;
1464
- }
1465
- get floatingUiOptions() {
1466
- return this._arg('floatingUiOptions') || this._envConfig[this.configKey]?.floatingUiOptions || this._envConfig.floatingUiOptions || DEFAULTS.floatingUiOptions;
1471
+ get targetArg() {
1472
+ return this._arg('target');
1467
1473
  }
1468
1474
  get configKey() {
1469
1475
  if (this._defaultConfigKey) {
1470
1476
  return this._defaultConfigKey;
1471
1477
  }
1472
- const argKey = this._arg('configKey');
1473
- if (argKey) {
1474
- return argKey;
1475
- }
1476
1478
  return this.ariaRole === 'tooltip' ? 'tooltip' : 'popover';
1477
1479
  }
1478
1480
  get _isTooltip() {
1479
1481
  return this.configKey === 'tooltip' || this.ariaRole === 'tooltip';
1480
1482
  }
1481
- get isFillAnimation() {
1482
- return this.animation === 'fill';
1483
+ get arrow() {
1484
+ return Boolean(this._opt('arrow'));
1483
1485
  }
1484
- get renderFloatingElement() {
1485
- return Boolean(this.renderInPlace || this._currentTarget);
1486
+ get isFillAnimation() {
1487
+ return this._opt('animation') === 'fill';
1486
1488
  }
1487
1489
  get shouldRenderFloatingElement() {
1488
- return !this.lazyRender || this._mustRender;
1490
+ return !this._opt('lazyRender') || this._mustRender;
1489
1491
  }
1490
1492
  get id() {
1491
1493
  return this._arg('id') || this._elementId || this._defaultId;
1492
1494
  }
1493
- get parentElement() {
1494
- return this._parentElement;
1495
+ get popoverAttr() {
1496
+ return this._usePopoverHost ? 'manual' : undefined;
1495
1497
  }
1496
- get _class() {
1497
- const showOrHideClass = `ember-attacher-${this._isStartingAnimation ? 'show' : 'hide'}`;
1498
- const arrowClass = `ember-attacher-${this.arrow ? 'with' : 'without'}-arrow`;
1499
- const additionalClass = this._getAdditionalClass ? this._getAdditionalClass() : this._arg('additionalClass') || '';
1500
- return [`ember-attacher-${this.animation}`, this.class || '', additionalClass, showOrHideClass, arrowClass].filter(Boolean).join(' ');
1498
+ get liveIsShown() {
1499
+ return this._isShown;
1501
1500
  }
1502
- get _style() {
1503
- const style = this.style;
1504
- if (!style) {
1505
- return undefined;
1506
- }
1507
- warn('@ember/string/htmlSafe must be used for any `style` passed to ember-attacher', isHTMLSafe(style), {
1508
- id: 'ember-attacher-require-html-safe-style'
1509
- });
1510
- return style;
1501
+ get innerClass() {
1502
+ const arrowClass = `ember-attacher-${this.arrow ? 'with' : 'without'}-arrow`;
1503
+ const defaultClass = this._getDefaultClass ? this._getDefaultClass() : '';
1504
+ return [`ember-attacher-${this._opt('animation')}`, this._opt('class') || '', defaultClass, arrowClass].filter(Boolean).join(' ');
1511
1505
  }
1512
1506
  get isDestroyed() {
1513
1507
  return this._isDestroyed;
@@ -1547,32 +1541,18 @@ let AttacherCore = (_class = class AttacherCore {
1547
1541
  hasContent: false
1548
1542
  };
1549
1543
  }
1550
- const entry = this._registeredEntries.get(activeEl);
1551
- const parentElement = this._parentElement || this._listenerTarget?.parentElement || null;
1552
- const reuseMountedContainer = !this._hasCustomFloatingElementContainer && !this._renderInPlace && !this._modalContainer && this._floatingElement?.isConnected && this._floatingElement.parentNode?.tagName !== 'DIALOG';
1553
- let container;
1554
- if (reuseMountedContainer) {
1555
- container = this._floatingElement.parentNode;
1556
- } else {
1557
- container = resolveHostContainer({
1558
- renderInPlace: this._renderInPlace,
1559
- parentElement,
1560
- maybeContainer: this.floatingElementContainer,
1561
- hasCustomContainer: this._hasCustomFloatingElementContainer,
1562
- modalContainer: this._modalContainer,
1563
- usePopoverHost: this._usePopoverHost
1564
- });
1565
- }
1544
+ const entry = isElementTarget(activeEl) ? this._registeredEntries.get(activeEl) : undefined;
1545
+ const ownerForRoot = entry?.owner || this._owner;
1546
+ const container = typeof document !== 'undefined' ? this._modalContainer || resolveOwnerRootElement(ownerForRoot, document) : null;
1566
1547
  return {
1567
1548
  activeElement: activeEl,
1568
1549
  id: this.id,
1569
1550
  role: this.ariaRole || 'tooltip',
1570
- popoverAttr: this._popoverAttr,
1571
- className: this._class,
1572
- style: this._style,
1551
+ popoverAttr: this.popoverAttr,
1552
+ className: this.innerClass,
1573
1553
  text: entry?.data != null ? String(entry.data) : '',
1574
1554
  hasContent: Boolean(entry && entry.data != null && entry.data !== ''),
1575
- arrow: Boolean(this.arrow),
1555
+ arrow: this.arrow,
1576
1556
  isFillAnimation: this.isFillAnimation,
1577
1557
  isShown: this._isShown,
1578
1558
  isHiding: this._isHiding,
@@ -1588,62 +1568,83 @@ let AttacherCore = (_class = class AttacherCore {
1588
1568
  return this._envConfig;
1589
1569
  }
1590
1570
  get _envConfig() {
1591
- const entryOwner = this._currentTarget && this._registeredEntries.get(this._currentTarget)?.owner || this._registeredTarget && this._registeredEntries.get(this._registeredTarget)?.owner || this._registeredEntries.values().next().value?.owner || this._owner;
1571
+ const currentEl = isElementTarget(this._currentTarget) ? this._currentTarget : null;
1572
+ const registeredEl = isElementTarget(this._registeredTarget) ? this._registeredTarget : null;
1573
+ const entryOwner = currentEl && this._registeredEntries.get(currentEl)?.owner || registeredEl && this._registeredEntries.get(registeredEl)?.owner || this._registeredEntries.values().next().value?.owner || this._owner;
1592
1574
  return readEmberAttacherEnv(entryOwner);
1593
1575
  }
1594
1576
  get _hideOn() {
1595
- return normalizeTriggerList(this.hideOn, DEFAULTS.hideOn);
1577
+ const fallback = this._defaultFor('hideOn') ?? null;
1578
+ return normalizeTriggerList(this._opt('hideOn'), fallback);
1596
1579
  }
1597
1580
  get _showOn() {
1598
- return normalizeTriggerList(this.showOn, DEFAULTS.showOn);
1581
+ const fallback = this._defaultFor('showOn') ?? null;
1582
+ return normalizeTriggerList(this._opt('showOn'), fallback);
1599
1583
  }
1600
1584
  get _middleware() {
1601
1585
  return buildMiddleware({
1602
1586
  rawMiddleware: this._opt('middleware'),
1603
1587
  arrowElement: this._arrowElement,
1604
- flipOption: this.flip,
1605
- overflowPadding: this.overflowPadding,
1606
- arrowEnabled: Boolean(this.arrow) || !this._isComponentHost && Boolean(this._arrowElement)
1588
+ arrowEnabled: this.arrow || !this._isComponentHost && Boolean(this._arrowElement)
1607
1589
  });
1608
1590
  }
1609
- get _hasCustomFloatingElementContainer() {
1610
- return Boolean(this._arg('floatingElementContainer') || this._envConfig[this.configKey]?.floatingElementContainer || this._envConfig.floatingElementContainer);
1611
- }
1612
1591
  get _usePopoverHost() {
1613
- return supportsPopoverHost() && !this._renderInPlace && !this._hasCustomFloatingElementContainer;
1614
- }
1615
- get _popoverAttr() {
1616
- return this._usePopoverHost ? 'manual' : undefined;
1592
+ return supportsPopoverHost() && !this._renderInPlace;
1617
1593
  }
1618
1594
  get _renderInPlace() {
1619
- return typeof document !== 'undefined' ? Boolean(this.renderInPlace) : true;
1620
- }
1621
- get _floatingElementContainer() {
1622
- return resolveHostContainer({
1623
- renderInPlace: this._renderInPlace,
1624
- parentElement: this._parentElement,
1625
- maybeContainer: this.floatingElementContainer,
1626
- hasCustomContainer: this._hasCustomFloatingElementContainer,
1627
- modalContainer: this._modalContainer,
1628
- usePopoverHost: this._usePopoverHost
1595
+ return typeof document !== 'undefined' ? Boolean(this._opt('renderInPlace')) : true;
1596
+ }
1597
+ get _delayGroupOwner() {
1598
+ const currentEl = isElementTarget(this._currentTarget) ? this._currentTarget : null;
1599
+ const registeredEl = isElementTarget(this._registeredTarget) ? this._registeredTarget : null;
1600
+ return this._owner || currentEl && this._registeredEntries.get(currentEl)?.owner || registeredEl && this._registeredEntries.get(registeredEl)?.owner || this._registeredEntries.values().next().value?.owner || null;
1601
+ }
1602
+ _hasSuppliedTargetBinding() {
1603
+ const args = this._getArgs() || EMPTY_OBJECT;
1604
+ if ('target' in args || this._hasTargetBlock || this._usedTargetModifier || this._usedSetTarget || this._registeredTarget != null || this._registeredEntries.size > 0 || this._popoverTargetEntries.size > 0 || this._currentTarget != null) {
1605
+ return true;
1606
+ }
1607
+ const explicitId = this._arg('id') || this._elementId;
1608
+ if (explicitId) {
1609
+ const {
1610
+ allTargets
1611
+ } = findTriggerTargetElements(explicitId);
1612
+ if (allTargets.length > 0) {
1613
+ return true;
1614
+ }
1615
+ }
1616
+ return false;
1617
+ }
1618
+ _assertInitialTargetBinding() {
1619
+ if (!this._isComponentHost || this._hasCheckedInitialTarget || typeof document === 'undefined') {
1620
+ return;
1621
+ }
1622
+ this._hasCheckedInitialTarget = true;
1623
+ runInDebug(() => {
1624
+ assert('[ember-attacher] <AttachTooltip> and <AttachPopover> require a Target in 5.0.0. Supply @target, <:target>, {{a.target}}, a.setTarget(), [popovertarget], or [interestfor].', this._hasSuppliedTargetBinding());
1629
1625
  });
1630
1626
  }
1631
1627
  scheduleArgsSync() {
1632
- cancel(this._syncArgsTimer);
1633
- this._syncArgsTimer = schedule('actions', () => {
1634
- this._syncArgsTimer = null;
1628
+ cancelScheduled(this._syncArgsHandle);
1629
+ this._syncArgsHandle = scheduleMicrotask(() => {
1630
+ this._syncArgsHandle = null;
1635
1631
  if (this._isDestroyed) {
1636
1632
  return;
1637
1633
  }
1638
- this._checkDeprecatedArgs(this._getArgs());
1639
- const targetKey = `${this.showOn}|${this.hideOn}|${this.id}`;
1640
- const explicitTarget = this.explicitTarget;
1641
- if (!this._prevSyncedTargetKey || this._prevSyncedTargetKey !== targetKey || this._prevSyncedExplicitTarget !== explicitTarget) {
1634
+ this._warnRemoved4xArgs(this._getArgs());
1635
+ const targetKey = `${this._opt('showOn')}|${this._opt('hideOn')}|${this.id}|${this._renderInPlace}`;
1636
+ const targetArg = this.targetArg;
1637
+ const isInitialSync = !this._prevSyncedTargetKey;
1638
+ const targetChanged = isInitialSync || this._prevSyncedTargetKey !== targetKey || this._prevSyncedTarget !== targetArg;
1639
+ if (targetChanged) {
1642
1640
  this._prevSyncedTargetKey = targetKey;
1643
- this._prevSyncedExplicitTarget = explicitTarget;
1641
+ this._prevSyncedTarget = targetArg;
1644
1642
  this._initializeAttacher();
1645
1643
  }
1646
- const isShown = this.controlledIsShown;
1644
+ if (isInitialSync) {
1645
+ this._assertInitialTargetBinding();
1646
+ }
1647
+ const isShown = this._opt('isShown');
1647
1648
  if (this._prevSyncedIsShown !== isShown) {
1648
1649
  this._prevSyncedIsShown = isShown;
1649
1650
  this._syncIsShown();
@@ -1653,18 +1654,15 @@ let AttacherCore = (_class = class AttacherCore {
1653
1654
  this._syncHeadlessAttachmentElement(this._floatingElement);
1654
1655
  }
1655
1656
  this._syncAria();
1656
- this._update();
1657
+ if (!targetChanged) {
1658
+ this._update();
1659
+ }
1657
1660
  });
1658
1661
  }
1659
- /**
1660
- * Owner used for the tooltip delay-group. Pool cores are constructed without an
1661
- * Ember owner; fall back to the active/registered target's modifier owner.
1662
- */
1663
- get _delayGroupOwner() {
1664
- return this._owner || this._currentTarget && this._registeredEntries.get(this._currentTarget)?.owner || this._registeredTarget && this._registeredEntries.get(this._registeredTarget)?.owner || this._registeredEntries.values().next().value?.owner || null;
1665
- }
1666
1662
  registerTargetElement(element, data, options = null, owner = null) {
1667
- this._checkDeprecatedArgs(options);
1663
+ if (options) {
1664
+ this._warnRemoved4xArgs(options);
1665
+ }
1668
1666
  let entry = this._registeredEntries.get(element);
1669
1667
  const isNew = !entry;
1670
1668
  if (!entry) {
@@ -1675,7 +1673,8 @@ let AttacherCore = (_class = class AttacherCore {
1675
1673
  owner,
1676
1674
  showListeners: {},
1677
1675
  showOnKey: null,
1678
- useCapture: null
1676
+ useCapture: null,
1677
+ updateHandle: null
1679
1678
  };
1680
1679
  this._registeredEntries.set(element, entry);
1681
1680
  } else {
@@ -1685,22 +1684,25 @@ let AttacherCore = (_class = class AttacherCore {
1685
1684
  entry.owner = owner;
1686
1685
  }
1687
1686
  }
1688
- if (owner && !this._owner) {
1689
- this._owner = owner;
1687
+ const internalOwner = owner;
1688
+ if (internalOwner && !this._owner) {
1689
+ this._owner = internalOwner;
1690
1690
  }
1691
1691
  this._syncEntryShowListeners(entry);
1692
1692
  if (!isNew && (this._registeredTarget === element || this._currentTarget === element)) {
1693
1693
  this._activeEntryOptions = options;
1694
- cancel(entry.updateTimer);
1695
- entry.updateTimer = schedule('actions', () => {
1696
- entry.updateTimer = null;
1694
+ cancelScheduled(entry.updateHandle);
1695
+ entry.updateHandle = scheduleMicrotask(() => {
1696
+ if (entry) {
1697
+ entry.updateHandle = null;
1698
+ }
1697
1699
  if (this._isDestroyed) {
1698
1700
  return;
1699
1701
  }
1700
1702
  if (this._registeredTarget === element || this._currentTarget === element) {
1701
1703
  this._setTracked('_data', data);
1702
- this._syncAria();
1703
1704
  this._notifyRenderStateChange();
1705
+ this._syncAria();
1704
1706
  if (!this._isHidden || this._isShown) {
1705
1707
  this._update();
1706
1708
  }
@@ -1714,7 +1716,7 @@ let AttacherCore = (_class = class AttacherCore {
1714
1716
  if (!entry) {
1715
1717
  return;
1716
1718
  }
1717
- cancel(entry.updateTimer);
1719
+ cancelScheduled(entry.updateHandle);
1718
1720
  this._removeEntryShowListeners(entry);
1719
1721
  this._registeredEntries.delete(element);
1720
1722
  if (this._listenerTarget === element) {
@@ -1728,7 +1730,7 @@ let AttacherCore = (_class = class AttacherCore {
1728
1730
  if (this._registeredTarget === element || this._currentTarget === element) {
1729
1731
  this._activeEntryOptions = null;
1730
1732
  const shouldHide = !this._isHidden || this._isShown;
1731
- schedule('actions', () => {
1733
+ scheduleMicrotask(() => {
1732
1734
  if (this._isDestroyed) {
1733
1735
  return;
1734
1736
  }
@@ -1745,7 +1747,7 @@ let AttacherCore = (_class = class AttacherCore {
1745
1747
  if (!this._registeredEntries.has(element)) {
1746
1748
  return;
1747
1749
  }
1748
- const currentRegistered = this._registeredTarget;
1750
+ const currentRegistered = isElementTarget(this._registeredTarget) ? this._registeredTarget : null;
1749
1751
  if (!currentRegistered || !this._registeredEntries.has(currentRegistered)) {
1750
1752
  this._setTracked('_registeredTarget', element);
1751
1753
  this._setTracked('_data', data);
@@ -1776,7 +1778,7 @@ let AttacherCore = (_class = class AttacherCore {
1776
1778
  element.removeAttribute('popover');
1777
1779
  this._addedManagedPopover = false;
1778
1780
  }
1779
- if (this._isHidden && !this._isShown) {
1781
+ if (this._isHidden && !this._isShown && !element.classList.contains('ember-attacher')) {
1780
1782
  element.style.display = 'none';
1781
1783
  element.setAttribute('aria-hidden', 'true');
1782
1784
  }
@@ -1798,11 +1800,12 @@ let AttacherCore = (_class = class AttacherCore {
1798
1800
  element.removeEventListener('beforetoggle', this._onPopoverBeforeToggle);
1799
1801
  this._attachedPopoverEventsOn = null;
1800
1802
  }
1801
- _onPopoverBeforeToggle(event) {
1803
+ _onPopoverBeforeToggle(rawEvent) {
1802
1804
  if (this._isDestroyed || this._syncingPopoverHost) {
1803
1805
  return;
1804
1806
  }
1805
- const trigger = this._pendingPopoverTrigger || (event.source?.hasAttribute?.('popovertarget') ? event.source : null);
1807
+ const event = rawEvent;
1808
+ const trigger = this._pendingPopoverTrigger || (event.source?.hasAttribute?.('popovertarget') || event.source?.hasAttribute?.('interestfor') ? event.source : null);
1806
1809
  this._pendingPopoverTrigger = null;
1807
1810
  if (!trigger && this._popoverTargetEntries.size === 0) {
1808
1811
  return;
@@ -1831,14 +1834,11 @@ let AttacherCore = (_class = class AttacherCore {
1831
1834
  }
1832
1835
  _onPopoverTargetClick(event) {
1833
1836
  const trigger = event.currentTarget;
1834
- if (!trigger || this._isDestroyed) {
1837
+ if (!(trigger instanceof Element) || this._isDestroyed) {
1835
1838
  return;
1836
1839
  }
1837
1840
  const floatingEl = this._floatingElement;
1838
1841
  const actionAttr = (trigger.getAttribute('popovertargetaction') || 'toggle').toLowerCase();
1839
-
1840
- // When the browser promotes `[popover]` natively, the native invoker runs after
1841
- // click dispatch and emits `beforetoggle`, so avoid double-toggling here.
1842
1842
  if (floatingEl?.hasAttribute('popover') && typeof floatingEl.showPopover === 'function') {
1843
1843
  this._pendingPopoverTrigger = trigger;
1844
1844
  if (actionAttr !== 'hide' && this._currentTarget !== trigger) {
@@ -1867,13 +1867,14 @@ let AttacherCore = (_class = class AttacherCore {
1867
1867
  const baseArgs = this._getArgs() || EMPTY_OBJECT;
1868
1868
  const env = this._envConfig;
1869
1869
  const keyedEnv = env[this.configKey];
1870
- const showOn = normalizeTriggerList(opts.showOn === undefined ? baseArgs.showOn : opts.showOn, keyedEnv?.showOn ?? env.showOn ?? DEFAULTS.showOn);
1870
+ const showOnFallback = keyedEnv?.showOn ?? env.showOn ?? this._defaultFor('showOn') ?? null;
1871
+ const showOn = normalizeTriggerList(opts.showOn === undefined ? baseArgs.showOn : opts.showOn, showOnFallback);
1871
1872
  const useCapture = Boolean(opts.useCapture ?? baseArgs.useCapture ?? keyedEnv?.useCapture ?? env.useCapture ?? DEFAULTS.useCapture);
1872
1873
  const showOnKey = showOn.join(' ');
1873
1874
  if (entry.showOnKey === showOnKey && entry.useCapture === useCapture) {
1874
1875
  return;
1875
1876
  }
1876
- cancel(entry.updateTimer);
1877
+ cancelScheduled(entry.updateHandle);
1877
1878
  this._removeEntryShowListeners(entry);
1878
1879
  entry.showOnKey = showOnKey;
1879
1880
  entry.useCapture = useCapture;
@@ -1897,7 +1898,10 @@ let AttacherCore = (_class = class AttacherCore {
1897
1898
  const listeners = entry.showListeners;
1898
1899
  const capture = Boolean(entry.useCapture);
1899
1900
  for (const eventName of Object.keys(listeners)) {
1900
- entry.element.removeEventListener(eventName, listeners[eventName], capture);
1901
+ const listener = listeners[eventName];
1902
+ if (listener) {
1903
+ entry.element.removeEventListener(eventName, listener, capture);
1904
+ }
1901
1905
  delete listeners[eventName];
1902
1906
  }
1903
1907
  entry.showOnKey = null;
@@ -1922,41 +1926,38 @@ let AttacherCore = (_class = class AttacherCore {
1922
1926
  this._setTracked('_currentTarget', targetEl);
1923
1927
  this._syncModalContainer();
1924
1928
  syncParentAttachment(this);
1925
- this._aria.bind(this._listenerTarget, {
1926
- isTooltip: this._isTooltip,
1927
- id: this.id,
1928
- ariaRole: this.ariaRole,
1929
- isOpen: this._ariaOpen
1930
- });
1931
1929
  this._notifyRenderStateChange();
1930
+ this._syncAria();
1932
1931
  }
1933
1932
  _syncPopoverTargetListeners(popoverTargets) {
1934
1933
  const nextSet = new Set(popoverTargets);
1934
+ const useCapture = Boolean(this._opt('useCapture'));
1935
1935
  for (const [el, listener] of this._popoverTargetEntries) {
1936
1936
  if (!nextSet.has(el)) {
1937
- el.removeEventListener('click', listener, this.useCapture);
1937
+ el.removeEventListener('click', listener, useCapture);
1938
1938
  this._popoverTargetEntries.delete(el);
1939
1939
  }
1940
1940
  }
1941
1941
  for (const el of nextSet) {
1942
1942
  if (!this._popoverTargetEntries.has(el)) {
1943
- el.addEventListener('click', this._onPopoverTargetClick, this.useCapture);
1943
+ el.addEventListener('click', this._onPopoverTargetClick, useCapture);
1944
1944
  this._popoverTargetEntries.set(el, this._onPopoverTargetClick);
1945
1945
  }
1946
1946
  }
1947
1947
  }
1948
1948
  _clearPopoverTargetListeners() {
1949
+ const useCapture = Boolean(this._opt('useCapture'));
1949
1950
  for (const [el, listener] of this._popoverTargetEntries) {
1950
- el.removeEventListener('click', listener, this.useCapture);
1951
+ el.removeEventListener('click', listener, useCapture);
1951
1952
  }
1952
1953
  this._popoverTargetEntries.clear();
1953
1954
  }
1954
1955
  _syncModalContainer() {
1955
- if (this._renderInPlace || this._hasCustomFloatingElementContainer) {
1956
+ if (this._renderInPlace) {
1956
1957
  this._setTracked('_modalContainer', null);
1957
1958
  return false;
1958
1959
  }
1959
- const modalDialog = getModalDialogContainer(this._listenerTarget || this._parentElement);
1960
+ const modalDialog = getModalDialogContainer(this._listenerTarget);
1960
1961
  if (this._modalContainer !== modalDialog) {
1961
1962
  this._modalContainer = modalDialog;
1962
1963
  return true;
@@ -1967,66 +1968,142 @@ let AttacherCore = (_class = class AttacherCore {
1967
1968
  if (!isVisible) {
1968
1969
  this._cleanup?.();
1969
1970
  this._cleanup = null;
1971
+ return;
1970
1972
  }
1971
- if (!this._floatingElement) {
1973
+ this._isHidden = false;
1974
+ const el = this._floatingElement;
1975
+ if (!el) {
1972
1976
  return;
1973
1977
  }
1974
- this._floatingElement.style.display = isVisible ? 'block' : 'none';
1975
- // Prevent jank until _startShowAnimation() positions the attachment.
1976
- this._floatingElement.style.visibility = isVisible ? 'hidden' : '';
1978
+ const showDuration = parseInt(String(this._opt('showDuration') ?? 0), 10) || 0;
1979
+ const initialPlacement = this._opt('placement') || DEFAULTS.placement;
1980
+ el.removeAttribute('data-closing');
1981
+ if (!el.hasAttribute('data-placement')) {
1982
+ el.setAttribute('data-placement', initialPlacement);
1983
+ }
1984
+ if (!el.hasAttribute('x-placement')) {
1985
+ el.setAttribute('x-placement', initialPlacement);
1986
+ }
1987
+ el.style.setProperty('--ember-attacher-transition-duration', `${showDuration}ms`);
1988
+ if (!el.classList.contains('ember-attacher')) {
1989
+ el.style.display = 'block';
1990
+ } else if (el.style.display === 'none') {
1991
+ el.style.display = '';
1992
+ }
1993
+ if (!el.style.left) {
1994
+ // Avoid a 0,0 flash for the microtask before computePosition() resolves.
1995
+ el.style.visibility = 'hidden';
1996
+ } else if (!el.hasAttribute('data-reference-hidden') && !el.hasAttribute('data-escaped')) {
1997
+ el.style.visibility = '';
1998
+ }
1999
+ el.setAttribute('data-open', '');
2000
+ el.setAttribute('aria-hidden', 'false');
1977
2001
  this._syncingPopoverHost = true;
1978
2002
  try {
1979
2003
  if (!this._skipNativePopoverToggle) {
1980
- if (isVisible) {
1981
- showPopoverHost(this._floatingElement);
1982
- } else {
1983
- hidePopoverHost(this._floatingElement);
1984
- }
2004
+ showPopoverHost(el);
1985
2005
  }
1986
2006
  } finally {
1987
2007
  this._syncingPopoverHost = false;
1988
2008
  }
1989
- this._arg('onChange')?.(isVisible);
2009
+ this._arg('onChange')?.(true);
1990
2010
  }
1991
- _setIsVisibleAfterDelay(isVisible, delay) {
1992
- if (!this._floatingElement) {
1993
- this._scheduleAnimationFrame(() => {
1994
- if (this._isDestroyed || (isVisible ? this._isHiding : !this._isHiding)) {
1995
- return;
1996
- }
1997
- this._setIsVisibleAfterDelay(isVisible, delay);
1998
- });
2011
+ _waitForExitAnimations(element, hideDuration, onDone) {
2012
+ if (hideDuration <= 0 || !element) {
2013
+ onDone();
1999
2014
  return;
2000
2015
  }
2001
- if (delay) {
2002
- this._delayedVisibilityToggle = later(this, () => {
2003
- if (this._isDestroyed || (isVisible ? this._isHiding : !this._isHiding)) {
2004
- return;
2016
+
2017
+ // Flush styles so CSS transitions triggered by [data-closing] are registered
2018
+ // before querying WAAPI animations on the same turn.
2019
+ if (typeof getComputedStyle === 'function') {
2020
+ void getComputedStyle(element).opacity;
2021
+ }
2022
+ const animations = typeof element.getAnimations === 'function' ? element.getAnimations({
2023
+ subtree: true
2024
+ }) : [];
2025
+ const generation = this._closeGeneration;
2026
+ const token = attacherWaiter.beginAsync();
2027
+ let done = false;
2028
+ let timeoutId = null;
2029
+ const finish = () => {
2030
+ if (done) {
2031
+ return;
2032
+ }
2033
+ done = true;
2034
+ if (timeoutId !== null) {
2035
+ clearTimeout(timeoutId);
2036
+ timeoutId = null;
2037
+ }
2038
+ attacherWaiter.endAsync(token);
2039
+ this._activeCloseCancel = null;
2040
+ if (!this._isDestroyed && this._closeGeneration === generation && this._isHiding) {
2041
+ onDone();
2042
+ }
2043
+ };
2044
+ this._activeCloseCancel = () => {
2045
+ if (!done) {
2046
+ done = true;
2047
+ if (timeoutId !== null) {
2048
+ clearTimeout(timeoutId);
2049
+ timeoutId = null;
2005
2050
  }
2006
- this._scheduleAnimationFrame(() => {
2007
- if (this._isDestroyed || (isVisible ? this._isHiding : !this._isHiding)) {
2008
- return;
2009
- }
2010
- this._applyVisibility(isVisible);
2011
- });
2012
- }, delay);
2051
+ attacherWaiter.endAsync(token);
2052
+ this._activeCloseCancel = null;
2053
+ }
2054
+ };
2055
+ if (animations.length > 0) {
2056
+ timeoutId = setTimeout(finish, hideDuration + 250);
2057
+ Promise.allSettled(animations.map(anim => anim.finished)).then(finish);
2013
2058
  } else {
2014
- this._applyVisibility(isVisible);
2059
+ // Fall back to hideDuration timer when no WAAPI animations are reported
2060
+ // (older engines, headless custom markup without CSS transitions, etc.)
2061
+ // so exit never silently short-circuits to an instant hide.
2062
+ timeoutId = setTimeout(finish, hideDuration);
2063
+ }
2064
+ }
2065
+ _finishHide() {
2066
+ const el = this._floatingElement;
2067
+ if (el) {
2068
+ el.style.setProperty('--ember-attacher-transition-duration', '0ms');
2069
+ el.removeAttribute('data-closing');
2070
+ el.removeAttribute('data-open');
2071
+ if (!el.classList.contains('ember-attacher')) {
2072
+ el.style.display = 'none';
2073
+ } else {
2074
+ el.style.display = '';
2075
+ }
2076
+ el.style.visibility = '';
2077
+ this._syncingPopoverHost = true;
2078
+ try {
2079
+ if (!this._skipNativePopoverToggle) {
2080
+ hidePopoverHost(el);
2081
+ }
2082
+ } finally {
2083
+ this._syncingPopoverHost = false;
2084
+ }
2015
2085
  }
2086
+ this._arg('onChange')?.(false);
2087
+ }
2088
+ _cancelCloseAnimation() {
2089
+ this._closeGeneration += 1;
2090
+ this._activeCloseCancel?.();
2091
+ this._activeCloseCancel = null;
2016
2092
  }
2017
2093
  show(target = undefined, data = undefined) {
2018
2094
  if (typeof Event !== 'undefined' && target instanceof Event) {
2019
2095
  target = undefined;
2020
2096
  }
2021
2097
  if (target !== undefined) {
2022
- if (this._registeredEntries.has(target)) {
2023
- const entry = this._registeredEntries.get(target);
2098
+ const targetEl = target;
2099
+ const entry = isElementTarget(targetEl) ? this._registeredEntries.get(targetEl) : undefined;
2100
+ if (entry) {
2024
2101
  if (data !== undefined) {
2025
2102
  entry.data = data;
2026
2103
  }
2027
2104
  this._activateRegisteredEntry(entry);
2028
- } else if (isElementTarget(target) || isVirtualReference(target)) {
2029
- this._switchTargetFromEvent(target, data, this._activeEntryOptions);
2105
+ } else if (isElementTarget(targetEl) || isVirtualReference(targetEl)) {
2106
+ this._switchTargetFromEvent(targetEl, data, this._activeEntryOptions);
2030
2107
  } else {
2031
2108
  runInDebug(() => {
2032
2109
  warn('[ember-attacher] Ignoring non-Target argument passed to show().', false, {
@@ -2034,10 +2111,13 @@ let AttacherCore = (_class = class AttacherCore {
2034
2111
  });
2035
2112
  });
2036
2113
  }
2114
+ } else if (data !== undefined) {
2115
+ this._setTracked('_data', data);
2116
+ this._notifyRenderStateChange();
2037
2117
  }
2038
2118
  this._show();
2039
2119
  if (!this._isDestroyed) {
2040
- next(this, () => {
2120
+ scheduleMicrotask(() => {
2041
2121
  if (!this._isDestroyed && !this._isHidden) {
2042
2122
  this._addListenersForHideEvents();
2043
2123
  }
@@ -2058,13 +2138,14 @@ let AttacherCore = (_class = class AttacherCore {
2058
2138
  this._updatePosition();
2059
2139
  }
2060
2140
  setTarget(target, data = undefined) {
2061
- cancel(this._setReferenceTimer);
2141
+ this._usedSetTarget = true;
2142
+ cancelScheduled(this._setTargetHandle);
2062
2143
  if (data !== undefined) {
2063
2144
  this._pendingRegisteredData = data;
2064
2145
  this._hasPendingData = true;
2065
2146
  }
2066
- this._setReferenceTimer = schedule('actions', () => {
2067
- this._setReferenceTimer = null;
2147
+ this._setTargetHandle = scheduleMicrotask(() => {
2148
+ this._setTargetHandle = null;
2068
2149
  if (this._isDestroyed) {
2069
2150
  return;
2070
2151
  }
@@ -2083,13 +2164,24 @@ let AttacherCore = (_class = class AttacherCore {
2083
2164
  this._initializeAttacher();
2084
2165
  });
2085
2166
  }
2086
- setReference(target) {
2087
- this._deprecateOnce('ember-attacher.api.set-reference', '[ember-attacher] The yielded `setReference` method is deprecated and will be removed in ember-attacher 5.0.0. Use `setTarget` instead.');
2088
- this.setTarget(target);
2167
+ _warnRemoved4xArgs(args) {
2168
+ if (!args) {
2169
+ return;
2170
+ }
2171
+ runInDebug(() => {
2172
+ for (const argName of Object.keys(REMOVED_4X_ARGS)) {
2173
+ if (args[argName] !== undefined && !this._warnedRemovedArgs.has(argName)) {
2174
+ this._warnedRemovedArgs.add(argName);
2175
+ warn(`[ember-attacher] @${argName} was removed in 5.0.0 and is ignored. ${REMOVED_4X_ARGS[argName]}`, false, {
2176
+ id: `ember-attacher.removed-arg.${argName}`
2177
+ });
2178
+ }
2179
+ }
2180
+ });
2089
2181
  }
2090
2182
  _ensureArgumentsAreValid() {
2091
2183
  runInDebug(() => {
2092
- if (this.useCapture !== this._lastUseCaptureArgumentValue) {
2184
+ if (Boolean(this._opt('useCapture')) !== this._lastUseCaptureArgumentValue) {
2093
2185
  warn('The value of the useCapture argument was mutated', {
2094
2186
  id: 'ember-attacher.use-capture-mutated'
2095
2187
  });
@@ -2097,91 +2189,98 @@ let AttacherCore = (_class = class AttacherCore {
2097
2189
  });
2098
2190
  }
2099
2191
  _syncAria() {
2192
+ const entryText = this._data != null && this._data !== '' ? String(this._data) : null;
2100
2193
  this._aria.bind(this._listenerTarget, {
2101
2194
  isTooltip: this._isTooltip,
2102
2195
  id: this.id,
2103
2196
  ariaRole: this.ariaRole,
2104
- isOpen: this._ariaOpen
2197
+ isOpen: this._ariaOpen,
2198
+ attachmentEl: this._floatingElement,
2199
+ tooltipText: entryText
2105
2200
  });
2106
2201
  }
2107
2202
  _initializeAttacher() {
2108
2203
  if (this._isDestroyed) {
2109
2204
  return;
2110
2205
  }
2111
- this._checkDeprecatedArgs(this._getArgs());
2112
- this._removeLegacyShowEventListeners();
2206
+ this._removeTargetShowEventListeners();
2113
2207
  this._removeHideEventListeners();
2114
2208
  const explicitId = this._arg('id') || this._elementId;
2115
- const popoverTargets = explicitId ? findPopoverTargetElements(explicitId) : [];
2209
+ const {
2210
+ popoverTargets,
2211
+ allTargets
2212
+ } = explicitId ? findTriggerTargetElements(explicitId) : {
2213
+ popoverTargets: [],
2214
+ allTargets: []
2215
+ };
2116
2216
  this._syncPopoverTargetListeners(popoverTargets);
2117
2217
  const target = resolveAttachmentTarget({
2118
- explicitTarget: this.explicitTarget,
2218
+ target: this.targetArg,
2119
2219
  registeredTarget: this._registeredTarget,
2120
- popoverTargets,
2121
- parentElement: this._parentElement,
2122
- allowParentFallback: this._allowParentFallback
2220
+ triggerTargets: allTargets
2123
2221
  });
2124
- const usedParentFallback = this._allowParentFallback && this.explicitTarget == null && this._registeredTarget == null && popoverTargets.length === 0 && target != null && target === this._parentElement;
2125
- if (usedParentFallback) {
2126
- this._deprecateOnce('ember-attacher.implicit-parent-target', '[ember-attacher] Attaching implicitly to the parent DOM element is deprecated and will be removed in ember-attacher 5.0.0. Bind an explicit Target with {{tooltip}}, @target, {{a.target}}, <:target>, or [popovertarget].');
2127
- }
2128
2222
  this._listenerTarget = getListenerTarget(target);
2129
2223
  this._setTracked('_currentTarget', target);
2130
- if (target && this._registeredEntries.has(target)) {
2224
+ if (isElementTarget(target) && this._registeredEntries.has(target)) {
2131
2225
  const entry = this._registeredEntries.get(target);
2132
2226
  this._activeEntryOptions = entry.options || null;
2133
2227
  this._setTracked('_data', entry.data);
2134
2228
  }
2135
2229
  this._syncModalContainer();
2136
2230
  syncParentAttachment(this);
2137
- this._addLegacyShowListenersIfUnregistered();
2231
+ this._addShowListenersIfUnregistered();
2138
2232
  this._notifyRenderStateChange();
2139
- const shouldBeOpen = !this._isHiding && (!this._isHidden || this._isShown) || Boolean(this.controlledIsShown);
2140
- if (shouldBeOpen) {
2233
+ const shouldBeOpen = !this._isHiding && (!this._isHidden || this._isShown) || Boolean(this._opt('isShown'));
2234
+ if (shouldBeOpen && target) {
2141
2235
  this._ariaOpen = true;
2142
2236
  this._syncAria();
2143
2237
  this._addListenersForHideEvents();
2144
2238
  if (!this._isShown) {
2145
2239
  this._show();
2146
- } else if (this._floatingElement && this._floatingElement.style.display !== 'block') {
2147
- this._cancelAnimation();
2148
- this._applyVisibility(true);
2149
- this._startShowAnimation();
2150
2240
  } else {
2241
+ this._applyVisibility(true);
2151
2242
  this._update();
2152
2243
  }
2153
2244
  } else {
2154
2245
  this._ariaOpen = false;
2155
2246
  this._syncAria();
2156
2247
  }
2157
- this._arg('onInitializeAttacher')?.(this._currentTarget, this.id);
2158
2248
  }
2159
- _addLegacyShowListenersIfUnregistered() {
2249
+ _addShowListenersIfUnregistered() {
2160
2250
  const target = this._listenerTarget;
2161
2251
  if (!target || this._registeredEntries.has(target) || this._popoverTargetEntries.has(target)) {
2162
2252
  return;
2163
2253
  }
2254
+ const useCapture = Boolean(this._opt('useCapture'));
2164
2255
  this._showOn.forEach(event => {
2165
- this._legacyShowListenersOnTargetByEvent[event] = this._showAfterDelay;
2166
- target.addEventListener(event, this._showAfterDelay, this.useCapture);
2256
+ this._targetShowListenersByEvent[event] = this._showAfterDelay;
2257
+ target.addEventListener(event, this._showAfterDelay, useCapture);
2167
2258
  });
2168
2259
  }
2169
- _removeLegacyShowEventListeners() {
2260
+ _removeTargetShowEventListeners() {
2170
2261
  const target = this._listenerTarget;
2171
2262
  if (!target) {
2172
2263
  return;
2173
2264
  }
2174
- Object.keys(this._legacyShowListenersOnTargetByEvent).forEach(event => {
2175
- target.removeEventListener(event, this._legacyShowListenersOnTargetByEvent[event], this.useCapture);
2176
- delete this._legacyShowListenersOnTargetByEvent[event];
2265
+ const useCapture = Boolean(this._opt('useCapture'));
2266
+ Object.keys(this._targetShowListenersByEvent).forEach(event => {
2267
+ const listener = this._targetShowListenersByEvent[event];
2268
+ if (listener) {
2269
+ target.removeEventListener(event, listener, useCapture);
2270
+ }
2271
+ delete this._targetShowListenersByEvent[event];
2177
2272
  });
2178
2273
  }
2179
2274
  _removeHideEventListeners({
2180
2275
  restoreClickShow = false
2181
2276
  } = {}) {
2277
+ const useCapture = Boolean(this._opt('useCapture'));
2182
2278
  this._mouseLeaveOrigin = null;
2183
2279
  Object.keys(this._hideListenersOnDocumentByEvent).forEach(eventType => {
2184
- document.removeEventListener(eventType, this._hideListenersOnDocumentByEvent[eventType], this.useCapture);
2280
+ const listener = this._hideListenersOnDocumentByEvent[eventType];
2281
+ if (listener) {
2282
+ document.removeEventListener(eventType, listener, useCapture);
2283
+ }
2185
2284
  delete this._hideListenersOnDocumentByEvent[eventType];
2186
2285
  });
2187
2286
  const target = this._listenerTarget;
@@ -2191,23 +2290,26 @@ let AttacherCore = (_class = class AttacherCore {
2191
2290
  if (restoreClickShow && this._showOn.includes('click') && !this._registeredEntries.has(target) && !this._popoverTargetEntries.has(target)) {
2192
2291
  const hideOnClickListener = this._hideListenersOnTargetByEvent.click;
2193
2292
  if (hideOnClickListener) {
2194
- target.removeEventListener('click', hideOnClickListener, this.useCapture);
2293
+ target.removeEventListener('click', hideOnClickListener, useCapture);
2195
2294
  delete this._hideListenersOnTargetByEvent.click;
2196
2295
  }
2197
- this._legacyShowListenersOnTargetByEvent.click = this._showAfterDelay;
2198
- target.addEventListener('click', this._showAfterDelay, this.useCapture);
2296
+ this._targetShowListenersByEvent.click = this._showAfterDelay;
2297
+ target.addEventListener('click', this._showAfterDelay, useCapture);
2199
2298
  }
2200
2299
  Object.keys(this._hideListenersOnTargetByEvent).forEach(event => {
2201
- target.removeEventListener(event, this._hideListenersOnTargetByEvent[event], this.useCapture);
2300
+ const listener = this._hideListenersOnTargetByEvent[event];
2301
+ if (listener) {
2302
+ target.removeEventListener(event, listener, useCapture);
2303
+ }
2202
2304
  delete this._hideListenersOnTargetByEvent[event];
2203
2305
  });
2204
2306
  }
2205
2307
  _syncIsShown() {
2206
- const isShown = this.controlledIsShown;
2308
+ const isShown = this._opt('isShown');
2207
2309
  if (isShown === true && this._isHidden) {
2208
2310
  this._show();
2209
- next(this, () => {
2210
- if (!this._isDestroyed) {
2311
+ scheduleMicrotask(() => {
2312
+ if (!this._isDestroyed && !this._isHidden) {
2211
2313
  this._addListenersForHideEvents();
2212
2314
  }
2213
2315
  });
@@ -2219,20 +2321,21 @@ let AttacherCore = (_class = class AttacherCore {
2219
2321
  if (this._suppressFocusShow && (event?.type === 'focus' || event?.type === 'focusin')) {
2220
2322
  return;
2221
2323
  }
2222
- cancel(this._delayedVisibilityToggle);
2223
- this._cancelAnimation();
2324
+ cancelScheduled(this._delayedVisibilityToggle);
2325
+ this._cancelCloseAnimation();
2224
2326
  this._isHiding = false;
2225
2327
  this._setTracked('_mustRender', true);
2226
2328
  syncParentAttachment(this);
2227
2329
  this._addListenersForHideEvents();
2228
- const parsedShowDelay = parseInt(this.showDelay, 10) || 0;
2330
+ const parsedShowDelay = parseInt(String(this._opt('showDelay') ?? 0), 10) || 0;
2229
2331
  const isWarm = Boolean(this._isTooltip && peekDelayGroup(this._delayGroupOwner)?.isWarmFor());
2230
2332
  const effectiveDelay = isWarm ? 0 : parsedShowDelay;
2231
- this._delayedVisibilityToggle = debounce(this, this._show, effectiveDelay, !effectiveDelay);
2333
+ this._delayedVisibilityToggle = debounceTimeout(this._delayedVisibilityToggle, this._show, effectiveDelay, !effectiveDelay);
2232
2334
  }
2233
2335
  _show() {
2234
- cancel(this._delayedVisibilityToggle);
2235
- this._cancelAnimation();
2336
+ cancelScheduled(this._delayedVisibilityToggle);
2337
+ this._delayedVisibilityToggle = null;
2338
+ this._cancelCloseAnimation();
2236
2339
  if (!this._currentTarget) {
2237
2340
  return;
2238
2341
  }
@@ -2242,67 +2345,27 @@ let AttacherCore = (_class = class AttacherCore {
2242
2345
  this._setTracked('_mustRender', true);
2243
2346
  this._setTracked('_isShown', true);
2244
2347
  this._ariaOpen = true;
2245
- this._aria.setOpen(true);
2246
- if (this._isTooltip && this.controlledIsShown !== true) {
2348
+ if (this._isTooltip && this._opt('isShown') !== true) {
2247
2349
  getDelayGroup(this._delayGroupOwner)?.open(this);
2248
2350
  }
2249
- const modalContainerChanged = this._syncModalContainer();
2351
+ this._syncModalContainer();
2250
2352
  syncParentAttachment(this);
2251
2353
  this._notifyRenderStateChange();
2252
- if (modalContainerChanged) {
2253
- next(this, () => {
2254
- if (!this._isDestroyed && !this._isHiding && this._currentTarget) {
2255
- this._setIsVisibleAfterDelay(true, 0);
2256
- this._startShowAnimation();
2257
- }
2258
- });
2259
- return;
2260
- }
2261
- this._setIsVisibleAfterDelay(true, 0);
2262
- this._startShowAnimation();
2263
- }
2264
- _startShowAnimation() {
2265
- this._scheduleAnimationFrame(() => {
2266
- if (this._isDestroyed || !this._currentTarget || this._isHiding) {
2267
- return;
2268
- }
2269
- const floatingElement = this._floatingElement;
2270
- if (!floatingElement || floatingElement.style.display === 'none') {
2271
- this._startShowAnimation();
2272
- return;
2273
- }
2274
- this._update();
2275
- this._scheduleAnimationFrame(() => {
2276
- if (this._isDestroyed || !this._currentTarget || this._isHiding) {
2277
- return;
2278
- }
2279
- run(() => {
2280
- if (this._isDestroyed || !this._currentTarget || this._isHiding) {
2281
- return;
2282
- }
2283
- if (!floatingElement.hasAttribute('data-reference-hidden') && !floatingElement.hasAttribute('data-escaped')) {
2284
- floatingElement.style.visibility = '';
2285
- }
2286
- const showDuration = parseInt(this.showDuration, 10) || 0;
2287
- floatingElement.style.setProperty('--ember-attacher-transition-duration', `${showDuration}ms`);
2288
- this._setTracked('_isStartingAnimation', true);
2289
- this._notifyRenderStateChange();
2290
- floatingElement.setAttribute('aria-hidden', 'false');
2291
- });
2292
- this._isHidden = false;
2293
- });
2294
- });
2354
+ this._applyVisibility(true);
2355
+ this._syncAria();
2356
+ this._update();
2295
2357
  }
2296
2358
  _hideAfterDelay() {
2297
- cancel(this._delayedVisibilityToggle);
2359
+ cancelScheduled(this._delayedVisibilityToggle);
2298
2360
  this._isHiding = true;
2299
- const hideDelay = parseInt(this.hideDelay, 10) || 0;
2300
- this._delayedVisibilityToggle = debounce(this, this._hide, hideDelay, !hideDelay);
2361
+ const hideDelay = parseInt(String(this._opt('hideDelay') ?? 0), 10) || 0;
2362
+ this._delayedVisibilityToggle = debounceTimeout(this._delayedVisibilityToggle, this._hide, hideDelay, !hideDelay);
2301
2363
  }
2302
2364
  _hide() {
2303
2365
  const wasShown = this._isShown || !this._isHidden;
2304
- cancel(this._delayedVisibilityToggle);
2305
- this._cancelAnimation();
2366
+ cancelScheduled(this._delayedVisibilityToggle);
2367
+ this._delayedVisibilityToggle = null;
2368
+ this._cancelCloseAnimation();
2306
2369
  this._isHiding = true;
2307
2370
  this._positioningSuspended = true;
2308
2371
  this._ariaOpen = false;
@@ -2318,104 +2381,109 @@ let AttacherCore = (_class = class AttacherCore {
2318
2381
  this._removeHideEventListeners({
2319
2382
  restoreClickShow: true
2320
2383
  });
2321
- if (!this._floatingElement) {
2322
- this._setTracked('_isStartingAnimation', false);
2323
- this._aria.setOpen(false);
2324
- this._isHidden = true;
2325
- return;
2384
+ if (this._restoreFocusOnHide) {
2385
+ this._restoreFocusOnHide = false;
2386
+ this._suppressFocusShow = true;
2387
+ try {
2388
+ restoreFocusOnEscape(this._listenerTarget, this._floatingElement);
2389
+ } finally {
2390
+ this._suppressFocusShow = false;
2391
+ }
2326
2392
  }
2327
- this._scheduleAnimationFrame(() => {
2328
- if (this._isDestroyed || !this._isHiding) {
2329
- return;
2393
+ this._aria.setOpen(false);
2394
+ this._isHidden = true;
2395
+ this._notifyRenderStateChange();
2396
+ const floatingElement = this._floatingElement;
2397
+ if (!floatingElement) {
2398
+ if (wasShown) {
2399
+ this._arg('onChange')?.(false);
2330
2400
  }
2331
- const hideDuration = parseInt(this.hideDuration, 10) || 0;
2332
- run(() => {
2333
- if (this._isDestroyed || !this._isHiding) {
2334
- return;
2335
- }
2336
- if (this._restoreFocusOnHide) {
2337
- this._restoreFocusOnHide = false;
2338
- this._suppressFocusShow = true;
2339
- try {
2340
- restoreFocusOnEscape(this._listenerTarget, this._floatingElement);
2341
- } finally {
2342
- this._suppressFocusShow = false;
2343
- }
2344
- }
2345
- if (this._floatingElement) {
2346
- this._floatingElement.style.setProperty('--ember-attacher-transition-duration', `${hideDuration}ms`);
2347
- this._floatingElement.setAttribute('aria-hidden', 'true');
2348
- }
2349
- this._setTracked('_isStartingAnimation', false);
2350
- this._notifyRenderStateChange();
2351
- this._aria.setOpen(false);
2352
- this._setIsVisibleAfterDelay(false, hideDuration);
2353
- });
2354
- this._isHidden = true;
2401
+ return;
2402
+ }
2403
+ const hideDuration = parseInt(String(this._opt('hideDuration') ?? 0), 10) || 0;
2404
+ floatingElement.setAttribute('aria-hidden', 'true');
2405
+ if (hideDuration <= 0) {
2406
+ this._finishHide();
2407
+ return;
2408
+ }
2409
+ floatingElement.style.setProperty('--ember-attacher-transition-duration', `${hideDuration}ms`);
2410
+ floatingElement.setAttribute('data-closing', '');
2411
+ this._waitForExitAnimations(floatingElement, hideDuration, () => {
2412
+ this._finishHide();
2355
2413
  });
2356
2414
  }
2357
2415
  _addListenersForHideEvents() {
2358
2416
  const hideOn = this._hideOn;
2359
2417
  const target = this._listenerTarget;
2418
+ const useCapture = Boolean(this._opt('useCapture'));
2360
2419
  if (!this._currentTarget || this._isDestroyed) {
2361
2420
  return;
2362
2421
  }
2363
2422
  const entry = target ? this._registeredEntries.get(target) : null;
2364
2423
  const entryHandlesClickToggle = Boolean(entry && entry.showOnKey?.split(' ').includes('click')) || Boolean(target && this._popoverTargetEntries.has(target));
2365
2424
  if (target && hideOn.includes('click') && !entryHandlesClickToggle) {
2366
- const showOnClickListener = this._legacyShowListenersOnTargetByEvent.click;
2425
+ const showOnClickListener = this._targetShowListenersByEvent.click;
2367
2426
  if (showOnClickListener) {
2368
- target.removeEventListener('click', showOnClickListener, this.useCapture);
2369
- delete this._legacyShowListenersOnTargetByEvent.click;
2427
+ target.removeEventListener('click', showOnClickListener, useCapture);
2428
+ delete this._targetShowListenersByEvent.click;
2370
2429
  }
2371
2430
  this._hideListenersOnTargetByEvent.click = this._hideAfterDelay;
2372
- target.addEventListener('click', this._hideAfterDelay, this.useCapture);
2431
+ target.addEventListener('click', this._hideAfterDelay, useCapture);
2373
2432
  }
2374
2433
  if (hideOn.includes('clickout') && !this._hideListenersOnDocumentByEvent.click && !this._hideListenersOnDocumentByEvent.touchend) {
2375
- const clickoutEvent = 'ontouchstart' in window ? 'touchend' : 'click';
2434
+ const clickoutEvent = typeof window !== 'undefined' && 'ontouchstart' in window ? 'touchend' : 'click';
2376
2435
  this._hideListenersOnDocumentByEvent[clickoutEvent] = this._hideOnClickOut;
2377
- document.addEventListener(clickoutEvent, this._hideOnClickOut, this.useCapture);
2436
+ document.addEventListener(clickoutEvent, this._hideOnClickOut, useCapture);
2378
2437
  }
2379
2438
  if (hideOn.includes('escapekey') && !this._hideListenersOnDocumentByEvent.keydown) {
2380
2439
  this._hideListenersOnDocumentByEvent.keydown = this._hideOnEscapeKey;
2381
- document.addEventListener('keydown', this._hideOnEscapeKey, this.useCapture);
2440
+ document.addEventListener('keydown', this._hideOnEscapeKey, useCapture);
2382
2441
  }
2383
2442
  if (target && hideOn.includes('mouseleave') && !this._hideListenersOnTargetByEvent.mouseleave) {
2384
2443
  this._hideListenersOnTargetByEvent.mouseleave = this._hideOnMouseLeaveTarget;
2385
- target.addEventListener('mouseleave', this._hideOnMouseLeaveTarget, this.useCapture);
2444
+ target.addEventListener('mouseleave', this._hideOnMouseLeaveTarget, useCapture);
2386
2445
  }
2387
2446
  if (target) {
2388
2447
  ['blur', 'focusout'].forEach(eventType => {
2389
2448
  if (hideOn.includes(eventType) && !this._hideListenersOnTargetByEvent[eventType]) {
2390
2449
  this._hideListenersOnTargetByEvent[eventType] = this._hideOnLostFocus;
2391
- target.addEventListener(eventType, this._hideOnLostFocus, this.useCapture);
2450
+ target.addEventListener(eventType, this._hideOnLostFocus, useCapture);
2392
2451
  }
2393
2452
  });
2394
2453
  }
2395
2454
  }
2396
- _hideOnMouseLeaveTarget(event) {
2397
- if (this.interactive) {
2455
+ _hideOnMouseLeaveTarget(rawEvent) {
2456
+ const event = rawEvent;
2457
+ if (this._isHidden && !this._isShown) {
2458
+ this._hideAfterDelay();
2459
+ return;
2460
+ }
2461
+ if (this._opt('interactive')) {
2398
2462
  this._mouseLeaveOrigin = event ? {
2399
2463
  x: event.clientX,
2400
2464
  y: event.clientY
2401
2465
  } : null;
2402
2466
  if (!this._hideListenersOnDocumentByEvent.mousemove) {
2467
+ const useCapture = Boolean(this._opt('useCapture'));
2403
2468
  this._hideListenersOnDocumentByEvent.mousemove = this._hideIfMouseOutsideTargetOrAttachment;
2404
- document.addEventListener('mousemove', this._hideIfMouseOutsideTargetOrAttachment, this.useCapture);
2469
+ document.addEventListener('mousemove', this._hideIfMouseOutsideTargetOrAttachment, useCapture);
2405
2470
  }
2406
2471
  } else {
2407
2472
  this._hideAfterDelay();
2408
2473
  }
2409
2474
  }
2410
- _hideIfMouseOutsideTargetOrAttachment(event) {
2475
+ _hideIfMouseOutsideTargetOrAttachment(rawEvent) {
2476
+ const event = rawEvent;
2411
2477
  const target = this._listenerTarget;
2412
2478
  if (!target) {
2413
2479
  return;
2414
2480
  }
2415
- if (!target.contains(event.target) && !descendantAttachmentContainsEvent(this, event) && !isCursorInSafePolygon(event, this._mouseLeaveOrigin, this._currentTarget, this._floatingElement) && this._floatingElement && !this._floatingElement.contains(event.target)) {
2481
+ const eventTarget = event.target instanceof Node ? event.target : null;
2482
+ if (!target.contains(eventTarget) && !descendantAttachmentContainsEvent(this, event) && !isCursorInSafePolygon(event, this._mouseLeaveOrigin, this._currentTarget, this._floatingElement) && this._floatingElement && !this._floatingElement.contains(eventTarget)) {
2483
+ const useCapture = Boolean(this._opt('useCapture'));
2416
2484
  this._mouseLeaveOrigin = null;
2417
2485
  delete this._hideListenersOnDocumentByEvent.mousemove;
2418
- document.removeEventListener('mousemove', this._hideIfMouseOutsideTargetOrAttachment, this.useCapture);
2486
+ document.removeEventListener('mousemove', this._hideIfMouseOutsideTargetOrAttachment, useCapture);
2419
2487
  this._hideAfterDelay();
2420
2488
  }
2421
2489
  }
@@ -2424,17 +2492,19 @@ let AttacherCore = (_class = class AttacherCore {
2424
2492
  if (elementContainsEvent(target, event) || descendantAttachmentContainsEvent(this, event)) {
2425
2493
  return;
2426
2494
  }
2427
- if (!this.interactive || !elementContainsEvent(this._floatingElement, event)) {
2495
+ if (!this._opt('interactive') || !floatingElementContainsEvent(this._floatingElement, event)) {
2428
2496
  this._hideAfterDelay();
2429
2497
  }
2430
2498
  }
2431
- _hideOnEscapeKey(event) {
2499
+ _hideOnEscapeKey(rawEvent) {
2500
+ const event = rawEvent;
2432
2501
  if ((event.key === 'Escape' || event.keyCode === 27) && shouldHandleEscapeKey(this, event)) {
2433
2502
  this._restoreFocusOnHide = !this._isTooltip;
2434
- return this._hideAfterDelay();
2503
+ this._hideAfterDelay();
2435
2504
  }
2436
2505
  }
2437
- _hideOnLostFocus(event) {
2506
+ _hideOnLostFocus(rawEvent) {
2507
+ const event = rawEvent;
2438
2508
  if (event.relatedTarget === null) {
2439
2509
  this._hideAfterDelay();
2440
2510
  return;
@@ -2443,10 +2513,11 @@ let AttacherCore = (_class = class AttacherCore {
2443
2513
  if (!target) {
2444
2514
  return;
2445
2515
  }
2446
- if (target.contains(event.relatedTarget) || descendantAttachmentContainsNode(this, event.relatedTarget)) {
2516
+ const relatedNode = event.relatedTarget instanceof Node ? event.relatedTarget : null;
2517
+ if (target.contains(relatedNode) || descendantAttachmentContainsNode(this, relatedNode)) {
2447
2518
  return;
2448
2519
  }
2449
- if (!this.interactive || !this._floatingElement?.contains(event.relatedTarget)) {
2520
+ if (!this._opt('interactive') || !this._floatingElement?.contains(relatedNode)) {
2450
2521
  this._hideAfterDelay();
2451
2522
  }
2452
2523
  }
@@ -2456,8 +2527,9 @@ let AttacherCore = (_class = class AttacherCore {
2456
2527
  if (this._isDestroyed || this._positioningSuspended || !this._currentTarget || !this._floatingElement || !isTargetConnected(this._currentTarget) || !this._floatingElement.isConnected) {
2457
2528
  return;
2458
2529
  }
2459
- if (this.autoUpdate) {
2460
- this._cleanup = autoUpdate(this._currentTarget, this._floatingElement, this._updatePosition, typeof this.autoUpdate === 'object' && this.autoUpdate !== null ? this.autoUpdate : undefined);
2530
+ const autoUpdateOpt = this._opt('autoUpdate');
2531
+ if (autoUpdateOpt) {
2532
+ this._cleanup = autoUpdate(this._currentTarget, this._floatingElement, this._updatePosition, typeof autoUpdateOpt === 'object' && autoUpdateOpt !== null ? autoUpdateOpt : undefined);
2461
2533
  } else {
2462
2534
  this._updatePosition();
2463
2535
  }
@@ -2471,12 +2543,11 @@ let AttacherCore = (_class = class AttacherCore {
2471
2543
  this._cleanup = null;
2472
2544
  return;
2473
2545
  }
2474
- const strategy = this.strategy;
2475
- const computePositionToken = animationTestWaiter.beginAsync();
2546
+ const strategy = this._opt('strategy') || DEFAULTS.strategy;
2547
+ const computePositionToken = attacherWaiter.beginAsync();
2476
2548
  computePosition(this._currentTarget, this._floatingElement, {
2477
- ...this.floatingUiOptions,
2478
2549
  middleware: this._middleware,
2479
- placement: this.placement,
2550
+ placement: this._opt('placement'),
2480
2551
  strategy
2481
2552
  }).then(({
2482
2553
  x,
@@ -2485,7 +2556,7 @@ let AttacherCore = (_class = class AttacherCore {
2485
2556
  strategy: computedStrategy,
2486
2557
  middlewareData
2487
2558
  }) => {
2488
- animationTestWaiter.endAsync(computePositionToken);
2559
+ attacherWaiter.endAsync(computePositionToken);
2489
2560
  if (this._isDestroyed || !this._floatingElement || !this._floatingElement.isConnected) {
2490
2561
  return;
2491
2562
  }
@@ -2502,7 +2573,7 @@ let AttacherCore = (_class = class AttacherCore {
2502
2573
  this._middlewareData = middlewareData;
2503
2574
  }
2504
2575
  }).catch(error => {
2505
- animationTestWaiter.endAsync(computePositionToken);
2576
+ attacherWaiter.endAsync(computePositionToken);
2506
2577
  if (!this._isDestroyed) {
2507
2578
  warn(`[ember-attacher] Positioning error: ${error?.message ?? error}`, {
2508
2579
  id: 'ember-attacher.positioning-error'
@@ -2510,31 +2581,6 @@ let AttacherCore = (_class = class AttacherCore {
2510
2581
  }
2511
2582
  });
2512
2583
  }
2513
- _scheduleAnimationFrame(callback) {
2514
- if (typeof requestAnimationFrame !== 'function') {
2515
- return;
2516
- }
2517
- const token = animationTestWaiter.beginAsync();
2518
- const entry = {
2519
- id: null,
2520
- token
2521
- };
2522
- entry.id = requestAnimationFrame(() => {
2523
- this._pendingRafs.delete(entry);
2524
- animationTestWaiter.endAsync(token);
2525
- callback();
2526
- });
2527
- this._pendingRafs.add(entry);
2528
- }
2529
- _cancelAnimation() {
2530
- for (const entry of this._pendingRafs) {
2531
- if (typeof cancelAnimationFrame === 'function') {
2532
- cancelAnimationFrame(entry.id);
2533
- }
2534
- animationTestWaiter.endAsync(entry.token);
2535
- }
2536
- this._pendingRafs.clear();
2537
- }
2538
2584
  destroy() {
2539
2585
  if (this._isDestroyed) {
2540
2586
  return;
@@ -2546,101 +2592,78 @@ let AttacherCore = (_class = class AttacherCore {
2546
2592
  unregisterAttacher(this);
2547
2593
  this._cleanup?.();
2548
2594
  this._cleanup = null;
2549
- cancel(this._syncArgsTimer);
2550
- cancel(this._setReferenceTimer);
2551
- this._cancelAnimation();
2552
- cancel(this._delayedVisibilityToggle);
2595
+ cancelScheduled(this._syncArgsHandle);
2596
+ cancelScheduled(this._setTargetHandle);
2597
+ this._cancelCloseAnimation();
2598
+ cancelScheduled(this._delayedVisibilityToggle);
2553
2599
  this._detachPopoverEvents(this._attachedPopoverEventsOn);
2554
2600
  this._aria.unbind();
2555
- this._removeLegacyShowEventListeners();
2601
+ this._removeTargetShowEventListeners();
2556
2602
  this._removeHideEventListeners();
2557
2603
  this._clearPopoverTargetListeners();
2558
2604
  for (const entry of this._registeredEntries.values()) {
2559
- cancel(entry.updateTimer);
2605
+ cancelScheduled(entry.updateHandle);
2560
2606
  this._removeEntryShowListeners(entry);
2561
2607
  }
2562
2608
  this._registeredEntries.clear();
2563
- this._checkDeprecatedArgs(this._getArgs());
2564
- this._arg('onWillDestroy')?.(this._currentTarget, this.id);
2565
- }
2566
- }, _descriptor = _applyDecoratedDescriptor(_class.prototype, "_parentNotFound", [tracked], {
2567
- configurable: true,
2568
- enumerable: true,
2569
- writable: true,
2570
- initializer: function () {
2571
- return true;
2572
- }
2573
- }), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "_parentElement", [tracked], {
2574
- configurable: true,
2575
- enumerable: true,
2576
- writable: true,
2577
- initializer: function () {
2578
- return null;
2579
- }
2580
- }), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, "_isStartingAnimation", [tracked], {
2581
- configurable: true,
2582
- enumerable: true,
2583
- writable: true,
2584
- initializer: function () {
2585
- return false;
2586
2609
  }
2587
- }), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, "_arrowElement", [tracked], {
2610
+ }, _descriptor = _applyDecoratedDescriptor(_class.prototype, "_arrowElement", [tracked], {
2588
2611
  configurable: true,
2589
2612
  enumerable: true,
2590
2613
  writable: true,
2591
2614
  initializer: function () {
2592
2615
  return null;
2593
2616
  }
2594
- }), _descriptor5 = _applyDecoratedDescriptor(_class.prototype, "_currentTarget", [tracked], {
2617
+ }), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "_currentTarget", [tracked], {
2595
2618
  configurable: true,
2596
2619
  enumerable: true,
2597
2620
  writable: true,
2598
2621
  initializer: function () {
2599
2622
  return null;
2600
2623
  }
2601
- }), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, "_registeredTarget", [tracked], {
2624
+ }), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, "_registeredTarget", [tracked], {
2602
2625
  configurable: true,
2603
2626
  enumerable: true,
2604
2627
  writable: true,
2605
2628
  initializer: function () {
2606
2629
  return null;
2607
2630
  }
2608
- }), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, "_mustRender", [tracked], {
2631
+ }), _descriptor4 = _applyDecoratedDescriptor(_class.prototype, "_mustRender", [tracked], {
2609
2632
  configurable: true,
2610
2633
  enumerable: true,
2611
2634
  writable: true,
2612
2635
  initializer: function () {
2613
2636
  return false;
2614
2637
  }
2615
- }), _descriptor8 = _applyDecoratedDescriptor(_class.prototype, "_modalContainer", [tracked], {
2638
+ }), _descriptor5 = _applyDecoratedDescriptor(_class.prototype, "_modalContainer", [tracked], {
2616
2639
  configurable: true,
2617
2640
  enumerable: true,
2618
2641
  writable: true,
2619
2642
  initializer: function () {
2620
2643
  return null;
2621
2644
  }
2622
- }), _descriptor9 = _applyDecoratedDescriptor(_class.prototype, "_isShown", [tracked], {
2645
+ }), _descriptor6 = _applyDecoratedDescriptor(_class.prototype, "_isShown", [tracked], {
2623
2646
  configurable: true,
2624
2647
  enumerable: true,
2625
2648
  writable: true,
2626
2649
  initializer: function () {
2627
2650
  return false;
2628
2651
  }
2629
- }), _descriptor0 = _applyDecoratedDescriptor(_class.prototype, "_data", [tracked], {
2652
+ }), _descriptor7 = _applyDecoratedDescriptor(_class.prototype, "_data", [tracked], {
2630
2653
  configurable: true,
2631
2654
  enumerable: true,
2632
2655
  writable: true,
2633
2656
  initializer: function () {
2634
2657
  return undefined;
2635
2658
  }
2636
- }), _descriptor1 = _applyDecoratedDescriptor(_class.prototype, "_resolvedPlacement", [tracked], {
2659
+ }), _descriptor8 = _applyDecoratedDescriptor(_class.prototype, "_resolvedPlacement", [tracked], {
2637
2660
  configurable: true,
2638
2661
  enumerable: true,
2639
2662
  writable: true,
2640
2663
  initializer: function () {
2641
2664
  return undefined;
2642
2665
  }
2643
- }), _descriptor10 = _applyDecoratedDescriptor(_class.prototype, "_middlewareData", [tracked], {
2666
+ }), _descriptor9 = _applyDecoratedDescriptor(_class.prototype, "_middlewareData", [tracked], {
2644
2667
  configurable: true,
2645
2668
  enumerable: true,
2646
2669
  writable: true,
@@ -2649,5 +2672,5 @@ let AttacherCore = (_class = class AttacherCore {
2649
2672
  }
2650
2673
  }), _class);
2651
2674
 
2652
- export { AttacherCore as A, resolveTooltipClass as r };
2653
- //# sourceMappingURL=attacher-core-m7x5g04q.js.map
2675
+ export { AttacherCore as A, cancelScheduled as c, resolveTooltipClass as r, scheduleMicrotask as s };
2676
+ //# sourceMappingURL=attacher-core-DIAMEQR6.js.map