js.foresight-devtools 1.3.0-beta.1 → 1.3.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/LICENSE +21 -0
- package/README.md +45 -124
- package/dist/index.d.ts +11 -0
- package/dist/index.js +141 -80
- package/package.json +64 -63
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Bart Spaans
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# js.foresight-devtools
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/js.foresight-devtools)
|
|
4
4
|
[](http://www.typescriptlang.org/)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`ForesightJS` offers dedicated [Development Tools](https://github.com/spaansba/ForesightJS/tree/main/packages/js.foresight-devtools), written in [Lit](https://lit.dev/), to help you better understand and fine-tune how `ForesightJS` works within your application. You can see the development tools in action on the [playground page](https://foresightjs.com/#playground), which includes visual trajectory indicators, element boundaries, and a control panel in the bottom-right corner.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
The ForesightJS Development Tools are a companion development package that provides visual development capabilities for ForesightJS implementations. They help developers understand and tune how ForesightJS is working in their applications by providing real-time visualization of:
|
|
12
|
-
|
|
13
|
-
- **Mouse trajectory predictions** - See predicted cursor paths and intersection points
|
|
14
|
-
- **Element bounds and hit slop areas** - Visualize registered elements and their interaction zones
|
|
15
|
-
- **Keyboard navigation sequences** - Track tab-based navigation predictions
|
|
16
|
-
- **Callback execution** - Monitor when and why prediction callbacks fire
|
|
17
|
-
- **Real-time settings control** - Adjust ForesightJS parameters on the fly
|
|
18
|
-
|
|
19
|
-

|
|
9
|
+
These tools are built entirely using `ForesightJS`'s [built-in events](/docs/events), demonstrating how you can create your own monitoring and debugging tools using the same event system.
|
|
20
10
|
|
|
21
11
|
## Installation
|
|
22
12
|
|
|
13
|
+
To install the `ForesightJS` Development Tools package, use your preferred package manager:
|
|
14
|
+
|
|
23
15
|
```bash
|
|
24
16
|
pnpm add -D js.foresight-devtools
|
|
25
17
|
# or
|
|
@@ -28,142 +20,71 @@ npm install -D js.foresight-devtools
|
|
|
28
20
|
yarn add -D js.foresight-devtools
|
|
29
21
|
```
|
|
30
22
|
|
|
31
|
-
##
|
|
32
|
-
|
|
33
|
-
```javascript
|
|
34
|
-
import { ForesightManager } from "js.foresight"
|
|
35
|
-
import { ForesightDevtools } from "js.foresight-devtools"
|
|
36
|
-
|
|
37
|
-
// Initialize ForesightJS
|
|
38
|
-
ForesightManager.initialize()
|
|
39
|
-
|
|
40
|
-
// Initialize development tools
|
|
41
|
-
ForesightDevtools.initialize()
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Configuration Options
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
type DevelopmentToolsSettings = {
|
|
48
|
-
showDebugger?: boolean
|
|
49
|
-
isControlPanelDefaultMinimized?: boolean
|
|
50
|
-
showNameTags?: boolean // Show element names on overlays
|
|
51
|
-
sortElementList?: "documentOrder" | "visibility" | "insertionOrder" // Control panel sorting
|
|
52
|
-
logging: {
|
|
53
|
-
logLocation: "controlPanel" | "console" | "both" | "none" // Where to log the Foresight Events
|
|
54
|
-
callbackCompleted: boolean
|
|
55
|
-
callbackInvoked: boolean
|
|
56
|
-
elementDataUpdated: boolean
|
|
57
|
-
elementRegistered: boolean
|
|
58
|
-
elementUnregistered: boolean
|
|
59
|
-
managerSettingsChanged: boolean
|
|
60
|
-
mouseTrajectoryUpdate: boolean
|
|
61
|
-
scrollTrajectoryUpdate: boolean
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Available Development Tools Settings
|
|
67
|
-
|
|
68
|
-
**TypeScript Type:** `DevelopmentToolsSettings`
|
|
69
|
-
|
|
70
|
-
| Setting | Type | Default | Description |
|
|
71
|
-
| -------------------------------- | ----------------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
72
|
-
| `showDebugger` | `boolean` | `true` | Controls whether the development tools are visible and active |
|
|
73
|
-
| `isControlPanelDefaultMinimized` | `boolean` | `false` | When true, the development tools control panel will be minimized on page load |
|
|
74
|
-
| `showNameTags` | `boolean` | `true` | Shows the element `name` (or `id` if no `name` is given) above registered elements |
|
|
75
|
-
| `sortElementList` | `SortElementList` | `visibility` | Controls element sorting in control panel: `visibility` sorts by viewport visibility, `documentOrder` sorts by HTML structure order, `insertionOrder` sorts by registration order |
|
|
76
|
-
|
|
77
|
-
### Logging Configuration
|
|
78
|
-
|
|
79
|
-
**TypeScript Type:** `LogEvents & { logLocation: LoggingLocations }`
|
|
80
|
-
|
|
81
|
-
| Setting | Type | Default | Description |
|
|
82
|
-
| ------------------------ | ------------------------------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------- |
|
|
83
|
-
| `logLocation` | `"controlPanel"` \| `"console"` \| `"both"` \| `"none"` | `"controlPanel"` | Where to output the ForesightJS event logs |
|
|
84
|
-
| `callbackCompleted` | `boolean` | `false` | Log when element callbacks finish executing (includes success/error status and execution time) |
|
|
85
|
-
| `callbackInvoked` | `boolean` | `false` | Log when element callbacks are triggered (includes hit type: mouse/keyboard/scroll) |
|
|
86
|
-
| `elementDataUpdated` | `boolean` | `false` | Log when element data changes (bounds updates, visibility changes) |
|
|
87
|
-
| `elementRegistered` | `boolean` | `false` | Log when new elements are registered with ForesightJS |
|
|
88
|
-
| `elementUnregistered` | `boolean` | `false` | Log when elements are unregistered (includes reason: callbackHit/disconnected/apiCall) |
|
|
89
|
-
| `managerSettingsChanged` | `boolean` | `false` | Log when ForesightManager global settings are modified |
|
|
90
|
-
| `mouseTrajectoryUpdate` | `boolean` | `false` | Log real-time mouse trajectory predictions (high frequency - use with caution) |
|
|
91
|
-
| `scrollTrajectoryUpdate` | `boolean` | `false` | Log scroll direction predictions and trajectory updates |
|
|
92
|
-
|
|
93
|
-
### Usage Example with All Options
|
|
23
|
+
## Enabling Development Tools
|
|
94
24
|
|
|
95
25
|
```javascript
|
|
96
26
|
import { ForesightManager } from "js.foresight"
|
|
97
27
|
import { ForesightDevtools } from "js.foresight-devtools"
|
|
98
28
|
|
|
99
29
|
// Initialize ForesightJS
|
|
100
|
-
ForesightManager.initialize({
|
|
101
|
-
trajectoryPredictionTime: 100,
|
|
102
|
-
defaultHitSlop: { top: 10, right: 10, bottom: 10, left: 10 },
|
|
103
|
-
enableMousePrediction: true,
|
|
104
|
-
enableTabPrediction: true,
|
|
105
|
-
enableScrollPrediction: true,
|
|
106
|
-
})
|
|
30
|
+
ForesightManager.initialize({})
|
|
107
31
|
|
|
108
|
-
// Initialize development tools
|
|
32
|
+
// Initialize the development tools (all options are optional)
|
|
109
33
|
ForesightDevtools.initialize({
|
|
110
34
|
showDebugger: true,
|
|
111
|
-
isControlPanelDefaultMinimized: false,
|
|
112
|
-
showNameTags: true,
|
|
113
|
-
sortElementList: "visibility",
|
|
35
|
+
isControlPanelDefaultMinimized: false, // optional setting which allows you to minimize the control panel on default
|
|
36
|
+
showNameTags: true, // optional setting which shows the name of the element
|
|
37
|
+
sortElementList: "visibility", // optional setting for how the elements in the control panel are sorted
|
|
114
38
|
logging: {
|
|
115
|
-
logLocation: "controlPanel",
|
|
39
|
+
logLocation: "controlPanel", // Where to log the Foresight Events
|
|
116
40
|
callbackCompleted: true,
|
|
41
|
+
elementReactivated: true,
|
|
117
42
|
callbackInvoked: true,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
43
|
+
elementDataUpdated: false,
|
|
44
|
+
elementRegistered: false,
|
|
45
|
+
elementUnregistered: false,
|
|
121
46
|
managerSettingsChanged: true,
|
|
122
|
-
mouseTrajectoryUpdate: false, //
|
|
123
|
-
scrollTrajectoryUpdate: false, //
|
|
124
|
-
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
// Register elements as usual
|
|
128
|
-
ForesightManager.instance.register({
|
|
129
|
-
element: document.getElementById("my-button"),
|
|
130
|
-
callback: () => {
|
|
131
|
-
console.log("Prediction triggered!")
|
|
47
|
+
mouseTrajectoryUpdate: false, // dont log this to the devtools
|
|
48
|
+
scrollTrajectoryUpdate: false, // dont log this to the devtools
|
|
49
|
+
deviceStrategyChanged: true,
|
|
132
50
|
},
|
|
133
|
-
name: "my-button", // This name will appear in the development tools
|
|
134
51
|
})
|
|
135
52
|
```
|
|
136
53
|
|
|
137
|
-
## Development
|
|
54
|
+
## Development Tools Features
|
|
55
|
+
|
|
56
|
+
Once enabled, the `ForesightJS` Development Tools add several visual layers to your application, including mouse and scroll trajectories and element hitboxes. A control panel also appears in the bottom-right corner of the screen.
|
|
57
|
+
|
|
58
|
+
### Control Panel
|
|
59
|
+
|
|
60
|
+
The control panel provides three main tabs for debugging and configuration. Each tab serves a specific purpose in understanding and tuning ForesightJS behavior.
|
|
138
61
|
|
|
139
|
-
|
|
62
|
+
#### Settings Tab
|
|
140
63
|
|
|
141
|
-
|
|
142
|
-
2. **Fine-tuning prediction parameters** for specific UI components
|
|
143
|
-
3. **Debugging callback execution** issues or unexpected behavior
|
|
144
|
-
4. **Optimizing hit slop areas** for better user experience
|
|
145
|
-
5. **Understanding prediction accuracy** across different interaction patterns
|
|
64
|
+
The Settings tab provides real-time controls for all [Global Configurations](/docs/configuration/global-settings). Changes made through these controls immediately affect the `ForesightManager` configuration, allowing you to see how different settings impact your app without fiddling in your code.
|
|
146
65
|
|
|
147
|
-
|
|
66
|
+
#### Elements Tab
|
|
148
67
|
|
|
149
|
-
|
|
68
|
+
The Elements tab displays a overview of all currently registered elements within the `ForesightManage`r. Each element entry shows its current status through color-coded indicators:
|
|
150
69
|
|
|
151
|
-
-
|
|
152
|
-
-
|
|
153
|
-
-
|
|
154
|
-
-
|
|
155
|
-
-
|
|
70
|
+
- 🟢 **Green** - Active visible elements in desktop mode
|
|
71
|
+
- ⚫ **Grey** - Active invisible elements in desktop mode
|
|
72
|
+
- 🟣 **Purple** - Active elements while in touch device mode (all elements, we dont track visibility in this mode)
|
|
73
|
+
- 🟡 **Yellow** - Elements which callbacks are currently executing
|
|
74
|
+
- 🔘 **Light Gray** - Inactive elements
|
|
156
75
|
|
|
157
|
-
|
|
76
|
+
Each element can also be expanded to reveal its [`ForesightElementData`](/docs/next/getting-started/typescript#foresightelementdata) information including settings, callback status, and metadata. A countdown timer appears for elements in their reactivation cooldown period (`reactivateAfter`), clicking this timer will instantly reactivate the element.
|
|
158
77
|
|
|
159
|
-
|
|
78
|
+
#### Log Tab
|
|
160
79
|
|
|
161
|
-
|
|
80
|
+
The Log tab displays real-time [events](/docs/events) emitted by `ForesightJS`. You can see callback execution times, the full element's lifecycle and other system events. Events can be filtered through the devtools initialization configuration or in the control panel itself.
|
|
162
81
|
|
|
163
|
-
|
|
82
|
+
You can also print out the complete [`ForesightManager.instance.getManagerData`](/docs/debugging/static-properties#foresightmanagerinstancegetmanagerdata) state without having to call it from your code.
|
|
164
83
|
|
|
165
|
-
|
|
84
|
+
:::caution
|
|
85
|
+
Avoid logging frequently emitted events to the browser console, as it can noticeably slow down your development environment. Use the control panel for this instead.
|
|
86
|
+
:::
|
|
166
87
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
88
|
+
:::note
|
|
89
|
+
Element overlay visualization and visibility sorting in the control panel only work with desktop/mouse prediction strategies. When debugging `touchDeviceStrategy` configurations, these features are not available as touch strategies don't track the same positioning data.
|
|
90
|
+
:::
|
package/dist/index.d.ts
CHANGED
|
@@ -196,6 +196,10 @@ declare class SingleElement extends LitElement {
|
|
|
196
196
|
isActive: boolean;
|
|
197
197
|
isExpanded: boolean;
|
|
198
198
|
onToggle: ((elementId: string) => void) | undefined;
|
|
199
|
+
private currentDeviceStrategy;
|
|
200
|
+
private _abortController;
|
|
201
|
+
connectedCallback(): void;
|
|
202
|
+
disconnectedCallback(): void;
|
|
199
203
|
private getBorderColor;
|
|
200
204
|
private getStatusIndicatorClass;
|
|
201
205
|
private getStatusText;
|
|
@@ -273,6 +277,11 @@ interface ElementRegisteredPayload extends PayloadBase {
|
|
|
273
277
|
}
|
|
274
278
|
interface ElementUnregisteredEvent extends PayloadBase {
|
|
275
279
|
type: "elementUnregistered";
|
|
280
|
+
name: string;
|
|
281
|
+
id: string;
|
|
282
|
+
callbackInfo: ElementCallbackInfo;
|
|
283
|
+
meta: Record<string, unknown>;
|
|
284
|
+
wasLastRegisteredElement: boolean;
|
|
276
285
|
}
|
|
277
286
|
interface ElementReactivatedPayload extends PayloadBase {
|
|
278
287
|
type: "elementReactivated";
|
|
@@ -298,11 +307,13 @@ interface CallbackInvokedPayload extends PayloadBase {
|
|
|
298
307
|
}
|
|
299
308
|
interface CallbackCompletedPayload extends PayloadBase {
|
|
300
309
|
type: "callbackCompleted";
|
|
310
|
+
elapsed: string;
|
|
301
311
|
name: string;
|
|
302
312
|
hitType: CallbackHitType;
|
|
303
313
|
status: "success" | "error" | undefined;
|
|
304
314
|
errorMessage: string | undefined | null;
|
|
305
315
|
callbackInfo: ElementCallbackInfo;
|
|
316
|
+
wasLastActiveElement: boolean;
|
|
306
317
|
meta: Record<string, unknown>;
|
|
307
318
|
}
|
|
308
319
|
interface MouseTrajectoryUpdatePayload extends PayloadBase {
|