Repository navigation
Expand file tree
/
Copy pathDocMask.html
More file actions
2669 lines (2350 loc) · 135 KB
/
Copy pathDocMask.html
File metadata and controls
2669 lines (2350 loc) · 135 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="pl">
<head>
<!--
==========================================================================
@project DocMask — Lokalna Anonimizacja Dokumentów
@version v6.0
@author lebinho (https://github.com/lebinho)
@repository https://github.com/lebinho/DocMask
@description Narzędzie typu Single-File Web App do 100% lokalnego
wykrywania i maskowania danych wrażliwych w plikach PDF,
DOCX, skanach oraz zdjęciach dokumentów.
==========================================================================
-->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="lebinho">
<title>DocMask v6 — Lokalna Anonimizacja Dokumentów</title>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- PDF.js do lokalnego renderowania i analizy struktury plików PDF -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"></script>
<!-- Tesseract.js do lokalnego rozpoznawania tekstu (OCR) ze zdjęć i skanów -->
<script src="https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js"></script>
<!-- jsPDF do generowania spłaszczonych oraz hybrydowych plików PDF -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<!-- JSZip do lokalnego odczytu i budowania plików Microsoft Word (.docx) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
body {
font-family: 'Inter', sans-serif;
background-color: #f1f5f9;
color: #0f172a;
}
.canvas-page-wrapper {
position: relative;
display: inline-block;
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
border-radius: 6px;
overflow: hidden;
background: #ffffff;
margin-bottom: 1.5rem;
user-select: none;
touch-action: none;
}
.canvas-page-wrapper canvas {
display: block;
max-width: 100%;
height: auto;
}
.redaction-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
cursor: crosshair;
}
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: #e2e8f0;
}
::-webkit-scrollbar-thumb {
background: #94a3b8;
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: #64748b;
}
</style>
</head>
<body class="min-h-screen flex flex-col">
<!-- Górny pasek nawigacyjny DocMask -->
<header class="bg-slate-900 text-white border-b border-slate-800 sticky top-0 z-30">
<div class="max-w-7xl mx-auto px-4 py-3 flex flex-wrap items-center justify-between gap-3">
<div class="flex items-center gap-3">
<div class="w-9 h-9 rounded-lg bg-emerald-600 flex items-center justify-center font-bold text-lg shadow">
🛡️
</div>
<div>
<div class="flex items-center gap-2">
<h1 class="font-bold text-base sm:text-lg leading-tight tracking-tight">DocMask</h1>
<span class="px-2 py-0.5 text-[11px] font-mono font-semibold bg-emerald-900/80 text-emerald-300 border border-emerald-700 rounded-md">
v6
</span>
<span class="hidden sm:inline-block text-xs text-slate-400 font-medium">
— Lokalna Anonimizacja Dokumentów
</span>
</div>
<p class="text-xs text-slate-400">100% prywatności • Przetwarzanie wyłącznie w Twojej przeglądarce (bez wysyłania do sieci)</p>
</div>
</div>
<div class="flex items-center gap-2 flex-wrap">
<a href="https://github.com/lebinho/DocMask" target="_blank" rel="noopener noreferrer"
class="px-3 py-1.5 text-xs font-medium bg-slate-800 hover:bg-slate-700 text-slate-200 rounded-lg border border-slate-700 transition flex items-center gap-1.5"
title="Otwórz repozytorium projektu DocMask na GitHub">
<span>🐙 GitHub</span>
</a>
<button id="btnDownloadAppHtml" class="px-3 py-1.5 text-xs font-medium bg-slate-800 hover:bg-slate-700 text-emerald-300 rounded-lg border border-slate-700 transition" title="Pobierz aplikację jako pojedynczy plik DocMask.html">
💾 Pobierz aplikację (DocMask.html)
</button>
<button id="btnLoadSample" class="px-3 py-1.5 text-xs font-medium bg-slate-800 hover:bg-slate-700 text-slate-200 rounded-lg border border-slate-700 transition">
📄 Przykładowa umowa (Test)
</button>
<label for="fileInput" class="cursor-pointer px-4 py-1.5 text-xs sm:text-sm font-semibold bg-emerald-600 hover:bg-emerald-500 text-white rounded-lg shadow transition flex items-center gap-1.5">
<span>📂 Wgraj plik (PDF / DOCX / Zdjęcie / TXT)</span>
</label>
<input id="fileInput" type="file" accept=".pdf,.docx,image/png,image/jpeg,image/webp,.txt" class="hidden" />
</div>
</div>
</header>
<!-- Główna zawartość aplikacji -->
<main class="flex-1 max-w-7xl w-full mx-auto px-4 py-5 grid grid-cols-1 lg:grid-cols-12 gap-6">
<!-- LEWY PANEL: Reguły maskowania, OCR i eksport -->
<aside class="lg:col-span-4 space-y-4">
<!-- Karta 1: Automatyczne wykrywanie danych wrażliwych -->
<div class="bg-white rounded-xl border border-slate-200 p-4 shadow-sm">
<div class="flex items-center justify-between mb-3">
<h2 class="font-bold text-sm uppercase tracking-wider text-slate-700">1. Automatyczne wykrywanie</h2>
<span id="badgeFoundCount" class="px-2.5 py-0.5 text-xs font-bold bg-slate-100 text-slate-800 rounded-full">
0 zamaskowanych
</span>
</div>
<p class="text-xs text-slate-500 mb-3">
Zaznacz kategorie danych, które mają zostać automatycznie zamaskowane w całym dokumencie:
</p>
<div class="space-y-2 text-sm">
<label class="flex items-center gap-2.5 p-1.5 rounded-lg hover:bg-slate-50 cursor-pointer">
<input type="checkbox" class="rule-checkbox w-4 h-4 accent-slate-900 rounded" value="pesel" checked>
<span class="font-medium text-slate-800">Numer PESEL</span>
<span class="ml-auto text-xs text-slate-400">11 cyfr</span>
</label>
<label class="flex items-center gap-2.5 p-1.5 rounded-lg hover:bg-slate-50 cursor-pointer">
<input type="checkbox" class="rule-checkbox w-4 h-4 accent-slate-900 rounded" value="idcard" checked>
<span class="font-medium text-slate-800">Dowód osobisty / Paszport</span>
<span class="ml-auto text-xs text-slate-400">np. ABC 123456</span>
</label>
<label class="flex items-center gap-2.5 p-1.5 rounded-lg hover:bg-slate-50 cursor-pointer">
<input type="checkbox" class="rule-checkbox w-4 h-4 accent-slate-900 rounded" value="nip_regon" checked>
<span class="font-medium text-slate-800">NIP / REGON / KRS</span>
<span class="ml-auto text-xs text-slate-400">Firmowe i osobiste</span>
</label>
<label class="flex items-center gap-2.5 p-1.5 rounded-lg hover:bg-slate-50 cursor-pointer">
<input type="checkbox" class="rule-checkbox w-4 h-4 accent-slate-900 rounded" value="iban" checked>
<span class="font-medium text-slate-800">Konta bankowe (NRB / IBAN)</span>
<span class="ml-auto text-xs text-slate-400">26 cyfr</span>
</label>
<label class="flex items-center gap-2.5 p-1.5 rounded-lg hover:bg-slate-50 cursor-pointer">
<input type="checkbox" class="rule-checkbox w-4 h-4 accent-slate-900 rounded" value="phone" checked>
<span class="font-medium text-slate-800">Numery telefonów</span>
<span class="ml-auto text-xs text-slate-400">+48 / 9 cyfr</span>
</label>
<label class="flex items-center gap-2.5 p-1.5 rounded-lg hover:bg-slate-50 cursor-pointer">
<input type="checkbox" class="rule-checkbox w-4 h-4 accent-slate-900 rounded" value="email" checked>
<span class="font-medium text-slate-800">Adresy e-mail</span>
<span class="ml-auto text-xs text-slate-400">np. jan@domena.pl</span>
</label>
<label class="flex items-center gap-2.5 p-1.5 rounded-lg hover:bg-slate-50 cursor-pointer">
<input type="checkbox" class="rule-checkbox w-4 h-4 accent-slate-900 rounded" value="address" checked>
<span class="font-medium text-slate-800">Adresy i kody pocztowe</span>
<span class="ml-auto text-xs text-slate-400">ul., 00-000, nr</span>
</label>
<label class="flex items-center gap-2.5 p-1.5 rounded-lg hover:bg-slate-50 cursor-pointer">
<input type="checkbox" class="rule-checkbox w-4 h-4 accent-slate-900 rounded" value="names" checked>
<span class="font-medium text-slate-800">Imiona i nazwiska</span>
<span class="ml-auto text-xs text-slate-400">Także WIELKIE LITERY i 2-członowe</span>
</label>
<label class="flex items-center gap-2.5 p-1.5 rounded-lg hover:bg-slate-50 cursor-pointer">
<input type="checkbox" class="rule-checkbox w-4 h-4 accent-slate-900 rounded" value="vehicle_policy" checked>
<span class="font-medium text-slate-800">Polisa / VIN / KW / Faktura / ID</span>
<span class="ml-auto text-xs text-slate-400">OC/AC, KW, nr klienta/faktury</span>
</label>
<label class="flex items-center gap-2.5 p-1.5 rounded-lg hover:bg-slate-50 cursor-pointer">
<input type="checkbox" class="rule-checkbox w-4 h-4 accent-slate-900 rounded" value="sig_frames" checked>
<span class="font-medium text-slate-800">Ramki i pola podpisów</span>
<span class="ml-auto text-xs text-slate-400">Pola formularzowe</span>
</label>
<label class="flex items-center gap-2.5 p-1.5 rounded-lg hover:bg-slate-50 cursor-pointer">
<input type="checkbox" class="rule-checkbox w-4 h-4 accent-slate-900 rounded" value="sig_handwritten" checked>
<span class="font-medium text-slate-800">Podpisy odręczne (tusz)</span>
<span class="ml-auto text-xs text-slate-400">Pismo długopisem</span>
</label>
<label class="flex items-center gap-2.5 p-1.5 rounded-lg hover:bg-slate-50 cursor-pointer">
<input type="checkbox" class="rule-checkbox w-4 h-4 accent-slate-900 rounded" value="stamps" checked>
<span class="font-medium text-slate-800">Pieczątki i agencje</span>
<span class="ml-auto text-xs text-slate-400">Pieczęcie firmowe</span>
</label>
<label class="flex items-center gap-2.5 p-1.5 rounded-lg hover:bg-slate-50 cursor-pointer">
<input type="checkbox" class="rule-checkbox w-4 h-4 accent-slate-900 rounded" value="dates">
<span class="font-medium text-slate-800">Wszystkie daty</span>
<span class="ml-auto text-xs text-slate-400">DD.MM.RRRR</span>
</label>
</div>
<!-- Podsumowanie wykrytych kategorii (Chipy) -->
<div id="detectedStatsBox" class="mt-3 pt-2.5 border-t border-slate-100 flex flex-wrap gap-1.5">
<span class="text-[11px] text-slate-400">Brak wykrytych elementów</span>
</div>
<!-- Własne słowa do ukrycia -->
<div class="mt-3 pt-3 border-t border-slate-200">
<label for="customWordsInput" class="block text-xs font-bold text-slate-700 mb-1">
Dodatkowe słowa / nazwiska do zamaskowania (oddziel przecinkiem lub średnikiem):
</label>
<input id="customWordsInput" type="text" placeholder="np. Kowalski, Janusz, Wiśniowa 14, ABC-Kredyt"
class="w-full px-3 py-2 text-sm bg-slate-50 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-slate-900" />
<p class="text-[11px] text-slate-400 mt-1">
Wpisz np. rdzeń nazwiska („Kowalsk”), aby zamaskować też odmiany („Kowalskiego”, „Kowalskiej”).
</p>
</div>
<div class="mt-4 flex gap-2">
<button id="btnRunAutoRedact" class="w-full py-2.5 px-4 bg-slate-900 hover:bg-slate-800 text-white font-semibold text-sm rounded-lg shadow transition flex items-center justify-center gap-2">
<span>⚡ Maskuj automatycznie teraz</span>
</button>
</div>
</div>
<!-- Karta 2: Silnik OCR dla skanów i zdjęć -->
<div class="bg-white rounded-xl border border-slate-200 p-4 shadow-sm">
<h2 class="font-bold text-sm uppercase tracking-wider text-slate-700 mb-2">2. Zdjęcia i skany (OCR)</h2>
<p class="text-xs text-slate-500 mb-3">
Jeśli wgrałeś zdjęcie dokumentu lub skan PDF bez warstwy tekstowej, uruchom optyczne rozpoznawanie tekstu (OCR) w języku polskim:
</p>
<button id="btnRunOCR" class="w-full py-2 px-3 bg-indigo-600 hover:bg-indigo-500 disabled:bg-slate-300 text-white font-semibold text-xs sm:text-sm rounded-lg transition flex items-center justify-center gap-2">
<span>🔍 Rozpoznaj tekst ze skanu / zdjęcia (OCR)</span>
</button>
<div id="ocrProgressBox" class="hidden mt-3">
<div class="flex justify-between text-xs font-medium text-slate-600 mb-1">
<span id="ocrStatusText">Inicjalizacja silnika OCR...</span>
<span id="ocrPercentText">0%</span>
</div>
<div class="w-full bg-slate-200 h-2 rounded-full overflow-hidden">
<div id="ocrProgressBar" class="bg-indigo-600 h-full transition-all duration-200" style="width: 0%"></div>
</div>
</div>
</div>
<!-- Karta 3: Eksport gotowego pliku -->
<div class="bg-white rounded-xl border border-slate-200 p-4 shadow-sm">
<h2 class="font-bold text-sm uppercase tracking-wider text-slate-700 mb-2">3. Pobierz zanonimizowany plik</h2>
<p class="text-xs text-slate-500 mb-3">
Dane pod czarnymi maskami są fizycznie usuwane z warstwy tekstowej i wypalane na obrazie – AI odczyta resztę dokumentu, ale nigdy nie odczyta zamaskowanych informacji.
</p>
<div class="space-y-2.5">
<button id="btnExportPDF" class="w-full py-2.5 px-4 bg-red-600 hover:bg-red-500 text-white font-semibold text-sm rounded-lg shadow-sm transition flex items-center justify-between">
<span>📕 Pobierz jako PDF (.pdf)</span>
<span class="text-xs bg-red-700 px-2 py-0.5 rounded">Gotowy dla AI</span>
</button>
<button id="btnExportMD" class="w-full py-2.5 px-4 bg-violet-600 hover:bg-violet-500 text-white font-semibold text-sm rounded-lg shadow-sm transition flex items-center justify-between">
<span>📝 Pobierz jako Markdown (.md)</span>
<span class="text-xs bg-violet-700 px-2 py-0.5 rounded">Tekst dla AI</span>
</button>
<button id="btnExportDOCX" class="w-full py-2.5 px-4 bg-blue-600 hover:bg-blue-500 text-white font-semibold text-sm rounded-lg shadow-sm transition flex items-center justify-between">
<span>📘 Pobierz jako Word (.docx)</span>
<span class="text-xs bg-blue-700 px-2 py-0.5 rounded">MS Word</span>
</button>
<button id="btnExportPNG" class="w-full py-2.5 px-4 bg-emerald-600 hover:bg-emerald-500 text-white font-semibold text-sm rounded-lg shadow-sm transition flex items-center justify-between">
<span>🖼️ Pobierz jako Zdjęcie (.png)</span>
<span class="text-xs bg-emerald-700 px-2 py-0.5 rounded">Obraz</span>
</button>
</div>
<!-- Wybór trybu eksportu PDF i Word z oznaczeniem typu A / B / C -->
<div class="mt-3 pt-3 border-t border-slate-100 space-y-2">
<div>
<label class="block text-xs font-medium text-slate-600 mb-1">Tryb pliku PDF (.pdf) – oznaczany w nazwie pliku:</label>
<select id="pdfExportMode" class="w-full text-xs p-2 border border-slate-300 rounded-lg bg-slate-50 font-medium">
<option value="hybrid_ai">[Typ A] Hybrydowy dla AI (Obraz + tekst bez zakrytych słów)</option>
<option value="text_ai">[Typ B] Czysty tekstowy PDF dla AI (Tylko zanonimizowany tekst)</option>
<option value="flat_image">[Typ C] Tylko spłaszczony obraz (Brak warstwy tekstowej)</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-slate-600 mb-1">Tryb pliku Word (.docx) – oznaczany w nazwie pliku:</label>
<select id="docxExportMode" class="w-full text-xs p-2 border border-slate-300 rounded-lg bg-slate-50 font-medium">
<option value="both">[Typ A] Tekst z czarnymi blokami + Obraz dokumentu</option>
<option value="text_only">[Typ B] Tylko edytowalny tekst (z zamaskowanymi danymi ████)</option>
<option value="images_only">[Typ C] Tylko zamaskowane strony jako obrazy w Wordzie</option>
</select>
</div>
<div class="bg-slate-50 border border-slate-200 rounded-lg p-2 text-[11px] text-slate-500 leading-snug">
🕒 <strong>Nazewnictwo plików:</strong> każdy pobrany plik otrzymuje w nazwie sygnaturę <code>DocMask</code>, kod wybranego trybu (np. <code>A-hybrydowyAI</code>, <code>B-tekstAI</code>, <code>C-splaszczony</code>) oraz znacznik czasu (<code>RRRR-MM-DD_GG-MM-SS</code>).
</div>
</div>
</div>
</aside>
<!-- PRAWY PANEL: Podgląd graficzny, edycja masek oraz widok tekstowy -->
<section class="lg:col-span-8 flex flex-col space-y-4">
<!-- Pasek narzędzi podglądu -->
<div class="bg-white rounded-xl border border-slate-200 p-3 shadow-sm flex flex-wrap items-center justify-between gap-3">
<div class="flex items-center bg-slate-100 p-1 rounded-lg">
<button id="tabBtnVisual" class="px-3 py-1.5 text-xs sm:text-sm font-semibold rounded-md bg-white text-slate-900 shadow-sm transition">
👁️ Widok Dokumentu (Graficzny)
</button>
<button id="tabBtnText" class="px-3 py-1.5 text-xs sm:text-sm font-semibold rounded-md text-slate-600 hover:text-slate-900 transition">
📝 Widok Tekstowy (do AI / Word)
</button>
</div>
<!-- Narzędzia ręcznego rysowania masek na dokumencie -->
<div id="visualToolsBar" class="flex items-center gap-2 flex-wrap">
<label class="flex items-center gap-1.5 text-xs font-medium text-slate-700 cursor-pointer bg-slate-100 px-2.5 py-1.5 rounded-lg">
<input id="chkShowOutlines" type="checkbox" class="accent-slate-900 rounded" checked>
<span>Pokaż czerwone ramki edycji</span>
</label>
<button id="btnUndoBox" class="px-2.5 py-1.5 text-xs font-medium bg-slate-100 hover:bg-slate-200 text-slate-700 rounded-lg transition" title="Cofnij ostatnią maskę">
↩️ Cofnij
</button>
<button id="btnClearBoxes" class="px-2.5 py-1.5 text-xs font-medium bg-rose-50 hover:bg-rose-100 text-rose-700 rounded-lg transition" title="Usuń wszystkie czarne prostokąty">
🗑️ Wyczyść ramki
</button>
</div>
</div>
<!-- Podpowiedź interakcji -->
<div id="helperBanner" class="bg-amber-50 border border-amber-200 text-amber-900 px-4 py-2.5 rounded-xl text-xs flex items-center justify-between gap-2">
<div>
<strong>💡 Wskazówka:</strong> Możesz <strong>przeciągnąć myszką (lub palcem)</strong> w dowolnym miejscu na dokumencie, aby ręcznie zamaskować podpis, pieczątkę lub fragment tekstu. <strong>Kliknij</strong> w istniejący czarny prostokąt, jeśli chcesz go usunąć.
</div>
</div>
<!-- ZAKŁADKA 1: Widok Graficzny (Strony PDF / Zdjęcia) -->
<div id="viewVisualContainer" class="bg-slate-200/80 border border-slate-300 rounded-xl p-4 sm:p-6 min-h-[540px] flex flex-col items-center justify-start overflow-y-auto max-h-[80vh]">
<div id="pagesWrapper" class="w-full flex flex-col items-center">
<!-- Tutaj renderują się strony dokumentu -->
</div>
</div>
<!-- ZAKŁADKA 2: Widok Tekstowy -->
<div id="viewTextContainer" class="hidden bg-white border border-slate-200 rounded-xl p-4 shadow-sm flex-col space-y-3">
<div class="flex flex-wrap items-center justify-between gap-2 pb-2 border-b border-slate-100">
<div>
<h3 class="font-bold text-sm text-slate-800">Tekst / Markdown po anonimizacji (gotowy do wklejenia do AI lub zapisu)</h3>
<p class="text-xs text-slate-500">Wszystkie słowa przykryte na podglądzie graficznym (także ręcznie myszką!) są tutaj automatycznie zastępowane symbolem ████████.</p>
</div>
<div class="flex items-center gap-2">
<button id="btnCopyMarkdown" class="px-3 py-1.5 bg-violet-600 hover:bg-violet-500 text-white text-xs font-semibold rounded-lg transition">
📝 Kopiuj jako Markdown
</button>
<button id="btnCopyText" class="px-3 py-1.5 bg-slate-900 hover:bg-slate-800 text-white text-xs font-semibold rounded-lg transition">
📋 Kopiuj tekst
</button>
</div>
</div>
<textarea id="redactedTextArea" rows="18"
class="w-full p-3 text-sm font-mono bg-slate-50 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-slate-900 leading-relaxed"
placeholder="Wczytaj dokument lub wklej tutaj treść umowy, aby automatycznie zamaskować dane osobowe..."></textarea>
</div>
</section>
</main>
<!-- Stopka informacyjna z danymi autora i linkiem do repozytorium GitHub -->
<footer class="bg-white border-t border-slate-200 mt-8 py-4">
<div class="max-w-7xl mx-auto px-4 flex flex-col sm:flex-row items-center justify-between gap-2 text-xs text-slate-500">
<div class="flex items-center gap-2">
<span class="font-bold text-slate-800">DocMask v6</span>
<span>•</span>
<span>Lokalna aplikacja do anonimizacji dokumentów (100% Client-Side)</span>
</div>
<div class="flex items-center gap-2">
<span>Autor: <strong class="text-slate-800">lebinho</strong></span>
<span>•</span>
<a href="https://github.com/lebinho/DocMask" target="_blank" rel="noopener noreferrer"
class="text-emerald-600 hover:text-emerald-700 font-semibold underline underline-offset-2">
https://github.com/lebinho/DocMask
</a>
</div>
</div>
</footer>
<!-- Powiadomienia (Toast) -->
<div id="toastBox" class="fixed bottom-5 right-5 z-50 hidden bg-slate-900 text-white px-4 py-3 rounded-xl shadow-lg text-sm font-medium flex items-center gap-2.5 border border-slate-700">
<span id="toastIcon">✅</span>
<span id="toastMessage">Gotowe!</span>
</div>
<script>
/**
* ============================================================================
* DocMask v6 — Core Engine
* Author: lebinho (https://github.com/lebinho/DocMask)
* ============================================================================
*/
const APP_META = Object.freeze({
name: 'DocMask',
version: 'v6',
fileName: 'DocMask.html',
author: 'lebinho',
repoUrl: 'https://github.com/lebinho/DocMask'
});
// Konfiguracja workera PDF.js
if (window.pdfjsLib) {
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js';
}
// Globalny stan aplikacji
const state = {
fileName: 'umowa_kredytowa',
activeTab: 'visual',
showOutlines: true,
// Tablica stron: { pageIndex, width, height, baseCanvas, words: [], lines: [], boxes: [] }
pages: [],
rawFullText: '',
redactedFullText: '',
cachedFontBase64: null
};
// Słownik słów urzędowych, prawnych i formularzowych, które zaczynają się wielką literą, ale NIE są nazwiskami
const POLISH_LEGAL_WHITELIST = new Set([
'Umowa', 'Kredytu', 'Kredytowa', 'Pożyczki', 'Pożyczka', 'Gotówkowej', 'Hipotecznego', 'Hipoteczny',
'Wniosek', 'Formularz', 'Testowy', 'Wyciąg', 'Rachunku', 'Dokument', 'Polisa', 'Komunikacyjna',
'Bank', 'Banku', 'Polski', 'Polska', 'Spółka', 'Akcyjna', 'Ograniczoną', 'Odpowiedzialnością',
'Sąd', 'Rejonowy', 'Okręgowy', 'Krajowy', 'Rejestr', 'Sądowy', 'Kodeks', 'Cywilny', 'Prawo',
'Bankowe', 'Ustawa', 'Dziennik', 'Ustaw', 'Rzeczpospolita', 'Warszawa', 'Warszawie', 'Kraków',
'Krakowie', 'Wrocław', 'Wrocławiu', 'Poznań', 'Poznaniu', 'Gdańsk', 'Gdańsku', 'Łódź', 'Łodzi',
'Katowice', 'Katowicach', 'Szczecin', 'Lublin', 'Bydgoszcz', 'Białystok', 'Gdynia', 'Częstochowa',
'Radom', 'Toruń', 'Sosnowiec', 'Kielce', 'Rzeszów', 'Gliwice', 'Zabrze', 'Olsztyn', 'Bielsko',
'Sopot', 'Sopocie', 'Straszyn', 'Straszynie', 'Robakowo', 'Gądki', 'strona', 'Strony', 'Stron',
'Paragraf', 'Artykuł', 'Ustęp', 'Punkt', 'Załącznik', 'Regulamin', 'Tabela', 'Opłat', 'Prowizji',
'Całkowita', 'Kwota', 'Rzeczywista', 'Roczna', 'Stopa', 'Oprocentowanie', 'Kredytobiorca',
'Kredytobiorcy', 'Kredytodawca', 'Pożyczkodawca', 'Poręczyciel', 'Ubezpieczyciel', 'Ubezpieczony',
'Ubezpieczający', 'Ubezpieczeniowa', 'Ubezpieczenia', 'Ubezpieczenie', 'Zleceniodawca',
'Zleceniobiorca', 'Wykonawca', 'Zamawiający', 'Wynajmujący', 'Najemca', 'Sprzedający', 'Kupujący',
'Podpis', 'Czytelny', 'Pieczęć', 'Data', 'Miejsce', 'Zawarcia', 'Niniejsza', 'Niniejszej',
'Niniejszy', 'Umowy', 'Postanowienia', 'Końcowe', 'Ogólne', 'Warunki', 'Świadczenia', 'Usług',
'Zwanym', 'Zwaną', 'Dalej', 'Oraz', 'Dane', 'Wnioskodawcy', 'Współwnioskodawca', 'Imię', 'Nazwisko',
'Seria', 'Numer', 'Dowodu', 'Urodzenia', 'Telefon', 'Adres', 'Zamieszkania', 'Zatrudnienie',
'Dochody', 'Pracodawca', 'Pracownik', 'Pracownika', 'Stanowisko', 'Miesięczny', 'Dochód', 'Netto',
'Brutto', 'Wypłaty', 'Informacje', 'Nieruchomości', 'Wartość', 'Wnioskowana', 'Okres',
'Kredytowania', 'Posiadacz', 'Wyciągu', 'Zestawienie', 'Operacji', 'Wpływ', 'Wynagrodzenia',
'Wynagrodzenie', 'Pasek', 'Miesiąc', 'Służbowy', 'Kontaktowy', 'Korespondencyjny', 'Przelew',
'Opłata', 'Płatność', 'Kartą', 'Podsumowanie', 'Saldo', 'Początkowe', 'Suma', 'Wpływów',
'Obciążeń', 'Marka', 'Model', 'Ochrony', 'Rejestracyjny', 'Polisy', 'Analityk', 'Danych',
'Przykładowe', 'Technologie', 'Energia', 'Fabryka', 'Testowych', 'Faktura', 'Faktury', 'Klient',
'Klienta', 'Odbiorca', 'Termin', 'Płatności', 'Zapłaty', 'Przedmiot', 'Księgi', 'Wieczystej',
'Powierzchnia', 'Budynku', 'Towarzystwo', 'Ubezpieczeń', 'Składka', 'Osoba', 'Uposażona',
'Stopień', 'Pokrewieństwa', 'Zakres', 'Dom', 'Jednorodzinny', 'Ruchomości', 'Domowe', 'Pomoc',
'Domu', 'Wariant', 'Komfort', 'Dodatkowe', 'Odpowiedzialność', 'Cywilna', 'Życiu', 'Prywatnym',
'Terytorialny', 'Zniżki', 'Zwyżki', 'Składki', 'Łączna', 'Schemat', 'Jednorazowy', 'Opłacono',
'Tytuł', 'Przelewu', 'Cesja', 'Cesji', 'Cesjonariusz', 'Opis', 'Konstrukcja', 'Właścicielem'
]);
// Baza popularnych polskich imion do precyzyjnego wykrywania pełnych imion i nazwisk (w tym dwuczłonowych i WIELKIMI LITERAMI)
const POLISH_FIRST_NAMES = new Set([
'Jan', 'Janem', 'Jana', 'Janowi', 'Anna', 'Anną', 'Anny', 'Annie', 'Piotr', 'Piotra', 'Piotrem',
'Marta', 'Marty', 'Martą', 'Katarzyna', 'Katarzyny', 'Katarzyną', 'Michał', 'Michała', 'Michałem',
'Krzysztof', 'Krzysztofa', 'Tomasz', 'Tomasza', 'Paweł', 'Pawła', 'Marcin', 'Marcina', 'Agnieszka',
'Agnieszki', 'Magdalena', 'Magdaleny', 'Barbara', 'Barbary', 'Ewa', 'Ewy', 'Krystyna', 'Krystyny',
'Elżbieta', 'Elżbiety', 'Zofia', 'Zofii', 'Teresa', 'Teresy', 'Małgorzata', 'Małgorzaty', 'Joanna',
'Joanny', 'Monika', 'Moniki', 'Danuta', 'Danuty', 'Natalia', 'Natalii', 'Karolina', 'Karoliny',
'Aleksandra', 'Aleksandry', 'Justyna', 'Justyny', 'Beata', 'Beaty', 'Dorota', 'Doroty', 'Halina',
'Jadwiga', 'Irena', 'Alicja', 'Grażyna', 'Bożena', 'Iwona', 'Paulina', 'Patrycja', 'Kinga',
'Sylwia', 'Agata', 'Dominika', 'Wioletta', 'Renata', 'Urszula', 'Emilia', 'Julia', 'Zuzanna',
'Maja', 'Hanna', 'Lena', 'Andrzej', 'Andrzeja', 'Stanisław', 'Stanisława', 'Marek', 'Marka',
'Grzegorz', 'Grzegorza', 'Józef', 'Józefa', 'Łukasz', 'Łukasza', 'Łukaszem', 'Adam', 'Adama',
'Zbigniew', 'Jerzy', 'Dariusz', 'Mariusz', 'Wojciech', 'Wojciecha', 'Ryszard', 'Jakub', 'Jakuba',
'Robert', 'Roberta', 'Rafał', 'Rafała', 'Jacek', 'Jacka', 'Janusz', 'Janusza', 'Mirosław', 'Maciej',
'Macieja', 'Sławomir', 'Jarosław', 'Kamil', 'Kamila', 'Wiesław', 'Roman', 'Władysław', 'Kazimierz',
'Artur', 'Artura', 'Tadeusz', 'Marian', 'Filip', 'Filipa', 'Bartosz', 'Bartosza', 'Mateusz',
'Mateusza', 'Szymon', 'Szymona', 'Dawid', 'Dawida', 'Kacper', 'Antoni', 'Franciszek', 'Aleksander',
'Mikołaj', 'Przemysław', 'Cezary', 'Konrad', 'Sebastian', 'Damian', 'Patryk', 'Arkadiusz',
'Bogdan', 'Waldemar', 'Radosław', 'Karol', 'Karola', 'Stefan', 'Henryk', 'Edward', 'Leszek',
'Wiktoria', 'Amelia', 'Oliwia', 'Natalia', 'Klaudia', 'Martyna', 'Weronika', 'Kornelia', 'Łucja'
]);
// Normalizuje słowo do postaci Title Case (np. "ŁUKASZ" -> "Łukasz"), aby słowniki działały również dla WIELKICH LITER
function toTitleCaseWord(word) {
if (!word) return '';
const clean = word.replace(/^[^\p{L}]+|[^\p{L}]+$/gu, '');
if (!clean) return '';
return clean.charAt(0).toUpperCase() + clean.slice(1).toLowerCase();
}
function isWhitelistedWord(word) {
const tc = toTitleCaseWord(word);
return POLISH_LEGAL_WHITELIST.has(tc) || POLISH_LEGAL_WHITELIST.has(word);
}
function isKnownFirstName(word) {
const tc = toTitleCaseWord(word);
return POLISH_FIRST_NAMES.has(tc);
}
// Pomocniczy kontekst Canvas do precyzyjnego mierzenia szerokości znaków i słów
const _measureCanvas = document.createElement('canvas');
const _measureCtx = _measureCanvas.getContext('2d');
function showToast(message, icon = '✅') {
const box = document.getElementById('toastBox');
document.getElementById('toastIcon').textContent = icon;
document.getElementById('toastMessage').textContent = message;
box.classList.remove('hidden');
clearTimeout(window._toastTimer);
window._toastTimer = setTimeout(() => {
box.classList.add('hidden');
}, 3800);
}
function updateFoundCounter() {
let totalBoxes = 0;
const countsByLabel = {};
for (const p of state.pages) {
totalBoxes += p.boxes.length;
for (const b of p.boxes) {
const lbl = b.label || 'INNE';
countsByLabel[lbl] = (countsByLabel[lbl] || 0) + 1;
}
}
const badge = document.getElementById('badgeFoundCount');
badge.textContent = `${totalBoxes} zamaskowanych`;
if (totalBoxes > 0) {
badge.className = 'px-2.5 py-0.5 text-xs font-bold bg-emerald-100 text-emerald-800 rounded-full';
} else {
badge.className = 'px-2.5 py-0.5 text-xs font-bold bg-slate-100 text-slate-800 rounded-full';
}
// Aktualizacja chipów z podsumowaniem wykrytych kategorii
const statsBox = document.getElementById('detectedStatsBox');
if (statsBox) {
const entries = Object.entries(countsByLabel);
if (!entries.length) {
statsBox.innerHTML = '<span class="text-[11px] text-slate-400">Brak wykrytych elementów</span>';
} else {
statsBox.innerHTML = entries
.map(([k, v]) => `<span class="px-2 py-0.5 text-[11px] font-semibold bg-slate-100 text-slate-700 rounded-md border border-slate-200">${k}: ${v}</span>`)
.join('');
}
}
}
// Rozbija ciąg tekstowy na pojedyncze słowa wraz z ich dokładnymi współrzędnymi X i szerokością W
function splitItemIntoWordTokens(str, itemX, itemY, itemW, itemH, fontSpec = '18px Inter, sans-serif') {
const tokens = [];
if (!str || !str.trim()) return tokens;
_measureCtx.font = fontSpec;
const fullMeasured = Math.max(_measureCtx.measureText(str).width, 1);
const scaleFactor = itemW / fullMeasured;
const wordRegex = /\S+/g;
let match;
while ((match = wordRegex.exec(str)) !== null) {
const wordStr = match[0];
const prefixStr = str.slice(0, match.index);
const prefixW = _measureCtx.measureText(prefixStr).width * scaleFactor;
const wordW = Math.max(_measureCtx.measureText(wordStr).width * scaleFactor, 4);
tokens.push({
str: wordStr,
x: itemX + prefixW,
y: itemY,
w: wordW,
h: itemH
});
}
return tokens;
}
// Buduje strukturę spanów ze zbioru słów
function createTextAndSpans(wordArray) {
let text = '';
const wordSpans = [];
wordArray.forEach((w, idx) => {
if (idx > 0) text += ' ';
const startChar = text.length;
text += w.str;
const endChar = text.length;
wordSpans.push({ word: w, startChar, endChar });
});
const minX = wordArray.length ? Math.min(...wordArray.map(w => w.x)) : 0;
const maxX = wordArray.length ? Math.max(...wordArray.map(w => w.x + w.w)) : 0;
const minY = wordArray.length ? Math.min(...wordArray.map(w => w.y)) : 0;
const maxY = wordArray.length ? Math.max(...wordArray.map(w => w.y + w.h)) : 0;
return { text, wordSpans, minX, maxX, minY, maxY, words: wordArray };
}
// Grupuje pojedyncze słowa (z PDF lub z OCR) w logiczne wiersze dokumentu oraz wydziela kolumny (segments),
// dzięki czemu wielokolumnowe polisy i tabele formularzy są analizowane precyzyjnie bez błędów na styku kolumn.
function buildLogicalLinesFromWords(words) {
if (!words || !words.length) return [];
const sorted = [...words].filter(w => w.str && w.str.trim()).sort((a, b) => {
const centerYa = a.y + a.h / 2;
const centerYb = b.y + b.h / 2;
if (Math.abs(centerYa - centerYb) > Math.max(a.h, b.h) * 0.65) {
return centerYa - centerYb;
}
return a.x - b.x;
});
const rawRows = [];
for (const word of sorted) {
const wordCenterY = word.y + word.h / 2;
let bestRow = null;
let bestDist = Infinity;
for (const row of rawRows) {
const refWord = row.words[row.words.length - 1];
const refCenterY = refWord.y + refWord.h / 2;
const maxTol = Math.max(row.avgH, word.h) * 0.72;
const dy = Math.abs(wordCenterY - refCenterY);
if (dy <= maxTol && dy < bestDist) {
bestDist = dy;
bestRow = row;
}
}
if (bestRow) {
bestRow.words.push(word);
bestRow.avgH = (bestRow.avgH * (bestRow.words.length - 1) + word.h) / bestRow.words.length;
bestRow.avgY = (bestRow.avgY * (bestRow.words.length - 1) + wordCenterY) / bestRow.words.length;
} else {
rawRows.push({
avgY: wordCenterY,
avgH: word.h,
words: [word]
});
}
}
rawRows.sort((a, b) => a.avgY - b.avgY);
return rawRows.map(row => {
row.words.sort((a, b) => a.x - b.x);
const fullLine = createTextAndSpans(row.words);
// Podział wiersza na segmenty kolumnowe przy dużym odstępie poziomym
const segments = [];
let currentSegWords = [];
const colGapThreshold = Math.max(28, row.avgH * 1.75);
for (let i = 0; i < row.words.length; i++) {
const w = row.words[i];
if (currentSegWords.length > 0) {
const prev = currentSegWords[currentSegWords.length - 1];
const gap = w.x - (prev.x + prev.w);
if (gap > colGapThreshold) {
segments.push(createTextAndSpans(currentSegWords));
currentSegWords = [];
}
}
currentSegWords.push(w);
}
if (currentSegWords.length > 0) {
segments.push(createTextAndSpans(currentSegWords));
}
return {
text: fullLine.text,
wordSpans: fullLine.wordSpans,
avgY: row.avgY,
avgH: row.avgH,
segments
};
});
}
// Wylicza precyzyjne prostokąty (co do słowa / fragmentu słowa) dla dopasowania [matchStart, matchEnd]
function computeBoxesForLineMatch(lineOrSeg, matchStart, matchEnd, label, pageWidth) {
const boxes = [];
const matchedPieces = [];
for (const span of lineOrSeg.wordSpans) {
if (span.endChar <= matchStart || span.startChar >= matchEnd) continue;
const wObj = span.word;
const wordLen = Math.max(span.endChar - span.startChar, 1);
const localStart = Math.max(0, matchStart - span.startChar);
const localEnd = Math.min(wordLen, matchEnd - span.startChar);
let subX = wObj.x;
let subW = wObj.w;
if (localStart > 0 || localEnd < wordLen) {
const startRatio = localStart / wordLen;
const endRatio = localEnd / wordLen;
subX = wObj.x + wObj.w * startRatio;
subW = wObj.w * (endRatio - startRatio);
}
matchedPieces.push({
x: subX,
y: wObj.y,
w: subW,
h: wObj.h
});
}
if (!matchedPieces.length) return boxes;
const padX = 4;
const padY = 3;
let current = { ...matchedPieces[0] };
for (let i = 1; i < matchedPieces.length; i++) {
const next = matchedPieces[i];
const horizGap = next.x - (current.x + current.w);
const vertDiff = Math.abs(next.y - current.y);
if (horizGap < 45 && vertDiff < Math.max(current.h, next.h) * 0.6) {
const rightEdge = Math.max(current.x + current.w, next.x + next.w);
const topEdge = Math.min(current.y, next.y);
const bottomEdge = Math.max(current.y + current.h, next.y + next.h);
current.x = Math.min(current.x, next.x);
current.y = topEdge;
current.w = rightEdge - current.x;
current.h = bottomEdge - topEdge;
} else {
boxes.push({
x: Math.max(0, current.x - padX),
y: Math.max(0, current.y - padY),
w: Math.min(pageWidth - current.x, current.w + padX * 2),
h: current.h + padY * 2,
label,
source: 'auto'
});
current = { ...next };
}
}
boxes.push({
x: Math.max(0, current.x - padX),
y: Math.max(0, current.y - padY),
w: Math.min(pageWidth - current.x, current.w + padX * 2),
h: current.h + padY * 2,
label,
source: 'auto'
});
return boxes;
}
// Reguły tabelaryczne (Gdy lewa kolumna w tabeli to etykieta pola, zamaskuj odpowiadającą jej prawą kolumnę z wartością)
function buildTableSensitiveLabelRules() {
const checked = Array.from(document.querySelectorAll('.rule-checkbox:checked')).map(cb => cb.value);
const labelRules = [];
if (checked.includes('names')) {
labelRules.push({
label: 'OSOBA',
regex: /^(?:Imi[ęe]\s+i\s+nazwisko|Pracownik|Ubezpieczaj[ąa]cy|Ubezpieczony|Wsp[óo][łl]wnioskodawca|Wnioskodawca|Osoba\s+uposa[żz]ona|Posiadacz\s+rachunku|Odbiorca|Kredytobiorca|Por[ęe]czyciel)[\s:]*$/i
});
}
if (checked.includes('pesel')) {
labelRules.push({
label: 'PESEL',
regex: /^PESEL(?:\s+klienta|\s+wnioskodawcy|\s+ubezpieczonego|\s+pracownika)?[\s:]*$/i
});
}
if (checked.includes('idcard')) {
labelRules.push({
label: 'DOKUMENT',
regex: /^(?:Seria\s+i\s+numer\s+dowodu(?:\s+osobistego)?|Dow[óo]d\s+osobisty|Numer\s+dowodu|Paszport|Numer\s+paszportu)[\s:]*$/i
});
}
if (checked.includes('nip_regon')) {
labelRules.push({
label: 'NIP/REGON',
regex: /^(?:NIP(?:\s+pracodawcy|\s+klienta|\s+nabywcy|\s+sprzedawcy)?|REGON|KRS)[\s:]*$/i
});
}
if (checked.includes('iban')) {
labelRules.push({
label: 'KONTO',
regex: /^(?:Numer\s+rachunku(?:\s+do\s+wyp[łl]aty|\s+bankowego)?|Rachunek(?:\s+do\s+p[łl]atno[śs]ci|\s+bankowy)?|Nr\s+rachunku|Konto\s+bankowe|IBAN)[\s:]*$/i
});
}
if (checked.includes('phone')) {
labelRules.push({
label: 'TELEFON',
regex: /^(?:Telefon(?:\s+kontaktowy|\s+s[łl]u[żz]bowy|\s+kom[óo]rkowy)?|Nr\s+telefonu|Tel\.?)[\s:]*$/i
});
}
if (checked.includes('email')) {
labelRules.push({
label: 'EMAIL',
regex: /^(?:E-?mail(?:\s+s[łl]u[żz]bowy|\s+kontaktowy|\s+prywatny)?|Adres\s+e-?mail|Poczta\s+elektroniczna)[\s:]*$/i
});
}
if (checked.includes('address')) {
labelRules.push({
label: 'ADRES',
regex: /^(?:Adres(?:\s+zamieszkania|\s+nieruchomo[śs]ci|\s+korespondencyjny|\s+ubezpieczenia|\s+punktu\s+poboru|\s+miejsca\s+ubezpieczenia|\s+zameldowania|\s+do\s+dor[ęe]cze[ńn])?|Miejsce\s+zamieszkania|Miejsce\s+ubezpieczenia)[\s:]*$/i
});
}
if (checked.includes('vehicle_policy')) {
labelRules.push({
label: 'POLISA/ID',
regex: /^(?:Numer\s+polisy|Nr\s+polisy|Numer\s+ksi[ęe]gi\s+wieczystej|Nr\s+KW|Numer\s+pracownika|Numer\s+klienta|ID\s+klienta|Numer\s+faktury|Nr\s+faktury|Numer\s+rejestracyjny|Nr\s+rej\.?|VIN|Numer\s+VIN)[\s:]*$/i
});
}
if (checked.includes('dates')) {
labelRules.push({
label: 'DATA',
regex: /^(?:Data\s+urodzenia|Data\s+zawarcia|Termin\s+p[łl]atno[śs]ci)[\s:]*$/i
});
}
return labelRules;
}
// Zwraca listę aktywnych reguł regex na podstawie zaznaczonych kategorii i własnych słów
function buildActiveRegexPatterns() {
const checked = Array.from(document.querySelectorAll('.rule-checkbox:checked')).map(cb => cb.value);
const patterns = [];
// 1. Numer PESEL (11 cyfr, z uwzględnieniem przekłamań OCR)
if (checked.includes('pesel')) {
patterns.push({
label: 'PESEL',
regex: /\b\d{11}\b/g
});
patterns.push({
label: 'PESEL',
regex: /(?<=PESEL(?:\s+klienta)?[\s:]*)[0-9OIl]{11}\b/gi
});
}
// 2. Dowód osobisty / Paszport
if (checked.includes('idcard')) {
patterns.push({
label: 'DOKUMENT',
regex: /\b[A-Z]{2,3}[\s\-]?\d{6,7}\b/g
});
patterns.push({
label: 'DOKUMENT',
regex: /(?<=(?:Seria i numer dowodu|dowód osobisty|dowodem osobistym|seria i numer|paszport)[\s:]*)[A-Z0-9]{2,4}[\s\-]?[0-9O]{5,7}\b/gi
});
}
// 3. NIP / REGON / KRS
if (checked.includes('nip_regon')) {
patterns.push({
label: 'NIP/REGON',
regex: /\b(?:\d{3}-\d{3}-\d{2}-\d{2}|\d{3}-\d{2}-\d{2}-\d{3}|\d{2}-\d{2}-\d{3}-\d{3}|(?:NIP|REGON|KRS)[\s:]*[\d\-]{9,14}|\d{10}|\d{9})\b/gi
});
patterns.push({
label: 'NIP/REGON',
regex: /(?<=(?:NIP(?:\s+pracodawcy)?|REGON|KRS)[\s:]*)[0-9O\-]{9,15}\b/gi
});
}
// 4. Konto bankowe NRB / IBAN
if (checked.includes('iban')) {
patterns.push({
label: 'KONTO',
regex: /\b(?:PL|PL00|PLOO)?[\s]?[0-9O]{2}(?:[\s\-]?[0-9O]{4}){5,7}\b/gi
});
patterns.push({
label: 'KONTO',
regex: /(?<=(?:Numer rachunku(?:\s+do wypłaty)?|Rachunek(?:\s+do płatności|\s+bankowy)?|Nr rachunku|NRB|IBAN)[\s:]*)(?:PL[\s]?)?[0-9O]{2}(?:[\s\-]?[0-9O]{4}){4,7}/gi
});
}
// 5. Numery telefonów
if (checked.includes('phone')) {
patterns.push({
label: 'TELEFON',
regex: /(?:(?:\+|00)48[\s\-]?)?(?:\b\d{3}[\s\-]\d{3}[\s\-]\d{3}\b|\b\d{2}[\s\-]\d{3}[\s\-]\d{2}[\s\-]\d{2}\b|\(\d{2}\)[\s\-]?\d{3}[\s\-]?\d{2}[\s\-]?\d{2}|\b[4-8]\d{8}\b|\b80[01][\s\-]?\d{3}[\s\-]\d{3}\b)/g
});
patterns.push({
label: 'TELEFON',
regex: /(?<=(?:Telefon(?:\s+kontaktowy|\s+służbowy)?|Tel\.?|pod numer)[\s:]+)(?:\+?\d[\d\s\-()]{6,16}\d)/gi
});
}
// 6. Adresy e-mail
if (checked.includes('email')) {
patterns.push({
label: 'EMAIL',
regex: /\b[A-Za-z0-9._%+\-]+\s*(?:@|©|\(a\))\s*(?:[A-Za-z0-9\-]+\s*\.\s*)+[A-Za-z]{2,}\b/g
});
patterns.push({
label: 'EMAIL',
regex: /(?<=(?:E-?mail(?:\s+s[łl]u[żz]bowy|\s+kontaktowy|\s+prywatny)?|Adres e-?mail|poczty elektronicznej)[\s:]+)[A-Za-z0-9._%+\-]+(?:@|[O©Qa])(?:[A-Za-z0-9\-]+\.)+[A-Za-z]{2,}/gi
});
patterns.push({
label: 'EMAIL',
regex: /\b[a-z0-9._\-]+\.[a-z0-9._\-]+[@O©Qa](?:[a-z0-9\-]+\.)+[a-z]{2,}\b/gi
});
}
// 7. Adresy zamieszkania, nieruchomości, miejsca ubezpieczenia i kody pocztowe
if (checked.includes('address')) {
patterns.push({
label: 'ADRES',
regex: /(?<=(?:Adres\s+zamieszkania|Adres\s+nieruchomo[śs]ci|Adres\s+korespondencyjny|Adres\s+ubezpieczenia|Adres\s+miejsca\s+ubezpieczenia|Adres\s+punktu\s+poboru|Miejsce\s+zamieszkania|Miejsce\s+ubezpieczenia|Opis\s+nieruchomo[śs]ci|zamieszka[łl](?:y|a|ego|ej|ym)(?:\s+przy|\s+w)?|zam\.|adres)\s*:\s*)(?!\s*(?:zamieszkania|nieruchomo[śs]ci|korespondencyjn|ubezpieczenia|miejsca|punktu|siedziby)\b)[A-ZĄĆĘŁŃÓŚŹŻ0-9a-ząćęłńóśźż][a-ząćęłńóśźżA-ZĄĆĘŁŃÓŚŹŻ0-9\s\.\-\/,]{3,75}?(?=\s*(?:,\s*PESEL|,\s*tel|,\s*legitym|$))/gi
});
patterns.push({
label: 'ADRES',
regex: /\b(?:ul\.|ulica|al\.|aleja|os\.|osiedle|pl\.|plac|rondo)\s*[A-ZĄĆĘŁŃÓŚŹŻ0-9][a-ząćęłńóśźżA-ZĄĆĘŁŃÓŚŹŻ0-9\s\.\-]{1,35}?\s+\d+[a-zA-Z]?(?:[\s\/\-]+(?:m\.?\s*|lok\.?\s*)?\d+[a-zA-Z]?)?(?:[\s,]+\d{2}-\d{3}\s+[A-ZĄĆĘŁŃÓŚŹŻ][a-ząćęłńóśźżA-ZĄĆĘŁŃÓŚŹŻ\-]+(?:\s+[A-ZĄĆĘŁŃÓŚŹŻ][a-ząćęłńóśźżA-ZĄĆĘŁŃÓŚŹŻ\-]+)?)?/gi
});
patterns.push({
label: 'ADRES',
regex: /\b(?:[A-ZĄĆĘŁŃÓŚŹŻ][A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż\-]{2,25},\s+)?[A-ZĄĆĘŁŃÓŚŹŻ][A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż\.\-]{2,25}(?:\s+[A-ZĄĆĘŁŃÓŚŹŻ][A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż\.\-]{2,25})?\s+\d{1,4}[A-Za-z]?(?:\/\d{1,4}[A-Za-z]?)?\s*,?\s+\d{2}-\d{3}(?:\s+[A-ZĄĆĘŁŃÓŚŹŻ][A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż\-]+(?:\s+[A-ZĄĆĘŁŃÓŚŹŻ][A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż\-]+)?)?\b/g
});
patterns.push({
label: 'ADRES',
regex: /\b\d{2}-\d{3}\s+[A-ZĄĆĘŁŃÓŚŹŻ][A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż\-]{2,25}(?:\s+[A-ZĄĆĘŁŃÓŚŹŻ][A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż\-]{2,25})?\b/g,
validateMatch: (m) => !/\b(?:PLN|EUR|USD|zł|miesięcy|lat)\b/i.test(m)
});
}
// 8. Imiona i nazwiska (w tym dwuczłonowe oraz WIELKIMI LITERAMI)
if (checked.includes('names')) {
patterns.push({
label: 'OSOBA',
regex: /(?<=(?:Imi[ęe] i nazwisko|Pracownik|Ubezpieczon(?:y|a|ego)|Ubezpieczaj[ąa]c(?:y|a|ego)|Posiadacz rachunku|Wnioskodawc(?:a|y)|Wsp[óo][łl]wnioskodawc(?:a|y)|Kredytobiorc(?:a|ą|y)|Po[żz]yczkobiorc(?:a|ą|y)|Por[ęe]czyciel(?:em)?|Odbiorca|Nadawca|Podpis(?:\s+Kredytobiorcy)?|Przelew\s*:|\bPan(?:i|em|ią|u)?)\s*[:\s]\s*)[A-ZĄĆĘŁŃÓŚŹŻ][A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż]{2,18}(?:\s+[A-ZĄĆĘŁŃÓŚŹŻ][A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż]{2,18})?\s+[A-ZĄĆĘŁŃÓŚŹŻ][A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż]{2,25}(?:\s*[\-–—]\s*[A-ZĄĆĘŁŃÓŚŹŻ][A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż]{2,25})?/g,
validateMatch: (matchStr) => {
const tokens = matchStr.trim().split(/[\s\-–—]+/);
return !tokens.some(t => isWhitelistedWord(t));
}
});
patterns.push({
label: 'OSOBA',
regex: /\b[A-ZĄĆĘŁŃÓŚŹŻ][A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż]{2,15}\s+[A-ZĄĆĘŁŃÓŚŹŻ][A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż]{2,25}(?:\s*[\-–—]\s*[A-ZĄĆĘŁŃÓŚŹŻ][A-ZĄĆĘŁŃÓŚŹŻa-ząćęłńóśźż]{2,25})?\b/g,
validateMatch: (matchStr) => {
const parts = matchStr.trim().split(/\s+/);
if (parts.length < 2) return false;
const firstName = parts[0];
const surnameParts = parts.slice(1).join(' ').split(/[\-–—]/).map(s => s.trim()).filter(Boolean);
if (isWhitelistedWord(firstName) || surnameParts.some(sp => isWhitelistedWord(sp))) {
return false;
}
if (isKnownFirstName(firstName)) {
return true;
}
const strictSurnameSuffix = /(?:ski|ska|cki|cka|dzki|dzka|wicz|czyk|czak|skiego|skiej|ckiemu|ckiej|wiczem|wicza)$/i;
return surnameParts.some(sp => strictSurnameSuffix.test(sp));
}
});
}
// 9. Polisy, VIN, Księga Wieczysta (KW), Numery faktur, Numery pracownika/klienta i Karty płatnicze
if (checked.includes('vehicle_policy')) {
patterns.push({
label: 'KW',
regex: /\b[A-Z]{2}\d[A-Z]\/\d{8}\/\d\b/g
});
patterns.push({
label: 'POLISA/ID',
regex: /(?<=(?:Numer polisy|Nr polisy|Polisa numer|Polisa nr|Numer ksi[ęe]gi wieczystej|Numer pracownika|Numer klienta|Numer faktury|Nr faktury|VIN|Numer VIN|Numer rejestracyjny|Nr rej\.?)[\s:]+)[A-Z0-9\/\-]{3,28}(?:\s+[A-Z0-9]{2,8})?/gi
});
patterns.push({
label: 'NR DOKUMENTU',
regex: /\b(?:[A-Z]{2,6}\/[A-Z0-9]{2,10}\/[A-Z0-9\/\-]{2,15}|[A-Z]{1,4}\/\d{4}\/[A-Z0-9\/\-]{3,12})\b/g
});
patterns.push({
label: 'ID KLIENTA',
regex: /\b(?:EMP|KLIENT|PRAC|ID|USR|POL)[\-_][A-Z0-9\-_]{3,22}\b/g
});
patterns.push({
label: 'VIN',
regex: /\b[A-HJ-NPR-Z0-9]{17}\b/g
});
patterns.push({
label: 'KARTA',
regex: /(?:\*{4}[\s\-]?){1,3}\d{4}\b/g
});
}