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.

arrow.ts 2.1KB

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. 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. get start(): number[] {
  61. return this.shape.handles.start.point
  62. }
  63. set start(point: number[]) {
  64. getShapeUtils(this.shape).onHandleChange(this.shape, {
  65. start: { ...this.shape.handles.start, point },
  66. })
  67. }
  68. get middle(): number[] {
  69. return this.shape.handles.bend.point
  70. }
  71. set middle(point: number[]) {
  72. getShapeUtils(this.shape).onHandleChange(this.shape, {
  73. bend: { ...this.shape.handles.bend, point },
  74. })
  75. }
  76. get end(): number[] {
  77. return this.shape.handles.end.point
  78. }
  79. set end(point: number[]) {
  80. getShapeUtils(this.shape).onHandleChange(this.shape, {
  81. end: { ...this.shape.handles.end, point },
  82. })
  83. }
  84. get bend(): number {
  85. return this.shape.bend
  86. }
  87. }