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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { uniqueId } from 'utils'
  2. import { DotShape, ShapeType } from 'types'
  3. import { intersectCircleBounds } from 'utils/intersections'
  4. import { boundsContained, translateBounds } from 'utils'
  5. import { defaultStyle } from 'state/shape-styles'
  6. import { registerShapeUtils } from './register'
  7. const dot = registerShapeUtils<DotShape>({
  8. boundsCache: new WeakMap([]),
  9. create(props) {
  10. return {
  11. id: uniqueId(),
  12. seed: Math.random(),
  13. type: ShapeType.Dot,
  14. isGenerated: false,
  15. name: 'Dot',
  16. parentId: 'page1',
  17. childIndex: 0,
  18. point: [0, 0],
  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. render({ id }) {
  32. return <use id={id} href="#dot" fill="black" />
  33. },
  34. getBounds(shape) {
  35. if (!this.boundsCache.has(shape)) {
  36. const bounds = {
  37. minX: 0,
  38. maxX: 1,
  39. minY: 0,
  40. maxY: 1,
  41. width: 1,
  42. height: 1,
  43. }
  44. this.boundsCache.set(shape, bounds)
  45. }
  46. return translateBounds(this.boundsCache.get(shape), shape.point)
  47. },
  48. getRotatedBounds(shape) {
  49. return this.getBounds(shape)
  50. },
  51. getCenter(shape) {
  52. return shape.point
  53. },
  54. hitTest() {
  55. return true
  56. },
  57. hitTestBounds(this, shape, brushBounds) {
  58. const shapeBounds = this.getBounds(shape)
  59. return (
  60. boundsContained(shapeBounds, brushBounds) ||
  61. intersectCircleBounds(shape.point, 4, brushBounds).length > 0
  62. )
  63. },
  64. transform(shape, bounds) {
  65. shape.point = [bounds.minX, bounds.minY]
  66. return this
  67. },
  68. canTransform: false,
  69. canChangeAspectRatio: false,
  70. })
  71. export default dot