Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
1349 lines (1267 loc) · 71.3 KB
/
Copy pathindex.html
File metadata and controls
1349 lines (1267 loc) · 71.3 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="ko">
<head>
<meta charset="utf-8">
<script>
// GitHub 페이지(옛 주소)로 온 방문자만 새 주소로 보낸다. 책갈피 사이트 사본도 이 파일을 쓰므로 조건을 빼면 무한 이동.
if (location.hostname.endsWith('github.io')) location.replace('https://chaekgalpi.co.kr/apps/spreadsplit/' + location.search + location.hash);
</script>
<link rel="canonical" href="https://chaekgalpi.co.kr/apps/spreadsplit/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>펼침면 나누기</title>
<meta name="description" content="두 쪽이 한 장에 담긴 스캔 PDF를 왼쪽·오른쪽 쪽으로 나누는 브라우저 도구. Split two-page scanned PDF spreads in your browser.">
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect x='3' y='7' width='12' height='18' rx='2' fill='%231d1d1b'/%3E%3Crect x='17' y='7' width='12' height='18' rx='2' fill='%231d1d1b'/%3E%3Crect x='15.25' y='3' width='1.5' height='26' rx='.75' fill='%23e5484d'/%3E%3C/svg%3E">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/variable/pretendardvariable-dynamic-subset.min.css">
<style>
:root {
--bg: #f5f4f0;
--surface: #ffffff;
--surface-2: #efede7;
--ink: #1d1d1b;
--ink-2: #4a4944;
--muted: #8a8880;
--line: #e4e1d9;
--line-strong: #d2cec3;
--primary: #1d1d1b;
--primary-ink: #ffffff;
--accent: #e5484d;
--accent-soft: rgba(229, 72, 77, .16);
--cut: rgba(29, 29, 27, .55);
--ok: #2b8a57;
--shadow: 0 1px 2px rgba(30, 28, 20, .05), 0 6px 20px rgba(30, 28, 20, .06);
--radius: 14px;
color-scheme: light;
}
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) {
--bg: #131312; --surface: #1c1c1a; --surface-2: #252522; --ink: #ededea; --ink-2: #c4c2ba;
--muted: #8f8d86; --line: #2f2e2b; --line-strong: #403f3a; --primary: #ededea; --primary-ink: #151514;
--accent: #ff6369; --accent-soft: rgba(255, 99, 105, .2); --cut: rgba(0, 0, 0, .6); --ok: #4cc38a;
--shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
color-scheme: dark;
}
}
:root[data-theme="dark"] {
--bg: #131312; --surface: #1c1c1a; --surface-2: #252522; --ink: #ededea; --ink-2: #c4c2ba;
--muted: #8f8d86; --line: #2f2e2b; --line-strong: #403f3a; --primary: #ededea; --primary-ink: #151514;
--accent: #ff6369; --accent-soft: rgba(255, 99, 105, .2); --cut: rgba(0, 0, 0, .6); --ok: #4cc38a;
--shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
background: var(--bg);
color: var(--ink);
font: 15px/1.55 "Pretendard Variable", Pretendard, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
-webkit-font-smoothing: antialiased;
min-height: 100vh;
}
html[lang="ja"] body { font-family: "Pretendard Variable", Pretendard, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif; }
html[lang="zh"] body { font-family: "Pretendard Variable", Pretendard, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
/* ── top bar ── */
.topbar {
position: sticky; top: 0; z-index: 20;
display: flex; align-items: center; gap: 10px;
padding: 14px 24px;
background: color-mix(in srgb, var(--bg) 88%, transparent);
backdrop-filter: blur(10px);
border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; flex: none; }
.brand small { font-weight: 500; color: var(--muted); margin-left: 2px; }
.topbar .spacer { flex: 1; }
.link-btn {
display: inline-flex; align-items: center; gap: 6px;
padding: 7px 12px; border-radius: 9px; border: 1px solid var(--line);
background: var(--surface); color: var(--ink-2); text-decoration: none; font-size: 14px; white-space: nowrap;
}
.link-btn:hover { border-color: var(--line-strong); color: var(--ink); }
.lang {
appearance: none; -webkit-appearance: none;
padding: 7px 30px 7px 12px; border-radius: 9px; border: 1px solid var(--line);
background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8880' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
color: var(--ink-2); font-size: 14px; cursor: pointer;
}
.lang:hover { border-color: var(--line-strong); color: var(--ink); }
/* ── empty state ── */
.empty { max-width: 760px; margin: 0 auto; padding: 72px 20px 48px; text-align: center; }
.empty h1 { font-size: clamp(28px, 4.2vw, 40px); line-height: 1.25; letter-spacing: -.025em; margin: 0 0 12px; }
.empty .lead { color: var(--ink-2); margin: 0 0 36px; font-size: 16px; }
.drop {
position: relative; display: grid; place-items: center; gap: 14px;
padding: 56px 24px; border-radius: 22px;
border: 1.5px dashed var(--line-strong); background: var(--surface);
transition: border-color .15s, background .15s, transform .15s;
cursor: pointer;
}
.drop:hover { border-color: var(--ink-2); }
.drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 5%, var(--surface)); transform: scale(1.005); }
.drop-art { width: 132px; height: 84px; }
.drop strong { font-size: 18px; }
.drop span { color: var(--muted); font-size: 14px; }
.btn {
display: inline-flex; align-items: center; justify-content: center; gap: 8px;
padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line-strong);
background: var(--surface); font-weight: 600; font-size: 14px; white-space: nowrap;
transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { border-color: var(--ink-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { opacity: .9; }
.btn.big { width: 100%; padding: 13px 16px; font-size: 15px; border-radius: 12px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); padding: 7px 10px; }
.btn.ghost:hover { background: var(--surface-2); }
.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 28px; text-align: left; }
.feature { padding: 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.feature b { display: block; font-size: 14px; margin-bottom: 2px; }
.feature p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.loading { margin-top: 20px; color: var(--ink-2); font-size: 14px; }
.loading .bar { height: 4px; margin: 10px auto 0; max-width: 320px; }
/* ── workspace ── */
.workspace { display: grid; grid-template-columns: 300px 1fr; gap: 24px; padding: 24px; align-items: start; }
.panel {
position: sticky; top: 80px;
background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
box-shadow: var(--shadow); padding: 6px 18px 18px;
max-height: calc(100vh - 104px); overflow: auto;
}
.group { padding: 14px 0; border-bottom: 1px solid var(--line); }
.group:last-of-type { border-bottom: 0; }
.label { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 9px; }
.label output { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 700; }
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.5; margin: 8px 0 0; }
.file-name { font-weight: 700; word-break: break-all; line-height: 1.35; }
.file-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.file-row { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.seg { display: flex; padding: 3px; background: var(--surface-2); border-radius: 10px; gap: 2px; }
.seg button {
flex: 1; border: 0; background: transparent; padding: 7px 8px; border-radius: 8px;
font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--line); }
.seg button:hover:not([aria-pressed="true"]) { color: var(--ink); }
.row { display: flex; gap: 6px; margin-top: 10px; }
.row .btn { flex: 1; padding: 7px 10px; font-size: 13px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: var(--line-strong); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--line-strong); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: var(--surface); border: 2px solid var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 2px solid var(--ink); }
.summary { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 12px; font-size: 14px; color: var(--ink-2); }
.summary b { color: var(--ink); font-variant-numeric: tabular-nums; }
.summary .arrow { color: var(--muted); }
.bar { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.done {
margin-top: 12px; padding: 12px; border-radius: 12px; font-size: 13.5px;
background: color-mix(in srgb, var(--ok) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent);
}
.done b { color: var(--ok); }
.done a { color: var(--ink); font-weight: 600; }
/* ── page grid ── */
.grid-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 2px 0 14px; }
.grid-head h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 12.5px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 2px; background: var(--accent); display: inline-block; }
.legend i.band { height: 10px; width: 10px; border-radius: 2px; background: var(--accent-soft); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.card {
background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
overflow: hidden; transition: border-color .15s, box-shadow .15s;
}
.card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.stage {
container-type: size; aspect-ratio: 4 / 3;
display: grid; place-items: center; padding: 0;
background: var(--surface-2);
}
.thumb {
--ar: 1.4;
position: relative; aspect-ratio: var(--ar);
width: min(calc(100cqw - 24px), calc((100cqh - 24px) * var(--ar)));
background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.14);
user-select: none; touch-action: none;
}
.thumb canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; opacity: 0; transition: opacity .2s; }
.thumb.ready canvas { opacity: 1; }
.thumb::before {
content: ""; position: absolute; inset: 0;
background: linear-gradient(100deg, transparent 30%, rgba(0,0,0,.04) 50%, transparent 70%) #f3f2ee;
background-size: 300% 100%; animation: shimmer 1.4s infinite linear;
}
.thumb.ready::before { display: none; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -200% 0; } }
.band, .cut, .tag, .skip-mark { position: absolute; }
.band { top: 0; bottom: 0; pointer-events: none; }
.band.overlap { background: var(--accent-soft); }
.band.gap { background: repeating-linear-gradient(135deg, var(--cut) 0 3px, transparent 3px 7px); }
.cut { top: -6px; bottom: -6px; width: 22px; margin-left: -11px; cursor: ew-resize; z-index: 2; }
.cut::before { content: ""; position: absolute; left: 10px; top: 6px; bottom: 6px; width: 2px; background: var(--accent); box-shadow: 0 0 0 1px rgba(255,255,255,.55); }
.cut::after {
content: ""; position: absolute; left: 4px; top: 50%; width: 14px; height: 26px; margin-top: -13px;
border-radius: 7px; background: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.3);
opacity: 0; transition: opacity .12s;
}
.thumb:hover .cut::after, .thumb.dragging .cut::after, .cut:focus-visible::after { opacity: 1; }
.cut:focus-visible { outline: none; }
.tag {
top: 8px; transform: translateX(-50%);
min-width: 26px; padding: 1px 7px; border-radius: 99px; text-align: center;
background: rgba(29,29,27,.82); color: #fff; font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums;
pointer-events: none; z-index: 1;
}
.skip-mark { inset: 0; display: grid; place-items: center; background: rgba(245,244,240,.72); color: #4a4944; font-weight: 700; font-size: 13px; }
.card.mode-skip .thumb canvas { filter: grayscale(1); }
.card-foot { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 14px; border-top: 1px solid var(--line); }
.pno { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 34px; }
.pno em { display: block; font-style: normal; font-weight: 500; color: var(--accent); font-size: 11px; line-height: 1.2; }
.card-foot .seg { flex: 1; padding: 2px; }
.card-foot .seg button { padding: 5px 4px; font-size: 12px; }
.icon-btn {
width: 32px; height: 32px; display: grid; place-items: center; flex: none;
border: 1px solid var(--line); background: var(--surface); border-radius: 9px; color: var(--ink-2);
}
.icon-btn:hover { border-color: var(--line-strong); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }
/* ── viewer ── */
dialog.viewer {
width: min(1280px, calc(100vw - 32px)); height: calc(100vh - 32px); max-height: none; max-width: none;
padding: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--ink);
box-shadow: 0 30px 80px rgba(0,0,0,.35);
}
dialog.viewer[open] { display: grid; grid-template-rows: auto 1fr auto; }
dialog.viewer::backdrop { background: rgba(15,15,14,.55); backdrop-filter: blur(3px); }
.v-head, .v-foot { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.v-head { border-bottom: 1px solid var(--line); }
.v-foot { border-top: 1px solid var(--line); justify-content: space-between; font-size: 13.5px; color: var(--ink-2); }
.v-head .title { font-weight: 700; }
.v-head .seg { width: 260px; }
.v-head .spacer { flex: 1; }
.v-stage { container-type: size; display: grid; place-items: center; background: var(--surface-2); min-height: 0; }
.v-stage .thumb { width: min(calc(100cqw - 48px), calc((100cqh - 48px) * var(--ar))); }
.v-stage .tag { font-size: 13px; padding: 2px 10px; top: 12px; }
.v-info { font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.kbd { font: 600 11.5px/1 ui-monospace, Consolas, monospace; padding: 3px 6px; border-radius: 5px; border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink-2); }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
/* ── toast ── */
.toast {
position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; z-index: 50;
padding: 11px 16px; border-radius: 12px; background: var(--primary); color: var(--primary-ink);
font-size: 14px; font-weight: 500; box-shadow: 0 10px 30px rgba(0,0,0,.25); pointer-events: none;
transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.drag-veil {
position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; pointer-events: none;
background: color-mix(in srgb, var(--bg) 80%, transparent); border: 3px dashed var(--accent);
font-size: 20px; font-weight: 700;
}
@media (max-width: 880px) {
.workspace { grid-template-columns: 1fr; padding: 16px; }
.panel { position: static; max-height: none; }
.topbar { padding: 12px 16px; gap: 8px; }
.features { grid-template-columns: 1fr; }
.grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.v-head .seg { width: auto; }
.brand small { display: none; }
.link-btn span { display: none; }
.link-btn { padding: 7px 9px; }
}
</style>
</head>
<body>
<noscript><p style="margin:0;padding:10px 16px;background:#fff4d6;text-align:center">펼침면 나누기는 <a href="https://chaekgalpi.co.kr/apps/spreadsplit/">https://chaekgalpi.co.kr/apps/spreadsplit/</a> 에서 씁니다(자바스크립트 필요). Spread Split now lives at the address above.</p></noscript>
<header class="topbar">
<div class="brand">
<svg viewBox="0 0 32 32" aria-hidden="true"><rect x="3" y="7" width="12" height="18" rx="2" fill="currentColor"/><rect x="17" y="7" width="12" height="18" rx="2" fill="currentColor"/><rect x="15.25" y="3" width="1.5" height="26" rx=".75" fill="var(--accent)"/></svg>
<span data-i18n="brand">펼침면 나누기</span> <small data-i18n="brandSub">Spread Split</small>
</div>
<div class="spacer"></div>
<select class="lang" id="lang" aria-label="Language">
<option value="ko">한국어</option>
<option value="en">English</option>
<option value="zh">中文</option>
<option value="ja">日本語</option>
</select>
<a class="link-btn" id="guideLink" href="guide.html" target="_blank" rel="noopener">
<svg width="15" height="15" 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="9.5"/><path d="M9.3 9.2a2.8 2.8 0 0 1 5.4 1c0 1.9-2.7 2.6-2.7 2.6M12 16.8h.01"/></svg>
<span data-i18n="guide">사용 설명</span>
</a>
</header>
<main>
<!-- empty -->
<section id="empty" class="empty">
<h1 data-i18n="h1">펼쳐서 스캔한 PDF를<br>한 쪽씩 나눕니다</h1>
<p class="lead" data-i18n="lead">한 장에 두 쪽이 담긴 스캔본을 왼쪽·오른쪽으로 잘라 새 PDF로 만들어요.</p>
<label class="drop" id="drop" tabindex="0">
<svg class="drop-art" viewBox="0 0 132 84" fill="none" aria-hidden="true">
<rect x="6" y="10" width="56" height="68" rx="4" fill="var(--surface-2)" stroke="var(--line-strong)"/>
<rect x="70" y="10" width="56" height="68" rx="4" fill="var(--surface-2)" stroke="var(--line-strong)"/>
<g stroke="var(--line-strong)" stroke-width="3" stroke-linecap="round">
<path d="M16 26h36M16 36h36M16 46h28M16 56h34"/><path d="M80 26h36M80 36h30M80 46h36M80 56h24"/>
</g>
<path d="M66 2v80" stroke="var(--accent)" stroke-width="2" stroke-dasharray="4 4"/>
</svg>
<strong data-i18n="dropMain">PDF 파일을 여기에 끌어다 놓으세요</strong>
<span data-i18n="dropSub">또는 눌러서 파일 고르기</span>
<input id="file" type="file" accept="application/pdf,.pdf" hidden>
</label>
<div id="loading" class="loading" hidden>
<div id="loadingText"></div>
<div class="bar"><i id="loadingBar"></i></div>
</div>
<div class="features">
<div class="feature"><b data-i18n="f1t"></b><p data-i18n="f1p"></p></div>
<div class="feature"><b data-i18n="f2t"></b><p data-i18n="f2p"></p></div>
<div class="feature"><b data-i18n="f3t"></b><p data-i18n="f3p"></p></div>
</div>
</section>
<!-- workspace -->
<section id="workspace" class="workspace" hidden>
<aside class="panel" id="panel">
<div class="group">
<div class="file-row">
<div>
<div class="file-name" id="fName"></div>
<div class="file-meta" id="fMeta"></div>
</div>
<button class="btn ghost" id="btnOther" data-i18n="change" data-i18n-title="changeTitle"></button>
</div>
</div>
<div class="group">
<div class="label" data-i18n="dir"></div>
<div class="seg" id="dirSeg">
<button data-dir="ltr" aria-pressed="true" data-i18n="ltr"></button>
<button data-dir="rtl" aria-pressed="false" data-i18n="rtl"></button>
</div>
<p class="hint" data-i18n="dirHint"></p>
</div>
<div class="group">
<div class="label"><span data-i18n="pos"></span><output id="posOut">50.0%</output></div>
<input type="range" id="pos" min="30" max="70" step="0.1" value="50" data-i18n-aria="pos">
<div class="row">
<button class="btn" id="btnAuto" data-i18n="auto"></button>
<button class="btn" id="btnClear" disabled data-i18n="clear"></button>
</div>
<p class="hint" data-i18n="posHint"></p>
</div>
<div class="group">
<div class="label"><span data-i18n="overlap"></span><output id="ovOut">0.0%</output></div>
<input type="range" id="overlap" min="-4" max="4" step="0.1" value="0" data-i18n-aria="overlap">
<p class="hint" data-i18n="overlapHint"></p>
</div>
<div class="group">
<div class="label" data-i18n="bulk"></div>
<div class="seg" id="bulkSeg">
<button data-bulk="auto" aria-pressed="false" data-i18n="bulkAuto"></button>
<button data-bulk="split" aria-pressed="false" data-i18n="bulkAll"></button>
<button data-bulk="whole" aria-pressed="false" data-i18n="bulkNone"></button>
</div>
<p class="hint" data-i18n="bulkHint"></p>
</div>
<div class="summary">
<span><span data-i18n="sumSrc"></span> <b id="sumIn">0</b><span data-i18n="pagesUnit"></span></span>
<span class="arrow">→</span>
<span><span data-i18n="sumOut"></span> <b id="sumOut">0</b><span data-i18n="pagesUnit"></span></span>
</div>
<button class="btn primary big" id="btnBuild">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 4v11m0 0 4.5-4.5M12 15l-4.5-4.5M5 20h14"/></svg>
<span id="btnBuildLabel" data-i18n="build"></span>
</button>
<div class="bar" id="buildBarWrap" hidden><i id="buildBar"></i></div>
<div class="done" id="done" hidden></div>
</aside>
<div>
<div class="grid-head">
<h2 data-i18n="preview"></h2>
<div class="legend">
<span><i></i><span data-i18n="legendLine"></span></span>
<span><i class="band"></i><span data-i18n="legendBand"></span></span>
<span data-i18n="legendDbl"></span>
</div>
</div>
<div class="grid" id="grid"></div>
</div>
</section>
</main>
<dialog class="viewer" id="viewer" data-i18n-aria="zoomTitle">
<div class="v-head">
<span class="title" id="vTitle"></span>
<div class="spacer"></div>
<div class="seg" id="vSeg">
<button data-mode="split" data-i18n="modeSplit"></button>
<button data-mode="whole" data-i18n="modeWhole"></button>
<button data-mode="skip" data-i18n="modeSkip"></button>
</div>
<button class="icon-btn" id="vClose" data-i18n-aria="close"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><path d="M6 6l12 12M18 6 6 18"/></svg></button>
</div>
<div class="v-stage"><div class="thumb" id="vThumb"><canvas></canvas></div></div>
<div class="v-foot">
<button class="btn" id="vPrev" data-i18n="prev"></button>
<div class="v-info" id="vInfo"></div>
<button class="btn" id="vNext" data-i18n="next"></button>
</div>
</dialog>
<div class="toast" id="toast" role="status"></div>
<div class="drag-veil" id="veil" hidden data-i18n="veil"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf-lib/1.17.1/pdf-lib.min.js"></script>
<script>
(() => {
'use strict';
/* ───────── i18n ───────── */
const I18N = {
ko: {
brand: '펼침면 나누기', brandSub: 'Spread Split', guide: '사용 설명', docTitle: '펼침면 나누기',
h1: '펼쳐서 스캔한 PDF를<br>한 쪽씩 나눕니다',
lead: '한 장에 두 쪽이 담긴 스캔본을 왼쪽·오른쪽으로 잘라 새 PDF로 만들어요.',
dropMain: 'PDF 파일을 여기에 끌어다 놓으세요', dropSub: '또는 눌러서 파일 고르기',
loadingOpen: '파일 여는 중…', loadingPages: '쪽 정보 읽는 중… {i} / {n}',
f1t: '화질 그대로', f1p: '이미지를 다시 압축하지 않고 보이는 영역만 잘라서 원본 화질과 OCR 글자를 유지해요.',
f2t: '파일은 내 컴퓨터에만', f2p: '모든 처리는 브라우저 안에서 끝나요. 서버로 올라가지 않아요.',
f3t: '쪽마다 조정', f3p: '분할선을 끌어서 옮기거나 자동 맞춤으로 제본선을 찾을 수 있어요.',
change: '바꾸기', changeTitle: '다른 파일 열기',
dir: '읽기 방향', ltr: '왼쪽 → 오른쪽', rtl: '오른쪽 → 왼쪽', dirHint: '세로쓰기 책이나 일본 만화는 오른쪽 쪽이 먼저예요.',
pos: '분할선 위치', auto: '자동 맞춤', autoBusy: '찾는 중 {done}/{total} · 멈추기', clear: '개별 조정 지우기', clearN: '개별 조정 지우기 ({n})',
posHint: '미리보기의 빨간 선을 끌면 그 쪽만 따로 옮겨져요.',
overlap: '가운데 겹침', overlapHint: '<b>+</b> 쪽마다 제본선 부분을 조금 더 넣고, <b>−</b> 가운데 그림자를 잘라내요.',
bulk: '나눌 쪽 한꺼번에 고르기', bulkAuto: '가로 쪽만', bulkAll: '모두', bulkNone: '나누지 않음',
bulkHint: '보통은 <b>가로 쪽만</b>이 맞아요. 세로로 긴 표지는 그대로 둬요.',
sumSrc: '원본', sumOut: '결과', pagesUnit: '쪽', build: 'PDF 만들기',
preview: '미리보기', legendLine: '분할선', legendBand: '겹치는 부분', legendDbl: '선 더블클릭 = 되돌리기',
modeSplit: '나누기', modeWhole: '통째로', modeSkip: '빼기', pageN: '{n}쪽', zoomN: '{n}쪽 크게 보기', zoomTitle: '크게 보기', close: '닫기',
prev: '← 이전 쪽', next: '다음 쪽 →', skipMark: '결과에서 빠짐', cutLabel: '분할선',
vTitle: '{i}쪽 / {n}쪽', vLine: '분할선 {p}', vCustom: '이 쪽만 조정됨', vReset: '되돌리기',
vHint: '· 선을 끌거나 <span class="kbd">Tab</span> 후 <span class="kbd">←</span><span class="kbd">→</span>',
vWhole: '이 쪽은 나누지 않고 그대로 넣어요', vSkip: '이 쪽은 결과에 넣지 않아요',
meta: '{n}쪽 · {size} · 펼침면 {s}쪽',
tBusy: 'PDF를 만드는 중이에요. 끝난 뒤에 다시 시도해 주세요.', tPdfOnly: 'PDF 파일만 열 수 있어요.',
tNoPages: '쪽이 하나도 없는 PDF예요.', tEncrypted: '보안 설정(암호)이 걸린 PDF는 나눌 수 없어요. 암호를 해제한 사본으로 다시 열어 주세요.',
tPassword: '암호가 걸린 PDF는 열 수 없어요. 암호를 푼 뒤 다시 열어 주세요.', tReadFail: 'PDF를 읽지 못했어요. 파일이 손상되지 않았는지 확인해 주세요.',
tLibFail: '필요한 라이브러리를 불러오지 못했어요. 인터넷 연결을 확인한 뒤 새로고침해 주세요.',
tCleared: '모든 쪽이 기본 분할선을 따라가요.', tNoSplit: '나누기로 표시된 쪽이 없어요.',
tFound: '{n}쪽의 제본선을 찾았어요. 미리보기에서 확인해 주세요.', tNotFound: '제본선을 뚜렷하게 찾지 못했어요. 직접 조정해 주세요.',
tBuildErr: 'PDF를 만들다가 문제가 생겼어요: {msg}',
progRead: '원본 읽는 중…', progCopy: '쪽 복사하는 중…', progSplit: '쪽 나누는 중… {i}/{n}', progSave: '저장하는 중…', progDone: '완성!',
done: '완성했어요. ', doneInfo: '{n}쪽 · {size} ', again: '다시 받기', view: '열어 보기',
veil: '여기에 놓으면 이 파일로 바꿔요', producer: '펼침면 나누기 (pdf-lib)',
},
en: {
brand: 'Spread Split', brandSub: 'two-page scan splitter', guide: 'Guide', docTitle: 'Spread Split',
h1: 'Split scanned book spreads<br>into single pages',
lead: 'Turn a PDF scanned two pages per sheet into a new PDF with one page per sheet.',
dropMain: 'Drop a PDF file here', dropSub: 'or click to choose a file',
loadingOpen: 'Opening file…', loadingPages: 'Reading pages… {i} / {n}',
f1t: 'Original quality', f1p: 'Images are never re-encoded. Only the visible area is trimmed, so quality and OCR text stay intact.',
f2t: 'Files stay on your computer', f2p: 'Everything runs inside the browser. Nothing is uploaded to a server.',
f3t: 'Adjust per page', f3p: 'Drag the split line on any page, or let auto-fit find the gutter for you.',
change: 'Change', changeTitle: 'Open another file',
dir: 'Reading order', ltr: 'Left → right', rtl: 'Right → left', dirHint: 'Vertical-text books and manga read the right page first.',
pos: 'Split position', auto: 'Auto-fit', autoBusy: 'Finding {done}/{total} · Stop', clear: 'Reset per-page lines', clearN: 'Reset per-page lines ({n})',
posHint: 'Drag the red line in a preview to move that page only.',
overlap: 'Center overlap', overlapHint: '<b>+</b> includes a little of the gutter on both pages; <b>−</b> trims the gutter shadow away.',
bulk: 'Choose pages to split', bulkAuto: 'Landscape only', bulkAll: 'All', bulkNone: 'None',
bulkHint: '<b>Landscape only</b> is usually right: portrait covers are kept whole.',
sumSrc: 'Source', sumOut: 'Result', pagesUnit: ' pages', build: 'Create PDF',
preview: 'Preview', legendLine: 'split line', legendBand: 'overlap', legendDbl: 'double-click line = reset',
modeSplit: 'Split', modeWhole: 'Whole', modeSkip: 'Skip', pageN: 'p. {n}', zoomN: 'Enlarge page {n}', zoomTitle: 'Enlarge', close: 'Close',
prev: '← Previous', next: 'Next →', skipMark: 'Skipped', cutLabel: 'Split line',
vTitle: 'Page {i} of {n}', vLine: 'Split at {p}', vCustom: 'Adjusted on this page', vReset: 'Reset',
vHint: '· drag the line, or press <span class="kbd">Tab</span> then <span class="kbd">←</span><span class="kbd">→</span>',
vWhole: 'This page is kept whole', vSkip: 'This page is left out of the result',
meta: '{n} pages · {size} · {s} spreads',
tBusy: 'Still creating the PDF. Please try again when it finishes.', tPdfOnly: 'Only PDF files can be opened.',
tNoPages: 'This PDF has no pages.', tEncrypted: 'This PDF is protected (encrypted) and cannot be split. Please remove the password first.',
tPassword: 'Password-protected PDFs cannot be opened. Please remove the password first.', tReadFail: 'Could not read the PDF. Please check that the file is not damaged.',
tLibFail: 'Could not load the required libraries. Check your internet connection and reload.',
tCleared: 'All pages now follow the global split line.', tNoSplit: 'No page is marked to be split.',
tFound: 'Found the gutter on {n} pages. Please check the previews.', tNotFound: 'Could not find a clear gutter. Please adjust manually.',
tBuildErr: 'Something went wrong while creating the PDF: {msg}',
progRead: 'Reading source…', progCopy: 'Copying pages…', progSplit: 'Splitting pages… {i}/{n}', progSave: 'Saving…', progDone: 'Done!',
done: 'Done. ', doneInfo: '{n} pages · {size} ', again: 'Download again', view: 'Open',
veil: 'Drop to replace the current file', producer: 'Spread Split (pdf-lib)',
},
zh: {
brand: '跨页拆分', brandSub: 'Spread Split', guide: '使用说明', docTitle: '跨页拆分',
h1: '把摊开扫描的 PDF<br>拆成单页',
lead: '将一张含两页的扫描件按左右页裁开,生成新的 PDF。',
dropMain: '把 PDF 文件拖到这里', dropSub: '或点击选择文件',
loadingOpen: '正在打开文件…', loadingPages: '正在读取页面信息… {i} / {n}',
f1t: '画质不变', f1p: '不重新压缩图片,只裁剪可见区域,保留原始画质和 OCR 文字。',
f2t: '文件只在本机处理', f2p: '所有处理都在浏览器内完成,不会上传到服务器。',
f3t: '逐页调整', f3p: '可拖动分割线,或用自动对齐找到装订线。',
change: '更换', changeTitle: '打开其他文件',
dir: '阅读方向', ltr: '左 → 右', rtl: '右 → 左', dirHint: '竖排书籍和日本漫画先读右页。',
pos: '分割线位置', auto: '自动对齐', autoBusy: '查找中 {done}/{total} · 停止', clear: '清除逐页调整', clearN: '清除逐页调整 ({n})',
posHint: '拖动预览中的红线,只移动该页的分割线。',
overlap: '中间重叠', overlapHint: '<b>+</b> 让两页都多含一点装订线部分;<b>−</b> 裁掉中间的阴影。',
bulk: '批量选择要拆分的页', bulkAuto: '仅横向页', bulkAll: '全部', bulkNone: '不拆分',
bulkHint: '通常选 <b>仅横向页</b> 即可,竖向的封面保持原样。',
sumSrc: '原文件', sumOut: '结果', pagesUnit: ' 页', build: '生成 PDF',
preview: '预览', legendLine: '分割线', legendBand: '重叠部分', legendDbl: '双击分割线 = 还原',
modeSplit: '拆分', modeWhole: '整页', modeSkip: '排除', pageN: '第 {n} 页', zoomN: '放大第 {n} 页', zoomTitle: '放大查看', close: '关闭',
prev: '← 上一页', next: '下一页 →', skipMark: '不计入结果', cutLabel: '分割线',
vTitle: '第 {i} 页 / 共 {n} 页', vLine: '分割线 {p}', vCustom: '仅此页已调整', vReset: '还原',
vHint: '· 拖动分割线,或按 <span class="kbd">Tab</span> 后用 <span class="kbd">←</span><span class="kbd">→</span>',
vWhole: '此页不拆分,整页保留', vSkip: '此页不计入结果',
meta: '{n} 页 · {size} · 跨页 {s} 页',
tBusy: '正在生成 PDF,请稍后再试。', tPdfOnly: '只能打开 PDF 文件。',
tNoPages: '这个 PDF 没有任何页面。', tEncrypted: '带有安全设置(加密)的 PDF 无法拆分,请先解除密码后再打开。',
tPassword: '无法打开带密码的 PDF,请先解除密码。', tReadFail: '无法读取 PDF,请确认文件没有损坏。',
tLibFail: '无法加载所需的库,请检查网络连接后刷新页面。',
tCleared: '所有页面已恢复为默认分割线。', tNoSplit: '没有标记为拆分的页面。',
tFound: '已在 {n} 页找到装订线,请在预览中确认。', tNotFound: '未能明确找到装订线,请手动调整。',
tBuildErr: '生成 PDF 时出错:{msg}',
progRead: '正在读取原文件…', progCopy: '正在复制页面…', progSplit: '正在拆分页面… {i}/{n}', progSave: '正在保存…', progDone: '完成!',
done: '已完成。', doneInfo: '{n} 页 · {size} ', again: '再次下载', view: '打开查看',
veil: '放开即可替换当前文件', producer: 'Spread Split (pdf-lib)',
},
ja: {
brand: '見開き分割', brandSub: 'Spread Split', guide: '使い方', docTitle: '見開き分割',
h1: '見開きスキャンの PDF を<br>1 ページずつに分けます',
lead: '1 枚に 2 ページ写ったスキャンを左右に切り分け、新しい PDF を作ります。',
dropMain: 'PDF ファイルをここにドロップ', dropSub: 'またはクリックして選択',
loadingOpen: 'ファイルを開いています…', loadingPages: 'ページ情報を読み込み中… {i} / {n}',
f1t: '画質そのまま', f1p: '画像を再圧縮せず表示範囲だけを切り取るので、元の画質と OCR テキストが保たれます。',
f2t: 'ファイルは PC の中だけ', f2p: 'すべての処理はブラウザ内で完結し、サーバーには送られません。',
f3t: 'ページごとに調整', f3p: '分割線をドラッグで動かしたり、自動調整でのどを見つけたりできます。',
change: '変更', changeTitle: '別のファイルを開く',
dir: '読む順序', ltr: '左 → 右', rtl: '右 → 左', dirHint: '縦書きの本やマンガは右ページが先です。',
pos: '分割線の位置', auto: '自動調整', autoBusy: '検出中 {done}/{total} · 停止', clear: 'ページ別の調整を消す', clearN: 'ページ別の調整を消す ({n})',
posHint: 'プレビューの赤い線をドラッグすると、そのページだけ動きます。',
overlap: '中央の重なり', overlapHint: '<b>+</b> のど付近を両ページに少し含め、<b>−</b> 中央の影を切り落とします。',
bulk: '分割するページをまとめて選ぶ', bulkAuto: '横長のみ', bulkAll: 'すべて', bulkNone: '分割しない',
bulkHint: 'ふつうは <b>横長のみ</b> で合っています。縦長の表紙はそのままです。',
sumSrc: '元', sumOut: '結果', pagesUnit: ' ページ', build: 'PDF を作成',
preview: 'プレビュー', legendLine: '分割線', legendBand: '重なり', legendDbl: '線をダブルクリック = 戻す',
modeSplit: '分割', modeWhole: 'そのまま', modeSkip: '除外', pageN: '{n} ページ', zoomN: '{n} ページを拡大', zoomTitle: '拡大表示', close: '閉じる',
prev: '← 前のページ', next: '次のページ →', skipMark: '結果に含めない', cutLabel: '分割線',
vTitle: '{i} / {n} ページ', vLine: '分割線 {p}', vCustom: 'このページのみ調整済み', vReset: '戻す',
vHint: '· 線をドラッグ、または <span class="kbd">Tab</span> のあと <span class="kbd">←</span><span class="kbd">→</span>',
vWhole: 'このページは分割せずそのまま入れます', vSkip: 'このページは結果に含めません',
meta: '{n} ページ · {size} · 見開き {s} ページ',
tBusy: 'PDF を作成中です。終わってからもう一度お試しください。', tPdfOnly: 'PDF ファイルのみ開けます。',
tNoPages: 'ページが 1 つもない PDF です。', tEncrypted: 'セキュリティ(暗号化)が設定された PDF は分割できません。パスワードを解除したコピーで開いてください。',
tPassword: 'パスワード付きの PDF は開けません。解除してから開いてください。', tReadFail: 'PDF を読めませんでした。ファイルが壊れていないか確認してください。',
tLibFail: '必要なライブラリを読み込めませんでした。インターネット接続を確認して再読み込みしてください。',
tCleared: 'すべてのページが共通の分割線に従います。', tNoSplit: '分割に設定されたページがありません。',
tFound: '{n} ページでのどを見つけました。プレビューで確認してください。', tNotFound: 'のどをはっきり見つけられませんでした。手動で調整してください。',
tBuildErr: 'PDF の作成中に問題が起きました: {msg}',
progRead: '元ファイルを読み込み中…', progCopy: 'ページをコピー中…', progSplit: 'ページを分割中… {i}/{n}', progSave: '保存中…', progDone: '完成!',
done: '完成しました。', doneInfo: '{n} ページ · {size} ', again: 'もう一度保存', view: '開く',
veil: 'ここにドロップするとこのファイルに切り替わります', producer: 'Spread Split (pdf-lib)',
},
};
const LANG_KEY = 'spreadSplit.lang';
let LANG = 'ko';
// 저장소가 막힌 환경(사생활 보호 모드, 일부 file:// 등)에서도 동작하도록 감싼다
const store = {
get: k => { try { return localStorage.getItem(k); } catch { return null; } },
set: (k, v) => { try { localStorage.setItem(k, v); } catch {} },
};
const t = (key, vars) => {
let s = (I18N[LANG] && I18N[LANG][key]) ?? I18N.ko[key] ?? key;
if (vars) for (const k in vars) s = s.replaceAll('{' + k + '}', vars[k]);
return s;
};
function detectLang() {
const saved = store.get(LANG_KEY);
if (I18N[saved]) return saved;
for (const l of navigator.languages || [navigator.language || 'en']) {
const p = l.toLowerCase().slice(0, 2);
if (I18N[p]) return p;
}
return 'en';
}
function applyLang(lang) {
LANG = I18N[lang] ? lang : 'en';
document.documentElement.lang = LANG;
document.title = t('docTitle');
document.querySelectorAll('[data-i18n]').forEach(el => { el.innerHTML = t(el.dataset.i18n); });
document.querySelectorAll('[data-i18n-title]').forEach(el => { el.title = t(el.dataset.i18nTitle); });
document.querySelectorAll('[data-i18n-aria]').forEach(el => { el.setAttribute('aria-label', t(el.dataset.i18nAria)); });
document.getElementById('lang').value = LANG;
document.getElementById('guideLink').href = 'guide.html#' + LANG;
}
const $ = (s, r = document) => r.querySelector(s);
const clamp = (v, a, b) => Math.min(b, Math.max(a, v));
const fmtPct = f => (f * 100).toFixed(1) + '%';
const fmtSize = b => b < 1024 * 1024 ? (b / 1024).toFixed(0) + 'KB' : (b / 1024 / 1024).toFixed(1) + 'MB';
const LANDSCAPE = 1.1; // 가로/세로 비율이 이보다 크면 펼침면으로 봄
const POS_MIN = 0.1, POS_MAX = 0.9;
applyLang(detectLang());
document.getElementById('lang').addEventListener('change', e => {
store.set(LANG_KEY, e.target.value);
applyLang(e.target.value);
refresh({ keepDone: true }); // 언어만 바뀐 것이므로 만들어 둔 결과 링크는 그대로 둔다
});
if (!window.pdfjsLib || !window.PDFLib) {
alert(t('tLibFail'));
return;
}
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js';
const S = {
name: '', size: 0, bytes: null, doc: null,
pages: [], // { w, h, mode: 'split'|'whole'|'skip', pos: number|null }
pos: 0.5, overlap: 0, dir: 'ltr',
gen: 0, busy: false, detecting: false, outUrl: null,
};
const el = {
empty: $('#empty'), workspace: $('#workspace'), drop: $('#drop'), file: $('#file'),
loading: $('#loading'), loadingText: $('#loadingText'), loadingBar: $('#loadingBar'),
grid: $('#grid'), fName: $('#fName'), fMeta: $('#fMeta'),
pos: $('#pos'), posOut: $('#posOut'), overlap: $('#overlap'), ovOut: $('#ovOut'),
btnAuto: $('#btnAuto'), btnClear: $('#btnClear'), btnBuild: $('#btnBuild'), btnBuildLabel: $('#btnBuildLabel'), btnOther: $('#btnOther'),
sumIn: $('#sumIn'), sumOut: $('#sumOut'), buildBarWrap: $('#buildBarWrap'), buildBar: $('#buildBar'), done: $('#done'),
viewer: $('#viewer'), vThumb: $('#vThumb'), vTitle: $('#vTitle'), vInfo: $('#vInfo'), vSeg: $('#vSeg'),
toast: $('#toast'), veil: $('#veil'),
};
/* ───────── helpers ───────── */
let toastTimer;
function toast(msg, ms = 2600) {
el.toast.textContent = msg;
el.toast.classList.add('show');
clearTimeout(toastTimer);
toastTimer = setTimeout(() => el.toast.classList.remove('show'), ms);
}
const effPos = p => p.pos ?? S.pos;
const halves = (s, g) => ({ left: [0, clamp(s + g, 0, 1)], right: [clamp(s - g, 0, 1), 1] });
/* ───────── open file ───────── */
async function openFile(file) {
if (!file) return;
if (S.busy) { toast(t('tBusy')); return; }
if (!/\.pdf$/i.test(file.name) && file.type !== 'application/pdf') { toast(t('tPdfOnly')); return; }
const gen = ++S.gen;
S.detecting = false;
el.loading.hidden = false;
el.loadingText.textContent = t('loadingOpen');
el.loadingBar.style.width = '0%';
try {
const bytes = new Uint8Array(await file.arrayBuffer());
const doc = await pdfjsLib.getDocument({ data: bytes.slice() }).promise;
if (doc.numPages === 0) {
doc.destroy();
toast(t('tNoPages'));
return;
}
// 권한 암호만 걸린 PDF는 열리긴 하지만 내용 스트림이 암호화되어 있어 그대로 복사하면 깨진 파일이 나온다
const info = (await doc.getMetadata().catch(() => ({}))).info || {};
if (info.EncryptFilterName) {
doc.destroy();
toast(t('tEncrypted'), 5000);
return;
}
const pages = [];
for (let i = 1; i <= doc.numPages; i++) {
const pg = await doc.getPage(i);
const vp = pg.getViewport({ scale: 1 });
pages.push({ w: vp.width, h: vp.height, mode: vp.width / vp.height > LANDSCAPE ? 'split' : 'whole', pos: null });
if (i % 20 === 0) {
el.loadingText.textContent = t('loadingPages', { i, n: doc.numPages });
el.loadingBar.style.width = (i / doc.numPages * 100) + '%';
}
}
if (gen !== S.gen) { doc.destroy(); return; }
if (S.doc) S.doc.destroy();
Object.assign(S, { name: file.name, size: file.size, bytes, doc, pages });
showWorkspace();
} catch (err) {
console.error(err);
toast(err && err.name === 'PasswordException' ? t('tPassword') : t('tReadFail'), 4000);
} finally {
if (gen === S.gen) el.loading.hidden = true;
}
}
function showWorkspace() {
el.empty.hidden = true;
el.workspace.hidden = false;
el.fName.textContent = S.name;
el.done.hidden = true;
if (S.outUrl) { URL.revokeObjectURL(S.outUrl); S.outUrl = null; }
buildGrid();
refresh();
window.scrollTo({ top: 0 });
}
/* ───────── overlay (shared by cards & viewer) ───────── */
function ensureOverlay(thumb) {
if (thumb._ov) return thumb._ov;
const band = document.createElement('div'); band.className = 'band';
const cut = document.createElement('div'); cut.className = 'cut'; cut.tabIndex = 0;
cut.setAttribute('role', 'slider');
const tagA = document.createElement('div'); tagA.className = 'tag';
const tagB = document.createElement('div'); tagB.className = 'tag';
const skip = document.createElement('div'); skip.className = 'skip-mark';
thumb.append(band, cut, tagA, tagB, skip);
return (thumb._ov = { band, cut, tagA, tagB, skip });
}
function paintOverlay(thumb, p, nums) {
const ov = ensureOverlay(thumb);
thumb.style.setProperty('--ar', p.w / p.h);
const split = p.mode === 'split';
const s = effPos(p), g = S.overlap;
ov.cut.hidden = ov.band.hidden = !split;
ov.cut.setAttribute('aria-label', t('cutLabel'));
ov.skip.hidden = p.mode !== 'skip';
ov.skip.textContent = t('skipMark');
ov.tagA.hidden = p.mode === 'skip';
ov.tagB.hidden = !split;
if (split) {
ov.cut.style.left = (s * 100) + '%';
ov.cut.setAttribute('aria-valuenow', (s * 100).toFixed(1));
const a = Math.min(s - g, s + g), b = Math.max(s - g, s + g);
ov.band.style.left = (a * 100) + '%';
ov.band.style.width = ((b - a) * 100) + '%';
ov.band.className = 'band ' + (g > 0 ? 'overlap' : 'gap');
const first = nums[0], second = nums[1];
const [lNum, rNum] = S.dir === 'ltr' ? [first, second] : [second, first];
ov.tagA.textContent = lNum; ov.tagA.style.left = (s / 2 * 100) + '%';
ov.tagB.textContent = rNum; ov.tagB.style.left = ((1 + s) / 2 * 100) + '%';
} else if (p.mode === 'whole') {
ov.tagA.textContent = nums[0]; ov.tagA.style.left = '50%';
}
}
function bindCut(thumb, getIndex) {
const { cut } = ensureOverlay(thumb);
cut.addEventListener('pointerdown', e => {
if (e.button !== 0) return;
e.preventDefault();
cut.setPointerCapture(e.pointerId);
thumb.classList.add('dragging');
const move = ev => {
const r = thumb.getBoundingClientRect();
const f = clamp((ev.clientX - r.left) / r.width, POS_MIN, POS_MAX);
setPagePos(getIndex(), Math.round(f * 1000) / 1000);
};
const up = () => {
thumb.classList.remove('dragging');
cut.removeEventListener('pointermove', move);
cut.removeEventListener('pointerup', up);
cut.removeEventListener('pointercancel', up);
};
cut.addEventListener('pointermove', move);
cut.addEventListener('pointerup', up);
cut.addEventListener('pointercancel', up);
});
cut.addEventListener('dblclick', () => setPagePos(getIndex(), null));
cut.addEventListener('keydown', e => {
if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
e.preventDefault(); e.stopPropagation();
const p = S.pages[getIndex()];
const step = (e.shiftKey ? 0.01 : 0.002) * (e.key === 'ArrowLeft' ? -1 : 1);
setPagePos(getIndex(), Math.round(clamp(effPos(p) + step, POS_MIN, POS_MAX) * 1000) / 1000);
});
}
function setPagePos(i, v) {
S.pages[i].pos = v;
refresh();
}
function setPageMode(i, mode) {
S.pages[i].mode = mode;
refresh();
}
/* ───────── grid ───────── */
const ICON_ZOOM = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><circle cx="10.5" cy="10.5" r="6.5"/><path d="m20 20-4.8-4.8"/></svg>';
let io, queue = [], active = 0;
function buildGrid() {
if (io) io.disconnect();
queue = [];
el.grid.textContent = '';
const frag = document.createDocumentFragment();
S.pages.forEach((p, i) => {
const card = document.createElement('div');
card.className = 'card';
card.dataset.i = i;
card.innerHTML = `
<div class="stage"><div class="thumb"><canvas></canvas></div></div>
<div class="card-foot">
<div class="pno"><span></span><em></em></div>
<div class="seg">
<button data-mode="split"></button>
<button data-mode="whole"></button>
<button data-mode="skip"></button>
</div>
<button class="icon-btn" data-zoom>${ICON_ZOOM}</button>
</div>`;
const thumb = card.querySelector('.thumb');
card._thumb = thumb;
card._pno = card.querySelector('.pno span');
card._badge = card.querySelector('.pno em');
card._segBtns = card.querySelectorAll('.seg button');
card._zoom = card.querySelector('[data-zoom]');
bindCut(thumb, () => i);
thumb.addEventListener('dblclick', e => { if (!e.target.closest('.cut')) openViewer(i); });
frag.appendChild(card);
});
el.grid.appendChild(frag);
io = new IntersectionObserver(entries => {
for (const e of entries) {
if (!e.isIntersecting) continue;
io.unobserve(e.target);
queue.push(+e.target.dataset.i);
}
pump();
}, { rootMargin: '900px 0px' });
el.grid.querySelectorAll('.card').forEach(c => io.observe(c));
}
el.grid.addEventListener('click', e => {
const card = e.target.closest('.card');
if (!card) return;
const i = +card.dataset.i;
const modeBtn = e.target.closest('.seg button');
if (modeBtn) setPageMode(i, modeBtn.dataset.mode);
else if (e.target.closest('[data-zoom]')) openViewer(i);
});
function pump() {
const gen = S.gen;
while (active < 3 && queue.length) {
const i = queue.shift();
active++;
renderInto(el.grid.children[i]._thumb, i, 2, 900, gen)
.catch(err => console.warn('thumb', i, err))
.finally(() => { active--; pump(); });
}
}
async function renderInto(thumb, i, dprCap, maxW, gen) {
const page = await S.doc.getPage(i + 1);
if (gen !== S.gen) return;
const canvas = thumb.querySelector('canvas');
const cssW = thumb.clientWidth || 300;
const targetW = Math.min(maxW, Math.round(cssW * Math.min(devicePixelRatio || 1, dprCap)));
const base = page.getViewport({ scale: 1 });
const vp = page.getViewport({ scale: targetW / base.width });
const tmp = document.createElement('canvas');
tmp.width = Math.round(vp.width); tmp.height = Math.round(vp.height);
await page.render({ canvasContext: tmp.getContext('2d'), viewport: vp }).promise;
if (gen !== S.gen) return;
canvas.width = tmp.width; canvas.height = tmp.height;
canvas.getContext('2d').drawImage(tmp, 0, 0);
thumb.classList.add('ready');
}
/* ───────── refresh UI ───────── */
function numbering() {
let n = 1;
return S.pages.map(p => {
if (p.mode === 'split') { n += 2; return [n - 2, n - 1]; }
if (p.mode === 'whole') { n += 1; return [n - 1]; }
return [];
});
}
const MODE_KEYS = { split: 'modeSplit', whole: 'modeWhole', skip: 'modeSkip' };
function refresh({ keepDone = false } = {}) {
if (el.workspace.hidden) return;
const nums = numbering();
const total = nums.reduce((a, x) => a + x.length, 0);
let overrides = 0;
S.pages.forEach((p, i) => {
const card = el.grid.children[i];
if (!card) return;
card.className = 'card mode-' + p.mode;
paintOverlay(card._thumb, p, nums[i]);
card._pno.textContent = t('pageN', { n: i + 1 });
card._zoom.setAttribute('aria-label', t('zoomN', { n: i + 1 }));
card._zoom.title = t('zoomTitle');
card._segBtns.forEach(b => { b.setAttribute('aria-pressed', b.dataset.mode === p.mode); b.textContent = t(MODE_KEYS[b.dataset.mode]); });
const custom = p.mode === 'split' && p.pos != null;
card._badge.textContent = custom ? fmtPct(p.pos) : '';
if (p.pos != null) overrides++;
});
const nSplit = S.pages.filter(p => p.mode === 'split').length;
el.fMeta.textContent = t('meta', { n: S.pages.length, size: fmtSize(S.size), s: nSplit });
el.sumIn.textContent = S.pages.length;
el.sumOut.textContent = total;
el.btnClear.disabled = overrides === 0;
el.btnClear.textContent = overrides ? t('clearN', { n: overrides }) : t('clear');
if (!S.detecting) el.btnAuto.textContent = t('auto');
el.posOut.textContent = fmtPct(S.pos);
el.ovOut.textContent = (S.overlap > 0 ? '+' : S.overlap < 0 ? '−' : '') + Math.abs(S.overlap * 100).toFixed(1) + '%';
el.btnBuild.disabled = total === 0 || S.busy;
// 한꺼번에 고르기 — 현재 상태와 일치하는 버튼 표시
const modes = S.pages.map(p => p.mode);
const autoModes = S.pages.map(p => p.w / p.h > LANDSCAPE ? 'split' : 'whole');
const match = {
auto: modes.every((m, i) => m === autoModes[i]),
split: modes.every(m => m === 'split'),
whole: modes.every(m => m === 'whole'),
};
let pressed = match.auto ? 'auto' : match.split ? 'split' : match.whole ? 'whole' : '';
document.querySelectorAll('#bulkSeg button').forEach(b => b.setAttribute('aria-pressed', b.dataset.bulk === pressed));
document.querySelectorAll('#dirSeg button').forEach(b => b.setAttribute('aria-pressed', b.dataset.dir === S.dir));
if (el.viewer.open) paintViewer();
if (!keepDone) el.done.hidden = true;
}
/* ───────── panel controls ───────── */
el.pos.addEventListener('input', () => { S.pos = +el.pos.value / 100; refresh(); });
el.overlap.addEventListener('input', () => { S.overlap = +el.overlap.value / 100; refresh(); });
$('#dirSeg').addEventListener('click', e => {
const b = e.target.closest('button'); if (!b) return;
S.dir = b.dataset.dir; refresh();
});
$('#bulkSeg').addEventListener('click', e => {
const b = e.target.closest('button'); if (!b) return;
S.pages.forEach(p => {
p.mode = b.dataset.bulk === 'auto' ? (p.w / p.h > LANDSCAPE ? 'split' : 'whole') : b.dataset.bulk;
});
refresh();
});
el.btnClear.addEventListener('click', () => { S.pages.forEach(p => p.pos = null); refresh(); toast(t('tCleared')); });
el.btnOther.addEventListener('click', () => el.file.click());
/* ───────── auto detect gutter ───────── */
el.btnAuto.addEventListener('click', async () => {
if (S.detecting) { S.detecting = false; return; }
const targets = S.pages.map((p, i) => i).filter(i => S.pages[i].mode === 'split');
if (!targets.length) { toast(t('tNoSplit')); return; }
S.detecting = true;
const gen = S.gen;
let found = 0, done = 0;
for (const i of targets) {
if (!S.detecting || gen !== S.gen) break;
el.btnAuto.textContent = t('autoBusy', { done, total: targets.length });
try {
const f = await detectGutter(i);
if (gen !== S.gen) break;
if (f != null) { S.pages[i].pos = Math.round(f * 1000) / 1000; found++; }
} catch (err) { console.warn('detect', i, err); }
done++;
if (done % 4 === 0) refresh();
}
S.detecting = false;
el.btnAuto.textContent = t('auto');
if (gen !== S.gen) return;
refresh();
toast(found ? t('tFound', { n: found }) : t('tNotFound'), 3600);
});
async function detectGutter(i) {
const page = await S.doc.getPage(i + 1);
const base = page.getViewport({ scale: 1 });
const vp = page.getViewport({ scale: 600 / base.width });
const c = document.createElement('canvas');