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

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 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/hit",
3
- "version": "1.0.0-alpha.23",
3
+ "version": "1.0.0-alpha.31",
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.23",
23
- "@leafer-ui/interface": "1.0.0-alpha.23"
22
+ "@leafer/interface": "1.0.0-alpha.31",
23
+ "@leafer-ui/interface": "1.0.0-alpha.31"
24
24
  }
25
25
  }
package/src/UIHit.ts CHANGED
@@ -3,31 +3,40 @@ 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
-
11
6
  export const UIHit: IUIHitModule = {
12
7
 
8
+ __updateHitCanvas(): void {
9
+ if (!this.__hitCanvas) this.__hitCanvas = this.leafer.hitCanvasManager.getPathType(this)
10
+ this.__drawHitPath(this.__hitCanvas)
11
+ this.__hitCanvas.setStrokeOptions(this.__)
12
+ },
13
+
13
14
  __hit(inner: IRadiusPointData): boolean {
14
15
  const { __hitCanvas: h } = this
15
16
 
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
19
-
20
- const { stroke, __strokeOuterWidth: outerWidth } = this.__
21
- const hitStroke = (stroke && strokeVisibleType.includes(hitType)) || strokeType.includes(hitType)
22
- if (!hitFill && !hitStroke) return false
23
-
24
- const strokeWidth = ((hitStroke ? (outerWidth || 0) : 0) + inner.radiusX) * 2
25
- if (h.strokeWidth !== strokeWidth) {
26
- h.strokeWidth = strokeWidth
27
- h.stroke()
17
+ const { fill, hitFill, windingRule } = this.__
18
+ const needHitFill = (fill && hitFill === 'visible') || hitFill === 'always'
19
+ if (needHitFill && h.hitFill(inner, windingRule)) return true
20
+
21
+ const { stroke, hitStroke, strokeWidth, strokeAlign } = this.__
22
+ const needHitStroke = (stroke && hitStroke === 'visible') || hitStroke === 'always'
23
+ 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
35
+ hitWidth = radiusWidth
36
+ }
28
37
  }
29
38
 
30
- return h.hitStroke(inner)
39
+ return hitWidth ? h.hitStroke(inner, hitWidth) : false
31
40
  }
32
41
 
33
42
  }