Skip to content

The VS Code of video editing, built for agents.

TypeScript

Refactor SVG icons and enhance path settings component

konstantin-paulus397090440072
diff --git a/apps/web/src/assets/icons/path.trim-end.svg b/apps/web/src/assets/icons/path.trim-end.svg
index 695b91dd..527a5119 100644
--- a/apps/web/src/assets/icons/path.trim-end.svg
+++ b/apps/web/src/assets/icons/path.trim-end.svg
@@ -1,4 +1,3 @@
<svg viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
-<path opacity="0.5" d="M8 12.5H13" stroke="currentColor" stroke-dasharray="1 1"/>
-<rect x="15.5" y="6.5" width="2" height="12" rx="1" stroke="currentColor"/>
+<path d="M14.5 9.5H10.5V15.5H14.5M10.5 12.5H14" stroke="currentColor"/>
</svg>
diff --git a/apps/web/src/assets/icons/path.trim-offset.svg b/apps/web/src/assets/icons/path.trim-offset.svg
deleted file mode 100644
index 8ee0ce45..00000000
--- a/apps/web/src/assets/icons/path.trim-offset.svg
+++ /dev/null
@@ -1,5 +0,0 @@
-<svg viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
-<path opacity="0.5" d="M7 12.5H10" stroke="currentColor" stroke-dasharray="1 1"/>
-<rect x="11.5" y="6.5" width="2" height="12" rx="1" stroke="currentColor"/>
-<path opacity="0.5" d="M15 12.5H18" stroke="currentColor" stroke-dasharray="1 1"/>
-</svg>
diff --git a/apps/web/src/assets/icons/path.trim-start.svg b/apps/web/src/assets/icons/path.trim-start.svg
index c3865c4a..9188ae41 100644
--- a/apps/web/src/assets/icons/path.trim-start.svg
+++ b/apps/web/src/assets/icons/path.trim-start.svg
@@ -1,4 +1,3 @@
<svg viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
-<rect x="7.5" y="6.5" width="2" height="12" rx="1" stroke="currentColor"/>
-<path opacity="0.5" d="M12 12.5H17" stroke="currentColor" stroke-dasharray="1 1"/>
+<path d="M14.5 10.6C14.2 9.9 13.5 9.5 12.5 9.5C11.3 9.5 10.5 10.1 10.5 11C10.5 11.9 11.2 12.3 12.5 12.5C13.8 12.7 14.5 13.1 14.5 14C14.5 14.9 13.7 15.5 12.5 15.5C11.4 15.5 10.6 15.1 10.4 14.4" stroke="currentColor"/>
</svg>
diff --git a/apps/web/src/assets/icons/vector-path.svg b/apps/web/src/assets/icons/vector-path.svg
new file mode 100644
index 00000000..b65e030d
--- /dev/null
+++ b/apps/web/src/assets/icons/vector-path.svg
@@ -0,0 +1,7 @@
+<svg viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
+<circle cx="8.5" cy="8.5" r="1.5" stroke="currentColor"/>
+<circle cx="16.5" cy="8.5" r="1.5" stroke="currentColor"/>
+<circle cx="8.5" cy="16.5" r="1.5" stroke="currentColor"/>
+<circle cx="16.5" cy="16.5" r="1.5" stroke="currentColor"/>
+<path d="M10.5 8.5H14.5M10.5 16.5H14.5M8.5 10.5V14.5M16.5 10.5V14.5" stroke="currentColor"/>
+</svg>
diff --git a/apps/web/src/assets/icons/vector-side-count.svg b/apps/web/src/assets/icons/vector-side-count.svg
new file mode 100644
index 00000000..8e667f0c
--- /dev/null
+++ b/apps/web/src/assets/icons/vector-side-count.svg
@@ -0,0 +1,3 @@
+<svg viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M12.5 7.5V17.5M7.5 12.5H17.5M9 9L16 16M16 9L9 16" stroke="currentColor" stroke-linecap="round"/>
+</svg>
diff --git a/apps/web/src/components/sidebar-right/inspector/appearance.tsx b/apps/web/src/components/sidebar-right/inspector/appearance.tsx
index b4763cf7..5980d602 100644
--- a/apps/web/src/components/sidebar-right/inspector/appearance.tsx
+++ b/apps/web/src/components/sidebar-right/inspector/appearance.tsx
@@ -353,7 +353,7 @@ export function AppearanceSettings(props: AppearanceSettingsProps) {
step={1}
min={3}
onNumber={handlePointCountChange}
- icon={<Icon name="tool.polygon-small" />}
+ icon={<Icon name="vector-side-count" />}
sliderEnabled
limitEvents
/>
diff --git a/apps/web/src/components/sidebar-right/inspector/path.tsx b/apps/web/src/components/sidebar-right/inspector/path.tsx
index 31da7c8c..3f90d1cd 100644
--- a/apps/web/src/components/sidebar-right/inspector/path.tsx
+++ b/apps/web/src/components/sidebar-right/inspector/path.tsx
@@ -2,28 +2,42 @@
* 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 { Button } from "@/components/ui/button";
+import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
+import { createMemo, Show } from "solid-js";
import { ControlRow } from "@/components/ui/control-group";
import { Icon } from "@/components/ui/icon";
import { Keyframe } from "@/components/ui/keyframe";
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 { ControlledTextField } from "@/components/ui/text-field";
-import { useHas, useWorld } from "@diffusionstudio/koota-solid";
-import { Computed, EvenOdd } from "@diffusionstudio/runtime";
+import {
+ DropdownMenu,
+ DropdownMenuTrigger,
+ DropdownMenuContent,
+ DropdownMenuItem,
+} from "@/components/ui/dropdown-menu";
+import {
+ ContextMenu,
+ ContextMenuTrigger,
+ ContextMenuContent,
+ ContextMenuItem,
+} from "@/components/ui/context-menu";
+import { useWorld } from "@diffusionstudio/koota-solid";
+import { Computed } from "@diffusionstudio/runtime";
import { useDerived, useEditor } from "@/engine/hooks";
import { syncKeyframe } from "@/engine/keyframes";
+import { createStoredSignal } from "@/lib/store";
+import { store } from "@/init";
-import type { FillRule } from "@diffusionstudio/jsx";
import type { Entity } from "koota";
type PathSettingsProps = {
selection: Entity[];
};
-const FILL_RULES: { value: FillRule; label: string }[] = [
- { value: "nonzero", label: "Nonzero" },
- { value: "evenodd", label: "Even-odd" },
-];
+type PathAddon = "trim" | "offset";
+type PathAddons = Partial<Record<PathAddon, boolean>>;
type TrimProp = "trimStart" | "trimEnd" | "trimOffset";
@@ -33,104 +47,164 @@ const TRIM_DEFAULTS: Record<TrimProp, number> = { trimStart: 0, trimEnd: 1, trim
const percent = (fraction: number) => Math.round(fraction * 10000) / 100;
/**
- * What only a `<path>` has: its outline, its fill rule, and the trim that
- * draws part of its length (`trimStart`/`trimEnd`/`trimOffset`, shown in
- * percent of the length and keyframable like any prop). The outline has no
- * value to type — it is edited on the canvas — so its keyframe sits in the
- * section's header: a `d` keyframe of the outline as it is at the playhead,
- * which the vertex edits made there then key.
+ * What only a `<path>` has: its outline and the trim that draws part of its
+ * length (`trimStart`/`trimEnd`/`trimOffset`, shown in percent of the length
+ * and keyframable like any prop). The outline has no value to type — it is
+ * edited on the canvas — so its row only carries the keyframe: a `d`
+ * keyframe of the outline as it is at the playhead, which the vertex edits
+ * made there then key. The trim rows are opt-in and which ones are shown is
+ * app state, kept per user rather than per node.
*/
export function PathSettings(props: PathSettingsProps) {
const world = useWorld();
const editor = useEditor();
const entity = () => props.selection[0]!;
- const evenOdd = useHas(entity, EvenOdd);
- const fillRule = (): FillRule => (evenOdd() ? "evenodd" : "nonzero");
+ const [addons, setAddons] = createStoredSignal(
+ store.define<PathAddons>("path.addons", {})
+ );
const trimStart = useDerived(() => entity().get(Computed)?.trimStart ?? 0);
const trimEnd = useDerived(() => entity().get(Computed)?.trimEnd ?? 1);
const trimOffset = useDerived(() => entity().get(Computed)?.trimOffset ?? 0);
- const handleFillRuleChange = (rule: FillRule | null) => {
- if (rule === null || rule === fillRule()) return;
- editor.editProperty(entity(), "fillRule", rule === "nonzero" ? false : rule);
- };
+ const isTrimDefault = createMemo(() => trimStart() === 0 && trimEnd() === 1);
const handleTrimChange = (name: TrimProp, value: number) => {
const fraction = Math.round(value * 100) / 10000;
- const clamped = name === "trimOffset" ? fraction : Math.min(1, Math.max(0, fraction));
+ const clamped = Math.min(1, Math.max(0, fraction));
editor.editProperty(entity(), name, clamped === TRIM_DEFAULTS[name] ? false : clamped);
syncKeyframe(world, editor, entity(), name, clamped);
};
+ const showAddon = (addon: PathAddon) => addons()[addon] === true;
+ const toggleAddon = (addon: PathAddon, on: boolean) => {
+ setAddons({ ...addons(), [addon]: on });
+ };
+
return (
<PanelSection
title="Path"
- actions={<Keyframe target={entity()} property="d" class="h-7" />}
+ actions={
+ <Show when={!showAddon("trim") || !showAddon("offset")}>
+ <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 path setting</TooltipContent>
+ </Tooltip>
+ <DropdownMenuContent>
+ <Show when={!showAddon("trim")}>
+ <DropdownMenuItem onSelect={() => toggleAddon("trim", true)}>
+ Trim
+ </DropdownMenuItem>
+ </Show>
+ <Show when={!showAddon("offset")}>
+ <DropdownMenuItem onSelect={() => toggleAddon("offset", true)}>
+ Offset
+ </DropdownMenuItem>
+ </Show>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </Show>
+ }
>
- <ControlRow label="Fill rule">
- <Select<FillRule>
- value={fillRule()}
- onChange={handleFillRuleChange}
- options={FILL_RULES.map((rule) => rule.value)}
- itemComponent={(itemProps) => (
- <SelectItem item={itemProps.item}>
- {FILL_RULES.find((rule) => rule.value === itemProps.item.rawValue)?.label}
- </SelectItem>
- )}
- >
- <SelectTrigger>
- <SelectValue class="text-xs">{FILL_RULES.find((rule) => rule.value === fillRule())?.label}</SelectValue>
- </SelectTrigger>
- <SelectPortal>
- <SelectContent />
- </SelectPortal>
- </Select>
+ <ControlRow label="Path">
+ <div class="flex h-7 items-center rounded-md bg-input text-xs text-foreground select-none">
+ <span class="flex w-6 shrink-0 items-center justify-center text-muted-foreground">
+ <Icon name="vector-path" />
+ </span>
+ <span class="min-w-0 flex-1 truncate">Shape</span>
+ <span class="flex w-6 shrink-0 items-center justify-center">
+ <Keyframe target={entity()} property="d" />
+ </span>
+ </div>
</ControlRow>
- <ControlRow label="Trim" contentClass="grid grid-cols-2 gap-2">
- <ControlledTextField
- value={percent(trimStart())}
- onNumber={(value) => handleTrimChange("trimStart", value)}
- icon={<Icon name="path.trim-start" />}
- unit="%"
- step={1}
- min={0}
- max={100}
- autoSelect
- sliderEnabled
- limitEvents
- keyframe={<Keyframe target={entity()} property="trimStart" />}
- />
- <ControlledTextField
- value={percent(trimEnd())}
- onNumber={(value) => handleTrimChange("trimEnd", value)}
- icon={<Icon name="path.trim-end" />}
- unit="%"
- step={1}
- min={0}
- max={100}
- autoSelect
- sliderEnabled
- limitEvents
- keyframe={<Keyframe target={entity()} property="trimEnd" />}
- />
- </ControlRow>
+ <Show when={showAddon("trim")}>
+ <ContextMenu>
+ <ContextMenuTrigger<typeof ControlRow>
+ as={ControlRow}
+ label="Trim"
+ contentClass="grid grid-cols-2 gap-2"
+ >
+ <ControlledTextField
+ value={percent(trimStart())}
+ onNumber={(value) => handleTrimChange("trimStart", value)}
+ icon={<Icon name="path.trim-start" />}
+ unit="%"
+ step={1}
+ min={0}
+ max={100}
+ autoSelect
+ sliderEnabled
+ limitEvents
+ keyframe={<Keyframe target={entity()} property="trimStart" />}
+ />
+ <ControlledTextField
+ value={percent(trimEnd())}
+ onNumber={(value) => handleTrimChange("trimEnd", value)}
+ icon={<Icon name="path.trim-end" />}
+ unit="%"
+ step={1}
+ min={0}
+ max={100}
+ autoSelect
+ sliderEnabled
+ limitEvents
+ keyframe={<Keyframe target={entity()} property="trimEnd" />}
+ />
+ </ContextMenuTrigger>
+ <ContextMenuContent>
+ <ContextMenuItem
+ disabled={isTrimDefault()}
+ onSelect={() => {
+ handleTrimChange("trimStart", 0);
+ handleTrimChange("trimEnd", 100);
+ }}
+ >
+ Reset to Default
+ </ContextMenuItem>
+ <ContextMenuItem onSelect={() => toggleAddon("trim", false)}>
+ Remove row
+ </ContextMenuItem>
+ </ContextMenuContent>
+ </ContextMenu>
+ </Show>
- <ControlRow label="Offset">
- <ControlledTextField
- value={percent(trimOffset())}
- onNumber={(value) => handleTrimChange("trimOffset", value)}
- icon={<Icon name="path.trim-offset" />}
- unit="%"
- step={1}
- autoSelect
- sliderEnabled
- limitEvents
- keyframe={<Keyframe target={entity()} property="trimOffset" />}
- />
- </ControlRow>
+ <Show when={showAddon("offset")}>
+ <ContextMenu>
+ <ContextMenuTrigger<typeof ControlRow> as={ControlRow} label="Offset">
+ <SliderInput
+ value={percent(trimOffset())}
+ onChange={(value) => handleTrimChange("trimOffset", value)}
+ format={(value) => `${value}%`}
+ keyframe={<Keyframe target={entity()} property="trimOffset" />}
+ />
+ </ContextMenuTrigger>
+ <ContextMenuContent>
+ <ContextMenuItem
+ disabled={trimOffset() === 0}
+ onSelect={() => handleTrimChange("trimOffset", 0)}
+ >
+ Reset to Default
+ </ContextMenuItem>
+ <ContextMenuItem onSelect={() => toggleAddon("offset", false)}>
+ Remove row
+ </ContextMenuItem>
+ </ContextMenuContent>
+ </ContextMenu>
+ </Show>
</PanelSection>
);
}