Skip to content

The VS Code of video editing, built for agents.

TypeScript

Integrate TransitionSettings into Inspector for enhanced transition management

konstantin-paulusedc79c417301
diff --git a/apps/web/src/components/sidebar-right/inspector/inspector.tsx b/apps/web/src/components/sidebar-right/inspector/inspector.tsx
index fd46f0af..76dff123 100644
--- a/apps/web/src/components/sidebar-right/inspector/inspector.tsx
+++ b/apps/web/src/components/sidebar-right/inspector/inspector.tsx
@@ -35,7 +35,7 @@ import { StrokesSettings } from "./strokes";
import { ShadowsSettings } from "./shadows";
import { EffectsSettings } from "./effects";
import { AnimationsSettings } from "./animations";
-// import { TransitionSettings } from "./transition";
+import { TransitionSettings } from "./transition";
// import { MasksSettings } from "./masks";
// import { AudioSettings } from "./audio";
// import { InterpolationSettings } from "./interpolation";
@@ -80,10 +80,10 @@ export function Inspector() {
// For ExportPanel (root scenes only) and TransitionSettings (sequence items).
const parent = createMemo(() => getParentNode(first()));
const isNested = createMemo(() => parent() !== null);
- // const isSequenceChild = createMemo(() => {
- // const entity = parent();
- // return entity !== null && isSequence(entity);
- // });
+ const isSequenceChild = createMemo(() => {
+ const entity = parent();
+ return entity !== null && isSequence(entity);
+ });
const selectionTarget = createMemo<SelectionTarget>(() => {
if (tool() === ToolType.SCENE) return "scene-tool";
@@ -169,9 +169,9 @@ export function Inspector() {
<AnimationsSettings selection={nodes()} />
</Show>
- {/* <Show when={includesTarget("shape") && isSequenceChild()}>
+ <Show when={includesTarget("shape") && isSequenceChild()}>
<TransitionSettings selection={nodes()} />
- </Show> */}
+ </Show>
{/* <Show when={includesTarget("shape", "text", "caption", "group")}>
<MasksSettings selection={nodes()} />
diff --git a/apps/web/src/components/sidebar-right/inspector/transition-types.ts b/apps/web/src/components/sidebar-right/inspector/transition-types.ts
new file mode 100644
index 00000000..e5ae0ef5
--- /dev/null
+++ b/apps/web/src/components/sidebar-right/inspector/transition-types.ts
@@ -0,0 +1,39 @@
+/* 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 { TRANSITION_TYPES } from "@diffusionstudio/reconciler";
+
+import type { TransitionType as TransitionName } from "@diffusionstudio/jsx";
+import type { TransitionType } from "@diffusionstudio/runtime";
+
+export type TransitionOption = {
+ name: TransitionName;
+ label: string;
+};
+
+/** The transition styles, in menu order. */
+export const TRANSITION_OPTIONS: TransitionOption[] = [
+ { name: "dissolve", label: "Dissolve" },
+ { name: "slideFromRight", label: "Slide From Right" },
+ { name: "slideFromLeft", label: "Slide From Left" },
+ { name: "fadeToBlack", label: "Fade To Black" },
+ { name: "fadeToWhite", label: "Fade To White" },
+];
+
+/** What the panel's plus authors: a one second dissolve, the prop's own defaults. */
+export const DEFAULT_TRANSITION: TransitionOption = TRANSITION_OPTIONS[0]!;
+export const DEFAULT_TRANSITION_DURATION = 1;
+
+const BY_TYPE = new Map<TransitionType, TransitionOption>(
+ TRANSITION_OPTIONS.map((option) => [TRANSITION_TYPES[option.name]!, option]),
+);
+
+/**
+ * The option for the type a `Transition` trait holds. Identity matters: the
+ * type select compares its value against the array it was given, so this
+ * hands back the option itself rather than a copy.
+ */
+export function transitionOption(type: TransitionType | undefined): TransitionOption {
+ return (type === undefined ? undefined : BY_TYPE.get(type)) ?? DEFAULT_TRANSITION;
+}
diff --git a/apps/web/src/components/sidebar-right/inspector/transition.tsx b/apps/web/src/components/sidebar-right/inspector/transition.tsx
index b997c7b1..491b2f2c 100644
--- a/apps/web/src/components/sidebar-right/inspector/transition.tsx
+++ b/apps/web/src/components/sidebar-right/inspector/transition.tsx
@@ -2,90 +2,96 @@
* 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 { Show, createMemo, createSignal } from "solid-js";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { ControlRow } from "@/components/ui/control-group";
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuPortal,
- DropdownMenuTrigger,
-} from "@/components/ui/dropdown-menu";
import {
FloatingInspector,
FloatingInspectorContent,
FloatingInspectorHeader,
FloatingInspectorSeparator,
- FloatingInspectorTitle,
} from "@/components/ui/floating-inspector";
import { Icon } from "@/components/ui/icon";
import { ItemRow } from "@/components/ui/item-row";
import { PanelSection } from "@/components/ui/panel-section";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectPortal,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
import { SliderInput } from "@/components/ui/slider-input";
-import { For, Show, createMemo, createSignal } from "solid-js";
-
-import { useEntityState, useEntityTag, TransitionType, removeComponent, setComponent } from "@/components/engine";
-import { useEngine } from "@/context/engine";
-import { secondsToFrames } from "@/components/engine/utils/time";
+import { useHas, useTrait, useWorld } from "@diffusionstudio/koota-solid";
+import { FrameRate, Transition, framesToSeconds } from "@diffusionstudio/runtime";
+import { useEditor } from "@/engine/hooks";
+import {
+ DEFAULT_TRANSITION,
+ DEFAULT_TRANSITION_DURATION,
+ TRANSITION_OPTIONS,
+ transitionOption,
+} from "./transition-types";
+import type { TransitionOption } from "./transition-types";
+import type { Entity } from "koota";
type TransitionSettingsProps = {
- selection: Set<number>;
-};
-
-const TRANSITION_OPTIONS = Object.values(TransitionType).filter(
- (v): v is TransitionType => typeof v === "number",
-);
-
-const TRANSITION_LABELS: Record<TransitionType, string> = {
- [TransitionType.DISSOLVE]: "Dissolve",
- [TransitionType.SLIDE_FROM_RIGHT]: "Slide From Right",
- [TransitionType.SLIDE_FROM_LEFT]: "Slide From Left",
- [TransitionType.FADE_TO_BLACK]: "Fade To Black",
- [TransitionType.FADE_TO_WHITE]: "Fade To White",
+ selection: Entity[];
};
+/**
+ * The clip's `transition`: how it comes in from the one before it, rendered
+ * centered on the cut. A prop rather than a child element, and one per clip,
+ * so the panel is a single row and its plus goes once a transition is there.
+ *
+ * The prop is written whole, both fields every time. The document merges a
+ * partial into the transition already set while the file would spell only
+ * what it was handed, so a partial write would leave the two saying
+ * different things; a transition is two settings and the panel shows both.
+ */
export function TransitionSettings(props: TransitionSettingsProps) {
- const { world } = useEngine();
- const [isInspectorOpen, setIsInspectorOpen] = createSignal(false);
+ const world = useWorld();
+ const editor = useEditor();
+ const entity = () => props.selection[0]!;
- const c = world.components;
- let anchorRef: HTMLDivElement | undefined;
+ let anchorRef!: HTMLDivElement;
- const eid = () => props.selection.values().next().value!;
+ const [open, setOpen] = createSignal(false);
- const hasTransition = useEntityTag(c.Transition, eid);
- const transitionType = useEntityState(c.Transition.type, eid, TransitionType.DISSOLVE);
- const transitionDuration = useEntityState(c.Transition.duration, eid, world.frameRate);
- const transitionDurationInSeconds = createMemo(() => transitionDuration() / world.frameRate);
+ const transition = useTrait(entity, Transition);
+ const has = useHas(entity, Transition);
+ const frameRate = useTrait(world, FrameRate);
+
+ const option = createMemo(() => transitionOption(transition()?.type));
+ const duration = createMemo(() =>
+ framesToSeconds(transition()?.duration ?? 0, frameRate()?.value ?? 30),
+ );
- const transitionLabel = createMemo(() => {
- if (!hasTransition()) return "";
- return TRANSITION_LABELS[transitionType() as TransitionType] ?? "Dissolve";
- });
+ const write = (type: TransitionOption, seconds: number) => {
+ editor.editProperty(entity(), "transition", { type: type.name, duration: seconds });
+ };
- const handleSetTransition = (type: TransitionType) => {
- setComponent(world, eid(), c.Transition, {
- duration: world.frameRate,
- type,
- });
+ const handleAddTransition = () => {
+ write(DEFAULT_TRANSITION, DEFAULT_TRANSITION_DURATION);
+ setOpen(true);
};
const handleRemoveTransition = () => {
- removeComponent(world, eid(), c.Transition);
- setIsInspectorOpen(false);
+ // `false` is what the writer spells as the attribute's absence; the
+ // document reads anything but an object as "no transition".
+ editor.editProperty(entity(), "transition", false);
+ setOpen(false);
};
- const handleSetDuration = (durationSec: number) => {
- setComponent(world, eid(), c.Transition, {
- duration: secondsToFrames(durationSec),
- });
+ const handleTypeChange = (next: TransitionOption | null) => {
+ if (next === null || next.name === option().name) return;
+ write(next, duration());
};
- const openInspector = () => {
- if (!hasTransition()) return;
- setIsInspectorOpen(true);
+ const handleDurationChange = (seconds: number) => {
+ write(option(), Math.round(seconds * 10) / 10);
};
return (
@@ -94,48 +100,28 @@ export function TransitionSettings(props: TransitionSettingsProps) {
title="Transition"
ref={anchorRef}
actions={
- <DropdownMenu placement="bottom-end">
+ <Show when={!has()}>
<Tooltip>
- <TooltipTrigger<typeof DropdownMenuTrigger>
- as={(triggerProps: object) => (
- <DropdownMenuTrigger<typeof Button>
- {...triggerProps}
- as={(buttonProps) => (
- <Button
- size="icon"
- variant="ghost"
- class="text-muted-foreground"
- disabled={!eid()}
- {...buttonProps}
- >
- <Icon name="plus-add" />
- </Button>
- )}
- />
- )}
- />
+ <TooltipTrigger
+ as={Button}
+ size="icon"
+ variant="ghost"
+ class="text-muted-foreground"
+ onClick={handleAddTransition}
+ >
+ <Icon name="plus-add" />
+ </TooltipTrigger>
<TooltipContent>Add transition</TooltipContent>
</Tooltip>
- <DropdownMenuPortal>
- <DropdownMenuContent class="w-44">
- <For each={TRANSITION_OPTIONS}>
- {(type) => (
- <DropdownMenuItem onSelect={() => handleSetTransition(type)}>
- {TRANSITION_LABELS[type]}
- </DropdownMenuItem>
- )}
- </For>
- </DropdownMenuContent>
- </DropdownMenuPortal>
- </DropdownMenu>
+ </Show>
}
>
- <Show when={hasTransition()}>
+ <Show when={has()}>
<ItemRow
label="Type"
- value={transitionLabel()}
+ value={option().label}
icon={<Icon name="video-transition" />}
- onClick={() => openInspector()}
+ onClick={() => setOpen(true)}
>
<Tooltip>
<TooltipTrigger
@@ -153,17 +139,35 @@ export function TransitionSettings(props: TransitionSettingsProps) {
</Show>
</PanelSection>
- <Show when={isInspectorOpen() && hasTransition()}>
- <FloatingInspector open={true} anchorRef={() => anchorRef} width={248}>
- <FloatingInspectorHeader class="items-center justify-between">
- <FloatingInspectorTitle>{transitionLabel()}</FloatingInspectorTitle>
+ <Show when={open() && has()}>
+ <FloatingInspector open anchorRef={anchorRef} width={248}>
+ <FloatingInspectorHeader class="items-center justify-between px-2">
+ <Select<TransitionOption>
+ value={option()}
+ onChange={handleTypeChange}
+ options={TRANSITION_OPTIONS}
+ optionValue="name"
+ optionTextValue="label"
+ itemComponent={(itemProps) => (
+ <SelectItem item={itemProps.item}>{itemProps.item.rawValue.label}</SelectItem>
+ )}
+ >
+ <SelectTrigger>
+ <SelectValue<TransitionOption>>
+ {(state) => state.selectedOption()?.label}
+ </SelectValue>
+ </SelectTrigger>
+ <SelectPortal>
+ <SelectContent class="w-44" />
+ </SelectPortal>
+ </Select>
<Tooltip>
<TooltipTrigger
as={Button}
size="icon"
variant="ghost"
class="text-muted-foreground"
- onClick={() => setIsInspectorOpen(false)}
+ onClick={() => setOpen(false)}
>
<Icon name="close-remove" />
</TooltipTrigger>
@@ -174,14 +178,12 @@ export function TransitionSettings(props: TransitionSettingsProps) {
<FloatingInspectorContent class="p-4">
<ControlRow label="Duration">
<SliderInput
- value={transitionDurationInSeconds()}
+ value={duration()}
+ onChange={handleDurationChange}
min={0.1}
max={10}
step={0.1}
- format={(v) => `${v.toFixed(1)}s`}
- onDragStart={() => world.history.startTransaction("Edit transition duration")}
- onDragEnd={() => world.history.commitTransaction()}
- onChange={handleSetDuration}
+ format={(value) => `${value.toFixed(1)}s`}
/>
</ControlRow>
</FloatingInspectorContent>
diff --git a/packages/reconciler/src/document.ts b/packages/reconciler/src/document.ts
index d0b775db..f343e4d6 100644
--- a/packages/reconciler/src/document.ts
+++ b/packages/reconciler/src/document.ts
@@ -163,7 +163,7 @@ const PAINT_TYPES: Record<string, PaintType> = {
surfacePaint: PaintType.SURFACE,
};
-const TRANSITION_TYPES: Record<string, TransitionType> = {
+export const TRANSITION_TYPES: Record<string, TransitionType> = {
dissolve: TransitionType.DISSOLVE,
slideFromRight: TransitionType.SLIDE_FROM_RIGHT,
slideFromLeft: TransitionType.SLIDE_FROM_LEFT,
diff --git a/packages/runtime/MIGRATION.md b/packages/runtime/MIGRATION.md
index 1cb65841..227018aa 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 | `components/sidebar-right/inspector/` |
+| Panels: header, background, scene template, asset info, time, appearance, alignment, export, layout, text, strokes, shadows, effects, animations, transition | `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.
@@ -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: transform, caption-settings, fills, transition, masks, audio, interpolation panels; the timeline's keyframe layer; the whole timeline UI.
+Still on bitecs: transform, caption-settings, fills, masks, audio, interpolation panels; the timeline's keyframe layer; the whole timeline UI.
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).
@@ -103,6 +103,8 @@ The effects panel dropped its add menu: the plus authors an `<effect type="blur"
The animations panel took the same plus: it authors `<animation type="fade">` (every node can play a fade) and opens the inspector, whose header select picks the preset out of the groups the node can play, `animation-types.ts` carrying them. The Text and Audio groups are offered on a text node and on one with something to hear (an audio clip, a video paint, a video fill), plus whichever group holds the preset already set, so an animation authored before the node lost its audio still has a value the select can show. `type` is required and always written; `phase`, `duration` and `delay` unset at "in", 1s and 0. Phase moved out of the header into a row of its own, since the header now names the animation. Rows list the in-animations before the out ones, each in the file's order, which is the order two animations on one property resolve in.
+The transition panel is the odd one of the three: `transition` is a prop of the clip (a `TransitionSpec`, one per clip), not a child element, so there is one row and the plus goes once a transition is there, the way the export panel's does. Its plus authors `{ type: "dissolve", duration: 1 }` and opens the inspector, where the same header select changes the style. **Both fields are written every time**: `setProperty` merges a partial into the transition already set, while the writer spells the attribute as whatever it was last handed, so a partial write would leave the file and the trait saying different things (and a switch back to `dissolve` would never land). Removal writes `false`, not `null`: `null` is a spelling the prop accepts but the writer would put it in the file, while `false` is what it drops the attribute for.
+
The shadow panel kept the shape it had: a row per `<shadow>` opening a floating inspector, since nothing in the shadow model moved the way the stroke's line style did. The one thing it says that the file does not is what "Add shadow" authors (`opacity` 0.25, `blur` 4, `offsetY` 4): `<shadow>`'s own defaults are all zero, which casts the silhouette back onto itself, so a shadow added from the panel has to spell out where it sits. Every control unsets at the prop's default (0 for the offsets and the blur, 1 for opacity); `color` is required and always written.
Two deliberate departures from the old text panel: `letterSpacing` is shown in px (the trait's unit and the prop's; the bitecs panel showed the same number as a percentage), and the font a text is set in — family, weight, size — is written out plainly rather than unset at its default, since a font is what a text *is* and not a modifier of it. `<captions>` has no host yet, so the caption half of the panel is unreachable and was carried over as it stood.