@versa_ai/vmml-editor 1.0.56 → 1.0.58

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/dist/index.mjs CHANGED
@@ -1027,7 +1027,7 @@ function usePeekControl(canvas, hideConfig) {
1027
1027
  return canvas;
1028
1028
  }
1029
1029
  var EditorCanvas = forwardRef(
1030
- ({ previewState, showCanvas, canvasSize, enterPreview, intoTextEdit, frame, vmml, dragState, initFcObjs, editClips = [], onVideoChange, isBatchModify, hideConfig, textWarapCenter, updateVmml }, ref) => {
1030
+ ({ lockInBounds, previewState, showCanvas, canvasSize, enterPreview, intoTextEdit, frame, vmml, dragState, initFcObjs, editClips = [], onVideoChange, isBatchModify, hideConfig, textWarapCenter, updateVmml }, ref) => {
1031
1031
  const [fc, setFc] = useState(null);
1032
1032
  const [history, setHistory] = useState(null);
1033
1033
  const [canvasReady, setCanvasReady] = useState(false);
@@ -1037,6 +1037,8 @@ var EditorCanvas = forwardRef(
1037
1037
  const heightScaleRef = useRef(1);
1038
1038
  const widthScaleRef = useRef(1);
1039
1039
  const fontCacheRef = useRef(/* @__PURE__ */ new Map());
1040
+ const lockInBoundsRef = useRef(lockInBounds);
1041
+ const lastValidScaleRef = useRef(null);
1040
1042
  const initCanvas = () => {
1041
1043
  const canvas = new fabric.Canvas("canvas", {
1042
1044
  width: canvasSize.width,
@@ -1111,6 +1113,46 @@ var EditorCanvas = forwardRef(
1111
1113
  const active = canvas.getActiveObject();
1112
1114
  handleIntoTextMenu(active, canvas);
1113
1115
  });
1116
+ canvas.on("object:moving", (e) => {
1117
+ if (!lockInBoundsRef.current) return;
1118
+ const obj = e.target;
1119
+ const canvasWidth = canvas.getWidth();
1120
+ const canvasHeight = canvas.getHeight();
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
+ }
1155
+ });
1114
1156
  };
1115
1157
  const imitateDBclick = (active, canvas) => {
1116
1158
  active.isSelected++;
@@ -1272,7 +1314,9 @@ var EditorCanvas = forwardRef(
1272
1314
  top,
1273
1315
  angle: posParam.rotationZ,
1274
1316
  originX: "center",
1317
+ // 圆点:中心点
1275
1318
  originY: "center",
1319
+ // 圆点:中心点
1276
1320
  clipData: {
1277
1321
  id: clip.id,
1278
1322
  isMute: null,
@@ -1331,6 +1375,7 @@ var EditorCanvas = forwardRef(
1331
1375
  });
1332
1376
  window.dispatchEvent(event);
1333
1377
  };
1378
+ const isVisibleColor = (color) => !!color && color !== "transparent" && !/rgba\([^)]*,\s*0\s*\)$/.test(color);
1334
1379
  const createTextObjs = async ({ strokeW, stColor, fontAssetUrl = null, letterSpace, bgColor, textContent, textBasicInfo, textColor }) => {
1335
1380
  const { width, height } = vmml.template.dimension;
1336
1381
  const fontSize = getFontSize(width, height);
@@ -1404,8 +1449,11 @@ var EditorCanvas = forwardRef(
1404
1449
  rx: round,
1405
1450
  ry: round
1406
1451
  });
1452
+ let list = [];
1453
+ if (bgColor && isVisibleColor(bgColor)) list = [bgRect, ...textObjs];
1454
+ else list = [...textObjs];
1407
1455
  return {
1408
- objects: [bgRect, ...textObjs],
1456
+ objects: list,
1409
1457
  fontFamily
1410
1458
  };
1411
1459
  };
@@ -1706,6 +1754,9 @@ var EditorCanvas = forwardRef(
1706
1754
  }
1707
1755
  }
1708
1756
  }, [fc]);
1757
+ useEffect(() => {
1758
+ lockInBoundsRef.current = lockInBounds;
1759
+ }, [lockInBounds]);
1709
1760
  const getCanvasCtx = () => {
1710
1761
  return fc;
1711
1762
  };
@@ -2506,6 +2557,7 @@ var EditorFn = ({
2506
2557
  textWarapCenter = false,
2507
2558
  backgroundColor = "#000",
2508
2559
  existenceBorderRadio = true,
2560
+ lockInBounds = false,
2509
2561
  hideConfig = { hideDelete: false, hideEdit: false, hideMute: false, hideVolume: false }
2510
2562
  // { hideDelete: false, hideEdit: false, hideMute: false, hideVolume: false }
2511
2563
  }, ref) => {
@@ -3000,6 +3052,7 @@ var EditorFn = ({
3000
3052
  /* @__PURE__ */ jsx(
3001
3053
  EditorCanvas_default,
3002
3054
  {
3055
+ lockInBounds,
3003
3056
  ref: canvasRef,
3004
3057
  previewState,
3005
3058
  showCanvas,