Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Add image style tags and hierarchy drag and drop

Bittie945ce564609
diff --git a/src/components/workspace/ImageEditor.test.tsx b/src/components/workspace/ImageEditor.test.tsx
new file mode 100644
index 0000000..5e0da2e
--- /dev/null
+++ b/src/components/workspace/ImageEditor.test.tsx
@@ -0,0 +1,97 @@
+// @vitest-environment jsdom
+import "@testing-library/jest-dom/vitest";
+import { useState } from "react";
+import { cleanup, createEvent, fireEvent, render, screen, within } from "@testing-library/react";
+import { afterEach, expect, it, vi } from "vitest";
+import { ImageEditor } from "./ImageEditor";
+import { parseProjectConfig, type ProjectConfig } from "../../lib/project";
+import { imageScenePrompt } from "../../lib/imageScene";
+import fixture from "../../../fixtures/project-v1-image.json";
+
+afterEach(() => { cleanup(); localStorage.clear(); });
+function setup(initial = parseProjectConfig(fixture)) {
+ let latest: ProjectConfig = initial;
+ function Harness() {
+ const [config, setConfig] = useState(initial);
+ latest = config;
+ return <ImageEditor config={config} folderPath="D:/Images" onChange={setConfig} onGenerate={vi.fn()} onCancel={vi.fn()} />;
+ }
+ render(<Harness />);
+ return () => latest;
+}
+
+it("edits ordered style chips with suggestions, custom tags, removal, undo, and mode-specific choices", () => {
+ const current = setup();
+ expect(screen.getByRole("button", { name: "Aesthetics tag: Minimal poster" })).toBeInTheDocument();
+ fireEvent.click(screen.getByRole("button", { name: "Add Aesthetics tag" }));
+ const popup = within(screen.getByRole("dialog", { name: "Add Aesthetics tag" }));
+ expect(popup.getByRole("button", { name: "whimsical" })).toBeInTheDocument();
+ fireEvent.click(popup.getByRole("button", { name: "vibrant" }));
+ expect(popup.queryByRole("button", { name: "vibrant" })).not.toBeInTheDocument();
+ const custom = popup.getByRole("textbox", { name: "Custom Aesthetics tags" });
+ fireEvent.change(custom, { target: { value: " VIBRANT, intricate, custom finish, , " } });
+ fireEvent.keyDown(custom, { key: "Enter" });
+ expect(current().imageScene!.style.aesthetics).toBe("Minimal poster, vibrant, intricate, custom finish");
+ expect(custom).toHaveValue("");
+ fireEvent.keyDown(window, { key: "Escape" });
+ expect(screen.getByRole("button", { name: "Add Aesthetics tag" })).toHaveFocus();
+ fireEvent.click(screen.getByRole("button", { name: "Remove vibrant from Aesthetics" }));
+ fireEvent.keyDown(screen.getByRole("button", { name: "Aesthetics tag: intricate" }), { key: "ArrowLeft", altKey: true });
+ expect(current().imageScene!.style.aesthetics).toBe("intricate, Minimal poster, custom finish");
+ fireEvent.click(screen.getByRole("button", { name: "Undo image edit" }));
+ expect(current().imageScene!.style.aesthetics).toBe("Minimal poster, intricate, custom finish");
+ fireEvent.change(screen.getByLabelText("Mode"), { target: { value: "photo" } });
+ fireEvent.click(screen.getByRole("button", { name: "Add Lighting tag" }));
+ fireEvent.click(screen.getByRole("button", { name: "golden hour" }));
+ fireEvent.keyDown(window, { key: "Escape" });
+ fireEvent.click(screen.getByRole("button", { name: "Add Camera / lens tag" }));
+ fireEvent.click(screen.getByRole("button", { name: "35mm" }));
+ expect(imageScenePrompt(current().imageScene!)).toContain("Style: Photograph. Minimal poster, intricate, custom finish. Sunrise, golden hour. Screen print, 35mm.");
+ fireEvent.keyDown(window, { key: "Escape" });
+ fireEvent.click(screen.getByRole("button", { name: "Add Aesthetics tag" }));
+ expect(screen.getByRole("button", { name: "photorealistic" })).toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: "whimsical" })).not.toBeInTheDocument();
+ fireEvent.pointerDown(screen.getByLabelText("Mode"));
+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
+ expect(parseProjectConfig(JSON.parse(JSON.stringify(current()))).imageScene).toEqual(current().imageScene);
+});
+
+it("drags whole hierarchy branches to nest or reorder, preserves placement, and rejects cycles", () => {
+ const initial = parseProjectConfig(fixture);
+ const scene = initial.imageScene!;
+ scene.nodes.push({ ...scene.nodes[1], id: "cloud", name: "Cloud", parentId: "image-root" });
+ scene.nodes.push({ ...scene.nodes[2], id: "cloud-detail", name: "Cloud detail", parentId: "cloud" });
+ const current = setup(initial);
+ const row = (name: string) => screen.getByRole("button", { name }).closest<HTMLDivElement>(".image-tree__row")!;
+ const transfer = { setData: vi.fn(), effectAllowed: "", dropEffect: "" };
+ const drop = (source: string, target: string, y = 50) => {
+ fireEvent.dragStart(row(source), { dataTransfer: transfer });
+ const destination = row(target);
+ vi.spyOn(destination, "getBoundingClientRect").mockReturnValue({ top: 0, height: 100 } as DOMRect);
+ for (const type of ["dragOver", "drop"] as const) {
+ const event = createEvent[type](destination, { dataTransfer: transfer });
+ Object.defineProperty(event, "clientY", { value: y });
+ fireEvent(destination, event);
+ }
+ };
+ fireEvent.click(screen.getByRole("button", { name: "Collapse Cloud" }));
+ drop("Rocket", "Cloud");
+ expect(current().imageScene!.nodes.find((node) => node.id === "group-rocket")?.parentId).toBe("cloud");
+ expect(current().imageScene!.nodes.find((node) => node.id === "title")).toEqual(scene.nodes[2]);
+ expect(screen.getByRole("button", { name: "Collapse Cloud" })).toBeInTheDocument();
+ expect(screen.getByLabelText("Parent")).toHaveValue("cloud");
+ const nested = current().imageScene;
+ drop("Cloud", "Title");
+ expect(current().imageScene).toBe(nested);
+ drop("Rocket", "Rocket");
+ expect(current().imageScene).toBe(nested);
+ fireEvent.click(screen.getByRole("button", { name: "Undo image edit" }));
+ expect(current().imageScene).toEqual(scene);
+ drop("Rocket", "Cloud", 99);
+ expect(current().imageScene!.nodes.filter((node) => node.parentId === "image-root").map((node) => node.id)).toEqual(["cloud", "group-rocket"]);
+ drop("Rocket", "Cloud", 1);
+ expect(current().imageScene!.nodes.filter((node) => node.parentId === "image-root").map((node) => node.id)).toEqual(["group-rocket", "cloud"]);
+ expect(row("Image")).toHaveAttribute("draggable", "false");
+ expect(current().imageScene!.nodes.find((node) => node.id === "group-rocket")?.box).toEqual(scene.nodes[1].box);
+ expect(parseProjectConfig(JSON.parse(JSON.stringify(current()))).imageScene).toEqual(current().imageScene);
+});
diff --git a/src/components/workspace/ImageEditor.tsx b/src/components/workspace/ImageEditor.tsx
index df0ea1b..8845361 100644
--- a/src/components/workspace/ImageEditor.tsx
+++ b/src/components/workspace/ImageEditor.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useMemo, useRef, useState, useSyncExternalStore, type CSSProperties, type PointerEvent } from "react";
+import { useEffect, useMemo, useRef, useState, useSyncExternalStore, type CSSProperties, type DragEvent, type PointerEvent } from "react";
import { Box, ChevronDown, ChevronRight, Copy, Download, Image, Plus, Redo2, Sparkles, Square, Trash2, Undo2 } from "lucide-react";
import { invoke } from "@tauri-apps/api/core";
import { addImageNode, createImageScene, duplicateImageNode, imageDescendants, imageScenePrompt, removeImageNode, resizeImageNode, type ImageBox, type ImageNode, type ImageScene } from "../../lib/imageScene";
@@ -11,6 +11,9 @@ import { isWorkActive, type WorkItem } from "../../lib/workQueue";
import type { ConfigUpdate } from "./TimelineView";
import { ReferenceImage } from "./ReferenceImage";
import { DebugPromptDialog } from "./DebugPromptDialog";
+import { TagEditor } from "./TagEditor";
+import styleSuggestions from "../../lib/imageStyleSuggestions.json";
+import { applyImageCommand } from "../../lib/imageCommands";
import "../../styles/image-editor.css";
export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancel, work }: {
@@ -22,6 +25,8 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancel
const [selection, setSelection] = useState(root.id);
const selected = scene.nodes.find((node) => node.id === selection) ?? root;
const [collapsed, setCollapsed] = useState(new Set<string>());
+ const [draggedNode, setDraggedNode] = useState<string | null>(null);
+ const [treeDrop, setTreeDrop] = useState<{ id: string; placement: "before" | "inside" | "after" } | null>(null);
const [templates, setTemplates] = useState(loadGeneratorTemplateSettings);
const [templateId, setTemplateId] = useState(() => localStorage.getItem("slopus.image-generator-template.v1") ?? defaultGeneratorTemplate().id);
const imageTemplates = templates.templates.filter((template) => template.mode !== "animate");
@@ -98,11 +103,47 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancel
pointer.current = null; setDraftBox(null);
};
const descendants = imageDescendants(scene, selected.id);
+ const dropDestination = (event: DragEvent<HTMLDivElement>, target: ImageNode) => {
+ const source = scene.nodes.find((node) => node.id === draggedNode);
+ if (!source || source.kind === "root" || imageDescendants(scene, source.id).has(target.id)) return null;
+ const bounds = event.currentTarget.getBoundingClientRect();
+ const fraction = bounds.height ? (event.clientY - bounds.top) / bounds.height : 0.5;
+ const placement = target.kind === "root" ? "inside" : fraction < 0.25 ? "before" : fraction > 0.75 ? "after" : "inside";
+ const parent = placement === "inside" ? target.id : target.parentId!;
+ const siblings = scene.nodes.filter((node) => node.parentId === parent && node.id !== source.id);
+ const before = placement === "before" ? target.id : placement === "after" ? siblings[siblings.findIndex((node) => node.id === target.id) + 1]?.id : undefined;
+ return { id: target.id, placement, parent, before } as const;
+ };
const tree = (node: ImageNode, depth: number) => {
const children = scene.nodes.filter((child) => child.parentId === node.id);
const open = !collapsed.has(node.id);
return <div key={node.id} role="treeitem" aria-selected={selected.id === node.id} aria-expanded={children.length ? open : undefined}>
- <div className={`image-tree__row ${selected.id === node.id ? "selected" : ""}`} style={{ paddingLeft: `calc(var(--space-2) + ${depth} * var(--space-4))` }}>
+ <div className={`image-tree__row ${selected.id === node.id ? "selected" : ""}${draggedNode === node.id ? " dragging" : ""}${treeDrop?.id === node.id ? ` image-tree__drop--${treeDrop.placement}` : ""}`} style={{ paddingLeft: `calc(var(--space-2) + ${depth} * var(--space-4))` }}
+ draggable={node.kind !== "root"}
+ onDragStart={(event) => {
+ if (node.kind === "root") { event.preventDefault(); return; }
+ event.stopPropagation();
+ event.dataTransfer.setData("application/x-slopus-image-node", node.id);
+ event.dataTransfer.effectAllowed = "move";
+ setDraggedNode(node.id); setSelection(node.id);
+ }}
+ onDragEnd={() => { setDraggedNode(null); setTreeDrop(null); }}
+ onDragOver={(event) => {
+ event.stopPropagation();
+ const destination = dropDestination(event, node);
+ if (destination) { event.preventDefault(); event.dataTransfer.dropEffect = "move"; setTreeDrop(destination); }
+ else { event.dataTransfer.dropEffect = "none"; setTreeDrop(null); }
+ }}
+ onDragLeave={(event) => { if (!(event.relatedTarget instanceof Node) || !event.currentTarget.contains(event.relatedTarget)) setTreeDrop(null); }}
+ onDrop={(event) => {
+ event.preventDefault(); event.stopPropagation();
+ const destination = dropDestination(event, node);
+ if (destination && draggedNode) attempt(() => {
+ commit(applyImageCommand(scene, { op: "image.node.move", id: draggedNode, parent: destination.parent, before: destination.before }));
+ setCollapsed((current) => { const next = new Set(current); next.delete(destination.parent); return next; });
+ });
+ setDraggedNode(null); setTreeDrop(null);
+ }}>
{children.length ? <button className="icon-button" aria-label={`${open ? "Collapse" : "Expand"} ${node.name}`} onClick={() => setCollapsed((current) => { const next = new Set(current); if (open) next.add(node.id); else next.delete(node.id); return next; })}>{open ? <ChevronDown size={14} /> : <ChevronRight size={14} />}</button> : <span className="image-tree__spacer" />}
<button className="image-tree__select" onClick={() => setSelection(node.id)}><span aria-hidden="true">{node.kind === "text" ? "T" : node.kind === "root" ? <Image size={16} /> : <Box size={16} />}</span><span>{node.name}</span></button>
</div>
@@ -114,6 +155,7 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancel
<header><strong>Scene</strong><div className="image-editor__actions"><button className="icon-button" title="Undo" aria-label="Undo image edit" disabled={!undo.current.length} onClick={() => history(true)}><Undo2 size={16} /></button><button className="icon-button" title="Redo" aria-label="Redo image edit" disabled={!redo.current.length} onClick={() => history(false)}><Redo2 size={16} /></button></div></header>
<div className="image-tree__add">{(["object", "text", "group", "background"] as const).map((kind) => <button className="secondary-button" key={kind} onClick={() => add(kind)}><Plus size={14} />{kind[0].toUpperCase() + kind.slice(1)}</button>)}</div>
<div role="tree" aria-label="Image nodes">{tree(root, 0)}</div>
+ <p className="image-tree__hint">Drag onto a node to nest, or between nodes to reorder.</p>
<div className="image-tree__footer"><button className="secondary-button" disabled={selected.kind === "root"} onClick={() => { const next = duplicateImageNode(scene, selected.id); commit(next); setSelection(next.nodes[scene.nodes.length].id); }}><Copy size={15} /> Duplicate</button><button className="icon-button" aria-label="Delete selected node and children" disabled={selected.kind === "root"} onClick={() => { commit(removeImageNode(scene, selected.id)); setSelection(selected.parentId ?? root.id); }}><Trash2 size={16} /></button></div>
</aside>
<section className="image-center" aria-label="Image panel">
@@ -154,7 +196,10 @@ export function ImageEditor({ config, folderPath, onChange, onGenerate, onCancel
<label>Aspect ratio<select value={config.settings.aspectRatio} onChange={(event) => { const aspectRatio = event.target.value as ProjectConfig["settings"]["aspectRatio"]; onChange((current) => ({ ...current, settings: { ...current.settings, aspectRatio }, brief: { ...current.brief, aspectRatio } })); }}>{["16:9", "9:16", "1:1", "4:5"].map((ratio) => <option key={ratio}>{ratio}</option>)}</select></label>
<label>Resolution<select value={config.settings.resolution} onChange={(event) => { const resolution = event.target.value as ProjectConfig["settings"]["resolution"]; onChange((current) => ({ ...current, settings: { ...current.settings, resolution }, brief: { ...current.brief, resolution } })); }}>{[...new Set([...PROJECT_RESOLUTIONS, config.settings.resolution])].map((resolution) => { const size = outputDimensions(resolution, config.settings.aspectRatio); return <option key={resolution} value={resolution}>{size.width} × {size.height}</option>; })}</select></label>
<h3>Style</h3><label>Mode<select value={scene.style.mode} onChange={(event) => commit({ ...scene, style: { ...scene.style, mode: event.target.value as "photo" | "art" } })}><option value="photo">Photo</option><option value="art">Art</option></select></label>
- {(["aesthetics", "lighting", ...(scene.style.mode === "art" ? ["medium" as const] : []), "detail"] as const).map((field) => <label key={field}>{field === "detail" ? scene.style.mode === "photo" ? "Camera / lens" : "Art style" : field[0].toUpperCase() + field.slice(1)}<input value={scene.style[field]} onChange={(event) => commit({ ...scene, style: { ...scene.style, [field]: event.target.value } })} /></label>)}
+ <TagEditor label="Aesthetics" value={scene.style.aesthetics} suggestions={scene.style.mode === "photo" ? styleSuggestions.PhotoAestheticsSuggestions : styleSuggestions.ArtAestheticsSuggestions} onChange={(aesthetics) => commit({ ...scene, style: { ...scene.style, aesthetics } })} />
+ <TagEditor label="Lighting" value={scene.style.lighting} suggestions={scene.style.mode === "photo" ? styleSuggestions.PhotoLightingSuggestions : styleSuggestions.ArtLightingSuggestions} onChange={(lighting) => commit({ ...scene, style: { ...scene.style, lighting } })} />
+ {scene.style.mode === "art" && <TagEditor label="Medium" value={scene.style.medium} suggestions={styleSuggestions.MediumSuggestions} onChange={(medium) => commit({ ...scene, style: { ...scene.style, medium } })} />}
+ <TagEditor key={scene.style.mode} label={scene.style.mode === "photo" ? "Camera / lens" : "Art style"} value={scene.style.detail} suggestions={scene.style.mode === "photo" ? styleSuggestions.PhotoSuggestions : styleSuggestions.ArtSuggestions} onChange={(detail) => commit({ ...scene, style: { ...scene.style, detail } })} />
<h3>References</h3>{config.references.filter((reference) => reference.kind === "image" || reference.kind === "text").map((reference) => <label className="image-check" key={reference.id}><input type="checkbox" checked={scene.referenceIds.includes(reference.id)} onChange={(event) => commit({ ...scene, referenceIds: event.target.checked ? [...scene.referenceIds, reference.id] : scene.referenceIds.filter((id) => id !== reference.id) })} />{reference.name}</label>)}{!config.references.length && <p>Add image or text references in the References tab.</p>}
</>}
{selected.kind !== "root" && <><h3>Placement (0–1000)</h3><label className="image-check"><input type="checkbox" checked={Boolean(selected.box)} onChange={(event) => patchNode({ box: event.target.checked ? { x: 250, y: 250, width: 500, height: 500 } : null })} />Explicit placement</label>{selected.box && <div className="image-box-fields">{(["x", "y", "width", "height"] as const).map((field) => <label key={field}>{field}<input type="number" min={field === "x" || field === "y" ? 0 : 1} max="1000" value={selected.box![field]} onChange={(event) => { const value = Number(event.target.value); const box = { ...selected.box!, [field]: value }; if (Number.isFinite(value) && box.x >= 0 && box.y >= 0 && box.width > 0 && box.height > 0 && box.x + box.width <= 1000 && box.y + box.height <= 1000) commit(resizeImageNode(scene, selected.id, box)); }} /></label>)}</div>}</>}
diff --git a/src/components/workspace/TagEditor.tsx b/src/components/workspace/TagEditor.tsx
new file mode 100644
index 0000000..21abc02
--- /dev/null
+++ b/src/components/workspace/TagEditor.tsx
@@ -0,0 +1,111 @@
+import { Plus, X } from "lucide-react";
+import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
+import { createPortal } from "react-dom";
+import "../../styles/tag-editor.css";
+
+/** ImgFab's ordered style chips, stored as the existing comma-separated string. */
+export function TagEditor({ label, value, suggestions, onChange }: {
+ label: string; value: string; suggestions: readonly string[]; onChange: (value: string) => void;
+}) {
+ const id = useId();
+ const tags = value.split(",").map((tag) => tag.trim()).filter(Boolean);
+ const [open, setOpen] = useState(false);
+ const [custom, setCustom] = useState("");
+ const [position, setPosition] = useState({ left: 0, top: 0 });
+ const [dragging, setDragging] = useState<number | null>(null);
+ const host = useRef<HTMLDivElement>(null);
+ const addButton = useRef<HTMLButtonElement>(null);
+ const popup = useRef<HTMLDivElement>(null);
+ const input = useRef<HTMLInputElement>(null);
+ const drag = useRef<{ index: number; x: number; y: number; active: boolean } | null>(null);
+ const available = suggestions.filter((suggestion) => !tags.some((tag) => tag.toLowerCase() === suggestion.toLowerCase()));
+ const close = () => { setOpen(false); addButton.current?.focus(); };
+ const add = (raw: string) => {
+ const next = [...tags];
+ for (const tag of raw.split(",").map((part) => part.trim()).filter(Boolean)) {
+ if (!next.some((existing) => existing.toLowerCase() === tag.toLowerCase())) next.push(tag);
+ }
+ if (next.length !== tags.length) onChange(next.join(", "));
+ setCustom("");
+ input.current?.focus();
+ };
+ const move = (from: number, to: number) => {
+ if (from === to || to < 0 || to >= tags.length) return;
+ const next = [...tags];
+ next.splice(to, 0, next.splice(from, 1)[0]);
+ onChange(next.join(", "));
+ };
+ useLayoutEffect(() => {
+ if (!open) return;
+ const place = () => {
+ const anchor = addButton.current!.getBoundingClientRect();
+ const bounds = popup.current!.getBoundingClientRect();
+ const top = anchor.bottom + 6 + bounds.height <= window.innerHeight - 8 ? anchor.bottom + 6 : anchor.top - bounds.height - 6;
+ setPosition({ left: Math.max(8, Math.min(anchor.left, window.innerWidth - bounds.width - 8)), top: Math.max(8, top) });
+ };
+ place();
+ window.addEventListener("resize", place);
+ window.addEventListener("scroll", place, true);
+ return () => { window.removeEventListener("resize", place); window.removeEventListener("scroll", place, true); };
+ }, [open, available.length]);
+ useEffect(() => {
+ if (!open) return;
+ input.current?.focus();
+ const outside = (event: PointerEvent) => {
+ if (event.target instanceof Node && !host.current?.contains(event.target) && !popup.current?.contains(event.target)) setOpen(false);
+ };
+ const escape = (event: KeyboardEvent) => {
+ if (event.key === "Escape") { event.preventDefault(); event.stopPropagation(); close(); }
+ };
+ document.addEventListener("pointerdown", outside);
+ window.addEventListener("keydown", escape, true);
+ return () => { document.removeEventListener("pointerdown", outside); window.removeEventListener("keydown", escape, true); };
+ }, [open]);
+
+ return <div className="tag-editor" ref={host} role="group" aria-labelledby={`${id}-label`} onBlur={(event) => {
+ const next = event.relatedTarget;
+ if (next instanceof Node && !host.current?.contains(next) && !popup.current?.contains(next)) setOpen(false);
+ }}>
+ <span className="tag-editor__label" id={`${id}-label`}>{label}</span>
+ <div className="tag-editor__chips">
+ {tags.map((tag, index) => <span key={`${index}-${tag}`} data-tag-index={index} className={`tag-editor__chip${dragging === index ? " dragging" : ""}`}>
+ <button type="button" className="tag-editor__drag" aria-label={`${label} tag: ${tag}`} title="Drag to reorder, or use Alt + Left/Right" onKeyDown={(event) => {
+ if (event.altKey && (event.key === "ArrowLeft" || event.key === "ArrowRight")) {
+ event.preventDefault(); event.stopPropagation();
+ const to = index + (event.key === "ArrowLeft" ? -1 : 1);
+ move(index, to);
+ if (to >= 0 && to < tags.length) requestAnimationFrame(() => host.current?.querySelector<HTMLButtonElement>(`[data-tag-index="${to}"] .tag-editor__drag`)?.focus());
+ }
+ }} onPointerDown={(event) => {
+ if (event.button !== 0) return;
+ drag.current = { index, x: event.clientX, y: event.clientY, active: false };
+ event.currentTarget.setPointerCapture(event.pointerId);
+ }} onPointerMove={(event) => {
+ const start = drag.current;
+ if (start && Math.hypot(event.clientX - start.x, event.clientY - start.y) >= 4) { start.active = true; setDragging(start.index); }
+ }} onPointerUp={(event) => {
+ const start = drag.current;
+ if (start?.active) {
+ let target = start.index, distance = Infinity;
+ host.current?.querySelectorAll<HTMLElement>("[data-tag-index]").forEach((chip) => {
+ const box = chip.getBoundingClientRect();
+ const d = Math.hypot(event.clientX - box.left - box.width / 2, event.clientY - box.top - box.height / 2);
+ if (d < distance) { distance = d; target = Number(chip.dataset.tagIndex); }
+ });
+ move(start.index, target);
+ }
+ drag.current = null; setDragging(null);
+ }} onLostPointerCapture={() => { drag.current = null; setDragging(null); }}>{tag}</button>
+ <button type="button" className="tag-editor__remove" aria-label={`Remove ${tag} from ${label}`} onClick={() => onChange(tags.filter((_, i) => i !== index).join(", "))}><X size={12} /></button>
+ </span>)}
+ <button ref={addButton} type="button" className="tag-editor__add" aria-label={`Add ${label} tag`} aria-haspopup="dialog" aria-expanded={open} aria-controls={open ? `${id}-popup` : undefined} onClick={() => setOpen(!open)}><Plus size={13} /> Add</button>
+ </div>
+ {open && createPortal(<div ref={popup} id={`${id}-popup`} className="tag-editor__popup" role="dialog" aria-label={`Add ${label} tag`} style={position}>
+ <strong>Add tag</strong>
+ <div className="tag-editor__custom"><input ref={input} aria-label={`Custom ${label} tags`} placeholder="Custom tag…" value={custom} onChange={(event) => setCustom(event.target.value)} onKeyDown={(event) => {
+ if (event.key === "Enter" && !event.nativeEvent.isComposing) { event.preventDefault(); event.stopPropagation(); add(custom); }
+ }} /><button type="button" className="secondary-button" disabled={!custom.trim()} onClick={() => add(custom)}>Add</button></div>
+ {available.length > 0 && <><span className="tag-editor__hint">Suggestions</span><div className="tag-editor__suggestions">{available.map((tag) => <button type="button" key={tag} onClick={() => add(tag)}>{tag}</button>)}</div></>}
+ </div>, document.body)}
+ </div>;
+}
diff --git a/src/lib/imageStyleSuggestions.json b/src/lib/imageStyleSuggestions.json
new file mode 100644
index 0000000..742562b
--- /dev/null
+++ b/src/lib/imageStyleSuggestions.json
@@ -0,0 +1,142 @@
+{
+ "PhotoAestheticsSuggestions": [
+ "cinematic",
+ "photorealistic",
+ "high detail",
+ "moody",
+ "desaturated",
+ "vibrant",
+ "dramatic",
+ "soft focus",
+ "candid",
+ "editorial",
+ "documentary",
+ "fashion",
+ "film still",
+ "high contrast",
+ "muted tones",
+ "natural color",
+ "grainy",
+ "hyperrealistic"
+ ],
+ "ArtAestheticsSuggestions": [
+ "highly detailed",
+ "stylized",
+ "whimsical",
+ "surreal",
+ "vibrant",
+ "minimal",
+ "dreamlike",
+ "dramatic",
+ "ethereal",
+ "retro",
+ "psychedelic",
+ "moody",
+ "intricate",
+ "bold colors",
+ "pastel",
+ "monochrome",
+ "grunge",
+ "storybook"
+ ],
+ "PhotoLightingSuggestions": [
+ "golden hour",
+ "soft light",
+ "rim light",
+ "dramatic shadows",
+ "studio light",
+ "backlit",
+ "neon",
+ "overcast",
+ "blue hour",
+ "harsh sunlight",
+ "window light",
+ "candlelight",
+ "high key",
+ "low key",
+ "split lighting",
+ "ring light",
+ "moonlight",
+ "practical lights"
+ ],
+ "ArtLightingSuggestions": [
+ "volumetric",
+ "god rays",
+ "rim light",
+ "dramatic shadows",
+ "ambient glow",
+ "backlit",
+ "neon glow",
+ "bioluminescent",
+ "soft diffused",
+ "chiaroscuro",
+ "magic hour",
+ "subsurface scattering",
+ "iridescent",
+ "moonlit",
+ "bloom",
+ "flat lighting",
+ "spotlight",
+ "underlighting"
+ ],
+ "MediumSuggestions": [
+ "illustration",
+ "3d_render",
+ "painting",
+ "graphic_design",
+ "digital art",
+ "watercolor",
+ "oil painting",
+ "sketch",
+ "acrylic painting",
+ "gouache",
+ "pencil drawing",
+ "charcoal",
+ "ink drawing",
+ "pixel art",
+ "vector art",
+ "collage",
+ "linocut",
+ "pastel"
+ ],
+ "PhotoSuggestions": [
+ "35mm",
+ "50mm",
+ "85mm",
+ "f/1.4",
+ "f/2.8",
+ "shallow depth of field",
+ "bokeh",
+ "wide angle",
+ "telephoto",
+ "macro",
+ "film grain",
+ "long exposure",
+ "tilt-shift",
+ "fisheye",
+ "Kodak Portra",
+ "Fujifilm",
+ "polaroid",
+ "drone shot"
+ ],
+ "ArtSuggestions": [
+ "flat vector",
+ "bold outlines",
+ "cel shaded",
+ "concept art",
+ "line art",
+ "impasto",
+ "halftone",
+ "ink wash",
+ "art nouveau",
+ "art deco",
+ "ukiyo-e",
+ "low poly",
+ "vaporwave",
+ "anime",
+ "comic book",
+ "isometric",
+ "stained glass",
+ "claymation"
+ ]
+}
diff --git a/src/styles/image-editor.css b/src/styles/image-editor.css
index 9ca16b4..a36459b 100644
--- a/src/styles/image-editor.css
+++ b/src/styles/image-editor.css
@@ -11,7 +11,14 @@
.image-editor__actions, .image-tree__footer { display: flex; align-items: center; gap: var(--space-1); }
.image-tree__add { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-1); padding: var(--space-2); }
.image-tree__add button { padding-inline: var(--space-2); font-size: var(--text-xs); }
-.image-tree__row { display: flex; align-items: center; min-height: var(--control-md); }
+.image-tree__row { position: relative; display: flex; align-items: center; min-height: var(--control-md); }
+.image-tree__row[draggable="true"] .image-tree__select { cursor: grab; }
+.image-tree__row.dragging { opacity: 0.45; }
+.image-tree__drop--inside { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--panel-3); }
+.image-tree__drop--before::before, .image-tree__drop--after::after { content: ""; position: absolute; left: 0; right: 0; height: 2px; background: var(--accent); pointer-events: none; }
+.image-tree__drop--before::before { top: 0; }
+.image-tree__drop--after::after { bottom: 0; }
+.image-tree__hint { margin: 0; padding: var(--space-2) var(--space-3); color: var(--text-muted); font-size: var(--text-xs); }
.image-tree__row.selected { background: var(--panel-3); color: var(--text-primary); box-shadow: inset 3px 0 var(--accent); }
.image-tree__select { display: flex; gap: var(--space-2); align-items: center; flex: 1; min-width: 0; padding: var(--space-2); text-align: left; border: 0; background: transparent; color: inherit; }
.image-tree__select span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
diff --git a/src/styles/tag-editor.css b/src/styles/tag-editor.css
new file mode 100644
index 0000000..4a18114
--- /dev/null
+++ b/src/styles/tag-editor.css
@@ -0,0 +1,18 @@
+.tag-editor { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; font-size: var(--text-sm); }
+.tag-editor__chips, .tag-editor__suggestions { display: flex; flex-wrap: wrap; gap: var(--space-1); align-items: center; }
+.tag-editor__chip { display: inline-flex; align-items: center; max-width: 100%; border-radius: 14px; background: var(--panel-3); border: 1px solid var(--line); }
+.tag-editor__chip:hover { border-color: var(--line-strong); }
+.tag-editor__chip.dragging { opacity: 0.45; }
+.tag-editor__drag { min-width: 0; padding: 4px 3px 4px 9px; border: 0; background: transparent; color: var(--text-primary); font-size: inherit; text-align: left; overflow-wrap: anywhere; cursor: grab; touch-action: none; user-select: none; }
+.tag-editor__drag:active { cursor: grabbing; }
+.tag-editor__remove { display: grid; place-items: center; flex: 0 0 24px; align-self: stretch; padding: 3px; border: 0; border-radius: 50%; background: transparent; color: var(--text-muted); }
+.tag-editor__remove:hover { color: var(--danger); }
+.tag-editor__add { display: inline-flex; align-items: center; gap: 3px; padding: 4px 9px; border: 1px solid var(--line-strong); border-radius: 14px; background: transparent; color: var(--text-muted); font-size: inherit; }
+.tag-editor__add:hover, .tag-editor__add[aria-expanded="true"] { background: var(--panel-3); color: var(--text-primary); }
+.tag-editor__popup { position: fixed; z-index: 115; width: min(280px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); overflow: auto; display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3); border: 1px solid var(--line-strong); border-radius: var(--radius-md); background: var(--panel); color: var(--text-primary); box-shadow: var(--shadow); font-size: var(--text-sm); }
+.tag-editor__custom { display: flex; gap: var(--space-1); }
+.tag-editor__custom input { width: 100%; min-width: 0; min-height: var(--field-height); padding: var(--space-2); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--field-bg); color: var(--text-primary); }
+.tag-editor__custom button { flex-shrink: 0; }
+.tag-editor__hint { color: var(--text-muted); font-size: var(--text-xs); }
+.tag-editor__suggestions button { padding: 4px 8px; border: 1px solid transparent; border-radius: 12px; background: var(--panel-2); color: var(--text-primary); font-size: inherit; }
+.tag-editor__suggestions button:hover { background: var(--panel-3); border-color: var(--line-strong); }