dsh-quick-translate 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +81 -2
- package/client.js +2657 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +17 -0
- package/index.js +361 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +52 -4
package/client.js
ADDED
|
@@ -0,0 +1,2657 @@
|
|
|
1
|
+
// 快速翻译 · 浏览器半边(界面风格:E 纸本)
|
|
2
|
+
// - 侧栏加一个「快速翻译」入口,主区域是一张桌面:原文写在方格本上,译文印在叠在上面的硫酸纸上
|
|
3
|
+
// - 模型选择在硫酸纸底部(点开是一张索引卡),列的是 DSH「设置 › 模型」里配好的 provider + 模型,默认跟随 DSH 默认模型
|
|
4
|
+
// - 翻译走 Host 的 SSE 接口,边生成边显示;⌘/Ctrl+Enter 翻译,Esc 取消
|
|
5
|
+
// - 接缝上的牛皮纸「互换」签是真正的互换:原文和译文对调、方向翻转,再点一次就换回来
|
|
6
|
+
// - 每次完成的翻译自动进历史(热敏小票),点击任意一条即可回看;历史和偏好都存在 localStorage
|
|
7
|
+
// - 桌面跟随 DSH 明暗主题;纸张、墨色、印章是"作品",颜色固定(见 AGENTS.md §3.4);文案走 DSH 的 locale 服务
|
|
8
|
+
window.__ModuleLoader__.load({
|
|
9
|
+
id: 'dsh-quick-translate',
|
|
10
|
+
factory(require) {
|
|
11
|
+
const React = require('react')
|
|
12
|
+
const h = React.createElement
|
|
13
|
+
const { useState, useEffect, useRef, useCallback, useMemo } = React
|
|
14
|
+
|
|
15
|
+
const PANEL = 'quick-translate'
|
|
16
|
+
const API = '/quick-translate/api'
|
|
17
|
+
const PREFS_KEY = 'dsh-quick-translate:prefs'
|
|
18
|
+
const DRAFT_KEY = 'dsh-quick-translate:draft'
|
|
19
|
+
const HISTORY_KEY = 'dsh-quick-translate:history'
|
|
20
|
+
const SEP = '\u001f'
|
|
21
|
+
const HISTORY_MAX = 100
|
|
22
|
+
const HISTORY_MAX_CHARS = 600_000
|
|
23
|
+
const EMPTY_LIST = []
|
|
24
|
+
const AUTHOR = 'Erek'
|
|
25
|
+
const COMP_W = 1200 // 画板 E 的桌面尺寸(去掉标题行)
|
|
26
|
+
const COMP_H = 690
|
|
27
|
+
const FIELD_W = 1200 // 画板 F 色场的工作区(1200×760 去掉 64px 头部)
|
|
28
|
+
const FIELD_H = 696
|
|
29
|
+
const FIELD_MAX_ZOOM = 1.3 // 简洁风格放太大会显得臃肿(作者 2026-11-24 同意)
|
|
30
|
+
|
|
31
|
+
/* ============================== 文案 ================================ */
|
|
32
|
+
|
|
33
|
+
const STR = {
|
|
34
|
+
zh: {
|
|
35
|
+
title: '快速翻译',
|
|
36
|
+
subtitle: '英译中 / 中译英,用 DSH 里已配置的模型',
|
|
37
|
+
en2zh: '英 → 中',
|
|
38
|
+
zh2en: '中 → 英',
|
|
39
|
+
auto: '自动',
|
|
40
|
+
model: '模型',
|
|
41
|
+
direction: '方向',
|
|
42
|
+
followDefault: '跟随 DSH 默认',
|
|
43
|
+
refresh: '刷新模型',
|
|
44
|
+
refreshing: '刷新中…',
|
|
45
|
+
source: '原文',
|
|
46
|
+
result: '译文',
|
|
47
|
+
langZh: '中文',
|
|
48
|
+
langEn: '英文',
|
|
49
|
+
sourcePlaceholder: '粘贴或输入要翻译的内容…',
|
|
50
|
+
resultPlaceholder: '译文会显示在这里',
|
|
51
|
+
translate: '翻译',
|
|
52
|
+
translating: '翻译中…',
|
|
53
|
+
cancel: '取消',
|
|
54
|
+
clear: '清空',
|
|
55
|
+
clearTitle: '清空原文和译文',
|
|
56
|
+
copy: '复制',
|
|
57
|
+
copied: '已复制',
|
|
58
|
+
copyFailed: '复制失败',
|
|
59
|
+
copyFailedHint: '剪贴板被拒绝,已选中译文,请按 {key}+C 手动复制',
|
|
60
|
+
swap: '交换原文和译文(再点一次换回来)',
|
|
61
|
+
chars: '字符',
|
|
62
|
+
seconds: '秒',
|
|
63
|
+
noModels: 'DSH 里还没有可用的文字模型。到「设置 › 模型」里添加一个,再点下面的按钮重新加载。',
|
|
64
|
+
noModelsRefresh: '重新加载模型',
|
|
65
|
+
loadingModels: '正在读取模型列表…',
|
|
66
|
+
loadModelsFailed: '模型列表读取失败',
|
|
67
|
+
retry: '重试',
|
|
68
|
+
someSkipped: (n) => `${n} 个模型服务商暂时没有响应,请稍后重试`,
|
|
69
|
+
selectModel: '选择模型',
|
|
70
|
+
autoHint: (t) => `译成${t === 'zh' ? '中文' : '英文'}`,
|
|
71
|
+
emptySource: (key) => `输入内容后按 ${key} + Enter`,
|
|
72
|
+
done: '完成',
|
|
73
|
+
truncated: '输出达到模型上限,已截断',
|
|
74
|
+
cancelledPartial: '已取消 · 仅为已收到的部分',
|
|
75
|
+
streamBroken: '连接中断,没有收到完整结果',
|
|
76
|
+
history: '历史',
|
|
77
|
+
historyEmpty: '还没有翻译记录\n完成一次翻译后会自动出现在这里',
|
|
78
|
+
historyEmptyFiltered: '没有匹配的记录',
|
|
79
|
+
historySearch: '搜索原文、译文或模型',
|
|
80
|
+
historyClear: '清空历史',
|
|
81
|
+
historyConfirm: '再点一次确认清空',
|
|
82
|
+
historyDelete: '删除这条',
|
|
83
|
+
justNow: '刚刚',
|
|
84
|
+
minutesAgo: (n) => `${n} 分钟前`,
|
|
85
|
+
hoursAgo: (n) => `${n} 小时前`,
|
|
86
|
+
yesterday: '昨天',
|
|
87
|
+
defaultShort: '默认',
|
|
88
|
+
share: '分享图片',
|
|
89
|
+
shareTitle: '分享卡片',
|
|
90
|
+
shareMaking: '正在生成图片…',
|
|
91
|
+
shareCopy: '复制图片',
|
|
92
|
+
shareCopied: '图片已复制,可以直接粘贴到聊天里',
|
|
93
|
+
shareCopyFailed: '剪贴板不接受图片,请用「保存图片」',
|
|
94
|
+
shareSave: '保存图片',
|
|
95
|
+
shareSaved: '已保存到下载文件夹',
|
|
96
|
+
shareClose: '关闭',
|
|
97
|
+
today: '今天',
|
|
98
|
+
deskTitle: 'Quick Translate',
|
|
99
|
+
receiving: '接收中',
|
|
100
|
+
standby: '待命',
|
|
101
|
+
locked: '锁定 · 翻译中',
|
|
102
|
+
swapShort: '互换',
|
|
103
|
+
stamp: '已译',
|
|
104
|
+
statSrc: '源文字符',
|
|
105
|
+
statDst: '译文字符',
|
|
106
|
+
statTime: '用时',
|
|
107
|
+
waiting: '等待翻译',
|
|
108
|
+
waitingHint: (key) => `在左边写好原文,按 ${key} ↵ 开始`,
|
|
109
|
+
modelCount: (n) => `DSH 已配置 ${n} 个`,
|
|
110
|
+
historyTotal: (n) => `共 ${n} 条`,
|
|
111
|
+
noModelsTitle: '还没有可用的模型',
|
|
112
|
+
skin: '风格',
|
|
113
|
+
skinPaper: '纸本',
|
|
114
|
+
skinField: '色场',
|
|
115
|
+
fieldAuto: '自动识别',
|
|
116
|
+
fieldAutoTo: (t) => `自动识别 · 译成${t === 'zh' ? '中文' : '英文'}`,
|
|
117
|
+
fieldLocked: '翻译中,原文已锁定',
|
|
118
|
+
fSrc: '源文',
|
|
119
|
+
fDst: '译文',
|
|
120
|
+
historyCount: (n) => `${n} 条`,
|
|
121
|
+
historyHide: '收起历史',
|
|
122
|
+
historyKeep: '最多保留 100 条 · 点一条即可回看',
|
|
123
|
+
refreshShort: '刷新',
|
|
124
|
+
},
|
|
125
|
+
en: {
|
|
126
|
+
title: 'Quick translate',
|
|
127
|
+
subtitle: 'English ↔ Chinese with the models you already added to DSH',
|
|
128
|
+
en2zh: 'EN → ZH',
|
|
129
|
+
zh2en: 'ZH → EN',
|
|
130
|
+
auto: 'Auto',
|
|
131
|
+
model: 'Model',
|
|
132
|
+
direction: 'Direction',
|
|
133
|
+
followDefault: 'Use DSH default',
|
|
134
|
+
refresh: 'Refresh models',
|
|
135
|
+
refreshing: 'Refreshing…',
|
|
136
|
+
source: 'Source',
|
|
137
|
+
result: 'Translation',
|
|
138
|
+
langZh: 'Chinese',
|
|
139
|
+
langEn: 'English',
|
|
140
|
+
sourcePlaceholder: 'Paste or type the text to translate…',
|
|
141
|
+
resultPlaceholder: 'The translation appears here',
|
|
142
|
+
translate: 'Translate',
|
|
143
|
+
translating: 'Translating…',
|
|
144
|
+
cancel: 'Cancel',
|
|
145
|
+
clear: 'Clear',
|
|
146
|
+
clearTitle: 'Clear source and translation',
|
|
147
|
+
copy: 'Copy',
|
|
148
|
+
copied: 'Copied',
|
|
149
|
+
copyFailed: 'Copy failed',
|
|
150
|
+
copyFailedHint: 'Clipboard blocked; text selected, press {key}+C to copy manually',
|
|
151
|
+
swap: 'Swap source and translation (click again to swap back)',
|
|
152
|
+
chars: 'chars',
|
|
153
|
+
seconds: 's',
|
|
154
|
+
noModels: 'No text model is available yet. Add one under Settings › Models, then reload below.',
|
|
155
|
+
noModelsRefresh: 'Reload models',
|
|
156
|
+
loadingModels: 'Loading models…',
|
|
157
|
+
loadModelsFailed: 'Failed to load models',
|
|
158
|
+
retry: 'Retry',
|
|
159
|
+
someSkipped: (n) => `${n} provider(s) did not respond; try again shortly`,
|
|
160
|
+
selectModel: 'Select a model',
|
|
161
|
+
autoHint: (t) => `to ${t === 'zh' ? 'Chinese' : 'English'}`,
|
|
162
|
+
emptySource: (key) => `Type, then press ${key} + Enter`,
|
|
163
|
+
done: 'Done',
|
|
164
|
+
truncated: 'Hit the model output limit; result may be cut off',
|
|
165
|
+
cancelledPartial: 'Cancelled · partial result only',
|
|
166
|
+
streamBroken: 'The connection closed before the translation finished',
|
|
167
|
+
history: 'History',
|
|
168
|
+
historyEmpty: 'No translations yet\nFinished translations appear here automatically',
|
|
169
|
+
historyEmptyFiltered: 'No matching entries',
|
|
170
|
+
historySearch: 'Search source, translation or model',
|
|
171
|
+
historyClear: 'Clear history',
|
|
172
|
+
historyConfirm: 'Click again to confirm',
|
|
173
|
+
historyDelete: 'Delete this entry',
|
|
174
|
+
justNow: 'just now',
|
|
175
|
+
minutesAgo: (n) => `${n} min ago`,
|
|
176
|
+
hoursAgo: (n) => `${n} h ago`,
|
|
177
|
+
yesterday: 'yesterday',
|
|
178
|
+
defaultShort: 'default',
|
|
179
|
+
share: 'Share image',
|
|
180
|
+
shareTitle: 'Share card',
|
|
181
|
+
shareMaking: 'Rendering image…',
|
|
182
|
+
shareCopy: 'Copy image',
|
|
183
|
+
shareCopied: 'Image copied — paste it into any chat',
|
|
184
|
+
shareCopyFailed: 'Clipboard refused the image; use Save image',
|
|
185
|
+
shareSave: 'Save image',
|
|
186
|
+
shareSaved: 'Saved to your Downloads folder',
|
|
187
|
+
shareClose: 'Close',
|
|
188
|
+
today: 'Today',
|
|
189
|
+
deskTitle: 'Quick Translate',
|
|
190
|
+
receiving: 'Receiving',
|
|
191
|
+
standby: 'Standby',
|
|
192
|
+
locked: 'Locked while translating',
|
|
193
|
+
swapShort: 'Swap',
|
|
194
|
+
stamp: 'DONE',
|
|
195
|
+
statSrc: 'Source chars',
|
|
196
|
+
statDst: 'Output chars',
|
|
197
|
+
statTime: 'Time',
|
|
198
|
+
waiting: 'Waiting',
|
|
199
|
+
waitingHint: (key) => `Write on the left, then press ${key} ↵`,
|
|
200
|
+
modelCount: (n) => `${n} in DSH`,
|
|
201
|
+
historyTotal: (n) => `${n} total`,
|
|
202
|
+
noModelsTitle: 'No model yet',
|
|
203
|
+
skin: 'Style',
|
|
204
|
+
skinPaper: 'Paper',
|
|
205
|
+
skinField: 'Field',
|
|
206
|
+
fieldAuto: 'Auto-detect',
|
|
207
|
+
fieldAutoTo: (t) => `Auto-detect · to ${t === 'zh' ? 'Chinese' : 'English'}`,
|
|
208
|
+
fieldLocked: 'Translating · source locked',
|
|
209
|
+
fSrc: 'Source',
|
|
210
|
+
fDst: 'Output',
|
|
211
|
+
historyCount: (n) => `${n}`,
|
|
212
|
+
historyHide: 'Hide history',
|
|
213
|
+
historyKeep: 'Keeps the latest 100 · click one to reopen',
|
|
214
|
+
refreshShort: 'Refresh',
|
|
215
|
+
},
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const isMac = /mac|iphone|ipad/i.test(navigator.platform || navigator.userAgent || '')
|
|
219
|
+
const modKey = isMac ? '⌘' : 'Ctrl'
|
|
220
|
+
|
|
221
|
+
const langStore = {
|
|
222
|
+
lang: detectLang(),
|
|
223
|
+
listeners: new Set(),
|
|
224
|
+
get() {
|
|
225
|
+
return this.lang
|
|
226
|
+
},
|
|
227
|
+
set(next) {
|
|
228
|
+
if (!next || next === this.lang) return
|
|
229
|
+
this.lang = next
|
|
230
|
+
this.listeners.forEach((fn) => fn())
|
|
231
|
+
},
|
|
232
|
+
subscribe(fn) {
|
|
233
|
+
this.listeners.add(fn)
|
|
234
|
+
return () => this.listeners.delete(fn)
|
|
235
|
+
},
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function detectLang() {
|
|
239
|
+
const id = String(navigator.language || 'en').toLowerCase()
|
|
240
|
+
return id.startsWith('zh') ? 'zh' : 'en'
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function useLang() {
|
|
244
|
+
const [lang, setLang] = useState(langStore.get())
|
|
245
|
+
useEffect(() => langStore.subscribe(() => setLang(langStore.get())), [])
|
|
246
|
+
return lang
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/* ============================== 样式 ================================ */
|
|
250
|
+
|
|
251
|
+
// 全部走 --dsw-alias-* token;字号从 --dsh-content-font-size 派生,用户在 DSH 里调大正文时整页跟着变。
|
|
252
|
+
const CSS = `
|
|
253
|
+
/* ============ 纸本(E):按 Design 画板 E 的尺寸和坐标原样搭一张 1200×690 的桌面,再整体缩放到面板大小 ============ */
|
|
254
|
+
.qt-root{
|
|
255
|
+
--qt-fs:var(--dsh-content-font-size,14px);
|
|
256
|
+
--qt-mono:"IBM Plex Mono",var(--dsh-font-family-code,ui-monospace),"SF Mono",Menlo,monospace;
|
|
257
|
+
--qt-grot:"Inter Tight","Helvetica Neue",Helvetica,Arial,sans-serif;
|
|
258
|
+
--qt-zh-serif:"Songti SC","Noto Serif SC","Source Han Serif SC","STSong",serif;
|
|
259
|
+
--qt-zh-sans:"PingFang SC","Noto Sans SC","Microsoft YaHei",sans-serif;
|
|
260
|
+
--qt-en-serif:"Iowan Old Style","Newsreader","Palatino",Georgia,serif;
|
|
261
|
+
--qt-desk:#1d1d1d;--qt-desk-ink:#e6e3dc;--qt-desk-faint:#3d3d3d;
|
|
262
|
+
--qt-paper:#eeede7;--qt-grid:#c6d0d8;--qt-ink:#1b1b1b;--qt-ink-2:#34363d;--qt-ink-3:#77787e;
|
|
263
|
+
--qt-indigo:#41468a;--qt-stamp:#3a3fa6;--qt-red:#ef4a23;--qt-redpen:#c8361a;--qt-kraft:#b88f62;--qt-receipt:#f5f5f2;--qt-masking:rgba(232,220,186,.92);
|
|
264
|
+
--qt-grain:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .28 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
|
|
265
|
+
--qt-grain-light:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .09 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
|
|
266
|
+
--qt-tape-clip:polygon(0 8%,3% 0,7% 10%,11% 2%,100% 0,97% 92%,100% 100%,0 100%,2% 50%);
|
|
267
|
+
--qt-ease:cubic-bezier(.2,.7,.1,1);
|
|
268
|
+
position:relative;display:flex;flex-direction:column;height:100%;min-height:0;overflow:hidden;
|
|
269
|
+
background:var(--qt-grain-light),radial-gradient(120% 90% at 45% 40%,transparent 50%,rgba(0,0,0,.55) 100%),var(--qt-desk);
|
|
270
|
+
color:var(--qt-desk-ink);font-family:var(--qt-zh-sans);font-size:14px;line-height:1.5;
|
|
271
|
+
}
|
|
272
|
+
.qt-root *,.qt-root *::before,.qt-root *::after{box-sizing:border-box}
|
|
273
|
+
:where(.qt-root) :where(button,input,textarea){font:inherit;color:inherit}
|
|
274
|
+
:where(.qt-root) button{appearance:none;border:0;background:none;padding:0;cursor:pointer}
|
|
275
|
+
:where(.qt-root) button:disabled{cursor:default}
|
|
276
|
+
.qt-root :focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}
|
|
277
|
+
.qt-mono{font-family:var(--qt-mono);letter-spacing:.02em;text-transform:uppercase}
|
|
278
|
+
.qt-br::before{content:"[ "}.qt-br::after{content:" ]"}
|
|
279
|
+
.qt-dots{height:2px;flex:none;background-image:radial-gradient(circle,currentColor 1px,transparent 1.3px);background-size:7px 2px;opacity:.55}
|
|
280
|
+
.qt-spacer{flex:1}
|
|
281
|
+
|
|
282
|
+
/* 头部(窗口拖拽区):画板左上角的标题和右上角的 History */
|
|
283
|
+
.qt-header{display:flex;align-items:baseline;gap:14px;flex:none;padding:22px 40px 0;padding-top:calc(22px + var(--dsh-frame-top-clearance,0px));padding-left:calc(40px + var(--dsh-frame-leading-clearance,0px))}
|
|
284
|
+
.qt-title{font-family:var(--qt-grot);font-weight:900;font-size:23px;letter-spacing:-.035em;white-space:nowrap}
|
|
285
|
+
.qt-subtitle{font-size:11px;opacity:.55;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
|
|
286
|
+
.qt-hbtn{font-family:var(--qt-mono);font-size:12px;text-transform:uppercase;letter-spacing:.02em;display:inline-flex;align-items:center;gap:8px;white-space:nowrap;color:var(--qt-desk-ink);opacity:.85;padding:4px 0}
|
|
287
|
+
.qt-hbtn:hover,.qt-hbtn[aria-pressed="true"]{opacity:1}
|
|
288
|
+
.qt-hbtn:disabled{opacity:.4}
|
|
289
|
+
.qt-badge{padding:1px 6px;border:1px solid currentColor;line-height:1.4;font-variant-numeric:tabular-nums}
|
|
290
|
+
.qt-hbtn[aria-pressed="true"] .qt-badge{background:var(--qt-desk-ink);color:var(--qt-desk)}
|
|
291
|
+
|
|
292
|
+
/* 桌面 */
|
|
293
|
+
.qt-board{flex:1;min-height:0;position:relative;display:flex;align-items:center;justify-content:center;overflow:hidden}
|
|
294
|
+
.qt-comp{position:relative;width:1200px;height:690px;flex:none}
|
|
295
|
+
.qt-deco-date{position:absolute;left:6px;bottom:72px;transform:rotate(-90deg);transform-origin:left bottom;font-family:var(--qt-grot);font-weight:800;font-size:30px;letter-spacing:-.02em;color:var(--qt-desk-faint);white-space:nowrap;pointer-events:none}
|
|
296
|
+
.qt-deco-side{position:absolute;right:14px;top:50px;writing-mode:vertical-rl;font-family:var(--qt-mono);font-size:11px;line-height:1.7;color:var(--qt-desk-faint);pointer-events:none}
|
|
297
|
+
.qt-col{position:absolute;isolation:isolate}
|
|
298
|
+
.qt-paper{position:absolute;inset:0;z-index:-1;pointer-events:none}
|
|
299
|
+
.qt-colhead{display:flex;justify-content:space-between;gap:12px;font-family:var(--qt-mono);font-size:11.5px;letter-spacing:.02em;text-transform:uppercase;white-space:nowrap;flex:none}
|
|
300
|
+
.qt-colhead > *{overflow:hidden;text-overflow:ellipsis}
|
|
301
|
+
.qt-locked{color:var(--qt-red)}
|
|
302
|
+
.qt-textarea{flex:1;min-height:0;width:100%;resize:none;border:0;outline:0;background:transparent;padding:0;margin:0;color:inherit;scrollbar-width:thin;scrollbar-color:rgba(0,0,0,.22) transparent}
|
|
303
|
+
.qt-textarea:focus-visible{outline:0}
|
|
304
|
+
.qt-textarea{scrollbar-width:none}
|
|
305
|
+
.qt-textarea::-webkit-scrollbar{display:none}
|
|
306
|
+
.qt-tawrap{position:relative;flex:1;min-height:0;display:flex}
|
|
307
|
+
.qt-tarul{position:absolute;right:-24px;top:4px;bottom:4px;width:7px;pointer-events:none;background:repeating-linear-gradient(to bottom,currentColor 0 1px,transparent 1px 6px);opacity:0;transition:opacity .5s ease}
|
|
308
|
+
.qt-tarul.is-on{opacity:.55;transition-duration:.12s}
|
|
309
|
+
.qt-tarul i{position:absolute;left:0;right:0;background:currentColor}
|
|
310
|
+
.qt-note .qt-tarul{right:auto;left:-13px;color:var(--qt-ink-2)}
|
|
311
|
+
|
|
312
|
+
/* 原文:方格本(画板坐标 62,12 · 540×606 · -1.1°) */
|
|
313
|
+
.qt-note{left:62px;top:12px;width:540px;height:606px;transform:rotate(-1.1deg);color:var(--qt-ink)}
|
|
314
|
+
.qt-note .qt-paper{filter:drop-shadow(0 24px 30px rgba(0,0,0,.45))}
|
|
315
|
+
.qt-note .qt-paper::before{content:"";position:absolute;inset:0;
|
|
316
|
+
background:var(--qt-grain),
|
|
317
|
+
linear-gradient(90deg,transparent 62px,rgba(214,80,60,.45) 62px,rgba(214,80,60,.45) 63px,transparent 63px),
|
|
318
|
+
linear-gradient(var(--qt-grid) 1px,transparent 1px) 0 10px/22px 22px,
|
|
319
|
+
linear-gradient(90deg,var(--qt-grid) 1px,transparent 1px) 0 0/22px 22px,
|
|
320
|
+
var(--qt-paper);
|
|
321
|
+
clip-path:polygon(0 0,100% 0,100% 97.4%,96% 98.6%,91% 97.2%,86% 99.1%,80% 97.6%,74% 98.9%,69% 97%,63% 98.4%,57% 97.3%,51% 99.2%,45% 97.5%,39% 98.8%,33% 97.1%,27% 98.6%,21% 97.4%,15% 99%,9% 97.6%,4% 98.7%,0 97.5%)}
|
|
322
|
+
.qt-rings{position:absolute;left:0;top:0;bottom:18px;width:16px;background:repeating-linear-gradient(to bottom,#141414 0 11px,transparent 11px 25px);pointer-events:none}
|
|
323
|
+
.qt-holes{position:absolute;left:28px;top:6px;bottom:24px;width:18px;background:radial-gradient(circle,var(--qt-desk) 6.5px,transparent 7px) 0 0/18px 25px repeat-y;pointer-events:none}
|
|
324
|
+
.qt-note-in{position:absolute;left:82px;right:70px;top:34px;bottom:34px;display:flex;flex-direction:column}
|
|
325
|
+
.qt-note .qt-colhead{color:var(--qt-ink-2)}
|
|
326
|
+
.qt-note .qt-dots{margin:14px 0 22px;color:var(--qt-ink-2)}
|
|
327
|
+
.qt-src{font-family:var(--qt-mono);font-size:15.5px;line-height:1.85;color:var(--qt-ink)}
|
|
328
|
+
.qt-comp:not(.is-narrow) .qt-note .qt-tawrap{margin-right:30px}
|
|
329
|
+
.qt-src::placeholder{color:#8b8d93}
|
|
330
|
+
.qt-src[readonly]{cursor:default}
|
|
331
|
+
.qt-note-foot{display:flex;align-items:center;gap:16px;flex:none;min-height:56px;padding-right:150px}
|
|
332
|
+
.qt-meta{font-family:var(--qt-mono);font-size:11px;text-transform:uppercase;letter-spacing:.02em;color:var(--qt-ink-2);white-space:nowrap}
|
|
333
|
+
|
|
334
|
+
/* 文具胶带:翻译(红布胶带)· 清空 / 互换(美纹纸) */
|
|
335
|
+
.qt-tapebtn{position:relative;display:inline-flex;align-items:center;justify-content:center;clip-path:var(--qt-tape-clip);transition:transform .2s var(--qt-ease),opacity .15s,filter .15s}
|
|
336
|
+
.qt-tapebtn:disabled{opacity:.45}
|
|
337
|
+
.qt-tapebtn:focus-visible{outline:2px dashed currentColor;outline-offset:-7px}
|
|
338
|
+
.qt-actions{position:absolute;right:62px;bottom:30px;display:flex;align-items:center;gap:6px}
|
|
339
|
+
.qt-go{gap:16px;padding:14px 22px 14px 28px;transform:rotate(-2deg);font-family:var(--qt-zh-sans);font-weight:900;font-size:25px;letter-spacing:.06em;line-height:1.1;white-space:nowrap}
|
|
340
|
+
.qt-go:hover:not(:disabled){transform:rotate(-2deg) translateY(-2px)}
|
|
341
|
+
.qt-go kbd{font-family:var(--qt-mono);font-weight:600;font-size:11px;letter-spacing:.04em;padding:2px 5px;border:1.5px solid currentColor;line-height:1.2}
|
|
342
|
+
.qt-btn-primary{background:var(--qt-grain),linear-gradient(180deg,rgba(255,255,255,.14),rgba(255,255,255,0) 55%),var(--qt-red);color:#141414}
|
|
343
|
+
.qt-btn-stop{background:var(--qt-grain),#1b1b1b;color:var(--qt-paper)}
|
|
344
|
+
.qt-clear{padding:8px 20px 8px 22px;transform:rotate(-2.5deg);background:var(--qt-grain),linear-gradient(180deg,rgba(255,255,255,.22),rgba(255,255,255,0) 60%),var(--qt-masking);color:#26241f;font-family:var(--qt-zh-sans);font-weight:800;font-size:15px;letter-spacing:.24em}
|
|
345
|
+
.qt-clear:hover:not(:disabled){transform:rotate(-2.5deg) translateY(-2px)}
|
|
346
|
+
|
|
347
|
+
/* 互换:画板里那张牛皮纸竖签,一半压在硫酸纸下面(层级:方格本 1 → 互换 2 → 硫酸纸 3),透过磨砂纸面能看到被盖住的那半 */
|
|
348
|
+
.qt-note{z-index:1}
|
|
349
|
+
.qt-vellum{z-index:3;pointer-events:none}
|
|
350
|
+
.qt-vel-in,.qt-vellum .qt-picker{pointer-events:auto}
|
|
351
|
+
.qt-swap{position:absolute;left:512px;top:316px;z-index:2;width:78px;height:128px;display:flex;flex-direction:column;align-items:flex-start;justify-content:center;gap:10px;padding-left:8px;transform:rotate(-3deg);color:#171717;
|
|
352
|
+
background:var(--qt-grain),var(--qt-grain),linear-gradient(180deg,rgba(0,0,0,.10),rgba(0,0,0,0) 14%,rgba(0,0,0,0) 86%,rgba(0,0,0,.12)),repeating-linear-gradient(90deg,rgba(0,0,0,.05) 0 1px,transparent 1px 4px),var(--qt-kraft);
|
|
353
|
+
box-shadow:-5px 9px 16px -6px rgba(0,0,0,.5),inset 0 0 0 1px rgba(60,35,10,.18);transition:transform .25s var(--qt-ease),opacity .15s}
|
|
354
|
+
.qt-swap:hover:not(:disabled){transform:rotate(-3deg) translateX(-8px)}
|
|
355
|
+
.qt-swap:disabled{opacity:.5}
|
|
356
|
+
.qt-swap small,.qt-swap b{width:26px;display:flex;justify-content:center}
|
|
357
|
+
.qt-swap small{font-family:var(--qt-mono);font-size:11px;font-weight:600;line-height:1}
|
|
358
|
+
.qt-swap b{writing-mode:vertical-rl;font-family:var(--qt-zh-sans);font-weight:900;font-size:19px;letter-spacing:.12em;line-height:1}
|
|
359
|
+
|
|
360
|
+
/* 译文:硫酸纸(画板坐标 556,48 · 600×540 · 0.7°) */
|
|
361
|
+
.qt-vellum{left:556px;top:48px;width:600px;height:540px;transform:rotate(.7deg);color:var(--qt-indigo)}
|
|
362
|
+
.qt-vellum .qt-paper{background:var(--qt-grain),rgba(226,227,223,.76);-webkit-backdrop-filter:blur(2.5px) brightness(1.06);backdrop-filter:blur(2.5px) brightness(1.06);box-shadow:0 34px 60px -28px rgba(0,0,0,.65),inset 0 0 0 1px rgba(255,255,255,.35)}
|
|
363
|
+
.qt-vel-in{position:absolute;inset:40px 44px 36px;display:flex;flex-direction:column}
|
|
364
|
+
.qt-vellum .qt-colhead{font-size:12px}
|
|
365
|
+
.qt-vellum .qt-dots{margin:16px 0 26px}
|
|
366
|
+
.qt-vellum .qt-dots.qt-dots-end{margin:0 0 16px}
|
|
367
|
+
.qt-tape{position:absolute;height:30px;z-index:7;pointer-events:none;background:var(--qt-grain),rgba(236,231,214,.6);clip-path:var(--qt-tape-clip)}
|
|
368
|
+
.qt-tape-a{left:528px;top:34px;width:118px;transform:rotate(-9deg)}
|
|
369
|
+
.qt-tape-b{left:1070px;top:40px;width:104px;transform:rotate(7deg)}
|
|
370
|
+
.qt-body{flex:1;min-height:0;position:relative;display:flex;flex-direction:column}
|
|
371
|
+
.qt-res{font-weight:600;font-size:23px;line-height:1.8;letter-spacing:.02em;color:var(--qt-indigo)}
|
|
372
|
+
.qt-res[data-lang="zh"]{font-family:var(--qt-zh-serif)}
|
|
373
|
+
.qt-res[data-lang="en"]{font-family:var(--qt-en-serif);font-weight:500;line-height:1.6;letter-spacing:0}
|
|
374
|
+
.qt-res::placeholder{color:transparent}
|
|
375
|
+
.qt-waiting{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;text-align:center;pointer-events:none;opacity:.55}
|
|
376
|
+
.qt-waiting b{font-family:var(--qt-zh-sans);font-weight:900;font-size:52px;letter-spacing:.08em;line-height:1.1}
|
|
377
|
+
.qt-waiting span{font-family:var(--qt-mono);font-size:12px}
|
|
378
|
+
.qt-chip-ok{font-weight:600}
|
|
379
|
+
.qt-chip-warn{color:var(--qt-redpen);font-weight:600}
|
|
380
|
+
.qt-live::after{content:" ···";animation:qt-blink 1s steps(2) infinite}
|
|
381
|
+
@keyframes qt-blink{50%{opacity:.2}}
|
|
382
|
+
.qt-error{margin:0 0 14px;padding:10px 12px;border:2px solid var(--qt-redpen);border-radius:3px 9px 4px 11px;transform:rotate(-.6deg);color:var(--qt-redpen);display:flex;gap:12px;align-items:flex-start;font-size:13px;line-height:1.5;flex:none}
|
|
383
|
+
.qt-error-text{flex:1;min-width:0;word-break:break-word}
|
|
384
|
+
.qt-stats{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));font-family:var(--qt-mono);font-size:11.5px;line-height:1.5;flex:none}
|
|
385
|
+
.qt-stats b{display:block;font-weight:600;font-size:15px;font-variant-numeric:tabular-nums}
|
|
386
|
+
.qt-stats > :nth-child(2){text-align:center}.qt-stats > :nth-child(3){text-align:right}
|
|
387
|
+
.qt-bar{height:18px;margin:14px 0 16px;flex:none;position:relative;overflow:hidden;background:repeating-linear-gradient(90deg,currentColor 0 2px,transparent 2px 6px);opacity:.18}
|
|
388
|
+
.qt-bar[data-state="done"]{opacity:.8}
|
|
389
|
+
.qt-bar[data-state="streaming"]{opacity:1;background:none}
|
|
390
|
+
.qt-bar[data-state="streaming"]::before{content:"";position:absolute;inset:0;background:repeating-linear-gradient(90deg,currentColor 0 2px,transparent 2px 6px);opacity:.18}
|
|
391
|
+
.qt-bar[data-state="streaming"]::after{content:"";position:absolute;top:0;bottom:0;left:0;width:38%;background:repeating-linear-gradient(90deg,currentColor 0 2px,transparent 2px 6px);opacity:.85;animation:qt-feed 1.6s linear infinite}
|
|
392
|
+
@keyframes qt-feed{from{left:-38%}to{left:100%}}
|
|
393
|
+
.qt-vfoot{display:flex;align-items:center;gap:12px;flex:none}
|
|
394
|
+
.qt-link{font-family:var(--qt-mono);font-size:12px;letter-spacing:.02em;white-space:nowrap;padding:6px 0;opacity:.9}
|
|
395
|
+
.qt-link:hover:not(:disabled){opacity:1;text-decoration:underline;text-underline-offset:3px}
|
|
396
|
+
.qt-link:disabled{opacity:.35}
|
|
397
|
+
.qt-btn-warn{color:var(--qt-redpen);opacity:1}
|
|
398
|
+
.qt-sign{width:96px;height:32px;color:var(--qt-stamp);flex:none}
|
|
399
|
+
.qt-stamp{position:absolute;right:70px;bottom:62px;width:112px;height:112px;transform:rotate(-14deg);opacity:.6;mix-blend-mode:multiply;color:var(--qt-stamp);pointer-events:none;animation:qt-stamp .38s var(--qt-ease)}
|
|
400
|
+
@keyframes qt-stamp{from{opacity:0;transform:rotate(-14deg) scale(1.35)}}
|
|
401
|
+
|
|
402
|
+
/* 模型:索引卡(红页眉线 + 蓝横线,每行正好落在一条横线上) */
|
|
403
|
+
.qt-picker{position:relative;min-width:0}
|
|
404
|
+
.qt-picker-btn{display:inline-flex;align-items:baseline;gap:8px;max-width:100%;font-family:var(--qt-mono);font-size:12px;text-transform:uppercase;letter-spacing:.02em;white-space:nowrap}
|
|
405
|
+
.qt-picker-btn:disabled{opacity:.5}
|
|
406
|
+
.qt-picker-label{font-family:var(--qt-grot);font-weight:800;font-size:17px;letter-spacing:-.01em;text-transform:none;overflow:hidden;text-overflow:ellipsis;min-width:0}
|
|
407
|
+
.qt-picker-tag{flex:none;opacity:.7}
|
|
408
|
+
.qt-chev{display:inline-block;transition:transform .2s var(--qt-ease)}
|
|
409
|
+
.qt-picker-btn[aria-expanded="true"] .qt-chev{transform:rotate(180deg)}
|
|
410
|
+
.qt-picker-menu{position:absolute;left:-6px;bottom:calc(100% + 14px);z-index:30;width:352px;max-height:352px;overflow:auto;padding:22px 22px 16px;transform:rotate(-1.6deg);transform-origin:bottom left;color:var(--qt-ink);
|
|
411
|
+
background:var(--qt-grain),#fbfbf8;box-shadow:0 24px 40px -12px rgba(0,0,0,.55);animation:qt-card .2s var(--qt-ease)}
|
|
412
|
+
@keyframes qt-card{from{opacity:0;transform:rotate(-1.6deg) translateY(8px)}}
|
|
413
|
+
.qt-picker-head{display:flex;justify-content:space-between;align-items:baseline;height:34px;border-bottom:1.5px solid rgba(214,80,60,.55);margin-bottom:6px}
|
|
414
|
+
.qt-picker-head b{font-family:var(--qt-grot);font-weight:900;font-size:20px;letter-spacing:-.03em}
|
|
415
|
+
.qt-picker-head span{font-family:var(--qt-mono);font-size:10.5px;color:#55575e}
|
|
416
|
+
.qt-picker-group-title,.qt-picker-item,.qt-picker-empty{height:28px;border-bottom:1px solid rgba(90,130,190,.28)}
|
|
417
|
+
.qt-picker-group-title{display:flex;align-items:flex-end;padding-bottom:4px;font-family:var(--qt-mono);font-size:10px;letter-spacing:.06em;color:#9a2d16;text-transform:uppercase}
|
|
418
|
+
.qt-picker-item{display:flex;align-items:center;gap:10px;width:100%;text-align:left;font-size:13px;white-space:nowrap;color:var(--qt-ink)}
|
|
419
|
+
.qt-picker-item:hover .qt-name{text-decoration:underline;text-underline-offset:3px}
|
|
420
|
+
.qt-picker-item .qt-check{width:18px;flex:none;color:var(--qt-stamp);visibility:hidden;display:inline-flex}
|
|
421
|
+
.qt-picker-item[aria-selected="true"] .qt-check{visibility:visible}
|
|
422
|
+
.qt-picker-item[aria-selected="true"] .qt-name{font-weight:700}
|
|
423
|
+
.qt-picker-item .qt-name{overflow:hidden;text-overflow:ellipsis;min-width:0}
|
|
424
|
+
.qt-picker-item .qt-id{margin-left:auto;font-family:var(--qt-mono);font-size:10px;color:var(--qt-ink-3);overflow:hidden;text-overflow:ellipsis;max-width:48%}
|
|
425
|
+
.qt-picker-empty{display:flex;align-items:center;font-size:12px;color:var(--qt-ink-3)}
|
|
426
|
+
|
|
427
|
+
/* 方向:牛皮纸标签(380×140 · -2°),和画板一样贴着面板右下角、露出一截被裁掉 */
|
|
428
|
+
.qt-tagwrap{position:absolute;right:0;bottom:0;z-index:6;pointer-events:none}
|
|
429
|
+
.qt-tagwrap .qt-tag{pointer-events:auto}
|
|
430
|
+
.qt-tag{position:relative;margin:0 -52px -22px 0;width:380px;height:140px;transform:rotate(-2deg);transform-origin:right bottom;padding:14px 22px;display:flex;flex-direction:column;gap:4px;color:#171717;
|
|
431
|
+
background:var(--qt-grain),repeating-linear-gradient(90deg,rgba(0,0,0,.05) 0 1px,transparent 1px 4px),var(--qt-kraft);box-shadow:0 -10px 30px -12px rgba(0,0,0,.5)}
|
|
432
|
+
.qt-seg{display:flex;gap:14px;font-family:var(--qt-mono);font-size:11px}
|
|
433
|
+
.qt-seg button{opacity:.6;white-space:nowrap}
|
|
434
|
+
.qt-seg button:hover:not(:disabled){opacity:.85}
|
|
435
|
+
.qt-seg button[aria-pressed="true"]{opacity:1;font-weight:600}
|
|
436
|
+
.qt-seg button[aria-pressed="true"]::before{content:"[ "}.qt-seg button[aria-pressed="true"]::after{content:" ]"}
|
|
437
|
+
.qt-tag-big{font-family:var(--qt-zh-sans);font-weight:900;font-size:44px;letter-spacing:-.01em;line-height:1.15;white-space:nowrap}
|
|
438
|
+
|
|
439
|
+
/* 历史:热敏小票(画板坐标 右 34,-10 · 304×600 · 1.4°,整张连字一起倾斜) */
|
|
440
|
+
.qt-backdrop{position:absolute;inset:0;z-index:8}
|
|
441
|
+
.qt-history{right:34px;top:-10px;width:304px;height:600px;transform:rotate(1.4deg);z-index:9;display:flex;flex-direction:column;padding:26px 24px 22px;color:var(--qt-ink);filter:drop-shadow(0 26px 30px rgba(0,0,0,.5))}
|
|
442
|
+
.qt-history .qt-paper{background:var(--qt-grain),var(--qt-receipt);
|
|
443
|
+
clip-path:polygon(0 1.2%,4% 0,8% 1.2%,12% 0,16% 1.2%,20% 0,24% 1.2%,28% 0,32% 1.2%,36% 0,40% 1.2%,44% 0,48% 1.2%,52% 0,56% 1.2%,60% 0,64% 1.2%,68% 0,72% 1.2%,76% 0,80% 1.2%,84% 0,88% 1.2%,92% 0,96% 1.2%,100% 0,100% 100%,96% 98.8%,92% 100%,88% 98.8%,84% 100%,80% 98.8%,76% 100%,72% 98.8%,68% 100%,64% 98.8%,60% 100%,56% 98.8%,52% 100%,48% 98.8%,44% 100%,40% 98.8%,36% 100%,32% 98.8%,28% 100%,24% 98.8%,20% 100%,16% 98.8%,12% 100%,8% 98.8%,4% 100%,0 98.8%)}
|
|
444
|
+
.qt-history-head{display:flex;justify-content:space-between;align-items:baseline;flex:none}
|
|
445
|
+
.qt-history-head b{font-family:var(--qt-grot);font-weight:900;font-size:20px;letter-spacing:-.03em}
|
|
446
|
+
.qt-history-head span{font-family:var(--qt-mono);font-size:11px}
|
|
447
|
+
.qt-history-search{display:flex;gap:8px;align-items:center;margin-top:12px;padding-bottom:6px;font-family:var(--qt-mono);font-size:11px;text-transform:uppercase;flex:none}
|
|
448
|
+
.qt-history-search input{flex:1;min-width:0;border:0;outline:0;background:none;font-family:var(--qt-zh-sans);font-size:12px;text-transform:none;color:var(--qt-ink)}
|
|
449
|
+
.qt-history-search input::placeholder{color:var(--qt-ink-3)}
|
|
450
|
+
.qt-perf{height:6px;margin:0 -24px;flex:none;background:radial-gradient(circle at 3px 3px,var(--qt-desk) 2.2px,transparent 2.6px) 0 0/9px 6px repeat-x}
|
|
451
|
+
.qt-history-scroll{flex:1;min-height:0;position:relative;margin-right:-10px}
|
|
452
|
+
.qt-history-list{position:absolute;inset:0;overflow-y:auto;padding:0 22px 8px 0;scrollbar-width:none}
|
|
453
|
+
.qt-history-list::-webkit-scrollbar{display:none}
|
|
454
|
+
.qt-ruler{position:absolute;right:0;top:34px;bottom:6px;width:8px;pointer-events:none;background:repeating-linear-gradient(to bottom,rgba(28,28,28,.35) 0 1px,transparent 1px 6px)}
|
|
455
|
+
.qt-ruler i{position:absolute;left:0;right:0;background:#1c1c1c}
|
|
456
|
+
.qt-hday{position:sticky;top:0;z-index:2;background:var(--qt-receipt);padding:10px 0 6px;font-family:var(--qt-mono);font-size:10.5px;color:#9a2d16;box-shadow:0 6px 6px -6px rgba(0,0,0,.22)}
|
|
457
|
+
.qt-hitem-wrap{position:relative}
|
|
458
|
+
.qt-hitem-wrap + .qt-hitem-wrap{border-top:1px dotted rgba(28,28,28,.3)}
|
|
459
|
+
.qt-hitem{display:block;text-align:left;padding:9px 8px 10px;margin:0 -8px;width:calc(100% + 16px);color:var(--qt-ink)}
|
|
460
|
+
.qt-hitem[aria-current="true"]{background:linear-gradient(transparent 8%,rgba(239,74,35,.2) 8%,rgba(239,74,35,.2) 92%,transparent 92%)}
|
|
461
|
+
.qt-hitem-meta{display:flex;gap:10px;font-family:var(--qt-mono);font-size:10.5px;text-transform:uppercase;letter-spacing:.02em;color:#55575e;white-space:nowrap;overflow:hidden;padding-right:20px}
|
|
462
|
+
.qt-hitem-meta .qt-model{overflow:hidden;text-overflow:ellipsis;min-width:0}
|
|
463
|
+
.qt-hitem-dst{margin-top:4px;font-size:13.5px;line-height:1.55;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;word-break:break-word;white-space:pre-line}
|
|
464
|
+
.qt-hitem-dst[data-lang="zh"]{font-family:var(--qt-zh-serif)}
|
|
465
|
+
.qt-hitem-dst[data-lang="en"]{font-family:var(--qt-en-serif)}
|
|
466
|
+
.qt-hitem-src{margin-top:2px;font-size:11px;color:var(--qt-ink-3);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
467
|
+
.qt-hitem-del{position:absolute;top:8px;right:0;width:20px;height:20px;font-family:var(--qt-mono);font-size:13px;color:var(--qt-ink-3);opacity:0;pointer-events:none}
|
|
468
|
+
.qt-hitem-wrap:hover .qt-hitem-del,.qt-hitem-del:focus-visible{opacity:1;pointer-events:auto}
|
|
469
|
+
.qt-hitem-del:hover{color:var(--qt-redpen)}
|
|
470
|
+
.qt-empty-sm{padding:28px 4px;font-family:var(--qt-mono);font-size:11px;color:var(--qt-ink-3);white-space:pre-line;line-height:1.7;text-align:center}
|
|
471
|
+
.qt-history-foot{display:flex;justify-content:space-between;align-items:center;padding-top:10px;flex:none;font-family:var(--qt-mono);font-size:11px}
|
|
472
|
+
.qt-history-foot .qt-link{font-size:11px;padding:0}
|
|
473
|
+
.qt-history-foot .qt-danger{color:var(--qt-redpen);opacity:1}
|
|
474
|
+
.qt-barcode{height:30px;margin-top:12px;flex:none;background:repeating-linear-gradient(90deg,#1c1c1c 0 1px,transparent 1px 3px,#1c1c1c 3px 6px,transparent 6px 8px,#1c1c1c 8px 9px,transparent 9px 13px)}
|
|
475
|
+
|
|
476
|
+
/* 没有模型 */
|
|
477
|
+
.qt-empty-card{position:relative;isolation:isolate;max-width:460px;margin:24px;padding:30px 34px 26px;color:var(--qt-ink);display:flex;flex-direction:column;align-items:flex-start;gap:16px;transform:rotate(-1deg)}
|
|
478
|
+
.qt-empty-card .qt-paper{background:var(--qt-grain),var(--qt-receipt);box-shadow:0 24px 40px -16px rgba(0,0,0,.5)}
|
|
479
|
+
.qt-empty-card b{font-family:var(--qt-grot);font-weight:900;font-size:22px;letter-spacing:-.03em}
|
|
480
|
+
.qt-empty-card p{margin:0;font-size:13px;line-height:1.7;white-space:pre-line}
|
|
481
|
+
.qt-empty-card .qt-go{position:relative;right:auto;bottom:auto}
|
|
482
|
+
|
|
483
|
+
/* 分享 */
|
|
484
|
+
.qt-share{position:absolute;inset:0;z-index:60;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;padding:24px;background:rgba(10,10,10,.62);-webkit-backdrop-filter:blur(3px);backdrop-filter:blur(3px);animation:qt-fade .2s ease}
|
|
485
|
+
@keyframes qt-fade{from{opacity:0}}
|
|
486
|
+
.qt-share-card{flex:1 1 0;min-height:0;width:100%;display:flex;align-items:center;justify-content:center}
|
|
487
|
+
.qt-share-card img{display:block;max-width:min(560px,100%);max-height:100%;width:auto;height:auto;object-fit:contain;box-shadow:0 30px 60px -20px rgba(0,0,0,.7);animation:qt-card .3s var(--qt-ease)}
|
|
488
|
+
.qt-share-wait{font-family:var(--qt-mono);font-size:12px;color:#e6e3dc}
|
|
489
|
+
.qt-share-bar{display:flex;align-items:center;gap:22px;flex-wrap:wrap;justify-content:center;color:#e6e3dc}
|
|
490
|
+
.qt-share-bar .qt-go,.qt-share-bar .qt-clear{position:relative;right:auto;bottom:auto;transform:none;font-size:20px;letter-spacing:.08em;padding:12px 26px}
|
|
491
|
+
.qt-share-bar .qt-go:hover:not(:disabled),.qt-share-bar .qt-clear:hover:not(:disabled){transform:translateY(-2px)}
|
|
492
|
+
.qt-share-bar .qt-hbtn{font-size:14px}
|
|
493
|
+
.qt-share-msg{font-family:var(--qt-mono);font-size:11px;opacity:.8;width:100%;text-align:center}
|
|
494
|
+
|
|
495
|
+
/* 窄面板:两张纸上下叠放,不缩放 */
|
|
496
|
+
.qt-board.is-narrow{align-items:flex-start;overflow-y:auto}
|
|
497
|
+
.qt-comp.is-narrow{width:100%;height:auto;padding:14px 16px 40px 20px;display:flex;flex-direction:column}
|
|
498
|
+
.qt-comp.is-narrow .qt-deco-date,.qt-comp.is-narrow .qt-deco-side,.qt-comp.is-narrow .qt-tape{display:none}
|
|
499
|
+
.qt-comp.is-narrow .qt-note{position:relative;left:auto;top:auto;width:auto;height:420px;transform:rotate(-.8deg)}
|
|
500
|
+
.qt-comp.is-narrow .qt-note-in{left:66px;right:22px;top:28px;bottom:28px}
|
|
501
|
+
.qt-comp.is-narrow .qt-note-foot{padding-right:0;flex-wrap:wrap;row-gap:8px}
|
|
502
|
+
.qt-comp.is-narrow .qt-actions{position:relative;right:auto;bottom:auto;margin-left:auto}
|
|
503
|
+
.qt-comp.is-narrow .qt-vellum{position:relative;left:auto;top:auto;width:auto;height:480px;margin-top:30px;transform:rotate(.6deg)}
|
|
504
|
+
.qt-comp.is-narrow .qt-vel-in{inset:30px 24px 26px}
|
|
505
|
+
.qt-comp.is-narrow .qt-swap{position:relative;left:auto;top:auto;align-self:flex-end;margin:-46px 26px -40px 0;width:132px;height:42px;flex-direction:row;transform:rotate(3deg);
|
|
506
|
+
}
|
|
507
|
+
.qt-comp.is-narrow .qt-swap b{writing-mode:horizontal-tb}
|
|
508
|
+
.qt-comp.is-narrow .qt-stamp{right:22px}
|
|
509
|
+
.qt-comp.is-narrow .qt-tag{position:relative;left:auto;top:auto;width:auto;height:auto;margin:18px -24px 0 30px;padding-bottom:22px}
|
|
510
|
+
.qt-comp.is-narrow .qt-history{position:absolute;right:6px;top:4px;width:min(304px,92%)}
|
|
511
|
+
.qt-title{-webkit-text-stroke:.5px currentColor}
|
|
512
|
+
.qt-go,.qt-clear,.qt-swap b,.qt-picker-head b,.qt-history-head b,.qt-empty-card b{-webkit-text-stroke:.6px currentColor}
|
|
513
|
+
.qt-tag-big,.qt-waiting b{-webkit-text-stroke:1.1px currentColor}
|
|
514
|
+
/* 纸本头部的风格切换:打字机字「风格: [ 纸本 ] / 色场」 */
|
|
515
|
+
.qt-skinsw{display:inline-flex;align-items:center;gap:10px;font-size:12px;margin-right:10px;white-space:nowrap}
|
|
516
|
+
.qt-skinsw-k{opacity:.55}
|
|
517
|
+
.qt-skinsw-sep{opacity:.4}
|
|
518
|
+
.qt-skinsw .qt-hbtn[aria-pressed="true"]{font-weight:600}
|
|
519
|
+
.qt-skinsw .qt-hbtn[aria-pressed="true"]::before{content:"[ "}.qt-skinsw .qt-hbtn[aria-pressed="true"]::after{content:" ]"}
|
|
520
|
+
.qt-skinsw .qt-hbtn[aria-pressed="false"]{opacity:.6}
|
|
521
|
+
.qt-skinsw .qt-hbtn[aria-pressed="false"]:hover{opacity:1}
|
|
522
|
+
|
|
523
|
+
/* ============ 色场(F):画板 F 的 1200×696 工作区原样搭,再整体缩放(最多 1.3 倍);颜色全部走 DSH 主题 token ============ */
|
|
524
|
+
.qt-root.qt-skin-field{
|
|
525
|
+
--qt-f-base:var(--dsw-alias-bg-base,#fff);--qt-f-l1:var(--dsw-alias-bg-layer-1,#f6f6f8);--qt-f-l2:var(--dsw-alias-bg-layer-2,#ececf0);--qt-f-ov:var(--dsw-alias-bg-overlay,#fff);
|
|
526
|
+
--qt-f-b1:var(--dsw-alias-border-l1,#e9e9ee);--qt-f-b2:var(--dsw-alias-border-l2,#d8d8de);--qt-f-brand:var(--dsw-alias-brand-primary,#4d6bfe);
|
|
527
|
+
--qt-f-ink:var(--dsw-alias-label-primary,#1d1d22);--qt-f-mute:var(--dsw-alias-label-secondary,#6c6c75);--qt-f-idle:var(--dsw-alias-state-idle-primary,#a7a7ae);
|
|
528
|
+
--qt-f-err:var(--dsw-alias-state-error-primary,#d14343);
|
|
529
|
+
--qt-f-field:var(--qt-f-brand);--qt-f-on:#fff;--qt-f-on2:rgba(255,255,255,.86);--qt-f-on3:rgba(255,255,255,.16);--qt-f-wm:rgba(255,255,255,.08);
|
|
530
|
+
--qt-f-ui:-apple-system,BlinkMacSystemFont,"PingFang SC","Helvetica Neue",var(--qt-zh-sans);
|
|
531
|
+
--qt-f-mono:"SF Mono",Menlo,var(--qt-mono);
|
|
532
|
+
background:var(--qt-f-base);color:var(--qt-f-ink);font-family:var(--qt-f-ui)}
|
|
533
|
+
.qt-root.qt-skin-field[data-tone="dark"]{--qt-f-field:color-mix(in srgb,var(--qt-f-brand) 55%,var(--qt-f-base));--qt-f-on2:rgba(255,255,255,.8);--qt-f-on3:rgba(255,255,255,.12);--qt-f-wm:rgba(255,255,255,.06)}
|
|
534
|
+
.qt-skin-field :focus-visible{outline:2px solid var(--qt-f-brand);outline-offset:2px}
|
|
535
|
+
.qt-ffield :focus-visible{outline-color:#fff}
|
|
536
|
+
|
|
537
|
+
/* 头部 */
|
|
538
|
+
.qt-fhead{display:flex;align-items:center;gap:12px;flex:none;height:calc(64px + var(--dsh-frame-top-clearance,0px));padding:var(--dsh-frame-top-clearance,0px) 32px 0 calc(32px + var(--dsh-frame-leading-clearance,0px))}
|
|
539
|
+
.qt-ftitle{font-size:17px;font-weight:700;letter-spacing:-.01em;white-space:nowrap}
|
|
540
|
+
.qt-fsub{font-size:12px;color:var(--qt-f-mute);margin-right:auto;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
|
|
541
|
+
.qt-ftrack{display:flex;gap:2px;padding:3px;border-radius:11px;background:var(--qt-f-l2);flex:none}
|
|
542
|
+
.qt-ftrack button{height:28px;padding:0 12px;border-radius:8px;font-size:12.5px;color:var(--qt-f-mute);display:inline-flex;align-items:center;gap:7px;white-space:nowrap;transition:background .15s,color .15s}
|
|
543
|
+
.qt-ftrack button:hover:not(:disabled){color:var(--qt-f-ink)}
|
|
544
|
+
.qt-ftrack button[aria-pressed="true"]{background:var(--qt-f-base);color:var(--qt-f-ink);font-weight:600;box-shadow:0 1px 2px rgba(0,0,0,.08),0 0 0 .5px rgba(0,0,0,.04)}
|
|
545
|
+
.qt-ftrack button:disabled{opacity:.45}
|
|
546
|
+
.qt-fsw{width:10px;height:10px;border-radius:3px;flex:none}
|
|
547
|
+
.qt-fsw-paper{background:#eeede7;box-shadow:inset 0 0 0 1px rgba(0,0,0,.18),inset -4px 0 0 #b88f62}
|
|
548
|
+
.qt-fsw-field{background:var(--qt-f-brand)}
|
|
549
|
+
.qt-fhb{height:32px;padding:0 12px;border-radius:10px;display:inline-flex;align-items:center;gap:8px;font-size:13px;color:var(--qt-f-mute);white-space:nowrap;flex:none;transition:background .15s,color .15s}
|
|
550
|
+
.qt-fhb:hover:not(:disabled),.qt-fhb[aria-pressed="true"]{background:var(--qt-f-l2);color:var(--qt-f-ink)}
|
|
551
|
+
.qt-fhb:disabled{opacity:.5}
|
|
552
|
+
.qt-fcnt{min-width:20px;height:18px;padding:0 6px;border-radius:9px;background:var(--qt-f-l2);color:var(--qt-f-ink);font-size:11px;font-weight:600;display:inline-grid;place-items:center;font-variant-numeric:tabular-nums}
|
|
553
|
+
.qt-fhb[aria-pressed="true"] .qt-fcnt,.qt-fhb:hover .qt-fcnt{background:var(--qt-f-base)}
|
|
554
|
+
|
|
555
|
+
/* 工作区 */
|
|
556
|
+
.qt-fboard{flex:1;min-height:0;position:relative;display:flex;align-items:center;justify-content:center;overflow:hidden}
|
|
557
|
+
.qt-fcomp{position:relative;width:1200px;height:696px;flex:none}
|
|
558
|
+
.qt-fbox{position:absolute;top:8px;height:664px;border-radius:28px;display:flex;flex-direction:column;min-width:0}
|
|
559
|
+
.qt-fsrc{left:24px;width:556px;padding:32px 36px 28px 40px;background:var(--qt-f-l1);box-shadow:inset 0 0 0 1px var(--qt-f-b1)}
|
|
560
|
+
.qt-ffield{left:596px;width:580px;padding:32px 36px 28px 48px;background:var(--qt-f-field);color:var(--qt-f-on);overflow:hidden}
|
|
561
|
+
.qt-frow{position:relative;display:flex;align-items:center;gap:12px;height:40px;flex:none;min-width:0}
|
|
562
|
+
.qt-flang{font-size:28px;line-height:1;white-space:nowrap;flex:none}
|
|
563
|
+
.qt-flang[data-lang="en"]{font-family:var(--qt-en-serif);font-style:italic}
|
|
564
|
+
.qt-flang[data-lang="zh"]{font-family:var(--qt-zh-serif);font-weight:600}
|
|
565
|
+
.qt-fhint{font-size:12.5px;color:var(--qt-f-mute);margin-right:auto;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
|
|
566
|
+
.qt-fhint.is-locked{color:var(--qt-f-brand)}
|
|
567
|
+
.qt-ffield .qt-fhint{color:var(--qt-f-on2)}
|
|
568
|
+
.qt-fchip-warn{color:var(--qt-f-on);font-weight:600;padding:3px 8px;border-radius:8px;background:var(--qt-f-on3)}
|
|
569
|
+
.qt-fbody{position:relative;flex:1;min-height:0;display:flex;flex-direction:column}
|
|
570
|
+
.qt-fta{flex:1;min-height:0;width:100%;resize:none;border:0;outline:0;background:transparent;padding:0;margin:28px 0 0;color:inherit;scrollbar-width:thin;scrollbar-color:var(--qt-f-b2) transparent}
|
|
571
|
+
.qt-fta:focus-visible{outline:0}
|
|
572
|
+
.qt-fsrc .qt-fta{font-family:var(--qt-f-ui);font-size:18px;line-height:1.75}
|
|
573
|
+
.qt-fsrc .qt-fta::placeholder{color:var(--qt-f-idle)}
|
|
574
|
+
.qt-fsrc .qt-fta[readonly]{color:var(--qt-f-mute);cursor:default}
|
|
575
|
+
.qt-ffield .qt-fta{scrollbar-color:rgba(255,255,255,.35) transparent}
|
|
576
|
+
.qt-fres{font-family:var(--qt-zh-serif);font-size:25px;font-weight:600;line-height:1.8;letter-spacing:.02em}
|
|
577
|
+
.qt-fres[data-lang="en"]{font-family:var(--qt-en-serif);font-weight:500;line-height:1.6;letter-spacing:0}
|
|
578
|
+
.qt-fres::placeholder{color:transparent}
|
|
579
|
+
.qt-fwait{position:absolute;inset:28px 0 0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;padding-bottom:40px;text-align:center;pointer-events:none}
|
|
580
|
+
.qt-fwait b{font-family:var(--qt-zh-serif);font-size:44px;font-weight:600;letter-spacing:.08em;line-height:1.2}
|
|
581
|
+
.qt-fwait span{font-size:13px;color:var(--qt-f-on2)}
|
|
582
|
+
.qt-ffoot{position:relative;display:flex;align-items:center;gap:8px;height:48px;flex:none;min-width:0}
|
|
583
|
+
.qt-fcount{font-size:12.5px;color:var(--qt-f-mute);margin-right:auto;font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
584
|
+
.qt-fclear{height:40px;padding:0 16px;border-radius:12px;font-size:13.5px;color:var(--qt-f-mute);white-space:nowrap}
|
|
585
|
+
.qt-fclear:hover:not(:disabled){background:var(--qt-f-l2);color:var(--qt-f-ink)}
|
|
586
|
+
.qt-fclear:disabled{opacity:.4}
|
|
587
|
+
.qt-fgo{height:44px;padding:0 8px 0 20px;border-radius:14px;background:var(--qt-f-ink);color:var(--qt-f-base);font-size:14.5px;font-weight:600;display:inline-flex;align-items:center;gap:12px;white-space:nowrap;flex:none;transition:transform .15s,opacity .15s}
|
|
588
|
+
.qt-fgo:hover:not(:disabled){transform:translateY(-1px)}
|
|
589
|
+
.qt-fgo:disabled{opacity:.32}
|
|
590
|
+
.qt-fgo kbd{font:inherit;font-size:11.5px;font-weight:500;height:26px;padding:0 8px;border-radius:8px;display:inline-grid;place-items:center;background:color-mix(in srgb,currentColor 16%,transparent)}
|
|
591
|
+
.qt-fgo.is-stop{background:var(--qt-f-base);color:var(--qt-f-ink);box-shadow:inset 0 0 0 1px var(--qt-f-b2)}
|
|
592
|
+
.qt-fgo.is-stop kbd{background:var(--qt-f-l2)}
|
|
593
|
+
.qt-fswap{position:absolute;left:562px;top:38px;z-index:5;width:52px;height:52px;border-radius:50%;background:var(--qt-f-base);color:var(--qt-f-ink);display:grid;place-items:center;box-shadow:0 0 0 6px var(--qt-f-base),0 8px 22px -6px rgba(0,0,0,.28);transition:transform .3s var(--qt-ease),opacity .15s}
|
|
594
|
+
.qt-fswap:hover:not(:disabled){transform:rotate(180deg)}
|
|
595
|
+
.qt-fswap:disabled{opacity:.45}
|
|
596
|
+
.qt-fcomp.is-hist .qt-fswap{visibility:hidden}
|
|
597
|
+
.qt-fwm{position:absolute;right:-44px;bottom:-132px;font-family:var(--qt-zh-serif);font-weight:600;font-size:480px;line-height:1;color:var(--qt-f-wm);pointer-events:none;user-select:none}
|
|
598
|
+
.qt-fwm[data-lang="en"]{font-family:var(--qt-en-serif);font-weight:500;right:-20px;bottom:-150px}
|
|
599
|
+
.qt-fstats{position:relative;display:flex;gap:20px;font-size:12px;color:var(--qt-f-on2);padding-bottom:14px;flex:none;font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden}
|
|
600
|
+
.qt-fprog{position:absolute;left:0;right:0;top:0;height:3px;background:var(--qt-f-on3);overflow:hidden}
|
|
601
|
+
.qt-fprog::after{content:"";position:absolute;top:0;bottom:0;left:-36%;width:36%;border-radius:2px;background:rgba(255,255,255,.75);animation:qt-fprog 1.4s ease-in-out infinite}
|
|
602
|
+
@keyframes qt-fprog{from{left:-36%}to{left:100%}}
|
|
603
|
+
.qt-ferror{position:relative;margin:20px 0 0;padding:10px 10px 10px 16px;border-radius:14px;background:var(--qt-f-on3);display:flex;gap:12px;align-items:center;font-size:13px;line-height:1.55;flex:none}
|
|
604
|
+
.qt-ferror .qt-error-text{flex:1;min-width:0;word-break:break-word}
|
|
605
|
+
.qt-ferror button,.qt-fcopy{height:40px;padding:0 18px;border-radius:12px;background:#fff;color:color-mix(in srgb,var(--qt-f-field) 82%,#000);font-size:13.5px;font-weight:600;white-space:nowrap;flex:none}
|
|
606
|
+
.qt-ferror button{height:32px;padding:0 14px;border-radius:10px}
|
|
607
|
+
.qt-fcopy.is-warn{color:var(--qt-f-err)}
|
|
608
|
+
.qt-fcopy:disabled,.qt-flink:disabled{opacity:.4}
|
|
609
|
+
.qt-flink{height:40px;padding:0 14px;border-radius:12px;font-size:13.5px;color:var(--qt-f-on);white-space:nowrap;flex:none}
|
|
610
|
+
.qt-flink:hover:not(:disabled){background:var(--qt-f-on3)}
|
|
611
|
+
|
|
612
|
+
/* 色场的模型选择:白字按钮 + 往上弹的圆角菜单 */
|
|
613
|
+
.qt-fpick{position:relative;min-width:0;flex:0 1 auto}
|
|
614
|
+
.qt-fpick-btn{height:40px;padding:0 14px;border-radius:12px;background:var(--qt-f-on3);color:var(--qt-f-on);display:inline-flex;align-items:center;gap:8px;font-size:13.5px;white-space:nowrap;max-width:100%;transition:background .15s}
|
|
615
|
+
.qt-fpick-btn:hover:not(:disabled),.qt-fpick-btn[aria-expanded="true"]{background:rgba(255,255,255,.28)}
|
|
616
|
+
.qt-fpick-btn:disabled{opacity:.5}
|
|
617
|
+
.qt-fpick-k,.qt-fpick-tag{color:var(--qt-f-on2);flex:none}
|
|
618
|
+
.qt-fpick-label{font-weight:600;overflow:hidden;text-overflow:ellipsis;min-width:0}
|
|
619
|
+
.qt-fpick-btn svg{flex:none;transition:transform .2s var(--qt-ease)}
|
|
620
|
+
.qt-fpick-btn[aria-expanded="true"] svg{transform:rotate(180deg)}
|
|
621
|
+
.qt-fmenu{position:absolute;left:0;bottom:calc(100% + 10px);z-index:30;width:336px;max-height:420px;overflow:auto;padding:16px 8px 8px;background:var(--qt-f-ov);color:var(--qt-f-ink);border:1px solid var(--qt-f-b1);border-radius:20px;box-shadow:0 24px 60px -16px rgba(0,0,0,.28),0 2px 8px rgba(0,0,0,.06);animation:qt-fade .15s ease}
|
|
622
|
+
.qt-fmenu-head{display:flex;align-items:baseline;justify-content:space-between;gap:12px;padding:0 12px 8px}
|
|
623
|
+
.qt-fmenu-head b{font-size:15px;font-weight:600}
|
|
624
|
+
.qt-fmenu-head span{font-size:12px;color:var(--qt-f-mute)}
|
|
625
|
+
.qt-fmi{display:flex;align-items:center;gap:10px;width:100%;height:40px;padding:0 12px;border-radius:10px;font-size:13.5px;text-align:left;white-space:nowrap;color:var(--qt-f-ink)}
|
|
626
|
+
.qt-fmi:hover{background:var(--qt-f-l1)}
|
|
627
|
+
.qt-fmi[aria-selected="true"]{background:var(--qt-f-l2);font-weight:600}
|
|
628
|
+
.qt-fmi .qt-check{width:16px;flex:none;color:var(--qt-f-brand);visibility:hidden;display:inline-flex}
|
|
629
|
+
.qt-fmi[aria-selected="true"] .qt-check{visibility:visible}
|
|
630
|
+
.qt-fmi .qt-name{overflow:hidden;text-overflow:ellipsis;min-width:0}
|
|
631
|
+
.qt-fmi .qt-id{margin-left:auto;font-family:var(--qt-f-mono);font-size:11px;font-weight:400;color:var(--qt-f-mute);overflow:hidden;text-overflow:ellipsis;max-width:46%}
|
|
632
|
+
.qt-fmg{padding:12px 12px 4px;font-size:11.5px;font-weight:600;color:var(--qt-f-mute)}
|
|
633
|
+
.qt-fmenu-empty{padding:10px 12px;font-size:12.5px;color:var(--qt-f-mute)}
|
|
634
|
+
|
|
635
|
+
/* 色场的历史:一张和译文容器同样大的卡,盖在译文的位置上;头尾固定,中间单独滚动 */
|
|
636
|
+
.qt-fhist{position:absolute;left:596px;top:8px;width:580px;height:664px;border-radius:28px;background:var(--qt-f-ov);color:var(--qt-f-ink);box-shadow:inset 0 0 0 1px var(--qt-f-b1),0 24px 60px -24px rgba(0,0,0,.22);display:flex;flex-direction:column;overflow:hidden;z-index:6;animation:qt-fade .18s ease}
|
|
637
|
+
.qt-fhist-head{display:flex;align-items:center;gap:12px;height:68px;padding:28px 28px 0 36px;flex:none;min-width:0}
|
|
638
|
+
.qt-fhist-head b{font-size:20px;font-weight:600;white-space:nowrap}
|
|
639
|
+
.qt-fhist-head > span{font-size:12.5px;color:var(--qt-f-mute);margin-right:auto;white-space:nowrap}
|
|
640
|
+
.qt-fhist-search{width:240px;min-width:0;height:36px;border-radius:10px;background:var(--qt-f-l1);box-shadow:inset 0 0 0 1px var(--qt-f-b1);display:flex;align-items:center;gap:8px;padding:0 12px;color:var(--qt-f-mute)}
|
|
641
|
+
.qt-fhist-search svg{flex:none}
|
|
642
|
+
.qt-fhist-search input{flex:1;min-width:0;border:0;outline:0;background:none;font-size:13px;color:var(--qt-f-ink)}
|
|
643
|
+
.qt-fhist-search input::placeholder{color:var(--qt-f-mute)}
|
|
644
|
+
.qt-fhist-search:focus-within{box-shadow:inset 0 0 0 1.5px var(--qt-f-brand)}
|
|
645
|
+
.qt-ficon{width:36px;height:36px;border-radius:10px;display:grid;place-items:center;color:var(--qt-f-mute);flex:none}
|
|
646
|
+
.qt-ficon:hover{background:var(--qt-f-l2);color:var(--qt-f-ink)}
|
|
647
|
+
.qt-fhist-rule{height:1px;background:var(--qt-f-b1);margin-top:20px;flex:none}
|
|
648
|
+
.qt-fhist-scroll{flex:1;min-height:0;position:relative}
|
|
649
|
+
.qt-fhist-list{position:absolute;inset:0;overflow-y:auto;padding:0 24px 24px 20px;scrollbar-width:none}
|
|
650
|
+
.qt-fhist-list::-webkit-scrollbar{display:none}
|
|
651
|
+
.qt-fhday{position:sticky;top:0;z-index:2;background:var(--qt-f-ov);padding:16px 12px 6px;font-size:12px;font-weight:600;color:var(--qt-f-mute)}
|
|
652
|
+
.qt-fhi-wrap{position:relative;margin-bottom:2px}
|
|
653
|
+
.qt-fhi{display:grid;grid-template-columns:44px minmax(0,1fr) 112px;column-gap:14px;align-items:start;width:100%;text-align:left;padding:14px 14px 14px 12px;border-radius:14px;color:var(--qt-f-ink);transition:background .12s}
|
|
654
|
+
.qt-fhi-wrap:hover .qt-fhi{background:var(--qt-f-l2)}
|
|
655
|
+
.qt-fhi[aria-current="true"],.qt-fhi-wrap:hover .qt-fhi[aria-current="true"]{background:color-mix(in srgb,var(--qt-f-brand) 10%,transparent)}
|
|
656
|
+
.qt-fhi-time{font-size:12px;color:var(--qt-f-mute);padding-top:3px;font-variant-numeric:tabular-nums}
|
|
657
|
+
.qt-fhi-main{display:flex;flex-direction:column;gap:4px;min-width:0}
|
|
658
|
+
.qt-fhi-dst{font-family:var(--qt-zh-serif);font-size:15px;line-height:1.55;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;word-break:break-word;white-space:pre-line}
|
|
659
|
+
.qt-fhi-dst[data-lang="en"]{font-family:var(--qt-en-serif)}
|
|
660
|
+
.qt-fhi-src{font-size:12.5px;color:var(--qt-f-mute);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
661
|
+
.qt-fhi-meta{display:flex;flex-direction:column;align-items:flex-end;gap:3px;font-size:11.5px;color:var(--qt-f-mute);padding-top:3px;white-space:nowrap;overflow:hidden;min-width:0}
|
|
662
|
+
.qt-fhi-meta span{max-width:100%;overflow:hidden;text-overflow:ellipsis}
|
|
663
|
+
.qt-fhi-wrap:hover .qt-fhi-meta{visibility:hidden}
|
|
664
|
+
.qt-fhi-del{position:absolute;right:12px;top:14px;width:26px;height:26px;border-radius:8px;display:grid;place-items:center;color:var(--qt-f-mute);background:var(--qt-f-base);opacity:0;pointer-events:none}
|
|
665
|
+
.qt-fhi-wrap:hover .qt-fhi-del,.qt-fhi-del:focus-visible{opacity:1;pointer-events:auto}
|
|
666
|
+
.qt-fhi-del:hover{color:var(--qt-f-err)}
|
|
667
|
+
.qt-fempty{padding:56px 12px;text-align:center;font-size:13px;line-height:1.8;color:var(--qt-f-mute);white-space:pre-line}
|
|
668
|
+
.qt-ffade-top,.qt-ffade-bot{position:absolute;left:0;right:0;pointer-events:none;z-index:3}
|
|
669
|
+
.qt-ffade-top{top:38px;height:36px;background:linear-gradient(var(--qt-f-ov),transparent)}
|
|
670
|
+
.qt-ffade-bot{bottom:0;height:64px;background:linear-gradient(transparent,var(--qt-f-ov))}
|
|
671
|
+
.qt-fthumb{position:absolute;right:8px;top:10px;bottom:10px;width:4px;pointer-events:none;z-index:4}
|
|
672
|
+
.qt-fthumb i{position:absolute;left:0;right:0;border-radius:2px;background:var(--qt-f-b2)}
|
|
673
|
+
.qt-fhist-foot{display:flex;align-items:center;justify-content:space-between;gap:12px;height:65px;padding:0 28px 4px 26px;border-top:1px solid var(--qt-f-b1);flex:none;font-size:12px;color:var(--qt-f-mute);white-space:nowrap}
|
|
674
|
+
.qt-fhist-foot > span{overflow:hidden;text-overflow:ellipsis;min-width:0}
|
|
675
|
+
.qt-fhist-clear{height:34px;padding:0 10px;border-radius:9px;font-size:13px;color:var(--qt-f-mute);flex:none}
|
|
676
|
+
.qt-fhist-clear:hover{background:var(--qt-f-l2);color:var(--qt-f-ink)}
|
|
677
|
+
.qt-fhist-clear.is-armed{color:var(--qt-f-err)}
|
|
678
|
+
|
|
679
|
+
/* 色场:没有模型 */
|
|
680
|
+
.qt-fempty-card{max-width:440px;margin:24px;padding:32px 36px;border-radius:28px;background:var(--qt-f-l1);box-shadow:inset 0 0 0 1px var(--qt-f-b1);display:flex;flex-direction:column;align-items:flex-start;gap:14px}
|
|
681
|
+
.qt-fempty-card b{font-size:18px;font-weight:600}
|
|
682
|
+
.qt-fempty-card p{margin:0;font-size:13.5px;line-height:1.7;color:var(--qt-f-mute);white-space:pre-line}
|
|
683
|
+
.qt-fempty-card .qt-fgo{padding:0 20px}
|
|
684
|
+
|
|
685
|
+
/* 分享浮层在色场下的按钮 */
|
|
686
|
+
.qt-fsbtn{height:44px;padding:0 22px;border-radius:14px;font-size:14.5px;font-weight:600;white-space:nowrap}
|
|
687
|
+
.qt-fsbtn-primary{background:var(--qt-f-brand);color:#fff}
|
|
688
|
+
.qt-fsbtn-secondary{background:#fff;color:#1d1d22}
|
|
689
|
+
.qt-fsbtn:disabled{opacity:.45}
|
|
690
|
+
.qt-share-bar .qt-fhb{color:#e6e3dc}
|
|
691
|
+
.qt-share-bar .qt-fhb:hover{background:rgba(255,255,255,.12);color:#fff}
|
|
692
|
+
|
|
693
|
+
/* 色场窄面板(< 760):上下叠放、不缩放,尺寸照画板「F 色场 · 窄面板 440」 */
|
|
694
|
+
.qt-fhead.is-narrow{height:calc(56px + var(--dsh-frame-top-clearance,0px));gap:6px;padding-right:12px;padding-left:calc(16px + var(--dsh-frame-leading-clearance,0px))}
|
|
695
|
+
.qt-fhead.is-narrow .qt-ftitle{font-size:15px;margin-right:auto}
|
|
696
|
+
.qt-fhead.is-narrow .qt-fsub{display:none}
|
|
697
|
+
.qt-fhead.is-narrow .qt-ftrack button{padding:0 10px;gap:6px}
|
|
698
|
+
.qt-fhead.is-narrow .qt-fhb{padding:0 10px;gap:6px}
|
|
699
|
+
.qt-fboard.is-narrow{align-items:flex-start;overflow-y:auto}
|
|
700
|
+
.qt-fcomp.is-narrow{width:100%;height:auto;padding:0 16px 16px;display:flex;flex-direction:column}
|
|
701
|
+
.qt-fcomp.is-narrow .qt-fbox,.qt-fcomp.is-narrow .qt-fhist{position:relative;left:auto;top:auto;width:auto;flex:none;border-radius:24px}
|
|
702
|
+
.qt-fcomp.is-narrow .qt-fsrc{height:360px;padding:22px 22px 18px 24px}
|
|
703
|
+
.qt-fcomp.is-narrow .qt-ffield{height:452px;padding:30px 22px 18px 24px}
|
|
704
|
+
.qt-fcomp.is-narrow .qt-fhist{height:452px}
|
|
705
|
+
.qt-fcomp.is-narrow .qt-frow{height:34px;gap:10px}
|
|
706
|
+
.qt-fcomp.is-narrow .qt-flang{font-size:24px}
|
|
707
|
+
.qt-fcomp.is-narrow .qt-fsrc .qt-fhint{display:none}
|
|
708
|
+
.qt-fcomp.is-narrow .qt-fsrc .qt-frow .qt-ftrack{margin-left:auto}
|
|
709
|
+
.qt-fcomp.is-narrow .qt-ftrack button{padding:0 10px}
|
|
710
|
+
.qt-fcomp.is-narrow .qt-fta{margin-top:18px}
|
|
711
|
+
.qt-fcomp.is-narrow .qt-fsrc .qt-fta{font-size:16px;line-height:1.7}
|
|
712
|
+
.qt-fcomp.is-narrow .qt-fres{font-size:21px}
|
|
713
|
+
.qt-fcomp.is-narrow .qt-fwait{inset:18px 0 0}
|
|
714
|
+
.qt-fcomp.is-narrow .qt-fwait b{font-size:36px}
|
|
715
|
+
.qt-fcomp.is-narrow .qt-fwm{font-size:340px;right:-40px;bottom:-96px}
|
|
716
|
+
.qt-fcomp.is-narrow .qt-fstats{gap:14px;padding-bottom:10px}
|
|
717
|
+
.qt-fcomp.is-narrow .qt-ffoot{height:44px;gap:4px}
|
|
718
|
+
.qt-fcomp.is-narrow .qt-fclear{padding:0 14px}
|
|
719
|
+
.qt-fcomp.is-narrow .qt-fgo{padding-left:18px;gap:10px}
|
|
720
|
+
.qt-fcomp.is-narrow .qt-fpick-btn{padding:0 12px;gap:6px;font-size:13px}
|
|
721
|
+
.qt-fcomp.is-narrow .qt-fpick-k{display:none}
|
|
722
|
+
.qt-fcomp.is-narrow .qt-flink{padding:0 10px;font-size:13px}
|
|
723
|
+
.qt-fcomp.is-narrow .qt-fcopy{padding:0 16px;font-size:13px}
|
|
724
|
+
.qt-fcomp.is-narrow .qt-fswap{position:relative;left:auto;top:auto;align-self:center;margin:-16px 0;width:48px;height:48px;flex:none}
|
|
725
|
+
.qt-fcomp.is-narrow .qt-fswap svg{transform:rotate(90deg)}
|
|
726
|
+
.qt-fcomp.is-narrow .qt-fmenu{width:min(336px,calc(100vw - 72px))}
|
|
727
|
+
.qt-fcomp.is-narrow .qt-fhist-head{height:58px;padding:22px 16px 0 20px;gap:8px}
|
|
728
|
+
.qt-fcomp.is-narrow .qt-fhist-head > span{display:none}
|
|
729
|
+
.qt-fcomp.is-narrow .qt-fhist-search{flex:1;width:auto}
|
|
730
|
+
.qt-fcomp.is-narrow .qt-fhist-rule{margin-top:14px}
|
|
731
|
+
.qt-fcomp.is-narrow .qt-fhist-list{padding:0 16px 20px 10px}
|
|
732
|
+
.qt-fcomp.is-narrow .qt-fhi{grid-template-columns:40px minmax(0,1fr);column-gap:10px}
|
|
733
|
+
.qt-fcomp.is-narrow .qt-fhi-meta{display:none}
|
|
734
|
+
.qt-fcomp.is-narrow .qt-fhist-foot{height:56px;padding:0 20px 2px 14px}
|
|
735
|
+
@media (prefers-reduced-motion:reduce){.qt-root *,.qt-root *::before,.qt-root *::after{animation:none!important;transition:none!important}}
|
|
736
|
+
`
|
|
737
|
+
|
|
738
|
+
function ensureStyle() {
|
|
739
|
+
const tagId = 'dsh-quick-translate/style.css'
|
|
740
|
+
let tag = document.querySelector(`style[data-plugin-css="${tagId}"]`)
|
|
741
|
+
if (!tag) {
|
|
742
|
+
tag = document.createElement('style')
|
|
743
|
+
tag.dataset.plugin = 'dsh-quick-translate'
|
|
744
|
+
tag.dataset.pluginCss = tagId
|
|
745
|
+
tag.textContent = CSS
|
|
746
|
+
document.head.appendChild(tag)
|
|
747
|
+
}
|
|
748
|
+
return tag
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/* ============================== 工具 ================================ */
|
|
752
|
+
|
|
753
|
+
function readJson(key, fallback) {
|
|
754
|
+
try {
|
|
755
|
+
const raw = localStorage.getItem(key)
|
|
756
|
+
const value = raw ? JSON.parse(raw) : fallback
|
|
757
|
+
return value === undefined || value === null ? fallback : value
|
|
758
|
+
} catch {
|
|
759
|
+
return fallback
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
function writeJson(key, value) {
|
|
764
|
+
try {
|
|
765
|
+
localStorage.setItem(key, JSON.stringify(value))
|
|
766
|
+
} catch {
|
|
767
|
+
/* 隐私模式或配额满:忽略,不影响使用 */
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
function modelKey(entry) {
|
|
772
|
+
return `${entry.provider}${SEP}${entry.model}`
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
function parseKey(key) {
|
|
776
|
+
if (typeof key !== 'string') return null
|
|
777
|
+
const i = key.indexOf(SEP)
|
|
778
|
+
return i < 0 ? null : { provider: key.slice(0, i), model: key.slice(i + 1) }
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// 自动模式:汉字够多就译成英文,否则译成中文(英文句里夹几个中文词名仍译成中文)。只看前 2000 个字符
|
|
782
|
+
function resolveTarget(direction, text) {
|
|
783
|
+
if (direction === 'en2zh') return 'zh'
|
|
784
|
+
if (direction === 'zh2en') return 'en'
|
|
785
|
+
let han = 0
|
|
786
|
+
let latin = 0
|
|
787
|
+
let seen = 0
|
|
788
|
+
for (const ch of text) {
|
|
789
|
+
if (++seen > 2000) break
|
|
790
|
+
if (/\p{Script=Han}/u.test(ch)) han++
|
|
791
|
+
else if (/\p{Script=Latin}/u.test(ch)) latin++
|
|
792
|
+
}
|
|
793
|
+
return han >= 1 && han >= latin / 3 ? 'en' : 'zh'
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
async function fetchModels(refresh) {
|
|
797
|
+
const url = new URL(`${API}/models${refresh ? '?refresh=1' : ''}`, document.baseURI)
|
|
798
|
+
const response = await fetch(url, { credentials: 'same-origin' })
|
|
799
|
+
let payload = null
|
|
800
|
+
try {
|
|
801
|
+
payload = await response.json()
|
|
802
|
+
} catch {
|
|
803
|
+
payload = null
|
|
804
|
+
}
|
|
805
|
+
if (!response.ok || !payload || payload.ok === false) {
|
|
806
|
+
throw new Error((payload && (payload.message || payload.error)) || `HTTP ${response.status}`)
|
|
807
|
+
}
|
|
808
|
+
return payload
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// 读 Host 的 SSE 流:meta → delta* → done | error
|
|
812
|
+
async function streamTranslate({ text, target, provider, model, onMeta, onDelta, signal }) {
|
|
813
|
+
const response = await fetch(new URL(`${API}/translate`, document.baseURI), {
|
|
814
|
+
method: 'POST',
|
|
815
|
+
credentials: 'same-origin',
|
|
816
|
+
headers: { 'Content-Type': 'application/json' },
|
|
817
|
+
body: JSON.stringify({ text, target, provider, model }),
|
|
818
|
+
signal,
|
|
819
|
+
})
|
|
820
|
+
if (!response.ok || !response.body) {
|
|
821
|
+
let payload = null
|
|
822
|
+
try {
|
|
823
|
+
payload = await response.json()
|
|
824
|
+
} catch {
|
|
825
|
+
payload = null
|
|
826
|
+
}
|
|
827
|
+
throw new Error((payload && (payload.message || payload.error)) || `HTTP ${response.status}`)
|
|
828
|
+
}
|
|
829
|
+
const reader = response.body.getReader()
|
|
830
|
+
const decoder = new TextDecoder()
|
|
831
|
+
let buffer = ''
|
|
832
|
+
let done = null
|
|
833
|
+
const handleBlock = (block) => {
|
|
834
|
+
for (const line of block.split('\n')) {
|
|
835
|
+
if (!line.startsWith('data:')) continue
|
|
836
|
+
let event
|
|
837
|
+
try {
|
|
838
|
+
event = JSON.parse(line.slice(5).trim())
|
|
839
|
+
} catch {
|
|
840
|
+
continue
|
|
841
|
+
}
|
|
842
|
+
if (event.type === 'meta') onMeta?.(event)
|
|
843
|
+
else if (event.type === 'delta') onDelta?.(String(event.text || ''))
|
|
844
|
+
else if (event.type === 'error') {
|
|
845
|
+
const error = new Error(event.message || 'unknown')
|
|
846
|
+
error.cancelled = Boolean(event.cancelled)
|
|
847
|
+
throw error
|
|
848
|
+
} else if (event.type === 'done') done = event
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
for (;;) {
|
|
852
|
+
const { value, done: finished } = await reader.read()
|
|
853
|
+
if (finished) break
|
|
854
|
+
buffer += decoder.decode(value, { stream: true })
|
|
855
|
+
let idx
|
|
856
|
+
while ((idx = buffer.indexOf('\n\n')) >= 0) {
|
|
857
|
+
const block = buffer.slice(0, idx)
|
|
858
|
+
buffer = buffer.slice(idx + 2)
|
|
859
|
+
handleBlock(block)
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
buffer += decoder.decode()
|
|
863
|
+
if (buffer.trim()) handleBlock(buffer)
|
|
864
|
+
if (!done) throw new Error('__stream_broken__')
|
|
865
|
+
return done
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// 耗时文案;不足 1 秒显示毫秒
|
|
869
|
+
function fmtElapsed(ms, t) {
|
|
870
|
+
if (!ms || !(ms > 0)) return `0 ${t.seconds}`
|
|
871
|
+
return ms < 1000 ? `${Math.round(ms)} ms` : `${(ms / 1000).toFixed(1)} ${t.seconds}`
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// 相对时间
|
|
875
|
+
function relTime(ts, t) {
|
|
876
|
+
const diff = Date.now() - Number(ts || 0)
|
|
877
|
+
const m = Math.floor(diff / 60000)
|
|
878
|
+
if (m < 1) return t.justNow
|
|
879
|
+
if (m < 60) return t.minutesAgo(m)
|
|
880
|
+
const hrs = Math.floor(m / 60)
|
|
881
|
+
if (hrs < 24) return t.hoursAgo(hrs)
|
|
882
|
+
const d = new Date(ts)
|
|
883
|
+
const now = new Date()
|
|
884
|
+
const day = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime()
|
|
885
|
+
if (Math.round((day(now) - day(d)) / 86400000) === 1) return t.yesterday
|
|
886
|
+
return `${d.getMonth() + 1}/${d.getDate()}`
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// 历史只保留结构完整的条目,并限制条数和总体积
|
|
890
|
+
function sanitizeHistory(list) {
|
|
891
|
+
if (!Array.isArray(list)) return []
|
|
892
|
+
const out = []
|
|
893
|
+
let total = 0
|
|
894
|
+
for (const e of list) {
|
|
895
|
+
if (!e || typeof e.source !== 'string' || typeof e.result !== 'string') continue
|
|
896
|
+
total += e.source.length + e.result.length
|
|
897
|
+
if (out.length >= HISTORY_MAX || total > HISTORY_MAX_CHARS) break
|
|
898
|
+
out.push({
|
|
899
|
+
id: typeof e.id === 'string' ? e.id : `${Number(e.at) || Date.now()}-${out.length}`,
|
|
900
|
+
source: e.source,
|
|
901
|
+
result: e.result,
|
|
902
|
+
target: e.target === 'en' ? 'en' : 'zh',
|
|
903
|
+
provider: String(e.provider || ''),
|
|
904
|
+
model: String(e.model || ''),
|
|
905
|
+
modelName: String(e.modelName || e.model || ''),
|
|
906
|
+
at: Number(e.at) || Date.now(),
|
|
907
|
+
elapsedMs: Number(e.elapsedMs) || 0,
|
|
908
|
+
truncated: Boolean(e.truncated),
|
|
909
|
+
})
|
|
910
|
+
}
|
|
911
|
+
return out
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
// 新条目放最前;最新一条若原文、目标语言、模型都相同,就替换而不是再堆一条
|
|
915
|
+
function pushHistory(list, entry) {
|
|
916
|
+
const rest = list.filter((e, i) => !(i === 0 && e.source === entry.source && e.target === entry.target && e.model === entry.model))
|
|
917
|
+
return sanitizeHistory([entry, ...rest])
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
function groupModels(list) {
|
|
921
|
+
const map = new Map()
|
|
922
|
+
for (const m of list) {
|
|
923
|
+
const key = m.provider
|
|
924
|
+
if (!map.has(key)) map.set(key, { provider: key, name: m.providerName || key, models: [] })
|
|
925
|
+
map.get(key).models.push(m)
|
|
926
|
+
}
|
|
927
|
+
return [...map.values()]
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/* ============================== 图形 ================================ */
|
|
931
|
+
|
|
932
|
+
const svgProps = { fill: 'none', stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true }
|
|
933
|
+
const P = (...d) => d.map((dd) => h('path', { d: dd }))
|
|
934
|
+
|
|
935
|
+
// 侧栏图标:DSH 侧栏里和其它插件并排,保持 Lucide 线条风格
|
|
936
|
+
function TranslateIcon({ size = 18 }) {
|
|
937
|
+
return h('svg', { ...svgProps, width: size, height: size, viewBox: '0 0 24 24' }, ...P('m5 8 6 6', 'm4 14 6-6 2-3', 'M2 5h12', 'M7 2h1', 'm22 22-5-10-5 10', 'M14 18h6'))
|
|
938
|
+
}
|
|
939
|
+
// 索引卡上的手写勾
|
|
940
|
+
function TickMark() {
|
|
941
|
+
return h('svg', { viewBox: '0 0 24 24', width: 18, height: 18, 'aria-hidden': true }, h('path', { d: 'M3 13c3 1 5 4 6 6 3-7 7-12 13-16', fill: 'none', stroke: 'currentColor', strokeWidth: 2.4, strokeLinecap: 'round' }))
|
|
942
|
+
}
|
|
943
|
+
// 模型名旁的手写签名(装饰)
|
|
944
|
+
function Signature() {
|
|
945
|
+
return h('svg', { className: 'qt-sign', viewBox: '0 0 120 40', 'aria-hidden': true }, h('path', { d: 'M4 30c10-2 14-22 22-20s-8 22 2 20 10-18 18-16-4 14 4 13 12-12 20-11 2 9 10 8 18-14 34-18', fill: 'none', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round' }))
|
|
946
|
+
}
|
|
947
|
+
// 完成时盖的「已译」章
|
|
948
|
+
function Stamp({ label, arrow }) {
|
|
949
|
+
return h(
|
|
950
|
+
'svg',
|
|
951
|
+
{ className: 'qt-stamp', viewBox: '0 0 140 140', 'aria-hidden': true },
|
|
952
|
+
h('defs', null, h('path', { id: 'qt-stamp-ring', d: 'M70 70 m-52 0 a52 52 0 1 1 104 0 a52 52 0 1 1 -104 0' })),
|
|
953
|
+
h('circle', { cx: 70, cy: 70, r: 66, fill: 'none', stroke: 'currentColor', strokeWidth: 3, strokeDasharray: '60 2 30 3 90 1' }),
|
|
954
|
+
h('circle', { cx: 70, cy: 70, r: 40, fill: 'none', stroke: 'currentColor', strokeWidth: 1.5 }),
|
|
955
|
+
h('text', { fontFamily: 'IBM Plex Mono, ui-monospace, monospace', fontSize: 11, letterSpacing: 3, fill: 'currentColor' }, h('textPath', { href: '#qt-stamp-ring' }, `TRANSLATED ✦ DSH ✦ ${arrow} ✦ QUICK ✦`)),
|
|
956
|
+
h('text', { x: 70, y: 80, textAnchor: 'middle', fontFamily: 'PingFang SC, Noto Sans SC, sans-serif', fontWeight: 900, fontSize: label.length > 2 ? 22 : 28, fill: 'currentColor' }, label),
|
|
957
|
+
)
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
// 色场风格用的几枚线条图标(纸本风格不用)
|
|
961
|
+
const icon = (size, ...d) => h('svg', { ...svgProps, width: size, height: size, viewBox: '0 0 24 24', strokeWidth: 2 }, ...P(...d))
|
|
962
|
+
const SwapIcon = () => icon(18, 'm16 3 4 4-4 4', 'M20 7H4', 'm8 21-4-4 4-4', 'M4 17h16')
|
|
963
|
+
const RefreshIcon = () => icon(15, 'M21 12a9 9 0 1 1-3-6.7L21 8', 'M21 3v5h-5')
|
|
964
|
+
const SearchIcon = () => h('svg', { ...svgProps, width: 14, height: 14, viewBox: '0 0 24 24', strokeWidth: 2 }, h('circle', { cx: 11, cy: 11, r: 7 }), h('path', { d: 'm20 20-3.5-3.5' }))
|
|
965
|
+
const CloseIcon = ({ size = 14 }) => h('svg', { ...svgProps, width: size, height: size, viewBox: '0 0 24 24', strokeWidth: 2.3 }, h('path', { d: 'M6 6l12 12M18 6 6 18' }))
|
|
966
|
+
const CheckIcon = () => h('svg', { ...svgProps, width: 16, height: 16, viewBox: '0 0 24 24', strokeWidth: 2.6 }, h('path', { d: 'm5 12.5 4.5 4.5L19 7' }))
|
|
967
|
+
const ChevronIcon = () => h('svg', { ...svgProps, width: 12, height: 12, viewBox: '0 0 24 24', strokeWidth: 2.4 }, h('path', { d: 'm6 9 6 6 6-6' }))
|
|
968
|
+
// 语言在色场里用它自己的名字写:English / 中文
|
|
969
|
+
const nativeName = (code) => (code === 'en' ? 'English' : '中文')
|
|
970
|
+
|
|
971
|
+
const MONTHS = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
|
|
972
|
+
const pad2 = (n) => String(n).padStart(2, '0')
|
|
973
|
+
const fmtClock = (ts) => { const d = new Date(ts); return `${pad2(d.getHours())}:${pad2(d.getMinutes())}` }
|
|
974
|
+
// 历史小票的日期分组:今天 / 昨天 / 11 月 21 日
|
|
975
|
+
function dayLabel(ts, t, lang) {
|
|
976
|
+
const d = new Date(ts)
|
|
977
|
+
const day = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime()
|
|
978
|
+
const diff = Math.round((day(new Date()) - day(d)) / 86400000)
|
|
979
|
+
if (diff <= 0) return t.today
|
|
980
|
+
if (diff === 1) return t.yesterday
|
|
981
|
+
return lang === 'zh' ? `${d.getMonth() + 1} 月 ${d.getDate()} 日` : `${MONTHS[d.getMonth()]} ${d.getDate()}`
|
|
982
|
+
}
|
|
983
|
+
const arrowOf = (target) => (target === 'zh' ? 'EN >>> ZH' : target === 'en' ? 'ZH >>> EN' : '— >>> —')
|
|
984
|
+
|
|
985
|
+
/* ============================== 分享卡片 ============================== */
|
|
986
|
+
|
|
987
|
+
// 用 canvas 把这次翻译画成一张竖版拼贴卡:深色桌面、方格本(原文)、硫酸纸(译文)、美纹纸胶带、「已译」章、条码
|
|
988
|
+
const SHARE_FONTS = {
|
|
989
|
+
mono: '"IBM Plex Mono", "SF Mono", Menlo, monospace',
|
|
990
|
+
grot: '"Inter Tight", "Helvetica Neue", Helvetica, Arial, sans-serif',
|
|
991
|
+
zhSerif: '"Songti SC", "Noto Serif SC", "Source Han Serif SC", serif',
|
|
992
|
+
zhSans: '"PingFang SC", "Noto Sans SC", sans-serif',
|
|
993
|
+
enSerif: '"Iowan Old Style", "Newsreader", Palatino, Georgia, serif',
|
|
994
|
+
}
|
|
995
|
+
const CJK_RE = /[⺀-鿿豈-- -〿]/
|
|
996
|
+
|
|
997
|
+
// 按宽度断行:中文逐字断,英文按词断;超过 maxLines 截断并补省略号
|
|
998
|
+
function wrapLines(ctx, text, maxWidth, maxLines) {
|
|
999
|
+
const out = []
|
|
1000
|
+
const paras = String(text || '').replace(/\r/g, '').split('\n')
|
|
1001
|
+
paras.forEach((para, pi) => {
|
|
1002
|
+
if (!para.trim()) {
|
|
1003
|
+
if (out.length && pi < paras.length - 1 && out[out.length - 1] !== '') out.push('')
|
|
1004
|
+
return
|
|
1005
|
+
}
|
|
1006
|
+
const tokens = para.match(new RegExp(`${CJK_RE.source}|[^\\s\\u2E80-\\u9FFF\\uF900-\\uFAFF\\uFF00-\\uFFEF\\u3000-\\u303F]+|\\s+`, 'g')) || []
|
|
1007
|
+
let line = ''
|
|
1008
|
+
for (const tok of tokens) {
|
|
1009
|
+
if (!line && /^\s+$/.test(tok)) continue
|
|
1010
|
+
if (ctx.measureText(line + tok).width <= maxWidth) {
|
|
1011
|
+
line += tok
|
|
1012
|
+
continue
|
|
1013
|
+
}
|
|
1014
|
+
if (line) out.push(line.trimEnd())
|
|
1015
|
+
line = ''
|
|
1016
|
+
if (/^\s+$/.test(tok)) continue
|
|
1017
|
+
let rest = tok
|
|
1018
|
+
while (ctx.measureText(rest).width > maxWidth && rest.length > 1) {
|
|
1019
|
+
let i = rest.length
|
|
1020
|
+
while (i > 1 && ctx.measureText(rest.slice(0, i)).width > maxWidth) i--
|
|
1021
|
+
out.push(rest.slice(0, i))
|
|
1022
|
+
rest = rest.slice(i)
|
|
1023
|
+
}
|
|
1024
|
+
line = rest
|
|
1025
|
+
}
|
|
1026
|
+
if (line) out.push(line.trimEnd())
|
|
1027
|
+
})
|
|
1028
|
+
while (out.length && out[out.length - 1] === '') out.pop()
|
|
1029
|
+
if (out.length <= maxLines) return { lines: out, truncated: false }
|
|
1030
|
+
const cut = out.slice(0, maxLines)
|
|
1031
|
+
let last = cut[maxLines - 1]
|
|
1032
|
+
while (last && ctx.measureText(`${last}…`).width > maxWidth) last = last.slice(0, -1)
|
|
1033
|
+
cut[maxLines - 1] = `${last}…`
|
|
1034
|
+
return { lines: cut, truncated: true }
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
function grainPattern(ctx, alpha) {
|
|
1038
|
+
const c = document.createElement('canvas')
|
|
1039
|
+
c.width = 180
|
|
1040
|
+
c.height = 180
|
|
1041
|
+
const g = c.getContext('2d')
|
|
1042
|
+
const img = g.createImageData(180, 180)
|
|
1043
|
+
for (let i = 0; i < img.data.length; i += 4) {
|
|
1044
|
+
const v = Math.random() * 255
|
|
1045
|
+
img.data[i] = v
|
|
1046
|
+
img.data[i + 1] = v
|
|
1047
|
+
img.data[i + 2] = v
|
|
1048
|
+
img.data[i + 3] = Math.random() * alpha
|
|
1049
|
+
}
|
|
1050
|
+
g.putImageData(img, 0, 0)
|
|
1051
|
+
return ctx.createPattern(c, 'repeat')
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
async function renderShareCard({ source, result, target, modelName, elapsedMs, t }) {
|
|
1055
|
+
try {
|
|
1056
|
+
await document.fonts?.ready
|
|
1057
|
+
} catch {
|
|
1058
|
+
/* 字体没就绪就用回退字体画 */
|
|
1059
|
+
}
|
|
1060
|
+
const F = SHARE_FONTS
|
|
1061
|
+
const W = 1080
|
|
1062
|
+
const S = 2
|
|
1063
|
+
const toZh = target !== 'en'
|
|
1064
|
+
const measure = document.createElement('canvas').getContext('2d')
|
|
1065
|
+
|
|
1066
|
+
// ---- 排版 ----
|
|
1067
|
+
const padX = 84
|
|
1068
|
+
const noteX = padX
|
|
1069
|
+
const noteW = W - padX * 2
|
|
1070
|
+
const noteY = 196
|
|
1071
|
+
const srcFont = `400 25px ${F.mono}`
|
|
1072
|
+
measure.font = srcFont
|
|
1073
|
+
const src = wrapLines(measure, source, noteW - 128 - 56, 7)
|
|
1074
|
+
const srcLH = 42
|
|
1075
|
+
const noteH = 52 + 24 + 34 + src.lines.length * srcLH + 64
|
|
1076
|
+
|
|
1077
|
+
const velX = padX + 34
|
|
1078
|
+
const velW = noteW - 34
|
|
1079
|
+
const velY = noteY + noteH - 26
|
|
1080
|
+
let size = 46
|
|
1081
|
+
let dst = null
|
|
1082
|
+
for (; size >= 30; size -= 4) {
|
|
1083
|
+
measure.font = toZh ? `600 ${size}px ${F.zhSerif}` : `500 ${size}px ${F.enSerif}`
|
|
1084
|
+
dst = wrapLines(measure, result, velW - 116, 12)
|
|
1085
|
+
if (!dst.truncated && dst.lines.length <= 8) break
|
|
1086
|
+
}
|
|
1087
|
+
size = Math.max(size, 30)
|
|
1088
|
+
const dstFont = toZh ? `600 ${size}px ${F.zhSerif}` : `500 ${size}px ${F.enSerif}`
|
|
1089
|
+
const dstLH = Math.round(size * (toZh ? 1.72 : 1.5))
|
|
1090
|
+
const velH = 58 + 24 + 40 + dst.lines.length * dstLH + 36 + 34 + 56 + 34 + 60
|
|
1091
|
+
const H = Math.max(1180, velY + velH + 150)
|
|
1092
|
+
|
|
1093
|
+
const canvas = document.createElement('canvas')
|
|
1094
|
+
canvas.width = W * S
|
|
1095
|
+
canvas.height = H * S
|
|
1096
|
+
const ctx = canvas.getContext('2d')
|
|
1097
|
+
ctx.scale(S, S)
|
|
1098
|
+
ctx.textBaseline = 'alphabetic'
|
|
1099
|
+
const shadow = (blur, y, a) => {
|
|
1100
|
+
ctx.shadowColor = `rgba(0,0,0,${a})`
|
|
1101
|
+
ctx.shadowBlur = blur
|
|
1102
|
+
ctx.shadowOffsetY = y
|
|
1103
|
+
}
|
|
1104
|
+
const noShadow = () => {
|
|
1105
|
+
ctx.shadowColor = 'transparent'
|
|
1106
|
+
ctx.shadowBlur = 0
|
|
1107
|
+
ctx.shadowOffsetY = 0
|
|
1108
|
+
}
|
|
1109
|
+
const tilt = (x, y, w, h, a) => {
|
|
1110
|
+
ctx.translate(x + w / 2, y + h / 2)
|
|
1111
|
+
ctx.rotate(a)
|
|
1112
|
+
ctx.translate(-(x + w / 2), -(y + h / 2))
|
|
1113
|
+
}
|
|
1114
|
+
const dots = (x1, x2, y, color) => {
|
|
1115
|
+
ctx.fillStyle = color
|
|
1116
|
+
for (let x = x1; x < x2; x += 9) {
|
|
1117
|
+
ctx.beginPath()
|
|
1118
|
+
ctx.arc(x, y, 1.3, 0, Math.PI * 2)
|
|
1119
|
+
ctx.fill()
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
const tape = (x, y, w, a) => {
|
|
1123
|
+
ctx.save()
|
|
1124
|
+
tilt(x, y, w, 34, a)
|
|
1125
|
+
ctx.beginPath()
|
|
1126
|
+
ctx.moveTo(x, y + 3)
|
|
1127
|
+
for (let i = 0; i <= 6; i++) ctx.lineTo(x + i * 3, y + (i % 2 ? 0 : 4))
|
|
1128
|
+
ctx.lineTo(x + w, y)
|
|
1129
|
+
for (let i = 0; i <= 6; i++) ctx.lineTo(x + w - (i % 2 ? 3 : 0), y + i * 5.6)
|
|
1130
|
+
ctx.lineTo(x, y + 34)
|
|
1131
|
+
for (let i = 6; i >= 0; i--) ctx.lineTo(x + (i % 2 ? 3 : 0), y + i * 5.6)
|
|
1132
|
+
ctx.closePath()
|
|
1133
|
+
shadow(4, 2, 0.18)
|
|
1134
|
+
ctx.fillStyle = 'rgba(232,220,186,0.9)'
|
|
1135
|
+
ctx.fill()
|
|
1136
|
+
noShadow()
|
|
1137
|
+
ctx.restore()
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
// ---- 桌面 ----
|
|
1141
|
+
ctx.fillStyle = '#1c1b1a'
|
|
1142
|
+
ctx.fillRect(0, 0, W, H)
|
|
1143
|
+
const vg = ctx.createRadialGradient(W * 0.45, H * 0.38, W * 0.15, W * 0.5, H * 0.5, W)
|
|
1144
|
+
vg.addColorStop(0, 'rgba(255,255,255,0.05)')
|
|
1145
|
+
vg.addColorStop(1, 'rgba(0,0,0,0.5)')
|
|
1146
|
+
ctx.fillStyle = vg
|
|
1147
|
+
ctx.fillRect(0, 0, W, H)
|
|
1148
|
+
ctx.fillStyle = '#e8e5de'
|
|
1149
|
+
ctx.font = `900 54px ${F.grot}`
|
|
1150
|
+
ctx.fillText('Quick Translate', padX, 116)
|
|
1151
|
+
ctx.strokeStyle = '#e8e5de'
|
|
1152
|
+
ctx.lineWidth = 1.2
|
|
1153
|
+
ctx.strokeText('Quick Translate', padX, 116)
|
|
1154
|
+
ctx.font = `500 19px ${F.mono}`
|
|
1155
|
+
ctx.fillStyle = 'rgba(232,229,222,0.5)'
|
|
1156
|
+
ctx.fillText(`[ ${t.title} ] DEEPSEEK HARNESS PLUGIN · BY ${AUTHOR.toUpperCase()}`, padX, 152)
|
|
1157
|
+
ctx.textAlign = 'right'
|
|
1158
|
+
ctx.font = `600 22px ${F.mono}`
|
|
1159
|
+
ctx.fillStyle = 'rgba(232,229,222,0.8)'
|
|
1160
|
+
ctx.fillText(arrowOf(target), W - padX, 116)
|
|
1161
|
+
ctx.textAlign = 'left'
|
|
1162
|
+
|
|
1163
|
+
// ---- 原文:方格本 ----
|
|
1164
|
+
ctx.save()
|
|
1165
|
+
tilt(noteX, noteY, noteW, noteH, -0.009)
|
|
1166
|
+
const torn = () => {
|
|
1167
|
+
ctx.beginPath()
|
|
1168
|
+
ctx.moveTo(noteX, noteY)
|
|
1169
|
+
ctx.lineTo(noteX + noteW, noteY)
|
|
1170
|
+
ctx.lineTo(noteX + noteW, noteY + noteH - 12)
|
|
1171
|
+
const n = 24
|
|
1172
|
+
for (let i = n; i >= 0; i--) ctx.lineTo(noteX + (noteW * i) / n, noteY + noteH - (i % 2 ? 3 : 13) - ((i * 7) % 5))
|
|
1173
|
+
ctx.closePath()
|
|
1174
|
+
}
|
|
1175
|
+
shadow(40, 22, 0.45)
|
|
1176
|
+
ctx.fillStyle = '#eeede7'
|
|
1177
|
+
torn()
|
|
1178
|
+
ctx.fill()
|
|
1179
|
+
noShadow()
|
|
1180
|
+
ctx.save()
|
|
1181
|
+
torn()
|
|
1182
|
+
ctx.clip()
|
|
1183
|
+
ctx.strokeStyle = '#c6d0d8'
|
|
1184
|
+
ctx.lineWidth = 1
|
|
1185
|
+
for (let gx = noteX + 8; gx < noteX + noteW; gx += 28) {
|
|
1186
|
+
ctx.beginPath()
|
|
1187
|
+
ctx.moveTo(gx + 0.5, noteY)
|
|
1188
|
+
ctx.lineTo(gx + 0.5, noteY + noteH)
|
|
1189
|
+
ctx.stroke()
|
|
1190
|
+
}
|
|
1191
|
+
for (let gy = noteY + 14; gy < noteY + noteH; gy += 28) {
|
|
1192
|
+
ctx.beginPath()
|
|
1193
|
+
ctx.moveTo(noteX, gy + 0.5)
|
|
1194
|
+
ctx.lineTo(noteX + noteW, gy + 0.5)
|
|
1195
|
+
ctx.stroke()
|
|
1196
|
+
}
|
|
1197
|
+
ctx.strokeStyle = 'rgba(214,80,60,0.5)'
|
|
1198
|
+
ctx.beginPath()
|
|
1199
|
+
ctx.moveTo(noteX + 98.5, noteY)
|
|
1200
|
+
ctx.lineTo(noteX + 98.5, noteY + noteH)
|
|
1201
|
+
ctx.stroke()
|
|
1202
|
+
ctx.fillStyle = '#1c1b1a'
|
|
1203
|
+
for (let hy = noteY + 24; hy < noteY + noteH - 24; hy += 34) {
|
|
1204
|
+
ctx.beginPath()
|
|
1205
|
+
ctx.arc(noteX + 52, hy, 8.5, 0, Math.PI * 2)
|
|
1206
|
+
ctx.fill()
|
|
1207
|
+
}
|
|
1208
|
+
ctx.restore()
|
|
1209
|
+
ctx.fillStyle = '#121212'
|
|
1210
|
+
for (let hy = noteY + 16; hy < noteY + noteH - 30; hy += 34) ctx.fillRect(noteX - 8, hy, 26, 15)
|
|
1211
|
+
const tx = noteX + 128
|
|
1212
|
+
ctx.fillStyle = '#34363d'
|
|
1213
|
+
ctx.font = `500 18px ${F.mono}`
|
|
1214
|
+
ctx.fillText(`${t.source} / SOURCE`, tx, noteY + 52)
|
|
1215
|
+
ctx.textAlign = 'right'
|
|
1216
|
+
ctx.fillText(toZh ? 'EN' : 'ZH', noteX + noteW - 56, noteY + 52)
|
|
1217
|
+
ctx.textAlign = 'left'
|
|
1218
|
+
dots(tx, noteX + noteW - 56, noteY + 76, 'rgba(52,54,61,0.5)')
|
|
1219
|
+
ctx.fillStyle = '#1b1b1b'
|
|
1220
|
+
ctx.font = srcFont
|
|
1221
|
+
src.lines.forEach((ln, i) => ctx.fillText(ln, tx, noteY + 52 + 24 + 34 + 26 + i * srcLH))
|
|
1222
|
+
ctx.restore()
|
|
1223
|
+
|
|
1224
|
+
// ---- 译文:硫酸纸 ----
|
|
1225
|
+
ctx.save()
|
|
1226
|
+
tilt(velX, velY, velW, velH, 0.007)
|
|
1227
|
+
shadow(60, 30, 0.5)
|
|
1228
|
+
ctx.fillStyle = 'rgba(229,230,226,0.985)'
|
|
1229
|
+
ctx.fillRect(velX, velY, velW, velH)
|
|
1230
|
+
noShadow()
|
|
1231
|
+
const vx = velX + 58
|
|
1232
|
+
const vr = velX + velW - 58
|
|
1233
|
+
const indigo = '#41468a'
|
|
1234
|
+
ctx.fillStyle = indigo
|
|
1235
|
+
ctx.font = `500 18px ${F.mono}`
|
|
1236
|
+
ctx.fillText(`${t.result} / TRANSLATION`, vx, velY + 58)
|
|
1237
|
+
ctx.textAlign = 'right'
|
|
1238
|
+
ctx.fillText(elapsedMs ? `${t.done} ${fmtElapsed(elapsedMs, t)}` : t.done, vr, velY + 58)
|
|
1239
|
+
ctx.textAlign = 'left'
|
|
1240
|
+
dots(vx, vr, velY + 82, 'rgba(65,70,138,0.5)')
|
|
1241
|
+
ctx.font = dstFont
|
|
1242
|
+
ctx.fillStyle = indigo
|
|
1243
|
+
const dy0 = velY + 82 + 40 + size
|
|
1244
|
+
dst.lines.forEach((ln, i) => ctx.fillText(ln, vx, dy0 + i * dstLH))
|
|
1245
|
+
let y = dy0 + (dst.lines.length - 1) * dstLH + 46
|
|
1246
|
+
dots(vx, vr, y, 'rgba(65,70,138,0.5)')
|
|
1247
|
+
y += 50
|
|
1248
|
+
ctx.font = `500 17px ${F.mono}`
|
|
1249
|
+
ctx.fillText('MODEL:', vx, y)
|
|
1250
|
+
ctx.font = `800 27px ${F.grot}`
|
|
1251
|
+
ctx.fillText(modelName || '—', vx + 82, y + 1)
|
|
1252
|
+
y += 30
|
|
1253
|
+
const barY = y
|
|
1254
|
+
let seed = 0
|
|
1255
|
+
for (const ch of String(result)) seed = (seed * 31 + ch.charCodeAt(0)) >>> 0
|
|
1256
|
+
ctx.fillStyle = indigo
|
|
1257
|
+
for (let x = vx; x < vr - 196; ) {
|
|
1258
|
+
seed = (seed * 1103515245 + 12345) >>> 0
|
|
1259
|
+
const w = 1 + (seed % 3)
|
|
1260
|
+
ctx.fillRect(x, y, w, 34)
|
|
1261
|
+
x += w + 2 + ((seed >> 4) % 4)
|
|
1262
|
+
}
|
|
1263
|
+
ctx.restore()
|
|
1264
|
+
tape(velX - 26, velY - 14, 126, -0.16)
|
|
1265
|
+
tape(velX + velW - 104, velY - 10, 116, 0.12)
|
|
1266
|
+
|
|
1267
|
+
// 「已译」章
|
|
1268
|
+
ctx.save()
|
|
1269
|
+
const cx = velX + velW - 58 - 92
|
|
1270
|
+
const cy = barY + 2
|
|
1271
|
+
ctx.translate(cx, cy)
|
|
1272
|
+
ctx.rotate(-0.26)
|
|
1273
|
+
ctx.globalAlpha = 0.66
|
|
1274
|
+
ctx.strokeStyle = '#3a3fa6'
|
|
1275
|
+
ctx.fillStyle = '#3a3fa6'
|
|
1276
|
+
ctx.lineWidth = 4
|
|
1277
|
+
ctx.beginPath()
|
|
1278
|
+
ctx.arc(0, 0, 82, 0, Math.PI * 2)
|
|
1279
|
+
ctx.stroke()
|
|
1280
|
+
ctx.lineWidth = 2
|
|
1281
|
+
ctx.beginPath()
|
|
1282
|
+
ctx.arc(0, 0, 50, 0, Math.PI * 2)
|
|
1283
|
+
ctx.stroke()
|
|
1284
|
+
ctx.font = `900 ${t.stamp.length > 2 ? 26 : 36}px ${F.zhSans}`
|
|
1285
|
+
ctx.textAlign = 'center'
|
|
1286
|
+
ctx.fillText(t.stamp, 0, 12)
|
|
1287
|
+
ctx.font = `600 13px ${F.mono}`
|
|
1288
|
+
const ring = 'TRANSLATED ✦ DSH ✦ QUICK TRANSLATE ✦ '
|
|
1289
|
+
const step = (Math.PI * 2) / ring.length
|
|
1290
|
+
;[...ring].forEach((ch, i) => {
|
|
1291
|
+
ctx.save()
|
|
1292
|
+
ctx.rotate(-Math.PI / 2 + i * step)
|
|
1293
|
+
ctx.translate(0, -62)
|
|
1294
|
+
ctx.fillText(ch, 0, 4)
|
|
1295
|
+
ctx.restore()
|
|
1296
|
+
})
|
|
1297
|
+
ctx.restore()
|
|
1298
|
+
|
|
1299
|
+
// ---- 桌面底部 ----
|
|
1300
|
+
const now = new Date()
|
|
1301
|
+
ctx.fillStyle = 'rgba(232,229,222,0.2)'
|
|
1302
|
+
ctx.font = `800 38px ${F.grot}`
|
|
1303
|
+
ctx.fillText(`${now.getDate()} ${MONTHS[now.getMonth()]} ${now.getFullYear()}`, padX, H - 66)
|
|
1304
|
+
ctx.textAlign = 'right'
|
|
1305
|
+
ctx.font = `500 17px ${F.mono}`
|
|
1306
|
+
ctx.fillStyle = 'rgba(232,229,222,0.45)'
|
|
1307
|
+
ctx.fillText('MADE WITH DEEPSEEK HARNESS', W - padX, H - 70)
|
|
1308
|
+
ctx.textAlign = 'left'
|
|
1309
|
+
|
|
1310
|
+
// 颗粒
|
|
1311
|
+
ctx.fillStyle = grainPattern(ctx, 22)
|
|
1312
|
+
ctx.fillRect(0, 0, W, H)
|
|
1313
|
+
|
|
1314
|
+
return new Promise((resolve) => canvas.toBlob((b) => resolve(b), 'image/png'))
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
// 色场风格的分享卡片:白底,上面一块浅灰圆角(原文),下面一整块品牌色圆角(译文 + 超大「文」),照画板「F 色场 · 分享卡片」540 宽 ×2
|
|
1318
|
+
async function renderFieldShareCard({ source, result, target, modelName, elapsedMs, t, brand }) {
|
|
1319
|
+
try {
|
|
1320
|
+
await document.fonts?.ready
|
|
1321
|
+
} catch {
|
|
1322
|
+
/* 字体没就绪就用回退字体画 */
|
|
1323
|
+
}
|
|
1324
|
+
const F = { ...SHARE_FONTS, ui: '-apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif' }
|
|
1325
|
+
const W = 1080
|
|
1326
|
+
const S = 2
|
|
1327
|
+
const toZh = target !== 'en'
|
|
1328
|
+
const blue = brand || '#4d6bfe'
|
|
1329
|
+
const measure = document.createElement('canvas').getContext('2d')
|
|
1330
|
+
const padX = 64
|
|
1331
|
+
const innerW = W - padX * 2
|
|
1332
|
+
|
|
1333
|
+
// 原文卡
|
|
1334
|
+
const srcFont = `400 29px ${F.ui}`
|
|
1335
|
+
measure.font = srcFont
|
|
1336
|
+
const src = wrapLines(measure, source, innerW - 96, 7)
|
|
1337
|
+
const srcLH = 49
|
|
1338
|
+
const srcY = 160
|
|
1339
|
+
const srcH = 44 + 40 + 24 + src.lines.length * srcLH + 40
|
|
1340
|
+
|
|
1341
|
+
// 译文卡:字号随长度在 42 → 32 之间收
|
|
1342
|
+
let size = 42
|
|
1343
|
+
let dst = null
|
|
1344
|
+
for (; size >= 32; size -= 2) {
|
|
1345
|
+
measure.font = toZh ? `600 ${size}px ${F.zhSerif}` : `500 ${size}px ${F.enSerif}`
|
|
1346
|
+
dst = wrapLines(measure, result, innerW - 104, 12)
|
|
1347
|
+
if (!dst.truncated && dst.lines.length <= 9) break
|
|
1348
|
+
}
|
|
1349
|
+
size = Math.max(size, 32)
|
|
1350
|
+
const dstFont = toZh ? `600 ${size}px ${F.zhSerif}` : `500 ${size}px ${F.enSerif}`
|
|
1351
|
+
const dstLH = Math.round(size * (toZh ? 1.8 : 1.55))
|
|
1352
|
+
const fieldY = srcY + srcH + 28
|
|
1353
|
+
const fieldH = Math.max(520, 48 + 40 + 28 + dst.lines.length * dstLH + 44 + 52 + 44)
|
|
1354
|
+
const H = fieldY + fieldH + 28 + 22 + 52
|
|
1355
|
+
|
|
1356
|
+
const canvas = document.createElement('canvas')
|
|
1357
|
+
canvas.width = W * S
|
|
1358
|
+
canvas.height = H * S
|
|
1359
|
+
const ctx = canvas.getContext('2d')
|
|
1360
|
+
ctx.scale(S, S)
|
|
1361
|
+
ctx.textBaseline = 'alphabetic'
|
|
1362
|
+
const round = (x, y, w, hh, r) => {
|
|
1363
|
+
ctx.beginPath()
|
|
1364
|
+
ctx.moveTo(x + r, y)
|
|
1365
|
+
ctx.arcTo(x + w, y, x + w, y + hh, r)
|
|
1366
|
+
ctx.arcTo(x + w, y + hh, x, y + hh, r)
|
|
1367
|
+
ctx.arcTo(x, y + hh, x, y, r)
|
|
1368
|
+
ctx.arcTo(x, y, x + w, y, r)
|
|
1369
|
+
ctx.closePath()
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
ctx.fillStyle = '#ffffff'
|
|
1373
|
+
ctx.fillRect(0, 0, W, H)
|
|
1374
|
+
|
|
1375
|
+
// 头部
|
|
1376
|
+
ctx.fillStyle = '#1d1d22'
|
|
1377
|
+
ctx.font = `700 38px ${F.ui}`
|
|
1378
|
+
ctx.fillText('Quick Translate', padX + 8, 112)
|
|
1379
|
+
const titleW = ctx.measureText('Quick Translate').width
|
|
1380
|
+
ctx.font = `400 22px ${F.ui}`
|
|
1381
|
+
ctx.fillStyle = '#6c6c75'
|
|
1382
|
+
ctx.fillText(`${t.title} · DSH Plugin · by ${AUTHOR}`, padX + 8 + titleW + 20, 112)
|
|
1383
|
+
ctx.textAlign = 'right'
|
|
1384
|
+
ctx.font = `400 24px ${F.ui}`
|
|
1385
|
+
ctx.fillText(toZh ? t.en2zh : t.zh2en, W - padX - 8, 112)
|
|
1386
|
+
ctx.textAlign = 'left'
|
|
1387
|
+
|
|
1388
|
+
// 原文卡
|
|
1389
|
+
round(padX, srcY, innerW, srcH, 40)
|
|
1390
|
+
ctx.fillStyle = '#f6f6f8'
|
|
1391
|
+
ctx.fill()
|
|
1392
|
+
ctx.strokeStyle = '#e9e9ee'
|
|
1393
|
+
ctx.lineWidth = 2
|
|
1394
|
+
ctx.stroke()
|
|
1395
|
+
const sx = padX + 48
|
|
1396
|
+
ctx.fillStyle = '#1d1d22'
|
|
1397
|
+
ctx.font = toZh ? `italic 400 40px ${F.enSerif}` : `600 40px ${F.zhSerif}`
|
|
1398
|
+
ctx.fillText(nativeName(toZh ? 'en' : 'zh'), sx, srcY + 44 + 32)
|
|
1399
|
+
ctx.font = srcFont
|
|
1400
|
+
src.lines.forEach((ln, i) => ctx.fillText(ln, sx, srcY + 44 + 40 + 24 + 22 + i * srcLH))
|
|
1401
|
+
|
|
1402
|
+
// 译文卡
|
|
1403
|
+
ctx.save()
|
|
1404
|
+
round(padX, fieldY, innerW, fieldH, 40)
|
|
1405
|
+
ctx.fillStyle = blue
|
|
1406
|
+
ctx.fill()
|
|
1407
|
+
ctx.clip()
|
|
1408
|
+
ctx.fillStyle = 'rgba(255,255,255,0.08)'
|
|
1409
|
+
ctx.textAlign = 'right'
|
|
1410
|
+
ctx.font = toZh ? `600 600px ${F.zhSerif}` : `500 640px ${F.enSerif}`
|
|
1411
|
+
ctx.fillText(toZh ? '文' : 'A', padX + innerW + 68, fieldY + fieldH + 120)
|
|
1412
|
+
ctx.textAlign = 'left'
|
|
1413
|
+
const fx = padX + 52
|
|
1414
|
+
ctx.fillStyle = '#ffffff'
|
|
1415
|
+
ctx.font = toZh ? `600 40px ${F.zhSerif}` : `italic 400 40px ${F.enSerif}`
|
|
1416
|
+
const lname = nativeName(toZh ? 'zh' : 'en')
|
|
1417
|
+
ctx.fillText(lname, fx, fieldY + 48 + 32)
|
|
1418
|
+
const lw = ctx.measureText(lname).width
|
|
1419
|
+
ctx.font = `400 23px ${F.ui}`
|
|
1420
|
+
ctx.fillStyle = 'rgba(255,255,255,0.86)'
|
|
1421
|
+
ctx.fillText(elapsedMs ? `${t.done} · ${fmtElapsed(elapsedMs, t)}` : t.done, fx + lw + 20, fieldY + 48 + 30)
|
|
1422
|
+
ctx.fillStyle = '#ffffff'
|
|
1423
|
+
ctx.font = dstFont
|
|
1424
|
+
const dy0 = fieldY + 48 + 40 + 28 + size
|
|
1425
|
+
dst.lines.forEach((ln, i) => ctx.fillText(ln, fx, dy0 + i * dstLH))
|
|
1426
|
+
// 底部:模型胶囊 + 日期
|
|
1427
|
+
const by = fieldY + fieldH - 44 - 52
|
|
1428
|
+
ctx.font = `600 24px ${F.ui}`
|
|
1429
|
+
const mn = modelName || '—'
|
|
1430
|
+
const mw = Math.min(ctx.measureText(mn).width, innerW - 104 - 260)
|
|
1431
|
+
round(fx, by, mw + 40, 52, 18)
|
|
1432
|
+
ctx.fillStyle = 'rgba(255,255,255,0.16)'
|
|
1433
|
+
ctx.fill()
|
|
1434
|
+
ctx.fillStyle = '#ffffff'
|
|
1435
|
+
ctx.fillText(mn, fx + 20, by + 34, mw)
|
|
1436
|
+
const now = new Date()
|
|
1437
|
+
ctx.textAlign = 'right'
|
|
1438
|
+
ctx.font = `400 24px ${F.ui}`
|
|
1439
|
+
ctx.fillStyle = 'rgba(255,255,255,0.86)'
|
|
1440
|
+
ctx.fillText(`${now.getFullYear()}.${pad2(now.getMonth() + 1)}.${pad2(now.getDate())}`, padX + innerW - 52, by + 34)
|
|
1441
|
+
ctx.textAlign = 'left'
|
|
1442
|
+
ctx.restore()
|
|
1443
|
+
|
|
1444
|
+
// 页脚
|
|
1445
|
+
ctx.fillStyle = '#9a9aa4'
|
|
1446
|
+
ctx.font = `400 22px ${F.ui}`
|
|
1447
|
+
ctx.fillText('Made with DeepSeek Harness', padX + 8, H - 52)
|
|
1448
|
+
ctx.textAlign = 'right'
|
|
1449
|
+
ctx.fillText('dsh-quick-translate', W - padX - 8, H - 52)
|
|
1450
|
+
ctx.textAlign = 'left'
|
|
1451
|
+
|
|
1452
|
+
return new Promise((resolve) => canvas.toBlob((b) => resolve(b), 'image/png'))
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
/** 分享:生成卡片 → 预览 → 复制图片 / 保存图片。浮层画在面板自己里面,不往 body 挂东西。 */
|
|
1456
|
+
function ShareSheet({ data, t, onClose }) {
|
|
1457
|
+
const [url, setUrl] = useState('')
|
|
1458
|
+
const [blob, setBlob] = useState(null)
|
|
1459
|
+
const [msg, setMsg] = useState('')
|
|
1460
|
+
const field = data.skin === 'field'
|
|
1461
|
+
useEffect(() => {
|
|
1462
|
+
let alive = true
|
|
1463
|
+
let made = ''
|
|
1464
|
+
;(data.skin === 'field' ? renderFieldShareCard : renderShareCard)(data)
|
|
1465
|
+
.then((b) => {
|
|
1466
|
+
if (!alive || !b) return
|
|
1467
|
+
made = URL.createObjectURL(b)
|
|
1468
|
+
setBlob(b)
|
|
1469
|
+
setUrl(made)
|
|
1470
|
+
})
|
|
1471
|
+
.catch((err) => alive && setMsg(String(err?.message || err)))
|
|
1472
|
+
return () => {
|
|
1473
|
+
alive = false
|
|
1474
|
+
if (made) URL.revokeObjectURL(made)
|
|
1475
|
+
}
|
|
1476
|
+
}, [data])
|
|
1477
|
+
useEffect(() => {
|
|
1478
|
+
const onKey = (e) => {
|
|
1479
|
+
if (e.key !== 'Escape') return
|
|
1480
|
+
e.stopPropagation()
|
|
1481
|
+
onClose()
|
|
1482
|
+
}
|
|
1483
|
+
document.addEventListener('keydown', onKey, true)
|
|
1484
|
+
return () => document.removeEventListener('keydown', onKey, true)
|
|
1485
|
+
}, [onClose])
|
|
1486
|
+
const copy = async () => {
|
|
1487
|
+
try {
|
|
1488
|
+
await navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })])
|
|
1489
|
+
setMsg(t.shareCopied)
|
|
1490
|
+
} catch {
|
|
1491
|
+
setMsg(t.shareCopyFailed)
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
const save = () => {
|
|
1495
|
+
const a = document.createElement('a')
|
|
1496
|
+
a.href = url
|
|
1497
|
+
a.download = `quick-translate-${new Date().toISOString().slice(0, 19).replace(/[:T]/g, '-')}.png`
|
|
1498
|
+
a.click()
|
|
1499
|
+
setMsg(t.shareSaved)
|
|
1500
|
+
}
|
|
1501
|
+
return h(
|
|
1502
|
+
'div',
|
|
1503
|
+
{ className: 'qt-share', role: 'dialog', 'aria-modal': 'true', 'aria-label': t.shareTitle, onClick: (e) => e.target === e.currentTarget && onClose() },
|
|
1504
|
+
h('div', { className: 'qt-share-card' }, url ? h('img', { src: url, alt: t.shareTitle }) : h('span', { className: 'qt-share-wait' }, msg || t.shareMaking)),
|
|
1505
|
+
h(
|
|
1506
|
+
'div',
|
|
1507
|
+
{ className: 'qt-share-bar' },
|
|
1508
|
+
h('button', { type: 'button', className: field ? 'qt-fsbtn qt-fsbtn-primary' : 'qt-tapebtn qt-go qt-btn-primary', onClick: copy, disabled: !blob }, t.shareCopy),
|
|
1509
|
+
h('button', { type: 'button', className: field ? 'qt-fsbtn qt-fsbtn-secondary' : 'qt-tapebtn qt-clear', onClick: save, disabled: !url }, t.shareSave),
|
|
1510
|
+
h('button', { type: 'button', className: field ? 'qt-fhb' : 'qt-hbtn', onClick: onClose }, t.shareClose),
|
|
1511
|
+
url && msg ? h('span', { className: 'qt-share-msg', role: 'status' }, msg) : null,
|
|
1512
|
+
),
|
|
1513
|
+
)
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
// 解析主题 token 的颜色值(#rgb / #rrggbb / rgb()),算相对亮度判断明暗;解析不了就看系统偏好
|
|
1517
|
+
function isDarkColor(value) {
|
|
1518
|
+
const v = String(value || '').trim()
|
|
1519
|
+
let rgb = null
|
|
1520
|
+
const hex = v.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i)
|
|
1521
|
+
if (hex) {
|
|
1522
|
+
const x = hex[1].length === 3 ? hex[1].replace(/./g, '$&$&') : hex[1]
|
|
1523
|
+
rgb = [0, 2, 4].map((i) => parseInt(x.slice(i, i + 2), 16))
|
|
1524
|
+
} else {
|
|
1525
|
+
const m = v.match(/rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i)
|
|
1526
|
+
if (m) rgb = [m[1], m[2], m[3]].map(Number)
|
|
1527
|
+
}
|
|
1528
|
+
if (!rgb) return Boolean(window.matchMedia?.('(prefers-color-scheme: dark)').matches)
|
|
1529
|
+
const [r, g, b] = rgb.map((c) => {
|
|
1530
|
+
const k = c / 255
|
|
1531
|
+
return k <= 0.03928 ? k / 12.92 : ((k + 0.055) / 1.055) ** 2.4
|
|
1532
|
+
})
|
|
1533
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b < 0.3
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
// 文本框的刻度尺:内容超出时才出现,实心段表示当前位置
|
|
1537
|
+
function thumbOf(el) {
|
|
1538
|
+
if (!el || !el.scrollHeight) return null
|
|
1539
|
+
const sh = el.scrollHeight
|
|
1540
|
+
const ch = el.clientHeight
|
|
1541
|
+
if (sh <= ch + 2) return null
|
|
1542
|
+
const size = Math.max(8, (ch / sh) * 100)
|
|
1543
|
+
return { top: (el.scrollTop / (sh - ch)) * (100 - size), size }
|
|
1544
|
+
}
|
|
1545
|
+
const rulerOf = (thumb) => (thumb ? h('div', { className: `qt-tarul ${thumb.on ? 'is-on' : ''}`, 'aria-hidden': 'true' }, h('i', { style: { top: `${thumb.top}%`, height: `${thumb.size}%` } })) : null)
|
|
1546
|
+
|
|
1547
|
+
/* ============================== 组件 ================================ */
|
|
1548
|
+
|
|
1549
|
+
/** 模型选择:硫酸纸底部的一行字,点开是一张索引卡(absolute 锚在按钮上方,不受祖先 transform 影响)。 */
|
|
1550
|
+
// 两种风格共用一套逻辑,只换类名和图形
|
|
1551
|
+
const PICKER_CLS = {
|
|
1552
|
+
paper: { root: 'qt-picker', btn: 'qt-picker-btn', label: 'qt-picker-label', tag: 'qt-picker-tag', menu: 'qt-picker-menu', head: 'qt-picker-head', group: 'qt-picker-group-title', item: 'qt-picker-item', empty: 'qt-picker-empty' },
|
|
1553
|
+
field: { root: 'qt-fpick', btn: 'qt-fpick-btn', label: 'qt-fpick-label', tag: 'qt-fpick-tag', menu: 'qt-fmenu', head: 'qt-fmenu-head', group: 'qt-fmg', item: 'qt-fmi', empty: 'qt-fmenu-empty' },
|
|
1554
|
+
}
|
|
1555
|
+
function ModelPicker({ groups, defaultRoute, value, onChange, loading, disabled, t, skin }) {
|
|
1556
|
+
const field = skin === 'field'
|
|
1557
|
+
const C = PICKER_CLS[field ? 'field' : 'paper']
|
|
1558
|
+
const [open, setOpen] = useState(false)
|
|
1559
|
+
const btnRef = useRef(null)
|
|
1560
|
+
const menuRef = useRef(null)
|
|
1561
|
+
const parsed = parseKey(value)
|
|
1562
|
+
const selected = parsed ? groups.flatMap((g) => g.models).find((m) => m.provider === parsed.provider && m.model === parsed.model) || null : null
|
|
1563
|
+
const label = selected
|
|
1564
|
+
? selected.name || selected.model
|
|
1565
|
+
: defaultRoute
|
|
1566
|
+
? defaultRoute.model
|
|
1567
|
+
: loading
|
|
1568
|
+
? t.loadingModels
|
|
1569
|
+
: t.selectModel
|
|
1570
|
+
const total = groups.reduce((n, g) => n + g.models.length, 0)
|
|
1571
|
+
|
|
1572
|
+
useEffect(() => {
|
|
1573
|
+
if (!open) return undefined
|
|
1574
|
+
const onDown = (e) => {
|
|
1575
|
+
if (btnRef.current?.contains(e.target) || menuRef.current?.contains(e.target)) return
|
|
1576
|
+
setOpen(false)
|
|
1577
|
+
}
|
|
1578
|
+
const onKey = (e) => {
|
|
1579
|
+
if (e.key !== 'Escape') return
|
|
1580
|
+
// 只关菜单,别让同一下 Esc 穿透到面板的「取消翻译」
|
|
1581
|
+
e.stopPropagation()
|
|
1582
|
+
setOpen(false)
|
|
1583
|
+
}
|
|
1584
|
+
document.addEventListener('mousedown', onDown)
|
|
1585
|
+
document.addEventListener('keydown', onKey)
|
|
1586
|
+
return () => {
|
|
1587
|
+
document.removeEventListener('mousedown', onDown)
|
|
1588
|
+
document.removeEventListener('keydown', onKey)
|
|
1589
|
+
}
|
|
1590
|
+
}, [open])
|
|
1591
|
+
|
|
1592
|
+
const toggle = () => {
|
|
1593
|
+
if (disabled) return
|
|
1594
|
+
setOpen((v) => !v)
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
const pick = (key) => {
|
|
1598
|
+
onChange(key)
|
|
1599
|
+
setOpen(false)
|
|
1600
|
+
btnRef.current?.focus()
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
const item = (key, name, id) =>
|
|
1604
|
+
h(
|
|
1605
|
+
'button',
|
|
1606
|
+
{ type: 'button', key: key || '__default', className: C.item, role: 'option', 'aria-selected': value === key ? 'true' : 'false', onClick: () => pick(key) },
|
|
1607
|
+
h('span', { className: 'qt-check' }, field ? h(CheckIcon) : h(TickMark)),
|
|
1608
|
+
h('span', { className: 'qt-name' }, name),
|
|
1609
|
+
id && id !== name ? h('span', { className: 'qt-id' }, id) : null,
|
|
1610
|
+
)
|
|
1611
|
+
|
|
1612
|
+
return h(
|
|
1613
|
+
'div',
|
|
1614
|
+
{ className: C.root },
|
|
1615
|
+
h(
|
|
1616
|
+
'button',
|
|
1617
|
+
{ ref: btnRef, type: 'button', className: C.btn, onClick: toggle, disabled: disabled || loading, 'aria-haspopup': 'listbox', 'aria-expanded': open ? 'true' : 'false', title: !selected && defaultRoute ? `${t.followDefault} · ${label}` : label },
|
|
1618
|
+
h('span', { className: field ? 'qt-fpick-k' : undefined }, field ? t.model : `${t.model}:`),
|
|
1619
|
+
h('span', { className: C.label }, label),
|
|
1620
|
+
!selected && defaultRoute ? h('span', { className: C.tag }, field ? `(${t.defaultShort})` : `[${t.defaultShort}]`) : null,
|
|
1621
|
+
field ? h(ChevronIcon) : h('span', { className: 'qt-chev', 'aria-hidden': true }, '▾'),
|
|
1622
|
+
),
|
|
1623
|
+
open
|
|
1624
|
+
? h(
|
|
1625
|
+
'div',
|
|
1626
|
+
{ ref: menuRef, className: C.menu, role: 'listbox', 'aria-label': t.selectModel },
|
|
1627
|
+
h('div', { className: C.head }, h('b', null, field ? t.selectModel : t.model), h('span', null, t.modelCount(total))),
|
|
1628
|
+
defaultRoute ? item('', `${t.followDefault}`, defaultRoute.model) : null,
|
|
1629
|
+
groups.map((g) =>
|
|
1630
|
+
h(
|
|
1631
|
+
'div',
|
|
1632
|
+
{ key: g.provider },
|
|
1633
|
+
h('div', { className: C.group }, g.name),
|
|
1634
|
+
g.models.map((m) => item(modelKey(m), m.name || m.model, m.model)),
|
|
1635
|
+
),
|
|
1636
|
+
),
|
|
1637
|
+
loading ? h('div', { className: C.empty }, t.loadingModels) : null,
|
|
1638
|
+
!loading && groups.length === 0 && !defaultRoute ? h('div', { className: C.empty }, t.selectModel) : null,
|
|
1639
|
+
)
|
|
1640
|
+
: null,
|
|
1641
|
+
)
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
/** 历史:一张热敏小票。头尾固定,中间单独滚动;日期标签吸顶;右边缘的刻度尺代替滚动条。 */
|
|
1645
|
+
function HistoryPanel({ history, currentId, query, onQuery, onPick, onDelete, onClear, clearArmed, t, lang }) {
|
|
1646
|
+
const [thumb, setThumb] = useState({ top: 0, size: 100 })
|
|
1647
|
+
const q = query.trim().toLowerCase()
|
|
1648
|
+
const shown = q
|
|
1649
|
+
? history.filter((e) => e.source.toLowerCase().includes(q) || e.result.toLowerCase().includes(q) || e.modelName.toLowerCase().includes(q))
|
|
1650
|
+
: history
|
|
1651
|
+
const onScroll = (event) => {
|
|
1652
|
+
const el = event.currentTarget
|
|
1653
|
+
const size = el.scrollHeight > 0 ? Math.min(100, (el.clientHeight / el.scrollHeight) * 100) : 100
|
|
1654
|
+
const room = el.scrollHeight - el.clientHeight
|
|
1655
|
+
setThumb({ top: room > 0 ? (el.scrollTop / room) * (100 - size) : 0, size })
|
|
1656
|
+
}
|
|
1657
|
+
const rows = []
|
|
1658
|
+
let lastDay = ''
|
|
1659
|
+
for (const e of shown) {
|
|
1660
|
+
const d = dayLabel(e.at, t, lang)
|
|
1661
|
+
if (d !== lastDay) {
|
|
1662
|
+
rows.push(h('div', { key: `d-${e.id}`, className: 'qt-hday' }, `— ${d} —`))
|
|
1663
|
+
lastDay = d
|
|
1664
|
+
}
|
|
1665
|
+
rows.push(
|
|
1666
|
+
h(
|
|
1667
|
+
'div',
|
|
1668
|
+
{ key: e.id, role: 'listitem', className: 'qt-hitem-wrap' },
|
|
1669
|
+
h(
|
|
1670
|
+
'button',
|
|
1671
|
+
{ type: 'button', className: 'qt-hitem', 'aria-current': e.id === currentId ? 'true' : 'false', onClick: () => onPick(e), title: e.source.slice(0, 200) },
|
|
1672
|
+
h(
|
|
1673
|
+
'div',
|
|
1674
|
+
{ className: 'qt-hitem-meta' },
|
|
1675
|
+
h('span', null, fmtClock(e.at)),
|
|
1676
|
+
h('span', null, e.target === 'zh' ? 'EN>ZH' : 'ZH>EN'),
|
|
1677
|
+
e.modelName ? h('span', { className: 'qt-model' }, e.modelName) : null,
|
|
1678
|
+
),
|
|
1679
|
+
h('div', { className: 'qt-hitem-dst', 'data-lang': e.target }, e.result),
|
|
1680
|
+
h('div', { className: 'qt-hitem-src' }, e.source),
|
|
1681
|
+
),
|
|
1682
|
+
h(
|
|
1683
|
+
'button',
|
|
1684
|
+
{ type: 'button', className: 'qt-hitem-del', title: t.historyDelete, 'aria-label': t.historyDelete, onClick: (ev) => { ev.stopPropagation(); onDelete(e.id) } },
|
|
1685
|
+
'×',
|
|
1686
|
+
),
|
|
1687
|
+
),
|
|
1688
|
+
)
|
|
1689
|
+
}
|
|
1690
|
+
return h(
|
|
1691
|
+
'aside',
|
|
1692
|
+
{ className: 'qt-history qt-col', 'aria-label': t.history },
|
|
1693
|
+
h('div', { className: 'qt-paper', 'aria-hidden': 'true' }),
|
|
1694
|
+
h('div', { className: 'qt-history-head' }, h('b', null, t.history), h('span', null, `No. ${pad2(history.length)}`)),
|
|
1695
|
+
h(
|
|
1696
|
+
'label',
|
|
1697
|
+
{ className: 'qt-history-search' },
|
|
1698
|
+
h('span', null, 'Find:'),
|
|
1699
|
+
h('input', { type: 'search', value: query, placeholder: t.historySearch, onChange: (e) => onQuery(e.target.value), 'aria-label': t.historySearch, disabled: history.length === 0 }),
|
|
1700
|
+
),
|
|
1701
|
+
h('div', { className: 'qt-perf', 'aria-hidden': 'true' }),
|
|
1702
|
+
h(
|
|
1703
|
+
'div',
|
|
1704
|
+
{ className: 'qt-history-scroll' },
|
|
1705
|
+
h(
|
|
1706
|
+
'div',
|
|
1707
|
+
{ className: 'qt-history-list', role: 'list', onScroll },
|
|
1708
|
+
history.length === 0
|
|
1709
|
+
? h('div', { className: 'qt-empty-sm' }, t.historyEmpty)
|
|
1710
|
+
: shown.length === 0
|
|
1711
|
+
? h('div', { className: 'qt-empty-sm' }, t.historyEmptyFiltered)
|
|
1712
|
+
: rows,
|
|
1713
|
+
),
|
|
1714
|
+
thumb.size < 100
|
|
1715
|
+
? h('div', { className: 'qt-ruler', 'aria-hidden': 'true' }, h('i', { style: { top: `${thumb.top}%`, height: `${thumb.size}%` } }))
|
|
1716
|
+
: null,
|
|
1717
|
+
),
|
|
1718
|
+
h('div', { className: 'qt-perf', 'aria-hidden': 'true' }),
|
|
1719
|
+
h(
|
|
1720
|
+
'div',
|
|
1721
|
+
{ className: 'qt-history-foot' },
|
|
1722
|
+
history.length
|
|
1723
|
+
? h(
|
|
1724
|
+
'button',
|
|
1725
|
+
{ type: 'button', className: `qt-link qt-br ${clearArmed ? 'qt-danger' : ''}`, onClick: onClear },
|
|
1726
|
+
clearArmed ? t.historyConfirm : t.historyClear,
|
|
1727
|
+
)
|
|
1728
|
+
: h('span'),
|
|
1729
|
+
h('span', null, t.historyTotal(history.length)),
|
|
1730
|
+
),
|
|
1731
|
+
h('div', { className: 'qt-barcode', 'aria-hidden': 'true' }),
|
|
1732
|
+
)
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
/** 色场的历史:和译文容器一样大的一张卡,盖在译文的位置上。头尾固定,中间单独滚动;日期吸顶,上下渐隐,右侧细滚动条。 */
|
|
1736
|
+
function FieldHistory({ history, currentId, query, onQuery, onPick, onDelete, onClear, onClose, clearArmed, t, lang }) {
|
|
1737
|
+
const [scroll, setScroll] = useState({ top: 0, size: 100, atTop: true, atEnd: true })
|
|
1738
|
+
const listRef = useRef(null)
|
|
1739
|
+
const q = query.trim().toLowerCase()
|
|
1740
|
+
const shown = q
|
|
1741
|
+
? history.filter((e) => e.source.toLowerCase().includes(q) || e.result.toLowerCase().includes(q) || e.modelName.toLowerCase().includes(q))
|
|
1742
|
+
: history
|
|
1743
|
+
const measure = (el) => {
|
|
1744
|
+
if (!el) return
|
|
1745
|
+
const room = el.scrollHeight - el.clientHeight
|
|
1746
|
+
const size = el.scrollHeight > 0 ? Math.min(100, (el.clientHeight / el.scrollHeight) * 100) : 100
|
|
1747
|
+
setScroll({ top: room > 0 ? (el.scrollTop / room) * (100 - size) : 0, size, atTop: el.scrollTop <= 2, atEnd: room - el.scrollTop <= 2 })
|
|
1748
|
+
}
|
|
1749
|
+
useEffect(() => measure(listRef.current), [shown.length])
|
|
1750
|
+
const rows = []
|
|
1751
|
+
let lastDay = ''
|
|
1752
|
+
for (const e of shown) {
|
|
1753
|
+
const d = dayLabel(e.at, t, lang)
|
|
1754
|
+
if (d !== lastDay) {
|
|
1755
|
+
rows.push(h('div', { key: `d-${e.id}`, className: 'qt-fhday' }, d))
|
|
1756
|
+
lastDay = d
|
|
1757
|
+
}
|
|
1758
|
+
rows.push(
|
|
1759
|
+
h(
|
|
1760
|
+
'div',
|
|
1761
|
+
{ key: e.id, role: 'listitem', className: 'qt-fhi-wrap' },
|
|
1762
|
+
h(
|
|
1763
|
+
'button',
|
|
1764
|
+
{ type: 'button', className: 'qt-fhi', 'aria-current': e.id === currentId ? 'true' : 'false', onClick: () => onPick(e), title: e.source.slice(0, 200) },
|
|
1765
|
+
h('span', { className: 'qt-fhi-time' }, fmtClock(e.at)),
|
|
1766
|
+
h('span', { className: 'qt-fhi-main' }, h('span', { className: 'qt-fhi-dst', 'data-lang': e.target }, e.result), h('span', { className: 'qt-fhi-src' }, e.source)),
|
|
1767
|
+
h('span', { className: 'qt-fhi-meta' }, h('span', null, e.target === 'zh' ? t.en2zh : t.zh2en), e.modelName ? h('span', null, e.modelName) : null),
|
|
1768
|
+
),
|
|
1769
|
+
h(
|
|
1770
|
+
'button',
|
|
1771
|
+
{ type: 'button', className: 'qt-fhi-del', title: t.historyDelete, 'aria-label': t.historyDelete, onClick: (ev) => { ev.stopPropagation(); onDelete(e.id) } },
|
|
1772
|
+
h(CloseIcon, { size: 12 }),
|
|
1773
|
+
),
|
|
1774
|
+
),
|
|
1775
|
+
)
|
|
1776
|
+
}
|
|
1777
|
+
return h(
|
|
1778
|
+
'aside',
|
|
1779
|
+
{ className: 'qt-fhist', 'aria-label': t.history },
|
|
1780
|
+
h(
|
|
1781
|
+
'div',
|
|
1782
|
+
{ className: 'qt-fhist-head' },
|
|
1783
|
+
h('b', null, t.history),
|
|
1784
|
+
h('span', null, t.historyCount(history.length)),
|
|
1785
|
+
h(
|
|
1786
|
+
'label',
|
|
1787
|
+
{ className: 'qt-fhist-search' },
|
|
1788
|
+
h(SearchIcon),
|
|
1789
|
+
h('input', { type: 'search', value: query, placeholder: t.historySearch, onChange: (e) => onQuery(e.target.value), 'aria-label': t.historySearch, disabled: history.length === 0 }),
|
|
1790
|
+
),
|
|
1791
|
+
h('button', { type: 'button', className: 'qt-ficon', title: t.historyHide, 'aria-label': t.historyHide, onClick: onClose }, h(CloseIcon, { size: 15 })),
|
|
1792
|
+
),
|
|
1793
|
+
h('div', { className: 'qt-fhist-rule', 'aria-hidden': 'true' }),
|
|
1794
|
+
h(
|
|
1795
|
+
'div',
|
|
1796
|
+
{ className: 'qt-fhist-scroll' },
|
|
1797
|
+
h(
|
|
1798
|
+
'div',
|
|
1799
|
+
{ ref: listRef, className: 'qt-fhist-list', role: 'list', onScroll: (ev) => measure(ev.currentTarget) },
|
|
1800
|
+
history.length === 0
|
|
1801
|
+
? h('div', { className: 'qt-fempty' }, t.historyEmpty)
|
|
1802
|
+
: shown.length === 0
|
|
1803
|
+
? h('div', { className: 'qt-fempty' }, t.historyEmptyFiltered)
|
|
1804
|
+
: rows,
|
|
1805
|
+
),
|
|
1806
|
+
!scroll.atTop ? h('div', { className: 'qt-ffade-top', 'aria-hidden': 'true' }) : null,
|
|
1807
|
+
!scroll.atEnd ? h('div', { className: 'qt-ffade-bot', 'aria-hidden': 'true' }) : null,
|
|
1808
|
+
scroll.size < 100 ? h('div', { className: 'qt-fthumb', 'aria-hidden': 'true' }, h('i', { style: { top: `${scroll.top}%`, height: `${scroll.size}%` } })) : null,
|
|
1809
|
+
),
|
|
1810
|
+
h(
|
|
1811
|
+
'div',
|
|
1812
|
+
{ className: 'qt-fhist-foot' },
|
|
1813
|
+
history.length
|
|
1814
|
+
? h('button', { type: 'button', className: `qt-fhist-clear ${clearArmed ? 'is-armed' : ''}`, onClick: onClear }, clearArmed ? t.historyConfirm : t.historyClear)
|
|
1815
|
+
: h('span'),
|
|
1816
|
+
h('span', null, t.historyKeep),
|
|
1817
|
+
),
|
|
1818
|
+
)
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
function TranslatePanel() {
|
|
1822
|
+
const lang = useLang()
|
|
1823
|
+
const t = STR[lang] || STR.en
|
|
1824
|
+
const langName = (code) => (code === 'zh' ? t.langZh : t.langEn)
|
|
1825
|
+
|
|
1826
|
+
const prefs = useMemo(() => readJson(PREFS_KEY, {}), [])
|
|
1827
|
+
const draft = useMemo(() => readJson(DRAFT_KEY, {}), [])
|
|
1828
|
+
const [source, setSource] = useState(typeof draft.source === 'string' ? draft.source : '')
|
|
1829
|
+
const [result, setResult] = useState(typeof draft.result === 'string' ? draft.result : '')
|
|
1830
|
+
const [direction, setDirection] = useState(['en2zh', 'zh2en', 'auto'].includes(prefs.direction) ? prefs.direction : 'auto')
|
|
1831
|
+
// 窄屏下历史是盖住内容的小票,默认不展开,免得一打开面板先看到的是「还没有翻译记录」
|
|
1832
|
+
const [historyOpen, setHistoryOpen] = useState(prefs.historyOpen === true && window.innerWidth > 720)
|
|
1833
|
+
const [history, setHistory] = useState(() => sanitizeHistory(readJson(HISTORY_KEY, [])))
|
|
1834
|
+
const [historyQuery, setHistoryQuery] = useState('')
|
|
1835
|
+
const [clearArmed, setClearArmed] = useState(false)
|
|
1836
|
+
const [currentId, setCurrentId] = useState(null)
|
|
1837
|
+
const [models, setModels] = useState(null)
|
|
1838
|
+
const [skipped, setSkipped] = useState(0)
|
|
1839
|
+
const [defaultRoute, setDefaultRoute] = useState(null)
|
|
1840
|
+
const [modelKeyState, setModelKeyState] = useState(typeof prefs.modelKey === 'string' ? prefs.modelKey : '')
|
|
1841
|
+
const [modelsLoading, setModelsLoading] = useState(false)
|
|
1842
|
+
const [modelsError, setModelsError] = useState('')
|
|
1843
|
+
const [status, setStatus] = useState('idle') // idle | streaming | done | error
|
|
1844
|
+
const [error, setError] = useState('')
|
|
1845
|
+
const [elapsed, setElapsed] = useState(0)
|
|
1846
|
+
const [usedRoute, setUsedRoute] = useState(null)
|
|
1847
|
+
const [usedTarget, setUsedTarget] = useState(null)
|
|
1848
|
+
const [truncated, setTruncated] = useState(false)
|
|
1849
|
+
const [cancelled, setCancelled] = useState(false)
|
|
1850
|
+
const [copied, setCopied] = useState(false)
|
|
1851
|
+
const [copyFailed, setCopyFailed] = useState(false)
|
|
1852
|
+
const [shareData, setShareData] = useState(null)
|
|
1853
|
+
// 界面风格:paper = E 纸本(默认),field = F 色场(简洁版);记在偏好里
|
|
1854
|
+
const [skin, setSkin] = useState(prefs.skin === 'field' ? 'field' : 'paper')
|
|
1855
|
+
const [tone, setTone] = useState('light')
|
|
1856
|
+
const rootRef = useRef(null)
|
|
1857
|
+
const boardRef = useRef(null)
|
|
1858
|
+
// 桌面按画板 E 的 1200×690 原样搭好,再整体缩放到面板大小;面板窄于 760 时改成上下叠放、不缩放
|
|
1859
|
+
const [fit, setFit] = useState({ scale: 1, narrow: window.innerWidth < 760 })
|
|
1860
|
+
useEffect(() => {
|
|
1861
|
+
const el = boardRef.current
|
|
1862
|
+
if (!el || typeof ResizeObserver === 'undefined') return undefined
|
|
1863
|
+
const measure = () => {
|
|
1864
|
+
const w = el.clientWidth
|
|
1865
|
+
const hh = el.clientHeight
|
|
1866
|
+
const narrow = w < 760
|
|
1867
|
+
const scale = narrow
|
|
1868
|
+
? 1
|
|
1869
|
+
: skin === 'field'
|
|
1870
|
+
? Math.max(0.55, Math.min(FIELD_MAX_ZOOM, w / FIELD_W, hh / FIELD_H))
|
|
1871
|
+
: Math.max(0.55, Math.min(1.6, (w - 16) / COMP_W, (hh - 8) / COMP_H))
|
|
1872
|
+
setFit((p) => (p.narrow === narrow && Math.abs(p.scale - scale) < 0.004 ? p : { scale, narrow }))
|
|
1873
|
+
}
|
|
1874
|
+
const ro = new ResizeObserver(measure)
|
|
1875
|
+
ro.observe(el)
|
|
1876
|
+
measure()
|
|
1877
|
+
return () => ro.disconnect()
|
|
1878
|
+
}, [skin])
|
|
1879
|
+
// 色场的颜色跟 DSH 主题走:读 --dsw-alias-bg-base 判断明暗,暗色下品牌色场压暗一些,白字才清楚
|
|
1880
|
+
useEffect(() => {
|
|
1881
|
+
if (skin !== 'field') return undefined
|
|
1882
|
+
const el = rootRef.current
|
|
1883
|
+
if (!el || typeof getComputedStyle !== 'function') return undefined
|
|
1884
|
+
const read = () => setTone(isDarkColor(getComputedStyle(el).getPropertyValue('--dsw-alias-bg-base')) ? 'dark' : 'light')
|
|
1885
|
+
read()
|
|
1886
|
+
const mo = typeof MutationObserver === 'function' ? new MutationObserver(read) : null
|
|
1887
|
+
mo?.observe(document.documentElement, { attributes: true })
|
|
1888
|
+
if (document.body) mo?.observe(document.body, { attributes: true })
|
|
1889
|
+
const mq = window.matchMedia?.('(prefers-color-scheme: dark)')
|
|
1890
|
+
mq?.addEventListener?.('change', read)
|
|
1891
|
+
return () => {
|
|
1892
|
+
mo?.disconnect()
|
|
1893
|
+
mq?.removeEventListener?.('change', read)
|
|
1894
|
+
}
|
|
1895
|
+
}, [skin])
|
|
1896
|
+
const [srcThumb, setSrcThumb] = useState(null)
|
|
1897
|
+
const [resThumb, setResThumb] = useState(null)
|
|
1898
|
+
const rulerTimers = useRef({})
|
|
1899
|
+
// 滚动时亮出刻度尺,停下 900ms 后淡出
|
|
1900
|
+
const flashRuler = (key, setter, el) => {
|
|
1901
|
+
const th = thumbOf(el)
|
|
1902
|
+
setter(th ? { ...th, on: true } : null)
|
|
1903
|
+
clearTimeout(rulerTimers.current[key])
|
|
1904
|
+
rulerTimers.current[key] = setTimeout(() => setter((p) => (p ? { ...p, on: false } : p)), 900)
|
|
1905
|
+
}
|
|
1906
|
+
useEffect(() => setSrcThumb(thumbOf(sourceRef.current)), [source, fit])
|
|
1907
|
+
useEffect(() => {
|
|
1908
|
+
const el = resultRef.current
|
|
1909
|
+
// 流式输出时跟着最新一行往下走
|
|
1910
|
+
if (el && status === 'streaming') el.scrollTop = el.scrollHeight
|
|
1911
|
+
setResThumb(thumbOf(el))
|
|
1912
|
+
}, [result, fit, status])
|
|
1913
|
+
const abortRef = useRef(null)
|
|
1914
|
+
const resultRef = useRef(null)
|
|
1915
|
+
const sourceRef = useRef(null)
|
|
1916
|
+
|
|
1917
|
+
// 草稿和偏好落 localStorage:切到别的面板再回来不丢。流式输出时 delta 很密,草稿写入做 400ms 去抖
|
|
1918
|
+
useEffect(() => {
|
|
1919
|
+
const id = setTimeout(() => writeJson(DRAFT_KEY, { source, result }), 400)
|
|
1920
|
+
return () => clearTimeout(id)
|
|
1921
|
+
}, [source, result])
|
|
1922
|
+
useEffect(() => writeJson(PREFS_KEY, { modelKey: modelKeyState, direction, historyOpen, skin }), [modelKeyState, direction, historyOpen, skin])
|
|
1923
|
+
useEffect(() => writeJson(HISTORY_KEY, history), [history])
|
|
1924
|
+
|
|
1925
|
+
// 「确认清空」3 秒后自动撤回
|
|
1926
|
+
useEffect(() => {
|
|
1927
|
+
if (!clearArmed) return undefined
|
|
1928
|
+
const id = setTimeout(() => setClearArmed(false), 3000)
|
|
1929
|
+
return () => clearTimeout(id)
|
|
1930
|
+
}, [clearArmed])
|
|
1931
|
+
|
|
1932
|
+
const loadModels = useCallback(
|
|
1933
|
+
async (refresh) => {
|
|
1934
|
+
setModelsLoading(true)
|
|
1935
|
+
setModelsError('')
|
|
1936
|
+
try {
|
|
1937
|
+
const payload = await fetchModels(refresh)
|
|
1938
|
+
const list = Array.isArray(payload.models) ? payload.models : []
|
|
1939
|
+
setModels(list)
|
|
1940
|
+
setSkipped(Array.isArray(payload.skipped) ? payload.skipped.length : 0)
|
|
1941
|
+
setDefaultRoute(payload.default && payload.default.provider && payload.default.model ? payload.default : null)
|
|
1942
|
+
// 上次选的模型已经被用户从 DSH 里删掉 → 退回跟随默认
|
|
1943
|
+
setModelKeyState((prev) => {
|
|
1944
|
+
const parsed = parseKey(prev)
|
|
1945
|
+
if (!parsed) return prev
|
|
1946
|
+
return list.some((m) => m.provider === parsed.provider && m.model === parsed.model) ? prev : ''
|
|
1947
|
+
})
|
|
1948
|
+
} catch (err) {
|
|
1949
|
+
setModelsError(String(err?.message || err))
|
|
1950
|
+
} finally {
|
|
1951
|
+
setModelsLoading(false)
|
|
1952
|
+
}
|
|
1953
|
+
},
|
|
1954
|
+
[],
|
|
1955
|
+
)
|
|
1956
|
+
|
|
1957
|
+
useEffect(() => {
|
|
1958
|
+
loadModels(false)
|
|
1959
|
+
}, [loadModels])
|
|
1960
|
+
|
|
1961
|
+
const list = models ?? EMPTY_LIST
|
|
1962
|
+
const groups = useMemo(() => groupModels(list), [list])
|
|
1963
|
+
// 当前生效的模型:用户选了就用选的(必须在当前列表里),否则跟随 DSH 默认
|
|
1964
|
+
const selected = useMemo(() => {
|
|
1965
|
+
const parsed = parseKey(modelKeyState)
|
|
1966
|
+
if (!parsed) return null
|
|
1967
|
+
return list.find((m) => m.provider === parsed.provider && m.model === parsed.model) || null
|
|
1968
|
+
}, [modelKeyState, list])
|
|
1969
|
+
const effective = selected || defaultRoute
|
|
1970
|
+
|
|
1971
|
+
const canTranslate = source.trim().length > 0 && Boolean(effective) && status !== 'streaming'
|
|
1972
|
+
const hasText = Boolean(source.trim())
|
|
1973
|
+
// 译文栏的语言标签:有结果时显示这次实际译成的语言,没结果时才显示「如果现在翻会译成什么」
|
|
1974
|
+
const target = hasText ? resolveTarget(direction, source) : null
|
|
1975
|
+
const shownTarget = status === 'done' ? usedTarget : target
|
|
1976
|
+
|
|
1977
|
+
const cancel = useCallback(() => {
|
|
1978
|
+
abortRef.current?.abort()
|
|
1979
|
+
}, [])
|
|
1980
|
+
|
|
1981
|
+
const runTranslate = useCallback(async () => {
|
|
1982
|
+
const text = source.trim()
|
|
1983
|
+
if (!text) return
|
|
1984
|
+
const to = resolveTarget(direction, source)
|
|
1985
|
+
const route = selected || defaultRoute
|
|
1986
|
+
if (!route) {
|
|
1987
|
+
setStatus('error')
|
|
1988
|
+
setError(t.noModels)
|
|
1989
|
+
return
|
|
1990
|
+
}
|
|
1991
|
+
abortRef.current?.abort()
|
|
1992
|
+
const controller = new AbortController()
|
|
1993
|
+
abortRef.current = controller
|
|
1994
|
+
const started = performance.now()
|
|
1995
|
+
setStatus('streaming')
|
|
1996
|
+
setError('')
|
|
1997
|
+
setResult('')
|
|
1998
|
+
setTruncated(false)
|
|
1999
|
+
setCancelled(false)
|
|
2000
|
+
setElapsed(0)
|
|
2001
|
+
setUsedRoute({ provider: route.provider, model: route.model, name: route.name || route.model })
|
|
2002
|
+
setUsedTarget(to)
|
|
2003
|
+
setCurrentId(null)
|
|
2004
|
+
// 色场的历史卡盖在译文位置上,开始翻译就收起它,免得挡住译文
|
|
2005
|
+
if (skin === 'field') setHistoryOpen(false)
|
|
2006
|
+
let acc = ''
|
|
2007
|
+
try {
|
|
2008
|
+
const done = await streamTranslate({
|
|
2009
|
+
text,
|
|
2010
|
+
target: to,
|
|
2011
|
+
provider: route.provider,
|
|
2012
|
+
model: route.model,
|
|
2013
|
+
signal: controller.signal,
|
|
2014
|
+
onMeta: (meta) => meta?.model && setUsedRoute({ provider: meta.provider, model: meta.model, name: route.name || meta.model }),
|
|
2015
|
+
onDelta: (delta) => {
|
|
2016
|
+
acc += delta
|
|
2017
|
+
setResult((prev) => prev + delta)
|
|
2018
|
+
},
|
|
2019
|
+
})
|
|
2020
|
+
if (typeof done.text === 'string') {
|
|
2021
|
+
acc = done.text
|
|
2022
|
+
setResult(done.text)
|
|
2023
|
+
}
|
|
2024
|
+
const ms = Number(done.elapsedMs) || performance.now() - started
|
|
2025
|
+
setElapsed(ms)
|
|
2026
|
+
setTruncated(Boolean(done.truncated))
|
|
2027
|
+
const used = { provider: done.provider || route.provider, model: done.model || route.model }
|
|
2028
|
+
setUsedRoute({ ...used, name: route.name || used.model })
|
|
2029
|
+
setStatus('done')
|
|
2030
|
+
// 完成的翻译进历史
|
|
2031
|
+
const entry = {
|
|
2032
|
+
id: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
2033
|
+
source: text,
|
|
2034
|
+
result: acc,
|
|
2035
|
+
target: to,
|
|
2036
|
+
provider: used.provider,
|
|
2037
|
+
model: used.model,
|
|
2038
|
+
modelName: route.name || used.model,
|
|
2039
|
+
at: Date.now(),
|
|
2040
|
+
elapsedMs: ms,
|
|
2041
|
+
truncated: Boolean(done.truncated),
|
|
2042
|
+
}
|
|
2043
|
+
setHistory((prev) => pushHistory(prev, entry))
|
|
2044
|
+
setCurrentId(entry.id)
|
|
2045
|
+
} catch (err) {
|
|
2046
|
+
if (controller.signal.aborted || err?.cancelled) {
|
|
2047
|
+
if (abortRef.current !== controller) return
|
|
2048
|
+
// 取消后已经收到的那部分留着给用户看,但要明确标成「已取消的部分结果」
|
|
2049
|
+
const partial = acc.trim().length > 0
|
|
2050
|
+
setCancelled(partial)
|
|
2051
|
+
setElapsed(partial ? performance.now() - started : 0)
|
|
2052
|
+
setStatus(partial ? 'done' : 'idle')
|
|
2053
|
+
return
|
|
2054
|
+
}
|
|
2055
|
+
const message = String(err?.message || err)
|
|
2056
|
+
setStatus('error')
|
|
2057
|
+
setError(message === '__stream_broken__' ? t.streamBroken : message)
|
|
2058
|
+
} finally {
|
|
2059
|
+
if (abortRef.current === controller) abortRef.current = null
|
|
2060
|
+
}
|
|
2061
|
+
}, [source, direction, selected, defaultRoute, t, skin])
|
|
2062
|
+
|
|
2063
|
+
const onSourceKey = (event) => {
|
|
2064
|
+
if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
|
|
2065
|
+
event.preventDefault()
|
|
2066
|
+
if (canTranslate) runTranslate()
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
useEffect(() => {
|
|
2071
|
+
const onKey = (event) => {
|
|
2072
|
+
// 输入法组合中按 Esc 是在取消候选词,不是取消翻译;焦点在历史搜索框时也别响应
|
|
2073
|
+
if (event.key !== 'Escape' || event.isComposing || event.keyCode === 229) return
|
|
2074
|
+
if (event.target?.closest?.('.qt-history-search, .qt-fhist-search')) return
|
|
2075
|
+
if (!abortRef.current) return
|
|
2076
|
+
event.preventDefault()
|
|
2077
|
+
abortRef.current.abort()
|
|
2078
|
+
}
|
|
2079
|
+
window.addEventListener('keydown', onKey)
|
|
2080
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
2081
|
+
}, [])
|
|
2082
|
+
|
|
2083
|
+
useEffect(() => () => abortRef.current?.abort(), [])
|
|
2084
|
+
|
|
2085
|
+
const copyResult = async () => {
|
|
2086
|
+
if (!result) return
|
|
2087
|
+
try {
|
|
2088
|
+
await navigator.clipboard.writeText(result)
|
|
2089
|
+
setCopied(true)
|
|
2090
|
+
setCopyFailed(false)
|
|
2091
|
+
setTimeout(() => setCopied(false), 1500)
|
|
2092
|
+
} catch {
|
|
2093
|
+
resultRef.current?.select()
|
|
2094
|
+
setCopyFailed(true)
|
|
2095
|
+
setTimeout(() => setCopyFailed(false), 3000)
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
const resetOutcome = () => {
|
|
2100
|
+
setStatus('idle')
|
|
2101
|
+
setError('')
|
|
2102
|
+
setElapsed(0)
|
|
2103
|
+
setTruncated(false)
|
|
2104
|
+
setCancelled(false)
|
|
2105
|
+
setUsedRoute(null)
|
|
2106
|
+
setUsedTarget(null)
|
|
2107
|
+
setCurrentId(null)
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
// 真正的互换:原文 ⇄ 译文,方向翻转;再点一次就换回来
|
|
2111
|
+
const swap = () => {
|
|
2112
|
+
if (!result || status === 'streaming') return
|
|
2113
|
+
const s = source
|
|
2114
|
+
const r = result
|
|
2115
|
+
setSource(r)
|
|
2116
|
+
setResult(s)
|
|
2117
|
+
resetOutcome()
|
|
2118
|
+
if (direction === 'en2zh') setDirection('zh2en')
|
|
2119
|
+
else if (direction === 'zh2en') setDirection('en2zh')
|
|
2120
|
+
sourceRef.current?.focus()
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2123
|
+
const clearAll = () => {
|
|
2124
|
+
abortRef.current?.abort()
|
|
2125
|
+
abortRef.current = null
|
|
2126
|
+
setSource('')
|
|
2127
|
+
setResult('')
|
|
2128
|
+
resetOutcome()
|
|
2129
|
+
sourceRef.current?.focus()
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
// 回看一条历史:填回两栏,方向若与之矛盾就顺手改过来;窄屏下顺手收起抽屉,别挡着译文
|
|
2133
|
+
const pickHistory = (e) => {
|
|
2134
|
+
abortRef.current?.abort()
|
|
2135
|
+
abortRef.current = null
|
|
2136
|
+
setSource(e.source)
|
|
2137
|
+
setResult(e.result)
|
|
2138
|
+
setStatus('done')
|
|
2139
|
+
setError('')
|
|
2140
|
+
setElapsed(e.elapsedMs || 0)
|
|
2141
|
+
setTruncated(Boolean(e.truncated))
|
|
2142
|
+
setCancelled(false)
|
|
2143
|
+
setUsedRoute({ provider: e.provider, model: e.model, name: e.modelName })
|
|
2144
|
+
setUsedTarget(e.target)
|
|
2145
|
+
setCurrentId(e.id)
|
|
2146
|
+
if (direction === 'en2zh' && e.target === 'en') setDirection('zh2en')
|
|
2147
|
+
else if (direction === 'zh2en' && e.target === 'zh') setDirection('en2zh')
|
|
2148
|
+
// 窄屏下顺手收起抽屉;色场的历史卡盖在译文上,回看时一律收起
|
|
2149
|
+
if (window.innerWidth <= 720 || skin === 'field') setHistoryOpen(false)
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
const deleteHistory = (id) => {
|
|
2153
|
+
setHistory((prev) => prev.filter((e) => e.id !== id))
|
|
2154
|
+
if (id === currentId) setCurrentId(null)
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
const clearHistory = () => {
|
|
2158
|
+
if (!clearArmed) return setClearArmed(true)
|
|
2159
|
+
setHistory([])
|
|
2160
|
+
setHistoryQuery('')
|
|
2161
|
+
setCurrentId(null)
|
|
2162
|
+
setClearArmed(false)
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
// 没有任何可用路由时整个面板换成空状态:区分「真没有模型」「服务商没响应」「列表读取失败」
|
|
2166
|
+
const modelsMissing = !modelsLoading && !defaultRoute && list.length === 0 && (models !== null || Boolean(modelsError))
|
|
2167
|
+
const emptyMessage = modelsError
|
|
2168
|
+
? `${t.loadModelsFailed}:${modelsError}`
|
|
2169
|
+
: skipped > 0
|
|
2170
|
+
? t.someSkipped(skipped)
|
|
2171
|
+
: t.noModels
|
|
2172
|
+
|
|
2173
|
+
const streaming = status === 'streaming'
|
|
2174
|
+
const shownArrow = arrowOf(shownTarget || (status === 'done' ? usedTarget : null))
|
|
2175
|
+
const cleanDone = status === 'done' && !cancelled && !truncated && Boolean(result)
|
|
2176
|
+
const today = new Date()
|
|
2177
|
+
const deskDate = `${today.getDate()} ${MONTHS[today.getMonth()]} ${today.getFullYear()}`
|
|
2178
|
+
const noDrag = { WebkitAppRegion: 'no-drag' }
|
|
2179
|
+
const kbdLabel = `${modKey === 'Ctrl' ? 'Ctrl' : '⌘'} ↵`
|
|
2180
|
+
|
|
2181
|
+
const segButton = (value, label) =>
|
|
2182
|
+
h('button', { type: 'button', 'aria-pressed': direction === value ? 'true' : 'false', onClick: () => setDirection(value), disabled: streaming }, label)
|
|
2183
|
+
|
|
2184
|
+
// 硫酸纸右上角:这次翻译的状态
|
|
2185
|
+
const statusChip = () => {
|
|
2186
|
+
if (streaming) return h('span', { className: 'qt-chip qt-live' }, t.receiving)
|
|
2187
|
+
if (status !== 'done') return h('span', { className: 'qt-chip' }, t.standby)
|
|
2188
|
+
if (cancelled) return h('span', { className: 'qt-chip qt-chip-warn', title: t.cancelledPartial }, t.cancelledPartial)
|
|
2189
|
+
if (truncated) return h('span', { className: 'qt-chip qt-chip-warn', title: t.truncated }, t.truncated)
|
|
2190
|
+
return h('span', { className: 'qt-chip qt-chip-ok' }, `${t.done} ${fmtElapsed(elapsed, t)}`)
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
// 方格本右上角:这一页会译成什么(预测值);翻译中显示「锁定」
|
|
2194
|
+
const sourceHint = streaming
|
|
2195
|
+
? h('span', { className: 'qt-locked' }, `[ ${t.locked} ]`)
|
|
2196
|
+
: hasText
|
|
2197
|
+
? h('span', null, direction === 'auto' ? `${t.auto} → ${langName(target)}` : `→ ${langName(target)}`)
|
|
2198
|
+
: h('span', null, direction === 'auto' ? `[ ${t.auto} ]` : '')
|
|
2199
|
+
|
|
2200
|
+
// 牛皮纸标签上的大字:手动方向优先;只有「自动」时才看上次实际译成的方向
|
|
2201
|
+
const bigTarget = direction === 'en2zh' ? 'zh' : direction === 'zh2en' ? 'en' : streaming || status === 'done' ? usedTarget || target : target
|
|
2202
|
+
const bigLabel = bigTarget === 'en' ? t.zh2en : bigTarget === 'zh' ? t.en2zh : t.auto
|
|
2203
|
+
|
|
2204
|
+
const narrow = fit.narrow
|
|
2205
|
+
const compStyle = narrow ? undefined : { zoom: fit.scale }
|
|
2206
|
+
// 分享卡片的数据:两种风格共用,色场多带一个品牌色
|
|
2207
|
+
const openShare = () => {
|
|
2208
|
+
let brand = ''
|
|
2209
|
+
try {
|
|
2210
|
+
brand = rootRef.current && typeof getComputedStyle === 'function' ? getComputedStyle(rootRef.current).getPropertyValue('--dsw-alias-brand-primary').trim() : ''
|
|
2211
|
+
} catch {
|
|
2212
|
+
brand = ''
|
|
2213
|
+
}
|
|
2214
|
+
setShareData({
|
|
2215
|
+
source,
|
|
2216
|
+
result,
|
|
2217
|
+
target: usedTarget || shownTarget || resolveTarget(direction, source),
|
|
2218
|
+
modelName: usedRoute?.name || usedRoute?.model || selected?.name || defaultRoute?.model || '',
|
|
2219
|
+
elapsedMs: status === 'done' ? elapsed : 0,
|
|
2220
|
+
t,
|
|
2221
|
+
skin,
|
|
2222
|
+
brand,
|
|
2223
|
+
})
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
if (skin === 'field') return fieldView()
|
|
2227
|
+
|
|
2228
|
+
/** F 色场:两块大圆角容器(素色原文 + 品牌色译文),坐标照画板 F(1200×696 工作区)。 */
|
|
2229
|
+
function fieldView() {
|
|
2230
|
+
// 原文那块写成哪种语言:有字或手动方向时按预测;空白自动时按画板写 English
|
|
2231
|
+
const srcLang = target ? (target === 'zh' ? 'en' : 'zh') : direction === 'zh2en' ? 'zh' : 'en'
|
|
2232
|
+
const dstLang = shownTarget || (direction === 'zh2en' ? 'en' : 'zh')
|
|
2233
|
+
const srcHint = streaming
|
|
2234
|
+
? h('span', { className: 'qt-fhint is-locked' }, t.fieldLocked)
|
|
2235
|
+
: h('span', { className: 'qt-fhint' }, direction === 'auto' ? (hasText ? t.fieldAutoTo(target) : t.fieldAuto) : hasText ? t.autoHint(target) : '')
|
|
2236
|
+
const fieldStatus = streaming
|
|
2237
|
+
? h('span', { className: 'qt-fhint' }, t.translating)
|
|
2238
|
+
: status !== 'done'
|
|
2239
|
+
? h('span', { className: 'qt-fhint' }, status === 'error' ? '' : t.standby)
|
|
2240
|
+
: cancelled
|
|
2241
|
+
? h('span', { className: 'qt-fhint' }, h('span', { className: 'qt-fchip-warn', title: t.cancelledPartial }, t.cancelledPartial))
|
|
2242
|
+
: truncated
|
|
2243
|
+
? h('span', { className: 'qt-fhint' }, h('span', { className: 'qt-fchip-warn', title: t.truncated }, t.truncated))
|
|
2244
|
+
: h('span', { className: 'qt-fhint qt-fchip-ok' }, `${t.done} · ${fmtElapsed(elapsed, t)}`)
|
|
2245
|
+
const histOpen = historyOpen && !modelsMissing
|
|
2246
|
+
const fhb = (props, ...kids) => h('button', { type: 'button', className: 'qt-fhb', style: noDrag, ...props }, ...kids)
|
|
2247
|
+
|
|
2248
|
+
const srcBox = h(
|
|
2249
|
+
'section',
|
|
2250
|
+
{ className: 'qt-fbox qt-fsrc', 'aria-label': t.source },
|
|
2251
|
+
h(
|
|
2252
|
+
'div',
|
|
2253
|
+
{ className: 'qt-frow' },
|
|
2254
|
+
h('span', { className: 'qt-flang', 'data-lang': srcLang }, nativeName(srcLang)),
|
|
2255
|
+
srcHint,
|
|
2256
|
+
h('div', { className: 'qt-ftrack', role: 'group', 'aria-label': t.direction }, segButton('en2zh', t.en2zh), segButton('zh2en', t.zh2en), segButton('auto', t.auto)),
|
|
2257
|
+
),
|
|
2258
|
+
h('textarea', {
|
|
2259
|
+
ref: sourceRef,
|
|
2260
|
+
className: 'qt-fta',
|
|
2261
|
+
value: source,
|
|
2262
|
+
placeholder: t.sourcePlaceholder,
|
|
2263
|
+
spellCheck: false,
|
|
2264
|
+
autoFocus: true,
|
|
2265
|
+
readOnly: streaming,
|
|
2266
|
+
onKeyDown: onSourceKey,
|
|
2267
|
+
onChange: (event) => setSource(event.target.value),
|
|
2268
|
+
}),
|
|
2269
|
+
h(
|
|
2270
|
+
'div',
|
|
2271
|
+
{ className: 'qt-ffoot' },
|
|
2272
|
+
h('span', { className: 'qt-fcount' }, `${source.length} ${t.chars}`),
|
|
2273
|
+
h('button', { type: 'button', className: 'qt-fclear', onClick: clearAll, title: t.clearTitle, disabled: streaming || (!source && !result) }, t.clear),
|
|
2274
|
+
streaming
|
|
2275
|
+
? h('button', { type: 'button', className: 'qt-fgo is-stop', onClick: cancel, title: 'Esc' }, t.cancel, h('kbd', null, 'Esc'))
|
|
2276
|
+
: h('button', { type: 'button', className: 'qt-fgo qt-fgo-primary', disabled: !canTranslate, onClick: runTranslate, title: `${modKey} + Enter` }, t.translate, h('kbd', null, kbdLabel)),
|
|
2277
|
+
),
|
|
2278
|
+
)
|
|
2279
|
+
|
|
2280
|
+
const swapBtn = h('button', { type: 'button', className: 'qt-fswap', title: t.swap, 'aria-label': t.swap, disabled: !result || streaming, onClick: swap }, h(SwapIcon))
|
|
2281
|
+
|
|
2282
|
+
const fieldBox = h(
|
|
2283
|
+
'section',
|
|
2284
|
+
{ className: 'qt-fbox qt-ffield', 'aria-label': t.result },
|
|
2285
|
+
h('span', { className: 'qt-fwm', 'data-lang': dstLang, 'aria-hidden': 'true' }, dstLang === 'en' ? 'A' : '文'),
|
|
2286
|
+
streaming ? h('div', { className: 'qt-fprog', 'aria-hidden': 'true' }) : null,
|
|
2287
|
+
h('div', { className: 'qt-frow' }, h('span', { className: 'qt-flang', 'data-lang': dstLang }, nativeName(dstLang)), fieldStatus),
|
|
2288
|
+
status === 'error' && error
|
|
2289
|
+
? h('div', { className: 'qt-ferror', role: 'alert' }, h('span', { className: 'qt-error-text' }, error), h('button', { type: 'button', onClick: runTranslate }, t.retry))
|
|
2290
|
+
: null,
|
|
2291
|
+
h(
|
|
2292
|
+
'div',
|
|
2293
|
+
{ className: 'qt-fbody' },
|
|
2294
|
+
h('textarea', {
|
|
2295
|
+
ref: resultRef,
|
|
2296
|
+
className: 'qt-fta qt-fres',
|
|
2297
|
+
'data-lang': dstLang,
|
|
2298
|
+
value: result,
|
|
2299
|
+
placeholder: t.resultPlaceholder,
|
|
2300
|
+
readOnly: true,
|
|
2301
|
+
spellCheck: false,
|
|
2302
|
+
}),
|
|
2303
|
+
!result && !streaming && status !== 'error'
|
|
2304
|
+
? h('div', { className: 'qt-fwait', 'aria-hidden': 'true' }, h('b', null, t.waiting), h('span', null, t.waitingHint(modKey === 'Ctrl' ? 'Ctrl' : '⌘')))
|
|
2305
|
+
: null,
|
|
2306
|
+
),
|
|
2307
|
+
h(
|
|
2308
|
+
'div',
|
|
2309
|
+
{ className: 'qt-fstats' },
|
|
2310
|
+
h('span', null, `${t.fSrc} ${source.length} ${t.chars}`),
|
|
2311
|
+
h('span', null, `${t.fDst} ${result ? result.length : '—'} ${t.chars}`),
|
|
2312
|
+
h('span', null, `${t.statTime} ${status === 'done' && elapsed ? fmtElapsed(elapsed, t) : '—'}`),
|
|
2313
|
+
),
|
|
2314
|
+
h(
|
|
2315
|
+
'div',
|
|
2316
|
+
{ className: 'qt-ffoot' },
|
|
2317
|
+
h(ModelPicker, { groups, defaultRoute, value: modelKeyState, onChange: setModelKeyState, loading: modelsLoading, disabled: modelsMissing, t, skin: 'field' }),
|
|
2318
|
+
h('span', { className: 'qt-spacer' }),
|
|
2319
|
+
h('button', { type: 'button', className: 'qt-flink qt-share-btn', disabled: !result || streaming, onClick: openShare }, t.share),
|
|
2320
|
+
h(
|
|
2321
|
+
'button',
|
|
2322
|
+
{ type: 'button', className: `qt-fcopy ${copyFailed ? 'is-warn' : ''}`, onClick: copyResult, disabled: !result, title: copyFailed ? t.copyFailedHint.replace('{key}', modKey) : '' },
|
|
2323
|
+
copyFailed ? t.copyFailed : copied ? t.copied : t.copy,
|
|
2324
|
+
),
|
|
2325
|
+
),
|
|
2326
|
+
)
|
|
2327
|
+
|
|
2328
|
+
const hist = histOpen
|
|
2329
|
+
? h(FieldHistory, {
|
|
2330
|
+
history,
|
|
2331
|
+
currentId,
|
|
2332
|
+
query: historyQuery,
|
|
2333
|
+
onQuery: setHistoryQuery,
|
|
2334
|
+
onPick: pickHistory,
|
|
2335
|
+
onDelete: deleteHistory,
|
|
2336
|
+
onClear: clearHistory,
|
|
2337
|
+
onClose: () => setHistoryOpen(false),
|
|
2338
|
+
clearArmed,
|
|
2339
|
+
t,
|
|
2340
|
+
lang,
|
|
2341
|
+
})
|
|
2342
|
+
: null
|
|
2343
|
+
|
|
2344
|
+
return h(
|
|
2345
|
+
'div',
|
|
2346
|
+
{ ref: rootRef, className: 'qt-root qt-skin-field', 'data-state': status, 'data-tone': tone },
|
|
2347
|
+
h(
|
|
2348
|
+
'header',
|
|
2349
|
+
{ className: `qt-fhead ${narrow ? 'is-narrow' : ''}`, 'data-window-drag': '' },
|
|
2350
|
+
h('span', { className: 'qt-ftitle' }, t.deskTitle),
|
|
2351
|
+
h('span', { className: 'qt-fsub' }, `${t.title} · DSH Plugin · by ${AUTHOR}`),
|
|
2352
|
+
h(
|
|
2353
|
+
'div',
|
|
2354
|
+
{ className: 'qt-ftrack', role: 'group', 'aria-label': t.skin, style: noDrag },
|
|
2355
|
+
h('button', { type: 'button', 'aria-pressed': 'false', onClick: () => setSkin('paper') }, h('span', { className: 'qt-fsw qt-fsw-paper', 'aria-hidden': 'true' }), t.skinPaper),
|
|
2356
|
+
h('button', { type: 'button', 'aria-pressed': 'true', onClick: () => setSkin('field') }, h('span', { className: 'qt-fsw qt-fsw-field', 'aria-hidden': 'true' }), t.skinField),
|
|
2357
|
+
),
|
|
2358
|
+
fhb({ 'aria-pressed': historyOpen ? 'true' : 'false', onClick: () => setHistoryOpen((v) => !v) }, t.history, h('span', { className: 'qt-fcnt' }, `${history.length}`)),
|
|
2359
|
+
fhb({ title: modelsError || t.refresh, 'aria-label': t.refresh, disabled: modelsLoading, onClick: () => loadModels(true) }, h(RefreshIcon), modelsLoading ? t.refreshing : narrow ? t.refreshShort : t.refresh),
|
|
2360
|
+
),
|
|
2361
|
+
h(
|
|
2362
|
+
'div',
|
|
2363
|
+
{ ref: boardRef, className: `qt-fboard ${narrow ? 'is-narrow' : ''}` },
|
|
2364
|
+
modelsMissing
|
|
2365
|
+
? h(
|
|
2366
|
+
'div',
|
|
2367
|
+
{ className: 'qt-fempty-card' },
|
|
2368
|
+
h('b', null, t.noModelsTitle),
|
|
2369
|
+
h('p', null, emptyMessage),
|
|
2370
|
+
h('button', { type: 'button', className: 'qt-fgo', onClick: () => loadModels(true), disabled: modelsLoading }, t.noModelsRefresh),
|
|
2371
|
+
)
|
|
2372
|
+
: h(
|
|
2373
|
+
'div',
|
|
2374
|
+
{ className: `qt-fcomp ${narrow ? 'is-narrow' : ''} ${histOpen ? 'is-hist' : ''}`, style: compStyle },
|
|
2375
|
+
srcBox,
|
|
2376
|
+
swapBtn,
|
|
2377
|
+
narrow && hist ? hist : fieldBox,
|
|
2378
|
+
narrow ? null : hist,
|
|
2379
|
+
),
|
|
2380
|
+
),
|
|
2381
|
+
shareData ? h(ShareSheet, { data: shareData, t, onClose: () => setShareData(null) }) : null,
|
|
2382
|
+
)
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2385
|
+
|
|
2386
|
+
const note = h(
|
|
2387
|
+
'section',
|
|
2388
|
+
{ className: 'qt-col qt-note', 'aria-label': t.source },
|
|
2389
|
+
h('div', { className: 'qt-paper', 'aria-hidden': 'true' }),
|
|
2390
|
+
h('div', { className: 'qt-rings', 'aria-hidden': 'true' }),
|
|
2391
|
+
h('div', { className: 'qt-holes', 'aria-hidden': 'true' }),
|
|
2392
|
+
h(
|
|
2393
|
+
'div',
|
|
2394
|
+
{ className: 'qt-note-in' },
|
|
2395
|
+
h('div', { className: 'qt-colhead' }, h('span', null, `${t.source} / Source`), sourceHint),
|
|
2396
|
+
h('div', { className: 'qt-dots', 'aria-hidden': 'true' }),
|
|
2397
|
+
h(
|
|
2398
|
+
'div',
|
|
2399
|
+
{ className: 'qt-tawrap' },
|
|
2400
|
+
h('textarea', {
|
|
2401
|
+
ref: sourceRef,
|
|
2402
|
+
className: 'qt-textarea qt-src',
|
|
2403
|
+
value: source,
|
|
2404
|
+
placeholder: t.sourcePlaceholder,
|
|
2405
|
+
spellCheck: false,
|
|
2406
|
+
autoFocus: true,
|
|
2407
|
+
// 流式输出期间锁住原文,避免译完了原文却和译文/历史条目对不上
|
|
2408
|
+
readOnly: streaming,
|
|
2409
|
+
onKeyDown: onSourceKey,
|
|
2410
|
+
onChange: (event) => setSource(event.target.value),
|
|
2411
|
+
onScroll: (event) => flashRuler('src', setSrcThumb, event.currentTarget),
|
|
2412
|
+
}),
|
|
2413
|
+
rulerOf(srcThumb),
|
|
2414
|
+
),
|
|
2415
|
+
h(
|
|
2416
|
+
'div',
|
|
2417
|
+
{ className: 'qt-note-foot' },
|
|
2418
|
+
h('span', { className: 'qt-meta' }, `${source.length} ${t.chars}`),
|
|
2419
|
+
h('button', { type: 'button', className: 'qt-tapebtn qt-clear', onClick: clearAll, title: t.clearTitle, disabled: streaming || (!source && !result) }, t.clear),
|
|
2420
|
+
narrow ? actions() : null,
|
|
2421
|
+
),
|
|
2422
|
+
),
|
|
2423
|
+
narrow ? null : actions(),
|
|
2424
|
+
)
|
|
2425
|
+
|
|
2426
|
+
function actions() {
|
|
2427
|
+
return h('div', { className: 'qt-actions' }, goButton())
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
function goButton() {
|
|
2431
|
+
return streaming
|
|
2432
|
+
? h('button', { type: 'button', className: 'qt-tapebtn qt-go qt-btn-stop', onClick: cancel, title: 'Esc' }, t.cancel, h('kbd', null, 'Esc'))
|
|
2433
|
+
: h('button', { type: 'button', className: 'qt-tapebtn qt-go qt-btn-primary', disabled: !canTranslate, onClick: runTranslate, title: `${modKey} + Enter` }, t.translate, h('kbd', null, kbdLabel))
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
const swapTape = h(
|
|
2437
|
+
'button',
|
|
2438
|
+
{ type: 'button', className: 'qt-swap', title: t.swap, 'aria-label': t.swap, disabled: !result || streaming, onClick: swap },
|
|
2439
|
+
h('small', { 'aria-hidden': 'true' }, '<>'),
|
|
2440
|
+
h('b', { 'aria-hidden': 'true' }, t.swapShort),
|
|
2441
|
+
)
|
|
2442
|
+
|
|
2443
|
+
const vellum = h(
|
|
2444
|
+
'section',
|
|
2445
|
+
{ className: 'qt-col qt-vellum', 'aria-label': t.result },
|
|
2446
|
+
h('div', { className: 'qt-paper', 'aria-hidden': 'true' }),
|
|
2447
|
+
h(
|
|
2448
|
+
'div',
|
|
2449
|
+
{ className: 'qt-vel-in' },
|
|
2450
|
+
h('div', { className: 'qt-colhead' }, h('span', null, `${t.result} / Translation`), h('span', null, shownArrow), statusChip()),
|
|
2451
|
+
h('div', { className: 'qt-dots', 'aria-hidden': 'true' }),
|
|
2452
|
+
status === 'error' && error
|
|
2453
|
+
? h(
|
|
2454
|
+
'div',
|
|
2455
|
+
{ className: 'qt-error', role: 'alert' },
|
|
2456
|
+
h('span', { className: 'qt-error-text' }, error),
|
|
2457
|
+
h('button', { type: 'button', className: 'qt-link qt-br', onClick: runTranslate }, t.retry),
|
|
2458
|
+
)
|
|
2459
|
+
: null,
|
|
2460
|
+
h(
|
|
2461
|
+
'div',
|
|
2462
|
+
{ className: 'qt-body' },
|
|
2463
|
+
h('textarea', {
|
|
2464
|
+
ref: resultRef,
|
|
2465
|
+
className: 'qt-textarea qt-res',
|
|
2466
|
+
'data-lang': shownTarget || 'zh',
|
|
2467
|
+
value: result,
|
|
2468
|
+
placeholder: t.resultPlaceholder,
|
|
2469
|
+
readOnly: true,
|
|
2470
|
+
spellCheck: false,
|
|
2471
|
+
onScroll: (event) => flashRuler('res', setResThumb, event.currentTarget),
|
|
2472
|
+
}),
|
|
2473
|
+
rulerOf(resThumb),
|
|
2474
|
+
!result && !streaming && status !== 'error'
|
|
2475
|
+
? h('div', { className: 'qt-waiting', 'aria-hidden': 'true' }, h('b', null, t.waiting), h('span', null, t.waitingHint(modKey === 'Ctrl' ? 'Ctrl' : '⌘')))
|
|
2476
|
+
: null,
|
|
2477
|
+
),
|
|
2478
|
+
h('div', { className: 'qt-dots qt-dots-end', 'aria-hidden': 'true' }),
|
|
2479
|
+
h(
|
|
2480
|
+
'div',
|
|
2481
|
+
{ className: 'qt-stats' },
|
|
2482
|
+
h('div', null, t.statSrc, h('b', null, hasText ? `${source.length}` : '—')),
|
|
2483
|
+
h('div', null, t.statDst, h('b', null, result ? `${result.length}` : '—')),
|
|
2484
|
+
h('div', null, t.statTime, h('b', null, status === 'done' && elapsed ? fmtElapsed(elapsed, t) : '—')),
|
|
2485
|
+
),
|
|
2486
|
+
h('div', { className: 'qt-bar', 'data-state': streaming ? 'streaming' : result ? 'done' : 'idle', 'aria-hidden': 'true' }),
|
|
2487
|
+
h(
|
|
2488
|
+
'div',
|
|
2489
|
+
{ className: 'qt-vfoot' },
|
|
2490
|
+
h(ModelPicker, {
|
|
2491
|
+
groups,
|
|
2492
|
+
defaultRoute,
|
|
2493
|
+
value: modelKeyState,
|
|
2494
|
+
onChange: setModelKeyState,
|
|
2495
|
+
loading: modelsLoading,
|
|
2496
|
+
disabled: modelsMissing,
|
|
2497
|
+
t,
|
|
2498
|
+
}),
|
|
2499
|
+
cleanDone && !narrow ? h(Signature) : null,
|
|
2500
|
+
h('span', { className: 'qt-spacer' }),
|
|
2501
|
+
h(
|
|
2502
|
+
'button',
|
|
2503
|
+
{
|
|
2504
|
+
type: 'button',
|
|
2505
|
+
className: `qt-link qt-br ${copyFailed ? 'qt-btn-warn' : ''}`,
|
|
2506
|
+
onClick: copyResult,
|
|
2507
|
+
disabled: !result,
|
|
2508
|
+
title: copyFailed ? t.copyFailedHint.replace('{key}', modKey) : '',
|
|
2509
|
+
},
|
|
2510
|
+
copyFailed ? t.copyFailed : copied ? t.copied : t.copy,
|
|
2511
|
+
),
|
|
2512
|
+
h(
|
|
2513
|
+
'button',
|
|
2514
|
+
{
|
|
2515
|
+
type: 'button',
|
|
2516
|
+
className: 'qt-link qt-br qt-share-btn',
|
|
2517
|
+
disabled: !result || streaming,
|
|
2518
|
+
onClick: openShare,
|
|
2519
|
+
},
|
|
2520
|
+
t.share,
|
|
2521
|
+
),
|
|
2522
|
+
),
|
|
2523
|
+
),
|
|
2524
|
+
cleanDone ? h(Stamp, { key: currentId || 'stamp', label: t.stamp, arrow: shownArrow.replace(/ >>> /, '>') }) : null,
|
|
2525
|
+
)
|
|
2526
|
+
|
|
2527
|
+
const tag = h(
|
|
2528
|
+
'div',
|
|
2529
|
+
{ className: 'qt-tag' },
|
|
2530
|
+
h('div', { className: 'qt-seg', role: 'group', 'aria-label': t.direction }, segButton('en2zh', t.en2zh), segButton('zh2en', t.zh2en), segButton('auto', t.auto)),
|
|
2531
|
+
h('div', { className: 'qt-tag-big', 'aria-hidden': 'true' }, bigLabel),
|
|
2532
|
+
)
|
|
2533
|
+
|
|
2534
|
+
return h(
|
|
2535
|
+
'div',
|
|
2536
|
+
{ ref: rootRef, className: 'qt-root', 'data-state': status },
|
|
2537
|
+
h(
|
|
2538
|
+
'header',
|
|
2539
|
+
{ className: 'qt-header', 'data-window-drag': '' },
|
|
2540
|
+
h('span', { className: 'qt-title' }, t.deskTitle),
|
|
2541
|
+
h('span', { className: 'qt-subtitle qt-mono' }, `[ ${t.title} ] DSH Plugin · by ${AUTHOR}`),
|
|
2542
|
+
h('span', { className: 'qt-spacer' }),
|
|
2543
|
+
h(
|
|
2544
|
+
'div',
|
|
2545
|
+
{ className: 'qt-skinsw qt-mono', role: 'group', 'aria-label': t.skin, style: noDrag },
|
|
2546
|
+
h('span', { className: 'qt-skinsw-k' }, `${t.skin}:`),
|
|
2547
|
+
h('button', { type: 'button', className: 'qt-hbtn', 'aria-pressed': 'true', onClick: () => setSkin('paper') }, t.skinPaper),
|
|
2548
|
+
h('span', { className: 'qt-skinsw-sep', 'aria-hidden': 'true' }, '/'),
|
|
2549
|
+
h('button', { type: 'button', className: 'qt-hbtn', 'aria-pressed': 'false', onClick: () => setSkin('field') }, t.skinField),
|
|
2550
|
+
),
|
|
2551
|
+
h(
|
|
2552
|
+
'button',
|
|
2553
|
+
{
|
|
2554
|
+
type: 'button',
|
|
2555
|
+
className: 'qt-hbtn',
|
|
2556
|
+
'aria-pressed': historyOpen ? 'true' : 'false',
|
|
2557
|
+
style: noDrag,
|
|
2558
|
+
onClick: () => setHistoryOpen((v) => !v),
|
|
2559
|
+
},
|
|
2560
|
+
t.history,
|
|
2561
|
+
h('span', { className: 'qt-badge' }, `${history.length}`),
|
|
2562
|
+
),
|
|
2563
|
+
h(
|
|
2564
|
+
'button',
|
|
2565
|
+
{
|
|
2566
|
+
type: 'button',
|
|
2567
|
+
className: 'qt-hbtn',
|
|
2568
|
+
title: modelsError || t.refresh,
|
|
2569
|
+
'aria-label': t.refresh,
|
|
2570
|
+
disabled: modelsLoading,
|
|
2571
|
+
style: noDrag,
|
|
2572
|
+
onClick: () => loadModels(true),
|
|
2573
|
+
},
|
|
2574
|
+
modelsLoading ? t.refreshing : t.refresh,
|
|
2575
|
+
),
|
|
2576
|
+
),
|
|
2577
|
+
h(
|
|
2578
|
+
'div',
|
|
2579
|
+
{ ref: boardRef, className: `qt-board ${narrow ? 'is-narrow' : ''}` },
|
|
2580
|
+
modelsMissing
|
|
2581
|
+
? h(
|
|
2582
|
+
'div',
|
|
2583
|
+
{ className: 'qt-empty-card' },
|
|
2584
|
+
h('div', { className: 'qt-paper', 'aria-hidden': 'true' }),
|
|
2585
|
+
h('b', null, t.noModelsTitle),
|
|
2586
|
+
h('p', null, emptyMessage),
|
|
2587
|
+
h('button', { type: 'button', className: 'qt-tapebtn qt-go qt-btn-primary', onClick: () => loadModels(true), disabled: modelsLoading }, t.noModelsRefresh),
|
|
2588
|
+
)
|
|
2589
|
+
: h(
|
|
2590
|
+
'div',
|
|
2591
|
+
{ className: `qt-comp ${narrow ? 'is-narrow' : ''}`, style: compStyle },
|
|
2592
|
+
h('span', { className: 'qt-deco-date', 'aria-hidden': 'true' }, deskDate),
|
|
2593
|
+
h(
|
|
2594
|
+
'span',
|
|
2595
|
+
{ className: 'qt-deco-side', 'aria-hidden': 'true' },
|
|
2596
|
+
'DSH-QT / V0.3',
|
|
2597
|
+
h('br'),
|
|
2598
|
+
shownArrow,
|
|
2599
|
+
modelsError ? h('br') : null,
|
|
2600
|
+
modelsError ? t.loadModelsFailed : skipped > 0 ? t.someSkipped(skipped) : null,
|
|
2601
|
+
),
|
|
2602
|
+
note,
|
|
2603
|
+
h('span', { className: 'qt-tape qt-tape-a', 'aria-hidden': 'true' }),
|
|
2604
|
+
h('span', { className: 'qt-tape qt-tape-b', 'aria-hidden': 'true' }),
|
|
2605
|
+
vellum,
|
|
2606
|
+
swapTape,
|
|
2607
|
+
narrow ? tag : null,
|
|
2608
|
+
historyOpen && narrow ? h('div', { className: 'qt-backdrop', onClick: () => setHistoryOpen(false), 'aria-hidden': 'true' }) : null,
|
|
2609
|
+
historyOpen
|
|
2610
|
+
? h(HistoryPanel, {
|
|
2611
|
+
history,
|
|
2612
|
+
currentId,
|
|
2613
|
+
query: historyQuery,
|
|
2614
|
+
onQuery: setHistoryQuery,
|
|
2615
|
+
onPick: pickHistory,
|
|
2616
|
+
onDelete: deleteHistory,
|
|
2617
|
+
onClear: clearHistory,
|
|
2618
|
+
clearArmed,
|
|
2619
|
+
t,
|
|
2620
|
+
lang,
|
|
2621
|
+
})
|
|
2622
|
+
: null,
|
|
2623
|
+
),
|
|
2624
|
+
!narrow && !modelsMissing ? h('div', { className: 'qt-tagwrap', style: { zoom: fit.scale } }, tag) : null,
|
|
2625
|
+
),
|
|
2626
|
+
shareData ? h(ShareSheet, { data: shareData, t, onClose: () => setShareData(null) }) : null,
|
|
2627
|
+
)
|
|
2628
|
+
}
|
|
2629
|
+
|
|
2630
|
+
function SidebarIcon({ size }) {
|
|
2631
|
+
return h(TranslateIcon, { size: size || 18 })
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
/* ============================== 入口 ================================ */
|
|
2635
|
+
|
|
2636
|
+
function apply(ctx) {
|
|
2637
|
+
ensureStyle()
|
|
2638
|
+
|
|
2639
|
+
// 语言跟随 DSH:有 locale 服务就用它,没有就跟随浏览器
|
|
2640
|
+
ctx.inject(['locale'], (c) => {
|
|
2641
|
+
const push = () => langStore.set(String(c.locale.getSnapshot()?.active || '').slice(0, 2).toLowerCase())
|
|
2642
|
+
push()
|
|
2643
|
+
c.on('locale/change', push)
|
|
2644
|
+
})
|
|
2645
|
+
|
|
2646
|
+
ctx.slots.inject('sidebar.panellist', () =>
|
|
2647
|
+
ctx.slots.register(
|
|
2648
|
+
{ name: 'sidebar.panellist', id: PANEL, order: 7, label: () => STR[langStore.get()]?.title || STR.en.title },
|
|
2649
|
+
SidebarIcon,
|
|
2650
|
+
),
|
|
2651
|
+
)
|
|
2652
|
+
ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: PANEL }, TranslatePanel))
|
|
2653
|
+
}
|
|
2654
|
+
|
|
2655
|
+
return { apply, inject: ['slots'] }
|
|
2656
|
+
},
|
|
2657
|
+
})
|