()
| 166 | }; |
| 167 | |
| 168 | const addCaptionAtPlayhead = () => { |
| 169 | const total = totalDuration(); |
| 170 | const defaultDuration = 2; |
| 171 | const outputStart = |
| 172 | total > 0 |
| 173 | ? Math.min( |
| 174 | Math.max(editorState.playbackTime, 0), |
| 175 | Math.max(total - 0.25, 0), |
| 176 | ) |
| 177 | : Math.max(editorState.playbackTime, 0); |
| 178 | const start = |
| 179 | mapEditedTimeToSource( |
| 180 | outputStart, |
| 181 | project.timeline?.segments ?? [], |
| 182 | recordingSegments(), |
| 183 | ) ?? outputStart; |
| 184 | const end = start + defaultDuration; |
| 185 | const text = "New caption"; |
| 186 | |
| 187 | setProject( |
| 188 | produce((p) => { |
| 189 | p.captions ??= { |
| 190 | segments: [], |
| 191 | settings: { ...defaultCaptionSettings, enabled: true }, |
| 192 | sourceTimed: true, |
| 193 | }; |
| 194 | p.captions.settings = { |
| 195 | ...defaultCaptionSettings, |
| 196 | ...p.captions.settings, |
| 197 | enabled: true, |
| 198 | }; |
| 199 | p.captions.sourceTimed = true; |
| 200 | p.timeline ??= { |
| 201 | segments: [{ start: 0, end: total || end, timescale: 1 }], |
| 202 | zoomSegments: [], |
| 203 | sceneSegments: [], |
| 204 | maskSegments: [], |
| 205 | textSegments: [], |
| 206 | captionSegments: [], |
| 207 | keyboardSegments: [], |
| 208 | }; |
| 209 | |
| 210 | p.captions.segments.push({ |
| 211 | id: `caption-${Date.now()}-${Math.random().toString(36).slice(2)}`, |
| 212 | start, |
| 213 | end, |
| 214 | text, |
| 215 | words: syncCaptionWordsWithText(text, undefined, start, end), |
| 216 | }); |
| 217 | p.captions.segments.sort((a, b) => a.start - b.start); |
| 218 | }), |
| 219 | ); |
| 220 | setEditorState("timeline", "tracks", "caption", true); |
| 221 | setEditorState("captions", "isStale", false); |
| 222 | }; |
| 223 | |
| 224 | const handleExportCaptions = async (format: CaptionExportFormat) => { |
| 225 | const cues = exportableCues(); |
nothing calls this directly
no test coverage detected