Skip to content

The VS Code of video editing, built for agents.

TypeScript

Implement generating color functionality and enhance clip rendering

konstantin-paulusfa00825223b0
diff --git a/apps/web/src/engine/timeline/render/clip.ts b/apps/web/src/engine/timeline/render/clip.ts
index 5c1f31df..72dd8ab6 100644
--- a/apps/web/src/engine/timeline/render/clip.ts
+++ b/apps/web/src/engine/timeline/render/clip.ts
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-import { Caption, CaptionType, Chars, ClipDragOrigin, Computed, Hidden, Name, Selected, TrimDragOrigin, fitsChildren, isCaption, isGroup, isText, store } from '@diffusionstudio/runtime';
+import { Caption, CaptionType, Chars, ClipDragOrigin, Computed, Generating, Hidden, Name, Selected, TrimDragOrigin, fitsChildren, getGeneratingColor, isCaption, isGroup, isText, store } from '@diffusionstudio/runtime';
import { getDocumentEditor } from '../../editor';
import {
@@ -66,14 +66,18 @@ export function renderClip(
left = framesToPixels(computed.start[entity.id()] ?? 0, resolution);
}
+ const generating = entity.has(Generating);
+
ctx.save();
ctx.beginPath();
ctx.roundRect(left, 0, width, row.height, CLIP_CORNER_RADIUS);
- ctx.fillStyle = style.background;
+ ctx.fillStyle = generating ? getGeneratingColor(world) : style.background;
ctx.fill();
ctx.restore();
- renderContent(world, scene, surface, entity, asset, style, row);
+ if (!generating) {
+ renderContent(world, scene, surface, entity, asset, style, row);
+ }
renderLabel(world, scene, surface, entity, style.foreground, left, width, row);
@@ -259,8 +263,9 @@ function renderLabel(
const ctx = surface.ctx!;
// A caption's row is mostly its words; below a certain height the label
- // would be all there is room for, so the words win.
- if (isCaption(entity) && row.height < CLIP_BREAKPOINTS.sm) return;
+ // would be all there is room for, so the words win. One still generating
+ // has no words yet, so there is nothing for the label to crowd out.
+ if (isCaption(entity) && !entity.has(Generating) && row.height < CLIP_BREAKPOINTS.sm) return;
const label = clipLabel(entity);
if (!label) return;
@@ -305,6 +310,8 @@ const CAPTION_PRESETS: Record<CaptionType, string> = {
* naming the thing it is drawing is an edit nobody asked for.
*/
function clipLabel(entity: Entity): string {
+ if (entity.has(Generating)) return 'Generating...';
+
const name = entity.get(Name)?.value;
if (isCaption(entity)) {
diff --git a/packages/runtime/src/systems/render.ts b/packages/runtime/src/systems/render.ts
index 798c0546..fb71b950 100644
--- a/packages/runtime/src/systems/render.ts
+++ b/packages/runtime/src/systems/render.ts
@@ -9,7 +9,6 @@
// attaches its handlers.
import { Not, Or } from 'koota';
-import { cubicBezier } from 'animejs';
import { store } from '../world/store';
import {
@@ -22,13 +21,14 @@ import {
BlendMode, Effect, Transition, MixedCornerRadius,
LocalTransform, WorldTransform, Computed, Cache,
HtmlHostHandle, SurfaceHostHandle,
- Mode, Time, FrameRate, Camera, Background, RenderSurface,
+ Mode, FrameRate, Camera, Background, RenderSurface,
HitRegions,
Root,
} from '../traits';
import { getParentNode } from '../queries/hierarchy';
import { getViewMatrix } from '../queries/camera';
import { colorToHex } from '../utils/color';
+import { getGeneratingColor } from '../utils/generating';
import { applyStrokeStyle } from '../utils/stroke';
import { renderText } from '../utils/text';
import { getTransitionWindow } from '../utils/transition';
@@ -551,53 +551,12 @@ function renderStrokes(world: World, entity: Entity): void {
}
}
-/**
- * Pulse animation for entities with the Generating tag.
- *
- * Easing: cubic-bezier(0.52, 0.18, 0.56, 0.88)
- * Duration: 0.6s per half-cycle (alternating)
- * Delay: 0.2s before the first transition
- * Full cycle: 0.2 delay + 0.6 forward + 0.6 reverse = 1.4s
- * repeats ∞ for the entire gen phase (~4.5s)
- *
- * Pulses between --background (#1c1c1c) and --secondary (#292929).
- */
-const generatingEase = cubicBezier(0.52, 0.18, 0.56, 0.88);
-
-const GEN_DELAY = 200; // ms
-const GEN_DURATION = 600; // ms per half-cycle
-const GEN_CYCLE = GEN_DURATION * 2; // full forward+reverse cycle
-
-// Colors: #1c1c1c → rgb(28,28,28) and #292929 → rgb(41,41,41)
-const GEN_FROM_R = 28, GEN_FROM_G = 28, GEN_FROM_B = 28;
-const GEN_TO_R = 41, GEN_TO_G = 41, GEN_TO_B = 41;
-
+/** The pulse a node waiting on a generation is filled with (see `../utils/generating`). */
function renderGenerating(world: World, entity: Entity): void {
- const ctx = getCtx(world);
if (!entity.has(Generating)) return;
- const t = world.get(Time)?.now ?? 0;
-
- // Before initial delay → show base color
- const elapsed = t % (GEN_DELAY + GEN_CYCLE);
- let factor = 0;
-
- if (elapsed >= GEN_DELAY) {
- const cycleT = elapsed - GEN_DELAY;
- const half = cycleT % GEN_DURATION;
- const progress = half / GEN_DURATION;
- const eased = generatingEase(progress);
-
- // Alternate direction: first half forward, second half reverse
- const inReverse = cycleT >= GEN_DURATION;
- factor = inReverse ? 1 - eased : eased;
- }
-
- const r = Math.round(GEN_FROM_R + (GEN_TO_R - GEN_FROM_R) * factor);
- const g = Math.round(GEN_FROM_G + (GEN_TO_G - GEN_FROM_G) * factor);
- const b = Math.round(GEN_FROM_B + (GEN_TO_B - GEN_FROM_B) * factor);
-
- ctx.fillStyle = `rgb(${r},${g},${b})`;
+ const ctx = getCtx(world);
+ ctx.fillStyle = getGeneratingColor(world);
ctx.fill();
}
diff --git a/packages/runtime/src/utils/generating.ts b/packages/runtime/src/utils/generating.ts
new file mode 100644
index 00000000..044e4fec
--- /dev/null
+++ b/packages/runtime/src/utils/generating.ts
@@ -0,0 +1,60 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Pulse animation for entities with the Generating tag. Everything that draws
+ * one reads it from here — the stage and the timeline both — so a node
+ * waiting on a generation pulses in step wherever it is shown.
+ *
+ * Easing: cubic-bezier(0.52, 0.18, 0.56, 0.88)
+ * Duration: 0.6s per half-cycle (alternating)
+ * Delay: 0.2s before the first transition
+ * Full cycle: 0.2 delay + 0.6 forward + 0.6 reverse = 1.4s
+ * repeats ∞ for the entire gen phase (~4.5s)
+ *
+ * Pulses between --background (#1c1c1c) and --secondary (#292929).
+ */
+
+import { cubicBezier } from 'animejs';
+
+import { Time } from '../traits';
+
+import type { World } from 'koota';
+
+const generatingEase = cubicBezier(0.52, 0.18, 0.56, 0.88);
+
+const GEN_DELAY = 200; // ms
+const GEN_DURATION = 600; // ms per half-cycle
+const GEN_CYCLE = GEN_DURATION * 2; // full forward+reverse cycle
+
+// Colors: #1c1c1c → rgb(28,28,28) and #292929 → rgb(41,41,41)
+const GEN_FROM_R = 28, GEN_FROM_G = 28, GEN_FROM_B = 28;
+const GEN_TO_R = 41, GEN_TO_G = 41, GEN_TO_B = 41;
+
+/** Where the pulse stands on the world's clock: 0 at rest, 1 fully lit. */
+function generatingFactor(world: World): number {
+ const t = world.get(Time)?.now ?? 0;
+
+ // Before initial delay → show base color
+ const elapsed = t % (GEN_DELAY + GEN_CYCLE);
+ if (elapsed < GEN_DELAY) return 0;
+
+ const cycleT = elapsed - GEN_DELAY;
+ const half = cycleT % GEN_DURATION;
+ const eased = generatingEase(half / GEN_DURATION);
+
+ // Alternate direction: first half forward, second half reverse
+ return cycleT >= GEN_DURATION ? 1 - eased : eased;
+}
+
+/** The fill a node in generation is painted with this frame. */
+export function getGeneratingColor(world: World): string {
+ const factor = generatingFactor(world);
+
+ const r = Math.round(GEN_FROM_R + (GEN_TO_R - GEN_FROM_R) * factor);
+ const g = Math.round(GEN_FROM_G + (GEN_TO_G - GEN_FROM_G) * factor);
+ const b = Math.round(GEN_FROM_B + (GEN_TO_B - GEN_FROM_B) * factor);
+
+ return `rgb(${r},${g},${b})`;
+}
diff --git a/packages/runtime/src/utils/index.ts b/packages/runtime/src/utils/index.ts
index a89f8649..91e2e026 100644
--- a/packages/runtime/src/utils/index.ts
+++ b/packages/runtime/src/utils/index.ts
@@ -2,6 +2,7 @@
export * from './assert';
export * from './async';
export * from './color';
+export * from './generating';
export * from './text';
export * from './live-mounts';
export * from './sort';