Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import CodeShape from './index'
  2. import { uniqueId } from 'utils'
  3. import { ArrowShape, Decoration, ShapeProps, ShapeType } from 'types'
  4. import { defaultStyle } from 'state/shape-styles'
  5. import { getShapeUtils } from 'state/shape-utils'
  6. import Vec from 'utils/vec'
  7. /* ----------------- Start Copy Here ---------------- */
  8. export default class Arrow extends CodeShape<ArrowShape> {
  9. constructor(
  10. props = {} as ShapeProps<ArrowShape> & { start: number[]; end: number[] }
  11. ) {
  12. const { start = [0, 0], end = [0, 0] } = props
  13. const {
  14. point = [0, 0],
  15. handles = {
  16. start: {
  17. id: 'start',
  18. index: 0,
  19. point: start,
  20. },
  21. end: {
  22. id: 'end',
  23. index: 1,
  24. point: end,
  25. },
  26. bend: {
  27. id: 'bend',
  28. index: 2,
  29. point: Vec.med(start, end),
  30. },
  31. },
  32. } = props
  33. super({
  34. id: uniqueId(),
  35. type: ShapeType.Arrow,
  36. isGenerated: false,
  37. name: 'Arrow',
  38. parentId: 'page1',
  39. childIndex: 0,
  40. point,
  41. rotation: 0,
  42. isAspectRatioLocked: false,
  43. isLocked: false,
  44. isHidden: false,
  45. bend: 0,
  46. handles,
  47. decorations: {
  48. start: null,
  49. middle: null,
  50. end: Decoration.Arrow,
  51. },
  52. ...props,
  53. style: {
  54. ...defaultStyle,
  55. ...props.style,
  56. isFilled: false,
  57. },
  58. })
  59. }
  60. /**
  61. * The arrow's start point.
  62. *
  63. * ```ts
  64. * const startPoint = shape.start
  65. *
  66. * shape.start = [100, 100]
  67. * ```
  68. */
  69. get start(): number[] {
  70. return this.shape.handles.start.point
  71. }
  72. set start(point: number[]) {
  73. getShapeUtils(this.shape).onHandleChange(this.shape, {
  74. start: { ...this.shape.handles.start, point },
  75. })
  76. }
  77. /**
  78. * The arrow's middle point.
  79. *
  80. * ```ts
  81. * const middlePoint = shape.middle
  82. *
  83. * shape.middle = [100, 100]
  84. * ```
  85. */
  86. get middle(): number[] {
  87. return this.shape.handles.bend.point
  88. }
  89. set middle(point: number[]) {
  90. getShapeUtils(this.shape).onHandleChange(this.shape, {
  91. bend: { ...this.shape.handles.bend, point },
  92. })
  93. }
  94. /**
  95. * The arrow's end point.
  96. *
  97. * ```ts
  98. * const endPoint = shape.end
  99. *
  100. * shape.end = [100, 100]
  101. * ```
  102. */
  103. get end(): number[] {
  104. return this.shape.handles.end.point
  105. }
  106. set end(point: number[]) {
  107. getShapeUtils(this.shape).onHandleChange(this.shape, {
  108. end: { ...this.shape.handles.end, point },
  109. })
  110. }
  111. get bend(): number {
  112. return this.shape.bend
  113. }
  114. }