@versa_ai/vmml-editor 1.0.57 → 1.0.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +8 -8
- package/dist/index.js +40 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/components/EditorCanvas.tsx +68 -26
package/dist/index.mjs
CHANGED
|
@@ -1038,6 +1038,7 @@ var EditorCanvas = forwardRef(
|
|
|
1038
1038
|
const widthScaleRef = useRef(1);
|
|
1039
1039
|
const fontCacheRef = useRef(/* @__PURE__ */ new Map());
|
|
1040
1040
|
const lockInBoundsRef = useRef(lockInBounds);
|
|
1041
|
+
const lastValidScaleRef = useRef(null);
|
|
1041
1042
|
const initCanvas = () => {
|
|
1042
1043
|
const canvas = new fabric.Canvas("canvas", {
|
|
1043
1044
|
width: canvasSize.width,
|
|
@@ -1109,7 +1110,6 @@ var EditorCanvas = forwardRef(
|
|
|
1109
1110
|
vmmlConverterRef.current.changeMute(clipData);
|
|
1110
1111
|
});
|
|
1111
1112
|
canvas.on("object:textEdit", (e) => {
|
|
1112
|
-
console.log("1111111111");
|
|
1113
1113
|
const active = canvas.getActiveObject();
|
|
1114
1114
|
handleIntoTextMenu(active, canvas);
|
|
1115
1115
|
});
|
|
@@ -1118,17 +1118,40 @@ var EditorCanvas = forwardRef(
|
|
|
1118
1118
|
const obj = e.target;
|
|
1119
1119
|
const canvasWidth = canvas.getWidth();
|
|
1120
1120
|
const canvasHeight = canvas.getHeight();
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
if (
|
|
1130
|
-
if (
|
|
1131
|
-
|
|
1121
|
+
const scaleX = obj.scaleX ?? 1;
|
|
1122
|
+
const scaleY = obj.scaleY ?? 1;
|
|
1123
|
+
const width = obj.width * scaleX;
|
|
1124
|
+
const height = obj.height * scaleY;
|
|
1125
|
+
let left = obj.left ?? 0;
|
|
1126
|
+
let top = obj.top ?? 0;
|
|
1127
|
+
const halfW = width / 2;
|
|
1128
|
+
const halfH = height / 2;
|
|
1129
|
+
if (left - halfW < 0) left = halfW;
|
|
1130
|
+
if (left + halfW > canvasWidth) left = canvasWidth - halfW;
|
|
1131
|
+
if (top - halfH < 0) top = halfH;
|
|
1132
|
+
if (top + halfH > canvasHeight) top = canvasHeight - halfH;
|
|
1133
|
+
obj.set({ left, top });
|
|
1134
|
+
});
|
|
1135
|
+
canvas.on("object:scaling", (e) => {
|
|
1136
|
+
if (!lockInBoundsRef.current) return;
|
|
1137
|
+
const obj = e.target;
|
|
1138
|
+
obj.setCoords();
|
|
1139
|
+
const bounds = obj.getBoundingRect();
|
|
1140
|
+
const canvasWidth = canvas.getWidth();
|
|
1141
|
+
const canvasHeight = canvas.getHeight();
|
|
1142
|
+
const outOfBounds = bounds.left < 0 || bounds.top < 0 || bounds.left + bounds.width > canvasWidth || bounds.top + bounds.height > canvasHeight;
|
|
1143
|
+
if (outOfBounds) {
|
|
1144
|
+
if (lastValidScaleRef.current) {
|
|
1145
|
+
obj.set(lastValidScaleRef.current).setCoords();
|
|
1146
|
+
}
|
|
1147
|
+
} else {
|
|
1148
|
+
lastValidScaleRef.current = {
|
|
1149
|
+
scaleX: obj.scaleX,
|
|
1150
|
+
scaleY: obj.scaleY,
|
|
1151
|
+
left: obj.left,
|
|
1152
|
+
top: obj.top
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1132
1155
|
});
|
|
1133
1156
|
};
|
|
1134
1157
|
const imitateDBclick = (active, canvas) => {
|
|
@@ -1352,6 +1375,7 @@ var EditorCanvas = forwardRef(
|
|
|
1352
1375
|
});
|
|
1353
1376
|
window.dispatchEvent(event);
|
|
1354
1377
|
};
|
|
1378
|
+
const isVisibleColor = (color) => !!color && color !== "transparent" && !/rgba\([^)]*,\s*0\s*\)$/.test(color);
|
|
1355
1379
|
const createTextObjs = async ({ strokeW, stColor, fontAssetUrl = null, letterSpace, bgColor, textContent, textBasicInfo, textColor }) => {
|
|
1356
1380
|
const { width, height } = vmml.template.dimension;
|
|
1357
1381
|
const fontSize = getFontSize(width, height);
|
|
@@ -1425,8 +1449,11 @@ var EditorCanvas = forwardRef(
|
|
|
1425
1449
|
rx: round,
|
|
1426
1450
|
ry: round
|
|
1427
1451
|
});
|
|
1452
|
+
let list = [];
|
|
1453
|
+
if (bgColor && isVisibleColor(bgColor)) list = [bgRect, ...textObjs];
|
|
1454
|
+
else list = [...textObjs];
|
|
1428
1455
|
return {
|
|
1429
|
-
objects:
|
|
1456
|
+
objects: list,
|
|
1430
1457
|
fontFamily
|
|
1431
1458
|
};
|
|
1432
1459
|
};
|