File size: 9,129 Bytes
5ccfcd1
 
49852ff
5ccfcd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49852ff
5ccfcd1
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import React from "react";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
import { Minimize2, Type, BookOpen } from "lucide-react";
import { Document } from "../../types";

interface ReadingModeViewProps {
  activeDoc: Document;
  charCount: number;
  wordCount: number;
  readingTheme: "dark" | "sepia" | "light";
  setReadingTheme: (theme: "dark" | "sepia" | "light") => void;
  readingFontFamily: "sans" | "serif" | "mono";
  setReadingFontFamily: (ff: "sans" | "serif" | "mono") => void;
  readingFontSize: "sm" | "base" | "lg" | "xl";
  setReadingFontSize: (sz: "sm" | "base" | "lg" | "xl") => void;
  readingLineHeight: "normal" | "relaxed" | "loose";
  setReadingLineHeight: (lh: "normal" | "relaxed" | "loose") => void;
  setIsReadingMode: (isReading: boolean) => void;
}

export default function ReadingModeView({
  activeDoc,
  charCount,
  wordCount,
  readingTheme,
  setReadingTheme,
  readingFontFamily,
  setReadingFontFamily,
  readingFontSize,
  setReadingFontSize,
  readingLineHeight,
  setReadingLineHeight,
  setIsReadingMode
}: ReadingModeViewProps) {
  return (
    <div 
      id="reading-mode-canvas" 
      className={`min-h-screen flex flex-col transition-colors duration-250 ${
        readingTheme === "dark" ? "bg-[#090B0E] text-slate-200" :
        readingTheme === "sepia" ? "bg-[#FAF4EB] text-amber-955" :
        "bg-[#FCFBFA] text-slate-900"
      }`}
    >
      <header className={`sticky top-0 z-30 shadow-sm border-b transition-colors duration-200 ${
        readingTheme === "dark" ? "bg-[#0F1216] border-slate-800" :
        readingTheme === "sepia" ? "bg-[#F3EADF] border-amber-200" :
        "bg-white border-slate-200"
      }`}>
        <div className="max-w-4xl mx-auto px-6 h-14 flex items-center justify-between">
          <div className="flex items-center gap-2 animate-pulse">
            <span className="text-[10px] font-mono tracking-wider uppercase text-slate-500">
              Reading: <span className="font-semibold text-blue-505 font-mono text-xs">{activeDoc.title}</span>
            </span>
          </div>

          <div className="flex items-center gap-3">
            <div className="flex items-center gap-1 p-0.5 rounded-lg border border-slate-700/20 bg-black/5 text-[10px]">
              <button
                type="button"
                onClick={() => setReadingTheme("dark")}
                className={`px-2 py-1 font-mono rounded transition cursor-pointer ${
                  readingTheme === "dark" ? "bg-slate-800 text-white font-medium" : "text-slate-500 hover:text-slate-800"
                }`}
              >
                Dark
              </button>
              <button
                type="button"
                onClick={() => setReadingTheme("sepia")}
                className={`px-2 py-1 font-mono rounded transition cursor-pointer ${
                  readingTheme === "sepia" ? "bg-amber-800/10 text-amber-800 font-bold" : "text-slate-500 hover:text-slate-800"
                }`}
              >
                Sepia
              </button>
              <button
                type="button"
                onClick={() => setReadingTheme("light")}
                className={`px-2 py-1 font-mono rounded transition cursor-pointer ${
                  readingTheme === "light" ? "bg-slate-200 text-slate-900 font-medium" : "text-slate-505 hover:text-slate-800"
                }`}
              >
                Light
              </button>
            </div>

            <div className={`h-6 w-px ${readingTheme === "dark" ? "bg-slate-800" : "bg-slate-200"}`} />
            
            <div className="flex items-center gap-1.5">
              <Type className="h-3.5 w-3.5 text-slate-500" />
              <div className="flex items-center gap-1">
                {(["sm", "base", "lg", "xl"] as const).map((sz) => (
                  <button
                    key={sz}
                    type="button"
                    onClick={() => setReadingFontSize(sz)}
                    className={`h-6 w-6 rounded text-[10px] font-mono font-bold transition cursor-pointer flex items-center justify-center uppercase ${
                      readingFontSize === sz 
                        ? "bg-blue-600 text-white shadow-sm" 
                        : readingTheme === "dark" ? "text-slate-500 hover:bg-slate-800" : "text-slate-600 hover:bg-slate-202"
                    }`}
                  >
                    {sz}
                  </button>
                ))}
              </div>
            </div>

            <div className={`h-6 w-px ${readingTheme === "dark" ? "bg-slate-800" : "bg-slate-200"}`} />
            <div className="flex items-center gap-1 bg-black/5 p-0.5 rounded-lg border border-slate-700/30 text-[10px]">
              {(["sans", "serif", "mono"] as const).map((ff) => (
                <button
                  key={ff}
                  type="button"
                  onClick={() => setReadingFontFamily(ff)}
                  className={`px-1.5 py-0.5 rounded text-[9px] font-mono transition cursor-pointer font-bold uppercase ${
                    readingFontFamily === ff 
                      ? "bg-slate-800 text-white shadow-sm font-semibold" 
                      : "text-slate-500 hover:text-slate-800"
                  }`}
                >
                  {ff}
                </button>
              ))}
            </div>

            <div className={`h-6 w-px ${readingTheme === "dark" ? "bg-slate-800" : "bg-slate-200"}`} />
            <button
              type="button"
              onClick={() => {
                const nextHeight: Record<typeof readingLineHeight, typeof readingLineHeight> = {
                  normal: "relaxed",
                  relaxed: "loose",
                  loose: "normal"
                };
                setReadingLineHeight(nextHeight[readingLineHeight]);
              }}
              className={`px-2 py-0.5 rounded text-[10px] font-mono border transition cursor-pointer ${
                readingTheme === "dark" ? "border-slate-800 bg-[#15181E] text-slate-400 hover:text-white" : "border-slate-200 bg-slate-100 text-slate-700"
              }`}
              title="Line Spacing"
            >
              Spacing: <span className="capitalize">{readingLineHeight}</span>
            </button>

            <div className={`h-6 w-px ${readingTheme === "dark" ? "bg-slate-800" : "bg-slate-200"}`} />
            
            <button
              type="button"
              onClick={() => setIsReadingMode(false)}
              className="px-2.5 py-1 text-xs bg-red-600 hover:bg-red-500 text-white font-medium rounded transition flex items-center gap-1 cursor-pointer font-sans"
            >
              <Minimize2 className="h-3.5 w-3.5" /> Close Reader
            </button>
          </div>
        </div>
      </header>

      <main className="flex-1 w-full max-w-2xl mx-auto px-6 py-12 overflow-y-auto">
        <div className="text-left select-text">
          <h1 className={`text-4xl font-sans tracking-tight font-extrabold mb-3 ${
            readingTheme === "dark" ? "text-white" :
            readingTheme === "sepia" ? "text-amber-950" : "text-slate-900"
          }`}>
            {activeDoc.title.replace(/\.[^/.]+$/, "")}
          </h1>
          <div className={`mb-8 pb-3 border-b text-[10px] font-mono ${
            readingTheme === "dark" ? "border-slate-800 text-slate-500" :
            readingTheme === "sepia" ? "border-amber-200 text-amber-800/60" : "border-slate-200 text-slate-400"
          }`}>
            Last saved {new Date(activeDoc.lastSaved).toLocaleString()} • {charCount} characters • {wordCount} words
          </div>

          <div className={`prose ${
            readingTheme === "dark" ? "prose-invert text-slate-300" :
            readingTheme === "sepia" ? "text-amber-900" : "text-slate-800"
          } ${
            readingFontFamily === "sans" ? "font-sans font-normal" :
            readingFontFamily === "serif" ? "font-serif tracking-wide" : "font-mono text-xs tracking-tight"
          } ${
            readingFontSize === "sm" ? "text-sm" :
            readingFontSize === "base" ? "text-base" :
            readingFontSize === "lg" ? "text-lg" : "text-xl"
          } ${
            readingLineHeight === "normal" ? "leading-normal" :
            readingLineHeight === "relaxed" ? "leading-relaxed" : "leading-loose"
          } markdown-body transition-all duration-150`}>
            <ReactMarkdown remarkPlugins={[remarkGfm]}>{activeDoc.content}</ReactMarkdown>
          </div>
        </div>
      </main>

      <footer className={`h-12 border-t text-center flex items-center justify-center text-[11px] font-mono ${
        readingTheme === "dark" ? "border-slate-900 bg-[#0A0C10] text-slate-600" :
        readingTheme === "sepia" ? "border-amber-100 bg-[#F3EADF] text-amber-800/40" : "bg-white border-slate-150 text-slate-500"
      }`}>
        Press <kbd className="px-1.5 py-0.5 rounded bg-black/5 border border-slate-400/20 text-[10px] mx-1">ESC</kbd> to exit readers view
      </footer>
    </div>
  );
}