ember-attacher 4.2.1 → 4.4.0

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