@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/.turbo/turbo-build.log +8 -8
- package/dist/index.js +55 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/components/EditorCanvas.tsx +87 -14
- package/src/index.tsx +3 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @versa_ai/vmml-editor@1.0.
|
|
2
|
+
> @versa_ai/vmml-editor@1.0.58 build D:\code\work\vmml-player\packages\editor
|
|
3
3
|
> tsup
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.tsx
|
|
@@ -124,12 +124,12 @@ More info and automated migrator: https://sass-lang.com/d/slash-div[0m [1m[35
|
|
|
124
124
|
|
|
125
125
|
|
|
126
126
|
|
|
127
|
-
[
|
|
128
|
-
[
|
|
129
|
-
[
|
|
130
|
-
[
|
|
131
|
-
[
|
|
132
|
-
[
|
|
133
|
-
[32mDTS[39m ⚡️ Build success in
|
|
127
|
+
[32mESM[39m [1mdist\index.mjs [22m[32m122.67 KB[39m
|
|
128
|
+
[32mESM[39m [1mdist\index.mjs.map [22m[32m239.53 KB[39m
|
|
129
|
+
[32mESM[39m ⚡️ Build success in 3480ms
|
|
130
|
+
[32mCJS[39m [1mdist\index.js [22m[32m124.56 KB[39m
|
|
131
|
+
[32mCJS[39m [1mdist\index.js.map [22m[32m239.83 KB[39m
|
|
132
|
+
[32mCJS[39m ⚡️ Build success in 3480ms
|
|
133
|
+
[32mDTS[39m ⚡️ Build success in 3938ms
|
|
134
134
|
[32mDTS[39m [1mdist\index.d.ts [22m[32m158.00 B[39m
|
|
135
135
|
[32mDTS[39m [1mdist\index.d.mts [22m[32m158.00 B[39m
|
package/dist/index.js
CHANGED
|
@@ -1033,7 +1033,7 @@ function usePeekControl(canvas, hideConfig) {
|
|
|
1033
1033
|
return canvas;
|
|
1034
1034
|
}
|
|
1035
1035
|
var EditorCanvas = react.forwardRef(
|
|
1036
|
-
({ previewState, showCanvas, canvasSize, enterPreview, intoTextEdit, frame, vmml, dragState, initFcObjs, editClips = [], onVideoChange, isBatchModify, hideConfig, textWarapCenter, updateVmml }, ref) => {
|
|
1036
|
+
({ lockInBounds, previewState, showCanvas, canvasSize, enterPreview, intoTextEdit, frame, vmml, dragState, initFcObjs, editClips = [], onVideoChange, isBatchModify, hideConfig, textWarapCenter, updateVmml }, ref) => {
|
|
1037
1037
|
const [fc, setFc] = react.useState(null);
|
|
1038
1038
|
const [history, setHistory] = react.useState(null);
|
|
1039
1039
|
const [canvasReady, setCanvasReady] = react.useState(false);
|
|
@@ -1043,6 +1043,8 @@ var EditorCanvas = react.forwardRef(
|
|
|
1043
1043
|
const heightScaleRef = react.useRef(1);
|
|
1044
1044
|
const widthScaleRef = react.useRef(1);
|
|
1045
1045
|
const fontCacheRef = react.useRef(/* @__PURE__ */ new Map());
|
|
1046
|
+
const lockInBoundsRef = react.useRef(lockInBounds);
|
|
1047
|
+
const lastValidScaleRef = react.useRef(null);
|
|
1046
1048
|
const initCanvas = () => {
|
|
1047
1049
|
const canvas = new fabric.fabric.Canvas("canvas", {
|
|
1048
1050
|
width: canvasSize.width,
|
|
@@ -1117,6 +1119,46 @@ var EditorCanvas = react.forwardRef(
|
|
|
1117
1119
|
const active = canvas.getActiveObject();
|
|
1118
1120
|
handleIntoTextMenu(active, canvas);
|
|
1119
1121
|
});
|
|
1122
|
+
canvas.on("object:moving", (e) => {
|
|
1123
|
+
if (!lockInBoundsRef.current) return;
|
|
1124
|
+
const obj = e.target;
|
|
1125
|
+
const canvasWidth = canvas.getWidth();
|
|
1126
|
+
const canvasHeight = canvas.getHeight();
|
|
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
|
+
}
|
|
1161
|
+
});
|
|
1120
1162
|
};
|
|
1121
1163
|
const imitateDBclick = (active, canvas) => {
|
|
1122
1164
|
active.isSelected++;
|
|
@@ -1278,7 +1320,9 @@ var EditorCanvas = react.forwardRef(
|
|
|
1278
1320
|
top,
|
|
1279
1321
|
angle: posParam.rotationZ,
|
|
1280
1322
|
originX: "center",
|
|
1323
|
+
// 圆点:中心点
|
|
1281
1324
|
originY: "center",
|
|
1325
|
+
// 圆点:中心点
|
|
1282
1326
|
clipData: {
|
|
1283
1327
|
id: clip.id,
|
|
1284
1328
|
isMute: null,
|
|
@@ -1337,6 +1381,7 @@ var EditorCanvas = react.forwardRef(
|
|
|
1337
1381
|
});
|
|
1338
1382
|
window.dispatchEvent(event);
|
|
1339
1383
|
};
|
|
1384
|
+
const isVisibleColor = (color) => !!color && color !== "transparent" && !/rgba\([^)]*,\s*0\s*\)$/.test(color);
|
|
1340
1385
|
const createTextObjs = async ({ strokeW, stColor, fontAssetUrl = null, letterSpace, bgColor, textContent, textBasicInfo, textColor }) => {
|
|
1341
1386
|
const { width, height } = vmml.template.dimension;
|
|
1342
1387
|
const fontSize = vmmlUtils.getFontSize(width, height);
|
|
@@ -1410,8 +1455,11 @@ var EditorCanvas = react.forwardRef(
|
|
|
1410
1455
|
rx: round,
|
|
1411
1456
|
ry: round
|
|
1412
1457
|
});
|
|
1458
|
+
let list = [];
|
|
1459
|
+
if (bgColor && isVisibleColor(bgColor)) list = [bgRect, ...textObjs];
|
|
1460
|
+
else list = [...textObjs];
|
|
1413
1461
|
return {
|
|
1414
|
-
objects:
|
|
1462
|
+
objects: list,
|
|
1415
1463
|
fontFamily
|
|
1416
1464
|
};
|
|
1417
1465
|
};
|
|
@@ -1712,6 +1760,9 @@ var EditorCanvas = react.forwardRef(
|
|
|
1712
1760
|
}
|
|
1713
1761
|
}
|
|
1714
1762
|
}, [fc]);
|
|
1763
|
+
react.useEffect(() => {
|
|
1764
|
+
lockInBoundsRef.current = lockInBounds;
|
|
1765
|
+
}, [lockInBounds]);
|
|
1715
1766
|
const getCanvasCtx = () => {
|
|
1716
1767
|
return fc;
|
|
1717
1768
|
};
|
|
@@ -2512,6 +2563,7 @@ var EditorFn = ({
|
|
|
2512
2563
|
textWarapCenter = false,
|
|
2513
2564
|
backgroundColor = "#000",
|
|
2514
2565
|
existenceBorderRadio = true,
|
|
2566
|
+
lockInBounds = false,
|
|
2515
2567
|
hideConfig = { hideDelete: false, hideEdit: false, hideMute: false, hideVolume: false }
|
|
2516
2568
|
// { hideDelete: false, hideEdit: false, hideMute: false, hideVolume: false }
|
|
2517
2569
|
}, ref) => {
|
|
@@ -3006,6 +3058,7 @@ var EditorFn = ({
|
|
|
3006
3058
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3007
3059
|
EditorCanvas_default,
|
|
3008
3060
|
{
|
|
3061
|
+
lockInBounds,
|
|
3009
3062
|
ref: canvasRef,
|
|
3010
3063
|
previewState,
|
|
3011
3064
|
showCanvas,
|