tighten export and capture handling
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
<script lang="ts">
|
||||
import GifControls from "./GifControls.svelte"
|
||||
import type { Format, GifBudgetMode, GifDither } from "./api"
|
||||
import { maxTargetMB, minTargetMB } from "./exportSizing"
|
||||
|
||||
let {
|
||||
clip,
|
||||
format,
|
||||
targetMB = $bindable(),
|
||||
fps = $bindable(),
|
||||
keepAudio = $bindable(),
|
||||
gifBudgetMode = $bindable(),
|
||||
gifDither = $bindable(),
|
||||
gifColors = $bindable(),
|
||||
cropEnabled = $bindable(),
|
||||
cropX = $bindable(),
|
||||
cropY = $bindable(),
|
||||
cropW = $bindable(),
|
||||
cropH = $bindable(),
|
||||
outputPath = $bindable(),
|
||||
previewDims,
|
||||
trimmedDuration,
|
||||
onPreview,
|
||||
onPathInput,
|
||||
onBrowse,
|
||||
onExport,
|
||||
onDiscard,
|
||||
}: {
|
||||
clip: { duration_secs: number; width: number; height: number }
|
||||
format: Format
|
||||
targetMB: number
|
||||
fps: number
|
||||
keepAudio: boolean
|
||||
gifBudgetMode: GifBudgetMode
|
||||
gifDither: GifDither
|
||||
gifColors: number
|
||||
cropEnabled: boolean
|
||||
cropX: number
|
||||
cropY: number
|
||||
cropW: number
|
||||
cropH: number
|
||||
outputPath: string
|
||||
previewDims: string
|
||||
trimmedDuration: number
|
||||
onPreview: () => void
|
||||
onPathInput: () => void
|
||||
onBrowse: () => void
|
||||
onExport: () => void
|
||||
onDiscard: () => void
|
||||
} = $props()
|
||||
|
||||
function clampCrop() {
|
||||
cropX = Math.max(0, Math.min(cropX, Math.max(0, clip.width - 1)))
|
||||
cropY = Math.max(0, Math.min(cropY, Math.max(0, clip.height - 1)))
|
||||
cropW = Math.max(1, Math.min(cropW, clip.width - cropX))
|
||||
cropH = Math.max(1, Math.min(cropH, clip.height - cropY))
|
||||
}
|
||||
|
||||
let cropInvalid = $derived.by(() => {
|
||||
if (!cropEnabled) return false
|
||||
return cropX < 0 || cropY < 0 || cropW < 1 || cropH < 1
|
||||
|| cropX + cropW > clip.width
|
||||
|| cropY + cropH > clip.height
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="edit-right">
|
||||
<div class="control-group">
|
||||
<div class="control-head">
|
||||
<span class="section-title">Target size</span>
|
||||
<span class="mono size-readout">{targetMB.toFixed(1)} MB</span>
|
||||
</div>
|
||||
<input
|
||||
type="range"
|
||||
class="styled-range"
|
||||
min={minTargetMB(clip.duration_secs)}
|
||||
max={maxTargetMB(clip.duration_secs)}
|
||||
step="0.1"
|
||||
bind:value={targetMB}
|
||||
onchange={onPreview}
|
||||
/>
|
||||
<p class="estimate">{previewDims} · {fps}fps · {trimmedDuration.toFixed(1)}s</p>
|
||||
</div>
|
||||
|
||||
{#if format === "gif"}
|
||||
<GifControls
|
||||
bind:budgetMode={gifBudgetMode}
|
||||
bind:dither={gifDither}
|
||||
bind:colors={gifColors}
|
||||
onChange={onPreview}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<div class="control-row">
|
||||
<label class="control">
|
||||
<span class="control-label">FPS</span>
|
||||
<select bind:value={fps} onchange={onPreview}>
|
||||
{#each [1, 2, 5, 10, 15, 24, 30, 60] as f}<option value={f}>{f}</option>{/each}
|
||||
</select>
|
||||
</label>
|
||||
{#if format !== "gif"}
|
||||
<label class="check-control">
|
||||
<input type="checkbox" bind:checked={keepAudio} />
|
||||
<span>Keep audio</span>
|
||||
</label>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="control-head">
|
||||
<span class="section-title">Crop</span>
|
||||
<label class="check-control compact">
|
||||
<input type="checkbox" bind:checked={cropEnabled} />
|
||||
<span>Enable</span>
|
||||
</label>
|
||||
</div>
|
||||
{#if cropEnabled}
|
||||
<div class="crop-grid" class:invalid={cropInvalid}>
|
||||
<label class="crop-field">
|
||||
<span>X</span>
|
||||
<input type="number" min="0" max={clip.width} bind:value={cropX} onblur={clampCrop} />
|
||||
</label>
|
||||
<label class="crop-field">
|
||||
<span>Y</span>
|
||||
<input type="number" min="0" max={clip.height} bind:value={cropY} onblur={clampCrop} />
|
||||
</label>
|
||||
<label class="crop-field">
|
||||
<span>W</span>
|
||||
<input type="number" min="1" max={clip.width} bind:value={cropW} onblur={clampCrop} />
|
||||
</label>
|
||||
<label class="crop-field">
|
||||
<span>H</span>
|
||||
<input type="number" min="1" max={clip.height} bind:value={cropH} onblur={clampCrop} />
|
||||
</label>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<span class="section-title">Output</span>
|
||||
<div class="path-row">
|
||||
<input type="text" class="path-input" bind:value={outputPath} oninput={onPathInput} aria-label="output file path" />
|
||||
<button class="btn-ghost" onclick={onBrowse}>Browse</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="edit-actions">
|
||||
<button class="btn-primary" onclick={onExport} disabled={cropInvalid}>Export</button>
|
||||
<button class="btn-ghost" onclick={onDiscard}>Discard</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.edit-right {
|
||||
background: var(--bg);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
overflow: auto;
|
||||
min-height: 0;
|
||||
padding: 20px;
|
||||
border-left: 1px solid var(--border);
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.edit-right { border-left: none; border-top: 1px solid var(--border); }
|
||||
}
|
||||
|
||||
.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); }
|
||||
.size-readout { font-size: 14px; color: var(--text); }
|
||||
.styled-range { -webkit-appearance: none; 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; 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); }
|
||||
.estimate { margin: 0; font-size: 11px; color: var(--text-3); font-family: var(--mono); }
|
||||
.control-row { display: flex; gap: 16px; align-items: flex-end; }
|
||||
.control { display: flex; flex-direction: column; gap: 6px; }
|
||||
.control-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); }
|
||||
select { padding: 7px 10px; background: var(--bg-2); border: 1px solid var(--border); color: var(--text); border-radius: var(--r-sm); font-family: var(--mono); font-size: 12px; cursor: pointer; outline: none; }
|
||||
select:focus { border-color: var(--accent); }
|
||||
.check-control { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); cursor: pointer; }
|
||||
.check-control.compact { font-size: 11px; }
|
||||
.check-control input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--accent); cursor: pointer; }
|
||||
.crop-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
|
||||
.crop-grid.invalid input { border-color: var(--err); background: var(--err-dim); }
|
||||
.crop-field { display: flex; flex-direction: column; gap: 4px; }
|
||||
.crop-field span { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }
|
||||
.crop-field input { padding: 6px 8px; background: var(--bg-2); border: 1px solid var(--border); color: var(--text); border-radius: var(--r-sm); font-family: var(--mono); font-size: 12px; outline: none; width: 100%; }
|
||||
.crop-field input:focus { border-color: var(--accent); }
|
||||
.path-row { display: flex; gap: 6px; }
|
||||
.path-input { flex: 1; padding: 7px 10px; background: var(--bg-2); border: 1px solid var(--border); color: var(--text); border-radius: var(--r-sm); font-family: var(--mono); font-size: 11px; outline: none; }
|
||||
.path-input:focus { border-color: var(--accent); }
|
||||
.btn-primary { padding: 10px 24px; background: var(--accent); border: none; color: var(--accent-text); border-radius: var(--r-sm); font-family: var(--sans); font-size: 13px; font-weight: 600; cursor: pointer; transition: background 80ms; white-space: nowrap; }
|
||||
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
|
||||
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.btn-ghost { padding: 10px 18px; background: transparent; border: 1px solid var(--border-2); color: var(--text-3); border-radius: var(--r-sm); font-family: var(--sans); font-size: 13px; cursor: pointer; transition: border-color 80ms, color 80ms; white-space: nowrap; }
|
||||
.btn-ghost:hover { border-color: var(--border-3); color: var(--text); }
|
||||
.edit-actions { display: flex; gap: 10px; margin-top: auto; padding-top: 8px; }
|
||||
</style>
|
||||
@@ -107,6 +107,7 @@
|
||||
|
||||
.styled-range {
|
||||
-webkit-appearance: none;
|
||||
appearance: none;
|
||||
width: 100%;
|
||||
height: 3px;
|
||||
background: var(--bg-3);
|
||||
@@ -116,6 +117,7 @@
|
||||
}
|
||||
.styled-range::-webkit-slider-thumb {
|
||||
-webkit-appearance: none;
|
||||
appearance: none;
|
||||
width: 14px; height: 14px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent);
|
||||
|
||||
+45
-259
@@ -4,9 +4,11 @@
|
||||
import { save } from "@tauri-apps/plugin-dialog"
|
||||
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"
|
||||
import ExportSidebar from "./ExportSidebar.svelte"
|
||||
import { resetTrimPreview } from "./trimPreviewState.svelte"
|
||||
import { minTargetMB } from "./exportSizing"
|
||||
|
||||
type Phase = "idle" | "recording" | "paused" | "editing" | "exporting" | "done"
|
||||
|
||||
@@ -209,7 +211,7 @@
|
||||
cropH = c.height
|
||||
pathOverridden = false
|
||||
outputPath = await api.defaultOutputPath(format)
|
||||
const sensible = Math.min(50, Math.max(minMB(c.duration_secs), Math.round(c.duration_secs * 0.5)))
|
||||
const sensible = Math.min(50, Math.max(minTargetMB(c.duration_secs), Math.round(c.duration_secs * 0.5)))
|
||||
targetMB = sensible
|
||||
} catch (e) { errMsg = String(e); phase = "idle"; clearTick() }
|
||||
}
|
||||
@@ -314,7 +316,7 @@
|
||||
clip = null; exportResult = null; errMsg = null; encodeProgress = null
|
||||
thumbnails = []; deletedFrames = new Set()
|
||||
thumbCache = new Map()
|
||||
previewPath = null; trimPreviewPath = null
|
||||
previewPath = null; resetTrimPreview()
|
||||
if (previewTimer !== null) { clearTimeout(previewTimer); previewTimer = null }
|
||||
elapsed = 0; phase = "idle"
|
||||
if (config) {
|
||||
@@ -347,25 +349,6 @@
|
||||
|
||||
function tick() { elapsedTimer = window.setInterval(() => { elapsed += 0.1 }, 100) }
|
||||
function clearTick() { if (elapsedTimer !== null) { clearInterval(elapsedTimer); elapsedTimer = null } }
|
||||
// Minimum target file size (MB) for a clip of `s` seconds.
|
||||
// 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 state is lifted here so the Preview component can read it
|
||||
// (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 trimPreviewPath: string | null = $state(null)
|
||||
let trimPreviewBust: number = $state(0)
|
||||
|
||||
// Reactivity
|
||||
$effect(() => {
|
||||
@@ -563,9 +546,6 @@
|
||||
{previewPath}
|
||||
{previewLoading}
|
||||
{previewCacheBust}
|
||||
{trimPreviewPath}
|
||||
{trimPreviewBust}
|
||||
{dragging}
|
||||
/>
|
||||
|
||||
<!-- Trim timeline -->
|
||||
@@ -573,9 +553,6 @@
|
||||
{clip}
|
||||
bind:trimStart
|
||||
bind:trimEnd
|
||||
bind:dragging
|
||||
bind:trimPreviewPath
|
||||
bind:trimPreviewBust
|
||||
onAfterChange={refreshPreview}
|
||||
/>
|
||||
|
||||
@@ -592,96 +569,29 @@
|
||||
</div>
|
||||
|
||||
<!-- Right: controls -->
|
||||
<div class="edit-right">
|
||||
<!-- Target size -->
|
||||
<div class="control-group">
|
||||
<div class="control-head">
|
||||
<span class="section-title">Target size</span>
|
||||
<span class="mono size-readout">{targetMB.toFixed(1)} MB</span>
|
||||
</div>
|
||||
<input
|
||||
type="range"
|
||||
class="styled-range"
|
||||
min={minMB(clip.duration_secs)}
|
||||
max={maxMB(clip.duration_secs)}
|
||||
step="0.1"
|
||||
bind:value={targetMB}
|
||||
onchange={refreshPreview}
|
||||
/>
|
||||
<p class="estimate">{previewDims} · {fps}fps · {trimmedDuration.toFixed(1)}s</p>
|
||||
</div>
|
||||
|
||||
{#if format === "gif"}
|
||||
<GifControls
|
||||
bind:budgetMode={gifBudgetMode}
|
||||
bind:dither={gifDither}
|
||||
bind:colors={gifColors}
|
||||
onChange={refreshPreview}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<!-- FPS + Audio -->
|
||||
<div class="control-row">
|
||||
<label class="control">
|
||||
<span class="control-label">FPS</span>
|
||||
<select bind:value={fps} onchange={refreshPreview}>
|
||||
{#each [1, 2, 5, 10, 15, 24, 30, 60] as f}<option value={f}>{f}</option>{/each}
|
||||
</select>
|
||||
</label>
|
||||
{#if format !== "gif"}
|
||||
<label class="check-control">
|
||||
<input type="checkbox" bind:checked={keepAudio} />
|
||||
<span>Keep audio</span>
|
||||
</label>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Crop -->
|
||||
<div class="control-group">
|
||||
<div class="control-head">
|
||||
<span class="section-title">Crop</span>
|
||||
<label class="check-control compact">
|
||||
<input type="checkbox" bind:checked={cropEnabled} />
|
||||
<span>Enable</span>
|
||||
</label>
|
||||
</div>
|
||||
{#if cropEnabled}
|
||||
<div class="crop-grid">
|
||||
<label class="crop-field">
|
||||
<span>X</span>
|
||||
<input type="number" min="0" max={clip?.width ?? 9999} bind:value={cropX} />
|
||||
</label>
|
||||
<label class="crop-field">
|
||||
<span>Y</span>
|
||||
<input type="number" min="0" max={clip?.height ?? 9999} bind:value={cropY} />
|
||||
</label>
|
||||
<label class="crop-field">
|
||||
<span>W</span>
|
||||
<input type="number" min="1" max={clip?.width ?? 9999} bind:value={cropW} />
|
||||
</label>
|
||||
<label class="crop-field">
|
||||
<span>H</span>
|
||||
<input type="number" min="1" max={clip?.height ?? 9999} bind:value={cropH} />
|
||||
</label>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Output path -->
|
||||
<div class="control-group">
|
||||
<span class="section-title">Output</span>
|
||||
<div class="path-row">
|
||||
<input type="text" class="path-input" bind:value={outputPath} oninput={() => pathOverridden = true} aria-label="output file path" />
|
||||
<button class="btn-ghost" onclick={browseOutput}>Browse</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<div class="edit-actions">
|
||||
<button class="btn-primary" onclick={doExport}>Export</button>
|
||||
<button class="btn-ghost" onclick={confirmDiscard}>Discard</button>
|
||||
</div>
|
||||
</div>
|
||||
<ExportSidebar
|
||||
{clip}
|
||||
{format}
|
||||
bind:targetMB
|
||||
bind:fps
|
||||
bind:keepAudio
|
||||
bind:gifBudgetMode
|
||||
bind:gifDither
|
||||
bind:gifColors
|
||||
bind:cropEnabled
|
||||
bind:cropX
|
||||
bind:cropY
|
||||
bind:cropW
|
||||
bind:cropH
|
||||
bind:outputPath
|
||||
{previewDims}
|
||||
{trimmedDuration}
|
||||
onPreview={refreshPreview}
|
||||
onPathInput={() => pathOverridden = true}
|
||||
onBrowse={browseOutput}
|
||||
onExport={doExport}
|
||||
onDiscard={confirmDiscard}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- EXPORTING -->
|
||||
@@ -693,11 +603,18 @@
|
||||
<span class="mono">{encodeProgress.pct.toFixed(0)}%</span>
|
||||
</div>
|
||||
<div class="enc-track">
|
||||
<div class="enc-fill" style="width:{encodeProgress.pct}%"></div>
|
||||
{#each Array(encodeProgress.total) as _, i}
|
||||
<div class="enc-segment">
|
||||
<div
|
||||
class="enc-fill"
|
||||
style="width:{i + 1 < encodeProgress.pass ? 100 : i + 1 === encodeProgress.pass ? encodeProgress.pct : 0}%"
|
||||
></div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="enc-meta"><span>Preparing</span></div>
|
||||
<div class="enc-track"><div class="enc-fill" style="width:0%"></div></div>
|
||||
<div class="enc-track"><div class="enc-segment"><div class="enc-fill" style="width:0%"></div></div></div>
|
||||
{/if}
|
||||
<p class="enc-hint">ffmpeg is encoding your clip</p>
|
||||
<button class="btn-ghost" onclick={cancelExport}>Cancel</button>
|
||||
@@ -1066,7 +983,7 @@
|
||||
background: var(--border);
|
||||
min-height: 0;
|
||||
}
|
||||
.edit-left, .edit-right {
|
||||
.edit-left {
|
||||
background: var(--bg);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -1075,11 +992,9 @@
|
||||
min-height: 0;
|
||||
}
|
||||
.edit-left { padding: 20px; gap: 20px; }
|
||||
.edit-right { padding: 20px; gap: 20px; border-left: 1px solid var(--border); }
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.edit { grid-template-columns: 1fr; }
|
||||
.edit-right { border-left: none; border-top: 1px solid var(--border); }
|
||||
}
|
||||
|
||||
/* Format bar */
|
||||
@@ -1108,135 +1023,6 @@
|
||||
.fmt-chip:hover { color: var(--text-2); }
|
||||
.fmt-chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
|
||||
|
||||
/* Preview (Trim, Frames, GifControls own their styles in their components) */
|
||||
.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);
|
||||
}
|
||||
.size-readout { font-size: 14px; color: var(--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); }
|
||||
|
||||
.estimate {
|
||||
margin: 0;
|
||||
font-size: 11px;
|
||||
color: var(--text-3);
|
||||
font-family: var(--mono);
|
||||
}
|
||||
|
||||
.control-row {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
align-items: flex-end;
|
||||
}
|
||||
.control { display: flex; flex-direction: column; gap: 6px; }
|
||||
.control-label {
|
||||
font-size: 10px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
color: var(--text-3);
|
||||
}
|
||||
|
||||
select {
|
||||
padding: 7px 10px;
|
||||
background: var(--bg-2);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
border-radius: var(--r-sm);
|
||||
font-family: var(--mono);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
}
|
||||
select:focus { border-color: var(--accent); }
|
||||
|
||||
.check-control {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 12px;
|
||||
color: var(--text-2);
|
||||
cursor: pointer;
|
||||
}
|
||||
.check-control.compact { font-size: 11px; }
|
||||
.check-control input[type="checkbox"] {
|
||||
width: 14px; height: 14px;
|
||||
accent-color: var(--accent);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Crop */
|
||||
.crop-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 8px;
|
||||
}
|
||||
.crop-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
.crop-field span {
|
||||
font-size: 10px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--text-3);
|
||||
}
|
||||
.crop-field input {
|
||||
padding: 6px 8px;
|
||||
background: var(--bg-2);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
border-radius: var(--r-sm);
|
||||
font-family: var(--mono);
|
||||
font-size: 12px;
|
||||
outline: none;
|
||||
width: 100%;
|
||||
}
|
||||
.crop-field input:focus { border-color: var(--accent); }
|
||||
|
||||
/* Path */
|
||||
.path-row { display: flex; gap: 6px; }
|
||||
.path-input {
|
||||
flex: 1;
|
||||
padding: 7px 10px;
|
||||
background: var(--bg-2);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
border-radius: var(--r-sm);
|
||||
font-family: var(--mono);
|
||||
font-size: 11px;
|
||||
outline: none;
|
||||
}
|
||||
.path-input:focus { border-color: var(--accent); }
|
||||
|
||||
.btn-primary {
|
||||
padding: 10px 24px;
|
||||
background: var(--accent);
|
||||
@@ -1266,13 +1052,6 @@
|
||||
}
|
||||
.btn-ghost:hover { border-color: var(--border-3); color: var(--text); }
|
||||
|
||||
.edit-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: auto;
|
||||
padding-top: 8px;
|
||||
}
|
||||
|
||||
/* ---- Exporting ---- */
|
||||
.exporting {
|
||||
flex: 1;
|
||||
@@ -1299,7 +1078,10 @@
|
||||
background: var(--bg-3);
|
||||
border-radius: 2px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
}
|
||||
.enc-segment { flex: 1; background: var(--bg-3); overflow: hidden; }
|
||||
.enc-fill {
|
||||
height: 100%;
|
||||
background: var(--accent);
|
||||
@@ -1398,6 +1180,7 @@
|
||||
background: rgba(0,0,0,0.5);
|
||||
display: grid; place-items: center;
|
||||
z-index: 50;
|
||||
animation: fadein 120ms ease-out;
|
||||
}
|
||||
.confirm-card {
|
||||
background: var(--bg-2);
|
||||
@@ -1406,7 +1189,10 @@
|
||||
padding: 24px;
|
||||
min-width: 280px;
|
||||
text-align: center;
|
||||
animation: cardin 140ms ease-out;
|
||||
}
|
||||
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
|
||||
@keyframes cardin { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
|
||||
.confirm-card p { margin: 0 0 16px; font-size: 14px; color: var(--text); }
|
||||
.confirm-actions { display: flex; gap: 10px; justify-content: center; }
|
||||
</style>
|
||||
|
||||
@@ -1,26 +1,21 @@
|
||||
<script lang="ts">
|
||||
import { convertFileSrc } from "./api"
|
||||
import { trimPreviewState } from "./trimPreviewState.svelte"
|
||||
|
||||
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}
|
||||
{#if trimPreviewState.dragging && trimPreviewState.path}
|
||||
<div class="preview-box">
|
||||
<img src={convertFileSrc(trimPreviewPath) + "?t=" + trimPreviewBust} alt="preview frame" class="preview-img"/>
|
||||
<img src={convertFileSrc(trimPreviewState.path) + "?t=" + trimPreviewState.bust} alt="preview frame" class="preview-img"/>
|
||||
<div class="preview-loading">original</div>
|
||||
</div>
|
||||
{:else if previewPath}
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
<script lang="ts">
|
||||
import { api } from "./api"
|
||||
import { trimPreviewState } from "./trimPreviewState.svelte"
|
||||
|
||||
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()
|
||||
|
||||
@@ -35,24 +30,24 @@
|
||||
if (now - lastTrimPreview < 100) return
|
||||
lastTrimPreview = now
|
||||
try {
|
||||
trimPreviewPath = await api.renderRawPreview(secs)
|
||||
trimPreviewBust = Date.now()
|
||||
trimPreviewState.path = await api.renderRawPreview(secs)
|
||||
trimPreviewState.bust = Date.now()
|
||||
} catch {
|
||||
lastTrimPreview = 0
|
||||
}
|
||||
}
|
||||
|
||||
function startDrag(which: "start" | "end", e: PointerEvent) {
|
||||
dragging = which
|
||||
trimPreviewState.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
|
||||
if (!trimPreviewState.dragging) return
|
||||
const secs = pointerToSecs(e)
|
||||
if (dragging === "start") {
|
||||
if (trimPreviewState.dragging === "start") {
|
||||
trimStart = Math.min(secs, trimEnd - 0.1)
|
||||
} else {
|
||||
trimEnd = Math.max(secs, trimStart + 0.1)
|
||||
@@ -63,8 +58,8 @@
|
||||
function endDrag(e: PointerEvent) {
|
||||
const el = e.currentTarget as HTMLElement
|
||||
el.releasePointerCapture(e.pointerId)
|
||||
dragging = null
|
||||
trimPreviewPath = null
|
||||
trimPreviewState.dragging = null
|
||||
trimPreviewState.path = null
|
||||
onAfterChange()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export function minTargetMB(seconds: number): number {
|
||||
const perSecBytes = seconds * 50_000
|
||||
const floorBytes = 50_000
|
||||
return Math.max(0.1, Math.max(floorBytes, perSecBytes) / 1_048_576)
|
||||
}
|
||||
|
||||
export function maxTargetMB(seconds: number): number {
|
||||
return Math.min(200, Math.max(10, seconds * 5))
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
export const trimPreviewState = $state<{
|
||||
dragging: "start" | "end" | null
|
||||
path: string | null
|
||||
bust: number
|
||||
}>({
|
||||
dragging: null,
|
||||
path: null,
|
||||
bust: 0,
|
||||
})
|
||||
|
||||
export function resetTrimPreview() {
|
||||
trimPreviewState.dragging = null
|
||||
trimPreviewState.path = null
|
||||
trimPreviewState.bust = 0
|
||||
}
|
||||
Reference in New Issue
Block a user