trim dragging shows raw frame at current position for instant feedback, switches to compressed preview on release; gif preview now shows actual palette/dithering effects
This commit is contained in:
+22
-3
@@ -295,6 +295,8 @@
|
||||
// Trim drag
|
||||
let trackEl: HTMLDivElement | null = $state(null)
|
||||
let dragging: 'start' | 'end' | null = $state(null)
|
||||
let trimPreviewPath: string | null = $state(null)
|
||||
let trimPreviewBust: number = $state(0)
|
||||
|
||||
function pointerToSecs(e: PointerEvent): number {
|
||||
if (!trackEl || !clip) return 0
|
||||
@@ -304,10 +306,19 @@
|
||||
return ratio * clip.duration_secs
|
||||
}
|
||||
|
||||
async function updateTrimPreview(secs: number) {
|
||||
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) {
|
||||
@@ -318,12 +329,17 @@
|
||||
} 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) {
|
||||
@@ -516,10 +532,13 @@
|
||||
</div>
|
||||
|
||||
<!-- Preview -->
|
||||
{#if previewPath}
|
||||
{@const displayPath = dragging && trimPreviewPath ? trimPreviewPath : previewPath}
|
||||
{@const displayBust = dragging && trimPreviewPath ? trimPreviewBust : previewCacheBust}
|
||||
{#if displayPath}
|
||||
<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}
|
||||
<img src={convertFileSrc(displayPath) + "?t=" + displayBust} alt="preview frame" class="preview-img"/>
|
||||
{#if previewLoading && !dragging}<div class="preview-loading">rendering</div>{/if}
|
||||
{#if dragging}<div class="preview-loading">original</div>{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="preview-box empty">
|
||||
|
||||
Reference in New Issue
Block a user