The VS Code of video editing, built for agents.
TypeScript
Refine canvas handling and opacity management in rendering
konstantin-paulus66051a5b86ed
diff --git a/apps/web/src/engine/capture.ts b/apps/web/src/engine/capture.tsindex f326baaa..52ef6180 100644--- a/apps/web/src/engine/capture.ts+++ b/apps/web/src/engine/capture.ts@@ -96,15 +96,20 @@ export async function createCapture(source: World, node: Entity, options: Captur// The encoder sizes it once it knows how big the picture is. It sits inside// the viewport, behind the app, not parked off-screen: the browser only// paints layout near the viewport, and drawElementImage draws from that- // cached paint — on a canvas at left:-100000px it throws "no cached paint- // record" and every HTML paint captures blank. The opacity keeps it from- // showing through translucent UI above it (the rendering overlay) while- // staying over Chromium's minimum visible opacity (0.0004), under which the- // subtree would again not be painted.+ // cached paint — on a canvas at left:-100000px (or below the fold) it+ // throws "no cached paint record" and every HTML paint captures blank.+ // Only the canvas's origin has to intersect the viewport, not its whole+ // box: a `layoutsubtree` child is paint-contained and records in full, so a+ // 4K canvas in a small window still captures its far corner.+ // `opacity:0` alone would not do — Blink skips painting a subtree under its+ // minimum visible opacity (0.0004) — but `will-change:opacity` keeps the+ // effect node composited, so the subtree is painted at opacity 0 all the+ // same and nothing shows through translucent UI above it. Canvas opacity is+ // not baked into what drawElementImage yields.const canvas = document.createElement('canvas');canvas.width = 2;canvas.height = 2;- canvas.style.cssText = 'position:fixed;left:0;top:0;z-index:-9999;opacity:0.001;pointer-events:none;';+ canvas.style.cssText = 'position:fixed;left:0;top:0;z-index:-9999;opacity:0;will-change:opacity;pointer-events:none;';document.body.appendChild(canvas);// Shares the source's assets and generation service — a `src` names thediff --git a/examples/05-anime-timeline.tsx b/examples/05-anime-timeline.tsxindex 713b75a9..511cca76 100644--- a/examples/05-anime-timeline.tsx+++ b/examples/05-anime-timeline.tsx@@ -68,12 +68,14 @@ export default function AnimeTimeline() {<div style={{ "font-size": "34px", "font-weight": "700", color: `hsl(${hue()} 90% 65%)` }}>DOM, meet timeline</div>- {/* Dimmed via alpha colors, not opacity: a fractional opacity here- would nest under the wrapper's animated one, which blanks the- subtree mid-fade (see reference/jsx/html.md limitations). */}- <div style={{ "font-size": "18px", color: "rgba(255,255,255,0.7)", margin: "6px 0 24px" }}>+ <div style={{ "font-size": "18px", color: "white", opacity: 0.7, margin: "6px 0 24px" }}>anime.js seeked from the playhead at t = {time().toFixed(2)}s</div>+ {/* The track is dimmed with an alpha color rather than its own+ `opacity`: an element that carries both a fractional opacity and+ a painted box blanks the whole subtree while an ancestor is+ mid-fade (see reference/jsx/html.md limitations). Dimming text+ with `opacity`, as above, is fine. */}<div style={{ height: "14px", "border-radius": "7px", background: "#ffffff22" }}><divstyle={{diff --git a/reference/jsx/html.md b/reference/jsx/html.mdindex c73bad2d..ecb019e9 100644--- a/reference/jsx/html.md+++ b/reference/jsx/html.md@@ -83,4 +83,4 @@ The module is re-executed in every context: on reload, export, and [`dapi captur- Pointer and media event handlers on the DOM children are ignored: the subtree is rasterized into the canvas, not interacted with. Styles, classes, attributes, `innerHTML` and `textContent` all apply and are reactive.- **`<html>` is sourceless, so with no `end` it defaults to a 16-second duration and disappears after 16 s** — a silent cutoff with no error.- **`scale()` blanks large or clipped subtrees in captures.** The rasterizer renders a subtree as *empty* when a CSS `scale()` sits on a large wrapper (e.g. a full-box `width:100%;height:100%` group), or when any `overflow:hidden` clip lives beneath a scaled ancestor. Animate entrances, holds, and exits with `translate` and `opacity`; use `scale` only on small, content-sized leaf elements with no clipping inside them. A masked text reveal (`overflow:hidden` + inner `translateY`) is fine as long as no ancestor of the mask carries a transform.-- **Nested fractional `opacity` blanks the subtree in captures.** A child with `opacity` < 1 under an ancestor whose `opacity` is also < 1 makes the rasterizer drop the ancestor's entire subtree for exactly as long as the ancestor's opacity is fractional — so a wrapper fading in over children styled with `opacity: 0.7` is blank mid-fade and pops in the moment the fade lands on 1. In the live editor the dropped subtree does not just go blank: the promoted layer escapes the canvas and paints itself on top of the stage at the canvas's top-left corner, at authored size, with no camera or scene transform — HTML content appearing untransformed over the stage instead of inside its scene is this bug, not a broken transform. Keep animated `opacity` to a single level of the tree: dim static children with alpha colors (`rgba()` / `hsl()` alpha) instead of `opacity`.+- **Fractional `opacity` on a painted box blanks the subtree in captures.** Under an ancestor whose `opacity` is fractional (a wrapper mid-fade), a descendant that carries *both* its own `opacity` < 1 *and* a painted box — `background`, `border`, `box-shadow`, `outline` — makes the rasterizer drop the ancestor's entire subtree for exactly as long as the ancestor's opacity is fractional, so the content is blank mid-fade and pops in the moment the fade lands on 1. Splitting the two across a parent and a child does not help; nor does `will-change`, `isolation`, `contain`, or `filter: opacity()`. Dimming **text** with `opacity` is fine, and so is a box whose background is dimmed with an alpha color — give decorated boxes `rgba()` / `hsl()` alpha instead of `opacity`. In the live editor the dropped subtree does not just go blank: the promoted layer escapes the canvas and paints itself on top of the stage at the canvas's top-left corner, at authored size, with no camera or scene transform — HTML content appearing untransformed over the stage instead of inside its scene is this bug, not a broken transform.