@leafer-ui/hit 1.5.3 → 1.6.1

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.5.3",
3
+ "version": "1.6.1",
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.5.3",
26
- "@leafer-ui/draw": "1.5.3"
25
+ "@leafer/core": "1.6.1",
26
+ "@leafer-ui/draw": "1.6.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.5.3",
30
- "@leafer-ui/interface": "1.5.3"
29
+ "@leafer/interface": "1.6.1",
30
+ "@leafer-ui/interface": "1.6.1"
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
- if (!this.__.hitSelf) return false
11
+ const data = this.__
12
+ if (!data.hitSelf) return false
12
13
 
13
- if (this.__.hitRadius) {
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, this.__.hitRadius)
19
+ setRadius(point, data.hitRadius)
16
20
  }
17
21
 
18
- toInnerRadiusPointOf(point, this.__world, inner)
19
-
20
- const { width, height } = this.__world
21
- const isSmall = width < 10 && height < 10
22
+ toInnerRadiusPointOf(point, world, inner)
22
23
 
23
- if (this.__.hitBox || isSmall) {
24
- if (BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner)) return true
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 (this.__layout.hitCanvasChanged || !this.__hitCanvas) {
29
+ if (layout.hitCanvasChanged || !this.__hitCanvas) {
29
30
  this.__updateHitCanvas()
30
- if (!this.__layout.boundsChanged) this.__layout.hitCanvasChanged = false
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, ImageManager } from '@leafer-ui/draw'
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
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ export { HitCanvasManager } from './HitCanvasManager'
3
3
  import './LeafHit'
4
4
  import './UIHit'
5
5
  import './RectHit'
6
+ import './TextHit'
6
7
 
7
8
  import './pick'
8
9
  import './canvas'