Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(website): stabilize preview resizing and timeline spacing

EtienneLescotb60a519bdea2
diff --git a/website/src/components/Recreation/driver.ts b/website/src/components/Recreation/driver.ts
index 67c8a0279..6374e3894 100644
--- a/website/src/components/Recreation/driver.ts
+++ b/website/src/components/Recreation/driver.ts
@@ -23,9 +23,11 @@
*/
import { CURSORS } from "./generated";
+import { followHeight } from "./layout";
import { createPlayback, DOCK_VIEWPORTS, followDock } from "./playback";
import {
BEATS,
+ type BeatId,
CUT_INDEX,
type Frame,
frameAt,
@@ -107,6 +109,8 @@ const WRITTEN = [
"--card-height",
"--footage-fit",
"--column-h",
+ "--timeline-content-h",
+ "--timeline-bottom",
];
/** Piecewise-linear read of `[[t, ...values]]`, clamped at both ends. */
@@ -186,7 +190,10 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
const { band, root, cam, padValue, flow, pause } = refs;
const hero = document.querySelector<HTMLElement>("[data-home-hero]");
const card = root.querySelector<HTMLElement>("[data-composite]")!;
- const column = root.querySelector<HTMLElement>("[data-editor-column]")!;
+ const captions = root.querySelector<HTMLElement>("[data-cap]")!.parentElement!;
+ const panel = root.querySelector<HTMLElement>("[data-editor-panel]")!;
+ const palette = root.querySelector<HTMLElement>("[data-tool-palette]")!;
+ const timeline = root.querySelector<HTMLElement>("[data-editor-timeline]")!;
let raf = 0;
const sample = createPlayback(T_TOTAL);
let paused = false;
@@ -199,10 +206,19 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
let heroWidth = 1;
let dockWidth = 1;
let columnHeight = 1;
- let currentDock = 1;
+ const paneHeights = new Map<BeatId, number>();
+ let fullBoxHeight = 1;
+ let timelineHeight = 0;
+ let timelineInset = 0;
let smoothOffset = 0;
let lastTick: number | undefined;
+ const heightFor = (beat: BeatId | null, paletteOn: number, timelineOn: number) => {
+ if (paletteOn) return paneHeights.get("timeline") ?? columnHeight;
+ const settled = paneHeights.get(beat ?? "transcript") ?? columnHeight;
+ return Math.min(settled, fullBoxHeight - timelineOn * (timelineHeight + timelineInset));
+ };
+
/* ── the target cache ─────────────────────────────────────────────────── */
/**
@@ -272,9 +288,8 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
* pointer spends the whole ride a hundred pixels from everything it is
* meant to be clicking. That was the first defect this build shipped.
*
- * Opening each pane in turn is also the only correct way to do it: the panes
- * share one flow container, so showing them together would measure each one
- * stacked below the others.
+ * Open each pane in turn to read its settled height and target positions
+ * without including an outgoing pane's transition.
*/
/**
* Where the things the recorded pointer aims at actually are, in the frame's
@@ -398,31 +413,55 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
);
root.style.removeProperty("--card-height");
root.style.setProperty("--footage-fit", "1");
- for (const b of BEATS) {
- root.dataset.beat = b.id;
- // Opening the pane is not enough. Three of the frame's numbers place
- // boxes rather than paint them, and a beat measured with the wrong ones
- // is measured in the wrong place: --tl moves the panel and the
- // composite by the 151px between the two acts, and --panel and
- // --palette each hold their box at its entrance offset until they
- // finish arriving. The pointer wore all three.
- //
- // frameAt takes PROGRESS, not seconds: the rAF calls it as
- // frameAt(off / span). Handing it a midpoint in seconds asks for a
- // frame past the end of the scene, which answers with the closing act
- // for every beat, including the three that play in the opening one.
- const f = frameAt((b.from + b.to) / 2 / T_TOTAL);
- for (const g of GEOMETRY) root.style.setProperty(g.css, g.of(f).toFixed(3));
- root.style.setProperty("--column-h", `${column.offsetHeight}px`);
- if (b.id === "style") {
- heroWidth =
- window.innerWidth * (window.innerWidth > 900 ? 0.91 : 1) -
- (window.innerWidth > 900 ? 0 : 36);
- dockWidth = card.offsetWidth;
- previewScale = heroWidth / dockWidth;
+ const measurePanes = (withTargets: boolean) => {
+ for (const b of BEATS) {
+ root.dataset.beat = b.id;
+ // Opening the pane is not enough. Three of the frame's numbers place
+ // boxes rather than paint them, and a beat measured with the wrong ones
+ // is measured in the wrong place: --tl moves the panel and the
+ // composite by the 151px between the two acts, and --panel and
+ // --palette each hold their box at its entrance offset until they
+ // finish arriving. The pointer wore all three.
+ //
+ // frameAt takes PROGRESS, not seconds: the rAF calls it as
+ // frameAt(off / span). Handing it a midpoint in seconds asks for a
+ // frame past the end of the scene, which answers with the closing act
+ // for every beat, including the three that play in the opening one.
+ const f = frameAt((b.from + b.to) / 2 / T_TOTAL);
+ for (const g of GEOMETRY) root.style.setProperty(g.css, g.of(f).toFixed(3));
+ const paneHeight = f.palette
+ ? palette.getBoundingClientRect().height +
+ Number.parseFloat(getComputedStyle(palette).marginTop)
+ : panel.getBoundingClientRect().height;
+ const height = captions.offsetHeight + paneHeight;
+ paneHeights.set(b.id, height);
+ root.style.setProperty("--column-h", `${height}px`);
+ if (b.id === "style") {
+ fullBoxHeight =
+ captions.offsetHeight + Number.parseFloat(getComputedStyle(panel).maxHeight);
+ heroWidth =
+ window.innerWidth * (window.innerWidth > 900 ? 0.91 : 1) -
+ (window.innerWidth > 900 ? 0 : 36);
+ dockWidth = card.offsetWidth;
+ previewScale = heroWidth / dockWidth;
+ }
+ if (withTargets) measureVisible(claimed);
}
- measureVisible(claimed);
+ };
+ // Measure final panes, never their temporary combined cross-fade height.
+ // The largest closing pane sets one bottom inset for the entire tour.
+ root.style.setProperty("--timeline-bottom", "0px");
+ measurePanes(false);
+ if (window.innerWidth > 900) {
+ const closingHeight = Math.max(paneHeights.get("timeline")!, paneHeights.get("transcript")!);
+ root.style.setProperty("--timeline-content-h", `${closingHeight}px`);
+ } else {
+ root.style.removeProperty("--timeline-content-h");
}
+ root.style.removeProperty("--timeline-bottom");
+ timelineHeight = timeline.offsetHeight;
+ timelineInset = Number.parseFloat(getComputedStyle(timeline).bottom);
+ measurePanes(true);
if (had === undefined) delete root.dataset.beat;
else root.dataset.beat = had;
for (const [css, was] of [...kept, ...layoutKept]) {
@@ -445,9 +484,16 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
measureShots();
delete root.dataset.measuring;
if (window.innerWidth > 900) {
- columnHeight = column.getBoundingClientRect().height;
+ columnHeight = heightFor(
+ (had as BeatId | undefined) ?? "style",
+ Number(root.style.getPropertyValue("--palette")),
+ Number(root.style.getPropertyValue("--tl")),
+ );
root.style.setProperty("--column-h", `${columnHeight}px`);
+ } else {
+ root.style.removeProperty("--column-h");
}
+ fitCard(Number(root.style.getPropertyValue("--dock")));
};
const at = (name: string, fx = 20, fy = 45): [number, number] => {
@@ -612,7 +658,6 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
};
const apply = (f: Frame, dock: number, phase: string) => {
- currentDock = dock;
num("--dock", dock);
fitCard(dock);
// Keep the first-screen picture in viewport space while it docks. The
@@ -724,10 +769,9 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
};
const tick = (now: number) => {
raf = 0;
+ const elapsed = lastTick === undefined ? 0 : now - lastTick;
smoothOffset =
- lastTick === undefined
- ? offset
- : followDock(smoothOffset, offset, now - lastTick, dockDistance);
+ lastTick === undefined ? offset : followDock(smoothOffset, offset, elapsed, dockDistance);
lastTick = now;
const following = smoothOffset !== offset;
const playing = visible && !paused && !document.hidden;
@@ -739,12 +783,19 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
phase === "editor"
? scored
: { ...scored, tl: 0, beat: "style" as const, panel: 1, intro: 1, palette: 0 };
+ let resizing = false;
+ if (window.innerWidth > 900) {
+ const target = heightFor(frame.beat, frame.palette, frame.tl);
+ columnHeight = followHeight(columnHeight, target, elapsed);
+ root.style.setProperty("--column-h", `${columnHeight.toFixed(3)}px`);
+ resizing = columnHeight !== target;
+ }
apply(frame, dock, phase);
if (visible) {
primeCam();
primeStrip();
}
- if (!document.hidden && (following || (phase === "preview" && playing))) {
+ if (!document.hidden && (following || resizing || (phase === "preview" && playing))) {
raf = requestAnimationFrame(tick);
}
};
@@ -780,19 +831,6 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
{ threshold: 0 },
);
observer.observe(root);
- // ResizeObserver reports the actual flow height, including pane transitions
- // and translated captions, without forcing a layout read in the animation loop.
- const columnObserver = new ResizeObserver(([entry]) => {
- if (window.innerWidth <= 900) return;
- columnHeight = entry.borderBoxSize[0]?.blockSize ?? entry.contentRect.height;
- root.style.setProperty("--column-h", `${columnHeight}px`);
- // Update before this frame paints, rather than waiting one rAF behind
- // the pane's height transition.
- fitCard(currentDock);
- schedule();
- });
- columnObserver.observe(column);
-
// Coalesced into a frame, like the scroll. `measure()` opens all five beats,
// reads a rect for every `data-t` node and forces layout to do it; a window
// drag fires resize many times a second, and running that work per event was
@@ -843,7 +881,6 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
document.removeEventListener("visibilitychange", onVisibility);
pause.removeEventListener("click", onPause);
observer.disconnect();
- columnObserver.disconnect();
// The video outlives the driver — it is the same element on re-attach —
// so listeners left on it accumulate one pair per breakpoint crossing,
// each holding a dead driver's closure alive.
diff --git a/website/src/components/Recreation/index.tsx b/website/src/components/Recreation/index.tsx
index 168c83ee2..b970e7f2d 100644
--- a/website/src/components/Recreation/index.tsx
+++ b/website/src/components/Recreation/index.tsx
@@ -335,7 +335,7 @@ export default function Recreation() {
{/* ═══ THE INSPECTOR ═══ Drawn from the app's English strings in
every locale, as is the scene: both carry lang="en", which the
translated captions beside them must not. */}
- <div className={styles.panel} aria-hidden="true" lang="en">
+ <div className={styles.panel} data-editor-panel="" aria-hidden="true" lang="en">
<header className={styles.panelHead}>
{/* One pane in the app: Background is a section of Composition. */}
<h4 className={styles.panelTitle} data-pane="style">
@@ -496,7 +496,7 @@ export default function Recreation() {
</div>
{/* ═══ THE TOOL PALETTE ═══ six tools, the app's own bar */}
- <div className={styles.palette}>
+ <div className={styles.palette} data-tool-palette="">
<span
className={`${styles.tool} ${styles.toolWand}`}
data-t="wand"
@@ -746,7 +746,7 @@ export default function Recreation() {
</div>
{/* ═══ THE FLOOR ═══ */}
- <div className={styles.floor}>
+ <div className={styles.floor} data-editor-timeline="">
<div className={styles.floorClip}>
{/* Static positions, one transform. */}
<div className={styles.rail}>
diff --git a/website/src/components/Recreation/layout.test.ts b/website/src/components/Recreation/layout.test.ts
new file mode 100644
index 000000000..e62bea831
--- /dev/null
+++ b/website/src/components/Recreation/layout.test.ts
@@ -0,0 +1,41 @@
+import assert from "node:assert/strict";
+import { test } from "node:test";
+
+import { followHeight } from "./layout.ts";
+
+test("pane height changes stay between their endpoints and settle without a yoyo", () => {
+ for (const [from, target] of [
+ [318, 360],
+ [503, 410],
+ [410, 318],
+ ]) {
+ let height = from;
+ for (let frame = 0; frame < 60; frame++) {
+ const next = followHeight(height, target, 16);
+ assert.ok(next >= Math.min(height, target) && next <= Math.max(height, target));
+ height = next;
+ }
+ assert.equal(height, target);
+ }
+});
+
+test("reversing a height change continues from the displayed height", () => {
+ let height = followHeight(318, 503, 48);
+ assert.ok(height > 318 && height < 503);
+ const reversed = followHeight(height, 318, 16);
+ assert.ok(reversed < height && reversed > 318);
+ height = followHeight(reversed, 360, 16);
+ assert.ok(height >= Math.min(reversed, 360) && height <= Math.max(reversed, 360));
+});
+
+test("height changes have the same pace at 60 Hz and 120 Hz", () => {
+ const at = (step: number) => {
+ let height = 318;
+ for (let elapsed = 0; elapsed < 96; elapsed += step) {
+ height = followHeight(height, 503, step);
+ }
+ return height;
+ };
+ assert.ok(Math.abs(at(16) - at(8)) < 0.001);
+ assert.equal(followHeight(318, 503, 0), 318);
+});
diff --git a/website/src/components/Recreation/layout.ts b/website/src/components/Recreation/layout.ts
new file mode 100644
index 000000000..e1a61a5ed
--- /dev/null
+++ b/website/src/components/Recreation/layout.ts
@@ -0,0 +1,5 @@
+/** Follow a settled pane height without ever overshooting it. */
+export function followHeight(current: number, target: number, elapsed: number): number {
+ if (Math.abs(target - current) < 0.25) return target;
+ return current + (target - current) * (1 - Math.exp(-Math.max(0, elapsed) / 70));
+}
diff --git a/website/src/components/Recreation/styles.module.css b/website/src/components/Recreation/styles.module.css
index 605a860ff..602a67aad 100644
--- a/website/src/components/Recreation/styles.module.css
+++ b/website/src/components/Recreation/styles.module.css
@@ -269,7 +269,16 @@
caption band the width of the screen for a caption that only ever occupies
the left column. */
--box-top: calc(var(--nav) + var(--gut));
- --box-bot: calc(100vh - var(--gut) - var(--tl) * var(--tl-h));
+ /* Measured once per resize, so the inset never follows pane transitions. */
+ --timeline-content-h: 0px;
+ --timeline-bottom: clamp(
+ 0px,
+ calc((100vh - var(--nav) - 2 * var(--gut) - var(--tl-h) - var(--timeline-content-h)) / 2),
+ min(4.5vh, 48px)
+ );
+ --box-bot: calc(
+ 100vh - var(--gut) - var(--tl) * var(--tl-h) - var(--tl) * var(--timeline-bottom)
+ );
--box-h: calc(var(--box-bot) - var(--box-top));
/* What the column has left for a pane once the caption has taken its share. */
--pane-h: calc(var(--box-h) - var(--cap-h));
@@ -375,17 +384,13 @@
/* ═══ THE CAPTIONS ═════════════════════════════════════════════════════════ */
-/* The left column: the caption and the inspector, balanced against the picture
- as one thing. They were two absolutely positioned boxes with no relationship,
- so the pair could only ever be aligned by accident — the caption sat at the
- picture's top and the panel hung below it, and on a laptop the pair finished
- 120px past the picture's bottom. In one flow the group has a height, and a
- height is all it takes to centre it on the same line the picture is centred
- on. */
+/* One controlled height for the caption, its pane and the picture. The panes
+ overlap while fading, so their combined transition height never sizes it. */
.column {
position: absolute;
left: 4.5vw;
width: var(--pnl-w);
+ height: var(--column-h, var(--box-h));
top: calc(var(--v-t) + var(--v-h) / 2);
transform: translateY(-50%);
z-index: 11;
@@ -395,8 +400,7 @@
.captions {
position: relative;
width: calc(var(--pnl-w) - 8px);
- /* Its children are absolute and take turns, so the box has no height of its
- own — and the flow above needs one. */
+ /* Its absolute children take turns within one reserved caption height. */
height: var(--cap-h);
/* Gated with the inspector, on the inspector's own threshold and the
inspector's own timing, so the title does not announce a panel that is not
@@ -469,32 +473,25 @@
transition: none !important;
}
+.stage[data-measuring] .panel {
+ height: auto;
+}
+
/* ═══ THE INSPECTOR ════════════════════════════════════════════════════════ */
.panel {
- /* Under the caption, in the column's flow, free to be shorter than its slot.
-
- The ceiling is the room the column has between the gutters once the
- caption has taken its share — and NOT the footage's height, which is what
- was originally asked for and which turns out to clip. On a 1289x904 laptop
- the picture is 460px tall and the cursor pane needs 470, so that ceiling
- cut the Smoothing slider off the bottom of the demo. A panel ten pixels
- taller than the picture is a smaller price than a control missing from it,
- and now that the pair is centred on the picture rather than hanging past
- it, the difference reads as symmetry instead of overflow. */
- position: relative;
+ /* Below the caption, following the same settled height as the picture. The
+ measurement pass releases this height to read each pane's natural size. */
+ position: absolute;
+ top: var(--cap-h);
+ left: 0;
box-sizing: border-box;
display: flex;
flex-direction: column;
width: 100%;
- height: auto;
- /* Multiplied by --panel, so the pane collapses out of the column's flow as
- it fades rather than holding its height while invisible. It used to keep
- it: during the timeline beat, where the palette owns the column and is
- absolute, the column was sized for a panel nobody could see and the
- visible group — caption plus palette — sat 124px above the picture it is
- supposed to be balanced against. The transition matches the opacity's, so
- the two swap in one movement. */
+ height: calc(var(--column-h, var(--box-h)) - var(--cap-h));
+ /* Clip the outgoing pane as it fades without contributing a second height
+ to the column while the tool palette is arriving. */
max-height: calc(var(--panel) * var(--pane-h));
transition:
opacity 0.45s var(--ease),
@@ -916,13 +913,11 @@
.palette {
--tool-size: 72px;
--palette-padding: 14px;
- /* In the column's flow, like the inspector, and collapsing the same way: the
- two are alternatives, so whichever is hidden must give its height back or
- the column is sized for something nobody sees. Absolute, it never counted
- at all and the visible pair sat 79px below the picture; in flow with the
- panel holding its height, 124px above it. In flow with both collapsing,
- the column is exactly the caption plus whichever pane is up. */
- position: relative;
+ /* Shares the inspector's slot; the driver's settled measurement includes
+ this palette's own padding and the gap below the caption. */
+ position: absolute;
+ top: var(--cap-h);
+ left: 50%;
margin: calc(var(--palette) * 12px) auto 0;
width: max-content;
z-index: 12;
@@ -932,16 +927,13 @@
border-radius: 22px;
background: color-mix(in srgb, var(--ost-surface) 90%, transparent);
box-shadow: var(--ost-elev-pop), inset 0 1px 0 var(--ost-lip);
- /* The padding and the border collapse with the box, not just its content:
- max-height alone left 20px of column standing for a palette that is not
- there, and that is half a caption's worth of drift on the four beats where
- the inspector is the one showing. 220px clears two rows of 72 plus gaps. */
+ /* 220px clears both rows, including gaps and outer padding. */
box-sizing: border-box;
padding: calc(var(--palette) * var(--palette-padding));
border: calc(var(--palette) * 1px) solid var(--ost-border);
max-height: calc(var(--palette) * 220px);
overflow: hidden;
- transform: translateY(calc((1 - var(--palette)) * -16px));
+ transform: translateX(-50%) translateY(calc((1 - var(--palette)) * -16px));
opacity: calc(var(--palette) * var(--editor-reveal));
pointer-events: none;
transition:
@@ -1677,7 +1669,7 @@
position: absolute;
left: 0;
right: 0;
- bottom: 0;
+ bottom: var(--timeline-bottom);
height: var(--tl-h);
z-index: 8;
background: color-mix(in srgb, var(--ost-surface) 97%, transparent);
@@ -1686,7 +1678,7 @@
/* No transition: `--tl` is eased in the score, and easing a scroll-driven
value twice makes the floor chase a target it reaches late — which is how
it came to sit 16px below its own `bottom: 0`. */
- transform: translateY(calc((1 - var(--tl)) * (var(--tl-h) + 20px)));
+ transform: translateY(calc((1 - var(--tl)) * (var(--tl-h) + var(--timeline-bottom) + 20px)));
}
.floorClip {
@@ -1917,6 +1909,9 @@
little air on each side — a toolbar touching the picture above it and
the floor below it reads as a mistake. */
--pane-min: clamp(184px, 24vh, 198px);
+ --timeline-content-h: calc(
+ var(--cap-h) + (100vw - 2 * var(--gut-h)) * 0.5625 + var(--pane-min)
+ );
/* Full width, but never more height than the box has left once the
caption, the pane and the floor have taken theirs. Taking the width
@@ -1962,6 +1957,7 @@
left: var(--gut-h);
top: calc(var(--v-t) + var(--v-h) + 14px);
width: calc(100vw - 2 * var(--gut-h));
+ height: auto;
max-height: calc(var(--box-bot) - var(--v-t) - var(--v-h) - 14px);
transform: translateY(calc((1 - var(--panel)) * 12px));
}
@@ -2015,6 +2011,7 @@
.column {
position: static;
width: auto;
+ height: auto;
max-width: 60ch;
margin: 0 auto;
transform: none;
@@ -2037,6 +2034,9 @@
.panel {
max-height: none;
+ position: relative;
+ top: auto;
+ height: auto;
margin: 26px 24px 0;
}
@@ -2138,6 +2138,7 @@
}
.band:not([data-driven]) .stage {
+ --timeline-bottom: 0px;
display: flex;
flex-direction: column;
position: static;
@@ -2166,6 +2167,7 @@
display: block;
position: static;
width: auto;
+ height: auto;
max-width: 60ch;
margin: 36px auto;
transform: none;