@edv4h/usketch-plugin-presence-enhanced 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 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.
@@ -0,0 +1,2 @@
1
+ export { createPresenceEnhancedPlugin } from "./plugin.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { createPresenceEnhancedPlugin } from "./plugin.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { UsketchPlugin } from "@edv4h/usketch-shared";
2
+ import type { WsProviderHandle } from "@edv4h/usketch-sync";
3
+ export interface PresenceEnhancedOptions {
4
+ wsProvider: WsProviderHandle;
5
+ boardId: string;
6
+ apiUrl: string;
7
+ }
8
+ export declare function createPresenceEnhancedPlugin(options: PresenceEnhancedOptions): 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;AAsG5D,MAAM,WAAW,uBAAuB;IACvC,UAAU,EAAE,gBAAgB,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,uBAAuB,GAAG,aAAa,CAuG5F"}
package/dist/plugin.js ADDED
@@ -0,0 +1,157 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ const GHOST_AVATAR_SIZE = 36;
3
+ function formatTimeAgo(isoString) {
4
+ const diff = Date.now() - new Date(isoString).getTime();
5
+ const minutes = Math.floor(diff / 60000);
6
+ if (minutes < 1)
7
+ return "just now";
8
+ if (minutes < 60)
9
+ return `${minutes}m ago`;
10
+ const hours = Math.floor(minutes / 60);
11
+ if (hours < 24)
12
+ return `${hours}h ago`;
13
+ const days = Math.floor(hours / 24);
14
+ return `${days}d ago`;
15
+ }
16
+ function GhostAvatar({ obj }) {
17
+ const name = obj.data.name || "";
18
+ const image = obj.data.image ?? null;
19
+ const lastSeenAt = obj.data.lastSeenAt || "";
20
+ const initials = name
21
+ .split(/\s+/)
22
+ .map((w) => w[0])
23
+ .filter(Boolean)
24
+ .slice(0, 2)
25
+ .join("")
26
+ .toUpperCase();
27
+ return (_jsxs("div", { style: {
28
+ position: "absolute",
29
+ left: -GHOST_AVATAR_SIZE / 2,
30
+ top: -GHOST_AVATAR_SIZE / 2,
31
+ opacity: 0.4,
32
+ pointerEvents: "none",
33
+ }, children: [_jsx("div", { style: {
34
+ width: GHOST_AVATAR_SIZE,
35
+ height: GHOST_AVATAR_SIZE,
36
+ borderRadius: "50%",
37
+ overflow: "hidden",
38
+ border: "2px solid #999",
39
+ background: "#ccc",
40
+ display: "flex",
41
+ alignItems: "center",
42
+ justifyContent: "center",
43
+ fontSize: GHOST_AVATAR_SIZE * 0.35,
44
+ fontWeight: 600,
45
+ color: "#fff",
46
+ fontFamily: "system-ui, sans-serif",
47
+ filter: "grayscale(1)",
48
+ }, children: image ? (_jsx("img", { src: image, alt: name, style: { width: "100%", height: "100%", objectFit: "cover" } })) : (initials || "?") }), _jsx("div", { style: {
49
+ textAlign: "center",
50
+ fontSize: 9,
51
+ color: "#999",
52
+ fontFamily: "system-ui, sans-serif",
53
+ marginTop: 2,
54
+ whiteSpace: "nowrap",
55
+ }, children: name }), lastSeenAt && (_jsx("div", { style: {
56
+ textAlign: "center",
57
+ fontSize: 8,
58
+ color: "#bbb",
59
+ fontFamily: "system-ui, sans-serif",
60
+ }, children: formatTimeAgo(lastSeenAt) }))] }));
61
+ }
62
+ export function createPresenceEnhancedPlugin(options) {
63
+ const { wsProvider, boardId, apiUrl } = options;
64
+ const { awareness } = wsProvider;
65
+ let cleanup;
66
+ return {
67
+ id: "usketch-plugin-presence-enhanced",
68
+ name: "拡張プレゼンス",
69
+ setup(ctx) {
70
+ ctx.transient.registerType("ghost-avatar", {
71
+ render: (obj) => _jsx(GhostAvatar, { obj: obj }),
72
+ });
73
+ const activeGhosts = new Set();
74
+ let pollTimer = null;
75
+ async function fetchAndRenderGhosts() {
76
+ try {
77
+ const res = await fetch(`${apiUrl}/api/boards/${boardId}/members`, {
78
+ credentials: "include",
79
+ });
80
+ if (!res.ok)
81
+ return;
82
+ const members = await res.json();
83
+ const onlineClientIds = new Set();
84
+ for (const [clientId] of awareness.getStates()) {
85
+ onlineClientIds.add(clientId);
86
+ }
87
+ // オフラインメンバーのゴーストを表示
88
+ const newGhosts = new Set();
89
+ for (const member of members) {
90
+ if (member.status === "online")
91
+ continue;
92
+ if (!member.lastViewport)
93
+ continue;
94
+ let viewport;
95
+ try {
96
+ viewport = JSON.parse(member.lastViewport);
97
+ }
98
+ catch {
99
+ continue;
100
+ }
101
+ if (typeof viewport.x !== "number" || typeof viewport.y !== "number")
102
+ continue;
103
+ const ghostId = `ghost-${member.userId}`;
104
+ newGhosts.add(ghostId);
105
+ ctx.transient.emit({
106
+ id: ghostId,
107
+ type: "ghost-avatar",
108
+ sourceUserId: member.userId,
109
+ position: viewport,
110
+ data: {
111
+ name: member.name,
112
+ image: member.image,
113
+ lastSeenAt: member.lastSeenAt,
114
+ },
115
+ createdAt: Date.now(),
116
+ });
117
+ }
118
+ // 消えたゴーストをdismiss
119
+ for (const id of activeGhosts) {
120
+ if (!newGhosts.has(id)) {
121
+ ctx.transient.dismiss(id);
122
+ }
123
+ }
124
+ activeGhosts.clear();
125
+ for (const id of newGhosts) {
126
+ activeGhosts.add(id);
127
+ }
128
+ }
129
+ catch {
130
+ // フェッチ失敗は無視
131
+ }
132
+ }
133
+ // 初回フェッチ + 30秒間隔でポーリング
134
+ fetchAndRenderGhosts();
135
+ pollTimer = setInterval(fetchAndRenderGhosts, 30000);
136
+ // awareness変更時にも更新(オンラインになったらゴースト消す)
137
+ function onAwarenessChange() {
138
+ fetchAndRenderGhosts();
139
+ }
140
+ awareness.on("change", onAwarenessChange);
141
+ cleanup = () => {
142
+ if (pollTimer)
143
+ clearInterval(pollTimer);
144
+ awareness.off("change", onAwarenessChange);
145
+ for (const id of activeGhosts) {
146
+ ctx.transient.dismiss(id);
147
+ }
148
+ activeGhosts.clear();
149
+ ctx.layers.unregister("presence-enhanced");
150
+ };
151
+ },
152
+ teardown() {
153
+ cleanup?.();
154
+ },
155
+ };
156
+ }
157
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.tsx"],"names":[],"mappings":";AAGA,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,SAAS,aAAa,CAAC,SAAiB;IACvC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;IACxD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;IACzC,IAAI,OAAO,GAAG,CAAC;QAAE,OAAO,UAAU,CAAC;IACnC,IAAI,OAAO,GAAG,EAAE;QAAE,OAAO,GAAG,OAAO,OAAO,CAAC;IAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC;IACvC,IAAI,KAAK,GAAG,EAAE;QAAE,OAAO,GAAG,KAAK,OAAO,CAAC;IACvC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;IACpC,OAAO,GAAG,IAAI,OAAO,CAAC;AACvB,CAAC;AAED,SAAS,WAAW,CAAC,EAAE,GAAG,EAA4B;IACrD,MAAM,IAAI,GAAI,GAAG,CAAC,IAAI,CAAC,IAAe,IAAI,EAAE,CAAC;IAC7C,MAAM,KAAK,GAAI,GAAG,CAAC,IAAI,CAAC,KAAuB,IAAI,IAAI,CAAC;IACxD,MAAM,UAAU,GAAI,GAAG,CAAC,IAAI,CAAC,UAAqB,IAAI,EAAE,CAAC;IACzD,MAAM,QAAQ,GAAG,IAAI;SACnB,KAAK,CAAC,KAAK,CAAC;SACZ,GAAG,CAAC,CAAC,CAAC,EA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oBACrB,KAAK,MAAM,EAAE,IAAI,SAAS,EAAE,CAAC;wBAC5B,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;oBACtB,CAAC;gBACF,CAAC;gBAAC,MAAM,CAAC;oBACR,YAAY;gBACb,CAAC;YACF,CAAC;YAED,uBAAuB;YACvB,oBAAoB,EAAE,CAAC;YACvB,SAAS,GAAG,WAAW,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;YAErD,qCAAqC;YACrC,SAAS,iBAAiB;gBACzB,oBAAoB,EAAE,CAAC;YACxB,CAAC;YACD,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;YAE1C,OAAO,GAAG,GAAG,EAAE;gBACd,IAAI,SAAS;oBAAE,aAAa,CAAC,SAAS,CAAC,CAAC;gBACxC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;gBAC3C,KAAK,MAAM,EAAE,IAAI,YAAY,EAAE,CAAC;oBAC/B,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBAC3B,CAAC;gBACD,YAAY,CAAC,KAAK,EAAE,CAAC;gBACrB,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;YAC5C,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-enhanced",
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-enhanced"
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
+ }