@supermousejs/core 2.1.0 → 2.3.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 CHANGED
@@ -1,51 +1,68 @@
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
1
+ # @supermousejs/core
2
+
3
+ ## 2.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8dc8e06: cleanup and robustness pass: better case-insensitive data-\* handling, safer plugin lifecycle behavior, more reliable cursor restoration, and a more consistent reset/update flow
8
+ - 600de13: added `dataPrefix` option for customizable data attribute handling, added a `start()` public method to manually start the raf loop and enhanced supermouse's resistance to bugs
9
+
10
+ ### Patch Changes
11
+
12
+ - b72e264: Renamed `setCursor` to `setNativeCursor` for simplicity and removed redundant checks on `ignoreOnNative`
13
+
14
+ ## 2.2.0
15
+
16
+ ### Minor Changes
17
+
18
+ - f6f44b2: Improved tree-shaking by consolidating subordinate files and helpers into the main module file
19
+
20
+ ## 2.1.0
21
+
22
+ ### Minor Changes
23
+
24
+ - 2590af3: - Refactored engine by removing 200 lines of redundant comments and typedocs, with appropriate re-reference to canon web docs
25
+ - Fixed a framework reactivity cache trap by moving away from WeakMap (computations are light and relatively inexpensive)
26
+ - Fixed double crashing by implementing a `try {} catch {}` safety net for plugin installation
27
+ - Fixed the Input layer not refreshing plugin states (particularly on hover) when DOM content is detached in reactive frameworks with `Node.isConnected`
28
+
29
+ ### Patch Changes
30
+
31
+ - 6d70c18: remove legacy package and update supermouse domain in readme
32
+ - 14fb5b6: Updated tsconfig to be reference-compliant with core, utils and zoetrope when required
33
+
34
+ ## 2.0.5
35
+
36
+ ### Patch Changes
37
+
38
+ - 67f771b: Add relevant npm metadata to package.json file
39
+
40
+ ## 2.0.4
41
+
42
+ ### Patch Changes
43
+
44
+ - 993dc67: Updated supemousejs packages with proper author, license and url descriptors to repo
45
+
46
+ ## 2.0.3
47
+
48
+ ### Patch Changes
49
+
50
+ - Add keywords to core package
51
+
52
+ ## 2.0.2
53
+
54
+ ### Patch Changes
55
+
56
+ - ae219a0: Update READMEs with correct link to documentation
57
+
58
+ ## 2.0.1
59
+
60
+ ### Patch Changes
61
+
62
+ - Add minimal README.md files to packages
63
+
64
+ ## 2.0.0
65
+
66
+ ### Major Changes
67
+
68
+ - Initial v2.0.0 release
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.
@@ -26,21 +28,21 @@ export declare interface MousePosition {
26
28
  }
27
29
 
28
30
  export declare interface MouseState {
29
- /** The raw position of the input pointer (mouse/touch). */
31
+ /** The raw position from the latest pointer event, before smoothing is applied. */
30
32
  pointer: MousePosition;
31
- /** The target position the cursor logic wants to reach. */
33
+ /** The current goal position that the core loop is driving toward. */
32
34
  target: MousePosition;
33
35
  /** The smoothed/interpolated position used for rendering. */
34
36
  smooth: MousePosition;
35
- /** The current velocity vector of the smooth position. */
37
+ /** The current movement vector derived from the smoothed state. */
36
38
  velocity: MousePosition;
37
- /** The angle of movement in degrees. Calculated from velocity. */
39
+ /** The current movement angle in degrees, derived from velocity. */
38
40
  angle: number;
39
41
  /** Whether the pointer is currently pressed down. */
40
42
  isDown: boolean;
41
43
  /** Whether the pointer is currently hovering over a registered interactive element. */
42
44
  isHover: boolean;
43
- /** Whether the native cursor is currently forced visible by internal logic (e.g. input elements). */
45
+ /** Whether the runtime has temporarily restored the native cursor due to native-input heuristics. */
44
46
  isNative: boolean;
45
47
  /**
46
48
  * If set, this overrides all auto-detection logic.
@@ -69,11 +71,15 @@ export declare interface ShapeState {
69
71
  borderRadius: number;
70
72
  }
71
73
 
74
+ /* Excluded from this release type: Stage */
75
+
72
76
  /**
73
- * Runtime Loop of Supermouse.
77
+ * Supermouse Runtime Loop
74
78
  *
75
- * This class orchestrates the application state, manages the animation loop (`requestAnimationFrame`),
76
- * and coordinates data flow between the Input system, the Stage system, and the Plugins.
79
+ * This class orchestrates the application state, manages the animation loop,
80
+ * and coordinates data flow between the internal systems, and the plugins.
81
+ *
82
+ * @default
77
83
  */
78
84
  export declare class Supermouse {
79
85
  static readonly version: string;
@@ -125,11 +131,11 @@ export declare class Supermouse {
125
131
  */
126
132
  get container(): HTMLDivElement;
127
133
  /**
128
- * Manually override the native cursor visibility.
134
+ * Sets the native cursor visibility.
129
135
  *
130
- * @param type 'auto' (Show Native), 'none' (Hide Native), or null (Resume Auto-detection)
136
+ * @param mode
131
137
  */
132
- setCursor(type: "auto" | "none" | null): void;
138
+ setNativeCursor(mode: "hide" | "show" | "auto"): void;
133
139
  private init;
134
140
  enable(): void;
135
141
  disable(): void;
@@ -139,8 +145,13 @@ export declare class Supermouse {
139
145
  * @param plugin - The plugin object to install.
140
146
  */
141
147
  use(plugin: SupermousePlugin): this;
142
- private resetPosition;
148
+ private reset;
143
149
  private startLoop;
150
+ /**
151
+ * Starts the animation loop. This is automatically called if `autoStart` is true.
152
+ * Plugins can call this method to resume the loop if it has been stopped.
153
+ */
154
+ start(): void;
144
155
  /**
145
156
  * Manually steps the animation loop.
146
157
  *
@@ -184,20 +195,24 @@ export declare interface SupermouseOptions {
184
195
  autoDisableOnMobile?: boolean;
185
196
  /**
186
197
  * Strategy for detecting when to fallback to the native cursor.
187
- * - `true` / `'auto'`: Checks both HTML tags and CSS cursor styles (Accurate but slower).
198
+ * - `'auto'`: Checks both HTML tags and CSS cursor styles (Accurate but slower).
188
199
  * - `'tag'`: Checks only semantic tags like <input>, <textarea> (Fastest, prevents layout thrashing).
189
200
  * - `'css'`: Checks only computed CSS cursor styles (Slow, triggers reflow).
190
- * - `false`: Never fallback to native cursor.
201
+ * - `null`: Never fallback to native cursor.
202
+ *
191
203
  * @default 'auto'
192
204
  */
193
- ignoreOnNative?: boolean | NativeIgnoreStrategy;
205
+ ignoreOnNative?: NativeIgnoreStrategy | null;
194
206
  /**
195
- * Whether to hide the native cursor via global CSS injection.
207
+ * Whether to hide the native cursor via scoped CSS injection on the container.
208
+ * When enabled, the stage toggles `cursor: none` on the configured container and
209
+ * on registered hover targets.
196
210
  * @default true
197
211
  */
198
212
  hideCursor?: boolean;
199
213
  /**
200
- * Whether to hide the custom cursor when the mouse leaves the browser window.
214
+ * Whether to hide the custom cursor when the pointer leaves the browser viewport.
215
+ * When enabled the runtime clears the cursor back to an off-screen position to avoid stale hover state.
201
216
  * @default true
202
217
  */
203
218
  hideOnLeave?: boolean;
@@ -217,14 +232,24 @@ export declare interface SupermouseOptions {
217
232
  autoStart?: boolean;
218
233
  /**
219
234
  * Semantic rules mapping CSS selectors to interaction state.
235
+ * Rules are evaluated against hovered elements and merged into `state.interaction`.
236
+ * Matching data attributes on the same element are also read and can override or enrich the final object.
220
237
  * @example { 'button': { icon: 'pointer' } }
221
238
  */
222
239
  rules?: Record<string, InteractionState>;
223
240
  /**
224
241
  * Custom strategy to resolve interaction state from a hovered element.
225
- * Overrides the default data-attribute scraping.
242
+ * When provided, this callback bypasses the default `rules` + `data-[prefix]-*` scraping and
243
+ * returns the interaction payload directly for the current hover target.
226
244
  */
227
245
  resolveInteraction?: (target: HTMLElement) => InteractionState;
246
+ /**
247
+ * The prefix used for data attributes to store hover metadata.
248
+ * For example, if dataPrefix is "supermouse", then the attribute would be "data-supermouse-*".
249
+ * This allows for multiple instances of Supermouse to coexist without conflicting data attributes.
250
+ * @default "supermouse"
251
+ */
252
+ dataPrefix?: string;
228
253
  }
229
254
 
230
255
  /**
@@ -239,7 +264,7 @@ export declare interface SupermousePlugin {
239
264
  isEnabled?: boolean;
240
265
  /** Called when `app.use()` is executed. */
241
266
  install?: (instance: Supermouse) => void;
242
- /** Called on every animation frame. */
267
+ /** Called on every animation frame with the frame delta time in milliseconds. */
243
268
  update?: (instance: Supermouse, deltaTime: number) => void;
244
269
  /** Called when the plugin is removed or the app is destroyed. */
245
270
  destroy?: (instance: Supermouse) => void;
@@ -251,6 +276,7 @@ export declare interface SupermousePlugin {
251
276
 
252
277
  /**
253
278
  * Allows a property to be a static value or a function that returns the value based on state.
279
+ * This is primarily useful for plugin option definitions that should react to the current runtime state.
254
280
  */
255
281
  export declare type ValueOrGetter<T> = T | ((state: MouseState) => T);
256
282