@supermousejs/trail 2.2.1 → 2.3.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 +8 -0
- package/dist/index.d.ts +2 -2
- package/package.json +4 -4
- package/src/index.ts +66 -66
- package/tsconfig.json +4 -4
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SupermousePlugin } from '
|
|
2
|
-
import { ValueOrGetter } from '
|
|
1
|
+
import { SupermousePlugin } from '../packages/core/src';
|
|
2
|
+
import { ValueOrGetter } from '../packages/core/src';
|
|
3
3
|
|
|
4
4
|
export declare const Trail: (options?: TrailOptions) => SupermousePlugin;
|
|
5
5
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supermousejs/trail",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"main": "dist/index.umd.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"url": "https://github.com/Whitestar14/supermouse-js",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@supermousejs/utils": "2.
|
|
11
|
+
"@supermousejs/utils": "2.3.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@supermousejs/core": "2.
|
|
14
|
+
"@supermousejs/core": "2.2.0"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@supermousejs/core": "2.
|
|
17
|
+
"@supermousejs/core": "2.2.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
package/src/index.ts
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import type { ValueOrGetter, Supermouse } 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
|
-
{
|
|
22
|
-
name: options.name || "trail",
|
|
23
|
-
|
|
24
|
-
create: () => {
|
|
25
|
-
segments.length = 0;
|
|
26
|
-
history.length = 0;
|
|
27
|
-
const container = dom.createActor("div") as HTMLDivElement;
|
|
28
|
-
container.style.zIndex = Layers.TRACE;
|
|
29
|
-
|
|
30
|
-
for (let i = 0; i < length; i++) {
|
|
31
|
-
const d = dom.createCircle(0, "#000");
|
|
32
|
-
d.style.position = "absolute";
|
|
33
|
-
d.style.opacity = String(1 - i / length);
|
|
34
|
-
container.appendChild(d);
|
|
35
|
-
segments.push(d);
|
|
36
|
-
history.push({ x: -100, y: -100 });
|
|
37
|
-
}
|
|
38
|
-
return container;
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
update: (app: Supermouse) => {
|
|
42
|
-
const { x, y } = app.state.smooth;
|
|
43
|
-
|
|
44
|
-
// Shift history
|
|
45
|
-
history.pop();
|
|
46
|
-
history.unshift({ x, y });
|
|
47
|
-
|
|
48
|
-
const baseSize = getSize(app.state);
|
|
49
|
-
const color = getColor(app.state);
|
|
50
|
-
|
|
51
|
-
segments.forEach((seg, i) => {
|
|
52
|
-
const pos = history[i];
|
|
53
|
-
const scale = 1 - i / length;
|
|
54
|
-
const size = baseSize * scale;
|
|
55
|
-
|
|
56
|
-
dom.setStyle(seg, "width", `${size}px`);
|
|
57
|
-
dom.setStyle(seg, "height", `${size}px`);
|
|
58
|
-
dom.setStyle(seg, "backgroundColor", color);
|
|
59
|
-
|
|
60
|
-
dom.setTransform(seg, pos.x, pos.y);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
options
|
|
65
|
-
);
|
|
66
|
-
};
|
|
1
|
+
import type { ValueOrGetter, Supermouse } 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
|
+
{
|
|
22
|
+
name: options.name || "trail",
|
|
23
|
+
|
|
24
|
+
create: () => {
|
|
25
|
+
segments.length = 0;
|
|
26
|
+
history.length = 0;
|
|
27
|
+
const container = dom.createActor("div") as HTMLDivElement;
|
|
28
|
+
container.style.zIndex = Layers.TRACE;
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < length; i++) {
|
|
31
|
+
const d = dom.createCircle(0, "#000");
|
|
32
|
+
d.style.position = "absolute";
|
|
33
|
+
d.style.opacity = String(1 - i / length);
|
|
34
|
+
container.appendChild(d);
|
|
35
|
+
segments.push(d);
|
|
36
|
+
history.push({ x: -100, y: -100 });
|
|
37
|
+
}
|
|
38
|
+
return container;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
update: (app: Supermouse) => {
|
|
42
|
+
const { x, y } = app.state.smooth;
|
|
43
|
+
|
|
44
|
+
// Shift history
|
|
45
|
+
history.pop();
|
|
46
|
+
history.unshift({ x, y });
|
|
47
|
+
|
|
48
|
+
const baseSize = getSize(app.state);
|
|
49
|
+
const color = getColor(app.state);
|
|
50
|
+
|
|
51
|
+
segments.forEach((seg, i) => {
|
|
52
|
+
const pos = history[i];
|
|
53
|
+
const scale = 1 - i / length;
|
|
54
|
+
const size = baseSize * scale;
|
|
55
|
+
|
|
56
|
+
dom.setStyle(seg, "width", `${size}px`);
|
|
57
|
+
dom.setStyle(seg, "height", `${size}px`);
|
|
58
|
+
dom.setStyle(seg, "backgroundColor", color);
|
|
59
|
+
|
|
60
|
+
dom.setTransform(seg, pos.x, pos.y);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
options
|
|
65
|
+
);
|
|
66
|
+
};
|
package/tsconfig.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.plugin.json",
|
|
3
|
-
"include": ["src"]
|
|
4
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.plugin.json",
|
|
3
|
+
"include": ["src"]
|
|
4
|
+
}
|