@supermousejs/trail 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 +13 -0
- package/LICENSE.md +21 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.mjs +28 -0
- package/dist/index.umd.js +1 -0
- package/meta.json +15 -0
- package/package.json +26 -0
- package/src/index.ts +61 -0
- package/tsconfig.json +18 -0
- package/vite.config.ts +22 -0
package/CHANGELOG.md
ADDED
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.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SupermousePlugin } from '../../core/src/index.ts';
|
|
2
|
+
import { ValueOrGetter } from '../../core/src/index.ts';
|
|
3
|
+
|
|
4
|
+
export declare const Trail: (options?: TrailOptions) => SupermousePlugin;
|
|
5
|
+
|
|
6
|
+
export declare interface TrailOptions {
|
|
7
|
+
name?: string;
|
|
8
|
+
isEnabled?: boolean;
|
|
9
|
+
length?: number;
|
|
10
|
+
size?: ValueOrGetter<number>;
|
|
11
|
+
color?: ValueOrGetter<string>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { }
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { normalize as d, definePlugin as p, dom as o, Layers as z } from "@supermousejs/utils";
|
|
2
|
+
const C = (s = {}) => {
|
|
3
|
+
const l = s.length || 10, f = d(s.size, 6), m = d(s.color, "#ff00ff"), a = [], r = [];
|
|
4
|
+
return p({
|
|
5
|
+
name: s.name || "trail",
|
|
6
|
+
create: () => {
|
|
7
|
+
const t = o.createActor("div");
|
|
8
|
+
t.style.zIndex = z.TRACE;
|
|
9
|
+
for (let n = 0; n < l; n++) {
|
|
10
|
+
const e = o.createCircle(0, "#000");
|
|
11
|
+
e.style.position = "absolute", e.style.opacity = String(1 - n / l), t.appendChild(e), a.push(e), r.push({ x: -100, y: -100 });
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
},
|
|
15
|
+
update: (t) => {
|
|
16
|
+
const { x: n, y: e } = t.state.smooth;
|
|
17
|
+
r.pop(), r.unshift({ x: n, y: e });
|
|
18
|
+
const u = f(t.state), x = m(t.state);
|
|
19
|
+
a.forEach((c, i) => {
|
|
20
|
+
const h = r[i], g = 1 - i / l, y = u * g;
|
|
21
|
+
o.setStyle(c, "width", `${y}px`), o.setStyle(c, "height", `${y}px`), o.setStyle(c, "backgroundColor", x), o.setTransform(c, h.x, h.y);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}, s);
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
C as Trail
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(t,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("@supermousejs/utils")):typeof define=="function"&&define.amd?define(["exports","@supermousejs/utils"],e):(t=typeof globalThis<"u"?globalThis:t||self,e(t.SupermouseTrail={},t.SupermouseUtils))})(this,(function(t,e){"use strict";const u=(s={})=>{const d=s.length||10,y=e.normalize(s.size,6),h=e.normalize(s.color,"#ff00ff"),a=[],c=[];return e.definePlugin({name:s.name||"trail",create:()=>{const o=e.dom.createActor("div");o.style.zIndex=e.Layers.TRACE;for(let r=0;r<d;r++){const n=e.dom.createCircle(0,"#000");n.style.position="absolute",n.style.opacity=String(1-r/d),o.appendChild(n),a.push(n),c.push({x:-100,y:-100})}return o},update:o=>{const{x:r,y:n}=o.state.smooth;c.pop(),c.unshift({x:r,y:n});const p=y(o.state),S=h(o.state);a.forEach((i,f)=>{const l=c[f],x=1-f/d,m=p*x;e.dom.setStyle(i,"width",`${m}px`),e.dom.setStyle(i,"height",`${m}px`),e.dom.setStyle(i,"backgroundColor",S),e.dom.setTransform(i,l.x,l.y)})}},s)};t.Trail=u,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|
package/meta.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
{
|
|
3
|
+
"id": "trail",
|
|
4
|
+
"name": "Trail",
|
|
5
|
+
"package": "@supermousejs/trail",
|
|
6
|
+
"description": "Generates procedural particles that trail behind your motion.",
|
|
7
|
+
"code": "app.use(Trail({ length: 12, color: '#f0f' }));",
|
|
8
|
+
"recipeId": "ghost-trail",
|
|
9
|
+
"icon": "trail",
|
|
10
|
+
"options": [
|
|
11
|
+
{ "name": "length", "type": "number", "default": "10", "description": "Number of trail segments.", "reactive": false },
|
|
12
|
+
{ "name": "size", "type": "number", "default": "6", "description": "Size of trail particles.", "reactive": true },
|
|
13
|
+
{ "name": "color", "type": "string", "default": "'#ff00ff'", "description": "Color of segments.", "reactive": true }
|
|
14
|
+
]
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@supermousejs/trail",
|
|
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,61 @@
|
|
|
1
|
+
import type { ValueOrGetter } from '@supermousejs/core';
|
|
2
|
+
import { definePlugin, normalize, dom, Layers } from '@supermousejs/utils';
|
|
3
|
+
|
|
4
|
+
export interface TrailOptions {
|
|
5
|
+
name?: string;
|
|
6
|
+
isEnabled?: boolean;
|
|
7
|
+
length?: number;
|
|
8
|
+
size?: ValueOrGetter<number>;
|
|
9
|
+
color?: ValueOrGetter<string>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const Trail = (options: TrailOptions = {}) => {
|
|
13
|
+
const length = options.length || 10;
|
|
14
|
+
const getSize = normalize(options.size, 6);
|
|
15
|
+
const getColor = normalize(options.color, '#ff00ff');
|
|
16
|
+
|
|
17
|
+
const segments: HTMLDivElement[] = [];
|
|
18
|
+
const history: { x: number, y: number }[] = [];
|
|
19
|
+
|
|
20
|
+
return definePlugin<HTMLDivElement, TrailOptions>({
|
|
21
|
+
name: options.name || 'trail',
|
|
22
|
+
|
|
23
|
+
create: () => {
|
|
24
|
+
const container = dom.createActor('div') as HTMLDivElement;
|
|
25
|
+
container.style.zIndex = Layers.TRACE;
|
|
26
|
+
|
|
27
|
+
for(let i=0; i<length; i++) {
|
|
28
|
+
const d = dom.createCircle(0, '#000');
|
|
29
|
+
d.style.position = 'absolute';
|
|
30
|
+
d.style.opacity = String(1 - (i / length));
|
|
31
|
+
container.appendChild(d);
|
|
32
|
+
segments.push(d);
|
|
33
|
+
history.push({ x: -100, y: -100 });
|
|
34
|
+
}
|
|
35
|
+
return container;
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
update: (app) => {
|
|
39
|
+
const { x, y } = app.state.smooth;
|
|
40
|
+
|
|
41
|
+
// Shift history
|
|
42
|
+
history.pop();
|
|
43
|
+
history.unshift({ x, y });
|
|
44
|
+
|
|
45
|
+
const baseSize = getSize(app.state);
|
|
46
|
+
const color = getColor(app.state);
|
|
47
|
+
|
|
48
|
+
segments.forEach((seg, i) => {
|
|
49
|
+
const pos = history[i];
|
|
50
|
+
const scale = 1 - (i / length);
|
|
51
|
+
const size = baseSize * scale;
|
|
52
|
+
|
|
53
|
+
dom.setStyle(seg, 'width', `${size}px`);
|
|
54
|
+
dom.setStyle(seg, 'height', `${size}px`);
|
|
55
|
+
dom.setStyle(seg, 'backgroundColor', color);
|
|
56
|
+
|
|
57
|
+
dom.setTransform(seg, pos.x, pos.y);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}, options);
|
|
61
|
+
};
|
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: 'SupermouseTrail',
|
|
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
|
+
});
|