fix: multiple elements resizing regressions (#5586)
This commit is contained in:
parent
c8f6e3faa8
commit
f5379d1563
@ -22,7 +22,7 @@ const _ce = ({
|
|||||||
backgroundColor: "#000",
|
backgroundColor: "#000",
|
||||||
fillStyle: "solid",
|
fillStyle: "solid",
|
||||||
strokeWidth: 1,
|
strokeWidth: 1,
|
||||||
roughness: 1,
|
roughness: 0,
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
@ -106,7 +106,7 @@ describe("getElementBounds", () => {
|
|||||||
} as ExcalidrawLinearElement);
|
} as ExcalidrawLinearElement);
|
||||||
expect(x1).toEqual(360.3176068760539);
|
expect(x1).toEqual(360.3176068760539);
|
||||||
expect(y1).toEqual(185.90654264413516);
|
expect(y1).toEqual(185.90654264413516);
|
||||||
expect(x2).toEqual(473.8171188951176);
|
expect(x2).toEqual(480.87005902729743);
|
||||||
expect(y2).toEqual(320.391865303557);
|
expect(y2).toEqual(320.4751269334226);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -387,34 +387,49 @@ export const getArrowheadPoints = (
|
|||||||
return [x2, y2, x3, y3, x4, y4];
|
return [x2, y2, x3, y3, x4, y4];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const generateLinearElementShape = (
|
||||||
|
element: ExcalidrawLinearElement,
|
||||||
|
): Drawable => {
|
||||||
|
const generator = rough.generator();
|
||||||
|
const options = generateRoughOptions(element);
|
||||||
|
|
||||||
|
const method = (() => {
|
||||||
|
if (element.strokeSharpness !== "sharp") {
|
||||||
|
return "curve";
|
||||||
|
}
|
||||||
|
if (options.fill) {
|
||||||
|
return "polygon";
|
||||||
|
}
|
||||||
|
return "linearPath";
|
||||||
|
})();
|
||||||
|
|
||||||
|
return generator[method](element.points as Mutable<Point>[], options);
|
||||||
|
};
|
||||||
|
|
||||||
const getLinearElementRotatedBounds = (
|
const getLinearElementRotatedBounds = (
|
||||||
element: ExcalidrawLinearElement,
|
element: ExcalidrawLinearElement,
|
||||||
cx: number,
|
cx: number,
|
||||||
cy: number,
|
cy: number,
|
||||||
): [number, number, number, number] => {
|
): [number, number, number, number] => {
|
||||||
if (element.points.length < 2 || !getShapeForElement(element)) {
|
if (element.points.length < 2) {
|
||||||
// XXX this is just a poor estimate and not very useful
|
const [pointX, pointY] = element.points[0];
|
||||||
const { minX, minY, maxX, maxY } = element.points.reduce(
|
const [x, y] = rotate(
|
||||||
(limits, [x, y]) => {
|
element.x + pointX,
|
||||||
[x, y] = rotate(element.x + x, element.y + y, cx, cy, element.angle);
|
element.y + pointY,
|
||||||
limits.minY = Math.min(limits.minY, y);
|
cx,
|
||||||
limits.minX = Math.min(limits.minX, x);
|
cy,
|
||||||
limits.maxX = Math.max(limits.maxX, x);
|
element.angle,
|
||||||
limits.maxY = Math.max(limits.maxY, y);
|
|
||||||
return limits;
|
|
||||||
},
|
|
||||||
{ minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity },
|
|
||||||
);
|
);
|
||||||
return [minX, minY, maxX, maxY];
|
return [x, y, x, y];
|
||||||
}
|
}
|
||||||
|
|
||||||
const shape = getShapeForElement(element)!;
|
|
||||||
|
|
||||||
// first element is always the curve
|
// first element is always the curve
|
||||||
const ops = getCurvePathOps(shape[0]);
|
const cachedShape = getShapeForElement(element)?.[0];
|
||||||
|
const shape = cachedShape ?? generateLinearElementShape(element);
|
||||||
|
const ops = getCurvePathOps(shape);
|
||||||
const transformXY = (x: number, y: number) =>
|
const transformXY = (x: number, y: number) =>
|
||||||
rotate(element.x + x, element.y + y, cx, cy, element.angle);
|
rotate(element.x + x, element.y + y, cx, cy, element.angle);
|
||||||
|
|
||||||
return getMinMaxXYFromCurvePathOps(ops, transformXY);
|
return getMinMaxXYFromCurvePathOps(ops, transformXY);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -538,6 +553,7 @@ export const getResizedElementAbsoluteCoords = (
|
|||||||
points as [number, number][],
|
points as [number, number][],
|
||||||
generateRoughOptions(element),
|
generateRoughOptions(element),
|
||||||
);
|
);
|
||||||
|
|
||||||
const ops = getCurvePathOps(curve);
|
const ops = getCurvePathOps(curve);
|
||||||
bounds = getMinMaxXYFromCurvePathOps(ops);
|
bounds = getMinMaxXYFromCurvePathOps(ops);
|
||||||
}
|
}
|
||||||
|
@ -721,7 +721,7 @@ const resizeMultipleElements = (
|
|||||||
(pointerSideY * Math.abs(pointerY - anchorY)) / (maxY - minY),
|
(pointerSideY * Math.abs(pointerY - anchorY)) / (maxY - minY),
|
||||||
) * (shouldResizeFromCenter ? 2 : 1);
|
) * (shouldResizeFromCenter ? 2 : 1);
|
||||||
|
|
||||||
if (scale === 1) {
|
if (scale === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -766,7 +766,11 @@ const resizeMultipleElements = (
|
|||||||
width - optionalPadding,
|
width - optionalPadding,
|
||||||
height - optionalPadding,
|
height - optionalPadding,
|
||||||
);
|
);
|
||||||
if (textMeasurements) {
|
|
||||||
|
if (!textMeasurements) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isTextElement(element.orig)) {
|
if (isTextElement(element.orig)) {
|
||||||
update.fontSize = textMeasurements.size;
|
update.fontSize = textMeasurements.size;
|
||||||
update.baseline = textMeasurements.baseline;
|
update.baseline = textMeasurements.baseline;
|
||||||
@ -779,7 +783,8 @@ const resizeMultipleElements = (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
updateBoundElements(element.latest, { newSize: { width, height } });
|
||||||
|
|
||||||
mutateElement(element.latest, update);
|
mutateElement(element.latest, update);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user