js.foresight-devtools 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { ForesightManager } from "js.foresight";
2
- import type { DebuggerSettings, ForesightDebuggerData } from "../types";
1
+ import { ForesightManager } from 'js.foresight';
2
+ import type { DebuggerSettings, ForesightDebuggerData } from '../types';
3
3
  export type ElementOverlays = {
4
4
  expandedOverlay: HTMLElement;
5
5
  nameLabel: HTMLElement;
@@ -0,0 +1,341 @@
1
+ import PositionObserver from '@thednp/position-observer';
2
+ import { DebuggerControlPanel } from './DebuggerControlPanel';
3
+ import { createAndAppendElement, createAndAppendStyle } from './helpers/createAndAppend';
4
+ import { updateElementOverlays } from './helpers/updateElementOverlays';
5
+ // PositionObserver imported above
6
+ // Import constants that should be available from js.foresight
7
+ // These constants need to be part of the main package's public API
8
+ var DEFAULT_IS_DEBUGGER_MINIMIZED = false;
9
+ var DEFAULT_SHOW_DEBUGGER = true;
10
+ var DEFAULT_SHOW_NAME_TAGS = true;
11
+ var DEFAULT_SORT_ELEMENT_LIST = 'visibility';
12
+ // Helper function that should be available from js.foresight or implemented locally
13
+ function shouldUpdateSetting(newValue, currentValue) {
14
+ return newValue !== undefined && newValue !== currentValue;
15
+ }
16
+ // Helper function that should be available from js.foresight or implemented locally
17
+ function evaluateRegistrationConditions() {
18
+ return {
19
+ shouldRegister: typeof window !== 'undefined' && !('ontouchstart' in window),
20
+ };
21
+ }
22
+ var ForesightDebugger = /** @class */ (function () {
23
+ function ForesightDebugger(foresightManager) {
24
+ var _this = this;
25
+ this.callbackAnimations = new Map();
26
+ this._debuggerSettings = {
27
+ showDebugger: DEFAULT_SHOW_DEBUGGER,
28
+ isControlPanelDefaultMinimized: DEFAULT_IS_DEBUGGER_MINIMIZED,
29
+ showNameTags: DEFAULT_SHOW_NAME_TAGS,
30
+ sortElementList: DEFAULT_SORT_ELEMENT_LIST,
31
+ };
32
+ this.debugElementOverlays = new Map();
33
+ this.predictedMouseIndicator = null;
34
+ this.mouseTrajectoryLine = null;
35
+ this.scrollTrajectoryLine = null;
36
+ this.managerSubscriptionsController = null;
37
+ this.animationPositionObserver = null;
38
+ this.handleAnimationPositionChange = function (entries) {
39
+ for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
40
+ var entry = entries_1[_i];
41
+ var animationData = _this.callbackAnimations.get(entry.target);
42
+ if (animationData) {
43
+ var rect = entry.boundingClientRect;
44
+ var hitSlop = animationData.hitSlop, overlay = animationData.overlay;
45
+ var newLeft = rect.left - hitSlop.left;
46
+ var newTop = rect.top - hitSlop.top;
47
+ var newWidth = rect.width + hitSlop.left + hitSlop.right;
48
+ var newHeight = rect.height + hitSlop.top + hitSlop.bottom;
49
+ overlay.style.transform = "translate3d(".concat(newLeft, "px, ").concat(newTop, "px, 0)");
50
+ overlay.style.width = "".concat(newWidth, "px");
51
+ overlay.style.height = "".concat(newHeight, "px");
52
+ }
53
+ }
54
+ };
55
+ this.handleElementDataUpdated = function (e) {
56
+ var _a;
57
+ switch (e.updatedProp) {
58
+ case 'bounds':
59
+ _this.createOrUpdateElementOverlay(e.elementData);
60
+ break;
61
+ case 'visibility':
62
+ if (!e.elementData.isIntersectingWithViewport) {
63
+ _this.removeElementOverlay(e.elementData);
64
+ }
65
+ (_a = _this.controlPanel) === null || _a === void 0 ? void 0 : _a.updateElementVisibilityStatus(e.elementData);
66
+ break;
67
+ }
68
+ };
69
+ /**
70
+ * Removes all debug overlays and data associated with an element.
71
+ *
72
+ * This method cleans up the link overlay, expanded overlay, and name label
73
+ * for the specified element, removes it from internal tracking maps, and
74
+ * refreshes the control panel's element list to reflect the removal.
75
+ *
76
+ * @param element - The ForesightElement to remove from debugging visualization
77
+ */
78
+ this.handleRemoveElement = function (e) {
79
+ var _a;
80
+ (_a = _this.controlPanel) === null || _a === void 0 ? void 0 : _a.removeElementFromList(e.elementData);
81
+ _this.removeElementOverlay(e.elementData);
82
+ };
83
+ this.handleCallbackFired = function (e) {
84
+ _this.showCallbackAnimation(e.elementData);
85
+ };
86
+ this.handleAddElement = function (e) {
87
+ _this.createOrUpdateElementOverlay(e.elementData);
88
+ _this.controlPanel.addElementToList(e.elementData, e.sort);
89
+ };
90
+ this.handleMouseTrajectoryUpdate = function (e) {
91
+ if (!_this.shadowRoot || !_this.debugContainer) {
92
+ return;
93
+ }
94
+ if (!_this.predictedMouseIndicator || !_this.mouseTrajectoryLine) {
95
+ return;
96
+ }
97
+ //Hide scroll visuals on mouse move
98
+ if (_this.scrollTrajectoryLine) {
99
+ _this.scrollTrajectoryLine.style.display = 'none';
100
+ }
101
+ var _a = e.trajectoryPositions, predictedPoint = _a.predictedPoint, currentPoint = _a.currentPoint;
102
+ // Use transform for positioning to avoid layout reflow.
103
+ // The CSS handles centering the element with `translate(-50%, -50%)`.
104
+ _this.predictedMouseIndicator.style.transform = "translate3d(".concat(predictedPoint.x, "px, ").concat(predictedPoint.y, "px, 0) translate3d(-50%, -50%, 0)");
105
+ _this.predictedMouseIndicator.style.display = e.predictionEnabled ? 'block' : 'none';
106
+ // This hides the circle from the UI at the top-left corner when refreshing the page with the cursor outside of the window
107
+ if (predictedPoint.x === 0 && predictedPoint.y === 0) {
108
+ _this.predictedMouseIndicator.style.display = 'none';
109
+ return;
110
+ }
111
+ if (!e.predictionEnabled) {
112
+ _this.mouseTrajectoryLine.style.display = 'none';
113
+ return;
114
+ }
115
+ var dx = predictedPoint.x - currentPoint.x;
116
+ var dy = predictedPoint.y - currentPoint.y;
117
+ var length = Math.sqrt(dx * dx + dy * dy);
118
+ var angle = (Math.atan2(dy, dx) * 180) / Math.PI;
119
+ // Use a single transform to position, rotate, and scale the line,
120
+ // avoiding reflow from top/left changes.
121
+ _this.mouseTrajectoryLine.style.transform = "translate3d(".concat(currentPoint.x, "px, ").concat(currentPoint.y, "px, 0) rotate(").concat(angle, "deg)");
122
+ _this.mouseTrajectoryLine.style.width = "".concat(length, "px");
123
+ _this.mouseTrajectoryLine.style.display = 'block';
124
+ };
125
+ this.handleScrollTrajectoryUpdate = function (e) {
126
+ if (!_this.scrollTrajectoryLine)
127
+ return;
128
+ var dx = e.predictedPoint.x - e.currentPoint.x;
129
+ var dy = e.predictedPoint.y - e.currentPoint.y;
130
+ var length = Math.sqrt(dx * dx + dy * dy);
131
+ var angle = (Math.atan2(dy, dx) * 180) / Math.PI;
132
+ _this.scrollTrajectoryLine.style.transform = "translate3d(".concat(e.currentPoint.x, "px, ").concat(e.currentPoint.y, "px, 0) rotate(").concat(angle, "deg)");
133
+ _this.scrollTrajectoryLine.style.width = "".concat(length, "px");
134
+ _this.scrollTrajectoryLine.style.display = 'block';
135
+ };
136
+ this.handleSettingsChanged = function (e) {
137
+ var _a;
138
+ (_a = _this.controlPanel) === null || _a === void 0 ? void 0 : _a.updateControlsState(e.newSettings, _this._debuggerSettings);
139
+ };
140
+ this.foresightManagerInstance = foresightManager;
141
+ }
142
+ Object.defineProperty(ForesightDebugger.prototype, "getDebuggerData", {
143
+ get: function () {
144
+ return {
145
+ settings: this._debuggerSettings,
146
+ };
147
+ },
148
+ enumerable: false,
149
+ configurable: true
150
+ });
151
+ ForesightDebugger.initialize = function (foresightManager, props) {
152
+ if (typeof window === 'undefined' || !evaluateRegistrationConditions().shouldRegister) {
153
+ return null;
154
+ }
155
+ if (!ForesightDebugger.isInitiated) {
156
+ ForesightDebugger.debuggerInstance = new ForesightDebugger(foresightManager);
157
+ }
158
+ var instance = ForesightDebugger.debuggerInstance;
159
+ instance.subscribeToManagerEvents();
160
+ instance.alterDebuggerSettings(props);
161
+ // Always call at the end of the initialize function
162
+ if (!instance.shadowHost) {
163
+ instance._setupDOM();
164
+ }
165
+ return instance;
166
+ };
167
+ Object.defineProperty(ForesightDebugger, "instance", {
168
+ get: function () {
169
+ if (!ForesightDebugger.debuggerInstance) {
170
+ throw new Error('ForesightDebugger has not been initialized. Call ForesightDebugger.initialize() first.');
171
+ }
172
+ return ForesightDebugger.debuggerInstance;
173
+ },
174
+ enumerable: false,
175
+ configurable: true
176
+ });
177
+ ForesightDebugger.prototype._setupDOM = function () {
178
+ // If for some reason we call this on an already-setup instance, do nothing.
179
+ if (this.shadowHost) {
180
+ return;
181
+ }
182
+ this.shadowHost = createAndAppendElement('div', document.body, {
183
+ id: 'jsforesight-debugger-shadow-host',
184
+ });
185
+ this.shadowRoot = this.shadowHost.attachShadow({ mode: 'open' });
186
+ this.debugContainer = createAndAppendElement('div', this.shadowRoot, {
187
+ id: 'jsforesight-debug-container',
188
+ });
189
+ this.predictedMouseIndicator = createAndAppendElement('div', this.debugContainer, {
190
+ className: 'jsforesight-mouse-predicted',
191
+ });
192
+ this.mouseTrajectoryLine = createAndAppendElement('div', this.debugContainer, {
193
+ className: 'jsforesight-trajectory-line',
194
+ });
195
+ this.scrollTrajectoryLine = createAndAppendElement('div', this.debugContainer, {
196
+ className: 'jsforesight-scroll-trajectory-line',
197
+ });
198
+ this.controlPanel = DebuggerControlPanel.initialize(this.foresightManagerInstance, ForesightDebugger.debuggerInstance, this.shadowRoot, this._debuggerSettings);
199
+ createAndAppendStyle(debuggerCSS, this.shadowRoot, 'screen-visuals');
200
+ this.animationPositionObserver = new PositionObserver(this.handleAnimationPositionChange);
201
+ };
202
+ Object.defineProperty(ForesightDebugger, "isInitiated", {
203
+ get: function () {
204
+ return !!ForesightDebugger.debuggerInstance;
205
+ },
206
+ enumerable: false,
207
+ configurable: true
208
+ });
209
+ ForesightDebugger.prototype.alterDebuggerSettings = function (props) {
210
+ if (shouldUpdateSetting(props === null || props === void 0 ? void 0 : props.showNameTags, this._debuggerSettings.showNameTags)) {
211
+ this._debuggerSettings.showNameTags = props.showNameTags;
212
+ this.toggleNameTagVisibility();
213
+ }
214
+ if (shouldUpdateSetting(props === null || props === void 0 ? void 0 : props.isControlPanelDefaultMinimized, this._debuggerSettings.isControlPanelDefaultMinimized)) {
215
+ this._debuggerSettings.isControlPanelDefaultMinimized = props.isControlPanelDefaultMinimized;
216
+ }
217
+ if (shouldUpdateSetting(props === null || props === void 0 ? void 0 : props.sortElementList, this._debuggerSettings.sortElementList)) {
218
+ this._debuggerSettings.sortElementList = props.sortElementList;
219
+ }
220
+ if (shouldUpdateSetting(props === null || props === void 0 ? void 0 : props.showDebugger, this._debuggerSettings.showDebugger)) {
221
+ this._debuggerSettings.showDebugger = props.showDebugger;
222
+ if (this._debuggerSettings.showDebugger) {
223
+ ForesightDebugger.initialize(this.foresightManagerInstance);
224
+ }
225
+ else {
226
+ this.cleanup();
227
+ }
228
+ }
229
+ };
230
+ ForesightDebugger.prototype.subscribeToManagerEvents = function () {
231
+ this.managerSubscriptionsController = new AbortController();
232
+ var signal = this.managerSubscriptionsController.signal;
233
+ var manager = this.foresightManagerInstance;
234
+ manager.addEventListener('elementRegistered', this.handleAddElement, { signal: signal });
235
+ manager.addEventListener('elementUnregistered', this.handleRemoveElement, { signal: signal });
236
+ manager.addEventListener('elementDataUpdated', this.handleElementDataUpdated, { signal: signal });
237
+ manager.addEventListener('mouseTrajectoryUpdate', this.handleMouseTrajectoryUpdate, {
238
+ signal: signal,
239
+ });
240
+ manager.addEventListener('scrollTrajectoryUpdate', this.handleScrollTrajectoryUpdate, {
241
+ signal: signal,
242
+ });
243
+ manager.addEventListener('managerSettingsChanged', this.handleSettingsChanged, { signal: signal });
244
+ manager.addEventListener('callbackFired', this.handleCallbackFired, { signal: signal });
245
+ };
246
+ ForesightDebugger.prototype.createElementOverlays = function (elementData) {
247
+ var expandedOverlay = createAndAppendElement('div', this.debugContainer, {
248
+ className: 'jsforesight-expanded-overlay',
249
+ data: elementData.name,
250
+ });
251
+ var nameLabel = createAndAppendElement('div', this.debugContainer, {
252
+ className: 'jsforesight-name-label',
253
+ });
254
+ var overlays = { expandedOverlay: expandedOverlay, nameLabel: nameLabel };
255
+ this.debugElementOverlays.set(elementData.element, overlays);
256
+ return overlays;
257
+ };
258
+ ForesightDebugger.prototype.createOrUpdateElementOverlay = function (newData) {
259
+ var _a;
260
+ if (!this.debugContainer || !this.shadowRoot)
261
+ return;
262
+ var overlays = this.debugElementOverlays.get(newData.element);
263
+ if (!overlays) {
264
+ overlays = this.createElementOverlays(newData);
265
+ }
266
+ updateElementOverlays(overlays, newData, (_a = this._debuggerSettings.showNameTags) !== null && _a !== void 0 ? _a : DEFAULT_SHOW_NAME_TAGS);
267
+ };
268
+ // TODO :fix
269
+ ForesightDebugger.prototype.toggleNameTagVisibility = function () {
270
+ var _this = this;
271
+ this.foresightManagerInstance.registeredElements.forEach(function (elementData) {
272
+ var _a;
273
+ var overlays = _this.debugElementOverlays.get(elementData.element);
274
+ if (!overlays)
275
+ return;
276
+ updateElementOverlays(overlays, elementData, (_a = _this._debuggerSettings.showNameTags) !== null && _a !== void 0 ? _a : DEFAULT_SHOW_NAME_TAGS);
277
+ });
278
+ };
279
+ ForesightDebugger.prototype.removeElementOverlay = function (elementData) {
280
+ var overlays = this.debugElementOverlays.get(elementData.element);
281
+ if (overlays) {
282
+ overlays.expandedOverlay.remove();
283
+ overlays.nameLabel.remove();
284
+ this.debugElementOverlays.delete(elementData.element);
285
+ }
286
+ };
287
+ ForesightDebugger.prototype.showCallbackAnimation = function (elementData) {
288
+ var _this = this;
289
+ var _a, _b;
290
+ var element = elementData.element, elementBounds = elementData.elementBounds;
291
+ var existingAnimation = this.callbackAnimations.get(element);
292
+ // If an animation is already running for this element, reset it
293
+ if (existingAnimation) {
294
+ clearTimeout(existingAnimation.timeoutId);
295
+ existingAnimation.overlay.remove();
296
+ (_a = this.animationPositionObserver) === null || _a === void 0 ? void 0 : _a.unobserve(element);
297
+ this.callbackAnimations.delete(element);
298
+ }
299
+ var animationOverlay = createAndAppendElement('div', this.debugContainer, {
300
+ className: 'jsforesight-callback-indicator',
301
+ });
302
+ var _c = elementBounds.expandedRect, left = _c.left, top = _c.top, right = _c.right, bottom = _c.bottom;
303
+ var width = right - left;
304
+ var height = bottom - top;
305
+ animationOverlay.style.display = 'block';
306
+ animationOverlay.style.transform = "translate3d(".concat(left, "px, ").concat(top, "px, 0)");
307
+ animationOverlay.style.width = "".concat(width, "px");
308
+ animationOverlay.style.height = "".concat(height, "px");
309
+ animationOverlay.classList.add('animate');
310
+ var animationDuration = 500;
311
+ var timeoutId = setTimeout(function () {
312
+ var _a;
313
+ animationOverlay.remove();
314
+ _this.callbackAnimations.delete(element);
315
+ (_a = _this.animationPositionObserver) === null || _a === void 0 ? void 0 : _a.unobserve(element);
316
+ }, animationDuration);
317
+ this.callbackAnimations.set(element, {
318
+ hitSlop: elementData.elementBounds.hitSlop,
319
+ overlay: animationOverlay,
320
+ timeoutId: timeoutId,
321
+ });
322
+ (_b = this.animationPositionObserver) === null || _b === void 0 ? void 0 : _b.observe(element);
323
+ };
324
+ ForesightDebugger.prototype.cleanup = function () {
325
+ var _a, _b, _c;
326
+ (_a = this.managerSubscriptionsController) === null || _a === void 0 ? void 0 : _a.abort();
327
+ (_b = this.controlPanel) === null || _b === void 0 ? void 0 : _b.cleanup();
328
+ (_c = this.shadowHost) === null || _c === void 0 ? void 0 : _c.remove();
329
+ this.debugElementOverlays.clear();
330
+ this.shadowHost = null;
331
+ this.shadowRoot = null;
332
+ this.debugContainer = null;
333
+ this.predictedMouseIndicator = null;
334
+ this.mouseTrajectoryLine = null;
335
+ this.scrollTrajectoryLine = null;
336
+ this.controlPanel = null;
337
+ };
338
+ return ForesightDebugger;
339
+ }());
340
+ export { ForesightDebugger };
341
+ var debuggerCSS = /* css */ "\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-trajectory-line{\n display: none;\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 ";
@@ -0,0 +1,16 @@
1
+ export function createAndAppendElement(tag, parent, attributes) {
2
+ var element = document.createElement(tag);
3
+ if (attributes.id)
4
+ element.id = attributes.id;
5
+ if (attributes.className)
6
+ element.className = attributes.className;
7
+ if (attributes.data)
8
+ element.setAttribute("data-value", attributes.data);
9
+ return parent.appendChild(element);
10
+ }
11
+ export function createAndAppendStyle(styleSheet, parent, id) {
12
+ var element = document.createElement("style");
13
+ element.textContent = styleSheet;
14
+ element.id = id;
15
+ return parent.appendChild(element);
16
+ }
@@ -0,0 +1,3 @@
1
+ export var getIntersectingIcon = function (isIntersectingWithViewport) {
2
+ return isIntersectingWithViewport ? "👁️" : "🚫";
3
+ };
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Converts a JavaScript object into a readable method call string format.
3
+ *
4
+ * This utility is designed for copying object configurations and transforming them
5
+ * into method call syntax for easy copy-pasting of global settings or configurations.
6
+ *
7
+ * @template T - The type of the input object, constrained to Record<string, any>
8
+ * @param obj - The object to convert to method call format
9
+ * @param methodName - The name of the method to wrap the object in (e.g., 'ForesightManager.initialize')
10
+ * @returns A formatted string representing the object as a method call with proper indentation
11
+ *
12
+ */
13
+ export function objectToMethodCall(obj, methodName) {
14
+ var entries = Object.entries(obj);
15
+ // Filter out deprecated keys
16
+ var filteredEntries = entries.filter(function (_a) {
17
+ var key = _a[0];
18
+ var keyStr = String(key);
19
+ if (keyStr === "resizeScrollThrottleDelay") {
20
+ return false;
21
+ }
22
+ return true;
23
+ });
24
+ var formattedEntries = filteredEntries
25
+ .map(function (_a) {
26
+ var key = _a[0], value = _a[1];
27
+ return " ".concat(String(key), ": ").concat(formatValue(value));
28
+ })
29
+ .join(",\n");
30
+ return "".concat(methodName, "({\n").concat(formattedEntries, "\n})");
31
+ }
32
+ /**
33
+ * Formats a value with proper indentation and type-appropriate string representation.
34
+ *
35
+ * @param value - The value to format (can be any type)
36
+ * @param indent - The current indentation level (defaults to 2 spaces)
37
+ * @returns A formatted string representation of the value
38
+ */
39
+ var formatValue = function (value, indent) {
40
+ if (indent === void 0) { indent = 2; }
41
+ var spaces = " ".repeat(indent);
42
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
43
+ var entries = Object.entries(value);
44
+ if (entries.length === 0)
45
+ return "{}";
46
+ var formattedEntries = entries
47
+ .map(function (_a) {
48
+ var key = _a[0], val = _a[1];
49
+ return "".concat(spaces, " ").concat(key, ": ").concat(formatValue(val, indent + 2));
50
+ })
51
+ .join(",\n");
52
+ return "{\n".concat(formattedEntries, "\n").concat(spaces, "}");
53
+ }
54
+ if (typeof value === "string")
55
+ return "'".concat(value, "'");
56
+ if (typeof value === "boolean" || typeof value === "number")
57
+ return String(value);
58
+ if (value === null)
59
+ return "null";
60
+ if (value === undefined)
61
+ return "undefined";
62
+ if (Array.isArray(value))
63
+ return JSON.stringify(value);
64
+ return String(value);
65
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * removes stale debuggers that might have been left behind in the dom
3
+ */
4
+ export function removeOldDebuggers() {
5
+ var oldDebuggers = document.querySelectorAll("#jsforesight-debugger-shadow-host");
6
+ oldDebuggers.forEach(function (element) { return element.remove(); });
7
+ }
@@ -0,0 +1,18 @@
1
+ export function updateElementOverlays(currentOverlays, newData, showNameTags) {
2
+ var expandedOverlay = currentOverlays.expandedOverlay, nameLabel = currentOverlays.nameLabel;
3
+ var expandedRect = newData.elementBounds.expandedRect;
4
+ var expandedWidth = expandedRect.right - expandedRect.left;
5
+ var expandedHeight = expandedRect.bottom - expandedRect.top;
6
+ expandedOverlay.style.width = "".concat(expandedWidth, "px");
7
+ expandedOverlay.style.height = "".concat(expandedHeight, "px");
8
+ expandedOverlay.style.transform = "translate3d(".concat(expandedRect.left, "px, ").concat(expandedRect.top, "px, 0)");
9
+ expandedOverlay.style.display = "block";
10
+ nameLabel.textContent = newData.name;
11
+ if (newData.name === "" || !showNameTags) {
12
+ nameLabel.style.display = "none";
13
+ }
14
+ else {
15
+ nameLabel.style.display = "block";
16
+ nameLabel.style.transform = "translate3d(".concat(expandedRect.left, "px, ").concat(expandedRect.top - 25, "px, 0)");
17
+ }
18
+ }