index.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import * as arrow from './arrow'
  2. import * as rectangle from './rectangle'
  3. import * as circle from './circle'
  4. import * as triangle from './triangle'
  5. import * as polygon from './polygon'
  6. import * as line from './line'
  7. import * as text from './text'
  8. import * as icon from './icon'
  9. import * as image from './image'
  10. import { ArrowData } from './arrow'
  11. import { RectangleData } from './rectangle'
  12. import { CircleData } from './circle'
  13. import { TriangleData } from './triangle'
  14. import { PolygonData } from './polygon'
  15. import { LineData } from './line'
  16. import { TextData } from './text'
  17. import { IconData } from './icon'
  18. import { ImageData } from './image'
  19. import { Pos } from '@/utils/math'
  20. const _components = {
  21. arrow,
  22. rectangle,
  23. circle,
  24. triangle,
  25. polygon,
  26. line,
  27. text,
  28. icon,
  29. image
  30. }
  31. export const components = _components as Components
  32. export type Components = {
  33. [key in keyof typeof _components]: (typeof _components)[key] & {
  34. getSnapInfos?: (items: DrawItem<key>) => ComponentSnapInfo[]
  35. }
  36. }
  37. export type ComponentValue<T extends ShapeType, K extends keyof Components[T]> = Components[T][K]
  38. export type DrawDataItem = {
  39. arrow: ArrowData,
  40. rectangle: RectangleData,
  41. circle: CircleData,
  42. triangle: TriangleData,
  43. polygon: PolygonData,
  44. line: LineData,
  45. text: TextData,
  46. icon: IconData,
  47. image: ImageData,
  48. }
  49. export type ShapeType = keyof DrawDataItem
  50. export type DrawData = {
  51. [k in ShapeType]?: DrawDataItem[k][]
  52. }
  53. export type DrawItem<T extends ShapeType = ShapeType> = DrawDataItem[T]
  54. export type SnapPoint = Pos & { view?: boolean }
  55. export type ComponentSnapInfo = {
  56. point: SnapPoint,
  57. links: Pos[]
  58. linkDirections: Pos[],
  59. linkAngle: number[]
  60. }