選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

dot.tsx 1.8KB

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