@supermousejs/core 2.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -31
- package/LICENSE.md +21 -21
- package/README.md +30 -31
- package/dist/index.d.ts +8 -55
- package/dist/index.mjs +85 -146
- package/dist/index.umd.js +2 -2
- package/package.json +11 -1
- package/src/Supermouse.ts +339 -405
- package/src/index.ts +2 -2
- package/src/systems/Input.ts +231 -262
- package/src/systems/Stage.ts +126 -156
- package/src/systems/index.ts +2 -2
- package/src/types.ts +168 -169
- package/src/utils/math.ts +11 -20
- package/tsconfig.json +7 -14
- package/tsconfig.tsbuildinfo +1 -0
- package/vite.config.ts +32 -32
package/CHANGELOG.md
CHANGED
|
@@ -1,31 +1,51 @@
|
|
|
1
|
-
# @supermousejs/core
|
|
2
|
-
|
|
3
|
-
## 2.0
|
|
4
|
-
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
# @supermousejs/core
|
|
2
|
+
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 2590af3: - Refactored engine by removing 200 lines of redundant comments and typedocs, with appropriate re-reference to canon web docs
|
|
8
|
+
- Fixed a framework reactivity cache trap by moving away from WeakMap (computations are light and relatively inexpensive)
|
|
9
|
+
- Fixed double crashing by implementing a `try {} catch {}` safety net for plugin installation
|
|
10
|
+
- Fixed the Input layer not refreshing plugin states (particularly on hover) when DOM content is detached in reactive frameworks with `Node.isConnected`
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 6d70c18: remove legacy package and update supermouse domain in readme
|
|
15
|
+
- 14fb5b6: Updated tsconfig to be reference-compliant with core, utils and zoetrope when required
|
|
16
|
+
|
|
17
|
+
## 2.0.5
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 67f771b: Add relevant npm metadata to package.json file
|
|
22
|
+
|
|
23
|
+
## 2.0.4
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 993dc67: Updated supemousejs packages with proper author, license and url descriptors to repo
|
|
28
|
+
|
|
29
|
+
## 2.0.3
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Add keywords to core package
|
|
34
|
+
|
|
35
|
+
## 2.0.2
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- ae219a0: Update READMEs with correct link to documentation
|
|
40
|
+
|
|
41
|
+
## 2.0.1
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- Add minimal README.md files to packages
|
|
46
|
+
|
|
47
|
+
## 2.0.0
|
|
48
|
+
|
|
49
|
+
### Major Changes
|
|
50
|
+
|
|
51
|
+
- Initial v2.0.0 release
|
package/LICENSE.md
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Sijibomi Olusunmbola
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sijibomi Olusunmbola
|
|
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,31 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
Full documentation and interactive playground available at [supermouse](https://supermouse.vercel.app) or [check out the repo](https://github.com/Whitestar14/supermouse-js).
|
|
1
|
+
# @supermousejs/core
|
|
2
|
+
|
|
3
|
+
The high-performance runtime engine for **Supermouse v2**.
|
|
4
|
+
|
|
5
|
+
It separates cursor **intent** (input, physics, logic) from **rendering** (visuals), exposing a deterministic plugin pipeline.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @supermousejs/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Basic Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Supermouse } from "@supermousejs/core";
|
|
17
|
+
// Import visuals separately to keep bundle size low
|
|
18
|
+
import { Dot } from "@supermousejs/dot";
|
|
19
|
+
|
|
20
|
+
const app = new Supermouse({
|
|
21
|
+
smoothness: 0.15, // 0-1 (Physics damping)
|
|
22
|
+
hideCursor: true // Auto-hide native cursor
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
app.use(Dot({ size: 8, color: "#f59e0b" }));
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Documentation
|
|
29
|
+
|
|
30
|
+
Full documentation and interactive playground available at [supermouse](https://supermouse.js.org) or [check out the repo](https://github.com/Whitestar14/supermouse-js).
|
package/dist/index.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export declare interface MouseState {
|
|
|
48
48
|
* 'none' = Force Custom Cursor (Hide Native)
|
|
49
49
|
* null = Let the Core decide based on isNative/isHover
|
|
50
50
|
*/
|
|
51
|
-
forcedCursor:
|
|
51
|
+
forcedCursor: "auto" | "none" | null;
|
|
52
52
|
/** The DOM element currently being hovered, if any. */
|
|
53
53
|
hoverTarget: HTMLElement | null;
|
|
54
54
|
/** Whether the user has `prefers-reduced-motion` enabled. */
|
|
@@ -61,7 +61,7 @@ export declare interface MouseState {
|
|
|
61
61
|
interaction: InteractionState;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export declare type NativeIgnoreStrategy =
|
|
64
|
+
export declare type NativeIgnoreStrategy = "auto" | "tag" | "css";
|
|
65
65
|
|
|
66
66
|
export declare interface ShapeState {
|
|
67
67
|
width: number;
|
|
@@ -70,41 +70,22 @@ export declare interface ShapeState {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
73
|
+
* Runtime Loop of Supermouse.
|
|
74
74
|
*
|
|
75
75
|
* This class orchestrates the application state, manages the animation loop (`requestAnimationFrame`),
|
|
76
76
|
* and coordinates data flow between the Input system, the Stage system, and the Plugins.
|
|
77
|
-
*
|
|
78
|
-
* ## Architecture
|
|
79
|
-
* 1. **Input System**: Captures raw events and writes to `state.pointer`.
|
|
80
|
-
* 2. **Logic Plugins**: (Priority < 0) Read `pointer`, modify `state.target` (e.g. Magnetic, Stick).
|
|
81
|
-
* 3. **Physics**: Core interpolates `state.smooth` towards `state.target`.
|
|
82
|
-
* 4. **Visual Plugins**: (Priority >= 0) Read `state.smooth`, update DOM transforms.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```ts
|
|
86
|
-
* const app = new Supermouse({ smoothness: 0.15 });
|
|
87
|
-
* app.use(Dot({ color: 'red' }));
|
|
88
|
-
* ```
|
|
89
77
|
*/
|
|
90
78
|
export declare class Supermouse {
|
|
91
|
-
/** The current version of Supermouse.js */
|
|
92
79
|
static readonly version: string;
|
|
93
80
|
readonly version: string;
|
|
94
|
-
/**
|
|
95
|
-
* The Single Source of Truth.
|
|
96
|
-
*
|
|
97
|
-
* This object is shared by reference. `Input` writes to it; `Supermouse` physics reads/writes to it;
|
|
98
|
-
* Plugins read/write to it.
|
|
99
|
-
*/
|
|
100
81
|
state: MouseState;
|
|
101
82
|
/**
|
|
102
83
|
* Configuration options.
|
|
103
84
|
*/
|
|
104
85
|
options: SupermouseOptions;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
86
|
+
private plugins;
|
|
87
|
+
private stage;
|
|
88
|
+
private input;
|
|
108
89
|
private rafId;
|
|
109
90
|
private lastTime;
|
|
110
91
|
private isRunning;
|
|
@@ -138,16 +119,6 @@ export declare class Supermouse {
|
|
|
138
119
|
* Toggles the enabled state of a plugin.
|
|
139
120
|
*/
|
|
140
121
|
togglePlugin(name: string): void;
|
|
141
|
-
/**
|
|
142
|
-
* Registers a CSS selector as an "Interactive Target".
|
|
143
|
-
*
|
|
144
|
-
* When the mouse hovers over an element matching this selector:
|
|
145
|
-
* 1. `state.isHover` becomes `true`.
|
|
146
|
-
* 2. `state.hoverTarget` is set to the element.
|
|
147
|
-
* 3. The `Stage` system injects CSS to hide the native cursor for this element (if `hideCursor: true`).
|
|
148
|
-
*
|
|
149
|
-
* @param selector - A valid CSS selector string (e.g., `.my-button`, `[data-trigger]`).
|
|
150
|
-
*/
|
|
151
122
|
registerHoverTarget(selector: string): void;
|
|
152
123
|
/**
|
|
153
124
|
* The fixed container element where plugins should append their DOM nodes.
|
|
@@ -155,30 +126,16 @@ export declare class Supermouse {
|
|
|
155
126
|
get container(): HTMLDivElement;
|
|
156
127
|
/**
|
|
157
128
|
* Manually override the native cursor visibility.
|
|
158
|
-
* Useful for drag-and-drop operations, modals, or special UI states.
|
|
159
129
|
*
|
|
160
130
|
* @param type 'auto' (Show Native), 'none' (Hide Native), or null (Resume Auto-detection)
|
|
161
131
|
*/
|
|
162
|
-
setCursor(type:
|
|
132
|
+
setCursor(type: "auto" | "none" | null): void;
|
|
163
133
|
private init;
|
|
164
|
-
/**
|
|
165
|
-
* Starts the update loop and enables input listeners.
|
|
166
|
-
* Hides the native cursor if configured.
|
|
167
|
-
*/
|
|
168
134
|
enable(): void;
|
|
169
|
-
/**
|
|
170
|
-
* Stops the update loop, disables listeners, and restores the native cursor.
|
|
171
|
-
* Resets internal state positions to off-screen.
|
|
172
|
-
*/
|
|
173
135
|
disable(): void;
|
|
174
136
|
/**
|
|
175
137
|
* Registers a new plugin.
|
|
176
138
|
*
|
|
177
|
-
* @remarks
|
|
178
|
-
* Plugins are sorted by `priority` immediately after registration.
|
|
179
|
-
* - **Negative Priority (< 0)**: Logic plugins (run before physics).
|
|
180
|
-
* - **Positive Priority (>= 0)**: Visual plugins (run after physics).
|
|
181
|
-
*
|
|
182
139
|
* @param plugin - The plugin object to install.
|
|
183
140
|
*/
|
|
184
141
|
use(plugin: SupermousePlugin): this;
|
|
@@ -186,21 +143,17 @@ export declare class Supermouse {
|
|
|
186
143
|
private startLoop;
|
|
187
144
|
/**
|
|
188
145
|
* Manually steps the animation loop.
|
|
189
|
-
* Useful when integrating with external game loops (e.g., Three.js, PixiJS) where
|
|
190
|
-
* you want to disable the internal RAF and drive `Supermouse` from your own ticker.
|
|
191
146
|
*
|
|
192
147
|
* @param time Current timestamp in milliseconds.
|
|
193
148
|
*/
|
|
194
149
|
step(time: number): void;
|
|
195
150
|
private runPluginSafe;
|
|
196
151
|
/**
|
|
197
|
-
* The Heartbeat.
|
|
198
152
|
* Runs on every animation frame.
|
|
199
153
|
*/
|
|
200
154
|
private tick;
|
|
201
155
|
/**
|
|
202
156
|
* Destroys the instance.
|
|
203
|
-
* Stops the loop, removes all DOM elements, removes all event listeners, and calls destroy on all plugins.
|
|
204
157
|
*/
|
|
205
158
|
destroy(): void;
|
|
206
159
|
}
|
|
@@ -297,7 +250,7 @@ export declare interface SupermousePlugin {
|
|
|
297
250
|
}
|
|
298
251
|
|
|
299
252
|
/**
|
|
300
|
-
*
|
|
253
|
+
* Allows a property to be a static value or a function that returns the value based on state.
|
|
301
254
|
*/
|
|
302
255
|
export declare type ValueOrGetter<T> = T | ((state: MouseState) => T);
|
|
303
256
|
|