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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. seed: Math.random(),
  36. type: ShapeType.Arrow,
  37. isGenerated: false,
  38. name: 'Arrow',
  39. parentId: 'page1',
  40. childIndex: 0,
  41. point,
  42. rotation: 0,
  43. isAspectRatioLocked: false,
  44. isLocked: false,
  45. isHidden: false,
  46. bend: 0,
  47. handles,
  48. decorations: {
  49. start: null,
  50. middle: null,
  51. end: Decoration.Arrow,
  52. },
  53. ...props,
  54. style: {
  55. ...defaultStyle,
  56. ...props.style,
  57. isFilled: false,
  58. },
  59. })
  60. }
  61. get start(): number[] {
  62. return this.shape.handles.start.point
  63. }
  64. set start(point: number[]) {
  65. getShapeUtils(this.shape).onHandleChange(this.shape, {
  66. start: { ...this.shape.handles.start, point },
  67. })
  68. }
  69. get middle(): number[] {
  70. return this.shape.handles.bend.point
  71. }
  72. set middle(point: number[]) {
  73. getShapeUtils(this.shape).onHandleChange(this.shape, {
  74. bend: { ...this.shape.handles.bend, point },
  75. })
  76. }
  77. get end(): number[] {
  78. return this.shape.handles.end.point
  79. }
  80. set end(point: number[]) {
  81. getShapeUtils(this.shape).onHandleChange(this.shape, {
  82. end: { ...this.shape.handles.end, point },
  83. })
  84. }
  85. get bend(): number {
  86. return this.shape.bend
  87. }
  88. }