circle.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <TempCircle :data="tData" :ref="(v: any) => shape = v?.shape" :id="data.id" />
  3. <PropertyUpdate
  4. :describes="describes"
  5. :data="data"
  6. :target="shape"
  7. @change="emit('updateShape', { ...data })"
  8. />
  9. <Operate :target="shape" :menus="operateMenus" />
  10. </template>
  11. <script lang="ts" setup>
  12. import { CircleData, getMouseStyle, defaultStyle } from "./index.ts";
  13. import { PropertyUpdate, Operate } from "../../propertys";
  14. import TempCircle from "./temp-circle.vue";
  15. import { useComponentStatus } from "@/core/hook/use-component.ts";
  16. import { Transform } from "konva/lib/Util";
  17. import { MathUtils } from "three";
  18. import { cloneRepShape, useCustomTransformer } from "@/core/hook/use-transformer.ts";
  19. import { setShapeTransform } from "@/utils/shape.ts";
  20. import { Ellipse } from "konva/lib/shapes/Ellipse";
  21. import { Pos } from "@/utils/math.ts";
  22. const props = defineProps<{ data: CircleData }>();
  23. const emit = defineEmits<{
  24. (e: "updateShape", value: CircleData): void;
  25. (e: "addShape", value: CircleData): void;
  26. (e: "delShape"): void;
  27. }>();
  28. const matToData = (data: CircleData, mat: Transform, initRadius?: Pos) => {
  29. // data.mat = mat.m;
  30. // return data;
  31. if (!initRadius) {
  32. initRadius = {
  33. x: data.radiusX,
  34. y: data.radiusY,
  35. };
  36. }
  37. const dec = mat.decompose();
  38. data.radiusY = dec.scaleY * initRadius.y;
  39. data.radiusX = dec.scaleX * initRadius.x;
  40. data.mat = new Transform()
  41. .translate(dec.x, dec.y)
  42. .rotate(MathUtils.degToRad(dec.rotation)).m;
  43. return data;
  44. };
  45. const { shape, tData, data, operateMenus, describes } = useComponentStatus<
  46. Ellipse,
  47. CircleData
  48. >({
  49. emit,
  50. props,
  51. getMouseStyle,
  52. defaultStyle,
  53. alignment: (data, mat) => {
  54. const tf = shape.value!.getNode().getTransform();
  55. mat.multiply(tf);
  56. return matToData(data, mat);
  57. },
  58. // transformType: "mat",
  59. transformType: "custom",
  60. customTransform(callback, shape, data) {
  61. let initRadius: Pos;
  62. useCustomTransformer(shape, data, {
  63. openSnap: true,
  64. getRepShape($shape) {
  65. const repShape = cloneRepShape($shape).shape;
  66. initRadius = { x: repShape.radiusX(), y: repShape.radiusY() };
  67. return {
  68. shape: repShape,
  69. };
  70. },
  71. handler(data, mat) {
  72. matToData(data, mat, initRadius);
  73. return true;
  74. },
  75. callback,
  76. });
  77. },
  78. copyHandler(mat, data) {
  79. const tf = shape.value!.getNode().getTransform();
  80. mat.multiply(tf);
  81. return matToData({ ...data }, mat);
  82. },
  83. propertys: [
  84. "fill",
  85. "stroke",
  86. "strokeWidth",
  87. "dash",
  88. // "ref",
  89. "opacity",
  90. // "zIndex"
  91. ],
  92. });
  93. </script>