You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

types.ts 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. export interface Data {
  2. camera: {
  3. point: number[]
  4. zoom: number
  5. }
  6. brush?: Bounds
  7. currentPageId: string
  8. selectedIds: string[]
  9. pointedId?: string
  10. document: {
  11. pages: Record<string, Page>
  12. }
  13. }
  14. export interface Page {
  15. id: string
  16. type: "page"
  17. childIndex: number
  18. name: string
  19. shapes: Record<string, Shape>
  20. }
  21. export enum ShapeType {
  22. Dot = "dot",
  23. Circle = "circle",
  24. Ellipse = "ellipse",
  25. Line = "line",
  26. Ray = "ray",
  27. Polyline = "Polyline",
  28. Rectangle = "rectangle",
  29. // Glob = "glob",
  30. // Spline = "spline",
  31. // Cubic = "cubic",
  32. // Conic = "conic",
  33. }
  34. export interface BaseShape {
  35. id: string
  36. type: ShapeType
  37. parentId: string
  38. childIndex: number
  39. name: string
  40. point: number[]
  41. rotation: 0
  42. }
  43. export interface DotShape extends BaseShape {
  44. type: ShapeType.Dot
  45. }
  46. export interface CircleShape extends BaseShape {
  47. type: ShapeType.Circle
  48. radius: number
  49. }
  50. export interface EllipseShape extends BaseShape {
  51. type: ShapeType.Ellipse
  52. radiusX: number
  53. radiusY: number
  54. }
  55. export interface LineShape extends BaseShape {
  56. type: ShapeType.Line
  57. vector: number[]
  58. }
  59. export interface RayShape extends BaseShape {
  60. type: ShapeType.Ray
  61. vector: number[]
  62. }
  63. export interface PolylineShape extends BaseShape {
  64. type: ShapeType.Polyline
  65. points: number[][]
  66. }
  67. export interface RectangleShape extends BaseShape {
  68. type: ShapeType.Rectangle
  69. size: number[]
  70. }
  71. export type Shape =
  72. | DotShape
  73. | CircleShape
  74. | EllipseShape
  75. | LineShape
  76. | RayShape
  77. | PolylineShape
  78. | RectangleShape
  79. export interface Bounds {
  80. minX: number
  81. minY: number
  82. maxX: number
  83. maxY: number
  84. width: number
  85. height: number
  86. }
  87. export interface Shapes extends Record<ShapeType, Shape> {
  88. [ShapeType.Dot]: DotShape
  89. [ShapeType.Circle]: CircleShape
  90. [ShapeType.Ellipse]: EllipseShape
  91. [ShapeType.Line]: LineShape
  92. [ShapeType.Ray]: RayShape
  93. [ShapeType.Polyline]: PolylineShape
  94. [ShapeType.Rectangle]: RectangleShape
  95. }