2026-03-11 15:34:56 +08:00
|
|
|
/** 克隆对象 */
|
|
|
|
|
export async function cloneObjects(objects = []) {
|
|
|
|
|
const arrs = []
|
|
|
|
|
for (const obj of objects) {
|
|
|
|
|
const clonedObj = await new Promise((resolve, reject) => {
|
|
|
|
|
obj.clone((v) => {
|
|
|
|
|
v.set({
|
|
|
|
|
left: obj.left,
|
|
|
|
|
top: obj.top,
|
|
|
|
|
width: obj.width,
|
|
|
|
|
height: obj.height,
|
|
|
|
|
scaleX: obj.scaleX,
|
|
|
|
|
scaleY: obj.scaleY,
|
2026-03-13 14:08:40 +08:00
|
|
|
angle: obj.angle,
|
2026-03-11 15:34:56 +08:00
|
|
|
})
|
|
|
|
|
resolve(v)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
arrs.push(clonedObj)
|
|
|
|
|
}
|
|
|
|
|
return arrs
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 获取组合对象边界 */
|
|
|
|
|
export async function getObjectsBoundingBox(objects = []) {
|
|
|
|
|
const box1 = { x: Infinity, y: Infinity }
|
|
|
|
|
const box2 = { x: -Infinity, y: -Infinity }
|
|
|
|
|
objects.forEach(obj => {
|
2026-03-13 14:08:40 +08:00
|
|
|
const rect = obj.getBoundingRect()
|
|
|
|
|
box1.x = Math.min(box1.x, rect.left)
|
|
|
|
|
box1.y = Math.min(box1.y, rect.top)
|
|
|
|
|
box2.x = Math.max(box2.x, rect.left + rect.width)
|
|
|
|
|
box2.y = Math.max(box2.y, rect.top + rect.height)
|
2026-03-11 15:34:56 +08:00
|
|
|
})
|
|
|
|
|
return {
|
|
|
|
|
left: box1.x,
|
|
|
|
|
top: box1.y,
|
|
|
|
|
width: box2.x - box1.x,
|
|
|
|
|
height: box2.y - box1.y,
|
|
|
|
|
}
|
|
|
|
|
}
|