選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

line.ts 1.1KB

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