Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions src/app/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand Down Expand Up @@ -145,6 +147,10 @@ export function createApp(deps: UiDeps): AppHandle {
playIcon: must<HTMLElement>(doc, 'play-icon'),
fwdFrame: must<HTMLButtonElement>(doc, 'fwd-frame'),
fwdSecond: must<HTMLButtonElement>(doc, 'fwd-second'),
backSkipLabel: must<HTMLElement>(doc, 'back-skip-label'),
fwdSkipLabel: must<HTMLElement>(doc, 'fwd-skip-label'),
skipSeconds: must<HTMLButtonElement>(doc, 'skip-seconds'),
skipFrames: must<HTMLButtonElement>(doc, 'skip-frames'),
grabBtn: must<HTMLButtonElement>(doc, 'grab-btn'),
rangeStartBtn: must<HTMLButtonElement>(doc, 'range-start-btn'),
rangeEndBtn: must<HTMLButtonElement>(doc, 'range-end-btn'),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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);

Expand All @@ -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));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)),
);
Expand Down
44 changes: 29 additions & 15 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ <h2 class="empty__title" id="empty-title">Choose a video</h2>
<!-- Transport: big, evenly spread, thumb-reachable -->
<div class="transport" role="group" aria-label="Playback controls">
<button type="button" class="btn btn--icon" id="back-second" aria-label="Back one second">
<span aria-hidden="true">−1s</span>
<span aria-hidden="true" id="back-skip-label">−1s</span>
</button>
<button type="button" class="btn btn--icon" id="back-frame" aria-label="Previous frame">
<span aria-hidden="true">◀|</span>
Expand All @@ -111,7 +111,7 @@ <h2 class="empty__title" id="empty-title">Choose a video</h2>
<span aria-hidden="true">|▶</span>
</button>
<button type="button" class="btn btn--icon" id="fwd-second" aria-label="Forward one second">
<span aria-hidden="true">+1s</span>
<span aria-hidden="true" id="fwd-skip-label">+1s</span>
</button>
</div>

Expand All @@ -123,6 +123,33 @@ <h2 class="empty__title" id="empty-title">Choose a video</h2>
<details class="panel" id="settings-panel" open>
<summary class="panel__summary">Output settings</summary>
<div class="panel__body">
<div class="field-box">
<div class="field">
<span class="field__label" id="skip-label">Skip buttons</span>
<div class="segmented" role="radiogroup" aria-labelledby="skip-label">
<button type="button" class="segmented__btn is-active" id="skip-seconds" role="radio" aria-checked="true">
1 second
</button>
<button type="button" class="segmented__btn" id="skip-frames" role="radio" aria-checked="false">
6 frames
</button>
</div>
</div>

<div class="field">
<label class="field__label" for="fps-input">
Frame rate <span class="field__hint" id="fps-hint">used by the frame-step buttons</span>
</label>
<div class="stepper stepper--fps">
<button type="button" class="stepper__btn" id="fps-prev-std" aria-label="Previous standard frame rate">«</button>
<button type="button" class="stepper__btn" id="fps-minus" aria-label="Lower frame rate">−</button>
<input type="text" inputmode="decimal" id="fps-input" class="stepper__input" value="30" />
<button type="button" class="stepper__btn" id="fps-plus" aria-label="Raise frame rate">+</button>
<button type="button" class="stepper__btn" id="fps-next-std" aria-label="Next standard frame rate">»</button>
</div>
</div>
</div>

<div class="field">
<span class="field__label" id="format-label">Format</span>
<div class="segmented" role="radiogroup" aria-labelledby="format-label" id="format-group"></div>
Expand Down Expand Up @@ -164,19 +191,6 @@ <h2 class="empty__title" id="empty-title">Choose a video</h2>
</div>
</div>

<div class="field">
<label class="field__label" for="fps-input">
Frame rate <span class="field__hint" id="fps-hint">used by the frame-step buttons</span>
</label>
<div class="stepper stepper--fps">
<button type="button" class="stepper__btn" id="fps-prev-std" aria-label="Previous standard frame rate">«</button>
<button type="button" class="stepper__btn" id="fps-minus" aria-label="Lower frame rate">−</button>
<input type="text" inputmode="decimal" id="fps-input" class="stepper__input" value="30" />
<button type="button" class="stepper__btn" id="fps-plus" aria-label="Raise frame rate">+</button>
<button type="button" class="stepper__btn" id="fps-next-std" aria-label="Next standard frame rate">»</button>
</div>
</div>

<button type="button" class="btn btn--ghost" id="change-video">Use a different video</button>
</div>
</details>
Expand Down
9 changes: 9 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 34 additions & 0 deletions test/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLVideoElement>('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<HTMLInputElement>('scrub').value).toBe('1');
});

it('follows the frame rate when stepping 6 frames', () => {
const video = h.el<HTMLVideoElement>('video');
h.click('skip-frames');
const fps = h.el<HTMLInputElement>('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<HTMLInputElement>('scrub');
scrub.value = '4.5';
Expand Down
Loading