js.foresight 2.2.3 → 3.0.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.
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
10
10
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
11
- [![Demo](https://img.shields.io/badge/demo-live-blue)](https://foresightjs.com/)
11
+ [![Demo](https://img.shields.io/badge/demo-live-blue)](https://foresightjs.com/#playground)
12
12
 
13
13
  ForesightJS is a lightweight JavaScript library with full TypeScript support that predicts user intent based on mouse movements, scroll and keyboard navigation. By analyzing cursor/scroll trajectory and tab sequences, it anticipates which elements a user is likely to interact with, allowing developers to trigger actions before the actual hover or click occurs (for example prefetching).
14
14
 
package/dist/index.d.ts CHANGED
@@ -14,6 +14,25 @@ type ForesightCallback = () => void;
14
14
  * This is typically a standard DOM `Element`.
15
15
  */
16
16
  type ForesightElement = Element;
17
+ /**
18
+ * Represents a mouse position captured at a specific point in time.
19
+ * Used for tracking mouse movement history.
20
+ */
21
+ type MousePosition = {
22
+ /** The (x, y) coordinates of the mouse. */
23
+ point: Point;
24
+ /** The timestamp (e.g., from `performance.now()`) when this position was recorded. */
25
+ time: number;
26
+ };
27
+ type Point = {
28
+ x: number;
29
+ y: number;
30
+ };
31
+ type TrajectoryPositions = {
32
+ positions: MousePosition[];
33
+ currentPoint: Point;
34
+ predictedPoint: Point;
35
+ };
17
36
  /**
18
37
  * Internal type representing the calculated boundaries of a foresight element,
19
38
  * including its original dimensions and the expanded hit area.
@@ -26,41 +45,6 @@ type ElementBounds = {
26
45
  /** The hit slop values applied to this element. */
27
46
  hitSlop: Exclude<HitSlop, number>;
28
47
  };
29
- type DebuggerSettings = {
30
- /**
31
- * Determines if the debugger control panel should be initialized in a minimized state.
32
- *
33
- * @link https://foresightjs.com/docs/getting_started/debug
34
- *
35
- * @default false
36
- */
37
- isControlPanelDefaultMinimized?: boolean;
38
- /**
39
- * Determines if name tags should be displayed visually above each registered element.
40
- * This is a helpful visual aid for identifying which elements are being tracked.
41
- *
42
- * @link https://foresightjs.com/docs/getting_started/debug
43
- *
44
- * @default false
45
- */
46
- showNameTags?: boolean;
47
- /**
48
- * Specifies the default sorting order for the list of registered elements in the debugger panel.
49
- * - `'visibility'`: Sorts elements by their viewport visibility (visible elements first),
50
- * with a secondary documentOrder sort.
51
- * - `'documentOrder'`: Sorts elements based on their order of appearance in the
52
- * document's structure (matching the HTML source).
53
- * - `'insertionOrder'`: Sorts by registration order.
54
- *
55
- *
56
- * @link https://foresightjs.com/docs/getting_started/debug
57
- *
58
- * @default 'visibility'
59
- *
60
- */
61
- sortElementList?: SortElementList;
62
- };
63
- type SortElementList = "documentOrder" | "visibility" | "insertionOrder";
64
48
  /**
65
49
  * Represents trajectory hit related data for a foresight element.
66
50
  */
@@ -85,7 +69,7 @@ type ForesightRegisterResult = {
85
69
  /**
86
70
  * Represents the data associated with a registered foresight element.
87
71
  */
88
- type ForesightElementData = Required<Pick<ForesightRegisterOptions, "callback" | "unregisterOnCallback" | "name">> & {
72
+ type ForesightElementData = Required<Pick<ForesightRegisterOptions, "callback" | "name">> & {
89
73
  /** The boundary information for the element. */
90
74
  elementBounds: ElementBounds;
91
75
  /** True if the mouse cursor is currently hovering over the element's expanded bounds. */
@@ -99,7 +83,7 @@ type ForesightElementData = Required<Pick<ForesightRegisterOptions, "callback" |
99
83
  */
100
84
  isIntersectingWithViewport: boolean;
101
85
  /**
102
- * Amount of times this callback has been hit, will be 0/1 if unregisterOnCallback is true
86
+ * Amount of times this callback has been hit
103
87
  */
104
88
  callbackHits: CallbackHits;
105
89
  /**
@@ -123,6 +107,16 @@ type CallbackHits = {
123
107
  tab: TabCallbackCounts;
124
108
  scroll: ScrollCallbackCounts;
125
109
  };
110
+ type HitType = {
111
+ kind: "mouse";
112
+ subType: keyof MouseCallbackCounts;
113
+ } | {
114
+ kind: "tab";
115
+ subType: keyof TabCallbackCounts;
116
+ } | {
117
+ kind: "scroll";
118
+ subType: keyof ScrollCallbackCounts;
119
+ };
126
120
  /**
127
121
  * Snapshot of the current ForesightManager state
128
122
  */
@@ -190,18 +184,6 @@ type BaseForesightManagerSettings = {
190
184
  * @default 2
191
185
  */
192
186
  tabOffset: number;
193
- /**
194
- * Whether to show visual debugging information on the screen.
195
- * This includes overlays for elements, hit slop areas, the predicted mouse path and a debug control panel.
196
- * @default false
197
- */
198
- debug: boolean;
199
- /**
200
- * @deprecated This property will be removed in v3.0.0. Use automatic optimization instead.
201
- */
202
- resizeScrollThrottleDelay: number;
203
- /** Options for the debugger */
204
- debuggerSettings: DebuggerSettings;
205
187
  /**
206
188
  * A global callback that runs whenever a callback is fired for any
207
189
  * registered element, just after the element's specific callback is fired.
@@ -232,6 +214,9 @@ type ForesightRegisterOptions = {
232
214
  element: ForesightElement;
233
215
  callback: ForesightCallback;
234
216
  hitSlop?: HitSlop;
217
+ /**
218
+ * @deprecated will be removed in V4.0
219
+ */
235
220
  unregisterOnCallback?: boolean;
236
221
  name?: string;
237
222
  };
@@ -248,6 +233,62 @@ type ForesightRegisterOptionsWithoutElement = Omit<ForesightRegisterOptions, "el
248
233
  * Basically increases the hover hitbox
249
234
  */
250
235
  type HitSlop = Rect | number;
236
+ interface ForesightEventMap {
237
+ elementRegistered: ElementRegisteredEvent;
238
+ elementUnregistered: ElementUnregisteredEvent;
239
+ elementDataUpdated: ElementDataUpdatedEvent;
240
+ callbackFired: CallbackFiredEvent;
241
+ mouseTrajectoryUpdate: MouseTrajectoryUpdateEvent;
242
+ scrollTrajectoryUpdate: ScrollTrajectoryUpdateEvent;
243
+ managerSettingsChanged: ManagerSettingsChangedEvent;
244
+ }
245
+ type ForesightEventType = keyof ForesightEventMap;
246
+ interface ForesightEvent {
247
+ type: ForesightEventType;
248
+ timestamp: number;
249
+ }
250
+ interface ElementRegisteredEvent extends ForesightEvent {
251
+ type: "elementRegistered";
252
+ elementData: ForesightElementData;
253
+ isLastElement?: boolean;
254
+ sort: boolean;
255
+ }
256
+ interface ElementUnregisteredEvent extends ForesightEvent {
257
+ type: "elementUnregistered";
258
+ elementData: ForesightElementData;
259
+ unregisterReason: ElementUnregisteredReason;
260
+ }
261
+ /**
262
+ * The reason an element was unregistered from ForesightManager's tracking.
263
+ * - `callbackHit`: The element was automatically unregistered after its callback fired.
264
+ * - `disconnected`: The element was automatically unregistered because it was removed from the DOM.
265
+ * - `apiCall`: The developer manually called the `unregister()` function for the element.
266
+ */
267
+ type ElementUnregisteredReason = "callbackHit" | "disconnected" | "apiCall";
268
+ interface ElementDataUpdatedEvent extends ForesightEvent {
269
+ type: "elementDataUpdated";
270
+ elementData: ForesightElementData;
271
+ updatedProp: "bounds" | "visibility";
272
+ }
273
+ interface CallbackFiredEvent extends ForesightEvent {
274
+ type: "callbackFired";
275
+ elementData: ForesightElementData;
276
+ hitType: HitType;
277
+ }
278
+ interface MouseTrajectoryUpdateEvent extends ForesightEvent {
279
+ type: "mouseTrajectoryUpdate";
280
+ trajectoryPositions: TrajectoryPositions;
281
+ predictionEnabled: boolean;
282
+ }
283
+ interface ScrollTrajectoryUpdateEvent extends ForesightEvent {
284
+ type: "scrollTrajectoryUpdate";
285
+ currentPoint: Point;
286
+ predictedPoint: Point;
287
+ }
288
+ interface ManagerSettingsChangedEvent extends ForesightEvent {
289
+ type: "managerSettingsChanged";
290
+ newSettings: ForesightManagerSettings;
291
+ }
251
292
 
252
293
  /**
253
294
  * Manages the prediction of user intent based on mouse trajectory and element interactions.
@@ -259,7 +300,6 @@ type HitSlop = Rect | number;
259
300
  * - Invoking callbacks associated with elements upon predicted or actual interaction.
260
301
  * - Optionally unregistering elements after their callback is triggered.
261
302
  * - Handling global settings for prediction behavior (e.g., history size, prediction time).
262
- * - Optionally enabling a {@link ForesightDebugger} for visual feedback.
263
303
  * - Automatically updating element bounds on resize using {@link ResizeObserver}.
264
304
  * - Automatically unregistering elements removed from the DOM using {@link MutationObserver}.
265
305
  * - Detecting broader layout shifts via {@link MutationObserver} to update element positions.
@@ -271,7 +311,6 @@ declare class ForesightManager {
271
311
  private static manager;
272
312
  private elements;
273
313
  private isSetup;
274
- private debugger;
275
314
  private _globalCallbackHits;
276
315
  private _globalSettings;
277
316
  private trajectoryPositions;
@@ -283,18 +322,24 @@ declare class ForesightManager {
283
322
  private positionObserver;
284
323
  private lastKeyDown;
285
324
  private globalListenersController;
325
+ private eventListeners;
286
326
  private constructor();
287
327
  static initialize(props?: Partial<UpdateForsightManagerSettings>): ForesightManager;
328
+ addEventListener<K extends ForesightEventType>(eventType: K, listener: (event: ForesightEventMap[K]) => void, options?: {
329
+ signal?: AbortSignal;
330
+ }): (() => void) | undefined;
331
+ removeEventListener<K extends ForesightEventType>(eventType: K, listener: (event: ForesightEventMap[K]) => void): void;
332
+ logSubscribers(): void;
333
+ private emit;
288
334
  get getManagerData(): Readonly<ForesightManagerData>;
289
335
  static get isInitiated(): Readonly<boolean>;
290
336
  static get instance(): ForesightManager;
291
337
  get registeredElements(): ReadonlyMap<ForesightElement, ForesightElementData>;
292
- register({ element, callback, hitSlop, unregisterOnCallback, name, }: ForesightRegisterOptions): ForesightRegisterResult;
338
+ register({ element, callback, hitSlop, name, }: ForesightRegisterOptions): ForesightRegisterResult;
293
339
  private unregister;
294
340
  private updateNumericSettings;
295
341
  private updateBooleanSetting;
296
342
  alterGlobalSettings(props?: Partial<UpdateForsightManagerSettings>): void;
297
- private turnOnDebugMode;
298
343
  private forceUpdateAllElementBounds;
299
344
  private updatePointerState;
300
345
  /**
@@ -308,21 +353,7 @@ declare class ForesightManager {
308
353
  * @param elementData - The data object for the foresight element.
309
354
  * @param element - The HTML element being interacted with.
310
355
  */
311
- private handleSingleCallbackInteraction;
312
- /**
313
- * Processes persistent elements that can have multiple callbacks and require state tracking.
314
- *
315
- * This handler is responsible for elements where `unregisterOnCallback` is false.
316
- * It triggers callbacks only on the "leading edge" of an interaction—that is,
317
- * the first moment the mouse enters an element or the first moment a trajectory
318
- * is predicted to hit it. This prevents the callback from firing on every
319
- * mouse move. It also manages the element's state (`isHovering`, `isTrajectoryHit`)
320
- * for visual feedback in the {@link ForesightDebugger}.
321
- *
322
- * @param elementData - The current data object for the foresight element.
323
- * @param element - The HTML element being interacted with.
324
- */
325
- private handleMultiCallbackInteraction;
356
+ private handleCallbackInteraction;
326
357
  private handleMouseMove;
327
358
  /**
328
359
  * Detects when registered elements are removed from the DOM and automatically unregisters them to prevent stale references.
@@ -348,4 +379,4 @@ declare class ForesightManager {
348
379
  }
349
380
 
350
381
  export { ForesightManager };
351
- export type { CallbackHits as ForesightCallbackHits, ForesightElement, ForesightElementData, ForesightManagerSettings, Rect as ForesightRect, ForesightRegisterOptions, ForesightRegisterOptionsWithoutElement, ForesightRegisterResult, UpdateForsightManagerSettings };
382
+ export type { CallbackFiredEvent, ElementDataUpdatedEvent, ElementRegisteredEvent, ElementUnregisteredEvent, CallbackHits as ForesightCallbackHits, ForesightElement, ForesightElementData, ForesightEvent, ForesightManagerSettings, Rect as ForesightRect, ForesightRegisterOptions, ForesightRegisterOptionsWithoutElement, ForesightRegisterResult, HitSlop, ManagerSettingsChangedEvent, MouseTrajectoryUpdateEvent, ScrollTrajectoryUpdateEvent, UpdateForsightManagerSettings };
package/dist/index.js CHANGED
@@ -3,5 +3,5 @@
3
3
  * tabbable 6.2.0
4
4
  * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
5
5
  */
6
- var e=["input:not([inert])","select:not([inert])","textarea:not([inert])","a[href]:not([inert])","button:not([inert])","[tabindex]:not(slot):not([inert])","audio[controls]:not([inert])","video[controls]:not([inert])",'[contenteditable]:not([contenteditable="false"]):not([inert])',"details>summary:first-of-type:not([inert])","details:not([inert])"].join(","),n="undefined"==typeof Element,i=n?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,o=!n&&Element.prototype.getRootNode?function(t){var e;return null==t||null===(e=t.getRootNode)||void 0===e?void 0:e.call(t)}:function(t){return null==t?void 0:t.ownerDocument},r=function t(e,n){var i;void 0===n&&(n=!0);var o=null==e||null===(i=e.getAttribute)||void 0===i?void 0:i.call(e,"inert");return""===o||"true"===o||n&&e&&t(e.parentNode)},s=function t(n,o,s){for(var a=[],l=Array.from(n);l.length;){var c=l.shift();if(!r(c,!1))if("SLOT"===c.tagName){var d=c.assignedElements(),u=t(d.length?d:c.children,!0,s);s.flatten?a.push.apply(a,u):a.push({scopeParent:c,candidates:u})}else{i.call(c,e)&&s.filter(c)&&(o||!n.includes(c))&&a.push(c);var h=c.shadowRoot||"function"==typeof s.getShadowRoot&&s.getShadowRoot(c),g=!r(h,!1)&&(!s.shadowRootFilter||s.shadowRootFilter(c));if(h&&g){var p=t(!0===h?c.children:h.children,!0,s);s.flatten?a.push.apply(a,p):a.push({scopeParent:c,candidates:p})}else l.unshift.apply(l,c.children)}}return a},a=function(t){return!isNaN(parseInt(t.getAttribute("tabindex"),10))},l=function(t){if(!t)throw new Error("No node provided");return t.tabIndex<0&&(/^(AUDIO|VIDEO|DETAILS)$/.test(t.tagName)||function(t){var e,n=null==t||null===(e=t.getAttribute)||void 0===e?void 0:e.call(t,"contenteditable");return""===n||"true"===n}(t))&&!a(t)?0:t.tabIndex},c=function(t,e){return t.tabIndex===e.tabIndex?t.documentOrder-e.documentOrder:t.tabIndex-e.tabIndex},d=function(t){return"INPUT"===t.tagName},u=function(t){return function(t){return d(t)&&"radio"===t.type}(t)&&!function(t){if(!t.name)return!0;var e,n=t.form||o(t),i=function(t){return n.querySelectorAll('input[type="radio"][name="'+t+'"]')};if("undefined"!=typeof window&&void 0!==window.CSS&&"function"==typeof window.CSS.escape)e=i(window.CSS.escape(t.name));else try{e=i(t.name)}catch(t){return console.error("Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s",t.message),!1}var r=function(t,e){for(var n=0;n<t.length;n++)if(t[n].checked&&t[n].form===e)return t[n]}(e,t.form);return!r||r===t}(t)},h=function(t){var e=t.getBoundingClientRect(),n=e.width,i=e.height;return 0===n&&0===i},g=function(t,e){var n=e.displayCheck,r=e.getShadowRoot;if("hidden"===getComputedStyle(t).visibility)return!0;var s=i.call(t,"details>summary:first-of-type")?t.parentElement:t;if(i.call(s,"details:not([open]) *"))return!0;if(n&&"full"!==n&&"legacy-full"!==n){if("non-zero-area"===n)return h(t)}else{if("function"==typeof r){for(var a=t;t;){var l=t.parentElement,c=o(t);if(l&&!l.shadowRoot&&!0===r(l))return h(t);t=t.assignedSlot?t.assignedSlot:l||c===t.ownerDocument?l:c.host}t=a}if(function(t){var e,n,i,r,s=t&&o(t),a=null===(e=s)||void 0===e?void 0:e.host,l=!1;if(s&&s!==t)for(l=!!(null!==(n=a)&&void 0!==n&&null!==(i=n.ownerDocument)&&void 0!==i&&i.contains(a)||null!=t&&null!==(r=t.ownerDocument)&&void 0!==r&&r.contains(t));!l&&a;){var c,d,u;l=!(null===(d=a=null===(c=s=o(a))||void 0===c?void 0:c.host)||void 0===d||null===(u=d.ownerDocument)||void 0===u||!u.contains(a))}return l}(t))return!t.getClientRects().length;if("legacy-full"!==n)return!0}return!1},p=function(t,e){return!(e.disabled||r(e)||function(t){return d(t)&&"hidden"===t.type}(e)||g(e,t)||function(t){return"DETAILS"===t.tagName&&Array.prototype.slice.apply(t.children).some((function(t){return"SUMMARY"===t.tagName}))}(e)||function(t){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(t.tagName))for(var e=t.parentElement;e;){if("FIELDSET"===e.tagName&&e.disabled){for(var n=0;n<e.children.length;n++){var o=e.children.item(n);if("LEGEND"===o.tagName)return!!i.call(e,"fieldset[disabled] *")||!o.contains(t)}return!0}e=e.parentElement}return!1}(e))},b=function(t,e){return!(u(e)||l(e)<0||!p(t,e))},m=function(t){var e=parseInt(t.getAttribute("tabindex"),10);return!!(isNaN(e)||e>=0)},f=function t(e){var n=[],i=[];return e.forEach((function(e,o){var r=!!e.scopeParent,s=r?e.scopeParent:e,c=function(t,e){var n=l(t);return n<0&&e&&!a(t)?0:n}(s,r),d=r?t(e.candidates):s;0===c?r?n.push.apply(n,d):n.push(s):i.push({documentOrder:o,tabIndex:c,item:e,isScope:r,content:d})})),i.sort(c).reduce((function(t,e){return e.isScope?t.push.apply(t,e.content):t.push(e.content),t}),[]).concat(n)},v=function(t,n){var o;return o=(n=n||{}).getShadowRoot?s([t],n.includeContainer,{filter:b.bind(null,n),flatten:!1,getShadowRoot:n.getShadowRoot,shadowRootFilter:m}):function(t,n,o){if(r(t))return[];var s=Array.prototype.slice.apply(t.querySelectorAll(e));return n&&i.call(t,e)&&s.unshift(t),s.filter(o)}(t,n.includeContainer,b.bind(null,n)),f(o)},y="ms",S="points",x="tabs",w=2e3,C=!1,k=!0;var E=function(t,e){void 0===e&&(e=2);var n=" ".repeat(e);if("object"==typeof t&&null!==t&&!Array.isArray(t)){var i=Object.entries(t);if(0===i.length)return"{}";var o=i.map((function(t){var i=t[0],o=t[1];return"".concat(n," ").concat(i,": ").concat(E(o,e+2))})).join(",\n");return"{\n".concat(o,"\n").concat(n,"}")}return"string"==typeof t?"'".concat(t,"'"):"boolean"==typeof t||"number"==typeof t?String(t):null===t?"null":void 0===t?"undefined":Array.isArray(t)?JSON.stringify(t):String(t)};function M(t,e,n){var i=document.createElement(t);return n.id&&(i.id=n.id),n.className&&(i.className=n.className),n.data&&i.setAttribute("data-value",n.data),e.appendChild(i)}function O(t,e,n){var i=document.createElement("style");return i.textContent=t,i.id=n,e.appendChild(i)}var j=function(t){return t?"👁️":"🚫"},T='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>',P="<em>No elements registered.</em>",I=function(){function t(t){this.elementListItemsContainer=null,this.elementCountSpan=null,this.callbackCountSpan=null,this.elementListItems=new Map,this.trajectoryEnabledCheckbox=null,this.tabEnabledCheckbox=null,this.scrollEnabledCheckbox=null,this.historySizeSlider=null,this.historyValueSpan=null,this.predictionTimeSlider=null,this.predictionValueSpan=null,this.tabOffsetSlider=null,this.tabOffsetValueSpan=null,this.scrollMarginSlider=null,this.scrollMarginValueSpan=null,this.showNameTagsCheckbox=null,this.sortOptionsPopup=null,this.sortButton=null,this.containerMinimizeButton=null,this.allSettingsSectionsContainer=null,this.debuggerElementsSection=null,this.isContainerMinimized=!1,this.isMouseSettingsMinimized=!0,this.isKeyboardSettingsMinimized=!0,this.isScrollSettingsMinimized=!0,this.isGeneralSettingsMinimized=!0,this.SESSION_STORAGE_KEY="jsforesightDebuggerSectionStates",this.copySettingsButton=null,this.minimizedElementCount=null,this.copyTimeoutId=null,this.closeSortDropdownHandler=null,this.foresightManagerInstance=t}return t.prototype._setupDOMAndListeners=function(t,e){var n;this.controlsContainer||(this.shadowRoot=t,this.isContainerMinimized=null!==(n=e.isControlPanelDefaultMinimized)&&void 0!==n?n:C,this.controlsContainer=this.createControlContainer(),this.shadowRoot.appendChild(this.controlsContainer),this.controlPanelStyleElement=O(this.getStyles(),this.shadowRoot,"debug-control-panel"),this.queryDOMElements(),this.originalSectionStates(),this.setupEventListeners(),this.updateContainerVisibilityState())},t.initialize=function(e,n,i){t.isInitiated||(t.debuggerControlPanelInstance=new t(e));var o=t.debuggerControlPanelInstance;return o._setupDOMAndListeners(n,i),o},Object.defineProperty(t,"isInitiated",{get:function(){return!!t.debuggerControlPanelInstance},enumerable:!1,configurable:!0}),t.prototype.loadSectionStatesFromSessionStorage=function(){var t,e,n,i,o=sessionStorage.getItem(this.SESSION_STORAGE_KEY),r={};return o&&(r=JSON.parse(o)),this.isMouseSettingsMinimized=null===(t=r.mouse)||void 0===t||t,this.isKeyboardSettingsMinimized=null===(e=r.keyboard)||void 0===e||e,this.isScrollSettingsMinimized=null===(n=r.scroll)||void 0===n||n,this.isGeneralSettingsMinimized=null===(i=r.general)||void 0===i||i,r},t.prototype.saveSectionStatesToSessionStorage=function(){var t={mouse:this.isMouseSettingsMinimized,keyboard:this.isKeyboardSettingsMinimized,scroll:this.isScrollSettingsMinimized,general:this.isGeneralSettingsMinimized};try{sessionStorage.setItem(this.SESSION_STORAGE_KEY,JSON.stringify(t))}catch(t){console.error("Foresight Debugger: Could not save section states to session storage.",t)}},t.prototype.queryDOMElements=function(){this.trajectoryEnabledCheckbox=this.controlsContainer.querySelector("#trajectory-enabled"),this.tabEnabledCheckbox=this.controlsContainer.querySelector("#tab-enabled"),this.scrollEnabledCheckbox=this.controlsContainer.querySelector("#scroll-enabled"),this.historySizeSlider=this.controlsContainer.querySelector("#history-size"),this.historyValueSpan=this.controlsContainer.querySelector("#history-value"),this.predictionTimeSlider=this.controlsContainer.querySelector("#prediction-time"),this.predictionValueSpan=this.controlsContainer.querySelector("#prediction-value"),this.tabOffsetSlider=this.controlsContainer.querySelector("#tab-offset"),this.tabOffsetValueSpan=this.controlsContainer.querySelector("#tab-offset-value"),this.scrollMarginSlider=this.controlsContainer.querySelector("#scroll-margin"),this.scrollMarginValueSpan=this.controlsContainer.querySelector("#scroll-margin-value"),this.elementListItemsContainer=this.controlsContainer.querySelector("#element-list-items-container"),this.showNameTagsCheckbox=this.controlsContainer.querySelector("#toggle-name-tags"),this.sortOptionsPopup=this.controlsContainer.querySelector("#sort-options-popup"),this.sortButton=this.controlsContainer.querySelector(".sort-button"),this.elementCountSpan=this.controlsContainer.querySelector("#element-count"),this.callbackCountSpan=this.controlsContainer.querySelector("#callback-count"),this.containerMinimizeButton=this.controlsContainer.querySelector(".minimize-button"),this.allSettingsSectionsContainer=this.controlsContainer.querySelector(".all-settings-sections-container"),this.debuggerElementsSection=this.controlsContainer.querySelector(".debugger-elements"),this.copySettingsButton=this.controlsContainer.querySelector(".copy-settings-button"),this.minimizedElementCount=this.controlsContainer.querySelector(".minimized-element-count")},t.prototype.handleCopySettings=function(){var t,e,n,i=this;this.copySettingsButton&&navigator.clipboard.writeText((t=this.foresightManagerInstance.getManagerData.globalSettings,e="ForesightManager.initialize",n=Object.entries(t).filter((function(t){var e=t[0];return"resizeScrollThrottleDelay"!==String(e)})).map((function(t){var e=t[0],n=t[1];return" ".concat(String(e),": ").concat(E(n))})).join(",\n"),"".concat(e,"({\n").concat(n,"\n})"))).then((function(){i.copySettingsButton.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>',i.copyTimeoutId&&clearTimeout(i.copyTimeoutId),i.copyTimeoutId=setTimeout((function(){i.copySettingsButton&&(i.copySettingsButton.innerHTML=T),i.copyTimeoutId=null}),3e3)})).catch((function(t){console.error("Foresight Debugger: Could not copy settings to clipboard",t)}))},t.prototype.createInputEventListener=function(t,e,n,i){var o=this;t&&e&&t.addEventListener("input",(function(t){var r,s=parseInt(t.target.value,10);e.textContent="".concat(s," ").concat(n),o.foresightManagerInstance.alterGlobalSettings(((r={})[i]=s,r))}))},t.prototype.createChangeEventListener=function(t,e){var n=this;t&&t.addEventListener("change",(function(t){var i;"name-tag"===e?n.foresightManagerInstance.alterGlobalSettings({debuggerSettings:{showNameTags:t.target.checked}}):n.foresightManagerInstance.alterGlobalSettings(((i={})[e]=t.target.checked,i))}))},t.prototype.createSectionVisibilityToggleEventListener=function(t,e){var n=this,i=null==t?void 0:t.querySelector(".debugger-section-header");null==i||i.addEventListener("click",(function(i){i.stopPropagation(),n.toggleMinimizeSection(t,n[e]=!n[e])}))},t.prototype.setupEventListeners=function(){var t,e,n,i,o=this;this.createChangeEventListener(this.trajectoryEnabledCheckbox,"enableMousePrediction"),this.createChangeEventListener(this.tabEnabledCheckbox,"enableTabPrediction"),this.createChangeEventListener(this.scrollEnabledCheckbox,"enableScrollPrediction"),this.createChangeEventListener(this.showNameTagsCheckbox,"name-tag"),this.createInputEventListener(this.historySizeSlider,this.historyValueSpan,S,"positionHistorySize"),this.createInputEventListener(this.predictionTimeSlider,this.predictionValueSpan,y,"trajectoryPredictionTime"),this.createInputEventListener(this.tabOffsetSlider,this.tabOffsetValueSpan,x,"tabOffset"),this.createInputEventListener(this.scrollMarginSlider,this.scrollMarginValueSpan,"px","scrollMargin"),null===(t=this.sortButton)||void 0===t||t.addEventListener("click",(function(t){var e;t.stopPropagation(),null===(e=o.sortOptionsPopup)||void 0===e||e.classList.toggle("active")})),null===(e=this.sortOptionsPopup)||void 0===e||e.addEventListener("click",(function(t){var e,n=t.target.closest("[data-sort]");if(n){var i=n.dataset.sort;o.foresightManagerInstance.alterGlobalSettings({debuggerSettings:{sortElementList:i}}),console.log("here"),o.sortAndReorderElements(),o.updateSortOptionUI(i),null===(e=o.sortOptionsPopup)||void 0===e||e.classList.remove("active")}})),this.closeSortDropdownHandler=function(t){var e,n;(null===(e=o.sortOptionsPopup)||void 0===e?void 0:e.classList.contains("active"))&&!(null===(n=o.sortButton)||void 0===n?void 0:n.contains(t.target))&&o.sortOptionsPopup.classList.remove("active")},document.addEventListener("click",this.closeSortDropdownHandler),null===(n=this.containerMinimizeButton)||void 0===n||n.addEventListener("click",(function(){o.isContainerMinimized=!o.isContainerMinimized,o.updateContainerVisibilityState()})),null===(i=this.copySettingsButton)||void 0===i||i.addEventListener("click",this.handleCopySettings.bind(this)),this.createSectionVisibilityToggleEventListener(this.controlsContainer.querySelector(".mouse-settings-section"),"isMouseSettingsMinimized"),this.createSectionVisibilityToggleEventListener(this.controlsContainer.querySelector(".keyboard-settings-section"),"isKeyboardSettingsMinimized"),this.createSectionVisibilityToggleEventListener(this.controlsContainer.querySelector(".scroll-settings-section"),"isScrollSettingsMinimized"),this.createSectionVisibilityToggleEventListener(this.controlsContainer.querySelector(".general-settings-section"),"isGeneralSettingsMinimized")},t.prototype.toggleMinimizeSection=function(t,e){if(t){var n=t.querySelector(".debugger-section-content"),i=t.querySelector(".section-minimize-button");n&&i&&(e?(n.style.display="none",i.textContent="+"):(n.style.display="flex",i.textContent="-")),this.saveSectionStatesToSessionStorage()}},t.prototype.originalSectionStates=function(){var t,e,n,i,o,r=this.loadSectionStatesFromSessionStorage();this.toggleMinimizeSection(this.controlsContainer.querySelector(".mouse-settings-section"),null===(t=r.mouse)||void 0===t||t),this.toggleMinimizeSection(this.controlsContainer.querySelector(".keyboard-settings-section"),null===(e=r.keyboard)||void 0===e||e),this.toggleMinimizeSection(this.controlsContainer.querySelector(".scroll-settings-section"),null===(n=r.scroll)||void 0===n||n),this.toggleMinimizeSection(this.controlsContainer.querySelector(".general-settings-section"),null===(i=r.general)||void 0===i||i);var s=null===(o=this.debuggerElementsSection)||void 0===o?void 0:o.querySelector(".debugger-section-content");s&&(s.style.display="flex")},t.prototype.updateContainerVisibilityState=function(){this.containerMinimizeButton&&(this.isContainerMinimized?(this.controlsContainer.classList.add("minimized"),this.containerMinimizeButton.textContent="+",this.allSettingsSectionsContainer&&(this.allSettingsSectionsContainer.style.display="none"),this.debuggerElementsSection&&(this.debuggerElementsSection.style.display="none"),this.copySettingsButton&&(this.copySettingsButton.style.display="none"),this.minimizedElementCount&&(this.minimizedElementCount.style.display="")):(this.controlsContainer.classList.remove("minimized"),this.containerMinimizeButton.textContent="-",this.allSettingsSectionsContainer&&(this.allSettingsSectionsContainer.style.display=""),this.debuggerElementsSection&&(this.debuggerElementsSection.style.display=""),this.copySettingsButton&&(this.copySettingsButton.style.display=""),this.minimizedElementCount&&(this.minimizedElementCount.style.display="none")))},t.prototype.updateSortOptionUI=function(t){var e;null===(e=this.sortOptionsPopup)||void 0===e||e.querySelectorAll("[data-sort]").forEach((function(e){var n=e;n.dataset.sort===t?n.classList.add("active-sort-option"):n.classList.remove("active-sort-option")}))},t.prototype.updateControlsState=function(t){var e,n;this.trajectoryEnabledCheckbox&&(this.trajectoryEnabledCheckbox.checked=t.enableMousePrediction),this.tabEnabledCheckbox&&(this.tabEnabledCheckbox.checked=t.enableTabPrediction),this.scrollEnabledCheckbox&&(this.scrollEnabledCheckbox.checked=t.enableScrollPrediction),this.showNameTagsCheckbox&&(this.showNameTagsCheckbox.checked=null!==(e=t.debuggerSettings.showNameTags)&&void 0!==e?e:k),this.updateSortOptionUI(null!==(n=t.debuggerSettings.sortElementList)&&void 0!==n?n:"visibility"),this.historySizeSlider&&this.historyValueSpan&&(this.historySizeSlider.value=t.positionHistorySize.toString(),this.historyValueSpan.textContent="".concat(t.positionHistorySize," ").concat(S)),this.predictionTimeSlider&&this.predictionValueSpan&&(this.predictionTimeSlider.value=t.trajectoryPredictionTime.toString(),this.predictionValueSpan.textContent="".concat(t.trajectoryPredictionTime," ").concat(y)),this.tabOffsetSlider&&this.tabOffsetValueSpan&&(this.tabOffsetSlider.value=t.tabOffset.toString(),this.tabOffsetValueSpan.textContent="".concat(t.tabOffset," ").concat(x)),this.scrollMarginSlider&&this.scrollMarginValueSpan&&(this.scrollMarginSlider.value=t.scrollMargin.toString(),this.scrollMarginValueSpan.textContent="".concat(t.scrollMargin," ").concat("px"))},t.prototype.refreshRegisteredElementCountDisplay=function(t){if(this.elementCountSpan&&this.callbackCountSpan){var e=0;t.forEach((function(t){t.isIntersectingWithViewport&&e++}));var n=t.size,i=this.foresightManagerInstance.getManagerData.globalCallbackHits,o=i.tab,r=i.mouse,s=i.scroll,a=i.total,l=["Element Visibility Status","━━━━━━━━━━━━━━━━━━━━━━━━━━━━","Visible in Viewport: ".concat(e),"Not in Viewport: ".concat(n-e),"Total Registered Elements: ".concat(n),"","Note: Only elements visible in the viewport","are actively tracked by intersection observers."];this.minimizedElementCount&&(this.minimizedElementCount.textContent="".concat(e,"/").concat(n),this.minimizedElementCount.title=l.join("\n")),this.elementCountSpan.textContent="Visible: ".concat(e,"/").concat(n," ~ "),this.elementCountSpan.title=l.join("\n"),this.callbackCountSpan.textContent="Mouse: ".concat(r.hover+r.trajectory," Tab: ").concat(o.forwards+o.reverse," Scroll: ").concat(s.down+s.left+s.right+s.up),this.callbackCountSpan.title=["Callback Execution Stats","━━━━━━━━━━━━━━━━━━━━━━━━","Mouse Callbacks"," • Trajectory: ".concat(r.trajectory)," • Hover: ".concat(r.hover)," • Subtotal: ".concat(r.hover+r.trajectory),"","Keyboard Callbacks:"," • Tab Forward: ".concat(o.forwards)," • Tab Reverse: ".concat(o.reverse)," • Subtotal: ".concat(o.forwards+o.reverse),"","Scroll Callbacks:"," • Up: ".concat(s.up," | Down: ").concat(s.down)," • Left: ".concat(s.left," | Right: ").concat(s.right)," • Subtotal: ".concat(s.up+s.down+s.left+s.right),"","Total Callbacks: "+a].join("\n")}},t.prototype.removeElementFromList=function(t){if(this.elementListItemsContainer){var e=this.elementListItems.get(t.element);if(e){e.remove(),this.elementListItems.delete(t.element);var n=this.foresightManagerInstance.registeredElements;this.refreshRegisteredElementCountDisplay(n),0===this.elementListItems.size&&(this.elementListItemsContainer.innerHTML=P)}}},t.prototype.updateElementVisibilityStatus=function(t){if(this.elementListItemsContainer){var e=this.elementListItems.get(t.element);if(e){e.classList.toggle("not-in-viewport",!t.isIntersectingWithViewport);var n=e.querySelector(".intersecting-indicator");if(n){var i=j(t.isIntersectingWithViewport);n.textContent=i}this.refreshRegisteredElementCountDisplay(this.foresightManagerInstance.registeredElements),this.sortAndReorderElements()}else this.addElementToList(t)}},t.prototype.sortAndReorderElements=function(){var t,e=this;if(this.elementListItemsContainer){var n=null!==(t=this.foresightManagerInstance.getManagerData.globalSettings.debuggerSettings.sortElementList)&&void 0!==t?t:"visibility",i=Array.from(this.foresightManagerInstance.registeredElements.values());if("insertionOrder"!==n){var o=function(t,e){var n=t.element.compareDocumentPosition(e.element);return n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0};"visibility"===n?i.sort((function(t,e){return t.isIntersectingWithViewport!==e.isIntersectingWithViewport?t.isIntersectingWithViewport?-1:1:o(t,e)})):"documentOrder"===n&&i.sort(o)}var r=document.createDocumentFragment();i.length&&(i.forEach((function(t){var n=e.elementListItems.get(t.element);n&&r.appendChild(n)})),this.elementListItemsContainer.innerHTML="",this.elementListItemsContainer.appendChild(r))}},t.prototype.addElementToList=function(t,e){if(void 0===e&&(e=!0),this.elementListItemsContainer&&(this.elementListItemsContainer.innerHTML===P&&(this.elementListItemsContainer.innerHTML=""),!this.elementListItems.has(t.element))){var n=document.createElement("div");n.className="element-list-item",this.updateListItemContent(n,t),this.elementListItemsContainer.appendChild(n),this.elementListItems.set(t.element,n),this.refreshRegisteredElementCountDisplay(this.foresightManagerInstance.registeredElements),e&&this.sortAndReorderElements()}},t.prototype.updateListItemContent=function(t,e){var n=j(e.isIntersectingWithViewport);t.classList.toggle("not-in-viewport",!e.isIntersectingWithViewport);var i=e.unregisterOnCallback?"Single":"Multi",o="N/A";if(e.elementBounds.hitSlop){var r=e.elementBounds.hitSlop,s=r.top,a=r.right,l=r.bottom,c=r.left;o="T:".concat(s," R:").concat(a," B:").concat(l," L:").concat(c)}var d=["".concat(e.name||"Unnamed Element"),"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━","Viewport Status:",e.isIntersectingWithViewport?" ✓ In viewport - actively tracked by observers":" ✗ Not in viewport - not being tracked","","Hit Behavior:",e.unregisterOnCallback?" • Single: Callback triggers once":" • Multi: Callback can trigger multiple times","","Hit Slop:",e.elementBounds.hitSlop?[" Top: ".concat(e.elementBounds.hitSlop.top,"px, Bottom: ").concat(e.elementBounds.hitSlop.bottom,"px ")," Right: ".concat(e.elementBounds.hitSlop.right,"px, Left: ").concat(e.elementBounds.hitSlop.left,"px")].join("\n"):" • Not defined - using element's natural boundaries",""].join("\n");t.title=d,t.innerHTML='\n <span class="intersecting-indicator">'.concat(n,'</span>\n <span class="element-name">').concat(e.name||"Unnamed Element",'</span>\n <span class="hit-slop">').concat(o,'</span>\n <span class="hit-behavior">').concat(i,"</span>\n ")},t.prototype.cleanup=function(){var t,e;null===(t=this.controlsContainer)||void 0===t||t.remove(),null===(e=this.controlPanelStyleElement)||void 0===e||e.remove(),this.copyTimeoutId&&(clearTimeout(this.copyTimeoutId),this.copyTimeoutId=null),this.closeSortDropdownHandler&&(document.removeEventListener("click",this.closeSortDropdownHandler),this.closeSortDropdownHandler=null),this.controlsContainer=null,this.controlPanelStyleElement=null,this.elementListItemsContainer=null,this.elementCountSpan=null,this.callbackCountSpan=null,this.elementListItems.clear(),this.containerMinimizeButton=null,this.allSettingsSectionsContainer=null,this.debuggerElementsSection=null,this.trajectoryEnabledCheckbox=null,this.tabEnabledCheckbox=null,this.scrollEnabledCheckbox=null,this.historySizeSlider=null,this.historyValueSpan=null,this.predictionTimeSlider=null,this.predictionValueSpan=null,this.tabOffsetSlider=null,this.tabOffsetValueSpan=null,this.scrollMarginSlider=null,this.scrollMarginValueSpan=null,this.showNameTagsCheckbox=null,this.sortOptionsPopup=null,this.sortButton=null,this.copySettingsButton=null},t.prototype.createControlContainer=function(){var t=document.createElement("div");return t.id="debug-controls",t.innerHTML='\n <div class="debugger-title-container">\n <button class="minimize-button">-</button>\n <div class="title-group">\n <h2>Foresight Debugger</h2>\n <span class="info-icon" title="'.concat(["Foresight Debugger Information","━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━","Session-Only Changes:","All adjustments made here apply only to the","current browser session and won't persist.","","Permanent Configuration:","To make lasting changes, update the initial","values in your ForesightManager.initialize().","","You can copy the current debugger settings","with the button on the right"].join("\n"),'">i</span>\n </div>\n <button class="copy-settings-button" title="').concat(["Copy Settings to Clipboard","━━━━━━━━━━━━━━━━━━━━━━━━━━━━━","Copies the current configuration as a","formatted method call that you can paste","directly into your code."].join("\n"),'">\n ').concat(T,'\n </button>\n <span class="minimized-element-count">\n </span>\n </div>\n\n <div class="all-settings-sections-container">\n <div class="debugger-section mouse-settings-section">\n <div class="debugger-section-header collapsible">\n <h3>Mouse Settings</h3>\n <button class="section-minimize-button">-</button>\n </div>\n <div class="debugger-section-content mouse-settings-content">\n <div class="control-row">\n <label for="trajectory-enabled">\n Enable Mouse Prediction\n <span class="info-icon" title="').concat(["Mouse Prediction Control","━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━","When enabled: Predicts mouse movement","trajectory and triggers callbacks before","the cursor reaches the target element.","","When disabled: Only direct hover events","trigger actions (next to tab/scroll).","","Property: enableMousePrediction"].join("\n"),'">i</span>\n </label>\n <input type="checkbox" id="trajectory-enabled">\n </div>\n <div class="control-row">\n <label for="history-size">\n History Size\n <span class="info-icon" title="').concat(["Position History","━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━","Controls how many past mouse positions","are stored for velocity calculations.","","Higher values:"," • More accurate trajectory predictions"," • Smoother movement detection"," • Slightly increased processing overhead","","Lower values:"," • Faster response to direction changes"," • Less memory usage"," • May be less accurate for fast movements","","Property: positionHistorySize"].join("\n"),'">i</span>\n </label>\n <input type="range" id="history-size" min="').concat(2,'" max="').concat(30,'">\n <span id="history-value"></span>\n </div>\n <div class="control-row">\n <label for="prediction-time">\n Prediction Time\n <span class="info-icon" title="').concat(["Trajectory Prediction Time","━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━","How far into the future (in ".concat(y,")"),"to calculate the mouse trajectory path.","","Larger values:"," • Elements are detected sooner"," • More time for preloading/preparation"," • May trigger false positives for curved paths","","Smaller values:"," • More precise targeting"," • Reduced false positive rate"," • Less time for preparation","","Property: trajectoryPredictionTime"].join("\n"),'">i</span>\n </label>\n <input type="range" id="prediction-time" min="').concat(10,'" max="').concat(200,'" step="10">\n <span id="prediction-value"></span>\n </div>\n </div>\n </div>\n\n <div class="debugger-section keyboard-settings-section">\n <div class="debugger-section-header collapsible">\n <h3>Keyboard Settings</h3>\n <button class="section-minimize-button">-</button>\n </div>\n <div class="debugger-section-content keyboard-settings-content">\n <div class="control-row">\n <label for="tab-enabled">\n Enable Tab Prediction\n <span class="info-icon" title="').concat(["Tab Navigation Prediction","━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━","When enabled: Callbacks are executed when","the user is ".concat(this.foresightManagerInstance.getManagerData.globalSettings.tabOffset," (tabOffset) ").concat(x," away from"),"a registered element during tab navigation.","","(works with Shift+Tab too).","","Property: enableTabPrediction"].join("\n"),'">i</span>\n </label>\n <input type="checkbox" id="tab-enabled">\n </div>\n <div class="control-row">\n <label for="tab-offset">\n Tab Offset\n <span class="info-icon" title="').concat(["Tab Offset","━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━","Number of tabbable elements to look ahead","when predicting tab navigation targets.","","How it works:"," • Tracks the current focused element"," • Looks ahead by the specified offset"," • Triggers callbacks for registered elements"," within that range","","Property: tabOffset"].join("\n"),'">i</span>\n </label>\n <input type="range" id="tab-offset" min="').concat(0,'" max="').concat(20,'" step="1">\n <span id="tab-offset-value"></span>\n </div>\n </div>\n </div>\n\n <div class="debugger-section scroll-settings-section">\n <div class="debugger-section-header collapsible">\n <h3>Scroll Settings</h3>\n <button class="section-minimize-button">-</button>\n </div>\n <div class="debugger-section-content scroll-settings-content">\n <div class="control-row">\n <label for="scroll-enabled">\n Enable Scroll Prediction\n <span class="info-icon" title="').concat(["Scroll Prediction","━━━━━━━━━━━━━━━━━━━━━━━━━━━━","Enables predictive scrolling based on mouse","position and scroll direction.","","When enabled, calculates scroll direction from","mouse movement and triggers callbacks for","elements that intersect the predicted path.","","Property: enableScrollPrediction"].join("\n"),'">i</span>\n </label>\n <input type="checkbox" id="scroll-enabled">\n </div>\n <div class="control-row">\n <label for="scroll-margin">\n Scroll Margin\n <span class="info-icon" title="').concat(["Scroll Margin","━━━━━━━━━━━━━━━━━━━━━━━━━━━━━","Sets the pixel distance to check from the","mouse position in the scroll direction.","","Higher values check further ahead, allowing","earlier detection of elements that will come","into view during scrolling.","","Property: scrollMargin"].join("\n"),'">i</span>\n </label>\n <input type="range" id="scroll-margin" min="').concat(30,'" max="').concat(300,'" step="10">\n <span id="scroll-margin-value"></span>\n </div>\n </div>\n\n <div class="debugger-section general-settings-section">\n <div class="debugger-section-header collapsible">\n <h3>General Settings</h3>\n <button class="section-minimize-button">-</button>\n </div>\n <div class="debugger-section-content general-settings-content">\n <div class="control-row">\n <label for="toggle-name-tags">\n Show Name Tags\n <span class="info-icon" title="').concat(["Visual Debug Name Tags","━━━━━━━━━━━━━━━━━━━━━━━━━━━━━","When enabled: Displays name tags over","each registered element in debug mode.","","Property: debuggerSettings.showNameTags"].join("\n"),'">i</span>\n </label>\n <input type="checkbox" id="toggle-name-tags">\n </div>\n </div>\n </div>\n </div>\n\n <div class="debugger-section debugger-elements">\n <div class="debugger-section-header elements-list-header">\n <h3>Elements <span id="element-count"></span> <span id="callback-count"></span></h3>\n <div class="header-controls">\n <div class="sort-control-container">\n <button class="sort-button" title="Change element list sort order">\n ').concat('<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"></polygon></svg>','\n </button>\n <div id="sort-options-popup">\n <button\n data-sort="visibility"\n title="').concat(["Sort by Visibility","━━━━━━━━━━━━━━━━━━━━━━━━━━━━━","Sorts elements by their viewport visibility","(visible elements first), with a secondary","sort by their order in the document.","","Property: debuggerSettings.sortElementList","Value: 'visibility'"].join("\n"),'">\n Visibility\n </button>\n <button\n data-sort="documentOrder"\n title="').concat(["Sort by Document Order","━━━━━━━━━━━━━━━━━━━━━━━━━━━━━","Sorts elements based on their order of","appearance in the document's structure","(matching the HTML source).","","Property: debuggerSettings.sortElementList","Value: 'documentOrder'"].join("\n"),'"\n >\n Document Order\n </button>\n <button\n data-sort="insertionOrder"\n title="').concat(["Sort by Insertion Order","━━━━━━━━━━━━━━━━━━━━━━━━━━━━━","Sorts elements based on the order they","were registered with the ForesightManager.","","Property: debuggerSettings.sortElementList","Value: 'insertionOrder'"].join("\n"),'"\n >\n Insertion Order\n </button>\n </div>\n </div>\n </div>\n </div>\n <div class="debugger-section-content element-list">\n <div id="element-list-items-container">\n </div>\n </div>\n </div>\n '),t},t.prototype.getStyles=function(){return'\n #debug-controls {\n position: fixed; bottom: 10px; right: 10px;\n background-color: rgba(0, 0, 0, 0.90); color: white; padding: 12px;\n border-radius: 5px; font-family: Arial, sans-serif; font-size: 13px;\n z-index: 10001; pointer-events: auto; display: flex; flex-direction: column; gap: 8px;\n width: 400px;\n transition: width 0.3s ease, height 0.3s ease;\n }\n #debug-controls.minimized {\n width: 250px;\n overflow: hidden;\n padding: 12px 0; \n }\n #debug-controls.minimized .debugger-title-container {\n padding-left: 10px; \n padding-right: 10px;\n gap: 10px; \n }\n #debug-controls.minimized .debugger-title-container h2 {\n display: inline;\n font-size: 14px;\n margin: 0;\n white-space: nowrap;\n }\n #debug-controls.minimized .info-icon {\n display: none;\n }\n\n #element-count,#callback-count {\n font-size: 12px;\n color: #9e9e9e;\n }\n\n .debugger-title-container {\n display: flex;\n align-items: center;\n justify-content: space-between; \n padding: 0 0px; \n }\n .title-group { \n display: flex;\n align-items: center;\n gap: 8px; \n\n }\n .minimize-button {\n background: none; border: none; color: white;\n font-size: 22px; cursor: pointer;\n line-height: 1;\n padding-inline: 0px;\n }\n .debugger-title-container h2 { margin: 0; font-size: 15px; }\n\n .copy-settings-button {\n background: none; border: none; color: white;\n cursor: pointer; padding: 0;\n display: flex; align-items: center; justify-content: center;\n }\n\n .copy-settings-button svg {\n width: 16px; height: 16px;\n stroke: white;\n }\n\n .minimized-element-count {\n font-size: 14px;\n min-width: 30px;\n text-align: right;\n }\n\n .all-settings-sections-container {\n display: flex;\n flex-direction: column;\n gap: 8px;\n }\n\n .debugger-section-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n margin-top: 5px;\n margin-bottom: 2px;\n padding-bottom: 2px;\n border-bottom: 1px solid #444;\n }\n .debugger-section-header.collapsible {\n cursor: pointer;\n }\n .debugger-section-header h3 {\n margin: 0;\n font-size: 14px;\n font-weight: bold;\n color: #b0c4de;\n flex-grow: 1;\n }\n\n .section-minimize-button {\n background: none;\n border: none;\n color: white;\n font-size: 18px;\n cursor: pointer;\n padding: 0px;\n line-height: 1;\n }\n\n #debug-controls .control-row {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 8px;\n }\n #debug-controls label {\n display: flex;\n align-items: center;\n gap: 5px;\n cursor: pointer;\n }\n #debug-controls .control-row:has(input[type="checkbox"]) label {\n flex-grow: 1;\n }\n #debug-controls .control-row input[type="checkbox"] {\n appearance: none; -webkit-appearance: none; -moz-appearance: none;\n position: relative; width: 40px; height: 18px;\n background-color: #555; border-radius: 10px; cursor: pointer;\n outline: none; transition: background-color 0.2s ease;\n vertical-align: middle; flex-shrink: 0; margin: 0;\n }\n #debug-controls .control-row input[type="checkbox"]::before {\n content: ""; position: absolute; width: 14px; height: 14px;\n border-radius: 50%; background-color: white; top: 2px; left: 2px;\n transition: transform 0.2s ease; box-shadow: 0 1px 3px rgba(0,0,0,0.4);\n }\n #debug-controls .control-row input[type="checkbox"]:checked {\n background-color: #b0c4de;\n }\n #debug-controls .control-row input[type="checkbox"]:checked::before {\n transform: translateX(22px);\n }\n #debug-controls .control-row:has(input[type="range"]) label {\n flex-basis: 170px; flex-shrink: 0;\n }\n #debug-controls input[type="range"] {\n flex-grow: 1; margin: 0; cursor: pointer; -webkit-appearance: none;\n appearance: none; background: transparent; height: 18px; vertical-align: middle;\n }\n #debug-controls input[type="range"]::-webkit-slider-runnable-track {\n height: 6px; background: #555; border-radius: 3px;\n }\n #debug-controls input[type="range"]::-moz-range-track {\n height: 6px; background: #555; border-radius: 3px;\n }\n #debug-controls input[type="range"]::-webkit-slider-thumb {\n -webkit-appearance: none; appearance: none; margin-top: -5px;\n background: #b0c4de; height: 16px; width: 16px;\n border-radius: 50%; border: 1px solid #333;\n }\n #debug-controls input[type="range"]::-moz-range-thumb {\n background: #b0c4de; height: 16px; width: 16px;\n border-radius: 50%; border: 1px solid #333; border: none;\n }\n #debug-controls .control-row:has(input[type="range"]) span:not(.info-icon) {\n width: 55px; min-width: 55px; text-align: right; flex-shrink: 0;\n }\n .info-icon {\n display: inline-flex; align-items: center; justify-content: center;\n width: 16px; height: 16px; border-radius: 50%;\n background-color: #555; color: white; font-size: 10px;\n font-style: italic; font-weight: bold; font-family: \'Georgia\', serif;\n cursor: help; user-select: none; flex-shrink: 0;\n }\n .debugger-section {\n display: flex; flex-direction: column; gap: 6px;\n }\n .debugger-section-content {\n display: none; flex-direction: column; gap: 8px;\n }\n\n /* Element List Styles */\n .elements-list-header { cursor: default; }\n .header-controls {\n display: flex;\n align-items: center;\n gap: 8px;\n }\n .sort-control-container {\n position: relative;\n }\n .sort-button {\n background: none; border: none; color: white; cursor: pointer;\n padding: 0; display: flex; align-items: center; justify-content: center;\n }\n .sort-button svg {\n width: 16px; height: 16px; stroke: #b0c4de; transition: stroke 0.2s;\n }\n .sort-button:hover svg { stroke: white; }\n \n #sort-options-popup {\n position: absolute;\n bottom: calc(100% + 5px);\n right: -5px;\n z-index: 10;\n display: none;\n flex-direction: column;\n gap: 4px;\n background-color: #3a3a3a;\n border: 1px solid #555;\n border-radius: 4px;\n padding: 3px;\n width: 200px;\n box-shadow: 0 4px 8px rgba(0,0,0,0.3);\n }\n #sort-options-popup.active {\n display: flex;\n }\n #sort-options-popup button {\n background: none; border: none; color: #ccc;\n font-size: 12px; text-align: left; padding: 5px 8px;\n cursor: pointer; border-radius: 3px;\n transition: background-color 0.2s, color 0.2s;\n display: flex;\n align-items: center;\n height: 26px;\n }\n #sort-options-popup button:hover {\n background-color: #555;\n color: white;\n }\n #sort-options-popup button.active-sort-option {\n color: #b0c4de;\n font-weight: bold;\n }\n #sort-options-popup button.active-sort-option::before {\n content: \'✓\';\n margin-right: 6px;\n width: 10px;\n }\n #sort-options-popup button::before {\n content: \'\';\n margin-right: 6px;\n width: 10px;\n }\n\n .element-list { /* Scroll container */\n min-height: '.concat(237,"px;\n max-height: ").concat(237,"px; \n overflow-y: auto;\n background-color: rgba(20, 20, 20, 0.5);\n border-radius: 3px;\n padding: 0;\n display: flex;\n }\n\n /* Modern Scrollbar Styling */\n .element-list::-webkit-scrollbar { width: 8px; }\n .element-list::-webkit-scrollbar-track { background: rgba(30, 30, 30, 0.5); border-radius: 4px; }\n .element-list::-webkit-scrollbar-thumb { background-color: rgba(176, 196, 222, 0.5); border-radius: 4px; border: 2px solid rgba(0, 0, 0, 0.2); }\n .element-list::-webkit-scrollbar-thumb:hover { background-color: rgba(176, 196, 222, 0.7); }\n .element-list { scrollbar-width: thin; scrollbar-color: rgba(176, 196, 222, 0.5) rgba(30, 30, 30, 0.5); }\n\n #element-list-items-container { \n display: flex;\n flex-wrap: wrap;\n gap: ").concat(3,"px;\n padding: ").concat(6,"px;\n min-height: ").concat(225,"px;\n box-sizing: border-box;\n align-content: flex-start;\n }\n #element-list-items-container > em {\n flex-basis: 100%;\n text-align: center;\n padding: 10px 0;\n font-style: italic;\n color: #ccc;\n font-size: 12px;\n }\n .element-list-item {\n flex-basis: calc((100% - (").concat(0," * ").concat(3,"px)) / ").concat(1,");\n flex-grow: 0;\n flex-shrink: 0;\n height: ").concat(35,"px;\n box-sizing: border-box;\n padding: 3px 5px;\n border-radius: 2px;\n display: flex;\n align-items: center;\n gap: 5px;\n background-color: rgba(50,50,50,0.7);\n transition: background-color 0.2s ease, opacity 0.2s ease;\n font-size: 11px; \n overflow: hidden;\n }\n \n /* Viewport intersection styling */\n .element-list-item.not-in-viewport { opacity: 0.4; }\n \n .element-list-item .element-name {\n flex-grow: 1;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n font-size: 12px; \n font-weight: bold;\n }\n .element-list-item .intersecting-indicator {\n font-size: 12px;\n flex-shrink: 0;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 16px;\n height: 16px;\n }\n .element-list-item .hit-behavior,\n .element-list-item .hit-slop {\n font-size: 10px; \n color: #b0b0b0;\n padding: 2px 5px; \n border-radius: 3px; \n background-color: rgba(0,0,0,0.2);\n flex-shrink: 0;\n }\n ")},t}();function z(t,e,n){var i=t.expandedOverlay,o=t.nameLabel,r=e.elementBounds.expandedRect,s=r.right-r.left,a=r.bottom-r.top;i.style.width="".concat(s,"px"),i.style.height="".concat(a,"px"),i.style.transform="translate3d(".concat(r.left,"px, ").concat(r.top,"px, 0)"),i.style.display="block",o.textContent=e.name,""!==e.name&&n?(o.style.display="block",o.style.transform="translate3d(".concat(r.left,"px, ").concat(r.top-25,"px, 0)")):o.style.display="none"}var L=class{static intersect(t,e){const n=Math.max(t.left,e.left),i=Math.min(t.right,e.right),o=Math.max(t.top,e.top),r=Math.min(t.bottom,e.bottom),s=Math.max(0,i-n),a=Math.max(0,r-o);return new DOMRect(n,o,s,a)}static clip(t,e){const n={...t.toJSON(),top:t.top+e.top,left:t.left+e.left,bottom:t.bottom-e.bottom,right:t.right-e.right};return n.width=n.right-n.left,n.height=n.bottom-n.top,n}static clipOffsets(t,e){return{top:e.top-t.top,left:e.left-t.left,bottom:t.bottom-e.bottom,right:t.right-e.right}}static equals(t,e){return null==t||null==e?t===e:t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}static sizeEqual(t,e){return Math.round(t.width)===Math.round(e.width)&&Math.round(t.height)===Math.round(e.height)}};function R(t,e){const n=Math.max(t.width,3),i=Math.max(t.height,3),o=t.top-e.top- -1,r=t.left-e.left- -1,s=e.right-t.left-n- -1,a=e.bottom-t.top-i- -1;return`${-Math.round(o)}px ${-Math.round(s)}px ${-Math.round(a)}px ${-Math.round(r)}px`}var D=[...Array.from({length:1e3},((t,e)=>e/1e3)),1],B=class{constructor(t,e,n){this.#t=e,this.#e=n,this.#n=n.clientRect,this.#i(t)}#t;#o=void 0;#e;#n;#r=void 0;get visibleRect(){const t=this.#e.clip;return t?L.clip(this.#n,t):this.#n}get isIntersecting(){const{width:t,height:e}=this.visibleRect;return t>0&&e>0}#i(t){const{root:e,rootBounds:n}=this.#e,{visibleRect:i}=this;this.#o?.disconnect(),this.#o=new IntersectionObserver(this.#s,{root:e,rootMargin:R(i,n),threshold:D}),this.#o.observe(t)}#s=t=>{if(!this.#o)return;const e=t[t.length-1];if(e){const{intersectionRatio:t,boundingClientRect:n}=e,i=this.#n;this.#n=n;const o=this.#r,r=!L.equals(n,i);if(t!==this.#r||r){const i=this.#e.rootBounds,s=L.intersect(n,i),a=s.width>0&&s.height>0;if(!a)return;this.#r=t,(null!=o||r)&&(this.#t(new H(e.target,n,e.intersectionRect,a,i),this),this.#i(e.target))}}};disconnect(){this.#o?.disconnect()}},H=class{constructor(t,e,n,i,o){this.target=t,this.boundingClientRect=e,this.intersectionRect=n,this.isIntersecting=i,this.rootBounds=o}},N=class{constructor(t,e){const n=function(t){return!t||function(t){return t.nodeType===Node.DOCUMENT_NODE}(t)?t?.defaultView??window:t}(t);if(function(t){return A(t)&&t.nodeType===Node.ELEMENT_NODE}(n)){const t=n.ownerDocument??document;this.rootBounds=n.getBoundingClientRect(),this.#a=new ResizeObserver((t=>{for(const n of t){const[{inlineSize:t,blockSize:i}]=n.borderBoxSize;if(L.sizeEqual(this.rootBounds,{width:t,height:i}))continue;const o=n.target.getBoundingClientRect();this.rootBounds=o,e(o,this)}})),this.#a.observe(n),t.addEventListener("scroll",(t=>{t.target&&t.target!==n&&A(t.target)&&t.target.contains(n)&&(this.rootBounds=n.getBoundingClientRect(),e(this.rootBounds,this))}),{capture:!0,passive:!0,signal:this.#l.signal})}else{const t=n.visualViewport??n;this.rootBounds=V(n);const i=()=>{const t=V(n);L.equals(this.rootBounds,t)||(this.rootBounds=t,e(t,this))};t.addEventListener("resize",i,{signal:this.#l.signal})}}#a;#l=new AbortController;rootBounds;disconnect(){this.#a?.disconnect(),this.#l.abort()}};function V(t){const e=t.visualViewport?.width??t.innerWidth,n=t.visualViewport?.height??t.innerHeight;return new DOMRect(0,0,e,n)}function A(t){return"nodeType"in t}var _=class{constructor(t,e){this.#e=e,this.#t=e=>{const n=[];for(const t of e){const e=this.intersections.get(t.target);this.intersections.set(t.target,t),e?.isIntersecting===t.isIntersecting&&L.equals(e?.intersectionRect,t.intersectionRect)||n.push(t)}n.length>0&&t(n,this)}}#t;#c=new Map;#e;intersections=new WeakMap;observe(t){const e=t.ownerDocument;if(!e)return;let n=this.#c.get(e);n||(n=new IntersectionObserver(this.#t,{...this.#e,threshold:D}),this.#c.set(e,n)),n.observe(t)}unobserve(t){const e=t.ownerDocument;if(!e)return;const n=this.#c.get(e);n&&(n.unobserve(t),this.intersections.delete(t))}disconnect(){for(const t of this.#c.values())t.disconnect();this.#c.clear()}},q=class{constructor(t,e){this.#t=t,this.#e=e,this.#d=new N(e?.root,this.#u),this.#h=new _(this.#g,e),this.#a=new ResizeObserver(this.#p)}#t;#e;#b=new Map;#a;#m=new WeakMap;#d;#h;observe(t){this.#h.observe(t)}unobserve(t){t?(this.#b.get(t)?.disconnect(),this.#h.unobserve(t)):this.disconnect()}disconnect(){for(const t of this.#b.values())t.disconnect();this.#a.disconnect(),this.#d.disconnect(),this.#h.disconnect()}#f(t){const e=[];for(const n of t){const{target:t}=n;U(n,this.#m.get(t))||(this.#m.set(t,n),e.push(n))}e.length>0&&this.#t(e)}#u=t=>{const e=[];for(const[n]of this.#b){const i=n.getBoundingClientRect(),o=this.#v(n,i);e.push(new F(n,i,o.visibleRect,o.isIntersecting,t))}this.#f(e)};#v(t,e){const n=this.#h;this.#b.get(t)?.disconnect();const i=new B(t,this.#y,{clientRect:e,root:this.#e?.root,rootBounds:this.#d.rootBounds,get clip(){const e=n.intersections.get(t);if(!e)return;const{intersectionRect:i,boundingClientRect:o}=e;return L.clipOffsets(o,i)}});return this.#b.set(t,i),i}#g=t=>{const e=[];for(const n of t){const{target:t,isIntersecting:i,boundingClientRect:o}=n;i?(this.#v(t,o),this.#a.observe(t)):(this.#b.get(t)?.disconnect(),this.#b.delete(t),this.#a.unobserve(t));const r=this.#b.get(t);e.push(new F(t,o,r?.visibleRect??n.intersectionRect,i,this.#d.rootBounds))}this.#f(e)};#y=(t,e)=>{this.#f([new F(t.target,t.boundingClientRect,e.visibleRect,t.isIntersecting,this.#d.rootBounds)])};#p=t=>{const e=[];for(const n of t){const{target:t,borderBoxSize:i}=n,o=this.#m.get(t);if(o){const[{inlineSize:t,blockSize:e}]=i;if(L.sizeEqual(o.boundingClientRect,{width:t,height:e}))continue}const r=t.getBoundingClientRect(),s=this.#v(t,r);e.push(new F(t,r,s.visibleRect,this.#h.intersections.get(t)?.isIntersecting??!1,this.#d.rootBounds))}this.#f(e)}},F=class{constructor(t,e,n,i,o){this.target=t,this.boundingClientRect=e,this.intersectionRect=n,this.isIntersecting=i,this.rootBounds=o}};function U(t,e){return null!=e&&(t.target===e.target&&t.isIntersecting===e.isIntersecting&&L.equals(t.boundingClientRect,e.boundingClientRect)&&L.equals(t.intersectionRect,e.intersectionRect))}function W(){var t,e=window.matchMedia("(pointer: coarse)").matches&&navigator.maxTouchPoints>0,n=!!(t=navigator.connection)&&(/2g/.test(t.effectiveType)||t.saveData);return{isTouchDevice:e,isLimitedConnection:n,shouldRegister:!e&&!n}}var G=function(){function t(t){var e=this;this.callbackAnimations=new Map,this.debugElementOverlays=new Map,this.predictedMouseIndicator=null,this.mouseTrajectoryLine=null,this.scrollTrajectoryLine=null,this.animationPositionObserver=null,this.handleAnimationPositionChange=function(t){for(var n=0,i=t;n<i.length;n++){var o=i[n],r=e.callbackAnimations.get(o.target);if(r){var s=o.boundingClientRect,a=r.hitSlop,l=r.overlay,c=s.left-a.left,d=s.top-a.top,u=s.width+a.left+a.right,h=s.height+a.top+a.bottom;l.style.transform="translate3d(".concat(c,"px, ").concat(d,"px, 0)"),l.style.width="".concat(u,"px"),l.style.height="".concat(h,"px")}}},this.foresightManagerInstance=t}return t.prototype._setupDOM=function(){this.shadowHost||(this.shadowHost=M("div",document.body,{id:"jsforesight-debugger-shadow-host"}),this.shadowRoot=this.shadowHost.attachShadow({mode:"open"}),this.debugContainer=M("div",this.shadowRoot,{id:"jsforesight-debug-container"}),this.predictedMouseIndicator=M("div",this.debugContainer,{className:"jsforesight-mouse-predicted"}),this.mouseTrajectoryLine=M("div",this.debugContainer,{className:"jsforesight-trajectory-line"}),this.scrollTrajectoryLine=M("div",this.debugContainer,{className:"jsforesight-scroll-trajectory-line"}),this.controlPanel=I.initialize(this.foresightManagerInstance,this.shadowRoot,this.foresightManagerInstance.getManagerData.globalSettings.debuggerSettings),O(K,this.shadowRoot,"screen-visuals"),this.animationPositionObserver=new q(this.handleAnimationPositionChange))},Object.defineProperty(t,"isInitiated",{get:function(){return!!t.debuggerInstance},enumerable:!1,configurable:!0}),t.initialize=function(e,n){if(document.querySelectorAll("#jsforesight-debugger-shadow-host").forEach((function(t){return t.remove()})),"undefined"==typeof window||!W().shouldRegister)return null;t.isInitiated||(t.debuggerInstance=new t(e));var i=t.debuggerInstance;return i.shadowHost||i._setupDOM(),i.updateMouseTrajectoryVisuals(n,e.getManagerData.globalSettings.enableMousePrediction),i},t.prototype.createElementOverlays=function(t){var e={expandedOverlay:M("div",this.debugContainer,{className:"jsforesight-expanded-overlay",data:t.name}),nameLabel:M("div",this.debugContainer,{className:"jsforesight-name-label"})};return this.debugElementOverlays.set(t.element,e),e},t.prototype.createOrUpdateElementOverlay=function(t){var e;if(this.debugContainer&&this.shadowRoot){var n=this.debugElementOverlays.get(t.element);n||(n=this.createElementOverlays(t)),z(n,t,null!==(e=this.foresightManagerInstance.getManagerData.globalSettings.debuggerSettings.showNameTags)&&void 0!==e?e:k)}},t.prototype.toggleNameTagVisibility=function(){var t=this;this.foresightManagerInstance.registeredElements.forEach((function(e){var n,i=t.debugElementOverlays.get(e.element);i&&z(i,e,null!==(n=t.foresightManagerInstance.getManagerData.globalSettings.debuggerSettings.showNameTags)&&void 0!==n?n:k)}))},t.prototype.removeElement=function(t){var e;this.removeElementOverlay(t),null===(e=this.controlPanel)||void 0===e||e.removeElementFromList(t)},t.prototype.removeElementOverlay=function(t){var e=this.debugElementOverlays.get(t.element);e&&(e.expandedOverlay.remove(),e.nameLabel.remove(),this.debugElementOverlays.delete(t.element))},t.prototype.addElement=function(t,e){void 0===e&&(e=!0),this.createOrUpdateElementOverlay(t),this.controlPanel.addElementToList(t,e)},t.prototype.updateMouseTrajectoryVisuals=function(t,e){if(this.shadowRoot&&this.debugContainer&&this.predictedMouseIndicator&&this.mouseTrajectoryLine){var n=t.predictedPoint,i=t.currentPoint;if(this.predictedMouseIndicator.style.transform="translate3d(".concat(n.x,"px, ").concat(n.y,"px, 0) translate3d(-50%, -50%, 0)"),this.predictedMouseIndicator.style.display=e?"block":"none",0!==n.x||0!==n.y)if(e){var o=n.x-i.x,r=n.y-i.y,s=Math.sqrt(o*o+r*r),a=180*Math.atan2(r,o)/Math.PI;this.mouseTrajectoryLine.style.transform="translate3d(".concat(i.x,"px, ").concat(i.y,"px, 0) rotate(").concat(a,"deg)"),this.mouseTrajectoryLine.style.width="".concat(s,"px"),this.mouseTrajectoryLine.style.display="block"}else this.mouseTrajectoryLine.style.display="none";else this.predictedMouseIndicator.style.display="none"}},t.prototype.updateScrollTrajectoryVisuals=function(t,e){if(this.scrollTrajectoryLine){var n=e.x-t.x,i=e.y-t.y,o=Math.sqrt(n*n+i*i),r=180*Math.atan2(i,n)/Math.PI;this.scrollTrajectoryLine.style.transform="translate3d(".concat(t.x,"px, ").concat(t.y,"px, 0) rotate(").concat(r,"deg)"),this.scrollTrajectoryLine.style.width="".concat(o,"px"),this.scrollTrajectoryLine.style.display="block"}},t.prototype.hideScrollTrajectoryVisuals=function(){this.scrollTrajectoryLine&&(this.scrollTrajectoryLine.style.display="none")},t.prototype.updateControlsState=function(t){var e;null===(e=this.controlPanel)||void 0===e||e.updateControlsState(t)},t.prototype.updateElementVisibilityStatus=function(t){var e;null===(e=this.controlPanel)||void 0===e||e.updateElementVisibilityStatus(t)},t.prototype.removeElementFromList=function(t){var e;null===(e=this.controlPanel)||void 0===e||e.removeElementFromList(t)},t.prototype.showCallbackAnimation=function(t){var e,n,i=this,o=t.element,r=t.elementBounds,s=this.callbackAnimations.get(o);s&&(clearTimeout(s.timeoutId),s.overlay.remove(),null===(e=this.animationPositionObserver)||void 0===e||e.unobserve(o),this.callbackAnimations.delete(o));var a=M("div",this.debugContainer,{className:"jsforesight-callback-indicator"}),l=r.expandedRect,c=l.left,d=l.top,u=l.right-c,h=l.bottom-d;a.style.display="block",a.style.transform="translate3d(".concat(c,"px, ").concat(d,"px, 0)"),a.style.width="".concat(u,"px"),a.style.height="".concat(h,"px"),a.classList.add("animate");var g=setTimeout((function(){var t;a.remove(),i.callbackAnimations.delete(o),null===(t=i.animationPositionObserver)||void 0===t||t.unobserve(o)}),500);this.callbackAnimations.set(o,{hitSlop:t.elementBounds.hitSlop,overlay:a,timeoutId:g}),null===(n=this.animationPositionObserver)||void 0===n||n.observe(o)},t.prototype.cleanup=function(){var t,e;null===(t=this.controlPanel)||void 0===t||t.cleanup(),null===(e=this.shadowHost)||void 0===e||e.remove(),this.debugElementOverlays.clear(),this.shadowHost=null,this.shadowRoot=null,this.debugContainer=null,this.predictedMouseIndicator=null,this.mouseTrajectoryLine=null,this.scrollTrajectoryLine=null,this.controlPanel=null},t}(),K='\n #jsforesight-debug-container { \n position: fixed; top: 0; left: 0; width: 100%; height: 100%;\n pointer-events: none; z-index: 9999;\n }\n\n .jsforesight-expanded-overlay, \n .jsforesight-name-label, \n .jsforesight-callback-indicator,\n .jsforesight-mouse-predicted,\n .jsforesight-scroll-trajectory-line,\n .jsforesight-trajectory-line {\n position: absolute;\n top: 0;\n left: 0;\n will-change: transform; \n }\n .jsforesight-expanded-overlay {\n border: 1px dashed rgba(100, 116, 139, 0.4);\n background-color: rgba(100, 116, 139, 0.05);\n box-sizing: border-box;\n border-radius: 8px;\n }\n .jsforesight-mouse-predicted {\n display: none !important;\n /* transform is now set dynamically via JS for performance */\n }\n .jsforesight-trajectory-line {\n height: 4px;\n background: linear-gradient(90deg, #3b82f6, rgba(59, 130, 246, 0.4));\n transform-origin: left center;\n z-index: 9999;\n border-radius: 2px;\n box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);\n position: relative;\n /* width and transform are set dynamically via JS for performance */\n }\n .jsforesight-trajectory-line::after {\n content: \'\';\n position: absolute;\n right: -6px;\n top: 50%;\n transform: translateY(-50%);\n width: 0;\n height: 0;\n border-left: 8px solid #3b82f6;\n border-top: 4px solid transparent;\n border-bottom: 4px solid transparent;\n filter: drop-shadow(0 0 6px rgba(59, 130, 246, 0.6));\n }\n .jsforesight-name-label {\n background-color: rgba(27, 31, 35, 0.85);\n backdrop-filter: blur(4px);\n color: white;\n padding: 4px 8px;\n font-size: 11px;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";\n border-radius: 4px;\n z-index: 10001;\n white-space: nowrap;\n pointer-events: none;\n }\n .jsforesight-callback-indicator {\n border: 4px solid oklch(65% 0.22 280); \n border-radius: 8px;\n box-sizing: border-box;\n pointer-events: none;\n opacity: 0;\n z-index: 10002;\n display: none; \n }\n .jsforesight-callback-indicator.animate {\n animation: jsforesight-callback-pulse 0.5s ease-out forwards;\n }\n \n .jsforesight-scroll-trajectory-line {\n height: 4px;\n background: repeating-linear-gradient(\n 90deg,\n #22c55e 0px,\n #22c55e 8px,\n transparent 8px,\n transparent 16px\n );\n transform-origin: left center;\n z-index: 9999;\n border-radius: 2px;\n display: none;\n animation: scroll-dash-flow 1.5s linear infinite;\n position: relative;\n box-shadow: 0 0 12px rgba(34, 197, 94, 0.4);\n }\n\n .jsforesight-scroll-trajectory-line::after {\n content: \'\';\n position: absolute;\n right: -6px;\n top: 50%;\n transform: translateY(-50%);\n width: 0;\n height: 0;\n border-left: 8px solid #22c55e;\n border-top: 4px solid transparent;\n border-bottom: 4px solid transparent;\n filter: drop-shadow(0 0 6px rgba(34, 197, 94, 0.6));\n animation: scroll-arrow-pulse 1.5s ease-in-out infinite;\n }\n\n @keyframes scroll-dash-flow {\n 0% { background-position: 0px 0px; }\n 100% { background-position: 16px 0px; }\n }\n\n @keyframes scroll-arrow-pulse {\n 0%, 100% { \n transform: translateY(-50%) scale(1);\n filter: drop-shadow(0 0 6px rgba(34, 197, 94, 0.6));\n }\n 50% {\n transform: translateY(-50%) scale(1.2);\n filter: drop-shadow(0 0 12px rgba(34, 197, 94, 0.8));\n }\n }\n\n\n \n @keyframes jsforesight-callback-pulse {\n 0% {\n opacity: 1;\n box-shadow: 0 0 15px oklch(65% 0.22 280 / 0.7);\n }\n 100% {\n opacity: 0;\n box-shadow: 0 0 25px oklch(65% 0.22 280 / 0);\n }\n }\n ';function J(t,e,n,i,o){return i&&(t<e?console.warn('ForesightJS: "'.concat(o,'" value ').concat(t," is below minimum bound ").concat(e,", clamping to ").concat(e)):t>n&&console.warn('ForesightJS: "'.concat(o,'" value ').concat(t," is above maximum bound ").concat(n,", clamping to ").concat(n))),Math.min(Math.max(t,e),n)}function Y(t,e,n){var i=0,o=1,r=e.x-t.x,s=e.y-t.y,a=function(t,e){if(0===t){if(e<0)return!1}else{var n=e/t;if(t<0){if(n>o)return!1;n>i&&(i=n)}else{if(n<i)return!1;n<o&&(o=n)}}return!0};return!!a(-r,t.x-n.left)&&(!!a(r,n.right-t.x)&&(!!a(-s,t.y-n.top)&&(!!a(s,n.bottom-t.y)&&i<=o)))}function $(t,e){if("number"==typeof t){var n=J(t,0,w,e,"hitslop");return{top:n,left:n,right:n,bottom:n}}return{top:J(t.top,0,w,e,"hitslop - top"),left:J(t.left,0,w,e,"hitslop - left"),right:J(t.right,0,w,e,"hitslop - right"),bottom:J(t.bottom,0,w,e,"hitslop - bottom")}}function X(t,e){return{left:t.left-e.left,right:t.right+e.right,top:t.top-e.top,bottom:t.bottom+e.bottom}}function Q(t,e){return t&&e?t.left===e.left&&t.right===e.right&&t.top===e.top&&t.bottom===e.bottom:t===e}function Z(t,e){return t.x>=e.left&&t.x<=e.right&&t.y>=e.top&&t.y<=e.bottom}function tt(t,e){return void 0!==t&&e!==t}var et=function(){function e(){var t=this;this.elements=new Map,this.isSetup=!1,this.debugger=null,this._globalCallbackHits={mouse:{hover:0,trajectory:0},tab:{forwards:0,reverse:0},scroll:{down:0,left:0,right:0,up:0},total:0},this._globalSettings={debug:false,enableMousePrediction:true,enableScrollPrediction:true,positionHistorySize:8,trajectoryPredictionTime:120,scrollMargin:150,defaultHitSlop:{top:0,left:0,right:0,bottom:0},resizeScrollThrottleDelay:0,debuggerSettings:{isControlPanelDefaultMinimized:C,showNameTags:k,sortElementList:"visibility"},enableTabPrediction:true,tabOffset:2,onAnyCallbackFired:function(t,e){}},this.trajectoryPositions={positions:[],currentPoint:{x:0,y:0},predictedPoint:{x:0,y:0}},this.tabbableElementsCache=[],this.lastFocusedIndex=null,this.predictedScrollPoint=null,this.scrollDirection=null,this.domObserver=null,this.positionObserver=null,this.lastKeyDown=null,this.globalListenersController=null,this.handleMouseMove=function(e){t.updatePointerState(e),t.elements.forEach((function(e){e.isIntersectingWithViewport&&(e.unregisterOnCallback?t.handleSingleCallbackInteraction(e):t.handleMultiCallbackInteraction(e))})),t.debugger&&(t.debugger.hideScrollTrajectoryVisuals(),t.debugger.updateMouseTrajectoryVisuals(t.trajectoryPositions,t._globalSettings.enableMousePrediction))},this.handleDomMutations=function(e){e.length&&(t.tabbableElementsCache=[],t.lastFocusedIndex=null);for(var n=0,i=e;n<i.length;n++){var o=i[n];if("childList"===o.type&&o.removedNodes.length>0)for(var r=0,s=Array.from(t.elements.keys());r<s.length;r++){var a=s[r];a.isConnected||t.unregister(a)}}},this.handleKeyDown=function(e){"Tab"===e.key&&(t.lastKeyDown=e)},this.handleFocusIn=function(e){if(t.lastKeyDown&&t._globalSettings.enableTabPrediction){var n=e.target;if(n instanceof HTMLElement){t.tabbableElementsCache.length||(t.tabbableElementsCache=v(document.documentElement),t._globalSettings.debug&&console.log("ForesightJS: Recomputed tabbable elements cache because of DOM change"));var i=t.lastKeyDown.shiftKey,o=function(t,e,n,i){if(null!==e){var o=t?e-1:e+1;if(o>=0&&o<n.length&&n[o]===i)return o}return n.findIndex((function(t){return t===i}))}(i,t.lastFocusedIndex,t.tabbableElementsCache,n);t.lastFocusedIndex=o,t.lastKeyDown=null;for(var r=[],s=0;s<=t._globalSettings.tabOffset;s++)if(i){var a=t.tabbableElementsCache[o-s];t.elements.has(a)&&r.push(a)}else{a=t.tabbableElementsCache[o+s];t.elements.has(a)&&r.push(a)}r.forEach((function(e){t.callCallback(t.elements.get(e),{kind:"tab",subType:i?"reverse":"forwards"})}))}}},this.handlePositionChange=function(e){for(var n,i,o=0,r=e;o<r.length;o++){var s=r[o],a=t.elements.get(s.target);if(a){var l=a.isIntersectingWithViewport,c=s.isIntersecting;a.isIntersectingWithViewport=c,l!==c&&(null===(n=t.debugger)||void 0===n||n.updateElementVisibilityStatus(a)),c?(t.updateElementBounds(s.boundingClientRect,a),t.handleScrollPrefetch(a,s.boundingClientRect)):t._globalSettings.debug&&l&&(null===(i=t.debugger)||void 0===i||i.removeElementOverlay(a))}}t.scrollDirection=null,t.predictedScrollPoint=null}}return e.initialize=function(t){return this.isInitiated||(e.manager=new e),void 0!==t&&e.manager.alterGlobalSettings(t),e.manager},Object.defineProperty(e.prototype,"getManagerData",{get:function(){return{registeredElements:this.elements,globalSettings:this._globalSettings,globalCallbackHits:this._globalCallbackHits}},enumerable:!1,configurable:!0}),Object.defineProperty(e,"isInitiated",{get:function(){return!!e.manager},enumerable:!1,configurable:!0}),Object.defineProperty(e,"instance",{get:function(){return this.initialize()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"registeredElements",{get:function(){return this.elements},enumerable:!1,configurable:!0}),e.prototype.register=function(t){var e,n,i=this,o=t.element,r=t.callback,s=t.hitSlop,a=t.unregisterOnCallback,l=t.name,c=W(),d=c.shouldRegister,u=c.isTouchDevice,h=c.isLimitedConnection;if(!d)return{isLimitedConnection:h,isTouchDevice:u,isRegistered:!1,unregister:function(){}};this.isSetup||this.initializeGlobalListeners();var g=s?$(s,this._globalSettings.debug):this._globalSettings.defaultHitSlop,p={element:o,callback:r,callbackHits:{mouse:{hover:0,trajectory:0},tab:{forwards:0,reverse:0},scroll:{down:0,left:0,right:0,up:0},total:0},elementBounds:{originalRect:void 0,expandedRect:{top:0,left:0,right:0,bottom:0},hitSlop:g},isHovering:!1,trajectoryHitData:{isTrajectoryHit:!1,trajectoryHitTime:0,trajectoryHitExpirationTimeoutId:void 0},name:null!==(e=null!=l?l:o.id)&&void 0!==e?e:"",unregisterOnCallback:null==a||a,isIntersectingWithViewport:!0};return this.elements.set(o,p),null===(n=this.positionObserver)||void 0===n||n.observe(o),this.debugger&&this.debugger.addElement(p),{isTouchDevice:u,isLimitedConnection:h,isRegistered:!0,unregister:function(){return i.unregister(o)}}},e.prototype.unregister=function(t){var e;if(this.elements.has(t)){var n=this.elements.get(t);(null==n?void 0:n.trajectoryHitData.trajectoryHitExpirationTimeoutId)&&clearTimeout(n.trajectoryHitData.trajectoryHitExpirationTimeoutId),null===(e=this.positionObserver)||void 0===e||e.unobserve(t),this.elements.delete(t),this.debugger&&n&&this.debugger.removeElement(n),0===this.elements.size&&this.isSetup&&this.removeGlobalListeners()}},e.prototype.updateNumericSettings=function(t,e,n,i){return!!tt(t,this._globalSettings[e])&&(this._globalSettings[e]=J(t,n,i,this._globalSettings.debug,e),!0)},e.prototype.updateBooleanSetting=function(t,e){return!!tt(t,this._globalSettings[e])&&(this._globalSettings[e]=t,!0)},e.prototype.alterGlobalSettings=function(t){var e,n,i,o=this._globalSettings.positionHistorySize,r=this.updateNumericSettings(null==t?void 0:t.positionHistorySize,"positionHistorySize",2,30);r&&this._globalSettings.positionHistorySize<o&&this.trajectoryPositions.positions.length>this._globalSettings.positionHistorySize&&(this.trajectoryPositions.positions=this.trajectoryPositions.positions.slice(this.trajectoryPositions.positions.length-this._globalSettings.positionHistorySize));var s=this.updateNumericSettings(null==t?void 0:t.trajectoryPredictionTime,"trajectoryPredictionTime",10,200),a=this.updateNumericSettings(null==t?void 0:t.scrollMargin,"scrollMargin",30,300),l=this.updateNumericSettings(null==t?void 0:t.tabOffset,"tabOffset",0,20);void 0!==(null==t?void 0:t.resizeScrollThrottleDelay)&&console.warn("resizeScrollThrottleDelay is deprecated and will be removed in V3.0.0 of ForesightJS");var c=this.updateBooleanSetting(null==t?void 0:t.enableMousePrediction,"enableMousePrediction"),d=this.updateBooleanSetting(null==t?void 0:t.enableScrollPrediction,"enableScrollPrediction"),u=this.updateBooleanSetting(null==t?void 0:t.enableTabPrediction,"enableTabPrediction");void 0!==(null==t?void 0:t.onAnyCallbackFired)&&(this._globalSettings.onAnyCallbackFired=t.onAnyCallbackFired);var h=!1;void 0!==(null===(e=null==t?void 0:t.debuggerSettings)||void 0===e?void 0:e.isControlPanelDefaultMinimized)&&(this._globalSettings.debuggerSettings.isControlPanelDefaultMinimized=t.debuggerSettings.isControlPanelDefaultMinimized,h=!0),void 0!==(null===(n=null==t?void 0:t.debuggerSettings)||void 0===n?void 0:n.showNameTags)&&(this._globalSettings.debuggerSettings.showNameTags=t.debuggerSettings.showNameTags,h=!0,this.debugger&&this.debugger.toggleNameTagVisibility()),void 0!==(null===(i=null==t?void 0:t.debuggerSettings)||void 0===i?void 0:i.sortElementList)&&(this._globalSettings.debuggerSettings.sortElementList=t.debuggerSettings.sortElementList,h=!0,this.debugger);var g=!1;if(void 0!==(null==t?void 0:t.defaultHitSlop)){var p=$(t.defaultHitSlop,this._globalSettings.debug);Q(this._globalSettings.defaultHitSlop,p)||(this._globalSettings.defaultHitSlop=p,g=!0,this.forceUpdateAllElementBounds())}var b=!1;void 0!==(null==t?void 0:t.debug)&&this._globalSettings.debug!==t.debug&&"undefined"!=typeof window&&"undefined"!=typeof document&&(this._globalSettings.debug=t.debug,b=!0,this._globalSettings.debug?this.turnOnDebugMode():this.debugger&&(this.debugger.cleanup(),this.debugger=null)),(r||s||l||c||u||d||h||g||a||b)&&this.debugger&&this.debugger.updateControlsState(this._globalSettings)},e.prototype.turnOnDebugMode=function(){var t=this;if(this.debugger)this.debugger.updateControlsState(this._globalSettings);else{this.debugger=G.initialize(e.instance,this.trajectoryPositions);var n=Array.from(this.elements.values());n.forEach((function(e,i){var o,r=i===n.length-1;null===(o=t.debugger)||void 0===o||o.addElement(e,r)}))}},e.prototype.forceUpdateAllElementBounds=function(){var t=this;this.elements.forEach((function(e,n){var i=t.elements.get(n);i&&i.isIntersectingWithViewport&&t.forceUpdateElementBounds(i)}))},e.prototype.updatePointerState=function(e){this.trajectoryPositions.currentPoint={x:e.clientX,y:e.clientY},this.trajectoryPositions.predictedPoint=this._globalSettings.enableMousePrediction?function(t,e,n,i){var o={point:t,time:performance.now()},r=t.x,s=t.y;if(e.push(o),e.length>n&&e.shift(),e.length<2)return{x:r,y:s};var a=e[0],l=e[e.length-1],c=(l.time-a.time)/1e3;if(0===c)return{x:r,y:s};var d=i/1e3;return{x:r+(l.point.x-a.point.x)/c*d,y:s+(l.point.y-a.point.y)/c*d}}(this.trajectoryPositions.currentPoint,this.trajectoryPositions.positions,this._globalSettings.positionHistorySize,this._globalSettings.trajectoryPredictionTime):t({},this.trajectoryPositions.currentPoint)},e.prototype.handleSingleCallbackInteraction=function(t){var e=t.elementBounds.expandedRect;if(this._globalSettings.enableMousePrediction)Y(this.trajectoryPositions.currentPoint,this.trajectoryPositions.predictedPoint,e)&&this.callCallback(t,{kind:"mouse",subType:"trajectory"});else if(Z(this.trajectoryPositions.currentPoint,e))return void this.callCallback(t,{kind:"mouse",subType:"hover"})},e.prototype.handleMultiCallbackInteraction=function(e){var n=this,i=e.elementBounds.expandedRect,o=Z(this.trajectoryPositions.currentPoint,i),r=o&&!e.isHovering,s=this._globalSettings.enableMousePrediction&&!o&&!e.trajectoryHitData.isTrajectoryHit&&Y(this.trajectoryPositions.currentPoint,this.trajectoryPositions.predictedPoint,i);if((r||s)&&this.callCallback(e,{kind:"mouse",subType:r?"hover":"trajectory"}),o!==e.isHovering||s){var a=t(t({},e),{isHovering:o,trajectoryHitData:t(t({},e.trajectoryHitData),{isTrajectoryHit:s,trajectoryHitTime:s?performance.now():e.trajectoryHitData.trajectoryHitTime})});s&&(a.trajectoryHitData.trajectoryHitExpirationTimeoutId&&clearTimeout(a.trajectoryHitData.trajectoryHitExpirationTimeoutId),a.trajectoryHitData.trajectoryHitExpirationTimeoutId=setTimeout((function(){var t,i=n.elements.get(e.element);i&&i.trajectoryHitData.trajectoryHitTime===a.trajectoryHitData.trajectoryHitTime&&(i.trajectoryHitData.isTrajectoryHit=!1,null===(t=n.debugger)||void 0===t||t.createOrUpdateElementOverlay(i))}),200)),this.elements.set(e.element,a)}},e.prototype.updateHitCounters=function(t,e){switch(e.kind){case"mouse":t.callbackHits.mouse[e.subType]++,this._globalCallbackHits.mouse[e.subType]++;break;case"tab":t.callbackHits.tab[e.subType]++,this._globalCallbackHits.tab[e.subType]++;break;case"scroll":t.callbackHits.scroll[e.subType]++,this._globalCallbackHits.scroll[e.subType]++}t.callbackHits.total++,this._globalCallbackHits.total++},e.prototype.callCallback=function(t,e){t&&(this.updateHitCounters(t,e),t.callback(),this._globalSettings.onAnyCallbackFired(t,this.getManagerData),this.debugger&&this.debugger.showCallbackAnimation(t),t.unregisterOnCallback&&this.unregister(t.element))},e.prototype.forceUpdateElementBounds=function(e){var n=e.element.getBoundingClientRect(),i=X(n,e.elementBounds.hitSlop);if(!Q(i,e.elementBounds.expandedRect)&&(this.elements.set(e.element,t(t({},e),{elementBounds:t(t({},e.elementBounds),{originalRect:n,expandedRect:i})})),this.debugger)){var o=this.elements.get(e.element);o&&this.debugger.createOrUpdateElementOverlay(o)}},e.prototype.updateElementBounds=function(e,n){if(this.elements.set(n.element,t(t({},n),{elementBounds:t(t({},n.elementBounds),{originalRect:e,expandedRect:X(e,n.elementBounds.hitSlop)})})),this.debugger){var i=this.elements.get(n.element);i&&this.debugger.createOrUpdateElementOverlay(i)}},e.prototype.handleScrollPrefetch=function(t,e){var n,i;if(this._globalSettings.enableScrollPrediction){if(!t.elementBounds.originalRect)return;if(this.scrollDirection=null!==(n=this.scrollDirection)&&void 0!==n?n:function(t,e){var n=e.top-t.top,i=e.left-t.left;return n<-1?"down":n>1?"up":i<-1?"right":i>1?"left":"none"}(t.elementBounds.originalRect,e),"none"===this.scrollDirection)return;this.predictedScrollPoint=null!==(i=this.predictedScrollPoint)&&void 0!==i?i:function(t,e,n){var i={x:t.x,y:t.y};switch(e){case"down":i.y+=n;break;case"up":i.y-=n;break;case"left":i.x-=n;break;case"right":i.x+=n}return i}(this.trajectoryPositions.currentPoint,this.scrollDirection,this._globalSettings.scrollMargin),Y(this.trajectoryPositions.currentPoint,this.predictedScrollPoint,null==t?void 0:t.elementBounds.expandedRect)&&this.callCallback(t,{kind:"scroll",subType:this.scrollDirection}),this.debugger&&this.debugger.updateScrollTrajectoryVisuals(this.trajectoryPositions.currentPoint,this.predictedScrollPoint)}else Z(this.trajectoryPositions.currentPoint,t.elementBounds.expandedRect)&&this.callCallback(t,{kind:"mouse",subType:"hover"})},e.prototype.initializeGlobalListeners=function(){if(!this.isSetup&&"undefined"!=typeof window&&"undefined"!=typeof document){this.globalListenersController=new AbortController;var t=this.globalListenersController.signal;document.addEventListener("mousemove",this.handleMouseMove,{signal:t}),document.addEventListener("keydown",this.handleKeyDown,{signal:t}),document.addEventListener("focusin",this.handleFocusIn,{signal:t}),this.domObserver=new MutationObserver(this.handleDomMutations),this.domObserver.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!1}),this.positionObserver=new q(this.handlePositionChange),this.isSetup=!0}},e.prototype.removeGlobalListeners=function(){var t,e,n;this.isSetup=!1,this.debugger?console.log("ForesightJS: All elements have successfully been unregistered. ForesightJS would typically perform cleanup events now, but these are currently skipped while in debug mode. Observers are cleared up."):(null===(t=this.globalListenersController)||void 0===t||t.abort(),this.globalListenersController=null),null===(e=this.domObserver)||void 0===e||e.disconnect(),this.domObserver=null,null===(n=this.positionObserver)||void 0===n||n.disconnect(),this.positionObserver=null},e}();exports.ForesightManager=et;
6
+ var e=["input:not([inert])","select:not([inert])","textarea:not([inert])","a[href]:not([inert])","button:not([inert])","[tabindex]:not(slot):not([inert])","audio[controls]:not([inert])","video[controls]:not([inert])",'[contenteditable]:not([contenteditable="false"]):not([inert])',"details>summary:first-of-type:not([inert])","details:not([inert])"].join(","),n="undefined"==typeof Element,i=n?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,o=!n&&Element.prototype.getRootNode?function(t){var e;return null==t||null===(e=t.getRootNode)||void 0===e?void 0:e.call(t)}:function(t){return null==t?void 0:t.ownerDocument},r=function t(e,n){var i;void 0===n&&(n=!0);var o=null==e||null===(i=e.getAttribute)||void 0===i?void 0:i.call(e,"inert");return""===o||"true"===o||n&&e&&t(e.parentNode)},s=function t(n,o,s){for(var l=[],a=Array.from(n);a.length;){var c=a.shift();if(!r(c,!1))if("SLOT"===c.tagName){var u=c.assignedElements(),h=t(u.length?u:c.children,!0,s);s.flatten?l.push.apply(l,h):l.push({scopeParent:c,candidates:h})}else{i.call(c,e)&&s.filter(c)&&(o||!n.includes(c))&&l.push(c);var d=c.shadowRoot||"function"==typeof s.getShadowRoot&&s.getShadowRoot(c),p=!r(d,!1)&&(!s.shadowRootFilter||s.shadowRootFilter(c));if(d&&p){var b=t(!0===d?c.children:d.children,!0,s);s.flatten?l.push.apply(l,b):l.push({scopeParent:c,candidates:b})}else a.unshift.apply(a,c.children)}}return l},l=function(t){return!isNaN(parseInt(t.getAttribute("tabindex"),10))},a=function(t){if(!t)throw new Error("No node provided");return t.tabIndex<0&&(/^(AUDIO|VIDEO|DETAILS)$/.test(t.tagName)||function(t){var e,n=null==t||null===(e=t.getAttribute)||void 0===e?void 0:e.call(t,"contenteditable");return""===n||"true"===n}(t))&&!l(t)?0:t.tabIndex},c=function(t,e){return t.tabIndex===e.tabIndex?t.documentOrder-e.documentOrder:t.tabIndex-e.tabIndex},u=function(t){return"INPUT"===t.tagName},h=function(t){return function(t){return u(t)&&"radio"===t.type}(t)&&!function(t){if(!t.name)return!0;var e,n=t.form||o(t),i=function(t){return n.querySelectorAll('input[type="radio"][name="'+t+'"]')};if("undefined"!=typeof window&&void 0!==window.CSS&&"function"==typeof window.CSS.escape)e=i(window.CSS.escape(t.name));else try{e=i(t.name)}catch(t){return console.error("Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s",t.message),!1}var r=function(t,e){for(var n=0;n<t.length;n++)if(t[n].checked&&t[n].form===e)return t[n]}(e,t.form);return!r||r===t}(t)},d=function(t){var e=t.getBoundingClientRect(),n=e.width,i=e.height;return 0===n&&0===i},p=function(t,e){var n=e.displayCheck,r=e.getShadowRoot;if("hidden"===getComputedStyle(t).visibility)return!0;var s=i.call(t,"details>summary:first-of-type")?t.parentElement:t;if(i.call(s,"details:not([open]) *"))return!0;if(n&&"full"!==n&&"legacy-full"!==n){if("non-zero-area"===n)return d(t)}else{if("function"==typeof r){for(var l=t;t;){var a=t.parentElement,c=o(t);if(a&&!a.shadowRoot&&!0===r(a))return d(t);t=t.assignedSlot?t.assignedSlot:a||c===t.ownerDocument?a:c.host}t=l}if(function(t){var e,n,i,r,s=t&&o(t),l=null===(e=s)||void 0===e?void 0:e.host,a=!1;if(s&&s!==t)for(a=!!(null!==(n=l)&&void 0!==n&&null!==(i=n.ownerDocument)&&void 0!==i&&i.contains(l)||null!=t&&null!==(r=t.ownerDocument)&&void 0!==r&&r.contains(t));!a&&l;){var c,u,h;a=!(null===(u=l=null===(c=s=o(l))||void 0===c?void 0:c.host)||void 0===u||null===(h=u.ownerDocument)||void 0===h||!h.contains(l))}return a}(t))return!t.getClientRects().length;if("legacy-full"!==n)return!0}return!1},b=function(t,e){return!(e.disabled||r(e)||function(t){return u(t)&&"hidden"===t.type}(e)||p(e,t)||function(t){return"DETAILS"===t.tagName&&Array.prototype.slice.apply(t.children).some(function(t){return"SUMMARY"===t.tagName})}(e)||function(t){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(t.tagName))for(var e=t.parentElement;e;){if("FIELDSET"===e.tagName&&e.disabled){for(var n=0;n<e.children.length;n++){var o=e.children.item(n);if("LEGEND"===o.tagName)return!!i.call(e,"fieldset[disabled] *")||!o.contains(t)}return!0}e=e.parentElement}return!1}(e))},g=function(t,e){return!(h(e)||a(e)<0||!b(t,e))},f=function(t){var e=parseInt(t.getAttribute("tabindex"),10);return!!(isNaN(e)||e>=0)},v=function t(e){var n=[],i=[];return e.forEach(function(e,o){var r=!!e.scopeParent,s=r?e.scopeParent:e,c=function(t,e){var n=a(t);return n<0&&e&&!l(t)?0:n}(s,r),u=r?t(e.candidates):s;0===c?r?n.push.apply(n,u):n.push(s):i.push({documentOrder:o,tabIndex:c,item:e,isScope:r,content:u})}),i.sort(c).reduce(function(t,e){return e.isScope?t.push.apply(t,e.content):t.push(e.content),t},[]).concat(n)},m=function(t,n){var o;return o=(n=n||{}).getShadowRoot?s([t],n.includeContainer,{filter:g.bind(null,n),flatten:!1,getShadowRoot:n.getShadowRoot,shadowRootFilter:f}):function(t,n,o){if(r(t))return[];var s=Array.prototype.slice.apply(t.querySelectorAll(e));return n&&i.call(t,e)&&s.unshift(t),s.filter(o)}(t,n.includeContainer,g.bind(null,n)),v(o)};function y(){var t,e=window.matchMedia("(pointer: coarse)").matches&&navigator.maxTouchPoints>0,n=!!(t=navigator.connection)&&(/2g/.test(t.effectiveType)||t.saveData);return{isTouchDevice:e,isLimitedConnection:n,shouldRegister:!e&&!n}}var S=2e3;function w(t,e,n,i){return t<e?console.warn('ForesightJS: "'.concat(i,'" value ').concat(t," is below minimum bound ").concat(e,", clamping to ").concat(e)):t>n&&console.warn('ForesightJS: "'.concat(i,'" value ').concat(t," is above maximum bound ").concat(n,", clamping to ").concat(n)),Math.min(Math.max(t,e),n)}function R(t,e,n){var i=0,o=1,r=e.x-t.x,s=e.y-t.y,l=function(t,e){if(0===t){if(e<0)return!1}else{var n=e/t;if(t<0){if(n>o)return!1;n>i&&(i=n)}else{if(n<i)return!1;n<o&&(o=n)}}return!0};return!!l(-r,t.x-n.left)&&(!!l(r,n.right-t.x)&&(!!l(-s,t.y-n.top)&&(!!l(s,n.bottom-t.y)&&i<=o)))}function P(t){if("number"==typeof t){var e=w(t,0,S,"hitslop");return{top:e,left:e,right:e,bottom:e}}return{top:w(t.top,0,S,"hitslop - top"),left:w(t.left,0,S,"hitslop - left"),right:w(t.right,0,S,"hitslop - right"),bottom:w(t.bottom,0,S,"hitslop - bottom")}}function C(t,e){return{left:t.left-e.left,right:t.right+e.right,top:t.top-e.top,bottom:t.bottom+e.bottom}}function O(t,e){return t&&e?t.left===e.left&&t.right===e.right&&t.top===e.top&&t.bottom===e.bottom:t===e}function E(t,e){return t.x>=e.left&&t.x<=e.right&&t.y>=e.top&&t.y<=e.bottom}function x(t,e){return void 0!==t&&e!==t}var k=class{static intersect(t,e){const n=Math.max(t.left,e.left),i=Math.min(t.right,e.right),o=Math.max(t.top,e.top),r=Math.min(t.bottom,e.bottom),s=Math.max(0,i-n),l=Math.max(0,r-o);return new DOMRect(n,o,s,l)}static clip(t,e){const n={...t.toJSON(),top:t.top+e.top,left:t.left+e.left,bottom:t.bottom-e.bottom,right:t.right-e.right};return n.width=n.right-n.left,n.height=n.bottom-n.top,n}static clipOffsets(t,e){return{top:e.top-t.top,left:e.left-t.left,bottom:t.bottom-e.bottom,right:t.right-e.right}}static equals(t,e){return null==t||null==e?t===e:t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}static sizeEqual(t,e){return Math.round(t.width)===Math.round(e.width)&&Math.round(t.height)===Math.round(e.height)}};function D(t,e){const n=Math.max(t.width,3),i=Math.max(t.height,3),o=t.top-e.top- -1,r=t.left-e.left- -1,s=e.right-t.left-n- -1,l=e.bottom-t.top-i- -1;return`${-Math.round(o)}px ${-Math.round(s)}px ${-Math.round(l)}px ${-Math.round(r)}px`}var B=[...Array.from({length:1e3},(t,e)=>e/1e3),1],M=class{constructor(t,e,n){this.#t=e,this.#e=n,this.#n=n.clientRect,this.#i(t)}#t;#o=void 0;#e;#n;#r=void 0;get visibleRect(){const t=this.#e.clip;return t?k.clip(this.#n,t):this.#n}get isIntersecting(){const{width:t,height:e}=this.visibleRect;return t>0&&e>0}#i(t){const{root:e,rootBounds:n}=this.#e,{visibleRect:i}=this;this.#o?.disconnect(),this.#o=new IntersectionObserver(this.#s,{root:e,rootMargin:D(i,n),threshold:B}),this.#o.observe(t)}#s=t=>{if(!this.#o)return;const e=t[t.length-1];if(e){const{intersectionRatio:t,boundingClientRect:n}=e,i=this.#n;this.#n=n;const o=this.#r,r=!k.equals(n,i);if(t!==this.#r||r){const i=this.#e.rootBounds,s=k.intersect(n,i),l=s.width>0&&s.height>0;if(!l)return;this.#r=t,(null!=o||r)&&(this.#t(new I(e.target,n,e.intersectionRect,l,i),this),this.#i(e.target))}}};disconnect(){this.#o?.disconnect()}},I=class{constructor(t,e,n,i,o){this.target=t,this.boundingClientRect=e,this.intersectionRect=n,this.isIntersecting=i,this.rootBounds=o}},T=class{constructor(t,e){const n=function(t){return!t||function(t){return t.nodeType===Node.DOCUMENT_NODE}(t)?t?.defaultView??window:t}(t);if(function(t){return L(t)&&t.nodeType===Node.ELEMENT_NODE}(n)){const t=n.ownerDocument??document;this.rootBounds=n.getBoundingClientRect(),this.#l=new ResizeObserver(t=>{for(const n of t){const[{inlineSize:t,blockSize:i}]=n.borderBoxSize;if(k.sizeEqual(this.rootBounds,{width:t,height:i}))continue;const o=n.target.getBoundingClientRect();this.rootBounds=o,e(o,this)}}),this.#l.observe(n),t.addEventListener("scroll",t=>{t.target&&t.target!==n&&L(t.target)&&t.target.contains(n)&&(this.rootBounds=n.getBoundingClientRect(),e(this.rootBounds,this))},{capture:!0,passive:!0,signal:this.#a.signal})}else{const t=n.visualViewport??n;this.rootBounds=j(n);const i=()=>{const t=j(n);k.equals(this.rootBounds,t)||(this.rootBounds=t,e(t,this))};t.addEventListener("resize",i,{signal:this.#a.signal})}}#l;#a=new AbortController;rootBounds;disconnect(){this.#l?.disconnect(),this.#a.abort()}};function j(t){const e=t.visualViewport?.width??t.innerWidth,n=t.visualViewport?.height??t.innerHeight;return new DOMRect(0,0,e,n)}function L(t){return"nodeType"in t}var H=class{constructor(t,e){this.#e=e,this.#t=e=>{const n=[];for(const t of e){const e=this.intersections.get(t.target);this.intersections.set(t.target,t),e?.isIntersecting===t.isIntersecting&&k.equals(e?.intersectionRect,t.intersectionRect)||n.push(t)}n.length>0&&t(n,this)}}#t;#c=new Map;#e;intersections=new WeakMap;observe(t){const e=t.ownerDocument;if(!e)return;let n=this.#c.get(e);n||(n=new IntersectionObserver(this.#t,{...this.#e,threshold:B}),this.#c.set(e,n)),n.observe(t)}unobserve(t){const e=t.ownerDocument;if(!e)return;const n=this.#c.get(e);n&&(n.unobserve(t),this.intersections.delete(t))}disconnect(){for(const t of this.#c.values())t.disconnect();this.#c.clear()}},z=class{constructor(t,e){this.#t=t,this.#e=e,this.#u=new T(e?.root,this.#h),this.#d=new H(this.#p,e),this.#l=new ResizeObserver(this.#b)}#t;#e;#g=new Map;#l;#f=new WeakMap;#u;#d;observe(t){this.#d.observe(t)}unobserve(t){t?(this.#g.get(t)?.disconnect(),this.#d.unobserve(t)):this.disconnect()}disconnect(){for(const t of this.#g.values())t.disconnect();this.#l.disconnect(),this.#u.disconnect(),this.#d.disconnect()}#v(t){const e=[];for(const n of t){const{target:t}=n;_(n,this.#f.get(t))||(this.#f.set(t,n),e.push(n))}e.length>0&&this.#t(e)}#h=t=>{const e=[];for(const[n]of this.#g){const i=n.getBoundingClientRect(),o=this.#m(n,i);e.push(new N(n,i,o.visibleRect,o.isIntersecting,t))}this.#v(e)};#m(t,e){const n=this.#d;this.#g.get(t)?.disconnect();const i=new M(t,this.#y,{clientRect:e,root:this.#e?.root,rootBounds:this.#u.rootBounds,get clip(){const e=n.intersections.get(t);if(!e)return;const{intersectionRect:i,boundingClientRect:o}=e;return k.clipOffsets(o,i)}});return this.#g.set(t,i),i}#p=t=>{const e=[];for(const n of t){const{target:t,isIntersecting:i,boundingClientRect:o}=n;i?(this.#m(t,o),this.#l.observe(t)):(this.#g.get(t)?.disconnect(),this.#g.delete(t),this.#l.unobserve(t));const r=this.#g.get(t);e.push(new N(t,o,r?.visibleRect??n.intersectionRect,i,this.#u.rootBounds))}this.#v(e)};#y=(t,e)=>{this.#v([new N(t.target,t.boundingClientRect,e.visibleRect,t.isIntersecting,this.#u.rootBounds)])};#b=t=>{const e=[];for(const n of t){const{target:t,borderBoxSize:i}=n,o=this.#f.get(t);if(o){const[{inlineSize:t,blockSize:e}]=i;if(k.sizeEqual(o.boundingClientRect,{width:t,height:e}))continue}const r=t.getBoundingClientRect(),s=this.#m(t,r);e.push(new N(t,r,s.visibleRect,this.#d.intersections.get(t)?.isIntersecting??!1,this.#u.rootBounds))}this.#v(e)}},N=class{constructor(t,e,n,i,o){this.target=t,this.boundingClientRect=e,this.intersectionRect=n,this.isIntersecting=i,this.rootBounds=o}};function _(t,e){return null!=e&&(t.target===e.target&&t.isIntersecting===e.isIntersecting&&k.equals(t.boundingClientRect,e.boundingClientRect)&&k.equals(t.intersectionRect,e.intersectionRect))}var A=function(){function e(){var t=this;this.elements=new Map,this.isSetup=!1,this._globalCallbackHits={mouse:{hover:0,trajectory:0},tab:{forwards:0,reverse:0},scroll:{down:0,left:0,right:0,up:0},total:0},this._globalSettings={enableMousePrediction:true,enableScrollPrediction:true,positionHistorySize:8,trajectoryPredictionTime:120,scrollMargin:150,defaultHitSlop:{top:0,left:0,right:0,bottom:0},enableTabPrediction:true,tabOffset:2,onAnyCallbackFired:function(t,e){}},this.trajectoryPositions={positions:[],currentPoint:{x:0,y:0},predictedPoint:{x:0,y:0}},this.tabbableElementsCache=[],this.lastFocusedIndex=null,this.predictedScrollPoint=null,this.scrollDirection=null,this.domObserver=null,this.positionObserver=null,this.lastKeyDown=null,this.globalListenersController=null,this.eventListeners=new Map,this.handleMouseMove=function(e){t.updatePointerState(e),t.elements.forEach(function(e){e.isIntersectingWithViewport&&t.handleCallbackInteraction(e)}),t.emit({type:"mouseTrajectoryUpdate",predictionEnabled:t._globalSettings.enableMousePrediction,timestamp:Date.now(),trajectoryPositions:t.trajectoryPositions})},this.handleDomMutations=function(e){e.length&&(t.tabbableElementsCache=[],t.lastFocusedIndex=null);for(var n=0,i=e;n<i.length;n++){var o=i[n];if("childList"===o.type&&o.removedNodes.length>0)for(var r=0,s=Array.from(t.elements.keys());r<s.length;r++){var l=s[r];l.isConnected||t.unregister(l,"disconnected")}}},this.handleKeyDown=function(e){"Tab"===e.key&&(t.lastKeyDown=e)},this.handleFocusIn=function(e){if(t.lastKeyDown&&t._globalSettings.enableTabPrediction){var n=e.target;if(n instanceof HTMLElement){t.tabbableElementsCache.length||(t.tabbableElementsCache=m(document.documentElement));var i=t.lastKeyDown.shiftKey,o=function(t,e,n,i){if(null!==e){var o=t?e-1:e+1;if(o>=0&&o<n.length&&n[o]===i)return o}return n.findIndex(function(t){return t===i})}(i,t.lastFocusedIndex,t.tabbableElementsCache,n);t.lastFocusedIndex=o,t.lastKeyDown=null;for(var r=[],s=0;s<=t._globalSettings.tabOffset;s++)if(i){var l=t.tabbableElementsCache[o-s];t.elements.has(l)&&r.push(l)}else{l=t.tabbableElementsCache[o+s];t.elements.has(l)&&r.push(l)}r.forEach(function(e){t.callCallback(t.elements.get(e),{kind:"tab",subType:i?"reverse":"forwards"})})}}},this.handlePositionChange=function(e){for(var n=0,i=e;n<i.length;n++){var o=i[n],r=t.elements.get(o.target);if(r){var s=r.isIntersectingWithViewport,l=o.isIntersecting;r.isIntersectingWithViewport=l,s!==l&&t.emit({type:"elementDataUpdated",elementData:r,timestamp:Date.now(),updatedProp:"visibility"}),l&&(t.updateElementBounds(o.boundingClientRect,r),t.handleScrollPrefetch(r,o.boundingClientRect))}}t.scrollDirection=null,t.predictedScrollPoint=null}}return e.initialize=function(t){return this.isInitiated||(e.manager=new e),void 0!==t&&e.manager.alterGlobalSettings(t),e.manager},e.prototype.addEventListener=function(t,e,n){var i,o,r=this;if(null===(i=null==n?void 0:n.signal)||void 0===i?void 0:i.aborted)return function(){};this.eventListeners.has(t)||this.eventListeners.set(t,[]),this.eventListeners.get(t).push(e),null===(o=null==n?void 0:n.signal)||void 0===o||o.addEventListener("abort",function(){return r.removeEventListener(t,e)})},e.prototype.removeEventListener=function(t,e){var n=this.eventListeners.get(t);if(n){var i=n.indexOf(e);i>-1&&n.splice(i,1)}},e.prototype.logSubscribers=function(){var t=this;console.log("%c[ForesightManager] Current Subscribers:","font-weight: bold; color: #3b82f6;");var e=Array.from(this.eventListeners.keys());0!==e.length?e.forEach(function(e){var n=t.eventListeners.get(e);n&&n.length>0&&(console.groupCollapsed("Event: %c".concat(e),"font-weight: bold;","(".concat(n.length," listener").concat(n.length>1?"s":"",")")),n.forEach(function(t,e){console.log("[".concat(e,"]:"),t)}),console.groupEnd())}):console.log(" No active subscribers.")},e.prototype.emit=function(t){var e=this.eventListeners.get(t.type);e&&e.forEach(function(e){try{e(t)}catch(e){console.error("Error in ForesightManager event listener for ".concat(t.type,":"),e)}})},Object.defineProperty(e.prototype,"getManagerData",{get:function(){return{registeredElements:this.elements,globalSettings:this._globalSettings,globalCallbackHits:this._globalCallbackHits}},enumerable:!1,configurable:!0}),Object.defineProperty(e,"isInitiated",{get:function(){return!!e.manager},enumerable:!1,configurable:!0}),Object.defineProperty(e,"instance",{get:function(){return this.initialize()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"registeredElements",{get:function(){return this.elements},enumerable:!1,configurable:!0}),e.prototype.register=function(t){var e,n,i=this,o=t.element,r=t.callback,s=t.hitSlop,l=t.name,a=y(),c=a.shouldRegister,u=a.isTouchDevice,h=a.isLimitedConnection;if(!c)return{isLimitedConnection:h,isTouchDevice:u,isRegistered:!1,unregister:function(){}};this.isSetup||this.initializeGlobalListeners();var d=s?P(s):this._globalSettings.defaultHitSlop,p={element:o,callback:r,callbackHits:{mouse:{hover:0,trajectory:0},tab:{forwards:0,reverse:0},scroll:{down:0,left:0,right:0,up:0},total:0},elementBounds:{originalRect:void 0,expandedRect:{top:0,left:0,right:0,bottom:0},hitSlop:d},isHovering:!1,trajectoryHitData:{isTrajectoryHit:!1,trajectoryHitTime:0,trajectoryHitExpirationTimeoutId:void 0},name:null!==(e=null!=l?l:o.id)&&void 0!==e?e:"",isIntersectingWithViewport:!0};return this.elements.set(o,p),null===(n=this.positionObserver)||void 0===n||n.observe(o),this.emit({type:"elementRegistered",timestamp:Date.now(),elementData:p,sort:!0}),{isTouchDevice:u,isLimitedConnection:h,isRegistered:!0,unregister:function(){return i.unregister(o,"apiCall")}}},e.prototype.unregister=function(t,e){var n;if(this.elements.has(t)){var i=this.elements.get(t);i&&this.emit({type:"elementUnregistered",elementData:i,timestamp:Date.now(),unregisterReason:e}),(null==i?void 0:i.trajectoryHitData.trajectoryHitExpirationTimeoutId)&&clearTimeout(i.trajectoryHitData.trajectoryHitExpirationTimeoutId),null===(n=this.positionObserver)||void 0===n||n.unobserve(t),this.elements.delete(t),0===this.elements.size&&this.isSetup&&this.removeGlobalListeners()}},e.prototype.updateNumericSettings=function(t,e,n,i){return!!x(t,this._globalSettings[e])&&(this._globalSettings[e]=w(t,n,i,e),!0)},e.prototype.updateBooleanSetting=function(t,e){return!!x(t,this._globalSettings[e])&&(this._globalSettings[e]=t,!0)},e.prototype.alterGlobalSettings=function(t){var e=this._globalSettings.positionHistorySize,n=this.updateNumericSettings(null==t?void 0:t.positionHistorySize,"positionHistorySize",2,30);n&&this._globalSettings.positionHistorySize<e&&this.trajectoryPositions.positions.length>this._globalSettings.positionHistorySize&&(this.trajectoryPositions.positions=this.trajectoryPositions.positions.slice(this.trajectoryPositions.positions.length-this._globalSettings.positionHistorySize));var i=this.updateNumericSettings(null==t?void 0:t.trajectoryPredictionTime,"trajectoryPredictionTime",10,200),o=this.updateNumericSettings(null==t?void 0:t.scrollMargin,"scrollMargin",30,300),r=this.updateNumericSettings(null==t?void 0:t.tabOffset,"tabOffset",0,20),s=this.updateBooleanSetting(null==t?void 0:t.enableMousePrediction,"enableMousePrediction"),l=this.updateBooleanSetting(null==t?void 0:t.enableScrollPrediction,"enableScrollPrediction"),a=this.updateBooleanSetting(null==t?void 0:t.enableTabPrediction,"enableTabPrediction");void 0!==(null==t?void 0:t.onAnyCallbackFired)&&(this._globalSettings.onAnyCallbackFired=t.onAnyCallbackFired);var c=!1;if(void 0!==(null==t?void 0:t.defaultHitSlop)){var u=P(t.defaultHitSlop);O(this._globalSettings.defaultHitSlop,u)||(this._globalSettings.defaultHitSlop=u,c=!0,this.forceUpdateAllElementBounds())}(n||i||r||s||a||l||c||o)&&this.emit({type:"managerSettingsChanged",timestamp:Date.now(),newSettings:this._globalSettings})},e.prototype.forceUpdateAllElementBounds=function(){var t=this;this.elements.forEach(function(e,n){var i=t.elements.get(n);i&&i.isIntersectingWithViewport&&t.forceUpdateElementBounds(i)})},e.prototype.updatePointerState=function(e){this.trajectoryPositions.currentPoint={x:e.clientX,y:e.clientY},this.trajectoryPositions.predictedPoint=this._globalSettings.enableMousePrediction?function(t,e,n,i){var o={point:t,time:performance.now()},r=t.x,s=t.y;if(e.push(o),e.length>n&&e.shift(),e.length<2)return{x:r,y:s};var l=e[0],a=e[e.length-1],c=(a.time-l.time)/1e3;if(0===c)return{x:r,y:s};var u=i/1e3;return{x:r+(a.point.x-l.point.x)/c*u,y:s+(a.point.y-l.point.y)/c*u}}(this.trajectoryPositions.currentPoint,this.trajectoryPositions.positions,this._globalSettings.positionHistorySize,this._globalSettings.trajectoryPredictionTime):t({},this.trajectoryPositions.currentPoint)},e.prototype.handleCallbackInteraction=function(t){var e=t.elementBounds.expandedRect;if(this._globalSettings.enableMousePrediction)R(this.trajectoryPositions.currentPoint,this.trajectoryPositions.predictedPoint,e)&&this.callCallback(t,{kind:"mouse",subType:"trajectory"});else if(E(this.trajectoryPositions.currentPoint,e))return void this.callCallback(t,{kind:"mouse",subType:"hover"})},e.prototype.updateHitCounters=function(t,e){switch(e.kind){case"mouse":t.callbackHits.mouse[e.subType]++,this._globalCallbackHits.mouse[e.subType]++;break;case"tab":t.callbackHits.tab[e.subType]++,this._globalCallbackHits.tab[e.subType]++;break;case"scroll":t.callbackHits.scroll[e.subType]++,this._globalCallbackHits.scroll[e.subType]++}t.callbackHits.total++,this._globalCallbackHits.total++},e.prototype.callCallback=function(t,e){t&&(this.updateHitCounters(t,e),t.callback(),this._globalSettings.onAnyCallbackFired(t,this.getManagerData),this.emit({type:"callbackFired",timestamp:Date.now(),elementData:t,hitType:e}),this.unregister(t.element,"callbackHit"))},e.prototype.forceUpdateElementBounds=function(e){var n=e.element.getBoundingClientRect(),i=C(n,e.elementBounds.hitSlop);if(!O(i,e.elementBounds.expandedRect)){var o=t(t({},e),{elementBounds:t(t({},e.elementBounds),{originalRect:n,expandedRect:i})});this.elements.set(e.element,o),this.emit({type:"elementDataUpdated",timestamp:Date.now(),elementData:o,updatedProp:"bounds"})}},e.prototype.updateElementBounds=function(e,n){var i=t(t({},n),{elementBounds:t(t({},n.elementBounds),{originalRect:e,expandedRect:C(e,n.elementBounds.hitSlop)})});this.elements.set(n.element,i),this.emit({type:"elementDataUpdated",timestamp:Date.now(),elementData:i,updatedProp:"bounds"})},e.prototype.handleScrollPrefetch=function(t,e){var n,i;if(this._globalSettings.enableScrollPrediction){if(!t.elementBounds.originalRect)return;if(this.scrollDirection=null!==(n=this.scrollDirection)&&void 0!==n?n:function(t,e){var n=e.top-t.top,i=e.left-t.left;return n<-1?"down":n>1?"up":i<-1?"right":i>1?"left":"none"}(t.elementBounds.originalRect,e),"none"===this.scrollDirection)return;this.predictedScrollPoint=null!==(i=this.predictedScrollPoint)&&void 0!==i?i:function(t,e,n){var i={x:t.x,y:t.y};switch(e){case"down":i.y+=n;break;case"up":i.y-=n;break;case"left":i.x-=n;break;case"right":i.x+=n}return i}(this.trajectoryPositions.currentPoint,this.scrollDirection,this._globalSettings.scrollMargin),R(this.trajectoryPositions.currentPoint,this.predictedScrollPoint,null==t?void 0:t.elementBounds.expandedRect)&&this.callCallback(t,{kind:"scroll",subType:this.scrollDirection}),this.emit({type:"scrollTrajectoryUpdate",timestamp:Date.now(),currentPoint:this.trajectoryPositions.currentPoint,predictedPoint:this.predictedScrollPoint})}else E(this.trajectoryPositions.currentPoint,t.elementBounds.expandedRect)&&this.callCallback(t,{kind:"mouse",subType:"hover"})},e.prototype.initializeGlobalListeners=function(){if(!this.isSetup&&"undefined"!=typeof window&&"undefined"!=typeof document){this.globalListenersController=new AbortController;var t=this.globalListenersController.signal;document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("keydown",this.handleKeyDown,{signal:t}),document.addEventListener("focusin",this.handleFocusIn,{signal:t}),this.domObserver=new MutationObserver(this.handleDomMutations),this.domObserver.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!1}),this.positionObserver=new z(this.handlePositionChange),this.isSetup=!0}},e.prototype.removeGlobalListeners=function(){var t,e,n;this.isSetup=!1,null===(t=this.globalListenersController)||void 0===t||t.abort(),this.globalListenersController=null,null===(e=this.domObserver)||void 0===e||e.disconnect(),this.domObserver=null,null===(n=this.positionObserver)||void 0===n||n.disconnect(),this.positionObserver=null},e}();exports.ForesightManager=A;
7
7
  //# sourceMappingURL=index.js.map