Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

document.tsx

135 lines3.7 KB

1import type { Handle, RemixNode } from 'remix/ui'
2import { css } from 'remix/ui'
3​
4import { entryHref, entryPreloads, partialJsonHref } from '../assets.ts'
5​
6export interface DocumentProps {
7 children?: RemixNode
8 head?: RemixNode
9 title?: string
11​
12const DEFAULT_TITLE = readAppDisplayName('ts-remix-chat')
13​
14export function Document(handle: Handle<DocumentProps>) {
15 return () => {
16 let { children, head, title = DEFAULT_TITLE } = handle.props
17​
18 return (
19 <html lang="en">
20 <head>
21 <meta charSet="utf-8" />
22 <meta name="viewport" content="width=device-width, initial-scale=1" />
23 <meta name="color-scheme" content="light dark" />
24 <link
25 rel="icon"
26 type="image/svg+xml"
27 href="https://tanstack.com/favicon-light.svg"
28 media="(prefers-color-scheme: light)"
29 />
30 <link
31 rel="icon"
32 type="image/svg+xml"
33 href="https://tanstack.com/favicon-dark.svg"
34 media="(prefers-color-scheme: dark)"
35 />
36 <link rel="preconnect" href="https://fonts.googleapis.com" />
37 <link
38 rel="preconnect"
39 href="https://fonts.gstatic.com"
40 crossOrigin="anonymous"
41 />
42 <link
43 href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,700&family=Inter:wght@300;400;600&display=swap"
44 rel="stylesheet"
45 />
46 <title>{title}</title>
47 <style>{PAGE_STYLES}</style>
48 {head}
49 {entryPreloads.map((href) => (
50 <link key={href} rel="modulepreload" href={href} />
51 ))}
52 <script type="importmap">
53 {`{"imports":{"partial-json":${JSON.stringify(partialJsonHref)}}}`}
54 </script>
55 <script type="module" src={entryHref}></script>
56 </head>
57 <body mix={bodyStyle}>{children}</body>
58 </html>
59 )
60 }
62​
63const PAGE_STYLES = `
64:root {
65 color-scheme: light dark;
66 --bg: #eeebd4;
67 --ink: #111111;
68 --muted: #3e3529;
69 --accent: #d3481b;
70 --surface: #fffdf6;
71 --border: color-mix(in srgb, #111111 14%, transparent);
72 --shadow: 0 1px 2px color-mix(in srgb, #111111 8%, transparent),
73 0 8px 24px color-mix(in srgb, #111111 6%, transparent);
74 --font-display: 'Bricolage Grotesque', ui-sans-serif, system-ui, sans-serif;
75 --font-body: 'Inter', ui-sans-serif, system-ui, sans-serif;
77@media (prefers-color-scheme: dark) {
78 :root {
79 --bg: #111111;
80 --ink: #ffffff;
81 --muted: #aea691;
82 --accent: #e06e49;
83 --surface: #1c1c1c;
84 --border: color-mix(in srgb, #ffffff 16%, transparent);
85 --shadow: 0 1px 2px color-mix(in srgb, #000000 40%, transparent),
86 0 8px 24px color-mix(in srgb, #000000 35%, transparent);
87 }
89@media (forced-colors: active) {
90 :root {
91 --bg: Canvas;
92 --ink: CanvasText;
93 --muted: CanvasText;
94 --accent: LinkText;
95 --surface: Canvas;
96 --border: CanvasText;
97 --shadow: none;
98 }
100html {
101 height: 100%;
102 font-size: 100%;
104body {
105 height: 100%;
106 min-height: 100%;
108@media (prefers-reduced-motion: reduce) {
109 *, *::before, *::after {
110 animation-duration: 0.01ms !important;
111 animation-iteration-count: 1 !important;
112 transition-duration: 0.01ms !important;
113 scroll-behavior: auto !important;
114 }
116@media (prefers-color-scheme: dark) {
117 img[alt="TanStack"] {
118 filter: invert(1);
119 }
122​
123const bodyStyle = css({
124 margin: 0,
125 minHeight: '100%',
126 background: 'var(--bg)',
127 color: 'var(--ink)',
128 fontFamily: 'var(--font-body)',
129 fontWeight: 300,
130 lineHeight: 1.5,
131})
132​
133function readAppDisplayName(value: string): string {
134 return value.startsWith('%%') ? 'Remix App' : decodeURIComponent(value)