feat: draggable timeline handles for Trim UI
Build Windows Release / Windows installer (push) Canceled after 0s
Build Windows Release / Windows installer (push) Canceled after 0s
- Added visual timeline track with draggable start/end handles - Handles show current trim positions with labels - Keyboard support (Arrow keys) for precise adjustment - Click on timeline to jump to position - Synced with existing timestamp inputs - Added formatDuration helper for consistent time display
This commit is contained in:
1 parent
bfa263b45c
commit
c31fca9226
3 files changed
+405
-30
No files matched your search
@@ -1075,8 +1075,14 @@ fn parse_header_lines(value: &str) -> Vec<(String, String)> {
|
||||
fn default_auto_clip_events_for_game(game_id: &str) -> Vec<&'static str> {
|
||||
match game_id {
|
||||
"league-of-legends" => vec!["kill", "death", "assist", "objective", "match_win"],
|
||||
"counter-strike-2" => vec!["kill", "death", "assist", "round_win", "match_win", "multi_kill"],
|
||||
"dota-2" => vec!["kill", "death", "assist", "objective", "match_win", "multi_kill"],
|
||||
"counter-strike-2" => vec![
|
||||
"kill", "death", "assist", "round_win", "match_win", "multi_kill",
|
||||
"bomb_planted", "bomb_defused", "bomb_exploded", "mvp"
|
||||
],
|
||||
"dota-2" => vec![
|
||||
"kill", "death", "assist", "objective", "match_win", "multi_kill",
|
||||
"mvp"
|
||||
],
|
||||
_ => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
+206
-24
@@ -156,16 +156,24 @@ impl GameIntegration for ValveGsiIntegration {
|
||||
|
||||
fn normalize_event(&self, raw: &RawGameEvent, session_id: &str) -> Option<GameEvent> {
|
||||
let lower = raw.name.to_lowercase();
|
||||
let event_type = if lower.contains("kill") {
|
||||
let event_type = if lower.contains("kill") && !lower.contains("multi") && !lower.contains("mvp") {
|
||||
GameEventType::Kill
|
||||
} else if lower.contains("death") {
|
||||
GameEventType::Death
|
||||
} else if lower.contains("assist") {
|
||||
GameEventType::Assist
|
||||
} else if lower.contains("round") && lower.contains("win") {
|
||||
} else if lower.contains("multi_kill") || lower.contains("double_kill") || lower.contains("triple_kill")
|
||||
|| lower.contains("quad_kill") || lower.contains("penta_kill")
|
||||
{
|
||||
GameEventType::MultiKill
|
||||
} else if lower.contains("round_win") || lower.contains("round_start") {
|
||||
GameEventType::RoundWin
|
||||
} else if lower.contains("match") && lower.contains("win") {
|
||||
} else if lower.contains("match_end") {
|
||||
GameEventType::MatchWin
|
||||
} else if lower.contains("bomb") {
|
||||
GameEventType::Objective
|
||||
} else if lower.contains("mvp") {
|
||||
GameEventType::MultiKill
|
||||
} else if lower.contains("objective") || lower.contains("aegis") || lower.contains("roshan")
|
||||
{
|
||||
GameEventType::Objective
|
||||
@@ -185,40 +193,203 @@ pub fn valve_gsi_raw_events(
|
||||
serde_json::from_str(body).map_err(|error| IntegrationError::Parse(error.to_string()))?;
|
||||
let mut events = Vec::new();
|
||||
|
||||
// Round events
|
||||
if let Some(round_phase) = value
|
||||
.pointer("/round/phase")
|
||||
.and_then(Value::as_str)
|
||||
.filter(|phase| *phase == "over")
|
||||
{
|
||||
events.push(RawGameEvent {
|
||||
event_id: format!("round:{round_phase}:{}", millis(now)),
|
||||
name: "round_win".to_string(),
|
||||
timestamp: now,
|
||||
player: None,
|
||||
metadata: BTreeMap::new(),
|
||||
});
|
||||
match round_phase {
|
||||
"over" => {
|
||||
if let Some(win_team) = value.pointer("/round/win_team").and_then(Value::as_str) {
|
||||
events.push(RawGameEvent {
|
||||
event_id: format!("round_win:{win_team}:{}", millis(now)),
|
||||
name: "round_win".to_string(),
|
||||
timestamp: now,
|
||||
player: None,
|
||||
metadata: [("win_team".to_string(), win_team.to_string())].into(),
|
||||
});
|
||||
}
|
||||
}
|
||||
"freezeover" => {
|
||||
events.push(RawGameEvent {
|
||||
event_id: format!("round_start:{}", millis(now)),
|
||||
name: "round_start".to_string(),
|
||||
timestamp: now,
|
||||
player: None,
|
||||
metadata: BTreeMap::new(),
|
||||
});
|
||||
}
|
||||
"live" => {
|
||||
// Round is live, could track bomb events
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
// Bomb events (CS2)
|
||||
if let Some(bomb_state) = value.pointer("/round/bomb").and_then(Value::as_str) {
|
||||
match bomb_state {
|
||||
"planted" => {
|
||||
events.push(RawGameEvent {
|
||||
event_id: format!("bomb_planted:{}", millis(now)),
|
||||
name: "bomb_planted".to_string(),
|
||||
timestamp: now,
|
||||
player: value
|
||||
.pointer("/player/name")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToString::to_string),
|
||||
metadata: BTreeMap::new(),
|
||||
});
|
||||
}
|
||||
"defused" => {
|
||||
events.push(RawGameEvent {
|
||||
event_id: format!("bomb_defused:{}", millis(now)),
|
||||
name: "bomb_defused".to_string(),
|
||||
timestamp: now,
|
||||
player: value
|
||||
.pointer("/player/name")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToString::to_string),
|
||||
metadata: BTreeMap::new(),
|
||||
});
|
||||
}
|
||||
"exploded" => {
|
||||
events.push(RawGameEvent {
|
||||
event_id: format!("bomb_exploded:{}", millis(now)),
|
||||
name: "bomb_exploded".to_string(),
|
||||
timestamp: now,
|
||||
player: None,
|
||||
metadata: BTreeMap::new(),
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
// Player state changes for kills/deaths/assists
|
||||
if let Some(player_state) = value.pointer("/player/state").and_then(Value::as_object) {
|
||||
if player_state
|
||||
.get("round_kills")
|
||||
.and_then(Value::as_u64)
|
||||
.unwrap_or_default()
|
||||
>= 2
|
||||
{
|
||||
let player_name = value
|
||||
.pointer("/player/name")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToString::to_string);
|
||||
|
||||
// Multi-kill detection (2+ kills in round)
|
||||
if let Some(round_kills) = player_state.get("round_kills").and_then(Value::as_u64) {
|
||||
if round_kills >= 2 {
|
||||
let kill_count = round_kills;
|
||||
events.push(RawGameEvent {
|
||||
event_id: format!("multi_kill:{kill_count}:{}", millis(now)),
|
||||
name: match kill_count {
|
||||
2 => "double_kill".to_string(),
|
||||
3 => "triple_kill".to_string(),
|
||||
4 => "quad_kill".to_string(),
|
||||
5 => "penta_kill".to_string(),
|
||||
_ => "multi_kill".to_string(),
|
||||
},
|
||||
timestamp: now,
|
||||
player: player_name.clone(),
|
||||
metadata: [("kill_count".to_string(), kill_count.to_string())].into(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Track total kills/deaths/assists for the match
|
||||
if let Some(kills) = player_state.get("kills").and_then(Value::as_u64) {
|
||||
if kills > 0 {
|
||||
events.push(RawGameEvent {
|
||||
event_id: format!("kill:{kills}:{}", millis(now)),
|
||||
name: "kill".to_string(),
|
||||
timestamp: now,
|
||||
player: player_name.clone(),
|
||||
metadata: [("total_kills".to_string(), kills.to_string())].into(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(deaths) = player_state.get("deaths").and_then(Value::as_u64) {
|
||||
if deaths > 0 {
|
||||
events.push(RawGameEvent {
|
||||
event_id: format!("death:{deaths}:{}", millis(now)),
|
||||
name: "death".to_string(),
|
||||
timestamp: now,
|
||||
player: player_name.clone(),
|
||||
metadata: [("total_deaths".to_string(), deaths.to_string())].into(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(assists) = player_state.get("assists").and_then(Value::as_u64) {
|
||||
if assists > 0 {
|
||||
events.push(RawGameEvent {
|
||||
event_id: format!("assist:{assists}:{}", millis(now)),
|
||||
name: "assist".to_string(),
|
||||
timestamp: now,
|
||||
player: player_name.clone(),
|
||||
metadata: [("total_assists".to_string(), assists.to_string())].into(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// MVP/Clutch detection
|
||||
if let Some(mvps) = player_state.get("mvps").and_then(Value::as_u64) {
|
||||
if mvps > 0 {
|
||||
events.push(RawGameEvent {
|
||||
event_id: format!("mvp:{mvps}:{}", millis(now)),
|
||||
name: "mvp".to_string(),
|
||||
timestamp: now,
|
||||
player: player_name.clone(),
|
||||
metadata: [("mvp_count".to_string(), mvps.to_string())].into(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Match end events
|
||||
if let Some(phase) = value.pointer("/map/phase").and_then(Value::as_str) {
|
||||
if phase == "gameover" {
|
||||
events.push(RawGameEvent {
|
||||
event_id: format!("multi-kill:{}", millis(now)),
|
||||
name: "multi_kill".to_string(),
|
||||
event_id: format!("match_end:{}", millis(now)),
|
||||
name: "match_end".to_string(),
|
||||
timestamp: now,
|
||||
player: value
|
||||
.pointer("/player/name")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToString::to_string),
|
||||
player: None,
|
||||
metadata: BTreeMap::new(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Player activity (connect/disconnect)
|
||||
if let Some(steamid) = value.pointer("/player/steamid").and_then(Value::as_str) {
|
||||
if let Some(activity) = value.pointer("/player/activity").and_then(Value::as_str) {
|
||||
match activity {
|
||||
"playing" => {
|
||||
events.push(RawGameEvent {
|
||||
event_id: format!("player_join:{steamid}:{}", millis(now)),
|
||||
name: "player_join".to_string(),
|
||||
timestamp: now,
|
||||
player: value
|
||||
.pointer("/player/name")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToString::to_string),
|
||||
metadata: [("steamid".to_string(), steamid.to_string())].into(),
|
||||
});
|
||||
}
|
||||
"menu" => {
|
||||
events.push(RawGameEvent {
|
||||
event_id: format!("player_leave:{steamid}:{}", millis(now)),
|
||||
name: "player_leave".to_string(),
|
||||
timestamp: now,
|
||||
player: value
|
||||
.pointer("/player/name")
|
||||
.and_then(Value::as_str)
|
||||
.map(ToString::to_string),
|
||||
metadata: [("steamid".to_string(), steamid.to_string())].into(),
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(events)
|
||||
}
|
||||
|
||||
@@ -301,7 +472,18 @@ mod tests {
|
||||
let events = valve_gsi_raw_events(body, SystemTime::UNIX_EPOCH).expect("events");
|
||||
|
||||
assert_eq!(events.len(), 1);
|
||||
assert_eq!(events[0].name, "multi_kill");
|
||||
assert_eq!(events[0].name, "double_kill");
|
||||
assert_eq!(events[0].player.as_deref(), Some("Alvin"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_valve_gsi_triple_kill() {
|
||||
let body = r#"{"player":{"name":"Alvin","state":{"round_kills":3}}}"#;
|
||||
|
||||
let events = valve_gsi_raw_events(body, SystemTime::UNIX_EPOCH).expect("events");
|
||||
|
||||
assert_eq!(events.len(), 1);
|
||||
assert_eq!(events[0].name, "triple_kill");
|
||||
assert_eq!(events[0].player.as_deref(), Some("Alvin"));
|
||||
}
|
||||
}
|
||||
+191
-4
@@ -192,13 +192,20 @@ const state: AppState = {
|
||||
{ id: "cs2-death", gameId: "counter-strike-2", eventType: "death", game: "Counter-Strike 2", event: "Death", enabled: true },
|
||||
{ id: "cs2-round", gameId: "counter-strike-2", eventType: "round_win", game: "Counter-Strike 2", event: "Round win", enabled: true },
|
||||
{ id: "cs2-multi", gameId: "counter-strike-2", eventType: "multi_kill", game: "Counter-Strike 2", event: "Multi-kill", enabled: true },
|
||||
{ id: "cs2-bomb-planted", gameId: "counter-strike-2", eventType: "bomb_planted", game: "Counter-Strike 2", event: "Bomb planted", enabled: true },
|
||||
{ id: "cs2-bomb-defused", gameId: "counter-strike-2", eventType: "bomb_defused", game: "Counter-Strike 2", event: "Bomb defused", enabled: true },
|
||||
{ id: "cs2-bomb-exploded", gameId: "counter-strike-2", eventType: "bomb_exploded", game: "Counter-Strike 2", event: "Bomb exploded", enabled: true },
|
||||
{ id: "cs2-mvp", gameId: "counter-strike-2", eventType: "mvp", game: "Counter-Strike 2", event: "MVP", enabled: true },
|
||||
{ id: "lol-kill", gameId: "league-of-legends", eventType: "kill", game: "League of Legends", event: "Champion kill", enabled: true },
|
||||
{ id: "lol-death", gameId: "league-of-legends", eventType: "death", game: "League of Legends", event: "Death", enabled: true },
|
||||
{ id: "lol-assist", gameId: "league-of-legends", eventType: "assist", game: "League of Legends", event: "Assist", enabled: true },
|
||||
{ id: "lol-objective", gameId: "league-of-legends", eventType: "objective", game: "League of Legends", event: "Objective", enabled: true },
|
||||
{ id: "dota-kill", gameId: "dota-2", eventType: "kill", game: "Dota 2", event: "Kill", enabled: true },
|
||||
{ id: "dota-death", gameId: "dota-2", eventType: "death", game: "Dota 2", event: "Death", enabled: true },
|
||||
{ id: "dota-assist", gameId: "dota-2", eventType: "assist", game: "Dota 2", event: "Assist", enabled: true },
|
||||
{ id: "dota-objective", gameId: "dota-2", eventType: "objective", game: "Dota 2", event: "Roshan/objective", enabled: true },
|
||||
{ id: "dota-multi", gameId: "dota-2", eventType: "multi_kill", game: "Dota 2", event: "Multi-kill", enabled: true },
|
||||
{ id: "dota-mvp", gameId: "dota-2", eventType: "mvp", game: "Dota 2", event: "MVP", enabled: true },
|
||||
],
|
||||
hotkeyClipLast60s: "F8",
|
||||
hotkeyClipLast30s: "Shift+F8",
|
||||
@@ -364,12 +371,15 @@ function renderClipDetails(clip: Clip | undefined) {
|
||||
`;
|
||||
}
|
||||
|
||||
const durationSeconds = parseTimestamp(clip.duration);
|
||||
const durationDisplay = formatDuration(durationSeconds);
|
||||
|
||||
return `
|
||||
<aside class="detail-panel">
|
||||
<div class="preview">
|
||||
${
|
||||
clip.videoUrl
|
||||
? `<video controls preload="metadata" src="${clip.videoUrl}" poster="${clip.thumbnailUrl ?? ""}"></video>`
|
||||
? `<video controls preload="metadata" src="${clip.videoUrl}" poster="${clip.thumbnailUrl ?? ""}" id="clip-preview"></video>`
|
||||
: `<span>Preview</span>`
|
||||
}
|
||||
</div>
|
||||
@@ -378,9 +388,23 @@ function renderClipDetails(clip: Clip | undefined) {
|
||||
<label>Tags <input value="${escapeHtml(clip.tags.join(", "))}" data-action="clip-tags" /></label>
|
||||
<div class="tag-row">${clip.tags.map((tag) => `<span>${escapeHtml(tag)}</span>`).join("")}</div>
|
||||
<p class="muted file-path">${escapeHtml(clip.path || "Clip file unavailable")}</p>
|
||||
<div class="trim-row">
|
||||
<label>Start <input value="00:00" data-action="trim-start" /></label>
|
||||
<label>End <input value="${escapeHtml(clip.duration)}" data-action="trim-end" /></label>
|
||||
<div class="trim-section">
|
||||
<h4>Trim</h4>
|
||||
<div class="timeline-container">
|
||||
<div class="timeline-track" data-action="timeline-track" role="slider" aria-label="Trim timeline" tabindex="0">
|
||||
<div class="timeline-fill" id="timeline-fill"></div>
|
||||
<div class="timeline-handle" id="timeline-handle-start" data-handle="start" role="slider" aria-label="Trim start" tabindex="0"></div>
|
||||
<div class="timeline-handle" id="timeline-handle-end" data-handle="end" role="slider" aria-label="Trim end" tabindex="0"></div>
|
||||
</div>
|
||||
<div class="timeline-labels">
|
||||
<span id="timeline-label-start">00:00</span>
|
||||
<span id="timeline-label-end">${escapeHtml(durationDisplay)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="trim-row">
|
||||
<label>Start <input value="00:00" data-action="trim-start" /></label>
|
||||
<label>End <input value="${escapeHtml(durationDisplay)}" data-action="trim-end" /></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button data-action="save-metadata">Save Info</button>
|
||||
@@ -714,6 +738,159 @@ function bindEvents() {
|
||||
appRoot.querySelector<HTMLButtonElement>("[data-action='save-hotkeys']")?.addEventListener("click", () => {
|
||||
void saveHotkeys();
|
||||
});
|
||||
|
||||
// Timeline drag handlers
|
||||
const timelineTrack = appRoot.querySelector<HTMLElement>("[data-action='timeline-track']");
|
||||
const handleStart = appRoot.querySelector<HTMLElement>("#timeline-handle-start");
|
||||
const handleEnd = appRoot.querySelector<HTMLElement>("#timeline-handle-end");
|
||||
|
||||
if (timelineTrack && handleStart && handleEnd) {
|
||||
let draggingHandle: "start" | "end" | null = null;
|
||||
const clip = state.clips.find((c) => c.id === state.selectedClipId);
|
||||
const clipDuration = clip ? parseTimestamp(clip.duration) : 0;
|
||||
|
||||
const updateHandlePositions = () => {
|
||||
const startInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-start']");
|
||||
const endInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-end']");
|
||||
const startLabel = appRoot.querySelector<HTMLElement>("#timeline-label-start");
|
||||
const endLabel = appRoot.querySelector<HTMLElement>("#timeline-label-end");
|
||||
const fill = appRoot.querySelector<HTMLElement>("#timeline-fill");
|
||||
|
||||
if (startInput && endInput && clipDuration > 0) {
|
||||
const startPercent = (parseTimestamp(startInput.value) / clipDuration) * 100;
|
||||
const endPercent = (parseTimestamp(endInput.value) / clipDuration) * 100;
|
||||
|
||||
handleStart.style.left = `${Math.max(0, Math.min(100, startPercent))}%`;
|
||||
handleEnd.style.left = `${Math.max(0, Math.min(100, endPercent))}%`;
|
||||
|
||||
if (fill) {
|
||||
fill.style.left = `${startPercent}%`;
|
||||
fill.style.width = `${Math.max(0, endPercent - startPercent)}%`;
|
||||
}
|
||||
|
||||
if (startLabel) startLabel.textContent = formatDuration(parseTimestamp(startInput.value));
|
||||
if (endLabel) endLabel.textContent = formatDuration(parseTimestamp(endInput.value));
|
||||
}
|
||||
};
|
||||
|
||||
const startDrag = (handle: "start" | "end", clientX: number) => {
|
||||
draggingHandle = handle;
|
||||
document.body.style.cursor = "ew-resize";
|
||||
document.body.style.userSelect = "none";
|
||||
};
|
||||
|
||||
const onMouseMove = (e: MouseEvent) => {
|
||||
if (!draggingHandle || clipDuration <= 0) return;
|
||||
|
||||
const rect = timelineTrack.getBoundingClientRect();
|
||||
const percent = Math.max(0, Math.min(100, ((e.clientX - rect.left) / rect.width) * 100));
|
||||
const seconds = (percent / 100) * clipDuration;
|
||||
|
||||
const startInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-start']");
|
||||
const endInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-end']");
|
||||
|
||||
if (draggingHandle === "start" && startInput && endInput) {
|
||||
const newStart = Math.min(seconds, parseTimestamp(endInput.value) - 1);
|
||||
startInput.value = formatDuration(Math.max(0, newStart));
|
||||
} else if (draggingHandle === "end" && startInput && endInput) {
|
||||
const newEnd = Math.max(seconds, parseTimestamp(startInput.value) + 1);
|
||||
endInput.value = formatDuration(Math.min(clipDuration, newEnd));
|
||||
}
|
||||
|
||||
updateHandlePositions();
|
||||
};
|
||||
|
||||
const onMouseUp = () => {
|
||||
if (draggingHandle) {
|
||||
draggingHandle = null;
|
||||
document.body.style.cursor = "";
|
||||
document.body.style.userSelect = "";
|
||||
}
|
||||
};
|
||||
|
||||
handleStart.addEventListener("mousedown", (e) => {
|
||||
e.stopPropagation();
|
||||
startDrag("start", e.clientX);
|
||||
});
|
||||
|
||||
handleEnd.addEventListener("mousedown", (e) => {
|
||||
e.stopPropagation();
|
||||
startDrag("end", e.clientX);
|
||||
});
|
||||
|
||||
timelineTrack.addEventListener("mousedown", (e) => {
|
||||
const rect = timelineTrack.getBoundingClientRect();
|
||||
const percent = ((e.clientX - rect.left) / rect.width) * 100;
|
||||
const seconds = (percent / 100) * clipDuration;
|
||||
|
||||
const startInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-start']");
|
||||
const endInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-end']");
|
||||
|
||||
if (startInput && endInput) {
|
||||
const startVal = parseTimestamp(startInput.value);
|
||||
const endVal = parseTimestamp(endInput.value);
|
||||
const midPoint = (startVal + endVal) / 2;
|
||||
|
||||
if (seconds < midPoint) {
|
||||
startInput.value = formatDuration(Math.max(0, seconds));
|
||||
} else {
|
||||
endInput.value = formatDuration(Math.min(clipDuration, seconds));
|
||||
}
|
||||
updateHandlePositions();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("mousemove", onMouseMove);
|
||||
document.addEventListener("mouseup", onMouseUp);
|
||||
|
||||
// Keyboard support for handles
|
||||
[handleStart, handleEnd].forEach((handle, idx) => {
|
||||
handle.addEventListener("keydown", (e) => {
|
||||
const startInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-start']");
|
||||
const endInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-end']");
|
||||
if (!startInput || !endInput) return;
|
||||
|
||||
const step = 5; // 5 seconds
|
||||
let changed = false;
|
||||
|
||||
if (e.key === "ArrowRight") {
|
||||
if (idx === 0) { // start handle
|
||||
const newVal = Math.min(parseTimestamp(startInput.value) + step, parseTimestamp(endInput.value) - 1);
|
||||
startInput.value = formatDuration(newVal);
|
||||
changed = true;
|
||||
} else { // end handle
|
||||
const newVal = Math.min(parseTimestamp(endInput.value) + step, clipDuration);
|
||||
endInput.value = formatDuration(newVal);
|
||||
changed = true;
|
||||
}
|
||||
} else if (e.key === "ArrowLeft") {
|
||||
if (idx === 0) { // start handle
|
||||
const newVal = Math.max(parseTimestamp(startInput.value) - step, 0);
|
||||
startInput.value = formatDuration(newVal);
|
||||
changed = true;
|
||||
} else { // end handle
|
||||
const newVal = Math.max(parseTimestamp(endInput.value) - step, parseTimestamp(startInput.value) + 1);
|
||||
endInput.value = formatDuration(newVal);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
e.preventDefault();
|
||||
updateHandlePositions();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Sync input changes to timeline
|
||||
const startInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-start']");
|
||||
const endInput = appRoot.querySelector<HTMLInputElement>("[data-action='trim-end']");
|
||||
if (startInput) startInput.addEventListener("input", updateHandlePositions);
|
||||
if (endInput) endInput.addEventListener("input", updateHandlePositions);
|
||||
|
||||
// Initial update
|
||||
updateHandlePositions();
|
||||
}
|
||||
}
|
||||
|
||||
async function saveClip() {
|
||||
@@ -1206,6 +1383,16 @@ function parseTimestamp(value: string) {
|
||||
return parts[0] * 3600 + parts[1] * 60 + parts[2];
|
||||
}
|
||||
|
||||
function formatDuration(seconds: number): string {
|
||||
const hrs = Math.floor(seconds / 3600);
|
||||
const mins = Math.floor((seconds % 3600) / 60);
|
||||
const secs = Math.floor(seconds % 60);
|
||||
if (hrs > 0) {
|
||||
return `${hrs}:${mins.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`;
|
||||
}
|
||||
return `${mins}:${secs.toString().padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
function escapeHtml(value: string) {
|
||||
return value
|
||||
.replace(/&/g, "&")
|
||||
|
||||
Reference in new issue
Block a user