index.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { Pos } from "@/utils/math.ts";
  2. import { themeMouseColors } from "@/constant/help-style.ts";
  3. import { BaseItem, generateSnapInfos, getBaseItem } from "../util.ts";
  4. import { getMouseColors } from "@/utils/colors.ts";
  5. import { InteractiveFix, InteractiveTo } from "../index.ts";
  6. export { default as Component } from "./polygon.vue";
  7. export { default as TempComponent } from "./temp-polygon.vue";
  8. export const shapeName = "多边形";
  9. export const defaultStyle = {
  10. stroke: themeMouseColors.theme,
  11. strokeWidth: 5,
  12. dash: [30, 0],
  13. };
  14. export const getMouseStyle = (data: PolygonData) => {
  15. const fillStatus = data.fill && getMouseColors(data.fill);
  16. const strokeStatus = getMouseColors(data.stroke || defaultStyle.stroke);
  17. const strokeWidth = data.strokeWidth;
  18. return {
  19. default: {
  20. fill: fillStatus && fillStatus.pub,
  21. stroke: strokeStatus.pub,
  22. strokeWidth,
  23. },
  24. hover: { fill: fillStatus && fillStatus.hover, stroke: strokeStatus.hover },
  25. press: { fill: fillStatus && fillStatus.press, stroke: strokeStatus.press },
  26. };
  27. };
  28. export const addMode = "dots";
  29. export const getSnapInfos = (data: PolygonData) =>
  30. generateSnapInfos(getSnapPoints(data), true, true);
  31. export const getSnapPoints = (data: PolygonData) => {
  32. return data.points;
  33. };
  34. export type PolygonData = Partial<typeof defaultStyle> &
  35. BaseItem & {
  36. fill?: string;
  37. points: Pos[];
  38. attitude: number[];
  39. };
  40. export const interactiveToData: InteractiveTo<"polygon"> = ({
  41. info,
  42. preset = {},
  43. ...args
  44. }) => {
  45. if (info.cur) {
  46. return interactiveFixData({
  47. ...args,
  48. info,
  49. data: {
  50. ...getBaseItem(),
  51. ...preset,
  52. points: [],
  53. attitude: [1, 0, 0, 1, 0, 0],
  54. },
  55. });
  56. }
  57. };
  58. export const interactiveFixData: InteractiveFix<"polygon"> = ({
  59. data,
  60. info,
  61. }) => {
  62. data.points = [...info.consumed, info.cur!];
  63. return data;
  64. };