The VS Code of video editing, built for agents.
TypeScript
Integrate MasksSettings into Inspector for enhanced mask management
konstantin-paulusf5cdb1d287c8
diff --git a/apps/web/src/components/sidebar-right/inspector/inspector.tsx b/apps/web/src/components/sidebar-right/inspector/inspector.tsxindex 76dff123..54569c8c 100644--- a/apps/web/src/components/sidebar-right/inspector/inspector.tsx+++ b/apps/web/src/components/sidebar-right/inspector/inspector.tsx@@ -36,7 +36,7 @@ import { ShadowsSettings } from "./shadows";import { EffectsSettings } from "./effects";import { AnimationsSettings } from "./animations";import { TransitionSettings } from "./transition";-// import { MasksSettings } from "./masks";+import { MasksSettings } from "./masks";// import { AudioSettings } from "./audio";// import { InterpolationSettings } from "./interpolation";@@ -173,9 +173,9 @@ export function Inspector() {<TransitionSettings selection={nodes()} /></Show>- {/* <Show when={includesTarget("shape", "text", "caption", "group")}>+ <Show when={includesTarget("shape", "text", "caption", "group")}><MasksSettings selection={nodes()} />- </Show> */}+ </Show>{/* <Show when={includesTarget("shape", "audio", "group")}><AudioSettings selection={nodes()} />diff --git a/apps/web/src/components/sidebar-right/inspector/masks.tsx b/apps/web/src/components/sidebar-right/inspector/masks.tsxindex c451e6d8..afadfb04 100644--- a/apps/web/src/components/sidebar-right/inspector/masks.tsx+++ b/apps/web/src/components/sidebar-right/inspector/masks.tsx@@ -2,104 +2,126 @@* 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 { For } from "solid-js";import { Button } from "@/components/ui/button";import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";-import { Icon } from '@/components/ui/icon';+import { Icon } from "@/components/ui/icon";import { ItemRow } from "@/components/ui/item-row";-import { PanelSection } from '@/components/ui/panel-section';-import { For } from "solid-js";+import { PanelSection } from "@/components/ui/panel-section";+import { useTrait, useWorld } from "@diffusionstudio/koota-solid";+import { Rect } from "@diffusionstudio/reconciler";+import { Cache, Computed, Name, getNextName } from "@diffusionstudio/runtime";+import { useDerived, useEditor } from "@/engine/hooks";++import type { Entity } from "koota";++/**+ * Where a new mask sits in its parent, px. Offset rather than flush so the+ * mask shows itself the moment it is added: at the parent's own size it+ * clips a band off two edges instead of landing invisibly on top of it.+ */+const MASK_INSET = 20;-import { useEntityState, getNextName, createEntity, deleteEntity, GeometryType, PaintType, type EngineWorld, addComponent, appendChild, setComponent, resizeEntity, clearComponent } from "@/components/engine";-import { useEngine } from "@/context/engine";+// Stable identity, so a node without masks does not resample every tick.+const NO_MASKS: Entity[] = [];type MasksSettingsProps = {- selection: Set<number>;+ selection: Entity[];};+/**+ * The `<rect mask>` children of the selected node: the boxes it is clipped+ * to (several intersect). A mask is a rect like any other, so it has no+ * inspector of its own — a row selects it and the transform, time and+ * appearance panels are then its own. Its `fill`, `opacity` and paint+ * children have no effect (a mask is never drawn), which is why the plus+ * authors neither.+ */export function MasksSettings(props: MasksSettingsProps) {- const { world } = useEngine();+ const world = useWorld();+ const editor = useEditor();+ const entity = () => props.selection[0]!;- const eid = () => props.selection.values().next().value!;- const maskEids = useEntityState(world.components.Cache.masks, eid, []);- const handleAddMask = () => createMask(world, eid());- const handleRemoveMask = (maskEid: number) => deleteEntity(world, maskEid);+ // Cache is derived state, written without change events.+ const masks = useDerived(() => entity().get(Cache)?.masks ?? NO_MASKS);- return (- <PanelSection- title="Masks"- actions={- <Tooltip>- <TooltipTrigger- as={Button}- size="icon"- variant="ghost"- class="text-muted-foreground"- onClick={handleAddMask}- >- <Icon name="plus-add" />- </TooltipTrigger>- <TooltipContent>Add mask</TooltipContent>- </Tooltip>- }- >- <For each={maskEids()}>- {(maskEid: number) => {- const name = useEntityState(world.components.Name, maskEid, '');- return (- <ItemRow- label="Mask"- value={name()}- icon={<Icon name="mask-small" />}- class="text-foreground"- >- <Tooltip>- <TooltipTrigger- as={Button}- size="icon"- variant="ghost"- class="text-muted-foreground"- onClick={() => handleRemoveMask(maskEid)}- >- <Icon name="close-remove-small" />- </TooltipTrigger>- <TooltipContent>Remove mask</TooltipContent>- </Tooltip>- </ItemRow>- );- }}- </For>- </PanelSection>- );-}--function createMask(world: EngineWorld, targetEid: number) {- const c = world.components;+ const handleAppendMask = () => {+ const node = entity();+ const computed = node.get(Computed);+ const width = Math.round(computed?.width ?? 0);+ const height = Math.round(computed?.height ?? 0);+ // A mask without a size of its own is 500x500, which is the honest+ // answer for a parent that has no box yet (an empty group).+ const size = width > 0 && height > 0 ? { width, height } : {};- world.history.transaction('Add mask', () => {- const width = c.Computed.width[targetEid] ?? 0;- const height = c.Computed.height[targetEid] ?? 0;+ const [mask] = editor.insertElement(node, () => (+ <Rect mask name={getNextName(world, "Mask")} x={MASK_INSET} y={MASK_INSET} {...size} />+ ));- const parentDelay = c.Computed.delay[targetEid] ?? 0;- const parentStart = c.Computed.start[targetEid] ?? parentDelay;- const parentEnd = c.Computed.end[targetEid] ?? parentDelay;+ // The mask is what the user came to place, so the selection moves to it.+ if (mask) editor.select(mask);+ };- const maskEid = createEntity(world);- setComponent(world, maskEid, c.Geometry, GeometryType.RECT);- setComponent(world, maskEid, c.Name, `${getNextName(world, 'Mask')} [Mask Shape]`);- setComponent(world, maskEid, c.Position, { x: 20, y: 20 });- setComponent(world, maskEid, c.Trim, { start: parentStart - parentDelay, end: parentEnd - parentDelay });- resizeEntity(world, maskEid, { width, height });+ return (+ <PanelSection+ title="Masks"+ actions={+ <Tooltip>+ <TooltipTrigger+ as={Button}+ size="icon"+ variant="ghost"+ class="text-muted-foreground"+ onClick={handleAppendMask}+ >+ <Icon name="plus-add" />+ </TooltipTrigger>+ <TooltipContent>Add mask</TooltipContent>+ </Tooltip>+ }+ >+ <For each={masks()}>+ {(mask) => (+ <MaskRow+ mask={mask}+ onSelect={() => editor.select(mask)}+ onRemove={() => editor.remove(mask)}+ />+ )}+ </For>+ </PanelSection>+ );+}- const fillEid = createEntity(world);- setComponent(world, fillEid, c.Paint, PaintType.SOLID);- setComponent(world, fillEid, c.Color, 0xFFFFFF);- appendChild(world, fillEid, maskEid);+type MaskRowProps = {+ mask: Entity;+ onSelect(): void;+ onRemove(): void;+};- addComponent(world, maskEid, c.IsMask);- appendChild(world, maskEid, targetEid);- addComponent(world, targetEid, c.Expanded);+function MaskRow(props: MaskRowProps) {+ const name = useTrait(() => props.mask, Name);- clearComponent(world, c.Selected);- addComponent(world, maskEid, c.Selected);- });+ return (+ <ItemRow+ label="Mask"+ value={name()?.value || "Mask"}+ icon={<Icon name="mask-small" />}+ class="text-foreground"+ onClick={props.onSelect}+ >+ <Tooltip>+ <TooltipTrigger+ as={Button}+ size="icon"+ variant="ghost"+ class="text-muted-foreground"+ onClick={props.onRemove}+ >+ <Icon name="close-remove-small" />+ </TooltipTrigger>+ <TooltipContent>Remove mask</TooltipContent>+ </Tooltip>+ </ItemRow>+ );}diff --git a/packages/runtime/MIGRATION.md b/packages/runtime/MIGRATION.mdindex 227018aa..dcfb1d84 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 | `components/sidebar-right/inspector/` |+| Panels: header, background, scene template, asset info, time, appearance, alignment, export, layout, text, strokes, shadows, effects, animations, transition, masks | `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, masks, audio, interpolation panels; the timeline's keyframe layer; the whole timeline UI.+Still on bitecs: transform, caption-settings, fills, 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).@@ -105,6 +105,8 @@ The animations panel took the same plus: it authors `<animation type="fade">` (eThe 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 masks panel got shorter with the model. A mask is `<rect mask>`, a rect like any other, so it needs no inspector of its own: a row selects it and the transform, time and appearance panels are then its own. Three things the bitecs "Add mask" authored are gone with them: the white solid fill and the trim to the parent's window (a mask is never drawn, and without an `end` it already clips for the parent's whole window), and the `[Mask Shape]` name suffix, which was there for a timeline that could not tell a mask apart otherwise. What it still authors is the parent's own size (a mask without one is 500x500, which is what an empty group gets) at a 20px inset, so the new mask shows itself instead of landing invisibly on top of the parent. `Expanded` is not set on the parent: that is app-side timeline state the koota side has not picked up yet.+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.