@leafer-ui/hit 1.0.0-beta.7 → 1.0.0-beta.9

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/UIHit.ts +27 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/hit",
3
- "version": "1.0.0-beta.7",
3
+ "version": "1.0.0-beta.9",
4
4
  "description": "@leafer-ui/hit",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -19,7 +19,7 @@
19
19
  "leaferjs"
20
20
  ],
21
21
  "devDependencies": {
22
- "@leafer/interface": "1.0.0-beta.7",
23
- "@leafer-ui/interface": "1.0.0-beta.7"
22
+ "@leafer/interface": "1.0.0-beta.9",
23
+ "@leafer-ui/interface": "1.0.0-beta.9"
24
24
  }
25
25
  }
package/src/UIHit.ts CHANGED
@@ -1,39 +1,51 @@
1
1
  import { IRadiusPointData } from '@leafer/interface'
2
2
 
3
3
  import { IUIHitModule } from '@leafer-ui/interface'
4
+ import { Platform } from '@leafer/core'
4
5
 
5
6
 
6
7
  export const UIHit: IUIHitModule = {
7
8
 
8
9
  __updateHitCanvas(): void {
9
10
  if (!this.__hitCanvas) this.__hitCanvas = this.leafer.hitCanvasManager.getPathType(this)
10
- this.__drawHitPath(this.__hitCanvas)
11
- this.__hitCanvas.setStrokeOptions(this.__)
11
+ const h = this.__hitCanvas
12
+ this.__drawHitPath(h)
13
+ h.setStrokeOptions(this.__)
12
14
  },
13
15
 
14
16
  __hit(inner: IRadiusPointData): boolean {
15
17
  const { __hitCanvas: h } = this
18
+ if (Platform.name === 'miniapp') this.__drawHitPath(h) // fix: 小程序需要实时更新
16
19
 
17
20
  const { fill, hitFill, windingRule } = this.__
18
21
  const needHitFill = (fill && hitFill === 'path') || hitFill === 'all'
19
- if (needHitFill && h.hitFill(inner, windingRule)) return true
22
+ const isHitFill = h.hitFill(inner, windingRule)
23
+ if (needHitFill && isHitFill) return true
20
24
 
21
25
  const { stroke, hitStroke, strokeWidth, strokeAlign } = this.__
22
26
  const needHitStroke = (stroke && hitStroke === 'path') || hitStroke === 'all'
23
27
  const radiusWidth = inner.radiusX * 2
24
- let hitWidth = (needHitStroke ? (strokeAlign === 'center' ? strokeWidth / 2 : strokeWidth) : 0) * 2 + radiusWidth
25
- if (!hitWidth) return false
26
-
27
- switch (strokeAlign) {
28
- case 'inside':
29
- if (!needHitFill && (h.hitFill(inner, windingRule) && h.hitStroke(inner, hitWidth))) return true
30
- hitWidth = radiusWidth
31
- break
32
- case 'outside':
33
- if (!needHitFill) {
34
- if (!h.hitFill(inner, windingRule) && h.hitStroke(inner, hitWidth)) return true
28
+
29
+ let hitWidth = radiusWidth
30
+
31
+ if (needHitStroke) {
32
+ switch (strokeAlign) {
33
+ case 'inside':
34
+ hitWidth += strokeWidth * 2
35
+ if (!needHitFill && (isHitFill && h.hitStroke(inner, hitWidth))) return true
35
36
  hitWidth = radiusWidth
36
- }
37
+ break
38
+ case 'center':
39
+ hitWidth += strokeWidth
40
+ break
41
+ case 'outside':
42
+ hitWidth += strokeWidth * 2
43
+ if (!needHitFill) {
44
+ if (!isHitFill && h.hitStroke(inner, hitWidth)) return true
45
+ hitWidth = radiusWidth
46
+ }
47
+ break
48
+ }
37
49
  }
38
50
 
39
51
  return hitWidth ? h.hitStroke(inner, hitWidth) : false