Repository navigation
Expand file tree
/
Copy pathbookleaf.html
More file actions
1286 lines (1171 loc) · 43.2 KB
/
Copy pathbookleaf.html
File metadata and controls
1286 lines (1171 loc) · 43.2 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bookleaf</title>
<meta name="theme-color" content="#00ADCE">
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'><rect width='100' height='100' rx='22' fill='%2300ADCE'/><path d='M50 90 L24 92 L26 96 L50 94 Z' fill='%23F2B5A0'/><path d='M50 90 L76 92 L74 96 L50 94 Z' fill='%23F2B5A0' opacity='0.78'/><path d='M43 58 L47 72 L36 90 L32 92' fill='none' stroke='%23FFFFFF' stroke-width='2.3' stroke-linecap='round' stroke-linejoin='round'/><path d='M39 59 L41 74 L48 90 L52 92' fill='none' stroke='%23FFFFFF' stroke-width='2.3' stroke-linecap='round' stroke-linejoin='round'/><path d='M20 45 L10 38 L19 51 Z' fill='%23FFFFFF'/><path d='M18 50 C16 42 24 37 35 37 C48 37 57 43 55 52 C54 60 45 63 35 62 C26 61 20 58 18 50 Z' fill='%23FFFFFF'/><path d='M52 44 C49 30 55 20 62 12' fill='none' stroke='%23FFFFFF' stroke-width='4.6' stroke-linecap='round'/><circle cx='63' cy='11' r='3.8' fill='%23FFFFFF'/><path d='M65 9 L72 11 L70 15 L66 14 Z' fill='%23F2B5A0'/></svg>">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Spectral:ital,wght@0,300;0,400;0,500;1,300;1,400&family=Noto+Serif+SC:wght@300;400;500&family=Inter:wght@300;400;500&display=swap" rel="stylesheet">
<script src="https://unpkg.com/epubjs/dist/epub.min.js"></script>
<style>
/* ============================================================
Theme tokens
============================================================ */
:root {
--bg: #FBF7F0;
--text: #1A1A1A;
--text-muted: #888;
--border: rgba(0,0,0,0.08);
--bar-bg: rgba(251,247,240,0.94);
--hover: rgba(0,0,0,0.05);
--panel-bg: #F2EDE4;
--accent: #6B5340;
--shadow: rgba(0,0,0,0.10);
}
[data-theme="sepia"] {
--bg: #F5E9D5;
--text: #3B2E1E;
--text-muted: #9A7E62;
--border: rgba(59,46,30,0.10);
--bar-bg: rgba(245,233,213,0.94);
--hover: rgba(59,46,30,0.06);
--panel-bg: #EDE0C8;
--accent: #8B5E3C;
--shadow: rgba(59,46,30,0.12);
}
[data-theme="night"] {
--bg: #1C1C1E;
--text: #E5E0D8;
--text-muted: #6E6E73;
--border: rgba(255,255,255,0.07);
--bar-bg: rgba(28,28,30,0.94);
--hover: rgba(255,255,255,0.06);
--panel-bg: #2C2C2E;
--accent: #C8A87A;
--shadow: rgba(0,0,0,0.35);
}
/* ============================================================
Reset
============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
width: 100%; height: 100%; overflow: hidden;
background: var(--bg); color: var(--text);
font-family: 'Inter', system-ui, -apple-system, sans-serif;
-webkit-font-smoothing: antialiased;
transition: background .3s, color .3s;
}
button { cursor: pointer; font-family: inherit; }
textarea, input { font-family: inherit; }
/* ============================================================
Drop zone
============================================================ */
#drop-zone {
position: fixed; inset: 0; z-index: 200;
display: flex; flex-direction: column;
align-items: center; justify-content: center;
gap: 14px;
background: var(--bg);
transition: background .3s;
}
#drop-zone.drag-over { background: var(--panel-bg); }
.dz-icon {
font-size: 72px; line-height: 1;
opacity: .18; user-select: none;
transition: opacity .2s;
}
#drop-zone.drag-over .dz-icon { opacity: .35; }
.dz-title {
font-family: 'Spectral', 'Noto Serif SC', serif;
font-size: 32px; font-weight: 300; letter-spacing: -.5px;
color: var(--text); opacity: .82;
}
.dz-sub {
font-size: 14px; font-weight: 300;
color: var(--text-muted); letter-spacing: .2px;
}
.dz-btn {
margin-top: 4px;
padding: 9px 26px; border-radius: 22px;
border: 1.5px solid var(--border);
background: transparent; color: var(--text);
font-size: 14px; font-weight: 400;
transition: background .15s, border-color .15s;
}
.dz-btn:hover { background: var(--hover); border-color: var(--accent); }
/* theme row on drop zone */
.dz-theme-row {
display: flex; gap: 10px; margin-top: 4px;
}
.dz-theme-dot {
width: 22px; height: 22px; border-radius: 50%;
border: 2px solid transparent;
cursor: pointer; transition: transform .15s, border-color .15s;
}
.dz-theme-dot:hover { transform: scale(1.15); }
.dz-theme-dot.active { border-color: var(--accent); }
.dz-theme-dot[data-t="day"] { background: #FBF7F0; box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.dz-theme-dot[data-t="sepia"] { background: #F5E9D5; box-shadow: 0 0 0 1px rgba(0,0,0,.1); }
.dz-theme-dot[data-t="night"] { background: #1C1C1E; box-shadow: 0 0 0 1px rgba(0,0,0,.4); }
.dz-sync {
position: absolute; bottom: 28px;
display: flex; align-items: center; gap: 8px;
font-size: 12px; color: var(--text-muted);
}
.sync-dot {
width: 6px; height: 6px; border-radius: 50%;
background: var(--text-muted); opacity: .4; flex-shrink: 0;
transition: background .3s, opacity .3s;
}
.sync-dot.on { background: #34C759; opacity: 1; }
.dz-sync-btn {
padding: 3px 10px; border-radius: 10px;
border: 1px solid var(--border); background: transparent;
color: var(--text-muted); font-size: 11px;
transition: all .15s;
}
.dz-sync-btn:hover { background: var(--hover); color: var(--text); }
/* ============================================================
Reader skeleton
============================================================ */
#reader {
position: fixed; inset: 0;
display: flex; flex-direction: column;
opacity: 0; pointer-events: none;
transition: opacity .4s ease;
}
#reader.on { opacity: 1; pointer-events: all; }
/* ---- Toolbar ---- */
#toolbar {
height: 46px; flex-shrink: 0;
display: flex; align-items: center;
padding: 0 14px;
background: var(--bar-bg);
backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
border-bottom: 1px solid var(--border);
transition: background .3s;
position: relative; z-index: 60; user-select: none;
}
.tb-left, .tb-right {
display: flex; align-items: center; gap: 2px; flex: 1;
}
.tb-right { justify-content: flex-end; }
.tb-center { flex: 2; text-align: center; overflow: hidden; }
.tb-title {
font-family: 'Spectral','Noto Serif SC', serif;
font-size: 13.5px; font-weight: 400;
color: var(--text); opacity: .65;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
max-width: 280px; margin: 0 auto;
}
.tb-btn {
width: 30px; height: 30px; border-radius: 7px;
border: none; background: transparent; color: var(--text);
display: flex; align-items: center; justify-content: center;
font-size: 13px; opacity: .6;
transition: background .15s, opacity .15s;
}
.tb-btn:hover { background: var(--hover); opacity: 1; }
.tb-btn.lit { opacity: 1; background: var(--hover); }
.tb-sep { width: 1px; height: 16px; background: var(--border); margin: 0 4px; }
.fs-num {
font-size: 11.5px; color: var(--text-muted);
min-width: 24px; text-align: center; pointer-events: none;
font-variant-numeric: tabular-nums;
}
/* ---- Reader area ---- */
#reader-area {
flex: 1; position: relative; overflow: hidden;
display: flex; align-items: stretch;
}
#epub-viewer { flex: 1; position: relative; }
/* Page shadow line (book spine effect) */
#epub-viewer::after {
content: '';
position: absolute; top: 8%; bottom: 8%;
left: 50%; width: 1px;
background: linear-gradient(to bottom,
transparent 0%, var(--border) 20%,
var(--shadow) 50%,
var(--border) 80%, transparent 100%);
pointer-events: none; z-index: 5;
display: none; /* shown only in spread mode */
}
#epub-viewer.spread::after { display: block; }
/* Nav arrows */
.nav-btn {
position: absolute; top: 0; bottom: 0;
width: 56px; border: none; background: none;
display: flex; align-items: center; justify-content: center;
z-index: 10; opacity: 0;
transition: opacity .2s;
}
#reader-area:hover .nav-btn { opacity: 1; }
#prev-btn { left: 0; }
#next-btn { right: 0; }
.nav-chevron {
width: 8px; height: 16px;
color: var(--text); opacity: .3;
transition: opacity .15s;
}
.nav-btn:hover .nav-chevron { opacity: .75; }
/* ---- Bottom bar ---- */
#bottom-bar {
height: 34px; flex-shrink: 0;
display: flex; align-items: center;
justify-content: space-between;
padding: 0 22px;
background: var(--bar-bg);
backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
border-top: 1px solid var(--border);
transition: background .3s;
}
#ch-title {
font-size: 11px; color: var(--text-muted); font-weight: 300;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
max-width: 55%; letter-spacing: .15px;
}
.prog-row { display: flex; align-items: center; gap: 10px; }
#prog-track {
width: 90px; height: 2px;
background: var(--border); border-radius: 1px; overflow: hidden;
}
#prog-fill {
height: 100%; width: 0%;
background: var(--accent); border-radius: 1px;
transition: width .4s ease;
}
#prog-pct {
font-size: 11px; color: var(--text-muted);
font-variant-numeric: tabular-nums; white-space: nowrap;
}
/* ============================================================
Page-turn animation
============================================================ */
@keyframes leafNext {
0% { transform: translateX(0) scaleX(1); opacity: 1; }
30% { transform: translateX(-18px) scaleX(.97); opacity: .15; }
31% { transform: translateX(18px) scaleX(.97); opacity: .15; }
100% { transform: translateX(0) scaleX(1); opacity: 1; }
}
@keyframes leafPrev {
0% { transform: translateX(0) scaleX(1); opacity: 1; }
30% { transform: translateX(18px) scaleX(.97); opacity: .15; }
31% { transform: translateX(-18px) scaleX(.97); opacity: .15; }
100% { transform: translateX(0) scaleX(1); opacity: 1; }
}
.anim-next { animation: leafNext .32s cubic-bezier(.4,0,.2,1); }
.anim-prev { animation: leafPrev .32s cubic-bezier(.4,0,.2,1); }
/* ============================================================
Panels (TOC + Notes)
============================================================ */
.panel {
position: fixed; top: 0; bottom: 0; width: 290px;
background: var(--panel-bg);
transition: transform .28s cubic-bezier(.4,0,.2,1), background .3s;
z-index: 120; display: flex; flex-direction: column;
}
#toc-panel { left: 0; border-right: 1px solid var(--border);
transform: translateX(-100%); box-shadow: 4px 0 30px var(--shadow); }
#note-panel { right: 0; border-left: 1px solid var(--border);
transform: translateX(100%); box-shadow: -4px 0 30px var(--shadow); }
#toc-panel.open { transform: translateX(0); }
#note-panel.open { transform: translateX(0); }
.panel-head {
height: 50px; flex-shrink: 0;
display: flex; align-items: center; justify-content: space-between;
padding: 0 18px;
border-bottom: 1px solid var(--border);
}
.panel-label {
font-size: 11px; font-weight: 500; letter-spacing: .8px;
text-transform: uppercase; color: var(--text-muted);
}
.panel-x {
width: 26px; height: 26px; border-radius: 6px;
border: none; background: transparent; color: var(--text);
display: flex; align-items: center; justify-content: center;
font-size: 14px; opacity: .45;
transition: opacity .15s, background .15s;
}
.panel-x:hover { opacity: 1; background: var(--hover); }
.panel-body {
flex: 1; overflow-y: auto; padding: 8px 0;
}
.panel-body::-webkit-scrollbar { width: 3px; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
/* TOC */
.toc-row {
display: block; width: 100%; text-align: left;
border: none; background: none; color: var(--text);
font-family: 'Spectral','Noto Serif SC',serif;
font-size: 14px; font-weight: 400; line-height: 1.45;
padding: 9px 18px; cursor: pointer;
transition: background .12s;
}
.toc-row:hover { background: var(--hover); }
.toc-row.cur { color: var(--accent); }
.toc-row[data-d="2"] { padding-left: 32px; font-size: 13px; opacity: .82; }
.toc-row[data-d="3"] { padding-left: 46px; font-size: 12px; opacity: .65; }
/* Note items */
.note-row {
padding: 14px 18px; border-bottom: 1px solid var(--border);
cursor: default;
transition: background .12s;
}
.note-row:hover { background: var(--hover); }
.note-quote {
font-family: 'Spectral','Noto Serif SC',serif;
font-size: 13px; line-height: 1.55; color: var(--text);
padding-left: 9px; position: relative; margin-bottom: 5px;
}
.note-quote::before {
content: ''; position: absolute; left: 0; top: 2px; bottom: 2px;
width: 2.5px; border-radius: 1.5px;
}
[data-c="yellow"] .note-quote::before { background: #E8B84B; }
[data-c="green"] .note-quote::before { background: #4CAF75; }
[data-c="blue"] .note-quote::before { background: #5B8FD6; }
[data-c="pink"] .note-quote::before { background: #E8607A; }
.note-body { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.note-acts { display: flex; gap: 4px; margin-top: 8px; }
.note-act {
font-size: 11px; padding: 2px 8px; border-radius: 5px;
border: none; background: transparent; color: var(--text-muted);
transition: all .12s;
}
.note-act:hover { background: var(--hover); color: var(--text); }
.note-act.del:hover { color: #FF3B30; }
.panel-empty {
padding: 36px 18px; text-align: center;
font-size: 13px; color: var(--text-muted); line-height: 1.7;
}
/* ============================================================
Selection pop-up (highlight colors)
============================================================ */
#sel-bar {
position: fixed; z-index: 300;
display: none; align-items: center; gap: 3px;
background: var(--bar-bg);
border: 1px solid var(--border);
border-radius: 10px; padding: 5px 7px;
box-shadow: 0 6px 24px var(--shadow);
backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
transition: background .3s;
}
#sel-bar.on { display: flex; }
.sel-dot {
width: 20px; height: 20px; border-radius: 50%;
border: 2px solid rgba(255,255,255,.55);
transition: transform .12s, border-color .12s;
}
.sel-dot:hover { transform: scale(1.2); border-color: rgba(255,255,255,.9); }
.sel-dot[data-c="yellow"] { background: #E8B84B; }
.sel-dot[data-c="green"] { background: #4CAF75; }
.sel-dot[data-c="blue"] { background: #5B8FD6; }
.sel-dot[data-c="pink"] { background: #E8607A; }
.sel-sep { width: 1px; height: 16px; background: var(--border); margin: 0 3px; }
.sel-note-btn {
font-size: 12px; padding: 1px 8px; border-radius: 6px;
border: none; background: transparent; color: var(--text);
transition: background .12s;
}
.sel-note-btn:hover { background: var(--hover); }
/* ============================================================
Note editor modal
============================================================ */
#note-modal {
position: fixed; inset: 0; z-index: 400;
display: flex; align-items: center; justify-content: center;
background: rgba(0,0,0,.38);
backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
opacity: 0; pointer-events: none;
transition: opacity .2s;
}
#note-modal.on { opacity: 1; pointer-events: all; }
.note-card {
background: var(--panel-bg); border-radius: 18px;
width: 370px; max-width: 92vw; padding: 22px;
box-shadow: 0 24px 64px rgba(0,0,0,.22);
transition: background .3s;
}
.note-card-quote {
font-family: 'Spectral','Noto Serif SC',serif;
font-size: 13.5px; line-height: 1.6; color: var(--text);
opacity: .7; margin-bottom: 14px;
padding-left: 11px;
border-left: 2.5px solid var(--accent);
}
.note-ta {
width: 100%; min-height: 96px;
background: rgba(128,128,128,.07);
border: 1.5px solid var(--border); border-radius: 10px;
padding: 11px 13px; resize: vertical;
font-size: 14px; color: var(--text);
outline: none; transition: border-color .15s;
}
.note-ta:focus { border-color: var(--accent); }
.note-ta::placeholder { color: var(--text-muted); }
.note-card-acts {
display: flex; justify-content: flex-end; gap: 7px; margin-top: 11px;
}
.nc-btn {
padding: 7px 17px; border-radius: 8px; border: none;
font-size: 13.5px; transition: all .15s;
}
.nc-btn.cancel { background: transparent; color: var(--text-muted); }
.nc-btn.cancel:hover { background: var(--hover); }
.nc-btn.save { background: var(--accent); color: #fff; }
.nc-btn.save:hover { opacity: .85; }
/* ============================================================
Theme popup
============================================================ */
#theme-pop {
position: absolute; top: 50px; right: 12px;
background: var(--panel-bg);
border: 1px solid var(--border);
border-radius: 12px; padding: 6px;
box-shadow: 0 8px 28px var(--shadow);
display: none; flex-direction: column; gap: 1px;
z-index: 80; min-width: 132px;
backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
transition: background .3s;
}
#theme-pop.on { display: flex; }
.tp-opt {
display: flex; align-items: center; gap: 9px;
padding: 7px 11px; border-radius: 7px;
border: none; background: none; color: var(--text);
font-size: 13px; width: 100%; text-align: left;
transition: background .12s;
}
.tp-opt:hover { background: var(--hover); }
.tp-opt.cur { color: var(--accent); }
.tp-swatch {
width: 17px; height: 17px; border-radius: 50%; flex-shrink: 0;
border: 1px solid rgba(0,0,0,.12);
}
/* ============================================================
Overlay
============================================================ */
#overlay {
position: fixed; inset: 0; z-index: 100;
display: none;
}
#overlay.on { display: block; }
/* ============================================================
Misc
============================================================ */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
</style>
</head>
<body data-theme="sepia">
<!-- =================== DROP ZONE =================== -->
<div id="drop-zone">
<div class="dz-icon">📖</div>
<div class="dz-title">Bookleaf</div>
<div class="dz-sub">Drop an EPUB here, or click to open</div>
<button class="dz-btn" id="open-btn">Open File…</button>
<div class="dz-theme-row">
<div class="dz-theme-dot" data-t="day" title="Day"></div>
<div class="dz-theme-dot active" data-t="sepia" title="Sepia"></div>
<div class="dz-theme-dot" data-t="night" title="Night"></div>
</div>
<div class="dz-sync">
<div class="sync-dot" id="sync-dot"></div>
<span id="sync-label">No sync folder</span>
<button class="dz-sync-btn" id="sync-btn">Connect…</button>
</div>
</div>
<!-- =================== READER =================== -->
<div id="reader">
<!-- Toolbar -->
<div id="toolbar">
<div class="tb-left">
<button class="tb-btn" id="toc-btn" title="Contents">
<svg width="15" height="12" viewBox="0 0 15 12" fill="currentColor">
<rect x="0" y="0" width="15" height="1.8" rx=".9"/>
<rect x="0" y="5" width="10" height="1.8" rx=".9"/>
<rect x="0" y="10" width="12" height="1.8" rx=".9"/>
</svg>
</button>
<button class="tb-btn" id="home-btn" title="Close">
<svg width="14" height="14" viewBox="0 0 14 14" fill="currentColor">
<path d="M7 .5L.5 6H2.5V13H5.5V9H8.5V13H11.5V6H13.5Z"/>
</svg>
</button>
</div>
<div class="tb-center">
<div class="tb-title" id="tb-title">—</div>
</div>
<div class="tb-right">
<button class="tb-btn" id="fs-down" title="Smaller text" style="font-size:11px;font-weight:500;letter-spacing:-.3px">A−</button>
<div class="fs-num" id="fs-num">18</div>
<button class="tb-btn" id="fs-up" title="Larger text" style="font-size:13px;font-weight:500;">A+</button>
<div class="tb-sep"></div>
<button class="tb-btn" id="theme-btn" title="Appearance">
<svg width="15" height="15" viewBox="0 0 15 15" fill="none">
<circle cx="7.5" cy="7.5" r="6" stroke="currentColor" stroke-width="1.5"/>
<line x1="7.5" y1="1.5" x2="7.5" y2="13.5" stroke="currentColor" stroke-width="1.5"/>
<path d="M7.5 1.5A6 6 0 0 1 7.5 13.5Z" fill="currentColor"/>
</svg>
</button>
<button class="tb-btn" id="notes-btn" title="Highlights">
<svg width="14" height="14" viewBox="0 0 14 14" fill="currentColor">
<path d="M1 1h12v9H8.5L6 13V10H1V1Z"/>
</svg>
</button>
<!-- Theme popup (inside toolbar for positioning) -->
<div id="theme-pop">
<button class="tp-opt" data-t="day">
<div class="tp-swatch" style="background:#FBF7F0"></div>Day
</button>
<button class="tp-opt cur" data-t="sepia">
<div class="tp-swatch" style="background:#F5E9D5"></div>Sepia
</button>
<button class="tp-opt" data-t="night">
<div class="tp-swatch" style="background:#1C1C1E;border-color:rgba(255,255,255,.15)"></div>Night
</button>
</div>
</div>
</div>
<!-- Reader area -->
<div id="reader-area">
<button class="nav-btn" id="prev-btn" title="Previous">
<svg class="nav-chevron" viewBox="0 0 8 16" fill="none"
stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<polyline points="7,1 1,8 7,15"/>
</svg>
</button>
<div id="epub-viewer"></div>
<button class="nav-btn" id="next-btn" title="Next">
<svg class="nav-chevron" viewBox="0 0 8 16" fill="none"
stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<polyline points="1,1 7,8 1,15"/>
</svg>
</button>
</div>
<!-- Bottom bar -->
<div id="bottom-bar">
<div id="ch-title">—</div>
<div class="prog-row">
<div id="prog-track"><div id="prog-fill"></div></div>
<div id="prog-pct">0%</div>
</div>
</div>
</div>
<!-- =================== OVERLAY =================== -->
<div id="overlay"></div>
<!-- =================== TOC PANEL =================== -->
<div class="panel" id="toc-panel">
<div class="panel-head">
<span class="panel-label">Contents</span>
<button class="panel-x" id="toc-x">✕</button>
</div>
<div class="panel-body" id="toc-body">
<div class="panel-empty">Open a book to see its chapters.</div>
</div>
</div>
<!-- =================== NOTES PANEL =================== -->
<div class="panel" id="note-panel">
<div class="panel-head">
<span class="panel-label">Highlights</span>
<button class="panel-x" id="note-x">✕</button>
</div>
<div class="panel-body" id="note-body">
<div class="panel-empty">
Select text while reading<br>to highlight and annotate.
</div>
</div>
</div>
<!-- =================== SELECTION BAR =================== -->
<div id="sel-bar">
<button class="sel-dot" data-c="yellow" title="Yellow"></button>
<button class="sel-dot" data-c="green" title="Green"></button>
<button class="sel-dot" data-c="blue" title="Blue"></button>
<button class="sel-dot" data-c="pink" title="Pink"></button>
<div class="sel-sep"></div>
<button class="sel-note-btn" id="sel-note">Note</button>
</div>
<!-- =================== NOTE MODAL =================== -->
<div id="note-modal">
<div class="note-card">
<div class="note-card-quote" id="nm-quote"></div>
<textarea class="note-ta" id="nm-ta" placeholder="Add a note…"></textarea>
<div class="note-card-acts">
<button class="nc-btn cancel" id="nm-cancel">Cancel</button>
<button class="nc-btn save" id="nm-save">Save</button>
</div>
</div>
</div>
<!-- hidden file input -->
<input type="file" id="file-in" accept=".epub" style="display:none">
<!-- =================== JAVASCRIPT =================== -->
<script>
'use strict';
/* ============================================================
State
============================================================ */
let book = null;
let rend = null; // rendition
let bookId = null;
let allData = { v: 1, books: {} };
let syncDir = null; // FileSystemDirectoryHandle
let theme = 'sepia';
let fontSize = 18;
let animating = false;
let selCfi = null;
let selText = null;
let pendingHl = null; // { cfi, text, color } awaiting note
let nmCb = null; // note modal callback
const HL_FILLS = {
yellow: 'rgba(232,184,75,.40)',
green: 'rgba(76,175,117,.38)',
blue: 'rgba(91,143,214,.38)',
pink: 'rgba(232,96,122,.35)',
};
/* ============================================================
DOM helpers
============================================================ */
const $ = id => document.getElementById(id);
const dropZone = $('drop-zone');
const reader = $('reader');
const epubViewer = $('epub-viewer');
const selBar = $('sel-bar');
const noteModal = $('note-modal');
const overlay = $('overlay');
/* ============================================================
IndexedDB – persist FileSystemDirectoryHandle
============================================================ */
function openIDB() {
return new Promise((res, rej) => {
const r = indexedDB.open('bookleaf_v1', 1);
r.onupgradeneeded = e => e.target.result.createObjectStore('kv');
r.onsuccess = e => res(e.target.result);
r.onerror = rej;
});
}
async function idbGet(k) {
const db = await openIDB();
return new Promise((res, rej) => {
const tx = db.transaction('kv','readonly');
const r = tx.objectStore('kv').get(k);
r.onsuccess = e => res(e.target.result);
r.onerror = rej;
});
}
async function idbSet(k, v) {
const db = await openIDB();
return new Promise((res, rej) => {
const tx = db.transaction('kv','readwrite');
tx.objectStore('kv').put(v, k);
tx.oncomplete = res; tx.onerror = rej;
});
}
/* ============================================================
Sync folder (File System Access API)
============================================================ */
async function initSync() {
try {
const h = await idbGet('syncDir');
if (!h) return;
const perm = await h.queryPermission({ mode: 'readwrite' });
if (perm === 'granted') {
syncDir = h;
setSyncUI(true);
await loadData();
} else {
syncDir = h;
setSyncUI(false, 'Re-connect sync folder');
}
} catch(_) {}
}
async function connectSync() {
try {
const h = await window.showDirectoryPicker({ mode: 'readwrite' });
syncDir = h;
await idbSet('syncDir', h);
setSyncUI(true);
await loadData();
} catch(e) {
if (e.name !== 'AbortError') console.warn(e);
}
}
function setSyncUI(ok, msg) {
$('sync-dot').className = 'sync-dot' + (ok ? ' on' : '');
$('sync-label').textContent = ok
? `Syncing · ${syncDir.name}`
: (msg || 'No sync folder');
}
async function loadData() {
if (!syncDir) return;
try {
const fh = await syncDir.getFileHandle('bookleaf.json', { create: true });
const file = await fh.getFile();
const txt = await file.text();
if (txt.trim()) allData = JSON.parse(txt);
if (!allData.books) allData.books = {};
} catch(e) { console.warn('loadData', e); }
}
async function saveData() {
if (!syncDir) return;
try {
const perm = await syncDir.requestPermission({ mode: 'readwrite' });
if (perm !== 'granted') return;
const fh = await syncDir.getFileHandle('bookleaf.json', { create: true });
const wr = await fh.createWritable();
await wr.write(JSON.stringify(allData, null, 2));
await wr.close();
} catch(e) { console.warn('saveData', e); }
}
function bookData() {
if (!bookId) return null;
if (!allData.books[bookId])
allData.books[bookId] = { title:'', author:'', progress: null, hl:[] };
return allData.books[bookId];
}
/* ============================================================
Simple string hash for book ID
============================================================ */
function hash(s) {
let h = 0x811c9dc5;
for (let i = 0; i < s.length; i++) {
h ^= s.charCodeAt(i);
h = (h * 0x01000193) >>> 0;
}
return h.toString(36);
}
/* ============================================================
Theme
============================================================ */
const THEMES = {
day: { body: { background: '#FBF7F0 !important', color: '#1A1A1A !important' } },
sepia: { body: { background: '#F5E9D5 !important', color: '#3B2E1E !important' } },
night: { body: { background: '#1C1C1E !important', color: '#E5E0D8 !important' } },
};
function setTheme(t) {
theme = t;
document.body.setAttribute('data-theme', t);
document.querySelectorAll('.dz-theme-dot').forEach(d =>
d.classList.toggle('active', d.dataset.t === t));
document.querySelectorAll('.tp-opt').forEach(o =>
o.classList.toggle('cur', o.dataset.t === t));
if (rend) rend.themes.select(t);
}
/* ============================================================
Font size
============================================================ */
function setFontSize(n) {
fontSize = Math.max(12, Math.min(30, n));
$('fs-num').textContent = fontSize;
if (rend) rend.themes.fontSize(fontSize + 'px');
}
/* ============================================================
Open book
============================================================ */
async function openBook(buf, filename) {
// tear down previous
if (rend) { rend.destroy(); rend = null; }
if (book) { book.destroy(); book = null; }
epubViewer.innerHTML = '';
book = ePub(buf);
await book.ready;
const meta = book.packaging.metadata;
const title = meta.title || filename.replace(/\.epub$/i,'');
const author = meta.creator || '';
bookId = hash(title + author);
const bd = bookData();
bd.title = title; bd.author = author;
$('tb-title').textContent = title;
// Rendition
const wide = window.innerWidth >= 860;
rend = book.renderTo('epub-viewer', {
width: epubViewer.clientWidth,
height: epubViewer.clientHeight,
spread: wide ? 'always' : 'none',
minSpreadWidth: 0,
flow: 'paginated',
});
// Show spine line if in spread mode
epubViewer.classList.toggle('spread', wide);
// Register themes
Object.entries(THEMES).forEach(([n, s]) => rend.themes.register(n, s));
rend.themes.select(theme);
rend.themes.fontSize(fontSize + 'px');
// Inject reading styles + Google Fonts into each chapter iframe
rend.hooks.content.register(contents => {
const doc = contents.document;
// fonts
const lnk = doc.createElement('link');
lnk.rel = 'stylesheet';
lnk.href = 'https://fonts.googleapis.com/css2?family=Spectral:ital,wght@0,300;0,400;0,500;1,300;1,400&family=Noto+Serif+SC:wght@300;400;500&display=swap';
doc.head.appendChild(lnk);
// reading styles
const st = doc.createElement('style');
st.textContent = `
body {
font-family: 'Spectral','Noto Serif SC',Georgia,serif !important;
line-height: 1.80 !important;
-webkit-font-smoothing: antialiased;
}
p { text-indent: 1.5em; margin-bottom: 0 !important; margin-top: 0 !important; }
h1,h2,h3,h4,h5,h6 {
font-family: 'Spectral','Noto Serif SC',serif !important;
line-height: 1.3 !important; text-indent: 0 !important;
}
a { color: inherit !important; }
`;
doc.head.appendChild(st);
});
// Location change
rend.on('locationChanged', loc => onLocationChanged(loc));
// Text selection → highlight bar
rend.on('selected', (cfiRange, contents) => {
const sel = contents.window.getSelection();
if (!sel || sel.isCollapsed) return;
const txt = sel.toString().trim();
if (txt.length < 2) return;
selCfi = cfiRange;
selText = txt;
// Position sel-bar near selection
try {
const range = sel.getRangeAt(0);
const rect = range.getBoundingClientRect();
const iframe = epubViewer.querySelector('iframe');
const iRect = iframe ? iframe.getBoundingClientRect() : {left:0,top:0};
const cx = iRect.left + rect.left + rect.width / 2;
const cy = iRect.top + rect.top - 52;
selBar.style.left = Math.max(8, Math.min(cx - 115, window.innerWidth - 248)) + 'px';
selBar.style.top = Math.max(8, cy) + 'px';
selBar.classList.add('on');
} catch(_) {}
});
// Deselect → hide bar (with slight delay so dot click fires first)
rend.on('deselected', () => setTimeout(hideSelBar, 180));
// Start position
const start = bd.progress?.cfi || undefined;
await rend.display(start);
buildTOC();
restoreHighlights();
// Show reader
dropZone.style.display = 'none';
reader.classList.add('on');
}
/* ============================================================
Location / progress
============================================================ */
async function onLocationChanged(loc) {
if (!loc || !book) return;
const s = loc.start;
const bd = bookData();
if (bd) {
bd.progress = { cfi: s.cfi, pct: s.percentage, ts: Date.now() };
}
const pct = Math.round((s.percentage || 0) * 100);
$('prog-fill').style.width = pct + '%';
$('prog-pct').textContent = pct + '%';
// Chapter label
try {
const nav = book.navigation;
const item = nav && nav.get(s.href);
$('ch-title').textContent = item ? (item.label?.trim() || '—') : '—';
} catch(_) {}
await saveData();
}
/* ============================================================
Navigation with page-turn animation
============================================================ */
function go(dir) {
if (animating || !rend) return;
animating = true;
const cls = dir === 'next' ? 'anim-next' : 'anim-prev';
epubViewer.classList.add(cls);
epubViewer.addEventListener('animationend', () => {
epubViewer.classList.remove(cls);
animating = false;
}, { once: true });
dir === 'next' ? rend.next() : rend.prev();
}
/* ============================================================
TOC
============================================================ */
async function buildTOC() {
const nav = book.navigation;
const body = $('toc-body');
if (!nav?.toc?.length) {
body.innerHTML = '<div class="panel-empty">No table of contents.</div>';
return;
}
body.innerHTML = '';
function walk(items, depth) {
items.forEach(item => {
const btn = document.createElement('button');
btn.className = 'toc-row';
btn.dataset.d = depth;
btn.textContent = item.label?.trim() || 'Untitled';
btn.onclick = () => { rend.display(item.href); closeAll(); };
body.appendChild(btn);
if (item.subitems?.length) walk(item.subitems, depth + 1);
});
}
walk(nav.toc, 1);