-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
4008 lines (3578 loc) · 167 KB
/
index.html
File metadata and controls
4008 lines (3578 loc) · 167 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="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Parallel Reader - 极简项目批注版</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf_viewer.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.js"></script>
<style>
:root { color-scheme: light; }
body.theme-normal {
--bg-main:#f5f7fb; --bg-toolbar:rgba(255,255,255,.92); --bg-header:#ffffff; --surface:#ffffff; --surface-2:#f8fafc;
--text-main:#111827; --text-muted:#64748b; --border:#e5e7eb; --border-soft:#eef2f7;
--btn-hover:#f1f5f9; --input-bg:#ffffff; --page-bg:#ffffff; --shadow:0 18px 45px rgba(15,23,42,.08);
--sidebar-bg:#fbfdff; --sidebar-hover:#eef6ff; --accent:#2563eb; --accent-soft:#e8f0ff; --danger:#dc2626; --danger-soft:#fff1f2;
--selection:rgba(37,99,235,.38); --page-filter:none; --page-blend:normal; --focus:0 0 0 3px rgba(37,99,235,.16);
}
body.theme-dark {
color-scheme: dark;
--bg-main:#101318; --bg-toolbar:rgba(18,22,28,.92); --bg-header:#161b22; --surface:#161b22; --surface-2:#111720;
--text-main:#e5e7eb; --text-muted:#94a3b8; --border:#263241; --border-soft:#1f2937;
--btn-hover:#202a36; --input-bg:#0d1117; --page-bg:#1c212b; --shadow:0 20px 50px rgba(0,0,0,.38);
--sidebar-bg:#131922; --sidebar-hover:#1f2937; --accent:#60a5fa; --accent-soft:#14243b; --danger:#f87171; --danger-soft:#351a1f;
--selection:rgba(96,165,250,.48); --page-filter:invert(.86) hue-rotate(180deg) contrast(1.06); --page-blend:normal; --focus:0 0 0 3px rgba(96,165,250,.20);
}
body.theme-green {
--bg-main:#eef7ef; --bg-toolbar:rgba(248,253,249,.92); --bg-header:#f9fffa; --surface:#fbfffc; --surface-2:#f0f8f1;
--text-main:#1f3d27; --text-muted:#5f7f67; --border:#d6e8d9; --border-soft:#e6f2e8;
--btn-hover:#e6f3e8; --input-bg:#ffffff; --page-bg:#edf8ee; --shadow:0 18px 45px rgba(31,61,39,.10);
--sidebar-bg:#f4fbf5; --sidebar-hover:#e4f2e6; --accent:#2f7d4f; --accent-soft:#e7f4ec; --danger:#c2410c; --danger-soft:#fff4ed;
--selection:rgba(37,99,235,.36); --page-filter:none; --page-blend:multiply; --focus:0 0 0 3px rgba(47,125,79,.18);
}
body.theme-sepia {
--bg-main:#f7f0e2; --bg-toolbar:rgba(255,250,240,.92); --bg-header:#fff8ec; --surface:#fffaf0; --surface-2:#fbf1df;
--text-main:#473829; --text-muted:#8a735a; --border:#eadcc4; --border-soft:#f2e8d7;
--btn-hover:#f4e8d2; --input-bg:#fffaf0; --page-bg:#fff6e6; --shadow:0 18px 45px rgba(71,56,41,.10);
--sidebar-bg:#fff8ec; --sidebar-hover:#f3e4ca; --accent:#9a6a2f; --accent-soft:#f3e7d5; --danger:#b45309; --danger-soft:#fff7ed;
--selection:rgba(37,99,235,.34); --page-filter:none; --page-blend:multiply; --focus:0 0 0 3px rgba(154,106,47,.18);
}
body.theme-gray {
--bg-main:#f1f3f5; --bg-toolbar:rgba(255,255,255,.90); --bg-header:#ffffff; --surface:#ffffff; --surface-2:#f6f7f8;
--text-main:#22272e; --text-muted:#6b7280; --border:#d7dce2; --border-soft:#e7eaee;
--btn-hover:#eef0f2; --input-bg:#ffffff; --page-bg:#f7f7f7; --shadow:0 18px 45px rgba(0,0,0,.08);
--sidebar-bg:#fafafa; --sidebar-hover:#eceff2; --accent:#475569; --accent-soft:#edf0f4; --danger:#dc2626; --danger-soft:#fff1f2;
--selection:rgba(37,99,235,.34); --page-filter:none; --page-blend:multiply; --focus:0 0 0 3px rgba(71,85,105,.16);
}
* { box-sizing:border-box; }
body {
margin:0; height:100vh; overflow:hidden; display:flex; flex-direction:column;
font-family:Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Microsoft YaHei", sans-serif;
background:linear-gradient(180deg, var(--surface-2) 0%, var(--bg-main) 44%, var(--bg-main) 100%);
color:var(--text-main); transition:background .18s,color .18s;
-webkit-font-smoothing:antialiased; text-rendering:geometricPrecision;
}
button, select, input { font:inherit; }
button:focus-visible, select:focus-visible, input:focus-visible { outline:none; box-shadow:var(--focus); }
.toolbar {
min-height:56px; padding:10px 14px; display:flex; align-items:center; flex-wrap:wrap; gap:10px;
background:var(--bg-toolbar); border-bottom:1px solid var(--border); z-index:100; backdrop-filter:saturate(180%) blur(16px);
}
.brand { display:flex; flex-direction:column; gap:1px; padding:0 6px 0 2px; min-width:128px; }
.brand-title { font-size:14px; font-weight:760; letter-spacing:-.02em; line-height:1.1; }
.brand-subtitle { font-size:11px; color:var(--text-muted); line-height:1.2; }
.toolbar-group { display:flex; align-items:center; gap:6px; padding:4px; border:1px solid var(--border-soft); border-radius:999px; background:rgba(255,255,255,.42); }
.project-status { font-size:12px; color:var(--text-muted); padding:0 6px; max-width:180px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.toggle-label { display:flex; align-items:center; gap:4px; font-size:12px; color:var(--text-muted); padding:0 4px; user-select:none; white-space:nowrap; }
.toggle-label input { accent-color:var(--accent); }
body.theme-dark .toolbar-group { background:rgba(255,255,255,.03); }
.toolbar button, .toolbar select, .mini-btn {
height:30px; padding:0 11px; border-radius:999px; border:1px solid transparent; background:transparent; color:var(--text-main);
font-size:12px; cursor:pointer; transition:background .14s,border-color .14s,box-shadow .14s,transform .12s,opacity .14s; white-space:nowrap;
}
.toolbar button:hover:not(:disabled), .toolbar select:hover, .mini-btn:hover:not(:disabled) { background:var(--btn-hover); border-color:var(--border); }
.toolbar button.icon-btn { width:30px; min-width:30px; padding:0; display:inline-grid; place-items:center; font-size:14px; font-weight:760; line-height:1; }
.quick-nav { gap:3px; }
.quick-nav .icon-btn[disabled] { opacity:.32; }
.toolbar-menu { position:relative; }
.toolbar-menu summary { list-style:none; height:30px; padding:0 12px; border-radius:999px; border:1px solid transparent; display:flex; align-items:center; gap:6px; cursor:pointer; font-size:12px; user-select:none; white-space:nowrap; }
.toolbar-menu summary::-webkit-details-marker { display:none; }
.toolbar-menu summary::after { content:"⌄"; font-size:11px; color:var(--text-muted); transform:translateY(-1px); }
.toolbar-menu[open] summary, .toolbar-menu summary:hover { background:var(--btn-hover); border-color:var(--border); }
.toolbar-popover { position:absolute; top:calc(100% + 8px); left:0; min-width:230px; padding:10px; border:1px solid var(--border); border-radius:16px; background:var(--surface); box-shadow:0 22px 60px rgba(15,23,42,.18); display:flex; flex-direction:column; gap:8px; z-index:500; }
body.theme-dark .toolbar-popover { box-shadow:0 24px 70px rgba(0,0,0,.46); }
.toolbar-popover.right { left:auto; right:0; }
.toolbar-popover .menu-row { display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.toolbar-popover button, .toolbar-popover select { border-color:var(--border); background:transparent; }
.toolbar-popover .menu-label { font-size:11px; color:var(--text-muted); padding:0 4px; }
.color-palette { display:flex; align-items:center; gap:5px; padding:2px 3px; border-radius:999px; border:1px solid var(--border-soft); background:var(--surface); }
.color-swatch { width:22px!important; height:22px!important; min-width:22px!important; padding:0!important; border-radius:999px!important; border:1px solid rgba(15,23,42,.14)!important; box-shadow:inset 0 0 0 2px rgba(255,255,255,.58); }
.color-swatch.active { outline:2px solid var(--accent); outline-offset:2px; }
.color-swatch[data-color="yellow"] { background:#fde047!important; }
.color-swatch[data-color="green"] { background:#86efac!important; }
.color-swatch[data-color="blue"] { background:#93c5fd!important; }
.color-swatch[data-color="pink"] { background:#f9a8d4!important; }
.color-swatch[data-color="purple"] { background:#c4b5fd!important; }
.compact-label { display:inline-flex; align-items:center; gap:6px; font-size:12px; color:var(--text-muted); white-space:nowrap; }
.toolbar button:active:not(:disabled), .mini-btn:active:not(:disabled) { transform:translateY(1px); }
.toolbar button:disabled, .mini-btn:disabled { opacity:.36; cursor:not-allowed; }
.btn-primary { background:var(--accent)!important; border-color:var(--accent)!important; color:#fff!important; font-weight:700; box-shadow:0 8px 22px rgba(37,99,235,.20); }
body.theme-dark .btn-primary { color:#07111f!important; box-shadow:0 10px 28px rgba(96,165,250,.18); }
.btn-active { background:var(--accent-soft)!important; border-color:var(--accent)!important; color:var(--accent)!important; font-weight:700; }
.btn-danger:hover { background:var(--danger-soft)!important; border-color:var(--danger)!important; color:var(--danger)!important; }
.divider { width:1px; height:22px; background:var(--border); margin:0 2px; flex:0 0 auto; opacity:.8; }
#fileListHint, #memoryHint, #memoryStats { color:var(--text-muted); font-size:12px; max-width:300px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
#memoryHint { color:var(--accent); display:none; }
#memoryStats { margin-left:auto; padding:0 4px; }
.zoom-group { display:flex; align-items:center; gap:2px; border:1px solid var(--border); border-radius:999px; padding:2px 3px; background:var(--surface); }
.zoom-group .mini-btn { height:24px; min-width:24px; padding:0 7px; }
.data-input {
width:42px; height:24px; padding:0 3px; border:0; border-radius:999px; background:transparent; color:var(--text-main);
text-align:center; font-size:12px; font-weight:720;
}
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button { -webkit-appearance:none; margin:0; }
input[type="number"] { -moz-appearance:textfield; }
#viewer-container { flex:1; display:flex; min-height:0; width:100%; overflow:hidden; gap:12px; padding:12px; background:transparent; }
.empty-state {
margin:auto; width:min(520px, calc(100% - 32px)); padding:38px 36px; color:var(--text-muted); text-align:center; line-height:1.8; font-size:14px;
border:1px solid var(--border); border-radius:24px; background:var(--surface); box-shadow:var(--shadow);
}
.empty-state .empty-mark { width:54px; height:54px; margin:0 auto 14px; border-radius:18px; display:grid; place-items:center; background:var(--accent-soft); color:var(--accent); font-weight:800; font-size:22px; }
.empty-state .empty-title { margin-bottom:6px; color:var(--text-main); font-size:18px; font-weight:780; letter-spacing:-.02em; }
.empty-state .empty-desc { font-size:13px; }
.panel-wrapper {
flex:1 1 0; min-width:280px; display:flex; flex-direction:column; overflow:hidden; background:var(--surface);
border:1px solid var(--border); border-radius:18px; box-shadow:var(--shadow);
}
.panel-wrapper.loading .pdf-panel { opacity:0; }
.panel-wrapper.loading .panel-body { position:relative; }
.panel-wrapper.loading .panel-body::after {
content:"正在加载 PDF…"; position:absolute; inset:0; display:grid; place-items:center;
color:var(--text-muted); font-size:13px; background:var(--surface-2); z-index:2;
}
.panel-wrapper:last-child { border-right:1px solid var(--border); }
.panel-header {
min-height:44px; padding:7px 9px; display:flex; align-items:center; justify-content:space-between; gap:8px;
background:var(--bg-header); border-bottom:1px solid var(--border-soft); z-index:50;
}
.header-left { display:flex; align-items:center; gap:7px; flex:1 1 auto; min-width:0; }
.drag-handle { cursor:grab; color:var(--text-muted); padding:0 6px; user-select:none; font-size:15px; border-radius:999px; }
.drag-handle:hover { background:var(--btn-hover); color:var(--text-main); }
.drag-handle:active { cursor:grabbing; color:var(--accent); }
.panel-title { font-size:12.5px; font-weight:760; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; min-width:0; letter-spacing:-.01em; }
.panel-controls { display:flex; align-items:center; gap:4px; color:var(--text-muted); flex:0 0 auto; }
.panel-controls .divider { height:18px; margin:0 3px; }
.mini-btn { height:26px; padding:0 9px; font-size:11.5px; border:1px solid var(--border); background:var(--surface); }
.mini-btn.active { background:var(--accent-soft); border-color:var(--accent); color:var(--accent); font-weight:700; }
.btn-close { width:26px; height:26px; border:none; border-radius:999px; background:transparent; color:var(--text-muted); font-size:16px; cursor:pointer; padding:0; display:grid; place-items:center; }
.btn-close:hover { color:var(--danger); background:var(--danger-soft); }
.panel-body { flex:1; min-height:0; display:flex; overflow:hidden; background:var(--surface-2); }
.panel-sidebar {
width:250px; flex:0 0 250px; display:none; flex-direction:column; overflow:hidden; background:var(--sidebar-bg); border-right:1px solid var(--border-soft); font-size:12px;
}
.sidebar-tabs { display:flex; gap:4px; padding:8px; border-bottom:1px solid var(--border-soft); flex:0 0 auto; overflow-x:auto; }
.sidebar-tabs::-webkit-scrollbar { height: 0; }
.sidebar-tab { flex:1; min-width:40px; height:30px; padding:0 8px; color:var(--text-muted); background:transparent; border:1px solid transparent; border-radius:999px; cursor:pointer; font-size:12px; }
.sidebar-tab:hover { background:var(--btn-hover); }
.sidebar-tab.active { color:var(--accent); font-weight:760; border-color:var(--accent); background:var(--accent-soft); }
.sidebar-content { flex:1; min-height:0; overflow:auto; padding:10px; scrollbar-gutter:stable; }
ul.toc-list { list-style:none; margin:0; padding-left:10px; }
ul.toc-list > li { margin:3px 0; }
.toc-link { display:block; padding:6px 8px; color:var(--text-main); text-decoration:none; border-radius:10px; line-height:1.36; cursor:pointer; }
.toc-link:hover { background:var(--sidebar-hover); color:var(--accent); }
.search-box { display:flex; gap:6px; margin-bottom:10px; }
.search-input { min-width:0; flex:1; height:34px; padding:0 11px; border:1px solid var(--border); border-radius:12px; outline:none; background:var(--input-bg); color:var(--text-main); font-size:12px; }
.search-input:focus { border-color:var(--accent); box-shadow:var(--focus); }
.search-result-item { padding:9px 8px; border:1px solid transparent; border-bottom-color:var(--border-soft); border-radius:12px; cursor:pointer; line-height:1.45; word-break:break-word; }
.search-result-item:hover { background:var(--sidebar-hover); border-color:var(--border-soft); }
.search-result-item b { color:var(--accent); }
.pdf-panel { flex:1; min-width:0; overflow:auto; padding:24px 0; position:relative; scroll-behavior:auto; background:linear-gradient(180deg,var(--surface-2),var(--bg-main)); scrollbar-gutter:stable; }
.page-wrapper {
position:relative; margin:0 auto 18px auto; display:flex; align-items:center; justify-content:center; overflow:hidden;
background:var(--page-bg); border:1px solid rgba(148,163,184,.18); border-radius:6px; box-shadow:0 10px 28px rgba(15,23,42,.12); color:var(--text-muted); font-size:12px;
}
body.theme-dark .page-wrapper { box-shadow:0 16px 32px rgba(0,0,0,.32); border-color:rgba(148,163,184,.12); }
.page-placeholder { user-select:none; color:var(--text-muted); opacity:.72; }
.page-content { position:absolute; left:0; top:0; transform-origin:0 0; will-change:transform; mix-blend-mode:var(--page-blend); }
.page-wrapper canvas { display:block; filter:var(--page-filter); mix-blend-mode:normal; image-rendering:auto; backface-visibility:hidden; }
.textLayer { position:absolute; inset:0; overflow:hidden; transform-origin:0 0; z-index:6; }
.textLayer ::selection { background:var(--selection)!important; color:transparent!important; }
.pdf-link { position:absolute; z-index:20; border-radius:4px; transition:background .12s, box-shadow .12s; }
.pdf-link:hover { background:rgba(37,99,235,.14); box-shadow:0 0 0 1px rgba(37,99,235,.26) inset; }
.search-hit-layer { position:absolute; inset:0; z-index:9; pointer-events:none; }
.search-hit {
position:absolute; border-radius:4px;
background:rgba(255, 221, 51, .62);
outline:3px solid rgba(245, 158, 11, .96);
box-shadow:0 0 0 4px rgba(245, 158, 11, .18), 0 8px 20px rgba(245, 158, 11, .22);
mix-blend-mode:multiply;
animation:searchHitPulse 1.15s ease-in-out 0s 3;
}
body.theme-dark .search-hit { mix-blend-mode:screen; background:rgba(250, 204, 21, .38); outline-color:rgba(251, 191, 36, .95); }
@keyframes searchHitPulse {
0%, 100% { transform:scale(1); opacity:.92; }
50% { transform:scale(1.025); opacity:1; }
}
.toast {
position:fixed; left:50%; bottom:24px; transform:translateX(-50%) translateY(8px); padding:10px 14px; border-radius:999px;
background:rgba(15,23,42,.88); color:#fff; font-size:13px; z-index:999; opacity:0; pointer-events:none; transition:opacity .18s, transform .18s; box-shadow:0 16px 40px rgba(0,0,0,.22); backdrop-filter:blur(10px);
}
.toast.show { opacity:1; transform:translateX(-50%) translateY(0); }
.notes-actions { display:flex; gap:6px; margin-bottom:8px; flex-wrap:wrap; }
.notes-actions .mini-btn { height:28px; }
.note-search-input { width:100%; height:34px; padding:0 11px; margin-bottom:10px; border:1px solid var(--border); border-radius:12px; outline:none; background:var(--input-bg); color:var(--text-main); font-size:12px; }
.note-search-input:focus { border-color:var(--accent); box-shadow:var(--focus); }
.notes-list { display:flex; flex-direction:column; gap:8px; }
.note-item { padding:9px 9px; border:1px solid var(--border-soft); border-radius:12px; background:var(--surface); cursor:pointer; line-height:1.42; }
.note-item:hover { background:var(--sidebar-hover); border-color:var(--border); }
.note-item.active-note {
border-color:var(--accent);
background:var(--accent-soft);
box-shadow:0 0 0 2px color-mix(in srgb, var(--accent) 16%, transparent);
}
.note-meta { display:flex; align-items:center; justify-content:space-between; gap:8px; margin-bottom:5px; font-size:11px; color:var(--text-muted); }
.note-type { color:var(--accent); font-weight:760; display:inline-flex; align-items:center; gap:5px; }
.note-color-dot { width:9px; height:9px; border-radius:999px; display:inline-block; border:1px solid rgba(15,23,42,.16); }
.note-title { font-size:12px; color:var(--text-main); font-weight:720; margin-bottom:3px; word-break:break-word; }
.note-locator { display:flex; align-items:center; gap:6px; flex-wrap:wrap; margin-bottom:6px; font-size:11px; color:var(--text-muted); }
.note-chip { display:inline-flex; align-items:center; height:20px; padding:0 7px; border-radius:999px; background:var(--accent-soft); color:var(--accent); font-weight:760; }
.note-excerpt-label { margin-top:6px; margin-bottom:3px; font-size:11px; color:var(--text-muted); font-weight:760; }
.note-quote { padding:6px 8px; border-radius:10px; background:rgba(148,163,184,.10); color:var(--text-muted); font-size:11.5px; line-height:1.45; word-break:break-word; }
.note-body { font-size:12px; color:var(--text-main); word-break:break-word; max-height:180px; overflow:auto; padding:7px 8px; border-radius:10px; background:var(--surface-2); }
.note-body:empty::before { content:"(空批注)"; color:var(--text-muted); }
.markdown-body { line-height:1.55; color:inherit; }
.markdown-body p { margin:0 0 6px; }
.markdown-body p:last-child { margin-bottom:0; }
.markdown-body ul, .markdown-body ol { margin:4px 0 8px 18px; padding:0; }
.markdown-body li { margin:2px 0; }
.markdown-body blockquote { margin:6px 0; padding:4px 8px; border-left:3px solid var(--border); background:var(--surface-2); border-radius:8px; }
.markdown-body code { padding:1px 5px; border-radius:6px; background:var(--surface-2); color:var(--text-main); font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; font-size:.92em; }
.markdown-body pre { margin:6px 0; padding:8px; border-radius:10px; background:var(--surface-2); overflow:auto; }
.markdown-body pre code { padding:0; background:transparent; }
.markdown-body a { color:var(--accent); text-decoration:none; }
.markdown-body a:hover { text-decoration:underline; }
.markdown-body .katex-display { margin:.55em 0; overflow-x:auto; overflow-y:hidden; padding:2px 0; }
.markdown-body .katex { color:var(--text-main); }
.markdown-body .math-error { color:var(--danger); font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; }
.panel-wrapper { position:relative; }
.panel-resizer {
position:absolute; top:0; width:14px; height:100%;
cursor:col-resize; z-index:80; touch-action:none;
}
.panel-resizer-right { right:-7px; }
.panel-resizer-left { left:-7px; }
.panel-resizer::after {
content:""; position:absolute; top:48px; bottom:18px; left:6px; width:2px;
border-radius:999px; background:transparent; transition:background .14s, box-shadow .14s;
}
.panel-resizer:hover::after,
.panel-resizer.dragging::after {
background:var(--accent);
box-shadow:0 0 0 3px var(--accent-soft);
}
body.resizing-layout { cursor:col-resize!important; user-select:none; }
body.resizing-layout * { cursor:col-resize!important; }
.note-actions-row { display:flex; gap:6px; margin-top:8px; }
.note-actions-row button { height:24px; padding:0 8px; border-radius:999px; border:1px solid var(--border); background:transparent; color:var(--text-main); font-size:11px; cursor:pointer; }
.note-actions-row button:hover { background:var(--btn-hover); }
.page-note-marker { position:absolute; right:10px; top:10px; z-index:18; min-width:26px; height:26px; padding:0 8px; border-radius:999px; border:1px solid rgba(202,138,4,.35); background:rgba(254,243,199,.92); color:#92400e; font-size:12px; font-weight:760; display:flex; align-items:center; justify-content:center; cursor:pointer; box-shadow:0 8px 20px rgba(146,64,14,.16); backdrop-filter:blur(6px); }
body.theme-dark .page-note-marker { background:rgba(120,77,20,.86); color:#fde68a; border-color:rgba(253,230,138,.30); }
.note-highlight-layer { position:absolute; inset:0; z-index:7; pointer-events:none; }
.note-highlight { position:absolute; border-radius:3px; box-shadow:0 0 0 1px rgba(15,23,42,.10) inset; mix-blend-mode:multiply; pointer-events:auto; cursor:pointer; }
body.theme-dark .note-highlight { mix-blend-mode:screen; }
.note-highlight:hover { outline:2px solid rgba(37,99,235,.38); }
.note-modal-backdrop {
position:fixed; inset:0; z-index:1200; display:none; pointer-events:none;
background:transparent; backdrop-filter:none;
}
.note-modal-backdrop.show { display:block; }
.note-modal {
position:fixed; left:24px; top:78px; width:min(560px, calc(100vw - 48px)); height:520px;
min-width:340px; min-height:260px; max-width:calc(100vw - 24px); max-height:calc(100vh - 24px);
border:1px solid var(--border); border-radius:20px; background:var(--surface);
box-shadow:0 28px 80px rgba(15,23,42,.28); overflow:hidden; pointer-events:auto;
resize:both; display:flex; flex-direction:column;
}
.note-modal-header { display:flex; align-items:center; justify-content:space-between; gap:10px; padding:14px 16px; border-bottom:1px solid var(--border-soft); cursor:move; user-select:none; }
.note-modal-title { font-size:15px; font-weight:780; color:var(--text-main); }
.note-modal-close { width:28px; height:28px; border:0; border-radius:999px; background:transparent; color:var(--text-muted); cursor:pointer; font-size:18px; }
.note-modal-close:hover { background:var(--btn-hover); color:var(--danger); }
.note-modal-body {
padding:14px 16px; flex:1; min-height:0;
display:flex; flex-direction:column; overflow:hidden;
}
.note-modal-hint { flex:0 0 auto; margin-bottom:8px; font-size:12px; color:var(--text-muted); line-height:1.45; }
.note-modal-text {
display:block; width:100%; max-width:100%; min-width:0; box-sizing:border-box;
flex:1 1 54%; min-height:80px; resize:none; overflow:auto; padding:11px 12px;
border:1px solid var(--border); border-radius:14px; outline:none;
background:var(--input-bg); color:var(--text-main); font-size:13px; line-height:1.55;
}
.note-modal-text:focus { border-color:var(--accent); box-shadow:var(--focus); }
.note-modal-splitter {
flex:0 0 12px; margin:7px 0; cursor:row-resize; position:relative; touch-action:none;
}
.note-modal-splitter::before {
content:""; position:absolute; left:38%; right:38%; top:5px; height:2px;
border-radius:999px; background:var(--border); transition:background .14s, left .14s, right .14s;
}
.note-modal-splitter:hover::before,
.note-modal-splitter.dragging::before {
left:28%; right:28%; background:var(--accent);
}
.note-modal-preview {
display:block; margin-top:0; padding:10px 12px; width:100%; max-width:100%; min-width:0; box-sizing:border-box;
flex:1 1 46%; min-height:70px; resize:none; overflow:auto;
border:1px dashed var(--border); border-radius:14px; background:var(--surface-2); font-size:13px;
}
.note-modal-preview:empty::before { content:"Markdown / LaTeX 预览"; color:var(--text-muted); opacity:.75; }
.note-modal-footer { flex:0 0 auto; display:flex; justify-content:space-between; gap:8px; padding:12px 16px 16px; border-top:1px solid var(--border-soft); }
.note-modal-footer .left, .note-modal-footer .right { display:flex; gap:8px; }
.note-modal-footer button { height:32px; padding:0 13px; border-radius:999px; border:1px solid var(--border); background:transparent; color:var(--text-main); cursor:pointer; font-size:12px; }
.note-modal-footer button:hover { background:var(--btn-hover); }
.note-modal-footer .primary { background:var(--accent); border-color:var(--accent); color:#fff; font-weight:760; }
.note-modal-footer .danger { color:var(--danger); border-color:rgba(220,38,38,.35); }
.note-modal-footer .danger:hover { background:var(--danger-soft); border-color:var(--danger); }
/* === 新增:分组相关样式 === */
.note-modal-groups { flex: 0 0 auto; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border-soft); }
.group-input-wrapper { display: flex; gap: 6px; margin-bottom: 8px; }
.group-input-wrapper input { flex: 1; height: 28px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--input-bg); color: var(--text-main); font-size: 12px; }
.group-input-wrapper input:focus { border-color: var(--accent); outline: none; }
.note-group-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.group-tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 600; border-radius: 999px; }
.group-tag .remove-tag { cursor: pointer; opacity: 0.6; }
.group-tag .remove-tag:hover { opacity: 1; color: var(--danger); }
.note-group-relations { font-size: 11px; color: var(--text-muted); max-height: 80px; overflow-y: auto; }
.relation-link { color: var(--accent); cursor: pointer; text-decoration: underline; margin-right: 8px; display: inline-block; }
.group-folder { margin-bottom: 8px; border: 1px solid var(--border-soft); border-radius: 8px; background: var(--surface); overflow: hidden; }
.group-folder-header { padding: 8px 10px; background: var(--surface-2); font-weight: 700; font-size: 12px; color: var(--text-main); cursor: pointer; display: flex; justify-content: space-between; }
.group-folder-header:hover { background: var(--btn-hover); }
.group-folder-content { padding: 6px; display: none; }
.group-folder.open .group-folder-content { display: block; }
.group-item-mini { padding: 6px; border-radius: 6px; cursor: pointer; font-size: 11px; margin-bottom: 4px; border: 1px solid transparent; }
.group-item-mini:hover { background: var(--sidebar-hover); border-color: var(--border-soft); }
.note-chip-group { font-size: 10px; padding: 1px 6px; background: var(--border-soft); border-radius: 4px; margin-right: 4px; color: var(--text-muted); }
@media (max-width: 900px) {
.brand { min-width:100%; flex-direction:row; align-items:baseline; gap:8px; }
.toolbar { gap:8px; }
.toolbar-group { max-width:100%; }
#viewer-container { padding:8px; gap:8px; }
.panel-sidebar { width:220px; flex-basis:220px; }
}
</style>
</head>
<body class="theme-normal">
<div class="toolbar">
<input type="file" id="fileInput" multiple accept="application/pdf,.pdf" style="display:none">
<input type="file" id="projectFileInput" accept=".prproj,.readerproj,.json,application/json" style="display:none">
<div class="brand" aria-label="应用名称">
<div class="brand-title">Parallel Reader</div>
<div class="brand-subtitle">极简同步阅读 · 项目 + 批注</div>
</div>
<div class="toolbar-group">
<button id="btnAddFile" class="btn-primary">打开 PDF</button>
<button id="btnLoad" class="btn-primary">开始阅读</button>
<button id="btnClear" class="btn-danger" title="清空当前工作区">清空</button>
</div>
<span id="fileListHint"></span>
<span id="memoryHint"></span>
<div class="toolbar-group" id="persistGroup">
<details class="toolbar-menu">
<summary>项目</summary>
<div class="toolbar-popover">
<span id="projectStatus" class="project-status" title="当前项目保存状态">项目:临时</span>
<label class="toggle-label" title="开启后,锚点、缩放和阅读进度会自动保存到当前项目"><input id="chkAutoSave" type="checkbox" checked>自动保存</label>
<label class="toggle-label" title="开启后,保存项目文件时会把 PDF 副本也写入项目文件;关闭则只保存文件名、锚点和进度"><input id="chkSavePdfCopy" type="checkbox" checked>保存 PDF</label>
<div class="menu-row"><button id="btnSaveProject" title="把当前打开的 PDF、锚点和阅读进度保存到浏览器暂存区">保存暂存</button><button id="btnRestorePersist" title="打开浏览器本地暂存的项目">打开暂存</button></div>
<div class="menu-row"><button id="btnExportProject" title="弹出另存为窗口,手动选择 .readerproj 项目文件保存位置;不支持时自动回退为浏览器下载">导出项目</button><button id="btnImportProject" title="从 .prproj / .readerproj 项目文件恢复文档、锚点和阅读进度">导入项目</button></div>
<div class="menu-row"><button id="btnTempMode" title="切换为临时阅读,不再自动写入项目数据库">临时模式</button><button id="btnClearPersist" class="btn-danger" title="删除浏览器本地暂存的项目数据">删除项目</button></div>
</div>
</details>
</div>
<div class="toolbar-group">
<button id="btnToggleSync" class="btn-active">同步开启</button>
<button id="btnAnchor" title="记录当前各文档页码错位关系">锁定锚点</button>
</div>
<div class="toolbar-group quick-nav" aria-label="视图快捷操作">
<button id="btnResetView" class="icon-btn" title="重置缩放和同步锚点,并回到顶部">↺</button>
<button id="btnHistoryBack" class="icon-btn" disabled title="后退:Alt + ←">←</button>
<button id="btnHistoryForward" class="icon-btn" disabled title="前进:Alt + →">→</button>
</div>
<div class="toolbar-group" title="对当前活跃文档进行批注">
<span class="compact-label">高亮</span>
<div id="highlightPalette" class="color-palette" role="group" aria-label="高亮颜色">
<button class="color-swatch active" data-color="yellow" type="button" title="黄色高亮"></button>
<button class="color-swatch" data-color="green" type="button" title="绿色高亮"></button>
<button class="color-swatch" data-color="blue" type="button" title="蓝色高亮"></button>
<button class="color-swatch" data-color="pink" type="button" title="粉色高亮"></button>
<button class="color-swatch" data-color="purple" type="button" title="紫色高亮"></button>
</div>
<button id="btnHighlight" title="先选中文本,再点击这里添加当前颜色的高亮和笔记">标记</button>
<details class="toolbar-menu">
<summary>批注</summary>
<div class="toolbar-popover">
<button id="btnPageNote" title="给当前页添加或编辑页面便签">页面便签</button>
<button id="btnShowNotes" title="打开当前文档的批注列表并可搜索笔记">批注列表</button>
<div class="menu-label">提示:先选择高亮颜色,再选中文本点击“标记”。</div>
</div>
</details>
</div>
<details class="toolbar-menu">
<summary>视图</summary>
<div class="toolbar-popover right">
<div class="menu-row">
<span class="menu-label">全局缩放</span>
<div class="zoom-group" title="全局缩放">
<button id="btnGlobalZoomOut" class="mini-btn">−</button>
<input id="globalZoomInput" class="data-input" type="number" value="90" min="30" max="300" title="全局缩放,回车生效">
<span style="font-size:11px;color:var(--text-muted)">%</span>
<button id="btnGlobalZoomIn" class="mini-btn">+</button>
</div>
</div>
<div class="menu-row">
<span class="menu-label">单文档宽度</span>
<div class="zoom-group" title="只有打开 1 个 PDF 时生效">
<button id="btnSingleWidthDown" class="mini-btn">−</button>
<input id="singleWidthInput" class="data-input" type="number" value="92" min="45" max="100" title="单文档面板宽度,回车生效">
<span style="font-size:11px;color:var(--text-muted)">%</span>
<button id="btnSingleWidthUp" class="mini-btn">+</button>
</div>
</div>
<div class="menu-row">
<span class="menu-label">单文档位置</span>
<select id="singleAlignSelect" title="只有打开 1 个 PDF 时生效"><option value="flex-start">靠左</option><option value="center" selected>居中</option><option value="flex-end">靠右</option></select>
</div>
<div class="menu-row">
<button id="btnResetLayout" title="重置单文档宽度、位置和多文档占比">重置布局</button>
</div>
<div class="menu-row">
<span class="menu-label">主题</span>
<select id="themeSelect" title="主题"><option value="normal">清新白</option><option value="dark">深色</option><option value="green">豆沙绿</option><option value="sepia">米色纸</option><option value="gray">柔和灰</option></select>
</div>
</div>
</details>
<span id="memoryStats" title="当前已保留的渲染页数;性能版默认降低预渲染并延后文本层"></span>
</div>
<div id="viewer-container">
<div class="empty-state">
<div class="empty-mark">PDF</div>
<div class="empty-title">选择文档开始阅读</div>
<div class="empty-desc">支持 1–4 个 PDF 并排阅读、错位锚点同步、项目文件导入导出、目录检索、页面便签、文本高亮和笔记搜索。</div>
</div>
</div>
<div id="toast" class="toast"></div>
<div id="noteModalBackdrop" class="note-modal-backdrop" role="dialog" aria-modal="true" aria-labelledby="noteModalTitle">
<div class="note-modal">
<div class="note-modal-header">
<div id="noteModalTitle" class="note-modal-title">编辑笔记</div>
<button id="noteModalClose" class="note-modal-close" type="button" aria-label="关闭">×</button>
</div>
<div class="note-modal-body">
<div id="noteModalHint" class="note-modal-hint"></div>
<textarea id="noteModalText" class="note-modal-text" placeholder="输入笔记内容..."></textarea>
<div id="noteModalSplit" class="note-modal-splitter" title="拖拽调整输入区和预览区高度"></div>
<div id="noteModalPreview" class="note-modal-preview markdown-body"></div>
<div class="note-modal-groups">
<div class="group-input-wrapper">
<input type="text" id="noteGroupInput" placeholder="输入组名并回车添加,或从已有组选择..." list="existingGroupsList">
<datalist id="existingGroupsList"></datalist>
<button type="button" id="btnAddGroup" class="mini-btn">加入组</button>
</div>
<div id="noteGroupTags" class="note-group-tags"></div>
<div id="noteGroupRelations" class="note-group-relations"></div>
</div>
</div>
<div class="note-modal-footer">
<div class="left"><button id="noteModalDelete" class="danger" type="button">删除</button></div>
<div class="right"><button id="noteModalCancel" type="button">取消</button><button id="noteModalSave" class="primary" type="button">保存</button></div>
</div>
</div>
</div>
<script>
(() => {
'use strict';
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js';
const MAX_DOCS = 4;
const DEFAULT_ZOOM = 0.90;
const MIN_ZOOM = 0.30;
const MAX_ZOOM = 3.00;
const PREFETCH_PAGES = 1;
const KEEP_DISTANCE = 3;
const MAX_RENDERED_PAGES_PER_DOC = 6;
const HI_DPI_MAX_SCALE = 2;
const MAX_CANVAS_PIXELS = 18_000_000;
const ZOOM_RERENDER_IDLE_MS = 260;
const SYNC_ANCHOR_RATIO = 0.18;
const BOUNDARY_SYNC_SWITCH_RATIO = 0.50;
const BOUNDARY_BLEND_START = 0.34;
const BOUNDARY_BLEND_END = 0.66;
const SCROLL_RENDER_IDLE_FAST_MS = 460;
const SCROLL_RENDER_IDLE_NORMAL_MS = 95;
const FAST_SCROLL_PX_PER_MS = 1.4;
const FAST_SCROLL_VIEWPORT_FACTOR = 0.70;
const RENDER_STALE_DISTANCE = 1;
const DETAILS_LAYER_IDLE_MS = 420;
const WORKSPACE_KEY = 'parallel_pdf_reader_anchor_workspace_v1';
const PERSIST_DB_NAME = 'parallel_pdf_reader_persistent_db_v1';
const PERSIST_DB_VERSION = 1;
const PERSIST_FILES_STORE = 'files';
const PERSIST_META_STORE = 'meta';
const PERSIST_META_KEY = 'workspace';
const els = {
fileInput: document.getElementById('fileInput'),
projectFileInput: document.getElementById('projectFileInput'),
btnAddFile: document.getElementById('btnAddFile'),
btnClear: document.getElementById('btnClear'),
btnLoad: document.getElementById('btnLoad'),
btnToggleSync: document.getElementById('btnToggleSync'),
btnAnchor: document.getElementById('btnAnchor'),
btnPageNote: document.getElementById('btnPageNote'),
btnHighlight: document.getElementById('btnHighlight'),
btnShowNotes: document.getElementById('btnShowNotes'),
btnResetView: document.getElementById('btnResetView'),
btnHistoryBack: document.getElementById('btnHistoryBack'),
btnHistoryForward: document.getElementById('btnHistoryForward'),
btnGlobalZoomOut: document.getElementById('btnGlobalZoomOut'),
btnGlobalZoomIn: document.getElementById('btnGlobalZoomIn'),
globalZoomInput: document.getElementById('globalZoomInput'),
btnSingleWidthDown: document.getElementById('btnSingleWidthDown'),
btnSingleWidthUp: document.getElementById('btnSingleWidthUp'),
singleWidthInput: document.getElementById('singleWidthInput'),
singleAlignSelect: document.getElementById('singleAlignSelect'),
btnResetLayout: document.getElementById('btnResetLayout'),
themeSelect: document.getElementById('themeSelect'),
fileListHint: document.getElementById('fileListHint'),
memoryHint: document.getElementById('memoryHint'),
persistGroup: document.getElementById('persistGroup'),
projectStatus: document.getElementById('projectStatus'),
chkAutoSave: document.getElementById('chkAutoSave'),
chkSavePdfCopy: document.getElementById('chkSavePdfCopy'),
btnSaveProject: document.getElementById('btnSaveProject'),
btnExportProject: document.getElementById('btnExportProject'),
btnImportProject: document.getElementById('btnImportProject'),
btnRestorePersist: document.getElementById('btnRestorePersist'),
btnTempMode: document.getElementById('btnTempMode'),
btnClearPersist: document.getElementById('btnClearPersist'),
memoryStats: document.getElementById('memoryStats'),
container: document.getElementById('viewer-container'),
toast: document.getElementById('toast'),
noteModalBackdrop: document.getElementById('noteModalBackdrop'),
noteModalTitle: document.getElementById('noteModalTitle'),
noteModalHint: document.getElementById('noteModalHint'),
noteModalText: document.getElementById('noteModalText'),
noteModalPreview: document.getElementById('noteModalPreview'),
noteModalClose: document.getElementById('noteModalClose'),
noteModalSave: document.getElementById('noteModalSave'),
noteModalCancel: document.getElementById('noteModalCancel'),
noteModalDelete: document.getElementById('noteModalDelete'),
highlightColorSwatches: Array.from(document.querySelectorAll('#highlightPalette .color-swatch'))
};
const app = {
files: [],
docs: [],
anchors: [],
syncEnabled: true,
syncing: false,
userActiveDocId: null,
suppressHistory: false,
saveTimer: 0,
persistTimer: 0,
historyTimer: 0,
navHistory: [],
navIndex: -1,
resizeTimer: 0,
renderSeq: 0,
savedWorkspace: null,
hasPersistentWorkspace: false,
isPersisting: false,
projectActive: false,
autoSaveProject: true,
savePdfCopy: true,
highlightColor: 'yellow',
singleDocWidth: 92,
singleDocAlign: 'center',
notes: []
};
function uid() {
return `doc_${Date.now()}_${Math.random().toString(16).slice(2)}`;
}
function clamp(n, min, max) {
return Math.max(min, Math.min(max, n));
}
function smoothstep(edge0, edge1, x) {
const t = clamp((x - edge0) / Math.max(0.0001, edge1 - edge0), 0, 1);
return t * t * (3 - 2 * t);
}
function escapeHtml(s) {
return String(s).replace(/[&<>'"]/g, c => ({ '&':'&', '<':'<', '>':'>', "'":''', '"':'"' }[c]));
}
function escapeRegExp(s) {
return String(s).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
function findSearchMatchInfo(textItems, matchIdx, queryLength, viewport) {
let offset = 0;
for (let itemIndex = 0; itemIndex < textItems.length; itemIndex++) {
const item = textItems[itemIndex];
const str = String(item.str || '');
const start = offset;
const end = start + str.length;
if (matchIdx >= start && matchIdx <= end && str.trim()) {
const localStart = clamp(matchIdx - start, 0, Math.max(0, str.length - 1));
const localLen = Math.max(1, Math.min(queryLength, Math.max(1, str.length - localStart)));
try {
const tx = pdfjsLib.Util.transform(viewport.transform, item.transform);
const itemWidth = Math.max(1, Number(item.width || 0));
const itemHeight = Math.max(6, Number(item.height || 12));
const x = tx[4] + itemWidth * (localStart / Math.max(1, str.length));
const y = tx[5] - itemHeight;
const w = Math.max(8, itemWidth * (localLen / Math.max(1, str.length)));
const h = itemHeight * 1.32;
const rect = {
x: clamp(x / Math.max(1, viewport.width), 0, 0.999),
y: clamp(y / Math.max(1, viewport.height), 0, 0.999),
w: clamp(w / Math.max(1, viewport.width), 0.006, 1),
h: clamp(h / Math.max(1, viewport.height), 0.006, 1)
};
return {
pagePct: clamp((rect.y + rect.h / 2), 0, 0.999),
rect,
itemIndex,
localStart,
localLen,
itemTextLength: Math.max(1, str.length)
};
} catch (_) {
return { pagePct: null, rect: null, itemIndex, localStart, localLen, itemTextLength: Math.max(1, str.length) };
}
}
offset += str.length + 1;
}
return { pagePct: null, rect: null, itemIndex: -1, localStart: 0, localLen: 0, itemTextLength: 1 };
}
function scrollDocToSearchMatch(doc, pageIndex, matchInfo = {}, syncAfter = false) {
const idx = clamp(pageIndex, 0, Math.max(0, doc.pages.length - 1));
const el = doc.pages[idx]?.el;
if (!el) return;
const pendingHit = {
pageIndex: idx,
rect: matchInfo.rect || null,
pagePct: matchInfo.pagePct ?? 0.5,
itemIndex: Number.isFinite(matchInfo.itemIndex) ? matchInfo.itemIndex : -1,
localStart: matchInfo.localStart || 0,
localLen: matchInfo.localLen || 0,
itemTextLength: matchInfo.itemTextLength || 1,
createdAt: Date.now(),
recentered: false
};
const exactRect = getExactSearchRectFromTextLayer(doc, idx, pendingHit);
if (exactRect) pendingHit.rect = exactRect;
const rect = pendingHit.rect || null;
const pagePct = pendingHit.pagePct ?? 0.5;
const yInPage = rect
? (rect.y + rect.h / 2) * el.offsetHeight
: clamp(pagePct, 0, 0.999) * el.offsetHeight;
const targetY = el.offsetTop + yInPage - doc.scroller.clientHeight / 2;
doc.scroller.scrollTo({ top: Math.max(0, targetY), behavior: 'smooth' });
updateIndicator(doc);
doc.searchHit = pendingHit;
scheduleRenderAround(doc);
renderSearchHitForPage(doc, idx);
clearTimeout(doc.searchHitTimer);
doc.searchHitTimer = setTimeout(() => {
if (doc.searchHit?.pageIndex === idx) doc.searchHit = null;
doc.pages[idx]?.el?.querySelector('.search-hit-layer')?.remove();
}, 9000);
scheduleWorkspaceSave();
if (syncAfter) {
setTimeout(() => performSync(doc), 120);
}
}
function getExactSearchRectFromTextLayer(doc, pageIndex, hit) {
const pageState = doc.pages[pageIndex];
const content = pageState?.el?.querySelector('.page-content');
const textDivs = pageState?.textDivs;
if (!content || !textDivs || hit.itemIndex < 0 || !textDivs[hit.itemIndex]) return null;
const div = textDivs[hit.itemIndex];
const contentBox = content.getBoundingClientRect();
const box = div.getBoundingClientRect();
if (!contentBox.width || !contentBox.height || !box.width || !box.height) return null;
const startRatio = clamp(hit.localStart / Math.max(1, hit.itemTextLength), 0, 0.98);
const lenRatio = clamp(hit.localLen / Math.max(1, hit.itemTextLength), 0.02, 1);
const xPx = (box.left - contentBox.left) + box.width * startRatio;
const yPx = box.top - contentBox.top;
const wPx = Math.max(8, box.width * lenRatio);
const hPx = Math.max(8, box.height);
return {
x: clamp(xPx / contentBox.width, 0, 0.999),
y: clamp(yPx / contentBox.height, 0, 0.999),
w: clamp(wPx / contentBox.width, 0.006, 1),
h: clamp(hPx / contentBox.height, 0.006, 1)
};
}
function recenterSearchHit(doc, pageIndex, rect) {
const hit = doc.searchHit;
if (!hit || hit.pageIndex !== pageIndex || hit.recentered) return;
if (Date.now() - hit.createdAt > 3500) return;
const el = doc.pages[pageIndex]?.el;
if (!el) return;
const yInPage = (rect.y + rect.h / 2) * el.offsetHeight;
const targetY = Math.max(0, el.offsetTop + yInPage - doc.scroller.clientHeight / 2);
if (Math.abs(doc.scroller.scrollTop - targetY) > 18) {
doc.scroller.scrollTo({ top: targetY, behavior: 'smooth' });
}
hit.recentered = true;
}
function centerSearchHitElement(doc, element, hit) {
if (!doc || !element || !hit) return;
if (hit.centeredAt && Date.now() - hit.centeredAt < 800) return;
requestAnimationFrame(() => {
try {
element.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' });
hit.centeredAt = Date.now();
} catch (_) {
const pageState = doc.pages[hit.pageIndex];
const el = pageState?.el;
if (!el) return;
const r = hit.rect || { y: hit.pagePct ?? 0.5, h: 0.02 };
const yInPage = (r.y + r.h / 2) * el.offsetHeight;
doc.scroller.scrollTo({ top: Math.max(0, el.offsetTop + yInPage - doc.scroller.clientHeight / 2), behavior: 'smooth' });
hit.centeredAt = Date.now();
}
});
}
function renderSearchHitForPage(doc, pageIndex) {
const hit = doc.searchHit;
const pageState = doc.pages[pageIndex];
if (!hit || hit.pageIndex !== pageIndex || !pageState?.loaded) return;
const content = pageState.el.querySelector('.page-content');
if (!content) return;
content.querySelector('.search-hit-layer')?.remove();
const exactRect = getExactSearchRectFromTextLayer(doc, pageIndex, hit);
const r = exactRect || hit.rect || { x: 0.12, y: 0.45, w: 0.76, h: 0.055 };
if (exactRect) {
hit.rect = exactRect;
}
const layer = document.createElement('div');
layer.className = 'search-hit-layer';
const div = document.createElement('div');
div.className = 'search-hit';
div.style.left = `${r.x * 100}%`;
div.style.top = `${r.y * 100}%`;
div.style.width = `${Math.max(0.02, r.w) * 100}%`;
div.style.height = `${Math.max(0.012, r.h) * 100}%`;
layer.appendChild(div);
content.appendChild(layer);
if (hit.shouldCenter !== false) {
centerSearchHitElement(doc, div, hit);
}
}
function renderLatex(src, displayMode = false) {
const latex = String(src || '').trim();
if (!latex) return '';
if (window.katex?.renderToString) {
try {
return window.katex.renderToString(latex, {
displayMode,
throwOnError: false,
strict: 'ignore',
trust: false,
output: 'html'
});
} catch (err) {
return `<span class="math-error">${escapeHtml(latex)}</span>`;
}
}
return `<span class="math-error">${escapeHtml(displayMode ? `$$${latex}$$` : `$${latex}$`)}</span>`;
}
function renderInlineText(raw) {
let s = escapeHtml(raw || '');
s = s.replace(/`([^`]+)`/g, '<code>$1</code>');
s = s.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
s = s.replace(/__([^_]+)__/g, '<strong>$1</strong>');
s = s.replace(/(?<!\*)\*([^*\n]+)\*(?!\*)/g, '<em>$1</em>');
s = s.replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>');
return s;
}
function renderMarkdownInline(raw) {
const input = String(raw || '');
const out = [];
let i = 0;
let buffer = '';
const flush = () => {
if (buffer) {
out.push(renderInlineText(buffer));
buffer = '';
}
};
while (i < input.length) {
if (input.startsWith('\\(', i)) {
const end = input.indexOf('\\)', i + 2);
if (end !== -1) {
flush();
out.push(renderLatex(input.slice(i + 2, end), false));
i = end + 2;
continue;
}
}
if (input[i] === '$' && input[i + 1] !== '$') {
const end = input.indexOf('$', i + 1);
if (end !== -1) {
const expr = input.slice(i + 1, end);
if (expr.trim()) {
flush();
out.push(renderLatex(expr, false));
i = end + 1;
continue;
}
}
}
buffer += input[i];
i++;
}
flush();
return out.join('');
}
function renderMarkdown(raw) {
const text = String(raw || '').replace(/\r\n/g, '\n').trim();
if (!text) return '';
const lines = text.split('\n');
const out = [];
let inCode = false;
let code = [];
let list = null;
let inMath = false;
let math = [];
const closeList = () => {
if (list) {
out.push(`<${list.type}>${list.items.map(item => `<li>${renderMarkdownInline(item)}</li>`).join('')}</${list.type}>`);
list = null;
}
};
const closeCode = () => {
if (inCode) {
out.push(`<pre><code>${escapeHtml(code.join('\n'))}</code></pre>`);
code = [];
inCode = false;
}
};
const closeMath = () => {
if (inMath) {
out.push(renderLatex(math.join('\n'), true));
math = [];
inMath = false;
}
};
for (const line of lines) {
const trimmed = line.trim();
if (/^\s*```/.test(line)) {
if (inMath) { math.push(line); continue; }
if (inCode) closeCode();
else { closeList(); inCode = true; code = []; }
continue;
}
if (inCode) { code.push(line); continue; }
if (trimmed === '$$' || trimmed === '\\[' || trimmed === '\\]') {
closeList();
if (inMath) closeMath();
else { inMath = true; math = []; }
continue;
}
if (trimmed.startsWith('$$') && trimmed.endsWith('$$') && trimmed.length > 4) {
closeList();
out.push(renderLatex(trimmed.slice(2, -2), true));
continue;
}
if (trimmed.startsWith('\\[') && trimmed.endsWith('\\]') && trimmed.length > 4) {
closeList();
out.push(renderLatex(trimmed.slice(2, -2), true));
continue;
}
if (inMath) {
math.push(line);
continue;
}
if (!trimmed) {
closeList();
continue;
}
const heading = /^(#{1,4})\s+(.+)$/.exec(line);
if (heading) {
closeList();
const level = Math.min(4, heading[1].length);
out.push(`<h${level}>${renderMarkdownInline(heading[2])}</h${level}>`);
continue;
}
const quote = /^>\s?(.+)$/.exec(line);
if (quote) {
closeList();
out.push(`<blockquote>${renderMarkdownInline(quote[1])}</blockquote>`);
continue;
}
const ul = /^[-*]\s+(.+)$/.exec(line);
const ol = /^\d+\.\s+(.+)$/.exec(line);
if (ul || ol) {
const type = ul ? 'ul' : 'ol';
if (!list || list.type !== type) {
closeList();
list = { type, items: [] };
}
list.items.push((ul || ol)[1]);
continue;
}
closeList();
out.push(`<p>${renderMarkdownInline(line)}</p>`);
}
closeMath();
closeCode();
closeList();
return out.join('');