costum shape

This commit is contained in:
hamid zarghami
2026-06-13 16:22:46 +03:30
parent e6fc300fba
commit f9113ef9c8
17 changed files with 610 additions and 3 deletions
@@ -481,6 +481,29 @@ export const useTransformHandlers = (
: undefined,
});
}
} else if (selectedObject.type === "custom-shape") {
// Scale each vertex in-place; no width/height anchor needed
const oldPoints = selectedObject.points ?? [];
const newPoints = oldPoints.map((val, i) =>
i % 2 === 0 ? val * scaleX : val * scaleY,
);
// Recompute axis-aligned bounding box from the scaled points
const xs = newPoints.filter((_, i) => i % 2 === 0);
const ys = newPoints.filter((_, i) => i % 2 !== 0);
const newWidth =
xs.length > 0 ? Math.max(...xs) - Math.min(...xs) : 0;
const newHeight =
ys.length > 0 ? Math.max(...ys) - Math.min(...ys) : 0;
updateObject(selectedObject.id, {
x: node.x(),
y: node.y(),
rotation: node.rotation(),
points: newPoints,
width: Math.max(1, newWidth),
height: Math.max(1, newHeight),
});
} else {
// Default for other objects (image, etc.)
updateObject(selectedObject.id, {