Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

rectangle.ts 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import CodeShape from './index'
  2. import { uniqueId } from 'utils'
  3. import { RectangleShape, ShapeProps, ShapeType } from 'types'
  4. import { defaultStyle } from 'state/shape-styles'
  5. import { getShapeUtils } from 'state/shape-utils'
  6. /* ----------------- Start Copy Here ---------------- */
  7. export default class Rectangle extends CodeShape<RectangleShape> {
  8. constructor(props = {} as ShapeProps<RectangleShape>) {
  9. super({
  10. id: uniqueId(),
  11. parentId: (window as any).currentPageId,
  12. type: ShapeType.Rectangle,
  13. isGenerated: true,
  14. name: 'Rectangle',
  15. childIndex: 0,
  16. point: [0, 0],
  17. size: [100, 100],
  18. rotation: 0,
  19. radius: 2,
  20. isAspectRatioLocked: false,
  21. isLocked: false,
  22. isHidden: false,
  23. ...props,
  24. style: {
  25. ...defaultStyle,
  26. ...props.style,
  27. },
  28. })
  29. }
  30. /**
  31. * The rectangle's width.
  32. *
  33. * ```ts
  34. * const shapeWidth = shape.width
  35. *
  36. * shape.width = 100
  37. * ```
  38. */
  39. get width(): number {
  40. return this.shape.size[0]
  41. }
  42. set width(width: number) {
  43. getShapeUtils(this.shape).setProperty(this.shape, 'size', [
  44. width,
  45. this.height,
  46. ])
  47. }
  48. /**
  49. * The rectangle's height.
  50. *
  51. * ```ts
  52. * const shapeHeight = shape.height
  53. *
  54. * shape.height = 100
  55. * ```
  56. */
  57. get height(): number {
  58. return this.shape.size[1]
  59. }
  60. set height(height: number) {
  61. getShapeUtils(this.shape).setProperty(this.shape, 'size', [
  62. this.width,
  63. height,
  64. ])
  65. }
  66. }