The VS Code of video editing, built for agents.
TypeScript
Enhance InterpolationSettings integration in Inspector for improved keyframe management
konstantin-pauluse7ff64686adc
diff --git a/apps/web/src/components/sidebar-right/inspector/easing-types.ts b/apps/web/src/components/sidebar-right/inspector/easing-types.tsnew file mode 100644index 00000000..bfd25c13--- /dev/null+++ b/apps/web/src/components/sidebar-right/inspector/easing-types.ts@@ -0,0 +1,56 @@+/* 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/. */++import { EASINGS } from "@diffusionstudio/reconciler";++import type { Easing } from "@diffusionstudio/jsx";++/**+ * The easings the JSX has a word for, which are exactly the presets the+ * interpolation panel offers. `descriptor` is what the runtime stores for the+ * name (`EASINGS` is the one table mapping them, linear being the empty+ * string); the panel matches on it to know which preset a keyframe is set to,+ * and writes `name` back so the file reads `easing="easeOut"` rather than the+ * bezier behind it.+ */+export type EasingPreset = {+ name: Easing;+ label: string;+ descriptor: string;+};++const preset = (name: Easing, label: string): EasingPreset => ({+ name,+ label,+ descriptor: EASINGS[name] ?? name,+});++export const EASE_PRESETS: EasingPreset[] = [+ preset("linear", "Linear"),+ preset("easeIn", "Ease In"),+ preset("easeOut", "Ease Out"),+ preset("easeInOut", "Ease In & Out"),+];++export const SPRING_PRESETS: EasingPreset[] = [+ preset("gentle", "Gentle"),+ preset("snappy", "Snappy"),+ preset("bouncy", "Bouncy"),+ preset("strong", "Strong"),+];++/** What the Spring tab starts a keyframe at. */+export const DEFAULT_SPRING: EasingPreset = SPRING_PRESETS[0]!;++/** `<keyframe>`'s default: absent easing is linear. */+export const LINEAR: EasingPreset = EASE_PRESETS[0]!;++const BY_DESCRIPTOR = new Map<string, EasingPreset>(+ [...EASE_PRESETS, ...SPRING_PRESETS].map((option) => [option.descriptor, option]),+);++/** The named easing a descriptor is, or null for one the JSX can only spell out. */+export function easingPreset(descriptor: string): EasingPreset | null {+ return BY_DESCRIPTOR.get(descriptor) ?? null;+}diff --git a/apps/web/src/components/sidebar-right/inspector/inspector.tsx b/apps/web/src/components/sidebar-right/inspector/inspector.tsxindex 28f031b9..f5ca15c9 100644--- a/apps/web/src/components/sidebar-right/inspector/inspector.tsx+++ b/apps/web/src/components/sidebar-right/inspector/inspector.tsx@@ -38,7 +38,7 @@ import { AnimationsSettings } from "./animations";import { TransitionSettings } from "./transition";import { MasksSettings } from "./masks";import { AudioSettings } from "./audio";-// import { InterpolationSettings } from "./interpolation";+import { InterpolationSettings } from "./interpolation";import type { Entity } from "koota";@@ -70,8 +70,6 @@ function classifyNode(entity: Entity): SelectionTarget {return "stage";}-// Panels still on the bitecs world are commented out below; each comes back-// in place as it moves onto the koota world.export function Inspector() {const tool = useTool();const { nodes, keyframes, first } = useSelection();@@ -185,9 +183,9 @@ export function Inspector() {<AssetInfoPanel /></Show>- {/* <Show when={includesTarget("keyframe")}>- <InterpolationSettings />- </Show> */}+ <Show when={includesTarget("keyframe")}>+ <InterpolationSettings selection={keyframes()} />+ </Show></ControlScrollArea></Show></div>diff --git a/apps/web/src/components/sidebar-right/inspector/interpolation.tsx b/apps/web/src/components/sidebar-right/inspector/interpolation.tsxindex 8e5c262c..b86bd6f9 100644--- a/apps/web/src/components/sidebar-right/inspector/interpolation.tsx+++ b/apps/web/src/components/sidebar-right/inspector/interpolation.tsx@@ -17,24 +17,25 @@ import {SelectValue,} from "@/components/ui/select";import { SegmentedIconTabs } from "@/components/ui/segmented-icon-tabs";-import { useEngine } from "@/context/engine";-import { useECS } from "@/context/ecs";---import { setComponent } from '@/components/engine';-type InterpolationType = "hold" | "ease" | "spring";--type EasePreset = {- label: string;- value: string;+import { useTrait } from "@diffusionstudio/koota-solid";+import { Keyframe } from "@diffusionstudio/runtime";+import { useEditor } from "@/engine/hooks";+import {+ DEFAULT_SPRING,+ EASE_PRESETS,+ LINEAR,+ SPRING_PRESETS,+ easingPreset,+} from "./easing-types";++import type { EasingPreset } from "./easing-types";+import type { Entity } from "koota";++type InterpolationSettingsProps = {+ selection: Entity[];};-const EASE_PRESETS: EasePreset[] = [- { label: "Linear", value: "" },- { label: "Ease In", value: "cubicBezier(0.42,0,1,1)" },- { label: "Ease Out", value: "cubicBezier(0,0,0.58,1)" },- { label: "Ease In & Out", value: "cubicBezier(0.42,0,0.58,1)" },-];+type InterpolationType = "hold" | "ease" | "spring";function getEasingType(easing: string): InterpolationType {if (easing.startsWith("steps(")) return "hold";@@ -68,79 +69,76 @@ function parseSpring(easing: string): { bounce: number; duration: number } {return { bounce: parseFloat(match[1]), duration: parseFloat(match[2]) };}-type SpringPreset = {- label: string;- value: { bounce: number; duration: number };-};--const SPRING_PRESETS: SpringPreset[] = [- { label: "Gentle", value: { bounce: 0.5, duration: 628 } },- { label: "Snappy", value: { bounce: 0.15, duration: 300 } },- { label: "Bouncy", value: { bounce: 0.4, duration: 500 } },- { label: "Strong", value: { bounce: 0.65, duration: 400 } },-];-function springToString(bounce: number, duration: number): string {return `spring(${bounce},${duration})`;}-function findSpringPreset(- bounce: number,- duration: number,-): SpringPreset | undefined {- return SPRING_PRESETS.find(- (p) => p.value.bounce === bounce && p.value.duration === duration,- );+function bezierToString(points: [number, number, number, number]): string {+ const [x1, y1, x2, y2] = points;+ const isLinear = x1 === 0 && y1 === 0 && x2 === 1 && y2 === 1;+ return isLinear ? LINEAR.descriptor : `cubicBezier(${x1},${y1},${x2},${y2})`;}function formatBezier(points: [number, number, number, number]): string {return points.map((p) => p.toFixed(2)).join(", ");}-function findPreset(easing: string): EasePreset | undefined {- return EASE_PRESETS.find((p) => p.value === easing);-}--export function InterpolationSettings() {- const { world } = useEngine();- const { selectedKeyframes } = useECS();- const c = world.components;-- // Bump to force currentEasing memo to re-read ECS after local mutations- const [easingVersion, setEasingVersion] = createSignal(0);-- const currentEasing = createMemo(() => {- easingVersion(); // reactive dependency on local mutations- const set = selectedKeyframes();- const kid = set.values().next().value;- return world.components.Keyframe.easing[kid ?? -1] ?? "";- });+/**+ * The easing of the selected keyframes: which segment shape they use and its+ * parameters. What a `<keyframe>` says is one `easing` prop, either a named+ * preset or the descriptor spelled out, so a curve dragged by hand travels as+ * `cubicBezier(...)` while the four ease and four spring presets travel as+ * their names. Linear is `<keyframe>`'s default and so is unset rather than+ * written.+ *+ * The panel shows the first selected keyframe and writes to all of them, the+ * way it always has: a multi-selection is being set to one easing, not being+ * asked what each of them says.+ */+export function InterpolationSettings(props: InterpolationSettingsProps) {+ const editor = useEditor();++ const keyframe = useTrait(() => props.selection[0], Keyframe);+ const currentEasing = () => keyframe()?.easing ?? LINEAR.descriptor;const activeTab = createMemo(() => getEasingType(currentEasing()));const bezierPoints = createMemo(() => parseBezier(currentEasing()));const stepsCount = createMemo(() => parseSteps(currentEasing()));- const currentPreset = createMemo(() => findPreset(currentEasing()) ?? null);+ const currentPreset = createMemo(+ () => EASE_PRESETS.find((p) => p.descriptor === currentEasing()) ?? null,+ );const springParams = createMemo(() => parseSpring(currentEasing()));- const currentSpringPreset = createMemo(- () => findSpringPreset(springParams().bounce, springParams().duration) ?? null,- );+ // Matched on the numbers rather than on the descriptor, so a file spelling+ // one of them as `spring(0.50,628)` still reads as the preset it is.+ const currentSpringPreset = createMemo(() => {+ const { bounce, duration } = springParams();+ return SPRING_PRESETS.find((p) => {+ const preset = parseSpring(p.descriptor);+ return preset.bounce === bounce && preset.duration === duration;+ }) ?? null;+ });++ /**+ * Writes `descriptor` to every selected keyframe, named where the JSX has a+ * word for it. Linear is the prop's default, so it unsets instead.+ */+ const setEasingForAll = (descriptor: string) => {+ const named = easingPreset(descriptor);+ const value = named === LINEAR ? false : (named?.name ?? descriptor);+ for (const entity of props.selection) {+ editor.editProperty(entity, "easing", value);+ }+ };const setSpringBounce = (bounce: number) =>setEasingForAll(springToString(Math.max(BOUNCE_MIN, Math.min(BOUNCE_MAX, Math.round(bounce * 100) / 100)), springParams().duration));const setSpringDuration = (duration: number) =>setEasingForAll(springToString(springParams().bounce, Math.max(DURATION_MIN, Math.min(DURATION_MAX, Math.round(duration)))));- const handleSpringPresetChange = (preset: SpringPreset | null) => {+ const handlePresetChange = (preset: EasingPreset | null) => {if (!preset) return;- setEasingForAll(springToString(preset.value.bounce, preset.value.duration));- };-- const setEasingForAll = (easing: string) => {- for (const kid of selectedKeyframes()) {- setComponent(world, kid, c.Keyframe, { easing });- }- setEasingVersion((v) => v + 1);+ setEasingForAll(preset.descriptor);};const handleTabChange = (tab: InterpolationType) => {@@ -150,41 +148,22 @@ export function InterpolationSettings() {setEasingForAll("steps(1)");break;case "ease":- setEasingForAll("");+ setEasingForAll(LINEAR.descriptor);break;case "spring":- setEasingForAll("spring(0.5,628)");+ setEasingForAll(DEFAULT_SPRING.descriptor);break;}};- const handlePresetChange = (preset: EasePreset | null) => {- if (!preset) return;- setEasingForAll(preset.value);- };-const setBezierPoints = (points: [number, number, number, number]) => {- const [x1, y1, x2, y2] = points;- const isLinear = x1 === 0 && y1 === 0 && x2 === 1 && y2 === 1;- const easing = isLinear ? "" : `cubicBezier(${x1},${y1},${x2},${y2})`;- for (const kid of selectedKeyframes()) {- setComponent(world, kid, c.Keyframe, { easing });- }- setEasingVersion((v) => v + 1);+ setEasingForAll(bezierToString(points));};const handleBezierInput = (raw: string) => {- const parts = raw- .split(",")- .map((s) => parseFloat(s.trim()));+ const parts = raw.split(",").map((s) => parseFloat(s.trim()));if (parts.length !== 4 || parts.some((p) => isNaN(p))) return;- const [x1, y1, x2, y2] = parts;- const isLinear =- x1 === 0 && y1 === 0 && x2 === 1 && y2 === 1;- const easing = isLinear- ? ""- : `cubicBezier(${x1},${y1},${x2},${y2})`;- setEasingForAll(easing);+ setBezierPoints(parts as [number, number, number, number]);};const TAB_ITEMS = [@@ -248,11 +227,11 @@ export function InterpolationSettings() {<div class="flex flex-col gap-2 pt-1"><ControlRow label="Ease">- <Select<EasePreset>+ <Select<EasingPreset>value={currentPreset()}onChange={handlePresetChange}options={EASE_PRESETS}- optionValue="value"+ optionValue="name"optionTextValue="label"placeholder="Custom"itemComponent={(itemProps) => (@@ -262,7 +241,7 @@ export function InterpolationSettings() {)}><SelectTrigger>- <SelectValue<EasePreset> class="text-xs">+ <SelectValue<EasingPreset> class="text-xs">{(state) => state.selectedOption()?.label ?? "Custom"}</SelectValue></SelectTrigger>@@ -302,11 +281,11 @@ export function InterpolationSettings() {<div class="flex flex-col gap-2 pt-1"><ControlRow label="Spring">- <Select<SpringPreset>+ <Select<EasingPreset>value={currentSpringPreset()}- onChange={handleSpringPresetChange}+ onChange={handlePresetChange}options={SPRING_PRESETS}- optionValue="label"+ optionValue="name"optionTextValue="label"placeholder="Custom"itemComponent={(itemProps) => (@@ -316,7 +295,7 @@ export function InterpolationSettings() {)}><SelectTrigger>- <SelectValue<SpringPreset> class="text-xs">+ <SelectValue<EasingPreset> class="text-xs">{(state) => state.selectedOption()?.label ?? "Custom"}</SelectValue></SelectTrigger>diff --git a/packages/reconciler/src/document.ts b/packages/reconciler/src/document.tsindex 4daeb966..e5558412 100644--- a/packages/reconciler/src/document.ts+++ b/packages/reconciler/src/document.ts@@ -240,7 +240,7 @@ const CORNER_PROPS = ['cornerRadiusTopLeft', 'cornerRadiusTopRight', 'cornerRadi* interpolation inspector) speak; the descriptor forms pass through with* their whitespace dropped, linear is the empty string.*/-const EASINGS: Record<string, string> = {+export const EASINGS: Record<string, string> = {linear: '',easeIn: 'cubicBezier(0.42,0,1,1)',easeOut: 'cubicBezier(0,0,0.58,1)',diff --git a/packages/runtime/MIGRATION.md b/packages/runtime/MIGRATION.mdindex 1bb54957..c9955578 100644--- a/packages/runtime/MIGRATION.md+++ b/packages/runtime/MIGRATION.md@@ -76,7 +76,7 @@ Done:| Draw tools + toolbar (armed tool is the `Tool` world trait) | `components/canvas/draw-overlay.tsx` || Input, HUD, camera, alignment | `engine/input/`, `engine/hud/`, `engine/align.ts` || Project config (per-scene export settings in package.json) | `engine/project-config.ts` |-| Panels: header, background, scene template, asset info, time, appearance, alignment, export, layout, text, strokes, shadows, effects, animations, transition, masks, audio, fills, transform, caption | `components/sidebar-right/inspector/` |+| Panels: all of them (header, background, scene template, asset info, time, appearance, alignment, export, layout, text, strokes, shadows, effects, animations, transition, masks, audio, fills, transform, caption, interpolation) | `components/sidebar-right/inspector/` || Local font families (web fonts and loading are the runtime's) | `engine/fonts.ts` (`getLocalFonts`) |Hosted JSX surface is `COMPOSITION_TAGS` (`packages/jsx/src/source.ts`): the structural tags, the media tags, `<captions>`, the paint family, `<stroke>`, `<shadow>`, `<effect>`, `<animation>`, `<keyframeTrack>`/`<keyframe>`, `<html>`/`<surface>`. `mask` is a `<rect>` prop, not a tag.@@ -87,7 +87,7 @@ Conventions worth repeating when migrating the next panel:- Writes go through `editor.editProperty` in JSX vocabulary. `false` is the value the writer removes an attribute for, so a default is unset rather than written.- `syncKeyframe` after a prop write keeps an existing track in step, since the motion system would otherwise overwrite the edit next tick. **Exception:** `width`/`height` sync *before* the write, because the document's handler is `resizeEntity`, which syncs the track itself and would mint an unsourced keyframe first. The canvas resize in `engine/input/interactions.ts` has the same gap, unfixed.- State with no JSX spelling (`KeepAspectRatio`, `ClipsContent`, `Skew`) is written to the trait alone and does not survive a recompile. Giving any of them a prop is a separate decision; a lock snapshot would then have to come from the authored size, not from whatever `Size` holds at mount.-- Panels still on bitecs import the diamond from `components/ui/keyframe-bitecs.tsx` until they move.+- `components/ui/keyframe-bitecs.tsx` has one importer left, the timeline's keyframe layer; it goes when that moves.- A picker that previews on hover writes the trait alone, so while it is open the trait holds the hover and not the authored value. Keep the authored one in a signal seeded at mount (panels remount per selection) and move it only on a selection: it is what the control displays *and* what the close restores. Reading it back off the trait restores the hover instead, permanently. `AppearanceSettings`' blend mode and the text panel's family/weight both do this.- What a `<text>` says is its children, not a prop, so it travels as its own edit end to end: `editor.editText` -> `TextEdit` -> the writer's `SourceSet.text` -> `RuntimeDocument.setText`. The document keeps the reconciler's text nodes: the first says all of it and the rest say nothing, so a project that later re-renders one of them still lands.- A text is the one element whose box is optional (`Size` absent = sized to its glyphs), so the text panel's "Grow" toggle is `width`/`height` being authored at all. Unsetting a bound drops `Size` only once neither is left, which is why the toggle writes `width` before `height`.@@ -95,7 +95,7 @@ Conventions worth repeating when migrating the next panel:- Reordering siblings is a swap through `editor.reparent`, not an index write: `ItemIndex` is the document's to assign (`insertNode` renumbers the whole sibling list), and a move needs an anchor, since `reparent` appends without one and refuses an append into the parent the element already has. So "move later" moves the *next* sibling in front of this one.- A shared control that knows *which* prop it edits keyframes it itself, off an `Entity` (`ColorOpacityPicker`'s `keyframeTarget`, now koota's); only a control that cannot know takes the diamond as a slot (`ControlledTextField`, `ColorOpacityRow`). Moving one of these moves it whole: the bitecs panels still calling it lose their diamonds until they migrate, and its recent-colors palette now queries the koota world for them too (both providers are mounted).-Still on bitecs: the interpolation panel; the timeline's keyframe layer; the whole timeline UI. Auto-captions (`components/genai/use-auto-captions.ts`) is still bitecs too, so nothing in the app *creates* a caption on the koota side yet: a `<captions>` element reaches the world by being written in a project file.+Still on bitecs: the timeline's keyframe layer and the whole timeline UI, plus auto-captions (`components/genai/use-auto-captions.ts`). Two of the panels are therefore complete but unreachable until those move: nothing on the koota side *creates* a caption (a `<captions>` element gets into the world by being written in a project file) and nothing *selects* a keyframe (only nodes and scenes are selected, by the canvas).The stroke panel moved with the model: `StrokeStyle` is the stroke's, not the node's (as `<stroke width join cap miterLimit>` always was), so Weight/Join/Miter sit under each stroke's row instead of once per node. `<stroke>` is a solid paint that takes no paint children, so its picker is the color one alone, with no gradient or asset tab and no `FillPicker` behind it. `cap` still has no control (it shows only on open paths, and there are no icons for it).@@ -143,11 +143,17 @@ Worth knowing: `placeCaption` returns false when `getParentNode` is null, so a `Still narrower than the inspector: `CaptionsProps` declares timing, offset, `src` and the three above, while the inspector also shows layout, appearance, text, fills, strokes, shadows and effects for a caption target. Those write props `<captions>` does not have, so the file they produce would not typecheck. Settling that (widen the element, or narrow the panel list) is its own decision and was left alone.+The interpolation panel is a plain port: `<keyframe easing>` was already hosted, and the widgets under it (the bezier, spring and step curves, and the preview) never touched the ECS, so only the top of the file moved. What changed is the vocabulary. The panel's four ease presets and four spring presets **are** the eight easings the JSX has names for, and `EASINGS` (now exported from the reconciler) is the one table mapping name to descriptor, so `easing-types.ts` builds both preset lists off it rather than restating the beziers. A preset is written back as its name, so the file reads `easing="easeOut"` and `easing="bouncy"`; a curve dragged by hand has no name and travels as `cubicBezier(...)`, a hold as `steps(n)`. Linear is `<keyframe>`'s default and unsets. The `easingVersion` signal the bitecs panel bumped after every write is gone: a koota `set` fires a change event, which is what `useTrait` is waiting for.++Which spring preset is showing is matched on the parsed numbers, not on the descriptor string, so a file spelling one as `spring(0.50,628)` still reads as Gentle; everything the panel writes itself is canonical, so the write side matches on the string.++**A decision the timeline slice has to make**: `useSelection` splits the `Selected` query on `has(Keyframe)`, so a selected keyframe is how this panel is reached — but `editor.setSelected` reports `selected` as a prop edit for anything it selects, and `KeyframeProps` has no `selected`. Whoever moves the keyframe layer either gives `<keyframe>` the prop (as `<captions>` was given `IdentityProps`) or stops reporting selection for sub-entities. For a keyframe the second looks right: unlike a node's, the selection is momentary, there can be dozens of them, and persisting it would churn the source on every click in the timeline.+**Left stale on purpose** (deferred to a docs/examples pass): the eight `examples/*.tsx` still open with `<rect scene="...">` and no `<stage>`, so `tsc -p examples --noEmit` fails on them, and `reference/jsx/*` still describes the pre-`<stage>` model and `key` as the `syncTo` target. `reference/jsx` is stale as a whole; patching rows piecemeal would hide that.## Remaining work-1. **apps/web**: remaining panels and the timeline UI, app-side world traits (store, timelineIndex signal), history via koota events, re-adding the editing-surface `syncKeyframeTrack` calls the observers slice dropped. `utils/captions.ts` stays app-side, rewired to `@diffusionstudio/encoder`. Once real content loads into the koota world, delete the hidden bitecs canvas and `engine/components`, `engine/api` progressively.+1. **apps/web**: the timeline UI (its keyframe layer included) and auto-captions, app-side world traits (store, timelineIndex signal), history via koota events, re-adding the editing-surface `syncKeyframeTrack` calls the observers slice dropped. The inspector panels are all across. `utils/captions.ts` stays app-side, rewired to `@diffusionstudio/encoder`. Once real content loads into the koota world, delete the hidden bitecs canvas and `engine/components`, `engine/api` progressively.2. **CLI**: point node capture at the runtime + encoder packages, importing `MAX_FRAMES_PER_SHEET` from the encoder instead of redefining it in `cli-channels.ts`.## Package reminders