Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(website): give the scene back whole when the driver stops
Etienne Lescotc73c6f1093ba
diff --git a/website/src/components/Recreation/driver.ts b/website/src/components/Recreation/driver.tsindex d2a047604..f2e4ab81c 100644--- a/website/src/components/Recreation/driver.ts+++ b/website/src/components/Recreation/driver.ts@@ -48,7 +48,6 @@ export interface DriverRefs {export interface DriverClasses {struck: string;- cue: string;}export const SCENE_QUERIES = [@@ -67,16 +66,17 @@ export function sceneEnabled(): boolean {}}-/** Everything `apply` writes, so a driver that shuts down hands the element back- * to the stylesheet's resting values rather than freezing mid-ride. */+/** Every custom property `apply` writes, so a driver that shuts down hands the+ * element back to the stylesheet's resting values rather than freezing mid-ride.+ * Attributes and classes are handed back by `release` below. */const WRITTEN = ["--t","--tf","--tl",- "--bg","--fit","--pad-pct","--frame-scale",+ "--win-vis","--size-pct","--cur-size","--size-u",@@ -105,11 +105,6 @@ const WRITTEN = ["--wand","--comment","--k",- "--trim-0",- "--trim-1",- "--trim-2",- "--trim-3",- "--trim-4",];const fmtSec = (sec: number) => {@@ -153,10 +148,38 @@ const TEXTS = [];const inAny = (t: number, w: number[][]) => w.some(([a, b]) => t >= a && t < b);+/**+ * Hands the scene back to the stylesheet.+ *+ * Not only the custom properties: `apply` also selects the wallpaper, the+ * cursor pack and the pointer art with attributes, writes each trim's opacity+ * inline, and strikes words with a class. A driver that stops — the reader+ * crossed a breakpoint, or turned reduced motion on mid-ride — has to give all+ * of it back, or the still it hands over is a frozen frame of the ride rather+ * than the closing one the stylesheet is written for.+ *+ * `data-bg` is restored rather than removed, because there is no resting value+ * for it in the stylesheet: the wallpaper is chosen by attribute, and the still+ * shows the one the take ends on. The markup renders the same expression.+ */+function release(refs: DriverRefs, cls: DriverClasses): void {+ const { root, flow } = refs;+ for (const name of WRITTEN) root.style.removeProperty(name);+ delete root.dataset.beat;+ delete root.dataset.cur;+ delete root.dataset.curSel;+ root.dataset.bg = String(frameAt(1).bg);+ for (const el of Array.from(root.querySelectorAll<HTMLElement>("[data-trim]"))) {+ el.style.removeProperty("opacity");+ }+ for (const el of Array.from(flow.querySelectorAll<HTMLElement>(`.${cls.struck}`))) {+ el.classList.remove(cls.struck);+ }+}+export function attachDriver(refs: DriverRefs, cls: DriverClasses): () => void {if (!sceneEnabled()) {- for (const name of WRITTEN) refs.root.style.removeProperty(name);- delete refs.root.dataset.beat;+ release(refs, cls);return () => {// Nothing was attached, so there is nothing to detach.};diff --git a/website/src/components/Recreation/index.tsx b/website/src/components/Recreation/index.tsxindex db2b20419..e9f451743 100644--- a/website/src/components/Recreation/index.tsx+++ b/website/src/components/Recreation/index.tsx@@ -55,9 +55,11 @@ import {CLIPS,CUT_INDEX,FLOOR_H,+ frameAt,LANES,PLAYHEAD,SPEED,+ shotCursorSrc,TOKENS,trims,WALLPAPER_COUNT_SHOWN,@@ -74,6 +76,10 @@ import styles from "./styles.module.css";Inline styles, so postcss never sees this calc. */const x = (sec: number) => `calc(${sec.toFixed(3)} * var(--k) * 1px)`;+/** The frame the scene comes to rest on, and the one a reader with no driver is+ * handed. Everything below that needs a resting value reads it. */+const REST = frameAt(1);+/** The twelve wallpapers the picker shows, in the design's order. */const WALLPAPERS = [2, 5, 8, 11, 1, 4, 6, 7, 9, 10, 12, 13];/** The four the background beat steps through, as full-size canvas layers. */@@ -140,12 +146,12 @@ export default function Recreation() {flow: flow.current,};if (Object.values(refs).some((el) => el === null)) return;- const classes = { struck: styles.struck, cue: styles.cue };+ const classes = { struck: styles.struck };// The gate is re-checked, not decided once: a reader who opens the page- // narrow and widens it past 901px gets the stage from CSS the instant the- // query flips, and a driver that had given up at mount would leave it- // frozen at its resting frame with the scroll doing nothing.+ // narrower than 360px and widens it past that gets the stage from CSS the+ // instant the query flips, and a driver that had given up at mount would+ // leave it frozen at its resting frame with the scroll doing nothing.let detach = attachDriver(refs as Parameters<typeof attachDriver>[0], classes);const queries = SCENE_QUERIES.map((q) => window.matchMedia(q));const recheck = () => {@@ -163,18 +169,27 @@ export default function Recreation() {return (<section className={styles.band} ref={band} data-recreation="">- {/* The two cursor sprites are set here rather than in the stylesheet: a- url() inside a CSS module is inlined by webpack as a data URI, and- these two came to a quarter of the site's only render-blocking- resource — paid for on every docs page, which have no stage on them.- The driver writes both properties onto this same element. */}+ {/* Three resting values that cannot live in the stylesheet, all read off+ the closing frame rather than typed:++ the two cursor sprites, because a url() inside a CSS module is+ inlined by webpack as a data URI and these two came to a quarter of+ the site's only render-blocking resource — paid for on every docs+ page, none of which has a stage on it;++ the wallpaper, because the selection is an attribute rather than a+ custom property, so there is nowhere in the sheet to declare it.+ `release()` restores it from the same expression.++ The driver overwrites all three per frame. */}<divclassName={styles.stage}ref={root}+ data-bg={String(REST.bg)}style={{- "--shot-cursor": 'url("/img/cursors/01-arrow.png")',- "--ui-cursor": 'url("/img/cursors/00-arrow.png")',+ "--shot-cursor": `url("${shotCursorSrc(REST)}")`,+ "--ui-cursor": `url("${CURSORS.themes[0].src}")`,} as React.CSSProperties}>@@ -233,8 +248,8 @@ export default function Recreation() {<spankey={n}className={styles.swatch}+ data-i={i}data-t={i < 4 ? `th-${i}` : undefined}- style={{ ["--i" as string]: i }}>{/* Lazy, and warmed by the driver — see primeStrip(). Thesetwelve sit in a pane held at `display: none` until thediff --git a/website/src/components/Recreation/styles.module.css b/website/src/components/Recreation/styles.module.cssindex 79a7e9195..538548e8b 100644--- a/website/src/components/Recreation/styles.module.css+++ b/website/src/components/Recreation/styles.module.css@@ -27,6 +27,11 @@* closing frame — so a reader with no JavaScript, or a reduced-motion* preference, gets a still, complete editor rather than something stranded at* opacity 0.+ *+ * Two things in that frame are not custom properties and so cannot be declared+ * here: the selected wallpaper, which is an attribute the markup renders and the+ * driver overwrites, and the transcript's struck words, which are a class and+ * are therefore the one part of the closing frame the still cannot show.*//* ═══ TOKENS ═══════════════════════════════════════════════════════════════@@ -114,7 +119,6 @@driver — no JS, reduced motion — sees the captions rather than aninvalid declaration falling back to whatever opacity happens to be. */--intro: 1;- --bg: 3;--fit: 0.88;--pad-pct: 30;--frame-scale: 1;@@ -148,11 +152,13 @@--palette: 0;--wand: 0;--comment: 0;- --trim-0: 1;- --trim-1: 1;- --trim-2: 1;- --trim-3: 1;- --trim-4: 1;+ /* The trims, for a reader with no driver. Each pill's own opacity is written+ inline once there is one — the order they are placed in is not the order+ they sit in, so no count can express it, which is what --zooms-placed can+ do and this cannot. The one thing the still cannot show is the transcript's+ five struck words: striking is a class, and nothing applies it without the+ driver. */+ --trims-shown: 1;/* ── the grid, once ── */--c2x: calc(4.5vw + var(--pnl-w) + 26px);@@ -451,9 +457,10 @@}/* Selection is a `data-bg` on the stage matched against the swatch's own index.- An arithmetic version — opacity from `--i` against `--bg` — reads better and- is a trap: postcss-calc cannot fold min()/max() over custom properties and- drops the whole declaration, in the production build only. */+ An arithmetic version — opacity from the swatch's `--i` against a `--bg` the+ driver would write — reads better and is a trap: postcss-calc cannot fold+ min()/max() over custom properties and drops the whole declaration, in the+ production build only. */.swatch::after {content: "";position: absolute;@@ -717,10 +724,6 @@background: var(--ost-danger-soft);}-.cue {- color: var(--os-fg-emphasis);-}-/* ═══ THE TOOL PALETTE ═════════════════════════════════════════════════════Centred in the left column, between the caption and the floor. */@@ -823,8 +826,10 @@transition: transform 0.7s var(--ease);}-/* Four wallpapers, cross-fading on `--bg`. Only the one whose index matches is- opaque, so the picker's selection and the canvas cannot disagree. */+/* Four wallpapers, cross-fading on `data-bg`. Only the one whose index matches+ is opaque, so the picker's selection and the canvas cannot disagree. The+ attribute is always present — the markup renders the closing frame's pick and+ the driver overwrites it per frame — so this needs no undriven fallback. */.bg {position: absolute;inset: 0;@@ -836,7 +841,8 @@}/* The first one is the floor of the stack, so something is always painted while- the others cross-fade over it. */+ the others cross-fade over it. It is first in the markup as well as here: a+ floor drawn later would paint over the picture it is meant to sit under. */.bg[data-i="0"] {opacity: 1;}@@ -1586,13 +1592,13 @@color: var(--ost-danger);}-/* Each trim's opacity is written straight onto the element by the driver.- `:nth-of-type` looked tidier and is wrong: it counts siblings of the same+/* Each trim's opacity is written straight onto the element by the driver, over+ this. `:nth-of-type` looked tidier and is wrong: it counts siblings of the same*element* — and the rail is full of spans for ticks and other pills — so thefive rules matched five arbitrary nodes and every trim showed from the firstframe. */.pillTrim {- opacity: 0;+ opacity: var(--trims-shown);}.playhead {