@supermousejs/core 2.0.5 → 2.2.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 +20 -0
- package/LICENSE.md +21 -21
- package/README.md +30 -31
- package/dist/index.d.ts +16 -56
- package/dist/index.mjs +181 -234
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
- package/src/Supermouse.ts +708 -405
- package/src/index.ts +2 -2
- package/src/types.ts +168 -168
- package/tsconfig.json +9 -16
- package/tsconfig.tsbuildinfo +1 -0
- package/vite.config.ts +32 -32
- package/src/systems/Input.ts +0 -262
- package/src/systems/Stage.ts +0 -155
- package/src/systems/index.ts +0 -2
- package/src/utils/math.ts +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @supermousejs/core
|
|
2
2
|
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f6f44b2: Improved tree-shaking by consolidating subordinate files and helpers into the main module file
|
|
8
|
+
|
|
9
|
+
## 2.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 2590af3: - Refactored engine by removing 200 lines of redundant comments and typedocs, with appropriate re-reference to canon web docs
|
|
14
|
+
- Fixed a framework reactivity cache trap by moving away from WeakMap (computations are light and relatively inexpensive)
|
|
15
|
+
- Fixed double crashing by implementing a `try {} catch {}` safety net for plugin installation
|
|
16
|
+
- Fixed the Input layer not refreshing plugin states (particularly on hover) when DOM content is detached in reactive frameworks with `Node.isConnected`
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 6d70c18: remove legacy package and update supermouse domain in readme
|
|
21
|
+
- 14fb5b6: Updated tsconfig to be reference-compliant with core, utils and zoetrope when required
|
|
22
|
+
|
|
3
23
|
## 2.0.5
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
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
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const DEFAULT_HOVER_SELECTORS: string[];
|
|
2
2
|
|
|
3
|
+
/* Excluded from this release type: Input */
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* The Interface for interaction state.
|
|
5
7
|
* Plugins should use Module Augmentation to add their specific properties to this interface.
|
|
@@ -48,7 +50,7 @@ export declare interface MouseState {
|
|
|
48
50
|
* 'none' = Force Custom Cursor (Hide Native)
|
|
49
51
|
* null = Let the Core decide based on isNative/isHover
|
|
50
52
|
*/
|
|
51
|
-
forcedCursor:
|
|
53
|
+
forcedCursor: "auto" | "none" | null;
|
|
52
54
|
/** The DOM element currently being hovered, if any. */
|
|
53
55
|
hoverTarget: HTMLElement | null;
|
|
54
56
|
/** Whether the user has `prefers-reduced-motion` enabled. */
|
|
@@ -61,7 +63,7 @@ export declare interface MouseState {
|
|
|
61
63
|
interaction: InteractionState;
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
export declare type NativeIgnoreStrategy =
|
|
66
|
+
export declare type NativeIgnoreStrategy = "auto" | "tag" | "css";
|
|
65
67
|
|
|
66
68
|
export declare interface ShapeState {
|
|
67
69
|
width: number;
|
|
@@ -69,42 +71,27 @@ export declare interface ShapeState {
|
|
|
69
71
|
borderRadius: number;
|
|
70
72
|
}
|
|
71
73
|
|
|
74
|
+
/* Excluded from this release type: Stage */
|
|
75
|
+
|
|
72
76
|
/**
|
|
73
|
-
*
|
|
77
|
+
* Supermouse Runtime Loop
|
|
74
78
|
*
|
|
75
|
-
* This class orchestrates the application state, manages the animation loop
|
|
76
|
-
* and coordinates data flow between the
|
|
79
|
+
* This class orchestrates the application state, manages the animation loop,
|
|
80
|
+
* and coordinates data flow between the internal systems, and the plugins.
|
|
77
81
|
*
|
|
78
|
-
*
|
|
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
|
-
* ```
|
|
82
|
+
* @default
|
|
89
83
|
*/
|
|
90
84
|
export declare class Supermouse {
|
|
91
|
-
/** The current version of Supermouse.js */
|
|
92
85
|
static readonly version: string;
|
|
93
86
|
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
87
|
state: MouseState;
|
|
101
88
|
/**
|
|
102
89
|
* Configuration options.
|
|
103
90
|
*/
|
|
104
91
|
options: SupermouseOptions;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
92
|
+
private plugins;
|
|
93
|
+
private stage;
|
|
94
|
+
private input;
|
|
108
95
|
private rafId;
|
|
109
96
|
private lastTime;
|
|
110
97
|
private isRunning;
|
|
@@ -138,16 +125,6 @@ export declare class Supermouse {
|
|
|
138
125
|
* Toggles the enabled state of a plugin.
|
|
139
126
|
*/
|
|
140
127
|
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
128
|
registerHoverTarget(selector: string): void;
|
|
152
129
|
/**
|
|
153
130
|
* The fixed container element where plugins should append their DOM nodes.
|
|
@@ -155,52 +132,35 @@ export declare class Supermouse {
|
|
|
155
132
|
get container(): HTMLDivElement;
|
|
156
133
|
/**
|
|
157
134
|
* Manually override the native cursor visibility.
|
|
158
|
-
* Useful for drag-and-drop operations, modals, or special UI states.
|
|
159
135
|
*
|
|
160
136
|
* @param type 'auto' (Show Native), 'none' (Hide Native), or null (Resume Auto-detection)
|
|
161
137
|
*/
|
|
162
|
-
setCursor(type:
|
|
138
|
+
setCursor(type: "auto" | "none" | null): void;
|
|
163
139
|
private init;
|
|
164
|
-
/**
|
|
165
|
-
* Starts the update loop and enables input listeners.
|
|
166
|
-
* Hides the native cursor if configured.
|
|
167
|
-
*/
|
|
168
140
|
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
141
|
disable(): void;
|
|
174
142
|
/**
|
|
175
143
|
* Registers a new plugin.
|
|
176
144
|
*
|
|
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
145
|
* @param plugin - The plugin object to install.
|
|
183
146
|
*/
|
|
184
147
|
use(plugin: SupermousePlugin): this;
|
|
148
|
+
private resetCoords;
|
|
185
149
|
private resetPosition;
|
|
186
150
|
private startLoop;
|
|
187
151
|
/**
|
|
188
152
|
* 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
153
|
*
|
|
192
154
|
* @param time Current timestamp in milliseconds.
|
|
193
155
|
*/
|
|
194
156
|
step(time: number): void;
|
|
195
157
|
private runPluginSafe;
|
|
196
158
|
/**
|
|
197
|
-
* The Heartbeat.
|
|
198
159
|
* Runs on every animation frame.
|
|
199
160
|
*/
|
|
200
161
|
private tick;
|
|
201
162
|
/**
|
|
202
163
|
* Destroys the instance.
|
|
203
|
-
* Stops the loop, removes all DOM elements, removes all event listeners, and calls destroy on all plugins.
|
|
204
164
|
*/
|
|
205
165
|
destroy(): void;
|
|
206
166
|
}
|
|
@@ -297,7 +257,7 @@ export declare interface SupermousePlugin {
|
|
|
297
257
|
}
|
|
298
258
|
|
|
299
259
|
/**
|
|
300
|
-
*
|
|
260
|
+
* Allows a property to be a static value or a function that returns the value based on state.
|
|
301
261
|
*/
|
|
302
262
|
export declare type ValueOrGetter<T> = T | ((state: MouseState) => T);
|
|
303
263
|
|