js.foresight 1.1.1 → 1.1.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.
Files changed (2) hide show
  1. package/README.md +17 -7
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -65,20 +65,30 @@ ForesightManager.initialize({
65
65
 
66
66
  // Register an element to be tracked
67
67
  const myButton = document.getElementById("my-button")
68
- const unregister = ForesightManager.instance.register(
69
- myButton, // The element to track.
70
- () => {preloadData()} // Callback when user is predicted to interact with the element,
71
- 20 // Optional: "hit slop" in pixels. Overwrites defaultHitSlop
72
- )
68
+
69
+ const { isTouchDevice, unregister } = ForesightManager.instance.register({
70
+ element: myButton,
71
+ callback: () => {
72
+ console.log("prefetching")
73
+ }, // Callback when user is predicted to interact with the element,
74
+ hitSlop: 20, // Optional: "hit slop" in pixels. Overwrites defaultHitSlop
75
+ })
73
76
 
74
77
  // Later, when done with this element:
75
78
  unregister()
76
79
  ```
80
+ ## What about touch devices?
81
+ ForesightJS focuses on using mouse movement for prefetching, so you'll need your own approach for touch devices like phones and tablets. The `ForesightManager.instance.register()` method returns an `isTouchDevice` boolean that you can use to create this separate logic. You can safely call `register()` even on touch devices, as the Foresight manager will bounce touch devices to avoid unnecessary processing.
82
+
83
+ An example of what to do with touch devices can be found in the [Next.JS](https://foresightjs.com/docs/integrations/nextjs) or [React Router](https://foresightjs.com/docs/integrations/react) ForesightLink components.
84
+
85
+ ## Integrations
86
+ Since ForesightJS is framework agnostic, it can be integrated with any JavaScript framework. While I haven't yet built integrations for every framework, ready-to-use implementations for [React Router](https://foresightjs.com/docs/integrations/react) and [Next.js](https://foresightjs.com/docs/integrations/nextjs) are already available. Sharing integrations for other frameworks/packages is highly appreciated!
77
87
 
78
88
  ## Configuration
89
+ ForesightJS can be used bare-bones but also can be configured. For all configuration possibilities you can reference the [docs](https://foresightjs.com/docs/config).
79
90
 
80
- [Docs](https://foresightjs.com/docs/config)
81
91
 
82
92
  ## Debugging visualization
93
+ ForesightJS includes a [Visual Debugging](https://foresightjs.com/docs/debugging) system that helps you understand and tune how foresight is working in your application. This is particularly helpful when setting up ForesightJS for the first time or when fine-tuning for specific UI components.
83
94
 
84
- [Docs](https://foresightjs.com/docs/debugging)
package/package.json CHANGED
@@ -1,15 +1,10 @@
1
1
  {
2
2
  "name": "js.foresight",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Predicts mouse trajectory to trigger actions as users approach elements, enabling anticipatory UI updates or pre-loading. Made with vanilla javascript and usable in every framework.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
- "scripts": {
9
- "build": "tsc --build --clean && tsc",
10
- "test": "cd ./test_project && pnpm dev",
11
- "rollup": "rollup -c --bundleConfigAsCjs"
12
- },
13
8
  "exports": {
14
9
  ".": {
15
10
  "types": "./dist/index.d.ts",
@@ -51,5 +46,10 @@
51
46
  "rollup-plugin-peer-deps-external": "^2.2.4",
52
47
  "rollup-plugin-postcss": "^4.0.2",
53
48
  "tslib": "^2.8.1"
49
+ },
50
+ "scripts": {
51
+ "build": "tsc --build --clean && tsc",
52
+ "test": "cd ./test_project && pnpm dev",
53
+ "rollup": "rollup -c --bundleConfigAsCjs"
54
54
  }
55
- }
55
+ }