The VS Code of video editing, built for agents.
TypeScript
Enhance HTML rendering capabilities with new `<html>` element
konstantin-paulus924218d0d42e
diff --git a/apps/web/src/components/engine/api/query.ts b/apps/web/src/components/engine/api/query.tsindex aa208e97..559b9b55 100644--- a/apps/web/src/components/engine/api/query.ts+++ b/apps/web/src/components/engine/api/query.ts@@ -3,7 +3,7 @@* file, You can obtain one at http://mozilla.org/MPL/2.0/. */import { query, hasComponent, Not } from 'bitecs';-import { ChildOf, GeometryType } from '../components';+import { ChildOf, GeometryType, PaintType } from '../components';import { getParentEntity } from './base';import type { EngineWorld } from './world';@@ -70,6 +70,11 @@ export function isShape(world: EngineWorld, eid: number): boolean {&& !hasComponent(world, eid, c.Audio);}+export function hasHtmlPaint(world: EngineWorld, eid: number): boolean {+ const c = world.components;+ return (c.Cache.fills[eid] ?? []).some(fid => c.Paint[fid] === PaintType.HTML);+}+export function isMask(world: EngineWorld, eid: number): boolean {return hasComponent(world, eid, world.components.IsMask);}diff --git a/apps/web/src/components/engine/timeline/render/clip.ts b/apps/web/src/components/engine/timeline/render/clip.tsindex 04d35242..002c4c50 100644--- a/apps/web/src/components/engine/timeline/render/clip.ts+++ b/apps/web/src/components/engine/timeline/render/clip.ts@@ -9,7 +9,7 @@ import { CLIP_BREAKPOINTS, CLIP_CORNER_RADIUS, CLIP_FONT, CLIP_LABEL_HEIGHT, CLIimport { renderImageThumbnails } from "./image";import { renderAudioWaveform } from "./audio";import { renderVideoThumbnails } from "./video";-import { getParentEntity, isAdjustmentLayer, isCaption, isGroup, isMask, isScene, isText } from "../../api";+import { getParentEntity, hasHtmlPaint, isAdjustmentLayer, isCaption, isGroup, isMask, isScene, isText } from "../../api";import { renderCaption } from "./caption";import { hasComponent, Not, Or, query } from "bitecs";import { addComponent, clearComponent, removeComponent, setComponent } from "../../api/events";@@ -330,6 +330,10 @@ export function getClipStyle(return timeline.colors.clip.adjustment;}+ if (hasHtmlPaint(world, eid)) {+ return timeline.colors.clip.html;+ }+if (asset?.type == 'VIDEO') {return timeline.colors.clip.video;}diff --git a/apps/web/src/utils/jsx.ts b/apps/web/src/utils/jsx.tsindex bb3a5038..a245d955 100644--- a/apps/web/src/utils/jsx.ts+++ b/apps/web/src/utils/jsx.ts@@ -555,10 +555,10 @@ export class WorldDocument implements ProjectDocument<DocumentNode> {} case "colorStop": case "stop": {setComponent(world, eid, c.ColorStop, {});break;- } case "htmlPaint": case "html": {+ } case "htmlPaint": {assert(isHtmlInCanvasSupported(),- "<html> requires the html-in-canvas API; enable chrome://flags/#canvas-draw-element",+ "<htmlPaint> requires the html-in-canvas API; enable chrome://flags/#canvas-draw-element",);setComponent(world, eid, c.Paint, PaintType.HTML);const host = new HtmlHost();@@ -566,6 +566,23 @@ export class WorldDocument implements ProjectDocument<DocumentNode> {c.HtmlHost[eid] = host;node.host = host;break;+ } case "html": {+ // A rect carrying an html paint; the node's children are the paint's+ // DOM content, so `node.host` points at the paint's host.+ assert(+ isHtmlInCanvasSupported(),+ "<html> requires the html-in-canvas API; enable chrome://flags/#canvas-draw-element",+ );+ setComponent(world, eid, c.Geometry, GeometryType.RECT);+ setComponent(world, eid, c.Name, getNextName(world, "HTML"));+ const fid = createEntity(world);+ setComponent(world, fid, c.Paint, PaintType.HTML);+ const host = new HtmlHost();+ addComponent(world, fid, c.HtmlHost, false);+ c.HtmlHost[fid] = host;+ appendChild(world, fid, eid);+ node.host = host;+ break;} default: {assert(false, `<${node.tag}> is only valid inside <html> content`);}diff --git a/docs/composition.md b/docs/composition.mdindex 7e81e5d1..f3b38fb2 100644--- a/docs/composition.md+++ b/docs/composition.md@@ -38,6 +38,7 @@ The first rendered root becomes the active scene. New roots are auto-placed on t| `<audio>` | Sound only, no spatial props. || `<sequence>` | Track container for back-to-back clips (positions are explicit); hosts transitions. || `<captions>` | Styled captions: transcribes the scene's audio, or mounts a transcript given via `src`. |+| `<html>` | A rectangle whose children are HTML/SVG, laid out by the browser at the node's box size and drawn into it. Equivalent to a `<rect>` with an `<htmlPaint>`. || `<solidPaint>`, `<linearGradientPaint>`, `<radialGradientPaint>`, `<colorStop>` (aliases `<solid>`, `<linearGradient>`, `<radialGradient>`, `<stop>`) | Fills, declared as children; see [Paints](#paints). |User-defined components are ordinary Solid components; only intrinsic elements produce nodes.@@ -72,6 +73,7 @@ Animatable props also take a keyframe list — see [Animation](#animation).- **`<image>`**: `src` (required), `objectFit` (default `"contain"`).- **`<audio>`**: `src` (required), `volume` (dB; `0` = unity, negative attenuates), `muted`, `syncTo`, timing props.- **`<text>`**: string children (required), `fontFamily` (see `dapi fonts`), `fontSize`, `fontWeight`, `fontStyle`, `fill`, `textAlign`, `textBaseline`.+- **`<html>`**: HTML/SVG children. Fully reactive: signals in attributes, styles, and text update the drawn content. Event handlers are dropped (the content is painted, not interactive).These same props are what `dapi node patch` assigns on existing nodes.@@ -180,7 +182,7 @@ A node's fill is a **paint child**; the `fill` prop is shorthand for a solid pai</rect>```-`<solidPaint>` takes `color` (required) and `opacity`; gradient paints take `rotation` and `opacity` and only `<colorStop>` children (`offset` and `color` required). Colors are any CSS color; alpha is ignored, use `opacity`. Each paint tag has a short alias (`<solid>`, `<linearGradient>`, `<radialGradient>`, `<stop>`, `<html>`); the SVG name overlap is unambiguous because tags resolve by environment.+`<solidPaint>` takes `color` (required) and `opacity`; gradient paints take `rotation` and `opacity` and only `<colorStop>` children (`offset` and `color` required). Colors are any CSS color; alpha is ignored, use `opacity`. Each paint tag has a short alias (`<solid>`, `<linearGradient>`, `<radialGradient>`, `<stop>`); the SVG name overlap is unambiguous because tags resolve by environment. `<htmlPaint>` draws browser-laid-out HTML/SVG children into the node's box; the `<html>` element is shorthand for a `<rect>` carrying one.## Generated assetsdiff --git a/packages/jsx/src/index.ts b/packages/jsx/src/index.tsindex 2df7b90b..01aab8d6 100644--- a/packages/jsx/src/index.ts+++ b/packages/jsx/src/index.ts@@ -30,6 +30,7 @@ export type {GradientPaintProps,GroupProps,HtmlPaintProps,+ HtmlProps,ImageProps,Keyframe,PatchProps,diff --git a/packages/jsx/src/jsx-runtime.ts b/packages/jsx/src/jsx-runtime.tsindex 8fdd335d..f5f1e856 100644--- a/packages/jsx/src/jsx-runtime.ts+++ b/packages/jsx/src/jsx-runtime.ts@@ -17,6 +17,7 @@ import type {GradientPaintProps,GroupProps,HtmlPaintProps,+ HtmlProps,ImageProps,RectProps,SceneProps,@@ -27,7 +28,7 @@ import type {} from "./types";// "html" is dropped alongside the media tags: in composition context it is-// the <htmlPaint> alias, and as a DOM tag it is useless inside a paint host.+// the html node element, and as a DOM tag it is useless inside a paint host.type HtmlElementTags = Omit<SolidJSX.HTMLElementTags, "audio" | "video" | "html">;// SVG vocabulary for <htmlPaint> content. Tags the editor also declares keep@@ -66,6 +67,6 @@ export declare namespace JSX {colorStop: ColorStopProps;stop: ColorStopProps;htmlPaint: HtmlPaintProps;- html: HtmlPaintProps;+ html: HtmlProps;}}diff --git a/packages/jsx/src/types.ts b/packages/jsx/src/types.tsindex 7e85d1f1..206596f3 100644--- a/packages/jsx/src/types.ts+++ b/packages/jsx/src/types.ts@@ -295,6 +295,9 @@ export type HtmlPaintProps = Pick<PatchProps, "opacity"> & {children?: SolidJSX.Element;};+/** `<html>` — a rectangle carrying an `<htmlPaint>` with the given children. */+export type HtmlProps = CommonProps & Pick<HtmlPaintProps, "children">;+export type AudioProps = TimingProps &Required<Pick<PatchProps, "src">> &Pick<PatchProps, "name" | "volume" | "muted" | "syncTo" | "animations">;diff --git a/samples/reconciler/05-html-paint.tsx b/samples/reconciler/05-html-paint.tsxindex d291395f..8e3567d1 100644--- a/samples/reconciler/05-html-paint.tsx+++ b/samples/reconciler/05-html-paint.tsx@@ -7,12 +7,13 @@* not available in Electron 35, so use a supporting build): without it the* mount fails cleanly at <html> materialization.*- * The left <rect> is an ECS entity. Inside <html> (long form <htmlPaint>),- * <rect> is an SVG element (namespace inherited from <svg>), <div> is plain- * HTML, and the counter text updates reactively in the drawn DOM. Note the- * type-level approximation: shared tag names keep their composition prop- * types everywhere, so the SVG <rect> below sticks to numeric props that- * satisfy both sides.+ * The left <rect> is an ECS entity. <html> is a node too (a rect carrying an+ * <htmlPaint>), but its children are browser DOM: <rect> inside it is an SVG+ * element (namespace inherited from <svg>), <div> is plain HTML, and the+ * counter text updates reactively in the drawn DOM. Note the type-level+ * approximation: shared tag names keep their composition prop types+ * everywhere, so the SVG <rect> below sticks to numeric props that satisfy+ * both sides.*/import { createSignal } from "solid-js";@@ -24,17 +25,15 @@ export default () => (<scene key="sample-html" name="HTML paint" width={960} height={540} fill="#101014"><rect x={40} y={120} width={200} height={300} cornerRadius={16} fill="#22ccff" />- <rect x={280} y={60} width={640} height={420}>- <html>- <div style={{ color: "white", "font-family": "Inter", "font-size": "28px", padding: "16px" }}>- DOM counter: {n()}- </div>- <svg viewBox="0 0 200 100" width={640} height={320}>- <rect x={10} y={10} width={80} height={50} fill="#ff4466" />- <circle cx={140 + (n() % 3) * 15} cy={35} r={20} fill="#44dd88" />- <path d="M 10 80 H 190" stroke="#ffaa22" stroke-width={4} />- </svg>- </html>- </rect>+ <html x={280} y={60} width={640} height={420}>+ <div style={{ color: "white", "font-family": "Inter", "font-size": "28px", padding: "16px" }}>+ DOM counter: {n()}+ </div>+ <svg viewBox="0 0 200 100" width={640} height={320}>+ <rect x={10} y={10} width={80} height={50} fill="#ff4466" />+ <circle cx={140 + (n() % 3) * 15} cy={35} r={20} fill="#44dd88" />+ <path d="M 10 80 H 190" stroke="#ffaa22" stroke-width={4} />+ </svg>+ </html></scene>);diff --git a/samples/reconciler/06-anime-timeline.tsx b/samples/reconciler/06-anime-timeline.tsxnew file mode 100644index 00000000..3de6859d--- /dev/null+++ b/samples/reconciler/06-anime-timeline.tsx@@ -0,0 +1,88 @@+/* @jsxImportSource @diffusionstudio/jsx */+/* Anime.js timeline scrubbed by the playhead: one clock, two render worlds.+ *+ * dapi mount --live samples/reconciler/06-anime-timeline.tsx+ *+ * Needs the html-in-canvas API (see 05-html-paint.tsx). A paused anime.js+ * timeline tweens plain-object targets; a createEffect seeks it to the+ * scene playhead (looping over the timeline length) and mirrors the values+ * into a store. The same values drive an ECS chip on the canvas and a DOM+ * card drawn via <html>, so scrubbing or playing keeps both in lockstep,+ * including the shared hue. Deterministic: same playhead, same picture.+ */++import { createEffect } from "solid-js";+import { createStore } from "solid-js/store";+import { createTimeline } from "animejs";+import { useTicker } from "@diffusionstudio/jsx";++const chip = { x: -160, y: 190, rotation: -90, cornerRadius: 12, opacity: 0 };+const card = { rise: 90, opacity: 0, progress: 0, hue: 210 };++const tl = createTimeline({ autoplay: false })+ .add(chip, { x: 110, opacity: 1, duration: 1000, ease: "outElastic(1, .6)" }, 0)+ .add(chip, { rotation: 270, cornerRadius: 80, duration: 1400, ease: "inOutQuad" }, 1000)+ .add(chip, { cornerRadius: 12, rotation: 360, duration: 800, ease: "outBack" }, 2600)+ .add(card, { rise: 0, opacity: 1, duration: 800, ease: "outCubic" }, 200)+ .add(card, { progress: 100, duration: 2800, ease: "inOutSine" }, 500)+ .add(card, { hue: 570, duration: 3400, ease: "linear" }, 0);++export default () => {+ const { time } = useTicker();+ const [v, setV] = createStore({ chip: { ...chip }, card: { ...card } });++ createEffect(() => {+ tl.seek((time() * 1000) % tl.duration);+ setV("chip", { ...chip });+ setV("card", { ...card });+ });++ const hue = () => Math.round(v.card.hue);++ return (+ <scene key="sample-anime" name="Anime timeline" width={960} height={540} fill="#101014">+ <rect+ x={v.chip.x}+ y={v.chip.y}+ width={160}+ height={160}+ rotation={v.chip.rotation}+ cornerRadius={v.chip.cornerRadius}+ opacity={v.chip.opacity}+ fill={`hsl(${hue()} 90% 60%)`}+ />++ <html x={380} y={120} width={500} height={300}>+ <div+ style={{+ "font-family": "Inter",+ color: "white",+ padding: "28px 32px",+ transform: `translateY(${v.card.rise}px)`,+ opacity: v.card.opacity,+ }}+ >+ <div style={{ "font-size": "34px", "font-weight": "700", color: `hsl(${hue()} 90% 65%)` }}>+ DOM, meet timeline+ </div>+ <div style={{ "font-size": "18px", opacity: 0.7, margin: "6px 0 24px" }}>+ anime.js seeked from the playhead at t = {time().toFixed(2)}s+ </div>+ <div style={{ height: "14px", "border-radius": "7px", background: "#ffffff22" }}>+ <div+ style={{+ width: `${v.card.progress}%`,+ height: "100%",+ "border-radius": "7px",+ background: `linear-gradient(90deg, hsl(${hue() - 40} 90% 55%), hsl(${hue()} 90% 65%))`,+ }}+ />+ </div>+ <div style={{ "font-size": "16px", opacity: 0.6, "margin-top": "10px" }}>+ {Math.round(v.card.progress)}% through the loop+ </div>+ </div>+ </html>+ </scene>+ );+};diff --git a/samples/reconciler/07-anime-mini.tsx b/samples/reconciler/07-anime-mini.tsxnew file mode 100644index 00000000..412b3f39--- /dev/null+++ b/samples/reconciler/07-anime-mini.tsx@@ -0,0 +1,35 @@+/* @jsxImportSource @diffusionstudio/jsx */+/* Anime.js timeline scrubbed by the playhead: canvas and DOM in lockstep.+ * dapi mount --live samples/reconciler/07-anime-mini.tsx+ */+import { createEffect, createSignal } from "solid-js";+import { createTimeline } from "animejs";+import { useTicker } from "@diffusionstudio/jsx";++const box = { x: 60, spin: 0, pct: 0 };++export default function HtmlInCanvasDemo() {+ const { time } = useTicker();+ const [v, setV] = createSignal(box, { equals: false });++ const tl = createTimeline({ autoplay: false })+ .add(box, { x: 700, pct: 100, duration: 2400, ease: "inOutQuad" })+ .add(box, { spin: 360, duration: 900, ease: "outBack" });++ createEffect(() => {+ tl.seek((time() * 1000) % tl.duration);+ setV(box);+ });++ return (+ <scene key="sample-anime-mini" name="Anime mini" width={960} height={540} fill="#101014">+ <rect x={v().x} y={280} width={140} height={140} rotation={v().spin} cornerRadius={28} fill="#22ccff" />++ <html x={60} y={90} width={840} height={120} name="Live HTML">+ <div style="color: white; font-family: Inter; font-size: 60px; font-weight: 700">+ Timeline at <span style="color: #22ccff">{Math.round(v().pct)}%</span>+ </div>+ </html>+ </scene>+ );+};diff --git a/samples/reconciler/README.md b/samples/reconciler/README.mdindex cac52ee5..f6da5c14 100644--- a/samples/reconciler/README.md+++ b/samples/reconciler/README.md@@ -10,6 +10,8 @@ Run from the repo root with the editor open:| [03-live-list.tsx](03-live-list.tsx) | `dapi mount --live samples/reconciler/03-live-list.tsx` | \<For\> moves (reorder without recreate), list insert/remove || [04-ticker.tsx](04-ticker.tsx) | `dapi mount --live samples/reconciler/04-ticker.tsx` | useTicker playhead reactivity (press play) || [05-html-paint.tsx](05-html-paint.tsx) | `dapi mount --live samples/reconciler/05-html-paint.tsx` | DOM/SVG materialization under \<html\>; needs html-in-canvas |+| [06-anime-timeline.tsx](06-anime-timeline.tsx) | `dapi mount --live samples/reconciler/06-anime-timeline.tsx` | anime.js timeline seeked from useTicker, driving an ECS node and \<html\> content in lockstep |+| [07-anime-mini.tsx](07-anime-mini.tsx) | `dapi mount --live samples/reconciler/07-anime-mini.tsx` | minimal anime.js + useTicker sync, sized for a social post |Each root scene carries a stable key, so re-mounting a sample replaces itsscene in place. Inspect results with `dapi node tree`; entity ids in sample 03