-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
1036 lines (952 loc) · 47.9 KB
/
Copy pathindex.html
File metadata and controls
1036 lines (952 loc) · 47.9 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, viewport-fit=cover">
<meta name="description" content="Clean up document photos: remove shadows and uneven lighting, entirely in your browser. ZigZag — ACM DocEng'24.">
<meta property="og:title" content="ZigZag — Document Image Binarizer">
<meta property="og:description" content="Remove shadows and uneven lighting from document photos. 100% in-browser, nothing leaves your device.">
<meta property="og:image" content="https://bloechle.github.io/zigzag/assets/zigzag-logo.png">
<meta property="og:url" content="https://bloechle.github.io/zigzag/">
<meta property="og:type" content="website">
<meta name="twitter:card" content="summary_large_image">
<meta name="theme-color" content="#0a0a0b">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<link rel="manifest" href="manifest.json">
<link rel="apple-touch-icon" href="assets/icon-192.png">
<title>ZigZag — Document Image Binarizer</title>
<link rel="icon" href="assets/icon-192.png">
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #0a0a0b;
--bg-elevated: #1c1c1f;
--bg-hover: #252528;
--border: #2a2a2e;
--text: #e4e4e7;
--dim: #a1a1aa;
--muted: #52525b;
--accent: #005393; /* corporate blue — fills */
--accent-soft: #4da3dd; /* readable tint of it on dark — text & glows */
--ok: #34d399;
--radius: 12px;
--ease: cubic-bezier(0.16, 1, 0.3, 1);
--safe-t: env(safe-area-inset-top, 0px);
--safe-b: env(safe-area-inset-bottom, 0px);
}
html, body {
height: 100%;
background: var(--bg);
color: var(--text);
font: 15px/1.5 -apple-system, system-ui, 'Segoe UI', Roboto, sans-serif;
overflow: hidden;
-webkit-font-smoothing: antialiased;
user-select: none;
-webkit-user-select: none;
touch-action: manipulation;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
/* ═══ LANDING ═══ */
#landing {
position: fixed; inset: 0; z-index: 50;
display: flex; align-items: center; justify-content: center;
padding: 24px; padding-top: calc(24px + var(--safe-t)); padding-bottom: calc(24px + var(--safe-b));
background:
radial-gradient(60% 40% at 50% 0%, rgba(77, 163, 221, .08), transparent 70%),
var(--bg);
}
.landing-content { width: 100%; max-width: 340px; text-align: center; }
.landing-content img { width: 84px; height: 84px; margin-bottom: 18px; }
.landing-content h1 { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; }
.landing-sub { color: var(--dim); margin: 2px 0 10px; }
.landing-desc { color: var(--muted); font-size: .85rem; line-height: 1.55; margin-bottom: 28px; }
.landing-buttons { display: grid; gap: 10px; margin-bottom: 18px; }
.btn-primary, .btn-secondary {
display: flex; align-items: center; justify-content: center; gap: 9px;
padding: 15px; border-radius: var(--radius); font-weight: 600; font-size: .95rem;
transition: transform .15s var(--ease), background .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--bg-elevated); border: 1px solid var(--border); }
.btn-primary:active, .btn-secondary:active { transform: scale(.97); }
.landing-hint { color: var(--muted); font-size: .78rem; }
.link-btn { color: var(--accent-soft); font-size: inherit; text-decoration: underline; text-underline-offset: 2px; }
.link-btn:disabled { opacity: .5; }
#gpuStatus { margin-top: 8px; font-size: .72rem; color: var(--muted); min-height: 1.2em; }
#gpuStatus.on { color: var(--ok); }
.landing-credits {
margin-top: 30px; font-size: .72rem; color: var(--muted);
display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
}
.landing-credits a { color: var(--dim); text-decoration: none; border-bottom: 1px solid var(--border); }
/* ═══ APP ═══ */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#viewport { flex: 1; position: relative; min-height: 0; overflow: hidden; }
/* comparison: result below, original clipped above, draggable line */
#compareWrap {
position: absolute; top: 0; left: 0;
transform-origin: 0 0; touch-action: none;
--invz: 1; /* 1/zoom — keeps overlays at constant screen size */
}
#compareWrap canvas {
position: absolute; inset: 0;
border-radius: 8px; box-shadow: 0 8px 40px rgba(0, 0, 0, .55);
}
#compareClip { position: absolute; inset: 0 auto 0 0; width: 50%; overflow: hidden; }
#compareClip canvas { position: absolute; top: 0; left: 0; border-radius: 8px 0 0 8px; }
#compareLine {
position: absolute; top: 0; bottom: 0; left: 50%; width: calc(2px * var(--invz));
background: var(--accent); transform: translateX(-50%);
box-shadow: 0 0 12px rgba(77, 163, 221, .55);
}
.compare-handle {
position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(var(--invz));
width: 38px; height: 38px; border-radius: 50%;
background: var(--accent); color: #fff;
display: flex; align-items: center; justify-content: center;
}
#compareWrap.toggled #compareLine,
#compareWrap.toggled #tagResult { display: none; }
.corner-tag {
position: absolute; top: 8px; font-size: .62rem; font-weight: 700; letter-spacing: .08em;
padding: 3px 8px; border-radius: 5px; background: rgba(10, 10, 11, .65);
backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
color: var(--dim); pointer-events: none;
transform: scale(var(--invz));
}
#tagOriginal { left: 8px; transform-origin: top left; }
#tagResult { right: 8px; transform-origin: top right; }
#infoBadge {
position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
max-width: calc(100% - 20px); text-align: center; line-height: 1.4;
font-size: .7rem; color: var(--dim); padding: 5px 12px; border-radius: 14px;
background: rgba(28, 28, 31, .75); border: 1px solid var(--border);
backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
transition: transform .3s var(--ease);
}
/* keep the live readout visible above the settings sheet */
#app.sheet-open #infoBadge { transform: translate(-50%, calc(-1 * var(--sheet-h, 0px) - 8px)); }
#infoBadge:empty { display: none; }
#spinner {
position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
background: rgba(10, 10, 11, .35); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
}
.spinner-ring {
width: 38px; height: 38px; border-radius: 50%;
border: 3px solid var(--border); border-top-color: var(--accent-soft);
animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* ═══ BOTTOM BAR ═══ */
.bottom-bar {
flex-shrink: 0; padding: 10px 12px calc(10px + var(--safe-b));
background: rgba(20, 20, 22, .85); border-top: 1px solid var(--border);
backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.mode-row {
display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
padding: 4px; margin-bottom: 10px;
}
.mode-btn {
padding: 9px 0; border-radius: 7px; font-size: .82rem; font-weight: 600; color: var(--dim);
transition: background .15s, color .15s;
}
.mode-btn.active { background: var(--accent); color: #fff; }
.action-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; }
.action-btn {
display: flex; flex-direction: column; align-items: center; gap: 4px;
padding: 8px 2px 6px; border-radius: 9px; font-size: .66rem; color: var(--dim);
transition: background .15s;
}
.action-btn:active { background: var(--bg-hover); }
.action-btn:disabled { opacity: .35; }
.action-btn.accent { color: var(--accent-soft); }
/* ═══ SETTINGS SHEET ═══ */
#sheet { position: fixed; inset: 0; z-index: 60; }
.sheet-backdrop { position: absolute; inset: 0; } /* click-to-close, no dimming: live preview stays visible */
.sheet-panel {
position: absolute; left: 0; right: 0; bottom: 0;
background: var(--bg-elevated); border-radius: 18px 18px 0 0;
border-top: 1px solid var(--border);
padding: 8px 20px calc(22px + var(--safe-b));
transform: translateY(0); transition: transform .3s var(--ease);
}
#sheet.hidden-anim .sheet-panel { transform: translateY(100%); }
.sheet-drag-bar { width: 36px; height: 4px; border-radius: 2px; background: var(--border); margin: 4px auto 14px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.sheet-title { font-weight: 600; font-size: .95rem; }
.sheet-reset { font-size: .8rem; font-weight: 600; color: var(--accent-soft); padding: 4px 8px; }
.sheet-actions { display: flex; align-items: center; gap: 4px; }
.sheet-help {
width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--border);
color: var(--dim); font-size: .72rem; font-weight: 700; line-height: 1;
display: flex; align-items: center; justify-content: center;
transition: background .15s, color .15s, border-color .15s;
}
.sheet-help[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.param-row { display: grid; grid-template-columns: 88px 1fr 50px; align-items: center; gap: 12px; margin-bottom: 14px; }
.param-row label { font-size: .8rem; color: var(--dim); }
.param-val { font-size: .8rem; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.param-hint {
grid-column: 1 / -1; display: none;
font-size: .72rem; color: var(--muted); line-height: 1.45; margin: 2px 0 2px;
}
#sheet.hints .param-hint { display: block; }
input[type=range] { -webkit-appearance: none; appearance: none; height: 4px; border-radius: 2px; background: var(--border); outline: none; }
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none; appearance: none; width: 22px; height: 22px; border-radius: 50%;
background: var(--accent); border: none; cursor: pointer;
}
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); border: none; }
/* ═══ DROP OVERLAY (desktop) ═══ */
#dropOverlay {
position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center;
background: rgba(10, 10, 11, .85); border: 2px dashed var(--accent-soft); border-radius: 16px;
}
.drop-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--accent-soft); font-weight: 600; }
</style>
</head>
<body>
<!-- ═══ LANDING ═══ -->
<div id="landing">
<div class="landing-content">
<img src="assets/zigzag-logo.png" alt="ZigZag">
<h1>ZigZag</h1>
<p class="landing-sub">Clean up document photos</p>
<p class="landing-desc">Remove shadows and uneven lighting instantly. 100% private — nothing leaves your device.</p>
<div class="landing-buttons">
<button id="btnCamera" class="btn-primary">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/></svg>
Take a photo
</button>
<button id="btnGallery" class="btn-secondary">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>
Choose an image
</button>
</div>
<p class="landing-hint">or drop / paste an image · <button id="btnExample" class="link-btn">try an example</button></p>
<div id="gpuStatus" role="status"></div>
<div class="landing-credits">
<a href="https://github.com/Bloechle/zigzag" target="_blank" rel="noopener">GitHub</a>
<span>·</span>
<a href="https://doi.org/10.1145/3685650.3685661" target="_blank" rel="noopener">DocEng'24 paper</a>
<span>·</span>
<span>Bloechle, Hennebert & Gisler</span>
</div>
</div>
</div>
<!-- ═══ APP ═══ -->
<div id="app" class="hidden">
<div id="viewport">
<div id="compareWrap">
<canvas id="canvasResult" role="img" aria-label="Cleaned-up document"></canvas>
<div id="compareClip"><canvas id="canvasOriginal" role="img" aria-label="Original photo"></canvas></div>
<span id="tagOriginal" class="corner-tag">ORIGINAL</span>
<span id="tagResult" class="corner-tag">ZIGZAG</span>
<div id="compareLine">
<div class="compare-handle">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="9 6 4 12 9 18"/><polyline points="15 6 20 12 15 18"/></svg>
</div>
</div>
</div>
<div id="infoBadge" role="status"></div>
<div id="spinner" class="hidden"><div class="spinner-ring"></div></div>
</div>
<div class="bottom-bar">
<div class="mode-row" id="modeRow" role="radiogroup" aria-label="Output mode">
<button class="mode-btn active" data-mode="binary" role="radio" aria-checked="true">B&W</button>
<button class="mode-btn" data-mode="gray" role="radio" aria-checked="false">Gray</button>
<button class="mode-btn" data-mode="color" role="radio" aria-checked="false">Color</button>
</div>
<div class="action-row">
<button id="btnNew" class="action-btn" title="New image (N)">
<svg width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/></svg>
<span>New</span>
</button>
<button id="btnRotate" class="action-btn" title="Rotate 90° (R)" disabled>
<svg width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg>
<span>Rotate</span>
</button>
<button id="btnTune" class="action-btn" title="Settings (T)">
<svg width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><line x1="4" y1="21" x2="4" y2="14"/><line x1="4" y1="10" x2="4" y2="3"/><line x1="12" y1="21" x2="12" y2="12"/><line x1="12" y1="8" x2="12" y2="3"/><line x1="20" y1="21" x2="20" y2="16"/><line x1="20" y1="12" x2="20" y2="3"/><line x1="1" y1="14" x2="7" y2="14"/><line x1="9" y1="8" x2="15" y2="8"/><line x1="17" y1="16" x2="23" y2="16"/></svg>
<span>Tune</span>
</button>
<button id="btnShare" class="action-btn" title="Share or copy (C)" disabled>
<span class="icon-share"><svg width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"/><polyline points="16 6 12 2 8 6"/><line x1="12" y1="2" x2="12" y2="15"/></svg></span>
<span class="icon-copy"><svg width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><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></span>
<span class="lbl">Copy</span>
</button>
<button id="btnSave" class="action-btn accent" title="Save PNG (S)" disabled>
<svg width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><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>
<span>Save</span>
</button>
</div>
</div>
<div id="sheet" class="hidden hidden-anim">
<div class="sheet-backdrop" id="sheetBackdrop"></div>
<div class="sheet-panel" id="sheetPanel">
<div class="sheet-drag-bar"></div>
<div class="sheet-head">
<span class="sheet-title">Settings</span>
<div class="sheet-actions">
<button id="btnHints" class="sheet-help" aria-pressed="false"
aria-label="Explain these settings" title="Explain these settings">?</button>
<button id="btnReset" class="sheet-reset">Reset</button>
</div>
</div>
<div class="param-row">
<label for="slSize">Window</label>
<input type="range" id="slSize"
title="Size of the local analysis window, in pixels.">
<span id="valSize" class="param-val">30 px</span>
<p class="param-hint">How far ZigZag looks around each pixel to judge the local lighting.
Lower it for fine print, raise it for large text or broad shadows.</p>
</div>
<div class="param-row">
<label for="slWeight">Background</label>
<input type="range" id="slWeight"
title="How bright a pixel must be, relative to its neighbours, to count as background.">
<span id="valWeight" class="param-val">90 %</span>
<p class="param-hint">How bright a pixel must be, next to its neighbours, to be treated as
background. Lower it to about 60 % to rescue faint ink on degraded documents.</p>
</div>
<div class="param-row">
<label for="slThr">Ink</label>
<input type="range" id="slThr"
title="Shifts the automatic threshold.">
<span id="valThr" class="param-val">0</span>
<p class="param-hint">Nudges the automatic threshold. Positive keeps more ink — bolder, but
noisier; negative cleans harder at the risk of thinning strokes.</p>
</div>
</div>
</div>
</div>
<!-- ═══ DROP OVERLAY ═══ -->
<div id="dropOverlay" class="hidden">
<div class="drop-inner">
<svg width="38" height="38" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><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>
<span>Drop image to process</span>
</div>
</div>
<input type="file" id="fileCamera" accept="image/*" capture="environment" hidden>
<input type="file" id="fileGallery" accept="image/*" hidden>
<script type="module">
import { ZigZag, MODES } from './js/zigzag.js';
import { ZigZagGPU } from './js/zigzag-gpu.js';
// PWA: offline cache + installability (no-op on file:// or unsupported)
if ('serviceWorker' in navigator && location.protocol.startsWith('http')) {
addEventListener('load', () => navigator.serviceWorker.register('sw.js').catch(() => {}));
}
const $ = id => document.getElementById(id);
const el = {};
['landing', 'app', 'viewport', 'compareWrap', 'compareClip', 'compareLine',
'canvasOriginal', 'canvasResult', 'infoBadge', 'spinner', 'gpuStatus',
'btnCamera', 'btnGallery', 'btnExample',
'btnNew', 'btnRotate', 'btnTune', 'btnShare', 'btnSave',
'modeRow', 'sheet', 'sheetBackdrop', 'sheetPanel', 'btnReset',
'slSize', 'slWeight', 'slThr', 'valSize', 'valWeight', 'valThr', 'btnHints',
'dropOverlay', 'fileCamera', 'fileGallery'].forEach(id => el[id] = $(id));
const SLIDERS = [['slSize', 'valSize'], ['slWeight', 'valWeight'], ['slThr', 'valThr']];
const UNITS = { slSize: ' px', slWeight: ' %', slThr: '' };
// Discrete scales: the slider carries an *index*, the value comes from here.
// Window stops at 128: past ~192 the local mean drifts toward global and the
// shadow comes back as ink, and at 256 (2r+1)^2*255 crosses 2^24, the largest
// integer the GPU's f32 box sums still represent exactly.
// Weight steps of 5 were indistinguishable (<0.15 pt of ink), so 10.
// Ink stops at +/-60: beyond it the threshold saturates instead of nudging.
const SCALES = {
slSize: [4, 8, 12, 16, 20, 24, 30, 40, 56, 80, 128],
slWeight: [50, 60, 70, 80, 90, 100],
slThr: Array.from({ length: 25 }, (_, i) => -60 + i * 5),
};
const DEFAULTS = { slSize: 30, slWeight: 90, slThr: 0 };
const sliderValue = s => SCALES[s][+el[s].value];
/** Snap a raw value onto a scale (also migrates prefs from an older scale). */
function setSliderValue(s, v) {
const scale = SCALES[s];
let best = 0;
for (let i = 1; i < scale.length; i++) {
if (Math.abs(scale[i] - v) < Math.abs(scale[best] - v)) best = i;
}
el[s].value = best;
}
const PREFS_KEY = 'zigzag.prefs';
// The CPU port needs ~64 bytes/pixel of float64 scratch and runs at ~0.4 s/MP,
// so it gets a much tighter budget than the GPU (whose ceiling is a device limit).
const CPU_MAX_PIXELS = 4_000_000;
const GPU_MAX_PIXELS = 12_000_000;
let gpu = null; // WebGPU accelerator, null => CPU
let worker = null; // CPU port off the main thread, null => inline
let srcImage = null; // ImageData of the (possibly downscaled) source
let srcName = 'document';
let origSize = null; // [w, h] before downscale, or null
let mode = 'binary';
let busy = false, pending = false, debounceId = 0;
let comparePos = 0.5, toggled = false;
let allowUpsample = true; // cleared if the browser refuses the 2x canvas
let sheetOpen = false;
let lastBadge = '', badgeTimer = 0;
// ── backends ──
if (ZigZagGPU.isSupported()) {
try {
const g = new ZigZagGPU();
await g.init();
gpu = g;
} catch { gpu = null; }
}
/** Landing-page backend line — also refreshed when the GPU is dropped mid-session. */
function setGpuStatus() {
el.gpuStatus.textContent = gpu ? '⚡ WebGPU acceleration active' : 'Running on CPU';
el.gpuStatus.classList.toggle('on', !!gpu);
}
setGpuStatus();
const jobs = new Map();
let jobId = 0;
try {
worker = new Worker(new URL('./js/zigzag-worker.js', import.meta.url), { type: 'module' });
worker.onmessage = e => {
const done = jobs.get(e.data.id);
jobs.delete(e.data.id);
done?.(e.data.error ? null : e.data);
};
worker.onerror = () => { // module workers unsupported / failed
worker = null;
for (const done of jobs.values()) done(null);
jobs.clear();
};
} catch { worker = null; }
/** CPU pipeline, in the worker when available, inline otherwise. */
function cpuProcess(opts) {
if (!worker) return Promise.resolve(ZigZag.process(srcImage, opts));
const id = ++jobId;
return new Promise(resolve => {
jobs.set(id, resolve);
worker.postMessage({ id, opts });
});
}
/** Transient message; the info badge returns after a couple of seconds. */
function notify(msg) {
if (el.landing.classList.contains('hidden')) {
el.infoBadge.textContent = msg;
clearTimeout(badgeTimer);
badgeTimer = setTimeout(() => { el.infoBadge.textContent = lastBadge; }, 2200);
} else {
el.gpuStatus.textContent = msg;
el.gpuStatus.classList.remove('on');
}
}
// ── preferences ──
function savePrefs() {
try {
localStorage.setItem(PREFS_KEY, JSON.stringify({
mode,
size: sliderValue('slSize'),
weight: sliderValue('slWeight'),
thr: sliderValue('slThr'),
hints: el.sheet.classList.contains('hints'),
}));
} catch { /* private mode */ }
}
function loadPrefs() {
try {
const p = JSON.parse(localStorage.getItem(PREFS_KEY) || '{}');
if (MODES.includes(p.mode)) setMode(p.mode, false);
if (p.hints) {
el.sheet.classList.add('hints');
el.btnHints.setAttribute('aria-pressed', 'true');
}
for (const [key, s] of [['size', 'slSize'], ['weight', 'slWeight'], ['thr', 'slThr']]) {
if (p[key] != null) setSliderValue(s, +p[key]); // snaps old values
}
} catch { /* ignore corrupt prefs */ }
SLIDERS.forEach(([s, v]) => showSlider(s, v));
}
// ── image loading ──
/** Install a new source image: GPU upload, worker upload, preview, run. */
async function setSource(image) {
srcImage = image;
allowUpsample = true; // a previous oversized image must not stick at 1x
if (gpu) {
try { await gpu.uploadImage(image); } catch { gpu = null; setGpuStatus(); }
}
if (worker) {
const copy = new Uint8ClampedArray(image.data);
worker.postMessage(
{ image: { data: copy, width: image.width, height: image.height } },
[copy.buffer]);
}
el.canvasOriginal.width = image.width;
el.canvasOriginal.height = image.height;
el.canvasOriginal.getContext('2d').putImageData(image, 0, 0);
el.landing.classList.add('hidden');
el.app.classList.remove('hidden');
el.btnRotate.disabled = false;
fitCanvases();
run();
}
/** Bitmap or ImageData -> ImageData, downscaled to fit a pixel budget. */
async function toImageData(src, budget) {
const n = src.width * src.height;
const s = n > budget ? Math.sqrt(budget / n) : 1;
const w = Math.max(1, Math.round(src.width * s));
const h = Math.max(1, Math.round(src.height * s));
const c = document.createElement('canvas');
c.width = w; c.height = h;
const ctx = c.getContext('2d', { willReadFrequently: true });
const own = src instanceof ImageData;
const bmp = own ? await createImageBitmap(src) : src;
ctx.drawImage(bmp, 0, 0, w, h);
if (own) bmp.close();
return ctx.getImageData(0, 0, w, h);
}
async function loadBlob(blob, name) {
const budget = gpu ? Math.min(gpu.maxPixels, GPU_MAX_PIXELS) : CPU_MAX_PIXELS;
srcName = (name || 'document').replace(/\.[^/.]+$/, '');
const bmp = await createImageBitmap(blob, { imageOrientation: 'from-image' });
origSize = (bmp.width * bmp.height > budget) ? [bmp.width, bmp.height] : null;
const image = await toImageData(bmp, budget);
bmp.close();
await setSource(image);
}
function loadFile(file) {
if (!file) return;
if (!file.type.startsWith('image/')) return notify('Not an image file');
loadBlob(file, file.name).catch(() => notify(`Could not read “${file.name}”`));
}
/** Rotate the source 90° clockwise, keeping the current parameters.
* Safe mid-run: the worker holds its own copy and run() supersedes itself. */
async function rotate() {
if (!srcImage) return;
const { width: w, height: h } = srcImage;
const c = document.createElement('canvas');
c.width = h; c.height = w;
const ctx = c.getContext('2d', { willReadFrequently: true });
ctx.setTransform(0, 1, -1, 0, h, 0); // (x, y) -> (h - y, x)
ctx.drawImage(await createImageBitmap(srcImage), 0, 0);
if (origSize) origSize = [origSize[1], origSize[0]];
await setSource(ctx.getImageData(0, 0, h, w));
}
// ── processing (GPU first, worker, then inline CPU) ──
/** Paint the result; false when the browser silently refused the canvas size. */
function showResult(res) {
const c = el.canvasResult;
c.width = res.width;
c.height = res.height;
if (c.width !== res.width || c.height !== res.height) return false;
const ctx = c.getContext('2d');
try {
ctx.putImageData(new ImageData(res.data, res.width, res.height), 0, 0);
// over the browser's canvas-area limit the canvas stays blank instead
// of throwing, so probe a pixel we know is opaque
return ctx.getImageData(res.width - 1, res.height - 1, 1, 1).data[3] === 255;
} catch {
return false;
}
}
async function run() {
if (!srcImage) return;
if (busy) { pending = true; return; }
busy = true;
el.spinner.classList.remove('hidden');
await new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)));
const opts = {
mode,
size: sliderValue('slSize'),
weight: sliderValue('slWeight'),
thresholdOffset: sliderValue('slThr'),
upsample: allowUpsample,
};
const t0 = performance.now();
let res = null, backend = 'cpu';
if (gpu) {
try {
res = await gpu.process(opts);
backend = 'gpu';
} catch {
gpu = null;
setGpuStatus();
// the source was sized for the GPU budget; the CPU port needs
// ~64 bytes/pixel of float64 scratch, so shrink before falling back
if (srcImage.width * srcImage.height > CPU_MAX_PIXELS) {
busy = false; // setSource() re-enters run()
pending = false;
origSize ??= [srcImage.width, srcImage.height];
notify('GPU unavailable — reduced for the CPU');
return setSource(await toImageData(srcImage, CPU_MAX_PIXELS));
}
}
}
if (!res) res = await cpuProcess(opts);
if (!res) res = ZigZag.process(srcImage, opts); // worker died mid-flight
const ms = performance.now() - t0;
busy = false;
if (!showResult(res)) {
el.spinner.classList.add('hidden');
if (res.width > srcImage.width) { // 2x is too big for this browser
allowUpsample = false;
return run();
}
pending = false;
return notify('Image too large for this browser');
}
const i = res.info;
const ds = origSize ? ` (from ${origSize[0]}×${origSize[1]})` : '';
const up = res.width !== srcImage.width ? ` → ${res.width}×${res.height}` : '';
const ot = i.threshold !== i.otsu ? ` · thr ${i.threshold} (otsu ${i.otsu})` : ` · otsu ${i.otsu}`;
const wt = i.weight !== 90 ? ` · w ${i.weight}` : '';
clearTimeout(badgeTimer);
lastBadge = `${srcImage.width}×${srcImage.height}${ds}${up} · size ${i.size}${wt}${ot} · ${backend} · ${ms.toFixed(0)} ms`;
el.infoBadge.textContent = lastBadge;
el.btnSave.disabled = false;
el.btnShare.disabled = false;
el.spinner.classList.add('hidden');
if (pending) { pending = false; run(); }
}
// ── viewport: full-width fit + pinch zoom & pan ──
const view = { w0: 0, h0: 0, z: 1, zMin: 1, tx: 0, ty: 0 };
function fitCanvases() {
if (!srcImage) return;
view.w0 = el.viewport.clientWidth;
view.h0 = view.w0 * srcImage.height / srcImage.width;
view.zMin = Math.min(1, el.viewport.clientHeight / view.h0); // pinch out to whole page
view.z = 1; // default: full width
view.tx = 0;
view.ty = 0; // tall documents start at the top
el.compareWrap.style.width = view.w0 + 'px';
el.compareWrap.style.height = view.h0 + 'px';
for (const c of [el.canvasOriginal, el.canvasResult]) {
c.style.width = view.w0 + 'px'; // px, not %: the original's containing
c.style.height = view.h0 + 'px'; // block is #compareClip, which the slider resizes
}
applyView();
applyCompare();
}
function applyView() {
const vw = el.viewport.clientWidth, vh = el.viewport.clientHeight;
const sw = view.w0 * view.z, sh = view.h0 * view.z;
view.tx = sw <= vw ? (vw - sw) / 2 : Math.max(vw - sw, Math.min(0, view.tx));
view.ty = sh <= vh ? (vh - sh) / 2 : Math.max(vh - sh, Math.min(0, view.ty));
el.compareWrap.style.transform = `translate(${view.tx}px, ${view.ty}px) scale(${view.z})`;
el.compareWrap.style.setProperty('--invz', 1 / view.z);
}
function zoomAt(f, cx, cy) { // cx/cy in viewport coordinates
const z = Math.max(view.zMin, Math.min(8, view.z * f));
f = z / view.z;
view.tx = cx - (cx - view.tx) * f;
view.ty = cy - (cy - view.ty) * f;
view.z = z;
applyView();
}
function applyCompare() {
const pct = (toggled ? 1 : comparePos) * 100;
el.compareClip.style.width = pct + '%';
el.compareLine.style.left = pct + '%';
el.compareWrap.classList.toggle('toggled', toggled);
}
// one finger: horizontal drag = slider, vertical drag = pan, tap = toggle original,
// double-tap / double-click = reset view · two fingers: pinch zoom & pan · wheel: zoom
const pointers = new Map();
let gesture = null, moved = false, downT = 0, lastTap = 0;
let pinchDist = 0, pinchX = 0, pinchY = 0;
const vpXY = (x, y) => {
const r = el.viewport.getBoundingClientRect();
return [x - r.left, y - r.top];
};
const pinchState = () => {
const [a, b] = [...pointers.values()];
return [Math.hypot(a.x - b.x, a.y - b.y), ...vpXY((a.x + b.x) / 2, (a.y + b.y) / 2)];
};
el.compareWrap.addEventListener('pointerdown', e => {
if (!srcImage) return;
el.compareWrap.setPointerCapture(e.pointerId);
pointers.set(e.pointerId, { x: e.clientX, y: e.clientY, x0: e.clientX, y0: e.clientY });
if (pointers.size === 2) {
gesture = 'pinch';
moved = true;
[pinchDist, pinchX, pinchY] = pinchState();
} else {
gesture = e.target.closest('#compareLine') ? 'slider' : null;
moved = false;
downT = Date.now();
}
});
el.compareWrap.addEventListener('pointermove', e => {
const p = pointers.get(e.pointerId);
if (!p) return;
const dx = e.clientX - p.x, dy = e.clientY - p.y;
p.x = e.clientX; p.y = e.clientY;
if (!moved && Math.hypot(p.x - p.x0, p.y - p.y0) > 6) {
moved = true;
gesture ??= view.z > 1 ? 'pan' // zoomed in: drag pans, slider via its handle
: Math.abs(p.x - p.x0) >= Math.abs(p.y - p.y0) ? 'slider' : 'pan';
}
if (!moved) return;
if (gesture === 'pinch') {
const [d, cx, cy] = pinchState();
view.tx += cx - pinchX;
view.ty += cy - pinchY;
zoomAt(d / pinchDist, cx, cy);
[pinchDist, pinchX, pinchY] = [d, cx, cy];
} else if (gesture === 'pan') {
view.tx += dx;
view.ty += dy;
applyView();
} else if (gesture === 'slider') {
const r = el.compareWrap.getBoundingClientRect();
comparePos = Math.max(0.02, Math.min(0.98, (e.clientX - r.left) / r.width));
toggled = false;
applyCompare();
}
});
const endPointer = e => {
if (!pointers.delete(e.pointerId)) return;
if (gesture === 'pinch') {
const p = pointers.values().next().value; // pinch → remaining finger pans
if (p) { p.x0 = p.x; p.y0 = p.y; }
gesture = 'pan';
} else if (!moved && e.type === 'pointerup' && Date.now() - downT < 300) {
const now = Date.now();
toggled = !toggled; // tap: toggle full original
if (now - lastTap < 300) { toggled = !toggled; fitCanvases(); } // double-tap: reset
lastTap = now;
applyCompare();
}
if (!pointers.size) gesture = null;
};
el.compareWrap.addEventListener('pointerup', endPointer);
el.compareWrap.addEventListener('pointercancel', endPointer);
el.viewport.addEventListener('wheel', e => {
if (!srcImage) return;
e.preventDefault();
zoomAt(Math.exp(-e.deltaY * 0.002), ...vpXY(e.clientX, e.clientY));
}, { passive: false });
el.viewport.addEventListener('dblclick', fitCanvases);
// width-only: a height change (mobile URL bar, keyboard) must not reset zoom & pan
if (typeof ResizeObserver !== 'undefined') {
let lastW = 0;
new ResizeObserver(() => {
const w = el.viewport.clientWidth;
if (w && w !== lastW) { lastW = w; fitCanvases(); }
}).observe(el.viewport);
}
// ── input sources ──
el.btnCamera.addEventListener('click', () => el.fileCamera.click());
el.btnGallery.addEventListener('click', () => el.fileGallery.click());
for (const input of [el.fileCamera, el.fileGallery]) {
input.addEventListener('change', () => { loadFile(input.files[0]); input.value = ''; });
}
el.btnExample.addEventListener('click', async () => {
el.btnExample.disabled = true;
try {
const r = await fetch('examples/02_04.jpg');
if (!r.ok) throw new Error(r.status);
await loadBlob(await r.blob(), 'example.jpg');
} catch {
notify('Example image unavailable');
}
el.btnExample.disabled = false;
});
// ── modes & parameters ──
function setMode(m, rerun = true) {
mode = m;
for (const b of el.modeRow.querySelectorAll('.mode-btn')) {
const on = b.dataset.mode === m;
b.classList.toggle('active', on);
b.setAttribute('aria-checked', String(on));
}
if (rerun) { savePrefs(); run(); }
}
el.modeRow.addEventListener('click', e => {
const btn = e.target.closest('.mode-btn');
if (btn && btn.dataset.mode !== mode) setMode(btn.dataset.mode);
});
function showSlider(s, v) {
const n = sliderValue(s);
el[v].textContent = (s === 'slThr' && n > 0 ? '+' + n : String(n)) + UNITS[s];
}
SLIDERS.forEach(([s, v]) => {
el[s].addEventListener('input', () => {
showSlider(s, v);
clearTimeout(debounceId);
debounceId = setTimeout(() => { savePrefs(); run(); }, 150);
});
});
// ── settings sheet ──
/** Lift the info badge by how far the panel intrudes into the viewport. */
function liftBadge() {
const intrusion = el.viewport.getBoundingClientRect().bottom
- (innerHeight - el.sheetPanel.offsetHeight);
el.app.style.setProperty('--sheet-h', Math.max(0, intrusion) + 'px');
}
function showSheet(on) {
sheetOpen = on;
if (on) {
el.sheet.classList.remove('hidden');
liftBadge();
el.app.classList.add('sheet-open');
requestAnimationFrame(() => el.sheet.classList.remove('hidden-anim'));
} else {
el.app.classList.remove('sheet-open');
el.sheet.classList.add('hidden-anim');
setTimeout(() => el.sheet.classList.add('hidden'), 300);
}
}
el.btnTune.addEventListener('click', () => showSheet(!sheetOpen));
el.btnHints.addEventListener('click', () => {
const on = el.sheet.classList.toggle('hints');
el.btnHints.setAttribute('aria-pressed', String(on));
liftBadge();
savePrefs();
});
el.sheetBackdrop.addEventListener('click', () => showSheet(false));
el.btnReset.addEventListener('click', () => {
let changed = false;
for (const [s, v] of SLIDERS) {
const before = el[s].value;
setSliderValue(s, DEFAULTS[s]);
if (el[s].value !== before) {
showSlider(s, v);
changed = true;
}
}
if (changed) { savePrefs(); run(); }
});
// swipe the panel down to dismiss
let sheetDragY = null;
el.sheetPanel.addEventListener('pointerdown', e => {
if (e.target.closest('button')) return; // never swallow Reset / help taps
if (!e.target.closest('.sheet-drag-bar, .sheet-head')) return;
sheetDragY = e.clientY;
el.sheetPanel.setPointerCapture(e.pointerId);
el.sheetPanel.style.transition = 'none';
});
el.sheetPanel.addEventListener('pointermove', e => {
if (sheetDragY !== null) {
el.sheetPanel.style.transform = `translateY(${Math.max(0, e.clientY - sheetDragY)}px)`;
}
});
const endSheetDrag = e => {
if (sheetDragY === null) return;
const dy = e.clientY - sheetDragY;
sheetDragY = null;
el.sheetPanel.style.transition = '';
el.sheetPanel.style.transform = '';
if (dy > 60) showSheet(false);
};
el.sheetPanel.addEventListener('pointerup', endSheetDrag);
el.sheetPanel.addEventListener('pointercancel', endSheetDrag);
// ── output ──
el.btnNew.addEventListener('click', () => {
srcImage = null;
origSize = null;
gpu?.destroy(); // release the per-image GPU buffers
worker?.postMessage({ image: null }); // and the worker's copy
el.canvasResult.width = el.canvasResult.height = 0;
el.canvasOriginal.width = el.canvasOriginal.height = 0;
allowUpsample = true;
lastBadge = '';
el.infoBadge.textContent = '';
el.btnSave.disabled = true;
el.btnShare.disabled = true;
el.btnRotate.disabled = true;
el.app.classList.add('hidden');
el.landing.classList.remove('hidden');
});
const exportBlob = fn => el.canvasResult.toBlob(
b => b ? fn(b) : notify('Export failed'), 'image/png');
el.btnSave.addEventListener('click', () => exportBlob(blob => {
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = `${srcName}_ZZ.png`;
a.click();
URL.revokeObjectURL(a.href);
}));
// one button: the native share sheet where files can be shared, clipboard elsewhere
const canShare = !!navigator.canShare?.(
{ files: [new File([new Uint8Array(1)], 'probe.png', { type: 'image/png' })] });
el.btnShare.querySelector('.lbl').textContent = canShare ? 'Share' : 'Copy';
el.btnShare.querySelector(canShare ? '.icon-copy' : '.icon-share').classList.add('hidden');
if (!canShare && !window.ClipboardItem) el.btnShare.classList.add('hidden');
el.btnShare.addEventListener('click', () => exportBlob(async blob => {
const name = `${srcName}_ZZ.png`;
if (canShare) {
try {
await navigator.share({ files: [new File([blob], name, { type: 'image/png' })] });
} catch (err) {
if (err.name !== 'AbortError') notify('Sharing failed');
}
return;
}
try {
await navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);
notify('Copied to clipboard');
} catch {
notify('Clipboard blocked by the browser');
}
}));
el.btnRotate.addEventListener('click', rotate);
// ── keyboard (desktop) ──
addEventListener('keydown', e => {
if (e.metaKey || e.ctrlKey || e.altKey) return;
if (e.key === 'Escape' && sheetOpen) { showSheet(false); e.preventDefault(); return; }
if (e.target.closest('input')) return; // a focused slider owns its keys
if (el.app.classList.contains('hidden') || !srcImage) return;
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
comparePos = Math.max(0.02, Math.min(0.98,
comparePos + (e.key === 'ArrowRight' ? 0.02 : -0.02)));
toggled = false;
applyCompare();
e.preventDefault();
return;
}
const k = e.key.toLowerCase();
if (k === '1' || k === '2' || k === '3') setMode(MODES[Number(k) - 1]);
else if (k === 'r') rotate();
else if (k === 't') showSheet(!sheetOpen);
else if (k === 's') el.btnSave.click();
else if (k === 'c') el.btnShare.click();
else if (k === 'n') el.btnNew.click();
else if (k === '0') fitCanvases();
else if (k === 'tab') return;