| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- import CodeShape from './index'
- import { uniqueId } from 'utils'
- import { ArrowShape, Decoration, ShapeProps, ShapeType } from 'types'
- import { defaultStyle } from 'state/shape-styles'
- import { getShapeUtils } from 'state/shape-utils'
- import Vec from 'utils/vec'
-
- /* ----------------- Start Copy Here ---------------- */
-
- export default class Arrow extends CodeShape<ArrowShape> {
- constructor(
- props = {} as ShapeProps<ArrowShape> & { start: number[]; end: number[] }
- ) {
- const { start = [0, 0], end = [0, 0] } = props
-
- const {
- point = [0, 0],
- handles = {
- start: {
- id: 'start',
- index: 0,
- point: start,
- },
- end: {
- id: 'end',
- index: 1,
- point: end,
- },
- bend: {
- id: 'bend',
- index: 2,
- point: Vec.med(start, end),
- },
- },
- } = props
-
- super({
- id: uniqueId(),
-
- type: ShapeType.Arrow,
- isGenerated: false,
- name: 'Arrow',
- parentId: 'page1',
- childIndex: 0,
- point,
- rotation: 0,
- isAspectRatioLocked: false,
- isLocked: false,
- isHidden: false,
- bend: 0,
- handles,
- decorations: {
- start: null,
- middle: null,
- end: Decoration.Arrow,
- },
- ...props,
- style: {
- ...defaultStyle,
- ...props.style,
- isFilled: false,
- },
- })
- }
-
- /**
- * The arrow's start point.
- *
- * ```ts
- * const startPoint = shape.start
- *
- * shape.start = [100, 100]
- * ```
- */
- get start(): number[] {
- return this.shape.handles.start.point
- }
-
- set start(point: number[]) {
- getShapeUtils(this.shape).onHandleChange(this.shape, {
- start: { ...this.shape.handles.start, point },
- })
- }
-
- /**
- * The arrow's middle point.
- *
- * ```ts
- * const middlePoint = shape.middle
- *
- * shape.middle = [100, 100]
- * ```
- */
- get middle(): number[] {
- return this.shape.handles.bend.point
- }
-
- set middle(point: number[]) {
- getShapeUtils(this.shape).onHandleChange(this.shape, {
- bend: { ...this.shape.handles.bend, point },
- })
- }
-
- /**
- * The arrow's end point.
- *
- * ```ts
- * const endPoint = shape.end
- *
- * shape.end = [100, 100]
- * ```
- */
- get end(): number[] {
- return this.shape.handles.end.point
- }
-
- set end(point: number[]) {
- getShapeUtils(this.shape).onHandleChange(this.shape, {
- end: { ...this.shape.handles.end, point },
- })
- }
-
- get bend(): number {
- return this.shape.bend
- }
- }
|