|
@@ -13,7 +13,7 @@
|
|
:target="shape"
|
|
:target="shape"
|
|
@change="emit('updateShape', { ...data })"
|
|
@change="emit('updateShape', { ...data })"
|
|
/>
|
|
/>
|
|
- <!-- <Operate :target="shape" :menus="operateMenus" v-if="!editText" /> -->
|
|
|
|
|
|
+ <Operate :target="shape" :menus="operateMenus" v-if="!editText" />
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
@@ -29,7 +29,7 @@ import {
|
|
} from "@/core/hook/use-transformer.ts";
|
|
} from "@/core/hook/use-transformer.ts";
|
|
import { Transform } from "konva/lib/Util";
|
|
import { Transform } from "konva/lib/Util";
|
|
import { Text } from "konva/lib/shapes/Text";
|
|
import { Text } from "konva/lib/shapes/Text";
|
|
-import { computed, ref, shallowRef, watchEffect } from "vue";
|
|
|
|
|
|
+import { computed, ref, shallowRef, watch, watchEffect } from "vue";
|
|
import { setShapeTransform } from "@/utils/shape.ts";
|
|
import { setShapeTransform } from "@/utils/shape.ts";
|
|
import { zeroEq } from "@/utils/math.ts";
|
|
import { zeroEq } from "@/utils/math.ts";
|
|
import { MathUtils } from "three";
|
|
import { MathUtils } from "three";
|
|
@@ -42,7 +42,6 @@ const emit = defineEmits<{
|
|
(e: "delShape"): void;
|
|
(e: "delShape"): void;
|
|
}>();
|
|
}>();
|
|
|
|
|
|
-const minWidth = computed(() => (props.data.fontSize || 12) * 2);
|
|
|
|
const { shape, tData, data, operateMenus, describes } = useComponentStatus<
|
|
const { shape, tData, data, operateMenus, describes } = useComponentStatus<
|
|
Text,
|
|
Text,
|
|
TextData
|
|
TextData
|
|
@@ -53,30 +52,6 @@ const { shape, tData, data, operateMenus, describes } = useComponentStatus<
|
|
defaultStyle,
|
|
defaultStyle,
|
|
transformType: "custom",
|
|
transformType: "custom",
|
|
customTransform(callback, shape, data) {
|
|
customTransform(callback, shape, data) {
|
|
- const update = (mat: Transform, data: TextData) => {
|
|
|
|
- const { scaleX, x, y, rotation } = mat.decompose();
|
|
|
|
- if (!zeroEq(scaleX - 1)) {
|
|
|
|
- let width: number | undefined;
|
|
|
|
- if ("width" in data) {
|
|
|
|
- width = Math.max(data.width! * scaleX, minWidth.value);
|
|
|
|
- } else {
|
|
|
|
- width = Math.max(shape.value!.getNode()!.width() * scaleX, minWidth.value);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return {
|
|
|
|
- width,
|
|
|
|
- mat: new Transform()
|
|
|
|
- .translate(x, y)
|
|
|
|
- .rotate(MathUtils.degToRad(rotation))
|
|
|
|
- .scale(1, 1).m,
|
|
|
|
- };
|
|
|
|
- } else {
|
|
|
|
- return {
|
|
|
|
- mat: mat.m,
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
useCustomTransformer(shape, data, {
|
|
useCustomTransformer(shape, data, {
|
|
openSnap: true,
|
|
openSnap: true,
|
|
getRepShape($shape) {
|
|
getRepShape($shape) {
|
|
@@ -91,11 +66,9 @@ const { shape, tData, data, operateMenus, describes } = useComponentStatus<
|
|
},
|
|
},
|
|
transformerConfig: {
|
|
transformerConfig: {
|
|
rotateEnabled: true,
|
|
rotateEnabled: true,
|
|
- keepRatio: true,
|
|
|
|
enabledAnchors: ["middle-left", "middle-right"],
|
|
enabledAnchors: ["middle-left", "middle-right"],
|
|
- flipEnabled: false,
|
|
|
|
boundBoxFunc: (oldBox, newBox) => {
|
|
boundBoxFunc: (oldBox, newBox) => {
|
|
- if (Math.abs(newBox.width) < minWidth.value) {
|
|
|
|
|
|
+ if (newBox.width - minWidth.value < -0.01) {
|
|
return oldBox;
|
|
return oldBox;
|
|
}
|
|
}
|
|
return newBox;
|
|
return newBox;
|
|
@@ -120,8 +93,58 @@ const { shape, tData, data, operateMenus, describes } = useComponentStatus<
|
|
mat: tf.multiply(new Transform(data.mat)).m,
|
|
mat: tf.multiply(new Transform(data.mat)).m,
|
|
};
|
|
};
|
|
},
|
|
},
|
|
|
|
+ propertys: [
|
|
|
|
+ "fill",
|
|
|
|
+ "stroke",
|
|
|
|
+ "strokeWidth",
|
|
|
|
+ "align",
|
|
|
|
+ "fontSize",
|
|
|
|
+ "fontStyle",
|
|
|
|
+ "dash",
|
|
|
|
+ "opacity",
|
|
|
|
+ "ref",
|
|
|
|
+ "zIndex",
|
|
|
|
+ ],
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+const minWidth = computed(() => (data.value.fontSize || 12) * 2);
|
|
|
|
+const getWidth = (data: TextData, scaleX: number) => {
|
|
|
|
+ let width: number;
|
|
|
|
+ if ("width" in data) {
|
|
|
|
+ width = Math.max(data.width! * scaleX, minWidth.value);
|
|
|
|
+ } else {
|
|
|
|
+ width = Math.max(shape.value!.getNode()!.width() * scaleX, minWidth.value);
|
|
|
|
+ }
|
|
|
|
+ return width;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+const update = (mat: Transform, data: TextData) => {
|
|
|
|
+ const { scaleX, x, y, rotation } = mat.decompose();
|
|
|
|
+ if (!zeroEq(scaleX - 1)) {
|
|
|
|
+ return {
|
|
|
|
+ width: getWidth(data, scaleX),
|
|
|
|
+ mat: new Transform()
|
|
|
|
+ .translate(x, y)
|
|
|
|
+ .rotate(MathUtils.degToRad(rotation))
|
|
|
|
+ .scale(1, 1).m,
|
|
|
|
+ };
|
|
|
|
+ } else {
|
|
|
|
+ return {
|
|
|
|
+ mat: mat.m,
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+// 字体大小变化时,更新width
|
|
|
|
+watch(
|
|
|
|
+ () => data.value.fontSize,
|
|
|
|
+ () => {
|
|
|
|
+ data.value.width = getWidth(data.value, 1);
|
|
|
|
+ const $shape = shape.value?.getNode();
|
|
|
|
+ $shape && $shape.fire("bound-change");
|
|
|
|
+ }
|
|
|
|
+);
|
|
|
|
+
|
|
watchEffect((oncleanup) => {
|
|
watchEffect((oncleanup) => {
|
|
if (shape.value?.getNode()) {
|
|
if (shape.value?.getNode()) {
|
|
textNodeMap[props.data.id] = shape.value.getNode();
|
|
textNodeMap[props.data.id] = shape.value.getNode();
|