Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

index.html

450 lines16.8 KB

1<!doctype html>
2<html lang="en">
3 <head>
4 <meta charset="UTF-8" />
5 <meta
6 name="viewport"
7 content="width=device-width, initial-scale=1.0, viewport-fit=cover, interactive-widget=resizes-content"
8 />
9 <meta name="theme-color" content="#0a0a0a" />
10 <link rel="icon" href="/favicon.ico" sizes="48x48" />
11 <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
12 <script>
13 (() => {
14 const LIGHT_BACKGROUND = "#ffffff";
15 const DARK_BACKGROUND = "#0a0a0a";
16 const CUSTOM_THEMES_STORAGE_KEY = "t3code:themes:v1";
17 const THEME_FOLLOW_SYSTEM_STORAGE_KEY = "t3code:theme-follow-system";
18 const THEME_APPEARANCE_MODE_STORAGE_KEY = "t3code:theme-appearance-mode";
19 const THEME_HALVES_STORAGE_KEY = "t3code:theme-halves:v1";
20 const SPLASH_COLORS = {
21 light: {
22 background: "#ffffff",
23 foreground: "#262626",
24 accent: "#4f46e5",
25 },
26 dark: {
27 background: "#0a0a0a",
28 foreground: "#f5f5f5",
29 accent: "#818cf8",
30 },
31 };
32 // These are the runtime defaults used to complete a custom palette
33 // when a stored theme omits a role. Keep them separate from the
34 // unselected splash so a partial custom theme does not flash generic
35 // app colors before React mounts.
36 const DEFAULT_THEME_PALETTES = {
37 light: {
38 background: "#fdf7fd",
39 foreground: "#501854",
40 accent: "#e33f86",
41 chrome: "#fdf7fd",
42 },
43 dark: {
44 background: "#1f1a24",
45 foreground: "#f9f8fb",
46 accent: "#a3004c",
47 chrome: "#1f1a24",
48 },
49 };
50 // Keep this small boot-time copy in sync with the built-in palettes so
51 // the selected theme is visible before the app has mounted.
52 const BUILT_IN_THEME_PALETTES = {
53 "t3-chat": {
54 light: {
55 background: "#fdf7fd",
56 foreground: "#501854",
57 accent: "#e33f86",
58 chrome: "#fdf7fd",
59 },
60 dark: {
61 background: "#1f1a24",
62 foreground: "#f9f8fb",
63 accent: "#a3004c",
64 chrome: "#1f1a24",
65 },
66 },
67 grove: {
68 light: {
69 background: "#f3f7f4",
70 foreground: "#241523",
71 accent: "#1b7d50",
72 chrome: "#f3f7f4",
73 },
74 dark: {
75 background: "#1b2821",
76 foreground: "#fffaff",
77 accent: "#69d69a",
78 chrome: "#1b2821",
79 },
80 },
81 ocean: {
82 light: {
83 background: "#f5f7f8",
84 foreground: "#241523",
85 accent: "#2672af",
86 chrome: "#f5f7f8",
87 },
88 dark: {
89 background: "#17212b",
90 foreground: "#fffaff",
91 accent: "#70b9ee",
92 chrome: "#17212b",
93 },
94 },
95 ember: {
96 light: {
97 background: "#f9f7f5",
98 foreground: "#241523",
99 accent: "#ae552a",
100 chrome: "#f9f7f5",
101 },
102 dark: {
103 background: "#291e1a",
104 foreground: "#fffaff",
105 accent: "#f09a64",
106 chrome: "#291e1a",
107 },
108 },
109 iris: {
110 light: {
111 background: "#f8f7f9",
112 foreground: "#241523",
113 accent: "#7253b9",
114 chrome: "#f8f7f9",
115 },
116 dark: {
117 background: "#1d1929",
118 foreground: "#fffaff",
119 accent: "#9d7df2",
120 chrome: "#1d1929",
121 },
122 },
123 };
124 // Keep the built-in mode list in sync with the runtime so the selected
125 // T3 Chat palette is visible before React has mounted.
126 const BUILT_IN_THEME_MODES = Object.fromEntries(
127 Object.entries(BUILT_IN_THEME_PALETTES).map(([id, palettes]) => [
128 id,
129 Object.keys(palettes),
130 ]),
131 );
132 const RESERVED_THEME_IDS = [
133 "system",
134 "light",
135 "dark",
136 "t3-chat",
137 "grove",
138 "ocean",
139 "ember",
140 "iris",
141 "t3-chat-dark",
142 "t3-grove",
143 "t3-ocean",
144 "t3-ember",
145 "t3-iris",
146 ];
147 // Update every theme-color meta so any element another layer added
148 // carries the resolved color too.
149 const setThemeColor = (color) => {
150 for (const meta of document.querySelectorAll('meta[name="theme-color"]')) {
151 meta.setAttribute("content", color);
152 }
153 };
154​
155 const isHexColor = (value) =>
156 typeof value === "string" &&
157 /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(value);
158 const isRecord = (value) =>
159 typeof value === "object" && value !== null && !Array.isArray(value);
160 const isThemeId = (value) =>
161 typeof value === "string" && /^[a-z0-9](?:[a-z0-9-]{0,47})$/.test(value);
162 const isThemeLabel = (value) =>
163 typeof value === "string" && value.trim().length > 0 && value.trim().length <= 48;
164 const isThemePreferenceMode = (value) =>
165 value === "light" || value === "dark" || value === "system";
166 const isThemeAppearance = (value) => value === "light" || value === "dark";
167 const isStoredCustomTheme = (value) => {
168 if (
169 !isRecord(value) ||
170 !isThemeId(value.id) ||
171 RESERVED_THEME_IDS.includes(value.id) ||
172 !isThemeLabel(value.label) ||
173 !isThemeAppearance(value.appearance) ||
174 !isRecord(value.colors)
175 ) {
176 return false;
177 }
178 if (value.variants === undefined) return true;
179 if (!isRecord(value.variants)) return false;
180 return Object.entries(value.variants).every(
181 ([appearance, colors]) =>
182 isThemeAppearance(appearance) &&
183 (appearance === value.appearance || isRecord(colors)),
184 );
185 };
186 const findCustomTheme = (themeId) => {
187 if (RESERVED_THEME_IDS.includes(themeId)) return null;
188 try {
189 const parsed = JSON.parse(
190 window.localStorage.getItem(CUSTOM_THEMES_STORAGE_KEY) ?? "null",
191 );
192 if (!Array.isArray(parsed)) return null;
193 return (
194 parsed.find((value) => isStoredCustomTheme(value) && value.id === themeId) ?? null
195 );
196 } catch {
197 return null;
198 }
199 };
200​
201 try {
202 const storedTheme = window.localStorage.getItem("t3code:theme");
203 const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
204 // Older builds stored the dark T3 Chat palette as its own theme id
205 // and every maintainer theme under a t3- prefix; keep those
206 // preferences readable. Mirrors the runtime's legacy alias table.
207 const LEGACY_THEME_IDS = {
208 "t3-chat-dark": "t3-chat",
209 "t3-grove": "grove",
210 "t3-ocean": "ocean",
211 "t3-ember": "ember",
212 "t3-iris": "iris",
213 };
214 const isLegacyT3ChatDark = storedTheme === "t3-chat-dark";
215 const themeId =
216 storedTheme === null ? "" : (LEGACY_THEME_IDS[storedTheme] ?? storedTheme);
217 const legacyMode = isLegacyT3ChatDark ? "dark" : null;
218 const builtInModes = BUILT_IN_THEME_MODES[themeId] ?? null;
219 const customTheme = builtInModes ? null : findCustomTheme(themeId);
220 const themeModes =
221 builtInModes ??
222 (customTheme
223 ? ["light", "dark"].filter(
224 (mode) => mode === customTheme.appearance || customTheme.variants?.[mode],
225 )
226 : null);
227 // Mirrors the runtime's isKnownThemePreference.
228 const isKnownTheme =
229 storedTheme === "light" ||
230 storedTheme === "dark" ||
231 storedTheme === "system" ||
232 themeModes !== null;
233 const theme = isKnownTheme && storedTheme ? storedTheme : "system";
234 const isThemed = isKnownTheme && themeModes !== null;
235 const baseAppearance = customTheme ? customTheme.appearance : "light";
236 const systemMode = prefersDark ? "dark" : "light";
237 const storedAppearanceMode = window.localStorage.getItem(
238 THEME_APPEARANCE_MODE_STORAGE_KEY,
239 );
240 const storedFollowSystem = window.localStorage.getItem(THEME_FOLLOW_SYSTEM_STORAGE_KEY);
241 // Mirrors the runtime's getThemePreferenceMode fallback: a bare
242 // "light"/"dark" preference names its own mode.
243 const preferenceMode =
244 theme === "light" || theme === "dark" ? theme : (legacyMode ?? baseAppearance);
245 const appearanceMode = isThemePreferenceMode(storedAppearanceMode)
246 ? storedAppearanceMode
247 : storedFollowSystem === "true"
248 ? "system"
249 : storedFollowSystem === "false"
250 ? preferenceMode
251 : theme === "system"
252 ? "system"
253 : preferenceMode;
254 // A valid mix half for the wanted appearance takes over: it decides
255 // light vs dark even when the base theme cannot render that mode.
256 // Mirrors the runtime's halves-aware resolveThemeAppearance.
257 const wantedMode = appearanceMode === "system" ? systemMode : appearanceMode;
258 let halfThemeId = null;
259 let halfCustomTheme = null;
260 try {
261 const halvesRaw = JSON.parse(
262 window.localStorage.getItem(THEME_HALVES_STORAGE_KEY) ?? "null",
263 );
264 const candidate = isRecord(halvesRaw) ? halvesRaw[wantedMode] : null;
265 if (typeof candidate === "string") {
266 const halfId = LEGACY_THEME_IDS[candidate] ?? candidate;
267 const halfBuiltIn = BUILT_IN_THEME_MODES[halfId] ?? null;
268 const halfCustom = halfBuiltIn ? null : findCustomTheme(halfId);
269 const halfModes =
270 halfBuiltIn ??
271 (halfCustom
272 ? ["light", "dark"].filter(
273 (mode) => mode === halfCustom.appearance || halfCustom.variants?.[mode],
274 )
275 : null);
276 if (halfModes && halfModes.includes(wantedMode)) {
277 halfThemeId = halfId;
278 halfCustomTheme = halfCustom;
279 }
280 }
281 } catch {
282 // A malformed mix degrades to the base preference.
283 }
284 const themeMode = !isThemed
285 ? null
286 : appearanceMode === "system"
287 ? themeModes.includes(systemMode)
288 ? systemMode
289 : baseAppearance
290 : themeModes.includes(appearanceMode)
291 ? appearanceMode
292 : baseAppearance;
293 const isDark =
294 halfThemeId !== null
295 ? wantedMode === "dark"
296 : isThemed
297 ? themeMode === "dark"
298 : appearanceMode === "system"
299 ? prefersDark
300 : appearanceMode === "dark";
301 const effectiveIsThemed = halfThemeId !== null || isThemed;
302 const effectiveThemeId = halfThemeId ?? themeId;
303 const effectiveCustomTheme = halfThemeId !== null ? halfCustomTheme : customTheme;
304 const effectiveThemeMode = halfThemeId !== null ? wantedMode : themeMode;
305 const customColors =
306 effectiveIsThemed && effectiveCustomTheme
307 ? effectiveThemeMode === effectiveCustomTheme.appearance
308 ? effectiveCustomTheme.colors
309 : (effectiveCustomTheme.variants?.[effectiveThemeMode] ??
310 effectiveCustomTheme.colors)
311 : null;
312 const customDefaults =
313 effectiveCustomTheme && effectiveThemeMode
314 ? DEFAULT_THEME_PALETTES[effectiveThemeMode]
315 : null;
316 // The runtime tolerates individual malformed colors, so fall back
317 // per role rather than dropping the theme.
318 const builtInSplash =
319 effectiveIsThemed && !effectiveCustomTheme && effectiveThemeMode
320 ? (BUILT_IN_THEME_PALETTES[effectiveThemeId]?.[effectiveThemeMode] ?? null)
321 : null;
322 const fallbackSplash = isDark ? SPLASH_COLORS.dark : SPLASH_COLORS.light;
323 const customSplash = customColors
324 ? {
325 background: isHexColor(customColors.canvas)
326 ? customColors.canvas
327 : (customDefaults?.background ?? fallbackSplash.background),
328 foreground: isHexColor(customColors.text)
329 ? customColors.text
330 : (customDefaults?.foreground ?? fallbackSplash.foreground),
331 accent: isHexColor(customColors.accent)
332 ? customColors.accent
333 : (customDefaults?.accent ?? fallbackSplash.accent),
334 }
335 : null;
336 if (effectiveIsThemed) {
337 document.documentElement.dataset.themeId = effectiveCustomTheme
338 ? effectiveCustomTheme.id
339 : effectiveThemeId;
340 } else {
341 delete document.documentElement.dataset.themeId;
342 }
343 // A resolved half is a selection even when the base theme is gone
344 // (deleting the base leaves the mix pointing at a real theme).
345 const hasSelection = halfThemeId !== null || (isKnownTheme && storedTheme !== null);
346 if (hasSelection) {
347 document.documentElement.dataset.themeSelected = "true";
348 } else {
349 delete document.documentElement.dataset.themeSelected;
350 }
351 document.documentElement.classList.toggle("dark", isDark);
352 const chromeColor = customColors
353 ? isHexColor(customColors.chrome)
354 ? customColors.chrome
355 : (customDefaults?.chrome ?? fallbackSplash.background)
356 : builtInSplash
357 ? builtInSplash.chrome
358 : isDark
359 ? DARK_BACKGROUND
360 : LIGHT_BACKGROUND;
361 document.documentElement.style.backgroundColor = chromeColor;
362 if (hasSelection) {
363 const splashColors = customSplash ?? builtInSplash ?? fallbackSplash;
364 for (const [name, value] of Object.entries(splashColors)) {
365 document.documentElement.style.setProperty(`--boot-${name}`, value);
366 }
367 }
368 setThemeColor(chromeColor);
369 } catch {
370 // Mirror the runtime's storage-failure fallback: follow the OS.
371 let prefersDark = true;
372 try {
373 prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
374 } catch {
375 // Keep the dark default when even matchMedia is unavailable.
376 }
377 delete document.documentElement.dataset.themeId;
378 delete document.documentElement.dataset.themeSelected;
379 document.documentElement.classList.toggle("dark", prefersDark);
380 const fallbackColor = prefersDark ? DARK_BACKGROUND : LIGHT_BACKGROUND;
381 document.documentElement.style.backgroundColor = fallbackColor;
382 setThemeColor(fallbackColor);
383 }
384 })();
385 </script>
386 <style>
387 html,
388 body,
389 #root {
390 width: 100%;
391 height: 100%;
392 margin: 0;
393 }
394​
395 body {
396 background: #ffffff;
397 color: #262626;
398 font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
399 }
400​
401 html.dark body {
402 background: #0a0a0a;
403 color: #f5f5f5;
404 }
405​
406 #boot-shell {
407 position: relative;
408 overflow: hidden;
409 display: flex;
410 min-height: 100%;
411 align-items: center;
412 justify-content: center;
413 background: inherit;
414 color: inherit;
415 }
416​
417 html[data-theme-selected="true"] #boot-shell {
418 background: var(--boot-background);
419 color: var(--boot-foreground);
420 }
421​
422 #boot-shell-card {
423 position: relative;
424 z-index: 1;
425 display: flex;
426 align-items: center;
427 justify-content: center;
428 width: 96px;
429 height: 96px;
430 }
431​
432 #boot-shell-logo {
433 width: 64px;
434 height: 64px;
435 object-fit: contain;
436 }
437 </style>
438 <title>T3 Code (Alpha)</title>
439 </head>
440 <body>
441 <div id="root">
442 <div id="boot-shell">
443 <div id="boot-shell-card" aria-label="T3 Code splash screen">
444 <img id="boot-shell-logo" src="/apple-touch-icon.png" alt="T3 Code" />
445 </div>
446 </div>
447 </div>
448 <script type="module" src="/src/main.tsx"></script>
449 </body>
450</html>