alignment setting

This commit is contained in:
hamid zarghami
2026-05-02 16:14:34 +03:30
parent 47309c30dc
commit acb2f33b67
7 changed files with 433 additions and 9 deletions
+36 -4
View File
@@ -71,11 +71,11 @@ export const reorderByIds = (
return nextItems;
};
const getObjectBounds = (obj: EditorObject) => {
let w = obj.width || 0;
let h = obj.height || 0;
export const getObjectBounds = (obj: EditorObject) => {
// TextShape: متن با align="right" در Konva؛ گوشهٔ بالا-راست جعبه در (x,y)، نقاط بدنه به‌سمت چپ است.
if (obj.type === "text") {
let w = obj.width || 0;
let h = obj.height || 0;
if (!w) {
const textLength = (obj.text || "").length;
const fontSize = obj.fontSize || 24;
@@ -84,8 +84,40 @@ const getObjectBounds = (obj: EditorObject) => {
if (!h) {
h = obj.fontSize || 24;
}
const px = obj.x ?? 0;
const py = obj.y ?? 0;
const rot = ((obj.rotation || 0) * Math.PI) / 180;
const cornersLocal = [
{ x: -w, y: 0 },
{ x: 0, y: 0 },
{ x: 0, y: h },
{ x: -w, y: h },
];
let minX = Infinity;
let minY = Infinity;
let maxX = -Infinity;
let maxY = -Infinity;
cornersLocal.forEach(({ x: lx, y: ly }) => {
const rx = lx * Math.cos(rot) - ly * Math.sin(rot);
const ry = lx * Math.sin(rot) + ly * Math.cos(rot);
const wx = px + rx;
const wy = py + ry;
minX = Math.min(minX, wx);
minY = Math.min(minY, wy);
maxX = Math.max(maxX, wx);
maxY = Math.max(maxY, wy);
});
return { minX, minY, maxX, maxY };
}
let w = obj.width || 0;
let h = obj.height || 0;
if (obj.type === "rectangle" && obj.shapeType === "circle") {
const radius = w / 2;
const cx = obj.x || 0;