@supermousejs/magnetic 2.1.0 → 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 +82 -59
- package/LICENSE.md +21 -21
- package/README.md +36 -34
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +26 -21
- package/dist/index.umd.js +1 -1
- package/meta.json +25 -14
- package/package.json +13 -4
- package/src/index.ts +59 -57
- package/tsconfig.json +3 -17
- package/vite.config.ts +23 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,59 +1,82 @@
|
|
|
1
|
-
# @supermousejs/magnetic
|
|
2
|
-
|
|
3
|
-
## 2.
|
|
4
|
-
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- Updated dependencies [
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
# @supermousejs/magnetic
|
|
2
|
+
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6d70c18: remove legacy package and update supermouse domain in readme
|
|
8
|
+
- 14fb5b6: Updated tsconfig to be reference-compliant with core, utils and zoetrope when required
|
|
9
|
+
- Updated dependencies [6d70c18]
|
|
10
|
+
- Updated dependencies [2590af3]
|
|
11
|
+
- Updated dependencies [14fb5b6]
|
|
12
|
+
- Updated dependencies [9fe1a7b]
|
|
13
|
+
- Updated dependencies [9fa6ece]
|
|
14
|
+
- @supermousejs/core@2.1.0
|
|
15
|
+
- @supermousejs/utils@2.2.0
|
|
16
|
+
|
|
17
|
+
## 2.1.1
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 67f771b: Add relevant npm metadata to package.json file
|
|
22
|
+
- Updated dependencies [67f771b]
|
|
23
|
+
- @supermousejs/utils@2.1.1
|
|
24
|
+
- @supermousejs/core@2.0.5
|
|
25
|
+
|
|
26
|
+
## 2.1.0
|
|
27
|
+
|
|
28
|
+
### Minor Changes
|
|
29
|
+
|
|
30
|
+
- 0a1652d: fixed build architecture and updated plugin metadata
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Updated dependencies [0a1652d]
|
|
35
|
+
- @supermousejs/utils@2.1.0
|
|
36
|
+
|
|
37
|
+
## 2.0.4
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- 993dc67: Updated supemousejs packages with proper author, license and url descriptors to repo
|
|
42
|
+
- Updated dependencies [993dc67]
|
|
43
|
+
- @supermousejs/utils@2.0.4
|
|
44
|
+
- @supermousejs/core@2.0.4
|
|
45
|
+
|
|
46
|
+
## 2.0.3
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- Updated dependencies
|
|
51
|
+
- @supermousejs/core@2.0.3
|
|
52
|
+
- @supermousejs/utils@2.0.3
|
|
53
|
+
|
|
54
|
+
## 2.0.2
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- ae219a0: Update READMEs with correct link to documentation
|
|
59
|
+
- Updated dependencies [ae219a0]
|
|
60
|
+
- @supermousejs/utils@2.0.2
|
|
61
|
+
- @supermousejs/core@2.0.2
|
|
62
|
+
|
|
63
|
+
## 2.0.1
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- Add minimal README.md files to packages
|
|
68
|
+
- Updated dependencies
|
|
69
|
+
- @supermousejs/utils@2.0.1
|
|
70
|
+
- @supermousejs/core@2.0.1
|
|
71
|
+
|
|
72
|
+
## 2.0.0
|
|
73
|
+
|
|
74
|
+
### Major Changes
|
|
75
|
+
|
|
76
|
+
- Initial v2.0.0 release
|
|
77
|
+
|
|
78
|
+
### Patch Changes
|
|
79
|
+
|
|
80
|
+
- Updated dependencies
|
|
81
|
+
- @supermousejs/utils@2.0.0
|
|
82
|
+
- @supermousejs/core@2.0.0
|
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,34 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
# @supermousejs/magnetic
|
|
2
|
+
|
|
3
|
+
A **Logic Plugin** that attracts the cursor to interactive elements.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @supermousejs/magnetic
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Supermouse } from "@supermousejs/core";
|
|
15
|
+
import { Magnetic } from "@supermousejs/magnetic";
|
|
16
|
+
|
|
17
|
+
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
|
+
);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**HTML:**
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<button data-supermouse-magnetic="true">Magnetic Button</button>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Documentation
|
|
35
|
+
|
|
36
|
+
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,5 @@
|
|
|
1
|
-
import { SupermousePlugin } from '../../core/src
|
|
2
|
-
import { ValueOrGetter } from '../../core/src
|
|
1
|
+
import { SupermousePlugin } from '../../core/src';
|
|
2
|
+
import { ValueOrGetter } from '../../core/src';
|
|
3
3
|
|
|
4
4
|
export declare const Magnetic: (options?: MagneticOptions) => SupermousePlugin;
|
|
5
5
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
import { normalize as u, definePlugin as h, dom as v, math as o } from "@supermousejs/utils";
|
|
2
2
|
const b = (i = {}) => {
|
|
3
|
-
let a = null
|
|
3
|
+
let a = null;
|
|
4
|
+
const n = { x: 0, y: 0 };
|
|
5
|
+
let s = !1;
|
|
4
6
|
const f = u(i.attraction, 0.3), y = u(i.distance, 100);
|
|
5
|
-
return h(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
t
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
return h(
|
|
8
|
+
{
|
|
9
|
+
name: "magnetic",
|
|
10
|
+
priority: -10,
|
|
11
|
+
install(t) {
|
|
12
|
+
t.registerHoverTarget("[data-supermouse-magnetic]");
|
|
13
|
+
},
|
|
14
|
+
update(t) {
|
|
15
|
+
const c = t.state.hoverTarget, r = t.state.interaction.magnetic, g = r === !0 || r === "true" || typeof r == "number" && r > 0;
|
|
16
|
+
if (g && c !== a) {
|
|
17
|
+
a = c;
|
|
18
|
+
const e = v.projectRect(c, t.container);
|
|
19
|
+
n.x = e.left + e.width / 2, n.y = e.top + e.height / 2, s = !0;
|
|
20
|
+
} else !g && a && (a = null, s = !1);
|
|
21
|
+
if (s && a) {
|
|
22
|
+
const { x: e, y: l } = t.state.pointer, d = o.dist(e, l, n.x, n.y), x = y(t.state);
|
|
23
|
+
if (d < x) {
|
|
24
|
+
const m = typeof r == "number" ? r : f(t.state);
|
|
25
|
+
t.state.target.x = o.lerp(e, n.x, m), t.state.target.y = o.lerp(l, n.y, m);
|
|
26
|
+
}
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
|
-
}
|
|
26
|
-
|
|
29
|
+
},
|
|
30
|
+
i
|
|
31
|
+
);
|
|
27
32
|
};
|
|
28
33
|
export {
|
|
29
34
|
b as Magnetic
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(n,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("@supermousejs/utils")):typeof define=="function"&&define.amd?define(["exports","@supermousejs/utils"],e):(n=typeof globalThis<"u"?globalThis:n||self,e(n.SupermouseMagnetic={},n.SupermouseUtils))})(this,(function(n,e){"use strict";const
|
|
1
|
+
(function(n,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("@supermousejs/utils")):typeof define=="function"&&define.amd?define(["exports","@supermousejs/utils"],e):(n=typeof globalThis<"u"?globalThis:n||self,e(n.SupermouseMagnetic={},n.SupermouseUtils))})(this,(function(n,e){"use strict";const d=(a={})=>{let o=null;const r={x:0,y:0};let c=!1;const l=e.normalize(a.attraction,.3),y=e.normalize(a.distance,100);return e.definePlugin({name:"magnetic",priority:-10,install(t){t.registerHoverTarget("[data-supermouse-magnetic]")},update(t){const u=t.state.hoverTarget,s=t.state.interaction.magnetic,f=s===!0||s==="true"||typeof s=="number"&&s>0;if(f&&u!==o){o=u;const i=e.dom.projectRect(u,t.container);r.x=i.left+i.width/2,r.y=i.top+i.height/2,c=!0}else!f&&o&&(o=null,c=!1);if(c&&o){const{x:i,y:g}=t.state.pointer,h=e.math.dist(i,g,r.x,r.y),x=y(t.state);if(h<x){const m=typeof s=="number"?s:l(t.state);t.state.target.x=e.math.lerp(i,r.x,m),t.state.target.y=e.math.lerp(g,r.y,m)}}}},a)};n.Magnetic=d,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
|
package/meta.json
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supermousejs/magnetic",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"main": "dist/index.umd.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,14 +8,23 @@
|
|
|
8
8
|
"url": "https://github.com/Whitestar14/supermouse-js",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@supermousejs/utils": "2.
|
|
11
|
+
"@supermousejs/utils": "2.2.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@supermousejs/core": "2.0
|
|
14
|
+
"@supermousejs/core": "2.1.0"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@supermousejs/core": "2.0
|
|
17
|
+
"@supermousejs/core": "2.1.0"
|
|
18
18
|
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/Whitestar14/supermouse-js.git",
|
|
22
|
+
"directory": "packages/core"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/Whitestar14/supermouse-js/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/Whitestar14/supermouse-js/tree/main/packages/magnetic#readme",
|
|
19
28
|
"exports": {
|
|
20
29
|
".": {
|
|
21
30
|
"types": "./dist/index.d.ts",
|
package/src/index.ts
CHANGED
|
@@ -1,57 +1,59 @@
|
|
|
1
|
-
import type { ValueOrGetter } from
|
|
2
|
-
import { definePlugin, normalize, math, dom } from
|
|
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
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
app
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "../../tsconfig.
|
|
3
|
-
"include": [
|
|
4
|
-
|
|
5
|
-
],
|
|
6
|
-
"compilerOptions": {
|
|
7
|
-
"outDir": "dist",
|
|
8
|
-
"baseUrl": ".",
|
|
9
|
-
"paths": {
|
|
10
|
-
"@supermousejs/core": [
|
|
11
|
-
"../core/src/index.ts"
|
|
12
|
-
],
|
|
13
|
-
"@supermousejs/utils": [
|
|
14
|
-
"../utils/src/index.ts"
|
|
15
|
-
]
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
2
|
+
"extends": "../../tsconfig.plugin.json",
|
|
3
|
+
"include": ["src"]
|
|
4
|
+
}
|
package/vite.config.ts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import { defineConfig } from
|
|
2
|
-
import dts from
|
|
3
|
-
import path from
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
build: {
|
|
7
|
-
lib: {
|
|
8
|
-
entry: path.resolve(__dirname,
|
|
9
|
-
name:
|
|
10
|
-
fileName: (format) => format ===
|
|
11
|
-
},
|
|
12
|
-
rollupOptions: {
|
|
13
|
-
external: [
|
|
14
|
-
output: {
|
|
15
|
-
globals: {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})
|
|
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
|
+
});
|