-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·2513 lines (2453 loc) · 146 KB
/
Copy pathindex.html
File metadata and controls
executable file
·2513 lines (2453 loc) · 146 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<script>(function(){try{var t=localStorage.getItem("theme");if(t&&t!=="auto")document.documentElement.setAttribute("data-theme",t);if(localStorage.getItem("flatDesign")==="1")document.documentElement.classList.add("flat");}catch(e){}})();</script>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>File Viewer</title>
<script src="https://cdn.jsdelivr.net/npm/hls.js@1"></script>
<style>
/* Styles remain consistent */
:root {
--bg-primary: #0d1117;
--bg-secondary: #161b22;
--bg-tertiary: #21262d;
--bg-hover: #30363d;
--border-color: #30363d;
--text-primary: #e6edf3;
--text-secondary: #8b949e;
--text-muted: #6e7681;
--accent: #58a6ff;
--accent-hover: #79b8ff;
--success: #3fb950;
--warning: #d29922;
--danger: #f85149;
--radius: 6px;
--radius-lg: 8px;
--shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
--transition: 0.15s ease;
--font-size-base: 16px;
}
html[data-theme="light"] {
--bg-primary: #ffffff;
--bg-secondary: #f6f8fa;
--bg-tertiary: #eaeef2;
--bg-hover: #d0d7de;
--border-color: #d0d7de;
--text-primary: #1f2328;
--text-secondary: #656d76;
--text-muted: #8c959f;
--accent: #0969da;
--accent-hover: #0550ae;
--shadow: 0 4px 12px rgba(140, 149, 159, 0.2);
}
/* High contrast dark: based on the classic Windows high-contrast black scheme
(black background, white text, cyan title accent, magenta hyperlinks, purple buttons) */
html[data-theme="hc-dark"] {
--bg-primary: #000000;
--bg-secondary: #000000;
--bg-tertiary: #000000;
--bg-hover: #262626;
--border-color: #9370ff;
--text-primary: #ffffff;
--text-secondary: #ffffff;
--text-muted: #a3a3a3;
--accent: #00ffff;
--accent-hover: #33ffff;
--success: #00ffff;
--warning: #ff37cb;
--danger: #ff4444;
--shadow: 0 4px 12px rgba(255, 255, 255, 0.15);
}
/* High contrast light: the hc-dark palette with every color inverted (per RGB channel) */
html[data-theme="hc-light"] {
--bg-primary: #ffffff;
--bg-secondary: #ffffff;
--bg-tertiary: #ffffff;
--bg-hover: #d9d9d9;
--border-color: #6c8f00;
--text-primary: #000000;
--text-secondary: #000000;
--text-muted: #5c5c5c;
--accent: #ff0000;
--accent-hover: #cc0000;
--success: #ff0000;
--warning: #00c834;
--danger: #00bbbb;
--shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
@media (prefers-color-scheme: light) {
:root:not([data-theme]) {
--bg-primary: #ffffff;
--bg-secondary: #f6f8fa;
--bg-tertiary: #eaeef2;
--bg-hover: #d0d7de;
--border-color: #d0d7de;
--text-primary: #1f2328;
--text-secondary: #656d76;
--text-muted: #8c959f;
--accent: #0969da;
--accent-hover: #0550ae;
--shadow: 0 4px 12px rgba(140, 149, 159, 0.2);
}
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: var(--font-size-base); }
body {
font-family: -apple-system, BlinkMacSystemFont, segoe ui, noto sans, Helvetica, Arial, sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
line-height: 1.4;
height: 100vh;
height: 100dvh;
display: flex;
flex-direction: column;
overflow: hidden;
}
.header { background: var(--bg-secondary); border-bottom: 1px solid var(--border-color); padding: 0.5rem 1rem; flex-shrink: 0; }
.header-content { max-width: 1600px; margin: 0 auto; display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.logo { display: flex; align-items: center; gap: 0.5rem; font-size: 1rem; font-weight: 600; color: var(--text-primary); cursor: pointer; flex-shrink: 0; }
.logo svg { width: 20px; height: 20px; }
.breadcrumb { display: flex; align-items: center; gap: 0.125rem; flex-wrap: wrap; font-size: 0.85rem; flex: 1; min-width: 0; }
.breadcrumb-item { color: var(--accent); padding: 0.125rem 0.375rem; border-radius: var(--radius); cursor: pointer; white-space: nowrap; }
.breadcrumb-item:hover { background: var(--bg-hover); }
.breadcrumb-item.current { color: var(--text-primary); cursor: default; }
.breadcrumb-item.current:hover { background: 0 0; }
.breadcrumb-separator { color: var(--text-muted); font-size: 0.75rem; }
.header-actions { display: flex; gap: 0.375rem; align-items: center; }
.search-container { position: relative; width: 200px; }
.search-input { width: 100%; padding: 0.375rem 0.5rem 0.375rem 1.75rem; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: var(--radius); color: var(--text-primary); font-size: 0.85rem; }
.search-input:focus { outline: none; border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }
.search-icon { position: absolute; left: 0.5rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); width: 14px; height: 14px; }
.settings-dropdown { position: relative; }
.settings-btn { padding: 0.375rem; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: var(--radius); color: var(--text-secondary); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.settings-btn:hover { color: var(--text-primary); border-color: var(--accent); }
.settings-btn svg { width: 16px; height: 16px; }
.settings-menu { position: absolute; top: 100%; right: 0; margin-top: 0.25rem; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 230px; z-index: 100; display: none; }
.settings-menu.active { display: block; }
.settings-section { padding: 0.5rem; }
.settings-section-title { font-size: 0.7rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 0.375rem; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.25rem 0; }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider { position: absolute; inset: 0; cursor: pointer; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 999px; transition: 0.2s; }
.switch-slider::before { content: ""; position: absolute; height: 14px; width: 14px; left: 3px; top: 3px; background: var(--text-secondary); border-radius: 50%; transition: 0.2s; }
.switch input:checked + .switch-slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + .switch-slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.settings-label { font-size: 0.85rem; color: var(--text-secondary); }
.settings-control { display: flex; gap: 0.25rem; }
.settings-control button { padding: 0.25rem 0.5rem; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 4px; color: var(--text-secondary); cursor: pointer; font-size: 0.75rem; }
.settings-control button:hover { color: var(--text-primary); border-color: var(--accent); }
.settings-control button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.theme-toggle { display: flex; flex-wrap: wrap; background: var(--bg-tertiary); border-radius: var(--radius); padding: 2px; gap: 2px; }
.theme-btn { padding: 0.25rem 0.5rem; background: 0 0; border: none; color: var(--text-secondary); cursor: pointer; border-radius: 4px; font-size: 0.75rem; display: flex; align-items: center; gap: 0.25rem; }
.theme-btn:hover { background: var(--bg-hover); }
.theme-btn.active { background: var(--bg-primary); }
.theme-btn svg { width: 12px; height: 12px; }
/* Label text is forced to a single uniform color (the current theme's own text color) on
every button, in every state. Only the icon above carries a distinct per-theme color. */
.theme-btn .theme-btn-label { color: var(--text-secondary) !important; }
/* Each theme gets its own icon color as a visual identifier. The label text stays on the
theme-following neutral color above so it's always legible against whatever background
the menu happens to be rendered in (light, dark, HC black, or HC white). */
.theme-btn[data-theme="light"] svg { color: #e3a008; }
.theme-btn[data-theme="dark"] svg { color: #7c8fff; }
.theme-btn[data-theme="auto"] svg { color: #14b8a6; }
.theme-btn[data-theme="hc-dark"] svg { color: #22d3ee; }
.theme-btn[data-theme="hc-light"] svg { color: #c026d3; }
.theme-swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.4rem; width: 100%; }
.theme-swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15); }
.theme-swatch:hover { transform: scale(1.1); }
.theme-swatch.active { border-color: var(--text-primary); }
.theme-custom-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }
.theme-custom-row input[type="color"] { width: 32px; height: 28px; border: 1px solid var(--border-color); border-radius: 4px; background: 0 0; padding: 0; cursor: pointer; }
.theme-reset-btn { flex: 1; border: 1px solid var(--border-color); background: var(--bg-tertiary); color: var(--text-secondary); border-radius: var(--radius); padding: 0.3rem 0.5rem; cursor: pointer; font-size: 0.75rem; }
.theme-reset-btn:hover { color: var(--text-primary); border-color: var(--accent); }
.view-toggle { display: flex; background: var(--bg-tertiary); border-radius: var(--radius); padding: 2px; }
.view-btn { padding: 0.25rem 0.375rem; background: 0 0; border: none; color: var(--text-secondary); cursor: pointer; border-radius: 4px; display: flex; align-items: center; justify-content: center; }
.view-btn:hover { color: var(--text-primary); }
.view-btn.active { background: var(--bg-primary); color: var(--text-primary); }
.view-btn svg { width: 16px; height: 16px; }
.app-container { flex: 1; display: flex; overflow: hidden; }
.tree-panel { width: 240px; background: var(--bg-secondary); border-right: 1px solid var(--border-color); display: none; flex-shrink: 0; flex-direction: column; }
.tree-panel.visible { display: flex; }
.tree-header { padding: 0.5rem 0.75rem; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.tree-content { padding: 0.25rem 0; overflow-y: auto; flex: 1; min-height: 0; }
.tree-content:not(.needs-scroll) { overflow-y: visible; }
.tree-item { display: flex; align-items: center; gap: 0.25rem; padding: 0.25rem 0.5rem; cursor: pointer; font-size: 0.85rem; color: var(--text-secondary); border-left: 2px solid transparent; }
.tree-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.tree-item.active { background: var(--bg-tertiary); color: var(--text-primary); border-left-color: var(--accent); }
.tree-item svg { width: 14px; height: 14px; flex-shrink: 0; }
.tree-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-children { margin-left: 0.75rem; }
.tree-toggle { width: 14px; height: 14px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.tree-toggle svg { width: 10px; height: 10px; transition: transform var(--transition); }
.tree-toggle.expanded svg { transform: rotate(90deg); }
.tree-toggle.empty { visibility: hidden; }
.main { flex: 1; overflow: auto; padding: 0.75rem; display: flex; flex-direction: column; }
.main-content { flex: 1; }
.stats-bar { display: flex; gap: 1rem; margin-bottom: 0.5rem; font-size: 0.75rem; color: var(--text-muted); }
.stat { display: flex; align-items: center; gap: 0.25rem; }
.stat svg { width: 12px; height: 12px; }
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.5rem; }
.file-list { display: flex; flex-direction: column; gap: 1px; }
.file-card { background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 0.625rem; cursor: pointer; transition: border-color var(--transition), box-shadow var(--transition); display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.375rem; }
.file-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.file-card.directory { background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%); }
html.flat .file-card.directory { background: var(--bg-secondary); }
.file-card.parent-dir .file-name { color: var(--text-secondary); }
.file-icon { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 4px; background: var(--bg-tertiary); }
.file-icon svg { width: 20px; height: 20px; }
.file-icon.folder { color: #8b949e; background: rgba(139, 148, 158, 0.1); }
.file-icon.image { color: #a371f7; background: rgba(163, 113, 247, 0.1); }
.file-icon.video { color: #f85149; background: rgba(248, 81, 73, 0.1); }
.file-icon.audio { color: #3fb950; background: rgba(63, 185, 80, 0.1); }
.file-icon.code { color: #58a6ff; background: rgba(88, 166, 255, 0.1); }
.file-icon.document { color: #f0883e; background: rgba(240, 136, 62, 0.1); }
.file-icon.text { color: #8b949e; background: rgba(139, 148, 158, 0.1); }
.file-icon.data { color: #d29922; background: rgba(210, 153, 34, 0.1); }
.file-icon.archive { color: #a5d6ff; background: rgba(165, 214, 255, 0.1); }
.file-icon.playlist { color: #f778ba; background: rgba(247, 120, 186, 0.1); }
.file-name { font-weight: 500; word-break: break-word; font-size: 0.8rem; max-width: 100%; line-height: 1.2; }
.file-meta { font-size: 0.7rem; color: var(--text-muted); }
.file-path { display: block; font-size: 0.65rem; color: var(--text-muted); word-break: break-all; margin-top: 2px; }
.file-thumbnail { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 4px; background: var(--bg-tertiary); }
.file-thumbnail.lazy { opacity: 0; transition: opacity 0.2s; }
.file-thumbnail.loaded { opacity: 1; }
.file-list .file-card { flex-direction: row; text-align: left; padding: 0.375rem 0.5rem; gap: 0.5rem; border-radius: 4px; }
.file-list .file-card:hover { box-shadow: none; }
.file-list .file-icon { width: 24px; height: 24px; }
.file-list .file-icon svg { width: 14px; height: 14px; }
.file-list .file-info { flex: 1; min-width: 0; }
.file-list .file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .file-meta { font-size: 0.7rem; }
.file-list .file-size { color: var(--text-muted); font-size: 0.75rem; flex-shrink: 0; }
.file-list .file-thumbnail { display: none; }
.list-columns { --list-cols: 24px 1fr 70px 90px 100px 80px; }
.file-list-header { display: grid; grid-template-columns: var(--list-cols); gap: 0.5rem; padding: 0.4rem 0.5rem; margin-bottom: 2px; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); border-bottom: 1px solid var(--border-color); position: sticky; top: 0; background: var(--bg-primary); z-index: 5; }
.file-list-header .col-icon-spacer { width: 24px; }
.file-list-header .col { display: flex; align-items: center; gap: 0.25rem; cursor: pointer; user-select: none; }
.file-list-header .col:hover { color: var(--text-primary); }
.file-list-header .col.active { color: var(--accent); }
.file-list-header .sort-arrow { font-size: 0.6rem; width: 0.7em; display: inline-block; }
.file-list-header .col-ext, .file-list-header .col-size, .file-list-header .col-date, .file-list-header .col-time { justify-content: flex-end; }
.file-list.list-columns .file-card { display: grid; grid-template-columns: var(--list-cols); align-items: center; }
.file-list.list-columns .col-ext, .file-list.list-columns .col-size, .file-list.list-columns .col-date, .file-list.list-columns .col-time { text-align: right; font-size: 0.75rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) {
.list-columns { --list-cols: 24px 1fr 60px; }
.file-list-header .col-ext, .file-list-header .col-date, .file-list-header .col-time { display: none; }
.file-list.list-columns .col-ext, .file-list.list-columns .col-date, .file-list.list-columns .col-time { display: none; }
}
.empty-state { text-align: center; padding: 2rem; color: var(--text-secondary); }
.empty-state svg { width: 40px; height: 40px; margin-bottom: 0.5rem; opacity: 0.5; }
.empty-state h2 { font-size: 1rem; margin-bottom: 0.25rem; color: var(--text-primary); }
.empty-state p { font-size: 0.85rem; }
.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.85); display: flex; align-items: center; justify-content: center; z-index: 1000; opacity: 0; visibility: hidden; transition: all 0.2s; padding: 0.5rem; }
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal { background: var(--bg-secondary); border-radius: var(--radius-lg); max-width: 95vw; max-height: 95vh; max-height: 95dvh; width: 100%; display: flex; flex-direction: column; transform: scale(0.95); transition: transform 0.2s; overflow: hidden; border: 1px solid var(--border-color); }
.modal.video-modal { height: 95vh; height: 95dvh; }
.modal-overlay.active .modal { transform: scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border-color); gap: 0.5rem; flex-shrink: 0; }
.modal-title { font-size: 0.9rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.modal-actions { display: flex; gap: 0.25rem; }
.modal-btn { padding: 0.375rem; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: var(--radius); color: var(--text-primary); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 0.25rem; }
.modal-btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.modal-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.modal-btn:disabled:hover { background: var(--bg-tertiary); border-color: var(--border-color); }
.modal-btn svg { width: 16px; height: 16px; }
.modal-btn.play-playlist-btn { padding: 0.375rem 0.5rem; font-size: 0.75rem; color: var(--accent); }
.modal-btn.play-playlist-btn:hover { color: var(--text-primary); }
.modal-btn.hidden { display: none; }
.playlist-bar { display: none; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; background: var(--bg-tertiary); border-bottom: 1px solid var(--border-color); position: relative; }
.playlist-bar.active { display: flex; }
.playlist-controls { display: flex; gap: 0.25rem; align-items: center; }
.playlist-btn.top-native-btn { display: none; }
body.native-player-mode .playlist-btn.top-native-btn { display: inline-flex; }
.playlist-btn { padding: 0.375rem 0.5rem; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius); color: var(--text-primary); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 0.25rem; font-size: 0.75rem; }
.playlist-btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.playlist-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.playlist-btn svg { width: 14px; height: 14px; }
.playlist-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.playlist-info { flex: 1; font-size: 0.8rem; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.playlist-track { color: var(--text-primary); font-weight: 500; }
.playlist-stop-btn { padding: 0.375rem 0.5rem; background: var(--danger); border: 1px solid var(--danger); border-radius: var(--radius); color: #fff; cursor: pointer; font-size: 0.75rem; }
.playlist-stop-btn:hover { opacity: 0.9; }
.goto-quick { display: flex; align-items: center; gap: 0.35rem; }
.goto-input { width: 3.4rem; text-align: center; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--radius); color: var(--text-primary); font-size: 0.8rem; padding: 0.35rem 0.2rem; -moz-appearance: textfield; }
.goto-input::-webkit-outer-spin-button, .goto-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.goto-input:focus { outline: none; border-color: var(--accent); }
.goto-input:disabled { opacity: 0.4; cursor: not-allowed; }
.goto-stepper { display: flex; flex-direction: column; }
.goto-step-btn { width: 1.5rem; height: 1rem; display: flex; align-items: center; justify-content: center; background: var(--bg-secondary); border: 1px solid var(--border-color); color: var(--text-primary); cursor: pointer; padding: 0; line-height: 0; }
.goto-step-btn svg { width: 10px; height: 10px; }
.goto-step-btn:first-child { border-radius: var(--radius) var(--radius) 0 0; border-bottom: none; }
.goto-step-btn:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.goto-step-btn:hover:not(:disabled) { background: var(--bg-hover); }
.goto-step-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.modal-body { flex: 1; overflow: auto; background: var(--bg-primary); display: flex; flex-direction: column; min-height: 0; }
.preview-image { max-width: 100%; max-height: 90vh; object-fit: contain; display: block; margin: auto; }
.preview-media-container { width: 100%; max-width: 900px; height: 100%; min-height: 0; padding: 1rem; margin: 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; position: relative; }
.preview-video { flex: 1; min-height: 0; max-width: 100%; width: auto; object-fit: contain; background: #000; border-radius: var(--radius); }
.preview-audio-container { width: 100%; max-width: 500px; padding: 1.25rem 1rem; margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 0.6rem; position: relative; }
.audio-icon { width: 80px; height: 80px; background: var(--bg-tertiary); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--accent); }
.audio-icon svg { width: 40px; height: 40px; }
.playlist-now-playing { font-weight: 500; text-align: center; width: 100%; max-height: 4.2em; line-height: 1.4em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; word-break: break-word; }
.preview-audio { width: 100%; height: 40px; display: none; }
.preview-audio[controls] { display: block; }
.player-bar { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; width: 100%; max-width: 480px; margin: 0.15rem auto 0; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: var(--radius-lg); padding: 0.6rem 0.75rem; }
.player-seek-row { display: flex; align-items: center; gap: 0.5rem; width: 100%; }
.player-seek { flex: 1; accent-color: var(--accent); cursor: pointer; height: 4px; }
.player-seek:disabled { opacity: 0.4; cursor: not-allowed; }
.player-controls-row { display: flex; align-items: center; justify-content: center; gap: 0.4rem; width: 100%; flex-wrap: nowrap; overflow-x: auto; }
.player-controls-row .playlist-btn { padding: 0.5rem; flex-shrink: 0; }
.player-divider { width: 1px; height: 1.25rem; background: var(--border-color); flex-shrink: 0; }
.player-play-btn { background: var(--accent) !important; border-color: var(--accent) !important; color: #fff !important; border-radius: 50% !important; width: 2.35rem; height: 2.35rem; padding: 0 !important; }
.player-play-btn:hover { background: var(--accent-hover) !important; border-color: var(--accent-hover) !important; }
.player-play-btn svg { width: 18px; height: 18px; }
.player-time, .player-vol { font-size: 0.75rem; color: var(--text-secondary); min-width: 2.5rem; text-align: center; user-select: none; }
.player-info-btn { position: absolute; top: 0.5rem; right: 0.5rem; padding: 0.375rem; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: var(--radius); color: var(--text-primary); cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 2; }
.player-info-btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.player-info-btn svg { width: 16px; height: 16px; }
.player-info-btn.copied { background: var(--accent); border-color: var(--accent); color: #fff; }
.preview-code { width: 100%; min-height: 100%; padding: 0.5rem; background: var(--bg-primary); }
.preview-code pre { margin: 0; font-family: ui-monospace, SFMono-Regular, sf mono, Menlo, Consolas, monospace; font-size: 0.8rem; line-height: 0.9; white-space: pre-wrap; word-break: break-word; }
.preview-code.line-numbers pre { counter-reset: line; }
.preview-code.line-numbers pre .line { display: block; counter-increment: line; }
.preview-code.line-numbers pre .line::before { content: counter(line); display: inline-block; width: 3em; margin-right: 1em; text-align: right; color: var(--text-muted); user-select: none; font-size: 0.75rem; }
.preview-pdf { width: 100%; height: 90vh; border: none; }
.preview-unavailable { text-align: center; padding: 2rem; color: var(--text-secondary); }
.preview-unavailable svg { width: 40px; height: 40px; margin-bottom: 0.5rem; opacity: 0.5; }
.preview-unavailable h3 { margin-bottom: 0.25rem; color: var(--text-primary); font-size: 1rem; }
.download-btn { display: inline-flex; align-items: center; gap: 0.375rem; margin-top: 0.75rem; padding: 0.5rem 1rem; background: var(--accent); color: #fff; text-decoration: none; border-radius: var(--radius); font-weight: 500; font-size: 0.85rem; }
.download-btn:hover { background: var(--accent-hover); }
.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem; color: var(--text-secondary); }
.spinner { width: 28px; height: 28px; border: 2px solid var(--border-color); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin-bottom: 0.5rem; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
.playlist-track.buffering::after { content: " \00b7 Buffering\2026"; color: var(--text-muted); font-weight: 400; animation: pulse 1s ease-in-out infinite; }
.preview-audio.buffering, .preview-video.buffering { opacity: 0.6; transition: opacity 0.15s ease; }
@media (max-width: 768px) { .search-container { width: 150px; } .tree-panel { width: 180px; } .file-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); } }
@media (max-width: 480px) { .tree-panel { display: none !important; } .search-container { width: 120px; } }
@media (max-width: 640px) {
.modal-overlay { padding: 0; }
.modal { width: 100vw; height: 100vh; height: 100dvh; max-width: 100vw; max-height: 100vh; max-height: 100dvh; border-radius: 0; }
.modal-header { padding: 0.5rem 0.5rem; gap: 0.375rem; }
.modal-title { font-size: 0.8rem; }
.modal-actions { gap: 0.15rem; flex-shrink: 0; }
.modal-btn { padding: 0.4rem; min-width: 32px; min-height: 32px; }
.modal-btn svg { width: 15px; height: 15px; }
.modal-btn.play-playlist-btn { padding: 0.4rem; }
.modal-btn.play-playlist-btn .btn-label { display: none; }
.playlist-bar { padding: 0.5rem; flex-wrap: wrap; }
.playlist-btn span { display: none; }
.preview-image { max-height: 80vh; max-height: 80dvh; }
.preview-pdf { height: 80vh; height: 80dvh; }
.preview-media-container { padding: 0.5rem; }
.player-bar { padding: 0.5rem 0.5rem; max-width: 100%; gap: 0.25rem; }
.player-bar .playlist-btn { padding: 0.4rem; }
.player-bar .playlist-btn svg { width: 12px; height: 12px; }
.player-play-btn { width: 2rem !important; height: 2rem !important; }
.player-play-btn svg { width: 15px !important; height: 15px !important; }
.player-time { min-width: 1.6rem; font-size: 0.65rem; }
.player-vol { min-width: 1.9rem; font-size: 0.65rem; }
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: 0 0; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.search-input:focus-visible { outline-offset: 0; }
.file-card:focus-visible { outline-offset: -2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.breadcrumb { overflow-x: auto; scrollbar-width: thin; flex-wrap: nowrap; }
.breadcrumb::-webkit-scrollbar { height: 4px; }
.sort-select { background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 4px; color: var(--text-secondary); font-size: 0.75rem; padding: 0.25rem 0.375rem; }
.load-more-btn { display: block; margin: 0.75rem auto 0; padding: 0.375rem 1rem; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: var(--radius); color: var(--text-primary); cursor: pointer; font-size: 0.8rem; }
.load-more-btn:hover { border-color: var(--accent); }
.truncation-notice { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; background: var(--bg-tertiary); border-bottom: 1px solid var(--border-color); color: var(--text-muted); font-size: 0.75rem; }
.modal-btn.copied { color: var(--success); border-color: var(--success); }
</style>
</head>
<body>
<header class="header">
<div class="header-content">
<div class="logo" id="logoHome" role="button" tabindex="0" aria-label="Go to home folder">
<svg viewBox="0 0 24 24" fill="currentcolor"><path d="M20 6h-8l-2-2H4c-1.1.0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1.0 2-.9 2-2V8c0-1.1-.9-2-2-2zm0 12H4V8h16v10z"/></svg>
<span>File Viewer</span>
</div>
<nav class="breadcrumb" id="breadcrumb" aria-label="Breadcrumb"></nav>
<div class="header-actions">
<div class="search-container">
<svg class="search-icon" viewBox="0 0 24 24" fill="currentcolor"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61.0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/></svg>
<input class="search-input" id="search" placeholder="Search..." autocomplete="off" aria-label="Search files" />
</div>
<div class="settings-dropdown" id="settingsDropdown">
<button class="settings-btn" id="settingsBtn" title="Settings" aria-label="Settings" aria-haspopup="true" aria-expanded="false">
<svg viewBox="0 0 24 24" fill="currentcolor"><path d="M19.14 12.94c.04-.31.06-.63.06-.94.0-.31-.02-.63-.06-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24.0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47.0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.04.31-.06.63-.06.94s.02.63.06.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24.0.44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47.0.59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98.0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z"/></svg>
</button>
<div class="settings-menu" id="settingsMenu">
<div class="settings-section">
<div class="settings-section-title">Font Size</div>
<div class="settings-row">
<span class="settings-label" id="fontSizeLabel">14px</span>
<div class="settings-control">
<button id="fontDecrease" title="Decrease font size" aria-label="Decrease font size">A-</button>
<button id="fontIncrease" title="Increase font size" aria-label="Increase font size">A+</button>
</div>
</div>
</div>
<div class="settings-section" style="border-top: 1px solid var(--border-color)">
<div class="settings-section-title">Sort By</div>
<div class="settings-row">
<select class="sort-select" id="sortSelect" aria-label="Sort files by">
<option value="name-asc">Name (A-Z)</option>
<option value="name-desc">Name (Z-A)</option>
<option value="ext-asc">Extension (A-Z)</option>
<option value="ext-desc">Extension (Z-A)</option>
<option value="size-asc">Size (Smallest)</option>
<option value="size-desc">Size (Largest)</option>
<option value="date-asc">Date (Oldest)</option>
<option value="date-desc">Date (Newest)</option>
<option value="type">Type</option>
</select>
</div>
</div>
<div class="settings-section" style="border-top: 1px solid var(--border-color)">
<div class="settings-section-title">Media Player</div>
<div class="settings-row">
<span class="settings-label">Use native player</span>
<label class="switch">
<input type="checkbox" id="nativePlayerToggle" aria-label="Use native browser player controls instead of the custom player" />
<span class="switch-slider"></span>
</label>
</div>
</div>
</div>
</div>
<div class="settings-dropdown" id="themeColorDropdown">
<button class="settings-btn" id="themeColorBtn" title="Theme & color" aria-label="Theme and color settings" aria-haspopup="true" aria-expanded="false">
<svg viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3a9 9 0 1 0 0 18c1.1 0 2-.9 2-2 0-.5-.2-1-.5-1.3-.3-.4-.5-.8-.5-1.3 0-1.1.9-2 2-2h1.5A4.5 4.5 0 0 0 21 10c0-4-4-7-9-7z"/><circle cx="7.5" cy="10.5" r="1.4" fill="currentcolor" stroke="none"/><circle cx="10.5" cy="7" r="1.4" fill="currentcolor" stroke="none"/><circle cx="14.5" cy="7" r="1.4" fill="currentcolor" stroke="none"/><circle cx="17" cy="10.5" r="1.4" fill="currentcolor" stroke="none"/></svg>
</button>
<div class="settings-menu" id="themeColorMenu">
<div class="settings-section">
<div class="settings-section-title">Theme</div>
<div class="settings-row">
<div class="theme-toggle" id="themeToggle">
<button class="theme-btn" data-theme="light" title="Light theme"><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M12 7c-2.76.0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zM2 13h2c.55.0 1-.45 1-1s-.45-1-1-1H2c-.55.0-1 .45-1 1s.45 1 1 1zm18 0h2c.55.0 1-.45 1-1s-.45-1-1-1h-2c-.55.0-1 .45-1 1s.45 1 1 1zM11 2v2c0 .55.45 1 1 1s1-.45 1-1V2c0-.55-.45-1-1-1s-1 .45-1 1zm0 18v2c0 .55.45 1 1 1s1-.45 1-1v-2c0-.55-.45-1-1-1s-1 .45-1 1zM5.99 4.58c-.39-.39-1.03-.39-1.41.0-.39.39-.39 1.03.0 1.41l1.06 1.06c.39.39 1.03.39 1.41.0s.39-1.03.0-1.41L5.99 4.58zm12.37 12.37c-.39-.39-1.03-.39-1.41.0-.39.39-.39 1.03.0 1.41l1.06 1.06c.39.39 1.03.39 1.41.0.39-.39.39-1.03.0-1.41l-1.06-1.06zm1.06-10.96c.39-.39.39-1.03.0-1.41-.39-.39-1.03-.39-1.41.0l-1.06 1.06c-.39.39-.39 1.03.0 1.41s1.03.39 1.41.0l1.06-1.06zM7.05 18.36c.39-.39.39-1.03.0-1.41-.39-.39-1.03-.39-1.41.0l-1.06 1.06c-.39.39-.39 1.03.0 1.41s1.03.39 1.41.0l1.06-1.06z"/></svg><span class="theme-btn-label">Light</span></button>
<button class="theme-btn" data-theme="dark" title="Dark theme"><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M12 3c-4.97.0-9 4.03-9 9s4.03 9 9 9 9-4.03 9-9c0-.46-.04-.92-.1-1.36-.98 1.37-2.58 2.26-4.4 2.26-2.98.0-5.4-2.42-5.4-5.4.0-1.81.89-3.42 2.26-4.4-.44-.06-.9-.1-1.36-.1z"/></svg><span class="theme-btn-label">Dark</span></button>
<button class="theme-btn" data-theme="auto" title="System theme"><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M12 22C6.49 22 2 17.51 2 12S6.49 2 12 2s10 4.04 10 9c0 3.31-2.69 6-6 6h-1.77c-.28.0-.5.22-.5.5.0.12.05.23.13.33.41.47.64 1.06.64 1.67A2.5 2.5.0 0112 22zm0-18c-4.41.0-8 3.59-8 8s3.59 8 8 8c.28.0.5-.22.5-.5a.54.54.0 00-.14-.35c-.41-.46-.63-1.05-.63-1.65a2.5 2.5.0 012.5-2.5H16c2.21.0 4-1.79 4-4 0-3.86-3.59-7-8-7z"/><circle cx="6.5" cy="11.5" r="1.5"/><circle cx="9.5" cy="7.5" r="1.5"/><circle cx="14.5" cy="7.5" r="1.5"/><circle cx="17.5" cy="11.5" r="1.5"/></svg><span class="theme-btn-label">Auto</span></button>
<button class="theme-btn" data-theme="hc-dark" title="High contrast dark theme"><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M12 2a10 10 0 000 20 10 10 0 000-20zm0 2v16a8 8 0 010-16z"/></svg><span class="theme-btn-label">HC Dark</span></button>
<button class="theme-btn" data-theme="hc-light" title="High contrast light theme"><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M12 2a10 10 0 000 20 10 10 0 000-20zm0 18V4a8 8 0 010 16z"/></svg><span class="theme-btn-label">HC Light</span></button>
</div>
</div>
<div class="settings-row" style="margin-top: 0.375rem">
<span class="settings-label">Flat design</span>
<label class="switch">
<input type="checkbox" id="flatDesignToggle" aria-label="Use flat design (remove gradients)" />
<span class="switch-slider"></span>
</label>
</div>
</div>
<div class="settings-section" style="border-top: 1px solid var(--border-color)">
<div class="settings-section-title">Base Color</div>
<div class="settings-row">
<div class="theme-swatches" id="themeSwatches"></div>
</div>
<div class="theme-custom-row">
<input type="color" id="themeColorInput" value="#58a6ff" title="Pick a custom color" />
<button id="themeResetBtn" class="theme-reset-btn">Reset</button>
</div>
</div>
</div>
</div>
<div class="view-toggle" role="group" aria-label="View mode">
<button class="view-btn" data-view="grid" title="Grid" aria-label="Grid view"><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M4 8h4V4H4v4zm6 12h4v-4h-4v4zm-6 0h4v-4H4v4zm0-6h4v-4H4v4zm6 0h4v-4h-4v4zm6-10v4h4V4h-4zm-6 4h4V4h-4v4zm6 6h4v-4h-4v4zm0 6h4v-4h-4v4z"/></svg></button>
<button class="view-btn" data-view="list" title="List" aria-label="List view"><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M4 14h4v-4H4v4zm0 5h4v-4H4v4zM4 9h4V5H4v4zm5 5h12v-4H9v4zm0 5h12v-4H9v4zM9 5v4h12V5H9z"/></svg></button>
<button class="view-btn active" data-view="tree" title="Tree" aria-label="Tree view"><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M22 11V3h-7v3H9V3H2v8h7V8h2v10h4v3h7v-8h-7v3h-2V8h2v3h7zM7 9H4V5h3v4zm10 6h3v4h-3v-4zm0-10h3v4h-3V5z"/></svg></button>
</div>
</div>
</div>
</header>
<div class="app-container">
<aside class="tree-panel visible" id="treePanel">
<div class="tree-header">Folders</div>
<div class="tree-content" id="treeContent"></div>
</aside>
<main class="main" id="main">
<div class="loading">
<div class="spinner"></div>
<span>Loading...</span>
</div>
</main>
</div>
<div class="modal-overlay" id="modal" role="dialog" aria-modal="true" aria-labelledby="modalTitle">
<div class="modal" id="modalContent">
<div class="modal-header">
<span class="modal-title" id="modalTitle">File Preview</span>
<div class="modal-actions">
<button class="modal-btn play-playlist-btn hidden" id="playPlaylistBtn" title="Play as playlist" aria-label="Play as playlist"><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M15 6H3v2h12V6zm0 4H3v2h12v-2zM3 16h8v-2H3v2zM17 6v8.18c-.31-.11-.65-.18-1-.18-1.66.0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3V8h3V6h-5z"/></svg><span class="btn-label">Play</span></button>
<button class="modal-btn" id="copyLinkBtn" title="Copy link" aria-label="Copy raw file link"><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76.0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71.0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71.0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76.0 5-2.24 5-5s-2.24-5-5-5z"/></svg></button>
<a class="modal-btn" id="downloadBtn" title="Download" aria-label="Download file" download><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z" /></svg></a>
<a class="modal-btn" id="rawBtn" title="Open raw" aria-label="Open raw file in new tab" target="_blank" rel="noopener"><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M19 19H5V5h7V3H5c-1.11.0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1.0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z"/></svg></a>
<button class="modal-btn" id="closeBtn" title="Close" aria-label="Close preview"><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg></button>
</div>
</div>
<div class="playlist-bar" id="playlistBar">
<div class="playlist-controls">
<button class="playlist-btn prev-btn top-native-btn" id="topPrevBtn" title="Previous track" aria-label="Previous track" disabled><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M6 6h2v12H6zm3.5 6 8.5 6V6z" /></svg></button>
<button class="playlist-btn next-btn top-native-btn" id="topNextBtn" title="Next track" aria-label="Next track" disabled><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M6 18l8.5-6L6 6v12zM16 6v12h2V6h-2z" /></svg></button>
<button class="playlist-btn shuffle-btn top-native-btn" id="topShuffleBtn" title="Shuffle" aria-label="Toggle shuffle" aria-pressed="false" disabled><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M10.59 9.17 5.41 4 4 5.41l5.17 5.17 1.42-1.41zM14.5 4l2.04 2.04L4 18.59 5.41 20 17.96 7.46 20 9.5V4h-5.5zm.33 9.41-1.41 1.41 3.13 3.13L14.5 20H20v-5.5l-2.04 2.04-3.13-3.13z" /></svg></button>
<div class="goto-quick" id="gotoQuick" title="Go to track">
<input type="number" class="goto-input" id="gotoInput" min="1" step="1" inputmode="numeric" aria-label="Go to track number" />
<div class="goto-stepper">
<button type="button" class="goto-step-btn" id="gotoUpBtn" aria-label="Next track number" title="Hold to skip faster"><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M7 14l5-5 5 5z" /></svg></button>
<button type="button" class="goto-step-btn" id="gotoDownBtn" aria-label="Previous track number" title="Hold to skip faster"><svg viewBox="0 0 24 24" fill="currentcolor"><path d="M7 10l5 5 5-5z" /></svg></button>
</div>
</div>
</div>
<div class="playlist-info"><span class="playlist-track" id="playlistTrack">Track 1 of 10</span></div>
<button class="playlist-stop-btn" id="playlistStop" title="Stop playlist" aria-label="Stop playlist">Stop</button>
</div>
<div class="modal-body" id="modalBody"></div>
</div>
</div>
<script>
let fileIndex = null,
currentPath = [],
currentView = "tree",
searchQuery = "",
intersectionObserver = null,
expandedFolders = new Set([""]),
currentPlaylist = [],
currentPlaylistIndex = 0,
isShuffle = false,
shuffleBag = [],
shuffleHistory = [],
currentFilePath = "",
currentFileName = "",
isPlaylistFile = !1,
currentFontSize = 16,
themeHue = null,
currentHls = null,
streamTimeout = null,
allFiles = [],
sortBy = "name-asc",
searchResultLimit = 100,
lastFocusedElement = null,
fetchCache = new Map(),
currentVolume = 0.5, // Default volume set to 50%
audioCtx = null,
normalizedElements = new WeakSet(),
compressor = null,
useNativePlayer = false;
// How long to wait for a track to start loading before we assume it's
// dead/unreachable and skip to the next one. Raise this if you're on a
// slow connection and tracks are getting skipped before they finish buffering.
const STREAM_TIMEOUT_MS = 15000;
const icons = {
folder: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/></svg>`,
image: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/></svg>`,
video: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M18 4l2 4h-3l-2-4h-2l2 4h-3l-2-4H8l2 4H7L5 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4h-4z"/></svg>`,
audio: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 3v9.28c-.47-.17-.97-.28-1.5-.28C8.01 12 6 14.01 6 16.5S8.01 21 10.5 21c2.31 0 4.2-1.75 4.45-4H15V6h4V3h-7z"/></svg>`,
code: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"/></svg>`,
document: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"/></svg>`,
text: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"/></svg>`,
data: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"/></svg>`,
archive: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M20.54 5.23l-1.39-1.68C18.88 3.21 18.47 3 18 3H6c-.47 0-.88.21-1.16.55L3.46 5.23C3.17 5.57 3 6.02 3 6.5V19c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6.5c0-.48-.17-.93-.46-1.27zM12 17.5L6.5 12H10v-2h4v2h3.5L12 17.5zM5.12 5l.81-1h12l.94 1H5.12z"/></svg>`,
font: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M9.93 13.5h4.14L12 7.98zM20 2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-4.05 16.5l-1.14-3H9.17l-1.12 3H5.96l5.11-13h1.86l5.11 13h-2.09z"/></svg>`,
markup: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"/></svg>`,
style: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M2.53 19.65l1.34.56v-9.03l-2.43 5.86c-.41 1.02.08 2.19 1.09 2.61zm19.5-3.7L17.07 3.98c-.31-.75-1.04-1.21-1.81-1.23-.26 0-.53.04-.79.15L7.1 5.95c-.75.31-1.21 1.03-1.23 1.8-.01.27.04.54.15.8l4.96 11.97c.31.76 1.05 1.22 1.83 1.23.26 0 .52-.05.77-.15l7.36-3.05c1.02-.42 1.51-1.59 1.09-2.6zm-9.2 3.8L7.87 7.79l7.35-3.04h.01l4.95 11.95-7.35 3.05z"/></svg>`,
playlist: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M15 6H3v2h12V6zm0 4H3v2h12v-2zM3 16h8v-2H3v2zM17 6v8.18c-.31-.11-.65-.18-1-.18-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3V8h3V6h-5z"/></svg>`,
playCtl: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>`,
pauseCtl: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>`,
prevCtl: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M6 6h2v12H6zm3.5 6 8.5 6V6z"/></svg>`,
nextCtl: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M6 18l8.5-6L6 6v12zM16 6v12h2V6h-2z"/></svg>`,
shuffleCtl: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M10.59 9.17 5.41 4 4 5.41l5.17 5.17 1.42-1.41zM14.5 4l2.04 2.04L4 18.59 5.41 20 17.96 7.46 20 9.5V4h-5.5zm.33 9.41-1.41 1.41 3.13 3.13L14.5 20H20v-5.5l-2.04 2.04-3.13-3.13z"/></svg>`,
volDownCtl: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M19 13H5v-2h14v2z"/></svg>`,
volUpCtl: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/></svg>`,
other: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M6 2c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6H6zm7 7V3.5L18.5 9H13z"/></svg>`,
chevron: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg>`,
info: `<svg viewBox="0 0 24 24" fill="currentColor"><path d="M11 7h2v2h-2V7zm0 4h2v6h-2v-6zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z"/></svg>`,
};
function loadSettings() {
const e = localStorage.getItem("theme");
e && e !== "auto"
? document.documentElement.setAttribute("data-theme", e)
: document.documentElement.removeAttribute("data-theme");
const t = localStorage.getItem("fontSize");
t &&
((currentFontSize = parseInt(t)),
document.documentElement.style.setProperty("--font-size-base", currentFontSize + "px")),
updateThemeButtons(),
updateFontSizeLabel();
const v = localStorage.getItem("viewMode");
if (v === "grid" || v === "list" || v === "tree") {
currentView = v;
document.querySelectorAll(".view-btn").forEach((btn) => {
btn.classList.toggle("active", btn.dataset.view === v);
});
document.getElementById("treePanel").classList.toggle("visible", v === "tree");
}
const so = localStorage.getItem("sortBy");
if (so) sortBy = so;
const sortSel = document.getElementById("sortSelect");
if (sortSel) sortSel.value = sortBy;
useNativePlayer = localStorage.getItem("useNativePlayer") === "1";
const nativeToggle = document.getElementById("nativePlayerToggle");
if (nativeToggle) nativeToggle.checked = useNativePlayer;
document.body.classList.toggle("native-player-mode", useNativePlayer);
const flatOn = localStorage.getItem("flatDesign") === "1";
const flatToggle = document.getElementById("flatDesignToggle");
if (flatToggle) flatToggle.checked = flatOn;
document.documentElement.classList.toggle("flat", flatOn);
initThemeColor();
}
function setFlatDesign(on) {
document.documentElement.classList.toggle("flat", on);
localStorage.setItem("flatDesign", on ? "1" : "0");
}
function saveTheme(e) {
e === "auto"
? (localStorage.removeItem("theme"), document.documentElement.removeAttribute("data-theme"))
: (localStorage.setItem("theme", e), document.documentElement.setAttribute("data-theme", e)),
updateThemeButtons();
if (themeHue != null) applyThemeHue(themeHue);
}
function setupDropdown(btnId, menuId, dropdownId) {
const btn = document.getElementById(btnId),
menu = document.getElementById(menuId);
btn.addEventListener("click", (e) => {
e.stopPropagation();
document.querySelectorAll(".settings-menu.active").forEach((m) => {
if (m !== menu) {
m.classList.remove("active");
const otherBtn = m.previousElementSibling;
if (otherBtn) otherBtn.setAttribute("aria-expanded", "false");
}
});
const isActive = menu.classList.toggle("active");
btn.setAttribute("aria-expanded", isActive ? "true" : "false");
});
document.addEventListener("click", (e) => {
if (!e.target.closest("#" + dropdownId)) {
menu.classList.remove("active");
btn.setAttribute("aria-expanded", "false");
}
});
}
/* ---------------------------------------------------------------
Base Color engine
Lets the user pick a new "base driving color" that re-tints every
theme preset (Light, Dark, Auto, HC Dark, HC Light). Each themed
variable keeps its own original saturation & lightness so the
preset's brightness/contrast balance stays exactly as designed —
only the hue shifts to match whatever color the user picks.
--------------------------------------------------------------- */
const THEME_HUE_KEY = "themeHue";
const THEME_BASE = {
dark: {
"--bg-primary": "#0d1117", "--bg-secondary": "#161b22", "--bg-tertiary": "#21262d",
"--bg-hover": "#30363d", "--border-color": "#30363d", "--text-primary": "#e6edf3",
"--text-secondary": "#8b949e", "--text-muted": "#6e7681", "--accent": "#58a6ff",
"--accent-hover": "#79b8ff", "--success": "#3fb950", "--warning": "#d29922", "--danger": "#f85149"
},
light: {
"--bg-primary": "#ffffff", "--bg-secondary": "#f6f8fa", "--bg-tertiary": "#eaeef2",
"--bg-hover": "#d0d7de", "--border-color": "#d0d7de", "--text-primary": "#1f2328",
"--text-secondary": "#656d76", "--text-muted": "#8c959f", "--accent": "#0969da",
"--accent-hover": "#0550ae"
},
"hc-dark": {
"--bg-primary": "#000000", "--bg-secondary": "#000000", "--bg-tertiary": "#000000",
"--bg-hover": "#262626", "--border-color": "#9370ff", "--text-primary": "#ffffff",
"--text-secondary": "#ffffff", "--text-muted": "#a3a3a3", "--accent": "#00ffff",
"--accent-hover": "#33ffff", "--success": "#00ffff", "--warning": "#ff37cb", "--danger": "#ff4444"
},
"hc-light": {
"--bg-primary": "#ffffff", "--bg-secondary": "#ffffff", "--bg-tertiary": "#ffffff",
"--bg-hover": "#d9d9d9", "--border-color": "#6c8f00", "--text-primary": "#000000",
"--text-secondary": "#000000", "--text-muted": "#5c5c5c", "--accent": "#ff0000",
"--accent-hover": "#cc0000", "--success": "#ff0000", "--warning": "#00c834", "--danger": "#00bbbb"
}
};
const THEME_PRESETS = [
{ name: "Blue", hue: 209.2 }, { name: "Indigo", hue: 243 }, { name: "Purple", hue: 262 },
{ name: "Pink", hue: 330 }, { name: "Red", hue: 4 }, { name: "Orange", hue: 28 },
{ name: "Yellow", hue: 48 }, { name: "Green", hue: 142 }, { name: "Teal", hue: 174 },
{ name: "Cyan", hue: 191 }, { name: "Sky", hue: 199 }, { name: "Rose", hue: 350 }
];
function hexToHsl(hex) {
hex = hex.replace("#", "");
if (hex.length === 3) hex = hex.split("").map((c) => c + c).join("");
const r = parseInt(hex.substr(0, 2), 16) / 255,
g = parseInt(hex.substr(2, 2), 16) / 255,
b = parseInt(hex.substr(4, 2), 16) / 255;
const max = Math.max(r, g, b), min = Math.min(r, g, b);
let h = 0, s = 0;
const l = (max + min) / 2, d = max - min;
if (d !== 0) {
s = d / (1 - Math.abs(2 * l - 1));
switch (max) {
case r: h = 60 * (((g - b) / d) % 6); break;
case g: h = 60 * ((b - r) / d + 2); break;
case b: h = 60 * ((r - g) / d + 4); break;
}
}
if (h < 0) h += 360;
return { h, s: s * 100, l: l * 100 };
}
function hslToHex(h, s, l) {
s /= 100; l /= 100;
const c = (1 - Math.abs(2 * l - 1)) * s,
x = c * (1 - Math.abs((h / 60) % 2 - 1)),
m = l - c / 2;
let r = 0, g = 0, b = 0;
if (h < 60) { r = c; g = x; b = 0; }
else if (h < 120) { r = x; g = c; b = 0; }
else if (h < 180) { r = 0; g = c; b = x; }
else if (h < 240) { r = 0; g = x; b = c; }
else if (h < 300) { r = x; g = 0; b = c; }
else { r = c; g = 0; b = x; }
const toHex = (v) => {
const n = Math.max(0, Math.min(255, Math.round((v + m) * 255)));
return n.toString(16).padStart(2, "0");
};
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
}
function getActivePaletteKey() {
const attr = document.documentElement.getAttribute("data-theme");
if (attr === "light" || attr === "hc-dark" || attr === "hc-light") return attr;
if (attr === "dark") return "dark";
const dark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
return dark ? "dark" : "light";
}
function applyThemeHue(hue) {
const root = document.documentElement.style;
const base = THEME_BASE[getActivePaletteKey()];
for (const [varName, baseHex] of Object.entries(base)) {
const { s, l } = hexToHsl(baseHex);
root.setProperty(varName, hslToHex(hue, s, l));
}
markActiveSwatch(hue);
}
function clearThemeHueVars() {
const root = document.documentElement.style;
for (const key of ["dark", "light", "hc-dark", "hc-light"]) {
for (const varName of Object.keys(THEME_BASE[key])) root.removeProperty(varName);
}
}
function setThemeHue(hue) {
themeHue = hue;
localStorage.setItem(THEME_HUE_KEY, String(hue));
applyThemeHue(hue);
}
function resetThemeHue() {
themeHue = null;
localStorage.removeItem(THEME_HUE_KEY);
clearThemeHueVars();
markActiveSwatch(null);
}
function markActiveSwatch(hue) {
const wrap = document.getElementById("themeSwatches");
if (!wrap) return;
wrap.querySelectorAll(".theme-swatch").forEach((sw) => {
const swHue = parseFloat(sw.dataset.hue);
sw.classList.toggle("active", hue != null && Math.abs(swHue - hue) < 0.5);
});
}
function renderThemeSwatches() {
const wrap = document.getElementById("themeSwatches");
if (!wrap) return;
wrap.innerHTML = THEME_PRESETS.map((p) => {
const swatchColor = hslToHex(p.hue, 80, 60);
return `<button type="button" class="theme-swatch" data-hue="${p.hue}" title="${p.name}" style="background:${swatchColor}"></button>`;
}).join("");
}
function wireThemeColorPicker() {
const input = document.getElementById("themeColorInput"),
resetBtn = document.getElementById("themeResetBtn"),
swatches = document.getElementById("themeSwatches");
if (input) input.addEventListener("input", (e) => setThemeHue(hexToHsl(e.target.value).h));
if (resetBtn) resetBtn.addEventListener("click", () => resetThemeHue());
if (swatches) swatches.addEventListener("click", (e) => {
const sw = e.target.closest(".theme-swatch");
if (sw) setThemeHue(parseFloat(sw.dataset.hue));
});
if (window.matchMedia) {
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
if (themeHue != null) applyThemeHue(themeHue);
});
}
}
function initThemeColor() {
renderThemeSwatches();
const stored = localStorage.getItem(THEME_HUE_KEY);
if (stored !== null && stored !== "") {
const hue = parseFloat(stored);
if (!Number.isNaN(hue)) {
themeHue = hue;
applyThemeHue(hue);
const input = document.getElementById("themeColorInput");
if (input) input.value = hslToHex(hue, 100, 60);
return;
}
}
markActiveSwatch(null);
}
function updateThemeButtons() {
const e = localStorage.getItem("theme") || "auto";
document.querySelectorAll(".theme-btn").forEach((t) => {
t.classList.toggle("active", t.dataset.theme === e);
});
}
function updateFontSizeLabel() {
document.getElementById("fontSizeLabel").textContent = currentFontSize + "px";
}
function changeFontSize(e) {
(currentFontSize = Math.max(10, Math.min(20, currentFontSize + e))),
document.documentElement.style.setProperty("--font-size-base", currentFontSize + "px"),
localStorage.setItem("fontSize", currentFontSize),
updateFontSizeLabel();
}
function isPlaylistExtension(e) {
const t = e.toLowerCase();
return t.endsWith(".m3u") || t.endsWith(".m3u8");
}
function preprocessFiles(nodes, pathPrefix = "") {
for (const node of nodes) {
const currentPathStr = pathPrefix ? `${pathPrefix}/${node.name}` : node.name;
const searchKey = currentPathStr.toLowerCase();
const navPath = pathPrefix ? [...pathPrefix.split('/'), node.name] : [node.name];
// Precompute fuzzy-search keys once per file so every keystroke
// doesn't have to re-derive them:
// - normalizedKey: lowercase path with all separators/punctuation
// collapsed to single spaces (e.g. "+checked+/c/chillout" -> "checked c chillout")
// - compactKey: normalizedKey with the spaces removed, used for
// subsequence/fuzzy matching (e.g. "checkedcchillout")
// - boundarySet: indices within compactKey where a "word" starts,
// used to give bonus weight to matches that land on word starts
const normalizedKey = searchKey.replace(/[^a-z0-9]+/g, " ").trim().replace(/\s+/g, " ");
const words = normalizedKey.length ? normalizedKey.split(" ") : [];
const boundarySet = new Set();
let compactKey = "";
for (const w of words) {
boundarySet.add(compactKey.length);
compactKey += w;
}
allFiles.push({
...node,
fullPath: currentPathStr,
navPath: navPath,
searchKey: searchKey,
normalizedKey: normalizedKey,
compactKey: compactKey,
boundarySet: boundarySet,
parentPath: pathPrefix.toLowerCase()
});
if (node.type === "directory" && node.children) {
preprocessFiles(node.children, currentPathStr);
}
}
}
// Scores a single fuzzy-subsequence match of `query` against `str`.
// Returns null if `query`'s characters don't all appear in order within `str`.
// Rewards consecutive runs of matched characters and matches that land on
// word boundaries (tracked via `boundarySet`), and gives a small bonus for
// matching earlier in the string.
function fuzzySubsequenceScore(query, str, boundarySet) {
let qi = 0, score = 0, prevIndex = -2, consecutiveRun = 0, firstIndex = -1;
for (let i = 0; i < str.length && qi < query.length; i++) {
if (str[i] === query[qi]) {
if (firstIndex === -1) firstIndex = i;
if (prevIndex === i - 1) {
consecutiveRun++;
score += 8 + consecutiveRun * 4;
} else {
consecutiveRun = 0;
score += 4;
}
if (boundarySet && boundarySet.has(i)) score += 10;
prevIndex = i;
qi++;
}
}
if (qi < query.length) return null;
score += Math.max(0, 10 - firstIndex * 0.5);
return score;
}
// Scores how well a single file/folder item matches the search query.
// Returns null when the item doesn't match at all. Matches are grouped
// into tiers (higher score range = more relevant), so that a precise
// match (e.g. "check chill") always outranks a loose fuzzy one
// (e.g. "checkchill"), regardless of which folder either file is in:
// Tier 4 (~2000+): the full query, separators and all, is a direct
// substring of the path ("c/chillout")
// Tier 3 (~1400-1900): every space/slash-separated token is present
// as its own substring ("check chill", "check/chill")
// Tier 2 (~1000-1300): a single-token query matches as a substring
// once punctuation is ignored
// Tier 1 (~300-800): fuzzy subsequence match only ("checkchill")
function scoreSearchItem(query, tokens, compactQuery, item) {
const rawKey = item.searchKey;
const normKey = item.normalizedKey;
const exactIdx = rawKey.indexOf(query);
if (exactIdx !== -1) {
return 2200 - exactIdx * 2 - rawKey.length * 0.1;
}
if (tokens.length > 1 && tokens.every((tok) => normKey.includes(tok))) {
let score = 1400;
let lastIdx = -1;
let inOrder = true;
for (const tok of tokens) {
const idx = normKey.indexOf(tok);
if (idx < lastIdx) inOrder = false;
lastIdx = idx;
if (idx === 0 || normKey[idx - 1] === " ") score += 25;
score += Math.max(0, 10 - idx * 0.05);
}
if (inOrder) score += 60;
score -= normKey.length * 0.05;
return score;
}
if (tokens.length === 1 && normKey.includes(tokens[0])) {
const idx = normKey.indexOf(tokens[0]);
let score = 1000;
if (idx === 0 || normKey[idx - 1] === " ") score += 30;
score -= idx * 0.1;
score -= normKey.length * 0.05;
return score;
}
// Cheap length check before the character-by-character scan below:
// a query longer than the path it's being matched against can never
// be a subsequence, so skip the scan entirely.
if (compactQuery.length > 0 && compactQuery.length <= item.compactKey.length) {
const fuzzy = fuzzySubsequenceScore(compactQuery, item.compactKey, item.boundarySet);
if (fuzzy !== null) {
return 300 + fuzzy - item.compactKey.length * 0.05;
}
}
return null;
}
// Runs the fuzzy search across every indexed file/folder and returns
// results ranked by relevance first, with a bonus applied to items
// that live in the folder currently being viewed so, among comparably
// relevant results, local matches surface before matches from other
// folders.
function searchFiles(query) {
const tokens = query.split(/[\s/]+/).filter(Boolean);
const compactQuery = query.replace(/[^a-z0-9]/g, "");
const currentFolderKey = currentPath.join("/").toLowerCase();
const SAME_FOLDER_BONUS = 400;
const scored = [];
for (const item of allFiles) {
const score = scoreSearchItem(query, tokens, compactQuery, item);
if (score === null) continue;
const inCurrentFolder = item.parentPath === currentFolderKey;
scored.push({ item, score: score + (inCurrentFolder ? SAME_FOLDER_BONUS : 0) });
}
scored.sort((a, b) => b.score - a.score);
return scored.map((s) => s.item);
}
// Initialize Web Audio API for Normalization
function setupAudioNormalization(mediaElement) {
// A media element can only ever be connected to one MediaElementSourceNode.
// Since we now reuse the same <audio>/<video> element across playlist
// track changes, skip re-connecting if it's already wired up.
if (normalizedElements.has(mediaElement)) return;
try {
// Ensure CORS is handled for Web Audio
mediaElement.crossOrigin = "anonymous";
if (!audioCtx) {
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// Settings for a "broadcast style" leveling
compressor = audioCtx.createDynamicsCompressor();
compressor.threshold.value = -24; // Start compressing early to catch peaks
compressor.knee.value = 30; // Soft knee for smooth transition
compressor.ratio.value = 12; // High ratio to act as a leveler
compressor.attack.value = 0.003; // Fast attack
compressor.release.value = 0.25; // Standard release
compressor.connect(audioCtx.destination);
}
// Browser policy requires user interaction to resume audio context
if (audioCtx.state === 'suspended') {
audioCtx.resume();
}
// Connect source to compressor
// Note: creating a new source for a new element is standard
const source = audioCtx.createMediaElementSource(mediaElement);
source.connect(compressor);
normalizedElements.add(mediaElement);
} catch (e) {
// Fails quietly if CORS blocks it or AudioContext not supported