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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { v4 as uuid } from 'uuid'
  2. import * as vec from 'utils/vec'
  3. import { DotShape, ShapeType } from 'types'
  4. import { registerShapeUtils } from './index'
  5. import { boundsContained } from 'utils/bounds'
  6. import { intersectCircleBounds } from 'utils/intersections'
  7. import { DotCircle } from 'components/canvas/misc'
  8. import { translateBounds } from 'utils/utils'
  9. import { defaultStyle } from 'lib/shape-styles'
  10. const dot = registerShapeUtils<DotShape>({
  11. boundsCache: new WeakMap([]),
  12. create(props) {
  13. return {
  14. id: uuid(),
  15. type: ShapeType.Dot,
  16. isGenerated: false,
  17. name: 'Dot',
  18. parentId: 'page0',
  19. childIndex: 0,
  20. point: [0, 0],
  21. rotation: 0,
  22. isAspectRatioLocked: false,
  23. isLocked: false,
  24. isHidden: false,
  25. ...props,
  26. style: {
  27. ...defaultStyle,
  28. ...props.style,
  29. isFilled: false,
  30. },
  31. }
  32. },
  33. render({ id }) {
  34. return <DotCircle id={id} cx={0} cy={0} r={3} />
  35. },
  36. applyStyles(shape, style) {
  37. Object.assign(shape.style, style)
  38. return this
  39. },
  40. getBounds(shape) {
  41. if (!this.boundsCache.has(shape)) {
  42. const bounds = {
  43. minX: 0,
  44. maxX: 1,
  45. minY: 0,
  46. maxY: 1,
  47. width: 1,
  48. height: 1,
  49. }
  50. this.boundsCache.set(shape, bounds)
  51. }
  52. return translateBounds(this.boundsCache.get(shape), shape.point)
  53. },
  54. getRotatedBounds(shape) {
  55. return this.getBounds(shape)
  56. },
  57. getCenter(shape) {
  58. return shape.point
  59. },
  60. hitTest(shape, test) {
  61. return true
  62. },
  63. hitTestBounds(this, shape, brushBounds) {
  64. const shapeBounds = this.getBounds(shape)
  65. return (
  66. boundsContained(shapeBounds, brushBounds) ||
  67. intersectCircleBounds(shape.point, 4, brushBounds).length > 0
  68. )
  69. },
  70. transform(shape, bounds) {
  71. shape.point = [bounds.minX, bounds.minY]
  72. return this
  73. },
  74. transformSingle(shape, bounds, info) {
  75. this.transform(shape, bounds, info)
  76. return this
  77. },
  78. setProperty(shape, prop, value) {
  79. shape[prop] = value
  80. return this
  81. },
  82. canTransform: false,
  83. canChangeAspectRatio: false,
  84. canStyleFill: true,
  85. })
  86. export default dot