"use client"; import { useMemo } from "react"; import { useCanvasGraph } from "@/components/canvas/canvas-graph-context"; import { usePipelinePreview } from "@/hooks/use-pipeline-preview"; import { collectPipelineFromGraph, getSourceImageFromGraph, } from "@/lib/canvas-render-preview"; import type { PipelineStep } from "@/lib/image-pipeline/contracts"; import { buildHistogramPlot } from "@/lib/image-pipeline/histogram-plot"; const PREVIEW_PIPELINE_TYPES = new Set([ "curves", "color-adjust", "light-adjust", "detail-adjust", ]); export default function AdjustmentPreview({ nodeId, nodeWidth, currentType, currentParams, }: { nodeId: string; nodeWidth: number; currentType: string; currentParams: unknown; }) { const graph = useCanvasGraph(); const sourceUrl = useMemo( () => getSourceImageFromGraph(graph, { nodeId, isSourceNode: (node) => node.type === "image" || node.type === "ai-image" || node.type === "asset", getSourceImageFromNode: (node) => { const sourceData = (node.data ?? {}) as Record; const directUrl = typeof sourceData.url === "string" ? sourceData.url : null; if (directUrl && directUrl.length > 0) { return directUrl; } const previewUrl = typeof sourceData.previewUrl === "string" ? sourceData.previewUrl : null; return previewUrl && previewUrl.length > 0 ? previewUrl : null; }, }), [graph, nodeId], ); const steps = useMemo(() => { const collected = collectPipelineFromGraph(graph, { nodeId, isPipelineNode: (node) => PREVIEW_PIPELINE_TYPES.has(node.type ?? ""), }); return collected.map((step) => { if (step.nodeId === nodeId && step.type === currentType) { return { ...step, params: currentParams, } as PipelineStep; } return step as PipelineStep; }); }, [currentParams, currentType, graph, nodeId]); const { canvasRef, histogram, isRendering, hasSource, previewAspectRatio, error } = usePipelinePreview({ sourceUrl, steps, nodeWidth, includeHistogram: true, // Die Vorschau muss in-Node gut lesbar bleiben, aber nicht in voller // Display-Auflösung rechnen. previewScale: 0.5, maxPreviewWidth: 720, maxDevicePixelRatio: 1.25, }); const histogramPlot = useMemo(() => { return buildHistogramPlot(histogram, { points: 64, width: 96, height: 44, }); }, [histogram.blue, histogram.green, histogram.red, histogram.rgb]); return (
{!hasSource ? (
Verbinde eine Bild-, Asset- oder KI-Bild-Node fuer Live-Preview.
) : null} {hasSource ? ( ) : null} {isRendering ? (
Rendering...
) : null}
{error ?

{error}

: null}
); }