@supermousejs/stick 2.0.1 → 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 +37 -0
- package/README.md +4 -0
- package/package.json +11 -5
- package/src/index.ts +73 -73
- package/tsconfig.json +17 -17
- package/vite.config.ts +21 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @supermousejs/stick
|
|
2
2
|
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 0a1652d: fixed build architecture and updated plugin metadata
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [0a1652d]
|
|
12
|
+
- @supermousejs/utils@2.1.0
|
|
13
|
+
|
|
14
|
+
## 2.0.4
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 993dc67: Updated supemousejs packages with proper author, license and url descriptors to repo
|
|
19
|
+
- Updated dependencies [993dc67]
|
|
20
|
+
- @supermousejs/utils@2.0.4
|
|
21
|
+
- @supermousejs/core@2.0.4
|
|
22
|
+
|
|
23
|
+
## 2.0.3
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies
|
|
28
|
+
- @supermousejs/core@2.0.3
|
|
29
|
+
- @supermousejs/utils@2.0.3
|
|
30
|
+
|
|
31
|
+
## 2.0.2
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- ae219a0: Update READMEs with correct link to documentation
|
|
36
|
+
- Updated dependencies [ae219a0]
|
|
37
|
+
- @supermousejs/utils@2.0.2
|
|
38
|
+
- @supermousejs/core@2.0.2
|
|
39
|
+
|
|
3
40
|
## 2.0.1
|
|
4
41
|
|
|
5
42
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -27,3 +27,7 @@ app.use(Ring()); // Ring automatically detects 'stick' state and morphs
|
|
|
27
27
|
```html
|
|
28
28
|
<button data-supermouse-stick="true">Sticky Element</button>
|
|
29
29
|
```
|
|
30
|
+
|
|
31
|
+
## Documentation
|
|
32
|
+
|
|
33
|
+
Full documentation and interactive playground available at [supermouse](https://supermouse.vercel.app) or [check out the repo](https://github.com/Whitestar14/supermouse-js).
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supermousejs/stick",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"main": "dist/index.umd.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"author": "O.S David",
|
|
8
|
+
"url": "https://github.com/Whitestar14/supermouse-js",
|
|
9
|
+
"license": "MIT",
|
|
7
10
|
"dependencies": {
|
|
8
|
-
"@supermousejs/utils": "2.0
|
|
9
|
-
|
|
11
|
+
"@supermousejs/utils": "2.1.0"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@supermousejs/core": "2.0.4"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@supermousejs/core": "2.0.4"
|
|
10
18
|
},
|
|
11
|
-
"devDependencies": {},
|
|
12
|
-
"peerDependencies": {},
|
|
13
19
|
"exports": {
|
|
14
20
|
".": {
|
|
15
21
|
"types": "./dist/index.d.ts",
|
package/src/index.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
import type { ValueOrGetter } from '@supermousejs/core';
|
|
3
|
-
import { definePlugin, normalize, dom } from '@supermousejs/utils';
|
|
4
|
-
|
|
5
|
-
export interface StickOptions {
|
|
6
|
-
name?: string;
|
|
7
|
-
isEnabled?: boolean;
|
|
8
|
-
/** Extra padding around the element when calculating shape. Default 10. */
|
|
9
|
-
padding?: ValueOrGetter<number>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const Stick = (options: StickOptions = {}) => {
|
|
13
|
-
const getPadding = normalize(options.padding, 10);
|
|
14
|
-
|
|
15
|
-
let lastTarget: HTMLElement | null = null;
|
|
16
|
-
let cache: { width: number; height: number; radius: number; x: number; y: number } | null = null;
|
|
17
|
-
|
|
18
|
-
return definePlugin({
|
|
19
|
-
name: options.name || 'stick',
|
|
20
|
-
// Logic plugin: must run before visuals to set the shape state
|
|
21
|
-
priority: -10,
|
|
22
|
-
|
|
23
|
-
install(app) {
|
|
24
|
-
app.registerHoverTarget('[data-supermouse-stick]');
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
update(app) {
|
|
28
|
-
// Check normalized interaction key (camelCase, no prefix)
|
|
29
|
-
const target = app.state.hoverTarget;
|
|
30
|
-
const isSticky = app.state.interaction.stick === true || app.state.interaction.stick === 'true';
|
|
31
|
-
|
|
32
|
-
if (target && isSticky) {
|
|
33
|
-
|
|
34
|
-
// Recalculate only if target changed or on first frame
|
|
35
|
-
if (target !== lastTarget || !cache) {
|
|
36
|
-
lastTarget = target;
|
|
37
|
-
|
|
38
|
-
const rect = dom.projectRect(target, app.container);
|
|
39
|
-
const style = window.getComputedStyle(target);
|
|
40
|
-
const padding = getPadding(app.state);
|
|
41
|
-
|
|
42
|
-
cache = {
|
|
43
|
-
width: rect.width + padding,
|
|
44
|
-
height: rect.height + padding,
|
|
45
|
-
radius: parseFloat(style.borderRadius) || 0,
|
|
46
|
-
x: rect.left + rect.width / 2,
|
|
47
|
-
y: rect.top + rect.height / 2
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (cache) {
|
|
52
|
-
// 1. Override Target (Physics) - Snap target to center of element
|
|
53
|
-
app.state.target.x = cache.x;
|
|
54
|
-
app.state.target.y = cache.y;
|
|
55
|
-
|
|
56
|
-
// 2. Set Shape (Visuals) - Visual plugins like Ring will read this
|
|
57
|
-
app.state.shape = {
|
|
58
|
-
width: cache.width,
|
|
59
|
-
height: cache.height,
|
|
60
|
-
borderRadius: cache.radius
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
// Reset
|
|
65
|
-
if (lastTarget) {
|
|
66
|
-
lastTarget = null;
|
|
67
|
-
cache = null;
|
|
68
|
-
}
|
|
69
|
-
app.state.shape = null;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}, options);
|
|
73
|
-
};
|
|
1
|
+
|
|
2
|
+
import type { ValueOrGetter } from '@supermousejs/core';
|
|
3
|
+
import { definePlugin, normalize, dom } from '@supermousejs/utils';
|
|
4
|
+
|
|
5
|
+
export interface StickOptions {
|
|
6
|
+
name?: string;
|
|
7
|
+
isEnabled?: boolean;
|
|
8
|
+
/** Extra padding around the element when calculating shape. Default 10. */
|
|
9
|
+
padding?: ValueOrGetter<number>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const Stick = (options: StickOptions = {}) => {
|
|
13
|
+
const getPadding = normalize(options.padding, 10);
|
|
14
|
+
|
|
15
|
+
let lastTarget: HTMLElement | null = null;
|
|
16
|
+
let cache: { width: number; height: number; radius: number; x: number; y: number } | null = null;
|
|
17
|
+
|
|
18
|
+
return definePlugin({
|
|
19
|
+
name: options.name || 'stick',
|
|
20
|
+
// Logic plugin: must run before visuals to set the shape state
|
|
21
|
+
priority: -10,
|
|
22
|
+
|
|
23
|
+
install(app) {
|
|
24
|
+
app.registerHoverTarget('[data-supermouse-stick]');
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
update(app) {
|
|
28
|
+
// Check normalized interaction key (camelCase, no prefix)
|
|
29
|
+
const target = app.state.hoverTarget;
|
|
30
|
+
const isSticky = app.state.interaction.stick === true || app.state.interaction.stick === 'true';
|
|
31
|
+
|
|
32
|
+
if (target && isSticky) {
|
|
33
|
+
|
|
34
|
+
// Recalculate only if target changed or on first frame
|
|
35
|
+
if (target !== lastTarget || !cache) {
|
|
36
|
+
lastTarget = target;
|
|
37
|
+
|
|
38
|
+
const rect = dom.projectRect(target, app.container);
|
|
39
|
+
const style = window.getComputedStyle(target);
|
|
40
|
+
const padding = getPadding(app.state);
|
|
41
|
+
|
|
42
|
+
cache = {
|
|
43
|
+
width: rect.width + padding,
|
|
44
|
+
height: rect.height + padding,
|
|
45
|
+
radius: parseFloat(style.borderRadius) || 0,
|
|
46
|
+
x: rect.left + rect.width / 2,
|
|
47
|
+
y: rect.top + rect.height / 2
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (cache) {
|
|
52
|
+
// 1. Override Target (Physics) - Snap target to center of element
|
|
53
|
+
app.state.target.x = cache.x;
|
|
54
|
+
app.state.target.y = cache.y;
|
|
55
|
+
|
|
56
|
+
// 2. Set Shape (Visuals) - Visual plugins like Ring will read this
|
|
57
|
+
app.state.shape = {
|
|
58
|
+
width: cache.width,
|
|
59
|
+
height: cache.height,
|
|
60
|
+
borderRadius: cache.radius
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
// Reset
|
|
65
|
+
if (lastTarget) {
|
|
66
|
+
lastTarget = null;
|
|
67
|
+
cache = null;
|
|
68
|
+
}
|
|
69
|
+
app.state.shape = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, options);
|
|
73
|
+
};
|
package/tsconfig.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"include": [
|
|
4
|
-
"src"
|
|
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
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"include": [
|
|
4
|
+
"src"
|
|
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
18
|
}
|
package/vite.config.ts
CHANGED
|
@@ -1,22 +1,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: 'SupermouseStick',
|
|
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
|
-
plugins: [dts({ rollupTypes: true })]
|
|
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: 'SupermouseStick',
|
|
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
|
+
plugins: [dts({ rollupTypes: true })]
|
|
22
22
|
});
|