ember-attacher 4.3.0 → 5.0.0-beta.1

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