@clagentic/console 1.0.0-beta.1
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/CREDITS.md +3 -0
- package/LICENSE +21 -0
- package/README.md +250 -0
- package/bin/cli.js +2812 -0
- package/lib/agents-favorites.js +164 -0
- package/lib/agents.js +282 -0
- package/lib/ask-user-mcp-server.js +120 -0
- package/lib/browser-mcp-server.js +484 -0
- package/lib/build-user-env.js +63 -0
- package/lib/certs/fullchain.pem +47 -0
- package/lib/certs/privkey.pem +5 -0
- package/lib/cli-sessions.js +265 -0
- package/lib/codex-defaults.js +18 -0
- package/lib/config.js +332 -0
- package/lib/crisis-safety.js +60 -0
- package/lib/daemon-projects.js +164 -0
- package/lib/daemon.js +1602 -0
- package/lib/dm.js +128 -0
- package/lib/ipc.js +125 -0
- package/lib/ipv4-only.js +39 -0
- package/lib/mcp-local.js +385 -0
- package/lib/notes.js +141 -0
- package/lib/os-users.js +529 -0
- package/lib/pages.js +1325 -0
- package/lib/project-connection.js +302 -0
- package/lib/project-external-trigger.js +236 -0
- package/lib/project-file-watch.js +120 -0
- package/lib/project-filesystem.js +528 -0
- package/lib/project-http.js +753 -0
- package/lib/project-image.js +95 -0
- package/lib/project-knowledge.js +88 -0
- package/lib/project-loop.js +1304 -0
- package/lib/project-mcp.js +374 -0
- package/lib/project-memory.js +39 -0
- package/lib/project-notifications.js +262 -0
- package/lib/project-sessions.js +1581 -0
- package/lib/project-user-mention.js +193 -0
- package/lib/project-user-message.js +628 -0
- package/lib/project.js +1303 -0
- package/lib/public/app.js +1031 -0
- package/lib/public/apple-touch-icon.png +0 -0
- package/lib/public/claude-code-avatar.png +0 -0
- package/lib/public/codex-avatar.png +0 -0
- package/lib/public/console-icon.png +0 -0
- package/lib/public/css/admin.css +736 -0
- package/lib/public/css/agent-picker.css +119 -0
- package/lib/public/css/base.css +235 -0
- package/lib/public/css/channel-layout.css +441 -0
- package/lib/public/css/command-palette.css +559 -0
- package/lib/public/css/debate.css +1609 -0
- package/lib/public/css/diff.css +139 -0
- package/lib/public/css/filebrowser.css +1976 -0
- package/lib/public/css/highlight.css +144 -0
- package/lib/public/css/home-hub.css +545 -0
- package/lib/public/css/icon-strip.css +1856 -0
- package/lib/public/css/input.css +1349 -0
- package/lib/public/css/loop.css +1248 -0
- package/lib/public/css/mention.css +317 -0
- package/lib/public/css/menus.css +857 -0
- package/lib/public/css/messages.css +1833 -0
- package/lib/public/css/mobile-nav.css +1332 -0
- package/lib/public/css/notifications-center.css +296 -0
- package/lib/public/css/overlays.css +1273 -0
- package/lib/public/css/playbook.css +264 -0
- package/lib/public/css/profile.css +397 -0
- package/lib/public/css/rewind.css +671 -0
- package/lib/public/css/scheduler-modal.css +1495 -0
- package/lib/public/css/scheduler.css +1420 -0
- package/lib/public/css/server-settings.css +909 -0
- package/lib/public/css/session-search.css +159 -0
- package/lib/public/css/sidebar.css +2012 -0
- package/lib/public/css/skills.css +789 -0
- package/lib/public/css/sticky-notes.css +854 -0
- package/lib/public/css/stt.css +155 -0
- package/lib/public/css/title-bar.css +674 -0
- package/lib/public/css/tooltip.css +67 -0
- package/lib/public/css/user-settings.css +702 -0
- package/lib/public/emoji-data.json +1 -0
- package/lib/public/favicon-banded-32.png +0 -0
- package/lib/public/favicon-banded.png +0 -0
- package/lib/public/favicon-dark.svg +32 -0
- package/lib/public/favicon.svg +32 -0
- package/lib/public/icon-192.png +0 -0
- package/lib/public/icon-512.png +0 -0
- package/lib/public/icon-banded-76.png +0 -0
- package/lib/public/icon-banded-96.png +0 -0
- package/lib/public/icon-mono.svg +25 -0
- package/lib/public/icons/email/gmail.svg +7 -0
- package/lib/public/icons/email/outlook.svg +35 -0
- package/lib/public/icons/email/yahoo.svg +1 -0
- package/lib/public/index.html +1946 -0
- package/lib/public/manifest.json +27 -0
- package/lib/public/markdown-worker.js +43 -0
- package/lib/public/marked.min.js +6 -0
- package/lib/public/modules/admin.js +954 -0
- package/lib/public/modules/agent-picker.js +429 -0
- package/lib/public/modules/app-connection.js +216 -0
- package/lib/public/modules/app-cursors.js +492 -0
- package/lib/public/modules/app-dm.js +265 -0
- package/lib/public/modules/app-favicon.js +231 -0
- package/lib/public/modules/app-header.js +242 -0
- package/lib/public/modules/app-home-hub.js +432 -0
- package/lib/public/modules/app-loop-ui.js +691 -0
- package/lib/public/modules/app-loop-wizard.js +439 -0
- package/lib/public/modules/app-messages.js +1415 -0
- package/lib/public/modules/app-misc.js +463 -0
- package/lib/public/modules/app-notifications.js +651 -0
- package/lib/public/modules/app-panels.js +1061 -0
- package/lib/public/modules/app-projects.js +875 -0
- package/lib/public/modules/app-rate-limit.js +529 -0
- package/lib/public/modules/app-rendering.js +739 -0
- package/lib/public/modules/app-skills-install.js +285 -0
- package/lib/public/modules/avatar.js +36 -0
- package/lib/public/modules/command-palette.js +491 -0
- package/lib/public/modules/console-logo.js +162 -0
- package/lib/public/modules/context-sources.js +365 -0
- package/lib/public/modules/diff.js +412 -0
- package/lib/public/modules/dom-refs.js +21 -0
- package/lib/public/modules/emoji-picker.js +222 -0
- package/lib/public/modules/events.js +21 -0
- package/lib/public/modules/filebrowser.js +1966 -0
- package/lib/public/modules/fileicons.js +172 -0
- package/lib/public/modules/icons.js +80 -0
- package/lib/public/modules/input.js +1102 -0
- package/lib/public/modules/longpress.js +74 -0
- package/lib/public/modules/markdown.js +486 -0
- package/lib/public/modules/mcp-ui.js +295 -0
- package/lib/public/modules/mention.js +1093 -0
- package/lib/public/modules/notifications.js +613 -0
- package/lib/public/modules/playbook.js +578 -0
- package/lib/public/modules/profile.js +594 -0
- package/lib/public/modules/project-settings.js +849 -0
- package/lib/public/modules/project-switcher.js +375 -0
- package/lib/public/modules/qrcode.js +87 -0
- package/lib/public/modules/rewind.js +381 -0
- package/lib/public/modules/scheduler-config.js +1611 -0
- package/lib/public/modules/scheduler-history.js +131 -0
- package/lib/public/modules/scheduler.js +1689 -0
- package/lib/public/modules/server-settings.js +842 -0
- package/lib/public/modules/session-search.js +456 -0
- package/lib/public/modules/settings-defaults.js +253 -0
- package/lib/public/modules/sidebar-mobile.js +1425 -0
- package/lib/public/modules/sidebar-projects.js +2022 -0
- package/lib/public/modules/sidebar-sessions.js +1548 -0
- package/lib/public/modules/sidebar-users.js +449 -0
- package/lib/public/modules/sidebar.js +348 -0
- package/lib/public/modules/skills.js +793 -0
- package/lib/public/modules/state.js +3 -0
- package/lib/public/modules/sticky-notes.js +1221 -0
- package/lib/public/modules/store.js +34 -0
- package/lib/public/modules/stt.js +266 -0
- package/lib/public/modules/terminal.js +987 -0
- package/lib/public/modules/theme.js +812 -0
- package/lib/public/modules/tool-palette.js +562 -0
- package/lib/public/modules/tools.js +2285 -0
- package/lib/public/modules/tooltip.js +150 -0
- package/lib/public/modules/user-settings.js +544 -0
- package/lib/public/modules/utils.js +56 -0
- package/lib/public/modules/ws-ref.js +26 -0
- package/lib/public/style.css +34 -0
- package/lib/public/sw.js +159 -0
- package/lib/push.js +149 -0
- package/lib/scheduler.js +471 -0
- package/lib/sdk-bridge.js +1792 -0
- package/lib/sdk-message-processor.js +740 -0
- package/lib/sdk-message-queue.js +42 -0
- package/lib/sdk-skill-discovery.js +131 -0
- package/lib/sdk-worker.js +677 -0
- package/lib/server-admin.js +712 -0
- package/lib/server-auth.js +737 -0
- package/lib/server-dm.js +170 -0
- package/lib/server-palette.js +104 -0
- package/lib/server-settings.js +553 -0
- package/lib/server-skills.js +280 -0
- package/lib/server.js +1390 -0
- package/lib/session-search.js +693 -0
- package/lib/sessions.js +946 -0
- package/lib/smtp.js +221 -0
- package/lib/terminal-manager.js +219 -0
- package/lib/terminal.js +39 -0
- package/lib/themes/ayu-light.json +9 -0
- package/lib/themes/catppuccin-latte.json +9 -0
- package/lib/themes/catppuccin-mocha.json +9 -0
- package/lib/themes/clagentic-dark.json +10 -0
- package/lib/themes/clagentic-light.json +10 -0
- package/lib/themes/dracula.json +9 -0
- package/lib/themes/everforest-light.json +9 -0
- package/lib/themes/everforest.json +9 -0
- package/lib/themes/github-light.json +9 -0
- package/lib/themes/gruvbox-dark.json +9 -0
- package/lib/themes/gruvbox-light.json +9 -0
- package/lib/themes/monokai.json +9 -0
- package/lib/themes/nord-light.json +9 -0
- package/lib/themes/nord.json +9 -0
- package/lib/themes/one-dark.json +9 -0
- package/lib/themes/one-light.json +9 -0
- package/lib/themes/rose-pine-dawn.json +9 -0
- package/lib/themes/rose-pine.json +9 -0
- package/lib/themes/solarized-dark.json +9 -0
- package/lib/themes/solarized-light.json +9 -0
- package/lib/themes/tokyo-night-light.json +9 -0
- package/lib/themes/tokyo-night.json +9 -0
- package/lib/updater.js +124 -0
- package/lib/user-presence.js +92 -0
- package/lib/users-auth.js +146 -0
- package/lib/users-permissions.js +118 -0
- package/lib/users-preferences.js +254 -0
- package/lib/users.js +465 -0
- package/lib/utils.js +64 -0
- package/lib/worktree.js +134 -0
- package/lib/ws-schema.js +464 -0
- package/lib/yoke/adapters/claude-worker.js +759 -0
- package/lib/yoke/adapters/claude.js +1599 -0
- package/lib/yoke/adapters/codex.js +1559 -0
- package/lib/yoke/codex-app-server.js +352 -0
- package/lib/yoke/index.js +319 -0
- package/lib/yoke/instructions.js +61 -0
- package/lib/yoke/interface.js +98 -0
- package/lib/yoke/mcp-bridge-server.js +302 -0
- package/lib/yoke/package.json +7 -0
- package/package.json +72 -0
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
// User profile module — Discord-style popover for name, language, avatar
|
|
2
|
+
// Stores profile server-side in ~/.clay/profile.json
|
|
3
|
+
// Avatar generated via DiceBear API (deterministic SVG from seed)
|
|
4
|
+
|
|
5
|
+
import { iconHtml, refreshIcons } from './icons.js';
|
|
6
|
+
import { setSTTLang } from './stt.js';
|
|
7
|
+
import { avatarUrl, AVATAR_STYLES } from './avatar.js';
|
|
8
|
+
import { store } from './store.js';
|
|
9
|
+
|
|
10
|
+
var ctx;
|
|
11
|
+
var profile = { name: '', lang: 'en-US', avatarStyle: 'thumbs', avatarSeed: '', avatarColor: '#7c3aed', avatarCustom: '' };
|
|
12
|
+
var profileUsername = '';
|
|
13
|
+
var popoverEl = null;
|
|
14
|
+
var saveTimer = null;
|
|
15
|
+
var previewSeed = '';
|
|
16
|
+
|
|
17
|
+
// AVATAR_STYLES imported from avatar.js
|
|
18
|
+
|
|
19
|
+
var COLORS = [
|
|
20
|
+
'#7c3aed', '#4f46e5', '#2563eb', '#0891b2',
|
|
21
|
+
'#059669', '#65a30d', '#d97706', '#dc2626',
|
|
22
|
+
'#db2777', '#6366f1', '#0d9488', '#ea580c',
|
|
23
|
+
'#475569', '#1e293b', '#be123c', '#a21caf',
|
|
24
|
+
'#0369a1', '#15803d',
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
// avatarUrl imported from avatar.js
|
|
28
|
+
|
|
29
|
+
function getAvatarSeed() {
|
|
30
|
+
return profile.avatarSeed || 'anonymous';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// --- API ---
|
|
34
|
+
function fetchProfile() {
|
|
35
|
+
return fetch('/api/profile').then(function(r) { return r.json(); });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function saveProfile() {
|
|
39
|
+
return fetch('/api/profile', {
|
|
40
|
+
method: 'PUT',
|
|
41
|
+
headers: { 'Content-Type': 'application/json' },
|
|
42
|
+
body: JSON.stringify(profile),
|
|
43
|
+
}).then(function(r) { return r.json(); });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function debouncedSave() {
|
|
47
|
+
if (saveTimer) clearTimeout(saveTimer);
|
|
48
|
+
saveTimer = setTimeout(function() {
|
|
49
|
+
saveProfile();
|
|
50
|
+
saveTimer = null;
|
|
51
|
+
}, 400);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// --- DOM updates ---
|
|
55
|
+
export function applyToIsland() {
|
|
56
|
+
var avatarWrap = document.querySelector('.user-island-avatar');
|
|
57
|
+
var nameEl = document.querySelector('.user-island-name');
|
|
58
|
+
if (!avatarWrap || !nameEl) {
|
|
59
|
+
requestAnimationFrame(applyToIsland);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
var displayName = profile.name || 'Console User';
|
|
64
|
+
|
|
65
|
+
// Replace letter fallback with avatar img
|
|
66
|
+
var existingImg = avatarWrap.querySelector('img');
|
|
67
|
+
var existingLetter = avatarWrap.querySelector('.user-island-avatar-letter');
|
|
68
|
+
var url = profile.avatarCustom
|
|
69
|
+
? profile.avatarCustom
|
|
70
|
+
: avatarUrl(profile.avatarStyle || 'thumbs', getAvatarSeed(), 32);
|
|
71
|
+
|
|
72
|
+
if (existingImg) {
|
|
73
|
+
existingImg.src = url;
|
|
74
|
+
} else {
|
|
75
|
+
if (existingLetter) existingLetter.style.display = 'none';
|
|
76
|
+
var img = document.createElement('img');
|
|
77
|
+
img.src = url;
|
|
78
|
+
img.alt = displayName;
|
|
79
|
+
avatarWrap.appendChild(img);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
nameEl.textContent = displayName;
|
|
83
|
+
|
|
84
|
+
// Show CTA if user hasn't personalized their name
|
|
85
|
+
var ctaEl = document.querySelector('.user-island-cta');
|
|
86
|
+
if (ctaEl) {
|
|
87
|
+
var isDefault = profileUsername && profile.name === profileUsername;
|
|
88
|
+
if (isDefault) {
|
|
89
|
+
ctaEl.classList.remove('hidden');
|
|
90
|
+
} else {
|
|
91
|
+
ctaEl.classList.add('hidden');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// --- Avatar position picker ---
|
|
97
|
+
export function showAvatarPositioner(img, objectUrl, onDone) {
|
|
98
|
+
var outputSize = 256;
|
|
99
|
+
var viewSize = 220;
|
|
100
|
+
|
|
101
|
+
// State
|
|
102
|
+
var scale = 1;
|
|
103
|
+
var offsetX = 0;
|
|
104
|
+
var offsetY = 0;
|
|
105
|
+
|
|
106
|
+
// Fit image so shorter side fills the circle
|
|
107
|
+
var baseScale = Math.max(viewSize / img.width, viewSize / img.height);
|
|
108
|
+
|
|
109
|
+
function clampOffsets() {
|
|
110
|
+
var sw = img.width * baseScale * scale;
|
|
111
|
+
var sh = img.height * baseScale * scale;
|
|
112
|
+
var maxX = Math.max(0, (sw - viewSize) / 2);
|
|
113
|
+
var maxY = Math.max(0, (sh - viewSize) / 2);
|
|
114
|
+
if (offsetX > maxX) offsetX = maxX;
|
|
115
|
+
if (offsetX < -maxX) offsetX = -maxX;
|
|
116
|
+
if (offsetY > maxY) offsetY = maxY;
|
|
117
|
+
if (offsetY < -maxY) offsetY = -maxY;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function updatePreview() {
|
|
121
|
+
var s = baseScale * scale;
|
|
122
|
+
var tx = (viewSize - img.width * s) / 2 + offsetX;
|
|
123
|
+
var ty = (viewSize - img.height * s) / 2 + offsetY;
|
|
124
|
+
previewImg.style.width = (img.width * s) + 'px';
|
|
125
|
+
previewImg.style.height = (img.height * s) + 'px';
|
|
126
|
+
previewImg.style.transform = 'translate(' + tx + 'px, ' + ty + 'px)';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Build overlay
|
|
130
|
+
var overlay = document.createElement('div');
|
|
131
|
+
overlay.className = 'avatar-positioner-overlay';
|
|
132
|
+
|
|
133
|
+
var container = document.createElement('div');
|
|
134
|
+
container.className = 'avatar-positioner-container';
|
|
135
|
+
|
|
136
|
+
var closeBtn = document.createElement('button');
|
|
137
|
+
closeBtn.className = 'avatar-positioner-close';
|
|
138
|
+
closeBtn.innerHTML = '×';
|
|
139
|
+
container.appendChild(closeBtn);
|
|
140
|
+
|
|
141
|
+
var title = document.createElement('div');
|
|
142
|
+
title.className = 'avatar-positioner-title';
|
|
143
|
+
title.textContent = 'Position your avatar';
|
|
144
|
+
container.appendChild(title);
|
|
145
|
+
|
|
146
|
+
var viewport = document.createElement('div');
|
|
147
|
+
viewport.className = 'avatar-positioner-viewport';
|
|
148
|
+
viewport.style.width = viewSize + 'px';
|
|
149
|
+
viewport.style.height = viewSize + 'px';
|
|
150
|
+
|
|
151
|
+
var previewImg = document.createElement('img');
|
|
152
|
+
previewImg.src = objectUrl;
|
|
153
|
+
previewImg.className = 'avatar-positioner-img';
|
|
154
|
+
previewImg.draggable = false;
|
|
155
|
+
viewport.appendChild(previewImg);
|
|
156
|
+
container.appendChild(viewport);
|
|
157
|
+
|
|
158
|
+
// Zoom slider
|
|
159
|
+
var sliderWrap = document.createElement('div');
|
|
160
|
+
sliderWrap.className = 'avatar-positioner-slider-wrap';
|
|
161
|
+
var slider = document.createElement('input');
|
|
162
|
+
slider.type = 'range';
|
|
163
|
+
slider.min = '1';
|
|
164
|
+
slider.max = '6';
|
|
165
|
+
slider.step = '0.05';
|
|
166
|
+
slider.value = '1';
|
|
167
|
+
slider.className = 'avatar-positioner-slider';
|
|
168
|
+
sliderWrap.appendChild(slider);
|
|
169
|
+
container.appendChild(sliderWrap);
|
|
170
|
+
|
|
171
|
+
// Buttons
|
|
172
|
+
var btnRow = document.createElement('div');
|
|
173
|
+
btnRow.className = 'avatar-positioner-buttons';
|
|
174
|
+
var cancelBtn = document.createElement('button');
|
|
175
|
+
cancelBtn.className = 'avatar-positioner-btn avatar-positioner-btn-cancel';
|
|
176
|
+
cancelBtn.textContent = 'Cancel';
|
|
177
|
+
var doneBtn = document.createElement('button');
|
|
178
|
+
doneBtn.className = 'avatar-positioner-btn avatar-positioner-btn-done';
|
|
179
|
+
doneBtn.textContent = 'Done';
|
|
180
|
+
btnRow.appendChild(cancelBtn);
|
|
181
|
+
btnRow.appendChild(doneBtn);
|
|
182
|
+
container.appendChild(btnRow);
|
|
183
|
+
|
|
184
|
+
overlay.appendChild(container);
|
|
185
|
+
document.body.appendChild(overlay);
|
|
186
|
+
updatePreview();
|
|
187
|
+
|
|
188
|
+
// Drag
|
|
189
|
+
var dragging = false;
|
|
190
|
+
var dragStartX = 0;
|
|
191
|
+
var dragStartY = 0;
|
|
192
|
+
var startOffsetX = 0;
|
|
193
|
+
var startOffsetY = 0;
|
|
194
|
+
|
|
195
|
+
viewport.addEventListener('mousedown', startDrag);
|
|
196
|
+
viewport.addEventListener('touchstart', startDrag, { passive: false });
|
|
197
|
+
|
|
198
|
+
function startDrag(e) {
|
|
199
|
+
e.preventDefault();
|
|
200
|
+
dragging = true;
|
|
201
|
+
var pt = e.touches ? e.touches[0] : e;
|
|
202
|
+
dragStartX = pt.clientX;
|
|
203
|
+
dragStartY = pt.clientY;
|
|
204
|
+
startOffsetX = offsetX;
|
|
205
|
+
startOffsetY = offsetY;
|
|
206
|
+
document.addEventListener('mousemove', onDrag);
|
|
207
|
+
document.addEventListener('mouseup', endDrag);
|
|
208
|
+
document.addEventListener('touchmove', onDrag, { passive: false });
|
|
209
|
+
document.addEventListener('touchend', endDrag);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function onDrag(e) {
|
|
213
|
+
if (!dragging) return;
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
var pt = e.touches ? e.touches[0] : e;
|
|
216
|
+
offsetX = startOffsetX + (pt.clientX - dragStartX);
|
|
217
|
+
offsetY = startOffsetY + (pt.clientY - dragStartY);
|
|
218
|
+
clampOffsets();
|
|
219
|
+
updatePreview();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function endDrag() {
|
|
223
|
+
dragging = false;
|
|
224
|
+
document.removeEventListener('mousemove', onDrag);
|
|
225
|
+
document.removeEventListener('mouseup', endDrag);
|
|
226
|
+
document.removeEventListener('touchmove', onDrag);
|
|
227
|
+
document.removeEventListener('touchend', endDrag);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Zoom
|
|
231
|
+
slider.addEventListener('input', function() {
|
|
232
|
+
scale = parseFloat(slider.value);
|
|
233
|
+
clampOffsets();
|
|
234
|
+
updatePreview();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// Scroll to zoom
|
|
238
|
+
viewport.addEventListener('wheel', function(e) {
|
|
239
|
+
e.preventDefault();
|
|
240
|
+
scale += e.deltaY < 0 ? 0.1 : -0.1;
|
|
241
|
+
if (scale < 1) scale = 1;
|
|
242
|
+
if (scale > 6) scale = 6;
|
|
243
|
+
slider.value = scale;
|
|
244
|
+
clampOffsets();
|
|
245
|
+
updatePreview();
|
|
246
|
+
}, { passive: false });
|
|
247
|
+
|
|
248
|
+
function cleanup(revoke) {
|
|
249
|
+
overlay.remove();
|
|
250
|
+
if (revoke) URL.revokeObjectURL(objectUrl);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
closeBtn.addEventListener('click', function() { cleanup(true); });
|
|
254
|
+
cancelBtn.addEventListener('click', function() { cleanup(true); });
|
|
255
|
+
|
|
256
|
+
doneBtn.addEventListener('click', function() {
|
|
257
|
+
// Render cropped area to canvas
|
|
258
|
+
var canvas = document.createElement('canvas');
|
|
259
|
+
canvas.width = outputSize;
|
|
260
|
+
canvas.height = outputSize;
|
|
261
|
+
var c = canvas.getContext('2d');
|
|
262
|
+
var s = baseScale * scale;
|
|
263
|
+
var tx = (viewSize - img.width * s) / 2 + offsetX;
|
|
264
|
+
var ty = (viewSize - img.height * s) / 2 + offsetY;
|
|
265
|
+
// Map from viewSize coords to outputSize
|
|
266
|
+
var ratio = outputSize / viewSize;
|
|
267
|
+
c.drawImage(img,
|
|
268
|
+
0, 0, img.width, img.height,
|
|
269
|
+
tx * ratio, ty * ratio, img.width * s * ratio, img.height * s * ratio
|
|
270
|
+
);
|
|
271
|
+
canvas.toBlob(function(blob) {
|
|
272
|
+
cleanup(false);
|
|
273
|
+
if (blob) onDone(blob);
|
|
274
|
+
}, 'image/jpeg', 0.9);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// --- Popover ---
|
|
279
|
+
function showPopover() {
|
|
280
|
+
if (popoverEl) {
|
|
281
|
+
hidePopover();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
popoverEl = document.createElement('div');
|
|
286
|
+
popoverEl.className = 'profile-popover';
|
|
287
|
+
|
|
288
|
+
var displayName = profile.name || '';
|
|
289
|
+
var currentColor = profile.avatarColor || '#7c3aed';
|
|
290
|
+
var currentStyle = profile.avatarStyle || 'thumbs';
|
|
291
|
+
var seed = getAvatarSeed();
|
|
292
|
+
previewSeed = seed;
|
|
293
|
+
|
|
294
|
+
var html = '';
|
|
295
|
+
|
|
296
|
+
// Banner + close
|
|
297
|
+
html += '<div class="profile-banner" style="background:' + currentColor + '">';
|
|
298
|
+
html += '<button class="profile-close-btn">×</button>';
|
|
299
|
+
html += '</div>';
|
|
300
|
+
|
|
301
|
+
// Avatar row (overlapping banner)
|
|
302
|
+
html += '<div class="profile-avatar-row">';
|
|
303
|
+
html += '<div class="profile-popover-avatar">';
|
|
304
|
+
html += '<img class="profile-popover-avatar-img" src="' + (profile.avatarCustom || avatarUrl(currentStyle, seed, 80)) + '" alt="avatar">';
|
|
305
|
+
html += '</div>';
|
|
306
|
+
html += '<div class="profile-name-display">' + escapeAttr(displayName || 'Console User') + '</div>';
|
|
307
|
+
html += '</div>';
|
|
308
|
+
|
|
309
|
+
// Body
|
|
310
|
+
html += '<div class="profile-popover-body">';
|
|
311
|
+
|
|
312
|
+
// Name
|
|
313
|
+
html += '<div class="profile-field">';
|
|
314
|
+
html += '<label class="profile-field-label">Display Name</label>';
|
|
315
|
+
html += '<input type="text" class="profile-field-input" id="profile-name-input" value="' + escapeAttr(displayName) + '" placeholder="Enter your name..." maxlength="50" spellcheck="false" autocomplete="off">';
|
|
316
|
+
html += '</div>';
|
|
317
|
+
|
|
318
|
+
// Avatar picker
|
|
319
|
+
html += '<div class="profile-field">';
|
|
320
|
+
html += '<label class="profile-field-label">Avatar <button class="profile-shuffle-btn" title="Shuffle">' + iconHtml('shuffle') + '</button></label>';
|
|
321
|
+
html += '<div class="profile-avatar-grid">';
|
|
322
|
+
// Upload button as first cell
|
|
323
|
+
var uploadActive = profile.avatarCustom ? ' profile-avatar-option-active' : '';
|
|
324
|
+
html += '<button class="profile-avatar-option profile-avatar-upload' + uploadActive + '" title="Upload photo">';
|
|
325
|
+
if (profile.avatarCustom) {
|
|
326
|
+
html += '<img src="' + profile.avatarCustom + '" alt="Custom" class="profile-avatar-custom-preview">';
|
|
327
|
+
} else {
|
|
328
|
+
html += '<span class="profile-avatar-upload-icon"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg></span>';
|
|
329
|
+
}
|
|
330
|
+
html += '</button>';
|
|
331
|
+
html += '<input type="file" id="profile-avatar-file" accept="image/*" style="display:none">';
|
|
332
|
+
for (var j = 0; j < AVATAR_STYLES.length; j++) {
|
|
333
|
+
var st = AVATAR_STYLES[j];
|
|
334
|
+
var activeS = (!profile.avatarCustom && currentStyle === st.id) ? ' profile-avatar-option-active' : '';
|
|
335
|
+
html += '<button class="profile-avatar-option' + activeS + '" data-style="' + st.id + '" title="' + st.name + '">';
|
|
336
|
+
html += '<img src="' + avatarUrl(st.id, seed, 40) + '" alt="' + st.name + '">';
|
|
337
|
+
html += '</button>';
|
|
338
|
+
}
|
|
339
|
+
html += '</div>';
|
|
340
|
+
html += '</div>';
|
|
341
|
+
|
|
342
|
+
// Color
|
|
343
|
+
html += '<div class="profile-field">';
|
|
344
|
+
html += '<label class="profile-field-label">Color</label>';
|
|
345
|
+
html += '<div class="profile-color-grid">';
|
|
346
|
+
for (var k = 0; k < COLORS.length; k++) {
|
|
347
|
+
var c = COLORS[k];
|
|
348
|
+
var activeC = (currentColor === c) ? ' profile-color-active' : '';
|
|
349
|
+
html += '<button class="profile-color-swatch' + activeC + '" data-color="' + c + '" style="background:' + c + '"></button>';
|
|
350
|
+
}
|
|
351
|
+
html += '</div>';
|
|
352
|
+
html += '</div>';
|
|
353
|
+
|
|
354
|
+
html += '</div>'; // close body
|
|
355
|
+
|
|
356
|
+
popoverEl.innerHTML = html;
|
|
357
|
+
|
|
358
|
+
// --- Events ---
|
|
359
|
+
popoverEl.querySelector('.profile-close-btn').addEventListener('click', function(e) {
|
|
360
|
+
e.stopPropagation();
|
|
361
|
+
hidePopover();
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
var nameInput = popoverEl.querySelector('#profile-name-input');
|
|
365
|
+
nameInput.addEventListener('input', function() {
|
|
366
|
+
profile.name = nameInput.value.trim();
|
|
367
|
+
applyToIsland();
|
|
368
|
+
updatePopoverHeader();
|
|
369
|
+
debouncedSave();
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
nameInput.addEventListener('keydown', function(e) {
|
|
373
|
+
if (e.key === 'Enter') {
|
|
374
|
+
e.preventDefault();
|
|
375
|
+
hidePopover();
|
|
376
|
+
}
|
|
377
|
+
e.stopPropagation();
|
|
378
|
+
});
|
|
379
|
+
nameInput.addEventListener('keyup', function(e) { e.stopPropagation(); });
|
|
380
|
+
nameInput.addEventListener('keypress', function(e) { e.stopPropagation(); });
|
|
381
|
+
|
|
382
|
+
// Avatar upload button
|
|
383
|
+
var uploadBtn = popoverEl.querySelector('.profile-avatar-upload');
|
|
384
|
+
var fileInput = popoverEl.querySelector('#profile-avatar-file');
|
|
385
|
+
if (uploadBtn && fileInput) {
|
|
386
|
+
uploadBtn.addEventListener('click', function() {
|
|
387
|
+
fileInput.click();
|
|
388
|
+
});
|
|
389
|
+
fileInput.addEventListener('change', function() {
|
|
390
|
+
var file = fileInput.files[0];
|
|
391
|
+
if (!file) return;
|
|
392
|
+
|
|
393
|
+
function uploadBlob(blob) {
|
|
394
|
+
blob.arrayBuffer().then(function(ab) {
|
|
395
|
+
var buf = new Uint8Array(ab);
|
|
396
|
+
fetch('/api/avatar', {
|
|
397
|
+
method: 'POST',
|
|
398
|
+
headers: { 'Content-Type': 'application/octet-stream' },
|
|
399
|
+
body: buf,
|
|
400
|
+
}).then(function(r) { return r.json(); }).then(function(data) {
|
|
401
|
+
if (data.ok) {
|
|
402
|
+
profile.avatarCustom = data.avatar;
|
|
403
|
+
applyToIsland();
|
|
404
|
+
updatePopoverHeader();
|
|
405
|
+
if (popoverEl) {
|
|
406
|
+
popoverEl.querySelectorAll('.profile-avatar-option').forEach(function(b) {
|
|
407
|
+
b.classList.remove('profile-avatar-option-active');
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
if (uploadBtn) {
|
|
411
|
+
uploadBtn.classList.add('profile-avatar-option-active');
|
|
412
|
+
uploadBtn.innerHTML = '<img src="' + data.avatar + '" alt="Custom" class="profile-avatar-custom-preview">';
|
|
413
|
+
}
|
|
414
|
+
debouncedSave();
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Load image and open position picker
|
|
421
|
+
var img = new Image();
|
|
422
|
+
var objectUrl = URL.createObjectURL(file);
|
|
423
|
+
img.onload = function() {
|
|
424
|
+
showAvatarPositioner(img, objectUrl, function(croppedBlob) {
|
|
425
|
+
URL.revokeObjectURL(objectUrl);
|
|
426
|
+
uploadBlob(croppedBlob);
|
|
427
|
+
});
|
|
428
|
+
};
|
|
429
|
+
img.src = objectUrl;
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Avatar style — clicking confirms both the style and the current previewSeed
|
|
434
|
+
popoverEl.querySelectorAll('.profile-avatar-option[data-style]').forEach(function(btn) {
|
|
435
|
+
btn.addEventListener('click', function() {
|
|
436
|
+
profile.avatarCustom = '';
|
|
437
|
+
profile.avatarStyle = btn.dataset.style;
|
|
438
|
+
profile.avatarSeed = previewSeed;
|
|
439
|
+
applyToIsland();
|
|
440
|
+
updatePopoverHeader();
|
|
441
|
+
popoverEl.querySelectorAll('.profile-avatar-option').forEach(function(b) {
|
|
442
|
+
b.classList.remove('profile-avatar-option-active');
|
|
443
|
+
});
|
|
444
|
+
btn.classList.add('profile-avatar-option-active');
|
|
445
|
+
// Reset upload button to + icon
|
|
446
|
+
var upBtn = popoverEl.querySelector('.profile-avatar-upload');
|
|
447
|
+
if (upBtn) upBtn.innerHTML = '<span class="profile-avatar-upload-icon"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg></span>';
|
|
448
|
+
debouncedSave();
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
// Shuffle button — only changes preview candidates, not the actual profile
|
|
453
|
+
popoverEl.querySelector('.profile-shuffle-btn').addEventListener('click', function(e) {
|
|
454
|
+
e.stopPropagation();
|
|
455
|
+
previewSeed = Math.random().toString(36).substring(2, 10);
|
|
456
|
+
refreshAvatarPreviews();
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
// Color swatches
|
|
460
|
+
popoverEl.querySelectorAll('.profile-color-swatch').forEach(function(btn) {
|
|
461
|
+
btn.addEventListener('click', function() {
|
|
462
|
+
profile.avatarColor = btn.dataset.color;
|
|
463
|
+
applyToIsland();
|
|
464
|
+
var bannerEl = popoverEl.querySelector('.profile-banner');
|
|
465
|
+
if (bannerEl) bannerEl.style.background = profile.avatarColor;
|
|
466
|
+
popoverEl.querySelectorAll('.profile-color-swatch').forEach(function(b) {
|
|
467
|
+
b.classList.remove('profile-color-active');
|
|
468
|
+
});
|
|
469
|
+
btn.classList.add('profile-color-active');
|
|
470
|
+
debouncedSave();
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
// Prevent clicks inside popover from closing it
|
|
475
|
+
popoverEl.addEventListener('click', function(e) {
|
|
476
|
+
e.stopPropagation();
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
var island = document.getElementById('user-island');
|
|
480
|
+
island.appendChild(popoverEl);
|
|
481
|
+
refreshIcons();
|
|
482
|
+
|
|
483
|
+
if (!profile.name) {
|
|
484
|
+
nameInput.focus();
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
setTimeout(function() {
|
|
488
|
+
document.addEventListener('click', closeOnOutside);
|
|
489
|
+
document.addEventListener('keydown', closeOnEscape);
|
|
490
|
+
}, 0);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function updatePopoverHeader() {
|
|
494
|
+
if (!popoverEl) return;
|
|
495
|
+
var img = popoverEl.querySelector('.profile-popover-avatar-img');
|
|
496
|
+
var nd = popoverEl.querySelector('.profile-name-display');
|
|
497
|
+
if (img) img.src = profile.avatarCustom
|
|
498
|
+
? profile.avatarCustom
|
|
499
|
+
: avatarUrl(profile.avatarStyle || 'thumbs', getAvatarSeed(), 80);
|
|
500
|
+
if (nd) nd.textContent = profile.name || 'Console User';
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
function refreshAvatarPreviews() {
|
|
505
|
+
if (!popoverEl) return;
|
|
506
|
+
popoverEl.querySelectorAll('.profile-avatar-option[data-style] img').forEach(function(img) {
|
|
507
|
+
var style = img.closest('.profile-avatar-option').dataset.style;
|
|
508
|
+
img.src = avatarUrl(style, previewSeed, 40);
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function closeOnOutside(e) {
|
|
513
|
+
var island = document.getElementById('user-island');
|
|
514
|
+
if (popoverEl && !popoverEl.contains(e.target) && !island.contains(e.target)) {
|
|
515
|
+
hidePopover();
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function closeOnEscape(e) {
|
|
520
|
+
if (e.key === 'Escape' && popoverEl) {
|
|
521
|
+
hidePopover();
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function hidePopover() {
|
|
526
|
+
if (popoverEl) {
|
|
527
|
+
popoverEl.remove();
|
|
528
|
+
popoverEl = null;
|
|
529
|
+
}
|
|
530
|
+
document.removeEventListener('click', closeOnOutside);
|
|
531
|
+
document.removeEventListener('keydown', closeOnEscape);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function escapeAttr(str) {
|
|
535
|
+
return str.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<');
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// --- Init ---
|
|
539
|
+
export function initProfile(_ctx) {
|
|
540
|
+
ctx = _ctx;
|
|
541
|
+
|
|
542
|
+
var island = document.getElementById('user-island');
|
|
543
|
+
if (!island) return;
|
|
544
|
+
|
|
545
|
+
var profileArea = island.querySelector('.user-island-profile');
|
|
546
|
+
if (profileArea) {
|
|
547
|
+
profileArea.addEventListener('click', function(e) {
|
|
548
|
+
e.stopPropagation();
|
|
549
|
+
showPopover();
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
var ctaEl = island.querySelector('.user-island-cta');
|
|
554
|
+
if (ctaEl) {
|
|
555
|
+
ctaEl.addEventListener('click', function(e) {
|
|
556
|
+
e.stopPropagation();
|
|
557
|
+
showPopover();
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
fetchProfile().then(function(data) {
|
|
562
|
+
if (data.name !== undefined) profile.name = data.name;
|
|
563
|
+
if (data.lang) profile.lang = data.lang;
|
|
564
|
+
if (data.avatarColor) profile.avatarColor = data.avatarColor;
|
|
565
|
+
if (data.avatarStyle) profile.avatarStyle = data.avatarStyle;
|
|
566
|
+
if (data.avatarSeed) profile.avatarSeed = data.avatarSeed;
|
|
567
|
+
if (data.avatarCustom) profile.avatarCustom = data.avatarCustom;
|
|
568
|
+
if (data.username) profileUsername = data.username;
|
|
569
|
+
|
|
570
|
+
// Auto-generate seed if none exists
|
|
571
|
+
if (!profile.avatarSeed) {
|
|
572
|
+
profile.avatarSeed = Math.random().toString(36).substring(2, 10);
|
|
573
|
+
saveProfile();
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
applyToIsland();
|
|
577
|
+
|
|
578
|
+
if (profile.lang) {
|
|
579
|
+
setSTTLang(profile.lang);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
}).catch(function(err) {
|
|
583
|
+
console.warn('[Profile] Failed to load:', err);
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
export function getProfile() {
|
|
588
|
+
return profile;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
export function getProfileLang() {
|
|
592
|
+
return profile.lang;
|
|
593
|
+
}
|
|
594
|
+
|