@alexsun-top/opencode-chat-room 0.8.1 → 0.8.3
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 +33 -0
- package/README.md +18 -62
- package/README.zh-CN.md +25 -69
- package/dist/cli.js +1008 -274
- package/package.json +10 -7
- package/packages/chat-room-channeld/README.md +42 -15
- package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
- package/packages/chat-room-channeld/src/adapter.ts +150 -7
- package/packages/chat-room-channeld/src/cli.ts +72 -5
- package/packages/chat-room-channeld/src/host.ts +41 -11
- package/packages/chat-room-channeld/src/inbound.ts +13 -4
- package/packages/chat-room-channeld/src/pg/database.ts +187 -0
- package/packages/chat-room-channeld/src/pg/migrate.ts +150 -0
- package/packages/chat-room-channeld/src/pg/schema.ts +60 -0
- package/packages/chat-room-channeld/src/pg/sql.mjs +175 -0
- package/packages/chat-room-channeld/src/pg/sqlite.ts +100 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +133 -0
- package/packages/chat-room-channeld/src/protocol.ts +53 -1
- package/packages/chat-room-channeld/src/rules.ts +7 -2
- package/packages/chat-room-channeld/src/state.ts +73 -97
- package/packages/chat-room-channeld/src/stats.ts +140 -109
- package/plugin.ts +1 -1
- package/server/assets/base.css +11 -3
- package/server/assets/chat/admin-badge.js +32 -30
- package/server/assets/chat/admin.js +198 -163
- package/server/assets/chat/announcements.js +295 -210
- package/server/assets/chat/attachment-store.js +106 -75
- package/server/assets/chat/attachments.js +686 -441
- package/server/assets/chat/chat-background.js +206 -0
- package/server/assets/chat/clipboard.js +44 -25
- package/server/assets/chat/confirm-dialog.js +36 -34
- package/server/assets/chat/copy-action.js +40 -40
- package/server/assets/chat/create-room-dialog.js +50 -48
- package/server/assets/chat/diagram-viewer.js +293 -228
- package/server/assets/chat/doc-preview.js +510 -388
- package/server/assets/chat/editor.js +423 -335
- package/server/assets/chat/events.js +637 -502
- package/server/assets/chat/files.js +476 -426
- package/server/assets/chat/history-loader.js +79 -73
- package/server/assets/chat/icons.js +9 -11
- package/server/assets/chat/image-zoom.js +239 -169
- package/server/assets/chat/index.js +6 -5
- package/server/assets/chat/install-prompt.js +86 -66
- package/server/assets/chat/integration-account-schema.js +101 -0
- package/server/assets/chat/integration-editor.js +162 -153
- package/server/assets/chat/integration-values.js +109 -100
- package/server/assets/chat/integrations.js +696 -479
- package/server/assets/chat/join-requests.js +408 -358
- package/server/assets/chat/locales/de.js +193 -194
- package/server/assets/chat/locales/es.js +193 -194
- package/server/assets/chat/locales/fr.js +193 -194
- package/server/assets/chat/locales/index.js +1 -2
- package/server/assets/chat/locales/it.js +193 -194
- package/server/assets/chat/locales/ja.js +193 -193
- package/server/assets/chat/locales/ko.js +193 -193
- package/server/assets/chat/markdown-footnotes.js +134 -102
- package/server/assets/chat/markdown.js +553 -386
- package/server/assets/chat/members.js +236 -197
- package/server/assets/chat/mentions.js +157 -133
- package/server/assets/chat/message-cache.js +40 -33
- package/server/assets/chat/message-polling.js +280 -227
- package/server/assets/chat/message-window.js +74 -55
- package/server/assets/chat/messages.js +552 -479
- package/server/assets/chat/office-preview.js +46 -45
- package/server/assets/chat/palette.js +450 -412
- package/server/assets/chat/panels.js +94 -58
- package/server/assets/chat/pwa.js +144 -73
- package/server/assets/chat/questions.js +372 -302
- package/server/assets/chat/recall.js +320 -273
- package/server/assets/chat/receipts.js +149 -122
- package/server/assets/chat/reminders.js +331 -216
- package/server/assets/chat/replies.js +165 -136
- package/server/assets/chat/resource-format.js +59 -62
- package/server/assets/chat/room-list.js +58 -55
- package/server/assets/chat/room-watcher.js +72 -50
- package/server/assets/chat/rooms.js +623 -505
- package/server/assets/chat/search.js +136 -114
- package/server/assets/chat/settings.js +229 -140
- package/server/assets/chat/shiki.js +61 -62
- package/server/assets/chat/shortcuts.js +212 -190
- package/server/assets/chat/side-pane.js +166 -131
- package/server/assets/chat/state.js +851 -707
- package/server/assets/chat/system-events.js +55 -27
- package/server/assets/chat/system-messages.js +59 -49
- package/server/assets/chat/task-form.js +178 -182
- package/server/assets/chat/task-row.js +158 -155
- package/server/assets/chat/tasks.js +653 -593
- package/server/assets/chat/viewport.js +32 -29
- package/server/assets/chat/window-controls.js +37 -0
- package/server/assets/code-highlight.css +22 -6
- package/server/assets/conversation.css +65 -16
- package/server/assets/doc-preview.css +6 -1
- package/server/assets/files.css +3 -0
- package/server/assets/monaco/integration-rules.css +1 -1
- package/server/assets/monaco/integration-rules.js +841 -533
- package/server/assets/responsive.css +32 -2
- package/server/assets/settings.css +117 -13
- package/server/assets/window-controls.css +36 -0
- package/server/channel-attachments.ts +133 -0
- package/server/channel-integration.ts +79 -26
- package/server/channels.ts +15 -5
- package/server/chat-server.ts +9 -1
- package/server/chat.html +73 -38
- package/server/manifest.webmanifest +1 -0
- package/server/routes/pages.ts +7 -5
- package/server/sw.js +346 -267
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-database.ts +5 -5
- package/src/state/pg-migrate.ts +7 -7
- package/src/state/pg-worker.mjs +2 -17
- package/src/state/sqlite-database.ts +14 -5
- package/src/state/sqlite-rooms.ts +130 -23
- package/src/state/sqlite-state-store.ts +6 -5
- package/src/state/sqlite.ts +3 -3
- package/src/web/integration-rules-editor.ts +141 -5
- package/src/web/integration-rules.ts +6 -2
- package/src/web/integration-schema.ts +7 -6
- package/packages/chat-room-channeld/dist/feishu-adapter.js +0 -1262
- package/packages/chat-room-channeld/src/feishu-adapter.ts +0 -303
- package/packages/chat-room-channeld/src/feishu-card.ts +0 -27
- package/packages/chat-room-channeld/src/feishu-inbound.ts +0 -158
- package/packages/chat-room-channeld/src/feishu-live.ts +0 -355
- package/packages/chat-room-channeld/src/feishu-send.ts +0 -342
- package/packages/chat-room-channeld/src/feishu-ws-frames.ts +0 -173
- package/server/assets/chat/forward.js +0 -69
|
@@ -1,87 +1,86 @@
|
|
|
1
1
|
// Lazy Shiki highlighting. The bundle is fetched on the first fenced code block,
|
|
2
2
|
// so a conversation without code never downloads or parses it.
|
|
3
|
-
|
|
4
3
|
const LANGUAGE_ALIASES = new Map([
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
["ts", "typescript"], ["typescript", "typescript"],
|
|
5
|
+
["tsx", "tsx"],
|
|
6
|
+
["js", "javascript"], ["javascript", "javascript"], ["mjs", "javascript"], ["cjs", "javascript"], ["node", "javascript"],
|
|
7
|
+
["jsx", "jsx"],
|
|
8
|
+
["json", "json"], ["jsonc", "json"],
|
|
9
|
+
["bash", "shellscript"], ["sh", "shellscript"], ["zsh", "shellscript"],
|
|
10
|
+
["shell", "shellscript"], ["shellscript", "shellscript"], ["console", "shellscript"],
|
|
11
|
+
["yml", "yaml"], ["yaml", "yaml"],
|
|
12
|
+
["md", "markdown"], ["markdown", "markdown"],
|
|
13
|
+
["py", "python"], ["python", "python"],
|
|
14
|
+
["rs", "rust"], ["rust", "rust"],
|
|
15
|
+
["go", "go"], ["golang", "go"],
|
|
16
|
+
["java", "java"],
|
|
17
|
+
["sql", "sql"],
|
|
18
|
+
["html", "html"], ["htm", "html"],
|
|
19
|
+
["xml", "xml"], ["svg", "xml"], ["xsl", "xml"],
|
|
20
|
+
["css", "css"],
|
|
22
21
|
]);
|
|
23
|
-
|
|
24
22
|
const pending = new Set();
|
|
25
23
|
let highlighterPromise;
|
|
26
24
|
let failed = false;
|
|
27
25
|
let warned = false;
|
|
28
|
-
|
|
29
26
|
function warnOnce(error) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
if (warned)
|
|
28
|
+
return;
|
|
29
|
+
warned = true;
|
|
30
|
+
console.warn("Syntax highlighting unavailable; showing plain code.", error);
|
|
33
31
|
}
|
|
34
|
-
|
|
35
32
|
function getHighlighter() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
if (failed)
|
|
34
|
+
return null;
|
|
35
|
+
highlighterPromise ??= import("/assets/shiki.bundle.js")
|
|
36
|
+
.then((module) => module.createHighlighter())
|
|
37
|
+
.catch((error) => {
|
|
38
|
+
failed = true;
|
|
39
|
+
warnOnce(error);
|
|
40
|
+
return null;
|
|
43
41
|
});
|
|
44
|
-
|
|
42
|
+
return highlighterPromise;
|
|
45
43
|
}
|
|
46
|
-
|
|
47
44
|
function languageOf(code) {
|
|
48
|
-
|
|
45
|
+
return (/language-(\S+)/.exec(code.className) || [])[1]?.toLowerCase() || "";
|
|
49
46
|
}
|
|
50
|
-
|
|
51
47
|
// Returns Shiki's HTML (it escapes the code text) or null for an unknown or failed language.
|
|
52
48
|
export async function highlightToHtml(code, lang) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
const language = LANGUAGE_ALIASES.get(String(lang || "").toLowerCase());
|
|
50
|
+
if (!language)
|
|
51
|
+
return null;
|
|
52
|
+
try {
|
|
53
|
+
const highlighter = await getHighlighter();
|
|
54
|
+
if (!highlighter)
|
|
55
|
+
return null;
|
|
56
|
+
return highlighter.codeToHtml(code, { lang: language, theme: "chatroom" });
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
warnOnce(error);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
63
62
|
}
|
|
64
|
-
|
|
65
63
|
export function whenShikiIdle() {
|
|
66
|
-
|
|
64
|
+
return Promise.allSettled([...pending]);
|
|
67
65
|
}
|
|
68
|
-
|
|
69
66
|
// Replaces the escaped text inside one code element, leaving the surrounding
|
|
70
67
|
// pre, toolbar, wrap state, and copy button alone.
|
|
71
68
|
export function enhanceCodeElement(code) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
const task = embed(code).catch(() => { }).finally(() => pending.delete(task));
|
|
70
|
+
pending.add(task);
|
|
71
|
+
return task;
|
|
75
72
|
}
|
|
76
|
-
|
|
77
73
|
async function embed(code) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
74
|
+
if (!LANGUAGE_ALIASES.has(languageOf(code)))
|
|
75
|
+
return;
|
|
76
|
+
const markup = await highlightToHtml(code.textContent || "", languageOf(code));
|
|
77
|
+
if (!markup || !code.isConnected)
|
|
78
|
+
return;
|
|
79
|
+
const template = document.createElement("template");
|
|
80
|
+
template.innerHTML = markup;
|
|
81
|
+
const rendered = template.content.querySelector("code");
|
|
82
|
+
if (!rendered)
|
|
83
|
+
return;
|
|
84
|
+
code.replaceChildren(...rendered.childNodes);
|
|
85
|
+
code.classList.add("shiki");
|
|
86
|
+
}
|
|
@@ -1,199 +1,221 @@
|
|
|
1
1
|
// The shortcut sheet lists genuine ChatRoom shortcuts. Alt+/ opens it; the
|
|
2
2
|
// composer keeps one visible entry and no per-control badges.
|
|
3
3
|
export function initShortcuts(app) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
lead
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const openSheet = () => {
|
|
18
|
-
if (dialog.open || document.querySelector("dialog[open]")) return;
|
|
19
|
-
app.closePanels?.();
|
|
20
|
-
app.closeMention?.();
|
|
21
|
-
dialog.showModal();
|
|
22
|
-
heading?.focus();
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
app.$("#btnShortcuts")?.addEventListener("mousedown", (event) => event.preventDefault());
|
|
26
|
-
app.$("#btnShortcuts")?.addEventListener("click", openSheet);
|
|
27
|
-
app.$("#btnCloseShortcuts")?.addEventListener("click", () => dialog.close());
|
|
28
|
-
dialog.addEventListener("click", (event) => {
|
|
29
|
-
if (event.target === dialog) dialog.close();
|
|
30
|
-
});
|
|
31
|
-
dialog.addEventListener("close", () => requestAnimationFrame(() => app.focusComposer?.()));
|
|
32
|
-
let scrollFrame = 0;
|
|
33
|
-
let scrollGeneration = 0;
|
|
34
|
-
let pageTarget = null;
|
|
35
|
-
let pageFrame = 0;
|
|
36
|
-
const cancelScroll = () => {
|
|
37
|
-
cancelAnimationFrame(scrollFrame);
|
|
38
|
-
scrollFrame = 0;
|
|
39
|
-
scrollGeneration++;
|
|
40
|
-
};
|
|
41
|
-
const cancelPageScroll = () => {
|
|
42
|
-
cancelAnimationFrame(pageFrame);
|
|
43
|
-
pageFrame = 0;
|
|
44
|
-
pageTarget = null;
|
|
45
|
-
};
|
|
46
|
-
const animateScroll = (target) => {
|
|
47
|
-
if (!thread) return;
|
|
48
|
-
cancelPageScroll();
|
|
49
|
-
const max = Math.max(0, thread.scrollHeight - thread.clientHeight);
|
|
50
|
-
const end = Math.max(0, Math.min(max, target));
|
|
51
|
-
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
52
|
-
cancelScroll();
|
|
53
|
-
thread.scrollTop = end;
|
|
54
|
-
return;
|
|
4
|
+
const dialog = app.$("#shortcutsDialog");
|
|
5
|
+
if (!dialog)
|
|
6
|
+
return;
|
|
7
|
+
const heading = app.$("#shortcutsHeading");
|
|
8
|
+
const thread = app.$("#thread");
|
|
9
|
+
const modifier = /Mac|iPhone|iPad|iPod/.test(navigator.platform || navigator.userAgent) ? "Option" : "Alt";
|
|
10
|
+
document.body.classList.toggle("is-mac", modifier === "Option");
|
|
11
|
+
document.querySelectorAll(".shortcut-mod").forEach((key) => { key.textContent = modifier; });
|
|
12
|
+
const lead = app.$("#shortcutsLead");
|
|
13
|
+
if (lead) {
|
|
14
|
+
lead._i18nValues = { modifier };
|
|
15
|
+
lead.textContent = app.t("shortcutsLead", { modifier });
|
|
55
16
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
17
|
+
const openSheet = () => {
|
|
18
|
+
if (dialog.open || document.querySelector("dialog[open]"))
|
|
19
|
+
return;
|
|
20
|
+
app.closePanels?.();
|
|
21
|
+
app.closeMention?.();
|
|
22
|
+
dialog.showModal();
|
|
23
|
+
heading?.focus();
|
|
24
|
+
};
|
|
25
|
+
app.$("#btnShortcuts")?.addEventListener("mousedown", (event) => event.preventDefault());
|
|
26
|
+
app.$("#btnShortcuts")?.addEventListener("click", openSheet);
|
|
27
|
+
app.$("#btnCloseShortcuts")?.addEventListener("click", () => dialog.close());
|
|
28
|
+
dialog.addEventListener("close", () => requestAnimationFrame(() => app.focusComposer?.()));
|
|
29
|
+
let scrollFrame = 0;
|
|
30
|
+
let scrollGeneration = 0;
|
|
31
|
+
let pageTarget = null;
|
|
32
|
+
let pageFrame = 0;
|
|
33
|
+
const cancelScroll = () => {
|
|
34
|
+
cancelAnimationFrame(scrollFrame);
|
|
64
35
|
scrollFrame = 0;
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
const progress = Math.min(1, (now - start) / duration);
|
|
68
|
-
const eased = 1 - Math.pow(1 - progress, 3);
|
|
69
|
-
thread.scrollTop = from + distance * eased;
|
|
70
|
-
if (progress < 1) scrollFrame = requestAnimationFrame(step);
|
|
71
|
-
else scrollFrame = 0;
|
|
36
|
+
scrollGeneration++;
|
|
72
37
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const pageScrollBy = (delta) => {
|
|
76
|
-
if (!thread) return;
|
|
77
|
-
cancelScroll();
|
|
78
|
-
const max = Math.max(0, thread.scrollHeight - thread.clientHeight);
|
|
79
|
-
const clamp = (value) => Math.max(0, Math.min(max, value));
|
|
80
|
-
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
81
|
-
cancelPageScroll();
|
|
82
|
-
thread.scrollTop = clamp(thread.scrollTop + delta);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const base = pageTarget ?? thread.scrollTop;
|
|
86
|
-
pageTarget = clamp(base + delta);
|
|
87
|
-
if (pageFrame) return;
|
|
88
|
-
const step = () => {
|
|
89
|
-
if (pageTarget === null) {
|
|
38
|
+
const cancelPageScroll = () => {
|
|
39
|
+
cancelAnimationFrame(pageFrame);
|
|
90
40
|
pageFrame = 0;
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const remaining = pageTarget - thread.scrollTop;
|
|
94
|
-
if (Math.abs(remaining) <= 0.6) {
|
|
95
|
-
thread.scrollTop = pageTarget;
|
|
96
41
|
pageTarget = null;
|
|
97
|
-
pageFrame = 0;
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
thread.scrollTop += remaining * 0.28;
|
|
101
|
-
pageFrame = requestAnimationFrame(step);
|
|
102
42
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
43
|
+
const animateScroll = (target) => {
|
|
44
|
+
if (!thread)
|
|
45
|
+
return;
|
|
46
|
+
cancelPageScroll();
|
|
47
|
+
const max = Math.max(0, thread.scrollHeight - thread.clientHeight);
|
|
48
|
+
const end = Math.max(0, Math.min(max, target));
|
|
49
|
+
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
50
|
+
cancelScroll();
|
|
51
|
+
thread.scrollTop = end;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
cancelScroll();
|
|
55
|
+
const generation = scrollGeneration;
|
|
56
|
+
const from = thread.scrollTop;
|
|
57
|
+
const distance = end - from;
|
|
58
|
+
const duration = Math.min(300, Math.max(140, Math.abs(distance) * 0.3));
|
|
59
|
+
const start = performance.now();
|
|
60
|
+
const step = (now) => {
|
|
61
|
+
if (generation !== scrollGeneration) {
|
|
62
|
+
scrollFrame = 0;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const progress = Math.min(1, (now - start) / duration);
|
|
66
|
+
const eased = 1 - Math.pow(1 - progress, 3);
|
|
67
|
+
thread.scrollTop = from + distance * eased;
|
|
68
|
+
if (progress < 1)
|
|
69
|
+
scrollFrame = requestAnimationFrame(step);
|
|
70
|
+
else
|
|
71
|
+
scrollFrame = 0;
|
|
72
|
+
};
|
|
73
|
+
scrollFrame = requestAnimationFrame(step);
|
|
74
|
+
};
|
|
75
|
+
const pageScrollBy = (delta) => {
|
|
76
|
+
if (!thread)
|
|
77
|
+
return;
|
|
78
|
+
cancelScroll();
|
|
79
|
+
const max = Math.max(0, thread.scrollHeight - thread.clientHeight);
|
|
80
|
+
const clamp = (value) => Math.max(0, Math.min(max, value));
|
|
81
|
+
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
82
|
+
cancelPageScroll();
|
|
83
|
+
thread.scrollTop = clamp(thread.scrollTop + delta);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const base = pageTarget ?? thread.scrollTop;
|
|
87
|
+
pageTarget = clamp(base + delta);
|
|
88
|
+
if (pageFrame)
|
|
89
|
+
return;
|
|
90
|
+
const step = () => {
|
|
91
|
+
if (pageTarget === null) {
|
|
92
|
+
pageFrame = 0;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const remaining = pageTarget - thread.scrollTop;
|
|
96
|
+
if (Math.abs(remaining) <= 0.6) {
|
|
97
|
+
thread.scrollTop = pageTarget;
|
|
98
|
+
pageTarget = null;
|
|
99
|
+
pageFrame = 0;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
thread.scrollTop += remaining * 0.28;
|
|
103
|
+
pageFrame = requestAnimationFrame(step);
|
|
104
|
+
};
|
|
105
|
+
pageFrame = requestAnimationFrame(step);
|
|
106
|
+
};
|
|
107
|
+
const cancelThreadScroll = () => {
|
|
108
|
+
cancelScroll();
|
|
109
|
+
cancelPageScroll();
|
|
110
|
+
};
|
|
111
|
+
app.cancelThreadScrollAnimation = cancelThreadScroll;
|
|
112
|
+
thread?.addEventListener("wheel", cancelThreadScroll, { passive: true });
|
|
113
|
+
thread?.addEventListener("touchmove", cancelThreadScroll, { passive: true });
|
|
114
|
+
thread?.addEventListener("pointerdown", cancelThreadScroll, { passive: true });
|
|
115
|
+
app.animateThreadScrollTo = animateScroll;
|
|
116
|
+
app.animateThreadScrollBy = pageScrollBy;
|
|
117
|
+
const scrollToEdge = (bottom) => {
|
|
118
|
+
if (!thread)
|
|
119
|
+
return;
|
|
120
|
+
const reduced = matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
121
|
+
app.state.userScrollIntentUntil = performance.now() + 700;
|
|
122
|
+
if (!bottom) {
|
|
123
|
+
app.state.jumpToLoadedTop = true;
|
|
124
|
+
clearTimeout(app.state.jumpToLoadedTopTimer);
|
|
125
|
+
app.state.jumpToLoadedTopTimer = setTimeout(() => { app.state.jumpToLoadedTop = false; }, reduced ? 150 : 800);
|
|
126
|
+
}
|
|
127
|
+
animateScroll(bottom ? thread.scrollHeight : 0);
|
|
128
|
+
};
|
|
129
|
+
app.animateRoomSwitch = (direction) => {
|
|
130
|
+
// Fluent motion lives in the selected indicator: the old bar collapses toward
|
|
131
|
+
// the direction of travel while the new bar expands from the opposite edge.
|
|
132
|
+
const oldId = app.state.previousRoomId;
|
|
133
|
+
const oldRows = oldId ? document.querySelectorAll(`#roomListChat .room-row[data-room-id="${CSS.escape(oldId)}"]`) : [];
|
|
134
|
+
for (const row of oldRows) {
|
|
135
|
+
row.classList.remove("room-switch-leave");
|
|
136
|
+
row.style.setProperty("--room-switch-origin", direction > 0 ? "bottom" : "top");
|
|
137
|
+
void row.offsetWidth;
|
|
138
|
+
row.classList.add("room-switch-leave");
|
|
139
|
+
setTimeout(() => row.classList.remove("room-switch-leave"), 220);
|
|
140
|
+
}
|
|
141
|
+
for (const row of document.querySelectorAll("#roomListChat .room-row.selected")) {
|
|
142
|
+
row.classList.remove("room-switch-enter");
|
|
143
|
+
row.style.setProperty("--room-switch-origin", direction > 0 ? "top" : "bottom");
|
|
144
|
+
void row.offsetWidth;
|
|
145
|
+
row.classList.add("room-switch-enter");
|
|
146
|
+
setTimeout(() => row.classList.remove("room-switch-enter"), 220);
|
|
147
|
+
row.scrollIntoView({ block: "nearest" });
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
app.switchRoom = (roomId, direction) => {
|
|
151
|
+
const list = app.$("#msgList");
|
|
152
|
+
const transition = app.LS.contentTransition && list && !matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
153
|
+
if (!transition || app.state.contentSwitching) {
|
|
154
|
+
if (app.state.contentSwitching)
|
|
155
|
+
return;
|
|
156
|
+
app.activateRoom(roomId);
|
|
157
|
+
app.animateRoomSwitch?.(direction);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const out = direction > 0 ? "room-content-out-next" : "room-content-out-prev";
|
|
161
|
+
const into = direction > 0 ? "room-content-in-next" : "room-content-in-prev";
|
|
162
|
+
app.state.contentSwitching = true;
|
|
163
|
+
list.classList.add(out);
|
|
164
|
+
setTimeout(() => {
|
|
165
|
+
app.activateRoom(roomId);
|
|
166
|
+
app.animateRoomSwitch?.(direction);
|
|
167
|
+
list.classList.remove(out, "room-content-in-next", "room-content-in-prev");
|
|
168
|
+
void list.offsetWidth;
|
|
169
|
+
list.classList.add(into);
|
|
170
|
+
setTimeout(() => {
|
|
171
|
+
list.classList.remove(into);
|
|
172
|
+
app.state.contentSwitching = false;
|
|
173
|
+
}, 220);
|
|
174
|
+
}, 140);
|
|
175
|
+
};
|
|
176
|
+
document.addEventListener("keydown", (event) => {
|
|
177
|
+
if (event.defaultPrevented || event.isComposing)
|
|
178
|
+
return;
|
|
179
|
+
if (!event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
|
|
180
|
+
return;
|
|
181
|
+
if (document.querySelector("dialog[open]"))
|
|
182
|
+
return;
|
|
183
|
+
if (event.key === "Home" || event.code === "Home") {
|
|
184
|
+
event.preventDefault();
|
|
185
|
+
scrollToEdge(false);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (event.key === "End" || event.code === "End") {
|
|
189
|
+
event.preventDefault();
|
|
190
|
+
scrollToEdge(true);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const digit = /^(?:Digit|Numpad)([1-9])$/.exec(event.code)?.[1] ?? (/^[1-9]$/.test(event.key) ? event.key : null);
|
|
194
|
+
if (digit) {
|
|
195
|
+
const rows = Array.from(document.querySelectorAll("#roomListChat .room-row.joined"));
|
|
196
|
+
const target = rows[Number(digit) - 1];
|
|
197
|
+
if (!target)
|
|
198
|
+
return;
|
|
199
|
+
event.preventDefault();
|
|
200
|
+
const current = rows.findIndex((row) => row.dataset.roomId === app.state.room?.id);
|
|
201
|
+
const targetIndex = Number(digit) - 1;
|
|
202
|
+
if (targetIndex === current)
|
|
203
|
+
return;
|
|
204
|
+
const direction = current < 0 || targetIndex > current ? 1 : -1;
|
|
205
|
+
const roomId = target.dataset.roomId;
|
|
206
|
+
if (roomId) {
|
|
207
|
+
if (app.switchRoom)
|
|
208
|
+
app.switchRoom(roomId, direction);
|
|
209
|
+
else {
|
|
210
|
+
app.activateRoom(roomId);
|
|
211
|
+
app.animateRoomSwitch?.(direction);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (event.key !== "/" && event.code !== "Slash")
|
|
217
|
+
return;
|
|
218
|
+
event.preventDefault();
|
|
219
|
+
openSheet();
|
|
220
|
+
});
|
|
221
|
+
}
|