fix(canvas): split compare into two panes for transparent outputs
This commit is contained in:
parent
a1035c5dae
commit
7c69ccefc2
@ -287,6 +287,7 @@ export function ImageNode({ node, isSelected }: ImageNodeProps) {
|
|||||||
// 文件输入的 ref
|
// 文件输入的 ref
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
const compareFrameRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const updateNode = useCanvasStore((state) => state.updateNode);
|
const updateNode = useCanvasStore((state) => state.updateNode);
|
||||||
const deleteNode = useCanvasStore((state) => state.deleteNode);
|
const deleteNode = useCanvasStore((state) => state.deleteNode);
|
||||||
@ -387,6 +388,17 @@ export function ImageNode({ node, isSelected }: ImageNodeProps) {
|
|||||||
}
|
}
|
||||||
}, [hasCompareSource, isThisNodePicking]);
|
}, [hasCompareSource, isThisNodePicking]);
|
||||||
|
|
||||||
|
const updateCompareSplitByClientX = useCallback((clientX: number) => {
|
||||||
|
const frame = compareFrameRef.current;
|
||||||
|
if (!frame) return;
|
||||||
|
|
||||||
|
const rect = frame.getBoundingClientRect();
|
||||||
|
if (rect.width <= 0) return;
|
||||||
|
|
||||||
|
const rawPercent = ((clientX - rect.left) / rect.width) * 100;
|
||||||
|
setCompareSplitPercent(Math.max(0, Math.min(100, rawPercent)));
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isCompareMode) return;
|
if (!isCompareMode) return;
|
||||||
|
|
||||||
@ -1589,6 +1601,7 @@ export function ImageNode({ node, isSelected }: ImageNodeProps) {
|
|||||||
<div className="relative w-full h-full">
|
<div className="relative w-full h-full">
|
||||||
{isCompareMode && hasCompareSource ? (
|
{isCompareMode && hasCompareSource ? (
|
||||||
<div
|
<div
|
||||||
|
ref={compareFrameRef}
|
||||||
className="relative h-full w-full overflow-hidden bg-muted/30 select-none cursor-col-resize"
|
className="relative h-full w-full overflow-hidden bg-muted/30 select-none cursor-col-resize"
|
||||||
style={{ touchAction: "none" }}
|
style={{ touchAction: "none" }}
|
||||||
data-canvas-no-drag="true"
|
data-canvas-no-drag="true"
|
||||||
@ -1600,22 +1613,31 @@ export function ImageNode({ node, isSelected }: ImageNodeProps) {
|
|||||||
updateCompareSplitByClientX(event.clientX);
|
updateCompareSplitByClientX(event.clientX);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<img
|
<div
|
||||||
src={compareSource}
|
className="pointer-events-none absolute inset-0 overflow-hidden"
|
||||||
alt={`${displayTitle}-原图`}
|
style={{
|
||||||
className="absolute inset-0 h-full w-full object-contain"
|
clipPath: `inset(0 ${100 - compareSplitPercent}% 0 0)`,
|
||||||
draggable={false}
|
}}
|
||||||
/>
|
>
|
||||||
|
<div className="absolute inset-0 bg-muted/30" />
|
||||||
|
<img
|
||||||
|
src={data.src}
|
||||||
|
alt={displayTitle}
|
||||||
|
className="absolute inset-0 h-full w-full object-contain"
|
||||||
|
draggable={false}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
className="pointer-events-none absolute inset-0 overflow-hidden"
|
className="pointer-events-none absolute inset-0 overflow-hidden"
|
||||||
style={{
|
style={{
|
||||||
clipPath: `inset(0 0 0 ${compareSplitPercent}%)`,
|
clipPath: `inset(0 0 0 ${compareSplitPercent}%)`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<div className="absolute inset-0 bg-muted/30" />
|
||||||
<img
|
<img
|
||||||
src={data.src}
|
src={compareSource}
|
||||||
alt={displayTitle}
|
alt={`${displayTitle}-原图`}
|
||||||
className="h-full w-full object-contain"
|
className="absolute inset-0 h-full w-full object-contain"
|
||||||
draggable={false}
|
draggable={false}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -1631,10 +1653,10 @@ export function ImageNode({ node, isSelected }: ImageNodeProps) {
|
|||||||
<>
|
<>
|
||||||
</div>
|
</div>
|
||||||
<div className="pointer-events-none absolute left-2 top-2 rounded bg-black/55 px-1.5 py-0.5 text-[10px] text-white">
|
<div className="pointer-events-none absolute left-2 top-2 rounded bg-black/55 px-1.5 py-0.5 text-[10px] text-white">
|
||||||
原图
|
新图
|
||||||
</div>
|
</div>
|
||||||
<div className="pointer-events-none absolute right-2 top-2 rounded bg-black/55 px-1.5 py-0.5 text-[10px] text-white">
|
<div className="pointer-events-none absolute right-2 top-2 rounded bg-black/55 px-1.5 py-0.5 text-[10px] text-white">
|
||||||
新图
|
原图
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user