dsh-ai-subtitle 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +52 -5
- package/README.ja.md +34 -3
- package/README.ko.md +34 -3
- package/README.md +33 -3
- package/client.js +812 -29
- package/docs/DETAIL.md +1 -1
- package/docs/PLAN.md +3 -3
- package/docs/REVIEW.md +105 -0
- package/index.js +191 -5
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +4 -2
- package/scripts/check-client.mjs +17 -0
- package/src/api.js +394 -21
- package/src/cues.js +28 -4
- package/src/feedback.js +59 -0
- package/src/glossary.js +252 -0
- package/src/hints.js +32 -0
- package/src/jobs.js +18 -0
- package/src/llm.js +177 -0
- package/src/messages.js +19 -0
- package/src/paths.js +11 -0
- package/src/recent.js +34 -0
- package/src/review.js +317 -0
- package/src/runtime.js +30 -8
package/client.js
CHANGED
|
@@ -10,7 +10,7 @@ window.__ModuleLoader__.load({
|
|
|
10
10
|
const PANEL_ID = 'subtitle-studio-panel'
|
|
11
11
|
const API = '/dsh-ai-subtitle/api'
|
|
12
12
|
// Bump whenever the bundle needs to be distinguishable in the running page.
|
|
13
|
-
const BUILD = 'ui-2026-12-
|
|
13
|
+
const BUILD = 'ui-2026-12-05b'
|
|
14
14
|
function trace(message) {
|
|
15
15
|
try {
|
|
16
16
|
const payload = JSON.stringify({ msg: String(message).slice(0, 300) })
|
|
@@ -79,7 +79,7 @@ window.__ModuleLoader__.load({
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
const label = { font: 'inherit', padding: '6px 10px', borderRadius: 8, cursor: 'pointer' }
|
|
82
|
+
const label = { font: 'inherit', padding: '6px 10px', borderRadius: 8, cursor: 'pointer', minHeight: 32, boxSizing: 'border-box' }
|
|
83
83
|
const button = { ...label, className: 'subs-btn', border: '1px solid ' + tokens.border, background: 'transparent', color: tokens.text }
|
|
84
84
|
const primary = { ...button, className: 'subs-btn subs-btn-primary', borderColor: tokens.accent, color: tokens.accent, fontWeight: 600 }
|
|
85
85
|
const dangerButton = { ...button, className: 'subs-btn subs-btn-danger', color: tokens.danger, borderColor: tokens.danger }
|
|
@@ -314,6 +314,85 @@ window.__ModuleLoader__.load({
|
|
|
314
314
|
)
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
+
|
|
318
|
+
/** Native <select> popups follow the OS theme, which breaks inside the dark panel. */
|
|
319
|
+
function RouteSelect({ value, options, onChange, placeholder }) {
|
|
320
|
+
const [open, setOpen] = useState(false)
|
|
321
|
+
const [rect, setRect] = useState(null)
|
|
322
|
+
const anchor = useRef(null)
|
|
323
|
+
const current = options.find((option) => option.value === value)
|
|
324
|
+
|
|
325
|
+
const toggle = () => {
|
|
326
|
+
if (!open && anchor.current) {
|
|
327
|
+
const box = anchor.current.getBoundingClientRect()
|
|
328
|
+
setRect({ left: box.left, top: box.bottom + 4, width: box.width })
|
|
329
|
+
}
|
|
330
|
+
setOpen(!open)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return h(
|
|
334
|
+
'div',
|
|
335
|
+
{ style: { marginTop: 6, position: 'relative' } },
|
|
336
|
+
h(
|
|
337
|
+
'div',
|
|
338
|
+
{
|
|
339
|
+
ref: anchor,
|
|
340
|
+
onClick: toggle,
|
|
341
|
+
style: { ...input, display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 8, cursor: 'pointer', userSelect: 'none' },
|
|
342
|
+
},
|
|
343
|
+
h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, current ? current.label : placeholder || '选择模型'),
|
|
344
|
+
h('span', { style: { opacity: 0.6, fontSize: 10 } }, open ? '▲' : '▼'),
|
|
345
|
+
),
|
|
346
|
+
open
|
|
347
|
+
? h('div', { key: 'backdrop', style: { position: 'fixed', inset: 0, zIndex: 900 }, onClick: () => setOpen(false) })
|
|
348
|
+
: null,
|
|
349
|
+
open && rect
|
|
350
|
+
? h(
|
|
351
|
+
'div',
|
|
352
|
+
{
|
|
353
|
+
key: 'menu',
|
|
354
|
+
style: {
|
|
355
|
+
position: 'fixed',
|
|
356
|
+
left: rect.left,
|
|
357
|
+
top: rect.top,
|
|
358
|
+
width: rect.width,
|
|
359
|
+
maxHeight: 260,
|
|
360
|
+
overflow: 'auto',
|
|
361
|
+
zIndex: 1000,
|
|
362
|
+
padding: 4,
|
|
363
|
+
borderRadius: 8,
|
|
364
|
+
border: '1px solid ' + tokens.border,
|
|
365
|
+
background: 'var(--dsw-alias-bg-primary, #1b1f27)',
|
|
366
|
+
boxShadow: '0 12px 32px rgba(0,0,0,0.45)',
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
options.map((option) =>
|
|
370
|
+
h(
|
|
371
|
+
'div',
|
|
372
|
+
{
|
|
373
|
+
key: option.value,
|
|
374
|
+
onClick: () => {
|
|
375
|
+
onChange(option.value)
|
|
376
|
+
setOpen(false)
|
|
377
|
+
},
|
|
378
|
+
style: {
|
|
379
|
+
padding: '8px 10px',
|
|
380
|
+
fontSize: 12,
|
|
381
|
+
borderRadius: 6,
|
|
382
|
+
cursor: 'pointer',
|
|
383
|
+
color: option.value === value ? tokens.accent : tokens.text,
|
|
384
|
+
background: option.value === value ? 'var(--subs-hover, rgba(127,127,127,0.16))' : 'transparent',
|
|
385
|
+
userSelect: 'none',
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
option.label,
|
|
389
|
+
),
|
|
390
|
+
),
|
|
391
|
+
)
|
|
392
|
+
: null,
|
|
393
|
+
)
|
|
394
|
+
}
|
|
395
|
+
|
|
317
396
|
/** A render error must never take the host page down with it. */
|
|
318
397
|
class Boundary extends React.Component {
|
|
319
398
|
constructor(props) {
|
|
@@ -364,12 +443,36 @@ window.__ModuleLoader__.load({
|
|
|
364
443
|
const [notice, setNotice] = useState('')
|
|
365
444
|
const [projects, setProjects] = useState([])
|
|
366
445
|
const [detail, setDetail] = useState(null)
|
|
446
|
+
const [review, setReview] = useState(null)
|
|
447
|
+
const [llmRoute, setLlmRoute] = useState(null)
|
|
448
|
+
const [translateBusy, setTranslateBusy] = useState(false)
|
|
449
|
+
const [translateJobId, setTranslateJobId] = useState('')
|
|
450
|
+
const [translateNotice, setTranslateNotice] = useState('')
|
|
451
|
+
const [hints, setHints] = useState({ tags: [], note: '' })
|
|
452
|
+
const [tagDraft, setTagDraft] = useState('')
|
|
453
|
+
const [contextDialog, setContextDialog] = useState(false)
|
|
454
|
+
const [glossaryInfo, setGlossaryInfo] = useState(null)
|
|
455
|
+
const [glossaryText, setGlossaryText] = useState('')
|
|
456
|
+
const [proofread, setProofread] = useState(true)
|
|
457
|
+
const [feedbackDraft, setFeedbackDraft] = useState({})
|
|
458
|
+
const [batchNote, setBatchNote] = useState('')
|
|
459
|
+
const [reviewBatch, setReviewBatch] = useState(null)
|
|
460
|
+
const [reviewInput, setReviewInput] = useState('')
|
|
461
|
+
const [reviewAllowEmpty, setReviewAllowEmpty] = useState(false)
|
|
367
462
|
const [cueSource, setCueSource] = useState('')
|
|
368
463
|
const [showHidden, setShowHidden] = useState(false)
|
|
369
464
|
const [editing, setEditing] = useState(false)
|
|
370
465
|
const [draft, setDraft] = useState([])
|
|
371
466
|
const [runtimeOpen, setRuntimeOpen] = useState(false)
|
|
372
467
|
const [picker, setPicker] = useState(null)
|
|
468
|
+
const [recent, setRecent] = useState({ files: [], dirs: [] })
|
|
469
|
+
const [recentOpen, setRecentOpen] = useState(false)
|
|
470
|
+
const [pickerTarget, setPickerTarget] = useState('install')
|
|
471
|
+
const [projectsInfo, setProjectsInfo] = useState(null)
|
|
472
|
+
const [projectsDialog, setProjectsDialog] = useState(false)
|
|
473
|
+
const [helpDialog, setHelpDialog] = useState(false)
|
|
474
|
+
const [projectsDraft, setProjectsDraft] = useState('')
|
|
475
|
+
const [projectsMove, setProjectsMove] = useState(true)
|
|
373
476
|
const [places, setPlaces] = useState([])
|
|
374
477
|
const lastDir = useRef('')
|
|
375
478
|
const [componentDialog, setComponentDialog] = useState('')
|
|
@@ -404,6 +507,7 @@ window.__ModuleLoader__.load({
|
|
|
404
507
|
useEffect(() => {
|
|
405
508
|
mounted.current = true
|
|
406
509
|
refresh()
|
|
510
|
+
loadProjectsInfo()
|
|
407
511
|
const timer = setInterval(refresh, 5000)
|
|
408
512
|
trace('body:mounted')
|
|
409
513
|
return () => {
|
|
@@ -438,7 +542,7 @@ window.__ModuleLoader__.load({
|
|
|
438
542
|
refresh()
|
|
439
543
|
}
|
|
440
544
|
|
|
441
|
-
const KIND_LABEL = { install: '安装', transcribe: '转写' }
|
|
545
|
+
const KIND_LABEL = { install: '安装', transcribe: '转写', translate: '翻译' }
|
|
442
546
|
const STATUS_LABEL = { running: '进行中', done: '完成', failed: '失败', cancelled: '已取消' }
|
|
443
547
|
const PHASE_LABEL = {
|
|
444
548
|
starting: '准备',
|
|
@@ -454,20 +558,84 @@ window.__ModuleLoader__.load({
|
|
|
454
558
|
audio: '音频',
|
|
455
559
|
asr: '识别',
|
|
456
560
|
post: '整理',
|
|
561
|
+
translate: '翻译',
|
|
457
562
|
done: '完成',
|
|
458
563
|
}
|
|
459
564
|
|
|
460
|
-
const
|
|
565
|
+
const applyPick = (target, chosen) => {
|
|
566
|
+
if (target === 'projects') setProjectsDraft(chosen)
|
|
567
|
+
else if (target === 'media') setMedia(chosen)
|
|
568
|
+
else setInstallDir(chosen)
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
const browseFor = async (mode, startDir, target = 'install') => {
|
|
461
572
|
const result = await callApi('/fs/pick', { method: 'POST', body: JSON.stringify({ mode }) })
|
|
462
573
|
if (result && result.path) {
|
|
463
|
-
|
|
464
|
-
else setMedia(result.path)
|
|
574
|
+
applyPick(target, result.path)
|
|
465
575
|
return
|
|
466
576
|
}
|
|
467
577
|
if (result && result.canceled) return
|
|
578
|
+
setPickerTarget(target)
|
|
468
579
|
openPicker(mode, startDir)
|
|
469
580
|
}
|
|
470
581
|
|
|
582
|
+
const openProjectsFolder = async () => {
|
|
583
|
+
const dir = projectsInfo ? projectsInfo.projectsDir : ''
|
|
584
|
+
const result = await callApi('/open-folder', { method: 'POST', body: JSON.stringify({ dir }) })
|
|
585
|
+
if (result.error) setNotice('打开失败:' + result.error)
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const loadProjectsInfo = async () => {
|
|
589
|
+
const info = await callApi('/settings')
|
|
590
|
+
if (!info.error) setProjectsInfo(info)
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const openProjectsDialog = async () => {
|
|
594
|
+
const info = await callApi('/settings')
|
|
595
|
+
if (info.error) {
|
|
596
|
+
setNotice('读取设置失败:' + info.error)
|
|
597
|
+
return
|
|
598
|
+
}
|
|
599
|
+
setProjectsInfo(info)
|
|
600
|
+
setProjectsDraft(info.projectsDir || info.defaultDir)
|
|
601
|
+
setProjectsMove(true)
|
|
602
|
+
setProjectsDialog(true)
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
const saveProjectsDir = async () => {
|
|
606
|
+
if (!projectsDraft.trim()) return
|
|
607
|
+
const result = await callApi('/settings/projects', {
|
|
608
|
+
method: 'POST',
|
|
609
|
+
body: JSON.stringify({ dir: projectsDraft.trim(), move: projectsMove }),
|
|
610
|
+
})
|
|
611
|
+
if (result.error) {
|
|
612
|
+
setNotice('切换失败:' + result.error)
|
|
613
|
+
return
|
|
614
|
+
}
|
|
615
|
+
const parts = ['项目目录已切换到 ' + result.projectsDir]
|
|
616
|
+
if (projectsMove) parts.push('已移动 ' + result.moved + ' 个项目')
|
|
617
|
+
if (result.failed && result.failed.length) parts.push('未移动:' + result.failed.join('、'))
|
|
618
|
+
setNotice(parts.join(','))
|
|
619
|
+
setProjectsDialog(false)
|
|
620
|
+
setDetail(null)
|
|
621
|
+
setEditing(false)
|
|
622
|
+
refresh()
|
|
623
|
+
loadProjectsInfo()
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
const clearTasks = async () => {
|
|
627
|
+
const result = await callApi('/job/clear', { method: 'POST', body: '{}' })
|
|
628
|
+
if (result.error) setNotice('清空失败:' + result.error)
|
|
629
|
+
else if (!result.removed) setNotice('没有可清空的任务')
|
|
630
|
+
refresh()
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const removeTask = async (id) => {
|
|
634
|
+
const result = await callApi('/job/remove', { method: 'POST', body: JSON.stringify({ id }) })
|
|
635
|
+
if (result.error || !result.ok) setNotice('删除失败:任务仍在运行或不存在')
|
|
636
|
+
refresh()
|
|
637
|
+
}
|
|
638
|
+
|
|
471
639
|
const cancelTask = async (id) => {
|
|
472
640
|
const result = await callApi('/job/cancel', { method: 'POST', body: JSON.stringify({ id }) })
|
|
473
641
|
setNotice(result.error ? '取消失败:' + result.error : '已取消任务 ' + id)
|
|
@@ -503,6 +671,9 @@ window.__ModuleLoader__.load({
|
|
|
503
671
|
const list = await callApi('/fs/places')
|
|
504
672
|
if (Array.isArray(list.places)) setPlaces(list.places)
|
|
505
673
|
}
|
|
674
|
+
const info = await callApi('/recent')
|
|
675
|
+
if (!info.error) setRecent({ files: info.files || [], dirs: info.dirs || [] })
|
|
676
|
+
setRecentOpen(false)
|
|
506
677
|
loadDir(mode, initial)
|
|
507
678
|
}
|
|
508
679
|
|
|
@@ -511,7 +682,7 @@ window.__ModuleLoader__.load({
|
|
|
511
682
|
loadDir(mode, entry.path)
|
|
512
683
|
return
|
|
513
684
|
}
|
|
514
|
-
|
|
685
|
+
applyPick('media', entry.path)
|
|
515
686
|
setPicker(null)
|
|
516
687
|
}
|
|
517
688
|
|
|
@@ -623,6 +794,219 @@ window.__ModuleLoader__.load({
|
|
|
623
794
|
refresh()
|
|
624
795
|
}
|
|
625
796
|
|
|
797
|
+
const reviewLabel = (progress) => {
|
|
798
|
+
if (!progress || progress.batches === 0) return null
|
|
799
|
+
if (progress.translated >= progress.batches) return h('span', { style: { color: tokens.ok } }, '已翻译')
|
|
800
|
+
if (progress.translated === 0) return h('span', { style: { color: tokens.warn } }, '待翻译')
|
|
801
|
+
return h('span', null, '翻译 ' + progress.translated + '/' + progress.batches + ' 批')
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
const exportProject = async (dir) => {
|
|
805
|
+
const result = await callApi('/export', { method: 'POST', body: JSON.stringify({ dir }) })
|
|
806
|
+
if (result.error) {
|
|
807
|
+
setNotice('导出失败:' + result.error)
|
|
808
|
+
return
|
|
809
|
+
}
|
|
810
|
+
setNotice('已导出 ' + result.stats.cues + ' 条字幕:' + result.out)
|
|
811
|
+
refresh()
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
const loadRoute = async () => {
|
|
815
|
+
const result = await callApi('/llm/route')
|
|
816
|
+
if (!result.error) setLlmRoute(result)
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
const chooseRoute = async (value) => {
|
|
820
|
+
if (!detail || !value) return
|
|
821
|
+
const separator = value.indexOf('/')
|
|
822
|
+
const provider = value.slice(0, separator)
|
|
823
|
+
const model = value.slice(separator + 1)
|
|
824
|
+
await callApi('/llm/route', { method: 'POST', body: JSON.stringify({ dir: detail.dir, provider, model }) })
|
|
825
|
+
setLlmRoute((current) => (current ? { ...current, active: { provider, model } } : { providers: [], active: { provider, model } }))
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
const translateNow = async (all) => {
|
|
829
|
+
if (!detail) return
|
|
830
|
+
setTranslateBusy(true)
|
|
831
|
+
setTranslateNotice('翻译中…')
|
|
832
|
+
try {
|
|
833
|
+
const payload = { dir: detail.dir, mode: proofread ? 'proofread' : 'translate' }
|
|
834
|
+
if (all) payload.all = true
|
|
835
|
+
else if (reviewBatch) payload.batch = reviewBatch.batch
|
|
836
|
+
if (llmRoute && llmRoute.active) {
|
|
837
|
+
payload.provider = llmRoute.active.provider
|
|
838
|
+
payload.model = llmRoute.active.model
|
|
839
|
+
}
|
|
840
|
+
const result = await callApi('/review/translate', { method: 'POST', body: JSON.stringify(payload) })
|
|
841
|
+
if (result.error) {
|
|
842
|
+
setNotice('翻译失败:' + result.error)
|
|
843
|
+
return
|
|
844
|
+
}
|
|
845
|
+
if (result.jobId) {
|
|
846
|
+
setTranslateJobId(result.jobId)
|
|
847
|
+
setNotice('开始翻译:共 ' + result.total + ' 批')
|
|
848
|
+
setTranslateNotice('准备中…')
|
|
849
|
+
const dir = detail.dir
|
|
850
|
+
for (let tick = 0; tick < 900; tick += 1) {
|
|
851
|
+
await new Promise((resolve) => setTimeout(resolve, 2000))
|
|
852
|
+
const job = await callApi('/job?id=' + encodeURIComponent(result.jobId))
|
|
853
|
+
if (job.error) {
|
|
854
|
+
setNotice('翻译任务:' + job.error)
|
|
855
|
+
break
|
|
856
|
+
}
|
|
857
|
+
if (job.status === 'done') {
|
|
858
|
+
setNotice('翻译完成')
|
|
859
|
+
break
|
|
860
|
+
}
|
|
861
|
+
if (job.status === 'failed') {
|
|
862
|
+
setNotice('翻译失败:' + (job.error || '未知错误'))
|
|
863
|
+
break
|
|
864
|
+
}
|
|
865
|
+
if (job.status === 'cancelled') {
|
|
866
|
+
setNotice('翻译已取消')
|
|
867
|
+
break
|
|
868
|
+
}
|
|
869
|
+
setNotice('翻译中:' + (job.msg || job.pct + '% ' + (job.phase || '')))
|
|
870
|
+
setTranslateNotice(job.msg || '翻译中…')
|
|
871
|
+
}
|
|
872
|
+
setTranslateJobId('')
|
|
873
|
+
await loadReview(dir)
|
|
874
|
+
refresh()
|
|
875
|
+
return
|
|
876
|
+
}
|
|
877
|
+
setNotice('已翻译批次 ' + result.batch + '(' + result.route + '),写入 ' + result.cues + ' 条' + (result.jpChanged ? ',校正日文 ' + result.jpChanged + ' 条' : ''))
|
|
878
|
+
setFeedbackDraft({})
|
|
879
|
+
setBatchNote('')
|
|
880
|
+
await openProject(detail)
|
|
881
|
+
} finally {
|
|
882
|
+
setTranslateBusy(false)
|
|
883
|
+
setTranslateNotice('')
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
const saveFeedbackAndRetranslate = async () => {
|
|
888
|
+
if (!detail || !reviewBatch) return
|
|
889
|
+
const batch = reviewBatch.batch
|
|
890
|
+
for (const [range, note] of Object.entries(feedbackDraft)) {
|
|
891
|
+
if (!note.trim()) continue
|
|
892
|
+
await callApi('/review/feedback', { method: 'POST', body: JSON.stringify({ dir: detail.dir, batch, range, note }) })
|
|
893
|
+
}
|
|
894
|
+
if (batchNote.trim()) {
|
|
895
|
+
await callApi('/review/feedback', { method: 'POST', body: JSON.stringify({ dir: detail.dir, batch, note: batchNote }) })
|
|
896
|
+
}
|
|
897
|
+
setBatchNote('')
|
|
898
|
+
await translateNow(false)
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
const loadHints = async (dir) => {
|
|
902
|
+
const result = await callApi('/hints?dir=' + encodeURIComponent(dir))
|
|
903
|
+
if (!result.error) setHints({ tags: result.tags || [], note: result.note || '' })
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
const loadGlossaryInfo = async (dir) => {
|
|
907
|
+
const result = await callApi('/glossary?dir=' + encodeURIComponent(dir))
|
|
908
|
+
if (!result.error) setGlossaryInfo(result.glossary)
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
const openContextDialog = async () => {
|
|
912
|
+
if (!detail) return
|
|
913
|
+
await loadGlossaryInfo(detail.dir)
|
|
914
|
+
setContextDialog(true)
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
const saveContext = async () => {
|
|
918
|
+
if (!detail) return
|
|
919
|
+
const result = await callApi('/hints', {
|
|
920
|
+
method: 'POST',
|
|
921
|
+
body: JSON.stringify({ dir: detail.dir, tags: hints.tags, note: hints.note }),
|
|
922
|
+
})
|
|
923
|
+
if (result.error) {
|
|
924
|
+
setNotice('保存失败:' + result.error)
|
|
925
|
+
return
|
|
926
|
+
}
|
|
927
|
+
setHints(result.hints)
|
|
928
|
+
setNotice('背景与标签已保存,下一次翻译会带上')
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
const addTag = () => {
|
|
932
|
+
const tag = tagDraft.trim()
|
|
933
|
+
if (!tag) return
|
|
934
|
+
if (!hints.tags.includes(tag)) setHints({ ...hints, tags: [...hints.tags, tag].slice(0, 20) })
|
|
935
|
+
setTagDraft('')
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
const importGlossary = async () => {
|
|
939
|
+
if (!detail) return
|
|
940
|
+
if (!glossaryText.trim()) {
|
|
941
|
+
setNotice('请先粘贴 CSV 内容')
|
|
942
|
+
return
|
|
943
|
+
}
|
|
944
|
+
const result = await callApi('/glossary/import', {
|
|
945
|
+
method: 'POST',
|
|
946
|
+
body: JSON.stringify({ dir: detail.dir, text: glossaryText }),
|
|
947
|
+
})
|
|
948
|
+
if (result.error) {
|
|
949
|
+
setNotice('导入失败:' + result.error)
|
|
950
|
+
return
|
|
951
|
+
}
|
|
952
|
+
setGlossaryText('')
|
|
953
|
+
await loadGlossaryInfo(detail.dir)
|
|
954
|
+
setNotice('术语表已导入:新增 ' + result.summary.added + ',更新 ' + result.summary.updated)
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
const exportGlossary = async () => {
|
|
958
|
+
if (!detail) return
|
|
959
|
+
const result = await callApi('/glossary/export', { method: 'POST', body: JSON.stringify({ dir: detail.dir }) })
|
|
960
|
+
if (result.error) {
|
|
961
|
+
setNotice('导出失败:' + result.error)
|
|
962
|
+
return
|
|
963
|
+
}
|
|
964
|
+
setNotice('已导出 CSV:' + result.path)
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
const loadReview = async (dir, batchId) => {
|
|
968
|
+
const status = await callApi('/review/status?dir=' + encodeURIComponent(dir))
|
|
969
|
+
if (status.error) {
|
|
970
|
+
setReview(null)
|
|
971
|
+
setReviewBatch(null)
|
|
972
|
+
return
|
|
973
|
+
}
|
|
974
|
+
setReview(status)
|
|
975
|
+
const wanted = batchId || status.next
|
|
976
|
+
if (!wanted) {
|
|
977
|
+
setReviewBatch(null)
|
|
978
|
+
return
|
|
979
|
+
}
|
|
980
|
+
const got = await callApi('/review/next?dir=' + encodeURIComponent(dir) + '&batch=' + encodeURIComponent(wanted))
|
|
981
|
+
setReviewBatch(got.error || got.done ? null : got)
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
const applyReview = async () => {
|
|
985
|
+
if (!detail || !reviewBatch) return
|
|
986
|
+
const result = await callApi('/review/apply', {
|
|
987
|
+
method: 'POST',
|
|
988
|
+
body: JSON.stringify({ dir: detail.dir, batch: reviewBatch.batch, lines: reviewInput, allowEmpty: reviewAllowEmpty }),
|
|
989
|
+
})
|
|
990
|
+
if (result.error) {
|
|
991
|
+
setNotice('应用失败:' + result.error)
|
|
992
|
+
return
|
|
993
|
+
}
|
|
994
|
+
const skipped = result.skipped ? `,跳過 ${result.skipped} 段` : ''
|
|
995
|
+
setNotice(`已应用批次 ${result.batch}:写入 ${result.cues} 条${skipped}`)
|
|
996
|
+
setReviewInput('')
|
|
997
|
+
await openProject(detail)
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
const copyBatch = async () => {
|
|
1001
|
+
if (!reviewBatch) return
|
|
1002
|
+
try {
|
|
1003
|
+
await navigator.clipboard.writeText(reviewBatch.lines)
|
|
1004
|
+
setNotice('已复制批次 ' + reviewBatch.batch + ',粘贴给模型即可')
|
|
1005
|
+
} catch {
|
|
1006
|
+
setNotice('浏览器不允许写剪贴板,请手动选择下方文本复制')
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
|
|
626
1010
|
const openProject = async (project) => {
|
|
627
1011
|
const next = await callApi('/project?dir=' + encodeURIComponent(project.dir))
|
|
628
1012
|
if (next.error) {
|
|
@@ -632,6 +1016,14 @@ window.__ModuleLoader__.load({
|
|
|
632
1016
|
setDetail(next)
|
|
633
1017
|
setEditing(false)
|
|
634
1018
|
setDraft(Array.isArray(next.cueList) ? next.cueList.map((cue) => ({ ...cue })) : [])
|
|
1019
|
+
setReviewInput('')
|
|
1020
|
+
setReviewBatch(null)
|
|
1021
|
+
setReview(null)
|
|
1022
|
+
setFeedbackDraft({})
|
|
1023
|
+
setBatchNote('')
|
|
1024
|
+
loadRoute()
|
|
1025
|
+
loadHints(next.dir)
|
|
1026
|
+
loadReview(next.dir)
|
|
635
1027
|
}
|
|
636
1028
|
|
|
637
1029
|
const togglePin = async (project) => {
|
|
@@ -665,7 +1057,15 @@ window.__ModuleLoader__.load({
|
|
|
665
1057
|
}
|
|
666
1058
|
|
|
667
1059
|
const updateDraft = (index, field, value) => {
|
|
668
|
-
setDraft((current) =>
|
|
1060
|
+
setDraft((current) =>
|
|
1061
|
+
current.map((cue, position) => {
|
|
1062
|
+
if (position !== index) return cue
|
|
1063
|
+
// typing text over a skipped range turns it back into a normal cue
|
|
1064
|
+
const next = { ...cue, [field]: value }
|
|
1065
|
+
if ((field === 'jp' || field === 'zh') && String(value).trim()) delete next.skip
|
|
1066
|
+
return next
|
|
1067
|
+
}),
|
|
1068
|
+
)
|
|
669
1069
|
}
|
|
670
1070
|
|
|
671
1071
|
const saveEdits = async () => {
|
|
@@ -690,14 +1090,14 @@ window.__ModuleLoader__.load({
|
|
|
690
1090
|
|
|
691
1091
|
const importCues = async () => {
|
|
692
1092
|
if (!detail || !cueSource.trim()) {
|
|
693
|
-
setNotice('
|
|
1093
|
+
setNotice('请先选择项目并填写字幕内容文件的绝对路径')
|
|
694
1094
|
return
|
|
695
1095
|
}
|
|
696
1096
|
const result = await callApi('/import-cues', {
|
|
697
1097
|
method: 'POST',
|
|
698
1098
|
body: JSON.stringify({ dir: detail.dir, from: cueSource.trim() }),
|
|
699
1099
|
})
|
|
700
|
-
setNotice(result.error ? '导入失败:' + result.error : '
|
|
1100
|
+
setNotice(result.error ? '导入失败:' + result.error : '已导入字幕内容')
|
|
701
1101
|
openProject(detail)
|
|
702
1102
|
}
|
|
703
1103
|
|
|
@@ -801,7 +1201,9 @@ window.__ModuleLoader__.load({
|
|
|
801
1201
|
setDraft((current) => current.map((cue) => ({ from: cue.from, to: cue.to, jp: cue.jp, zh: cue.zh })))
|
|
802
1202
|
}
|
|
803
1203
|
|
|
804
|
-
const small = { ...button, padding: '2px 7px', fontSize: 11 }
|
|
1204
|
+
const small = { ...button, padding: '2px 7px', fontSize: 11, minHeight: 26 }
|
|
1205
|
+
/** Between the tiny inline buttons and the main toolbar actions. */
|
|
1206
|
+
const medium = { ...button, padding: '4px 10px', fontSize: 12, minHeight: 30 }
|
|
805
1207
|
|
|
806
1208
|
return h(
|
|
807
1209
|
'div',
|
|
@@ -978,7 +1380,14 @@ window.__ModuleLoader__.load({
|
|
|
978
1380
|
h(
|
|
979
1381
|
'div',
|
|
980
1382
|
{ style: { ...card } },
|
|
981
|
-
h(
|
|
1383
|
+
h(
|
|
1384
|
+
'div',
|
|
1385
|
+
{ style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6 } },
|
|
1386
|
+
h('div', { style: sectionTitle }, '任务'),
|
|
1387
|
+
jobs.some((job) => job.status !== 'running')
|
|
1388
|
+
? h(B, { style: medium, onClick: clearTasks }, '清空已结束')
|
|
1389
|
+
: null,
|
|
1390
|
+
),
|
|
982
1391
|
jobs.length === 0
|
|
983
1392
|
? h('div', { style: { ...code, marginTop: 4 } }, '暂无任务')
|
|
984
1393
|
: jobs.map((job) =>
|
|
@@ -998,11 +1407,12 @@ window.__ModuleLoader__.load({
|
|
|
998
1407
|
{ style: { display: 'flex', gap: 6, alignItems: 'center' } },
|
|
999
1408
|
h('span', { style: code }, job.pct + '% ' + (PHASE_LABEL[job.phase] || job.phase || '')),
|
|
1000
1409
|
job.status === 'running'
|
|
1001
|
-
? h(B, { style:
|
|
1002
|
-
:
|
|
1410
|
+
? h(B, { style: medium, onClick: () => cancelTask(job.id) }, '取消')
|
|
1411
|
+
: h(B, { style: medium, onClick: () => removeTask(job.id) }, '删除'),
|
|
1003
1412
|
),
|
|
1004
1413
|
),
|
|
1005
1414
|
h(Progress, { pct: job.pct, status: job.status }),
|
|
1415
|
+
job.msg ? h('div', { style: { ...code, marginTop: 4 } }, job.msg) : null,
|
|
1006
1416
|
job.error ? h('div', { style: { ...code, color: tokens.danger, marginTop: 8 } }, job.error) : null,
|
|
1007
1417
|
job.projectDir ? h('div', { style: { ...code, marginTop: 4 } }, job.projectDir) : null,
|
|
1008
1418
|
),
|
|
@@ -1018,10 +1428,21 @@ window.__ModuleLoader__.load({
|
|
|
1018
1428
|
h('div', { style: sectionTitle }, '项目'),
|
|
1019
1429
|
h(
|
|
1020
1430
|
'label',
|
|
1021
|
-
{ style: { display: 'flex', gap: 4, alignItems: 'center', fontSize: 11, color: tokens.muted } },
|
|
1431
|
+
{ style: { display: 'flex', gap: 4, alignItems: 'center', fontSize: 11, color: tokens.muted }, title: '只从列表移除、文件仍保留的项目会出现在这里,可以再恢复' },
|
|
1022
1432
|
h('input', { type: 'checkbox', checked: showHidden, onChange: (event) => setShowHidden(event.target.checked) }),
|
|
1023
|
-
'
|
|
1433
|
+
'显示已移除的项目',
|
|
1434
|
+
),
|
|
1435
|
+
),
|
|
1436
|
+
h(
|
|
1437
|
+
'div',
|
|
1438
|
+
{ style: { display: 'flex', gap: 8, alignItems: 'center', marginBottom: 8, flexWrap: 'wrap' } },
|
|
1439
|
+
h(
|
|
1440
|
+
'span',
|
|
1441
|
+
{ style: { ...code, fontSize: 11, flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', userSelect: 'text' } },
|
|
1442
|
+
projectsInfo ? projectsInfo.projectsDir : '项目目录读取中…',
|
|
1024
1443
|
),
|
|
1444
|
+
h(B, { style: medium, onClick: openProjectsDialog }, '更改目录'),
|
|
1445
|
+
h(B, { style: medium, onClick: openProjectsFolder }, '打开目录'),
|
|
1025
1446
|
),
|
|
1026
1447
|
visibleProjects.length === 0
|
|
1027
1448
|
? h('div', { style: code }, '还没有项目,先在下面转写一个视频')
|
|
@@ -1042,6 +1463,15 @@ window.__ModuleLoader__.load({
|
|
|
1042
1463
|
},
|
|
1043
1464
|
project.name,
|
|
1044
1465
|
),
|
|
1466
|
+
project.review && project.review.translated < project.review.batches
|
|
1467
|
+
? h(B, {
|
|
1468
|
+
style: { ...primary, padding: '4px 10px', flex: '0 0 auto' },
|
|
1469
|
+
onClick: () => openProject(project),
|
|
1470
|
+
}, project.review.translated === 0 ? '开始翻译' : '继续翻译')
|
|
1471
|
+
: h(B, {
|
|
1472
|
+
style: { ...medium, flex: '0 0 auto' },
|
|
1473
|
+
onClick: () => exportProject(project.dir),
|
|
1474
|
+
}, '导出'),
|
|
1045
1475
|
h(B, {
|
|
1046
1476
|
style: { ...button, padding: '6px 8px' },
|
|
1047
1477
|
title: project.pinned ? '取消置顶' : '置顶',
|
|
@@ -1057,22 +1487,30 @@ window.__ModuleLoader__.load({
|
|
|
1057
1487
|
style: { ...button, padding: '6px 8px' },
|
|
1058
1488
|
title: '恢复显示',
|
|
1059
1489
|
onClick: () => restoreProject(project),
|
|
1060
|
-
}, '
|
|
1490
|
+
}, '恢复到列表')
|
|
1061
1491
|
: null,
|
|
1062
1492
|
),
|
|
1063
1493
|
h(
|
|
1064
1494
|
'div',
|
|
1065
|
-
{ style: { ...code, display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
1066
|
-
h('span', null, project.fragments + '
|
|
1067
|
-
h('span', null, project.cues + '
|
|
1495
|
+
{ style: { ...code, display: 'flex', gap: 8, flexWrap: 'wrap', alignItems: 'center' } },
|
|
1496
|
+
h('span', null, project.fragments + ' 句'),
|
|
1497
|
+
h('span', null, project.cues + ' 条字幕'),
|
|
1498
|
+
reviewLabel(project.review),
|
|
1068
1499
|
project.srt ? h('span', null, 'SRT') : null,
|
|
1069
|
-
project.hidden ? h('span', { style: { color: tokens.danger } }, '
|
|
1500
|
+
project.hidden ? h('span', { style: { color: tokens.danger } }, '已从列表移除') : null,
|
|
1070
1501
|
),
|
|
1071
1502
|
),
|
|
1072
1503
|
),
|
|
1073
1504
|
),
|
|
1074
1505
|
),
|
|
1075
1506
|
|
|
1507
|
+
h(
|
|
1508
|
+
'div',
|
|
1509
|
+
{ key: 'footer', style: { display: 'flex', gap: 8, alignItems: 'center', marginTop: 14, flexWrap: 'wrap' } },
|
|
1510
|
+
h(B, { style: medium, onClick: () => setHelpDialog(true) }, '使用说明'),
|
|
1511
|
+
h('span', { style: { ...code, fontSize: 11 } }, '首次使用先安装运行时;翻译用 DSH 已配置的模型'),
|
|
1512
|
+
),
|
|
1513
|
+
|
|
1076
1514
|
detail
|
|
1077
1515
|
? h(Modal, {
|
|
1078
1516
|
title: detail.name,
|
|
@@ -1087,13 +1525,22 @@ window.__ModuleLoader__.load({
|
|
|
1087
1525
|
h(B, { key: 'close', style: quietButton, onClick: () => { setDetail(null); setEditing(false) } }, '关闭'),
|
|
1088
1526
|
],
|
|
1089
1527
|
children: [
|
|
1528
|
+
h(
|
|
1529
|
+
'div',
|
|
1530
|
+
{ key: 'stepper', style: { display: 'flex', gap: 6, alignItems: 'center', marginBottom: 8, fontSize: 12, color: tokens.muted, flexWrap: 'wrap' } },
|
|
1531
|
+
h('span', { style: { color: tokens.ok } }, '① 转写 ✓'),
|
|
1532
|
+
h('span', null, '→'),
|
|
1533
|
+
h('span', { style: review && review.translated >= review.batches ? { color: tokens.ok } : { color: tokens.text } }, review ? '② 翻译 ' + review.translated + '/' + review.batches + ' 批' : '② 翻译 …'),
|
|
1534
|
+
h('span', null, '→'),
|
|
1535
|
+
h('span', null, '③ 导出字幕'),
|
|
1536
|
+
),
|
|
1090
1537
|
detail.errors && detail.errors.length
|
|
1091
1538
|
? h('div', { key: 'errors', style: { ...code, color: tokens.danger, marginBottom: 8 } }, detail.errors.join(';'))
|
|
1092
1539
|
: null,
|
|
1093
1540
|
h(
|
|
1094
1541
|
'div',
|
|
1095
1542
|
{ key: 'toolbar', style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
1096
|
-
h(B, { style: primary, onClick: exportSrt }, '
|
|
1543
|
+
h(B, { style: primary, onClick: exportSrt }, '导出字幕'),
|
|
1097
1544
|
h(B,
|
|
1098
1545
|
{
|
|
1099
1546
|
style: editing ? primary : button,
|
|
@@ -1103,21 +1550,145 @@ window.__ModuleLoader__.load({
|
|
|
1103
1550
|
},
|
|
1104
1551
|
disabled: !detail.cueList || detail.cueList.length === 0,
|
|
1105
1552
|
},
|
|
1106
|
-
editing ? '
|
|
1553
|
+
editing ? '取消修改' : '逐条修改',
|
|
1107
1554
|
),
|
|
1108
1555
|
editing
|
|
1109
1556
|
? h(B, { style: primary, onClick: saveEdits }, '保存修改')
|
|
1110
1557
|
: h(B, { style: button, onClick: () => openProject(detail) }, '刷新'),
|
|
1111
1558
|
editing ? h(B, { style: quietButton, onClick: resetTimes }, '全部恢复自动时间') : null,
|
|
1112
1559
|
),
|
|
1560
|
+
!editing && review && review.batches > 0 && review.translated < review.batches
|
|
1561
|
+
? h(
|
|
1562
|
+
'div',
|
|
1563
|
+
{ key: 'review', style: { marginTop: 10, padding: 10, border: '1px solid ' + tokens.border, borderRadius: 8 } },
|
|
1564
|
+
h(
|
|
1565
|
+
'div',
|
|
1566
|
+
{ style: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } },
|
|
1567
|
+
h('div', { style: sectionTitle }, '自动翻译 · 第 ' + (reviewBatch ? reviewBatch.batch.replace('-', '–') : '…') + ' 句'),
|
|
1568
|
+
h('span', { style: code }, llmRoute && llmRoute.active ? llmRoute.active.provider + '/' + llmRoute.active.model : '模型解析中…'),
|
|
1569
|
+
h(B, { style: medium, onClick: loadRoute }, '刷新模型'),
|
|
1570
|
+
),
|
|
1571
|
+
llmRoute && llmRoute.providers && llmRoute.providers.length > 0
|
|
1572
|
+
? h(RouteSelect, {
|
|
1573
|
+
value: llmRoute.active ? llmRoute.active.provider + '/' + llmRoute.active.model : '',
|
|
1574
|
+
placeholder: '选择模型',
|
|
1575
|
+
options: llmRoute.providers.flatMap((provider) =>
|
|
1576
|
+
provider.models.map((model) => ({
|
|
1577
|
+
value: provider.id + '/' + model,
|
|
1578
|
+
label: provider.name + ' · ' + model,
|
|
1579
|
+
})),
|
|
1580
|
+
),
|
|
1581
|
+
onChange: chooseRoute,
|
|
1582
|
+
})
|
|
1583
|
+
: null,
|
|
1584
|
+
h(
|
|
1585
|
+
'div',
|
|
1586
|
+
{ style: { display: 'flex', gap: 6, marginTop: 8, alignItems: 'center', flexWrap: 'wrap' } },
|
|
1587
|
+
hints.tags.length > 0
|
|
1588
|
+
? hints.tags.map((tag) => h('span', { key: tag, style: { ...small, cursor: 'default', padding: '2px 8px', opacity: 0.9 } }, '#' + tag))
|
|
1589
|
+
: h('span', { style: { ...code, marginRight: 4 } }, '未设置背景标签'),
|
|
1590
|
+
h(B, { style: medium, onClick: openContextDialog }, '背景与术语'),
|
|
1591
|
+
),
|
|
1592
|
+
h(
|
|
1593
|
+
'div',
|
|
1594
|
+
{ style: { display: 'flex', gap: 6, marginTop: 8, flexWrap: 'wrap' } },
|
|
1595
|
+
h(B, { style: primary, onClick: () => translateNow(false), disabled: translateBusy || !reviewBatch }, translateBusy ? translateNotice || '翻译中…' : '自动翻译本批'),
|
|
1596
|
+
h(B, { style: button, onClick: () => translateNow(true), disabled: translateBusy }, '自动翻译全部剩余'),
|
|
1597
|
+
translateJobId
|
|
1598
|
+
? h(B, {
|
|
1599
|
+
style: dangerButton,
|
|
1600
|
+
onClick: async () => {
|
|
1601
|
+
await callApi('/job/cancel', { method: 'POST', body: JSON.stringify({ id: translateJobId }) })
|
|
1602
|
+
setNotice('已请求取消翻译')
|
|
1603
|
+
},
|
|
1604
|
+
}, '停止翻译')
|
|
1605
|
+
: null,
|
|
1606
|
+
h(B, { style: small, onClick: () => loadReview(detail.dir) }, '刷新进度'),
|
|
1607
|
+
h(
|
|
1608
|
+
'label',
|
|
1609
|
+
{ style: { display: 'flex', gap: 4, alignItems: 'center', fontSize: 11, color: tokens.muted } },
|
|
1610
|
+
h('input', { type: 'checkbox', checked: proofread, onChange: (event) => setProofread(event.target.checked) }),
|
|
1611
|
+
'同时校正日文识别',
|
|
1612
|
+
),
|
|
1613
|
+
),
|
|
1614
|
+
reviewBatch && reviewBatch.cues && reviewBatch.cues.length > 0
|
|
1615
|
+
? h(
|
|
1616
|
+
'div',
|
|
1617
|
+
{ style: { marginTop: 10 } },
|
|
1618
|
+
h('div', { style: sectionTitle }, '这一段的结果与意见'),
|
|
1619
|
+
reviewBatch.cues.map((cue) =>
|
|
1620
|
+
h(
|
|
1621
|
+
'div',
|
|
1622
|
+
{ key: cue.from + '-' + cue.to, style: { padding: '6px 0', borderTop: '1px solid ' + tokens.border } },
|
|
1623
|
+
h('div', { style: code }, cue.from + '-' + cue.to + (cue.skip ? ' · 跳过' : '')),
|
|
1624
|
+
h('div', null, cue.jp),
|
|
1625
|
+
h('div', { style: { color: tokens.muted } }, cue.zh || '(空)'),
|
|
1626
|
+
h('input', {
|
|
1627
|
+
style: { ...input, marginTop: 4, fontSize: 11 },
|
|
1628
|
+
placeholder: '对这一条的意见,例如:称呼应译成“老板”',
|
|
1629
|
+
value: feedbackDraft[cue.from + '-' + cue.to] || '',
|
|
1630
|
+
onChange: (event) => setFeedbackDraft({ ...feedbackDraft, [cue.from + '-' + cue.to]: event.target.value }),
|
|
1631
|
+
}),
|
|
1632
|
+
),
|
|
1633
|
+
),
|
|
1634
|
+
h('input', {
|
|
1635
|
+
style: { ...input, marginTop: 8, fontSize: 11 },
|
|
1636
|
+
placeholder: '整批意见(可选)',
|
|
1637
|
+
value: batchNote,
|
|
1638
|
+
onChange: (event) => setBatchNote(event.target.value),
|
|
1639
|
+
}),
|
|
1640
|
+
h(
|
|
1641
|
+
'div',
|
|
1642
|
+
{ style: { display: 'flex', gap: 6, marginTop: 8, flexWrap: 'wrap' } },
|
|
1643
|
+
h(B, { style: button, onClick: saveFeedbackAndRetranslate, disabled: translateBusy }, '保存意见并重译本批'),
|
|
1644
|
+
h(B, { style: small, onClick: () => { setFeedbackDraft({}); setBatchNote('') } }, '清空意见'),
|
|
1645
|
+
),
|
|
1646
|
+
)
|
|
1647
|
+
: null,
|
|
1648
|
+
h(
|
|
1649
|
+
'details',
|
|
1650
|
+
{ style: { marginTop: 10 } },
|
|
1651
|
+
h('summary', { style: { cursor: 'pointer', fontSize: 11, color: tokens.muted } }, '手动:复制批次 / 粘贴模型结果'),
|
|
1652
|
+
h('textarea', {
|
|
1653
|
+
readOnly: true,
|
|
1654
|
+
value: reviewBatch ? reviewBatch.lines : '',
|
|
1655
|
+
onFocus: (event) => event.target.select(),
|
|
1656
|
+
style: { ...input, height: 110, fontSize: 11, marginTop: 6, fontFamily: 'ui-monospace, monospace' },
|
|
1657
|
+
}),
|
|
1658
|
+
h('div', { style: { display: 'flex', gap: 6, marginTop: 6 } }, h(B, { style: small, onClick: copyBatch, disabled: !reviewBatch }, '复制本批')),
|
|
1659
|
+
h('textarea', {
|
|
1660
|
+
placeholder: '粘贴 from-to|jp|zh 行',
|
|
1661
|
+
value: reviewInput,
|
|
1662
|
+
onChange: (event) => setReviewInput(event.target.value),
|
|
1663
|
+
style: { ...input, height: 100, fontSize: 11, marginTop: 6, fontFamily: 'ui-monospace, monospace' },
|
|
1664
|
+
}),
|
|
1665
|
+
h(
|
|
1666
|
+
'div',
|
|
1667
|
+
{ style: { display: 'flex', gap: 8, marginTop: 6, alignItems: 'center' } },
|
|
1668
|
+
h(B, { style: primary, onClick: applyReview, disabled: !reviewBatch || !reviewInput.trim() }, '应用本批'),
|
|
1669
|
+
h(
|
|
1670
|
+
'label',
|
|
1671
|
+
{ style: { display: 'flex', gap: 4, alignItems: 'center', fontSize: 11, color: tokens.muted } },
|
|
1672
|
+
h('input', { type: 'checkbox', checked: reviewAllowEmpty, onChange: (event) => setReviewAllowEmpty(event.target.checked) }),
|
|
1673
|
+
'允许空中文',
|
|
1674
|
+
),
|
|
1675
|
+
),
|
|
1676
|
+
),
|
|
1677
|
+
)
|
|
1678
|
+
: h(
|
|
1679
|
+
'div',
|
|
1680
|
+
{ key: 'review-done', style: { marginTop: 10, padding: 10, border: '1px solid ' + tokens.border, borderRadius: 8 } },
|
|
1681
|
+
h('div', { style: { ...code, color: review && review.batches > 0 ? tokens.ok : tokens.muted, marginBottom: 8 } }, review && review.batches > 0 ? '已全部翻译完成,可以导出字幕了' : '还没有字幕内容,点上面的「自动翻译本批」开始'),
|
|
1682
|
+
h(B, { style: primary, onClick: exportSrt }, '导出字幕'),
|
|
1683
|
+
),
|
|
1113
1684
|
h('input', {
|
|
1114
1685
|
key: 'import',
|
|
1115
1686
|
style: { ...input, marginTop: 8 },
|
|
1116
1687
|
value: cueSource,
|
|
1117
|
-
placeholder: '
|
|
1688
|
+
placeholder: '高级:从文件导入字幕内容(cues.json 绝对路径)',
|
|
1118
1689
|
onChange: (event) => setCueSource(event.target.value),
|
|
1119
1690
|
}),
|
|
1120
|
-
h(B, { key: 'import-btn', style: { ...button, marginTop: 6 }, onClick: importCues }, '
|
|
1691
|
+
h(B, { key: 'import-btn', style: { ...button, marginTop: 6 }, onClick: importCues }, '从文件导入'),
|
|
1121
1692
|
editing
|
|
1122
1693
|
? h(
|
|
1123
1694
|
'div',
|
|
@@ -1129,11 +1700,12 @@ window.__ModuleLoader__.load({
|
|
|
1129
1700
|
h(
|
|
1130
1701
|
'div',
|
|
1131
1702
|
{ style: code },
|
|
1132
|
-
'#' + (index + 1) + ' · ' + Number(cue.start).toFixed(2) + 's → ' + Number(cue.end).toFixed(2) + 's ·
|
|
1703
|
+
'#' + (index + 1) + ' · ' + Number(cue.start).toFixed(2) + 's → ' + Number(cue.end).toFixed(2) + 's · 第 ' + cue.from + (cue.to > cue.from ? '–' + cue.to : '') + ' 句' + (cue.fixed ? ' · 手动时间' : '') + (cue.skip ? ' · 已删除(不显示)' : ''),
|
|
1133
1704
|
),
|
|
1134
1705
|
h('input', {
|
|
1135
1706
|
style: { ...input, marginTop: 4 },
|
|
1136
1707
|
value: cue.jp,
|
|
1708
|
+
placeholder: cue.skip ? '已删除,不显示在字幕里' : '',
|
|
1137
1709
|
onChange: (event) => updateDraft(index, 'jp', event.target.value),
|
|
1138
1710
|
}),
|
|
1139
1711
|
h('input', {
|
|
@@ -1149,7 +1721,12 @@ window.__ModuleLoader__.load({
|
|
|
1149
1721
|
h(B, { style: small, onClick: () => nudgeTime(index, 'end', -0.1) }, '终点 −0.1'),
|
|
1150
1722
|
h(B, { style: small, onClick: () => nudgeTime(index, 'end', 0.1) }, '终点 +0.1'),
|
|
1151
1723
|
h(B, { style: small, onClick: () => splitCue(index) }, '拆分'),
|
|
1152
|
-
|
|
1724
|
+
h(B, { style: small, disabled: index === draft.length - 1, onClick: () => mergeNext(index) }, '与下一条合并'),
|
|
1725
|
+
h(
|
|
1726
|
+
B,
|
|
1727
|
+
{ style: cue.skip ? small : dangerButton, onClick: () => setDraft((current) => current.map((item, i) => (i === index ? { ...item, skip: !item.skip } : item))) },
|
|
1728
|
+
cue.skip ? '恢复' : '删除',
|
|
1729
|
+
),
|
|
1153
1730
|
),
|
|
1154
1731
|
),
|
|
1155
1732
|
),
|
|
@@ -1182,6 +1759,55 @@ window.__ModuleLoader__.load({
|
|
|
1182
1759
|
inlineActions: true,
|
|
1183
1760
|
onClose: () => setPicker(null),
|
|
1184
1761
|
children: [
|
|
1762
|
+
(recent.files.length > 0 || recent.dirs.length > 0)
|
|
1763
|
+
? h(
|
|
1764
|
+
'div',
|
|
1765
|
+
{ key: 'recent', style: { marginBottom: 8 } },
|
|
1766
|
+
h(
|
|
1767
|
+
B,
|
|
1768
|
+
{
|
|
1769
|
+
style: { ...medium, width: '100%', textAlign: 'left', justifyContent: 'flex-start' },
|
|
1770
|
+
onClick: () => setRecentOpen(!recentOpen),
|
|
1771
|
+
},
|
|
1772
|
+
(recentOpen ? '▾ ' : '▸ ') + '最近使用(' + recent.files.length + ' 个文件 / ' + recent.dirs.length + ' 个文件夹)',
|
|
1773
|
+
),
|
|
1774
|
+
recentOpen
|
|
1775
|
+
? h(
|
|
1776
|
+
'div',
|
|
1777
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 4, marginTop: 6 } },
|
|
1778
|
+
picker.mode === 'file'
|
|
1779
|
+
? recent.files.map((entry) =>
|
|
1780
|
+
h(
|
|
1781
|
+
B,
|
|
1782
|
+
{
|
|
1783
|
+
key: entry,
|
|
1784
|
+
title: entry,
|
|
1785
|
+
style: { ...small, width: '100%', textAlign: 'left', justifyContent: 'flex-start', fontSize: 12, height: 30, padding: '0 10px' },
|
|
1786
|
+
onClick: () => {
|
|
1787
|
+
applyPick('media', entry)
|
|
1788
|
+
setPicker(null)
|
|
1789
|
+
},
|
|
1790
|
+
},
|
|
1791
|
+
'🎬 ' + entry.split(/[\\/]/).pop(),
|
|
1792
|
+
),
|
|
1793
|
+
)
|
|
1794
|
+
: null,
|
|
1795
|
+
recent.dirs.map((entry) =>
|
|
1796
|
+
h(
|
|
1797
|
+
B,
|
|
1798
|
+
{
|
|
1799
|
+
key: entry,
|
|
1800
|
+
title: entry,
|
|
1801
|
+
style: { ...small, width: '100%', textAlign: 'left', justifyContent: 'flex-start', fontSize: 12, height: 30, padding: '0 10px' },
|
|
1802
|
+
onClick: () => loadDir(picker.mode, entry),
|
|
1803
|
+
},
|
|
1804
|
+
'📁 ' + entry,
|
|
1805
|
+
),
|
|
1806
|
+
),
|
|
1807
|
+
)
|
|
1808
|
+
: null,
|
|
1809
|
+
)
|
|
1810
|
+
: null,
|
|
1185
1811
|
places.length > 0
|
|
1186
1812
|
? h(
|
|
1187
1813
|
'div',
|
|
@@ -1245,13 +1871,170 @@ window.__ModuleLoader__.load({
|
|
|
1245
1871
|
],
|
|
1246
1872
|
actions: [
|
|
1247
1873
|
picker.mode === 'dir'
|
|
1248
|
-
? h(B, { key: 'choose', style: primary, onClick: () => {
|
|
1874
|
+
? h(B, { key: 'choose', style: primary, onClick: () => { applyPick(pickerTarget, picker.dir); setPicker(null) } }, '选择当前文件夹')
|
|
1249
1875
|
: null,
|
|
1250
1876
|
h(B, { key: 'cancel', style: quietButton, onClick: () => setPicker(null) }, '取消'),
|
|
1251
1877
|
].filter(Boolean),
|
|
1252
1878
|
})
|
|
1253
1879
|
: null,
|
|
1254
1880
|
|
|
1881
|
+
contextDialog
|
|
1882
|
+
? h(Modal, {
|
|
1883
|
+
title: '背景与术语',
|
|
1884
|
+
subtitle: '标签和说明会随每次翻译一起交给模型;术语表用于统一人名与专有名词',
|
|
1885
|
+
width: 'min(720px, 94vw)',
|
|
1886
|
+
height: '78vh',
|
|
1887
|
+
onClose: () => setContextDialog(false),
|
|
1888
|
+
children: [
|
|
1889
|
+
h('div', { key: 'h1', style: sectionTitle }, '背景标签'),
|
|
1890
|
+
h(
|
|
1891
|
+
'div',
|
|
1892
|
+
{ key: 'tags', style: { display: 'flex', gap: 6, flexWrap: 'wrap', marginTop: 6 } },
|
|
1893
|
+
hints.tags.length > 0
|
|
1894
|
+
? hints.tags.map((tag) =>
|
|
1895
|
+
h(
|
|
1896
|
+
B,
|
|
1897
|
+
{
|
|
1898
|
+
key: tag,
|
|
1899
|
+
style: { ...small, padding: '3px 8px' },
|
|
1900
|
+
title: '点击移除',
|
|
1901
|
+
onClick: () => setHints({ ...hints, tags: hints.tags.filter((item) => item !== tag) }),
|
|
1902
|
+
},
|
|
1903
|
+
'#' + tag + ' ×',
|
|
1904
|
+
),
|
|
1905
|
+
)
|
|
1906
|
+
: h('span', { style: { ...code, opacity: 0.7 } }, '还没有标签,例如「声优节目」「广播」「游戏实况」'),
|
|
1907
|
+
),
|
|
1908
|
+
h(
|
|
1909
|
+
'div',
|
|
1910
|
+
{ key: 'tagbar', style: { display: 'flex', gap: 6, marginTop: 8 } },
|
|
1911
|
+
h('input', {
|
|
1912
|
+
style: input,
|
|
1913
|
+
value: tagDraft,
|
|
1914
|
+
placeholder: '输入标签后回车或点「添加」',
|
|
1915
|
+
onChange: (event) => setTagDraft(event.target.value),
|
|
1916
|
+
onKeyDown: (event) => {
|
|
1917
|
+
if (event.key === 'Enter') addTag()
|
|
1918
|
+
},
|
|
1919
|
+
}),
|
|
1920
|
+
h(B, { style: button, onClick: addTag }, '添加'),
|
|
1921
|
+
),
|
|
1922
|
+
h('div', { key: 'h2', style: { ...sectionTitle, marginTop: 14 } }, '说明'),
|
|
1923
|
+
h('textarea', {
|
|
1924
|
+
key: 'note',
|
|
1925
|
+
style: { ...input, height: 80, marginTop: 6, fontSize: 12 },
|
|
1926
|
+
value: hints.note,
|
|
1927
|
+
placeholder: '例如:这是声优的生放送,称呼要口语化,第三人称用「她」',
|
|
1928
|
+
onChange: (event) => setHints({ ...hints, note: event.target.value }),
|
|
1929
|
+
}),
|
|
1930
|
+
h(
|
|
1931
|
+
'div',
|
|
1932
|
+
{ key: 'savebar', style: { display: 'flex', gap: 6, marginTop: 8 } },
|
|
1933
|
+
h(B, { style: primary, onClick: saveContext }, '保存背景'),
|
|
1934
|
+
),
|
|
1935
|
+
h('div', { key: 'h3', style: { ...sectionTitle, marginTop: 16 } }, '术语表(' + (glossaryInfo ? glossaryInfo.terms.length : 0) + ' 条)'),
|
|
1936
|
+
glossaryInfo && glossaryInfo.terms.length > 0
|
|
1937
|
+
? h(
|
|
1938
|
+
'div',
|
|
1939
|
+
{ key: 'terms', style: { maxHeight: 160, overflow: 'auto', marginTop: 6 } },
|
|
1940
|
+
glossaryInfo.terms.map((term) =>
|
|
1941
|
+
h('div', { key: term.jp, style: { ...code, padding: '2px 0' } }, term.jp + ' → ' + term.zh),
|
|
1942
|
+
),
|
|
1943
|
+
)
|
|
1944
|
+
: h('div', { key: 'noterms', style: { ...code, opacity: 0.7 } }, '还没有术语;可以粘贴 CSV 导入'),
|
|
1945
|
+
h('textarea', {
|
|
1946
|
+
key: 'csv',
|
|
1947
|
+
style: { ...input, height: 90, marginTop: 8, fontSize: 11, fontFamily: 'ui-monospace, monospace' },
|
|
1948
|
+
value: glossaryText,
|
|
1949
|
+
placeholder: '粘贴 CSV:type,jp,zh,note(每行一条)',
|
|
1950
|
+
onChange: (event) => setGlossaryText(event.target.value),
|
|
1951
|
+
}),
|
|
1952
|
+
h(
|
|
1953
|
+
'div',
|
|
1954
|
+
{ key: 'glossbar', style: { display: 'flex', gap: 6, marginTop: 8, flexWrap: 'wrap' } },
|
|
1955
|
+
h(B, { style: button, onClick: importGlossary }, '导入粘贴的术语'),
|
|
1956
|
+
h(B, { style: button, onClick: exportGlossary }, '导出 CSV'),
|
|
1957
|
+
),
|
|
1958
|
+
],
|
|
1959
|
+
actions: [h(B, { key: 'close', style: quietButton, onClick: () => setContextDialog(false) }, '关闭')],
|
|
1960
|
+
})
|
|
1961
|
+
: null,
|
|
1962
|
+
|
|
1963
|
+
helpDialog
|
|
1964
|
+
? h(Modal, {
|
|
1965
|
+
title: '使用说明',
|
|
1966
|
+
subtitle: '从安装运行时到导出字幕的完整流程',
|
|
1967
|
+
width: 'min(760px, 94vw)',
|
|
1968
|
+
height: '84vh',
|
|
1969
|
+
onClose: () => setHelpDialog(false),
|
|
1970
|
+
children: [
|
|
1971
|
+
h(
|
|
1972
|
+
'div',
|
|
1973
|
+
{ key: 'flow', style: { display: 'flex', flexDirection: 'column', gap: 12, fontSize: 12, lineHeight: 1.7 } },
|
|
1974
|
+
h('div', null, h('div', { style: { fontWeight: 600, marginBottom: 4 } }, '① 安装运行时(只做一次)'),
|
|
1975
|
+
h('div', { style: code }, '首次使用点「安装运行时」:下载 ffmpeg、Python、PyTorch(约 3 GB)。有 NVIDIA 显卡自动用 CUDA,没有则用 CPU;可勾选同时下载 Whisper 模型(约 1.6 GB)。')),
|
|
1976
|
+
h('div', null, h('div', { style: { fontWeight: 600, marginBottom: 4 } }, '② 转写'),
|
|
1977
|
+
h('div', { style: code }, '「转写」里选择视频或音频文件,点开始。任务卡显示进度,可随时取消;完成后项目出现在下面的列表里。')),
|
|
1978
|
+
h('div', null, h('div', { style: { fontWeight: 600, marginBottom: 4 } }, '③ 翻译'),
|
|
1979
|
+
h('div', { style: code }, '打开项目 → 选模型 →「自动翻译本批」或「自动翻译全部剩余」。勾选「同时校正日文识别」会先修正同音字、漏字和断句。')),
|
|
1980
|
+
h('div', null, h('div', { style: { fontWeight: 600, marginBottom: 4 } }, '④ 校对与修改'),
|
|
1981
|
+
h('div', { style: code }, '「逐条修改」可改日文和中文、拆分合并、微调时间、删除不需要的行(删除只是不在字幕里显示,不影响导出校验)。也可以给某一条或整批写意见,再「保存意见并重译本批」。')),
|
|
1982
|
+
h('div', null, h('div', { style: { fontWeight: 600, marginBottom: 4 } }, '⑤ 导出'),
|
|
1983
|
+
h('div', { style: code }, '点「导出字幕」,生成与视频同名的 .srt,放在项目目录下。')),
|
|
1984
|
+
h('div', null, h('div', { style: { fontWeight: 600, marginBottom: 4 } }, '背景与术语'),
|
|
1985
|
+
h('div', { style: code }, '「背景与术语」里的标签和说明会随每次翻译交给模型,适合写人名、作品名和节目风格;术语表支持粘贴 CSV 导入和导出。')),
|
|
1986
|
+
h('div', null, h('div', { style: { fontWeight: 600, marginBottom: 4 } }, '注意事项'),
|
|
1987
|
+
h('div', { style: { ...code, display: 'flex', flexDirection: 'column', gap: 2 } },
|
|
1988
|
+
h('span', null, '· 仅支持 Windows;需要 DSH 0.2.1 及以上。'),
|
|
1989
|
+
h('span', null, '· 转写在本机完成;翻译只把你选中的字幕文本发给你在 DSH 里选择的模型服务。'),
|
|
1990
|
+
h('span', null, '· 插件不保存任何 API key,模型凭证由 DSH 管理。'),
|
|
1991
|
+
h('span', null, '· 项目默认在「文档\\DshSubtitle\\projects」,可在面板里更改或直接打开。'),
|
|
1992
|
+
h('span', null, '· 数小时的视频转写较慢,建议先转写完再分几批翻译。'),
|
|
1993
|
+
h('span', null, '· 删除项目时可选「仅从列表移除」或「连本地文件一起删除」,后者不可撤销。'),
|
|
1994
|
+
)),
|
|
1995
|
+
),
|
|
1996
|
+
],
|
|
1997
|
+
actions: [h(B, { key: 'close', style: quietButton, onClick: () => setHelpDialog(false) }, '知道了')],
|
|
1998
|
+
})
|
|
1999
|
+
: null,
|
|
2000
|
+
|
|
2001
|
+
projectsDialog
|
|
2002
|
+
? h(Modal, {
|
|
2003
|
+
title: '项目目录',
|
|
2004
|
+
subtitle: '新项目会保存在这里,也可以把现有项目一起搬过去',
|
|
2005
|
+
width: 'min(640px, 92vw)',
|
|
2006
|
+
onClose: () => setProjectsDialog(false),
|
|
2007
|
+
children: [
|
|
2008
|
+
h('input', {
|
|
2009
|
+
key: 'dir',
|
|
2010
|
+
style: input,
|
|
2011
|
+
value: projectsDraft,
|
|
2012
|
+
placeholder: '例如 C:\\Users\\你\\Documents\\DshSubtitle\\projects',
|
|
2013
|
+
onChange: (event) => setProjectsDraft(event.target.value),
|
|
2014
|
+
}),
|
|
2015
|
+
h(
|
|
2016
|
+
'div',
|
|
2017
|
+
{ key: 'bar', style: { display: 'flex', gap: 6, marginTop: 8, flexWrap: 'wrap' } },
|
|
2018
|
+
h(B, { style: button, onClick: () => browseFor('dir', projectsDraft, 'projects') }, '浏览…'),
|
|
2019
|
+
h(B, { style: small, onClick: () => setProjectsDraft(projectsInfo ? projectsInfo.defaultDir : '') }, '恢复默认(文档)'),
|
|
2020
|
+
),
|
|
2021
|
+
h(
|
|
2022
|
+
'label',
|
|
2023
|
+
{ key: 'move', style: { display: 'flex', gap: 6, alignItems: 'center', marginTop: 10, fontSize: 12, color: tokens.muted } },
|
|
2024
|
+
h('input', { type: 'checkbox', checked: projectsMove, onChange: (event) => setProjectsMove(event.target.checked) }),
|
|
2025
|
+
'把现有项目一起移动到新目录',
|
|
2026
|
+
),
|
|
2027
|
+
projectsInfo && projectsInfo.legacyDir !== projectsInfo.projectsDir
|
|
2028
|
+
? h('div', { key: 'hint', style: { ...code, marginTop: 8, fontSize: 11 } }, '旧目录仍在:' + projectsInfo.legacyDir)
|
|
2029
|
+
: null,
|
|
2030
|
+
],
|
|
2031
|
+
actions: [
|
|
2032
|
+
h(B, { key: 'save', style: primary, onClick: saveProjectsDir }, '保存'),
|
|
2033
|
+
h(B, { key: 'cancel', style: quietButton, onClick: () => setProjectsDialog(false) }, '取消'),
|
|
2034
|
+
],
|
|
2035
|
+
})
|
|
2036
|
+
: null,
|
|
2037
|
+
|
|
1255
2038
|
deleteDialog
|
|
1256
2039
|
? h(Modal, {
|
|
1257
2040
|
title: '删除项目',
|
|
@@ -1260,7 +2043,7 @@ window.__ModuleLoader__.load({
|
|
|
1260
2043
|
children: h(
|
|
1261
2044
|
'div',
|
|
1262
2045
|
{ style: { fontSize: 12, color: tokens.muted, lineHeight: 1.6 } },
|
|
1263
|
-
'
|
|
2046
|
+
'「仅从列表移除」会保留磁盘上的音频、转写结果和字幕文件;「连本地文件一起删除」会删掉整个项目目录,无法撤销。',
|
|
1264
2047
|
),
|
|
1265
2048
|
actions: [
|
|
1266
2049
|
h(B, { key: 'ref', style: button, onClick: () => removeProject(deleteDialog.dir, 'reference') }, '仅从列表移除(保留文件)'),
|