@ginhotaru282/reader 0.1.0

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 (81) hide show
  1. package/.dockerignore +5 -0
  2. package/.gitattributes +2 -0
  3. package/Dockerfile +26 -0
  4. package/README.md +36 -0
  5. package/eslint.config.mjs +18 -0
  6. package/next.config.ts +8 -0
  7. package/package.json +31 -0
  8. package/postcss.config.mjs +7 -0
  9. package/public/file.svg +1 -0
  10. package/public/globe.svg +1 -0
  11. package/public/window.svg +1 -0
  12. package/scripts/obfuscate-build.mjs +77 -0
  13. package/src/app/(reader)/[id]/page.tsx +40 -0
  14. package/src/app/(reader)/layout.tsx +38 -0
  15. package/src/app/api/bookmark/[id]/toggle/route.ts +41 -0
  16. package/src/app/api/chapter/[id]/audio/route.ts +37 -0
  17. package/src/app/api/chapter/[id]/audio-status/route.ts +36 -0
  18. package/src/app/api/chapter/[id]/unlock/route.ts +49 -0
  19. package/src/app/api/comment/story/[id]/route.ts +48 -0
  20. package/src/app/api/reading-progress/[storyId]/route.ts +26 -0
  21. package/src/app/api/reading-progress/sync/route.ts +38 -0
  22. package/src/app/api/story/[id]/combo-unlock/route.ts +47 -0
  23. package/src/app/globals.css +26 -0
  24. package/src/app/icon.png +0 -0
  25. package/src/app/layout.tsx +35 -0
  26. package/src/app/page.tsx +3 -0
  27. package/src/assets/fonts/Lora-Variable.ttf +0 -0
  28. package/src/assets/fonts/PlusJakartaSans-Variable.ttf +0 -0
  29. package/src/components/ssr/Skeleton/index.module.css +22 -0
  30. package/src/components/ssr/Skeleton/index.tsx +38 -0
  31. package/src/modules/reader/ReaderView.tsx +48 -0
  32. package/src/modules/reader/api/backend-data.ts +231 -0
  33. package/src/modules/reader/api/client-audio-api.ts +33 -0
  34. package/src/modules/reader/api/client-bookmark-api.ts +21 -0
  35. package/src/modules/reader/api/client-comment-api.ts +31 -0
  36. package/src/modules/reader/api/client-progress-api.ts +36 -0
  37. package/src/modules/reader/api/client-purchase-api.ts +64 -0
  38. package/src/modules/reader/api/get-reader-page-data.ts +48 -0
  39. package/src/modules/reader/api/types.ts +47 -0
  40. package/src/modules/reader/components/AudioPlayerBar.tsx +299 -0
  41. package/src/modules/reader/components/AutoScrollDrawer.tsx +58 -0
  42. package/src/modules/reader/components/ChapterBottomNav.tsx +16 -0
  43. package/src/modules/reader/components/ChapterContent.tsx +43 -0
  44. package/src/modules/reader/components/ChapterListDrawer.tsx +84 -0
  45. package/src/modules/reader/components/ChapterNav.tsx +20 -0
  46. package/src/modules/reader/components/ChapterSelect.tsx +24 -0
  47. package/src/modules/reader/components/ChapterWatermark.tsx +53 -0
  48. package/src/modules/reader/components/CommentSection.tsx +156 -0
  49. package/src/modules/reader/components/LockedChapterGate.tsx +37 -0
  50. package/src/modules/reader/components/MobileDock.tsx +62 -0
  51. package/src/modules/reader/components/NavButton.tsx +22 -0
  52. package/src/modules/reader/components/ReaderBreadcrumbs.tsx +20 -0
  53. package/src/modules/reader/components/ReaderChrome.tsx +206 -0
  54. package/src/modules/reader/components/ReaderToolbar.tsx +52 -0
  55. package/src/modules/reader/components/ReaderTopbar.tsx +31 -0
  56. package/src/modules/reader/components/SettingsPanel.tsx +158 -0
  57. package/src/modules/reader/components/Toast.tsx +15 -0
  58. package/src/modules/reader/constants/index.ts +22 -0
  59. package/src/modules/reader/hooks/useAudioPlayer.ts +633 -0
  60. package/src/modules/reader/hooks/useAutoScroll.ts +31 -0
  61. package/src/modules/reader/hooks/useBookmark.ts +32 -0
  62. package/src/modules/reader/hooks/useComments.ts +86 -0
  63. package/src/modules/reader/hooks/useContentProtection.ts +81 -0
  64. package/src/modules/reader/hooks/useDrawers.ts +27 -0
  65. package/src/modules/reader/hooks/useFullscreen.ts +24 -0
  66. package/src/modules/reader/hooks/usePrefs.ts +66 -0
  67. package/src/modules/reader/hooks/useReaderView.ts +190 -0
  68. package/src/modules/reader/hooks/useReadingProgress.ts +95 -0
  69. package/src/modules/reader/hooks/useScrollVisibility.ts +44 -0
  70. package/src/modules/reader/hooks/useToast.ts +19 -0
  71. package/src/modules/reader/hooks/useUnlock.ts +59 -0
  72. package/src/modules/reader/styles/reader.module.css +1986 -0
  73. package/src/modules/reader/types.ts +145 -0
  74. package/src/modules/reader/utils/affiliate.ts +43 -0
  75. package/src/modules/reader/utils/chapter-label.ts +8 -0
  76. package/src/modules/reader/utils/format-date.ts +10 -0
  77. package/src/modules/reader/utils/obfuscate-content.ts +70 -0
  78. package/src/modules/reader/utils/silent-wav.ts +33 -0
  79. package/src/modules/reader/utils/tiktok-tts.ts +251 -0
  80. package/src/modules/reader/utils/word-svg.ts +132 -0
  81. package/tsconfig.json +34 -0
@@ -0,0 +1,299 @@
1
+ "use client";
2
+
3
+ import styles from "../styles/reader.module.css";
4
+ import type { useAudioPlayer } from "../hooks/useAudioPlayer";
5
+
6
+ function formatTime(time: number) {
7
+ if (Number.isNaN(time)) return "0:00";
8
+ const m = Math.floor(time / 60);
9
+ const s = Math.floor(time % 60);
10
+ return `${m}:${s < 10 ? "0" : ""}${s}`;
11
+ }
12
+
13
+ export type AudioPlayerBarProps = {
14
+ chapterLabel: string;
15
+ player: ReturnType<typeof useAudioPlayer>;
16
+ };
17
+
18
+ export function AudioPlayerBar({ chapterLabel, player }: AudioPlayerBarProps) {
19
+ const {
20
+ selectedVoice,
21
+ handleVoiceChange,
22
+ voices,
23
+ audioStatus,
24
+ isPlaying,
25
+ currentTime,
26
+ duration,
27
+ volume,
28
+ setVolume,
29
+ isMuted,
30
+ setIsMuted,
31
+ playbackRate,
32
+ setPlaybackRate,
33
+ currentParagraphIndex,
34
+ paragraphCount,
35
+ isGeneratingParagraph,
36
+ localProgress,
37
+ setLocalProgress,
38
+ continuousPlay,
39
+ setContinuousPlay,
40
+ isPlayerDisabled,
41
+ audioRef1,
42
+ audioRef2,
43
+ togglePlay,
44
+ handlePrevParagraph,
45
+ handleNextParagraph,
46
+ jumpToProgress,
47
+ handleTimeUpdate,
48
+ handleLoadedMetadata,
49
+ handleEnded,
50
+ handlePlay,
51
+ handlePause,
52
+ setPlayerOpen,
53
+ playerOpen,
54
+ } = player;
55
+
56
+ const isStudio = selectedVoice === "server";
57
+
58
+ return (
59
+ <div className={styles.bottomPlayerContainer}>
60
+ <div className={`${styles.bottomPlayerBar} ${playerOpen ? "" : styles.bottomPlayerBarHidden}`}>
61
+ <audio
62
+ ref={audioRef1}
63
+ hidden
64
+ onTimeUpdate={() => handleTimeUpdate(1)}
65
+ onLoadedMetadata={() => handleLoadedMetadata(1)}
66
+ onEnded={() => handleEnded(1)}
67
+ onPlay={() => handlePlay(1)}
68
+ onPause={() => handlePause(1)}
69
+ />
70
+ <audio
71
+ ref={audioRef2}
72
+ hidden
73
+ onTimeUpdate={() => handleTimeUpdate(2)}
74
+ onLoadedMetadata={() => handleLoadedMetadata(2)}
75
+ onEnded={() => handleEnded(2)}
76
+ onPlay={() => handlePlay(2)}
77
+ onPause={() => handlePause(2)}
78
+ />
79
+
80
+ <div className={styles.playerRow1}>
81
+ <div className={styles.playerLeft}>
82
+ <div className={styles.playerIconCircle}>
83
+ <span className="material-icons-round">headphones</span>
84
+ </div>
85
+ <div className={styles.playerInfoTexts}>
86
+ <span className={styles.playerChapTitle}>
87
+ {chapterLabel}
88
+ {!isStudio && paragraphCount > 0 && (
89
+ <span className={styles.segmentIndicator}>
90
+ Đoạn {currentParagraphIndex + 1}/{paragraphCount}
91
+ </span>
92
+ )}
93
+ </span>
94
+ <span className={styles.playerSubtitle}>
95
+ {isGeneratingParagraph
96
+ ? "Đang tạo âm thanh đoạn..."
97
+ : isStudio && (audioStatus === "generating" || audioStatus === "loading")
98
+ ? "Đang tải âm thanh chương..."
99
+ : audioStatus === "failed" || audioStatus === "error"
100
+ ? "Lỗi tải audio"
101
+ : !isStudio
102
+ ? voices[selectedVoice] || "Giọng đọc"
103
+ : "Giọng Studio"}
104
+ </span>
105
+ </div>
106
+ </div>
107
+
108
+ <div className={styles.playerControlsRow}>
109
+ {isStudio ? (
110
+ <>
111
+ <button
112
+ className={styles.playerControlBtn}
113
+ disabled={isPlayerDisabled}
114
+ style={{ opacity: isPlayerDisabled ? 0.5 : 1 }}
115
+ onClick={() => {
116
+ if (audioRef1.current) audioRef1.current.currentTime = Math.max(0, audioRef1.current.currentTime - 10);
117
+ }}
118
+ >
119
+ <span className="material-icons-round">replay_10</span>
120
+ </button>
121
+
122
+ <button
123
+ className={styles.playerPlayBtn}
124
+ onClick={togglePlay}
125
+ disabled={isPlayerDisabled}
126
+ style={{ opacity: isPlayerDisabled ? 0.6 : 1 }}
127
+ >
128
+ {audioStatus === "generating" || audioStatus === "loading" ? (
129
+ <span className={`material-icons-round ${styles.spin}`} style={{ fontSize: 24 }}>
130
+ sync
131
+ </span>
132
+ ) : (
133
+ <span className="material-icons-round" style={{ fontSize: 24 }}>
134
+ {isPlaying ? "pause" : "play_arrow"}
135
+ </span>
136
+ )}
137
+ </button>
138
+
139
+ <button
140
+ className={styles.playerControlBtn}
141
+ disabled={isPlayerDisabled}
142
+ style={{ opacity: isPlayerDisabled ? 0.5 : 1 }}
143
+ onClick={() => {
144
+ if (audioRef1.current) {
145
+ audioRef1.current.currentTime = Math.min(duration, audioRef1.current.currentTime + 10);
146
+ }
147
+ }}
148
+ >
149
+ <span className="material-icons-round">forward_10</span>
150
+ </button>
151
+ </>
152
+ ) : (
153
+ <>
154
+ <button
155
+ className={styles.playerControlBtn}
156
+ disabled={currentParagraphIndex === 0 || paragraphCount === 0}
157
+ style={{ opacity: currentParagraphIndex === 0 ? 0.5 : 1 }}
158
+ onClick={handlePrevParagraph}
159
+ title="Đoạn trước"
160
+ >
161
+ <span className="material-icons-round">skip_previous</span>
162
+ </button>
163
+
164
+ <button
165
+ className={styles.playerPlayBtn}
166
+ onClick={togglePlay}
167
+ disabled={paragraphCount === 0}
168
+ style={{ opacity: paragraphCount === 0 ? 0.6 : 1 }}
169
+ >
170
+ {isGeneratingParagraph ? (
171
+ <span className={`material-icons-round ${styles.spin}`} style={{ fontSize: 24 }}>
172
+ sync
173
+ </span>
174
+ ) : (
175
+ <span className="material-icons-round" style={{ fontSize: 24 }}>
176
+ {isPlaying ? "pause" : "play_arrow"}
177
+ </span>
178
+ )}
179
+ </button>
180
+
181
+ <button
182
+ className={styles.playerControlBtn}
183
+ disabled={currentParagraphIndex === paragraphCount - 1 || paragraphCount === 0}
184
+ style={{ opacity: currentParagraphIndex === paragraphCount - 1 ? 0.5 : 1 }}
185
+ onClick={handleNextParagraph}
186
+ title="Đoạn sau"
187
+ >
188
+ <span className="material-icons-round">skip_next</span>
189
+ </button>
190
+ </>
191
+ )}
192
+ </div>
193
+
194
+ <div className={styles.playerRight}>
195
+ <div className={styles.playerVolumeWrap}>
196
+ <button className={styles.playerControlBtn} disabled={isPlayerDisabled} onClick={() => setIsMuted((prev) => !prev)}>
197
+ <span className="material-icons-round">{isMuted ? "volume_off" : "volume_up"}</span>
198
+ </button>
199
+ <input
200
+ type="range"
201
+ className={styles.playerVolumeSlider}
202
+ min="0"
203
+ max="1"
204
+ step="0.05"
205
+ disabled={isPlayerDisabled}
206
+ value={isMuted ? 0 : volume}
207
+ onChange={(e) => {
208
+ const vol = Number(e.target.value);
209
+ setVolume(vol);
210
+ setIsMuted(vol === 0);
211
+ }}
212
+ />
213
+ </div>
214
+
215
+ <button
216
+ className={styles.playerSpeedBtn}
217
+ disabled={isPlayerDisabled}
218
+ onClick={() => {
219
+ const nextSpeed = playbackRate === 1 ? 1.25 : playbackRate === 1.25 ? 1.5 : playbackRate === 1.5 ? 2.0 : 1.0;
220
+ setPlaybackRate(nextSpeed);
221
+ }}
222
+ >
223
+ {playbackRate}x
224
+ </button>
225
+
226
+ <button
227
+ className={`${styles.playerContinuousBtn} ${continuousPlay ? styles.activeContinuous : ""}`}
228
+ onClick={() => setContinuousPlay((prev) => !prev)}
229
+ title={continuousPlay ? "Đang bật tự động chuyển chương" : "Đang tắt tự động chuyển chương"}
230
+ >
231
+ <span className="material-icons-round" style={{ fontSize: "18px" }}>
232
+ {continuousPlay ? "sync" : "sync_disabled"}
233
+ </span>
234
+ <span className={styles.continuousText}>Tự Động Chuyển Chương</span>
235
+ </button>
236
+
237
+ <select className={styles.voiceSelect} value={selectedVoice} onChange={(e) => handleVoiceChange(e.target.value)}>
238
+ <option value="BV074_streaming">🔊 Nữ Audio</option>
239
+ <option value="BV421_vivn_streaming">🔊 Nữ Hoạt Hình</option>
240
+ <option value="BV075_streaming">🔊 Nam Review</option>
241
+ <option value="vi_female_huong">🔊 Nữ Review</option>
242
+ </select>
243
+
244
+ <button className={styles.playerControlBtn} onClick={() => setPlayerOpen(false)}>
245
+ <span className="material-icons-round">close</span>
246
+ </button>
247
+ </div>
248
+ </div>
249
+
250
+ <div className={styles.playerProgressRow}>
251
+ {isStudio ? (
252
+ <>
253
+ <span className={styles.playerTime}>{formatTime(currentTime)}</span>
254
+ <input
255
+ type="range"
256
+ className={styles.playerSlider}
257
+ min="0"
258
+ max={duration || 100}
259
+ value={currentTime}
260
+ disabled={isPlayerDisabled}
261
+ onChange={(e) => {
262
+ if (audioRef1.current) {
263
+ audioRef1.current.currentTime = Number(e.target.value);
264
+ }
265
+ }}
266
+ />
267
+ <span className={styles.playerTime}>{formatTime(duration)}</span>
268
+ </>
269
+ ) : (
270
+ <>
271
+ <span className={styles.playerTime} style={{ minWidth: "54px" }}>
272
+ Đoạn {currentParagraphIndex + 1}
273
+ </span>
274
+ <input
275
+ type="range"
276
+ className={styles.playerSlider}
277
+ min="0"
278
+ max={paragraphCount}
279
+ step="0.01"
280
+ value={localProgress !== null ? localProgress : currentParagraphIndex + (duration ? currentTime / duration : 0)}
281
+ disabled={paragraphCount === 0}
282
+ onChange={(e) => setLocalProgress(Number(e.target.value))}
283
+ onMouseUp={() => {
284
+ if (localProgress !== null) jumpToProgress(localProgress);
285
+ }}
286
+ onTouchEnd={() => {
287
+ if (localProgress !== null) jumpToProgress(localProgress);
288
+ }}
289
+ />
290
+ <span className={styles.playerTime} style={{ minWidth: "54px", textAlign: "right" }}>
291
+ {paragraphCount} đoạn
292
+ </span>
293
+ </>
294
+ )}
295
+ </div>
296
+ </div>
297
+ </div>
298
+ );
299
+ }
@@ -0,0 +1,58 @@
1
+ import styles from "../styles/reader.module.css";
2
+ import type { AutoScrollDrawerProps } from "../types";
3
+
4
+ export function AutoScrollDrawer({
5
+ open,
6
+ onClose,
7
+ isAutoScrolling,
8
+ scrollSpeed,
9
+ onChangeSpeed,
10
+ onStart,
11
+ onStop,
12
+ }: AutoScrollDrawerProps) {
13
+ return (
14
+ <div className={`${styles.readerModalOverlay} ${open ? styles.open : ""}`} onClick={onClose}>
15
+ <div className={styles.scrollDrawer} onClick={(e) => e.stopPropagation()}>
16
+ <div className={styles.drawerHeader}>
17
+ <h3>Cuộn tự động</h3>
18
+ <button className={styles.drawerCloseBtn} onClick={onClose}>
19
+ <span className="material-icons-round">close</span>
20
+ </button>
21
+ </div>
22
+ <div className={styles.drawerBody}>
23
+ <div className={styles.scrollStatus}>
24
+ <span className={styles.statusDot} style={{ background: isAutoScrolling ? "#10b981" : "#71717a" }} />
25
+ <span>{isAutoScrolling ? "Đang cuộn" : "Sẵn sàng"}</span>
26
+ </div>
27
+
28
+ <div className={styles.scrollSpeedControl}>
29
+ <label>Tốc độ cuộn: {scrollSpeed.toFixed(1)}x</label>
30
+ <input
31
+ type="range"
32
+ min="0.5"
33
+ max="5"
34
+ step="0.5"
35
+ value={scrollSpeed}
36
+ onChange={(e) => onChangeSpeed(Number(e.target.value))}
37
+ className={styles.drawerSlider}
38
+ />
39
+ <div className={styles.sliderLabels}>
40
+ <span>Chậm</span>
41
+ <span>Vừa</span>
42
+ <span>Nhanh</span>
43
+ </div>
44
+ </div>
45
+
46
+ <div className={styles.drawerActions}>
47
+ <button className={styles.btnStartScroll} onClick={onStart} disabled={isAutoScrolling}>
48
+ <span className="material-icons-round">play_arrow</span> Bắt đầu
49
+ </button>
50
+ <button className={styles.btnStopScroll} onClick={onStop} disabled={!isAutoScrolling}>
51
+ <span className="material-icons-round">pause</span> Dừng
52
+ </button>
53
+ </div>
54
+ </div>
55
+ </div>
56
+ </div>
57
+ );
58
+ }
@@ -0,0 +1,16 @@
1
+ import styles from "../styles/reader.module.css";
2
+ import type { ChapterBottomNavProps } from "../types";
3
+ import { NavButton } from "./NavButton";
4
+
5
+ export function ChapterBottomNav({ chapter }: ChapterBottomNavProps) {
6
+ return (
7
+ <div className={styles.navBottom}>
8
+ <NavButton href={chapter.prevChapterId} variant="ghost">
9
+ <span className="material-icons-round">chevron_left</span> Chương trước
10
+ </NavButton>
11
+ <NavButton href={chapter.nextChapterId} variant="primary">
12
+ Chương sau <span className="material-icons-round">chevron_right</span>
13
+ </NavButton>
14
+ </div>
15
+ );
16
+ }
@@ -0,0 +1,43 @@
1
+ "use client";
2
+
3
+ import styles from "../styles/reader.module.css";
4
+ import type { ChapterContentProps } from "../types";
5
+
6
+ export function ChapterContent({
7
+ renderedParagraphs,
8
+ highlightedIndex,
9
+ clickable,
10
+ onParagraphClick,
11
+ }: ChapterContentProps) {
12
+ return (
13
+ <article className={styles.content}>
14
+ {renderedParagraphs.map((segments, idx) => (
15
+ <p
16
+ key={idx}
17
+ className={idx === highlightedIndex ? styles.highlightedParagraph : ""}
18
+ style={{ cursor: clickable ? "pointer" : "default" }}
19
+ onClick={() => {
20
+ if (clickable) onParagraphClick(idx);
21
+ }}
22
+ >
23
+ {segments.map((seg, i) =>
24
+ seg.type === "text" ? (
25
+ <span key={i}>{seg.value}</span>
26
+ ) : (
27
+ <span key={i}>
28
+ <span
29
+ className={styles.obfWordLora}
30
+ dangerouslySetInnerHTML={{ __html: seg.lora }}
31
+ />
32
+ <span
33
+ className={styles.obfWordJakarta}
34
+ dangerouslySetInnerHTML={{ __html: seg.jakarta }}
35
+ />
36
+ </span>
37
+ )
38
+ )}
39
+ </p>
40
+ ))}
41
+ </article>
42
+ );
43
+ }
@@ -0,0 +1,84 @@
1
+ "use client";
2
+
3
+ import { useEffect, useRef } from "react";
4
+ import styles from "../styles/reader.module.css";
5
+ import type { ChapterListDrawerProps } from "../types";
6
+
7
+ export function ChapterListDrawer({
8
+ open,
9
+ onClose,
10
+ chapter,
11
+ allChapters,
12
+ onSelect,
13
+ }: ChapterListDrawerProps) {
14
+ const gridRef = useRef<HTMLDivElement>(null);
15
+ const touchStartYRef = useRef(0);
16
+
17
+ useEffect(() => {
18
+ if (!open) return;
19
+ const scrollToActive = () => {
20
+ const grid = gridRef.current;
21
+ const activeBtn = grid?.querySelector(`.${styles.drawerChapterActive}`);
22
+ if (activeBtn && grid) {
23
+ const btnRect = activeBtn.getBoundingClientRect();
24
+ const gridRect = grid.getBoundingClientRect();
25
+ grid.scrollTop = grid.scrollTop + (btnRect.top - gridRect.top);
26
+ }
27
+ };
28
+ const timers = [50, 150, 450].map((ms) => setTimeout(scrollToActive, ms));
29
+ return () => timers.forEach(clearTimeout);
30
+ }, [open, chapter.id]);
31
+
32
+ const handleOverlayTouchStart = (e: React.TouchEvent) => {
33
+ if (e.touches.length > 0) touchStartYRef.current = e.touches[0].clientY;
34
+ };
35
+
36
+ const handleOverlayTouchMove = (e: React.TouchEvent) => {
37
+ if (gridRef.current?.contains(e.target as Node)) return;
38
+ if (e.touches.length > 0 && gridRef.current) {
39
+ const currentY = e.touches[0].clientY;
40
+ gridRef.current.scrollTop -= currentY - touchStartYRef.current;
41
+ touchStartYRef.current = currentY;
42
+ if (e.cancelable) e.preventDefault();
43
+ }
44
+ };
45
+
46
+ return (
47
+ <div
48
+ className={`${styles.readerModalOverlay} ${open ? styles.open : ""}`}
49
+ onClick={onClose}
50
+ onTouchStart={handleOverlayTouchStart}
51
+ onTouchMove={handleOverlayTouchMove}
52
+ >
53
+ <div className={styles.chapterDrawer} onClick={(e) => e.stopPropagation()}>
54
+ <div className={styles.drawerHeader}>
55
+ <h3>Danh sách chương</h3>
56
+ <button className={styles.drawerCloseBtn} onClick={onClose}>
57
+ <span className="material-icons-round">close</span>
58
+ </button>
59
+ </div>
60
+ <div className={styles.drawerGrid} ref={gridRef}>
61
+ {allChapters.map((ch) => (
62
+ <button
63
+ key={ch.id}
64
+ className={`${styles.drawerChapterBtn} ${ch.id === chapter.id ? styles.drawerChapterActive : ""}`}
65
+ onClick={() => onSelect(ch.id)}
66
+ >
67
+ <span style={{ overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", flex: 1 }}>
68
+ {ch.title}
69
+ </span>
70
+ {ch.type === "vip" && (
71
+ <span className={styles.drawerVipBadge}>
72
+ <span className="material-icons-round" style={{ fontSize: 11, marginRight: 2, verticalAlign: "middle" }}>
73
+ star
74
+ </span>
75
+ VIP
76
+ </span>
77
+ )}
78
+ </button>
79
+ ))}
80
+ </div>
81
+ </div>
82
+ </div>
83
+ );
84
+ }
@@ -0,0 +1,20 @@
1
+ import styles from "../styles/reader.module.css";
2
+ import type { ChapterNavProps } from "../types";
3
+ import { NavButton } from "./NavButton";
4
+ import { ChapterSelect } from "./ChapterSelect";
5
+
6
+ export function ChapterNav({ chapter, allChapters }: ChapterNavProps) {
7
+ return (
8
+ <div className={styles.navTop}>
9
+ <NavButton href={chapter.prevChapterId} variant="ghost">
10
+ <span className="material-icons-round">chevron_left</span> Chương trước
11
+ </NavButton>
12
+
13
+ <ChapterSelect chapter={chapter} allChapters={allChapters} />
14
+
15
+ <NavButton href={chapter.nextChapterId} variant="ghost">
16
+ Chương sau <span className="material-icons-round">chevron_right</span>
17
+ </NavButton>
18
+ </div>
19
+ );
20
+ }
@@ -0,0 +1,24 @@
1
+ "use client";
2
+
3
+ import { useRouter } from "next/navigation";
4
+ import styles from "../styles/reader.module.css";
5
+ import type { ChapterSelectProps } from "../types";
6
+
7
+ export function ChapterSelect({ chapter, allChapters }: ChapterSelectProps) {
8
+ const router = useRouter();
9
+ return (
10
+ <div className={styles.chapterSelectWrap}>
11
+ <select
12
+ value={chapter.id}
13
+ onChange={(e) => router.push(`/${e.target.value}`)}
14
+ className={styles.chapterSelect}
15
+ >
16
+ {allChapters.map((ch) => (
17
+ <option key={ch.id} value={ch.id}>
18
+ {ch.title}
19
+ </option>
20
+ ))}
21
+ </select>
22
+ </div>
23
+ );
24
+ }
@@ -0,0 +1,53 @@
1
+ "use client";
2
+
3
+ import { useMemo } from "react";
4
+ import type { CSSProperties } from "react";
5
+ import styles from "../styles/reader.module.css";
6
+ import type { ChapterWatermarkProps } from "../types";
7
+
8
+ const TILE_WIDTH = 360;
9
+ const TILE_HEIGHT = 260;
10
+ const BRAND_LABEL = "TẠP HÓA TRUYỆN HAY";
11
+
12
+ function escapeXml(value: string): string {
13
+ return value
14
+ .replace(/&/g, "&amp;")
15
+ .replace(/</g, "&lt;")
16
+ .replace(/>/g, "&gt;")
17
+ .replace(/"/g, "&quot;")
18
+ .replace(/'/g, "&apos;");
19
+ }
20
+
21
+ /**
22
+ * Lớp pattern mờ đè lên nội dung mọi chương (VIP lẫn miễn phí): dệt cả tên thương hiệu
23
+ * lẫn username người đang đọc (nếu đã đăng nhập), nhằm phá vỡ đường nét chữ khi bị chụp
24
+ * màn hình / crawl ảnh rồi chạy OCR lại — đồng thời để lại dấu vết user nếu ảnh rò rỉ.
25
+ * Mắt người đọc bình thường (chữ liền mạch, tương phản cao) không bị ảnh hưởng nhiều.
26
+ * Không liên quan tới useContentProtection (chặn copy/devtools) hay obfuscateChapterContent
27
+ * (phá DOM text scraping) — đây là lớp chống OCR + watermark trên ảnh chụp.
28
+ */
29
+ export function ChapterWatermark({ theme, viewer }: ChapterWatermarkProps) {
30
+ const backgroundImage = useMemo(() => {
31
+ const label = viewer ? `${BRAND_LABEL} · ${viewer.username}` : BRAND_LABEL;
32
+ const fill = theme === "dark" ? "rgba(255,61,136,0.10)" : "rgba(255,61,136,0.12)";
33
+
34
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${TILE_WIDTH}" height="${TILE_HEIGHT}">
35
+ <text x="${TILE_WIDTH / 2}" y="${TILE_HEIGHT / 2}" transform="rotate(-28 ${TILE_WIDTH / 2} ${TILE_HEIGHT / 2})" font-size="14" font-family="sans-serif" font-weight="700" letter-spacing="3" fill="${fill}" text-anchor="middle">${escapeXml(label)}</text>
36
+ </svg>`;
37
+
38
+ return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
39
+ }, [theme, viewer]);
40
+
41
+ return (
42
+ <div
43
+ aria-hidden="true"
44
+ className={styles.watermarkLayer}
45
+ style={
46
+ {
47
+ backgroundImage,
48
+ backgroundSize: `${TILE_WIDTH}px ${TILE_HEIGHT}px`,
49
+ } as CSSProperties
50
+ }
51
+ />
52
+ );
53
+ }