-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
2516 lines (2317 loc) · 153 KB
/
index.html
File metadata and controls
2516 lines (2317 loc) · 153 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 dir="rtl" lang="he">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>מערכת השוואת מדרשים וגניזת קהיר</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Assistant:wght@300;400;600;700&family=Suez+One&display=swap" rel="stylesheet">
<style>
body { font-family: 'Assistant', sans-serif; background-color: #f1f5f9; }
.serif-heb { font-family: 'Suez One', serif; line-height: 1.8; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.text-view { max-height: 38vh; overflow-y: auto; scrollbar-width: thin; }
.highlight-src { background-color: #dcfce7; font-weight: 600; color: #166534; padding: 0 4px; border-radius: 4px; border-bottom: 2px solid #86efac; }
.highlight-tgt { background-color: #fee2e2; font-weight: 600; color: #991b1b; padding: 0 4px; border-radius: 4px; border-bottom: 2px solid #fca5a5; }
/* Dual Range Slider */
.range-slider { position: relative; width: 180px; height: 24px; }
.range-slider input[type="range"] { position: absolute; width: 100%; height: 100%; top: 0; left: 0; pointer-events: none; -webkit-appearance: none; background: none; z-index: 2; margin: 0; }
.range-slider input[type="range"]::-webkit-slider-thumb { pointer-events: auto; width: 16px; height: 16px; border-radius: 50%; background: #2563eb; cursor: pointer; -webkit-appearance: none; box-shadow: 0 1px 3px rgba(0,0,0,0.3); border: 2px solid white; }
.range-track { position: absolute; top: 10px; height: 4px; width: 100%; background: #cbd5e1; border-radius: 2px; z-index: 1; }
.range-fill { position: absolute; top: 10px; height: 4px; background: #3b82f6; border-radius: 2px; z-index: 1; }
/* Skyline */
.skyline-container { display: flex; align-items: flex-end; gap: 1px; overflow-x: auto; overflow-y: hidden; height: 280px; padding: 20px 20px 0 20px; background: linear-gradient(to bottom, #1e293b, #0f172a); border-radius: 16px; box-shadow: inset 0 4px 20px rgba(0,0,0,0.5); }
.skyline-bar { background-color: #334155; transition: all 0.3s ease; cursor: pointer; border-top-left-radius: 2px; border-top-right-radius: 2px; position: relative; }
.skyline-bar:hover { filter: brightness(1.5); box-shadow: 0 0 10px rgba(255,255,255,0.2); z-index: 10; }
.skyline-bar.active-bar { background-color: #3b82f6 !important; box-shadow: 0 0 15px #3b82f6; }
.dr-tooltip { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.85); color: white; padding: 4px 8px; border-radius: 4px; font-size: 10px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity 0.2s; margin-bottom: 8px; font-family: monospace; }
.skyline-bar:hover .dr-tooltip { opacity: 1; }
/* Metadata panel */
.meta-label { font-size: 10px; font-weight: 700; text-transform: uppercase; color: #0f766e; letter-spacing: 0.05em; display: block; margin-bottom: 2px; }
.meta-panel { background: linear-gradient(135deg, #f0fdfa, #ecfeff); border-top: 1px solid #99f6e4; }
/* Search tab */
.search-card { background: white; border: 1px solid #e2e8f0; border-radius: 12px; transition: all 0.2s; }
.search-card:hover { border-color: #93c5fd; box-shadow: 0 4px 12px rgba(59,130,246,0.1); }
.match-border-has { border-right: 4px solid #10b981; }
.match-border-none { border-right: 4px solid #cbd5e1; }
.stat-bar { height: 8px; background: #f1f5f9; border-radius: 9999px; overflow: hidden; }
.stat-bar-fill { height: 100%; border-radius: 9999px; transition: width 0.6s ease; }
/* Tabs within left column */
.inner-tab-active { background: white; color: #92400e; font-weight: 700; border-bottom: 2px solid #f59e0b; }
.inner-tab-inactive { background: transparent; color: #78716c; border-bottom: 2px solid transparent; }
/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 4px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
/* Distant Reading sub-tabs */
.dr-nav-tab { padding: 12px 20px; font-weight: 700; font-size: 13px; cursor: pointer; border-bottom: 3px solid transparent; transition: all 0.2s; color: #94a3b8; }
.dr-nav-tab:hover { background: rgba(255,255,255,0.05); }
.dr-nav-tab.dr-active { border-bottom-color: #3b82f6; color: #93c5fd; background: rgba(59,130,246,0.08); }
/* DR Cards */
.dr-frag-card { background: #1e293b; border: 1px solid #334155; border-radius: 12px; transition: all 0.2s; }
.dr-frag-card:hover { border-color: #3b82f6; box-shadow: 0 4px 16px rgba(59,130,246,0.15); }
.dr-meta-tag { display: inline-block; background: #334155; color: #94a3b8; font-size: 11px; padding: 2px 8px; border-radius: 9999px; margin: 2px; }
.dr-meta-tag-active { background: #1e40af; color: #93c5fd; }
/* DR Chips */
.dr-chip { display: inline-flex; align-items: center; gap: 4px; background: #334155; color: #cbd5e1; font-size: 12px; padding: 4px 12px; border-radius: 9999px; cursor: pointer; transition: all 0.15s; border: 1px solid transparent; }
.dr-chip:hover { border-color: #64748b; }
.dr-chip.selected { background: #1e40af; color: white; border-color: #3b82f6; }
/* DR Stat bars */
.dr-stat-bar { height: 6px; background: #1e293b; border-radius: 9999px; overflow: hidden; }
.dr-stat-fill { height: 100%; border-radius: 9999px; transition: width 0.5s ease; }
/* DR Mini skyline */
.dr-mini-skyline { display: flex; align-items: flex-end; gap: 1px; height: 40px; }
.dr-mini-bar { min-width: 3px; border-radius: 1px 1px 0 0; transition: all 0.2s; }
</style>
</head>
<body class="h-screen flex flex-col overflow-hidden text-slate-800">
<!-- ═══════════════ HEADER ═══════════════ -->
<header class="bg-slate-900 text-white p-3 shadow-xl flex justify-between items-center z-50 flex-wrap gap-2">
<div class="flex items-center gap-3">
<div class="bg-blue-600 p-2.5 rounded-xl shadow-inner flex-shrink-0">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253" />
</svg>
</div>
<div>
<h1 class="text-lg font-bold tracking-tight" id="mainTitle">מערכת השוואת מדרשים — גניזת קהיר</h1>
<p class="text-[10px] text-blue-300 font-bold uppercase tracking-widest">גרסה 3.0 | טעינה מרובת-ספרים · מדדי דמיון · חיפוש מתקדם</p>
</div>
</div>
<div class="flex gap-3 items-center flex-wrap">
<!-- Score Slider -->
<div class="flex flex-col bg-slate-800 px-3 py-2 rounded-xl border border-slate-700">
<div class="flex justify-between items-center mb-1">
<span class="text-[10px] text-slate-400 font-bold uppercase">סינון ציון:</span>
<span id="rangeLabel" class="text-[10px] text-blue-400 font-mono font-bold">0.00 – 1.00</span>
</div>
<div class="range-slider">
<div class="range-track"></div>
<div class="range-fill" id="sliderFill"></div>
<input type="range" id="minScore" min="0" max="1" step="any" value="0">
<input type="range" id="maxScore" min="0" max="1" step="any" value="1">
</div>
</div>
<div class="w-px h-10 bg-slate-700"></div>
<!-- Dataset Tabs -->
<div id="datasetTabs" class="hidden flex gap-1 bg-slate-800 p-1 rounded-xl border border-slate-700 max-w-xs overflow-x-auto flex-shrink-0"></div>
<!-- Open Directory / Load Files -->
<div class="flex flex-row items-center gap-2">
<button onclick="openDirectory()" class="bg-blue-600 hover:bg-blue-500 px-4 py-2 rounded-lg text-xs font-bold shadow-md flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" class="h-3.5 w-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" /></svg>
פתח תיקיה
</button>
<input type="file" id="multiFileInput" accept=".json" multiple class="hidden">
</div>
<!-- Enriched JSON (metadata) -->
<div class="flex flex-col gap-1">
<button onclick="document.getElementById('enrichedJsonInput').click()" class="bg-teal-600 hover:bg-teal-500 px-4 py-2 rounded-lg text-xs transition-all font-bold shadow-md flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" class="h-3.5 w-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" /></svg>
מטה-דאטה גניזה
</button>
<span id="enrichedJsonStatus" class="text-[10px] text-center px-2 py-0.5 rounded-full bg-slate-700 text-slate-400 font-bold">לא נטען</span>
</div>
<input type="file" id="enrichedJsonInput" accept=".json" class="hidden">
<!-- Metric Selector -->
<div class="flex flex-col bg-slate-800 px-3 py-2 rounded-xl border border-slate-700 flex-shrink-0">
<span class="text-[10px] text-slate-400 font-bold uppercase mb-1">מדד דמיון:</span>
<div class="flex gap-1">
<button onclick="setActiveMetric('alignment_score')" id="metricBtn-alignment_score" class="px-2 py-1 rounded text-[10px] font-bold bg-blue-600 text-white">יישור</button>
<button onclick="setActiveMetric('norm_score')" id="metricBtn-norm_score" class="px-2 py-1 rounded text-[10px] font-bold bg-slate-700 text-slate-300 hover:bg-slate-600">מנורמל</button>
<button onclick="setActiveMetric('score')" id="metricBtn-score" class="px-2 py-1 rounded text-[10px] font-bold bg-slate-700 text-slate-300 hover:bg-slate-600">גלם</button>
</div>
</div>
</div>
</header>
<!-- ═══════════════ NAV TABS ═══════════════ -->
<nav class="bg-white border-b border-slate-200 flex shadow-sm z-30 px-4">
<button onclick="switchView('units')" id="nav-units" class="px-6 py-3.5 font-bold text-sm transition-all border-b-4 border-blue-600 text-blue-800 bg-blue-50">השוואת קטעים פרטנית</button>
<button onclick="switchView('fragments')" id="nav-fragments" class="px-6 py-3.5 font-bold text-sm transition-all border-b-4 border-transparent text-slate-600 hover:bg-slate-50">מקבצי גניזה (לפי דפים)</button>
<button onclick="switchView('distant')" id="nav-distant" class="px-6 py-3.5 font-bold text-sm transition-all border-b-4 border-transparent text-indigo-700 flex items-center gap-2 hover:bg-indigo-50">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" /><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" /></svg>
מבט-על (Distant Reading)
</button>
<button onclick="switchView('search')" id="nav-search" class="px-6 py-3.5 font-bold text-sm transition-all border-b-4 border-transparent text-purple-700 flex items-center gap-2 hover:bg-purple-50">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" /></svg>
חיפוש וניתוח ◈
</button>
</nav>
<main class="flex-1 flex overflow-hidden">
<!-- ═══════════════ SIDEBAR ═══════════════ -->
<aside id="sidebar" class="w-72 bg-slate-50 border-l border-slate-200 flex flex-col h-full shadow-[inset_0_0_10px_rgba(0,0,0,0.02)] transition-all z-20 flex-shrink-0">
<div class="p-3 border-b border-slate-200 bg-white">
<div class="relative">
<input type="text" id="sidebarSearch" placeholder="חיפוש קטעים..." class="w-full pr-9 pl-3 py-2.5 bg-slate-100 border border-slate-200 rounded-lg text-sm outline-none focus:ring-2 focus:ring-blue-500 focus:bg-white transition-all">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 absolute right-2.5 top-3 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" /></svg>
</div>
</div>
<div id="sidebarStats" class="text-[10px] text-slate-500 font-bold py-1 px-3 bg-slate-100 border-b border-slate-200 text-center uppercase tracking-wider">מציג 0 קטעים</div>
<div id="sidebarList" class="flex-1 overflow-y-auto p-2 relative">
<div class="text-center text-slate-400 mt-10 p-5 border-2 border-dashed border-slate-200 rounded-xl">
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 mx-auto text-slate-300 mb-2" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7v8a2 2 0 002 2h6M8 7V5a2 2 0 012-2h4.586a1 1 0 01.707.293l4.414 4.414a1 1 0 01.293.707V15a2 2 0 01-2 2h-2M8 7H6a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2v-2" /></svg>
<p class="text-sm font-bold">טען קובץ נתונים</p>
</div>
</div>
</aside>
<!-- ═══════════════ CONTENT AREA ═══════════════ -->
<section id="contentArea" class="flex-1 flex flex-col bg-slate-100 overflow-hidden opacity-30 pointer-events-none transition-opacity duration-500 relative">
<!-- ── VIEW 1: UNITS ── -->
<div id="view-units" class="flex-1 flex flex-col overflow-hidden absolute inset-0">
<div class="flex-1 grid grid-cols-1 lg:grid-cols-2 gap-px bg-slate-300">
<!-- RIGHT: Sefer HaBahir (source) -->
<div class="bg-white flex flex-col overflow-hidden">
<div class="p-5 bg-blue-50/80 border-b border-blue-100 flex flex-col justify-center min-h-[96px]">
<div class="flex justify-between items-start">
<div class="flex flex-col items-start gap-1.5">
<div class="flex items-center gap-2">
<span id="sourceBookLabel" class="px-2 py-0.5 bg-blue-600 text-white text-[10px] rounded font-bold uppercase tracking-widest">ספר מקור</span>
<span id="jobId" class="text-[10px] text-slate-400 font-mono">ID: -</span>
</div>
<h2 id="currentUnitTitle" class="text-sm font-bold text-blue-800 bg-blue-100/50 border border-blue-200 px-3 py-1.5 rounded-lg font-mono tracking-tight">-</h2>
</div>
<a id="sefariaLink" href="#" target="_blank" class="hidden text-xs bg-white border border-slate-200 text-slate-700 hover:bg-slate-50 px-3 py-1.5 rounded-lg font-bold transition-all shadow-sm items-center gap-2">
<svg viewBox="0 0 24 24" class="w-4 h-4" fill="currentColor"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/></svg>
ספריא
</a>
</div>
</div>
<div class="flex-1 p-7 text-xl leading-relaxed text-slate-800 serif-heb text-view whitespace-pre-wrap bg-white" id="sourceText"></div>
</div>
<!-- LEFT: Genizah (target + metadata) -->
<div class="bg-slate-50 flex flex-col overflow-hidden">
<!-- Candidate selector header -->
<div class="p-5 bg-amber-50/80 border-b border-amber-100 flex flex-col justify-center min-h-[96px]">
<div class="flex justify-between items-start mb-3">
<div>
<div class="flex items-center gap-2 mb-1">
<span class="px-2 py-0.5 bg-amber-600 text-white text-[10px] rounded font-bold uppercase tracking-widest">מקבילות מהגניזה</span>
</div>
<h3 class="text-base font-bold text-amber-900 serif-heb">הצעות זיהוי מגניזת קהיר</h3>
</div>
<button id="btnFragmentJump" onclick="navToCurrentFragment()" class="hidden bg-white text-amber-700 hover:bg-amber-600 hover:text-white border border-amber-200 px-3 py-1.5 rounded-lg text-xs font-bold transition-all shadow-sm items-center gap-2">
הצג בהקשר המלא
<svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 5l7 7m0 0l-7 7m7-7H3" /></svg>
</button>
</div>
<div class="flex items-center gap-2">
<span class="text-[10px] font-bold text-slate-500 uppercase flex-shrink-0">בחר מועמד:</span>
<div id="candContainer" class="flex gap-1.5 overflow-x-auto pb-1 flex-1"></div>
</div>
</div>
<!-- Meta bar -->
<div id="targetMeta" class="grid grid-cols-3 gap-3 bg-white px-5 py-3 border-b border-slate-200 text-sm shadow-sm z-10">
<div class="flex flex-col">
<span class="text-[10px] text-slate-400 font-bold uppercase mb-1">מזהה גניזה</span>
<div class="flex items-center gap-1.5">
<span id="metaLoc" class="font-mono text-xs text-blue-600 font-bold break-all leading-none">-</span>
<span id="metaLocCount" class="hidden bg-indigo-100 text-indigo-800 text-[10px] px-1.5 py-0.5 rounded font-bold whitespace-nowrap border border-indigo-200"></span>
</div>
</div>
<div class="flex flex-col"><span id="metaScoreLabel" class="text-[10px] text-slate-400 font-bold uppercase">ציון התאמה</span><span id="metaScore" class="text-lg font-bold text-emerald-600 leading-none">-</span></div>
<div class="flex flex-col"><span class="text-[10px] text-slate-400 font-bold uppercase">סוג זיהוי</span><span id="metaType" class="font-bold text-slate-700 text-xs">-</span></div>
</div>
<!-- Inner tabs: Text | Metadata -->
<div class="flex bg-amber-50/60 border-b border-amber-100">
<button id="innerTab-text" onclick="switchInnerTab('text')" class="px-5 py-2 text-xs font-bold transition-all inner-tab-active">טקסט הגניזה</button>
<button id="innerTab-meta" onclick="switchInnerTab('meta')" class="px-5 py-2 text-xs font-bold transition-all inner-tab-inactive flex items-center gap-1.5">
<svg xmlns="http://www.w3.org/2000/svg" class="h-3.5 w-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" /></svg>
פרטי מטה-דאטה
<span id="metaBadge" class="hidden bg-teal-500 text-white text-[9px] px-1.5 py-0.5 rounded-full font-bold">✓</span>
</button>
</div>
<!-- Genizah text view -->
<div id="innerView-text" class="flex-1 p-7 text-xl leading-relaxed text-slate-800 serif-heb text-view whitespace-pre-wrap bg-slate-50/50"></div>
<!-- Metadata view (hidden by default) -->
<div id="innerView-meta" class="hidden flex-1 overflow-y-auto p-5 meta-panel">
<div id="unitMetaPanel" class="text-sm text-teal-700 italic">טען את קובץ המטה-דאטה לצפייה בפרטים.</div>
</div>
</div>
</div>
</div>
<!-- ── VIEW 2: FRAGMENTS ── -->
<div id="view-fragments" class="hidden flex-1 flex flex-col overflow-hidden absolute inset-0 bg-slate-50">
<div class="bg-white border-b border-slate-200 p-5 shadow-sm flex flex-col gap-3">
<div class="flex justify-between items-end">
<div>
<h2 class="text-xl font-bold text-slate-800 serif-heb">מקבצי גניזה</h2>
<p class="text-xs text-slate-500 mt-0.5">דפי גניזה המכילים מספר מקבילות לספר המקור</p>
</div>
<div id="fragStatsBadge" class="bg-blue-100 text-blue-800 px-4 py-2 rounded-xl text-sm font-bold border border-blue-200">0 דפי גניזה</div>
</div>
<div class="flex flex-wrap gap-3 items-center bg-slate-50 p-3 rounded-xl border border-slate-200">
<div class="flex-1 relative min-w-[260px]">
<input type="text" id="fragSearch" placeholder="חיפוש חופשי (מזהה, כותרת, מוסד...)" class="w-full pl-9 pr-4 py-2 bg-white border border-slate-300 rounded-lg text-sm outline-none focus:ring-2 focus:ring-blue-500 shadow-sm">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 absolute left-2.5 top-2.5 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" /></svg>
</div>
<div id="fragDatasetFilterBar" class="hidden flex gap-1 flex-wrap"></div>
<div class="flex gap-2">
<button onclick="sortFragments('count')" id="sortCountBtn" class="px-4 py-2 bg-slate-800 text-white rounded-lg text-xs font-bold shadow-md">מיין לפי כמות</button>
<button onclick="sortFragments('id')" id="sortIdBtn" class="px-4 py-2 bg-white text-slate-700 border border-slate-300 hover:bg-slate-50 rounded-lg text-xs font-bold shadow-sm">מיון אלפביתי</button>
<button onclick="resetFragments()" class="px-4 py-2 text-red-600 hover:bg-red-50 rounded-lg text-xs font-bold ml-2">נקה סינונים</button>
</div>
</div>
</div>
<div class="flex-1 overflow-y-auto p-6">
<div id="fragmentsList" class="max-w-5xl mx-auto space-y-5"></div>
</div>
</div>
<!-- ── VIEW 3: DISTANT READING (מבט-על) ── -->
<div id="view-distant" class="hidden flex-1 flex flex-col overflow-hidden absolute inset-0 bg-slate-900 text-white">
<!-- Sub navigation -->
<nav class="bg-slate-900/80 border-b border-slate-800 flex px-4 z-30">
<div onclick="dr_switchTab('fragments')" id="dr-tab-fragments" class="dr-nav-tab dr-active">מקבצי גניזה</div>
<div onclick="dr_switchTab('subjects')" id="dr-tab-subjects" class="dr-nav-tab">חיבורים בגניזה</div>
<div onclick="dr_switchTab('metadata')" id="dr-tab-metadata" class="dr-nav-tab">מטה-דאטה</div>
</nav>
<!-- Empty state -->
<div id="dr-emptyState" class="flex-1 flex items-center justify-center">
<div class="text-center p-10 border-2 border-dashed border-slate-700 rounded-2xl max-w-md">
<svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 mx-auto text-slate-600 mb-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" /><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" /></svg>
<p class="text-slate-400 font-bold text-lg mb-2">מבט-על · Distant Reading</p>
<p class="text-slate-500 text-sm mb-4">פתח את תיקיית הנתונים כדי להתחיל</p>
</div>
</div>
<!-- Fragments tab -->
<div id="dr-view-fragments" class="hidden absolute inset-0 flex flex-col overflow-hidden" style="top:49px">
<div class="p-4 border-b border-slate-800 flex flex-wrap gap-3 items-center bg-slate-900/60">
<input type="text" id="dr-fragSearch" placeholder="חיפוש קטע גניזה..." class="flex-1 min-w-[200px] px-4 py-2 bg-slate-800 border border-slate-700 rounded-lg text-sm text-slate-200 outline-none focus:ring-2 focus:ring-blue-500">
<select id="dr-fragBookFilter" onchange="dr_renderFragments()" class="px-3 py-2 bg-slate-800 border border-slate-700 rounded-lg text-xs text-slate-300 outline-none">
<option value="all">כל הספרים</option>
</select>
<select id="dr-fragSort" onchange="dr_renderFragments()" class="px-3 py-2 bg-slate-800 border border-slate-700 rounded-lg text-xs text-slate-300 outline-none">
<option value="count">מיון לפי כמות מקבילות</option>
<option value="score">מיון לפי ציון מקסימלי</option>
<option value="books">מיון לפי מספר ספרים</option>
<option value="id">מיון אלפביתי</option>
</select>
<span id="dr-fragCount" class="text-[10px] text-slate-500 font-bold uppercase">0 קטעים</span>
</div>
<div id="dr-fragList" class="flex-1 overflow-y-auto p-4 space-y-3"></div>
</div>
<!-- Subjects tab -->
<div id="dr-view-subjects" class="hidden absolute inset-0 flex flex-col overflow-hidden" style="top:49px">
<div class="p-4 border-b border-slate-800 bg-slate-900/60">
<p class="text-xs text-slate-400 mb-2">בחר חיבור מהגניזה כדי לראות את הנוכחות שלו בספרי המקור:</p>
<div id="dr-subjectChips" class="flex flex-wrap gap-2 mb-3"></div>
<div class="flex gap-3 items-center">
<input type="text" id="dr-subjectSearch" placeholder="חיפוש חיבורים בהערות / נושאים..." class="flex-1 max-w-md px-4 py-2 bg-slate-800 border border-slate-700 rounded-lg text-sm text-slate-200 outline-none focus:ring-2 focus:ring-blue-500">
<select id="dr-subjectBookFilter" onchange="dr_renderSubjectView()" class="px-3 py-2 bg-slate-800 border border-slate-700 rounded-lg text-xs text-slate-300 outline-none">
<option value="all">כל הספרים</option>
</select>
</div>
</div>
<div id="dr-subjectContent" class="flex-1 overflow-y-auto p-6"></div>
</div>
<!-- Metadata tab -->
<div id="dr-view-metadata" class="hidden absolute inset-0 flex flex-col overflow-hidden" style="top:49px">
<div class="p-4 border-b border-slate-800 bg-slate-900/60 flex flex-wrap gap-3 items-center">
<select id="dr-metaGroupBy" onchange="dr_renderMetadata()" class="px-3 py-2 bg-slate-800 border border-slate-700 rounded-lg text-xs text-slate-300 outline-none">
<option value="owner">קיבוץ לפי מוסד</option>
<option value="language">קיבוץ לפי שפה</option>
<option value="script_tradition">קיבוץ לפי מסורת כתיבה</option>
</select>
<select id="dr-metaBookFilter" onchange="dr_renderMetadata()" class="px-3 py-2 bg-slate-800 border border-slate-700 rounded-lg text-xs text-slate-300 outline-none">
<option value="all">כל הספרים</option>
</select>
</div>
<div id="dr-metaContent" class="flex-1 overflow-y-auto p-6"></div>
</div>
</div>
<!-- ── VIEW 4: SEARCH & ANALYSIS ── -->
<div id="view-search" class="hidden flex-1 flex flex-col overflow-hidden absolute inset-0 bg-slate-50">
<!-- Search controls -->
<div class="bg-white border-b border-slate-200 p-4 shadow-sm">
<div class="max-w-6xl mx-auto">
<div class="flex gap-3 items-end flex-wrap mb-3">
<!-- Mode tabs -->
<div class="flex bg-slate-100 rounded-xl p-1 gap-1 border border-slate-200">
<button id="searchModeBtn-search" onclick="setSearchMode('search')" class="px-4 py-1.5 rounded-lg text-xs font-bold bg-white shadow-sm text-purple-700 transition-all">חיפוש</button>
<button id="searchModeBtn-analysis" onclick="setSearchMode('analysis')" class="px-4 py-1.5 rounded-lg text-xs font-bold text-slate-500 transition-all">ניתוח וסטטיסטיקה</button>
</div>
</div>
<!-- Search form -->
<div id="searchForm" class="flex flex-wrap gap-3 items-end">
<div class="flex-1 relative min-w-[240px]">
<input type="text" id="searchInput" placeholder="חיפוש חופשי בנתוני הגניזה..." class="w-full pl-9 pr-4 py-2.5 bg-slate-100 border border-slate-200 rounded-xl text-sm outline-none focus:ring-2 focus:ring-purple-500 focus:bg-white transition-all" oninput="runSearch()">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 absolute left-2.5 top-3 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" /></svg>
</div>
<div class="flex flex-col">
<label class="text-[10px] font-bold text-slate-400 uppercase mb-1">חפש ב</label>
<select id="searchField" onchange="runSearch()" class="px-3 py-2 bg-white border border-slate-300 rounded-lg text-xs outline-none focus:ring-2 focus:ring-purple-400 shadow-sm">
<option value="all">כל השדות</option>
<option value="title">כותרת</option>
<option value="notes">הערות כלליות</option>
<option value="bibliography">ביבליוגרפיה</option>
<option value="subject">נושאים</option>
<option value="owner">מוסד מחזיק</option>
</select>
</div>
<div class="flex flex-col">
<label class="text-[10px] font-bold text-slate-400 uppercase mb-1">שפה</label>
<select id="langFilter" onchange="runSearch()" class="px-3 py-2 bg-white border border-slate-300 rounded-lg text-xs outline-none focus:ring-2 focus:ring-purple-400 shadow-sm min-w-[120px]">
<option value="">כל השפות</option>
</select>
</div>
<div class="flex flex-col">
<label class="text-[10px] font-bold text-slate-400 uppercase mb-1">מוסד</label>
<select id="ownerFilter" onchange="runSearch()" class="px-3 py-2 bg-white border border-slate-300 rounded-lg text-xs outline-none focus:ring-2 focus:ring-purple-400 shadow-sm min-w-[180px]">
<option value="">כל המוסדות</option>
</select>
</div>
<div class="flex flex-col">
<label class="text-[10px] font-bold text-slate-400 uppercase mb-1">ציון מינ׳</label>
<input type="number" id="searchMinScore" value="0" min="0" max="1" step="0.05" oninput="runSearch()" class="w-20 px-3 py-2 bg-white border border-slate-300 rounded-lg text-xs outline-none focus:ring-2 focus:ring-purple-400 shadow-sm">
</div>
<button onclick="clearSearch()" class="px-4 py-2 text-red-500 hover:bg-red-50 rounded-lg text-xs font-bold transition-all">נקה</button>
</div>
<!-- Stats bar -->
<div id="searchStatsBar" class="flex gap-2 items-center mt-3 flex-wrap"></div>
</div>
</div>
<!-- Search results / Analysis content -->
<div id="searchScroll" class="flex-1 overflow-y-auto p-5">
<div class="max-w-6xl mx-auto">
<div id="searchResults"></div>
<div id="analysisContent" class="hidden"></div>
</div>
</div>
</div>
</section>
</main>
<script>
// ═══════════════════════════════════════════
// UTILS
// ═══════════════════════════════════════════
function getHtmlStr(data) {
if (!data) return '';
if (typeof data === 'string') return data;
if (Array.isArray(data)) return data.map(item => (typeof item === 'string' ? item : (typeof item === 'object' ? item.text || item.html || JSON.stringify(item) : String(item)))).join(' ');
if (typeof data === 'object') return data.text || data.html || JSON.stringify(data);
return String(data);
}
function extractNum(str) {
if (!str) return 0;
const parts = str.split('__');
if (parts.length >= 2) {
const ref = parts[parts.length - 1];
const nums = ref.match(/\d+/g);
if (nums && nums.length >= 2) return parseInt(nums[0]) * 10000 + parseInt(nums[1]);
if (nums && nums.length === 1) return parseInt(nums[0]);
}
const first = str.match(/\d+/);
return first ? parseInt(first[0], 10) : 0;
}
// ═══════════════════════════════════════════
// UNIT LABEL & SEFARIA LINK HELPERS
// ═══════════════════════════════════════════
const PARASHA_HE_MAP = {
Bereshit:'בראשית', Noach:'נח', Lech_Lecha:'לך לך', Vayera:'וירא', Chayei_Sara:'חיי שרה',
Toldot:'תולדות', Vayetzei:'ויצא', Vayishlach:'וישלח', Vayeshev:'וישב', Miketz:'מקץ',
Vayigash:'ויגש', Vayechi:'ויחי', Shemot:'שמות', Vaera:'וארא', Bo:'בא',
Beshalach:'בשלח', Yitro:'יתרו', Mishpatim:'משפטים', Terumah:'תרומה', Tetzaveh:'תצוה',
Ki_Tisa:'כי תשא', Vayakhel:'ויקהל', Pekudei:'פקודי', Vayikra:'ויקרא', Tzav:'צו',
Shemini:'שמיני', Tazria:'תזריע', Metzora:'מצורע', Acharei_Mot:'אחרי מות',
Kedoshim:'קדושים', Emor:'אמור', Behar:'בהר', Bechukotai:'בחקתי', Bamidbar:'במדבר',
Nasso:'נשא', Behaalotcha:'בהעלותך', Shelach:'שלח', Korach:'קרח', Chukat:'חקת',
Balak:'בלק', Pinchas:'פנחס', Matot:'מטות', Masei:'מסעי', Devarim:'דברים',
Vaetchanan:'ואתחנן', Eikev:'עקב', Reeh:'ראה', Shoftim:'שופטים', Ki_Teitzei:'כי תצא',
Ki_Tavo:'כי תבוא', Nitzavim:'נצבים', Vayeilech:'וילך', Haazinu:'האזינו',
VZot_HaBerachah:'וזאת הברכה',
};
const PARASHA_ORDER = [
'Bereshit','Noach','Lech_Lecha','Vayera','Chayei_Sara','Toldot','Vayetzei','Vayishlach','Vayeshev','Miketz','Vayigash','Vayechi',
'Shemot','Vaera','Bo','Beshalach','Yitro','Mishpatim','Terumah','Tetzaveh','Ki_Tisa','Vayakhel','Pekudei',
'Vayikra','Tzav','Shemini','Tazria','Metzora','Acharei_Mot','Kedoshim','Emor','Behar','Bechukotai',
'Bamidbar','Nasso','Behaalotcha','Shelach','Korach','Chukat','Balak','Pinchas','Matot','Masei',
'Devarim','Vaetchanan','Eikev','Reeh','Shoftim','Ki_Teitzei','Ki_Tavo','Nitzavim','Vayeilech','Haazinu','VZot_HaBerachah'
];
const PARASHA_ORDER_INDEX = Object.fromEntries(PARASHA_ORDER.map((p, i) => [p, i]));
const PARASHA_ALIASES = {
Achrei_Mot: 'Acharei_Mot',
HaAzinu: 'Haazinu',
Shlach: 'Shelach',
Shmini: 'Shemini'
};
const DEVARIM_RABBAH_PARASHA_BY_CHAPTER = {
1: 'Devarim',
2: 'Vaetchanan',
3: 'Eikev',
4: 'Reeh',
5: 'Shoftim',
6: 'Ki_Teitzei',
7: 'Ki_Tavo',
8: 'Nitzavim',
9: 'Vayeilech',
10: 'Haazinu',
11: 'VZot_HaBerachah'
};
function getParashaOrderIndex(parashaKey) {
if (!parashaKey) return 999;
const normalized = PARASHA_ALIASES[parashaKey] || parashaKey;
if (PARASHA_ORDER_INDEX[normalized] !== undefined) return PARASHA_ORDER_INDEX[normalized];
// Handle combined parashot (use first recognizable parasha)
const parts = normalized.split('_');
for (let i = parts.length - 1; i >= 1; i--) {
const cand = parts.slice(0, i).join('_');
if (PARASHA_ORDER_INDEX[cand] !== undefined) return PARASHA_ORDER_INDEX[cand];
}
return 999;
}
function parseParashaRef(ref) {
if (!ref) return null;
const m = ref.match(/^([A-Za-z]+(?:_[A-Za-z]+)*)_(\d+)(?:_(\d+))?$/);
if (!m) return null;
let rawKey = m[1];
let isIntro = false;
let isAppendix = false;
let appendixTo = null;
if (rawKey === 'Midrash_Tanchuma') isIntro = true;
if (rawKey.startsWith('Appendix_to_')) {
isAppendix = true;
appendixTo = rawKey.replace(/^Appendix_to_/, '');
rawKey = appendixTo;
}
const parashaKey = PARASHA_ALIASES[rawKey] || rawKey;
return {
parashaKey,
section: parseInt(m[2], 10) || 0,
sub: parseInt(m[3] || '0', 10) || 0,
isIntro,
isAppendix,
appendixTo: appendixTo ? (PARASHA_ALIASES[appendixTo] || appendixTo) : null
};
}
function formatUnitLabel(key) {
if (!key) return '-';
const parts = key.split('__');
if (parts.length < 2) {
const m = key.match(/__?(\d+)/);
return m ? `§${m[1]}` : key.slice(-20);
}
const bookPath = parts[0];
const ref = parts.slice(1).join('__');
if (bookPath.includes('Devarim_Rabbah')) {
const m = ref.match(/^(\d+)_(\d+)$/);
if (m) {
const parashaKey = DEVARIM_RABBAH_PARASHA_BY_CHAPTER[m[1]];
if (parashaKey) {
const he = PARASHA_HE_MAP[parashaKey] || parashaKey.replace(/_/g, ' ');
return `${he} ${m[2]}`;
}
return unitLabelMode === 'section_only' ? `פרק ${m[1]}` : `${m[1]}:${m[2]}`;
}
const m1 = ref.match(/^(\d+)$/);
if (m1) {
const parashaKey = DEVARIM_RABBAH_PARASHA_BY_CHAPTER[m1[1]];
if (parashaKey) return PARASHA_HE_MAP[parashaKey] || parashaKey.replace(/_/g, ' ');
return `פרק ${m1[1]}`;
}
} else if (bookPath.includes('Tanchuma_Buber') || bookPath.includes('Midrash_Tanchuma')) {
const info = parseParashaRef(ref);
if (info) {
if (info.isIntro || info.parashaKey === 'Midrash_Tanchuma') {
return `תנחומא ${info.section}`;
}
const he = PARASHA_HE_MAP[info.parashaKey] || info.parashaKey.replace(/_/g, ' ');
const prefix = info.isAppendix ? `נספח ל${he}` : he;
return unitLabelMode === 'section_only' ? `${prefix} ${info.section}` : `${prefix} ${info.section}${info.sub ? ':' + info.sub : ''}`;
}
} else if (bookPath.includes('Midrash_Tehillim')) {
const m = ref.match(/^(\d+)_(\d+)$/);
if (m) return `תהלים ${m[1]}:${m[2]}`;
const m1 = ref.match(/^(\d+)$/);
if (m1) return `תהלים ${m1[1]}`;
} else if (bookPath.includes('Otzar_Midrashim')) {
const m = ref.match(/(\d+)$/);
if (m) return unitLabelMode === 'section_only' ? `סעיף ${m[1]}` : `תנחומא ${m[1]}`;
}
// Generic fallback
const nums = ref.match(/\d+/g);
if (nums && nums.length >= 2) return unitLabelMode === 'section_only' ? nums[0] : `${nums[0]}:${nums[1]}`;
if (nums) return nums[0];
return ref.replace(/_/g, ' ').slice(0, 25);
}
function buildSefariaLink(key) {
if (!key) return null;
const parts = key.split('__');
if (parts.length < 2) return null;
const bookPath = parts[0];
const ref = parts.slice(1).join('__');
if (bookPath.includes('Devarim_Rabbah')) {
const m = ref.match(/^(\d+)_(\d+)$/);
if (m) return `https://www.sefaria.org.il/Devarim_Rabbah.${m[1]}.${m[2]}`;
const m1 = ref.match(/^(\d+)$/);
if (m1) return `https://www.sefaria.org.il/Devarim_Rabbah.${m1[1]}`;
} else if (bookPath.includes('Tanchuma_Buber')) {
const m = ref.match(/^([A-Za-z]+(?:_[A-Za-z]+)*)_(\d+)_(\d+)$/);
if (m) return `https://www.sefaria.org.il/Midrash_Tanchuma_Buber,_${m[1]}.${m[2]}.${m[3]}`;
const m2 = ref.match(/^([A-Za-z]+(?:_[A-Za-z]+)*)_(\d+)$/);
if (m2) return `https://www.sefaria.org.il/Midrash_Tanchuma_Buber,_${m2[1]}.${m2[2]}`;
} else if (bookPath.includes('Midrash_Tehillim')) {
const m = ref.match(/^(\d+)_(\d+)$/);
if (m) return `https://www.sefaria.org.il/Midrash_Tehillim.${m[1]}.${m[2]}`;
const m1 = ref.match(/^(\d+)$/);
if (m1) return `https://www.sefaria.org.il/Midrash_Tehillim.${m1[1]}`;
} else if (bookPath.includes('Otzar_Midrashim') || ref.startsWith('Midrash_Tanchuma')) {
return `https://www.sefaria.org.il/Midrash_Tanchuma`;
}
return null;
}
function getBookLabel() {
if (activeDatasetIdx >= 0 && allDatasets[activeDatasetIdx]) return allDatasets[activeDatasetIdx].label;
return 'ספר מקור';
}
function getUnitSortKey(key) {
if (!key) return { group: 1, num: 0, tie: '' };
const parts = key.split('__');
const bookPath = parts.length >= 2 ? parts[0] : '';
const ref = parts.length >= 2 ? parts.slice(1).join('__') : key;
const isTanchuma = bookPath.includes('Tanchuma_Buber') || bookPath.includes('Midrash_Tanchuma');
if (isTanchuma) {
const info = parseParashaRef(ref);
if (info) {
return {
group: 0,
parashaIdx: info.isIntro || info.parashaKey === 'Midrash_Tanchuma' ? -1 : getParashaOrderIndex(info.parashaKey),
appendixRank: info.isAppendix ? 1 : 0,
section: info.section,
sub: info.sub,
tie: key
};
}
}
const isDevarimRabbah = bookPath.includes('Devarim_Rabbah');
if (isDevarimRabbah) {
const m = ref.match(/^(\d+)_(\d+)$/);
if (m) {
const parashaKey = DEVARIM_RABBAH_PARASHA_BY_CHAPTER[m[1]];
return {
group: 0,
parashaIdx: getParashaOrderIndex(parashaKey),
appendixRank: 0,
section: parseInt(m[2], 10) || 0,
sub: 0,
tie: key
};
}
}
const isTehillim = bookPath.includes('Midrash_Tehillim');
if (isTehillim) {
const m = ref.match(/^(\d+)_(\d+)$/);
if (m) return { group: 0, parashaIdx: parseInt(m[1], 10), appendixRank: 0, section: parseInt(m[2], 10), sub: 0, tie: key };
}
return { group: 1, num: extractNum(key), tie: key };
}
function compareUnitKeys(a, b) {
const ka = getUnitSortKey(a);
const kb = getUnitSortKey(b);
if (ka.group !== kb.group) return ka.group - kb.group;
if (ka.group === 0) {
if (ka.parashaIdx !== kb.parashaIdx) return ka.parashaIdx - kb.parashaIdx;
const aAppend = ka.appendixRank || 0;
const bAppend = kb.appendixRank || 0;
if (aAppend !== bAppend) return aAppend - bAppend;
if (ka.section !== kb.section) return ka.section - kb.section;
if (ka.sub !== kb.sub) return ka.sub - kb.sub;
return (ka.tie || '').localeCompare(kb.tie || '');
}
if (ka.num !== kb.num) return ka.num - kb.num;
return (ka.tie || '').localeCompare(kb.tie || '');
}
function getScore(c) {
const val = c[activeMetric];
if (val != null && !isNaN(val)) return val;
return c.alignment_score ?? c.norm_score ?? c.score ?? 0;
}
// Returns true if this candidate's alignment_details was a throttled API error (HTTP 429)
function isThrottled(cand) {
const ad = cand.alignment_details || cand.reuse_details || {};
return ad && typeof ad === 'object' && !Array.isArray(ad)
&& (ad.status_code === 429 || ad.status_code === '429');
}
function extractText(cand, item, type) {
let details = cand.alignment_details || cand.reuse_details || cand.details || {};
if (typeof details === 'string') { try { details = JSON.parse(details); } catch(e) { details = {}; } }
if (Array.isArray(details)) details = details[0] || {};
// Detect HTTP 429 rate-limit error stored in alignment_details
if (details.status_code === 429 || details.status_code === '429') {
return `<div class="flex flex-col items-center justify-center py-8 text-center gap-3">
<div class="bg-orange-100 border border-orange-300 rounded-xl p-4 max-w-sm">
<div class="text-2xl mb-2">⏱️</div>
<div class="font-bold text-orange-800 text-sm mb-1">טקסט לא נטען — Rate Limit (429)</div>
<div class="text-orange-700 text-xs leading-relaxed">כשנאספו הנתונים, ה-API הגביל את הבקשות (<em>throttling</em>). המידע הסטטיסטי (ציון ההתאמה, מזהה הגניזה) תקין, אך הטקסט עצמו לא חולץ. יש לבקש מחדש את נתוני ה-alignment לקטע זה.</div>
</div>
</div>`;
}
let htmlData = details[`${type}_html`] || cand[`${type}_html`];
let textData = details[`${type}_text`] || cand[`${type}_text`] || details[type] || cand[type];
let res = getHtmlStr(htmlData);
if (!res || res.trim() === '') res = getHtmlStr(textData);
if ((!res || res.trim() === '') && type === 'passage') res = getHtmlStr(item.passage_html || item.text || item.passage_text || item.Habahir_text);
if ((!res || res.trim() === '') && type === 'source') res = getHtmlStr(details.suspect_html || cand.suspect_html || details.target_html || cand.target_html);
return (res && res.trim() !== '') ? res : `<span class="text-slate-400 italic text-sm">טקסט לא נמצא במבנה הנתונים</span>`;
}
// Language code → Hebrew name
const LANG_MAP = { heb:'עברית', arc:'ארמית', jrb:'יהודית-ערבית', arb:'ערבית', ara:'ערבית', yid:'יידיש', lad:'לאדינו', gre:'יוונית', lat:'לטינית', per:'פרסית', grk:'יוונית', cop:'קופטית', syr:'סורית' };
function langDisplay(langStr) {
if (!langStr) return '';
return langStr.split('|').map(l => LANG_MAP[l.trim()] || l.trim()).filter(Boolean).join(' | ');
}
// ═══════════════════════════════════════════
// STATE
// ═══════════════════════════════════════════
let rawData = {};
let enrichedData = null;
let fragments = {};
let orderedUnits = [];
let currentUnitId = null;
let currentCandIdx = 0;
let scoreRange = [0, 1];
let fragmentSortBy = 'count';
let currentSearchMode = 'search';
let currentInnerTab = 'text';
let currentView = 'units';
// Multi-dataset
let allDatasets = [];
let activeDatasetIdx = -1;
let currentDirHandle = null; // File System Access API directory handle
// Metric & label mode
let activeMetric = 'alignment_score';
let unitLabelMode = 'full';
// Background pre-loader
let _preloadToken = 0; // increment to cancel any running preload
// Performance: virtual sidebar cache
let sidebarCache = null;
let sidebarFilteredKeys = [];
let sidebarRenderRange = { start: 0, end: 0 };
const SIDEBAR_ROW_HEIGHT = 60;
// Performance: avoid rebuilding DR derived data unless needed
let dr_needsRebuild = true;
// Performance: avoid re-running search when nothing changed
let lastSearchKey = null;
let searchResultsCache = [];
let searchRenderedCount = 0;
const SEARCH_PAGE_SIZE = 30;
const SEARCH_MAX_RESULTS = 200;
let lastSearchQuery = '';
// Fragments dataset filter
let fragDatasetFilter = 'all';
// ═══════════════════════════════════════════
// FILE LOADING — handled by multi-dataset functions below
// ═══════════════════════════════════════════
// ═══════════════════════════════════════════
// METADATA HELPERS
// ═══════════════════════════════════════════
function getNliId(location) {
if (!location) return null;
const m = String(location).match(/Geniza_(\d{12,20})/);
return m ? m[1] : null;
}
function getFragmentMeta(location) {
if (!enrichedData || !location) return null;
const id = getNliId(location);
return id ? (enrichedData[id] || null) : null;
}
function buildMetaPanelHtml(location) {
const md = getFragmentMeta(location);
if (!md) {
const id = getNliId(location);
if (!enrichedData) return `<p class="text-teal-600 text-xs italic text-center py-4">טען את קובץ המטה-דאטה לצפייה בפרטים נוספים על קטע הגניזה.</p>`;
return `<p class="text-slate-400 text-xs italic text-center py-4">לא נמצאה רשומה עבור מזהה ${id || 'לא ידוע'}.</p>`;
}
const ld = langDisplay(md.language || '');
const ownShort = (md.current_owner || '').split('|')[0].trim();
const field = (label, value, dir) => value ? `
<div class="mb-3">
<span class="meta-label">${label}</span>
<div class="text-sm text-slate-800 leading-relaxed ${dir ? 'dir-ltr' : ''}" ${dir ? 'dir="ltr"' : ''}>${value}</div>
</div>` : '';
const detailsBlock = (label, value, dir) => value ? `
<details class="mb-3">
<summary class="meta-label cursor-pointer hover:text-teal-800 select-none">${label} ▶</summary>
<div class="mt-1 text-xs text-slate-700 leading-relaxed p-3 bg-teal-50/60 rounded-lg mt-2 ${dir ? '' : ''}" ${dir ? 'dir="ltr"' : ''}>${value}</div>
</details>` : '';
let subjectTags = '';
if (md.subject_headings) {
const tags = md.subject_headings.split(/[,;|]/).map(s => s.trim()).filter(Boolean);
if (tags.length) subjectTags = `
<div class="mb-3">
<span class="meta-label">נושאים</span>
<div class="flex flex-wrap gap-1 mt-1">${tags.map(s => `<span class="bg-teal-100 text-teal-800 text-xs px-2 py-0.5 rounded-full border border-teal-200">${s}</span>`).join('')}</div>
</div>`;
}
return `
<div>
<div class="font-bold text-teal-900 text-base serif-heb leading-snug mb-1">${md.title || '—'}</div>
${md.title_alt ? `<div class="text-teal-600 text-xs mb-3 leading-relaxed">${md.title_alt}</div>` : ''}
<div class="grid grid-cols-2 gap-x-4">
${field('מוסד מחזיק', ownShort)}
${field('שיוך / Shelfmark', md.shelfmark || '', true)}
${field('שפה', ld, true)}
${field('פורמט דיגיטיזציה', md.digitization_format || '', true)}
${field('תיאור פיזי', md.physical_description)}
${field('מספר עמודים', md.page_count)}
${md.material_and_hand ? field('חומר וכתיבה', md.material_and_hand) : ''}
${md.script_tradition ? field('מסורת כתיבה', md.script_tradition) : ''}
${md.former_owner ? field('בעלים קודמים', md.former_owner) : ''}
${md.copyright_status ? field('זכויות יוצרים', md.copyright_status) : ''}
</div>
${subjectTags}
${detailsBlock('הערות כלליות', md.general_notes)}
${detailsBlock('קטעים קשורים', md.related_fragments, true)}
${detailsBlock('ביבליוגרפיה', md.bibliography)}
${md.provenance_notes ? detailsBlock('הערות מוצא', md.provenance_notes) : ''}
<div class="flex flex-wrap gap-2 pt-3 border-t border-teal-200 mt-3">
${md.friedberg_id ? `<span class="text-[10px] bg-slate-100 text-slate-600 px-2 py-1 rounded font-mono border border-slate-200">Friedberg: ${md.friedberg_id}</span>` : ''}
${md.nli_id ? `<span class="text-[10px] bg-slate-100 text-slate-600 px-2 py-1 rounded font-mono border border-slate-200">NLI: ${md.nli_id}</span>` : ''}
${md.nli_ie_id ? `<span class="text-[10px] bg-slate-100 text-slate-600 px-2 py-1 rounded font-mono border border-slate-200" dir="ltr">${md.nli_ie_id}</span>` : ''}
${md.nli_fl_id ? `<span class="text-[10px] bg-slate-100 text-slate-600 px-2 py-1 rounded font-mono border border-slate-200" dir="ltr">${md.nli_fl_id}</span>` : ''}
${md.collection_source ? `<div class="text-[10px] text-slate-400 w-full mt-1">${md.collection_source}</div>` : ''}
</div>
</div>`;
}
function updateUnitMetaPanel(loc) {
const panel = document.getElementById('unitMetaPanel');
if (panel) panel.innerHTML = buildMetaPanelHtml(loc);
}
function switchInnerTab(tab) {
currentInnerTab = tab;
const textView = document.getElementById('innerView-text');
const metaView = document.getElementById('innerView-meta');
const tabText = document.getElementById('innerTab-text');
const tabMeta = document.getElementById('innerTab-meta');
if (tab === 'text') {
textView.classList.remove('hidden');
metaView.classList.add('hidden');
tabText.className = 'px-5 py-2 text-xs font-bold transition-all inner-tab-active';
tabMeta.className = 'px-5 py-2 text-xs font-bold transition-all inner-tab-inactive flex items-center gap-1.5';
} else {
textView.classList.add('hidden');
metaView.classList.remove('hidden');
tabText.className = 'px-5 py-2 text-xs font-bold transition-all inner-tab-inactive';
tabMeta.className = 'px-5 py-2 text-xs font-bold transition-all inner-tab-active flex items-center gap-1.5';
}
}
// ═══════════════════════════════════════════
// DATA PROCESSING
// ═══════════════════════════════════════════
function initData() {
fragments = {};
sidebarCache = null;
orderedUnits = Object.keys(rawData);
orderedUnits.sort(compareUnitKeys);
let globalMaxScore = 0;
orderedUnits.forEach(unitId => {
const item = rawData[unitId];
let cands = item.candidates || item.matches || item.results || [];
if (!Array.isArray(cands) && typeof cands === 'object') cands = Object.values(cands);
item._cands = cands;
const isIndexedMode = allDatasets[activeDatasetIdx]?.mode === 'indexed';
cands.forEach((cand, idx) => {
let s = getScore(cand);
if (s > globalMaxScore) globalMaxScore = s;
let details = cand.alignment_details || cand.reuse_details || {};
const loc = cand.location || details.location || cand.elastic_id || cand.id || `Unknown_${idx}`;
if (!fragments[loc]) fragments[loc] = [];
fragments[loc].push({
unitId, idx, score: s, throttled: isThrottled(cand),
bahir_html: isIndexedMode ? null : extractText(cand, item, 'passage'),
genizah_html: isIndexedMode ? null : extractText(cand, item, 'source'),
_needsLoad: isIndexedMode
});
});
});
globalMaxScore = globalMaxScore > 0 ? globalMaxScore : 1;
minScoreInput.min = 0; maxScoreInput.min = 0;
minScoreInput.max = globalMaxScore; maxScoreInput.max = globalMaxScore;
minScoreInput.step = 'any'; maxScoreInput.step = 'any';
minScoreInput.value = 0; maxScoreInput.value = globalMaxScore;
scoreRange = [0, globalMaxScore];
applyProcessedData(globalMaxScore);
const ds = allDatasets[activeDatasetIdx];
if (ds) {
ds._cache = ds._cache || {};
ds._cache[activeMetric] = { orderedUnits, fragments, maxScore: globalMaxScore };
}
}
function applyProcessedData(globalMaxScore) {
const maxScore = globalMaxScore > 0 ? globalMaxScore : 1;
minScoreInput.min = 0; maxScoreInput.min = 0;
minScoreInput.max = maxScore; maxScoreInput.max = maxScore;
minScoreInput.value = 0; maxScoreInput.value = maxScore;
scoreRange = [0, maxScore];
document.getElementById('contentArea').classList.remove('opacity-30', 'pointer-events-none');
updateSliderTrack();
if (orderedUnits.length > 0) selectUnit(orderedUnits[0]);
if (enrichedData) buildSearchFilters();
dr_needsRebuild = true;
dr_buildAndRender();
// Start background pre-loader after a short delay so the UI renders first
const dsIdx = activeDatasetIdx;
if (allDatasets[dsIdx]?.mode === 'indexed' && allDatasets[dsIdx]?.unitsDir) {
setTimeout(() => startBackgroundPreload(dsIdx), 800);
}
}
async function startBackgroundPreload(dsIdx) {
const ds = allDatasets[dsIdx];
if (!ds || ds.mode !== 'indexed' || !ds.unitsDir) return;
const token = ++_preloadToken;
const units = Object.keys(ds.indexData || {});
const total = units.length;
let done = 0;
const BATCH = 4;
// UI indicator
let indEl = document.getElementById('preloadIndicator');
if (!indEl) {
indEl = document.createElement('div');
indEl.id = 'preloadIndicator';
indEl.style.cssText = 'font-size:10px;color:#93c5fd;font-weight:700;white-space:nowrap;display:flex;align-items:center;gap:6px;';
const hdr = document.querySelector('header .flex.gap-3');
if (hdr) hdr.prepend(indEl);
}
const updateInd = () => {
if (!indEl) return;
if (done >= total) { indEl.textContent = ''; indEl.style.display = 'none'; return; }
indEl.style.display = 'flex';
indEl.innerHTML = `<div style="width:10px;height:10px;border:2px solid #93c5fd;border-top-color:transparent;border-radius:50%;animation:spin 1s linear infinite;"></div> ⤵ ${done}/${total}`;
};
updateInd();
for (let i = 0; i < units.length; i += BATCH) {
if (_preloadToken !== token) { if (indEl) { indEl.textContent = ''; indEl.style.display = 'none'; } return; }
const batch = units.slice(i, i + BATCH).filter(uid => !rawData[uid]?._hasFullData);
await Promise.all(batch.map(uid => loadUnitDetail(dsIdx, uid)));
done = Math.min(i + BATCH, total);
updateInd();
// Yield to browser between batches
await new Promise(r => setTimeout(r, 0));
}
updateInd();
}
// ═══════════════════════════════════════════
// SLIDER
// ═══════════════════════════════════════════
const minScoreInput = document.getElementById('minScore');
const maxScoreInput = document.getElementById('maxScore');
const sliderFill = document.getElementById('sliderFill');
const rangeLabel = document.getElementById('rangeLabel');
function updateSliderTrack() {
let v1 = parseFloat(minScoreInput.value), v2 = parseFloat(maxScoreInput.value);
const maxA = parseFloat(minScoreInput.max) || 1;
if (v1 > v2) { let t = v1; v1 = v2; v2 = t; }
scoreRange = [v1, v2];
dr_needsRebuild = true;
rangeLabel.innerText = `${v1.toFixed(2)} – ${v2.toFixed(2)}`;
sliderFill.style.left = (v1 / maxA * 100) + '%';
sliderFill.style.width = ((v2 - v1) / maxA * 100) + '%';
updateUI();
}
function debounce(fn, ms) { let t; return (...a) => { clearTimeout(t); t = setTimeout(() => fn(...a), ms); }; }
minScoreInput.addEventListener('input', debounce(updateSliderTrack, 80));
maxScoreInput.addEventListener('input', debounce(updateSliderTrack, 80));
function updateUI() {
renderSidebar();
renderFragments();
if (currentView === 'distant') {
if (dr_rebuildDerived()) dr_renderCurrentTab();
}