fix diffrent size in editor and viewer
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
hamid zarghami
2026-07-01 11:53:30 +03:30
parent 168af3bf95
commit 2b4fd31ea2
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from "react"; import { useEffect, useMemo, useRef, useState } from "react";
import { Image as KonvaImage, Rect, Group, Circle, Text as KonvaText } from "react-konva"; import { Image as KonvaImage, Rect, Group, Circle, Text as KonvaText } from "react-konva";
import Konva from "konva"; import Konva from "konva";
import useImage from "use-image"; import useImage from "use-image";
@@ -73,6 +73,35 @@ const VideoShape = ({
const containerWidth = obj.width || 400; const containerWidth = obj.width || 400;
const containerHeight = obj.height || 300; const containerHeight = obj.height || 300;
// هم‌تراز با viewer که object-fit: contain دارد
const imageLayout = useMemo(() => {
if (!image) {
return { x: 0, y: 0, width: containerWidth, height: containerHeight };
}
const naturalWidth = image.width || 1;
const naturalHeight = image.height || 1;
const containerRatio = containerWidth / containerHeight;
const imageRatio = naturalWidth / naturalHeight;
let width: number;
let height: number;
if (imageRatio > containerRatio) {
width = containerWidth;
height = containerWidth / imageRatio;
} else {
height = containerHeight;
width = containerHeight * imageRatio;
}
return {
x: (containerWidth - width) / 2,
y: (containerHeight - height) / 2,
width,
height,
};
}, [image, containerWidth, containerHeight]);
const handlePlayClick = (e: Konva.KonvaEventObject<MouseEvent>) => { const handlePlayClick = (e: Konva.KonvaEventObject<MouseEvent>) => {
e.cancelBubble = true; e.cancelBubble = true;
const evt = e.evt; const evt = e.evt;
@@ -121,20 +150,30 @@ const VideoShape = ({
<Rect <Rect
width={containerWidth} width={containerWidth}
height={containerHeight} height={containerHeight}
fill="#000000" fill="transparent"
stroke={isSelected ? "#3b82f6" : "#666666"} stroke={isSelected ? "#3b82f6" : "#666666"}
strokeWidth={isSelected ? 3 : (obj.strokeWidth ?? 0)} strokeWidth={isSelected ? 3 : (obj.strokeWidth ?? 0)}
onClick={handleGroupClick} onClick={handleGroupClick}
/> />
{image ? ( {image ? (
<KonvaImage <>
x={0} <Rect
y={0} x={imageLayout.x}
width={containerWidth} y={imageLayout.y}
height={containerHeight} width={imageLayout.width}
image={image} height={imageLayout.height}
onClick={handleGroupClick} fill="#000000"
/> onClick={handleGroupClick}
/>
<KonvaImage
x={imageLayout.x}
y={imageLayout.y}
width={imageLayout.width}
height={imageLayout.height}
image={image}
onClick={handleGroupClick}
/>
</>
) : ( ) : (
<Rect <Rect
x={0} x={0}