index.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { InteractiveMessage } from "../../hook/use-interactive.ts";
  2. import { ImageConfig } from "konva/lib/shapes/Image";
  3. export { default as Component } from "./icon.vue";
  4. export const shapeName = "图例";
  5. export const defaultStyle = {
  6. strokeScaleEnabled: true,
  7. width: 80,
  8. height: 80
  9. };
  10. export const addMode = 'dot'
  11. export const style = {
  12. default: defaultStyle,
  13. focus: defaultStyle,
  14. hover: defaultStyle,
  15. };
  16. export type IconData = Partial<typeof defaultStyle> & {
  17. fill?: string;
  18. stroke?: string;
  19. strokeWidth?: number;
  20. coverFill?: string;
  21. coverStroke?: string,
  22. coverStrokeWidth?: number,
  23. width: number;
  24. height: number;
  25. x: number;
  26. y: number;
  27. url: string
  28. };
  29. export const dataToConfig = (data: IconData): Omit<ImageConfig, 'image'> => ({
  30. ...defaultStyle,
  31. ...data
  32. })
  33. export const interactiveToData = (
  34. info: InteractiveMessage,
  35. preset: Partial<IconData> = {}
  36. ): IconData | undefined => {
  37. if (info.dot) {
  38. return interactiveFixData({ ...preset, } as unknown as IconData, info);
  39. }
  40. };
  41. export const interactiveFixData = (
  42. data: IconData,
  43. info: InteractiveMessage
  44. ) => {
  45. data.x = info.dot!.x
  46. data.y = info.dot!.y
  47. return data;
  48. };