Luca448 commited on
Commit
27d4736
Β·
1 Parent(s): 5d693c4

Feat: Premium glass vault redesign with cinematic folder animations (BUILD 1.8.0)

Browse files
index.html CHANGED
@@ -51,7 +51,7 @@
51
  </head>
52
  <body class="dark-theme in-chat-view">
53
 
54
- <div id="live-version-badge" style="position: fixed; top: 50px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-secondary); opacity: 0.6; z-index: 99999; pointer-events: none; font-weight: 500; font-family: monospace; letter-spacing: 1px; background: rgba(0,0,0,0.2); padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05);">BUILD 1.7.2</div>
55
 
56
  <!-- SVG Filters for Liquid Glass Refraction -->
57
  <svg width="0" height="0" style="position: absolute; pointer-events: none;">
 
51
  </head>
52
  <body class="dark-theme in-chat-view">
53
 
54
+ <div id="live-version-badge" style="position: fixed; top: 50px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-secondary); opacity: 0.6; z-index: 99999; pointer-events: none; font-weight: 500; font-family: monospace; letter-spacing: 1px; background: rgba(0,0,0,0.2); padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05);">BUILD 1.8.0</div>
55
 
56
  <!-- SVG Filters for Liquid Glass Refraction -->
57
  <svg width="0" height="0" style="position: absolute; pointer-events: none;">
src/styles/design-tokens.css CHANGED
@@ -43,8 +43,8 @@
43
  */
44
  .liquid-glass {
45
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.02) 100%);
46
- backdrop-filter: blur(20px) saturate(190%);
47
- -webkit-backdrop-filter: blur(20px) saturate(190%);
48
  border: 1px solid rgba(255, 255, 255, 0.05);
49
  border-top: 1px solid rgba(255, 255, 255, 0.25);
50
  border-left: 1px solid rgba(255, 255, 255, 0.15);
@@ -58,8 +58,8 @@
58
 
59
  .liquid-glass-subtle {
60
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0.01) 100%);
61
- backdrop-filter: blur(10px) saturate(150%);
62
- -webkit-backdrop-filter: blur(10px) saturate(150%);
63
  border: 0.5px solid rgba(255, 255, 255, 0.05);
64
  border-top: 0.5px solid rgba(255, 255, 255, 0.12);
65
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.08);
@@ -67,8 +67,8 @@
67
 
68
  .liquid-glass-heavy {
69
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12) 0%, rgba(255, 255, 255, 0.04) 100%);
70
- backdrop-filter: blur(30px) saturate(210%);
71
- -webkit-backdrop-filter: blur(30px) saturate(210%);
72
  border: 1px solid rgba(255, 255, 255, 0.08);
73
  border-top: 1px solid rgba(255, 255, 255, 0.35);
74
  border-left: 1px solid rgba(255, 255, 255, 0.2);
 
43
  */
44
  .liquid-glass {
45
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.02) 100%);
46
+ backdrop-filter: blur(28px) saturate(200%);
47
+ -webkit-backdrop-filter: blur(28px) saturate(200%);
48
  border: 1px solid rgba(255, 255, 255, 0.05);
49
  border-top: 1px solid rgba(255, 255, 255, 0.25);
50
  border-left: 1px solid rgba(255, 255, 255, 0.15);
 
58
 
59
  .liquid-glass-subtle {
60
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0.01) 100%);
61
+ backdrop-filter: blur(16px) saturate(160%);
62
+ -webkit-backdrop-filter: blur(16px) saturate(160%);
63
  border: 0.5px solid rgba(255, 255, 255, 0.05);
64
  border-top: 0.5px solid rgba(255, 255, 255, 0.12);
65
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.08);
 
67
 
68
  .liquid-glass-heavy {
69
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12) 0%, rgba(255, 255, 255, 0.04) 100%);
70
+ backdrop-filter: blur(40px) saturate(220%);
71
+ -webkit-backdrop-filter: blur(40px) saturate(220%);
72
  border: 1px solid rgba(255, 255, 255, 0.08);
73
  border-top: 1px solid rgba(255, 255, 255, 0.35);
74
  border-left: 1px solid rgba(255, 255, 255, 0.2);
src/styles/global.css CHANGED
@@ -3392,4 +3392,466 @@ body.in-chat-view .tts-player-container {
3392
  padding: 4px 8px;
3393
  cursor: pointer;
3394
  margin-left: 4px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3395
  }
 
3392
  padding: 4px 8px;
3393
  cursor: pointer;
3394
  margin-left: 4px;
3395
+ }
3396
+
3397
+ /* ═══════════════════════════════════════════════════════════════════
3398
+ GLASS VAULT β€” Premium Document View Redesign
3399
+ ═══════════════════════════════════════════════════════════════════ */
3400
+
3401
+ /* Wrapper */
3402
+ #vault-glass-wrapper {
3403
+ width: 100%;
3404
+ box-sizing: border-box;
3405
+ padding: 20px 16px 140px 16px;
3406
+ max-width: 800px;
3407
+ margin: 0 auto;
3408
+ min-height: 100vh;
3409
+ background: linear-gradient(180deg, #000000 0%, #0a1628 50%, #0d1f3c 100%);
3410
+ display: flex;
3411
+ flex-direction: column;
3412
+ position: relative;
3413
+ }
3414
+
3415
+ /* Big Ambient Title */
3416
+ .vault-ambient-title {
3417
+ font-size: 36px;
3418
+ font-weight: 800;
3419
+ color: white;
3420
+ opacity: 0.10;
3421
+ line-height: 1.15;
3422
+ margin: 0 0 8px 4px;
3423
+ pointer-events: none;
3424
+ user-select: none;
3425
+ white-space: pre-line;
3426
+ letter-spacing: -0.5px;
3427
+ }
3428
+
3429
+ /* Header bar */
3430
+ .vault-header {
3431
+ display: flex;
3432
+ flex-wrap: wrap;
3433
+ align-items: center;
3434
+ justify-content: space-between;
3435
+ gap: 12px;
3436
+ margin-bottom: 20px;
3437
+ }
3438
+ .vault-header-left {
3439
+ display: flex;
3440
+ flex-direction: column;
3441
+ max-width: 100%;
3442
+ }
3443
+ .vault-header-title {
3444
+ font-size: 20px;
3445
+ font-weight: 700;
3446
+ margin: 0;
3447
+ display: flex;
3448
+ align-items: center;
3449
+ gap: 8px;
3450
+ word-break: break-word;
3451
+ color: white;
3452
+ }
3453
+ .vault-header-sub {
3454
+ font-size: 13px;
3455
+ color: rgba(255,255,255,0.35);
3456
+ margin-top: 2px;
3457
+ }
3458
+ .vault-header-actions {
3459
+ display: flex;
3460
+ gap: 10px;
3461
+ flex-wrap: wrap;
3462
+ }
3463
+
3464
+ /* Action buttons inside vault header */
3465
+ .vault-action-btn {
3466
+ padding: 9px 16px;
3467
+ border-radius: 12px;
3468
+ font-weight: 600;
3469
+ font-size: 14px;
3470
+ display: flex;
3471
+ align-items: center;
3472
+ gap: 7px;
3473
+ cursor: pointer;
3474
+ border: 1px solid rgba(255,255,255,0.10);
3475
+ background: rgba(255,255,255,0.04);
3476
+ color: rgba(255,255,255,0.85);
3477
+ transition: opacity 0.2s, transform 0.15s;
3478
+ -webkit-tap-highlight-color: transparent;
3479
+ }
3480
+ .vault-action-btn:active {
3481
+ transform: scale(0.96);
3482
+ opacity: 0.8;
3483
+ }
3484
+
3485
+ /* 2-Column Grid */
3486
+ #vault-grid {
3487
+ display: grid;
3488
+ grid-template-columns: repeat(2, 1fr);
3489
+ gap: 16px;
3490
+ flex-grow: 1;
3491
+ align-content: flex-start;
3492
+ width: 100%;
3493
+ }
3494
+
3495
+ /* ── Glass Folder ─────────────────────────── */
3496
+ .vault-folder {
3497
+ cursor: pointer;
3498
+ -webkit-tap-highlight-color: transparent;
3499
+ transition: transform 0.25s cubic-bezier(.22,.68,0,1.1), opacity 0.25s ease;
3500
+ will-change: auto;
3501
+ position: relative;
3502
+ }
3503
+ .vault-folder:active {
3504
+ transform: scale(0.97);
3505
+ }
3506
+
3507
+ .vault-folder-body {
3508
+ position: relative;
3509
+ width: 100%;
3510
+ aspect-ratio: 1.3;
3511
+ border-radius: 16px;
3512
+ overflow: visible;
3513
+ }
3514
+
3515
+ /* Tab (top-left flap) */
3516
+ .vault-folder-tab {
3517
+ position: absolute;
3518
+ top: -8px;
3519
+ left: 8px;
3520
+ width: 35%;
3521
+ height: 16px;
3522
+ background: linear-gradient(180deg, rgba(50,55,70,0.8), rgba(35,40,55,0.9));
3523
+ border-radius: 8px 8px 0 0;
3524
+ z-index: 1;
3525
+ }
3526
+
3527
+ /* Front face */
3528
+ .vault-folder-front {
3529
+ position: absolute;
3530
+ top: 0; left: 0; right: 0; bottom: 0;
3531
+ background: linear-gradient(145deg, rgba(45,50,65,0.75) 0%, rgba(20,25,40,0.92) 100%);
3532
+ border-radius: 16px;
3533
+ border: 1px solid rgba(255,255,255,0.08);
3534
+ border-top: 1px solid rgba(255,255,255,0.18);
3535
+ box-shadow: 0 8px 32px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.1);
3536
+ backdrop-filter: blur(12px);
3537
+ -webkit-backdrop-filter: blur(12px);
3538
+ z-index: 2;
3539
+ overflow: hidden;
3540
+ }
3541
+
3542
+ /* Icon overlay centered in folder */
3543
+ .vault-folder-icon {
3544
+ position: absolute;
3545
+ inset: 0;
3546
+ display: flex;
3547
+ align-items: center;
3548
+ justify-content: center;
3549
+ opacity: 0.20;
3550
+ transform: translateY(4px);
3551
+ pointer-events: none;
3552
+ }
3553
+ .vault-folder-icon svg {
3554
+ width: 36px;
3555
+ height: 36px;
3556
+ color: rgba(255,255,255,0.9);
3557
+ }
3558
+
3559
+ /* Preview paper snippets */
3560
+ .vault-folder-previews {
3561
+ position: absolute;
3562
+ top: -10px;
3563
+ right: 10px;
3564
+ display: flex;
3565
+ gap: 3px;
3566
+ z-index: 3;
3567
+ pointer-events: none;
3568
+ }
3569
+ .vault-folder-previews .vault-preview-chip {
3570
+ width: 14px;
3571
+ height: 10px;
3572
+ border-radius: 2px;
3573
+ background: rgba(255,255,255,0.25);
3574
+ transform: rotate(-3deg);
3575
+ }
3576
+ .vault-folder-previews .vault-preview-chip:nth-child(2) {
3577
+ transform: rotate(2deg) translateY(-1px);
3578
+ background: rgba(255,255,255,0.18);
3579
+ }
3580
+ .vault-folder-previews .vault-preview-chip:nth-child(3) {
3581
+ transform: rotate(-1deg) translateY(1px);
3582
+ background: rgba(255,255,255,0.12);
3583
+ }
3584
+
3585
+ /* Folder name below */
3586
+ .vault-folder-name {
3587
+ text-align: center;
3588
+ font-size: 13px;
3589
+ font-weight: 600;
3590
+ color: rgba(255,255,255,0.85);
3591
+ margin-top: 10px;
3592
+ text-shadow: 0 1px 4px rgba(0,0,0,0.5);
3593
+ white-space: nowrap;
3594
+ overflow: hidden;
3595
+ text-overflow: ellipsis;
3596
+ padding: 0 4px;
3597
+ }
3598
+
3599
+ /* Edit button on glass folder */
3600
+ .vault-folder .folder-edit-btn {
3601
+ position: absolute;
3602
+ top: -6px;
3603
+ right: -6px;
3604
+ width: 26px;
3605
+ height: 26px;
3606
+ border-radius: 50%;
3607
+ background: rgba(30,30,40,0.85);
3608
+ color: rgba(255,255,255,0.7);
3609
+ border: 1px solid rgba(255,255,255,0.12);
3610
+ display: flex;
3611
+ align-items: center;
3612
+ justify-content: center;
3613
+ cursor: pointer;
3614
+ opacity: 0;
3615
+ transform: scale(0.8);
3616
+ transition: opacity 0.2s, transform 0.2s;
3617
+ z-index: 10;
3618
+ box-shadow: 0 4px 12px rgba(0,0,0,0.4);
3619
+ }
3620
+ .vault-folder:hover .folder-edit-btn,
3621
+ .vault-folder .folder-edit-btn.visible {
3622
+ opacity: 1;
3623
+ transform: scale(1);
3624
+ }
3625
+
3626
+ /* Delete button on items */
3627
+ .vault-item-delete {
3628
+ position: absolute;
3629
+ top: 6px;
3630
+ left: 6px;
3631
+ width: 24px;
3632
+ height: 24px;
3633
+ border-radius: 50%;
3634
+ background: rgba(255,50,50,0.2);
3635
+ color: #ff4444;
3636
+ border: none;
3637
+ display: flex;
3638
+ align-items: center;
3639
+ justify-content: center;
3640
+ cursor: pointer;
3641
+ opacity: 0;
3642
+ z-index: 10;
3643
+ padding: 0;
3644
+ transition: opacity 0.15s;
3645
+ }
3646
+
3647
+ /* ── Glass File Card ─────────────────────────── */
3648
+ .vault-file {
3649
+ cursor: pointer;
3650
+ -webkit-tap-highlight-color: transparent;
3651
+ transition: transform 0.25s cubic-bezier(.22,.68,0,1.1), opacity 0.25s ease;
3652
+ will-change: auto;
3653
+ position: relative;
3654
+ }
3655
+ .vault-file:active {
3656
+ transform: scale(0.97);
3657
+ }
3658
+
3659
+ .vault-file-body {
3660
+ position: relative;
3661
+ width: 100%;
3662
+ aspect-ratio: 1.3;
3663
+ border-radius: 16px;
3664
+ overflow: hidden;
3665
+ background: linear-gradient(145deg, rgba(45,50,65,0.75) 0%, rgba(20,25,40,0.92) 100%);
3666
+ border: 1px solid rgba(255,255,255,0.08);
3667
+ border-top: 1px solid rgba(255,255,255,0.18);
3668
+ box-shadow: 0 8px 32px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.1);
3669
+ backdrop-filter: blur(12px);
3670
+ -webkit-backdrop-filter: blur(12px);
3671
+ display: flex;
3672
+ flex-direction: column;
3673
+ align-items: center;
3674
+ justify-content: center;
3675
+ padding: 12px;
3676
+ }
3677
+
3678
+ .vault-file-icon {
3679
+ font-size: 28px;
3680
+ opacity: 0.5;
3681
+ margin-bottom: 4px;
3682
+ }
3683
+
3684
+ .vault-file-preview-text {
3685
+ font-size: 9px;
3686
+ line-height: 1.25;
3687
+ color: rgba(255,255,255,0.40);
3688
+ text-align: center;
3689
+ overflow: hidden;
3690
+ max-height: 36px;
3691
+ word-break: break-all;
3692
+ padding: 0 4px;
3693
+ }
3694
+
3695
+ .vault-file-preview-img {
3696
+ position: absolute;
3697
+ inset: 0;
3698
+ background-size: cover;
3699
+ background-position: center;
3700
+ opacity: 0.35;
3701
+ border-radius: 16px;
3702
+ }
3703
+
3704
+ .vault-file-name {
3705
+ text-align: center;
3706
+ font-size: 12px;
3707
+ font-weight: 500;
3708
+ color: rgba(255,255,255,0.75);
3709
+ margin-top: 8px;
3710
+ white-space: nowrap;
3711
+ overflow: hidden;
3712
+ text-overflow: ellipsis;
3713
+ padding: 0 4px;
3714
+ }
3715
+ .vault-file-size {
3716
+ text-align: center;
3717
+ font-size: 10px;
3718
+ color: rgba(255,255,255,0.30);
3719
+ margin-top: 2px;
3720
+ }
3721
+
3722
+ /* ── Empty State ─────────────────────────── */
3723
+ .vault-empty {
3724
+ grid-column: 1 / -1;
3725
+ text-align: center;
3726
+ padding: 60px 20px;
3727
+ color: rgba(255,255,255,0.3);
3728
+ }
3729
+ .vault-empty-icon {
3730
+ font-size: 48px;
3731
+ margin-bottom: 16px;
3732
+ opacity: 0.35;
3733
+ }
3734
+ .vault-empty-title {
3735
+ font-size: 18px;
3736
+ font-weight: 500;
3737
+ color: rgba(255,255,255,0.6);
3738
+ margin-bottom: 8px;
3739
+ }
3740
+ .vault-empty-sub {
3741
+ font-size: 14px;
3742
+ }
3743
+
3744
+ /* ── Skeleton ─────────────────────────── */
3745
+ .vault-skeleton-item {
3746
+ aspect-ratio: 1.3;
3747
+ border-radius: 16px;
3748
+ background: rgba(255,255,255,0.03);
3749
+ animation: pulse 2s infinite;
3750
+ }
3751
+
3752
+ /* ── Animations ─────────────────────────── */
3753
+
3754
+ /* Item fade-in (staggered via inline --delay) */
3755
+ @keyframes vaultItemIn {
3756
+ from {
3757
+ opacity: 0;
3758
+ transform: translateY(20px);
3759
+ }
3760
+ to {
3761
+ opacity: 1;
3762
+ transform: translateY(0);
3763
+ }
3764
+ }
3765
+
3766
+ .vault-item-enter {
3767
+ opacity: 0;
3768
+ animation: vaultItemIn 0.35s cubic-bezier(.22,.68,0,1.1) forwards;
3769
+ animation-delay: var(--delay, 0ms);
3770
+ }
3771
+
3772
+ /* Fade out for navigation */
3773
+ .vault-item-exit {
3774
+ transition: opacity 0.2s ease, transform 0.2s ease;
3775
+ opacity: 0 !important;
3776
+ transform: scale(0.95) !important;
3777
+ }
3778
+
3779
+ /* Long-press: scale-up glow */
3780
+ .vault-folder-pressing {
3781
+ transform: scale(1.05) !important;
3782
+ z-index: 50;
3783
+ }
3784
+ .vault-folder-pressing .vault-folder-front {
3785
+ box-shadow: 0 8px 32px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.1), 0 0 40px rgba(100,140,255,0.15);
3786
+ }
3787
+
3788
+ /* Other items fade away during long-press */
3789
+ .vault-item-hide {
3790
+ transition: opacity 0.3s ease, transform 0.3s ease;
3791
+ opacity: 0 !important;
3792
+ transform: scale(0.85) !important;
3793
+ pointer-events: none;
3794
+ }
3795
+
3796
+ /* Detail mode: folder flies to position */
3797
+ .vault-folder-detail {
3798
+ position: fixed !important;
3799
+ z-index: 100;
3800
+ transition: top 0.45s cubic-bezier(.22,.68,0,1.1),
3801
+ left 0.45s cubic-bezier(.22,.68,0,1.1),
3802
+ width 0.45s cubic-bezier(.22,.68,0,1.1),
3803
+ transform 0.45s cubic-bezier(.22,.68,0,1.1);
3804
+ }
3805
+
3806
+ /* Detail mode overlay */
3807
+ .vault-detail-overlay {
3808
+ position: fixed;
3809
+ inset: 0;
3810
+ z-index: 90;
3811
+ background: rgba(0,0,0,0.01);
3812
+ cursor: pointer;
3813
+ }
3814
+
3815
+ /* Child items flying out from folder */
3816
+ @keyframes vaultChildFlyOut {
3817
+ from {
3818
+ opacity: 0;
3819
+ transform: scale(0.3);
3820
+ }
3821
+ to {
3822
+ opacity: 1;
3823
+ transform: scale(1);
3824
+ }
3825
+ }
3826
+
3827
+ .vault-child-enter {
3828
+ opacity: 0;
3829
+ animation: vaultChildFlyOut 0.4s cubic-bezier(.22,.68,0,1.1) forwards;
3830
+ animation-delay: var(--delay, 0ms);
3831
+ }
3832
+
3833
+ /* Child items flying back */
3834
+ .vault-child-exit {
3835
+ transition: opacity 0.25s ease, transform 0.25s ease;
3836
+ transition-delay: var(--delay, 0ms);
3837
+ opacity: 0 !important;
3838
+ transform: scale(0.3) !important;
3839
+ }
3840
+
3841
+ /* Items returning after back */
3842
+ .vault-item-return {
3843
+ opacity: 0;
3844
+ transform: scale(0.85);
3845
+ animation: vaultItemReturn 0.35s cubic-bezier(.22,.68,0,1.1) forwards;
3846
+ animation-delay: var(--delay, 0ms);
3847
+ }
3848
+ @keyframes vaultItemReturn {
3849
+ from {
3850
+ opacity: 0;
3851
+ transform: scale(0.85);
3852
+ }
3853
+ to {
3854
+ opacity: 1;
3855
+ transform: scale(1);
3856
+ }
3857
  }
src/views/documents/documents-view.js CHANGED
@@ -6,6 +6,12 @@ export class DocumentsView {
6
  constructor(containerId) {
7
  this.container = document.getElementById(containerId);
8
  this.currentPath = ''; // Root is empty string
 
 
 
 
 
 
9
  }
10
 
11
  async init() {
@@ -14,66 +20,54 @@ export class DocumentsView {
14
  await this.render();
15
  }
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  async render() {
 
18
  this.container.innerHTML = `
19
- <div id="documents-wrapper" style="width: 100%; box-sizing: border-box; padding: 24px; padding-bottom: 140px; max-width: 800px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column;">
20
-
21
- <style>
22
- .doc-action-btn {
23
- color: rgba(255, 255, 255, 0.95) !important;
24
- transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
25
- }
26
- .doc-action-btn:hover {
27
- transform: translateY(-2px);
28
- box-shadow: 0 4px 12px rgba(0,0,0,0.2), 0 0 20px rgba(255,255,255,0.05);
29
- }
30
- .doc-action-btn:active {
31
- transform: translateY(1px);
32
- }
33
- .doc-trash-btn:hover {
34
- background: rgba(255, 75, 75, 0.15) !important;
35
- border-color: rgba(255, 75, 75, 0.4) !important;
36
- color: #ff6b6b !important;
37
- }
38
- .doc-new-btn:hover {
39
- background: rgba(144, 100, 255, 0.15) !important;
40
- border-color: rgba(144, 100, 255, 0.4) !important;
41
- color: #c183f0 !important;
42
- }
43
- </style>
44
 
45
- <div style="display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px;">
46
- <div style="max-width: 100%;">
47
- <h2 style="font-size: 24px; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; word-break: break-word;">
 
 
48
  ${this.currentPath ? `
49
- <button id="doc-back-btn" class="icon-btn" style="width: 32px; height: 32px; background: rgba(255,255,255,0.05);">
50
  <svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 18 9 12 15 6"></polyline></svg>
51
  </button>
52
- ` : '<span style="font-size: 24px;">πŸ“</span>'}
53
- ${this.currentPath ? this.currentPath.split('/').pop() : 'Meine Dokumente'}
54
  </h2>
55
- <p style="color: var(--text-secondary); font-size: 14px;">${this.currentPath ? `SchoolMind/${this.currentPath}` : 'Lokaler Vault'}</p>
56
  </div>
57
- <div style="display: flex; gap: 12px; flex-wrap: wrap;">
58
- <button id="trash-btn" class="liquid-glass doc-action-btn doc-trash-btn" style="padding: 10px 20px; border-radius: 12px; font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; cursor: pointer; border: 1px solid rgba(255,255,255,0.15);">
59
- <span style="font-size: 16px;">πŸ—‘οΈ</span>
60
  Papierkorb
61
  </button>
62
- <button id="new-folder-btn" class="liquid-glass doc-action-btn doc-new-btn" style="padding: 10px 20px; border-radius: 12px; font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; cursor: pointer; border: 1px solid rgba(255,255,255,0.15);">
63
- <svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
64
  Neuer Ordner
65
  </button>
66
  </div>
67
  </div>
68
 
69
- <div id="file-list" style="display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; flex-grow: 1; align-content: flex-start; width: 100%;">
70
- <!-- Skeleton Loader -->
71
- ${Array(6).fill(0).map(() => `
72
- <div style="background: rgba(255,255,255,0.03); border-radius: 16px; padding: 16px; aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; animation: pulse 2s infinite;">
73
- <div style="width: 48px; height: 48px; background: rgba(255,255,255,0.05); border-radius: 12px;"></div>
74
- <div style="width: 80%; height: 12px; background: rgba(255,255,255,0.05); border-radius: 6px;"></div>
75
- </div>
76
- `).join('')}
77
  </div>
78
 
79
  </div>
@@ -83,18 +77,18 @@ export class DocumentsView {
83
  this.attachEvents();
84
  }
85
 
 
86
  async loadFiles() {
87
  const files = await fsService.readDir(this.currentPath);
88
- const fileListEl = document.getElementById('file-list');
89
-
90
- if (!fileListEl) return;
91
 
92
  if (files.length === 0) {
93
- fileListEl.innerHTML = `
94
- <div style="grid-column: 1 / -1; text-align: center; padding: 60px 20px; color: var(--text-secondary);">
95
- <div style="font-size: 48px; margin-bottom: 16px; opacity: 0.5;">πŸ“‚</div>
96
- <div style="font-size: 18px; font-weight: 500; color: white;">Ordner ist leer</div>
97
- <div style="font-size: 14px; margin-top: 8px;">Die KI kann hier automatisch Berichte ablegen.</div>
98
  </div>
99
  `;
100
  return;
@@ -107,86 +101,151 @@ export class DocumentsView {
107
  return a.name.localeCompare(b.name);
108
  });
109
 
110
- fileListEl.innerHTML = files.map(f => {
 
 
111
  const isDir = f.type === 'directory';
112
  const path = this.currentPath ? `${this.currentPath}/${f.name}` : f.name;
113
-
114
- let iconHtml = '';
115
  if (isDir) {
116
- const meta = db.getFolderMetadata(path) || { emoji: 'folder', color: '#4285f4' };
117
- // Fallback to 'folder' if it's an old unicode emoji or an invalid name
118
- const iconName = ICON_NAMES.includes(meta.emoji) ? meta.emoji : 'folder';
119
- const color = meta.color || '#4285f4';
120
-
121
- const svgIconHtml = getIconSvg(iconName, {
122
- class: 'folder-icon-engraved',
123
- width: '32',
124
- height: '32'
125
- });
126
-
127
- iconHtml = `
128
- <div class="macos-folder">
129
- <svg viewBox="0 0 100 80" xmlns="http://www.w3.org/2000/svg">
130
- <defs>
131
- <linearGradient id="folderGrad_${f.name.replace(/[^a-zA-Z0-9]/g, '')}" x1="0" y1="0" x2="0" y2="1">
132
- <stop offset="0%" stop-color="${color}" stop-opacity="0.9" />
133
- <stop offset="100%" stop-color="${color}" />
134
- </linearGradient>
135
- </defs>
136
- <path d="M5 20 Q5 10 15 10 L35 10 Q40 10 42 15 L45 20 L90 20 Q95 20 95 30 L95 70 Q95 80 85 80 L15 80 Q5 80 5 70 Z" fill="${color}" opacity="0.6"/>
137
- <path d="M5 30 Q5 25 10 25 L90 25 Q95 25 95 30 L95 70 Q95 80 85 80 L15 80 Q5 80 5 70 Z" fill="url(#folderGrad_${f.name.replace(/[^a-zA-Z0-9]/g, '')})"/>
138
- </svg>
139
- <div class="folder-emoji-wrapper">
140
- ${svgIconHtml}
141
- </div>
142
- </div>
143
- <button class="folder-edit-btn" data-path="${path}" data-emoji="${iconName}" data-color="${color}" title="Ordner anpassen">
144
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 20h9"></path><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"></path></svg>
145
- </button>
146
- `;
147
  } else {
148
- const icon = f.name.endsWith('.md') ? 'πŸ“' : 'πŸ“„';
149
- iconHtml = `<div style="font-size: 42px; line-height: 1; filter: drop-shadow(0 4px 12px rgba(0,0,0,0.2));">${icon}</div>`;
150
  }
151
-
152
- const sizeStr = !isDir && f.size ? Math.round(f.size / 1024) + ' KB' : '';
153
-
154
- const itemClass = isDir ? 'file-item folder-item' : 'file-item liquid-glass-subtle';
155
-
156
- return `
157
- <div class="${itemClass}" data-name="${f.name}" data-isdir="${isDir}" style="border-radius: 16px; padding: ${isDir ? '8px' : '16px'}; aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; cursor: pointer; transition: transform 0.2s, filter 0.2s; position: relative;">
158
- ${iconHtml}
159
- <div style="text-align: center; width: 100%;">
160
- <div style="font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: white; ${isDir ? 'text-shadow: 0 2px 4px rgba(0,0,0,0.5); margin-top: 4px;' : ''}">${f.name}</div>
161
- ${sizeStr ? `<div style="font-size: 11px; color: var(--text-secondary); margin-top: 4px;">${sizeStr}</div>` : ''}
162
- </div>
163
-
164
- <button class="delete-file-btn icon-btn" style="position: absolute; top: 8px; left: 8px; width: 24px; height: 24px; opacity: 0; background: rgba(255,50,50,0.2); color: #ff4444; border: none; padding: 0; z-index: 5;" title="LΓΆschen" data-name="${f.name}" data-isdir="${isDir}">
165
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>
166
- </button>
167
- </div>
168
- `;
169
  }).join('');
170
 
171
- // Add hover effect for action buttons
172
- document.querySelectorAll('.file-item').forEach(item => {
 
 
 
173
  item.addEventListener('mouseenter', () => {
174
- const btn = item.querySelector('.delete-file-btn');
175
- if(btn) btn.style.opacity = '1';
176
  });
177
  item.addEventListener('mouseleave', () => {
178
- const btn = item.querySelector('.delete-file-btn');
179
- if(btn) btn.style.opacity = '0';
180
  });
181
  });
182
  }
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  attachEvents() {
185
- const wrapper = this.container.querySelector('#documents-wrapper');
186
  if (!wrapper) return;
 
 
 
 
187
  wrapper.addEventListener('click', async (e) => {
188
- const fileItem = e.target.closest('.file-item');
189
- const deleteBtn = e.target.closest('.delete-file-btn');
 
 
 
 
 
 
 
190
  const editBtn = e.target.closest('.folder-edit-btn');
191
  const backBtn = e.target.closest('#doc-back-btn');
192
  const newFolderBtn = e.target.closest('#new-folder-btn');
@@ -221,292 +280,28 @@ export class DocumentsView {
221
  return;
222
  }
223
 
224
- if (fileItem) {
225
- const name = fileItem.dataset.name;
226
- const isDir = fileItem.dataset.isdir === 'true';
227
  const path = this.currentPath ? `${this.currentPath}/${name}` : name;
 
 
 
228
 
229
- if (isDir) {
230
- this.currentPath = path;
231
- this.render(); // Re-render to update header
232
- } else if (name.endsWith('.md') || name.endsWith('.txt') || name.endsWith('.csv')) {
233
- // Open PDF Modal with markdown content
234
- const content = await fsService.readFile(path);
235
- if (content && window.openPdfModal) {
236
- window.openPdfModal(content);
237
- }
238
- } else if (name.toLowerCase().endsWith('.pdf')) {
239
- const base64 = await fsService.readBinaryFile(path);
240
- if (base64) {
241
- // Container that holds everything
242
- const viewerWrapper = document.createElement('div');
243
- viewerWrapper.id = 'pdf-viewer-wrapper';
244
- viewerWrapper.style.position = 'fixed';
245
- viewerWrapper.style.top = '0'; viewerWrapper.style.left = '0'; viewerWrapper.style.width = '100vw'; viewerWrapper.style.height = '100vh';
246
- viewerWrapper.style.zIndex = '999999';
247
- viewerWrapper.style.backgroundColor = '#1a1a1a';
248
- viewerWrapper.style.overflow = 'auto';
249
- viewerWrapper.style.boxSizing = 'border-box';
250
- // Use horizontal padding to center the PDF initially
251
- viewerWrapper.style.padding = '80px 20px';
252
-
253
- // Force text selection and hit-testing on Android Webview
254
- const textSelectStyle = document.createElement('style');
255
- textSelectStyle.textContent = `
256
- #pdf-viewer-wrapper, #pdf-viewer-wrapper * {
257
- -webkit-user-select: text !important;
258
- user-select: text !important;
259
- -webkit-touch-callout: default !important;
260
- }
261
- #pdf-viewer-wrapper .textLayer span {
262
- /* Android WebView sometimes ignores hit testing on 100% transparent text */
263
- color: rgba(0,0,0,0.01) !important;
264
- pointer-events: all !important;
265
- cursor: text !important;
266
- }
267
- #pdf-viewer-wrapper ::selection {
268
- background: rgba(0, 120, 255, 0.3) !important;
269
- }
270
- `;
271
- viewerWrapper.appendChild(textSelectStyle);
272
-
273
- const pdfContainer = document.createElement('div');
274
- // By NOT using flexbox align-items: center, we prevent the browser from clipping the left side when zoomed in!
275
- pdfContainer.style.display = 'block';
276
- // We will use the CSS zoom property for scaling
277
- pdfContainer.style.zoom = '1.0';
278
- pdfContainer.style.transformOrigin = '0 0'; // ensure scale origin is top-left just in case
279
-
280
- viewerWrapper.appendChild(pdfContainer);
281
-
282
- // Floating Close Button
283
- const closeBtn = document.createElement('button');
284
- closeBtn.innerHTML = 'ZurΓΌck';
285
- closeBtn.style.position = 'fixed';
286
- closeBtn.style.top = 'env(safe-area-inset-top, 20px)';
287
- closeBtn.style.right = '20px';
288
- closeBtn.style.padding = '8px 16px';
289
- closeBtn.style.background = 'rgba(0,0,0,0.5)';
290
- closeBtn.style.color = '#fff';
291
- closeBtn.style.border = '1px solid rgba(255,255,255,0.2)';
292
- closeBtn.style.borderRadius = '12px';
293
- closeBtn.style.cursor = 'pointer';
294
- closeBtn.style.backdropFilter = 'blur(10px)';
295
- closeBtn.style.fontWeight = '600';
296
- closeBtn.style.boxShadow = '0 4px 12px rgba(0,0,0,0.5)';
297
- closeBtn.style.zIndex = '1000000';
298
-
299
- // Floating Zoom Controls
300
- const zoomControls = document.createElement('div');
301
- zoomControls.style.position = 'fixed';
302
- zoomControls.style.bottom = '20px';
303
- zoomControls.style.left = '50%';
304
- zoomControls.style.transform = 'translateX(-50%)';
305
- zoomControls.style.display = 'flex';
306
- zoomControls.style.gap = '12px';
307
- zoomControls.style.background = 'rgba(30, 30, 35, 0.9)';
308
- zoomControls.style.padding = '8px';
309
- zoomControls.style.borderRadius = '16px';
310
- zoomControls.style.border = '1px solid rgba(255,255,255,0.1)';
311
- zoomControls.style.backdropFilter = 'blur(10px)';
312
- zoomControls.style.zIndex = '1000000';
313
- zoomControls.style.boxShadow = '0 8px 24px rgba(0,0,0,0.5)';
314
-
315
- let currentZoom = 1.0;
316
- const updateZoom = (newZoom) => {
317
- if (newZoom < 1.0) newZoom = 1.0;
318
- if (newZoom > 4.0) newZoom = 4.0;
319
- currentZoom = newZoom;
320
- pdfContainer.style.zoom = currentZoom;
321
- };
322
-
323
- const zoomToPoint = (delta, centerX, centerY) => {
324
- const pointX = (centerX + viewerWrapper.scrollLeft) / currentZoom;
325
- const pointY = (centerY + viewerWrapper.scrollTop) / currentZoom;
326
-
327
- updateZoom(currentZoom + delta);
328
-
329
- viewerWrapper.scrollLeft = (pointX * currentZoom) - centerX;
330
- viewerWrapper.scrollTop = (pointY * currentZoom) - centerY;
331
- };
332
-
333
- const zoomOutBtn = document.createElement('button');
334
- zoomOutBtn.innerHTML = '<svg viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><line x1="5" y1="12" x2="19" y2="12"></line></svg>';
335
- zoomOutBtn.style.background = 'transparent'; zoomOutBtn.style.border = 'none'; zoomOutBtn.style.color = 'white'; zoomOutBtn.style.cursor = 'pointer'; zoomOutBtn.style.padding = '8px';
336
- zoomOutBtn.onclick = () => zoomToPoint(-0.5, viewerWrapper.clientWidth / 2, viewerWrapper.clientHeight / 2);
337
-
338
- const zoomInBtn = document.createElement('button');
339
- zoomInBtn.innerHTML = '<svg viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>';
340
- zoomInBtn.style.background = 'transparent'; zoomInBtn.style.border = 'none'; zoomInBtn.style.color = 'white'; zoomInBtn.style.cursor = 'pointer'; zoomInBtn.style.padding = '8px';
341
- zoomInBtn.onclick = () => zoomToPoint(0.5, viewerWrapper.clientWidth / 2, viewerWrapper.clientHeight / 2);
342
-
343
- zoomControls.appendChild(zoomOutBtn);
344
- zoomControls.appendChild(zoomInBtn);
345
-
346
- // Custom Pinch-To-Zoom Handler
347
- let initialDistance = 0;
348
- let initialZoom = 1.0;
349
- let pinchPoint = { x: 0, y: 0 };
350
-
351
- viewerWrapper.addEventListener('touchstart', (e) => {
352
- if (e.touches.length === 2) {
353
- const t1 = e.touches[0];
354
- const t2 = e.touches[1];
355
- const dx = t1.clientX - t2.clientX;
356
- const dy = t1.clientY - t2.clientY;
357
- initialDistance = Math.sqrt(dx*dx + dy*dy);
358
- initialZoom = currentZoom;
359
-
360
- const centerX = (t1.clientX + t2.clientX) / 2;
361
- const centerY = (t1.clientY + t2.clientY) / 2;
362
-
363
- pinchPoint.x = (centerX + viewerWrapper.scrollLeft) / currentZoom;
364
- pinchPoint.y = (centerY + viewerWrapper.scrollTop) / currentZoom;
365
- }
366
- });
367
- viewerWrapper.addEventListener('touchmove', (e) => {
368
- if (e.touches.length === 2) {
369
- e.preventDefault(); // Stop native behavior for 2-finger touch
370
- const t1 = e.touches[0];
371
- const t2 = e.touches[1];
372
- const dx = t1.clientX - t2.clientX;
373
- const dy = t1.clientY - t2.clientY;
374
- const dist = Math.sqrt(dx*dx + dy*dy);
375
-
376
- const newZoom = initialZoom * (dist / initialDistance);
377
- updateZoom(newZoom);
378
-
379
- const centerX = (t1.clientX + t2.clientX) / 2;
380
- const centerY = (t1.clientY + t2.clientY) / 2;
381
-
382
- viewerWrapper.scrollLeft = (pinchPoint.x * currentZoom) - centerX;
383
- viewerWrapper.scrollTop = (pinchPoint.y * currentZoom) - centerY;
384
- }
385
- }, { passive: false });
386
-
387
- closeBtn.onclick = () => {
388
- if(viewerWrapper.parentNode) document.body.removeChild(viewerWrapper);
389
- };
390
-
391
- viewerWrapper.appendChild(closeBtn);
392
- viewerWrapper.appendChild(zoomControls);
393
- document.body.appendChild(viewerWrapper);
394
-
395
- const loadingText = document.createElement('div');
396
- loadingText.innerHTML = 'Lade PDF...';
397
- loadingText.style.color = '#fff';
398
- loadingText.style.fontFamily = 'sans-serif';
399
- loadingText.style.textAlign = 'center';
400
- pdfContainer.appendChild(loadingText);
401
-
402
- // Dynamically load pdf.js in the parent
403
- const loadPdfJs = () => new Promise((resolve, reject) => {
404
- // Load CSS
405
- const link = document.createElement('link');
406
- link.rel = 'stylesheet';
407
- link.href = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf_viewer.min.css';
408
- document.head.appendChild(link);
409
-
410
- if (window['pdfjs-dist/build/pdf']) return resolve(window['pdfjs-dist/build/pdf']);
411
- const script = document.createElement('script');
412
- script.src = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js';
413
- script.onload = () => resolve(window['pdfjs-dist/build/pdf']);
414
- script.onerror = reject;
415
- document.head.appendChild(script);
416
- });
417
-
418
- try {
419
- const pdfjsLib = await loadPdfJs();
420
- pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js';
421
-
422
- const pdfData = atob(base64);
423
- const uint8Array = new Uint8Array(pdfData.length);
424
- for (let i = 0; i < pdfData.length; i++) {
425
- uint8Array[i] = pdfData.charCodeAt(i);
426
- }
427
-
428
- const loadingTask = pdfjsLib.getDocument({ data: uint8Array });
429
- const pdf = await loadingTask.promise;
430
-
431
- if(loadingText && loadingText.parentNode) {
432
- loadingText.parentNode.removeChild(loadingText);
433
- }
434
-
435
- // Render all pages
436
- for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) {
437
- const page = await pdf.getPage(pageNum);
438
-
439
- const unscaledViewport = page.getViewport({ scale: 1.0 });
440
- // We use baseScale so it exactly fits the phone screen width initially
441
- const screenWidth = window.innerWidth - 40;
442
- const baseScale = screenWidth / unscaledViewport.width;
443
-
444
- // Render at a high density (4x) so zooming up to 4x stays sharp
445
- const renderScale = baseScale * 4;
446
-
447
- const cssViewport = page.getViewport({ scale: baseScale });
448
- const renderViewport = page.getViewport({ scale: renderScale });
449
-
450
- const pageContainerDiv = document.createElement('div');
451
- pageContainerDiv.style.position = 'relative';
452
- pageContainerDiv.style.width = cssViewport.width + 'px';
453
- pageContainerDiv.style.height = cssViewport.height + 'px';
454
- pageContainerDiv.style.marginBottom = '24px';
455
- pageContainerDiv.style.boxShadow = '0 8px 24px rgba(0,0,0,0.5)';
456
- pageContainerDiv.style.borderRadius = '8px';
457
- pageContainerDiv.style.backgroundColor = 'white';
458
-
459
- const canvas = document.createElement('canvas');
460
- const context = canvas.getContext('2d');
461
- canvas.width = renderViewport.width;
462
- canvas.height = renderViewport.height;
463
- canvas.style.width = cssViewport.width + 'px';
464
- canvas.style.height = cssViewport.height + 'px';
465
- canvas.style.display = 'block';
466
- canvas.style.borderRadius = '8px';
467
- pageContainerDiv.appendChild(canvas);
468
-
469
- const textLayerDiv = document.createElement('div');
470
- textLayerDiv.setAttribute('class', 'textLayer selectable-text');
471
- textLayerDiv.style.width = cssViewport.width + 'px';
472
- textLayerDiv.style.height = cssViewport.height + 'px';
473
- textLayerDiv.style.position = 'absolute';
474
- textLayerDiv.style.top = '0';
475
- textLayerDiv.style.left = '0';
476
- textLayerDiv.style.setProperty('--scale-factor', cssViewport.scale);
477
- pageContainerDiv.appendChild(textLayerDiv);
478
-
479
- pdfContainer.appendChild(pageContainerDiv);
480
-
481
- const renderTask = page.render({
482
- canvasContext: context,
483
- viewport: renderViewport
484
- });
485
- await renderTask.promise;
486
-
487
- const textContent = await page.getTextContent();
488
- pdfjsLib.renderTextLayer({
489
- textContentSource: textContent,
490
- container: textLayerDiv,
491
- viewport: cssViewport,
492
- textDivs: []
493
- });
494
- }
495
- } catch (err) {
496
- if(loadingText) loadingText.innerHTML = 'Fehler beim Laden der PDF.';
497
- console.error(err);
498
- }
499
- }
500
- }
501
  return;
502
  }
503
 
504
  if (backBtn) {
505
- // Go up one level
506
  const parts = this.currentPath.split('/');
507
  parts.pop();
508
  this.currentPath = parts.join('/');
509
  this.render();
 
510
  }
511
 
512
  if (newFolderBtn) {
@@ -514,17 +309,13 @@ export class DocumentsView {
514
  if (folderName && folderName.trim()) {
515
  const cleanName = folderName.trim();
516
  const path = this.currentPath ? `${this.currentPath}/${cleanName}` : cleanName;
517
-
518
- // First create the folder physically to update UI fast
519
  await fsService.createFolder(path);
520
  this.loadFiles();
521
-
522
- // In background, use AI to fetch an emoji and then re-render
523
  try {
524
  const { folderAgent } = await import('../../ai/folder-agent.js?v=2');
525
  const visuals = await folderAgent.generateVisualsForFolder(cleanName);
526
  db.saveFolderMetadata(path, visuals.emoji, visuals.color);
527
- this.loadFiles(); // Re-render to show emoji
528
  } catch (err) {
529
  console.error('Background emoji assignment failed:', err);
530
  }
@@ -534,8 +325,592 @@ export class DocumentsView {
534
  });
535
  }
536
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
537
  showFolderPopover(btnEl) {
538
- // Remove existing popovers
539
  document.querySelectorAll('.folder-popover').forEach(p => p.remove());
540
 
541
  const path = btnEl.dataset.path;
@@ -543,19 +918,16 @@ export class DocumentsView {
543
  const currentColor = btnEl.dataset.color;
544
  const popover = document.createElement('div');
545
  popover.className = 'folder-popover';
546
-
547
- // Position it below the button
548
  const rect = btnEl.getBoundingClientRect();
549
-
550
  const previewSvg = getIconSvg(currentEmoji, { class: 'folder-icon-engraved', width: '32', height: '32' });
551
-
552
- // Build icon grid
553
  const iconGridHtml = ICON_NAMES.map(name => `
554
  <div class="icon-grid-item ${name === currentEmoji ? 'selected' : ''}" data-name="${name}">
555
  ${getIconSvg(name, { width: '20', height: '20' })}
556
  </div>
557
  `).join('');
558
-
559
  popover.innerHTML = `
560
  <h3>Ordner Anpassen</h3>
561
  <div style="display: flex; gap: 12px; align-items: center; justify-content: space-between;">
@@ -566,19 +938,16 @@ export class DocumentsView {
566
  </div>
567
  <input type="color" id="popover-color" value="${currentColor}" style="width: 100px;">
568
  </div>
569
-
570
  <div class="icon-picker-grid" style="display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; max-height: 200px; overflow-y: auto; margin-top: 16px; padding-right: 4px;">
571
  ${iconGridHtml}
572
  </div>
573
-
574
  <button id="popover-save" class="liquid-glass" style="padding: 10px; border-radius: 8px; border: none; cursor: pointer; color: white; font-weight: 600; width: 100%; margin-top: 16px;">Speichern</button>
575
  `;
576
 
577
  document.body.appendChild(popover);
578
 
579
  let selectedEmoji = currentEmoji;
580
-
581
- // Handle icon selection
582
  popover.querySelectorAll('.icon-grid-item').forEach(item => {
583
  item.addEventListener('click', () => {
584
  popover.querySelectorAll('.icon-grid-item').forEach(i => i.classList.remove('selected'));
@@ -588,40 +957,32 @@ export class DocumentsView {
588
  });
589
  });
590
 
591
- // Dynamic positioning
592
  let top = rect.bottom + window.scrollY + 10;
593
  let left = rect.left + window.scrollX - (popover.offsetWidth / 2) + 14;
594
-
595
- // Boundary checks
596
  if (left + popover.offsetWidth > window.innerWidth) left = window.innerWidth - popover.offsetWidth - 20;
597
  if (left < 20) left = 20;
598
-
599
  popover.style.top = `${top}px`;
600
  popover.style.left = `${left}px`;
601
 
602
- // Handle Save
603
  popover.querySelector('#popover-save').addEventListener('click', () => {
604
  const newColor = popover.querySelector('#popover-color').value;
605
-
606
  db.saveFolderMetadata(path, selectedEmoji, newColor);
607
  popover.remove();
608
- this.loadFiles(); // Re-render to show changes
609
  });
610
 
611
- // Handle click outside
612
  const closePopover = (e) => {
613
  if (!popover.contains(e.target) && !btnEl.contains(e.target)) {
614
  popover.remove();
615
  document.removeEventListener('click', closePopover);
616
  }
617
  };
618
-
619
- // Delay adding the event listener so it doesn't trigger on the current click
620
  setTimeout(() => {
621
  document.addEventListener('click', closePopover);
622
  }, 10);
623
  }
624
 
 
625
  showCustomConfirm(title, text, onConfirm, confirmText = 'LΓΆschen') {
626
  const overlay = document.createElement('div');
627
  overlay.className = 'custom-modal-overlay';
@@ -636,12 +997,10 @@ export class DocumentsView {
636
  </div>
637
  `;
638
  document.body.appendChild(overlay);
639
-
640
  const close = () => {
641
  overlay.classList.add('fade-out');
642
  setTimeout(() => overlay.remove(), 200);
643
  };
644
-
645
  overlay.querySelector('.cancel').onclick = close;
646
  overlay.querySelector('.confirm').onclick = () => {
647
  onConfirm();
@@ -663,25 +1022,19 @@ export class DocumentsView {
663
  </div>
664
  `;
665
  document.body.appendChild(overlay);
666
-
667
  const input = overlay.querySelector('#custom-prompt-input');
668
  input.focus();
669
-
670
  const close = () => {
671
  overlay.classList.add('fade-out');
672
  setTimeout(() => overlay.remove(), 200);
673
  };
674
-
675
  overlay.querySelector('.cancel').onclick = close;
676
  overlay.querySelector('.confirm').onclick = () => {
677
  onConfirm(input.value);
678
  close();
679
  };
680
  input.addEventListener('keydown', (e) => {
681
- if (e.key === 'Enter') {
682
- onConfirm(input.value);
683
- close();
684
- }
685
  if (e.key === 'Escape') close();
686
  });
687
  }
@@ -695,10 +1048,10 @@ export class DocumentsView {
695
  alert('Error fetching trash items: ' + err.message);
696
  return;
697
  }
698
-
699
  const overlay = document.createElement('div');
700
  overlay.className = 'custom-modal-overlay';
701
-
702
  let listHtml = '';
703
  if (items.length === 0) {
704
  listHtml = '<div style="text-align: center; color: var(--text-secondary); padding: 20px;">Der Papierkorb ist leer.</div>';
@@ -742,15 +1095,15 @@ export class DocumentsView {
742
  </div>
743
  `;
744
  document.body.appendChild(overlay);
745
-
746
  const close = () => {
747
  overlay.classList.add('fade-out');
748
  setTimeout(() => overlay.remove(), 200);
749
  this.loadFiles();
750
  };
751
-
752
  overlay.querySelector('.close-trash-btn').onclick = close;
753
-
754
  const emptyBtn = overlay.querySelector('#empty-trash-btn');
755
  if (emptyBtn) {
756
  emptyBtn.onclick = async () => {
@@ -761,7 +1114,7 @@ export class DocumentsView {
761
  if (item.is_dir === 1) db.deleteFolderMetadata(item.original_path);
762
  }
763
  close();
764
- this.showTrashModal(); // Reopen to show empty state
765
  });
766
  };
767
  }
@@ -772,7 +1125,7 @@ export class DocumentsView {
772
  btn.style.opacity = '0.5';
773
  await fsService.restoreFromTrash(id);
774
  close();
775
- this.showTrashModal(); // Reopen
776
  };
777
  });
778
 
@@ -787,7 +1140,7 @@ export class DocumentsView {
787
  db.removeTrashItem(id);
788
  if (isDir && item) db.deleteFolderMetadata(item.original_path);
789
  close();
790
- this.showTrashModal(); // Reopen
791
  });
792
  };
793
  });
 
6
  constructor(containerId) {
7
  this.container = document.getElementById(containerId);
8
  this.currentPath = ''; // Root is empty string
9
+ this.viewState = 'grid'; // 'grid' or 'detail'
10
+ this._longPressTimer = null;
11
+ this._longPressTarget = null;
12
+ this._isLongPress = false;
13
+ this._cachedFiles = []; // cached file list for current path
14
+ this._filePreviewCache = new Map(); // path β†’ preview HTML
15
  }
16
 
17
  async init() {
 
20
  await this.render();
21
  }
22
 
23
+ // ─── Ambient title text ─────────────────────────────────
24
+ _getAmbientTitle() {
25
+ if (this.currentPath) {
26
+ return this.currentPath.split('/').pop();
27
+ }
28
+ const greetings = [
29
+ 'Was mΓΆchtest du\nlernen?',
30
+ 'Dein Wissen,\norganisiert.',
31
+ 'Bereit zum\nEntdecken?',
32
+ 'Deine Dateien,\nimmer dabei.'
33
+ ];
34
+ return greetings[Math.floor(Math.random() * greetings.length)];
35
+ }
36
+
37
+ // ─── Main Render ─────────────────────────────────
38
  async render() {
39
+ this.viewState = 'grid';
40
  this.container.innerHTML = `
41
+ <div id="vault-glass-wrapper">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
+ <div class="vault-ambient-title">${this._getAmbientTitle()}</div>
44
+
45
+ <div class="vault-header">
46
+ <div class="vault-header-left">
47
+ <h2 class="vault-header-title">
48
  ${this.currentPath ? `
49
+ <button id="doc-back-btn" class="icon-btn" style="width: 32px; height: 32px; background: rgba(255,255,255,0.05); flex-shrink: 0;">
50
  <svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 18 9 12 15 6"></polyline></svg>
51
  </button>
52
+ ` : ''}
53
+ ${this.currentPath ? this.currentPath.split('/').pop() : 'Mein Vault'}
54
  </h2>
55
+ <div class="vault-header-sub">${this.currentPath ? `SchoolMind/${this.currentPath}` : 'Lokaler Vault'}</div>
56
  </div>
57
+ <div class="vault-header-actions">
58
+ <button id="trash-btn" class="vault-action-btn">
59
+ <span style="font-size: 15px;">πŸ—‘οΈ</span>
60
  Papierkorb
61
  </button>
62
+ <button id="new-folder-btn" class="vault-action-btn">
63
+ <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
64
  Neuer Ordner
65
  </button>
66
  </div>
67
  </div>
68
 
69
+ <div id="vault-grid">
70
+ ${Array(6).fill(0).map(() => `<div class="vault-skeleton-item"></div>`).join('')}
 
 
 
 
 
 
71
  </div>
72
 
73
  </div>
 
77
  this.attachEvents();
78
  }
79
 
80
+ // ─── Load & Render Files ─────────────────────────────────
81
  async loadFiles() {
82
  const files = await fsService.readDir(this.currentPath);
83
+ const gridEl = document.getElementById('vault-grid');
84
+ if (!gridEl) return;
 
85
 
86
  if (files.length === 0) {
87
+ gridEl.innerHTML = `
88
+ <div class="vault-empty">
89
+ <div class="vault-empty-icon">πŸ“‚</div>
90
+ <div class="vault-empty-title">Ordner ist leer</div>
91
+ <div class="vault-empty-sub">Die KI kann hier automatisch Berichte ablegen.</div>
92
  </div>
93
  `;
94
  return;
 
101
  return a.name.localeCompare(b.name);
102
  });
103
 
104
+ this._cachedFiles = files;
105
+
106
+ gridEl.innerHTML = files.map((f, idx) => {
107
  const isDir = f.type === 'directory';
108
  const path = this.currentPath ? `${this.currentPath}/${f.name}` : f.name;
109
+ const delay = idx * 40;
110
+
111
  if (isDir) {
112
+ return this._renderFolder(f, path, delay);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  } else {
114
+ return this._renderFile(f, path, delay);
 
115
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  }).join('');
117
 
118
+ // Load async file previews (text/image)
119
+ this._loadFilePreviews(files);
120
+
121
+ // Hover shows delete btn
122
+ gridEl.querySelectorAll('.vault-folder, .vault-file').forEach(item => {
123
  item.addEventListener('mouseenter', () => {
124
+ const btn = item.querySelector('.vault-item-delete');
125
+ if (btn) btn.style.opacity = '1';
126
  });
127
  item.addEventListener('mouseleave', () => {
128
+ const btn = item.querySelector('.vault-item-delete');
129
+ if (btn) btn.style.opacity = '0';
130
  });
131
  });
132
  }
133
 
134
+ // ─── Render a Glass Folder ─────────────────────────────────
135
+ _renderFolder(f, path, delay) {
136
+ const meta = db.getFolderMetadata(path) || { emoji: 'folder', color: '#4285f4' };
137
+ const iconName = ICON_NAMES.includes(meta.emoji) ? meta.emoji : 'folder';
138
+ const color = meta.color || '#4285f4';
139
+
140
+ const svgIconHtml = getIconSvg(iconName, {
141
+ class: 'folder-icon-engraved',
142
+ width: '36',
143
+ height: '36'
144
+ });
145
+
146
+ return `
147
+ <div class="vault-folder vault-item-enter" style="--delay: ${delay}ms" data-name="${f.name}" data-isdir="true" data-path="${path}" data-emoji="${iconName}" data-color="${color}">
148
+ <div class="vault-folder-body">
149
+ <div class="vault-folder-tab"></div>
150
+ <div class="vault-folder-front">
151
+ <div class="vault-folder-icon">${svgIconHtml}</div>
152
+ </div>
153
+ <div class="vault-folder-previews">
154
+ <div class="vault-preview-chip"></div>
155
+ <div class="vault-preview-chip"></div>
156
+ <div class="vault-preview-chip"></div>
157
+ </div>
158
+ </div>
159
+ <div class="vault-folder-name">${f.name}</div>
160
+ <button class="folder-edit-btn" data-path="${path}" data-emoji="${iconName}" data-color="${color}" title="Ordner anpassen">
161
+ <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 20h9"></path><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"></path></svg>
162
+ </button>
163
+ <button class="vault-item-delete" title="LΓΆschen" data-name="${f.name}" data-isdir="true">
164
+ <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>
165
+ </button>
166
+ </div>
167
+ `;
168
+ }
169
+
170
+ // ─── Render a Glass File Card ─────────────────────────────────
171
+ _renderFile(f, path, delay) {
172
+ const ext = f.name.split('.').pop().toLowerCase();
173
+ const isImage = ['jpg', 'jpeg', 'png', 'gif', 'webp'].includes(ext);
174
+ const isPdf = ext === 'pdf';
175
+ const isText = ['md', 'txt', 'csv'].includes(ext);
176
+ const sizeStr = f.size ? Math.round(f.size / 1024) + ' KB' : '';
177
+
178
+ let icon = 'πŸ“„';
179
+ if (isText) icon = 'πŸ“';
180
+ if (isPdf) icon = 'πŸ“•';
181
+ if (isImage) icon = 'πŸ–ΌοΈ';
182
+
183
+ return `
184
+ <div class="vault-file vault-item-enter" style="--delay: ${delay}ms" data-name="${f.name}" data-isdir="false" data-path="${path}">
185
+ <div class="vault-file-body">
186
+ <div id="preview-${path.replace(/[^a-zA-Z0-9]/g, '_')}" class="vault-file-preview-slot">
187
+ <div class="vault-file-icon">${icon}</div>
188
+ </div>
189
+ </div>
190
+ <div class="vault-file-name">${f.name}</div>
191
+ ${sizeStr ? `<div class="vault-file-size">${sizeStr}</div>` : ''}
192
+ <button class="vault-item-delete" title="LΓΆschen" data-name="${f.name}" data-isdir="false">
193
+ <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>
194
+ </button>
195
+ </div>
196
+ `;
197
+ }
198
+
199
+ // ─── Async preview loading ─────────────────────────────────
200
+ async _loadFilePreviews(files) {
201
+ for (const f of files) {
202
+ if (f.type === 'directory') continue;
203
+ const path = this.currentPath ? `${this.currentPath}/${f.name}` : f.name;
204
+ const slotId = `preview-${path.replace(/[^a-zA-Z0-9]/g, '_')}`;
205
+ const slot = document.getElementById(slotId);
206
+ if (!slot) continue;
207
+
208
+ const ext = f.name.split('.').pop().toLowerCase();
209
+ const isImage = ['jpg', 'jpeg', 'png', 'gif', 'webp'].includes(ext);
210
+ const isText = ['md', 'txt', 'csv'].includes(ext);
211
+
212
+ try {
213
+ if (isImage) {
214
+ const base64 = await fsService.readBinaryFile(path);
215
+ if (base64 && slot.isConnected) {
216
+ slot.innerHTML = `<div class="vault-file-preview-img" style="background-image: url('data:image/${ext === 'jpg' ? 'jpeg' : ext};base64,${base64}')"></div><div class="vault-file-icon" style="position:relative;z-index:2;">πŸ–ΌοΈ</div>`;
217
+ }
218
+ } else if (isText) {
219
+ const content = await fsService.readFile(path);
220
+ if (content && slot.isConnected) {
221
+ const preview = content.substring(0, 60).replace(/[#*_\-=]/g, '').replace(/</g, '&lt;');
222
+ slot.innerHTML = `<div class="vault-file-icon">πŸ“</div><div class="vault-file-preview-text">${preview}${content.length > 60 ? '…' : ''}</div>`;
223
+ }
224
+ }
225
+ } catch (e) {
226
+ // Silently fail for previews
227
+ }
228
+ }
229
+ }
230
+
231
+ // ─── Events ─────────────────────────────────
232
  attachEvents() {
233
+ const wrapper = this.container.querySelector('#vault-glass-wrapper');
234
  if (!wrapper) return;
235
+
236
+ // Long-press handling for folders
237
+ this._setupLongPress(wrapper);
238
+
239
  wrapper.addEventListener('click', async (e) => {
240
+ // If the long press just ended, ignore the click
241
+ if (this._isLongPress) {
242
+ this._isLongPress = false;
243
+ return;
244
+ }
245
+
246
+ const folder = e.target.closest('.vault-folder');
247
+ const file = e.target.closest('.vault-file');
248
+ const deleteBtn = e.target.closest('.vault-item-delete');
249
  const editBtn = e.target.closest('.folder-edit-btn');
250
  const backBtn = e.target.closest('#doc-back-btn');
251
  const newFolderBtn = e.target.closest('#new-folder-btn');
 
280
  return;
281
  }
282
 
283
+ if (folder) {
284
+ e.stopPropagation();
285
+ const name = folder.dataset.name;
286
  const path = this.currentPath ? `${this.currentPath}/${name}` : name;
287
+ this._navigateToFolder(path);
288
+ return;
289
+ }
290
 
291
+ if (file) {
292
+ e.stopPropagation();
293
+ const name = file.dataset.name;
294
+ const path = this.currentPath ? `${this.currentPath}/${name}` : name;
295
+ this._openFile(name, path);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  return;
297
  }
298
 
299
  if (backBtn) {
 
300
  const parts = this.currentPath.split('/');
301
  parts.pop();
302
  this.currentPath = parts.join('/');
303
  this.render();
304
+ return;
305
  }
306
 
307
  if (newFolderBtn) {
 
309
  if (folderName && folderName.trim()) {
310
  const cleanName = folderName.trim();
311
  const path = this.currentPath ? `${this.currentPath}/${cleanName}` : cleanName;
 
 
312
  await fsService.createFolder(path);
313
  this.loadFiles();
 
 
314
  try {
315
  const { folderAgent } = await import('../../ai/folder-agent.js?v=2');
316
  const visuals = await folderAgent.generateVisualsForFolder(cleanName);
317
  db.saveFolderMetadata(path, visuals.emoji, visuals.color);
318
+ this.loadFiles();
319
  } catch (err) {
320
  console.error('Background emoji assignment failed:', err);
321
  }
 
325
  });
326
  }
327
 
328
+ // ─── Long-press Setup ─────────────────────────────────
329
+ _setupLongPress(wrapper) {
330
+ let pressTimer = null;
331
+ let pressTarget = null;
332
+ let pressed = false;
333
+
334
+ const onStart = (e) => {
335
+ const folder = e.target.closest('.vault-folder');
336
+ if (!folder || e.target.closest('.folder-edit-btn') || e.target.closest('.vault-item-delete')) return;
337
+
338
+ pressTarget = folder;
339
+ pressed = false;
340
+
341
+ pressTimer = setTimeout(() => {
342
+ pressed = true;
343
+ this._isLongPress = true;
344
+ this._cinematicOpen(folder);
345
+ }, 500);
346
+ };
347
+
348
+ const onEnd = () => {
349
+ if (pressTimer) {
350
+ clearTimeout(pressTimer);
351
+ pressTimer = null;
352
+ }
353
+ if (pressed) {
354
+ // Prevent the click that follows touchend
355
+ this._isLongPress = true;
356
+ }
357
+ pressTarget = null;
358
+ };
359
+
360
+ const onMove = (e) => {
361
+ // Cancel long-press if finger moves
362
+ if (pressTimer) {
363
+ clearTimeout(pressTimer);
364
+ pressTimer = null;
365
+ }
366
+ };
367
+
368
+ wrapper.addEventListener('touchstart', onStart, { passive: true });
369
+ wrapper.addEventListener('touchend', onEnd, { passive: true });
370
+ wrapper.addEventListener('touchmove', onMove, { passive: true });
371
+ wrapper.addEventListener('touchcancel', onEnd, { passive: true });
372
+
373
+ // Mouse fallback
374
+ wrapper.addEventListener('mousedown', onStart);
375
+ wrapper.addEventListener('mouseup', onEnd);
376
+ wrapper.addEventListener('mouseleave', onEnd);
377
+ }
378
+
379
+ // ─── Tap Navigation (quick folder open) ─────────────────
380
+ _navigateToFolder(path) {
381
+ const grid = document.getElementById('vault-grid');
382
+ if (!grid) {
383
+ this.currentPath = path;
384
+ this.render();
385
+ return;
386
+ }
387
+
388
+ // Fade out all items
389
+ const items = grid.querySelectorAll('.vault-folder, .vault-file');
390
+ items.forEach(item => item.classList.add('vault-item-exit'));
391
+
392
+ // After fade-out, navigate
393
+ setTimeout(() => {
394
+ this.currentPath = path;
395
+ this.render();
396
+ }, 200);
397
+ }
398
+
399
+ // ─── Cinematic Long-Press Open ─────────────────────────────
400
+ async _cinematicOpen(folderEl) {
401
+ // Haptic feedback
402
+ if (navigator.vibrate) navigator.vibrate(30);
403
+
404
+ const folderName = folderEl.dataset.name;
405
+ const path = folderEl.dataset.path || (this.currentPath ? `${this.currentPath}/${folderName}` : folderName);
406
+ const grid = document.getElementById('vault-grid');
407
+ if (!grid) return;
408
+
409
+ // 1. Scale up pressed folder
410
+ folderEl.classList.add('vault-folder-pressing');
411
+ folderEl.style.willChange = 'transform, opacity';
412
+
413
+ // 2. Hide all other items
414
+ const allItems = grid.querySelectorAll('.vault-folder, .vault-file');
415
+ allItems.forEach(item => {
416
+ if (item !== folderEl) {
417
+ item.classList.add('vault-item-hide');
418
+ item.style.willChange = 'transform, opacity';
419
+ }
420
+ });
421
+
422
+ // Wait for hide animation
423
+ await this._wait(300);
424
+
425
+ // 3. Get folder's current position, then fly it to detail position
426
+ const rect = folderEl.getBoundingClientRect();
427
+ const targetTop = window.innerHeight * 0.08;
428
+ const targetLeft = window.innerWidth * 0.05;
429
+ const targetWidth = window.innerWidth * 0.45;
430
+
431
+ // Save original styles for back animation
432
+ folderEl._originalRect = rect;
433
+
434
+ // Switch to fixed positioning
435
+ folderEl.style.position = 'fixed';
436
+ folderEl.style.top = rect.top + 'px';
437
+ folderEl.style.left = rect.left + 'px';
438
+ folderEl.style.width = rect.width + 'px';
439
+ folderEl.style.zIndex = '100';
440
+ folderEl.classList.remove('vault-folder-pressing');
441
+
442
+ // Force reflow
443
+ folderEl.offsetHeight;
444
+
445
+ // Animate to detail position
446
+ folderEl.style.transition = 'top 0.45s cubic-bezier(.22,.68,0,1.1), left 0.45s cubic-bezier(.22,.68,0,1.1), width 0.45s cubic-bezier(.22,.68,0,1.1)';
447
+ folderEl.style.top = targetTop + 'px';
448
+ folderEl.style.left = targetLeft + 'px';
449
+ folderEl.style.width = targetWidth + 'px';
450
+
451
+ // 4. Update ambient title
452
+ const titleEl = document.querySelector('.vault-ambient-title');
453
+ if (titleEl) titleEl.textContent = folderName;
454
+
455
+ // 5. Add detail overlay
456
+ const overlay = document.createElement('div');
457
+ overlay.className = 'vault-detail-overlay';
458
+ overlay.addEventListener('click', () => this._cinematicClose(folderEl, allItems));
459
+ document.body.appendChild(overlay);
460
+
461
+ this.viewState = 'detail';
462
+
463
+ // 6. Load child items and display them flying out from the folder
464
+ await this._wait(250);
465
+
466
+ try {
467
+ const childFiles = await fsService.readDir(path);
468
+ childFiles.sort((a, b) => {
469
+ if (a.type === 'directory' && b.type !== 'directory') return -1;
470
+ if (a.type !== 'directory' && b.type === 'directory') return 1;
471
+ return a.name.localeCompare(b.name);
472
+ });
473
+
474
+ if (childFiles.length > 0) {
475
+ // Create a container for child items below the folder
476
+ const childGrid = document.createElement('div');
477
+ childGrid.id = 'vault-detail-children';
478
+ childGrid.style.cssText = `
479
+ position: fixed;
480
+ top: ${targetTop + targetWidth / 1.3 + 30}px;
481
+ left: 16px;
482
+ right: 16px;
483
+ bottom: 120px;
484
+ overflow-y: auto;
485
+ z-index: 101;
486
+ display: grid;
487
+ grid-template-columns: repeat(2, 1fr);
488
+ gap: 14px;
489
+ align-content: flex-start;
490
+ padding: 4px;
491
+ `;
492
+
493
+ childGrid.innerHTML = childFiles.map((cf, idx) => {
494
+ const childPath = `${path}/${cf.name}`;
495
+ const delay = idx * 60;
496
+ if (cf.type === 'directory') {
497
+ return this._renderFolder(cf, childPath, 0).replace('vault-item-enter', `vault-child-enter`).replace('--delay: 0ms', `--delay: ${delay}ms`);
498
+ } else {
499
+ return this._renderFile(cf, childPath, 0).replace('vault-item-enter', `vault-child-enter`).replace('--delay: 0ms', `--delay: ${delay}ms`);
500
+ }
501
+ }).join('');
502
+
503
+ document.body.appendChild(childGrid);
504
+
505
+ // Load previews for child files
506
+ this._loadFilePreviewsInContainer(childFiles, path, childGrid);
507
+
508
+ // Attach events to child items
509
+ this._attachDetailChildEvents(childGrid, path, folderEl, allItems);
510
+ }
511
+ } catch (err) {
512
+ console.error('Error loading children in detail view:', err);
513
+ }
514
+ }
515
+
516
+ // ─── Cinematic Close (back to grid) ─────────────────────────
517
+ async _cinematicClose(folderEl, allItems) {
518
+ // 1. Fly child items back
519
+ const childGrid = document.getElementById('vault-detail-children');
520
+ if (childGrid) {
521
+ const children = childGrid.querySelectorAll('.vault-folder, .vault-file');
522
+ children.forEach((child, idx) => {
523
+ child.style.setProperty('--delay', `${(children.length - 1 - idx) * 40}ms`);
524
+ child.classList.remove('vault-child-enter');
525
+ child.classList.add('vault-child-exit');
526
+ child.style.willChange = 'transform, opacity';
527
+ });
528
+ await this._wait(300);
529
+ childGrid.remove();
530
+ }
531
+
532
+ // 2. Remove overlay
533
+ document.querySelectorAll('.vault-detail-overlay').forEach(o => o.remove());
534
+
535
+ // 3. Animate folder back to original position
536
+ const origRect = folderEl._originalRect;
537
+ if (origRect) {
538
+ folderEl.style.top = origRect.top + 'px';
539
+ folderEl.style.left = origRect.left + 'px';
540
+ folderEl.style.width = origRect.width + 'px';
541
+ }
542
+
543
+ await this._wait(450);
544
+
545
+ // 4. Reset folder styles
546
+ folderEl.style.position = '';
547
+ folderEl.style.top = '';
548
+ folderEl.style.left = '';
549
+ folderEl.style.width = '';
550
+ folderEl.style.zIndex = '';
551
+ folderEl.style.transition = '';
552
+ folderEl.style.willChange = '';
553
+
554
+ // 5. Bring back other items
555
+ allItems.forEach((item, idx) => {
556
+ if (item !== folderEl) {
557
+ item.classList.remove('vault-item-hide');
558
+ item.style.setProperty('--delay', `${idx * 30}ms`);
559
+ item.classList.add('vault-item-return');
560
+ item.style.willChange = 'transform, opacity';
561
+ }
562
+ });
563
+
564
+ // 6. Restore title
565
+ const titleEl = document.querySelector('.vault-ambient-title');
566
+ if (titleEl) titleEl.textContent = this._getAmbientTitle();
567
+
568
+ this.viewState = 'grid';
569
+
570
+ // Cleanup will-change after animation
571
+ setTimeout(() => {
572
+ allItems.forEach(item => {
573
+ item.classList.remove('vault-item-return');
574
+ item.style.willChange = '';
575
+ });
576
+ }, 500);
577
+ }
578
+
579
+ // ─── Attach events to detail-view children ───────────────
580
+ _attachDetailChildEvents(childGrid, parentPath, folderEl, allItems) {
581
+ childGrid.addEventListener('click', async (e) => {
582
+ const folder = e.target.closest('.vault-folder');
583
+ const file = e.target.closest('.vault-file');
584
+ const deleteBtn = e.target.closest('.vault-item-delete');
585
+ const editBtn = e.target.closest('.folder-edit-btn');
586
+
587
+ if (deleteBtn) {
588
+ e.stopPropagation();
589
+ const name = deleteBtn.dataset.name;
590
+ const isDir = deleteBtn.dataset.isdir === 'true';
591
+ this.showCustomConfirm(
592
+ isDir ? 'In den Papierkorb verschieben' : 'Dokument in den Papierkorb',
593
+ `MΓΆchtest du "${name}" wirklich in den Papierkorb verschieben?`,
594
+ async () => {
595
+ const path = `${parentPath}/${name}`;
596
+ await fsService.moveToTrash(path, isDir);
597
+ // Refresh: close and reopen
598
+ await this._cinematicClose(folderEl, allItems);
599
+ },
600
+ 'Verschieben'
601
+ );
602
+ return;
603
+ }
604
+
605
+ if (editBtn) {
606
+ e.stopPropagation();
607
+ this.showFolderPopover(editBtn);
608
+ return;
609
+ }
610
+
611
+ if (folder) {
612
+ e.stopPropagation();
613
+ const name = folder.dataset.name;
614
+ // Close detail, navigate to sub-folder
615
+ await this._cinematicClose(folderEl, allItems);
616
+ this.currentPath = `${parentPath}/${name}`;
617
+ this.render();
618
+ return;
619
+ }
620
+
621
+ if (file) {
622
+ e.stopPropagation();
623
+ const name = file.dataset.name;
624
+ const path = `${parentPath}/${name}`;
625
+ this._openFile(name, path);
626
+ return;
627
+ }
628
+ });
629
+
630
+ // Hover shows delete btn
631
+ childGrid.querySelectorAll('.vault-folder, .vault-file').forEach(item => {
632
+ item.addEventListener('mouseenter', () => {
633
+ const btn = item.querySelector('.vault-item-delete');
634
+ if (btn) btn.style.opacity = '1';
635
+ });
636
+ item.addEventListener('mouseleave', () => {
637
+ const btn = item.querySelector('.vault-item-delete');
638
+ if (btn) btn.style.opacity = '0';
639
+ });
640
+ });
641
+ }
642
+
643
+ // ─── Load previews for child items in container ─────────
644
+ async _loadFilePreviewsInContainer(files, parentPath, container) {
645
+ for (const f of files) {
646
+ if (f.type === 'directory') continue;
647
+ const path = `${parentPath}/${f.name}`;
648
+ const slotId = `preview-${path.replace(/[^a-zA-Z0-9]/g, '_')}`;
649
+ const slot = container.querySelector(`#${slotId}`);
650
+ if (!slot) continue;
651
+
652
+ const ext = f.name.split('.').pop().toLowerCase();
653
+ const isImage = ['jpg', 'jpeg', 'png', 'gif', 'webp'].includes(ext);
654
+ const isText = ['md', 'txt', 'csv'].includes(ext);
655
+
656
+ try {
657
+ if (isImage) {
658
+ const base64 = await fsService.readBinaryFile(path);
659
+ if (base64 && slot.isConnected) {
660
+ slot.innerHTML = `<div class="vault-file-preview-img" style="background-image: url('data:image/${ext === 'jpg' ? 'jpeg' : ext};base64,${base64}')"></div><div class="vault-file-icon" style="position:relative;z-index:2;">πŸ–ΌοΈ</div>`;
661
+ }
662
+ } else if (isText) {
663
+ const content = await fsService.readFile(path);
664
+ if (content && slot.isConnected) {
665
+ const preview = content.substring(0, 60).replace(/[#*_\-=]/g, '').replace(/</g, '&lt;');
666
+ slot.innerHTML = `<div class="vault-file-icon">πŸ“</div><div class="vault-file-preview-text">${preview}${content.length > 60 ? '…' : ''}</div>`;
667
+ }
668
+ }
669
+ } catch (e) { /* Silently fail */ }
670
+ }
671
+ }
672
+
673
+ // ─── Open File ─────────────────────────────────
674
+ async _openFile(name, path) {
675
+ if (name.endsWith('.md') || name.endsWith('.txt') || name.endsWith('.csv')) {
676
+ const content = await fsService.readFile(path);
677
+ if (content && window.openPdfModal) {
678
+ window.openPdfModal(content);
679
+ }
680
+ } else if (name.toLowerCase().endsWith('.pdf')) {
681
+ const base64 = await fsService.readBinaryFile(path);
682
+ if (base64) {
683
+ this._openPdfViewer(base64);
684
+ }
685
+ }
686
+ }
687
+
688
+ // ─── PDF Viewer (extracted, unchanged logic) ─────────────
689
+ _openPdfViewer(base64) {
690
+ const viewerWrapper = document.createElement('div');
691
+ viewerWrapper.id = 'pdf-viewer-wrapper';
692
+ viewerWrapper.style.position = 'fixed';
693
+ viewerWrapper.style.top = '0'; viewerWrapper.style.left = '0'; viewerWrapper.style.width = '100vw'; viewerWrapper.style.height = '100vh';
694
+ viewerWrapper.style.zIndex = '999999';
695
+ viewerWrapper.style.backgroundColor = '#1a1a1a';
696
+ viewerWrapper.style.overflow = 'auto';
697
+ viewerWrapper.style.boxSizing = 'border-box';
698
+ viewerWrapper.style.padding = '80px 20px';
699
+
700
+ const textSelectStyle = document.createElement('style');
701
+ textSelectStyle.textContent = `
702
+ #pdf-viewer-wrapper, #pdf-viewer-wrapper * {
703
+ -webkit-user-select: text !important;
704
+ user-select: text !important;
705
+ -webkit-touch-callout: default !important;
706
+ }
707
+ #pdf-viewer-wrapper .textLayer span {
708
+ color: rgba(0,0,0,0.01) !important;
709
+ pointer-events: all !important;
710
+ cursor: text !important;
711
+ }
712
+ #pdf-viewer-wrapper ::selection {
713
+ background: rgba(0, 120, 255, 0.3) !important;
714
+ }
715
+ `;
716
+ viewerWrapper.appendChild(textSelectStyle);
717
+
718
+ const pdfContainer = document.createElement('div');
719
+ pdfContainer.style.display = 'block';
720
+ pdfContainer.style.zoom = '1.0';
721
+ pdfContainer.style.transformOrigin = '0 0';
722
+ viewerWrapper.appendChild(pdfContainer);
723
+
724
+ // Close Button
725
+ const closeBtn = document.createElement('button');
726
+ closeBtn.innerHTML = 'ZurΓΌck';
727
+ closeBtn.style.position = 'fixed';
728
+ closeBtn.style.top = 'env(safe-area-inset-top, 20px)';
729
+ closeBtn.style.right = '20px';
730
+ closeBtn.style.padding = '8px 16px';
731
+ closeBtn.style.background = 'rgba(0,0,0,0.5)';
732
+ closeBtn.style.color = '#fff';
733
+ closeBtn.style.border = '1px solid rgba(255,255,255,0.2)';
734
+ closeBtn.style.borderRadius = '12px';
735
+ closeBtn.style.cursor = 'pointer';
736
+ closeBtn.style.backdropFilter = 'blur(10px)';
737
+ closeBtn.style.fontWeight = '600';
738
+ closeBtn.style.boxShadow = '0 4px 12px rgba(0,0,0,0.5)';
739
+ closeBtn.style.zIndex = '1000000';
740
+
741
+ // Zoom Controls
742
+ const zoomControls = document.createElement('div');
743
+ zoomControls.style.position = 'fixed';
744
+ zoomControls.style.bottom = '20px';
745
+ zoomControls.style.left = '50%';
746
+ zoomControls.style.transform = 'translateX(-50%)';
747
+ zoomControls.style.display = 'flex';
748
+ zoomControls.style.gap = '12px';
749
+ zoomControls.style.background = 'rgba(30, 30, 35, 0.9)';
750
+ zoomControls.style.padding = '8px';
751
+ zoomControls.style.borderRadius = '16px';
752
+ zoomControls.style.border = '1px solid rgba(255,255,255,0.1)';
753
+ zoomControls.style.backdropFilter = 'blur(10px)';
754
+ zoomControls.style.zIndex = '1000000';
755
+ zoomControls.style.boxShadow = '0 8px 24px rgba(0,0,0,0.5)';
756
+
757
+ let currentZoom = 1.0;
758
+ const updateZoom = (newZoom) => {
759
+ if (newZoom < 1.0) newZoom = 1.0;
760
+ if (newZoom > 4.0) newZoom = 4.0;
761
+ currentZoom = newZoom;
762
+ pdfContainer.style.zoom = currentZoom;
763
+ };
764
+
765
+ const zoomToPoint = (delta, centerX, centerY) => {
766
+ const pointX = (centerX + viewerWrapper.scrollLeft) / currentZoom;
767
+ const pointY = (centerY + viewerWrapper.scrollTop) / currentZoom;
768
+ updateZoom(currentZoom + delta);
769
+ viewerWrapper.scrollLeft = (pointX * currentZoom) - centerX;
770
+ viewerWrapper.scrollTop = (pointY * currentZoom) - centerY;
771
+ };
772
+
773
+ const zoomOutBtn = document.createElement('button');
774
+ zoomOutBtn.innerHTML = '<svg viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><line x1="5" y1="12" x2="19" y2="12"></line></svg>';
775
+ zoomOutBtn.style.background = 'transparent'; zoomOutBtn.style.border = 'none'; zoomOutBtn.style.color = 'white'; zoomOutBtn.style.cursor = 'pointer'; zoomOutBtn.style.padding = '8px';
776
+ zoomOutBtn.onclick = () => zoomToPoint(-0.5, viewerWrapper.clientWidth / 2, viewerWrapper.clientHeight / 2);
777
+
778
+ const zoomInBtn = document.createElement('button');
779
+ zoomInBtn.innerHTML = '<svg viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>';
780
+ zoomInBtn.style.background = 'transparent'; zoomInBtn.style.border = 'none'; zoomInBtn.style.color = 'white'; zoomInBtn.style.cursor = 'pointer'; zoomInBtn.style.padding = '8px';
781
+ zoomInBtn.onclick = () => zoomToPoint(0.5, viewerWrapper.clientWidth / 2, viewerWrapper.clientHeight / 2);
782
+
783
+ zoomControls.appendChild(zoomOutBtn);
784
+ zoomControls.appendChild(zoomInBtn);
785
+
786
+ // Pinch-To-Zoom
787
+ let initialDistance = 0;
788
+ let initialZoom = 1.0;
789
+ let pinchPoint = { x: 0, y: 0 };
790
+
791
+ viewerWrapper.addEventListener('touchstart', (e) => {
792
+ if (e.touches.length === 2) {
793
+ const t1 = e.touches[0]; const t2 = e.touches[1];
794
+ const dx = t1.clientX - t2.clientX; const dy = t1.clientY - t2.clientY;
795
+ initialDistance = Math.sqrt(dx * dx + dy * dy);
796
+ initialZoom = currentZoom;
797
+ const centerX = (t1.clientX + t2.clientX) / 2;
798
+ const centerY = (t1.clientY + t2.clientY) / 2;
799
+ pinchPoint.x = (centerX + viewerWrapper.scrollLeft) / currentZoom;
800
+ pinchPoint.y = (centerY + viewerWrapper.scrollTop) / currentZoom;
801
+ }
802
+ });
803
+ viewerWrapper.addEventListener('touchmove', (e) => {
804
+ if (e.touches.length === 2) {
805
+ e.preventDefault();
806
+ const t1 = e.touches[0]; const t2 = e.touches[1];
807
+ const dx = t1.clientX - t2.clientX; const dy = t1.clientY - t2.clientY;
808
+ const dist = Math.sqrt(dx * dx + dy * dy);
809
+ const newZoom = initialZoom * (dist / initialDistance);
810
+ updateZoom(newZoom);
811
+ const centerX = (t1.clientX + t2.clientX) / 2;
812
+ const centerY = (t1.clientY + t2.clientY) / 2;
813
+ viewerWrapper.scrollLeft = (pinchPoint.x * currentZoom) - centerX;
814
+ viewerWrapper.scrollTop = (pinchPoint.y * currentZoom) - centerY;
815
+ }
816
+ }, { passive: false });
817
+
818
+ closeBtn.onclick = () => {
819
+ if (viewerWrapper.parentNode) document.body.removeChild(viewerWrapper);
820
+ };
821
+
822
+ viewerWrapper.appendChild(closeBtn);
823
+ viewerWrapper.appendChild(zoomControls);
824
+ document.body.appendChild(viewerWrapper);
825
+
826
+ const loadingText = document.createElement('div');
827
+ loadingText.innerHTML = 'Lade PDF...';
828
+ loadingText.style.color = '#fff';
829
+ loadingText.style.fontFamily = 'sans-serif';
830
+ loadingText.style.textAlign = 'center';
831
+ pdfContainer.appendChild(loadingText);
832
+
833
+ const loadPdfJs = () => new Promise((resolve, reject) => {
834
+ const link = document.createElement('link');
835
+ link.rel = 'stylesheet';
836
+ link.href = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf_viewer.min.css';
837
+ document.head.appendChild(link);
838
+ if (window['pdfjs-dist/build/pdf']) return resolve(window['pdfjs-dist/build/pdf']);
839
+ const script = document.createElement('script');
840
+ script.src = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js';
841
+ script.onload = () => resolve(window['pdfjs-dist/build/pdf']);
842
+ script.onerror = reject;
843
+ document.head.appendChild(script);
844
+ });
845
+
846
+ (async () => {
847
+ try {
848
+ const pdfjsLib = await loadPdfJs();
849
+ pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js';
850
+ const pdfData = atob(base64);
851
+ const uint8Array = new Uint8Array(pdfData.length);
852
+ for (let i = 0; i < pdfData.length; i++) {
853
+ uint8Array[i] = pdfData.charCodeAt(i);
854
+ }
855
+ const loadingTask = pdfjsLib.getDocument({ data: uint8Array });
856
+ const pdf = await loadingTask.promise;
857
+ if (loadingText && loadingText.parentNode) {
858
+ loadingText.parentNode.removeChild(loadingText);
859
+ }
860
+ for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) {
861
+ const page = await pdf.getPage(pageNum);
862
+ const unscaledViewport = page.getViewport({ scale: 1.0 });
863
+ const screenWidth = window.innerWidth - 40;
864
+ const baseScale = screenWidth / unscaledViewport.width;
865
+ const renderScale = baseScale * 4;
866
+ const cssViewport = page.getViewport({ scale: baseScale });
867
+ const renderViewport = page.getViewport({ scale: renderScale });
868
+ const pageContainerDiv = document.createElement('div');
869
+ pageContainerDiv.style.position = 'relative';
870
+ pageContainerDiv.style.width = cssViewport.width + 'px';
871
+ pageContainerDiv.style.height = cssViewport.height + 'px';
872
+ pageContainerDiv.style.marginBottom = '24px';
873
+ pageContainerDiv.style.boxShadow = '0 8px 24px rgba(0,0,0,0.5)';
874
+ pageContainerDiv.style.borderRadius = '8px';
875
+ pageContainerDiv.style.backgroundColor = 'white';
876
+ const canvas = document.createElement('canvas');
877
+ const context = canvas.getContext('2d');
878
+ canvas.width = renderViewport.width;
879
+ canvas.height = renderViewport.height;
880
+ canvas.style.width = cssViewport.width + 'px';
881
+ canvas.style.height = cssViewport.height + 'px';
882
+ canvas.style.display = 'block';
883
+ canvas.style.borderRadius = '8px';
884
+ pageContainerDiv.appendChild(canvas);
885
+ const textLayerDiv = document.createElement('div');
886
+ textLayerDiv.setAttribute('class', 'textLayer selectable-text');
887
+ textLayerDiv.style.width = cssViewport.width + 'px';
888
+ textLayerDiv.style.height = cssViewport.height + 'px';
889
+ textLayerDiv.style.position = 'absolute';
890
+ textLayerDiv.style.top = '0';
891
+ textLayerDiv.style.left = '0';
892
+ textLayerDiv.style.setProperty('--scale-factor', cssViewport.scale);
893
+ pageContainerDiv.appendChild(textLayerDiv);
894
+ pdfContainer.appendChild(pageContainerDiv);
895
+ const renderTask = page.render({ canvasContext: context, viewport: renderViewport });
896
+ await renderTask.promise;
897
+ const textContent = await page.getTextContent();
898
+ pdfjsLib.renderTextLayer({ textContentSource: textContent, container: textLayerDiv, viewport: cssViewport, textDivs: [] });
899
+ }
900
+ } catch (err) {
901
+ if (loadingText) loadingText.innerHTML = 'Fehler beim Laden der PDF.';
902
+ console.error(err);
903
+ }
904
+ })();
905
+ }
906
+
907
+ // ─── Utility ─────────────────────────────────
908
+ _wait(ms) {
909
+ return new Promise(resolve => setTimeout(resolve, ms));
910
+ }
911
+
912
+ // ─── Folder Popover (unchanged) ─────────────────────────
913
  showFolderPopover(btnEl) {
 
914
  document.querySelectorAll('.folder-popover').forEach(p => p.remove());
915
 
916
  const path = btnEl.dataset.path;
 
918
  const currentColor = btnEl.dataset.color;
919
  const popover = document.createElement('div');
920
  popover.className = 'folder-popover';
921
+
 
922
  const rect = btnEl.getBoundingClientRect();
 
923
  const previewSvg = getIconSvg(currentEmoji, { class: 'folder-icon-engraved', width: '32', height: '32' });
924
+
 
925
  const iconGridHtml = ICON_NAMES.map(name => `
926
  <div class="icon-grid-item ${name === currentEmoji ? 'selected' : ''}" data-name="${name}">
927
  ${getIconSvg(name, { width: '20', height: '20' })}
928
  </div>
929
  `).join('');
930
+
931
  popover.innerHTML = `
932
  <h3>Ordner Anpassen</h3>
933
  <div style="display: flex; gap: 12px; align-items: center; justify-content: space-between;">
 
938
  </div>
939
  <input type="color" id="popover-color" value="${currentColor}" style="width: 100px;">
940
  </div>
 
941
  <div class="icon-picker-grid" style="display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; max-height: 200px; overflow-y: auto; margin-top: 16px; padding-right: 4px;">
942
  ${iconGridHtml}
943
  </div>
 
944
  <button id="popover-save" class="liquid-glass" style="padding: 10px; border-radius: 8px; border: none; cursor: pointer; color: white; font-weight: 600; width: 100%; margin-top: 16px;">Speichern</button>
945
  `;
946
 
947
  document.body.appendChild(popover);
948
 
949
  let selectedEmoji = currentEmoji;
950
+
 
951
  popover.querySelectorAll('.icon-grid-item').forEach(item => {
952
  item.addEventListener('click', () => {
953
  popover.querySelectorAll('.icon-grid-item').forEach(i => i.classList.remove('selected'));
 
957
  });
958
  });
959
 
 
960
  let top = rect.bottom + window.scrollY + 10;
961
  let left = rect.left + window.scrollX - (popover.offsetWidth / 2) + 14;
 
 
962
  if (left + popover.offsetWidth > window.innerWidth) left = window.innerWidth - popover.offsetWidth - 20;
963
  if (left < 20) left = 20;
 
964
  popover.style.top = `${top}px`;
965
  popover.style.left = `${left}px`;
966
 
 
967
  popover.querySelector('#popover-save').addEventListener('click', () => {
968
  const newColor = popover.querySelector('#popover-color').value;
 
969
  db.saveFolderMetadata(path, selectedEmoji, newColor);
970
  popover.remove();
971
+ this.loadFiles();
972
  });
973
 
 
974
  const closePopover = (e) => {
975
  if (!popover.contains(e.target) && !btnEl.contains(e.target)) {
976
  popover.remove();
977
  document.removeEventListener('click', closePopover);
978
  }
979
  };
 
 
980
  setTimeout(() => {
981
  document.addEventListener('click', closePopover);
982
  }, 10);
983
  }
984
 
985
+ // ─── Modals (unchanged) ─────────────────────────────────
986
  showCustomConfirm(title, text, onConfirm, confirmText = 'LΓΆschen') {
987
  const overlay = document.createElement('div');
988
  overlay.className = 'custom-modal-overlay';
 
997
  </div>
998
  `;
999
  document.body.appendChild(overlay);
 
1000
  const close = () => {
1001
  overlay.classList.add('fade-out');
1002
  setTimeout(() => overlay.remove(), 200);
1003
  };
 
1004
  overlay.querySelector('.cancel').onclick = close;
1005
  overlay.querySelector('.confirm').onclick = () => {
1006
  onConfirm();
 
1022
  </div>
1023
  `;
1024
  document.body.appendChild(overlay);
 
1025
  const input = overlay.querySelector('#custom-prompt-input');
1026
  input.focus();
 
1027
  const close = () => {
1028
  overlay.classList.add('fade-out');
1029
  setTimeout(() => overlay.remove(), 200);
1030
  };
 
1031
  overlay.querySelector('.cancel').onclick = close;
1032
  overlay.querySelector('.confirm').onclick = () => {
1033
  onConfirm(input.value);
1034
  close();
1035
  };
1036
  input.addEventListener('keydown', (e) => {
1037
+ if (e.key === 'Enter') { onConfirm(input.value); close(); }
 
 
 
1038
  if (e.key === 'Escape') close();
1039
  });
1040
  }
 
1048
  alert('Error fetching trash items: ' + err.message);
1049
  return;
1050
  }
1051
+
1052
  const overlay = document.createElement('div');
1053
  overlay.className = 'custom-modal-overlay';
1054
+
1055
  let listHtml = '';
1056
  if (items.length === 0) {
1057
  listHtml = '<div style="text-align: center; color: var(--text-secondary); padding: 20px;">Der Papierkorb ist leer.</div>';
 
1095
  </div>
1096
  `;
1097
  document.body.appendChild(overlay);
1098
+
1099
  const close = () => {
1100
  overlay.classList.add('fade-out');
1101
  setTimeout(() => overlay.remove(), 200);
1102
  this.loadFiles();
1103
  };
1104
+
1105
  overlay.querySelector('.close-trash-btn').onclick = close;
1106
+
1107
  const emptyBtn = overlay.querySelector('#empty-trash-btn');
1108
  if (emptyBtn) {
1109
  emptyBtn.onclick = async () => {
 
1114
  if (item.is_dir === 1) db.deleteFolderMetadata(item.original_path);
1115
  }
1116
  close();
1117
+ this.showTrashModal();
1118
  });
1119
  };
1120
  }
 
1125
  btn.style.opacity = '0.5';
1126
  await fsService.restoreFromTrash(id);
1127
  close();
1128
+ this.showTrashModal();
1129
  };
1130
  });
1131
 
 
1140
  db.removeTrashItem(id);
1141
  if (isDir && item) db.deleteFolderMetadata(item.original_path);
1142
  close();
1143
+ this.showTrashModal();
1144
  });
1145
  };
1146
  });