AI media harness for planning, generating, and editing locally
TypeScript
Add image Export view
Bitti8933901a6763
diff --git a/src/components/workspace/ImageExportView.test.tsx b/src/components/workspace/ImageExportView.test.tsxnew file mode 100644index 0000000..311d9ae--- /dev/null+++ b/src/components/workspace/ImageExportView.test.tsx@@ -0,0 +1,42 @@+// @vitest-environment jsdom+import "@testing-library/jest-dom/vitest";+import { cleanup, render, screen, within } from "@testing-library/react";+import { afterEach, expect, it, vi } from "vitest";+import fixture from "../../../fixtures/project-v1-image.json";+import { parseProjectConfig, type ProjectConfig } from "../../lib/project";+import * as persistence from "../../lib/persistence";+import { ImageExportView } from "./ImageExportView";++vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));+afterEach(() => { cleanup(); localStorage.clear(); vi.restoreAllMocks(); });++function withOutput(patch: Partial<ProjectConfig["assets"][number]> = {}): ProjectConfig {+ const config = parseProjectConfig(fixture);+ config.assets = [{ id: "out", name: "Out", kind: "image", relativePath: "media/generated/out.png", mimeType: "image/png", createdAt: config.createdAt, ...patch } as ProjectConfig["assets"][number]];+ config.imageScene!.outputAssetId = "out";+ return config;+}++it("lays the page out like the video export: stage, splitter, settings pane with a pinned Export…", () => {+ vi.spyOn(persistence, "isTauri").mockReturnValue(true);+ vi.spyOn(persistence, "readMediaFileUrl").mockResolvedValue(null);+ const { container } = render(<ImageExportView config={withOutput({ width: 2048, height: 1152 })} folderPath="D:/Images" />);+ const body = container.querySelector(".export-body")!;+ expect(Array.from(body.children).map((child) => child.className.split(" ")[0])).toEqual(["export-preview", "ui-splitter", "export-settings"]);+ expect(screen.getByRole("separator", { name: "Resize export settings" })).toBeInTheDocument();+ const settings = screen.getByRole("region", { name: "Export settings" });+ expect(settings.querySelector(".export-settings__scroll")?.firstElementChild).toHaveClass("ui-prop-section");+ expect(within(settings).getByText("2048 × 1152 px")).toBeInTheDocument();+ const foot = settings.querySelector(".export-settings__foot")!;+ expect(within(foot as HTMLElement).getByRole("button", { name: "Export…" })).toBeEnabled();+ expect(screen.queryByText("Nothing to export yet")).not.toBeInTheDocument();+});++it("refuses to export a draft and says why", () => {+ vi.spyOn(persistence, "isTauri").mockReturnValue(true);+ render(<ImageExportView config={withOutput({ imageDraft: true })} folderPath="D:/Images" />);+ const button = screen.getByRole("button", { name: "Export…" });+ expect(button).toBeDisabled();+ expect(button).toHaveAttribute("data-tooltip", "This image is still a draft. Generate it before exporting.");+ expect(screen.getByText("The image is a draft")).toBeInTheDocument();+});diff --git a/src/components/workspace/ImageExportView.tsx b/src/components/workspace/ImageExportView.tsxnew file mode 100644index 0000000..469fd40--- /dev/null+++ b/src/components/workspace/ImageExportView.tsx@@ -0,0 +1,86 @@+import { invoke } from "@tauri-apps/api/core";+import { useState } from "react";+import type { ProjectConfig } from "../../lib/project";+import { isTauri } from "../../lib/persistence";+import { EmptyState, InfoBar, PropSection, Splitter, tooltipProps, usePaneSize } from "../ui";+import { Image32 } from "../ui/icons";+import { ReferenceImage } from "./ReferenceImage";++/* The image project's Export tab: the same page as the video export (see+ export.css) — the image on the stage, filling it, and the resizable settings+ pane on the right opening straight on its first section, with Export… pinned+ at its foot. For now Export… only opens the Save dialog (JPG or PNG is picked+ there); the pane is where output settings will grow. */+export function ImageExportView({ config, folderPath }: { config: ProjectConfig; folderPath: string }) {+ const settingsPane = usePaneSize("export.settings", 340, { min: 280, max: 560 });+ const [exporting, setExporting] = useState(false);+ const [error, setError] = useState<string | null>(null);+ const output = config.assets.find((asset) => asset.kind === "image" && asset.id === config.imageScene?.outputAssetId);+ const draft = Boolean(output?.imageDraft);+ const desktop = isTauri();++ /* Why there is nothing to export, in the order the user can fix it. */+ const blocker = !output?.relativePath ? "Generate an image in the Editor first."+ : draft ? "This image is still a draft. Generate it before exporting."+ : !desktop ? "Exporting is available in the Slopus desktop app."+ : null;+ const disabled = blocker !== null || exporting;+ const size = output?.width && output?.height ? `${output.width} × ${output.height}` : null;++ const exportImage = async () => {+ if (!output?.relativePath || disabled) return;+ setExporting(true); setError(null);+ try { await invoke("export_generated_image", { folderPath, relativePath: output.relativePath }); }+ catch (reason) { setError(String(reason)); }+ finally { setExporting(false); }+ };++ const facts: [string, string][] = [["Format", "JPG or PNG, chosen when saving"]];+ if (size) facts.push(["Size", `${size} px`]);++ return <div className="export-view" style={settingsPane.style}>+ <h1 className="sr-only">Export</h1>+ <div className="export-body">+ <section className="export-preview" aria-label="Image preview">+ <div className="export-stage">+ <div className="export-screen">+ {output?.relativePath && !draft+ ? <ReferenceImage className="export-image" folderPath={folderPath} relativePath={output.relativePath} alt={output.name} />+ : <EmptyState className="export-empty" icon={<Image32 />} title={draft ? "The image is a draft" : "No image to export yet"} description={blocker ?? undefined} />}+ </div>+ </div>+ </section>++ <Splitter {...settingsPane.splitterProps} reverse aria-label="Resize export settings" aria-controls="image-export-settings" />++ {/* No title: the pane opens on its first section, like every inspector. */}+ <section id="image-export-settings" className="export-settings" aria-label="Export settings">+ <div className="export-settings__scroll">+ <PropSection title="Output" persistKey="export.image.output">+ <dl className="export-summary">+ {facts.map(([term, value]) => <div key={term}>+ <dt>{term}</dt>+ <dd>{value}</dd>+ </div>)}+ </dl>+ </PropSection>+ <div className="export-messages">+ {blocker && <InfoBar severity="informational" title="Nothing to export yet" message={blocker} />}+ {error && <InfoBar severity="error" title="Couldn’t export image" message={error} onClose={() => setError(null)} />}+ </div>+ </div>+ <div className="export-settings__foot">+ <div className="export-settings__actions">+ <button+ type="button"+ className="primary-button"+ disabled={disabled}+ onClick={() => void exportImage()}+ {...tooltipProps(exporting ? "Export is running" : blocker ?? "Save the image as JPG or PNG")}+ >{exporting ? "Exporting…" : "Export…"}</button>+ </div>+ </div>+ </section>+ </div>+ </div>;+}diff --git a/src/styles/export.css b/src/styles/export.cssindex f12111b..4fad735 100644--- a/src/styles/export.css+++ b/src/styles/export.css@@ -101,6 +101,46 @@pointer-events: none;}+/* The image project's Export tab: the image itself, contained in the screen+ with the stage colour around it. The file is the export, so there is no+ frame box — just the picture at its own shape. */+.export-image {+ position: absolute;+ inset: 0;+ width: 100%;+ height: 100%;+ object-fit: contain;+}++img.export-image {+ display: block;+}++.export-image.reference-image-fallback {+ display: flex;+ flex-direction: column;+ align-items: center;+ justify-content: center;+ gap: var(--space-2);+ color: var(--on-stage);+ font-size: var(--text-xs);+}++/* Nothing to show: the shared empty state, in stage ink — the stage is dark+ in both themes. */+.export-empty.ui-empty-state {+ height: 100%;+}++.export-empty .ui-empty-state__icon,+.export-empty .ui-empty-state__description {+ color: color-mix(in srgb, var(--on-stage) 62%, transparent);+}++.export-empty .ui-empty-state__title {+ color: var(--on-stage);+}+/* --- Transport ----------------------------------------------------------------Windowed: a static 36px chrome bar under the picture — flat 24px buttonslike the timeline's, a Fluent slider, and "00:00:12:05 / 00:01:30:00". No