@edv4h/usketch-plugin-presence-cursor 1.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/LICENSE +21 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +9 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +114 -0
- package/dist/plugin.js.map +1 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 EdV4H
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAA8B,MAAM,aAAa,CAAC"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { UsketchPlugin } from "@edv4h/usketch-shared";
|
|
2
|
+
import type { WsProviderHandle } from "@edv4h/usketch-sync";
|
|
3
|
+
export interface PresenceCursorOptions {
|
|
4
|
+
wsProvider: WsProviderHandle;
|
|
5
|
+
userId: string;
|
|
6
|
+
userName: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function createPresenceCursorPlugin(options: PresenceCursorOptions): UsketchPlugin;
|
|
9
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkC,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAwE5D,MAAM,WAAW,qBAAqB;IACrC,UAAU,EAAE,gBAAgB,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,qBAAqB,GAAG,aAAa,CAwFxF"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
const CURSOR_COLORS = [
|
|
3
|
+
"#e74c3c",
|
|
4
|
+
"#3498db",
|
|
5
|
+
"#2ecc71",
|
|
6
|
+
"#f39c12",
|
|
7
|
+
"#9b59b6",
|
|
8
|
+
"#1abc9c",
|
|
9
|
+
"#e67e22",
|
|
10
|
+
"#e84393",
|
|
11
|
+
];
|
|
12
|
+
function getUserColor(userId) {
|
|
13
|
+
let hash = 0;
|
|
14
|
+
for (let i = 0; i < userId.length; i++) {
|
|
15
|
+
hash = (hash * 31 + userId.charCodeAt(i)) | 0;
|
|
16
|
+
}
|
|
17
|
+
return CURSOR_COLORS[Math.abs(hash) % CURSOR_COLORS.length];
|
|
18
|
+
}
|
|
19
|
+
const STATUS_EMOJI = {
|
|
20
|
+
active: "",
|
|
21
|
+
away: "💤",
|
|
22
|
+
busy: "🔴",
|
|
23
|
+
presenting: "📺",
|
|
24
|
+
};
|
|
25
|
+
function RemoteCursor({ obj }) {
|
|
26
|
+
const color = obj.data.color || "#999";
|
|
27
|
+
const name = obj.data.name || "";
|
|
28
|
+
const status = obj.data.status || "active";
|
|
29
|
+
const statusEmoji = STATUS_EMOJI[status] ?? "";
|
|
30
|
+
return (_jsxs(_Fragment, { children: [_jsx("svg", { width: "16", height: "22", viewBox: "0 0 16 22", style: { position: "absolute", left: -2, top: -2 }, children: _jsx("path", { d: "M0 0L14 10.5L7.5 11.5L11 21L7 19L4 11L0 14Z", fill: color, stroke: "#fff", strokeWidth: "1" }) }), (name || statusEmoji) && (_jsxs("div", { style: {
|
|
31
|
+
position: "absolute",
|
|
32
|
+
left: 16,
|
|
33
|
+
top: 16,
|
|
34
|
+
background: color,
|
|
35
|
+
color: "#fff",
|
|
36
|
+
fontSize: "11px",
|
|
37
|
+
padding: "1px 5px",
|
|
38
|
+
borderRadius: "3px",
|
|
39
|
+
whiteSpace: "nowrap",
|
|
40
|
+
pointerEvents: "none",
|
|
41
|
+
}, children: [statusEmoji && _jsx("span", { style: { marginRight: 2 }, children: statusEmoji }), name] }))] }));
|
|
42
|
+
}
|
|
43
|
+
export function createPresenceCursorPlugin(options) {
|
|
44
|
+
const { wsProvider, userId, userName } = options;
|
|
45
|
+
const color = getUserColor(userId);
|
|
46
|
+
const { awareness } = wsProvider;
|
|
47
|
+
let cleanup;
|
|
48
|
+
return {
|
|
49
|
+
id: "usketch-plugin-presence-cursor",
|
|
50
|
+
name: "プレゼンスカーソル",
|
|
51
|
+
setup(ctx) {
|
|
52
|
+
ctx.transient.registerType("remote-cursor", {
|
|
53
|
+
render: (obj) => _jsx(RemoteCursor, { obj: obj }),
|
|
54
|
+
});
|
|
55
|
+
awareness.setLocalStateField("user", { name: userName, color });
|
|
56
|
+
const activeCursors = new Set();
|
|
57
|
+
function onAwarenessChange() {
|
|
58
|
+
const states = awareness.getStates();
|
|
59
|
+
const currentClients = new Set();
|
|
60
|
+
for (const [clientId, state] of states) {
|
|
61
|
+
if (clientId === awareness.doc.clientID)
|
|
62
|
+
continue;
|
|
63
|
+
const user = state.user;
|
|
64
|
+
const cursor = state.cursor;
|
|
65
|
+
// バリデーション
|
|
66
|
+
if (!user || !cursor || typeof cursor.x !== "number" || typeof cursor.y !== "number") {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
currentClients.add(clientId);
|
|
70
|
+
ctx.transient.emit({
|
|
71
|
+
id: `cursor-${clientId}`,
|
|
72
|
+
type: "remote-cursor",
|
|
73
|
+
sourceUserId: String(clientId),
|
|
74
|
+
position: { x: cursor.x, y: cursor.y },
|
|
75
|
+
data: {
|
|
76
|
+
name: user.name || "",
|
|
77
|
+
color: user.color || getUserColor(String(clientId)),
|
|
78
|
+
status: user.status ?? (state.presenting === true ? "presenting" : "active"),
|
|
79
|
+
},
|
|
80
|
+
ttl: 5000,
|
|
81
|
+
createdAt: Date.now(),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
for (const clientId of activeCursors) {
|
|
85
|
+
if (!currentClients.has(clientId)) {
|
|
86
|
+
ctx.transient.dismiss(`cursor-${clientId}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
activeCursors.clear();
|
|
90
|
+
for (const id of currentClients) {
|
|
91
|
+
activeCursors.add(id);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
awareness.on("change", onAwarenessChange);
|
|
95
|
+
// canvas:pointermoveイベントからworldPoint座標を取得
|
|
96
|
+
const unsubPointerMove = ctx.events.on("canvas:pointermove", (event) => {
|
|
97
|
+
awareness.setLocalStateField("cursor", event.worldPoint);
|
|
98
|
+
});
|
|
99
|
+
const handleMouseLeave = () => {
|
|
100
|
+
awareness.setLocalStateField("cursor", null);
|
|
101
|
+
};
|
|
102
|
+
window.addEventListener("mouseleave", handleMouseLeave);
|
|
103
|
+
cleanup = () => {
|
|
104
|
+
awareness.off("change", onAwarenessChange);
|
|
105
|
+
unsubPointerMove();
|
|
106
|
+
window.removeEventListener("mouseleave", handleMouseLeave);
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
teardown() {
|
|
110
|
+
cleanup?.();
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.tsx"],"names":[],"mappings":";AAGA,MAAM,aAAa,GAAG;IACrB,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;CACT,CAAC;AAEF,SAAS,YAAY,CAAC,MAAc;IACnC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,IAAI,GAAG,CAAC,IAAI,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IA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0CAA0C;YAC1C,MAAM,gBAAgB,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CACrC,oBAAoB,EACpB,CAAC,KAA+C,EAAE,EAAE;gBACnD,SAAS,CAAC,kBAAkB,CAAC,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;YAC1D,CAAC,CACD,CAAC;YAEF,MAAM,gBAAgB,GAAG,GAAG,EAAE;gBAC7B,SAAS,CAAC,kBAAkB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAC9C,CAAC,CAAC;YAEF,MAAM,CAAC,gBAAgB,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;YAExD,OAAO,GAAG,GAAG,EAAE;gBACd,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;gBAC3C,gBAAgB,EAAE,CAAC;gBACnB,MAAM,CAAC,mBAAmB,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;YAC5D,CAAC,CAAC;QACH,CAAC;QAED,QAAQ;YACP,OAAO,EAAE,EAAE,CAAC;QACb,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@edv4h/usketch-plugin-presence-cursor",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.ts",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@edv4h/usketch-sync": "1.0.0",
|
|
16
|
+
"@edv4h/usketch-shared": "1.0.0"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"react": ">=19"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/react": "19.2.14",
|
|
23
|
+
"typescript": "5.9.3",
|
|
24
|
+
"vitest": "3.2.4"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/EdV4H/usketch.git",
|
|
37
|
+
"directory": "plugins/usketch-plugin-presence-cursor"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/EdV4H/usketch#readme",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/EdV4H/usketch/issues"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc -p tsconfig.json",
|
|
45
|
+
"typecheck": "tsc --noEmit",
|
|
46
|
+
"test": "vitest run --passWithNoTests",
|
|
47
|
+
"clean": "rm -rf dist"
|
|
48
|
+
}
|
|
49
|
+
}
|