-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtapcode.html
More file actions
3927 lines (3417 loc) · 134 KB
/
tapcode.html
File metadata and controls
3927 lines (3417 loc) · 134 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="manifest" href="manifest.webmanifest">
<meta name="application-name" content="IdleGames">
<meta name="theme-color" content="#2d3748">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<script src="assets/js/pwa.js" defer></script>
<title>Tap Code</title>
<style>
:root {
--bg-color: #f7fafc;
--text-color: #2d3748;
--text-muted: #718096;
--panel-bg: #ffffff;
--border-color: #e2e8f0;
--accent: #4a5568;
--accent-hover: #2d3748;
--btn-bg: #edf2f7;
--btn-hover: #e2e8f0;
--btn-active: #cbd5e0;
--btn-send: #48bb78;
--btn-send-hover: #38a169;
--btn-stop: #f56565;
--btn-stop-hover: #e53e3e;
--grid-highlight: #bee3f8;
--grid-active: #3182ce;
--selection-bg: var(--grid-highlight);
--selection-text: var(--text-color);
--scrollbar-track: var(--panel-bg);
--scrollbar-thumb: var(--btn-active);
--scrollbar-thumb-hover: var(--accent);
}
[data-theme="dark"] {
--bg-color: #1a202c;
--text-color: #e2e8f0;
--text-muted: #a0aec0;
--panel-bg: #2d3748;
--border-color: #4a5568;
--accent: #a0aec0;
--accent-hover: #e2e8f0;
--btn-bg: #4a5568;
--btn-hover: #718096;
--btn-active: #2d3748;
--btn-send: #48bb78;
--btn-send-hover: #68d391;
--btn-stop: #fc8181;
--btn-stop-hover: #f56565;
--grid-highlight: #2c5282;
--grid-active: #63b3ed;
--selection-bg: var(--grid-highlight);
--selection-text: var(--text-color);
--scrollbar-track: var(--panel-bg);
--scrollbar-thumb: var(--btn-hover);
--scrollbar-thumb-hover: var(--accent-hover);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
::selection {
background: var(--selection-bg);
color: var(--selection-text);
}
::-moz-selection {
background: var(--selection-bg);
color: var(--selection-text);
}
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg-color);
color: var(--text-color);
min-height: 100vh;
padding: 1rem;
transition: background 0.3s, color 0.3s;
}
.container {
max-width: 600px;
margin: 0 auto;
}
header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1.5rem;
}
h1 {
font-size: 1.5rem;
font-weight: 600;
display: flex;
align-items: center;
gap: 0.5rem;
}
.theme-btn {
background: none;
border: none;
cursor: pointer;
padding: 0.5rem;
border-radius: 0.5rem;
color: var(--text-color);
transition: background 0.2s;
}
.theme-btn:hover {
background: var(--btn-hover);
}
.theme-btn svg {
width: 24px;
height: 24px;
}
/* Tap Code Grid */
.grid-section {
margin-bottom: 1.5rem;
}
.section-label {
font-size: 0.875rem;
color: var(--text-muted);
margin-bottom: 0.5rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.tap-grid {
display: grid;
grid-template-columns: auto repeat(5, 1fr);
gap: 2px;
background: var(--panel-bg);
border-radius: 0.75rem;
padding: 0.75rem;
font-size: 1rem;
}
.grid-header {
font-weight: 600;
text-align: center;
padding: 0.5rem;
color: var(--text-muted);
}
.grid-cell {
text-align: center;
padding: 0.625rem;
border-radius: 0.375rem;
transition: background 0.15s;
}
.grid-cell.letter {
font-weight: 500;
font-size: 1.6rem;
line-height: 1.1;
letter-spacing: 0.02em;
}
.grid-cell.highlight {
background: var(--grid-highlight);
}
.grid-cell.active {
background: var(--grid-active);
color: white;
}
.grid-cell.ck {
font-size: 1.1rem;
letter-spacing: 0;
}
/* Text areas */
.io-section {
margin-bottom: 1.5rem;
}
.io-label {
font-size: 0.875rem;
color: var(--text-muted);
margin-bottom: 0.5rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.io-label svg {
width: 16px;
height: 16px;
}
textarea {
width: 100%;
min-height: 100px;
padding: 0.75rem;
border: 1px solid var(--border-color);
border-radius: 0.5rem;
background: var(--panel-bg);
color: var(--text-color);
font-family: inherit;
font-size: 1rem;
resize: vertical;
transition: border-color 0.2s;
scrollbar-width: thin;
scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
textarea::-webkit-scrollbar {
width: 10px;
height: 10px;
}
textarea::-webkit-scrollbar-track {
background: var(--scrollbar-track);
border-radius: 999px;
}
textarea::-webkit-scrollbar-thumb {
background-color: var(--scrollbar-thumb);
border-radius: 999px;
border: 2px solid var(--scrollbar-track);
}
textarea::-webkit-scrollbar-thumb:hover {
background-color: var(--scrollbar-thumb-hover);
}
textarea::-webkit-scrollbar-corner {
background: var(--scrollbar-track);
}
textarea:focus {
outline: none;
border-color: var(--accent);
}
.mono {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
/* Buttons */
.btn-group {
display: flex;
gap: 0.5rem;
margin-top: 0.75rem;
}
.btn {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
padding: 0.75rem 1rem;
border: none;
border-radius: 0.5rem;
font-size: 0.9375rem;
font-weight: 500;
cursor: pointer;
transition: background 0.2s, transform 0.1s;
}
.btn:active {
transform: scale(0.98);
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
}
.btn svg {
width: 18px;
height: 18px;
}
.btn-send {
background: var(--btn-send);
color: white;
}
.btn-send:hover:not(:disabled) {
background: var(--btn-send-hover);
}
.btn-stop {
background: var(--btn-stop);
color: white;
}
.btn-stop:hover:not(:disabled) {
background: var(--btn-stop-hover);
}
.btn-receive {
background: var(--btn-bg);
color: var(--text-color);
}
.btn-receive:hover:not(:disabled) {
background: var(--btn-hover);
}
/* TX frequency controls */
.freq-row {
display: flex;
align-items: center;
gap: 0.5rem;
margin-top: 0.75rem;
}
.freq-row label {
font-size: 0.875rem;
color: var(--text-muted);
white-space: nowrap;
}
.freq-row input[type="number"] {
width: 8.5rem;
padding: 0.5rem 0.65rem;
border: 1px solid var(--border-color);
border-radius: 0.5rem;
background: var(--panel-bg);
color: var(--text-color);
font-family: inherit;
font-size: 0.9375rem;
}
.freq-row input[type="number"]:focus {
outline: none;
border-color: var(--accent);
}
.freq-row .btn {
flex: 0 0 auto;
padding: 0.5rem 0.75rem;
font-size: 0.875rem;
}
/* Status indicator */
.status {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.875rem;
color: var(--text-muted);
margin-top: 0.5rem;
min-height: 1.5rem;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--text-muted);
}
.status-dot.sending {
background: var(--btn-send);
animation: pulse 0.5s ease-in-out infinite;
}
.status-dot.recording {
background: var(--btn-stop);
animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.4; }
}
/* Tap visualization */
.tap-viz {
display: flex;
align-items: center;
gap: 0.25rem;
margin-top: 0.5rem;
min-height: 24px;
font-family: monospace;
font-size: 0.875rem;
color: var(--text-muted);
}
/* Info section */
.info {
background: var(--panel-bg);
border-radius: 0.75rem;
padding: 1rem;
font-size: 0.8125rem;
color: var(--text-muted);
line-height: 1.6;
}
.info h3 {
font-size: 0.875rem;
font-weight: 600;
color: var(--text-color);
margin-bottom: 0.5rem;
}
.info ul {
margin: 0.5rem 0;
padding-left: 1.25rem;
}
.info li {
margin: 0.25rem 0;
}
.info code {
background: var(--btn-bg);
padding: 0.125rem 0.375rem;
border-radius: 0.25rem;
font-size: 0.75rem;
}
/* Debug section */
.debug {
background: var(--panel-bg);
border-radius: 0.75rem;
padding: 1rem;
border: 1px solid var(--border-color);
margin-top: 1.5rem;
}
.debug h3 {
font-size: 0.875rem;
font-weight: 600;
color: var(--text-color);
margin-bottom: 0.5rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.debug p {
font-size: 0.8125rem;
color: var(--text-muted);
line-height: 1.5;
margin-bottom: 0.75rem;
}
.debug-grid {
display: grid;
gap: 0.75rem;
}
.debug-card {
border: 1px solid var(--border-color);
border-radius: 0.5rem;
padding: 0.75rem;
background: var(--bg-color);
}
.debug-card {
cursor: pointer;
}
.debug-card:focus {
outline: 2px solid var(--grid-active);
outline-offset: 2px;
}
.debug-title {
font-size: 0.8125rem;
font-weight: 600;
color: var(--text-color);
margin-bottom: 0.5rem;
display: flex;
justify-content: space-between;
gap: 0.5rem;
flex-wrap: wrap;
}
.debug-meta {
font-size: 0.75rem;
color: var(--text-muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
canvas.debug-canvas {
width: 100%;
height: 140px;
display: block;
border-radius: 0.375rem;
background: var(--panel-bg);
}
/* Fullscreen debug modal */
.dbg-modal {
position: fixed;
inset: 0;
z-index: 9999;
display: none;
background: var(--panel-bg);
touch-action: none;
}
.dbg-modal.open {
display: block;
}
.dbg-modal canvas {
display: block;
width: 100vw;
height: 100vh;
}
.dbg-modal .dbg-modal-close {
position: fixed;
top: 0.75rem;
right: 0.75rem;
z-index: 10000;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
padding: 0.55rem 0.75rem;
border: 1px solid var(--border-color);
border-radius: 0.65rem;
background: rgba(0, 0, 0, 0.06);
color: var(--text-color);
cursor: pointer;
font-size: 0.9rem;
font-weight: 600;
touch-action: manipulation;
user-select: none;
-webkit-tap-highlight-color: transparent;
backdrop-filter: blur(6px);
}
[data-theme="dark"] .dbg-modal .dbg-modal-close {
background: rgba(255, 255, 255, 0.08);
}
.dbg-modal .dbg-modal-close:hover {
background: rgba(0, 0, 0, 0.10);
}
[data-theme="dark"] .dbg-modal .dbg-modal-close:hover {
background: rgba(255, 255, 255, 0.12);
}
.dbg-modal .dbg-modal-close:active {
transform: scale(0.98);
}
.dbg-modal .dbg-modal-close:focus {
outline: 2px solid var(--grid-active);
outline-offset: 2px;
}
@media (max-width: 480px) {
.tap-grid {
font-size: 0.75rem;
}
.grid-cell {
padding: 0.5rem 0.25rem;
}
.grid-cell.letter {
font-size: 1.25rem;
}
.grid-cell.ck {
font-size: 0.95rem;
}
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>
<svg viewBox="0 0 24 24" width="28" height="28" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z"/>
<path d="M19 10v2a7 7 0 0 1-14 0v-2"/>
<line x1="12" y1="19" x2="12" y2="22"/>
</svg>
Tap Code
</h1>
<button class="theme-btn" id="themeBtn" aria-label="Toggle theme">
<svg id="systemIcon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:none">
<rect x="3" y="4" width="18" height="12" rx="2" />
<path d="M8 20h8" />
<path d="M12 16v4" />
</svg>
<svg id="sunIcon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="5"/>
<line x1="12" y1="1" x2="12" y2="3"/>
<line x1="12" y1="21" x2="12" y2="23"/>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
<line x1="1" y1="12" x2="3" y2="12"/>
<line x1="21" y1="12" x2="23" y2="12"/>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
</svg>
<svg id="moonIcon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:none">
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
</svg>
</button>
</header>
<!-- Tap Code Grid -->
<section class="grid-section" aria-label="Tap Code Reference Grid">
<div class="section-label">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<rect x="3" y="3" width="7" height="7"/>
<rect x="14" y="3" width="7" height="7"/>
<rect x="14" y="14" width="7" height="7"/>
<rect x="3" y="14" width="7" height="7"/>
</svg>
Polybius Square (5×5)
</div>
<div class="tap-grid" id="tapGrid" role="grid" aria-label="Tap code grid">
<div class="grid-header"></div>
<div class="grid-header">1</div>
<div class="grid-header">2</div>
<div class="grid-header">3</div>
<div class="grid-header">4</div>
<div class="grid-header">5</div>
<div class="grid-header">1</div>
<div class="grid-cell letter" data-pos="1,1">A</div>
<div class="grid-cell letter" data-pos="1,2">B</div>
<div class="grid-cell letter ck" data-pos="1,3">C/K</div>
<div class="grid-cell letter" data-pos="1,4">D</div>
<div class="grid-cell letter" data-pos="1,5">E</div>
<div class="grid-header">2</div>
<div class="grid-cell letter" data-pos="2,1">F</div>
<div class="grid-cell letter" data-pos="2,2">G</div>
<div class="grid-cell letter" data-pos="2,3">H</div>
<div class="grid-cell letter" data-pos="2,4">I</div>
<div class="grid-cell letter" data-pos="2,5">J</div>
<div class="grid-header">3</div>
<div class="grid-cell letter" data-pos="3,1">L</div>
<div class="grid-cell letter" data-pos="3,2">M</div>
<div class="grid-cell letter" data-pos="3,3">N</div>
<div class="grid-cell letter" data-pos="3,4">O</div>
<div class="grid-cell letter" data-pos="3,5">P</div>
<div class="grid-header">4</div>
<div class="grid-cell letter" data-pos="4,1">Q</div>
<div class="grid-cell letter" data-pos="4,2">R</div>
<div class="grid-cell letter" data-pos="4,3">S</div>
<div class="grid-cell letter" data-pos="4,4">T</div>
<div class="grid-cell letter" data-pos="4,5">U</div>
<div class="grid-header">5</div>
<div class="grid-cell letter" data-pos="5,1">V</div>
<div class="grid-cell letter" data-pos="5,2">W</div>
<div class="grid-cell letter" data-pos="5,3">X</div>
<div class="grid-cell letter" data-pos="5,4">Y</div>
<div class="grid-cell letter" data-pos="5,5">Z</div>
</div>
</section>
<!-- Send Section -->
<section class="io-section" aria-label="Send message">
<label class="io-label" for="sendInput">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<line x1="22" y1="2" x2="11" y2="13"/>
<polygon points="22 2 15 22 11 13 2 9 22 2"/>
</svg>
Message to Send
</label>
<textarea id="sendInput" placeholder="Type message to send as tap code..." aria-describedby="sendHelp"></textarea>
<div class="btn-group">
<button class="btn btn-receive" id="encodeBtn" aria-label="Encode message to dot lines">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M4 7h16" />
<path d="M4 12h10" />
<path d="M4 17h16" />
<circle cx="18" cy="12" r="1.5" fill="currentColor" stroke="none" />
<circle cx="21" cy="12" r="1.5" fill="currentColor" stroke="none" />
</svg>
Encode
</button>
<button class="btn btn-send" id="sendBtn" aria-label="Start sending">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<polygon points="5 3 19 12 5 21 5 3"/>
</svg>
Send
</button>
<button class="btn btn-stop" id="stopSendBtn" disabled aria-label="Stop sending">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<rect x="6" y="6" width="12" height="12" rx="2"/>
</svg>
Stop
</button>
</div>
<div class="freq-row" aria-label="Transmit tone frequency">
<label for="txFreqHz">Tone (Hz)</label>
<input id="txFreqHz" type="number" inputmode="numeric" min="200" max="4000" step="10" aria-label="Transmit tone frequency in Hz" />
<button class="btn btn-receive" id="txFreqResetBtn" type="button" aria-label="Reset tone frequency">Reset</button>
</div>
<div class="btn-group" aria-label="Export audio">
<button class="btn btn-receive" id="exportSendWavBtn" type="button" aria-label="Export current send message as WAV">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="7 10 12 15 17 10"/>
<line x1="12" y1="15" x2="12" y2="3"/>
</svg>
Export WAV
</button>
</div>
<label class="io-label" for="encodedDots" style="margin-top: 1rem;">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M4 7h16" />
<path d="M4 12h16" />
<path d="M4 17h16" />
</svg>
Encoded (dots, one line per character)
</label>
<textarea id="encodedDots" class="mono" placeholder="Example:\n•• •••\n• •••••\n\n(blank line = space)" aria-label="Encoded dot lines"></textarea>
<div class="btn-group">
<button class="btn btn-receive" id="decodeDotsBtn" aria-label="Decode dot lines into received message">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M4 7h16" />
<path d="M4 12h10" />
<path d="M4 17h16" />
<path d="M16 10l4 2-4 2" />
</svg>
Decode
</button>
<button class="btn btn-receive" id="copyDotsBtn" aria-label="Copy encoded dot lines to clipboard">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<rect x="9" y="9" width="13" height="13" rx="2" />
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
</svg>
Copy
</button>
</div>
<div class="status" id="sendStatus">
<span class="status-dot" id="sendDot"></span>
<span id="sendStatusText">Ready to send</span>
</div>
<div class="tap-viz" id="sendViz" aria-live="polite"></div>
</section>
<!-- Receive Section -->
<section class="io-section" aria-label="Receive message">
<label class="io-label" for="receiveOutput">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="7 10 12 15 17 10"/>
<line x1="12" y1="15" x2="12" y2="3"/>
</svg>
Received Message
</label>
<textarea id="receiveOutput" readonly placeholder="Decoded message will appear here..."></textarea>
<div class="btn-group">
<button class="btn btn-receive" id="receiveBtn" aria-label="Start recording">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<circle cx="12" cy="12" r="10"/>
<circle cx="12" cy="12" r="4" fill="currentColor"/>
</svg>
Record
</button>
<button class="btn btn-stop" id="stopReceiveBtn" disabled aria-label="Stop recording and decode">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<rect x="6" y="6" width="12" height="12" rx="2"/>
</svg>
Stop & Decode
</button>
<button class="btn btn-receive" id="copyReceivedBtn" aria-label="Copy received message to clipboard">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<rect x="9" y="9" width="13" height="13" rx="2" />
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
</svg>
Copy
</button>
</div>
<div class="btn-group" aria-label="Audio import and export">
<button class="btn btn-receive" id="importAudioBtn" type="button" aria-label="Import audio file and decode">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
Import Audio
</button>
<input id="importAudioFile" type="file" accept="audio/*,.wav,.mp3,.ogg,.webm" style="display:none" />
</div>
<div class="status" id="receiveStatus">
<span class="status-dot" id="receiveDot"></span>
<span id="receiveStatusText">Ready to receive</span>
</div>
</section>
<!-- Info Section -->
<section class="info" aria-label="How it works">
<h3>How Tap Code Works</h3>
<p>Each letter is encoded as two numbers: <strong>row</strong> then <strong>column</strong>.</p>
<ul>
<li><strong>H</strong> = row 2, col 3 → <code>•• •••</code> (2 taps, pause, 3 taps)</li>
<li><strong>K</strong> uses <strong>C</strong>'s position (1,3)</li>
<li><strong>X</strong> alone can mean a full stop (.)</li>
</ul>
<p><strong>Timing:</strong> Short pause between row/col. Longer pause between letters. Longest pause between words.</p>
<p><strong>Symbols:</strong> Numbers spelled out (ONE, TWO...). Special chars: <code>AMP</code> (&), <code>AT</code> (@), etc.</p>
<p><strong>Receiver:</strong> Uses 800Hz tone detection with SNR analysis—works even with low volume tones in noisy environments or with speech.</p>
</section>
<!-- Debug Section -->
<section class="debug" aria-label="Receiver debug analysis">
<h3>
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M4 19h16" />
<path d="M4 15l4-4 4 4 4-8 4 4" />
</svg>
Debug (Receiver)
</h3>
<p>Shows the spectrum for each processing step (raw → filtered) and the final envelope used for edge detection.</p>
<div class="debug-grid">
<div class="debug-card" data-debug-open="raw-spectrum" role="button" tabindex="0" aria-label="Open raw mic spectrum fullscreen">
<div class="debug-title">
<span>Raw mic spectrum</span>
<span class="debug-meta" id="dbgRawMeta">—</span>
</div>
<canvas class="debug-canvas" id="dbgRawSpectrum" width="900" height="200" aria-label="Raw spectrum canvas"></canvas>
</div>
<div class="debug-card" data-debug-open="raw-waterfall" role="button" tabindex="0" aria-label="Open raw waterfall fullscreen">
<div class="debug-title">
<span>Raw waterfall (sideways)</span>
<span class="debug-meta" id="dbgRawWaterMeta">—</span>
</div>
<canvas class="debug-canvas" id="dbgRawWaterfall" width="900" height="220" aria-label="Raw sideways waterfall canvas"></canvas>
</div>
<div class="debug-card" data-debug-open="filtered-spectrum" role="button" tabindex="0" aria-label="Open filtered spectrum fullscreen">
<div class="debug-title">
<span>Filtered spectrum (band-pass)</span>
<span class="debug-meta" id="dbgFiltMeta">—</span>
</div>
<canvas class="debug-canvas" id="dbgFilteredSpectrum" width="900" height="200" aria-label="Filtered spectrum canvas"></canvas>
</div>
<div class="debug-card" data-debug-open="filtered-waterfall" role="button" tabindex="0" aria-label="Open filtered waterfall fullscreen">
<div class="debug-title">
<span>Filtered waterfall (sideways)</span>
<span class="debug-meta" id="dbgFiltWaterMeta">—</span>
</div>
<canvas class="debug-canvas" id="dbgFilteredWaterfall" width="900" height="220" aria-label="Filtered sideways waterfall canvas"></canvas>
</div>
<div class="debug-card" data-debug-open="envelope" role="button" tabindex="0" aria-label="Open envelope and detected taps fullscreen">
<div class="debug-title">
<span>Envelope + detected taps</span>
<span class="debug-meta" id="dbgEnvMeta">—</span>
</div>
<canvas class="debug-canvas" id="dbgEnvelope" width="900" height="200" aria-label="Envelope canvas"></canvas>
</div>
<div class="debug-card" data-debug-open="time-domain" role="button" tabindex="0" aria-label="Open time-domain level and edges fullscreen">
<div class="debug-title">
<span>Time-domain level + edges (filtered)</span>
<span class="debug-meta" id="dbgTimeMeta">—</span>
</div>
<canvas class="debug-canvas" id="dbgTimeDomain" width="900" height="220" aria-label="Time-domain debug canvas"></canvas>
</div>
</div>
</section>
<div class="dbg-modal" id="dbgModal" role="dialog" aria-modal="true" aria-label="Debug fullscreen view">
<button class="dbg-modal-close" id="dbgModalCloseBtn" type="button" aria-label="Close fullscreen chart">Close</button>
<canvas id="dbgModalCanvas"></canvas>
</div>
</div>
<script>
// Tap Code Grid: A-Z without K (C/K share position 1,3)
const TAP_GRID = [
['A', 'B', 'C', 'D', 'E'], // row 1
['F', 'G', 'H', 'I', 'J'], // row 2
['L', 'M', 'N', 'O', 'P'], // row 3
['Q', 'R', 'S', 'T', 'U'], // row 4
['V', 'W', 'X', 'Y', 'Z'] // row 5
];
// Letter to [row, col] mapping (1-indexed)
const LETTER_TO_POS = {};
TAP_GRID.forEach((row, ri) => {
row.forEach((letter, ci) => {
LETTER_TO_POS[letter] = [ri + 1, ci + 1];
});
});
LETTER_TO_POS['K'] = [1, 3]; // K uses C's position
// Position to letter (for decoding)
const POS_TO_LETTER = {};
TAP_GRID.forEach((row, ri) => {
row.forEach((letter, ci) => {
POS_TO_LETTER[`${ri + 1},${ci + 1}`] = letter;
});
});
// Symbol substitutions
const SYMBOL_MAP = {
'.': 'X', // Full stop
',': 'COMMA',
'?': 'QM',
'!': 'EM',
"'": 'APO',
'"': 'QUO',
'@': 'AT',
'&': 'AMP',
'#': 'HASH',
'$': 'DOL',
'%': 'PCT',
'+': 'PLUS',
'-': 'DASH',
'=': 'EQ',
'/': 'SL',
'\\': 'BSL',
'*': 'STAR',
'(': 'LP',
')': 'RP',
'[': 'LB',
']': 'RB',
'{': 'LC',
'}': 'RC',
'<': 'LT',
'>': 'GT',
':': 'COL',
';': 'SEMI',
'_': 'UND',
'^': 'CAR',
'~': 'TIL',
'|': 'PIPE',
'`': 'BT',
'0': 'ZERO',
'1': 'ONE',
'2': 'TWO',
'3': 'THREE',
'4': 'FOUR',
'5': 'FIVE',
'6': 'SIX',
'7': 'SEVEN',
'8': 'EIGHT',
'9': 'NINE'
};
// Reverse map for decoding SYM escapes back to original characters.
const TOKEN_TO_SYMBOL = Object.fromEntries(
Object.entries(SYMBOL_MAP).map(([symbol, token]) => [token, symbol])
);
// Timing constants (ms)
const TIMING = {
TAP_DURATION: 90, // More robust over speaker/mic/phone
INTRA_TAP: 90, // 1x unit
ROW_COL_PAUSE: 270, // 3x unit (switch row->col)
LETTER_PAUSE: 540, // 6x unit (end of letter)
WORD_PAUSE: 900 // word gap (>= ~10x)
};
const TX_DEFAULT_FREQ = 800; // Hz (within phone band)
// Audio context
let audioCtx = null;
function getAudioContext() {
if (!audioCtx) {
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
}
return audioCtx;
}
// Text preprocessing: convert to tap-codeable format
// Output must be only A-Z and spaces (tap code can't represent digits directly).
function preprocessText(text) {
let result = '';
const input = String(text ?? '');
const hexDigitToTapToken = (hexDigit) => {
// Keep A-F as-is, convert 0-9 to their word tokens.
if (hexDigit >= '0' && hexDigit <= '9') return SYMBOL_MAP[hexDigit];
return hexDigit; // A-F