@alexsun-top/opencode-chat-room 0.8.2 → 0.8.4
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 +12 -0
- package/README.md +18 -62
- package/README.zh-CN.md +25 -69
- package/dist/cli.js +466 -188
- package/package.json +11 -5
- package/packages/chat-room-channeld/README.md +25 -3
- package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
- package/packages/chat-room-channeld/src/adapter.ts +5 -0
- package/packages/chat-room-channeld/src/cli.ts +72 -5
- package/packages/chat-room-channeld/src/host.ts +17 -2
- 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 +1 -0
- package/packages/chat-room-channeld/src/state.ts +73 -97
- package/packages/chat-room-channeld/src/stats.ts +140 -109
- package/server/assets/base.css +3 -1
- package/server/assets/chat/admin-badge.js +32 -30
- package/server/assets/chat/admin.js +201 -161
- package/server/assets/chat/announcements.js +302 -208
- package/server/assets/chat/attachment-store.js +116 -76
- package/server/assets/chat/attachments.js +701 -441
- package/server/assets/chat/chat-background.js +179 -156
- package/server/assets/chat/clipboard.js +45 -25
- package/server/assets/chat/confirm-dialog.js +38 -35
- package/server/assets/chat/copy-action.js +40 -41
- package/server/assets/chat/create-room-dialog.js +50 -47
- package/server/assets/chat/diagram-viewer.js +293 -236
- package/server/assets/chat/doc-preview.js +516 -443
- package/server/assets/chat/editor.js +446 -336
- package/server/assets/chat/events.js +650 -510
- package/server/assets/chat/files.js +505 -431
- package/server/assets/chat/history-loader.js +81 -73
- package/server/assets/chat/icons.js +9 -11
- package/server/assets/chat/image-zoom.js +246 -179
- package/server/assets/chat/index.js +2 -3
- package/server/assets/chat/install-prompt.js +90 -69
- package/server/assets/chat/integration-account-schema.js +91 -87
- package/server/assets/chat/integration-editor.js +162 -155
- package/server/assets/chat/integration-values.js +116 -101
- package/server/assets/chat/integrations.js +750 -626
- package/server/assets/chat/join-requests.js +415 -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 -103
- package/server/assets/chat/markdown.js +557 -404
- package/server/assets/chat/members.js +259 -197
- package/server/assets/chat/mentions.js +181 -133
- package/server/assets/chat/message-cache.js +40 -33
- package/server/assets/chat/message-polling.js +299 -227
- package/server/assets/chat/message-window.js +78 -55
- package/server/assets/chat/messages.js +562 -480
- package/server/assets/chat/office-preview.js +46 -45
- package/server/assets/chat/palette.js +464 -417
- package/server/assets/chat/panels.js +94 -79
- package/server/assets/chat/pwa.js +147 -75
- package/server/assets/chat/questions.js +374 -302
- package/server/assets/chat/recall.js +338 -273
- package/server/assets/chat/receipts.js +151 -121
- package/server/assets/chat/reminders.js +345 -214
- package/server/assets/chat/replies.js +181 -130
- 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 +76 -50
- package/server/assets/chat/rooms.js +631 -500
- package/server/assets/chat/search.js +138 -114
- package/server/assets/chat/settings.js +225 -201
- package/server/assets/chat/shiki.js +62 -63
- package/server/assets/chat/shortcuts.js +212 -189
- package/server/assets/chat/side-pane.js +161 -150
- package/server/assets/chat/state.js +860 -737
- package/server/assets/chat/system-events.js +46 -44
- package/server/assets/chat/system-messages.js +57 -56
- package/server/assets/chat/task-form.js +179 -183
- package/server/assets/chat/task-row.js +158 -155
- package/server/assets/chat/tasks.js +665 -587
- package/server/assets/chat/viewport.js +32 -29
- package/server/assets/chat/window-controls.js +32 -32
- package/server/assets/conversation.css +10 -4
- package/server/chat-server.ts +9 -1
- package/server/chat.html +3 -1
- package/server/routes/pages.ts +7 -5
- package/server/sw.js +346 -268
- package/src/web/integration-rules-editor.ts +2 -0
|
@@ -1,211 +1,235 @@
|
|
|
1
|
-
// Browser settings shared by the join page and the chat: language, theme, window frame, and the optional token.
|
|
2
1
|
export const THEMES = ["system", "light", "dark", "forest", "sand", "custom"];
|
|
3
2
|
const DEFAULT_CUSTOM_THEME = "#22695c";
|
|
4
3
|
const validColor = (value) => /^#[0-9a-f]{6}$/i.test(value) ? value : DEFAULT_CUSTOM_THEME;
|
|
5
4
|
// Relative luminance, so a dark choice gets the dark palette instead of dark text on it.
|
|
6
5
|
const isDarkColor = (color) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const channels = (color.slice(1).match(/../g) || []).map((part) => {
|
|
7
|
+
const value = parseInt(part, 16) / 255;
|
|
8
|
+
return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
9
|
+
});
|
|
10
|
+
return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2] < 0.4;
|
|
12
11
|
};
|
|
13
|
-
|
|
14
12
|
export function initSettings(app) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
$("#
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
13
|
+
const $ = app.$;
|
|
14
|
+
const dialog = $("#chatSettings");
|
|
15
|
+
if (!dialog)
|
|
16
|
+
return;
|
|
17
|
+
const tokenInput = $("#inTokenChat"), tokenHint = $("#tokenHint");
|
|
18
|
+
if (!tokenInput)
|
|
19
|
+
return;
|
|
20
|
+
const contentInput = $("#inContentTransition");
|
|
21
|
+
const pageInput = $("#inPageStep"), pageValue = $("#pageStepValue");
|
|
22
|
+
const frameSelect = $("#inWindowFrame");
|
|
23
|
+
const panelInputs = [...dialog.querySelectorAll("[data-panel-mode]")];
|
|
24
|
+
if (document.body.dataset.integrationsAdmin !== "true") {
|
|
25
|
+
$("#settingsTabIntegrations")?.remove();
|
|
26
|
+
$("#settingsPanelIntegrations")?.remove();
|
|
27
|
+
}
|
|
28
|
+
const tabs = [...dialog.querySelectorAll('[role="tab"]')];
|
|
29
|
+
const customColorInput = $("#inCustomThemeColor");
|
|
30
|
+
const scheme = matchMedia("(prefers-color-scheme: dark)");
|
|
31
|
+
let opener = null;
|
|
32
|
+
let customFrame = 0;
|
|
33
|
+
let customPersistTimer = 0;
|
|
34
|
+
let pendingCustomColor = "";
|
|
35
|
+
const CUSTOM_COLOR_PERSIST_DELAY = 300;
|
|
36
|
+
const customColor = () => validColor(app.LS.customTheme);
|
|
37
|
+
const paintCustomColor = (color) => {
|
|
38
|
+
document.documentElement.style.setProperty("--custom-bg", color);
|
|
39
|
+
document.documentElement.dataset.customDark = String(isDarkColor(color));
|
|
40
|
+
if (customColorInput)
|
|
41
|
+
customColorInput.value = color;
|
|
42
|
+
};
|
|
43
|
+
const syncCustomColor = () => {
|
|
44
|
+
const color = customColor();
|
|
45
|
+
paintCustomColor(color);
|
|
46
|
+
return color;
|
|
47
|
+
};
|
|
48
|
+
// Live drags coalesce to one paint per frame; storage and theme metadata wait.
|
|
49
|
+
const clearCustomSchedules = () => {
|
|
50
|
+
if (customFrame)
|
|
51
|
+
cancelAnimationFrame(customFrame);
|
|
52
|
+
customFrame = 0;
|
|
53
|
+
clearTimeout(customPersistTimer);
|
|
54
|
+
customPersistTimer = 0;
|
|
55
|
+
pendingCustomColor = "";
|
|
56
|
+
};
|
|
57
|
+
const scheduleCustomPaint = (color) => {
|
|
58
|
+
pendingCustomColor = color;
|
|
59
|
+
if (customFrame)
|
|
60
|
+
return;
|
|
61
|
+
customFrame = requestAnimationFrame(() => {
|
|
62
|
+
customFrame = 0;
|
|
63
|
+
paintCustomColor(pendingCustomColor);
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const commitCustomColor = (color) => {
|
|
67
|
+
clearCustomSchedules();
|
|
68
|
+
app.LS.customTheme = color;
|
|
69
|
+
if (document.documentElement.dataset.theme === "custom") {
|
|
70
|
+
paintCustomColor(color);
|
|
71
|
+
syncThemeColor();
|
|
72
|
+
}
|
|
73
|
+
else
|
|
74
|
+
applyTheme("custom", true);
|
|
75
|
+
};
|
|
76
|
+
const syncThemeColor = () => {
|
|
77
|
+
const meta = document.querySelector('meta[name="theme-color"]');
|
|
78
|
+
const token = document.documentElement.dataset.windowFrame === "borderless" ? "--surface" : "--bg";
|
|
79
|
+
const background = document.documentElement.dataset.theme === "custom" ? customColor() : getComputedStyle(document.documentElement).getPropertyValue(token).trim();
|
|
80
|
+
if (meta && background)
|
|
81
|
+
meta.content = background;
|
|
82
|
+
};
|
|
83
|
+
const syncThemeInputs = () => {
|
|
84
|
+
const stored = THEMES.includes(app.LS.theme) ? app.LS.theme : "system";
|
|
85
|
+
for (const input of dialog.querySelectorAll('input[name="theme"]'))
|
|
86
|
+
input.checked = input.value === stored;
|
|
87
|
+
if (customColorInput)
|
|
88
|
+
customColorInput.value = customColor();
|
|
89
|
+
};
|
|
90
|
+
const syncPanelInputs = () => {
|
|
91
|
+
for (const select of panelInputs)
|
|
92
|
+
select.value = app.panelMode(select.dataset.panelMode || "");
|
|
93
|
+
};
|
|
94
|
+
const applyTheme = (value, persist) => {
|
|
95
|
+
clearCustomSchedules();
|
|
96
|
+
const theme = THEMES.includes(value) ? value : "system";
|
|
97
|
+
syncCustomColor();
|
|
98
|
+
document.documentElement.dataset.theme = theme;
|
|
99
|
+
if (persist)
|
|
100
|
+
app.LS.theme = theme;
|
|
101
|
+
syncThemeInputs();
|
|
102
|
+
syncThemeColor();
|
|
103
|
+
};
|
|
104
|
+
app.setTheme = (value) => applyTheme(value, true);
|
|
105
|
+
app.settingsOpen = () => dialog.open;
|
|
106
|
+
const framePreference = () => app.LS.windowFrame === "borderless" ? "borderless" : "framed";
|
|
107
|
+
const applyWindowFrame = (mode, persist) => {
|
|
108
|
+
const preference = mode === "borderless" ? "borderless" : "framed";
|
|
109
|
+
document.documentElement.dataset.windowFrame = preference;
|
|
110
|
+
if (frameSelect)
|
|
111
|
+
frameSelect.value = preference;
|
|
112
|
+
if (persist)
|
|
113
|
+
app.LS.windowFrame = preference;
|
|
114
|
+
syncThemeColor();
|
|
115
|
+
};
|
|
116
|
+
app.setWindowFrame = (value) => applyWindowFrame(value, true);
|
|
117
|
+
// One tab stop for the whole tablist; arrow keys move selection like a native tab widget.
|
|
118
|
+
const activateTab = (name, { focus = false } = {}) => {
|
|
119
|
+
for (const tab of tabs) {
|
|
120
|
+
const selected = tab.dataset.settingsTab === name;
|
|
121
|
+
tab.setAttribute("aria-selected", String(selected));
|
|
122
|
+
tab.tabIndex = selected ? 0 : -1;
|
|
123
|
+
const panel = document.getElementById(tab.getAttribute("aria-controls") || "");
|
|
124
|
+
if (panel)
|
|
125
|
+
panel.hidden = !selected;
|
|
126
|
+
if (selected && focus)
|
|
127
|
+
tab.focus();
|
|
128
|
+
}
|
|
129
|
+
if (name === "integrations")
|
|
130
|
+
app.loadIntegrations?.();
|
|
131
|
+
};
|
|
132
|
+
const onTabKey = (event) => {
|
|
133
|
+
const index = event.target instanceof HTMLElement ? tabs.indexOf(event.target) : -1;
|
|
134
|
+
if (index < 0)
|
|
135
|
+
return;
|
|
136
|
+
const step = event.key === "ArrowUp" || event.key === "ArrowLeft" ? -1 : event.key === "ArrowDown" || event.key === "ArrowRight" ? 1 : 0;
|
|
137
|
+
const target = event.key === "Home" ? 0 : event.key === "End" ? tabs.length - 1 : step ? (index + step + tabs.length) % tabs.length : -1;
|
|
138
|
+
if (target < 0)
|
|
139
|
+
return;
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
activateTab(tabs[target].dataset.settingsTab, { focus: true });
|
|
142
|
+
};
|
|
110
143
|
for (const tab of tabs) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
tab.tabIndex = selected ? 0 : -1;
|
|
114
|
-
const panel = document.getElementById(tab.getAttribute("aria-controls"));
|
|
115
|
-
if (panel) panel.hidden = !selected;
|
|
116
|
-
if (selected && focus) tab.focus();
|
|
144
|
+
tab.addEventListener("click", () => activateTab(tab.dataset.settingsTab));
|
|
145
|
+
tab.addEventListener("keydown", onTabKey);
|
|
117
146
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
147
|
+
const open = ({ token = false } = {}) => {
|
|
148
|
+
app.closePanels?.();
|
|
149
|
+
syncThemeInputs();
|
|
150
|
+
syncPanelInputs();
|
|
151
|
+
applyWindowFrame(framePreference(), false);
|
|
152
|
+
if (contentInput)
|
|
153
|
+
contentInput.checked = app.LS.contentTransition;
|
|
154
|
+
if (pageInput)
|
|
155
|
+
pageInput.value = String(app.LS.pageStep);
|
|
156
|
+
if (pageValue)
|
|
157
|
+
pageValue.textContent = `${app.LS.pageStep}%`;
|
|
158
|
+
tokenInput.value = app.LS.token;
|
|
159
|
+
if (tokenHint)
|
|
160
|
+
tokenHint.hidden = !token;
|
|
161
|
+
if (dialog.open) {
|
|
162
|
+
if (token) {
|
|
163
|
+
activateTab("connection");
|
|
164
|
+
tokenInput.focus();
|
|
165
|
+
}
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
169
|
+
opener?.setAttribute("aria-expanded", "true");
|
|
170
|
+
activateTab(token ? "connection" : "general");
|
|
171
|
+
dialog.showModal();
|
|
172
|
+
(token ? tokenInput : $("#localeSelectSettings"))?.focus();
|
|
173
|
+
};
|
|
174
|
+
app.openSettings = () => open();
|
|
175
|
+
app.openChatSettings = () => open({ token: true });
|
|
176
|
+
$("#btnSettings")?.addEventListener("click", () => app.openSettings());
|
|
177
|
+
$("#btnJoinSettings")?.addEventListener("click", () => app.openSettings());
|
|
178
|
+
const close = () => {
|
|
179
|
+
opener?.setAttribute("aria-expanded", "false");
|
|
180
|
+
dialog.close();
|
|
181
|
+
};
|
|
182
|
+
$("#btnCloseSettings")?.addEventListener("click", close);
|
|
183
|
+
dialog.addEventListener("cancel", () => opener?.setAttribute("aria-expanded", "false"));
|
|
184
|
+
pageInput?.addEventListener("input", () => {
|
|
185
|
+
app.LS.pageStep = Number(pageInput.value);
|
|
186
|
+
pageInput.value = String(app.LS.pageStep);
|
|
187
|
+
if (pageValue)
|
|
188
|
+
pageValue.textContent = `${app.LS.pageStep}%`;
|
|
189
|
+
});
|
|
190
|
+
customColorInput?.addEventListener("input", () => {
|
|
191
|
+
const color = validColor(customColorInput.value);
|
|
192
|
+
scheduleCustomPaint(color);
|
|
193
|
+
clearTimeout(customPersistTimer);
|
|
194
|
+
customPersistTimer = setTimeout(() => {
|
|
195
|
+
customPersistTimer = 0;
|
|
196
|
+
commitCustomColor(validColor(customColorInput.value));
|
|
197
|
+
}, CUSTOM_COLOR_PERSIST_DELAY);
|
|
198
|
+
});
|
|
199
|
+
// Release commits the final color and flushes both the paint and storage at once.
|
|
200
|
+
customColorInput?.addEventListener("change", () => {
|
|
201
|
+
commitCustomColor(validColor(customColorInput.value));
|
|
202
|
+
});
|
|
203
|
+
dialog.addEventListener("change", (event) => {
|
|
204
|
+
if (event.target instanceof HTMLInputElement && event.target.name === "theme")
|
|
205
|
+
app.setTheme(event.target.value);
|
|
206
|
+
if (frameSelect && event.target === frameSelect)
|
|
207
|
+
app.setWindowFrame(frameSelect.value === "borderless" ? "borderless" : "framed");
|
|
208
|
+
if (event.target instanceof HTMLSelectElement && event.target.dataset.panelMode) {
|
|
209
|
+
app.setPanelMode(event.target.dataset.panelMode, event.target.value);
|
|
210
|
+
}
|
|
211
|
+
if (contentInput && event.target === contentInput)
|
|
212
|
+
app.LS.contentTransition = contentInput.checked;
|
|
213
|
+
if (pageInput && event.target === pageInput) {
|
|
214
|
+
app.LS.pageStep = Number(pageInput.value);
|
|
215
|
+
pageInput.value = String(app.LS.pageStep);
|
|
216
|
+
if (pageValue)
|
|
217
|
+
pageValue.textContent = `${app.LS.pageStep}%`;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
dialog.addEventListener("close", () => {
|
|
221
|
+
const target = opener;
|
|
222
|
+
opener = null;
|
|
223
|
+
if (target?.isConnected)
|
|
224
|
+
target.setAttribute("aria-expanded", "false");
|
|
225
|
+
if (app.focusChatComposer?.({ force: true }))
|
|
226
|
+
return;
|
|
227
|
+
if (target?.isConnected)
|
|
228
|
+
target.focus({ preventScroll: true });
|
|
229
|
+
});
|
|
230
|
+
// The palette follows the system through its media query; only the browser chrome needs a nudge.
|
|
231
|
+
scheme.addEventListener("change", () => { if (app.LS.theme === "system")
|
|
232
|
+
syncThemeColor(); });
|
|
233
|
+
applyTheme(app.LS.theme, false);
|
|
138
234
|
applyWindowFrame(framePreference(), false);
|
|
139
|
-
|
|
140
|
-
if (pageInput) pageInput.value = String(app.LS.pageStep);
|
|
141
|
-
if (pageValue) pageValue.textContent = `${app.LS.pageStep}%`;
|
|
142
|
-
tokenInput.value = app.LS.token;
|
|
143
|
-
if (tokenHint) tokenHint.hidden = !token;
|
|
144
|
-
if (dialog.open) {
|
|
145
|
-
if (token) {
|
|
146
|
-
activateTab("connection");
|
|
147
|
-
tokenInput.focus();
|
|
148
|
-
}
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
152
|
-
opener?.setAttribute("aria-expanded", "true");
|
|
153
|
-
activateTab(token ? "connection" : "general");
|
|
154
|
-
dialog.showModal();
|
|
155
|
-
(token ? tokenInput : $("#localeSelectSettings"))?.focus();
|
|
156
|
-
};
|
|
157
|
-
app.openSettings = () => open();
|
|
158
|
-
app.openChatSettings = () => open({ token: true });
|
|
159
|
-
|
|
160
|
-
$("#btnSettings")?.addEventListener("click", () => app.openSettings());
|
|
161
|
-
$("#btnJoinSettings")?.addEventListener("click", () => app.openSettings());
|
|
162
|
-
const close = () => {
|
|
163
|
-
opener?.setAttribute("aria-expanded", "false");
|
|
164
|
-
dialog.close();
|
|
165
|
-
};
|
|
166
|
-
$("#btnCloseSettings")?.addEventListener("click", close);
|
|
167
|
-
dialog.addEventListener("cancel", () => opener?.setAttribute("aria-expanded", "false"));
|
|
168
|
-
pageInput?.addEventListener("input", () => {
|
|
169
|
-
app.LS.pageStep = pageInput.value;
|
|
170
|
-
pageInput.value = String(app.LS.pageStep);
|
|
171
|
-
if (pageValue) pageValue.textContent = `${app.LS.pageStep}%`;
|
|
172
|
-
});
|
|
173
|
-
customColorInput?.addEventListener("input", () => {
|
|
174
|
-
const color = validColor(customColorInput.value);
|
|
175
|
-
scheduleCustomPaint(color);
|
|
176
|
-
clearTimeout(customPersistTimer);
|
|
177
|
-
customPersistTimer = setTimeout(() => {
|
|
178
|
-
customPersistTimer = 0;
|
|
179
|
-
commitCustomColor(validColor(customColorInput.value));
|
|
180
|
-
}, CUSTOM_COLOR_PERSIST_DELAY);
|
|
181
|
-
});
|
|
182
|
-
// Release commits the final color and flushes both the paint and storage at once.
|
|
183
|
-
customColorInput?.addEventListener("change", () => {
|
|
184
|
-
commitCustomColor(validColor(customColorInput.value));
|
|
185
|
-
});
|
|
186
|
-
dialog.addEventListener("change", (event) => {
|
|
187
|
-
if (event.target instanceof HTMLInputElement && event.target.name === "theme") app.setTheme(event.target.value);
|
|
188
|
-
if (event.target === frameSelect) app.setWindowFrame(frameSelect.value);
|
|
189
|
-
if (event.target instanceof HTMLSelectElement && event.target.dataset.panelMode) {
|
|
190
|
-
app.setPanelMode(event.target.dataset.panelMode, event.target.value);
|
|
191
|
-
}
|
|
192
|
-
if (event.target === contentInput) app.LS.contentTransition = contentInput.checked;
|
|
193
|
-
if (event.target === pageInput) {
|
|
194
|
-
app.LS.pageStep = pageInput.value;
|
|
195
|
-
pageInput.value = String(app.LS.pageStep);
|
|
196
|
-
if (pageValue) pageValue.textContent = `${app.LS.pageStep}%`;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
dialog.addEventListener("close", () => {
|
|
200
|
-
const target = opener;
|
|
201
|
-
opener = null;
|
|
202
|
-
if (target?.isConnected) target.setAttribute("aria-expanded", "false");
|
|
203
|
-
if (app.focusChatComposer?.({ force: true })) return;
|
|
204
|
-
if (target?.isConnected) target.focus({ preventScroll: true });
|
|
205
|
-
});
|
|
206
|
-
// The palette follows the system through its media query; only the browser chrome needs a nudge.
|
|
207
|
-
scheme.addEventListener("change", () => { if (app.LS.theme === "system") syncThemeColor(); });
|
|
208
|
-
|
|
209
|
-
applyTheme(app.LS.theme, false);
|
|
210
|
-
applyWindowFrame(framePreference(), false);
|
|
211
|
-
}
|
|
235
|
+
}
|
|
@@ -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
|
-
let highlighterPromise;
|
|
23
|
+
let highlighterPromise = null;
|
|
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
|
+
}
|