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.

rectangle.ts 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import CodeShape from './index'
  2. import { uniqueId } from 'utils/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. ...props,
  21. style: {
  22. ...defaultStyle,
  23. ...props.style,
  24. },
  25. })
  26. }
  27. /**
  28. * The rectangle's width.
  29. *
  30. * ```ts
  31. * const shapeWidth = shape.width
  32. *
  33. * shape.width = 100
  34. * ```
  35. */
  36. get width(): number {
  37. return this.shape.size[0]
  38. }
  39. set width(width: number) {
  40. getShapeUtils(this.shape).setProperty(this.shape, 'size', [
  41. width,
  42. this.height,
  43. ])
  44. }
  45. /**
  46. * The rectangle's height.
  47. *
  48. * ```ts
  49. * const shapeHeight = shape.height
  50. *
  51. * shape.height = 100
  52. * ```
  53. */
  54. get height(): number {
  55. return this.shape.size[1]
  56. }
  57. set height(height: number) {
  58. getShapeUtils(this.shape).setProperty(this.shape, 'size', [
  59. this.width,
  60. height,
  61. ])
  62. }
  63. }