dsh-ai-subtitle 0.2.0 → 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/README.en.md +18 -5
- package/README.ja.md +13 -3
- package/README.ko.md +13 -3
- package/README.md +12 -3
- package/client.js +766 -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-05a'
|
|
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,35 @@ 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 [projectsDraft, setProjectsDraft] = useState('')
|
|
474
|
+
const [projectsMove, setProjectsMove] = useState(true)
|
|
373
475
|
const [places, setPlaces] = useState([])
|
|
374
476
|
const lastDir = useRef('')
|
|
375
477
|
const [componentDialog, setComponentDialog] = useState('')
|
|
@@ -404,6 +506,7 @@ window.__ModuleLoader__.load({
|
|
|
404
506
|
useEffect(() => {
|
|
405
507
|
mounted.current = true
|
|
406
508
|
refresh()
|
|
509
|
+
loadProjectsInfo()
|
|
407
510
|
const timer = setInterval(refresh, 5000)
|
|
408
511
|
trace('body:mounted')
|
|
409
512
|
return () => {
|
|
@@ -438,7 +541,7 @@ window.__ModuleLoader__.load({
|
|
|
438
541
|
refresh()
|
|
439
542
|
}
|
|
440
543
|
|
|
441
|
-
const KIND_LABEL = { install: '安装', transcribe: '转写' }
|
|
544
|
+
const KIND_LABEL = { install: '安装', transcribe: '转写', translate: '翻译' }
|
|
442
545
|
const STATUS_LABEL = { running: '进行中', done: '完成', failed: '失败', cancelled: '已取消' }
|
|
443
546
|
const PHASE_LABEL = {
|
|
444
547
|
starting: '准备',
|
|
@@ -454,20 +557,84 @@ window.__ModuleLoader__.load({
|
|
|
454
557
|
audio: '音频',
|
|
455
558
|
asr: '识别',
|
|
456
559
|
post: '整理',
|
|
560
|
+
translate: '翻译',
|
|
457
561
|
done: '完成',
|
|
458
562
|
}
|
|
459
563
|
|
|
460
|
-
const
|
|
564
|
+
const applyPick = (target, chosen) => {
|
|
565
|
+
if (target === 'projects') setProjectsDraft(chosen)
|
|
566
|
+
else if (target === 'media') setMedia(chosen)
|
|
567
|
+
else setInstallDir(chosen)
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const browseFor = async (mode, startDir, target = 'install') => {
|
|
461
571
|
const result = await callApi('/fs/pick', { method: 'POST', body: JSON.stringify({ mode }) })
|
|
462
572
|
if (result && result.path) {
|
|
463
|
-
|
|
464
|
-
else setMedia(result.path)
|
|
573
|
+
applyPick(target, result.path)
|
|
465
574
|
return
|
|
466
575
|
}
|
|
467
576
|
if (result && result.canceled) return
|
|
577
|
+
setPickerTarget(target)
|
|
468
578
|
openPicker(mode, startDir)
|
|
469
579
|
}
|
|
470
580
|
|
|
581
|
+
const openProjectsFolder = async () => {
|
|
582
|
+
const dir = projectsInfo ? projectsInfo.projectsDir : ''
|
|
583
|
+
const result = await callApi('/open-folder', { method: 'POST', body: JSON.stringify({ dir }) })
|
|
584
|
+
if (result.error) setNotice('打开失败:' + result.error)
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const loadProjectsInfo = async () => {
|
|
588
|
+
const info = await callApi('/settings')
|
|
589
|
+
if (!info.error) setProjectsInfo(info)
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
const openProjectsDialog = async () => {
|
|
593
|
+
const info = await callApi('/settings')
|
|
594
|
+
if (info.error) {
|
|
595
|
+
setNotice('读取设置失败:' + info.error)
|
|
596
|
+
return
|
|
597
|
+
}
|
|
598
|
+
setProjectsInfo(info)
|
|
599
|
+
setProjectsDraft(info.projectsDir || info.defaultDir)
|
|
600
|
+
setProjectsMove(true)
|
|
601
|
+
setProjectsDialog(true)
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const saveProjectsDir = async () => {
|
|
605
|
+
if (!projectsDraft.trim()) return
|
|
606
|
+
const result = await callApi('/settings/projects', {
|
|
607
|
+
method: 'POST',
|
|
608
|
+
body: JSON.stringify({ dir: projectsDraft.trim(), move: projectsMove }),
|
|
609
|
+
})
|
|
610
|
+
if (result.error) {
|
|
611
|
+
setNotice('切换失败:' + result.error)
|
|
612
|
+
return
|
|
613
|
+
}
|
|
614
|
+
const parts = ['项目目录已切换到 ' + result.projectsDir]
|
|
615
|
+
if (projectsMove) parts.push('已移动 ' + result.moved + ' 个项目')
|
|
616
|
+
if (result.failed && result.failed.length) parts.push('未移动:' + result.failed.join('、'))
|
|
617
|
+
setNotice(parts.join(','))
|
|
618
|
+
setProjectsDialog(false)
|
|
619
|
+
setDetail(null)
|
|
620
|
+
setEditing(false)
|
|
621
|
+
refresh()
|
|
622
|
+
loadProjectsInfo()
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
const clearTasks = async () => {
|
|
626
|
+
const result = await callApi('/job/clear', { method: 'POST', body: '{}' })
|
|
627
|
+
if (result.error) setNotice('清空失败:' + result.error)
|
|
628
|
+
else if (!result.removed) setNotice('没有可清空的任务')
|
|
629
|
+
refresh()
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
const removeTask = async (id) => {
|
|
633
|
+
const result = await callApi('/job/remove', { method: 'POST', body: JSON.stringify({ id }) })
|
|
634
|
+
if (result.error || !result.ok) setNotice('删除失败:任务仍在运行或不存在')
|
|
635
|
+
refresh()
|
|
636
|
+
}
|
|
637
|
+
|
|
471
638
|
const cancelTask = async (id) => {
|
|
472
639
|
const result = await callApi('/job/cancel', { method: 'POST', body: JSON.stringify({ id }) })
|
|
473
640
|
setNotice(result.error ? '取消失败:' + result.error : '已取消任务 ' + id)
|
|
@@ -503,6 +670,9 @@ window.__ModuleLoader__.load({
|
|
|
503
670
|
const list = await callApi('/fs/places')
|
|
504
671
|
if (Array.isArray(list.places)) setPlaces(list.places)
|
|
505
672
|
}
|
|
673
|
+
const info = await callApi('/recent')
|
|
674
|
+
if (!info.error) setRecent({ files: info.files || [], dirs: info.dirs || [] })
|
|
675
|
+
setRecentOpen(false)
|
|
506
676
|
loadDir(mode, initial)
|
|
507
677
|
}
|
|
508
678
|
|
|
@@ -511,7 +681,7 @@ window.__ModuleLoader__.load({
|
|
|
511
681
|
loadDir(mode, entry.path)
|
|
512
682
|
return
|
|
513
683
|
}
|
|
514
|
-
|
|
684
|
+
applyPick('media', entry.path)
|
|
515
685
|
setPicker(null)
|
|
516
686
|
}
|
|
517
687
|
|
|
@@ -623,6 +793,219 @@ window.__ModuleLoader__.load({
|
|
|
623
793
|
refresh()
|
|
624
794
|
}
|
|
625
795
|
|
|
796
|
+
const reviewLabel = (progress) => {
|
|
797
|
+
if (!progress || progress.batches === 0) return null
|
|
798
|
+
if (progress.translated >= progress.batches) return h('span', { style: { color: tokens.ok } }, '已翻译')
|
|
799
|
+
if (progress.translated === 0) return h('span', { style: { color: tokens.warn } }, '待翻译')
|
|
800
|
+
return h('span', null, '翻译 ' + progress.translated + '/' + progress.batches + ' 批')
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
const exportProject = async (dir) => {
|
|
804
|
+
const result = await callApi('/export', { method: 'POST', body: JSON.stringify({ dir }) })
|
|
805
|
+
if (result.error) {
|
|
806
|
+
setNotice('导出失败:' + result.error)
|
|
807
|
+
return
|
|
808
|
+
}
|
|
809
|
+
setNotice('已导出 ' + result.stats.cues + ' 条字幕:' + result.out)
|
|
810
|
+
refresh()
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
const loadRoute = async () => {
|
|
814
|
+
const result = await callApi('/llm/route')
|
|
815
|
+
if (!result.error) setLlmRoute(result)
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
const chooseRoute = async (value) => {
|
|
819
|
+
if (!detail || !value) return
|
|
820
|
+
const separator = value.indexOf('/')
|
|
821
|
+
const provider = value.slice(0, separator)
|
|
822
|
+
const model = value.slice(separator + 1)
|
|
823
|
+
await callApi('/llm/route', { method: 'POST', body: JSON.stringify({ dir: detail.dir, provider, model }) })
|
|
824
|
+
setLlmRoute((current) => (current ? { ...current, active: { provider, model } } : { providers: [], active: { provider, model } }))
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
const translateNow = async (all) => {
|
|
828
|
+
if (!detail) return
|
|
829
|
+
setTranslateBusy(true)
|
|
830
|
+
setTranslateNotice('翻译中…')
|
|
831
|
+
try {
|
|
832
|
+
const payload = { dir: detail.dir, mode: proofread ? 'proofread' : 'translate' }
|
|
833
|
+
if (all) payload.all = true
|
|
834
|
+
else if (reviewBatch) payload.batch = reviewBatch.batch
|
|
835
|
+
if (llmRoute && llmRoute.active) {
|
|
836
|
+
payload.provider = llmRoute.active.provider
|
|
837
|
+
payload.model = llmRoute.active.model
|
|
838
|
+
}
|
|
839
|
+
const result = await callApi('/review/translate', { method: 'POST', body: JSON.stringify(payload) })
|
|
840
|
+
if (result.error) {
|
|
841
|
+
setNotice('翻译失败:' + result.error)
|
|
842
|
+
return
|
|
843
|
+
}
|
|
844
|
+
if (result.jobId) {
|
|
845
|
+
setTranslateJobId(result.jobId)
|
|
846
|
+
setNotice('开始翻译:共 ' + result.total + ' 批')
|
|
847
|
+
setTranslateNotice('准备中…')
|
|
848
|
+
const dir = detail.dir
|
|
849
|
+
for (let tick = 0; tick < 900; tick += 1) {
|
|
850
|
+
await new Promise((resolve) => setTimeout(resolve, 2000))
|
|
851
|
+
const job = await callApi('/job?id=' + encodeURIComponent(result.jobId))
|
|
852
|
+
if (job.error) {
|
|
853
|
+
setNotice('翻译任务:' + job.error)
|
|
854
|
+
break
|
|
855
|
+
}
|
|
856
|
+
if (job.status === 'done') {
|
|
857
|
+
setNotice('翻译完成')
|
|
858
|
+
break
|
|
859
|
+
}
|
|
860
|
+
if (job.status === 'failed') {
|
|
861
|
+
setNotice('翻译失败:' + (job.error || '未知错误'))
|
|
862
|
+
break
|
|
863
|
+
}
|
|
864
|
+
if (job.status === 'cancelled') {
|
|
865
|
+
setNotice('翻译已取消')
|
|
866
|
+
break
|
|
867
|
+
}
|
|
868
|
+
setNotice('翻译中:' + (job.msg || job.pct + '% ' + (job.phase || '')))
|
|
869
|
+
setTranslateNotice(job.msg || '翻译中…')
|
|
870
|
+
}
|
|
871
|
+
setTranslateJobId('')
|
|
872
|
+
await loadReview(dir)
|
|
873
|
+
refresh()
|
|
874
|
+
return
|
|
875
|
+
}
|
|
876
|
+
setNotice('已翻译批次 ' + result.batch + '(' + result.route + '),写入 ' + result.cues + ' 条' + (result.jpChanged ? ',校正日文 ' + result.jpChanged + ' 条' : ''))
|
|
877
|
+
setFeedbackDraft({})
|
|
878
|
+
setBatchNote('')
|
|
879
|
+
await openProject(detail)
|
|
880
|
+
} finally {
|
|
881
|
+
setTranslateBusy(false)
|
|
882
|
+
setTranslateNotice('')
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
const saveFeedbackAndRetranslate = async () => {
|
|
887
|
+
if (!detail || !reviewBatch) return
|
|
888
|
+
const batch = reviewBatch.batch
|
|
889
|
+
for (const [range, note] of Object.entries(feedbackDraft)) {
|
|
890
|
+
if (!note.trim()) continue
|
|
891
|
+
await callApi('/review/feedback', { method: 'POST', body: JSON.stringify({ dir: detail.dir, batch, range, note }) })
|
|
892
|
+
}
|
|
893
|
+
if (batchNote.trim()) {
|
|
894
|
+
await callApi('/review/feedback', { method: 'POST', body: JSON.stringify({ dir: detail.dir, batch, note: batchNote }) })
|
|
895
|
+
}
|
|
896
|
+
setBatchNote('')
|
|
897
|
+
await translateNow(false)
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
const loadHints = async (dir) => {
|
|
901
|
+
const result = await callApi('/hints?dir=' + encodeURIComponent(dir))
|
|
902
|
+
if (!result.error) setHints({ tags: result.tags || [], note: result.note || '' })
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
const loadGlossaryInfo = async (dir) => {
|
|
906
|
+
const result = await callApi('/glossary?dir=' + encodeURIComponent(dir))
|
|
907
|
+
if (!result.error) setGlossaryInfo(result.glossary)
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
const openContextDialog = async () => {
|
|
911
|
+
if (!detail) return
|
|
912
|
+
await loadGlossaryInfo(detail.dir)
|
|
913
|
+
setContextDialog(true)
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
const saveContext = async () => {
|
|
917
|
+
if (!detail) return
|
|
918
|
+
const result = await callApi('/hints', {
|
|
919
|
+
method: 'POST',
|
|
920
|
+
body: JSON.stringify({ dir: detail.dir, tags: hints.tags, note: hints.note }),
|
|
921
|
+
})
|
|
922
|
+
if (result.error) {
|
|
923
|
+
setNotice('保存失败:' + result.error)
|
|
924
|
+
return
|
|
925
|
+
}
|
|
926
|
+
setHints(result.hints)
|
|
927
|
+
setNotice('背景与标签已保存,下一次翻译会带上')
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
const addTag = () => {
|
|
931
|
+
const tag = tagDraft.trim()
|
|
932
|
+
if (!tag) return
|
|
933
|
+
if (!hints.tags.includes(tag)) setHints({ ...hints, tags: [...hints.tags, tag].slice(0, 20) })
|
|
934
|
+
setTagDraft('')
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
const importGlossary = async () => {
|
|
938
|
+
if (!detail) return
|
|
939
|
+
if (!glossaryText.trim()) {
|
|
940
|
+
setNotice('请先粘贴 CSV 内容')
|
|
941
|
+
return
|
|
942
|
+
}
|
|
943
|
+
const result = await callApi('/glossary/import', {
|
|
944
|
+
method: 'POST',
|
|
945
|
+
body: JSON.stringify({ dir: detail.dir, text: glossaryText }),
|
|
946
|
+
})
|
|
947
|
+
if (result.error) {
|
|
948
|
+
setNotice('导入失败:' + result.error)
|
|
949
|
+
return
|
|
950
|
+
}
|
|
951
|
+
setGlossaryText('')
|
|
952
|
+
await loadGlossaryInfo(detail.dir)
|
|
953
|
+
setNotice('术语表已导入:新增 ' + result.summary.added + ',更新 ' + result.summary.updated)
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
const exportGlossary = async () => {
|
|
957
|
+
if (!detail) return
|
|
958
|
+
const result = await callApi('/glossary/export', { method: 'POST', body: JSON.stringify({ dir: detail.dir }) })
|
|
959
|
+
if (result.error) {
|
|
960
|
+
setNotice('导出失败:' + result.error)
|
|
961
|
+
return
|
|
962
|
+
}
|
|
963
|
+
setNotice('已导出 CSV:' + result.path)
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
const loadReview = async (dir, batchId) => {
|
|
967
|
+
const status = await callApi('/review/status?dir=' + encodeURIComponent(dir))
|
|
968
|
+
if (status.error) {
|
|
969
|
+
setReview(null)
|
|
970
|
+
setReviewBatch(null)
|
|
971
|
+
return
|
|
972
|
+
}
|
|
973
|
+
setReview(status)
|
|
974
|
+
const wanted = batchId || status.next
|
|
975
|
+
if (!wanted) {
|
|
976
|
+
setReviewBatch(null)
|
|
977
|
+
return
|
|
978
|
+
}
|
|
979
|
+
const got = await callApi('/review/next?dir=' + encodeURIComponent(dir) + '&batch=' + encodeURIComponent(wanted))
|
|
980
|
+
setReviewBatch(got.error || got.done ? null : got)
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
const applyReview = async () => {
|
|
984
|
+
if (!detail || !reviewBatch) return
|
|
985
|
+
const result = await callApi('/review/apply', {
|
|
986
|
+
method: 'POST',
|
|
987
|
+
body: JSON.stringify({ dir: detail.dir, batch: reviewBatch.batch, lines: reviewInput, allowEmpty: reviewAllowEmpty }),
|
|
988
|
+
})
|
|
989
|
+
if (result.error) {
|
|
990
|
+
setNotice('应用失败:' + result.error)
|
|
991
|
+
return
|
|
992
|
+
}
|
|
993
|
+
const skipped = result.skipped ? `,跳過 ${result.skipped} 段` : ''
|
|
994
|
+
setNotice(`已应用批次 ${result.batch}:写入 ${result.cues} 条${skipped}`)
|
|
995
|
+
setReviewInput('')
|
|
996
|
+
await openProject(detail)
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
const copyBatch = async () => {
|
|
1000
|
+
if (!reviewBatch) return
|
|
1001
|
+
try {
|
|
1002
|
+
await navigator.clipboard.writeText(reviewBatch.lines)
|
|
1003
|
+
setNotice('已复制批次 ' + reviewBatch.batch + ',粘贴给模型即可')
|
|
1004
|
+
} catch {
|
|
1005
|
+
setNotice('浏览器不允许写剪贴板,请手动选择下方文本复制')
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
|
|
626
1009
|
const openProject = async (project) => {
|
|
627
1010
|
const next = await callApi('/project?dir=' + encodeURIComponent(project.dir))
|
|
628
1011
|
if (next.error) {
|
|
@@ -632,6 +1015,14 @@ window.__ModuleLoader__.load({
|
|
|
632
1015
|
setDetail(next)
|
|
633
1016
|
setEditing(false)
|
|
634
1017
|
setDraft(Array.isArray(next.cueList) ? next.cueList.map((cue) => ({ ...cue })) : [])
|
|
1018
|
+
setReviewInput('')
|
|
1019
|
+
setReviewBatch(null)
|
|
1020
|
+
setReview(null)
|
|
1021
|
+
setFeedbackDraft({})
|
|
1022
|
+
setBatchNote('')
|
|
1023
|
+
loadRoute()
|
|
1024
|
+
loadHints(next.dir)
|
|
1025
|
+
loadReview(next.dir)
|
|
635
1026
|
}
|
|
636
1027
|
|
|
637
1028
|
const togglePin = async (project) => {
|
|
@@ -665,7 +1056,15 @@ window.__ModuleLoader__.load({
|
|
|
665
1056
|
}
|
|
666
1057
|
|
|
667
1058
|
const updateDraft = (index, field, value) => {
|
|
668
|
-
setDraft((current) =>
|
|
1059
|
+
setDraft((current) =>
|
|
1060
|
+
current.map((cue, position) => {
|
|
1061
|
+
if (position !== index) return cue
|
|
1062
|
+
// typing text over a skipped range turns it back into a normal cue
|
|
1063
|
+
const next = { ...cue, [field]: value }
|
|
1064
|
+
if ((field === 'jp' || field === 'zh') && String(value).trim()) delete next.skip
|
|
1065
|
+
return next
|
|
1066
|
+
}),
|
|
1067
|
+
)
|
|
669
1068
|
}
|
|
670
1069
|
|
|
671
1070
|
const saveEdits = async () => {
|
|
@@ -690,14 +1089,14 @@ window.__ModuleLoader__.load({
|
|
|
690
1089
|
|
|
691
1090
|
const importCues = async () => {
|
|
692
1091
|
if (!detail || !cueSource.trim()) {
|
|
693
|
-
setNotice('
|
|
1092
|
+
setNotice('请先选择项目并填写字幕内容文件的绝对路径')
|
|
694
1093
|
return
|
|
695
1094
|
}
|
|
696
1095
|
const result = await callApi('/import-cues', {
|
|
697
1096
|
method: 'POST',
|
|
698
1097
|
body: JSON.stringify({ dir: detail.dir, from: cueSource.trim() }),
|
|
699
1098
|
})
|
|
700
|
-
setNotice(result.error ? '导入失败:' + result.error : '
|
|
1099
|
+
setNotice(result.error ? '导入失败:' + result.error : '已导入字幕内容')
|
|
701
1100
|
openProject(detail)
|
|
702
1101
|
}
|
|
703
1102
|
|
|
@@ -801,7 +1200,9 @@ window.__ModuleLoader__.load({
|
|
|
801
1200
|
setDraft((current) => current.map((cue) => ({ from: cue.from, to: cue.to, jp: cue.jp, zh: cue.zh })))
|
|
802
1201
|
}
|
|
803
1202
|
|
|
804
|
-
const small = { ...button, padding: '2px 7px', fontSize: 11 }
|
|
1203
|
+
const small = { ...button, padding: '2px 7px', fontSize: 11, minHeight: 26 }
|
|
1204
|
+
/** Between the tiny inline buttons and the main toolbar actions. */
|
|
1205
|
+
const medium = { ...button, padding: '4px 10px', fontSize: 12, minHeight: 30 }
|
|
805
1206
|
|
|
806
1207
|
return h(
|
|
807
1208
|
'div',
|
|
@@ -978,7 +1379,14 @@ window.__ModuleLoader__.load({
|
|
|
978
1379
|
h(
|
|
979
1380
|
'div',
|
|
980
1381
|
{ style: { ...card } },
|
|
981
|
-
h(
|
|
1382
|
+
h(
|
|
1383
|
+
'div',
|
|
1384
|
+
{ style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6 } },
|
|
1385
|
+
h('div', { style: sectionTitle }, '任务'),
|
|
1386
|
+
jobs.some((job) => job.status !== 'running')
|
|
1387
|
+
? h(B, { style: medium, onClick: clearTasks }, '清空已结束')
|
|
1388
|
+
: null,
|
|
1389
|
+
),
|
|
982
1390
|
jobs.length === 0
|
|
983
1391
|
? h('div', { style: { ...code, marginTop: 4 } }, '暂无任务')
|
|
984
1392
|
: jobs.map((job) =>
|
|
@@ -998,11 +1406,12 @@ window.__ModuleLoader__.load({
|
|
|
998
1406
|
{ style: { display: 'flex', gap: 6, alignItems: 'center' } },
|
|
999
1407
|
h('span', { style: code }, job.pct + '% ' + (PHASE_LABEL[job.phase] || job.phase || '')),
|
|
1000
1408
|
job.status === 'running'
|
|
1001
|
-
? h(B, { style:
|
|
1002
|
-
:
|
|
1409
|
+
? h(B, { style: medium, onClick: () => cancelTask(job.id) }, '取消')
|
|
1410
|
+
: h(B, { style: medium, onClick: () => removeTask(job.id) }, '删除'),
|
|
1003
1411
|
),
|
|
1004
1412
|
),
|
|
1005
1413
|
h(Progress, { pct: job.pct, status: job.status }),
|
|
1414
|
+
job.msg ? h('div', { style: { ...code, marginTop: 4 } }, job.msg) : null,
|
|
1006
1415
|
job.error ? h('div', { style: { ...code, color: tokens.danger, marginTop: 8 } }, job.error) : null,
|
|
1007
1416
|
job.projectDir ? h('div', { style: { ...code, marginTop: 4 } }, job.projectDir) : null,
|
|
1008
1417
|
),
|
|
@@ -1018,10 +1427,21 @@ window.__ModuleLoader__.load({
|
|
|
1018
1427
|
h('div', { style: sectionTitle }, '项目'),
|
|
1019
1428
|
h(
|
|
1020
1429
|
'label',
|
|
1021
|
-
{ style: { display: 'flex', gap: 4, alignItems: 'center', fontSize: 11, color: tokens.muted } },
|
|
1430
|
+
{ style: { display: 'flex', gap: 4, alignItems: 'center', fontSize: 11, color: tokens.muted }, title: '只从列表移除、文件仍保留的项目会出现在这里,可以再恢复' },
|
|
1022
1431
|
h('input', { type: 'checkbox', checked: showHidden, onChange: (event) => setShowHidden(event.target.checked) }),
|
|
1023
|
-
'
|
|
1432
|
+
'显示已移除的项目',
|
|
1433
|
+
),
|
|
1434
|
+
),
|
|
1435
|
+
h(
|
|
1436
|
+
'div',
|
|
1437
|
+
{ style: { display: 'flex', gap: 8, alignItems: 'center', marginBottom: 8, flexWrap: 'wrap' } },
|
|
1438
|
+
h(
|
|
1439
|
+
'span',
|
|
1440
|
+
{ style: { ...code, fontSize: 11, flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', userSelect: 'text' } },
|
|
1441
|
+
projectsInfo ? projectsInfo.projectsDir : '项目目录读取中…',
|
|
1024
1442
|
),
|
|
1443
|
+
h(B, { style: medium, onClick: openProjectsDialog }, '更改目录'),
|
|
1444
|
+
h(B, { style: medium, onClick: openProjectsFolder }, '打开目录'),
|
|
1025
1445
|
),
|
|
1026
1446
|
visibleProjects.length === 0
|
|
1027
1447
|
? h('div', { style: code }, '还没有项目,先在下面转写一个视频')
|
|
@@ -1042,6 +1462,15 @@ window.__ModuleLoader__.load({
|
|
|
1042
1462
|
},
|
|
1043
1463
|
project.name,
|
|
1044
1464
|
),
|
|
1465
|
+
project.review && project.review.translated < project.review.batches
|
|
1466
|
+
? h(B, {
|
|
1467
|
+
style: { ...primary, padding: '4px 10px', flex: '0 0 auto' },
|
|
1468
|
+
onClick: () => openProject(project),
|
|
1469
|
+
}, project.review.translated === 0 ? '开始翻译' : '继续翻译')
|
|
1470
|
+
: h(B, {
|
|
1471
|
+
style: { ...medium, flex: '0 0 auto' },
|
|
1472
|
+
onClick: () => exportProject(project.dir),
|
|
1473
|
+
}, '导出'),
|
|
1045
1474
|
h(B, {
|
|
1046
1475
|
style: { ...button, padding: '6px 8px' },
|
|
1047
1476
|
title: project.pinned ? '取消置顶' : '置顶',
|
|
@@ -1057,16 +1486,17 @@ window.__ModuleLoader__.load({
|
|
|
1057
1486
|
style: { ...button, padding: '6px 8px' },
|
|
1058
1487
|
title: '恢复显示',
|
|
1059
1488
|
onClick: () => restoreProject(project),
|
|
1060
|
-
}, '
|
|
1489
|
+
}, '恢复到列表')
|
|
1061
1490
|
: null,
|
|
1062
1491
|
),
|
|
1063
1492
|
h(
|
|
1064
1493
|
'div',
|
|
1065
|
-
{ style: { ...code, display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
1066
|
-
h('span', null, project.fragments + '
|
|
1067
|
-
h('span', null, project.cues + '
|
|
1494
|
+
{ style: { ...code, display: 'flex', gap: 8, flexWrap: 'wrap', alignItems: 'center' } },
|
|
1495
|
+
h('span', null, project.fragments + ' 句'),
|
|
1496
|
+
h('span', null, project.cues + ' 条字幕'),
|
|
1497
|
+
reviewLabel(project.review),
|
|
1068
1498
|
project.srt ? h('span', null, 'SRT') : null,
|
|
1069
|
-
project.hidden ? h('span', { style: { color: tokens.danger } }, '
|
|
1499
|
+
project.hidden ? h('span', { style: { color: tokens.danger } }, '已从列表移除') : null,
|
|
1070
1500
|
),
|
|
1071
1501
|
),
|
|
1072
1502
|
),
|
|
@@ -1087,13 +1517,22 @@ window.__ModuleLoader__.load({
|
|
|
1087
1517
|
h(B, { key: 'close', style: quietButton, onClick: () => { setDetail(null); setEditing(false) } }, '关闭'),
|
|
1088
1518
|
],
|
|
1089
1519
|
children: [
|
|
1520
|
+
h(
|
|
1521
|
+
'div',
|
|
1522
|
+
{ key: 'stepper', style: { display: 'flex', gap: 6, alignItems: 'center', marginBottom: 8, fontSize: 12, color: tokens.muted, flexWrap: 'wrap' } },
|
|
1523
|
+
h('span', { style: { color: tokens.ok } }, '① 转写 ✓'),
|
|
1524
|
+
h('span', null, '→'),
|
|
1525
|
+
h('span', { style: review && review.translated >= review.batches ? { color: tokens.ok } : { color: tokens.text } }, review ? '② 翻译 ' + review.translated + '/' + review.batches + ' 批' : '② 翻译 …'),
|
|
1526
|
+
h('span', null, '→'),
|
|
1527
|
+
h('span', null, '③ 导出字幕'),
|
|
1528
|
+
),
|
|
1090
1529
|
detail.errors && detail.errors.length
|
|
1091
1530
|
? h('div', { key: 'errors', style: { ...code, color: tokens.danger, marginBottom: 8 } }, detail.errors.join(';'))
|
|
1092
1531
|
: null,
|
|
1093
1532
|
h(
|
|
1094
1533
|
'div',
|
|
1095
1534
|
{ key: 'toolbar', style: { display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
1096
|
-
h(B, { style: primary, onClick: exportSrt }, '
|
|
1535
|
+
h(B, { style: primary, onClick: exportSrt }, '导出字幕'),
|
|
1097
1536
|
h(B,
|
|
1098
1537
|
{
|
|
1099
1538
|
style: editing ? primary : button,
|
|
@@ -1103,21 +1542,145 @@ window.__ModuleLoader__.load({
|
|
|
1103
1542
|
},
|
|
1104
1543
|
disabled: !detail.cueList || detail.cueList.length === 0,
|
|
1105
1544
|
},
|
|
1106
|
-
editing ? '
|
|
1545
|
+
editing ? '取消修改' : '逐条修改',
|
|
1107
1546
|
),
|
|
1108
1547
|
editing
|
|
1109
1548
|
? h(B, { style: primary, onClick: saveEdits }, '保存修改')
|
|
1110
1549
|
: h(B, { style: button, onClick: () => openProject(detail) }, '刷新'),
|
|
1111
1550
|
editing ? h(B, { style: quietButton, onClick: resetTimes }, '全部恢复自动时间') : null,
|
|
1112
1551
|
),
|
|
1552
|
+
!editing && review && review.batches > 0 && review.translated < review.batches
|
|
1553
|
+
? h(
|
|
1554
|
+
'div',
|
|
1555
|
+
{ key: 'review', style: { marginTop: 10, padding: 10, border: '1px solid ' + tokens.border, borderRadius: 8 } },
|
|
1556
|
+
h(
|
|
1557
|
+
'div',
|
|
1558
|
+
{ style: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } },
|
|
1559
|
+
h('div', { style: sectionTitle }, '自动翻译 · 第 ' + (reviewBatch ? reviewBatch.batch.replace('-', '–') : '…') + ' 句'),
|
|
1560
|
+
h('span', { style: code }, llmRoute && llmRoute.active ? llmRoute.active.provider + '/' + llmRoute.active.model : '模型解析中…'),
|
|
1561
|
+
h(B, { style: medium, onClick: loadRoute }, '刷新模型'),
|
|
1562
|
+
),
|
|
1563
|
+
llmRoute && llmRoute.providers && llmRoute.providers.length > 0
|
|
1564
|
+
? h(RouteSelect, {
|
|
1565
|
+
value: llmRoute.active ? llmRoute.active.provider + '/' + llmRoute.active.model : '',
|
|
1566
|
+
placeholder: '选择模型',
|
|
1567
|
+
options: llmRoute.providers.flatMap((provider) =>
|
|
1568
|
+
provider.models.map((model) => ({
|
|
1569
|
+
value: provider.id + '/' + model,
|
|
1570
|
+
label: provider.name + ' · ' + model,
|
|
1571
|
+
})),
|
|
1572
|
+
),
|
|
1573
|
+
onChange: chooseRoute,
|
|
1574
|
+
})
|
|
1575
|
+
: null,
|
|
1576
|
+
h(
|
|
1577
|
+
'div',
|
|
1578
|
+
{ style: { display: 'flex', gap: 6, marginTop: 8, alignItems: 'center', flexWrap: 'wrap' } },
|
|
1579
|
+
hints.tags.length > 0
|
|
1580
|
+
? hints.tags.map((tag) => h('span', { key: tag, style: { ...small, cursor: 'default', padding: '2px 8px', opacity: 0.9 } }, '#' + tag))
|
|
1581
|
+
: h('span', { style: { ...code, marginRight: 4 } }, '未设置背景标签'),
|
|
1582
|
+
h(B, { style: medium, onClick: openContextDialog }, '背景与术语'),
|
|
1583
|
+
),
|
|
1584
|
+
h(
|
|
1585
|
+
'div',
|
|
1586
|
+
{ style: { display: 'flex', gap: 6, marginTop: 8, flexWrap: 'wrap' } },
|
|
1587
|
+
h(B, { style: primary, onClick: () => translateNow(false), disabled: translateBusy || !reviewBatch }, translateBusy ? translateNotice || '翻译中…' : '自动翻译本批'),
|
|
1588
|
+
h(B, { style: button, onClick: () => translateNow(true), disabled: translateBusy }, '自动翻译全部剩余'),
|
|
1589
|
+
translateJobId
|
|
1590
|
+
? h(B, {
|
|
1591
|
+
style: dangerButton,
|
|
1592
|
+
onClick: async () => {
|
|
1593
|
+
await callApi('/job/cancel', { method: 'POST', body: JSON.stringify({ id: translateJobId }) })
|
|
1594
|
+
setNotice('已请求取消翻译')
|
|
1595
|
+
},
|
|
1596
|
+
}, '停止翻译')
|
|
1597
|
+
: null,
|
|
1598
|
+
h(B, { style: small, onClick: () => loadReview(detail.dir) }, '刷新进度'),
|
|
1599
|
+
h(
|
|
1600
|
+
'label',
|
|
1601
|
+
{ style: { display: 'flex', gap: 4, alignItems: 'center', fontSize: 11, color: tokens.muted } },
|
|
1602
|
+
h('input', { type: 'checkbox', checked: proofread, onChange: (event) => setProofread(event.target.checked) }),
|
|
1603
|
+
'同时校正日文识别',
|
|
1604
|
+
),
|
|
1605
|
+
),
|
|
1606
|
+
reviewBatch && reviewBatch.cues && reviewBatch.cues.length > 0
|
|
1607
|
+
? h(
|
|
1608
|
+
'div',
|
|
1609
|
+
{ style: { marginTop: 10 } },
|
|
1610
|
+
h('div', { style: sectionTitle }, '这一段的结果与意见'),
|
|
1611
|
+
reviewBatch.cues.map((cue) =>
|
|
1612
|
+
h(
|
|
1613
|
+
'div',
|
|
1614
|
+
{ key: cue.from + '-' + cue.to, style: { padding: '6px 0', borderTop: '1px solid ' + tokens.border } },
|
|
1615
|
+
h('div', { style: code }, cue.from + '-' + cue.to + (cue.skip ? ' · 跳过' : '')),
|
|
1616
|
+
h('div', null, cue.jp),
|
|
1617
|
+
h('div', { style: { color: tokens.muted } }, cue.zh || '(空)'),
|
|
1618
|
+
h('input', {
|
|
1619
|
+
style: { ...input, marginTop: 4, fontSize: 11 },
|
|
1620
|
+
placeholder: '对这一条的意见,例如:称呼应译成“老板”',
|
|
1621
|
+
value: feedbackDraft[cue.from + '-' + cue.to] || '',
|
|
1622
|
+
onChange: (event) => setFeedbackDraft({ ...feedbackDraft, [cue.from + '-' + cue.to]: event.target.value }),
|
|
1623
|
+
}),
|
|
1624
|
+
),
|
|
1625
|
+
),
|
|
1626
|
+
h('input', {
|
|
1627
|
+
style: { ...input, marginTop: 8, fontSize: 11 },
|
|
1628
|
+
placeholder: '整批意见(可选)',
|
|
1629
|
+
value: batchNote,
|
|
1630
|
+
onChange: (event) => setBatchNote(event.target.value),
|
|
1631
|
+
}),
|
|
1632
|
+
h(
|
|
1633
|
+
'div',
|
|
1634
|
+
{ style: { display: 'flex', gap: 6, marginTop: 8, flexWrap: 'wrap' } },
|
|
1635
|
+
h(B, { style: button, onClick: saveFeedbackAndRetranslate, disabled: translateBusy }, '保存意见并重译本批'),
|
|
1636
|
+
h(B, { style: small, onClick: () => { setFeedbackDraft({}); setBatchNote('') } }, '清空意见'),
|
|
1637
|
+
),
|
|
1638
|
+
)
|
|
1639
|
+
: null,
|
|
1640
|
+
h(
|
|
1641
|
+
'details',
|
|
1642
|
+
{ style: { marginTop: 10 } },
|
|
1643
|
+
h('summary', { style: { cursor: 'pointer', fontSize: 11, color: tokens.muted } }, '手动:复制批次 / 粘贴模型结果'),
|
|
1644
|
+
h('textarea', {
|
|
1645
|
+
readOnly: true,
|
|
1646
|
+
value: reviewBatch ? reviewBatch.lines : '',
|
|
1647
|
+
onFocus: (event) => event.target.select(),
|
|
1648
|
+
style: { ...input, height: 110, fontSize: 11, marginTop: 6, fontFamily: 'ui-monospace, monospace' },
|
|
1649
|
+
}),
|
|
1650
|
+
h('div', { style: { display: 'flex', gap: 6, marginTop: 6 } }, h(B, { style: small, onClick: copyBatch, disabled: !reviewBatch }, '复制本批')),
|
|
1651
|
+
h('textarea', {
|
|
1652
|
+
placeholder: '粘贴 from-to|jp|zh 行',
|
|
1653
|
+
value: reviewInput,
|
|
1654
|
+
onChange: (event) => setReviewInput(event.target.value),
|
|
1655
|
+
style: { ...input, height: 100, fontSize: 11, marginTop: 6, fontFamily: 'ui-monospace, monospace' },
|
|
1656
|
+
}),
|
|
1657
|
+
h(
|
|
1658
|
+
'div',
|
|
1659
|
+
{ style: { display: 'flex', gap: 8, marginTop: 6, alignItems: 'center' } },
|
|
1660
|
+
h(B, { style: primary, onClick: applyReview, disabled: !reviewBatch || !reviewInput.trim() }, '应用本批'),
|
|
1661
|
+
h(
|
|
1662
|
+
'label',
|
|
1663
|
+
{ style: { display: 'flex', gap: 4, alignItems: 'center', fontSize: 11, color: tokens.muted } },
|
|
1664
|
+
h('input', { type: 'checkbox', checked: reviewAllowEmpty, onChange: (event) => setReviewAllowEmpty(event.target.checked) }),
|
|
1665
|
+
'允许空中文',
|
|
1666
|
+
),
|
|
1667
|
+
),
|
|
1668
|
+
),
|
|
1669
|
+
)
|
|
1670
|
+
: h(
|
|
1671
|
+
'div',
|
|
1672
|
+
{ key: 'review-done', style: { marginTop: 10, padding: 10, border: '1px solid ' + tokens.border, borderRadius: 8 } },
|
|
1673
|
+
h('div', { style: { ...code, color: review && review.batches > 0 ? tokens.ok : tokens.muted, marginBottom: 8 } }, review && review.batches > 0 ? '已全部翻译完成,可以导出字幕了' : '还没有字幕内容,点上面的「自动翻译本批」开始'),
|
|
1674
|
+
h(B, { style: primary, onClick: exportSrt }, '导出字幕'),
|
|
1675
|
+
),
|
|
1113
1676
|
h('input', {
|
|
1114
1677
|
key: 'import',
|
|
1115
1678
|
style: { ...input, marginTop: 8 },
|
|
1116
1679
|
value: cueSource,
|
|
1117
|
-
placeholder: '
|
|
1680
|
+
placeholder: '高级:从文件导入字幕内容(cues.json 绝对路径)',
|
|
1118
1681
|
onChange: (event) => setCueSource(event.target.value),
|
|
1119
1682
|
}),
|
|
1120
|
-
h(B, { key: 'import-btn', style: { ...button, marginTop: 6 }, onClick: importCues }, '
|
|
1683
|
+
h(B, { key: 'import-btn', style: { ...button, marginTop: 6 }, onClick: importCues }, '从文件导入'),
|
|
1121
1684
|
editing
|
|
1122
1685
|
? h(
|
|
1123
1686
|
'div',
|
|
@@ -1129,11 +1692,12 @@ window.__ModuleLoader__.load({
|
|
|
1129
1692
|
h(
|
|
1130
1693
|
'div',
|
|
1131
1694
|
{ style: code },
|
|
1132
|
-
'#' + (index + 1) + ' · ' + Number(cue.start).toFixed(2) + 's → ' + Number(cue.end).toFixed(2) + 's ·
|
|
1695
|
+
'#' + (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
1696
|
),
|
|
1134
1697
|
h('input', {
|
|
1135
1698
|
style: { ...input, marginTop: 4 },
|
|
1136
1699
|
value: cue.jp,
|
|
1700
|
+
placeholder: cue.skip ? '已删除,不显示在字幕里' : '',
|
|
1137
1701
|
onChange: (event) => updateDraft(index, 'jp', event.target.value),
|
|
1138
1702
|
}),
|
|
1139
1703
|
h('input', {
|
|
@@ -1149,7 +1713,12 @@ window.__ModuleLoader__.load({
|
|
|
1149
1713
|
h(B, { style: small, onClick: () => nudgeTime(index, 'end', -0.1) }, '终点 −0.1'),
|
|
1150
1714
|
h(B, { style: small, onClick: () => nudgeTime(index, 'end', 0.1) }, '终点 +0.1'),
|
|
1151
1715
|
h(B, { style: small, onClick: () => splitCue(index) }, '拆分'),
|
|
1152
|
-
|
|
1716
|
+
h(B, { style: small, disabled: index === draft.length - 1, onClick: () => mergeNext(index) }, '与下一条合并'),
|
|
1717
|
+
h(
|
|
1718
|
+
B,
|
|
1719
|
+
{ style: cue.skip ? small : dangerButton, onClick: () => setDraft((current) => current.map((item, i) => (i === index ? { ...item, skip: !item.skip } : item))) },
|
|
1720
|
+
cue.skip ? '恢复' : '删除',
|
|
1721
|
+
),
|
|
1153
1722
|
),
|
|
1154
1723
|
),
|
|
1155
1724
|
),
|
|
@@ -1182,6 +1751,55 @@ window.__ModuleLoader__.load({
|
|
|
1182
1751
|
inlineActions: true,
|
|
1183
1752
|
onClose: () => setPicker(null),
|
|
1184
1753
|
children: [
|
|
1754
|
+
(recent.files.length > 0 || recent.dirs.length > 0)
|
|
1755
|
+
? h(
|
|
1756
|
+
'div',
|
|
1757
|
+
{ key: 'recent', style: { marginBottom: 8 } },
|
|
1758
|
+
h(
|
|
1759
|
+
B,
|
|
1760
|
+
{
|
|
1761
|
+
style: { ...medium, width: '100%', textAlign: 'left', justifyContent: 'flex-start' },
|
|
1762
|
+
onClick: () => setRecentOpen(!recentOpen),
|
|
1763
|
+
},
|
|
1764
|
+
(recentOpen ? '▾ ' : '▸ ') + '最近使用(' + recent.files.length + ' 个文件 / ' + recent.dirs.length + ' 个文件夹)',
|
|
1765
|
+
),
|
|
1766
|
+
recentOpen
|
|
1767
|
+
? h(
|
|
1768
|
+
'div',
|
|
1769
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 4, marginTop: 6 } },
|
|
1770
|
+
picker.mode === 'file'
|
|
1771
|
+
? recent.files.map((entry) =>
|
|
1772
|
+
h(
|
|
1773
|
+
B,
|
|
1774
|
+
{
|
|
1775
|
+
key: entry,
|
|
1776
|
+
title: entry,
|
|
1777
|
+
style: { ...small, width: '100%', textAlign: 'left', justifyContent: 'flex-start', fontSize: 12, height: 30, padding: '0 10px' },
|
|
1778
|
+
onClick: () => {
|
|
1779
|
+
applyPick('media', entry)
|
|
1780
|
+
setPicker(null)
|
|
1781
|
+
},
|
|
1782
|
+
},
|
|
1783
|
+
'🎬 ' + entry.split(/[\\/]/).pop(),
|
|
1784
|
+
),
|
|
1785
|
+
)
|
|
1786
|
+
: null,
|
|
1787
|
+
recent.dirs.map((entry) =>
|
|
1788
|
+
h(
|
|
1789
|
+
B,
|
|
1790
|
+
{
|
|
1791
|
+
key: entry,
|
|
1792
|
+
title: entry,
|
|
1793
|
+
style: { ...small, width: '100%', textAlign: 'left', justifyContent: 'flex-start', fontSize: 12, height: 30, padding: '0 10px' },
|
|
1794
|
+
onClick: () => loadDir(picker.mode, entry),
|
|
1795
|
+
},
|
|
1796
|
+
'📁 ' + entry,
|
|
1797
|
+
),
|
|
1798
|
+
),
|
|
1799
|
+
)
|
|
1800
|
+
: null,
|
|
1801
|
+
)
|
|
1802
|
+
: null,
|
|
1185
1803
|
places.length > 0
|
|
1186
1804
|
? h(
|
|
1187
1805
|
'div',
|
|
@@ -1245,13 +1863,132 @@ window.__ModuleLoader__.load({
|
|
|
1245
1863
|
],
|
|
1246
1864
|
actions: [
|
|
1247
1865
|
picker.mode === 'dir'
|
|
1248
|
-
? h(B, { key: 'choose', style: primary, onClick: () => {
|
|
1866
|
+
? h(B, { key: 'choose', style: primary, onClick: () => { applyPick(pickerTarget, picker.dir); setPicker(null) } }, '选择当前文件夹')
|
|
1249
1867
|
: null,
|
|
1250
1868
|
h(B, { key: 'cancel', style: quietButton, onClick: () => setPicker(null) }, '取消'),
|
|
1251
1869
|
].filter(Boolean),
|
|
1252
1870
|
})
|
|
1253
1871
|
: null,
|
|
1254
1872
|
|
|
1873
|
+
contextDialog
|
|
1874
|
+
? h(Modal, {
|
|
1875
|
+
title: '背景与术语',
|
|
1876
|
+
subtitle: '标签和说明会随每次翻译一起交给模型;术语表用于统一人名与专有名词',
|
|
1877
|
+
width: 'min(720px, 94vw)',
|
|
1878
|
+
height: '78vh',
|
|
1879
|
+
onClose: () => setContextDialog(false),
|
|
1880
|
+
children: [
|
|
1881
|
+
h('div', { key: 'h1', style: sectionTitle }, '背景标签'),
|
|
1882
|
+
h(
|
|
1883
|
+
'div',
|
|
1884
|
+
{ key: 'tags', style: { display: 'flex', gap: 6, flexWrap: 'wrap', marginTop: 6 } },
|
|
1885
|
+
hints.tags.length > 0
|
|
1886
|
+
? hints.tags.map((tag) =>
|
|
1887
|
+
h(
|
|
1888
|
+
B,
|
|
1889
|
+
{
|
|
1890
|
+
key: tag,
|
|
1891
|
+
style: { ...small, padding: '3px 8px' },
|
|
1892
|
+
title: '点击移除',
|
|
1893
|
+
onClick: () => setHints({ ...hints, tags: hints.tags.filter((item) => item !== tag) }),
|
|
1894
|
+
},
|
|
1895
|
+
'#' + tag + ' ×',
|
|
1896
|
+
),
|
|
1897
|
+
)
|
|
1898
|
+
: h('span', { style: { ...code, opacity: 0.7 } }, '还没有标签,例如「声优节目」「广播」「游戏实况」'),
|
|
1899
|
+
),
|
|
1900
|
+
h(
|
|
1901
|
+
'div',
|
|
1902
|
+
{ key: 'tagbar', style: { display: 'flex', gap: 6, marginTop: 8 } },
|
|
1903
|
+
h('input', {
|
|
1904
|
+
style: input,
|
|
1905
|
+
value: tagDraft,
|
|
1906
|
+
placeholder: '输入标签后回车或点「添加」',
|
|
1907
|
+
onChange: (event) => setTagDraft(event.target.value),
|
|
1908
|
+
onKeyDown: (event) => {
|
|
1909
|
+
if (event.key === 'Enter') addTag()
|
|
1910
|
+
},
|
|
1911
|
+
}),
|
|
1912
|
+
h(B, { style: button, onClick: addTag }, '添加'),
|
|
1913
|
+
),
|
|
1914
|
+
h('div', { key: 'h2', style: { ...sectionTitle, marginTop: 14 } }, '说明'),
|
|
1915
|
+
h('textarea', {
|
|
1916
|
+
key: 'note',
|
|
1917
|
+
style: { ...input, height: 80, marginTop: 6, fontSize: 12 },
|
|
1918
|
+
value: hints.note,
|
|
1919
|
+
placeholder: '例如:这是声优的生放送,称呼要口语化,第三人称用「她」',
|
|
1920
|
+
onChange: (event) => setHints({ ...hints, note: event.target.value }),
|
|
1921
|
+
}),
|
|
1922
|
+
h(
|
|
1923
|
+
'div',
|
|
1924
|
+
{ key: 'savebar', style: { display: 'flex', gap: 6, marginTop: 8 } },
|
|
1925
|
+
h(B, { style: primary, onClick: saveContext }, '保存背景'),
|
|
1926
|
+
),
|
|
1927
|
+
h('div', { key: 'h3', style: { ...sectionTitle, marginTop: 16 } }, '术语表(' + (glossaryInfo ? glossaryInfo.terms.length : 0) + ' 条)'),
|
|
1928
|
+
glossaryInfo && glossaryInfo.terms.length > 0
|
|
1929
|
+
? h(
|
|
1930
|
+
'div',
|
|
1931
|
+
{ key: 'terms', style: { maxHeight: 160, overflow: 'auto', marginTop: 6 } },
|
|
1932
|
+
glossaryInfo.terms.map((term) =>
|
|
1933
|
+
h('div', { key: term.jp, style: { ...code, padding: '2px 0' } }, term.jp + ' → ' + term.zh),
|
|
1934
|
+
),
|
|
1935
|
+
)
|
|
1936
|
+
: h('div', { key: 'noterms', style: { ...code, opacity: 0.7 } }, '还没有术语;可以粘贴 CSV 导入'),
|
|
1937
|
+
h('textarea', {
|
|
1938
|
+
key: 'csv',
|
|
1939
|
+
style: { ...input, height: 90, marginTop: 8, fontSize: 11, fontFamily: 'ui-monospace, monospace' },
|
|
1940
|
+
value: glossaryText,
|
|
1941
|
+
placeholder: '粘贴 CSV:type,jp,zh,note(每行一条)',
|
|
1942
|
+
onChange: (event) => setGlossaryText(event.target.value),
|
|
1943
|
+
}),
|
|
1944
|
+
h(
|
|
1945
|
+
'div',
|
|
1946
|
+
{ key: 'glossbar', style: { display: 'flex', gap: 6, marginTop: 8, flexWrap: 'wrap' } },
|
|
1947
|
+
h(B, { style: button, onClick: importGlossary }, '导入粘贴的术语'),
|
|
1948
|
+
h(B, { style: button, onClick: exportGlossary }, '导出 CSV'),
|
|
1949
|
+
),
|
|
1950
|
+
],
|
|
1951
|
+
actions: [h(B, { key: 'close', style: quietButton, onClick: () => setContextDialog(false) }, '关闭')],
|
|
1952
|
+
})
|
|
1953
|
+
: null,
|
|
1954
|
+
|
|
1955
|
+
projectsDialog
|
|
1956
|
+
? h(Modal, {
|
|
1957
|
+
title: '项目目录',
|
|
1958
|
+
subtitle: '新项目会保存在这里,也可以把现有项目一起搬过去',
|
|
1959
|
+
width: 'min(640px, 92vw)',
|
|
1960
|
+
onClose: () => setProjectsDialog(false),
|
|
1961
|
+
children: [
|
|
1962
|
+
h('input', {
|
|
1963
|
+
key: 'dir',
|
|
1964
|
+
style: input,
|
|
1965
|
+
value: projectsDraft,
|
|
1966
|
+
placeholder: '例如 C:\\Users\\你\\Documents\\DshSubtitle\\projects',
|
|
1967
|
+
onChange: (event) => setProjectsDraft(event.target.value),
|
|
1968
|
+
}),
|
|
1969
|
+
h(
|
|
1970
|
+
'div',
|
|
1971
|
+
{ key: 'bar', style: { display: 'flex', gap: 6, marginTop: 8, flexWrap: 'wrap' } },
|
|
1972
|
+
h(B, { style: button, onClick: () => browseFor('dir', projectsDraft, 'projects') }, '浏览…'),
|
|
1973
|
+
h(B, { style: small, onClick: () => setProjectsDraft(projectsInfo ? projectsInfo.defaultDir : '') }, '恢复默认(文档)'),
|
|
1974
|
+
),
|
|
1975
|
+
h(
|
|
1976
|
+
'label',
|
|
1977
|
+
{ key: 'move', style: { display: 'flex', gap: 6, alignItems: 'center', marginTop: 10, fontSize: 12, color: tokens.muted } },
|
|
1978
|
+
h('input', { type: 'checkbox', checked: projectsMove, onChange: (event) => setProjectsMove(event.target.checked) }),
|
|
1979
|
+
'把现有项目一起移动到新目录',
|
|
1980
|
+
),
|
|
1981
|
+
projectsInfo && projectsInfo.legacyDir !== projectsInfo.projectsDir
|
|
1982
|
+
? h('div', { key: 'hint', style: { ...code, marginTop: 8, fontSize: 11 } }, '旧目录仍在:' + projectsInfo.legacyDir)
|
|
1983
|
+
: null,
|
|
1984
|
+
],
|
|
1985
|
+
actions: [
|
|
1986
|
+
h(B, { key: 'save', style: primary, onClick: saveProjectsDir }, '保存'),
|
|
1987
|
+
h(B, { key: 'cancel', style: quietButton, onClick: () => setProjectsDialog(false) }, '取消'),
|
|
1988
|
+
],
|
|
1989
|
+
})
|
|
1990
|
+
: null,
|
|
1991
|
+
|
|
1255
1992
|
deleteDialog
|
|
1256
1993
|
? h(Modal, {
|
|
1257
1994
|
title: '删除项目',
|
|
@@ -1260,7 +1997,7 @@ window.__ModuleLoader__.load({
|
|
|
1260
1997
|
children: h(
|
|
1261
1998
|
'div',
|
|
1262
1999
|
{ style: { fontSize: 12, color: tokens.muted, lineHeight: 1.6 } },
|
|
1263
|
-
'
|
|
2000
|
+
'「仅从列表移除」会保留磁盘上的音频、转写结果和字幕文件;「连本地文件一起删除」会删掉整个项目目录,无法撤销。',
|
|
1264
2001
|
),
|
|
1265
2002
|
actions: [
|
|
1266
2003
|
h(B, { key: 'ref', style: button, onClick: () => removeProject(deleteDialog.dir, 'reference') }, '仅从列表移除(保留文件)'),
|