Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import React from "react"
  2. export interface Data {
  3. isReadOnly: boolean
  4. camera: {
  5. point: number[]
  6. zoom: number
  7. }
  8. brush?: Bounds
  9. currentPageId: string
  10. selectedIds: Set<string>
  11. pointedId?: string
  12. document: {
  13. pages: Record<string, Page>
  14. }
  15. }
  16. export interface Page {
  17. id: string
  18. type: "page"
  19. childIndex: number
  20. name: string
  21. shapes: Record<string, Shape>
  22. }
  23. export enum ShapeType {
  24. Dot = "dot",
  25. Circle = "circle",
  26. Ellipse = "ellipse",
  27. Line = "line",
  28. Ray = "ray",
  29. Polyline = "polyline",
  30. Rectangle = "rectangle",
  31. // Glob = "glob",
  32. // Spline = "spline",
  33. // Cubic = "cubic",
  34. // Conic = "conic",
  35. }
  36. export interface BaseShape {
  37. id: string
  38. type: ShapeType
  39. parentId: string
  40. childIndex: number
  41. name: string
  42. point: number[]
  43. rotation: 0
  44. style: Partial<React.SVGProps<SVGUseElement>>
  45. }
  46. export interface DotShape extends BaseShape {
  47. type: ShapeType.Dot
  48. }
  49. export interface CircleShape extends BaseShape {
  50. type: ShapeType.Circle
  51. radius: number
  52. }
  53. export interface EllipseShape extends BaseShape {
  54. type: ShapeType.Ellipse
  55. radiusX: number
  56. radiusY: number
  57. }
  58. export interface LineShape extends BaseShape {
  59. type: ShapeType.Line
  60. vector: number[]
  61. }
  62. export interface RayShape extends BaseShape {
  63. type: ShapeType.Ray
  64. vector: number[]
  65. }
  66. export interface PolylineShape extends BaseShape {
  67. type: ShapeType.Polyline
  68. points: number[][]
  69. }
  70. export interface RectangleShape extends BaseShape {
  71. type: ShapeType.Rectangle
  72. size: number[]
  73. }
  74. export type Shape =
  75. | DotShape
  76. | CircleShape
  77. | EllipseShape
  78. | LineShape
  79. | RayShape
  80. | PolylineShape
  81. | RectangleShape
  82. export interface Bounds {
  83. minX: number
  84. minY: number
  85. maxX: number
  86. maxY: number
  87. width: number
  88. height: number
  89. }
  90. export interface Shapes extends Record<ShapeType, Shape> {
  91. [ShapeType.Dot]: DotShape
  92. [ShapeType.Circle]: CircleShape
  93. [ShapeType.Ellipse]: EllipseShape
  94. [ShapeType.Line]: LineShape
  95. [ShapeType.Ray]: RayShape
  96. [ShapeType.Polyline]: PolylineShape
  97. [ShapeType.Rectangle]: RectangleShape
  98. }
  99. export type Difference<A, B> = A extends B ? never : A
  100. export type ShapeSpecificProps<T extends Shape> = Pick<
  101. T,
  102. Difference<keyof T, keyof BaseShape>
  103. >
  104. export type ShapeIndicatorProps<T extends Shape> = ShapeSpecificProps<T>
  105. export type BaseLibShape<K extends ShapeType> = {
  106. create(props: Partial<Shapes[K]>): Shapes[K]
  107. getBounds(shape: Shapes[K]): Bounds
  108. hitTest(shape: Shapes[K], test: number[]): boolean
  109. rotate(shape: Shapes[K]): Shapes[K]
  110. translate(shape: Shapes[K], delta: number[]): Shapes[K]
  111. scale(shape: Shapes[K], scale: number): Shapes[K]
  112. stretch(shape: Shapes[K], scaleX: number, scaleY: number): Shapes[K]
  113. render(shape: Shapes[K]): JSX.Element
  114. }
  115. export interface PointerInfo {
  116. pointerId: number
  117. origin: number[]
  118. point: number[]
  119. shiftKey: boolean
  120. ctrlKey: boolean
  121. metaKey: boolean
  122. altKey: boolean
  123. }