@leafer-ui/hit 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/hit",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "@leafer-ui/hit",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,11 +22,11 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.8.0",
26
- "@leafer-ui/draw": "1.8.0"
25
+ "@leafer/core": "1.9.0",
26
+ "@leafer-ui/draw": "1.9.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.8.0",
30
- "@leafer-ui/interface": "1.8.0"
29
+ "@leafer/interface": "1.9.0",
30
+ "@leafer-ui/interface": "1.9.0"
31
31
  }
32
32
  }
package/src/LeafHit.ts CHANGED
@@ -1,12 +1,25 @@
1
- import { IRadiusPointData, ILeaferCanvas } from '@leafer/interface'
2
- import { Leaf, PointHelper, BoundsHelper } from '@leafer/core'
1
+ import { IRadiusPointData, ILeaferCanvas, IPointData, IBranch } from '@leafer/interface'
2
+ import { Leaf, PointHelper, BoundsHelper, Platform } from '@leafer/core'
3
3
 
4
4
 
5
5
  const { toInnerRadiusPointOf, copy, setRadius } = PointHelper
6
- const inner = {} as IRadiusPointData
6
+ const { hitRadiusPoint, hitPoint } = BoundsHelper
7
+ const inner = {} as IRadiusPointData, worldRadiusPoint = {} as IRadiusPointData
7
8
 
8
9
  const leaf = Leaf.prototype
9
10
 
11
+ leaf.hit = function (worldPoint: IPointData, hitRadius: number = 0): boolean {
12
+ this.updateLayout()
13
+
14
+ copy(worldRadiusPoint, worldPoint)
15
+ setRadius(worldRadiusPoint, hitRadius)
16
+
17
+ const world = this.__world
18
+ if (hitRadius ? !hitRadiusPoint(world, worldRadiusPoint) : !hitPoint(world, worldRadiusPoint)) return false
19
+
20
+ return this.isBranch ? Platform.getSelector(this).hitPoint({ ...worldRadiusPoint }, hitRadius, { target: this as unknown as IBranch }) : this.__hitWorld(worldRadiusPoint)
21
+ }
22
+
10
23
  leaf.__hitWorld = function (point: IRadiusPointData): boolean {
11
24
  const data = this.__
12
25
  if (!data.hitSelf) return false
package/src/index.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { HitCanvasManager } from './HitCanvasManager'
2
2
 
3
+ import './selector'
4
+
3
5
  import './LeafHit'
4
6
  import './UIHit'
5
7
  import './RectHit'
package/src/pick.ts CHANGED
@@ -1,14 +1,11 @@
1
- import { Platform, Creator } from '@leafer/core'
1
+ import { Platform } from '@leafer/core'
2
2
 
3
- import { IPointData, IPickOptions, IPickResult, ISelector, IUI } from '@leafer-ui/interface'
3
+ import { IPointData, IPickOptions, IPickResult } from '@leafer-ui/interface'
4
4
  import { Group, emptyData } from '@leafer-ui/draw'
5
5
 
6
- function getSelector(ui: IUI): ISelector {
7
- return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()))
8
- }
9
6
 
10
7
  Group.prototype.pick = function (hitPoint: IPointData, options?: IPickOptions): IPickResult {
11
8
  options || (options = emptyData)
12
9
  this.updateLayout()
13
- return getSelector(this).getByPoint(hitPoint, options.hitRadius || 0, { ...options, target: this })
10
+ return Platform.getSelector(this).getByPoint(hitPoint, options.hitRadius || 0, { ...options, target: this })
14
11
  }
@@ -0,0 +1,8 @@
1
+ import { Platform, Creator } from '@leafer/core'
2
+
3
+ import { ISelector, ILeaf } from '@leafer-ui/interface'
4
+
5
+
6
+ Platform.getSelector = function (leaf: ILeaf): ISelector {
7
+ return leaf.leafer ? leaf.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()))
8
+ }