fix ccolor one page

This commit is contained in:
hamid zarghami
2026-05-06 14:53:55 +03:30
parent b1068eec26
commit 8717afbced
7 changed files with 77 additions and 30 deletions
+16 -12
View File
@@ -84,21 +84,25 @@ const TextShape = ({
textNode._setTextData();
const { width: rw, height: rh } = textNode.getClientRect({
// اندازه‌گیری طبیعی متن (بدون width تحمیلی) تا باکس واقعاً دور متن فیت شود.
const measureNode = textNode.clone({
width: undefined,
x: 0,
y: 0,
});
measureNode._setTextData();
const { width: rw, height: rh } = measureNode.getClientRect({
skipTransform: true,
});
const measuredWidth = Math.ceil(rw);
const h = Math.ceil(rh);
const nextWidth = obj.width && obj.width > 0 ? obj.width : measuredWidth;
measureNode.destroy();
// For text alignment to be visible, keep an existing text box width
// and only auto-calc width when the object has no width yet.
if (
nextWidth > 0 &&
h > 0 &&
(nextWidth !== obj.width || h !== obj.height)
) {
onUpdate(obj.id, { width: nextWidth, height: h });
const nextWidth = Math.max(1, Math.ceil(rw));
const nextHeight = Math.max(1, Math.ceil(rh));
const widthChanged = Math.abs((obj.width || 0) - nextWidth) > 1;
const heightChanged = Math.abs((obj.height || 0) - nextHeight) > 1;
if (widthChanged || heightChanged) {
onUpdate(obj.id, { width: nextWidth, height: nextHeight });
}
textNode.getLayer()?.batchDraw();
};