您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

dot.tsx 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { getFromCache, uniqueId } from 'utils/utils'
  2. import { DotShape, ShapeType } from 'types'
  3. import { intersectCircleBounds } from 'utils/intersections'
  4. import { boundsContained, translateBounds } from 'utils'
  5. import { defaultStyle, getShapeStyle } from 'state/shape-styles'
  6. import { registerShapeUtils } from './register'
  7. const dot = registerShapeUtils<DotShape>({
  8. boundsCache: new WeakMap([]),
  9. defaultProps: {
  10. id: uniqueId(),
  11. type: ShapeType.Dot,
  12. name: 'Dot',
  13. parentId: 'page1',
  14. childIndex: 0,
  15. point: [0, 0],
  16. rotation: 0,
  17. style: defaultStyle,
  18. },
  19. render(shape, { isDarkMode }) {
  20. const styles = getShapeStyle(shape.style, isDarkMode)
  21. return <use href="#dot" stroke={styles.stroke} fill={styles.stroke} />
  22. },
  23. getBounds(shape) {
  24. const bounds = getFromCache(this.boundsCache, shape, (cache) => {
  25. cache.set(shape, {
  26. minX: 0,
  27. maxX: 1,
  28. minY: 0,
  29. maxY: 1,
  30. width: 1,
  31. height: 1,
  32. })
  33. })
  34. return translateBounds(bounds, shape.point)
  35. },
  36. getRotatedBounds(shape) {
  37. return this.getBounds(shape)
  38. },
  39. getCenter(shape) {
  40. return shape.point
  41. },
  42. hitTest() {
  43. return true
  44. },
  45. hitTestBounds(this, shape, brushBounds) {
  46. const shapeBounds = this.getBounds(shape)
  47. return (
  48. boundsContained(shapeBounds, brushBounds) ||
  49. intersectCircleBounds(shape.point, 4, brushBounds).length > 0
  50. )
  51. },
  52. transform(shape, bounds) {
  53. shape.point = [bounds.minX, bounds.minY]
  54. return this
  55. },
  56. canTransform: false,
  57. canChangeAspectRatio: false,
  58. })
  59. export default dot