circle.vue 2.9 KB

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