split Main into components, move gif math to backend
This commit is contained in:
@@ -511,6 +511,48 @@ fn resume_capture(app: AppHandle, state: State<'_, AppState>) -> Result<(), Stri
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Restart the audio capture mid-recording. Used when the initial WASAPI
|
||||||
|
/// session failed (e.g. endpoint was busy) and the user wants to retry
|
||||||
|
/// without ending the recording. Stops the current session, appends its
|
||||||
|
/// pcm segment to the session, and starts a new one with a fresh file.
|
||||||
|
#[tauri::command]
|
||||||
|
fn restart_audio_capture(
|
||||||
|
app: AppHandle,
|
||||||
|
state: State<'_, AppState>,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let audio_enabled = {
|
||||||
|
let ss = lock(&state.session);
|
||||||
|
let ss = ss.as_ref().ok_or_else(|| "no session in progress".to_string())?;
|
||||||
|
if !ss.audio {
|
||||||
|
return Err("audio is not enabled for this recording".to_string());
|
||||||
|
}
|
||||||
|
ss.audio
|
||||||
|
};
|
||||||
|
|
||||||
|
// Stop the existing session and stash its file. Don't touch capture
|
||||||
|
// or click recording - they keep running.
|
||||||
|
let next_idx = {
|
||||||
|
let mut ss = lock(&state.session);
|
||||||
|
let ss = ss.as_mut().ok_or_else(|| "no session in progress".to_string())?;
|
||||||
|
if let Some(a) = lock(&state.audio).take() {
|
||||||
|
if let Ok(p) = a.stop() {
|
||||||
|
ss.audio_segments.push(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ss.audio_segments.len() + 1
|
||||||
|
};
|
||||||
|
|
||||||
|
let audio_path = audio_segment_path(&state.app_dir, next_idx);
|
||||||
|
let audio_recovered = try_start_audio(&app, audio_enabled, audio_path);
|
||||||
|
let recovered = audio_recovered.is_some();
|
||||||
|
*lock(&state.audio) = audio_recovered;
|
||||||
|
|
||||||
|
if recovered {
|
||||||
|
let _ = app.emit("audio-recovered", ());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn stop_capture(app: AppHandle, state: State<'_, AppState>) -> Result<RecordedClip, String> {
|
fn stop_capture(app: AppHandle, state: State<'_, AppState>) -> Result<RecordedClip, String> {
|
||||||
set_overlay_clickthrough(&app, false);
|
set_overlay_clickthrough(&app, false);
|
||||||
@@ -678,6 +720,14 @@ pub struct PreviewRequest {
|
|||||||
pub gif_dither: Option<GifDither>,
|
pub gif_dither: Option<GifDither>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub gif_colors: Option<u16>,
|
pub gif_colors: Option<u16>,
|
||||||
|
/// Optional clip dimensions/duration. Required by `estimate_gif_params`,
|
||||||
|
/// unused by `render_preview` (which uses the current `last_clip`).
|
||||||
|
#[serde(default)]
|
||||||
|
pub clip_width: u32,
|
||||||
|
#[serde(default)]
|
||||||
|
pub clip_height: u32,
|
||||||
|
#[serde(default)]
|
||||||
|
pub duration_secs: Option<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -726,6 +776,91 @@ fn render_preview(
|
|||||||
Ok(preview_path)
|
Ok(preview_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
pub struct GifEstimate {
|
||||||
|
pub width: u32,
|
||||||
|
pub fps: u32,
|
||||||
|
pub height: u32,
|
||||||
|
pub dims_label: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn estimate_gif_params(request: PreviewRequest) -> GifEstimate {
|
||||||
|
let budget = encode::GifBudgetInput {
|
||||||
|
gif_colors: request.gif_colors.unwrap_or(256),
|
||||||
|
target_bytes: request.target_bytes,
|
||||||
|
fps: request.fps,
|
||||||
|
duration_secs: request.duration_secs.unwrap_or(0.0),
|
||||||
|
gif_budget_mode: request.gif_budget_mode,
|
||||||
|
};
|
||||||
|
let (w, fps) = encode::gif_params(&budget, request.clip_width, request.clip_height);
|
||||||
|
let aspect = if request.clip_height > 0 {
|
||||||
|
request.clip_width as f64 / request.clip_height as f64
|
||||||
|
} else {
|
||||||
|
16.0 / 9.0
|
||||||
|
};
|
||||||
|
let height = if w == 0 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
((w as f64 / aspect).round() as u32 / 2) * 2
|
||||||
|
};
|
||||||
|
let dims_label = format!("{w}x{height} @ {fps}fps");
|
||||||
|
GifEstimate { width: w, fps, height, dims_label }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn make_request(target_bytes: u64, fps: u32, mode: GifBudgetMode) -> PreviewRequest {
|
||||||
|
PreviewRequest {
|
||||||
|
format: Format::Gif,
|
||||||
|
fps,
|
||||||
|
target_bytes,
|
||||||
|
gif_budget_mode: mode,
|
||||||
|
gif_dither: Some(GifDither::FloydSteinberg),
|
||||||
|
gif_colors: Some(256),
|
||||||
|
clip_width: 1920,
|
||||||
|
clip_height: 1080,
|
||||||
|
duration_secs: Some(5.0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn estimate_balanced_matches_gif_params() {
|
||||||
|
// The frontend uses estimate_gif_params for the on-screen dims label.
|
||||||
|
// The backend uses gif_params for the actual encode. The two must agree.
|
||||||
|
let req = make_request(8 * 1024 * 1024, 30, GifBudgetMode::Balanced);
|
||||||
|
let est = estimate_gif_params(req);
|
||||||
|
|
||||||
|
let budget = encode::GifBudgetInput {
|
||||||
|
gif_colors: 256,
|
||||||
|
target_bytes: 8 * 1024 * 1024,
|
||||||
|
fps: 30,
|
||||||
|
duration_secs: 5.0,
|
||||||
|
gif_budget_mode: GifBudgetMode::Balanced,
|
||||||
|
};
|
||||||
|
let (encode_w, encode_fps) = encode::gif_params(&budget, 1920, 1080);
|
||||||
|
assert_eq!(est.width, encode_w);
|
||||||
|
assert_eq!(est.fps, encode_fps);
|
||||||
|
// height should be a multiple of 2 and within aspect
|
||||||
|
assert_eq!(est.height % 2, 0);
|
||||||
|
let expected_height = ((encode_w as f64 / (1920.0 / 1080.0)).round() as u32 / 2) * 2;
|
||||||
|
assert_eq!(est.height, expected_height);
|
||||||
|
// dims_label should be "{w}x{h} @ {fps}fps"
|
||||||
|
assert_eq!(est.dims_label, format!("{}x{} @ {}fps", encode_w, est.height, encode_fps));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn estimate_zero_height_falls_back_aspect() {
|
||||||
|
let mut req = make_request(1024, 30, GifBudgetMode::Balanced);
|
||||||
|
req.clip_height = 0;
|
||||||
|
let est = estimate_gif_params(req);
|
||||||
|
// Should not panic and should produce some height
|
||||||
|
assert!(est.height > 0 || est.width == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn extract_thumbnails(
|
fn extract_thumbnails(
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
@@ -771,6 +906,16 @@ const OVERLAY_BORDER_LOGICAL_PX: f64 = 4.0;
|
|||||||
const OVERLAY_TITLEBAR_LOGICAL_PX: f64 = 24.0;
|
const OVERLAY_TITLEBAR_LOGICAL_PX: f64 = 24.0;
|
||||||
|
|
||||||
|
|
||||||
|
/// Remove temporary recording artifacts (segments, previews, thumbs).
|
||||||
|
/// Called on app exit so a discarded clip doesn't linger in `temp/`.
|
||||||
|
fn cleanup_temp_on_exit(app: &AppHandle) {
|
||||||
|
let st = match app.try_state::<AppState>() {
|
||||||
|
Some(s) => s,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
clear_temp_segments(&st.app_dir);
|
||||||
|
}
|
||||||
|
|
||||||
fn start_overlay_clickthrough_poll(app: AppHandle, shutdown: Arc<AtomicBool>) {
|
fn start_overlay_clickthrough_poll(app: AppHandle, shutdown: Arc<AtomicBool>) {
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use windows::Win32::Foundation::{HWND, POINT};
|
use windows::Win32::Foundation::{HWND, POINT};
|
||||||
@@ -1525,7 +1670,13 @@ pub fn run() {
|
|||||||
}
|
}
|
||||||
if check_on_launch {
|
if check_on_launch {
|
||||||
let handle = app.handle().clone();
|
let handle = app.handle().clone();
|
||||||
|
let app_dir = app.state::<AppState>().app_dir.clone();
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
|
// Skip the network call if we checked within the last 6 hours.
|
||||||
|
if !updates::should_check(&app_dir, std::time::Duration::from_secs(6 * 3600)) {
|
||||||
|
tracing::debug!("update check skipped (TTL not elapsed)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
match updates::check_for_update().await {
|
match updates::check_for_update().await {
|
||||||
Ok(Some(info)) => {
|
Ok(Some(info)) => {
|
||||||
tracing::info!(version = info.version, "update available");
|
tracing::info!(version = info.version, "update available");
|
||||||
@@ -1534,6 +1685,9 @@ pub fn run() {
|
|||||||
Ok(None) => tracing::debug!("no update available"),
|
Ok(None) => tracing::debug!("no update available"),
|
||||||
Err(e) => tracing::warn!("update check failed: {e:#}"),
|
Err(e) => tracing::warn!("update check failed: {e:#}"),
|
||||||
}
|
}
|
||||||
|
// Stamp success on Ok results so a future launch won't
|
||||||
|
// re-check until the TTL elapses. Errors don't stamp.
|
||||||
|
updates::stamp_check(&app_dir);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -1549,12 +1703,14 @@ pub fn run() {
|
|||||||
start_capture,
|
start_capture,
|
||||||
pause_capture,
|
pause_capture,
|
||||||
resume_capture,
|
resume_capture,
|
||||||
|
restart_audio_capture,
|
||||||
stop_capture,
|
stop_capture,
|
||||||
export,
|
export,
|
||||||
default_output_path,
|
default_output_path,
|
||||||
extract_thumbnails,
|
extract_thumbnails,
|
||||||
render_preview,
|
render_preview,
|
||||||
render_raw_preview,
|
render_raw_preview,
|
||||||
|
estimate_gif_params,
|
||||||
reveal_in_explorer,
|
reveal_in_explorer,
|
||||||
open_url,
|
open_url,
|
||||||
show_overlay,
|
show_overlay,
|
||||||
@@ -1577,6 +1733,7 @@ pub fn run() {
|
|||||||
if let Some(st) = _app.try_state::<AppState>() {
|
if let Some(st) = _app.try_state::<AppState>() {
|
||||||
st.overlay_poll_shutdown.store(true, Ordering::SeqCst);
|
st.overlay_poll_shutdown.store(true, Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
|
cleanup_temp_on_exit(_app);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,34 @@ pub fn pending_update_path(app_dir: &Path) -> PathBuf {
|
|||||||
app_dir.join("ByteSize.new.exe")
|
app_dir.join("ByteSize.new.exe")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn last_check_path(app_dir: &Path) -> PathBuf {
|
||||||
|
app_dir.join("temp").join("last-update-check")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if the last successful update check happened more than `ttl`
|
||||||
|
/// ago, or never. The stamp file's mtime is the source of truth.
|
||||||
|
pub fn should_check(app_dir: &Path, ttl: std::time::Duration) -> bool {
|
||||||
|
let path = last_check_path(app_dir);
|
||||||
|
let Ok(meta) = std::fs::metadata(&path) else {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
let Ok(modified) = meta.modified() else {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
let Ok(elapsed) = modified.elapsed() else {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
elapsed > ttl
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stamp_check(app_dir: &Path) {
|
||||||
|
let path = last_check_path(app_dir);
|
||||||
|
if let Some(parent) = path.parent() {
|
||||||
|
let _ = std::fs::create_dir_all(parent);
|
||||||
|
}
|
||||||
|
let _ = std::fs::write(&path, b"");
|
||||||
|
}
|
||||||
|
|
||||||
pub fn has_pending_update(app_dir: &Path) -> bool {
|
pub fn has_pending_update(app_dir: &Path) -> bool {
|
||||||
pending_update_path(app_dir).is_file()
|
pending_update_path(app_dir).is_file()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { convertFileSrc } from "./api"
|
||||||
|
|
||||||
|
let {
|
||||||
|
thumbnails,
|
||||||
|
deletedFrames,
|
||||||
|
loading,
|
||||||
|
onToggle,
|
||||||
|
onClear,
|
||||||
|
}: {
|
||||||
|
thumbnails: string[]
|
||||||
|
deletedFrames: Set<number>
|
||||||
|
loading: boolean
|
||||||
|
onToggle: (idx: number) => void
|
||||||
|
onClear: () => void
|
||||||
|
} = $props()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="frames-block">
|
||||||
|
<div class="frames-head">
|
||||||
|
<span class="section-title">Frames</span>
|
||||||
|
{#if deletedFrames.size > 0}
|
||||||
|
<button class="text-btn" onclick={onClear}>Clear ({deletedFrames.size})</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{#if loading}
|
||||||
|
<p class="frames-hint">extracting...</p>
|
||||||
|
{:else}
|
||||||
|
<div class="frames-strip">
|
||||||
|
{#each thumbnails as path, idx}
|
||||||
|
<button
|
||||||
|
class="frame-thumb"
|
||||||
|
class:del={deletedFrames.has(idx)}
|
||||||
|
onclick={() => onToggle(idx)}
|
||||||
|
aria-pressed={deletedFrames.has(idx)}
|
||||||
|
aria-label="frame {idx+1} - {deletedFrames.has(idx) ? 'deleted, click to restore' : 'click to delete'}"
|
||||||
|
title={deletedFrames.has(idx) ? "restore" : "delete"}
|
||||||
|
>
|
||||||
|
<img src={convertFileSrc(path)} alt="" loading="lazy" />
|
||||||
|
<span class="frame-idx">{idx+1}</span>
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.frames-block { display: flex; flex-direction: column; gap: 8px; }
|
||||||
|
.frames-head { display: flex; justify-content: space-between; align-items: center; }
|
||||||
|
.section-title {
|
||||||
|
font-size: 10px;
|
||||||
|
font-weight: 600;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.1em;
|
||||||
|
color: var(--text-3);
|
||||||
|
}
|
||||||
|
.frames-hint { margin: 0; font-size: 11px; color: var(--text-3); }
|
||||||
|
.frames-strip {
|
||||||
|
display: flex;
|
||||||
|
gap: 4px;
|
||||||
|
overflow-x: auto;
|
||||||
|
padding-bottom: 4px;
|
||||||
|
}
|
||||||
|
.frames-strip::-webkit-scrollbar { height: 3px; }
|
||||||
|
.frames-strip::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 2px; }
|
||||||
|
|
||||||
|
.frame-thumb {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
position: relative;
|
||||||
|
padding: 0;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: var(--r-sm);
|
||||||
|
background: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
overflow: hidden;
|
||||||
|
transition: border-color 80ms;
|
||||||
|
}
|
||||||
|
.frame-thumb img { display: block; width: 64px; height: auto; border-radius: 2px; }
|
||||||
|
.frame-thumb:hover { border-color: var(--accent); }
|
||||||
|
.frame-thumb.del img { opacity: 0.2; filter: grayscale(1); }
|
||||||
|
.frame-thumb.del { border-color: var(--err); }
|
||||||
|
.frame-idx {
|
||||||
|
position: absolute; bottom: 2px; right: 3px;
|
||||||
|
font-family: var(--mono); font-size: 9px;
|
||||||
|
color: var(--text-3);
|
||||||
|
background: rgba(0,0,0,0.6);
|
||||||
|
padding: 0 3px;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-btn {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: var(--accent);
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 11px;
|
||||||
|
font-family: var(--sans);
|
||||||
|
padding: 0;
|
||||||
|
transition: color 80ms;
|
||||||
|
}
|
||||||
|
.text-btn:hover { color: var(--accent-hover); }
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { GifBudgetMode, GifDither } from "./api"
|
||||||
|
|
||||||
|
let {
|
||||||
|
budgetMode = $bindable(),
|
||||||
|
dither = $bindable(),
|
||||||
|
colors = $bindable(),
|
||||||
|
onChange,
|
||||||
|
}: {
|
||||||
|
budgetMode: GifBudgetMode
|
||||||
|
dither: GifDither
|
||||||
|
colors: number
|
||||||
|
onChange: () => void
|
||||||
|
} = $props()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<span class="section-title">Budget priority</span>
|
||||||
|
<div class="fmt-bar">
|
||||||
|
{#each (["resolution", "framerate", "balanced"] as const) as m}
|
||||||
|
<button
|
||||||
|
class="fmt-chip"
|
||||||
|
class:active={budgetMode === m}
|
||||||
|
onclick={() => { budgetMode = m; onChange() }}
|
||||||
|
>{m === "resolution" ? "Resolution" : m === "framerate" ? "Framerate" : "Balanced"}</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
<p class="estimate">
|
||||||
|
{budgetMode === "resolution" ? "Keeps resolution high, may reduce FPS" :
|
||||||
|
budgetMode === "framerate" ? "Keeps FPS high, may reduce resolution" :
|
||||||
|
"Balances resolution and FPS"}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<span class="section-title">Colors</span>
|
||||||
|
<div class="control-head">
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
class="styled-range"
|
||||||
|
min={2}
|
||||||
|
max={256}
|
||||||
|
step={1}
|
||||||
|
bind:value={colors}
|
||||||
|
onchange={onChange}
|
||||||
|
/>
|
||||||
|
<span class="mono" style="min-width:32px;text-align:right">{colors}</span>
|
||||||
|
</div>
|
||||||
|
<p class="estimate">{colors <= 32 ? "Low - small file, posterized" : colors <= 128 ? "Medium - balanced" : "High - full color"}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<span class="section-title">Dithering</span>
|
||||||
|
<div class="fmt-bar">
|
||||||
|
{#each (["floyd_steinberg", "bayer", "none"] as const) as d}
|
||||||
|
<button
|
||||||
|
class="fmt-chip"
|
||||||
|
class:active={dither === d}
|
||||||
|
onclick={() => { dither = d; onChange() }}
|
||||||
|
>{d === "floyd_steinberg" ? "Floyd-Steinberg" : d === "bayer" ? "Bayer" : "None"}</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
<p class="estimate">{dither === "floyd_steinberg" ? "Smooth gradients, slightly larger" : dither === "bayer" ? "Patterned, smaller file" : "No dithering, smallest file"}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.control-group { display: flex; flex-direction: column; gap: 8px; }
|
||||||
|
.control-head { display: flex; justify-content: space-between; align-items: center; }
|
||||||
|
.section-title {
|
||||||
|
font-size: 10px;
|
||||||
|
font-weight: 600;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.1em;
|
||||||
|
color: var(--text-3);
|
||||||
|
}
|
||||||
|
.estimate {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-3);
|
||||||
|
font-family: var(--mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
.fmt-bar {
|
||||||
|
display: flex;
|
||||||
|
gap: 2px;
|
||||||
|
padding: 3px;
|
||||||
|
background: var(--bg-2);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--r-sm);
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
.fmt-chip {
|
||||||
|
padding: 5px 14px;
|
||||||
|
background: transparent;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
color: var(--text-3);
|
||||||
|
border-radius: var(--r-sm);
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 500;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 80ms;
|
||||||
|
}
|
||||||
|
.fmt-chip:hover { color: var(--text-2); }
|
||||||
|
.fmt-chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
|
||||||
|
|
||||||
|
.styled-range {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
width: 100%;
|
||||||
|
height: 3px;
|
||||||
|
background: var(--bg-3);
|
||||||
|
border-radius: 2px;
|
||||||
|
outline: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.styled-range::-webkit-slider-thumb {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
width: 14px; height: 14px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--accent);
|
||||||
|
border: 2px solid var(--bg);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: transform 80ms;
|
||||||
|
}
|
||||||
|
.styled-range::-webkit-slider-thumb:hover { transform: scale(1.2); }
|
||||||
|
.mono { font-family: var(--mono); }
|
||||||
|
</style>
|
||||||
+126
-370
@@ -1,8 +1,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import { api, convertFileSrc, formatBytes, type Config, type Format, type GifBudgetMode, type GifDither, type RecordedClip, type ExportResult, type CaptureRect } from "./api"
|
import { api, formatBytes, type Config, type Format, type GifBudgetMode, type GifDither, type RecordedClip, type ExportResult, type CaptureRect } from "./api"
|
||||||
import { save } from "@tauri-apps/plugin-dialog"
|
import { save } from "@tauri-apps/plugin-dialog"
|
||||||
import { emit, listen } from "@tauri-apps/api/event"
|
import { emit, listen } from "@tauri-apps/api/event"
|
||||||
|
import TrimPanel from "./TrimPanel.svelte"
|
||||||
|
import GifControls from "./GifControls.svelte"
|
||||||
|
import Preview from "./Preview.svelte"
|
||||||
|
import FramesStrip from "./FramesStrip.svelte"
|
||||||
|
|
||||||
type Phase = "idle" | "recording" | "paused" | "editing" | "exporting" | "done"
|
type Phase = "idle" | "recording" | "paused" | "editing" | "exporting" | "done"
|
||||||
|
|
||||||
@@ -50,6 +54,7 @@
|
|||||||
let errMsg: string | null = $state(null)
|
let errMsg: string | null = $state(null)
|
||||||
let encodeProgress: { pass: number; total: number; pct: number } | null = $state(null)
|
let encodeProgress: { pass: number; total: number; pct: number } | null = $state(null)
|
||||||
let audioWarning: string | null = $state(null)
|
let audioWarning: string | null = $state(null)
|
||||||
|
let retryingAudio: boolean = $state(false)
|
||||||
let useFrame: boolean = $state(false)
|
let useFrame: boolean = $state(false)
|
||||||
let previewTimer: number | null = null
|
let previewTimer: number | null = null
|
||||||
let thumbCache: Map<string, string[]> = $state(new Map())
|
let thumbCache: Map<string, string[]> = $state(new Map())
|
||||||
@@ -66,44 +71,49 @@
|
|||||||
|
|
||||||
// Derived
|
// Derived
|
||||||
let trimmedDuration = $derived(Math.max(0.1, trimEnd - trimStart))
|
let trimmedDuration = $derived(Math.max(0.1, trimEnd - trimStart))
|
||||||
// NOTE: This logic mirrors gif_params() in encode.rs. Keep in sync.
|
// GIF size/dimensions estimate - computed by the Rust backend so the
|
||||||
|
// math stays in lockstep with encode.rs::gif_params.
|
||||||
|
let gifEstimate: { width: number; fps: number; height: number; dims_label: string } | null = $state(null)
|
||||||
|
let gifEstimateTimer: number | null = null
|
||||||
|
|
||||||
|
async function refreshGifEstimate() {
|
||||||
|
if (!clip || format !== "gif") { gifEstimate = null; return }
|
||||||
|
try {
|
||||||
|
gifEstimate = await api.estimateGifParams({
|
||||||
|
format: "gif",
|
||||||
|
fps,
|
||||||
|
target_bytes: Math.round(targetMB * 1_048_576),
|
||||||
|
gif_budget_mode: gifBudgetMode,
|
||||||
|
gif_dither: gifDither,
|
||||||
|
gif_colors: gifColors,
|
||||||
|
clip_width: clip.width,
|
||||||
|
clip_height: clip.height,
|
||||||
|
duration_secs: trimmedDuration,
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
gifEstimate = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debounced reactive estimate: any change to the inputs re-estimates
|
||||||
|
// ~150 ms after the last change. Cancels in-flight when inputs change again.
|
||||||
|
$effect(() => {
|
||||||
|
// Touch every input so the effect re-runs on any of them changing.
|
||||||
|
void phase; void clip; void format; void fps; void targetMB
|
||||||
|
void gifBudgetMode; void gifDither; void gifColors
|
||||||
|
void trimStart; void trimEnd
|
||||||
|
if (phase !== "editing" || !clip) return
|
||||||
|
if (gifEstimateTimer !== null) clearTimeout(gifEstimateTimer)
|
||||||
|
gifEstimateTimer = window.setTimeout(() => { void refreshGifEstimate() }, 150)
|
||||||
|
return () => {
|
||||||
|
if (gifEstimateTimer !== null) { clearTimeout(gifEstimateTimer); gifEstimateTimer = null }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
let previewDims = $derived.by(() => {
|
let previewDims = $derived.by(() => {
|
||||||
if (!clip) return ""
|
if (!clip) return ""
|
||||||
if (format === "gif") {
|
if (format === "gif") {
|
||||||
const colorFactor = Math.sqrt(gifColors / 256)
|
return gifEstimate ? gifEstimate.dims_label : "computing..."
|
||||||
const bpf = 0.2 * colorFactor
|
|
||||||
const requestedFps = fps
|
|
||||||
const aspect = clip.height === 0 ? 16 / 9 : clip.width / clip.height
|
|
||||||
|
|
||||||
if (gifBudgetMode === "resolution") {
|
|
||||||
const maxW = Math.min(clip.width, 1280)
|
|
||||||
const w = Math.max(120, maxW)
|
|
||||||
const h = Math.round(w / aspect)
|
|
||||||
const pixelsPerFrame = w * h
|
|
||||||
const bytesPerFrame = pixelsPerFrame * bpf
|
|
||||||
const maxFrames = Math.max(1, Math.floor((targetMB * 1_048_576) / bytesPerFrame))
|
|
||||||
const minFps = Math.max(1, Math.round(maxFrames / trimmedDuration))
|
|
||||||
const effectiveFps = Math.max(1, Math.min(requestedFps, minFps))
|
|
||||||
const w2 = w & ~1
|
|
||||||
const h2 = Math.round(w2 / aspect) & ~1
|
|
||||||
return `${w2}x${h2} @ ${effectiveFps}fps`
|
|
||||||
} else if (gifBudgetMode === "framerate") {
|
|
||||||
const frames = Math.max(1, requestedFps * trimmedDuration)
|
|
||||||
const budget = (targetMB * 1_048_576) / (frames * bpf)
|
|
||||||
const w = Math.sqrt(budget * aspect)
|
|
||||||
const w2 = Math.min(clip.width, Math.max(120, Math.round(w))) & ~1
|
|
||||||
const h2 = Math.round(w2 / aspect) & ~1
|
|
||||||
return `${w2}x${h2}`
|
|
||||||
} else {
|
|
||||||
const framesAtFull = Math.max(1, requestedFps * trimmedDuration)
|
|
||||||
const budgetAtFull = (targetMB * 1_048_576) / (framesAtFull * bpf)
|
|
||||||
const wAtFull = Math.sqrt(budgetAtFull * aspect)
|
|
||||||
const scale = wAtFull < clip.width ? Math.sqrt(wAtFull / clip.width) : 1
|
|
||||||
const w2 = Math.max(60, Math.round(clip.width * scale)) & ~1
|
|
||||||
const h2 = Math.round(w2 / aspect) & ~1
|
|
||||||
const effectiveFps = Math.max(1, Math.min(requestedFps, Math.round(requestedFps * scale)))
|
|
||||||
return `${w2}x${h2} @ ${effectiveFps}fps`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return `${clip.width}x${clip.height}`
|
return `${clip.width}x${clip.height}`
|
||||||
})
|
})
|
||||||
@@ -112,10 +122,11 @@
|
|||||||
let unlistenHotkey: (() => void) | null = null
|
let unlistenHotkey: (() => void) | null = null
|
||||||
let unlistenProgress: (() => void) | null = null
|
let unlistenProgress: (() => void) | null = null
|
||||||
let unlistenAudio: (() => void) | null = null
|
let unlistenAudio: (() => void) | null = null
|
||||||
|
let unlistenAudioRecovered: (() => void) | null = null
|
||||||
let unlistenOverlayClosed: (() => void) | null = null
|
let unlistenOverlayClosed: (() => void) | null = null
|
||||||
|
|
||||||
void (async () => {
|
void (async () => {
|
||||||
const [overlayClosed, hotkey, progress, audio] = await Promise.all([
|
const [overlayClosed, hotkey, progress, audio, audioRecovered] = await Promise.all([
|
||||||
listen("overlay-closed", () => { useFrame = false }),
|
listen("overlay-closed", () => { useFrame = false }),
|
||||||
api.onHotkey((kind) => {
|
api.onHotkey((kind) => {
|
||||||
if (kind === "start" && phase === "idle") void startRec()
|
if (kind === "start" && phase === "idle") void startRec()
|
||||||
@@ -132,11 +143,13 @@
|
|||||||
api.onAudioFailed((msg) => {
|
api.onAudioFailed((msg) => {
|
||||||
audioWarning = msg || "audio capture failed - audio will not be recorded"
|
audioWarning = msg || "audio capture failed - audio will not be recorded"
|
||||||
}),
|
}),
|
||||||
|
listen("audio-recovered", () => { audioWarning = null }),
|
||||||
])
|
])
|
||||||
unlistenOverlayClosed = overlayClosed
|
unlistenOverlayClosed = overlayClosed
|
||||||
unlistenHotkey = hotkey
|
unlistenHotkey = hotkey
|
||||||
unlistenProgress = progress
|
unlistenProgress = progress
|
||||||
unlistenAudio = audio
|
unlistenAudio = audio
|
||||||
|
unlistenAudioRecovered = audioRecovered
|
||||||
|
|
||||||
try {
|
try {
|
||||||
config = await api.getConfig()
|
config = await api.getConfig()
|
||||||
@@ -152,6 +165,7 @@
|
|||||||
unlistenHotkey?.()
|
unlistenHotkey?.()
|
||||||
unlistenProgress?.()
|
unlistenProgress?.()
|
||||||
unlistenAudio?.()
|
unlistenAudio?.()
|
||||||
|
unlistenAudioRecovered?.()
|
||||||
unlistenOverlayClosed?.()
|
unlistenOverlayClosed?.()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -220,6 +234,17 @@
|
|||||||
} catch (e) { errMsg = String(e) }
|
} catch (e) { errMsg = String(e) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function retryAudio() {
|
||||||
|
if (retryingAudio) return
|
||||||
|
retryingAudio = true
|
||||||
|
try {
|
||||||
|
await api.restartAudioCapture()
|
||||||
|
// On success, the audio-recovered listener clears audioWarning.
|
||||||
|
// On failure, onAudioFailed re-fires with the new error message.
|
||||||
|
} catch (e) { errMsg = String(e) }
|
||||||
|
finally { retryingAudio = false }
|
||||||
|
}
|
||||||
|
|
||||||
async function browseOutput() {
|
async function browseOutput() {
|
||||||
const ext = format === "gif" ? "gif" : format === "webm" ? "webm" : "mp4"
|
const ext = format === "gif" ? "gif" : format === "webm" ? "webm" : "mp4"
|
||||||
const picked = await save({ defaultPath: outputPath, filters: [{ name: format.toUpperCase(), extensions: [ext] }] })
|
const picked = await save({ defaultPath: outputPath, filters: [{ name: format.toUpperCase(), extensions: [ext] }] })
|
||||||
@@ -322,74 +347,25 @@
|
|||||||
|
|
||||||
function tick() { elapsedTimer = window.setInterval(() => { elapsed += 0.1 }, 100) }
|
function tick() { elapsedTimer = window.setInterval(() => { elapsed += 0.1 }, 100) }
|
||||||
function clearTick() { if (elapsedTimer !== null) { clearInterval(elapsedTimer); elapsedTimer = null } }
|
function clearTick() { if (elapsedTimer !== null) { clearInterval(elapsedTimer); elapsedTimer = null } }
|
||||||
function minMB(s: number): number { return Math.max(0.1, Math.max(50_000, s * 50_000) / 1_048_576) }
|
// Minimum target file size (MB) for a clip of `s` seconds.
|
||||||
function maxMB(s: number): number { return Math.min(200, Math.max(10, s * 5)) }
|
// Hard floor of 0.1 MB; otherwise scale ~50 KB/sec with a 50 KB absolute floor.
|
||||||
|
function minMB(s: number): number {
|
||||||
|
const perSecBytes = s * 50_000
|
||||||
|
const floorBytes = 50_000
|
||||||
|
return Math.max(0.1, Math.max(floorBytes, perSecBytes) / 1_048_576)
|
||||||
|
}
|
||||||
|
// Maximum target file size (MB) for a clip of `s` seconds.
|
||||||
|
// Capped at 200 MB; floor of 10 MB; otherwise scale 5 MB/sec.
|
||||||
|
function maxMB(s: number): number {
|
||||||
|
return Math.min(200, Math.max(10, s * 5))
|
||||||
|
}
|
||||||
|
|
||||||
// Trim drag
|
// Trim state is lifted here so the Preview component can read it
|
||||||
let trackEl: HTMLDivElement | null = $state(null)
|
// (to swap to the raw frame during drag) and the parent can debounce
|
||||||
|
// exports that depend on the values.
|
||||||
let dragging: 'start' | 'end' | null = $state(null)
|
let dragging: 'start' | 'end' | null = $state(null)
|
||||||
let trimPreviewPath: string | null = $state(null)
|
let trimPreviewPath: string | null = $state(null)
|
||||||
let trimPreviewBust: number = $state(0)
|
let trimPreviewBust: number = $state(0)
|
||||||
let lastTrimPreview = 0
|
|
||||||
|
|
||||||
function pointerToSecs(e: PointerEvent): number {
|
|
||||||
if (!trackEl || !clip) return 0
|
|
||||||
const rect = trackEl.getBoundingClientRect()
|
|
||||||
const x = e.clientX - rect.left
|
|
||||||
const ratio = Math.max(0, Math.min(1, x / rect.width))
|
|
||||||
return ratio * clip.duration_secs
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updateTrimPreview(secs: number) {
|
|
||||||
const now = Date.now()
|
|
||||||
if (now - lastTrimPreview < 100) return // 10Hz max
|
|
||||||
lastTrimPreview = now
|
|
||||||
try {
|
|
||||||
trimPreviewPath = await api.renderRawPreview(secs)
|
|
||||||
trimPreviewBust = Date.now()
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
|
|
||||||
function startDrag(which: 'start' | 'end', e: PointerEvent) {
|
|
||||||
dragging = which
|
|
||||||
const el = e.currentTarget as HTMLElement
|
|
||||||
el.setPointerCapture(e.pointerId)
|
|
||||||
// Show raw frame at current trim position
|
|
||||||
void updateTrimPreview(which === 'start' ? trimStart : trimEnd)
|
|
||||||
}
|
|
||||||
|
|
||||||
function onDrag(e: PointerEvent) {
|
|
||||||
if (!dragging || !clip) return
|
|
||||||
const secs = pointerToSecs(e)
|
|
||||||
if (dragging === 'start') {
|
|
||||||
trimStart = Math.min(secs, trimEnd - 0.1)
|
|
||||||
} else {
|
|
||||||
trimEnd = Math.max(secs, trimStart + 0.1)
|
|
||||||
}
|
|
||||||
// Update raw preview as user drags
|
|
||||||
void updateTrimPreview(secs)
|
|
||||||
}
|
|
||||||
|
|
||||||
function endDrag(e: PointerEvent) {
|
|
||||||
const el = e.currentTarget as HTMLElement
|
|
||||||
el.releasePointerCapture(e.pointerId)
|
|
||||||
dragging = null
|
|
||||||
// Switch back to compressed preview
|
|
||||||
trimPreviewPath = null
|
|
||||||
void refreshPreview()
|
|
||||||
}
|
|
||||||
|
|
||||||
function onTrackClick(e: PointerEvent) {
|
|
||||||
if (!clip || !trackEl) return
|
|
||||||
const secs = pointerToSecs(e)
|
|
||||||
const distToStart = Math.abs(secs - trimStart)
|
|
||||||
const distToEnd = Math.abs(secs - trimEnd)
|
|
||||||
if (distToStart < distToEnd) {
|
|
||||||
trimStart = Math.min(secs, trimEnd - 0.1)
|
|
||||||
} else {
|
|
||||||
trimEnd = Math.max(secs, trimStart + 0.1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reactivity
|
// Reactivity
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
@@ -540,7 +516,10 @@
|
|||||||
<svg width="12" height="12" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round">
|
<svg width="12" height="12" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round">
|
||||||
<path d="M7 1L13 12H1L7 1z"/><line x1="7" y1="5" x2="7" y2="8"/><circle cx="7" cy="10.5" r="0.5" fill="currentColor"/>
|
<path d="M7 1L13 12H1L7 1z"/><line x1="7" y1="5" x2="7" y2="8"/><circle cx="7" cy="10.5" r="0.5" fill="currentColor"/>
|
||||||
</svg>
|
</svg>
|
||||||
{audioWarning}
|
<span>{audioWarning}</span>
|
||||||
|
<button class="audio-retry" onclick={retryAudio} disabled={retryingAudio}>
|
||||||
|
{retryingAudio ? "Retrying" : "Retry"}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{:else if config?.capture.capture_audio}
|
{:else if config?.capture.capture_audio}
|
||||||
<div class="audio-ok">
|
<div class="audio-ok">
|
||||||
@@ -580,113 +559,35 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Preview -->
|
<!-- Preview -->
|
||||||
{#if dragging && trimPreviewPath}
|
<Preview
|
||||||
<div class="preview-box">
|
{previewPath}
|
||||||
<img src={convertFileSrc(trimPreviewPath) + "?t=" + trimPreviewBust} alt="preview frame" class="preview-img"/>
|
{previewLoading}
|
||||||
<div class="preview-loading">original</div>
|
{previewCacheBust}
|
||||||
</div>
|
{trimPreviewPath}
|
||||||
{:else if previewPath}
|
{trimPreviewBust}
|
||||||
<div class="preview-box">
|
{dragging}
|
||||||
<img src={convertFileSrc(previewPath) + "?t=" + previewCacheBust} alt="preview frame" class="preview-img"/>
|
/>
|
||||||
{#if previewLoading}<div class="preview-loading">rendering</div>{/if}
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<div class="preview-box empty">
|
|
||||||
<span class="preview-placeholder">preview</span>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<!-- Trim timeline -->
|
<!-- Trim timeline -->
|
||||||
<div class="trim-block">
|
<TrimPanel
|
||||||
<div class="trim-labels">
|
{clip}
|
||||||
<span class="mono">{trimStart.toFixed(2)}s</span>
|
bind:trimStart
|
||||||
<span class="trim-kept">{trimmedDuration.toFixed(2)}s kept</span>
|
bind:trimEnd
|
||||||
<span class="mono">{trimEnd.toFixed(2)}s</span>
|
bind:dragging
|
||||||
</div>
|
bind:trimPreviewPath
|
||||||
<div
|
bind:trimPreviewBust
|
||||||
class="trim-track"
|
onAfterChange={refreshPreview}
|
||||||
bind:this={trackEl}
|
/>
|
||||||
onpointerdown={onTrackClick}
|
|
||||||
role="none"
|
|
||||||
>
|
|
||||||
<div class="trim-range" style="left:{(trimStart/clip.duration_secs)*100}%; right:{(1-trimEnd/clip.duration_secs)*100}%"></div>
|
|
||||||
<div
|
|
||||||
class="trim-handle trim-start"
|
|
||||||
style="left:{(trimStart/clip.duration_secs)*100}%"
|
|
||||||
role="slider"
|
|
||||||
aria-label="trim start"
|
|
||||||
aria-valuemin={0}
|
|
||||||
aria-valuemax={trimEnd - 0.1}
|
|
||||||
aria-valuenow={trimStart}
|
|
||||||
tabindex="0"
|
|
||||||
onpointerdown={(e) => startDrag('start', e)}
|
|
||||||
onpointermove={onDrag}
|
|
||||||
onpointerup={endDrag}
|
|
||||||
onkeydown={(e) => {
|
|
||||||
if (!clip) return
|
|
||||||
const step = e.shiftKey ? 0.5 : 0.05
|
|
||||||
if (e.key === 'ArrowLeft') { trimStart = Math.max(0, trimStart - step); e.preventDefault() }
|
|
||||||
else if (e.key === 'ArrowRight') { trimStart = Math.min(trimEnd - 0.1, trimStart + step); e.preventDefault() }
|
|
||||||
}}
|
|
||||||
></div>
|
|
||||||
<div
|
|
||||||
class="trim-handle trim-end"
|
|
||||||
style="left:{(trimEnd/clip.duration_secs)*100}%"
|
|
||||||
role="slider"
|
|
||||||
aria-label="trim end"
|
|
||||||
aria-valuemin={trimStart + 0.1}
|
|
||||||
aria-valuemax={clip.duration_secs}
|
|
||||||
aria-valuenow={trimEnd}
|
|
||||||
tabindex="0"
|
|
||||||
onpointerdown={(e) => startDrag('end', e)}
|
|
||||||
onpointermove={onDrag}
|
|
||||||
onpointerup={endDrag}
|
|
||||||
onkeydown={(e) => {
|
|
||||||
if (!clip) return
|
|
||||||
const step = e.shiftKey ? 0.5 : 0.05
|
|
||||||
if (e.key === 'ArrowLeft') { trimEnd = Math.max(trimStart + 0.1, trimEnd - step); e.preventDefault() }
|
|
||||||
else if (e.key === 'ArrowRight') { trimEnd = Math.min(clip.duration_secs, trimEnd + step); e.preventDefault() }
|
|
||||||
}}
|
|
||||||
></div>
|
|
||||||
</div>
|
|
||||||
<!-- Screen reader alternative: these range inputs mirror the drag handle positions. -->
|
|
||||||
<input type="range" min="0" max={clip.duration_secs} step="0.05" value={trimStart}
|
|
||||||
oninput={(e) => { const v = parseFloat((e.currentTarget as HTMLInputElement).value); trimStart = Math.min(v, trimEnd - 0.1) }}
|
|
||||||
class="sr-only" aria-label="trim start seconds" />
|
|
||||||
<input type="range" min="0" max={clip.duration_secs} step="0.05" value={trimEnd}
|
|
||||||
oninput={(e) => { const v = parseFloat((e.currentTarget as HTMLInputElement).value); trimEnd = Math.max(v, trimStart + 0.1) }}
|
|
||||||
class="sr-only" aria-label="trim end seconds" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- GIF frames -->
|
<!-- GIF frames -->
|
||||||
{#if format === "gif" && (thumbnails.length > 0 || loadingThumbs)}
|
{#if format === "gif" && (thumbnails.length > 0 || loadingThumbs)}
|
||||||
<div class="frames-block">
|
<FramesStrip
|
||||||
<div class="frames-head">
|
{thumbnails}
|
||||||
<span class="section-title">Frames</span>
|
{deletedFrames}
|
||||||
{#if deletedFrames.size > 0}
|
loading={loadingThumbs}
|
||||||
<button class="text-btn" onclick={clearDeleted}>Clear ({deletedFrames.size})</button>
|
onToggle={toggleThumb}
|
||||||
{/if}
|
onClear={clearDeleted}
|
||||||
</div>
|
/>
|
||||||
{#if loadingThumbs}
|
|
||||||
<p class="frames-hint">extracting...</p>
|
|
||||||
{:else}
|
|
||||||
<div class="frames-strip">
|
|
||||||
{#each thumbnails as path, idx}
|
|
||||||
<button
|
|
||||||
class="frame-thumb"
|
|
||||||
class:del={deletedFrames.has(idx)}
|
|
||||||
onclick={() => toggleThumb(idx)}
|
|
||||||
aria-pressed={deletedFrames.has(idx)}
|
|
||||||
aria-label="frame {idx+1} - {deletedFrames.has(idx) ? 'deleted, click to restore' : 'click to delete'}"
|
|
||||||
title={deletedFrames.has(idx) ? "restore" : "delete"}
|
|
||||||
>
|
|
||||||
<img src={convertFileSrc(path)} alt="" loading="lazy" />
|
|
||||||
<span class="frame-idx">{idx+1}</span>
|
|
||||||
</button>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -711,54 +612,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if format === "gif"}
|
{#if format === "gif"}
|
||||||
<div class="control-group">
|
<GifControls
|
||||||
<span class="section-title">Budget priority</span>
|
bind:budgetMode={gifBudgetMode}
|
||||||
<div class="fmt-bar">
|
bind:dither={gifDither}
|
||||||
{#each (["resolution", "framerate", "balanced"] as const) as m}
|
bind:colors={gifColors}
|
||||||
<button
|
onChange={refreshPreview}
|
||||||
class="fmt-chip"
|
|
||||||
class:active={gifBudgetMode === m}
|
|
||||||
onclick={() => { gifBudgetMode = m }}
|
|
||||||
>{m === "resolution" ? "Resolution" : m === "framerate" ? "Framerate" : "Balanced"}</button>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
<p class="estimate">
|
|
||||||
{gifBudgetMode === "resolution" ? "Keeps resolution high, may reduce FPS" :
|
|
||||||
gifBudgetMode === "framerate" ? "Keeps FPS high, may reduce resolution" :
|
|
||||||
"Balances resolution and FPS"}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="control-group">
|
|
||||||
<span class="section-title">Colors</span>
|
|
||||||
<div class="control-head">
|
|
||||||
<input
|
|
||||||
type="range"
|
|
||||||
class="styled-range"
|
|
||||||
min={2}
|
|
||||||
max={256}
|
|
||||||
step={1}
|
|
||||||
bind:value={gifColors}
|
|
||||||
onchange={refreshPreview}
|
|
||||||
/>
|
/>
|
||||||
<span class="mono" style="min-width:32px;text-align:right">{gifColors}</span>
|
|
||||||
</div>
|
|
||||||
<p class="estimate">{gifColors <= 32 ? "Low - small file, posterized" : gifColors <= 128 ? "Medium - balanced" : "High - full color"}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="control-group">
|
|
||||||
<span class="section-title">Dithering</span>
|
|
||||||
<div class="fmt-bar">
|
|
||||||
{#each (["floyd_steinberg", "bayer", "none"] as const) as d}
|
|
||||||
<button
|
|
||||||
class="fmt-chip"
|
|
||||||
class:active={gifDither === d}
|
|
||||||
onclick={() => { gifDither = d; refreshPreview() }}
|
|
||||||
>{d === "floyd_steinberg" ? "Floyd-Steinberg" : d === "bayer" ? "Bayer" : "None"}</button>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
<p class="estimate">{gifDither === "floyd_steinberg" ? "Smooth gradients, slightly larger" : gifDither === "bayer" ? "Patterned, smaller file" : "No dithering, smallest file"}</p>
|
|
||||||
</div>
|
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!-- FPS + Audio -->
|
<!-- FPS + Audio -->
|
||||||
@@ -1126,6 +985,21 @@
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: var(--err);
|
color: var(--err);
|
||||||
}
|
}
|
||||||
|
.audio-warn > span { flex: 1; }
|
||||||
|
.audio-retry {
|
||||||
|
background: transparent;
|
||||||
|
border: 1px solid var(--err-border);
|
||||||
|
color: var(--err);
|
||||||
|
padding: 3px 10px;
|
||||||
|
border-radius: var(--r-sm);
|
||||||
|
font-family: var(--sans);
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background 80ms, border-color 80ms;
|
||||||
|
}
|
||||||
|
.audio-retry:hover:not(:disabled) { background: var(--err); color: #fff; }
|
||||||
|
.audio-retry:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||||
|
|
||||||
.audio-ok {
|
.audio-ok {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -1234,113 +1108,7 @@
|
|||||||
.fmt-chip:hover { color: var(--text-2); }
|
.fmt-chip:hover { color: var(--text-2); }
|
||||||
.fmt-chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
|
.fmt-chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
|
||||||
|
|
||||||
/* Preview */
|
/* Preview (Trim, Frames, GifControls own their styles in their components) */
|
||||||
.preview-box {
|
|
||||||
position: relative;
|
|
||||||
border-radius: var(--r-sm);
|
|
||||||
overflow: hidden;
|
|
||||||
background: var(--bg-2);
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
display: grid;
|
|
||||||
place-items: center;
|
|
||||||
aspect-ratio: 16 / 9;
|
|
||||||
}
|
|
||||||
.preview-box.empty { aspect-ratio: 16 / 9; }
|
|
||||||
.preview-img {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
object-fit: contain;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
.preview-placeholder {
|
|
||||||
font-size: 11px;
|
|
||||||
color: var(--text-4);
|
|
||||||
text-transform: uppercase;
|
|
||||||
letter-spacing: 0.08em;
|
|
||||||
}
|
|
||||||
.preview-loading {
|
|
||||||
position: absolute; inset: 0;
|
|
||||||
background: rgba(0,0,0,0.5);
|
|
||||||
display: grid; place-items: center;
|
|
||||||
font-size: 11px;
|
|
||||||
color: var(--text-3);
|
|
||||||
text-transform: uppercase;
|
|
||||||
letter-spacing: 0.06em;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Trim */
|
|
||||||
.trim-block { display: flex; flex-direction: column; gap: 8px; }
|
|
||||||
.trim-track {
|
|
||||||
position: relative;
|
|
||||||
height: 4px;
|
|
||||||
background: var(--bg-3);
|
|
||||||
border-radius: 2px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
.trim-range {
|
|
||||||
position: absolute; top: 0; bottom: 0;
|
|
||||||
background: var(--accent);
|
|
||||||
border-radius: 2px;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
.trim-handle {
|
|
||||||
position: absolute; top: 50%; transform: translate(-50%, -50%);
|
|
||||||
width: 12px; height: 22px;
|
|
||||||
background: var(--accent);
|
|
||||||
border-radius: var(--r-sm);
|
|
||||||
cursor: ew-resize;
|
|
||||||
z-index: 1;
|
|
||||||
touch-action: none;
|
|
||||||
}
|
|
||||||
.trim-handle:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--accent-glow); }
|
|
||||||
.trim-labels {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
font-size: 11px;
|
|
||||||
color: var(--text-3);
|
|
||||||
font-family: var(--mono);
|
|
||||||
}
|
|
||||||
.trim-kept { color: var(--accent); }
|
|
||||||
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
|
|
||||||
|
|
||||||
/* Frames */
|
|
||||||
.frames-block { display: flex; flex-direction: column; gap: 8px; }
|
|
||||||
.frames-head { display: flex; justify-content: space-between; align-items: center; }
|
|
||||||
.frames-hint { margin: 0; font-size: 11px; color: var(--text-3); }
|
|
||||||
.frames-strip {
|
|
||||||
display: flex;
|
|
||||||
gap: 4px;
|
|
||||||
overflow-x: auto;
|
|
||||||
padding-bottom: 4px;
|
|
||||||
}
|
|
||||||
.frames-strip::-webkit-scrollbar { height: 3px; }
|
|
||||||
.frames-strip::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 2px; }
|
|
||||||
|
|
||||||
.frame-thumb {
|
|
||||||
flex: 0 0 auto;
|
|
||||||
position: relative;
|
|
||||||
padding: 0;
|
|
||||||
border: 1px solid transparent;
|
|
||||||
border-radius: var(--r-sm);
|
|
||||||
background: transparent;
|
|
||||||
cursor: pointer;
|
|
||||||
overflow: hidden;
|
|
||||||
transition: border-color 80ms;
|
|
||||||
}
|
|
||||||
.frame-thumb img { display: block; width: 64px; height: auto; border-radius: 2px; }
|
|
||||||
.frame-thumb:hover { border-color: var(--accent); }
|
|
||||||
.frame-thumb.del img { opacity: 0.2; filter: grayscale(1); }
|
|
||||||
.frame-thumb.del { border-color: var(--err); }
|
|
||||||
.frame-idx {
|
|
||||||
position: absolute; bottom: 2px; right: 3px;
|
|
||||||
font-family: var(--mono); font-size: 9px;
|
|
||||||
color: var(--text-3);
|
|
||||||
background: rgba(0,0,0,0.6);
|
|
||||||
padding: 0 3px;
|
|
||||||
border-radius: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Right panel controls */
|
|
||||||
.control-group { display: flex; flex-direction: column; gap: 8px; }
|
.control-group { display: flex; flex-direction: column; gap: 8px; }
|
||||||
.control-head {
|
.control-head {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -1505,18 +1273,6 @@
|
|||||||
padding-top: 8px;
|
padding-top: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.text-btn {
|
|
||||||
background: none;
|
|
||||||
border: none;
|
|
||||||
color: var(--accent);
|
|
||||||
cursor: pointer;
|
|
||||||
font-size: 11px;
|
|
||||||
font-family: var(--sans);
|
|
||||||
padding: 0;
|
|
||||||
transition: color 80ms;
|
|
||||||
}
|
|
||||||
.text-btn:hover { color: var(--accent-hover); }
|
|
||||||
|
|
||||||
/* ---- Exporting ---- */
|
/* ---- Exporting ---- */
|
||||||
.exporting {
|
.exporting {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { convertFileSrc } from "./api"
|
||||||
|
|
||||||
|
let {
|
||||||
|
previewPath,
|
||||||
|
previewLoading,
|
||||||
|
previewCacheBust,
|
||||||
|
trimPreviewPath,
|
||||||
|
trimPreviewBust,
|
||||||
|
dragging,
|
||||||
|
}: {
|
||||||
|
previewPath: string | null
|
||||||
|
previewLoading: boolean
|
||||||
|
previewCacheBust: number
|
||||||
|
trimPreviewPath: string | null
|
||||||
|
trimPreviewBust: number
|
||||||
|
dragging: "start" | "end" | null
|
||||||
|
} = $props()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if dragging && trimPreviewPath}
|
||||||
|
<div class="preview-box">
|
||||||
|
<img src={convertFileSrc(trimPreviewPath) + "?t=" + trimPreviewBust} alt="preview frame" class="preview-img"/>
|
||||||
|
<div class="preview-loading">original</div>
|
||||||
|
</div>
|
||||||
|
{:else if previewPath}
|
||||||
|
<div class="preview-box">
|
||||||
|
<img src={convertFileSrc(previewPath) + "?t=" + previewCacheBust} alt="preview frame" class="preview-img"/>
|
||||||
|
{#if previewLoading}<div class="preview-loading">rendering</div>{/if}
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="preview-box empty">
|
||||||
|
<span class="preview-placeholder">preview</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.preview-box {
|
||||||
|
position: relative;
|
||||||
|
border-radius: var(--r-sm);
|
||||||
|
overflow: hidden;
|
||||||
|
background: var(--bg-2);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
aspect-ratio: 16 / 9;
|
||||||
|
}
|
||||||
|
.preview-box.empty { aspect-ratio: 16 / 9; }
|
||||||
|
.preview-img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: contain;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.preview-placeholder {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-4);
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
}
|
||||||
|
.preview-loading {
|
||||||
|
position: absolute; inset: 0;
|
||||||
|
background: rgba(0,0,0,0.5);
|
||||||
|
display: grid; place-items: center;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-3);
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.06em;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { api } from "./api"
|
||||||
|
|
||||||
|
let {
|
||||||
|
clip,
|
||||||
|
trimStart = $bindable(),
|
||||||
|
trimEnd = $bindable(),
|
||||||
|
trimPreviewPath = $bindable(),
|
||||||
|
trimPreviewBust = $bindable(),
|
||||||
|
dragging = $bindable(),
|
||||||
|
onAfterChange,
|
||||||
|
}: {
|
||||||
|
clip: { temp_path: string; duration_secs: number; width: number; height: number }
|
||||||
|
trimStart: number
|
||||||
|
trimEnd: number
|
||||||
|
trimPreviewPath: string | null
|
||||||
|
trimPreviewBust: number
|
||||||
|
dragging: "start" | "end" | null
|
||||||
|
onAfterChange: () => void
|
||||||
|
} = $props()
|
||||||
|
|
||||||
|
let trackEl: HTMLDivElement | null = $state(null)
|
||||||
|
let lastTrimPreview = 0
|
||||||
|
|
||||||
|
function pointerToSecs(e: PointerEvent): number {
|
||||||
|
if (!trackEl) return 0
|
||||||
|
const rect = trackEl.getBoundingClientRect()
|
||||||
|
const x = e.clientX - rect.left
|
||||||
|
const ratio = Math.max(0, Math.min(1, x / rect.width))
|
||||||
|
return ratio * clip.duration_secs
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateTrimPreview(secs: number) {
|
||||||
|
const now = Date.now()
|
||||||
|
if (now - lastTrimPreview < 100) return
|
||||||
|
lastTrimPreview = now
|
||||||
|
try {
|
||||||
|
trimPreviewPath = await api.renderRawPreview(secs)
|
||||||
|
trimPreviewBust = Date.now()
|
||||||
|
} catch {
|
||||||
|
lastTrimPreview = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startDrag(which: "start" | "end", e: PointerEvent) {
|
||||||
|
dragging = which
|
||||||
|
const el = e.currentTarget as HTMLElement
|
||||||
|
el.setPointerCapture(e.pointerId)
|
||||||
|
void updateTrimPreview(which === "start" ? trimStart : trimEnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDrag(e: PointerEvent) {
|
||||||
|
if (!dragging) return
|
||||||
|
const secs = pointerToSecs(e)
|
||||||
|
if (dragging === "start") {
|
||||||
|
trimStart = Math.min(secs, trimEnd - 0.1)
|
||||||
|
} else {
|
||||||
|
trimEnd = Math.max(secs, trimStart + 0.1)
|
||||||
|
}
|
||||||
|
void updateTrimPreview(secs)
|
||||||
|
}
|
||||||
|
|
||||||
|
function endDrag(e: PointerEvent) {
|
||||||
|
const el = e.currentTarget as HTMLElement
|
||||||
|
el.releasePointerCapture(e.pointerId)
|
||||||
|
dragging = null
|
||||||
|
trimPreviewPath = null
|
||||||
|
onAfterChange()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTrackClick(e: PointerEvent) {
|
||||||
|
if (!trackEl) return
|
||||||
|
const secs = pointerToSecs(e)
|
||||||
|
const distToStart = Math.abs(secs - trimStart)
|
||||||
|
const distToEnd = Math.abs(secs - trimEnd)
|
||||||
|
if (distToStart < distToEnd) {
|
||||||
|
trimStart = Math.min(secs, trimEnd - 0.1)
|
||||||
|
} else {
|
||||||
|
trimEnd = Math.max(secs, trimStart + 0.1)
|
||||||
|
}
|
||||||
|
onAfterChange()
|
||||||
|
}
|
||||||
|
|
||||||
|
let trimmedDuration = $derived(Math.max(0.1, trimEnd - trimStart))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="trim-block">
|
||||||
|
<div class="trim-labels">
|
||||||
|
<span class="mono">{trimStart.toFixed(2)}s</span>
|
||||||
|
<span class="trim-kept">{trimmedDuration.toFixed(2)}s kept</span>
|
||||||
|
<span class="mono">{trimEnd.toFixed(2)}s</span>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="trim-track"
|
||||||
|
bind:this={trackEl}
|
||||||
|
onpointerdown={onTrackClick}
|
||||||
|
role="none"
|
||||||
|
>
|
||||||
|
<div class="trim-range" style="left:{(trimStart/clip.duration_secs)*100}%; right:{(1-trimEnd/clip.duration_secs)*100}%"></div>
|
||||||
|
<div
|
||||||
|
class="trim-handle trim-start"
|
||||||
|
style="left:{(trimStart/clip.duration_secs)*100}%"
|
||||||
|
role="slider"
|
||||||
|
aria-label="trim start"
|
||||||
|
aria-valuemin={0}
|
||||||
|
aria-valuemax={trimEnd - 0.1}
|
||||||
|
aria-valuenow={trimStart}
|
||||||
|
tabindex="0"
|
||||||
|
onpointerdown={(e) => startDrag("start", e)}
|
||||||
|
onpointermove={onDrag}
|
||||||
|
onpointerup={endDrag}
|
||||||
|
onkeydown={(e) => {
|
||||||
|
const step = e.shiftKey ? 0.5 : 0.05
|
||||||
|
if (e.key === "ArrowLeft") { trimStart = Math.max(0, trimStart - step); e.preventDefault() }
|
||||||
|
else if (e.key === "ArrowRight") { trimStart = Math.min(trimEnd - 0.1, trimStart + step); e.preventDefault() }
|
||||||
|
}}
|
||||||
|
></div>
|
||||||
|
<div
|
||||||
|
class="trim-handle trim-end"
|
||||||
|
style="left:{(trimEnd/clip.duration_secs)*100}%"
|
||||||
|
role="slider"
|
||||||
|
aria-label="trim end"
|
||||||
|
aria-valuemin={trimStart + 0.1}
|
||||||
|
aria-valuemax={clip.duration_secs}
|
||||||
|
aria-valuenow={trimEnd}
|
||||||
|
tabindex="0"
|
||||||
|
onpointerdown={(e) => startDrag("end", e)}
|
||||||
|
onpointermove={onDrag}
|
||||||
|
onpointerup={endDrag}
|
||||||
|
onkeydown={(e) => {
|
||||||
|
const step = e.shiftKey ? 0.5 : 0.05
|
||||||
|
if (e.key === "ArrowLeft") { trimEnd = Math.max(trimStart + 0.1, trimEnd - step); e.preventDefault() }
|
||||||
|
else if (e.key === "ArrowRight") { trimEnd = Math.min(clip.duration_secs, trimEnd + step); e.preventDefault() }
|
||||||
|
}}
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
|
<input type="range" min="0" max={clip.duration_secs} step="0.05" value={trimStart}
|
||||||
|
oninput={(e) => { const v = parseFloat((e.currentTarget as HTMLInputElement).value); trimStart = Math.min(v, trimEnd - 0.1) }}
|
||||||
|
class="sr-only" aria-label="trim start seconds" />
|
||||||
|
<input type="range" min="0" max={clip.duration_secs} step="0.05" value={trimEnd}
|
||||||
|
oninput={(e) => { const v = parseFloat((e.currentTarget as HTMLInputElement).value); trimEnd = Math.max(v, trimStart + 0.1) }}
|
||||||
|
class="sr-only" aria-label="trim end seconds" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.trim-block { display: flex; flex-direction: column; gap: 8px; }
|
||||||
|
.trim-track {
|
||||||
|
position: relative;
|
||||||
|
height: 4px;
|
||||||
|
background: var(--bg-3);
|
||||||
|
border-radius: 2px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.trim-range {
|
||||||
|
position: absolute; top: 0; bottom: 0;
|
||||||
|
background: var(--accent);
|
||||||
|
border-radius: 2px;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.trim-handle {
|
||||||
|
position: absolute; top: 50%; transform: translate(-50%, -50%);
|
||||||
|
width: 12px; height: 22px;
|
||||||
|
background: var(--accent);
|
||||||
|
border-radius: var(--r-sm);
|
||||||
|
cursor: ew-resize;
|
||||||
|
z-index: 1;
|
||||||
|
touch-action: none;
|
||||||
|
}
|
||||||
|
.trim-handle:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--accent-glow); }
|
||||||
|
.trim-labels {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-3);
|
||||||
|
font-family: var(--mono);
|
||||||
|
}
|
||||||
|
.trim-kept { color: var(--accent); }
|
||||||
|
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
|
||||||
|
</style>
|
||||||
@@ -141,6 +141,13 @@ export type EncodeProgress = {
|
|||||||
percent: number
|
percent: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type GifEstimate = {
|
||||||
|
width: number
|
||||||
|
fps: number
|
||||||
|
height: number
|
||||||
|
dims_label: string
|
||||||
|
}
|
||||||
|
|
||||||
export type AudioFailed = string
|
export type AudioFailed = string
|
||||||
|
|
||||||
export const api = {
|
export const api = {
|
||||||
@@ -154,6 +161,7 @@ export const api = {
|
|||||||
invoke<void>("start_capture", { request }),
|
invoke<void>("start_capture", { request }),
|
||||||
pauseCapture: () => invoke<void>("pause_capture"),
|
pauseCapture: () => invoke<void>("pause_capture"),
|
||||||
resumeCapture: () => invoke<void>("resume_capture"),
|
resumeCapture: () => invoke<void>("resume_capture"),
|
||||||
|
restartAudioCapture: () => invoke<void>("restart_audio_capture"),
|
||||||
stopCapture: () => invoke<RecordedClip>("stop_capture"),
|
stopCapture: () => invoke<RecordedClip>("stop_capture"),
|
||||||
export: (request: ExportRequest) => invoke<ExportResult>("export", { request }),
|
export: (request: ExportRequest) => invoke<ExportResult>("export", { request }),
|
||||||
revealInExplorer: (path: string) => invoke<void>("reveal_in_explorer", { path }),
|
revealInExplorer: (path: string) => invoke<void>("reveal_in_explorer", { path }),
|
||||||
@@ -171,6 +179,18 @@ export const api = {
|
|||||||
invoke<string[]>("extract_thumbnails", { fps }),
|
invoke<string[]>("extract_thumbnails", { fps }),
|
||||||
renderPreview: (format: Format, fps: number, target_bytes: number, gif_budget_mode?: GifBudgetMode, gif_dither?: GifDither, gif_colors?: number) =>
|
renderPreview: (format: Format, fps: number, target_bytes: number, gif_budget_mode?: GifBudgetMode, gif_dither?: GifDither, gif_colors?: number) =>
|
||||||
invoke<string>("render_preview", { request: { format, fps, target_bytes, gif_budget_mode, gif_dither, gif_colors } }),
|
invoke<string>("render_preview", { request: { format, fps, target_bytes, gif_budget_mode, gif_dither, gif_colors } }),
|
||||||
|
estimateGifParams: (input: {
|
||||||
|
format: Format
|
||||||
|
fps: number
|
||||||
|
target_bytes: number
|
||||||
|
gif_budget_mode?: GifBudgetMode
|
||||||
|
gif_dither?: GifDither
|
||||||
|
gif_colors?: number
|
||||||
|
clip_width: number
|
||||||
|
clip_height: number
|
||||||
|
duration_secs: number
|
||||||
|
}) =>
|
||||||
|
invoke<GifEstimate>("estimate_gif_params", { request: input }),
|
||||||
renderRawPreview: (timestamp: number) =>
|
renderRawPreview: (timestamp: number) =>
|
||||||
invoke<string>("render_raw_preview", { timestamp }),
|
invoke<string>("render_raw_preview", { timestamp }),
|
||||||
defaultOutputPath: (format: Format) =>
|
defaultOutputPath: (format: Format) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user