Skip to content

The VS Code of video editing, built for agents.

TypeScript

Remove Object Mask SVG Icon and Update Toolbar References

konstantin-paulus5d1d023ea02f
diff --git a/apps/web/src/assets/icons/object-mask.svg b/apps/web/src/assets/icons/object-mask.svg
new file mode 100644
index 00000000..3928fc73
--- /dev/null
+++ b/apps/web/src/assets/icons/object-mask.svg
@@ -0,0 +1,3 @@
+<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M14.5 9.5C17.2614 9.5 19.5 11.7386 19.5 14.5C19.5 17.2614 17.2614 19.5 14.5 19.5C11.7386 19.5 9.5 17.2614 9.5 14.5C9.5 11.7386 11.7386 9.5 14.5 9.5ZM14.5 16C13.4075 16 12.5203 16.876 12.501 17.9639C13.0893 18.3041 13.7715 18.5 14.5 18.5C15.2281 18.5 15.9099 18.3038 16.498 17.9639C16.4788 16.876 15.5925 16 14.5 16ZM14.5 10.5C12.2909 10.5 10.5 12.2909 10.5 14.5C10.5 15.5658 10.9181 16.533 11.5977 17.25C11.8055 16.4434 12.3377 15.7681 13.0498 15.374C12.71 15.0156 12.5 14.5329 12.5 14C12.5 12.8954 13.3954 12 14.5 12C15.6046 12 16.5 12.8954 16.5 14C16.5 14.5331 16.2893 15.0155 15.9492 15.374C16.6616 15.768 17.1934 16.4433 17.4014 17.25C18.0812 16.533 18.5 15.566 18.5 14.5C18.5 12.2909 16.7091 10.5 14.5 10.5ZM6.00488 13.8799C6.28098 13.8799 6.50481 14.1038 6.50488 14.3799V15.5049H7.62988C7.90598 15.5049 8.12982 15.7288 8.12988 16.0049C8.12988 16.281 7.90603 16.5049 7.62988 16.5049H6.50488C5.9527 16.5048 5.50489 16.0571 5.50488 15.5049V14.3799C5.50495 14.1039 5.72887 13.88 6.00488 13.8799ZM14.5 13C13.9477 13 13.5 13.4477 13.5 14C13.5 14.5523 13.9477 15 14.5 15C15.0523 15 15.5 14.5523 15.5 14C15.5 13.4477 15.0523 13 14.5 13ZM6.00488 9.37988C6.28098 9.37988 6.50481 9.6038 6.50488 9.87988V12.1299C6.50489 12.406 6.28103 12.6299 6.00488 12.6299C5.72881 12.6298 5.50489 12.406 5.50488 12.1299V9.87988C5.50495 9.60383 5.72882 9.37993 6.00488 9.37988ZM7.62988 5.50488C7.90598 5.50488 8.12982 5.7288 8.12988 6.00488C8.12988 6.28103 7.90603 6.50488 7.62988 6.50488H6.50488V7.62988C6.50489 7.90603 6.28102 8.12988 6.00488 8.12988C5.72876 8.12986 5.50489 7.90601 5.50488 7.62988V6.50488C5.50495 5.95266 5.95264 5.50489 6.50488 5.50488H7.62988ZM15.5049 5.50488C16.0571 5.50488 16.5048 5.95265 16.5049 6.50488V7.62988C16.5049 7.90603 16.281 8.12988 16.0049 8.12988C15.7287 8.12988 15.5049 7.90603 15.5049 7.62988V6.50488H14.3799C14.1037 6.50488 13.8799 6.28102 13.8799 6.00488C13.8799 5.7288 14.1038 5.50488 14.3799 5.50488H15.5049ZM12.1299 5.50488C12.406 5.50488 12.6298 5.7288 12.6299 6.00488C12.6299 6.28103 12.406 6.50488 12.1299 6.50488H9.87988C9.60374 6.50488 9.37988 6.28102 9.37988 6.00488C9.37995 5.7288 9.60378 5.50489 9.87988 5.50488H12.1299Z" fill="currentColor"/>
+</svg>
diff --git a/apps/web/src/assets/icons/tool.object-mask.svg b/apps/web/src/assets/icons/tool.object-mask.svg
deleted file mode 100644
index 00c33422..00000000
--- a/apps/web/src/assets/icons/tool.object-mask.svg
+++ /dev/null
@@ -1,8 +0,0 @@
-<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
-<path d="M12 4.5C9.51472 4.5 7.5 6.51472 7.5 9C7.5 11.4853 9.51472 13.5 12 13.5C14.4853 13.5 16.5 11.4853 16.5 9C16.5 6.51472 14.4853 4.5 12 4.5ZM8.625 9C8.625 7.13604 10.136 5.625 12 5.625C13.864 5.625 15.375 7.13604 15.375 9C15.375 10.864 13.864 12.375 12 12.375C10.136 12.375 8.625 10.864 8.625 9Z" fill="currentColor"/>
-<path d="M12 14.625C8.89 14.625 6.5 16.4 5.4 19.5H18.6C17.5 16.4 15.11 14.625 12 14.625ZM12 15.75C14.2 15.75 15.9 16.85 16.9 18.375H7.1C8.1 16.85 9.8 15.75 12 15.75Z" fill="currentColor"/>
-<path d="M4.5 6.5V5.5C4.5 4.94772 4.94772 4.5 5.5 4.5H6.5" stroke="currentColor" stroke-width="1.125" stroke-linecap="round" stroke-dasharray="1.5 1.5"/>
-<path d="M17.5 4.5H18.5C19.0523 4.5 19.5 4.94772 19.5 5.5V6.5" stroke="currentColor" stroke-width="1.125" stroke-linecap="round" stroke-dasharray="1.5 1.5"/>
-<path d="M19.5 17.5V18.5C19.5 19.0523 19.0523 19.5 18.5 19.5H17.5" stroke="currentColor" stroke-width="1.125" stroke-linecap="round" stroke-dasharray="1.5 1.5"/>
-<path d="M6.5 19.5H5.5C4.94772 19.5 4.5 19.0523 4.5 18.5V17.5" stroke="currentColor" stroke-width="1.125" stroke-linecap="round" stroke-dasharray="1.5 1.5"/>
-</svg>
diff --git a/apps/web/src/components/canvas/toolbar.tsx b/apps/web/src/components/canvas/toolbar.tsx
index bdbb1cc8..793f45b6 100644
--- a/apps/web/src/components/canvas/toolbar.tsx
+++ b/apps/web/src/components/canvas/toolbar.tsx
@@ -25,7 +25,7 @@ import { usePromptInput } from "@/context/prompt-input";
const CURSOR_TOOLS = [
{ tool: ToolType.MOVE, label: 'Move', shortcut: 'V', icon: 'move', menuIcon: 'move-small' },
{ tool: ToolType.HAND, label: 'Hand', shortcut: 'H', icon: 'hand', menuIcon: 'hand' },
- { tool: ToolType.OBJECT_MASK, label: 'Object Mask', shortcut: 'M', icon: 'tool.object-mask', menuIcon: 'tool.object-mask' },
+ { tool: ToolType.OBJECT_MASK, label: 'Object Mask', shortcut: 'M', icon: 'object-mask', menuIcon: 'object-mask' },
] as const;
export function Toolbar() {
diff --git a/apps/web/src/components/sidebar-right/inspector/effects-inspector.tsx b/apps/web/src/components/sidebar-right/inspector/effects-inspector.tsx
index 3a18c502..c092d12d 100644
--- a/apps/web/src/components/sidebar-right/inspector/effects-inspector.tsx
+++ b/apps/web/src/components/sidebar-right/inspector/effects-inspector.tsx
@@ -16,7 +16,7 @@ import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
- DropdownMenuSeparator,
+ DropdownMenuPortal,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { Icon } from "@/components/ui/icon";
@@ -37,9 +37,9 @@ import { useHas, useTrait, useWorld } from "@diffusionstudio/koota-solid";
import { Cache, Computed, Effect, Hidden, getParentNode } from "@diffusionstudio/runtime";
import { useDerived, useEditor } from "@/engine/hooks";
import { removeKeyframeTrack, syncKeyframe } from "@/engine/keyframes";
-import { beginObjectMaskFor, copyObjectMask, effectHasObjectMask, getVideoRect, listObjectMasks } from "@/engine/object-mask";
+import { copyObjectMask, effectHasObjectMask, getVideoRect, listObjectMasks } from "@/engine/object-mask";
import { EFFECT_OPTIONS, effectOption } from "./effect-types";
-import { ObjectMaskInspector } from "./object-mask";
+import { ObjectMaskInspector, objectMaskName } from "./object-mask";
import type { EffectOption } from "./effect-types";
import type { Entity } from "koota";
@@ -94,8 +94,6 @@ export function EffectsInspector(props: EffectsInspectorProps) {
return mask !== undefined && masks().includes(mask) ? mask : undefined;
});
-
-
const editValue = (next: number) => {
editor.editProperty(props.effect, "value", next);
syncKeyframe(world, editor, props.effect, "value", next);
@@ -177,7 +175,7 @@ export function EffectsInspector(props: EffectsInspectorProps) {
</div>
</FloatingInspectorHeader>
<FloatingInspectorSeparator />
- <FloatingInspectorContent class="flex flex-col gap-2 p-4" ref={contentRef}>
+ <FloatingInspectorContent class="flex flex-col gap-2 px-4 py-3" ref={contentRef}>
<Show when={option().unit === "amount"}>
<ControlRow label="Amount">
<SliderInput
@@ -228,51 +226,44 @@ export function EffectsInspector(props: EffectsInspectorProps) {
</Show>
<Show when={isVideo()}>
- <div class="flex items-center justify-between pt-2">
- <span class="text-xs text-muted-foreground">Masks</span>
- <DropdownMenu placement="bottom-end">
- <Tooltip>
- <TooltipTrigger<typeof DropdownMenuTrigger>
- as={(triggerProps: object) => (
- <DropdownMenuTrigger<typeof Button>
- {...triggerProps}
- as={(buttonProps) => (
- <Button size="icon" variant="ghost" class="text-muted-foreground" {...buttonProps}>
- <Icon name="plus-add" />
- </Button>
- )}
- />
- )}
- />
- <TooltipContent>Add mask</TooltipContent>
- </Tooltip>
- <DropdownMenuContent>
- <For each={shareable()}>
- {(source) => (
- <DropdownMenuItem onSelect={() => copyObjectMask(world, props.effect, source)}>
- {source.name}
- </DropdownMenuItem>
- )}
- </For>
- <Show when={shareable().length > 0}>
- <DropdownMenuSeparator />
- </Show>
- <DropdownMenuItem onSelect={() => beginObjectMaskFor(world, props.effect)}>
- Track new object…
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- </div>
<For each={masks()}>
- {(mask) => (
- <ObjectMaskRow
- mask={mask}
- active={editingMask() === mask}
- onSelect={() => setPickedMask(editingMask() === mask ? undefined : mask)}
- onRemove={() => editor.remove(mask)}
- />
+ {(mask, index) => (
+ <ControlRow label="Mask" labelClass={index() > 0 ? "invisible" : undefined}>
+ <ObjectMaskRow
+ mask={mask}
+ active={editingMask() === mask}
+ onSelect={() => setPickedMask(editingMask() === mask ? undefined : mask)}
+ onRemove={() => editor.remove(mask)}
+ />
+ </ControlRow>
)}
</For>
+ <ControlRow label="Mask" labelClass={masks().length > 0 ? "invisible" : undefined}>
+ <DropdownMenu placement="bottom-start">
+ <DropdownMenuTrigger
+ as="button"
+ type="button"
+ disabled={shareable().length === 0}
+ class="flex h-7 w-full min-w-0 cursor-default items-center gap-2 overflow-clip rounded-md bg-input p-1 pr-2 text-xs text-muted-foreground transition-colors hover:bg-input/80 disabled:opacity-50 disabled:hover:bg-input"
+ >
+ <div class="flex size-5 shrink-0 items-center justify-center overflow-clip rounded-sm bg-secondary text-foreground">
+ <Icon name="plus-add" />
+ </div>
+ <span class="min-w-0 flex-1 truncate text-left">Add matte mask</span>
+ </DropdownMenuTrigger>
+ <DropdownMenuPortal>
+ <DropdownMenuContent>
+ <For each={shareable()}>
+ {(source) => (
+ <DropdownMenuItem onSelect={() => copyObjectMask(world, props.effect, source)}>
+ {source.name}
+ </DropdownMenuItem>
+ )}
+ </For>
+ </DropdownMenuContent>
+ </DropdownMenuPortal>
+ </DropdownMenu>
+ </ControlRow>
</Show>
</FloatingInspectorContent>
@@ -294,18 +285,18 @@ type ObjectMaskRowProps = {
onRemove(): void;
};
-/** One `<mask>` of the effect; a click opens its settings. */
+/** One `<mask>` of the effect, by its file's name; a click opens its settings. */
function ObjectMaskRow(props: ObjectMaskRowProps) {
+ const world = useWorld();
const hidden = useHas(() => props.mask, Hidden);
+ const name = useDerived(() => objectMaskName(world, props.mask));
return (
<ItemRow
- label="Mask"
- value={"Object"}
+ value={name()}
disabled={hidden()}
- icon={<Icon name="mask-small" />}
- class="text-foreground"
- classList={{ "bg-accent/40": props.active }}
+ icon={<Icon name="object-mask" />}
+ classList={{ "rounded-md bg-accent/40": props.active }}
onClick={props.onSelect}
>
<Tooltip>
diff --git a/apps/web/src/components/sidebar-right/inspector/object-mask.tsx b/apps/web/src/components/sidebar-right/inspector/object-mask.tsx
index 82b71af3..962b5b79 100644
--- a/apps/web/src/components/sidebar-right/inspector/object-mask.tsx
+++ b/apps/web/src/components/sidebar-right/inspector/object-mask.tsx
@@ -4,7 +4,7 @@
import { Show, createResource, onMount } from "solid-js";
import { SAM2_MODELS, downloadSize, sam2Model } from "@diffusionstudio/sam2/models";
-import { DEFAULT_MASK_SMOOTHING } from "@diffusionstudio/assets";
+import { DEFAULT_MASK_SMOOTHING, assetName } from "@diffusionstudio/assets";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { ControlRow } from "@/components/ui/control-group";
@@ -13,9 +13,9 @@ import {
FloatingInspectorContent,
FloatingInspectorHeader,
FloatingInspectorSeparator,
- FloatingInspectorTitle,
} from "@/components/ui/floating-inspector";
import { Icon } from "@/components/ui/icon";
+import { IncrementDecrementControl } from "@/components/ui/increment-decrement-control";
import { Keyframe } from "@/components/ui/keyframe";
import { PanelSection } from "@/components/ui/panel-section";
import { Progress } from "@/components/ui/progress";
@@ -23,6 +23,7 @@ import { SegmentedIconTabs } from "@/components/ui/segmented-icon-tabs";
import { Select, SelectContent, SelectItem, SelectPortal, SelectTrigger, SelectValue } from "@/components/ui/select";
import { SliderInput } from "@/components/ui/slider-input";
import { Switch, SwitchControl, SwitchInput, SwitchThumb } from "@/components/ui/switch";
+import { ControlledTextField } from "@/components/ui/text-field";
import { useHas, useTrait, useWorld } from "@diffusionstudio/koota-solid";
import {
AssetId, Computed, Effect, Hidden, Library, Mask, Name, VideoDecoderHandle, getParentNode,
@@ -36,6 +37,7 @@ import {
getMaskRestore,
getMaskRestoreOf,
getObjectTrack,
+ listObjectMasks,
objectMaskMode,
objectMaskModel,
objectMaskModelLoad,
@@ -50,13 +52,16 @@ import {
} from "@/engine/object-mask";
import { effectOption } from "./effect-types";
-import type { Entity } from "koota";
+import type { Entity, World } from "koota";
import type { MaskAsset } from "@diffusionstudio/assets";
import type { Sam2Model, Sam2ModelId } from "@diffusionstudio/sam2/models";
-import type { MaskRestore, ObjectMaskMode, ObjectMaskModelLoad, ObjectTrackStatus } from "@/engine/object-mask";
-
-/** The most a feather goes to from the slider, px. */
-const MAX_FEATHER = 50;
+import type {
+ MaskRestore,
+ ObjectMaskMode,
+ ObjectMaskModelLoad,
+ ObjectMaskSource,
+ ObjectTrackStatus,
+} from "@/engine/object-mask";
const MODE_TABS = [
{ value: "points", label: "Points" },
@@ -266,10 +271,11 @@ type ObjectMaskInspectorProps = {
/**
* One `<mask>`'s settings, opened from its row in the effect's inspector the
- * way a paint opens its picker: feather, how strongly it limits the effect,
- * and inversion, plus a way to hide or remove it. A mask whose file cannot be
- * read — its decoder failed, as a video's does — can be restored from its
- * recipe.
+ * way a paint opens its picker: which tracked mask of the clip it is (the
+ * header), how strongly it limits the effect, smoothing, feather and
+ * inversion, plus a way to hide it; its row in the effect removes it. A mask
+ * whose file cannot be read — its decoder failed, as a video's does — can be
+ * restored from its recipe.
*/
export function ObjectMaskInspector(props: ObjectMaskInspectorProps) {
const world = useWorld();
@@ -328,15 +334,49 @@ export function ObjectMaskInspector(props: ObjectMaskInspectorProps) {
editor.editProperty(props.mask, "hidden", !hidden());
};
- const remove = () => {
- props.onClose();
- editor.remove(props.mask);
+ const name = useDerived(() => objectMaskName(world, props.mask));
+
+ // The tracked masks of the clip's footage: the header picks which of them this mask is.
+ const sources = useDerived(
+ () => {
+ const clip = getParentNode(getParentNode(props.mask));
+ return clip ? listObjectMasks(world, clip) : [];
+ },
+ (a, b) => a.length === b.length && a.every((source, i) => source.asset.id === b[i]!.asset.id && source.name === b[i]!.name),
+ );
+ const source = () => sources().find((option) => option.asset.id === props.mask.get(AssetId)?.value);
+
+ /** Points the mask at another tracked mask's frames, placed where they were written for. */
+ const switchSource = (next: ObjectMaskSource | null) => {
+ if (!next || next.asset.id === source()?.asset.id) return;
+ editor.editProperty(props.mask, "src", next.asset.path);
+ editor.editProperty(props.mask, "sourceIn", next.sourceIn > 0 ? next.sourceIn : false);
};
return (
<FloatingInspector open anchorRef={props.anchorRef} width={248}>
- <FloatingInspectorHeader class="items-center justify-between px-4">
- <FloatingInspectorTitle>Object Mask</FloatingInspectorTitle>
+ <FloatingInspectorHeader class="items-center justify-between px-2">
+ <Select<ObjectMaskSource>
+ value={source()}
+ onChange={switchSource}
+ options={sources()}
+ optionValue={(option) => option.asset.id}
+ optionTextValue="name"
+ itemComponent={(itemProps) => (
+ <SelectItem item={itemProps.item}>
+ {itemProps.item.rawValue.name}
+ </SelectItem>
+ )}
+ >
+ <SelectTrigger>
+ <SelectValue<ObjectMaskSource>>
+ {(state) => state.selectedOption()?.name ?? name()}
+ </SelectValue>
+ </SelectTrigger>
+ <SelectPortal>
+ <SelectContent />
+ </SelectPortal>
+ </Select>
<div class="flex items-center gap-1">
<Tooltip>
<TooltipTrigger
@@ -367,7 +407,7 @@ export function ObjectMaskInspector(props: ObjectMaskInspectorProps) {
</div>
</FloatingInspectorHeader>
<FloatingInspectorSeparator />
- <FloatingInspectorContent class="flex flex-col gap-2 p-4">
+ <FloatingInspectorContent class="flex flex-col gap-2 px-4 pt-3 pb-4">
<Show when={failed()}>
<div class="flex flex-col gap-2 pb-2">
<span class="flex items-center gap-1.5 text-xs">
@@ -391,16 +431,6 @@ export function ObjectMaskInspector(props: ObjectMaskInspectorProps) {
</div>
<FloatingInspectorSeparator class="-mx-4 mb-2" />
</Show>
- <ControlRow label="Feather">
- <SliderInput
- value={Math.round(feather())}
- min={0}
- max={MAX_FEATHER}
- onChange={editFeather}
- format={(value) => `${value}px`}
- keyframe={<Keyframe target={props.mask} property="blur" />}
- />
- </ControlRow>
<ControlRow label="Strength">
<SliderInput
value={Math.round(opacity() * 100)}
@@ -420,7 +450,25 @@ export function ObjectMaskInspector(props: ObjectMaskInspectorProps) {
format={(value) => `${value}%`}
/>
</ControlRow>
- <ControlRow label="Invert">
+ <ControlRow label="Feather" contentClass="grid grid-cols-2 gap-2">
+ <ControlledTextField
+ value={Math.round(feather())}
+ onNumber={editFeather}
+ unit="px"
+ min={0}
+ autoSelect
+ sliderEnabled
+ limitEvents
+ keyframe={<Keyframe target={props.mask} property="blur" />}
+ />
+ <IncrementDecrementControl
+ onDecrement={() => editFeather(feather() - 1)}
+ onIncrement={() => editFeather(feather() + 1)}
+ decrementLabel="Decrease feather"
+ incrementLabel="Increase feather"
+ />
+ </ControlRow>
+ <ControlRow label="Invert" class="h-7">
<Switch checked={mask()?.inverted ?? false} onChange={editInverted}>
<SwitchInput />
<SwitchControl variant="compact">
@@ -428,16 +476,17 @@ export function ObjectMaskInspector(props: ObjectMaskInspectorProps) {
</SwitchControl>
</Switch>
</ControlRow>
- <div class="flex justify-end pt-1">
- <Button size="small" variant="ghost" onClick={remove}>
- Remove mask
- </Button>
- </div>
</FloatingInspectorContent>
</FloatingInspector>
);
}
+/** What a `<mask>` is called: its file's name in the library, without the extension. */
+export function objectMaskName(world: World, mask: Entity): string {
+ const asset = world.get(Library)?.get(mask.get(AssetId)?.value ?? "");
+ return asset ? assetName(asset).replace(/\.[^.]+$/, "") : "Mask";
+}
+
function describe(state: SessionState): string {
const strokes = state.strokes === 0 ? "" : ` and ${state.strokes} ${state.strokes === 1 ? "stroke" : "strokes"}`;
const points = `${state.points} ${state.points === 1 ? "point" : "points"}${strokes}`;