add mouse flicks to the gif filmstrip
This commit is contained in:
@@ -1146,9 +1146,14 @@ pub(crate) fn extract_thumbnails(
|
|||||||
drop(std::fs::remove_file(extra));
|
drop(std::fs::remove_file(extra));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Keep both sides of a page boundary available while scrolling.
|
||||||
for entry in std::fs::read_dir(out_dir)?.flatten() {
|
for entry in std::fs::read_dir(out_dir)?.flatten() {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
if path != page_dir && entry.file_type().is_ok_and(|kind| kind.is_dir()) {
|
let name = entry.file_name();
|
||||||
|
let nearby = name.to_str().and_then(|name| name.split_once('-'))
|
||||||
|
.and_then(|(rate, offset)| Some((rate.parse::<u32>().ok()?, offset.parse::<u32>().ok()?)))
|
||||||
|
.is_some_and(|(rate, offset)| rate == fps && offset.abs_diff(start) <= PAGE_SIZE as u32 * 2);
|
||||||
|
if !nearby && entry.file_type().is_ok_and(|kind| kind.is_dir()) {
|
||||||
drop(std::fs::remove_dir_all(path));
|
drop(std::fs::remove_dir_all(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+159
-71
@@ -2,36 +2,65 @@
|
|||||||
import { gsap } from "gsap"
|
import { gsap } from "gsap"
|
||||||
import { untrack } from "svelte"
|
import { untrack } from "svelte"
|
||||||
import type { Action } from "svelte/action"
|
import type { Action } from "svelte/action"
|
||||||
|
import { SvelteMap } from "svelte/reactivity"
|
||||||
import { api, convertFileSrc, type SourceRange } from "./api"
|
import { api, convertFileSrc, type SourceRange } from "./api"
|
||||||
import { clipRanges, mergeRanges, rangesDuration, subtractRanges } from "./gifFrames"
|
import { clipRanges, mergeRanges, rangesDuration, subtractRanges } from "./gifFrames"
|
||||||
import { IconArrowLeft, IconArrowRight, IconCheck, IconChevronDown, IconMinus, IconScissors } from "./ui/icons"
|
import { IconArrowLeft, IconArrowRight, IconCheck, IconChevronDown, IconMinus, IconScissors } from "./ui/icons"
|
||||||
|
import { kineticFilmstrip, type FilmstripView } from "./ui/kineticFilmstrip"
|
||||||
import { animate, bound, disclosure, fadeMotion, timecode } from "./ui/motion"
|
import { animate, bound, disclosure, fadeMotion, timecode } from "./ui/motion"
|
||||||
|
|
||||||
import { scrollbar } from "./ui/scrollbar"
|
let { fps, playhead, seekRequest, trimStart, trimEnd, removed = $bindable(), disabled, onSeek, onScrub }: {
|
||||||
|
|
||||||
let { fps, playhead, trimStart, trimEnd, removed = $bindable(), disabled, onSeek }: {
|
|
||||||
fps: number; playhead: number; trimStart: number; trimEnd: number; removed: SourceRange[]
|
fps: number; playhead: number; trimStart: number; trimEnd: number; removed: SourceRange[]
|
||||||
disabled: boolean; onSeek: (seconds: number) => void
|
seekRequest: { seconds: number } | null; disabled: boolean; onSeek: (seconds: number) => void
|
||||||
|
onScrub: (seconds: number) => void
|
||||||
} = $props()
|
} = $props()
|
||||||
|
|
||||||
const pageSize = 80
|
const pageSize = 80
|
||||||
|
const pageAhead = 24
|
||||||
|
const overscan = 3
|
||||||
|
const mapCells = 30
|
||||||
|
const frameWidth = 79
|
||||||
|
const gap = 7
|
||||||
|
const inset = 7
|
||||||
|
const stride = frameWidth + gap
|
||||||
const panelId = $props.id()
|
const panelId = $props.id()
|
||||||
|
const pages = new SvelteMap<number, string[]>()
|
||||||
|
const errors = new SvelteMap<number, string>()
|
||||||
let open = $state(false)
|
let open = $state(false)
|
||||||
let strip = $state<HTMLDivElement>()
|
let host: HTMLDivElement | undefined = $state()
|
||||||
let chevron = $state<HTMLElement>()
|
let strip: HTMLDivElement | undefined = $state()
|
||||||
let page = $state<{ start: number; fps: number; paths: string[] }>()
|
let track: HTMLDivElement | undefined = $state()
|
||||||
let failure = $state("")
|
let scroller: ReturnType<typeof kineticFilmstrip> | undefined = $state.raw()
|
||||||
let retry = $state(0)
|
let view = $state.raw<FilmstripView>({ first: 0, last: 0, before: false, after: false })
|
||||||
|
let chevron: HTMLElement | undefined = $state()
|
||||||
|
let loading = $state(false)
|
||||||
let selected = $state<SourceRange[]>([])
|
let selected = $state<SourceRange[]>([])
|
||||||
let anchor: number | null = null
|
let anchor: number | null = null
|
||||||
let focusFrame = $state<number>()
|
let focusFrame = $state<number>()
|
||||||
let queue = Promise.resolve()
|
|
||||||
|
|
||||||
let firstFrame = $derived(Math.floor(trimStart * fps + 0.000_001))
|
let firstFrame = $derived(Math.floor(trimStart * fps + 0.000_001))
|
||||||
let lastFrame = $derived(Math.max(firstFrame, Math.ceil(trimEnd * fps - 0.000_001) - 1))
|
let lastFrame = $derived(Math.max(firstFrame, Math.ceil(trimEnd * fps - 0.000_001) - 1))
|
||||||
|
let frameCount = $derived(lastFrame - firstFrame + 1)
|
||||||
let activeFrame = $derived(bound(Math.floor(playhead * fps + 0.000_001), firstFrame, lastFrame))
|
let activeFrame = $derived(bound(Math.floor(playhead * fps + 0.000_001), firstFrame, lastFrame))
|
||||||
let start = $derived(Math.floor(activeFrame / pageSize) * pageSize)
|
let shownFirst = $derived(firstFrame + bound(view.first, 0, frameCount - 1))
|
||||||
let visiblePage = $derived(page?.start === start && page?.fps === fps ? page : undefined)
|
let shownLast = $derived(firstFrame + bound(view.last, 0, frameCount - 1))
|
||||||
|
let tabFrame = $derived(bound(activeFrame, shownFirst, shownLast))
|
||||||
|
let visibleFrames = $derived.by(() => {
|
||||||
|
const from = Math.max(firstFrame, shownFirst - overscan)
|
||||||
|
const to = Math.min(lastFrame, shownLast + overscan)
|
||||||
|
return Array.from({ length: to - from + 1 }, (_, index) => from + index)
|
||||||
|
})
|
||||||
|
let wantedPages = $derived.by(() => {
|
||||||
|
const from = pageStart(Math.max(firstFrame, shownFirst - pageAhead))
|
||||||
|
const to = pageStart(Math.min(lastFrame, shownLast + pageAhead))
|
||||||
|
const center = (shownFirst + shownLast) / 2
|
||||||
|
const distance = (start: number) => Math.abs(center - bound(center, start, start + pageSize - 1))
|
||||||
|
return Array.from({ length: (to - from) / pageSize + 1 }, (_, index) => from + index * pageSize)
|
||||||
|
.sort((a, b) => distance(a) - distance(b))
|
||||||
|
})
|
||||||
|
let failedPage = $derived(wantedPages.find(start =>
|
||||||
|
start <= shownLast && start + pageSize > shownFirst && errors.has(start)))
|
||||||
|
let viewportLabel = $derived(`Frames ${shownFirst - firstFrame + 1}-${shownLast - firstFrame + 1} of ${frameCount}`)
|
||||||
let activeSelection = $derived(clipRanges(selected, trimStart, trimEnd))
|
let activeSelection = $derived(clipRanges(selected, trimStart, trimEnd))
|
||||||
let selectedCount = $derived.by(() => activeSelection.reduce((total, range) =>
|
let selectedCount = $derived.by(() => activeSelection.reduce((total, range) =>
|
||||||
total + Math.ceil(range.end_secs * fps - 0.000_001) - Math.floor(range.start_secs * fps + 0.000_001), 0))
|
total + Math.ceil(range.end_secs * fps - 0.000_001) - Math.floor(range.start_secs * fps + 0.000_001), 0))
|
||||||
@@ -41,6 +70,10 @@
|
|||||||
let keepsFrames = $derived(trimEnd - trimStart - rangesDuration(clipRanges(nextCuts, trimStart, trimEnd)) > .01)
|
let keepsFrames = $derived(trimEnd - trimStart - rangesDuration(clipRanges(nextCuts, trimStart, trimEnd)) > .01)
|
||||||
let canRestore = $derived(activeSelection.some(range => coverage(removed, range) > 0))
|
let canRestore = $derived(activeSelection.some(range => coverage(removed, range) > 0))
|
||||||
|
|
||||||
|
function pageStart(frame: number) {
|
||||||
|
return Math.floor(frame / pageSize) * pageSize
|
||||||
|
}
|
||||||
|
|
||||||
function coverage(ranges: SourceRange[], range: SourceRange) {
|
function coverage(ranges: SourceRange[], range: SourceRange) {
|
||||||
const length = range.end_secs - range.start_secs
|
const length = range.end_secs - range.start_secs
|
||||||
return length > 0 ? bound(rangesDuration(clipRanges(ranges, range.start_secs, range.end_secs)) / length, 0, 1) : 0
|
return length > 0 ? bound(rangesDuration(clipRanges(ranges, range.start_secs, range.end_secs)) / length, 0, 1) : 0
|
||||||
@@ -80,6 +113,7 @@
|
|||||||
const next = event.key === "Home" ? firstFrame : event.key === "End" ? lastFrame
|
const next = event.key === "Home" ? firstFrame : event.key === "End" ? lastFrame
|
||||||
: bound(frame + (event.key === "ArrowRight" ? 1 : -1), firstFrame, lastFrame)
|
: bound(frame + (event.key === "ArrowRight" ? 1 : -1), firstFrame, lastFrame)
|
||||||
if (next === frame) return
|
if (next === frame) return
|
||||||
|
scroller?.reveal(next - firstFrame)
|
||||||
focusFrame = next
|
focusFrame = next
|
||||||
choose(next, event.shiftKey, event.ctrlKey || event.metaKey)
|
choose(next, event.shiftKey, event.ctrlKey || event.metaKey)
|
||||||
} else if (event.key === "Delete") {
|
} else if (event.key === "Delete") {
|
||||||
@@ -103,38 +137,63 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
void fps
|
if (!host || !strip || !track) return
|
||||||
untrack(() => { selected = []; anchor = null })
|
const controller = kineticFilmstrip(host, strip, track, {
|
||||||
})
|
stride, gap, inset,
|
||||||
|
onView: next => { view = next },
|
||||||
$effect(() => {
|
onScrub: index => { onScrub(Math.max(trimStart, (firstFrame + index) / fps)) },
|
||||||
void retry
|
|
||||||
const offset = start
|
|
||||||
const rate = fps
|
|
||||||
if (!open || visiblePage) return
|
|
||||||
let current = true
|
|
||||||
failure = ""
|
|
||||||
queue = queue.then(async () => {
|
|
||||||
if (!current) return
|
|
||||||
try {
|
|
||||||
const result = await api.extractThumbnails(rate, offset)
|
|
||||||
if (current) page = { start: offset, fps: rate, paths: result.paths }
|
|
||||||
} catch (error) {
|
|
||||||
if (current) failure = String(error)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
return () => { current = false }
|
scroller = controller
|
||||||
|
return () => controller.destroy()
|
||||||
})
|
})
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const frame = activeFrame
|
void fps
|
||||||
if (!open || !strip || !visiblePage) return
|
untrack(() => {
|
||||||
const item = strip.querySelector<HTMLElement>("[data-frame='" + frame + "']")
|
pages.clear()
|
||||||
if (!item) return
|
errors.clear()
|
||||||
if (focusFrame === frame) { item.focus({ preventScroll: true }); focusFrame = undefined }
|
selected = []
|
||||||
if (item.offsetLeft < strip.scrollLeft || item.offsetLeft + item.offsetWidth > strip.scrollLeft + strip.clientWidth) {
|
anchor = null
|
||||||
animate(strip, { scrollLeft: Math.max(0, item.offsetLeft - (strip.clientWidth - item.offsetWidth) / 2) })
|
focusFrame = undefined
|
||||||
}
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
const controller = scroller
|
||||||
|
const count = frameCount
|
||||||
|
const first = firstFrame
|
||||||
|
const rate = fps
|
||||||
|
if (open && controller) untrack(() => controller.setRange(count, bound(Math.floor(playhead * rate + .000_001) - first, 0, count - 1)))
|
||||||
|
})
|
||||||
|
|
||||||
|
$effect(() => scroller?.setEnabled(open && !disabled))
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
const request = seekRequest
|
||||||
|
if (request && scroller) untrack(() => {
|
||||||
|
if (open) scroller?.reveal(bound(Math.floor(request.seconds * fps + .000_001) - firstFrame, 0, frameCount - 1))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (!open || !scroller || loading) return
|
||||||
|
const start = wantedPages.find(start => !pages.has(start) && !errors.has(start))
|
||||||
|
if (start === undefined) return
|
||||||
|
const rate = fps
|
||||||
|
loading = true
|
||||||
|
api.extractThumbnails(rate, start).then(result => {
|
||||||
|
// The backend removes files outside this window.
|
||||||
|
for (const other of pages.keys()) if (Math.abs(other - start) > pageSize * 2) pages.delete(other)
|
||||||
|
if (fps === rate) pages.set(start, result.paths)
|
||||||
|
}).catch(error => {
|
||||||
|
if (fps === rate) errors.set(start, String(error))
|
||||||
|
}).finally(() => { loading = false })
|
||||||
|
})
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (!open || focusFrame === undefined) return
|
||||||
|
strip?.querySelector<HTMLElement>("[data-frame='" + focusFrame + "']")?.focus({ preventScroll: true })
|
||||||
|
focusFrame = undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
type FrameState = { selected: boolean; removed: number; active: boolean }
|
type FrameState = { selected: boolean; removed: number; active: boolean }
|
||||||
@@ -160,25 +219,23 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<div class="disclosure-body" id={panelId} inert={!open}>
|
<div class="disclosure-body" id={panelId} inert={!open}>
|
||||||
<div class="frame-content stack">
|
<div class="frame-content stack">
|
||||||
<div class="row between wrap">
|
<p class="note">Drag or scroll to browse. Click to inspect, Shift-click for a range, or Ctrl-click to toggle individual frames.</p>
|
||||||
<p class="note">Click to inspect. Shift-click for a range, Ctrl-click to toggle individual frames.</p>
|
<div class="thumbnail-scroll" bind:this={host}>
|
||||||
<div class="row">
|
<span class="strip-side" aria-hidden="true">
|
||||||
<button type="button" class="button ghost icon-only" aria-label="Previous frames" disabled={disabled || start <= firstFrame}
|
{#if view.before}<span class="more" transition:fadeMotion><IconArrowLeft size={16} /></span>
|
||||||
onclick={() => seek(Math.max(firstFrame, start - 1))}><IconArrowLeft size={16} /></button>
|
{:else}<span class="endstop" transition:fadeMotion>Start</span>{/if}
|
||||||
<button type="button" class="button ghost icon-only" aria-label="Next frames" disabled={disabled || start + pageSize > lastFrame}
|
</span>
|
||||||
onclick={() => seek(start + pageSize)}><IconArrowRight size={16} /></button>
|
<div class="strip" bind:this={strip} role="group" aria-label="GIF frames" style:--frame-width={frameWidth + "px"}>
|
||||||
</div>
|
<div class="track" bind:this={track}>
|
||||||
</div>
|
{#if open}
|
||||||
<div class="thumbnail-scroll">
|
{#each visibleFrames as frame (frame)}
|
||||||
<div class="strip" bind:this={strip} use:scrollbar={"x"} role="group" aria-label="GIF frames" aria-busy={!visiblePage && !failure}>
|
{@const start = pageStart(frame)}
|
||||||
{#if open && visiblePage}
|
{@const path = pages.get(start)?.[frame - start]}
|
||||||
{#each visiblePage.paths as path, index (index)}
|
|
||||||
{@const frame = visiblePage.start + index}
|
|
||||||
{@const interval = span(frame)}
|
{@const interval = span(frame)}
|
||||||
{#if frame >= firstFrame && frame <= lastFrame}
|
{@const cut = coverage(removed, interval)}
|
||||||
{@const cut = coverage(removed, interval)}
|
{@const picked = coverage(activeSelection, interval) > 0}
|
||||||
{@const picked = coverage(activeSelection, interval) > 0}
|
<button type="button" class="button thumb" data-frame={frame} tabindex={frame === tabFrame ? 0 : -1}
|
||||||
<button type="button" class="button thumb" data-frame={frame} tabindex={frame === activeFrame ? 0 : -1}
|
style:left={inset + (frame - firstFrame) * stride + "px"}
|
||||||
use:frameMotion={{ selected: picked, removed: cut > 0 ? Math.max(.65, cut) : 0, active: frame === activeFrame }}
|
use:frameMotion={{ selected: picked, removed: cut > 0 ? Math.max(.65, cut) : 0, active: frame === activeFrame }}
|
||||||
{disabled} aria-pressed={picked}
|
{disabled} aria-pressed={picked}
|
||||||
aria-label={"Frame " + (frame + 1) + " at " + timecode(frame / fps) + (cut > .999 ? ", removed" : cut > 0 ? ", partly removed" : "")}
|
aria-label={"Frame " + (frame + 1) + " at " + timecode(frame / fps) + (cut > .999 ? ", removed" : cut > 0 ? ", partly removed" : "")}
|
||||||
@@ -189,18 +246,30 @@
|
|||||||
</div>
|
</div>
|
||||||
<span class="mono timestamp">{timecode(frame / fps)}</span>
|
<span class="mono timestamp">{timecode(frame / fps)}</span>
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
|
||||||
{/each}
|
{/each}
|
||||||
{:else if failure}
|
{/if}
|
||||||
<div class="row between wrap">
|
</div>
|
||||||
<p class="note selectable" role="alert">{failure}</p>
|
|
||||||
<button type="button" class="button" onclick={() => retry++}>Retry thumbnails</button>
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<p class="note">Loading frames...</p>
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
|
<span class="strip-side" aria-hidden="true">
|
||||||
|
{#if view.after}<span class="more" transition:fadeMotion><IconArrowRight size={16} /></span>
|
||||||
|
{:else}<span class="endstop" transition:fadeMotion>End</span>{/if}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="viewport-overview">
|
||||||
|
<div class="minimap" aria-hidden="true">
|
||||||
|
{#each Array(mapCells) as _, index (index)}
|
||||||
|
<span class:in-view={index >= Math.floor((shownFirst - firstFrame) * mapCells / frameCount)
|
||||||
|
&& index < Math.ceil((shownLast - firstFrame + 1) * mapCells / frameCount)}></span>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
<span class="mono note">{viewportLabel}</span>
|
||||||
|
</div>
|
||||||
|
{#if failedPage !== undefined}
|
||||||
|
<div class="row between wrap thumbnail-error" transition:fadeMotion>
|
||||||
|
<p class="note selectable" role="alert">{errors.get(failedPage)}</p>
|
||||||
|
<button type="button" class="button" onclick={() => { if (failedPage !== undefined) errors.delete(failedPage) }}>Retry thumbnails</button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
<div class="row between wrap">
|
<div class="row between wrap">
|
||||||
<p class="note" aria-live="polite">{selectedCount ? selectedCount + (selectedCount === 1 ? " frame selected" : " frames selected") : "Select frames to remove or restore."}</p>
|
<p class="note" aria-live="polite">{selectedCount ? selectedCount + (selectedCount === 1 ? " frame selected" : " frames selected") : "Select frames to remove or restore."}</p>
|
||||||
<div class="row wrap">
|
<div class="row wrap">
|
||||||
@@ -222,15 +291,34 @@
|
|||||||
.chevron { display:grid; place-items:center; color:var(--muted); }
|
.chevron { display:grid; place-items:center; color:var(--muted); }
|
||||||
.frame-content { min-width:0; padding-top:12px; }
|
.frame-content { min-width:0; padding-top:12px; }
|
||||||
.frame-content .button { min-height:32px; font-size:12px; }
|
.frame-content .button { min-height:32px; font-size:12px; }
|
||||||
.thumbnail-scroll { position:relative; min-width:0; }
|
.thumbnail-scroll { display:grid; grid-template-columns:32px minmax(0,1fr) 32px; min-width:0; align-items:stretch; border-radius:var(--control-radius); background:var(--input); }
|
||||||
.strip { position:relative; display:flex; gap:7px; overflow:auto hidden; min-height:91px; padding:5px 5px 14px; }
|
.strip { position:relative; height:83px; overflow:clip; }
|
||||||
.thumb { display:grid; flex:0 0 79px; align-content:start; gap:0; padding:0; border-radius:6px; background:var(--caption);
|
.strip-side { display:grid; place-items:center; border-inline-end:1px solid var(--rule); color:var(--muted); }
|
||||||
|
.strip-side:last-child { border:0; border-inline-start:1px solid var(--rule); }
|
||||||
|
.strip-side > span { grid-area:1 / 1; }
|
||||||
|
.more { display:grid; place-items:center; color:var(--copy); }
|
||||||
|
.endstop { font:500 9px/1.2 var(--mono); }
|
||||||
|
.track { position:absolute; inset:0; }
|
||||||
|
.thumb { position:absolute; top:7px; width:var(--frame-width); height:69px; display:grid; align-content:start; gap:0; min-width:0; padding:0; overflow:hidden; border-radius:6px; background:var(--caption);
|
||||||
box-shadow:inset 0 0 0 2px color-mix(in srgb,transparent,var(--signal) calc(var(--selected,0) * 100%)); }
|
box-shadow:inset 0 0 0 2px color-mix(in srgb,transparent,var(--signal) calc(var(--selected,0) * 100%)); }
|
||||||
.thumbnail { position:relative; width:75px; height:45px; margin:2px 2px 0; border-radius:3px; background:var(--raised); }
|
.thumbnail-scroll:global([data-scrollable="true"]) { cursor:grab; }
|
||||||
|
.thumbnail-scroll:global([data-scrollable="true"]) .thumb:not(:disabled) { cursor:grab; }
|
||||||
|
.thumbnail-scroll:global([data-dragging]), .thumbnail-scroll:global([data-dragging]) .thumb:not(:disabled) { cursor:grabbing; }
|
||||||
|
.thumbnail { position:relative; width:calc(var(--frame-width) - 4px); height:45px; margin:2px 2px 0; border-radius:3px; background:var(--raised); }
|
||||||
.thumbnail img { display:block; width:100%; height:45px; object-fit:cover; border-radius:3px; filter:grayscale(var(--removed,0)) brightness(calc(1 - var(--removed,0) * .48)); }
|
.thumbnail img { display:block; width:100%; height:45px; object-fit:cover; border-radius:3px; filter:grayscale(var(--removed,0)) brightness(calc(1 - var(--removed,0) * .48)); }
|
||||||
.thumbnail span { position:absolute; top:3px; width:17px; height:17px; display:grid; place-items:center; border-radius:3px; }
|
.thumbnail span { position:absolute; top:3px; width:17px; height:17px; display:grid; place-items:center; border-radius:3px; }
|
||||||
.omitted { left:3px; background:var(--alert); color:var(--alert-ink); opacity:var(--removed,0); }
|
.omitted { left:3px; background:var(--alert); color:var(--alert-ink); opacity:var(--removed,0); }
|
||||||
.picked { right:3px; background:var(--signal); color:var(--signal-ink); opacity:var(--selected,0); }
|
.picked { right:3px; background:var(--signal); color:var(--signal-ink); opacity:var(--selected,0); }
|
||||||
.timestamp { padding:3px 1px; color:color-mix(in srgb,var(--muted),var(--ink) calc(var(--active,0) * 100%)); }
|
.timestamp { padding:3px 1px; color:color-mix(in srgb,var(--muted),var(--ink) calc(var(--active,0) * 100%)); }
|
||||||
.thumb:focus-visible { outline-offset:1px; }
|
.thumb:focus-visible { outline-offset:1px; }
|
||||||
|
.viewport-overview { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-top:-4px; pointer-events:none; }
|
||||||
|
.minimap { flex:1 1 auto; min-width:0; padding-inline:3px; display:grid; grid-template-columns:repeat(30,minmax(0,1fr)); gap:3px; }
|
||||||
|
.minimap span { height:6px; border-radius:1px; background:var(--rule); }
|
||||||
|
.minimap span.in-view { background:var(--muted); }
|
||||||
|
.viewport-overview .note { font:500 11px/1.3 var(--mono); white-space:nowrap; }
|
||||||
|
.thumbnail-error { overflow-wrap:anywhere; }
|
||||||
|
@media (forced-colors: active) {
|
||||||
|
.minimap span { background:GrayText; forced-color-adjust:none; }
|
||||||
|
.minimap span.in-view { background:Highlight; }
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
+5
-5
@@ -66,7 +66,7 @@
|
|||||||
let previewLoading = $state(false)
|
let previewLoading = $state(false)
|
||||||
let previewCanceling = $state(false)
|
let previewCanceling = $state(false)
|
||||||
let previewFailure = $state("")
|
let previewFailure = $state("")
|
||||||
let previewSeek = $state<{ seconds: number } | null>(null)
|
let previewSeek = $state<{ seconds: number; scrub: boolean } | null>(null)
|
||||||
let exportPending = $state(false)
|
let exportPending = $state(false)
|
||||||
let exportCanceling = $state(false)
|
let exportCanceling = $state(false)
|
||||||
let savingReviewed = $state(false)
|
let savingReviewed = $state(false)
|
||||||
@@ -512,9 +512,9 @@
|
|||||||
catch (e) { previewCanceling = false; errMsg = String(e) }
|
catch (e) { previewCanceling = false; errMsg = String(e) }
|
||||||
}
|
}
|
||||||
|
|
||||||
function seekPreview(seconds: number) {
|
function seekPreview(seconds: number, scrub = false) {
|
||||||
playhead = seconds
|
playhead = seconds
|
||||||
previewSeek = { seconds }
|
previewSeek = { seconds, scrub }
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeFormat(next: Format) {
|
function changeFormat(next: Format) {
|
||||||
@@ -815,8 +815,8 @@
|
|||||||
removals={format === "gif" ? removedFrames : []} onSeek={seekPreview}>
|
removals={format === "gif" ? removedFrames : []} onSeek={seekPreview}>
|
||||||
{#snippet gifFrames()}
|
{#snippet gifFrames()}
|
||||||
{#if format === "gif"}
|
{#if format === "gif"}
|
||||||
<FramesStrip {fps} {playhead} {trimStart} {trimEnd}
|
<FramesStrip {fps} {playhead} seekRequest={previewSeek?.scrub ? null : previewSeek} {trimStart} {trimEnd}
|
||||||
bind:removed={removedFrames} disabled={exportPending} onSeek={seekPreview} />
|
bind:removed={removedFrames} disabled={exportPending} onSeek={seekPreview} onScrub={seconds => seekPreview(seconds, true)} />
|
||||||
{/if}
|
{/if}
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</TrimPanel>
|
</TrimPanel>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
let { path, label, dimensions, seek = null, playbackRangeOnly = false, frameStep = .04,
|
let { path, label, dimensions, seek = null, playbackRangeOnly = false, frameStep = .04,
|
||||||
playhead = $bindable(0), trimStart, trimEnd, crop, onOpenFile }: {
|
playhead = $bindable(0), trimStart, trimEnd, crop, onOpenFile }: {
|
||||||
path: string; label: string; dimensions: string; seek?: { seconds: number } | null
|
path: string; label: string; dimensions: string; seek?: { seconds: number; scrub?: boolean } | null
|
||||||
playbackRangeOnly?: boolean; frameStep?: number
|
playbackRangeOnly?: boolean; frameStep?: number
|
||||||
playhead?: number; trimStart: number; trimEnd: number
|
playhead?: number; trimStart: number; trimEnd: number
|
||||||
crop?: CaptureRect & { imageWidth: number; imageHeight: number }
|
crop?: CaptureRect & { imageWidth: number; imageHeight: number }
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
if (!request) return
|
if (!request) return
|
||||||
untrack(() => {
|
untrack(() => {
|
||||||
pending = request
|
pending = request
|
||||||
if (player?.readyState) applySeek(player)
|
if (player?.readyState && (!request.scrub || !player.seeking)) applySeek(player)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -44,6 +44,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function finishSeek() {
|
||||||
|
if (!player || player.seeking) return
|
||||||
|
if (pending) applySeek(player)
|
||||||
|
else updateTime()
|
||||||
|
}
|
||||||
|
|
||||||
function metadata() {
|
function metadata() {
|
||||||
if (!player) return
|
if (!player) return
|
||||||
loadError = false
|
loadError = false
|
||||||
@@ -79,7 +85,7 @@
|
|||||||
<!-- svelte-ignore a11y_media_has_caption (A local user recording has no caption track.) -->
|
<!-- svelte-ignore a11y_media_has_caption (A local user recording has no caption track.) -->
|
||||||
<video src={convertFileSrc(path)} bind:this={player} preload="auto" playsinline aria-label={label}
|
<video src={convertFileSrc(path)} bind:this={player} preload="auto" playsinline aria-label={label}
|
||||||
{muted} onplay={() => playing = true} onpause={() => playing = false} onended={() => playing = false}
|
{muted} onplay={() => playing = true} onpause={() => playing = false} onended={() => playing = false}
|
||||||
ontimeupdate={updateTime} onloadedmetadata={metadata} onerror={() => { loadError = true; playing = false }}></video>
|
ontimeupdate={updateTime} onseeked={finishSeek} onloadedmetadata={metadata} onerror={() => { loadError = true; playing = false }}></video>
|
||||||
{#if crop}
|
{#if crop}
|
||||||
<span class="crop-guide" aria-hidden="true"
|
<span class="crop-guide" aria-hidden="true"
|
||||||
style:inset={crop.y / crop.imageHeight * 100 + "% " + (crop.imageWidth - crop.x - crop.width) / crop.imageWidth * 100 + "% " + (crop.imageHeight - crop.y - crop.height) / crop.imageHeight * 100 + "% " + crop.x / crop.imageWidth * 100 + "%"}></span>
|
style:inset={crop.y / crop.imageHeight * 100 + "% " + (crop.imageWidth - crop.x - crop.width) / crop.imageWidth * 100 + "% " + (crop.imageHeight - crop.y - crop.height) / crop.imageHeight * 100 + "% " + crop.x / crop.imageWidth * 100 + "%"}></span>
|
||||||
|
|||||||
@@ -0,0 +1,264 @@
|
|||||||
|
import { gsap } from "gsap"
|
||||||
|
import { bound, duration } from "./motion"
|
||||||
|
|
||||||
|
export type FilmstripView = { first: number; last: number; before: boolean; after: boolean }
|
||||||
|
|
||||||
|
const coastRate = -1000 * Math.log(.998)
|
||||||
|
const stopSpeed = 35
|
||||||
|
const sampleWindow = 90
|
||||||
|
const dragThreshold = 5
|
||||||
|
const rubberCoefficient = .55
|
||||||
|
const springRate = 15
|
||||||
|
|
||||||
|
export function kineticFilmstrip(
|
||||||
|
host: HTMLElement, viewport: HTMLElement, track: HTMLElement,
|
||||||
|
{ stride, gap, inset, onView, onScrub }: {
|
||||||
|
stride: number; gap: number; inset: number
|
||||||
|
onView: (view: FilmstripView) => void; onScrub: (frame: number) => void
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
let count = 0
|
||||||
|
let width = 0
|
||||||
|
let limit = 0
|
||||||
|
let position = 0
|
||||||
|
let enabled = false
|
||||||
|
let tween: gsap.core.Tween | undefined
|
||||||
|
let wheelTarget: number | undefined
|
||||||
|
let gestureOrigin: number | undefined
|
||||||
|
let scrubFrame: number | undefined
|
||||||
|
let drag: {
|
||||||
|
id: number; x: number; y: number; origin: number; started: boolean
|
||||||
|
samples: { x: number; time: number }[]
|
||||||
|
} | undefined
|
||||||
|
let suppressClick = false
|
||||||
|
const translate = gsap.quickSetter(track, "x", "px")
|
||||||
|
const events = new AbortController()
|
||||||
|
const { signal } = events
|
||||||
|
let view: FilmstripView | undefined
|
||||||
|
|
||||||
|
function frameAt(x: number) {
|
||||||
|
return bound(Math.floor((x - inset) / stride), 0, Math.max(0, count - 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
function paint(next: number) {
|
||||||
|
position = next
|
||||||
|
const offset = bound(next, 0, limit)
|
||||||
|
const excess = (next - offset) * rubberCoefficient
|
||||||
|
const distance = Math.min(74, width * .22)
|
||||||
|
const stretch = distance ? excess / (1 + Math.abs(excess) / distance) : 0
|
||||||
|
translate(-offset - stretch)
|
||||||
|
|
||||||
|
if (limit && gestureOrigin !== undefined && (scrubFrame !== undefined || Math.abs(offset - gestureOrigin) >= 1)) {
|
||||||
|
// Follow the clamped offset so the playhead stays inside the trim.
|
||||||
|
const frame = Math.round(offset / limit * (count - 1))
|
||||||
|
if (frame !== scrubFrame) {
|
||||||
|
scrubFrame = frame
|
||||||
|
onScrub(frame)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const first = frameAt(offset + gap)
|
||||||
|
const last = frameAt(offset + width - .5)
|
||||||
|
const before = limit > 0 && offset > inset + .5
|
||||||
|
const after = limit > 0 && offset < limit - inset - .5
|
||||||
|
if (view?.first === first && view.last === last && view.before === before && view.after === after) return
|
||||||
|
view = { first, last, before, after }
|
||||||
|
onView(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
function interrupt() {
|
||||||
|
tween?.kill()
|
||||||
|
tween = undefined
|
||||||
|
wheelTarget = undefined
|
||||||
|
gestureOrigin = undefined
|
||||||
|
scrubFrame = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function simulate(seconds: number, at: (elapsed: number) => number, complete: () => void) {
|
||||||
|
const clock = { elapsed: 0 }
|
||||||
|
tween = gsap.to(clock, {
|
||||||
|
elapsed: seconds, duration: seconds, ease: "none",
|
||||||
|
onUpdate: () => paint(at(clock.elapsed)), onComplete: complete,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function bounce(velocity = 0) {
|
||||||
|
const edge = bound(position, 0, limit)
|
||||||
|
const excess = position - edge
|
||||||
|
if (!limit || !duration() || (!excess && !velocity)) {
|
||||||
|
paint(edge)
|
||||||
|
interrupt()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Critically damped return. Keep the spring on the overscrolled side of the edge.
|
||||||
|
const outward = Math.sign(excess || velocity)
|
||||||
|
const speed = outward * bound(outward * velocity, -Math.abs(excess) * springRate, 3800)
|
||||||
|
simulate(.56, time => edge + (excess + (speed + springRate * excess) * time) * Math.exp(-springRate * time), () => {
|
||||||
|
paint(edge)
|
||||||
|
interrupt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function coast(velocity: number) {
|
||||||
|
if (position < 0 || position > limit) return bounce(velocity)
|
||||||
|
if (!duration() || Math.abs(velocity) < stopSpeed) return interrupt()
|
||||||
|
const start = position
|
||||||
|
const edge = velocity < 0 ? 0 : limit
|
||||||
|
const remaining = (edge - start) * coastRate / velocity
|
||||||
|
const hit = remaining < 1 ? -Math.log1p(-remaining) / coastRate : Infinity
|
||||||
|
const end = bound(Math.log(Math.abs(velocity) / stopSpeed) / coastRate, .5, 2)
|
||||||
|
const time = Math.min(hit, end)
|
||||||
|
const hitEdge = hit <= end
|
||||||
|
const finish = () => {
|
||||||
|
if (!hitEdge) return interrupt()
|
||||||
|
paint(edge)
|
||||||
|
bounce(velocity * Math.exp(-coastRate * hit) / rubberCoefficient)
|
||||||
|
}
|
||||||
|
if (time <= .001) return finish()
|
||||||
|
simulate(time, elapsed => start - velocity * Math.expm1(-coastRate * elapsed) / coastRate, finish)
|
||||||
|
}
|
||||||
|
|
||||||
|
function endDrag() {
|
||||||
|
const previous = drag
|
||||||
|
drag = undefined
|
||||||
|
delete host.dataset.dragging
|
||||||
|
if (previous && host.hasPointerCapture(previous.id)) host.releasePointerCapture(previous.id)
|
||||||
|
return previous
|
||||||
|
}
|
||||||
|
|
||||||
|
host.addEventListener("pointerdown", event => {
|
||||||
|
if (event.button !== 0 || event.pointerType !== "mouse") return
|
||||||
|
suppressClick = false
|
||||||
|
if (!enabled || !limit || drag) return
|
||||||
|
interrupt()
|
||||||
|
if (event.shiftKey || event.ctrlKey || event.metaKey) {
|
||||||
|
paint(bound(position, 0, limit))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
drag = { id: event.pointerId, x: event.clientX, y: event.clientY, origin: position, started: false,
|
||||||
|
samples: [{ x: event.clientX, time: event.timeStamp }] }
|
||||||
|
}, { signal })
|
||||||
|
|
||||||
|
window.addEventListener("pointermove", event => {
|
||||||
|
if (!drag || drag.id !== event.pointerId) return
|
||||||
|
const x = event.clientX
|
||||||
|
const delta = x - drag.x
|
||||||
|
if (!drag.started) {
|
||||||
|
if (Math.abs(delta) < dragThreshold || Math.abs(delta) < Math.abs(event.clientY - drag.y)) return
|
||||||
|
drag.started = true
|
||||||
|
suppressClick = true
|
||||||
|
gestureOrigin = bound(drag.origin, 0, limit)
|
||||||
|
host.setPointerCapture(event.pointerId)
|
||||||
|
host.dataset.dragging = ""
|
||||||
|
}
|
||||||
|
event.preventDefault()
|
||||||
|
const time = event.timeStamp
|
||||||
|
drag.samples.push({ x, time })
|
||||||
|
while (drag.samples.length > 2 && drag.samples[0].time < time - sampleWindow) drag.samples.shift()
|
||||||
|
const next = drag.origin - delta
|
||||||
|
paint(duration() ? next : bound(next, 0, limit))
|
||||||
|
}, { signal })
|
||||||
|
|
||||||
|
window.addEventListener("pointerup", event => {
|
||||||
|
if (drag?.id !== event.pointerId) return
|
||||||
|
const previous = endDrag()
|
||||||
|
if (!previous?.started) {
|
||||||
|
if (position !== bound(position, 0, limit)) bounce()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const first = previous.samples[0]
|
||||||
|
const last = previous.samples[previous.samples.length - 1]
|
||||||
|
const velocity = event.timeStamp - last.time < sampleWindow
|
||||||
|
? bound((first.x - last.x) * 1000 / Math.max(16, event.timeStamp - first.time), -3000, 3000) : 0
|
||||||
|
coast(velocity)
|
||||||
|
}, { signal })
|
||||||
|
|
||||||
|
function cancelDrag(event: PointerEvent) {
|
||||||
|
if (drag?.id !== event.pointerId) return
|
||||||
|
endDrag()
|
||||||
|
bounce()
|
||||||
|
}
|
||||||
|
window.addEventListener("pointercancel", cancelDrag, { signal })
|
||||||
|
host.addEventListener("lostpointercapture", cancelDrag, { signal })
|
||||||
|
host.addEventListener("click", event => {
|
||||||
|
if (!suppressClick || event.detail === 0) return
|
||||||
|
suppressClick = false
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
}, { capture: true, signal })
|
||||||
|
|
||||||
|
host.addEventListener("wheel", event => {
|
||||||
|
if (!enabled || !limit || !event.cancelable || event.ctrlKey || event.metaKey) return
|
||||||
|
const delta = Math.abs(event.deltaX) >= Math.abs(event.deltaY) ? event.deltaX : event.deltaY
|
||||||
|
if (!delta) return
|
||||||
|
event.preventDefault()
|
||||||
|
if (drag) return
|
||||||
|
const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? width : 1
|
||||||
|
const allowance = Math.min(125, width * .22)
|
||||||
|
gestureOrigin ??= bound(position, 0, limit)
|
||||||
|
const target = bound((wheelTarget ?? position) + delta * unit, -allowance, limit + allowance)
|
||||||
|
if (target === wheelTarget) return
|
||||||
|
tween?.kill()
|
||||||
|
wheelTarget = target
|
||||||
|
if (!duration()) {
|
||||||
|
paint(bound(target, 0, limit))
|
||||||
|
interrupt()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const offset = { x: position }
|
||||||
|
tween = gsap.to(offset, { x: target, duration: .5, ease: "power2.out",
|
||||||
|
onUpdate: () => paint(offset.x), onComplete: () => {
|
||||||
|
wheelTarget = undefined
|
||||||
|
bounce()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}, { passive: false, signal })
|
||||||
|
|
||||||
|
function measure() {
|
||||||
|
const next = viewport.clientWidth
|
||||||
|
if (!next) return
|
||||||
|
width = next
|
||||||
|
limit = Math.max(0, 2 * inset + count * stride - gap - width)
|
||||||
|
host.dataset.scrollable = String(limit > 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
const resize = new ResizeObserver(() => {
|
||||||
|
if (!viewport.clientWidth || viewport.clientWidth === width) return
|
||||||
|
interrupt()
|
||||||
|
endDrag()
|
||||||
|
measure()
|
||||||
|
paint(bound(position, 0, limit))
|
||||||
|
})
|
||||||
|
resize.observe(viewport)
|
||||||
|
|
||||||
|
return {
|
||||||
|
setRange(frames: number, center: number) {
|
||||||
|
interrupt()
|
||||||
|
endDrag()
|
||||||
|
count = frames
|
||||||
|
measure()
|
||||||
|
paint(bound(center * stride + inset + (stride - gap) / 2 - width / 2, 0, limit))
|
||||||
|
},
|
||||||
|
setEnabled(value: boolean) {
|
||||||
|
enabled = value
|
||||||
|
if (value) return
|
||||||
|
interrupt()
|
||||||
|
endDrag()
|
||||||
|
paint(bound(position, 0, limit))
|
||||||
|
},
|
||||||
|
reveal(index: number) {
|
||||||
|
const left = inset + index * stride
|
||||||
|
const right = left + stride - gap
|
||||||
|
if (!width || (left >= position && right <= position + width)) return
|
||||||
|
interrupt()
|
||||||
|
endDrag()
|
||||||
|
paint(bound(left < position ? left - inset : right + inset - width, 0, limit))
|
||||||
|
},
|
||||||
|
destroy() {
|
||||||
|
interrupt()
|
||||||
|
endDrag()
|
||||||
|
resize.disconnect()
|
||||||
|
events.abort()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user