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.

line.ts 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import CodeShape from './index'
  2. import { v4 as uuid } from 'uuid'
  3. import { LineShape, ShapeType } from 'types'
  4. import { vectorToPoint } from 'utils/utils'
  5. import { defaultStyle } from 'lib/shape-styles'
  6. export default class Line extends CodeShape<LineShape> {
  7. constructor(props = {} as Partial<LineShape>) {
  8. props.point = vectorToPoint(props.point)
  9. props.direction = vectorToPoint(props.direction)
  10. super({
  11. id: uuid(),
  12. type: ShapeType.Line,
  13. isGenerated: true,
  14. name: 'Line',
  15. parentId: 'page0',
  16. childIndex: 0,
  17. point: [0, 0],
  18. direction: [-0.5, 0.5],
  19. rotation: 0,
  20. isAspectRatioLocked: false,
  21. isLocked: false,
  22. isHidden: false,
  23. ...props,
  24. style: {
  25. ...defaultStyle,
  26. ...props.style,
  27. isFilled: false,
  28. },
  29. })
  30. }
  31. export() {
  32. const shape = { ...this.shape }
  33. shape.point = vectorToPoint(shape.point)
  34. shape.direction = vectorToPoint(shape.direction)
  35. return shape
  36. }
  37. get direction() {
  38. return this.shape.direction
  39. }
  40. }