@alexsun-top/opencode-chat-room 0.8.2 → 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.
Files changed (92) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +18 -62
  3. package/README.zh-CN.md +25 -69
  4. package/dist/cli.js +466 -188
  5. package/package.json +8 -5
  6. package/packages/chat-room-channeld/README.md +25 -3
  7. package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
  8. package/packages/chat-room-channeld/src/adapter.ts +5 -0
  9. package/packages/chat-room-channeld/src/cli.ts +72 -5
  10. package/packages/chat-room-channeld/src/host.ts +17 -2
  11. package/packages/chat-room-channeld/src/pg/database.ts +187 -0
  12. package/packages/chat-room-channeld/src/pg/migrate.ts +150 -0
  13. package/packages/chat-room-channeld/src/pg/schema.ts +60 -0
  14. package/packages/chat-room-channeld/src/pg/sql.mjs +175 -0
  15. package/packages/chat-room-channeld/src/pg/sqlite.ts +100 -0
  16. package/packages/chat-room-channeld/src/pg/worker.mjs +133 -0
  17. package/packages/chat-room-channeld/src/protocol.ts +1 -0
  18. package/packages/chat-room-channeld/src/state.ts +73 -97
  19. package/packages/chat-room-channeld/src/stats.ts +140 -109
  20. package/server/assets/base.css +3 -1
  21. package/server/assets/chat/admin-badge.js +32 -30
  22. package/server/assets/chat/admin.js +198 -161
  23. package/server/assets/chat/announcements.js +295 -208
  24. package/server/assets/chat/attachment-store.js +106 -75
  25. package/server/assets/chat/attachments.js +686 -441
  26. package/server/assets/chat/chat-background.js +185 -156
  27. package/server/assets/chat/clipboard.js +44 -25
  28. package/server/assets/chat/confirm-dialog.js +36 -33
  29. package/server/assets/chat/copy-action.js +40 -40
  30. package/server/assets/chat/create-room-dialog.js +50 -47
  31. package/server/assets/chat/diagram-viewer.js +293 -234
  32. package/server/assets/chat/doc-preview.js +507 -441
  33. package/server/assets/chat/editor.js +423 -335
  34. package/server/assets/chat/events.js +637 -510
  35. package/server/assets/chat/files.js +476 -430
  36. package/server/assets/chat/history-loader.js +79 -73
  37. package/server/assets/chat/icons.js +9 -11
  38. package/server/assets/chat/image-zoom.js +239 -176
  39. package/server/assets/chat/index.js +2 -3
  40. package/server/assets/chat/install-prompt.js +86 -66
  41. package/server/assets/chat/integration-account-schema.js +88 -86
  42. package/server/assets/chat/integration-editor.js +162 -153
  43. package/server/assets/chat/integration-values.js +109 -100
  44. package/server/assets/chat/integrations.js +689 -622
  45. package/server/assets/chat/join-requests.js +408 -358
  46. package/server/assets/chat/locales/de.js +193 -194
  47. package/server/assets/chat/locales/es.js +193 -194
  48. package/server/assets/chat/locales/fr.js +193 -194
  49. package/server/assets/chat/locales/index.js +1 -2
  50. package/server/assets/chat/locales/it.js +193 -194
  51. package/server/assets/chat/locales/ja.js +193 -193
  52. package/server/assets/chat/locales/ko.js +193 -193
  53. package/server/assets/chat/markdown-footnotes.js +134 -102
  54. package/server/assets/chat/markdown.js +547 -403
  55. package/server/assets/chat/members.js +236 -197
  56. package/server/assets/chat/mentions.js +157 -133
  57. package/server/assets/chat/message-cache.js +40 -33
  58. package/server/assets/chat/message-polling.js +280 -227
  59. package/server/assets/chat/message-window.js +74 -55
  60. package/server/assets/chat/messages.js +552 -480
  61. package/server/assets/chat/office-preview.js +46 -45
  62. package/server/assets/chat/palette.js +450 -417
  63. package/server/assets/chat/panels.js +94 -78
  64. package/server/assets/chat/pwa.js +144 -73
  65. package/server/assets/chat/questions.js +372 -302
  66. package/server/assets/chat/recall.js +320 -273
  67. package/server/assets/chat/receipts.js +149 -121
  68. package/server/assets/chat/reminders.js +331 -214
  69. package/server/assets/chat/replies.js +165 -130
  70. package/server/assets/chat/resource-format.js +59 -62
  71. package/server/assets/chat/room-list.js +58 -55
  72. package/server/assets/chat/room-watcher.js +72 -50
  73. package/server/assets/chat/rooms.js +623 -500
  74. package/server/assets/chat/search.js +136 -114
  75. package/server/assets/chat/settings.js +223 -200
  76. package/server/assets/chat/shiki.js +61 -62
  77. package/server/assets/chat/shortcuts.js +212 -187
  78. package/server/assets/chat/side-pane.js +160 -150
  79. package/server/assets/chat/state.js +849 -735
  80. package/server/assets/chat/system-events.js +45 -43
  81. package/server/assets/chat/system-messages.js +57 -56
  82. package/server/assets/chat/task-form.js +178 -182
  83. package/server/assets/chat/task-row.js +158 -155
  84. package/server/assets/chat/tasks.js +653 -587
  85. package/server/assets/chat/viewport.js +32 -29
  86. package/server/assets/chat/window-controls.js +32 -32
  87. package/server/assets/conversation.css +10 -4
  88. package/server/chat-server.ts +9 -1
  89. package/server/chat.html +2 -1
  90. package/server/routes/pages.ts +7 -5
  91. package/server/sw.js +346 -268
  92. package/src/web/integration-rules-editor.ts +2 -0
@@ -4,208 +4,231 @@ const DEFAULT_CUSTOM_THEME = "#22695c";
4
4
  const validColor = (value) => /^#[0-9a-f]{6}$/i.test(value) ? value : DEFAULT_CUSTOM_THEME;
5
5
  // Relative luminance, so a dark choice gets the dark palette instead of dark text on it.
6
6
  const isDarkColor = (color) => {
7
- const channels = color.slice(1).match(/../g).map((part) => {
8
- const value = parseInt(part, 16) / 255;
9
- return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
10
- });
11
- return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2] < 0.4;
7
+ const channels = color.slice(1).match(/../g).map((part) => {
8
+ const value = parseInt(part, 16) / 255;
9
+ return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
10
+ });
11
+ return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2] < 0.4;
12
12
  };
13
-
14
13
  export function initSettings(app) {
15
- const $ = app.$;
16
- const dialog = $("#chatSettings");
17
- if (!dialog) return;
18
- const tokenInput = $("#inTokenChat"), tokenHint = $("#tokenHint");
19
- const contentInput = $("#inContentTransition");
20
- const pageInput = $("#inPageStep"), pageValue = $("#pageStepValue");
21
- const frameSelect = $("#inWindowFrame");
22
- const panelInputs = [...dialog.querySelectorAll("[data-panel-mode]")];
23
- if (document.body.dataset.integrationsAdmin !== "true") {
24
- $("#settingsTabIntegrations")?.remove();
25
- $("#settingsPanelIntegrations")?.remove();
26
- }
27
- const tabs = [...dialog.querySelectorAll('[role="tab"]')];
28
- const customColorInput = $("#inCustomThemeColor");
29
- const scheme = matchMedia("(prefers-color-scheme: dark)");
30
- let opener = null;
31
- let customFrame = 0;
32
- let customPersistTimer = 0;
33
- let pendingCustomColor = "";
34
- const CUSTOM_COLOR_PERSIST_DELAY = 300;
35
-
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) customColorInput.value = color;
41
- };
42
- const syncCustomColor = () => {
43
- const color = customColor();
44
- paintCustomColor(color);
45
- return color;
46
- };
47
- // Live drags coalesce to one paint per frame; storage and theme metadata wait.
48
- const clearCustomSchedules = () => {
49
- if (customFrame) cancelAnimationFrame(customFrame);
50
- customFrame = 0;
51
- clearTimeout(customPersistTimer);
52
- customPersistTimer = 0;
53
- pendingCustomColor = "";
54
- };
55
- const scheduleCustomPaint = (color) => {
56
- pendingCustomColor = color;
57
- if (customFrame) return;
58
- customFrame = requestAnimationFrame(() => {
59
- customFrame = 0;
60
- paintCustomColor(pendingCustomColor);
61
- });
62
- };
63
- const commitCustomColor = (color) => {
64
- clearCustomSchedules();
65
- app.LS.customTheme = color;
66
- if (document.documentElement.dataset.theme === "custom") {
67
- paintCustomColor(color);
68
- syncThemeColor();
69
- } else applyTheme("custom", true);
70
- };
71
-
72
- const syncThemeColor = () => {
73
- const meta = document.querySelector('meta[name="theme-color"]');
74
- const token = document.documentElement.dataset.windowFrame === "borderless" ? "--surface" : "--bg";
75
- const background = document.documentElement.dataset.theme === "custom" ? customColor() : getComputedStyle(document.documentElement).getPropertyValue(token).trim();
76
- if (meta && background) meta.content = background;
77
- };
78
- const syncThemeInputs = () => {
79
- const stored = THEMES.includes(app.LS.theme) ? app.LS.theme : "system";
80
- for (const input of dialog.querySelectorAll('input[name="theme"]')) input.checked = input.value === stored;
81
- if (customColorInput) customColorInput.value = customColor();
82
- };
83
- const syncPanelInputs = () => {
84
- for (const select of panelInputs) select.value = app.panelMode(select.dataset.panelMode);
85
- };
86
- const applyTheme = (value, persist) => {
87
- clearCustomSchedules();
88
- const theme = THEMES.includes(value) ? value : "system";
89
- syncCustomColor();
90
- document.documentElement.dataset.theme = theme;
91
- if (persist) app.LS.theme = theme;
92
- syncThemeInputs();
93
- syncThemeColor();
94
- };
95
- app.setTheme = (value) => applyTheme(value, true);
96
- app.settingsOpen = () => dialog.open;
97
-
98
- const framePreference = () => app.LS.windowFrame === "borderless" ? "borderless" : "framed";
99
- const applyWindowFrame = (mode, persist) => {
100
- const preference = mode === "borderless" ? "borderless" : "framed";
101
- document.documentElement.dataset.windowFrame = preference;
102
- if (frameSelect) frameSelect.value = preference;
103
- if (persist) app.LS.windowFrame = preference;
104
- syncThemeColor();
105
- };
106
- app.setWindowFrame = (value) => applyWindowFrame(value, true);
107
-
108
- // One tab stop for the whole tablist; arrow keys move selection like a native tab widget.
109
- const activateTab = (name, { focus = false } = {}) => {
14
+ const $ = app.$;
15
+ const dialog = $("#chatSettings");
16
+ if (!dialog)
17
+ return;
18
+ const tokenInput = $("#inTokenChat"), tokenHint = $("#tokenHint");
19
+ const contentInput = $("#inContentTransition");
20
+ const pageInput = $("#inPageStep"), pageValue = $("#pageStepValue");
21
+ const frameSelect = $("#inWindowFrame");
22
+ const panelInputs = [...dialog.querySelectorAll("[data-panel-mode]")];
23
+ if (document.body.dataset.integrationsAdmin !== "true") {
24
+ $("#settingsTabIntegrations")?.remove();
25
+ $("#settingsPanelIntegrations")?.remove();
26
+ }
27
+ const tabs = [...dialog.querySelectorAll('[role="tab"]')];
28
+ const customColorInput = $("#inCustomThemeColor");
29
+ const scheme = matchMedia("(prefers-color-scheme: dark)");
30
+ let opener = null;
31
+ let customFrame = 0;
32
+ let customPersistTimer = 0;
33
+ let pendingCustomColor = "";
34
+ const CUSTOM_COLOR_PERSIST_DELAY = 300;
35
+ const customColor = () => validColor(app.LS.customTheme);
36
+ const paintCustomColor = (color) => {
37
+ document.documentElement.style.setProperty("--custom-bg", color);
38
+ document.documentElement.dataset.customDark = String(isDarkColor(color));
39
+ if (customColorInput)
40
+ customColorInput.value = color;
41
+ };
42
+ const syncCustomColor = () => {
43
+ const color = customColor();
44
+ paintCustomColor(color);
45
+ return color;
46
+ };
47
+ // Live drags coalesce to one paint per frame; storage and theme metadata wait.
48
+ const clearCustomSchedules = () => {
49
+ if (customFrame)
50
+ cancelAnimationFrame(customFrame);
51
+ customFrame = 0;
52
+ clearTimeout(customPersistTimer);
53
+ customPersistTimer = 0;
54
+ pendingCustomColor = "";
55
+ };
56
+ const scheduleCustomPaint = (color) => {
57
+ pendingCustomColor = color;
58
+ if (customFrame)
59
+ return;
60
+ customFrame = requestAnimationFrame(() => {
61
+ customFrame = 0;
62
+ paintCustomColor(pendingCustomColor);
63
+ });
64
+ };
65
+ const commitCustomColor = (color) => {
66
+ clearCustomSchedules();
67
+ app.LS.customTheme = color;
68
+ if (document.documentElement.dataset.theme === "custom") {
69
+ paintCustomColor(color);
70
+ syncThemeColor();
71
+ }
72
+ else
73
+ applyTheme("custom", true);
74
+ };
75
+ const syncThemeColor = () => {
76
+ const meta = document.querySelector('meta[name="theme-color"]');
77
+ const token = document.documentElement.dataset.windowFrame === "borderless" ? "--surface" : "--bg";
78
+ const background = document.documentElement.dataset.theme === "custom" ? customColor() : getComputedStyle(document.documentElement).getPropertyValue(token).trim();
79
+ if (meta && background)
80
+ meta.content = background;
81
+ };
82
+ const syncThemeInputs = () => {
83
+ const stored = THEMES.includes(app.LS.theme) ? app.LS.theme : "system";
84
+ for (const input of dialog.querySelectorAll('input[name="theme"]'))
85
+ input.checked = input.value === stored;
86
+ if (customColorInput)
87
+ customColorInput.value = customColor();
88
+ };
89
+ const syncPanelInputs = () => {
90
+ for (const select of panelInputs)
91
+ select.value = app.panelMode(select.dataset.panelMode);
92
+ };
93
+ const applyTheme = (value, persist) => {
94
+ clearCustomSchedules();
95
+ const theme = THEMES.includes(value) ? value : "system";
96
+ syncCustomColor();
97
+ document.documentElement.dataset.theme = theme;
98
+ if (persist)
99
+ app.LS.theme = theme;
100
+ syncThemeInputs();
101
+ syncThemeColor();
102
+ };
103
+ app.setTheme = (value) => applyTheme(value, true);
104
+ app.settingsOpen = () => dialog.open;
105
+ const framePreference = () => app.LS.windowFrame === "borderless" ? "borderless" : "framed";
106
+ const applyWindowFrame = (mode, persist) => {
107
+ const preference = mode === "borderless" ? "borderless" : "framed";
108
+ document.documentElement.dataset.windowFrame = preference;
109
+ if (frameSelect)
110
+ frameSelect.value = preference;
111
+ if (persist)
112
+ app.LS.windowFrame = preference;
113
+ syncThemeColor();
114
+ };
115
+ app.setWindowFrame = (value) => applyWindowFrame(value, true);
116
+ // One tab stop for the whole tablist; arrow keys move selection like a native tab widget.
117
+ const activateTab = (name, { focus = false } = {}) => {
118
+ for (const tab of tabs) {
119
+ const selected = tab.dataset.settingsTab === name;
120
+ tab.setAttribute("aria-selected", String(selected));
121
+ tab.tabIndex = selected ? 0 : -1;
122
+ const panel = document.getElementById(tab.getAttribute("aria-controls"));
123
+ if (panel)
124
+ panel.hidden = !selected;
125
+ if (selected && focus)
126
+ tab.focus();
127
+ }
128
+ if (name === "integrations")
129
+ app.loadIntegrations?.();
130
+ };
131
+ const onTabKey = (event) => {
132
+ const index = tabs.indexOf(event.target);
133
+ if (index < 0)
134
+ return;
135
+ const step = event.key === "ArrowUp" || event.key === "ArrowLeft" ? -1 : event.key === "ArrowDown" || event.key === "ArrowRight" ? 1 : 0;
136
+ const target = event.key === "Home" ? 0 : event.key === "End" ? tabs.length - 1 : step ? (index + step + tabs.length) % tabs.length : -1;
137
+ if (target < 0)
138
+ return;
139
+ event.preventDefault();
140
+ activateTab(tabs[target].dataset.settingsTab, { focus: true });
141
+ };
110
142
  for (const tab of tabs) {
111
- const selected = tab.dataset.settingsTab === name;
112
- tab.setAttribute("aria-selected", String(selected));
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();
143
+ tab.addEventListener("click", () => activateTab(tab.dataset.settingsTab));
144
+ tab.addEventListener("keydown", onTabKey);
117
145
  }
118
- if (name === "integrations") app.loadIntegrations?.();
119
- };
120
- const onTabKey = (event) => {
121
- const index = tabs.indexOf(event.target);
122
- if (index < 0) return;
123
- const step = event.key === "ArrowUp" || event.key === "ArrowLeft" ? -1 : event.key === "ArrowDown" || event.key === "ArrowRight" ? 1 : 0;
124
- const target = event.key === "Home" ? 0 : event.key === "End" ? tabs.length - 1 : step ? (index + step + tabs.length) % tabs.length : -1;
125
- if (target < 0) return;
126
- event.preventDefault();
127
- activateTab(tabs[target].dataset.settingsTab, { focus: true });
128
- };
129
- for (const tab of tabs) {
130
- tab.addEventListener("click", () => activateTab(tab.dataset.settingsTab));
131
- tab.addEventListener("keydown", onTabKey);
132
- }
133
-
134
- const open = ({ token = false } = {}) => {
135
- app.closePanels?.();
136
- syncThemeInputs();
137
- syncPanelInputs();
146
+ const open = ({ token = false } = {}) => {
147
+ app.closePanels?.();
148
+ syncThemeInputs();
149
+ syncPanelInputs();
150
+ applyWindowFrame(framePreference(), false);
151
+ if (contentInput)
152
+ contentInput.checked = app.LS.contentTransition;
153
+ if (pageInput)
154
+ pageInput.value = String(app.LS.pageStep);
155
+ if (pageValue)
156
+ pageValue.textContent = `${app.LS.pageStep}%`;
157
+ tokenInput.value = app.LS.token;
158
+ if (tokenHint)
159
+ tokenHint.hidden = !token;
160
+ if (dialog.open) {
161
+ if (token) {
162
+ activateTab("connection");
163
+ tokenInput.focus();
164
+ }
165
+ return;
166
+ }
167
+ opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
168
+ opener?.setAttribute("aria-expanded", "true");
169
+ activateTab(token ? "connection" : "general");
170
+ dialog.showModal();
171
+ (token ? tokenInput : $("#localeSelectSettings"))?.focus();
172
+ };
173
+ app.openSettings = () => open();
174
+ app.openChatSettings = () => open({ token: true });
175
+ $("#btnSettings")?.addEventListener("click", () => app.openSettings());
176
+ $("#btnJoinSettings")?.addEventListener("click", () => app.openSettings());
177
+ const close = () => {
178
+ opener?.setAttribute("aria-expanded", "false");
179
+ dialog.close();
180
+ };
181
+ $("#btnCloseSettings")?.addEventListener("click", close);
182
+ dialog.addEventListener("cancel", () => opener?.setAttribute("aria-expanded", "false"));
183
+ pageInput?.addEventListener("input", () => {
184
+ app.LS.pageStep = pageInput.value;
185
+ pageInput.value = String(app.LS.pageStep);
186
+ if (pageValue)
187
+ pageValue.textContent = `${app.LS.pageStep}%`;
188
+ });
189
+ customColorInput?.addEventListener("input", () => {
190
+ const color = validColor(customColorInput.value);
191
+ scheduleCustomPaint(color);
192
+ clearTimeout(customPersistTimer);
193
+ customPersistTimer = setTimeout(() => {
194
+ customPersistTimer = 0;
195
+ commitCustomColor(validColor(customColorInput.value));
196
+ }, CUSTOM_COLOR_PERSIST_DELAY);
197
+ });
198
+ // Release commits the final color and flushes both the paint and storage at once.
199
+ customColorInput?.addEventListener("change", () => {
200
+ commitCustomColor(validColor(customColorInput.value));
201
+ });
202
+ dialog.addEventListener("change", (event) => {
203
+ if (event.target instanceof HTMLInputElement && event.target.name === "theme")
204
+ app.setTheme(event.target.value);
205
+ if (event.target === frameSelect)
206
+ app.setWindowFrame(frameSelect.value);
207
+ if (event.target instanceof HTMLSelectElement && event.target.dataset.panelMode) {
208
+ app.setPanelMode(event.target.dataset.panelMode, event.target.value);
209
+ }
210
+ if (event.target === contentInput)
211
+ app.LS.contentTransition = contentInput.checked;
212
+ if (event.target === pageInput) {
213
+ app.LS.pageStep = pageInput.value;
214
+ pageInput.value = String(app.LS.pageStep);
215
+ if (pageValue)
216
+ pageValue.textContent = `${app.LS.pageStep}%`;
217
+ }
218
+ });
219
+ dialog.addEventListener("close", () => {
220
+ const target = opener;
221
+ opener = null;
222
+ if (target?.isConnected)
223
+ target.setAttribute("aria-expanded", "false");
224
+ if (app.focusChatComposer?.({ force: true }))
225
+ return;
226
+ if (target?.isConnected)
227
+ target.focus({ preventScroll: true });
228
+ });
229
+ // The palette follows the system through its media query; only the browser chrome needs a nudge.
230
+ scheme.addEventListener("change", () => { if (app.LS.theme === "system")
231
+ syncThemeColor(); });
232
+ applyTheme(app.LS.theme, false);
138
233
  applyWindowFrame(framePreference(), false);
139
- if (contentInput) contentInput.checked = app.LS.contentTransition;
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
- }
234
+ }
@@ -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
- ["ts", "typescript"], ["typescript", "typescript"],
6
- ["tsx", "tsx"],
7
- ["js", "javascript"], ["javascript", "javascript"], ["mjs", "javascript"], ["cjs", "javascript"], ["node", "javascript"],
8
- ["jsx", "jsx"],
9
- ["json", "json"], ["jsonc", "json"],
10
- ["bash", "shellscript"], ["sh", "shellscript"], ["zsh", "shellscript"],
11
- ["shell", "shellscript"], ["shellscript", "shellscript"], ["console", "shellscript"],
12
- ["yml", "yaml"], ["yaml", "yaml"],
13
- ["md", "markdown"], ["markdown", "markdown"],
14
- ["py", "python"], ["python", "python"],
15
- ["rs", "rust"], ["rust", "rust"],
16
- ["go", "go"], ["golang", "go"],
17
- ["java", "java"],
18
- ["sql", "sql"],
19
- ["html", "html"], ["htm", "html"],
20
- ["xml", "xml"], ["svg", "xml"], ["xsl", "xml"],
21
- ["css", "css"],
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
- if (warned) return;
31
- warned = true;
32
- console.warn("Syntax highlighting unavailable; showing plain code.", error);
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
- if (failed) return null;
37
- highlighterPromise ??= import("/assets/shiki.bundle.js")
38
- .then((module) => module.createHighlighter())
39
- .catch((error) => {
40
- failed = true;
41
- warnOnce(error);
42
- return null;
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
- return highlighterPromise;
42
+ return highlighterPromise;
45
43
  }
46
-
47
44
  function languageOf(code) {
48
- return (/language-(\S+)/.exec(code.className) || [])[1]?.toLowerCase() || "";
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
- const language = LANGUAGE_ALIASES.get(String(lang || "").toLowerCase());
54
- if (!language) return null;
55
- try {
56
- const highlighter = await getHighlighter();
57
- if (!highlighter) return null;
58
- return highlighter.codeToHtml(code, { lang: language, theme: "chatroom" });
59
- } catch (error) {
60
- warnOnce(error);
61
- return null;
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
- return Promise.allSettled([...pending]);
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
- const task = embed(code).catch(() => {}).finally(() => pending.delete(task));
73
- pending.add(task);
74
- return task;
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
- if (!LANGUAGE_ALIASES.has(languageOf(code))) return;
79
- const markup = await highlightToHtml(code.textContent || "", languageOf(code));
80
- if (!markup || !code.isConnected) return;
81
- const template = document.createElement("template");
82
- template.innerHTML = markup;
83
- const rendered = template.content.querySelector("code");
84
- if (!rendered) return;
85
- code.replaceChildren(...rendered.childNodes);
86
- code.classList.add("shiki");
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
+ }