js.foresight 2.2.3 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -123
- package/dist/Manager/ForesightManager.d.ts +89 -0
- package/dist/Manager/ForesightManager.d.ts.map +1 -0
- package/dist/Manager/ForesightManager.js +639 -0
- package/dist/Manager/ForesightManager.js.map +1 -0
- package/dist/Manager/constants.d.ts +23 -0
- package/dist/Manager/constants.d.ts.map +1 -0
- package/dist/Manager/constants.js +24 -0
- package/dist/Manager/constants.js.map +1 -0
- package/dist/Manager/helpers/clampNumber.d.ts +2 -0
- package/dist/Manager/helpers/clampNumber.d.ts.map +1 -0
- package/dist/Manager/helpers/clampNumber.js +10 -0
- package/dist/Manager/helpers/clampNumber.js.map +1 -0
- package/dist/Manager/helpers/getFocusedElementIndex.d.ts +15 -0
- package/dist/Manager/helpers/getFocusedElementIndex.d.ts.map +1 -0
- package/dist/Manager/helpers/getFocusedElementIndex.js +27 -0
- package/dist/Manager/helpers/getFocusedElementIndex.js.map +1 -0
- package/dist/Manager/helpers/getScrollDirection.d.ts +3 -0
- package/dist/Manager/helpers/getScrollDirection.d.ts.map +1 -0
- package/dist/Manager/helpers/getScrollDirection.js +21 -0
- package/dist/Manager/helpers/getScrollDirection.js.map +1 -0
- package/dist/Manager/helpers/lineSigmentIntersectsRect.d.ts +12 -0
- package/dist/Manager/helpers/lineSigmentIntersectsRect.d.ts.map +1 -0
- package/dist/Manager/helpers/lineSigmentIntersectsRect.js +52 -0
- package/dist/Manager/helpers/lineSigmentIntersectsRect.js.map +1 -0
- package/dist/Manager/helpers/predictNextMousePosition.d.ts +19 -0
- package/dist/Manager/helpers/predictNextMousePosition.d.ts.map +1 -0
- package/dist/Manager/helpers/predictNextMousePosition.js +43 -0
- package/dist/Manager/helpers/predictNextMousePosition.js.map +1 -0
- package/dist/Manager/helpers/predictNextScrollPosition.d.ts +6 -0
- package/dist/Manager/helpers/predictNextScrollPosition.d.ts.map +1 -0
- package/dist/Manager/helpers/predictNextScrollPosition.js +20 -0
- package/dist/Manager/helpers/predictNextScrollPosition.js.map +1 -0
- package/dist/Manager/helpers/rectAndHitSlop.d.ts +33 -0
- package/dist/Manager/helpers/rectAndHitSlop.d.ts.map +1 -0
- package/dist/Manager/helpers/rectAndHitSlop.js +66 -0
- package/dist/Manager/helpers/rectAndHitSlop.js.map +1 -0
- package/dist/Manager/helpers/shouldUpdateSetting.d.ts +11 -0
- package/dist/Manager/helpers/shouldUpdateSetting.d.ts.map +1 -0
- package/dist/Manager/helpers/shouldUpdateSetting.js +16 -0
- package/dist/Manager/helpers/shouldUpdateSetting.js.map +1 -0
- package/dist/helpers/shouldRegister.d.ts +8 -0
- package/dist/helpers/shouldRegister.d.ts.map +1 -0
- package/dist/helpers/shouldRegister.js +31 -0
- package/dist/helpers/shouldRegister.js.map +1 -0
- package/dist/index.d.ts +105 -72
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/dist/src/Manager/ForesightManager.d.ts +89 -0
- package/dist/src/Manager/ForesightManager.d.ts.map +1 -0
- package/dist/src/Manager/ForesightManager.test.d.ts +2 -0
- package/dist/src/Manager/ForesightManager.test.d.ts.map +1 -0
- package/dist/src/Manager/constants.d.ts +23 -0
- package/dist/src/Manager/constants.d.ts.map +1 -0
- package/dist/src/Manager/helpers/clampNumber.d.ts +2 -0
- package/dist/src/Manager/helpers/clampNumber.d.ts.map +1 -0
- package/dist/src/Manager/helpers/clampNumber.test.d.ts +2 -0
- package/dist/src/Manager/helpers/clampNumber.test.d.ts.map +1 -0
- package/dist/src/Manager/helpers/getFocusedElementIndex.d.ts +15 -0
- package/dist/src/Manager/helpers/getFocusedElementIndex.d.ts.map +1 -0
- package/dist/src/Manager/helpers/getFocusedElementIndex.test.d.ts +2 -0
- package/dist/src/Manager/helpers/getFocusedElementIndex.test.d.ts.map +1 -0
- package/dist/src/Manager/helpers/getScrollDirection.d.ts +3 -0
- package/dist/src/Manager/helpers/getScrollDirection.d.ts.map +1 -0
- package/dist/src/Manager/helpers/lineSegmentIntersectsRect.test.d.ts +2 -0
- package/dist/src/Manager/helpers/lineSegmentIntersectsRect.test.d.ts.map +1 -0
- package/dist/src/Manager/helpers/lineSigmentIntersectsRect.d.ts +12 -0
- package/dist/src/Manager/helpers/lineSigmentIntersectsRect.d.ts.map +1 -0
- package/dist/src/Manager/helpers/predictNextMousePosition.d.ts +19 -0
- package/dist/src/Manager/helpers/predictNextMousePosition.d.ts.map +1 -0
- package/dist/src/Manager/helpers/predictNextMousePosition.test.d.ts +2 -0
- package/dist/src/Manager/helpers/predictNextMousePosition.test.d.ts.map +1 -0
- package/dist/src/Manager/helpers/predictNextScrollPosition.d.ts +6 -0
- package/dist/src/Manager/helpers/predictNextScrollPosition.d.ts.map +1 -0
- package/dist/src/Manager/helpers/rectAndHitSlop.d.ts +33 -0
- package/dist/src/Manager/helpers/rectAndHitSlop.d.ts.map +1 -0
- package/dist/src/Manager/helpers/rectAndHitSlop.test.d.ts +2 -0
- package/dist/src/Manager/helpers/rectAndHitSlop.test.d.ts.map +1 -0
- package/dist/src/Manager/helpers/shouldUpdateSetting.d.ts +11 -0
- package/dist/src/Manager/helpers/shouldUpdateSetting.d.ts.map +1 -0
- package/dist/src/helpers/shouldRegister.d.ts +8 -0
- package/dist/src/helpers/shouldRegister.d.ts.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/types/types.d.ts +309 -0
- package/dist/src/types/types.d.ts.map +1 -0
- package/dist/test-setup.d.ts +17 -0
- package/dist/test-setup.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/types.d.ts +312 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +2 -0
- package/dist/types/types.js.map +1 -0
- package/package.json +11 -10
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" | "
|
|
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. */
|
|
@@ -98,10 +82,6 @@ type ForesightElementData = Required<Pick<ForesightRegisterOptions, "callback" |
|
|
|
98
82
|
* Is the element intersecting with the viewport, usefull to track which element we should observe or not
|
|
99
83
|
*/
|
|
100
84
|
isIntersectingWithViewport: boolean;
|
|
101
|
-
/**
|
|
102
|
-
* Amount of times this callback has been hit, will be 0/1 if unregisterOnCallback is true
|
|
103
|
-
*/
|
|
104
|
-
callbackHits: CallbackHits;
|
|
105
85
|
/**
|
|
106
86
|
* The element you registered
|
|
107
87
|
*/
|
|
@@ -123,6 +103,16 @@ type CallbackHits = {
|
|
|
123
103
|
tab: TabCallbackCounts;
|
|
124
104
|
scroll: ScrollCallbackCounts;
|
|
125
105
|
};
|
|
106
|
+
type HitType = {
|
|
107
|
+
kind: "mouse";
|
|
108
|
+
subType: keyof MouseCallbackCounts;
|
|
109
|
+
} | {
|
|
110
|
+
kind: "tab";
|
|
111
|
+
subType: keyof TabCallbackCounts;
|
|
112
|
+
} | {
|
|
113
|
+
kind: "scroll";
|
|
114
|
+
subType: keyof ScrollCallbackCounts;
|
|
115
|
+
};
|
|
126
116
|
/**
|
|
127
117
|
* Snapshot of the current ForesightManager state
|
|
128
118
|
*/
|
|
@@ -144,6 +134,13 @@ type BaseForesightManagerSettings = {
|
|
|
144
134
|
* @default 8
|
|
145
135
|
*/
|
|
146
136
|
positionHistorySize: number;
|
|
137
|
+
/**
|
|
138
|
+
*
|
|
139
|
+
* @deprecated will be removed from v4.0
|
|
140
|
+
* ForesightJS now have its stand-alone devtools library with the debugger built-in
|
|
141
|
+
* @link https://github.com/spaansba/ForesightJS-DevTools
|
|
142
|
+
*/
|
|
143
|
+
debug: boolean;
|
|
147
144
|
/**
|
|
148
145
|
* How far ahead (in milliseconds) to predict the mouse trajectory.
|
|
149
146
|
* A larger value means the prediction extends further into the future. (meaning it will trigger callbacks sooner)
|
|
@@ -190,18 +187,6 @@ type BaseForesightManagerSettings = {
|
|
|
190
187
|
* @default 2
|
|
191
188
|
*/
|
|
192
189
|
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
190
|
/**
|
|
206
191
|
* A global callback that runs whenever a callback is fired for any
|
|
207
192
|
* registered element, just after the element's specific callback is fired.
|
|
@@ -232,6 +217,9 @@ type ForesightRegisterOptions = {
|
|
|
232
217
|
element: ForesightElement;
|
|
233
218
|
callback: ForesightCallback;
|
|
234
219
|
hitSlop?: HitSlop;
|
|
220
|
+
/**
|
|
221
|
+
* @deprecated will be removed in V4.0
|
|
222
|
+
*/
|
|
235
223
|
unregisterOnCallback?: boolean;
|
|
236
224
|
name?: string;
|
|
237
225
|
};
|
|
@@ -248,6 +236,61 @@ type ForesightRegisterOptionsWithoutElement = Omit<ForesightRegisterOptions, "el
|
|
|
248
236
|
* Basically increases the hover hitbox
|
|
249
237
|
*/
|
|
250
238
|
type HitSlop = Rect | number;
|
|
239
|
+
interface ForesightEventMap {
|
|
240
|
+
elementRegistered: ElementRegisteredEvent;
|
|
241
|
+
elementUnregistered: ElementUnregisteredEvent;
|
|
242
|
+
elementDataUpdated: ElementDataUpdatedEvent;
|
|
243
|
+
callbackFired: CallbackFiredEvent;
|
|
244
|
+
mouseTrajectoryUpdate: MouseTrajectoryUpdateEvent;
|
|
245
|
+
scrollTrajectoryUpdate: ScrollTrajectoryUpdateEvent;
|
|
246
|
+
managerSettingsChanged: ManagerSettingsChangedEvent;
|
|
247
|
+
}
|
|
248
|
+
type ForesightEventType = keyof ForesightEventMap;
|
|
249
|
+
interface ForesightEvent {
|
|
250
|
+
type: ForesightEventType;
|
|
251
|
+
timestamp: number;
|
|
252
|
+
}
|
|
253
|
+
interface ElementRegisteredEvent extends ForesightEvent {
|
|
254
|
+
type: "elementRegistered";
|
|
255
|
+
elementData: ForesightElementData;
|
|
256
|
+
}
|
|
257
|
+
interface ElementUnregisteredEvent extends ForesightEvent {
|
|
258
|
+
type: "elementUnregistered";
|
|
259
|
+
elementData: ForesightElementData;
|
|
260
|
+
unregisterReason: ElementUnregisteredReason;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* The reason an element was unregistered from ForesightManager's tracking.
|
|
264
|
+
* - `callbackHit`: The element was automatically unregistered after its callback fired.
|
|
265
|
+
* - `disconnected`: The element was automatically unregistered because it was removed from the DOM.
|
|
266
|
+
* - `apiCall`: The developer manually called the `unregister()` function for the element.
|
|
267
|
+
*/
|
|
268
|
+
type ElementUnregisteredReason = "callbackHit" | "disconnected" | "apiCall";
|
|
269
|
+
interface ElementDataUpdatedEvent extends ForesightEvent {
|
|
270
|
+
type: "elementDataUpdated";
|
|
271
|
+
elementData: ForesightElementData;
|
|
272
|
+
updatedProp: "bounds" | "visibility";
|
|
273
|
+
}
|
|
274
|
+
interface CallbackFiredEvent extends ForesightEvent {
|
|
275
|
+
type: "callbackFired";
|
|
276
|
+
elementData: ForesightElementData;
|
|
277
|
+
hitType: HitType;
|
|
278
|
+
managerData: ForesightManagerData;
|
|
279
|
+
}
|
|
280
|
+
interface MouseTrajectoryUpdateEvent extends ForesightEvent {
|
|
281
|
+
type: "mouseTrajectoryUpdate";
|
|
282
|
+
trajectoryPositions: TrajectoryPositions;
|
|
283
|
+
predictionEnabled: boolean;
|
|
284
|
+
}
|
|
285
|
+
interface ScrollTrajectoryUpdateEvent extends ForesightEvent {
|
|
286
|
+
type: "scrollTrajectoryUpdate";
|
|
287
|
+
currentPoint: Point;
|
|
288
|
+
predictedPoint: Point;
|
|
289
|
+
}
|
|
290
|
+
interface ManagerSettingsChangedEvent extends ForesightEvent {
|
|
291
|
+
type: "managerSettingsChanged";
|
|
292
|
+
managerData: ForesightManagerData;
|
|
293
|
+
}
|
|
251
294
|
|
|
252
295
|
/**
|
|
253
296
|
* Manages the prediction of user intent based on mouse trajectory and element interactions.
|
|
@@ -259,7 +302,6 @@ type HitSlop = Rect | number;
|
|
|
259
302
|
* - Invoking callbacks associated with elements upon predicted or actual interaction.
|
|
260
303
|
* - Optionally unregistering elements after their callback is triggered.
|
|
261
304
|
* - Handling global settings for prediction behavior (e.g., history size, prediction time).
|
|
262
|
-
* - Optionally enabling a {@link ForesightDebugger} for visual feedback.
|
|
263
305
|
* - Automatically updating element bounds on resize using {@link ResizeObserver}.
|
|
264
306
|
* - Automatically unregistering elements removed from the DOM using {@link MutationObserver}.
|
|
265
307
|
* - Detecting broader layout shifts via {@link MutationObserver} to update element positions.
|
|
@@ -271,7 +313,6 @@ declare class ForesightManager {
|
|
|
271
313
|
private static manager;
|
|
272
314
|
private elements;
|
|
273
315
|
private isSetup;
|
|
274
|
-
private debugger;
|
|
275
316
|
private _globalCallbackHits;
|
|
276
317
|
private _globalSettings;
|
|
277
318
|
private trajectoryPositions;
|
|
@@ -283,18 +324,24 @@ declare class ForesightManager {
|
|
|
283
324
|
private positionObserver;
|
|
284
325
|
private lastKeyDown;
|
|
285
326
|
private globalListenersController;
|
|
327
|
+
private eventListeners;
|
|
286
328
|
private constructor();
|
|
287
329
|
static initialize(props?: Partial<UpdateForsightManagerSettings>): ForesightManager;
|
|
330
|
+
addEventListener<K extends ForesightEventType>(eventType: K, listener: (event: ForesightEventMap[K]) => void, options?: {
|
|
331
|
+
signal?: AbortSignal;
|
|
332
|
+
}): (() => void) | undefined;
|
|
333
|
+
removeEventListener<K extends ForesightEventType>(eventType: K, listener: (event: ForesightEventMap[K]) => void): void;
|
|
334
|
+
logSubscribers(): void;
|
|
335
|
+
private emit;
|
|
288
336
|
get getManagerData(): Readonly<ForesightManagerData>;
|
|
289
337
|
static get isInitiated(): Readonly<boolean>;
|
|
290
338
|
static get instance(): ForesightManager;
|
|
291
339
|
get registeredElements(): ReadonlyMap<ForesightElement, ForesightElementData>;
|
|
292
|
-
register({ element, callback, hitSlop,
|
|
340
|
+
register({ element, callback, hitSlop, name, }: ForesightRegisterOptions): ForesightRegisterResult;
|
|
293
341
|
private unregister;
|
|
294
342
|
private updateNumericSettings;
|
|
295
343
|
private updateBooleanSetting;
|
|
296
344
|
alterGlobalSettings(props?: Partial<UpdateForsightManagerSettings>): void;
|
|
297
|
-
private turnOnDebugMode;
|
|
298
345
|
private forceUpdateAllElementBounds;
|
|
299
346
|
private updatePointerState;
|
|
300
347
|
/**
|
|
@@ -308,21 +355,7 @@ declare class ForesightManager {
|
|
|
308
355
|
* @param elementData - The data object for the foresight element.
|
|
309
356
|
* @param element - The HTML element being interacted with.
|
|
310
357
|
*/
|
|
311
|
-
private
|
|
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;
|
|
358
|
+
private handleCallbackInteraction;
|
|
326
359
|
private handleMouseMove;
|
|
327
360
|
/**
|
|
328
361
|
* Detects when registered elements are removed from the DOM and automatically unregisters them to prevent stale references.
|
|
@@ -348,4 +381,4 @@ declare class ForesightManager {
|
|
|
348
381
|
}
|
|
349
382
|
|
|
350
383
|
export { ForesightManager };
|
|
351
|
-
export type { CallbackHits as ForesightCallbackHits, ForesightElement, ForesightElementData, ForesightManagerSettings, Rect as ForesightRect, ForesightRegisterOptions, ForesightRegisterOptionsWithoutElement, ForesightRegisterResult, UpdateForsightManagerSettings };
|
|
384
|
+
export type { CallbackFiredEvent, ElementDataUpdatedEvent, ElementRegisteredEvent, ElementUnregisteredEvent, CallbackHits as ForesightCallbackHits, ForesightElement, ForesightElementData, ForesightEvent, ForesightManagerSettings, Rect as ForesightRect, ForesightRegisterOptions, ForesightRegisterOptionsWithoutElement, ForesightRegisterResult, HitSlop, ManagerSettingsChangedEvent, MouseTrajectoryUpdateEvent, ScrollTrajectoryUpdateEvent, UpdateForsightManagerSettings };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAC7D,YAAY,EACV,IAAI,IAAI,aAAa,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,6BAA6B,EAC7B,wBAAwB,EACxB,wBAAwB,EACxB,sCAAsC,EACtC,oBAAoB,EACpB,YAAY,IAAI,qBAAqB,EACrC,cAAc,EACd,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,kBAAkB,EAClB,0BAA0B,EAC1B,2BAA2B,EAC3B,2BAA2B,EAC3B,OAAO,GACR,MAAM,eAAe,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
2
|
/*!
|
|
3
3
|
* tabbable 6.2.0
|
|
4
4
|
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
|
|
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;
|
|
5
|
+
*/var t=["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(","),e="undefined"==typeof Element,i=e?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,n=!e&&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},o=function t(e,i){var n;void 0===i&&(i=!0);var o=null==e||null===(n=e.getAttribute)||void 0===n?void 0:n.call(e,"inert");return""===o||"true"===o||i&&e&&t(e.parentNode)},s=function e(n,s,r){for(var l=[],a=Array.from(n);a.length;){var c=a.shift();if(!o(c,!1))if("SLOT"===c.tagName){var h=c.assignedElements(),u=e(h.length?h:c.children,!0,r);r.flatten?l.push.apply(l,u):l.push({scopeParent:c,candidates:u})}else{i.call(c,t)&&r.filter(c)&&(s||!n.includes(c))&&l.push(c);var d=c.shadowRoot||"function"==typeof r.getShadowRoot&&r.getShadowRoot(c),g=!o(d,!1)&&(!r.shadowRootFilter||r.shadowRootFilter(c));if(d&&g){var b=e(!0===d?c.children:d.children,!0,r);r.flatten?l.push.apply(l,b):l.push({scopeParent:c,candidates:b})}else a.unshift.apply(a,c.children)}}return l},r=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,i=null==t||null===(e=t.getAttribute)||void 0===e?void 0:e.call(t,"contenteditable");return""===i||"true"===i}(t))&&!r(t)?0:t.tabIndex},a=function(t,e){return t.tabIndex===e.tabIndex?t.documentOrder-e.documentOrder:t.tabIndex-e.tabIndex},c=function(t){return"INPUT"===t.tagName},h=function(t){return function(t){return c(t)&&"radio"===t.type}(t)&&!function(t){if(!t.name)return!0;var e,i=t.form||n(t),o=function(t){return i.querySelectorAll('input[type="radio"][name="'+t+'"]')};if("undefined"!=typeof window&&void 0!==window.CSS&&"function"==typeof window.CSS.escape)e=o(window.CSS.escape(t.name));else try{e=o(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 s=function(t,e){for(var i=0;i<t.length;i++)if(t[i].checked&&t[i].form===e)return t[i]}(e,t.form);return!s||s===t}(t)},u=function(t){var e=t.getBoundingClientRect(),i=e.width,n=e.height;return 0===i&&0===n},d=function(t,e){var o=e.displayCheck,s=e.getShadowRoot;if("hidden"===getComputedStyle(t).visibility)return!0;var r=i.call(t,"details>summary:first-of-type")?t.parentElement:t;if(i.call(r,"details:not([open]) *"))return!0;if(o&&"full"!==o&&"legacy-full"!==o){if("non-zero-area"===o)return u(t)}else{if("function"==typeof s){for(var l=t;t;){var a=t.parentElement,c=n(t);if(a&&!a.shadowRoot&&!0===s(a))return u(t);t=t.assignedSlot?t.assignedSlot:a||c===t.ownerDocument?a:c.host}t=l}if(function(t){var e,i,o,s,r=t&&n(t),l=null===(e=r)||void 0===e?void 0:e.host,a=!1;if(r&&r!==t)for(a=!!(null!==(i=l)&&void 0!==i&&null!==(o=i.ownerDocument)&&void 0!==o&&o.contains(l)||null!=t&&null!==(s=t.ownerDocument)&&void 0!==s&&s.contains(t));!a&&l;){var c,h,u;a=!(null===(h=l=null===(c=r=n(l))||void 0===c?void 0:c.host)||void 0===h||null===(u=h.ownerDocument)||void 0===u||!u.contains(l))}return a}(t))return!t.getClientRects().length;if("legacy-full"!==o)return!0}return!1},g=function(t,e){return!(e.disabled||o(e)||function(t){return c(t)&&"hidden"===t.type}(e)||d(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!(h(e)||l(e)<0||!g(t,e))},p=function(t){var e=parseInt(t.getAttribute("tabindex"),10);return!!(isNaN(e)||e>=0)},f=function t(e){var i=[],n=[];return e.forEach(function(e,o){var s=!!e.scopeParent,a=s?e.scopeParent:e,c=function(t,e){var i=l(t);return i<0&&e&&!r(t)?0:i}(a,s),h=s?t(e.candidates):a;0===c?s?i.push.apply(i,h):i.push(a):n.push({documentOrder:o,tabIndex:c,item:e,isScope:s,content:h})}),n.sort(a).reduce(function(t,e){return e.isScope?t.push.apply(t,e.content):t.push(e.content),t},[]).concat(i)},m=function(e,n){var r;return r=(n=n||{}).getShadowRoot?s([e],n.includeContainer,{filter:b.bind(null,n),flatten:!1,getShadowRoot:n.getShadowRoot,shadowRootFilter:p}):function(e,n,s){if(o(e))return[];var r=Array.prototype.slice.apply(e.querySelectorAll(t));return n&&i.call(e,t)&&r.unshift(e),r.filter(s)}(e,n.includeContainer,b.bind(null,n)),f(r)};function v(){const t=window.matchMedia("(pointer: coarse)").matches&&navigator.maxTouchPoints>0,e=function(){const t=navigator.connection;return!!t&&(/2g/.test(t.effectiveType)||t.saveData)}();return{isTouchDevice:t,isLimitedConnection:e,shouldRegister:!t&&!e}}const y=2e3;function S(t,e,i,n){return t<e?console.warn(`ForesightJS: "${n}" value ${t} is below minimum bound ${e}, clamping to ${e}`):t>i&&console.warn(`ForesightJS: "${n}" value ${t} is above maximum bound ${i}, clamping to ${i}`),Math.min(Math.max(t,e),i)}function w(t,e,i){let n=0,o=1;const s=e.x-t.x,r=e.y-t.y,l=(t,e)=>{if(0===t){if(e<0)return!1}else{const i=e/t;if(t<0){if(i>o)return!1;i>n&&(n=i)}else{if(i<n)return!1;i<o&&(o=i)}}return!0};return!!l(-s,t.x-i.left)&&(!!l(s,i.right-t.x)&&(!!l(-r,t.y-i.top)&&(!!l(r,i.bottom-t.y)&&n<=o)))}function R(t){if("number"==typeof t){const e=S(t,0,y,"hitslop");return{top:e,left:e,right:e,bottom:e}}return{top:S(t.top,0,y,"hitslop - top"),left:S(t.left,0,y,"hitslop - left"),right:S(t.right,0,y,"hitslop - right"),bottom:S(t.bottom,0,y,"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 P(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 O(t,e){return void 0!==t&&e!==t}var D=class{static intersect(t,e){const i=Math.max(t.left,e.left),n=Math.min(t.right,e.right),o=Math.max(t.top,e.top),s=Math.min(t.bottom,e.bottom),r=Math.max(0,n-i),l=Math.max(0,s-o);return new DOMRect(i,o,r,l)}static clip(t,e){const i={...t.toJSON(),top:t.top+e.top,left:t.left+e.left,bottom:t.bottom-e.bottom,right:t.right-e.right};return i.width=i.right-i.left,i.height=i.bottom-i.top,i}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 x(t,e){const i=Math.max(t.width,3),n=Math.max(t.height,3),o=t.top-e.top- -1,s=t.left-e.left- -1,r=e.right-t.left-i- -1,l=e.bottom-t.top-n- -1;return`${-Math.round(o)}px ${-Math.round(r)}px ${-Math.round(l)}px ${-Math.round(s)}px`}var B=[...Array.from({length:1e3},(t,e)=>e/1e3),1],M=class{constructor(t,e,i){this.#t=e,this.#e=i,this.#i=i.clientRect,this.#n(t)}#t;#o=void 0;#e;#i;#s=void 0;get visibleRect(){const t=this.#e.clip;return t?D.clip(this.#i,t):this.#i}get isIntersecting(){const{width:t,height:e}=this.visibleRect;return t>0&&e>0}#n(t){const{root:e,rootBounds:i}=this.#e,{visibleRect:n}=this;this.#o?.disconnect(),this.#o=new IntersectionObserver(this.#r,{root:e,rootMargin:x(n,i),threshold:B}),this.#o.observe(t)}#r=t=>{if(!this.#o)return;const e=t[t.length-1];if(e){const{intersectionRatio:t,boundingClientRect:i}=e,n=this.#i;this.#i=i;const o=this.#s,s=!D.equals(i,n);if(t!==this.#s||s){const n=this.#e.rootBounds,r=D.intersect(i,n),l=r.width>0&&r.height>0;if(!l)return;this.#s=t,(null!=o||s)&&(this.#t(new k(e.target,i,e.intersectionRect,l,n),this),this.#n(e.target))}}};disconnect(){this.#o?.disconnect()}},k=class{constructor(t,e,i,n,o){this.target=t,this.boundingClientRect=e,this.intersectionRect=i,this.isIntersecting=n,this.rootBounds=o}},I=class{constructor(t,e){const i=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}(i)){const t=i.ownerDocument??document;this.rootBounds=i.getBoundingClientRect(),this.#l=new ResizeObserver(t=>{for(const i of t){const[{inlineSize:t,blockSize:n}]=i.borderBoxSize;if(D.sizeEqual(this.rootBounds,{width:t,height:n}))continue;const o=i.target.getBoundingClientRect();this.rootBounds=o,e(o,this)}}),this.#l.observe(i),t.addEventListener("scroll",t=>{t.target&&t.target!==i&&L(t.target)&&t.target.contains(i)&&(this.rootBounds=i.getBoundingClientRect(),e(this.rootBounds,this))},{capture:!0,passive:!0,signal:this.#a.signal})}else{const t=i.visualViewport??i;this.rootBounds=T(i);const n=()=>{const t=T(i);D.equals(this.rootBounds,t)||(this.rootBounds=t,e(t,this))};t.addEventListener("resize",n,{signal:this.#a.signal})}}#l;#a=new AbortController;rootBounds;disconnect(){this.#l?.disconnect(),this.#a.abort()}};function T(t){const e=t.visualViewport?.width??t.innerWidth,i=t.visualViewport?.height??t.innerHeight;return new DOMRect(0,0,e,i)}function L(t){return"nodeType"in t}var z=class{constructor(t,e){this.#e=e,this.#t=e=>{const i=[];for(const t of e){const e=this.intersections.get(t.target);this.intersections.set(t.target,t),e?.isIntersecting===t.isIntersecting&&D.equals(e?.intersectionRect,t.intersectionRect)||i.push(t)}i.length>0&&t(i,this)}}#t;#c=new Map;#e;intersections=new WeakMap;observe(t){const e=t.ownerDocument;if(!e)return;let i=this.#c.get(e);i||(i=new IntersectionObserver(this.#t,{...this.#e,threshold:B}),this.#c.set(e,i)),i.observe(t)}unobserve(t){const e=t.ownerDocument;if(!e)return;const i=this.#c.get(e);i&&(i.unobserve(t),this.intersections.delete(t))}disconnect(){for(const t of this.#c.values())t.disconnect();this.#c.clear()}},j=class{constructor(t,e){this.#t=t,this.#e=e,this.#h=new I(e?.root,this.#u),this.#d=new z(this.#g,e),this.#l=new ResizeObserver(this.#b)}#t;#e;#p=new Map;#l;#f=new WeakMap;#h;#d;observe(t){this.#d.observe(t)}unobserve(t){t?(this.#p.get(t)?.disconnect(),this.#d.unobserve(t)):this.disconnect()}disconnect(){for(const t of this.#p.values())t.disconnect();this.#l.disconnect(),this.#h.disconnect(),this.#d.disconnect()}#m(t){const e=[];for(const i of t){const{target:t}=i;N(i,this.#f.get(t))||(this.#f.set(t,i),e.push(i))}e.length>0&&this.#t(e)}#u=t=>{const e=[];for(const[i]of this.#p){const n=i.getBoundingClientRect(),o=this.#v(i,n);e.push(new H(i,n,o.visibleRect,o.isIntersecting,t))}this.#m(e)};#v(t,e){const i=this.#d;this.#p.get(t)?.disconnect();const n=new M(t,this.#y,{clientRect:e,root:this.#e?.root,rootBounds:this.#h.rootBounds,get clip(){const e=i.intersections.get(t);if(!e)return;const{intersectionRect:n,boundingClientRect:o}=e;return D.clipOffsets(o,n)}});return this.#p.set(t,n),n}#g=t=>{const e=[];for(const i of t){const{target:t,isIntersecting:n,boundingClientRect:o}=i;n?(this.#v(t,o),this.#l.observe(t)):(this.#p.get(t)?.disconnect(),this.#p.delete(t),this.#l.unobserve(t));const s=this.#p.get(t);e.push(new H(t,o,s?.visibleRect??i.intersectionRect,n,this.#h.rootBounds))}this.#m(e)};#y=(t,e)=>{this.#m([new H(t.target,t.boundingClientRect,e.visibleRect,t.isIntersecting,this.#h.rootBounds)])};#b=t=>{const e=[];for(const i of t){const{target:t,borderBoxSize:n}=i,o=this.#f.get(t);if(o){const[{inlineSize:t,blockSize:e}]=n;if(D.sizeEqual(o.boundingClientRect,{width:t,height:e}))continue}const s=t.getBoundingClientRect(),r=this.#v(t,s);e.push(new H(t,s,r.visibleRect,this.#d.intersections.get(t)?.isIntersecting??!1,this.#h.rootBounds))}this.#m(e)}},H=class{constructor(t,e,i,n,o){this.target=t,this.boundingClientRect=e,this.intersectionRect=i,this.isIntersecting=n,this.rootBounds=o}};function N(t,e){return null!=e&&(t.target===e.target&&t.isIntersecting===e.isIntersecting&&D.equals(t.boundingClientRect,e.boundingClientRect)&&D.equals(t.intersectionRect,e.intersectionRect))}class _{constructor(){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={debug:!1,enableMousePrediction:true,enableScrollPrediction:true,positionHistorySize:8,trajectoryPredictionTime:120,scrollMargin:150,defaultHitSlop:{top:0,left:0,right:0,bottom:0},enableTabPrediction:true,tabOffset:2,onAnyCallbackFired:(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=t=>{this.updatePointerState(t),this.elements.forEach(t=>{t.isIntersectingWithViewport&&this.handleCallbackInteraction(t)}),this.emit({type:"mouseTrajectoryUpdate",predictionEnabled:this._globalSettings.enableMousePrediction,timestamp:Date.now(),trajectoryPositions:this.trajectoryPositions})},this.handleDomMutations=t=>{t.length&&(this.tabbableElementsCache=[],this.lastFocusedIndex=null);for(const e of t)if("childList"===e.type&&e.removedNodes.length>0)for(const t of Array.from(this.elements.keys()))t.isConnected||this.unregister(t,"disconnected")},this.handleKeyDown=t=>{"Tab"===t.key&&(this.lastKeyDown=t)},this.handleFocusIn=t=>{if(!this.lastKeyDown||!this._globalSettings.enableTabPrediction)return;const e=t.target;if(!(e instanceof HTMLElement))return;this.tabbableElementsCache.length||(this.tabbableElementsCache=m(document.documentElement));const i=this.lastKeyDown.shiftKey,n=function(t,e,i,n){if(null!==e){const o=t?e-1:e+1;if(o>=0&&o<i.length&&i[o]===n)return o}return i.findIndex(t=>t===n)}(i,this.lastFocusedIndex,this.tabbableElementsCache,e);this.lastFocusedIndex=n,this.lastKeyDown=null;const o=[];for(let t=0;t<=this._globalSettings.tabOffset;t++)if(i){const e=this.tabbableElementsCache[n-t];this.elements.has(e)&&o.push(e)}else{const e=this.tabbableElementsCache[n+t];this.elements.has(e)&&o.push(e)}o.forEach(t=>{this.callCallback(this.elements.get(t),{kind:"tab",subType:i?"reverse":"forwards"})})},this.handlePositionChange=t=>{for(const e of t){const t=this.elements.get(e.target);if(!t)continue;const i=t.isIntersectingWithViewport,n=e.isIntersecting;t.isIntersectingWithViewport=n,i!==n&&this.emit({type:"elementDataUpdated",elementData:t,timestamp:Date.now(),updatedProp:"visibility"}),n&&(this.updateElementBounds(e.boundingClientRect,t),this.handleScrollPrefetch(t,e.boundingClientRect))}this.scrollDirection=null,this.predictedScrollPoint=null}}static initialize(t){return this.isInitiated||(_.manager=new _),void 0!==t&&_.manager.alterGlobalSettings(t),_.manager}addEventListener(t,e,i){if(i?.signal?.aborted)return()=>{};this.eventListeners.has(t)||this.eventListeners.set(t,[]),this.eventListeners.get(t).push(e),i?.signal?.addEventListener("abort",()=>this.removeEventListener(t,e))}removeEventListener(t,e){const i=this.eventListeners.get(t);if(i){const t=i.indexOf(e);t>-1&&i.splice(t,1)}}logSubscribers(){console.log("%c[ForesightManager] Current Subscribers:","font-weight: bold; color: #3b82f6;");const t=Array.from(this.eventListeners.keys());0!==t.length?t.forEach(t=>{const e=this.eventListeners.get(t);e&&e.length>0&&(console.groupCollapsed(`Event: %c${t}`,"font-weight: bold;",`(${e.length} listener${e.length>1?"s":""})`),e.forEach((t,e)=>{console.log(`[${e}]:`,t)}),console.groupEnd())}):console.log(" No active subscribers.")}emit(t){const e=this.eventListeners.get(t.type);e&&e.forEach(e=>{try{e(t)}catch(e){console.error(`Error in ForesightManager event listener for ${t.type}:`,e)}})}get getManagerData(){return{registeredElements:this.elements,globalSettings:this._globalSettings,globalCallbackHits:this._globalCallbackHits}}static get isInitiated(){return!!_.manager}static get instance(){return this.initialize()}get registeredElements(){return this.elements}register({element:t,callback:e,hitSlop:i,name:n}){const{shouldRegister:o,isTouchDevice:s,isLimitedConnection:r}=v();if(!o)return{isLimitedConnection:r,isTouchDevice:s,isRegistered:!1,unregister:()=>{}};this.isSetup||this.initializeGlobalListeners();const l=i?R(i):this._globalSettings.defaultHitSlop,a={element:t,callback:e,elementBounds:{originalRect:void 0,expandedRect:{top:0,left:0,right:0,bottom:0},hitSlop:l},isHovering:!1,trajectoryHitData:{isTrajectoryHit:!1,trajectoryHitTime:0,trajectoryHitExpirationTimeoutId:void 0},name:n??t.id??"",isIntersectingWithViewport:!0};return this.elements.set(t,a),this.positionObserver?.observe(t),this.emit({type:"elementRegistered",timestamp:Date.now(),elementData:a}),{isTouchDevice:s,isLimitedConnection:r,isRegistered:!0,unregister:()=>this.unregister(t,"apiCall")}}unregister(t,e){if(!this.elements.has(t))return;const i=this.elements.get(t);i&&this.emit({type:"elementUnregistered",elementData:i,timestamp:Date.now(),unregisterReason:e}),i?.trajectoryHitData.trajectoryHitExpirationTimeoutId&&clearTimeout(i.trajectoryHitData.trajectoryHitExpirationTimeoutId),this.positionObserver?.unobserve(t),this.elements.delete(t),0===this.elements.size&&this.isSetup&&this.removeGlobalListeners()}updateNumericSettings(t,e,i,n){return!!O(t,this._globalSettings[e])&&(this._globalSettings[e]=S(t,i,n,e),!0)}updateBooleanSetting(t,e){return!!O(t,this._globalSettings[e])&&(this._globalSettings[e]=t,!0)}alterGlobalSettings(t){const e=this._globalSettings.positionHistorySize,i=this.updateNumericSettings(t?.positionHistorySize,"positionHistorySize",2,30);i&&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));const n=this.updateNumericSettings(t?.trajectoryPredictionTime,"trajectoryPredictionTime",10,200),o=this.updateNumericSettings(t?.scrollMargin,"scrollMargin",30,300),s=this.updateNumericSettings(t?.tabOffset,"tabOffset",0,20),r=this.updateBooleanSetting(t?.enableMousePrediction,"enableMousePrediction"),l=this.updateBooleanSetting(t?.enableScrollPrediction,"enableScrollPrediction"),a=this.updateBooleanSetting(t?.enableTabPrediction,"enableTabPrediction");void 0!==t?.onAnyCallbackFired&&(this._globalSettings.onAnyCallbackFired=t.onAnyCallbackFired);let c=!1;if(void 0!==t?.defaultHitSlop){const e=R(t.defaultHitSlop);P(this._globalSettings.defaultHitSlop,e)||(this._globalSettings.defaultHitSlop=e,c=!0,this.forceUpdateAllElementBounds())}(i||n||s||r||a||l||c||o)&&this.emit({type:"managerSettingsChanged",timestamp:Date.now(),managerData:this.getManagerData})}forceUpdateAllElementBounds(){this.elements.forEach((t,e)=>{const i=this.elements.get(e);i&&i.isIntersectingWithViewport&&this.forceUpdateElementBounds(i)})}updatePointerState(t){this.trajectoryPositions.currentPoint={x:t.clientX,y:t.clientY},this.trajectoryPositions.predictedPoint=this._globalSettings.enableMousePrediction?function(t,e,i,n){const o={point:t,time:performance.now()},{x:s,y:r}=t;if(e.push(o),e.length>i&&e.shift(),e.length<2)return{x:s,y:r};const l=e[0],a=e[e.length-1],c=(a.time-l.time)/1e3;if(0===c)return{x:s,y:r};const h=n/1e3;return{x:s+(a.point.x-l.point.x)/c*h,y:r+(a.point.y-l.point.y)/c*h}}(this.trajectoryPositions.currentPoint,this.trajectoryPositions.positions,this._globalSettings.positionHistorySize,this._globalSettings.trajectoryPredictionTime):{...this.trajectoryPositions.currentPoint}}handleCallbackInteraction(t){const{expandedRect:e}=t.elementBounds;if(this._globalSettings.enableMousePrediction)w(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"})}updateHitCounters(t,e){switch(e.kind){case"mouse":this._globalCallbackHits.mouse[e.subType]++;break;case"tab":this._globalCallbackHits.tab[e.subType]++;break;case"scroll":this._globalCallbackHits.scroll[e.subType]++}this._globalCallbackHits.total++}callCallback(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,managerData:this.getManagerData}),this.unregister(t.element,"callbackHit"))}forceUpdateElementBounds(t){const e=t.element.getBoundingClientRect(),i=C(e,t.elementBounds.hitSlop);if(!P(i,t.elementBounds.expandedRect)){const n={...t,elementBounds:{...t.elementBounds,originalRect:e,expandedRect:i}};this.elements.set(t.element,n),this.emit({type:"elementDataUpdated",timestamp:Date.now(),elementData:n,updatedProp:"bounds"})}}updateElementBounds(t,e){const i={...e,elementBounds:{...e.elementBounds,originalRect:t,expandedRect:C(t,e.elementBounds.hitSlop)}};this.elements.set(e.element,i),this.emit({type:"elementDataUpdated",timestamp:Date.now(),elementData:i,updatedProp:"bounds"})}handleScrollPrefetch(t,e){if(this._globalSettings.enableScrollPrediction){if(!t.elementBounds.originalRect)return;if(this.scrollDirection=this.scrollDirection??function(t,e){const i=e.top-t.top,n=e.left-t.left;return i<-1?"down":i>1?"up":n<-1?"right":n>1?"left":"none"}(t.elementBounds.originalRect,e),"none"===this.scrollDirection)return;this.predictedScrollPoint=this.predictedScrollPoint??function(t,e,i){const{x:n,y:o}=t,s={x:n,y:o};switch(e){case"down":s.y+=i;break;case"up":s.y-=i;break;case"left":s.x-=i;break;case"right":s.x+=i}return s}(this.trajectoryPositions.currentPoint,this.scrollDirection,this._globalSettings.scrollMargin),w(this.trajectoryPositions.currentPoint,this.predictedScrollPoint,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"})}initializeGlobalListeners(){if(this.isSetup)return;if("undefined"==typeof window||"undefined"==typeof document)return;this.globalListenersController=new AbortController;const{signal:t}=this.globalListenersController;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 j(this.handlePositionChange),this.isSetup=!0}removeGlobalListeners(){this.isSetup=!1,this.globalListenersController?.abort(),this.globalListenersController=null,this.domObserver?.disconnect(),this.domObserver=null,this.positionObserver?.disconnect(),this.positionObserver=null}}exports.ForesightManager=_;
|
|
7
6
|
//# sourceMappingURL=index.js.map
|