forked from lightningpixel/modly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreviewImageNode.tsx
More file actions
76 lines (72 loc) · 2.64 KB
/
Copy pathPreviewImageNode.tsx
File metadata and controls
76 lines (72 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { Handle, Position, useReactFlow } from '@xyflow/react'
import { useWorkflowRunStore } from '../workflowRunStore'
import BaseNode from './BaseNode'
const INPUT_COLOR = '#38bdf8'
/**
* Preview node for multi-view image outputs (e.g. MV-Adapter Generate Views).
*
* Expects a vertical strip PNG where N views are stacked top→bottom.
* Displays them in a 2×3 grid using CSS background-position cropping.
*/
export default function PreviewImageNode({ id, selected }: { id: string; selected?: boolean }) {
const nodeImageOutputs = useWorkflowRunStore((s) => s.nodeImageOutputs)
const { getEdges } = useReactFlow()
// Find the image URL fed into this node (first matching incoming edge)
const incomingEdge = getEdges().find((e) => e.target === id)
const imageUrl = incomingEdge ? nodeImageOutputs[incomingEdge.source] : undefined
return (
<BaseNode
id={id}
selected={selected}
title="Preview Views"
minWidth={200}
icon={
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke={INPUT_COLOR} strokeWidth="2">
<rect x="3" y="3" width="18" height="18" rx="2"/>
<circle cx="8.5" cy="8.5" r="1.5"/>
<polyline points="21 15 16 10 5 21"/>
</svg>
}
subheader={
<div className="flex items-center gap-1.5 px-3 py-2">
<span className="inline-flex items-center px-1.5 py-0.5 rounded text-[9px] font-medium border border-sky-500/30 bg-sky-500/10 text-sky-400">image</span>
<span className="text-[9px] text-zinc-600">→ preview</span>
</div>
}
handles={
<Handle
type="target"
position={Position.Left}
style={{ background: INPUT_COLOR, width: 14, height: 14, border: '2.5px solid #18181b' }}
/>
}
>
<div className="px-2 pb-2 pt-1">
{imageUrl ? (
<div
className="nodrag grid gap-0.5 rounded overflow-hidden"
style={{ gridTemplateColumns: 'repeat(3, 1fr)' }}
>
{[0, 1, 2, 3, 4, 5].map((i) => (
<div
key={i}
style={{
aspectRatio: '1',
backgroundImage: `url(${imageUrl})`,
backgroundSize: '100% 600%',
backgroundPosition: `0 ${i * 20}%`,
backgroundRepeat: 'no-repeat',
borderRadius: '2px',
}}
/>
))}
</div>
) : (
<p className="py-2 text-center text-[10px] text-zinc-600 italic">
Connect a multi-view image to preview.
</p>
)}
</div>
</BaseNode>
)
}