Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: add caption/keyboard track segments, keyboard settings, and backwards-compatible caption migration

Cursor Agent03019a1538a4
diff --git a/crates/project/src/configuration.rs b/crates/project/src/configuration.rs
index f2f49fbea..2a5ab46f5 100644
--- a/crates/project/src/configuration.rs
+++ b/crates/project/src/configuration.rs
@@ -788,6 +788,33 @@ pub struct TimelineConfiguration {
pub mask_segments: Vec<MaskSegment>,
#[serde(default)]
pub text_segments: Vec<TextSegment>,
+ #[serde(default)]
+ pub caption_segments: Vec<CaptionTrackSegment>,
+ #[serde(default)]
+ pub keyboard_segments: Vec<crate::KeyboardTrackSegment>,
+}
+
+#[derive(Type, Serialize, Deserialize, Clone, Debug)]
+#[serde(rename_all = "camelCase")]
+pub struct CaptionTrackSegment {
+ pub id: String,
+ pub start: f64,
+ pub end: f64,
+ pub text: String,
+ #[serde(default)]
+ pub words: Vec<CaptionWord>,
+ #[serde(default)]
+ pub fade_duration_override: Option<f32>,
+ #[serde(default)]
+ pub linger_duration_override: Option<f32>,
+ #[serde(default)]
+ pub position_override: Option<String>,
+ #[serde(default)]
+ pub color_override: Option<String>,
+ #[serde(default)]
+ pub background_color_override: Option<String>,
+ #[serde(default)]
+ pub font_size_override: Option<u32>,
}
impl TimelineConfiguration {
@@ -934,6 +961,50 @@ pub struct CaptionsData {
pub settings: CaptionSettings,
}
+#[derive(Type, Serialize, Deserialize, Clone, Debug)]
+#[serde(rename_all = "camelCase", default)]
+pub struct KeyboardSettings {
+ pub enabled: bool,
+ pub font: String,
+ pub size: u32,
+ pub color: String,
+ pub background_color: String,
+ pub background_opacity: u32,
+ pub position: String,
+ pub font_weight: u32,
+ pub fade_duration: f32,
+ pub linger_duration: f32,
+ pub grouping_threshold_ms: f64,
+ pub show_modifiers: bool,
+ pub show_special_keys: bool,
+}
+
+impl Default for KeyboardSettings {
+ fn default() -> Self {
+ Self {
+ enabled: false,
+ font: "System Sans-Serif".to_string(),
+ size: 28,
+ color: "#FFFFFF".to_string(),
+ background_color: "#000000".to_string(),
+ background_opacity: 85,
+ position: "above-captions".to_string(),
+ font_weight: 500,
+ fade_duration: 0.15,
+ linger_duration: 0.8,
+ grouping_threshold_ms: 300.0,
+ show_modifiers: true,
+ show_special_keys: true,
+ }
+ }
+}
+
+#[derive(Type, Serialize, Deserialize, Clone, Debug, Default)]
+#[serde(rename_all = "camelCase")]
+pub struct KeyboardData {
+ pub settings: KeyboardSettings,
+}
+
#[derive(Type, Serialize, Deserialize, Clone, Copy, Debug, Default)]
pub struct ClipOffsets {
#[serde(default)]
@@ -1083,6 +1154,7 @@ pub struct ProjectConfiguration {
pub hotkeys: HotkeysConfiguration,
pub timeline: Option<TimelineConfiguration>,
pub captions: Option<CaptionsData>,
+ pub keyboard: Option<KeyboardData>,
pub clips: Vec<ClipConfiguration>,
pub annotations: Vec<Annotation>,
#[serde(skip_serializing)]
diff --git a/crates/project/src/meta.rs b/crates/project/src/meta.rs
index 4217516ab..f75fccdca 100644
--- a/crates/project/src/meta.rs
+++ b/crates/project/src/meta.rs
@@ -168,6 +168,38 @@ impl RecordingMeta {
debug!("No captions.json found");
}
+ if let Some(ref captions) = config.captions {
+ let timeline_has_captions = config
+ .timeline
+ .as_ref()
+ .map(|t| !t.caption_segments.is_empty())
+ .unwrap_or(false);
+
+ if !timeline_has_captions && !captions.segments.is_empty() {
+ let caption_track_segments: Vec<crate::CaptionTrackSegment> = captions
+ .segments
+ .iter()
+ .map(|seg| crate::CaptionTrackSegment {
+ id: seg.id.clone(),
+ start: seg.start as f64,
+ end: seg.end as f64,
+ text: seg.text.clone(),
+ words: seg.words.clone(),
+ fade_duration_override: None,
+ linger_duration_override: None,
+ position_override: None,
+ color_override: None,
+ background_color_override: None,
+ font_size_override: None,
+ })
+ .collect();
+
+ if let Some(ref mut timeline) = config.timeline {
+ timeline.caption_segments = caption_track_segments;
+ }
+ }
+ }
+
config
}