@versa_ai/vmml-editor 1.0.57 → 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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @versa_ai/vmml-editor@1.0.57 build D:\code\work\vmml-player\packages\editor
2
+ > @versa_ai/vmml-editor@1.0.58 build D:\code\work\vmml-player\packages\editor
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: src/index.tsx
@@ -124,12 +124,12 @@ More info and automated migrator: https://sass-lang.com/d/slash-div [35
124
124
 
125
125
 
126
126
 
127
- CJS dist\index.js 123.55 KB
128
- CJS dist\index.js.map 237.48 KB
129
- CJS ⚡️ Build success in 779ms
130
- ESM dist\index.mjs 121.66 KB
131
- ESM dist\index.mjs.map 237.17 KB
132
- ESM ⚡️ Build success in 780ms
133
- DTS ⚡️ Build success in 1976ms
127
+ ESM dist\index.mjs 122.67 KB
128
+ ESM dist\index.mjs.map 239.53 KB
129
+ ESM ⚡️ Build success in 3480ms
130
+ CJS dist\index.js 124.56 KB
131
+ CJS dist\index.js.map 239.83 KB
132
+ CJS ⚡️ Build success in 3480ms
133
+ DTS ⚡️ Build success in 3938ms
134
134
  DTS dist\index.d.ts 158.00 B
135
135
  DTS dist\index.d.mts 158.00 B
package/dist/index.js CHANGED
@@ -1044,6 +1044,7 @@ var EditorCanvas = react.forwardRef(
1044
1044
  const widthScaleRef = react.useRef(1);
1045
1045
  const fontCacheRef = react.useRef(/* @__PURE__ */ new Map());
1046
1046
  const lockInBoundsRef = react.useRef(lockInBounds);
1047
+ const lastValidScaleRef = react.useRef(null);
1047
1048
  const initCanvas = () => {
1048
1049
  const canvas = new fabric.fabric.Canvas("canvas", {
1049
1050
  width: canvasSize.width,
@@ -1115,7 +1116,6 @@ var EditorCanvas = react.forwardRef(
1115
1116
  vmmlConverterRef.current.changeMute(clipData);
1116
1117
  });
1117
1118
  canvas.on("object:textEdit", (e) => {
1118
- console.log("1111111111");
1119
1119
  const active = canvas.getActiveObject();
1120
1120
  handleIntoTextMenu(active, canvas);
1121
1121
  });
@@ -1124,17 +1124,40 @@ var EditorCanvas = react.forwardRef(
1124
1124
  const obj = e.target;
1125
1125
  const canvasWidth = canvas.getWidth();
1126
1126
  const canvasHeight = canvas.getHeight();
1127
- let left = obj.left;
1128
- let top = obj.top;
1129
- let w = obj.width;
1130
- let h = obj.height;
1131
- const paddingX = 15;
1132
- const paddingY = 10;
1133
- if (left <= w / 2 - paddingX) left = w / 2 - paddingX;
1134
- if (left >= canvasWidth - (w / 2 - paddingX - 2.5)) left = canvasWidth - (w / 2 - paddingX - 2.5);
1135
- if (top <= (h - paddingY) / 2) top = (h - paddingY) / 2;
1136
- if (top >= canvasHeight - (h - paddingY) / 2) top = canvasHeight - (h - paddingY) / 2;
1137
- obj.set({ left, top }).setCoords();
1127
+ const scaleX = obj.scaleX ?? 1;
1128
+ const scaleY = obj.scaleY ?? 1;
1129
+ const width = obj.width * scaleX;
1130
+ const height = obj.height * scaleY;
1131
+ let left = obj.left ?? 0;
1132
+ let top = obj.top ?? 0;
1133
+ const halfW = width / 2;
1134
+ const halfH = height / 2;
1135
+ if (left - halfW < 0) left = halfW;
1136
+ if (left + halfW > canvasWidth) left = canvasWidth - halfW;
1137
+ if (top - halfH < 0) top = halfH;
1138
+ if (top + halfH > canvasHeight) top = canvasHeight - halfH;
1139
+ obj.set({ left, top });
1140
+ });
1141
+ canvas.on("object:scaling", (e) => {
1142
+ if (!lockInBoundsRef.current) return;
1143
+ const obj = e.target;
1144
+ obj.setCoords();
1145
+ const bounds = obj.getBoundingRect();
1146
+ const canvasWidth = canvas.getWidth();
1147
+ const canvasHeight = canvas.getHeight();
1148
+ const outOfBounds = bounds.left < 0 || bounds.top < 0 || bounds.left + bounds.width > canvasWidth || bounds.top + bounds.height > canvasHeight;
1149
+ if (outOfBounds) {
1150
+ if (lastValidScaleRef.current) {
1151
+ obj.set(lastValidScaleRef.current).setCoords();
1152
+ }
1153
+ } else {
1154
+ lastValidScaleRef.current = {
1155
+ scaleX: obj.scaleX,
1156
+ scaleY: obj.scaleY,
1157
+ left: obj.left,
1158
+ top: obj.top
1159
+ };
1160
+ }
1138
1161
  });
1139
1162
  };
1140
1163
  const imitateDBclick = (active, canvas) => {
@@ -1358,6 +1381,7 @@ var EditorCanvas = react.forwardRef(
1358
1381
  });
1359
1382
  window.dispatchEvent(event);
1360
1383
  };
1384
+ const isVisibleColor = (color) => !!color && color !== "transparent" && !/rgba\([^)]*,\s*0\s*\)$/.test(color);
1361
1385
  const createTextObjs = async ({ strokeW, stColor, fontAssetUrl = null, letterSpace, bgColor, textContent, textBasicInfo, textColor }) => {
1362
1386
  const { width, height } = vmml.template.dimension;
1363
1387
  const fontSize = vmmlUtils.getFontSize(width, height);
@@ -1431,8 +1455,11 @@ var EditorCanvas = react.forwardRef(
1431
1455
  rx: round,
1432
1456
  ry: round
1433
1457
  });
1458
+ let list = [];
1459
+ if (bgColor && isVisibleColor(bgColor)) list = [bgRect, ...textObjs];
1460
+ else list = [...textObjs];
1434
1461
  return {
1435
- objects: [bgRect, ...textObjs],
1462
+ objects: list,
1436
1463
  fontFamily
1437
1464
  };
1438
1465
  };