Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

rectangle.tsx 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { v4 as uuid } from "uuid"
  2. import * as vec from "utils/vec"
  3. import { BaseLibShape, RectangleShape, ShapeType } from "types"
  4. const Rectangle: BaseLibShape<ShapeType.Rectangle> = {
  5. create(props): RectangleShape {
  6. return {
  7. id: uuid(),
  8. type: ShapeType.Rectangle,
  9. name: "Rectangle",
  10. parentId: "page0",
  11. childIndex: 0,
  12. point: [0, 0],
  13. size: [1, 1],
  14. rotation: 0,
  15. style: {},
  16. ...props,
  17. }
  18. },
  19. render({ id, size }) {
  20. return <rect id={id} width={size[0]} height={size[1]} />
  21. },
  22. getBounds(shape) {
  23. const {
  24. point: [x, y],
  25. size: [width, height],
  26. } = shape
  27. return {
  28. minX: x,
  29. maxX: x + width,
  30. minY: y,
  31. maxY: y + height,
  32. width,
  33. height,
  34. }
  35. },
  36. hitTest(shape) {
  37. return true
  38. },
  39. rotate(shape) {
  40. return shape
  41. },
  42. translate(shape) {
  43. return shape
  44. },
  45. scale(shape, scale: number) {
  46. return shape
  47. },
  48. stretch(shape, scaleX: number, scaleY: number) {
  49. return shape
  50. },
  51. }
  52. export default Rectangle