@supermousejs/magnetic 2.3.0 → 2.4.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/README.md +12 -15
- package/package.json +9 -4
- package/CHANGELOG.md +0 -90
- package/meta.json +0 -25
- package/src/index.ts +0 -59
- package/tsconfig.json +0 -4
- package/vite.config.ts +0 -23
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @supermousejs/magnetic
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Attracts the cursor to interactive elements using physics-based magnetism.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,28 +8,25 @@ A **Logic Plugin** that attracts the cursor to interactive elements.
|
|
|
8
8
|
pnpm add @supermousejs/magnetic
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Magnetic
|
|
12
|
+
|
|
13
|
+
Attracts the cursor to interactive elements using physics-based magnetism.
|
|
14
|
+
|
|
15
|
+
### Usage
|
|
12
16
|
|
|
13
17
|
```ts
|
|
14
18
|
import { Supermouse } from "@supermousejs/core";
|
|
15
19
|
import { Magnetic } from "@supermousejs/magnetic";
|
|
16
|
-
|
|
17
20
|
const app = new Supermouse();
|
|
18
|
-
|
|
19
|
-
// Priority is handled automatically (-10)
|
|
20
|
-
app.use(
|
|
21
|
-
Magnetic({
|
|
22
|
-
attraction: 0.3, // Strength (0-1)
|
|
23
|
-
distance: 100 // Capture radius in px
|
|
24
|
-
})
|
|
25
|
-
);
|
|
21
|
+
app.use(Magnetic({ attraction: 0.4, distance: 100 }));
|
|
26
22
|
```
|
|
27
23
|
|
|
28
|
-
|
|
24
|
+
### Options
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
| Name | Type | Default | Description |
|
|
27
|
+
| --- | --- | --- | --- |
|
|
28
|
+
| attraction | number | 0.3 | Strength of the pull (0-1). |
|
|
29
|
+
| distance | number | 100 | Radius in pixels where attraction begins. |
|
|
33
30
|
|
|
34
31
|
## Documentation
|
|
35
32
|
|
package/package.json
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supermousejs/magnetic",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"main": "dist/index.umd.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"description": "Attracts the cursor to interactive elements using physics-based magnetism.",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
7
12
|
"author": "O.S David",
|
|
8
13
|
"url": "https://github.com/Whitestar14/supermouse-js",
|
|
9
14
|
"license": "MIT",
|
|
10
15
|
"dependencies": {
|
|
11
|
-
"@supermousejs/utils": "2.
|
|
16
|
+
"@supermousejs/utils": "2.4.0"
|
|
12
17
|
},
|
|
13
18
|
"devDependencies": {
|
|
14
|
-
"@supermousejs/core": "2.
|
|
19
|
+
"@supermousejs/core": "2.4.0"
|
|
15
20
|
},
|
|
16
21
|
"peerDependencies": {
|
|
17
|
-
"@supermousejs/core": "2.
|
|
22
|
+
"@supermousejs/core": "2.4.0"
|
|
18
23
|
},
|
|
19
24
|
"repository": {
|
|
20
25
|
"type": "git",
|
package/CHANGELOG.md
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
# @supermousejs/magnetic
|
|
2
|
-
|
|
3
|
-
## 2.3.0
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- Updated dependencies [f6f44b2]
|
|
8
|
-
- @supermousejs/core@2.2.0
|
|
9
|
-
- @supermousejs/utils@2.3.0
|
|
10
|
-
|
|
11
|
-
## 2.2.0
|
|
12
|
-
|
|
13
|
-
### Patch Changes
|
|
14
|
-
|
|
15
|
-
- 6d70c18: remove legacy package and update supermouse domain in readme
|
|
16
|
-
- 14fb5b6: Updated tsconfig to be reference-compliant with core, utils and zoetrope when required
|
|
17
|
-
- Updated dependencies [6d70c18]
|
|
18
|
-
- Updated dependencies [2590af3]
|
|
19
|
-
- Updated dependencies [14fb5b6]
|
|
20
|
-
- Updated dependencies [9fe1a7b]
|
|
21
|
-
- Updated dependencies [9fa6ece]
|
|
22
|
-
- @supermousejs/core@2.1.0
|
|
23
|
-
- @supermousejs/utils@2.2.0
|
|
24
|
-
|
|
25
|
-
## 2.1.1
|
|
26
|
-
|
|
27
|
-
### Patch Changes
|
|
28
|
-
|
|
29
|
-
- 67f771b: Add relevant npm metadata to package.json file
|
|
30
|
-
- Updated dependencies [67f771b]
|
|
31
|
-
- @supermousejs/utils@2.1.1
|
|
32
|
-
- @supermousejs/core@2.0.5
|
|
33
|
-
|
|
34
|
-
## 2.1.0
|
|
35
|
-
|
|
36
|
-
### Minor Changes
|
|
37
|
-
|
|
38
|
-
- 0a1652d: fixed build architecture and updated plugin metadata
|
|
39
|
-
|
|
40
|
-
### Patch Changes
|
|
41
|
-
|
|
42
|
-
- Updated dependencies [0a1652d]
|
|
43
|
-
- @supermousejs/utils@2.1.0
|
|
44
|
-
|
|
45
|
-
## 2.0.4
|
|
46
|
-
|
|
47
|
-
### Patch Changes
|
|
48
|
-
|
|
49
|
-
- 993dc67: Updated supemousejs packages with proper author, license and url descriptors to repo
|
|
50
|
-
- Updated dependencies [993dc67]
|
|
51
|
-
- @supermousejs/utils@2.0.4
|
|
52
|
-
- @supermousejs/core@2.0.4
|
|
53
|
-
|
|
54
|
-
## 2.0.3
|
|
55
|
-
|
|
56
|
-
### Patch Changes
|
|
57
|
-
|
|
58
|
-
- Updated dependencies
|
|
59
|
-
- @supermousejs/core@2.0.3
|
|
60
|
-
- @supermousejs/utils@2.0.3
|
|
61
|
-
|
|
62
|
-
## 2.0.2
|
|
63
|
-
|
|
64
|
-
### Patch Changes
|
|
65
|
-
|
|
66
|
-
- ae219a0: Update READMEs with correct link to documentation
|
|
67
|
-
- Updated dependencies [ae219a0]
|
|
68
|
-
- @supermousejs/utils@2.0.2
|
|
69
|
-
- @supermousejs/core@2.0.2
|
|
70
|
-
|
|
71
|
-
## 2.0.1
|
|
72
|
-
|
|
73
|
-
### Patch Changes
|
|
74
|
-
|
|
75
|
-
- Add minimal README.md files to packages
|
|
76
|
-
- Updated dependencies
|
|
77
|
-
- @supermousejs/utils@2.0.1
|
|
78
|
-
- @supermousejs/core@2.0.1
|
|
79
|
-
|
|
80
|
-
## 2.0.0
|
|
81
|
-
|
|
82
|
-
### Major Changes
|
|
83
|
-
|
|
84
|
-
- Initial v2.0.0 release
|
|
85
|
-
|
|
86
|
-
### Patch Changes
|
|
87
|
-
|
|
88
|
-
- Updated dependencies
|
|
89
|
-
- @supermousejs/utils@2.0.0
|
|
90
|
-
- @supermousejs/core@2.0.0
|
package/meta.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": "magnetic",
|
|
3
|
-
"name": "Magnetic",
|
|
4
|
-
"package": "@supermousejs/magnetic",
|
|
5
|
-
"description": "Attracts the cursor to interactive elements using physics-based magnetism.",
|
|
6
|
-
"code": "app.use(Magnetic({ attraction: 0.4, distance: 100 }));",
|
|
7
|
-
"recipeId": "magnetic-button",
|
|
8
|
-
"icon": "magnetic",
|
|
9
|
-
"options": [
|
|
10
|
-
{
|
|
11
|
-
"name": "attraction",
|
|
12
|
-
"type": "number",
|
|
13
|
-
"default": "0.3",
|
|
14
|
-
"description": "Strength of the pull (0-1).",
|
|
15
|
-
"reactive": true
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"name": "distance",
|
|
19
|
-
"type": "number",
|
|
20
|
-
"default": "100",
|
|
21
|
-
"description": "Radius in pixels where attraction begins.",
|
|
22
|
-
"reactive": true
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { ValueOrGetter } from "@supermousejs/core";
|
|
2
|
-
import { definePlugin, normalize, math, dom } from "@supermousejs/utils";
|
|
3
|
-
|
|
4
|
-
export interface MagneticOptions {
|
|
5
|
-
name?: string;
|
|
6
|
-
isEnabled?: boolean;
|
|
7
|
-
attraction?: ValueOrGetter<number>;
|
|
8
|
-
distance?: ValueOrGetter<number>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const Magnetic = (options: MagneticOptions = {}) => {
|
|
12
|
-
let lastTarget: HTMLElement | null = null;
|
|
13
|
-
const magnetCenter = { x: 0, y: 0 };
|
|
14
|
-
let isActive = false;
|
|
15
|
-
|
|
16
|
-
const getAttraction = normalize(options.attraction, 0.3);
|
|
17
|
-
const getDistance = normalize(options.distance, 100);
|
|
18
|
-
|
|
19
|
-
return definePlugin(
|
|
20
|
-
{
|
|
21
|
-
name: "magnetic",
|
|
22
|
-
priority: -10,
|
|
23
|
-
|
|
24
|
-
install(app) {
|
|
25
|
-
app.registerHoverTarget("[data-supermouse-magnetic]");
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
update(app) {
|
|
29
|
-
const target = app.state.hoverTarget;
|
|
30
|
-
const val = app.state.interaction.magnetic;
|
|
31
|
-
const isMagnetic = val === true || val === "true" || (typeof val === "number" && val > 0);
|
|
32
|
-
|
|
33
|
-
if (isMagnetic && target !== lastTarget) {
|
|
34
|
-
lastTarget = target!;
|
|
35
|
-
const rect = dom.projectRect(target!, app.container);
|
|
36
|
-
magnetCenter.x = rect.left + rect.width / 2;
|
|
37
|
-
magnetCenter.y = rect.top + rect.height / 2;
|
|
38
|
-
isActive = true;
|
|
39
|
-
} else if (!isMagnetic && lastTarget) {
|
|
40
|
-
lastTarget = null;
|
|
41
|
-
isActive = false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (isActive && lastTarget) {
|
|
45
|
-
const { x, y } = app.state.pointer;
|
|
46
|
-
const dist = math.dist(x, y, magnetCenter.x, magnetCenter.y);
|
|
47
|
-
const range = getDistance(app.state);
|
|
48
|
-
|
|
49
|
-
if (dist < range) {
|
|
50
|
-
const attraction = typeof val === "number" ? val : getAttraction(app.state);
|
|
51
|
-
app.state.target.x = math.lerp(x, magnetCenter.x, attraction);
|
|
52
|
-
app.state.target.y = math.lerp(y, magnetCenter.y, attraction);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
options
|
|
58
|
-
);
|
|
59
|
-
};
|
package/tsconfig.json
DELETED
package/vite.config.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "vite";
|
|
2
|
-
import dts from "vite-plugin-dts";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
build: {
|
|
7
|
-
lib: {
|
|
8
|
-
entry: path.resolve(__dirname, "src/index.ts"),
|
|
9
|
-
name: "SupermouseMagnetic",
|
|
10
|
-
fileName: (format) => (format === "es" ? "index.mjs" : "index.umd.js")
|
|
11
|
-
},
|
|
12
|
-
rollupOptions: {
|
|
13
|
-
external: ["@supermousejs/core", "@supermousejs/utils"],
|
|
14
|
-
output: {
|
|
15
|
-
globals: {
|
|
16
|
-
"@supermousejs/core": "SupermouseCore",
|
|
17
|
-
"@supermousejs/utils": "SupermouseUtils"
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
plugins: [dts({ rollupTypes: true })]
|
|
23
|
-
});
|