dsh-bilingual-reader 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +40 -10
- package/README.md +41 -10
- package/docs/architecture.md +5 -4
- package/docs/demo.jpg +0 -0
- package/docs/release-v0.1.0.md +47 -0
- package/docs/release-v0.1.1.md +31 -0
- package/docs/release-v0.2.0.md +41 -0
- package/package.json +2 -2
- package/src/config.js +1 -0
- package/src/glossary.js +33 -0
- package/src/quality.js +30 -0
- package/src/routes.js +96 -14
- package/src/store.js +30 -2
- package/src/translator.js +57 -22
- package/src/util.js +2 -2
- package/web/app.js +425 -22
- package/web/index.html +27 -8
- package/web/style.css +125 -4
package/web/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
6
|
<title>双语阅读 · DSH</title>
|
|
7
7
|
<link rel="icon" href="./favicon.svg" type="image/svg+xml">
|
|
8
|
-
<link rel="stylesheet" href="./style.css">
|
|
8
|
+
<link rel="stylesheet" href="./style.css?v=0.2.0">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<div id="app">
|
|
@@ -18,13 +18,23 @@
|
|
|
18
18
|
</div>
|
|
19
19
|
</div>
|
|
20
20
|
<div class="top-actions">
|
|
21
|
+
<div class="font-control" role="group" aria-label="阅读字号">
|
|
22
|
+
<button type="button" id="font-smaller" class="icon-button" aria-label="减小字号" title="减小字号">A−</button>
|
|
23
|
+
<button type="button" id="font-reset" class="icon-button" aria-label="恢复默认字号" title="恢复默认字号">A</button>
|
|
24
|
+
<button type="button" id="font-larger" class="icon-button" aria-label="增大字号" title="增大字号">A+</button>
|
|
25
|
+
</div>
|
|
21
26
|
<button type="button" id="glossary-btn" class="button ghost">术语表 <span id="glossary-count">0</span></button>
|
|
22
27
|
</div>
|
|
23
28
|
</header>
|
|
24
29
|
|
|
25
30
|
<section class="composer">
|
|
31
|
+
<div class="composer-modes" role="group" aria-label="输入方式">
|
|
32
|
+
<button type="button" data-compose-mode="url" class="active" aria-pressed="true">网页链接</button>
|
|
33
|
+
<button type="button" data-compose-mode="text" aria-pressed="false">粘贴文本</button>
|
|
34
|
+
</div>
|
|
26
35
|
<form id="read-form" autocomplete="off">
|
|
27
36
|
<input id="url-input" type="url" placeholder="粘贴网页链接,例如 https://example.com/article" required>
|
|
37
|
+
<textarea id="text-input" rows="4" placeholder="粘贴 Markdown 或纯文本,最多 20000 字符" required hidden></textarea>
|
|
28
38
|
<select id="lang-select" aria-label="目标语言"></select>
|
|
29
39
|
<button type="submit" id="read-btn" class="button primary">读取并翻译</button>
|
|
30
40
|
</form>
|
|
@@ -36,7 +46,7 @@
|
|
|
36
46
|
<aside class="sidebar" aria-label="最近文档">
|
|
37
47
|
<div class="sidebar-head">
|
|
38
48
|
<h2>最近</h2>
|
|
39
|
-
<button type="button" id="refresh-docs" class="icon-button" title="刷新">↻</button>
|
|
49
|
+
<button type="button" id="refresh-docs" class="icon-button" title="刷新" aria-label="刷新最近文档">↻</button>
|
|
40
50
|
</div>
|
|
41
51
|
<div id="docs" class="docs"></div>
|
|
42
52
|
</aside>
|
|
@@ -45,9 +55,9 @@
|
|
|
45
55
|
<div id="empty" class="empty-state">
|
|
46
56
|
<div class="empty-mark" aria-hidden="true">译</div>
|
|
47
57
|
<h2>把网页读成双语</h2>
|
|
48
|
-
<p
|
|
58
|
+
<p>粘贴一个公开文章链接或一段正文,也可以让 Agent 调用 <code>bilingual_read_url</code>。代码、公式、链接和表格保持原样,只翻译正文。</p>
|
|
49
59
|
<ul>
|
|
50
|
-
<li
|
|
60
|
+
<li>上下 / 对照 / 原文 / 译文四种视图</li>
|
|
51
61
|
<li>术语表 + 内容哈希缓存,重复段落不再调用模型</li>
|
|
52
62
|
<li>导出双语 Markdown,保留标题层级与代码块</li>
|
|
53
63
|
</ul>
|
|
@@ -61,18 +71,22 @@
|
|
|
61
71
|
</div>
|
|
62
72
|
<div class="doc-actions">
|
|
63
73
|
<div class="view-switch" role="group" aria-label="视图">
|
|
64
|
-
<button type="button" data-view="
|
|
74
|
+
<button type="button" data-view="inline" class="active">上下</button>
|
|
75
|
+
<button type="button" data-view="bilingual">对照</button>
|
|
65
76
|
<button type="button" data-view="original">原文</button>
|
|
66
77
|
<button type="button" data-view="translation">译文</button>
|
|
67
78
|
</div>
|
|
79
|
+
<button type="button" id="print-btn" class="button">打印</button>
|
|
80
|
+
<button type="button" id="copy-btn" class="button" title="复制全部译文(Markdown)">复制译文</button>
|
|
68
81
|
<a id="export-link" class="button" href="#" download>导出双语 Markdown</a>
|
|
82
|
+
<a id="inbox-link" class="button" href="#" target="_blank" rel="noopener" hidden>存入阅读箱</a>
|
|
69
83
|
<button type="button" id="retry-btn" class="button" hidden>重试失败段</button>
|
|
70
84
|
<button type="button" id="delete-btn" class="button danger">删除</button>
|
|
71
85
|
</div>
|
|
72
86
|
</div>
|
|
73
|
-
<div class="progress" aria-
|
|
87
|
+
<div class="progress" id="progress-wrap" role="progressbar" aria-label="翻译进度" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div id="progress-bar"></div></div>
|
|
74
88
|
<p class="doc-status" id="doc-status"></p>
|
|
75
|
-
<article id="blocks" class="blocks view-
|
|
89
|
+
<article id="blocks" class="blocks view-inline"></article>
|
|
76
90
|
</div>
|
|
77
91
|
</section>
|
|
78
92
|
</main>
|
|
@@ -83,6 +97,11 @@
|
|
|
83
97
|
<button type="button" id="glossary-close" class="icon-button" aria-label="关闭">×</button>
|
|
84
98
|
</div>
|
|
85
99
|
<p class="dialog-hint">翻译时会强制使用这些译法。示例:token → 令牌。</p>
|
|
100
|
+
<div class="glossary-tools">
|
|
101
|
+
<a id="glossary-export" class="button small" href="#" download="dsh-bilingual-glossary.json">导出 JSON</a>
|
|
102
|
+
<button type="button" id="glossary-import" class="button small">导入 JSON</button>
|
|
103
|
+
<input type="file" id="glossary-file" accept="application/json,.json" hidden>
|
|
104
|
+
</div>
|
|
86
105
|
<div id="glossary-list" class="glossary-list"></div>
|
|
87
106
|
<form id="glossary-form" class="glossary-form" autocomplete="off">
|
|
88
107
|
<input id="term-source" type="text" placeholder="原文术语" required maxlength="80">
|
|
@@ -93,6 +112,6 @@
|
|
|
93
112
|
<p class="notice" id="glossary-notice" role="status" hidden></p>
|
|
94
113
|
</dialog>
|
|
95
114
|
</div>
|
|
96
|
-
<script src="./app.js"></script>
|
|
115
|
+
<script src="./app.js?v=0.2.0"></script>
|
|
97
116
|
</body>
|
|
98
117
|
</html>
|
package/web/style.css
CHANGED
|
@@ -101,22 +101,69 @@ code, pre {
|
|
|
101
101
|
|
|
102
102
|
.top-actions { display: flex; align-items: center; gap: 8px; }
|
|
103
103
|
|
|
104
|
+
.font-control {
|
|
105
|
+
display: inline-flex;
|
|
106
|
+
align-items: center;
|
|
107
|
+
gap: 1px;
|
|
108
|
+
padding: 1px;
|
|
109
|
+
border: 1px solid var(--border);
|
|
110
|
+
border-radius: 9px;
|
|
111
|
+
background: var(--bg);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.font-control .icon-button {
|
|
115
|
+
width: 30px;
|
|
116
|
+
height: 26px;
|
|
117
|
+
border-radius: 7px;
|
|
118
|
+
font-size: 12px;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.font-control .icon-button:disabled { opacity: 0.4; cursor: default; }
|
|
122
|
+
|
|
104
123
|
.composer {
|
|
105
124
|
padding: 14px 22px 10px;
|
|
106
125
|
background: var(--panel);
|
|
107
126
|
border-bottom: 1px solid var(--border);
|
|
108
127
|
}
|
|
109
128
|
|
|
129
|
+
.composer-modes {
|
|
130
|
+
display: flex;
|
|
131
|
+
gap: 2px;
|
|
132
|
+
max-width: 1200px;
|
|
133
|
+
margin: 0 auto 8px;
|
|
134
|
+
width: fit-content;
|
|
135
|
+
padding: 2px;
|
|
136
|
+
border: 1px solid var(--border);
|
|
137
|
+
border-radius: 9px;
|
|
138
|
+
background: var(--bg);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.composer-modes button {
|
|
142
|
+
border: 0;
|
|
143
|
+
background: transparent;
|
|
144
|
+
padding: 4px 10px;
|
|
145
|
+
border-radius: 7px;
|
|
146
|
+
font-size: 12px;
|
|
147
|
+
color: var(--muted);
|
|
148
|
+
cursor: pointer;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.composer-modes button.active {
|
|
152
|
+
background: var(--accent-soft);
|
|
153
|
+
color: var(--accent);
|
|
154
|
+
font-weight: 600;
|
|
155
|
+
}
|
|
156
|
+
|
|
110
157
|
.composer form {
|
|
111
158
|
display: flex;
|
|
159
|
+
flex-wrap: wrap;
|
|
112
160
|
gap: 10px;
|
|
113
161
|
max-width: 1200px;
|
|
114
162
|
margin: 0 auto;
|
|
115
163
|
}
|
|
116
164
|
|
|
117
|
-
#url-input
|
|
118
|
-
|
|
119
|
-
min-width: 0;
|
|
165
|
+
#url-input,
|
|
166
|
+
#text-input {
|
|
120
167
|
padding: 10px 14px;
|
|
121
168
|
border: 1px solid var(--border);
|
|
122
169
|
border-radius: 10px;
|
|
@@ -124,7 +171,19 @@ code, pre {
|
|
|
124
171
|
outline: none;
|
|
125
172
|
}
|
|
126
173
|
|
|
127
|
-
#url-input
|
|
174
|
+
#url-input {
|
|
175
|
+
flex: 1;
|
|
176
|
+
min-width: 0;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
#text-input {
|
|
180
|
+
flex: 1 1 100%;
|
|
181
|
+
min-height: 96px;
|
|
182
|
+
resize: vertical;
|
|
183
|
+
font: inherit;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
#url-input:focus, #text-input:focus, select:focus, input:focus {
|
|
128
187
|
border-color: var(--accent);
|
|
129
188
|
box-shadow: 0 0 0 3px var(--accent-soft);
|
|
130
189
|
}
|
|
@@ -390,6 +449,23 @@ select {
|
|
|
390
449
|
}
|
|
391
450
|
.badge.warn { background: rgba(162, 105, 27, 0.14); color: var(--warn); }
|
|
392
451
|
|
|
452
|
+
.badge-action {
|
|
453
|
+
margin-left: 6px;
|
|
454
|
+
padding: 1px 7px;
|
|
455
|
+
border: 1px solid var(--border);
|
|
456
|
+
border-radius: 99px;
|
|
457
|
+
background: var(--panel);
|
|
458
|
+
color: var(--muted);
|
|
459
|
+
font-size: 11px;
|
|
460
|
+
line-height: 1.5;
|
|
461
|
+
cursor: pointer;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
.badge-action:hover {
|
|
465
|
+
border-color: var(--accent);
|
|
466
|
+
color: var(--accent);
|
|
467
|
+
}
|
|
468
|
+
|
|
393
469
|
.blocks.view-original .block,
|
|
394
470
|
.blocks.view-translation .block {
|
|
395
471
|
grid-template-columns: minmax(0, 1fr);
|
|
@@ -398,6 +474,19 @@ select {
|
|
|
398
474
|
.blocks.view-translation .orig { display: none; }
|
|
399
475
|
.blocks.view-translation .trans { padding-left: 0; border-left: 0; }
|
|
400
476
|
|
|
477
|
+
/* Default reading mode: the translation sits directly under each paragraph. */
|
|
478
|
+
.blocks.view-inline .block {
|
|
479
|
+
display: block;
|
|
480
|
+
padding: 18px 0;
|
|
481
|
+
}
|
|
482
|
+
.blocks.view-inline .trans {
|
|
483
|
+
margin-top: 10px;
|
|
484
|
+
padding: 10px 14px;
|
|
485
|
+
border-left: 3px solid var(--accent);
|
|
486
|
+
border-radius: 0 10px 10px 0;
|
|
487
|
+
background: var(--accent-soft);
|
|
488
|
+
}
|
|
489
|
+
|
|
401
490
|
.dialog {
|
|
402
491
|
width: min(560px, calc(100vw - 40px));
|
|
403
492
|
border: 1px solid var(--border);
|
|
@@ -413,6 +502,12 @@ select {
|
|
|
413
502
|
.dialog-head h2 { margin: 0; font-size: 18px; }
|
|
414
503
|
.dialog-hint { color: var(--muted); font-size: 12px; margin: 6px 0 12px; }
|
|
415
504
|
|
|
505
|
+
.glossary-tools {
|
|
506
|
+
display: flex;
|
|
507
|
+
gap: 8px;
|
|
508
|
+
margin-bottom: 10px;
|
|
509
|
+
}
|
|
510
|
+
|
|
416
511
|
.glossary-list {
|
|
417
512
|
max-height: 300px;
|
|
418
513
|
overflow-y: auto;
|
|
@@ -455,6 +550,32 @@ select {
|
|
|
455
550
|
.glossary-form input#term-note { grid-column: 1 / -1; }
|
|
456
551
|
.glossary-form .button { grid-column: 1 / -1; justify-self: start; }
|
|
457
552
|
|
|
553
|
+
@media print {
|
|
554
|
+
:root { color-scheme: light; }
|
|
555
|
+
body { background: #fff; color: #000; }
|
|
556
|
+
.topbar, .composer, .sidebar, .doc-actions, .progress, .doc-status, .badge-action {
|
|
557
|
+
display: none !important;
|
|
558
|
+
}
|
|
559
|
+
.layout { display: block; }
|
|
560
|
+
.reader { padding: 0; overflow: visible; }
|
|
561
|
+
.doc-view { max-width: none; }
|
|
562
|
+
.block {
|
|
563
|
+
display: block;
|
|
564
|
+
break-inside: avoid;
|
|
565
|
+
page-break-inside: avoid;
|
|
566
|
+
border-bottom: 1px solid #ddd;
|
|
567
|
+
padding: 10px 0;
|
|
568
|
+
}
|
|
569
|
+
.trans {
|
|
570
|
+
margin-top: 6px;
|
|
571
|
+
padding: 6px 10px;
|
|
572
|
+
border-left: 2px solid #999;
|
|
573
|
+
background: #f5f5f5;
|
|
574
|
+
}
|
|
575
|
+
.blocks.view-original .trans, .blocks.view-translation .orig { display: none; }
|
|
576
|
+
a { color: #000; text-decoration: none; }
|
|
577
|
+
}
|
|
578
|
+
|
|
458
579
|
@media (max-width: 860px) {
|
|
459
580
|
.topbar { padding: 12px 14px; }
|
|
460
581
|
.composer { padding: 12px 14px 8px; }
|