@supermousejs/stick 2.0.0 → 2.0.2

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,5 +1,23 @@
1
1
  # @supermousejs/stick
2
2
 
3
+ ## 2.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - ae219a0: Update READMEs with correct link to documentation
8
+ - Updated dependencies [ae219a0]
9
+ - @supermousejs/utils@2.0.2
10
+ - @supermousejs/core@2.0.2
11
+
12
+ ## 2.0.1
13
+
14
+ ### Patch Changes
15
+
16
+ - Add minimal README.md files to packages
17
+ - Updated dependencies
18
+ - @supermousejs/utils@2.0.1
19
+ - @supermousejs/core@2.0.1
20
+
3
21
  ## 2.0.0
4
22
 
5
23
  ### Major Changes
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+
2
+ # @supermousejs/stick
3
+
4
+ A **Logic Plugin** that calculates the bounding box of hovered elements.
5
+ Used in combination with `@supermousejs/ring` (or SmartRing) to create a morphing effect.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pnpm add @supermousejs/stick
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { Supermouse } from '@supermousejs/core';
17
+ import { Stick } from '@supermousejs/stick';
18
+ import { Ring } from '@supermousejs/ring';
19
+
20
+ const app = new Supermouse();
21
+
22
+ app.use(Stick({ padding: 10 }));
23
+ app.use(Ring()); // Ring automatically detects 'stick' state and morphs
24
+ ```
25
+
26
+ **HTML:**
27
+ ```html
28
+ <button data-supermouse-stick="true">Sticky Element</button>
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,12 +1,12 @@
1
1
  {
2
2
  "name": "@supermousejs/stick",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "main": "dist/index.umd.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
7
7
  "dependencies": {
8
- "@supermousejs/core": "2.0.0",
9
- "@supermousejs/utils": "2.0.0"
8
+ "@supermousejs/core": "2.0.2",
9
+ "@supermousejs/utils": "2.0.2"
10
10
  },
11
11
  "devDependencies": {},
12
12
  "peerDependencies": {},
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
  });