@leafer-ui/hit 1.5.2 → 1.6.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 +12 -11
- package/src/TextHit.ts +13 -0
- package/src/UIHit.ts +8 -5
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/hit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.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.6.0",
|
|
26
|
+
"@leafer-ui/draw": "1.6.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.
|
|
30
|
-
"@leafer-ui/interface": "1.
|
|
29
|
+
"@leafer/interface": "1.6.0",
|
|
30
|
+
"@leafer-ui/interface": "1.6.0"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/LeafHit.ts
CHANGED
|
@@ -8,26 +8,27 @@ const inner = {} as IRadiusPointData
|
|
|
8
8
|
const leaf = Leaf.prototype
|
|
9
9
|
|
|
10
10
|
leaf.__hitWorld = function (point: IRadiusPointData): boolean {
|
|
11
|
-
|
|
11
|
+
const data = this.__
|
|
12
|
+
if (!data.hitSelf) return false
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
const world = this.__world, layout = this.__layout
|
|
15
|
+
const isSmall = world.width < 10 && world.height < 10
|
|
16
|
+
|
|
17
|
+
if (data.hitRadius) {
|
|
14
18
|
copy(inner, point), point = inner
|
|
15
|
-
setRadius(point,
|
|
19
|
+
setRadius(point, data.hitRadius)
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
toInnerRadiusPointOf(point,
|
|
19
|
-
|
|
20
|
-
const { width, height } = this.__world
|
|
21
|
-
const isSmall = width < 10 && height < 10
|
|
22
|
+
toInnerRadiusPointOf(point, world, inner)
|
|
22
23
|
|
|
23
|
-
if (
|
|
24
|
-
if (BoundsHelper.hitRadiusPoint(
|
|
24
|
+
if (data.hitBox || isSmall) {
|
|
25
|
+
if (BoundsHelper.hitRadiusPoint(layout.boxBounds, inner)) return true
|
|
25
26
|
if (isSmall) return false
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
if (
|
|
29
|
+
if (layout.hitCanvasChanged || !this.__hitCanvas) {
|
|
29
30
|
this.__updateHitCanvas()
|
|
30
|
-
if (!
|
|
31
|
+
if (!layout.boundsChanged) layout.hitCanvasChanged = false
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
return this.__hit(inner)
|
package/src/TextHit.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ILeaferCanvas } from '@leafer/interface'
|
|
2
|
+
import { Text } from '@leafer-ui/draw'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Text.prototype.__drawHitPath = function (canvas: ILeaferCanvas): void {
|
|
6
|
+
const { __lineHeight, fontSize, __baseLine, __letterSpacing, __textDrawData: data } = this.__
|
|
7
|
+
|
|
8
|
+
canvas.beginPath()
|
|
9
|
+
|
|
10
|
+
if (__letterSpacing < 0) this.__drawPathByBox(canvas)
|
|
11
|
+
else data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight))
|
|
12
|
+
}
|
|
13
|
+
|
package/src/UIHit.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { IRadiusPointData } from '@leafer/interface'
|
|
2
|
-
import { Platform, Matrix, tempBounds } from '@leafer/core'
|
|
3
|
-
import { UI
|
|
2
|
+
import { Platform, Matrix, ImageManager, tempBounds } from '@leafer/core'
|
|
3
|
+
import { UI } from '@leafer-ui/draw'
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
const matrix = new Matrix()
|
|
7
7
|
const ui = UI.prototype
|
|
8
8
|
|
|
9
9
|
ui.__updateHitCanvas = function (): void {
|
|
10
|
-
const data = this.__, { hitCanvasManager } = this.leafer
|
|
11
10
|
|
|
11
|
+
if (this.__box) this.__box.__updateHitCanvas()
|
|
12
|
+
|
|
13
|
+
const data = this.__, { hitCanvasManager } = this.leafer || this.parent.leafer // 兼容 boxStyle
|
|
12
14
|
const isHitPixelFill = (data.__pixelFill || data.__isCanvas) && data.hitFill === 'pixel'
|
|
13
15
|
const isHitPixelStroke = data.__pixelStroke && data.hitStroke === 'pixel'
|
|
14
16
|
const isHitPixel = isHitPixelFill || isHitPixelStroke
|
|
@@ -41,13 +43,14 @@ ui.__updateHitCanvas = function (): void {
|
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
ui.__hit = function (inner: IRadiusPointData): boolean {
|
|
44
|
-
// hit pixel
|
|
45
46
|
|
|
47
|
+
if (this.__box && this.__box.__hit(inner)) return true
|
|
48
|
+
|
|
49
|
+
// hit pixel
|
|
46
50
|
const data = this.__
|
|
47
51
|
if (data.__isHitPixel && this.__hitPixel(inner)) return true
|
|
48
52
|
|
|
49
53
|
// hit path
|
|
50
|
-
|
|
51
54
|
const { hitFill } = data
|
|
52
55
|
const needHitFillPath = ((data.fill || data.__isCanvas) && (hitFill === 'path' || (hitFill === 'pixel' && !(data.__pixelFill || data.__isCanvas)))) || hitFill === 'all'
|
|
53
56
|
if (needHitFillPath && this.__hitFill(inner)) return true
|