diff --git a/src/app/ui.ts b/src/app/ui.ts index 02e1338..9699ab2 100644 --- a/src/app/ui.ts +++ b/src/app/ui.ts @@ -63,6 +63,8 @@ const FPS_HINTS = { unreadable: 'not stored in this file; set it to match the video', user: 'set by you', } as const; +/** Frames moved by the outer transport buttons in frame-skip mode. */ +const SKIP_FRAMES = 6; /** How long a toast stays up. */ const TOAST_MS = 2600; /** @@ -145,6 +147,10 @@ export function createApp(deps: UiDeps): AppHandle { playIcon: must(doc, 'play-icon'), fwdFrame: must(doc, 'fwd-frame'), fwdSecond: must(doc, 'fwd-second'), + backSkipLabel: must(doc, 'back-skip-label'), + fwdSkipLabel: must(doc, 'fwd-skip-label'), + skipSeconds: must(doc, 'skip-seconds'), + skipFrames: must(doc, 'skip-frames'), grabBtn: must(doc, 'grab-btn'), rangeStartBtn: must(doc, 'range-start-btn'), rangeEndBtn: must(doc, 'range-end-btn'), @@ -222,6 +228,8 @@ export function createApp(deps: UiDeps): AppHandle { */ let fpsSource: 'default' | 'file' | 'unreadable' | 'user' = 'default'; let fpsVaries = false; + /** What the outer transport buttons move by; per session, reset with each video. */ + let skipUnit: 'seconds' | 'frames' = 'seconds'; const timers: TimerLike = deps.timers ?? { setTimeout: (handler, ms) => setTimeout(handler, ms), @@ -344,6 +352,7 @@ export function createApp(deps: UiDeps): AppHandle { el.qualityValue.textContent = `${Math.round(settings.quality * 100)}%`; el.fpsInput.value = formatFps(settings.fps); el.fpsHint.textContent = FPS_HINTS[fpsSource]; + renderSkipUnit(); el.intervalInput.value = String(settings.intervalSeconds); el.countInput.value = String(settings.frameCount); @@ -367,6 +376,23 @@ export function createApp(deps: UiDeps): AppHandle { renderPlanSummary(); } + function renderSkipUnit(): void { + const frames = skipUnit === 'frames'; + const unit = frames ? `${SKIP_FRAMES}f` : '1s'; + el.backSkipLabel.textContent = `−${unit}`; + el.fwdSkipLabel.textContent = `+${unit}`; + const spoken = frames ? `${SKIP_FRAMES} frames` : 'one second'; + el.backSecond.setAttribute('aria-label', `Back ${spoken}`); + el.fwdSecond.setAttribute('aria-label', `Forward ${spoken}`); + for (const [button, active] of [ + [el.skipSeconds, !frames], + [el.skipFrames, frames], + ] as const) { + button.classList.toggle('is-active', active); + button.setAttribute('aria-checked', active ? 'true' : 'false'); + } + } + /** Most frames one run may produce: the plan cap, or what's left of the gallery if less. */ function frameCap(): number { return Math.min(MAX_PLAN_FRAMES, Math.max(1, store.remainingCapacity)); @@ -588,6 +614,7 @@ export function createApp(deps: UiDeps): AppHandle { sourceUrl = deps.createObjectURL(file); baseName = sanitizeBaseName(file.name); videoKey = videoKeyFor(file); + skipUnit = 'seconds'; // Whatever was armed belonged to the old timeline. disarmDuplicate(); // A trim range and a detected crop are both properties of the clip they @@ -697,8 +724,23 @@ export function createApp(deps: UiDeps): AppHandle { setTime(Number(el.scrub.value)); }); - on(el.backSecond, 'click', () => setTime(video.currentTime - 1)); - on(el.fwdSecond, 'click', () => setTime(video.currentTime + 1)); + function skip(direction: -1 | 1): void { + setTime( + skipUnit === 'frames' + ? stepByFrames(video.currentTime, direction * SKIP_FRAMES, settings.fps, video.duration) + : video.currentTime + direction, + ); + } + on(el.backSecond, 'click', () => skip(-1)); + on(el.fwdSecond, 'click', () => skip(1)); + on(el.skipSeconds, 'click', () => { + skipUnit = 'seconds'; + renderSkipUnit(); + }); + on(el.skipFrames, 'click', () => { + skipUnit = 'frames'; + renderSkipUnit(); + }); on(el.backFrame, 'click', () => setTime(stepByFrames(video.currentTime, -1, settings.fps, video.duration)), ); diff --git a/src/index.html b/src/index.html index 7c2b8f7..b1d3467 100644 --- a/src/index.html +++ b/src/index.html @@ -99,7 +99,7 @@

Choose a video

@@ -123,6 +123,33 @@

Choose a video

Output settings
+
+
+ Skip buttons +
+ + +
+
+ +
+ +
+ + + + + +
+
+
+
Format
@@ -164,19 +191,6 @@

Choose a video

-
- -
- - - - - -
-
-
diff --git a/src/styles.css b/src/styles.css index 3b7c862..e1500f0 100644 --- a/src/styles.css +++ b/src/styles.css @@ -442,6 +442,15 @@ main { gap: 8px; } +.field-box { + display: flex; + flex-direction: column; + gap: var(--gap); + padding: var(--pad); + border: 1px solid var(--line); + border-radius: var(--radius); +} + .field__label { font-size: 15px; font-weight: 600; diff --git a/test/ui.test.ts b/test/ui.test.ts index a31a2a1..d1c65bb 100644 --- a/test/ui.test.ts +++ b/test/ui.test.ts @@ -249,6 +249,40 @@ describe('transport controls', () => { expect(video.currentTime).toBeCloseTo(0, 5); }); + it('swaps the outer buttons to 6-frame steps and back', () => { + const video = h.el('video'); + expect(h.el('fwd-skip-label').textContent).toBe('+1s'); + h.click('skip-frames'); + expect(h.el('back-skip-label').textContent).toBe('−6f'); + expect(h.el('fwd-skip-label').textContent).toBe('+6f'); + expect(h.el('skip-frames').getAttribute('aria-checked')).toBe('true'); + expect(h.el('skip-seconds').getAttribute('aria-checked')).toBe('false'); + h.click('fwd-second'); + expect(video.currentTime).toBeCloseTo(6 / 30, 5); + h.click('back-second'); + expect(video.currentTime).toBeCloseTo(0, 5); + h.click('skip-seconds'); + expect(h.el('fwd-skip-label').textContent).toBe('+1s'); + h.click('fwd-second'); + expect(h.el('scrub').value).toBe('1'); + }); + + it('follows the frame rate when stepping 6 frames', () => { + const video = h.el('video'); + h.click('skip-frames'); + const fps = h.el('fps-input'); + fps.value = '60'; + fps.dispatchEvent(new Event('change')); + h.click('fwd-second'); + expect(video.currentTime).toBeCloseTo(6 / 60, 5); + }); + + it('returns the outer buttons to 1 second when another video is loaded', async () => { + h.click('skip-frames'); + await h.loadVideo(); + expect(h.el('fwd-skip-label').textContent).toBe('+1s'); + }); + it('updates the read-out while scrubbing and stops fighting timeupdate', () => { const scrub = h.el('scrub'); scrub.value = '4.5';