index.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { InteractiveMessage } from "../../hook/use-interactive.ts";
  2. import { Pos } from "@/utils/math.ts";
  3. import { themeMouseColors } from "@/constant/help-style.ts";
  4. import { BaseItem, generateSnapInfos, getBaseItem } from "../util.ts";
  5. import { getMouseColors } from "@/utils/colors.ts";
  6. export { default as Component } from "./triangle.vue";
  7. export { default as TempComponent } from "./temp-triangle.vue";
  8. export const shapeName = "三角形";
  9. export const defaultStyle = {
  10. stroke: themeMouseColors.theme,
  11. strokeWidth: 5,
  12. fill: "#fff",
  13. };
  14. export const addMode = "area";
  15. export const getMouseStyle = (data: TriangleData) => {
  16. const fillStatus = getMouseColors(data.fill || defaultStyle.fill);
  17. const strokeStatus = getMouseColors(data.stroke || defaultStyle.stroke);
  18. const strokeWidth = data.strokeWidth || defaultStyle.strokeWidth;
  19. return {
  20. default: { fill: fillStatus.pub, stroke: strokeStatus.pub, strokeWidth },
  21. hover: { fill: fillStatus.hover },
  22. press: { fill: fillStatus.press },
  23. };
  24. };
  25. export type TriangleData = Partial<typeof defaultStyle> &
  26. BaseItem & { points: Pos[]; attitude: number[] };
  27. export const getSnapInfos = (data: TriangleData) => generateSnapInfos(data.points, true, false)
  28. export const interactiveToData = (
  29. info: InteractiveMessage,
  30. preset: Partial<TriangleData> = {}
  31. ): TriangleData | undefined => {
  32. if (info.area) {
  33. const item = {
  34. ...getBaseItem(),
  35. ...preset,
  36. points: [],
  37. } as unknown as TriangleData;
  38. return interactiveFixData(item, info);
  39. }
  40. };
  41. export const interactiveFixData = (
  42. data: TriangleData,
  43. info: InteractiveMessage
  44. ) => {
  45. const area = info.area!;
  46. data.points[0] = {
  47. x: area[0].x - (area[1].x - area[0].x),
  48. y: area[1].y,
  49. };
  50. data.points[1] = area[0];
  51. data.points[2] = area[1];
  52. return data;
  53. };