fix resize

This commit is contained in:
hamid zarghami
2026-01-05 15:22:30 +03:30
parent 5e0550ec26
commit f492d4a29f
11 changed files with 160 additions and 192 deletions
@@ -58,26 +58,6 @@ const AbstractShape = ({ obj, isSelected, onSelect, onUpdate, draggable }: Shape
y: node.y() - (obj.height || 100) / 2,
});
}}
onTransformEnd={() => {
const node = shapeRef.current;
if (!node) return;
const scaleX = node.scaleX();
const scaleY = node.scaleY();
node.scaleX(1);
node.scaleY(1);
const newRadius = Math.max(5, baseRadius * Math.min(scaleX, scaleY));
const newSize = newRadius * 2;
onUpdate(obj.id, {
x: node.x() - newSize / 2,
y: node.y() - newSize / 2,
rotation: node.rotation(),
width: newSize,
height: newSize,
});
}}
/>
);
};
@@ -46,29 +46,6 @@ const ArrowShape = ({ obj, isSelected, onSelect, onUpdate, draggable }: ShapePro
height: newY + dy,
});
}}
onTransformEnd={() => {
const node = shapeRef.current;
if (!node) return;
const scaleX = node.scaleX();
const scaleY = node.scaleY();
node.scaleX(1);
node.scaleY(1);
const newX = node.x();
const newY = node.y();
const dx = (endX - startX) * scaleX;
const dy = (endY - startY) * scaleY;
onUpdate(obj.id, {
x: newX,
y: newY,
rotation: node.rotation(),
width: newX + dx,
height: newY + dy,
});
}}
/>
);
};
@@ -52,24 +52,6 @@ const CircleShape = ({ obj, isSelected, onSelect, onUpdate, draggable }: ShapePr
y: node.y(),
});
}}
onTransformEnd={() => {
const node = shapeRef.current;
if (!node) return;
const scaleX = node.scaleX();
node.scaleX(1);
node.scaleY(1);
const newRadius = Math.max(5, ((obj.width || 50) / 2) * scaleX);
onUpdate(obj.id, {
x: node.x(),
y: node.y(),
rotation: node.rotation(),
width: newRadius * 2,
height: newRadius * 2,
});
}}
/>
);
};
@@ -45,24 +45,6 @@ const ImageObject = ({
y: node.y(),
});
}}
onTransformEnd={() => {
const node = shapeRef.current;
if (!node) return;
const scaleX = node.scaleX();
const scaleY = node.scaleY();
node.scaleX(1);
node.scaleY(1);
onUpdate(obj.id, {
x: node.x(),
y: node.y(),
rotation: node.rotation(),
width: Math.max(5, (obj.width || image.width) * scaleX),
height: Math.max(5, (obj.height || image.height) * scaleY),
});
}}
/>
);
};
@@ -44,29 +44,6 @@ const LineShape = ({ obj, isSelected, onSelect, onUpdate, draggable }: ShapeProp
height: newY + dy,
});
}}
onTransformEnd={() => {
const node = shapeRef.current;
if (!node) return;
const scaleX = node.scaleX();
const scaleY = node.scaleY();
node.scaleX(1);
node.scaleY(1);
const newX = node.x();
const newY = node.y();
const dx = (endX - startX) * scaleX;
const dy = (endY - startY) * scaleY;
onUpdate(obj.id, {
x: newX,
y: newY,
rotation: node.rotation(),
width: newX + dx,
height: newY + dy,
});
}}
/>
);
};
@@ -50,22 +50,6 @@ const LinkShape = ({
y: node.y(),
});
}}
onTransformEnd={() => {
const node = shapeRef.current;
if (!node) return;
const scaleX = node.scaleX();
node.scaleX(1);
node.scaleY(1);
onUpdate(obj.id, {
x: node.x(),
y: node.y(),
rotation: node.rotation(),
fontSize: obj.fontSize ? Math.max(5, obj.fontSize * scaleX) : undefined,
});
}}
/>
);
};
@@ -53,24 +53,6 @@ const RectangleShape = ({ obj, isSelected, onSelect, onUpdate, draggable }: Shap
y: node.y(),
});
}}
onTransformEnd={() => {
const node = shapeRef.current;
if (!node) return;
const scaleX = node.scaleX();
const scaleY = node.scaleY();
node.scaleX(1);
node.scaleY(1);
onUpdate(obj.id, {
x: node.x(),
y: node.y(),
rotation: node.rotation(),
width: Math.max(5, (obj.width || 100) * scaleX),
height: Math.max(5, (obj.height || 100) * scaleY),
});
}}
/>
);
};
@@ -107,29 +107,6 @@ const TextShape = ({
y: node.y(),
});
}}
onTransformEnd={() => {
const node = shapeRef.current;
if (!node) return;
const scaleX = node.scaleX();
const scaleY = node.scaleY();
node.scaleX(1);
node.scaleY(1);
// محاسبه اندازه واقعی متن بعد از transform
const clientRect = node.getClientRect({ skipTransform: true });
const newWidth = clientRect.width * scaleX;
const newHeight = clientRect.height * scaleY;
onUpdate(obj.id, {
x: node.x(),
y: node.y(),
rotation: node.rotation(),
width: Math.max(5, newWidth),
height: Math.max(5, newHeight),
});
}}
/>
);
};
@@ -54,26 +54,6 @@ const TriangleShape = ({ obj, isSelected, onSelect, onUpdate, draggable }: Shape
y: node.y() - (obj.height || 100) / 2,
});
}}
onTransformEnd={() => {
const node = shapeRef.current;
if (!node) return;
const scaleX = node.scaleX();
const scaleY = node.scaleY();
node.scaleX(1);
node.scaleY(1);
const newRadius = Math.max(5, radius * Math.min(scaleX, scaleY));
const newSize = newRadius * 2;
onUpdate(obj.id, {
x: node.x() - newSize / 2,
y: node.y() - newSize / 2,
rotation: node.rotation(),
width: newSize,
height: newSize,
});
}}
/>
);
};