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

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 +30 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/hit",
3
- "version": "1.0.0-alpha.9",
3
+ "version": "1.0.0-beta",
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.9",
23
- "@leafer-ui/interface": "1.0.0-alpha.9"
22
+ "@leafer/interface": "1.0.0-beta",
23
+ "@leafer-ui/interface": "1.0.0-beta"
24
24
  }
25
25
  }
package/src/UIHit.ts CHANGED
@@ -5,24 +5,38 @@ import { IUIHitModule } from '@leafer-ui/interface'
5
5
 
6
6
  export const UIHit: IUIHitModule = {
7
7
 
8
- __hit(local: IRadiusPointData): boolean {
9
-
10
- if (this.__.fill) {
11
- if (this.__hitCanvas.hitPath(local, this.__.windingRule)) return true
12
- }
13
-
14
- const strokeWidth = ((this.__.__strokeOuterWidth || 0) + local.radiusX) * 2
15
-
16
- if (strokeWidth) {
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
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
+
14
+ __hit(inner: IRadiusPointData): boolean {
15
+ const { __hitCanvas: h } = this
16
+
17
+ const { fill, hitFill, windingRule } = this.__
18
+ const needHitFill = (fill && hitFill === 'path') || hitFill === 'all'
19
+ if (needHitFill && h.hitFill(inner, windingRule)) return true
20
+
21
+ const { stroke, hitStroke, strokeWidth, strokeAlign } = this.__
22
+ const needHitStroke = (stroke && hitStroke === 'path') || hitStroke === 'all'
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
+ }
23
37
  }
24
38
 
25
- return false
39
+ return hitWidth ? h.hitStroke(inner, hitWidth) : false
26
40
  }
27
41
 
28
42
  }