temp-text.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <ShareText
  3. :config="{
  4. ...data,
  5. wrap: 'char',
  6. ...matConfig,
  7. text: data.content,
  8. zIndex: undefined,
  9. verticalAlign: 'center',
  10. opacity: addMode ? 0.3 : data.opacity,
  11. }"
  12. :parent-id="data.id"
  13. :ref="(r: any) => shape = r?.shape"
  14. :editer="editer && !data.disableEditText"
  15. @update-text="(v) => emit('updateContent', v)"
  16. />
  17. </template>
  18. <script lang="ts" setup>
  19. import ShareText from "../share/text.vue";
  20. import { defaultStyle, TextData, textNodeMap } from "./index.ts";
  21. import { computed, ref, watchEffect } from "vue";
  22. import { DC } from "@/deconstruction.js";
  23. import { Transform } from "konva/lib/Util";
  24. import { Text } from "konva/lib/shapes/Text";
  25. const props = defineProps<{ data: TextData; addMode?: boolean; editer?: boolean }>();
  26. const emit = defineEmits<{
  27. (e: "updateContent", data: string): void;
  28. (e: "update:isEdit", val: boolean): void;
  29. }>();
  30. const defStyle = { ...defaultStyle };
  31. const data = computed(() => ({ ...defStyle, ...props.data }));
  32. const shape = ref<DC<Text>>();
  33. defineExpose({
  34. get shape() {
  35. return shape.value;
  36. },
  37. });
  38. const matConfig = computed(() => {
  39. return new Transform(data.value.mat).decompose();
  40. });
  41. watchEffect((oncleanup) => {
  42. if (shape.value?.getNode()) {
  43. textNodeMap[props.data.id] = shape.value.getNode();
  44. oncleanup(() => delete textNodeMap[props.data.id]);
  45. }
  46. });
  47. </script>