Skip to content

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

feat(website): aim the recorded pointer at the frame, not at coordinates

Etienne Lescote4b98d88908e
diff --git a/website/src/components/Recreation/driver.ts b/website/src/components/Recreation/driver.ts
index 28f56efbb..d2a047604 100644
--- a/website/src/components/Recreation/driver.ts
+++ b/website/src/components/Recreation/driver.ts
@@ -23,7 +23,17 @@
*/
import { CURSORS } from "./generated";
-import { BEATS, CUT_INDEX, type Frame, frameAt, railScale, strikeOf, T_TOTAL } from "./scene";
+import {
+ BEATS,
+ CUT_INDEX,
+ type Frame,
+ frameAt,
+ railScale,
+ SHOT_PATH,
+ type ShotKey,
+ strikeOf,
+ T_TOTAL,
+} from "./scene";
export interface DriverRefs {
band: HTMLElement;
@@ -226,6 +236,107 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
* share one flow container, so showing them together would measure each one
* stacked below the others.
*/
+ /**
+ * Where the things the recorded pointer aims at actually are, in the frame's
+ * own per-cent — the space `--shot-x` is read in.
+ *
+ * Layout offsets and not rectangles: a rectangle comes back with every
+ * transform already applied, and three of them sit over this one — the
+ * zoomer's zoom, the frame's padding scale, the page's scroll. An offset
+ * ignores all three, so the box is measured once here and put back through
+ * them by `shotKey`, out of numbers the frame already carries. Nothing in
+ * the loop reads layout.
+ */
+ type ShotBox = {
+ x: number;
+ y: number;
+ w: number;
+ h: number;
+ scrolls: boolean;
+ /** The recorded window's own box, when the target is inside it. */
+ win: { x: number; y: number; w: number; h: number } | null;
+ };
+ const shots = new Map<string, ShotBox>();
+ let shotSpace: { w: number; h: number; page: number } | null = null;
+
+ const measureShots = () => {
+ const zoomer = root.querySelector<HTMLElement>("[data-shot-box]");
+ if (!zoomer || zoomer.offsetWidth <= 0) return;
+ const page = root.querySelector<HTMLElement>("[data-shot-scroll]");
+ shotSpace = { w: zoomer.offsetWidth, h: zoomer.offsetHeight, page: page?.offsetHeight ?? 0 };
+ const winEl = root.querySelector<HTMLElement>("[data-shot-win]");
+ let win: ShotBox["win"] = null;
+ for (const el of Array.from(root.querySelectorAll<HTMLElement>("[data-shot]"))) {
+ let x = 0;
+ let y = 0;
+ let n: HTMLElement | null = el;
+ while (n && n !== zoomer) {
+ if (n === winEl) win = { x, y, w: n.offsetWidth, h: n.offsetHeight };
+ x += n.offsetLeft;
+ y += n.offsetTop;
+ n = n.offsetParent as HTMLElement | null;
+ }
+ // Not under the zoomer, or in a pane with no box: keep the last answer,
+ // the way the pointer's own targets do.
+ if (n !== zoomer) continue;
+ shots.set(el.dataset.shot!, {
+ x,
+ y,
+ w: el.offsetWidth,
+ h: el.offsetHeight,
+ scrolls: page?.contains(el) ?? false,
+ // Offsets are measured from the target, so the window's own box comes
+ // back relative to it; put it in the zoomer's frame.
+ win: win && { ...win, x: x - win.x, y: y - win.y },
+ });
+ win = null;
+ }
+ };
+
+ /** One keyframe of the recorded pointer's path. A named one is put back
+ * through the transforms between the thing and the pointer, in the order
+ * the browser applies them: the page scrolls inside the frame, the frame
+ * scales about the middle of the zoomer — which is also the middle of the
+ * frame, since it is inset by the same per-cent on both sides. */
+ const shotKey = (k: ShotKey, f: Frame): [number, number] => {
+ if (typeof k[1] === "number") return [k[1], k[2]];
+ const b = shots.get(k[1]);
+ if (!b || !shotSpace) return [50, 50];
+ let x = b.x + k[2] * b.w;
+ let y = b.y + k[3] * b.h;
+ if (b.win) {
+ // The window scales as it opens, about a point of its own — so a target
+ // on it is somewhere else for as long as that lasts. Same shape as the
+ // stylesheet's `scale(0.82 + --win-vis * 0.18)`, and the same number
+ // only because both read `winVis` off the frame.
+ const s = 0.82 + f.winVis * 0.18;
+ x = b.win.x + 0.26 * b.win.w + (x - (b.win.x + 0.26 * b.win.w)) * s;
+ y = b.win.y + 0.42 * b.win.h + (y - (b.win.y + 0.42 * b.win.h)) * s;
+ }
+ x = (x / shotSpace.w) * 100;
+ y = (y / shotSpace.h) * 100;
+ if (b.scrolls) y += (f.pageY * shotSpace.page) / shotSpace.h;
+ return [50 + (x - 50) * f.frameScale, 50 + (y - 50) * f.frameScale];
+ };
+
+ /** The path, interpolated after its keyframes resolve and not before: a
+ * named keyframe answers differently every frame. */
+ const shotPoint = (f: Frame): [number, number] => {
+ const t = f.tf;
+ for (let i = 1; i < SHOT_PATH.length; i++) {
+ if (t <= SHOT_PATH[i][0]) {
+ const a = SHOT_PATH[i - 1];
+ const b = SHOT_PATH[i];
+ if (t <= a[0]) return shotKey(a, f);
+ const k = (t - a[0]) / (b[0] - a[0]);
+ const [ax, ay] = shotKey(a, f);
+ const [bx, by] = shotKey(b, f);
+ return [ax + (bx - ax) * k, ay + (by - ay) * k];
+ }
+ }
+ return shotKey(SHOT_PATH[SHOT_PATH.length - 1], f);
+ };
+
/* The rail's scale, which is a function of the stage and not of the frame —
so it is written here, where resizes land, rather than every rAF. The
stylesheet's own `--k` is the resting value for a reader who never gets
@@ -277,6 +388,8 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
property here makes the restored state the one transitions start from,
so there is nothing to animate. */
void root.offsetHeight;
+ // After the restore, so the boxes are the ones the reader is looking at.
+ measureShots();
delete root.dataset.measuring;
};
@@ -452,14 +565,16 @@ export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {
num("--fit", f.fit);
num("--pad-pct", f.paddingPct, 2);
num("--frame-scale", f.frameScale, 4);
+ num("--win-vis", f.winVis, 4);
num("--size-pct", f.cursorSizePct, 2);
num("--cur-size", f.cursorSize, 2);
num("--size-u", f.cursorSizeU, 4);
num("--zoom", f.zoom, 4);
root.style.setProperty("--zoom-origin", f.zoomOrigin);
num("--zoom-active", f.zoomActive, 0);
- num("--shot-x", f.shot[0], 2);
- num("--shot-y", f.shot[1], 2);
+ const [shotX, shotY] = shotPoint(f);
+ num("--shot-x", shotX, 2);
+ num("--shot-y", shotY, 2);
num("--shot-bounce", f.shotBounce, 4);
num("--page-y", f.pageY, 2);
num("--ui-bounce", f.uiBounce, 4);
diff --git a/website/src/components/Recreation/index.tsx b/website/src/components/Recreation/index.tsx
index 6ba1f8b59..db2b20419 100644
--- a/website/src/components/Recreation/index.tsx
+++ b/website/src/components/Recreation/index.tsx
@@ -392,7 +392,7 @@ export default function Recreation() {
{/* ═══ THE COMPOSITE ═══ */}
<div className={styles.card}>
<div className={styles.cardClip}>
- <div className={styles.zoomer}>
+ <div className={styles.zoomer} data-shot-box>
{CANVAS_BG.map((n) => (
<img
key={n}
@@ -417,7 +417,7 @@ export default function Recreation() {
<span className={styles.omnibox}>fern.garden</span>
</div>
<div className={styles.viewport}>
- <div className={styles.page}>
+ <div className={styles.page} data-shot-scroll>
<div className={styles.pageNav}>
<span className={styles.pageMark} />
<span className={styles.pageBrand}>Fern</span>
@@ -435,10 +435,10 @@ export default function Recreation() {
when they ask for it.
</p>
<div className={styles.pageBtns}>
- <span className={styles.pageCta}>Download the app</span>
- <span className={styles.pageGhost} data-shot="see">
- See how it works
+ <span className={styles.pageCta} data-shot="cta">
+ Download the app
</span>
+ <span className={styles.pageGhost}>See how it works</span>
</div>
</div>
<div className={styles.pageShot}>
@@ -528,8 +528,8 @@ export default function Recreation() {
{/* The app the recording opens, half-way through the take. Two
states crossfaded on the footage clock, under one title bar. */}
- <div className={styles.appWin}>
- <div className={styles.appBar}>
+ <div className={styles.appWin} data-shot-win>
+ <div className={styles.appBar} data-shot="app-bar">
<span className={styles.appLights}>
<span data-l="r" />
<span data-l="y" />
@@ -550,7 +550,9 @@ export default function Recreation() {
<span className={styles.appDot} />
Searching nearby…
</div>
- <span className={styles.appBtn}>Pair sensor</span>
+ <span className={styles.appBtn} data-shot="app-go">
+ Pair sensor
+ </span>
</div>
<div className={styles.appDone}>
diff --git a/website/src/components/Recreation/scene.ts b/website/src/components/Recreation/scene.ts
index bfa1a978e..8c27323d5 100644
--- a/website/src/components/Recreation/scene.ts
+++ b/website/src/components/Recreation/scene.ts
@@ -348,37 +348,50 @@ function bounce(t: number, win: number, clicks: number[]): number {
: 1 + Math.sin(((e - 0.38) / 0.62) * Math.PI) * 0.32;
}
-/** The recorded pointer's path and the recorded page's scroll, both on the
- * footage clock. Percentages of the frame, so neither has a pixel baked in. */
-const SHOT_PATH: number[][] = [
+/**
+ * The recorded pointer's path, on the footage clock.
+ *
+ * A keyframe is either a place in the frame — percentages, so no pixel is baked
+ * in — or the NAME of something in it, matched against `[data-shot]` and
+ * resolved by the driver against what that thing actually measures.
+ *
+ * The names are the point. Coordinates copied from the design describe the
+ * design's frame, not ours: our padding comes off the vendored document, so the
+ * recorded window sits somewhere else, and the pointer parked outside the very
+ * window it had just clicked. A name cannot drift, because whatever moves the
+ * window moves the answer with it.
+ *
+ * The wandering between clicks stays in coordinates. It is not aimed at
+ * anything, so there is nothing for it to name.
+ */
+export type ShotKey =
+ | readonly [at: number, x: number, y: number]
+ | readonly [at: number, on: string, fx: number, fy: number];
+
+export const SHOT_PATH: readonly ShotKey[] = [
[0.8, 38, 60],
[3.5, 52, 55],
[6.4, 46, 50],
- [7.4, 34.5, 49],
- [8.9, 34.5, 49],
+ /* The page's own call to action, which is what the take opens by pressing.
+ Named through the scroll: the page is at -6% here and at -62% when the
+ pointer comes back to this same spot at 21.9, so one coordinate cannot
+ mean the same thing twice. */
+ [7.4, "cta", 0.5, 0.5],
+ [8.9, "cta", 0.5, 0.5],
[10.5, 52, 58],
[11.2, 46, 64],
[12.3, 46, 64],
[13.8, 50, 60],
[14.6, 44, 62],
[15.5, 44, 62],
- [15.9, 50, 61.5],
- [16.9, 50, 61.5],
- /* (40, 36) and not the design's (34.8, 27.6): that point is on the window's
- title bar in the design's frame and misses ours by six per cent of the
- height, because the frame is inset by OUR padding — read off the vendored
- document — and not by the design's. Measured against the rendered window,
- which spans 36.0-64.0 across and 33.6-73.2 down, with the bar the 5.2%
- slice at its top.
-
- These are still coordinates, which is the same shape of fragility that put
- the reader's pointer 151px off its targets and swept the wrong word: the
- robust version aims at the window the way the pointer aims at `[data-t]`.
- That is a refactor rather than a patch — the shot path is evaluated in the
- pure score, which has no DOM to measure — and `data-shot="see"` in the
- markup is the unbuilt half of it. */
- [17.4, 40, 36],
- [18.3, 40, 36],
+ /* The button it is about to press. */
+ [15.9, "app-go", 0.5, 0.5],
+ [16.9, "app-go", 0.5, 0.5],
+ /* On the window's own title bar, a fifth of the way along it — where a hand
+ goes to move a window. Named, so the padding can move the window without
+ taking the pointer off it. */
+ [17.4, "app-bar", 0.2, 0.5],
+ [18.3, "app-bar", 0.2, 0.5],
[19.2, 35, 68],
[20.2, 58, 58],
[21.3, 34.5, 49],
@@ -458,6 +471,8 @@ export interface Frame {
/** Uniform scale on the recorded window — v4 scales the frame rather than
* insetting it, so the page's internal layout never reflows. */
frameScale: number;
+ /** The recorded app window's entrance, 0-1. */
+ winVis: number;
cursorSize: number;
cursorSizePct: number;
/** The size drag as 0-1, which is what the recorded cursor scales on. */
@@ -468,7 +483,6 @@ export interface Frame {
zoomOrigin: string;
zoomLabel: string;
zoomActive: number;
- shot: [number, number];
shotBounce: number;
uiBounce: number;
pageY: number;
@@ -533,7 +547,6 @@ export function frameAt(p: number): Frame {
const live = ZOOMS.slice(1).find((z) => t >= z.from && t <= z.to);
const zoomsPlaced = ZOOMS.filter((z) => t >= z.placedAt).length;
- const [shotX, shotY] = kf(tf, SHOT_PATH);
const [pageY] = kf(tf, PAGE_PATH);
const placedTrims = trims(t);
@@ -564,6 +577,13 @@ export function frameAt(p: number): Frame {
paddingPct:
((padding - CONTROLS.padding.min) / (CONTROLS.padding.max - CONTROLS.padding.min)) * 100,
frameScale: 1 - padU * 0.36,
+ /* The window opens and shuts on the footage clock, so it rides the speed
+ ramp with everything else in the recording. Here and not in the
+ stylesheet, because the pointer has to aim at a window this scales: it
+ is the third transform between a named target and the frame, after the
+ page's scroll and the padding. The `* 8` IS the ease — nothing may
+ transition on top of it. */
+ winVis: Math.min(clamp01((tf - 15.25) * 8), clamp01((17.95 - tf) * 8)),
cursorSize,
cursorSizeU: sizeU,
cursorSizePct:
@@ -575,7 +595,6 @@ export function frameAt(p: number): Frame {
zoomOrigin: live ? live.origin : "52% 58%",
zoomLabel: live ? live.label : ZOOMS[1].label,
zoomActive: live ? 1 : 0,
- shot: [shotX, shotY],
shotBounce: bounce(tf, 0.32, FOOTAGE_CLICKS),
uiBounce: bounce(t, 0.42, UI_CLICKS),
pageY,
diff --git a/website/src/components/Recreation/styles.module.css b/website/src/components/Recreation/styles.module.css
index 6e05dfed9..dab825438 100644
--- a/website/src/components/Recreation/styles.module.css
+++ b/website/src/components/Recreation/styles.module.css
@@ -1196,11 +1196,13 @@
background: #fbfcfd;
box-shadow: 0 4cqh 10cqh rgba(8, 12, 18, 0.45), 0 0 0 1px rgba(15, 23, 42, 0.08);
transform-origin: 26% 42%;
- /* Open between footage 15.25 and 17.95 — expressed as a window on --tf so it
- rides the speed ramp with everything else in the recording. */
- --open: clamp(0, (var(--tf) - 15.25) * 8, 1);
- --shut: clamp(0, (17.95 - var(--tf)) * 8, 1);
- --vis: min(var(--open), var(--shut));
+ /* Open between footage 15.25 and 17.95, on the footage clock so it rides the
+ speed ramp with everything else in the recording. The ramp itself lives in
+ the score (scene.ts, `winVis`), because the recorded pointer has to aim at
+ a window this scales and cannot read a stylesheet. Zero without the driver
+ — which is what a reader with no JS sees anyway, the scene frozen at its
+ opening frame with the window not yet open. */
+ --vis: var(--win-vis, 0);
opacity: var(--vis);
transform: scale(calc(0.82 + var(--vis) * 0.18));
/* No transition. --vis is min() of two clamp() ramps off --tf, which the