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

index.html

467 lines19.1 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: "oklch(0.982446 0.010114 325.653)",
39 foreground: "oklch(0.325698 0.116116 325.037)",
40 accent: "oklch(0.591646 0.217985 0.584)",
41 chrome: "oklch(0.982446 0.010114 325.653)",
42 },
43 dark: {
44 background: "oklch(0.22813 0.020366 307.469)",
45 foreground: "oklch(0.980735 0.004092 301.426)",
46 accent: "oklch(0.460685 0.185347 4.099)",
47 chrome: "oklch(0.22813 0.020366 307.469)",
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: "oklch(0.982446 0.010114 325.653)",
56 foreground: "oklch(0.325698 0.116116 325.037)",
57 accent: "oklch(0.591646 0.217985 0.584)",
58 chrome: "oklch(0.982446 0.010114 325.653)",
59 },
60 dark: {
61 background: "oklch(0.22813 0.020366 307.469)",
62 foreground: "oklch(0.980735 0.004092 301.426)",
63 accent: "oklch(0.460685 0.185347 4.099)",
64 chrome: "oklch(0.22813 0.020366 307.469)",
65 },
66 },
67 grove: {
68 light: {
69 background: "oklch(0.972369 0.005497 157.15)",
70 foreground: "oklch(0.222003 0.03479 328.979)",
71 accent: "oklch(0.523295 0.112292 158.089)",
72 chrome: "oklch(0.972369 0.005497 157.15)",
73 },
74 dark: {
75 background: "oklch(0.260865 0.02152 162.75)",
76 foreground: "oklch(0.990339 0.008411 325.64)",
77 accent: "oklch(0.796228 0.133058 157.319)",
78 chrome: "oklch(0.260865 0.02152 162.75)",
79 },
80 },
81 ocean: {
82 light: {
83 background: "oklch(0.974199 0.002856 241.597)",
84 foreground: "oklch(0.222003 0.03479 328.979)",
85 accent: "oklch(0.536684 0.120219 247.01)",
86 chrome: "oklch(0.974199 0.002856 241.597)",
87 },
88 dark: {
89 background: "oklch(0.242641 0.024125 250.573)",
90 foreground: "oklch(0.990339 0.008411 325.64)",
91 accent: "oklch(0.758933 0.105833 241.548)",
92 chrome: "oklch(0.242641 0.024125 250.573)",
93 },
94 },
95 ember: {
96 light: {
97 background: "oklch(0.976527 0.002685 60.725)",
98 foreground: "oklch(0.222003 0.03479 328.979)",
99 accent: "oklch(0.552831 0.129438 44.656)",
100 chrome: "oklch(0.976527 0.002685 60.725)",
101 },
102 dark: {
103 background: "oklch(0.245899 0.019144 42.044)",
104 foreground: "oklch(0.990339 0.008411 325.64)",
105 accent: "oklch(0.762174 0.124117 52.082)",
106 chrome: "oklch(0.245899 0.019144 42.044)",
107 },
108 },
109 iris: {
110 light: {
111 background: "oklch(0.976531 0.003855 303.226)",
112 foreground: "oklch(0.222003 0.03479 328.979)",
113 accent: "oklch(0.525348 0.15373 294.176)",
114 chrome: "oklch(0.976531 0.003855 303.226)",
115 },
116 dark: {
117 background: "oklch(0.225975 0.031062 293.741)",
118 foreground: "oklch(0.990339 0.008411 325.64)",
119 accent: "oklch(0.671712 0.169136 293.929)",
120 chrome: "oklch(0.225975 0.031062 293.741)",
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 // The runtime decodes the same literal CSS formats into OKLCH. Keep
156 // contextual colors out: they cannot be resolved from stored data.
157 const SYSTEM_COLOR_KEYWORD =
158 /^(?:accentcolor(?:text)?|active(?:border|caption|text)|appworkspace|background|button(?:border|face|highlight|shadow|text)|canvas(?:text)?|captiontext|field(?:text)?|graytext|highlight(?:text)?|inactive(?:border|caption(?:text)?)|info(?:background|text)|linktext|mark(?:text)?|menu(?:text)?|scrollbar|selecteditem(?:text)?|threed(?:darkshadow|face|highlight|lightshadow|shadow)|visitedtext|window(?:frame|text)?)$/i;
159 const isThemeColor = (value) => {
160 if (typeof value !== "string" || typeof CSS === "undefined") return false;
161 const color = value.trim();
162 if (
163 /^(?:currentcolor|inherit|initial|revert|revert-layer|unset)$/i.test(color) ||
164 SYSTEM_COLOR_KEYWORD.test(color) ||
165 /\bfrom\b|(?:var|env|attr|calc|min|max|clamp)\(/i.test(color)
166 ) {
167 return false;
168 }
169 const isLiteralColor =
170 /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color) ||
171 /^[a-z]+$/i.test(color) ||
172 /^(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\(/i.test(color);
173 return isLiteralColor && CSS.supports("color", color);
174 };
175 const isRecord = (value) =>
176 typeof value === "object" && value !== null && !Array.isArray(value);
177 const isThemeId = (value) =>
178 typeof value === "string" && /^[a-z0-9](?:[a-z0-9-]{0,47})$/.test(value);
179 const isThemeLabel = (value) =>
180 typeof value === "string" && value.trim().length > 0 && value.trim().length <= 48;
181 const isThemePreferenceMode = (value) =>
182 value === "light" || value === "dark" || value === "system";
183 const isThemeAppearance = (value) => value === "light" || value === "dark";
184 const isStoredCustomTheme = (value) => {
185 if (
186 !isRecord(value) ||
187 !isThemeId(value.id) ||
188 RESERVED_THEME_IDS.includes(value.id) ||
189 !isThemeLabel(value.label) ||
190 !isThemeAppearance(value.appearance) ||
191 !isRecord(value.colors)
192 ) {
193 return false;
194 }
195 if (value.variants === undefined) return true;
196 if (!isRecord(value.variants)) return false;
197 return Object.entries(value.variants).every(
198 ([appearance, colors]) =>
199 isThemeAppearance(appearance) &&
200 (appearance === value.appearance || isRecord(colors)),
201 );
202 };
203 const findCustomTheme = (themeId) => {
204 if (RESERVED_THEME_IDS.includes(themeId)) return null;
205 try {
206 const parsed = JSON.parse(
207 window.localStorage.getItem(CUSTOM_THEMES_STORAGE_KEY) ?? "null",
208 );
209 if (!Array.isArray(parsed)) return null;
210 return (
211 parsed.find((value) => isStoredCustomTheme(value) && value.id === themeId) ?? null
212 );
213 } catch {
214 return null;
215 }
216 };
217​
218 try {
219 const storedTheme = window.localStorage.getItem("t3code:theme");
220 const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
221 // Older builds stored the dark T3 Chat palette as its own theme id
222 // and every maintainer theme under a t3- prefix; keep those
223 // preferences readable. Mirrors the runtime's legacy alias table.
224 const LEGACY_THEME_IDS = {
225 "t3-chat-dark": "t3-chat",
226 "t3-grove": "grove",
227 "t3-ocean": "ocean",
228 "t3-ember": "ember",
229 "t3-iris": "iris",
230 };
231 const isLegacyT3ChatDark = storedTheme === "t3-chat-dark";
232 const themeId =
233 storedTheme === null ? "" : (LEGACY_THEME_IDS[storedTheme] ?? storedTheme);
234 const legacyMode = isLegacyT3ChatDark ? "dark" : null;
235 const builtInModes = BUILT_IN_THEME_MODES[themeId] ?? null;
236 const customTheme = builtInModes ? null : findCustomTheme(themeId);
237 const themeModes =
238 builtInModes ??
239 (customTheme
240 ? ["light", "dark"].filter(
241 (mode) => mode === customTheme.appearance || customTheme.variants?.[mode],
242 )
243 : null);
244 // Mirrors the runtime's isKnownThemePreference.
245 const isKnownTheme =
246 storedTheme === "light" ||
247 storedTheme === "dark" ||
248 storedTheme === "system" ||
249 themeModes !== null;
250 const theme = isKnownTheme && storedTheme ? storedTheme : "system";
251 const isThemed = isKnownTheme && themeModes !== null;
252 const baseAppearance = customTheme ? customTheme.appearance : "light";
253 const systemMode = prefersDark ? "dark" : "light";
254 const storedAppearanceMode = window.localStorage.getItem(
255 THEME_APPEARANCE_MODE_STORAGE_KEY,
256 );
257 const storedFollowSystem = window.localStorage.getItem(THEME_FOLLOW_SYSTEM_STORAGE_KEY);
258 // Mirrors the runtime's getThemePreferenceMode fallback: a bare
259 // "light"/"dark" preference names its own mode.
260 const preferenceMode =
261 theme === "light" || theme === "dark" ? theme : (legacyMode ?? baseAppearance);
262 const appearanceMode = isThemePreferenceMode(storedAppearanceMode)
263 ? storedAppearanceMode
264 : storedFollowSystem === "true"
265 ? "system"
266 : storedFollowSystem === "false"
267 ? preferenceMode
268 : theme === "system"
269 ? "system"
270 : preferenceMode;
271 // A valid mix half for the wanted appearance takes over: it decides
272 // light vs dark even when the base theme cannot render that mode.
273 // Mirrors the runtime's halves-aware resolveThemeAppearance.
274 const wantedMode = appearanceMode === "system" ? systemMode : appearanceMode;
275 let halfThemeId = null;
276 let halfCustomTheme = null;
277 try {
278 const halvesRaw = JSON.parse(
279 window.localStorage.getItem(THEME_HALVES_STORAGE_KEY) ?? "null",
280 );
281 const candidate = isRecord(halvesRaw) ? halvesRaw[wantedMode] : null;
282 if (typeof candidate === "string") {
283 const halfId = LEGACY_THEME_IDS[candidate] ?? candidate;
284 const halfBuiltIn = BUILT_IN_THEME_MODES[halfId] ?? null;
285 const halfCustom = halfBuiltIn ? null : findCustomTheme(halfId);
286 const halfModes =
287 halfBuiltIn ??
288 (halfCustom
289 ? ["light", "dark"].filter(
290 (mode) => mode === halfCustom.appearance || halfCustom.variants?.[mode],
291 )
292 : null);
293 if (halfModes && halfModes.includes(wantedMode)) {
294 halfThemeId = halfId;
295 halfCustomTheme = halfCustom;
296 }
297 }
298 } catch {
299 // A malformed mix degrades to the base preference.
300 }
301 const themeMode = !isThemed
302 ? null
303 : appearanceMode === "system"
304 ? themeModes.includes(systemMode)
305 ? systemMode
306 : baseAppearance
307 : themeModes.includes(appearanceMode)
308 ? appearanceMode
309 : baseAppearance;
310 const isDark =
311 halfThemeId !== null
312 ? wantedMode === "dark"
313 : isThemed
314 ? themeMode === "dark"
315 : appearanceMode === "system"
316 ? prefersDark
317 : appearanceMode === "dark";
318 const effectiveIsThemed = halfThemeId !== null || isThemed;
319 const effectiveThemeId = halfThemeId ?? themeId;
320 const effectiveCustomTheme = halfThemeId !== null ? halfCustomTheme : customTheme;
321 const effectiveThemeMode = halfThemeId !== null ? wantedMode : themeMode;
322 const customColors =
323 effectiveIsThemed && effectiveCustomTheme
324 ? effectiveThemeMode === effectiveCustomTheme.appearance
325 ? effectiveCustomTheme.colors
326 : (effectiveCustomTheme.variants?.[effectiveThemeMode] ??
327 effectiveCustomTheme.colors)
328 : null;
329 const customDefaults =
330 effectiveCustomTheme && effectiveThemeMode
331 ? DEFAULT_THEME_PALETTES[effectiveThemeMode]
332 : null;
333 // The runtime tolerates individual malformed colors, so fall back
334 // per role rather than dropping the theme.
335 const builtInSplash =
336 effectiveIsThemed && !effectiveCustomTheme && effectiveThemeMode
337 ? (BUILT_IN_THEME_PALETTES[effectiveThemeId]?.[effectiveThemeMode] ?? null)
338 : null;
339 const fallbackSplash = isDark ? SPLASH_COLORS.dark : SPLASH_COLORS.light;
340 const customSplash = customColors
341 ? {
342 background: isThemeColor(customColors.canvas)
343 ? customColors.canvas
344 : (customDefaults?.background ?? fallbackSplash.background),
345 foreground: isThemeColor(customColors.text)
346 ? customColors.text
347 : (customDefaults?.foreground ?? fallbackSplash.foreground),
348 accent: isThemeColor(customColors.accent)
349 ? customColors.accent
350 : (customDefaults?.accent ?? fallbackSplash.accent),
351 }
352 : null;
353 if (effectiveIsThemed) {
354 document.documentElement.dataset.themeId = effectiveCustomTheme
355 ? effectiveCustomTheme.id
356 : effectiveThemeId;
357 } else {
358 delete document.documentElement.dataset.themeId;
359 }
360 // A resolved half is a selection even when the base theme is gone
361 // (deleting the base leaves the mix pointing at a real theme).
362 const hasSelection = halfThemeId !== null || (isKnownTheme && storedTheme !== null);
363 if (hasSelection) {
364 document.documentElement.dataset.themeSelected = "true";
365 } else {
366 delete document.documentElement.dataset.themeSelected;
367 }
368 document.documentElement.classList.toggle("dark", isDark);
369 const chromeColor = customColors
370 ? isThemeColor(customColors.chrome)
371 ? customColors.chrome
372 : (customDefaults?.chrome ?? fallbackSplash.background)
373 : builtInSplash
374 ? builtInSplash.chrome
375 : isDark
376 ? DARK_BACKGROUND
377 : LIGHT_BACKGROUND;
378 document.documentElement.style.backgroundColor = chromeColor;
379 if (hasSelection) {
380 const splashColors = customSplash ?? builtInSplash ?? fallbackSplash;
381 for (const [name, value] of Object.entries(splashColors)) {
382 document.documentElement.style.setProperty(`--boot-${name}`, value);
383 }
384 }
385 setThemeColor(chromeColor);
386 } catch {
387 // Mirror the runtime's storage-failure fallback: follow the OS.
388 let prefersDark = true;
389 try {
390 prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
391 } catch {
392 // Keep the dark default when even matchMedia is unavailable.
393 }
394 delete document.documentElement.dataset.themeId;
395 delete document.documentElement.dataset.themeSelected;
396 document.documentElement.classList.toggle("dark", prefersDark);
397 const fallbackColor = prefersDark ? DARK_BACKGROUND : LIGHT_BACKGROUND;
398 document.documentElement.style.backgroundColor = fallbackColor;
399 setThemeColor(fallbackColor);
400 }
401 })();
402 </script>
403 <style>
404 html,
405 body,
406 #root {
407 width: 100%;
408 height: 100%;
409 margin: 0;
410 }
411​
412 body {
413 background: #ffffff;
414 color: #262626;
415 font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
416 }
417​
418 html.dark body {
419 background: #0a0a0a;
420 color: #f5f5f5;
421 }
422​
423 #boot-shell {
424 position: relative;
425 overflow: hidden;
426 display: flex;
427 min-height: 100%;
428 align-items: center;
429 justify-content: center;
430 background: inherit;
431 color: inherit;
432 }
433​
434 html[data-theme-selected="true"] #boot-shell {
435 background: var(--boot-background);
436 color: var(--boot-foreground);
437 }
438​
439 #boot-shell-card {
440 position: relative;
441 z-index: 1;
442 display: flex;
443 align-items: center;
444 justify-content: center;
445 width: 96px;
446 height: 96px;
447 }
448​
449 #boot-shell-logo {
450 width: 64px;
451 height: 64px;
452 object-fit: contain;
453 }
454 </style>
455 <title>T3 Code (Alpha)</title>
456 </head>
457 <body>
458 <div id="root">
459 <div id="boot-shell">
460 <div id="boot-shell-card" aria-label="T3 Code splash screen">
461 <img id="boot-shell-logo" src="/apple-touch-icon.png" alt="T3 Code" />
462 </div>
463 </div>
464 </div>
465 <script type="module" src="/src/main.tsx"></script>
466 </body>
467</html>