@leafer-ui/hit 1.7.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 +5 -5
- package/src/LeafHit.ts +20 -7
- package/src/UIHit.ts +8 -5
- package/src/index.ts +2 -0
- package/src/pick.ts +3 -6
- package/src/selector.ts +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/hit",
|
|
3
|
-
"version": "1.
|
|
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.
|
|
26
|
-
"@leafer-ui/draw": "1.
|
|
25
|
+
"@leafer/core": "1.9.0",
|
|
26
|
+
"@leafer-ui/draw": "1.9.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.
|
|
30
|
-
"@leafer-ui/interface": "1.
|
|
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
|
|
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
|
|
@@ -34,10 +47,10 @@ leaf.__hitWorld = function (point: IRadiusPointData): boolean {
|
|
|
34
47
|
return this.__hit(inner)
|
|
35
48
|
}
|
|
36
49
|
|
|
37
|
-
leaf.__hitFill = function (inner: IRadiusPointData): boolean {
|
|
50
|
+
leaf.__hitFill = function (inner: IRadiusPointData): boolean { const h = this.__hitCanvas; return h && h.hitFill(inner, this.__.windingRule) }
|
|
38
51
|
|
|
39
|
-
leaf.__hitStroke = function (inner: IRadiusPointData, strokeWidth: number): boolean {
|
|
52
|
+
leaf.__hitStroke = function (inner: IRadiusPointData, strokeWidth: number): boolean { const h = this.__hitCanvas; return h && h.hitStroke(inner, strokeWidth) }
|
|
40
53
|
|
|
41
|
-
leaf.__hitPixel = function (inner: IRadiusPointData): boolean {
|
|
54
|
+
leaf.__hitPixel = function (inner: IRadiusPointData): boolean { const h = this.__hitCanvas; return h && h.hitPixel(inner, this.__layout.renderBounds, h.hitScale) }
|
|
42
55
|
|
|
43
|
-
leaf.__drawHitPath = function (canvas: ILeaferCanvas): void {
|
|
56
|
+
leaf.__drawHitPath = function (canvas: ILeaferCanvas): void { canvas && this.__drawRenderPath(canvas) }
|
package/src/UIHit.ts
CHANGED
|
@@ -10,7 +10,10 @@ ui.__updateHitCanvas = function (): void {
|
|
|
10
10
|
|
|
11
11
|
if (this.__box) this.__box.__updateHitCanvas()
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const leafer = this.leafer || (this.parent && this.parent.leafer) // 兼容 boxStyle
|
|
14
|
+
if (!leafer) return
|
|
15
|
+
|
|
16
|
+
const data = this.__, { hitCanvasManager } = leafer
|
|
14
17
|
const isHitPixelFill = (data.__isAlphaPixelFill || data.__isCanvas) && data.hitFill === 'pixel'
|
|
15
18
|
const isHitPixelStroke = data.__isAlphaPixelStroke && data.hitStroke === 'pixel'
|
|
16
19
|
const isHitPixel = isHitPixelFill || isHitPixelStroke
|
|
@@ -55,7 +58,7 @@ ui.__hit = function (inner: IRadiusPointData): boolean {
|
|
|
55
58
|
const needHitFillPath = ((data.fill || data.__isCanvas) && (hitFill === 'path' || (hitFill === 'pixel' && !(data.__isAlphaPixelFill || data.__isCanvas)))) || hitFill === 'all'
|
|
56
59
|
if (needHitFillPath && this.__hitFill(inner)) return true
|
|
57
60
|
|
|
58
|
-
const { hitStroke,
|
|
61
|
+
const { hitStroke, __maxStrokeWidth: strokeWidth } = data
|
|
59
62
|
const needHitStrokePath = (data.stroke && (hitStroke === 'path' || (hitStroke === 'pixel' && !data.__isAlphaPixelStroke))) || hitStroke === 'all'
|
|
60
63
|
if (!needHitFillPath && !needHitStrokePath) return false
|
|
61
64
|
|
|
@@ -65,15 +68,15 @@ ui.__hit = function (inner: IRadiusPointData): boolean {
|
|
|
65
68
|
if (needHitStrokePath) {
|
|
66
69
|
switch (data.strokeAlign) {
|
|
67
70
|
case 'inside':
|
|
68
|
-
hitWidth +=
|
|
71
|
+
hitWidth += strokeWidth * 2
|
|
69
72
|
if (!needHitFillPath && this.__hitFill(inner) && this.__hitStroke(inner, hitWidth)) return true
|
|
70
73
|
hitWidth = radiusWidth
|
|
71
74
|
break
|
|
72
75
|
case 'center':
|
|
73
|
-
hitWidth +=
|
|
76
|
+
hitWidth += strokeWidth
|
|
74
77
|
break
|
|
75
78
|
case 'outside':
|
|
76
|
-
hitWidth +=
|
|
79
|
+
hitWidth += strokeWidth * 2
|
|
77
80
|
if (!needHitFillPath) {
|
|
78
81
|
if (!this.__hitFill(inner) && this.__hitStroke(inner, hitWidth)) return true
|
|
79
82
|
hitWidth = radiusWidth
|
package/src/index.ts
CHANGED
package/src/pick.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { Platform
|
|
1
|
+
import { Platform } from '@leafer/core'
|
|
2
2
|
|
|
3
|
-
import { IPointData, IPickOptions, IPickResult
|
|
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
|
}
|
package/src/selector.ts
ADDED
|
@@ -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
|
+
}
|