refboard: stabilize image flip and crop transforms

This commit is contained in:
Hiren Kangad
2026-03-13 11:21:27 +05:30
parent c40304464f
commit 12410c0098
11 changed files with 359 additions and 98 deletions
+12 -11
View File
@@ -53,32 +53,32 @@ export async function writeCanvasToClipboard(
y: number;
sx: number;
sy: number;
angle: number;
globalX: number;
globalY: number;
}>();
// Pre-compute world bounds for each item (handles group children with local coords)
const worldBoundsMap = new Map<string, { x: number; y: number; w: number; h: number }>();
for (const item of items) {
worldBoundsMap.set(item.id, getItemWorldBounds(item));
}
for (const item of items) {
const obj = item.displayObject;
const globalOrigin = obj.parent?.toGlobal(obj.position) ?? obj.position;
saved.set(item.id, {
parent: obj.parent as Container,
x: obj.x,
y: obj.y,
sx: obj.scale.x,
sy: obj.scale.y,
angle: obj.angle,
globalX: globalOrigin.x,
globalY: globalOrigin.y,
});
// Remove from current parent
obj.parent?.removeChild(obj);
// Position using world bounds (correct for both top-level and group children)
const wb = worldBoundsMap.get(item.id)!;
obj.position.set(wb.x - minX + pad, wb.y - minY + pad);
// Use data scale (not viewport-affected scale)
obj.scale.set(item.data.sx, item.data.sy);
const s = saved.get(item.id)!;
obj.position.set(s.globalX - minX + pad, s.globalY - minY + pad);
obj.scale.set(s.sx, s.sy);
obj.angle = s.angle;
tempContainer.addChild(obj);
}
@@ -111,6 +111,7 @@ export async function writeCanvasToClipboard(
s.parent.addChild(item.displayObject);
item.displayObject.position.set(s.x, s.y);
item.displayObject.scale.set(s.sx, s.sy);
item.displayObject.angle = s.angle;
}
tempContainer.destroy();
texture?.destroy(true);