@supermousejs/image 2.0.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 ADDED
@@ -0,0 +1,13 @@
1
+ # @supermousejs/image
2
+
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - Initial v2.0.0 release
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @supermousejs/utils@2.0.0
13
+ - @supermousejs/core@2.0.0
package/LICENSE.md ADDED
@@ -0,0 +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.
@@ -0,0 +1,15 @@
1
+ import { SupermousePlugin } from '../../core/src/index.ts';
2
+
3
+ declare const Image_2: (options?: ImageOptions) => SupermousePlugin;
4
+ export { Image_2 as Image }
5
+
6
+ export declare interface ImageOptions {
7
+ name?: string;
8
+ isEnabled?: boolean;
9
+ className?: string;
10
+ offset?: [number, number];
11
+ duration?: number;
12
+ smoothness?: number;
13
+ }
14
+
15
+ export { }
package/dist/index.mjs ADDED
@@ -0,0 +1,37 @@
1
+ import { definePlugin as S, dom as t, Easings as x, Layers as v, math as u } from "@supermousejs/utils";
2
+ const w = (s = {}) => {
3
+ const y = s.className || "supermouse-image", [g, p] = s.offset || [0, 30], h = s.duration || 200, n = s.smoothness || 1;
4
+ let a, m = null, r = !1, o = 0, i = 0;
5
+ return S({
6
+ name: "image",
7
+ selector: "[data-supermouse-img]",
8
+ create: () => {
9
+ const e = t.createActor("div");
10
+ return e.classList.add(...y.split(" ").filter(Boolean)), a = document.createElement("img"), t.applyStyles(a, {
11
+ width: "100%",
12
+ height: "100%",
13
+ objectFit: "cover",
14
+ display: "block"
15
+ }), e.appendChild(a), t.applyStyles(e, {
16
+ zIndex: v.OVERLAY,
17
+ opacity: "0",
18
+ overflow: "hidden",
19
+ transition: `opacity ${h}ms ${x.SMOOTH}`,
20
+ width: "150px",
21
+ height: "auto"
22
+ }), t.setTransform(e, -100, -100), e;
23
+ },
24
+ update: (e, c) => {
25
+ const l = e.state.interaction.img;
26
+ if (e.state.isHover && l) {
27
+ l !== m && (a.src = l, m = l), t.setStyle(c, "opacity", "1");
28
+ const d = e.state.pointer.x + g, f = e.state.pointer.y + p;
29
+ r ? (o = u.lerp(o, d, n), i = u.lerp(i, f, n)) : (o = d, i = f, r = !0), t.setTransform(c, o, i);
30
+ } else
31
+ t.setStyle(c, "opacity", "0"), r = !1;
32
+ }
33
+ }, s);
34
+ };
35
+ export {
36
+ w as Image
37
+ };
@@ -0,0 +1 @@
1
+ (function(s,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("@supermousejs/utils")):typeof define=="function"&&define.amd?define(["exports","@supermousejs/utils"],e):(s=typeof globalThis<"u"?globalThis:s||self,e(s.SupermouseImage={},s.SupermouseUtils))})(this,(function(s,e){"use strict";const p=(o={})=>{const y=o.className||"supermouse-image",[g,h]=o.offset||[0,30],S=o.duration||200,c=o.smoothness||1;let a,l=null,m=!1,n=0,r=0;return e.definePlugin({name:"image",selector:"[data-supermouse-img]",create:()=>{const t=e.dom.createActor("div");return t.classList.add(...y.split(" ").filter(Boolean)),a=document.createElement("img"),e.dom.applyStyles(a,{width:"100%",height:"100%",objectFit:"cover",display:"block"}),t.appendChild(a),e.dom.applyStyles(t,{zIndex:e.Layers.OVERLAY,opacity:"0",overflow:"hidden",transition:`opacity ${S}ms ${e.Easings.SMOOTH}`,width:"150px",height:"auto"}),e.dom.setTransform(t,-100,-100),t},update:(t,d)=>{const i=t.state.interaction.img;if(t.state.isHover&&i){i!==l&&(a.src=i,l=i),e.dom.setStyle(d,"opacity","1");const f=t.state.pointer.x+g,u=t.state.pointer.y+h;m?(n=e.math.lerp(n,f,c),r=e.math.lerp(r,u,c)):(n=f,r=u,m=!0),e.dom.setTransform(d,n,r)}else e.dom.setStyle(d,"opacity","0"),m=!1}},o)};s.Image=p,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
package/meta.json ADDED
@@ -0,0 +1,15 @@
1
+
2
+ {
3
+ "id": "image",
4
+ "name": "Image",
5
+ "package": "@supermousejs/image",
6
+ "description": "Displays a custom image or thumbnail as the cursor hover state.",
7
+ "code": "app.use(Image({ rounded: true }));",
8
+ "icon": "image",
9
+ "options": [
10
+ { "name": "className", "type": "string", "default": "'supermouse-image'", "description": "CSS class added to container.", "reactive": false },
11
+ { "name": "offset", "type": "[number, number]", "default": "[0, 30]", "description": "X/Y offset from cursor.", "reactive": false },
12
+ { "name": "duration", "type": "number", "default": "200", "description": "Fade transition time in ms.", "reactive": false },
13
+ { "name": "smoothness", "type": "number", "default": "1", "description": "Lerp factor for image lag.", "reactive": false }
14
+ ]
15
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@supermousejs/image",
3
+ "version": "2.0.0",
4
+ "main": "dist/index.umd.js",
5
+ "module": "dist/index.mjs",
6
+ "types": "dist/index.d.ts",
7
+ "dependencies": {
8
+ "@supermousejs/core": "2.0.0",
9
+ "@supermousejs/utils": "2.0.0"
10
+ },
11
+ "devDependencies": {},
12
+ "peerDependencies": {},
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.mjs",
17
+ "require": "./dist/index.umd.js"
18
+ }
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "scripts": {
24
+ "build": "vite build"
25
+ }
26
+ }
package/src/index.ts ADDED
@@ -0,0 +1,85 @@
1
+ import { definePlugin, dom, math, Layers, Easings } from '@supermousejs/utils';
2
+
3
+ export interface ImageOptions {
4
+ name?: string;
5
+ isEnabled?: boolean;
6
+ className?: string;
7
+ offset?: [number, number];
8
+ duration?: number;
9
+ smoothness?: number;
10
+ }
11
+
12
+ export const Image = (options: ImageOptions = {}) => {
13
+ const className = options.className || 'supermouse-image';
14
+ const [offX, offY] = options.offset || [0, 30];
15
+ const duration = options.duration || 200;
16
+ const smoothness = options.smoothness || 1;
17
+
18
+ let img: HTMLImageElement;
19
+ let lastSrc: string | null = null;
20
+ let isVisible = false;
21
+ let lx = 0;
22
+ let ly = 0;
23
+
24
+ return definePlugin<HTMLDivElement, ImageOptions>({
25
+ name: 'image',
26
+ selector: '[data-supermouse-img]',
27
+
28
+ create: () => {
29
+ const container = dom.createActor('div') as HTMLDivElement;
30
+ if (className) {
31
+ container.classList.add(...className.split(' ').filter(Boolean));
32
+ }
33
+
34
+ img = document.createElement('img');
35
+ dom.applyStyles(img, {
36
+ width: '100%', height: '100%', objectFit: 'cover', display: 'block'
37
+ });
38
+ container.appendChild(img);
39
+
40
+ dom.applyStyles(container, {
41
+ zIndex: Layers.OVERLAY,
42
+ opacity: '0',
43
+ overflow: 'hidden',
44
+ transition: `opacity ${duration}ms ${Easings.SMOOTH}`,
45
+ width: '150px', height: 'auto'
46
+ });
47
+
48
+ dom.setTransform(container, -100, -100);
49
+ return container;
50
+ },
51
+
52
+ update: (app, container) => {
53
+ // Use parsed interaction data
54
+ const src = app.state.interaction.img;
55
+
56
+ if (app.state.isHover && src) {
57
+ if (src !== lastSrc) {
58
+ img.src = src;
59
+ lastSrc = src;
60
+ }
61
+
62
+ dom.setStyle(container, 'opacity', '1');
63
+
64
+ const targetX = app.state.pointer.x + offX;
65
+ const targetY = app.state.pointer.y + offY;
66
+
67
+ // Reset position on first appearance to prevent flying in
68
+ if (!isVisible) {
69
+ lx = targetX;
70
+ ly = targetY;
71
+ isVisible = true;
72
+ } else {
73
+ lx = math.lerp(lx, targetX, smoothness);
74
+ ly = math.lerp(ly, targetY, smoothness);
75
+ }
76
+
77
+ dom.setTransform(container, lx, ly);
78
+
79
+ } else {
80
+ dom.setStyle(container, 'opacity', '0');
81
+ isVisible = false;
82
+ }
83
+ }
84
+ }, options);
85
+ };
package/tsconfig.json ADDED
@@ -0,0 +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
+ }
18
+ }
package/vite.config.ts ADDED
@@ -0,0 +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: 'SupermouseImage',
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
+ });