@lincyaw/workbench 0.2.0-rc.29 → 0.2.0-rc.30
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/package.json +4 -4
- package/src/MediaClipEditor.tsx +1 -1
- package/src/components.tsx +10 -5
- package/src/panels/ProductionCaptionSize.tsx +20 -0
- package/src/panels/ProductionPanel.tsx +5 -1
- package/src/panels/ProductionTimeline.tsx +6 -1
- package/src/production-messages.ts +6 -0
- package/src/workbench.ts +9 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/workbench",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.30",
|
|
4
4
|
"description": "Presmium's workbench panels in React (the documents, a document edited on its rendered page with comments and version history) with the workspace service's client and the preview protocol's workbench side; @lincyaw/dsh places them in presmium studio (experimental)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"@tiptap/pm": "3.32.0",
|
|
56
56
|
"katex": "0.18.10",
|
|
57
57
|
"react-resizable-panels": "4.14.5",
|
|
58
|
-
"@lincyaw/design": "1.0.0-rc.
|
|
59
|
-
"@lincyaw/kernel": "1.0.0-rc.
|
|
58
|
+
"@lincyaw/design": "1.0.0-rc.30",
|
|
59
|
+
"@lincyaw/kernel": "1.0.0-rc.30"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"react": "^18.3.1",
|
|
@@ -67,6 +67,6 @@
|
|
|
67
67
|
"@types/react-dom": "18.3.7",
|
|
68
68
|
"react": "^18.3.1",
|
|
69
69
|
"react-dom": "^18.3.1",
|
|
70
|
-
"@lincyaw/compiler": "1.0.0-rc.
|
|
70
|
+
"@lincyaw/compiler": "1.0.0-rc.30"
|
|
71
71
|
}
|
|
72
72
|
}
|
package/src/MediaClipEditor.tsx
CHANGED
|
@@ -101,7 +101,7 @@ export function MediaClipEditor(props: MediaClipEditorProps) {
|
|
|
101
101
|
{rangeError && <span id={rangeErrorId} className="pm-ui-field__error" role="alert">{rangeError}</span>}
|
|
102
102
|
<PmInput label={t.offset} density={density} width="number" inputMode="decimal" maxLength={32} value={draft.offsetText ?? (clip.attachment.offsetMs / 1000).toFixed(3)}
|
|
103
103
|
readOnly={disabled || !inspected} error={offsetMs === undefined ? t.invalidOffset : undefined} onChange={event => change({ offsetText: event.target.value })} {...composition('offset')} />
|
|
104
|
-
<PmField label={t.volume} density={density} group><div className="pm-ui-
|
|
104
|
+
<PmField label={t.volume} density={density} group><div className="pm-ui-range-row">
|
|
105
105
|
<PmRange label={t.volume} density={density} value={clip.volume * 100} max={100} disabled={disabled || !inspected} valueText={value => `${Math.round(value)}%`} onPreviewChange={setVolumePreview}
|
|
106
106
|
onValueCommit={value => change({ clip: { ...clip, volume: value / 100 } })} />
|
|
107
107
|
<output>{Math.round(volumePreview ?? clip.volume * 100)}%</output><PmButton density={density} aria-pressed={Boolean(clip.muted)} disabled={disabled || !inspected} onClick={() => change({ clip: { ...clip, muted: !clip.muted } })}>{clip.muted ? t.unmute : t.mute}</PmButton>
|
package/src/components.tsx
CHANGED
|
@@ -503,6 +503,10 @@ export interface TimelineProps {
|
|
|
503
503
|
showSteps?: boolean
|
|
504
504
|
/** A flush docked editor, with status and zoom in the same tool row. */
|
|
505
505
|
variant?: 'default' | 'editor'
|
|
506
|
+
/** The page has no place on this timeline (the lecture leaves it out): its status and notice say so, with no tracks to seek. */
|
|
507
|
+
excluded?: { status: string, notice: string }
|
|
508
|
+
/** A note about the selected step, under the tracks. */
|
|
509
|
+
notice?: string
|
|
506
510
|
}
|
|
507
511
|
|
|
508
512
|
const timelineTime = (ms: number) => `${String(Math.floor(ms / 60000)).padStart(2, '0')}:${(ms % 60000 / 1000).toFixed(3).padStart(6, '0')}`
|
|
@@ -517,11 +521,11 @@ function waveformPath(samples: readonly number[] | undefined): string | undefine
|
|
|
517
521
|
}
|
|
518
522
|
|
|
519
523
|
/** Data-only timeline; source, playback, seeking authority and all labels remain with its caller. */
|
|
520
|
-
export function PmTimeline({ label, tracks, labels, durationMs, durationStatus, currentTimeMs, selectedStepId, zoom, onZoomChange, onSelectStep, onSelectSegment, segmentPicker, onSeek, seekDisabled, disabled, loading, seeking, density = 'compact', showSteps = true, variant = 'default' }: TimelineProps) {
|
|
524
|
+
export function PmTimeline({ label, tracks, labels, durationMs, durationStatus, currentTimeMs, selectedStepId, zoom, onZoomChange, onSelectStep, onSelectSegment, segmentPicker, onSeek, seekDisabled, disabled, loading, seeking, density = 'compact', showSteps = true, variant = 'default', excluded, notice }: TimelineProps) {
|
|
521
525
|
const hintId = useId()
|
|
522
526
|
const viewport = useRef<HTMLDivElement>(null), tick = useRef<HTMLSpanElement>(null), composing = useRef(false)
|
|
523
527
|
const [width, setWidth] = useState(0), [tickWidth, setTickWidth] = useState(1), [localZoom, setLocalZoom] = useState(1), [raw, setRaw] = useState<string>(), [previewTime, setPreviewTime] = useState<number>()
|
|
524
|
-
const span = Number.isFinite(durationMs) && durationMs! >= 0 ? durationMs : undefined
|
|
528
|
+
const span = !excluded && Number.isFinite(durationMs) && durationMs! >= 0 ? durationMs : undefined
|
|
525
529
|
const timing = durationStatus ?? (span === undefined ? 'unknown' : 'confirmed')
|
|
526
530
|
const timed = span !== undefined && span > 0 && timing !== 'unknown'
|
|
527
531
|
const blocked = Boolean(disabled || loading), cannotSeek = Boolean(blocked || seeking || seekDisabled || !timed || timing !== 'confirmed')
|
|
@@ -562,10 +566,10 @@ export function PmTimeline({ label, tracks, labels, durationMs, durationStatus,
|
|
|
562
566
|
const marks = Array.from({ length: Math.min(200, Math.floor(span / unit) + 1) }, (_, index) => index * unit)
|
|
563
567
|
return [0, ...marks.filter(time => time > 0 && time < span && Math.min(time, span - time) / span * width * scale >= tickWidth), span]
|
|
564
568
|
}, [span, timed, width, scale, tickWidth])
|
|
565
|
-
const status = <div className="pm-ui-timeline__status" role="status">{loading ? labels.loading : timing === 'unknown' || span === undefined ? labels.unknown : `${timing === 'estimated' ? `${labels.estimated} · ` : ''}${timelineTime(span)}`}</div>
|
|
569
|
+
const status = <div className="pm-ui-timeline__status" role="status">{loading ? labels.loading : excluded ? excluded.status : timing === 'unknown' || span === undefined ? labels.unknown : `${timing === 'estimated' ? `${labels.estimated} · ` : ''}${timelineTime(span)}`}</div>
|
|
566
570
|
return <section className="pm-ui-timeline" data-variant={variant} data-density={density} data-disabled={blocked || undefined} data-segment-picker={segmentPicker?.track} aria-label={label} aria-busy={loading || seeking || undefined}>
|
|
567
571
|
<div className="pm-ui-timeline__tools">
|
|
568
|
-
<PmInput label={`${labels.position} (${labels.seconds})`} labelHidden={variant === 'editor'} width="time" density={density} inputMode="decimal" maxLength={32} value={raw ?? (position === undefined ? '' : (position / 1000).toFixed(3))} placeholder={labels.unknown} error={invalid ? labels.invalidPosition : undefined} disabled={cannotSeek}
|
|
572
|
+
<PmInput label={`${labels.position} (${labels.seconds})`} labelHidden={variant === 'editor'} width="time" density={density} inputMode="decimal" maxLength={32} value={raw ?? (position === undefined ? '' : (position / 1000).toFixed(3))} placeholder={excluded ? undefined : labels.unknown} error={invalid ? labels.invalidPosition : undefined} disabled={cannotSeek}
|
|
569
573
|
onChange={event => setRaw(event.target.value)} onBlur={commitPosition}
|
|
570
574
|
onCompositionStart={() => { composing.current = true }} onCompositionEnd={() => { composing.current = false }}
|
|
571
575
|
onKeyDown={event => { if (event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) return; if (event.key === 'Enter') { event.preventDefault(); commitPosition() } else if (event.key === 'Escape') setRaw(undefined) }} />
|
|
@@ -602,7 +606,8 @@ export function PmTimeline({ label, tracks, labels, durationMs, durationStatus,
|
|
|
602
606
|
<option value="">{segmentPicker.placeholder}</option>{pickerSegments.map(segment => <option key={segment.id} value={segment.id} disabled={segment.disabled}>{timelineTime(segment.startMs!)} · {segment.label}</option>)}
|
|
603
607
|
</PmSelect></div>}
|
|
604
608
|
{showSteps && <div className="pm-ui-timeline__steps">{steps.map(segment => <PmButton key={segment.stepId} density={density} disabled={blocked || segment.disabled} aria-pressed={segment.stepId === selectedStepId} variant={segment.stepId === selectedStepId ? 'accent' : 'default'} onClick={() => onSelectStep(segment.stepId!)}>{segment.label}</PmButton>)}</div>}
|
|
605
|
-
{!tracks.some(track => track.segments.length) && <PmNotice>{labels.empty}</PmNotice>}
|
|
609
|
+
{(excluded || !tracks.some(track => track.segments.length)) && <PmNotice>{excluded?.notice ?? labels.empty}</PmNotice>}
|
|
610
|
+
{notice && <PmNotice>{notice}</PmNotice>}
|
|
606
611
|
<p id={hintId} className="pm-ui-sr-only">{labels.seekHint}</p>
|
|
607
612
|
</section>
|
|
608
613
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { captionScale, CAPTION_SCALE_MAX, CAPTION_SCALE_MIN } from '@lincyaw/kernel'
|
|
3
|
+
import type { TeachingDocument } from '@lincyaw/kernel'
|
|
4
|
+
import { PmField, PmRange } from '../components.tsx'
|
|
5
|
+
import { useWorkbench, useWorkbenchState } from '../context.tsx'
|
|
6
|
+
import { PRODUCTION_MESSAGES } from '../production-messages.ts'
|
|
7
|
+
|
|
8
|
+
/** The document's caption size in percent steps of ten; a released drag or a key records it once. */
|
|
9
|
+
export function ProductionCaptionSize({ identity, document, disabled, onChanged }: { identity: string, document: TeachingDocument, disabled: boolean, onChanged(): void }) {
|
|
10
|
+
const workbench = useWorkbench(), locale = useWorkbenchState(state => state.locale), p = PRODUCTION_MESSAGES[locale]
|
|
11
|
+
const [preview, setPreview] = useState<number>()
|
|
12
|
+
const percent = Math.round(captionScale(document.production) * 100)
|
|
13
|
+
return <PmField label={p.captionSize} group hint={p.captionSizeHint}>
|
|
14
|
+
<div className="pm-ui-range-row">
|
|
15
|
+
<PmRange label={p.captionSize} value={percent} min={Math.round(CAPTION_SCALE_MIN * 100)} max={Math.round(CAPTION_SCALE_MAX * 100)} step={10} disabled={disabled} valueText={value => `${Math.round(value)}%`}
|
|
16
|
+
onPreviewChange={setPreview} onValueCommit={value => { workbench.setDocumentCaptionScale(value / 100, identity); onChanged() }} />
|
|
17
|
+
<output>{Math.round(preview ?? percent)}%</output>
|
|
18
|
+
</div>
|
|
19
|
+
</PmField>
|
|
20
|
+
}
|
|
@@ -12,6 +12,7 @@ import { DocumentVoiceField } from './DocumentVoiceField.tsx'
|
|
|
12
12
|
import { ExportPanel } from './ExportPanel.tsx'
|
|
13
13
|
import { PreviewPanel } from './PreviewPanel.tsx'
|
|
14
14
|
import { VoiceoverDialog } from './VoiceoverDialog.tsx'
|
|
15
|
+
import { ProductionCaptionSize } from './ProductionCaptionSize.tsx'
|
|
15
16
|
import { ProductionCaptionTiming } from './ProductionCaptionTiming.tsx'
|
|
16
17
|
import { ProductionTimeline } from './ProductionTimeline.tsx'
|
|
17
18
|
import { ProductionMediaClips } from './ProductionMediaClips.tsx'
|
|
@@ -254,7 +255,10 @@ export function ProductionPanel({ onClose, closing, active = true }: { onClose()
|
|
|
254
255
|
selectedAsset={transcriptionAsset?.identity === source.identity ? transcriptionAsset : undefined}
|
|
255
256
|
onSelectAsset={() => { transcriptionSelection.current++; setTranscriptionAsset(undefined) }} />
|
|
256
257
|
</div></PmTabPanel>
|
|
257
|
-
<PmTabPanel value="captions" keepMounted><
|
|
258
|
+
<PmTabPanel value="captions" keepMounted><div className="pmw-production__fields">
|
|
259
|
+
<ProductionCaptionSize identity={source.identity} document={document} disabled={blocked || closing} onChanged={() => setMediaRefresh(true)} />
|
|
260
|
+
<ProductionCaptionTiming key={source.identity} identity={source.identity} stepId={stepId} plan={plan} current={planCurrent} loading={preparing || planBusy} disabled={blocked || closing} onChanged={() => setMediaRefresh(true)} />
|
|
261
|
+
</div></PmTabPanel>
|
|
258
262
|
</PmTabs>
|
|
259
263
|
</PmSplitPanel>
|
|
260
264
|
</PmSplitGroup>
|
|
@@ -36,6 +36,10 @@ export function ProductionTimeline({ plan, sectionId, stepId, active, current, s
|
|
|
36
36
|
}, [workbench, directory, plan, sectionId, active, current])
|
|
37
37
|
const document = source?.content, section = document?.sections[sectionId]
|
|
38
38
|
const page = current ? plan?.pages.find(page => page.sectionId === sectionId) : undefined
|
|
39
|
+
// The current plan lists every page of the lecture; a page of the document it lacks is left out of the lecture.
|
|
40
|
+
const excluded = Boolean(current && plan && section && !page)
|
|
41
|
+
// On a page of the lecture, a step it leaves out is missing from the page's steps.
|
|
42
|
+
const stepLeftOut = Boolean(page && !page.steps.some(step => step.stepId === stepId))
|
|
39
43
|
const start = page?.startMs, end = page?.endMs, duration = start !== undefined && end !== undefined ? Math.max(0, end - start) : undefined
|
|
40
44
|
const position = plan && current && playback && sameProductionBinding(playback.binding, plan.binding) && playback.position?.sectionId === sectionId && start !== undefined ? Math.max(0, playback.position.timeMs - start) : undefined
|
|
41
45
|
const tracks: TimelineTrack[] = page && plan ? plan.tracks.map(track => ({ id: track.kind, label: p.tracks[track.kind], segments: track.segments.filter(segment => segment.sectionId === sectionId).map(segment => {
|
|
@@ -49,9 +53,10 @@ export function ProductionTimeline({ plan, sectionId, stepId, active, current, s
|
|
|
49
53
|
statusLabel: [status, track.kind === 'caption' && p.alignmentStatus[segment.alignment ?? 'none'], segment.audio && (wave === false ? p.waveformUnavailable : wave === undefined ? p.waveformLoading : undefined)].filter(Boolean).join(' · '),
|
|
50
54
|
waveform: wave ? wave.peaks : undefined,
|
|
51
55
|
}
|
|
52
|
-
}) })) : [{ id: 'visual', label: p.tracks.visual, segments: section?.stepOrder.map((id, index) => ({ id, stepId: id, label: document?.steps[id]?.title ?? p.stepNumber(index), timing: 'unknown' as const })) ?? [] }, { id: 'voice', label: p.tracks.voice, segments: [] }, { id: 'caption', label: p.tracks.caption, segments: [] }]
|
|
56
|
+
}) })) : [{ id: 'visual', label: p.tracks.visual, segments: excluded ? [] : section?.stepOrder.map((id, index) => ({ id, stepId: id, label: document?.steps[id]?.title ?? p.stepNumber(index), timing: 'unknown' as const })) ?? [] }, { id: 'voice', label: p.tracks.voice, segments: [] }, { id: 'caption', label: p.tracks.caption, segments: [] }]
|
|
53
57
|
const captionChoices = current ? plan?.tracks.find(track => track.kind === 'caption')?.segments.filter(segment => segment.stepId === stepId && (segment.alignment === 'words' || segment.alignment === 'manual') && segment.timing === 'confirmed').map(segment => segment.id) ?? [] : []
|
|
54
58
|
return <PmTimeline variant="editor" label={p.timeline} tracks={tracks} labels={p.timelineLabels} durationMs={duration} durationStatus={page?.timing ?? 'unknown'} currentTimeMs={position} selectedStepId={stepId} showSteps={false}
|
|
59
|
+
excluded={excluded ? { status: p.notInLecture, notice: p.notInLectureHint } : undefined} notice={stepLeftOut ? p.notInLectureStep : undefined}
|
|
55
60
|
segmentPicker={{ track: 'caption', ids: captionChoices, label: p.captionSegment, placeholder: p.chooseCaptionSegment }}
|
|
56
61
|
zoom={zoom} onZoomChange={setZoom} disabled={disabled} loading={loading} seeking={seeking} seekDisabled={!seekEnabled || start === undefined}
|
|
57
62
|
onSelectStep={onSelectStep} onSelectSegment={(track, selected) => {
|
|
@@ -57,6 +57,9 @@ const zh = {
|
|
|
57
57
|
alignmentStatus: { manual: '手动时间', words: '词时码', proportional: '比例估时', none: '未对齐' },
|
|
58
58
|
segmentStatus: { recorded: '原音频', cached: '已有配音', silent: '静音', missing: '配音待生成', blocked: '暂不可用' },
|
|
59
59
|
waveformLoading: '正在加载波形…', waveformUnavailable: '波形不可用', stepNumber: (index: number) => `步骤 ${index + 1}`,
|
|
60
|
+
notInLecture: '不在讲授中', notInLectureHint: '这一页的内容都限定在其他形态,又没有讲稿与音频,讲授视频中没有这一页。',
|
|
61
|
+
notInLectureStep: '这一步不在讲授中:它的内容都限定在其他形态,又没有讲稿与音频。',
|
|
62
|
+
captionSize: '字幕大小', captionSizeHint: '整个文稿的字幕:放映中显示的与导出视频中烧录的都按这个大小。',
|
|
60
63
|
timelineLabels: { position: '位置', seconds: '秒', seek: '播放头位置', zoomIn: '放大时间线', zoomOut: '缩小时间线', fit: '适配本页', estimated: '估计时长', unknown: '时长未知', loading: '正在加载时间线…', empty: '当前页暂无时间线片段', seekHint: '选择步骤,或用时间尺、方向键和精确时间定位;定位会先暂停播放。', invalidPosition: '请输入本页时长范围内的秒数。' },
|
|
61
64
|
failures: {
|
|
62
65
|
'production-source-changed': '文稿已更新,旧播放请求已停止。请重新准备当前版本。',
|
|
@@ -129,6 +132,9 @@ export const PRODUCTION_MESSAGES: Record<Locale, typeof zh> = {
|
|
|
129
132
|
alignmentStatus: { manual: 'Manual timing', words: 'Word timing', proportional: 'Proportional timing', none: 'Unaligned' },
|
|
130
133
|
segmentStatus: { recorded: 'Original audio', cached: 'Voiceover cached', silent: 'Silent', missing: 'Voiceover needed', blocked: 'Unavailable' },
|
|
131
134
|
waveformLoading: 'Loading waveform…', waveformUnavailable: 'Waveform unavailable', stepNumber: index => `Step ${index + 1}`,
|
|
135
|
+
notInLecture: 'Not in the lecture', notInLectureHint: 'Everything on this page is limited to other forms and it has no script or audio, so the lecture video leaves it out.',
|
|
136
|
+
notInLectureStep: 'This step is not in the lecture: everything on it is limited to other forms and it has no script or audio.',
|
|
137
|
+
captionSize: 'Caption size', captionSizeHint: 'For the whole document: captions shown in the presentation and burned into an exported video use this size.',
|
|
132
138
|
timelineLabels: { position: 'Position', seconds: 'seconds', seek: 'Playhead position', zoomIn: 'Zoom In Timeline', zoomOut: 'Zoom Out Timeline', fit: 'Fit Page', estimated: 'Estimated duration', unknown: 'Unknown duration', loading: 'Loading the timeline…', empty: 'This page has no timeline segments', seekHint: 'Select a step, or use the ruler, arrow keys, or an exact time to seek. Seeking pauses playback first.', invalidPosition: 'Enter a time in seconds within this page’s duration.' },
|
|
133
139
|
failures: {
|
|
134
140
|
'production-source-changed': 'The document changed and the old playback request stopped. Prepare the current version.',
|
package/src/workbench.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyDocumentCaptionTiming, randomUUID } from '@lincyaw/kernel'
|
|
1
|
+
import { applyDocumentCaptionTiming, changeDocumentCaptionScale, randomUUID } from '@lincyaw/kernel'
|
|
2
2
|
import type { DocumentCaptionTimingAction } from '@lincyaw/kernel'
|
|
3
3
|
import { reconcileCaptionTiming } from './caption-timing.ts'
|
|
4
4
|
import type { ProjectOperation, ProjectPlan } from '@lincyaw/kernel'
|
|
@@ -1587,6 +1587,14 @@ export class Workbench {
|
|
|
1587
1587
|
this.stopAuditions()
|
|
1588
1588
|
this.#documentSession.record(next)
|
|
1589
1589
|
}
|
|
1590
|
+
/** The whole document's caption size (`production.captions.scale`), recorded like a step's timing. */
|
|
1591
|
+
setDocumentCaptionScale(scale: number, identity?: string): void {
|
|
1592
|
+
const document = this.getDocument(identity)
|
|
1593
|
+
if (!document || isAgentChanging(this.#state)) return
|
|
1594
|
+
const next = changeDocumentCaptionScale(document, scale)
|
|
1595
|
+
if (next === document) return
|
|
1596
|
+
this.#documentSession.record(next)
|
|
1597
|
+
}
|
|
1590
1598
|
documentTimingDraft(stepId: string, key: StepDurationKey, identity: string, reset: number): StepDurationDraft | undefined {
|
|
1591
1599
|
const document = this.getDocument(identity)
|
|
1592
1600
|
return document && this.#state.authoring?.reset === reset ? this.#documentTimingDrafts.get(identity, document, stepId, key) : undefined
|