@leafer-ui/hit 1.0.0-alpha.10 → 1.0.0-alpha.23

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 +18 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/hit",
3
- "version": "1.0.0-alpha.10",
3
+ "version": "1.0.0-alpha.23",
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-alpha.10",
23
- "@leafer-ui/interface": "1.0.0-alpha.10"
22
+ "@leafer/interface": "1.0.0-alpha.23",
23
+ "@leafer-ui/interface": "1.0.0-alpha.23"
24
24
  }
25
25
  }
package/src/UIHit.ts CHANGED
@@ -3,26 +3,31 @@ import { IRadiusPointData } from '@leafer/interface'
3
3
  import { IUIHitModule } from '@leafer-ui/interface'
4
4
 
5
5
 
6
+ const fillVisibleType = ['visible', 'fill-visible']
7
+ const fillType = ['all', 'fill']
8
+ const strokeVisibleType = ['visible', 'stroke-visible']
9
+ const strokeType = ['all', 'stroke']
10
+
6
11
  export const UIHit: IUIHitModule = {
7
12
 
8
- __hit(local: IRadiusPointData): boolean {
13
+ __hit(inner: IRadiusPointData): boolean {
14
+ const { __hitCanvas: h } = this
9
15
 
10
- if (this.__.fill) {
11
- if (this.__hitCanvas.hitPath(local, this.__.windingRule)) return true
12
- }
16
+ const { fill, hitType } = this.__
17
+ const hitFill = (fill && fillVisibleType.includes(hitType)) || fillType.includes(hitType)
18
+ if (hitFill && h.hitFill(inner, this.__.windingRule)) return true
13
19
 
14
- if (this.__.__strokeOuterWidth) {
15
- const strokeWidth = (this.__.__strokeOuterWidth + local.radiusX) * 2
20
+ const { stroke, __strokeOuterWidth: outerWidth } = this.__
21
+ const hitStroke = (stroke && strokeVisibleType.includes(hitType)) || strokeType.includes(hitType)
22
+ if (!hitFill && !hitStroke) return false
16
23
 
17
- const { __hitCanvas: c } = this
18
- if (c.strokeWidth !== strokeWidth) {
19
- c.strokeWidth = strokeWidth
20
- c.stroke()
21
- }
22
- if (c.hitStroke(local)) return true
24
+ const strokeWidth = ((hitStroke ? (outerWidth || 0) : 0) + inner.radiusX) * 2
25
+ if (h.strokeWidth !== strokeWidth) {
26
+ h.strokeWidth = strokeWidth
27
+ h.stroke()
23
28
  }
24
29
 
25
- return false
30
+ return h.hitStroke(inner)
26
31
  }
27
32
 
28
33
  }