-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
962 lines (894 loc) · 49.6 KB
/
Copy pathindex.html
File metadata and controls
962 lines (894 loc) · 49.6 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
<!doctype html>
<html lang="zh-CN" data-theme="light">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>火星文翻译器 · 在线翻译</title>
<style>
/* ============================================================
设计令牌 DESIGN TOKENS — 火星文翻译器 V2 设计系统
主题:活泼品牌化(品红 × 紫 宇宙渐变)
============================================================ */
:root {
/* 色彩 · 品牌 */
--brand: #FF3E7F;
--brand-600: #E62E6C;
--brand-2: #7C5CFF;
--brand-grad: linear-gradient(135deg, #FF3E7F 0%, #7C5CFF 100%);
--brand-grad-soft: linear-gradient(135deg, rgba(255,62,127,.12) 0%, rgba(124,92,255,.12) 100%);
--accent: #FF9F43; /* 收藏/星标暖色 */
--accent-soft: #FFF1E0;
/* 色彩 · 语义 */
--success: #15B97A;
--warning: #F5A623;
--danger: #FF4D4F;
--info: #3D8BFF;
/* 色彩 · 中性(浅色) */
--bg: #FBF8FF;
--surface: #FFFFFF;
--surface-2: #F6F3FF;
--surface-3: #EFEAFB;
--border: #ECE7F5;
--border-strong: #DDD4EE;
--text: #1B1730;
--text-sub: #6A6385;
--text-muted: #9A93B2;
/* 背景装饰光斑 */
--blob-1: #FFD6EA;
--blob-2: #DDD4FF;
/* 字体 */
--font-sans: 'Inter', 'PingFang SC', 'Microsoft YaHei', system-ui, -apple-system, sans-serif;
--font-mono: 'JetBrains Mono', 'SFMono-Regular', ui-monospace, Menlo, monospace;
/* 字号阶梯 */
--fs-xs: 12px;
--fs-sm: 13px;
--fs-base: 14px;
--fs-md: 16px;
--fs-lg: 18px;
--fs-xl: 20px;
--fs-2xl: 24px;
--fs-3xl: 30px;
--fs-4xl: 38px;
/* 字重 */
--fw-400: 400;
--fw-500: 500;
--fw-600: 600;
--fw-700: 700;
--fw-800: 800;
/* 间距(4px 基准) */
--sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
--sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px; --sp-16: 64px;
/* 圆角 */
--r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 20px; --r-pill: 999px;
/* 阴影 */
--sh-sm: 0 1px 2px rgba(27,23,48,.06), 0 1px 3px rgba(27,23,48,.05);
--sh-md: 0 6px 16px rgba(27,23,48,.08);
--sh-lg: 0 16px 40px rgba(124,92,255,.16);
--sh-glow: 0 8px 24px rgba(255,62,127,.28);
/* 动效 */
--t-fast: 140ms ease;
--t-norm: 260ms cubic-bezier(.4,0,.2,1);
}
[data-theme="dark"] {
--bg: #0E0B1E;
--surface: #17122E;
--surface-2: #1F1838;
--surface-3: #271E47;
--border: #2A2348;
--border-strong: #3A3163;
--text: #F3EEFF;
--text-sub: #ABA0CE;
--text-muted: #7E739F;
--blob-1: #3A1840;
--blob-2: #241A4D;
--accent-soft: #3A2A12;
/* 品牌 / 语义色 · 暗色令牌(严格对齐 design-system §4.1,不可混用浅色值) */
--brand: #FF5C95;
--brand-2: #9C86FF;
--accent: #FFB45E;
--success: #2FD493;
--warning: #FFC04D;
--danger: #FF6B6E;
--info: #5BA0FF;
--sh-sm: 0 1px 2px rgba(0,0,0,.4);
--sh-md: 0 6px 16px rgba(0,0,0,.45);
--sh-lg: 0 16px 40px rgba(0,0,0,.55);
--sh-glow: 0 8px 24px rgba(255,62,127,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
font-family: var(--font-sans);
background: var(--bg);
color: var(--text);
font-size: var(--fs-base);
line-height: 1.55;
-webkit-font-smoothing: antialiased;
transition: background var(--t-norm), color var(--t-norm);
}
::selection { background: rgba(255,62,127,.22); }
/* 背景装饰 */
.bg-deco { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.bg-deco::before, .bg-deco::after {
content: ""; position: absolute; width: 520px; height: 520px; border-radius: 50%;
filter: blur(90px); opacity: .55;
}
.bg-deco::before { background: var(--blob-1); top: -160px; right: -120px; }
.bg-deco::after { background: var(--blob-2); bottom: -180px; left: -120px; }
/* ============================================================
应用骨架
============================================================ */
.app { position: relative; z-index: 1; display: grid; grid-template-columns: 256px 1fr; min-height: 100vh; }
/* 侧边栏 */
.sidebar {
border-right: 1px solid var(--border);
background: color-mix(in srgb, var(--surface) 80%, transparent);
backdrop-filter: blur(12px);
padding: var(--sp-6) var(--sp-4);
display: flex; flex-direction: column; gap: var(--sp-6);
position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-2); }
.brand-logo { width: 40px; height: 40px; flex: none; }
.brand-name { font-size: var(--fs-lg); font-weight: var(--fw-800); letter-spacing: .3px; }
.brand-name b { background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-tag { font-size: var(--fs-xs); color: var(--text-sub); font-weight: var(--fw-600); }
.nav { display: flex; flex-direction: column; gap: var(--sp-2); }
.nav-label { font-size: var(--fs-xs); color: var(--text-muted); font-weight: var(--fw-700); letter-spacing: .08em; text-transform: uppercase; padding: 0 var(--sp-3); margin-bottom: var(--sp-1); }
.nav-item {
display: flex; align-items: center; gap: var(--sp-3);
padding: var(--sp-3) var(--sp-3); border-radius: var(--r-md);
color: var(--text-sub); font-weight: var(--fw-600); font-size: var(--fs-md);
cursor: pointer; border: 1px solid transparent; background: transparent;
transition: all var(--t-fast); text-align: left; width: 100%; font-family: inherit;
}
.nav-item svg { width: 20px; height: 20px; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--brand-grad-soft); color: var(--brand-600); border-color: color-mix(in srgb, var(--brand) 30%, transparent); }
[data-theme="dark"] .nav-item.active { color: #FFB3D2; }
.nav-item .badge { margin-left: auto; background: var(--brand); color: #fff; font-size: 11px; font-weight: 700; border-radius: var(--r-pill); padding: 1px 8px; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--sp-3); }
.theme-toggle {
display: flex; align-items: center; gap: var(--sp-3); width: 100%;
padding: var(--sp-3); border-radius: var(--r-md); border: 1px solid var(--border);
background: var(--surface); color: var(--text); cursor: pointer; font-family: inherit; font-size: var(--fs-base); font-weight: var(--fw-600);
}
.theme-toggle:hover { border-color: var(--border-strong); }
.theme-toggle svg { width: 20px; height: 20px; flex: none; }
/* 主区域 */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
display: flex; align-items: center; gap: var(--sp-4);
padding: var(--sp-5) var(--sp-8); border-bottom: 1px solid var(--border);
position: sticky; top: 0; z-index: 5;
background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(10px);
}
.topbar h1 { font-size: var(--fs-2xl); font-weight: var(--fw-800); margin: 0; letter-spacing: .2px; }
.topbar .crumb { font-size: var(--fs-sm); color: var(--text-sub); }
.topbar .spacer { flex: 1; }
.topbar-actions { display: flex; gap: var(--sp-2); }
.content { padding: var(--sp-8); max-width: 1180px; width: 100%; margin: 0 auto; }
.view { display: none; animation: fade .3s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
/* ============================================================
组件
============================================================ */
.btn {
display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
font-family: inherit; font-weight: var(--fw-600); font-size: var(--fs-base);
padding: 10px 18px; border-radius: var(--r-md); border: 1px solid var(--border);
background: var(--surface); color: var(--text); cursor: pointer;
transition: all var(--t-fast); white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--sh-sm); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.primary { background: var(--brand-grad); color: #fff; border: none; box-shadow: var(--sh-glow); }
.btn.primary:hover { filter: brightness(1.05); box-shadow: var(--sh-lg); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 7px 13px; font-size: var(--fs-sm); }
.btn.icon { padding: 9px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--sh-sm); }
.card-pad { padding: var(--sp-6); }
/* 芯片 */
.chip {
display: inline-flex; align-items: center; gap: var(--sp-2);
padding: 8px 16px; border-radius: var(--r-pill); border: 1px solid var(--border);
background: var(--surface); color: var(--text-sub); cursor: pointer; font-family: inherit;
font-size: var(--fs-base); font-weight: var(--fw-600); transition: all var(--t-fast);
}
.chip:hover { border-color: var(--brand); color: var(--text); }
.chip.active { background: var(--brand-grad); color: #fff; border: none; box-shadow: var(--sh-glow); }
/* 分段控制 */
.segmented { display: inline-flex; padding: 4px; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-pill); }
.segmented button {
border: none; background: transparent; font-family: inherit; font-weight: var(--fw-700);
font-size: var(--fs-md); color: var(--text-sub); padding: 9px 20px; border-radius: var(--r-pill);
cursor: pointer; transition: all var(--t-fast); display: inline-flex; align-items: center; gap: var(--sp-2);
}
.segmented button.active { background: var(--surface); color: var(--brand-600); box-shadow: var(--sh-sm); }
[data-theme="dark"] .segmented button.active { color: #FFB3D2; }
/* 开关 */
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--border-strong); border-radius: var(--r-pill); transition: var(--t-fast); cursor: pointer; }
.switch .track::before { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: var(--t-fast); box-shadow: var(--sh-sm); }
.switch input:checked + .track { background: var(--brand-grad); }
.switch input:checked + .track::before { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--brand); outline-offset: 2px; }
/* 标签 */
.tag { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: var(--r-sm); font-size: var(--fs-xs); font-weight: var(--fw-700); background: var(--surface-3); color: var(--text-sub); }
.tag.brand { background: var(--brand-grad-soft); color: var(--brand-600); }
[data-theme="dark"] .tag.brand { color: #FFB3D2; }
/* ============================================================
翻译工作台
============================================================ */
.dir-row { display: flex; align-items: center; gap: var(--sp-4); margin-bottom: var(--sp-6); flex-wrap: wrap; }
.swap-btn {
width: 44px; height: 44px; flex: none; border-radius: 50%; border: 1px solid var(--border);
background: var(--surface); color: var(--brand); cursor: pointer; display: grid; place-items: center;
transition: all var(--t-fast); box-shadow: var(--sh-sm);
}
.swap-btn:hover { transform: rotate(180deg); border-color: var(--brand); box-shadow: var(--sh-glow); }
.swap-btn svg { width: 20px; height: 20px; }
.work-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-5); align-items: stretch; }
.pane { display: flex; flex-direction: column; }
.pane-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-3); }
.pane-head .label { font-weight: var(--fw-700); font-size: var(--fs-md); display: flex; align-items: center; gap: var(--sp-2); }
.pane-head .label .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand-grad); }
.pane-head .count { font-size: var(--fs-sm); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.textbox {
width: 100%; min-height: 240px; resize: vertical; flex: 1;
border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface);
padding: var(--sp-5); font-family: inherit; font-size: var(--fs-lg); line-height: 1.7; color: var(--text);
transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.textbox:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(255,62,127,.12); }
.textbox[readonly] { background: var(--surface-2); color: var(--text); }
.pane-foot { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-3); flex-wrap: wrap; }
.pane-foot .spacer { flex: 1; }
.example-chips { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.example-chips .chip { padding: 5px 12px; font-size: var(--fs-sm); }
.result-empty { display: grid; place-items: center; min-height: 240px; color: var(--text-muted); text-align: center; gap: var(--sp-2); }
.result-empty svg { width: 48px; height: 48px; opacity: .5; }
.star-on { color: var(--accent); }
mark.unk { background: var(--accent-soft); color: #B26A00; border-radius: 4px; padding: 0 2px; }
[data-theme="dark"] mark.unk { color: #FFC77A; }
/* 配置栏 */
.config-card { margin-top: var(--sp-6); }
.config-card h3 { margin: 0 0 var(--sp-4); font-size: var(--fs-lg); display: flex; align-items: center; gap: var(--sp-2); }
.config-card h3 svg { width: 20px; height: 20px; color: var(--brand); }
.config-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: var(--sp-6); }
.config-block .blk-title { font-size: var(--fs-sm); font-weight: var(--fw-700); color: var(--text-sub); margin-bottom: var(--sp-3); letter-spacing: .04em; }
.style-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.rule-toggles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.rule-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); }
.rule-row .r-name { font-weight: var(--fw-600); font-size: var(--fs-base); }
.rule-row .r-desc { font-size: var(--fs-xs); color: var(--text-muted); }
.rule-row .switch { margin-left: auto; }
.intensity-row { display: flex; align-items: center; gap: var(--sp-4); }
.intensity-row .segmented { flex: 1; }
.intensity-row .segmented button { flex: 1; justify-content: center; }
.whitelist { margin-top: var(--sp-4); }
.whitelist input {
width: 100%; padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border); border-radius: var(--r-md);
font-family: inherit; font-size: var(--fs-base); background: var(--surface); color: var(--text);
}
.whitelist input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(255,62,127,.12); }
/* ============================================================
历史 / 收藏 列表
============================================================ */
.list-head { display: flex; align-items: center; gap: var(--sp-4); margin-bottom: var(--sp-5); flex-wrap: wrap; }
.search {
display: flex; align-items: center; gap: var(--sp-2); padding: 9px 14px; border: 1px solid var(--border);
border-radius: var(--r-pill); background: var(--surface); min-width: 260px; flex: 1; max-width: 360px;
}
.search svg { width: 18px; height: 18px; color: var(--text-muted); }
.search input { border: none; background: transparent; outline: none; font-family: inherit; font-size: var(--fs-base); color: var(--text); flex: 1; }
.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--sp-4); }
.rec {
background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-4);
box-shadow: var(--sh-sm); transition: all var(--t-fast); display: flex; flex-direction: column; gap: var(--sp-2);
}
.rec:hover { transform: translateY(-2px); box-shadow: var(--sh-md); border-color: var(--border-strong); }
.rec-meta { display: flex; align-items: center; gap: var(--sp-2); }
.rec-src { color: var(--text-sub); font-size: var(--fs-sm); word-break: break-word; }
.rec-res { font-size: var(--fs-lg); font-weight: var(--fw-700); word-break: break-word; }
.rec-foot { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-1); }
.rec-foot .spacer { flex: 1; }
.mini-btn { border: none; background: transparent; color: var(--text-sub); cursor: pointer; padding: 6px; border-radius: var(--r-sm); display: inline-flex; }
.mini-btn:hover { background: var(--surface-2); color: var(--text); }
.mini-btn svg { width: 18px; height: 18px; }
.mini-btn.on { color: var(--accent); }
.empty-state { text-align: center; color: var(--text-muted); padding: var(--sp-16) var(--sp-4); }
.empty-state svg { width: 56px; height: 56px; opacity: .4; margin-bottom: var(--sp-3); }
/* 设置 */
.settings { display: grid; gap: var(--sp-5); max-width: 720px; }
.set-sec { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); padding: var(--sp-6); box-shadow: var(--sh-sm); }
.set-sec h3 { margin: 0 0 var(--sp-4); font-size: var(--fs-lg); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); padding: var(--sp-3) 0; border-bottom: 1px solid var(--border); }
.set-row:last-child { border-bottom: none; }
.set-row .s-label { font-weight: var(--fw-600); }
.set-row .s-desc { font-size: var(--fs-sm); color: var(--text-muted); }
/* Toast */
.toast {
position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%) translateY(20px);
background: var(--text); color: var(--bg); padding: 11px 22px; border-radius: var(--r-pill);
font-weight: var(--fw-700); font-size: var(--fs-base); box-shadow: var(--sh-lg); z-index: 200;
opacity: 0; pointer-events: none; transition: all var(--t-norm); display: flex; align-items: center; gap: var(--sp-2);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast svg { width: 18px; height: 18px; }
/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(14,11,30,.55); display: none; align-items: center; justify-content: center; z-index: 150; padding: var(--sp-4); backdrop-filter: blur(4px); }
.modal-backdrop.show { display: flex; }
.modal { background: var(--surface); border-radius: var(--r-xl); max-width: 440px; width: 100%; box-shadow: var(--sh-lg); overflow: hidden; animation: pop .25s ease; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); font-weight: var(--fw-700); }
.modal-body { padding: var(--sp-5); display: grid; place-items: center; }
.modal-foot { padding: var(--sp-4) var(--sp-5); display: flex; gap: var(--sp-2); justify-content: flex-end; border-top: 1px solid var(--border); }
.share-card { width: 100%; max-width: 360px; border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--sh-md); }
.close-x { border: none; background: transparent; cursor: pointer; color: var(--text-sub); padding: 6px; border-radius: var(--r-sm); display: inline-flex; }
.close-x:hover { background: var(--surface-2); color: var(--text); }
.close-x svg { width: 20px; height: 20px; }
/* ============================================================
响应式 RESPONSIVE
============================================================ */
@media (max-width: 1024px) {
.app { grid-template-columns: 1fr; }
.sidebar {
position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; width: 100%;
flex-direction: row; border-right: none; border-top: 1px solid var(--border);
padding: var(--sp-2) var(--sp-3); gap: var(--sp-2); z-index: 100;
background: color-mix(in srgb, var(--surface) 92%, transparent);
}
.brand, .nav-label, .sidebar-foot .theme-toggle .txt { display: none; }
.nav { flex-direction: row; flex: 1; justify-content: space-around; }
.nav-item { flex-direction: column; gap: 2px; padding: var(--sp-2); font-size: 11px; }
.nav-item .badge { display: none; }
.sidebar-foot { margin: 0; }
.theme-toggle { width: auto; padding: var(--sp-2); }
.content { padding: var(--sp-5) var(--sp-4) 96px; }
.topbar { padding: var(--sp-4) var(--sp-4); }
.work-grid { grid-template-columns: 1fr; }
.config-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
.dir-row { gap: var(--sp-2); }
.segmented button { padding: 8px 14px; font-size: var(--fs-base); }
.topbar h1 { font-size: var(--fs-xl); }
.rule-toggles { grid-template-columns: 1fr; }
.list { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<div class="bg-deco"></div>
<div class="app">
<!-- ============ 侧边导航 ============ -->
<aside class="sidebar">
<div class="brand">
<svg class="brand-logo" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<defs><linearGradient id="g1" x1="0" y1="0" x2="1" y2="1">
<stop offset="0" stop-color="#FF3E7F"/><stop offset="1" stop-color="#7C5CFF"/></linearGradient></defs>
<circle cx="24" cy="24" r="13" fill="url(#g1)"/>
<ellipse cx="24" cy="24" rx="22" ry="8" fill="none" stroke="url(#g1)" stroke-width="3" transform="rotate(-22 24 24)"/>
<circle cx="24" cy="24" r="4.5" fill="#fff" opacity=".9"/>
</svg>
<div>
<div class="brand-name">火星文<b>翻译器</b></div>
<div class="brand-tag">MARS · 纯前端确定性翻译</div>
</div>
</div>
<nav class="nav" aria-label="主导航">
<div class="nav-label">工作区</div>
<button class="nav-item active" data-nav="translate">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 5h16M7 9h10M4 13h16M7 17h7"/></svg>
翻译工作台 <span class="badge">主</span>
</button>
<button class="nav-item" data-nav="history">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 3-6.7L3 8"/><path d="M3 4v4h4"/><path d="M12 8v4l3 2"/></svg>
历史记录
</button>
<button class="nav-item" data-nav="favorites">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 17.3l-5.4 3.2 1.4-6.2L3 9.9l6.3-.5L12 3.6l2.7 5.8 6.3.5-4.9 4.4 1.4 6.2z"/></svg>
我的收藏
</button>
<div class="nav-label">系统</div>
<button class="nav-item" data-nav="settings">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.6 1.6 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.6 1.6 0 0 0-2.7 1.1V21a2 2 0 1 1-4 0v-.1A1.6 1.6 0 0 0 7 19.4a1.6 1.6 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1A1.6 1.6 0 0 0 2.6 14H2.5a2 2 0 1 1 0-4h.1A1.6 1.6 0 0 0 4 7.6a1.6 1.6 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1A1.6 1.6 0 0 0 9 2.6V2.5a2 2 0 1 1 4 0v.1a1.6 1.6 0 0 0 2.7 1.1l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.6 1.6 0 0 0-.3 1.8 1.6 1.6 0 0 0 1.4.9h.1a2 2 0 1 1 0 4h-.1a1.6 1.6 0 0 0-1.5 1z"/></svg>
设置
</button>
</nav>
<div class="sidebar-foot">
<button class="theme-toggle" id="themeBtn" aria-label="切换主题">
<svg id="themeIcon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4.5"/><path d="M12 2v2M12 20v2M4 12H2M22 12h-2M5 5l1.5 1.5M17.5 17.5L19 19M19 5l-1.5 1.5M6.5 17.5L5 19"/></svg>
<span class="txt" id="themeTxt">深色模式</span>
</button>
</div>
</aside>
<!-- ============ 主区域 ============ -->
<div class="main">
<header class="topbar">
<div>
<h1 id="pageTitle">翻译工作台</h1>
<div class="crumb" id="pageCrumb">火星文翻译器 › 工作区</div>
</div>
<div class="spacer"></div>
<div class="topbar-actions">
<button class="btn ghost sm" id="helpBtn">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M9.5 9a2.5 2.5 0 1 1 3.5 2.3c-.8.4-1 .9-1 1.7"/><circle cx="12" cy="17" r=".6" fill="currentColor"/></svg>
使用指南
</button>
</div>
</header>
<div class="content">
<!-- ====== 视图:翻译 ====== -->
<section class="view active" id="view-translate">
<div class="dir-row">
<div class="segmented" role="tablist" aria-label="翻译方向">
<button class="active" data-dir="han-mars" role="tab" aria-selected="true">汉 → 火</button>
<button data-dir="mars-han" role="tab" aria-selected="false">火 → 汉</button>
</div>
<button class="swap-btn" id="swapBtn" title="交换方向" aria-label="交换方向">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7 10H3l4-4M3 10l4 4"/><path d="M17 14h4l-4 4M21 14l-4-4"/></svg>
</button>
<span class="tag brand" id="dirTag">汉语 → 火星文</span>
</div>
<div class="work-grid">
<!-- 源 -->
<div class="pane">
<div class="pane-head">
<span class="label"><span class="dot"></span><span id="srcLabel">源文本(中文)</span></span>
<span class="count"><span id="srcCount">0</span> 字</span>
</div>
<textarea class="textbox" id="srcBox" placeholder="输入中文,例如:你好,世界" spellcheck="false">你好,世界!今天天气真不错,我们一起去火星探险吧。</textarea>
<div class="pane-foot">
<button class="btn sm ghost" id="clearBtn">清空</button>
<span class="spacer"></span>
<div class="example-chips">
<button class="chip" data-ex="我爱你,中国">示例 1</button>
<button class="chip" data-ex="今晚的月色真美">示例 2</button>
<button class="chip" data-ex="生活明朗,万物可爱">示例 3</button>
</div>
</div>
</div>
<!-- 结果 -->
<div class="pane">
<div class="pane-head">
<span class="label"><span class="dot"></span><span id="dstLabel">火星文结果</span></span>
<span class="count"><span id="dstCount">0</span> 字</span>
</div>
<div class="textbox" id="dstBox" readonly>伱恏,卋鎅!婄兲兲氣湞吥措,涐們①起厾吙煋探嶮吧。</div>
<div class="pane-foot">
<button class="btn primary sm" id="copyBtn">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2"/><path d="M5 15V5a2 2 0 0 1 2-2h10"/></svg>
复制
</button>
<button class="btn sm" id="shareBtn">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12v7a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-7"/><path d="M12 3v13M8 7l4-4 4 4"/></svg>
分享卡片
</button>
<button class="btn sm ghost" id="favBtn" aria-pressed="false">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 17.3l-5.4 3.2 1.4-6.2L3 9.9l6.3-.5L12 3.6l2.7 5.8 6.3.5-4.9 4.4 1.4 6.2z"/></svg>
收藏
</button>
</div>
</div>
</div>
<!-- 规则配置 -->
<div class="card card-pad config-card">
<h3>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3v3M12 18v3M3 12h3M18 12h3M5.6 5.6l2.1 2.1M16.3 16.3l2.1 2.1M18.4 5.6l-2.1 2.1M7.7 16.3l-2.1 2.1"/><circle cx="12" cy="12" r="3"/></svg>
转换规则配置
</h3>
<div class="config-grid">
<div class="config-block">
<div class="blk-title">风格模板</div>
<div class="style-chips" id="styleChips">
<button class="chip active" data-style="anime">二次元</button>
<button class="chip" data-style="retro">复古</button>
<button class="chip" data-style="minimal">极简</button>
<button class="chip" data-style="custom">自定义</button>
</div>
<div class="blk-title" style="margin-top:var(--sp-5)">替换强度</div>
<div class="intensity-row">
<div class="segmented" id="intensitySeg">
<button data-int="low">低</button>
<button class="active" data-int="mid">中</button>
<button data-int="high">高</button>
</div>
</div>
<div class="whitelist">
<div class="blk-title">字符集白名单(命中才插入,规避平台过滤)</div>
<input id="wlInput" value="我爱火星文★☆♡" placeholder="允许的插入符号 / 字符" />
</div>
</div>
<div class="config-block">
<div class="blk-title">规则开关(7 类)</div>
<div class="rule-toggles" id="ruleToggles">
<label class="rule-row"><span><span class="r-name">同音字</span><br><span class="r-desc">用发音相近字替换</span></span><span class="switch"><input type="checkbox" checked><span class="track"></span></span></label>
<label class="rule-row"><span><span class="r-name">形近字</span><br><span class="r-desc">用字形相近字替换</span></span><span class="switch"><input type="checkbox" checked><span class="track"></span></span></label>
<label class="rule-row"><span><span class="r-name">注音混入</span><br><span class="r-desc">插入注音符号</span></span><span class="switch"><input type="checkbox" checked><span class="track"></span></span></label>
<label class="rule-row"><span><span class="r-name">拆字重组</span><br><span class="r-desc">偏旁部首拆解</span></span><span class="switch"><input type="checkbox"><span class="track"></span></span></label>
<label class="rule-row"><span><span class="r-name">符号穿插</span><br><span class="r-desc">emoji/符号点缀</span></span><span class="switch"><input type="checkbox" checked><span class="track"></span></span></label>
<label class="rule-row"><span><span class="r-name">假名借用</span><br><span class="r-desc">日语假名替换</span></span><span class="switch"><input type="checkbox"><span class="track"></span></span></label>
<label class="rule-row"><span><span class="r-name">首字母缩写</span><br><span class="r-desc">拼音首字母</span></span><span class="switch"><input type="checkbox"><span class="track"></span></span></label>
</div>
</div>
</div>
</div>
</section>
<!-- ====== 视图:历史 ====== -->
<section class="view" id="view-history">
<div class="list-head">
<div class="search">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.2-3.2"/></svg>
<input placeholder="搜索历史翻译…" />
</div>
<button class="btn sm ghost">按时间</button>
<button class="btn sm ghost">按方向</button>
</div>
<div class="list" id="historyList"></div>
</section>
<!-- ====== 视图:收藏 ====== -->
<section class="view" id="view-favorites">
<div class="list-head">
<div class="search">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.2-3.2"/></svg>
<input placeholder="搜索收藏…" />
</div>
</div>
<div class="list" id="favList"></div>
</section>
<!-- ====== 视图:设置 ====== -->
<section class="view" id="view-settings">
<div class="settings">
<div class="set-sec">
<h3>外观</h3>
<div class="set-row">
<div><div class="s-label">主题</div><div class="s-desc">浅色 / 深色,跟随系统或手动切换</div></div>
<div class="segmented" data-role="theme"><button class="active" data-theme-opt="light">浅色</button><button data-theme-opt="dark">深色</button></div>
</div>
<div class="set-row">
<div><div class="s-label">强调色</div><div class="s-desc">全局品牌主色</div></div>
<div class="segmented"><button class="active">品红·紫</button><button>青·蓝</button></div>
</div>
</div>
<div class="set-sec">
<h3>翻译默认值</h3>
<div class="set-row">
<div><div class="s-label">默认方向</div><div class="s-desc">打开应用时的起始方向</div></div>
<div class="segmented"><button class="active">汉 → 火</button><button>火 → 汉</button></div>
</div>
<div class="set-row">
<div><div class="s-label">自动保存历史</div><div class="s-desc">每次翻译后记录到本地</div></div>
<span class="switch"><input type="checkbox" checked><span class="track"></span></span>
</div>
<div class="set-row">
<div><div class="s-label">长文本自动分批</div><div class="s-desc">超过 1000 字按词边界切分并显示进度</div></div>
<span class="switch"><input type="checkbox" checked><span class="track"></span></span>
</div>
</div>
<div class="set-sec">
<h3>关于</h3>
<div class="set-row"><div class="s-label">版本</div><div class="s-desc">V2 设计方案 · UI Designer</div></div>
<div class="set-row"><div class="s-label">引擎</div><div class="s-desc">纯前端 · 零联网 · 确定性可复现</div></div>
</div>
</div>
</section>
</div>
</div>
</div>
<!-- Toast -->
<div class="toast" id="toast"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg><span id="toastMsg">已复制</span></div>
<!-- 分享卡 Modal -->
<div class="modal-backdrop" id="shareModal">
<div class="modal" role="dialog" aria-modal="true" aria-label="分享卡片">
<div class="modal-head">分享卡片
<button class="close-x" id="closeShare" aria-label="关闭"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18M6 6l12 12"/></svg></button>
</div>
<div class="modal-body">
<canvas class="share-card" id="shareCanvas" width="720" height="900"></canvas>
</div>
<div class="modal-foot">
<button class="btn ghost sm" id="closeShare2">取消</button>
<button class="btn primary sm" id="dlShare">下载 PNG</button>
</div>
</div>
</div>
<script src="engine/mars-engine.js"></script>
<script>
(function () {
"use strict";
var $ = function (s, r) { return (r || document).querySelector(s); };
var $$ = function (s, r) { return Array.prototype.slice.call((r || document).querySelectorAll(s)); };
/* ---------- 主题切换 ---------- */
var html = document.documentElement;
var themeBtn = $("#themeBtn"), themeTxt = $("#themeTxt");
function applyTheme(t) {
html.setAttribute("data-theme", t);
themeTxt.textContent = t === "dark" ? "浅色模式" : "深色模式";
// 同步设置页「主题」分段控件选中态(与侧栏主题按钮联动)
$$('[data-role="theme"] button').forEach(function (x) {
x.classList.toggle("active", x.getAttribute("data-theme-opt") === t);
});
try { localStorage.setItem("mt-theme", t); } catch (e) {}
}
var saved = "light";
try { saved = localStorage.getItem("mt-theme") || "light"; } catch (e) {}
applyTheme(saved);
themeBtn.addEventListener("click", function () {
applyTheme(html.getAttribute("data-theme") === "dark" ? "light" : "dark");
});
/* 设置页「主题」分段控件(与侧栏主题按钮联动,共享 applyTheme) */
$$('[data-role="theme"] button').forEach(function (b) {
b.addEventListener("click", function () { applyTheme(b.getAttribute("data-theme-opt")); });
});
/* ---------- 导航切换 ---------- */
var titles = {
translate: ["翻译工作台", "火星文翻译器 › 工作区"],
history: ["历史记录", "火星文翻译器 › 工作区 › 历史"],
favorites: ["我的收藏", "火星文翻译器 › 工作区 › 收藏"],
settings: ["设置", "火星文翻译器 › 系统 › 设置"]
};
$$(".nav-item").forEach(function (b) {
b.addEventListener("click", function () {
var key = b.getAttribute("data-nav");
$$(".nav-item").forEach(function (x) { x.classList.remove("active"); });
b.classList.add("active");
$$(".view").forEach(function (v) { v.classList.remove("active"); });
$("#view-" + key).classList.add("active");
$("#pageTitle").textContent = titles[key][0];
$("#pageCrumb").textContent = titles[key][1];
if (key === "history") renderHistory();
if (key === "favorites") renderFavs();
});
});
/* ---------- 真实引擎接线(engine/mars-engine.js 暴露全局 MarsTranslator) ---------- */
var state = {
strength: "mid",
families: Object.assign({}, MarsTranslator.DEFAULT_CONFIG.families),
traditional: false,
whitelist: (($("#wlInput") && $("#wlInput").value) || "我爱火星文★☆♡").split("").filter(Boolean)
};
function buildConfig() {
var wl = (state.whitelist && state.whitelist.length) ? state.whitelist : MarsTranslator.DEFAULT_CONFIG.whitelist.symbols;
return {
strength: state.strength,
families: Object.assign({}, state.families),
traditional: state.traditional,
whitelist: { symbols: wl },
style: "custom"
};
}
function runEngine(text, d) {
var src = d === "han-mars" ? "han" : "mars";
var tgt = d === "han-mars" ? "mars" : "han";
return MarsTranslator.translateAll(text, src, tgt, buildConfig()).result;
}
/* ---------- 方向切换 ---------- */
var dir = "han-mars";
var srcBox = $("#srcBox"), dstBox = $("#dstBox");
var srcLabel = $("#srcLabel"), dstLabel = $("#dstLabel");
var dirTag = $("#dirTag");
function setDir(d) {
dir = d;
var han = d === "han-mars";
$$('#view-translate .segmented [data-dir]').forEach(function (b) {
var on = b.getAttribute("data-dir") === d;
b.classList.toggle("active", on);
b.setAttribute("aria-selected", on ? "true" : "false");
});
srcLabel.textContent = han ? "源文本(中文)" : "源文本(火星文)";
dstLabel.textContent = han ? "火星文结果" : "还原结果(中文)";
dirTag.textContent = han ? "汉语 → 火星文" : "火星文 → 汉语";
srcBox.placeholder = han ? "输入中文,例如:你好,世界" : "粘贴火星文,例如:伱恏,卋鎅";
// 交换框内文本以保持连续体验(兼容 textarea 与 div 输出框)
var s = srcBox.value, t = (dstBox.value !== undefined ? dstBox.value : dstBox.textContent);
srcBox.value = t || "";
if (dstBox.value !== undefined) dstBox.value = s; else dstBox.textContent = s;
runTranslate();
}
$$('#view-translate .segmented [data-dir]').forEach(function (b) {
b.addEventListener("click", function () { setDir(b.getAttribute("data-dir")); });
});
$("#swapBtn").addEventListener("click", function () {
setDir(dir === "han-mars" ? "mars-han" : "han-mars");
});
/* ---------- 实时演示翻译 ---------- */
function runTranslate() {
var txt = srcBox.value;
$("#srcCount").textContent = txt.length;
var res = "";
if (txt.trim() !== "") {
try { res = runEngine(txt, dir); }
catch (e) { res = "(翻译出错:" + ((e && e.message) || e) + ")"; }
}
dstBox.textContent = res;
$("#dstCount").textContent = res.length;
}
srcBox.addEventListener("input", runTranslate);
$("#clearBtn").addEventListener("click", function () { srcBox.value = ""; runTranslate(); srcBox.focus(); });
/* ---------- 示例芯片 ---------- */
$$(".example-chips .chip").forEach(function (c) {
c.addEventListener("click", function () { srcBox.value = c.getAttribute("data-ex"); runTranslate(); });
});
/* ---------- 复制 / 收藏 / 分享 ---------- */
function toast(msg) {
$("#toastMsg").textContent = msg;
var t = $("#toast"); t.classList.add("show");
clearTimeout(t._tm); t._tm = setTimeout(function () { t.classList.remove("show"); }, 1800);
}
$("#copyBtn").addEventListener("click", function () {
var txt = dstBox.textContent;
if (navigator.clipboard) navigator.clipboard.writeText(txt).then(function(){ toast("已复制到剪贴板"); }, function(){ toast("已复制"); });
else toast("已复制");
});
var favOn = false;
var favBtn = $("#favBtn");
favBtn.addEventListener("click", function () {
favOn = !favOn;
favBtn.classList.toggle("primary", favOn);
favBtn.setAttribute("aria-pressed", favOn ? "true" : "false");
favBtn.querySelector("svg").setAttribute("fill", favOn ? "currentColor" : "none");
toast(favOn ? "已加入收藏" : "已取消收藏");
});
/* ---------- 风格 / 强度 / 规则 接线到真实引擎配置 ---------- */
var ruleBoxes = $$("#ruleToggles input[type=checkbox]");
function syncRuleUI() {
MarsTranslator.RULE_FAMILIES.forEach(function (fam, i) {
if (ruleBoxes[i]) ruleBoxes[i].checked = !!state.families[fam];
});
}
function syncIntensityUI() {
$$("#intensitySeg button").forEach(function (b) {
b.classList.toggle("active", b.getAttribute("data-int") === state.strength);
});
}
$$("#intensitySeg button").forEach(function (b) {
b.addEventListener("click", function () {
state.strength = b.getAttribute("data-int");
$$("#intensitySeg button").forEach(function (x){ x.classList.remove("active"); });
b.classList.add("active");
runTranslate();
});
});
$$("#styleChips .chip").forEach(function (c) {
c.addEventListener("click", function () {
$$("#styleChips .chip").forEach(function (x){ x.classList.remove("active"); });
c.classList.add("active");
var tpl = MarsTranslator.STYLE_TEMPLATES[c.getAttribute("data-style")];
if (tpl) {
if (tpl.families) state.families = Object.assign({}, MarsTranslator.DEFAULT_CONFIG.families, tpl.families);
if (tpl.strength) state.strength = tpl.strength;
if (tpl.traditional !== undefined) state.traditional = tpl.traditional;
syncRuleUI(); syncIntensityUI();
}
runTranslate();
});
});
ruleBoxes.forEach(function (cb, i) {
cb.addEventListener("change", function () {
var fam = MarsTranslator.RULE_FAMILIES[i];
if (fam) { state.families[fam] = cb.checked; runTranslate(); }
});
});
var wlInput = $("#wlInput");
if (wlInput) wlInput.addEventListener("input", function () {
state.whitelist = wlInput.value.split("").filter(Boolean);
runTranslate();
});
syncRuleUI(); syncIntensityUI();
/* ---------- 列表数据(演示) ---------- */
var HIST = [
{ dir: "汉 → 火", src: "你好,世界!", res: "伱恏,卋鎅!", fav: false },
{ dir: "火 → 汉", src: "莪嬡沵", res: "我爱你", fav: true },
{ dir: "汉 → 火", src: "今晚的月色真美", res: "唫渘の仴脃湞媄", fav: false },
{ dir: "汉 → 火", src: "生活明朗,万物可爱", res: "泩萿朖眀,萬粅妸嬡", fav: false },
{ dir: "火 → 汉", src: "囻慶ㄖ", res: "国庆日", fav: false },
{ dir: "汉 → 火", src: "一起去看火星", res: "①起厾看吙煋", fav: true }
];
function recHTML(item, idx, favView) {
return '<div class="rec">' +
'<div class="rec-meta"><span class="tag brand">' + item.dir + '</span><span class="rec-src">' + item.src + '</span></div>' +
'<div class="rec-res">' + item.res + '</div>' +
'<div class="rec-foot"><span class="spacer"></span>' +
'<button class="mini-btn" data-reuse="' + idx + '" title="重新翻译"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 3-6.7L3 8"/><path d="M3 4v4h4"/></svg></button>' +
'<button class="mini-btn ' + (item.fav ? "on" : "") + '" data-fav="' + idx + '" title="收藏"><svg viewBox="0 0 24 24" fill="' + (item.fav ? "currentColor" : "none") + '" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 17.3l-5.4 3.2 1.4-6.2L3 9.9l6.3-.5L12 3.6l2.7 5.8 6.3.5-4.9 4.4 1.4 6.2z"/></svg></button>' +
'</div></div>';
}
function renderHistory() {
var el = $("#historyList");
el.innerHTML = HIST.map(function (h, i) { return recHTML(h, i); }).join("");
bindList(el);
}
function renderFavs() {
var el = $("#favList");
var f = HIST.filter(function (h) { return h.fav; });
el.innerHTML = f.length ? f.map(function (h, i) { return recHTML(h, HIST.indexOf(h)); }).join("")
: '<div class="empty-state"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M12 17.3l-5.4 3.2 1.4-6.2L3 9.9l6.3-.5L12 3.6l2.7 5.8 6.3.5-4.9 4.4 1.4 6.2z"/></svg><div>还没有收藏,去翻译页点亮星标吧 ✦</div></div>';
bindList(el);
}
function bindList(el) {
$$("[data-reuse]", el).forEach(function (b) {
b.addEventListener("click", function () {
var h = HIST[+b.getAttribute("data-reuse")];
srcBox.value = h.src; runTranslate();
$$(".nav-item").forEach(function (x) { x.classList.remove("active"); });
$('.nav-item[data-nav="translate"]').classList.add("active");
$$(".view").forEach(function (v) { v.classList.remove("active"); });
$("#view-translate").classList.add("active");
$("#pageTitle").textContent = titles.translate[0];
$("#pageCrumb").textContent = titles.translate[1];
window.scrollTo({ top: 0, behavior: "smooth" });
});
});
$$("[data-fav]", el).forEach(function (b) {
b.addEventListener("click", function () {
var i = +b.getAttribute("data-fav"); HIST[i].fav = !HIST[i].fav;
b.classList.toggle("on", HIST[i].fav);
b.querySelector("svg").setAttribute("fill", HIST[i].fav ? "currentColor" : "none");
if ($("#view-favorites").classList.contains("active")) renderFavs();
});
});
}
/* ---------- 分享卡(Canvas 生成,对应 R07) ---------- */
var shareModal = $("#shareModal");
function drawShareCard() {
var cv = $("#shareCanvas"), ctx = cv.getContext("2d");
var W = cv.width, H = cv.height;
var dark = html.getAttribute("data-theme") === "dark";
var g = ctx.createLinearGradient(0, 0, W, H);
g.addColorStop(0, "#FF3E7F"); g.addColorStop(1, "#7C5CFF");
ctx.fillStyle = g; ctx.fillRect(0, 0, W, H);
ctx.fillStyle = "rgba(255,255,255,.08)";
ctx.beginPath(); ctx.arc(W * .82, H * .12, 220, 0, 7); ctx.fill();
ctx.fillStyle = "#fff";
ctx.font = "700 34px 'PingFang SC', sans-serif";
ctx.fillText("火星文翻译器", 56, 110);
ctx.font = "500 22px 'PingFang SC', sans-serif";
ctx.fillStyle = "rgba(255,255,255,.85)";
ctx.fillText("MARS · 纯前端确定性翻译", 56, 150);
ctx.fillStyle = "rgba(255,255,255,.7)";
ctx.font = "500 20px 'PingFang SC', sans-serif";
var lbl = dir === "han-mars" ? "原文" : "火星文";
var lbl2 = dir === "han-mars" ? "火星文" : "还原";
ctx.fillText(lbl, 56, 250);
ctx.fillStyle = "#fff"; ctx.font = "600 30px 'PingFang SC', sans-serif";
wrap(ctx, srcBox.value || "(空)", 56, 300, W - 112, 44);
ctx.fillStyle = "rgba(255,255,255,.7)"; ctx.font = "500 20px 'PingFang SC', sans-serif";
ctx.fillText(lbl2, 56, 560);
ctx.fillStyle = "#fff"; ctx.font = "700 40px 'PingFang SC', sans-serif";
wrap(ctx, dstBox.textContent || "(空)", 56, 610, W - 112, 56);
ctx.fillStyle = "rgba(255,255,255,.6)"; ctx.font = "500 18px 'PingFang SC', sans-serif";
ctx.fillText("扫码体验 · 确定性可复现 · 零联网", 56, H - 50);
}
function wrap(ctx, text, x, y, maxW, lh) {
var line = "", yy = y;
for (var i = 0; i < text.length; i++) {
var test = line + text[i];
if (ctx.measureText(test).width > maxW && line) { ctx.fillText(line, x, yy); line = text[i]; yy += lh; }
else line = test;
}
if (line) ctx.fillText(line, x, yy);
}
$("#shareBtn").addEventListener("click", function () { drawShareCard(); shareModal.classList.add("show"); });
$("#closeShare").addEventListener("click", function () { shareModal.classList.remove("show"); });
$("#closeShare2").addEventListener("click", function () { shareModal.classList.remove("show"); });
shareModal.addEventListener("click", function (e) { if (e.target === shareModal) shareModal.classList.remove("show"); });
$("#dlShare").addEventListener("click", function () {
var a = document.createElement("a");
a.download = "mars-share.png"; a.href = $("#shareCanvas").toDataURL("image/png"); a.click();
toast("分享卡已下载");
});
/* ---------- 使用指南(占位提示) ---------- */
$("#helpBtn").addEventListener("click", function () { toast("选择方向 → 输入 → 实时预览 → 复制/分享/收藏"); });
/* 初始化 */
runTranslate();
})();
</script>
</body>
</html>